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/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::getInstance().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* 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);
        }
        // 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 "postDraw" 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
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 Diff Diff 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

615 Diff Diff IonutCava picture IonutCava Tue 22 Dec, 2015 16:30:42 +0000

[IonutCava]
not working properly
- Move HiZ buffer to separate render target
- Implement basic, per-scene, auto Save/Load system (works with camera position only for now)
- Fix a few wrong calls in glFramebuffer and glVertexArray
- Re-work skybox rendering

613 Diff Diff IonutCava picture IonutCava Sun 20 Dec, 2015 19:30:47 +0000

[IonutCava]
- Merge DEPTH and SCREEN render targets
- Use new anaglyph method:
— Render scene as usual for first pass and apply postFX
— If anaglyph enabled:
-— Blit screen target to anaglyph target
-— Render scene with IoD distance set for second pass and apply PostFX
-— Render scene with SCREEN and ANAGLYPH bound and anaglyphEnabled uniform set to true
— If anaglyph disabled:
-— Render scene with SCREEN and (non-blitted) ANAGLYPH bound and anaglyphEnabled uniform set to false

591 Diff Diff IonutCava picture IonutCava Wed 02 Dec, 2015 17:17:23 +0000

[IonutCava]
- More work on the ForwardPlus renderer
- Singleton cleanup
- First steps for reducing scope of GFXDevice class

577 Diff Diff IonutCava picture IonutCava Fri 20 Nov, 2015 15:59:10 +0000

[IonutCava]
- Replace all string indexed maps with unsigned long long indexed maps and add both compile time and runtime hashing functions to convert strings to the proper indices
— Balancing the calls between _ID and _ID_RT can reduce map lookup overhead, especially with ParamHandler and Locale::get

570 IonutCava picture IonutCava Tue 17 Nov, 2015 23:06:47 +0000

[IonutCava]
- First part of changing the Forward+ renderer to a compute based System
— Ref: http://bioglaze.blogspot.co.uk/2014/07/2048-point-lights-60-fps.html