summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-10-29 22:30:55 +0100
committerMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-11-10 07:58:51 +0100
commit8bb1fb8cd100ae33eb7bdf1f483c88bf098999af (patch)
treee36b5218ed2305d573f72f2fed1247163baacaa2 /vcl
parent80533fb4e03ef8c01125571a7dcc8da55aebf67d (diff)
extract shaders from source code
Conflicts: vcl/opengl/gdiimpl.cxx Change-Id: Ifbb55e58e0854cc491703b8ca8d8e582741a9bd9
Diffstat (limited to 'vcl')
-rw-r--r--vcl/Module_vcl.mk1
-rw-r--r--vcl/Package_opengl.mk23
-rw-r--r--vcl/inc/openglgdiimpl.hxx2
-rw-r--r--vcl/opengl/gdiimpl.cxx155
-rw-r--r--vcl/opengl/maskFragmentShader.glsl21
-rw-r--r--vcl/opengl/maskVertexShader.glsl19
-rw-r--r--vcl/opengl/maskedTextureFragmentShader.glsl22
-rw-r--r--vcl/opengl/maskedTextureVertexShader.glsl19
-rw-r--r--vcl/opengl/solidFragmentShader.glsl17
-rw-r--r--vcl/opengl/solidVertexShader.glsl16
-rw-r--r--vcl/opengl/textureFragmentShader.glsl18
-rw-r--r--vcl/opengl/textureVertexShader.glsl19
12 files changed, 182 insertions, 150 deletions
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 693c625e8269..f61cc7b59ba0 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -22,6 +22,7 @@ $(eval $(call gb_Module_Module,vcl))
$(eval $(call gb_Module_add_targets,vcl,\
CustomTarget_afm_hash \
Library_vcl \
+ Package_opengl \
$(if $(filter DESKTOP,$(BUILD_TYPE)), \
StaticLibrary_vclmain \
Executable_ui-previewer \
diff --git a/vcl/Package_opengl.mk b/vcl/Package_opengl.mk
new file mode 100644
index 000000000000..9b8f745ded66
--- /dev/null
+++ b/vcl/Package_opengl.mk
@@ -0,0 +1,23 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Package_Package,vcl_opengl_shader,$(SRCDIR)/vcl/opengl))
+
+$(eval $(call gb_Package_add_files,vcl_opengl_shader,$(LIBO_ETC_FOLDER)/opengl,\
+ maskFragmentShader.glsl \
+ maskVertexShader.glsl \
+ maskedTextureFragmentShader.glsl \
+ maskedTextureVertexShader.glsl \
+ solidFragmentShader.glsl \
+ solidVertexShader.glsl \
+ textureFragmentShader.glsl \
+ textureVertexShader.glsl \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index d3ee9ef3e8fe..d6f35fd38fd7 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -50,8 +50,6 @@ private:
GLuint mnMaskUniform;
GLuint mnMaskColorUniform;
- GLuint CompileShader( GLenum nType, const char *aSrc );
- GLuint CreateProgram( const char *aVertShaderSrc, const char *aFragShaderSrc );
bool CreateSolidProgram( void );
bool CreateTextureProgram( void );
bool CreateMaskedTextureProgram( void );
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index f59584aab56c..ef49d0355f15 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -23,6 +23,8 @@
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/polygon/b2dpolygontriangulator.hxx>
+#include <vcl/opengl/OpenGLHelper.hxx>
+
#define GL_ATTRIB_POS 0
#define GL_ATTRIB_TEX 1
@@ -136,99 +138,9 @@ void OpenGLSalGraphicsImpl::SetROPFillColor( SalROPColor /*nROPColor*/ )
{
}
-GLuint OpenGLSalGraphicsImpl::CompileShader( GLenum nType, const char *aSrc )
-{
- GLint nStatus;
- GLuint nShader;
- GLint nLogLen( 0 );
- char *aLog( NULL );
-
- nShader = glCreateShader( nType );
- glShaderSource( nShader, 1, (const GLchar **) &aSrc, NULL );
- glCompileShader( nShader );
- glGetShaderiv( nShader, GL_COMPILE_STATUS, &nStatus );
- if( nStatus )
- return nShader;
-
- glGetShaderiv( nShader, GL_INFO_LOG_LENGTH, &nLogLen );
- if( nLogLen > 1 )
- aLog = new char[nLogLen];
- if( aLog )
- glGetShaderInfoLog( nShader, nLogLen, NULL, aLog );
-
- SAL_WARN( "vcl.opengl", "::CompileShader failed: " << aLog );
-
- delete aLog;
- glDeleteShader( nShader );
-
- return 0;
-}
-
-GLuint OpenGLSalGraphicsImpl::CreateProgram( const char *aVertShaderSrc, const char *aFragShaderSrc )
-{
- GLuint nProgram;
- GLuint nVertShader, nFragShader;
- GLint nStatus;
-
- nVertShader = CompileShader( GL_VERTEX_SHADER, aVertShaderSrc );
- nFragShader = CompileShader( GL_FRAGMENT_SHADER, aFragShaderSrc );
- if( !nVertShader || !nFragShader )
- {
- SAL_WARN( "vcl.opengl", "::CreateProgram couldn't compile the shaders" );
- return 0;
- }
-
- nProgram = glCreateProgram();
- if( nProgram == 0 )
- {
- SAL_WARN( "vcl.opengl", "::CreateProgram couldn't create GL program" );
- return 0;
- }
-
- glAttachShader( nProgram, nVertShader );
- glAttachShader( nProgram, nFragShader );
- glLinkProgram( nProgram );
- glGetProgramiv( nProgram, GL_LINK_STATUS, &nStatus );
- if( !nStatus )
- {
- GLint nLogLen( 0 );
- char *aLog( NULL );
-
- glDeleteShader( nVertShader );
- glDeleteShader( nFragShader );
-
- glGetProgramiv( nProgram, GL_INFO_LOG_LENGTH, &nLogLen );
- if( nLogLen > 0 )
- aLog = new char[nLogLen];
- if( aLog )
- glGetProgramInfoLog( nProgram, nLogLen, NULL, aLog );
-
- SAL_WARN( "vcl.opengl", "::CreateSolidShader couldn't link program: " << aLog );
- delete aLog;
-
- return 0;
- }
-
- maShaders.push_back( nVertShader );
- maShaders.push_back( nFragShader );
- return nProgram;
-}
-
bool OpenGLSalGraphicsImpl::CreateSolidProgram( void )
{
- static const char aVertShaderSrc[] =
- "attribute vec4 position;\n"
- "void main() {\n"
- " gl_Position = position;\n"
- "}\n";
- static const char aFragShaderSrc[] =
- "precision mediump float;\n"
- "uniform vec4 color;\n"
- "void main() {\n"
- " gl_FragColor = color;\n"
- "}\n";
-
- mnSolidProgram = CreateProgram( aVertShaderSrc, aFragShaderSrc );
+ mnSolidProgram = OpenGLHelper::LoadShaders( "solidVertexShader", "solidFragmentShader" );
if( mnSolidProgram == 0 )
return false;
@@ -239,23 +151,9 @@ bool OpenGLSalGraphicsImpl::CreateSolidProgram( void )
bool OpenGLSalGraphicsImpl::CreateTextureProgram( void )
{
- static const char aVertShaderSrc[] =
- "attribute vec4 position;\n"
- "attribute vec2 tex_coord_in;\n"
- "varying vec2 tex_coord;\n"
- "void main() {\n"
- " gl_Position = position;\n"
- " tex_coord = tex_coord_in;\n"
- "}\n";
static const char aFragShaderSrc[] =
- "precision mediump float;\n"
- "varying vec2 tex_coord;\n"
- "uniform sampler2D sampler;\n"
- "void main() {\n"
- " gl_FragColor = texture2D(sampler, tex_coord);\n"
- "}\n";
-
- mnTextureProgram = CreateProgram( aVertShaderSrc, aFragShaderSrc );
+
+ mnTextureProgram = OpenGLHelper::( "textureVertexShader", "textureFragmentShader" );
if( mnTextureProgram == 0 )
return false;
@@ -267,27 +165,7 @@ bool OpenGLSalGraphicsImpl::CreateTextureProgram( void )
bool OpenGLSalGraphicsImpl::CreateMaskedTextureProgram( void )
{
- static const char aVertShaderSrc[] =
- "attribute vec4 position;\n"
- "attribute vec2 tex_coord_in;\n"
- "varying vec2 tex_coord;\n"
- "void main() {\n"
- " gl_Position = position;\n"
- " tex_coord = tex_coord_in;\n"
- "}\n";
- static const char aFragShaderSrc[] =
- "precision mediump float;\n"
- "varying vec2 tex_coord;\n"
- "uniform sampler2D sampler;\n"
- "uniform sampler2D mask;\n"
- "void main() {\n"
- " vec4 texel0, texel1;\n"
- " texel0 = texture2D(sampler, tex_coord);\n"
- " texel1 = texture2D(mask, tex_coord);\n"
- " gl_FragColor = texel0 * texel1.a;\n"
- "}\n";
-
- mnMaskedTextureProgram = CreateProgram( aVertShaderSrc, aFragShaderSrc );
+ mnMaskedTextureProgram = OpenGLHelper::LoadShaders( "maskedTextureVertexShader", "maskedTextureFragmentShader" );
if( mnMaskedTextureProgram == 0 )
return false;
@@ -300,26 +178,7 @@ bool OpenGLSalGraphicsImpl::CreateMaskedTextureProgram( void )
bool OpenGLSalGraphicsImpl::CreateMaskProgram( void )
{
- static const char aVertShaderSrc[] =
- "attribute vec4 position;\n"
- "attribute vec2 tex_coord_in;\n"
- "varying vec2 tex_coord;\n"
- "void main() {\n"
- " gl_Position = position;\n"
- " tex_coord = tex_coord_in;\n"
- "}\n";
- static const char aFragShaderSrc[] =
- "precision mediump float;\n"
- "varying vec2 tex_coord;\n"
- "uniform sampler2D sampler;\n"
- "uniform vec4 color;\n"
- "void main() {\n"
- " vec4 texel0;\n"
- " texel0 = texture2D(sampler, tex_coord);\n"
- " gl_FragColor = color * texel0.a;\n"
- "}\n";
-
- mnMaskedTextureProgram = CreateProgram( aVertShaderSrc, aFragShaderSrc );
+ mnMaskedTextureProgram = OpenGLHelper::LoadShaders( "maskVertexShader", "maskFragmentShader" );
if( mnMaskedTextureProgram == 0 )
return false;
diff --git a/vcl/opengl/maskFragmentShader.glsl b/vcl/opengl/maskFragmentShader.glsl
new file mode 100644
index 000000000000..35ecbd0c8df3
--- /dev/null
+++ b/vcl/opengl/maskFragmentShader.glsl
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+precision mediump float;
+varying vec2 tex_coord;
+uniform sampler2D sampler;
+uniform vec4 color;"
+
+void main() {
+ vec4 texel0;
+ texel0 = texture2D(sampler, tex_coord);
+ gl_FragColor = color * texel0.a;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/maskVertexShader.glsl b/vcl/opengl/maskVertexShader.glsl
new file mode 100644
index 000000000000..303ddececed2
--- /dev/null
+++ b/vcl/opengl/maskVertexShader.glsl
@@ -0,0 +1,19 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+attribute vec4 position;
+attribute vec2 tex_coord_in;
+varying vec2 tex_coord;
+
+void main() {
+ gl_Position = position;
+ tex_coord = tex_coord_in;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/maskedTextureFragmentShader.glsl b/vcl/opengl/maskedTextureFragmentShader.glsl
new file mode 100644
index 000000000000..5353250aa3c5
--- /dev/null
+++ b/vcl/opengl/maskedTextureFragmentShader.glsl
@@ -0,0 +1,22 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+precision mediump float;
+varying vec2 tex_coord;
+uniform sampler2D sampler;
+uniform sampler2D mask;
+
+void main() {
+ vec4 texel0, texel1;
+ texel0 = texture2D(sampler, tex_coord);
+ texel1 = texture2D(mask, tex_coord);
+ gl_FragColor = texel0 * texel1.a;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/maskedTextureVertexShader.glsl b/vcl/opengl/maskedTextureVertexShader.glsl
new file mode 100644
index 000000000000..303ddececed2
--- /dev/null
+++ b/vcl/opengl/maskedTextureVertexShader.glsl
@@ -0,0 +1,19 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+attribute vec4 position;
+attribute vec2 tex_coord_in;
+varying vec2 tex_coord;
+
+void main() {
+ gl_Position = position;
+ tex_coord = tex_coord_in;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/solidFragmentShader.glsl b/vcl/opengl/solidFragmentShader.glsl
new file mode 100644
index 000000000000..917cafce7a37
--- /dev/null
+++ b/vcl/opengl/solidFragmentShader.glsl
@@ -0,0 +1,17 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+precision mediump float;
+
+uniform vec4 color;
+void main() {
+ gl_FragColor = color;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/solidVertexShader.glsl b/vcl/opengl/solidVertexShader.glsl
new file mode 100644
index 000000000000..c3de9c57f349
--- /dev/null
+++ b/vcl/opengl/solidVertexShader.glsl
@@ -0,0 +1,16 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+attribute vec4 position;
+void main() {
+ gl_Position = position;
+};
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/textureFragmentShader.glsl b/vcl/opengl/textureFragmentShader.glsl
new file mode 100644
index 000000000000..eb510d80eb09
--- /dev/null
+++ b/vcl/opengl/textureFragmentShader.glsl
@@ -0,0 +1,18 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+precision mediump float;
+varying vec2 tex_coord;
+uniform sampler2D sampler;
+
+void main() {
+ gl_FragColor = texture2D(sampler, tex_coord);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/textureVertexShader.glsl b/vcl/opengl/textureVertexShader.glsl
new file mode 100644
index 000000000000..303ddececed2
--- /dev/null
+++ b/vcl/opengl/textureVertexShader.glsl
@@ -0,0 +1,19 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+attribute vec4 position;
+attribute vec2 tex_coord_in;
+varying vec2 tex_coord;
+
+void main() {
+ gl_Position = position;
+ tex_coord = tex_coord_in;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */