canvas/opengl/constantFragmentShader.glsl | 4 canvas/opengl/dummyVertexShader.glsl | 7 canvas/opengl/linearMultiColorGradientFragmentShader.glsl | 4 canvas/opengl/linearTwoColorGradientFragmentShader.glsl | 4 canvas/opengl/radialMultiColorGradientFragmentShader.glsl | 4 canvas/opengl/radialTwoColorGradientFragmentShader.glsl | 4 canvas/opengl/rectangularMultiColorGradientFragmentShader.glsl | 4 canvas/opengl/rectangularTwoColorGradientFragmentShader.glsl | 4 canvas/source/opengl/ogl_canvashelper.cxx | 84 +- canvas/source/opengl/ogl_canvastools.cxx | 10 canvas/source/opengl/ogl_canvastools.hxx | 2 canvas/source/opengl/ogl_renderHelper.cxx | 362 ++++++---- canvas/source/opengl/ogl_renderHelper.hxx | 70 + canvas/source/opengl/ogl_spritedevicehelper.cxx | 154 ---- canvas/source/opengl/ogl_spritedevicehelper.hxx | 20 15 files changed, 361 insertions(+), 376 deletions(-)
New commits: commit 9614f9de6edfdfe6e64b4ae270bef04dc793e186 Author: Michael Jaumann <meta_...@yahoo.com> Date: Tue Dec 9 12:19:21 2014 +0000 use gradients in canvashelper Change-Id: I242f63bb055336d208dad5efced3618c9f89e47f diff --git a/canvas/source/opengl/ogl_canvashelper.cxx b/canvas/source/opengl/ogl_canvashelper.cxx index eb645f6..de8ef93 100644 --- a/canvas/source/opengl/ogl_canvashelper.cxx +++ b/canvas/source/opengl/ogl_canvashelper.cxx @@ -180,7 +180,7 @@ namespace oglcanvas const ::basegfx::B2DPolyPolygonVector::const_iterator aEnd=rPolyPolygons.end(); while( aCurr != aEnd ) { - renderComplexPolyPolygon(*aCurr++, pRenderHelper, color, false); + renderComplexPolyPolygon(*aCurr++, pRenderHelper, color); } return true; @@ -213,6 +213,13 @@ namespace oglcanvas aBounds.expand(::basegfx::tools::getRange(*aCurr++)); aTextureTransform.translate(-aBounds.getMinX(), -aBounds.getMinY()); aTextureTransform.scale(1/aBounds.getWidth(), 1/aBounds.getHeight()); + const float aTextureTransformation[] = + { + float(aTextureTransform.get(1,0)), float(aTextureTransform.get(1,1)), + float(aTextureTransform.get(1,2)), float(aTextureTransform.get(0,0)), + float(aTextureTransform.get(0,1)), float(aTextureTransform.get(0,2)) + }; + const glm::mat3x2 aTexTransform = glm::make_mat3x2(aTextureTransformation); const sal_Int32 nNumCols=rValues.maColors.getLength(); uno::Sequence< rendering::ARGBColor > aColors(nNumCols); @@ -223,36 +230,45 @@ namespace oglcanvas OSL_ASSERT(nNumCols == rValues.maStops.getLength()); - switch( rValues.meType ) - { - case ::canvas::ParametricPolyPolygon::GRADIENT_LINEAR: - rHelper.getDeviceHelper()->useLinearGradientShader(pColors, - rValues.maStops, - aTextureTransform); - break; - - case ::canvas::ParametricPolyPolygon::GRADIENT_ELLIPTICAL: - rHelper.getDeviceHelper()->useRadialGradientShader(pColors, - rValues.maStops, - aTextureTransform); - break; - - case ::canvas::ParametricPolyPolygon::GRADIENT_RECTANGULAR: - rHelper.getDeviceHelper()->useRectangularGradientShader(pColors, - rValues.maStops, - aTextureTransform); - break; - - default: - ENSURE_OR_THROW( false, - "CanvasHelper lcl_fillGradientPolyPolygon(): Unexpected case" ); - } - - aCurr=rPolyPolygons.begin(); while( aCurr != aEnd ) { - renderComplexPolyPolygon(*aCurr++, pRenderHelper, color, true); + ::basegfx::B2DPolyPolygon aPolyPoly(*aCurr++); + if( aPolyPoly.areControlPointsUsed() ) + aPolyPoly = aPolyPoly.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())); + } + switch(rValues.meType) + { + case ::canvas::ParametricPolyPolygon::GRADIENT_LINEAR: + pRenderHelper->renderLinearGradient( vertices, nWidth, nHeight, GL_TRIANGLES, + pColors, rValues.maStops, aTexTransform); + break; + case ::canvas::ParametricPolyPolygon::GRADIENT_ELLIPTICAL: + pRenderHelper->renderRadialGradient( vertices, nWidth, nHeight, GL_TRIANGLES, + pColors, rValues.maStops, aTexTransform); + break; + case ::canvas::ParametricPolyPolygon::GRADIENT_RECTANGULAR: + pRenderHelper->renderRectangularGradient( vertices, nWidth, nHeight, GL_TRIANGLES, + pColors, rValues.maStops, aTexTransform); + break; + default: + ENSURE_OR_THROW( false, + "CanvasHelper lcl_fillGradientPolyPolygon(): Unexpected case" ); + } + } } glUseProgram(0); diff --git a/canvas/source/opengl/ogl_canvastools.cxx b/canvas/source/opengl/ogl_canvastools.cxx index 0894853..cc41d1c 100644 --- a/canvas/source/opengl/ogl_canvastools.cxx +++ b/canvas/source/opengl/ogl_canvastools.cxx @@ -30,14 +30,11 @@ namespace oglcanvas { // triangulates polygon before void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly, RenderHelper *renderHelper, - glm::vec4 color, const bool hasTexture) + glm::vec4 color) { ::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) @@ -50,10 +47,7 @@ namespace oglcanvas 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); + renderHelper->renderVertexConstColor(vertices, color, GL_TRIANGLES); } } diff --git a/canvas/source/opengl/ogl_canvastools.hxx b/canvas/source/opengl/ogl_canvastools.hxx index 5c7e1e6..229c56d 100644 --- a/canvas/source/opengl/ogl_canvastools.hxx +++ b/canvas/source/opengl/ogl_canvastools.hxx @@ -26,7 +26,7 @@ namespace basegfx { namespace oglcanvas { void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly, - RenderHelper *renderHelper, glm::vec4 color, const bool hasTexture); + RenderHelper *renderHelper, glm::vec4 color); 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); commit 4b6ef3855f760d5a90839ae9a082e37d39b10b47 Author: Michael Jaumann <meta_...@yahoo.com> Date: Tue Dec 9 09:38:21 2014 +0000 gradients move gradients from spritedevicehelper to renderHelper, render them with shaders. Change-Id: Id1b7c2d435e15d0e5f12ca32e7fe7311301a705b diff --git a/canvas/source/opengl/ogl_renderHelper.cxx b/canvas/source/opengl/ogl_renderHelper.cxx index e235a66..50e1269 100644 --- a/canvas/source/opengl/ogl_renderHelper.cxx +++ b/canvas/source/opengl/ogl_renderHelper.cxx @@ -11,6 +11,7 @@ #include "ogl_renderHelper.hxx" #include <vcl/opengl/OpenGLHelper.hxx> #include <vcl/opengl/GLMHelper.hxx> + namespace oglcanvas { RenderHelper::RenderHelper(): @@ -25,6 +26,20 @@ namespace oglcanvas m_simpleProgID = OpenGLHelper::LoadShaders("simpleVertexShader", "textFragmentShader"); m_texProgID = OpenGLHelper::LoadShaders("texVertexShader", "constantFragmentShader"); m_texTransProgID = OpenGLHelper::LoadShaders("textManipulatingVertexShader", "transformationFragmentShader"); + mnLinearMultiColorGradientProgram = + OpenGLHelper::LoadShaders("textManipulatingVertexShader", "linearMultiColorGradientFragmentShader"); + + mnLinearTwoColorGradientProgram = + OpenGLHelper::LoadShaders("textManipulatingVertexShader", "linearTwoColorGradientFragmentShader"); + mnRadialMultiColorGradientProgram = + OpenGLHelper::LoadShaders("textManipulatingVertexShader", "radialMultiColorGradientFragmentShader"); + mnRadialTwoColorGradientProgram = + OpenGLHelper::LoadShaders("textManipulatingVertexShader", "radialTwoColorGradientFragmentShader"); + mnRectangularMultiColorGradientProgram = + OpenGLHelper::LoadShaders("textManipulatingVertexShader", "rectangularMultiColorGradientFragmentShader"); + mnRectangularTwoColorGradientProgram = + OpenGLHelper::LoadShaders("textManipulatingVertexShader", "rectangularTwoColorGradientFragmentShader"); + // Get a handle for uniforms m_manTexUnf = glGetUniformLocation(m_texManProgID, "TextTex"); m_simpleTexUnf = glGetUniformLocation(m_simpleProgID, "TextTex"); @@ -127,11 +142,15 @@ namespace oglcanvas glDeleteProgram( m_texManProgID); glDeleteProgram( m_simpleProgID); glDeleteProgram( m_texProgID); + glDeleteProgram( mnRectangularTwoColorGradientProgram ); + glDeleteProgram( mnRectangularMultiColorGradientProgram ); + glDeleteProgram( mnRadialTwoColorGradientProgram ); + glDeleteProgram( mnRadialMultiColorGradientProgram ); + glDeleteProgram( mnLinearTwoColorGradientProgram ); + glDeleteProgram( mnLinearMultiColorGradientProgram ); } - // Renders a Polygon, Texture has to be stored in TextureUnit0 - // Uses fWidth,fHeight to generate texture coordinates in vertex-shader. - void RenderHelper::renderVertexTex(const std::vector<glm::vec2>& rVertices, GLfloat fWidth, GLfloat fHeight, + void RenderHelper::renderVertexTex(const std::vector<glm::vec2>& rVertices, const GLfloat fWidth, const GLfloat fHeight, const glm::vec4& vColor, GLenum mode) const { @@ -143,7 +162,7 @@ namespace oglcanvas setupColorMVP(m_texManProgID, vColor); const GLint nVertices = setupAttrb(rVertices,m_vertexBuffer, m_texManProgID, "vPosition"); - + glDisableVertexAttribArray(nVertices); glDrawArrays(mode, 0, rVertices.size()); cleanUp(); @@ -170,6 +189,163 @@ namespace oglcanvas glDisableVertexAttribArray(nVertices); cleanUp(); } + + void RenderHelper::setupGradientTransformation( unsigned int nProgramId, + const glm::mat3x2& rTexTransform, + GLfloat fWidth, GLfloat fHeight) const + { + const GLint nTransformLocation = glGetUniformLocation(nProgramId, + "m_transform" ); + glUniformMatrix3x2fv(nTransformLocation,1,false,&rTexTransform[0][0]); + + const GLint nMVPLocation = glGetUniformLocation(nProgramId,"MVP"); + glUniformMatrix4fv(nMVPLocation, 1, GL_FALSE, &m_MVP[0][0]); + + const GLint nTextTexLocation = glGetUniformLocation(mnLinearTwoColorGradientProgram, "texCord"); + glUniform2f(nTextTexLocation, fWidth, fHeight); + } + + + static void setupGradientUniform( unsigned int nProgramId, + const ::com::sun::star::rendering::ARGBColor* pColors, + const ::com::sun::star::uno::Sequence< double >& rStops) + { + glUseProgram(nProgramId); + + GLuint nColorsTexture; + glActiveTexture(GL_TEXTURE0); + glGenTextures(1, &nColorsTexture); + glBindTexture(GL_TEXTURE_1D, nColorsTexture); + + const sal_Int32 nColors=rStops.getLength(); + glTexImage1D( GL_TEXTURE_1D, 0, GL_RGBA, nColors, 0, GL_RGBA, GL_DOUBLE, pColors ); + glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + + GLuint nStopsTexture; + glActiveTexture(GL_TEXTURE1); + glGenTextures(1, &nStopsTexture); + glBindTexture(GL_TEXTURE_1D, nStopsTexture); + + glTexImage1D( GL_TEXTURE_1D, 0, GL_ALPHA, nColors, 0, GL_ALPHA, GL_DOUBLE, rStops.getConstArray() ); + glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + + const GLint nColorArrayLocation = glGetUniformLocation(nProgramId, + "t_colorArray4d" ); + glUniform1i( nColorArrayLocation, 0 ); // unit 0 + + const GLint nStopArrayLocation = glGetUniformLocation(nProgramId, + "t_stopArray1d" ); + glUniform1i( nStopArrayLocation, 1 ); // unit 1 + + const GLint nNumColorLocation = glGetUniformLocation(nProgramId, + "i_nColors" ); + glUniform1i( nNumColorLocation, nColors-1 ); + } + + static void setupGradientUniform( unsigned int nProgramId, + const ::com::sun::star::rendering::ARGBColor& rStartColor, + const ::com::sun::star::rendering::ARGBColor& rEndColor) + { + glUseProgram(nProgramId); + + const GLint nStartColorLocation = glGetUniformLocation(nProgramId, + "v_startColor4d" ); + glUniform4f(nStartColorLocation, + rStartColor.Red, + rStartColor.Green, + rStartColor.Blue, + rStartColor.Alpha); + + const GLint nEndColorLocation = glGetUniformLocation(nProgramId, + "v_endColor4d" ); + glUniform4f(nEndColorLocation, + rEndColor.Red, + rEndColor.Green, + rEndColor.Blue, + rEndColor.Alpha); + } + + void RenderHelper::renderLinearGradient(const std::vector<glm::vec2>& rVertices, + const GLfloat fWidth, const GLfloat fHeight, + const GLenum mode, + const ::com::sun::star::rendering::ARGBColor* pColors, + const ::com::sun::star::uno::Sequence< double >& rStops, + const glm::mat3x2& rTexTransform) const + { + if( rStops.getLength() > 2 ) + { + setupGradientUniform(mnLinearMultiColorGradientProgram, pColors, rStops); + setupGradientTransformation(mnLinearMultiColorGradientProgram, rTexTransform, fWidth, fHeight); + } + else + { + setupGradientUniform(mnLinearTwoColorGradientProgram, pColors[0], pColors[1]); + setupGradientTransformation(mnLinearTwoColorGradientProgram, rTexTransform, fWidth, fHeight); + } + const GLint nVertices = setupAttrb(rVertices,m_vertexBuffer, m_simpleProgID, "vPosition"); + + glDrawArrays(mode, 0, rVertices.size()); + + glDisableVertexAttribArray(nVertices); + cleanUp(); + } + + void RenderHelper::renderRadialGradient(const std::vector<glm::vec2>& rVertices, + const GLfloat fWidth, const GLfloat fHeight, + const GLenum mode, + const ::com::sun::star::rendering::ARGBColor* pColors, + const ::com::sun::star::uno::Sequence< double >& rStops, + const glm::mat3x2& rTexTransform) const + { + if( rStops.getLength() > 2 ) + { + setupGradientUniform(mnRadialMultiColorGradientProgram, pColors, rStops); + setupGradientTransformation(mnRadialMultiColorGradientProgram, rTexTransform, fWidth, fHeight); + } + else + { + setupGradientUniform(mnRadialTwoColorGradientProgram, pColors[0], pColors[1]); + setupGradientTransformation(mnRadialTwoColorGradientProgram , rTexTransform, fWidth, fHeight); + } + + const GLint nVertices = setupAttrb(rVertices,m_vertexBuffer, m_simpleProgID, "vPosition"); + + glDrawArrays(mode, 0, rVertices.size()); + + glDisableVertexAttribArray(nVertices); + cleanUp(); + } + + void RenderHelper::renderRectangularGradient(const std::vector<glm::vec2>& rVertices, + const GLfloat fWidth, const GLfloat fHeight, + const GLenum mode, + const ::com::sun::star::rendering::ARGBColor* pColors, + const ::com::sun::star::uno::Sequence< double >& rStops, + const glm::mat3x2& rTexTransform) const + { + if( rStops.getLength() > 2 ) + { + setupGradientUniform(mnRectangularMultiColorGradientProgram, pColors, rStops); + setupGradientTransformation(mnRectangularMultiColorGradientProgram, rTexTransform, fWidth, fHeight); + } + else + { + setupGradientUniform(mnRectangularTwoColorGradientProgram, pColors[0], pColors[1]); + setupGradientTransformation(mnRectangularTwoColorGradientProgram , rTexTransform, fWidth, fHeight); + } + + const GLint nVertices = setupAttrb(rVertices,m_vertexBuffer, m_simpleProgID, "vPosition"); + + glDrawArrays(mode, 0, rVertices.size()); + + glDisableVertexAttribArray(nVertices); + cleanUp(); + } + + + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/canvas/source/opengl/ogl_renderHelper.hxx b/canvas/source/opengl/ogl_renderHelper.hxx index 82d0ff4..011120a 100644 --- a/canvas/source/opengl/ogl_renderHelper.hxx +++ b/canvas/source/opengl/ogl_renderHelper.hxx @@ -13,20 +13,45 @@ #include <glm/glm.hpp> #include "glm/gtx/transform.hpp" #include <vector> +#include <com/sun/star/rendering/XGraphicDevice.hpp> + namespace oglcanvas { class RenderHelper { public: - + //renders vertices with a const color void renderVertexConstColor(const std::vector<glm::vec2>& rVertices, const glm::vec4& vColor, GLenum mode) const; + //renders a texture bound in texture units 0, with the given texture coordinates void renderVertexUVTex(const std::vector<glm::vec2>& rVertices, const std::vector<glm::vec2>& rUVcoords, const glm::vec4& vColor, GLenum mode) const; - void renderVertexTex(const std::vector<glm::vec2>& rVertices, GLfloat, GLfloat, + //renders a texture (texture unit 0) with texture coordinates at (vertice coord /(fWidth, fHeight)) + void renderVertexTex(const std::vector<glm::vec2>& rVertices, const GLfloat fWidth, const GLfloat gHeight, const glm::vec4& vColor, GLenum mode) const; + //see renderVertexTex description, just with an additional texture transformation matrix void renderTextureTransform(const std::vector<glm::vec2>& rVertices, GLfloat fWidth, GLfloat fHeight, const glm::vec4& color, GLenum mode, const glm::mat4& transform) const; - + //Gradients + void renderLinearGradient( const std::vector<glm::vec2>& rVertices, + const GLfloat fWidth, const GLfloat fHeight, + const GLenum mode, + const ::com::sun::star::rendering::ARGBColor* pColors, + const ::com::sun::star::uno::Sequence< double >& rStops, + const glm::mat3x2& rTexTransform) const; + + void renderRadialGradient( const std::vector<glm::vec2>& rVertices, + const GLfloat fWidth, const GLfloat fHeight, + const GLenum mode, + const ::com::sun::star::rendering::ARGBColor* pColors, + const ::com::sun::star::uno::Sequence< double >& rStops, + const glm::mat3x2& rTexTransform) const; + + void renderRectangularGradient( const std::vector<glm::vec2>& rVertices, + const GLfloat fWidth, const GLfloat fHeight, + const GLenum mode, + const ::com::sun::star::rendering::ARGBColor* pColors, + const ::com::sun::star::uno::Sequence< double >& rStops, + const glm::mat3x2& rTexTransform) const; RenderHelper(); void SetVP(const float width, const float height); @@ -40,6 +65,9 @@ namespace oglcanvas RenderHelper(const RenderHelper& other); void setupColorMVP(const unsigned int nProgramID, const glm::vec4& color) const; + void setupGradientTransformation( unsigned int nProgramId, + const glm::mat3x2& rTexTransform, + GLfloat fWidth, GLfloat fHeight) const; GLuint m_vertexBuffer; GLuint m_uvBuffer; @@ -64,6 +92,14 @@ namespace oglcanvas // Our ModelViewProjection : multiplication of our 3 matrices glm::mat4 m_MVP; + GLuint mnLinearTwoColorGradientProgram; + GLuint mnLinearMultiColorGradientProgram; + GLuint mnRadialMultiColorGradientProgram; + GLuint mnRadialTwoColorGradientProgram; + GLuint mnRectangularMultiColorGradientProgram; + GLuint mnRectangularTwoColorGradientProgram; + + }; } diff --git a/canvas/source/opengl/ogl_spritedevicehelper.cxx b/canvas/source/opengl/ogl_spritedevicehelper.cxx index ba49896..087cedd 100644 --- a/canvas/source/opengl/ogl_spritedevicehelper.cxx +++ b/canvas/source/opengl/ogl_spritedevicehelper.cxx @@ -70,13 +70,7 @@ namespace oglcanvas mpSpriteCanvas(NULL), maActiveSprites(), maLastUpdate(), - mpTextureCache(new TextureCache()), - mnLinearTwoColorGradientProgram(0), - mnLinearMultiColorGradientProgram(0), - mnRadialTwoColorGradientProgram(0), - mnRadialMultiColorGradientProgram(0), - mnRectangularTwoColorGradientProgram(0), - mnRectangularMultiColorGradientProgram(0) + mpTextureCache(new TextureCache()) {} SpriteDeviceHelper::~SpriteDeviceHelper() @@ -99,26 +93,6 @@ namespace oglcanvas // init window context initContext(); mRenderHelper.InitOpenGL(); - - - mnLinearMultiColorGradientProgram = - OpenGLHelper::LoadShaders("dummyVertexShader", "linearMultiColorGradientFragmentShader"); - - mnLinearTwoColorGradientProgram = - OpenGLHelper::LoadShaders("dummyVertexShader", "linearTwoColorGradientFragmentShader"); - - mnRadialMultiColorGradientProgram = - OpenGLHelper::LoadShaders("dummyVertexShader", "radialMultiColorGradientFragmentShader"); - - mnRadialTwoColorGradientProgram = - OpenGLHelper::LoadShaders("dummyVertexShader", "radialTwoColorGradientFragmentShader"); - - mnRectangularMultiColorGradientProgram = - OpenGLHelper::LoadShaders("dummyVertexShader", "rectangularMultiColorGradientFragmentShader"); - - mnRectangularTwoColorGradientProgram = - OpenGLHelper::LoadShaders("dummyVertexShader", "rectangularTwoColorGradientFragmentShader"); - mpContext->makeCurrent(); notifySizeUpdate(rViewArea); @@ -131,16 +105,6 @@ namespace oglcanvas mpSpriteCanvas = NULL; mpDevice = NULL; mpTextureCache.reset(); - - if( mpContext->isInitialized() ) - { - glDeleteProgram( mnRectangularTwoColorGradientProgram ); - glDeleteProgram( mnRectangularMultiColorGradientProgram ); - glDeleteProgram( mnRadialTwoColorGradientProgram ); - glDeleteProgram( mnRadialMultiColorGradientProgram ); - glDeleteProgram( mnLinearTwoColorGradientProgram ); - glDeleteProgram( mnLinearMultiColorGradientProgram ); - } mpContext.reset(); mRenderHelper.dispose(); } @@ -318,14 +282,15 @@ namespace oglcanvas aSprites.end(), boost::mem_fn(&CanvasCustomSprite::renderSprite)); - +#ifdef DEBUG_RENDERING // frame counter, other info const double denominator( maLastUpdate.getElapsedTime() ); maLastUpdate.reset(); + const double fps(denominator == 0.0 ? 100.0 : 1.0/denominator); -#ifdef DEBUG_RENDERING + std::vector<double> aVec; aVec.push_back(mfAlpha); aVec.push_back(mfPriority); @@ -412,117 +377,6 @@ namespace oglcanvas maActiveSprites.erase(xSprite); } - static void setupUniforms( unsigned int nProgramId, - const ::basegfx::B2DHomMatrix& rTexTransform ) - { - const GLint nTransformLocation = glGetUniformLocation(nProgramId, - "m_transform" ); - // OGL is column-major - float aTexTransform[] = - { - float(rTexTransform.get(0,0)), float(rTexTransform.get(1,0)), - float(rTexTransform.get(0,1)), float(rTexTransform.get(1,1)), - float(rTexTransform.get(0,2)), float(rTexTransform.get(1,2)) - }; - glUniformMatrix3x2fv(nTransformLocation,1,false,aTexTransform); - } - - static void setupUniforms( unsigned int nProgramId, - const rendering::ARGBColor* pColors, - const uno::Sequence< double >& rStops, - const ::basegfx::B2DHomMatrix& rTexTransform ) - { - glUseProgram(nProgramId); - - GLuint nColorsTexture; - glActiveTexture(GL_TEXTURE0); - glGenTextures(1, &nColorsTexture); - glBindTexture(GL_TEXTURE_1D, nColorsTexture); - - const sal_Int32 nColors=rStops.getLength(); - glTexImage1D( GL_TEXTURE_1D, 0, GL_RGBA, nColors, 0, GL_RGBA, GL_DOUBLE, pColors ); - glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); - glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); - - GLuint nStopsTexture; - glActiveTexture(GL_TEXTURE1); - glGenTextures(1, &nStopsTexture); - glBindTexture(GL_TEXTURE_1D, nStopsTexture); - - glTexImage1D( GL_TEXTURE_1D, 0, GL_ALPHA, nColors, 0, GL_ALPHA, GL_DOUBLE, rStops.getConstArray() ); - glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); - glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); - - const GLint nColorArrayLocation = glGetUniformLocation(nProgramId, - "t_colorArray4d" ); - glUniform1i( nColorArrayLocation, 0 ); // unit 0 - - const GLint nStopArrayLocation = glGetUniformLocation(nProgramId, - "t_stopArray1d" ); - glUniform1i( nStopArrayLocation, 1 ); // unit 1 - - const GLint nNumColorLocation = glGetUniformLocation(nProgramId, - "i_nColors" ); - glUniform1i( nNumColorLocation, nColors-1 ); - - setupUniforms(nProgramId,rTexTransform); - } - - static void setupUniforms( unsigned int nProgramId, - const rendering::ARGBColor& rStartColor, - const rendering::ARGBColor& rEndColor, - const ::basegfx::B2DHomMatrix& rTexTransform ) - { - glUseProgram(nProgramId); - - const GLint nStartColorLocation = glGetUniformLocation(nProgramId, - "v_startColor4d" ); - glUniform4f(nStartColorLocation, - rStartColor.Red, - rStartColor.Green, - rStartColor.Blue, - rStartColor.Alpha); - - const GLint nEndColorLocation = glGetUniformLocation(nProgramId, - "v_endColor4d" ); - glUniform4f(nEndColorLocation, - rEndColor.Red, - rEndColor.Green, - rEndColor.Blue, - rEndColor.Alpha); - - setupUniforms(nProgramId,rTexTransform); - } - - void SpriteDeviceHelper::useLinearGradientShader( const rendering::ARGBColor* pColors, - const uno::Sequence< double >& rStops, - const ::basegfx::B2DHomMatrix& rTexTransform ) - { - if( rStops.getLength() > 2 ) - setupUniforms(mnLinearMultiColorGradientProgram, pColors, rStops, rTexTransform); - else - setupUniforms(mnLinearTwoColorGradientProgram, pColors[0], pColors[1], rTexTransform); - } - - void SpriteDeviceHelper::useRadialGradientShader( const rendering::ARGBColor* pColors, - const uno::Sequence< double >& rStops, - const ::basegfx::B2DHomMatrix& rTexTransform ) - { - if( rStops.getLength() > 2 ) - setupUniforms(mnRadialMultiColorGradientProgram, pColors, rStops, rTexTransform); - else - setupUniforms(mnRadialTwoColorGradientProgram, pColors[0], pColors[1], rTexTransform); - } - - void SpriteDeviceHelper::useRectangularGradientShader( const rendering::ARGBColor* pColors, - const uno::Sequence< double >& rStops, - const ::basegfx::B2DHomMatrix& rTexTransform ) - { - if( rStops.getLength() > 2 ) - setupUniforms(mnRectangularMultiColorGradientProgram, pColors, rStops, rTexTransform); - else - setupUniforms(mnRectangularTwoColorGradientProgram, pColors[0], pColors[1], rTexTransform); - } bool SpriteDeviceHelper::activateWindowContext() { diff --git a/canvas/source/opengl/ogl_spritedevicehelper.hxx b/canvas/source/opengl/ogl_spritedevicehelper.hxx index 5e2cbca..f42c86b 100644 --- a/canvas/source/opengl/ogl_spritedevicehelper.hxx +++ b/canvas/source/opengl/ogl_spritedevicehelper.hxx @@ -99,19 +99,6 @@ namespace oglcanvas void show( const ::rtl::Reference< CanvasCustomSprite >& ); void hide( const ::rtl::Reference< CanvasCustomSprite >& ); - /// enable linear gradient shader "texture" with given parameters - void useLinearGradientShader( const ::com::sun::star::rendering::ARGBColor* pColors, - const ::com::sun::star::uno::Sequence< double >& rStops, - const ::basegfx::B2DHomMatrix& rTexTransform ); - /// enable radial gradient shader "texture" with given parameters - void useRadialGradientShader( const ::com::sun::star::rendering::ARGBColor* pColors, - const ::com::sun::star::uno::Sequence< double >& rStops, - const ::basegfx::B2DHomMatrix& rTexTransform ); - /// enable rectangular gradient shader "texture" with given parameters - void useRectangularGradientShader( const ::com::sun::star::rendering::ARGBColor* pColors, - const ::com::sun::star::uno::Sequence< double >& rStops, - const ::basegfx::B2DHomMatrix& rTexTransform ); - /// create a pbuffer context (for rendering into background surface) IBufferContextSharedPtr createBufferContext(const glm::vec2& rSize) const; @@ -146,13 +133,6 @@ namespace oglcanvas boost::shared_ptr<TextureCache> mpTextureCache; - unsigned int mnLinearTwoColorGradientProgram; - unsigned int mnLinearMultiColorGradientProgram; - unsigned int mnRadialTwoColorGradientProgram; - unsigned int mnRadialMultiColorGradientProgram; - unsigned int mnRectangularTwoColorGradientProgram; - unsigned int mnRectangularMultiColorGradientProgram; - boost::scoped_ptr<OpenGLContext> mpContext; RenderHelper mRenderHelper; }; commit 18580240565840ee2fa181fc930a3c5ab90ca062 Author: Michael Jaumann <meta_...@yahoo.com> Date: Tue Dec 9 09:08:13 2014 +0000 unify transmitted texture coordinate name Change-Id: I8c45ffeb6eb62ebe4d08214cccaaad6237621276 diff --git a/canvas/opengl/dummyVertexShader.glsl b/canvas/opengl/dummyVertexShader.glsl index 2948ee9..5efc9f8 100644 --- a/canvas/opengl/dummyVertexShader.glsl +++ b/canvas/opengl/dummyVertexShader.glsl @@ -6,11 +6,14 @@ * 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/. */ - + +uniform mat4 MVP; +attribute vec2 vPosition; +attribute vec2 vPosition; varying vec2 v_textureCoords2d; void main(void) { - gl_Position = ftransform(); + gl_Position = MVP * vec4(vPosition,1,1); v_textureCoords2d = gl_MultiTexCoord0.st; } diff --git a/canvas/opengl/linearMultiColorGradientFragmentShader.glsl b/canvas/opengl/linearMultiColorGradientFragmentShader.glsl index 7ad8813..bf161f6 100644 --- a/canvas/opengl/linearMultiColorGradientFragmentShader.glsl +++ b/canvas/opengl/linearMultiColorGradientFragmentShader.glsl @@ -13,7 +13,7 @@ uniform int i_nColors; uniform sampler1D t_colorArray4d; uniform sampler1D t_stopArray1d; uniform mat3x2 m_transform; -varying vec2 v_textureCoords2d; +varying vec2 textCoords; int max(int x, int y) { @@ -34,7 +34,7 @@ int findBucket(float t) void main(void) { float fAlpha = - clamp( (m_transform * vec3(v_textureCoords2d,1)).s, + clamp( (m_transform * vec3(textCoords,1)).s, 0.0, 1.0 ); int nMinBucket = findBucket( fAlpha ); diff --git a/canvas/opengl/linearTwoColorGradientFragmentShader.glsl b/canvas/opengl/linearTwoColorGradientFragmentShader.glsl index 8659bfd..267b124 100644 --- a/canvas/opengl/linearTwoColorGradientFragmentShader.glsl +++ b/canvas/opengl/linearTwoColorGradientFragmentShader.glsl @@ -12,14 +12,14 @@ uniform vec4 v_startColor4d; uniform vec4 v_endColor4d; uniform mat3x2 m_transform; -varying vec2 v_textureCoords2d; +varying vec2 textCoords; void main(void) { gl_FragColor = mix(v_startColor4d, v_endColor4d, clamp( - (m_transform * vec3(v_textureCoords2d,1)).s, + (m_transform*vec3(textCoords,1)).s, 0.0, 1.0)); } diff --git a/canvas/opengl/radialMultiColorGradientFragmentShader.glsl b/canvas/opengl/radialMultiColorGradientFragmentShader.glsl index ebc6d6f..8de4111 100644 --- a/canvas/opengl/radialMultiColorGradientFragmentShader.glsl +++ b/canvas/opengl/radialMultiColorGradientFragmentShader.glsl @@ -13,7 +13,7 @@ uniform int i_nColors; uniform sampler1D t_colorArray4d; uniform sampler1D t_stopArray1d; uniform mat3x2 m_transform; -varying vec2 v_textureCoords2d; +varying vec2 textCoords; const vec2 v_center2d = vec2(0,0); int max(int x, int y) @@ -36,7 +36,7 @@ void main(void) { float fAlpha = clamp( 1.0 - distance( - vec2( m_transform * vec3(v_textureCoords2d,1)), + vec2( m_transform * vec3(textCoords,1)), v_center2d), 0.0, 1.0 ); diff --git a/canvas/opengl/radialTwoColorGradientFragmentShader.glsl b/canvas/opengl/radialTwoColorGradientFragmentShader.glsl index a5d6134..2a7d9c7 100644 --- a/canvas/opengl/radialTwoColorGradientFragmentShader.glsl +++ b/canvas/opengl/radialTwoColorGradientFragmentShader.glsl @@ -12,7 +12,7 @@ uniform vec4 v_startColor4d; uniform vec4 v_endColor4d; uniform mat3x2 m_transform; -varying vec2 v_textureCoords2d; +varying vec2 textCoords; const vec2 v_center2d = vec2(0,0); void main(void) @@ -21,7 +21,7 @@ void main(void) v_endColor4d, 1.0 - distance( vec2( - m_transform * vec3(v_textureCoords2d,1)), + m_transform * vec3(textCoords,1)), v_center2d)); } diff --git a/canvas/opengl/rectangularMultiColorGradientFragmentShader.glsl b/canvas/opengl/rectangularMultiColorGradientFragmentShader.glsl index 331e57a..8a343fd 100644 --- a/canvas/opengl/rectangularMultiColorGradientFragmentShader.glsl +++ b/canvas/opengl/rectangularMultiColorGradientFragmentShader.glsl @@ -13,7 +13,7 @@ uniform int i_nColors; uniform sampler1D t_colorArray4d; uniform sampler1D t_stopArray1d; uniform mat3x2 m_transform; -varying vec2 v_textureCoords2d; +varying vec2 textCoords; int maxInt(int x, int y) { @@ -33,7 +33,7 @@ int findBucket(float t) void main(void) { - vec2 v = abs( vec2(m_transform * vec3(v_textureCoords2d,1)) ); + vec2 v = abs( vec2(m_transform * vec3(textCoords,1)) ); float fAlpha = 1.0 - max(v.x, v.y); int nMinBucket=findBucket( fAlpha ); diff --git a/canvas/opengl/rectangularTwoColorGradientFragmentShader.glsl b/canvas/opengl/rectangularTwoColorGradientFragmentShader.glsl index 038cdff..be779af 100644 --- a/canvas/opengl/rectangularTwoColorGradientFragmentShader.glsl +++ b/canvas/opengl/rectangularTwoColorGradientFragmentShader.glsl @@ -12,10 +12,10 @@ uniform vec4 v_startColor4d; uniform vec4 v_endColor4d; uniform mat3x2 m_transform; -varying vec2 v_textureCoords2d; +varying vec2 textCoords; void main(void) { - vec2 v = abs( vec2(m_transform * vec3(v_textureCoords2d,1)) ); + vec2 v = abs( vec2(m_transform * vec3(textCoords,1)) ); float t = max(v.x, v.y); gl_FragColor = mix(v_startColor4d, v_endColor4d, commit 39c6a055335128decf83a11bc942a11e67df0b37 Author: Michael Jaumann <meta_...@yahoo.com> Date: Thu Dec 4 09:33:22 2014 +0000 cleanup, unify shaders/renderHelper Change-Id: Ib9062728ad2ccf0921d4fd04db43189a10fc7c5c diff --git a/canvas/opengl/constantFragmentShader.glsl b/canvas/opengl/constantFragmentShader.glsl index 67b0a9c..bd4447f 100644 --- a/canvas/opengl/constantFragmentShader.glsl +++ b/canvas/opengl/constantFragmentShader.glsl @@ -9,11 +9,11 @@ #version 120 -uniform vec4 constantColor; +uniform vec4 colorTex; void main() { - gl_FragColor = constantColor; + gl_FragColor = colorTex; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/canvas/source/opengl/ogl_renderHelper.cxx b/canvas/source/opengl/ogl_renderHelper.cxx index 9d3c9cf..e235a66 100644 --- a/canvas/source/opengl/ogl_renderHelper.cxx +++ b/canvas/source/opengl/ogl_renderHelper.cxx @@ -32,128 +32,91 @@ namespace oglcanvas 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_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) + void RenderHelper::setupColorMVP(const unsigned int nProgramId, const glm::vec4& vColor) const { - m_VP = glm::ortho(0.0f, width, height, 0.0f); - } + const GLint nMVPLocation = glGetUniformLocation(nProgramId,"MVP"); + glUniformMatrix4fv(nMVPLocation, 1, GL_FALSE, &m_MVP[0][0]); - void RenderHelper::SetModelAndMVP(const glm::mat4& mat) - { - m_Model = mat; - m_MVP = m_VP*m_Model ; + const GLint ncolorTexLocation = glGetUniformLocation(nProgramId,"colorTex"); + glUniform4fv(ncolorTexLocation, 1, &vColor[0]); } - void RenderHelper::renderVertexConstColor(const std::vector<glm::vec2>& rVertices, glm::vec4 color, GLenum mode) const + static GLint setupAttrb(const std::vector<glm::vec2>& vattrb_data, const unsigned int buffer, const unsigned int nProgramId, const char sattribName[]) { - glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); - - glUseProgram(m_texProgID); + glBindBuffer(GL_ARRAY_BUFFER, buffer); + glBufferData(GL_ARRAY_BUFFER, vattrb_data.size()*sizeof(float)*2, &vattrb_data [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 + const GLint nAttrbLocation = glGetAttribLocation(nProgramId, sattribName); - glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); + glEnableVertexAttribArray(nAttrbLocation); //vertices glVertexAttribPointer( - m_texPosAttrb, - 2, // size - GL_FLOAT, // type - GL_FALSE, // normalized? - 0, // stride - (void*)0 // array buffer offset - ); - 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 - glVertexAttribPointer( - m_texPosAttrb, + nAttrbLocation, 2, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); + return nAttrbLocation; + } - glDrawArrays(mode, 0, rVertices.size()); + void RenderHelper::SetVP(const float nwidth, const float nheight) + { + m_VP = glm::ortho(0.0f, nwidth, nheight, 0.0f); + } - glDisableVertexAttribArray(m_texPosAttrb); + static void cleanUp() + { glBindBuffer(GL_ARRAY_BUFFER, 0); glUseProgram(0); + } + void RenderHelper::SetModelAndMVP(const glm::mat4& mat) + { + m_Model = mat; + m_MVP = m_VP*m_Model ; } - //Renders a TriangleStrip, Texture has to be stored in TextureUnit0 - void RenderHelper::renderVertexUVTex(const std::vector<glm::vec2>& rVertices, const std::vector<glm::vec2>& rUVcoords, glm::vec4 color, GLenum mode) const + + void RenderHelper::renderVertexConstColor(const std::vector<glm::vec2>& rVertices, const glm::vec4& vColor, + GLenum mode) const { - glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); - glBufferData(GL_ARRAY_BUFFER, rVertices.size()*sizeof(float)*2, &rVertices[0].x, GL_STATIC_DRAW); + glUseProgram(m_texProgID); + + setupColorMVP(m_texProgID, vColor); + const GLint nVertices = setupAttrb(rVertices, m_vertexBuffer, m_texProgID, "vPosition"); - glBindBuffer(GL_ARRAY_BUFFER, m_uvBuffer); - glBufferData(GL_ARRAY_BUFFER, rUVcoords.size()*sizeof(float)*2, &rUVcoords[0].x, GL_STATIC_DRAW); + glDrawArrays(mode, 0, rVertices.size()); + glDisableVertexAttribArray(nVertices); + cleanUp(); + } + //Renders a TriangleStrip, Texture has to be stored in TextureUnit0 + void RenderHelper::renderVertexUVTex(const std::vector<glm::vec2>& rVertices, const std::vector<glm::vec2>& rUVcoords, + const glm::vec4& vColor, GLenum mode) const + { glUseProgram(m_simpleProgID); glUniform1i(m_simpleTexUnf, 0); //Use texture Unit 0 - glUniform4fv(m_simpleColorUnf, 1, &color[0]); - glUniformMatrix4fv(m_simpleMVPUnf, 1, GL_FALSE, &m_MVP[0][0]); - - glEnableVertexAttribArray(m_simplePosAttrb); - glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); - glVertexAttribPointer( - m_simplePosAttrb, - 2, // size - GL_FLOAT, // type - GL_FALSE, // normalized? - 0, // stride - (void*)0 // array buffer offset - ); - - glEnableVertexAttribArray(m_simpleUvAttrb); - glBindBuffer(GL_ARRAY_BUFFER, m_uvBuffer); - glVertexAttribPointer( - m_simpleUvAttrb, - 2, // size - GL_FLOAT, // type - GL_FALSE, // normalized? - 0, // stride - (void*)0 // array buffer offset - ); + setupColorMVP(m_simpleProgID, vColor); + const GLint nUVAttrb = setupAttrb(rUVcoords,m_uvBuffer, m_simpleProgID, "UV"); + const GLint nVertices = setupAttrb(rVertices,m_vertexBuffer, m_simpleProgID, "vPosition"); glDrawArrays(mode, 0, rVertices.size()); - glDisableVertexAttribArray(m_simplePosAttrb); - glDisableVertexAttribArray(m_simpleUvAttrb); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glUseProgram(0); + glDisableVertexAttribArray(nVertices); + glDisableVertexAttribArray(nUVAttrb); + + cleanUp(); } //Clean up @@ -168,69 +131,44 @@ namespace oglcanvas // Renders a Polygon, Texture has to be stored in TextureUnit0 // Uses fWidth,fHeight to generate texture coordinates in vertex-shader. - void RenderHelper::renderVertexTex(const std::vector<glm::vec2>& rVertices, GLfloat fWidth, GLfloat fHeight, glm::vec4 color, GLenum mode) const + void RenderHelper::renderVertexTex(const std::vector<glm::vec2>& rVertices, GLfloat fWidth, GLfloat fHeight, + const glm::vec4& vColor, GLenum mode) const { - glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); - glBufferData(GL_ARRAY_BUFFER, rVertices.size()*sizeof(float)*2, &rVertices[0].x, GL_STATIC_DRAW); glUseProgram(m_texManProgID); //Set Uniforms glUniform1i(m_manTexUnf, 0); glUniform2f(m_manCordUnf,fWidth,fHeight); - glUniform4fv(m_manColorUnf, 1, &color[0]); - glUniformMatrix4fv(m_manMVPUnf, 1, GL_FALSE, &m_MVP[0][0]); - glEnableVertexAttribArray(m_manPosAttrb); - glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); - glVertexAttribPointer( - m_manPosAttrb, - 2, // size - GL_FLOAT, // type - GL_FALSE, // normalized? - 0, // stride - (void*)0 // array buffer offset - ); + setupColorMVP(m_texManProgID, vColor); + const GLint nVertices = setupAttrb(rVertices,m_vertexBuffer, m_texManProgID, "vPosition"); glDrawArrays(mode, 0, rVertices.size()); - glDisableVertexAttribArray(m_manPosAttrb); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glUseProgram(0); + cleanUp(); } - // 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 + // Uses fWidth,fHeight to generate texture coordinates in vertex-shader. + void RenderHelper::renderTextureTransform(const std::vector<glm::vec2>& rVertices, GLfloat fWidth, GLfloat fHeight, + const glm::vec4& vColor, GLenum mode, const 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? - 0, // stride - (void*)0 // array buffer offset - ); + setupColorMVP(m_texTransProgID, vColor); + const GLint nVertices = setupAttrb(rVertices,m_vertexBuffer, m_texTransProgID, "vPosition"); glDrawArrays(mode, 0, rVertices.size()); - glDisableVertexAttribArray(m_manPosAttrb); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glUseProgram(0); + glDisableVertexAttribArray(nVertices); + cleanUp(); } } diff --git a/canvas/source/opengl/ogl_renderHelper.hxx b/canvas/source/opengl/ogl_renderHelper.hxx index cca509b..82d0ff4 100644 --- a/canvas/source/opengl/ogl_renderHelper.hxx +++ b/canvas/source/opengl/ogl_renderHelper.hxx @@ -19,11 +19,13 @@ namespace oglcanvas { public: - 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 renderVertexConstColor(const std::vector<glm::vec2>& rVertices, const glm::vec4& vColor, GLenum mode) const; + void renderVertexUVTex(const std::vector<glm::vec2>& rVertices, const std::vector<glm::vec2>& rUVcoords, + const glm::vec4& vColor, GLenum mode) const; + void renderVertexTex(const std::vector<glm::vec2>& rVertices, GLfloat, GLfloat, + const glm::vec4& vColor, GLenum mode) const; void renderTextureTransform(const std::vector<glm::vec2>& rVertices, GLfloat fWidth, - GLfloat fHeight, glm::vec4 color, GLenum mode, glm::mat4 transform) const; + GLfloat fHeight, const glm::vec4& color, GLenum mode, const glm::mat4& transform) const; RenderHelper(); @@ -32,46 +34,32 @@ namespace oglcanvas void dispose(); void InitOpenGL(); + private: RenderHelper& operator = (const RenderHelper& other); RenderHelper(const RenderHelper& other); + void setupColorMVP(const unsigned int nProgramID, const glm::vec4& color) const; + GLuint m_vertexBuffer; GLuint m_uvBuffer; - GLuint m_simpleProgID; - GLuint m_simpleUvAttrb; - GLuint m_simplePosAttrb; GLuint m_simpleTexUnf; - GLuint m_simpleColorUnf; - GLuint m_simpleMVPUnf; GLuint m_manTexUnf; - GLuint m_manPosAttrb; GLuint m_manCordUnf; - GLuint m_manColorUnf; - GLuint m_manMVPUnf; - GLuint m_texPosAttrb; - GLuint m_texColorUnf; 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; glm::mat4 m_VP; - // Model matrix : an identity matrix (model will be at the origin + // Model matrix glm::mat4 m_Model; // Our ModelViewProjection : multiplication of our 3 matrices glm::mat4 m_MVP; commit 5a47fd99ca2917eafc5790a5559b994ab8dca5bf Author: Michael Jaumann <meta_...@yahoo.com> Date: Tue Dec 2 13:39:33 2014 +0000 transform bitmaps changed order of vertices/texture coordinates. Change-Id: I35bd8026aa091bf05f1cb54a735aa235a3cd1480 diff --git a/canvas/source/opengl/ogl_canvashelper.cxx b/canvas/source/opengl/ogl_canvashelper.cxx index 34d1342..eb645f6 100644 --- a/canvas/source/opengl/ogl_canvashelper.cxx +++ b/canvas/source/opengl/ogl_canvashelper.cxx @@ -306,17 +306,17 @@ namespace oglcanvas std::vector<glm::vec2> vertices; vertices.reserve(4); - vertices.push_back(glm::vec2(0, 0)); - vertices.push_back(glm::vec2(0, (float) rPixelSize.Height)); vertices.push_back(glm::vec2((float) rPixelSize.Width, 0)); vertices.push_back(glm::vec2((float) rPixelSize.Width, (float) rPixelSize.Height)); + vertices.push_back(glm::vec2(0, 0)); + vertices.push_back(glm::vec2(0, (float) rPixelSize.Height)); std::vector<glm::vec2> uvCoordinates; uvCoordinates.reserve(4); - uvCoordinates.push_back(glm::vec2(0, 0)); - uvCoordinates.push_back(glm::vec2(0, 1)); - uvCoordinates.push_back(glm::vec2(1, 0)); uvCoordinates.push_back(glm::vec2(1, 1)); + uvCoordinates.push_back(glm::vec2(1, 0)); + uvCoordinates.push_back(glm::vec2(0, 1)); + uvCoordinates.push_back(glm::vec2(0, 0)); pRenderHelper->renderVertexUVTex(vertices, uvCoordinates, color, GL_TRIANGLE_STRIP ); glBindTexture(GL_TEXTURE_2D, 0); @@ -371,7 +371,7 @@ namespace oglcanvas float aTexTransform[] = { (float) aTextureTransform.get(0,0), (float) aTextureTransform.get(1,0), 0, 0, - (float) aTextureTransform.get(0,1), (float) aTextureTransform.get(1,1), 0, 0, + (float) aTextureTransform.get(0,1), -(float) aTextureTransform.get(1,1), 0, 0, 0, 0, 1, 0, (float) aTextureTransform.get(0,2), (float) aTextureTransform.get(1,2), 0, 1 }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits