Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
5.4 KiB

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