本文整理汇总了C++中IDXGIResource类的典型用法代码示例。如果您正苦于以下问题:C++ IDXGIResource类的具体用法?C++ IDXGIResource怎么用?C++ IDXGIResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDXGIResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
DuplicatorInfo CDuplicateOutputDx11::GetNewFrame(ID3D11Texture2D** p2dTexture)
{
DXGI_OUTDUPL_FRAME_INFO frameInfo;
IDXGIResource* pDesktopResource = nullptr;
HRESULT hr = S_OK;
hr = m_pOutputDuplication->AcquireNextFrame(15, &frameInfo, &pDesktopResource);
if (hr == DXGI_ERROR_ACCESS_LOST)
{
return DuplicatorInfo_Lost;
}
else if (hr == DXGI_ERROR_WAIT_TIMEOUT)
{
return DuplicatorInfo_Timeout;
}
else if (hr == DXGI_ERROR_INVALID_CALL)
{
return DuplicatorInfo_InvalidCall;
}
else if (FAILED(hr))
{
return DuplicatorInfo_Error;
}
if (FAILED(hr = pDesktopResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(p2dTexture))))
{
SAFE_RELEASE(pDesktopResource);
DOLOG(" pDesktopResource->QueryInterface failed");
return DuplicatorInfo_Error;
}
SAFE_RELEASE(pDesktopResource);
return DuplicatorInfo_Acquired;
}
示例2: ASSERT
HRESULT CSurfaceQueueDeviceD3D10::GetSharedHandle(IUnknown* pUnknown, HANDLE* pHandle)
{
ASSERT(pUnknown);
ASSERT(pHandle);
if (NULL == pUnknown || NULL == pHandle)
{
return E_FAIL;
}
HRESULT hr = S_OK;
*pHandle = NULL;
IDXGIResource* pSurface;
if (FAILED(hr = pUnknown->QueryInterface(__uuidof(IDXGIResource), (void**)&pSurface)))
{
return hr;
}
hr = pSurface->GetSharedHandle(pHandle);
pSurface->Release();
return hr;
}
示例3: createPbufferFromClientBufferSurface
void createPbufferFromClientBufferSurface()
{
EGLAttrib device = 0;
EGLAttrib angleDevice = 0;
PFNEGLQUERYDISPLAYATTRIBEXTPROC queryDisplayAttribEXT;
PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttribEXT;
const char *extensionString =
static_cast<const char *>(eglQueryString(mDisplay, EGL_EXTENSIONS));
EXPECT_TRUE(strstr(extensionString, "EGL_EXT_device_query"));
queryDisplayAttribEXT =
(PFNEGLQUERYDISPLAYATTRIBEXTPROC)eglGetProcAddress("eglQueryDisplayAttribEXT");
queryDeviceAttribEXT =
(PFNEGLQUERYDEVICEATTRIBEXTPROC)eglGetProcAddress("eglQueryDeviceAttribEXT");
ASSERT_NE(nullptr, queryDisplayAttribEXT);
ASSERT_NE(nullptr, queryDeviceAttribEXT);
ASSERT_EGL_TRUE(queryDisplayAttribEXT(mDisplay, EGL_DEVICE_EXT, &angleDevice));
ASSERT_EGL_TRUE(queryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice),
EGL_D3D11_DEVICE_ANGLE, &device));
ID3D11Device *d3d11Device = reinterpret_cast<ID3D11Device *>(device);
D3D11_TEXTURE2D_DESC textureDesc = {0};
textureDesc.Width = mWindowWidth;
textureDesc.Height = mWindowWidth;
textureDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
ASSERT_TRUE(SUCCEEDED(
d3d11Device->CreateTexture2D(&textureDesc, nullptr, &mOffscreenSurfaceD3D11Texture)));
IDXGIResource *dxgiResource =
DynamicCastComObject<IDXGIResource>(mOffscreenSurfaceD3D11Texture);
ASSERT_NE(nullptr, dxgiResource);
HANDLE sharedHandle = 0;
ASSERT_TRUE(SUCCEEDED(dxgiResource->GetSharedHandle(&sharedHandle)));
SafeRelease(dxgiResource);
EGLint pBufferAttributes[] = {EGL_WIDTH, mWindowWidth, EGL_HEIGHT,
mWindowWidth, EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, EGL_NONE};
mSurface = eglCreatePbufferFromClientBuffer(mDisplay, EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE,
sharedHandle, mConfig, pBufferAttributes);
ASSERT_TRUE(EGL_NO_SURFACE != mSurface);
}
示例4: DoD3D11Hook
bool DoD3D11Hook(ID3D11Device *device)
{
HRESULT hErr;
D3D11_TEXTURE2D_DESC texGameDesc;
ZeroMemory(&texGameDesc, sizeof(texGameDesc));
texGameDesc.Width = d3d11CaptureInfo.cx;
texGameDesc.Height = d3d11CaptureInfo.cy;
texGameDesc.MipLevels = 1;
texGameDesc.ArraySize = 1;
texGameDesc.Format = dxgiFormat;
texGameDesc.SampleDesc.Count = 1;
texGameDesc.BindFlags = D3D11_BIND_RENDER_TARGET|D3D11_BIND_SHADER_RESOURCE;
texGameDesc.Usage = D3D11_USAGE_DEFAULT;
texGameDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
ID3D11Texture2D *d3d11Tex;
if(FAILED(hErr = device->CreateTexture2D(&texGameDesc, NULL, &d3d11Tex)))
{
RUNONCE logOutput << "DoD3D11Hook: creation of intermediary texture failed, result = " << UINT(hErr) << endl;
return false;
}
if(FAILED(hErr = d3d11Tex->QueryInterface(__uuidof(ID3D11Resource), (void**)©TextureGame)))
{
RUNONCE logOutput << "DoD3D11Hook: d3d11Tex->QueryInterface(ID3D11Resource) failed, result = " << UINT(hErr) << endl;
d3d11Tex->Release();
return false;
}
IDXGIResource *res;
if(FAILED(hErr = d3d11Tex->QueryInterface(IID_IDXGIResource, (void**)&res)))
{
RUNONCE logOutput << "DoD3D11Hook: d3d11Tex->QueryInterface(IID_IDXGIResource) failed, result = " << UINT(hErr) << endl;
d3d11Tex->Release();
return false;
}
if(FAILED(hErr = res->GetSharedHandle(&sharedHandle)))
{
RUNONCE logOutput << "DoD3D11Hook: res->GetSharedHandle failed, result = " << UINT(hErr) << endl;
d3d11Tex->Release();
res->Release();
return false;
}
d3d11Tex->Release();
res->Release();
return true;
}
示例5: hook_present
static HRESULT STDMETHODCALLTYPE hook_present(IDXGISwapChain *swap,
UINT sync_interval, UINT flags)
{
IDXGIResource *backbuffer = nullptr;
bool capture_overlay = global_hook_info->capture_overlay;
bool test_draw = (flags & DXGI_PRESENT_TEST) != 0;
bool capture;
HRESULT hr;
if (!data.swap && !capture_active()) {
setup_dxgi(swap);
}
capture = !test_draw && swap == data.swap && !!data.capture;
if (capture && !capture_overlay) {
backbuffer = get_dxgi_backbuffer(swap);
if (!!backbuffer) {
data.capture(swap, backbuffer);
backbuffer->Release();
}
}
unhook(&present);
present_t call = (present_t)present.call_addr;
hr = call(swap, sync_interval, flags);
rehook(&present);
if (capture && capture_overlay) {
/*
* It seems that the first call to Present after ResizeBuffers
* will cause the backbuffer to be invalidated, so do not
* perform the post-overlay capture if ResizeBuffers has
* recently been called. (The backbuffer returned by
* get_dxgi_backbuffer *will* be invalid otherwise)
*/
if (resize_buffers_called) {
resize_buffers_called = false;
} else {
backbuffer = get_dxgi_backbuffer(swap);
if (!!backbuffer) {
data.capture(swap, backbuffer);
backbuffer->Release();
}
}
}
return hr;
}
示例6: GetDescriptor
bool
GetDescriptor(ID3D10Texture2D* aTexture, SurfaceDescriptorD3D10* aDescr)
{
NS_ABORT_IF_FALSE(aTexture && aDescr, "Params must be nonnull");
HRESULT hr;
IDXGIResource* dr = nullptr;
hr = aTexture->QueryInterface(__uuidof(IDXGIResource), (void**)&dr);
if (!SUCCEEDED(hr) || !dr)
return false;
hr = dr->GetSharedHandle(reinterpret_cast<HANDLE*>(&aDescr->handle()));
return !!SUCCEEDED(hr);
}
示例7:
HRESULT D3DImageEx::GetSharedHandle(IUnknown *pUnknown, HANDLE * pHandle)
{
HRESULT hr = S_OK;
*pHandle = NULL;
IDXGIResource* pSurface;
if (FAILED(hr = pUnknown->QueryInterface(__uuidof(IDXGIResource), (void**)&pSurface)))
return hr;
hr = pSurface->GetSharedHandle(pHandle);
pSurface->Release();
return hr;
}
示例8: GetSharedHandle
//
// Returns shared handle
//
HANDLE OUTPUTMANAGER::GetSharedHandle()
{
HANDLE Hnd = nullptr;
// QI IDXGIResource interface to synchronized shared surface.
IDXGIResource* DXGIResource = nullptr;
HRESULT hr = m_SharedSurf->QueryInterface(__uuidof(IDXGIResource), reinterpret_cast<void**>(&DXGIResource));
if (SUCCEEDED(hr))
{
// Obtain handle to IDXGIResource object.
DXGIResource->GetSharedHandle(&Hnd);
DXGIResource->Release();
DXGIResource = nullptr;
}
return Hnd;
}
示例9: d3d9_shtex_init_shtex
static inline bool d3d9_shtex_init_shtex()
{
IDXGIResource *res;
HRESULT hr;
D3D11_TEXTURE2D_DESC desc = {};
desc.Width = data.cx;
desc.Height = data.cy;
desc.Format = data.dxgi_format;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.SampleDesc.Count = 1;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
desc.BindFlags = D3D11_BIND_RENDER_TARGET |
D3D11_BIND_SHADER_RESOURCE;
hr = data.d3d11_device->CreateTexture2D(&desc, nullptr,
(ID3D11Texture2D**)&data.d3d11_tex);
if (FAILED(hr)) {
hlog_hr("d3d9_shtex_init_shtex: Failed to create D3D11 texture",
hr);
return false;
}
hr = data.d3d11_tex->QueryInterface(__uuidof(IDXGIResource),
(void**)&res);
if (FAILED(hr)) {
hlog_hr("d3d9_shtex_init_shtex: Failed to query IDXGIResource",
hr);
return false;
}
hr = res->GetSharedHandle(&data.handle);
res->Release();
if (FAILED(hr)) {
hlog_hr("d3d9_shtex_init_shtex: Failed to get shared handle",
hr);
return false;
}
return true;
}
示例10: OpenD3D11TextureOnD3D10Device
IDXGISurface* OpenD3D11TextureOnD3D10Device(ID3D11Texture2D* texture, ID3D10Device1* device)
{
// Obtain share handle for texture
IDXGIResource* dxgiResource = NULL;
CHECK_HR(texture->QueryInterface(IID_PPV_ARGS(&dxgiResource)));
HANDLE shareHandle = NULL;
CHECK_HR(dxgiResource->GetSharedHandle(&shareHandle));
SafeRelease(dxgiResource);
// Open D3D11 texture on D3D10 device
IDXGISurface* dxgiSurface = NULL;
CHECK_HR(device->OpenSharedResource(shareHandle, IID_PPV_ARGS(&dxgiSurface)));
return dxgiSurface;
}
示例11:
ID3D11Texture2D* DX11Texture2::CreateSharedDXObject(ID3D11Device* device)
const
{
IDXGIResource* resource = nullptr;
HRESULT hr = mDXObject->QueryInterface(__uuidof(IDXGIResource),
(void**)&resource);
CHECK_HR_RETURN("QueryInterface failed", nullptr);
HANDLE handle = nullptr;
hr = resource->GetSharedHandle(&handle);
resource->Release();
CHECK_HR_RETURN("GetSharedHandle failed", nullptr);
ID3D11Texture2D* dxShared = nullptr;
hr = device->OpenSharedResource(handle, __uuidof(ID3D11Texture2D),
(void**)&dxShared);
CHECK_HR_RETURN("OpenSharedResource failed", nullptr);
return dxShared;
}
示例12: acquireNextFrame
ID3D11Texture2D* DesktopDuplication::acquireNextFrame(DXGI_OUTDUPL_FRAME_INFO& frameInfoOut)
{
IDXGIResource* frameResource;
hr = outputDuplication->AcquireNextFrame(acquireTimeout, &frameInfoOut, &frameResource);
if (hr != S_OK)
{
reinitialize(); // Second chance to recover adapter failure.
std::cout << "Next frame acquisition failed: " << hr << ". Reinitializing DXGI subsystems..." << std::endl;
CHECKED(hr, outputDuplication->AcquireNextFrame(acquireTimeout, &frameInfoOut, &frameResource));
}
ID3D11Texture2D* frameTex;
CHECKED(hr, frameResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void **>(&frameTex)));
frameResource->Release();
ID3D11Texture2D* frameStagingTex = copyToStaging(frameTex);
frameTex->Release();
CHECKED(hr, outputDuplication->ReleaseFrame());
return frameStagingTex;
}
示例13: GetNumEyes
//.........这里部分代码省略.........
if (FAILED(hr)) {
std::cerr << "RenderManagerD3D11OpenGL::RegisterRenderBuffers: "
"Can't create texture"
<< std::endl;
return false;
}
// Fill in the resource view for your render texture buffer here
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc = {};
// This must match what was created in the texture to be rendered
// @todo Figure this out by introspection on the texture?
// renderTargetViewDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
renderTargetViewDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
renderTargetViewDesc.Texture2D.MipSlice = 0;
// Create the render target view.
ID3D11RenderTargetView*
renderTargetView; //< Pointer to our render target view
hr = m_D3D11Renderer->m_D3D11device->CreateRenderTargetView(
D3DTexture, &renderTargetViewDesc, &renderTargetView);
if (FAILED(hr)) {
std::cerr << "RenderManagerD3D11OpenGL::RegisterRenderBuffers: "
"Could not create render target"
<< std::endl;
return false;
}
// Create a share handle for the texture, to enable it to be shared
// between multiple devices. Then register the share handle with
// interop.
// https://msdn.microsoft.com/en-us/library/windows/desktop/ff476531(v=vs.85).aspx
// https://www.opengl.org/registry/specs/NV/DX_interop.txt
IDXGIResource* pOtherResource = nullptr;
hr = D3DTexture->QueryInterface(__uuidof(IDXGIResource),
(void**)&pOtherResource);
HANDLE sharedHandle;
hr = pOtherResource->GetSharedHandle(&sharedHandle);
if (FAILED(hr)) {
std::cerr << "RenderManagerD3D11OpenGL::RegisterRenderBuffers: "
"Could not get shared handle"
<< std::endl;
return false;
}
if (wglDXSetResourceShareHandleNV(D3DTexture, sharedHandle) !=
TRUE) {
std::cerr << "RenderManagerD3D11OpenGL::RegisterRenderBuffers()"
": Could not share resource"
<< std::endl;
return false;
}
// Prepare the things we need for wrapping Direct3D
// objects. Information on how to do this comes from
// the DX_interop2.txt file from opengl.org and from the
// secondstory/ofDxSharedTextureExample project on Github.
// Bind the OpenGL texture to the D3D texture for rendering
HANDLE glColorHandle = wglDXRegisterObjectNV(
m_glD3DHandle, D3DTexture, buffers[i].OpenGL->colorBufferName,
GL_TEXTURE_2D, WGL_ACCESS_WRITE_DISCARD_NV);
if (glColorHandle == nullptr) {
std::cerr << "RenderManagerD3D11OpenGL::RegisterRenderBuffers: "
"Can't get Color buffer handle"
<< " (error " << GetLastError() << ")";
switch (GetLastError()) {
case ERROR_INVALID_HANDLE:
示例14: HookLog2
void D3D9Hook::gdiCreateSceneObjects()
{
if(m_sceneObjectsCreated)
return; // Already created
if(!isCapturable())
return; // Not capturable
// Is the back buffer format compatible with DXGI?
if(d3d9ToGdiCompatible(m_bbD3D9Format) == DXGI_FORMAT_UNKNOWN) {
HookLog2(InterprocessLog::Warning,
"Back buffer not compatible with DXGI, falling back to CPU capture");
m_useCpuCopy = true;
return;
}
// Create a dummy DirectX 10 or 10.1 device depending on the system
ID3D10Device *m_dx10Device = HookMain::s_instance->refDummyDX10Device();
if(m_dx10Device == NULL) {
HookLog2(InterprocessLog::Warning,
"Failed to create DirectX 10 device, falling back to CPU capture");
m_useCpuCopy = true;
return;
}
HookLog(stringf("Creating D3D9 scene objects for window of size %d x %d",
m_width, m_height));
// Create D3D9 render target surface
HRESULT res = m_device->CreateRenderTarget(
m_width, m_height, m_bbD3D9Format, D3DMULTISAMPLE_NONE, 0, TRUE,
&m_rtSurface, NULL);
if(FAILED(res)) {
HookLog2(InterprocessLog::Warning, stringf(
"Failed to create shared D3D9 render target. Reason = %s",
getD3D9ErrorCode(res).data()));
goto gdiCreateSceneObjectsFailed1;
}
// Create shared DX10 textures
D3D10_TEXTURE2D_DESC desc;
desc.Width = m_width;
desc.Height = m_height;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = d3d9ToGdiCompatible(m_bbD3D9Format);
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D10_USAGE_DEFAULT;
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
desc.CPUAccessFlags = 0;
desc.MiscFlags =
D3D10_RESOURCE_MISC_SHARED | D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
for(int i = 0; i < NUM_SHARED_TEXTURES; i++) {
res = m_dx10Device->CreateTexture2D(&desc, NULL, &m_dx10Texs[i]);
if(FAILED(res)) {
HookLog2(InterprocessLog::Warning, stringf(
"Failed to create shared DX10 target. Reason = %s",
getDX10ErrorCode(res).data()));
goto gdiCreateSceneObjectsFailed1;
}
}
m_nextDx10Tex = 0;
// Get DXGI shared handles from the textures
for(int i = 0; i < NUM_SHARED_TEXTURES; i++) {
IDXGIResource *dxgiRes = NULL;
res = m_dx10Texs[i]->QueryInterface(
__uuidof(IDXGIResource), (void **)&dxgiRes);
if(FAILED(res)) {
HookLog2(InterprocessLog::Warning, stringf(
"Failed to get DXGI resource. Reason = %s",
getDX10ErrorCode(res).data()));
goto gdiCreateSceneObjectsFailed1;
}
m_dx10TexHandles[i] = NULL;
res = dxgiRes->GetSharedHandle(&m_dx10TexHandles[i]);
dxgiRes->Release();
if(FAILED(res)) {
HookLog2(InterprocessLog::Warning, stringf(
"Failed to get DXGI shared handle. Reason = %s",
getDX10ErrorCode(res).data()));
goto gdiCreateSceneObjectsFailed1;
}
}
#if 0
// Create D3D9 render target surface
HRESULT res = m_device->CreateRenderTarget(
m_width, m_height, m_bbD3D9Format, D3DMULTISAMPLE_NONE, 0, FALSE,
&m_rtSurface, NULL);
if(FAILED(res)) {
HookLog2(InterprocessLog::Warning, stringf(
"Failed to create shared D3D9 render target. Reason = %s",
getD3D9ErrorCode(res).data()));
return; // TODO: Not safe to return here
}
// Create shared D3D9 texture
HANDLE sharedHandle = NULL;
res = m_device->CreateTexture(
//.........这里部分代码省略.........
示例15: ASSERT
//.........这里部分代码省略.........
offscreenTextureDesc.Height = backbufferHeight;
offscreenTextureDesc.Format = backbufferFormatInfo.texFormat;
offscreenTextureDesc.MipLevels = 1;
offscreenTextureDesc.ArraySize = 1;
offscreenTextureDesc.SampleDesc.Count = 1;
offscreenTextureDesc.SampleDesc.Quality = 0;
offscreenTextureDesc.Usage = D3D11_USAGE_DEFAULT;
offscreenTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
offscreenTextureDesc.CPUAccessFlags = 0;
offscreenTextureDesc.MiscFlags = useSharedResource ? ANGLE_RESOURCE_SHARE_TYPE : 0;
HRESULT result = device->CreateTexture2D(&offscreenTextureDesc, NULL, &mOffscreenTexture);
if (FAILED(result))
{
ERR("Could not create offscreen texture: %08lX", result);
release();
if (d3d11::isDeviceLostError(result))
{
return EGL_CONTEXT_LOST;
}
else
{
return EGL_BAD_ALLOC;
}
}
d3d11::SetDebugName(mOffscreenTexture, "Offscreen back buffer texture");
// EGL_ANGLE_surface_d3d_texture_2d_share_handle requires that we store a share handle for the client
if (useSharedResource)
{
IDXGIResource *offscreenTextureResource = NULL;
result = mOffscreenTexture->QueryInterface(__uuidof(IDXGIResource), (void**)&offscreenTextureResource);
// Fall back to no share handle on failure
if (FAILED(result))
{
ERR("Could not query offscreen texture resource: %08lX", result);
}
else
{
result = offscreenTextureResource->GetSharedHandle(&mShareHandle);
SafeRelease(offscreenTextureResource);
if (FAILED(result))
{
mShareHandle = NULL;
ERR("Could not get offscreen texture shared handle: %08lX", result);
}
}
}
}
// This may return null if the original texture was created without a keyed mutex.
mKeyedMutex = d3d11::DynamicCastComObject<IDXGIKeyedMutex>(mOffscreenTexture);
D3D11_RENDER_TARGET_VIEW_DESC offscreenRTVDesc;
offscreenRTVDesc.Format = backbufferFormatInfo.rtvFormat;
offscreenRTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
offscreenRTVDesc.Texture2D.MipSlice = 0;
HRESULT result = device->CreateRenderTargetView(mOffscreenTexture, &offscreenRTVDesc, &mOffscreenRTView);
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mOffscreenRTView, "Offscreen back buffer render target");