mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-26 09:29:45 +00:00
Reaches for conceptual const correctness.
This commit is contained in:
parent
dc4b5cc37d
commit
a5a3769a0f
@ -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<void(void)> function) {
|
||||
enqueued_functions_.push_back(function);
|
||||
}
|
||||
|
||||
void Shader::flush_functions() {
|
||||
void Shader::flush_functions() const {
|
||||
std::lock_guard<std::mutex> function_guard(function_mutex_);
|
||||
for(std::function<void(void)> function : enqueued_functions_) {
|
||||
function();
|
||||
|
@ -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<std::function<void(void)>> enqueued_functions_;
|
||||
std::mutex function_mutex_;
|
||||
void flush_functions() const;
|
||||
mutable std::vector<std::function<void(void)>> enqueued_functions_;
|
||||
mutable std::mutex function_mutex_;
|
||||
|
||||
protected:
|
||||
void enqueue_function(std::function<void(void)> function);
|
||||
|
@ -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<GLuint>(position_attribute));
|
||||
glEnableVertexAttribArray(static_cast<GLuint>(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<GLint>(texture_unit_ - GL_TEXTURE0));
|
||||
|
||||
threshold_uniform_ = pixel_shader_->get_uniform_location("threshold");
|
||||
|
@ -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<Shader> pixel_shader_;
|
||||
GLuint drawing_vertex_array_ = 0, drawing_array_buffer_ = 0;
|
||||
float set_aspect_ratio_ = 0.0f;
|
||||
mutable std::unique_ptr<Shader> 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_;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user