X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fshaderprogram.h;h=9cedab6de0450abdc85998a5f86fb0ebeae1578b;hp=c052566c6abeee876536cf297f0f011166967c69;hb=433bde2ed090928b264203c9f422a5b220857120;hpb=57c3c69cbc7d9b3724874fd83cd001984ac21b6a diff --git a/src/shaderprogram.h b/src/shaderprogram.h index c052566..9cedab6 100644 --- a/src/shaderprogram.h +++ b/src/shaderprogram.h @@ -7,18 +7,27 @@ namespace IPDF { - /* - * The "Shader" class represents a GLSL program made from shaders. + /** + * The "Shader" class represents a GLSL program made from shaders. */ class ShaderProgram { public: ShaderProgram() : m_program(0) {} ~ShaderProgram(); - bool AttachVertexProgram(const char *src); - bool AttachFragmentProgram(const char *src); - bool AttachGeometryProgram(const char *src); - bool Link(); + + inline bool AttachGeometryProgram(const char * geometry_file) {return AttachShader(geometry_file, GL_GEOMETRY_SHADER);} + inline bool AttachVertexProgram(const char * vertex_file) {return AttachShader(vertex_file, GL_VERTEX_SHADER);} + inline bool AttachFragmentProgram(const char * fragment_file) {return AttachShader(fragment_file, GL_FRAGMENT_SHADER);} + + /** Read shaders from files and attach them + * @returns false if any of the shaders cannot be attached + */ + inline bool AttachShaderPrograms(const char * geometry_file, const char * vertex_file, const char * fragment_file) + { + return AttachGeometryProgram(geometry_file) && AttachVertexProgram(vertex_file) && AttachFragmentProgram(fragment_file); + } + bool Link(); // currently always returns true? const void Use() const; // Unfortunately, we don't require GL 4.3/ARB_explicit_uniform_location // which would make this obsolete. One uday Mesa will support it. @@ -26,9 +35,12 @@ namespace IPDF // Mesa supports ARB_shading_language_420pack, but that'd be a bit more // work right with the way some of our uniforms are laid out at the moment. const GLint GetUniformLocation(const char *uniform_name) const; + private: void LazyCreateProgram(); - bool AttachShader(const char *src, GLenum type); + /** Read shader source from src_file and attach it as type **/ + bool AttachShader(const char * src_file, GLenum type); + char * GetShaderSource(const char * src_file) const; GLuint m_program; struct Shader {