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.

315 lines
8.5 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. //
  3. // glmgrbasics.h
  4. // types, common headers, forward declarations, utilities
  5. //
  6. //===============================================================================
  7. #ifndef GLMBASICS_H
  8. #define GLMBASICS_H
  9. #pragma once
  10. #ifdef OSX
  11. #include <OpenGL/OpenGL.h>
  12. #include <OpenGL/gl.h>
  13. #include <OpenGL/glext.h>
  14. #include <OpenGL/CGLTypes.h>
  15. #include <OpenGL/CGLRenderers.h>
  16. #include <OpenGL/CGLCurrent.h>
  17. #include <AvailabilityMacros.h>
  18. #ifndef MAC_OS_X_VERSION_10_9
  19. #include <OpenGL/CGLProfiler.h>
  20. #include <ApplicationServices/ApplicationServices.h>
  21. #endif
  22. #elif defined(DX_TO_GL_ABSTRACTION)
  23. #include <GL/gl.h>
  24. #include <GL/glext.h>
  25. #else
  26. #error
  27. #endif
  28. #include "tier0/platform.h"
  29. #include "bitmap/imageformat.h"
  30. #include "bitvec.h"
  31. #include "tier1/checksum_md5.h"
  32. #include "tier1/utlvector.h"
  33. #include "tier1/convar.h"
  34. #include <sys/stat.h>
  35. #include "dxabstract_types.h"
  36. struct GLMRect;
  37. typedef void *PseudoGLContextPtr;
  38. // types
  39. // 3-d integer box (used for texture lock/unlock etc)
  40. struct GLMRegion
  41. {
  42. int xmin,xmax;
  43. int ymin,ymax;
  44. int zmin,zmax;
  45. };
  46. struct GLMRect // follows GL convention - if coming from the D3D rect you will need to fiddle the Y's
  47. {
  48. int xmin; // left
  49. int ymin; // bottom
  50. int xmax; // right
  51. int ymax; // top
  52. };
  53. // macros
  54. //#define GLMassert(x) assert(x)
  55. // forward decls
  56. class GLMgr; // singleton
  57. class GLMContext; // GL context
  58. class CGLMContextTester; // testing class
  59. class CGLMTex;
  60. class CGLMFBO;
  61. class CGLMProgram;
  62. class CGLMBuffer;
  63. // utilities
  64. typedef enum
  65. {
  66. // D3D codes
  67. eD3D_DEVTYPE,
  68. eD3D_FORMAT,
  69. eD3D_RTYPE,
  70. eD3D_USAGE,
  71. eD3D_RSTATE, // render state
  72. eD3D_SIO, // D3D shader bytecode
  73. eD3D_VTXDECLUSAGE,
  74. // CGL codes
  75. eCGL_RENDID,
  76. // OpenGL error codes
  77. eGL_ERROR,
  78. // OpenGL enums
  79. eGL_ENUM,
  80. eGL_RENDERER
  81. } GLMThing_t;
  82. // these will look at the string to guess its flavor: <, >, ---, -M-, -S-
  83. #ifdef TOGL_DLL_EXPORT
  84. DLL_EXPORT const char* GLMDecode( GLMThing_t type, unsigned long value ); // decode a numeric const
  85. #else
  86. DLL_IMPORT const char* GLMDecode( GLMThing_t type, unsigned long value ); // decode a numeric const
  87. #endif
  88. const char* GLMDecodeMask( GLMThing_t type, unsigned long value ); // decode a bitmask
  89. FORCEINLINE void GLMStop( void ) { DXABSTRACT_BREAK_ON_ERROR(); }
  90. void GLMEnableTrace( bool on );
  91. //===============================================================================
  92. // output functions
  93. // expose these in release now
  94. // Mimic PIX events so we can decorate debug spew
  95. DLL_EXPORT void GLMBeginPIXEvent( const char *str );
  96. DLL_EXPORT void GLMEndPIXEvent( void );
  97. class CScopedGLMPIXEvent
  98. {
  99. CScopedGLMPIXEvent( const CScopedGLMPIXEvent & );
  100. CScopedGLMPIXEvent& operator= ( const CScopedGLMPIXEvent & );
  101. public:
  102. inline CScopedGLMPIXEvent( const char *pName ) { GLMBeginPIXEvent( pName ); }
  103. inline ~CScopedGLMPIXEvent() { GLMEndPIXEvent( ); }
  104. };
  105. #if GLMDEBUG
  106. //===============================================================================
  107. // classes
  108. // helper class making function tracking easier to wire up
  109. class GLMFuncLogger
  110. {
  111. public:
  112. // simple function log
  113. GLMFuncLogger( const char *funcName )
  114. {
  115. m_funcName = funcName;
  116. m_earlyOut = false;
  117. GLMPrintf( ">%s", m_funcName );
  118. };
  119. // more advanced version lets you pass args (i.e. called parameters or anything else of interest)
  120. // no macro for this one, since no easy way to pass through the args as well as the funcname
  121. GLMFuncLogger( const char *funcName, char *fmt, ... )
  122. {
  123. m_funcName = funcName;
  124. m_earlyOut = false;
  125. // this acts like GLMPrintf here
  126. // all the indent policy is down in GLMPrintfVA
  127. // which means we need to inject a ">" at the front of the format string to make this work... sigh.
  128. char modifiedFmt[2000];
  129. modifiedFmt[0] = '>';
  130. strcpy( modifiedFmt+1, fmt );
  131. va_list vargs;
  132. va_start(vargs, fmt);
  133. GLMPrintfVA( modifiedFmt, vargs );
  134. va_end( vargs );
  135. }
  136. ~GLMFuncLogger( )
  137. {
  138. if (m_earlyOut)
  139. {
  140. GLMPrintf( "<%s (early out)", m_funcName );
  141. }
  142. else
  143. {
  144. GLMPrintf( "<%s", m_funcName );
  145. }
  146. };
  147. void EarlyOut( void )
  148. {
  149. m_earlyOut = true;
  150. };
  151. const char *m_funcName; // set at construction time
  152. bool m_earlyOut;
  153. };
  154. // handy macro to go with the function tracking class
  155. #define GLM_FUNC GLMFuncLogger _logger_ ( __FUNCTION__ )
  156. #else
  157. #define GLM_FUNC tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "%s", __FUNCTION__ )
  158. #endif
  159. // class to keep an in-memory mirror of a file which may be getting edited during run
  160. class CGLMFileMirror
  161. {
  162. public:
  163. CGLMFileMirror( char *fullpath ); // just associates mirror with file. if file exists it will be read.
  164. //if non existent it will be created with size zero
  165. ~CGLMFileMirror( );
  166. bool HasData( void ); // see if data avail
  167. void GetData( char **dataPtr, uint *dataSizePtr ); // read it out
  168. void SetData( char *data, uint dataSize ); // put data in (and write it to disk)
  169. bool PollForChanges( void ); // check disk copy. If different, read it back in and return true.
  170. void UpdateStatInfo( void ); // make sure stat info is current for our file
  171. void ReadFile( void );
  172. void WriteFile( void );
  173. void OpenInEditor( bool foreground=false ); // pass TRUE if you would like the editor to pop to foreground
  174. /// how about a "wait for change" method..
  175. char *m_path; // fullpath to file
  176. bool m_exists;
  177. struct stat m_stat; // stat results for the file (last time checked)
  178. char *m_data; // content of file
  179. uint m_size; // length of content
  180. };
  181. // class based on the file mirror, that makes it easy to edit them outside the app.
  182. // it receives an initial block of text from the engine, and hashes it. ("orig")
  183. // it munges it by duplicating all the text after the "!!" line, and appending it in commented form. ("munged")
  184. // a mirror file is activated, using a filename based on the hash from the orig text.
  185. // if there is already content on disk matching that filename, use that content *unless* the 'blitz' parameter is set.
  186. // (i.e. engine is instructing this subsystem to wipe out any old/modified variants of the text)
  187. class CGLMEditableTextItem
  188. {
  189. public:
  190. CGLMEditableTextItem( char *text, uint size, bool forceOverwrite, char *prefix, char *suffix = NULL ); // create a text blob from text source, optional filename suffix
  191. ~CGLMEditableTextItem( );
  192. bool HasData( void );
  193. bool PollForChanges( void ); // return true if stale i.e. you need to get a new edition
  194. void GetCurrentText( char **textOut, uint *sizeOut ); // query for read access to the active blob (could be the original, could be external edited copy)
  195. void OpenInEditor( bool foreground=false ); // call user attention to this text
  196. // internal methods
  197. void GenHashOfOrigText( void );
  198. void GenBaseNameAndFullPath( char *prefix, char *suffix );
  199. void GenMungedText( bool fromMirror );
  200. // members
  201. // orig
  202. uint m_origSize;
  203. char *m_origText; // what was submitted
  204. unsigned char m_origDigest[MD5_DIGEST_LENGTH]; // digest of what was submitted
  205. // munged
  206. uint m_mungedSize;
  207. char *m_mungedText; // re-processed edition, initial content submission to the file mirror
  208. // mirror
  209. char *m_mirrorBaseName; // generated from the hash of the orig text, plus the label / prefix
  210. char *m_mirrorFullPath; // base name
  211. CGLMFileMirror *m_mirror; // file mirror itself. holds "official" copy for GetCurrentText to return.
  212. };
  213. // debug font
  214. extern unsigned char g_glmDebugFontMap[16384];
  215. // class for cracking multi-part text blobs
  216. // sections are demarcated by beginning-of-line markers submitted in a table by the caller
  217. struct GLMTextSection
  218. {
  219. int m_markerIndex; // based on table of markers passed in to constructor
  220. uint m_textOffset; // where is the text - offset
  221. int m_textLength; // how big is the section
  222. };
  223. class CGLMTextSectioner
  224. {
  225. public:
  226. CGLMTextSectioner( char *text, int textSize, const char **markers ); // constructor finds all the sections
  227. ~CGLMTextSectioner( );
  228. int Count( void ); // how many sections found
  229. void GetSection( int index, uint *offsetOut, uint *lengthOut, int *markerIndexOut );
  230. // find section, size, what marker
  231. // note that more than one section can be marked similarly.
  232. // so policy isn't made here, you walk the sections and decide what to do if there are dupes.
  233. //members
  234. //section table
  235. CUtlVector< GLMTextSection > m_sectionTable;
  236. };
  237. #ifndef OSX
  238. void GLMGPUTimestampManagerInit();
  239. void GLMGPUTimestampManagerDeinit();
  240. void GLMGPUTimestampManagerTick();
  241. #endif
  242. #endif // GLMBASICS_H