Vital
Loading...
Searching...
No Matches
BarRenderer Class Reference

A renderer for drawing a series of bars using OpenGL. More...

#include <bar_renderer.h>

Inheritance diagram for BarRenderer:
OpenGlComponent BarEditor ChorusViewer DelayViewer ModulationMeterReadouts SpreadVisualizer UnisonViewer

Public Member Functions

 BarRenderer (int num_points, bool vertical=true)
 Constructs a BarRenderer.
 
virtual ~BarRenderer ()
 Destructor.
 
virtual void init (OpenGlWrapper &open_gl) override
 Initializes the renderer with an OpenGL context.
 
virtual void render (OpenGlWrapper &open_gl, bool animate) override
 Renders the bars using the current OpenGL context.
 
virtual void destroy (OpenGlWrapper &open_gl) override
 Destroys any allocated OpenGL resources.
 
void setColor (const Colour &color)
 Sets the color of the bars.
 
void setScale (float scale)
 Sets the scaling factor for the bars.
 
void setOffset (float offset)
 Sets an offset applied to the bar positions.
 
void setBarWidth (float bar_width)
 Sets the relative width of each bar.
 
void setNumPoints (int num_points)
 Updates the number of points (bars) to display.
 
float getBarWidth ()
 Gets the current bar width factor.
 
float xAt (int index)
 Gets the x-position of the top-left vertex of the given bar.
 
float rightAt (int index)
 Gets the x-position of the top-right vertex of the given bar.
 
float yAt (int index)
 Gets the y-position of the top-left vertex of the given bar.
 
float bottomAt (int index)
 Gets the y-position of the bottom-left vertex of the given bar.
 
force_inline void setX (int index, float val)
 Sets the x-position for all vertices of a specific bar.
 
force_inline void setY (int index, float val)
 Sets the top y-position of a specific bar.
 
force_inline void setBottom (int index, float val)
 Sets the bottom y-position of a specific bar.
 
void positionBar (int index, float x, float y, float width, float height)
 Positions a bar at a specific rectangle.
 
void setBarSizes ()
 Updates the bar sizes based on their positions and scaling.
 
void setPowerScale (bool scale)
 Enables or disables power scaling of bar heights.
 
void setSquareScale (bool scale)
 Enables or disables square scaling of bar heights.
 
force_inline float scaledYAt (int index)
 Gets the scaled y-value of a bar at a given index.
 
force_inline void setScaledY (int index, float val)
 Sets the scaled y-value at a specific index.
 
force_inline void setAdditiveBlending (bool additive_blending)
 Enables or disables additive blending for the bar rendering.
 
- Public Member Functions inherited from OpenGlComponent
 OpenGlComponent (String name="")
 Constructs an OpenGlComponent.
 
virtual ~OpenGlComponent ()
 Destructor.
 
virtual void resized () override
 Called when the component is resized.
 
virtual void parentHierarchyChanged () override
 Called when the component's parent hierarchy changes.
 
void addRoundedCorners ()
 Adds rounded corners to the component's edges.
 
void addBottomRoundedCorners ()
 Adds rounded corners only at the bottom of the component.
 
void renderCorners (OpenGlWrapper &open_gl, bool animate, Colour color, float rounding)
 Renders the corner shapes using the given color and rounding amount.
 
void renderCorners (OpenGlWrapper &open_gl, bool animate)
 Renders corners with default body color and rounding.
 
virtual void paintBackground (Graphics &g)
 Paints a standard background for the component.
 
void repaintBackground ()
 Requests a repaint of the component's background on the OpenGL layer.
 
Colour getBodyColor () const
 Retrieves the component's body color.
 
void setParent (const SynthSection *parent)
 Sets a pointer to the parent SynthSection for skin value lookups.
 
float findValue (Skin::ValueId value_id)
 Finds a float value from the skin associated with this component's parent.
 
void setSkinValues (const Skin &skin)
 Applies the skin overrides to this component's colors.
 
void setSkinOverride (Skin::SectionOverride skin_override)
 Sets a skin override to control the component's color scheme.
 
force_inline void checkGlError ()
 Checks for and asserts that there are no OpenGL errors.
 
void setBackgroundColor (const Colour &color)
 Sets the background color of the component for painting operations.
 

Static Public Attributes

static constexpr float kScaleConstant = 5.0f
 A scaling constant used when applying power scaling.
 
static constexpr int kFloatsPerVertex = 3
 Number of float values per vertex (x, y, [and potentially other attributes]).
 
static constexpr int kVerticesPerBar = 4
 Number of vertices per bar.
 
static constexpr int kFloatsPerBar = kVerticesPerBar * kFloatsPerVertex
 Number of floats per bar (4 vertices * 3 floats each).
 
static constexpr int kTriangleIndicesPerBar = 6
 Number of triangle indices per bar (each bar represented as two triangles).
 
static constexpr int kCornerFloatsPerVertex = 2
 Number of corner floats per vertex (used to determine corner coordinates).
 
static constexpr int kCornerFloatsPerBar = kVerticesPerBar * kCornerFloatsPerVertex
 Number of corner floats per bar.
 

Protected Member Functions

void drawBars (OpenGlWrapper &open_gl)
 Draws the bars to the currently active OpenGL context.
 
- Protected Member Functions inherited from OpenGlComponent
bool setViewPort (OpenGlWrapper &open_gl)
 Sets the viewport for this component using the current OpenGlWrapper.
 

Protected Attributes

OpenGLShaderProgram * shader_
 The shader program used for rendering.
 
std::unique_ptr< OpenGLShaderProgram::Uniform > color_uniform_
 Uniform for bar color.
 
std::unique_ptr< OpenGLShaderProgram::Uniform > dimensions_uniform_
 Uniform for viewport dimensions.
 
std::unique_ptr< OpenGLShaderProgram::Uniform > offset_uniform_
 Uniform for position offset.
 
std::unique_ptr< OpenGLShaderProgram::Uniform > scale_uniform_
 Uniform for scaling factor.
 
std::unique_ptr< OpenGLShaderProgram::Uniform > width_percent_uniform_
 Uniform for bar width factor.
 
std::unique_ptr< OpenGLShaderProgram::Attribute > position_
 Attribute for vertex position.
 
std::unique_ptr< OpenGLShaderProgram::Attribute > corner_
 Attribute for corner coordinates.
 
Colour color_
 Current color of the bars.
 
bool vertical_
 True if bars are rendered vertically.
 
float scale_
 Scale factor for bar dimensions.
 
float offset_
 Offset applied to bar positions.
 
float bar_width_
 Relative width of each bar.
 
bool additive_blending_
 If true, uses additive blending for rendering.
 
float display_scale_
 Additional scaling factor applied to bar sizes.
 
bool power_scale_
 True if power scaling is applied to bar heights.
 
bool square_scale_
 True if square scaling is applied to bar heights.
 
bool dirty_
 True if bar data needs to be re-uploaded to the GPU.
 
int num_points_
 Number of bars to render.
 
int total_points_
 Total number of allocated points (bars).
 
std::unique_ptr< float[]> bar_data_
 Raw bar vertex position data.
 
std::unique_ptr< float[]> bar_corner_data_
 Bar corner coordinate data.
 
std::unique_ptr< int[]> bar_indices_
 Triangle index data for bars.
 
GLuint bar_buffer_
 OpenGL buffer object for bar positions.
 
GLuint bar_corner_buffer_
 OpenGL buffer object for bar corners.
 
GLuint bar_indices_buffer_
 OpenGL buffer object for bar indices.
 
- Protected Attributes inherited from OpenGlComponent
std::unique_ptr< OpenGlCornerscorners_
 Optional corners for rounded edges.
 
bool only_bottom_corners_
 Flag to round only the bottom corners.
 
Colour background_color_
 The background color of the component.
 
Colour body_color_
 The body color of the component.
 
const SynthSectionparent_
 Pointer to parent SynthSection for skin lookups.
 
Skin::SectionOverride skin_override_
 Skin override for custom appearance.
 
const vital::StatusOutputnum_voices_readout_
 StatusOutput for voice count lookups.
 

Additional Inherited Members

- Static Public Member Functions inherited from OpenGlComponent
static bool setViewPort (Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl)
 Sets the OpenGL viewport to match a specified rectangle within a component.
 
static bool setViewPort (Component *component, OpenGlWrapper &open_gl)
 Convenience overload that sets the viewport for the entire component's local bounds.
 
static void setScissor (Component *component, OpenGlWrapper &open_gl)
 Sets the OpenGL scissor region to the entire component's local bounds.
 
static void setScissorBounds (Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl)
 Sets the OpenGL scissor region to a specified rectangle within a component.
 
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.
 
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.
 
static String translateFragmentShader (const String &code)
 Translates a fragment shader code snippet to be compatible with the current GL version.
 
static String translateVertexShader (const String &code)
 Translates a vertex shader code snippet to be compatible with the current GL version.
 

Detailed Description

A renderer for drawing a series of bars using OpenGL.

This class creates and manages a collection of bars (vertical or horizontal), and handles their geometry, scaling, coloring, and rendering. It uses OpenGL for efficient rendering and can apply different scaling modes (linear, power, square) to the bar heights.

Constructor & Destructor Documentation

◆ BarRenderer()

BarRenderer::BarRenderer ( int num_points,
bool vertical = true )

Constructs a BarRenderer.

Constructs a BarRenderer and initializes bar vertex data.

Parameters
num_pointsThe number of bars to render.
verticalIf true, bars are oriented vertically; otherwise horizontally.

◆ ~BarRenderer()

BarRenderer::~BarRenderer ( )
virtual

Destructor.

Member Function Documentation

◆ bottomAt()

float BarRenderer::bottomAt ( int index)
inline

Gets the y-position of the bottom-left vertex of the given bar.

Parameters
indexThe bar index.
Returns
The y-position.

◆ destroy()

void BarRenderer::destroy ( OpenGlWrapper & open_gl)
overridevirtual

Destroys any allocated OpenGL resources.

Parameters
open_glThe OpenGL wrapper to use for resource cleanup.

Reimplemented from OpenGlComponent.

Reimplemented in BarEditor.

◆ drawBars()

void BarRenderer::drawBars ( OpenGlWrapper & open_gl)
protected

Draws the bars to the currently active OpenGL context.

Parameters
open_glThe OpenGL wrapper.

◆ getBarWidth()

float BarRenderer::getBarWidth ( )
inline

Gets the current bar width factor.

Returns
The bar width factor.

◆ init()

void BarRenderer::init ( OpenGlWrapper & open_gl)
overridevirtual

Initializes the renderer with an OpenGL context.

Parameters
open_glThe OpenGL wrapper to use for initialization.

Reimplemented from OpenGlComponent.

Reimplemented in BarEditor.

◆ positionBar()

void BarRenderer::positionBar ( int index,
float x,
float y,
float width,
float height )
inline

Positions a bar at a specific rectangle.

Parameters
indexThe bar index.
xThe left x-position.
yThe top y-position.
widthThe width of the bar.
heightThe height of the bar.

◆ render()

void BarRenderer::render ( OpenGlWrapper & open_gl,
bool animate )
overridevirtual

Renders the bars using the current OpenGL context.

Parameters
open_glThe OpenGL wrapper to use for rendering.
animateIf true, allows for animated updates (unused here).

Implements OpenGlComponent.

Reimplemented in BarEditor, ChorusViewer, DelayViewer, ModulationMeterReadouts, SpreadVisualizer, and UnisonViewer.

◆ rightAt()

float BarRenderer::rightAt ( int index)
inline

Gets the x-position of the top-right vertex of the given bar.

Parameters
indexThe bar index.
Returns
The x-position.

◆ scaledYAt()

force_inline float BarRenderer::scaledYAt ( int index)
inline

Gets the scaled y-value of a bar at a given index.

The scaling is applied based on the current mode (power/square).

Parameters
indexThe bar index.
Returns
The scaled y-value in [0, 1].

◆ setAdditiveBlending()

force_inline void BarRenderer::setAdditiveBlending ( bool additive_blending)
inline

Enables or disables additive blending for the bar rendering.

Parameters
additive_blendingTrue for additive blending, false for normal alpha blending.

◆ setBarSizes()

void BarRenderer::setBarSizes ( )

Updates the bar sizes based on their positions and scaling.

◆ setBarWidth()

void BarRenderer::setBarWidth ( float bar_width)
inline

Sets the relative width of each bar.

Parameters
bar_widthThe bar width factor.

◆ setBottom()

force_inline void BarRenderer::setBottom ( int index,
float val )
inline

Sets the bottom y-position of a specific bar.

Parameters
indexThe bar index.
valThe new bottom y-position.

◆ setColor()

void BarRenderer::setColor ( const Colour & color)
inline

Sets the color of the bars.

Parameters
colorThe colour to set.

◆ setNumPoints()

void BarRenderer::setNumPoints ( int num_points)
inline

Updates the number of points (bars) to display.

Parameters
num_pointsThe new number of bars.

◆ setOffset()

void BarRenderer::setOffset ( float offset)
inline

Sets an offset applied to the bar positions.

Parameters
offsetThe offset value.

◆ setPowerScale()

void BarRenderer::setPowerScale ( bool scale)

Enables or disables power scaling of bar heights.

Parameters
scaleTrue to enable power scaling, false to disable.

◆ setScale()

void BarRenderer::setScale ( float scale)
inline

Sets the scaling factor for the bars.

Parameters
scaleThe scaling factor.

◆ setScaledY()

force_inline void BarRenderer::setScaledY ( int index,
float val )
inline

Sets the scaled y-value at a specific index.

This function takes a value in [0,1], applies inverse scaling based on the current scaling modes, and updates the bar's actual y-position.

Parameters
indexThe bar index.
valThe scaled y-value [0,1].

◆ setSquareScale()

void BarRenderer::setSquareScale ( bool scale)

Enables or disables square scaling of bar heights.

Parameters
scaleTrue to enable square scaling, false to disable.

◆ setX()

force_inline void BarRenderer::setX ( int index,
float val )
inline

Sets the x-position for all vertices of a specific bar.

Parameters
indexThe bar index.
valThe new x-position.

◆ setY()

force_inline void BarRenderer::setY ( int index,
float val )
inline

Sets the top y-position of a specific bar.

Parameters
indexThe bar index.
valThe new top y-position.

◆ xAt()

float BarRenderer::xAt ( int index)
inline

Gets the x-position of the top-left vertex of the given bar.

Parameters
indexThe bar index.
Returns
The x-position.

◆ yAt()

float BarRenderer::yAt ( int index)
inline

Gets the y-position of the top-left vertex of the given bar.

Parameters
indexThe bar index.
Returns
The y-position.

Member Data Documentation

◆ additive_blending_

bool BarRenderer::additive_blending_
protected

If true, uses additive blending for rendering.

◆ bar_buffer_

GLuint BarRenderer::bar_buffer_
protected

OpenGL buffer object for bar positions.

◆ bar_corner_buffer_

GLuint BarRenderer::bar_corner_buffer_
protected

OpenGL buffer object for bar corners.

◆ bar_corner_data_

std::unique_ptr<float[]> BarRenderer::bar_corner_data_
protected

Bar corner coordinate data.

◆ bar_data_

std::unique_ptr<float[]> BarRenderer::bar_data_
protected

Raw bar vertex position data.

◆ bar_indices_

std::unique_ptr<int[]> BarRenderer::bar_indices_
protected

Triangle index data for bars.

◆ bar_indices_buffer_

GLuint BarRenderer::bar_indices_buffer_
protected

OpenGL buffer object for bar indices.

◆ bar_width_

float BarRenderer::bar_width_
protected

Relative width of each bar.

◆ color_

Colour BarRenderer::color_
protected

Current color of the bars.

◆ color_uniform_

std::unique_ptr<OpenGLShaderProgram::Uniform> BarRenderer::color_uniform_
protected

Uniform for bar color.

◆ corner_

std::unique_ptr<OpenGLShaderProgram::Attribute> BarRenderer::corner_
protected

Attribute for corner coordinates.

◆ dimensions_uniform_

std::unique_ptr<OpenGLShaderProgram::Uniform> BarRenderer::dimensions_uniform_
protected

Uniform for viewport dimensions.

◆ dirty_

bool BarRenderer::dirty_
protected

True if bar data needs to be re-uploaded to the GPU.

◆ display_scale_

float BarRenderer::display_scale_
protected

Additional scaling factor applied to bar sizes.

◆ kCornerFloatsPerBar

int BarRenderer::kCornerFloatsPerBar = kVerticesPerBar * kCornerFloatsPerVertex
staticconstexpr

Number of corner floats per bar.

◆ kCornerFloatsPerVertex

int BarRenderer::kCornerFloatsPerVertex = 2
staticconstexpr

Number of corner floats per vertex (used to determine corner coordinates).

◆ kFloatsPerBar

int BarRenderer::kFloatsPerBar = kVerticesPerBar * kFloatsPerVertex
staticconstexpr

Number of floats per bar (4 vertices * 3 floats each).

◆ kFloatsPerVertex

int BarRenderer::kFloatsPerVertex = 3
staticconstexpr

Number of float values per vertex (x, y, [and potentially other attributes]).

◆ kScaleConstant

float BarRenderer::kScaleConstant = 5.0f
staticconstexpr

A scaling constant used when applying power scaling.

◆ kTriangleIndicesPerBar

int BarRenderer::kTriangleIndicesPerBar = 6
staticconstexpr

Number of triangle indices per bar (each bar represented as two triangles).

◆ kVerticesPerBar

int BarRenderer::kVerticesPerBar = 4
staticconstexpr

Number of vertices per bar.

◆ num_points_

int BarRenderer::num_points_
protected

Number of bars to render.

◆ offset_

float BarRenderer::offset_
protected

Offset applied to bar positions.

◆ offset_uniform_

std::unique_ptr<OpenGLShaderProgram::Uniform> BarRenderer::offset_uniform_
protected

Uniform for position offset.

◆ position_

std::unique_ptr<OpenGLShaderProgram::Attribute> BarRenderer::position_
protected

Attribute for vertex position.

◆ power_scale_

bool BarRenderer::power_scale_
protected

True if power scaling is applied to bar heights.

◆ scale_

float BarRenderer::scale_
protected

Scale factor for bar dimensions.

◆ scale_uniform_

std::unique_ptr<OpenGLShaderProgram::Uniform> BarRenderer::scale_uniform_
protected

Uniform for scaling factor.

◆ shader_

OpenGLShaderProgram* BarRenderer::shader_
protected

The shader program used for rendering.

◆ square_scale_

bool BarRenderer::square_scale_
protected

True if square scaling is applied to bar heights.

◆ total_points_

int BarRenderer::total_points_
protected

Total number of allocated points (bars).

◆ vertical_

bool BarRenderer::vertical_
protected

True if bars are rendered vertically.

◆ width_percent_uniform_

std::unique_ptr<OpenGLShaderProgram::Uniform> BarRenderer::width_percent_uniform_
protected

Uniform for bar width factor.


The documentation for this class was generated from the following files: