9 shader_(nullptr), vertical_(vertical), additive_blending_(true), display_scale_(1.0f), power_scale_(false),
10 square_scale_(false), dirty_(false), num_points_(num_points), total_points_(num_points) {
30 bar_data_[vertex_index] = 2.0f * t - 1.0f;
64 open_gl.
context.extensions.glBufferData(GL_ARRAY_BUFFER, vert_size,
bar_data_.get(), GL_STATIC_DRAW);
76 open_gl.
context.extensions.glBufferData(GL_ELEMENT_ARRAY_BUFFER, bar_size,
bar_indices_.get(), GL_STATIC_DRAW);
101 glEnable(GL_SCISSOR_TEST);
103 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
105 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
114 open_gl.
context.extensions.glBufferData(GL_ARRAY_BUFFER, vert_size,
bar_data_.get(), GL_STATIC_DRAW);
115 open_gl.
context.extensions.glBindBuffer(GL_ARRAY_BUFFER, 0);
126 float min_width = 4.0f / getWidth();
133 open_gl.
context.extensions.glEnableVertexAttribArray(
position_->attributeID);
138 open_gl.
context.extensions.glEnableVertexAttribArray(
corner_->attributeID);
142 open_gl.
context.extensions.glDisableVertexAttribArray(
position_->attributeID);
143 open_gl.
context.extensions.glBindBuffer(GL_ARRAY_BUFFER, 0);
144 open_gl.
context.extensions.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
146 glDisable(GL_SCISSOR_TEST);
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
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
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
force_inline void setScaledY(int index, float val)
Sets the scaled y-value at a specific index.
Definition bar_renderer.h:236
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
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
std::unique_ptr< OpenGLShaderProgram::Attribute > corner_
Attribute for corner coordinates.
Definition bar_renderer.h:267
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
static bool setViewPort(Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl)
Sets the OpenGL viewport to match a specified rectangle within a component.
Definition open_gl_component.cpp:42
void addRoundedCorners()
Adds rounded corners to the component's edges.
Definition open_gl_component.cpp:138
static std::unique_ptr< OpenGLShaderProgram::Attribute > getAttribute(const OpenGlWrapper &open_gl, const OpenGLShaderProgram &program, const char *name)
Retrieves an attribute from the shader program if it exists.
Definition open_gl_component.h:79
virtual void destroy(OpenGlWrapper &open_gl)
Destroys any OpenGL-specific resources allocated by this component.
Definition open_gl_component.cpp:168
static std::unique_ptr< OpenGLShaderProgram::Uniform > getUniform(const OpenGlWrapper &open_gl, const OpenGLShaderProgram &program, const char *name)
Retrieves a uniform from the shader program if it exists.
Definition open_gl_component.h:64
virtual void init(OpenGlWrapper &open_gl)
Initializes any OpenGL-specific resources needed by the component.
Definition open_gl_component.cpp:148
@ kBarVerticalVertex
Definition shaders.h:48
@ kBarHorizontalVertex
Definition shaders.h:47
@ kBarFragment
Definition shaders.h:79
OpenGLShaderProgram * getShaderProgram(VertexShader vertex_shader, FragmentShader fragment_shader, const GLchar **varyings=nullptr)
Retrieves or creates an OpenGLShaderProgram from a given vertex and fragment shader pair.
Definition shaders.cpp:953
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174
OpenGLContext & context
The OpenGLContext for current rendering.
Definition shaders.h:181
Shaders * shaders
Pointer to the Shaders instance providing compiled shaders.
Definition shaders.h:182
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...