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

Michael Jaumann meta_dev at yahoo.com
Fri Oct 24 00:44:53 PDT 2014


 canvas/source/opengl/ogl_canvascustomsprite.cxx |   24 +++++----------------
 canvas/source/opengl/ogl_canvascustomsprite.hxx |    2 -
 canvas/source/opengl/ogl_renderHelper.cxx       |   27 ++++++++++++++++++++++++
 canvas/source/opengl/ogl_renderHelper.hxx       |   27 +++++++++++++++++++++++-
 4 files changed, 60 insertions(+), 20 deletions(-)

New commits:
commit 964c17891c580c6ef8821b5f9c3d380f448565ca
Author: Michael Jaumann <meta_dev at yahoo.com>
Date:   Fri Oct 24 07:39:11 2014 +0000

    renderHelper uses MVP shader, removed matricestack
    
    Change-Id: I850216b6d52df52f71672d3b7b8142de90a63f83

diff --git a/canvas/source/opengl/ogl_canvascustomsprite.cxx b/canvas/source/opengl/ogl_canvascustomsprite.cxx
index 812ab73..3f95107 100644
--- a/canvas/source/opengl/ogl_canvascustomsprite.cxx
+++ b/canvas/source/opengl/ogl_canvascustomsprite.cxx
@@ -47,6 +47,7 @@ namespace oglcanvas
         ::canvas::tools::setIdentityAffineMatrix2D(maTransformation);
         maCanvasHelper.init( *rRefDevice.get(),
                              rDeviceHelper );
+        mRenderHelper.SetVP(1600, 900);//is this right?
     }
 
     void CanvasCustomSprite::disposeThis()
@@ -126,30 +127,14 @@ namespace oglcanvas
     }
 
 
-    bool CanvasCustomSprite::renderSprite() const
+    bool CanvasCustomSprite::renderSprite()
     {
         if( ::basegfx::fTools::equalZero( mfAlpha ) )
             return true;
 
-        TransformationPreserver aPreserver1;
         const ::basegfx::B2IVector aSpriteSizePixel(
             ::canvas::tools::roundUp( maSize.Width ),
             ::canvas::tools::roundUp( maSize.Height ));
-        // translate sprite to output position
-        glTranslated(maPosition.getX(), maPosition.getY(), 0);
-
-        {
-            TransformationPreserver aPreserver2;
-
-            // apply sprite content transformation matrix
-            double aGLTransform[] =
-                {
-                    maTransformation.m00, maTransformation.m10, 0, 0,
-                    maTransformation.m01, maTransformation.m11, 0, 0,
-                    0,                    0,                    1, 0,
-                    maTransformation.m02, maTransformation.m12, 0, 1
-                };
-            glMultMatrixd(aGLTransform);
 
             IBufferContextSharedPtr pBufferContext;
             if( mfAlpha != 1.0 || mxClip.is() )
@@ -168,6 +153,8 @@ namespace oglcanvas
 
             if( pBufferContext )
             {
+                //no transformation
+                mRenderHelper.SetModelAndMVP(glm::mat4());
                 // content ended up in background buffer - compose to
                 // screen now. Calls below switches us back to window
                 // context, and binds to generated, dynamic texture
@@ -235,7 +222,8 @@ 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)));
         GLfloat vertices[] = {-2, -2,
                               -2, (float) maSize.Height+4,
                               (float) maSize.Width+4, (float) maSize.Height+4,
diff --git a/canvas/source/opengl/ogl_canvascustomsprite.hxx b/canvas/source/opengl/ogl_canvascustomsprite.hxx
index b678f1a..6f78a72 100644
--- a/canvas/source/opengl/ogl_canvascustomsprite.hxx
+++ b/canvas/source/opengl/ogl_canvascustomsprite.hxx
@@ -78,7 +78,7 @@ namespace oglcanvas
         double getPriority() const { return mfPriority; }
 
         /// Render sprite content at sprite position
-        bool renderSprite() const;
+        bool renderSprite();
 
     private:
         /** MUST hold here, too, since CanvasHelper only contains a
diff --git a/canvas/source/opengl/ogl_renderHelper.cxx b/canvas/source/opengl/ogl_renderHelper.cxx
index 5447a54..3bc934e 100644
--- a/canvas/source/opengl/ogl_renderHelper.cxx
+++ b/canvas/source/opengl/ogl_renderHelper.cxx
@@ -4,6 +4,9 @@
 namespace oglcanvas
 {
     RenderHelper::RenderHelper()
+    : m_iWidth(1600) //Why this dimensions?
+    , m_iHeight(900)
+    , m_Model(glm::mat4(1.0f))
     {
         InitOpenGL();
     }
@@ -16,10 +19,16 @@ namespace oglcanvas
         // Get a handle for uniforms
         m_manTexUnf = glGetUniformLocation(m_texManProgID, "TextTex");
         m_simpleTexUnf = glGetUniformLocation(m_simpleProgID, "TextTex");
+
         m_manCordUnf = glGetUniformLocation(m_texManProgID, "texCord");
         m_texColorUnf = glGetUniformLocation(m_texProgID, "constantColor");
+
         m_manColorUnf = glGetUniformLocation(m_texManProgID,"colorTex");
         m_simpleColorUnf = glGetUniformLocation(m_simpleProgID,"colorTex");
+
+        m_texMVPUnf = glGetUniformLocation(m_texProgID, "MVP");
+        m_manMVPUnf = glGetUniformLocation(m_texManProgID, "MVP");
+        m_simpleMVPUnf = glGetUniformLocation(m_simpleProgID, "MVP");
         //Gen Buffers for texturecoordinates/vertices
         glGenBuffers(1, &m_vertexBuffer);
         glGenBuffers(1, &m_uvBuffer);
@@ -27,8 +36,24 @@ namespace oglcanvas
         m_simpleUvAttrb = glGetAttribLocation(m_simpleProgID ,"UV");
         m_simplePosAttrb = glGetAttribLocation(m_simpleProgID ,"vPosition");
         m_texPosAttrb = glGetAttribLocation(m_texProgID ,"vPosition");
+
+        glViewport(0, 0, m_iWidth, m_iHeight);
     }
+    //Todo figgure out, which parameters i should use :)
+    void RenderHelper::SetVP(int width, int height)
+    {
+        m_Projection = glm::ortho(0.f, float(m_iWidth), 0.f, float(m_iHeight), -4.f, 3.f);
+        m_Projection = m_Projection * glm::scale(glm::vec3((float)width / m_iWidth, -(float)height / m_iHeight, 1.0f));
 
+        m_View       = glm::lookAt(glm::vec3(0,m_iHeight,1),
+                                   glm::vec3(0,m_iHeight,0),
+                                   glm::vec3(0,1,0) );
+    }
+    void RenderHelper::SetModelAndMVP(glm::mat4 mat)
+    {
+        m_Model = mat;
+        m_MVP = m_Projection * m_View * m_Model;
+    }
     void RenderHelper::renderVertexConstColor(GLfloat vertices[], GLfloat color[4], GLenum mode) const
     {
         glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
@@ -69,6 +94,7 @@ namespace oglcanvas
 
         glUniform1i(m_simpleTexUnf, 0); //Use texture Unit 0
         glUniform4f(m_simpleColorUnf, color[0], color[1], color[2], color[3]);
+        glUniformMatrix4fv(m_simpleMVPUnf, 1, GL_FALSE, &m_MVP[0][0]);
 
         glEnableVertexAttribArray(m_simplePosAttrb);
         glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
@@ -122,6 +148,7 @@ namespace oglcanvas
         glUniform1i(m_manTexUnf, 0);
         glUniform2f(m_manCordUnf,fWidth,fHeight);
         glUniform4f(m_manColorUnf, color[0], color[1], color[2], color[3] );
+        glUniformMatrix4fv(m_manMVPUnf, 1, GL_FALSE, &m_MVP[0][0]);
 
         glEnableVertexAttribArray(m_manPosAttrb);
         glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
diff --git a/canvas/source/opengl/ogl_renderHelper.hxx b/canvas/source/opengl/ogl_renderHelper.hxx
index 454b3ff..0a63ab1 100644
--- a/canvas/source/opengl/ogl_renderHelper.hxx
+++ b/canvas/source/opengl/ogl_renderHelper.hxx
@@ -1,4 +1,6 @@
 #include <GL/glew.h>
+#include <glm/glm.hpp>
+#include "glm/gtx/transform.hpp"
 namespace oglcanvas
 {
     class RenderHelper
@@ -8,12 +10,19 @@ namespace oglcanvas
         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 dispose();
+
         RenderHelper();
+
+        void SetVP(int width, int height);
+        void SetModelAndMVP(glm::mat4 mat);
+        void dispose();
+
     private:
         RenderHelper&  operator = (const RenderHelper& other);
         RenderHelper(const RenderHelper& other);
+
         void  InitOpenGL();
+
         GLuint                                            m_vertexBuffer;
         GLuint                                            m_uvBuffer;
 
@@ -23,15 +32,31 @@ namespace oglcanvas
         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;
+        //dimension
+        int                                               m_iWidth;
+        int                                               m_iHeight;
+
+        // Projection matrix : default 45 degree Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
+        glm::mat4                                         m_Projection;
+        // Camera matrix
+        glm::mat4                                         m_View;
+        // Model matrix : an identity matrix (model will be at the origin
+        glm::mat4                                         m_Model;
+        // Our ModelViewProjection : multiplication of our 3 matrices
+        glm::mat4                                         m_MVP;
+
     };
 }
\ No newline at end of file


More information about the Libreoffice-commits mailing list