织构#

class arcade.gl.Texture(ctx: Context, size: Tuple[int, int], *, components: int = 4, dtype: str = 'f1', data: Any = None, filter: Tuple[ctypes.c_uint, ctypes.c_uint] = None, wrap_x: ctypes.c_uint = None, wrap_y: ctypes.c_uint = None, target=3553, depth=False, samples: int = 0)[源代码]#

基类:object

OpenGL 2D纹理。我们可以创建空的黑色纹理或从字节数据创建纹理。也可以使用不同的数据类型创建纹理,例如浮点型、整型或无符号整型。

注意:当前不支持多采样纹理,尽管 _samples 已经设置好了。

创建纹理实例的最佳方法是通过 arcade.gl.Context.texture()

支撑点 dtype 值为:

# Float formats
'f1': UNSIGNED_BYTE
'f2': HALF_FLOAT
'f4': FLOAT
# int formats
'i1': BYTE
'i2': SHORT
'i4': INT
# uint formats
'u1': UNSIGNED_BYTE
'u2': UNSIGNED_SHORT
'u4': UNSIGNED_INT
参数
  • ctx (Context) -- 对象所属的上下文

  • size (Tuple[int, int]) -- 纹理的大小

  • components (int) -- 组件数量(1:R、2:RG、3:RGB、4:RGBA)

  • dtype (str) -- 各组件的数据类型:f1、f2、f4/i1、i2、i4/u1、u2、u4

  • data (Any) -- 纹理数据(可选)。可以是字节,也可以是支持缓冲区协议的任何对象。

  • data -- 纹理的字节数据。字节或任何支持缓冲区协议的内容。

  • filter (Tuple[gl.GLuint,gl.GLuint]) -- 纹理的缩小/放大滤镜

  • wrap_x (gl.GLuint) -- 换行模式x

  • wrap_y (gl.GLuint) -- 换行模式y

  • target (int) -- 纹理类型(忽略。传统)

  • depth (bool) -- 在以下情况下创建深度纹理 True

  • samples (int) -- 为大于0的值创建多采样纹理。该值将被限制在0和驱动程序报告的最大样本容量之间。

resize(size: Tuple[int, int])[源代码]#

调整纹理大小。这将重新分配内部内存,所有像素数据都将丢失。

property ctx: Context#

此纹理所属的上下文

类型

Context

property glo: ctypes.c_uint#

OpenGL纹理ID

类型

GLuint

property width: int#

纹理的宽度(以像素为单位

类型

集成

property height: int#

纹理的高度,以像素为单位

类型

集成

property dtype: str#

每个组件的数据类型

类型

应力

property size: Tuple[int, int]#

元组形式的纹理大小

类型

元组(宽、高)

property samples: int#

启用多重采样时的样本数(只读)

类型

集成

property byte_size: int#

纹理的字节大小。

类型

集成

property components: int#

纹理中的组件数量

类型

集成

property depth: bool#

如果这是深度纹理。

类型

布尔尔

property swizzle: str#

Str:纹理的swizzle遮罩(默认 'RGBA' )。

Swizzle遮罩更改/重新排序 vec4 方法返回的值 texture() 函数在GLSL着色器中。这由4个字符的字符串表示,其中每个字符可以是::

'R' GL_RED
'G' GL_GREEN
'B' GL_BLUE
'A' GL_ALPHA
'0' GL_ZERO
'1' GL_ONE

示例::

# Alpha channel will always return 1.0
texture.swizzle = 'RGB1'

# Only return the red component. The rest is masked to 0.0
texture.swizzle = 'R000'

# Reverse the components
texture.swizzle = 'ABGR'        
property filter: Tuple[int, int]#

获取或设置 (min, mag) 此纹理的过滤器。这些是纹理如何进行内插的规则。滤镜是为缩小和放大指定的。

默认值为 LINEAR, LINEAR 。可以设置为 NEAREST, NEAREST 用于像素化图形。

使用mipmap时,最小筛选器需要是 MIPMAP 变式。

接受的值::

# Enums can be accessed on the context or arcade.gl
NEAREST                # Nearest pixel
LINEAR                 # Linear interpolate
NEAREST_MIPMAP_NEAREST # Minification filter for mipmaps
LINEAR_MIPMAP_NEAREST  # Minification filter for mipmaps
NEAREST_MIPMAP_LINEAR  # Minification filter for mipmaps
LINEAR_MIPMAP_LINEAR   # Minification filter for mipmaps

另请参阅

类型

元组(最小过滤器、最大过滤器)

property wrap_x: int#

获取或设置纹理的水平换行。这决定了当纹理坐标位于 [0.0, 1.0] 区域。默认值为 REPEAT

有效选项包括:

# Note: Enums can also be accessed in arcade.gl
# Repeat pixels on the y axis
texture.wrap_x = ctx.REPEAT
# Repeat pixels on the y axis mirrored
texture.wrap_x = ctx.MIRRORED_REPEAT
# Repeat the edge pixels when reading outside the texture
texture.wrap_x = ctx.CLAMP_TO_EDGE
# Use the border color (black by default) when reading outside the texture
texture.wrap_x = ctx.CLAMP_TO_BORDER
类型

集成

property wrap_y: int#

获取或设置纹理的水平换行。这决定了当纹理坐标位于 [0.0, 1.0] 区域。默认值为 REPEAT

有效选项包括:

# Note: Enums can also be accessed in arcade.gl
# Repeat pixels on the x axis
texture.wrap_x = ctx.REPEAT
# Repeat pixels on the x axis mirrored
texture.wrap_x = ctx.MIRRORED_REPEAT
# Repeat the edge pixels when reading outside the texture
texture.wrap_x = ctx.CLAMP_TO_EDGE
# Use the border color (black by default) when reading outside the texture
texture.wrap_x = ctx.CLAMP_TO_BORDER
类型

集成

property anisotropy: float#

获取或设置此纹理的各向异性。

property compare_func: Optional[str]#

获取或设置深度纹理的比较函数::

texture.compare_func = None  # Disable depth comparison completely
texture.compare_func = '<='  # GL_LEQUAL
texture.compare_func = '<'   # GL_LESS
texture.compare_func = '>='  # GL_GEQUAL
texture.compare_func = '>'   # GL_GREATER
texture.compare_func = '=='  # GL_EQUAL
texture.compare_func = '!='  # GL_NOTEQUAL
texture.compare_func = '0'   # GL_NEVER
texture.compare_func = '1'   # GL_ALWAYS
类型

应力

read(level: int = 0, alignment: int = 1) bytearray[源代码]#

阅读纹理的内容。

参数
  • level (int) -- 要读取的纹理级别

  • alignment (int) -- 内存中每行起始位置的对齐方式(以字节数表示)。可能的值:1、2、4

返回类型

bytearray

write(data: Union[bytes, arcade.gl.buffer.Buffer, array.array], level: int = 0, viewport=None) None[源代码]#

将字节数据写入纹理。它可以是字节或 Buffer

参数
  • data (Union[bytes,Buffer]) -- 字节或包含要写入数据的缓冲区

  • level (int) -- 要写入的纹理级别

  • viewport (tuple) -- 这些都是适合写作的质地。2个或4个组件元组

build_mipmaps(base: int = 0, max_level: int = 1000) None[源代码]#

为该纹理生成mipmap。保留默认参数通常会起到作用。构建mipmap将创建几个较小的纹理版本(256 x 256、128 x 128、64 x 64、32 x 32等),帮助OpenGL在以较小版本渲染到屏幕时渲染更好的纹理版本。

请注意,仅当纹理过滤器配置了mipmap类型的缩小时,才会使用mipmap:

# Set up linear interpolating minification filter
texture.filter = ctx.LINEAR_MIPMAP_LINEAR, ctx.LINEAR
参数
  • base (int) -- Mipmap的级别开始于(通常为0)

  • max_level (int) -- 要生成的最大级别

另请参阅:https://www.khronos.org/opengl/wiki/Texture#Mip_maps

delete()[源代码]#

销毁底层OpenGL资源。除非你清楚地知道自己在做什么,否则不要使用这个。

static delete_glo(ctx: Context, glo: ctypes.c_uint)[源代码]#

破坏纹理。当对对象进行垃圾回收时,会自动调用此方法。

参数
use(unit: int = 0) None[源代码]#

将纹理绑定到通道,

参数

unit (int) -- 绑定纹理的纹理单元。

bind_to_image(unit: int, read: bool = True, write: bool = True, level: int = 0)[源代码]#

将纹理绑定到图像单位。

请注意,其中一个或两个都是 readwrite 需要是 True 。支持的模式有:只读、只写、读写

参数
  • unit (int) -- 图像单元

  • read (bool) -- 计算着色器打算从该图像中读取

  • write (bool) -- 计算着色器打算写入此图像

  • level (int) --