]> git.tdb.fi Git - libs/gl.git/commitdiff
Use wrappers for single-value glGet* calls
authorMikko Rasa <tdb@tdb.fi>
Thu, 28 Nov 2013 12:39:49 +0000 (14:39 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 28 Nov 2013 12:39:49 +0000 (14:39 +0200)
Having to create temporary stack variables just for passing in the return
pointer is quite annoying.

source/misc.cpp
source/misc.h
source/program.cpp
source/shader.cpp
source/texunit.cpp

index f27fa5e235820ebed59224fb365474712dd1f12e..3af18765f8fa468ea657dbf71f0f02c992c44fdb 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/gl/extensions/arb_shader_objects.h>
 #include "misc.h"
 
 namespace Msp {
@@ -33,5 +34,19 @@ int get_i(GLenum state)
        return data;
 }
 
+int get_shader_i(unsigned id, GLenum state)
+{
+       int data;
+       glGetShaderiv(id, state, &data);
+       return data;
+}
+
+int get_program_i(unsigned id, GLenum state)
+{
+       int data;
+       glGetProgramiv(id, state, &data);
+       return data;
+}
+
 } // namespace GL
 } // namespace Msp
index cfefdbf22e116fc823326482bbb9939d7881e7ef..86e09c044752f4844342a6869d449bb25ac34ba6 100644 (file)
@@ -12,6 +12,8 @@ void set(GLenum, bool);
 
 void get(GLenum, int *);
 int get_i(GLenum);
+int get_shader_i(unsigned, GLenum);
+int get_program_i(unsigned, GLenum);
 
 } // namespace GL
 } // namespace Msp
index ffdd3b6380e03180a6e3790ea730d57fcd6d8832..c8ce67a8897fc6fd5499b251e4a7713b71ff496e 100644 (file)
@@ -8,6 +8,7 @@
 #include <msp/strings/format.h>
 #include "buffer.h"
 #include "error.h"
+#include "misc.h"
 #include "program.h"
 #include "shader.h"
 
@@ -97,15 +98,13 @@ void Program::link()
        legacy_vars = false;
 
        glLinkProgram(id);
-       int value;
-       glGetProgramiv(id, GL_LINK_STATUS, &value);
-       if(!(linked = value))
+       linked = get_program_i(id, GL_LINK_STATUS);
+       if(!linked)
                throw compile_error(get_info_log());
 
-       int count;
-       glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &count);
+       unsigned count = get_program_i(id, GL_ACTIVE_UNIFORMS);
        vector<UniformInfo *> uniforms_by_index(count);
-       for(int i=0; i<count; ++i)
+       for(unsigned i=0; i<count; ++i)
        {
                char name[128];
                int len = 0;
@@ -132,8 +131,8 @@ void Program::link()
                        legacy_vars = true;
        }
 
-       glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &count);
-       for(int i=0; i<count; ++i)
+       count = get_program_i(id, GL_ACTIVE_ATTRIBUTES);
+       for(unsigned i=0; i<count; ++i)
        {
                char name[128];
                int len = 0;
@@ -146,8 +145,8 @@ void Program::link()
 
        if(ARB_uniform_buffer_object)
        {
-               glGetProgramiv(id, GL_ACTIVE_UNIFORM_BLOCKS, &count);
-               for(int i=0; i<count; ++i)
+               count = get_program_i(id, GL_ACTIVE_UNIFORM_BLOCKS);
+               for(unsigned i=0; i<count; ++i)
                {
                        char name[128];
                        int len;
@@ -155,6 +154,7 @@ void Program::link()
                        UniformBlockInfo &info = uniform_blocks[name];
                        info.name = name;
 
+                       int value;
                        glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_DATA_SIZE, &value);
                        info.data_size = value;
 
@@ -235,8 +235,7 @@ bool Program::uniform_location_compare(const UniformInfo *uni1, const UniformInf
 
 string Program::get_info_log() const
 {
-       GLsizei len = 0;
-       glGetProgramiv(id, GL_INFO_LOG_LENGTH, &len);
+       GLsizei len = get_program_i(id, GL_INFO_LOG_LENGTH);
        char *buf = new char[len+1];
        glGetProgramInfoLog(id, len+1, &len, buf);
        string log(buf, len);
index a1c576d8b3384c87fe31ff0e677e95224f21e44b..1b3455f1aa91270c810d0494ac80c3e80b7fe051 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/gl/extensions/arb_shader_objects.h>
 #include <msp/gl/extensions/arb_vertex_shader.h>
 #include "error.h"
+#include "misc.h"
 #include "shader.h"
 
 using namespace std;
@@ -57,16 +58,14 @@ void Shader::source(const char *str, int len)
 void Shader::compile()
 {
        glCompileShader(id);
-       int value = 0;
-       glGetShaderiv(id, GL_COMPILE_STATUS, &value);
-       if(!(compiled = value))
+       compiled = get_shader_i(id, GL_COMPILE_STATUS);
+       if(!compiled)
                throw compile_error(get_info_log());
 }
 
 string Shader::get_info_log() const
 {
-       GLsizei len = 0;
-       glGetShaderiv(id, GL_INFO_LOG_LENGTH, &len);
+       GLsizei len = get_shader_i(id, GL_INFO_LOG_LENGTH);
        char *buf = new char[len+1];
        glGetShaderInfoLog(id, len+1, &len, buf);
        string log(buf, len);
index 1129a0365617816a58ee1f0ff884cbd2f1e0ef59..714b65027d1786f03865bdfd22ab7d3851440f2b 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/gl/extensions/arb_multitexture.h>
 #include <msp/gl/extensions/arb_vertex_shader.h>
 #include "gl.h"
+#include "misc.h"
 #include "texunit.h"
 
 using namespace std;
@@ -62,9 +63,9 @@ unsigned TexUnit::get_n_units()
        if(count<0)
        {
                if(ARB_vertex_shader)
-                       glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &count);
+                       count = get_i(GL_MAX_TEXTURE_IMAGE_UNITS);
                else if(ARB_multitexture)
-                       glGetIntegerv(GL_MAX_TEXTURE_UNITS, &count);
+                       count = get_i(GL_MAX_TEXTURE_UNITS);
                else
                        count = 1;
        }