Tryst::SDL::Texture
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:
Staticuploads once and is drawn many times. Sprites, tiles, anything loaded from a file and never changed.Streamingis rewritten constantly - an emulator's framebuffer, a video frame, a software renderer's output.Targetis drawn INTO, withRenderer#draw_to. Off-screen composition, effects, caching an expensive drawing.
Constants
Bytes per pixel in the one format this hands out. ARGB8888 is what a caller with a pixel buffer almost always already has.
Constructors
A texture loaded straight from an image file. Shorthand for
renderer.load_image(path), for symmetry with the from-buffer
constructors above.
@api private - use Renderer#create_texture, which has the renderer to attach to.
Instance methods
Tints the texture as it is drawn, without touching its pixels. 255 everywhere leaves it alone.
How this texture is sampled when drawn at a size other than its own - Nearest for crisp upscaled pixel art, Linear to smooth it.
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.
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.