summaryrefslogtreecommitdiffstats
path: root/vcl
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock@collabora.com>2015-01-30 01:34:17 +1100
committerChris Sherlock <chris.sherlock79@gmail.com>2015-01-30 03:03:46 +0000
commita2b94b95626da1a1e6bd91e9f64cb3025962e770 (patch)
tree872b782265c1e3a5bfbbe7129f17045aa43f04ca /vcl
parentcallcatcher: large newly detected unused methods post de-virtualization (diff)
downloadcore-a2b94b95626da1a1e6bd91e9f64cb3025962e770.tar.gz
core-a2b94b95626da1a1e6bd91e9f64cb3025962e770.zip
vcl: OpenGL code for adding preambles to glsl fragments now handles #version
If you include the #version directive then it must be on the first non-comment line in a glsl fragment. This is now handled. Change-Id: I7e938c27b24d20f25e656667a122d7a341f51611 Reviewed-on: https://gerrit.libreoffice.org/14246 Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com> Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/opengl/OpenGLHelper.cxx33
1 files changed, 31 insertions, 2 deletions
diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 3523ae231f14..a574366ef375 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -97,6 +97,35 @@ namespace {
}
}
+static void addPreamble(OString& rShaderSource, const OString& rPreamble)
+{
+ if (rPreamble.isEmpty())
+ return;
+
+ OString aVersionStr("#version");
+ int nVersionStrStartPos = rShaderSource.indexOf(aVersionStr, 0);
+
+ if (nVersionStrStartPos == -1)
+ {
+ rShaderSource = rPreamble + "\n" + rShaderSource;
+ }
+ else
+ {
+ int nVersionStrEndPos = rShaderSource.indexOf('\n', nVersionStrStartPos);
+
+ // no way this should happen - if this is the case, then it's a syntax error
+ assert(nVersionStrEndPos != -1);
+
+ if (nVersionStrEndPos == -1)
+ nVersionStrEndPos = nVersionStrStartPos + 8;
+
+ OString aVersionLine = rShaderSource.copy(0, nVersionStrEndPos - nVersionStrStartPos);
+ OString aShaderBody = rShaderSource.copy(nVersionStrEndPos - nVersionStrStartPos);
+
+ rShaderSource = aVersionLine + "\n" + rPreamble + "\n" + aShaderBody;
+ }
+}
+
GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,const OUString& rFragmentShaderName, const OString& preamble)
{
// Create the shaders
@@ -108,7 +137,7 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,const OUString
// Compile Vertex Shader
OString aVertexShaderSource = loadShader(rVertexShaderName);
if( !preamble.isEmpty())
- aVertexShaderSource = preamble + "\n" + aVertexShaderSource;
+ addPreamble( aVertexShaderSource, preamble );
char const * VertexSourcePointer = aVertexShaderSource.getStr();
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
glCompileShader(VertexShaderID);
@@ -122,7 +151,7 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,const OUString
// Compile Fragment Shader
OString aFragmentShaderSource = loadShader(rFragmentShaderName);
if( !preamble.isEmpty())
- aFragmentShaderSource = preamble + "\n" + aFragmentShaderSource;
+ addPreamble( aFragmentShaderSource, preamble );
char const * FragmentSourcePointer = aFragmentShaderSource.getStr();
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
glCompileShader(FragmentShaderID);