-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathCL_GL.pas
270 lines (233 loc) · 9.71 KB
/
CL_GL.pas
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
(**********************************************************************************
* Copyright (c) 2008-2012 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are 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 Materials.
*
* THE MATERIALS ARE 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
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
**********************************************************************************
* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $
*
* cl_gl.h contains Khronos-approved (KHR) OpenCL extensions which have
* OpenGL dependencies. The application is responsible for #including
* OpenGL or OpenGL ES headers before #including cl_gl.h.
*)
// use dglOpenGL unit for OpenGL from http://www.delphigl.com instead of obsolete Borland OpenGL unit
// OpenCL 1.2 for Delphi 7 by Michal Pohanka: 2013-07-17.
// http://www.volny.cz/profipohanka
// OpenCL library is loaded manualy and the program will not crash
// when OpenCL is not installed.
// Check OpenCL_loaded variable to see if OpenCL is available.
// Avoid usage of Halt procedure to make sure the FINALIZATION section is executed
// some parts were inspired by porting of OpenCL 1.0 to FPC
// by Dmitry 'skalogryz' Boyarintsev: 28th apr 2009
unit CL_GL;
interface
{$INCLUDE 'CL.inc'}
uses
CL; // dglOpenGL is the latest header translation for OpenGL I found on http://www.delphigl.com
///////////////////////////////////////////////////////////////////////////////////////////////////
{cl_gl.h}
type
cl_gl_object_type = cl_uint;
cl_gl_texture_info = cl_uint;
cl_gl_platform_info = cl_uint;
__GLsync = _cl_emptyrecord;
cl_GLsync = ^__GLsync;
const
// cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken
CL_GL_OBJECT_BUFFER = $2000;
CL_GL_OBJECT_TEXTURE2D = $2001;
CL_GL_OBJECT_TEXTURE3D = $2002;
CL_GL_OBJECT_RENDERBUFFER = $2003;
CL_GL_OBJECT_TEXTURE2D_ARRAY = $200E;
CL_GL_OBJECT_TEXTURE1D = $200F;
CL_GL_OBJECT_TEXTURE1D_ARRAY = $2010;
CL_GL_OBJECT_TEXTURE_BUFFER = $2011;
// cl_gl_texture_info
CL_GL_TEXTURE_TARGET = $2004;
CL_GL_MIPMAP_LEVEL = $2005;
CL_GL_NUM_SAMPLES = $2012;
type
_t_clCreateFromGLBuffer = function ( // CL_API_SUFFIX__VERSION_1_0
context : cl_context;
falgs : cl_mem_flags;
bufobj : cl_GLuint;
errcode_ret : p_cl_int
): cl_mem; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
_t_clCreateFromGLTexture = function ( // CL_API_SUFFIX__VERSION_1_2
context: cl_context;
flags: cl_mem_flags;
target: cl_GLenum;
miplevel: cl_GLint;
texture: cl_GLuint;
errcode_ret: p_cl_int
): cl_mem; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
_t_clCreateFromGLRenderbuffer = function ( // CL_API_SUFFIX__VERSION_1_0
context : cl_context;
flags : cl_mem_flags;
renderbuffer : cl_GLuint;
errcode_ret : p_cl_int
): cl_mem; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
_t_clGetGLObjectInfo = function ( // CL_API_SUFFIX__VERSION_1_0
memobj : cl_mem;
gl_object_type : cl_gl_object_type;
gl_object_name : p_cl_GLuint
): cl_int; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
_t_clGetGLTextureInfo = function ( // CL_API_SUFFIX__VERSION_1_0
memobj : cl_mem;
param_name : cl_gl_texture_info;
param_value_size : size_t;
param_value : Pointer;
param_value_size_ret : p_size_t
): cl_int; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
_t_clEnqueueAcquireGLObjects = function ( // CL_API_SUFFIX__VERSION_1_0
command_queue : cl_command_queue;
num_objects : cl_uint;
mem_objects : p_cl_mem;
num_events_in_wait_list : cl_uint;
event_wait_list : p_cl_event;
event : p_cl_event
): cl_int; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
_t_clEnqueueReleaseGLObjects = function ( // CL_API_SUFFIX__VERSION_1_0
command_queue : cl_command_queue;
num_objects : cl_uint;
mem_objects : p_cl_mem;
num_events_in_wait_list : cl_uint;
event_wait_list : p_cl_event;
event : p_cl_event
): cl_int; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
// Deprecated OpenCL 1.1 APIs
_t_clCreateFromGLTexture2D = function ( // CL_API_SUFFIX__VERSION_1_0
context : cl_context;
flags : cl_mem_flags;
target : cl_GLenum;
miplevel : cl_GLint;
texture : cl_GLuint;
errcode_ret : p_cl_int
): cl_mem; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
_t_clCreateFromGLTexture3D = function ( // CL_API_SUFFIX__VERSION_1_0
context : cl_context;
flags : cl_mem_flags;
target : cl_GLenum;
miplevel : cl_GLint;
texture : cl_GLuint;
errcode_ret : p_cl_int
): cl_mem; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
// cl_khr_gl_sharing extension
const
cl_khr_gl_sharing = 1;
type
cl_gl_context_info = cl_uint;
const
// Additional Error Codes
CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR = -1000;
// cl_gl_context_info
CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR = $2006;
CL_DEVICES_FOR_GL_CONTEXT_KHR = $2007;
// Additional cl_context_properties
CL_GL_CONTEXT_KHR = $2008;
CL_EGL_DISPLAY_KHR = $2009;
CL_GLX_DISPLAY_KHR = $200A;
CL_WGL_HDC_KHR = $200B;
CL_CGL_SHAREGROUP_KHR = $200C;
type
_t_clGetGLContextInfoKHR = function ( // CL_API_SUFFIX__VERSION_1_0
properties : p_cl_context_properties;
param_name : cl_gl_context_info;
param_value_size : size_t;
param_value : pointer;
param_value_size_ret : p_size_t
): cl_int; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
clGetGLContextInfoKHR_fn = _t_clGetGLContextInfoKHR;
var
clCreateFromGLBuffer: _t_clCreateFromGLBuffer;
clCreateFromGLTexture: _t_clCreateFromGLTexture;
clCreateFromGLRenderbuffer: _t_clCreateFromGLRenderbuffer;
clGetGLObjectInfo: _t_clGetGLObjectInfo;
clGetGLTextureInfo: _t_clGetGLTextureInfo;
clEnqueueAcquireGLObjects: _t_clEnqueueAcquireGLObjects;
clEnqueueReleaseGLObjects: _t_clEnqueueReleaseGLObjects;
clGetGLContextInfoKHR: _t_clGetGLContextInfoKHR;
clCreateFromGLTexture2D: _t_clCreateFromGLTexture2D;
clCreateFromGLTexture3D: _t_clCreateFromGLTexture3D;
///////////////////////////////////////////////////////////////////////////////////////////////////
{cl_gl_ext.h}
(*
* For each extension, follow this template
* /* cl_VEN_extname extension */
* #define cl_VEN_extname 1
* ... define new types, if any
* ... define new tokens, if any
* ... define new APIs, if any
*
* If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header
* This allows us to avoid having to decide whether to include GL headers or GLES here.
*
* cl_khr_gl_event extension
* See section 9.9 in the OpenCL 1.1 spec for more information
*)
const
CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR = $200D;
type
_t_clCreateEventFromGLsyncKHR = function ( // CL_EXT_SUFFIX__VERSION_1_1
context : cl_context;
cl_GLsync : cl_GLsync;
errcode_ret : p_cl_int
): cl_event; {$IFDEF CDECL}cdecl{$ELSE}stdcall{$ENDIF};
var
clCreateEventFromGLsyncKHR: _t_clCreateEventFromGLsyncKHR;
///////////////////////////////////////////////////////////////////////////////////////////////////
// Delphi functions
procedure LoadOpenCL_GL; // Call after CL.LoadOpenCL
procedure UnloadOpenCL_GL;
IMPLEMENTATION
procedure LoadOpenCL_GL; // Call after CL.LoadOpenCL
begin
// Load API functions
@clCreateFromGLBuffer:=GetOpenCLFuncAddress('clCreateFromGLBuffer');
@clCreateFromGLTexture:=GetOpenCLFuncAddress('clCreateFromGLTexture');
@clCreateFromGLRenderbuffer:=GetOpenCLFuncAddress('clCreateFromGLRenderbuffer');
@clGetGLObjectInfo:=GetOpenCLFuncAddress('clGetGLObjectInfo');
@clGetGLTextureInfo:=GetOpenCLFuncAddress('clGetGLTextureInfo');
@clEnqueueAcquireGLObjects:=GetOpenCLFuncAddress('clEnqueueAcquireGLObjects');
@clEnqueueReleaseGLObjects:=GetOpenCLFuncAddress('clEnqueueReleaseGLObjects');
@clGetGLContextInfoKHR:=GetOpenCLFuncAddress('clGetGLContextInfoKHR');
@clCreateEventFromGLsyncKHR:=GetOpenCLFuncAddress('clCreateEventFromGLsyncKHR');
@clCreateFromGLTexture2D:=GetOpenCLFuncAddress('clCreateFromGLTexture2D');
@clCreateFromGLTexture3D:=GetOpenCLFuncAddress('clCreateFromGLTexture3D');
end;
procedure UnloadOpenCL_GL;
begin
// Load API functions
@clCreateFromGLBuffer:=nil;
@clCreateFromGLTexture:=nil;
@clCreateFromGLRenderbuffer:=nil;
@clGetGLObjectInfo:=nil;
@clGetGLTextureInfo:=nil;
@clEnqueueAcquireGLObjects:=nil;
@clEnqueueReleaseGLObjects:=nil;
@clGetGLContextInfoKHR:=nil;
@clCreateEventFromGLsyncKHR:=nil;
@clCreateFromGLTexture2D:=nil;
@clCreateFromGLTexture3D:=nil;
end;
INITIALIZATION
LoadOpenCL_GL;
FINALIZATION
UnloadOpenCL_GL;
END.