| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 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 QOPENGLBUFFER_H |
| 5 | #define QOPENGLBUFFER_H |
| 6 | |
| 7 | #include <QtOpenGL/qtopenglglobal.h> |
| 8 | |
| 9 | #ifndef QT_NO_OPENGL |
| 10 | |
| 11 | #include <QtGui/qopengl.h> |
| 12 | |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | |
| 16 | class QOpenGLBufferPrivate; |
| 17 | |
| 18 | class Q_OPENGL_EXPORT QOpenGLBuffer |
| 19 | { |
| 20 | public: |
| 21 | enum Type |
| 22 | { |
| 23 | VertexBuffer = 0x8892, // GL_ARRAY_BUFFER |
| 24 | IndexBuffer = 0x8893, // GL_ELEMENT_ARRAY_BUFFER |
| 25 | PixelPackBuffer = 0x88EB, // GL_PIXEL_PACK_BUFFER |
| 26 | PixelUnpackBuffer = 0x88EC // GL_PIXEL_UNPACK_BUFFER |
| 27 | }; |
| 28 | |
| 29 | QOpenGLBuffer(); |
| 30 | explicit QOpenGLBuffer(QOpenGLBuffer::Type type); |
| 31 | QOpenGLBuffer(const QOpenGLBuffer &other); |
| 32 | QOpenGLBuffer(QOpenGLBuffer &&other) noexcept |
| 33 | : d_ptr{std::exchange(obj&: other.d_ptr, new_val: nullptr)} {} |
| 34 | ~QOpenGLBuffer(); |
| 35 | |
| 36 | QOpenGLBuffer &operator=(const QOpenGLBuffer &other); |
| 37 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QOpenGLBuffer) |
| 38 | |
| 39 | void swap(QOpenGLBuffer &other) noexcept |
| 40 | { return qt_ptr_swap(lhs&: d_ptr, rhs&: other.d_ptr); } |
| 41 | |
| 42 | enum UsagePattern |
| 43 | { |
| 44 | StreamDraw = 0x88E0, // GL_STREAM_DRAW |
| 45 | StreamRead = 0x88E1, // GL_STREAM_READ |
| 46 | StreamCopy = 0x88E2, // GL_STREAM_COPY |
| 47 | StaticDraw = 0x88E4, // GL_STATIC_DRAW |
| 48 | StaticRead = 0x88E5, // GL_STATIC_READ |
| 49 | StaticCopy = 0x88E6, // GL_STATIC_COPY |
| 50 | DynamicDraw = 0x88E8, // GL_DYNAMIC_DRAW |
| 51 | DynamicRead = 0x88E9, // GL_DYNAMIC_READ |
| 52 | DynamicCopy = 0x88EA // GL_DYNAMIC_COPY |
| 53 | }; |
| 54 | |
| 55 | enum Access |
| 56 | { |
| 57 | ReadOnly = 0x88B8, // GL_READ_ONLY |
| 58 | WriteOnly = 0x88B9, // GL_WRITE_ONLY |
| 59 | ReadWrite = 0x88BA // GL_READ_WRITE |
| 60 | }; |
| 61 | |
| 62 | enum RangeAccessFlag |
| 63 | { |
| 64 | RangeRead = 0x0001, // GL_MAP_READ_BIT |
| 65 | RangeWrite = 0x0002, // GL_MAP_WRITE_BIT |
| 66 | RangeInvalidate = 0x0004, // GL_MAP_INVALIDATE_RANGE_BIT |
| 67 | RangeInvalidateBuffer = 0x0008, // GL_MAP_INVALIDATE_BUFFER_BIT |
| 68 | RangeFlushExplicit = 0x0010, // GL_MAP_FLUSH_EXPLICIT_BIT |
| 69 | RangeUnsynchronized = 0x0020 // GL_MAP_UNSYNCHRONIZED_BIT |
| 70 | }; |
| 71 | Q_DECLARE_FLAGS(RangeAccessFlags, RangeAccessFlag) |
| 72 | |
| 73 | QOpenGLBuffer::Type type() const; |
| 74 | |
| 75 | QOpenGLBuffer::UsagePattern usagePattern() const; |
| 76 | void setUsagePattern(QOpenGLBuffer::UsagePattern value); |
| 77 | |
| 78 | bool create(); |
| 79 | bool isCreated() const; |
| 80 | |
| 81 | void destroy(); |
| 82 | |
| 83 | bool bind(); |
| 84 | void release(); |
| 85 | |
| 86 | static void release(QOpenGLBuffer::Type type); |
| 87 | |
| 88 | GLuint bufferId() const; |
| 89 | |
| 90 | int size() const; |
| 91 | |
| 92 | bool read(int offset, void *data, int count); |
| 93 | void write(int offset, const void *data, int count); |
| 94 | |
| 95 | void allocate(const void *data, int count); |
| 96 | inline void allocate(int count) { allocate(data: nullptr, count); } |
| 97 | |
| 98 | void *map(QOpenGLBuffer::Access access); |
| 99 | void *mapRange(int offset, int count, QOpenGLBuffer::RangeAccessFlags access); |
| 100 | bool unmap(); |
| 101 | |
| 102 | private: |
| 103 | QOpenGLBufferPrivate *d_ptr; |
| 104 | |
| 105 | Q_DECLARE_PRIVATE(QOpenGLBuffer) |
| 106 | }; |
| 107 | Q_DECLARE_SHARED(QOpenGLBuffer) |
| 108 | |
| 109 | Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLBuffer::RangeAccessFlags) |
| 110 | |
| 111 | QT_END_NAMESPACE |
| 112 | |
| 113 | #endif // QT_NO_OPENGL |
| 114 | |
| 115 | #endif |
| 116 | |