LittleJS 1.30.1

Draw

TextureInfo

Texture Info - Stores info about each texture

Constructor

new TextureInfo(image, useWebGL, wrap, pixelated)engineDraw.js:275

Create a TextureInfo, called automatically by the engine

image HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap
useWebGL boolean optional, default true

Should use WebGL if available?

wrap boolean|Array<number> optional, default false

Should the texture wrap (REPEAT) or clamp (CLAMP_TO_EDGE)? Or the WebGL modes across and down, like [gl.CLAMP_TO_EDGE, gl.MIRRORED_REPEAT], as a glTF sampler gives them

pixelated boolean optional

Hard edged or smooth for this texture alone, undefined follows tilesPixelated

Members

Methods

Members

glTexture : WebGLTexture|undefinedengineDraw.js:295

WebGL texture

image : HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmapengineDraw.js:288

image source

pixelated : boolean|undefinedengineDraw.js:303

Hard edged or smooth for this texture alone, a soft glow in a pixel art game or pixel art in a smooth one; undefined follows tilesPixelated

size of the image

inverse of the size, cached for rendering

wrap : boolean|Array<number>engineDraw.js:299

true for REPEAT wrap mode, false for CLAMP_TO_EDGE, or the WebGL modes across and down

Methods

createWebGLTexture()engineDraw.js:308

Creates the WebGL texture, updates if already created

destroyWebGLTexture()engineDraw.js:368

Destroys the WebGL texture

hasWebGL() → booleanengineDraw.js:372

Check if the texture is webgl enabled

setPixelated(pixelated)engineDraw.js:387

Make this texture hard edged or smooth on its own, whatever tilesPixelated says for the rest; a change makes it again from its image with the new filtering, since a smooth one is stored premultiplied with mipmaps, so pixels put in with updateData are lost unless the image has them too, as after a lost context

pixelated boolean optional

undefined follows tilesPixelated again

setWrap(wrap)engineDraw.js:377

Set the wrap mode for this texture

wrap boolean|Array<number> optional, default true

true for REPEAT, false for CLAMP_TO_EDGE, or the WebGL modes across and down

updateData(pixels, x, y, width, height)engineDraw.js:333

Put new pixels into part of the texture without uploading all of it, for a texture that changes as the game runs, like an atlas decoded every frame where only a few tiles changed; what was batched with the old pixels is drawn first

  • x and y are image pixels from the top left, as a tile's pos is, and the rectangle must be inside the image
  • With WebGL only the texture changes, so a lost context brings back the image as it was: keep the image up to date too, or put the pixels in again from a plugin's glContextRestored
  • Without WebGL the image is what is drawn, so it must be a canvas, and the pixels are written into it
  • Call it outside the 3D pass, which may still hold draws that read the old pixels
pixels Uint8Array|Uint8ClampedArray|ImageData|HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap

RGBA bytes, width * height * 4 of them, or an image put in at its own size

x number optional, default 0
y number optional, default 0
width number optional

Width of a byte array's rectangle, the whole image by default

height number optional

Height of a byte array's rectangle, the whole image by default