@ -10,10 +10,17 @@
# import <OpenGLES / ES2 / gl.h>
# import <OpenGLES / ES2 / gl.h>
# import <OpenGLES / ES2 / glext.h>
# import <OpenGLES / ES2 / glext.h>
// TODO: do glValidateProgram, like in the OpenGL template
// TODO: do glValidateProgram, like in the OpenGL template (see bottom)
// TODO: add error checking at set_uniforms?
// TODO: add error checking at set_uniforms?
// TODO: use an uniform map? (benchmark first!)
namespace J {
namespace J {
enum {
ATTRIB_VERTEX ,
ATTRIB_COLOR ,
NUM_ATTRIBUTES
} ;
class shader {
class shader {
typedef std : : map < GLenum , GLuint > ShaderMap ;
typedef std : : map < GLenum , GLuint > ShaderMap ;
@ -43,6 +50,12 @@ public:
throw std : : runtime_error ( fragment_shader_filename + " couldn't be opened " ) ;
throw std : : runtime_error ( fragment_shader_filename + " couldn't be opened " ) ;
read_shader ( fragment_shader , GL_FRAGMENT_SHADER ) ;
read_shader ( fragment_shader , GL_FRAGMENT_SHADER ) ;
}
}
{ // TODO: think of a nice way to implement this
// Bind attribute locations.
// This needs to be done prior to linking.
glBindAttribLocation ( program , ATTRIB_VERTEX , " position " ) ;
glBindAttribLocation ( program , ATTRIB_COLOR , " color " ) ;
}
link_program ( ) ;
link_program ( ) ;
}
}
@ -54,6 +67,7 @@ public:
GLuint shader = it . second ;
GLuint shader = it . second ;
glDetachShader ( program , shader ) ;
glDetachShader ( program , shader ) ;
glDeleteShader ( shader ) ;
glDeleteShader ( shader ) ;
// NOTE: If a shader object to be deleted is attached to a program object, it will be flagged for deletion, but it will not be deleted until it is no longer attached to any program object
}
}
glDeleteProgram ( program ) ;
glDeleteProgram ( program ) ;
@ -182,6 +196,31 @@ private:
}
}
# endif
# endif
}
}
/*
// Validate program before drawing. This is a good check, but only really necessary in a debug build.
- ( BOOL ) validateProgram : ( GLuint ) prog
{
GLint logLength , status ;
glValidateProgram ( prog ) ;
glGetProgramiv ( prog , GL_INFO_LOG_LENGTH , & logLength ) ;
if ( logLength > 0 )
{
GLchar * log = ( GLchar * ) malloc ( logLength ) ;
glGetProgramInfoLog ( prog , logLength , & logLength , log ) ;
NSLog ( @ " Program validate log: \n %s " , log ) ;
free ( log ) ;
}
glGetProgramiv ( prog , GL_VALIDATE_STATUS , & status ) ;
if ( status = = 0 )
return FALSE ;
return TRUE ;
}
*/
} ;
} ;