doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RenderSystem.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 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.
23 
24 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.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __RENDERER_H__
30 #define __RENDERER_H__
31 
32 /*
33 ===============================================================================
34 
35  idRenderSystem is responsible for managing the screen, which can have
36  multiple idRenderWorld and 2D drawing done on it.
37 
38 ===============================================================================
39 */
40 
41 
42 // Contains variables specific to the OpenGL configuration being run right now.
43 // These are constant once the OpenGL subsystem is initialized.
44 typedef struct glconfig_s {
45  const char *renderer_string;
46  const char *vendor_string;
47  const char *version_string;
48  const char *extensions_string;
49  const char *wgl_extensions_string;
50 
51  float glVersion; // atof( version_string )
52 
53 
54  int maxTextureSize; // queried from GL
59 
61 
79 
80  // ati r200 extensions
82 
83  // ati r300
85 
86  int vidWidth, vidHeight; // passed to R_BeginFrame
87 
89 
91 
97 
99 } glconfig_t;
100 
101 
102 // font support
103 const int GLYPH_START = 0;
104 const int GLYPH_END = 255;
105 const int GLYPH_CHARSTART = 32;
106 const int GLYPH_CHAREND = 127;
108 
109 typedef struct {
110  int height; // number of scan lines
111  int top; // top of glyph in buffer
112  int bottom; // bottom of glyph in buffer
113  int pitch; // width for copying
114  int xSkip; // x adjustment
115  int imageWidth; // width of actual image
116  int imageHeight; // height of actual image
117  float s; // x offset in image where glyph starts
118  float t; // y offset in image where glyph starts
119  float s2;
120  float t2;
121  const idMaterial * glyph; // shader with the glyph
122  char shaderName[32];
123 } glyphInfo_t;
124 
125 typedef struct {
127  float glyphScale;
128  char name[64];
129 } fontInfo_t;
130 
131 typedef struct {
136  int maxWidth;
143  char name[64];
144 } fontInfoEx_t;
145 
146 const int SMALLCHAR_WIDTH = 8;
147 const int SMALLCHAR_HEIGHT = 16;
148 const int BIGCHAR_WIDTH = 16;
149 const int BIGCHAR_HEIGHT = 16;
150 
151 // all drawing is done to a 640 x 480 virtual screen size
152 // and will be automatically scaled to the real resolution
153 const int SCREEN_WIDTH = 640;
154 const int SCREEN_HEIGHT = 480;
155 
156 class idRenderWorld;
157 
158 
160 public:
161 
162  virtual ~idRenderSystem() {}
163 
164  // set up cvars and basic data structures, but don't
165  // init OpenGL, so it can also be used for dedicated servers
166  virtual void Init( void ) = 0;
167 
168  // only called before quitting
169  virtual void Shutdown( void ) = 0;
170 
171  virtual void InitOpenGL( void ) = 0;
172 
173  virtual void ShutdownOpenGL( void ) = 0;
174 
175  virtual bool IsOpenGLRunning( void ) const = 0;
176 
177  virtual bool IsFullScreen( void ) const = 0;
178  virtual int GetScreenWidth( void ) const = 0;
179  virtual int GetScreenHeight( void ) const = 0;
180 
181  // allocate a renderWorld to be used for drawing
182  virtual idRenderWorld * AllocRenderWorld( void ) = 0;
183  virtual void FreeRenderWorld( idRenderWorld * rw ) = 0;
184 
185  // All data that will be used in a level should be
186  // registered before rendering any frames to prevent disk hits,
187  // but they can still be registered at a later time
188  // if necessary.
189  virtual void BeginLevelLoad( void ) = 0;
190  virtual void EndLevelLoad( void ) = 0;
191 
192  // font support
193  virtual bool RegisterFont( const char *fontName, fontInfoEx_t &font ) = 0;
194 
195  // GUI drawing just involves shader parameter setting and axial image subsections
196  virtual void SetColor( const idVec4 &rgba ) = 0;
197  virtual void SetColor4( float r, float g, float b, float a ) = 0;
198 
199  virtual void DrawStretchPic( const idDrawVert *verts, const glIndex_t *indexes, int vertCount, int indexCount, const idMaterial *material,
200  bool clip = true, float min_x = 0.0f, float min_y = 0.0f, float max_x = 640.0f, float max_y = 480.0f ) = 0;
201  virtual void DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, const idMaterial *material ) = 0;
202 
203  virtual void DrawStretchTri ( idVec2 p1, idVec2 p2, idVec2 p3, idVec2 t1, idVec2 t2, idVec2 t3, const idMaterial *material ) = 0;
204  virtual void GlobalToNormalizedDeviceCoordinates( const idVec3 &global, idVec3 &ndc ) = 0;
205  virtual void GetGLSettings( int& width, int& height ) = 0;
206  virtual void PrintMemInfo( MemInfo_t *mi ) = 0;
207 
208  virtual void DrawSmallChar( int x, int y, int ch, const idMaterial *material ) = 0;
209  virtual void DrawSmallStringExt( int x, int y, const char *string, const idVec4 &setColor, bool forceColor, const idMaterial *material ) = 0;
210  virtual void DrawBigChar( int x, int y, int ch, const idMaterial *material ) = 0;
211  virtual void DrawBigStringExt( int x, int y, const char *string, const idVec4 &setColor, bool forceColor, const idMaterial *material ) = 0;
212 
213  // dump all 2D drawing so far this frame to the demo file
214  virtual void WriteDemoPics() = 0;
215 
216  // draw the 2D pics that were saved out with the current demo frame
217  virtual void DrawDemoPics() = 0;
218 
219  // FIXME: add an interface for arbitrary point/texcoord drawing
220 
221 
222  // a frame cam consist of 2D drawing and potentially multiple 3D scenes
223  // window sizes are needed to convert SCREEN_WIDTH / SCREEN_HEIGHT values
224  virtual void BeginFrame( int windowWidth, int windowHeight ) = 0;
225 
226  // if the pointers are not NULL, timing info will be returned
227  virtual void EndFrame( int *frontEndMsec, int *backEndMsec ) = 0;
228 
229  // aviDemo uses this.
230  // Will automatically tile render large screen shots if necessary
231  // Samples is the number of jittered frames for anti-aliasing
232  // If ref == NULL, session->updateScreen will be used
233  // This will perform swapbuffers, so it is NOT an approppriate way to
234  // generate image files that happen during gameplay, as for savegame
235  // markers. Use WriteRender() instead.
236  virtual void TakeScreenshot( int width, int height, const char *fileName, int samples, struct renderView_s *ref ) = 0;
237 
238  // the render output can be cropped down to a subset of the real screen, as
239  // for save-game reviews and split-screen multiplayer. Users of the renderer
240  // will not know the actual pixel size of the area they are rendering to
241 
242  // the x,y,width,height values are in virtual SCREEN_WIDTH / SCREEN_HEIGHT coordinates
243 
244  // to render to a texture, first set the crop size with makePowerOfTwo = true,
245  // then perform all desired rendering, then capture to an image
246  // if the specified physical dimensions are larger than the current cropped region, they will be cut down to fit
247  virtual void CropRenderSize( int width, int height, bool makePowerOfTwo = false, bool forceDimensions = false ) = 0;
248  virtual void CaptureRenderToImage( const char *imageName ) = 0;
249  // fixAlpha will set all the alpha channel values to 0xff, which allows screen captures
250  // to use the default tga loading code without having dimmed down areas in many places
251  virtual void CaptureRenderToFile( const char *fileName, bool fixAlpha = false ) = 0;
252  virtual void UnCrop() = 0;
253  virtual void GetCardCaps( bool &oldCard, bool &nv10or20 ) = 0;
254 
255  // the image has to be already loaded ( most straightforward way would be through a FindMaterial )
256  // texture filter / mipmapping / repeat won't be modified by the upload
257  // returns false if the image wasn't found
258  virtual bool UploadImage( const char *imageName, const byte *data, int width, int height ) = 0;
259 };
260 
262 
263 //
264 // functions mainly intended for editor and dmap integration
265 //
266 
267 // returns the frustum planes in world space
268 void R_RenderLightFrustum( const struct renderLight_s &renderLight, idPlane lightFrustum[6] );
269 
270 // for use by dmap to do the carving-on-light-boundaries and for the editor for display
271 void R_LightProjectionMatrix( const idVec3 &origin, const idPlane &rearPlane, idVec4 mat[4] );
272 
273 // used by the view shot taker
274 void R_ScreenshotFilename( int &lastNumber, const char *base, idStr &fileName );
275 
276 #endif /* !__RENDERER_H__ */
virtual bool IsOpenGLRunning(void) const =0
GLubyte g
Definition: glext.h:4662
virtual void UnCrop()=0
struct glconfig_s glconfig_t
virtual bool UploadImage(const char *imageName, const byte *data, int width, int height)=0
virtual void EndFrame(int *frontEndMsec, int *backEndMsec)=0
virtual void SetColor(const idVec4 &rgba)=0
const idMaterial * glyph
Definition: RenderSystem.h:121
virtual void FreeRenderWorld(idRenderWorld *rw)=0
virtual void ShutdownOpenGL(void)=0
bool allowR200Path
Definition: RenderSystem.h:95
fontInfo_t fontInfoLarge
Definition: RenderSystem.h:134
virtual void DrawDemoPics()=0
bool anisotropicAvailable
Definition: RenderSystem.h:64
bool allowARB2Path
Definition: RenderSystem.h:96
bool textureEnvCombineAvailable
Definition: RenderSystem.h:67
bool textureLODBiasAvailable
Definition: RenderSystem.h:65
float glyphScale
Definition: RenderSystem.h:127
void R_ScreenshotFilename(int &lastNumber, const char *base, idStr &fileName)
GLenum GLint GLint y
Definition: glext.h:2849
const int SCREEN_HEIGHT
Definition: RenderSystem.h:154
virtual bool RegisterFont(const char *fontName, fontInfoEx_t &font)=0
GLclampf ref
Definition: glext.h:4237
bool depthBoundsTestAvailable
Definition: RenderSystem.h:78
void R_LightProjectionMatrix(const idVec3 &origin, const idPlane &rearPlane, idVec4 mat[4])
int maxTextureSize
Definition: RenderSystem.h:54
Definition: Vector.h:316
virtual void DrawBigChar(int x, int y, int ch, const idMaterial *material)=0
virtual void GetGLSettings(int &width, int &height)=0
bool isFullscreen
Definition: RenderSystem.h:90
virtual void DrawSmallChar(int x, int y, int ch, const idMaterial *material)=0
bool allowNV20Path
Definition: RenderSystem.h:93
virtual void Init(void)=0
GLenum GLint x
Definition: glext.h:2849
virtual void BeginFrame(int windowWidth, int windowHeight)=0
fontInfo_t fontInfoMedium
Definition: RenderSystem.h:133
bool sharedTexturePaletteAvailable
Definition: RenderSystem.h:72
const int BIGCHAR_WIDTH
Definition: RenderSystem.h:148
bool texture3DAvailable
Definition: RenderSystem.h:71
bool allowNV30Path
Definition: RenderSystem.h:92
fontInfo_t fontInfoSmall
Definition: RenderSystem.h:132
virtual void BeginLevelLoad(void)=0
const char * wgl_extensions_string
Definition: RenderSystem.h:49
bool envDot3Available
Definition: RenderSystem.h:70
const int GLYPH_END
Definition: RenderSystem.h:104
int maxTextureCoords
Definition: RenderSystem.h:56
virtual void GlobalToNormalizedDeviceCoordinates(const idVec3 &global, idVec3 &ndc)=0
bool atiTwoSidedStencilAvailable
Definition: RenderSystem.h:84
const int SMALLCHAR_WIDTH
Definition: RenderSystem.h:146
virtual idRenderWorld * AllocRenderWorld(void)=0
Definition: Vector.h:52
float maxTextureAnisotropy
Definition: RenderSystem.h:58
virtual void CaptureRenderToFile(const char *fileName, bool fixAlpha=false)=0
virtual bool IsFullScreen(void) const =0
virtual void CaptureRenderToImage(const char *imageName)=0
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3454
Definition: Vector.h:808
bool ARBVertexBufferObjectAvailable
Definition: RenderSystem.h:73
const char * vendor_string
Definition: RenderSystem.h:46
virtual void DrawSmallStringExt(int x, int y, const char *string, const idVec4 &setColor, bool forceColor, const idMaterial *material)=0
virtual void PrintMemInfo(MemInfo_t *mi)=0
int glIndex_t
Definition: Model.h:52
bool multitextureAvailable
Definition: RenderSystem.h:62
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
bool ARBVertexProgramAvailable
Definition: RenderSystem.h:74
bool twoSidedStencilAvailable
Definition: RenderSystem.h:76
Definition: Plane.h:71
virtual int GetScreenWidth(void) const =0
bool registerCombinersAvailable
Definition: RenderSystem.h:68
virtual void SetColor4(float r, float g, float b, float a)=0
const char * extensions_string
Definition: RenderSystem.h:48
bool atiFragmentShaderAvailable
Definition: RenderSystem.h:81
GLenum GLsizei width
Definition: glext.h:2846
virtual int GetScreenHeight(void) const =0
virtual void InitOpenGL(void)=0
GLubyte GLubyte GLubyte a
Definition: glext.h:4662
virtual void DrawStretchPic(const idDrawVert *verts, const glIndex_t *indexes, int vertCount, int indexCount, const idMaterial *material, bool clip=true, float min_x=0.0f, float min_y=0.0f, float max_x=640.0f, float max_y=480.0f)=0
const int GLYPH_CHARSTART
Definition: RenderSystem.h:105
GLenum GLsizei GLsizei height
Definition: glext.h:2856
const char * renderer_string
Definition: RenderSystem.h:45
bool allowNV10Path
Definition: RenderSystem.h:94
virtual void DrawBigStringExt(int x, int y, const char *string, const idVec4 &setColor, bool forceColor, const idMaterial *material)=0
const int BIGCHAR_HEIGHT
Definition: RenderSystem.h:149
virtual void EndLevelLoad(void)=0
GLubyte GLubyte b
Definition: glext.h:4662
float glVersion
Definition: RenderSystem.h:51
bool cubeMapAvailable
Definition: RenderSystem.h:69
GLdouble GLdouble GLdouble r
Definition: glext.h:2951
void R_RenderLightFrustum(const struct renderLight_s &renderLight, idPlane lightFrustum[6])
bool textureCompressionAvailable
Definition: RenderSystem.h:63
const int SCREEN_WIDTH
Definition: RenderSystem.h:153
int displayFrequency
Definition: RenderSystem.h:88
tuple f
Definition: idal.py:89
int maxTextureImageUnits
Definition: RenderSystem.h:57
const char * version_string
Definition: RenderSystem.h:47
bool textureEnvAddAvailable
Definition: RenderSystem.h:66
unsigned char byte
Definition: Lib.h:75
const GLcharARB * name
Definition: glext.h:3629
virtual void Shutdown(void)=0
Definition: Str.h:116
const int SMALLCHAR_HEIGHT
Definition: RenderSystem.h:147
int maxTextureUnits
Definition: RenderSystem.h:55
const int GLYPHS_PER_FONT
Definition: RenderSystem.h:107
idRenderSystem * renderSystem
virtual void GetCardCaps(bool &oldCard, bool &nv10or20)=0
virtual void CropRenderSize(int width, int height, bool makePowerOfTwo=false, bool forceDimensions=false)=0
bool isInitialized
Definition: RenderSystem.h:98
virtual ~idRenderSystem()
Definition: RenderSystem.h:162
bool textureNonPowerOfTwoAvailable
Definition: RenderSystem.h:77
bool ARBFragmentProgramAvailable
Definition: RenderSystem.h:75
virtual void TakeScreenshot(int width, int height, const char *fileName, int samples, struct renderView_s *ref)=0
const int GLYPH_CHAREND
Definition: RenderSystem.h:106
virtual void DrawStretchTri(idVec2 p1, idVec2 p2, idVec2 p3, idVec2 t1, idVec2 t2, idVec2 t3, const idMaterial *material)=0
int stencilBits
Definition: RenderSystem.h:60
const int GLYPH_START
Definition: RenderSystem.h:103
virtual void WriteDemoPics()=0