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

A component for rendering multiple image quads using OpenGL. More...

#include <open_gl_multi_image.h>

Inheritance diagram for OpenGlMultiImage:
OpenGlComponent

Public Member Functions

 OpenGlMultiImage (int max_images)
 Constructs an OpenGlMultiImage with a given maximum number of quads.
 
virtual ~OpenGlMultiImage ()
 Destructor. Frees any allocated OpenGL resources.
 
virtual void init (OpenGlWrapper &open_gl) override
 Initializes OpenGL buffers and shader attributes for rendering.
 
virtual void render (OpenGlWrapper &open_gl, bool animate) override
 Renders the set of image quads using OpenGL.
 
virtual void destroy (OpenGlWrapper &open_gl) override
 Destroys the OpenGL resources used by this class.
 
void paintBackground (Graphics &g) override
 Override to suppress default background painting.
 
void resized () override
 Called when the component is resized, marks vertex data as dirty to recalculate.
 
void lock ()
 Locks the internal mutex for thread-safe image updates.
 
void unlock ()
 Unlocks the mutex locked by lock().
 
void setOwnImage (Image &image)
 Sets an owned image by making a copy and uses it for rendering.
 
void setImage (Image *image)
 Sets the image to render without ownership.
 
void setNumQuads (int num_quads)
 Sets the number of quads currently drawn.
 
void setColor (Colour color)
 Sets the color tint applied to all image quads.
 
void setQuad (int i, float x, float y, float w, float h)
 Sets the position and size of a quad.
 
int getImageWidth ()
 Gets the width of the current image.
 
int getImageHeight ()
 Gets the height of the current image.
 
void setAdditive (bool additive)
 Enables or disables additive blending for the image quads.
 
- Public Member Functions inherited from OpenGlComponent
 OpenGlComponent (String name="")
 Constructs an OpenGlComponent.
 
virtual ~OpenGlComponent ()
 Destructor.
 
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.
 

Static Public Attributes

static constexpr int kNumVertices = 4
 Number of vertices per quad (2 triangles forming a rectangle).
 
static constexpr int kNumFloatsPerVertex = 4
 Number of floats per vertex (x, y, u, v).
 
static constexpr int kNumFloatsPerQuad = kNumVertices * kNumFloatsPerVertex
 Number of floats per quad (4 vertices * 4 floats each).
 
static constexpr int kNumIndicesPerQuad = 6
 Number of indices per quad (2 triangles * 3 indices each).
 

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.
 
- 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.
 

Detailed Description

A component for rendering multiple image quads using OpenGL.

The OpenGlMultiImage class manages a set of quads, each displaying a portion (or the entirety) of a single image texture. It supports drawing a configurable number of these image quads at once, each positioned and sized independently. This enables rendering multiple image instances efficiently with a single texture.

Constructor & Destructor Documentation

◆ OpenGlMultiImage()

OpenGlMultiImage::OpenGlMultiImage ( int max_images)

Constructs an OpenGlMultiImage with a given maximum number of quads.

Parameters
max_imagesThe maximum number of quads (images) that can be drawn.

◆ ~OpenGlMultiImage()

OpenGlMultiImage::~OpenGlMultiImage ( )
virtual

Destructor. Frees any allocated OpenGL resources.

Member Function Documentation

◆ destroy()

void OpenGlMultiImage::destroy ( OpenGlWrapper & open_gl)
overridevirtual

Destroys the OpenGL resources used by this class.

Parameters
open_glThe OpenGlWrapper providing the current OpenGL context.

Reimplemented from OpenGlComponent.

◆ getImageHeight()

int OpenGlMultiImage::getImageHeight ( )
inline

Gets the height of the current image.

Returns
The image height in pixels.

◆ getImageWidth()

int OpenGlMultiImage::getImageWidth ( )
inline

Gets the width of the current image.

Returns
The image width in pixels.

◆ init()

void OpenGlMultiImage::init ( OpenGlWrapper & open_gl)
overridevirtual

Initializes OpenGL buffers and shader attributes for rendering.

Parameters
open_glThe OpenGlWrapper providing the current OpenGL context.

Reimplemented from OpenGlComponent.

◆ lock()

void OpenGlMultiImage::lock ( )
inline

Locks the internal mutex for thread-safe image updates.

◆ paintBackground()

void OpenGlMultiImage::paintBackground ( Graphics & g)
inlineoverridevirtual

Override to suppress default background painting.

Parameters
gThe graphics context.

Reimplemented from OpenGlComponent.

◆ render()

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

Renders the set of image quads using OpenGL.

Parameters
open_glThe OpenGlWrapper providing the current OpenGL context.
animateIf true, allows animated transitions (not typically needed for images).

Implements OpenGlComponent.

◆ resized()

void OpenGlMultiImage::resized ( )
inlineoverridevirtual

Called when the component is resized, marks vertex data as dirty to recalculate.

Reimplemented from OpenGlComponent.

◆ setAdditive()

void OpenGlMultiImage::setAdditive ( bool additive)
inline

Enables or disables additive blending for the image quads.

Parameters
additiveTrue for additive blending, false for normal blending.

◆ setColor()

void OpenGlMultiImage::setColor ( Colour color)
inline

Sets the color tint applied to all image quads.

Parameters
colorThe tint color.

◆ setImage()

void OpenGlMultiImage::setImage ( Image * image)
inline

Sets the image to render without ownership.

Parameters
imageA pointer to the image (must remain valid while used).

◆ setNumQuads()

void OpenGlMultiImage::setNumQuads ( int num_quads)
inline

Sets the number of quads currently drawn.

Parameters
num_quadsThe number of quads to draw.

◆ setOwnImage()

void OpenGlMultiImage::setOwnImage ( Image & image)
inline

Sets an owned image by making a copy and uses it for rendering.

Parameters
imageThe image to copy and use.

◆ setQuad()

void OpenGlMultiImage::setQuad ( int i,
float x,
float y,
float w,
float h )
inline

Sets the position and size of a quad.

Parameters
iThe quad index.
xThe x-position in normalized device space (-1 to 1).
yThe y-position in normalized device space (-1 to 1).
wThe width of the quad in normalized device units.
hThe height of the quad in normalized device units.

◆ unlock()

void OpenGlMultiImage::unlock ( )
inline

Unlocks the mutex locked by lock().

Member Data Documentation

◆ kNumFloatsPerQuad

int OpenGlMultiImage::kNumFloatsPerQuad = kNumVertices * kNumFloatsPerVertex
staticconstexpr

Number of floats per quad (4 vertices * 4 floats each).

◆ kNumFloatsPerVertex

int OpenGlMultiImage::kNumFloatsPerVertex = 4
staticconstexpr

Number of floats per vertex (x, y, u, v).

◆ kNumIndicesPerQuad

int OpenGlMultiImage::kNumIndicesPerQuad = 6
staticconstexpr

Number of indices per quad (2 triangles * 3 indices each).

◆ kNumVertices

int OpenGlMultiImage::kNumVertices = 4
staticconstexpr

Number of vertices per quad (2 triangles forming a rectangle).


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