ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
(Generate patch)

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.28 by root, Thu Apr 19 13:49:33 2012 UTC vs.
Revision 1.32 by root, Thu Apr 19 19:36:24 2012 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4
5#ifdef I_DLFCN
6 #include <dlfcn.h>
7#endif
4 8
5#ifdef __APPLE__ 9#ifdef __APPLE__
6 #include <OpenCL/opencl.h> 10 #include <OpenCL/opencl.h>
7#else 11#else
8 #include <CL/opencl.h> 12 #include <CL/opencl.h>
31 35
32typedef SV *FUTURE; 36typedef SV *FUTURE;
33 37
34/*****************************************************************************/ 38/*****************************************************************************/
35 39
40// name must include a leading underscore
41// all of this horrors would be unneceesary if somebody wrote a proper OpenGL module
42// for perl. doh.
43static void *
44glsym (const char *name)
45{
46 void *fun = 0;
47
48 #if defined I_DLFCN && defined RTLD_DEFAULT
49 fun = dlsym (RTLD_DEFAULT, name + 1);
50 if (!fun) fun = dlsym (RTLD_DEFAULT, name);
51
52 if (!fun)
53 {
54 static void *libgl;
55 static const char *glso[] = {
56 "libGL.so.1",
57 "libGL.so.3",
58 "libGL.so.4.0",
59 "libGL.so",
60 "/usr/lib/libGL.so",
61 "/usr/X11R6/lib/libGL.1.dylib"
62 };
63 int i;
64
65 for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i)
66 {
67 libgl = dlopen (glso [i], RTLD_LAZY);
68 if (libgl)
69 break;
70 }
71
72 if (libgl)
73 {
74 fun = dlsym (libgl, name + 1);
75 if (!fun) fun = dlsym (libgl, name);
76 }
77 }
78 #endif
79
80 return fun;
81}
82
83/*****************************************************************************/
84
36/* up to two temporary buffers */ 85/* up to two temporary buffers */
37static void * 86static void *
38tmpbuf (size_t size) 87tmpbuf (size_t size)
39{ 88{
40 enum { buffers = 3 }; 89 enum { buffers = 3 };
154 croak ("%s: %s is not a property list (must be even number of elements)", func, svname); 203 croak ("%s: %s is not a property list (must be even number of elements)", func, svname);
155 204
156 while (extracount--) 205 while (extracount--)
157 *l++ = *extra++; 206 *l++ = *extra++;
158 207
159 for (i = 0; i < len; ++i) 208 for (i = 0; i < len; i += 2)
160 { 209 {
161 cl_context_properties t = SvIV (*av_fetch (av, i, 0)); 210 cl_context_properties t = SvIV (*av_fetch (av, i , 0));
162 cl_context_properties v; 211 SV *p_sv = *av_fetch (av, i + 1, 0);
163 212 cl_context_properties v = SvIV (p_sv); // code below can override
164 ++i;
165 213
166 switch (t) 214 switch (t)
167 { 215 {
216 case CL_GLX_DISPLAY_KHR:
217 if (!SvOK (p_sv))
218 {
219 void *func = glsym ("_glXGetCurrentDisplay");
220 if (func)
221 v = (cl_context_properties)((void *(*)(void))func)();
222 }
223 break;
224
225 case CL_GL_CONTEXT_KHR:
226 if (!SvOK (p_sv))
227 {
228 void *func = glsym ("_glXGetCurrentContext");
229 if (func)
230 v = (cl_context_properties)((void *(*)(void))func)();
231 }
232 break;
233
168 default: 234 default:
169 /* unknown property, treat as int */ 235 /* unknown property, treat as int */
170 v = SvIV (*av_fetch (av, i, 0));
171 break; 236 break;
172 } 237 }
173 238
174 *l++ = t; 239 *l++ = t;
175 *l++ = v; 240 *l++ = v;
1245void 1310void
1246gl_object_info (OpenCL::Memory self) 1311gl_object_info (OpenCL::Memory self)
1247 PPCODE: 1312 PPCODE:
1248 cl_gl_object_type type; 1313 cl_gl_object_type type;
1249 cl_GLuint name; 1314 cl_GLuint name;
1250 NEED_SUCCESS (clGetGLObjectInfo, (self, &type, &name)); 1315 NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name));
1251 EXTEND (SP, 2); 1316 EXTEND (SP, 2);
1252 PUSHs (sv_2mortal (newSVuv (type))); 1317 PUSHs (sv_2mortal (newSVuv (type)));
1253 PUSHs (sv_2mortal (newSVuv (name))); 1318 PUSHs (sv_2mortal (newSVuv (name)));
1254 1319
1255#endif 1320#endif
1300 1365
1301void 1366void
1302target (OpenCL::Image self) 1367target (OpenCL::Image self)
1303 PPCODE: 1368 PPCODE:
1304 cl_GLenum value [1]; 1369 cl_GLenum value [1];
1305 NEED_SUCCESS (GetGlTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0)); 1370 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0));
1306 EXTEND (SP, 1); 1371 EXTEND (SP, 1);
1307 const int i = 0; 1372 const int i = 0;
1308 PUSHs (sv_2mortal (newSVuv (value [i]))); 1373 PUSHs (sv_2mortal (newSVuv (value [i])));
1309 1374
1310void 1375void
1311gl_mipmap_level (OpenCL::Image self) 1376gl_mipmap_level (OpenCL::Image self)
1312 PPCODE: 1377 PPCODE:
1313 cl_GLint value [1]; 1378 cl_GLint value [1];
1314 NEED_SUCCESS (GetGlTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0)); 1379 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0));
1315 EXTEND (SP, 1); 1380 EXTEND (SP, 1);
1316 const int i = 0; 1381 const int i = 0;
1317 PUSHs (sv_2mortal (newSViv (value [i]))); 1382 PUSHs (sv_2mortal (newSViv (value [i])));
1318 1383
1319#END:gl_texture 1384#END:gl_texture

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines