Advertisement Jump to content
Sign in to follow this  
Tank202

Direct3D and Direct2D interoperability through DXGISurface problem

This topic is 1817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone,

 

I'm trying to incorporate my direct2D engine in direct3D app. Microsoft has snippets of how to make direct2D render on DXGISurface but that example is very incomplete and one must always guess what object types Microsoft is using.

 

The result is that when I try to get back buffer from swap chain the program stops working and I get no errors from DXErr functions. Later I noticed that swap chain pointer is NULL so I think the error occurs while creating swap chain or even earlier.

 

If you have an idea of whats happening that my program crashes, please let me know. I'll be very grateful.

 

Link of Microsoft example: http://msdn.microsoft.com/en-us/library/windows/desktop/dd370966(v=vs.85).aspx

 

My code according to example code:

D3D10_FEATURE_LEVEL1 lvls[1] = {
	D3D10_FEATURE_LEVEL_10_0
};
IDXGIAdapter* adapter = 0;
HRESULT hr = D3D10CreateDevice1(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, NULL, D3D10_FEATURE_LEVEL_10_0, D3D10_1_SDK_VERSION, &device);
if(FAILED(hr))
{
	MessageBox(0, DX::DXGetErrorDescription(hr), DX::DXGetErrorString(hr), MB_OK);
}

if(SUCCEEDED(hr))
{
	hr = device->QueryInterface(&device1);
}
if(SUCCEEDED(hr))
{
	hr = device->QueryInterface(&dxgiDevice);
}
if(SUCCEEDED(hr))
{
	hr = dxgiDevice->GetAdapter(&adapter);
}
if(SUCCEEDED(hr))
{
	hr = adapter->GetParent(IID_PPV_ARGS(&dxgiFactory));
	if(FAILED(hr))
	{
		MessageBox(0, DX::DXGetErrorDescription(hr), DX::DXGetErrorString(hr), MB_OK);
	}
}
if(SUCCEEDED(hr))
{
	DXGI_SWAP_CHAIN_DESC swapDesc;
	::ZeroMemory(&swapDesc, sizeof(swapDesc));

	swapDesc.BufferDesc.Width = Window->GetRect().GetSize()->GetX();
	swapDesc.BufferDesc.Height = Window->GetRect().GetSize()->GetY();;
	swapDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	swapDesc.BufferDesc.RefreshRate.Numerator = 60;
	swapDesc.BufferDesc.RefreshRate.Denominator = 1;
	swapDesc.SampleDesc.Count = 1;
	swapDesc.SampleDesc.Quality = 0;
	swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapDesc.BufferCount = 1;
	swapDesc.OutputWindow = Window->GetHWND();
	swapDesc.Windowed = TRUE;

	hr = dxgiFactory->CreateSwapChain(device, &swapDesc, &swapChain);
	if(FAILED(hr))
	{
		MessageBox(0, DX::DXGetErrorDescription(hr), DX::DXGetErrorString(hr), MB_OK);
	}
}

std::cout << swapChain << " " << surface << std::endl;
hr = swapChain->GetBuffer(0, IID_PPV_ARGS(&surface));
if(FAILED(hr))
{
	MessageBox(0, DX::DXGetErrorDescription(hr), DX::DXGetErrorString(hr), MB_OK);
}

hr = D2D1CreateFactory((D2D1_FACTORY_TYPE)sdx.MultiThreaded, &factory);
if(FAILED(hr))
{
	MessageBox(0, DX::DXGetErrorDescription(hr), DX::DXGetErrorString(hr), MB_OK);
}
Eagle2D::recti rc = Window->GetRect();
/*factory->CreateHwndRenderTarget(
	D2D1::RenderTargetProperties(),
	D2D1::HwndRenderTargetProperties(Window->GetHWND(),
	D2D1::SizeU(rc.GetSize()->GetX(), rc.GetSize()->GetY())), &rt);*/
float dpiX, dpiY;
factory->GetDesktopDpi(&dpiX, &dpiY);
D2D1_RENDER_TARGET_PROPERTIES props =
	D2D1::RenderTargetProperties(
	D2D1_RENDER_TARGET_TYPE_HARDWARE,
	D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),
	dpiX, dpiY);
hr = factory->CreateDxgiSurfaceRenderTarget(surface, props, &rt);
if(FAILED(hr))
{
	MessageBox(0, DX::DXGetErrorDescription(hr), DX::DXGetErrorString(hr), MB_OK);
}

rt->CreateSolidColorBrush(Eagle2D::Color::DarkGrey._GetDirect2DColor(), &defBrush);

private members of Direct2D class:

ID2D1Factory* factory;
ID2D1SolidColorBrush* defBrush;
ID2D1RenderTarget* rt;
IWICImagingFactory* imageFactory;

ID3D10Device1* device;
IDXGIFactory1* device1;
IDXGISwapChain* swapChain;
IDXGIDevice* dxgiDevice;
IDXGIFactory* dxgiFactory;
IDXGISurface* surface;
Edited by Tank202

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!