Commit 89eede10 authored by Robert Menzel's avatar Robert Menzel

basic version of ProgramPipelines added

parent 08cb0ef2
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
......@@ -20,6 +20,7 @@
#include <ACGL/OpenGL/Objects/RenderObject.hh>
#include <ACGL/OpenGL/Objects/Shader.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/Objects/ProgramPipeline.hh>
#include <ACGL/OpenGL/Objects/ShaderProgramObject.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/OpenGL/Objects/Sampler.hh>
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2012, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_OBJECTS_PROGRAMPIPELINE_HH
#define ACGL_OPENGL_OBJECTS_PROGRAMPIPELINE_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
namespace ACGL{
namespace OpenGL{
/**
* OpenGL ProgramPipeline Objects
*
* Multiple ShaderPrograms that are set to be separable can be attached to one ProgramPipeline.
* Uniforms are still a ShaderProgram (not ProgramPipeline) state, so to update them you either have to
* select the correct ShaderProgram first (glActiveShaderProgram) or use the setProgramUniform variants.
*
* When using multiple ShaderPrograms in one ProgramPipeline the varyings don't just match based on
* the names any more, look up "Shader Interface Matching", cry, and rethink whether you still want to
* play around with ProgramPipeline Objects.
*/
#if (ACGL_OPENGL_VERSION >= 41)
class ProgramPipeline {
ACGL_NOT_COPYABLE(ProgramPipeline)
public:
ProgramPipeline();
~ProgramPipeline(void);
// ==================================================================================================== \/
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline GLuint operator() (void) const { return mObjectName; }
inline GLuint getObjectName(void) const { return mObjectName; }
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
//! Set this ProgramPipeline active, will override active ShaderPrograms!
inline void bind() const
{
glBindProgramPipeline( mObjectName );
openGLRareError();
}
//! unbinds the ProgramPipeline (if there is one bound), after that, ShaderPrograms can be used again directly
inline static void unBind() { glBindProgramPipeline( 0 ); }
//! Sets the given ShaderProgram (that should be part of the ProgramPipeline, which should be active) as target
//! for setUniform() calls. Alternatively use the setProgramUniform calls!
inline void setActiveShaderProgram( GLuint _shaderProgram ) { glActiveShaderProgram( mObjectName, _shaderProgram ); }
//! Sets the given ShaderProgram (that should be part of the ProgramPipeline, which should be active) as target
//! for setUniform() calls. Alternatively use the setProgramUniform calls!
inline void setActiveShaderProgram( const SharedShaderProgram &_shaderProgram ) { glActiveShaderProgram( mObjectName, _shaderProgram->getObjectName() ); }
//! _stages is a bitwise OR of GL_TESS_CONTROL_SHADER_BIT, GL_TESS_EVALUATION_SHADER_BIT, GL_VERTEX_SHADER_BIT, GL_GEOMETRY_SHADER_BIT,
//! and/or GL_FRAGMENT_SHADER_BIT _or_ GL_ALL_SHADER_BITS
void useProgramStages( GLbitfield _stages, SharedShaderProgram _shaderProgram ) {
if (_shaderProgram) {
glUseProgramStages( mObjectName, _stages, _shaderProgram->getObjectName() );
} else {
glUseProgramStages( mObjectName, _stages, 0 ); // deactivates that part of the pipeline (defined by _stages)
}
}
private:
// TODO: save 5 SharedPointer to the 5 ShaderPrograms for the individual stages
GLuint mObjectName;
};
ACGL_SMARTPOINTER_TYPEDEFS(ProgramPipeline)
#endif // OpenGL >= 4.1
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_OBJECTS_PROGRAMPIPELINE_HH
......@@ -106,6 +106,14 @@ public:
//! link the program, has to be redone after changing input or output locations:
bool link (void) const;
#if (ACGL_OPENGL_VERSION >= 41)
//! set the program separable to be used in a program pipeline object
inline bool setSeparable( GLboolean _b = GL_TRUE ) {
glProgramParameteri( mObjectName, GL_PROGRAM_SEPARABLE, _b );
return link();
}
#endif
// ===================================================================================================== \/
// =========================================================================================== LOCATIONS \/
// ===================================================================================================== \/
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2012, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Objects/ProgramPipeline.hh>
using namespace ACGL::OpenGL;
#if (ACGL_OPENGL_VERSION >= 41)
ProgramPipeline::ProgramPipeline()
{
glGenProgramPipelines(1, &mObjectName);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate ProgramPipeline!" << std::endl;
mObjectName = 0;
return;
}
}
ProgramPipeline::~ProgramPipeline(void)
{
// sampler 0 will get ignored by OpenGL
glDeleteProgramPipelines(1, &mObjectName);
}
#endif // OpenGL >= 4.1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment