summaryrefslogtreecommitdiff
path: root/vcl/source/opengl
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2015-10-08 13:24:12 +0300
committerTor Lillqvist <tml@collabora.com>2015-10-08 13:43:17 +0300
commitb69e55bdb2544f3fcc492d535a77ff17022ed6d5 (patch)
tree32e01348aa28d569a035a2646e32ea5a403e8ea9 /vcl/source/opengl
parent2bd7a569720fdd6b808e6076ce7c8ded1cb6a5a7 (diff)
Don't re-read the same glsl files over and over again
Change-Id: I10b4badaba01630e1a054b3d4d9cc4720822511a
Diffstat (limited to 'vcl/source/opengl')
-rw-r--r--vcl/source/opengl/OpenGLHelper.cxx24
1 files changed, 20 insertions, 4 deletions
diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 92bfe7db5b77..5290f8c2445e 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -11,6 +11,7 @@
#include <vcl/opengl/OpenGLHelper.hxx>
#include <osl/file.hxx>
+#include <osl/mutex.hxx>
#include <rtl/bootstrap.hxx>
#include <rtl/digest.h>
#include <rtl/strbuf.hxx>
@@ -66,6 +67,7 @@ OString loadShader(const OUString& rFilename)
{
OUString aFileURL = getShaderFolder() + rFilename +".glsl";
osl::File aFile(aFileURL);
+ SAL_INFO("vcl.opengl", "Reading " << aFileURL);
if(aFile.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None)
{
sal_uInt64 nSize = 0;
@@ -85,6 +87,20 @@ OString loadShader(const OUString& rFilename)
return OString();
}
+OString& getShaderSource(const OUString& rFilename)
+{
+ static std::unordered_map<OUString, OString, OUStringHash> aMap;
+ static osl::Mutex aMutex;
+ osl::MutexGuard aGuard(aMutex);
+
+ if (aMap.find(rFilename) == aMap.end())
+ {
+ aMap[rFilename] = loadShader(rFilename);
+ }
+
+ return aMap[rFilename];
+}
+
}
namespace {
@@ -189,8 +205,8 @@ namespace
const OString& rPreamble )
{
// read shaders source
- OString aVertexShaderSource = loadShader( rVertexShaderName );
- OString aFragmentShaderSource = loadShader( rFragmentShaderName );
+ OString aVertexShaderSource = getShaderSource( rVertexShaderName );
+ OString aFragmentShaderSource = getShaderSource( rFragmentShaderName );
// get info about the graphic device
#if defined( SAL_UNX ) && !defined( MACOSX ) && !defined( IOS )&& !defined( ANDROID )
@@ -374,8 +390,8 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,
GLint ProgramID = glCreateProgram();
// read shaders from file
- OString aVertexShaderSource = loadShader(rVertexShaderName);
- OString aFragmentShaderSource = loadShader(rFragmentShaderName);
+ OString aVertexShaderSource = getShaderSource(rVertexShaderName);
+ OString aFragmentShaderSource = getShaderSource(rFragmentShaderName);
GLint bBinaryResult = GL_FALSE;
if( GLEW_ARB_get_program_binary && !rDigest.isEmpty() )