diff --git a/cocos/2d/CCGLProgram.cpp b/cocos/2d/CCGLProgram.cpp index 0d9441cde3..dbdd14f686 100644 --- a/cocos/2d/CCGLProgram.cpp +++ b/cocos/2d/CCGLProgram.cpp @@ -49,6 +49,7 @@ const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR = "ShaderPositionTextu const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP = "ShaderPositionTextureColor_noMVP"; const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST = "ShaderPositionTextureColorAlphaTest"; const char* GLProgram::SHADER_NAME_POSITION_COLOR = "ShaderPositionColor"; +const char* GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP = "ShaderPositionColor_noMVP"; const char* GLProgram::SHADER_NAME_POSITION_TEXTURE = "ShaderPositionTexture"; const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_U_COLOR = "ShaderPositionTexture_uColor"; const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR = "ShaderPositionTextureA8Color"; diff --git a/cocos/2d/CCGLProgram.h b/cocos/2d/CCGLProgram.h index 84aaa113fa..24e6f47e7e 100644 --- a/cocos/2d/CCGLProgram.h +++ b/cocos/2d/CCGLProgram.h @@ -82,6 +82,7 @@ public: static const char* SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP; static const char* SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST; static const char* SHADER_NAME_POSITION_COLOR; + static const char* SHADER_NAME_POSITION_COLOR_NO_MVP; static const char* SHADER_NAME_POSITION_TEXTURE; static const char* SHADER_NAME_POSITION_TEXTURE_U_COLOR; static const char* SHADER_NAME_POSITION_TEXTURE_A8_COLOR; diff --git a/cocos/2d/CCLayer.cpp b/cocos/2d/CCLayer.cpp index 488dbc3d1a..1526a686a9 100644 --- a/cocos/2d/CCLayer.cpp +++ b/cocos/2d/CCLayer.cpp @@ -512,7 +512,7 @@ bool LayerColor::initWithColor(const Color4B& color, GLfloat w, GLfloat h) updateColor(); setContentSize(Size(w, h)); - setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_COLOR)); + setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP)); return true; } return false; @@ -567,6 +567,20 @@ void LayerColor::draw() _customCommand.init(0, _vertexZ); _customCommand.func = CC_CALLBACK_0(LayerColor::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); + + kmMat4 p, mvp; + kmGLGetMatrix(KM_GL_PROJECTION, &p); + kmGLGetMatrix(KM_GL_MODELVIEW, &mvp); + kmMat4Multiply(&mvp, &p, &mvp); + + for(int i = 0; i < 4; ++i) + { + kmVec3 pos; + pos.x = _squareVertices[i].x; pos.y = _squareVertices[i].y; pos.z = _vertexZ; + kmVec3TransformCoord(&pos, &pos, &mvp); + _noMVPVertices[i] = Vertex3F(pos.x,pos.y,pos.z); + } + } void LayerColor::onDraw() @@ -574,18 +588,17 @@ void LayerColor::onDraw() CC_NODE_DRAW_SETUP(); GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR ); - // // Attributes // #ifdef EMSCRIPTEN - setGLBufferData(_squareVertices, 4 * sizeof(Vertex2F), 0); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0); + setGLBufferData(_noMVPVertices, 4 * sizeof(Vertex3F), 0); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, 0, 0); setGLBufferData(_squareColors, 4 * sizeof(Color4F), 1); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, 0); #else - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, _squareVertices); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, 0, _noMVPVertices); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, _squareColors); #endif // EMSCRIPTEN diff --git a/cocos/2d/CCLayer.h b/cocos/2d/CCLayer.h index adc938909e..afe72b1aa7 100644 --- a/cocos/2d/CCLayer.h +++ b/cocos/2d/CCLayer.h @@ -36,6 +36,7 @@ THE SOFTWARE. #include "CCEventKeyboard.h" #include "renderer/CCCustomCommand.h" +#include "renderer/CCQuadCommand.h" NS_CC_BEGIN @@ -298,7 +299,7 @@ protected: Vertex2F _squareVertices[4]; Color4F _squareColors[4]; CustomCommand _customCommand; - + Vertex3F _noMVPVertices[4]; private: CC_DISALLOW_COPY_AND_ASSIGN(LayerColor); diff --git a/cocos/2d/CCShaderCache.cpp b/cocos/2d/CCShaderCache.cpp index c727294e30..ae987a0060 100644 --- a/cocos/2d/CCShaderCache.cpp +++ b/cocos/2d/CCShaderCache.cpp @@ -36,6 +36,7 @@ enum { kShaderType_PositionTextureColor_noMVP, kShaderType_PositionTextureColorAlphaTest, kShaderType_PositionColor, + kShaderType_PositionColor_noMVP, kShaderType_PositionTexture, kShaderType_PositionTexture_uColor, kShaderType_PositionTextureA8Color, @@ -124,6 +125,13 @@ void ShaderCache::loadDefaultShaders() loadDefaultShader(p, kShaderType_PositionColor); _programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_COLOR, p) ); + // + // Position, Color shader no MVP + // + p = new GLProgram(); + loadDefaultShader(p, kShaderType_PositionColor_noMVP); + _programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP, p) ); + // // Position Texture shader // @@ -202,6 +210,12 @@ void ShaderCache::reloadDefaultShaders() p->reset(); loadDefaultShader(p, kShaderType_PositionColor); + // + // Position, Color shader no MVP + // + p = getProgram(GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP); + loadDefaultShader(p, kShaderType_PositionColor_noMVP); + // // Position Texture shader // @@ -288,6 +302,12 @@ void ShaderCache::loadDefaultShader(GLProgram *p, int type) p->addAttribute(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); p->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); + break; + case kShaderType_PositionColor_noMVP: + p->initWithVertexShaderByteArray(ccPositionTextureColor_noMVP_vert ,ccPositionColor_frag); + + p->addAttribute(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); + p->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); break; case kShaderType_PositionTexture: p->initWithVertexShaderByteArray(ccPositionTexture_vert ,ccPositionTexture_frag);