chart2/Package_opengl.mk | 2 chart2/opengl/shape3DFragmentShader.glsl | 111 +++++++++++++++++++++ chart2/opengl/shape3DVertexShader.glsl | 30 +++++ chart2/source/view/inc/3DChartObjects.hxx | 12 ++ chart2/source/view/inc/GL3DRenderer.hxx | 11 +- chart2/source/view/main/3DChartObjects.cxx | 34 ++++++ chart2/source/view/main/GL3DRenderer.cxx | 148 +++++++++++------------------ 7 files changed, 254 insertions(+), 94 deletions(-)
New commits: commit e0dc3c8a0a69bb44a583b42d6fb823efbc311dc5 Author: xukai <[email protected]> Date: Mon May 5 14:05:08 2014 +0800 add codes to Line::render() Change-Id: I6510f486707b08ea8f611105f40cc4c7e1581a7f diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index 54b6a24..b1f8de4 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -54,6 +54,8 @@ class Line : public Renderable3DObject public: Line( sal_uInt32 nId ); + virtual void render() SAL_OVERRIDE; + private: glm::vec3 maPosBegin; glm::vec3 maPosEnd; @@ -87,7 +89,7 @@ class Camera : public Renderable3DObject { public: Camera(); - virtual void render(); + virtual void render() SAL_OVERRIDE; private: glm::vec3 maPos; glm::vec3 maUp; diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index 38279a3..045107b 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -54,6 +54,14 @@ Line::Line(sal_uInt32 nId): { } +void Line::render() +{ + getRender()->AddShapePolygon3DObject(0, true, (sal_Int32)maLineColor.GetColor(), 0, 0); + getRender()->AddPolygon3DObjectPoint(maPosBegin.x, maPosBegin.y, maPosBegin.z); + getRender()->AddPolygon3DObjectPoint(maPosEnd.x, maPosEnd.y, maPosEnd.z); + getRender()->EndAddShapePolygon3DObject(); +} + Text::Text(sal_uInt32 nId): Renderable3DObject(nId) { commit 461aa03c95e3297041de4eec8b3d44da348f60e8 Author: xukai <[email protected]> Date: Mon May 5 13:00:46 2014 +0800 remove the codes of set camera info to render() Change-Id: I9c2aecd5dea617e7cd69c1fc005b6a9ee237f202 diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index 1fa9402..54b6a24 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -87,6 +87,7 @@ class Camera : public Renderable3DObject { public: Camera(); + virtual void render(); private: glm::vec3 maPos; glm::vec3 maUp; diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index 6148f03..38279a3 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -70,9 +70,14 @@ Camera::Camera(): maUp(0, 1, 0), maDirection(glm::vec3(0,0,0)-maPos) { +} + +void Camera::render() +{ getRender()->SetCameraInfo(maPos, maDirection, maUp, true); } + namespace temporary { TemporaryContext::TemporaryContext(): commit 4e8a9d669f835cb2f1df3efc9b41d86d51af90d7 Author: xukai <[email protected]> Date: Mon May 5 12:25:42 2014 +0800 add codes to set camera info Change-Id: Id6bac3a8dd46d7994c9e64c9e0c16e8c7ac036ac diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index e3165e2..1fa9402 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -89,6 +89,7 @@ public: Camera(); private: glm::vec3 maPos; + glm::vec3 maUp; glm::vec3 maDirection; }; diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index b31a5ac..5f66203 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -109,6 +109,7 @@ typedef struct Extrude3DInfo typedef struct CameraInfo { + bool useDefault; glm::vec3 cameraPos; glm::vec3 cameraOrg; glm::vec3 cameraUp; @@ -179,7 +180,7 @@ public: void SetClickPos(Point aMPos); void RenderClickPos(Point aMPos); void SetSize(const Size& rSize); - + void SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up, bool useDefalut); private: void MoveModelf(PosVecf3& trans,PosVecf3& angle,PosVecf3& scale); diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index f7e0eb7..6148f03 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -67,8 +67,10 @@ Rectangle::Rectangle(sal_uInt32 nId): Camera::Camera(): Renderable3DObject(0), maPos(10,10,-10), + maUp(0, 1, 0), maDirection(glm::vec3(0,0,0)-maPos) { + getRender()->SetCameraInfo(maPos, maDirection, maUp, true); } namespace temporary { diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index baa8cba..651fca4 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -96,6 +96,8 @@ OpenGL3DRenderer::OpenGL3DRenderer(): m_SenceBox.minZCoord = FLT_MAX; m_uiSelectFrameCounter = 0; m_fHeightWeight = 1.0f; + m_CameraInfo.useDefault = true; + m_CameraInfo.cameraUp = glm::vec3(0, 1, 0); } void OpenGL3DRenderer::LoadShaders() @@ -111,6 +113,18 @@ void OpenGL3DRenderer::LoadShaders() Init3DUniformBlock(); } +void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up, bool useDefalut) +{ + m_CameraInfo.useDefault = useDefalut; + if (m_CameraInfo.useDefault) + { + return; + } + m_CameraInfo.cameraPos = pos; + m_CameraInfo.cameraOrg = pos + direction; + m_CameraInfo.cameraUp = up; +} + void OpenGL3DRenderer::init() { glGenBuffers(1, &m_CubeVertexBuf); @@ -801,21 +815,6 @@ void OpenGL3DRenderer::EndAddShapePolygon3DObject() void OpenGL3DRenderer::AddPolygon3DObjectNormalPoint(float x, float y, float z) { - float actualX = x - (float)m_iWidth / 2; - float actualY = y - (float)m_iHeight / 2; - float actualZ = z; - float maxCoord = std::max(actualX, std::max(actualY, actualZ)); - m_fZmax = std::max(maxCoord, m_fZmax); - m_Polygon3DInfo.vertices->push_back(glm::vec3(actualX, -actualY, actualZ)); - - m_SenceBox.maxXCoord = std::max(m_SenceBox.maxXCoord, actualX); - m_SenceBox.minXCoord = std::min(m_SenceBox.minXCoord, actualX); - - m_SenceBox.maxYCoord = std::max(m_SenceBox.maxYCoord, actualY); - m_SenceBox.minYCoord = std::min(m_SenceBox.minYCoord, actualY); - - m_SenceBox.maxZCoord = std::max(m_SenceBox.maxZCoord, actualZ); - m_SenceBox.minZCoord = std::min(m_SenceBox.minZCoord, actualZ); if (m_Polygon3DInfo.fillStyle) { if (!m_Polygon3DInfo.normals) @@ -844,61 +843,19 @@ void OpenGL3DRenderer::AddPolygon3DObjectPoint(float x, float y, float z) float maxCoord = std::max(actualX, std::max(actualY, actualZ)); m_fZmax = std::max(maxCoord, m_fZmax); m_Polygon3DInfo.vertices->push_back(glm::vec3(actualX, -actualY, actualZ)); + m_SenceBox.maxXCoord = std::max(m_SenceBox.maxXCoord, actualX); + m_SenceBox.minXCoord = std::min(m_SenceBox.minXCoord, actualX); + + m_SenceBox.maxYCoord = std::max(m_SenceBox.maxYCoord, actualY); + m_SenceBox.minYCoord = std::min(m_SenceBox.minYCoord, actualY); + + m_SenceBox.maxZCoord = std::max(m_SenceBox.maxZCoord, actualZ); + m_SenceBox.minZCoord = std::min(m_SenceBox.minZCoord, actualZ); } void OpenGL3DRenderer::EndAddPolygon3DObjectPoint() { m_Polygon3DInfo.verticesList.push_back(m_Polygon3DInfo.vertices); - //get the buttom surface to calc the camera org, just for the demo - if (m_Polygon3DInfo.vertices->size() && !m_bCameraUpdated) - { - float minX = m_Polygon3DInfo.vertices->at(0).x; - float maxX = m_Polygon3DInfo.vertices->at(0).x; - float minZ = m_Polygon3DInfo.vertices->at(0).z; - float maxZ = m_Polygon3DInfo.vertices->at(0).z; - float maxY = m_Polygon3DInfo.vertices->at(0).y; - float minY = m_Polygon3DInfo.vertices->at(0).y; - for (size_t i = 1; i < m_Polygon3DInfo.vertices->size(); i++) - { - minX = std::min(minX, m_Polygon3DInfo.vertices->at(i).x); - maxX = std::max(maxX, m_Polygon3DInfo.vertices->at(i).x); - minZ = std::min(minZ, m_Polygon3DInfo.vertices->at(i).z); - maxZ = std::max(maxZ, m_Polygon3DInfo.vertices->at(i).z); - minY = std::min(minY, m_Polygon3DInfo.vertices->at(i).y); - maxY = std::max(maxY, m_Polygon3DInfo.vertices->at(i).y); - } - - if (maxY == minY) - { - float distance = maxZ + 300; - float veriticalAngle = GL_PI / 6.0f; - float horizontalAngle = 0; - m_CameraInfo.cameraOrg = glm::vec3(minX + (maxX - minX) / 2, - minY + (maxY - minY) / 2, - minZ + (maxZ - minZ) / 2); - //update the camera position and org - m_CameraInfo.cameraPos.x = m_CameraInfo.cameraOrg.x + distance * cos(veriticalAngle) * sin(horizontalAngle); - m_CameraInfo.cameraPos.z = m_CameraInfo.cameraOrg.z + distance * cos(veriticalAngle) * cos(horizontalAngle); - m_CameraInfo.cameraPos.y = m_CameraInfo.cameraOrg.y - distance * sin(veriticalAngle); - - m_3DView = glm::lookAt(m_CameraInfo.cameraPos, // Camera is at (0,0,3), in World Space - m_CameraInfo.cameraOrg, // and looks at the origin - m_CameraInfo.cameraUp // Head is up (set to 0,-1,0 to look upside-down) - ); - m_3DViewBack = m_3DView; - #if 0 - cout << "update position" << endl; - cout << "m_CameraInfo.cameraPos.x = " << m_CameraInfo.cameraPos.x << endl; - cout << "m_CameraInfo.cameraPos.y = " << m_CameraInfo.cameraPos.y << endl; - cout << "m_CameraInfo.cameraPos.z = " << m_CameraInfo.cameraPos.z << endl; - - cout << "m_CameraInfo.cameraOrg.x = " << m_CameraInfo.cameraOrg.x << endl; - cout << "m_CameraInfo.cameraOrg.y = " << m_CameraInfo.cameraOrg.y << endl; - cout << "m_CameraInfo.cameraOrg.z = " << m_CameraInfo.cameraOrg.z << endl; - #endif - m_bCameraUpdated = true; - } - } m_Polygon3DInfo.vertices = NULL; } @@ -1263,14 +1220,16 @@ void OpenGL3DRenderer::CreateSceneBoxView() m_fHeightWeight = senceBoxWidth * (float)m_iHeight / (float)m_iWidth / senceBoxHeight; m_SenceBox.maxYCoord *= m_fHeightWeight; m_SenceBox.minYCoord *= m_fHeightWeight; - m_CameraInfo.cameraOrg = glm::vec3(m_SenceBox.minXCoord + senceBoxWidth / 2, - -m_SenceBox.minYCoord - senceBoxHeight * m_fHeightWeight/ 2, - m_SenceBox.minZCoord + senceBoxDepth / 2); - //update the camera position and org - m_CameraInfo.cameraPos.x = m_CameraInfo.cameraOrg.x + distance * cos(veriticalAngle) * sin(horizontalAngle); - m_CameraInfo.cameraPos.z = m_CameraInfo.cameraOrg.z + distance * cos(veriticalAngle) * cos(horizontalAngle); - m_CameraInfo.cameraPos.y = m_CameraInfo.cameraOrg.y - distance * sin(veriticalAngle); - + if (m_CameraInfo.useDefault) + { + m_CameraInfo.cameraOrg = glm::vec3(m_SenceBox.minXCoord + senceBoxWidth / 2, + -m_SenceBox.minYCoord - senceBoxHeight * m_fHeightWeight/ 2, + m_SenceBox.minZCoord + senceBoxDepth / 2); + //update the camera position and org + m_CameraInfo.cameraPos.x = m_CameraInfo.cameraOrg.x + distance * cos(veriticalAngle) * sin(horizontalAngle); + m_CameraInfo.cameraPos.z = m_CameraInfo.cameraOrg.z + distance * cos(veriticalAngle) * cos(horizontalAngle); + m_CameraInfo.cameraPos.y = m_CameraInfo.cameraOrg.y - distance * sin(veriticalAngle); + } m_3DView = glm::lookAt(m_CameraInfo.cameraPos, // Camera is at (0,0,3), in World Space m_CameraInfo.cameraOrg, // and looks at the origin m_CameraInfo.cameraUp // Head is up (set to 0,-1,0 to look upside-down) @@ -1395,14 +1354,16 @@ int OpenGL3DRenderer::ProcessExtrude3DPickingBox() extrude3DInfo.yRange[0] *= m_fHeightWeight; extrude3DInfo.yRange[1] *= m_fHeightWeight; int reverse = extrude3DInfo.yRange[0] > extrude3DInfo.yRange[1] ? 1 : -1; - m_CameraInfo.cameraOrg = glm::vec3(extrude3DInfo.xTransform + (extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0]) / 2, - -extrude3DInfo.yTransform + (extrude3DInfo.yRange[1] - extrude3DInfo.yRange[0]) *reverse, - extrude3DInfo.zTransform + (extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0]) / 2); - - m_CameraInfo.cameraPos.x = m_CameraInfo.cameraOrg.x - distance * cos(veriticalAngle) * sin(horizontalAngle); - m_CameraInfo.cameraPos.z = m_CameraInfo.cameraOrg.z + distance * cos(veriticalAngle) * cos(horizontalAngle); - m_CameraInfo.cameraPos.y = m_CameraInfo.cameraOrg.y + distance * sin(horizontalAngle) * reverse; + if (m_CameraInfo.useDefault) + { + m_CameraInfo.cameraOrg = glm::vec3(extrude3DInfo.xTransform + (extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0]) / 2, + -extrude3DInfo.yTransform + (extrude3DInfo.yRange[1] - extrude3DInfo.yRange[0]) *reverse, + extrude3DInfo.zTransform + (extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0]) / 2); + m_CameraInfo.cameraPos.x = m_CameraInfo.cameraOrg.x - distance * cos(veriticalAngle) * sin(horizontalAngle); + m_CameraInfo.cameraPos.z = m_CameraInfo.cameraOrg.z + distance * cos(veriticalAngle) * cos(horizontalAngle); + m_CameraInfo.cameraPos.y = m_CameraInfo.cameraOrg.y + distance * sin(horizontalAngle) * reverse; + } m_3DView = glm::lookAt(m_CameraInfo.cameraPos, // Camera is at (0,0,3), in World Space m_CameraInfo.cameraOrg, // and looks at the origin m_CameraInfo.cameraUp // Head is up (set to 0,-1,0 to look upside-down) commit 0714c0aba7ceb38ba73e11f6ee00ba876b3f48a0 Author: xukai <[email protected]> Date: Mon May 5 11:54:26 2014 +0800 Initial size of OpenGL3DRenderer Change-Id: Ibfed531e48848ea711be429d6e5c08094473f781 diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index c953eea..e3165e2 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -30,7 +30,7 @@ public: virtual void render(); - void getRender(); + OpenGL3DRenderer* getRender(); protected: sal_uInt32 mnUniqueId; @@ -94,7 +94,7 @@ private: namespace temporary { -class TemporaryContext +class TemporaryContext: public opengl3D::Renderable3DObject { public: TemporaryContext(); diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index abf611e..b31a5ac 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -178,6 +178,7 @@ public: void SetFPS(float fps); void SetClickPos(Point aMPos); void RenderClickPos(Point aMPos); + void SetSize(const Size& rSize); private: void MoveModelf(PosVecf3& trans,PosVecf3& angle,PosVecf3& scale); diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index 17d8111..f7e0eb7 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -25,7 +25,7 @@ void Renderable3DObject::render() (void) mnUniqueId; } -void Renderable3DObject::getRender() +OpenGL3DRenderer* Renderable3DObject::getRender() { if(mPrender==NULL) { @@ -33,6 +33,7 @@ void Renderable3DObject::getRender() mPrender->init(); mPrender->Set3DSenceInfo(); } + return mPrender; } @@ -73,6 +74,7 @@ Camera::Camera(): namespace temporary { TemporaryContext::TemporaryContext(): + Renderable3DObject(-1), miWidth(200), miHeight(200) { @@ -81,7 +83,9 @@ TemporaryContext::TemporaryContext(): void TemporaryContext::init() { maContext.init(); - maContext.setWinSize(Size(miWidth, miHeight)); + Size winSize(miWidth, miHeight); + maContext.setWinSize(winSize); + getRender()->SetSize(winSize); } void TemporaryContext::render() diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index 5b1ebe6..baa8cba 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -144,6 +144,12 @@ void OpenGL3DRenderer::init() m_IsOpenglInit = true; } +void OpenGL3DRenderer::SetSize(const Size& rSize) +{ + m_iWidth = rSize.Width(); + m_iHeight = rSize.Height(); +} + bool OpenGL3DRenderer::isOpenGLInitialized() { return m_IsOpenglInit; commit 4b6ba1eae6c2bae982190618ed46e9b66a3b2b2a Author: xukai <[email protected]> Date: Mon May 5 11:06:30 2014 +0800 Initialization of light Change-Id: I91220e8ebffa0090fa7e9146df853f16b6783491 diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index 049ea67..abf611e 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -160,7 +160,7 @@ public: void LoadShaders(); void init(); bool isOpenGLInitialized(); - void Set3DSenceInfo(const glm::vec3& cameraUp, sal_Int32 color, bool twoSidesLighting = false); + void Set3DSenceInfo(sal_Int32 color = 255, bool twoSidesLighting = true); void SetLightInfo(bool lightOn, sal_Int32 color, const glm::vec4& direction); void AddShapePolygon3DObject(sal_Int32 color, bool lineOnly, sal_Int32 lineColor, long fillStyle, sal_Int32 specular); diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index f3cb166..17d8111 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -31,6 +31,7 @@ void Renderable3DObject::getRender() { mPrender = new OpenGL3DRenderer(); mPrender->init(); + mPrender->Set3DSenceInfo(); } } diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index 5a6e17a..5b1ebe6 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -716,11 +716,8 @@ void OpenGL3DRenderer::RenderPolygon3DObject() return; } -void OpenGL3DRenderer::Set3DSenceInfo(const glm::vec3& cameraUp, sal_Int32 color, bool twoSidesLighting) +void OpenGL3DRenderer::Set3DSenceInfo(sal_Int32 color, bool twoSidesLighting) { - - m_CameraInfo.cameraUp = cameraUp; - m_Polygon3DInfo.material.twoSidesLighting = twoSidesLighting; m_LightsInfo.ambient = glm::vec4((float)(((color) & 0x00FF0000) >> 16) / 255.0f, @@ -729,10 +726,15 @@ void OpenGL3DRenderer::Set3DSenceInfo(const glm::vec3& cameraUp, sal_Int32 color 1.0); m_LightsInfo.lightNum = 0; + SetLightInfo(true, 255, glm::vec4(1.0, 1.0, 1.0, 0.0)); } void OpenGL3DRenderer::SetLightInfo(bool lightOn, sal_Int32 color, const glm::vec4& direction) { + if (m_LightsInfo.lightNum > MAX_LIGHT_NUM) + { + return; + } if (lightOn) { m_LightsInfo.light[m_LightsInfo.lightNum].lightColor = glm::vec4((float)(((color) & 0x00FF0000) >> 16) / 255.0f, commit d3832fc4e030c29eb9b7aef43931c46c66db3bc8 Author: xukai <[email protected]> Date: Mon May 5 10:42:20 2014 +0800 Introduce OpenGL3DRenderer object Change-Id: If0454ace5ef21b9d32299f3edea115a2726aac00 diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index 0483a74..c953eea 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -13,6 +13,9 @@ #include <vcl/bitmapex.hxx> #include <vcl/opengl/OpenGLContext.hxx> +#include "GL3DRenderer.hxx" + + namespace chart { @@ -27,8 +30,11 @@ public: virtual void render(); + void getRender(); + protected: sal_uInt32 mnUniqueId; + static OpenGL3DRenderer* mPrender; }; class Bar : public Renderable3DObject diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index 3600f0a..f3cb166 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -13,6 +13,8 @@ namespace chart { namespace opengl3D { +OpenGL3DRenderer* Renderable3DObject::mPrender = NULL; + Renderable3DObject::Renderable3DObject(sal_uInt32 nId): mnUniqueId(nId) { @@ -23,6 +25,16 @@ void Renderable3DObject::render() (void) mnUniqueId; } +void Renderable3DObject::getRender() +{ + if(mPrender==NULL) + { + mPrender = new OpenGL3DRenderer(); + mPrender->init(); + } +} + + Bar::Bar(const glm::mat4& rPosition, sal_uInt32 nId) : Renderable3DObject(nId) , mbRoundedCorners(false) commit bf293da67847f64fc0cf0acd54a9f4e4e76f9da5 Author: xukai <[email protected]> Date: Mon May 5 10:36:32 2014 +0800 To implement an abstract method:isOpenGLInitialized Change-Id: I651c0e5830008fd08ba886ccf1be99d40868bb72 diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index 26c9716..049ea67 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -159,7 +159,7 @@ public: void LoadShaders(); void init(); - + bool isOpenGLInitialized(); void Set3DSenceInfo(const glm::vec3& cameraUp, sal_Int32 color, bool twoSidesLighting = false); void SetLightInfo(bool lightOn, sal_Int32 color, const glm::vec4& direction); void AddShapePolygon3DObject(sal_Int32 color, bool lineOnly, sal_Int32 lineColor, @@ -227,7 +227,7 @@ private: glm::mat4 m_Model; // Our ModelViewProjection : multiplication of our 3 matrices glm::mat4 m_MVP; - + bool m_IsOpenglInit; #if 0 double m_dFreq; #endif diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index 762c873..5a6e17a 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -141,8 +141,15 @@ void OpenGL3DRenderer::init() m_3DProjection = glm::perspective(30.0f, (float)m_iWidth / (float)m_iHeight, 0.01f, 2000.0f); LoadShaders(); + m_IsOpenglInit = true; } +bool OpenGL3DRenderer::isOpenGLInitialized() +{ + return m_IsOpenglInit; +} + + void OpenGL3DRenderer::AddVertexData(GLuint vertexBuf) { glBindBuffer(GL_ARRAY_BUFFER, vertexBuf); commit 4493860167d998cf03274b6acc7c7959d5738c4b Author: xukai <[email protected]> Date: Mon May 5 10:28:38 2014 +0800 Update Function Set3DSenceInfo Change-Id: Ic117de10be2181a80e65ea48c888789456abfb0a diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index cc86bee..26c9716 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -160,8 +160,7 @@ public: void LoadShaders(); void init(); - void Set3DSenceInfo(const glm::vec3& cameraUp, const glm::mat4& D3DTrasform, - bool twoSidesLighting, sal_Int32 color); + void Set3DSenceInfo(const glm::vec3& cameraUp, sal_Int32 color, bool twoSidesLighting = false); void SetLightInfo(bool lightOn, sal_Int32 color, const glm::vec4& direction); void AddShapePolygon3DObject(sal_Int32 color, bool lineOnly, sal_Int32 lineColor, long fillStyle, sal_Int32 specular); diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index 0b210cb..762c873 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -577,7 +577,6 @@ void OpenGL3DRenderer::RenderLine3D(Polygon3DInfo &polygon) PosVecf3 scale = {1.0f, m_fHeightWeight, 1.0f}; MoveModelf(trans, angle, scale); - m_3DMVP = m_3DProjection * m_3DView * m_D3DTrasform; m_3DMVP = m_3DProjection * m_3DView * m_Model; //if line only, using the common shader to render @@ -710,13 +709,11 @@ void OpenGL3DRenderer::RenderPolygon3DObject() return; } -void OpenGL3DRenderer::Set3DSenceInfo(const glm::vec3& cameraUp, const glm::mat4& D3DTrasform, bool twoSidesLighting, sal_Int32 color) +void OpenGL3DRenderer::Set3DSenceInfo(const glm::vec3& cameraUp, sal_Int32 color, bool twoSidesLighting) { m_CameraInfo.cameraUp = cameraUp; - m_D3DTrasform = D3DTrasform; - m_Polygon3DInfo.material.twoSidesLighting = twoSidesLighting; m_LightsInfo.ambient = glm::vec4((float)(((color) & 0x00FF0000) >> 16) / 255.0f, commit eb0da9b80fa412202200cd5255e0e0eb6a9e38e9 Author: Markus Mohrhard <[email protected]> Date: Mon May 5 17:43:59 2014 +0200 fix whitespace issues Change-Id: I7a3680aa324c4242572b71c91ec5bc4f85eff9e9 diff --git a/chart2/opengl/shape3DFragmentShader.glsl b/chart2/opengl/shape3DFragmentShader.glsl index f527dd1..5cb521a 100644 --- a/chart2/opengl/shape3DFragmentShader.glsl +++ b/chart2/opengl/shape3DFragmentShader.glsl @@ -6,27 +6,27 @@ * 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 +#version 330 core #define MAX_LIGHT_NUM 8 in vec3 positionWorldspace; in vec3 normalCameraspace; uniform mat4 V; out vec4 actualColor; -struct MaterialParameters -{ - vec4 ambient; - vec4 diffuse; - vec4 specular; +struct MaterialParameters +{ + vec4 ambient; + vec4 diffuse; + vec4 specular; vec4 materialColor; - + int twoSidesLighting; float shininess; float pad; float pad1; }; -layout(std140) uniform GlobalMaterialParameters +layout(std140) uniform GlobalMaterialParameters { MaterialParameters matralParameter; }Material; @@ -51,23 +51,23 @@ layout(std140) uniform GlobalLights void main() { vec3 colorTotal = vec3(0.0f, 0.0f, 0.0f); - + vec3 vertexPositionCameraspace = (V * vec4(positionWorldspace,1)).xyz; - + vec3 MaterialDiffuseColor = Material.matralParameter.materialColor.rgb; - + vec3 normalDirectionCameraspace = normalCameraspace; - vec3 eyeDirectionCameraspace = normalize(vec3(0, 0, 0) - vertexPositionCameraspace); + 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 * + MaterialDiffuseColor * Material.matralParameter.ambient.rgb * 5.0; - + if ((Material.matralParameter.twoSidesLighting == 1) && (!gl_FrontFacing)) { normalDirectionCameraspace = -normalDirectionCameraspace; @@ -76,15 +76,15 @@ void main() { 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 * + vec3 lightDiffuse = LightPower * + attenuation * + Lights.light[i].lightColor.rgb * + MaterialDiffuseColor * + Material.matralParameter.diffuse.rgb * cosTheta; - + vec3 specularReflection; if (dot(normalDirectionCameraspace, lightDirectionCameraspace) < 0) { @@ -94,17 +94,18 @@ void main() { vec3 R = reflect(-lightDirectionCameraspace,normalDirectionCameraspace); float cosAlpha = clamp(dot(eyeDirectionCameraspace, R), 0,1); - specularReflection = attenuation * - LightPower * - Lights.light[i].lightColor.rgb * + 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: */ \ No newline at end of file + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/opengl/shape3DVertexShader.glsl b/chart2/opengl/shape3DVertexShader.glsl index 4587feb..d0bd693 100644 --- a/chart2/opengl/shape3DVertexShader.glsl +++ b/chart2/opengl/shape3DVertexShader.glsl @@ -21,9 +21,10 @@ uniform mat3 normalMatrix; void main() { gl_Position = P * V * M * vec4(vertexPositionModelspace,1); - + positionWorldspace = (M * vec4(vertexPositionModelspace,1)).xyz; normalCameraspace = normalize(mat3(V) * normalMatrix * vertexNormalModelspace); } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 8af5e1a9fbd48d173bd1cd98f153428234638707 Author: xukai <[email protected]> Date: Sun May 4 17:05:05 2014 +0800 add vertex shader and fragment shader for 3D rendering Change-Id: I7b1ca054006500d468da73d2d85eafaad85dda67 diff --git a/chart2/Package_opengl.mk b/chart2/Package_opengl.mk index ef33ebb..626a50f 100644 --- a/chart2/Package_opengl.mk +++ b/chart2/Package_opengl.mk @@ -20,6 +20,8 @@ $(eval $(call gb_Package_add_files,chart2_opengl_shader,$(LIBO_BIN_FOLDER)/openg symbolVertexShader.glsl \ textFragmentShader.glsl \ textVertexShader.glsl \ + shape3DFragmentShader.glsl \ + shape3DVertexShader.glsl \ )) # vim: set noet sw=4 ts=4: diff --git a/chart2/opengl/shape3DFragmentShader.glsl b/chart2/opengl/shape3DFragmentShader.glsl new file mode 100644 index 0000000..f527dd1 --- /dev/null +++ b/chart2/opengl/shape3DFragmentShader.glsl @@ -0,0 +1,110 @@ +/* -*- 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; +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 = Material.matralParameter.materialColor.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; + + if ((Material.matralParameter.twoSidesLighting == 1) && (!gl_FrontFacing)) + { + normalDirectionCameraspace = -normalDirectionCameraspace; + } + 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: */ \ No newline at end of file diff --git a/chart2/opengl/shape3DVertexShader.glsl b/chart2/opengl/shape3DVertexShader.glsl new file mode 100644 index 0000000..4587feb --- /dev/null +++ b/chart2/opengl/shape3DVertexShader.glsl @@ -0,0 +1,29 @@ +/* -*- 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; + +out vec3 positionWorldspace; +out vec3 normalCameraspace; + +uniform mat4 P; +uniform mat4 M; +uniform mat4 V; +uniform mat3 normalMatrix; + +void main() +{ + gl_Position = P * V * M * vec4(vertexPositionModelspace,1); + + positionWorldspace = (M * vec4(vertexPositionModelspace,1)).xyz; + + normalCameraspace = normalize(mat3(V) * normalMatrix * vertexNormalModelspace); +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index b977654..0b210cb 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -140,6 +140,7 @@ void OpenGL3DRenderer::init() m_3DProjection = glm::perspective(30.0f, (float)m_iWidth / (float)m_iHeight, 0.01f, 2000.0f); + LoadShaders(); } void OpenGL3DRenderer::AddVertexData(GLuint vertexBuf) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
