有人可以告诉我如何将 alpha 纹理绑定到 SpriteBatchNode。我有同时使用纹理 alpha 和 origin 的着色器。我扩展了 Sprite 并将 alpha 纹理绑定到它,它工作正常。但我不明白如何在 cocos2d-x v3 中将纹理绑定到 SpriteBatchNode。请帮我。谢谢
在 SpriteBatchNode 中,他们使用具有 init 和 execute 方法的 BatchCommand。在执行方法中,他们绑定主纹理这个源你可以在 CCBatchCommand.cpp 中找到。出于我的原因,我有自己的 ExtBatchNode,它继承自 SpriteBatchNode。
在我的 ExtBatchNode 的绘制方法中,我尝试以不同的方式绑定 myAlpha 纹理
void ExtBatchNode::draw(Renderer *renderer, Mat4 &transform, uint32_t flags) {
if( _textureAtlas->getTotalQuads() == 0 ) {
return;
}
for(const auto &child: _children)
child->updateTransform();
_customCommand.init(_globalZOrder);
_customCommand.func = [this, &transform](){
getGLProgram()->use();
getGLProgram()->setUniformsForBuiltins(transform);
cocos2d::GL::bindTexture2D(_textureAtlas->getTexture()->getName() );
if(_pTextureAlpha) {
// _pTextureAlpha it's my texture
// i try to bind texture for different ways
getGLProgramState()->setUniformTexture("u_AlphaTexture", _pTextureAlpha);
}
cocos2d::GL::blendFunc(_blendFunc.src, _blendFunc.dst);
// Draw
_textureAtlas->drawQuads();
// in textureAtlas they have one more main texture bind,maybe i should bind my alpha there?
};
renderer->addCommand(&_customCommand);
}