Texture2D

package
v0.0.0-...-fe0704e Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 29 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 Sprite2D or GUI Control.

Textures are often created by loading them from a file. See @GDScript.Load.

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 = MoreArgs

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

func (Instance) Draw

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

Draws the texture using a CanvasItem with the 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 CanvasItem with the 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 CanvasItem with the 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 Image that is a copy of data from this Texture2D (a new Image is created each time). Images can be accessed and manipulated directly.

Note: This will return null if this Texture2D is invalid.

Note: This will fetch the texture data from the GPU, which might cause performance problems when overused. Avoid calling 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 Texture2D has an alpha channel.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

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 [Texture2D]'s width is queried.
	//
	// [Texture2D]: https://pkg.go.dev/graphics.gd/classdb/Texture2D
	GetWidth() int
	// Called when the [Texture2D]'s height is queried.
	//
	// [Texture2D]: https://pkg.go.dev/graphics.gd/classdb/Texture2D
	GetHeight() int
	// Called when a pixel's opaque state in the [Texture2D] is queried at the specified (x, y) position.
	//
	// [Texture2D]: https://pkg.go.dev/graphics.gd/classdb/Texture2D
	IsPixelOpaque(x int, y int) bool
	// Called when the presence of an alpha channel in the [Texture2D] is queried.
	//
	// [Texture2D]: https://pkg.go.dev/graphics.gd/classdb/Texture2D
	HasAlpha() bool
	// Called when the entire [Texture2D] is requested to be drawn over a [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.
	//
	// [CanvasItem]: https://pkg.go.dev/graphics.gd/classdb/CanvasItem
	// [Texture2D]: https://pkg.go.dev/graphics.gd/classdb/Texture2D
	Draw(to_canvas_item RID.CanvasItem, pos Vector2.XY, modulate Color.RGBA, transpose bool)
	// Called when the [Texture2D] is requested to be drawn onto [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.
	//
	// [CanvasItem]: https://pkg.go.dev/graphics.gd/classdb/CanvasItem
	// [Texture2D]: https://pkg.go.dev/graphics.gd/classdb/Texture2D
	DrawRect(to_canvas_item RID.CanvasItem, rect Rect2.PositionSize, tile bool, modulate Color.RGBA, transpose bool)
	// Called when a part of the [Texture2D] specified by 'src_rect”s coordinates is requested to be drawn onto [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.
	//
	// [CanvasItem]: https://pkg.go.dev/graphics.gd/classdb/CanvasItem
	// [Texture2D]: https://pkg.go.dev/graphics.gd/classdb/Texture2D
	DrawRectRegion(to_canvas_item RID.CanvasItem, rect Rect2.PositionSize, src_rect Rect2.PositionSize, modulate Color.RGBA, transpose bool, clip_uv bool)
}

type MoreArgs

type MoreArgs [1]gdclass.Texture2D

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) Draw

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

Draws the texture using a CanvasItem with the RenderingServer API at the specified 'position'.

func (MoreArgs) DrawRect

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

Draws the texture using a CanvasItem with the RenderingServer API.

func (MoreArgs) DrawRectRegion

func (self MoreArgs) 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 CanvasItem with the RenderingServer API.

Jump to

Keyboard shortcuts

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