1 | // Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sean Harmer <sean.harmer@kdab.com> |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QOPENGLVERTEXARRAYOBJECT_H |
5 | #define QOPENGLVERTEXARRAYOBJECT_H |
6 | |
7 | #include <QtOpenGL/qtopenglglobal.h> |
8 | |
9 | #ifndef QT_NO_OPENGL |
10 | |
11 | #include <QtCore/QObject> |
12 | #include <QtGui/qopengl.h> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | class QOpenGLVertexArrayObjectPrivate; |
17 | |
18 | class Q_OPENGL_EXPORT QOpenGLVertexArrayObject : public QObject |
19 | { |
20 | Q_OBJECT |
21 | |
22 | public: |
23 | explicit QOpenGLVertexArrayObject(QObject* parent = nullptr); |
24 | ~QOpenGLVertexArrayObject(); |
25 | |
26 | bool create(); |
27 | void destroy(); |
28 | bool isCreated() const; |
29 | GLuint objectId() const; |
30 | void bind(); |
31 | void release(); |
32 | |
33 | class Binder |
34 | { |
35 | public: |
36 | inline Binder(QOpenGLVertexArrayObject *v) |
37 | : vao(v) |
38 | { |
39 | Q_ASSERT(v); |
40 | if (vao->isCreated() || vao->create()) |
41 | vao->bind(); |
42 | } |
43 | |
44 | inline ~Binder() |
45 | { |
46 | release(); |
47 | } |
48 | |
49 | inline void release() |
50 | { |
51 | vao->release(); |
52 | } |
53 | |
54 | inline void rebind() |
55 | { |
56 | vao->bind(); |
57 | } |
58 | |
59 | private: |
60 | Q_DISABLE_COPY(Binder) |
61 | QOpenGLVertexArrayObject *vao; |
62 | }; |
63 | |
64 | private: |
65 | Q_DISABLE_COPY(QOpenGLVertexArrayObject) |
66 | Q_DECLARE_PRIVATE(QOpenGLVertexArrayObject) |
67 | Q_PRIVATE_SLOT(d_func(), void _q_contextAboutToBeDestroyed()) |
68 | QOpenGLVertexArrayObject(QOpenGLVertexArrayObjectPrivate &dd); |
69 | }; |
70 | |
71 | QT_END_NAMESPACE |
72 | |
73 | #endif |
74 | |
75 | #endif // QOPENGLVERTEXARRAYOBJECT_H |
76 | |