Skip to content

Commit

Permalink
Cleaner errors upon invalid videocard
Browse files Browse the repository at this point in the history
  • Loading branch information
MadrMan committed Jun 25, 2012
1 parent f4b2bd3 commit b0610e4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 51 additions & 1 deletion gpuraytrace/Adapters/DeviceDirect3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,45 @@ DeviceDirect3D::~DeviceDirect3D()
if(swapBackBuffer) swapBackBuffer->Release();
}

bool DeviceDirect3D::getAdapterHandle(std::vector<IDXGIAdapter1*>* adapters)
{
HRESULT hr;

//Create DXGI factory
IDXGIFactory1* dxgiFactory;
hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&dxgiFactory));
if(FAILED(hr))
{
LOGERROR(hr, "CreateDXGIFactory1");
return false;
}

//Get all the adapters
UINT i = 0;
IDXGIAdapter1* pAdapter = nullptr;
while(dxgiFactory->EnumAdapters1(i, &pAdapter) != DXGI_ERROR_NOT_FOUND)
{
adapters->push_back(pAdapter);

DXGI_ADAPTER_DESC1 desc;
pAdapter->GetDesc1(&desc);
std::wstring descriptionw(desc.Description);
std::string description(descriptionw.begin(), descriptionw.end());
Logger() << "Adapter found: " << description;

++i;
}
dxgiFactory->Release();

if(adapters->empty())
{
LOGFUNCERROR("Your videocard does not appear to support DirectX 10 or later");
return false;
}

return true;
}

bool DeviceDirect3D::create()
{
HMODULE libD3D11 = LoadLibrary("d3d11.dll");
Expand All @@ -55,6 +94,12 @@ bool DeviceDirect3D::create()
FreeLibrary(libD3D11);
FreeLibrary(libCompiler43);

std::vector<IDXGIAdapter1*> adapters;
if(!getAdapterHandle(&adapters))
{
return false;
}

UINT createDeviceFlags = 0;
#if defined(_DEBUG)
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
Expand Down Expand Up @@ -85,7 +130,12 @@ bool DeviceDirect3D::create()

if(result != S_OK)
{
LOGERROR(result, "D3D11CreateDeviceAndSwapChain");
if(result == DXGI_ERROR_UNSUPPORTED)
{
LOGFUNCERROR("Your videocard does not appear to support DirectX 11");
} else {
LOGERROR(result, "D3D11CreateDeviceAndSwapChain");
}
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions gpuraytrace/Adapters/DeviceDirect3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class DeviceDirect3D : public IDevice
{ return uavSwapBuffer; }

private:
bool getAdapterHandle(std::vector<IDXGIAdapter1*>* adapters);

ID3D11Device* device;
ID3D11DeviceContext* context;
IDXGISwapChain* swapChain;
Expand Down

0 comments on commit b0610e4

Please sign in to comment.