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

#include "Core/Headers/Kernel.h"
#include "Core/Headers/Console.h"
#include "Core/Headers/TaskPool.h"
#include "Core/Headers/Application.h"
#include "Utility/Headers/Localization.h"
#include "Graphs/Headers/SceneGraphNode.h"
#include "Geometry/Shapes/Headers/Object3D.h"
#include "Geometry/Material/Headers/Material.h"

namespace Divide {

RenderQueue::RenderQueue(GFXDevice& context)
    : _context(context)
{
    _renderBins.fill(nullptr);
    _activeBins.reserve(to_const_uint(RenderBinType::COUNT));
}

RenderQueue::~RenderQueue()
{
    for (RenderBin* bin : _renderBins) {
        MemoryManager::DELETE(bin);
    }
    _renderBins.fill(nullptr);
    _activeBins.clear();
}

U16 RenderQueue::getRenderQueueStackSize() const {
    U16 temp = 0;
    for (RenderBin* bin : _activeBins) {
        temp += bin->getBinSize();
    }
    return temp;
}

RenderBin* RenderQueue::getOrCreateBin(RenderBinType rbType) {
    RenderBin* temp = getBin(rbType);
    if (temp != nullptr) {
        return temp;
    }

    RenderingOrder::List sortOrder = RenderingOrder::List::COUNT;
    switch (rbType) {
        case RenderBinType::RBT_OPAQUE: {
            // By state varies based on the current rendering stage
            sortOrder = RenderingOrder::List::BY_STATE;
        } break;
        case RenderBinType::RBT_SKY: {
            sortOrder = RenderingOrder::List::NONE;
        } break;
        case RenderBinType::RBT_IMPOSTOR:
        case RenderBinType::RBT_TERRAIN:
        case RenderBinType::RBT_DECALS: {
            sortOrder = RenderingOrder::List::FRONT_TO_BACK;
        } break;
        case RenderBinType::RBT_WATER:
        case RenderBinType::RBT_VEGETATION_GRASS:
        case RenderBinType::RBT_PARTICLES:
        case RenderBinType::RBT_TRANSLUCENT: {
            sortOrder = RenderingOrder::List::BACK_TO_FRONT;
        } break;

        default: {
            Console::errorfn(Locale::get(_ID("ERROR_INVALID_RENDER_BIN_CREATION")));
            return nullptr;
        } break;
    };

    temp = MemoryManager_NEW RenderBin(_context, rbType, sortOrder);
    // Bins are sorted by their type
    _renderBins[rbType._to_integral()] = temp;
    
    _activeBins.resize(0);
    for (RenderBin* bin : _renderBins) {
        if (bin != nullptr) {
            _activeBins.push_back(bin);
        }
    }

    return temp;
}

RenderBin* RenderQueue::getBinForNode(const std::shared_ptr<SceneNode>& node,
                                      const Material_ptr& matInstance) {
    assert(node != nullptr);
    switch (node->getType()) {
        case SceneNodeType::TYPE_LIGHT: {
            return getOrCreateBin(RenderBinType::RBT_IMPOSTOR);
        }
        case SceneNodeType::TYPE_WATER: {
            return getOrCreateBin(RenderBinType::RBT_WATER);
        }
        case SceneNodeType::TYPE_PARTICLE_EMITTER: {
            return getOrCreateBin(RenderBinType::RBT_PARTICLES);
        }
        case SceneNodeType::TYPE_VEGETATION_GRASS: {
            return getOrCreateBin(RenderBinType::RBT_VEGETATION_GRASS);
        }
        case SceneNodeType::TYPE_SKY: {
            return getOrCreateBin(RenderBinType::RBT_SKY);
        }
        case SceneNodeType::TYPE_VEGETATION_TREES:
        case SceneNodeType::TYPE_OBJECT3D: {
            if (static_cast<Object3D*>(node.get())->getObjectType() ==
                Object3D::ObjectType::TERRAIN) {
                return getOrCreateBin(RenderBinType::RBT_TERRAIN);
            }
            // Check if the object has a material with translucency
            if (matInstance && matInstance->isTranslucent()) {
                // Add it to the appropriate bin if so ...
                return getOrCreateBin(RenderBinType::RBT_TRANSLUCENT);
            }
            //... else add it to the general geometry bin
            return getOrCreateBin(RenderBinType::RBT_OPAQUE);
        }
    }
    return nullptr;
}

void RenderQueue::addNodeToQueue(const SceneGraphNode& sgn, RenderStage stage, const vec3<F32>& eyePos) {
    static Material_ptr defaultMat;

    RenderingComponent* const renderingCmp = sgn.get<RenderingComponent>();
    RenderBin* rb = getBinForNode(sgn.getNode(),
                                  renderingCmp
                                    ? renderingCmp->getMaterialInstance()
                                    : defaultMat);
    if (rb) {
        rb->addNodeToBin(sgn, stage, eyePos);
    }
}

void RenderQueue::populateRenderQueues(RenderStage renderStage) {
    TaskPool& pool = Application::instance().kernel().taskPool();

    TaskHandle populateTask = CreateTask(pool, DELEGATE_CBK<void, const Task&>());
    for (RenderBin* renderBin : _activeBins) {
        if (!renderBin->empty()) {
            populateTask.addChildTask(
                CreateTask(pool,
                           [renderBin, renderStage](const Task& parentTask) {
                               renderBin->populateRenderQueue(parentTask, renderStage);
                           })._task)->startTask(Task::TaskPriority::HIGH);
        }
    }
    populateTask.startTask(Task::TaskPriority::MAX);
    populateTask.wait();
}

void RenderQueue::postRender(const SceneRenderState& renderState, RenderStage renderStage, RenderSubPassCmds& subPassesInOut) {
    for (RenderBin* renderBin : _activeBins) {
        renderBin->postRender(renderState, renderStage, subPassesInOut);
    }
}

void RenderQueue::sort(RenderStage renderStage) {
    U32 index = 0;
    for (RenderBin* renderBin : _activeBins) {
        renderBin->binIndex(index);
        index += renderBin->getBinSize();
    }

    TaskPool& pool = Application::instance().kernel().taskPool();
    TaskHandle sortTask = CreateTask(pool, DELEGATE_CBK<void, const Task&>());
    for (RenderBin* renderBin : _activeBins) {
        if (!renderBin->empty()) {
            sortTask.addChildTask(CreateTask(pool,
                [renderBin, renderStage](const Task& parentTask) {
                    renderBin->sort(parentTask, renderStage);
                })._task)->startTask(Task::TaskPriority::HIGH);
        }
    }
    sortTask.startTask(Task::TaskPriority::MAX);
    sortTask.wait();
}

void RenderQueue::refresh() {
    for (RenderBin* renderBin : _activeBins) {
        renderBin->refresh();
    }
}

};

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

Diff revisions: vs.
Revision Author Commited Message
842 Diff Diff IonutCava picture IonutCava Wed 01 Feb, 2017 17:25:15 +0000

[IonutCava]
- Start to implement scripting support via ChaiScript: http://chaiscript.com/
- Cleanup DELEGATE_CBK alias

839 Diff Diff IonutCava picture IonutCava Tue 31 Jan, 2017 17:28:13 +0000

[IonutCava]
- Add simplefilewatcher libary: https://github.com/jameswynn/simplefilewatcher
- Use simplefilewatcher to automatically recompile shaders after save without restarting the app!
— Shaders can now be edited on the fly with automatic rebuild if they used one of the modified atoms.

819 Diff Diff IonutCava picture IonutCava Mon 16 Jan, 2017 21:30:53 +0000

[IonutCava]
- More threading updates to the LightPool class

811 Diff Diff IonutCava picture IonutCava Wed 11 Jan, 2017 17:26:49 +0000

[IonutCava]
- Fix some threadpool cleanup bugs
- Fix terrain rendering (except underwater caustics)
- Fix terrain loading
- Fix terrain unloading

801 Diff Diff IonutCava picture IonutCava Sun 27 Nov, 2016 21:28:01 +0000

[IonutCava]
- More performance analysis guided optimizations.
- Some refactoring to allow later removal of Singletons status for: GFXDevice, SFXDevice, PXDevice, GUI and Input.
— Pass a PlatformContext around objects to access these classes.

799 Diff Diff IonutCava picture IonutCava Thu 24 Nov, 2016 22:55:23 +0000

[IonutCava]
- Performance analysis guided optimizations.

781 Diff Diff IonutCava picture IonutCava Wed 12 Oct, 2016 16:03:46 +0000

[IonutCava]
- ShaderComputeQueue <-> Material shader request bug fix (element stuck in QUEUED state)
- More Camera class cleanups
- Add a method of removing EnvironmentProbes from their Pool

777 Diff Diff IonutCava picture IonutCava Fri 07 Oct, 2016 16:14:48 +0000

[IonutCava]
- Continue to implement CommandBuffer / RenderPass / RenderSubPass system.
— Rendering artefacts are still present.

760 Diff Diff IonutCava picture IonutCava Tue 09 Aug, 2016 16:30:12 +0000

[IonutCava]
- Complete rewrite of RenderPass system:
— Allow every rendering pass (reflection, environment, etc) to use the same rendering system: occlusion culling, light culling, etc
— Define render passes by a param based token similar to modern API systems (DX12/Vulkan)
— W.I.P.: Depth rendering slightly wrong; Environment Mapping ,reflection and refraction rendering currently disabled
- Add compile time variables for DEBUG/PROFILE/RELEASE builds to validate all code for every build

744 IonutCava picture IonutCava Tue 28 Jun, 2016 21:43:58 +0000

[IonutCava]
- More performance tweaks