Access byte arrays as arrays of vertex attributes.
Use create_attribute()
to create an attribute accessor given a
simple format string. Alternatively, the classes may be constructed directly.
An attribute format string specifies the format of a vertex attribute. Format
strings are accepted by the create_attribute()
function as well as most
methods in the pyglet.graphics
module.
Format strings have the following (BNF) syntax:
attribute ::= ( name | index 'g' 'n'? | texture 't' ) count type
name
describes the vertex attribute, and is one of the following
constants for the predefined attributes:
c
e
f
n
s
t
v
You can alternatively create a generic indexed vertex attribute by
specifying its index in decimal followed by the constant g
. For
example, 0g
specifies the generic vertex attribute with index 0.
If the optional constant n
is present after the g
, the
attribute is normalised to the range [0, 1]
or [-1, 1]
within
the range of the data type.
Texture coordinates for multiple texture units can be specified with the
texture number before the constant ‘t’. For example, 1t
gives the
texture coordinate attribute for texture unit 1.
count
gives the number of data components in the attribute. For
example, a 3D vertex position has a count of 3. Some attributes
constrain the possible counts that can be used; for example, a normal
vector must have a count of 3.
type
gives the data type of each component of the attribute. The
following types can be used:
b
GLbyte
B
GLubyte
s
GLshort
S
GLushort
i
GLint
I
GLuint
f
GLfloat
d
GLdouble
Some attributes constrain the possible data types; for example,
normal vectors must use one of the signed data types. The use of
some data types, while not illegal, may have severe performance
concerns. For example, the use of GLdouble
is discouraged,
and colours should be specified with GLubyte
.
Whitespace is prohibited within the format string.
Some examples follow:
v3f
c4b
1eb
0g3f
1gn1i
2gn4B
3t2f
AbstractAttribute
(count, gl_type)¶Abstract accessor for an attribute in a mapped buffer.
enable
()¶Enable the attribute using glEnableClientState
.
get_region
(buffer, start, count)¶Map a buffer region using this attribute as an accessor.
The returned region can be modified as if the buffer was a contiguous array of this attribute (though it may actually be interleaved or otherwise non-contiguous).
The returned region consists of a contiguous array of component
data elements. For example, if this attribute uses 3 floats per
vertex, and the count parameter is 4, the number of floats mapped
will be 3 * 4 = 12
.
Parameters: |
|
---|---|
Return type: | AbstractBufferRegion |
set_pointer
(offset)¶Setup this attribute to point to the currently bound buffer at the given offset.
offset
should be based on the currently bound buffer’s ptr
member.
Parameters: | offset (int) – Pointer offset to the currently bound buffer for this attribute. |
---|
set_region
(buffer, start, count, data)¶Set the data over a region of the buffer.
Parameters: |
|
---|
ColorAttribute
(count, gl_type)¶Color vertex attribute.
enable
()¶set_pointer
(pointer)¶plural
= ‘colors’¶EdgeFlagAttribute
(gl_type)¶Edge flag attribute.
enable
()¶set_pointer
(pointer)¶plural
= ‘edge_flags’¶FogCoordAttribute
(count, gl_type)¶Fog coordinate attribute.
enable
()¶set_pointer
(pointer)¶plural
= ‘fog_coords’¶GenericAttribute
(index, normalized, count, gl_type)¶Generic vertex attribute, used by shader programs.
enable
()¶set_pointer
(pointer)¶MultiTexCoordAttribute
(texture, count, gl_type)¶Texture coordinate attribute.
enable
()¶set_pointer
(pointer)¶NormalAttribute
(gl_type)¶Normal vector attribute.
enable
()¶set_pointer
(pointer)¶plural
= ‘normals’¶SecondaryColorAttribute
(gl_type)¶Secondary color attribute.
enable
()¶set_pointer
(pointer)¶plural
= ‘secondary_colors’¶TexCoordAttribute
(count, gl_type)¶Texture coordinate attribute.
convert_to_multi_tex_coord_attribute
()¶Changes the class of the attribute to MultiTexCoordAttribute.
enable
()¶set_pointer
(pointer)¶plural
= ‘tex_coords’¶VertexAttribute
(count, gl_type)¶Vertex coordinate attribute.
enable
()¶set_pointer
(pointer)¶plural
= ‘vertices’¶create_attribute
(format)¶Create a vertex attribute description from a format string.
The initial stride and offset of the attribute will be 0.
Parameters: | format (str) – Attribute format string. See the module summary for details. |
---|---|
Return type: | AbstractAttribute |
interleave_attributes
(attributes)¶Interleave attribute offsets.
Adjusts the offsets and strides of the given attributes so that they are interleaved. Alignment constraints are respected.
Parameters: | attributes (sequence of AbstractAttribute) – Attributes to interleave in-place. |
---|
serialize_attributes
(count, attributes)¶Serialize attribute offsets.
Adjust the offsets of the given attributes so that they are packed serially against each other for count vertices.
Parameters: |
|
---|