Kaydet (Commit) 8bb1fb8c authored tarafından Markus Mohrhard's avatar Markus Mohrhard

extract shaders from source code

Conflicts:
	vcl/opengl/gdiimpl.cxx

Change-Id: Ifbb55e58e0854cc491703b8ca8d8e582741a9bd9
üst 80533fb4
......@@ -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 \
......
# -*- 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:
......@@ -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 );
......
......@@ -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;
......
/* -*- 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: */
/* -*- 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: */
/* -*- 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: */
/* -*- 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: */
/* -*- 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: */
/* -*- 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: */
/* -*- 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: */
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment