Vital
Loading...
Searching...
No Matches
open_gl_component.h
Go to the documentation of this file.
1#pragma once
2
3#include "common.h"
4#include "shaders.h"
5#include "skin.h"
6#include "synth_module.h"
7
8class SynthSection;
9class OpenGlCorners;
10
20class OpenGlComponent : public Component {
21public:
32 static bool setViewPort(Component* component, Rectangle<int> bounds, OpenGlWrapper& open_gl);
33
40 static bool setViewPort(Component* component, OpenGlWrapper& open_gl);
41
47 static void setScissor(Component* component, OpenGlWrapper& open_gl);
48
55 static void setScissorBounds(Component* component, Rectangle<int> bounds, OpenGlWrapper& open_gl);
56
64 static std::unique_ptr<OpenGLShaderProgram::Uniform> getUniform(const OpenGlWrapper& open_gl,
65 const OpenGLShaderProgram& program,
66 const char* name) {
67 if (open_gl.context.extensions.glGetUniformLocation(program.getProgramID(), name) >= 0)
68 return std::make_unique<OpenGLShaderProgram::Uniform>(program, name);
69 return nullptr;
70 }
71
79 static std::unique_ptr<OpenGLShaderProgram::Attribute> getAttribute(const OpenGlWrapper& open_gl,
80 const OpenGLShaderProgram& program,
81 const char* name) {
82 if (open_gl.context.extensions.glGetAttribLocation(program.getProgramID(), name) >= 0)
83 return std::make_unique<OpenGLShaderProgram::Attribute>(program, name);
84 return nullptr;
85 }
86
91 OpenGlComponent(String name = "");
92
96 virtual ~OpenGlComponent();
97
103 virtual void resized() override;
104
110 virtual void parentHierarchyChanged() override;
111
115 void addRoundedCorners();
116
121
126 virtual void init(OpenGlWrapper& open_gl);
127
133 virtual void render(OpenGlWrapper& open_gl, bool animate) = 0;
134
142 void renderCorners(OpenGlWrapper& open_gl, bool animate, Colour color, float rounding);
143
149 void renderCorners(OpenGlWrapper& open_gl, bool animate);
150
155 virtual void destroy(OpenGlWrapper& open_gl);
156
161 virtual void paintBackground(Graphics& g);
162
166 void repaintBackground();
167
172 Colour getBodyColor() const { return body_color_; }
173
178 void setParent(const SynthSection* parent) { parent_ = parent; }
179
185 float findValue(Skin::ValueId value_id);
186
191 void setSkinValues(const Skin& skin) {
192 skin.setComponentColors(this, skin_override_, false);
193 }
194
199 void setSkinOverride(Skin::SectionOverride skin_override) { skin_override_ = skin_override; }
200
206 static inline String translateFragmentShader(const String& code) {
207#if OPENGL_ES
208 return String("#version 300 es\n") + "out mediump vec4 fragColor;\n" +
209 code.replace("varying", "in").replace("texture2D", "texture").replace("gl_FragColor", "fragColor");
210#else
211 return OpenGLHelpers::translateFragmentShaderToV3(code);
212#endif
213 }
214
220 static inline String translateVertexShader(const String& code) {
221#if OPENGL_ES
222 return String("#version 300 es\n") + code.replace("attribute", "in").replace("varying", "out");
223#else
224 return OpenGLHelpers::translateVertexShaderToV3(code);
225#endif
226 }
227
232#if DEBUG
233 int error = glGetError();
234 assert(error == GL_NO_ERROR);
235#endif
236 }
237
242 void setBackgroundColor(const Colour& color) { background_color_ = color; }
243
244protected:
250 bool setViewPort(OpenGlWrapper& open_gl);
251
252 std::unique_ptr<OpenGlCorners> corners_;
255 Colour body_color_;
259
260 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OpenGlComponent)
261};
A base component class that integrates JUCE's Component with OpenGL rendering.
Definition open_gl_component.h:20
bool only_bottom_corners_
Flag to round only the bottom corners.
Definition open_gl_component.h:253
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
virtual void render(OpenGlWrapper &open_gl, bool animate)=0
Pure virtual function to render the component using OpenGL.
void addRoundedCorners()
Adds rounded corners to the component's edges.
Definition open_gl_component.cpp:138
virtual void resized() override
Called when the component is resized.
Definition open_gl_component.cpp:121
void setSkinOverride(Skin::SectionOverride skin_override)
Sets a skin override to control the component's color scheme.
Definition open_gl_component.h:199
void addBottomRoundedCorners()
Adds rounded corners only at the bottom of the component.
Definition open_gl_component.cpp:143
const vital::StatusOutput * num_voices_readout_
StatusOutput for voice count lookups.
Definition open_gl_component.h:258
void setParent(const SynthSection *parent)
Sets a pointer to the parent SynthSection for skin value lookups.
Definition open_gl_component.h:178
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
void renderCorners(OpenGlWrapper &open_gl, bool animate, Colour color, float rounding)
Renders the corner shapes using the given color and rounding amount.
Definition open_gl_component.cpp:153
static void setScissorBounds(Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl)
Sets the OpenGL scissor region to a specified rectangle within a component.
Definition open_gl_component.cpp:82
Colour getBodyColor() const
Retrieves the component's body color.
Definition open_gl_component.h:172
force_inline void checkGlError()
Checks for and asserts that there are no OpenGL errors.
Definition open_gl_component.h:231
static void setScissor(Component *component, OpenGlWrapper &open_gl)
Sets the OpenGL scissor region to the entire component's local bounds.
Definition open_gl_component.cpp:78
float findValue(Skin::ValueId value_id)
Finds a float value from the skin associated with this component's parent.
Definition open_gl_component.cpp:173
virtual void destroy(OpenGlWrapper &open_gl)
Destroys any OpenGL-specific resources allocated by this component.
Definition open_gl_component.cpp:168
static String translateFragmentShader(const String &code)
Translates a fragment shader code snippet to be compatible with the current GL version.
Definition open_gl_component.h:206
OpenGlComponent(String name="")
Constructs an OpenGlComponent.
Definition open_gl_component.cpp:34
virtual ~OpenGlComponent()
Destructor.
Definition open_gl_component.cpp:40
void setBackgroundColor(const Colour &color)
Sets the background color of the component for painting operations.
Definition open_gl_component.h:242
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 paintBackground(Graphics &g)
Paints a standard background for the component.
Definition open_gl_component.cpp:105
Colour body_color_
The body color of the component.
Definition open_gl_component.h:255
virtual void init(OpenGlWrapper &open_gl)
Initializes any OpenGL-specific resources needed by the component.
Definition open_gl_component.cpp:148
Colour background_color_
The background color of the component.
Definition open_gl_component.h:254
void repaintBackground()
Requests a repaint of the component's background on the OpenGL layer.
Definition open_gl_component.cpp:112
static String translateVertexShader(const String &code)
Translates a vertex shader code snippet to be compatible with the current GL version.
Definition open_gl_component.h:220
std::unique_ptr< OpenGlCorners > corners_
Optional corners for rounded edges.
Definition open_gl_component.h:252
virtual void parentHierarchyChanged() override
Called when the component's parent hierarchy changes.
Definition open_gl_component.cpp:128
void setSkinValues(const Skin &skin)
Applies the skin overrides to this component's colors.
Definition open_gl_component.h:191
const SynthSection * parent_
Pointer to parent SynthSection for skin lookups.
Definition open_gl_component.h:256
Skin::SectionOverride skin_override_
Skin override for custom appearance.
Definition open_gl_component.h:257
A set of quads forming rounded corners, used to render corner shapes via OpenGL.
Definition open_gl_multi_quad.h:554
Manages the overall color and value theme (or "skin") of the user interface.
Definition skin.h:24
ValueId
Identifiers for various UI scaling/spacing values and configuration constants.
Definition skin.h:70
SectionOverride
Identifiers for different UI sections that can have color or value overrides.
Definition skin.h:30
void setComponentColors(Component *component) const
Applies all component colors to a given component.
Definition skin.cpp:207
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
A helper class to track the "status" of a particular Output as a poly_float value.
Definition synth_module.h:35
#define force_inline
Definition common.h:23
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
Defines the SynthModule class which extends ProcessorRouter to form a building block of the Vital syn...