RenderSystem.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 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 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. // Contains variables specific to the OpenGL configuration being run right now.
  29. // These are constant once the OpenGL subsystem is initialized.
  30. typedef struct glconfig_s {
  31. const char *renderer_string;
  32. const char *vendor_string;
  33. const char *version_string;
  34. const char *extensions_string;
  35. const char *wgl_extensions_string;
  36. float glVersion; // atof( version_string )
  37. int maxTextureSize; // queried from GL
  38. int maxTextureUnits;
  39. int maxTextureCoords;
  40. int maxTextureImageUnits;
  41. float maxTextureAnisotropy;
  42. int colorBits, depthBits, stencilBits;
  43. bool multitextureAvailable;
  44. bool textureCompressionAvailable;
  45. bool anisotropicAvailable;
  46. bool textureLODBiasAvailable;
  47. bool textureEnvAddAvailable;
  48. bool textureEnvCombineAvailable;
  49. bool registerCombinersAvailable;
  50. bool cubeMapAvailable;
  51. bool envDot3Available;
  52. bool texture3DAvailable;
  53. bool sharedTexturePaletteAvailable;
  54. bool ARBVertexBufferObjectAvailable;
  55. bool ARBVertexProgramAvailable;
  56. bool ARBFragmentProgramAvailable;
  57. bool twoSidedStencilAvailable;
  58. bool textureNonPowerOfTwoAvailable;
  59. bool depthBoundsTestAvailable;
  60. // ati r200 extensions
  61. bool atiFragmentShaderAvailable;
  62. // ati r300
  63. bool atiTwoSidedStencilAvailable;
  64. int vidWidth, vidHeight; // passed to R_BeginFrame
  65. int displayFrequency;
  66. bool isFullscreen;
  67. bool allowNV30Path;
  68. bool allowNV20Path;
  69. bool allowNV10Path;
  70. bool allowR200Path;
  71. bool allowARB2Path;
  72. bool isInitialized;
  73. } glconfig_t;
  74. // font support
  75. const int GLYPH_START = 0;
  76. const int GLYPH_END = 255;
  77. const int GLYPH_CHARSTART = 32;
  78. const int GLYPH_CHAREND = 127;
  79. const int GLYPHS_PER_FONT = GLYPH_END - GLYPH_START + 1;
  80. typedef struct {
  81. int height; // number of scan lines
  82. int top; // top of glyph in buffer
  83. int bottom; // bottom of glyph in buffer
  84. int pitch; // width for copying
  85. int xSkip; // x adjustment
  86. int imageWidth; // width of actual image
  87. int imageHeight; // height of actual image
  88. float s; // x offset in image where glyph starts
  89. float t; // y offset in image where glyph starts
  90. float s2;
  91. float t2;
  92. const idMaterial * glyph; // shader with the glyph
  93. char shaderName[32];
  94. } glyphInfo_t;
  95. typedef struct {
  96. glyphInfo_t glyphs [GLYPHS_PER_FONT];
  97. float glyphScale;
  98. char name[64];
  99. } fontInfo_t;
  100. typedef struct {
  101. fontInfo_t fontInfoSmall;
  102. fontInfo_t fontInfoMedium;
  103. fontInfo_t fontInfoLarge;
  104. int maxHeight;
  105. int maxWidth;
  106. int maxHeightSmall;
  107. int maxWidthSmall;
  108. int maxHeightMedium;
  109. int maxWidthMedium;
  110. int maxHeightLarge;
  111. int maxWidthLarge;
  112. char name[64];
  113. } fontInfoEx_t;
  114. const int SMALLCHAR_WIDTH = 8;
  115. const int SMALLCHAR_HEIGHT = 16;
  116. const int BIGCHAR_WIDTH = 16;
  117. const int BIGCHAR_HEIGHT = 16;
  118. // all drawing is done to a 640 x 480 virtual screen size
  119. // and will be automatically scaled to the real resolution
  120. const int SCREEN_WIDTH = 640;
  121. const int SCREEN_HEIGHT = 480;
  122. class idRenderWorld;
  123. class idRenderSystem {
  124. public:
  125. virtual ~idRenderSystem() {}
  126. // set up cvars and basic data structures, but don't
  127. // init OpenGL, so it can also be used for dedicated servers
  128. virtual void Init( void ) = 0;
  129. // only called before quitting
  130. virtual void Shutdown( void ) = 0;
  131. virtual void InitOpenGL( void ) = 0;
  132. virtual void ShutdownOpenGL( void ) = 0;
  133. virtual bool IsOpenGLRunning( void ) const = 0;
  134. virtual bool IsFullScreen( void ) const = 0;
  135. virtual int GetScreenWidth( void ) const = 0;
  136. virtual int GetScreenHeight( void ) const = 0;
  137. // allocate a renderWorld to be used for drawing
  138. virtual idRenderWorld * AllocRenderWorld( void ) = 0;
  139. virtual void FreeRenderWorld( idRenderWorld * rw ) = 0;
  140. // All data that will be used in a level should be
  141. // registered before rendering any frames to prevent disk hits,
  142. // but they can still be registered at a later time
  143. // if necessary.
  144. virtual void BeginLevelLoad( void ) = 0;
  145. virtual void EndLevelLoad( void ) = 0;
  146. // font support
  147. virtual bool RegisterFont( const char *fontName, fontInfoEx_t &font ) = 0;
  148. // GUI drawing just involves shader parameter setting and axial image subsections
  149. virtual void SetColor( const idVec4 &rgba ) = 0;
  150. virtual void SetColor4( float r, float g, float b, float a ) = 0;
  151. virtual void DrawStretchPic( const idDrawVert *verts, const glIndex_t *indexes, int vertCount, int indexCount, const idMaterial *material,
  152. bool clip = true, float min_x = 0.0f, float min_y = 0.0f, float max_x = 640.0f, float max_y = 480.0f ) = 0;
  153. virtual void DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, const idMaterial *material ) = 0;
  154. virtual void DrawStretchTri ( idVec2 p1, idVec2 p2, idVec2 p3, idVec2 t1, idVec2 t2, idVec2 t3, const idMaterial *material ) = 0;
  155. virtual void GlobalToNormalizedDeviceCoordinates( const idVec3 &global, idVec3 &ndc ) = 0;
  156. virtual void GetGLSettings( int& width, int& height ) = 0;
  157. virtual void PrintMemInfo( MemInfo_t *mi ) = 0;
  158. virtual void DrawSmallChar( int x, int y, int ch, const idMaterial *material ) = 0;
  159. virtual void DrawSmallStringExt( int x, int y, const char *string, const idVec4 &setColor, bool forceColor, const idMaterial *material ) = 0;
  160. virtual void DrawBigChar( int x, int y, int ch, const idMaterial *material ) = 0;
  161. virtual void DrawBigStringExt( int x, int y, const char *string, const idVec4 &setColor, bool forceColor, const idMaterial *material ) = 0;
  162. // dump all 2D drawing so far this frame to the demo file
  163. virtual void WriteDemoPics() = 0;
  164. // draw the 2D pics that were saved out with the current demo frame
  165. virtual void DrawDemoPics() = 0;
  166. // FIXME: add an interface for arbitrary point/texcoord drawing
  167. // a frame cam consist of 2D drawing and potentially multiple 3D scenes
  168. // window sizes are needed to convert SCREEN_WIDTH / SCREEN_HEIGHT values
  169. virtual void BeginFrame( int windowWidth, int windowHeight ) = 0;
  170. // if the pointers are not NULL, timing info will be returned
  171. virtual void EndFrame( int *frontEndMsec, int *backEndMsec ) = 0;
  172. // aviDemo uses this.
  173. // Will automatically tile render large screen shots if necessary
  174. // Samples is the number of jittered frames for anti-aliasing
  175. // If ref == NULL, session->updateScreen will be used
  176. // This will perform swapbuffers, so it is NOT an approppriate way to
  177. // generate image files that happen during gameplay, as for savegame
  178. // markers. Use WriteRender() instead.
  179. virtual void TakeScreenshot( int width, int height, const char *fileName, int samples, struct renderView_s *ref ) = 0;
  180. // the render output can be cropped down to a subset of the real screen, as
  181. // for save-game reviews and split-screen multiplayer. Users of the renderer
  182. // will not know the actual pixel size of the area they are rendering to
  183. // the x,y,width,height values are in virtual SCREEN_WIDTH / SCREEN_HEIGHT coordinates
  184. // to render to a texture, first set the crop size with makePowerOfTwo = true,
  185. // then perform all desired rendering, then capture to an image
  186. // if the specified physical dimensions are larger than the current cropped region, they will be cut down to fit
  187. virtual void CropRenderSize( int width, int height, bool makePowerOfTwo = false, bool forceDimensions = false ) = 0;
  188. virtual void CaptureRenderToImage( const char *imageName ) = 0;
  189. // fixAlpha will set all the alpha channel values to 0xff, which allows screen captures
  190. // to use the default tga loading code without having dimmed down areas in many places
  191. virtual void CaptureRenderToFile( const char *fileName, bool fixAlpha = false ) = 0;
  192. virtual void UnCrop() = 0;
  193. virtual void GetCardCaps( bool &oldCard, bool &nv10or20 ) = 0;
  194. // the image has to be already loaded ( most straightforward way would be through a FindMaterial )
  195. // texture filter / mipmapping / repeat won't be modified by the upload
  196. // returns false if the image wasn't found
  197. virtual bool UploadImage( const char *imageName, const byte *data, int width, int height ) = 0;
  198. };
  199. extern idRenderSystem * renderSystem;
  200. //
  201. // functions mainly intended for editor and dmap integration
  202. //
  203. // returns the frustum planes in world space
  204. void R_RenderLightFrustum( const struct renderLight_s &renderLight, idPlane lightFrustum[6] );
  205. // for use by dmap to do the carving-on-light-boundaries and for the editor for display
  206. void R_LightProjectionMatrix( const idVec3 &origin, const idPlane &rearPlane, idVec4 mat[4] );
  207. // used by the view shot taker
  208. void R_ScreenshotFilename( int &lastNumber, const char *base, idStr &fileName );
  209. #endif /* !__RENDERER_H__ */