![]() |
Qt 6.x
The Qt SDK
|
The QOpenGLBuffer class provides functions for creating and managing OpenGL buffer objects. More...
#include <qopenglbuffer.h>
Public Types | |
enum | Type { VertexBuffer = 0x8892 , IndexBuffer = 0x8893 , PixelPackBuffer = 0x88EB , PixelUnpackBuffer = 0x88EC } |
This enum defines the type of OpenGL buffer object to create with QOpenGLBuffer. More... | |
enum | UsagePattern { StreamDraw = 0x88E0 , StreamRead = 0x88E1 , StreamCopy = 0x88E2 , StaticDraw = 0x88E4 , StaticRead = 0x88E5 , StaticCopy = 0x88E6 , DynamicDraw = 0x88E8 , DynamicRead = 0x88E9 , DynamicCopy = 0x88EA } |
This enum defines the usage pattern of a QOpenGLBuffer object. More... | |
enum | Access { ReadOnly = 0x88B8 , WriteOnly = 0x88B9 , ReadWrite = 0x88BA } |
This enum defines the access mode for QOpenGLBuffer::map(). More... | |
enum | RangeAccessFlag { RangeRead = 0x0001 , RangeWrite = 0x0002 , RangeInvalidate = 0x0004 , RangeInvalidateBuffer = 0x0008 , RangeFlushExplicit = 0x0010 , RangeUnsynchronized = 0x0020 } |
This enum defines the access mode bits for QOpenGLBuffer::mapRange(). More... | |
Public Member Functions | |
QOpenGLBuffer () | |
Constructs a new buffer object of type QOpenGLBuffer::VertexBuffer. | |
QOpenGLBuffer (QOpenGLBuffer::Type type) | |
Constructs a new buffer object of type. | |
QOpenGLBuffer (const QOpenGLBuffer &other) | |
Constructs a shallow copy of other. | |
QOpenGLBuffer (QOpenGLBuffer &&other) noexcept | |
~QOpenGLBuffer () | |
Destroys this buffer object, including the storage being used in the OpenGL server. | |
QOpenGLBuffer & | operator= (const QOpenGLBuffer &other) |
Assigns a shallow copy of other to this object. | |
void | swap (QOpenGLBuffer &other) noexcept |
QOpenGLBuffer::Type | type () const |
Returns the type of buffer represented by this object. | |
QOpenGLBuffer::UsagePattern | usagePattern () const |
Returns the usage pattern for this buffer object. | |
void | setUsagePattern (QOpenGLBuffer::UsagePattern value) |
Sets the usage pattern for this buffer object to value. | |
bool | create () |
Creates the buffer object in the OpenGL server. | |
bool | isCreated () const |
Returns true if this buffer has been created; false otherwise. | |
void | destroy () |
Destroys this buffer object, including the storage being used in the OpenGL server. | |
bool | bind () |
Binds the buffer associated with this object to the current OpenGL context. | |
void | release () |
Releases the buffer associated with this object from the current OpenGL context. | |
GLuint | bufferId () const |
Returns the OpenGL identifier associated with this buffer; zero if the buffer has not been created. | |
int | size () const |
Returns the size of the data in this buffer, for reading operations. | |
bool | read (int offset, void *data, int count) |
Reads the count bytes in this buffer starting at offset into data. | |
void | write (int offset, const void *data, int count) |
Replaces the count bytes of this buffer starting at offset with the contents of data. | |
void | allocate (const void *data, int count) |
Allocates count bytes of space to the buffer, initialized to the contents of data. | |
void | allocate (int count) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Allocates count bytes of space to the buffer. | |
void * | map (QOpenGLBuffer::Access access) |
Maps the contents of this buffer into the application's memory space and returns a pointer to it. | |
void * | mapRange (int offset, int count, QOpenGLBuffer::RangeAccessFlags access) |
Maps the range specified by offset and count of the contents of this buffer into the application's memory space and returns a pointer to it. | |
bool | unmap () |
Unmaps the buffer after it was mapped into the application's memory space with a previous call to map(). | |
Static Public Member Functions | |
static void | release (QOpenGLBuffer::Type type) |
Releases the buffer associated with type in the current QOpenGLContext. | |
The QOpenGLBuffer class provides functions for creating and managing OpenGL buffer objects.
\inmodule QtOpenGL
Buffer objects are created in the OpenGL server so that the client application can avoid uploading vertices, indices, texture image data, etc every time they are needed.
QOpenGLBuffer objects can be copied around as a reference to the underlying OpenGL buffer object:
QOpenGLBuffer performs a shallow copy when objects are copied in this manner, but does not implement copy-on-write semantics. The original object will be affected whenever the copy is modified.
Definition at line 18 of file qopenglbuffer.h.
This enum defines the access mode for QOpenGLBuffer::map().
\value ReadOnly The buffer will be mapped for reading only. \value WriteOnly The buffer will be mapped for writing only. \value ReadWrite The buffer will be mapped for reading and writing.
Enumerator | |
---|---|
ReadOnly | |
WriteOnly | |
ReadWrite |
Definition at line 55 of file qopenglbuffer.h.
This enum defines the access mode bits for QOpenGLBuffer::mapRange().
\value RangeRead The buffer will be mapped for reading. \value RangeWrite The buffer will be mapped for writing. \value RangeInvalidate Discard the previous contents of the specified range. \value RangeInvalidateBuffer Discard the previous contents of the entire buffer. \value RangeFlushExplicit Indicates that modifications are to be flushed explicitly via glFlushMappedBufferRange
. \value RangeUnsynchronized Indicates that pending operations should not be synchronized before returning from mapRange().
Enumerator | |
---|---|
RangeRead | |
RangeWrite | |
RangeInvalidate | |
RangeInvalidateBuffer | |
RangeFlushExplicit | |
RangeUnsynchronized |
Definition at line 62 of file qopenglbuffer.h.
enum QOpenGLBuffer::Type |
This enum defines the type of OpenGL buffer object to create with QOpenGLBuffer.
\value VertexBuffer Vertex buffer object for use when specifying vertex arrays. \value IndexBuffer Index buffer object for use with {glDrawElements()}. \value PixelPackBuffer Pixel pack buffer object for reading pixel data from the OpenGL server (for example, with
{glReadPixels()}). Not supported under OpenGL/ES. \value PixelUnpackBuffer Pixel unpack buffer object for writing pixel data to the OpenGL server (for example, with
{glTexImage2D()}). Not supported under OpenGL/ES.
Enumerator | |
---|---|
VertexBuffer | |
IndexBuffer | |
PixelPackBuffer | |
PixelUnpackBuffer |
Definition at line 21 of file qopenglbuffer.h.
This enum defines the usage pattern of a QOpenGLBuffer object.
\value StreamDraw The data will be set once and used a few times for drawing operations. Under OpenGL/ES 1.1 this is identical to StaticDraw. \value StreamRead The data will be set once and used a few times for reading data back from the OpenGL server. Not supported under OpenGL/ES. \value StreamCopy The data will be set once and used a few times for reading data back from the OpenGL server for use in further drawing operations. Not supported under OpenGL/ES. \value StaticDraw The data will be set once and used many times for drawing operations. \value StaticRead The data will be set once and used many times for reading data back from the OpenGL server. Not supported under OpenGL/ES. \value StaticCopy The data will be set once and used many times for reading data back from the OpenGL server for use in further drawing operations. Not supported under OpenGL/ES. \value DynamicDraw The data will be modified repeatedly and used many times for drawing operations. \value DynamicRead The data will be modified repeatedly and used many times for reading data back from the OpenGL server. Not supported under OpenGL/ES. \value DynamicCopy The data will be modified repeatedly and used many times for reading data back from the OpenGL server for use in further drawing operations. Not supported under OpenGL/ES.
Enumerator | |
---|---|
StreamDraw | |
StreamRead | |
StreamCopy | |
StaticDraw | |
StaticRead | |
StaticCopy | |
DynamicDraw | |
DynamicRead | |
DynamicCopy |
Definition at line 42 of file qopenglbuffer.h.
QOpenGLBuffer::QOpenGLBuffer | ( | ) |
Constructs a new buffer object of type QOpenGLBuffer::VertexBuffer.
Note: this constructor just creates the QOpenGLBuffer instance. The actual buffer object in the OpenGL server is not created until create() is called.
Definition at line 133 of file qopenglbuffer.cpp.
|
explicit |
Constructs a new buffer object of type.
Note: this constructor just creates the QOpenGLBuffer instance. The actual buffer object in the OpenGL server is not created until create() is called.
Definition at line 146 of file qopenglbuffer.cpp.
QOpenGLBuffer::QOpenGLBuffer | ( | const QOpenGLBuffer & | other | ) |
Constructs a shallow copy of other.
Note: QOpenGLBuffer does not implement copy-on-write semantics, so other will be affected whenever the copy is modified.
Definition at line 157 of file qopenglbuffer.cpp.
References QBasicAtomicInteger< T >::ref(), and QOpenGLBufferPrivate::ref.
|
inlinenoexcept |
Move-constructs a new QOpenGLBuffer from other.
Definition at line 32 of file qopenglbuffer.h.
References other().
QOpenGLBuffer::~QOpenGLBuffer | ( | ) |
Destroys this buffer object, including the storage being used in the OpenGL server.
Definition at line 167 of file qopenglbuffer.cpp.
References QBasicAtomicInteger< T >::deref(), destroy(), and QOpenGLBufferPrivate::ref.
Allocates count bytes of space to the buffer, initialized to the contents of data.
Any previous contents will be removed.
It is assumed that create() has been called on this buffer and that it has been bound to the current context.
Definition at line 390 of file qopenglbuffer.cpp.
References d, isCreated(), and qWarning.
Referenced by QtWaylandClient::DecorationsBlitter::DecorationsBlitter(), and QOpenGLTextureGlyphCache::createTextureData().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Allocates count bytes of space to the buffer.
Any previous contents will be removed.
It is assumed that create() has been called on this buffer and that it has been bound to the current context.
Definition at line 96 of file qopenglbuffer.h.
References allocate().
Referenced by allocate().
bool QOpenGLBuffer::bind | ( | ) |
Binds the buffer associated with this object to the current OpenGL context.
Returns false
if binding was not possible, usually because type() is not supported on this OpenGL implementation.
The buffer must be bound to the same QOpenGLContext current when create() was called, or to another QOpenGLContext that is sharing with it. Otherwise, false will be returned from this function.
Definition at line 425 of file qopenglbuffer.cpp.
References bufferId(), QOpenGLContextGroup::currentContextGroup(), d, GLuint, isCreated(), and qWarning.
Referenced by QtWaylandClient::DecorationsBlitter::DecorationsBlitter(), QOpenGLTextureGlyphCache::createTextureData(), and QOpenGLTextureBlitterPrivate::prepareProgram().
GLuint QOpenGLBuffer::bufferId | ( | ) | const |
Returns the OpenGL identifier associated with this buffer; zero if the buffer has not been created.
Definition at line 491 of file qopenglbuffer.cpp.
References d.
Referenced by bind(), and create().
bool QOpenGLBuffer::create | ( | ) |
Creates the buffer object in the OpenGL server.
Returns true
if the object was created; false otherwise.
This function must be called with a current QOpenGLContext. The buffer will be bound to and can only be used in that context (or any other context that is shared with it).
This function will return false if the OpenGL implementation does not support buffers, or there is no current QOpenGLContext.
Definition at line 277 of file qopenglbuffer.cpp.
References bufferId(), QOpenGLContext::currentContext(), d, and GLuint.
Referenced by QtWaylandClient::DecorationsBlitter::DecorationsBlitter(), QOpenGLTextureGlyphCache::createTextureData(), and src_gui_opengl_qopenglbuffer::wrapper().
void QOpenGLBuffer::destroy | ( | ) |
Destroys this buffer object, including the storage being used in the OpenGL server.
All references to the buffer will become invalid.
Definition at line 315 of file qopenglbuffer.cpp.
References d.
Referenced by QOpenGL2PaintEngineExPrivate::~QOpenGL2PaintEngineExPrivate(), ~QOpenGLBuffer(), and operator=().
bool QOpenGLBuffer::isCreated | ( | ) | const |
Returns true
if this buffer has been created; false otherwise.
Definition at line 304 of file qopenglbuffer.cpp.
References d.
Referenced by allocate(), bind(), QOpenGLTextureGlyphCache::createTextureData(), map(), mapRange(), release(), unmap(), and write().
void * QOpenGLBuffer::map | ( | QOpenGLBuffer::Access | access | ) |
Maps the contents of this buffer into the application's memory space and returns a pointer to it.
Returns null if memory mapping is not possible. The access parameter indicates the type of access to be performed.
It is assumed that create() has been called on this buffer and that it has been bound to the current context.
GL_OES_mapbuffer
extension is present.GL_ARB_map_buffer_range
is supported, this function uses glMapBufferRange
instead of glMapBuffer
.Definition at line 534 of file qopenglbuffer.cpp.
References d, isCreated(), QOpenGLExtensions::MapBufferRange, qWarning, RangeRead, RangeWrite, ReadOnly, ReadWrite, and WriteOnly.
void * QOpenGLBuffer::mapRange | ( | int | offset, |
int | count, | ||
QOpenGLBuffer::RangeAccessFlags | access | ||
) |
Maps the range specified by offset and count of the contents of this buffer into the application's memory space and returns a pointer to it.
Returns null if memory mapping is not possible. The access parameter specifies a combination of access flags.
It is assumed that create() has been called on this buffer and that it has been bound to the current context.
Definition at line 575 of file qopenglbuffer.cpp.
References d, isCreated(), and qWarning.
QOpenGLBuffer & QOpenGLBuffer::operator= | ( | const QOpenGLBuffer & | other | ) |
Assigns a shallow copy of other to this object.
Note: QOpenGLBuffer does not implement copy-on-write semantics, so other will be affected whenever the copy is modified.
Move-assigns other to this QOpenGLBuffer instance.
Definition at line 181 of file qopenglbuffer.cpp.
References QBasicAtomicInteger< T >::deref(), destroy(), other(), and QOpenGLBufferPrivate::ref.
bool QOpenGLBuffer::read | ( | int | offset, |
void * | data, | ||
int | count | ||
) |
Reads the count bytes in this buffer starting at offset into data.
Returns true
on success; false if reading from the buffer is not supported. Buffer reading is not supported under OpenGL/ES.
It is assumed that this buffer has been bound to the current context.
Definition at line 336 of file qopenglbuffer.cpp.
References QOpenGLFunctions::Buffers, d, error, GL_CONTEXT_LOST, GLenum(), and Q_UNUSED.
void QOpenGLBuffer::release | ( | ) |
Releases the buffer associated with this object from the current OpenGL context.
This function must be called with the same QOpenGLContext current as when bind() was called on the buffer.
Definition at line 456 of file qopenglbuffer.cpp.
References d, isCreated(), and qWarning.
Referenced by QOpenGLTextureGlyphCache::createTextureData(), QOpenGLTextureBlitterPrivate::prepareProgram(), and src_gui_opengl_qopenglbuffer::wrapper().
|
static |
Releases the buffer associated with type in the current QOpenGLContext.
This function is a direct call to {glBindBuffer(type, 0)} for use when the caller does not know which QOpenGLBuffer has been bound to the context but wants to make sure that it is released.
Definition at line 478 of file qopenglbuffer.cpp.
References QOpenGLContext::currentContext(), and GLenum().
void QOpenGLBuffer::setUsagePattern | ( | QOpenGLBuffer::UsagePattern | value | ) |
Sets the usage pattern for this buffer object to value.
This function must be called before allocate() or write().
Definition at line 251 of file qopenglbuffer.cpp.
References d.
int QOpenGLBuffer::size | ( | ) | const |
Returns the size of the data in this buffer, for reading operations.
Returns -1 if fetching the buffer size is not supported, or the buffer has not been created.
It is assumed that this buffer has been bound to the current context.
Definition at line 506 of file qopenglbuffer.cpp.
References d, GL_BUFFER_SIZE, and GLint().
|
inlinenoexcept |
Swaps buffer other with this buffer. This operation is very fast and never fails.
Definition at line 39 of file qopenglbuffer.h.
References other(), and qt_ptr_swap().
QOpenGLBuffer::Type QOpenGLBuffer::type | ( | ) | const |
Returns the type of buffer represented by this object.
Definition at line 227 of file qopenglbuffer.cpp.
References d.
bool QOpenGLBuffer::unmap | ( | ) |
Unmaps the buffer after it was mapped into the application's memory space with a previous call to map().
Returns true
if the unmap succeeded; false otherwise.
It is assumed that this buffer has been bound to the current context, and that it was previously mapped with map().
{GL_OES_mapbuffer} extension is present.Definition at line 600 of file qopenglbuffer.cpp.
References d, isCreated(), and qWarning.
QOpenGLBuffer::UsagePattern QOpenGLBuffer::usagePattern | ( | ) | const |
Returns the usage pattern for this buffer object.
The default value is StaticDraw.
Definition at line 239 of file qopenglbuffer.cpp.
References d.
Replaces the count bytes of this buffer starting at offset with the contents of data.
Any other bytes in the buffer will be left unmodified.
It is assumed that create() has been called on this buffer and that it has been bound to the current context.
Definition at line 370 of file qopenglbuffer.cpp.
References d, isCreated(), and qWarning.
Referenced by QtWaylandClient::DecorationsBlitter::DecorationsBlitter().