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

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 🔗

返回使用的壓縮模式(初始化後有效)。


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.