Commit 16a302ba authored by Janis Born's avatar Janis Born
Browse files

Add support for passing LocationMappings into

* VertexArrayObjectControl
* VertexArrayObjectControlFile
* ShaderProgramControlFiles
* FrameBufferObjectControl
parent 3cd7068a
......@@ -10,11 +10,11 @@
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/FrameBufferObject.hh>
#include <ACGL/OpenGL/Data/LocationMappings.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/OpenGL/Objects/RenderBuffer.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <vector>
......@@ -30,7 +30,7 @@ public:
FrameBufferObjectControl(void)
: mColorAttachments(),
mDepthAttachment(),
mpShaderProgram()
mFragDataLocations()
{
mDepthAttachment.name = "";
mDepthAttachment.texture = ConstSharedTexture();
......@@ -44,7 +44,6 @@ public:
public:
inline FrameBufferObjectControl& depthTexture (const ConstSharedTexture& _pDepthTexture) { mDepthAttachment.texture = _pDepthTexture; return *this; }
inline FrameBufferObjectControl& depthRenderBuffer (const ConstSharedRenderBuffer& _pDepthRenderBuffer) { mDepthAttachment.renderBuffer = _pDepthRenderBuffer; return *this; }
inline FrameBufferObjectControl& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
inline FrameBufferObjectControl& colorTexture(const std::string& _name, const ConstSharedTexture& _texture)
{
......@@ -52,6 +51,7 @@ public:
mColorAttachments.push_back(attachment);
return *this;
}
inline FrameBufferObjectControl& colorRenderBuffer(const std::string& _name, const ConstSharedRenderBuffer& _renderBuffer)
{
FrameBufferObject::Attachment attachment = {_name, SharedTexture(), _renderBuffer, (GLuint) mColorAttachments.size()};
......@@ -59,6 +59,12 @@ public:
return *this;
}
inline FrameBufferObjectControl& externFragmentDataLocations(const SharedLocationMappings& _fragmentDataLocations)
{
mFragDataLocations = _fragmentDataLocations;
return *this;
}
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
......@@ -71,7 +77,7 @@ public:
protected:
FrameBufferObject::AttachmentVec mColorAttachments;
FrameBufferObject::Attachment mDepthAttachment;
ConstSharedShaderProgram mpShaderProgram;
SharedLocationMappings mFragDataLocations;
};
} // OpenGL
......
......@@ -115,6 +115,10 @@ public:
//! adds a whole list of mappings
inline ShaderProgramControlFiles& fragmentDataLocations(const SharedLocationMappings &_mapping) { mFragmentDataLocations->addLocations(_mapping); return *this; }
//! links to the external mapping object, earlyer mapping definitions get ignored, following
//! mappings will also change the external object!
inline ShaderProgramControlFiles& externFragmentDataLocations (SharedLocationMappings _mapping) { mFragmentDataLocations = _mapping; return *this; }
//
// Adding uniform buffer locations:
//
......
......@@ -11,6 +11,7 @@
#include <ACGL/Resource/FileController.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
#include <ACGL/OpenGL/Data/LocationMappings.hh>
namespace ACGL{
namespace OpenGL{
......@@ -27,7 +28,8 @@ public:
template<typename CONTROLLER>
VertexArrayObjectControlFile(const CONTROLLER& _fileController)
: Resource::FileController<VertexArrayObject>(_fileController.getFilename(), Base::Settings::the()->getFullTexturePath()),
mDataController(new CONTROLLER(_fileController))
mDataController(new CONTROLLER(_fileController)),
mAttributeLocations()
{}
virtual ~VertexArrayObjectControlFile(void) {}
......@@ -35,7 +37,8 @@ public:
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline VertexArrayObjectControlFile& foo () { return *this; }
//! links to an external LocationMappings object
inline VertexArrayObjectControlFile& externAttributeLocations(const SharedLocationMappings& _attributeLocations) { mAttributeLocations = _attributeLocations; return *this; }
private:
bool load(SharedVertexArrayObject& vao);
......@@ -52,6 +55,7 @@ public:
// =================================================================================================== \/
protected:
SharedGeometryDataControlFile mDataController;
SharedLocationMappings mAttributeLocations;
};
} // OpenGL
......
......@@ -170,6 +170,11 @@ public:
*/
void detachAttribute( const std::string &_name );
/**
* Will detach all currently attached Attributes
*/
void detachAllAttributes();
/**
* Query the attribute locations based on the attribute names in the ArrayBuffers.
* If they match, use the location reported from _locationMappings.
......@@ -240,11 +245,6 @@ public:
//! Draws all elements
inline void drawArrays(void) const
{
if(mAttributes.empty())
{
ACGL::Utils::error() << "cannot draw VAO with no attributes attached" << std::endl;
return;
}
drawArrays(mAttributes[getFirstAttributeIndex()].arrayBuffer->getElements());
}
......
......@@ -9,6 +9,7 @@ using namespace ACGL::OpenGL;
SharedFrameBufferObject FrameBufferObjectControl::create(void)
{
/*
SharedFrameBufferObject frameBuffer(new FrameBufferObject());
frameBuffer->bind();
......@@ -56,4 +57,33 @@ SharedFrameBufferObject FrameBufferObjectControl::create(void)
frameBuffer->setDepthRenderBuffer(mDepthAttachment.renderBuffer);
return frameBuffer;
*/
SharedFrameBufferObject fbo = SharedFrameBufferObject(new FrameBufferObject());
// attach all defined color Textures and RenderBuffers
for(FrameBufferObject::AttachmentVec::iterator it = mColorAttachments.begin();
it != mColorAttachments.end();
++it)
{
if(it->texture)
fbo->attachColorTexture(it->name, it->texture);
else if(it->renderBuffer)
fbo->attachColorRenderBuffer(it->name, it->renderBuffer);
}
// attach the depth attachment
if(mDepthAttachment.texture)
fbo->setDepthTexture(mDepthAttachment.texture);
else if(mDepthAttachment.renderBuffer)
fbo->setDepthRenderBuffer(mDepthAttachment.renderBuffer);
// update the LocationMappings mapping, if present
if(mFragDataLocations)
{
SharedLocationMappings fboMappings = fbo->getAttachmentLocations();
mFragDataLocations->addLocations(fboMappings);
}
return fbo;
}
......@@ -130,9 +130,10 @@ void ShaderProgramControlFiles::setBindings(SharedShaderProgram &_shaderProgram)
_shaderProgram->setFragmentDataLocations( mFragmentDataLocations ); // will relink on it's own
openGLRareErrorOccured();
SharedLocationMappings oldMap = _shaderProgram->getAttributeLocations();
mAttributeLocations->addLocations( oldMap ); // add as many old locations as possible without destoying the location map
_shaderProgram->setAttributeLocations( mAttributeLocations ); // will relink on it's own
SharedLocationMappings oldAttributeMap = _shaderProgram->getAttributeLocations();
mAttributeLocations->addLocations( oldAttributeMap ); // add as many old locations as possible without destoying the location map
_shaderProgram->setAttributeLocations( mAttributeLocations ); // will relink on it's own
openGLRareErrorOccured();
# else
if ( (mAttributeLocations->getSize() > 0) && (mFragmentDataLocations->getSize() > 0) ) {
......
......@@ -40,7 +40,16 @@ bool VertexArrayObjectControlFile::load(SharedVertexArrayObject& vao)
}
sab->setDataElements( tempData->getSize()/tempData->getStrideSize(), tempData->getData() );
vao->attachAllAttributes( sab );
vao->detachAllAttributes();
vao->attachAllAttributes(sab);
// merge the mappings of the new VAO into the linked LocationMappings object, if present
if(mAttributeLocations)
{
SharedLocationMappings vaoAttributeLocations = vao->getAttributeLocations();
mAttributeLocations->addLocations(vaoAttributeLocations);
vao->setAttributeLocations(mAttributeLocations);
}
return true;
}
......@@ -53,6 +62,7 @@ SharedVertexArrayObject VertexArrayObjectControlFile::create(void)
if(!load(vao))
return SharedVertexArrayObject();
return vao;
}
......
......@@ -47,7 +47,7 @@ void VertexArrayObject::attachElementArrayBuffer( const SharedElementArrayBuffer
void VertexArrayObject::attachAttribute( const Attribute &_attribute, GLint _location )
{
if ( (GLuint)_location >= mAttributes.size()) {
if ( _location >= (GLint)mAttributes.size()) {
ACGL::Utils::error() << "can't attach attribute " << _attribute.arrayBuffer->getAttributes()[_attribute.attributeID].name
<< " - maximum number of attributes: " << mAttributes.size() << std::endl;
return;
......@@ -141,6 +141,13 @@ void VertexArrayObject::detachAttribute( const std::string &_name )
ACGL::Utils::warning() << "can't detach attribute " << _name << " - no such Attribute" << std::endl;
}
void VertexArrayObject::detachAllAttributes()
{
for(AttributeVec::size_type i = 0; i < mAttributes.size(); ++i)
{
detachAttribute(i);
}
}
void VertexArrayObject::setAttributeLocations( ConstSharedLocationMappings _locationMappings )
{
......
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