[Libreoffice-commits] core.git: Branch 'feature/chart-3d-chart2' - 5 commits - chart2/opengl chart2/Package_opengl.mk chart2/source

weigao weigao at multicorewareinc.com
Fri Jun 20 18:28:02 PDT 2014


 chart2/Package_opengl.mk                    |    2 
 chart2/opengl/screenTextFragmentShader.glsl |    3 
 chart2/opengl/textFragmentShader.glsl       |    3 
 chart2/opengl/textFragmentShaderBatch.glsl  |   20 +
 chart2/opengl/textVertexShaderBatch.glsl    |   22 ++
 chart2/source/view/inc/GL3DRenderer.hxx     |   44 +++-
 chart2/source/view/main/3DChartObjects.cxx  |   11 -
 chart2/source/view/main/GL3DRenderer.cxx    |  288 +++++++++++++++++++++++-----
 8 files changed, 342 insertions(+), 51 deletions(-)

New commits:
commit e4939a72af3baff282a50bf1bce76c3184f26403
Author: weigao <weigao at multicorewareinc.com>
Date:   Wed Jun 18 08:21:41 2014 -0700

    add code to call batch texture render
    
    Change-Id: I09da7c49eb11da9ea2bc18a5e13f2fd2c0d6bd8f

diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 065b5fb..5f2167c 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -143,6 +143,23 @@ struct TextInfo
     float vertex[12];
 };
 
+struct TextureArrayInfo
+{
+    size_t subTextureNum;
+    int textureArrayWidth;
+    int textureArrayHeight;
+    GLuint textureID;
+};
+struct TextInfoBatch
+{
+    size_t batchNum;
+    std::vector<glm::vec4> idList;
+    std::vector<TextureArrayInfo> texture;
+    std::vector<glm::vec3> vertexList;
+    std::vector<glm::vec3> textureCoordList;
+};
+
+
 struct BatchBarInfo
 {
     std::vector <glm::mat4> modelMatrixList;
@@ -235,6 +252,18 @@ private:
     void UpdateBatch3DUniformBlock();
     void RenderBatchBars(bool bNewScene);
     void CheckGLSLVersion();
+    void RenderTextShapeBatch();
+    void ReleaseTextShapesBatch();
+    void CreateTextTextureSingle(const boost::shared_array<sal_uInt8> &bitmapBuf,
+                           ::Size maSizePixels,
+                           glm::vec3 vTopLeft,glm::vec3 vTopRight,
+                           glm::vec3 vBottomRight, glm::vec3 vBottomLeft,
+                           sal_uInt32 nUniqueId);
+    void CreateTextTextureBatch(const boost::shared_array<sal_uInt8> &bitmapBuf,
+                       ::Size maSizePixels,
+                       glm::vec3 vTopLeft,glm::vec3 vTopRight,
+                       glm::vec3 vBottomRight, glm::vec3 vBottomLeft,
+                       sal_uInt32 nUniqueId);
 private:
 
     struct ShaderResources
@@ -290,6 +319,14 @@ private:
         GLint m_3DBatchNormalID;
         GLint m_3DBatchColorID;
 
+        //Batch render text
+        bool mbTexBatchSupport;
+        GLint m_BatchTextProID;
+        GLint m_BatchTextMatrixID;
+        GLint m_BatchTextVertexID;
+        GLint m_BatchTextTexCoordID;
+        GLint m_BatchTextTexID;
+
         ShaderResources();
         ~ShaderResources();
 
@@ -362,7 +399,7 @@ private:
     std::vector <TextInfo> m_TextInfoList;
     std::vector <TextInfo> m_ScreenTextInfoList;
     GLuint m_TextTexCoordBuf;
-
+    GLuint m_TextTexCoordBufBatch;
     int m_uiSelectFrameCounter;
 
     std::vector<glm::vec3> m_Vertices;
@@ -392,6 +429,7 @@ private:
     MaterialParameters m_Batchmaterial;
     GLuint m_Batch3DUBOBuffer;
     GLint m_Batch3DActualSizeLight;
+    TextInfoBatch m_TextInfoBatch;
     //for 3.0 version
     int m_iLightNum;
     glm::vec4 m_Ambient;
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index cf22a86..60b3cb2 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -88,6 +88,7 @@ OpenGL3DRenderer::OpenGL3DRenderer():
 
 OpenGL3DRenderer::~OpenGL3DRenderer()
 {
+    ReleaseShapes();
     // delete buffers
     glDeleteBuffers(1, &m_CubeVertexBuf);
     glDeleteBuffers(1, &m_CubeNormalBuf);
@@ -103,10 +104,18 @@ OpenGL3DRenderer::~OpenGL3DRenderer()
     glDeleteBuffers(1, &m_Batch3DUBOBuffer);
     glDeleteBuffers(1, &m_3DUBOBuffer);
     glDeleteBuffers(1, &m_3DUBOBuffer);
+    glDeleteBuffers(1, &m_TextTexCoordBufBatch);
 
     glDeleteFramebuffers(1, &mnPickingFbo);
     glDeleteRenderbuffers(1, &mnPickingRboDepth);
     glDeleteRenderbuffers(1, &mnPickingRboColor);
+
+    for (size_t i = 0; i < m_TextInfoBatch.texture.size(); i++)
+    {
+        glDeleteTextures(1, &m_TextInfoBatch.texture[i].textureID);
+    }
+    m_TextInfoBatch.texture.clear();
+
 }
 
 OpenGL3DRenderer::ShaderResources::ShaderResources()
@@ -139,6 +148,12 @@ OpenGL3DRenderer::ShaderResources::ShaderResources()
     , m_3DBatchNormalID(0)
     , m_3DBatchColorID(0)
     , m_b330Support(false)
+    , m_BatchTextProID(0)
+    , m_BatchTextMatrixID(0)
+    , m_BatchTextVertexID(0)
+    , m_BatchTextTexCoordID(0)
+    , m_BatchTextTexID(0)
+    , mbTexBatchSupport(false)
 {
 }
 
@@ -149,6 +164,7 @@ OpenGL3DRenderer::ShaderResources::~ShaderResources()
     glDeleteProgram(m_ScreenTextProID);
     glDeleteProgram(m_3DProID);
     glDeleteProgram(m_3DBatchProID);
+    glDeleteProgram(m_BatchTextProID);
 }
 
 void OpenGL3DRenderer::CheckGLSLVersion()
@@ -204,6 +220,27 @@ void OpenGL3DRenderer::ShaderResources::LoadShaders()
         m_3DBatchVertexID = glGetAttribLocation(m_3DBatchProID, "vertexPositionModelspace");
         m_3DBatchNormalID = glGetAttribLocation(m_3DBatchProID, "vertexNormalModelspace");
         m_3DBatchColorID = glGetAttribLocation(m_3DBatchProID, "barColor");
+        //check whether the texture array is support
+        GLint numExtensions = 0;
+        glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
+        for( GLint i = 0; i < numExtensions; ++i )
+        {
+            OUString currExt = ::rtl::OUString::createFromAscii((char*)glGetStringi(GL_EXTENSIONS, i));
+            if (currExt == "GL_EXT_texture_array")
+            {
+                mbTexBatchSupport = true;
+                break;
+            }
+        }
+        if (mbTexBatchSupport)
+        {
+            m_BatchTextProID = OpenGLHelper::LoadShaders("textVertexShaderBatch", "textFragmentShaderBatch");
+            m_BatchTextMatrixID = glGetUniformLocation(m_BatchTextProID, "MVP");
+            m_BatchTextTexID = glGetUniformLocation(m_BatchTextProID, "texArray");
+            m_BatchTextVertexID = glGetAttribLocation(m_BatchTextProID, "vPosition");
+            m_BatchTextTexCoordID = glGetAttribLocation(m_BatchTextProID, "texCoord");
+        }
+        mbTexBatchSupport = m_BatchTextProID ? true : false;
     }
     else
     {
@@ -227,11 +264,14 @@ void OpenGL3DRenderer::ShaderResources::LoadShaders()
         m_3DVertexID = glGetAttribLocation(m_3DProID, "vertexPositionModelspace");
         m_3DNormalID = glGetAttribLocation(m_3DProID, "vertexNormalModelspace");
     }
-    m_TextProID = OpenGLHelper::LoadShaders("textVertexShader", "textFragmentShader");
-    m_TextMatrixID = glGetUniformLocation(m_TextProID, "MVP");
-    m_TextVertexID = glGetAttribLocation(m_TextProID, "vPosition");
-    m_TextTexCoordID = glGetAttribLocation(m_TextProID, "texCoord");
-    m_TextTexID = glGetUniformLocation(m_TextProID, "TextTex");
+    if (!mbTexBatchSupport)
+    {
+        m_TextProID = OpenGLHelper::LoadShaders("textVertexShader", "textFragmentShader");
+        m_TextMatrixID = glGetUniformLocation(m_TextProID, "MVP");
+        m_TextVertexID = glGetAttribLocation(m_TextProID, "vPosition");
+        m_TextTexCoordID = glGetAttribLocation(m_TextProID, "texCoord");
+        m_TextTexID = glGetUniformLocation(m_TextProID, "TextTex");
+    }
 
     m_ScreenTextProID = OpenGLHelper::LoadShaders("screenTextVertexShader", "screenTextFragmentShader");
     m_ScreenTextVertexID = glGetAttribLocation(m_ScreenTextProID, "vPosition");
@@ -303,6 +343,7 @@ void OpenGL3DRenderer::init()
     glGenBuffers(1, &m_BatchModelMatrixBuf);
     glGenBuffers(1, &m_BatchNormalMatrixBuf);
     glGenBuffers(1, &m_BatchColorBuf);
+    glGenBuffers(1, &m_TextTexCoordBufBatch);
     glGenBuffers(1, &m_BoundBox);
     glBindBuffer(GL_ARRAY_BUFFER, m_BoundBox);
     glBufferData(GL_ARRAY_BUFFER, sizeof(boundBox), boundBox, GL_STATIC_DRAW);
@@ -344,6 +385,7 @@ void OpenGL3DRenderer::init()
         Init3DUniformBlock();
         InitBatch3DUniformBlock();
     }
+    m_TextInfoBatch.batchNum = 512;
     CHECK_GL_ERROR();
     glViewport(0, 0, m_iWidth, m_iHeight);
     Set3DSenceInfo(0xFFFFFF, true);
@@ -1607,11 +1649,11 @@ void OpenGL3DRenderer::CreateScreenTextTexture(
     m_ScreenTextInfoList.push_back(aTextInfo);
 }
 
-void OpenGL3DRenderer::CreateTextTexture(const boost::shared_array<sal_uInt8> &bitmapBuf,
-                                         ::Size maSizePixels,
-                                         glm::vec3 vTopLeft,glm::vec3 vTopRight,
-                                         glm::vec3 vBottomRight, glm::vec3 vBottomLeft,
-                                         sal_uInt32 nUniqueId)
+void OpenGL3DRenderer::CreateTextTextureSingle(const boost::shared_array<sal_uInt8> &bitmapBuf,
+                           ::Size maSizePixels,
+                           glm::vec3 vTopLeft,glm::vec3 vTopRight,
+                           glm::vec3 vBottomRight, glm::vec3 vBottomLeft,
+                           sal_uInt32 nUniqueId)
 {
     long bmpWidth = maSizePixels.Width();
     long bmpHeight = maSizePixels.Height();
@@ -1652,6 +1694,91 @@ void OpenGL3DRenderer::CreateTextTexture(const boost::shared_array<sal_uInt8> &b
     glBindTexture(GL_TEXTURE_2D, 0);
     CHECK_GL_ERROR();
     m_TextInfoList.push_back(aTextInfo);
+
+}
+
+
+void OpenGL3DRenderer::CreateTextTextureBatch(const boost::shared_array<sal_uInt8> &bitmapBuf,
+                   ::Size maSizePixels,
+                   glm::vec3 vTopLeft,glm::vec3 vTopRight,
+                   glm::vec3 vBottomRight, glm::vec3 vBottomLeft,
+                   sal_uInt32 nUniqueId)
+{
+    long bmpWidth = maSizePixels.Width();
+    long bmpHeight = maSizePixels.Height();
+    glm::vec4 id = getColorAsVector(nUniqueId);
+    m_TextInfoBatch.idList.push_back(id);
+    m_TextInfoBatch.vertexList.push_back(glm::vec3(vBottomRight.x, vBottomRight.y, vBottomRight.z));
+    m_TextInfoBatch.vertexList.push_back(glm::vec3(vTopRight.x, vTopRight.y, vTopRight.z));
+    m_TextInfoBatch.vertexList.push_back(glm::vec3(vTopLeft.x, vTopLeft.y, vTopLeft.z));
+    m_TextInfoBatch.vertexList.push_back(glm::vec3(vBottomLeft.x, vBottomLeft.y, vBottomLeft.z));
+    //find the last vector, which size is small than default batch number;
+    size_t index = 0;
+    while ((m_TextInfoBatch.texture.size() > 0) &&
+           (m_TextInfoBatch.texture[index].subTextureNum >= m_TextInfoBatch.batchNum) &&
+           (index < m_TextInfoBatch.texture.size() - 1))
+    {
+        index++;
+    }
+    //if the sub texture number of the last texture array reach the largest, create a new textur array
+    if ((m_TextInfoBatch.texture.size() == 0) ||
+        (m_TextInfoBatch.texture[index].subTextureNum >= m_TextInfoBatch.batchNum))
+    {
+        TextureArrayInfo textureArray = {0};
+        glGenTextures(1, &textureArray.textureID);
+        CHECK_GL_ERROR();
+        glBindTexture(GL_TEXTURE_2D_ARRAY, textureArray.textureID);
+        glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        CHECK_GL_ERROR();
+        textureArray.textureArrayWidth = bmpHeight * 8;
+        textureArray.textureArrayHeight = bmpHeight;
+        glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, textureArray.textureArrayWidth, textureArray.textureArrayHeight,
+                     m_TextInfoBatch.batchNum, 0, GL_RGB,  GL_UNSIGNED_BYTE, NULL);
+        CHECK_GL_ERROR();
+        if (m_TextInfoBatch.texture.size() > 0)
+        {
+            index++;
+        }
+        m_TextInfoBatch.texture.push_back(textureArray);
+        glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
+    }
+    glBindTexture(GL_TEXTURE_2D_ARRAY, m_TextInfoBatch.texture[index].textureID);
+    CHECK_GL_ERROR();
+    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, m_TextInfoBatch.texture[index].subTextureNum, bmpWidth, bmpHeight, 1, GL_RGB, GL_UNSIGNED_BYTE, bitmapBuf.get());
+    CHECK_GL_ERROR();
+        //calc texture coordinate
+    m_TextInfoBatch.textureCoordList.push_back(glm::vec3((float)bmpWidth / (float)m_TextInfoBatch.texture[index].textureArrayWidth,
+                                                         0,
+                                                         m_TextInfoBatch.texture[index].subTextureNum));
+    m_TextInfoBatch.textureCoordList.push_back(glm::vec3((float)bmpWidth / (float)m_TextInfoBatch.texture[index].textureArrayWidth,
+                                                         (float)bmpHeight/ (float)m_TextInfoBatch.texture[index].textureArrayHeight,
+                                                         m_TextInfoBatch.texture[index].subTextureNum));
+    m_TextInfoBatch.textureCoordList.push_back(glm::vec3(0,
+                                                         (float)bmpHeight/ (float)m_TextInfoBatch.texture[index].textureArrayHeight,
+                                                         m_TextInfoBatch.texture[index].subTextureNum));
+    m_TextInfoBatch.textureCoordList.push_back(glm::vec3(0,
+                                                         0,
+                                                         m_TextInfoBatch.texture[index].subTextureNum));
+    m_TextInfoBatch.texture[index].subTextureNum++;
+    glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
+}
+void OpenGL3DRenderer::CreateTextTexture(const boost::shared_array<sal_uInt8> &bitmapBuf,
+                                         ::Size maSizePixels,
+                                         glm::vec3 vTopLeft,glm::vec3 vTopRight,
+                                         glm::vec3 vBottomRight, glm::vec3 vBottomLeft,
+                                         sal_uInt32 nUniqueId)
+{
+    if (maResources.mbTexBatchSupport)
+    {
+        CreateTextTextureBatch(bitmapBuf, maSizePixels, vTopLeft, vTopRight, vBottomRight, vBottomLeft, nUniqueId);
+    }
+    else
+    {
+        CreateTextTextureSingle(bitmapBuf, maSizePixels, vTopLeft, vTopRight, vBottomRight, vBottomLeft, nUniqueId);
+    }
 }
 
 void OpenGL3DRenderer::ReleaseTextShapes()
@@ -1729,7 +1856,67 @@ void OpenGL3DRenderer::RenderScreenTextShape()
     }
     CHECK_GL_ERROR();
 }
+void OpenGL3DRenderer::ReleaseTextShapesBatch()
+{
+    for (size_t i = 0; i < m_TextInfoBatch.texture.size(); i++)
+    {
+        m_TextInfoBatch.texture[i].subTextureNum = 0;
+    }
+    m_TextInfoBatch.vertexList.clear();
+    m_TextInfoBatch.textureCoordList.clear();
+    m_TextInfoBatch.idList.clear();
+}
 
+void OpenGL3DRenderer::RenderTextShapeBatch()
+{
+    glm::mat4 aMVP = m_3DProjection * m_3DView * m_GlobalScaleMatrix;
+    glUseProgram(maResources.m_BatchTextProID);
+    CHECK_GL_ERROR();
+    glUniformMatrix4fv(maResources.m_BatchTextMatrixID, 1, GL_FALSE, &aMVP[0][0]);
+    glEnableVertexAttribArray(maResources.m_BatchTextVertexID);
+    glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
+    glVertexAttribPointer(
+        maResources.m_BatchTextVertexID,
+        3,                  // size
+        GL_FLOAT,           // type
+        GL_FALSE,           // normalized?
+        0,                  // stride
+        (void*)0            // array buffer offset
+        );
+    //tex coord
+    CHECK_GL_ERROR();
+    glEnableVertexAttribArray(maResources.m_BatchTextTexCoordID);
+    glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBufBatch);
+    glVertexAttribPointer(
+        maResources.m_BatchTextTexCoordID,
+        3,                  // size
+        GL_FLOAT,           // type
+        GL_FALSE,           // normalized?
+        0,                  // stride
+        (void*)0            // array buffer offset
+        );
+    //use texture array to get the vertex
+    for (size_t i = 0; i < m_TextInfoBatch.texture.size(); i++)
+    {
+        int vertexNum = m_TextInfoBatch.texture[i].subTextureNum;
+        glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
+        glBufferData(GL_ARRAY_BUFFER, 4 * vertexNum * sizeof(glm::vec3), &m_TextInfoBatch.vertexList[4 * i * m_TextInfoBatch.batchNum], GL_STATIC_DRAW);
+        glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBufBatch);
+        glBufferData(GL_ARRAY_BUFFER, 4 * vertexNum * sizeof(glm::vec3), &m_TextInfoBatch.textureCoordList[4 * i * m_TextInfoBatch.batchNum], GL_STATIC_DRAW);
+        glBindTexture(GL_TEXTURE_2D_ARRAY, m_TextInfoBatch.texture[i].textureID);
+        CHECK_GL_ERROR();
+        glUniform1i(maResources.m_BatchTextTexID, 0);
+        CHECK_GL_ERROR();
+        //TODO: moggi: get rid fo GL_QUADS
+        glDrawArrays(GL_QUADS, 0, 4 * vertexNum);
+    }
+    glDisableVertexAttribArray(maResources.m_BatchTextVertexID);
+    CHECK_GL_ERROR();
+    glDisableVertexAttribArray(maResources.m_BatchTextTexCoordID);
+    CHECK_GL_ERROR();
+    glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
+    glUseProgram(0);
+}
 void OpenGL3DRenderer::RenderTextShape()
 {
     CHECK_GL_ERROR();
@@ -1855,7 +2042,14 @@ void OpenGL3DRenderer::ProcessUnrenderedShape(bool bNewScene)
         }
     }
     //render text
-    RenderTextShape();
+    if (maResources.mbTexBatchSupport)
+    {
+        RenderTextShapeBatch();
+    }
+    else
+    {
+        RenderTextShape();
+    }
     // render screen text
     RenderScreenTextShape();
 #if DEBUG_FBO
@@ -1915,6 +2109,7 @@ void OpenGL3DRenderer::ReleaseShapes()
     ReleaseTextShapes();
     ReleaseScreenTextShapes();
     ReleaseBatchBarInfo();
+    ReleaseTextShapesBatch();
 }
 
 void OpenGL3DRenderer::GetBatchMiddleInfo(Extrude3DInfo &extrude3D)
commit 580250bdb98a0e81a8f049e21c0b44bd0c970943
Author: weigao <weigao at multicorewareinc.com>
Date:   Wed Jun 18 08:01:46 2014 -0700

    add batch render texture shaders
    
    Change-Id: I922d24bc63ed7c1f16318c25da0b6b3401d24b6f

diff --git a/chart2/Package_opengl.mk b/chart2/Package_opengl.mk
index 3d68a93..6e1e298 100644
--- a/chart2/Package_opengl.mk
+++ b/chart2/Package_opengl.mk
@@ -32,6 +32,8 @@ $(eval $(call gb_Package_add_files,chart2_opengl_shader,$(LIBO_BIN_FOLDER)/openg
 	shape3DVertexShaderBatch.glsl \
 	shape3DFragmentShaderV300.glsl \
 	shape3DVertexShaderV300.glsl \
+	textFragmentShaderBatch.glsl \
+	textVertexShaderBatch.glsl \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/chart2/opengl/textFragmentShaderBatch.glsl b/chart2/opengl/textFragmentShaderBatch.glsl
new file mode 100644
index 0000000..d7bd4ae
--- /dev/null
+++ b/chart2/opengl/textFragmentShaderBatch.glsl
@@ -0,0 +1,20 @@
+/* -*- 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 330 core
+#extension GL_EXT_texture_array : enable
+uniform sampler2DArray texArray;
+in vec3 vTexCoord;
+
+out vec4 actualColor;
+void main()
+{
+	vec3 color = texture2DArray(texArray, vTexCoord.xyz).rgb;
+    actualColor = vec4(color, 1.0 - color.r);
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/opengl/textVertexShaderBatch.glsl b/chart2/opengl/textVertexShaderBatch.glsl
new file mode 100644
index 0000000..f894333
--- /dev/null
+++ b/chart2/opengl/textVertexShaderBatch.glsl
@@ -0,0 +1,22 @@
+/* -*- 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 330 core
+in vec3 vPosition;
+in vec3 texCoord;
+
+out vec3 vTexCoord;
+uniform mat4 MVP;
+
+void main()
+{
+    gl_Position =  MVP * vec4(vPosition, 1);
+    vTexCoord = texCoord;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 11bc1787baa529466a3a2374d991677a23160ad4
Author: weigao <weigao at multicorewareinc.com>
Date:   Wed Jun 18 01:10:05 2014 -0700

    use shader to calculate alpha channel
    
    Change-Id: I3cf9636b36ffd47589dd3ab61278802ca73644ce

diff --git a/chart2/opengl/screenTextFragmentShader.glsl b/chart2/opengl/screenTextFragmentShader.glsl
index a848103..7e2bd26 100644
--- a/chart2/opengl/screenTextFragmentShader.glsl
+++ b/chart2/opengl/screenTextFragmentShader.glsl
@@ -11,7 +11,8 @@ varying vec2 vTexCoord;
 uniform sampler2D TextTex;
 void main()
 {
-    gl_FragColor = vec4(texture2D(TextTex, vTexCoord).rgba);
+    vec3 color = texture2D(TextTex, vTexCoord).rgb;
+    gl_FragColor = vec4(color, 1.0 - color.r);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/opengl/textFragmentShader.glsl b/chart2/opengl/textFragmentShader.glsl
index ef8d44d..c1d44bc 100644
--- a/chart2/opengl/textFragmentShader.glsl
+++ b/chart2/opengl/textFragmentShader.glsl
@@ -11,7 +11,8 @@ uniform sampler2D TextTex;
 varying vec2 vTexCoord;
 void main()
 {
-    gl_FragColor = vec4(texture2D(TextTex, vTexCoord).rgba);
+    vec3 color = texture2D(TextTex, vTexCoord).rgb;
+    gl_FragColor = vec4(color, 1.0 - color.r);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index ce40540..065b5fb 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -379,8 +379,6 @@ private:
 
     float m_fViewAngle;
 
-    float m_fHeightWeight;
-
     bool mbPickingMode;
 
     GLuint mnPickingFbo;
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index 038caaf..001190f 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -12,6 +12,7 @@
 #include <vcl/svapp.hxx>
 
 #include <vcl/opengl/OpenGLHelper.hxx>
+#include <vcl/bmpacc.hxx>
 
 namespace chart {
 
@@ -90,7 +91,15 @@ const TextCacheItem& TextCache::getText(OUString rText)
     aDevice.DrawText(Point(0,0), rText);
 
     BitmapEx aText(aDevice.GetBitmapEx(Point(0,0), aDevice.GetOutputSize()));
-    TextCacheItem *pItem = new TextCacheItem(OpenGLHelper::ConvertBitmapExToRGBABuffer(aText), aText.GetSizePixel());
+//    TextCacheItem *pItem = new TextCacheItem(OpenGLHelper::ConvertBitmapExToRGBABuffer(aText), aText.GetSizePixel());
+    Bitmap aBitmap (aText.GetBitmap());
+    BitmapReadAccess *pAcc = aBitmap.AcquireReadAccess();
+    sal_uInt8 *buf = (sal_uInt8 *)pAcc->GetBuffer();
+    long nBmpWidth = aText.GetSizePixel().Width();
+    long nBmpHeight = aText.GetSizePixel().Height();
+    sal_uInt8* pBitmapBuf(new sal_uInt8[3* nBmpWidth * nBmpHeight]);
+    memcpy(pBitmapBuf, buf, 3* nBmpWidth * nBmpHeight);
+    TextCacheItem *pItem = new TextCacheItem(pBitmapBuf, aText.GetSizePixel());
     maTextCache.insert(rText, pItem);
 
     return *maTextCache.find(rText)->second;
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 8887a05..cf22a86 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -54,10 +54,10 @@ int static checkGLError(const char *file, int line)
 #define CHECK_GL_ERROR() checkGLError(__FILE__, __LINE__)
 
 GLfloat texCoords[] = {
-    0.0f, 0.0f,
     1.0f, 0.0f,
     1.0f, 1.0f,
-    0.0f, 1.0f
+    0.0f, 1.0f,
+    0.0f, 0.0f
 };
 
 glm::vec4 getColorAsVector(sal_uInt32 nColor)
@@ -73,7 +73,6 @@ glm::vec4 getColorAsVector(sal_uInt32 nColor)
 OpenGL3DRenderer::OpenGL3DRenderer():
     m_uiSelectFrameCounter(0)
     , m_fViewAngle(30.0f)
-    , m_fHeightWeight(1.0f)
     , mbPickingMode(false)
 {
     m_Polygon3DInfo.lineOnly = false;
@@ -763,7 +762,7 @@ void OpenGL3DRenderer::RenderLine3D(Polygon3DInfo &polygon)
     glUseProgram(maResources.m_CommonProID);
     PosVecf3 trans = {0.0f, 0, 0.0};
     PosVecf3 angle = {0.0f, 0.0f, 0.0f};
-    PosVecf3 scale = {1.0f, 1.0f, m_fHeightWeight};
+    PosVecf3 scale = {1.0f, 1.0f, 1.0f};
     MoveModelf(trans, angle, scale);
     m_Model = m_GlobalScaleMatrix * m_Model;
     m_3DMVP = m_3DProjection * m_3DView * m_Model;
@@ -854,7 +853,7 @@ void OpenGL3DRenderer::RenderPolygon3D(Polygon3DInfo &polygon)
         Normals3D *normalList = polygon.normalsList[i];
         PosVecf3 trans = {0.0f, 0.0f, 0.0};
         PosVecf3 angle = {0.0f, 0.0f, 0.0f};
-        PosVecf3 scale = {1.0f, 1.0f, m_fHeightWeight};
+        PosVecf3 scale = {1.0f, 1.0f, 1.0f};
         MoveModelf(trans, angle, scale);
         m_Model = m_GlobalScaleMatrix * m_Model;
         glm::mat3 normalMatrix(m_Model);
@@ -1522,8 +1521,6 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
                     (void*)0            // array buffer offset
                     );
         }
-        extrude3DInfo.zTransform *= m_fHeightWeight;
-        extrude3DInfo.zScale *= m_fHeightWeight;
         if(!mbPickingMode)
         {
             if (maResources.m_b330Support)
@@ -1574,22 +1571,22 @@ void OpenGL3DRenderer::CreateScreenTextTexture(
 
     TextInfo aTextInfo;
     aTextInfo.id = getColorAsVector(nUniqueId);
-    aTextInfo.vertex[0] = vTopLeft.x;
-    aTextInfo.vertex[1] = vTopLeft.y;
+    aTextInfo.vertex[0] = vBottomRight.x;
+    aTextInfo.vertex[1] = vBottomRight.y;
     aTextInfo.vertex[2] = 0;
 
     aTextInfo.vertex[3] = vBottomRight.x;
     aTextInfo.vertex[4] = vTopLeft.y;
     aTextInfo.vertex[5] = 0;
 
+    aTextInfo.vertex[6] = vTopLeft.x;
+    aTextInfo.vertex[7] = vTopLeft.y;
+    aTextInfo.vertex[8] = 0;
+
     aTextInfo.vertex[9] = vTopLeft.x;
     aTextInfo.vertex[10] = vBottomRight.y;
     aTextInfo.vertex[11] = 0;
 
-    aTextInfo.vertex[6] = vBottomRight.x;
-    aTextInfo.vertex[7] = vBottomRight.y;
-    aTextInfo.vertex[8] = 0;
-
     CHECK_GL_ERROR();
     glGenTextures(1, &aTextInfo.texture);
     CHECK_GL_ERROR();
@@ -1603,7 +1600,7 @@ void OpenGL3DRenderer::CreateScreenTextTexture(
     CHECK_GL_ERROR();
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     CHECK_GL_ERROR();
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmpWidth, bmpHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmapBuf.get());
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bmpWidth, bmpHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapBuf.get());
     CHECK_GL_ERROR();
     glBindTexture(GL_TEXTURE_2D, 0);
     CHECK_GL_ERROR();
@@ -1621,21 +1618,21 @@ void OpenGL3DRenderer::CreateTextTexture(const boost::shared_array<sal_uInt8> &b
 
     TextInfo aTextInfo;
     aTextInfo.id = getColorAsVector(nUniqueId);
-    aTextInfo.vertex[0] = vTopLeft.x;
-    aTextInfo.vertex[1] = vTopLeft.y;
-    aTextInfo.vertex[2] = vTopLeft.z * m_fHeightWeight;
+    aTextInfo.vertex[0] = vBottomRight.x;
+    aTextInfo.vertex[1] = vBottomRight.y;
+    aTextInfo.vertex[2] = vBottomRight.z;
 
     aTextInfo.vertex[3] = vTopRight.x;
     aTextInfo.vertex[4] = vTopRight.y;
-    aTextInfo.vertex[5] = vTopRight.z * m_fHeightWeight;
+    aTextInfo.vertex[5] = vTopRight.z;
 
     aTextInfo.vertex[9] = vBottomLeft.x;
     aTextInfo.vertex[10] = vBottomLeft.y;
-    aTextInfo.vertex[11] = vBottomLeft.z * m_fHeightWeight;
+    aTextInfo.vertex[11] = vBottomLeft.z;
 
-    aTextInfo.vertex[6] = vBottomRight.x;
-    aTextInfo.vertex[7] = vBottomRight.y;
-    aTextInfo.vertex[8] = vBottomRight.z * m_fHeightWeight;
+    aTextInfo.vertex[6] = vTopLeft.x;
+    aTextInfo.vertex[7] = vTopLeft.y;
+    aTextInfo.vertex[8] = vTopLeft.z;
 
     CHECK_GL_ERROR();
     glGenTextures(1, &aTextInfo.texture);
@@ -1650,7 +1647,7 @@ void OpenGL3DRenderer::CreateTextTexture(const boost::shared_array<sal_uInt8> &b
     CHECK_GL_ERROR();
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     CHECK_GL_ERROR();
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmpWidth, bmpHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmapBuf.get());
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bmpWidth, bmpHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapBuf.get());
     CHECK_GL_ERROR();
     glBindTexture(GL_TEXTURE_2D, 0);
     CHECK_GL_ERROR();
@@ -1816,11 +1813,11 @@ void OpenGL3DRenderer::ClearBuffer()
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
         glBegin (GL_QUADS);
-        glColor3f(0.3,0.3,0.3);
+        glColor3f(0.3f,0.3f,0.3f);
         glVertex3f (-1.0f, -1.0f, -1.0f);
         glVertex3f (1.0f, -1.0f, -1.0f);
 
-        glColor3f(0.0,0.0,0.0);
+        glColor3f(0.0f,0.0f,0.0f);
         glVertex3f (1.0f, 1.0f, -1.0f);
         glVertex3f (-1.0f, 1.0f, -1.0f);
         glEnd ();
@@ -1997,8 +1994,6 @@ void OpenGL3DRenderer::GetBatchBarsInfo()
     for (size_t i = 0; i < m_Extrude3DList.size(); i++)
     {
         Extrude3DInfo &extrude3DInfo = m_Extrude3DList[i];
-        extrude3DInfo.zTransform *= m_fHeightWeight;
-        extrude3DInfo.zScale *= m_fHeightWeight;
         if (m_Extrude3DInfo.rounded)
         {
             GetBatchTopAndFlatInfo(extrude3DInfo);
commit bfc5fec078d0a9dd5f0d423a560e4ab4c74d2513
Author: weigao <weigao at multicorewareinc.com>
Date:   Wed Jun 18 00:04:08 2014 -0700

    add global scale matrix
    
    Change-Id: I23b9929dd3f0f1b0a070091ed9c1fe920edfcbf9

diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 1e5df81..ce40540 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -400,6 +400,8 @@ private:
     glm::vec4 m_LightColor[MAX_LIGHT_NUM];
     glm::vec4 m_PositionWorldspace[MAX_LIGHT_NUM];
     float m_fLightPower[MAX_LIGHT_NUM];
+
+    glm::mat4 m_GlobalScaleMatrix;
 };
 
 }
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 08f911a..8887a05 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -348,6 +348,7 @@ void OpenGL3DRenderer::init()
     CHECK_GL_ERROR();
     glViewport(0, 0, m_iWidth, m_iHeight);
     Set3DSenceInfo(0xFFFFFF, true);
+    m_GlobalScaleMatrix = glm::scale(0.01f, 0.01f, 0.01f);
 }
 
 void OpenGL3DRenderer::SetSize(const Size& rSize)
@@ -764,7 +765,7 @@ void OpenGL3DRenderer::RenderLine3D(Polygon3DInfo &polygon)
     PosVecf3 angle = {0.0f, 0.0f, 0.0f};
     PosVecf3 scale = {1.0f, 1.0f, m_fHeightWeight};
     MoveModelf(trans, angle, scale);
-
+    m_Model = m_GlobalScaleMatrix * m_Model;
     m_3DMVP = m_3DProjection * m_3DView * m_Model;
 
     for (size_t i = 0; i < polygon.verticesList.size(); i++)
@@ -855,6 +856,7 @@ void OpenGL3DRenderer::RenderPolygon3D(Polygon3DInfo &polygon)
         PosVecf3 angle = {0.0f, 0.0f, 0.0f};
         PosVecf3 scale = {1.0f, 1.0f, m_fHeightWeight};
         MoveModelf(trans, angle, scale);
+        m_Model = m_GlobalScaleMatrix * m_Model;
         glm::mat3 normalMatrix(m_Model);
         glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix);
 
@@ -1253,7 +1255,7 @@ void OpenGL3DRenderer::RenderExtrudeFlatSurface(const Extrude3DInfo& extrude3D,
                       extrude3D.zTransform};
     glm::mat4 aTranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
     glm::mat4 flatScale = glm::scale(xyScale, xyScale, xyScale);
-    m_Model = aTranslationMatrix * extrude3D.rotation * flatScale;
+    m_Model = m_GlobalScaleMatrix * aTranslationMatrix * extrude3D.rotation * flatScale;
     if(!mbPickingMode)
     {
         glm::mat3 normalMatrix(m_Model);
@@ -1297,7 +1299,7 @@ void OpenGL3DRenderer::RenderExtrudeBottomSurface(const Extrude3DInfo& extrude3D
         glm::mat4 aTranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
         m_Model = aTranslationMatrix * extrude3D.rotation * topTrans * topScale;
     }
-
+    m_Model = m_GlobalScaleMatrix * m_Model;
     if(!mbPickingMode)
     {
         glm::mat3 normalMatrix(m_Model);
@@ -1342,7 +1344,7 @@ void OpenGL3DRenderer::RenderExtrudeMiddleSurface(const Extrude3DInfo& extrude3D
         glm::mat4 reverseMatrix = glm::translate(glm::vec3(0.0, 0.0, -1.0));
         m_Model = m_Model * reverseMatrix;
     }
-
+    m_Model = m_GlobalScaleMatrix * m_Model;
     if(!mbPickingMode)
     {
         glm::mat3 normalMatrix(m_Model);
@@ -1387,7 +1389,7 @@ void OpenGL3DRenderer::RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D)
         glm::mat4 aTranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
         m_Model = aTranslationMatrix * extrude3D.rotation * topTrans * topScale * orgTrans;
     }
-
+    m_Model = m_GlobalScaleMatrix * m_Model;
     if(!mbPickingMode)
     {
         glm::mat3 normalMatrix(m_Model);
@@ -1417,7 +1419,7 @@ void OpenGL3DRenderer::RenderNonRoundedBar(const Extrude3DInfo& extrude3D)
         glm::mat4 reverseMatrix = glm::translate(glm::vec3(0.0, 0.0, -1.0));
         m_Model = m_Model * reverseMatrix;
     }
-
+    m_Model = m_GlobalScaleMatrix * m_Model;
     if(!mbPickingMode)
     {
         glm::mat3 normalMatrix(m_Model);
@@ -1741,6 +1743,7 @@ void OpenGL3DRenderer::RenderTextShape()
         PosVecf3 angle = {0.0f, 0.0f, 0.0f};
         PosVecf3 scale = {1.0, 1.0, 1.0f};
         MoveModelf(trans, angle, scale);
+        m_Model = m_GlobalScaleMatrix * m_Model;
         glm::mat4 aMVP = m_3DProjection * m_3DView * m_Model;
         glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
         CHECK_GL_ERROR();
@@ -1794,6 +1797,8 @@ void OpenGL3DRenderer::RenderTextShape()
 
 void OpenGL3DRenderer::CreateSceneBoxView()
 {
+    m_CameraInfo.cameraPos = glm::vec3(m_GlobalScaleMatrix * glm::vec4(m_CameraInfo.cameraPos, 1.0));
+    m_CameraInfo.cameraOrg = glm::vec3(m_GlobalScaleMatrix * glm::vec4(m_CameraInfo.cameraOrg, 1.0));
     m_3DView = glm::lookAt(m_CameraInfo.cameraPos,
                m_CameraInfo.cameraOrg,
                m_CameraInfo.cameraUp);
@@ -1933,6 +1938,7 @@ void OpenGL3DRenderer::GetBatchMiddleInfo(Extrude3DInfo &extrude3D)
         glm::mat4 aTranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
         m_Model = aTranslationMatrix * extrude3D.rotation * scale;
     }
+    m_Model = m_GlobalScaleMatrix * m_Model;
     glm::mat3 normalMatrix(m_Model);
     glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix);
     m_BarSurface[MIDDLE_SURFACE].modelMatrixList.push_back(m_Model);
@@ -1967,6 +1973,7 @@ void OpenGL3DRenderer::GetBatchTopAndFlatInfo(Extrude3DInfo &extrude3D)
         glm::mat4 aTranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
         m_Model = aTranslationMatrix * extrude3D.rotation * topTrans * topScale * orgTrans;
     }
+    m_Model = m_GlobalScaleMatrix * m_Model;
     glm::mat3 normalMatrix(m_Model);
     glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix);
     m_BarSurface[TOP_SURFACE].modelMatrixList.push_back(m_Model);
@@ -1976,6 +1983,7 @@ void OpenGL3DRenderer::GetBatchTopAndFlatInfo(Extrude3DInfo &extrude3D)
     glm::mat4 aTranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
     glm::mat4 flatScale = glm::scale(xyScale, xyScale, xyScale);
     m_Model = aTranslationMatrix * extrude3D.rotation * flatScale;
+    m_Model = m_GlobalScaleMatrix * m_Model;
     normalMatrix = glm::mat3(m_Model);
     normalInverseTranspos = glm::inverseTranspose(normalMatrix);
 
@@ -2001,6 +2009,7 @@ void OpenGL3DRenderer::GetBatchBarsInfo()
             glm::mat4 transformMatrix = glm::translate(glm::vec3(extrude3DInfo.xTransform, extrude3DInfo.yTransform, extrude3DInfo.zTransform));
             glm::mat4 scaleMatrix = glm::scale(extrude3DInfo.xScale, extrude3DInfo.yScale, extrude3DInfo.zScale);
             m_Model = transformMatrix * extrude3DInfo.rotation * scaleMatrix;
+            m_Model = m_GlobalScaleMatrix * m_Model;
             glm::mat3 normalMatrix(m_Model);
             glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix);
             m_BarSurface[0].modelMatrixList.push_back(m_Model);
commit 7fce7e9916b0471310319b360bca99b96cec7eba
Author: weigao <weigao at multicorewareinc.com>
Date:   Tue Jun 17 23:29:09 2014 -0700

    fix the using 3.0 version bug
    
    Change-Id: Ie197d0156a2d8b54fe6b08a905d82a63d31513f2

diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 9098cd1..08f911a 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -172,7 +172,6 @@ void OpenGL3DRenderer::CheckGLSLVersion()
     if (iVersion > 3)
     {
         maResources.m_b330Support = true;
-        maResources.m_b330Support = false;
         return;
     }
     p++;


More information about the Libreoffice-commits mailing list