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 AttributeBufferObject

A buffer with system-memory backed store.

Updates to the data via set_data and set_data_region will be held in local memory until buffer_data is called. The advantage is that fewer OpenGL calls are needed, which can increasing performance at the expense of system memory.

__init__(size, attribute, usage=35048)
get_region(start, count)
invalidate()
invalidate_region(start, count)
resize(size)

Resize the buffer to a new size.

Parameters:
sizeint

New size of the buffer, in bytes

set_region(start, count, data)
sub_data()

Updates the buffer if any data has been changed or invalidated. Allows submitting multiple changes at once, rather than having to call glBufferSubData for every change.

class BufferObject

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 no get_region() method. See MappableVertexBufferObject for a Buffer class that does implement get_region().

__init__(size, usage=35048)
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.