summaryrefslogtreecommitdiffstats
path: root/src/openclgl/qclcontextgl.cpp
blob: 53bcbb5ca198014f32af540e20eac82c3cca48dc (plain)
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtOpenCL module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qclcontextgl.h"
#include "qcl_gl_p.h"
#include <QtCore/qdebug.h>
#include <QtCore/qvarlengtharray.h>

#if !defined(QT_NO_CL_OPENGL)
#if defined(QT_OPENGL_ES_2)
#include <EGL/egl.h>
#elif defined(QT_OPENGL_ES)
#include <GLES/egl.h>
#elif defined(Q_WS_X11)
#include <GL/glx.h>
#endif
#endif

QT_BEGIN_NAMESPACE

/*!
    \class QCLContextGL
    \brief The QCLContextGL class represents an OpenCL context that is suitable for use with OpenGL objects.
    \since 4.7
    \ingroup openclgl
*/

class QCLContextGLPrivate
{
public:
    QCLContextGLPrivate()
        : supportsSharing(false)
    {
    }

    bool supportsSharing;
};

/*!
    Constructs a new OpenCL context object that is suitable for use
    with OpenGL objects.
*/
QCLContextGL::QCLContextGL()
    : QCLContext(), d_ptr(new QCLContextGLPrivate())
{
}

/*!
    Destroys this OpenCL context.
*/
QCLContextGL::~QCLContextGL()
{
}

extern "C" {

static void qt_clgl_context_notify(const char *errinfo,
                                   const void *private_info,
                                   size_t cb,
                                   void *user_data)
{
    Q_UNUSED(private_info);
    Q_UNUSED(cb);
    Q_UNUSED(user_data);
    qWarning() << "OpenCL/GL context notification: " << errinfo;
}

};

#if !defined(CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR)
#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006
#endif

#if !defined(CL_DEVICES_FOR_GL_CONTEXT_KHR)
#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007
#endif

#if !defined(CL_GL_CONTEXT_KHR)
#define CL_GL_CONTEXT_KHR           0x2008
#define CL_EGL_DISPLAY_KHR          0x2009
#define CL_GLX_DISPLAY_KHR          0x200A
#define CL_WGL_HDC_KHR              0x200B
#define CL_CGL_SHAREGROUP_KHR       0x200C
#endif

/*!
    Creates an OpenCL context that is compatible with the current
    QGLContext and \a platform.  Returns false if there is no OpenGL
    context current or the OpenCL context could not be created for
    some reason.

    This function will first try to create a QCLDevice::GPU device,
    and will then fall back to QCLDevice::Default if a GPU is not found.

    If \a platform is null, then the first platform that has a GPU
    will be used.  If there is no GPU, then the first platform with a
    default device will be used.

    \sa supportsObjectSharing()
*/
bool QCLContextGL::create(const QCLPlatform &platform)
{
    Q_D(QCLContextGL);

    // Bail out if the context already exists.
    if (isCreated())
        return true;

    // Bail out if we don't have an OpenGL context.
    if (!QGLContext::currentContext()) {
        qWarning() << "QCLContextGL::create: needs a current GL context";
        setLastError(CL_INVALID_CONTEXT);
        return false;
    }

    // Find the first gpu device.
    QList<QCLDevice> devices;
    cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
    devices = QCLDevice::devices(QCLDevice::GPU, platform);
    if (devices.isEmpty()) {
        // Find the first default device.
        devices = QCLDevice::devices(QCLDevice::Default, platform);
        deviceType = CL_DEVICE_TYPE_DEFAULT;
    }
    if (devices.isEmpty()) {
        qWarning() << "QCLContextGL::create: no gpu devices found";
        setLastError(CL_DEVICE_NOT_FOUND);
        return false;
    }
    QCLDevice gpu = devices[0];
    QVarLengthArray<cl_device_id> devs;
    foreach (QCLDevice dev, devices)
        devs.append(dev.deviceId());

    // Add the platform identifier to the properties.
    QVarLengthArray<cl_context_properties> properties;
    properties.append(CL_CONTEXT_PLATFORM);
    properties.append(cl_context_properties(gpu.platform().platformId()));

    bool hasSharing = false;
#ifndef QT_NO_CL_OPENGL
    // Determine what kind of OpenCL-OpenGL sharing we have and enable it.
#if defined(__APPLE__) || defined(__MACOSX)
    bool appleSharing = gpu.hasExtension("cl_apple_gl_sharing");
    if (appleSharing) {
        CGLContextObj cglContext = CGLGetCurrentContext();
        CGLShareGroupObj cglShareGroup = CGLGetShareGroup(cglContext);
        properties.append(CL_CGL_SHAREGROUP_KHR);
        properties.append(cl_context_properties(cglShareGroup));
        hasSharing = true;
    }
#else
    bool khrSharing = gpu.hasExtension("cl_khr_gl_sharing");
#if defined(QT_OPENGL_ES_2) || defined(QT_OPENGL_ES)
    if (khrSharing) {
        properties.append(CL_EGL_DISPLAY_KHR);
        properties.append(cl_context_properties(eglGetCurrentDisplay()));
#ifdef EGL_OPENGL_ES_API
        eglBindAPI(EGL_OPENGL_ES_API);
#endif
        properties.append(CL_GL_CONTEXT_KHR);
        properties.append(cl_context_properties(eglGetCurrentContext()));
        hasSharing = true;
    }
#elif defined(Q_WS_X11)
    if (khrSharing) {
        properties.append(CL_GLX_DISPLAY_KHR);
        properties.append(cl_context_properties(glXGetCurrentDisplay()));
        properties.append(CL_GL_CONTEXT_KHR);
        properties.append(cl_context_properties(glXGetCurrentContext()));
        hasSharing = true;
    }
#else
    // Needs to be ported to other platforms.
    if (khrSharing)
        qWarning() << "QCLContextGL::create: do not know how to enable sharing";
#endif
#endif
#endif // !QT_NO_CL_OPENGL
    properties.append(0);

#ifndef QT_NO_CL_OPENGL
    // Query the actual OpenCL devices we should use with the OpenGL context.
    typedef cl_int (*q_PFNCLGETGLCONTEXTINFOKHR)
        (const cl_context_properties *, cl_uint, size_t, void *, size_t *);
    q_PFNCLGETGLCONTEXTINFOKHR getGLContextInfo =
        (q_PFNCLGETGLCONTEXTINFOKHR)clGetExtensionFunctionAddress
            ("clGetGLContextInfoKHR");
    if (getGLContextInfo && hasSharing) {
        size_t size;
        cl_device_id currentDev;
        if(getGLContextInfo(properties.data(),
                            CL_DEVICES_FOR_GL_CONTEXT_KHR,
                            0, 0, &size) == CL_SUCCESS && size > 0) {
            QVarLengthArray<cl_device_id> buf(size / sizeof(cl_device_id));
            getGLContextInfo(properties.data(),
                             CL_DEVICES_FOR_GL_CONTEXT_KHR,
                             size, buf.data(), 0);
            devs = buf;
            gpu = QCLDevice(devs[0]);
        }
        if (getGLContextInfo(properties.data(),
                             CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,
                             sizeof(currentDev), &currentDev, 0)
                == CL_SUCCESS) {
            gpu = QCLDevice(currentDev);
        }
    }
#endif

    // Create the OpenCL context.
    cl_context id;
    cl_int error;
    id = clCreateContext
        (properties.data(), devs.size(), devs.data(),
         qt_clgl_context_notify, 0, &error);
    if (!id && hasSharing) {
        // Try again without the sharing parameters.
        properties.resize(2);
        properties.append(0);
        hasSharing = false;
        id = clCreateContext
            (properties.data(), devs.size(), devs.data(),
             qt_clgl_context_notify, 0, &error);
    }
    setLastError(error);
    if (id == 0) {
        qWarning() << "QCLContextGL::create:" << errorName(error);
        d->supportsSharing = false;
    } else {
        setContextId(id);
        clReleaseContext(id);   // setContextId() adds an extra reference.
        setDefaultDevice(gpu);
        d->supportsSharing = hasSharing;
    }
    return id != 0;
}

/*!
    \reimp
*/
void QCLContextGL::release()
{
    Q_D(QCLContextGL);
    d->supportsSharing = false;
    QCLContext::release();
}

/*!
    Returns true if this OpenCL context supports object sharing
    with OpenGL; false otherwise.

    \sa createGLBuffer(), createTexture2D(), createTexture3D()
    \sa createRenderbuffer()
*/
bool QCLContextGL::supportsObjectSharing() const
{
    Q_D(const QCLContextGL);
    return d->supportsSharing;
}

/*!
    Creates an OpenCL memory buffer from the OpenGL buffer object
    \a bufobj, with the specified \a access mode.

    This function will only work if supportsObjectSharing() is true.
*/
QCLBuffer QCLContextGL::createGLBuffer(GLuint bufobj, QCLMemoryObject::Access access)
{
#ifndef QT_NO_CL_OPENGL
    cl_int error = CL_INVALID_CONTEXT;
    cl_mem_flags flags = cl_mem_flags(access);
    cl_mem mem = clCreateFromGLBuffer
        (contextId(), flags, bufobj, &error);
    reportError("QCLContextGL::createGLBuffer:", error);
    if (mem)
        return QCLBuffer(this, mem);
    else
        return QCLBuffer();
#else
    Q_UNUSED(bufobj);
    Q_UNUSED(access);
    reportError("QCLContextGL::createGLBuffer:", CL_INVALID_VALUE);
    return QCLBuffer();
#endif
}

#if QT_VERSION >= 0x040700 || defined(Q_QDOC)

/*!
    \overload

    Creates an OpenCL memory buffer from the OpenGL buffer object
    \a bufobj, with the specified \a access mode.

    This function will only work if supportsObjectSharing() is true.
*/
QCLBuffer QCLContextGL::createGLBuffer(QGLBuffer *bufobj, QCLMemoryObject::Access access)
{
    if (!bufobj)
        return QCLBuffer();
    return createGLBuffer(GLuint(bufobj->bufferId()), access);
}

#endif

/*!
    Creates a 2D OpenCL image object from the specified \a mipmapLevel,
    OpenGL \a texture object, and \a access mode.

    The \a type must be one of \c{GL_TEXTURE_2D},
    \c{GL_TEXTURE_CUBE_MAP_POSITIVE_X}, \c{GL_TEXTURE_CUBE_MAP_POSITIVE_Y},
    \c{GL_TEXTURE_CUBE_MAP_POSITIVE_Z}, \c{GL_TEXTURE_CUBE_MAP_NEGATIVE_X},
    \c{GL_TEXTURE_CUBE_MAP_NEGATIVE_Y}, \c{GL_TEXTURE_CUBE_MAP_NEGATIVE_Z},
    or \c{GL_TEXTURE_RECTANGLE}.  The \a texture does not need to be
    bound to an OpenGL texture target.

    This function will only work if supportsObjectSharing() is true.

    \sa createTexture3D(), createRenderbuffer()
*/
QCLImage2D QCLContextGL::createTexture2D
    (GLenum type, GLuint texture, GLint mipmapLevel, QCLMemoryObject::Access access)
{
#ifndef QT_NO_CL_OPENGL
    cl_int error = CL_INVALID_CONTEXT;
    cl_mem_flags flags = cl_mem_flags(access);
    cl_mem mem = clCreateFromGLTexture2D
        (contextId(), flags, type, mipmapLevel, texture, &error);
    reportError("QCLContextGL::createGLTexture2D:", error);
    if (mem)
        return QCLImage2D(this, mem);
    else
        return QCLImage2D();
#else
    Q_UNUSED(type);
    Q_UNUSED(texture);
    Q_UNUSED(mipmapLevel);
    Q_UNUSED(access);
    reportError("QCLContextGL::createGLTexture2D:", CL_INVALID_VALUE);
    return QCLImage2D();
#endif
}

/*!
    \overload

    Creates a 2D OpenCL image object from the specified OpenGL
    \a texture object, and the \a access mode.  If texture type is
    assumed to be \c{GL_TEXTURE_2D} and the mipmap level is
    assumed to be 0.

    This function will only work if supportsObjectSharing() is true.
*/
QCLImage2D QCLContextGL::createTexture2D(GLuint texture, QCLMemoryObject::Access access)
{
    return createTexture2D(GL_TEXTURE_2D, texture, 0, access);
}

#ifndef GL_TEXTURE_3D
#define GL_TEXTURE_3D 0x806F
#endif

/*!
    Creates a 3D OpenCL image object from the specified \a mipmapLevel,
    OpenGL \a texture object, and \a access mode.

    The \a type must be \c{GL_TEXTURE_3D}.  The \a texture does not need
    to be bound to an OpenGL texture target.

    This function will only work if supportsObjectSharing() is true.

    \sa createTexture2D()
*/
QCLImage3D QCLContextGL::createTexture3D
    (GLenum type, GLuint texture, GLint mipmapLevel, QCLMemoryObject::Access access)
{
#ifndef QT_NO_CL_OPENGL
    cl_int error = CL_INVALID_CONTEXT;
    cl_mem_flags flags = cl_mem_flags(access);
    cl_mem mem = clCreateFromGLTexture3D
        (contextId(), flags, type, mipmapLevel, texture, &error);
    reportError("QCLContextGL::createGLTexture3D:", error);
    if (mem)
        return QCLImage3D(this, mem);
    else
        return QCLImage3D();
#else
    Q_UNUSED(type);
    Q_UNUSED(texture);
    Q_UNUSED(mipmapLevel);
    Q_UNUSED(access);
    reportError("QCLContextGL::createGLTexture3D:", CL_INVALID_VALUE);
    return QCLImage3D();
#endif
}

/*!
    \overload

    Creates a 3D OpenCL image object from the specified OpenGL
    \a texture object, and \a access mode.  If texture type is
    assumed to be \c{GL_TEXTURE_3D} and the mipmap level is
    assumed to be 0.

    This function will only work if supportsObjectSharing() is true.
*/
QCLImage3D QCLContextGL::createTexture3D(GLuint texture, QCLMemoryObject::Access access)
{
    return createTexture3D(GL_TEXTURE_3D, texture, 0, access);
}

/*!
    Creates a 2D OpenCL image object from the specified OpenGL
    \a renderbuffer object, and the \a access mode.

    This function will only work if supportsObjectSharing() is true.

    \sa createTexture2D()
*/
QCLImage2D QCLContextGL::createRenderbuffer
    (GLuint renderbuffer, QCLMemoryObject::Access access)
{
#ifndef QT_NO_CL_OPENGL
    cl_int error = CL_INVALID_CONTEXT;
    cl_mem_flags flags = cl_mem_flags(access);
    cl_mem mem = clCreateFromGLRenderbuffer
        (contextId(), flags, renderbuffer, &error);
    reportError("QCLContextGL::createGLRenderbuffer:", error);
    if (mem)
        return QCLImage2D(this, mem);
    else
        return QCLImage2D();
#else
    Q_UNUSED(renderbuffer);
    Q_UNUSED(access);
    reportError("QCLContextGL::createRenderbuffer:", CL_INVALID_VALUE);
    return QCLImage2D();
#endif
}

/*!
    \internal
*/
void QCLContextGL::reportError(const char *name, cl_int error)
{
    setLastError(error);
    if (error != CL_SUCCESS)
        qWarning() << name << QCLContext::errorName(error);
}

#ifdef Q_MAC_COMPAT_GL_FUNCTIONS

/*!
    \internal
*/
QCLBuffer QCLContextGL::createGLBuffer
    (QMacCompatGLuint bufobj, QCLMemoryObject::Access access)
{
    return createGLBuffer(GLuint(bufobj), access);
}

/*!
    \internal
*/
QCLImage2D QCLContextGL::createTexture2D
    (QMacCompatGLenum type, QMacCompatGLuint texture,
     QMacCompatGLint mipmapLevel, QCLMemoryObject::Access access)
{
    return createTexture2D(GLenum(type), GLuint(texture),
                           GLint(mipmapLevel), access);
}

/*!
    \internal
*/
QCLImage2D QCLContextGL::createTexture2D
    (QMacCompatGLuint texture, QCLMemoryObject::Access access)
{
    return createTexture2D(GLenum(GL_TEXTURE_2D), GLuint(texture),
                           GLint(0), access);
}

/*!
    \internal
*/
QCLImage3D QCLContextGL::createTexture3D
    (QMacCompatGLenum type, QMacCompatGLuint texture,
     QMacCompatGLint mipmapLevel, QCLMemoryObject::Access access)
{
    return createTexture3D(GLenum(type), GLuint(texture),
                           GLint(mipmapLevel), access);
}

/*!
    \internal
*/
QCLImage3D QCLContextGL::createTexture3D
    (QMacCompatGLuint texture, QCLMemoryObject::Access access)
{
    return createTexture3D(GLenum(GL_TEXTURE_3D), GLuint(texture),
                           GLint(0), access);
}

/*!
    \internal
*/
QCLImage2D QCLContextGL::createRenderbuffer
    (QMacCompatGLuint renderbuffer, QCLMemoryObject::Access access)
{
    return createRenderbuffer(GLuint(renderbuffer), access);
}

#endif

/*!
    Returns true if the OpenCL \a buffer object is also an OpenGL
    buffer object; false otherwise.
*/
bool QCLContextGL::isGLBuffer(const QCLBuffer &buffer)
{
#ifndef QT_NO_CL_OPENGL
    cl_gl_object_type objectType;
    if (clGetGLObjectInfo
            (buffer.memoryId(), &objectType, 0) != CL_SUCCESS)
        return false;
    return objectType == CL_GL_OBJECT_BUFFER;
#else
    Q_UNUSED(buffer);
    return false;
#endif
}

/*!
    Returns true if the 2D OpenCL \a image object is also an OpenGL
    2D texture object; false otherwise.

    \sa isRenderbuffer(), isTexture3D()
*/
bool QCLContextGL::isTexture2D(const QCLImage2D &image)
{
#ifndef QT_NO_CL_OPENGL
    cl_gl_object_type objectType;
    if (clGetGLObjectInfo
            (image.memoryId(), &objectType, 0) != CL_SUCCESS)
        return false;
    return objectType == CL_GL_OBJECT_TEXTURE2D;
#else
    Q_UNUSED(image);
    return false;
#endif
}

/*!
    Returns true if the 3D OpenCL \a image object is also an OpenGL
    3D texture object; false otherwise.

    \sa isTexture2D()
*/
bool QCLContextGL::isTexture3D(const QCLImage3D &image)
{
#ifndef QT_NO_CL_OPENGL
    cl_gl_object_type objectType;
    if (clGetGLObjectInfo
            (image.memoryId(), &objectType, 0) != CL_SUCCESS)
        return false;
    return objectType == CL_GL_OBJECT_TEXTURE3D;
#else
    Q_UNUSED(image);
    return false;
#endif
}

/*!
    Returns true if the 2D OpenCL \a image object is also an OpenGL
    renderbuffer object; false otherwise.

    \sa isTexture2D()
*/
bool QCLContextGL::isRenderbuffer(const QCLImage2D &image)
{
#ifndef QT_NO_CL_OPENGL
    cl_gl_object_type objectType;
    if (clGetGLObjectInfo
            (image.memoryId(), &objectType, 0) != CL_SUCCESS)
        return false;
    return objectType == CL_GL_OBJECT_RENDERBUFFER;
#else
    Q_UNUSED(image);
    return false;
#endif
}

/*!
    Acquires access to the OpenGL object behind the OpenCL memory
    object \a mem.  This function must be called before performing
    an OpenCL operation on any OpenGL memory object.

    Returns an event object that can be used to wait for the
    request to finish.  The request is executed on the active
    command queue for this context.

    \sa release()
*/
QCLEvent QCLContextGL::acquire(const QCLMemoryObject &mem)
{
#ifndef QT_NO_CL_OPENGL
    cl_event event;
    cl_mem id = mem.memoryId();
    cl_int error = clEnqueueAcquireGLObjects
        (commandQueue().queueId(), 1, &id, 0, 0, &event);
    reportError("QCLContextGL::acquire:", error);
    if (error == CL_SUCCESS)
        return QCLEvent(event);
    else
        return QCLEvent();
#else
    Q_UNUSED(mem);
    return QCLEvent();
#endif
}

/*!
    \overload

    Acquires access to the OpenGL object behind the OpenCL memory
    object \a mem.  This function must be called before performing
    an OpenCL operation on any OpenGL memory object.

    The request will not start until all of the events in \a after
    have been signaled as finished.

    Returns an event object that can be used to wait for the
    request to finish.  The request is executed on the active
    command queue for this context.

    \sa release()
*/
QCLEvent QCLContextGL::acquire
    (const QCLMemoryObject &mem, const QCLEventList &after)
{
#ifndef QT_NO_CL_OPENGL
    cl_event event;
    cl_mem id = mem.memoryId();
    cl_int error = clEnqueueAcquireGLObjects
        (commandQueue().queueId(), 1, &id,
         after.size(), after.eventData(), &event);
    reportError("QCLContextGL::acquire(after):", error);
    if (error == CL_SUCCESS)
        return QCLEvent(event);
    else
        return QCLEvent();
#else
    Q_UNUSED(mem);
    Q_UNUSED(after);
    return QCLEvent();
#endif
}

/*!
    Releases access to the OpenGL object behind the OpenCL memory
    object \a mem.  This function must be called after performing
    an OpenCL operation on any OpenGL memory object, and before
    performing OpenGL operations on the object.

    Returns an event object that can be used to wait for the
    request to finish.  The request is executed on the active
    command queue for this context.

    \sa acquire()
*/
QCLEvent QCLContextGL::release(const QCLMemoryObject &mem)
{
#ifndef QT_NO_CL_OPENGL
    cl_event event;
    cl_mem id = mem.memoryId();
    cl_int error = clEnqueueReleaseGLObjects
        (commandQueue().queueId(), 1, &id, 0, 0, &event);
    reportError("QCLContextGL::release:", error);
    if (error == CL_SUCCESS)
        return QCLEvent(event);
    else
        return QCLEvent();
#else
    Q_UNUSED(mem);
    return QCLEvent();
#endif
}

/*!
    \overload

    Releases access to the OpenGL object behind the OpenCL memory
    object \a mem.  This function must be called after performing
    an OpenCL operation on any OpenGL memory object, and before
    performing OpenGL operations on the object.

    The request will not start until all of the events in \a after
    have been signaled as finished.

    Returns an event object that can be used to wait for the
    request to finish.  The request is executed on the active
    command queue for this context.

    \sa acquire()
*/
QCLEvent QCLContextGL::release
    (const QCLMemoryObject &mem, const QCLEventList &after)
{
#ifndef QT_NO_CL_OPENGL
    cl_event event;
    cl_mem id = mem.memoryId();
    cl_int error = clEnqueueReleaseGLObjects
        (commandQueue().queueId(), 1, &id,
         after.size(), after.eventData(), &event);
    reportError("QCLContextGL::release(after):", error);
    if (error == CL_SUCCESS)
        return QCLEvent(event);
    else
        return QCLEvent();
#else
    Q_UNUSED(mem);
    Q_UNUSED(after);
    return QCLEvent();
#endif
}

QT_END_NAMESPACE