Skip to content

Commit 8960cf2

Browse files
committed
texture meta data parsed and saved in cache
1 parent 1b9f25b commit 8960cf2

3 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/loader/Cache.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ Phaser.Cache = function (game) {
6464
bitmapData: {},
6565
bitmapFont: {},
6666
shader: {},
67-
renderTexture: {}
67+
renderTexture: {},
68+
compressedTexture: {}
6869
};
6970

7071
/**
@@ -111,6 +112,7 @@ Phaser.Cache = function (game) {
111112
this._cacheMap[Phaser.Cache.VIDEO] = this._cache.video;
112113
this._cacheMap[Phaser.Cache.SHADER] = this._cache.shader;
113114
this._cacheMap[Phaser.Cache.RENDER_TEXTURE] = this._cache.renderTexture;
115+
this._cacheMap[Phaser.Cache.COMPRESSED_TEXTURE] = this._cache.compressedTexture;
114116

115117
this.addDefaultImage();
116118
this.addMissingImage();
@@ -207,6 +209,12 @@ Phaser.Cache.SHADER = 14;
207209
*/
208210
Phaser.Cache.RENDER_TEXTURE = 15;
209211

212+
/**
213+
* @constant
214+
* @type {number}
215+
*/
216+
Phaser.Cache.COMPRESSED_TEXTURE = 16;
217+
210218
/**
211219
* The default image used for a texture when no other is specified.
212220
* @constant
@@ -227,6 +235,15 @@ Phaser.Cache.prototype = {
227235
// Add Methods //
228236
//////////////////
229237

238+
addCompressedTextureMetaData: function (key, url, extension, arrayBuffer) {
239+
this._cache.compressedTexture[key] = {
240+
data: Phaser.LoaderParser[extension](arrayBuffer),
241+
url: url,
242+
key: key,
243+
fileFormat: extension
244+
};
245+
},
246+
230247
/**
231248
* Add a new canvas object in to the cache.
232249
*

src/loader/Loader.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,8 +2662,7 @@ Phaser.Loader.prototype = {
26622662
file.data = data || {};
26632663
break;
26642664
case 'texture':
2665-
debugger;
2666-
this.cache.addImage(file.key, file.url, file.data);
2665+
this.cache.addCompressedTextureMetaData(file.key, file.url, file.url.split('.').pop().toLowerCase(), xhr.response);
26672666
break;
26682667
case 'image':
26692668

src/loader/LoaderParser.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ Phaser.LoaderParser = {
164164
return bitmapFontData;
165165

166166
},
167-
167+
168168
/**
169169
* Extract PVR header from loaded binary
170170
*
171171
* @method Phaser.LoaderParser.parsePVR
172172
* @param {ArrayBuffer} arrayBuffer - The BaseTexture this font uses.
173173
* @return {object} The parsed PVR file including texture data.
174174
*/
175-
parsePVR: function (arrayBuffer) {
175+
pvr: function (arrayBuffer) {
176176
// Reference: http://cdn.imgtec.com/sdk-documentation/PVR+File+Format.Specification.pdf
177177
// PVR 3 header structure
178178
// ---------------------------------------
@@ -201,6 +201,7 @@ Phaser.LoaderParser = {
201201
].indexOf(pixelFormat) >= 0
202202
) {
203203
pvrHeader = {
204+
fileFormat: 'PVR',
204205
flags: uintArray[1],
205206
pixelFormat: pixelFormat,
206207
colorSpace: uintArray[4],
@@ -225,7 +226,7 @@ Phaser.LoaderParser = {
225226
* @param {ArrayBuffer} arrayBuffer - The BaseTexture this font uses.
226227
* @return {object} The parsed DDS file including texture data.
227228
*/
228-
parseDDS: function (arrayBuffer) {
229+
dds: function (arrayBuffer) {
229230
// Reference at: https://msdn.microsoft.com/en-us/library/windows/desktop/bb943982(v=vs.85).aspx
230231
// DDS header structure
231232
// ---------------------------------------
@@ -267,6 +268,7 @@ Phaser.LoaderParser = {
267268
byteArray[2] === 0x53 &&
268269
byteArray[3] === 0x20) {
269270
ddsHeader = {
271+
fileFormat: 'DDS',
270272
size: uintArray[1],
271273
flags: uintArray[2],
272274
height: uintArray[3],
@@ -316,7 +318,7 @@ Phaser.LoaderParser = {
316318
* @param {ArrayBuffer} arrayBuffer - The BaseTexture this font uses.
317319
* @return {object} The parsed KTX file including texture data.
318320
*/
319-
parseKTX: function (arrayBuffer) {
321+
ktx: function (arrayBuffer) {
320322
// Reference: https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/
321323
// KTX header structure
322324
// ---------------------------------------
@@ -344,16 +346,23 @@ Phaser.LoaderParser = {
344346
ktxHeader = null,
345347
imageSizeOffset = 16 + (uintArray[15] / 4) | 0,
346348
imageSize = uintArray[imageSizeOffset];
347-
348349
if (byteArray[0] === 0xAB && byteArray[1] === 0x4B &&
349350
byteArray[2] === 0x54 && byteArray[3] === 0x58 &&
350351
byteArray[4] === 0x20 && byteArray[5] === 0x31 &&
351352
byteArray[6] === 0x31 && byteArray[7] === 0xBB &&
352353
byteArray[8] === 0x0D && byteArray[9] === 0x0A &&
353354
byteArray[10] === 0x1A && byteArray[11] === 0x0A &&
354-
//Check if internal GL format is ETC1_RGB8_OES
355-
uintArray[7] === 0x8D64) {
355+
//Check if internal GL format is supported by WebGL
356+
[
357+
// ETC1
358+
0x8D64,
359+
// PVRTC
360+
0x8C00, 0x8C01, 0x8C02, 0x8C03,
361+
// DXTC | S3TC
362+
0x83F0, 0x83F1, 0x83F2, 0x83F3
363+
].indexOf(uintArray[7]) >= 0) {
356364
ktxHeader = {
365+
fileFormat: 'KTX',
357366
endianness: uintArray[3],
358367
glType: uintArray[4],
359368
glTypeSize: uintArray[5],
@@ -382,7 +391,7 @@ Phaser.LoaderParser = {
382391
* @param {ArrayBuffer} arrayBuffer - The BaseTexture this font uses.
383392
* @return {object} The parsed PKM file including texture data.
384393
*/
385-
parsePKM: function (arrayBuffer) {
394+
pkm: function (arrayBuffer) {
386395
// PKM header structure
387396
// ---------------------------------------
388397
// address: 0, size 4 bytes: for 'PKM '
@@ -402,6 +411,7 @@ Phaser.LoaderParser = {
402411
byteArray[2] === 0x4D &&
403412
byteArray[3] === 0x20) {
404413
pkmHeader = {
414+
fileFormat: 'PKM',
405415
format: ((byteArray[6] << 8 | byteArray[7])) & 0xFFFF,
406416
extendedWidth: ((byteArray[8] << 8 | byteArray[9])) & 0xFFFF,
407417
extendedHeight: ((byteArray[10] << 8 | byteArray[11])) & 0xFFFF,

0 commit comments

Comments
 (0)