[Libreoffice-commits] core.git: Branch 'feature/opengl-canvas-rework' - canvas/opengl canvas/source
Michael Jaumann
meta_dev at yahoo.com
Mon Oct 20 05:59:55 PDT 2014
canvas/opengl/textFragmentShader.glsl | 5 +++--
canvas/source/opengl/ogl_canvascustomsprite.cxx | 23 +++++++++++++++++++++--
canvas/source/opengl/ogl_canvascustomsprite.hxx | 20 +++++++++++++-------
3 files changed, 37 insertions(+), 11 deletions(-)
New commits:
commit 5943fdb3dfa10268699cd55ea79aee5d1ca156fb
Author: Michael Jaumann <meta_dev at yahoo.com>
Date: Mon Oct 20 12:14:42 2014 +0000
reformating, alpha blending now in fragment shader
Change-Id: I9f1d707e2434712efb9e3e346ecf50aa9c539d5b
diff --git a/canvas/opengl/textFragmentShader.glsl b/canvas/opengl/textFragmentShader.glsl
index b1589c6..32a0423e 100644
--- a/canvas/opengl/textFragmentShader.glsl
+++ b/canvas/opengl/textFragmentShader.glsl
@@ -9,13 +9,14 @@
#version 120 core
-uniform sampler2D TextTex;
+uniform sampler2D TextTex;
+uniform vec4 colorTex;
//Texture Coordinates
varying vec2 textC oords;
void main()
{
- gl_FragColor = texture2D( TextTex, textCoords );
+ gl_FragColor = texture2D( TextTex, textCoords )*colorTex;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/canvas/source/opengl/ogl_canvascustomsprite.cxx b/canvas/source/opengl/ogl_canvascustomsprite.cxx
index cc04907..bf5f347 100644
--- a/canvas/source/opengl/ogl_canvascustomsprite.cxx
+++ b/canvas/source/opengl/ogl_canvascustomsprite.cxx
@@ -142,6 +142,8 @@ namespace oglcanvas
m_simpleTexUnf = glGetUniformLocation(m_simpleProgID, "TextTex");
m_manCordUnf = glGetUniformLocation(m_texManProgID, "texCord");
m_texColorUnf = glGetUniformLocation(m_texProgID, "constantColor");
+ m_manColorUnf = glGetUniformLocation(m_texManProgID,"colorTex");
+ m_simpleColorUnf = glGetUniformLocation(m_simpleProgID,"colorTex");
//Gen Buffers for texturecoordinates/vertices
glGenBuffers(1, &m_vertexBuffer);
glGenBuffers(1, &m_uvBuffer);
@@ -212,8 +214,6 @@ namespace oglcanvas
GL_ONE_MINUS_SRC_ALPHA);
// blend against fixed vertex color; texture alpha is multiplied in
- glColor4f(1,1,1,mfAlpha);
-
if( mxClip.is() )
{
const double fWidth=maSize.Width;
@@ -243,10 +243,14 @@ namespace oglcanvas
//Bind Buffers
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+
glUseProgram(m_texManProgID);
+
//Set Uniforms
glUniform1i(m_manTexUnf, 0);
glUniform2f(m_manCordUnf,fWidth,fHeight);
+ glUniform4f(m_manColorUnf, 1, 1, 1, mfAlpha);
+
glEnableVertexAttribArray(m_manPosAttrb);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glVertexAttribPointer(
@@ -257,7 +261,9 @@ namespace oglcanvas
0, // stride
(void*)0 // array buffer offset
);
+
glDrawArrays(GL_TRIANGLES, 0, rTriangulatedPolygon.count());
+
glDisableVertexAttribArray(m_manPosAttrb);
glUseProgram(0);
}
@@ -265,6 +271,7 @@ namespace oglcanvas
{
const double fWidth=maSize.Width/aSpriteSizePixel.getX();
const double fHeight=maSize.Height/aSpriteSizePixel.getY();
+
GLfloat vertices[] = {0, 0,
0, (float) aSpriteSizePixel.getY(),
(float) aSpriteSizePixel.getX(), 0,
@@ -273,13 +280,17 @@ namespace oglcanvas
0, (float) fHeight,
(float) fWidth, 0,
(float) fWidth, (float) fHeight };
+
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+
glBindBuffer(GL_ARRAY_BUFFER, m_uvBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(uvCoordinates), uvCoordinates, GL_STATIC_DRAW);
glUseProgram(m_simpleProgID);
+
glUniform1i(m_simpleTexUnf, 0);
+ glUniform4f(m_simpleColorUnf, 1, 1, 1, mfAlpha);
glEnableVertexAttribArray(m_simplePosAttrb); //richtige ID herausfinden
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
@@ -302,7 +313,9 @@ namespace oglcanvas
0, // stride
(void*)0 // array buffer offset
);
+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
glDisableVertexAttribArray(m_simplePosAttrb);
glDisableVertexAttribArray(m_simpleUvAttrb);
glUseProgram(0);
@@ -318,11 +331,15 @@ namespace oglcanvas
(float) maSize.Width+4, -2,
-2, -2,
(float) maSize.Width+4, (float) maSize.Height+4 };
+
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+
glUseProgram(m_texProgID);
+
glUniform4f(m_texColorUnf, 1, 0, 0, 1);
glEnableVertexAttribArray(m_texPosAttrb); //richtige ID herausfinden
+
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glVertexAttribPointer(
m_texPosAttrb,
@@ -332,7 +349,9 @@ namespace oglcanvas
0, // stride
(void*)0 // array buffer offset
);
+
glDrawArrays(GL_LINE_STRIP, 0, 6);
+
glDisableVertexAttribArray(m_texPosAttrb);
glUseProgram(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
diff --git a/canvas/source/opengl/ogl_canvascustomsprite.hxx b/canvas/source/opengl/ogl_canvascustomsprite.hxx
index f08af7e..46b59fe 100644
--- a/canvas/source/opengl/ogl_canvascustomsprite.hxx
+++ b/canvas/source/opengl/ogl_canvascustomsprite.hxx
@@ -92,20 +92,26 @@ namespace oglcanvas
::basegfx::B2DPoint maPosition;
double mfAlpha;
double mfPriority;
+
GLuint m_vertexBuffer;
GLuint m_uvBuffer;
- GLuint m_texManProgID;
- GLuint m_texProgID;
+
+
GLuint m_simpleProgID;
- GLuint m_manTexUnf;
- GLuint m_manPosAttrb;
GLuint m_simpleUvAttrb;
GLuint m_simplePosAttrb;
- GLuint m_texPosAttrb;
- GLuint m_manCordUnf;
- GLuint m_texColorUnf;
GLuint m_simpleTexUnf;
+ GLuint m_simpleColorUnf;
+
+ GLuint m_manTexUnf;
+ GLuint m_manPosAttrb;
+ GLuint m_manCordUnf;
+ GLuint m_manColorUnf;
+ GLuint m_texPosAttrb;
+ GLuint m_texColorUnf;
+ GLuint m_texManProgID;
+ GLuint m_texProgID;
};
}
More information about the Libreoffice-commits
mailing list