[Libreoffice-commits] core.git: Branch 'feature/opengl-canvas-rework' - canvas/source
Michael Jaumann
meta_dev at yahoo.com
Fri Nov 28 01:27:50 PST 2014
canvas/source/opengl/ogl_canvashelper.cxx | 14 +++++++-------
canvas/source/opengl/ogl_canvastools.cxx | 14 +++++++++-----
canvas/source/opengl/ogl_canvastools.hxx | 3 ++-
canvas/source/opengl/ogl_renderHelper.cxx | 23 +++++++++++++++++++----
4 files changed, 37 insertions(+), 17 deletions(-)
New commits:
commit 2bd148c0210571981af047245a3be9e670e99312
Author: Michael Jaumann <meta_dev at yahoo.com>
Date: Fri Nov 28 09:23:37 2014 +0000
drawArrays with triangles, correct buffersize
Change-Id: Ic2a7bff2b59e12ca4b455cbefb16ba692f81efc5
diff --git a/canvas/source/opengl/ogl_canvashelper.cxx b/canvas/source/opengl/ogl_canvashelper.cxx
index 7d25491..7a8e47c 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();
- 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();
- 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();
- 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();
- setupState(rTransform, eSrcBlend, eDstBlend);
+ // pRenderHelper->SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
glm::vec4 color = glm::vec4( (float) rColor.Red,
(float) rColor.Green,
(float) rColor.Blue,
@@ -179,7 +179,7 @@ namespace oglcanvas
const ::basegfx::B2DPolyPolygonVector::const_iterator aEnd=rPolyPolygons.end();
while( aCurr != aEnd )
{
- renderPolyPolygon(*aCurr++, pRenderHelper, color);
+ renderComplexPolyPolygon(*aCurr++, pRenderHelper, color, false);
}
return true;
@@ -251,7 +251,7 @@ namespace oglcanvas
aCurr=rPolyPolygons.begin();
while( aCurr != aEnd )
{
- renderComplexPolyPolygon(*aCurr++, pRenderHelper, color);
+ renderComplexPolyPolygon(*aCurr++, pRenderHelper, color, true);
}
glUseProgram(0);
@@ -381,7 +381,7 @@ namespace oglcanvas
aCurr=rPolyPolygons.begin();
while( aCurr != aEnd )
{
- renderComplexPolyPolygon(*aCurr++, pRenderHelper, color);
+ renderComplexPolyPolygon(*aCurr++, pRenderHelper, color, true);
}
diff --git a/canvas/source/opengl/ogl_canvastools.cxx b/canvas/source/opengl/ogl_canvastools.cxx
index 833c9eb..346d73a 100644
--- a/canvas/source/opengl/ogl_canvastools.cxx
+++ b/canvas/source/opengl/ogl_canvastools.cxx
@@ -29,8 +29,8 @@ using namespace ::com::sun::star;
namespace oglcanvas
{
/// triangulates polygon before
- //move to canvashelper, or take renderHelper as parameter?
- void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly, RenderHelper *renderHelper, glm::vec4 color )
+ void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly, RenderHelper *renderHelper,
+ glm::vec4 color, const bool hasTexture)
{
::basegfx::B2DPolyPolygon aPolyPoly(rPolyPoly);
if( aPolyPoly.areControlPointsUsed() )
@@ -47,7 +47,10 @@ namespace oglcanvas
const ::basegfx::B2DPoint& rPt( rTriangulatedPolygon.getB2DPoint(i) );
vertices.push_back(glm::vec2(rPt.getX(),rPt.getY()));
}
- renderHelper->renderVertexTex( vertices, nWidth, nHeight, 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.
@@ -74,7 +77,8 @@ namespace oglcanvas
const ::basegfx::B2DPoint& rPt( rPolygon.getB2DPoint( j % nPts ) );
vertices.push_back(glm::vec2(rPt.getX(),rPt.getY()));
}
- renderHelper->renderVertexConstColor(vertices, color, GL_LINE_STRIP);
+ if(nExtPts>0)
+ renderHelper->renderVertexConstColor(vertices, color, GL_LINE_STRIP);
}
}
@@ -115,7 +119,7 @@ namespace oglcanvas
aTmp=aTmp*aScaleShear;
aPoly.transform(aTmp);
// glColor4f(0,1,0,1);
- glm::vec4 color = glm::vec4(0.5, 0, 0, 0.5);
+ glm::vec4 color = glm::vec4(1, 0, 0, 0.5);
renderPolyPolygon(aPoly, renderHelper, color);
}
}
diff --git a/canvas/source/opengl/ogl_canvastools.hxx b/canvas/source/opengl/ogl_canvastools.hxx
index 904b7f6..2ac7a4b 100644
--- a/canvas/source/opengl/ogl_canvastools.hxx
+++ b/canvas/source/opengl/ogl_canvastools.hxx
@@ -25,7 +25,8 @@ namespace basegfx {
namespace oglcanvas
{
- void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly, RenderHelper *renderHelper, glm::vec4 color);
+ 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 );
glm::mat4 setupState( const ::basegfx::B2DHomMatrix& rTransform,
unsigned int eSrcBlend,
diff --git a/canvas/source/opengl/ogl_renderHelper.cxx b/canvas/source/opengl/ogl_renderHelper.cxx
index f53ab33..95d3b49 100644
--- a/canvas/source/opengl/ogl_renderHelper.cxx
+++ b/canvas/source/opengl/ogl_renderHelper.cxx
@@ -65,7 +65,7 @@ namespace oglcanvas
glUseProgram(m_texProgID);
- glBufferData(GL_ARRAY_BUFFER, rVertices.size()*sizeof(float), &rVertices[0].x, GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, testVertices.size()*sizeof(float)*2, &testVertices[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
@@ -79,6 +79,12 @@ namespace oglcanvas
0, // stride
(void*)0 // array buffer offset
);
+ glUseProgram(m_texProgID);
+
+ 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
glDrawArrays(mode, 0, rVertices.size());
@@ -91,10 +97,10 @@ namespace oglcanvas
void RenderHelper::renderVertexUVTex(const std::vector<glm::vec2>& rVertices, const std::vector<glm::vec2>& rUVcoords, glm::vec4 color, GLenum mode) const
{
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
- glBufferData(GL_ARRAY_BUFFER, rVertices.size()*sizeof(float), &rVertices[0].x, GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, rVertices.size()*sizeof(float)*2, &rVertices[0].x, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, m_uvBuffer);
- glBufferData(GL_ARRAY_BUFFER, rUVcoords.size()*sizeof(float), &rUVcoords[0].x, GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, rUVcoords.size()*sizeof(float)*2, &rUVcoords[0].x, GL_STATIC_DRAW);
glUseProgram(m_simpleProgID);
@@ -125,6 +131,15 @@ 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);
@@ -148,7 +163,7 @@ namespace oglcanvas
void RenderHelper::renderVertexTex(const std::vector<glm::vec2>& rVertices, GLfloat fWidth, GLfloat fHeight, glm::vec4 color, GLenum mode) const
{
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
- glBufferData(GL_ARRAY_BUFFER, rVertices.size()*sizeof(float), &rVertices[0].x, GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, rVertices.size()*sizeof(float)*2, &rVertices[0].x, GL_STATIC_DRAW);
glUseProgram(m_texManProgID);
More information about the Libreoffice-commits
mailing list