X-Git-Url: https://eleni.mutantstargoat.com/git/?p=demo;a=blobdiff_plain;f=src%2Fopengl%2Fshader-gl.cc;h=2b917543816cbbf32c5f07be1625f250d9249239;hp=67aa0968cc2986b18185740feaec9f4fe07f1c1b;hb=fcd6773bc770425ede4b47a84eef7cc78342542c;hpb=4bc86b416f29b4889075ad5c8dfdb1e11454a6c3 diff --git a/src/opengl/shader-gl.cc b/src/opengl/shader-gl.cc index 67aa096..2b91754 100644 --- a/src/opengl/shader-gl.cc +++ b/src/opengl/shader-gl.cc @@ -5,8 +5,6 @@ #include "state_manager.h" #include "opengl/shader-gl.h" -extern ShaderProgram *current_program; - ShaderGL::ShaderGL() { sdr = 0; @@ -84,7 +82,6 @@ ShaderProgramGL::ShaderProgramGL() prog = 0; memset(shaders, 0, sizeof shaders / sizeof *shaders); - current_program = 0; is_linked = false; } @@ -133,37 +130,17 @@ bool ShaderProgramGL::link() return status ? true : false; } -bool ShaderProgramGL::use() +bool ShaderProgramGL::use() const { - if(!is_linked && !link()) { + if(!is_linked) { //&& !link()) { return false; } if(!prog) { - glUseProgram(0); - current_program = 0; + return false; } glUseProgram(prog); - current_program = this; - - static void (*const set_uniform[16])(GLint, GLsizei, const GLfloat *) = { - 0, glUniform1fv, glUniform2fv, glUniform3fv, glUniform4fv - }; - - for(size_t i=0; inum < 5) { - set_uniform[st->num](uniforms[i].location, 1, st->data); - } - else if(st->num == 16) { - glUniformMatrix4fv(uniforms[i].location, 1, GL_TRUE, st->data); - } - else { - fprintf(stderr, "Invalid number of floats in state %s: %d\n", st->name, st->num); - continue; - } - } return true; } @@ -182,87 +159,12 @@ void ShaderProgramGL::attach_shader(Shader *shader) int ShaderProgramGL::get_uniform_location(const char *name) const { - if(!((ShaderProgramGL *)this)->use()) + if(!use()) return -1; return glGetUniformLocation(prog, name); } -int ShaderProgramGL::get_attribute_location(const char *name) const -{ - if(!((ShaderProgramGL *)this)->use()) - return -1; - - return glGetAttribLocation(prog, name); -} - -static int get_floats_num(unsigned int utype) -{ - switch(utype) { - case GL_FLOAT: - return 1; - case GL_FLOAT_VEC2: - return 2; - case GL_FLOAT_VEC3: - return 3; - case GL_FLOAT_VEC4: - return 4; - case GL_FLOAT_MAT2: - return 4; - case GL_FLOAT_MAT3: - return 9; - case GL_FLOAT_MAT4: - return 16; - default: - break; - } - - return -1; -} - -void ShaderProgramGL::cache_uniforms() -{ - uniforms.clear(); - - int num_uniforms; - glGetProgramiv(prog, GL_ACTIVE_UNIFORMS, &num_uniforms); - - int max_ulength; - glGetProgramiv(prog, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_ulength); - - char *name = new char[max_ulength + 1]; - name[max_ulength] = 0; - - for(int i=0; i