From 6924ea10c4111b11eab51f0e1aa5b4a6438da7d3 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 28 Nov 2013 14:39:49 +0200 Subject: [PATCH] Use wrappers for single-value glGet* calls Having to create temporary stack variables just for passing in the return pointer is quite annoying. --- source/misc.cpp | 15 +++++++++++++++ source/misc.h | 2 ++ source/program.cpp | 23 +++++++++++------------ source/shader.cpp | 9 ++++----- source/texunit.cpp | 5 +++-- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/source/misc.cpp b/source/misc.cpp index f27fa5e2..3af18765 100644 --- a/source/misc.cpp +++ b/source/misc.cpp @@ -1,3 +1,4 @@ +#include #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 diff --git a/source/misc.h b/source/misc.h index cfefdbf2..86e09c04 100644 --- a/source/misc.h +++ b/source/misc.h @@ -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 diff --git a/source/program.cpp b/source/program.cpp index ffdd3b63..c8ce67a8 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -8,6 +8,7 @@ #include #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 uniforms_by_index(count); - for(int i=0; i #include #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); diff --git a/source/texunit.cpp b/source/texunit.cpp index 1129a036..714b6502 100644 --- a/source/texunit.cpp +++ b/source/texunit.cpp @@ -2,6 +2,7 @@ #include #include #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; } -- 2.45.2