GraphicsAPIWrapper.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __GRAPHICSAPIWRAPPER_H__
  21. #define __GRAPHICSAPIWRAPPER_H__
  22. /*
  23. ================================================================================================
  24. Graphics API wrapper/helper functions
  25. This wraps platform specific graphics API functionality that is used at run-time. This
  26. functionality is wrapped to avoid excessive conditional compilation and/or code duplication
  27. throughout the run-time rendering code that is shared on all platforms.
  28. Most other graphics API functions are called for initialization purposes and are called
  29. directly from platform specific code implemented in files in the platform specific folders:
  30. renderer/OpenGL/
  31. renderer/DirectX/
  32. renderer/GCM/
  33. ================================================================================================
  34. */
  35. class idImage;
  36. //class idTriangles;
  37. class idRenderModelSurface;
  38. class idDeclRenderProg;
  39. class idRenderTexture;
  40. static const int MAX_OCCLUSION_QUERIES = 4096;
  41. // returned by GL_GetDeferredQueryResult() when the query is from too long ago and the result is no longer available
  42. static const int OCCLUSION_QUERY_TOO_OLD = -1;
  43. /*
  44. ================================================================================================
  45. Platform Specific Context
  46. ================================================================================================
  47. */
  48. #define USE_CORE_PROFILE
  49. struct wrapperContext_t {
  50. };
  51. /*
  52. ================================================
  53. wrapperConfig_t
  54. ================================================
  55. */
  56. struct wrapperConfig_t {
  57. // rendering options and settings
  58. bool disableStateCaching;
  59. bool lazyBindPrograms;
  60. bool lazyBindParms;
  61. bool lazyBindTextures;
  62. bool stripFragmentBranches;
  63. bool skipDetailTris;
  64. bool singleTriangle;
  65. // values for polygon offset
  66. float polyOfsFactor;
  67. float polyOfsUnits;
  68. // global texture filter settings
  69. int textureMinFilter;
  70. int textureMaxFilter;
  71. int textureMipFilter;
  72. float textureAnisotropy;
  73. float textureLODBias;
  74. };
  75. /*
  76. ================================================
  77. wrapperStats_t
  78. ================================================
  79. */
  80. struct wrapperStats_t {
  81. int c_queriesIssued;
  82. int c_queriesPassed;
  83. int c_queriesWaitTime;
  84. int c_queriesTooOld;
  85. int c_programsBound;
  86. int c_drawElements;
  87. int c_drawIndices;
  88. int c_drawVertices;
  89. };
  90. /*
  91. ================================================================================================
  92. API
  93. ================================================================================================
  94. */
  95. void GL_SetWrapperContext( const wrapperContext_t & context );
  96. void GL_SetWrapperConfig( const wrapperConfig_t & config );
  97. void GL_SetTimeDelta( uint64 delta ); // delta from GPU to CPU microseconds
  98. void GL_StartFrame( int frame ); // inserts a timing mark for the start of the GPU frame
  99. void GL_EndFrame(); // inserts a timing mark for the end of the GPU frame
  100. void GL_WaitForEndFrame(); // wait for the GPU to reach the last end frame marker
  101. void GL_GetLastFrameTime( uint64 & startGPUTimeMicroSec, uint64 & endGPUTimeMicroSec ); // GPU time between GL_StartFrame() and GL_EndFrame()
  102. void GL_StartDepthPass( const idScreenRect & rect );
  103. void GL_FinishDepthPass();
  104. void GL_GetDepthPassRect( idScreenRect & rect );
  105. void GL_SetDefaultState();
  106. void GL_State( uint64 stateVector, bool forceGlState = false );
  107. uint64 GL_GetCurrentState();
  108. uint64 GL_GetCurrentStateMinusStencil();
  109. void GL_Cull( int cullType );
  110. void GL_Scissor( int x /* left*/, int y /* bottom */, int w, int h );
  111. void GL_Viewport( int x /* left */, int y /* bottom */, int w, int h );
  112. ID_INLINE void GL_Scissor( const idScreenRect & rect ) { GL_Scissor( rect.x1, rect.y1, rect.x2 - rect.x1 + 1, rect.y2 - rect.y1 + 1 ); }
  113. ID_INLINE void GL_Viewport( const idScreenRect & rect ) { GL_Viewport( rect.x1, rect.y1, rect.x2 - rect.x1 + 1, rect.y2 - rect.y1 + 1 ); }
  114. ID_INLINE void GL_ViewportAndScissor( int x, int y, int w, int h ) { GL_Viewport( x, y, w, h ); GL_Scissor( x, y, w, h ); }
  115. ID_INLINE void GL_ViewportAndScissor( const idScreenRect& rect ) { GL_Viewport( rect ); GL_Scissor( rect ); }
  116. void GL_Clear( bool color, bool depth, bool stencil, byte stencilValue, float r, float g, float b, float a );
  117. void GL_PolygonOffset( float scale, float bias );
  118. void GL_DepthBoundsTest( const float zmin, const float zmax );
  119. void GL_Color( float * color );
  120. void GL_Color( float r, float g, float b );
  121. void GL_Color( float r, float g, float b, float a );
  122. void GL_SelectTexture( int unit );
  123. void GL_Flush(); // flush the GPU command buffer
  124. void GL_Finish(); // wait for the GPU to have executed all commands
  125. void GL_CheckErrors();
  126. wrapperStats_t GL_GetCurrentStats();
  127. void GL_ClearStats();
  128. #endif // !__GRAPHICSAPIWRAPPER_H__