|
|
@@ -34,8 +34,8 @@ namespace CamelotEngine
|
|
|
|
|
|
void D3D11RenderSystem::initialize_internal()
|
|
|
{
|
|
|
- HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&mDXGIFactory);
|
|
|
- if(FAILED(hr))
|
|
|
+ HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&mDXGIFactory);
|
|
|
+ if(FAILED(hr))
|
|
|
CM_EXCEPT(RenderingAPIException, "Failed to create Direct3D11 DXGIFactory");
|
|
|
|
|
|
mDriverList = new D3D11DriverList(mDXGIFactory);
|
|
|
@@ -43,33 +43,33 @@ namespace CamelotEngine
|
|
|
|
|
|
IDXGIAdapter* selectedAdapter = mActiveD3DDriver->getDeviceAdapter();
|
|
|
|
|
|
- D3D_FEATURE_LEVEL requestedLevels[] = {
|
|
|
- D3D_FEATURE_LEVEL_11_0,
|
|
|
- D3D_FEATURE_LEVEL_10_1,
|
|
|
- D3D_FEATURE_LEVEL_10_0,
|
|
|
- D3D_FEATURE_LEVEL_9_3,
|
|
|
- D3D_FEATURE_LEVEL_9_2,
|
|
|
- D3D_FEATURE_LEVEL_9_1
|
|
|
+ D3D_FEATURE_LEVEL requestedLevels[] = {
|
|
|
+ D3D_FEATURE_LEVEL_11_0,
|
|
|
+ D3D_FEATURE_LEVEL_10_1,
|
|
|
+ D3D_FEATURE_LEVEL_10_0,
|
|
|
+ D3D_FEATURE_LEVEL_9_3,
|
|
|
+ D3D_FEATURE_LEVEL_9_2,
|
|
|
+ D3D_FEATURE_LEVEL_9_1
|
|
|
};
|
|
|
|
|
|
UINT32 numRequestedLevel = sizeof(requestedLevels) / sizeof(requestedLevels[0]);
|
|
|
|
|
|
ID3D11Device* device;
|
|
|
- hr = D3D11CreateDevice(selectedAdapter, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0,
|
|
|
- requestedLevels, numRequestedLevel, D3D11_SDK_VERSION, &device, &mFeatureLevel, 0);
|
|
|
-
|
|
|
- if(FAILED(hr))
|
|
|
+ hr = D3D11CreateDevice(selectedAdapter, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0,
|
|
|
+ requestedLevels, numRequestedLevel, D3D11_SDK_VERSION, &device, &mFeatureLevel, 0);
|
|
|
+
|
|
|
+ if(FAILED(hr))
|
|
|
CM_EXCEPT(RenderingAPIException, "Failed to create Direct3D11 object. D3D11CreateDeviceN returned this error code: " + toString(hr));
|
|
|
|
|
|
mDevice = new D3D11Device(device);
|
|
|
|
|
|
- LARGE_INTEGER driverVersion;
|
|
|
- if(SUCCEEDED(selectedAdapter->CheckInterfaceSupport(IID_ID3D10Device /* intentionally D3D10, not D3D11 */, &driverVersion)))
|
|
|
- {
|
|
|
- mDriverVersion.major = HIWORD(driverVersion.HighPart);
|
|
|
- mDriverVersion.minor = LOWORD(driverVersion.HighPart);
|
|
|
- mDriverVersion.release = HIWORD(driverVersion.LowPart);
|
|
|
- mDriverVersion.build = LOWORD(driverVersion.LowPart);
|
|
|
+ LARGE_INTEGER driverVersion;
|
|
|
+ if(SUCCEEDED(selectedAdapter->CheckInterfaceSupport(IID_ID3D10Device /* intentionally D3D10, not D3D11 */, &driverVersion)))
|
|
|
+ {
|
|
|
+ mDriverVersion.major = HIWORD(driverVersion.HighPart);
|
|
|
+ mDriverVersion.minor = LOWORD(driverVersion.HighPart);
|
|
|
+ mDriverVersion.release = HIWORD(driverVersion.LowPart);
|
|
|
+ mDriverVersion.build = LOWORD(driverVersion.LowPart);
|
|
|
}
|
|
|
|
|
|
// Create the texture manager for use by others
|
|
|
@@ -230,109 +230,109 @@ namespace CamelotEngine
|
|
|
|
|
|
void D3D11RenderSystem::determineFSAASettings(UINT32 fsaa, const String& fsaaHint, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outFSAASettings)
|
|
|
{
|
|
|
- bool ok = false;
|
|
|
- bool qualityHint = fsaaHint.find("Quality") != String::npos;
|
|
|
- size_t origFSAA = fsaa;
|
|
|
- bool tryCSAA = false;
|
|
|
- // NVIDIA, prefer CSAA if available for 8+
|
|
|
- // it would be tempting to use getCapabilities()->getVendor() == GPU_NVIDIA but
|
|
|
- // if this is the first window, caps will not be initialised yet
|
|
|
-
|
|
|
- if (mActiveD3DDriver->getAdapterIdentifier().VendorId == 0x10DE &&
|
|
|
- fsaa >= 8)
|
|
|
- {
|
|
|
- tryCSAA = true;
|
|
|
- }
|
|
|
-
|
|
|
- while (!ok)
|
|
|
- {
|
|
|
- // Deal with special cases
|
|
|
- if (tryCSAA)
|
|
|
- {
|
|
|
- // see http://developer.nvidia.com/object/coverage-sampled-aa.html
|
|
|
- switch(fsaa)
|
|
|
- {
|
|
|
- case 8:
|
|
|
- if (qualityHint)
|
|
|
- {
|
|
|
- outFSAASettings->Count = 8;
|
|
|
- outFSAASettings->Quality = 8;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- outFSAASettings->Count = 4;
|
|
|
- outFSAASettings->Quality = 8;
|
|
|
- }
|
|
|
- break;
|
|
|
- case 16:
|
|
|
- if (qualityHint)
|
|
|
- {
|
|
|
- outFSAASettings->Count = 8;
|
|
|
- outFSAASettings->Quality = 16;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- outFSAASettings->Count = 4;
|
|
|
- outFSAASettings->Quality = 16;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- else // !CSAA
|
|
|
- {
|
|
|
- outFSAASettings->Count = fsaa == 0 ? 1 : fsaa;
|
|
|
- outFSAASettings->Quality = 0;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- HRESULT hr;
|
|
|
- UINT outQuality;
|
|
|
- hr = mDevice->getD3D11Device()->CheckMultisampleQualityLevels(format, outFSAASettings->Count, &outQuality);
|
|
|
-
|
|
|
- if (SUCCEEDED(hr) && (!tryCSAA || outQuality > outFSAASettings->Quality))
|
|
|
- {
|
|
|
- ok = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // downgrade
|
|
|
- if (tryCSAA && fsaa == 8)
|
|
|
- {
|
|
|
- // for CSAA, we'll try downgrading with quality mode at all samples.
|
|
|
- // then try without quality, then drop CSAA
|
|
|
- if (qualityHint)
|
|
|
- {
|
|
|
- // drop quality first
|
|
|
- qualityHint = false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // drop CSAA entirely
|
|
|
- tryCSAA = false;
|
|
|
- }
|
|
|
- // return to original requested samples
|
|
|
- fsaa = static_cast<UINT32>(origFSAA);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // drop samples
|
|
|
- --fsaa;
|
|
|
-
|
|
|
- if (fsaa == 1)
|
|
|
- {
|
|
|
- // ran out of options, no FSAA
|
|
|
- fsaa = 0;
|
|
|
- ok = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ bool ok = false;
|
|
|
+ bool qualityHint = fsaaHint.find("Quality") != String::npos;
|
|
|
+ size_t origFSAA = fsaa;
|
|
|
+ bool tryCSAA = false;
|
|
|
+ // NVIDIA, prefer CSAA if available for 8+
|
|
|
+ // it would be tempting to use getCapabilities()->getVendor() == GPU_NVIDIA but
|
|
|
+ // if this is the first window, caps will not be initialised yet
|
|
|
+
|
|
|
+ if (mActiveD3DDriver->getAdapterIdentifier().VendorId == 0x10DE &&
|
|
|
+ fsaa >= 8)
|
|
|
+ {
|
|
|
+ tryCSAA = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ while (!ok)
|
|
|
+ {
|
|
|
+ // Deal with special cases
|
|
|
+ if (tryCSAA)
|
|
|
+ {
|
|
|
+ // see http://developer.nvidia.com/object/coverage-sampled-aa.html
|
|
|
+ switch(fsaa)
|
|
|
+ {
|
|
|
+ case 8:
|
|
|
+ if (qualityHint)
|
|
|
+ {
|
|
|
+ outFSAASettings->Count = 8;
|
|
|
+ outFSAASettings->Quality = 8;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ outFSAASettings->Count = 4;
|
|
|
+ outFSAASettings->Quality = 8;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 16:
|
|
|
+ if (qualityHint)
|
|
|
+ {
|
|
|
+ outFSAASettings->Count = 8;
|
|
|
+ outFSAASettings->Quality = 16;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ outFSAASettings->Count = 4;
|
|
|
+ outFSAASettings->Quality = 16;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else // !CSAA
|
|
|
+ {
|
|
|
+ outFSAASettings->Count = fsaa == 0 ? 1 : fsaa;
|
|
|
+ outFSAASettings->Quality = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ HRESULT hr;
|
|
|
+ UINT outQuality;
|
|
|
+ hr = mDevice->getD3D11Device()->CheckMultisampleQualityLevels(format, outFSAASettings->Count, &outQuality);
|
|
|
+
|
|
|
+ if (SUCCEEDED(hr) && (!tryCSAA || outQuality > outFSAASettings->Quality))
|
|
|
+ {
|
|
|
+ ok = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // downgrade
|
|
|
+ if (tryCSAA && fsaa == 8)
|
|
|
+ {
|
|
|
+ // for CSAA, we'll try downgrading with quality mode at all samples.
|
|
|
+ // then try without quality, then drop CSAA
|
|
|
+ if (qualityHint)
|
|
|
+ {
|
|
|
+ // drop quality first
|
|
|
+ qualityHint = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // drop CSAA entirely
|
|
|
+ tryCSAA = false;
|
|
|
+ }
|
|
|
+ // return to original requested samples
|
|
|
+ fsaa = static_cast<UINT32>(origFSAA);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // drop samples
|
|
|
+ --fsaa;
|
|
|
+
|
|
|
+ if (fsaa == 1)
|
|
|
+ {
|
|
|
+ // ran out of options, no FSAA
|
|
|
+ fsaa = 0;
|
|
|
+ ok = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
} // while !ok
|
|
|
}
|
|
|
-
|
|
|
- bool D3D11RenderSystem::checkTextureFilteringSupported(TextureType ttype, PixelFormat format, int usage)
|
|
|
- {
|
|
|
- return true;
|
|
|
+
|
|
|
+ bool D3D11RenderSystem::checkTextureFilteringSupported(TextureType ttype, PixelFormat format, int usage)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
VertexElementType D3D11RenderSystem::getColorVertexElementType() const
|
|
|
@@ -342,21 +342,21 @@ namespace CamelotEngine
|
|
|
|
|
|
void D3D11RenderSystem::convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest, bool forGpuProgram /*= false */)
|
|
|
{
|
|
|
- dest = matrix;
|
|
|
-
|
|
|
- // Convert depth range from [-1,+1] to [0,1]
|
|
|
- dest[2][0] = (dest[2][0] + dest[3][0]) / 2;
|
|
|
- dest[2][1] = (dest[2][1] + dest[3][1]) / 2;
|
|
|
- dest[2][2] = (dest[2][2] + dest[3][2]) / 2;
|
|
|
- dest[2][3] = (dest[2][3] + dest[3][3]) / 2;
|
|
|
-
|
|
|
- if (!forGpuProgram)
|
|
|
- {
|
|
|
- // Convert right-handed to left-handed
|
|
|
- dest[0][2] = -dest[0][2];
|
|
|
- dest[1][2] = -dest[1][2];
|
|
|
- dest[2][2] = -dest[2][2];
|
|
|
- dest[3][2] = -dest[3][2];
|
|
|
+ dest = matrix;
|
|
|
+
|
|
|
+ // Convert depth range from [-1,+1] to [0,1]
|
|
|
+ dest[2][0] = (dest[2][0] + dest[3][0]) / 2;
|
|
|
+ dest[2][1] = (dest[2][1] + dest[3][1]) / 2;
|
|
|
+ dest[2][2] = (dest[2][2] + dest[3][2]) / 2;
|
|
|
+ dest[2][3] = (dest[2][3] + dest[3][3]) / 2;
|
|
|
+
|
|
|
+ if (!forGpuProgram)
|
|
|
+ {
|
|
|
+ // Convert right-handed to left-handed
|
|
|
+ dest[0][2] = -dest[0][2];
|
|
|
+ dest[1][2] = -dest[1][2];
|
|
|
+ dest[2][2] = -dest[2][2];
|
|
|
+ dest[3][2] = -dest[3][2];
|
|
|
}
|
|
|
}
|
|
|
|