… | |
… | |
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); |
… | |
… | |
1220 | OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR, |
1223 | OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR, |
1221 | OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS. |
1224 | OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS. |
1222 | |
1225 | |
1223 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> |
1226 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> |
1224 | |
1227 | |
|
|
1228 | A somewhat informative thread on the flags is: |
|
|
1229 | |
|
|
1230 | L<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 | |
1227 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and |
1234 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and |
1228 | initialise it with the given data values. |
1235 | initialise it with the given data values. |
1229 | |
1236 | |