From 100aa413bfee471520f9aa4992f7ec03fa76bd05 Mon Sep 17 00:00:00 2001 From: Felipe Alfonso Date: Mon, 1 Aug 2016 16:27:39 -0400 Subject: [PATCH] Texture loading depending on webgl extensions included default truecolor --- src/loader/Cache.js | 3 ++- src/loader/Loader.js | 22 +++++++++++++++++++--- src/pixi/renderers/webgl/WebGLRenderer.js | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/loader/Cache.js b/src/loader/Cache.js index 044db198f..215f596fb 100644 --- a/src/loader/Cache.js +++ b/src/loader/Cache.js @@ -236,8 +236,9 @@ Phaser.Cache.prototype = { ////////////////// addCompressedTextureMetaData: function (key, url, extension, arrayBuffer) { + var data = (extension in Phaser.LoaderParser) ? Phaser.LoaderParser[extension](arrayBuffer) : arrayBuffer; this._cache.compressedTexture[key] = { - data: Phaser.LoaderParser[extension](arrayBuffer), + data: data, url: url, key: key, fileFormat: extension diff --git a/src/loader/Loader.js b/src/loader/Loader.js index 077e01e51..fe1888dde 100644 --- a/src/loader/Loader.js +++ b/src/loader/Loader.js @@ -720,7 +720,17 @@ Phaser.Loader.prototype = { }, texture: function (key, object, overwrite) { - return this.addToFileList('texture', key, object, undefined, overwrite, '.pvr'); + var compression = this.game.renderer.extensions.compression, exkey; + if (this.game.renderType === Phaser.WEBGL) { + for (exkey in object) { + if (exkey in compression) { + this.addToFileList('texture', key + '_' + exkey, object[exkey], undefined, overwrite, '.pvr'); + } else if (exkey === 'truecolor') { + this.addToFileList('texture', key + '_' + exkey, object[exkey], undefined, overwrite, '.png'); + } + } + } + return this; }, /** @@ -1958,7 +1968,6 @@ Phaser.Loader.prototype = { file.errorMessage = errorMessage; console.warn('Phaser.Loader - ' + file.type + '[' + file.key + ']' + ': ' + errorMessage); - // debugger; } this.processLoadQueue(); @@ -2192,6 +2201,10 @@ Phaser.Loader.prototype = { this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.fileComplete); break; case 'texture': + if (file.key.split('_').pop() === 'truecolor') { + this.loadImageTag(file); + break; + } case 'binary': this.xhrLoad(file, this.transformUrl(file.url, file), 'arraybuffer', this.fileComplete); break; @@ -2666,7 +2679,10 @@ Phaser.Loader.prototype = { file.data = data || {}; break; case 'texture': - this.cache.addCompressedTextureMetaData(file.key, file.url, file.url.split('.').pop().toLowerCase(), xhr.response); + if (file.data != null) + this.cache.addCompressedTextureMetaData(file.key, file.url, file.url.split('.').pop().toLowerCase(), file.data); + else + this.cache.addCompressedTextureMetaData(file.key, file.url, file.url.split('.').pop().toLowerCase(), xhr.response); break; case 'image': diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index e290a6d19..01ee2b5c3 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -34,6 +34,8 @@ PIXI.WebGLRenderer = function (game) { */ this.type = PIXI.WEBGL_RENDERER; + this.extensions = {}; + /** * The resolution of the renderer * @@ -208,6 +210,7 @@ PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer; PIXI.WebGLRenderer.prototype.initContext = function() { var gl = this.view.getContext('webgl', this._contextOptions) || this.view.getContext('experimental-webgl', this._contextOptions); + var etc1, pvrtc, s3tc; this.gl = gl; this.maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); @@ -240,6 +243,17 @@ PIXI.WebGLRenderer.prototype.initContext = function() // now resize and we are good to go! this.resize(this.width, this.height); + + // Load WebGL extension + this.extensions.compression = {}; + + etc1 = gl.getExtension('WEBGL_compressed_texture_etc1') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_etc1'); + pvrtc = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc'); + s3tc = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc'); + + if (etc1) this.extensions.compression.etc1 = etc1; + if (pvrtc) this.extensions.compression.pvrtc = pvrtc; + if (s3tc) this.extensions.compression.s3tc = s3tc; }; PIXI.WebGLRenderer.prototype.setTexturePriority = function (textureNameCollection) {