diff options
author | Peilin <peilin@multicorewareinc.com> | 2014-02-03 20:49:40 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-02-03 20:53:05 +0100 |
commit | a47351f84e9d9fe569700d79f14b239b6eff70a6 (patch) | |
tree | a8a80c1b7fbfba9acba24efb7e9acbf9adf954bf /chart2/source | |
parent | 89c6efe4ec986d6bc3c1147fea260f882f04c66b (diff) |
replace malloc with std::vector
Change-Id: I3546d0d005d17286107ff2c70a29a4bceebd36a0
Diffstat (limited to 'chart2/source')
-rwxr-xr-x | chart2/source/view/main/OpenGLRender.cxx | 20 | ||||
-rwxr-xr-x | chart2/source/view/main/OpenGLRender.hxx | 6 |
2 files changed, 11 insertions, 15 deletions
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx index 8ca8a58fdc67..f6a473af4fb0 100755 --- a/chart2/source/view/main/OpenGLRender.cxx +++ b/chart2/source/view/main/OpenGLRender.cxx @@ -1074,18 +1074,18 @@ int OpenGLRender::CreateMultiSampleFrameBufObj() int OpenGLRender::Create2DCircle(int detail) { float angle; - int idx = 2; if (detail <= 0) { return -1; } - m_Bubble2DCircle.bufLen = 2 * (detail + 3)* sizeof(float); - m_Bubble2DCircle.pointBuf = (float *)malloc(m_Bubble2DCircle.bufLen); - memset(m_Bubble2DCircle.pointBuf, 0, m_Bubble2DCircle.bufLen); + m_Bubble2DCircle.clear(); + m_Bubble2DCircle.reserve(2 * (detail + 3)); + m_Bubble2DCircle.push_back(0); + m_Bubble2DCircle.push_back(0); for(angle = 2.0f * GL_PI; angle > -(2.0f * GL_PI / detail); angle -= (2.0f * GL_PI / detail)) { - m_Bubble2DCircle.pointBuf[idx++] = sin(angle); - m_Bubble2DCircle.pointBuf[idx++] = cos(angle); + m_Bubble2DCircle.push_back(sin(angle)); + m_Bubble2DCircle.push_back(cos(angle)); } return 0; } @@ -1093,7 +1093,7 @@ int OpenGLRender::Create2DCircle(int detail) int OpenGLRender::Bubble2DShapePoint(float x, float y, float directionX, float directionY) { //check whether to create the circle data - if (!m_Bubble2DCircle.pointBuf) + if (m_Bubble2DCircle.empty()) { Create2DCircle(100); } @@ -1126,11 +1126,11 @@ int OpenGLRender::RenderBubble2FBO(int) //render to fbo //fill vertex buffer glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer); - if (!m_Bubble2DCircle.pointBuf) + if (m_Bubble2DCircle.empty()) { Create2DCircle(100); } - glBufferData(GL_ARRAY_BUFFER, m_Bubble2DCircle.bufLen, m_Bubble2DCircle.pointBuf, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, m_Bubble2DCircle.size() * sizeof(GLfloat), &m_Bubble2DCircle[0], GL_STATIC_DRAW); glUseProgram(m_CommonProID); @@ -1148,7 +1148,7 @@ int OpenGLRender::RenderBubble2FBO(int) 0, // stride (void*)0 // array buffer offset ); - glDrawArrays(GL_TRIANGLE_FAN, 0, m_Bubble2DCircle.bufLen / sizeof(float) / 2); + glDrawArrays(GL_TRIANGLE_FAN, 0, m_Bubble2DCircle.size() / 2); glDisableVertexAttribArray(m_2DVertexID); glUseProgram(0); m_Bubble2DShapePointList.pop_front(); diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx index 18176f6cbc67..864a58c495b1 100755 --- a/chart2/source/view/main/OpenGLRender.hxx +++ b/chart2/source/view/main/OpenGLRender.hxx @@ -75,11 +75,7 @@ typedef struct Bubble2DPointList float yScale; }Bubble2DPointList; -typedef struct Bubble2DCircle -{ - float *pointBuf; - int bufLen; -}Bubble2DCircle; +typedef std::vector<GLfloat> Bubble2DCircle; struct RectanglePointList { |