summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-04-29 02:10:20 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-04-29 02:15:45 +0200
commitf6b2b84324944194250ea648d542d241b700dec3 (patch)
tree2a3da3d489e89d274fac2910e72074f74377f835 /chart2
parentea45852d7aa48bfa9b62a5d7eb8c29757b90164f (diff)
make the new 3D OpenGL chart renderer compile
still a lot of work needs to be done. Change-Id: I427d1a3ada15d2c9a480bb8e57940af6aef04f2f
Diffstat (limited to 'chart2')
-rw-r--r--chart2/Library_chartcore.mk7
-rw-r--r--chart2/source/view/inc/GL3DRenderer.hxx82
-rw-r--r--chart2/source/view/main/GL3DRenderer.cxx82
-rw-r--r--chart2/source/view/main/OpenGLRender.cxx4
-rw-r--r--chart2/source/view/main/OpenGLRender.hxx3
5 files changed, 146 insertions, 32 deletions
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk
index f62435c8f268..63f2ec1c77dc 100644
--- a/chart2/Library_chartcore.mk
+++ b/chart2/Library_chartcore.mk
@@ -103,6 +103,7 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\
chart2/source/view/main/Clipping \
chart2/source/view/main/DataPointSymbolSupplier \
chart2/source/view/main/DrawModelWrapper \
+ chart2/source/view/main/GL3DRenderer \
chart2/source/view/main/LabelPositionHelper \
chart2/source/view/main/Linear3DTransformation \
chart2/source/view/main/PlotterBase \
@@ -251,17 +252,17 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\
))
ifeq ($(strip $(OS)),WNT)
-$(eval $(call gb_Library_use_system_win32_libs,chartopengl,\
+$(eval $(call gb_Library_use_system_win32_libs,chartcore,\
opengl32 \
gdi32 \
glu32 \
))
else ifeq ($(OS),MACOSX)
-$(eval $(call gb_Library_use_system_darwin_frameworks,chartopengl,\
+$(eval $(call gb_Library_use_system_darwin_frameworks,chartcore,\
OpenGL \
))
else ifeq ($(OS),LINUX)
-$(eval $(call gb_Library_add_libs,chartopengl,\
+$(eval $(call gb_Library_add_libs,chartcore,\
-ldl \
-lGL \
-lGLU \
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 4285204b6a78..af14537b4caf 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -10,12 +10,33 @@
#ifndef CHART2_GL3DRENDERER_HXX
#define CHART2_GL3DRENDERER_HXX
+#include "glm/glm.hpp"
+#include "glm/gtx/transform.hpp"
+#include "glm/gtx/euler_angles.hpp"
+#include "glm/gtx/quaternion.hpp"
+
+#include <com/sun/star/awt/Point.hpp>
+#include <tools/gen.hxx>
+
+#include <vcl/opengl/IOpenGLRenderer.hxx>
+
#include <vector>
+#include <list>
+#include <map>
+
+#define MAX_LIGHT_NUM 8
namespace chart {
namespace opengl3D {
+struct PosVecf3
+{
+ float x;
+ float y;
+ float z;
+};
+
typedef std::vector <glm::vec3> Vertices3D;
typedef std::vector <glm::vec2> UVs3D;
typedef std::vector <glm::vec3> Normals3D;
@@ -60,9 +81,9 @@ typedef struct Polygon3DInfo
Vertices3D *vertices;
UVs3D *uvs;
Normals3D *normals;
- list <Vertices3D *> verticesList;
- list <UVs3D *> uvsList;
- list <Normals3D *> normalsList;
+ std::list <Vertices3D *> verticesList;
+ std::list <UVs3D *> uvsList;
+ std::list <Normals3D *> normalsList;
Material material;
}Polygon3DInfo;
@@ -123,9 +144,14 @@ struct PackedVertex{
class OpenGL3DRenderer : public IOpenGLInfoProvider
{
public:
- void Set3DSenceInfo(glm::vec3 cameraUp,glm::mat4 D3DTrasform,sal_Bool twoSidesLighting,sal_Int32 color);
- void SetLightInfo(sal_Bool lightOn,sal_Int32 color,glm::vec4 direction);
- void AddShapePolygon3DObject(sal_Int32 color,sal_Bool lineOnly,sal_Int32 lineColor,long fillStyle,sal_Int32 specular);
+ OpenGL3DRenderer();
+
+ void LoadShaders();
+ void init();
+
+ void Set3DSenceInfo(glm::vec3 cameraUp,glm::mat4 D3DTrasform,bool twoSidesLighting,sal_Int32 color);
+ void SetLightInfo(bool lightOn,sal_Int32 color,glm::vec4 direction);
+ void AddShapePolygon3DObject(sal_Int32 color,bool lineOnly,sal_Int32 lineColor,long fillStyle,sal_Int32 specular);
void EndAddShapePolygon3DObject();
void AddPolygon3DObjectNormalPoint(float x, float y, float z);
void EndAddPolygon3DObjectNormalPoint();
@@ -141,6 +167,8 @@ public:
int RenderClickPos(Point aMPos);
private:
+ int MoveModelf(PosVecf3 trans, PosVecf3 angle, PosVecf3 scale);
+
void GetFreq();
int RenderPolygon3DObject();
int RenderLine3D(Polygon3DInfo &polygon);
@@ -149,7 +177,7 @@ private:
int Update3DUniformBlock();
int RenderExtrude3DObject();
int RenderFPS(float fps);
- int RenderText(::rtl::OUString string, awt::Point aPos);
+ int RenderText(::rtl::OUString string, com::sun::star::awt::Point aPos);
int RenderExtrudeSurface(Extrude3DInfo extrude3D);
int RenderExtrudeTopSurface(Extrude3DInfo extrude3D);
int RenderExtrudeMiddleSurface(Extrude3DInfo extrude3D);
@@ -170,13 +198,28 @@ private:
);
void SetVertex(PackedVertex &packed,
std::map<PackedVertex,unsigned short> &VertexToOutIndex,
- vector<glm::vec3> &vertex,
- vector<glm::vec3> &normal,
- vector<unsigned short> &indeices);
+ std::vector<glm::vec3> &vertex,
+ std::vector<glm::vec3> &normal,
+ std::vector<unsigned short> &indeices);
void CreateActualRoundedCube(float fRadius, int iSubDivY, int iSubDivZ, float width, float height, float depth);
- int GenerateRoundCornerBar(vector<glm::vec3> &vertices, vector<glm::vec3> &normals, float fRadius, int iSubDivY,
+ int GenerateRoundCornerBar(std::vector<glm::vec3> &vertices, std::vector<glm::vec3> &normals, float fRadius, int iSubDivY,
int iSubDivZ, float width, float height, float depth);
private:
+ // Projection matrix : default 45 degree Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
+ glm::mat4 m_Projection;
+ // Camera matrix
+ glm::mat4 m_View;
+ // Model matrix : an identity matrix (model will be at the origin
+ glm::mat4 m_Model;
+ // Our ModelViewProjection : multiplication of our 3 matrices
+ glm::mat4 m_MVP;
+
+ double m_dFreq;
+
+ int m_iWidth;
+
+ int m_iHeight;
+
float m_fZmax;
Lights m_LightsInfo;
@@ -185,7 +228,7 @@ private:
Polygon3DInfo m_Polygon3DInfo;
- list <Polygon3DInfo> m_Polygon3DInfoList;
+ std::list <Polygon3DInfo> m_Polygon3DInfoList;
glm::mat4 m_D3DTrasform;
@@ -197,6 +240,8 @@ private:
glm::mat4 m_3DMVP;
+ glm::mat4 m_TranslationMatrix;
+
GLint m_3DProID;
GLuint m_3DProjectionID;
@@ -221,6 +266,12 @@ private:
GLuint m_NormalBuffer;
+ GLuint m_VertexBuffer;
+
+ GLint m_MatrixID;
+
+ GLuint m_FboID[2];
+
Extrude3DInfo m_Extrude3DInfo;
std::vector <Extrude3DInfo> m_Extrude3DList;
@@ -253,6 +304,13 @@ private:
RoundBarMesh m_RoundBarMesh;
+ GLint m_CommonProID;
+ GLint m_2DVertexID;
+ GLint m_2DColorID;
+
+ //TODO: moggi: kill the following parts
+ // don't add anything below or I will remove it
+ size_t m_iPointNum;
};
}
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index afe0a723df6e..834cb85d2ec4 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -7,15 +7,67 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#define RGB_WHITE (0xFF | (0xFF << 8) | (0xFF << 16))
+#include <GL/glew.h>
#include "GL3DRenderer.hxx"
+#include <vcl/opengl/OpenGLHelper.hxx>
+#include <vcl/font.hxx>
+#include <vcl/virdev.hxx>
+
+#include <com/sun/star/awt/Size.hpp>
+
+#include <StaticGeometry.h>
+#include "glm/gtc/matrix_inverse.hpp"
+
+#define GL_PI 3.14159f
+#define OPENGL_SCALE_VALUE 20
+#define RGB_WHITE (0xFF | (0xFF << 8) | (0xFF << 16))
+
+using namespace std;
+using namespace com::sun::star;
+
namespace chart {
namespace opengl3D {
-OpenGL3DRenderer::OpenGL3DRenderer()
+namespace {
+
+struct TextInfo
+{
+ GLuint texture;
+ double rotation;
+ float vertex[12];
+ float nDx;
+ float nDy;
+};
+
+int static checkGLError(const char *file, int line)
+{
+ GLenum glErr;
+ int retCode = 0;
+ glErr = glGetError();
+ while (glErr != GL_NO_ERROR)
+ {
+ const GLubyte* sError = gluErrorString(glErr);
+
+ if (sError)
+ SAL_WARN("chart2.opengl", "GL Error #" << glErr << "(" << gluErrorString(glErr) << ") " << " in File " << file << " at line: " << line);
+ else
+ SAL_WARN("chart2.opengl", "GL Error #" << glErr << " (no message available)" << " in File " << file << " at line: " << line);
+
+ retCode = -1;
+ return retCode;
+ }
+ return retCode;
+}
+
+#define CHECK_GL_ERROR() checkGLError(__FILE__, __LINE__)
+
+}
+
+OpenGL3DRenderer::OpenGL3DRenderer():
+ m_TranslationMatrix(glm::translate(m_Model, glm::vec3(0.0f, 0.0f, 0.0f)))
{
m_Polygon3DInfo.lineOnly = false;
m_Polygon3DInfo.twoSidesLighting = false;
@@ -658,7 +710,7 @@ int OpenGL3DRenderer::RenderPolygon3DObject()
return 0;
}
-void OpenGL3DRenderer::Set3DSenceInfo(glm::vec3 cameraUp,glm::mat4 D3DTrasform,sal_Bool twoSidesLighting,sal_Int32 color)
+void OpenGL3DRenderer::Set3DSenceInfo(glm::vec3 cameraUp,glm::mat4 D3DTrasform,bool twoSidesLighting,sal_Int32 color)
{
m_CameraInfo.cameraUp = cameraUp;
@@ -675,7 +727,7 @@ void OpenGL3DRenderer::Set3DSenceInfo(glm::vec3 cameraUp,glm::mat4 D3DTrasform,s
m_LightsInfo.lightNum = 0;
}
-void OpenGL3DRenderer::SetLightInfo(sal_Bool lightOn,sal_Int32 color,glm::vec4 direction)
+void OpenGL3DRenderer::SetLightInfo(bool lightOn,sal_Int32 color,glm::vec4 direction)
{
if (lightOn)
{
@@ -690,7 +742,7 @@ void OpenGL3DRenderer::SetLightInfo(sal_Bool lightOn,sal_Int32 color,glm::vec4 d
}
-void OpenGL3DRendereOpenGL3DRenderer::AddShapePolygon3DObject(sal_Int32 color,sal_Bool lineOnly,sal_Int32 lineColor,long fillStyle,sal_Int32 specular)
+void OpenGL3DRenderer::AddShapePolygon3DObject(sal_Int32 color,bool lineOnly,sal_Int32 lineColor,long fillStyle,sal_Int32 specular)
{
m_Polygon3DInfo.polygonColor = glm::vec4((float)(((color) & 0x00FF0000) >> 16) / 255.0f,
(float)(((color) & 0x0000FF00) >> 8) / 255.0f,
@@ -1132,9 +1184,10 @@ void OpenGL3DRenderer::SetClickPos(Point aMPos)
m_aMPos = aMPos;
}
-
-int OpenGL3DRenderer::RenderText(::rtl::OUString string, awt::Point aPos)
+int OpenGL3DRenderer::RenderText(::rtl::OUString , awt::Point )
{
+ //TODO: moggi: disabled for now
+ /*
Font aFont("Arial", Size(0, 100));
Rectangle aRect;
VirtualDevice aDevice;
@@ -1146,8 +1199,8 @@ int OpenGL3DRenderer::RenderText(::rtl::OUString string, awt::Point aPos)
textWidth = (textWidth + 3) & ~3;
awt::Size aSize(textWidth, textHeight);
//clear text info
- int listNum = m_TextInfoList.size();
- for (int i = 0; i < listNum; i++)
+ size_t listNum = m_TextInfoList.size();
+ for (size_t i = 0; i < listNum; i++)
{
TextInfo &textInfo = m_TextInfoList.front();
glDeleteTextures(1, &textInfo.texture);
@@ -1156,6 +1209,7 @@ int OpenGL3DRenderer::RenderText(::rtl::OUString string, awt::Point aPos)
//create text texture
CreateTextTexture(string, aFont, 0xFF0000, aPos, aSize, 0);
RenderTextShape();
+ */
return 0;
}
@@ -1265,7 +1319,7 @@ int OpenGL3DRenderer::ProcessExtrude3DPickingBox()
glUseProgram(0);
//read pixel to get the index
Point select = Point(m_aMPos.X() / OPENGL_SCALE_VALUE, m_aMPos.Y() / OPENGL_SCALE_VALUE);
- BYTE selectColor[4] = {0};
+ sal_uInt8 selectColor[4] = {0};
#if 0
int picWidth = m_iWidth - select.X();
int picHeight = m_iHeight - select.Y();
@@ -1369,6 +1423,14 @@ void OpenGL3DRenderer::RenderCoordinateAxis()
return;
}
+int OpenGL3DRenderer::MoveModelf(PosVecf3 trans, PosVecf3 angle, PosVecf3 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));
+ glm::mat4 aRotationMatrix = glm::eulerAngleYXZ(angle.y, angle.x, angle.z);
+ m_Model = aTranslationMatrix * aRotationMatrix * aScaleMatrix;
+ return 0;
+}
}
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index e27ca7ce6cc6..96368cd3cfc3 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -39,9 +39,6 @@
#include <vcl/opengl/OpenGLHelper.hxx>
#include <boost/scoped_array.hpp>
-
-#include <StaticGeometry.h>
-#include "glm/gtc/matrix_inverse.hpp"
#include "CommonConverters.hxx"
using namespace com::sun::star;
@@ -513,7 +510,6 @@ OpenGLRender::OpenGLRender(uno::Reference< drawing::XShape > xTarget):
, m_iWidth(1600)
, m_iHeight(900)
, m_Model(glm::mat4(1.0f))
- , m_TranslationMatrix(glm::translate(m_Model, glm::vec3(0.0f, 0.0f, 0.0f)))
, m_iPointNum(0)
, m_fLineWidth(0.001f)
, mbArbMultisampleSupported(false)
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index c689f0e65f8a..3e29c9b22a9f 100644
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -22,7 +22,6 @@
#include "glm/gtx/quaternion.hpp"
#define BMP_HEADER_LEN 54
-#define MAX_LIGHT_NUM 8
#define OPENGL_SCALE_VALUE 20
#define DEBUG_POSITIONING 0
@@ -145,8 +144,6 @@ private:
// Our ModelViewProjection : multiplication of our 3 matrices
glm::mat4 m_MVP;
- glm::mat4 m_TranslationMatrix;
-
GLint m_RenderProID;
glm::vec4 m_ClearColor;