1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00

Switched to suffix underscores.

This commit is contained in:
Thomas Harte 2016-11-21 11:57:45 +08:00
parent 340607e13e
commit bc03e12dc5
2 changed files with 25 additions and 25 deletions

View File

@ -46,34 +46,34 @@ GLuint Shader::compile_shader(const char *source, GLenum type)
Shader::Shader(const char *vertex_shader, const char *fragment_shader, const AttributeBinding *attribute_bindings) Shader::Shader(const char *vertex_shader, const char *fragment_shader, const AttributeBinding *attribute_bindings)
{ {
_shader_program = glCreateProgram(); shader_program_ = glCreateProgram();
GLuint vertex = compile_shader(vertex_shader, GL_VERTEX_SHADER); GLuint vertex = compile_shader(vertex_shader, GL_VERTEX_SHADER);
GLuint fragment = compile_shader(fragment_shader, GL_FRAGMENT_SHADER); GLuint fragment = compile_shader(fragment_shader, GL_FRAGMENT_SHADER);
glAttachShader(_shader_program, vertex); glAttachShader(shader_program_, vertex);
glAttachShader(_shader_program, fragment); glAttachShader(shader_program_, fragment);
if(attribute_bindings) if(attribute_bindings)
{ {
while(attribute_bindings->name) while(attribute_bindings->name)
{ {
glBindAttribLocation(_shader_program, attribute_bindings->index, attribute_bindings->name); glBindAttribLocation(shader_program_, attribute_bindings->index, attribute_bindings->name);
attribute_bindings++; attribute_bindings++;
} }
} }
glLinkProgram(_shader_program); glLinkProgram(shader_program_);
#if defined(DEBUG) #if defined(DEBUG)
GLint didLink = 0; GLint didLink = 0;
glGetProgramiv(_shader_program, GL_LINK_STATUS, &didLink); glGetProgramiv(shader_program_, GL_LINK_STATUS, &didLink);
if(didLink == GL_FALSE) if(didLink == GL_FALSE)
{ {
GLint logLength; GLint logLength;
glGetProgramiv(_shader_program, GL_INFO_LOG_LENGTH, &logLength); glGetProgramiv(shader_program_, GL_INFO_LOG_LENGTH, &logLength);
if(logLength > 0) { if(logLength > 0) {
GLchar *log = (GLchar *)malloc((size_t)logLength); GLchar *log = (GLchar *)malloc((size_t)logLength);
glGetProgramInfoLog(_shader_program, logLength, &logLength, log); glGetProgramInfoLog(shader_program_, logLength, &logLength, log);
printf("Link log:\n%s\n", log); printf("Link log:\n%s\n", log);
free(log); free(log);
} }
@ -85,14 +85,14 @@ Shader::Shader(const char *vertex_shader, const char *fragment_shader, const Att
Shader::~Shader() Shader::~Shader()
{ {
if(bound_shader == this) Shader::unbind(); if(bound_shader == this) Shader::unbind();
glDeleteProgram(_shader_program); glDeleteProgram(shader_program_);
} }
void Shader::bind() void Shader::bind()
{ {
if(bound_shader != this) if(bound_shader != this)
{ {
glUseProgram(_shader_program); glUseProgram(shader_program_);
bound_shader = this; bound_shader = this;
} }
flush_functions(); flush_functions();
@ -106,12 +106,12 @@ void Shader::unbind()
GLint Shader::get_attrib_location(const GLchar *name) GLint Shader::get_attrib_location(const GLchar *name)
{ {
return glGetAttribLocation(_shader_program, name); return glGetAttribLocation(shader_program_, name);
} }
GLint Shader::get_uniform_location(const GLchar *name) GLint Shader::get_uniform_location(const GLchar *name)
{ {
return glGetUniformLocation(_shader_program, name); return glGetUniformLocation(shader_program_, name);
} }
void Shader::enable_vertex_attribute_with_pointer(const char *name, GLint size, GLenum type, GLboolean normalised, GLsizei stride, const GLvoid *pointer, GLuint divisor) void Shader::enable_vertex_attribute_with_pointer(const char *name, GLint size, GLenum type, GLboolean normalised, GLsizei stride, const GLvoid *pointer, GLuint divisor)
@ -123,7 +123,7 @@ void Shader::enable_vertex_attribute_with_pointer(const char *name, GLint size,
} }
// The various set_uniforms... // The various set_uniforms...
#define location() glGetUniformLocation(_shader_program, name.c_str()) #define location() glGetUniformLocation(shader_program_, name.c_str())
void Shader::set_uniform(const std::string &name, GLint value) void Shader::set_uniform(const std::string &name, GLint value)
{ {
enqueue_function([name, value, this] { enqueue_function([name, value, this] {
@ -291,18 +291,18 @@ void Shader::set_uniform_matrix(const std::string &name, GLint size, GLsizei cou
void Shader::enqueue_function(std::function<void(void)> function) void Shader::enqueue_function(std::function<void(void)> function)
{ {
_function_mutex.lock(); function_mutex_.lock();
_enqueued_functions.push_back(function); enqueued_functions_.push_back(function);
_function_mutex.unlock(); function_mutex_.unlock();
} }
void Shader::flush_functions() void Shader::flush_functions()
{ {
_function_mutex.lock(); function_mutex_.lock();
for(std::function<void(void)> function : _enqueued_functions) for(std::function<void(void)> function : enqueued_functions_)
{ {
function(); function();
} }
_enqueued_functions.clear(); enqueued_functions_.clear();
_function_mutex.unlock(); function_mutex_.unlock();
} }

View File

@ -31,8 +31,8 @@ public:
}; };
struct AttributeBinding { struct AttributeBinding {
const GLchar *name; const GLchar *const name;
GLuint index; const GLuint index;
}; };
/*! /*!
@ -107,11 +107,11 @@ public:
private: private:
GLuint compile_shader(const char *source, GLenum type); GLuint compile_shader(const char *source, GLenum type);
GLuint _shader_program; GLuint shader_program_;
void flush_functions(); void flush_functions();
std::vector<std::function<void(void)>> _enqueued_functions; std::vector<std::function<void(void)>> enqueued_functions_;
std::mutex _function_mutex; std::mutex function_mutex_;
protected: protected:
void enqueue_function(std::function<void(void)> function); void enqueue_function(std::function<void(void)> function);