-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<num_uniforms; i++) {
- int usize;
- unsigned int utype;
- glGetActiveUniform(prog, i, max_ulength, 0, &usize, &utype, name);
-
- if(strstr(name, "gl_") == name)
- continue;
-
- if(strstr(name, "st_") != name)
- continue;
-
- int num_floats = get_floats_num(utype);
- if(num_floats == -1)
- continue;
-
- int idx = state_manager.add_state_element(name, num_floats);
- if(idx == -1)
- continue;
-
- Uniform uniform;
- uniform.name = name;
- uniform.location = glGetUniformLocation(prog, name);
- uniform.state_idx = idx;
-
- uniforms.push_back(uniform);
- }
-
- delete [] name;
-}
-