QOpenGLBuffer Class

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

Header: #include <QOpenGLBuffer>
qmake: QT += gui
Since: Qt 5.0

This class was introduced in Qt 5.0.

Public Types

enum Access { ReadOnly, WriteOnly, ReadWrite }
enum RangeAccessFlag { RangeRead, RangeWrite, RangeInvalidate, RangeInvalidateBuffer, RangeFlushExplicit, RangeUnsynchronized }
enum Type { VertexBuffer, IndexBuffer, PixelPackBuffer, PixelUnpackBuffer }
enum UsagePattern { StreamDraw, StreamRead, StreamCopy, StaticDraw, StaticRead, …, DynamicCopy }

Detailed Description

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 buffer1(QOpenGLBuffer::IndexBuffer);
     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.

Member Type Documentation

enum QOpenGLBuffer::Access

This enum defines the access mode for QOpenGLBuffer::map().

ConstantValueDescription
QOpenGLBuffer::ReadOnly0x88B8The buffer will be mapped for reading only.
QOpenGLBuffer::WriteOnly0x88B9The buffer will be mapped for writing only.
QOpenGLBuffer::ReadWrite0x88BAThe buffer will be mapped for reading and writing.

enum QOpenGLBuffer::RangeAccessFlag

This enum defines the access mode bits for QOpenGLBuffer::mapRange().

ConstantValueDescription
QOpenGLBuffer::RangeRead0x0001The buffer will be mapped for reading.
QOpenGLBuffer::RangeWrite0x0002The buffer will be mapped for writing.
QOpenGLBuffer::RangeInvalidate0x0004Discard the previous contents of the specified range.
QOpenGLBuffer::RangeInvalidateBuffer0x0008Discard the previous contents of the entire buffer.
QOpenGLBuffer::RangeFlushExplicit0x0010Indicates that modifications are to be flushed explicitly via glFlushMappedBufferRange.
QOpenGLBuffer::RangeUnsynchronized0x0020Indicates that pending operations should not be synchronized before returning from mapRange().

enum QOpenGLBuffer::Type

This enum defines the type of OpenGL buffer object to create with QOpenGLBuffer.

ConstantValueDescription
QOpenGLBuffer::VertexBuffer0x8892Vertex buffer object for use when specifying vertex arrays.
QOpenGLBuffer::IndexBuffer0x8893Index buffer object for use with glDrawElements().
QOpenGLBuffer::PixelPackBuffer0x88EBPixel pack buffer object for reading pixel data from the OpenGL server (for example, with glReadPixels()). Not supported under OpenGL/ES.
QOpenGLBuffer::PixelUnpackBuffer0x88ECPixel unpack buffer object for writing pixel data to the OpenGL server (for example, with glTexImage2D()). Not supported under OpenGL/ES.

enum QOpenGLBuffer::UsagePattern

This enum defines the usage pattern of a QOpenGLBuffer object.

ConstantValueDescription
QOpenGLBuffer::StreamDraw0x88E0The data will be set once and used a few times for drawing operations. Under OpenGL/ES 1.1 this is identical to StaticDraw.
QOpenGLBuffer::StreamRead0x88E1The data will be set once and used a few times for reading data back from the OpenGL server. Not supported under OpenGL/ES.
QOpenGLBuffer::StreamCopy0x88E2The 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.
QOpenGLBuffer::StaticDraw0x88E4The data will be set once and used many times for drawing operations.
QOpenGLBuffer::StaticRead0x88E5The data will be set once and used many times for reading data back from the OpenGL server. Not supported under OpenGL/ES.
QOpenGLBuffer::StaticCopy0x88E6The 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.
QOpenGLBuffer::DynamicDraw0x88E8The data will be modified repeatedly and used many times for drawing operations.
QOpenGLBuffer::DynamicRead0x88E9The data will be modified repeatedly and used many times for reading data back from the OpenGL server. Not supported under OpenGL/ES.
QOpenGLBuffer::DynamicCopy0x88EAThe 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.