How to get shared handle to texture?

Problems building or running the engine, queries about how to use features etc.
Post Reply
CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

How to get shared handle to texture?

Post by CrosRoad95 »

Ogre Version: : 3.0
Operating System: : Windows11
Render System: : Dx11

How can i get shared handle to texture? I want this because i have an old gui system that uses dx9, the idea is to create in dx11 render system a texture, and pass shared handle to dx9
can't see "getSharedHandle" method on any of ID3D11 resources

rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: How to get shared handle to texture?

Post by rpgplayerrobin »

I am not sure if this is possible, because I guess that Ogre is trying to be non-rendersystem specific, which means that getting a Direct3D9 texture pointer might be different than getting an OpenGL texture pointer for example.

Maybe there exists a code somewhere for it, but if it does not exist, you can alter the source code of Ogre to allow such a function from a TexturePtr which only works for specific one rendersystem such as Direct3D9 as you want.

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

Re: How to get shared handle to texture?

Post by dark_sylinc »

It is possible.

Do:

Code: Select all

ID3D11Resource *d3d11Tex = 0;
textureGpu->getCustomAttribute( Ogre::TextureGpu::msFinalTextureBuffer, (void*)&d3d11Tex );

This works for all other APIs (GL, Vulkan, Metal). But of course it won't be a ID3D11Resource.

Cheers
Matias

CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: How to get shared handle to texture?

Post by CrosRoad95 »

hmm, what i'm doing wrong?

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

Re: How to get shared handle to texture?

Post by dark_sylinc »

Try casting (void*)&pDXGIResource instead of (void**)&pDXGIResource.

But other than that it may be that you can't just query that pointer directly from d3d11Tex. I'm not familiar with querying IDXGIResource. You should check you got valid handles in the previous steps. By the time it crashed it's already too late.

d3d11Tex may have been nullptr
pDXGIResource may have been nullptr

Check those too.

CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: How to get shared handle to texture?

Post by CrosRoad95 »

(void*)&pDXGIResource - can't be used

"textureGpu", "d3d11Tex", "pDXGIResource" from the example above are not null
only last handle is null

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

Re: How to get shared handle to texture?

Post by dark_sylinc »

Initialize pDXGIResource to nullptr first, before the query call. It may be left uninitialized.

CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: How to get shared handle to texture?

Post by CrosRoad95 »

Initialized everything, handle still remain nullptr

Code: Select all

    Ogre::TextureGpu* textureGpu =
        m_pTextureManager->createOrRetrieveTexture("cegui", GpuPageOutStrategy::Discard, TextureFlags::ManualTexture, TextureTypes::Type2D);
    textureGpu->setResolution(1920, 1080);
    textureGpu->setPixelFormat(PFG_RGBA8_UNORM);
    textureGpu->scheduleTransitionTo(GpuResidency::Resident);
    ID3D11Resource* d3d11Tex = 0;

textureGpu->getCustomAttribute(Ogre::TextureGpu::msFinalTextureBuffer, (void*)&d3d11Tex);
IDXGIResource* pDXGIResource = 0;
d3d11Tex->QueryInterface(__uuidof(IDXGIResource), (void**)&pDXGIResource);
HANDLE                             handle = 0;
pDXGIResource->GetSharedHandle(&handle);
Post Reply