[Libreoffice-commits] core.git: Branch 'feature/opengl-canvas-rework' - 3 commits - canvas/source

Michael Jaumann meta_dev at yahoo.com
Tue Oct 28 01:50:48 PDT 2014


 canvas/source/opengl/ogl_canvascustomsprite.cxx |    6 -
 canvas/source/opengl/ogl_canvashelper.cxx       |  101 +++++++++++++-----------
 canvas/source/opengl/ogl_canvashelper.hxx       |    3 
 canvas/source/opengl/ogl_canvastools.cxx        |   28 +-----
 canvas/source/opengl/ogl_canvastools.hxx        |   17 ++--
 canvas/source/opengl/ogl_renderHelper.cxx       |   14 +--
 canvas/source/opengl/ogl_renderHelper.hxx       |   14 ++-
 7 files changed, 97 insertions(+), 86 deletions(-)

New commits:
commit f8b451457fbbf80e42e3fdd41a2d3776920579f9
Author: Michael Jaumann <meta_dev at yahoo.com>
Date:   Tue Oct 28 08:38:54 2014 +0000

    renderHelper instead fixedPipeline part 1
    
    Change-Id: Ic866a76be6a06ee259e25e2b1901693cd35562aa

diff --git a/canvas/source/opengl/ogl_canvashelper.cxx b/canvas/source/opengl/ogl_canvashelper.cxx
index 8c4969b..58e234f 100644
--- a/canvas/source/opengl/ogl_canvashelper.cxx
+++ b/canvas/source/opengl/ogl_canvashelper.cxx
@@ -98,15 +98,16 @@ namespace oglcanvas
                             GLenum                           eSrcBlend,
                             GLenum                           eDstBlend,
                             const rendering::ARGBColor&      rColor,
-                            const geometry::RealPoint2D&     rPoint )
+                            const geometry::RealPoint2D&     rPoint,
+                            RenderHelper& mRenderHelper)
         {
-            TransformationPreserver aPreserver;
-            setupState(rTransform, eSrcBlend, eDstBlend, rColor);
-
-            glBegin(GL_POINTS);
-            glVertex2d(rPoint.X, rPoint.Y);
-            glEnd();
-
+            mRenderHelper.SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
+            glm::vec4 color  = glm::vec4( (float) rColor.Red,
+                                (float) rColor.Green,
+                                (float) rColor.Blue,
+                                (float) rColor.Alpha);
+            GLfloat vertices[] = {(float) rPoint.X, (float) rPoint.Y};
+            mRenderHelper.renderVertexConstColor(vertices, color, GL_POINTS);
             return true;
         }
 
@@ -116,16 +117,17 @@ namespace oglcanvas
                            GLenum                           eDstBlend,
                            const rendering::ARGBColor&      rColor,
                            const geometry::RealPoint2D&     rStartPoint,
-                           const geometry::RealPoint2D&     rEndPoint )
+                           const geometry::RealPoint2D&     rEndPoint,
+                           RenderHelper& mRenderHelper)
         {
-            TransformationPreserver aPreserver;
-            setupState(rTransform, eSrcBlend, eDstBlend, rColor);
-
-            glBegin(GL_LINES);
-            glVertex2d(rStartPoint.X, rStartPoint.Y);
-            glVertex2d(rEndPoint.X, rEndPoint.Y);
-            glEnd();
-
+            mRenderHelper.SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
+            glm::vec4 color  = glm::vec4( (float) rColor.Red,
+                                (float) rColor.Green,
+                                (float) rColor.Blue,
+                                (float) rColor.Alpha);
+            GLfloat vertices[] = {(float) rStartPoint.X, (float) rStartPoint.Y,
+                                  (float) rEndPoint.X, (float) rEndPoint.Y };
+            mRenderHelper.renderVertexConstColor(vertices, color, GL_LINES);
             return true;
         }
 
@@ -136,9 +138,12 @@ namespace oglcanvas
                                   const rendering::ARGBColor&            rColor,
                                   const ::basegfx::B2DPolyPolygonVector& rPolyPolygons )
         {
-            TransformationPreserver aPreserver;
-            setupState(rTransform, eSrcBlend, eDstBlend, rColor);
-
+            //move renderPolyPolygon here?
+         //   mRenderHelper.SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
+            glm::vec4 color  = glm::vec4( (float) rColor.Red,
+                                (float) rColor.Green,
+                                (float) rColor.Blue,
+                                (float) rColor.Alpha);
             ::basegfx::B2DPolyPolygonVector::const_iterator aCurr=rPolyPolygons.begin();
             const ::basegfx::B2DPolyPolygonVector::const_iterator aEnd=rPolyPolygons.end();
             while( aCurr != aEnd )
@@ -154,8 +159,9 @@ namespace oglcanvas
                                   const rendering::ARGBColor&            rColor,
                                   const ::basegfx::B2DPolyPolygonVector& rPolyPolygons )
         {
+            //no texture bind ?
             TransformationPreserver aPreserver;
-            setupState(rTransform, eSrcBlend, eDstBlend, rColor);
+            setupState(rTransform, eSrcBlend, eDstBlend);
 
             ::basegfx::B2DPolyPolygonVector::const_iterator aCurr=rPolyPolygons.begin();
             const ::basegfx::B2DPolyPolygonVector::const_iterator aEnd=rPolyPolygons.end();
@@ -177,8 +183,10 @@ namespace oglcanvas
                                           const rendering::Texture&                      rTexture,
                                           const ::basegfx::B2DPolyPolygonVector&         rPolyPolygons )
         {
+          //not complete
             TransformationPreserver aPreserver;
-            setupState(rTransform, eSrcBlend, eDstBlend, rendering::ARGBColor());
+          //  setupState(rTransform, eSrcBlend, eDstBlend, rendering::ARGBColor());
+            setupState(rTransform, eSrcBlend, eDstBlend);
 
             // convert to weird canvas textur coordinate system (not
             // [0,1]^2, but path coordinate system)
@@ -251,7 +259,7 @@ namespace oglcanvas
                                 const CanvasBitmap&              rBitmap )
         {
             TransformationPreserver aPreserver;
-            setupState(rTransform, eSrcBlend, eDstBlend, rColor);
+            setupState(rTransform, eSrcBlend, eDstBlend);
 
             return rBitmap.renderRecordedActions();
         }
@@ -263,14 +271,15 @@ namespace oglcanvas
                                     const rendering::ARGBColor&      rColor,
                                     const geometry::IntegerSize2D&   rPixelSize,
                                     const uno::Sequence<sal_Int8>&   rPixelData,
-                                    sal_uInt32                       nPixelCrc32 )
+                                    sal_uInt32                       nPixelCrc32,
+                                    RenderHelper&                    mRenderHelper)
+
         {
-            TransformationPreserver aPreserver;
-            setupState(rTransform, eSrcBlend, eDstBlend, rColor);
+            mRenderHelper.SetModelAndMVP(setupState(rTransform, eSrcBlend, eDstBlend));
 
             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,
@@ -284,17 +293,19 @@ namespace oglcanvas
                         GL_ONE_MINUS_SRC_ALPHA);
 
             // blend against fixed vertex color; texture alpha is multiplied in
-            glColor4f(1,1,1,1);
-
-            glBegin(GL_TRIANGLE_STRIP);
-            glTexCoord2f(0,0); glVertex2d(0,0);
-            glTexCoord2f(0,1); glVertex2d(0, rPixelSize.Height);
-            glTexCoord2f(1,0); glVertex2d(rPixelSize.Width,0);
-            glTexCoord2f(1,1); glVertex2d(rPixelSize.Width,rPixelSize.Height);
-            glEnd();
+            glm::vec4 color  = glm::vec4(1, 1, 1, 1);
+
+            GLfloat vertices[] = {0, 0,
+                                  0, (float) rPixelSize.Height,
+                                  (float) rPixelSize.Width, 0,
+                                  (float) rPixelSize.Width, (float) rPixelSize.Height };
+            GLfloat uvCoordinates[] = {0, 0,
+                                       0, 1,
+                                       1, 0,
+                                       1, 1 };
+            mRenderHelper.renderVertexUVTex(vertices,  uvCoordinates, color, GL_TRIANGLE_STRIP );
 
             glBindTexture(GL_TEXTURE_2D, 0);
-            glDisable(GL_TEXTURE_2D);
 
             return true;
         }
@@ -310,7 +321,8 @@ namespace oglcanvas
                                           const ::basegfx::B2DPolyPolygonVector& rPolyPolygons )
         {
             TransformationPreserver aPreserver;
-            setupState(rTransform, eSrcBlend, eDstBlend, rendering::ARGBColor());
+         //   setupState(rTransform, eSrcBlend, eDstBlend, rendering::ARGBColor());
+            setupState(rTransform, eSrcBlend, eDstBlend);
 
             const unsigned int nTexId=rHelper.getDeviceHelper()->getTextureCache().getTexture(
                 rPixelSize, rPixelData.getConstArray(), nPixelCrc32);
@@ -376,7 +388,9 @@ namespace oglcanvas
         mpDevice( NULL ),
         mpDeviceHelper( NULL ),
         mpRecordedActions()
-    {}
+    {
+       mRenderHelper.SetVP(1600, 900);//is this right?
+    }
 
     CanvasHelper::~CanvasHelper()
     {}
@@ -422,7 +436,7 @@ namespace oglcanvas
             setupGraphicsState( rAct, viewState, renderState );
             rAct.maFunction = ::boost::bind(&lcl_drawPoint,
                                             _1,_2,_3,_4,_5,
-                                            aPoint);
+                                            aPoint, boost::ref(mRenderHelper));
         }
     }
 
@@ -436,11 +450,11 @@ namespace oglcanvas
         {
             mpRecordedActions->push_back( Action() );
             Action& rAct=mpRecordedActions->back();
-
             setupGraphicsState( rAct, viewState, renderState );
             rAct.maFunction = ::boost::bind(&lcl_drawLine,
                                             _1,_2,_3,_4,_5,
-                                            aStartPoint,aEndPoint);
+                                            aStartPoint,aEndPoint,
+                                            boost::ref(mRenderHelper));
         }
     }
 
@@ -463,7 +477,7 @@ namespace oglcanvas
                                             geometry::RealPoint2D(
                                                 aBezierSegment.Px,
                                                 aBezierSegment.Py),
-                                            aEndPoint);
+                                            aEndPoint, boost::ref(mRenderHelper));
         }
     }
 
@@ -867,7 +881,8 @@ namespace oglcanvas
                                                     aSize, aARGBBytes,
                                                     rtl_crc32(0,
                                                               aARGBBytes.getConstArray(),
-                                                              aARGBBytes.getLength()));
+                                                              aARGBBytes.getLength()),
+                                                    boost::ref(mRenderHelper));
                 }
                 // TODO(F1): handle non-integer case
             }
diff --git a/canvas/source/opengl/ogl_canvashelper.hxx b/canvas/source/opengl/ogl_canvashelper.hxx
index 0dc98e0..da2f7ab 100644
--- a/canvas/source/opengl/ogl_canvashelper.hxx
+++ b/canvas/source/opengl/ogl_canvashelper.hxx
@@ -17,6 +17,7 @@
 
 #include <o3tl/cow_wrapper.hxx>
 #include <vector>
+#include "ogl_renderHelper.hxx"
 
 namespace oglcanvas
 {
@@ -230,6 +231,8 @@ namespace oglcanvas
             copied (used e.g. for CanvasBitmap)
          */
         RecordVectorT                                mpRecordedActions;
+
+        RenderHelper                                 mRenderHelper;
     };
 }
 
diff --git a/canvas/source/opengl/ogl_canvastools.cxx b/canvas/source/opengl/ogl_canvastools.cxx
index 8144e43..64f5dc4 100644
--- a/canvas/source/opengl/ogl_canvastools.cxx
+++ b/canvas/source/opengl/ogl_canvastools.cxx
@@ -21,6 +21,7 @@
 #include <com/sun/star/rendering/ARGBColor.hpp>
 
 #include <GL/glew.h>
+#include <glm/gtc/type_ptr.hpp>
 
 using namespace ::com::sun::star;
 
@@ -75,34 +76,21 @@ namespace oglcanvas
         }
     }
 
-    void setupState( const ::basegfx::B2DHomMatrix&   rTransform,
+    glm::mat4 setupState( const ::basegfx::B2DHomMatrix&   rTransform,
                      GLenum                           eSrcBlend,
-                     GLenum                           eDstBlend,
-                     const rendering::ARGBColor&      rColor )
+                     GLenum                           eDstBlend)
     {
-        double aGLTransform[] =
+        float aGLTransform[] =
             {
-                rTransform.get(0,0), rTransform.get(1,0), 0, 0,
-                rTransform.get(0,1), rTransform.get(1,1), 0, 0,
+                (float) rTransform.get(0,0), (float) rTransform.get(1,0), 0, 0,
+                (float) rTransform.get(0,1), (float) rTransform.get(1,1), 0, 0,
                 0,                   0,                   1, 0,
-                rTransform.get(0,2), rTransform.get(1,2), 0, 1
+                (float) rTransform.get(0,2), (float) rTransform.get(1,2), 0, 1
             };
-        glMultMatrixd(aGLTransform);
 
         glEnable(GL_BLEND);
         glBlendFunc(eSrcBlend, eDstBlend);
-
-        glColor4d(rColor.Red,
-                  rColor.Green,
-                  rColor.Blue,
-                  rColor.Alpha);
-
-        // GL 1.2:
-        // glBlendEquation( GLenum mode );
-        // glBlendColor( GLclampf red, GLclampf green,GLclampf blue, GLclampf alpha );
-        // glConvolutionFilter1D
-        // glConvolutionFilter2D
-        // glSeparableFilter2D
+        return glm::make_mat4(aGLTransform);
     }
 
     void renderOSD( const std::vector<double>& rNumbers, double scale )
diff --git a/canvas/source/opengl/ogl_canvastools.hxx b/canvas/source/opengl/ogl_canvastools.hxx
index 2cd727c..4ce9819 100644
--- a/canvas/source/opengl/ogl_canvastools.hxx
+++ b/canvas/source/opengl/ogl_canvastools.hxx
@@ -12,6 +12,7 @@
 
 #include <sal/config.h>
 #include <vector>
+#include <glm/glm.hpp>
 
 namespace com { namespace sun { namespace star { namespace rendering {
     struct ARGBColor;
@@ -23,14 +24,14 @@ namespace basegfx {
 
 namespace oglcanvas
 {
-    void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly );
-    void renderPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly );
-    void setupState( const ::basegfx::B2DHomMatrix&                rTransform,
-                     unsigned int                                  eSrcBlend,
-                     unsigned int                                  eDstBlend,
-                     const ::com::sun::star::rendering::ARGBColor& rColor );
-
-    void renderOSD( const std::vector<double>& rNumbers, double scale );
+        void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly );
+        void renderPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPoly );
+        glm::mat4 setupState( const ::basegfx::B2DHomMatrix&                rTransform,
+                         unsigned int                                  eSrcBlend,
+                         unsigned int                                  eDstBlend );
+
+        void renderOSD( const std::vector<double>& rNumbers, double scale );
+
 }
 
 #endif
commit 0f87c270637420a947aa2298ef494cdcb5277b45
Author: Michael Jaumann <meta_dev at yahoo.com>
Date:   Tue Oct 28 08:00:18 2014 +0000

    removed glDisable(GL_TEXTURE_2D)
    
    Change-Id: I6d816d7518c6e551fb1b0489154fa3b0bfe0ddc9

diff --git a/canvas/source/opengl/ogl_canvascustomsprite.cxx b/canvas/source/opengl/ogl_canvascustomsprite.cxx
index 15eee9e..f6126f5 100644
--- a/canvas/source/opengl/ogl_canvascustomsprite.cxx
+++ b/canvas/source/opengl/ogl_canvascustomsprite.cxx
@@ -220,7 +220,6 @@ namespace oglcanvas
                 }
 
                 glBindTexture(GL_TEXTURE_2D, 0);
-                glDisable(GL_TEXTURE_2D);
             }
         // translate sprite to output position
         mRenderHelper.SetModelAndMVP(glm::translate(glm::vec3(maPosition.getX(), maPosition.getY(), 0)));
commit 8e135605b4ab9a6b1efbe900454ea4e93d1850dc
Author: Michael Jaumann <meta_dev at yahoo.com>
Date:   Mon Oct 27 09:07:18 2014 +0000

    use glm::vec4 instead of array for color
    
    Change-Id: I9649b5a0346ed6f4a8b6a169b2aab757b2587229

diff --git a/canvas/source/opengl/ogl_canvascustomsprite.cxx b/canvas/source/opengl/ogl_canvascustomsprite.cxx
index 3f95107..15eee9e 100644
--- a/canvas/source/opengl/ogl_canvascustomsprite.cxx
+++ b/canvas/source/opengl/ogl_canvascustomsprite.cxx
@@ -173,7 +173,7 @@ namespace oglcanvas
                 glBlendFunc(GL_SRC_ALPHA,
                             GL_ONE_MINUS_SRC_ALPHA);
 
-                GLfloat color[] = {1, 1, 1, (float)mfAlpha};
+                glm::vec4 color  =  glm::vec4(1, 1, 1, (float)mfAlpha);
 
                 if( mxClip.is() )
                 {
@@ -230,9 +230,8 @@ namespace oglcanvas
                               (float) maSize.Width+4, -2,
                               -2, -2,
                               (float) maSize.Width+4, (float) maSize.Height+4 };
-        GLfloat color[] = {1, 0, 0, 1};
 
-        mRenderHelper.renderVertexConstColor(vertices, color, GL_LINE_STRIP);
+        mRenderHelper.renderVertexConstColor(vertices, glm::vec4(1, 0, 0, 1), GL_LINE_STRIP);
 
         std::vector<double> aVec;
         aVec.push_back(mfAlpha);
diff --git a/canvas/source/opengl/ogl_renderHelper.cxx b/canvas/source/opengl/ogl_renderHelper.cxx
index 3bc934e..27cf96a 100644
--- a/canvas/source/opengl/ogl_renderHelper.cxx
+++ b/canvas/source/opengl/ogl_renderHelper.cxx
@@ -54,14 +54,14 @@ namespace oglcanvas
         m_Model = mat;
         m_MVP = m_Projection * m_View * m_Model;
     }
-    void RenderHelper::renderVertexConstColor(GLfloat vertices[], GLfloat color[4], GLenum mode) const
+    void RenderHelper::renderVertexConstColor(GLfloat vertices[], glm::vec4 color, GLenum mode) const
     {
         glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
         glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
 
         glUseProgram(m_texProgID);
 
-        glUniform4f(m_texColorUnf,color[0], color[1], color[2], color[3]);
+        glUniform4fv(m_texColorUnf, 4, glm::value_ptr(color));
         glEnableVertexAttribArray(m_texPosAttrb); //vertices
 
         glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
@@ -82,7 +82,7 @@ namespace oglcanvas
 
     }
     //Renders a TriangleStrip, Texture has to be stored in TextureUnit0
-    void RenderHelper::renderVertexUVTex(GLfloat vertices[], GLfloat uvCoordinates[], GLfloat color[4], GLenum mode) const
+    void RenderHelper::renderVertexUVTex(GLfloat vertices[], GLfloat uvCoordinates[], glm::vec4 color, GLenum mode) const
     {
         glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
         glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
@@ -93,7 +93,7 @@ namespace oglcanvas
         glUseProgram(m_simpleProgID);
 
         glUniform1i(m_simpleTexUnf, 0); //Use texture Unit 0
-        glUniform4f(m_simpleColorUnf, color[0], color[1], color[2], color[3]);
+        glUniform4fv(m_simpleColorUnf, 4, glm::value_ptr(color));
         glUniformMatrix4fv(m_simpleMVPUnf, 1, GL_FALSE, &m_MVP[0][0]);
 
         glEnableVertexAttribArray(m_simplePosAttrb);
@@ -102,7 +102,7 @@ namespace oglcanvas
             m_simplePosAttrb,
             2,                            // size
             GL_FLOAT,                     // type
-            GL_FALSE,                     // normalized?
+            GL_FALSE,                     // normalized?v
             0,                            // stride
             (void*)0                      // array buffer offset
         );
@@ -137,7 +137,7 @@ 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(GLfloat vertices[], GLfloat fWidth, GLfloat fHeight, GLfloat color[4], GLenum mode) const
+    void RenderHelper::renderVertexTex(GLfloat vertices[], GLfloat fWidth, GLfloat fHeight, glm::vec4 color, GLenum mode) const
     {
         glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
         glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
@@ -147,7 +147,7 @@ namespace oglcanvas
         //Set Uniforms
         glUniform1i(m_manTexUnf, 0);
         glUniform2f(m_manCordUnf,fWidth,fHeight);
-        glUniform4f(m_manColorUnf, color[0], color[1], color[2], color[3] );
+        glUniform4fv(m_manColorUnf, 4,  glm::value_ptr(color));
         glUniformMatrix4fv(m_manMVPUnf, 1, GL_FALSE, &m_MVP[0][0]);
 
         glEnableVertexAttribArray(m_manPosAttrb);
diff --git a/canvas/source/opengl/ogl_renderHelper.hxx b/canvas/source/opengl/ogl_renderHelper.hxx
index 0a63ab1..a7e7a54 100644
--- a/canvas/source/opengl/ogl_renderHelper.hxx
+++ b/canvas/source/opengl/ogl_renderHelper.hxx
@@ -1,15 +1,18 @@
+#ifndef RENDER_HELPER
+#define RENDER_HELPER
 #include <GL/glew.h>
 #include <glm/glm.hpp>
 #include "glm/gtx/transform.hpp"
+#include <glm/gtc/type_ptr.hpp>
 namespace oglcanvas
 {
     class RenderHelper
     {
     public:
 
-        void renderVertexConstColor(GLfloat vertices[] , GLfloat color[4], GLenum mode) const ;
-        void renderVertexUVTex(GLfloat vertices[], GLfloat uvCoordinates[], GLfloat color[4], GLenum mode) const ;
-        void renderVertexTex(GLfloat vertices[], GLfloat, GLfloat, GLfloat color[4], GLenum mode) const;
+        void renderVertexConstColor(GLfloat vertices[], glm::vec4 color, GLenum mode) const;
+        void renderVertexUVTex(GLfloat vertices[], GLfloat uvCoordinates[], glm::vec4 color, GLenum mode) const;
+        void renderVertexTex(GLfloat vertices[], GLfloat, GLfloat, glm::vec4 color, GLenum mode) const;
 
         RenderHelper();
 
@@ -59,4 +62,7 @@ namespace oglcanvas
         glm::mat4                                         m_MVP;
 
     };
-}
\ No newline at end of file
+}
+
+
+#endif /* RENDER_HELPER */
\ No newline at end of file


More information about the Libreoffice-commits mailing list