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

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.87 by root, Mon May 7 01:01:33 2012 UTC vs.
Revision 1.88 by root, Tue Oct 22 17:25:38 2013 UTC

232 # find and use the first opencl device that let's us get a shared opengl context 232 # find and use the first opencl device that let's us get a shared opengl context
233 my $platform; 233 my $platform;
234 my $dev; 234 my $dev;
235 my $ctx; 235 my $ctx;
236 236
237 sub get_context {
237 for (OpenCL::platforms) { 238 for (OpenCL::platforms) {
238 $platform = $_; 239 $platform = $_;
239 for ($platform->devices) { 240 for ($platform->devices) {
240 $dev = $_; 241 $dev = $_;
241 $ctx = $platform->context ([OpenCL::GLX_DISPLAY_KHR, undef, OpenCL::GL_CONTEXT_KHR, undef], [$dev]) 242 $ctx = eval { $platform->context ([OpenCL::GLX_DISPLAY_KHR, undef, OpenCL::GL_CONTEXT_KHR, undef], [$dev]) }
242 and last; 243 and return;
244 }
243 } 245 }
246
247 die "cannot find suitable OpenCL device\n";
244 } 248 }
245 249
246 $ctx 250 get_context;
247 or die "cannot find suitable OpenCL device\n";
248 251
249 my $queue = $ctx->queue ($dev); 252 my $queue = $ctx->queue ($dev);
250 253
251 # now attach an opencl image2d object to the opengl texture 254 # now attach an opencl image2d object to the opengl texture
252 my $tex = $ctx->gl_texture2d (OpenCL::MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, $texid); 255 my $tex = $ctx->gl_texture2d (OpenCL::MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, $texid);
1220OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR, 1223OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR,
1221OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS. 1224OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS.
1222 1225
1223L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> 1226L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html>
1224 1227
1228A somewhat informative thread on the flags is:
1229
1230L<http://www.khronos.org/message_boards/viewtopic.php?f=28&t=2440>
1231
1225=item $buf = $ctx->buffer_sv ($flags, $data) 1232=item $buf = $ctx->buffer_sv ($flags, $data)
1226 1233
1227Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and 1234Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and
1228initialise it with the given data values. 1235initialise it with the given data values.
1229 1236

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines