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
QGles2Buffer Struct Reference

#include <qrhigles2_p.h>

+ Inheritance diagram for QGles2Buffer:
+ Collaboration diagram for QGles2Buffer:

Classes

struct  UsageState
 

Public Types

enum  Access {
  AccessNone , AccessVertex , AccessIndex , AccessUniform ,
  AccessStorageRead , AccessStorageWrite , AccessStorageReadWrite , AccessUpdate
}
 
- Public Types inherited from QRhiBuffer
enum  Type { Immutable , Static , Dynamic }
 Specifies storage type of buffer resource. More...
 
enum  UsageFlag { VertexBuffer = 1 << 0 , IndexBuffer = 1 << 1 , UniformBuffer = 1 << 2 , StorageBuffer = 1 << 3 }
 Flag values to specify how the buffer is going to be used. More...
 
- Public Types inherited from QRhiResource
enum  Type {
  Buffer , Texture , Sampler , RenderBuffer ,
  RenderPassDescriptor , SwapChainRenderTarget , TextureRenderTarget , ShaderResourceBindings ,
  GraphicsPipeline , SwapChain , ComputePipeline , CommandBuffer
}
 Specifies type of the resource. More...
 

Public Member Functions

 QGles2Buffer (QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
 
 ~QGles2Buffer ()
 
void destroy () override
 Releases (or requests deferred releasing of) the underlying native graphics resources.
 
bool create () override
 Creates the corresponding native graphics resources.
 
QRhiBuffer::NativeBuffer nativeBuffer () override
 
char * beginFullDynamicBufferUpdateForCurrentFrame () override
 
void endFullDynamicBufferUpdateForCurrentFrame () override
 To be called when the entire contents of the buffer data has been updated in the memory block returned from beginFullDynamicBufferUpdateForCurrentFrame().
 
- Public Member Functions inherited from QRhiBuffer
QRhiResource::Type resourceType () const override
 
Type type () const
 
void setType (Type t)
 Sets the buffer's type to t.
 
UsageFlags usage () const
 
void setUsage (UsageFlags u)
 Sets the buffer's usage flags to u.
 
quint32 size () const
 
void setSize (quint32 sz)
 Sets the size of the buffer in bytes.
 
- Public Member Functions inherited from QRhiResource
virtual ~QRhiResource ()
 Destructor.
 
void deleteLater ()
 When called without a frame being recorded, this function is equivalent to deleting the object.
 
QByteArray name () const
 
void setName (const QByteArray &name)
 Sets a name for the object.
 
quint64 globalResourceId () const
 
QRhirhi () const
 

Public Attributes

quint32 nonZeroSize = 0
 
GLuint buffer = 0
 
GLenum targetForDataOps
 
QByteArray data
 
UsageState usageState
 

Friends

class QRhiGles2
 

Additional Inherited Members

- Protected Member Functions inherited from QRhiBuffer
 QRhiBuffer (QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_)
 \variable QRhiBuffer::NativeBuffer::objects
 
- Protected Member Functions inherited from QRhiResource
 QRhiResource (QRhiImplementation *rhi)
 
- Protected Attributes inherited from QRhiBuffer
Type m_type
 
UsageFlags m_usage
 
quint32 m_size
 
- Protected Attributes inherited from QRhiResource
QRhiImplementationm_rhi = nullptr
 
quint64 m_id
 
QByteArray m_objectName
 

Detailed Description

Definition at line 32 of file qrhigles2_p.h.

Member Enumeration Documentation

◆ Access

Enumerator
AccessNone 
AccessVertex 
AccessIndex 
AccessUniform 
AccessStorageRead 
AccessStorageWrite 
AccessStorageReadWrite 
AccessUpdate 

Definition at line 46 of file qrhigles2_p.h.

Constructor & Destructor Documentation

◆ QGles2Buffer()

QGles2Buffer::QGles2Buffer ( QRhiImplementation * rhi,
Type type,
UsageFlags usage,
quint32 size )

Definition at line 5260 of file qrhigles2.cpp.

◆ ~QGles2Buffer()

QGles2Buffer::~QGles2Buffer ( )

Definition at line 5265 of file qrhigles2.cpp.

References destroy().

+ Here is the call graph for this function:

Member Function Documentation

◆ beginFullDynamicBufferUpdateForCurrentFrame()

char * QGles2Buffer::beginFullDynamicBufferUpdateForCurrentFrame ( )
overridevirtual
Returns
a pointer to a memory block with the host visible buffer data.

This is a shortcut for medium-to-large dynamic uniform buffers that have their entire contents (or at least all regions that are read by the shaders in the current frame) changed {in every frame} and the QRhiResourceUpdateBatch-based update mechanism is seen too heavy due to the amount of data copying involved.

The call to this function must be eventually followed by a call to endFullDynamicUniformBufferUpdateForCurrentFrame(), before recording any render or compute pass that relies on this buffer.

Warning
Updating data via this method is not compatible with QRhiResourceUpdateBatch-based updates and readbacks. Unexpected behavior may occur when attempting to combine the two update models for the same buffer. Similarly, the data updated this direct way may not be visible to \l{QRhiResourceUpdateBatch::readBackBuffer()}{readBackBuffer operations}, depending on the backend.
When updating buffer data via this method, the update must be done in every frame, otherwise backends that perform double or triple buffering of resources may end up in unexpected behavior.
Partial updates are not possible with this approach since some backends may choose a strategy where the previous contents of the buffer is lost upon calling this function. Data must be written to all regions that are read by shaders in the frame currently being prepared.
This function can only be called when recording a frame, so between QRhi::beginFrame() and QRhi::endFrame().
This function can only be called on Dynamic buffers.

Reimplemented from QRhiBuffer.

Definition at line 5337 of file qrhigles2.cpp.

References QRhiBuffer::Dynamic, GL_MAP_READ_BIT, GL_MAP_WRITE_BIT, QRhiBuffer::m_type, QRhiBuffer::m_usage, nonZeroSize, Q_ASSERT, QRHI_RES_RHI, targetForDataOps, and QRhiBuffer::UniformBuffer.

◆ create()

bool QGles2Buffer::create ( )
overridevirtual

Creates the corresponding native graphics resources.

If there are already resources present due to an earlier create() with no corresponding destroy(), then destroy() is called implicitly first.

Returns
true when successful, false when a graphics operation failed. Regardless of the return value, calling destroy() is always safe.

Implements QRhiBuffer.

Definition at line 5289 of file qrhigles2.cpp.

References QGles2Buffer::UsageState::access, AccessNone, QByteArray::constData(), destroy(), QRhiBuffer::Dynamic, GL_ARRAY_BUFFER, GL_BUFFER, GL_DYNAMIC_DRAW, GL_ELEMENT_ARRAY_BUFFER, GL_SHADER_STORAGE_BUFFER, GL_STATIC_DRAW, QRhiBuffer::IndexBuffer, QRhiResource::m_objectName, QRhiBuffer::m_size, QRhiBuffer::m_type, QRhiBuffer::m_usage, nonZeroSize, QRHI_RES_RHI, qWarning, QRhiBuffer::StorageBuffer, targetForDataOps, QRhiBuffer::UniformBuffer, and usageState.

+ Here is the call graph for this function:

◆ destroy()

void QGles2Buffer::destroy ( )
overridevirtual

Releases (or requests deferred releasing of) the underlying native graphics resources.

Safe to call multiple times, subsequent invocations will be a no-op then.

Once destroy() is called, the QRhiResource instance can be reused, by calling create() again. That will then result in creating new native graphics resources underneath.

Note
Resources referenced by commands for the current frame should not be released until the frame is submitted by QRhi::endFrame().

The QRhiResource destructor also performs the same task, so calling this function is not necessary before deleting a QRhiResource.

See also
deleteLater()

Implements QRhiResource.

Definition at line 5270 of file qrhigles2.cpp.

References buffer, QRhiGles2::DeferredReleaseEntry::Buffer, QRhiGles2::DeferredReleaseEntry::buffer, QRHI_RES_RHI, and QRhiGles2::DeferredReleaseEntry::type.

Referenced by ~QGles2Buffer(), and create().

+ Here is the caller graph for this function:

◆ endFullDynamicBufferUpdateForCurrentFrame()

void QGles2Buffer::endFullDynamicBufferUpdateForCurrentFrame ( )
overridevirtual

To be called when the entire contents of the buffer data has been updated in the memory block returned from beginFullDynamicBufferUpdateForCurrentFrame().

Reimplemented from QRhiBuffer.

Definition at line 5355 of file qrhigles2.cpp.

References QRhiBuffer::m_usage, nonZeroSize, QRHI_RES_RHI, targetForDataOps, and QRhiBuffer::UniformBuffer.

◆ nativeBuffer()

QRhiBuffer::NativeBuffer QGles2Buffer::nativeBuffer ( )
overridevirtual
Returns
the underlying native resources for this buffer. The returned value will be empty if exposing the underlying native resources is not supported by the backend.

A QRhiBuffer may be backed by multiple native buffer objects, depending on the type() and the QRhi backend in use. When this is the case, all of them are returned in the objects array in the returned struct, with slotCount specifying the number of native buffer objects. While \l{QRhi::beginFrame()}{recording a frame}, QRhi::currentFrameSlot() can be used to determine which of the native buffers QRhi is using for operations that read or write from this QRhiBuffer within the frame being recorded.

In some cases a QRhiBuffer will not be backed by a native buffer object at all. In this case slotCount will be set to 0 and no valid native objects are returned. This is not an error, and is perfectly valid when a given backend does not use native buffers for QRhiBuffers with certain types or usages.

Note
Be aware that QRhi backends may employ various buffer update strategies. Unlike textures, where uploading image data always means recording a buffer-to-image (or similar) copy command on the command buffer, buffers, in particular Dynamic and UniformBuffer ones, can operate in many different ways. For example, a QRhiBuffer with usage type UniformBuffer may not even be backed by a native buffer object at all if uniform buffers are not used or supported by a given backend and graphics API. There are also differences to how data is written to the buffer and the type of backing memory used. For buffers backed by host visible memory, calling this function guarantees that pending host writes are executed for all the returned native buffers.
See also
QRhi::currentFrameSlot(), QRhi::FramesInFlight

Reimplemented from QRhiBuffer.

Definition at line 5329 of file qrhigles2.cpp.

References QRhiBuffer::m_usage, and QRhiBuffer::UniformBuffer.

Friends And Related Symbol Documentation

◆ QRhiGles2

friend class QRhiGles2
friend

Definition at line 60 of file qrhigles2_p.h.

Member Data Documentation

◆ buffer

GLuint QGles2Buffer::buffer = 0

Definition at line 43 of file qrhigles2_p.h.

Referenced by destroy().

◆ data

QByteArray QGles2Buffer::data

Definition at line 45 of file qrhigles2_p.h.

◆ nonZeroSize

quint32 QGles2Buffer::nonZeroSize = 0

◆ targetForDataOps

GLenum QGles2Buffer::targetForDataOps

◆ usageState

UsageState QGles2Buffer::usageState

Definition at line 59 of file qrhigles2_p.h.

Referenced by create().


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