[Libreoffice-commits] core.git: vcl/source

Chris Sherlock chris.sherlock at collabora.com
Thu Jan 29 19:04:06 PST 2015


 vcl/source/opengl/OpenGLHelper.cxx |   33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

New commits:
commit a2b94b95626da1a1e6bd91e9f64cb3025962e770
Author: Chris Sherlock <chris.sherlock at collabora.com>
Date:   Fri Jan 30 01:34:17 2015 +1100

    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 at gmail.com>
    Tested-by: Chris Sherlock <chris.sherlock79 at gmail.com>

diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 3523ae2..a574366 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);


More information about the Libreoffice-commits mailing list