kick.texture.Texture Class
Encapsulate a texture object and its configuration. Note that the texture configuration
must be set prior to assigning the texture (using either init, setImage or setImageData).
Cubemaps must have dimensions width = height * 6 and the order of the cubemap is positiveX, negativeX, positiveY, negativeY, positiveZ, negativeZ
Constructor
kick.texture.Texture
-
[config]
Parameters:
-
[config]
Object optional
Item Index
Methods
Methods
apply
()
Applies the texture settings
bind
-
textureSlot
Bind the current texture
Parameters:
-
textureSlot
Number
destroy
()
Deallocate the texture from memory
getTextureError
()
String | Null
Verifies the current texture configuration and returns the texture error (if any)
Returns:
init
()
Trigger getImageData if dataURI is defined
isFPTexturesSupported
()
Boolean
deprecated
Calling this function has the side effect of enabling floating point texture (in available on platform) Use GLState.depthTextureExtension instead
Returns:
recreateTextureIfDifferentType
()
private
setDataURI
-
newValue
-
automaticGetTextureData
Allows setting the dataURI without reloading the image
Parameters:
-
newValue
Object -
automaticGetTextureData
Object
setImage
-
imageObj
-
dataURI
Set texture image based on a image object.
The image is automatically resized nearest power of two
When a textureType == TEXTURE_CUBE_MAP the image needs to be in the following format:
- width = 6*height
- Image needs to be ordered: [Right, Left, Top, Bottom, Front, Back] (As in NVidia DDS Exporter)
Parameters:
-
imageObj
Imageimage object to import
-
dataURI
StringString representing the image
setImageData
-
width
-
height
-
border
-
type
-
pixels
-
dataURI
-
[cubemapIndex]
Set a image using a raw bytearray in a specified format. GL_FLOAT / GL_HALF_FLOAT_OES should only be used if extension is supported (See GLState.textureFloatExtension / GLState.textureFloatHalfExtension). If only one of GL_FLOAT/GL_HALF_FLOAT_OES is supported, then the engine will silently use the supported type. If used on cubemap-texture then all 6 sides of the cube is assigned
Parameters:
-
width
Numberimage width in pixels
-
height
Numberimage height in pixels
-
border
Numberimage border in pixels
-
type
ObjectGL_FLOAT, GL_HALF_FLOAT_OES, GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_5_5_5_1 or GL_UNSIGNED_SHORT_5_6_5
-
pixels
ArrayBufferViewarray of pixels (may be null)
-
dataURI
StringString representing the image
-
[cubemapIndex]
Number optionalThe cubemap index (only for cubemaps) [+x,-x,+y,-y,+z,-z]. Default is all cubemaps.
Example:
texture = new kick.texture.Texture();
var data = new Uint8Array([
255,255,255,255, 255,0,0,255,
0,255,0,255, 0,0,255,255
]);
texture.setImageData(2,2,0,kick.core.Constants.GL_UNSIGNED_BYTE,data);
setSubImageData
-
xoffset
-
yoffset
-
width
-
height
-
pixels
Updates a subset of the texture Note the type of pixels is assumed to be the same as in setImageData
Parameters:
-
xoffset
Number -
yoffset
Number -
width
Number -
height
Number -
pixels
ArrayBufferView
Example:
var texture = new kick.texture.Texture();
texture.setImageData(2,2,0,kick.core.Constants.GL_UNSIGNED_BYTE,null);
texture.setSubImageData(0, 0, 1, 1, new Uint8Array([255,255,255,255]));
setTemporaryTexture
()
Creates a 2x2 temporary image (white)
toJSON
()
Object
Serializes the data into a JSON object (that can be used as a config parameter in the constructor)
Note that the texture data is not serialized in the json format.
This means that either setImage() or setImageData() must be called before the texture can be bound
Returns:
config element
Properties
dataURI
String
URI of the texture. This property does not load any texture. To load a texture, set this property and
call the init function (or load the image manually and call the setImage() function).
If texture is not on same server, then the web server must support CORS
See http://hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/
dimension
Vec2
Dimension of texture [width,height].
Note for cube maps the size is for one face
flipY
Boolean
When importing image flip the Y direction of the image
This property is ignored for cube maps.
Default: true
generateMipmaps
Boolean
Autogenerate mipmap levels
When an existing texture (without mipmaps) has generateMipmaps=true, then mipmaps are created instantly.
Default: true
internalFormat
Number
Specifies the internal format of the image (format on GPU)
Must be one of the following:
GL_ALPHA,
GL_RGB,
GL_RGBA,
GL_LUMINANCE,
GL_LUMINANCE_ALPHA
Default: GL_RGBA
magFilter
Object
Texture.magFilter should be either GL_NEAREST or GL_LINEAR.
Default: GL_LINEAR
minFilter
Object
Texture.minFilter should be either GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST,
GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR
Default: GL_LINEAR
name
String
textureId
Number
protected
textureType
Number
Specifies the texture type
Default is GL_TEXTURE_2D
Must be one of the following:
GL_TEXTURE_2D,
GL_TEXTURE_CUBE_MAP
Default: GL_TEXTURE_2D
uid
Number
wrapS
Object
Texture.wrapS should be either GL_CLAMP_TO_EDGE or GL_REPEAT
Default: GL_REPEAT
wrapT
Object
Texture.wrapT should be either GL_CLAMP_TO_EDGE or GL_REPEAT
Default: GL_REPEAT