0

アルファ テクスチャを SpriteBatchNode にバインドする方法を教えてください。テクスチャ アルファとオリジンの両方を使用するシェーダーがあります。Sprite を拡張し、それにアルファ テクスチャをバインドすると、正常に動作します。しかし、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);
}
4

0 に答える 0