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/OpenGL/GLStates.cpp

Diff revisions: vs.
  @@ -1,7 +1,10 @@
1 1 //OpenGL state management: Lights, matrices, viewport, bound objects etc
2 2 #include "Headers/GLWrapper.h"
3 3 #include "Headers/glRenderStateBlock.h"
4 +
5 + #include "Core/Headers/ParamHandler.h"
4 6 #include "Managers/Headers/ShaderManager.h"
7 + #include "Rendering/Headers/Frustum.h"
5 8 #include "Rendering/Lighting/Headers/Light.h"
6 9 #include "Hardware/Video/Headers/GFXDevice.h"
7 10 #include "Hardware/Video/OpenGL/Buffers/VertexBufferObject/Headers/glVertexArrayObject.h"
  @@ -12,8 +15,6 @@
12 15 glShaderProgram* GL_API::_activeShaderProgram = NULL;
13 16 GLuint GL_API::_activeVAOId = 0;
14 17 GLuint GL_API::_activeTextureUnit = 0;
15 - vec4<GLint> GL_API::_prevViewportRect = vec4<GLint>(0,0,0,0);
16 - vec4<GLint> GL_API::_currentviewportRect = vec4<GLint>(0,0,0,0);
17 18 vec4<GLfloat> GL_API::_prevClearColor = DIVIDE_BLUE();
18 19
19 20 void GL_API::clearStates(const bool skipShader,const bool skipTextures,const bool skipBuffers, const bool forceAll){
  @@ -60,7 +61,6 @@
60 61 Divide::GL::_queryMatrix(NORMAL_MATRIX,mat);
61 62 }
62 63
63 -
64 64 void GL_API::toggle2D(bool state){
65 65 if(state == _2DRendering) return;
66 66
  @@ -138,16 +138,14 @@
138 138 //Setting _LookAt here for camera's or shadow projection
139 139 // -set the current matrix to GL_MODELVIEW
140 140 // -reset it to identity
141 - void GL_API::lookAt(const vec3<GLfloat>& eye,
142 - const vec3<GLfloat>& center,
143 - const vec3<GLfloat>& up,
144 - const bool invertx,
145 - const bool inverty){
146 - Divide::GL::_LookAt(glm::vec3(eye.x,eye.y,eye.z),
147 - glm::vec3(center.x,center.y,center.z),
148 - glm::vec3(up.x,up.y,up.z),
149 - invertx,
150 - inverty);
141 +
142 + void GL_API::lookAt(const vec3<F32>& eye, const vec3<F32>& target, const vec3<F32>& up){
143 + vec3<F32> viewDirection(eye-target);
144 +
145 + Divide::GL::_LookAt(glm::value_ptr(glm::lookAt(glm::vec3(eye.x, eye.y, eye.z),
146 + glm::vec3(target.x, target.y, target.z),
147 + glm::vec3(up.x, up.y, up.z))),
148 + normalize(viewDirection));
151 149 }
152 150
153 151 void GL_API::lockMatrices(const MATRIX_MODE& setCurrentMatrix, bool lockView, bool lockProjection){
  @@ -161,7 +159,7 @@
161 159 Divide::GL::_pushMatrix();
162 160 }
163 161
164 - ///This is such a cheap operation that no other checks are needed (even if we double set the VIEW_MATRIX)
162 + //This is such a cheap operation that no other checks are needed (even if we double set the VIEW_MATRIX)
165 163 Divide::GL::_matrixMode(setCurrentMatrix);
166 164 }
167 165
  @@ -176,7 +174,7 @@
176 174 Divide::GL::_popMatrix();
177 175 }
178 176
179 - ///This is such a cheap operation that no other checks are needed (even if we double set the VIEW_MATRIX)
177 + //This is such a cheap operation that no other checks are needed (even if we double set the VIEW_MATRIX)
180 178 Divide::GL::_matrixMode(setCurrentMatrix);
181 179 }
182 180
  @@ -200,14 +198,47 @@
200 198 Divide::GL::_matrixMode(VIEW_MATRIX);
201 199 }
202 200
201 + void GL_API::setAnaglyphFrustum(F32 camIOD, bool rightFrustum){
202 + ParamHandler& par = ParamHandler::getInstance();
203 + const vec2<GLfloat>& zPlanes = Frustum::getInstance().getZPlanes();
204 + GLfloat fov = par.getParam<GLfloat>("runtime.verticalFOV");
205 + GLfloat ratio = par.getParam<GLfloat>("runtime.aspectRatio");
206 + Divide::GL::_anaglyph(camIOD,(GLdouble)zPlanes.x, (GLdouble)zPlanes.y,ratio,fov,rightFrustum);
207 + }
208 +
209 + void GL_API::updateClipPlanes(){
210 + //ToDo: Hack because clearly, HW clipping is too complicated for some ATI cards ... -Ionut
211 + if(getGPUVendor() == GPU_VENDOR_AMD)
212 + return;
213 +
214 + const PlaneList& list = GFX_DEVICE.getClippingPlanes();
215 + bool clipPlaneState = false;
216 + for(GLuint clipPlaneIndex = 0; clipPlaneIndex < list.size(); clipPlaneIndex++){
217 + clipPlaneState = list[clipPlaneIndex].active();
218 + if(clipPlaneState != _activeClipPlanes[clipPlaneIndex]){
219 + _activeClipPlanes[clipPlaneIndex] = clipPlaneState;
220 + if(clipPlaneState){
221 + GLCheck(glEnable(GL_CLIP_DISTANCE0 + clipPlaneIndex));
222 + }else{
223 + GLCheck(glDisable(GL_CLIP_DISTANCE0 + clipPlaneIndex));
224 + }
225 + }
226 + }
227 +
228 + }
229 +
203 230 void GL_API::setActiveTextureUnit(GLuint unit,const bool force){
204 - if(_activeTextureUnit == unit && !force) return; //< prevent double bind
231 + if(_activeTextureUnit == unit && !force)
232 + return; //< prevent double bind
233 +
205 234 _activeTextureUnit = unit;
206 235 GLCheck(glActiveTexture(GL_TEXTURE0 + unit));
207 236 }
208 237
209 238 void GL_API::setActiveVAO(GLuint id,const bool force){
210 - if(_activeVAOId == id && !force) return; //<prevent double bind
239 + if(_activeVAOId == id && !force)
240 + return; //<prevent double bind
241 +
211 242 _activeVAOId = id;
212 243 GLCheck(glBindVertexArray(id));
213 244 }
  @@ -215,7 +246,8 @@
215 246 void GL_API::setActiveProgram(glShaderProgram* const program,const bool force){
216 247 U32 newProgramId = (program != NULL) ? program->getId() : 0;
217 248 U32 oldProgramId = (_activeShaderProgram != NULL) ? _activeShaderProgram->getId() : 0;
218 - if(oldProgramId == newProgramId && !force) return; //<prevent double bind
249 + if(oldProgramId == newProgramId && !force)
250 + return; //<prevent double bind
219 251
220 252 if(_activeShaderProgram != NULL) _activeShaderProgram->unbind(false);
221 253
  @@ -234,18 +266,24 @@
234 266 }
235 267 }
236 268
269 + static bool popViewport = false;
237 270 void GL_API::restoreViewport(){
238 - if(_currentviewportRect != _prevViewportRect){
239 - _currentviewportRect = _prevViewportRect;
240 - GLCheck(glViewport(_currentviewportRect.x,_currentviewportRect.y,_currentviewportRect.z,_currentviewportRect.w));
241 - }
242 - }
271 + if(popViewport)
272 + Divide::GL::_viewport.pop();
273 + const vec4<U32>& prevViewport = Divide::GL::_viewport.top();
274 + GLCheck(glViewport(prevViewport.x, prevViewport.y, prevViewport.z, prevViewport.w));
275 + }
276 +
277 + vec4<U32> GL_API::setViewport(const vec4<U32>& viewport, bool force){
278 + bool updateGL = !viewport.compare(Divide::GL::_viewport.top());
279 + popViewport = !force;
280 + if(force)
281 + Divide::GL::_viewport.top() = viewport;
282 + else
283 + Divide::GL::_viewport.push(viewport);
284 +
285 + if(updateGL)
286 + GLCheck(glViewport(viewport.x,viewport.y,viewport.z,viewport.w));
243 287
244 - void GL_API::setViewport(GLint x, GLint y, GLint width, GLint height,bool force){
245 - vec4<GLint> viewportRect(x,y,width,height);
246 - if(_currentviewportRect != viewportRect){
247 - _prevViewportRect = force ? viewportRect : _currentviewportRect;
248 - _currentviewportRect = viewportRect;
249 - GLCheck(glViewport(_currentviewportRect.x,_currentviewportRect.y,_currentviewportRect.z,_currentviewportRect.w));
250 - }
288 + return Divide::GL::_viewport.top();
251 289 }