- class QOpenGLBuffer¶
The
QOpenGLBuffer
class provides functions for creating and managing OpenGL buffer objects. More…Synopsis¶
Methods¶
def
__init__()
def
allocate()
def
bind()
def
bufferId()
def
create()
def
destroy()
def
isCreated()
def
map()
def
mapRange()
def
read()
def
release()
def
size()
def
swap()
def
type()
def
unmap()
def
usagePattern()
def
write()
Static functions¶
def
release()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 = QOpenGLBuffer(QOpenGLBuffer.IndexBuffer) buffer1.create() 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.- class Type¶
This enum defines the type of OpenGL buffer object to create with
QOpenGLBuffer
.Constant
Description
QOpenGLBuffer.VertexBuffer
Vertex buffer object for use when specifying vertex arrays.
QOpenGLBuffer.IndexBuffer
Index buffer object for use with
glDrawElements()
.QOpenGLBuffer.PixelPackBuffer
Pixel pack buffer object for reading pixel data from the OpenGL server (for example, with
glReadPixels()
). Not supported under OpenGL/ES.QOpenGLBuffer.PixelUnpackBuffer
Pixel unpack buffer object for writing pixel data to the OpenGL server (for example, with
glTexImage2D()
). Not supported under OpenGL/ES.
- class UsagePattern¶
This enum defines the usage pattern of a
QOpenGLBuffer
object.Constant
Description
QOpenGLBuffer.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.
QOpenGLBuffer.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.
QOpenGLBuffer.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.
QOpenGLBuffer.StaticDraw
The data will be set once and used many times for drawing operations.
QOpenGLBuffer.StaticRead
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
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
The data will be modified repeatedly and used many times for drawing operations.
QOpenGLBuffer.DynamicRead
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
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.
- class Access¶
This enum defines the access mode for
map()
.Constant
Description
QOpenGLBuffer.ReadOnly
The buffer will be mapped for reading only.
QOpenGLBuffer.WriteOnly
The buffer will be mapped for writing only.
QOpenGLBuffer.ReadWrite
The buffer will be mapped for reading and writing.
- class RangeAccessFlag¶
(inherits
enum.Flag
) This enum defines the access mode bits formapRange()
.Constant
Description
QOpenGLBuffer.RangeRead
The buffer will be mapped for reading.
QOpenGLBuffer.RangeWrite
The buffer will be mapped for writing.
QOpenGLBuffer.RangeInvalidate
Discard the previous contents of the specified range.
QOpenGLBuffer.RangeInvalidateBuffer
Discard the previous contents of the entire buffer.
QOpenGLBuffer.RangeFlushExplicit
Indicates that modifications are to be flushed explicitly via
glFlushMappedBufferRange
.QOpenGLBuffer.RangeUnsynchronized
Indicates that pending operations should not be synchronized before returning from
mapRange()
.
- __init__()¶
Constructs a new buffer object of type
VertexBuffer
.Note: this constructor just creates the
QOpenGLBuffer
instance. The actual buffer object in the OpenGL server is not created untilcreate()
is called.See also
- __init__(type)
- Parameters:
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 untilcreate()
is called.See also
- __init__(other)
- Parameters:
other –
QOpenGLBuffer
Constructs a shallow copy of
other
.Note:
QOpenGLBuffer
does not implement copy-on-write semantics, soother
will be affected whenever the copy is modified.- allocate(count)¶
- Parameters:
count – int
This is an overloaded function.
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.- allocate(data, count)
- Parameters:
data –
void
count – int
Allocates
count
bytes of space to the buffer, initialized to the contents ofdata
. 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.- bind()¶
- Return type:
bool
Binds the buffer associated with this object to the current OpenGL context. Returns
false
if binding was not possible, usually becausetype()
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.- bufferId()¶
- Return type:
int
Returns the OpenGL identifier associated with this buffer; zero if the buffer has not been created.
See also
- create()¶
- Return type:
bool
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
- destroy()¶
Destroys this buffer object, including the storage being used in the OpenGL server. All references to the buffer will become invalid.
- isCreated()¶
- Return type:
bool
Returns
true
if this buffer has been created; false otherwise.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.Note
On OpenGL ES 3.0 and newer, or, in case if desktop OpenGL, if
GL_ARB_map_buffer_range
is supported, this function usesglMapBufferRange
instead ofglMapBuffer
.See also
- mapRange(offset, count, access)¶
- Parameters:
offset – int
count – int
access – Combination of
RangeAccessFlag
- Return type:
void
Maps the range specified by
offset
andcount
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. Theaccess
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.- read(offset, data, count)¶
- Parameters:
offset – int
data –
void
count – int
- Return type:
bool
Reads the
count
bytes in this buffer starting atoffset
intodata
. Returnstrue
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.
- 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
- static release(type)
- Parameters:
type –
Type
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 whichQOpenGLBuffer
has been bound to the context but wants to make sure that it is released.QOpenGLBuffer.release(QOpenGLBuffer.VertexBuffer)
- setUsagePattern(value)¶
- Parameters:
value –
UsagePattern
Sets the usage pattern for this buffer object to
value
. This function must be called beforeallocate()
orwrite()
.See also
- size()¶
- Return type:
int
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
- swap(other)¶
- Parameters:
other –
QOpenGLBuffer
Swaps buffer
other
with this buffer. This operation is very fast and never fails.Returns the type of buffer represented by this object.
- unmap()¶
- Return type:
bool
Unmaps the buffer after it was mapped into the application’s memory space with a previous call to
map()
. Returnstrue
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
- usagePattern()¶
- Return type:
Returns the usage pattern for this buffer object. The default value is
StaticDraw
.See also
- write(offset, data, count)¶
- Parameters:
offset – int
data –
void
count – int
Replaces the
count
bytes of this buffer starting atoffset
with the contents ofdata
. 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