mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-11 08:30:55 +00:00
Introduced bind-if-necessary/unbind semantics for shaders.
This commit is contained in:
parent
fe2abbd4ed
commit
2616d748fe
@ -13,6 +13,10 @@
|
||||
|
||||
using namespace OpenGL;
|
||||
|
||||
namespace {
|
||||
Shader *bound_shader = nullptr;
|
||||
}
|
||||
|
||||
GLuint Shader::compile_shader(const char *source, GLenum type)
|
||||
{
|
||||
GLuint shader = glCreateShader(type);
|
||||
@ -80,12 +84,24 @@ Shader::Shader(const char *vertex_shader, const char *fragment_shader, const Att
|
||||
|
||||
Shader::~Shader()
|
||||
{
|
||||
if(bound_shader == this) Shader::unbind();
|
||||
glDeleteProgram(_shader_program);
|
||||
}
|
||||
|
||||
void Shader::bind()
|
||||
{
|
||||
glUseProgram(_shader_program);
|
||||
if(bound_shader != this)
|
||||
{
|
||||
glUseProgram(_shader_program);
|
||||
bound_shader = this;
|
||||
}
|
||||
else printf("-");
|
||||
}
|
||||
|
||||
void Shader::unbind()
|
||||
{
|
||||
bound_shader = nullptr;
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
GLint Shader::get_attrib_location(const GLchar *name)
|
||||
|
@ -41,10 +41,17 @@ public:
|
||||
~Shader();
|
||||
|
||||
/*!
|
||||
Performs an @c glUseProgram to make this the active shader.
|
||||
Performs an @c glUseProgram to make this the active shader unless:
|
||||
(i) it was the previous shader bound; and
|
||||
(ii) no calls have been received to unbind in the interim.
|
||||
*/
|
||||
void bind();
|
||||
|
||||
/*!
|
||||
Unbinds the current instance of Shader, if one is bound.
|
||||
*/
|
||||
static void unbind();
|
||||
|
||||
/*!
|
||||
Performs a @c glGetAttribLocation call.
|
||||
@param name The name of the attribute to locate.
|
||||
|
Loading…
x
Reference in New Issue
Block a user