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 QtOpenGL 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 QGLBUFFER_H
41#define QGLBUFFER_H
42
43#include <QtCore/qscopedpointer.h>
44#include <QtOpenGL/qgl.h>
45
46QT_BEGIN_NAMESPACE
47
48
49class QGLBufferPrivate;
50
51class Q_OPENGL_EXPORT QGLBuffer
52{
53public:
54 enum Type
55 {
56 VertexBuffer = 0x8892, // GL_ARRAY_BUFFER
57 IndexBuffer = 0x8893, // GL_ELEMENT_ARRAY_BUFFER
58 PixelPackBuffer = 0x88EB, // GL_PIXEL_PACK_BUFFER
59 PixelUnpackBuffer = 0x88EC // GL_PIXEL_UNPACK_BUFFER
60 };
61
62 QGLBuffer();
63 explicit QGLBuffer(QGLBuffer::Type type);
64 QGLBuffer(const QGLBuffer &other);
65 ~QGLBuffer();
66
67 QGLBuffer &operator=(const QGLBuffer &other);
68
69 enum UsagePattern
70 {
71 StreamDraw = 0x88E0, // GL_STREAM_DRAW
72 StreamRead = 0x88E1, // GL_STREAM_READ
73 StreamCopy = 0x88E2, // GL_STREAM_COPY
74 StaticDraw = 0x88E4, // GL_STATIC_DRAW
75 StaticRead = 0x88E5, // GL_STATIC_READ
76 StaticCopy = 0x88E6, // GL_STATIC_COPY
77 DynamicDraw = 0x88E8, // GL_DYNAMIC_DRAW
78 DynamicRead = 0x88E9, // GL_DYNAMIC_READ
79 DynamicCopy = 0x88EA // GL_DYNAMIC_COPY
80 };
81
82 enum Access
83 {
84 ReadOnly = 0x88B8, // GL_READ_ONLY
85 WriteOnly = 0x88B9, // GL_WRITE_ONLY
86 ReadWrite = 0x88BA // GL_READ_WRITE
87 };
88
89 QGLBuffer::Type type() const;
90
91 QGLBuffer::UsagePattern usagePattern() const;
92 void setUsagePattern(QGLBuffer::UsagePattern value);
93
94 bool create();
95 bool isCreated() const;
96
97 void destroy();
98
99 bool bind();
100 void release();
101
102 static void release(QGLBuffer::Type type);
103
104 GLuint bufferId() const;
105
106 int size() const;
107
108 bool read(int offset, void *data, int count);
109 void write(int offset, const void *data, int count);
110
111 void allocate(const void *data, int count);
112 inline void allocate(int count) { allocate(data: nullptr, count); }
113
114 void *map(QGLBuffer::Access access);
115 bool unmap();
116
117private:
118 QGLBufferPrivate *d_ptr;
119
120 Q_DECLARE_PRIVATE(QGLBuffer)
121};
122
123QT_END_NAMESPACE
124
125#endif
126

source code of qtbase/src/opengl/qglbuffer.h