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
#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/Time/Headers/ApplicationTimer.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "Platform/Video/Headers/IMPrimitive.h"
#include "Platform/Video/Textures/Headers/Texture.h"
#include "Platform/Video/Shaders/Headers/ShaderProgram.h"
#include "Platform/Video/Buffers/Framebuffer/Headers/Framebuffer.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::instance().getParam<bool>(
        _ID("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
        ResourceDescriptor fbPreview("fbPreview.LinearDepth.ScenePlanes");
        fbPreview.setPropertyList("USE_SCENE_ZPLANES");
        _previewDepthMapShader = CreateResource<ShaderProgram>(fbPreview);
        assert(_previewDepthMapShader != nullptr);
    }

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

    U16 screenWidth = std::max(_renderTarget[to_const_uint(RenderTargetID::SCREEN)]._buffer->getResolution().width, to_const_ushort(768));
    Texture_ptr depthTex = _renderTarget[to_const_uint(RenderTargetID::SCREEN)]._buffer->getAttachment(TextureDescriptor::AttachmentType::Depth);
    depthTex->Bind(to_const_ubyte(ShaderProgram::TextureUsage::UNIT0));
    {
        //HiZ preview
        _previewDepthMapShader->Uniform("lodLevel", to_float(to_uint((Time::ElapsedMilliseconds() / 750.0)) % 
                                                             (depthTex->getMaxMipLevel() - 1)));
        GFX::ScopedViewport viewport(screenWidth - 256, 0, 256, 256);
        drawTriangle(_defaultStateNoDepthHash, _previewDepthMapShader);
    }
    {
        //Depth preview
        _previewDepthMapShader->Uniform("lodLevel", to_float(0));
        GFX::ScopedViewport viewport(screenWidth - 512, 0, 256, 256);
        drawTriangle(_defaultStateNoDepthHash, _previewDepthMapShader);
    }
    {
        //Normals preview
        _renderTarget[to_const_uint(RenderTargetID::SCREEN)]._buffer
            ->bind(to_const_ubyte(ShaderProgram::TextureUsage::UNIT0),
                   TextureDescriptor::AttachmentType::Color1);

        GFX::ScopedViewport viewport(screenWidth - 768, 0, 256, 256);
        _framebufferDraw->Uniform("linearSpace", false);
        drawTriangle(_defaultStateNoDepthHash, _framebufferDraw);
    }
#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) {
    uploadGPUBlock();
    // 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);
    bool previousTextureFlag = false;
    // Loop over all available primitives and find active ones
    _activeImInterfaces.resize(0);
    for (IMPrimitive* prim : _imInterfaces) {
        // A primitive may be paused if drawing it isn't desired at the current point in time
        if (!prim->paused()) {
            _activeImInterfaces.push_back(prim);
        }
    }

    for (IMPrimitive* prim : _activeImInterfaces) {
        // 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
        if (prim->drawShader() == nullptr) {
            prim->drawShader(_imShader.get());
        }
        // Set the primitive's render state block
        setStateBlock(prim->stateHash());
        // Call any "onDraw" function the primitive may have attached
        prim->setupStates();
        // Check if any texture is present
        bool texture = (prim->_texture != nullptr);
        // And bind it to the first diffuse texture slot
        if (texture) {
            prim->_texture->Bind(to_const_ubyte(ShaderProgram::TextureUsage::UNIT0));
        }
        if (previousTextureFlag != texture) {
            previousTextureFlag = texture;
            // Inform the shader if we have (or don't have) a texture
            _imShader->Uniform(_imShaderTextureFlag, texture);
        }
        // Upload the primitive's world matrix to the shader
        _imShader->Uniform(_imShaderWorldMatrix, prim->worldMatrix());
        // Submit the render call. We do not support instancing yet!
        prim->render(prim->forceWireframe(), 1);
        registerDrawCall();
        // Call any "postRender" function the primitive may have attached
        prim->resetStates();
        if (prim->_canZombify) {
            prim->paused(true);
        }
    }
}

/// Draw the axis arrow gizmo
void GFXDevice::drawDebugAxis(const SceneRenderState& sceneRenderState) {
    // This is togglable, so check if it's actually requested
    if (!drawDebugAxis()) {
        return;
    }
  
    // 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
    U16 windowWidth = _renderTarget[to_const_uint(RenderTargetID::SCREEN)]._buffer->getWidth();
    drawLines(*_axisGizmo,
              _axisLines,
              vec4<I32>(windowWidth - 120, 8, 128, 128),
              true);
}
};

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

Diff revisions: vs.
Revision Author Commited Message
710 Diff Diff IonutCava picture IonutCava Fri 20 May, 2016 16:24:40 +0000

[IonutCava]
- Code cleanup
- Initial work on Scene loading and unloading with and without unloading assets:
— Need to change AIManager from a Singleton to a per-scene component

709 Diff Diff IonutCava picture IonutCava Thu 19 May, 2016 16:21:46 +0000

[IonutCava]
- Massive rewrite of the resource system:
— ResourceCache now uses a map of weak pointers and passes shared pointers to the call point of CreateResource
— RemoveResource is no longer needed, but resource based smart pointers use a custom deleter that calls unload()
— Keep a shared_ptr of the resource in the entity that needs it and pass shared_ptr references from getter methods
-— All of this removed the need for calls to RemoveResource, REGISTER_TRACKED_DEPENDENCY and UNREGISTER_TRACKED_DEPENDENCY reducing the number of mutex locks and atomic exchanges
- Singleton cleanup:
— Removed ShaderManager singleton and merged it’s data and responsibilities in static methods in both ShaderProgram and Shader classes.
Explanation: Due to the complex interdependency chains in the system, copying, updating, tracking the cache in a thread safe way became a lot more slower than a straight forward smart pointer based implementation. (e.g. scene graph nodes have 3d objects and material instances, 3d objects have materials, materials have textures and shaders, etc)

693 Diff Diff IonutCava picture IonutCava Thu 28 Apr, 2016 16:19:35 +0000

[IonutCava]
- Cleanup Time and Profiling code

670 Diff Diff IonutCava picture IonutCava Wed 06 Apr, 2016 16:21:35 +0000

[IonutCava]
- getInstance() renamed to instance() for simplicity (should really go away altogether, but that’s a different issue)
- some particle emitter threading updates

643 Diff Diff IonutCava picture IonutCava Sat 13 Feb, 2016 12:36:20 +0000

[IonutCava]
- Add support for multiple GFX render queues
— Flush all queues in a tight loop
— This may allow populating the render queues from renderbins in parallel

631 Diff Diff IonutCava picture IonutCava Sun 24 Jan, 2016 20:28:21 +0000

[IonutCava]
- Fix and optimize particle rendering system
- Temporarily disable Z_PRE_PASS system for testing
- Improve thread pool destruction system a bit
- Fix texture loading when used as fb attachment
- Forward+ renderer now takes the entire light buffer (no need to split up by light type)
- Start work on occlusion culling fixes:
— ToDo: Take into account batching system
— Fix gl_DrawIDARB usage

628 Diff Diff IonutCava picture IonutCava Wed 20 Jan, 2016 17:17:53 +0000

[IonutCava]
- Reworked GenericVertexData ring-buffering system and changed vertex attributes to the vertex format system
— Might be buggy
- Disabled bump-mapping for low-LoD level entities
- Removed a forgotten test line in BRDF shader that prevented lighting calculations to occur properly (an early return)
- Updated auto-reflection system for high shininess materials
- Converted a lot of ‘to_xyz’ calls to ‘to_const_xyz’ calls where appropriate to reduce runtime cost (‘to_const_xyz’ is evaluated at compile time)

625 Diff Diff IonutCava picture IonutCava Mon 18 Jan, 2016 17:19:59 +0000

[IonutCava]
- Limit number of shader compilations per frame
- Add initial support for deferred SGN postLoad calls (think multi-threaded loading support in the future)
- Various small profile-guided optimizations
- Removed some indirections in draw command submission

621 Diff Diff IonutCava picture IonutCava Tue 12 Jan, 2016 16:39:50 +0000

[IonutCava]
- Terrain rendering updates
- Framebuffer optimizations

617 IonutCava picture IonutCava Tue 05 Jan, 2016 16:47:21 +0000

[IonutCava]
- Depth writing is now a rendering API level toggle instead of a renderstateblock option
- Z-Pre-pass fixes and improvements
- Moved normal render target to the display stage from the pre-pass stage
— Normals are only used in post-processing. This improves pre-pass performance