[Libreoffice-commits] core.git: Branch 'private/moggi/debug-opengl' - 6 commits - chart2/source

Markus Mohrhard markus.mohrhard at collabora.co.uk
Sun Jan 12 04:48:02 PST 2014


 chart2/source/view/main/OpenGLRender.cxx |  131 +++++++++++++------------------
 chart2/source/view/main/OpenGLRender.hxx |   19 +---
 2 files changed, 62 insertions(+), 88 deletions(-)

New commits:
commit 9254d8e84e5cbbcd4fd24802d416a180c3b1ed5a
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sun Jan 12 13:46:46 2014 +0100

    more formatting and TODO comments
    
    for GL_QUADS see for example
    http://stackoverflow.com/questions/6644099/what-is-so-bad-about-gl-quads
    
    Change-Id: Ife53f1ac09125bc7e42c8aa91c53d7e7991ac0bf

diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index f3786a1..2e6b176 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -718,6 +718,7 @@ int OpenGLRender::RenderTexture2FBO(GLuint TexID)
         );
     glBindTexture(GL_TEXTURE_2D, TexID);
     glUniform1i(m_RenderTexID, 0);
+    //TODO: moggi: get rid fo GL_QUADS
     glDrawArrays(GL_QUADS, 0, 4);
     glDisableVertexAttribArray(m_RenderTexCoordID);
     glDisableVertexAttribArray(m_RenderVertexID);
@@ -757,6 +758,7 @@ int OpenGLRender::RenderTexture(GLuint TexID)
         );
     glBindTexture(GL_TEXTURE_2D, TexID);
     glUniform1i(m_RenderTexID, 0);
+    //TODO: moggi: get rid fo GL_QUADS
     glDrawArrays(GL_QUADS, 0, 4);
     glDisableVertexAttribArray(m_RenderTexCoordID);
     glDisableVertexAttribArray(m_RenderVertexID);
@@ -1083,7 +1085,7 @@ bool OpenGLRender::InitMultisample(PIXELFORMATDESCRIPTOR pfd)
         0,0
     };
     // First We Check To See If We Can Get A Pixel Format For 4 Samples
-    valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
+    valid = wglChoosePixelFormatARB(hDC, iAttributes, fAttributes, 1, &pixelFormat, &numFormats);
     // If We Returned True, And Our Format Count Is Greater Than 1
     if (valid && numFormats >= 1)
     {
@@ -1097,7 +1099,7 @@ bool OpenGLRender::InitMultisample(PIXELFORMATDESCRIPTOR pfd)
     }
     // Our Pixel Format With 4 Samples Failed, Test For 2 Samples
     iAttributes[19] = 2;
-    valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
+    valid = wglChoosePixelFormatARB(hDC, iAttributes, fAttributes, 1, &pixelFormat, &numFormats);
     if (valid && numFormats >= 1)
     {
         mbArbMultisampleSupported = true;
@@ -1272,7 +1274,6 @@ int OpenGLRender::Bubble2DShapePoint(float x, float y, float directionX, float d
     m_Bubble2DPointList.xScale = directionX / 10.0f;
     m_Bubble2DPointList.yScale = directionY / 10.0f;
 
-
     m_fPicLeft = std::min(m_fPicLeft, actualX);
     m_fPicRight = std::max(m_fPicRight, actualX);
     m_fPicBottom = std::min(m_fPicBottom, actualY);
@@ -1397,6 +1398,7 @@ int OpenGLRender::RenderRectangleShape()
             0,                  // stride
             (void*)0            // array buffer offset
             );
+
         // 2nd attribute buffer : color
         glEnableVertexAttribArray(m_BackgroundColorID);
         glBindBuffer(GL_ARRAY_BUFFER, m_ColorBuffer);
@@ -1408,6 +1410,7 @@ int OpenGLRender::RenderRectangleShape()
             0,                  // stride
             (void*)0            // array buffer offset
             );
+        //TODO: moggi: get rid of GL_QUADS
         glDrawArrays(GL_QUADS, 0, 4);
         glDisableVertexAttribArray(m_BackgroundVertexID);
         glDisableVertexAttribArray(m_BackgroundColorID);
@@ -1573,6 +1576,7 @@ int OpenGLRender::RenderTextShape()
         //texture
         glBindTexture(GL_TEXTURE_2D, textInfo.texture);
         glUniform1i(m_TextTexID, 0);
+        //TODO: moggi: get rid fo GL_QUADS
         glDrawArrays(GL_QUADS, 0, 4);
         glDisableVertexAttribArray(m_TextTexCoordID);
         glDisableVertexAttribArray(m_TextVertexID);
commit b2f278bd4eeeffa4a5094acefc1eb7da8aa7cd5c
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sun Jan 12 13:41:42 2014 +0100

    more clean-up
    
    Change-Id: Ie774afc8ab2c881c5f82be286c84fb3eb37821c1

diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 980cd50..f3786a1 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -615,13 +615,13 @@ void OpenGLRender::prepareToRender()
         CreateRenderObj(m_iWidth, m_iHeight);
         //create fbo
         CreateFrameBufferObj();
-        if (m_iArbMultisampleSupported)
+        if (mbArbMultisampleSupported)
         {
             CreateMultiSampleFrameBufObj();
         }
     }
     //bind fbo
-    if (m_iArbMultisampleSupported)
+    if (mbArbMultisampleSupported)
     {
         glBindFramebuffer(GL_FRAMEBUFFER,m_frameBufferMS);
     }
@@ -638,7 +638,7 @@ void OpenGLRender::prepareToRender()
 
 void OpenGLRender::renderToBitmap()
 {
-    if (m_iArbMultisampleSupported)
+    if (mbArbMultisampleSupported)
     {
         GLenum status;
         glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -909,7 +909,7 @@ OpenGLRender::OpenGLRender(uno::Reference< drawing::XShape > xTarget):
     m_iFboIdx(0),
     m_fLineAlpha(1.0),
     mxRenderTarget(xTarget),
-    m_iArbMultisampleSupported(false),
+    mbArbMultisampleSupported(false),
     m_TextVertexID(0),
     m_TextTexCoordID(1),
     m_ClearColor(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f))
@@ -1038,22 +1038,22 @@ bool OpenGLRender::InitMultisample(PIXELFORMATDESCRIPTOR pfd)
     //create a temp windwo to check whether support multi-sample, if support, get the format
     if (InitTempWindow(&hWnd, m_iWidth, m_iHeight, pfd) < 0)
     {
-        SAL_WARN("chart2.opengl", "Can't create temp window to test\n");
+        SAL_WARN("chart2.opengl", "Can't create temp window to test");
         return false;
     }
 
     // See If The String Exists In WGL!
     if (!WGLisExtensionSupported("WGL_ARB_multisample"))
     {
-        m_iArbMultisampleSupported = false;
-        SAL_WARN("chart2.opengl", "Device doesn't support multi sample\n");
+        mbArbMultisampleSupported = false;
+        SAL_WARN("chart2.opengl", "Device doesn't support multi sample");
         return false;
     }
     // Get Our Pixel Format
     PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
     if (!wglChoosePixelFormatARB)
     {
-        m_iArbMultisampleSupported = false;
+        mbArbMultisampleSupported = false;
         return false;
     }
     // Get Our Current Device Context
@@ -1087,39 +1087,39 @@ bool OpenGLRender::InitMultisample(PIXELFORMATDESCRIPTOR pfd)
     // If We Returned True, And Our Format Count Is Greater Than 1
     if (valid && numFormats >= 1)
     {
-        m_iArbMultisampleSupported = true;
+        mbArbMultisampleSupported = true;
         m_iArbMultisampleFormat = pixelFormat;
         wglMakeCurrent(NULL, NULL);
         wglDeleteContext(glWin.hRC);
         ReleaseDC(hWnd, glWin.hDC);
         DestroyWindow(hWnd);
-        return m_iArbMultisampleSupported;
+        return mbArbMultisampleSupported;
     }
     // Our Pixel Format With 4 Samples Failed, Test For 2 Samples
     iAttributes[19] = 2;
     valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
     if (valid && numFormats >= 1)
     {
-        m_iArbMultisampleSupported = true;
+        mbArbMultisampleSupported = true;
         m_iArbMultisampleFormat = pixelFormat;
         wglMakeCurrent(NULL, NULL);
         wglDeleteContext(glWin.hRC);
         ReleaseDC(hWnd, glWin.hDC);
         DestroyWindow(hWnd);
-        return m_iArbMultisampleSupported;
+        return mbArbMultisampleSupported;
     }
     // Return The Valid Format
     wglMakeCurrent(NULL, NULL);
     wglDeleteContext(glWin.hRC);
     ReleaseDC(hWnd, glWin.hDC);
     DestroyWindow(hWnd);
-    return  m_iArbMultisampleSupported;
+    return  mbArbMultisampleSupported;
 }
 #endif
 
 bool OpenGLRender::GetMSAASupport()
 {
-    return m_iArbMultisampleSupported;
+    return mbArbMultisampleSupported;
 }
 
 int OpenGLRender::GetMSAAFormat()
@@ -1415,6 +1415,7 @@ int OpenGLRender::RenderRectangleShape()
         glBindBuffer(GL_ARRAY_BUFFER, 0);
         m_RectangleShapePointList.pop_front();
     }
+    CHECK_GL_ERROR();
     return 0;
 }
 
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index 159bccb..8368fbc 100644
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -270,7 +270,7 @@ private:
     std::list <Line2DPointList> m_Line2DShapePointList;
 
     com::sun::star::uno::Reference< com::sun::star::drawing::XShape > mxRenderTarget;
-    bool m_iArbMultisampleSupported;
+    bool mbArbMultisampleSupported;
     int m_iArbMultisampleFormat;
     GLint m_iSampleBufs;
     GLint m_iSamples;
commit 173c4e7404ae914f85a19b91233ae0237608cbc3
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sun Jan 12 13:37:01 2014 +0100

    use std::min and std::max
    
    Change-Id: I5b8901606af2699a7d32978c897af73901fbc230

diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 1288e72..980cd50 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -541,13 +541,11 @@ int OpenGLRender::SetLine2DShapePoint(float x, float y, int listLength)
     m_Line2DPointList.push_back(actualX);
     m_Line2DPointList.push_back(actualY);
     m_Line2DPointList.push_back(m_fZStep);
-    m_fPicLeft = actualX < m_fPicLeft ? actualX : m_fPicLeft;
 
-    m_fPicRight = actualX > m_fPicRight ? actualX : m_fPicRight;
-
-    m_fPicBottom = actualY < m_fPicBottom ? actualY : m_fPicBottom;
-
-    m_fPicTop = actualY > m_fPicTop ? actualY : m_fPicTop;
+    m_fPicLeft = std::min(m_fPicLeft, actualX);
+    m_fPicRight = std::max(m_fPicRight, actualX);
+    m_fPicBottom = std::min(m_fPicBottom, actualY);
+    m_fPicTop = std::max(m_fPicTop, actualY);
 
     if (m_Line2DPointList.size() == size_t((listLength * 3) - 1))
     {
@@ -1274,13 +1272,11 @@ int OpenGLRender::Bubble2DShapePoint(float x, float y, float directionX, float d
     m_Bubble2DPointList.xScale = directionX / 10.0f;
     m_Bubble2DPointList.yScale = directionY / 10.0f;
 
-    m_fPicLeft = actualX < m_fPicLeft ? actualX : m_fPicLeft;
-
-    m_fPicRight = actualX > m_fPicRight ? actualX : m_fPicRight;
 
-    m_fPicBottom = actualY < m_fPicBottom ? actualY : m_fPicBottom;
-
-    m_fPicTop = actualY > m_fPicTop ? actualY : m_fPicTop;
+    m_fPicLeft = std::min(m_fPicLeft, actualX);
+    m_fPicRight = std::max(m_fPicRight, actualX);
+    m_fPicBottom = std::min(m_fPicBottom, actualY);
+    m_fPicTop = std::max(m_fPicTop, actualY);
 
     m_Bubble2DShapePointList.push_back(m_Bubble2DPointList);
     return 0;
@@ -1357,13 +1353,10 @@ int OpenGLRender::RectangleShapePoint(float x, float y, float directionX, float
     m_RectangleList.xScale = directionX / OPENGL_SCALE_VALUE;
     m_RectangleList.yScale = directionY / OPENGL_SCALE_VALUE;
 
-    m_fPicLeft = actualX < m_fPicLeft ? actualX : m_fPicLeft;
-
-    m_fPicRight = actualX > m_fPicRight ? actualX : m_fPicRight;
-
-    m_fPicBottom = actualY < m_fPicBottom ? actualY : m_fPicBottom;
-
-    m_fPicTop = actualY > m_fPicTop ? actualY : m_fPicTop;
+    m_fPicLeft = std::min(m_fPicLeft, actualX);
+    m_fPicRight = std::max(m_fPicRight, actualX);
+    m_fPicBottom = std::min(m_fPicBottom, actualY);
+    m_fPicTop = std::max(m_fPicTop, actualY);
 
     m_RectangleShapePointList.push_back(m_RectangleList);
     return 0;
@@ -1633,13 +1626,11 @@ int OpenGLRender::SetArea2DShapePoint(float x, float y, int listLength)
     m_Area2DPointList.push_back(actualX);
     m_Area2DPointList.push_back(actualY);
     m_Area2DPointList.push_back(m_fZStep);
-    m_fPicLeft = actualX < m_fPicLeft ? actualX : m_fPicLeft;
-
-    m_fPicRight = actualX > m_fPicRight ? actualX : m_fPicRight;
-
-    m_fPicBottom = actualY < m_fPicBottom ? actualY : m_fPicBottom;
 
-    m_fPicTop = actualY > m_fPicTop ? actualY : m_fPicTop;
+    m_fPicLeft = std::min(m_fPicLeft, actualX);
+    m_fPicRight = std::max(m_fPicRight, actualX);
+    m_fPicBottom = std::min(m_fPicBottom, actualY);
+    m_fPicTop = std::max(m_fPicTop, actualY);
 
     if (m_Area2DPointList.size() == size_t((listLength * 3) -1))
     {
commit 6d02ca2b99a2acdc7d8d335d92c613411c8853bc
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sun Jan 12 13:33:51 2014 +0100

    small fix for missed code
    
    Change-Id: Ida611464603a8a6229b771380ce5c6b20aa268ef

diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 3b3c621..1288e72 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -549,7 +549,7 @@ int OpenGLRender::SetLine2DShapePoint(float x, float y, int listLength)
 
     m_fPicTop = actualY > m_fPicTop ? actualY : m_fPicTop;
 
-    if (m_iPointNum == ((listLength * 3) - 1))
+    if (m_Line2DPointList.size() == size_t((listLength * 3) - 1))
     {
         m_Line2DShapePointList.push_back(m_Line2DPointList);
     }
@@ -597,7 +597,6 @@ int OpenGLRender::RenderLine2FBO(int)
         CHECK_GL_ERROR();
         m_Line2DShapePointList.pop_front();
     }
-    m_iPointNum = 0;
     GLenum status;
     CHECK_GL_ERROR();
     CHECK_GL_FRAME_BUFFER_STATUS();
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index 492588b..159bccb 100644
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -91,6 +91,7 @@ typedef struct RectanglePointList
     float xScale;
     float yScale;
 }RectanglePointList;
+
 typedef struct TextInfo
 {
     GLuint texture;
@@ -258,8 +259,6 @@ private:
 
     int m_iExternRC;
 
-    int m_iPointNum;
-
     Line2DPointList m_Line2DPointList;
 
     int m_iFboIdx;
commit f16f007de64ebc9789090397f6426320a5d4b792
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sun Jan 12 13:30:45 2014 +0100

    use std::vector instead of manual memory management
    
    Change-Id: I021068716b0c3f4bc858eeb76da684dce316ba60

diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index cd907ae1..3b3c621 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -909,7 +909,6 @@ OpenGLRender::OpenGLRender(uno::Reference< drawing::XShape > xTarget):
     m_Line2DColor(glm::vec4(1.0, 0.0, 0.0, 1.0)),
     m_iWidth(0),
     m_iHeight(0),
-    m_iPointNum(0),
     m_iFboIdx(0),
     m_fLineAlpha(1.0),
     mxRenderTarget(xTarget),
@@ -922,7 +921,6 @@ OpenGLRender::OpenGLRender(uno::Reference< drawing::XShape > xTarget):
     memset(&m_Bubble2DPointList, 0, sizeof(m_Bubble2DPointList));
     memset(&m_Bubble2DCircle, 0, sizeof(m_Bubble2DCircle));
     memset(&m_TextInfo, 0, sizeof(TextInfo));
-    memset(&m_Area2DPointList, 0, sizeof(m_Area2DPointList));
     memset(&m_RectangleList, 0, sizeof(RectanglePointList));
 
     m_iFboIdx = 0;
@@ -1627,17 +1625,15 @@ int OpenGLRender::CreateBMPHeaderRGBA(sal_uInt8 *bmpHeader, int xsize, int ysize
 
 int OpenGLRender::SetArea2DShapePoint(float x, float y, int listLength)
 {
-    if (!m_Area2DPointList.pointBuf)
+    if (m_Area2DPointList.empty())
     {
-        //a new point buffer should be alloc, we should push the old buffer first
-        m_Area2DPointList.bufLen = listLength * sizeof(float) * 3;
-        m_Area2DPointList.pointBuf = (float *)malloc(m_Area2DPointList.bufLen);
+        m_Area2DPointList.reserve(listLength);
     }
     float actualX = (x / OPENGL_SCALE_VALUE) - ((float)m_iWidth / 2);
     float actualY = (y / OPENGL_SCALE_VALUE) - ((float)m_iHeight / 2);
-    m_Area2DPointList.pointBuf[m_iPointNum++] = actualX;
-    m_Area2DPointList.pointBuf[m_iPointNum++] = actualY;
-    m_Area2DPointList.pointBuf[m_iPointNum++] = m_fZStep;
+    m_Area2DPointList.push_back(actualX);
+    m_Area2DPointList.push_back(actualY);
+    m_Area2DPointList.push_back(m_fZStep);
     m_fPicLeft = actualX < m_fPicLeft ? actualX : m_fPicLeft;
 
     m_fPicRight = actualX > m_fPicRight ? actualX : m_fPicRight;
@@ -1646,11 +1642,9 @@ int OpenGLRender::SetArea2DShapePoint(float x, float y, int listLength)
 
     m_fPicTop = actualY > m_fPicTop ? actualY : m_fPicTop;
 
-    if (m_iPointNum == (listLength * 3))
+    if (m_Area2DPointList.size() == size_t((listLength * 3) -1))
     {
         m_Area2DShapePointList.push_back(m_Area2DPointList);
-        m_Area2DPointList.pointBuf = NULL;
-        m_iPointNum = 0;
     }
     return 0;
 }
@@ -1666,12 +1660,12 @@ int OpenGLRender::RenderArea2DShape()
     PosVecf3 scale = {1.0f, 1.0f, 1.0f};
     MoveModelf(trans, angle, scale);
     m_MVP = m_Projection * m_View * m_Model;
-    for (size_t i = 0; i < listNum; i++)
+    for (size_t i = 0; i < listNum; ++i)
     {
         Area2DPointList &pointList = m_Area2DShapePointList.front();
         //fill vertex buffer
         glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
-        glBufferData(GL_ARRAY_BUFFER, pointList.bufLen, pointList.pointBuf, GL_STATIC_DRAW);
+        glBufferData(GL_ARRAY_BUFFER, pointList.size() * sizeof(float), &pointList[0], GL_STATIC_DRAW);
         // Use our shader
         glUseProgram(m_CommonProID);
 
@@ -1690,11 +1684,10 @@ int OpenGLRender::RenderArea2DShape()
             0,                  // stride
             (void*)0            // array buffer offset
             );
-        glDrawArrays(GL_POLYGON, 0, pointList.bufLen / sizeof(float) / 3); // 12*3 indices starting at 0 -> 12 triangles
+        glDrawArrays(GL_POLYGON, 0, pointList.size() / 3); // 12*3 indices starting at 0 -> 12 triangles
         glDisableVertexAttribArray(m_2DVertexID);
         glUseProgram(0);
         m_Area2DShapePointList.pop_front();
-        free(pointList.pointBuf);
     }
     glEnable(GL_MULTISAMPLE);
     m_fZStep += 0.01f;
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index 75afa06..492588b 100644
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -100,11 +100,9 @@ typedef struct TextInfo
     double rotation;
     float vertex[8];
 }TextInfo;
-typedef struct Area2DPointList
-{
-    float *pointBuf;
-    int bufLen;
-}Area2DPointList;
+
+typedef std::vector<float> Area2DPointList;
+
 /// Holds the information of our new child window
 struct GLWindow
 {
commit f3e5836b18a1ee33b057f7a419fb097cd562d058
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sun Jan 12 13:29:39 2014 +0100

    use std::vector instead of manual memory management
    
    Change-Id: I17da6947caffde0ba10717475da36dd265069ce5

diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index ebb7542..cd907ae1 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -532,18 +532,15 @@ BitmapEx OpenGLRender::GetAsBitmap()
 
 int OpenGLRender::SetLine2DShapePoint(float x, float y, int listLength)
 {
-    if (!m_Line2DPointList.pointBuf)
+    if (m_Line2DPointList.empty())
     {
-        //a new point buffer should be alloc, we should push the old buffer first
-        m_Line2DPointList.bufLen = listLength * sizeof(float) * 3;
-        m_Line2DPointList.pointBuf = (float *)malloc(m_Line2DPointList.bufLen);
-        m_iPointNum = 0;
+        m_Line2DPointList.reserve(listLength);
     }
     float actualX = (x / OPENGL_SCALE_VALUE) - ((float)m_iWidth / 2);
     float actualY = (y / OPENGL_SCALE_VALUE) - ((float)m_iHeight / 2);
-    m_Line2DPointList.pointBuf[m_iPointNum++] = actualX;
-    m_Line2DPointList.pointBuf[m_iPointNum++] = actualY;
-    m_Line2DPointList.pointBuf[m_iPointNum++] = m_fZStep;
+    m_Line2DPointList.push_back(actualX);
+    m_Line2DPointList.push_back(actualY);
+    m_Line2DPointList.push_back(m_fZStep);
     m_fPicLeft = actualX < m_fPicLeft ? actualX : m_fPicLeft;
 
     m_fPicRight = actualX > m_fPicRight ? actualX : m_fPicRight;
@@ -552,11 +549,9 @@ int OpenGLRender::SetLine2DShapePoint(float x, float y, int listLength)
 
     m_fPicTop = actualY > m_fPicTop ? actualY : m_fPicTop;
 
-    if (m_iPointNum == (listLength * 3))
+    if (m_iPointNum == ((listLength * 3) - 1))
     {
         m_Line2DShapePointList.push_back(m_Line2DPointList);
-        m_Line2DPointList.pointBuf = NULL;
-        m_iPointNum = 0;
     }
     return 0;
 }
@@ -572,7 +567,7 @@ int OpenGLRender::RenderLine2FBO(int)
         //fill vertex buffer
         glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
         CHECK_GL_ERROR();
-        glBufferData(GL_ARRAY_BUFFER, pointList.bufLen, pointList.pointBuf, GL_STATIC_DRAW);
+        glBufferData(GL_ARRAY_BUFFER, pointList.size() * sizeof(float), &pointList[0], GL_STATIC_DRAW);
         CHECK_GL_ERROR();
         // Use our shader
         glUseProgram(m_Line2DProID);
@@ -588,19 +583,18 @@ int OpenGLRender::RenderLine2FBO(int)
         CHECK_GL_ERROR();
         glVertexAttribPointer(
             m_Line2DVertexID,                  // attribute. No particular reason for 0, but must match the layout in the shader.
-            2,                  // size
+            3,                  // size
             GL_FLOAT,           // type
             GL_FALSE,           // normalized?
             0,                  // stride
             (void*)0            // array buffer offset
             );
-        glDrawArrays(GL_LINE_STRIP, 0, pointList.bufLen / sizeof(float) / 2); // 12*3 indices starting at 0 -> 12 triangles
+        glDrawArrays(GL_LINE_STRIP, 0, pointList.size()/3); // 12*3 indices starting at 0 -> 12 triangles
         CHECK_GL_ERROR();
         glDisableVertexAttribArray(m_Line2DWholeVertexID);
         CHECK_GL_ERROR();
         glUseProgram(0);
         CHECK_GL_ERROR();
-        free(pointList.pointBuf);
         m_Line2DShapePointList.pop_front();
     }
     m_iPointNum = 0;
@@ -925,7 +919,6 @@ OpenGLRender::OpenGLRender(uno::Reference< drawing::XShape > xTarget):
     m_ClearColor(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f))
 {
     //TODO: moggi: use STL
-    memset(&m_Line2DPointList, 0, sizeof(Line2DPointList));
     memset(&m_Bubble2DPointList, 0, sizeof(m_Bubble2DPointList));
     memset(&m_Bubble2DCircle, 0, sizeof(m_Bubble2DCircle));
     memset(&m_TextInfo, 0, sizeof(TextInfo));
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index 72c29a4..75afa06 100644
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -67,11 +67,7 @@ typedef struct PosVecf3
     float z;
 }PosVecf3;
 
-typedef struct Line2DPointList
-{
-    float *pointBuf;;
-    int bufLen;
-}Line2DPointList;
+typedef std::vector<float> Line2DPointList;
 
 typedef struct Bubble2DPointList
 {


More information about the Libreoffice-commits mailing list