1 | // Copyright (C) 2020 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_P_H |
5 | #define QOPENGLVERTEXARRAYOBJECT_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of the Qt OpenGL classes. This header file may change from |
13 | // version to version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtOpenGL/qtopenglglobal.h> |
19 | |
20 | #include <QtGui/qopengl.h> |
21 | #include <QtCore/private/qglobal_p.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QOpenGLContext; |
26 | |
27 | class QOpenGLVertexArrayObjectHelper |
28 | { |
29 | Q_DISABLE_COPY(QOpenGLVertexArrayObjectHelper) |
30 | |
31 | private: |
32 | explicit inline QOpenGLVertexArrayObjectHelper(QOpenGLContext *context) |
33 | : GenVertexArrays(nullptr) |
34 | , DeleteVertexArrays(nullptr) |
35 | , BindVertexArray(nullptr) |
36 | , IsVertexArray(nullptr) |
37 | { |
38 | initializeFromContext(context); |
39 | } |
40 | |
41 | void Q_OPENGL_EXPORT initializeFromContext(QOpenGLContext *context); |
42 | |
43 | public: |
44 | static Q_OPENGL_EXPORT QOpenGLVertexArrayObjectHelper *vertexArrayObjectHelperForContext(QOpenGLContext *context); |
45 | |
46 | inline bool isValid() const |
47 | { |
48 | return GenVertexArrays && DeleteVertexArrays && BindVertexArray && IsVertexArray; |
49 | } |
50 | |
51 | inline void glGenVertexArrays(GLsizei n, GLuint *arrays) const |
52 | { |
53 | GenVertexArrays(n, arrays); |
54 | } |
55 | |
56 | inline void glDeleteVertexArrays(GLsizei n, const GLuint *arrays) const |
57 | { |
58 | DeleteVertexArrays(n, arrays); |
59 | } |
60 | |
61 | inline void glBindVertexArray(GLuint array) const |
62 | { |
63 | BindVertexArray(array); |
64 | } |
65 | |
66 | inline GLboolean glIsVertexArray(GLuint array) const |
67 | { |
68 | return IsVertexArray(array); |
69 | } |
70 | |
71 | // Function signatures are equivalent between desktop core, ARB, APPLE, ES 3 and ES 2 extensions |
72 | typedef void (QOPENGLF_APIENTRYP qt_GenVertexArrays_t)(GLsizei n, GLuint *arrays); |
73 | typedef void (QOPENGLF_APIENTRYP qt_DeleteVertexArrays_t)(GLsizei n, const GLuint *arrays); |
74 | typedef void (QOPENGLF_APIENTRYP qt_BindVertexArray_t)(GLuint array); |
75 | typedef GLboolean (QOPENGLF_APIENTRYP qt_IsVertexArray_t)(GLuint array); |
76 | |
77 | qt_GenVertexArrays_t GenVertexArrays; |
78 | qt_DeleteVertexArrays_t DeleteVertexArrays; |
79 | qt_BindVertexArray_t BindVertexArray; |
80 | qt_IsVertexArray_t IsVertexArray; |
81 | }; |
82 | |
83 | QT_END_NAMESPACE |
84 | |
85 | #endif // QOPENGLVERTEXARRAYOBJECT_P_H |
86 | |