From a47d6526470807d8e657bf881b3809722b51483c Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Sun, 28 Aug 2011 15:23:39 +0200 Subject: [PATCH] added checking in debug build --- J.xcodeproj/project.pbxproj | 19 ++++++++++++++++++- J/J.h | 2 +- J/basic.cpp | 20 ++++++++++++++++++++ J/basic.h | 22 ++++++++++++++++++++++ J/fbo.h | 25 +++++++++++++------------ J/shader.h | 22 ++++++++++++++++------ 6 files changed, 90 insertions(+), 20 deletions(-) create mode 100644 J/basic.cpp create mode 100644 J/basic.h diff --git a/J.xcodeproj/project.pbxproj b/J.xcodeproj/project.pbxproj index 2b8eae5..85ec6d5 100644 --- a/J.xcodeproj/project.pbxproj +++ b/J.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 425E9DF2140A74DA00A81A65 /* basic.h in Headers */ = {isa = PBXBuildFile; fileRef = 425E9DF1140A74DA00A81A65 /* basic.h */; }; + 425E9DF6140A774D00A81A65 /* basic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 425E9DF5140A774D00A81A65 /* basic.cpp */; }; 42681369140A321800CBF943 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42681368140A321800CBF943 /* Foundation.framework */; }; 4268136F140A321800CBF943 /* J.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4268136E140A321800CBF943 /* J.mm */; }; 42ED6A6B140A380000402F76 /* fbo.h in Headers */ = {isa = PBXBuildFile; fileRef = 42ED6A68140A380000402F76 /* fbo.h */; }; @@ -15,6 +17,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 425E9DF1140A74DA00A81A65 /* basic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = basic.h; sourceTree = ""; }; + 425E9DF5140A774D00A81A65 /* basic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = basic.cpp; sourceTree = ""; }; 42681365140A321800CBF943 /* libJ.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libJ.a; sourceTree = BUILT_PRODUCTS_DIR; }; 42681368140A321800CBF943 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 4268136C140A321800CBF943 /* J-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "J-Prefix.pch"; sourceTree = ""; }; @@ -37,9 +41,19 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 425E9DF4140A751200A81A65 /* std */ = { + isa = PBXGroup; + children = ( + 42ED6A6A140A380000402F76 /* to_string.h */, + ); + name = std; + path = J; + sourceTree = ""; + }; 4268135A140A321700CBF943 = { isa = PBXGroup; children = ( + 425E9DF4140A751200A81A65 /* std */, 4268136A140A321800CBF943 /* J */, 42681367140A321800CBF943 /* Frameworks */, 42681366140A321800CBF943 /* Products */, @@ -65,9 +79,10 @@ 4268136A140A321800CBF943 /* J */ = { isa = PBXGroup; children = ( + 425E9DF1140A74DA00A81A65 /* basic.h */, + 425E9DF5140A774D00A81A65 /* basic.cpp */, 42ED6A68140A380000402F76 /* fbo.h */, 42ED6A69140A380000402F76 /* shader.h */, - 42ED6A6A140A380000402F76 /* to_string.h */, 4268136D140A321800CBF943 /* J.h */, 4268136E140A321800CBF943 /* J.mm */, 4268136B140A321800CBF943 /* Supporting Files */, @@ -93,6 +108,7 @@ 42ED6A6B140A380000402F76 /* fbo.h in Headers */, 42ED6A6C140A380000402F76 /* shader.h in Headers */, 42ED6A6D140A380000402F76 /* to_string.h in Headers */, + 425E9DF2140A74DA00A81A65 /* basic.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -147,6 +163,7 @@ buildActionMask = 2147483647; files = ( 4268136F140A321800CBF943 /* J.mm in Sources */, + 425E9DF6140A774D00A81A65 /* basic.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/J/J.h b/J/J.h index 5d98301..72a178e 100644 --- a/J/J.h +++ b/J/J.h @@ -7,7 +7,7 @@ // #import + #import "shader.h" #import "fbo.h" -#import "to_string.h" diff --git a/J/basic.cpp b/J/basic.cpp new file mode 100644 index 0000000..18514d2 --- /dev/null +++ b/J/basic.cpp @@ -0,0 +1,20 @@ +// +// basic.cpp +// J +// +// Created by Joshua Moerman on 8/28/11. +// Copyright 2011 Vadovas. All rights reserved. +// + +#include "basic.h" + +namespace J { + void check_error(){ + #if defined(DEBUG) + GLenum status = glGetError(); + if(status != GL_NO_ERROR){ + throw std::runtime_error("GL Error: " + std::to_string(status)); + } + #endif + } +} \ No newline at end of file diff --git a/J/basic.h b/J/basic.h new file mode 100644 index 0000000..e971061 --- /dev/null +++ b/J/basic.h @@ -0,0 +1,22 @@ +// +// basic.h +// J +// +// Created by Joshua Moerman on 8/28/11. +// Copyright 2011 Vadovas. All rights reserved. +// + +#ifndef J_basic_h +#define J_basic_h + +#include +#include "to_string.h" + +#import +#import + +namespace J { + void check_error(); +} + +#endif diff --git a/J/fbo.h b/J/fbo.h index 42fb2ca..6f9d661 100644 --- a/J/fbo.h +++ b/J/fbo.h @@ -1,14 +1,20 @@ +// +// fbo.h +// J +// +// Created by Joshua Moerman on 7/01/11. +// Copyright 2011 Vadovas. All rights reserved. +// + #ifndef FBO_H #define FBO_H #include #include #include - #include "to_string.h" -#import -#import +#include "basic.h" // TODO: more error checking in debug build. // TODO: make texture class? for easier switching between linear/nearest interpolation for example @@ -38,7 +44,8 @@ public: // attach depth create_attach_renderbuffer(GL_DEPTH_COMPONENT16, GL_DEPTH_ATTACHMENT); - + + check_error(); check_status(); glClearColor(0.0, 0.0, 0.0, 0.0); @@ -80,7 +87,6 @@ public: private: void bind(){ glBindFramebuffer(GL_FRAMEBUFFER, fbo_number); - check_error(); } @@ -99,6 +105,7 @@ private: } void check_status() { + #if defined(DEBUG) GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); switch(status) { case GL_FRAMEBUFFER_COMPLETE: @@ -121,13 +128,7 @@ private: break; } throw std::runtime_error("I will not continu.."); - } - - void check_error(){ - GLenum status = glGetError(); - if(status != GL_NO_ERROR){ - throw std::runtime_error("GL Error: " + std::to_string(status)); - } + #endif } }; diff --git a/J/shader.h b/J/shader.h index 5852e82..917597e 100644 --- a/J/shader.h +++ b/J/shader.h @@ -1,3 +1,11 @@ +// +// shader.h +// J +// +// Created by Joshua Moerman on 7/01/11. +// Copyright 2011 Vadovas. All rights reserved. +// + #ifndef SHADER_H #define SHADER_H @@ -7,8 +15,7 @@ #include #include -#import -#import +#import "basic.h" // TODO: do glValidateProgram, like in the OpenGL template (see bottom) // TODO: add error checking at set_uniforms? @@ -62,6 +69,7 @@ public: } link_program(); + check_error(); } ~shader(){ @@ -182,6 +190,7 @@ public: // ********* // validator void validate() { + #if defined(DEBUG) GLint status; glValidateProgram(program); glGetProgramiv(program, GL_VALIDATE_STATUS, &status); @@ -190,6 +199,7 @@ public: show_log(); throw std::runtime_error("Program not valid"); } + #endif } private: @@ -207,9 +217,7 @@ private: glShaderSource(shader, 1, &sptr, &ssize); glCompileShader(shader); - #if defined(DEBUG) check_compile_status(shader, buffer); - #endif // put it in tha map shaders[type] = shader; @@ -226,14 +234,13 @@ private: // link glLinkProgram(program); - #if defined(DEBUG) check_link_status(); - #endif } // *************** // status checking void check_compile_status(GLint shader, std::string source = "") { + #if defined(DEBUG) GLint status = GL_FALSE; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if(status == GL_FALSE || shader == 0) { @@ -242,9 +249,11 @@ private: show_log(); throw std::runtime_error("Shader failed to compile"); } + #endif } void check_link_status() { + #if defined(DEBUG) GLint status; glGetProgramiv(program, GL_LINK_STATUS, &status); if(status == GL_FALSE) { @@ -252,6 +261,7 @@ private: show_log(); throw std::runtime_error("Shader failed to link"); } + #endif } void show_log(std::ostream& out = std::cerr) {