179 inline void positionBar(
int index,
float x,
float y,
float width,
float height) {
219 float value =
yAt(index) * 0.5f + 0.5f;
242 value = sqrtf(value);
244 setY(index, 2.0f * value - 1.0f);
266 std::unique_ptr<OpenGLShaderProgram::Attribute>
position_;
267 std::unique_ptr<OpenGLShaderProgram::Attribute>
corner_;
289 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(
BarRenderer)
A renderer for drawing a series of bars using OpenGL.
Definition bar_renderer.h:18
void setColor(const Colour &color)
Sets the color of the bars.
Definition bar_renderer.h:76
void positionBar(int index, float x, float y, float width, float height)
Positions a bar at a specific rectangle.
Definition bar_renderer.h:179
void setOffset(float offset)
Sets an offset applied to the bar positions.
Definition bar_renderer.h:88
bool additive_blending_
If true, uses additive blending for rendering.
Definition bar_renderer.h:274
void setPowerScale(bool scale)
Enables or disables power scaling of bar heights.
Definition bar_renderer.cpp:197
float bottomAt(int index)
Gets the y-position of the bottom-left vertex of the given bar.
Definition bar_renderer.h:134
BarRenderer(int num_points, bool vertical=true)
Constructs a BarRenderer.
Definition bar_renderer.cpp:8
force_inline void setX(int index, float val)
Sets the x-position for all vertices of a specific bar.
Definition bar_renderer.h:141
float yAt(int index)
Gets the y-position of the top-left vertex of the given bar.
Definition bar_renderer.h:127
std::unique_ptr< OpenGLShaderProgram::Attribute > position_
Attribute for vertex position.
Definition bar_renderer.h:266
std::unique_ptr< OpenGLShaderProgram::Uniform > dimensions_uniform_
Uniform for viewport dimensions.
Definition bar_renderer.h:262
force_inline float scaledYAt(int index)
Gets the scaled y-value of a bar at a given index.
Definition bar_renderer.h:218
float bar_width_
Relative width of each bar.
Definition bar_renderer.h:273
std::unique_ptr< float[]> bar_corner_data_
Bar corner coordinate data.
Definition bar_renderer.h:283
Colour color_
Current color of the bars.
Definition bar_renderer.h:269
float rightAt(int index)
Gets the x-position of the top-right vertex of the given bar.
Definition bar_renderer.h:120
OpenGLShaderProgram * shader_
The shader program used for rendering.
Definition bar_renderer.h:260
bool power_scale_
True if power scaling is applied to bar heights.
Definition bar_renderer.h:277
force_inline void setBottom(int index, float val)
Sets the bottom y-position of a specific bar.
Definition bar_renderer.h:165
force_inline void setAdditiveBlending(bool additive_blending)
Enables or disables additive blending for the bar rendering.
Definition bar_renderer.h:251
std::unique_ptr< float[]> bar_data_
Raw bar vertex position data.
Definition bar_renderer.h:282
static constexpr int kCornerFloatsPerVertex
Number of corner floats per vertex (used to determine corner coordinates).
Definition bar_renderer.h:36
void setSquareScale(bool scale)
Enables or disables square scaling of bar heights.
Definition bar_renderer.cpp:212
std::unique_ptr< int[]> bar_indices_
Triangle index data for bars.
Definition bar_renderer.h:284
void setNumPoints(int num_points)
Updates the number of points (bars) to display.
Definition bar_renderer.h:100
float getBarWidth()
Gets the current bar width factor.
Definition bar_renderer.h:106
force_inline void setScaledY(int index, float val)
Sets the scaled y-value at a specific index.
Definition bar_renderer.h:236
void setScale(float scale)
Sets the scaling factor for the bars.
Definition bar_renderer.h:82
std::unique_ptr< OpenGLShaderProgram::Uniform > width_percent_uniform_
Uniform for bar width factor.
Definition bar_renderer.h:265
static constexpr int kFloatsPerBar
Number of floats per bar (4 vertices * 3 floats each).
Definition bar_renderer.h:30
float display_scale_
Additional scaling factor applied to bar sizes.
Definition bar_renderer.h:275
void setBarWidth(float bar_width)
Sets the relative width of each bar.
Definition bar_renderer.h:94
float offset_
Offset applied to bar positions.
Definition bar_renderer.h:272
void setBarSizes()
Updates the bar sizes based on their positions and scaling.
Definition bar_renderer.cpp:171
virtual void destroy(OpenGlWrapper &open_gl) override
Destroys any allocated OpenGL resources.
Definition bar_renderer.cpp:153
std::unique_ptr< OpenGLShaderProgram::Uniform > scale_uniform_
Uniform for scaling factor.
Definition bar_renderer.h:264
static constexpr int kCornerFloatsPerBar
Number of corner floats per bar.
Definition bar_renderer.h:39
bool vertical_
True if bars are rendered vertically.
Definition bar_renderer.h:270
virtual void init(OpenGlWrapper &open_gl) override
Initializes the renderer with an OpenGL context.
Definition bar_renderer.cpp:57
int num_points_
Number of bars to render.
Definition bar_renderer.h:280
float xAt(int index)
Gets the x-position of the top-left vertex of the given bar.
Definition bar_renderer.h:113
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the bars using the current OpenGL context.
Definition bar_renderer.cpp:149
static constexpr int kTriangleIndicesPerBar
Number of triangle indices per bar (each bar represented as two triangles).
Definition bar_renderer.h:33
bool dirty_
True if bar data needs to be re-uploaded to the GPU.
Definition bar_renderer.h:279
std::unique_ptr< OpenGLShaderProgram::Uniform > offset_uniform_
Uniform for position offset.
Definition bar_renderer.h:263
float scale_
Scale factor for bar dimensions.
Definition bar_renderer.h:271
void drawBars(OpenGlWrapper &open_gl)
Draws the bars to the currently active OpenGL context.
Definition bar_renderer.cpp:93
std::unique_ptr< OpenGLShaderProgram::Uniform > color_uniform_
Uniform for bar color.
Definition bar_renderer.h:261
static constexpr float kScaleConstant
A scaling constant used when applying power scaling.
Definition bar_renderer.h:21
std::unique_ptr< OpenGLShaderProgram::Attribute > corner_
Attribute for corner coordinates.
Definition bar_renderer.h:267
force_inline void setY(int index, float val)
Sets the top y-position of a specific bar.
Definition bar_renderer.h:154
virtual ~BarRenderer()
Destructor.
Definition bar_renderer.cpp:55
GLuint bar_indices_buffer_
OpenGL buffer object for bar indices.
Definition bar_renderer.h:287
int total_points_
Total number of allocated points (bars).
Definition bar_renderer.h:281
static constexpr int kFloatsPerVertex
Number of float values per vertex (x, y, [and potentially other attributes]).
Definition bar_renderer.h:24
GLuint bar_corner_buffer_
OpenGL buffer object for bar corners.
Definition bar_renderer.h:286
bool square_scale_
True if square scaling is applied to bar heights.
Definition bar_renderer.h:278
static constexpr int kVerticesPerBar
Number of vertices per bar.
Definition bar_renderer.h:27
GLuint bar_buffer_
OpenGL buffer object for bar positions.
Definition bar_renderer.h:285
A base component class that integrates JUCE's Component with OpenGL rendering.
Definition open_gl_component.h:20
#define force_inline
Definition common.h:23
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174