1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <vcl/font.hxx>
#if defined( UNX )
#include <prex.h>
#include "GL/glxew.h"
#include <postx.h>
#endif
#if defined( _WIN32 )
#include "prewin.h"
#include "windows.h"
#include "postwin.h"
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <vcl/window.hxx>
#include <vcl/syschild.hxx>
#include <vcl/sysdata.hxx>
#include <vcl/bitmapex.hxx>
#include <com/sun/star/drawing/HomogenMatrix3.hpp>
#if defined( _WIN32 )
#include <GL/glu.h>
#include <GL/glext.h>
#include <GL/wglext.h>
#elif defined( MACOSX )
#include "premac.h"
#include <Cocoa/Cocoa.h>
#include "postmac.h"
#elif defined( UNX )
#include <GL/glu.h>
#include <GL/glext.h>
#define GLX_GLXEXT_PROTOTYPES 1
#include <GL/glx.h>
#include <GL/glxext.h>
#endif
// Include GLM
#include <list>
#include "glm/glm.hpp"
#include "glm/gtx/transform.hpp"
#include "glm/gtx/euler_angles.hpp"
#include "glm/gtx/quaternion.hpp"
#define OPENGL_SCALE_VALUE 20
#define DEBUG_POSITIONING 0
#define RENDER_TO_FILE 0
typedef struct PosVecf3
{
float x;
float y;
float z;
}PosVecf3;
typedef std::vector<GLfloat> Line2DPointList;
typedef struct Bubble2DPointList
{
float x;
float y;
float xScale;
float yScale;
}Bubble2DPointList;
typedef struct Bubble2DCircle
{
float *pointBuf;
int bufLen;
}Bubble2DCircle;
struct RectanglePointList
{
float points[12];
};
typedef struct TextInfo
{
GLuint texture;
float x;
float y;
float z;
double rotation;
float vertex[12];
}TextInfo;
typedef std::vector<GLfloat> Area2DPointList;
typedef std::vector<GLfloat> PieSegment2DPointList;
/// Holds the information of our new child window
struct GLWindow
{
#if defined( _WIN32 )
HWND hWnd;
HDC hDC;
HGLRC hRC;
#elif defined( MACOSX )
#elif defined( UNX )
Display* dpy;
int screen;
XLIB_Window win;
#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap )
GLXFBConfig fbc;
#endif
XVisualInfo* vi;
GLXContext ctx;
bool HasGLXExtension( const char* name ) { return gluCheckExtension( (const GLubyte*) name, (const GLubyte*) GLXExtensions ); }
const char* GLXExtensions;
#endif
unsigned int bpp;
unsigned int Width;
unsigned int Height;
const GLubyte* GLExtensions;
bool HasGLExtension( const char* name ) { return gluCheckExtension( (const GLubyte*) name, GLExtensions ); }
};
class OpenGLRender
{
public:
OpenGLRender(com::sun::star::uno::Reference<
com::sun::star::drawing::XShape > xTarget );
~OpenGLRender();
int InitOpenGL(GLWindow);
int MoveModelf(PosVecf3 trans, PosVecf3 angle, PosVecf3 scale);
void SetWidth(int width);
void SetHeight(int height);
void Release();
#if RENDER_TO_FILE
int CreateBMPHeader(sal_uInt8 *bmpHeader, int xsize, int ysize);
#endif
int RenderLine2FBO(int wholeFlag);
int SetLine2DShapePoint(float x, float y, int listLength);
void SetLine2DColor(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b);
void SetLine2DWidth(int width);
BitmapEx GetAsBitmap();
#if defined( _WIN32 )
bool InitMultisample(PIXELFORMATDESCRIPTOR pfd);
#endif
bool GetMSAASupport();
int GetMSAAFormat();
void SetColor(sal_uInt32 color);
int Bubble2DShapePoint(float x, float y, float directionX, float directionY);
int RenderBubble2FBO(int wholeFlag);
void prepareToRender();
void renderToBitmap();
void SetTransparency(sal_uInt32 transparency);
int RenderRectangleShape(bool bBorder, bool bFill);
int RectangleShapePoint(float x, float y, float directionX, float directionY);
int CreateTextTexture(const BitmapEx& rBitmapEx,
com::sun::star::awt::Point aPos, com::sun::star::awt::Size aSize, long rotation,
const com::sun::star::drawing::HomogenMatrix3& rTrans);
int RenderTextShape();
int SetArea2DShapePoint(float x, float y, int listLength);
int RenderArea2DShape();
void SetChartTransparencyGradient(long transparencyGradient);
int SetPieSegment2DShapePoint(float x, float y, int listLength);
int RenderPieSegment2DShape();
#if DEBUG_POSITIONING
void renderDebug();
#endif
void SetBackGroundColor(sal_uInt32 color1, sal_uInt32 color2);
private:
GLint LoadShaders(const char *vertexShader,const char *fragmentShader);
int CreateTextureObj(int width, int height);
int CreateRenderObj(int width, int height);
int CreateFrameBufferObj();
int RenderTexture(GLuint TexID);
int RenderTexture2FBO(GLuint TexID);
#if defined( _WIN32 )
int InitTempWindow(HWND *hwnd, int width, int height, PIXELFORMATDESCRIPTOR inPfd);
bool WGLisExtensionSupported(const char *extension);
#endif
int CreateMultiSampleFrameBufObj();
int Create2DCircle(int detail);
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;
GLint m_RenderProID;
GLuint m_VertexBuffer;
GLuint m_ColorBuffer;
GLint m_MatrixID;
GLint m_VertexID;
GLint m_ColorID;
GLint m_RenderVertexID;
GLint m_RenderTexCoordID;
GLint m_Line2DVertexID;
GLint m_Line2DWholeVertexID;
GLint m_Line2DColorID;
GLint m_RenderTexID;
GLuint m_RenderVertexBuf;
GLuint m_RenderTexCoordBuf;
GLuint m_TextureObj;
GLuint m_FboID;
GLuint m_RboID;
int m_iWidth;
int m_iHeight;
GLWindow glWin;
Line2DPointList m_Line2DPointList;
float m_fLineWidth;
std::list <Line2DPointList> m_Line2DShapePointList;
com::sun::star::uno::Reference< com::sun::star::drawing::XShape > mxRenderTarget;
bool mbArbMultisampleSupported;
int m_iArbMultisampleFormat;
GLint m_iSampleBufs;
GLint m_iSamples;
glm::vec4 m_2DColor;
GLuint m_frameBufferMS;
GLuint m_renderBufferColorMS;
GLuint m_renderBufferDepthMS;
Bubble2DCircle m_Bubble2DCircle;
std::list <Bubble2DPointList> m_Bubble2DShapePointList;
GLint m_CommonProID;
GLint m_2DVertexID;
GLint m_2DColorID;
float m_fZStep;
float m_fAlpha;
std::list <RectanglePointList> m_RectangleShapePointList;
// add for text
std::list <TextInfo> m_TextInfoList;
GLint m_TextProID;
GLint m_TextMatrixID;
GLint m_TextVertexID;
GLint m_TextTexCoordID;
GLuint m_TextTexCoordBuf;
GLint m_TextTexID;
Area2DPointList m_Area2DPointList;
std::list <Area2DPointList> m_Area2DShapePointList;
GLint m_BackgroundProID;
GLint m_BackgroundMatrixID;
GLint m_BackgroundVertexID;
GLint m_BackgroundColorID;
float m_BackgroundColor[16];
glm::vec4 m_ClearColor;
PieSegment2DPointList m_PieSegment2DPointList;
std::list <PieSegment2DPointList> m_PieSegment2DShapePointList;
#if DEBUG_POSITIONING
GLuint m_DebugProID;
GLuint m_DebugVertexID;
GLuint m_DebugColorID;
#endif
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|