Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ACGL
acgl
Commits
2c6a0f1f
Commit
2c6a0f1f
authored
May 28, 2013
by
Janis Born
Browse files
embed VAO caching mechanism into loadVertexArrayObject function
parent
30b2db11
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/ACGL/OpenGL/Data/VertexArrayObjectLoadStore.hh
View file @
2c6a0f1f
...
...
@@ -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
...
...
src/ACGL/OpenGL/Data/VertexArrayObjectLoadStore.cc
View file @
2c6a0f1f
...
...
@@ -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
)
{
//
l
ower case file ending:
//
L
ower 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
(
_f
ile
n
ame
);
SharedArrayBuffer
ab
=
loadArrayBuffer
(
loadF
ile
N
ame
);
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
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment