Merge pull request #5649 from dabingnn/develop_fix_clippingNodeShaderBug

closed #4315: fixed clippingNode alphaTest Bug
This commit is contained in:
minggo 2014-03-10 21:45:47 +08:00
Родитель e9b13772e8 f8f2373c2a
Коммит 2aa5c7aadd
4 изменённых файлов: 21 добавлений и 1 удалений

Просмотреть файл

@ -231,7 +231,7 @@ void ClippingNode::visit(Renderer *renderer, const kmMat4 &parentTransform, bool
#else #else
// since glAlphaTest do not exists in OES, use a shader that writes // since glAlphaTest do not exists in OES, use a shader that writes
// pixel only if greater than an alpha threshold // pixel only if greater than an alpha threshold
GLProgram *program = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST); GLProgram *program = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV);
GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE); GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
// set our alphaThreshold // set our alphaThreshold
program->use(); program->use();

Просмотреть файл

@ -49,6 +49,7 @@ typedef struct _hashUniformEntry
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR = "ShaderPositionTextureColor"; const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR = "ShaderPositionTextureColor";
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP = "ShaderPositionTextureColor_noMVP"; 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_TEXTURE_ALPHA_TEST = "ShaderPositionTextureColorAlphaTest";
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV = "ShaderPositionTextureColorAlphaTest_NoMV";
const char* GLProgram::SHADER_NAME_POSITION_COLOR = "ShaderPositionColor"; 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_COLOR_NO_MVP = "ShaderPositionColor_noMVP";
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE = "ShaderPositionTexture"; const char* GLProgram::SHADER_NAME_POSITION_TEXTURE = "ShaderPositionTexture";

Просмотреть файл

@ -82,6 +82,7 @@ public:
static const char* SHADER_NAME_POSITION_TEXTURE_COLOR; static const char* SHADER_NAME_POSITION_TEXTURE_COLOR;
static const char* SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP; 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_TEXTURE_ALPHA_TEST;
static const char* SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV;
static const char* SHADER_NAME_POSITION_COLOR; static const char* SHADER_NAME_POSITION_COLOR;
static const char* SHADER_NAME_POSITION_COLOR_NO_MVP; static const char* SHADER_NAME_POSITION_COLOR_NO_MVP;
static const char* SHADER_NAME_POSITION_TEXTURE; static const char* SHADER_NAME_POSITION_TEXTURE;

Просмотреть файл

@ -36,6 +36,7 @@ enum {
kShaderType_PositionTextureColor, kShaderType_PositionTextureColor,
kShaderType_PositionTextureColor_noMVP, kShaderType_PositionTextureColor_noMVP,
kShaderType_PositionTextureColorAlphaTest, kShaderType_PositionTextureColorAlphaTest,
kShaderType_PositionTextureColorAlphaTestNoMV,
kShaderType_PositionColor, kShaderType_PositionColor,
kShaderType_PositionColor_noMVP, kShaderType_PositionColor_noMVP,
kShaderType_PositionTexture, kShaderType_PositionTexture,
@ -118,6 +119,10 @@ void ShaderCache::loadDefaultShaders()
loadDefaultShader(p, kShaderType_PositionTextureColorAlphaTest); loadDefaultShader(p, kShaderType_PositionTextureColorAlphaTest);
_programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST, p) ); _programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST, p) );
// Position Texture Color alpha test
p = new GLProgram();
loadDefaultShader(p, kShaderType_PositionTextureColorAlphaTestNoMV);
_programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV, p) );
// //
// Position, Color shader // Position, Color shader
// //
@ -199,6 +204,10 @@ void ShaderCache::reloadDefaultShaders()
p->reset(); p->reset();
loadDefaultShader(p, kShaderType_PositionTextureColorAlphaTest); loadDefaultShader(p, kShaderType_PositionTextureColorAlphaTest);
// Position Texture Color alpha test
p = getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV);
p->reset();
loadDefaultShader(p, kShaderType_PositionTextureColorAlphaTestNoMV);
// //
// Position, Color shader // Position, Color shader
// //
@ -288,6 +297,15 @@ void ShaderCache::loadDefaultShader(GLProgram *p, int type)
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS); p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
break; break;
case kShaderType_PositionTextureColorAlphaTestNoMV:
p->initWithByteArrays(ccPositionTextureColor_noMVP_vert, ccPositionTextureColorAlphaTest_frag);
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
break;
case kShaderType_PositionColor: case kShaderType_PositionColor:
p->initWithByteArrays(ccPositionColor_vert ,ccPositionColor_frag); p->initWithByteArrays(ccPositionColor_vert ,ccPositionColor_frag);