Vital
Loading...
Searching...
No Matches
open_gl_background.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "open_gl_component.h"
5
6#include <mutex>
7
17public:
22
26 virtual ~OpenGlBackground();
27
35 void updateBackgroundImage(Image background);
36
41 virtual void init(OpenGlWrapper& open_gl);
42
49 virtual void render(OpenGlWrapper& open_gl);
50
55 virtual void destroy(OpenGlWrapper& open_gl);
56
62 void lock() { mutex_.lock(); }
63
67 void unlock() { mutex_.unlock(); }
68
73 OpenGLShaderProgram* shader() { return image_shader_; }
74
79 OpenGLShaderProgram::Uniform* texture_uniform() { return texture_uniform_.get(); }
80
85 void bind(OpenGLContext& open_gl_context);
86
91 void enableAttributes(OpenGLContext& open_gl_context);
92
97 void disableAttributes(OpenGLContext& open_gl_context);
98
99private:
100 OpenGLShaderProgram* image_shader_;
101 std::unique_ptr<OpenGLShaderProgram::Uniform> texture_uniform_;
102 std::unique_ptr<OpenGLShaderProgram::Attribute> position_;
103 std::unique_ptr<OpenGLShaderProgram::Attribute> texture_coordinates_;
104
105 float vertices_[16];
106
107 std::mutex mutex_;
108 OpenGLTexture background_;
109 bool new_background_;
110 Image background_image_;
111
112 GLuint vertex_buffer_;
113 GLuint triangle_buffer_;
114
115 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OpenGlBackground)
116};
A class that manages and renders a background image using OpenGL.
Definition open_gl_background.h:16
void unlock()
Unlocks the mutex previously locked by lock().
Definition open_gl_background.h:67
void updateBackgroundImage(Image background)
Updates the background image to a new one.
Definition open_gl_background.cpp:135
virtual void destroy(OpenGlWrapper &open_gl)
Cleans up OpenGL resources when the background is no longer needed.
Definition open_gl_background.cpp:52
OpenGlBackground()
Constructs an OpenGlBackground with no initial image.
Definition open_gl_background.cpp:7
OpenGLShaderProgram::Uniform * texture_uniform()
Gets the shader uniform for the texture.
Definition open_gl_background.h:79
void disableAttributes(OpenGLContext &open_gl_context)
Disables vertex attribute arrays for position and texture coordinates.
Definition open_gl_background.cpp:85
virtual ~OpenGlBackground()
Destructor. Frees OpenGL resources if allocated.
Definition open_gl_background.cpp:13
void enableAttributes(OpenGLContext &open_gl_context)
Enables vertex attribute arrays for position and texture coordinates.
Definition open_gl_background.cpp:71
virtual void init(OpenGlWrapper &open_gl)
Initializes OpenGL buffers and shader resources.
Definition open_gl_background.cpp:15
void bind(OpenGLContext &open_gl_context)
Binds the vertex and element arrays, and the background texture.
Definition open_gl_background.cpp:65
OpenGLShaderProgram * shader()
Gets the shader used to render the image.
Definition open_gl_background.h:73
void lock()
Locks the mutex for thread-safe operations.
Definition open_gl_background.h:62
virtual void render(OpenGlWrapper &open_gl)
Renders the background image.
Definition open_gl_background.cpp:93
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174