@@ -233,6 +233,11 @@ namespace Ogre
233
233
// ---------------------------------------------------------------------
234
234
void D3D11Texture::_create2DTex ()
235
235
{
236
+ if (mSurface )
237
+ {
238
+ _createShared2DTex ();
239
+ return ;
240
+ }
236
241
// we must have those defined here
237
242
assert (mSrcWidth > 0 || mSrcHeight > 0 );
238
243
@@ -303,7 +308,90 @@ namespace Ogre
303
308
304
309
_create2DResourceView ();
305
310
}
306
- // ----------------------------------------------------------------------------
311
+ // ----------------------------------------------------------------------------
312
+ void D3D11Texture::_createShared2DTex ()
313
+ {
314
+ HRESULT hr = S_OK;
315
+
316
+ IUnknown* pUnk = (IUnknown*)mSurface ;
317
+
318
+ IDXGIResource* pDXGIResource;
319
+ hr = pUnk->QueryInterface (__uuidof (IDXGIResource), (void **)&pDXGIResource);
320
+ if (FAILED (hr))
321
+ {
322
+ this ->unloadImpl ();
323
+ OGRE_EXCEPT_EX (Exception::ERR_RENDERINGAPI_ERROR, hr,
324
+ " Error creating texture\n Error Description: Failed to query IDXGIResource interface from "
325
+ " the provided object." ,
326
+ " D3D11Texture::_create2DTex" );
327
+ }
328
+
329
+ HANDLE sharedHandle;
330
+ hr = pDXGIResource->GetSharedHandle (&sharedHandle);
331
+ if (FAILED (hr))
332
+ {
333
+ this ->unloadImpl ();
334
+ OGRE_EXCEPT_EX (Exception::ERR_RENDERINGAPI_ERROR, hr,
335
+ " Error creating texture\n Error Description: Failed to retrieve the shared handle from "
336
+ " IDXGIResource. Ensure the resource was "
337
+ " created with the D3D11_RESOURCE_MISC_SHARED flag." ,
338
+ " D3D11Texture::_create2DTex" );
339
+ }
340
+
341
+ pDXGIResource->Release ();
342
+
343
+ IUnknown* tempResource11;
344
+ hr = mDevice ->OpenSharedResource (sharedHandle, __uuidof (ID3D11Resource), (void **)(&tempResource11));
345
+ if (FAILED (hr))
346
+ {
347
+ this ->unloadImpl ();
348
+ OGRE_EXCEPT_EX (Exception::ERR_RENDERINGAPI_ERROR, hr,
349
+ " Error creating texture\n Error Description: Failed to open shared resource using the shared "
350
+ " handle. Ensure the handle is "
351
+ " valid and the device supports shared resources." ,
352
+ " D3D11Texture::_create2DTex" );
353
+ }
354
+
355
+ ID3D11Texture2D* pOutputResource;
356
+ hr = tempResource11->QueryInterface (__uuidof (ID3D11Texture2D), (void **)(&pOutputResource));
357
+ if (FAILED (hr))
358
+ {
359
+ this ->unloadImpl ();
360
+ OGRE_EXCEPT_EX (Exception::ERR_RENDERINGAPI_ERROR, hr,
361
+ " Error creating texture\n Error Description: Failed to query ID3D11Texture2D interface from "
362
+ " the shared resource. Ensure the "
363
+ " resource is of the correct type." ,
364
+ " D3D11Texture::_create2DTex" );
365
+ }
366
+ tempResource11->Release ();
367
+
368
+ mp2DTex = pOutputResource;
369
+
370
+ D3D11_TEXTURE2D_DESC desc;
371
+ mp2DTex->GetDesc (&desc);
372
+
373
+ D3D11_RENDER_TARGET_VIEW_DESC rtDesc;
374
+ rtDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
375
+ rtDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
376
+ rtDesc.Texture2D .MipSlice = 0 ;
377
+
378
+ ComPtr<ID3D11RenderTargetView> renderTargetView;
379
+ hr = mDevice ->CreateRenderTargetView (mp2DTex.Get (), nullptr , renderTargetView.GetAddressOf ());
380
+ if (FAILED (hr))
381
+ {
382
+ this ->unloadImpl ();
383
+ OGRE_EXCEPT_EX (Exception::ERR_RENDERINGAPI_ERROR, hr,
384
+ " Error creating texture\n Error Description: Failed to create ID3D11RenderTargetView. Verify "
385
+ " that the texture is valid, "
386
+ " properly initialized, and compatible with RenderTargetView creation." ,
387
+ " D3D11Texture::_create2DTex" );
388
+ }
389
+
390
+ _queryInterface<ID3D11Texture2D, ID3D11Resource>(mp2DTex, &mpTex);
391
+
392
+ _create2DResourceView ();
393
+ }
394
+ // ----------------------------------------------------------------------------
307
395
void D3D11Texture::_create2DResourceView ()
308
396
{
309
397
// set final tex. attributes from tex. description
@@ -506,6 +594,8 @@ namespace Ogre
506
594
}
507
595
}
508
596
// ---------------------------------------------------------------------
597
+ void D3D11Texture ::_setSurface (void * surface) { mSurface = surface; }
598
+ // ---------------------------------------------------------------------
509
599
// D3D11RenderTexture
510
600
// ---------------------------------------------------------------------
511
601
void D3D11RenderTexture::rebind ( D3D11HardwarePixelBuffer *buffer )
0 commit comments