[Libreoffice-commits] core.git: Branch 'feature/opengl-canvas-rework' - 8 commits - canvas/opengl canvas/Package_opengl.mk canvas/source include/vcl
Michael Jaumann
meta_dev at yahoo.com
Tue Dec 2 02:11:16 PST 2014
canvas/Package_opengl.mk | 1
canvas/opengl/transformationFragmentShader.glsl | 24 ++++++++
canvas/source/opengl/ogl_canvashelper.cxx | 42 +++++++-------
canvas/source/opengl/ogl_canvastools.cxx | 64 ++++++++++++++++------
canvas/source/opengl/ogl_canvastools.hxx | 2
canvas/source/opengl/ogl_renderHelper.cxx | 68 +++++++++++++++++++-----
canvas/source/opengl/ogl_renderHelper.hxx | 10 +++
canvas/source/opengl/ogl_spritedevicehelper.cxx | 26 ++-------
include/vcl/opengl/OpenGLContext.hxx | 3 +
9 files changed, 170 insertions(+), 70 deletions(-)
New commits:
commit d81798535aba8c3f4686cb89eb2238d1df322c35
Author: Michael Jaumann <meta_dev at yahoo.com>
Date: Tue Dec 2 10:06:36 2014 +0000
texture transformation shader
New texture transformation shader.
Renderhelper uses it.
Draw texturedPolygon with it.
Change-Id: I285bf9cce0f216fd382a933d53b786238005f74f
diff --git a/canvas/Package_opengl.mk b/canvas/Package_opengl.mk
index 13c6cb3..7948fda 100644
--- a/canvas/Package_opengl.mk
+++ b/canvas/Package_opengl.mk
@@ -22,6 +22,7 @@ $(eval $(call gb_Package_add_files,canvas_opengl_shader,$(LIBO_ETC_FOLDER)/openg
textFragmentShader.glsl \
textManipulatingVertexShader.glsl \
texVertexShader.glsl \
+ transformationFragmentShader.glsl \
))
# vim: set noet sw=4 ts=4:
diff --git a/canvas/opengl/transformationFragmentShader.glsl b/canvas/opengl/transformationFragmentShader.glsl
new file mode 100644
index 0000000..1a72b10
--- /dev/null
+++ b/canvas/opengl/transformationFragmentShader.glsl
@@ -0,0 +1,24 @@
+/* -*- 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/.
+ */
+
+#version 120
+
+uniform sampler2D TextTex;
+uniform vec4 colorTex;
+uniform mat4 texTrans;
+//Texture Coordinates
+varying vec2 textCoords;
+
+void main()
+{
+ vec2 texCoord = (texTrans * vec4(textCoords, 0, 1)).xy;
+ gl_FragColor = texture2D( TextTex, texCoord )*colorTex;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/canvas/source/opengl/ogl_canvashelper.cxx b/canvas/source/opengl/ogl_canvashelper.cxx
index 5c9e916..34d1342 100644
--- a/canvas/source/opengl/ogl_canvashelper.cxx
+++ b/canvas/source/opengl/ogl_canvashelper.cxx
@@ -35,6 +35,7 @@
#include "ogl_tools.hxx"
#include <GL/glew.h>
+#include <glm/gtc/type_ptr.hpp>
#include <boost/scoped_array.hpp>
@@ -336,14 +337,11 @@ namespace oglcanvas
RenderHelper* pRenderHelper = rHelper.getDeviceHelper()->getRenderHelper();
pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
- glm::vec4 color = glm::vec4( (float) rendering::ARGBColor().Red,
- (float) rendering::ARGBColor().Green,
- (float) rendering::ARGBColor().Blue,
- (float) rendering::ARGBColor().Alpha);
-
+ //blend against fixed color
+ glm::vec4 color = glm::vec4(1,1,1,1);
const unsigned int nTexId=rHelper.getDeviceHelper()->getTextureCache().getTexture(
rPixelSize, rPixelData.getConstArray(), nPixelCrc32);
-
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, nTexId);
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D,
@@ -364,24 +362,24 @@ namespace oglcanvas
::basegfx::B2DRange aBounds;
::basegfx::B2DPolyPolygonVector::const_iterator aCurr=rPolyPolygons.begin();
const ::basegfx::B2DPolyPolygonVector::const_iterator aEnd=rPolyPolygons.end();
- /* while( aCurr != aEnd )
+ while( aCurr != aEnd )
aBounds.expand(::basegfx::tools::getRange(*aCurr++));
aTextureTransform.translate(-aBounds.getMinX(), -aBounds.getMinY());
aTextureTransform.scale(1/aBounds.getWidth(), 1/aBounds.getHeight());
aTextureTransform.invert();
- double aTexTransform[] =
+ float aTexTransform[] =
{
- aTextureTransform.get(0,0), aTextureTransform.get(1,0), 0, 0,
- aTextureTransform.get(0,1), aTextureTransform.get(1,1), 0, 0,
+ (float) aTextureTransform.get(0,0), (float) aTextureTransform.get(1,0), 0, 0,
+ (float) aTextureTransform.get(0,1), (float) aTextureTransform.get(1,1), 0, 0,
0, 0, 1, 0,
- aTextureTransform.get(0,2), aTextureTransform.get(1,2), 0, 1
- };*/
+ (float) aTextureTransform.get(0,2), (float) aTextureTransform.get(1,2), 0, 1
+ };
aCurr=rPolyPolygons.begin();
while( aCurr != aEnd )
{
- renderComplexPolyPolygon(*aCurr++, pRenderHelper, color, true);
+ renderTransformComplexPolygon(*aCurr++, pRenderHelper, color, glm::make_mat4(aTexTransform));
}
diff --git a/canvas/source/opengl/ogl_canvastools.cxx b/canvas/source/opengl/ogl_canvastools.cxx
index 4e5bb8a..0894853 100644
--- a/canvas/source/opengl/ogl_canvastools.cxx
+++ b/canvas/source/opengl/ogl_canvastools.cxx
@@ -28,7 +28,7 @@ using namespace ::com::sun::star;
namespace oglcanvas
{
- /// triangulates polygon before
+ // triangulates polygon before
void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly, RenderHelper *renderHelper,
glm::vec4 color, const bool hasTexture)
{
@@ -57,6 +57,30 @@ namespace oglcanvas
}
}
+ void renderTransformComplexPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly, RenderHelper *renderHelper,
+ glm::vec4 color, glm::mat4 transform)
+ {
+ ::basegfx::B2DPolyPolygon aPolyPoly(rPolyPoly);
+ if( aPolyPoly.areControlPointsUsed() )
+ aPolyPoly = rPolyPoly.getDefaultAdaptiveSubdivision();
+ const ::basegfx::B2DRange& rBounds(aPolyPoly.getB2DRange());
+ const double nWidth=rBounds.getWidth();
+ const double nHeight=rBounds.getHeight();
+ const ::basegfx::B2DPolygon& rTriangulatedPolygon(
+ ::basegfx::triangulator::triangulate(aPolyPoly));
+ if(rTriangulatedPolygon.count()>0)
+ {
+ std::vector<glm::vec2> vertices;
+ vertices.reserve(rTriangulatedPolygon.count());
+ for( sal_uInt32 i=0; i<rTriangulatedPolygon.count(); i++ )
+ {
+ const ::basegfx::B2DPoint& rPt( rTriangulatedPolygon.getB2DPoint(i) );
+ vertices.push_back(glm::vec2(rPt.getX(),rPt.getY()));
+ }
+ renderHelper->renderTextureTransform( vertices, nWidth, nHeight, color, GL_TRIANGLES, transform);
+ }
+ }
+
/** only use this for line polygons.
better not leave triangulation to OpenGL. also, ignores texturing
diff --git a/canvas/source/opengl/ogl_canvastools.hxx b/canvas/source/opengl/ogl_canvastools.hxx
index 2ac7a4b..5c7e1e6 100644
--- a/canvas/source/opengl/ogl_canvastools.hxx
+++ b/canvas/source/opengl/ogl_canvastools.hxx
@@ -28,6 +28,8 @@ namespace oglcanvas
void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly,
RenderHelper *renderHelper, glm::vec4 color, const bool hasTexture);
void renderPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly, RenderHelper *renderHelper, glm::vec4 color );
+ void renderTransformComplexPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly, RenderHelper *renderHelper,
+ glm::vec4 color, glm::mat4 transform);
glm::mat4 setupState( const ::basegfx::B2DHomMatrix& rTransform,
unsigned int eSrcBlend,
unsigned int eDstBlend );
diff --git a/canvas/source/opengl/ogl_renderHelper.cxx b/canvas/source/opengl/ogl_renderHelper.cxx
index 17f7675..9d3c9cf 100644
--- a/canvas/source/opengl/ogl_renderHelper.cxx
+++ b/canvas/source/opengl/ogl_renderHelper.cxx
@@ -24,27 +24,35 @@ namespace oglcanvas
m_texManProgID = OpenGLHelper::LoadShaders("textManipulatingVertexShader", "textFragmentShader");
m_simpleProgID = OpenGLHelper::LoadShaders("simpleVertexShader", "textFragmentShader");
m_texProgID = OpenGLHelper::LoadShaders("texVertexShader", "constantFragmentShader");
+ m_texTransProgID = OpenGLHelper::LoadShaders("textManipulatingVertexShader", "transformationFragmentShader");
// Get a handle for uniforms
m_manTexUnf = glGetUniformLocation(m_texManProgID, "TextTex");
m_simpleTexUnf = glGetUniformLocation(m_simpleProgID, "TextTex");
+ m_transTexUnf = glGetUniformLocation(m_texTransProgID, "TextTex");
m_manCordUnf = glGetUniformLocation(m_texManProgID, "texCord");
+ m_transCordUnf = glGetUniformLocation(m_texTransProgID, "texCord");
m_texColorUnf = glGetUniformLocation(m_texProgID, "constantColor");
m_manColorUnf = glGetUniformLocation(m_texManProgID,"colorTex");
m_simpleColorUnf = glGetUniformLocation(m_simpleProgID,"colorTex");
+ m_transColorUnf = glGetUniformLocation(m_texTransProgID,"colorTex");
+ m_transTexTransform = glGetUniformLocation(m_texTransProgID,"texTrans");
m_texMVPUnf = glGetUniformLocation(m_texProgID, "MVP");
m_manMVPUnf = glGetUniformLocation(m_texManProgID, "MVP");
m_simpleMVPUnf = glGetUniformLocation(m_simpleProgID, "MVP");
+ m_transMVPUnf = glGetUniformLocation(m_texTransProgID, "MVP");
//Gen Buffers for texturecoordinates/vertices
glGenBuffers(1, &m_vertexBuffer);
glGenBuffers(1, &m_uvBuffer);
m_manPosAttrb = glGetAttribLocation(m_texManProgID ,"vPosition");
- m_simpleUvAttrb = glGetAttribLocation(m_simpleProgID ,"UV");
+ m_transPosAttrb = glGetAttribLocation(m_texTransProgID ,"vPosition");
m_simplePosAttrb = glGetAttribLocation(m_simpleProgID ,"vPosition");
m_texPosAttrb = glGetAttribLocation(m_texProgID ,"vPosition");
+ m_simpleUvAttrb = glGetAttribLocation(m_simpleProgID ,"UV");
+
}
void RenderHelper::SetVP(const float width, const float height)
@@ -85,19 +93,17 @@ namespace oglcanvas
glBufferData(GL_ARRAY_BUFFER, rVertices.size()*sizeof(float)*2, &rVertices[0].x, GL_STATIC_DRAW);
glUniform4fv(m_texColorUnf, 1, &color[0]);
glUniformMatrix4fv(m_texMVPUnf, 1, GL_FALSE, &m_MVP[0][0]);
-
glEnableVertexAttribArray(m_texPosAttrb); //vertices
glVertexAttribPointer(
- m_texPosAttrb,
- 2, // size
- GL_FLOAT, // type
- GL_FALSE, // normalized?
- 0, // stride
- (void*)0 // array buffer offset
+ m_texPosAttrb,
+ 2, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized?
+ 0, // stride
+ (void*)0 // array buffer offset
);
- glDrawArrays(mode, 0, rVertices.size());
-
+ glDrawArrays(mode, 0, rVertices.size());
glDisableVertexAttribArray(m_texPosAttrb);
glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -126,7 +132,7 @@ namespace oglcanvas
m_simplePosAttrb,
2, // size
GL_FLOAT, // type
- GL_FALSE, // normalized?v
+ GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
@@ -178,7 +184,41 @@ namespace oglcanvas
glEnableVertexAttribArray(m_manPosAttrb);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glVertexAttribPointer(
- m_manPosAttrb,
+ m_manPosAttrb,
+ 2, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized?
+ 0, // stride
+ (void*)0 // array buffer offset
+ );
+
+ glDrawArrays(mode, 0, rVertices.size());
+
+ glDisableVertexAttribArray(m_manPosAttrb);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glUseProgram(0);
+ }
+
+ // Uses fWidth,fHeight to generate texture coordinates in vertex-shader.
+ void RenderHelper::renderTextureTransform(const std::vector<glm::vec2>& rVertices, GLfloat fWidth,
+ GLfloat fHeight, glm::vec4 color, GLenum mode, glm::mat4 transform) const
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
+ glBufferData(GL_ARRAY_BUFFER, rVertices.size()*sizeof(float)*2, &rVertices[0].x, GL_STATIC_DRAW);
+
+ glUseProgram(m_texTransProgID);
+
+ //Set Uniforms
+ glUniform1i(m_transTexUnf, 0);
+ glUniform2f(m_transCordUnf,fWidth,fHeight);
+ glUniform4fv(m_transColorUnf, 1, &color[0]);
+ glUniformMatrix4fv(m_transTexTransform, 1, GL_FALSE, &transform[0][0]);
+ glUniformMatrix4fv(m_transMVPUnf, 1, GL_FALSE, &m_MVP[0][0]);
+
+ glEnableVertexAttribArray(m_transPosAttrb);
+ glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
+ glVertexAttribPointer(
+ m_transPosAttrb,
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
diff --git a/canvas/source/opengl/ogl_renderHelper.hxx b/canvas/source/opengl/ogl_renderHelper.hxx
index 504df4f..cca509b 100644
--- a/canvas/source/opengl/ogl_renderHelper.hxx
+++ b/canvas/source/opengl/ogl_renderHelper.hxx
@@ -22,6 +22,8 @@ namespace oglcanvas
void renderVertexConstColor(const std::vector<glm::vec2>& rVertices, glm::vec4 color, GLenum mode) const;
void renderVertexUVTex(const std::vector<glm::vec2>& rVertices, const std::vector<glm::vec2>& rUVcoords, glm::vec4 color, GLenum mode) const;
void renderVertexTex(const std::vector<glm::vec2>& rVertices, GLfloat, GLfloat, glm::vec4 color, GLenum mode) const;
+ void renderTextureTransform(const std::vector<glm::vec2>& rVertices, GLfloat fWidth,
+ GLfloat fHeight, glm::vec4 color, GLenum mode, glm::mat4 transform) const;
RenderHelper();
@@ -56,6 +58,14 @@ namespace oglcanvas
GLuint m_texManProgID;
GLuint m_texProgID;
GLuint m_texMVPUnf;
+
+ GLuint m_texTransProgID;
+ GLuint m_transPosAttrb;
+ GLuint m_transCordUnf;
+ GLuint m_transMVPUnf;
+ GLuint m_transTexUnf;
+ GLuint m_transColorUnf;
+ GLuint m_transTexTransform;
//dimension
int m_iWidth;
int m_iHeight;
commit 09d7907c1416c8f38387ca76a0928c285427e74b
Author: Michael Jaumann <meta_dev at yahoo.com>
Date: Mon Dec 1 12:33:07 2014 +0000
cleanup
Change-Id: Ide2746b3fc112642bc6e262689b710326166fd28
diff --git a/canvas/source/opengl/ogl_spritedevicehelper.cxx b/canvas/source/opengl/ogl_spritedevicehelper.cxx
index 0d171d6..ba49896 100644
--- a/canvas/source/opengl/ogl_spritedevicehelper.cxx
+++ b/canvas/source/opengl/ogl_spritedevicehelper.cxx
@@ -100,6 +100,7 @@ namespace oglcanvas
initContext();
mRenderHelper.InitOpenGL();
+
mnLinearMultiColorGradientProgram =
OpenGLHelper::LoadShaders("dummyVertexShader", "linearMultiColorGradientFragmentShader");
@@ -301,16 +302,6 @@ namespace oglcanvas
const ::Size& rOutputSize = pChildWindow->GetSizePixel();
initTransformation(rOutputSize);
- glm::mat4 ViewTranslate = glm::translate(
- glm::mat4(1.0f),
- glm::vec3(-1.0, 1.0, 0.0));
- glm::mat4 ViewScaled = glm::scale(
- ViewTranslate,
- glm::vec3(2.0 / rOutputSize.Width(),
- -2.0/ rOutputSize.Height(),
- 1.0 ));
- mRenderHelper.SetModelAndMVP(ViewScaled);
-
// render the actual spritecanvas content
mpSpriteCanvas->renderRecordedActions();
@@ -334,17 +325,16 @@ namespace oglcanvas
const double fps(denominator == 0.0 ? 100.0 : 1.0/denominator);
- mRenderHelper.SetModelAndMVP(ViewScaled);
+#ifdef DEBUG_RENDERING
+ std::vector<double> aVec;
+ aVec.push_back(mfAlpha);
+ aVec.push_back(mfPriority);
+ aVec.push_back(maCanvasHelper.getRecordedActionCount());
-#ifdef RENDER_DEBUG
- std::vector<double> aVec; aVec.push_back(fps);
- aVec.push_back(maActiveSprites.size());
- aVec.push_back(mpTextureCache->getCacheSize());
- aVec.push_back(mpTextureCache->getCacheMissCount());
- aVec.push_back(mpTextureCache->getCacheHitCount());
- renderOSD( aVec, 20 , getRenderHelper());
+ renderOSD( aVec, 20, pRenderHelper);
#endif
+
/*
* TODO: moggi: fix it!
// switch buffer, sync etc.
commit 72b7e7371b9cbfa7df294cb390aaf0ba5945ad4a
Author: Michael Jaumann <meta_dev at yahoo.com>
Date: Mon Dec 1 12:28:47 2014 +0000
make copy constructor private
Change-Id: Ic6a36ecfbf24652d9e0a998d35ce1bfe3920eb6e
diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx
index 4017923..175c663 100644
--- a/include/vcl/opengl/OpenGLContext.hxx
+++ b/include/vcl/opengl/OpenGLContext.hxx
@@ -149,6 +149,9 @@ struct GLWindow
class VCLOPENGL_DLLPUBLIC OpenGLContext
{
+private:
+ OpenGLContext(const OpenGLContext&);
+ OpenGLContext& operator=(const OpenGLContext&);
public:
OpenGLContext();
~OpenGLContext();
commit 3f559f788798cfffaf1e313b8c4d89a0701bcb26
Author: Michael Jaumann <meta_dev at yahoo.com>
Date: Mon Dec 1 10:47:10 2014 +0000
set transformation matrix before rendering
Change-Id: Ib90a5af88659bba4e6f14f17c767c8fc0892702a
diff --git a/canvas/source/opengl/ogl_canvashelper.cxx b/canvas/source/opengl/ogl_canvashelper.cxx
index 0d5b087..5c9e916 100644
--- a/canvas/source/opengl/ogl_canvashelper.cxx
+++ b/canvas/source/opengl/ogl_canvashelper.cxx
@@ -101,7 +101,7 @@ namespace oglcanvas
const geometry::RealPoint2D& rPoint)
{
RenderHelper* pRenderHelper = rHelper.getDeviceHelper()->getRenderHelper();
- // pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
+ pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
glm::vec4 color = glm::vec4( (float) rColor.Red,
(float) rColor.Green,
(float) rColor.Blue,
@@ -122,7 +122,7 @@ namespace oglcanvas
const geometry::RealPoint2D& rEndPoint)
{
RenderHelper* pRenderHelper = rHelper.getDeviceHelper()->getRenderHelper();
- // pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
+ pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
glm::vec4 color = glm::vec4( (float) rColor.Red,
(float) rColor.Green,
(float) rColor.Blue,
@@ -144,7 +144,7 @@ namespace oglcanvas
const ::basegfx::B2DPolyPolygonVector& rPolyPolygons)
{
RenderHelper* pRenderHelper = rHelper.getDeviceHelper()->getRenderHelper();
- // pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
+ pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
glm::vec4 color = glm::vec4( (float) rColor.Red,
(float) rColor.Green,
(float) rColor.Blue,
@@ -169,7 +169,7 @@ namespace oglcanvas
{
//no texture bind ?
RenderHelper* pRenderHelper = rHelper.getDeviceHelper()->getRenderHelper();
- // pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
+ pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
glm::vec4 color = glm::vec4( (float) rColor.Red,
(float) rColor.Green,
(float) rColor.Blue,
@@ -194,7 +194,7 @@ namespace oglcanvas
const ::basegfx::B2DPolyPolygonVector& rPolyPolygons )
{
RenderHelper* pRenderHelper = rHelper.getDeviceHelper()->getRenderHelper();
- setupState(rTransform, eSrcBlend, eDstBlend);
+ pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
glm::vec4 color = glm::vec4( (float) rendering::ARGBColor().Red,
(float) rendering::ARGBColor().Green,
(float) rendering::ARGBColor().Blue,
@@ -259,15 +259,15 @@ namespace oglcanvas
return true;
}
- bool lcl_drawOwnBitmap( const CanvasHelper& /*rHelper*/,
+ bool lcl_drawOwnBitmap( const CanvasHelper& rHelper,
const ::basegfx::B2DHomMatrix& rTransform,
GLenum eSrcBlend,
GLenum eDstBlend,
const rendering::ARGBColor& rColor,
const CanvasBitmap& rBitmap )
{
- setupState(rTransform, eSrcBlend, eDstBlend);
-
+ RenderHelper* pRenderHelper = rHelper.getDeviceHelper()->getRenderHelper();
+ pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
return rBitmap.renderRecordedActions();
}
@@ -283,7 +283,7 @@ namespace oglcanvas
{
RenderHelper* pRenderHelper = rHelper.getDeviceHelper()->getRenderHelper();
- setupState(rTransform, eSrcBlend, eDstBlend);
+ pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
const unsigned int nTexId=rHelper.getDeviceHelper()->getTextureCache().getTexture(
rPixelSize, rPixelData.getConstArray(), nPixelCrc32);
@@ -333,9 +333,9 @@ namespace oglcanvas
sal_uInt32 nPixelCrc32,
const ::basegfx::B2DPolyPolygonVector& rPolyPolygons )
{
- // setupState(rTransform, eSrcBlend, eDstBlend, rendering::ARGBColor());
RenderHelper* pRenderHelper = rHelper.getDeviceHelper()->getRenderHelper();
- setupState(rTransform, eSrcBlend, eDstBlend);
+ pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
+
glm::vec4 color = glm::vec4( (float) rendering::ARGBColor().Red,
(float) rendering::ARGBColor().Green,
(float) rendering::ARGBColor().Blue,
@@ -364,7 +364,7 @@ namespace oglcanvas
::basegfx::B2DRange aBounds;
::basegfx::B2DPolyPolygonVector::const_iterator aCurr=rPolyPolygons.begin();
const ::basegfx::B2DPolyPolygonVector::const_iterator aEnd=rPolyPolygons.end();
- while( aCurr != aEnd )
+ /* while( aCurr != aEnd )
aBounds.expand(::basegfx::tools::getRange(*aCurr++));
aTextureTransform.translate(-aBounds.getMinX(), -aBounds.getMinY());
aTextureTransform.scale(1/aBounds.getWidth(), 1/aBounds.getHeight());
@@ -376,7 +376,7 @@ namespace oglcanvas
aTextureTransform.get(0,1), aTextureTransform.get(1,1), 0, 0,
0, 0, 1, 0,
aTextureTransform.get(0,2), aTextureTransform.get(1,2), 0, 1
- };
+ };*/
aCurr=rPolyPolygons.begin();
while( aCurr != aEnd )
commit 94c98376d2a4c90d995432872fe481db2dd195f8
Author: Michael Jaumann <meta_dev at yahoo.com>
Date: Mon Dec 1 10:41:24 2014 +0000
compute mvp matrix in the right order
Change-Id: If167d80218a1a2b230d3ee8bad6a3b24676fe8c0
diff --git a/canvas/source/opengl/ogl_renderHelper.cxx b/canvas/source/opengl/ogl_renderHelper.cxx
index 40fa5ce..17f7675 100644
--- a/canvas/source/opengl/ogl_renderHelper.cxx
+++ b/canvas/source/opengl/ogl_renderHelper.cxx
@@ -56,7 +56,7 @@ namespace oglcanvas
void RenderHelper::SetModelAndMVP(const glm::mat4& mat)
{
m_Model = mat;
- m_MVP = m_Model * m_VP;
+ m_MVP = m_VP*m_Model ;
}
void RenderHelper::renderVertexConstColor(const std::vector<glm::vec2>& rVertices, glm::vec4 color, GLenum mode) const
commit 9157fe18b22778c19a594f70804a643b6c0e814d
Author: Michael Jaumann <meta_dev at yahoo.com>
Date: Mon Dec 1 10:32:29 2014 +0000
use vertex attribute in the correspending program
Change-Id: I1a16ec97a1733fa0d2e24a578d84bd4cf9cfa847
diff --git a/canvas/source/opengl/ogl_renderHelper.cxx b/canvas/source/opengl/ogl_renderHelper.cxx
index 95d3b49..40fa5ce 100644
--- a/canvas/source/opengl/ogl_renderHelper.cxx
+++ b/canvas/source/opengl/ogl_renderHelper.cxx
@@ -81,13 +81,24 @@ namespace oglcanvas
);
glUseProgram(m_texProgID);
+ glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, rVertices.size()*sizeof(float)*2, &rVertices[0].x, GL_STATIC_DRAW);
glUniform4fv(m_texColorUnf, 1, &color[0]);
glUniformMatrix4fv(m_texMVPUnf, 1, GL_FALSE, &m_MVP[0][0]);
- glEnableVertexAttribArray(m_texPosAttrb); //vertices
+ glEnableVertexAttribArray(m_texPosAttrb); //vertices
+ glVertexAttribPointer(
+ m_texPosAttrb,
+ 2, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized?
+ 0, // stride
+ (void*)0 // array buffer offset
+ );
glDrawArrays(mode, 0, rVertices.size());
+
+
glDisableVertexAttribArray(m_texPosAttrb);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);
@@ -131,15 +142,6 @@ namespace oglcanvas
(void*)0 // array buffer offset
);
- glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
- glVertexAttribPointer(
- m_texPosAttrb,
- 2, // size
- GL_FLOAT, // type
- GL_FALSE, // normalized?
- 0, // stride
- (void*)0 // array buffer offset
- );
glDrawArrays(mode, 0, rVertices.size());
glDisableVertexAttribArray(m_simplePosAttrb);
commit 0d94d3cc0ee1545dc5d153137cc0b1ac6611956d
Author: Michael Jaumann <meta_dev at yahoo.com>
Date: Fri Nov 28 14:02:01 2014 +0000
avoid rendering polygons with 0 vertices
Change-Id: I73d5671770bdad8a3b3b52d769d02f2819a16604
diff --git a/canvas/source/opengl/ogl_canvastools.cxx b/canvas/source/opengl/ogl_canvastools.cxx
index 346d73a..4e5bb8a 100644
--- a/canvas/source/opengl/ogl_canvastools.cxx
+++ b/canvas/source/opengl/ogl_canvastools.cxx
@@ -40,17 +40,21 @@ namespace oglcanvas
const double nHeight=rBounds.getHeight();
const ::basegfx::B2DPolygon& rTriangulatedPolygon(
::basegfx::triangulator::triangulate(aPolyPoly));
- std::vector<glm::vec2> vertices;
- vertices.reserve(rTriangulatedPolygon.count());
- for( sal_uInt32 i=0; i<rTriangulatedPolygon.count(); i++ )
+ if(rTriangulatedPolygon.count()>0)
{
- const ::basegfx::B2DPoint& rPt( rTriangulatedPolygon.getB2DPoint(i) );
- vertices.push_back(glm::vec2(rPt.getX(),rPt.getY()));
+ std::vector<glm::vec2> vertices;
+ vertices.reserve(rTriangulatedPolygon.count());
+ for( sal_uInt32 i=0; i<rTriangulatedPolygon.count(); i++ )
+ {
+ const ::basegfx::B2DPoint& rPt( rTriangulatedPolygon.getB2DPoint(i) );
+ vertices.push_back(glm::vec2(rPt.getX(),rPt.getY()));
+ }
+
+ if(hasTexture)
+ renderHelper->renderVertexTex( vertices, nWidth, nHeight, color, GL_TRIANGLES);
+ else
+ renderHelper->renderVertexConstColor(vertices, color, GL_TRIANGLES);
}
- if(hasTexture)
- renderHelper->renderVertexTex( vertices, nWidth, nHeight, color, GL_TRIANGLES);
- else
- renderHelper->renderVertexConstColor(vertices, color, GL_TRIANGLES);
}
/** only use this for line polygons.
@@ -70,15 +74,17 @@ namespace oglcanvas
const sal_uInt32 nPts=rPolygon.count();
const sal_uInt32 nExtPts=nPts + int(rPolygon.isClosed());
- std::vector<glm::vec2> vertices;
- vertices.reserve(nExtPts);
- for( sal_uInt32 j=0; j<nExtPts; j++ )
- {
- const ::basegfx::B2DPoint& rPt( rPolygon.getB2DPoint( j % nPts ) );
- vertices.push_back(glm::vec2(rPt.getX(),rPt.getY()));
- }
if(nExtPts>0)
+ {
+ std::vector<glm::vec2> vertices;
+ vertices.reserve(nExtPts);
+ for( sal_uInt32 j=0; j<nExtPts; j++ )
+ {
+ const ::basegfx::B2DPoint& rPt( rPolygon.getB2DPoint( j % nPts ) );
+ vertices.push_back(glm::vec2(rPt.getX(),rPt.getY()));
+ }
renderHelper->renderVertexConstColor(vertices, color, GL_LINE_STRIP);
+ }
}
}
commit 9e8905c0fc176cbff56bb763218c1796f1595aed
Author: Michael Jaumann <meta_dev at yahoo.com>
Date: Fri Nov 28 12:38:48 2014 +0000
bind lcl_drawPolyPolygon
Change-Id: I7926fd3c68d497f92093a284f415e773904f7e9b
diff --git a/canvas/source/opengl/ogl_canvashelper.cxx b/canvas/source/opengl/ogl_canvashelper.cxx
index 7a8e47c..0d5b087 100644
--- a/canvas/source/opengl/ogl_canvashelper.cxx
+++ b/canvas/source/opengl/ogl_canvashelper.cxx
@@ -532,7 +532,7 @@ namespace oglcanvas
rAct.maPolyPolys.back().makeUnique(); // own copy, for thread safety
// TODO(F3): fallback to drawPolyPolygon currently
- // rAct.maFunction = &lcl_drawPolyPolygon;
+ rAct.maFunction = &lcl_drawPolyPolygon;
}
// TODO(P1): Provide caching here.
More information about the Libreoffice-commits
mailing list