Commit b0941346 authored by Robert Menzel's avatar Robert Menzel

Merge branch 'refactorGLobjects' of...

Merge branch 'refactorGLobjects' of file:///data/git-repository/acgl/libraries/acgl into refactorGLobjects
parents c2fe617c d6ad6ee1
......@@ -11,11 +11,19 @@
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
#include <map>
#include <string>
namespace ACGL{
namespace OpenGL{
class ArrayBufferControlFile : public Resource::FileController<ArrayBuffer>
{
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
typedef std::map<uint_t, std::string> AttributeNameMap;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
......@@ -33,6 +41,13 @@ public:
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
ArrayBufferControlFile& nameAttribute(uint_t _attributeIndex, const std::string& _name)
{
mAttributeNameMap[_attributeIndex] = _name;
return *this;
}
private:
bool load(SharedArrayBuffer& _ab);
......@@ -48,6 +63,7 @@ public:
// =================================================================================================== \/
protected:
SharedGeometryDataControlFile mDataController;
AttributeNameMap mAttributeNameMap;
};
} // OpenGL
......
......@@ -144,8 +144,15 @@ public:
const std::string& _arrayBufferAttributeName,
GLint _attributeLocation = -1)
{
int32_t arrayBufferAttribute = _arrayBuffer->getAttributeIndexByName(_arrayBufferAttributeName);
if(arrayBufferAttribute == -1) {
ACGL::Utils::error() << "can't attach attribute: attribute " << _arrayBufferAttributeName << " not present in array buffer" << std::endl;
return;
}
attachAttribute(_arrayBuffer,
_arrayBuffer->getAttributeIndexByName(_arrayBufferAttributeName),
arrayBufferAttribute,
_attributeLocation);
}
......
......@@ -35,9 +35,16 @@ bool ArrayBufferControlFile::load(SharedArrayBuffer& _ab)
if(!tempData)
return false;
_ab->removeAttributes();
for(uint_t i = 0; i < tempData->mAttributes.size(); ++i)
{
_ab->defineAttribute(tempData->mAttributes[i]);
ArrayBuffer::Attribute attribute = tempData->mAttributes[i];
// Rename attribute if so specified
if(mAttributeNameMap.find(i) != mAttributeNameMap.end())
attribute.name = mAttributeNameMap[i];
_ab->defineAttribute(attribute);
}
_ab->setDataElements(tempData->getSize()/tempData->getStrideSize(), tempData->getData());
......
......@@ -47,7 +47,11 @@ void VertexArrayObject::attachElementArrayBuffer( const ConstSharedElementArrayB
void VertexArrayObject::attachAttribute( const Attribute &_attribute, GLint _location )
{
if ( _location >= (GLint)mAttributes.size()) {
if(_attribute.attributeID == -1) {
ACGL::Utils::error() << "can't attach attribute: invalid attribute ID" << std::endl;
return;
}
else 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;
......
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