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
|
#pragma once
#include "drape_frontend/render_state_extension.hpp"
#include "shaders/program_manager.hpp"
#include "drape/graphics_context.hpp"
#include "drape/vertex_array_buffer.hpp"
#include "drape/pointers.hpp"
namespace df
{
class RenderNode
{
public:
RenderNode(dp::RenderState const & state, drape_ptr<dp::VertexArrayBuffer> && buffer)
: m_state(state)
, m_buffer(std::move(buffer))
{}
template <typename ParamsType>
void Render(ref_ptr<dp::GraphicsContext> context, ref_ptr<gpu::ProgramManager> mng,
ParamsType const & params, dp::IndicesRange const & range)
{
Apply(context, mng, params);
m_buffer->RenderRange(context, m_state.GetDrawAsLine(), range);
}
template <typename ParamsType>
void Render(ref_ptr<dp::GraphicsContext> context, ref_ptr<gpu::ProgramManager> mng,
ParamsType const & params)
{
Apply(context, mng, params);
m_buffer->Render(context, m_state.GetDrawAsLine());
}
private:
template <typename ParamsType>
void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<gpu::ProgramManager> mng,
ParamsType const & params)
{
auto prg = mng->GetProgram(m_state.GetProgram<gpu::Program>());
prg->Bind();
if (!m_isBuilt)
{
m_buffer->Build(context, prg);
m_isBuilt = true;
}
dp::ApplyState(context, prg, m_state);
mng->GetParamsSetter()->Apply(context, prg, params);
}
dp::RenderState m_state;
drape_ptr<dp::VertexArrayBuffer> m_buffer;
bool m_isBuilt = false;
};
} // namespace df
|