I see this a little another:
RenderTexture::onBegin() call’s renderer->setRenderTarget(_renderTargetFlags, _texture2D, _depthStencilTexture, _depthStencilTexture); which exchange render->_renderPassDescriptor corresponding values.
(This allows to have one Frame buffer (with id == 1) and many others attachments combinations.)
RenderTexture_1::onBegin() -> set new depth/color/stencil values for _renderPassDescriptor
RenderTexture_1::onEnd() -> set old depth/color/stencil values for render->_renderPassDescriptor
RenderTexture_2::onBegin() -> set new depth/color/stencil values for _renderPassDescriptor
RenderTexture_2::onEnd() -> set old depth/color/stencil values for render->_renderPassDescriptor
Suppose, that there is only depthAttachmentTexture for RenderTexture_1.
Each calling of Renderer::drawXXXXCommand() will call CommandBufferGL::applyRenderPassDescriptor(). This function disable colorAttachmentTexture via
But there is no enabling it for RenderTexture_2. I mentioned how to patch this behavior in previous message.
Common cocos2d::RenderTexture::onBegin() and onEnd() form CallbackCommand and put it to the render queue where z == 0 (There is five render queues in render engine).
This helps for cocos2d::Sprite, but not for cocos2d::Sprite3D, since MeshCommand will be put to the Opaque or Transparent render queues.
My custom RenderTextureCustom does the following:
RenderTextureCustom::onBegin() -> put CallBackCommand to Opaque queue RenderTextureCustom::clear() -> put CallBackCommand to clear depth/color/stencil to Opaque queue
RenderTextureCustom::onExit() -> put CallBackCommand to Transparent queue.
That is exactly what my class performs. Sorry I do not have any demo, but I can provide you this class if you want.
I know that cocos2d::RenderTexture does not allow to be created without colorAttachmentTexture on the one side. But as I can see low level api should be possible to handle similar cases (different attachment combinations).