forked from projectM-visualizer/projectm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBorder.cpp
More file actions
78 lines (63 loc) · 2.93 KB
/
Border.cpp
File metadata and controls
78 lines (63 loc) · 2.93 KB
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
#include "Border.hpp"
#include <Renderer/BlendMode.hpp>
namespace libprojectM {
namespace MilkdropPreset {
Border::Border(PresetState& presetState)
: m_presetState(presetState)
, m_borderMesh(Renderer::VertexBufferUsage::StreamDraw)
{
m_borderMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::Triangles);
m_borderMesh.SetVertexCount(8);
m_borderMesh.Indices().Set({
{
0, 1, 4,
1, 4, 5,
2, 3, 6,
3, 7, 6,
2, 0, 6,
0, 4, 6,
3, 7, 5,
1, 3, 5
}});
}
void Border::Draw(const PerFrameContext& presetPerFrameContext)
{
// Draw Borders
float const outerBorderSize = static_cast<float>(*presetPerFrameContext.ob_size);
float const innerBorderSize = static_cast<float>(*presetPerFrameContext.ib_size);
// No additive drawing for borders
Renderer::BlendMode::Set(true, Renderer::BlendMode::Function::SourceAlpha, Renderer::BlendMode::Function::OneMinusSourceAlpha);
auto shader = m_presetState.untexturedShader.lock();
shader->Bind();
shader->SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjection);
shader->SetUniformFloat("vertex_point_size", 1.0f);
m_borderMesh.Bind();
for (int border = 0; border < 2; border++)
{
float r = (border == 0) ? static_cast<float>(*presetPerFrameContext.ob_r) : static_cast<float>(*presetPerFrameContext.ib_r);
float g = (border == 0) ? static_cast<float>(*presetPerFrameContext.ob_g) : static_cast<float>(*presetPerFrameContext.ib_g);
float b = (border == 0) ? static_cast<float>(*presetPerFrameContext.ob_b) : static_cast<float>(*presetPerFrameContext.ib_b);
float a = (border == 0) ? static_cast<float>(*presetPerFrameContext.ob_a) : static_cast<float>(*presetPerFrameContext.ib_a);
if (a > 0.001f)
{
glVertexAttrib4f(1, r, g, b, a);
float innerRadius = (border == 0) ? 1.0f - outerBorderSize : 1.0f - outerBorderSize - innerBorderSize;
float outerRadius = (border == 0) ? 1.0f : 1.0f - outerBorderSize;
m_borderMesh.Vertices().Set({{outerRadius, outerRadius},
{outerRadius, -outerRadius},
{-outerRadius, outerRadius},
{-outerRadius, -outerRadius},
{innerRadius, innerRadius},
{innerRadius, -innerRadius},
{-innerRadius, innerRadius},
{-innerRadius, -innerRadius}});
m_borderMesh.Update();
m_borderMesh.Draw();
}
}
Renderer::Mesh::Unbind();
Renderer::Shader::Unbind();
Renderer::BlendMode::SetBlendActive(false);
}
} // namespace MilkdropPreset
} // namespace libprojectM