Skip to content

Commit 702bc9b

Browse files
committed
fixed issues with conflict resolving
1 parent d0c23c1 commit 702bc9b

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

src/pixi/renderers/webgl/WebGLRenderer.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ PIXI.WebGLRenderer = function(game) {
2828
PIXI.defaultRenderer = this;
2929
}
3030

31+
this.extensions = {};
32+
3133
/**
3234
* @property type
3335
* @type Number
@@ -247,6 +249,17 @@ PIXI.WebGLRenderer.prototype.initContext = function()
247249

248250
// now resize and we are good to go!
249251
this.resize(this.width, this.height);
252+
253+
// Load WebGL extension
254+
this.extensions.compression = {};
255+
256+
etc1 = gl.getExtension('WEBGL_compressed_texture_etc1') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_etc1');
257+
pvrtc = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
258+
s3tc = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
259+
260+
if (etc1) this.extensions.compression.ETC1 = etc1;
261+
if (pvrtc) this.extensions.compression.PVRTC = pvrtc;
262+
if (s3tc) this.extensions.compression.S3TC = s3tc;
250263
};
251264

252265
/**
@@ -426,6 +439,65 @@ PIXI.WebGLRenderer.prototype.resize = function(width, height)
426439
this.projection.y = -this.height / 2 / this.resolution;
427440
};
428441

442+
/**
443+
* Updates and creates a WebGL compressed texture for the renderers context.
444+
*
445+
* @method updateCompressedTexture
446+
* @param texture {Texture} the texture to update
447+
* @return {boolean} True if the texture was successfully bound, otherwise false.
448+
*/
449+
PIXI.WebGLRenderer.prototype.updateCompressedTexture = function (texture) {
450+
if (!texture.hasLoaded)
451+
{
452+
return false;
453+
}
454+
var gl = this.gl;
455+
var textureMetaData = texture.source;
456+
457+
if (!texture._glTextures[gl.id])
458+
{
459+
texture._glTextures[gl.id] = gl.createTexture();
460+
}
461+
gl.activeTexture(gl.TEXTURE0 + texture.textureIndex);
462+
463+
gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
464+
465+
gl.compressedTexImage2D(
466+
gl.TEXTURE_2D,
467+
0,
468+
textureMetaData.glExtensionFormat,
469+
textureMetaData.width,
470+
textureMetaData.height,
471+
0,
472+
textureMetaData.textureData
473+
);
474+
475+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
476+
477+
if (texture.mipmap && PIXI.isPowerOfTwo(texture.width, texture.height))
478+
{
479+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST);
480+
gl.generateMipmap(gl.TEXTURE_2D);
481+
}
482+
else
483+
{
484+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
485+
}
486+
487+
if (!texture._powerOf2)
488+
{
489+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
490+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
491+
}
492+
else
493+
{
494+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
495+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
496+
}
497+
texture._dirty[gl.id] = false;
498+
return true;
499+
};
500+
429501
/**
430502
* Updates and Creates a WebGL texture for the renderers context.
431503
*
@@ -439,6 +511,9 @@ PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
439511
{
440512
return false;
441513
}
514+
if (texture.source.compressionAlgorithm) {
515+
return this.updateCompressedTexture(texture);
516+
}
442517

443518
var gl = this.gl;
444519

0 commit comments

Comments
 (0)