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

#include "Core/Headers/Console.h"
#include "Core/Headers/Application.h"
#include "Utility/Headers/Localization.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "Geometry/Shapes/Headers/Predefined/Quad3D.h"

#include "Platform/Video/Headers/GFXDevice.h"
#include "Platform/Video/Shaders/Headers/ShaderProgram.h"
#include "Platform/Video/Buffers/Framebuffer/Headers/Framebuffer.h"

namespace Divide {

Reflector::Reflector(ReflectorType type, const vec2<U16>& resolution)
    : FrameListener(),
      _type(type),
      _resolution(resolution),
      _updateTimer(0),
      _updateInterval(45),  /// 45 milliseconds?
      _reflectedTexture(nullptr),
      _createdFB(false),
      _updateSelf(false),
      _excludeSelfReflection(true),
      _previewReflection(false) {
    REGISTER_FRAME_LISTENER(this, 3);
    ResourceDescriptor reflectionPreviewShader("fbPreview");
    reflectionPreviewShader.setThreadedLoading(false);
    _previewReflectionShader =
        CreateResource<ShaderProgram>(reflectionPreviewShader);

    GFX_DEVICE.add2DRenderFunction(
        DELEGATE_BIND(&Reflector::previewReflection, this), 2);
}

Reflector::~Reflector() {
    UNREGISTER_FRAME_LISTENER(this);
    MemoryManager::DELETE(_reflectedTexture);
    RemoveResource(_previewReflectionShader);
}

/// Returning false in any of the FrameListener methods will exit the entire
/// application!
bool Reflector::framePreRenderEnded(const FrameEvent& evt) {
    // Do not update the reflection too often so that we can improve speed
    if (evt._currentTime - _updateTimer < _updateInterval) {
        return true;
    }
    _updateTimer += _updateInterval;
    if (!_createdFB) {
        if (!build()) {
            // Something wrong. Exit application!
            Console::errorfn(Locale::get(_ID("ERROR_REFLECTOR_INIT_FB")));
            return false;
        }
    }
    // We should never have an invalid FB
    assert(_reflectedTexture != nullptr);
    // mark ourselves as reflection target only if we do not wish to reflect
    // ourself back
    _updateSelf = !_excludeSelfReflection;
    // generate reflection texture
    updateReflection();
    // unmark from reflection target
    _updateSelf = true;
    return true;
}

bool Reflector::build() {
    Console::printfn(Locale::get(_ID("REFLECTOR_INIT_FB")), _resolution.x,
                     _resolution.y);
    SamplerDescriptor reflectionSampler;
    reflectionSampler.setWrapMode(TextureWrap::CLAMP_TO_EDGE);
    reflectionSampler.toggleMipMaps(false);
    // Less precision for reflections
    TextureDescriptor reflectionDescriptor(TextureType::TEXTURE_2D,
                                           GFXImageFormat::RGBA8,
                                           GFXDataFormat::UNSIGNED_BYTE);

    reflectionDescriptor.setSampler(reflectionSampler);

    _reflectedTexture = GFX_DEVICE.newFB();
    _reflectedTexture->addAttachment(reflectionDescriptor,
                                     TextureDescriptor::AttachmentType::Color0);
    _reflectedTexture->useAutoDepthBuffer(true);
    _createdFB = _reflectedTexture->create(_resolution.x, _resolution.y);

    return _createdFB;
}

void Reflector::previewReflection() {
#ifdef _DEBUG
    if (_previewReflection) {
        F32 height = _resolution.y * 0.333f;
        _reflectedTexture->bind(to_ubyte(ShaderProgram::TextureUsage::UNIT0));
        GFX::ScopedViewport viewport(0,
                                     to_int(GFX_DEVICE.getRenderTarget(GFXDevice::RenderTarget::SCREEN)->getResolution().y - height),
                                     to_int(_resolution.x * 0.333f),
                                     to_int(height));
        GFX_DEVICE.drawTriangle(GFX_DEVICE.getDefaultStateBlock(true), _previewReflectionShader);
    }
#endif
}
};

Commits for Divide-Framework/trunk/Source Code/Rendering/RenderPass/Reflector.cpp

Diff revisions: vs.
Revision Author Commited Message
612 Diff Diff IonutCava picture IonutCava Sun 20 Dec, 2015 17:47:26 +0000

[IonutCava]
- Z-PrePass system improvements
— Depth only rendertarget and both eye render targets (screen and anaglyph) share the same depth buffer
— Screen render targets don’t clear or write the/to the depth buffer

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

546 Diff Diff IonutCava picture IonutCava Tue 03 Nov, 2015 23:40:35 +0000

[IonutCava]
- Single pass (layered rendering) cascaded shadowmaps including blur
- Naming convention fixes

514 Diff Diff IonutCava picture IonutCava Fri 25 Sep, 2015 16:18:42 +0000

[IonutCava]
- Split fullscreen quad rendering system in two and use the most performant one depending on the situation:
— The old GL_POINTS expanded in Geometry shader method. (e.g. useful for blurs / fxaa)
— Single triangle 2x width and 2xheight of the screen with scaled UVs (e.g. useful for fullscreen rendering)
- Attempt to change line rendering system to support custom start and end widths
- First attempt at splitting vertex specifications from buffers (with glVertexAttribFormat) and use only one VAO per specification instead of one per object
- Code cleanups and small optimizations where appropriate

504 Diff Diff IonutCava picture IonutCava Tue 25 Aug, 2015 16:17:38 +0000

[IonutCava]
- Better caching of draw commands (W.I.P.)
- Remove unused occlusion culling code. Will be replaced with Hi-Z based culling

445 Diff Diff IonutCava picture IonutCava Fri 22 May, 2015 15:47:37 +0000

[Ionut]
- Experimental work on windowing system upgrades (to allow all 3 states: windowed / fullscreen / splash windows to exist and switch between each-other seamlessly)

444 Diff Diff IonutCava picture IonutCava Thu 21 May, 2015 16:06:53 +0000

[Ionut]
- More platform independent code cleanup:
— Moved platform specific defines to their respective header files (e.g. THREAD_LOCAL)
— Moved most preprocessor defines from the VisualC++ projects into source code
— Removed compiler specific code (e.g. warning disables) and fixed most warning resulting from this

411 Diff Diff IonutCava picture IonutCava Sun 26 Apr, 2015 22:56:34 +0000

[Ionut]
- Removed the “renderInViewport” method in favor of an explicit “ScopedViewport” usage where needed.
- Added a texture format deduction system based on the specified internal format
- Some glFramebuffer improvements
- Removed the state block macro checking system with explicit checks

390 IonutCava picture IonutCava Thu 26 Mar, 2015 22:41:09 +0000

[Ionut]
- Renamed most enum values to shorter names (possible due to enum-class type safety)
- Removed to redundant state change cases (glCullFace when CULL_MODE_NONE was used, and glLineWidth that didn’t have redundancy checks)
- Added a hacky SceneGraphNode render call count to skip the first 3 draw calls so that the data buffers have time to update properly (solves flickering and erroneous rendering when moving camera to include a new node)