0

Can someone tell me how to bind alpha texture to SpriteBatchNode. I have shader that use both textures alpha and origin. I extended Sprite and bind alpha texture to it and it works fine. But i don't understand how to bind texture to SpriteBatchNode in cocos2d-x v3. please help me. Thanks

In SpriteBatchNode they use BatchCommand that have methods init and execute. in execute method they bind main texture this source you can find in CCBatchCommand.cpp. For my reason i have my own ExtBatchNode that inherited from SpriteBatchNode.

In draw method of my ExtBatchNode i try to bind myAlpha texture for different ways

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);
}
Sufelfay
  • 43
  • 1
  • 4
  • if you can share some of your code then it will be very helpful . – shaqir saiyed Feb 02 '15 at 09:10
  • In SpriteBatchNode they use BatchCommand that have methods init and execute. in execute method they bind main texture this source you can find in CCBatchCommand.cpp. For my reason i have my own ExtBatchNode that inherited from SpriteBatchNode. – Sufelfay Feb 02 '15 at 09:28
  • In draw method of my ExtBatchNode i try to bind myAlpha texture for different ways. – Sufelfay Feb 02 '15 at 09:41
  • Sorry but i'm new here and cann't find how i should put my code in correct form that it's will be ease readable – Sufelfay Feb 02 '15 at 09:51

0 Answers0