Skip to content

Commit aba13a2

Browse files
committed
Merge pull request #2712 from dingpinglv/Iss2699_Sprite
Fixed #2699: added the parameter 'premultiplied' to cc.Texture
2 parents cfc8f72 + 32ec57d commit aba13a2

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

CCBoot.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,8 @@ cc._setup = function (el, width, height) {
18531853
'stencil': true,
18541854
'preserveDrawingBuffer': true,
18551855
'antialias': !cc.sys.isMobile,
1856-
'alpha': false});
1856+
'alpha': false
1857+
});
18571858
if (cc._renderContext) {
18581859
win.gl = cc._renderContext; // global variable declared in CCMacro.js
18591860
cc._drawingUtil = new cc.DrawingPrimitiveWebGL(cc._renderContext);

cocos2d/core/platform/CCTypesWebGL.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ cc._tmp.WebGLColor = function () {
561561
//redefine cc.V2F_C4B_T2F
562562
/**
563563
* @class cc.V2F_C4B_T2F
564-
* @param {new cc.Vertex2F} vertices
564+
* @param {cc.Vertex2F} vertices
565565
* @param {cc.color} colors
566566
* @param {cc.Tex2F} texCoords
567567
* @param {Array} arrayBuffer

cocos2d/core/textures/TexturesWebGL.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,10 @@ cc._tmp.WebGLTexture2D = function () {
442442

443443
/**
444444
* handler of texture loaded event
445+
* @param {Boolean} [premultipled=false]
445446
*/
446-
handleLoadedTexture: function () {
447+
handleLoadedTexture: function (premultipled) {
448+
premultipled = (premultipled === undefined)?false: premultipled;
447449
var self = this;
448450
// Not sure about this ! Some texture need to be updated even after loaded
449451
if (!cc._rendererInitialized)
@@ -462,6 +464,8 @@ cc._tmp.WebGLTexture2D = function () {
462464
cc.glBindTexture2D(self);
463465

464466
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
467+
if(premultipled)
468+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
465469

466470
// Specify OpenGL texture image
467471
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, self._htmlElementObj);
@@ -473,6 +477,8 @@ cc._tmp.WebGLTexture2D = function () {
473477

474478
self.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURE);
475479
cc.glBindTexture2D(null);
480+
if(premultipled)
481+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
476482

477483
var pixelsWide = self._htmlElementObj.width;
478484
var pixelsHigh = self._htmlElementObj.height;
@@ -483,7 +489,7 @@ cc._tmp.WebGLTexture2D = function () {
483489
self.maxS = 1;
484490
self.maxT = 1;
485491

486-
self._hasPremultipliedAlpha = false;
492+
self._hasPremultipliedAlpha = premultipled;
487493
self._hasMipmaps = false;
488494

489495
//dispatch load event to listener.

0 commit comments

Comments
 (0)