/
FullBrightRenderer.cpp
93 lines (71 loc) · 2.44 KB
/
FullBrightRenderer.cpp
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
#include "FullBrightRenderer.h"
#include "OpenGLShaderPass.h"
#include "OpenGLShader.h"
namespace render
{
namespace
{
class FullBrightRenderResult :
public IRenderResult
{
private:
std::string _statistics;
public:
FullBrightRenderResult(const std::string& statistics) :
_statistics(statistics)
{}
std::string toString() override
{
return _statistics;
}
};
}
IRenderResult::Ptr FullBrightRenderer::render(RenderStateFlags globalstate, const IRenderView& view, std::size_t time)
{
// Make sure all the data is uploaded
_geometryStore.syncToBufferObjects();
// Construct default OpenGL state
OpenGLState current;
setupState(current);
setupViewMatrices(view);
// Bind the vertex and index buffer object before drawing geometry
auto [vertexBuffer, indexBuffer] = _geometryStore.getBufferObjects();
vertexBuffer->bind();
indexBuffer->bind();
// Set the attribute pointers
ObjectRenderer::InitAttributePointers();
// Iterate over the sorted mapping between OpenGLStates and their
// OpenGLShaderPasses (containing the renderable geometry), and render the
// contents of each bucket. Each pass is passed a reference to the "current"
// state, which it can change.
for (const auto& [_, pass] : _sortedStates)
{
// Render the OpenGLShaderPass
if (pass->empty() || pass->hasRenderables()) continue;
if (pass->getShader().isVisible() && pass->isApplicableTo(_renderViewType))
{
// Apply our state to the current state object
pass->evaluateStagesAndApplyState(current, globalstate, time, nullptr);
pass->submitSurfaces(view);
}
}
// Unbind the geometry buffer and draw the rest of the renderables
vertexBuffer->unbind();
indexBuffer->unbind();
// Run all the passes with OpenGLRenderables
for (const auto& [_, pass] : _sortedStates)
{
// Render the OpenGLShaderPass
if (pass->empty() || !pass->hasRenderables()) continue;
if (pass->getShader().isVisible() && pass->isApplicableTo(_renderViewType))
{
// Apply our state to the current state object
pass->evaluateStagesAndApplyState(current, globalstate, time, nullptr);
pass->submitRenderables(current);
}
pass->clearRenderables();
}
cleanupState();
return std::make_shared<FullBrightRenderResult>(view.getCullStats());
}
}