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

A component that uses OpenGL to render a cached image of a JUCE component or custom drawing. More...

#include <open_gl_image_component.h>

Inheritance diagram for OpenGlImageComponent:
OpenGlComponent AppLogo MacroLabel PlainShapeComponent PlainTextComponent TransposeQuantizeButton ModulationButton

Public Member Functions

 OpenGlImageComponent (String name="")
 Constructs an OpenGlImageComponent.
 
virtual ~OpenGlImageComponent ()=default
 Destructor.
 
virtual void paintBackground (Graphics &g) override
 Paints the background by redrawing the image if needed.
 
virtual void paintToImage (Graphics &g)
 Renders the associated component (or itself) into the provided Graphics context.
 
virtual void init (OpenGlWrapper &open_gl) override
 Initializes any OpenGL resources for rendering this component.
 
virtual void render (OpenGlWrapper &open_gl, bool animate) override
 Renders the image using OpenGL.
 
virtual void destroy (OpenGlWrapper &open_gl) override
 Destroys OpenGL-related resources used by this component.
 
virtual void redrawImage (bool force)
 Redraws the image if necessary, creating or updating the internal Image.
 
void setComponent (Component *component)
 Sets the component to be drawn into the OpenGL image. If not set, uses this component.
 
void setScissor (bool scissor)
 Enables or disables scissor testing when drawing the image.
 
void setUseAlpha (bool use_alpha)
 Enables or disables alpha blending for the image.
 
void setColor (Colour color)
 Sets a color tint for the image.
 
OpenGlImageimage ()
 Provides access to the underlying OpenGlImage.
 
void setActive (bool active)
 Sets whether this component is active (rendered) or not.
 
void setStatic (bool static_image)
 Sets whether the image should be treated as static (not redrawn unless forced).
 
void paintEntireComponent (bool paint_entire_component)
 Controls whether paintToImage should paint the entire component hierarchy or just itself.
 
bool isActive () const
 Checks if this component is currently active.
 
- 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.
 
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.
 

Protected Attributes

Component * component_
 The component being drawn into the image (if any).
 
bool active_
 Whether this component is active and should render.
 
bool static_image_
 Whether the image is static or updated on events.
 
bool paint_entire_component_
 If true, paint entire component hierarchy to image.
 
std::unique_ptr< Image > draw_image_
 The cached image that stores the drawn component.
 
OpenGlImage image_
 The OpenGlImage used to upload and draw the cached image.
 
- 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.
 
- Protected Member Functions inherited from OpenGlComponent
bool setViewPort (OpenGlWrapper &open_gl)
 Sets the viewport for this component using the current OpenGlWrapper.
 

Detailed Description

A component that uses OpenGL to render a cached image of a JUCE component or custom drawing.

The OpenGlImageComponent captures the output of a Component (or itself) into a JUCE Image, then uploads that image as a texture and renders it using OpenGL. This approach allows complex components to be drawn once and reused for efficient OpenGL rendering. It supports redrawing when necessary and can be set to a static (non-updating) image.

Constructor & Destructor Documentation

◆ OpenGlImageComponent()

OpenGlImageComponent::OpenGlImageComponent ( String name = "")

Constructs an OpenGlImageComponent.

Parameters
nameOptional name for the component.

◆ ~OpenGlImageComponent()

virtual OpenGlImageComponent::~OpenGlImageComponent ( )
virtualdefault

Destructor.

Member Function Documentation

◆ destroy()

void OpenGlImageComponent::destroy ( OpenGlWrapper & open_gl)
overridevirtual

Destroys OpenGL-related resources used by this component.

Parameters
open_glThe OpenGlWrapper with the current OpenGL context.

Reimplemented from OpenGlComponent.

◆ image()

OpenGlImage & OpenGlImageComponent::image ( )
inline

Provides access to the underlying OpenGlImage.

Returns
Reference to the OpenGlImage object.

◆ init()

void OpenGlImageComponent::init ( OpenGlWrapper & open_gl)
overridevirtual

Initializes any OpenGL resources for rendering this component.

Parameters
open_glThe OpenGlWrapper with the current OpenGL context.

Reimplemented from OpenGlComponent.

◆ isActive()

bool OpenGlImageComponent::isActive ( ) const
inline

Checks if this component is currently active.

Returns
True if active, false otherwise.

◆ paintBackground()

virtual void OpenGlImageComponent::paintBackground ( Graphics & g)
inlineoverridevirtual

Paints the background by redrawing the image if needed.

Parameters
gThe graphics context.

Reimplemented from OpenGlComponent.

Reimplemented in ModulationButton, and TransposeQuantizeButton.

◆ paintEntireComponent()

void OpenGlImageComponent::paintEntireComponent ( bool paint_entire_component)
inline

Controls whether paintToImage should paint the entire component hierarchy or just itself.

Parameters
paint_entire_componentTrue to paint entire hierarchy, false otherwise.

◆ paintToImage()

virtual void OpenGlImageComponent::paintToImage ( Graphics & g)
inlinevirtual

Renders the associated component (or itself) into the provided Graphics context.

Parameters
gThe graphics context where the component is painted.

If paint_entire_component_ is true, the entire component hierarchy is painted, otherwise only this component is painted.

Reimplemented in PlainShapeComponent, and PlainTextComponent.

◆ redrawImage()

void OpenGlImageComponent::redrawImage ( bool force)
virtual

Redraws the image if necessary, creating or updating the internal Image.

Parameters
forceIf true, forces a redraw even if conditions haven't changed.

◆ render()

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

Renders the image using OpenGL.

Parameters
open_glThe OpenGlWrapper with the current OpenGL context.
animateIf true, allows for animated drawing.

Implements OpenGlComponent.

Reimplemented in ModulationButton.

◆ setActive()

void OpenGlImageComponent::setActive ( bool active)
inline

Sets whether this component is active (rendered) or not.

Parameters
activeTrue if active, false if inactive.

◆ setColor()

void OpenGlImageComponent::setColor ( Colour color)
inline

Sets a color tint for the image.

Parameters
colorThe tint color.

◆ setComponent()

void OpenGlImageComponent::setComponent ( Component * component)
inline

Sets the component to be drawn into the OpenGL image. If not set, uses this component.

Parameters
componentThe component to draw.

◆ setScissor()

void OpenGlImageComponent::setScissor ( bool scissor)
inline

Enables or disables scissor testing when drawing the image.

Parameters
scissorTrue to enable scissor testing, false otherwise.

◆ setStatic()

void OpenGlImageComponent::setStatic ( bool static_image)
inline

Sets whether the image should be treated as static (not redrawn unless forced).

Parameters
static_imageTrue if static, false for dynamic re-rendering.

◆ setUseAlpha()

void OpenGlImageComponent::setUseAlpha ( bool use_alpha)
inline

Enables or disables alpha blending for the image.

Parameters
use_alphaTrue to respect alpha, false to ignore.

Member Data Documentation

◆ active_

bool OpenGlImageComponent::active_
protected

Whether this component is active and should render.

◆ component_

Component* OpenGlImageComponent::component_
protected

The component being drawn into the image (if any).

◆ draw_image_

std::unique_ptr<Image> OpenGlImageComponent::draw_image_
protected

The cached image that stores the drawn component.

◆ image_

OpenGlImage OpenGlImageComponent::image_
protected

The OpenGlImage used to upload and draw the cached image.

◆ paint_entire_component_

bool OpenGlImageComponent::paint_entire_component_
protected

If true, paint entire component hierarchy to image.

◆ static_image_

bool OpenGlImageComponent::static_image_
protected

Whether the image is static or updated on events.


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