Custom Command in 4.0: How to draw a triangle strip

Hi there,
I am now updating to 4.0 and have problems updating my custom commands where I would do custom drawing.

Here is an example how I accomplished this in V3 -
I would create a custom command and draw my stuff in the callback function:

AnimatedTextureRender::AnimatedTextureRender(Size s, Texture2D *texture,bool stretchTexture){
    

    mTexture = texture;
    _stretchTexture = stretchTexture;
    setGLProgram(GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE));
    cocos2d::Texture2D::TexParams tp1 = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
    mTexture->setTexParameters(tp1);
    
    
    mTexture->retain();
    this->setContentSize(s);
    _s = s;
    autorelease();
    this->scheduleUpdate();
    
}




void AnimatedTextureRender::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4& transform, uint32_t flags){
    mCustomCommand.init(_globalZOrder);
    mCustomCommand.func = CC_CALLBACK_0(AnimatedTextureRender::onDraw, this, transform, flags);
    renderer->addCommand(&mCustomCommand);
    
}



void AnimatedTextureRender::onDraw(const cocos2d::Mat4 &transform, uint32_t flags){
    
    
    auto glProgram = getGLProgram();
    glProgram->use();
    glProgram->setUniformsForBuiltins(transform);
    
    
    GL::bindTexture2D(mTexture->getName());
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORD);
    
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, _groundVectorData);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, _textureVectorData);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)4);
    
    CC_INCREMENT_GL_DRAWS(1);
        
    
    
}

Could anybody help me to convert this code to V4 @zhangxm, @slackmoehrle ?

I cannot really find a tutorial where this is explained in detail, looking into https://docs.cocos2d-x.org/cocos2d-x/v4/en/upgradeGuide/customCommandTutorial.html helped a bit - but was not enough for me to understand what I need to do.

Any help is appreciated :slight_smile:

Hi,

you can refer to the CustomCommand codes here from CCTexture2D

and this is the part where it draws.

If your _groundVectorData or _textureVectorData is fixed from the start, you can refer to this example from Cpp-tests.

You can also describe which part do you have problem understanding