DPITexture
Inherits: Texture2D < Texture < Resource < RefCounted < Object
Description
Section titled “Description”An automatically scalable Texture2D based on an SVG image.
An automatically scalable Texture2D based on an SVG image. DPITextures are used to automatically re-rasterize icons and other texture based UI theme elements to match viewport scale and font oversampling. See also ProjectSettings.display/window/stretch/mode (“canvas_items” mode) and Viewport.oversampling_override.
Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| float | base_scale |
1.0 |
| Dictionary | color_map |
{} |
| bool | fix_alpha_border |
false |
| bool | premult_alpha |
false |
| bool | resource_local_to_scene |
false (overrides Resource) |
| float | saturation |
1.0 |
Methods
Section titled “Methods”| Returns | Method |
|---|---|
| DPITexture | create_from_string(source: String, scale: float = 1.0, saturation: float = 1.0, color_map: Dictionary = {}) static |
| RID | get_scaled_rid() const |
| String | get_source() const |
| void | set_size_override(size: Vector2i) |
| void | set_source(source: String) |
Property descriptions
Section titled “Property descriptions”base_scale
float base_scale = 1.0
Texture scale. 1.0 is the original SVG size. Higher values result in a larger image.
color_map
Dictionary color_map = {}
If set, remaps texture colors according to Color-Color map.
fix_alpha_border
bool fix_alpha_border = false
If true, puts pixels of the same surrounding color in transition from transparent to opaque areas. For textures displayed with bilinear filtering, this helps to reduce the outline effect when exporting images from an image editor.
premult_alpha
bool premult_alpha = false
An alternative to fixing darkened borders with fix_alpha_border is to use premultiplied alpha. By enabling this option, the texture will be converted to this format. A premultiplied alpha texture requires specific materials to be displayed correctly:
-
In 2D, a CanvasItemMaterial will need to be created and configured to use the
CanvasItemMaterial.BLEND_MODE_PREMULT_ALPHAblend mode on CanvasItems that use this texture. In customcanvas_itemshaders,render_mode blend_premul_alpha;should be used. -
In 3D, a BaseMaterial3D will need to be created and configured to use the
BaseMaterial3D.BLEND_MODE_PREMULT_ALPHAblend mode on materials that use this texture. In customspatialshaders,render_mode blend_premul_alpha;should be used.
saturation
float saturation = 1.0
Overrides texture saturation.
Method descriptions
Section titled “Method descriptions”create_from_string
DPITexture create_from_string(source: String, scale: float = 1.0, saturation: float = 1.0, color_map: Dictionary = {}) static
Creates a new DPITexture and initializes it by allocating and setting the SVG data to source.
get_scaled_rid
RID get_scaled_rid() const
Returns the RID of the texture rasterized to match the oversampling of the currently drawn canvas item.
get_source
String get_source() const
Returns this SVG texture’s source code.
set_size_override
void set_size_override(size: Vector2i)
Resizes the texture to the specified dimensions.
set_source
void set_source(source: String)
Sets this SVG texture’s source code.
