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>
32 const auto maxLights
= 8;
41 typedef std::vector
<glm::vec3
> Vertices3D
;
42 typedef std::vector
<glm::vec3
> Normals3D
;
44 // fields must match definition in GLSL shader file
45 struct MaterialParameters
50 glm::vec4 materialColor
;
52 bool twoSidesLighting
;
58 // fields must match definition in GLSL shader file
62 glm::vec4 positionWorldspace
;
73 LightSource light
[maxLights
];
80 bool twoSidesLighting
;
82 glm::vec4 polygonColor
;
86 std::vector
<Vertices3D
*> verticesList
;
87 std::vector
<Normals3D
*> normalsList
;
88 MaterialParameters material
;
94 bool twoSidesLighting
;
95 glm::vec4 extrudeColor
;
105 MaterialParameters material
;
118 cameraUp(glm::vec3(0, 0, 1)) {}
124 float bottomThreshold
;
125 int iMeshStartIndices
;
127 int iElementStartIndices
[5];
128 int iElementSizes
[5];
134 bool operator<(const PackedVertex
& that
) const{
135 return memcmp(this, &that
, sizeof(PackedVertex
))>0;
149 struct TextureArrayInfo
151 size_t subTextureNum
;
152 int textureArrayWidth
;
153 int textureArrayHeight
;
162 std::vector
<glm::vec4
> idList
;
163 std::vector
<TextureArrayInfo
> texture
;
164 std::vector
<glm::vec3
> vertexList
;
165 std::vector
<glm::vec3
> textureCoordList
;
170 std::vector
<glm::mat4
> modelMatrixList
;
171 std::vector
<glm::mat3
> normalMatrixList
;
172 std::vector
<glm::vec4
> colorList
;
173 std::map
<sal_uInt32
, unsigned int> mapId2Color
;
174 glm::vec4 selectBarColor
;
177 class OpenGL3DRenderer
184 void Set3DSenceInfo(Color color
, bool twoSidesLighting
= true);
185 void SetLightInfo(bool lightOn
, Color color
, const glm::vec4
& direction
);
186 void AddShapePolygon3DObject(Color color
, bool lineOnly
, Color lineColor
,
187 long fillStyle
, sal_uInt32 specular
, sal_uInt32 nUniqueId
);
188 void EndAddShapePolygon3DObject();
189 void AddPolygon3DObjectNormalPoint(float x
, float y
, float z
);
190 void EndAddPolygon3DObjectNormalPoint();
191 void AddPolygon3DObjectPoint(float x
, float y
, float z
);
192 void EndAddPolygon3DObjectPoint();
193 void AddShape3DExtrudeObject(bool roundedCorner
, Color color
, sal_uInt32 specular
, const glm::mat4
& modelMatrix
, sal_uInt32 nUniqueId
);
194 void EndAddShape3DExtrudeObject();
195 void SetSize(const Size
& rSize
);
196 void SetCameraInfo(const glm::vec3
& pos
, const glm::vec3
& direction
, const glm::vec3
& up
);
197 void CreateTextTexture(const boost::shared_array
<sal_uInt8
> &bitmapBuf
,
198 const ::Size
& rSizePixels
,
199 const glm::vec3
& vTopLeft
, const glm::vec3
& vTopRight
,
200 const glm::vec3
& vBottomRight
, const glm::vec3
& vBottomLeft
,
201 sal_uInt32 nUniqueId
);
202 void CreateScreenTextTexture(const boost::shared_array
<sal_uInt8
> &bitmapBuf
,
203 const ::Size
& rSizePixels
, const glm::vec2
& vTopLeft
,
204 const glm::vec2
& vBottomRight
, const glm::vec3
& vPos
, const glm::vec4
& vScreenTextColor
,
205 sal_uInt32 nUniqueId
);
206 void ProcessUnrenderedShape(bool bNewScene
);
208 void SetPickingMode(bool bPickingMode
);
210 Color
GetPixelColorFromPoint(long nX
, long nY
);
212 void ReleaseShapes();
213 void ReleaseScreenTextShapes();
214 void ReleaseTextTexture();
215 void ReleaseScreenTextTexture();
216 void StartClick(sal_uInt32 selectID
);
219 void SetScrollSpeed(float scrollSpeed
);
220 void SetScrollDistance(float scrollDistance
);
221 void SetSceneEdge(float minCoordX
, float maxCoordX
);
222 const glm::mat4
& GetProjectionMatrix();
223 const glm::mat4
& GetViewMatrix();
224 const glm::mat4
& GetGlobalScaleMatrix();
225 glm::mat4
GetDiffOfTwoCameras(const glm::vec3
& rBeginPos
, const glm::vec3
& rEndPos
, const glm::vec3
& rBeginDirection
, const glm::vec3
& rEndDirection
);
226 glm::mat4
GetDiffOfTwoCameras(const glm::vec3
& rEndPos
, const glm::vec3
& rEndDirection
);
227 void AddMatrixDiff(const glm::mat4
& aMat
);
228 void ResetMatrixDiff();
230 void MoveModelf( const PosVecf3
& trans
, const PosVecf3
& angle
, const PosVecf3
& scale
);
232 static void ClearBuffer();
233 void RenderPolygon3DObject();
234 void RenderLine3D(const Polygon3DInfo
&polygon
);
235 void RenderPolygon3D(const Polygon3DInfo
&polygon
);
236 void Init3DUniformBlock();
237 void Update3DUniformBlock();
238 void RenderExtrude3DObject();
240 void RenderTextShape();
241 void RenderScreenTextShape();
242 void RenderExtrudeSurface(const Extrude3DInfo
& extrude3D
);
243 void RenderExtrudeTopSurface(const Extrude3DInfo
& extrude3D
);
244 void RenderExtrudeMiddleSurface(const Extrude3DInfo
& extrude3D
);
245 void RenderExtrudeBottomSurface(const Extrude3DInfo
& extrude3D
);
246 void RenderExtrudeFlatSurface(const Extrude3DInfo
& extrude3D
, int surIndex
);
247 void AddVertexData(GLuint vertexBuf
);
248 void AddNormalData(GLuint normalBuf
);
249 void AddIndexData(GLuint indexBuf
);
250 void RenderNonRoundedBar(const Extrude3DInfo
& extrude3D
);
251 static bool GetSimilarVertexIndex(PackedVertex
const & packed
,
252 std::map
<PackedVertex
,unsigned short> & VertexToOutIndex
,
253 unsigned short & result
255 static void SetVertex(PackedVertex
const &packed
,
256 std::map
<PackedVertex
,unsigned short> &VertexToOutIndex
,
257 std::vector
<glm::vec3
> &vertex
,
258 std::vector
<glm::vec3
> &normal
,
259 std::vector
<unsigned short> &indeices
);
260 void CreateActualRoundedCube(float fRadius
, int iSubDivY
, int iSubDivZ
, float width
, float height
, float depth
);
261 static int GenerateRoundCornerBar(std::vector
<glm::vec3
> &vertices
, std::vector
<glm::vec3
> &normals
, float fRadius
, int iSubDivY
,
262 int iSubDivZ
, float width
, float height
, float depth
);
263 void CreateSceneBoxView();
265 void ReleasePolygonShapes();
266 void ReleaseExtrude3DShapes();
267 void ReleaseTextShapes();
268 void ReleaseBatchBarInfo();
269 void GetBatchBarsInfo();
270 void GetBatchTopAndFlatInfo(const Extrude3DInfo
&extrude3D
);
271 void GetBatchMiddleInfo(const Extrude3DInfo
&extrude3D
);
272 void InitBatch3DUniformBlock();
273 void UpdateBatch3DUniformBlock();
274 void RenderBatchBars(bool bNewScene
);
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_3DActualSizeLight
;
412 GLuint m_NormalBuffer
;
414 GLuint m_VertexBuffer
;
416 Extrude3DInfo m_Extrude3DInfo
;
418 std::vector
<Extrude3DInfo
> m_Extrude3DList
;
420 GLuint m_CubeVertexBuf
;
422 GLuint m_CubeElementBuf
;
424 GLuint m_CubeNormalBuf
;
427 GLuint m_BoundBoxNormal
;
429 std::vector
<TextInfo
> m_TextInfoList
;
430 std::vector
<TextInfo
> m_ScreenTextInfoList
;
431 GLuint m_TextTexCoordBuf
;
432 GLuint m_TextTexCoordBufBatch
;
434 std::vector
<glm::vec3
> m_Vertices
;
436 std::vector
<glm::vec3
> m_Normals
;
438 std::vector
<unsigned short> m_Indices
;
440 RoundBarMesh m_RoundBarMesh
;
442 GLuint m_RenderVertexBuf
;
444 GLuint m_RenderTexCoordBuf
;
451 GLuint mnPickingRboDepth
;
452 GLuint mnPickingRboColor
;
454 BatchBarInfo m_BarSurface
[3];
455 GLuint m_BatchModelMatrixBuf
;
456 GLuint m_BatchNormalMatrixBuf
;
457 GLuint m_BatchColorBuf
;
458 MaterialParameters m_Batchmaterial
;
459 GLuint m_Batch3DUBOBuffer
;
460 GLint m_Batch3DActualSizeLight
;
462 glm::mat4 m_GlobalScaleMatrix
;
463 TextInfoBatch m_TextInfoBatch
;
467 glm::vec4 m_LightColor
[maxLights
];
468 glm::vec4 m_PositionWorldspace
[maxLights
];
469 float m_fLightPower
[maxLights
];
471 std::vector
<GLuint
> m_Texturelist
;
472 std::vector
<GLuint
> m_ScreenTexturelist
;
473 bool m_bHighLighting
;
474 sal_uInt32 m_uiSelectID
;
475 float m_fScrollSpeed
;
476 float m_fScrollDistance
;
479 float m_fCurDistance
;
480 glm::mat4 m_ScrollMoveMatrix
;
491 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */