13 additive_(false), use_alpha_(false), scissor_(false) {
14 position_vertices_ = std::make_unique<float[]>(kNumPositions);
15 float position_vertices[kNumPositions] = {
16 0.0f, 1.0f, 0.0f, 1.0f,
17 0.0f, -1.0f, 0.0f, 0.0f,
18 0.1f, -1.0f, 1.0f, 0.0f,
19 0.1f, 1.0f, 1.0f, 1.0f
21 memcpy(position_vertices_.get(), position_vertices, kNumPositions *
sizeof(
float));
23 position_triangles_ = std::make_unique<int[]>(kNumTriangleIndices);
24 int position_triangles[kNumTriangleIndices] = {
28 memcpy(position_triangles_.get(), position_triangles, kNumTriangleIndices *
sizeof(
int));
35 open_gl.
context.extensions.glGenBuffers(1, &vertex_buffer_);
36 open_gl.
context.extensions.glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
38 GLsizeiptr vert_size =
static_cast<GLsizeiptr
>(
static_cast<size_t>(kNumPositions *
sizeof(float)));
39 open_gl.
context.extensions.glBufferData(GL_ARRAY_BUFFER, vert_size,
40 position_vertices_.get(), GL_STATIC_DRAW);
43 open_gl.
context.extensions.glGenBuffers(1, &triangle_buffer_);
44 open_gl.
context.extensions.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangle_buffer_);
46 GLsizeiptr tri_size =
static_cast<GLsizeiptr
>(
static_cast<size_t>(kNumTriangleIndices *
sizeof(float)));
47 open_gl.
context.extensions.glBufferData(GL_ELEMENT_ARRAY_BUFFER, tri_size,
48 position_triangles_.get(), GL_STATIC_DRAW);
63 texture_.loadImage(*image_);
70 glEnable(GL_SCISSOR_TEST);
72 glDisable(GL_SCISSOR_TEST);
76 glBlendFunc(GL_ONE, GL_ONE);
78 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
80 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
82 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
83 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
86 open_gl.
context.extensions.glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
87 GLsizeiptr vert_size =
static_cast<GLsizeiptr
>(
static_cast<size_t>(kNumPositions *
sizeof(float)));
91 open_gl.
context.extensions.glBufferData(GL_ARRAY_BUFFER, vert_size, position_vertices_.get(), GL_STATIC_DRAW);
94 open_gl.
context.extensions.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangle_buffer_);
96 open_gl.
context.extensions.glActiveTexture(GL_TEXTURE0);
102 image_color_->set(color_.getFloatRed(), color_.getFloatGreen(), color_.getFloatBlue(), color_.getFloatAlpha());
105 open_gl.
context.extensions.glVertexAttribPointer(image_position_->attributeID, 2, GL_FLOAT,
106 GL_FALSE, 4 *
sizeof(
float),
nullptr);
107 open_gl.
context.extensions.glEnableVertexAttribArray(image_position_->attributeID);
108 open_gl.
context.extensions.glVertexAttribPointer(texture_coordinates_->attributeID, 2, GL_FLOAT,
109 GL_FALSE, 4 *
sizeof(
float),
110 (GLvoid*)(2 *
sizeof(
float)));
111 open_gl.
context.extensions.glEnableVertexAttribArray(texture_coordinates_->attributeID);
114 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT,
nullptr);
117 open_gl.
context.extensions.glDisableVertexAttribArray(image_position_->attributeID);
118 open_gl.
context.extensions.glDisableVertexAttribArray(texture_coordinates_->attributeID);
121 open_gl.
context.extensions.glBindBuffer(GL_ARRAY_BUFFER, 0);
122 open_gl.
context.extensions.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
125 glDisable(GL_SCISSOR_TEST);
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
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
void init(OpenGlWrapper &open_gl)
Initializes the OpenGL buffers and shader attributes needed for rendering the image.
Definition open_gl_image.cpp:33
void drawImage(OpenGlWrapper &open_gl)
Draws the image to the current OpenGL context.
Definition open_gl_image.cpp:59
void destroy(OpenGlWrapper &open_gl)
Releases any OpenGL resources allocated by this object.
Definition open_gl_image.cpp:128
OpenGLShaderProgram * getShaderProgram(VertexShader vertex_shader, FragmentShader fragment_shader, const GLchar **varyings=nullptr)
Retrieves or creates an OpenGLShaderProgram from a given vertex and fragment shader pair.
Definition shaders.cpp:953
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...