LCOV - code coverage report
Current view: top level - chart2/source/view/inc - GL3DRenderer.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 13 0.0 %
Date: 2014-11-03 Functions: 0 19 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  */
       9             : 
      10             : #ifndef INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DRENDERER_HXX
      11             : #define INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DRENDERER_HXX
      12             : 
      13             : #include "glm/glm.hpp"
      14             : #include "glm/gtx/transform.hpp"
      15             : #include "glm/gtx/euler_angles.hpp"
      16             : #include "glm/gtx/quaternion.hpp"
      17             : 
      18             : #include <com/sun/star/awt/Point.hpp>
      19             : #include <boost/shared_array.hpp>
      20             : #include <tools/gen.hxx>
      21             : 
      22             : #include <vcl/bitmapex.hxx>
      23             : 
      24             : #include <vector>
      25             : #include <list>
      26             : #include <map>
      27             : 
      28             : #define MAX_LIGHT_NUM 8
      29             : 
      30             : namespace chart {
      31             : 
      32             : namespace opengl3D {
      33             : 
      34             : struct PosVecf3
      35             : {
      36             :     float x;
      37             :     float y;
      38             :     float z;
      39             : };
      40             : 
      41             : typedef std::vector <glm::vec3> Vertices3D;
      42             : typedef std::vector <glm::vec2> UVs3D;
      43             : typedef std::vector <glm::vec3> Normals3D;
      44             : 
      45           0 : struct MaterialParameters
      46             : {
      47             :     glm::vec4 ambient;
      48             :     glm::vec4 diffuse;
      49             :     glm::vec4 specular;
      50             :     glm::vec4 materialColor;
      51             : 
      52             :     bool twoSidesLighting;
      53             :     float shininess;
      54             :     float pad;
      55             :     float pad1;
      56             : };
      57             : 
      58           0 : struct LightSource
      59             : {
      60             :     glm::vec4   lightColor;
      61             :     glm::vec4   positionWorldspace;
      62             :     float  lightPower;
      63             :     float  pad1;
      64             :     float  pad2;
      65             :     float  pad3;
      66             : };
      67             : 
      68           0 : struct GlobalLights
      69             : {
      70             :     int lightNum;
      71             :     glm::vec4 ambient;
      72             :     LightSource light[MAX_LIGHT_NUM];
      73             : };
      74             : 
      75           0 : struct Polygon3DInfo
      76             : {
      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;
      88             : };
      89             : 
      90           0 : struct Extrude3DInfo
      91             : {
      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;
     108             : };
     109             : 
     110             : struct CameraInfo
     111             : {
     112             :     glm::vec3 cameraPos;
     113             :     glm::vec3 cameraOrg;
     114             :     glm::vec3 cameraUp;
     115             : 
     116           0 :     CameraInfo():
     117           0 :         cameraUp(glm::vec3(0, 0, 1)) {}
     118             : };
     119             : 
     120             : struct RoundBarMesh
     121             : {
     122             :     float topThreshold;
     123             :     float bottomThreshold;
     124             :     int iMeshStartIndices;
     125             :     int iMeshSizes;
     126             :     int iElementStartIndices[5];
     127             :     int iElementSizes[5];
     128             : };
     129             : 
     130           0 : struct PackedVertex{
     131             :     glm::vec3 position;
     132             :     glm::vec3 normal;
     133           0 :     bool operator<(const PackedVertex& that) const{
     134           0 :         return memcmp((void*)this, (void*)&that, sizeof(PackedVertex))>0;
     135             :     };
     136             : };
     137             : 
     138           0 : struct TextInfo
     139             : {
     140             :     glm::vec4 id;
     141             :     sal_uInt32 uniqueId;
     142             :     GLuint texture;
     143             :     float vertex[12];
     144             :     glm::vec3 pos;
     145             :     glm::vec4 textColor;
     146             : };
     147             : 
     148             : struct TextureArrayInfo
     149             : {
     150             :     size_t subTextureNum;
     151             :     int textureArrayWidth;
     152             :     int textureArrayHeight;
     153             :     GLuint textureID;
     154             : 
     155             :     TextureArrayInfo();
     156             : };
     157             : 
     158           0 : struct TextInfoBatch
     159             : {
     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;
     165             : };
     166             : 
     167           0 : struct BatchBarInfo
     168             : {
     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;
     174             : };
     175             : 
     176             : class OpenGL3DRenderer
     177             : {
     178             : public:
     179             :     OpenGL3DRenderer();
     180             :     ~OpenGL3DRenderer();
     181             : 
     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             :                            ::Size maSizePixels,
     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             :                                  ::Size maSizePixels, const glm::vec2& vTopLeft,
     203             :                                  const glm::vec2& vBottomRight, glm::vec3 vPos, glm::vec4 vScreenTextColor, sal_uInt32 nUniqueId);
     204             :     void ProcessUnrenderedShape(bool bNewScene);
     205             : 
     206             :     void SetPickingMode(bool bPickingMode);
     207             : 
     208             :     sal_uInt32 GetPixelColorFromPoint(long nX, long nY);
     209             : 
     210             :     void ReleaseShapes();
     211             :     void ReleaseScreenTextShapes();
     212             :     void ReleaseTextTexture();
     213             :     void ReleaseScreenTextTexture();
     214             :     void StartClick(sal_uInt32 &selectID);
     215             :     void EndClick();
     216             :     void SetScroll();
     217             :     void SetScrollSpeed(float scrollSpeed);
     218             :     void SetScrollDistance(float scrollDistance);
     219             :     void SetSceneEdge(float minCoordX, float maxCoordX);
     220             :     glm::mat4 GetProjectionMatrix();
     221             :     glm::mat4 GetViewMatrix();
     222             :     glm::mat4 GetGlobalScaleMatrix();
     223             :     glm::mat4 GetDiffOfTwoCameras(const glm::vec3& rBeginPos, const glm::vec3& rEndPos, const glm::vec3& rBeginDirection, const glm::vec3& rEndDirection);
     224             :     glm::mat4 GetDiffOfTwoCameras(const glm::vec3& rEndPos, const glm::vec3& rEndDirection);
     225             :     void AddMatrixDiff(const glm::mat4& aMat);
     226             :     void ResetMatrixDiff();
     227             : private:
     228             :     void MoveModelf( const PosVecf3& trans, const PosVecf3& angle, const PosVecf3& scale);
     229             : 
     230             :     void ClearBuffer();
     231             :     void RenderPolygon3DObject();
     232             :     void RenderLine3D(const Polygon3DInfo &polygon);
     233             :     void RenderPolygon3D(const Polygon3DInfo &polygon);
     234             :     void Init3DUniformBlock();
     235             :     void Update3DUniformBlock();
     236             :     void RenderExtrude3DObject();
     237             :     //add for text
     238             :     void RenderTextShape();
     239             :     void RenderScreenTextShape();
     240             :     void RenderExtrudeSurface(const Extrude3DInfo& extrude3D);
     241             :     void RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D);
     242             :     void RenderExtrudeMiddleSurface(const Extrude3DInfo& extrude3D);
     243             :     void RenderExtrudeBottomSurface(const Extrude3DInfo& extrude3D);
     244             :     void RenderExtrudeFlatSurface(const Extrude3DInfo& extrude3D, int surIndex);
     245             :     void AddVertexData(GLuint vertexBuf);
     246             :     void AddNormalData(GLuint normalBuf);
     247             :     void AddIndexData(GLuint indexBuf);
     248             :     void RenderNonRoundedBar(const Extrude3DInfo& extrude3D);
     249             :     bool GetSimilarVertexIndex(PackedVertex & packed,
     250             :         std::map<PackedVertex,unsigned short> & VertexToOutIndex,
     251             :         unsigned short & result
     252             :         );
     253             :     void SetVertex(PackedVertex &packed,
     254             :         std::map<PackedVertex,unsigned short> &VertexToOutIndex,
     255             :         std::vector<glm::vec3> &vertex,
     256             :         std::vector<glm::vec3> &normal,
     257             :         std::vector<unsigned short> &indeices);
     258             :     void CreateActualRoundedCube(float fRadius, int iSubDivY, int iSubDivZ, float width, float height, float depth);
     259             :     int GenerateRoundCornerBar(std::vector<glm::vec3> &vertices, std::vector<glm::vec3> &normals, float fRadius, int iSubDivY,
     260             :                                int iSubDivZ, float width, float height, float depth);
     261             :     void CreateSceneBoxView();
     262             : 
     263             :     void ReleasePolygonShapes();
     264             :     void ReleaseExtrude3DShapes();
     265             :     void ReleaseTextShapes();
     266             :     void ReleaseBatchBarInfo();
     267             :     void GetBatchBarsInfo();
     268             :     void GetBatchTopAndFlatInfo(const Extrude3DInfo &extrude3D);
     269             :     void GetBatchMiddleInfo(const Extrude3DInfo &extrude3D);
     270             :     void InitBatch3DUniformBlock();
     271             :     void UpdateBatch3DUniformBlock();
     272             :     void RenderBatchBars(bool bNewScene);
     273             :     void CheckGLSLVersion();
     274             :     void RenderTextShapeBatch();
     275             :     void ReleaseTextShapesBatch();
     276             :     void CreateTextTextureSingle(const boost::shared_array<sal_uInt8> &bitmapBuf,
     277             :                            ::Size maSizePixels,
     278             :                            glm::vec3 vTopLeft,glm::vec3 vTopRight,
     279             :                            glm::vec3 vBottomRight, glm::vec3 vBottomLeft,
     280             :                            sal_uInt32 nUniqueId);
     281             :     void CreateTextTextureBatch(const boost::shared_array<sal_uInt8> &bitmapBuf,
     282             :                        ::Size maSizePixels,
     283             :                        glm::vec3 vTopLeft,glm::vec3 vTopRight,
     284             :                        glm::vec3 vBottomRight, glm::vec3 vBottomLeft,
     285             :                        sal_uInt32 nUniqueId);
     286             :     void SetHighLightBar(BatchBarInfo &barInfo);
     287             :     void DisableHighLightBar(BatchBarInfo &barInfo);
     288             :     void CalcScrollMoveMatrix(bool bNewScene);
     289             : private:
     290             : 
     291             :     struct ShaderResources
     292             :     {
     293             :         bool m_b330Support;
     294             :         bool m_bScrollFlag;
     295             :         // 3DProID
     296             :         GLint m_3DProID;
     297             :         GLint m_3DProjectionID;
     298             :         GLint m_3DViewID;
     299             :         GLint m_3DModelID;
     300             :         GLint m_3DNormalMatrixID;
     301             :         GLint m_3DVertexID;
     302             :         GLint m_3DNormalID;
     303             :         GLint m_3DMinCoordXID;
     304             :         GLint m_3DMaxCoordXID;
     305             :         GLint m_3DUndrawID;
     306             :         //300 verson;
     307             :         GLint m_3DMaterialAmbientID;
     308             :         GLint m_3DMaterialDiffuseID;
     309             :         GLint m_3DMaterialSpecularID;
     310             :         GLint m_3DMaterialColorID;
     311             :         GLint m_3DMaterialTwoSidesID;
     312             :         GLint m_3DMaterialShininessID;
     313             :         GLint m_3DLightColorID;
     314             :         GLint m_3DLightPosID;
     315             :         GLint m_3DLightPowerID;
     316             :         GLint m_3DLightNumID;
     317             :         GLint m_3DLightAmbientID;
     318             : 
     319             :         // TextProID
     320             :         GLint m_TextProID;
     321             :         GLint m_TextMatrixID;
     322             :         GLint m_TextVertexID;
     323             :         GLint m_TextTexCoordID;
     324             :         GLint m_TextTexID;
     325             : 
     326             :         // ScreenTextProID
     327             :         GLint m_ScreenTextProID;
     328             :         GLint m_ScreenTextVertexID;
     329             :         GLint m_ScreenTextTexCoordID;
     330             :         GLint m_ScreenTextTexID;
     331             :         GLint m_ScreenTextColorID;
     332             : 
     333             :         // CommonProID
     334             :         GLint m_CommonProID;
     335             :         GLint m_2DVertexID;
     336             :         GLint m_2DColorID;
     337             :         GLint m_MatrixID;
     338             : 
     339             :         // Batch render
     340             :         GLint m_3DBatchProID;
     341             :         GLint m_3DBatchProjectionID;
     342             :         GLint m_3DBatchViewID;
     343             :         GLint m_3DBatchModelID;
     344             :         GLint m_3DBatchNormalMatrixID;
     345             :         GLint m_3DBatchVertexID;
     346             :         GLint m_3DBatchNormalID;
     347             :         GLint m_3DBatchColorID;
     348             :         GLint m_3DBatchTransMatrixID;
     349             :         GLint m_3DBatchMinCoordXID;
     350             :         GLint m_3DBatchMaxCoordXID;
     351             :         GLint m_3DBatchUndrawID;
     352             : 
     353             :         //Batch render text
     354             :         bool mbTexBatchSupport;
     355             :         GLint m_BatchTextProID;
     356             :         GLint m_BatchTextMatrixID;
     357             :         GLint m_BatchTextVertexID;
     358             :         GLint m_BatchTextTexCoordID;
     359             :         GLint m_BatchTextTexID;
     360             : 
     361             :         ShaderResources();
     362             :         ~ShaderResources();
     363             : 
     364             :         void LoadShaders();
     365             :     };
     366             : 
     367             :     struct PickingShaderResources
     368             :     {
     369             :         // CommonProID
     370             :         GLint m_CommonProID;
     371             :         GLint m_2DVertexID;
     372             :         GLint m_2DColorID;
     373             :         GLint m_MatrixID;
     374             :         GLint m_ModelID;
     375             :         GLint m_MinCoordXID;
     376             :         GLint m_MaxCoordXID;
     377             :         PickingShaderResources();
     378             :         ~PickingShaderResources();
     379             : 
     380             :         void LoadShaders();
     381             :     };
     382             : 
     383             :     ShaderResources maResources;
     384             :     PickingShaderResources maPickingResources;
     385             : 
     386             :     // Model matrix : an identity matrix (model will be at the origin
     387             :     glm::mat4 m_Model;
     388             : 
     389             :     sal_Int32 m_iWidth;
     390             : 
     391             :     sal_Int32 m_iHeight;
     392             : 
     393             :     GlobalLights m_LightsInfo;
     394             : 
     395             :     CameraInfo m_CameraInfo;
     396             : 
     397             :     Polygon3DInfo m_Polygon3DInfo;
     398             : 
     399             :     std::vector <Polygon3DInfo> m_Polygon3DInfoList;
     400             : 
     401             :     glm::mat4 m_3DProjection;
     402             : 
     403             :     glm::mat4 m_3DView;
     404             : 
     405             :     glm::mat4 m_3DMVP;
     406             : 
     407             :     GLuint m_3DUBOBuffer;
     408             : #if 0
     409             :     GLint m_3DLightBlockIndex;
     410             : 
     411             :     GLint m_3DMaterialBlockIndex;
     412             : #endif
     413             :     GLint m_3DActualSizeLight;
     414             : 
     415             :     GLuint m_NormalBuffer;
     416             : 
     417             :     GLuint m_VertexBuffer;
     418             : 
     419             :     Extrude3DInfo m_Extrude3DInfo;
     420             : 
     421             :     std::vector <Extrude3DInfo> m_Extrude3DList;
     422             : 
     423             :     GLuint m_CubeVertexBuf;
     424             : 
     425             :     GLuint m_CubeElementBuf;
     426             : 
     427             :     GLuint m_CubeNormalBuf;
     428             : 
     429             :     GLuint m_BoundBox;
     430             :     GLuint m_BoundBoxNormal;
     431             :      // add for text
     432             :     std::vector <TextInfo> m_TextInfoList;
     433             :     std::vector <TextInfo> m_ScreenTextInfoList;
     434             :     GLuint m_TextTexCoordBuf;
     435             :     GLuint m_TextTexCoordBufBatch;
     436             : 
     437             :     std::vector<glm::vec3> m_Vertices;
     438             : 
     439             :     std::vector<glm::vec3> m_Normals;
     440             : 
     441             :     std::vector<unsigned short> m_Indices;
     442             : 
     443             :     RoundBarMesh m_RoundBarMesh;
     444             : 
     445             :     GLuint m_RenderVertexBuf;
     446             : 
     447             :     GLuint m_RenderTexCoordBuf;
     448             : 
     449             :     float m_fViewAngle;
     450             : 
     451             :     bool mbPickingMode;
     452             : 
     453             :     GLuint mnPickingFbo;
     454             :     GLuint mnPickingRboDepth;
     455             :     GLuint mnPickingRboColor;
     456             : 
     457             :     BatchBarInfo m_BarSurface[3];
     458             :     GLuint m_BatchModelMatrixBuf;
     459             :     GLuint m_BatchNormalMatrixBuf;
     460             :     GLuint m_BatchColorBuf;
     461             :     MaterialParameters m_Batchmaterial;
     462             :     GLuint m_Batch3DUBOBuffer;
     463             :     GLint m_Batch3DActualSizeLight;
     464             : 
     465             :     glm::mat4 m_GlobalScaleMatrix;
     466             :     TextInfoBatch m_TextInfoBatch;
     467             :     //for 3.0 version
     468             :     int m_iLightNum;
     469             :     glm::vec4 m_Ambient;
     470             :     glm::vec4 m_LightColor[MAX_LIGHT_NUM];
     471             :     glm::vec4 m_PositionWorldspace[MAX_LIGHT_NUM];
     472             :     float m_fLightPower[MAX_LIGHT_NUM];
     473             :     //for 3.0 end
     474             :     std::vector<GLuint> m_Texturelist;
     475             :     std::vector<GLuint> m_ScreenTexturelist;
     476             :     bool m_bHighLighting;
     477             :     sal_uInt32 m_uiSelectID;
     478             :     float m_fScrollSpeed;
     479             :     float m_fScrollDistance;
     480             :     float m_fMinCoordX;
     481             :     float m_fMaxCoordX;
     482             :     float m_fCurDistance;
     483             :     glm::mat4 m_ScrollMoveMatrix;
     484             :     bool m_bUndrawFlag;
     485             :     glm::mat4 m_matDiff;
     486             : };
     487             : 
     488             : }
     489             : 
     490             : }
     491             : 
     492             : #endif
     493             : 
     494             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10