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

#include "Graphs/Headers/SceneGraph.h"
#include "Scenes/Headers/SceneState.h"
#include "Core/Math/Headers/Transform.h"
#include "Core/Resources/Headers/ResourceCache.h"

#include "Geometry/Shapes/Headers/SubMesh.h"
#include "Geometry/Shapes/Headers/Predefined/Box3D.h"
#include "Geometry/Shapes/Headers/Predefined/Sphere3D.h"
#include "Geometry/Shapes/Headers/Predefined/Quad3D.h"
#include "Geometry/Shapes/Headers/Predefined/Text3D.h"

#include "Hardware/Video/Headers/GFXDevice.h"

//Max number of frames before an unused primitive is deleted (default: 180 - 3 seconds at 60 fps)
const GLint GLIM_MAX_FRAMES_ZOMBIE_COUNT = 180;

GLint GL_API::FRAME_DRAW_CALLS = 0;
GLint GL_API::FRAME_DRAW_CALLS_PREV = 0;
GLuint64 GL_API::FRAME_DURATION_GPU = 0;
GLuint GL_API::FRAME_COUNT = 0;

#include <glim.h>

namespace IMPrimitiveValidation{
    inline bool zombieCountMatch(glIMPrimitive* const priv){
        if(priv->_canZombify) return priv->zombieCounter() < GLIM_MAX_FRAMES_ZOMBIE_COUNT;
        else return true;
    }
}

void GL_API::beginFrame(){
#ifdef _DEBUG
    GLuint queryId = _queryID[_queryBackBuffer][0];
    glBeginQuery(GL_TIME_ELAPSED, queryId);
#endif
    GL_API::clearColor(DefaultColors::DIVIDE_BLUE(), 0, true);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT/* | GL_STENCIL_BUFFER_BIT*/);
    GL_API::registerDrawCall();
    SET_DEFAULT_STATE_BLOCK();
}

void GL_API::endFrame(){

    //Remove dead primitives in 3 steps (or we could automate this with shared_ptr?):
    //1) Partition the vector in 2 parts: valid objects first, zombie objects second
    vectorImpl<glIMPrimitive* >::iterator zombie = std::partition(_glimInterfaces.begin(),
                                                                  _glimInterfaces.end(),
                                                                  IMPrimitiveValidation::zombieCountMatch);
    //2) For every zombie object, free the memory it's using
    for( vectorImpl<glIMPrimitive *>::iterator i = zombie ; i != _glimInterfaces.end() ; ++i ){
        SAFE_DELETE(*i);
    }

    //3) Remove all the zombie objects once the memory is freed
    _glimInterfaces.erase(zombie, _glimInterfaces.end());

    //unbind all states (shaders, textures, buffers)
    clearStates(false,false,false,true);

    glfwSwapBuffers(Divide::GLUtil::_mainWindow);
    GL_API::FRAME_COUNT++;

#ifdef _DEBUG
    glEndQuery(GL_TIME_ELAPSED);

    GLuint query = GL_API::FRAME_COUNT % 4;
    
    _queryBackBuffer = query;
    _queryFrontBuffer = 3 - _queryBackBuffer;
    
#endif
    GL_API::FRAME_DRAW_CALLS_PREV = GL_API::FRAME_DRAW_CALLS;
    GL_API::FRAME_DRAW_CALLS = 0;
}

void GL_API::debugDraw(const SceneRenderState& sceneRenderState){
    drawDebugAxisInternal(sceneRenderState);

    _imShader->bind();

    NS_GLIM::GLIM_BATCH::s_bForceWireframe = false;

    for(glIMPrimitive* priv : _glimInterfaces){
        if(priv->paused())
            continue;
        if(!priv->_inUse && priv->_canZombify) {
            ++priv->_zombieCounter;
            continue;
        }

        if(!priv->_setupStates.empty()){
            priv->_setupStates();
        }
        
        SET_STATE_BLOCK(priv->stateHash(), true);
        
        if(priv->_hasLines){
            glLineWidth(std::min(priv->_lineWidth, (F32)_lineWidthLimit));
        }

        bool texture = (priv->_texture != nullptr);

        if(texture){
            priv->_texture->Bind(0);
        }

        _imShader->Uniform("useTexture", texture);

        _imShader->uploadNodeMatrices();

        priv->renderBatch(priv->forceWireframe());

        if(priv->_hasLines) {
            glLineWidth(1.0f);
        }

        if(!priv->_resetStates.empty()){
            priv->_resetStates();
        }
        if(priv->_canZombify){
            priv->_inUse = false;
        }
    }
    _imShader->unbind();
}

void GL_API::flush(){
    clearStates(false,false,false,false);
}

void GL_API::drawBox3D(const vec3<GLfloat>& min,const vec3<GLfloat>& max, const mat4<GLfloat>& globalOffset){
    IMPrimitive* priv = getOrCreateIMPrimitive();

    priv->_hasLines = true;
    priv->_lineWidth = 4.0f;
    mat4<F32> offset(globalOffset);

    priv->stateHash(GFX_DEVICE._defaultStateBlockHash);
    priv->setRenderStates(DELEGATE_BIND(&GL_API::setupLineState, this, offset, false),
                          DELEGATE_BIND(&GL_API::releaseLineState, this, false));
    priv->beginBatch();

    vec4<GLubyte> color(0,0,255,255);
    priv->attribute4ub("inColorData", color);

    priv->begin(LINE_LOOP);
        priv->vertex( vec3<GLfloat>(min.x, min.y, min.z) );
        priv->vertex( vec3<GLfloat>(max.x, min.y, min.z) );
        priv->vertex( vec3<GLfloat>(max.x, min.y, max.z) );
        priv->vertex( vec3<GLfloat>(min.x, min.y, max.z) );
    priv->end();

    priv->begin(LINE_LOOP);
        priv->vertex( vec3<GLfloat>(min.x, max.y, min.z) );
        priv->vertex( vec3<GLfloat>(max.x, max.y, min.z) );
        priv->vertex( vec3<GLfloat>(max.x, max.y, max.z) );
        priv->vertex( vec3<GLfloat>(min.x, max.y, max.z) );
    priv->end();

    priv->begin(LINES);
        priv->vertex( vec3<GLfloat>(min.x, min.y, min.z) );
        priv->vertex( vec3<GLfloat>(min.x, max.y, min.z) );
        priv->vertex( vec3<GLfloat>(max.x, min.y, min.z) );
        priv->vertex( vec3<GLfloat>(max.x, max.y, min.z) );
        priv->vertex( vec3<GLfloat>(max.x, min.y, max.z) );
        priv->vertex( vec3<GLfloat>(max.x, max.y, max.z) );
        priv->vertex( vec3<GLfloat>(min.x, min.y, max.z) );
        priv->vertex( vec3<GLfloat>(min.x, max.y, max.z) );
    priv->end();

    priv->endBatch();
}

void GL_API::setupLineState(const mat4<F32>& mat, const bool ortho){
    GFX_DEVICE.pushWorldMatrix(mat,true);

    if(ortho)
        GFX_DEVICE.setViewport(vec4<GLint>(_cachedResolution.width - 128, 0, 128, 128));
}


void GL_API::releaseLineState(const bool ortho){
    GFX_DEVICE.popWorldMatrix();
    if(ortho)
        GFX_DEVICE.restoreViewport();
}

void GL_API::drawDebugAxisInternal(const SceneRenderState& sceneRenderState){
    if(!GFX_DEVICE.drawDebugAxis()) return;
    
    if(_axisPointsA.empty()){
        vec3<GLfloat> ORG(0,0,0);
        vec3<GLfloat> XP(1,0,0);
        vec3<GLfloat> YP(0,1,0);
        vec3<GLfloat> ZP(0,0,1);

        //Red X-axis
        _axisPointsA.push_back(ORG);
        _axisPointsB.push_back(XP);
        _axisColors.push_back(vec4<GLubyte>(255,0,0,255));

        //Green Y-axis
        _axisPointsA.push_back(ORG);
        _axisPointsB.push_back(YP);
        _axisColors.push_back(vec4<GLubyte>(0,255,0,255));

        //Blue Z-axis
        _axisPointsA.push_back(ORG);
        _axisPointsB.push_back(ZP);
        _axisColors.push_back(vec4<GLubyte>(0,0,255,255));
    }

    vec3<GLfloat> eyeVector = -(sceneRenderState.getCameraConst().getViewDir() * 2);
    mat4<F32> offset(eyeVector, vec3<F32>(0.0f), vec3<F32>(GFX_DEVICE._viewMatrix.m[0][1], GFX_DEVICE._viewMatrix.m[1][1], GFX_DEVICE._viewMatrix.m[2][1]));
    drawLines(_axisPointsA, _axisPointsB, _axisColors, offset, true, true);
}

void GL_API::drawLines(const vectorImpl<vec3<GLfloat> >& pointsA,
                       const vectorImpl<vec3<GLfloat> >& pointsB,
                       const vectorImpl<vec4<GLubyte> >& colors,
                       const mat4<GLfloat>& globalOffset,
                       const bool orthoMode,
                       const bool disableDepth){
    // We need a perfect pair of point A's to point B's
    // We need a color for each line, even if it is the same one
    if(pointsA.size() != pointsB.size() || pointsA.size() != colors.size()) return;
    

    IMPrimitive* priv = getOrCreateIMPrimitive();

    priv->_hasLines = true;
    priv->_lineWidth = std::min((F32)_lineWidthLimit, 5.0f);

    if(!priv->hasRenderStates()){
        priv->stateHash(disableDepth ? GFX_DEVICE._defaultStateNoDepthHash : GFX_DEVICE._defaultStateBlockHash);
        priv->setRenderStates(DELEGATE_BIND(&GL_API::setupLineState, this, globalOffset, orthoMode),
                              DELEGATE_BIND(&GL_API::releaseLineState, this, orthoMode));
    }

    priv->beginBatch();

    priv->attribute4ub("inColorData", colors[0]);

    priv->begin(LINES);
    for(GLushort i = 0; i < pointsA.size(); i++){
        priv->attribute4ub("inColorData", colors[i]);
        priv->vertex( pointsA[i] );
        priv->vertex( pointsB[i] );
    }

    priv->end();
    priv->endBatch();
}

void GL_API::drawPoints(GLuint numPoints) {
    GL_API::setActiveVAO(_pointDummyVAO);
    glDrawArrays(GL_POINTS, 0, numPoints);
    GL_API::registerDrawCall();
}

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

Diff revisions: vs.
Revision Author Commited Message
280 Diff Diff IonutCava picture IonutCava Sat 28 Jun, 2014 19:11:37 +0000

[Ionut] [[BR]]
- Improve ClipPlane management (bunch equations into the matrix shader buffer) [[BR]]
- Immediate mode emulation primitives set their own state based on specified hash instead of relying on state functions to be defined [[BR]]
- updateStates() function is now called right before the actual draw call to facilitate future batching work [[BR]]
- added tracked bool values (similar to those in ShaderInfo) to SGN class to fix selection bug. [[BR]]
— will probably create a “stateTracker” class to allow multiple classes to use tracked variables without all of the code duplication [[BR]]

275 Diff Diff IonutCava picture IonutCava Fri 13 Jun, 2014 15:11:02 +0000

[Ionut [[BR]]
- Removed all GLM dependencies (great library, but my math class can handle all of my requirements now) [[BR]]
- Moved view/projection/texture matrix management to GFXDevice class (from API specific classes) [[BR]]

273 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 20:34:00 +0000

[Ionut] [[BR]]
- Improved batching part2: [[BR]]
— Moved all bone transformation matrices upload from uniform functions in SceneNode to Shader Storage Buffers in AnimationController class with updates controlled by SceneGraphNode’s AnimationComponent [[BR]]
-— No double-buffering or efficient mapping of data yet. Just raw buffer updates [[BR]]
— Replaced all RenderStateBlock* pointers with I64 hash values [[BR]]
-— Will be used later in draw commands as per-shader state hash [[BR]]
— Moved getShaderProgram from Material to Material::ShaderInfo [[BR]]
-— Improved redundant uniform checks [[BR]]
— Improved texture unit changing in case of redundant texture bind case (i.e. skip changing the texture unit) [[BR]]
[[BR]]
- Improved float and double comparison functions using algorithms described in http://randomascii.wordpress.com/2012/02/13/dont-store-that-in-a-float/ [[BR]]
- Added a new utility function, DIVIDE_ASSERT, to more easily bind an assert check with a specific message [[BR]]
- Added missing files from Forward+ renderer’s initial code [[BR]]

272 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 11:30:51 +0000

[Ionut] [[BR]]
- Added initial code for Forward+ rendering (grid based light culling) [[BR]]
- Simplified Light class [[BR]]
- Moved more light uniform data to ShaderBuffers [[BR]]
- Double buffered grass rendering [[BR]]
- Added a better attribute interface to GenericVertexData [[BR]]
- Fixed screenshot capture [[BR]]
- Fixed texture double-bind checks [[BR]]

268 Diff Diff IonutCava picture IonutCava Wed 04 Jun, 2014 10:20:27 +0000

[IonutCava] [[BR]]
- Terrain and vegetation updates: [[BR]]
— Use standard phong lighting model [[BR]]
— Separate grass patches per chunk [[BR]]
— Reduce number of required texture bind points for terrain by adding both textures and normal maps in a single texture array [[BR]]
— Draw terrain with 2 drawcalls (using glMultiDrawElements twice, once for LoD == 0 and once for LoD > 0) [[BR]]
[[BR]]
- Buffer management updates: [[BR]]
— Unified buffer binding system [[BR]]
— Made Uniform buffer objects visible to all classes and moved lightUBO to LightManager, matricesUBO to GFXDevice etc [[BR]]
— Added initial support for Shader Buffer Objects [[BR]]
— Moved viewport management to GFXDevice class [[BR]]
[[BR]]
- Rendering improvements: [[BR]]
— Added Hi-Z occlusion culling to instanceCull shader (using Hi-Z depth buffer constructed in GFXDevice class) [[BR]]
— Resolved issues with shadow maps overriding texture bind locations [[[BR]]
— Improved shader and shader program loading [[BR]]
— Improved material transparency support [[BR]]
— Added buffer lock manager class from “Approaching Zero Driver Overhead in OpenGL (Presented by NVIDIA)” speech at GDC14 [[BR]]

267 Diff Diff k1ngp1n picture k1ngp1n Wed 28 May, 2014 11:08:12 +0000

[Ionut] [[BR]]
- Improved texture handling: [[BR]]
— No more texture unbind (except when clearing the frame state) [[BR]]
— Moved texture bind checking to the GL_API class [[BR]]
- Fixed a crash related to vegetation loading due to compiler optimizations [[BR]]
- removed all “releaseMaterial” functions as they are no longer needed [[BR]]

264 Diff Diff k1ngp1n picture k1ngp1n Tue 27 May, 2014 13:04:38 +0000

[Ionut] [[BR]]
- New camera system: [[BR]]
— Stack based (push/pop active camera) [[BR]]
— Per camera frustum [[BR]]
— Per camera projection [[BR]]
— Shadow mapping now uses the new camera system (each light has a shadow camera) [[BR]]
[[BR]]
- New terrain, water and vegetation system: [[BR]]
— Direct import of terrain from L3DT both as 8-bit grayscale and 16-bit raw formats [[BR]]
— Multiple alpha maps for texture splatting support [[BR]]
— Per texture detail map support [[BR]]
— Transform feedback based visibility culling for vegetation [[BR]]
— Alpha-map based vegetation placing on terrain [[BR]]
— Water now uses a refraction map instead of alpha blending for better refraction effects [[BR]]
[[BR]]
- SceneGraph improvements: [[BR]]
— Better bounding box updates from child to parent [[BR]]
— Better onDraw / postDraw implementation [[BR]]
[[BR]]
- Performance improvements: [[BR]]
— Batch 2D rendering tasks together as much as possible[[BR]]
— Improve renderStateBlock hash generation for better sorting [[BR]]
— Move most state related gfx changes from API implementation to the GFXDevice class [[BR]]
— Move viewport stack to the GFXDevice class [[BR]]
— Added various performance counters (frame duration with round-robin query system, draw call count, etc) [[BR]]
— Fixed and improved clip plane management [[BR]]
— Delete client-side texture data after GPU upload [[BR]]
[[BR]]
- New features: [[BR]]
— Added callback support to the Task class so that a specific task may call a function in the main thread upon completion [[BR]]
— Added mouse-wheel zoom support to Orbit/ThirdPerson cameras [[BR]]
— Added 2D Texture Array support (e.g. used for terrain textures) [[BR]]

263 Diff Diff k1ngp1n picture k1ngp1n Fri 09 May, 2014 16:43:53 +0000

[Ionut] [[BR]]
- Fullscreen quads are now rendered via Geometry Shaders [[BR]]
- Implemented shader subroutines [[BR]]
- Improved CVSM’s quality [[BR]]
- Separated shadow only light properties from general light properties in separate UBOs to improve update performance [[BR]]
- Removed shader mask and instead try to load all available shaders from a given file [[BR]]
- Added a method (hackish) of changing projection properties at runtime (e.g. z planes) [[BR]]
- Fixed a comparison bug in RenderStateBlock class (forgot to clean it at last commit) [[BR]]
- Fixed clipping plane upload to shader programs [[BR]]

262 Diff Diff k1ngp1n picture k1ngp1n Tue 06 May, 2014 21:04:00 +0000

[Ionut] [[BR]]
- Some AI refactoring (basic AIEntity <-> AESOP interoperability) [[BR]]
- Some render batch sorting code refactored and fixed (wasn’t properly sorted in FINAL_STAGE) [[BR]]
- Simplified RenderStateBlockDescriptor and deferred hash value calculation [[BR]]
- Basic draw call count implementation [[BR]]
- Renamed some classes [[BR]]

260 k1ngp1n picture k1ngp1n Sat 03 May, 2014 19:33:41 +0000

[Ionut] [[BR]]
- More work on CSM. Reverted back to VSM to allow easier blurring and filtering [[BR]]
- Rewrote FrameBuffer classes to fix MSAA and memory leaks that occurred on resize (double creation of textures) [[BR]]
— Removed FBType. FrameBuffer types depend only on attachment types and if it’s MSAA enabled or not [[BR]]
- Rewrote RenderState classes to be API agnostic [[BR]]
- Bug fixes in math classes [[BR]]
- Changed “resolution change” logic [[BR]]
- Simplified some options in config.xml [[BR]]
- Improved per-light shadow options [[BR]]