Subversion Repository Public Repository

Divide-Framework

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#include "Headers/glResources.h"
#ifndef GLM_MESSAGES
#undef  GLM_MESSAGES
#endif
#include <gtc/matrix_inverse.hpp>
#include <gtc/matrix_transform.hpp>
#include <gtc/type_ptr.hpp>
#include "Hardware/Video/Headers/RenderAPIEnums.h"
#include "Hardware/Video/OpenGL/Headers/GLWrapper.h"

namespace Divide {
	namespace GL {
		///Used for anaglyph rendering
		struct CameraFrustum {
			GLdouble leftfrustum;
			GLdouble rightfrustum;
			GLdouble bottomfrustum;
			GLdouble topfrustum;
			GLfloat modeltranslation;
		} _leftCam, _rightCam;

		/*-----------Object Management----*/
		GLuint _invalidObjectID = std::numeric_limits<U32>::max();

		/*-----------Context Management----*/
		bool _applicationClosing = false;
		bool _contextAvailable = false;
		bool _useDebugOutputCallback = false;
		GLFWwindow* _mainWindow     = NULL;
		GLFWwindow* _loaderWindow   = NULL;

		/*----------- GLU overrides ------*/
		///Matrix management
		MATRIX_MODE   _currentMatrixMode;
		matrixStack   _viewMatrix;
		matrixStack   _projectionMatrix;
		matrixStack   _textureMatrix;
		viewportStack _viewport;
		glm::mat4     _MVPCachedMatrix;
		glm::mat4     _MVCachedMatrix;
		glm::mat4     _identityMatrix;
		glm::mat4     _biasMatrix;
		glm::mat4     _modelMatrix;
		vector3Stack  _currentViewDirection;

		bool _MDirty = true;
		bool _VDirty = true;
		bool _PDirty = true;
		bool _isUniformScaled = true;
		bool _resetModelMatrixFlag = true;
		GLfloat  _anaglyphIOD = -0.01f;

		void _initStacks(){
			_currentViewDirection.push(vec3<F32>());
			_projectionMatrix.push(_identityMatrix);
			_viewMatrix.push(_identityMatrix);
			_textureMatrix.push(_identityMatrix);
			_viewport.push(vec4<U32>(0,0,0,0));
			_biasMatrix = glm::mat4(0.5, 0.0, 0.0, 0.0,
									0.0, 0.5, 0.0, 0.0,
									0.0, 0.0, 0.5, 0.0,
									0.5, 0.5, 0.5, 1.0);
		}

		void _LookAt(const GLfloat* viewMatrix, const vec3<F32>& viewDirection){
		   _matrixMode(VIEW_MATRIX);
		   _currentViewDirection.top() = viewDirection;
		   _viewMatrix.top() = glm::make_mat4(viewMatrix);
		   GL_API::getInstance().updateViewMatrix();
		   _VDirty = true;
		}

		void _ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar){
			_matrixMode(PROJECTION_MATRIX);
			_projectionMatrix.top() = glm::ortho(left,right,bottom,top,zNear,zFar);
			GL_API::getInstance().updateProjectionMatrix();
			_PDirty = true;
		}

		void _perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar){
			_matrixMode(PROJECTION_MATRIX);
			_projectionMatrix.top() = glm::perspective(fovy,aspect,zNear,zFar);
			GL_API::getInstance().updateProjectionMatrix();
			_PDirty = true;
		}

		void _anaglyph(GLfloat IOD, GLdouble zNear, GLdouble zFar, GLfloat aspect, GLfloat fovy, bool rightFrustum){
			if(!FLOAT_COMPARE(_anaglyphIOD,IOD)){
				static const GLdouble DTR = 0.0174532925;
				static const GLdouble screenZ = 10.0;
				
				//sets top of frustum based on fovy and near clipping plane
				GLdouble top = zNear*tan(DTR*fovy/2);            
				GLdouble right = aspect*top;                           
				//sets right of frustum based on aspect ratio
				GLdouble frustumshift = (IOD/2)*zNear/screenZ;

				_leftCam.topfrustum = top;
				_leftCam.bottomfrustum = -top;
				_leftCam.leftfrustum = -right + frustumshift;
				_leftCam.rightfrustum = right + frustumshift;
				_leftCam.modeltranslation = IOD/2;

				_rightCam.topfrustum = top;
				_rightCam.bottomfrustum = -top;
				_rightCam.leftfrustum = -right - frustumshift;
				_rightCam.rightfrustum = right - frustumshift;
				_rightCam.modeltranslation = -IOD/2;

				_anaglyphIOD = IOD;
			}

			_matrixMode(PROJECTION_MATRIX);

			CameraFrustum& tempCamera = rightFrustum ? _rightCam : _leftCam;

			_projectionMatrix.top() = glm::frustum(tempCamera.leftfrustum,
												   tempCamera.rightfrustum,
												   tempCamera.bottomfrustum,
												   tempCamera.topfrustum,
												   zNear,
												   zFar);
			//translate to cancel parallax
			glm::translate(_projectionMatrix.top(), glm::vec3(tempCamera.modeltranslation, 0.0, 0.0)); 
		
			GL_API::getInstance().updateProjectionMatrix();
			_PDirty = true;

			_matrixMode(VIEW_MATRIX);
		}

		void _resetModelMatrix(bool force){
			_resetModelMatrixFlag = !force;

			if(!force)
				return;

			_modelMatrix = _identityMatrix;
			_isUniformScaled = _MDirty = true;
		}

		void _setModelMatrix(const mat4<F32>& matrix, bool uniform){
			_modelMatrix = glm::make_mat4(matrix.mat);
			_isUniformScaled = uniform;
			_resetModelMatrixFlag = false;
			_MDirty = true;
		}

		void _pushMatrix(){
			if(_currentMatrixMode == PROJECTION_MATRIX) {
				_projectionMatrix.push(_projectionMatrix.top());
			}else if(_currentMatrixMode == VIEW_MATRIX){   
				_viewMatrix.push(_viewMatrix.top());
				_currentViewDirection.push(_currentViewDirection.top());
			}else if(_currentMatrixMode == TEXTURE_MATRIX) {
				_textureMatrix.push(_textureMatrix.top());
			}else {
				assert(_currentMatrixMode == -1);
			}
		}

		void _popMatrix(){
			if(_currentMatrixMode == PROJECTION_MATRIX){
				_projectionMatrix.pop();
				_PDirty = true;
				GL_API::getInstance().updateProjectionMatrix();
			}else if(_currentMatrixMode == VIEW_MATRIX){
				_viewMatrix.pop();
				_currentViewDirection.pop();
				GL_API::getInstance().updateViewMatrix();
				_VDirty = true;
			}else if(_currentMatrixMode == TEXTURE_MATRIX){
				_textureMatrix.pop();
			}else{
				assert(_currentMatrixMode == -1);
			}
		}

		void _loadIdentity(){
			if(_currentMatrixMode == PROJECTION_MATRIX){
				_projectionMatrix.top() = _identityMatrix;
				_PDirty = true;
				GL_API::getInstance().updateProjectionMatrix();
			}else if(_currentMatrixMode == VIEW_MATRIX){
				_viewMatrix.top() = _identityMatrix;
				_currentViewDirection.top() = vec3<F32>();
				GL_API::getInstance().updateViewMatrix();
				_VDirty = true;
			}else if(_currentMatrixMode == TEXTURE_MATRIX){
				_textureMatrix.top() = _identityMatrix;
			}else{
				assert(_currentMatrixMode == -1);
			}
		}

		void _queryMatrix(const MATRIX_MODE& mode, mat4<GLfloat>& mat){
			if(mode == VIEW_MATRIX)            
				mat.set(glm::value_ptr(_viewMatrix.top()));
			else if(mode == PROJECTION_MATRIX)
				mat.set(glm::value_ptr(_projectionMatrix.top()));
			else if(mode == TEXTURE_MATRIX)   
				mat.set(glm::value_ptr(_textureMatrix.top()));
			else
				assert(mode == -1);
		}

		void _queryMatrix(const EXTENDED_MATRIX& mode, mat4<GLfloat>& mat){
			assert(mode != NORMAL_MATRIX /*|| mode != ... */);
			const GLfloat* matrixValue = NULL;

			switch(mode){
				case MODEL_MATRIX:{ //check if we need to reset our model matrix
					if(_resetModelMatrixFlag)
						_resetModelMatrix(true);
					matrixValue = glm::value_ptr(_modelMatrix);
					}break;
				case MV_MATRIX:{
					_clean(); //refresh cache
					matrixValue = glm::value_ptr(_MVCachedMatrix);
				   }break;
				case MV_INV_MATRIX:{
					_clean(); //refresh cache
					matrixValue = glm::value_ptr(glm::inverse(_MVCachedMatrix));
					}break;
				case MVP_MATRIX:{
					_clean(); //refresh cache
					matrixValue = glm::value_ptr(_MVPCachedMatrix);
					}break;
				case BIAS_MATRIX:
					matrixValue = glm::value_ptr(_biasMatrix);
					break;
			};

			assert(matrixValue != NULL);
			mat.set(matrixValue);
		}

		void _queryMatrix(const EXTENDED_MATRIX& mode, mat3<GLfloat>& mat){
			assert(mode == NORMAL_MATRIX /*|| mode == ... */);
			_clean();
			// Normal Matrix
		   _isUniformScaled ? mat.set(glm::value_ptr(glm::mat3(_MVCachedMatrix))) : 
							  mat.set(glm::value_ptr(glm::inverseTranspose(glm::mat3(_MVCachedMatrix))));
		}

		 void _clean(){
			if(_resetModelMatrixFlag) 
				_resetModelMatrix(true);

			bool MVDirty = (_MDirty || _VDirty);

			if(MVDirty)	            
				_MVCachedMatrix = _viewMatrix.top() * _modelMatrix;
			if(_PDirty || MVDirty)	
				_MVPCachedMatrix = _projectionMatrix.top() * _MVCachedMatrix;
		

			_MDirty = _VDirty = _PDirty = false;
		}
	}//namespace GL
}// namespace Divide

Commits for Divide-Framework/trunk/Source Code/Hardware/Video/OpenGL/gluOverrides.cpp

Diff revisions: vs.
Revision Author Commited Message
168 Diff Diff k1ngp1n picture k1ngp1n Sat 26 Oct, 2013 19:03:21 +0000

- Reworked the Camera class[[BR]]
— Now fully quaternion based [[BR]]
— Basic camera types added but not used yet (third person, first person, orbit) [[BR]]
- Cleaned up Material and Texture handling [[BR]]
- Added clipping plane support [[BR]]
— Similar to OpenGL fixed-function clip planes but fully shader driven [[BR]]
— Added a new class, “Plane”, that helps define clip planes [[BR]]
- Optimized the Singleton class to allow faster “getInstance” calls without performance penalties [[BR]]
-- “createInstance” must be called for each singleton class before usage. Or “gerOrCreateInstance” can be used, which is basically the former “getInstance” implementation [[BR]]
- Improved console logging by changing some heap allocations to stack and removing dependencies on the std::string class [[BR]]
- Added a lot of performance optimizations related to coding standards and redundant calculations [[BR]]
— e.g. Frustum AABB check didn’t need to recompute the AABB points as they were calculated already [[BR]]
— e.g. A vector did not need to be set to 0 on initialization as that is already it’s default state on creation [[BR]]
— e.g. Faster Framerate and Timing calculations by using less member variables that are not needed outsied of calling functions [[BR]]
- The SceneState now contains the SceneRenderState and is passed on to the SceneGraph’s update calls [[BR]]
- Better material export/import to/from XML format [[BR]]
- More bug fixes and cleanups [[BR]]

155 Diff Diff k1ngp1n picture k1ngp1n Thu 27 Jun, 2013 15:02:43 +0000

[Ionut] [[BR]]
- Small matrix stack optimization [[BR]]

152 Diff Diff k1ngp1n picture k1ngp1n Thu 20 Jun, 2013 14:23:31 +0000

[Ionut] [[BR]]
- New rendering pipeline (experimental and unstable): [[BR]]
— OpenGL 3.x clean context (glLight commands are still used for now, but UBO support is there, but not used yet) [[BR]]
— Custom matrix stacks and UBO based shader data (UBOs cause some link errors on some nVidia cards)[[BR]]
— Multi-threaded texture loading and shader compilation (mt shader compilation disabled for now. needs more tests) [[BR]]
— VAO rendering is self contained (no more enable/disable calls before a draw request) [[BR]]
— Render instance class used for rendering information [[BR]]
[[BR]]
- New unique ID generation base class: GUIDWrapper. Each class that derives from this, gets an application wide unique id on construction [[BR]]
- Added base code for an in-game editor using CEGUI [[BR]]
- Replaced some mutex locks with lockless data structures or atomic data [[BR]]
- CEGUI 0.8.2, FTGL-GL3 and GLIM 0.4 modified to support GLEW_MX if defined [[BR]]
- Dropped VS2008 support [[BR]]
- Networking library, server framework and ReCast files are now projects inside the Divide Framework solution [[BR]]
- New console command “setFov” that modifies the horizontal FoV value in realtime [[BR]]
- New console command “recompileShader” that reparses shader files, recompiles shaders and relinks shader programs who’s names match or contain the argument string [[BR]]
- New debug utility: axis angle drawn in corner of the screen if needed [[BR]]
- More ‘const’-s pasted around the code, more loop performance tweaks (allocations before a loop, tighter loops, etc), more utility member functions added to various classes [[BR]]

146 k1ngp1n picture k1ngp1n Wed 10 Apr, 2013 13:20:15 +0000

[Ionut] [[BR]]
*Final LightBranch updates 2/3 : Main trunk merge and build test (VC90, VC100, gDebugger) [[BR]]
-Merged light branch with trunk [[BR]]
-Deleted light branch [[BR]]