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
#include "Headers/QuadtreeNode.h"

#include "Rendering/Headers/Frustum.h"
#include "Managers/Headers/SceneManager.h"
#include "Hardware/Video/Headers/GFXDevice.h"
#include "Environment/Terrain/Headers/Terrain.h"
#include "Environment/Terrain/Headers/TerrainChunk.h"
#include "Core/Math/BoundingVolumes/Headers/BoundingBox.h"

void QuadtreeNode::Build(U8 depth,const vec2<U32>& pos, const vec2<U32>& HMsize, U32 minHMSize, VertexBufferObject* const groundVBO){
	_LOD = 0;

	U32 div = (U32)pow(2.0f, (F32)depth);
	vec2<U32> nodesize = HMsize/(div);
	if(nodesize.x%2==0) nodesize.x++;
	if(nodesize.y%2==0) nodesize.y++;
	vec2<U32> newsize = nodesize/2;

	if(std::max(newsize.x, newsize.y) < minHMSize)	{
		_terrainChunk = New TerrainChunk();
		_terrainChunk->Load(depth, pos, HMsize);
		_children = NULL;
		return;
	}

	// Create 4 children
	_children = New QuadtreeNode[4];

	// Compute children bounding boxes
	const vec3<F32>& center = _boundingBox.getCenter();
	_children[CHILD_NW].setBoundingBox( BoundingBox(_boundingBox.getMin(), center) );
	_children[CHILD_NE].setBoundingBox( BoundingBox(vec3<F32>(center.x, 0.0f, _boundingBox.getMin().z), vec3<F32>(_boundingBox.getMax().x, 0.0f, center.z)) );
	_children[CHILD_SW].setBoundingBox( BoundingBox(vec3<F32>(_boundingBox.getMin().x, 0.0f, center.z), vec3<F32>(center.x, 0.0f, _boundingBox.getMax().z)) );
	_children[CHILD_SE].setBoundingBox( BoundingBox(center, _boundingBox.getMax()) );
	_children[CHILD_NW].setParentShaderProgram(_parentShaderProgram);
	_children[CHILD_NE].setParentShaderProgram(_parentShaderProgram);
	_children[CHILD_SW].setParentShaderProgram(_parentShaderProgram);
	_children[CHILD_SE].setParentShaderProgram(_parentShaderProgram);
	// Compute children positions
	vec2<U32> tNewHMpos[4];
	tNewHMpos[CHILD_NW] = pos + vec2<U32>(0, 0);
	tNewHMpos[CHILD_NE] = pos + vec2<U32>(newsize.x, 0);
	tNewHMpos[CHILD_SW] = pos + vec2<U32>(0, newsize.y);
	tNewHMpos[CHILD_SE] = pos + vec2<U32>(newsize.x, newsize.y);
	_children[CHILD_NW].Build(depth+1, tNewHMpos[CHILD_NW], HMsize, minHMSize, groundVBO);
	_children[CHILD_NE].Build(depth+1, tNewHMpos[CHILD_NE], HMsize, minHMSize, groundVBO);
	_children[CHILD_SW].Build(depth+1, tNewHMpos[CHILD_SW], HMsize, minHMSize, groundVBO);
	_children[CHILD_SE].Build(depth+1, tNewHMpos[CHILD_SE], HMsize, minHMSize, groundVBO);
}

bool QuadtreeNode::computeBoundingBox(const vectorImpl<vec3<F32> >& vertices){
	assert(!vertices.empty());

	if(_terrainChunk != NULL) {
		const vectorImpl<U32>& tIndices = _terrainChunk->getIndiceArray(0);
		F32 tempMin = 100000.0f;
		F32 tempMax = -100000.0f;

		for(U32 i=0; i<tIndices.size(); i++) {
			if(tIndices[i] == TERRAIN_STRIP_RESTART_INDEX) continue;
			F32 y = vertices[ tIndices[i] ].y;

			if(y > tempMax) tempMax = y;
			if(y < tempMin) tempMin = y;
		}

		_boundingBox.setMin(vec3<F32>(_boundingBox.getMin().x, tempMin,_boundingBox.getMin().z));
		_boundingBox.setMax(vec3<F32>(_boundingBox.getMax().x, tempMax,_boundingBox.getMax().z));
	}

	if(_children != NULL) {
		for(I8 i=0; i<4; i++) {
			_children[i].computeBoundingBox(vertices);

			if(_boundingBox.getMin().y > _children[i]._boundingBox.getMin().y){
				_boundingBox.setMin(vec3<F32>(_boundingBox.getMin().x,_children[i]._boundingBox.getMin().y,_boundingBox.getMin().z));
			}

			if(_boundingBox.getMax().y < _children[i]._boundingBox.getMax().y){
				_boundingBox.setMax(vec3<F32>(_boundingBox.getMax().x,_children[i]._boundingBox.getMax().y,_boundingBox.getMax().z));
			}
		}
	}
	_boundingBox.setComputed(true);
	return true;
}

void QuadtreeNode::Destroy(){
	SAFE_DELETE_ARRAY(_children);
	SAFE_DELETE(_terrainChunk);
}

#pragma message("ToDo: Change vegetation rendering and generation system. Stop relying on terrain! -Ionut")
void QuadtreeNode::DrawGrass(U32 geometryIndex, Transform* const parentTransform){
	if(_LOD < 0 ) return;

	if(!_children){
		assert(_terrainChunk);
		 _terrainChunk->DrawGrass(_LOD, _camDistance, geometryIndex, parentTransform);
	}else{
		_children[CHILD_NW].DrawGrass(geometryIndex, parentTransform);
		_children[CHILD_NE].DrawGrass(geometryIndex, parentTransform);
		_children[CHILD_SW].DrawGrass(geometryIndex, parentTransform);
		_children[CHILD_SE].DrawGrass(geometryIndex, parentTransform);
	}
}

void QuadtreeNode::DrawBBox(){
	if(!_children) {
		assert(_terrainChunk);
		GFX_DEVICE.drawBox3D(_boundingBox.getMin(),_boundingBox.getMax(),mat4<F32>());
	}else {
		if( _LOD < 0 ) return;
		_children[CHILD_NW].DrawBBox();
		_children[CHILD_NE].DrawBBox();
		_children[CHILD_SW].DrawBBox();
		_children[CHILD_SE].DrawBBox();
	}
}

void QuadtreeNode::DrawGround(I32 options,VertexBufferObject* const terrainVBO){

	const Frustum& frust = Frustum::getInstance();
	const vec3<F32>& center = _boundingBox.getCenter();
	const vec3<F32>& eyePos = frust.getEyePos();
	F32 radius = (_boundingBox.getMax()-center).length();

	if(options & CHUNK_BIT_TESTCHILDREN) {
		if(!_boundingBox.ContainsPoint(eyePos))	{
			switch(frust.ContainsSphere(center, radius)) {
				case FRUSTUM_OUT:	return;
				case FRUSTUM_IN:	options &= ~CHUNK_BIT_TESTCHILDREN;	break;
				case FRUSTUM_INTERSECT:	{
					switch(frust.ContainsBoundingBox(_boundingBox)) {
						case FRUSTUM_IN: options &= ~CHUNK_BIT_TESTCHILDREN; break;
						case FRUSTUM_OUT: return;
					};//inner switch
				};//case FRUSTUM_INTERSECT
			};//outer case
		}//if
	}//CHUNK_BIT_TESTCHILDREN option

	_LOD = 0;

	if(!_children) {
		assert(_terrainChunk);

		if(options & CHUNK_BIT_WATERREFLECTION) {
			_terrainChunk->DrawGround(Config::TERRAIN_CHUNKS_LOD-1,_parentShaderProgram,terrainVBO);
			return;
		}

		vec3<F32> vEyeToChunk = vec3<F32>(center - eyePos);
		_camDistance = vEyeToChunk.length();

		if(_camDistance > Config::TERRAIN_CHUNK_LOD1)		_LOD = 2;
		else if(_camDistance > Config::TERRAIN_CHUNK_LOD0)	_LOD = 1;

		_terrainChunk->DrawGround(_LOD,_parentShaderProgram,terrainVBO);
	}else{
		_children[CHILD_NW].DrawGround(options, terrainVBO);
		_children[CHILD_NE].DrawGround(options, terrainVBO);
		_children[CHILD_SW].DrawGround(options, terrainVBO);
		_children[CHILD_SE].DrawGround(options, terrainVBO);
	}
}

Commits for Divide-Framework/trunk/Source Code/Environment/Terrain/Quadtree/QuadtreeNode.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]]

167 Diff Diff k1ngp1n picture k1ngp1n Mon 22 Jul, 2013 16:14:32 +0000

[Ionut] [[BR]]
- Changed triangle list creation for terrain (reference: http://3dgep.com/?p=1116#The_Terrain_Class) [[BR]]
- NavMesh creation now works properly for terrain [[BR]]

162 Diff Diff k1ngp1n picture k1ngp1n Mon 15 Jul, 2013 19:14:45 +0000

[Ionut] [[BR]]
- Improved terrain rendering a lot by using OpenGL’s primitive restart feature. Now terrain is rendered in n-draw calls where n is the number of terrain chunks in the quadtree (main scene has 4 chunks per terrain). [[BR]]
- Some terrain nav mesh generation code fixed. Still not 100% working [[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]]

151 Diff Diff k1ngp1n picture k1ngp1n Tue 07 May, 2013 00:00:52 +0000

[Ionut] [[BR]]
- Better ReCast integration [[BR]]
— Any entity can be used as an obstacle in the NavMesh if that’s specified in each scene’s assets.xml file for said entity [[BR]]
— New console command, “createNavMesh”, that passes geometry data to ReCast [[BR]]
-— NavMesh generation is not yet complete [[BR]]
- Better PhysX integration [[BR]]
— Each scene passes data to and gets data from the Physics API better and safer[[BR]]
- Multi-threaded support extended: [[BR]]
— Event class replaced with Task [[BR]]
— Kernel uses a threadpool for scene tasks [[BR]]
— Each task can be added to a different threadpool if needed [[BR]]
— Most critical sections use the new boost::atomic wrapper for thread safety [[BR]]
- Rendering system updated [[BR]]
— VBO’s keep track of the geometry type internally [[BR]]
— Rendering by specific element list is internal to the VBO [[BR]]
— VBO’s can draw a “lite” version that doesn’t send Tangent, BiTangent and TexCoord data for depth rendering (disabled) [[BR]]
- Reflectors now offer a preview of the generated reflective texture if needed [[BR]]
- Buttons are now added and rendered by CEGUI [[BR]]
[[BR]]
Deprecation: [[BR]]
- Removed fixed pipeline material system [[BR]]
- Removed BoundingBox late update system [[BR]]
- Shadow references in the material system are now depth references [[BR]]
[[BR]]
Bug fixes: [[BR]]
- Problematic FBO double bind check removed [[BR]]
- Faster terrain rendering via chunk size selection through each scene’s terrain.xml[[BR]]
- Rendering is paused when the window is minimized [[BR]]
- CEGUI and impostors now render properly in deferred rendering mode [[BR]]
- Fixed various level 4 (VS2008) warnings [[BR]]
- Better state management and cleaning [[BR]]
- Better SceneGraph node management and trasformation/AABB update calls [[BR]]
- AITenisScene has proper collisions now [[BR]]

146 Diff Diff 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]]

117 Diff Diff k1ngp1n picture k1ngp1n Tue 05 Jun, 2012 17:30:40 +0000

[Ionut] [[BR]]
-Separated responsibilities between “Application” and “Kernel” [[BR]]
--“Application” handles data such as window dimensions, logs, “ParamHandler” etc [[BR]]
--“Kernel” handles the main loop, SFX, GFX, physics, sceneManager etc updates [[BR]]
---“Kernel” is now a “Core” component [[BR]]
-Reduced coupling between some classes by passing more info via parameters rather than relying on singleton access [[BR]]
--Ex: eyePos in “Terrain”,“Water” and “Trigger” classes is now passed as a "vec3<F32>" on render call rather than querying “CameraManager” [[BR]]
-Reworked “GLWrapper” shutdown routine [[BR]]
Singleton witch hunt [[BR]]
-“Kernel” is no longer a singleton and it’s initialized on application startup in the “Application” class[[BR]]
-“CameraManager” is no longer a singleton and it’s instantiated in the kernel [[BR]]

116 Diff Diff k1ngp1n picture k1ngp1n Mon 04 Jun, 2012 22:27:07 +0000

[Ionut] [[BR]]
-Removed now useless “BaseCache” class as a simple unordered_map in each manager-type class is all that’s needed [[BR]]
-Moved loading responsibility from each Resource implementation to each "ImplResourceLoader<T>" class (defaults via macro’s are available for convenience) [[BR]]
--Resources now have a “setInitialData” method for setting post-load values [[BR]]
--Also added a loader for Particle Emitters [[BR]]
-Added a new class, “HardwareResource” (for textures, shaders, etc) that needs special loading routines to facilitate future multi-threaded asset streaming [[BR]]
--HardwareResource’s have a “generateHWResource” that should be called after threaded loading routines join with main thread [[BR]]
-Renamed “Guardian” class to “Kernel” as that’s what it’s new responsibility will be in future revisions [[BR]]
-Added the “threadpool” library from here: http://threadpool.sourceforge.net/ (not used yet) [[BR]]
-Added some more macro’s and cleanups [[BR]]

111 Diff Diff k1ngp1n picture k1ngp1n Tue 08 May, 2012 21:49:31 +0000

[Ionut] [[BR]]
-Added animation support based on Scott Lee’s animation loader library added a few revision’s back [[BR]]
--Added cached skeleton rendering to the library [[BR]]
--Added cached AABB transformations based on current animation frame [[BR]]
--Scene animators are added per submesh and only processed if said submesh is visible and only in the rendering stage: FINAL_STAGE [[BR]]
[[BR]]
-Added support for shader-based VBO data upload (glVertexAttribPointer) with full backwards compatibility to old method (glTexCoordPointer)[[BR]]
-Added support for Index Buffer Object (improper name) indice upload for VBO’s with full backwards compatibility to old method [[BR]]
-Reworked coordination class to better handle AIEntity teams [[BR]]
-Added “updateSceneState(currentTime)” callback that is called once per frame (used for animation update)[[BR]]
-Added “initializeAI/deinitializeAI” scene callbacks for AI creation/destruction [[BR]]
-Templatized the Quaternion class [[BR]]
-Added a “drawLines” subroutine to the rendering api[[BR]]
-Disabled tree loading in MainScene as current ASSIMP implementation is slow. Will be restored after backing and loading models to own format is added in next revision [[BR]]
-Other various small performance tweaks [[BR]]

106 k1ngp1n picture k1ngp1n Wed 28 Mar, 2012 21:50:23 +0000

[Ionut] [[BR]]
Unstable revision – New animation code is not yet optimized and loading performance is low [[BR]]
[[BR]]
-Added animation loading and bone matrix calculations (actual skinning not implemented yet)[[BR]]
-Modified VBO classes to support dynamic data and faster updates [[BR]]
-Templatized Math classes (vec2,vec3,vec4,mat3,mat4) for greater flexibility [[BR]]
-Separated Rendering API from Rendering API version [[BR]]
-Fixed buggy GL error checking [[BR]]
-Small bugs fixed in Projectile and Weapon classes [[BR]]