chart2/Package_opengl.mk | 2 chart2/opengl/shape3DFragmentShaderBatch.glsl | 108 ++++++++ chart2/opengl/shape3DVertexShaderBatch.glsl | 34 ++ chart2/source/view/charttypes/GL3DBarChart.cxx | 22 + chart2/source/view/inc/GL3DBarChart.hxx | 1 chart2/source/view/inc/GL3DRenderer.hxx | 39 ++- chart2/source/view/inc/StaticGeometry.h | 6 chart2/source/view/main/GL3DRenderer.cxx | 315 +++++++++++++++++++++++-- 8 files changed, 503 insertions(+), 24 deletions(-)
New commits: commit a8b7fcf34914df128e9664bbd70dc269c7cf32cb Author: Markus Mohrhard <markus.mohrh...@collabora.co.uk> Date: Wed May 28 19:11:47 2014 +0200 prevent generating repeated information in rendering Change-Id: I1cc5453af6cabe7736cc43e13aad280aaf2c62f6 diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index bc1caee..b129b9f 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -296,8 +296,8 @@ void GL3DBarChart::render() { mpCamera->render(); } + mpRenderer->ProcessUnrenderedShape(mbNeedsNewRender); mbNeedsNewRender = false; - mpRenderer->ProcessUnrenderedShape(); mrWindow.getContext()->swapBuffers(); } diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index 4e85568..20fbca9 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -179,7 +179,7 @@ public: glm::vec2 vTopLeft, glm::vec2 vBottomRight, sal_uInt32 nUniqueId); - void ProcessUnrenderedShape(); + void ProcessUnrenderedShape(bool bNewScene); void SetPickingMode(bool bPickingMode); @@ -231,7 +231,7 @@ private: void GetBatchMiddleInfo(Extrude3DInfo &extrude3D); void InitBatch3DUniformBlock(); void UpdateBatch3DUniformBlock(); - void RenderBatchBars(); + void RenderBatchBars(bool bNewScene); private: struct ShaderResources diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index ae987ae..aded984 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -1693,7 +1693,7 @@ void OpenGL3DRenderer::CreateSceneBoxView() m_CameraInfo.cameraUp); } -void OpenGL3DRenderer::ProcessUnrenderedShape() +void OpenGL3DRenderer::ProcessUnrenderedShape(bool bNewScene) { glViewport(0, 0, m_iWidth, m_iHeight); glClearDepth(1.0f); @@ -1706,7 +1706,7 @@ void OpenGL3DRenderer::ProcessUnrenderedShape() if(mbPickingMode) RenderExtrude3DObject(); else - RenderBatchBars(); + RenderBatchBars(bNewScene); //render text RenderTextShape(); // render screen text @@ -1865,9 +1865,10 @@ void OpenGL3DRenderer::GetBatchBarsInfo() } } -void OpenGL3DRenderer::RenderBatchBars() +void OpenGL3DRenderer::RenderBatchBars(bool bNewScene) { - GetBatchBarsInfo(); + if(bNewScene) + GetBatchBarsInfo(); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); commit a45b16602f4d167d1cccfa285dd0c49a6c9d7c45 Author: Markus Mohrhard <markus.mohrh...@collabora.co.uk> Date: Wed May 28 18:51:38 2014 +0200 avoid transferring the textures for each frame Change-Id: I79466e66dc18dbbf72f192fe44d05fb6d657fa34 diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index 1bb558e..bc1caee 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -35,7 +35,8 @@ GL3DBarChart::GL3DBarChart( mnStep(0), mnStepsTotal(0), mnCornerId(0), - mbBlockUserInput(false) + mbBlockUserInput(false), + mbNeedsNewRender(true) { Size aSize = mrWindow.GetSizePixel(); mpRenderer->SetSize(aSize); @@ -93,6 +94,7 @@ double findMaxValue(const boost::ptr_vector<VDataSeries>& rDataSeriesContainer) void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSeriesContainer, ExplicitCategoriesProvider& rCatProvider) { + mpRenderer->ReleaseShapes(); // Each series of data flows from left to right, and multiple series are // stacked vertically along y axis. @@ -269,6 +271,8 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer mpCamera->setPosition(maCameraPosition); maCameraDirection = glm::vec3(mnMaxX/2, mnMaxY/2, 0); mpCamera->setDirection(maCameraDirection); + + mbNeedsNewRender = true; } void GL3DBarChart::render() @@ -280,11 +284,19 @@ void GL3DBarChart::render() Size aSize = mrWindow.GetSizePixel(); mpRenderer->SetSize(aSize); mrWindow.getContext()->setWinSize(aSize); - for(boost::ptr_vector<opengl3D::Renderable3DObject>::iterator itr = maShapes.begin(), - itrEnd = maShapes.end(); itr != itrEnd; ++itr) + if(mbNeedsNewRender) + { + for(boost::ptr_vector<opengl3D::Renderable3DObject>::iterator itr = maShapes.begin(), + itrEnd = maShapes.end(); itr != itrEnd; ++itr) + { + itr->render(); + } + } + else { - itr->render(); + mpCamera->render(); } + mbNeedsNewRender = false; mpRenderer->ProcessUnrenderedShape(); mrWindow.getContext()->swapBuffers(); } diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx index de92660..8c97ca8 100644 --- a/chart2/source/view/inc/GL3DBarChart.hxx +++ b/chart2/source/view/inc/GL3DBarChart.hxx @@ -105,6 +105,7 @@ private: std::map<sal_uInt32, const BarInformation> maBarMap; bool mbBlockUserInput; + bool mbNeedsNewRender; }; } diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index f16340d..4e85568 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -184,6 +184,9 @@ public: void SetPickingMode(bool bPickingMode); sal_uInt32 GetPixelColorFromPoint(long nX, long nY); + + void ReleaseShapes(); + void ReleaseScreenTextShapes(); private: void MoveModelf(PosVecf3& trans,PosVecf3& angle,PosVecf3& scale); @@ -219,11 +222,9 @@ private: int iSubDivZ, float width, float height, float depth); void CreateSceneBoxView(); - void ReleaseShapes(); void ReleasePolygonShapes(); void ReleaseExtrude3DShapes(); void ReleaseTextShapes(); - void ReleaseScreenTextShapes(); void ReleaseBatchBarInfo(); void GetBatchBarsInfo(); void GetBatchTopAndFlatInfo(Extrude3DInfo &extrude3D); diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index a6605a8..ae987ae 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -1711,7 +1711,6 @@ void OpenGL3DRenderer::ProcessUnrenderedShape() RenderTextShape(); // render screen text RenderScreenTextShape(); - ReleaseShapes(); #if DEBUG_FBO OUString aFileName = OUString("D://shaderout_") + OUString::number(m_iWidth) + "_" + OUString::number(m_iHeight) + ".png"; OpenGLHelper::renderToFile(m_iWidth, m_iHeight, aFileName); @@ -1762,7 +1761,6 @@ void OpenGL3DRenderer::ReleaseBatchBarInfo() } } - void OpenGL3DRenderer::ReleaseShapes() { ReleasePolygonShapes(); commit 8287ee51e91899bf2eac35b0eee567998cc99a25 Author: Markus Mohrhard <markus.mohrh...@collabora.co.uk> Date: Wed May 28 18:32:16 2014 +0200 fix picking mode for the batch rendering Change-Id: I9bfe64d56f9217561bb059eacde1fa3ece5f2cc1 diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index d0ada46..a6605a8 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -1703,8 +1703,10 @@ void OpenGL3DRenderer::ProcessUnrenderedShape() //Polygon RenderPolygon3DObject(); //Shape3DExtrudeObject - RenderBatchBars(); -// RenderExtrude3DObject(); + if(mbPickingMode) + RenderExtrude3DObject(); + else + RenderBatchBars(); //render text RenderTextShape(); // render screen text commit 3827c502946b60f314ef2fe566b990732dc7cd26 Author: Markus Mohrhard <markus.mohrh...@collabora.co.uk> Date: Wed May 28 18:28:59 2014 +0200 remove unnecessary glFinish Change-Id: I368e045a7635410a94f2f3a794e1c75a39418520 diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index 987c5e6..d0ada46 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -1965,7 +1965,6 @@ void OpenGL3DRenderer::RenderBatchBars() glDisableVertexAttribArray(maResources.m_3DBatchNormalMatrixID + i); glVertexAttribDivisor(maResources.m_3DBatchNormalMatrixID + i, 0); } - glFinish(); glUseProgram(0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glDisable(GL_CULL_FACE); commit 6d1598c30e99a951d635b53cb52af12e9a6c94b7 Author: weigao <wei...@multicorewareinc.com> Date: Wed May 28 20:53:07 2014 +0800 Modify the bar generate function Conflicts: chart2/source/view/main/GL3DRenderer.cxx Change-Id: Ia323c54b9113be15f01bff2a2f1e66da8ebfc39c diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index a031ab1..987c5e6 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -299,6 +299,7 @@ void OpenGL3DRenderer::init() OpenGLHelper::createFramebuffer(m_iWidth, m_iHeight, mnPickingFbo, mnPickingRboDepth, mnPickingRboColor); + m_Extrude3DInfo.rounded = false; CHECK_GL_ERROR(); Init3DUniformBlock(); InitBatch3DUniformBlock(); @@ -378,10 +379,6 @@ void OpenGL3DRenderer::SetVertex(PackedVertex &packed, void OpenGL3DRenderer::CreateActualRoundedCube(float fRadius, int iSubDivY, int iSubDivZ, float width, float height, float depth) { - if ((fRadius > (width / 2)) || (fRadius > (height / 2)) || (fRadius > (depth / 2))) - { - return; - } float topThreshold = depth - 2 * fRadius; float bottomThreshold = fRadius; @@ -1033,12 +1030,14 @@ void OpenGL3DRenderer::AddShape3DExtrudeObject(bool roundedCorner, sal_uInt32 nC m_Extrude3DInfo.xTransform = tranform.x; m_Extrude3DInfo.yTransform = tranform.y; m_Extrude3DInfo.zTransform = tranform.z; - m_Extrude3DInfo.rounded = roundedCorner; - if (m_Extrude3DInfo.rounded && (m_RoundBarMesh.iMeshSizes == 0)) - { - float radius = 0.2f; - CreateActualRoundedCube(radius, CORNER_DIVION_Y, CORNER_DIVION_Z, - 1.0f, m_Extrude3DInfo.yScale / m_Extrude3DInfo.xScale, 1 + 2 * radius); + float width = 1.0f; + float height = m_Extrude3DInfo.yScale / m_Extrude3DInfo.xScale; + float radius = height > 0.2f ? 0.2f : height / 4.0f; + float depth = 1 + 2 * radius; + bool NORoundedCube = (radius > (width / 2)) || (radius > (height / 2)) || (radius > (depth / 2)); + if (!NORoundedCube && roundedCorner && (m_RoundBarMesh.iMeshSizes == 0)) + { + CreateActualRoundedCube(radius, CORNER_DIVION_Y, CORNER_DIVION_Z, width, height, depth); AddVertexData(m_CubeVertexBuf); AddNormalData(m_CubeNormalBuf); AddIndexData(m_CubeElementBuf); @@ -1050,6 +1049,7 @@ void OpenGL3DRenderer::AddShape3DExtrudeObject(bool roundedCorner, sal_uInt32 nC m_Vertices.clear(); m_Normals.clear(); m_Indices.clear(); + m_Extrude3DInfo.rounded = true; } m_Batchmaterial = m_Extrude3DInfo.material; } @@ -1871,7 +1871,6 @@ void OpenGL3DRenderer::RenderBatchBars() glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); - glUseProgram(maResources.m_3DBatchProID); UpdateBatch3DUniformBlock(); glBindBuffer(GL_UNIFORM_BUFFER, m_Batch3DUBOBuffer); commit 4cde86a6e4648f49eb554cfaafcbf603c1a8a7c8 Author: weigao <wei...@multicorewareinc.com> Date: Wed May 28 13:35:40 2014 +0800 add batch render function diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index 4b2f906..f16340d 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -230,6 +230,7 @@ private: void GetBatchMiddleInfo(Extrude3DInfo &extrude3D); void InitBatch3DUniformBlock(); void UpdateBatch3DUniformBlock(); + void RenderBatchBars(); private: struct ShaderResources diff --git a/chart2/source/view/inc/StaticGeometry.h b/chart2/source/view/inc/StaticGeometry.h index 3ff412a..525b15b 100644 --- a/chart2/source/view/inc/StaticGeometry.h +++ b/chart2/source/view/inc/StaticGeometry.h @@ -12,9 +12,9 @@ #define TOP_SURFACE 0 #define MIDDLE_SURFACE 1 -#define BOTTOM_SURFACE 2 -#define FLAT_TOP_SURFACE 3 -#define FLAT_BOTTOM_SURFACE 4 +#define FLAT_BOTTOM_SURFACE 2 +#define BOTTOM_SURFACE 3 +#define FLAT_TOP_SURFACE 4 static GLfloat boundBox[] = { 0.0f, 0.0f, 0.0f, diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index e96b150..a031ab1 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -119,6 +119,9 @@ OpenGL3DRenderer::~OpenGL3DRenderer() glDeleteBuffers(1, &m_3DUBOBuffer); glDeleteBuffers(1, &m_VertexBuffer); glDeleteBuffers(1, &m_NormalBuffer); + glDeleteBuffers(1, &m_Batch3DUBOBuffer); + glDeleteBuffers(1, &m_3DUBOBuffer); + glDeleteBuffers(1, &m_3DUBOBuffer); glDeleteFramebuffers(1, &mnPickingFbo); glDeleteRenderbuffers(1, &mnPickingRboDepth); @@ -146,6 +149,14 @@ OpenGL3DRenderer::ShaderResources::ShaderResources() , m_2DVertexID(0) , m_2DColorID(0) , m_MatrixID(0) + , m_3DBatchProID(0) + , m_3DBatchProjectionID(0) + , m_3DBatchViewID(0) + , m_3DBatchModelID(0) + , m_3DBatchNormalMatrixID(0) + , m_3DBatchVertexID(0) + , m_3DBatchNormalID(0) + , m_3DBatchColorID(0) { } @@ -155,6 +166,7 @@ OpenGL3DRenderer::ShaderResources::~ShaderResources() glDeleteProgram(m_TextProID); glDeleteProgram(m_ScreenTextProID); glDeleteProgram(m_3DProID); + glDeleteProgram(m_3DBatchProID); } void OpenGL3DRenderer::ShaderResources::LoadShaders() @@ -183,6 +195,14 @@ void OpenGL3DRenderer::ShaderResources::LoadShaders() m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition"); m_2DColorID = glGetUniformLocation(m_CommonProID, "vColor"); + m_3DBatchProID = OpenGLHelper::LoadShaders("shape3DVertexShaderBatch", "shape3DFragmentShaderBatch"); + m_3DBatchProjectionID = glGetUniformLocation(m_3DBatchProID, "P"); + m_3DBatchViewID = glGetUniformLocation(m_3DBatchProID, "V"); + m_3DBatchModelID = glGetAttribLocation(m_3DBatchProID, "M"); + m_3DBatchNormalMatrixID = glGetAttribLocation(m_3DBatchProID, "normalMatrix"); + m_3DBatchVertexID = glGetAttribLocation(m_3DBatchProID, "vertexPositionModelspace"); + m_3DBatchNormalID = glGetAttribLocation(m_3DBatchProID, "vertexNormalModelspace"); + m_3DBatchColorID = glGetAttribLocation(m_3DBatchProID, "barColor"); CHECK_GL_ERROR(); } @@ -243,6 +263,9 @@ void OpenGL3DRenderer::init() glGenBuffers(1, &m_CubeElementBuf); glGenBuffers(1, &m_VertexBuffer); glGenBuffers(1, &m_NormalBuffer); + glGenBuffers(1, &m_BatchModelMatrixBuf); + glGenBuffers(1, &m_BatchNormalMatrixBuf); + glGenBuffers(1, &m_BatchColorBuf); glGenBuffers(1, &m_BoundBox); glBindBuffer(GL_ARRAY_BUFFER, m_BoundBox); glBufferData(GL_ARRAY_BUFFER, sizeof(boundBox), boundBox, GL_STATIC_DRAW); @@ -1028,6 +1051,7 @@ void OpenGL3DRenderer::AddShape3DExtrudeObject(bool roundedCorner, sal_uInt32 nC m_Normals.clear(); m_Indices.clear(); } + m_Batchmaterial = m_Extrude3DInfo.material; } void OpenGL3DRenderer::EndAddShape3DExtrudeObject() @@ -1679,7 +1703,8 @@ void OpenGL3DRenderer::ProcessUnrenderedShape() //Polygon RenderPolygon3DObject(); //Shape3DExtrudeObject - RenderExtrude3DObject(); + RenderBatchBars(); +// RenderExtrude3DObject(); //render text RenderTextShape(); // render screen text @@ -1839,6 +1864,113 @@ void OpenGL3DRenderer::GetBatchBarsInfo() } } } + +void OpenGL3DRenderer::RenderBatchBars() +{ + GetBatchBarsInfo(); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + + glUseProgram(maResources.m_3DBatchProID); + UpdateBatch3DUniformBlock(); + glBindBuffer(GL_UNIFORM_BUFFER, m_Batch3DUBOBuffer); + glBufferSubData(GL_UNIFORM_BUFFER, m_Batch3DActualSizeLight, sizeof(MaterialParameters), &m_Batchmaterial); + CHECK_GL_ERROR(); + glBindBuffer(GL_UNIFORM_BUFFER, 0); + glUniformMatrix4fv(maResources.m_3DBatchViewID, 1, GL_FALSE, &m_3DView[0][0]); + glUniformMatrix4fv(maResources.m_3DBatchProjectionID, 1, GL_FALSE, &m_3DProjection[0][0]); + CHECK_GL_ERROR(); + GLuint vertexBuf = m_Extrude3DInfo.rounded ? m_CubeVertexBuf : m_BoundBox; + GLuint normalBuf = m_Extrude3DInfo.rounded ? m_CubeNormalBuf : m_BoundBoxNormal; + //vertex + glEnableVertexAttribArray(maResources.m_3DBatchVertexID); + glBindBuffer(GL_ARRAY_BUFFER, vertexBuf); + glVertexAttribPointer(maResources.m_3DBatchVertexID, // attribute + 3, // size + GL_FLOAT, // type + GL_FALSE, // normalized? + 0, // stride + (void*)0 // array buffer offset + ); + //normal + glEnableVertexAttribArray(maResources.m_3DBatchNormalID); + glBindBuffer(GL_ARRAY_BUFFER, normalBuf); + glVertexAttribPointer(maResources.m_3DBatchNormalID, // attribute + 3, // size + GL_FLOAT, // type + GL_FALSE, // normalized? + 0, // stride + (void*)0 // array buffer offset + ); + + for (unsigned int i = 0; i < 4 ; i++) + { + glEnableVertexAttribArray(maResources.m_3DBatchModelID + i); + glBindBuffer(GL_ARRAY_BUFFER, m_BatchModelMatrixBuf); + glVertexAttribPointer(maResources.m_3DBatchModelID + i, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), reinterpret_cast<GLvoid*>(sizeof(GLfloat) * i * 4)); + glVertexAttribDivisor(maResources.m_3DBatchModelID + i, 1); + } + + for (unsigned int i = 0; i < 3 ; i++) + { + glEnableVertexAttribArray(maResources.m_3DBatchNormalMatrixID + i); + glBindBuffer(GL_ARRAY_BUFFER, m_BatchNormalMatrixBuf); + glVertexAttribPointer(maResources.m_3DBatchNormalMatrixID + i, 3, GL_FLOAT, GL_FALSE, sizeof(glm::mat3), reinterpret_cast<GLvoid*>(sizeof(GLfloat) * i * 3)); + glVertexAttribDivisor(maResources.m_3DBatchNormalMatrixID + i, 1); + } + glEnableVertexAttribArray(maResources.m_3DBatchColorID); + glBindBuffer(GL_ARRAY_BUFFER, m_BatchColorBuf); + glVertexAttribPointer(maResources.m_3DBatchColorID , 4, GL_FLOAT, GL_FALSE, sizeof(glm::vec4), 0); + glVertexAttribDivisor(maResources.m_3DBatchColorID, 1); + if (m_Extrude3DInfo.rounded) + { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_CubeElementBuf); + for (int i = 0; i < 3; i++) + { + glBindBuffer(GL_ARRAY_BUFFER, m_BatchModelMatrixBuf); + glBufferData(GL_ARRAY_BUFFER, sizeof(glm::mat4) * m_BarSurface[i].modelMatrixList.size(), &m_BarSurface[i].modelMatrixList[0][0], GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, m_BatchNormalMatrixBuf); + glBufferData(GL_ARRAY_BUFFER, sizeof(glm::mat3) * m_BarSurface[i].normalMatrixList.size(), &m_BarSurface[i].normalMatrixList[0][0], GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, m_BatchColorBuf); + glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec4) * m_BarSurface[i].colorList.size(), &m_BarSurface[i].colorList[0], GL_DYNAMIC_DRAW); + glDrawElementsInstancedBaseVertex(GL_TRIANGLES, + m_Extrude3DInfo.size[i], + GL_UNSIGNED_SHORT, + reinterpret_cast<GLvoid*>(m_Extrude3DInfo.startIndex[i]), + m_BarSurface[i].modelMatrixList.size(), + 0); + } + } + else + { + glBindBuffer(GL_ARRAY_BUFFER, m_BatchModelMatrixBuf); + glBufferData(GL_ARRAY_BUFFER, sizeof(glm::mat4) * m_BarSurface[0].modelMatrixList.size(), &m_BarSurface[0].modelMatrixList[0][0], GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, m_BatchNormalMatrixBuf); + glBufferData(GL_ARRAY_BUFFER, sizeof(glm::mat3) * m_BarSurface[0].normalMatrixList.size(), &m_BarSurface[0].normalMatrixList[0][0], GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, m_BatchColorBuf); + glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec4) * m_BarSurface[0].colorList.size(), &m_BarSurface[0].colorList[0], GL_DYNAMIC_DRAW); + glDrawArraysInstanced(GL_TRIANGLES, 0, 36, m_BarSurface[0].modelMatrixList.size()); + } + glDisableVertexAttribArray(maResources.m_3DBatchVertexID); + glDisableVertexAttribArray(maResources.m_3DBatchNormalID); + glDisableVertexAttribArray(maResources.m_3DBatchColorID); + glVertexAttribDivisor(maResources.m_3DBatchColorID, 0); + for (unsigned int i = 0; i < 4 ; i++) + { + glDisableVertexAttribArray(maResources.m_3DBatchModelID + i); + glVertexAttribDivisor(maResources.m_3DBatchModelID + i, 0); + } + for (unsigned int i = 0; i < 3 ; i++) + { + glDisableVertexAttribArray(maResources.m_3DBatchNormalMatrixID + i); + glVertexAttribDivisor(maResources.m_3DBatchNormalMatrixID + i, 0); + } + glFinish(); + glUseProgram(0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glDisable(GL_CULL_FACE); +} } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 3b3f92be9cd7d7ed32cb5650893d1ad512fb4a0b Author: weigao <wei...@multicorewareinc.com> Date: Wed May 28 13:06:07 2014 +0800 add get and release batch render info function diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index 88e5666..4b2f906 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -225,6 +225,9 @@ private: void ReleaseTextShapes(); void ReleaseScreenTextShapes(); void ReleaseBatchBarInfo(); + void GetBatchBarsInfo(); + void GetBatchTopAndFlatInfo(Extrude3DInfo &extrude3D); + void GetBatchMiddleInfo(Extrude3DInfo &extrude3D); void InitBatch3DUniformBlock(); void UpdateBatch3DUniformBlock(); private: diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index 59d0f92..e96b150 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -1725,16 +1725,120 @@ sal_uInt32 OpenGL3DRenderer::GetPixelColorFromPoint(long nX, long nY) return aColor.GetColor(); } +void OpenGL3DRenderer::ReleaseBatchBarInfo() +{ + for (int i = 0; i < 3; i++) + { + m_BarSurface[i].modelMatrixList.clear(); + m_BarSurface[i].normalMatrixList.clear(); + m_BarSurface[i].colorList.clear(); + } +} + + void OpenGL3DRenderer::ReleaseShapes() { ReleasePolygonShapes(); ReleaseExtrude3DShapes(); ReleaseTextShapes(); ReleaseScreenTextShapes(); + ReleaseBatchBarInfo(); } +void OpenGL3DRenderer::GetBatchMiddleInfo(Extrude3DInfo &extrude3D) +{ + float xyScale = extrude3D.xScale; + float zScale = extrude3D.zScale; + float actualZScale = zScale - m_RoundBarMesh.bottomThreshold * xyScale; + PosVecf3 trans = {extrude3D.xTransform, + extrude3D.yTransform, + extrude3D.zTransform}; + if (actualZScale < 0.0f) + { + return ; + } + else + { + glm::mat4 scale = glm::scale(xyScale, xyScale,actualZScale); + glm::mat4 aTranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z)); + m_Model = aTranslationMatrix * extrude3D.rotation * scale; + } + glm::mat3 normalMatrix(m_Model); + glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix); + m_BarSurface[MIDDLE_SURFACE].modelMatrixList.push_back(m_Model); + m_BarSurface[MIDDLE_SURFACE].normalMatrixList.push_back(normalInverseTranspos); + m_BarSurface[MIDDLE_SURFACE].colorList.push_back(extrude3D.material.materialColor); } +void OpenGL3DRenderer::GetBatchTopAndFlatInfo(Extrude3DInfo &extrude3D) +{ + float xyScale = extrude3D.xScale; + float zScale = extrude3D.zScale; + float actualZTrans = zScale - m_RoundBarMesh.bottomThreshold * xyScale; + PosVecf3 trans = {extrude3D.xTransform, + extrude3D.yTransform, + extrude3D.zTransform}; + glm::mat4 orgTrans = glm::translate(glm::vec3(0.0, 0.0, -1.0)); + if (actualZTrans < 0.0f) + { + // the height of rounded corner is higher than the cube than use the org scale matrix + //yScale /= (float)(1 + BOTTOM_THRESHOLD); + zScale /= (float)(m_RoundBarMesh.bottomThreshold); + glm::mat4 scale = glm::scale(xyScale, xyScale, zScale); + //MoveModelf(trans, angle, scale); + glm::mat4 aTranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z)); + m_Model = aTranslationMatrix * extrude3D.rotation * scale * orgTrans; + } + else + { + // use different matrices for different parts + glm::mat4 topTrans = glm::translate(glm::vec3(0.0, 0.0, actualZTrans)); + glm::mat4 topScale = glm::scale(xyScale, xyScale, xyScale); + glm::mat4 aTranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z)); + m_Model = aTranslationMatrix * extrude3D.rotation * topTrans * topScale * orgTrans; + } + glm::mat3 normalMatrix(m_Model); + glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix); + m_BarSurface[TOP_SURFACE].modelMatrixList.push_back(m_Model); + m_BarSurface[TOP_SURFACE].normalMatrixList.push_back(normalInverseTranspos); + m_BarSurface[TOP_SURFACE].colorList.push_back(extrude3D.material.materialColor); + + 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; + normalMatrix = glm::mat3(m_Model); + normalInverseTranspos = glm::inverseTranspose(normalMatrix); + + m_BarSurface[FLAT_BOTTOM_SURFACE].modelMatrixList.push_back(m_Model); + m_BarSurface[FLAT_BOTTOM_SURFACE].normalMatrixList.push_back(normalInverseTranspos); + m_BarSurface[FLAT_BOTTOM_SURFACE].colorList.push_back(extrude3D.material.materialColor); } +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); + GetBatchMiddleInfo(extrude3DInfo); + } + else + { + 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; + glm::mat3 normalMatrix(m_Model); + glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix); + m_BarSurface[0].modelMatrixList.push_back(m_Model); + m_BarSurface[0].normalMatrixList.push_back(normalInverseTranspos); + m_BarSurface[0].colorList.push_back(extrude3DInfo.material.materialColor); + } + } +} +} +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 0e332ba4e618413bb938f8aee3553530470d20ad Author: weigao <wei...@multicorewareinc.com> Date: Wed May 28 12:50:38 2014 +0800 add use and update uno function Change-Id: I79d7d7ab77fff9a5e60a392e94fe2dd839803b64 diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index 5e81419..88e5666 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -224,6 +224,9 @@ private: void ReleaseExtrude3DShapes(); void ReleaseTextShapes(); void ReleaseScreenTextShapes(); + void ReleaseBatchBarInfo(); + void InitBatch3DUniformBlock(); + void UpdateBatch3DUniformBlock(); private: struct ShaderResources diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index d869e16..59d0f92 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -278,6 +278,7 @@ void OpenGL3DRenderer::init() CHECK_GL_ERROR(); Init3DUniformBlock(); + InitBatch3DUniformBlock(); glViewport(0, 0, m_iWidth, m_iHeight); Set3DSenceInfo(0xFFFFFF, true); @@ -1070,6 +1071,59 @@ void OpenGL3DRenderer::Init3DUniformBlock() glBindBuffer(GL_UNIFORM_BUFFER, 0); } +void OpenGL3DRenderer::InitBatch3DUniformBlock() +{ + if(mbPickingMode) + return; + + GLuint a3DLightBlockIndex = glGetUniformBlockIndex(maResources.m_3DBatchProID, "GlobalLights"); + GLuint a3DMaterialBlockIndex = glGetUniformBlockIndex(maResources.m_3DBatchProID, "GlobalMaterialParameters"); + + if ((GL_INVALID_INDEX == a3DLightBlockIndex) || (GL_INVALID_INDEX == a3DMaterialBlockIndex)) + { + return; + } + int nUniformBufferAlignSize = 1; + glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &nUniformBufferAlignSize); + GLint nBlockDataSizeLight = 0, nBlockDataSizeMertrial = 0; + glGetActiveUniformBlockiv(maResources.m_3DBatchProID, a3DLightBlockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &nBlockDataSizeLight); + glGetActiveUniformBlockiv(maResources.m_3DBatchProID, a3DMaterialBlockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &nBlockDataSizeMertrial); + CHECK_GL_ERROR(); + glGenBuffers(1, &m_Batch3DUBOBuffer); + glBindBuffer(GL_UNIFORM_BUFFER, m_Batch3DUBOBuffer); + CHECK_GL_ERROR(); + m_Batch3DActualSizeLight = ((nBlockDataSizeLight / nUniformBufferAlignSize) + std::min(nBlockDataSizeLight % nUniformBufferAlignSize, 1)) * nUniformBufferAlignSize; +// cout << "nBlockDataSizeMertrial = " << nBlockDataSizeMertrial << ", nBlockDataSizeLight = " << nBlockDataSizeLight << ", m_3DActualSizeLight = " << m_3DActualSizeLight << endl; + int dataSize = m_Batch3DActualSizeLight + nBlockDataSizeMertrial; + glBufferData(GL_UNIFORM_BUFFER, dataSize, NULL, GL_DYNAMIC_DRAW); + glBindBufferRange(GL_UNIFORM_BUFFER, 2, m_Batch3DUBOBuffer, 0, nBlockDataSizeLight); + CHECK_GL_ERROR(); + glUniformBlockBinding(maResources.m_3DBatchProID, a3DLightBlockIndex, 2); + + glBindBufferRange(GL_UNIFORM_BUFFER, 3, m_Batch3DUBOBuffer, ((nBlockDataSizeLight / nUniformBufferAlignSize) + std::min(nBlockDataSizeLight % nUniformBufferAlignSize, 1)) * nUniformBufferAlignSize, nBlockDataSizeMertrial); + glUniformBlockBinding(maResources.m_3DBatchProID, a3DMaterialBlockIndex, 3); + //for the light source uniform, we must calc the offset of each element + CHECK_GL_ERROR(); + glBindBuffer(GL_UNIFORM_BUFFER, 0); +} + +void OpenGL3DRenderer::UpdateBatch3DUniformBlock() +{ + if(mbPickingMode) + return; + + glBindBuffer(GL_UNIFORM_BUFFER, m_Batch3DUBOBuffer); + glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(GLint), &m_LightsInfo.lightNum); + CHECK_GL_ERROR(); + //current std140 alignment: 16 + glBufferSubData(GL_UNIFORM_BUFFER, 16, sizeof(glm::vec4), &m_LightsInfo.ambient[0]); + CHECK_GL_ERROR(); + //current std140 alignment: 16 + glBufferSubData(GL_UNIFORM_BUFFER, 32, sizeof(LightSource) * MAX_LIGHT_NUM, &m_LightsInfo.light); + CHECK_GL_ERROR(); + glBindBuffer(GL_UNIFORM_BUFFER, 0); +} + void OpenGL3DRenderer::Update3DUniformBlock() { if(mbPickingMode) commit 47a417d93aa7a68f1b3b371e2a4a6b07fb1c6f07 Author: weigao <wei...@multicorewareinc.com> Date: Wed May 28 12:43:43 2014 +0800 add batch render variables Change-Id: Idfd6f5ce5f711631d6115fe9227724891ccd95ef diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index 4cba423..5e81419 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -142,6 +142,13 @@ struct TextInfo float vertex[12]; }; +struct BatchBarInfo +{ + std::vector <glm::mat4> modelMatrixList; + std::vector <glm::mat3> normalMatrixList; + std::vector <glm::vec4> colorList; +}; + class OpenGL3DRenderer { public: @@ -249,6 +256,16 @@ private: GLint m_2DColorID; GLint m_MatrixID; + // Batch render + GLint m_3DBatchProID; + GLint m_3DBatchProjectionID; + GLint m_3DBatchViewID; + GLint m_3DBatchModelID; + GLint m_3DBatchNormalMatrixID; + GLint m_3DBatchVertexID; + GLint m_3DBatchNormalID; + GLint m_3DBatchColorID; + ShaderResources(); ~ShaderResources(); @@ -343,6 +360,14 @@ private: GLuint mnPickingFbo; GLuint mnPickingRboDepth; GLuint mnPickingRboColor; + + BatchBarInfo m_BarSurface[3]; + GLuint m_BatchModelMatrixBuf; + GLuint m_BatchNormalMatrixBuf; + GLuint m_BatchColorBuf; + MaterialParameters m_Batchmaterial; + GLuint m_Batch3DUBOBuffer; + GLint m_Batch3DActualSizeLight; }; } commit ddeea3043d479e7c71f8f886bd0109920bc3003e Author: weigao <wei...@multicorewareinc.com> Date: Wed May 28 12:39:17 2014 +0800 add batch render shader Change-Id: I44cd54b35f872365268db3b4455beeac01ba3197 diff --git a/chart2/Package_opengl.mk b/chart2/Package_opengl.mk index 99cdde3..d8f9fa7 100644 --- a/chart2/Package_opengl.mk +++ b/chart2/Package_opengl.mk @@ -28,6 +28,8 @@ $(eval $(call gb_Package_add_files,chart2_opengl_shader,$(LIBO_BIN_FOLDER)/openg shape3DVertexShader.glsl \ renderTextureVertexShader.glsl \ renderTextureFragmentShader.glsl \ + shape3DFragmentShaderBatch.glsl \ + shape3DVertexShaderBatch.glsl \ )) # vim: set noet sw=4 ts=4: diff --git a/chart2/opengl/shape3DFragmentShaderBatch.glsl b/chart2/opengl/shape3DFragmentShaderBatch.glsl new file mode 100644 index 0000000..b7bdc7e --- /dev/null +++ b/chart2/opengl/shape3DFragmentShaderBatch.glsl @@ -0,0 +1,108 @@ +/* -*- 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 +#define MAX_LIGHT_NUM 8 + +in vec3 positionWorldspace; +in vec3 normalCameraspace; +in vec4 fragBarColor; +uniform mat4 V; +out vec4 actualColor; +struct MaterialParameters +{ + vec4 ambient; + vec4 diffuse; + vec4 specular; + vec4 materialColor; + + int twoSidesLighting; + float shininess; + float pad; + float pad1; +}; + +layout(std140) uniform GlobalMaterialParameters +{ + MaterialParameters matralParameter; +}Material; + +struct LightSource +{ + vec4 lightColor; + vec4 positionWorldspace; + float lightPower; + float pad1; + float pad2; + float pad3; +}; + +layout(std140) uniform GlobalLights +{ + int lightNum; + vec4 ambient; + LightSource light[MAX_LIGHT_NUM]; +} Lights; + +void main() +{ + vec3 colorTotal = vec3(0.0f, 0.0f, 0.0f); + + vec3 vertexPositionCameraspace = (V * vec4(positionWorldspace,1)).xyz; + + vec3 MaterialDiffuseColor = fragBarColor.rgb; + + vec3 normalDirectionCameraspace = normalCameraspace; + vec3 eyeDirectionCameraspace = normalize(vec3(0, 0, 0) - vertexPositionCameraspace); + float attenuation = 1.0; + int i = 0; + vec3 lightDirectionCameraspace; + vec3 vertexToLightSource; + + vec3 lightAmbient = Lights.ambient.rgb * + MaterialDiffuseColor * + Material.matralParameter.ambient.rgb + * 5.0; + + for (i = 0; i < Lights.lightNum; i++) + { + float LightPower = Lights.light[i].lightPower; + lightDirectionCameraspace = normalize((V * Lights.light[i].positionWorldspace).xyz); + + float cosTheta = clamp(dot(normalDirectionCameraspace,lightDirectionCameraspace), 0,1); + vec3 lightDiffuse = LightPower * + attenuation * + Lights.light[i].lightColor.rgb * + MaterialDiffuseColor * + Material.matralParameter.diffuse.rgb * + cosTheta; + + vec3 specularReflection; + if (dot(normalDirectionCameraspace, lightDirectionCameraspace) < 0) + { + specularReflection = vec3(0.0, 0.0, 0.0); + } + else + { + vec3 R = reflect(-lightDirectionCameraspace,normalDirectionCameraspace); + float cosAlpha = clamp(dot(eyeDirectionCameraspace, R), 0,1); + specularReflection = attenuation * + LightPower * + Lights.light[i].lightColor.rgb * + Material.matralParameter.specular.rgb * + MaterialDiffuseColor * + pow(max(0.0, cosAlpha), Material.matralParameter.shininess); + } + colorTotal += lightDiffuse + specularReflection; + + } + colorTotal += lightAmbient; + actualColor = vec4(colorTotal, 1.0); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/opengl/shape3DVertexShaderBatch.glsl b/chart2/opengl/shape3DVertexShaderBatch.glsl new file mode 100644 index 0000000..8c27c7a --- /dev/null +++ b/chart2/opengl/shape3DVertexShaderBatch.glsl @@ -0,0 +1,34 @@ +/* -*- 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 vertexPositionModelspace; +in vec3 vertexNormalModelspace; +in mat4 M; +in mat3 normalMatrix; +in vec4 barColor; + +out vec3 positionWorldspace; +out vec3 normalCameraspace; +out vec4 fragBarColor; + +uniform mat4 P; +uniform mat4 V; + +void main() +{ + gl_Position = P * V * M * vec4(vertexPositionModelspace,1); + + positionWorldspace = (M * vec4(vertexPositionModelspace,1)).xyz; + + normalCameraspace = normalize(mat3(V) * normalMatrix * vertexNormalModelspace); + + fragBarColor = barColor; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits