ScummVM API documentation
Renderer3D.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_RENDERER3D_H
29 #define HPL_RENDERER3D_H
30 
31 #include "hpl1/engine/graphics/GPUProgram.h"
32 #include "hpl1/engine/graphics/GraphicsTypes.h"
33 #include "hpl1/engine/graphics/Material.h"
34 #include "hpl1/engine/math/Frustum.h"
35 #include "hpl1/engine/math/MathTypes.h"
36 
37 namespace hpl {
38 
39 #define eRendererDebugFlag_DrawTangents (0x00000001)
40 #define eRendererDebugFlag_DrawNormals (0x00000002)
41 #define eRendererDebugFlag_DisableLighting (0x00000004)
42 #define eRendererDebugFlag_LogRendering (0x00000008)
43 #define eRendererDebugFlag_DrawBoundingBox (0x00000010)
44 #define eRendererDebugFlag_DrawBoundingSphere (0x00000020)
45 #define eRendererDebugFlag_DrawLightBoundingBox (0x00000040)
46 #define eRendererDebugFlag_RenderLines (0x00000080)
47 
48 typedef tFlag tRendererDebugFlag;
49 
50 class cResources;
51 class iLowLevelGraphics;
52 class LowLevelResources;
53 class iTexture;
54 class cCamera3D;
55 class cWorld3D;
56 class iVertexBuffer;
57 class cMeshCreator;
58 class cRenderList;
59 class iRenderable;
60 class iLight3D;
61 class cRendererPostEffects;
62 class cSector;
63 
64 class cResources;
65 
66 //---------------------------------------------
67 
68 enum eRendererShowShadows {
69  eRendererShowShadows_All,
70  eRendererShowShadows_Static,
71  eRendererShowShadows_None,
72  eRendererShowShadows_LastEnum
73 };
74 
75 //---------------------------------------------
76 
78 public:
80 
81  void Clear();
82  void Reset(iLowLevelGraphics *apLowLevel);
83 
84  // Setings that doesn't change:
85  iGpuProgram *extrudeProgram;
86  iLowLevelGraphics *mpLowLevel;
87 
88  unsigned int *mpTempIndexArray;
89 
90  // Setting that changes
91  iLight3D *mpLight;
92  cCamera3D *mpCamera;
93  cFrustum *mpFrustum;
94 
95  cSector *mpSector;
96 
97  bool mbFogActive;
98  bool mbFogCulling;
99  float mfFogStart;
100  float mfFogEnd;
101  cColor mFogColor;
102 
103  eRendererShowShadows mShowShadows;
104  bool mbLog;
105  tRendererDebugFlag mDebugFlags;
106 
107  // State settings
108  int mlLastShadowAlgo;
109 
110  bool mbDepthTest;
111 
112  eMaterialAlphaMode mAlphaMode;
113  eMaterialBlendMode mBlendMode;
114  eMaterialChannelMode mChannelMode;
115 
116  iGpuProgram *gpuProgram;
117  iMaterialProgramSetup *gpuProgramSetup;
118  iGpuProgram *mpVertexProgram;
119  bool mbVertexUseLight;
120  iMaterialProgramSetup *mpVtxProgramSetup;
121 
122  iGpuProgram *mpFragmentProgram;
123 
124  bool mbMatrixWasNULL;
125 
126  bool mbUsesLight;
127  bool mbUsesEye;
128 
129  cColor mAmbientColor;
130 
131  iTexture *mpTexture[MAX_TEXTUREUNITS];
132  eMaterialBlendMode mTextureBlend[MAX_TEXTUREUNITS];
133 
134  iVertexBuffer *mpVtxBuffer;
135 };
136 
137 //---------------------------------------------
138 
139 class cRenderer3D {
140 public:
141  cRenderer3D(iLowLevelGraphics *apLowLevelGraphics, cResources *apResources,
142  cMeshCreator *apMeshCreator, cRenderList *apRenderList);
143  ~cRenderer3D();
144 
145  void UpdateRenderList(cWorld3D *apWorld, cCamera3D *apCamera, float afFrameTime);
146 
147  void RenderWorld(cWorld3D *apWorld, cCamera3D *apCamera, float afFrameTime);
148 
149  void SetSkyBox(iTexture *apTexture, bool abAutoDestroy);
150  void SetSkyBoxActive(bool abX);
151  void SetSkyBoxColor(const cColor &aColor);
152 
153  iTexture *GetSkyBox() { return mpSkyBoxTexture; }
154  bool GetSkyBoxActive() { return mbSkyBoxActive; }
155  cColor GetSkyBoxColor() { return mSkyBoxColor; }
156 
157  void SetAmbientColor(const cColor &aColor) { mRenderSettings.mAmbientColor = aColor; }
158  cColor GetAmbientColor() { return mRenderSettings.mAmbientColor; }
159 
160  iTexture *GetFogSolidTexture() { return mpFogLinearSolidTexture; }
161  iTexture *GetFogAddTexture() { return mpFogLinearAddTexture; }
162  iTexture *GetFogAlphaTexture() { return mpFogLinearAlphaTexture; }
163 
164  void SetRefractionUsed(bool abX) { mbRefractionUsed = abX; }
165  bool GetRefractionUsed() { return mbRefractionUsed; }
166 
167  // Fog properties
168  void SetFogActive(bool abX);
169  void SetFogStart(float afX);
170  void SetFogEnd(float afX);
171  void SetFogColor(const cColor &aCol) { mRenderSettings.mFogColor = aCol; }
172  void SetFogCulling(bool abX) { mRenderSettings.mbFogCulling = abX; }
173 
174  bool GetFogActive() { return mRenderSettings.mbFogActive; }
175  float GetFogStart() { return mRenderSettings.mfFogStart; }
176  float GetFogEnd() { return mRenderSettings.mfFogEnd; }
177  cColor GetFogColor() { return mRenderSettings.mFogColor; }
178  bool GetFogCulling() { return mRenderSettings.mbFogCulling; }
179 
180  cBoundingVolume *GetFogBV() { return &mFogBV; }
181 
182  void SetPostEffects(cRendererPostEffects *apPostEffects) { mpPostEffects = apPostEffects; }
183 
184  // Debug setup
185  void SetDebugFlags(tRendererDebugFlag aFlags) { mDebugFlags = aFlags; }
186  tRendererDebugFlag GetDebugFlags() { return mDebugFlags; }
187 
188  cRenderList *GetRenderList() { return mpRenderList; }
189  cRenderSettings *GetRenderSettings() { return &mRenderSettings; }
190 
191  eRendererShowShadows GetShowShadows();
192  void SetShowShadows(eRendererShowShadows aState);
193 
194  void FetchOcclusionQueries();
195 
196 private:
197  inline void BeginRendering(cCamera3D *apCamera);
198 
199  void InitSkyBox();
200 
201  // Render steps
202  void RenderFog(cCamera3D *apCamera);
203 
204  void RenderSkyBox(cCamera3D *apCamera);
205 
206  void RenderZ(cCamera3D *apCamera);
207 
208  void RenderOcclusionQueries(cCamera3D *apCamera);
209 
210  void RenderLight(cCamera3D *apCamera);
211 
212  void RenderDiffuse(cCamera3D *apCamera);
213 
214  void RenderTrans(cCamera3D *apCamera);
215 
216  void RenderDebug(cCamera3D *apCamera);
217 
218  inline void RenderDebugObject(cCamera3D *apCamera, iRenderable *&apObject, iMaterial *apPrevMat,
219  int alPrevMatId, iVertexBuffer *apPrevVtxBuff,
220  eMaterialRenderType aRenderType, iLight3D *apLight);
221 
222  iLowLevelGraphics *mpLowLevelGraphics;
223  LowLevelResources *mpLowLevelResources;
224 
225  cRendererPostEffects *mpPostEffects;
226 
227  bool mbLog;
228 
229  float mfRenderTime;
230 
231  iGpuProgram *_diffuseProgram;
232  iGpuProgram *_solidFogProgram;
233 
234  iTexture *mpFogLinearSolidTexture;
235 
236  iTexture *mpFogLinearAddTexture;
237  iTexture *mpFogLinearAlphaTexture;
238 
239  iGpuProgram *_refractProgram;
240  iGpuProgram *_refractSpecProgram;
241  bool mbRefractionAvailable;
242  bool mbRefractionUsed;
243 
244  cRenderSettings mRenderSettings;
245 
246  cBoundingVolume mFogBV;
247 
248  tVertexVec mvVtxRect;
249 
250  cMeshCreator *mpMeshCreator;
251  cRenderList *mpRenderList;
252 
253  iVertexBuffer *mpSkyBox;
254  iTexture *mpSkyBoxTexture;
255  bool mbAutoDestroySkybox;
256  bool mbSkyBoxActive;
257  cColor mSkyBoxColor;
258 
259  cResources *mpResources;
260 
261  tRendererDebugFlag mDebugFlags;
262 };
263 
264 } // namespace hpl
265 
266 #endif // HPL_RENDERER3D_H
Definition: PortalContainer.h:181
Definition: AI.h:36
Definition: Renderer3D.h:77
Definition: VertexBuffer.h:90
Definition: Light3D.h:117
Definition: Texture.h:88
Definition: Material.h:181
Definition: BoundingVolume.h:71
Definition: Renderable.h:70
Definition: low_level_resources.h:40
Definition: RendererPostEffects.h:71
Definition: World3D.h:179
Definition: MeshCreator.h:43
Definition: Renderer3D.h:139
Definition: RenderList.h:145
Definition: Resources.h:160
Definition: Color.h:37
Definition: Material.h:203
Definition: LowLevelGraphics.h:200
Definition: Camera3D.h:53
Definition: GPUProgram.h:62
Definition: Frustum.h:57