+ 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;
+}
+
+void ShaderProgramGL::set_uniformi(int location, int value)
+{
+ if(!use() || location == -1) {
+ return;
+ }
+
+ glUniform1i(location, value);
+}
+
+void ShaderProgramGL::set_uniformi(int location, int x, int y)
+{
+ if(!use() || location == -1) {
+ return;
+ }
+
+ glUniform2i(location, x, y);
+}
+
+void ShaderProgramGL::set_uniformi(int location, int x, int y, int z)
+{
+ if(!use() || location == -1) {
+ return;
+ }
+
+ glUniform3i(location, x, y, z);
+}
+
+void ShaderProgramGL::set_uniformi(int location, int x, int y, int z, int w)
+{
+ if(!use() || location == -1) {
+ return;
+ }
+
+ glUniform4i(location, x, y, z, w);
+}
+
+void ShaderProgramGL::set_uniformf(int location, float value)
+{
+ if(!use() || location == -1) {
+ return;
+ }
+
+ glUniform1f(location, value);
+}
+
+void ShaderProgramGL::set_uniformf(int location, float x, float y)
+{
+ if(!use() || location == -1) {
+ return;
+ }
+
+ glUniform2f(location, x, y);
+}
+
+void ShaderProgramGL::set_uniformf(int location, float x, float y, float z)
+{
+ if(!use() || location == -1) {
+ return;
+ }
+
+ glUniform3f(location, x, y, z);
+}
+
+void ShaderProgramGL::set_uniformf(int location, float x, float y, float z, float w)
+{
+ if(!use() || location == -1) {
+ return;
+ }
+
+ glUniform4f(location, x, y, z, w);
+}
+
+void ShaderProgramGL::set_uniform_matrix(int location, const Mat4 &mat)
+{
+ if(!use() || location == -1) {
+ fprintf(stderr, "FOO\n");
+ return;
+ }
+
+ glUniformMatrix4fv(location, 1, GL_TRUE, (float *)&mat.m[0][0]);