From 3d531ace234ae7af1275932f2239c2afdfe7d82c Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 11 Jun 2015 20:16:39 -0400 Subject: [PATCH] add Program.get_uniform_location() --- include/glcxx/Program.hpp | 5 +++++ src/glcxx/Program.cpp | 12 ------------ test/frag.glsl | 4 +++- test/test.cpp | 2 ++ 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/glcxx/Program.hpp b/include/glcxx/Program.hpp index 0b88aaf..7b86f02 100644 --- a/include/glcxx/Program.hpp +++ b/include/glcxx/Program.hpp @@ -54,6 +54,11 @@ namespace glcxx bind_attributes(args...); } + GLint get_uniform_location(const char * uniform_name) + { + return glGetUniformLocation(m_id, uniform_name); + } + protected: void allocate(); diff --git a/src/glcxx/Program.cpp b/src/glcxx/Program.cpp index 84d8b67..2a3ae1b 100644 --- a/src/glcxx/Program.cpp +++ b/src/glcxx/Program.cpp @@ -49,16 +49,4 @@ namespace glcxx throw Error(message); } } - -#if 0 - for (;;) - { - const char *uniform_name = va_arg(va, const char *); - if (uniform_name == NULL) - break; - GLint loc = glGetUniformLocation(m_id, uniform_name); - m_uniform_locations.push_back(loc); - m_uniform_location_names[uniform_name] = loc; - } -#endif } diff --git a/test/frag.glsl b/test/frag.glsl index 34d1f54..b51cfff 100644 --- a/test/frag.glsl +++ b/test/frag.glsl @@ -1,4 +1,6 @@ +uniform vec4 color; + void main(void) { - gl_FragColor = vec4(0.5, 0.1, 0.9, 1.0); + gl_FragColor = color; } diff --git a/test/test.cpp b/test/test.cpp index b08ec7b..51026f8 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -48,6 +48,8 @@ void display(SDL_Window * window) glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL); program->use(); + GLint uniform_location = program->get_uniform_location("color"); + glUniform4f(uniform_location, 1.0, 0.6, 0.2, 1.0); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); SDL_GL_SwapWindow(window); }