Commit 0abdc61d authored by Robert Menzel's avatar Robert Menzel
Browse files

some work on VAO creation / controller

parent 0aa3296f
......@@ -32,6 +32,7 @@
#include <ACGL/OpenGL/Controller/TextureControl.hh>
#include <ACGL/OpenGL/Controller/TextureControlCubeMap.hh>
#include <ACGL/OpenGL/Controller/TextureControlFile.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_VERTEXARRAYOBJECTCONTROLFILE_HH
#define ACGL_OPENGL_CONTROLLER_VERTEXARRAYOBJECTCONTROLFILE_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/FileController.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
namespace ACGL{
namespace OpenGL{
class VertexArrayObjectControlFile : public Resource::FileController<VertexArrayObject>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
VertexArrayObjectControlFile(const std::string& _filename);
VertexArrayObjectControlFile(const char* _filename);
template<typename CONTROLLER>
VertexArrayObjectControlFile(const CONTROLLER& _fileController)
: Resource::FileController<VertexArrayObject>(_fileController.getFilename(), Base::Settings::the()->getFullTexturePath()),
mDataController(new CONTROLLER(_fileController))
{}
virtual ~VertexArrayObjectControlFile(void) {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline VertexArrayObjectControlFile& foo () { return *this; }
private:
bool load(SharedVertexArrayObject& vao);
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedVertexArrayObject create(void);
virtual bool update(SharedVertexArrayObject& vao);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
SharedGeometryDataControlFile mDataController;
};
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_VERTEXARRAYOBJECTCONTROLFILE_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/VertexArrayObjectControlFile.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>
using namespace ACGL::OpenGL;
VertexArrayObjectControlFile::VertexArrayObjectControlFile(const std::string& _filename)
: Resource::FileController<VertexArrayObject>(_filename, Base::Settings::the()->getFullTexturePath()),
mDataController(GeometryDataControlFileFactory::the()->create(_filename))
{
if(!mDataController)
ACGL::Utils::error() << "No valid VAO controller to load the geometry. Perhaps there is no loader for that file extension: " << _filename << std::endl;
}
VertexArrayObjectControlFile::VertexArrayObjectControlFile(const char* _filename)
: Resource::FileController<VertexArrayObject>(std::string(_filename), Base::Settings::the()->getFullTexturePath()),
mDataController(GeometryDataControlFileFactory::the()->create(std::string(_filename)))
{
if(!mDataController)
ACGL::Utils::error() << "No valid VAO controller to load the geometry. Perhaps there is no loader for that file extension: " << _filename << std::endl;
}
bool VertexArrayObjectControlFile::load(SharedVertexArrayObject& vao)
{
if(!mDataController)
return false;
SharedGeometryData tempData = mDataController->create();
if(!tempData)
return false;
SharedArrayBuffer sab = SharedArrayBuffer( new ArrayBuffer() );
for ( u_int i = 0; i < tempData->mAttributes.size(); ++i ) {
sab->defineAttribute( tempData->mAttributes[i] );
}
sab->setDataElements( tempData->getSize()/tempData->getStrideSize(), tempData->getData() );
vao->attachAllAttributes( sab );
return true;
}
SharedVertexArrayObject VertexArrayObjectControlFile::create(void)
{
updateFileModificationTime();
SharedVertexArrayObject vao(new VertexArrayObject());
if(!load(vao))
return SharedVertexArrayObject();
return vao;
}
bool VertexArrayObjectControlFile::update(SharedVertexArrayObject& vao)
{
if(fileIsUpToDate())
return false;
if(!load(vao))
return false;
updateFileModificationTime();
return true;
}
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