Vital
Loading...
Searching...
No Matches
open_gl_line_renderer.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "common.h"
5#include "open_gl_component.h"
7
17public:
19 static constexpr int kLineFloatsPerVertex = 3;
21 static constexpr int kFillFloatsPerVertex = 4;
23 static constexpr int kLineVerticesPerPoint = 6;
25 static constexpr int kFillVerticesPerPoint = 2;
30
36 OpenGlLineRenderer(int num_points, bool loop = false);
37
41 virtual ~OpenGlLineRenderer();
42
47 virtual void init(OpenGlWrapper& open_gl) override;
48
54 virtual void render(OpenGlWrapper& open_gl, bool animate) override;
55
60 virtual void destroy(OpenGlWrapper& open_gl) override;
61
63 force_inline void setColor(Colour color) { color_ = color; }
64
66 force_inline void setLineWidth(float width) { line_width_ = width; }
67
69 force_inline void setBoost(float boost) { boost_ = boost; }
70
72 force_inline float boostLeftAt(int index) const { return boost_left_[index]; }
73
75 force_inline float boostRightAt(int index) const { return boost_right_[index]; }
76
78 force_inline float yAt(int index) const { return y_[index]; }
79
81 force_inline float xAt(int index) const { return x_[index]; }
82
84 force_inline void setBoostLeft(int index, float val) {
85 boost_left_[index] = val;
86 dirty_ = true;
87 VITAL_ASSERT(num_points_ > index);
88 }
89
91 force_inline void setBoostRight(int index, float val) {
92 boost_right_[index] = val;
93 dirty_ = true;
94 VITAL_ASSERT(num_points_ > index);
95 }
96
98 force_inline void setYAt(int index, float val) {
99 y_[index] = val;
100 dirty_ = true;
101 VITAL_ASSERT(num_points_ > index);
102 }
103
105 force_inline void setXAt(int index, float val) {
106 x_[index] = val;
107 dirty_ = true;
108 VITAL_ASSERT(num_points_ > index);
109 }
110
115 void setFillVertices(bool left);
116
121 void setLineVertices(bool left);
122
124 force_inline void setFill(bool fill) { fill_ = fill; }
125
127 force_inline void setFillColor(Colour fill_color) {
128 setFillColors(fill_color, fill_color);
129 }
130
132 force_inline void setFillColors(Colour fill_color_from, Colour fill_color_to) {
133 fill_color_from_ = fill_color_from;
134 fill_color_to_ = fill_color_to;
135 }
136
138 force_inline void setFillCenter(float fill_center) { fill_center_ = fill_center; }
139
141 force_inline void setFit(bool fit) { fit_ = fit; }
142
144 force_inline void setBoostAmount(float boost_amount) { boost_amount_ = boost_amount; }
145
147 force_inline void setFillBoostAmount(float boost_amount) { fill_boost_amount_ = boost_amount; }
148
150 force_inline void setIndex(int index) { index_ = index; }
151
159 void boostLeftRange(float start, float end, int buffer_vertices, float min);
160
164 void boostRightRange(float start, float end, int buffer_vertices, float min);
165
169 void boostRange(float* boosts, float start, float end, int buffer_vertices, float min);
170
174 void boostRange(vital::poly_float start, vital::poly_float end, int buffer_vertices, vital::poly_float min);
175
181
183 void enableBackwardBoost(bool enable) { enable_backward_boost_ = enable; }
184
186 force_inline int numPoints() const { return num_points_; }
187
189 force_inline Colour color() const { return color_; }
190
196 void drawLines(OpenGlWrapper& open_gl, bool left);
197
202 bool anyBoostValue() { return any_boost_value_; }
203
204private:
205 Colour color_;
206 Colour fill_color_from_;
207 Colour fill_color_to_;
208
209 int num_points_;
210 float line_width_;
211 float boost_;
212 bool fill_;
213 float fill_center_;
214 bool fit_;
215
216 float boost_amount_;
217 float fill_boost_amount_;
218 bool enable_backward_boost_;
219 int index_;
220
221 bool dirty_;
222 bool last_drawn_left_;
223 bool last_negative_boost_;
224 bool loop_;
225 bool any_boost_value_;
226 int num_padding_;
227 int num_line_vertices_;
228 int num_fill_vertices_;
229 int num_line_floats_;
230 int num_fill_floats_;
231
232 OpenGLShaderProgram* shader_;
233 std::unique_ptr<OpenGLShaderProgram::Uniform> scale_uniform_;
234 std::unique_ptr<OpenGLShaderProgram::Uniform> color_uniform_;
235 std::unique_ptr<OpenGLShaderProgram::Uniform> boost_uniform_;
236 std::unique_ptr<OpenGLShaderProgram::Uniform> line_width_uniform_;
237 std::unique_ptr<OpenGLShaderProgram::Attribute> position_;
238
239 OpenGLShaderProgram* fill_shader_;
240 std::unique_ptr<OpenGLShaderProgram::Uniform> fill_scale_uniform_;
241 std::unique_ptr<OpenGLShaderProgram::Uniform> fill_color_from_uniform_;
242 std::unique_ptr<OpenGLShaderProgram::Uniform> fill_color_to_uniform_;
243 std::unique_ptr<OpenGLShaderProgram::Uniform> fill_center_uniform_;
244 std::unique_ptr<OpenGLShaderProgram::Uniform> fill_boost_amount_uniform_;
245 std::unique_ptr<OpenGLShaderProgram::Attribute> fill_position_;
246
247 GLuint vertex_array_object_;
248 GLuint line_buffer_;
249 GLuint fill_buffer_;
250 GLuint indices_buffer_;
251
252 std::unique_ptr<float[]> x_;
253 std::unique_ptr<float[]> y_;
254 std::unique_ptr<float[]> boost_left_;
255 std::unique_ptr<float[]> boost_right_;
256 std::unique_ptr<float[]> line_data_;
257 std::unique_ptr<float[]> fill_data_;
258 std::unique_ptr<int[]> indices_data_;
259
260 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OpenGlLineRenderer)
261};
A base component class that integrates JUCE's Component with OpenGL rendering.
Definition open_gl_component.h:20
A component for rendering lines with optional filling and boost effects using OpenGL.
Definition open_gl_line_renderer.h:16
virtual void init(OpenGlWrapper &open_gl) override
Initializes OpenGL resources for rendering the line.
Definition open_gl_line_renderer.cpp:78
virtual void destroy(OpenGlWrapper &open_gl) override
Destroys OpenGL resources allocated by this line renderer.
Definition open_gl_line_renderer.cpp:468
force_inline float xAt(int index) const
Gets the x-coordinate of a point at a given index.
Definition open_gl_line_renderer.h:81
force_inline void setFillCenter(float fill_center)
Sets the vertical center for the fill area.
Definition open_gl_line_renderer.h:138
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the line using OpenGL.
Definition open_gl_line_renderer.cpp:464
force_inline void setYAt(int index, float val)
Sets the y-coordinate of a point, marking data as dirty.
Definition open_gl_line_renderer.h:98
force_inline void setFill(bool fill)
Enables or disables filling below the line.
Definition open_gl_line_renderer.h:124
void decayBoosts(vital::poly_float mult)
Decays all boosts by a multiplicative factor, allowing animated damping.
Definition open_gl_line_renderer.cpp:185
static constexpr int kLineFloatsPerVertex
Floats per vertex in the line data (x, y, and potentially others).
Definition open_gl_line_renderer.h:19
force_inline void setFillBoostAmount(float boost_amount)
Sets the boost amount that affects fill thickness.
Definition open_gl_line_renderer.h:147
force_inline void setBoost(float boost)
Sets a global boost value affecting line thickness.
Definition open_gl_line_renderer.h:69
static constexpr int kFillVerticesPerPoint
Number of vertices per point in the fill representation.
Definition open_gl_line_renderer.h:25
force_inline float boostLeftAt(int index) const
Gets the left-side boost at a given point index.
Definition open_gl_line_renderer.h:72
force_inline void setBoostAmount(float boost_amount)
Sets the boost amount that affects line thickness.
Definition open_gl_line_renderer.h:144
virtual ~OpenGlLineRenderer()
Destructor.
Definition open_gl_line_renderer.cpp:76
force_inline void setBoostRight(int index, float val)
Sets the right-side boost for a point, marking data as dirty.
Definition open_gl_line_renderer.h:91
force_inline void setFillColor(Colour fill_color)
Sets a uniform fill color if only one color is needed.
Definition open_gl_line_renderer.h:127
force_inline void setXAt(int index, float val)
Sets the x-coordinate of a point, marking data as dirty.
Definition open_gl_line_renderer.h:105
void boostRightRange(float start, float end, int buffer_vertices, float min)
Boosts right-side range of the line.
Definition open_gl_line_renderer.cpp:124
static constexpr int kFillFloatsPerVertex
Floats per vertex in the fill data (x, y, and boost value).
Definition open_gl_line_renderer.h:21
static constexpr int kLineVerticesPerPoint
Number of vertices per point in the line representation.
Definition open_gl_line_renderer.h:23
force_inline void setFit(bool fit)
Enables fitting the line inside the available area.
Definition open_gl_line_renderer.h:141
void setLineVertices(bool left)
Sets line vertices according to the current line and boost data.
Definition open_gl_line_renderer.cpp:236
force_inline void setFillColors(Colour fill_color_from, Colour fill_color_to)
Sets a gradient fill from one color to another.
Definition open_gl_line_renderer.h:132
bool anyBoostValue()
Checks if any boost value is set.
Definition open_gl_line_renderer.h:202
void setFillVertices(bool left)
Sets fill vertices according to the current line and boost data.
Definition open_gl_line_renderer.cpp:196
static constexpr int kLineFloatsPerPoint
Floats per point in the line data (6 vertices * 3 floats each).
Definition open_gl_line_renderer.h:27
OpenGlLineRenderer(int num_points, bool loop=false)
Constructs an OpenGlLineRenderer for a given number of points.
Definition open_gl_line_renderer.cpp:35
force_inline void setLineWidth(float width)
Sets the line width in pixels.
Definition open_gl_line_renderer.h:66
static constexpr int kFillFloatsPerPoint
Floats per point in the fill data (2 vertices * 4 floats each).
Definition open_gl_line_renderer.h:29
force_inline float yAt(int index) const
Gets the y-coordinate of a point at a given index.
Definition open_gl_line_renderer.h:78
force_inline void setColor(Colour color)
Sets the line color.
Definition open_gl_line_renderer.h:63
force_inline float boostRightAt(int index) const
Gets the right-side boost at a given point index.
Definition open_gl_line_renderer.h:75
void boostRange(float *boosts, float start, float end, int buffer_vertices, float min)
Boosts a range for the given boost array.
Definition open_gl_line_renderer.cpp:128
force_inline int numPoints() const
Gets the number of points in the line.
Definition open_gl_line_renderer.h:186
force_inline void setBoostLeft(int index, float val)
Sets the left-side boost for a point, marking data as dirty.
Definition open_gl_line_renderer.h:84
void drawLines(OpenGlWrapper &open_gl, bool left)
Draws the line and optional fill using OpenGL.
Definition open_gl_line_renderer.cpp:386
force_inline void setIndex(int index)
Sets an index used for custom behavior (e.g., multiple line sets).
Definition open_gl_line_renderer.h:150
void boostLeftRange(float start, float end, int buffer_vertices, float min)
Boosts left-side range of the line.
Definition open_gl_line_renderer.cpp:120
force_inline Colour color() const
Gets the current line color.
Definition open_gl_line_renderer.h:189
void enableBackwardBoost(bool enable)
Enables backward boost calculation for symmetrical line deformation.
Definition open_gl_line_renderer.h:183
#define VITAL_ASSERT(x)
Definition common.h:11
#define force_inline
Definition common.h:23
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600