Access local texture in workspace listener? Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


jwwalker
Goblin
Posts: 268
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 19

Access local texture in workspace listener?

Post 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.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5477
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1359

Re: Access local texture in workspace listener?

Post 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).

jwwalker
Goblin
Posts: 268
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 19

Re: Access local texture in workspace listener?

Post 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.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5477
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1359

Re: Access local texture in workspace listener?

Post 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:

  1. nullptr (e.g. no MSAA or no resolve step)

  2. The same value as texture (IIRC, implicit resolved textures)

  3. 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).