1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QOPENGLBUFFER_H
41#define QOPENGLBUFFER_H
42
43#include <QtGui/qtguiglobal.h>
44
45#ifndef QT_NO_OPENGL
46
47#include <QtCore/qscopedpointer.h>
48#include <QtGui/qopengl.h>
49
50QT_BEGIN_NAMESPACE
51
52
53class QOpenGLBufferPrivate;
54
55class Q_GUI_EXPORT QOpenGLBuffer
56{
57public:
58 enum Type
59 {
60 VertexBuffer = 0x8892, // GL_ARRAY_BUFFER
61 IndexBuffer = 0x8893, // GL_ELEMENT_ARRAY_BUFFER
62 PixelPackBuffer = 0x88EB, // GL_PIXEL_PACK_BUFFER
63 PixelUnpackBuffer = 0x88EC // GL_PIXEL_UNPACK_BUFFER
64 };
65
66 QOpenGLBuffer();
67 explicit QOpenGLBuffer(QOpenGLBuffer::Type type);
68 QOpenGLBuffer(const QOpenGLBuffer &other);
69 ~QOpenGLBuffer();
70
71 QOpenGLBuffer &operator=(const QOpenGLBuffer &other);
72
73 enum UsagePattern
74 {
75 StreamDraw = 0x88E0, // GL_STREAM_DRAW
76 StreamRead = 0x88E1, // GL_STREAM_READ
77 StreamCopy = 0x88E2, // GL_STREAM_COPY
78 StaticDraw = 0x88E4, // GL_STATIC_DRAW
79 StaticRead = 0x88E5, // GL_STATIC_READ
80 StaticCopy = 0x88E6, // GL_STATIC_COPY
81 DynamicDraw = 0x88E8, // GL_DYNAMIC_DRAW
82 DynamicRead = 0x88E9, // GL_DYNAMIC_READ
83 DynamicCopy = 0x88EA // GL_DYNAMIC_COPY
84 };
85
86 enum Access
87 {
88 ReadOnly = 0x88B8, // GL_READ_ONLY
89 WriteOnly = 0x88B9, // GL_WRITE_ONLY
90 ReadWrite = 0x88BA // GL_READ_WRITE
91 };
92
93 enum RangeAccessFlag
94 {
95 RangeRead = 0x0001, // GL_MAP_READ_BIT
96 RangeWrite = 0x0002, // GL_MAP_WRITE_BIT
97 RangeInvalidate = 0x0004, // GL_MAP_INVALIDATE_RANGE_BIT
98 RangeInvalidateBuffer = 0x0008, // GL_MAP_INVALIDATE_BUFFER_BIT
99 RangeFlushExplicit = 0x0010, // GL_MAP_FLUSH_EXPLICIT_BIT
100 RangeUnsynchronized = 0x0020 // GL_MAP_UNSYNCHRONIZED_BIT
101 };
102 Q_DECLARE_FLAGS(RangeAccessFlags, RangeAccessFlag)
103
104 QOpenGLBuffer::Type type() const;
105
106 QOpenGLBuffer::UsagePattern usagePattern() const;
107 void setUsagePattern(QOpenGLBuffer::UsagePattern value);
108
109 bool create();
110 bool isCreated() const;
111
112 void destroy();
113
114 bool bind();
115 void release();
116
117 static void release(QOpenGLBuffer::Type type);
118
119 GLuint bufferId() const;
120
121 int size() const;
122
123 bool read(int offset, void *data, int count);
124 void write(int offset, const void *data, int count);
125
126 void allocate(const void *data, int count);
127 inline void allocate(int count) { allocate(nullptr, count); }
128
129 void *map(QOpenGLBuffer::Access access);
130 void *mapRange(int offset, int count, QOpenGLBuffer::RangeAccessFlags access);
131 bool unmap();
132
133private:
134 QOpenGLBufferPrivate *d_ptr;
135
136 Q_DECLARE_PRIVATE(QOpenGLBuffer)
137};
138
139Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLBuffer::RangeAccessFlags)
140
141QT_END_NAMESPACE
142
143#endif // QT_NO_OPENGL
144
145#endif
146