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.

PortableCompressedTexture2D

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

为磁盘和/或显存提供可移植的压缩纹理。

描述

这个类能够将压缩纹理存储为自包含的资源(与导入资源相对)。

用于 2D 时(在磁盘上压缩、在显存中不压缩)推荐使用有损和无损模式。用于 3D 时(在显存中压缩)则取决于目标平台。

如果你只想用于桌面平台,则推荐使用 S3TC 或 BPTC。如果只用于移动平台,则推荐使用 ETC2。

如果要实现可移植、自包含的 3D 纹理,让这种纹理能同时在桌面和移动平台使用,则推荐 Basis Universal(尽管代价是有较小的质量损耗和更长的压缩时间)。

这个资源应使用代码创建。

属性

bool

keep_compressed_buffer

false

bool

resource_local_to_scene

false (overrides Resource)

Vector2

size_override

Vector2(0, 0)

方法

void

create_from_image(image: Image, compression_mode: CompressionMode, normal_map: bool = false, lossy_quality: float = 0.8)

CompressionMode

get_compression_mode() const

bool

is_keeping_all_compressed_buffers() static

void

set_basisu_compressor_params(uastc_level: int, rdo_quality_loss: float)

void

set_keep_all_compressed_buffers(keep: bool) static


枚举

enum CompressionMode: 🔗

CompressionMode COMPRESSION_MODE_LOSSLESS = 0

There is currently no description for this enum. Please help us by contributing one!

CompressionMode COMPRESSION_MODE_LOSSY = 1

There is currently no description for this enum. Please help us by contributing one!

CompressionMode COMPRESSION_MODE_BASIS_UNIVERSAL = 2

There is currently no description for this enum. Please help us by contributing one!

CompressionMode COMPRESSION_MODE_S3TC = 3

There is currently no description for this enum. Please help us by contributing one!

CompressionMode COMPRESSION_MODE_ETC2 = 4

There is currently no description for this enum. Please help us by contributing one!

CompressionMode COMPRESSION_MODE_BPTC = 5

There is currently no description for this enum. Please help us by contributing one!

CompressionMode COMPRESSION_MODE_ASTC = 6

There is currently no description for this enum. Please help us by contributing one!


属性说明

bool keep_compressed_buffer = false 🔗

  • void set_keep_compressed_buffer(value: bool)

  • bool is_keeping_compressed_buffer()

如果为 true,则在编辑器中运行时,该纹理会将源压缩数据保留在内存中,从而使数据在加载后仍然存在。否则,源压缩数据在加载后会丢失,并且纹理无法重新保存。

注意:该属性必须在 create_from_image() 之前设置才能生效。


Vector2 size_override = Vector2(0, 0) 🔗

允许覆盖纹理大小(仅限 2D)。


方法说明

void create_from_image(image: Image, compression_mode: CompressionMode, normal_map: bool = false, lossy_quality: float = 0.8) 🔗

使用基础图像初始化压缩纹理。必须提供压缩模式。

如果该图像会用作法线贴图,则推荐使用 normal_map,确保达到最佳质量。

如果请求了有损压缩,还可以提供质量设置。会映射至有损 WebP 压缩质量。


CompressionMode get_compression_mode() const 🔗

返回使用的压缩模式(初始化后有效)。


bool is_keeping_all_compressed_buffers() static 🔗

如果此类型的纹理的所有标志都被覆盖,则返回 true


void set_basisu_compressor_params(uastc_level: int, rdo_quality_loss: float) 🔗

设置 Basis Universal 压缩的压缩器参数。另见 ResourceImporterTexture 中的设置。

注意:该方法必须在 create_from_image() 之前调用才能生效。


void set_keep_all_compressed_buffers(keep: bool) static 🔗

如果 keeptrue,则会全局覆盖所有此类纹理的标志。主要用于编辑器。