Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

DrawableTexture2D

继承: Texture2D < Texture < Resource < RefCounted < Object

一种支持通过 Blit 调用对自身进行绘制的 2D 纹理。

描述

一种可以通过 blit 调用进行修改的 2D 纹理,它能够将目标纹理的内容复制到自身上。这种纹理主要设计用于代码中进行管理,用户必须先调用 setup() 来初始化状态,然后才能开始绘制。每一次 blit_rect() 调用至少需要传入一个矩形(指定绘制的目标区域)以及另一张纹理(作为绘制的内容来源)。这些绘制调用会使用一个名为 Texture_Blit 的着色器(Shader)来逐像素处理和计算最终结果。用户也可以提供自己编写的 ShaderMaterial,配合自定义的 Texture_Blit 着色器来实现更复杂的绘制行为。

属性

bool

resource_local_to_scene

false (overrides Resource)

方法

void

blit_rect(rect: Rect2i, source: Texture2D, modulate: Color = Color(1, 1, 1, 1), mipmap: int = 0, material: Material = null)

void

blit_rect_multi(rect: Rect2i, sources: Array[Texture2D], extra_targets: Array[DrawableTexture2D], modulate: Color = Color(1, 1, 1, 1), mipmap: int = 0, material: Material = null)

void

generate_mipmaps()

bool

get_use_mipmaps() const

void

set_format(format: DrawableFormat)

void

set_use_mipmaps(mipmaps: bool)

void

setup(width: int, height: int, format: DrawableFormat, color: Color = Color(1, 1, 1, 1), use_mipmaps: bool = false)


枚举

enum DrawableFormat: 🔗

DrawableFormat DRAWABLE_FORMAT_RGBA8 = 0

一种具有四个分量的 OpenGL 纹理格式 RGBA,每个分量的位深度均为 8 位。

DrawableFormat DRAWABLE_FORMAT_RGBA8_SRGB = 1

一种具有四个分量、每个分量位深度均为 8 位的 OpenGL RGBA 纹理格式。

当向其进行绘制时,会执行从 sRGB 到线性颜色空间的转换。

DrawableFormat DRAWABLE_FORMAT_RGBAH = 2

一种 OpenGL 纹理格式 GL_RGBA16F,它包含四个分量,每个分量都是一个 16 位的 "半精度" 浮点数值。

DrawableFormat DRAWABLE_FORMAT_RGBAF = 3

一种 OpenGL 纹理格式 GL_RGBA32F,它包含四个分量,每个分量都是一个 32 位的浮点数值。


方法说明

void blit_rect(rect: Rect2i, source: Texture2D, modulate: Color = Color(1, 1, 1, 1), mipmap: int = 0, material: Material = null) 🔗

实验性: This function and its parameters are likely to change in the 4.7 Dev Cycle

通过从指定的 source(源纹理)复制内容,绘制到本纹理的指定 rect(矩形区域)上。可以传入一个 modulate(调制)颜色供着色器使用,默认值为白色。mipmap 值可以指定将内容绘制到更低的 mipmap 层级上。material 参数可以接收一个带有 TextureBlit 着色器的 ShaderMaterial,从而实现自定义的绘制行为。


void blit_rect_multi(rect: Rect2i, sources: Array[Texture2D], extra_targets: Array[DrawableTexture2D], modulate: Color = Color(1, 1, 1, 1), mipmap: int = 0, material: Material = null) 🔗

实验性: This function and its parameters are likely to change in the 4.7 Dev Cycle

绘制到本纹理的指定 rect(矩形区域)上,同时也会绘制到最多 3 个 DrawableTexture extra_targets(额外目标)上。所有 extra_targets 必须与原始目标(也就是调用该方法的纹理本身)具有相同的大小和 DrawableFormat(可绘制格式),否则着色器(Shader)可能会运行失败。该方法最多支持传入 4 张 Texture sources(源纹理),如果传入的源纹理不足 4 张,缺失的部分将会自动替换为默认的黑色纹理。


void generate_mipmaps() 🔗

按需重新计算该纹理的 Mipmap(多级渐远纹理)。


bool get_use_mipmaps() const 🔗

如果这个 DrawableTexture(可绘制纹理)被设置为使用 Mipmap,则返回 true


void set_format(format: DrawableFormat) 🔗

设置这个 DrawableTexture(可绘制纹理)的格式。


void set_use_mipmaps(mipmaps: bool) 🔗

设置此 DrawableTexture 是否应该使用 mipmap(多级渐远纹理)。


void setup(width: int, height: int, format: DrawableFormat, color: Color = Color(1, 1, 1, 1), use_mipmaps: bool = false) 🔗

实验性: This function and its parameters are likely to change in the 4.7 Dev Cycle

将 DrawableTexture 初始化为一张指定 width(宽度)、height(高度)和 format(格式)的白色纹理。