织构#
- 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) -- 对象所属的上下文
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和驱动程序报告的最大样本容量之间。
- property glo: ctypes.c_uint#
OpenGL纹理ID
- 类型
GLuint
- 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 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
- 类型
应力
- write(data: Union[bytes, arcade.gl.buffer.Buffer, array.array], level: int = 0, viewport=None) None [源代码]#
将字节数据写入纹理。它可以是字节或
Buffer
。
- 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
- static delete_glo(ctx: Context, glo: ctypes.c_uint)[源代码]#
破坏纹理。当对对象进行垃圾回收时,会自动调用此方法。
- 参数
ctx (arcade.gl.Context) -- OpenGL上下文
glo (gl.GLuint) -- OpenGL纹理ID