TableTexture (class)
Creates Float32Texture that is initialized by a Float32Array of appropriate size. The minification and the magification filters of the texture are set to 'linear' by default.
Constructor
The class constructor can be called by
var textureInstance = new TableTexture(
table,
width ,
height,
options ) ;
The arguments are:
-
table
A Float32Array of size
width*height*4
where each color of the pixel is represented by an element of the array.The texture is filled up, row by row, from the bottom up and with
RGBA
values followed in sequence. -
width
width of the texture to be created.
-
height
height of the texture to be created. (Default = 1)
-
options
object of optional named arguments. If none is provided, the default values will be assumed. The options object's available properties are:
-
wrapS
String indicating wrapping in the horizontal direction. Possible values are
'clamp_to_edge' (default) 'repeat' 'mirrored_repeat'
-
wrapT
String indicating wrapping in the vertical direction. Possible values are
'clamp_to_edge' (default) 'repeat' 'mirrored_repeat'
-
magFilter
Texture magnification filter. Possible values are
'nearest' 'linear' (default)
-
minFilter
Texture minification filter. Possible values are
'nearest' 'linear' (default) 'nearest_mipmap_nearest' 'linear_mipmap_nearest' 'nearest_mipmap_linear' 'linear_mipmap_linear'
Instance properties
The following properties have read and write permissions and hence can be modified.
-
width
\(^\dagger \) -
height
\(^\dagger \) -
wrapS
-
wrapT
-
minFilter
-
magFilter
-
table
-
data
Instance methods
-
.update(newTable)
updates the value of the texture based on a newTable provided to the function. If the original table to the construction is updated, using
.update()
on the instance with no arguments will update the value of the texture on the GPU.
Example
The code snippet below shows an example of setting up a table texture.
var width = 32 ; // number of pixels in the horizontal direction
var height = 16 ; // number of pixels in the vertical direction
var table = new Float32Array(width*height*4) ;
var p = 0 ; // counter that tracks the pixel index number
for(var j=0; j<height ; j++){ // represents row numbers
for(var i=0 ; i<width; i++){ // represents column numbers
table[p++] = i/width ; // the red channel
table[p++] = j/height ; // the green channel
table[p++] = 0. ; // the blue channel
table[p++] = 1. ; // the alpha channel
}
}
// texture definition
var texture = new Abubu.TableTexture( table, width, height ) ;
texture.magFilter = 'nearest' ; // setting magnification filter
texture.minFilter = 'nearest' ; // setting minification filter