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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2011 the Open Toolkit library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#endregion
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;
namespace Crow.Linux
{
using EGLNativeDisplayType = IntPtr;
using EGLNativeWindowType = IntPtr;
using EGLNativePixmapType = IntPtr;
using EGLConfig = IntPtr;
using EGLContext = IntPtr;
using EGLDisplay = IntPtr;
using EGLSurface = IntPtr;
using EGLClientBuffer = IntPtr;
enum RenderApi
{
ES = Egl.OPENGL_ES_API,
GL = Egl.OPENGL_API,
VG = Egl.OPENVG_API
}
[Flags]enum RenderableFlags
{
ES = Egl.OPENGL_ES_BIT,
ES2 = Egl.OPENGL_ES2_BIT,
ES3 = Egl.OPENGL_ES3_BIT,
GL = Egl.OPENGL_BIT,
VG = Egl.OPENVG_BIT,
}
public enum ErrorCode
{
SUCCESS = 12288,
NOT_INITIALIZED = 12289,
BAD_ACCESS = 12290,
BAD_ALLOC = 12291,
BAD_ATTRIBUTE = 12292,
BAD_CONFIG = 12293,
BAD_CONTEXT = 12294,
BAD_CURRENT_SURFACE = 12295,
BAD_DISPLAY = 12296,
BAD_MATCH = 12297,
BAD_NATIVE_PIXMAP = 12298,
BAD_NATIVE_WINDOW = 12299,
BAD_PARAMETER = 12300,
BAD_SURFACE = 12301,
CONTEXT_LOST = 12302,
}
static partial class Egl
{
public const int VERSION_1_0 = 1;
public const int VERSION_1_1 = 1;
public const int VERSION_1_2 = 1;
public const int VERSION_1_3 = 1;
public const int VERSION_1_4 = 1;
public const int FALSE = 0;
public const int TRUE = 1;
public const int DONT_CARE = -1;
public const int CONTEXT_LOST = 12302;
public const int BUFFER_SIZE = 12320;
public const int ALPHA_SIZE = 12321;
public const int BLUE_SIZE = 12322;
public const int GREEN_SIZE = 12323;
public const int RED_SIZE = 12324;
public const int DEPTH_SIZE = 12325;
public const int STENCIL_SIZE = 12326;
public const int CONFIG_CAVEAT = 12327;
public const int CONFIG_ID = 12328;
public const int LEVEL = 12329;
public const int MAX_PBUFFER_HEIGHT = 12330;
public const int MAX_PBUFFER_PIXELS = 12331;
public const int MAX_PBUFFER_WIDTH = 12332;
public const int NATIVE_RENDERABLE = 12333;
public const int NATIVE_VISUAL_ID = 12334;
public const int NATIVE_VISUAL_TYPE = 12335;
public const int PRESERVED_RESOURCES = 12336;
public const int SAMPLES = 12337;
public const int SAMPLE_BUFFERS = 12338;
public const int SURFACE_TYPE = 12339;
public const int TRANSPARENT_TYPE = 12340;
public const int TRANSPARENT_BLUE_VALUE = 12341;
public const int TRANSPARENT_GREEN_VALUE = 12342;
public const int TRANSPARENT_RED_VALUE = 12343;
public const int NONE = 12344;
public const int BIND_TO_TEXTURE_RGB = 12345;
public const int BIND_TO_TEXTURE_RGBA = 12346;
public const int MIN_SWAP_INTERVAL = 12347;
public const int MAX_SWAP_INTERVAL = 12348;
public const int LUMINANCE_SIZE = 12349;
public const int ALPHA_MASK_SIZE = 12350;
public const int COLOR_BUFFER_TYPE = 12351;
public const int RENDERABLE_TYPE = 12352;
public const int MATCH_NATIVE_PIXMAP = 12353;
public const int CONFORMANT = 12354;
public const int SLOW_CONFIG = 12368;
public const int NON_CONFORMANT_CONFIG = 12369;
public const int TRANSPARENT_RGB = 12370;
public const int RGB_BUFFER = 12430;
public const int LUMINANCE_BUFFER = 12431;
public const int NO_TEXTURE = 12380;
public const int TEXTURE_RGB = 12381;
public const int TEXTURE_RGBA = 12382;
public const int TEXTURE_2D = 12383;
public const int PBUFFER_BIT = 1;
public const int PIXMAP_BIT = 2;
public const int WINDOW_BIT = 4;
public const int VG_COLORSPACE_LINEAR_BIT = 32;
public const int VG_ALPHA_FORMAT_PRE_BIT = 64;
public const int MULTISAMPLE_RESOLVE_BOX_BIT = 512;
public const int SWAP_BEHAVIOR_PRESERVED_BIT = 1024;
public const int OPENGL_ES_BIT = 1;
public const int OPENVG_BIT = 2;
public const int OPENGL_ES2_BIT = 4;
public const int OPENGL_BIT = 8;
public const int OPENGL_ES3_BIT = 64;
public const int VENDOR = 12371;
public const int VERSION = 12372;
public const int EXTENSIONS = 12373;
public const int CLIENT_APIS = 12429;
public const int HEIGHT = 12374;
public const int WIDTH = 12375;
public const int LARGEST_PBUFFER = 12376;
public const int TEXTURE_FORMAT = 12416;
public const int TEXTURE_TARGET = 12417;
public const int MIPMAP_TEXTURE = 12418;
public const int MIPMAP_LEVEL = 12419;
public const int RENDER_BUFFER = 12422;
public const int VG_COLORSPACE = 12423;
public const int VG_ALPHA_FORMAT = 12424;
public const int HORIZONTAL_RESOLUTION = 12432;
public const int VERTICAL_RESOLUTION = 12433;
public const int PIXEL_ASPECT_RATIO = 12434;
public const int SWAP_BEHAVIOR = 12435;
public const int MULTISAMPLE_RESOLVE = 12441;
public const int BACK_BUFFER = 12420;
public const int SINGLE_BUFFER = 12421;
public const int VG_COLORSPACE_sRGB = 12425;
public const int VG_COLORSPACE_LINEAR = 12426;
public const int VG_ALPHA_FORMAT_NONPRE = 12427;
public const int VG_ALPHA_FORMAT_PRE = 12428;
public const int DISPLAY_SCALING = 10000;
public const int UNKNOWN = -1;
public const int BUFFER_PRESERVED = 12436;
public const int BUFFER_DESTROYED = 12437;
public const int OPENVG_IMAGE = 12438;
public const int CONTEXT_CLIENT_TYPE = 12439;
public const int CONTEXT_CLIENT_VERSION = 12440;
public const int MULTISAMPLE_RESOLVE_DEFAULT = 12442;
public const int MULTISAMPLE_RESOLVE_BOX = 12443;
public const int OPENGL_ES_API = 12448;
public const int OPENVG_API = 12449;
public const int OPENGL_API = 12450;
public const int DRAW = 12377;
public const int READ = 12378;
public const int CORE_NATIVE_ENGINE = 12379;
public const int COLORSPACE = VG_COLORSPACE;
public const int ALPHA_FORMAT = VG_ALPHA_FORMAT;
public const int COLORSPACE_sRGB = VG_COLORSPACE_sRGB;
public const int COLORSPACE_LINEAR = VG_COLORSPACE_LINEAR;
public const int ALPHA_FORMAT_NONPRE = VG_ALPHA_FORMAT_NONPRE;
public const int ALPHA_FORMAT_PRE = VG_ALPHA_FORMAT_PRE;
// EGL_ANGLE_d3d_share_handle_client_buffer
public const int D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE = 0x3200;
// EGL_ANGLE_window_fixed_size
public const int FIXED_SIZE_ANGLE = 0x3201;
// EGL_ANGLE_query_surface_pointer
[DllImport("libEGL.dll", EntryPoint = "eglQuerySurfacePointerANGLE")]
public static extern bool QuerySurfacePointerANGLE(EGLDisplay display, EGLSurface surface, int attribute, out IntPtr value);
// EGL_ANGLE_software_display
public static readonly EGLNativeDisplayType SOFTWARE_DISPLAY_ANGLE = new EGLNativeDisplayType(-1);
// EGL_ANGLE_direct3d_display
public static readonly EGLNativeDisplayType D3D11_ELSE_D3D9_DISPLAY_ANGLE = new EGLNativeDisplayType(-2);
public static readonly EGLNativeDisplayType D3D11_ONLY_DISPLAY_ANGLE = new EGLNativeDisplayType(-3);
// EGL_ANGLE_device_d3d
public const int D3D9_DEVICE_ANGLE = 0x33A0;
public const int D3D11_DEVICE_ANGLE = 0x33A1;
// EGL_ANGLE_platform_angle
public const int PLATFORM_ANGLE_ANGLE = 0x3202;
public const int PLATFORM_ANGLE_TYPE_ANGLE = 0x3203;
public const int PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE = 0x3204;
public const int PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE = 0x3205;
public const int PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE = 0x3206;
// EGL_ANGLE_platform_angle_d3d
public const int PLATFORM_ANGLE_TYPE_D3D9_ANGLE = 0x3207;
public const int PLATFORM_ANGLE_TYPE_D3D11_ANGLE = 0x3208;
public const int PLATFORM_ANGLE_DEVICE_TYPE_ANGLE = 0x3209;
public const int PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE = 0x320A;
public const int PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE = 0x320B;
public const int PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE_ANGLE = 0x320C;
public const int PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE = 0x320F;
// EGL_ANGLE_platform_angle_opengl
public const int PLATFORM_ANGLE_TYPE_OPENGL_ANGLE = 0x320D;
public const int PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE = 0x320E;
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetError")]
public static extern ErrorCode GetError();
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetDisplay")]
public static extern EGLDisplay GetDisplay(EGLNativeDisplayType display_id);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglInitialize")]
//[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool Initialize(EGLDisplay dpy, out int major, out int minor);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglTerminate")]
//[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool Terminate(EGLDisplay dpy);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglQueryString")]
public static extern IntPtr QueryString(EGLDisplay dpy, int name);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetConfigs")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool GetConfigs(EGLDisplay dpy, EGLConfig[] configs, int config_size, out int num_config);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglChooseConfig")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool ChooseConfig(EGLDisplay dpy, int[] attrib_list, [In, Out] EGLConfig[] configs, int config_size, out int num_config);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetConfigAttrib")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool GetConfigAttrib(EGLDisplay dpy, EGLConfig config, int attribute, out int value);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglCreateWindowSurface")]
public static extern EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, IntPtr win, IntPtr attrib_list);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglCreatePbufferSurface")]
public static extern EGLSurface CreatePbufferSurface(EGLDisplay dpy, EGLConfig config, int[] attrib_list);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglCreatePixmapSurface")]
public static extern EGLSurface CreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, int[] attrib_list);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglDestroySurface")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool DestroySurface(EGLDisplay dpy, EGLSurface surface);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglQuerySurface")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool QuerySurface(EGLDisplay dpy, EGLSurface surface, int attribute, out int value);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglBindAPI")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool BindAPI(RenderApi api);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglQueryAPI")]
public static extern int QueryAPI();
[DllImportAttribute("libEGL.dll", EntryPoint = "eglWaitClient")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool WaitClient();
[DllImportAttribute("libEGL.dll", EntryPoint = "eglReleaseThread")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool ReleaseThread();
[DllImportAttribute("libEGL.dll", EntryPoint = "eglCreatePbufferFromClientBuffer")]
public static extern EGLSurface CreatePbufferFromClientBuffer(EGLDisplay dpy, int buftype, EGLClientBuffer buffer, EGLConfig config, int[] attrib_list);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglSurfaceAttrib")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool SurfaceAttrib(EGLDisplay dpy, EGLSurface surface, int attribute, int value);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglBindTexImage")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool BindTexImage(EGLDisplay dpy, EGLSurface surface, int buffer);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglReleaseTexImage")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, int buffer);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglSwapInterval")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool SwapInterval(EGLDisplay dpy, int interval);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglCreateContext")]
static extern IntPtr eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, int[] attrib_list);
public static EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, int[] attrib_list)
{
IntPtr ptr = eglCreateContext(dpy, config, share_context, attrib_list);
if (ptr == IntPtr.Zero)
throw new Exception(String.Format("Failed to create EGL context, error: {0}.", GetError()));
return ptr;
}
[DllImportAttribute("libEGL.dll", EntryPoint = "eglDestroyContext")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool DestroyContext(EGLDisplay dpy, EGLContext ctx);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglMakeCurrent")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetCurrentContext")]
public static extern EGLContext GetCurrentContext();
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetCurrentSurface")]
public static extern EGLSurface GetCurrentSurface(int readdraw);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetCurrentDisplay")]
public static extern EGLDisplay GetCurrentDisplay();
[DllImportAttribute("libEGL.dll", EntryPoint = "eglQueryContext")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool QueryContext(EGLDisplay dpy, EGLContext ctx, int attribute, out int value);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglWaitGL")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool WaitGL();
[DllImportAttribute("libEGL.dll", EntryPoint = "eglWaitNative")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool WaitNative(int engine);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglSwapBuffers")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool SwapBuffers(EGLDisplay dpy, EGLSurface surface);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglCopyBuffers")]
[return: MarshalAsAttribute(UnmanagedType.I1)]
public static extern bool CopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetProcAddress")]
public static extern IntPtr GetProcAddress(string funcname);
[DllImportAttribute("libEGL.dll", EntryPoint = "eglGetProcAddress")]
public static extern IntPtr GetProcAddress(IntPtr funcname);
// EGL_EXT_platform_base
[DllImport("libEGL.dll", EntryPoint = "eglGetPlatformDisplayEXT")]
public static extern EGLDisplay GetPlatformDisplayEXT(int platform, EGLNativeDisplayType native_display, int[] attrib_list);
[DllImport("libEGL.dll", EntryPoint = "eglCreatePlatformWindowSurfaceEXT")]
public static extern EGLSurface CreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType native_window, int[] attrib_list);
[DllImport("libEGL.dll", EntryPoint = "eglCreatePlatformPixmapSurfaceEXT")]
public static extern EGLSurface CreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType native_pixmap, int[] attrib_list);
// Returns true if Egl drivers exist on the system.
public static bool IsSupported
{
get
{
try { GetCurrentContext(); }
catch (Exception) { return false; }
return true;
}
}
}
#pragma warning restore 0169
}
|