CGM Objects Library
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
DrawGL.h
1 // DrawGL.h: interface for the CDrawGL class.
2 //
3 // Copyright (c) 2008-2012, Larson Software Technology, Inc.
5 
6 #if !defined(AFX_DRAWGL_H__56DE0244_F36F_49DC_A5CD_79388C983A87__INCLUDED_)
7 #define AFX_DRAWGL_H__56DE0244_F36F_49DC_A5CD_79388C983A87__INCLUDED_
8 
9 #pragma once
10 
11 //#define POLYGONTESSELATOR
12 
13 #ifdef POLYGONTESSELATOR
14 #include "Utility/PolygonTesselator.h"
15 #endif
16 
17 #ifdef WIN32
18 #include <windows.h>
19 #ifndef OpenGLESv2
20 #include <GL/gl.h>
21 #include <GL/glu.h>
22 #else
23 #include <EGL/egl.h>
24 #include <GLES2/gl2.h>
25 #include <GLES2/gl2ext.h>
26 //#include <GL/glu.h>
27 #endif
28 #endif
29 
30 #ifdef LINUX
31 #include <GL/glx.h>
32 typedef struct X11DisplayInfo {
33  Display* display;
34  Window window;
35 } X11DisplayInfo;
36 #include <GL/gl.h>
37 #include <GL/glu.h>
38 #include <GL/glx.h>
39 #endif
40 
41 #ifdef IOS
42 #include <OpenGLES/ES2/gl.h>
43 #include <OpenGLES/ES2/glext.h>
44 #include <GL/gl.h>
45 #include <GL/glu.h>
46 #endif
47 
48 #ifdef ANDROID
49 #include <EGL/egl.h>
50 #include <GLES2/gl2.h>
51 #include <GLES2/gl2ext.h>
52 //#include <glu.h>
53 //#include <gluos.h>
54 #endif
55 
56 #ifdef EMSCRIPTEN
57 #include <EGL/egl.h>
58 #include <GLES/gl.h>
59 #endif
60 
61 
62 #include "DrawBase.h"
63 
64 namespace Larson
65 {
66 
68 
74  class CDrawGL : public CDrawBase
75  {
76  public:
77 #ifndef GLPOINTF
78 #define GLPOINTF
79 typedef struct { GLfloat x, y; } GLpointf;
80 #endif
81  enum ExceptionCodes
82  {
83  eChoosePixelFmtFailed = EXC_DRAWGL,
84  eSetPixelFormatFailed = EXC_DRAWGL + 1,
85  eCreateContextFailed = EXC_DRAWGL + 2,
86  eMakeCurrentFailed = EXC_DRAWGL + 3
87  };
88  CDrawGL();
89  virtual ~CDrawGL();
90 
91 #ifdef EMSCRIPTEN
92  GLuint loadShader(GLenum type, const char *source);
93  GLuint buildProgram(GLuint vertexShader, GLuint fragmentShader, int index);
94 #endif
95 
96  void setWorkaround_GL_LINE_LOOP_bug(bool bValue);
97 
98  void drawVertexArray(GLenum mode, GLpointf *pPoints, long count);
99 
100  void setDisplay(void *pDisplay, void* pOther = 0);
101 
102  void open();
103 
104  void memoryOpen(long width, long height);
105  unsigned char* getBitmap();
106  unsigned char* getBitmapAt(int x, int y, int w, int h);
107 
108  void SelectRectangle(LPoint downPt, LPoint currPt, bool bDraw);
109  void PanScreen(LPoint nOffset, bool bDragging);
110 
111  void PreProcess(CCgmObjects*, enum ProcessFlag);
112  void PostProcess(CCgmObjects*, enum ProcessFlag);
113 
114  void setTransform(DRect *window, DRect *viewport, DRect* clientRect, double rotation, int originFlag);
116  void clear();
117  void flush();
118 
119  void close();
120 
121  //void drawRect(CCgmRect *pCgmRect);
123  void drawText(CCgmText *pCgmText);
125  void drawPoly(CCgmPoly *pCgmPoly);
127  void drawCellArray(CCgmCellArray *pCCgmCellArray);
129  void drawFigure(CCgmFigure *pCgmFigure);
131  void drawPath(CCgmBaseObj *pCgmBaseObj, Path *pPath, bool fill);
133  void eraseDCarea(DRect *rect);
134 
135  protected:
137  void drawDCline(CCgmBaseObj *pCgmBaseObj, DPoint *pCa, long cnt, bool close);
138 
140  void drawDCfill(CCgmBaseObj *pCgmBaseObj, DPoint *pCa, long cnt);
141 
143  void drawDCdots(CCgmBaseObj *pCgmBaseObj, DPoint *pCa, long cnt);
144 
145  long setLineAttr(CCgmBaseObj* pCgmBaseObj);
147  long setLineStipple(long width, GLushort pattern);
149  long setFillAttr(CCgmBaseObj* pCgmBaseObj, unsigned long rgb);
151  long setFillAttr(CCgmBaseObj* pCgmBaseObj);
153  long setFillStipple(long flag, unsigned long *stipple = NULL, CColor fore = CColor(0,0,0,255), CColor back = CColor(0,0,0,0));
155 
156  public:
157  void setColor(CColor color);
159 
160  void setMinVisibleText(double minHeight) { m_minVisibleText = minHeight; };
162 
163  protected:
165  bool applyClipping(CCgmBaseObj*, DRect*);
168 
169  double m_saveScalingFactor;
170  double m_scalingFactor;
171 
172  double m_minVisibleText;
173 
175 // unsigned char* m_pCanvasImage;
177  LRect m_selRect;
178 
179  public:
181  unsigned char* m_mem_pBitmap;
182 
183 #ifdef WIN32
184  void* m_pRC;
185 # ifndef OpenGLESv2
186  HDC m_pDisplay;
187 # else
188  HWND m_pDisplay;
189 # endif
190 #endif
191 
192 #ifdef LINUX
193  X11DisplayInfo* m_pDisplay;
194  int m_screen;
195  int m_depth;
196  Visual* m_visual;
197  GLXContext m_context;
198 #endif
199 
200 #ifdef IOS
201  // IOS
202 #endif
203 
204 #if defined(EMSCRIPTEN) || defined(ANDROID) || defined(OpenGLESv2)
205 # if defined(EMSCRIPTEN) || defined(ANDROID_GLES2) || defined(OpenGLESv2)
206 
207 # define SOLID_SHADER 0
208 # define TEX_SHADER 1
209 
210 # if defined(ANDROID_ALLNATIVE) || defined(OpenGLESv2) || defined(EMSCRIPTEN)
211  EGLint m_eglError;
212 
213  EGLDisplay m_eglDisplay;
214  EGLContext m_eglContext;
215  EGLSurface m_eglSurface;
216  EGLint m_eglWidth;
217  EGLint m_eglHeight;
218 # endif
219 
220 # endif
221  GLuint m_textures[1];
222  GLfloat m_gl2Matrix[16];
223  GLfloat m_gl2Color[4];
224 #endif
225 
226  bool m_bUseTexture;
227 
228  long m_tessFlag;
229 #ifndef ANDROID_GLUTESSELATOR_VOIDP
230 #ifdef POLYGONTESSELATOR
231  void *m_tessObj;
232 #else
233  GLUtesselator *m_tessObj;
234 #endif
235 #else
236  void *m_tessObj;
237 #endif
238 
239  bool m_workaround_GL_LINE_LOOP_bug;
240 
241  long m_currentProgram;
242 
243  GLfloat m_psRange[2];
244  GLfloat m_lwRange[2];
245 
246  int m_canvasWidth;
247  int m_canvasHeight;
248  int m_canvasID;
249 
250  GLsizei m_mem_glWidth;
251  GLsizei m_mem_glHeight;
252  GLuint m_mem_framebuffer;
253  GLuint m_mem_colorRenderbuffer;
254  GLuint m_mem_depthRenderbuffer;
255 
256 #ifdef _DEBUG
257  void checkGLError(char*, int, char*);
258 #endif
259 
260  int m_masterClipStatus; // -1 = not set, 0 = set, no valid intersection, 1 = set, valid intersection
261  DRect m_masterClipRect;
262  };
263 
264 #if defined(ANDROID) && defined(WANT_C_API)
265  extern "C" {
266  typedef struct c_CDrawGL c_CDrawGL;
267 
268  inline CDrawGL* realCDrawGL(c_CDrawGL* p) { return (CDrawGL*)p; };
269 
270  c_CDrawGL* new_CDrawGL() { return (c_CDrawGL*)(new CDrawGL()); };
271 
272  void open_CDrawGL(c_CDrawGL* p) { realCDrawGL(p)->open(); };
273 
274  void bgColorFromObjects_CDrawBase(c_CDrawGL *p, c_CCgmObjects *pObj)
275  { ((CDrawBase*)p)->m_backgroundColor = ((CCgmObjects*)pObj)->m_backgroundColor; };
276 
277  void clear_CDrawGL(c_CDrawGL* p) { realCDrawGL(p)->clear(); };
278 
279  void flush_CDrawGL(c_CDrawGL* p) { realCDrawGL(p)->flush(); };
280 
281  void close_CDrawGL(c_CDrawGL* p) { realCDrawGL(p)->close(); };
282 
283  void delete_CDrawGL(c_CDrawGL* p) { delete realCDrawGL(p); };
284 
285  void setTransform_CDrawGL(c_CDrawGL *p, c_DRect *window, c_DRect *viewport, c_DRect *clientRect,
286  double rotation, int originFlag)
287  { realCDrawGL(p)->setTransform((DRect*)window, (DRect*)viewport, (DRect*)clientRect,
288  rotation, originFlag); };
289 
290  void setMinMarkerSize_CDrawGL(c_CDrawGL *p, double s)
291  { realCDrawGL(p)->m_dMinMarkerSize = s; };
292  };
293 #endif
294 };
295 #endif // !defined(AFX_DRAWGL_H__56DE0244_F36F_49DC_A5CD_79388C983A87__INCLUDED_)
unsigned char * m_mem_pBitmap
pointer to allocated bitmap pointer returned to user - valid until close()
Definition: DrawGL.h:181
void eraseDCarea(DRect *rect)
draws a graphical path to the GL device
Definition: DrawGL.cpp:6120
void setTransform(DRect *window, DRect *viewport, DRect *clientRect, double rotation, int originFlag)
set VDC to device coordinates transform
Definition: DrawGL.cpp:1759
void flush()
fills the device with the background color
Definition: DrawGL.cpp:1944
void drawDCfill(CCgmBaseObj *pCgmBaseObj, DPoint *pCa, long cnt)
draws a filled object to the GL device
Definition: DrawGL.cpp:2117
void drawDCdots(CCgmBaseObj *pCgmBaseObj, DPoint *pCa, long cnt)
draws one or more dots to the GL device
Definition: DrawGL.cpp:2278
void unApplyClipping(CCgmBaseObj *)
remove current clipping – used internally
Definition: DrawGL.cpp:2668
unsigned char * getBitmap()
initializes GL memory drawing
Definition: DrawGL.cpp:1340
CCgmCellArray – CellArray element container class.
Definition: CgmObj.h:933
CCgmFigure – Figure and Compund Line element container class.
Definition: CgmObj.h:1110
void SelectRectangle(LPoint downPt, LPoint currPt, bool bDraw)
returns a pointer to a memory bit at x,y of w,h
Definition: DrawGL.cpp:1396
void drawPoly(CCgmPoly *pCgmPoly)
draw text to the GL device
Definition: DrawGL.cpp:3438
long setLineAttr(CCgmBaseObj *pCgmBaseObj)
apply line attributes
Definition: DrawGL.cpp:5246
long setFillAttr(CCgmBaseObj *pCgmBaseObj, unsigned long rgb)
set the current line pattern via available OpenGL calls
Definition: DrawGL.cpp:5408
void setColor(CColor color)
set the current fill pattern via available OpenGL calls
Definition: DrawGL.cpp:6345
virtual ~CDrawGL()
standard constructor
Definition: DrawGL.cpp:559
void memoryOpen(long width, long height)
initializes GL screen drawing
Definition: DrawGL.cpp:1175
void setMinVisibleText(double minHeight)
set the current color via available OpenGL calls
Definition: DrawGL.h:160
void setDisplay(void *pDisplay, void *pOther=0)
select target device
Definition: DrawGL.cpp:583
CDrawBase – drawing base class from which all output specific draw classes are derived.
Definition: DrawBase.h:19
Definition: DrawGL.h:79
void setWorkaround_GL_LINE_LOOP_bug(bool bValue)
standard destructor
Definition: DrawGL.cpp:417
void drawCellArray(CCgmCellArray *pCCgmCellArray)
draw a polygon or polyline to the GL device
Definition: DrawGL.cpp:3773
void drawText(CCgmText *pCgmText)
close the GL device
Definition: DrawGL.cpp:2730
Path – graphical path data container class.
Definition: Path.h:17
bool applyClipping(CCgmBaseObj *, DRect *)
set minimum height at which text is rendered
Definition: DrawGL.cpp:2408
long setFillStipple(long flag, unsigned long *stipple=NULL, CColor fore=CColor(0, 0, 0, 255), CColor back=CColor(0, 0, 0, 0))
sets the current fill attributes according to the pCgmBaseObj attributes
Definition: DrawGL.cpp:5581
void drawFigure(CCgmFigure *pCgmFigure)
draw a cell array to the GL device
Definition: DrawGL.cpp:4722
CCgmPoly – Poly elements container class(Polyline, PolyBezier, Polygon, Disjoint Polyline) ...
Definition: CgmObj.h:883
void drawDCline(CCgmBaseObj *pCgmBaseObj, DPoint *pCa, long cnt, bool close)
draws a line to the GL device
Definition: DrawGL.cpp:1978
CCgmBaseObj – graphical element container base class.
Definition: CgmObj.h:121
long setLineStipple(long width, GLushort pattern)
sets the current line attributes according to the pCgmBaseObj attributes
Definition: DrawGL.cpp:5378
void drawPath(CCgmBaseObj *pCgmBaseObj, Path *pPath, bool fill)
draws a CGM figure to the GL device
Definition: DrawGL.cpp:5094
CCgmText – Text and RestrictedText elements container class.
Definition: CgmObj.h:794
void close()
forces completion of all GL drawing operations
Definition: DrawGL.cpp:2311
LRect m_selRect
pointer to allocated bitmap of selectRectangle area
Definition: DrawGL.h:177
void open()
open device for drawing
Definition: DrawGL.cpp:813
unsigned char * getBitmapAt(int x, int y, int w, int h)
returns a pointer to a memory bitmap
Definition: DrawGL.cpp:1367
void clear()
sets up the transformation between the window and viewport
Definition: DrawGL.cpp:1921
CCgmObjects – CGM Picture container.
Definition: CgmObjects.h:472
CDrawGL – OpenGL drawing class.
Definition: DrawGL.h:74