如何将alpha纹理绑定到SpriteBatchNode?

时间:2015-02-02 06:14:42

标签: cocos2d-x cocos2d-x-3.0 ccspritebatchnode

有人能告诉我如何将alpha纹理绑定到SpriteBatchNode。 我有使用纹理alpha和原点的着色器。我扩展了Sprite并将alpha纹理绑定到它,它工作正常。但我不明白如何将纹理绑定到cocos2d-x v3中的SpriteBatchNode。请帮我。感谢

在SpriteBatchNode中,他们使用具有init和execute方法的BatchCommand。在execute方法中,它们绑定主要纹理,这个源可以在CCBatchCommand.cpp中找到。因为我的原因,我有自己的继承自SpriteBatchNode的ExtBatchNode。

在我的ExtBatchNode的draw方法中,我尝试以不同的方式绑定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);
}

0 个答案:

没有答案