Texture2D

package
v0.0.0-...-c858641 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

A texture works by registering an image in the video hardware, which then can be used in 3D models or 2D graphics.gd/classdb/Sprite2D or GUI graphics.gd/classdb/Control.

Textures are often created by loading them from a file. See [graphics.gd/classdb/@GDScript.Instance.Load].

graphics.gd/classdb/Texture2D is a base for other resources. It cannot be used directly.

Note: The maximum texture size is 16384×16384 pixels due to graphics hardware limitations. Larger textures may fail to import.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsTexture2D() Instance
}

type Expanded

type Expanded [1]gdclass.Texture2D

func (Expanded) Draw

func (self Expanded) Draw(canvas_item RID.CanvasItem, position Vector2.XY, modulate Color.RGBA, transpose bool)

Draws the texture using a graphics.gd/classdb/CanvasItem with the graphics.gd/classdb/RenderingServer API at the specified 'position'.

func (Expanded) DrawRect

func (self Expanded) DrawRect(canvas_item RID.CanvasItem, rect Rect2.PositionSize, tile bool, modulate Color.RGBA, transpose bool)

Draws the texture using a graphics.gd/classdb/CanvasItem with the graphics.gd/classdb/RenderingServer API.

func (Expanded) DrawRectRegion

func (self Expanded) DrawRectRegion(canvas_item RID.CanvasItem, rect Rect2.PositionSize, src_rect Rect2.PositionSize, modulate Color.RGBA, transpose bool, clip_uv bool)

Draws a part of the texture using a graphics.gd/classdb/CanvasItem with the graphics.gd/classdb/RenderingServer API.

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this [Extension]See Interface for methods that can be overridden by T.

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

func (*Extension[T]) AsTexture

func (self *Extension[T]) AsTexture() Texture.Instance

func (*Extension[T]) AsTexture2D

func (self *Extension[T]) AsTexture2D() Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Implementation

type Implementation = implementation

Implementation implements Interface with empty methods.

type Instance

type Instance [1]gdclass.Texture2D

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) AsTexture

func (self Instance) AsTexture() Texture.Instance

func (Instance) AsTexture2D

func (self Instance) AsTexture2D() Instance

func (Instance) CreatePlaceholder

func (self Instance) CreatePlaceholder() Resource.Instance

Creates a placeholder version of this resource (graphics.gd/classdb/PlaceholderTexture2D).

func (Instance) Draw

func (self Instance) Draw(canvas_item RID.CanvasItem, position Vector2.XY)

Draws the texture using a graphics.gd/classdb/CanvasItem with the graphics.gd/classdb/RenderingServer API at the specified 'position'.

func (Instance) DrawRect

func (self Instance) DrawRect(canvas_item RID.CanvasItem, rect Rect2.PositionSize, tile bool)

Draws the texture using a graphics.gd/classdb/CanvasItem with the graphics.gd/classdb/RenderingServer API.

func (Instance) DrawRectRegion

func (self Instance) DrawRectRegion(canvas_item RID.CanvasItem, rect Rect2.PositionSize, src_rect Rect2.PositionSize)

Draws a part of the texture using a graphics.gd/classdb/CanvasItem with the graphics.gd/classdb/RenderingServer API.

func (Instance) GetHeight

func (self Instance) GetHeight() int

Returns the texture height in pixels.

func (Instance) GetImage

func (self Instance) GetImage() Image.Instance

Returns an graphics.gd/classdb/Image that is a copy of data from this graphics.gd/classdb/Texture2D (a new graphics.gd/classdb/Image is created each time). [graphics.gd/classdb/Image]s can be accessed and manipulated directly.

Note: This will return null if this graphics.gd/classdb/Texture2D is invalid.

Note: This will fetch the texture data from the GPU, which might cause performance problems when overused. Avoid calling Instance.GetImage every frame, especially on large textures.

func (Instance) GetSize

func (self Instance) GetSize() Vector2.XY

Returns the texture size in pixels.

func (Instance) GetWidth

func (self Instance) GetWidth() int

Returns the texture width in pixels.

func (Instance) HasAlpha

func (self Instance) HasAlpha() bool

Returns true if this graphics.gd/classdb/Texture2D has an alpha channel.

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type Interface

type Interface interface {
	// Called when the [graphics.gd/classdb/Texture2D]'s width is queried.
	GetWidth() int
	// Called when the [graphics.gd/classdb/Texture2D]'s height is queried.
	GetHeight() int
	// Called when a pixel's opaque state in the [graphics.gd/classdb/Texture2D] is queried at the specified (x, y) position.
	IsPixelOpaque(x int, y int) bool
	// Called when the presence of an alpha channel in the [graphics.gd/classdb/Texture2D] is queried.
	HasAlpha() bool
	// Called when the entire [graphics.gd/classdb/Texture2D] is requested to be drawn over a [graphics.gd/classdb/CanvasItem], with the top-left offset specified in 'pos'. 'modulate' specifies a multiplier for the colors being drawn, while 'transpose' specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).
	//
	// Note: This is only used in 2D rendering, not 3D.
	Draw(to_canvas_item RID.Any, pos Vector2.XY, modulate Color.RGBA, transpose bool)
	// Called when the [graphics.gd/classdb/Texture2D] is requested to be drawn onto [graphics.gd/classdb/CanvasItem]'s specified 'rect'. 'modulate' specifies a multiplier for the colors being drawn, while 'transpose' specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).
	//
	// Note: This is only used in 2D rendering, not 3D.
	DrawRect(to_canvas_item RID.Any, rect Rect2.PositionSize, tile bool, modulate Color.RGBA, transpose bool)
	// Called when a part of the [graphics.gd/classdb/Texture2D] specified by 'src_rect”s coordinates is requested to be drawn onto [graphics.gd/classdb/CanvasItem]'s specified 'rect'. 'modulate' specifies a multiplier for the colors being drawn, while 'transpose' specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).
	//
	// Note: This is only used in 2D rendering, not 3D.
	DrawRectRegion(to_canvas_item RID.Any, rect Rect2.PositionSize, src_rect Rect2.PositionSize, modulate Color.RGBA, transpose bool, clip_uv bool)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL