mirror of https://github.com/axmolengine/axmol.git
Merge pull request #4983 from dabingnn/develop_layerColorBug
fix layerColor occlude sprite bug on android
This commit is contained in:
commit
ac8a7b4ce1
|
@ -50,6 +50,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";
|
||||
|
|
|
@ -84,6 +84,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;
|
||||
|
|
|
@ -513,7 +513,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;
|
||||
|
@ -568,6 +568,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()
|
||||
|
@ -575,18 +589,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
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCEventKeyboard.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -299,7 +300,7 @@ protected:
|
|||
Vertex2F _squareVertices[4];
|
||||
Color4F _squareColors[4];
|
||||
CustomCommand _customCommand;
|
||||
|
||||
Vertex3F _noMVPVertices[4];
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(LayerColor);
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ enum {
|
|||
kShaderType_PositionTextureColor_noMVP,
|
||||
kShaderType_PositionTextureColorAlphaTest,
|
||||
kShaderType_PositionColor,
|
||||
kShaderType_PositionColor_noMVP,
|
||||
kShaderType_PositionTexture,
|
||||
kShaderType_PositionTexture_uColor,
|
||||
kShaderType_PositionTextureA8Color,
|
||||
|
@ -125,6 +126,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
|
||||
//
|
||||
|
@ -203,6 +211,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
|
||||
//
|
||||
|
@ -289,6 +303,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);
|
||||
|
|
Loading…
Reference in New Issue