AttributeRedirect

class AttributeRedirect extends Redirect

This redirect defines an attribute of a display-object's geometry. The attribute data is expected to be stored in a PIXI.ViewableBuffer, in an array, or (if just one element) as the property itself.


 // This attribute redirect calculates the tint used on top of a texture. Since the
 // tintMode can change anytime, it is better to use a derived source (function).
 //
 // Furthermore, the color is uploaded as four bytes (`attribute vec4 aTint`) while the
 // source returns an integer. This is done by splitting the 32-bit integer into four
 // 8-bit bytes.
 new AttributeRedirect({
     source: (tgt: ExampleDisplay) => (tgt.alpha < 1.0 && tgt.tintMode === PREMULTIPLY)
          ? premultiplyTint(tgt.rgb, tgt.alpha)
          : tgt.rgb + (tgt.alpha << 24);
     attrib: 'aTint',
     type: 'int32',
     size: '%notarray%', // optional/default
     glType: PIXI.TYPES.UNSIGNED_BYTE,
     glSize: 4,
     normalize: true // We are using [0, 255] range for RGBA here. Must normalize to [0, 1].
 });

Constructor


new AttributeRedirect(options: object) → {}
Parameters:
Name Type Attributes Default Description
options object
options.source string | Function

redirect source

options.attrib string

shader attribute variable

options.type string

<optional>

'float32'

the type of data stored in the source

options.size number | '%notarray%'

<optional>

0

size of the source array ('%notarray' if not an array & just one element)

options.glType PIXI.TYPES

<optional>

PIXI.TYPES.FLOAT

data format to be uploaded in

options.glSize number

number of elements to be uploaded as (size of source and upload must match)

options.normalize boolean

<optional>

false

whether to normalize the data before uploading

Summary


Properties from AttributeRedirect

number
glSize

Size of attribute in terms of glType.

PIXI.TYPES
glType

Type of attribute, when uploading.

boolean
normalize

Whether to normalize the attribute values.

number
properSize

This is equal to size or 1 if size is %notarray%.

number | '%notarray%'
size
string
type = 'float32'

Properties inherited from Redirect

string
glslIdentifer

The shader variable that references the resource, e.g. attribute or uniform name.

string | ((displayObject: PIXI.DisplayObject, renderer: BatchRenderer) => any)
source

The property on the display-object that holds the resource.

Public Properties


glSize AttributeRedirect.ts:77
glSize: number

Size of attribute in terms of glType.

Note that glSize * glType <= size * type

glType AttributeRedirect.ts:65
glType: PIXI.TYPES

Type of attribute, when uploading.

Normally, you would use the corresponding type for the view on source. However, to speed up uploads you can aggregate attribute values in larger data types. For example, an RGBA vec4 (byte-sized channels) can be represented as one Uint32, while having a glType of UNSIGNED_BYTE.

normalize AttributeRedirect.ts:86
normalize: boolean

Whether to normalize the attribute values.

properSize AttributeRedirect.ts:93
properSize: number

This is equal to size or 1 if size is %notarray%.

size AttributeRedirect.ts:54
size: number | '%notarray%'

Number of elements to extract out of source with the given view type, for one vertex.

If source isn't an array (only one element), then you can set this to '%notarray%'.

type AttributeRedirect.ts:44
type: string = 'float32'

The type of data stored in the source buffer. This can be any of: int8, uint8, int16, uint16, int32, uint32, or (by default) float32.

See: PIXI.ViewableBuffer#view

Powered by webdoc!