Commit 2c6a0f1f authored by Janis Born's avatar Janis Born

embed VAO caching mechanism into loadVertexArrayObject function

parent 30b2db11
......@@ -18,9 +18,15 @@ namespace OpenGL{
// generic load/save
///////////////////////////////////////////////////////////////////////////////////////////////////
//! @brief
//! Loads geometry data from a file and attaches the loaded array buffer data to a VertexArrayObject
//! Tries to guess the file format from the file extension
SharedVertexArrayObject loadVertexArrayObject(const std::string& _filename);
//! @param _filename The name of the file to load relative to the Geometry load path
//! @param _caching If true, a disk caching mechanism is used to speed up future reading of the same file.
//! When the file is loaded for the first time, a copy of the resulting VAO is stored in
//! the binary VAO format next to the original file. Successive loadings of the same file
//! will load the cached version if one is present.
SharedVertexArrayObject loadVertexArrayObject(const std::string& _filename, bool _caching = false);
///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific load
......
......@@ -15,30 +15,59 @@ using namespace ACGL::Utils;
namespace ACGL{
namespace OpenGL{
SharedVertexArrayObject loadVertexArrayObject(const std::string& _filename)
SharedVertexArrayObject loadVertexArrayObject(const std::string& _filename, bool _caching)
{
// lower case file ending:
// Lower case file ending:
std::string fileEnding = Base::FileHelpers::getFileEnding(_filename);
std::string loadFileName = _filename;
// Never cache VAO files
if(fileEnding == "vao")
_caching = false;
bool saveCachedVAO = false;
if(_caching)
{
return loadVertexArrayObjectVAO(_filename);
// See whether a cached version of the file is available
if(ACGL::Base::FileHelpers::fileExists(_filename + ".vao")
&& ACGL::Base::FileHelpers::getFileModificationTime(_filename + ".vao") > ACGL::Base::FileHelpers::getFileModificationTime(_filename))
{
// If so, load the cached file instead
loadFileName = _filename + ".vao";
fileEnding = "vao";
}
else
{
// Otherwise, create a cached copy after loading
saveCachedVAO = true;
}
}
// Load the VAO
SharedVertexArrayObject vao;
if(fileEnding == "vao")
{
vao = loadVertexArrayObjectVAO(loadFileName);
}
else
{
// Generic load: Try to load the file as an ArrayBuffer and attach it to a VAO
SharedArrayBuffer ab = loadArrayBuffer(_filename);
SharedArrayBuffer ab = loadArrayBuffer(loadFileName);
if(ab)
{
SharedVertexArrayObject vao(new VertexArrayObject);
vao = SharedVertexArrayObject(new VertexArrayObject);
vao->attachAllAttributes(ab);
return vao;
}
else
{
return SharedVertexArrayObject();
}
}
// If necessary, store a cached copy to disk
if(vao && saveCachedVAO)
{
ACGL::Utils::debug() << "Saving a cached copy of " << _filename << " ..." << std::endl;
saveVertexArrayObjectToVAO(vao, _filename + ".vao");
}
return vao;
}
}
......
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