fix ShadeNodeTest->SpriteBlur

This commit is contained in:
Huabing.Xu 2013-12-25 16:54:09 +08:00
parent 6b6b37b1ad
commit 2eaba86d76
1 changed files with 19 additions and 10 deletions

View File

@ -204,7 +204,6 @@ void ShaderNode::draw()
void ShaderNode::onDraw() void ShaderNode::onDraw()
{ {
return;
CC_NODE_DRAW_SETUP(); CC_NODE_DRAW_SETUP();
float w = SIZE_X, h = SIZE_Y; float w = SIZE_X, h = SIZE_Y;
@ -448,6 +447,8 @@ public:
GLuint blurLocation; GLuint blurLocation;
GLuint subLocation; GLuint subLocation;
protected:
void onDraw();
}; };
SpriteBlur::~SpriteBlur() SpriteBlur::~SpriteBlur()
@ -530,39 +531,47 @@ void SpriteBlur::initProgram()
} }
void SpriteBlur::draw() void SpriteBlur::draw()
{
CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(SpriteBlur::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(cmd);
}
void SpriteBlur::onDraw()
{ {
GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX ); GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
BlendFunc blend = getBlendFunc(); BlendFunc blend = getBlendFunc();
GL::blendFunc(blend.src, blend.dst); GL::blendFunc(blend.src, blend.dst);
getShaderProgram()->use(); getShaderProgram()->use();
getShaderProgram()->setUniformsForBuiltins(); getShaderProgram()->setUniformsForBuiltins();
getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y); getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y);
getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1); getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1);
GL::bindTexture2D( getTexture()->getName()); GL::bindTexture2D( getTexture()->getName());
// //
// Attributes // Attributes
// //
#define kQuadSize sizeof(_quad.bl) #define kQuadSize sizeof(_quad.bl)
long offset = (long)&_quad; long offset = (long)&_quad;
// vertex // vertex
int diff = offsetof( V3F_C4B_T2F, vertices); int diff = offsetof( V3F_C4B_T2F, vertices);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));
// texCoods // texCoods
diff = offsetof( V3F_C4B_T2F, texCoords); diff = offsetof( V3F_C4B_T2F, texCoords);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff)); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));
// color // color
diff = offsetof( V3F_C4B_T2F, colors); diff = offsetof( V3F_C4B_T2F, colors);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff)); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
CC_INCREMENT_GL_DRAWS(1); CC_INCREMENT_GL_DRAWS(1);
} }