RenderSystem.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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 __RENDERER_H__
  21. #define __RENDERER_H__
  22. /*
  23. ===============================================================================
  24. idRenderSystem is responsible for managing the screen, which can have
  25. multiple idRenderWorld and 2D drawing done on it.
  26. ===============================================================================
  27. */
  28. enum stereo3DMode_t {
  29. STEREO3D_OFF,
  30. // half-resolution, non-square pixel views
  31. STEREO3D_SIDE_BY_SIDE_COMPRESSED,
  32. STEREO3D_TOP_AND_BOTTOM_COMPRESSED,
  33. // two full resolution views side by side, as for a dual cable display
  34. STEREO3D_SIDE_BY_SIDE,
  35. STEREO3D_INTERLACED,
  36. // OpenGL quad buffer
  37. STEREO3D_QUAD_BUFFER,
  38. // two full resolution views stacked with a 30 pixel guard band
  39. // On the PC this can be configured as a custom video timing, but
  40. // it definitely isn't a consumer level task. The quad_buffer
  41. // support can handle 720P-3D with apropriate driver support.
  42. STEREO3D_HDMI_720
  43. };
  44. typedef enum {
  45. AUTORENDER_DEFAULTICON = 0,
  46. AUTORENDER_HELLICON,
  47. AUTORENDER_DIALOGICON,
  48. AUTORENDER_MAX
  49. } autoRenderIconType_t ;
  50. enum stereoDepthType_t {
  51. STEREO_DEPTH_TYPE_NONE,
  52. STEREO_DEPTH_TYPE_NEAR,
  53. STEREO_DEPTH_TYPE_MID,
  54. STEREO_DEPTH_TYPE_FAR
  55. };
  56. enum graphicsVendor_t {
  57. VENDOR_NVIDIA,
  58. VENDOR_AMD,
  59. VENDOR_INTEL
  60. };
  61. // Contains variables specific to the OpenGL configuration being run right now.
  62. // These are constant once the OpenGL subsystem is initialized.
  63. struct glconfig_t {
  64. const char * renderer_string;
  65. const char * vendor_string;
  66. const char * version_string;
  67. const char * extensions_string;
  68. const char * wgl_extensions_string;
  69. const char * shading_language_string;
  70. float glVersion; // atof( version_string )
  71. graphicsVendor_t vendor;
  72. int maxTextureSize; // queried from GL
  73. int maxTextureCoords;
  74. int maxTextureImageUnits;
  75. int uniformBufferOffsetAlignment;
  76. float maxTextureAnisotropy;
  77. int colorBits;
  78. int depthBits;
  79. int stencilBits;
  80. bool multitextureAvailable;
  81. bool directStateAccess;
  82. bool textureCompressionAvailable;
  83. bool anisotropicFilterAvailable;
  84. bool textureLODBiasAvailable;
  85. bool seamlessCubeMapAvailable;
  86. bool sRGBFramebufferAvailable;
  87. bool vertexBufferObjectAvailable;
  88. bool mapBufferRangeAvailable;
  89. bool vertexArrayObjectAvailable;
  90. bool drawElementsBaseVertexAvailable;
  91. bool fragmentProgramAvailable;
  92. bool glslAvailable;
  93. bool uniformBufferAvailable;
  94. bool twoSidedStencilAvailable;
  95. bool depthBoundsTestAvailable;
  96. bool syncAvailable;
  97. bool timerQueryAvailable;
  98. bool occlusionQueryAvailable;
  99. bool debugOutputAvailable;
  100. bool swapControlTearAvailable;
  101. stereo3DMode_t stereo3Dmode;
  102. int nativeScreenWidth; // this is the native screen width resolution of the renderer
  103. int nativeScreenHeight; // this is the native screen height resolution of the renderer
  104. int displayFrequency;
  105. int isFullscreen; // monitor number
  106. bool isStereoPixelFormat;
  107. bool stereoPixelFormatAvailable;
  108. int multisamples;
  109. // Screen separation for stereoscopic rendering is set based on this.
  110. // PC vid code sets this, converting from diagonals / inches / whatever as needed.
  111. // If the value can't be determined, set something reasonable, like 50cm.
  112. float physicalScreenWidthInCentimeters;
  113. float pixelAspect;
  114. GLuint global_vao;
  115. };
  116. struct emptyCommand_t;
  117. bool R_IsInitialized();
  118. const int SMALLCHAR_WIDTH = 8;
  119. const int SMALLCHAR_HEIGHT = 16;
  120. const int BIGCHAR_WIDTH = 16;
  121. const int BIGCHAR_HEIGHT = 16;
  122. // all drawing is done to a 640 x 480 virtual screen size
  123. // and will be automatically scaled to the real resolution
  124. const int SCREEN_WIDTH = 640;
  125. const int SCREEN_HEIGHT = 480;
  126. const int TITLESAFE_LEFT = 32;
  127. const int TITLESAFE_RIGHT = 608;
  128. const int TITLESAFE_TOP = 24;
  129. const int TITLESAFE_BOTTOM = 456;
  130. const int TITLESAFE_WIDTH = TITLESAFE_RIGHT - TITLESAFE_LEFT;
  131. const int TITLESAFE_HEIGHT = TITLESAFE_BOTTOM - TITLESAFE_TOP;
  132. class idRenderWorld;
  133. class idRenderSystem {
  134. public:
  135. virtual ~idRenderSystem() {}
  136. // set up cvars and basic data structures, but don't
  137. // init OpenGL, so it can also be used for dedicated servers
  138. virtual void Init() = 0;
  139. // only called before quitting
  140. virtual void Shutdown() = 0;
  141. virtual void ResetGuiModels() = 0;
  142. virtual void InitOpenGL() = 0;
  143. virtual void ShutdownOpenGL() = 0;
  144. virtual bool IsOpenGLRunning() const = 0;
  145. virtual bool IsFullScreen() const = 0;
  146. virtual int GetWidth() const = 0;
  147. virtual int GetHeight() const = 0;
  148. // return w/h of a single pixel. This will be 1.0 for normal cases.
  149. // A side-by-side stereo 3D frame will have a pixel aspect of 0.5.
  150. // A top-and-bottom stereo 3D frame will have a pixel aspect of 2.0
  151. virtual float GetPixelAspect() const = 0;
  152. // This is used to calculate stereoscopic screen offset for a given interocular distance.
  153. virtual float GetPhysicalScreenWidthInCentimeters() const = 0;
  154. // GetWidth() / GetHeight() return the size of a single eye
  155. // view, which may be replicated twice in a stereo display
  156. virtual stereo3DMode_t GetStereo3DMode() const = 0;
  157. virtual bool IsStereoScopicRenderingSupported() const = 0;
  158. virtual stereo3DMode_t GetStereoScopicRenderingMode() const = 0;
  159. virtual void EnableStereoScopicRendering( const stereo3DMode_t mode ) const = 0;
  160. virtual bool HasQuadBufferSupport() const = 0;
  161. // allocate a renderWorld to be used for drawing
  162. virtual idRenderWorld * AllocRenderWorld() = 0;
  163. virtual void FreeRenderWorld( idRenderWorld * rw ) = 0;
  164. // All data that will be used in a level should be
  165. // registered before rendering any frames to prevent disk hits,
  166. // but they can still be registered at a later time
  167. // if necessary.
  168. virtual void BeginLevelLoad() = 0;
  169. virtual void EndLevelLoad() = 0;
  170. virtual void Preload( const idPreloadManifest &manifest, const char *mapName ) = 0;
  171. virtual void LoadLevelImages() = 0;
  172. virtual void BeginAutomaticBackgroundSwaps( autoRenderIconType_t icon = AUTORENDER_DEFAULTICON ) = 0;
  173. virtual void EndAutomaticBackgroundSwaps() = 0;
  174. virtual bool AreAutomaticBackgroundSwapsRunning( autoRenderIconType_t * icon = NULL ) const = 0;
  175. // font support
  176. virtual class idFont * RegisterFont( const char * fontName ) = 0;
  177. virtual void ResetFonts() = 0;
  178. virtual void SetColor( const idVec4 & rgba ) = 0;
  179. virtual void SetColor4( float r, float g, float b, float a ) { SetColor( idVec4( r, g, b, a ) ); }
  180. virtual uint32 GetColor() = 0;
  181. virtual void SetGLState( const uint64 glState ) = 0;
  182. virtual void DrawFilled( const idVec4 & color, float x, float y, float w, float h ) = 0;
  183. virtual void DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, const idMaterial *material ) = 0;
  184. void DrawStretchPic( const idVec4 & rect, const idVec4 & st, const idMaterial * material ) { DrawStretchPic( rect.x, rect.y, rect.z, rect.w, st.x, st.y, st.z, st.w, material ); }
  185. virtual void DrawStretchPic( const idVec4 & topLeft, const idVec4 & topRight, const idVec4 & bottomRight, const idVec4 & bottomLeft, const idMaterial * material ) = 0;
  186. virtual void DrawStretchTri ( const idVec2 & p1, const idVec2 & p2, const idVec2 & p3, const idVec2 & t1, const idVec2 & t2, const idVec2 & t3, const idMaterial *material ) = 0;
  187. virtual idDrawVert * AllocTris( int numVerts, const triIndex_t * indexes, int numIndexes, const idMaterial * material, const stereoDepthType_t stereoType = STEREO_DEPTH_TYPE_NONE ) = 0;
  188. virtual void PrintMemInfo( MemInfo_t *mi ) = 0;
  189. virtual void DrawSmallChar( int x, int y, int ch ) = 0;
  190. virtual void DrawSmallStringExt( int x, int y, const char *string, const idVec4 &setColor, bool forceColor ) = 0;
  191. virtual void DrawBigChar( int x, int y, int ch ) = 0;
  192. virtual void DrawBigStringExt( int x, int y, const char *string, const idVec4 &setColor, bool forceColor ) = 0;
  193. // dump all 2D drawing so far this frame to the demo file
  194. virtual void WriteDemoPics() = 0;
  195. // draw the 2D pics that were saved out with the current demo frame
  196. virtual void DrawDemoPics() = 0;
  197. // Performs final closeout of any gui models being defined.
  198. //
  199. // Waits for the previous GPU rendering to complete and vsync.
  200. //
  201. // Returns the head of the linked command list that was just closed off.
  202. //
  203. // Returns timing information from the previous frame.
  204. //
  205. // After this is called, new command buffers can be built up in parallel
  206. // with the rendering of the closed off command buffers by RenderCommandBuffers()
  207. virtual const emptyCommand_t * SwapCommandBuffers( uint64 *frontEndMicroSec, uint64 *backEndMicroSec, uint64 *shadowMicroSec, uint64 *gpuMicroSec ) = 0;
  208. // SwapCommandBuffers operation can be split in two parts for non-smp rendering
  209. // where the GPU is idled intentionally for minimal latency.
  210. virtual void SwapCommandBuffers_FinishRendering( uint64 *frontEndMicroSec, uint64 *backEndMicroSec, uint64 *shadowMicroSec, uint64 *gpuMicroSec ) = 0;
  211. virtual const emptyCommand_t * SwapCommandBuffers_FinishCommandBuffers() = 0;
  212. // issues GPU commands to render a built up list of command buffers returned
  213. // by SwapCommandBuffers(). No references should be made to the current frameData,
  214. // so new scenes and GUIs can be built up in parallel with the rendering.
  215. virtual void RenderCommandBuffers( const emptyCommand_t * commandBuffers ) = 0;
  216. // aviDemo uses this.
  217. // Will automatically tile render large screen shots if necessary
  218. // Samples is the number of jittered frames for anti-aliasing
  219. // If ref == NULL, common->UpdateScreen will be used
  220. // This will perform swapbuffers, so it is NOT an approppriate way to
  221. // generate image files that happen during gameplay, as for savegame
  222. // markers. Use WriteRender() instead.
  223. virtual void TakeScreenshot( int width, int height, const char *fileName, int samples, struct renderView_s *ref ) = 0;
  224. // the render output can be cropped down to a subset of the real screen, as
  225. // for save-game reviews and split-screen multiplayer. Users of the renderer
  226. // will not know the actual pixel size of the area they are rendering to
  227. // the x,y,width,height values are in virtual SCREEN_WIDTH / SCREEN_HEIGHT coordinates
  228. // to render to a texture, first set the crop size with makePowerOfTwo = true,
  229. // then perform all desired rendering, then capture to an image
  230. // if the specified physical dimensions are larger than the current cropped region, they will be cut down to fit
  231. virtual void CropRenderSize( int width, int height ) = 0;
  232. virtual void CaptureRenderToImage( const char *imageName, bool clearColorAfterCopy = false ) = 0;
  233. // fixAlpha will set all the alpha channel values to 0xff, which allows screen captures
  234. // to use the default tga loading code without having dimmed down areas in many places
  235. virtual void CaptureRenderToFile( const char *fileName, bool fixAlpha = false ) = 0;
  236. virtual void UnCrop() = 0;
  237. // the image has to be already loaded ( most straightforward way would be through a FindMaterial )
  238. // texture filter / mipmapping / repeat won't be modified by the upload
  239. // returns false if the image wasn't found
  240. virtual bool UploadImage( const char *imageName, const byte *data, int width, int height ) = 0;
  241. // consoles switch stereo 3D eye views each 60 hz frame
  242. virtual int GetFrameCount() const = 0;
  243. };
  244. extern idRenderSystem * renderSystem;
  245. //
  246. // functions mainly intended for editor and dmap integration
  247. //
  248. // for use by dmap to do the carving-on-light-boundaries and for the editor for display
  249. void R_LightProjectionMatrix( const idVec3 &origin, const idPlane &rearPlane, idVec4 mat[4] );
  250. // used by the view shot taker
  251. void R_ScreenshotFilename( int &lastNumber, const char *base, idStr &fileName );
  252. #endif /* !__RENDERER_H__ */