… | |
… | |
14 | # find and use the first opencl device that let's us get a shared opengl context |
14 | # find and use the first opencl device that let's us get a shared opengl context |
15 | my $platform; |
15 | my $platform; |
16 | my $dev; |
16 | my $dev; |
17 | my $ctx; |
17 | my $ctx; |
18 | |
18 | |
|
|
19 | sub get_context { |
19 | for (OpenCL::platforms) { |
20 | for (OpenCL::platforms) { |
20 | $platform = $_; |
21 | $platform = $_; |
21 | for ($platform->devices) { |
22 | for ($platform->devices) { |
22 | $dev = $_; |
23 | $dev = $_; |
23 | $ctx = $platform->context ([OpenCL::GLX_DISPLAY_KHR, undef, OpenCL::GL_CONTEXT_KHR, undef], [$dev]) |
24 | $ctx = eval { $platform->context ([OpenCL::GLX_DISPLAY_KHR, undef, OpenCL::GL_CONTEXT_KHR, undef], [$dev]) } |
24 | and last; |
25 | and return; |
|
|
26 | } |
25 | } |
27 | } |
|
|
28 | |
|
|
29 | die "cannot find suitable OpenCL device\n"; |
26 | } |
30 | } |
27 | |
31 | |
28 | $ctx |
32 | get_context; |
29 | or die "cannot find suitable OpenCL device\n"; |
|
|
30 | |
33 | |
31 | print "using ", $dev->name, "\n"; |
34 | print "using ", $dev->name, "\n"; |
32 | |
35 | |
33 | my $queue = $ctx->queue ($dev); |
36 | my $queue = $ctx->queue ($dev); |
34 | |
37 | |