Page 1 of 1
Access local texture in workspace listener?
Posted: Wed Jun 21, 2023 12:54 am
by jwwalker
If a compositor node creates a local texture, how can I access that in a workspace listener callback, say passPreExecute or passPosExecute? I thought I could do it using compositorPass->getRenderPassDesc()->findAnyTexture, but It doesn't seem reliable. Maybe it works for render scene passes but not for render quad passes. In the cases where I'm not getting what I expect, the texture is there and has the expected dimensions, but is all black.
Re: Access local texture in workspace listener?
Posted: Wed Jun 21, 2023 6:16 am
by dark_sylinc
By name:
Code: Select all
pass->getParentNode()->getDefinedTexture( "texture_name" );
Though your have other, more direct, non-lookup ways.
If you know in advance where the texture is in the RTV, you can just do:
Code: Select all
pass->getRenderPassDesc()->mColour[idx].texture
Where idx is a value you already know on advance (typically 0 unless you're doing MRT).
Code: Select all
pass->getRenderPassDesc()->mDepth.texture
If it's depth.
And if it's a render quad, you can down cast to CompositorPassQuad and look for the material's texture unit (mat->getTechnique()->getPass()->getTextureUnitState).
Usually if I do the direct ways, I put a few asserts to double check the script hasn't gone out of sync with the code (i.e. things are the way I expect, like number of passes, type of pass at the idx I want, etc).
Re: Access local texture in workspace listener?
Posted: Wed Jun 21, 2023 6:01 pm
by jwwalker
Thanks for providing several approaches, that's very helpful. I knew about the mColour and mDepth members of RenderPassDescriptor by looking at the source code of the findAnyTexture method that I mentioned. But the mColour array doesn't always seem to have what I want in it. In a case I was looking at in the Xcode debugger, mColour[0].texture contains a value of type Ogre::MetalTextureGpuWindow* that doesn't contain an actual texture at this point, whereas the other two approaches show a value of type Ogre::MetalTextureGpuRenderTarget* containing the expected image.
By the way, the material member of the CompositorPassQuad class is protected, with no public accessor, so I had to add my own accessor to try it.
Re: Access local texture in workspace listener?
Posted: Wed Jun 21, 2023 6:29 pm
by dark_sylinc
jwwalker wrote: Wed Jun 21, 2023 6:01 pm
Thanks for providing several approaches, that's very helpful. I knew about the mColour and mDepth members of RenderPassDescriptor by looking at the source code of the findAnyTexture method that I mentioned. But the mColour array doesn't always seem to have what I want in it. In a case I was looking at in the Xcode debugger, mColour[0].texture contains a value of type Ogre::MetalTextureGpuWindow* that doesn't contain an actual texture at this point, whereas the other two approaches show a value of type Ogre::MetalTextureGpuRenderTarget* containing the expected image.
I forgot to mention:
If you're using MSAA, you may have to look in RenderPassTargetBase::resolveTexture as well.
resolveTexture can be:
-
nullptr (e.g. no MSAA or no resolve step)
-
The same value as texture (IIRC, implicit resolved textures)
-
A different value (e.g. explicit MSAA resolve where the RTV was setup by hand)
jwwalker wrote: Wed Jun 21, 2023 6:01 pm
By the way, the material member of the CompositorPassQuad class is protected, with no public accessor, so I had to add my own accessor to try it.
You have access to CompositorPassQuad::getPass which is even better, because a Material can have multiple techniques. The returned pass is essentially the same as material->getBestTechnique()->getPass(idx).