1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef SCRATCHPAD3D_H
#define SCRATCHPAD3D_H
#ifdef _WIN32
#pragma once
#endif
#include <stdio.h>
#include "iscratchpad3d.h"
#include "mathlib/vmatrix.h"
#include "filesystem.h"
class CFileRead;
class CScratchPad3D : public IScratchPad3D
{
// Commands that can go in the file.
public:
enum
{
COMMAND_POINT=0,
COMMAND_LINE,
COMMAND_POLYGON,
COMMAND_MATRIX,
COMMAND_RENDERSTATE,
COMMAND_TEXT,
COMMAND_NUMCOMMANDS
};
class ICachedRenderData
{
public:
virtual void Release() = 0;
};
class CBaseCommand
{
public:
CBaseCommand( unsigned char iCommand )
{
m_iCommand = (unsigned char)iCommand;
m_pCachedRenderData = NULL;
}
~CBaseCommand()
{
ReleaseCachedRenderData();
}
virtual void Read( CFileRead *pFile ) = 0;
virtual void Write( IFileSystem* pFileSystem, FileHandle_t fp ) = 0;
// Release cached render data. Usually used for releasing things like textures when
// the app is resizing..
void ReleaseCachedRenderData()
{
if ( m_pCachedRenderData )
{
m_pCachedRenderData->Release();
m_pCachedRenderData = NULL;
}
}
public:
unsigned char m_iCommand; // One of the COMMAND_ defines.
// The renderer can cache data with the commands to speedup the rendering after
// the first time (text uses this big time).
ICachedRenderData *m_pCachedRenderData;
};
class CCommand_Point : public CBaseCommand
{
public:
CCommand_Point() : CBaseCommand( COMMAND_POINT ) {}
virtual void Read( CFileRead *pFile );
virtual void Write( IFileSystem* pFileSystem, FileHandle_t fp );
float m_flPointSize;
CSPVert m_Vert;
};
class CCommand_Line : public CBaseCommand
{
public:
CCommand_Line() : CBaseCommand( COMMAND_LINE ) {}
virtual void Read( CFileRead *pFile );
virtual void Write( IFileSystem* pFileSystem, FileHandle_t fp );
CSPVert m_Verts[2];
};
class CCommand_Polygon : public CBaseCommand
{
public:
CCommand_Polygon() : CBaseCommand( COMMAND_POLYGON ) {}
virtual void Read( CFileRead *pFile );
virtual void Write( IFileSystem* pFileSystem, FileHandle_t fp );
CUtlVector<CSPVert> m_Verts;
};
class CCommand_Matrix : public CBaseCommand
{
public:
CCommand_Matrix() : CBaseCommand( COMMAND_MATRIX ) {}
virtual void Read( CFileRead *pFile );
virtual void Write( IFileSystem* pFileSystem, FileHandle_t fp );
VMatrix m_mMatrix;
};
class CCommand_RenderState : public CBaseCommand
{
public:
CCommand_RenderState() : CBaseCommand( COMMAND_RENDERSTATE ) {}
virtual void Read( CFileRead *pFile );
virtual void Write( IFileSystem* pFileSystem, FileHandle_t fp );
unsigned long m_State; // One of the RS_ enums.
unsigned long m_Val;
};
class CCommand_Text : public CBaseCommand
{
public:
CCommand_Text() : CBaseCommand( COMMAND_TEXT ) {}
virtual void Read( CFileRead *pFile );
virtual void Write( IFileSystem* pFileSystem, FileHandle_t fp );
CUtlVector<char> m_String; // The string to render.
CTextParams m_TextParams;
};
public:
CScratchPad3D( char const *pFilename, IFileSystem *pFileSystem, bool bAutoClear );
void AutoFlush();
void DrawRectGeneric( int iPlane, int otherDim1, int otherDim2, float planeDist, Vector2D const &vMin, Vector2D const &vMax, CSPColor const &vColor );
void DeleteCommands();
// Load a file...
bool LoadCommandsFromFile( );
public:
virtual void Release();
virtual void SetMapping(
Vector const &vInputMin,
Vector const &vInputMax,
Vector const &vOutputMin,
Vector const &vOutputMax );
virtual bool GetAutoFlush();
virtual void SetAutoFlush( bool bAutoFlush );
virtual void DrawPoint( CSPVert const &v, float flPointSize );
virtual void DrawLine( CSPVert const &v1, CSPVert const &v2 );
virtual void DrawPolygon( CSPVertList const &verts );
virtual void DrawRectYZ( float xPos, Vector2D const &vMin, Vector2D const &vMax, CSPColor const &vColor );
virtual void DrawRectXZ( float yPos, Vector2D const &vMin, Vector2D const &vMax, CSPColor const &vColor );
virtual void DrawRectXY( float zPos, Vector2D const &vMin, Vector2D const &vMax, CSPColor const &vColor );
virtual void DrawWireframeBox( Vector const &vMin, Vector const &vMax, Vector const &vColor );
virtual void DrawText( const char *pStr, const CTextParams ¶ms );
virtual void SetRenderState( RenderState state, unsigned long val );
virtual void Clear();
virtual void Flush();
virtual void DrawImageBW(
unsigned char const *pData,
int width,
int height,
int pitchInBytes,
bool bOutlinePixels=true,
bool bOutlineImage=false,
Vector *vCorners=NULL );
// Draw an RGBA image.
// Corners are in this order: bottom-left, top-left, top-right, bottom-right.
virtual void DrawImageRGBA(
SPRGBA *pData,
int width,
int height,
int pitchInBytes,
bool bOutlinePixels=true,
bool bOutlineImage=false,
Vector *vCorners=NULL );
void DrawPolygonsForPixels(
SPRGBA *pData,
int width,
int height,
int pitchInBytes,
Vector *vCorners );
public:
IFileSystem* m_pFileSystem;
char const *m_pFilename;
CUtlVector<CBaseCommand*> m_Commands;
bool m_bAutoFlush;
};
IFileSystem* ScratchPad3D_SetupFileSystem();
#endif // SCRATCHPAD3D_H
|