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

#include "Core/Headers/Application.h"
#include "Core/Headers/ParamHandler.h"
#include "Scenes/Headers/SceneState.h"
#include "Managers/Headers/CameraManager.h"
#include "Core/Resources/Headers/ResourceCache.h"

namespace Divide {
/// Show the contents of the depth buffer in a small rectangle in the bottom right of the screen
void GFXDevice::previewDepthBuffer() {
    // As this is touched once per frame, we'll only enable it in debug builds
#   ifdef _DEBUG
        // Early out if we didn't request the preview
        if (!ParamHandler::getInstance().getParam<bool>("rendering.previewDepthBuffer", false)) {
            return;
        }
        // Lazy-load preview shader
        if (!_previewDepthMapShader) {
            // The LinearDepth variant converts the depth values to linear values between the 2 scene z-planes
            _previewDepthMapShader = CreateResource<ShaderProgram>(ResourceDescriptor("fbPreview.LinearDepth"));
            assert(_previewDepthMapShader != nullptr);
            _previewDepthMapShader->Uniform("useScenePlanes", true);
        }

        if (_previewDepthMapShader->getState() != RES_LOADED) {
            return;
        }

        _renderTarget[RENDER_TARGET_DEPTH]->Bind(ShaderProgram::TEXTURE_UNIT0, TextureDescriptor::Depth);

		renderInViewport(vec4<I32>(Application::getInstance().getResolution().width - 256, 0, 256, 256), 
			             DELEGATE_BIND((void(GFXDevice::*)(U32, size_t, ShaderProgram* const))
                                       &GFXDevice::drawPoints,
                                       this, 
                                       1,
                                       _defaultStateNoDepthHash,
                                       _previewDepthMapShader));
#   endif
}

/// Render all of our immediate mode primitives. This isn't very optimised and most are recreated per frame!
void GFXDevice::debugDraw(const SceneRenderState& sceneRenderState) {
    // We need a shader that emulates the fixed pipeline in order to continue
    if (!_imShader->bind()) {
        return;
    }
    // Debug axis form the axis arrow gizmo in the corner of the screen
    drawDebugAxis(sceneRenderState);
    // Loop over all available primitives
    for (IMPrimitive* priv : _imInterfaces) {
        // A primitive may be paused if drawing it isn't desired at the current point in time
        if (priv->paused()) {
            continue;
        }
        // If the current primitive isn't in use, and can be recycled, increase it's "zombie counter" 
        if (!priv->inUse() && priv->_canZombify) {
            // The zombie counter represents the number of frames since the primitive was last used
            priv->zombieCounter(priv->zombieCounter() + 1);
            continue;
        }
        // Inform the primitive that we're using the imShader
        // A primitive can be rendered with any shader program available, so make sure we actually use the right one for this stage
        priv->drawShader(_imShader);
        // Set the primitive's render state block
        setStateBlock(priv->stateHash());
        // Call any "onDraw" function the primitive may have attached
        priv->setupStates();
        // If we are drawing lines, set the required width
        if (priv->_hasLines) {
            setLineWidth(priv->_lineWidth);
        }
        // Check if any texture is present
        bool texture = (priv->_texture != nullptr);
        // And bind it to the first diffuse texture slot
        if (texture) {
            priv->_texture->Bind(ShaderProgram::TEXTURE_UNIT0);
        }
        // Inform the shader if we have (or don't have) a texture
        _imShader->Uniform("useTexture", texture);
        // Upload the primitive's world matrix to the shader
        _imShader->Uniform("dvd_WorldMatrix", priv->worldMatrix());
        // Submit the render call. We do not support instancing yet!
        priv->render(priv->forceWireframe(), 1);
        // Reset line width if needed
        if (priv->_hasLines) {
            restoreLineWidth();
        }
        // Call any "postDraw" function the primitive may have attached
        priv->resetStates();
        // If this primitive is recyclable, clear it's inUse flag. It should be recreated next frame
        if (priv->_canZombify) {
            priv->inUse(false);
        }
    }
}

/// Draw the axis arrow gizmo
void GFXDevice::drawDebugAxis(const SceneRenderState& sceneRenderState) {
    // This is togglable, so check if it's actually requested 
    if (!drawDebugAxis()) {
        return;
    }
    // We need to transform the gizmo so that it always remains axis aligned
    const Camera& cam = sceneRenderState.getCameraConst();
    // Create a world matrix using a look at function with the eye position backed up from the camera's view direction
    mat4<F32> offset(- cam.getViewDir() * 2, VECTOR3_ZERO, cam.getUpDir());
    // Apply the inverse view matrix so that it cancels out in the shader
    // Submit the draw command, rendering it in a tiny viewport in the lower right corner
    drawLines(_axisLines, 
              offset * _gpuBlock._ViewMatrix.getInverse(),
              vec4<I32>(_renderTarget[RENDER_TARGET_SCREEN]->getWidth() - 128, 0, 128, 128),
              true,
              true);
}

};

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

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

323 Diff Diff IonutCava picture IonutCava Thu 11 Sep, 2014 20:58:50 +0000

[Ionut]
- Reworked GFXDevice API initialization system
- Added a separate map for boolean values in ParamHandler
- More cleanups in GFXDevice class
- Fixed an infinite loop issue in Task class

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

303 Diff Diff IonutCava picture IonutCava Sat 09 Aug, 2014 19:12:32 +0000

[Ionut]
- Fixed mouse movement (change resolution callback properly informs inputInterface of the new window’s width and height)
- Fixed immediate mode emulation rendering (destroyed index buffers for some reason)
- Added axis gizmos for Scene / Scene + Selected Object / Scene + All object cycled via the F5 key in debug

302 Diff Diff IonutCava picture IonutCava Wed 06 Aug, 2014 22:09:55 +0000

[Ionut]
- GenericVertexData buffer size (for read/write buffering) is now configurable instead of a fixed 3x and also applies to non-persistently mapped buffers
- Moved OpenGL enum tables to Divide::GLUtil::GL_ENUM_TABLE
- More code cleanups (glResources, glError, glVertexArray, glGenericVertexData, glIMPrimitive)

299 Diff Diff IonutCava picture IonutCava Mon 04 Aug, 2014 22:09:22 +0000

[Ionut]
- Disabled shader binary dump/load on non-nVidia GPUs (caused issues)
- More code cleanup/comments/formating (GFXDevice.cpp)

296 Diff Diff k1ngp1n picture k1ngp1n Sun 03 Aug, 2014 14:54:21 +0000

[Ionut]
- nVidia compatibility fixes (GUI, shadows, post-processing)
- Texture bind slots are now part of ShaderProgram class
- Renamed ForwardRenderer class to ForwardPlusRenderer and moved ligh grid creation to it
- More code cleanups and comments

294 Diff Diff k1ngp1n picture k1ngp1n Wed 30 Jul, 2014 20:19:14 +0000

[Ionut]
- More nVidia compatibility fixes (lighting shaders with textures still fail to compile):
— NS_GLIM compatibility fix (set ELEMENT_ARRAY_BUFFER to 0 in glimBatchData’s VAO on creation when setting attrib pointers)

  • Could improve NS_GLIM performance a lot by caching some buffers instead of re-creating them every time a batch is generated, but it’s suppose to be used only for debugging, so low prio*

- Removed interpolation factor from FrameEvent struct. Only using interpolation factor stored in GFXDevice instance
- Fixed the close button (added GLFW close callback)
- More code style improvements (no new comments yet)

287 IonutCava picture IonutCava Tue 22 Jul, 2014 16:11:05 +0000

[Ionut]
- Unified matrix transforms and node info and made it a vertex-shader only buffer
- World matrix queries have to be issued from the SceneGraphNode instead of the SGN’s Transform class to allow future interpolation algorithms to be more easily implemented
- Moved all lighting calculations per pixel to save varying and register space (caused compilation issues both on nVidia and AMD)
- Stored GPU buffer info (view, projection, viewport etc) into a special struct to avoid multiple redundant buffer uploads and to remove redundant client side matrix caches
- Some work on shader buffer locking system
- Cleaned up MathClasses.h and Transform.h
- Updated ASSIMP to 3.1.1