Commit 0545b116 authored by Lars Krecklau's avatar Lars Krecklau
Browse files

-Added controller for the uniforms

-Added SPOs to the state object
parent 0a3c77c3
......@@ -28,6 +28,7 @@
#include <ACGL/OpenGL/Controller/StateControl.hh>
#include <ACGL/OpenGL/Controller/TextureControl.hh>
#include <ACGL/OpenGL/Controller/TextureControlFileJPG.hh>
#include <ACGL/OpenGL/Controller/UniformControl.hh>
#include <ACGL/OpenGL/Controller/VertexBufferObjectControl.hh>
#include <ACGL/OpenGL/Controller/VertexBufferObjectControlFileOBJ.hh>
......
......@@ -24,11 +24,11 @@ public:
StateControl(
const ConstSharedVertexBufferObject& _vertexBufferObject,
const ConstSharedFrameBufferObject& _frameBufferObject,
const ConstSharedShaderProgram& _shaderProgram,
const ConstSharedShaderProgramObject& _shaderProgramObject,
const ConstSharedViewport& _viewport)
: mpVertexBufferObject(_vertexBufferObject),
mpFrameBufferObject(_frameBufferObject),
mpShaderProgram(_shaderProgram),
mpShaderProgramObject(_shaderProgramObject),
mpViewport(_viewport)
{}
virtual ~StateControl(void) {}
......@@ -37,9 +37,9 @@ public:
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline StateControl& vertexBuffer (const ConstSharedVertexBufferObject& _vertexBufferObject) { mpVertexBufferObject = _vertexBufferObject; return *this; }
inline StateControl& frameBuffer (const ConstSharedFrameBufferObject& _frameBufferObject) { mpFrameBufferObject = _frameBufferObject; return *this; }
inline StateControl& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
inline StateControl& vertexBufferObject (const ConstSharedVertexBufferObject& _vertexBufferObject) { mpVertexBufferObject = _vertexBufferObject; return *this; }
inline StateControl& frameBufferObject (const ConstSharedFrameBufferObject& _frameBufferObject) { mpFrameBufferObject = _frameBufferObject; return *this; }
inline StateControl& shaderProgramObject (const ConstSharedShaderProgramObject& _shaderProgramObject) { mpShaderProgramObject = _shaderProgramObject; return *this; }
inline StateControl& viewport (const ConstSharedViewport& _viewport) { mpViewport = _viewport; return *this; }
// ===================================================================================================== \/
......@@ -48,7 +48,7 @@ public:
public:
virtual SharedState create(void)
{
SharedState state(new State(mpVertexBufferObject, mpFrameBufferObject, mpShaderProgram, mpViewport));
SharedState state(new State(mpVertexBufferObject, mpFrameBufferObject, mpShaderProgramObject, mpViewport));
return state;
}
......@@ -59,7 +59,7 @@ public:
protected:
ConstSharedVertexBufferObject mpVertexBufferObject;
ConstSharedFrameBufferObject mpFrameBufferObject;
ConstSharedShaderProgram mpShaderProgram;
ConstSharedShaderProgramObject mpShaderProgramObject;
ConstSharedViewport mpViewport;
};
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_UNIFORMCONTROL_HH
#define ACGL_OPENGL_CONTROLLER_UNIFORMCONTROL_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/Uniform.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
template<class UNIFORM>
class UniformControl : public Resource::BasicCreateController<UNIFORM>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
UniformControl(const typename UNIFORM::DATA_TYPE& _value)
: mValue(_value)
{}
virtual ~UniformControl() {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline UniformControl& value (const typename UNIFORM::DATA_TYPE& _value) { mValue = _value; return *this; }
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual std::tr1::shared_ptr<UNIFORM> create(void)
{
std::tr1::shared_ptr<UNIFORM> uniform(new UNIFORM());
uniform->setValue(mValue);
return uniform;
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
typename UNIFORM::DATA_TYPE mValue;
};
typedef UniformControl<Uniform1i> Uniform1iControl;
typedef UniformControl<Uniform1f> Uniform1fControl;
typedef UniformControl<Uniform2f> Uniform2fControl;
typedef UniformControl<Uniform3f> Uniform3fControl;
typedef UniformControl<Uniform4f> Uniform4fControl;
typedef UniformControl<UniformMatrix2f> UniformMatrix2fControl;
typedef UniformControl<UniformMatrix3f> UniformMatrix3fControl;
typedef UniformControl<UniformMatrix4f> UniformMatrix4fControl;
typedef UniformControl<UniformTexture> UniformTextureControl;
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_ARRAYBUFFERCONTROL_HH
......@@ -26,8 +26,8 @@ class Shader
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef std::vector<std::string> AttributeVec;
typedef std::vector<std::string> FragmentDataVec;
typedef std::vector<std::string> AttributeNameVec;
typedef std::vector<std::string> FragmentDataNameVec;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
......@@ -53,8 +53,9 @@ public:
inline GLuint getContext (void) const { return mContext; }
inline GLenum getType (void) const { return mType; }
inline const std::vector<std::string>& getAttributes() const { return mAttributes; }
inline const std::vector<std::string>& getFragmentData() const { return mFragmentData; }
inline const std::vector<std::string>& getAttributeNames (void) const { return mAttributeNames; }
inline const std::vector<std::string>& getFragmentDataNames (void) const { return mFragmentDataNames; }
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
......@@ -71,8 +72,8 @@ protected:
protected:
GLuint mContext;
GLenum mType;
AttributeVec mAttributes;
FragmentDataVec mFragmentData;
AttributeNameVec mAttributeNames;
FragmentDataNameVec mFragmentDataNames;
};
ACGL_SHARED_TYPEDEF(Shader)
......
......@@ -18,7 +18,7 @@
#include <ACGL/OpenGL/Objects/VertexBufferObject.hh>
#include <ACGL/OpenGL/Objects/FrameBufferObject.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/Objects/ShaderProgramObject.hh>
#include <ACGL/OpenGL/Objects/Viewport.hh>
namespace ACGL{
......@@ -54,13 +54,13 @@ private:
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
State(ConstSharedVertexBufferObject _VertexBufferObject,
ConstSharedFrameBufferObject _FrameBufferObject,
ConstSharedShaderProgram _shaderProgram,
State(ConstSharedVertexBufferObject _vertexBufferObject,
ConstSharedFrameBufferObject _frameBufferObject,
ConstSharedShaderProgramObject _shaderProgram,
ConstSharedViewport _viewport)
: mpVertexBufferObject(_VertexBufferObject),
mpFrameBufferObject(_FrameBufferObject),
mpShaderProgram(_shaderProgram),
: mpVertexBufferObject(_vertexBufferObject),
mpFrameBufferObject(_frameBufferObject),
mpShaderProgramObject(_shaderProgram),
mpViewport(_viewport),
mAttributeMappings(),
mFragmentDataMappings(),
......@@ -81,33 +81,36 @@ public:
public:
inline ConstSharedVertexBufferObject getVertexBufferObject (void) const { return mpVertexBufferObject; }
inline ConstSharedFrameBufferObject getFrameBufferObject (void) const { return mpFrameBufferObject; }
inline ConstSharedShaderProgram getShaderProgram (void) const { return mpShaderProgram; }
inline ConstSharedShaderProgramObject getShaderProgramObject (void) const { return mpShaderProgramObject; }
inline ConstSharedViewport getViewport (void) const { return mpViewport; }
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
void useViewport (void);
void enableVertexBufferObject (void);
void bindFrameBufferObject (void);
void disableVertexBufferObject (void);
void updateMappings (void);
void useViewport (void) const;
void useShaderProgramObject (void) const;
void bindFrameBufferObject (void) const;
void enableVertexBufferObject (void) const;
void disableVertexBufferObject (void) const;
inline void validate (void) const
{
mpFrameBufferObject->validate();
mpVertexBufferObject->validate();
}
inline void draw(void)
inline void draw(void) const
{
mpVertexBufferObject->draw();
}
inline void render(void)
inline void render(void) const
{
useViewport();
useShaderProgramObject();
bindFrameBufferObject();
enableVertexBufferObject();
draw();
......@@ -120,7 +123,7 @@ public:
protected:
ConstSharedVertexBufferObject mpVertexBufferObject;
ConstSharedFrameBufferObject mpFrameBufferObject;
ConstSharedShaderProgram mpShaderProgram;
ConstSharedShaderProgramObject mpShaderProgramObject;
ConstSharedViewport mpViewport;
AttributeMappingVec mAttributeMappings;
......
......@@ -36,6 +36,12 @@ ACGL_SHARED_TYPEDEF(Uniform)
template<typename T>
class UniformData
{
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef T DATA_TYPE;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
......
......@@ -46,7 +46,8 @@ bool Shader::setSource(const std::string& _source)
std::istringstream stream(_source);
std::string line = "";
mAttributes.clear();
mAttributeNames.clear();
mFragmentDataNames.clear();
while (stream.good())
{
......@@ -62,7 +63,7 @@ bool Shader::setSource(const std::string& _source)
std::vector<std::string> tokensOfToken = StringOperations::split(tokens[2], ';');
if(tokensOfToken.size() > 0)
{
mAttributes.push_back(tokensOfToken[0]);
mAttributeNames.push_back(tokensOfToken[0]);
}
}
}
......@@ -77,7 +78,7 @@ bool Shader::setSource(const std::string& _source)
std::vector<std::string> tokensOfToken = StringOperations::split(tokens[2], ';');
if(tokensOfToken.size() > 0)
{
mFragmentData.push_back(tokensOfToken[0]);
mFragmentDataNames.push_back(tokensOfToken[0]);
}
}
}
......
......@@ -14,10 +14,9 @@ void ShaderProgram::bindAttributeLocations() const
{
for (ConstSharedShaderVec::size_type i = 0; i < mShaders.size(); ++i)
{
const Shader::AttributeVec& attribs = mShaders[i]->getAttributes();
for (Shader::AttributeVec::size_type k = 0; k < attribs.size(); ++k)
for (Shader::AttributeNameVec::size_type k = 0; k < mShaders[i]->getAttributeNames().size(); ++k)
{
glBindAttribLocation(mContext, k, attribs[k].c_str());
glBindAttribLocation(mContext, k, mShaders[i]->getAttributeNames()[k].c_str());
}
}
}
......@@ -26,10 +25,9 @@ void ShaderProgram::bindFragmentDataLocations() const
{
for (ConstSharedShaderVec::size_type i = 0; i < mShaders.size(); ++i)
{
const Shader::FragmentDataVec& fragData = mShaders[i]->getFragmentData();
for (Shader::FragmentDataVec::size_type k = 0; k < fragData.size(); ++k)
for (Shader::FragmentDataNameVec::size_type k = 0; k < mShaders[i]->getFragmentDataNames().size(); ++k)
{
glBindFragDataLocation(mContext, k, fragData[k].c_str());
glBindFragDataLocation(mContext, k, mShaders[i]->getFragmentDataNames()[k].c_str());
}
}
}
......
......@@ -14,18 +14,65 @@ using namespace ACGL::Base;
using namespace ACGL::Utils;
using namespace ACGL::OpenGL;
void State::useViewport()
void State::updateMappings (void)
{
ShaderProgram::ConstSharedShaderVec shaders = mpShaderProgramObject->getShaderProgram()->getShaders();
for(ShaderProgram::ConstSharedShaderVec::size_type shader = 0; shader < shaders.size(); shader++)
{
for(Shader::AttributeNameVec::size_type k = 0; k < shaders[shader]->getAttributeNames().size(); k++)
{
AttributeMapping mapping;
mapping.shaderProgramAttributeLocation = mpShaderProgramObject->getShaderProgram()->getAttributeLocation(shaders[shader]->getAttributeNames()[k]);
mapping.vertexBufferObjectAttribute = mpVertexBufferObject->getAttributeIndexByName(shaders[shader]->getAttributeNames()[k]);
mapping.arrayBufferID = mpVertexBufferObject->getArrayBufferIDByAttributeIndex(mapping.vertexBufferObjectAttribute);
bool inserted = false;
for (AttributeMappingVec::iterator it = mAttributeMappings.begin(); it < mAttributeMappings.end() && !inserted; it++)
{
if((*it).arrayBufferID > mapping.arrayBufferID)
{
mAttributeMappings.insert(it, mapping);
inserted = true;
}
}
if(!inserted)
mAttributeMappings.push_back(mapping);
}
for(Shader::FragmentDataNameVec::size_type k = 0; k < shaders[shader]->getFragmentDataNames().size(); k++)
{
FragmentDataMapping mapping;
mapping.shaderProgramFragmentDataLocation = mpShaderProgramObject->getShaderProgram()->getFragmentDataLocation(shaders[shader]->getFragmentDataNames()[k]);
mapping.frameBufferObjectColorAttachment = mpFrameBufferObject->getColorAttachmentIndexByName(shaders[shader]->getFragmentDataNames()[k]);
mFragmentDataMappings.push_back(mapping);
}
}
mpBuffers = new GLuint[mFragmentDataMappings.size()];
for(FragmentDataMappingVec::size_type k = 0; k < mFragmentDataMappings.size(); k++)
mpBuffers[k] = GL_COLOR_ATTACHMENT0 + mFragmentDataMappings[k].frameBufferObjectColorAttachment;
}
void State::useViewport (void) const
{
mpViewport->use();
}
void State::bindFrameBufferObject()
void State::useShaderProgramObject (void) const
{
mpShaderProgramObject->use();
}
void State::bindFrameBufferObject (void) const
{
mpFrameBufferObject->bind();
glDrawBuffers(mFragmentDataMappings.size(), mpBuffers);
}
void State::enableVertexBufferObject()
void State::enableVertexBufferObject (void) const
{
if(mpVertexBufferObject->getElementArrayBuffer())
mpVertexBufferObject->getElementArrayBuffer()->bind();
......@@ -45,7 +92,7 @@ void State::enableVertexBufferObject()
}
}
void State::disableVertexBufferObject()
void State::disableVertexBufferObject (void) const
{
int currentArrayBufferID = -1;
for(AttributeMappingVec::size_type k = 0; k < mAttributeMappings.size(); k++)
......@@ -59,49 +106,3 @@ void State::disableVertexBufferObject()
openGLRareError();
}
}
void State::updateMappings (void)
{
ShaderProgram::ConstSharedShaderVec shaders = mpShaderProgram->getShaders();
for(ShaderProgram::ConstSharedShaderVec::size_type shader = 0; shader < shaders.size(); shader++)
{
const Shader::AttributeVec& attributeVec = shaders[shader]->getAttributes();
for(Shader::AttributeVec::size_type k = 0; k < attributeVec.size(); k++)
{
AttributeMapping mapping;
mapping.shaderProgramAttributeLocation = mpShaderProgram->getAttributeLocation(attributeVec[k]);
mapping.vertexBufferObjectAttribute = mpVertexBufferObject->getAttributeIndexByName(attributeVec[k]);
mapping.arrayBufferID = mpVertexBufferObject->getArrayBufferIDByAttributeIndex(mapping.vertexBufferObjectAttribute);
bool inserted = false;
for (AttributeMappingVec::iterator it = mAttributeMappings.begin(); it < mAttributeMappings.end() && !inserted; it++)
{
if((*it).arrayBufferID > mapping.arrayBufferID)
{
mAttributeMappings.insert(it, mapping);
inserted = true;
}
}
if(!inserted)
mAttributeMappings.push_back(mapping);
}
const Shader::FragmentDataVec& fragmentDataVec = shaders[shader]->getFragmentData();
for(Shader::FragmentDataVec::size_type k = 0; k < fragmentDataVec.size(); k++)
{
FragmentDataMapping mapping;
mapping.shaderProgramFragmentDataLocation = mpShaderProgram->getFragmentDataLocation(fragmentDataVec[k]);
mapping.frameBufferObjectColorAttachment = mpFrameBufferObject->getColorAttachmentIndexByName(fragmentDataVec[k]);
mFragmentDataMappings.push_back(mapping);
}
}
mpBuffers = new GLuint[mFragmentDataMappings.size()];
for(FragmentDataMappingVec::size_type k = 0; k < mFragmentDataMappings.size(); k++)
mpBuffers[k] = GL_COLOR_ATTACHMENT0 + mFragmentDataMappings[k].frameBufferObjectColorAttachment;
}
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