diff options
author | Louis-Francis Ratté-Boulianne <lfrb@collabora.com> | 2014-11-28 14:56:08 -0500 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2014-12-02 11:58:45 +0100 |
commit | 99ade27b04d3d492648eadb620cda8ea9909bf45 (patch) | |
tree | 45a9221e508acc90e73db3ad998eeaa819099686 /vcl/inc | |
parent | 0d4233ef90a4350d63da0c9d1b98ced64b773ce0 (diff) |
vcl: Only load OpenGL shaders once for each context
Change-Id: Idbf9026c5e64ef41d4c913153dfddf36923ff7de
Diffstat (limited to 'vcl/inc')
-rw-r--r-- | vcl/inc/opengl/program.hxx | 72 | ||||
-rw-r--r-- | vcl/inc/opengl/salbmp.hxx | 11 | ||||
-rw-r--r-- | vcl/inc/opengl/texture.hxx | 1 | ||||
-rw-r--r-- | vcl/inc/openglgdiimpl.hxx | 67 |
4 files changed, 80 insertions, 71 deletions
diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx new file mode 100644 index 000000000000..4b2b26ffb95e --- /dev/null +++ b/vcl/inc/opengl/program.hxx @@ -0,0 +1,72 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_VCL_INC_OPENGL_PROGRAM_H +#define INCLUDED_VCL_INC_OPENGL_PROGRAM_H + +#include <GL/glew.h> +#include <vcl/dllapi.h> + +#include <basegfx/point/b2dpoint.hxx> +#include <rtl/ustring.hxx> +#include <tools/color.hxx> +#include <opengl/texture.hxx> + +#include <boost/unordered_map.hpp> + +typedef boost::unordered_map< OString, GLuint, OStringHash > UniformCache; +typedef std::list< OpenGLTexture > TextureList; + +class VCL_PLUGIN_PUBLIC OpenGLProgram +{ +private: + GLuint mnId; + UniformCache maUniformLocations; + sal_uInt32 mnEnabledAttribs; + GLuint mnAttribIndex; + GLuint mnPositionAttrib; + GLuint mnTexCoordAttrib; + GLuint mnAlphaCoordAttrib; + TextureList maTextures; + bool mbBlending; + +public: + OpenGLProgram(); + ~OpenGLProgram(); + + bool Load( const OUString& rVertexShader, const OUString& rFragmentShader ); + bool Use(); + bool Clean(); + + void SetVertices( const GLvoid* pData ); + void SetTextureCoord( const GLvoid* pData ); + void SetAlphaCoord( const GLvoid* pData ); + + void SetUniform2f( const OString& rName, GLfloat v1, GLfloat v2 ); + void SetUniform1fv( const OString& rName, GLsizei nCount, GLfloat* aValues ); + void SetUniform2fv( const OString& rName, GLsizei nCount, GLfloat* aValues ); + void SetColor( const OString& rName, SalColor nColor, sal_uInt8 nTransparency ); + void SetColorf( const OString& rName, SalColor nColor, double fTransparency ); + void SetColorWithIntensity( const OString& rName, const Color& rColor, long nFactor ); + void SetTexture( const OString& rName, OpenGLTexture& rTexture ); + void SetTransform( const OString& rName, const OpenGLTexture& rTexture, + const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, + const basegfx::B2DPoint& rY ); + void SetBlendMode( GLenum nSFactor, GLenum nDFactor ); + + bool DrawTexture( OpenGLTexture& rTexture ); + +protected: + void SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData ); + GLuint GetUniformLocation( const OString& rName ); +}; + +#endif // INCLUDED_VCL_INC_OPENGL_PROGRAM_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx index bc232b123380..6938a22a1846 100644 --- a/vcl/inc/opengl/salbmp.hxx +++ b/vcl/inc/opengl/salbmp.hxx @@ -99,17 +99,6 @@ private: private: - GLuint ImplGetTextureProgram(); - GLuint mnTexProgram; - GLuint mnTexSamplerUniform; - - GLuint ImplGetConvolutionProgram(); - GLuint mnConvProgram; - GLuint mnConvSamplerUniform; - GLuint mnConvKernelUniform; - GLuint mnConvKernelSizeUniform; - GLuint mnConvOffsetsUniform; - bool ImplScaleFilter( const double& rScaleX, const double& rScaleY, GLenum nFilter ); void ImplCreateKernel( const double& fScale, const Kernel& rKernel, GLfloat*& pWeights, sal_uInt32& aKernelSize ); bool ImplScaleConvolution( const double& rScaleX, const double& rScaleY, const Kernel& aKernel ); diff --git a/vcl/inc/opengl/texture.hxx b/vcl/inc/opengl/texture.hxx index ad4738a6948d..3d99526d2646 100644 --- a/vcl/inc/opengl/texture.hxx +++ b/vcl/inc/opengl/texture.hxx @@ -65,6 +65,7 @@ public: int GetWidth() const; int GetHeight() const; void GetCoord( GLfloat* pCoord, const SalTwoRect& rPosAry, bool bInverted=false ) const; + void GetWholeCoord( GLfloat* pCoord ) const; void Bind(); void Unbind(); diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx index 39e39fc77752..3f3ef4ed29a1 100644 --- a/vcl/inc/openglgdiimpl.hxx +++ b/vcl/inc/openglgdiimpl.hxx @@ -25,6 +25,7 @@ #include <vcl/dllapi.h> #include "opengl/framebuffer.hxx" +#include "opengl/program.hxx" #include "opengl/texture.hxx" #include "regionband.hxx" @@ -44,6 +45,7 @@ protected: /// Pointer to the SalFrame or SalVirtualDevice SalGeometryProvider* mpParent; OpenGLFramebuffer* mpFramebuffer; + OpenGLProgram* mpProgram; // clipping vcl::Region maClipRegion; @@ -56,72 +58,17 @@ protected: SalColor mnLineColor; SalColor mnFillColor; - GLuint mnSolidProgram; - GLuint mnColorUniform; - - GLuint mnTextureProgram; - GLuint mnSamplerUniform; - - GLuint mnTransformedTextureProgram; - GLuint mnTransformedViewportUniform; - GLuint mnTransformedTransformUniform; - GLuint mnTransformedSamplerUniform; - - GLuint mnTransformedMaskedTextureProgram; - GLuint mnTransformedMaskedViewportUniform; - GLuint mnTransformedMaskedTransformUniform; - GLuint mnTransformedMaskedSamplerUniform; - GLuint mnTransformedMaskedMaskUniform; - - GLuint mnDiffTextureProgram; - GLuint mnDiffTextureUniform; - GLuint mnDiffMaskUniform; - - GLuint mnMaskedTextureProgram; - GLuint mnMaskedSamplerUniform; - GLuint mnMaskSamplerUniform; - - GLuint mnBlendedTextureProgram; - GLuint mnBlendedTextureUniform; - GLuint mnBlendedMaskUniform; - GLuint mnBlendedAlphaUniform; - - GLuint mnMaskProgram; - GLuint mnMaskUniform; - GLuint mnMaskColorUniform; - - GLuint mnLinearGradientProgram; - GLuint mnLinearGradientStartColorUniform; - GLuint mnLinearGradientEndColorUniform; - - GLuint mnRadialGradientProgram; - GLuint mnRadialGradientStartColorUniform; - GLuint mnRadialGradientEndColorUniform; - GLuint mnRadialGradientCenterUniform; - void ImplInitClipRegion(); void ImplSetClipBit( const vcl::Region& rClip, GLuint nMask ); bool CheckOffscreenTexture(); - bool CreateSolidProgram( void ); - bool CreateTextureProgram( void ); - bool CreateTransformedTextureProgram( void ); - bool CreateDiffTextureProgram( void ); - bool CreateMaskedTextureProgram( void ); - bool CreateBlendedTextureProgram( void ); - bool CreateTransformedMaskedTextureProgram( void ); - bool CreateMaskProgram( void ); - bool CreateLinearGradientProgram( void ); - bool CreateRadialGradientProgram( void ); - public: - void BeginSolid( SalColor nColor, sal_uInt8 nTransparency ); - void BeginSolid( SalColor nColor, double fTransparency ); - void BeginSolid( SalColor nColor ); - void EndSolid( void ); - void BeginInvert( void ); - void EndInvert( void ); + bool UseProgram( const OUString& rVertexShader, const OUString& rFragmentShader ); + bool UseSolid( SalColor nColor, sal_uInt8 nTransparency ); + bool UseSolid( SalColor nColor, double fTransparency ); + bool UseSolid( SalColor nColor ); + bool UseInvert(); void DrawPoint( long nX, long nY ); void DrawLine( long nX1, long nY1, long nX2, long nY2 ); |