pyglet.graphics.shader

exception ShaderException
class Attribute

映射缓冲区中属性的抽象访问器。

__init__(
name: str,
location: int,
count: int,
gl_type: int,
normalize: bool,
instance: bool,
) None

创建属性访问器。

参数:
  • name (str) -- 点属性的名称。

  • location (int) -- 点属性的位置(索引)。

  • count (int) -- 属性中的组件数量。

  • gl_type (int) -- GL类型列举数;例如, GL_FLOAT

  • normalize (bool) -- 如果GL应规范化值,则为真

  • instance (bool) -- 如果GL应将其视为实例化属性,则为真。

enable() None

启用该属性。

返回类型:

None

get_region(
buffer: AttributeBufferObject,
start: int,
count: int,
) Array[Type[_SimpleCData]]

使用此属性作为访问器映射缓冲区。

返回的区域由组件数据元素的连续数组组成。例如,如果此属性对每个顶点使用3个浮点数,而 count 参数为4,则映射的浮点数将为 3 * 4 = 12

参数:
  • buffer (AttributeBufferObject) -- 要映射的缓冲区。

  • start (int) -- 要映射的第一个顶点的偏移。

  • count (int) -- 要映射的顶点数

返回类型:

Array[Type[_SimpleCData]]

set_divisor() None
返回类型:

None

set_pointer(ptr: int) None

将此属性设置为指向给定偏移量处的当前绑定缓冲区。

offset 应基于当前绑定的缓冲区的 ptr 成员。

参数:

ptr (int) -- 指向此属性的当前绑定缓冲区的指针偏移量。

返回类型:

None

set_region(
buffer: AttributeBufferObject,
start: int,
count: int,
data: Sequence[float],
) None

将数据设置在缓冲区的一个区域上。

参数:
  • buffer (AttributeBufferObject) -- 要映射的缓冲区。

  • start (int) -- 要映射的第一个顶点的偏移。

  • count (int) -- 要映射的顶点数

  • data (Sequence[float]) -- 数据组件的序列。

返回类型:

None

buffer: AttributeBufferObject | None

缓冲区是在VertexDomain创建期间创建和附加的。

c_type: Type[_SimpleCData]
count: int
element_size: int
gl_type: int
instance: bool
location: int
name: str
normalize: bool
stride: int
class ComputeShaderProgram

GL计算着色器程序。

__init__(source: str) None

从源代码创建一个GL ComputeShaderProgram。

bind() None
返回类型:

None

delete() None
返回类型:

None

static dispatch(
x: int = 1,
y: int = 1,
z: int = 1,
barrier: int = 4294967295,
) None

启动一个或多个计算工作组。

在调用此方法之前,ComputeShaderProgram应处于活动(绑定)状态。X、y和z参数指定将在X、Y和Z维度上调度的本地工作组的数量。

返回类型:

None

static stop() None
返回类型:

None

static unbind() None
返回类型:

None

use() None
返回类型:

None

property id: int
max_shared_memory_size: int
max_work_group_count: tuple[int, int, int]
max_work_group_invocations: int
max_work_group_size: tuple[int, int, int]
property uniform_blocks: dict[str, UniformBlock]
property uniforms: dict[str, dict[str, Any]]
class Shader

OpenGL着色器。

着色器对象在实例化时编译。可以在多个ShaderProgram中重复使用一个Shader对象。

__init__(
source_string: str,
shader_type: Literal['vertex', 'fragment', 'geometry', 'compute', 'tesscontrol', 'tessevaluation'],
) None

初始化着色器类型。

参数:
  • source_string (str) -- 包含着色器程序源代码的字符串。

  • shader_type (Literal['vertex', 'fragment', 'geometry', 'compute', 'tesscontrol', 'tessevaluation']) --

    包含着色器程序类型的字符串:

    • 'vertex'

    • 'fragment'

    • 'geometry'

    • 'compute'

    • 'tesscontrol'

    • 'tessevaluation'

delete() None

初始化着色器。

这是无法挽回的。

返回类型:

None

property id: int
type: Literal['vertex', 'fragment', 'geometry', 'compute', 'tesscontrol', 'tessevaluation']
class ShaderProgram

OpenGL着色器程序。

__init__(*shaders: Shader) None

使用至少两个Shader实例初始化ShaderProgram。

bind() None
返回类型:

None

delete() None
返回类型:

None

static stop() None
返回类型:

None

static unbind() None
返回类型:

None

use() None
返回类型:

None

vertex_list(
count: int,
mode: int,
batch: Batch = None,
group: Group = None,
**data: Any,
) VertexList

创建顶点列表。

参数:
  • count (int) -- 列表中的顶点数。

  • mode (int) -- OpenGL绘图模式枚举;例如, GL_POINTSGL_LINESGL_TRIANGLES 等等。这决定了如何在给定批次中绘制列表。

  • batch (Batch) -- 要将顶点列表添加到的批处理,或 None 如果将不使用批次。强烈建议使用批处理。

  • group (Group) -- 要将顶点列表添加到的组,或 None 如果不需要任何组,则。

  • data (Any) -- 顶点列表的属性格式和初始数据。

返回类型:

VertexList

vertex_list_indexed(
count: int,
mode: int,
indices: Sequence[int],
batch: Batch = None,
group: Group = None,
**data: Any,
) IndexedVertexList

创建IndexedVertex List。

参数:
  • count (int) -- 列表中的顶点数。

  • mode (int) -- OpenGL绘图模式枚举;例如, GL_POINTSGL_LINESGL_TRIANGLES 等等。这决定了如何在给定批次中绘制列表。

  • indices (Sequence[int]) -- 给出顶点列表索引的整数序列。

  • batch (Batch) -- 要将顶点列表添加到的批处理,或 None 如果将不使用批次。强烈建议使用批处理。

  • group (Group) -- 要将顶点列表添加到的组,或 None 如果不需要任何组,则。

  • data (Any) -- 顶点列表的属性格式和初始数据。

返回类型:

IndexedVertexList

vertex_list_instanced(
count: int,
mode: int,
instance_attributes: Sequence[str],
batch: Batch = None,
group: Group = None,
**data: Any,
) VertexList
返回类型:

VertexList

vertex_list_instanced_indexed(
count: int,
mode: int,
indices: Sequence[int],
instance_attributes: Sequence[str],
batch: Batch = None,
group: Group = None,
**data: Any,
) IndexedVertexList
返回类型:

IndexedVertexList

property attributes: dict[str, Any]

属性元数据字典。

此属性返回一个字典,其中包含在此ShaderProgram中自省的所有属性的元数据。修改此词典不起作用。

property id: int
property uniform_blocks: dict[str, UniformBlock]

内省UniformBlocks的词典。

此属性返回 UniformBlock 实例。可以通过名称访问它们。例如::

block = my_shader_program.uniform_blocks['WindowBlock']
ubo = block.create_ubo()
property uniforms: dict[str, Any]

统一的元数据字典。

此属性返回一个字典,其中包含在此ShaderProgram中内省的所有制服的元数据。修改此词典不起作用。若要设置或获取统一名称,统一名称将用作ShaderProgram实例上的键。例如::

my_shader_program[uniform_name] = 123
value = my_shader_program[uniform_name]
class ShaderSource

用于简化源代码解析的GLSL源代码容器。

我们支持定位属性和应用#Defines值。

备注

我们确实假设源代码足够简洁,可以以这种方式解析,并且一行中不包含多个陈述。

__init__(source: str, source_type: c_uint) None

创建着色器源包装。

validate() str

返回经过验证的着色器源。

返回类型:

str

class UniformBlock
__init__(
program: ShaderProgram,
name: str,
index: int,
size: int,
binding: int,
uniforms: dict[int, tuple[str, Type[c_int] | Type[c_float] | Type[c_ubyte] | int, int]],
) None

初始化ShaderProgram的统一块。

create_ubo() UniformBufferObject

从此Uniform块创建新的UniformBufferObject。

返回类型:

UniformBufferObject

set_binding(binding: int) None

将统一块重新绑定到新的绑定索引号。

这只会影响此Uniform Block所源自的程序。

Binding value of 0 is reserved for the Pyglet's internal uniform block named WindowBlock. :rtype: None

警告

通过手动设置绑定,用户需要手动管理所有着色器程序的所有Uniform Block绑定。由于内部全局ID将不知道此函数设置的更改,因此如果您使用较低的数字,可能会发生冲突。

备注

你必须打电话给我 create_ubo 在调用此之后获取另一个统一缓冲区对象,因为之前的缓冲区仍然绑定到旧的绑定点。

binding: int
index: int
name: str
program: CallableProxyType[Callable[..., Any] | Any] | Any
size: int
uniforms: dict[int, tuple[str, GLDataType, int]]
view_cls: type[Structure] | None
class UniformBufferObject
__init__(
view_class: type[Structure],
buffer_size: int,
binding: int,
) None

使用指定的结构初始化统一缓冲区对象。

bind() None

将此缓冲区绑定到UniformBuffer父级建立的绑定点。

返回类型:

None

read() bytes

读取缓冲区的字节内容。

返回类型:

bytes

binding: int
buffer: BufferObject
property id: int

与此UBO关联的缓冲区ID。

view: Structure
get_maximum_binding_count() int

可用于此硬件的最大绑定值。

返回类型:

int