class

Tryst::SDL::Texture

Inherits Reference < Object

An image living in the renderer, drawn with Renderer#copy.

Three kinds, and picking the wrong one is a performance problem rather than a correctness one:

  • Static uploads once and is drawn many times. Sprites, tiles, anything loaded from a file and never changed.
  • Streaming is rewritten constantly - an emulator's framebuffer, a video frame, a software renderer's output.
  • Target is drawn INTO, with Renderer#draw_to. Off-screen composition, effects, caching an expensive drawing.

Constants

BYTES_PER_PIXEL = 4

Bytes per pixel in the one format this hands out. ARGB8888 is what a caller with a pixel buffer almost always already has.

Constructors

from_file(renderer : Renderer, path : String) : Texture

A texture loaded straight from an image file. Shorthand for renderer.load_image(path), for symmetry with the from-buffer constructors above.

Source
new(renderer : Pointer(LibSDL::Renderer), width : Int32, height : Int32, access : Access)

@api private - use Renderer#create_texture, which has the renderer to attach to.

Source
new(texture : Pointer(LibSDL::Texture))

@api private - use Renderer#load_image or Font#render_text, which hand SDL a file or a rendered surface instead of asking for a blank texture by size. Always Static: that is what both IMG_LoadTexture and SDL_CreateTextureFromSurface produce.

Source

Instance methods

access
Source
blend_mode
Source
blend_mode=(value : BlendMode) : BlendMode
Source
color_mod=(color : Color) : Color

Tints the texture as it is drawn, without touching its pixels. 255 everywhere leaves it alone.

Source
destroy
Source
destroyed?
Source
height
Source
pitch

Bytes one full row of this texture occupies.

Source
scale_mode

How this texture is sampled when drawn at a size other than its own - Nearest for crisp upscaled pixel art, Linear to smooth it.

Source
scale_mode=(value : ScaleMode) : ScaleMode
Source
to_unsafe

@api private

Source
update(pixels : Bytes) : self

Replaces the whole texture from a buffer of ARGB8888 pixels.

THE SIZE IS CHECKED, which is the main reason to wrap this at all: SDL takes a bare pointer and a pitch and reads height * pitch bytes from it, so a buffer even one row short is read past its end - memory corruption, not an error. There is no way for SDL to notice, so this notices instead.

Source
width
Source
with_locked_rows

Locks a streaming texture and yields the memory to write into, one row at a time.

Faster than #update for a texture rewritten every frame, because it writes straight into the texture's own memory instead of copying a buffer into it. The yielded rows are WRITE-ONLY - whatever they currently contain is undefined, so every pixel has to be written, not just the changed ones.

SDL's pitch is its own and need not equal #pitch, which is why the block is handed a row at a time rather than one flat slice.

Source

Nested types