2016-11-29 12:54:25 +01:00
|
|
|
/**
|
|
|
|
* Raw Texture API object - should always correspond with the Texture Schema
|
|
|
|
* @param id
|
|
|
|
* @param typeId
|
|
|
|
* @param name
|
2017-06-08 18:17:03 +02:00
|
|
|
* @param image
|
2017-10-23 14:52:35 +02:00
|
|
|
* @param images
|
2016-11-29 12:54:25 +01:00
|
|
|
* @param wrapS
|
|
|
|
* @param wrapT
|
|
|
|
* @param repeat
|
|
|
|
* @param data
|
|
|
|
* @param format
|
|
|
|
* @param mapping
|
|
|
|
* @param magFilter
|
|
|
|
* @param minFilter
|
|
|
|
* @param textureType
|
|
|
|
* @param anisotropy
|
|
|
|
* @param offset
|
|
|
|
* @param generateMipmaps
|
|
|
|
* @param flipY
|
|
|
|
* @param mipmaps
|
|
|
|
* @param unpackAlignment
|
|
|
|
* @param premultiplyAlpha
|
|
|
|
* @param encoding
|
2017-10-09 10:18:59 +02:00
|
|
|
* @param canvas
|
2017-01-19 17:50:11 +01:00
|
|
|
* @param parentEntity
|
2016-11-29 12:54:25 +01:00
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.Texture = function(
|
|
|
|
id,
|
|
|
|
typeId,
|
|
|
|
name,
|
2017-06-08 18:17:03 +02:00
|
|
|
image,
|
2017-10-23 14:52:35 +02:00
|
|
|
images,
|
2016-11-29 12:54:25 +01:00
|
|
|
wrapS,
|
|
|
|
wrapT,
|
|
|
|
repeat,
|
|
|
|
data,
|
|
|
|
format,
|
|
|
|
mapping,
|
|
|
|
magFilter,
|
|
|
|
minFilter,
|
|
|
|
textureType,
|
|
|
|
anisotropy,
|
|
|
|
offset,
|
|
|
|
generateMipmaps,
|
|
|
|
flipY,
|
|
|
|
mipmaps,
|
|
|
|
unpackAlignment,
|
|
|
|
premultiplyAlpha,
|
2017-01-19 17:50:11 +01:00
|
|
|
encoding,
|
2017-10-09 10:18:59 +02:00
|
|
|
canvas,
|
2017-01-19 17:50:11 +01:00
|
|
|
parentEntity
|
2016-11-29 12:54:25 +01:00
|
|
|
) {
|
2017-01-19 17:50:11 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
|
|
parentEntity = null;
|
|
|
|
}
|
|
|
|
this.parentEntity = parentEntity;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
|
|
id = GameLib.Utils.RandomId();
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
|
|
|
this.id = id;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(typeId)) {
|
2017-06-12 15:35:13 +02:00
|
|
|
typeId = GameLib.D3.Texture.TEXTURE_TYPE_NORMAL;
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
|
|
|
this.typeId = typeId;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
2017-01-06 16:53:53 +01:00
|
|
|
name = 'Texture (' + id + ')';
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
|
|
|
this.name = name;
|
|
|
|
|
2017-06-08 18:17:03 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(image)) {
|
|
|
|
image = null;
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
2017-06-08 18:17:03 +02:00
|
|
|
this.image = image;
|
2016-11-29 12:54:25 +01:00
|
|
|
|
2017-10-23 14:52:35 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(images)) {
|
|
|
|
images = [];
|
|
|
|
}
|
|
|
|
this.images = images;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(wrapS)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
wrapS = GameLib.D3.Texture.TYPE_REPEAT_WRAPPING;
|
|
|
|
}
|
|
|
|
this.wrapS = wrapS;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(wrapT)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
wrapT = GameLib.D3.Texture.TYPE_REPEAT_WRAPPING;
|
|
|
|
}
|
|
|
|
this.wrapT = wrapT;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(repeat)) {
|
|
|
|
repeat = new GameLib.API.Vector2(1, 1);
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
|
|
|
this.repeat = repeat;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(data)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
data = null;
|
|
|
|
}
|
|
|
|
this.data = data;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(format)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
format = GameLib.D3.Texture.TYPE_RGBA_FORMAT;
|
|
|
|
}
|
|
|
|
this.format = format;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(mapping)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
mapping = GameLib.D3.Texture.TYPE_UV_MAPPING;
|
|
|
|
}
|
|
|
|
this.mapping = mapping;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(magFilter)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
magFilter = GameLib.D3.Texture.TYPE_LINEAR_FILTER;
|
|
|
|
}
|
|
|
|
this.magFilter = magFilter;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(minFilter)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
minFilter = GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER;
|
|
|
|
}
|
|
|
|
this.minFilter = minFilter;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(textureType)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
textureType = GameLib.D3.Texture.TYPE_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
this.textureType = textureType;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(anisotropy)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
anisotropy = 1;
|
|
|
|
}
|
|
|
|
this.anisotropy = anisotropy;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(offset)) {
|
|
|
|
offset = new GameLib.API.Vector2(0, 0);
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
|
|
|
this.offset = offset;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(generateMipmaps)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
generateMipmaps = true;
|
|
|
|
}
|
|
|
|
this.generateMipmaps = generateMipmaps;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(flipY)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
flipY = true;
|
|
|
|
}
|
|
|
|
this.flipY = flipY;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(mipmaps)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
mipmaps = [];
|
|
|
|
}
|
|
|
|
this.mipmaps = mipmaps;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(unpackAlignment)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
unpackAlignment = 4;
|
|
|
|
}
|
|
|
|
this.unpackAlignment = unpackAlignment;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(premultiplyAlpha)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
premultiplyAlpha = false;
|
|
|
|
}
|
|
|
|
this.premultiplyAlpha = premultiplyAlpha;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(encoding)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
encoding = GameLib.D3.Texture.TYPE_LINEAR_ENCODING;
|
|
|
|
}
|
|
|
|
this.encoding = encoding;
|
2017-05-22 15:42:05 +02:00
|
|
|
|
2017-10-09 10:18:59 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(canvas)) {
|
|
|
|
canvas = null;
|
|
|
|
}
|
|
|
|
this.canvas = canvas;
|
|
|
|
|
2017-05-22 15:42:05 +02:00
|
|
|
this.needsUpdate = false;
|
2016-11-29 12:54:25 +01:00
|
|
|
};
|
2017-01-05 19:34:28 +01:00
|
|
|
|
2017-05-11 04:48:02 +02:00
|
|
|
GameLib.D3.API.Texture.prototype = Object.create(GameLib.Component.prototype);
|
|
|
|
GameLib.D3.API.Texture.prototype.constructor = GameLib.D3.API.Texture;
|
|
|
|
|
2017-01-05 19:34:28 +01:00
|
|
|
/**
|
|
|
|
* Creates an API texture from Object data
|
|
|
|
* @param objectTexture
|
|
|
|
* @constructor
|
|
|
|
*/
|
2017-06-14 14:21:57 +02:00
|
|
|
GameLib.D3.API.Texture.FromObject = function(objectTexture) {
|
2017-01-06 16:53:53 +01:00
|
|
|
return new GameLib.D3.API.Texture(
|
2017-01-05 19:34:28 +01:00
|
|
|
objectTexture.id,
|
2017-06-19 12:42:15 +02:00
|
|
|
objectTexture.typeId,
|
2017-01-05 19:34:28 +01:00
|
|
|
objectTexture.name,
|
2017-06-08 18:17:03 +02:00
|
|
|
objectTexture.image,
|
2017-10-23 14:52:35 +02:00
|
|
|
objectTexture.images,
|
2017-01-05 19:34:28 +01:00
|
|
|
objectTexture.wrapS,
|
|
|
|
objectTexture.wrapT,
|
2017-06-14 14:21:57 +02:00
|
|
|
GameLib.API.Vector2.FromObject(objectTexture.repeat),
|
2017-01-05 19:34:28 +01:00
|
|
|
objectTexture.data,
|
|
|
|
objectTexture.format,
|
|
|
|
objectTexture.mapping,
|
|
|
|
objectTexture.magFilter,
|
|
|
|
objectTexture.minFilter,
|
|
|
|
objectTexture.textureType,
|
|
|
|
objectTexture.anisotropy,
|
2017-06-14 14:21:57 +02:00
|
|
|
GameLib.API.Vector2.FromObject(objectTexture.offset),
|
2017-01-05 19:34:28 +01:00
|
|
|
objectTexture.generateMipmaps,
|
|
|
|
objectTexture.flipY,
|
|
|
|
objectTexture.mipmaps,
|
|
|
|
objectTexture.unpackAlignment,
|
|
|
|
objectTexture.premultiplyAlpha,
|
2017-01-19 17:50:11 +01:00
|
|
|
objectTexture.encoding,
|
2017-10-09 10:18:59 +02:00
|
|
|
objectTexture.canvas,
|
2017-01-19 17:50:11 +01:00
|
|
|
objectTexture.parentEntity
|
2017-01-05 19:34:28 +01:00
|
|
|
)
|
|
|
|
};
|