Browse Source

added checking in debug build

master
Joshua Moerman 14 years ago
parent
commit
a47d652647
  1. 19
      J.xcodeproj/project.pbxproj
  2. 2
      J/J.h
  3. 20
      J/basic.cpp
  4. 22
      J/basic.h
  5. 23
      J/fbo.h
  6. 22
      J/shader.h

19
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 = "<group>"; };
425E9DF5140A774D00A81A65 /* basic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = basic.cpp; sourceTree = "<group>"; };
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 = "<group>"; };
@ -37,9 +41,19 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
425E9DF4140A751200A81A65 /* std */ = {
isa = PBXGroup;
children = (
42ED6A6A140A380000402F76 /* to_string.h */,
);
name = std;
path = J;
sourceTree = "<group>";
};
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;
};

2
J/J.h

@ -7,7 +7,7 @@
//
#import <Foundation/Foundation.h>
#import "shader.h"
#import "fbo.h"
#import "to_string.h"

20
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
}
}

22
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 <stdexcept>
#include "to_string.h"
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
namespace J {
void check_error();
}
#endif

23
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 <map>
#include <iostream>
#include <stdexcept>
#include "to_string.h"
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#include "basic.h"
// TODO: more error checking in debug build.
// TODO: make texture class? for easier switching between linear/nearest interpolation for example
@ -39,6 +45,7 @@ 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
}
};

22
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 <map>
#include <iterator>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#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) {