Commit 3cd7068a authored by Janis Born's avatar Janis Born
Browse files

add VertexArrayObjectControl

parent 41fca74c
......@@ -33,6 +33,7 @@
#include <ACGL/OpenGL/Controller/TextureControl.hh>
#include <ACGL/OpenGL/Controller/TextureControlCubeMap.hh>
#include <ACGL/OpenGL/Controller/TextureControlFile.hh>
#include <ACGL/OpenGL/Controller/VertexArrayObjectControl.hh>
#include <ACGL/OpenGL/Controller/VertexArrayObjectControlFile.hh>
#include <ACGL/OpenGL/Controller/UniformControl.hh>
#include <ACGL/OpenGL/Controller/ViewportControl.hh>
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_VERTEXARRAYOBJECTCONTROL_HH
#define ACGL_OPENGL_CONTROLLER_VERTEXARRAYOBJECTCONTROL_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh>
#include <ACGL/OpenGL/Objects/ElementArrayBuffer.hh>
#include <ACGL/OpenGL/Data/LocationMappings.hh>
#include <vector>
namespace ACGL{
namespace OpenGL{
class VertexArrayObjectControl : public Resource::BasicCreateController<VertexArrayObject>
{
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef std::vector<SharedArrayBuffer> ArrayBufferVec;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
VertexArrayObjectControl()
: mArrayBuffers(),
mElementArrayBuffer(),
mAttributeLocations(),
mMode(GL_TRIANGLES)
{}
virtual ~VertexArrayObjectControl()
{}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
//! adds all attributes of an ArrayBuffer to the VAO
inline VertexArrayObjectControl& arrayBuffer(const SharedArrayBuffer& _ab)
{ mArrayBuffers.push_back(_ab); return *this; }
//! sets the ElementArrayBuffer for the VAO
inline VertexArrayObjectControl& elementArrayBuffer(const SharedElementArrayBuffer& _eab)
{ mElementArrayBuffer = _eab; return *this; }
//! links to an external LocationMappings object
inline VertexArrayObjectControl& externAttributeLocations(const SharedLocationMappings& _attributeLocations)
{ mAttributeLocations = _attributeLocations; return *this; }
//! sets the draw mode, default is GL_TRIANGLES
inline VertexArrayObjectControl& mode(GLenum _mode)
{ mMode = _mode; return *this; }
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedVertexArrayObject create();
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ArrayBufferVec mArrayBuffers;
SharedElementArrayBuffer mElementArrayBuffer;
SharedLocationMappings mAttributeLocations;
GLenum mMode;
};
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_VERTEXARRAYOBJECTCONTROL_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/VertexArrayObjectControl.hh>
using namespace ACGL::OpenGL;
SharedVertexArrayObject VertexArrayObjectControl::create()
{
SharedVertexArrayObject vao = SharedVertexArrayObject(new VertexArrayObject());
vao->setMode(mMode);
// attach all ArrayBuffers
for(ArrayBufferVec::iterator it = mArrayBuffers.begin();
it != mArrayBuffers.end();
++it)
{
vao->attachAllAttributes(*it);
}
// attach the ElementArrayBuffer
if(mElementArrayBuffer)
vao->attachElementArrayBuffer(mElementArrayBuffer);
// 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 vao;
}
Supports Markdown
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