From 2fae3db7924db35e02444e6168f83452afb4caa2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 6 Jun 2013 14:41:22 +0800 Subject: [PATCH] Minor fix for CCSprite::draw(), checking whether texture is valid, if it's invalid, don't set the attribute for it. --- cocos2dx/sprite_nodes/CCSprite.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index 900a2bf97c..336130abe5 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -554,17 +554,13 @@ void CCSprite::draw(void) if (m_pobTexture != NULL) { ccGLBindTexture2D( m_pobTexture->getName() ); + ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex ); } else { ccGLBindTexture2D(0); + ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_Color ); } - - // - // Attributes - // - - ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex ); #define kQuadSize sizeof(m_sQuad.bl) #ifdef EMSCRIPTEN @@ -578,10 +574,13 @@ void CCSprite::draw(void) int diff = offsetof( ccV3F_C4B_T2F, vertices); glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); - // texCoods - diff = offsetof( ccV3F_C4B_T2F, texCoords); - glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff)); - + if (m_pobTexture != NULL) + { + // texCoods + diff = offsetof( ccV3F_C4B_T2F, texCoords); + glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff)); + } + // color diff = offsetof( ccV3F_C4B_T2F, colors); glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));