]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/renderer/RenderSystem.h
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / renderer / RenderSystem.h
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
55         int                                     maxTextureUnits;
56         int                                     maxTextureCoords;
57         int                                     maxTextureImageUnits;
58         float                           maxTextureAnisotropy;
59
60         int                                     colorBits, depthBits, stencilBits;
61
62         bool                            multitextureAvailable;
63         bool                            textureCompressionAvailable;
64         bool                            anisotropicAvailable;
65         bool                            textureLODBiasAvailable;
66         bool                            textureEnvAddAvailable;
67         bool                            textureEnvCombineAvailable;
68         bool                            registerCombinersAvailable;
69         bool                            cubeMapAvailable;
70         bool                            envDot3Available;
71         bool                            texture3DAvailable;
72         bool                            sharedTexturePaletteAvailable;
73         bool                            ARBVertexBufferObjectAvailable;
74         bool                            ARBVertexProgramAvailable;
75         bool                            ARBFragmentProgramAvailable;
76         bool                            twoSidedStencilAvailable;
77         bool                            textureNonPowerOfTwoAvailable;
78         bool                            depthBoundsTestAvailable;
79
80         // ati r200 extensions
81         bool                            atiFragmentShaderAvailable;
82
83         // ati r300
84         bool                            atiTwoSidedStencilAvailable;
85
86         int                                     vidWidth, vidHeight;    // passed to R_BeginFrame
87
88         int                                     displayFrequency;
89
90         bool                            isFullscreen;
91
92         bool                            allowNV30Path;
93         bool                            allowNV20Path;
94         bool                            allowNV10Path;
95         bool                            allowR200Path;
96         bool                            allowARB2Path;
97
98         bool                            isInitialized;
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;
107 const int GLYPHS_PER_FONT               = GLYPH_END - GLYPH_START + 1;
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 {
126         glyphInfo_t                     glyphs [GLYPHS_PER_FONT];
127         float                           glyphScale;
128         char                            name[64];
129 } fontInfo_t;
130
131 typedef struct {
132         fontInfo_t                      fontInfoSmall;
133         fontInfo_t                      fontInfoMedium;
134         fontInfo_t                      fontInfoLarge;
135         int                                     maxHeight;
136         int                                     maxWidth;
137         int                                     maxHeightSmall;
138         int                                     maxWidthSmall;
139         int                                     maxHeightMedium;
140         int                                     maxWidthMedium;
141         int                                     maxHeightLarge;
142         int                                     maxWidthLarge;
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
159 class idRenderSystem {
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
261 extern idRenderSystem *                 renderSystem;
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__ */