NAVTOR SDK  v.3.0
Software Development Kit for fast and efficient development of ECDIS, ECS and generic marine applications
gl2d_objects.h
Go to the documentation of this file.
1 #ifndef SDK_GL2D_OBJECTS_H_
11 #define SDK_GL2D_OBJECTS_H_
12 #pragma once
13 
14 #include <base/inc/platform.h>
15 #include <visualizationlayer/inc/vis_const.h>
16 
17 #include "gl_platform_includes.h"
18 
19 SDK_GL2D_BEGIN_NAMESPACE
20 
23 #if defined(SDK_GL2D_USE_WGL) // WGL based OpenGL implementation
24 __pragma(pack(push, 1))
25 struct GlCtx
26 {
27  HWND wnd;
28  HDC dc;
29  HGLRC ctx;
30 
31  GlCtx()
32  : wnd(NULL), dc(NULL), ctx(NULL)
33  {}
34  GlCtx(const HWND& wnd_, const HDC& dc_, const HGLRC& ctx_)
35  : wnd(wnd_), dc(dc_), ctx(ctx_)
36  {}
37  GlCtx(const GlCtx& context)
38  : wnd(context.wnd), dc(context.dc), ctx(context.ctx)
39  {}
40 
41  inline bool IsReady() const
42  { return ::IsWindow(wnd) && NULL != dc && NULL != ctx; }
43 
44  inline void ClearUp()
45  { wnd = NULL; dc = NULL; ctx = NULL; }
46 };
47 __pragma(pack(pop))
48 #elif defined(SDK_GL2D_USE_IMX6_EGL) // EGL based OpenGL implementation for iMX6
49 struct GlCtx
50 {
51  NativeDisplayType fb_disp; // FB display
52 
53  EGLDisplay disp;
54  EGLContext ctx;
55  EGLSurface surf;
56 
57  GlCtx()
58  : fb_disp(NULL), disp(EGL_NO_DISPLAY), ctx(EGL_NO_CONTEXT), surf(EGL_NO_SURFACE)
59  {}
60  GlCtx(const NativeDisplayType& fb_disp_, const EGLDisplay& disp_,
61  const EGLContext& ctx_, const EGLSurface& surf_)
62  : fb_disp(fb_disp_), disp(disp_), ctx(ctx_), surf(surf_)
63  {}
64  GlCtx(const GlCtx& context)
65  : fb_disp(context.fb_disp), disp(context.disp), ctx(context.ctx), surf(context.surf)
66  {}
67 
68  inline bool IsReady() const
69  {
70  return NULL != fb_disp && EGL_NO_DISPLAY != disp
71  && EGL_NO_CONTEXT != ctx && EGL_NO_SURFACE != surf;
72  }
73  inline void ClearUp()
74  {
75  fb_disp = NULL; disp = EGL_NO_DISPLAY;
76  ctx = EGL_NO_CONTEXT; surf = EGL_NO_SURFACE;
77  }
78 } __attribute__((packed));
79 #elif defined(SDK_GL2D_USE_ANDROID_EGL) // EGL based OpenGL implementation for Android
80 struct GlCtx
81 {
82  EGLDisplay disp;
83  EGLContext ctx;
84  EGLSurface surf;
85 
86  GlCtx()
87  : disp(EGL_NO_DISPLAY), ctx(EGL_NO_CONTEXT), surf(EGL_NO_SURFACE)
88  {}
89  GlCtx(const EGLDisplay& disp_, const EGLContext& ctx_, const EGLSurface& surf_)
90  : disp(disp_), ctx(ctx_), surf(surf_)
91  {}
92  GlCtx(const GlCtx& context)
93  : disp(context.disp), ctx(context.ctx), surf(context.surf)
94  {}
95 
96  inline bool IsReady() const
97  { return EGL_NO_DISPLAY != disp && EGL_NO_CONTEXT != ctx && EGL_NO_SURFACE != surf; }
98 
99  inline void ClearUp()
100  { disp = EGL_NO_DISPLAY; ctx = EGL_NO_CONTEXT; surf = EGL_NO_SURFACE; }
101 } __attribute__((packed));
102 #elif defined(SDK_GL2D_USE_EGL) // EGL based OpenGL implementation
103 struct GlCtx
104 {
105  EGLDisplay disp;
106  EGLContext ctx;
107  EGLSurface surf;
108 
109  GlCtx()
110  : disp(EGL_NO_DISPLAY), ctx(EGL_NO_CONTEXT), surf(EGL_NO_SURFACE)
111  {}
112  GlCtx(const EGLDisplay& disp_, const EGLContext& ctx_, const EGLSurface& surf_)
113  : disp(disp_), ctx(ctx_), surf(surf_)
114  {}
115  GlCtx(const GlCtx& context)
116  : disp(context.disp), ctx(context.ctx), surf(context.surf)
117  {}
118 
119  inline bool IsReady() const
120  { return EGL_NO_DISPLAY != disp && EGL_NO_CONTEXT != ctx && EGL_NO_SURFACE != surf; }
121 
122  inline void ClearUp()
123  { disp = EGL_NO_DISPLAY; ctx = EGL_NO_CONTEXT; surf = EGL_NO_SURFACE; }
124 } __attribute__((packed));
125 #elif defined(SDK_GL2D_USE_MESA) // Mesa based OpenGL implementation
126 struct GlCtx
127 {
128  OSMesaContext ctx;
129 
130  GlCtx()
131  : ctx(NULL)
132  {}
133  GlCtx(const OSMesaContext& ctx_)
134  : ctx(ctx_)
135  {}
136  GlCtx(const GlCtx& context)
137  : ctx(context.ctx)
138  {}
139 
140  inline bool IsReady() const
141  { return NULL != ctx; }
142 
143  inline void ClearUp()
144  { ctx = NULL; }
145 } __attribute__((packed));
146 #elif defined(SDK_GL2D_USE_GLX) // GLX based OpenGL implementation
147 struct GlCtx
148 {
149  Display* disp;
150  GLXContext ctx;
151  GLXPbuffer pbuffer;
152 
153  GlCtx()
154  : disp(NULL), ctx(NULL), pbuffer(0)
155  {}
156  GlCtx(Display* const disp_, const GLXContext& ctx_, const GLXPbuffer& pbuffer_)
157  : disp(disp_), ctx(ctx_), pbuffer(pbuffer_)
158  {}
159  GlCtx(const GlCtx& context)
160  : disp(context.disp), ctx(context.ctx), pbuffer(context.pbuffer)
161  {}
162 
163  inline bool IsReady() const
164  { return NULL != disp && NULL != ctx && 0 != pbuffer; }
165 
166  inline void ClearUp()
167  { disp = NULL; ctx = NULL; pbuffer = 0; }
168 } __attribute__((packed));
169 #else // Fake (unknown) OpenGL platform
170 struct GlCtx
171 {
172  const bool is_fake_opengl_platform_ready;
173 
174  GlCtx()
175  : is_fake_opengl_platform_ready(false)
176  {}
177 
178  inline bool IsReady() const
179  { return is_fake_opengl_platform_ready; }
180 
181  inline void ClearUp()
182  {}
183 };
184 #endif
185 
188 #if defined(SDK_GL2D_USE_WGL) // WGL based OpenGL implementation
189 __pragma(pack(push, 1))
190 struct GlSharedCtx
191 {
192  HGLRC ctx;
193 
194  GlSharedCtx() : ctx(NULL) {}
195  GlSharedCtx(const HGLRC& ctx_) : ctx(ctx_) {}
196  GlSharedCtx(const GlSharedCtx& shared_context) : ctx(shared_context.ctx) {}
197  GlSharedCtx(const GlCtx& context) : ctx(context.ctx) {}
198 
199  inline bool IsReady() const { return NULL != ctx; }
200 };
201 __pragma(pack(pop))
202 #elif defined(SDK_GL2D_USE_IMX6_EGL) // EGL based OpenGL implementation for iMX6
203 struct GlSharedCtx
204 {
205  NativeDisplayType fb_disp;
206  EGLDisplay disp;
207  EGLContext ctx;
208 
209  GlSharedCtx()
210  : fb_disp(NULL), disp(EGL_NO_DISPLAY), ctx(EGL_NO_CONTEXT)
211  {}
212  GlSharedCtx(const NativeDisplayType& fb_disp_,
213  const EGLDisplay& disp_, const EGLContext& ctx_)
214  : fb_disp(fb_disp_), disp(disp_), ctx(ctx_)
215  {}
216  GlSharedCtx(const GlSharedCtx& shared_context)
217  : fb_disp(shared_context.fb_disp), disp(shared_context.disp), ctx(shared_context.ctx)
218  {}
219  GlSharedCtx(const GlCtx& context)
220  : fb_disp(context.fb_disp), disp(context.disp), ctx(context.ctx)
221  {}
222 
223  inline bool IsReady() const
224  { return NULL != fb_disp && EGL_NO_DISPLAY != disp && EGL_NO_CONTEXT != ctx; }
225 } __attribute__((packed));
226 #elif defined(SDK_GL2D_USE_ANDROID_EGL) // EGL based OpenGL implementation for Android
227 struct GlSharedCtx
228 {
229  EGLContext ctx;
230 
231  GlSharedCtx() : ctx(EGL_NO_CONTEXT) {}
232  GlSharedCtx(const EGLContext& ctx_) : ctx(ctx_) {}
233  GlSharedCtx(const GlSharedCtx& shared_context) : ctx(shared_context.ctx) {}
234  GlSharedCtx(const GlCtx& context) : ctx(context.ctx) {}
235 
236  inline bool IsReady() const { return EGL_NO_CONTEXT != ctx; }
237 } __attribute__((packed));
238 #elif defined(SDK_GL2D_USE_EGL) // EGL based OpenGL implementation
239 struct GlSharedCtx
240 {
241  EGLContext ctx;
242 
243  GlSharedCtx() : ctx(EGL_NO_CONTEXT) {}
244  GlSharedCtx(const EGLContext& ctx_) : ctx(ctx_) {}
245  GlSharedCtx(const GlSharedCtx& shared_context) : ctx(shared_context.ctx) {}
246  GlSharedCtx(const GlCtx& context) : ctx(context.ctx) {}
247 
248  inline bool IsReady() const { return EGL_NO_CONTEXT != ctx; }
249 } __attribute__((packed));
250 #elif defined(SDK_GL2D_USE_MESA) // Mesa based OpenGL implementation
251 struct GlSharedCtx
252 {
253  OSMesaContext ctx;
254 
255  GlSharedCtx() : ctx(NULL) {}
256  GlSharedCtx(const OSMesaContext& ctx_) : ctx(ctx_) {}
257  GlSharedCtx(const GlSharedCtx& shared_context) : ctx(shared_context.ctx) {}
258  GlSharedCtx(const GlCtx& context) : ctx(context.ctx) {}
259 
260  inline bool IsReady() const { return NULL != ctx; }
261 } __attribute__((packed));
262 #elif defined(SDK_GL2D_USE_GLX) // GLX based OpenGL implementation
263 struct GlSharedCtx
264 {
265  GLXContext ctx;
266 
267  GlSharedCtx() : ctx(NULL) {}
268  GlSharedCtx(const GLXContext& ctx_) : ctx(ctx_) {}
269  GlSharedCtx(const GlSharedCtx& shared_context) : ctx(shared_context.ctx) {}
270  GlSharedCtx(const GlCtx& context) : ctx(context.ctx) {}
271 
272  inline bool IsReady() const { return NULL != ctx; }
273 } __attribute__((packed));
274 #else // Fake (unknown) OpenGL platform
276 {
277  const bool is_fake_opengl_shared_ctx_ready;
278 
279  GlSharedCtx()
280  : is_fake_opengl_shared_ctx_ready(false)
281  {}
282 
283  inline bool IsReady() const
284  { return is_fake_opengl_shared_ctx_ready; }
285 };
286 #endif
287 
288 SDK_GL2D_END_NAMESPACE
289 
290 #endif // SDK_GL2D_OBJECTS_H_
GlSharedCtx
Platform-specific OpenGL/ES2 context to share with.
Definition: gl2d_objects.h:275
platform.h
Describes the platform constants.
gl_platform_includes.h
Platform specific includes to use OpenGL (ES)
GlCtx
Platform-specific OpenGL/ES2 context.
Definition: gl2d_objects.h:170