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

Format

get_format() 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()

If true, when running in the editor, this texture will keep the source-compressed data in memory, allowing the data to persist after loading. Otherwise, the source-compressed data is lost after loading and the texture can't be re-saved.

Note: This property must be set before create_from_image() for this to work.


Vector2 size_override = Vector2(0, 0) 🔗

Allows overriding the texture's size (for 2D only).


方法说明

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 🔗

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


Format get_format() const 🔗

返回使用的图像格式(初始化后有效)。


bool is_keeping_all_compressed_buffers() static 🔗

Returns true if the flag is overridden for all textures of this type.


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

Sets the compressor parameters for Basis Universal compression. See also the settings in ResourceImporterTexture.

Note: This method must be called before create_from_image() for this to work.


void set_keep_all_compressed_buffers(keep: bool) static 🔗

If keep is true, overrides the flag globally for all textures of this type. This is used primarily by the editor.