vcl/Module_vcl.mk | 1 vcl/Package_opengl.mk | 23 ++++ vcl/inc/openglgdiimpl.hxx | 2 vcl/opengl/gdiimpl.cxx | 155 +--------------------------- vcl/opengl/maskFragmentShader.glsl | 21 +++ vcl/opengl/maskVertexShader.glsl | 19 +++ vcl/opengl/maskedTextureFragmentShader.glsl | 22 +++ vcl/opengl/maskedTextureVertexShader.glsl | 19 +++ vcl/opengl/solidFragmentShader.glsl | 17 +++ vcl/opengl/solidVertexShader.glsl | 16 ++ vcl/opengl/textureFragmentShader.glsl | 18 +++ vcl/opengl/textureVertexShader.glsl | 19 +++ 12 files changed, 182 insertions(+), 150 deletions(-)
New commits: commit 72d049a945e4239533f370630ef8688a3cfd07cf Author: Markus Mohrhard <markus.mohrh...@collabora.co.uk> Date: Wed Oct 29 22:30:55 2014 +0100 extract shaders from source code Conflicts: vcl/opengl/gdiimpl.cxx Change-Id: Ifbb55e58e0854cc491703b8ca8d8e582741a9bd9 diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk index 693c625..f61cc7b 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 0000000..9b8f745 --- /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 2d91419..40d3f9d 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 32187b6..02bba63 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -22,6 +22,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 @@ -135,99 +137,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; @@ -238,23 +150,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; @@ -266,27 +164,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; @@ -299,26 +177,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 0000000..35ecbd0 --- /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 0000000..303ddec --- /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 0000000..5353250 --- /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 0000000..303ddec --- /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 0000000..917cafc --- /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 0000000..c3de9c5 --- /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 0000000..eb510d8 --- /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 0000000..303ddec --- /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: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits