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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
   Copyright (c) 2013 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.
   
   Permission is hereby granted, free of charge, to any person obtaining a copy of this software
   and associated documentation files (the "Software"), to deal in the Software without restriction,
   including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
   and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _VERTEX_BUFFER_OBJECT_H
#define _VERTEX_BUFFER_OBJECT_H

#include <iostream>
#include <assert.h>
#include "Utility/Headers/Vector.h"
#include "Utility/Headers/GUIDWrapper.h"
#include "Core/Math/Headers/MathClasses.h"
#include "Hardware/Video/Headers/RenderAPIEnums.h"

enum PrimitiveType;
enum GFXDataFormat;
class ShaderProgram;
/// Vertex Buffer Object interface class to allow API-independent implementation of data
/// This class does NOT represent an API-level VBO, such as: GL_ARRAY_BUFFER / D3DVERTEXBUFFER
/// It is only a "buffer" for "vertex info" abstract of implementation. (e.g.: OGL uses a vertex array object for this)
class VertexBufferObject : public GUIDWrapper {
public:
    VertexBufferObject(const PrimitiveType& type) : GUIDWrapper(),
						    _type(type),
							_computeTriangles(true),
							_largeIndices(false),
							_format(UNSIGNED_SHORT),
							_currentShader(NULL),
							_firstElementPtr(NULL),
							_instanceCount(1),
							_indexDelimiter(0)
	{
		_depthPass = _forceOptimizeForDepth = false;
		_VBOid = _IBOid = _DepthVBOid = _LODcount = _rangeCount = 0;
		_useHWIndices = _optimizeForDepth = true;
		Reset();
	}

   	virtual ~VertexBufferObject()
	{
		_VBOid = _DepthVBOid = _IBOid = _LODcount = 0;
		_currentShader = NULL;
		Reset();
	}

	virtual bool Create(bool staticDraw = true) = 0;
	virtual void Destroy() = 0;

	virtual bool SetActive() = 0;

	virtual void Draw(const U8 LODindex = 0) = 0;
    virtual void DrawRange() = 0;

	virtual void setShaderProgram(ShaderProgram* const shaderProgram) = 0;
	inline ShaderProgram* const currentShader()  {return _currentShader;}

	inline void setInstanceCount(const U32 instanceCount)    {_instanceCount = instanceCount;}
	inline void setRangeCount(const U32 rangeCount)          {_rangeCount = rangeCount;}
	inline void setFirstElement(const void* firstElementPtr) {_firstElementPtr = firstElementPtr;}
	inline void setDepthPass(bool state = false)             {if(_optimizeForDepth) _depthPass = state;}

    inline void useHWIndices(bool state = true)              {assert(!_created); _useHWIndices = state;}
	inline void useLargeIndices(bool state = true)           {assert(!_created); _largeIndices = state; _format = _largeIndices ? UNSIGNED_INT : UNSIGNED_SHORT;}
	inline void setIndicesDelimiter(U32 delimiterValue)      {_indexDelimiter = delimiterValue;}
	inline void computeTriangles(bool state = true)          {_computeTriangles = state;}
	inline void reservePositionCount(U32 size)  {_dataPosition.reserve(size);}
	inline void reserveNormalCount(U32 size)    {_dataNormal.reserve(size);}
	inline void reserveTangentCount(U32 size)   {_dataTangent.reserve(size);}
	inline void reserveBiTangentCount(U32 size) {_dataBiTangent.reserve(size);}
	inline void reserveIndexCount(U32 size)     {_largeIndices ? _hardwareIndicesL.reserve(size) :_hardwareIndicesS.reserve(size);}

	inline void resizePositionCount(U32 size, const vec3<F32>& defaultValue = vec3<F32>(0.0f))  {
		_dataPosition.resize(size,defaultValue);
	}

	inline void resizeNormalCount(U32 size, const vec3<F32>& defaultValue = vec3<F32>(0.0f))    {
		_dataNormal.resize(size,defaultValue);
	}

	inline void resizeTangentCount(U32 size, const vec3<F32>& defaultValue = vec3<F32>(0.0f))   {
		_dataTangent.resize(size,defaultValue);
	}

	inline void resizeBiTangentCount(U32 size, const vec3<F32>& defaultValue = vec3<F32>(0.0f)) {
		_dataBiTangent.resize(size,defaultValue);
	}

	inline vectorImpl<vec2<F32> >&  getTexcoord()    { _texcoordDirty  = true; return _dataTexcoord;}
	inline vectorImpl<vec4<U8>  >&  getBoneIndices() { _indicesDirty   = true; return _boneIndices;}
	inline vectorImpl<vec4<F32> >&  getBoneWeights() { _weightsDirty   = true; return _boneWeights;}

	inline vectorImpl<vec3<U32> >&  getTriangles()   {return _dataTriangles;}
	inline const vec3<F32>&         getMinPosition() {return _minPosition;}
	inline const vec3<F32>&         getMaxPosition() {return _maxPosition;}

	inline const vectorImpl<vec3<F32> >&  getPosition()	 const {return _dataPosition;}
	inline const vectorImpl<vec3<F32> >&  getNormal()	 const {return _dataNormal;}
	inline const vectorImpl<vec3<F32> >&  getTangent()	 const {return _dataTangent;}
	inline const vectorImpl<vec3<F32> >&  getBiTangent() const {return _dataBiTangent;}

	inline const vec3<F32>&               getPosition(U32 index)  const {return _dataPosition[index];}
	inline const vec3<F32>&               getNormal(U32 index)    const {return _dataNormal[index];}
	inline const vec3<F32>&               getTangent(U32 index)   const {return _dataTangent[index];}
	inline const vec3<F32>&               getBiTangent(U32 index) const {return _dataBiTangent[index];}
    inline const PrimitiveType&           getPrimitiveType()      const {return _type;}
	virtual bool queueRefresh() = 0;

	inline U32  getIndexCount()     const { return _largeIndices ? _hardwareIndicesL.size() : _hardwareIndicesS.size();}
	inline U32  getIndex(U32 index) const { return _largeIndices ? _hardwareIndicesL[index] : _hardwareIndicesS[index];}

	inline void addIndex(U32 index){
		if(_largeIndices){
			_hardwareIndicesL.push_back(index);
		}else{
			_hardwareIndicesS.push_back(static_cast<U16>(index));
		}
	}

	inline void addPosition(const vec3<F32>& pos){
		if(pos.x > _maxPosition.x)	_maxPosition.x = pos.x;
		if(pos.x < _minPosition.x)	_minPosition.x = pos.x;
		if(pos.y > _maxPosition.y)	_maxPosition.y = pos.y;
		if(pos.y < _minPosition.y)	_minPosition.y = pos.y;
		if(pos.z > _maxPosition.z)	_maxPosition.z = pos.z;
		if(pos.z < _minPosition.z)	_minPosition.z = pos.z;
		_dataPosition.push_back(pos);
		_positionDirty  = true;
	}

	inline void addNormal(const vec3<F32>& norm){
		_dataNormal.push_back(norm);
		_normalDirty = true;
	}
	
	inline void addTangent(const vec3<F32>& tangent){
		_dataTangent.push_back(tangent);
		_tangentDirty = true;
	}

	inline void addBiTangent(const vec3<F32>& bitangent){
		_dataBiTangent.push_back(bitangent);
		_bitangentDirty = true;
	}

	inline void setIndiceLimits(const vec2<U32>& indiceLimits, U8 LODindex = 0) {
		assert(LODindex < _indiceLimits.size());
	   _indiceLimits[LODindex] = indiceLimits;
	}

	inline void modifyPositionValue(U32 index, const vec3<F32>& newValue){
		assert(index < _dataPosition.size());
		_dataPosition[index] = newValue;
		_positionDirty = true;
	}

	inline void modifyNormalValue(U32 index, const vec3<F32>& newValue)  {
		assert(index < _dataNormal.size());
		_dataNormal[index] = newValue;
		_normalDirty = true;
	}

	inline void modifyTangentValue(U32 index, const vec3<F32>& newValue)  {
		assert(index < _dataTangent.size());
		_dataTangent[index] = newValue;
		_tangentDirty = true;
	}

	inline void modifyBiTangentValue(U32 index, const vec3<F32>& newValue)  {
		assert(index < _dataBiTangent.size());
		_dataBiTangent[index] = newValue;
		_bitangentDirty = true;
	}

    inline void optimizeForDepth(bool state = true,bool force = false) {
		_optimizeForDepth = state;
		_forceOptimizeForDepth = force;
	}

	inline void Reset() {
		_created = false;  
		_VBOoffsetPosition = _VBOoffsetNormal = _VBOoffsetTexcoord = _VBOoffsetTangent = 0;
		_VBOoffsetBiTangent = _VBOoffsetBoneIndices = _VBOoffsetBoneWeights = 0;
        _VBOoffsetBoneIndicesDEPTH = _VBOoffsetBoneWeightsDEPTH = 0;
		_dataPosition.clear();
		_dataNormal.clear();
		_dataTexcoord.clear();
		_dataTangent.clear();
		_dataBiTangent.clear();
		_boneIndices.clear();
		_boneWeights.clear();
		_hardwareIndicesL.clear();
		_hardwareIndicesS.clear();
		_dataTriangles.clear();
		_indiceLimits.resize(Config::SCENE_NODE_LOD, vec2<U32>(0,0));
		_positionDirty = _normalDirty = _texcoordDirty = _tangentDirty = _bitangentDirty = _indicesDirty = _weightsDirty = true;
		_minPosition = vec3<F32>(10000.0f);
		_maxPosition = vec3<F32>(-10000.0f);
	}

protected:
	virtual void checkStatus() = 0;
	virtual bool Refresh() = 0;
	virtual bool CreateInternal() = 0;
    virtual bool computeTriangleList() = 0;

protected:

	U32         _IBOid;
	U32  		_VBOid, _DepthVBOid;
	U8          _LODcount; ///<Number of LOD nodes in this buffer
	///How many elements should we actually render when using "DrawRange"
	U32         _rangeCount;
	///The format of the buffer data
	GFXDataFormat _format;
	///Number of instances to draw
	U32         _instanceCount;
	///An index value that separates ojects (OGL: primitive restart index)
	U32         _indexDelimiter;
	ptrdiff_t	_VBOoffsetPosition;
	ptrdiff_t	_VBOoffsetNormal;
	ptrdiff_t	_VBOoffsetTexcoord;
	ptrdiff_t	_VBOoffsetTangent, _VBOoffsetBiTangent;
	ptrdiff_t   _VBOoffsetBoneIndices, _VBOoffsetBoneWeights;
    ptrdiff_t   _VBOoffsetBoneIndicesDEPTH, _VBOoffsetBoneWeightsDEPTH;

	vectorImpl<vec2<U32> > _indiceLimits;
	///Used for creating an "IBO". If it's empty, then an outside source should provide the indices
	vectorImpl<U32>        _hardwareIndicesL;
	vectorImpl<U16>        _hardwareIndicesS;
	vectorImpl<vec3<F32> > _dataPosition;
	vectorImpl<vec3<F32> > _dataNormal;
	vectorImpl<vec2<F32> > _dataTexcoord;
	vectorImpl<vec3<F32> > _dataTangent;
	vectorImpl<vec3<F32> > _dataBiTangent;
	vectorImpl<vec4<U8>  > _boneIndices;
	vectorImpl<vec4<F32> > _boneWeights;
	vectorImpl<vec3<U32> > _dataTriangles;	//< 3 indices, pointing to position values, that form a triangle in the mesh.
	vec3<F32> _minPosition,  _maxPosition;
    ///Some entities use their own indices for rendering (e.g. Terrain LOD system)
    bool _useHWIndices;
	///Use ither U32 or U16 indices. Always prefer the later
	bool _largeIndices;
	///Some objects need triangle data in order for other parts of the engine to take advantage of direct data (physics, navmeshes, etc)
	bool _computeTriangles;
	/// Cache system to update only required data
	bool _positionDirty, _normalDirty, _texcoordDirty, _tangentDirty, _bitangentDirty, _indicesDirty, _weightsDirty;
    ///Store position and animation data in different VBO so rendering to depth is faster (it skips tex coords, tangent and bitangent data upload to GPU mem)
    ///Set this to FALSE if you need bump/normal/parallax mapping in depth pass (normal mapped object casts correct shadows)
    bool _optimizeForDepth;
    bool _forceOptimizeForDepth; //<Override vbo requirements for optimization
    ///If it's true, use depth only VBO/VAO else use the regular buffers
    bool _depthPass;
	///Was the data submited to the GPU?
	bool _created;
	///Used for VertexAttribPointer data.
	ShaderProgram* _currentShader;
	///Pointer to the first element in the buffer
	const void *_firstElementPtr;
    ///The format the data is in (TRIANGLES, TRIANGLE_STRIP,QUADS,etc)
    PrimitiveType  _type;
};

#endif

Commits for Divide-Framework/trunk/Source Code/Hardware/Video/Buffers/VertexBufferObject/Headers/VertexBufferObject.h

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

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

160 Diff Diff k1ngp1n picture k1ngp1n Wed 10 Jul, 2013 17:07:04 +0000

[Ionut] [[BR]]
- Changed licensing from LGPL to the MIT license [[BR]]
— Code can now be used in non-commercial or commercial closed or open source projects [[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]]

141 Diff Diff k1ngp1n picture k1ngp1n Wed 30 Jan, 2013 19:35:31 +0000

[Ionut] [[BR]]
-Updated to boost 1.52 and CEGUI 0.7.9 [[BR]]
-Updated to PhysX 3.2 [[BR]]
-Updated copyright notices [[BR]]

122 k1ngp1n picture k1ngp1n Mon 11 Jun, 2012 14:39:08 +0000

[Ionut] [[BR]]
-Restructured “Hardware” folder to match the rest of the projects header-separation pattern [[BR]]