[Libreoffice-commits] core.git: Branch 'private/moggi/chart-opengl-window-version2' - 13 commits - chart2/source include/vcl sc/Library_sc.mk sc/source vcl/Library_vclopengl.mk vcl/source
Markus Mohrhard
markus.mohrhard at collabora.co.uk
Tue May 6 19:25:06 PDT 2014
chart2/source/model/main/ChartModel.cxx | 4
chart2/source/view/charttypes/GL3DBarChart.cxx | 12
chart2/source/view/inc/3DChartObjects.hxx | 7
chart2/source/view/inc/GL3DBarChart.hxx | 2
chart2/source/view/inc/GL3DRenderer.hxx | 40 +-
chart2/source/view/inc/StaticGeometry.h | 50 ++
chart2/source/view/main/3DChartObjects.cxx | 50 ++
chart2/source/view/main/GL3DRenderer.cxx | 477 ++++++++++++++++++-------
include/vcl/openglwin.hxx | 35 +
sc/Library_sc.mk | 1
sc/source/ui/drawfunc/fuins2.cxx | 4
vcl/Library_vclopengl.mk | 1
vcl/source/opengl/OpenGLContext.cxx | 2
vcl/source/window/openglwin.cxx | 47 ++
14 files changed, 588 insertions(+), 144 deletions(-)
New commits:
commit 6428038831145bfe9b9f12dae2cb066b0d74e729
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Wed May 7 04:20:02 2014 +0200
let us use the new OpenGLWindow
Change-Id: I5cbab0aa1707513b62f7a9958fac013b3beb2dcb
diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx
index a16f435..cf52cac 100644
--- a/chart2/source/model/main/ChartModel.cxx
+++ b/chart2/source/model/main/ChartModel.cxx
@@ -33,7 +33,7 @@
#include "UndoManager.hxx"
#include "ChartView.hxx"
-#include <vcl/window.hxx>
+#include <vcl/openglwin.hxx>
#include <com/sun/star/chart/ChartDataRowSource.hpp>
@@ -1413,7 +1413,7 @@ void ChartModel::setWindow( const sal_uInt64 nWindowPtr )
throw (uno::RuntimeException, std::exception)
{
void* pPtr = (void*)nWindowPtr;
- Window* pWindow = reinterpret_cast<Window*>(pPtr);
+ OpenGLWindow* pWindow = reinterpret_cast<OpenGLWindow*>(pPtr);
assert(pWindow);
}
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index eb4ace5..e8ab3b4 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -88,6 +88,7 @@ $(eval $(call gb_Library_use_libraries,sc,\
$(if $(filter TRUE,$(DISABLE_SCRIPTING)),, \
vbahelper) \
vcl \
+ vclopengl \
xo \
$(gb_UWINAPI) \
))
diff --git a/sc/source/ui/drawfunc/fuins2.cxx b/sc/source/ui/drawfunc/fuins2.cxx
index dde5089..873588d 100644
--- a/sc/source/ui/drawfunc/fuins2.cxx
+++ b/sc/source/ui/drawfunc/fuins2.cxx
@@ -32,7 +32,7 @@
#include <tools/urlobj.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/syschild.hxx>
-#include <vcl/sysdata.hxx>
+#include <vcl/openglwin.hxx>
#include <svl/urihelper.hxx>
#include <unotools/moduleoptions.hxx>
#include <svtools/insdlg.hxx>
@@ -544,7 +544,7 @@ FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, Window* pWin, ScDrawView*
ScDocument* pScDoc = pScDocSh->GetDocument();
bool bUndo (pScDoc->IsUndoEnabled());
- SystemChildWindow* pChildWindow = new SystemChildWindow(pData->GetActiveWin(), 0);
+ OpenGLWindow* pChildWindow = new OpenGLWindow(pData->GetActiveWin());
Size aWindowSize = pChildWindow->LogicToPixel( aSize, MapMode( MAP_100TH_MM ) );
pChildWindow->SetSizePixel(aWindowSize);
Wallpaper aBackground = pChildWindow->GetBackground();
commit da00bb1cb26e1bb9d4d7d70f56f8bbeaa8f43d21
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Wed May 7 04:16:54 2014 +0200
avoid linking against the OpenGL libs when only using the window
This lets us avoid to link libsclo against all the OpenGL libraries and
only link against libvcl_opengl. Only code actually using the context
will need to link against the OpenGL libs.
Change-Id: Ia47f4c651702a7fb8517073cda6fb113e7e26e50
diff --git a/include/vcl/openglwin.hxx b/include/vcl/openglwin.hxx
index 5c57d45..9c4e611 100644
--- a/include/vcl/openglwin.hxx
+++ b/include/vcl/openglwin.hxx
@@ -11,16 +11,23 @@
#define INCLUDED_VCL_OPENGLWIN_HXX
#include <vcl/syschild.hxx>
-#include <vcl/opengl/OpenGLContext.hxx>
+#include <vcl/vclopengl_dllapi.hxx>
-class OpenGLWindow : public SystemChildWindow
+#include <boost/scoped_ptr.hpp>
+
+class OpenGLContext;
+class OpenGLWindowImpl;
+
+// pImpl Pattern to avoid linking against OpenGL libs when using the class without the context
+class VCLOPENGL_DLLPUBLIC OpenGLWindow : public SystemChildWindow
{
public:
OpenGLWindow(Window* pParent);
- OpenGLContext& getContext();
+ ~OpenGLWindow();
+ OpenGLContext* getContext();
private:
- OpenGLContext maContext;
+ boost::scoped_ptr<OpenGLWindowImpl> mpImpl;
};
#endif
diff --git a/vcl/source/window/openglwin.cxx b/vcl/source/window/openglwin.cxx
index 29a21a2..3065718 100644
--- a/vcl/source/window/openglwin.cxx
+++ b/vcl/source/window/openglwin.cxx
@@ -8,15 +8,40 @@
*/
#include <vcl/openglwin.hxx>
+#include <vcl/opengl/OpenGLContext.hxx>
+
+class OpenGLWindowImpl
+{
+public:
+ OpenGLWindowImpl(SystemChildWindow* pWindow);
+ OpenGLContext* getContext();
+private:
+ OpenGLContext maContext;
+};
+
+OpenGLWindowImpl::OpenGLWindowImpl(SystemChildWindow* pWindow)
+{
+ maContext.init(pWindow);
+}
+
+OpenGLContext* OpenGLWindowImpl::getContext()
+{
+ return &maContext;
+}
OpenGLWindow::OpenGLWindow(Window* pParent):
- SystemChildWindow(pParent, 0)
+ SystemChildWindow(pParent, 0),
+ mpImpl(new OpenGLWindowImpl(this))
+{
+}
+
+OpenGLWindow::~OpenGLWindow()
{
}
-OpenGLContext& OpenGLWindow::getContext()
+OpenGLContext* OpenGLWindow::getContext()
{
- return maContext;
+ return mpImpl->getContext();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit d8ee1ac5c48417f8bd1b28c9f544d1de22744bde
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Wed May 7 03:45:41 2014 +0200
add new window that contains OpenGL context
Change-Id: I81ce3581942d03785809d728b6b54b570899bcdc
diff --git a/include/vcl/openglwin.hxx b/include/vcl/openglwin.hxx
new file mode 100644
index 0000000..5c57d45
--- /dev/null
+++ b/include/vcl/openglwin.hxx
@@ -0,0 +1,28 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_VCL_OPENGLWIN_HXX
+#define INCLUDED_VCL_OPENGLWIN_HXX
+
+#include <vcl/syschild.hxx>
+#include <vcl/opengl/OpenGLContext.hxx>
+
+class OpenGLWindow : public SystemChildWindow
+{
+public:
+ OpenGLWindow(Window* pParent);
+ OpenGLContext& getContext();
+
+private:
+ OpenGLContext maContext;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/Library_vclopengl.mk b/vcl/Library_vclopengl.mk
index 84310bb8..11b46e5 100644
--- a/vcl/Library_vclopengl.mk
+++ b/vcl/Library_vclopengl.mk
@@ -40,6 +40,7 @@ $(eval $(call gb_Library_use_libraries,vclopengl,\
$(eval $(call gb_Library_add_exception_objects,vclopengl,\
vcl/source/opengl/OpenGLContext \
vcl/source/opengl/OpenGLHelper \
+ vcl/source/window/openglwin \
))
ifeq ($(strip $(OS)),WNT)
diff --git a/vcl/source/window/openglwin.cxx b/vcl/source/window/openglwin.cxx
new file mode 100644
index 0000000..29a21a2
--- /dev/null
+++ b/vcl/source/window/openglwin.cxx
@@ -0,0 +1,22 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <vcl/openglwin.hxx>
+
+OpenGLWindow::OpenGLWindow(Window* pParent):
+ SystemChildWindow(pParent, 0)
+{
+}
+
+OpenGLContext& OpenGLWindow::getContext()
+{
+ return maContext;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 170976966397c48536f316dbfbe9a88d388e429a
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Tue May 6 13:09:30 2014 +0200
fix matrix generation
Change-Id: Id31caa16dfe0d0f23cf07589053233e9b311d02f
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index caf13a7..b29d193 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -53,8 +53,8 @@ void GL3DBarChart::create3DShapes()
float nYPos = nSeriesIndex * (nBarSizeY + nBarDistanceY);
glm::mat4 aBarPosition;
- glm::scale(aBarPosition, nBarSizeX, nBarSizeY, nVal);
- glm::translate(aBarPosition, nXPos, nYPos, nVal/2);
+ aBarPosition = glm::scale(aBarPosition, nBarSizeX, nBarSizeY, nVal);
+ aBarPosition = glm::translate(aBarPosition, nXPos, nYPos, nVal/2);
maShapes.push_back(new opengl3D::Bar(mpRenderer.get(), aBarPosition, nId++));
}
commit dfae78cf2e44aa5c879c534d62c27ab2f17cfc30
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Tue May 6 07:56:48 2014 +0200
add some missing pieces from the 2D renderer to the 3D one
Change-Id: I9933a429f42f8a350a88aa77514f934560ed58f3
diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx
index 9bbf284..02c008d 100644
--- a/chart2/source/view/inc/3DChartObjects.hxx
+++ b/chart2/source/view/inc/3DChartObjects.hxx
@@ -102,7 +102,7 @@ class TemporaryContext: public opengl3D::Renderable3DObject
public:
TemporaryContext(OpenGL3DRenderer* pRenderer);
- void render();
+ virtual void render();
void init();
private:
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index ac24762..0c5c078 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -169,6 +169,9 @@ class OpenGL3DRenderer : public IOpenGLInfoProvider
public:
OpenGL3DRenderer();
+ void CreateFrameBufferObj();
+ void CreateTextureObj(int,int);
+ void CreateRenderObj(int, int);
void LoadShaders();
void init();
bool isOpenGLInitialized();
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 3197c56..54f5e3d 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -119,6 +119,67 @@ void OpenGL3DRenderer::LoadShaders()
m_TextVertexID = glGetAttribLocation(m_TextProID, "vPosition");
m_TextTexCoordID = glGetAttribLocation(m_TextProID, "texCoord");
m_TextTexID = glGetUniformLocation(m_TextProID, "TextTex");
+
+ m_CommonProID = OpenGLHelper::LoadShaders("commonVertexShader", "commonFragmentShader");
+ m_MatrixID = glGetUniformLocation(m_CommonProID, "MVP");
+ m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition");
+ m_2DColorID = glGetUniformLocation(m_CommonProID, "vColor");
+ CHECK_GL_ERROR();
+}
+
+void OpenGL3DRenderer::CreateTextureObj(int width, int height)
+{
+ glGenTextures(2, m_TextureObj);
+ for (int i = 0; i < 2; i++)
+ {
+ glBindTexture(GL_TEXTURE_2D, m_TextureObj[i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ CHECK_GL_ERROR();
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+}
+
+void OpenGL3DRenderer::CreateRenderObj(int width, int height)
+{
+ glGenRenderbuffers(2, m_RboID);
+ for (int i = 0; i < 2; i++)
+ {
+ CHECK_GL_ERROR();
+ glBindRenderbuffer(GL_RENDERBUFFER, m_RboID[i]);
+ CHECK_GL_ERROR();
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
+ CHECK_GL_ERROR();
+ glBindRenderbuffer(GL_RENDERBUFFER, 0);
+ CHECK_GL_ERROR();
+ }
+}
+
+void OpenGL3DRenderer::CreateFrameBufferObj()
+{
+ CreateTextureObj(m_iWidth, m_iHeight);
+ CreateRenderObj(m_iWidth, m_iHeight);
+ // create a framebuffer object, you need to delete them when program exits.
+ glGenFramebuffers(2, m_FboID);
+ glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ for (int i = 0; i < 2; i++)
+ {
+ glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[i]);
+ glBindTexture(GL_TEXTURE_2D, m_TextureObj[i]);
+ // attach a texture to FBO color attachement point
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TextureObj[i], 0);
+ glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ // attach a renderbuffer to depth attachment point
+ glBindRenderbuffer(GL_RENDERBUFFER, m_RboID[i]);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RboID[i]);
+ glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ glBindRenderbuffer(GL_RENDERBUFFER, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[0]);
+ }
}
void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up, bool useDefalut)
@@ -163,6 +224,8 @@ void OpenGL3DRenderer::init()
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ CreateFrameBufferObj();
+
glGenBuffers(1, &m_CubeVertexBuf);
glGenBuffers(1, &m_CubeNormalBuf);
glGenBuffers(1, &m_CubeElementBuf);
@@ -1440,7 +1503,7 @@ sal_uInt32 OpenGL3DRenderer::GetIndexByColor(sal_uInt32 r, sal_uInt32 g, sal_uIn
void OpenGL3DRenderer::ProcessPickingBox()
{
glViewport(0, 0, m_iWidth, m_iHeight);
- glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[1]);
+ glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[0]);
glClearDepth(1.0f);
glClearColor(1.0, 1.0, 1.0, 1.0);
if(ProcessExtrude3DPickingBox() == 1)
@@ -1448,7 +1511,7 @@ void OpenGL3DRenderer::ProcessPickingBox()
//the picked object has been processed, return
return ;
}
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[0]);
}
int OpenGL3DRenderer::ProcessExtrude3DPickingBox()
@@ -1553,7 +1616,6 @@ int OpenGL3DRenderer::ProcessExtrude3DPickingBox()
m_coordinateAxisinfo.scale.y = 4 * extrude3DInfo.xScale;
m_coordinateAxisinfo.scale.z = 4 * extrude3DInfo.xScale;
m_coordinateAxisinfo.color = glm::vec4(0.5, 1.0, 0.8, 1.0);
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
return 1;
}
commit b77a9d9148bf67ed67e6b3f90fd9385cf4c802ee
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Tue May 6 07:21:43 2014 +0200
fix wrong shader names
Change-Id: Icd2d219446cdf78c4be97f96e38c9e4b174f9ddd
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 6617810..3197c56 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -106,7 +106,7 @@ GLfloat texCoords[] = {
void OpenGL3DRenderer::LoadShaders()
{
- m_3DProID = OpenGLHelper::LoadShaders("Shape3DVertexShader", "Shape3DFragmentShader");
+ m_3DProID = OpenGLHelper::LoadShaders("shape3DVertexShader", "shape3DFragmentShader");
m_3DProjectionID = glGetUniformLocation(m_3DProID, "P");
m_3DViewID = glGetUniformLocation(m_3DProID, "V");
m_3DModelID = glGetUniformLocation(m_3DProID, "M");
commit 811c6e67c0ebabbe2791403db3a9ffeea2b189be
Author: xukai <xukai at multicorewareinc.com>
Date: Tue May 6 10:45:10 2014 +0800
add code to call the bar api
Change-Id: Icee44999c175b5d964ebd51c56e9a1585506e036
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 5eab527..ac24762 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -97,12 +97,13 @@ typedef struct Extrude3DInfo
bool twoSidesLighting;
glm::vec4 extrudeColor;
long fillStyle;
- float xRange[2];
- float yRange[2];
- float zRange[2];
+ float xScale;
+ float yScale;
+ float zScale;
float xTransform;
float yTransform;
float zTransform;
+ glm::mat4 rotation;
Material material;
int startIndex[5];
int size[5];
@@ -180,11 +181,8 @@ public:
void EndAddPolygon3DObjectNormalPoint();
void AddPolygon3DObjectPoint(float x, float y, float z);
void EndAddPolygon3DObjectPoint();
- void AddShape3DExtrudeObject(sal_Int32 color, sal_Int32 specular, float xTransform,
- float yTransform, float zTransform);
+ void AddShape3DExtrudeObject(bool roundedCorner, sal_Int32 color, sal_Int32 specular, glm::mat4 modelMatrix);
void EndAddShape3DExtrudeObject();
- void AddExtrude3DObjectPoint(float x, float y, float z);
- void EndAddExtrude3DObjectPoint();
double GetTime();
void SetFPS(float fps);
void SetClickPos(Point aMPos);
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index ab1e12d..330747d 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -33,7 +33,8 @@ Bar::Bar(OpenGL3DRenderer* pRenderer, const glm::mat4& rPosition, sal_uInt32 nId
void Bar::render()
{
- (void) mbRoundedCorners;
+ mpRenderer->AddShape3DExtrudeObject(mbRoundedCorners, (sal_Int32)maColor.GetColor(), 0xFFFFFF, maPos);
+ mpRenderer->EndAddShape3DExtrudeObject();
}
Line::Line(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 9fdf6f4..6617810 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -119,13 +119,6 @@ void OpenGL3DRenderer::LoadShaders()
m_TextVertexID = glGetAttribLocation(m_TextProID, "vPosition");
m_TextTexCoordID = glGetAttribLocation(m_TextProID, "texCoord");
m_TextTexID = glGetUniformLocation(m_TextProID, "TextTex");
-
- glGenBuffers(1, &m_TextTexCoordBuf);
- glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBuf);
- glBufferData(GL_ARRAY_BUFFER, sizeof(texCoords), texCoords, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- CHECK_GL_ERROR();
- Init3DUniformBlock();
}
void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up, bool useDefalut)
@@ -191,6 +184,12 @@ void OpenGL3DRenderer::init()
m_3DProjection = glm::perspective(30.0f, (float)m_iWidth / (float)m_iHeight, 0.01f, 2000.0f);
LoadShaders();
+ glGenBuffers(1, &m_TextTexCoordBuf);
+ glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBuf);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(texCoords), texCoords, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ CHECK_GL_ERROR();
+ Init3DUniformBlock();
m_IsOpenglInit = true;
}
@@ -895,8 +894,18 @@ void OpenGL3DRenderer::EndAddPolygon3DObjectPoint()
m_Polygon3DInfo.vertices = NULL;
}
-void OpenGL3DRenderer::AddShape3DExtrudeObject(sal_Int32 color,sal_Int32 specular,float xTransform,float yTransform,float zTransform)
+void OpenGL3DRenderer::AddShape3DExtrudeObject(bool roundedCorner, sal_Int32 color,sal_Int32 specular, glm::mat4 modelMatrix)
{
+ glm::vec4 tranform = modelMatrix * glm::vec4(0.0, 0.0, 0.0, 1.0);
+ glm::vec4 DirX = modelMatrix * glm::vec4(1.0, 0.0, 0.0, 0.0);
+ glm::vec4 DirY = modelMatrix * glm::vec4(0.0, 1.0, 0.0, 0.0);
+ glm::vec4 DirZ = modelMatrix * glm::vec4(0.0, 0.0, 1.0, 0.0);
+ m_Extrude3DInfo.xScale = glm::length(DirX);
+ m_Extrude3DInfo.yScale = glm::length(DirY);
+ m_Extrude3DInfo.zScale = glm::length(DirZ);
+ glm::mat4 transformMatrixInverse = glm::inverse(glm::translate(glm::vec3(tranform)));
+ glm::mat4 scaleMatrixInverse = glm::inverse(glm::scale(m_Extrude3DInfo.xScale, m_Extrude3DInfo.yScale, m_Extrude3DInfo.zScale));
+ m_Extrude3DInfo.rotation = transformMatrixInverse * modelMatrix * scaleMatrixInverse;
//color
m_Extrude3DInfo.extrudeColor = glm::vec4((float)(((color) & 0x00FF0000) >> 16) / 255.0f,
(float)(((color) & 0x0000FF00) >> 8) / 255.0f,
@@ -915,10 +924,10 @@ void OpenGL3DRenderer::AddShape3DExtrudeObject(sal_Int32 color,sal_Int32 specula
m_Extrude3DInfo.material.ambient = glm::vec4(0.2, 0.2, 0.2, 1.0);
m_Extrude3DInfo.material.shininess = 1.0f;
-
- m_Extrude3DInfo.xTransform = xTransform - ((float)m_iWidth / 2);
- m_Extrude3DInfo.yTransform = yTransform - ((float)m_iHeight / 2);
- m_Extrude3DInfo.zTransform = zTransform;
+ m_Extrude3DInfo.xTransform = tranform.x - ((float)m_iWidth / 2);
+ m_Extrude3DInfo.yTransform = tranform.y - ((float)m_iHeight / 2);
+ m_Extrude3DInfo.zTransform = tranform.z;
+ m_Extrude3DInfo.rounded = roundedCorner;
}
void OpenGL3DRenderer::EndAddShape3DExtrudeObject()
@@ -927,33 +936,6 @@ void OpenGL3DRenderer::EndAddShape3DExtrudeObject()
m_Extrude3DList.push_back(m_Extrude3DInfo);
}
-void OpenGL3DRenderer::AddExtrude3DObjectPoint(float x, float y, float z)
-{
- float maxCoord = std::max(x, std::max(y, z));
- m_fZmax = std::max(maxCoord, m_fZmax);
- if (m_iPointNum == 0)
- {
- m_Extrude3DInfo.xRange[0] = x;
- m_Extrude3DInfo.xRange[1] = x;
- m_Extrude3DInfo.yRange[0] = y;
- m_Extrude3DInfo.yRange[1] = y;
- m_Extrude3DInfo.zRange[0] = z;
- m_Extrude3DInfo.zRange[1] = z;
- }
- m_Extrude3DInfo.xRange[0] = std::min(m_Extrude3DInfo.xRange[0], x);
- m_Extrude3DInfo.xRange[1] = std::max(m_Extrude3DInfo.xRange[1], x);
- m_Extrude3DInfo.yRange[0] = std::min(m_Extrude3DInfo.yRange[0], y);
- m_Extrude3DInfo.yRange[1] = std::max(m_Extrude3DInfo.yRange[1], y);
- m_Extrude3DInfo.zRange[0] = std::min(m_Extrude3DInfo.zRange[0], z);
- m_Extrude3DInfo.zRange[1] = std::max(m_Extrude3DInfo.zRange[1], z);
- m_iPointNum++;
-}
-
-void OpenGL3DRenderer::EndAddExtrude3DObjectPoint()
-{
- m_iPointNum = 0;
-}
-
void OpenGL3DRenderer::Init3DUniformBlock()
{
GLuint a3DLightBlockIndex = glGetUniformBlockIndex(m_3DProID, "GlobalLights");
@@ -1003,13 +985,13 @@ void OpenGL3DRenderer::Update3DUniformBlock()
void OpenGL3DRenderer::RenderExtrudeFlatSurface(const Extrude3DInfo& extrude3D, int surIndex)
{
- float xzScale = extrude3D.xRange[1] - extrude3D.xRange[0];
+ float xzScale = extrude3D.xScale;
PosVecf3 trans = {extrude3D.xTransform,//m_Extrude3DInfo.xTransform + 140,
-extrude3D.yTransform,
extrude3D.zTransform};
m_TranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
glm::mat4 flatScale = glm::scale(xzScale, xzScale, xzScale);
- m_Model = m_TranslationMatrix * flatScale;
+ m_Model = m_TranslationMatrix * extrude3D.rotation * flatScale;
glm::mat3 normalMatrix(m_Model);
glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix);
glUniformMatrix4fv(m_3DModelID, 1, GL_FALSE, &m_Model[0][0]);
@@ -1019,27 +1001,29 @@ void OpenGL3DRenderer::RenderExtrudeFlatSurface(const Extrude3DInfo& extrude3D,
void OpenGL3DRenderer::RenderExtrudeBottomSurface(const Extrude3DInfo& extrude3D)
{
- float xzScale = extrude3D.xRange[1] - extrude3D.xRange[0];
- float yScale = extrude3D.yRange[1] - extrude3D.yRange[0];
+ float xzScale = extrude3D.xScale;
+ float yScale = extrude3D.yScale;
float actualYTrans = yScale - m_RoundBarMesh.bottomThreshold * xzScale;
PosVecf3 trans = {extrude3D.xTransform,//m_Extrude3DInfo.xTransform + 140,
-extrude3D.yTransform,
extrude3D.zTransform};
- PosVecf3 angle = {0.0f, 0.0f, 0.0f};
+ //PosVecf3 angle = {0.0f, 0.0f, 0.0f};
if (actualYTrans < 0.0f)
{
// the height of rounded corner is higher than the cube than use the org scale matrix
// yScale /= (float)(1 + BOTTOM_THRESHOLD);
yScale /= (float)(m_RoundBarMesh.bottomThreshold);
PosVecf3 scale = {xzScale, yScale, xzScale};
- MoveModelf(trans, angle, scale);
+ glm::mat4 aTranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
+ glm::mat4 aScaleMatrix = glm::scale(glm::vec3(scale.x, scale.y, scale.z));
+ m_Model = aTranslationMatrix * extrude3D.rotation * aScaleMatrix;
}
else
{
glm::mat4 topTrans = glm::translate(glm::vec3(0.0, -actualYTrans, 0.0));
glm::mat4 topScale = glm::scale(xzScale, xzScale, xzScale);
m_TranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
- m_Model = m_TranslationMatrix * topTrans * topScale;
+ m_Model = m_TranslationMatrix * extrude3D.rotation * topTrans * topScale;
}
glm::mat3 normalMatrix(m_Model);
glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix);
@@ -1050,8 +1034,8 @@ void OpenGL3DRenderer::RenderExtrudeBottomSurface(const Extrude3DInfo& extrude3D
void OpenGL3DRenderer::RenderExtrudeMiddleSurface(const Extrude3DInfo& extrude3D)
{
- float xzScale = extrude3D.xRange[1] - extrude3D.xRange[0];
- float yScale = extrude3D.yRange[1] - extrude3D.yRange[0];
+ float xzScale = extrude3D.xScale;
+ float yScale = extrude3D.yScale;
float actualYScale = yScale - m_RoundBarMesh.bottomThreshold * xzScale;
PosVecf3 trans = {extrude3D.xTransform,//m_Extrude3DInfo.xTransform + 140,
-extrude3D.yTransform,
@@ -1068,7 +1052,7 @@ void OpenGL3DRenderer::RenderExtrudeMiddleSurface(const Extrude3DInfo& extrude3D
{
glm::mat4 scale = glm::scale(xzScale, actualYScale, xzScale);
m_TranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
- m_Model = m_TranslationMatrix * scale;
+ m_Model = m_TranslationMatrix * extrude3D.rotation * scale;
}
if (extrude3D.reverse)
@@ -1085,8 +1069,8 @@ void OpenGL3DRenderer::RenderExtrudeMiddleSurface(const Extrude3DInfo& extrude3D
void OpenGL3DRenderer::RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D)
{
- float xzScale = extrude3D.xRange[1] - extrude3D.xRange[0];
- float yScale = extrude3D.yRange[1] - extrude3D.yRange[0];
+ float xzScale = extrude3D.xScale;
+ float yScale = extrude3D.yScale;
float actualYTrans = yScale - m_RoundBarMesh.bottomThreshold * xzScale;
PosVecf3 trans = {extrude3D.xTransform,//m_Extrude3DInfo.xTransform + 140,
-extrude3D.yTransform,
@@ -1101,7 +1085,7 @@ void OpenGL3DRenderer::RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D)
glm::mat4 scale = glm::scale(xzScale, yScale, xzScale);
//MoveModelf(trans, angle, scale);
m_TranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
- m_Model = m_TranslationMatrix * scale * orgTrans;
+ m_Model = m_TranslationMatrix * extrude3D.rotation * scale * orgTrans;
}
else
{
@@ -1110,7 +1094,7 @@ void OpenGL3DRenderer::RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D)
glm::mat4 topTrans = glm::translate(glm::vec3(0.0, actualYTrans, 0.0));
glm::mat4 topScale = glm::scale(xzScale, xzScale, xzScale);
m_TranslationMatrix = glm::translate(glm::vec3(trans.x, trans.y, trans.z));
- m_Model = m_TranslationMatrix * topTrans * topScale * orgTrans;
+ m_Model = m_TranslationMatrix * extrude3D.rotation * topTrans * topScale * orgTrans;
}
glm::mat3 normalMatrix(m_Model);
glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix);
@@ -1122,14 +1106,14 @@ void OpenGL3DRenderer::RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D)
void OpenGL3DRenderer::RenderNonRoundedBar(const Extrude3DInfo& extrude3D)
{
- float xScale = extrude3D.xRange[1] - extrude3D.xRange[0];
- float yScale = extrude3D.yRange[1] - extrude3D.yRange[0];
- float zScale = extrude3D.zRange[1] - extrude3D.zRange[0];
+ float xScale = extrude3D.xScale;
+ float yScale = extrude3D.yScale;
+ float zScale = extrude3D.zScale;
glUniformMatrix4fv(m_3DViewID, 1, GL_FALSE, &m_3DView[0][0]);
glUniformMatrix4fv(m_3DProjectionID, 1, GL_FALSE, &m_3DProjection[0][0]);
glm::mat4 transformMatrix = glm::translate(glm::vec3(extrude3D.xTransform, -extrude3D.yTransform, extrude3D.zTransform));
glm::mat4 scaleMatrix = glm::scale(xScale, yScale, zScale);
- m_Model = transformMatrix * scaleMatrix;
+ m_Model = transformMatrix * extrude3D.rotation * scaleMatrix;
if (extrude3D.reverse)
{
glm::mat4 reverseMatrix = glm::translate(glm::vec3(0.0, -1.0, 0.0));
@@ -1174,16 +1158,14 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
Extrude3DInfo extrude3DInfo = m_Extrude3DList[i];
if (extrude3DInfo.rounded && (m_RoundBarMesh.iMeshSizes == 0))
{
- float xScale = extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0];
- float zScale = extrude3DInfo.zRange[1] - extrude3DInfo.zRange[0];
- CreateActualRoundedCube(0.1f, 30, 30, 1.0f, 1.2f, zScale / xScale);
+ CreateActualRoundedCube(0.1f, 30, 30, 1.0f, 1.2f, extrude3DInfo.zScale / extrude3DInfo.xScale);
AddVertexData(m_CubeVertexBuf);
AddNormalData(m_CubeNormalBuf);
AddIndexData(m_CubeElementBuf);
- for (int i = 0; i < 5; i++)
+ for (int j = 0; i < 5; i++)
{
- m_Extrude3DInfo.startIndex[i] = m_RoundBarMesh.iElementStartIndices[i];
- m_Extrude3DInfo.size[i] = m_RoundBarMesh.iElementSizes[i];
+ m_Extrude3DInfo.startIndex[j] = m_RoundBarMesh.iElementStartIndices[i];
+ m_Extrude3DInfo.size[j] = m_RoundBarMesh.iElementSizes[i];
}
}
GLuint vertexBuf = extrude3DInfo.rounded ? m_CubeVertexBuf : m_BoundBox;
@@ -1209,13 +1191,12 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
(void*)0 // array buffer offset
);
extrude3DInfo.yTransform *= m_fHeightWeight;
- extrude3DInfo.yRange[0] *= m_fHeightWeight;
- extrude3DInfo.yRange[1] *= m_fHeightWeight;
+ extrude3DInfo.yScale *= m_fHeightWeight;
glBindBuffer(GL_UNIFORM_BUFFER, m_3DUBOBuffer);
glBufferSubData(GL_UNIFORM_BUFFER, m_3DActualSizeLight, sizeof(Material), &extrude3DInfo.material);
CHECK_GL_ERROR();
glBindBuffer(GL_UNIFORM_BUFFER, 0);
- extrude3DInfo.reverse = -extrude3DInfo.yRange[0] > extrude3DInfo.yRange[1] ? 0 : 1;
+ extrude3DInfo.reverse = 0;
if (extrude3DInfo.rounded)
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_CubeElementBuf);
@@ -1437,6 +1418,8 @@ void OpenGL3DRenderer::ProcessUnrenderedShape()
RenderPolygon3DObject();
//Shape3DExtrudeObject
RenderExtrude3DObject();
+ //render text
+ RenderTextShape();
//render the axis
RenderCoordinateAxis();
}
@@ -1489,19 +1472,18 @@ int OpenGL3DRenderer::ProcessExtrude3DPickingBox()
{
extrude3DInfo = m_Extrude3DList[i];
extrude3DInfo.yTransform *= m_fHeightWeight;
- extrude3DInfo.yRange[0] *= m_fHeightWeight;
- extrude3DInfo.yRange[1] *= m_fHeightWeight;
+ extrude3DInfo.yScale *= m_fHeightWeight;
PosVecf3 trans = {extrude3DInfo.xTransform,//m_Extrude3DInfo.xTransform + 140,
-extrude3DInfo.yTransform,
extrude3DInfo.zTransform};
PosVecf3 angle = {0.0f, 0.0f, 0.0f};
- PosVecf3 scale = {extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0],
- extrude3DInfo.yRange[1] - extrude3DInfo.yRange[0],
- extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0]};
+ PosVecf3 scale = {extrude3DInfo.xScale,
+ extrude3DInfo.yScale,
+ extrude3DInfo.xScale};
MoveModelf(trans, angle, scale);
glm::mat4 boundMVP = m_3DProjection * m_3DView * m_Model;
glm::vec4 boundColor = GetColorByIndex(i);
- int reverse = extrude3DInfo.yRange[0] > extrude3DInfo.yRange[1] ? 1 : -1;
+ int reverse = 1;
if (reverse < 0)
{
glm::mat4 reverseMatrix = glm::translate(glm::vec3(0.0, -1.0, 0.0));
@@ -1543,14 +1525,13 @@ int OpenGL3DRenderer::ProcessExtrude3DPickingBox()
float horizontalAngle = GL_PI / 6.0f;
extrude3DInfo = m_Extrude3DList[selectID];
extrude3DInfo.yTransform *= m_fHeightWeight;
- extrude3DInfo.yRange[0] *= m_fHeightWeight;
- extrude3DInfo.yRange[1] *= m_fHeightWeight;
- int reverse = extrude3DInfo.yRange[0] > extrude3DInfo.yRange[1] ? 1 : -1;
+ extrude3DInfo.yScale *= m_fHeightWeight;
+ int reverse = 1;
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.cameraOrg = glm::vec3(extrude3DInfo.xTransform + extrude3DInfo.xScale / 2,
+ -extrude3DInfo.yTransform + extrude3DInfo.yScale *reverse,
+ extrude3DInfo.zTransform + extrude3DInfo.xScale / 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);
@@ -1564,13 +1545,13 @@ int OpenGL3DRenderer::ProcessExtrude3DPickingBox()
m_coordinateAxisinfo.pickingFlg = 1;
m_coordinateAxisinfo.reverse = reverse;
- m_coordinateAxisinfo.trans.x = extrude3DInfo.xTransform + (extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0]) / 2;
- m_coordinateAxisinfo.trans.y = -extrude3DInfo.yTransform + (extrude3DInfo.yRange[1] - extrude3DInfo.yRange[0] + 1.5) * reverse;
- m_coordinateAxisinfo.trans.z = extrude3DInfo.zTransform + (extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0]) / 2;
+ m_coordinateAxisinfo.trans.x = extrude3DInfo.xTransform + extrude3DInfo.xScale / 2;
+ m_coordinateAxisinfo.trans.y = -extrude3DInfo.yTransform + (extrude3DInfo.yScale + 1.5) * reverse;
+ m_coordinateAxisinfo.trans.z = extrude3DInfo.zTransform + extrude3DInfo.xScale / 2;
- m_coordinateAxisinfo.scale.x = 4 * (extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0]);
- m_coordinateAxisinfo.scale.y = 4 * (extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0]);
- m_coordinateAxisinfo.scale.z = 4 * (extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0]);
+ m_coordinateAxisinfo.scale.x = 4 * extrude3DInfo.xScale;
+ m_coordinateAxisinfo.scale.y = 4 * extrude3DInfo.xScale;
+ m_coordinateAxisinfo.scale.z = 4 * extrude3DInfo.xScale;
m_coordinateAxisinfo.color = glm::vec4(0.5, 1.0, 0.8, 1.0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
return 1;
commit fb3b832496ae6aafe2d0a8ec183a50b71606c2a3
Author: xukai <xukai at multicorewareinc.com>
Date: Tue May 6 09:43:08 2014 +0800
add api for render non rouded bar
Change-Id: I16bb4ec77cccf0ff9e73f02e13288562004eb5bc
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 3ef78cc..5eab527 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -91,6 +91,7 @@ typedef struct Polygon3DInfo
typedef struct Extrude3DInfo
{
int pickingFlg;
+ bool rounded;
bool lineOnly;
float lineWidth;
bool twoSidesLighting;
@@ -98,6 +99,7 @@ typedef struct Extrude3DInfo
long fillStyle;
float xRange[2];
float yRange[2];
+ float zRange[2];
float xTransform;
float yTransform;
float zTransform;
@@ -218,6 +220,7 @@ private:
void AddVertexData(GLuint vertexBuf);
void AddNormalData(GLuint normalBuf);
void AddIndexData(GLuint indexBuf);
+ void RenderNonRoundedBar(const Extrude3DInfo& extrude3D);
bool GetSimilarVertexIndex(PackedVertex & packed,
std::map<PackedVertex,unsigned short> & VertexToOutIndex,
unsigned short & result
@@ -322,7 +325,7 @@ private:
Point m_aMPos;
GLuint m_BoundBox;
-
+ GLuint m_BoundBoxNormal;
// add for text
std::list <TextInfo> m_TextInfoList;
GLint m_TextProID;
diff --git a/chart2/source/view/inc/StaticGeometry.h b/chart2/source/view/inc/StaticGeometry.h
index 99a3f9d..2ee0446 100644
--- a/chart2/source/view/inc/StaticGeometry.h
+++ b/chart2/source/view/inc/StaticGeometry.h
@@ -54,6 +54,56 @@ static GLfloat boundBox[] = {
1.0f, 0.0f, 1.0f//12
};
+static const GLfloat boundBoxNormal[] = {
+ -1.0f, 0.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,//1
+
+ -1.0f, 0.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,//2
+
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 0.0f, -1.0f,//3
+
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 0.0f, -1.0f,//4
+
+ 0.0f, -1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+ 0.0f,- 1.0f, 0.0f,//5
+
+ 0.0f, -1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,//6
+
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,//7
+
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,//8
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f,//9
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f,//10
+
+ 1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f,//11
+
+ 1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f//12
+};
+
GLfloat coordinateAxis[] = {
-1.0, 0.0, 0.0,
1.0, 0.0, 0.0,//x
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 682e897..9fdf6f4 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -79,12 +79,6 @@ OpenGL3DRenderer::OpenGL3DRenderer():
m_bCameraUpdated = false;
GetFreq();
-
- for (int i = 0; i < 5; i++)
- {
- m_Extrude3DInfo.startIndex[i] = m_RoundBarMesh.iElementStartIndices[i];
- m_Extrude3DInfo.size[i] = m_RoundBarMesh.iElementSizes[i];
- }
m_fViewAngle = 30.0f;
m_SenceBox.maxXCoord = -1.0 * FLT_MAX;
m_SenceBox.minXCoord = FLT_MAX;
@@ -96,6 +90,7 @@ OpenGL3DRenderer::OpenGL3DRenderer():
m_fHeightWeight = 1.0f;
m_CameraInfo.useDefault = true;
m_CameraInfo.cameraUp = glm::vec3(0, 1, 0);
+ m_RoundBarMesh.iMeshSizes = 0;
}
namespace {
@@ -176,25 +171,18 @@ void OpenGL3DRenderer::init()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glGenBuffers(1, &m_CubeVertexBuf);
- AddVertexData(m_CubeVertexBuf);
-
glGenBuffers(1, &m_CubeNormalBuf);
- AddNormalData(m_CubeNormalBuf);
-
glGenBuffers(1, &m_CubeElementBuf);
- AddIndexData(m_CubeElementBuf);
-
- for (int i = 0; i < 5; i++)
- {
- m_Extrude3DInfo.startIndex[i] = m_RoundBarMesh.iElementStartIndices[i];
- m_Extrude3DInfo.size[i] = m_RoundBarMesh.iElementSizes[i];
- }
-
glGenBuffers(1, &m_BoundBox);
glBindBuffer(GL_ARRAY_BUFFER, m_BoundBox);
glBufferData(GL_ARRAY_BUFFER, sizeof(boundBox), boundBox, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glGenBuffers(1, &m_BoundBoxNormal);
+ glBindBuffer(GL_ARRAY_BUFFER, m_BoundBoxNormal);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(boundBoxNormal), boundBoxNormal, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+
glGenBuffers(1, &m_CoordinateBuf);
glBindBuffer(GL_ARRAY_BUFFER, m_CoordinateBuf);
glBufferData(GL_ARRAY_BUFFER, sizeof(coordinateAxis), coordinateAxis, GL_STATIC_DRAW);
@@ -949,11 +937,15 @@ void OpenGL3DRenderer::AddExtrude3DObjectPoint(float x, float y, float z)
m_Extrude3DInfo.xRange[1] = x;
m_Extrude3DInfo.yRange[0] = y;
m_Extrude3DInfo.yRange[1] = y;
+ m_Extrude3DInfo.zRange[0] = z;
+ m_Extrude3DInfo.zRange[1] = z;
}
m_Extrude3DInfo.xRange[0] = std::min(m_Extrude3DInfo.xRange[0], x);
m_Extrude3DInfo.xRange[1] = std::max(m_Extrude3DInfo.xRange[1], x);
m_Extrude3DInfo.yRange[0] = std::min(m_Extrude3DInfo.yRange[0], y);
m_Extrude3DInfo.yRange[1] = std::max(m_Extrude3DInfo.yRange[1], y);
+ m_Extrude3DInfo.zRange[0] = std::min(m_Extrude3DInfo.zRange[0], z);
+ m_Extrude3DInfo.zRange[1] = std::max(m_Extrude3DInfo.zRange[1], z);
m_iPointNum++;
}
@@ -1128,6 +1120,28 @@ void OpenGL3DRenderer::RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D)
RenderExtrudeFlatSurface(extrude3D, FLAT_BOTTOM_SURFACE);
}
+void OpenGL3DRenderer::RenderNonRoundedBar(const Extrude3DInfo& extrude3D)
+{
+ float xScale = extrude3D.xRange[1] - extrude3D.xRange[0];
+ float yScale = extrude3D.yRange[1] - extrude3D.yRange[0];
+ float zScale = extrude3D.zRange[1] - extrude3D.zRange[0];
+ glUniformMatrix4fv(m_3DViewID, 1, GL_FALSE, &m_3DView[0][0]);
+ glUniformMatrix4fv(m_3DProjectionID, 1, GL_FALSE, &m_3DProjection[0][0]);
+ glm::mat4 transformMatrix = glm::translate(glm::vec3(extrude3D.xTransform, -extrude3D.yTransform, extrude3D.zTransform));
+ glm::mat4 scaleMatrix = glm::scale(xScale, yScale, zScale);
+ m_Model = transformMatrix * scaleMatrix;
+ if (extrude3D.reverse)
+ {
+ glm::mat4 reverseMatrix = glm::translate(glm::vec3(0.0, -1.0, 0.0));
+ m_Model = m_Model * reverseMatrix;
+ }
+ glm::mat3 normalMatrix(m_Model);
+ glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix);
+ glUniformMatrix4fv(m_3DModelID, 1, GL_FALSE, &m_Model[0][0]);
+ glUniformMatrix3fv(m_3DNormalMatrixID, 1, GL_FALSE, &normalInverseTranspos[0][0]);
+ glDrawArrays(GL_TRIANGLES, 0, 36);
+}
+
void OpenGL3DRenderer::RenderExtrudeSurface(const Extrude3DInfo& extrude3D)
{
glUniformMatrix4fv(m_3DViewID, 1, GL_FALSE, &m_3DView[0][0]);
@@ -1154,32 +1168,46 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
Update3DUniformBlock();
//render to fbo
glUseProgram(m_3DProID);
-
- // 1rst attribute buffer : vertices
- glEnableVertexAttribArray(m_3DVertexID);
- glBindBuffer(GL_ARRAY_BUFFER, m_CubeVertexBuf);
- glVertexAttribPointer(m_3DVertexID, // attribute. No particular reason for 0, but must match the layout in the shader.
- 3, // size
- GL_FLOAT, // type
- GL_FALSE, // normalized?
- 0, // stride
- (void*)0 // array buffer offset
- );
- // 2nd attribute buffer : normals
- glEnableVertexAttribArray(m_3DNormalID);
- glBindBuffer(GL_ARRAY_BUFFER, m_CubeNormalBuf);
- glVertexAttribPointer(m_3DNormalID, // attribute. No particular reason for 0, but must match the layout in the shader.
- 3, // size
- GL_FLOAT, // type
- GL_FALSE, // normalized?
- 0, // stride
- (void*)0 // array buffer offset
- );
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_CubeElementBuf);
size_t extrude3DNum = m_Extrude3DList.size();
for (size_t i = 0; i < extrude3DNum; i++)
{
Extrude3DInfo extrude3DInfo = m_Extrude3DList[i];
+ if (extrude3DInfo.rounded && (m_RoundBarMesh.iMeshSizes == 0))
+ {
+ float xScale = extrude3DInfo.xRange[1] - extrude3DInfo.xRange[0];
+ float zScale = extrude3DInfo.zRange[1] - extrude3DInfo.zRange[0];
+ CreateActualRoundedCube(0.1f, 30, 30, 1.0f, 1.2f, zScale / xScale);
+ AddVertexData(m_CubeVertexBuf);
+ AddNormalData(m_CubeNormalBuf);
+ AddIndexData(m_CubeElementBuf);
+ for (int i = 0; i < 5; i++)
+ {
+ m_Extrude3DInfo.startIndex[i] = m_RoundBarMesh.iElementStartIndices[i];
+ m_Extrude3DInfo.size[i] = m_RoundBarMesh.iElementSizes[i];
+ }
+ }
+ GLuint vertexBuf = extrude3DInfo.rounded ? m_CubeVertexBuf : m_BoundBox;
+ GLuint normalBuf = extrude3DInfo.rounded ? m_CubeNormalBuf : m_BoundBoxNormal;
+ // 1st attribute buffer : vertices
+ glEnableVertexAttribArray(m_3DVertexID);
+ glBindBuffer(GL_ARRAY_BUFFER, vertexBuf);
+ glVertexAttribPointer(m_3DVertexID, // attribute. No particular reason for 0, but must match the layout in the shader.
+ 3, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized?
+ 0, // stride
+ (void*)0 // array buffer offset
+ );
+ // 2nd attribute buffer : normals
+ glEnableVertexAttribArray(m_3DNormalID);
+ glBindBuffer(GL_ARRAY_BUFFER, normalBuf);
+ glVertexAttribPointer(m_3DNormalID, // attribute. No particular reason for 0, but must match the layout in the shader.
+ 3, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized?
+ 0, // stride
+ (void*)0 // array buffer offset
+ );
extrude3DInfo.yTransform *= m_fHeightWeight;
extrude3DInfo.yRange[0] *= m_fHeightWeight;
extrude3DInfo.yRange[1] *= m_fHeightWeight;
@@ -1188,11 +1216,19 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
CHECK_GL_ERROR();
glBindBuffer(GL_UNIFORM_BUFFER, 0);
extrude3DInfo.reverse = -extrude3DInfo.yRange[0] > extrude3DInfo.yRange[1] ? 0 : 1;
- RenderExtrudeSurface(extrude3DInfo);
+ if (extrude3DInfo.rounded)
+ {
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_CubeElementBuf);
+ RenderExtrudeSurface(extrude3DInfo);
+ }
+ else
+ {
+ RenderNonRoundedBar(extrude3DInfo);
+ }
+ glDisableVertexAttribArray(m_3DVertexID);
+ glDisableVertexAttribArray(m_3DNormalID);
}
m_Extrude3DList.clear();
- glDisableVertexAttribArray(m_3DVertexID);
- glDisableVertexAttribArray(m_3DNormalID);
glUseProgram(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisable(GL_CULL_FACE);
commit cf61acf3bb99a8d5d09994a6fd72318718321012
Author: xukai <xukai at multicorewareinc.com>
Date: Tue May 6 09:24:04 2014 +0800
add codes to Text::render()
Change-Id: I894cbb42b795f1adee41694011fa2477f87850f0
diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx
index 0ada599..9bbf284 100644
--- a/chart2/source/view/inc/3DChartObjects.hxx
+++ b/chart2/source/view/inc/3DChartObjects.hxx
@@ -63,6 +63,7 @@ class Text : public Renderable3DObject
{
public:
Text(OpenGL3DRenderer* pRenderer, sal_uInt32 nId);
+ virtual void render() SAL_OVERRIDE;
private:
BitmapEx maText;
glm::vec3 maTopLeft;
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 57adbef..3ef78cc 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -189,6 +189,7 @@ public:
void RenderClickPos(Point aMPos);
void SetSize(const Size& rSize);
void SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up, bool useDefalut);
+ void CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft);
private:
void MoveModelf(PosVecf3& trans,PosVecf3& angle,PosVecf3& scale);
@@ -201,7 +202,6 @@ private:
void RenderExtrude3DObject();
void RenderFPS(float fps);
//add for text
- void CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft);
void RenderTextShape();
void RenderText(const ::rtl::OUString& string, com::sun::star::awt::Point aPos);
void RenderExtrudeSurface(const Extrude3DInfo& extrude3D);
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index 2d69c4f..ab1e12d 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -54,6 +54,13 @@ Text::Text(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
{
}
+void Text::render()
+{
+ glm::vec3 dir2 = maTopRight - maTopLeft;
+ glm::vec3 bottomLeft = maBottomRight - dir2;
+ mpRenderer->CreateTextTexture(maText, maTopLeft, maTopRight, maBottomRight, bottomLeft);
+}
+
Rectangle::Rectangle(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
Renderable3DObject(pRenderer, nId)
{
commit 7cc83a6603dc75b503d890f4c4a15178ed254e40
Author: xukai <xukai at multicorewareinc.com>
Date: Mon May 5 18:12:03 2014 +0800
add the codes for rendering text in class:GL3dRenderer
Change-Id: Ia36e042d30afcc13be5fa3452123ae0778217877
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index bbef71f..57adbef 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -18,6 +18,7 @@
#include <com/sun/star/awt/Point.hpp>
#include <tools/gen.hxx>
+#include <vcl/bitmapex.hxx>
#include <vcl/opengl/IOpenGLRenderer.hxx>
#include <vector>
@@ -142,6 +143,13 @@ struct PackedVertex{
};
};
+typedef struct TextInfo
+{
+ GLuint texture;
+ float vertex[12];
+}TextInfo;
+
+
typedef struct SceneBox
{
float maxXCoord;
@@ -158,7 +166,6 @@ class OpenGL3DRenderer : public IOpenGLInfoProvider
public:
OpenGL3DRenderer();
- void CreateFrameBufferObj();
void LoadShaders();
void init();
bool isOpenGLInitialized();
@@ -193,6 +200,9 @@ private:
void Update3DUniformBlock();
void RenderExtrude3DObject();
void RenderFPS(float fps);
+ //add for text
+ void CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft);
+ void RenderTextShape();
void RenderText(const ::rtl::OUString& string, com::sun::star::awt::Point aPos);
void RenderExtrudeSurface(const Extrude3DInfo& extrude3D);
void RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D);
@@ -313,6 +323,15 @@ private:
GLuint m_BoundBox;
+ // add for text
+ std::list <TextInfo> m_TextInfoList;
+ GLint m_TextProID;
+ GLint m_TextMatrixID;
+ GLint m_TextVertexID;
+ GLint m_TextTexCoordID;
+ GLuint m_TextTexCoordBuf;
+ GLint m_TextTexID;
+
GLuint m_CoordinateBuf;
int m_uiSelectFrameCounter;
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index b28e42e..682e897 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -31,15 +31,6 @@ namespace opengl3D {
namespace {
-struct TextInfo
-{
- GLuint texture;
- double rotation;
- float vertex[12];
- float nDx;
- float nDy;
-};
-
int static checkGLError(const char *file, int line)
{
GLenum glErr;
@@ -65,7 +56,14 @@ int static checkGLError(const char *file, int line)
}
OpenGL3DRenderer::OpenGL3DRenderer():
- m_TranslationMatrix(glm::translate(m_Model, glm::vec3(0.0f, 0.0f, 0.0f)))
+ m_IsOpenglInit(false)
+ , m_TranslationMatrix(glm::translate(m_Model, glm::vec3(0.0f, 0.0f, 0.0f)))
+ , m_TextProID(0)
+ , m_TextMatrixID(0)
+ , m_TextVertexID(0)
+ , m_TextTexCoordID(0)
+ , m_TextTexCoordBuf(0)
+ , m_TextTexID(0)
{
m_Polygon3DInfo.lineOnly = false;
m_Polygon3DInfo.twoSidesLighting = false;
@@ -100,26 +98,15 @@ OpenGL3DRenderer::OpenGL3DRenderer():
m_CameraInfo.cameraUp = glm::vec3(0, 1, 0);
}
-void OpenGL3DRenderer::CreateFrameBufferObj()
-{
- // create a framebuffer object, you need to delete them when program exits.
- glGenFramebuffers(2, m_FboID);
- glCheckFramebufferStatus(GL_FRAMEBUFFER);
- for (int i = 0; i < 2; i++)
- {
- glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[i]);
- glBindTexture(GL_TEXTURE_2D, m_TextureObj[i]);
- // attach a texture to FBO color attachement point
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TextureObj[i], 0);
- glCheckFramebufferStatus(GL_FRAMEBUFFER);
- glBindTexture(GL_TEXTURE_2D, 0);
- // attach a renderbuffer to depth attachment point
- glBindRenderbuffer(GL_RENDERBUFFER, m_RboID[i]);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RboID[i]);
- glCheckFramebufferStatus(GL_FRAMEBUFFER);
- glBindRenderbuffer(GL_RENDERBUFFER, 0);
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- }
+namespace {
+
+GLfloat texCoords[] = {
+ 0.0f, 0.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+ 0.0f, 1.0f
+};
+
}
void OpenGL3DRenderer::LoadShaders()
@@ -132,12 +119,17 @@ void OpenGL3DRenderer::LoadShaders()
m_3DVertexID = glGetAttribLocation(m_3DProID, "vertexPositionModelspace");
m_3DNormalID = glGetAttribLocation(m_3DProID, "vertexNormalModelspace");
- m_CommonProID = OpenGLHelper::LoadShaders("commonVertexShader", "commonFragmentShader");
- m_MatrixID = glGetUniformLocation(m_CommonProID, "MVP");
- m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition");
- m_2DColorID = glGetUniformLocation(m_CommonProID, "vColor");
- CHECK_GL_ERROR();
+ m_TextProID = OpenGLHelper::LoadShaders("textVertexShader", "textFragmentShader");
+ m_TextMatrixID = glGetUniformLocation(m_TextProID, "MVP");
+ m_TextVertexID = glGetAttribLocation(m_TextProID, "vPosition");
+ m_TextTexCoordID = glGetAttribLocation(m_TextProID, "texCoord");
+ m_TextTexID = glGetUniformLocation(m_TextProID, "TextTex");
+ glGenBuffers(1, &m_TextTexCoordBuf);
+ glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBuf);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(texCoords), texCoords, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ CHECK_GL_ERROR();
Init3DUniformBlock();
}
@@ -153,6 +145,8 @@ void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::ve
m_CameraInfo.cameraUp = up;
}
+
+
void OpenGL3DRenderer::init()
{
if (glewIsSupported("framebuffer_object") != GLEW_OK)
@@ -209,7 +203,6 @@ void OpenGL3DRenderer::init()
m_3DProjection = glm::perspective(30.0f, (float)m_iWidth / (float)m_iHeight, 0.01f, 2000.0f);
LoadShaders();
- CreateFrameBufferObj();
m_IsOpenglInit = true;
}
@@ -1215,6 +1208,114 @@ void OpenGL3DRenderer::SetClickPos(Point aMPos)
m_aMPos = aMPos;
}
+void OpenGL3DRenderer::CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft)
+{
+ long bmpWidth = rBitmapEx.GetSizePixel().Width();
+ long bmpHeight = rBitmapEx.GetSizePixel().Height();
+ boost::scoped_array<sal_uInt8> bitmapBuf(OpenGLHelper::ConvertBitmapExToRGBABuffer(rBitmapEx));
+
+ TextInfo aTextInfo;
+ aTextInfo.vertex[0] = vBottomRight.x;
+ aTextInfo.vertex[1] = vBottomRight.y;
+ aTextInfo.vertex[2] = vBottomRight.z;
+
+ aTextInfo.vertex[3] = vTopRight.x;
+ aTextInfo.vertex[4] = vTopRight.y;
+ aTextInfo.vertex[5] = vTopRight.z;
+
+ aTextInfo.vertex[6] = vTopLeft.x;
+ aTextInfo.vertex[7] = vTopLeft.y;
+ aTextInfo.vertex[8] = vTopLeft.z;
+
+ aTextInfo.vertex[9] = vBottomLeft.x;
+ aTextInfo.vertex[10] = vBottomLeft.y;
+ aTextInfo.vertex[11] = vBottomLeft.z;
+
+ CHECK_GL_ERROR();
+ glGenTextures(1, &aTextInfo.texture);
+ CHECK_GL_ERROR();
+ glBindTexture(GL_TEXTURE_2D, aTextInfo.texture);
+ CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ CHECK_GL_ERROR();
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmpWidth, bmpHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmapBuf.get());
+ CHECK_GL_ERROR();
+ glBindTexture(GL_TEXTURE_2D, 0);
+ CHECK_GL_ERROR();
+ m_TextInfoList.push_back(aTextInfo);
+}
+
+void OpenGL3DRenderer::RenderTextShape()
+{
+ CHECK_GL_ERROR();
+ size_t listNum = m_TextInfoList.size();
+ for (size_t i = 0; i < listNum; i++)
+ {
+ TextInfo &textInfo = m_TextInfoList.front();
+ PosVecf3 trans = {0, 0, 0};
+ PosVecf3 angle = {0.0f, 0.0f, 0.0f};
+ PosVecf3 scale = {1.0, 1.0, 1.0f};
+ MoveModelf(trans, angle, scale);
+ m_MVP = m_Projection * m_View * m_Model;
+ glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
+ CHECK_GL_ERROR();
+ glBufferData(GL_ARRAY_BUFFER, sizeof(textInfo.vertex), textInfo.vertex, GL_STATIC_DRAW);
+ CHECK_GL_ERROR();
+ glUseProgram(m_TextProID);
+
+ CHECK_GL_ERROR();
+ glUniformMatrix4fv(m_TextMatrixID, 1, GL_FALSE, &m_MVP[0][0]);
+ // 1rst attribute buffer : vertices
+ glEnableVertexAttribArray(m_TextVertexID);
+ glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
+ glVertexAttribPointer(
+ m_TextVertexID,
+ 3, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized?
+ 0, // stride
+ (void*)0 // array buffer offset
+ );
+ //tex coord
+ CHECK_GL_ERROR();
+ glEnableVertexAttribArray(m_TextTexCoordID);
+ glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBuf);
+ glVertexAttribPointer(
+ m_TextTexCoordID,
+ 2, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized?
+ 0, // stride
+ (void*)0 // array buffer offset
+ );
+ //texture
+ CHECK_GL_ERROR();
+ glBindTexture(GL_TEXTURE_2D, textInfo.texture);
+ CHECK_GL_ERROR();
+ glUniform1i(m_TextTexID, 0);
+ CHECK_GL_ERROR();
+ //TODO: moggi: get rid fo GL_QUADS
+ glDrawArrays(GL_QUADS, 0, 4);
+ CHECK_GL_ERROR();
+ glDisableVertexAttribArray(m_TextTexCoordID);
+ CHECK_GL_ERROR();
+ glDisableVertexAttribArray(m_TextVertexID);
+ CHECK_GL_ERROR();
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glUseProgram(0);
+ glDeleteTextures(1, &textInfo.texture);
+ CHECK_GL_ERROR();
+ m_TextInfoList.pop_front();
+ }
+ CHECK_GL_ERROR();
+}
+
void OpenGL3DRenderer::RenderText(const ::rtl::OUString& , awt::Point )
{
//TODO: moggi: disabled for now
commit fdeb737ad9f4e5f0c64f8032c1b3bca9ec51de2b
Author: xukai <xukai at multicorewareinc.com>
Date: Mon May 5 16:24:44 2014 +0800
add codes to Rectangle::render()
Change-Id: I4a86de032970bfd9cba6270e8e6c6a00e550d74e
diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx
index 4694ae3..0ada599 100644
--- a/chart2/source/view/inc/3DChartObjects.hxx
+++ b/chart2/source/view/inc/3DChartObjects.hxx
@@ -8,7 +8,6 @@
*/
#include <glm/glm.hpp>
-
#include <tools/color.hxx>
#include <vcl/bitmapex.hxx>
@@ -75,6 +74,7 @@ class Rectangle : public Renderable3DObject
{
public:
Rectangle(OpenGL3DRenderer* pRenderer, sal_uInt32 nId);
+ virtual void render() SAL_OVERRIDE;
private:
glm::vec3 maTopLeft;
glm::vec3 maTopRight;
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index d45dc9f..2d69c4f 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -59,6 +59,37 @@ Rectangle::Rectangle(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
{
}
+void Rectangle::render()
+{
+ glm::vec3 dir1 = maBottomRight - maTopLeft;
+ glm::vec3 dir2 = maTopRight - maTopLeft;
+ glm::vec3 normal = glm::normalize(glm::cross(dir1, dir2));
+ mpRenderer->AddShapePolygon3DObject((sal_Int32)maColor.GetColor(), false, 0, 1, 0xFFFFFF);
+ glm::vec3 bottomLeft = maBottomRight - dir2;
+ //set polygon points and normals
+ mpRenderer->AddPolygon3DObjectPoint(maBottomRight.x, maBottomRight.y, maBottomRight.z);
+ mpRenderer->AddPolygon3DObjectNormalPoint(normal.x, normal.y, normal.z);
+ mpRenderer->AddPolygon3DObjectPoint(maTopRight.x, maTopRight.y, maTopRight.z);
+ mpRenderer->AddPolygon3DObjectNormalPoint(normal.x, normal.y, normal.z);
+ mpRenderer->AddPolygon3DObjectPoint(maTopLeft.x, maTopLeft.y, maTopLeft.z);
+ mpRenderer->AddPolygon3DObjectNormalPoint(normal.x, normal.y, normal.z);
+ mpRenderer->AddPolygon3DObjectPoint(bottomLeft.x, bottomLeft.y, bottomLeft.z);
+ mpRenderer->AddPolygon3DObjectNormalPoint(normal.x, normal.y, normal.z);
+ mpRenderer->EndAddPolygon3DObjectPoint();
+ mpRenderer->EndAddPolygon3DObjectNormalPoint();
+ //we should render the edge if the edge color is different from the fill color
+ if ((sal_Int32)maColor.GetColor() != (sal_Int32)maLineColor.GetColor())
+ {
+ mpRenderer->AddShapePolygon3DObject(0, true, (sal_Int32)maLineColor.GetColor(), 0, 0xFFFFFF);
+ mpRenderer->AddPolygon3DObjectPoint(maBottomRight.x, maBottomRight.y, maBottomRight.z);
+ mpRenderer->AddPolygon3DObjectPoint(maTopRight.x, maTopRight.y, maTopRight.z);
+ mpRenderer->AddPolygon3DObjectPoint(maTopLeft.x, maTopLeft.y, maTopLeft.z);
+ mpRenderer->AddPolygon3DObjectPoint(bottomLeft.x, bottomLeft.y, bottomLeft.z);
+ mpRenderer->EndAddPolygon3DObjectPoint();
+ }
+ mpRenderer->EndAddShapePolygon3DObject();
+}
+
Camera::Camera(OpenGL3DRenderer* pRenderer):
Renderable3DObject(pRenderer, 0),
maPos(10,10,-10),
commit e448671b155e473c970bc447f2efc1494bfe5078
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Tue May 6 07:00:28 2014 +0200
more 3D rendering fixes
Change-Id: I8943355de1b9440104e0281131fb0df3fc599bb4
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 5f66203..bbef71f 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -158,6 +158,7 @@ class OpenGL3DRenderer : public IOpenGLInfoProvider
public:
OpenGL3DRenderer();
+ void CreateFrameBufferObj();
void LoadShaders();
void init();
bool isOpenGLInitialized();
@@ -288,8 +289,12 @@ private:
GLint m_MatrixID;
+ GLuint m_TextureObj[2];
+
GLuint m_FboID[2];
+ GLuint m_RboID[2];
+
Extrude3DInfo m_Extrude3DInfo;
std::vector <Extrude3DInfo> m_Extrude3DList;
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index 4f9da33..d45dc9f 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -91,6 +91,7 @@ void TemporaryContext::init()
Size winSize(800, 600);
maContext.setWinSize(winSize);
mpRenderer->SetSize(winSize);
+ mpRenderer->init();
}
}
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 651fca4..b28e42e 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -100,6 +100,28 @@ OpenGL3DRenderer::OpenGL3DRenderer():
m_CameraInfo.cameraUp = glm::vec3(0, 1, 0);
}
+void OpenGL3DRenderer::CreateFrameBufferObj()
+{
+ // create a framebuffer object, you need to delete them when program exits.
+ glGenFramebuffers(2, m_FboID);
+ glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ for (int i = 0; i < 2; i++)
+ {
+ glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[i]);
+ glBindTexture(GL_TEXTURE_2D, m_TextureObj[i]);
+ // attach a texture to FBO color attachement point
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TextureObj[i], 0);
+ glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ // attach a renderbuffer to depth attachment point
+ glBindRenderbuffer(GL_RENDERBUFFER, m_RboID[i]);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RboID[i]);
+ glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ glBindRenderbuffer(GL_RENDERBUFFER, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ }
+}
+
void OpenGL3DRenderer::LoadShaders()
{
m_3DProID = OpenGLHelper::LoadShaders("Shape3DVertexShader", "Shape3DFragmentShader");
@@ -110,6 +132,12 @@ void OpenGL3DRenderer::LoadShaders()
m_3DVertexID = glGetAttribLocation(m_3DProID, "vertexPositionModelspace");
m_3DNormalID = glGetAttribLocation(m_3DProID, "vertexNormalModelspace");
+ m_CommonProID = OpenGLHelper::LoadShaders("commonVertexShader", "commonFragmentShader");
+ m_MatrixID = glGetUniformLocation(m_CommonProID, "MVP");
+ m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition");
+ m_2DColorID = glGetUniformLocation(m_CommonProID, "vColor");
+ CHECK_GL_ERROR();
+
Init3DUniformBlock();
}
@@ -127,6 +155,32 @@ void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::ve
void OpenGL3DRenderer::init()
{
+ if (glewIsSupported("framebuffer_object") != GLEW_OK)
+ {
+ SAL_WARN("chart2.opengl", "GL stack has no framebuffer support");
+ return;
+ }
+
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ // Enable depth test
+ glEnable(GL_DEPTH_TEST);
+ // Accept fragment if it closer to the camera than the former one
+ glDepthFunc(GL_LESS);
+ glEnable(GL_POINT_SMOOTH);
+ glEnable(GL_LINE_SMOOTH);
+ glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
+ glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glClearColor (1.0, 1.0, 1.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glClearDepth(1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
glGenBuffers(1, &m_CubeVertexBuf);
AddVertexData(m_CubeVertexBuf);
@@ -155,6 +209,7 @@ void OpenGL3DRenderer::init()
m_3DProjection = glm::perspective(30.0f, (float)m_iWidth / (float)m_iHeight, 0.01f, 2000.0f);
LoadShaders();
+ CreateFrameBufferObj();
m_IsOpenglInit = true;
}
commit eeec67413bd0b90e0fc8c28303a58a040a2f7996
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Tue May 6 06:35:32 2014 +0200
fix the OpenGL offscreen rendering a bit
Change-Id: I1f11cdff0de48e3281a58aec9ea37a78c637195e
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 9bb94f5..caf13a7 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -21,7 +21,8 @@ namespace chart {
GL3DBarChart::GL3DBarChart(const std::vector<VDataSeries*>& rDataSeries):
maDataSeries(rDataSeries),
- mxContext(new opengl3D::temporary::TemporaryContext())
+ mpRenderer(new opengl3D::OpenGL3DRenderer()),
+ mxContext(new opengl3D::temporary::TemporaryContext(mpRenderer.get()))
{
}
@@ -35,10 +36,9 @@ void GL3DBarChart::create3DShapes()
const float nBarSizeY = 10;
const float nBarDistanceX = nBarSizeX / 2;
const float nBarDistanceY = nBarSizeY / 2;
- opengl3D::OpenGL3DRenderer* pRenderer = NULL;
maShapes.clear();
- maShapes.push_back(new opengl3D::Camera(pRenderer));
+ maShapes.push_back(new opengl3D::Camera(mpRenderer.get()));
sal_Int32 nSeriesIndex = 0;
sal_uInt32 nId = 1;
for(std::vector<VDataSeries*>::const_iterator itr = maDataSeries.begin(),
@@ -56,7 +56,7 @@ void GL3DBarChart::create3DShapes()
glm::scale(aBarPosition, nBarSizeX, nBarSizeY, nVal);
glm::translate(aBarPosition, nXPos, nYPos, nVal/2);
- maShapes.push_back(new opengl3D::Bar(pRenderer, aBarPosition, nId++));
+ maShapes.push_back(new opengl3D::Bar(mpRenderer.get(), aBarPosition, nId++));
}
++nSeriesIndex;
diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx
index ae15a29..4694ae3 100644
--- a/chart2/source/view/inc/3DChartObjects.hxx
+++ b/chart2/source/view/inc/3DChartObjects.hxx
@@ -99,7 +99,7 @@ namespace temporary {
class TemporaryContext: public opengl3D::Renderable3DObject
{
public:
- TemporaryContext();
+ TemporaryContext(OpenGL3DRenderer* pRenderer);
void render();
void init();
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index 4eefdaa..da3d1e1 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -21,6 +21,7 @@ namespace chart {
namespace opengl3D {
class Renderable3DObject;
+class OpenGL3DRenderer;
namespace temporary {
@@ -43,6 +44,7 @@ private:
std::vector<VDataSeries*> maDataSeries;
boost::ptr_vector<opengl3D::Renderable3DObject> maShapes;
+ boost::scoped_ptr<opengl3D::OpenGL3DRenderer> mpRenderer;
boost::scoped_ptr<opengl3D::temporary::TemporaryContext> mxContext;
};
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index 6e3df0c..4f9da33 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -75,8 +75,8 @@ void Camera::render()
namespace temporary {
-TemporaryContext::TemporaryContext():
- Renderable3DObject(NULL, -1)
+TemporaryContext::TemporaryContext(OpenGL3DRenderer* pRenderer):
+ Renderable3DObject(pRenderer, -1)
{
}
@@ -87,6 +87,10 @@ void TemporaryContext::render()
void TemporaryContext::init()
{
+ maContext.init();
+ Size winSize(800, 600);
+ maContext.setWinSize(winSize);
+ mpRenderer->SetSize(winSize);
}
}
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index 99aeb90..3cd525e 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -545,7 +545,7 @@ void OpenGLContext::renderToFile()
BitmapEx aBmp = OpenGLHelper::ConvertBGRABufferToBitmapEx(buf.get(), iWidth, iHeight);
static int nIdx = 0;
- OUString aName = OUString( "file:///home/moggi/Documents/work/text" ) + OUString::number( nIdx++ ) + ".png";
+ OUString aName = OUString( "file:///home/moggi/Documents/work/output" ) + OUString::number( nIdx++ ) + ".png";
try {
vcl::PNGWriter aWriter( aBmp );
SvFileStream sOutput( aName, STREAM_WRITE );
More information about the Libreoffice-commits
mailing list