1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
28 #define MAX_LIGHT_NUM 8
41 typedef std::vector
<glm::vec3
> Vertices3D
;
42 typedef std::vector
<glm::vec2
> UVs3D
;
43 typedef std::vector
<glm::vec3
> Normals3D
;
45 struct MaterialParameters
50 glm::vec4 materialColor
;
52 bool twoSidesLighting
;
61 glm::vec4 positionWorldspace
;
72 LightSource light
[MAX_LIGHT_NUM
];
79 bool twoSidesLighting
;
81 glm::vec4 polygonColor
;
85 std::vector
<Vertices3D
*> verticesList
;
86 std::vector
<Normals3D
*> normalsList
;
87 MaterialParameters material
;
93 bool twoSidesLighting
;
94 glm::vec4 extrudeColor
;
104 MaterialParameters material
;
117 cameraUp(glm::vec3(0, 0, 1)) {}
123 float bottomThreshold
;
124 int iMeshStartIndices
;
126 int iElementStartIndices
[5];
127 int iElementSizes
[5];
133 bool operator<(const PackedVertex
& that
) const{
134 return memcmp((void*)this, (void*)&that
, sizeof(PackedVertex
))>0;
148 struct TextureArrayInfo
150 size_t subTextureNum
;
151 int textureArrayWidth
;
152 int textureArrayHeight
;
161 std::vector
<glm::vec4
> idList
;
162 std::vector
<TextureArrayInfo
> texture
;
163 std::vector
<glm::vec3
> vertexList
;
164 std::vector
<glm::vec3
> textureCoordList
;
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
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
);
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();
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();
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
);
292 struct ShaderResources
298 GLint m_3DProjectionID
;
301 GLint m_3DNormalMatrixID
;
304 GLint m_3DMinCoordXID
;
305 GLint m_3DMaxCoordXID
;
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
;
322 GLint m_TextMatrixID
;
323 GLint m_TextVertexID
;
324 GLint m_TextTexCoordID
;
328 GLint m_ScreenTextProID
;
329 GLint m_ScreenTextVertexID
;
330 GLint m_ScreenTextTexCoordID
;
331 GLint m_ScreenTextTexID
;
332 GLint m_ScreenTextColorID
;
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
;
355 bool mbTexBatchSupport
;
356 GLint m_BatchTextProID
;
357 GLint m_BatchTextMatrixID
;
358 GLint m_BatchTextVertexID
;
359 GLint m_BatchTextTexCoordID
;
360 GLint m_BatchTextTexID
;
368 struct PickingShaderResources
378 PickingShaderResources();
379 ~PickingShaderResources();
384 ShaderResources maResources
;
385 PickingShaderResources maPickingResources
;
387 // Model matrix : an identity matrix (model will be at the origin
394 GlobalLights m_LightsInfo
;
396 CameraInfo m_CameraInfo
;
398 Polygon3DInfo m_Polygon3DInfo
;
400 std::vector
<Polygon3DInfo
> m_Polygon3DInfoList
;
402 glm::mat4 m_3DProjection
;
408 GLuint m_3DUBOBuffer
;
410 GLint m_3DLightBlockIndex
;
412 GLint m_3DMaterialBlockIndex
;
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
;
431 GLuint m_BoundBoxNormal
;
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
;
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
;
471 glm::vec4 m_LightColor
[MAX_LIGHT_NUM
];
472 glm::vec4 m_PositionWorldspace
[MAX_LIGHT_NUM
];
473 float m_fLightPower
[MAX_LIGHT_NUM
];
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
;
483 float m_fCurDistance
;
484 glm::mat4 m_ScrollMoveMatrix
;
495 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */