LibreOffice Module vcl (master)  1
program.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef INCLUDED_VCL_INC_OPENGL_PROGRAM_H
11 #define INCLUDED_VCL_INC_OPENGL_PROGRAM_H
12 
13 #include <sal/config.h>
14 
15 #include <vector>
16 
17 #include <vcl/dllapi.h>
18 
20 #include <rtl/ustring.hxx>
21 #include <opengl/texture.hxx>
22 
23 #include <unordered_map>
24 
25 class Color;
26 
28 {
29  Normal = 0,
30  Blend,
31  Masked,
32  Diff,
34 };
35 
36 enum class DrawShaderType
37 {
38  Normal = 0,
39  Line
40 };
41 
43 {
44 private:
45  GLuint mnId;
46  std::unordered_map< OString, GLuint >
48  sal_uInt32 mnEnabledAttribs;
55 
56  std::vector< OpenGLTexture > maTextures;
57  bool mbBlending;
58 
59  float mfLastWidth;
60  float mfLastHeight;
62 
63 
64  OpenGLProgram(const OpenGLProgram &) = delete;
65 public:
66  OpenGLProgram();
68 
69  GLuint Id() { return mnId; }
70 
71  bool Load( const OUString& rVertexShader, const OUString& rFragmentShader,
72  const OString& preamble, const OString& rDigest );
73  void Use();
74  void Reuse();
75  void Clean();
76 
77  void SetVertices( const GLvoid* pData );
78  void SetTextureCoord( const GLvoid* pData );
79  void SetAlphaCoord( const GLvoid* pData );
80  void SetMaskCoord(const GLvoid* pData);
81  void SetExtrusionVectors(const GLvoid* pData);
82  void SetVertexColors(std::vector<GLubyte>& rColorVector);
83 
84  void SetUniform1f( const OString& rName, GLfloat v1 );
85  void SetUniform2f( const OString& rName, GLfloat v1, GLfloat v2 );
86  void SetUniform1fv( const OString& rName, GLsizei nCount, GLfloat const * aValues );
87  void SetUniform2fv( const OString& rName, GLsizei nCount, GLfloat const * aValues );
88  void SetUniform1i( const OString& rName, GLint v1 );
89  void SetColor( const OString& rName, const Color& rColor );
90  void SetColor( const OString& rName, Color nColor, sal_uInt8 nTransparency );
91  void SetColorf( const OString& rName, Color nColor, double fTransparency );
92  void SetColorWithIntensity( const OString& rName, const Color& rColor, long nFactor );
93  void SetTexture( const OString& rName, OpenGLTexture& rTexture );
94  void SetTransform( const OString& rName, const OpenGLTexture& rTexture,
95  const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX,
96  const basegfx::B2DPoint& rY );
97  void SetIdentityTransform(const OString& rName);
98  void SetShaderType(TextureShaderType eTextureShaderType);
99  void SetShaderType(DrawShaderType eDrawShaderType);
100 
101  void SetBlendMode( GLenum nSFactor, GLenum nDFactor );
102 
103  void ApplyMatrix(float fWidth, float fHeight, float fPixelOffset = 0.0f);
104 
105  void DrawTexture( const OpenGLTexture& rTexture );
106 
107  void DrawArrays(GLenum aMode, std::vector<GLfloat>& aVertices);
108  void DrawElements(GLenum aMode, GLuint nNumberOfVertices);
109 
110  bool EnableVertexAttrib(GLuint& rAttrib, const OString& rName);
111 
112  void SetVertexAttrib(GLuint& rAttrib, const OString& rName, GLint nSize,
113  GLenum eType, GLboolean bNormalized, GLsizei aStride,
114  const GLvoid* pPointer);
115 
116 private:
117  GLuint GetUniformLocation( const OString& rName );
118 };
119 
120 #endif // INCLUDED_VCL_INC_OPENGL_PROGRAM_H
121 
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
GLuint mnId
Definition: program.hxx:45
GLuint mnPositionAttrib
Definition: program.hxx:49
DrawShaderType
Definition: program.hxx:36
bool Load(const OUString &rVertexShader, const OUString &rFragmentShader, const OString &preamble, const OString &rDigest)
GLuint mnAlphaCoordAttrib
Definition: program.hxx:51
void SetVertexColors(std::vector< GLubyte > &rColorVector)
void SetVertexAttrib(GLuint &rAttrib, const OString &rName, GLint nSize, GLenum eType, GLboolean bNormalized, GLsizei aStride, const GLvoid *pPointer)
float mfLastPixelOffset
Definition: program.hxx:61
sal_uInt32 mnEnabledAttribs
Definition: program.hxx:48
float mfLastHeight
Definition: program.hxx:60
GLuint mnMaskCoordAttrib
Definition: program.hxx:52
void SetColor(const OString &rName, const Color &rColor)
void SetVertices(const GLvoid *pData)
void SetAlphaCoord(const GLvoid *pData)
void SetColorf(const OString &rName, Color nColor, double fTransparency)
void SetUniform1i(const OString &rName, GLint v1)
void DrawTexture(const OpenGLTexture &rTexture)
void SetTexture(const OString &rName, OpenGLTexture &rTexture)
void SetUniform2fv(const OString &rName, GLsizei nCount, GLfloat const *aValues)
void SetMaskCoord(const GLvoid *pData)
bool EnableVertexAttrib(GLuint &rAttrib, const OString &rName)
void SetUniform1fv(const OString &rName, GLsizei nCount, GLfloat const *aValues)
void SetExtrusionVectors(const GLvoid *pData)
void SetTextureCoord(const GLvoid *pData)
void SetTransform(const OString &rName, const OpenGLTexture &rTexture, const basegfx::B2DPoint &rNull, const basegfx::B2DPoint &rX, const basegfx::B2DPoint &rY)
void SetUniform2f(const OString &rName, GLfloat v1, GLfloat v2)
void SetIdentityTransform(const OString &rName)
void SetColorWithIntensity(const OString &rName, const Color &rColor, long nFactor)
GLuint mnTexCoordAttrib
Definition: program.hxx:50
void SetBlendMode(GLenum nSFactor, GLenum nDFactor)
GLuint GetUniformLocation(const OString &rName)
void SetUniform1f(const OString &rName, GLfloat v1)
GLuint mnVertexColorsAttrib
Definition: program.hxx:54
TextureShaderType
Definition: program.hxx:27
float mfLastWidth
Definition: program.hxx:59
unsigned char sal_uInt8
std::unordered_map< OString, GLuint > maUniformLocations
Definition: program.hxx:47
GLuint mnExtrusionVectorsAttrib
Definition: program.hxx:53
bool mbBlending
Definition: program.hxx:57
void SetShaderType(TextureShaderType eTextureShaderType)
void DrawElements(GLenum aMode, GLuint nNumberOfVertices)
void ApplyMatrix(float fWidth, float fHeight, float fPixelOffset=0.0f)
std::vector< OpenGLTexture > maTextures
Definition: program.hxx:56
void(* f)(TrueTypeTable *)
Definition: ttcr.cxx:466
void DrawArrays(GLenum aMode, std::vector< GLfloat > &aVertices)
GLuint Id()
Definition: program.hxx:69