Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QOpenGLBuffer Class Reference

The QOpenGLBuffer class provides functions for creating and managing OpenGL buffer objects. More...

#include <qopenglbuffer.h>

+ Collaboration diagram for QOpenGLBuffer:

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.
 
QOpenGLBufferoperator= (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.
 
voidmap (QOpenGLBuffer::Access access)
 Maps the contents of this buffer into the application's memory space and returns a pointer to it.
 
voidmapRange (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.
 

Detailed Description

The QOpenGLBuffer class provides functions for creating and managing OpenGL buffer objects.

Since
5.0

\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:

buffer1.create();
QOpenGLBuffer buffer2 = buffer1;

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.

Member Enumeration Documentation

◆ Access

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.

◆ RangeAccessFlag

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.

◆ 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.

◆ UsagePattern

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.

Constructor & Destructor Documentation

◆ QOpenGLBuffer() [1/4]

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.

See also
create()

Definition at line 133 of file qopenglbuffer.cpp.

◆ QOpenGLBuffer() [2/4]

QOpenGLBuffer::QOpenGLBuffer ( QOpenGLBuffer::Type type)
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.

See also
create()

Definition at line 146 of file qopenglbuffer.cpp.

◆ QOpenGLBuffer() [3/4]

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.

+ Here is the call graph for this function:

◆ QOpenGLBuffer() [4/4]

QOpenGLBuffer::QOpenGLBuffer ( QOpenGLBuffer && other)
inlinenoexcept
Since
6.5

Move-constructs a new QOpenGLBuffer from other.

Note
The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

Definition at line 32 of file qopenglbuffer.h.

References other().

+ Here is the call graph for this function:

◆ ~QOpenGLBuffer()

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.

+ Here is the call graph for this function:

Member Function Documentation

◆ allocate() [1/2]

void QOpenGLBuffer::allocate ( const void * data,
int count )

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.

See also
create(), read(), write()

Definition at line 390 of file qopenglbuffer.cpp.

References d, isCreated(), and qWarning.

Referenced by QtWaylandClient::DecorationsBlitter::DecorationsBlitter(), and QOpenGLTextureGlyphCache::createTextureData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ allocate() [2/2]

void QOpenGLBuffer::allocate ( int count)
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.

See also
create(), write()

Definition at line 96 of file qopenglbuffer.h.

References allocate().

Referenced by allocate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bind()

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.

See also
release(), create()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bufferId()

GLuint QOpenGLBuffer::bufferId ( ) const

Returns the OpenGL identifier associated with this buffer; zero if the buffer has not been created.

See also
isCreated()

Definition at line 491 of file qopenglbuffer.cpp.

References d.

Referenced by bind(), and create().

+ Here is the caller graph for this function:

◆ 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.

See also
isCreated(), allocate(), write(), destroy()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ destroy()

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=().

+ Here is the caller graph for this function:

◆ isCreated()

bool QOpenGLBuffer::isCreated ( ) const

Returns true if this buffer has been created; false otherwise.

See also
create(), destroy()

Definition at line 304 of file qopenglbuffer.cpp.

References d.

Referenced by allocate(), bind(), QOpenGLTextureGlyphCache::createTextureData(), map(), mapRange(), release(), unmap(), and write().

+ Here is the caller graph for this function:

◆ map()

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.

Note
This function is only supported under OpenGL ES 2.0 or earlier if the GL_OES_mapbuffer extension is present.
On OpenGL ES 3.0 and newer, or, in case if desktop OpenGL, if GL_ARB_map_buffer_range is supported, this function uses glMapBufferRange instead of glMapBuffer.
See also
unmap(), create(), bind(), mapRange()

Definition at line 534 of file qopenglbuffer.cpp.

References d, isCreated(), QOpenGLExtensions::MapBufferRange, qWarning, RangeRead, RangeWrite, ReadOnly, ReadWrite, and WriteOnly.

+ Here is the call graph for this function:

◆ mapRange()

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.

Note
This function is not available on OpenGL ES 2.0 and earlier.
See also
unmap(), create(), bind()

Definition at line 575 of file qopenglbuffer.cpp.

References d, isCreated(), and qWarning.

+ Here is the call graph for this function:

◆ operator=()

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.

Since
6.5

Move-assigns other to this QOpenGLBuffer instance.

Note
The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

Definition at line 181 of file qopenglbuffer.cpp.

References QBasicAtomicInteger< T >::deref(), destroy(), other(), and QOpenGLBufferPrivate::ref.

+ Here is the call graph for this function:

◆ read()

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.

See also
write(), bind()

Definition at line 336 of file qopenglbuffer.cpp.

References QOpenGLFunctions::Buffers, d, error, GL_CONTEXT_LOST, GLenum(), and Q_UNUSED.

+ Here is the call graph for this function:

◆ release() [1/2]

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.

See also
bind()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ release() [2/2]

void QOpenGLBuffer::release ( QOpenGLBuffer::Type type)
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().

+ Here is the call graph for this function:

◆ setUsagePattern()

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().

See also
usagePattern(), allocate(), write()

Definition at line 251 of file qopenglbuffer.cpp.

References d.

◆ size()

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.

See also
isCreated(), bind()

Definition at line 506 of file qopenglbuffer.cpp.

References d, GL_BUFFER_SIZE, and GLint().

+ Here is the call graph for this function:

◆ swap()

QOpenGLBuffer::swap ( QOpenGLBuffer & other)
inlinenoexcept
Since
6.5

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().

+ Here is the call graph for this function:

◆ type()

QOpenGLBuffer::Type QOpenGLBuffer::type ( ) const

Returns the type of buffer represented by this object.

Definition at line 227 of file qopenglbuffer.cpp.

References d.

◆ unmap()

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().

Note
This function is only supported under OpenGL ES 2.0 and earlier if the {GL_OES_mapbuffer} extension is present.
See also
map()

Definition at line 600 of file qopenglbuffer.cpp.

References d, isCreated(), and qWarning.

+ Here is the call graph for this function:

◆ usagePattern()

QOpenGLBuffer::UsagePattern QOpenGLBuffer::usagePattern ( ) const

Returns the usage pattern for this buffer object.

The default value is StaticDraw.

See also
setUsagePattern()

Definition at line 239 of file qopenglbuffer.cpp.

References d.

◆ write()

void QOpenGLBuffer::write ( int offset,
const void * data,
int count )

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.

See also
create(), read(), allocate()

Definition at line 370 of file qopenglbuffer.cpp.

References d, isCreated(), and qWarning.

Referenced by QtWaylandClient::DecorationsBlitter::DecorationsBlitter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: