Commit ed09d0bc authored by Janis Born's avatar Janis Born
Browse files

add ArrayBufferControlFile

* uses GeometryDataControlFileFactory for loading
* should replace ArrayBufferControlFileATB
parent 9f4fb499
......@@ -19,6 +19,7 @@
#include <ACGL/Resource/FileManager.hh>
#include <ACGL/OpenGL/Controller/ArrayBufferControl.hh>
#include <ACGL/OpenGL/Controller/ArrayBufferControlFile.hh>
#include <ACGL/OpenGL/Controller/ArrayBufferControlFileATB.hh>
#include <ACGL/OpenGL/Controller/ElementArrayBufferControl.hh>
#include <ACGL/OpenGL/Controller/FrameBufferObjectControl.hh>
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2012, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_ARRAYBUFFERCONTROLFILE_HH
#define ACGL_OPENGL_CONTROLLER_ARRAYBUFFERCONTROLFILE_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/FileController.hh>
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
namespace ACGL{
namespace OpenGL{
class ArrayBufferControlFile : public Resource::FileController<ArrayBuffer>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
ArrayBufferControlFile(const std::string& _filename);
ArrayBufferControlFile(const char* _filename);
template<typename CONTROLLER>
ArrayBufferControlFile(const CONTROLLER& _fileController)
: Resource::FileController<ArrayBuffer>(_fileController.getFilename(), Base::Settings::the()->getFullGeometryPath()),
mDataController(new CONTROLLER(_fileController))
{}
virtual ~ArrayBufferControlFile(void) {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
private:
bool load(SharedArrayBuffer& _ab);
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedArrayBuffer create();
virtual bool update(SharedArrayBuffer& _ab);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
SharedGeometryDataControlFile mDataController;
};
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_ARRAYBUFFERCONTROLFILE_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/ArrayBufferControlFile.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>
using namespace ACGL;
using namespace ACGL::OpenGL;
ArrayBufferControlFile::ArrayBufferControlFile(const std::string& _filename)
: Resource::FileController<ArrayBuffer>(_filename, Base::Settings::the()->getFullGeometryPath()),
mDataController(GeometryDataControlFileFactory::the()->create(_filename))
{
if(!mDataController)
ACGL::Utils::error() << "No valid controller to load the geometry. Perhaps there is no loader for that file extension: " << _filename << std::endl;
}
ArrayBufferControlFile::ArrayBufferControlFile(const char* _filename)
: Resource::FileController<ArrayBuffer>(std::string(_filename), Base::Settings::the()->getFullGeometryPath()),
mDataController(GeometryDataControlFileFactory::the()->create(std::string(_filename)))
{
if(!mDataController)
ACGL::Utils::error() << "No valid controller to load the geometry. Perhaps there is no loader for that file extension: " << _filename << std::endl;
}
bool ArrayBufferControlFile::load(SharedArrayBuffer& _ab)
{
if(!mDataController)
return false;
SharedGeometryData tempData = mDataController->create();
if(!tempData)
return false;
for(uint_t i = 0; i < tempData->mAttributes.size(); ++i)
{
_ab->defineAttribute(tempData->mAttributes[i]);
}
_ab->setDataElements(tempData->getSize()/tempData->getStrideSize(), tempData->getData());
return true;
}
SharedArrayBuffer ArrayBufferControlFile::create()
{
updateFileModificationTime();
SharedArrayBuffer ab(new ArrayBuffer);
if(!load(ab))
return SharedArrayBuffer();
return ab;
}
bool ArrayBufferControlFile::update(SharedArrayBuffer& _ab)
{
if(fileIsUpToDate())
return false;
if(!load(_ab))
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