fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / view / inc / GL3DRenderer.hxx
blobafaa0f0e278eef0d442d18dcae440ff918db777c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DRENDERER_HXX
11 #define INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DRENDERER_HXX
13 #include "glm/glm.hpp"
14 #include "glm/gtx/transform.hpp"
15 #include "glm/gtx/euler_angles.hpp"
16 #include "glm/gtx/quaternion.hpp"
18 #include <com/sun/star/awt/Point.hpp>
19 #include <boost/shared_array.hpp>
20 #include <tools/gen.hxx>
22 #include <vcl/bitmapex.hxx>
24 #include <vector>
25 #include <list>
26 #include <map>
28 #define MAX_LIGHT_NUM 8
30 namespace chart {
32 namespace opengl3D {
34 struct PosVecf3
36 float x;
37 float y;
38 float z;
41 typedef std::vector <glm::vec3> Vertices3D;
42 typedef std::vector <glm::vec2> UVs3D;
43 typedef std::vector <glm::vec3> Normals3D;
45 struct MaterialParameters
47 glm::vec4 ambient;
48 glm::vec4 diffuse;
49 glm::vec4 specular;
50 glm::vec4 materialColor;
52 bool twoSidesLighting;
53 float shininess;
54 float pad;
55 float pad1;
58 struct LightSource
60 glm::vec4 lightColor;
61 glm::vec4 positionWorldspace;
62 float lightPower;
63 float pad1;
64 float pad2;
65 float pad3;
68 struct GlobalLights
70 int lightNum;
71 glm::vec4 ambient;
72 LightSource light[MAX_LIGHT_NUM];
75 struct Polygon3DInfo
77 bool lineOnly;
78 float lineWidth;
79 bool twoSidesLighting;
80 long fillStyle;
81 glm::vec4 polygonColor;
82 glm::vec4 id;
83 Vertices3D *vertices;
84 Normals3D *normals;
85 std::vector <Vertices3D *> verticesList;
86 std::vector <Normals3D *> normalsList;
87 MaterialParameters material;
90 struct Extrude3DInfo
92 bool rounded;
93 bool twoSidesLighting;
94 glm::vec4 extrudeColor;
95 glm::vec4 id;
96 sal_uInt32 orgID;
97 float xScale;
98 float yScale;
99 float zScale;
100 float xTransform;
101 float yTransform;
102 float zTransform;
103 glm::mat4 rotation;
104 MaterialParameters material;
105 int startIndex[5];
106 int size[5];
107 int reverse;
110 struct CameraInfo
112 glm::vec3 cameraPos;
113 glm::vec3 cameraOrg;
114 glm::vec3 cameraUp;
116 CameraInfo():
117 cameraUp(glm::vec3(0, 0, 1)) {}
120 struct RoundBarMesh
122 float topThreshold;
123 float bottomThreshold;
124 int iMeshStartIndices;
125 int iMeshSizes;
126 int iElementStartIndices[5];
127 int iElementSizes[5];
130 struct PackedVertex{
131 glm::vec3 position;
132 glm::vec3 normal;
133 bool operator<(const PackedVertex& that) const{
134 return memcmp((void*)this, (void*)&that, sizeof(PackedVertex))>0;
138 struct TextInfo
140 glm::vec4 id;
141 sal_uInt32 uniqueId;
142 GLuint texture;
143 float vertex[12];
144 glm::vec3 pos;
145 glm::vec4 textColor;
148 struct TextureArrayInfo
150 size_t subTextureNum;
151 int textureArrayWidth;
152 int textureArrayHeight;
153 GLuint textureID;
155 TextureArrayInfo();
158 struct TextInfoBatch
160 size_t batchNum;
161 std::vector<glm::vec4> idList;
162 std::vector<TextureArrayInfo> texture;
163 std::vector<glm::vec3> vertexList;
164 std::vector<glm::vec3> textureCoordList;
167 struct BatchBarInfo
169 std::vector <glm::mat4> modelMatrixList;
170 std::vector <glm::mat3> normalMatrixList;
171 std::vector <glm::vec4> colorList;
172 std::map<sal_uInt32, unsigned int> mapId2Color;
173 glm::vec4 selectBarColor;
176 class OpenGL3DRenderer
178 public:
179 OpenGL3DRenderer();
180 ~OpenGL3DRenderer();
182 void init();
183 void Set3DSenceInfo(sal_uInt32 color = 255, bool twoSidesLighting = true);
184 void SetLightInfo(bool lightOn, sal_uInt32 color, const glm::vec4& direction);
185 void AddShapePolygon3DObject(sal_uInt32 color, bool lineOnly, sal_uInt32 lineColor,
186 long fillStyle, sal_uInt32 specular, sal_uInt32 nUniqueId);
187 void EndAddShapePolygon3DObject();
188 void AddPolygon3DObjectNormalPoint(float x, float y, float z);
189 void EndAddPolygon3DObjectNormalPoint();
190 void AddPolygon3DObjectPoint(float x, float y, float z);
191 void EndAddPolygon3DObjectPoint();
192 void AddShape3DExtrudeObject(bool roundedCorner, sal_uInt32 color, sal_uInt32 specular, const glm::mat4& modelMatrix, sal_uInt32 nUniqueId);
193 void EndAddShape3DExtrudeObject();
194 void SetSize(const Size& rSize);
195 void SetCameraInfo(const glm::vec3& pos, const glm::vec3& direction, const glm::vec3& up);
196 void CreateTextTexture(const boost::shared_array<sal_uInt8> &bitmapBuf,
197 const ::Size& rSizePixels,
198 const glm::vec3& vTopLeft, const glm::vec3& vTopRight,
199 const glm::vec3& vBottomRight, const glm::vec3& vBottomLeft,
200 sal_uInt32 nUniqueId);
201 void CreateScreenTextTexture(const boost::shared_array<sal_uInt8> &bitmapBuf,
202 const ::Size& rSizePixels, const glm::vec2& vTopLeft,
203 const glm::vec2& vBottomRight, const glm::vec3& vPos, const glm::vec4& vScreenTextColor,
204 sal_uInt32 nUniqueId);
205 void ProcessUnrenderedShape(bool bNewScene);
207 void SetPickingMode(bool bPickingMode);
209 sal_uInt32 GetPixelColorFromPoint(long nX, long nY);
211 void ReleaseShapes();
212 void ReleaseScreenTextShapes();
213 void ReleaseTextTexture();
214 void ReleaseScreenTextTexture();
215 void StartClick(sal_uInt32 &selectID);
216 void EndClick();
217 void SetScroll();
218 void SetScrollSpeed(float scrollSpeed);
219 void SetScrollDistance(float scrollDistance);
220 void SetSceneEdge(float minCoordX, float maxCoordX);
221 glm::mat4 GetProjectionMatrix();
222 glm::mat4 GetViewMatrix();
223 glm::mat4 GetGlobalScaleMatrix();
224 glm::mat4 GetDiffOfTwoCameras(const glm::vec3& rBeginPos, const glm::vec3& rEndPos, const glm::vec3& rBeginDirection, const glm::vec3& rEndDirection);
225 glm::mat4 GetDiffOfTwoCameras(const glm::vec3& rEndPos, const glm::vec3& rEndDirection);
226 void AddMatrixDiff(const glm::mat4& aMat);
227 void ResetMatrixDiff();
228 private:
229 void MoveModelf( const PosVecf3& trans, const PosVecf3& angle, const PosVecf3& scale);
231 static void ClearBuffer();
232 void RenderPolygon3DObject();
233 void RenderLine3D(const Polygon3DInfo &polygon);
234 void RenderPolygon3D(const Polygon3DInfo &polygon);
235 void Init3DUniformBlock();
236 void Update3DUniformBlock();
237 void RenderExtrude3DObject();
238 //add for text
239 void RenderTextShape();
240 void RenderScreenTextShape();
241 void RenderExtrudeSurface(const Extrude3DInfo& extrude3D);
242 void RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D);
243 void RenderExtrudeMiddleSurface(const Extrude3DInfo& extrude3D);
244 void RenderExtrudeBottomSurface(const Extrude3DInfo& extrude3D);
245 void RenderExtrudeFlatSurface(const Extrude3DInfo& extrude3D, int surIndex);
246 void AddVertexData(GLuint vertexBuf);
247 void AddNormalData(GLuint normalBuf);
248 void AddIndexData(GLuint indexBuf);
249 void RenderNonRoundedBar(const Extrude3DInfo& extrude3D);
250 static bool GetSimilarVertexIndex(PackedVertex & packed,
251 std::map<PackedVertex,unsigned short> & VertexToOutIndex,
252 unsigned short & result
254 static void SetVertex(PackedVertex &packed,
255 std::map<PackedVertex,unsigned short> &VertexToOutIndex,
256 std::vector<glm::vec3> &vertex,
257 std::vector<glm::vec3> &normal,
258 std::vector<unsigned short> &indeices);
259 void CreateActualRoundedCube(float fRadius, int iSubDivY, int iSubDivZ, float width, float height, float depth);
260 static int GenerateRoundCornerBar(std::vector<glm::vec3> &vertices, std::vector<glm::vec3> &normals, float fRadius, int iSubDivY,
261 int iSubDivZ, float width, float height, float depth);
262 void CreateSceneBoxView();
264 void ReleasePolygonShapes();
265 void ReleaseExtrude3DShapes();
266 void ReleaseTextShapes();
267 void ReleaseBatchBarInfo();
268 void GetBatchBarsInfo();
269 void GetBatchTopAndFlatInfo(const Extrude3DInfo &extrude3D);
270 void GetBatchMiddleInfo(const Extrude3DInfo &extrude3D);
271 void InitBatch3DUniformBlock();
272 void UpdateBatch3DUniformBlock();
273 void RenderBatchBars(bool bNewScene);
274 void CheckGLSLVersion();
275 void RenderTextShapeBatch();
276 void ReleaseTextShapesBatch();
277 void CreateTextTextureSingle(const boost::shared_array<sal_uInt8> &bitmapBuf,
278 const ::Size& rSizePixels,
279 const glm::vec3& vTopLeft, const glm::vec3& vTopRight,
280 const glm::vec3& vBottomRight, const glm::vec3& vBottomLeft,
281 sal_uInt32 nUniqueId);
282 void CreateTextTextureBatch(const boost::shared_array<sal_uInt8> &bitmapBuf,
283 const ::Size& rSizePixels,
284 const glm::vec3& vTopLeft, const glm::vec3& vTopRight,
285 const glm::vec3& vBottomRight, const glm::vec3& vBottomLeft,
286 sal_uInt32 nUniqueId);
287 void SetHighLightBar(BatchBarInfo &barInfo);
288 void DisableHighLightBar(BatchBarInfo &barInfo);
289 void CalcScrollMoveMatrix(bool bNewScene);
290 private:
292 struct ShaderResources
294 bool m_b330Support;
295 bool m_bScrollFlag;
296 // 3DProID
297 GLint m_3DProID;
298 GLint m_3DProjectionID;
299 GLint m_3DViewID;
300 GLint m_3DModelID;
301 GLint m_3DNormalMatrixID;
302 GLint m_3DVertexID;
303 GLint m_3DNormalID;
304 GLint m_3DMinCoordXID;
305 GLint m_3DMaxCoordXID;
306 GLint m_3DUndrawID;
307 //300 verson;
308 GLint m_3DMaterialAmbientID;
309 GLint m_3DMaterialDiffuseID;
310 GLint m_3DMaterialSpecularID;
311 GLint m_3DMaterialColorID;
312 GLint m_3DMaterialTwoSidesID;
313 GLint m_3DMaterialShininessID;
314 GLint m_3DLightColorID;
315 GLint m_3DLightPosID;
316 GLint m_3DLightPowerID;
317 GLint m_3DLightNumID;
318 GLint m_3DLightAmbientID;
320 // TextProID
321 GLint m_TextProID;
322 GLint m_TextMatrixID;
323 GLint m_TextVertexID;
324 GLint m_TextTexCoordID;
325 GLint m_TextTexID;
327 // ScreenTextProID
328 GLint m_ScreenTextProID;
329 GLint m_ScreenTextVertexID;
330 GLint m_ScreenTextTexCoordID;
331 GLint m_ScreenTextTexID;
332 GLint m_ScreenTextColorID;
334 // CommonProID
335 GLint m_CommonProID;
336 GLint m_2DVertexID;
337 GLint m_2DColorID;
338 GLint m_MatrixID;
340 // Batch render
341 GLint m_3DBatchProID;
342 GLint m_3DBatchProjectionID;
343 GLint m_3DBatchViewID;
344 GLint m_3DBatchModelID;
345 GLint m_3DBatchNormalMatrixID;
346 GLint m_3DBatchVertexID;
347 GLint m_3DBatchNormalID;
348 GLint m_3DBatchColorID;
349 GLint m_3DBatchTransMatrixID;
350 GLint m_3DBatchMinCoordXID;
351 GLint m_3DBatchMaxCoordXID;
352 GLint m_3DBatchUndrawID;
354 //Batch render text
355 bool mbTexBatchSupport;
356 GLint m_BatchTextProID;
357 GLint m_BatchTextMatrixID;
358 GLint m_BatchTextVertexID;
359 GLint m_BatchTextTexCoordID;
360 GLint m_BatchTextTexID;
362 ShaderResources();
363 ~ShaderResources();
365 void LoadShaders();
368 struct PickingShaderResources
370 // CommonProID
371 GLint m_CommonProID;
372 GLint m_2DVertexID;
373 GLint m_2DColorID;
374 GLint m_MatrixID;
375 GLint m_ModelID;
376 GLint m_MinCoordXID;
377 GLint m_MaxCoordXID;
378 PickingShaderResources();
379 ~PickingShaderResources();
381 void LoadShaders();
384 ShaderResources maResources;
385 PickingShaderResources maPickingResources;
387 // Model matrix : an identity matrix (model will be at the origin
388 glm::mat4 m_Model;
390 sal_Int32 m_iWidth;
392 sal_Int32 m_iHeight;
394 GlobalLights m_LightsInfo;
396 CameraInfo m_CameraInfo;
398 Polygon3DInfo m_Polygon3DInfo;
400 std::vector <Polygon3DInfo> m_Polygon3DInfoList;
402 glm::mat4 m_3DProjection;
404 glm::mat4 m_3DView;
406 glm::mat4 m_3DMVP;
408 GLuint m_3DUBOBuffer;
409 #if 0
410 GLint m_3DLightBlockIndex;
412 GLint m_3DMaterialBlockIndex;
413 #endif
414 GLint m_3DActualSizeLight;
416 GLuint m_NormalBuffer;
418 GLuint m_VertexBuffer;
420 Extrude3DInfo m_Extrude3DInfo;
422 std::vector <Extrude3DInfo> m_Extrude3DList;
424 GLuint m_CubeVertexBuf;
426 GLuint m_CubeElementBuf;
428 GLuint m_CubeNormalBuf;
430 GLuint m_BoundBox;
431 GLuint m_BoundBoxNormal;
432 // add for text
433 std::vector <TextInfo> m_TextInfoList;
434 std::vector <TextInfo> m_ScreenTextInfoList;
435 GLuint m_TextTexCoordBuf;
436 GLuint m_TextTexCoordBufBatch;
438 std::vector<glm::vec3> m_Vertices;
440 std::vector<glm::vec3> m_Normals;
442 std::vector<unsigned short> m_Indices;
444 RoundBarMesh m_RoundBarMesh;
446 GLuint m_RenderVertexBuf;
448 GLuint m_RenderTexCoordBuf;
450 float m_fViewAngle;
452 bool mbPickingMode;
454 GLuint mnPickingFbo;
455 GLuint mnPickingRboDepth;
456 GLuint mnPickingRboColor;
458 BatchBarInfo m_BarSurface[3];
459 GLuint m_BatchModelMatrixBuf;
460 GLuint m_BatchNormalMatrixBuf;
461 GLuint m_BatchColorBuf;
462 MaterialParameters m_Batchmaterial;
463 GLuint m_Batch3DUBOBuffer;
464 GLint m_Batch3DActualSizeLight;
466 glm::mat4 m_GlobalScaleMatrix;
467 TextInfoBatch m_TextInfoBatch;
468 //for 3.0 version
469 int m_iLightNum;
470 glm::vec4 m_Ambient;
471 glm::vec4 m_LightColor[MAX_LIGHT_NUM];
472 glm::vec4 m_PositionWorldspace[MAX_LIGHT_NUM];
473 float m_fLightPower[MAX_LIGHT_NUM];
474 //for 3.0 end
475 std::vector<GLuint> m_Texturelist;
476 std::vector<GLuint> m_ScreenTexturelist;
477 bool m_bHighLighting;
478 sal_uInt32 m_uiSelectID;
479 float m_fScrollSpeed;
480 float m_fScrollDistance;
481 float m_fMinCoordX;
482 float m_fMaxCoordX;
483 float m_fCurDistance;
484 glm::mat4 m_ScrollMoveMatrix;
485 bool m_bUndrawFlag;
486 glm::mat4 m_matDiff;
493 #endif
495 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */