-
-
Notifications
You must be signed in to change notification settings - Fork 454
Expand file tree
/
Copy pathFilters.cpp
More file actions
118 lines (94 loc) · 3.09 KB
/
Filters.cpp
File metadata and controls
118 lines (94 loc) · 3.09 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
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
#include "Filters.hpp"
#include <Renderer/BlendMode.hpp>
using libprojectM::Renderer::BlendMode;
namespace libprojectM {
namespace MilkdropPreset {
Filters::Filters(const PresetState& presetState)
: m_presetState(presetState)
{
Init();
}
void Filters::InitVertexAttrib()
{
glEnableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Point), reinterpret_cast<void*>(offsetof(Point, x)));
}
void Filters::Draw()
{
UpdateMesh();
if (m_viewportWidth == 0 || m_viewportHeight == 0)
{
return;
}
BlendMode::SetBlendActive(true);
auto shader = m_presetState.untexturedShader.lock();
shader->Bind();
shader->SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjection);
shader->SetUniformFloat("vertex_point_size", 1.0f);
glVertexAttrib4f(1, 1.0, 1.0, 1.0, 1.0);
if (m_presetState.brighten)
{
Brighten();
}
if (m_presetState.darken)
{
Darken();
}
if (m_presetState.solarize)
{
Solarize();
}
if (m_presetState.invert)
{
Invert();
}
Renderer::Mesh::Unbind();
Renderer::Shader::Unbind();
BlendMode::SetBlendActive(false);
}
void Filters::Brighten()
{
BlendMode::SetBlendFunction(BlendMode::Function::OneMinusDestinationColor, BlendMode::Function::Zero);
m_filterMesh.Draw();
BlendMode::SetBlendFunction(BlendMode::Function::Zero, BlendMode::Function::DestinationColor);
m_filterMesh.Draw();
BlendMode::SetBlendFunction(BlendMode::Function::OneMinusDestinationColor, BlendMode::Function::Zero);
m_filterMesh.Draw();
}
void Filters::Darken()
{
BlendMode::SetBlendFunction(BlendMode::Function::Zero, BlendMode::Function::DestinationColor);
m_filterMesh.Draw();
}
void Filters::Solarize()
{
BlendMode::SetBlendFunction(BlendMode::Function::Zero, BlendMode::Function::OneMinusDestinationColor);
m_filterMesh.Draw();
BlendMode::SetBlendFunction(BlendMode::Function::DestinationColor, BlendMode::Function::One);
m_filterMesh.Draw();
}
void Filters::Invert()
{
BlendMode::SetBlendFunction(BlendMode::Function::OneMinusDestinationColor, BlendMode::Function::Zero);
m_filterMesh.Draw();
}
void Filters::UpdateMesh()
{
if (m_viewportWidth == m_presetState.renderContext.viewportSizeX &&
m_viewportHeight == m_presetState.renderContext.viewportSizeY)
{
return;
}
m_viewportWidth = m_presetState.renderContext.viewportSizeX;
m_viewportHeight = m_presetState.renderContext.viewportSizeY;
float const fOnePlusInvWidth = 1.0f + 1.0f / static_cast<float>(m_viewportWidth);
float const fOnePlusInvHeight = 1.0f + 1.0f / static_cast<float>(m_viewportHeight);
m_filterMesh.Vertices().Set({{-fOnePlusInvWidth, fOnePlusInvHeight},
{fOnePlusInvWidth, fOnePlusInvHeight},
{-fOnePlusInvWidth, -fOnePlusInvHeight},
{fOnePlusInvWidth, -fOnePlusInvHeight}});
m_filterMesh.Update();
}
} // namespace MilkdropPreset
} // namespace libprojectM