From ee81c3870b88c4a1a6090d06410c2216716ce762 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 9 Nov 2017 11:25:22 +0800 Subject: [PATCH] Reset bound texture each frame --- cocos2d/core/renderer/RendererWebGL.js | 3 ++- cocos2d/shaders/CCGLStateCache.js | 6 +++--- extensions/spine/SGSkeletonTexture.js | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/renderer/RendererWebGL.js b/cocos2d/core/renderer/RendererWebGL.js index d5e4ee2605..ecdd999c75 100644 --- a/cocos2d/core/renderer/RendererWebGL.js +++ b/cocos2d/core/renderer/RendererWebGL.js @@ -485,8 +485,9 @@ cc.rendererWebGL = { i, len, cmd, context = ctx || cc._renderContext; - // Reset buffer for rendering + // Reset buffer and texture for rendering context.bindBuffer(context.ARRAY_BUFFER, null); + cc.gl.bindTexture2DN(0, null); for (i = 0, len = locCmds.length; i < len; ++i) { cmd = locCmds[i]; diff --git a/cocos2d/shaders/CCGLStateCache.js b/cocos2d/shaders/CCGLStateCache.js index 44a43a2cfb..cf4f258692 100644 --- a/cocos2d/shaders/CCGLStateCache.js +++ b/cocos2d/shaders/CCGLStateCache.js @@ -38,7 +38,7 @@ var MAX_ACTIVETEXTURE = 0, if (ENABLE_GL_STATE_CACHE) { MAX_ACTIVETEXTURE = 16; _currentShaderProgram = -1; - _currentBoundTexture = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]; + _currentBoundTexture = new Array(MAX_ACTIVETEXTURE); _blendingSource = -1; _blendingDest = -1; _GLServerState = 0; @@ -59,7 +59,7 @@ cc.gl.invalidateStateCache = function () { if (ENABLE_GL_STATE_CACHE) { _currentShaderProgram = -1; for (var i = 0; i < MAX_ACTIVETEXTURE; i++) { - _currentBoundTexture[i] = -1; + _currentBoundTexture[i] = null; } _blendingSource = -1; _blendingDest = -1; @@ -228,7 +228,7 @@ cc.gl.deleteTexture2D = function (texture) { cc.gl.deleteTexture2DN = function (textureUnit, texture) { if (ENABLE_GL_STATE_CACHE) { if (texture === _currentBoundTexture[ textureUnit ]) - _currentBoundTexture[ textureUnit ] = -1; + _currentBoundTexture[ textureUnit ] = null; } cc._renderContext.deleteTexture(texture._glID); }; diff --git a/extensions/spine/SGSkeletonTexture.js b/extensions/spine/SGSkeletonTexture.js index 9d544d7d2b..455ee25a54 100644 --- a/extensions/spine/SGSkeletonTexture.js +++ b/extensions/spine/SGSkeletonTexture.js @@ -58,7 +58,7 @@ sp.SkeletonTexture = cc.Class({ bind: function() { if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) { - cc.gl.bindTexture2D(this._texture); + cc.gl.bindTexture2DN(0, this._texture); } } });