Progress of new backend API

Progress of new backend API


If you don’t know what’s backend API, then you can refer to this ticket for detail information. The backend API is to design a API that cross metal/opengl/vulkan. This ticket will update the progress of the API design and implementation.

After about one or two months discussion and learning, i started implementing the API about weeks ago, and i added some test cases. My plan is to implement opengl backend first to polish the API, then use metal to implement it. Of course the API may change when implementing metal backend, but i think the architecture will not change, just adjust some API, such as the API names, parameters and so on.

You can download the codes to take a look of the API and run the test cases. The steps of downloading source codes and running tests are:

Currently, there are 3 test cases, you can change tests/main.cpp to run different test cases.

All the codes of new backend API is in src/backend, all the test cases are in test/tests/backend. As you can see, in order to draw a frame, you should use command buffer to commit things:

  • start render pass
  • set view port
  • set renderpipeline
  • set vertex buffer/index buffer
  • draw arrays/elements
  • end render pass

The backend API is not completed, but most parts are included. Some questions i have currently are:

  • Is it too complex to clear color/depth/stencil? But metal clear these values like this.
  • Device.createXXX return autoreleased objects as other cocos2d-x API, but most times, you don’t want autoreleased objects, they are retained to be used later. Should change it? Or use other better function names?
  • Command queue seems not needed in opengl, and metal also can have only one queue, should remove command queue, and use default command queue in metal?
  • Are there any important features missed?

Any feedback is appreciated. Thanks in advanced.

Graphics backend for opengl and metal
Getting Started with Cocos2D



  • add depth texture test
  • iOS can work too
  • can touch the screen to switch test cases
  • fix sampler usage
  • add TextureFormat::D16
  • fix some logic error in RenderCommandGL

Works left:

  • add blending support
  • add more test cases



  • add blending support and test case


I will start metal backend implementation tomorrow. I think it is time to do it. Though the API is not completed, but it covers at least 90% usage. Starting metal backend implementation will polish the API ASAP.


Great Work @zhangxm Can we expect Metal support cocos release in 5 or 6 months? Also initially are you planning to support Vulkan as well?


@kiranb47 if only implementing metal backend without adapting cocos2d-x, then i think it is not problem. Currently, i am not sure how long it should to adapt cocos2d-x, since it is not easily copy/paste. Vulkan supporting will be started after cocos2d-x supports metal.


Great Work @zhangxm.
We can do custom openGL rendering in current version of cocos.
Can we do same thing with metal in the future?
Thanks a lot.


@amin13a yep, i think it is possible. But you should not use opengl/metal API directly, use the backend API.


I’m waiting for a metal support cocos2dx version. May be Cocos2dx V4.x. I know it takes time. I will wait. Thank you


Thanks. And yes, it can be named v4.x since it may break some API, and i may remove 3d related codes to simplify the adaption.