Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Hardware/Video/GFXDevice.cpp

Diff revisions: vs.
  @@ -4,12 +4,12 @@
4 4 #include "GUI/Headers/GUI.h"
5 5 #include "GUI/Headers/GUIText.h"
6 6 #include "GUI/Headers/GUIFlash.h"
7 + #include "Core/Math/Headers/Plane.h"
7 8 #include "Core/Headers/Application.h"
8 9 #include "Core/Headers/ParamHandler.h"
9 10 #include "Rendering/Headers/Frustum.h"
10 11 #include "Managers/Headers/SceneManager.h"
11 12 #include "Managers/Headers/ShaderManager.h"
12 - #include "Rendering/Headers/Renderer.h"
13 13 #include "Rendering/PostFX/Headers/PostFX.h"
14 14 #include "Rendering/Camera/Headers/Camera.h"
15 15 #include "Rendering/RenderPass/Headers/RenderPass.h"
  @@ -21,7 +21,7 @@
21 21 #include "Geometry/Shapes/Headers/Predefined/Quad3D.h"
22 22 #include "Geometry/Shapes/Headers/Predefined/Text3D.h"
23 23
24 - GFXDevice::GFXDevice() : _api(GL_API::getInstance()) ///<Defaulting to OpenGL if no api has been defined
24 + GFXDevice::GFXDevice() : _api(GL_API::getOrCreateInstance()) ///<Defaulting to OpenGL if no api has been defined
25 25 {
26 26 _prevShaderId = 0;
27 27 _prevTextureId = 0;
  @@ -30,18 +30,20 @@
30 30 _previousStateBlock = NULL;
31 31 _stateBlockDirty = false;
32 32 _drawDebugAxis = false;
33 + _clippingPlanesDirty = true;
33 34 _renderer = NULL;
34 35 _renderStage = INVALID_STAGE;
36 + Frustum::createInstance();
35 37 RenderPass* diffusePass = New RenderPass("diffusePass");
36 - RenderPassManager::getInstance().addRenderPass(diffusePass,1);
38 + RenderPassManager::getOrCreateInstance().addRenderPass(diffusePass,1);
37 39 //RenderPassManager::getInstance().addRenderPass(shadowPass,2);
38 40 }
39 41
40 42 void GFXDevice::setApi(const RenderAPI& api){
41 43 switch(api) {
42 44 default:
43 - case OpenGL: _api = GL_API::getInstance(); break;
44 - case Direct3D: _api = DX_API::getInstance(); break;
45 + case OpenGL: _api = GL_API::getOrCreateInstance(); break;
46 + case Direct3D: _api = DX_API::getOrCreateInstance(); break;
45 47
46 48 case GFX_RENDER_API_PLACEHOLDER: ///< Placeholder - OpenGL 4.0 and DX 11 in another life maybe :) - Ionut
47 49 case Software:
  @@ -57,6 +59,7 @@
57 59 SAFE_DELETE(it.second);
58 60 }
59 61 _stateBlockMap.clear();
62 + Frustum::DestroyInstance();
60 63 ///Destroy all rendering Passes
61 64 RenderPassManager::getInstance().DestroyInstance();
62 65 }
  @@ -70,28 +73,32 @@
70 73 //All geometry is stored in VBO format
71 74 assert(instance->object3D() != NULL);
72 75
73 - if(instance->preDraw()){
76 + if(instance->preDraw())
74 77 instance->object3D()->onDraw(getRenderStage());
75 - }
76 -
78 +
77 79 if(instance->draw2D()){
78 80 //toggle2D(true);
79 81 }
80 - if(_stateBlockDirty) updateStates();
82 +
83 + if(_stateBlockDirty)
84 + updateStates();
81 85
82 86 _api.renderInstance(instance);
83 87 }
84 88
85 89 void GFXDevice::renderBuffer(VertexBufferObject* const vbo,Transform* const vboTransform){
86 - if(_stateBlockDirty) updateStates();
90 + if(_stateBlockDirty)
91 + updateStates();
87 92
88 93 _api.renderBuffer(vbo,vboTransform);
89 94 }
90 95
91 96 void GFXDevice::renderGUIElement(GUIElement* const element,ShaderProgram* const guiShader){
92 - if(!element) return; //< Console not created, for example
97 + if(!element)
98 + return; //< Console not created, for example
93 99
94 - if(_stateBlockDirty) updateStates();
100 + if(_stateBlockDirty)
101 + updateStates();
95 102
96 103 switch(element->getGuiType()){
97 104 case GUI_TEXT:{
  @@ -107,7 +114,7 @@
107 114 };
108 115 }
109 116
110 - void GFXDevice::render(boost::function0<void> renderFunction,SceneRenderState* const sceneRenderState){
117 + void GFXDevice::render(boost::function0<void> renderFunction, const SceneRenderState& sceneRenderState){
111 118 //Call the specific renderfunction that prepares the scene for presentation
112 119 _renderer->render(renderFunction,sceneRenderState);
113 120 }
  @@ -118,43 +125,61 @@
118 125 }
119 126
120 127 void GFXDevice::setRenderer(Renderer* const renderer) {
128 + assert(renderer != NULL);
121 129 SAFE_UPDATE(_renderer,renderer);
122 130 }
123 131
124 - bool GFXDevice::getDeferredRendering(){
125 - assert(_renderer != NULL);
126 - return (_renderer->getType() != RENDERER_FORWARD);
127 - }
128 -
129 132 void GFXDevice::generateCubeMap(FrameBufferObject& cubeMap,
130 - Camera* const activeCamera,
131 133 const vec3<F32>& pos,
132 - boost::function0<void> callback){
134 + boost::function0<void> callback,
135 + const RenderStage& renderStage){
133 136 //Don't need to override cubemap rendering callback
134 137 if(callback.empty()){
135 - SceneGraph* sg = GET_ACTIVE_SCENE()->getSceneGraph();
136 138 //Default case is that everything is reflected
137 - callback = SCENE_GRAPH_UPDATE(sg);
139 + callback = SCENE_GRAPH_UPDATE(GET_ACTIVE_SCENEGRAPH());
138 140 }
139 141 //Only use cube map FBO's
140 - if(cubeMap.getType() != FBO_CUBE_COLOR){
141 - ERROR_FN(Locale::get("ERROR_GFX_DEVICE_INVALID_FBO_CUBEMAP"));
142 + if(cubeMap.getType() != FBO_CUBE_COLOR && cubeMap.getType() != FBO_CUBE_DEPTH){
143 + if(cubeMap.getType() != FBO_CUBE_COLOR) {
144 + ERROR_FN(Locale::get("ERROR_GFX_DEVICE_INVALID_FBO_CUBEMAP"));
145 + }else{
146 + ERROR_FN(Locale::get("ERROR_GFX_DEVICE_INVALID_FBO_CUBEMAP_SHADOW"));
147 + }
142 148 return;
143 149 }
144 - //Save our current camera settings
145 - activeCamera->SaveCamera();
150 +
151 + static vec3<F32> TabUp[6] = {
152 + vec3<F32>(0.0f, -1.0f, 0.0f),
153 + vec3<F32>(0.0f, -1.0f, 0.0f),
154 + vec3<F32>(0.0f, 0.0f, 1.0f),
155 + vec3<F32>(0.0f, 0.0f, -1.0f),
156 + vec3<F32>(0.0f, -1.0f, 0.0f),
157 + vec3<F32>(0.0f, -1.0f, 0.0f)
158 + };
159 +
160 + ///Get the center and up vectors for each cube face
161 + vec3<F32> TabCenter[6] = {
162 + vec3<F32>(pos.x+1.0f, pos.y, pos.z),
163 + vec3<F32>(pos.x-1.0f, pos.y, pos.z),
164 + vec3<F32>(pos.x, pos.y+1.0f, pos.z),
165 + vec3<F32>(pos.x, pos.y-1.0f, pos.z),
166 + vec3<F32>(pos.x, pos.y, pos.z+1.0f),
167 + vec3<F32>(pos.x, pos.y, pos.z-1.0f)
168 + };
169 +
146 170 //And save all camera transform matrices
147 171 lockMatrices(PROJECTION_MATRIX,true,true);
148 172 //set a 90 degree vertical FoV perspective projection
149 173 setPerspectiveProjection(90.0,1,Frustum::getInstance().getZPlanes());
150 - //Save our old rendering stage
151 - RenderStage prev = getRenderStage();
152 174 //And set the current render stage to
153 - setRenderStage(ENVIRONMENT_MAPPING_STAGE);
175 + setRenderStage(renderStage);
154 176 //For each of the environment's faces (TOP,DOWN,NORTH,SOUTH,EAST,WEST)
155 177 for(U8 i = 0; i < 6; i++){
156 - //Set the correct camera orientation and position for current face
157 - activeCamera->RenderLookAtToCubeMap( pos, i );
178 + ///Set our Rendering API to render the desired face
179 + GFX_DEVICE.lookAt(pos,TabCenter[i],TabUp[i]);
180 + GET_ACTIVE_SCENE()->renderState().getCamera().updateListeners();
181 + ///Extract the view frustum associated with this face
182 + Frustum::getInstance().Extract(pos);
158 183 //Bind our FBO's current face
159 184 cubeMap.Begin(i);
160 185 //draw our scene
  @@ -163,11 +188,9 @@
163 188 cubeMap.End(i);
164 189 }
165 190 //Return to our previous rendering stage
166 - setRenderStage(prev);
191 + setPreviousRenderStage();
167 192 //Restore transfom matrices
168 193 releaseMatrices();
169 - //And restore camera
170 - activeCamera->RestoreCamera();
171 194 }
172 195
173 196 RenderStateBlock* GFXDevice::createStateBlock(const RenderStateBlockDescriptor& descriptor){
  @@ -206,11 +229,12 @@
206 229 void GFXDevice::updateStates(bool force) {
207 230 //Verify render states
208 231 if(force){
209 - if ( _newStateBlock ){
232 + if ( _newStateBlock )
210 233 updateStateInternal(_newStateBlock, true);
211 - }
234 +
212 235 _currentStateBlock = _newStateBlock;
213 236 }
237 +
214 238 if (_stateBlockDirty && !force) {
215 239 updateStateInternal(_newStateBlock);
216 240 _currentStateBlock = _newStateBlock;
  @@ -218,6 +242,7 @@
218 242 _stateBlockDirty = false;
219 243
220 244 LightManager::getInstance().update();
245 +
221 246 }
222 247
223 248 bool GFXDevice::excludeFromStateChange(const SceneNodeType& currentType){