Vital
Loading...
Searching...
No Matches
OpenGlComponent Class Referenceabstract

A base component class that integrates JUCE's Component with OpenGL rendering. More...

#include <open_gl_component.h>

Inheritance diagram for OpenGlComponent:
BarRenderer CompressorEditor MidiKeyboard OpenGlButtonComponent OpenGlImageComponent OpenGlLineRenderer OpenGlMultiImage OpenGlMultiQuad OpenGlShapeButtonComponent OverlayBackgroundRenderer PeakMeterViewer Wavetable3d

Public Member Functions

 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.
 
virtual void init (OpenGlWrapper &open_gl)
 Initializes any OpenGL-specific resources needed by the component.
 
virtual void render (OpenGlWrapper &open_gl, bool animate)=0
 Pure virtual function to render the component using OpenGL.
 
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 destroy (OpenGlWrapper &open_gl)
 Destroys any OpenGL-specific resources allocated by this component.
 
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 Member Functions

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.
 

Protected Member Functions

bool setViewPort (OpenGlWrapper &open_gl)
 Sets the viewport for this component using the current OpenGlWrapper.
 

Protected Attributes

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.
 

Detailed Description

A base component class that integrates JUCE's Component with OpenGL rendering.

The OpenGlComponent class acts as a foundation for GUI elements that require OpenGL rendering. It provides utility functions to set the viewport and scissor bounds, handle parent hierarchy changes, manage OpenGL corners (rounded rectangles), and integrate skin values from a parent SynthSection. Derived classes can override the rendering functions to draw custom visuals using OpenGL.

Constructor & Destructor Documentation

◆ OpenGlComponent()

OpenGlComponent::OpenGlComponent ( String name = "")

Constructs an OpenGlComponent.

Parameters
nameOptional name for the component.

◆ ~OpenGlComponent()

OpenGlComponent::~OpenGlComponent ( )
virtual

Destructor.

Member Function Documentation

◆ addBottomRoundedCorners()

void OpenGlComponent::addBottomRoundedCorners ( )

Adds rounded corners only at the bottom of the component.

◆ addRoundedCorners()

void OpenGlComponent::addRoundedCorners ( )

Adds rounded corners to the component's edges.

◆ checkGlError()

force_inline void OpenGlComponent::checkGlError ( )
inline

Checks for and asserts that there are no OpenGL errors.

◆ destroy()

◆ findValue()

float OpenGlComponent::findValue ( Skin::ValueId value_id)

Finds a float value from the skin associated with this component's parent.

Parameters
value_idThe Skin::ValueId to lookup.
Returns
The retrieved float value.

◆ getAttribute()

static std::unique_ptr< OpenGLShaderProgram::Attribute > OpenGlComponent::getAttribute ( const OpenGlWrapper & open_gl,
const OpenGLShaderProgram & program,
const char * name )
inlinestatic

Retrieves an attribute from the shader program if it exists.

Parameters
open_glThe OpenGlWrapper containing the GL context.
programThe shader program to query.
nameThe name of the attribute variable.
Returns
A unique_ptr to the Attribute, or nullptr if not found.

◆ getBodyColor()

Colour OpenGlComponent::getBodyColor ( ) const
inline

Retrieves the component's body color.

Returns
The body color.

◆ getUniform()

static std::unique_ptr< OpenGLShaderProgram::Uniform > OpenGlComponent::getUniform ( const OpenGlWrapper & open_gl,
const OpenGLShaderProgram & program,
const char * name )
inlinestatic

Retrieves a uniform from the shader program if it exists.

Parameters
open_glThe OpenGlWrapper containing the GL context.
programThe shader program to query.
nameThe name of the uniform variable.
Returns
A unique_ptr to the Uniform, or nullptr if not found.

◆ init()

◆ paintBackground()

◆ parentHierarchyChanged()

void OpenGlComponent::parentHierarchyChanged ( )
overridevirtual

Called when the component's parent hierarchy changes.

Used to retrieve parent references (like num_voices_readout_ from SynthGuiInterface).

Reimplemented in ChorusViewer, CompressorEditor, EnvelopeEditor, LfoEditor, LineMapEditor, MidiKeyboard, ModulationButton, ModulationMeterReadouts, OpenGlShapeButtonComponent, and RandomViewer.

◆ render()

◆ renderCorners() [1/2]

void OpenGlComponent::renderCorners ( OpenGlWrapper & open_gl,
bool animate )

Renders corners with default body color and rounding.

Parameters
open_glThe OpenGlWrapper for OpenGL context.
animateIf true, enable animated rendering.

◆ renderCorners() [2/2]

void OpenGlComponent::renderCorners ( OpenGlWrapper & open_gl,
bool animate,
Colour color,
float rounding )

Renders the corner shapes using the given color and rounding amount.

Parameters
open_glThe OpenGlWrapper for OpenGL context.
animateIf true, enable animated rendering.
colorThe color to draw the corners.
roundingThe rounding radius for corners.

◆ repaintBackground()

void OpenGlComponent::repaintBackground ( )

Requests a repaint of the component's background on the OpenGL layer.

◆ resized()

void OpenGlComponent::resized ( )
overridevirtual

◆ setBackgroundColor()

void OpenGlComponent::setBackgroundColor ( const Colour & color)
inline

Sets the background color of the component for painting operations.

Parameters
colorThe new background color.

◆ setParent()

void OpenGlComponent::setParent ( const SynthSection * parent)
inline

Sets a pointer to the parent SynthSection for skin value lookups.

Parameters
parentThe parent SynthSection.

◆ setScissor()

void OpenGlComponent::setScissor ( Component * component,
OpenGlWrapper & open_gl )
static

Sets the OpenGL scissor region to the entire component's local bounds.

Parameters
componentThe component for which the scissor is being set.
open_glThe OpenGlWrapper with the OpenGL context.

◆ setScissorBounds()

void OpenGlComponent::setScissorBounds ( Component * component,
Rectangle< int > bounds,
OpenGlWrapper & open_gl )
static

Sets the OpenGL scissor region to a specified rectangle within a component.

Parameters
componentThe component for which the scissor is being set.
boundsThe local bounds to restrict rendering to.
open_glThe OpenGlWrapper with the OpenGL context.

◆ setSkinOverride()

void OpenGlComponent::setSkinOverride ( Skin::SectionOverride skin_override)
inline

Sets a skin override to control the component's color scheme.

Parameters
skin_overrideThe skin override enum value.

◆ setSkinValues()

void OpenGlComponent::setSkinValues ( const Skin & skin)
inline

Applies the skin overrides to this component's colors.

Parameters
skinThe Skin object containing color definitions.

◆ setViewPort() [1/3]

bool OpenGlComponent::setViewPort ( Component * component,
OpenGlWrapper & open_gl )
static

Convenience overload that sets the viewport for the entire component's local bounds.

Parameters
componentThe component to set the viewport for.
open_glThe OpenGlWrapper with the OpenGL context.
Returns
True if the viewport is successfully set.

◆ setViewPort() [2/3]

bool OpenGlComponent::setViewPort ( Component * component,
Rectangle< int > bounds,
OpenGlWrapper & open_gl )
static

Sets the OpenGL viewport to match a specified rectangle within a component.

This function calculates the global position of the given bounds inside the component's hierarchy and sets the OpenGL viewport and scissor regions accordingly.

Parameters
componentThe component for which the viewport is being set.
boundsThe local bounds within the component to set as the viewport.
open_glThe OpenGlWrapper that holds the OpenGL context and scaling factors.
Returns
True if the viewport is successfully set, false otherwise.

◆ setViewPort() [3/3]

bool OpenGlComponent::setViewPort ( OpenGlWrapper & open_gl)
protected

Sets the viewport for this component using the current OpenGlWrapper.

Parameters
open_glThe OpenGlWrapper providing the OpenGL context.
Returns
True if viewport setup succeeded.

◆ translateFragmentShader()

static String OpenGlComponent::translateFragmentShader ( const String & code)
inlinestatic

Translates a fragment shader code snippet to be compatible with the current GL version.

Parameters
codeThe original shader code.
Returns
The translated shader code.

◆ translateVertexShader()

static String OpenGlComponent::translateVertexShader ( const String & code)
inlinestatic

Translates a vertex shader code snippet to be compatible with the current GL version.

Parameters
codeThe original shader code.
Returns
The translated shader code.

Member Data Documentation

◆ background_color_

Colour OpenGlComponent::background_color_
protected

The background color of the component.

◆ body_color_

Colour OpenGlComponent::body_color_
protected

The body color of the component.

◆ corners_

std::unique_ptr<OpenGlCorners> OpenGlComponent::corners_
protected

Optional corners for rounded edges.

◆ num_voices_readout_

const vital::StatusOutput* OpenGlComponent::num_voices_readout_
protected

StatusOutput for voice count lookups.

◆ only_bottom_corners_

bool OpenGlComponent::only_bottom_corners_
protected

Flag to round only the bottom corners.

◆ parent_

const SynthSection* OpenGlComponent::parent_
protected

Pointer to parent SynthSection for skin lookups.

◆ skin_override_

Skin::SectionOverride OpenGlComponent::skin_override_
protected

Skin override for custom appearance.


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