From a5a3769a0fbaf8114052cc914a6410b5a94b3722 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 23 Nov 2018 22:33:28 -0500 Subject: [PATCH] Reaches for conceptual const correctness. --- Outputs/OpenGL/Primitives/Shader.cpp | 8 ++++---- Outputs/OpenGL/Primitives/Shader.hpp | 12 ++++++------ Outputs/OpenGL/Primitives/TextureTarget.cpp | 10 +++++----- Outputs/OpenGL/Primitives/TextureTarget.hpp | 16 ++++++++-------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Outputs/OpenGL/Primitives/Shader.cpp b/Outputs/OpenGL/Primitives/Shader.cpp index 23a10351d..6b08fcc11 100644 --- a/Outputs/OpenGL/Primitives/Shader.cpp +++ b/Outputs/OpenGL/Primitives/Shader.cpp @@ -81,7 +81,7 @@ Shader::~Shader() { glDeleteProgram(shader_program_); } -void Shader::bind() { +void Shader::bind() const { // if(bound_shader != this) { glUseProgram(shader_program_); // bound_shader = this; @@ -94,11 +94,11 @@ void Shader::unbind() { glUseProgram(0); } -GLint Shader::get_attrib_location(const std::string &name) { +GLint Shader::get_attrib_location(const std::string &name) const { return glGetAttribLocation(shader_program_, name.c_str()); } -GLint Shader::get_uniform_location(const std::string &name) { +GLint Shader::get_uniform_location(const std::string &name) const { return glGetUniformLocation(shader_program_, name.c_str()); } @@ -259,7 +259,7 @@ void Shader::enqueue_function(std::function function) { enqueued_functions_.push_back(function); } -void Shader::flush_functions() { +void Shader::flush_functions() const { std::lock_guard function_guard(function_mutex_); for(std::function function : enqueued_functions_) { function(); diff --git a/Outputs/OpenGL/Primitives/Shader.hpp b/Outputs/OpenGL/Primitives/Shader.hpp index ca1cc17cf..8610a2c7e 100644 --- a/Outputs/OpenGL/Primitives/Shader.hpp +++ b/Outputs/OpenGL/Primitives/Shader.hpp @@ -54,7 +54,7 @@ public: Subsequently performs all work queued up for the next bind irrespective of whether a @c glUseProgram call occurred. */ - void bind(); + void bind() const; /*! Unbinds the current instance of Shader, if one is bound. @@ -66,14 +66,14 @@ public: @param name The name of the attribute to locate. @returns The location of the requested attribute. */ - GLint get_attrib_location(const std::string &name); + GLint get_attrib_location(const std::string &name) const; /*! Performs a @c glGetUniformLocation call. @param name The name of the uniform to locate. @returns The location of the requested uniform. */ - GLint get_uniform_location(const std::string &name); + GLint get_uniform_location(const std::string &name) const; /*! Shorthand for an appropriate sequence of: @@ -112,9 +112,9 @@ private: GLuint compile_shader(const std::string &source, GLenum type); GLuint shader_program_; - void flush_functions(); - std::vector> enqueued_functions_; - std::mutex function_mutex_; + void flush_functions() const; + mutable std::vector> enqueued_functions_; + mutable std::mutex function_mutex_; protected: void enqueue_function(std::function function); diff --git a/Outputs/OpenGL/Primitives/TextureTarget.cpp b/Outputs/OpenGL/Primitives/TextureTarget.cpp index 5a252e898..93a344ae1 100644 --- a/Outputs/OpenGL/Primitives/TextureTarget.cpp +++ b/Outputs/OpenGL/Primitives/TextureTarget.cpp @@ -65,12 +65,12 @@ void TextureTarget::bind_framebuffer() { glViewport(0, 0, width_, height_); } -void TextureTarget::bind_texture() { +void TextureTarget::bind_texture() const { glActiveTexture(texture_unit_); glBindTexture(GL_TEXTURE_2D, texture_); } -void TextureTarget::draw(float aspect_ratio, float colour_threshold) { +void TextureTarget::draw(float aspect_ratio, float colour_threshold) const { if(!pixel_shader_) { const char *vertex_shader = "#version 150\n" @@ -108,8 +108,8 @@ void TextureTarget::draw(float aspect_ratio, float colour_threshold) { glBindVertexArray(drawing_vertex_array_); glBindBuffer(GL_ARRAY_BUFFER, drawing_array_buffer_); - GLint position_attribute = pixel_shader_->get_attrib_location("position"); - GLint tex_coord_attribute = pixel_shader_->get_attrib_location("texCoord"); + const GLint position_attribute = pixel_shader_->get_attrib_location("position"); + const GLint tex_coord_attribute = pixel_shader_->get_attrib_location("texCoord"); glEnableVertexAttribArray(static_cast(position_attribute)); glEnableVertexAttribArray(static_cast(tex_coord_attribute)); @@ -118,7 +118,7 @@ void TextureTarget::draw(float aspect_ratio, float colour_threshold) { glVertexAttribPointer((GLuint)position_attribute, 2, GL_FLOAT, GL_FALSE, vertex_stride, (void *)0); glVertexAttribPointer((GLuint)tex_coord_attribute, 2, GL_FLOAT, GL_FALSE, vertex_stride, (void *)(2 * sizeof(GLfloat))); - GLint texIDUniform = pixel_shader_->get_uniform_location("texID"); + const GLint texIDUniform = pixel_shader_->get_uniform_location("texID"); glUniform1i(texIDUniform, static_cast(texture_unit_ - GL_TEXTURE0)); threshold_uniform_ = pixel_shader_->get_uniform_location("threshold"); diff --git a/Outputs/OpenGL/Primitives/TextureTarget.hpp b/Outputs/OpenGL/Primitives/TextureTarget.hpp index 647275f23..0c30acdfa 100644 --- a/Outputs/OpenGL/Primitives/TextureTarget.hpp +++ b/Outputs/OpenGL/Primitives/TextureTarget.hpp @@ -44,19 +44,19 @@ class TextureTarget { /*! Binds this target as a texture. */ - void bind_texture(); + void bind_texture() const; /*! @returns the width of the texture target. */ - GLsizei get_width() { + GLsizei get_width() const { return width_; } /*! @returns the height of the texture target. */ - GLsizei get_height() { + GLsizei get_height() const { return height_; } @@ -71,7 +71,7 @@ class TextureTarget { 0.5f being substituted elsewhere. This provides a way to ensure that the sort of persistent low-value errors that can result from an IIR are hidden. */ - void draw(float aspect_ratio, float colour_threshold = 0.0f); + void draw(float aspect_ratio, float colour_threshold = 0.0f) const; enum { ErrorFramebufferIncomplete @@ -83,11 +83,11 @@ class TextureTarget { GLsizei expanded_width_ = 0, expanded_height_ = 0; GLenum texture_unit_ = 0; - std::unique_ptr pixel_shader_; - GLuint drawing_vertex_array_ = 0, drawing_array_buffer_ = 0; - float set_aspect_ratio_ = 0.0f; + mutable std::unique_ptr pixel_shader_; + mutable GLuint drawing_vertex_array_ = 0, drawing_array_buffer_ = 0; + mutable float set_aspect_ratio_ = 0.0f; - GLint threshold_uniform_; + mutable GLint threshold_uniform_; }; }