QOpenGLBuffer 类

QOpenGLBuffer 类提供用于创建和管理 OpenGL 缓冲对象的函数。 更多...

头: #include <QOpenGLBuffer>
CMake: find_package(Qt6 REQUIRED COMPONENTS OpenGL)
target_link_libraries(mytarget PRIVATE Qt6::OpenGL)
qmake: QT += opengl

公共类型

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

公共函数

QOpenGLBuffer ()
QOpenGLBuffer (QOpenGLBuffer::Type type )
QOpenGLBuffer (const QOpenGLBuffer & other )
(从 6.5 起) QOpenGLBuffer (QOpenGLBuffer && other )
~QOpenGLBuffer ()
void allocate (const void * data , int count )
void allocate (int count )
bool bind ()
GLuint bufferId () const
bool create ()
void destroy ()
bool isCreated () const
void * map (QOpenGLBuffer::Access access )
void * mapRange (int offset , int count , QOpenGLBuffer::RangeAccessFlags access )
bool read (int offset , void * data , int count )
void release ()
void setUsagePattern (QOpenGLBuffer::UsagePattern value )
int size () const
(从 6.5 起) void swap (QOpenGLBuffer & other )
QOpenGLBuffer::Type type () const
bool unmap ()
QOpenGLBuffer::UsagePattern usagePattern () const
void write (int offset , const void * data , int count )
QOpenGLBuffer & operator= (const QOpenGLBuffer & other )
(从 6.5 起) QOpenGLBuffer & operator= (QOpenGLBuffer && other )

静态公共成员

void release (QOpenGLBuffer::Type type )

详细描述

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.

成员类型文档编制

enum QOpenGLBuffer:: Access

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

常量 描述
QOpenGLBuffer::ReadOnly 0x88B8 The buffer will be mapped for reading only.
QOpenGLBuffer::WriteOnly 0x88B9 The buffer will be mapped for writing only.
QOpenGLBuffer::ReadWrite 0x88BA The buffer will be mapped for reading and writing.

enum QOpenGLBuffer:: RangeAccessFlag
flags QOpenGLBuffer:: RangeAccessFlags

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

常量 描述
QOpenGLBuffer::RangeRead 0x0001 The buffer will be mapped for reading.
QOpenGLBuffer::RangeWrite 0x0002 The buffer will be mapped for writing.
QOpenGLBuffer::RangeInvalidate 0x0004 Discard the previous contents of the specified range.
QOpenGLBuffer::RangeInvalidateBuffer 0x0008 Discard the previous contents of the entire buffer.
QOpenGLBuffer::RangeFlushExplicit 0x0010 Indicates that modifications are to be flushed explicitly via glFlushMappedBufferRange .
QOpenGLBuffer::RangeUnsynchronized 0x0020 Indicates that pending operations should not be synchronized before returning from mapRange ().

The RangeAccessFlags type is a typedef for QFlags <RangeAccessFlag>. It stores an OR combination of RangeAccessFlag values.

enum QOpenGLBuffer:: Type

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

常量 描述
QOpenGLBuffer::VertexBuffer 0x8892 Vertex buffer object for use when specifying vertex arrays.
QOpenGLBuffer::IndexBuffer 0x8893 Index buffer object for use with glDrawElements() .
QOpenGLBuffer::PixelPackBuffer 0x88EB Pixel pack buffer object for reading pixel data from the OpenGL server (for example, with glReadPixels() ). Not supported under OpenGL/ES.
QOpenGLBuffer::PixelUnpackBuffer 0x88EC Pixel 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 对象。

常量 描述
QOpenGLBuffer::StreamDraw 0x88E0 The data will be set once and used a few times for drawing operations. Under OpenGL/ES 1.1 this is identical to StaticDraw.
QOpenGLBuffer::StreamRead 0x88E1 The data will be set once and used a few times for reading data back from the OpenGL server. Not supported under OpenGL/ES.
QOpenGLBuffer::StreamCopy 0x88E2 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.
QOpenGLBuffer::StaticDraw 0x88E4 The data will be set once and used many times for drawing operations.
QOpenGLBuffer::StaticRead 0x88E5 The data will be set once and used many times for reading data back from the OpenGL server. Not supported under OpenGL/ES.
QOpenGLBuffer::StaticCopy 0x88E6 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.
QOpenGLBuffer::DynamicDraw 0x88E8 The data will be modified repeatedly and used many times for drawing operations.
QOpenGLBuffer::DynamicRead 0x88E9 The data will be modified repeatedly and used many times for reading data back from the OpenGL server. Not supported under OpenGL/ES.
QOpenGLBuffer::DynamicCopy 0x88EA 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.

成员函数文档编制

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 () 被调用。

另请参阅 create ().

[explicit] QOpenGLBuffer:: QOpenGLBuffer ( QOpenGLBuffer::Type type )

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 () 被调用。

另请参阅 create ().

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.

[noexcept, since 6.5] QOpenGLBuffer:: QOpenGLBuffer ( QOpenGLBuffer && other )

Move-constructs a new QOpenGLBuffer from other .

注意: 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.

该函数在 Qt 6.5 引入。

[noexcept] QOpenGLBuffer:: ~QOpenGLBuffer ()

Destroys this buffer object, including the storage being used in the OpenGL server.

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.

另请参阅 create (), read (),和 write ().

void QOpenGLBuffer:: allocate ( int count )

这是重载函数。

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.

另请参阅 create () 和 write ().

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.

另请参阅 release () 和 create ().

GLuint QOpenGLBuffer:: bufferId () const

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

另请参阅 isCreated ().

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 .

另请参阅 isCreated (), allocate (), write (),和 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.

bool QOpenGLBuffer:: isCreated () const

返回 true if this buffer has been created; false otherwise.

另请参阅 create () 和 destroy ().

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.

注意: 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 而不是 glMapBuffer .

另请参阅 unmap (), create (), bind (),和 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.

注意: This function is not available on OpenGL ES 2.0 and earlier.

另请参阅 unmap (), create (),和 bind ().

bool QOpenGLBuffer:: read ( int offset , void * data , int count )

读取 count bytes in this buffer starting at offset into data 。返回 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.

另请参阅 write () 和 bind ().

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.

另请参阅 bind ().

[static] void QOpenGLBuffer:: release ( QOpenGLBuffer::Type type )

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.

QOpenGLBuffer::release(QOpenGLBuffer::VertexBuffer);
					

void QOpenGLBuffer:: setUsagePattern ( QOpenGLBuffer::UsagePattern value )

Sets the usage pattern for this buffer object to value . This function must be called before allocate () 或 write ().

另请参阅 usagePattern (), allocate (),和 write ().

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.

另请参阅 isCreated () 和 bind ().

[noexcept, since 6.5] void QOpenGLBuffer:: swap ( QOpenGLBuffer & other )

Swaps buffer other with this buffer. This operation is very fast and never fails.

该函数在 Qt 6.5 引入。

QOpenGLBuffer::Type QOpenGLBuffer:: type () const

Returns the type of buffer represented by this object.

bool QOpenGLBuffer:: unmap ()

Unmaps the buffer after it was mapped into the application's memory space with a previous call to map ()。返回 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 ().

注意: This function is only supported under OpenGL ES 2.0 and earlier if the GL_OES_mapbuffer extension is present.

另请参阅 map ().

QOpenGLBuffer::UsagePattern QOpenGLBuffer:: usagePattern () const

Returns the usage pattern for this buffer object. The default value is StaticDraw .

另请参阅 setUsagePattern ().

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.

另请参阅 create (), read (),和 allocate ().

QOpenGLBuffer &QOpenGLBuffer:: operator= (const QOpenGLBuffer & other )

Assigns a shallow copy of other 到此对象。

注意: QOpenGLBuffer does not implement copy-on-write semantics, so other will be affected whenever the copy is modified.

[noexcept, since 6.5] QOpenGLBuffer &QOpenGLBuffer:: operator= ( QOpenGLBuffer && other )

移动赋值 other 到此 QOpenGLBuffer 实例。

注意: 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.

该函数在 Qt 6.5 引入。