pyglet.graphics.vertexbuffer
Byte abstractions of OpenGL Buffer Objects.
Use create_buffer to create a Buffer Object.
Buffers can optionally be created “mappable” (incorporating the
AbstractMappable mix-in). In this case the buffer provides a get_region
method which provides the most efficient path for updating partial data within
the buffer.
- class AbstractBuffer
Abstract buffer of byte data.
- Ivariables
- sizeint
Size of buffer, in bytes
- ptrint
Memory offset of the buffer, as used by the
glVertexPointer
family of functions- usageint
OpenGL buffer usage, for example
GL_DYNAMIC_DRAW
- bind(target=34962)
Bind this buffer to an OpenGL target.
- delete()
Delete this buffer, reducing system resource usage.
- map()
Map the entire buffer into system memory.
The mapped region must be subsequently unmapped with unmap before performing any other operations on the buffer.
- Parameters
- invalidatebool
If True, the initial contents of the mapped block need not reflect the actual contents of the buffer.
- Return type
POINTER(ctypes.c_ubyte)
- Returns
Pointer to the mapped block in memory
- resize(size)
Resize the buffer to a new size.
- Parameters
- sizeint
New size of the buffer, in bytes
- set_data(data)
Set the entire contents of the buffer.
- Parameters
- datasequence of int or ctypes pointer
The byte array to set.
- set_data_region(data, start, length)
Set part of the buffer contents.
- Parameters
- datasequence of int or ctypes pointer
The byte array of data to set
- startint
Offset to start replacing data
- lengthint
Length of region to replace
- unbind()
Reset the buffer’s OpenGL target.
- unmap()
Unmap a previously mapped memory block.
- ptr = 0
- size = 0
- class AbstractMappable
- get_region(start, size, ptr_type)
Map a region of the buffer into a ctypes array of the desired type. This region does not need to be unmapped, but will become invalid if the buffer is resized.
Note that although a pointer type is required, an array is mapped. For example:
get_region(0, ctypes.sizeof(c_int) * 20, ctypes.POINTER(c_int * 20))
will map bytes 0 to 80 of the buffer to an array of 20 ints.
Changes to the array may not be recognised until the region’s
AbstractBufferRegion.invalidate()
method is called.- Parameters
- startint
Offset into the buffer to map from, in bytes
- sizeint
Size of the buffer region to map, in bytes
- ptr_typectypes pointer type
Pointer type describing the array format to create
- Return type
AbstractBufferRegion
- class BufferObject(size, usage=35048)
Lightweight representation of an OpenGL Buffer Object.
The data in the buffer is not replicated in any system memory (unless it is done so by the video driver). While this can improve memory usage and possibly performance, updates to the buffer are relatively slow. The target of the buffer is
GL_ARRAY_BUFFER
internally to avoid accidentally overriding other states when altering the buffer contents. The intended target can be set when binding the buffer.This class does not implement
AbstractMappable
, and so has noget_region()
method. SeeMappableVertexBufferObject
for a Buffer class that does implementget_region()
.- bind(target=34962)
Bind this buffer to an OpenGL target.
- bind_to_index_buffer()
Binds this buffer as an index buffer on the active vertex array.
- delete()
Delete this buffer, reducing system resource usage.
- invalidate()
- map()
Map the entire buffer into system memory.
The mapped region must be subsequently unmapped with unmap before performing any other operations on the buffer.
- Parameters
- invalidatebool
If True, the initial contents of the mapped block need not reflect the actual contents of the buffer.
- Return type
POINTER(ctypes.c_ubyte)
- Returns
Pointer to the mapped block in memory
- map_range(start, size, ptr_type)
- resize(size)
Resize the buffer to a new size.
- Parameters
- sizeint
New size of the buffer, in bytes
- set_data(data)
Set the entire contents of the buffer.
- Parameters
- datasequence of int or ctypes pointer
The byte array to set.
- set_data_region(data, start, length)
Set part of the buffer contents.
- Parameters
- datasequence of int or ctypes pointer
The byte array of data to set
- startint
Offset to start replacing data
- lengthint
Length of region to replace
- unbind()
Reset the buffer’s OpenGL target.
- unmap()
Unmap a previously mapped memory block.
- class BufferObjectRegion(buffer, start, end, array)
A mapped region of a MappableBufferObject.
- invalidate()
Mark this region as changed.
The buffer may not be updated with the latest contents of the array until this method is called. (However, it may not be updated until the next time the buffer is used, for efficiency).
- array
- buffer
- end
- start
- class MappableBufferObject(size, usage=35048)
A buffer with system-memory backed store.
Updates to the data via set_data, set_data_region and map will be held in local memory until bind is called. The advantage is that fewer OpenGL calls are needed, increasing performance.
There may also be less performance penalty for resizing this buffer.
Updates to data via
map()
are committed immediately.- bind()
Bind this buffer to an OpenGL target.
- get_region(start, size, ptr_type)
Map a region of the buffer into a ctypes array of the desired type. This region does not need to be unmapped, but will become invalid if the buffer is resized.
Note that although a pointer type is required, an array is mapped. For example:
get_region(0, ctypes.sizeof(c_int) * 20, ctypes.POINTER(c_int * 20))
will map bytes 0 to 80 of the buffer to an array of 20 ints.
Changes to the array may not be recognised until the region’s
AbstractBufferRegion.invalidate()
method is called.- Parameters
- startint
Offset into the buffer to map from, in bytes
- sizeint
Size of the buffer region to map, in bytes
- ptr_typectypes pointer type
Pointer type describing the array format to create
- Return type
AbstractBufferRegion
- map(invalidate=False)
Map the entire buffer into system memory.
The mapped region must be subsequently unmapped with unmap before performing any other operations on the buffer.
- Parameters
- invalidatebool
If True, the initial contents of the mapped block need not reflect the actual contents of the buffer.
- Return type
POINTER(ctypes.c_ubyte)
- Returns
Pointer to the mapped block in memory
- resize(size)
Resize the buffer to a new size.
- Parameters
- sizeint
New size of the buffer, in bytes
- set_data(data)
Set the entire contents of the buffer.
- Parameters
- datasequence of int or ctypes pointer
The byte array to set.
- set_data_region(data, start, length)
Set part of the buffer contents.
- Parameters
- datasequence of int or ctypes pointer
The byte array of data to set
- startint
Offset to start replacing data
- lengthint
Length of region to replace
- unmap()
Unmap a previously mapped memory block.