Update examples to use DXGI.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 5 Dec 2012 19:42:07 +0000 (19:42 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 5 Dec 2012 19:42:07 +0000 (19:42 +0000)
That's more common and challenging for apitrace.

apps/d3d10/CMakeLists.txt
apps/d3d10/tri.cpp
apps/d3d10/tri.ref.txt
apps/d3d10_1/CMakeLists.txt
apps/d3d10_1/tri.cpp
apps/d3d10_1/tri.ref.txt
apps/d3d11_1/tri.cpp
cmake/FindDirectX.cmake

index 75d110b717681da5cdfaa10303f9d93fe9ed9d88..226cd49c6897f4efbb65728e87b88afcdb73c1dd 100644 (file)
@@ -4,6 +4,7 @@ include_directories (
 )
 
 link_libraries (
+    ${DirectX_DXGI_LIBRARY}
     ${DirectX_D3D10_LIBRARY}
 )
 
index 18213427e5a8df6154cd7fd538e482350aaeddb0..1029be91906f95fe618c5735b53dde3f4f020cef 100644 (file)
@@ -38,6 +38,8 @@
 #include "tri_ps_4_0.h"
 
 
+static IDXGIFactory *g_pFactory = NULL;
+static IDXGIAdapter *g_pAdapter = NULL;
 static IDXGISwapChain* g_pSwapChain = NULL;
 static ID3D10Device * g_pDevice = NULL;
 
@@ -95,6 +97,26 @@ main(int argc, char *argv[])
         Flags |= D3D10_CREATE_DEVICE_DEBUG;
     }
 
+    hr = CreateDXGIFactory(IID_IDXGIFactory, (void**)(&g_pFactory) );
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    hr = g_pFactory->EnumAdapters(0, &g_pAdapter);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    hr = D3D10CreateDevice(g_pAdapter,
+                           D3D10_DRIVER_TYPE_HARDWARE,
+                           NULL,
+                           Flags,
+                           D3D10_SDK_VERSION,
+                           &g_pDevice);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
     DXGI_SWAP_CHAIN_DESC SwapChainDesc;
     ZeroMemory(&SwapChainDesc, sizeof SwapChainDesc);
     SwapChainDesc.BufferDesc.Width = WindowWidth;
@@ -109,14 +131,7 @@ main(int argc, char *argv[])
     SwapChainDesc.OutputWindow = hWnd;
     SwapChainDesc.Windowed = true;
 
-    hr = D3D10CreateDeviceAndSwapChain(NULL,
-                                       D3D10_DRIVER_TYPE_HARDWARE,
-                                       NULL,
-                                       Flags,
-                                       D3D10_SDK_VERSION,
-                                       &SwapChainDesc,
-                                       &g_pSwapChain,
-                                       &g_pDevice);
+    hr = g_pFactory->CreateSwapChain(g_pDevice, &SwapChainDesc, &g_pSwapChain);
     if (FAILED(hr)) {
         return 1;
     }
index e5d73561981692efe884add78928187d974714ff..66ab01931b1b73a88e53b62f8af5d4539017fdaa 100644 (file)
@@ -1,4 +1,7 @@
-D3D10CreateDeviceAndSwapChain(pAdapter = NULL, DriverType = D3D10_DRIVER_TYPE_HARDWARE, Software = NULL, Flags = <>, SDKVersion = 29, pSwapChainDesc = &{BufferDesc = {Width = 250, Height = 250, RefreshRate = {Numerator = 60, Denominator = 1}, Format = DXGI_FORMAT_R8G8B8A8_UNORM, ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, Scaling = DXGI_MODE_SCALING_UNSPECIFIED}, SampleDesc = {Count = 1, Quality = 0}, BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, BufferCount = 2, OutputWindow = <hWnd>, Windowed = TRUE, SwapEffect = DXGI_SWAP_EFFECT_DISCARD, Flags = 0x0}, ppSwapChain = &<pSwapChain>, ppDevice = &<pDevice>) = S_OK
+CreateDXGIFactory(riid = {Data1 = 2071029484, Data2 = 8647, Data3 = 17582, Data4 = {178, 26, 201, 174, 50, 26, 227, 105}}, ppFactory = &<pFactory>) = S_OK
+IDXGIFactory::EnumAdapters(this = <pFactory>, Adapter = 0, ppAdapter = &<pAdapter>) = S_OK
+D3D10CreateDevice(pAdapter = <pAdapter>, DriverType = D3D10_DRIVER_TYPE_HARDWARE, Software = NULL, Flags = <>, SDKVersion = 29, ppDevice = &<pDevice>) = S_OK
+IDXGIFactory::CreateSwapChain(this = <pFactory>, pDevice = <pDevice>, pDesc = &{BufferDesc = {Width = 250, Height = 250, RefreshRate = {Numerator = 60, Denominator = 1}, Format = DXGI_FORMAT_R8G8B8A8_UNORM, ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, Scaling = DXGI_MODE_SCALING_UNSPECIFIED}, SampleDesc = {Count = 1, Quality = 0}, BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, BufferCount = 2, OutputWindow = <hWnd>, Windowed = TRUE, SwapEffect = DXGI_SWAP_EFFECT_DISCARD, Flags = 0x0}, ppSwapChain = &<pSwapChain>) = S_OK
 IDXGISwapChain::GetBuffer(this = <pSwapChain>, Buffer = 0, riid = {Data1 = 2608745476, Data2 = 13356, Data3 = 16646, Data4 = {161, 159, 79, 39, 4, 246, 137, 240}}, ppSurface = &<pSurface>) = S_OK
 ID3D10Device::CreateRenderTargetView(this = <pDevice>, pResource = <pSurface>, pDesc = &{Format = DXGI_FORMAT_R8G8B8A8_UNORM, ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D, Texture2D = {MipSlice = 0}}, ppRTView = &<pRenderTargetView>) = S_OK
 ID3D10Texture2D::Release(this = <pSurface>) = 0
index 83455bc0f0b0295cead0bccb1ffe6212c9be980e..ccd3dbc5c8f46a75988d1a46105454b6682660a8 100644 (file)
@@ -4,6 +4,7 @@ include_directories (
 )
 
 link_libraries (
+    ${DirectX_DXGI_LIBRARY}
     ${DirectX_D3D10_1_LIBRARY}
 )
 
index 4aed3508ad693edc8cee319efc3a28a13b8fefc3..b9ed7d52cefa50d18000cb1f147502426ec08156 100644 (file)
 #include "tri_ps_4_0.h"
 
 
+static IDXGIFactory1 *g_pFactory = NULL;
+static IDXGIAdapter *g_pAdapter = NULL;
 static IDXGISwapChain* g_pSwapChain = NULL;
 static ID3D10Device1 * g_pDevice = NULL;
 
 
-int main(int argc, char *argv[]){
+int
+main(int argc, char *argv[])
+{
     HRESULT hr;
 
     HINSTANCE hInstance = GetModuleHandle(NULL);
@@ -93,6 +97,27 @@ int main(int argc, char *argv[]){
         Flags |= D3D10_CREATE_DEVICE_DEBUG;
     }
 
+    hr = CreateDXGIFactory1(IID_IDXGIFactory1, (void**)(&g_pFactory) );
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    hr = g_pFactory->EnumAdapters(0, &g_pAdapter);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    hr = D3D10CreateDevice1(g_pAdapter,
+                            D3D10_DRIVER_TYPE_HARDWARE,
+                            NULL,
+                            Flags,
+                            D3D10_FEATURE_LEVEL_10_0,
+                            D3D10_1_SDK_VERSION,
+                            &g_pDevice);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
     DXGI_SWAP_CHAIN_DESC SwapChainDesc;
     ZeroMemory(&SwapChainDesc, sizeof SwapChainDesc);
     SwapChainDesc.BufferDesc.Width = WindowWidth;
@@ -107,15 +132,7 @@ int main(int argc, char *argv[]){
     SwapChainDesc.OutputWindow = hWnd;
     SwapChainDesc.Windowed = true;
 
-    hr = D3D10CreateDeviceAndSwapChain1(NULL,
-                                        D3D10_DRIVER_TYPE_HARDWARE,
-                                        NULL,
-                                        Flags,
-                                        D3D10_FEATURE_LEVEL_10_0,
-                                        D3D10_1_SDK_VERSION,
-                                        &SwapChainDesc,
-                                        &g_pSwapChain,
-                                        &g_pDevice);
+    hr = g_pFactory->CreateSwapChain(g_pDevice, &SwapChainDesc, &g_pSwapChain);
     if (FAILED(hr)) {
         return 1;
     }
index 35fcd88b745c09ccd7aee4ac93acc86f552ecaad..aeae9bd542310c4e460c18e306279df419afd609 100644 (file)
@@ -1,4 +1,7 @@
-D3D10CreateDeviceAndSwapChain1(pAdapter = NULL, DriverType = D3D10_DRIVER_TYPE_HARDWARE, Software = NULL, Flags = <>, HardwareLevel = D3D10_FEATURE_LEVEL_10_0, SDKVersion = 32, pSwapChainDesc = &{BufferDesc = {Width = 250, Height = 250, RefreshRate = {Numerator = 60, Denominator = 1}, Format = DXGI_FORMAT_R8G8B8A8_UNORM, ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, Scaling = DXGI_MODE_SCALING_UNSPECIFIED}, SampleDesc = {Count = 1, Quality = 0}, BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, BufferCount = 2, OutputWindow = <hWnd>, Windowed = TRUE, SwapEffect = DXGI_SWAP_EFFECT_DISCARD, Flags = 0x0}, ppSwapChain = &<pSwapChain>, ppDevice = &<pDevice>) = S_OK
+CreateDXGIFactory1(riid = {Data1 = 1997188728, Data2 = 62063, Data3 = 19898, Data4 = {168, 41, 37, 60, 131, 209, 179, 135}}, ppFactory = &<pFactory>) = S_OK
+IDXGIFactory1::EnumAdapters(this = <pFactory>, Adapter = 0, ppAdapter = &<pAdapter>) = S_OK
+D3D10CreateDevice1(pAdapter = <pAdapter>, DriverType = D3D10_DRIVER_TYPE_HARDWARE, Software = NULL, Flags = <>, HardwareLevel = D3D10_FEATURE_LEVEL_10_0, SDKVersion = 32, ppDevice = &<pDevice>) = S_OK
+IDXGIFactory1::CreateSwapChain(this = <pFactory>, pDevice = <pDevice>, pDesc = &{BufferDesc = {Width = 250, Height = 250, RefreshRate = {Numerator = 60, Denominator = 1}, Format = DXGI_FORMAT_R8G8B8A8_UNORM, ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, Scaling = DXGI_MODE_SCALING_UNSPECIFIED}, SampleDesc = {Count = 1, Quality = 0}, BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, BufferCount = 2, OutputWindow = <hWnd>, Windowed = TRUE, SwapEffect = DXGI_SWAP_EFFECT_DISCARD, Flags = 0x0}, ppSwapChain = &<pSwapChain>) = S_OK
 IDXGISwapChain::GetBuffer(this = <pSwapChain>, Buffer = 0, riid = {Data1 = 2608745476, Data2 = 13356, Data3 = 16646, Data4 = {161, 159, 79, 39, 4, 246, 137, 240}}, ppSurface = &<pSurface>) = S_OK
 ID3D10Device1::CreateRenderTargetView(this = <pDevice>, pResource = <pSurface>, pDesc = &{Format = DXGI_FORMAT_R8G8B8A8_UNORM, ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D, Texture2D = {MipSlice = 0}}, ppRTView = &<pRenderTargetView>) = S_OK
 ID3D10Texture2D::Release(this = <pSurface>) = 0
index f86ab7c2b46168902c79d2dd763c8357cdd23c67..ff297ed69e78d4c912817b741009a23fdbfc4dee 100644 (file)
@@ -149,7 +149,12 @@ int main(int argc, char *argv[]){
     if (FAILED(hr)) {
         return 1;
     }
-    hr = g_pDevice1->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView);
+    D3D11_RENDER_TARGET_VIEW_DESC RenderTargetViewDesc;
+    ZeroMemory(&RenderTargetViewDesc, sizeof RenderTargetViewDesc);
+    RenderTargetViewDesc.Format = SwapChainDesc.BufferDesc.Format;
+    RenderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
+    RenderTargetViewDesc.Texture2D.MipSlice = 0;
+    hr = g_pDevice1->CreateRenderTargetView(pBackBuffer, &RenderTargetViewDesc, &pRenderTargetView);
     if (FAILED(hr)) {
         return 1;
     }
index cbbe4f134506e6f4c2d7a3e52b1c1f8a8f37c77a..6eb684e3182f2fe12c3f2282ef04aa41fab32734 100644 (file)
@@ -138,6 +138,11 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
        endif ()
 
 
+       find_library (DirectX_DXGI_LIBRARY dxgi
+               PATHS ${DirectX_LIB_SEARCH_PATH}
+               DOC "The directory where dxgi resides")
+
+
        find_path (DirectX_D3D10_INCLUDE_DIR d3d10.h
                PATHS ${DirectX_INC_SEARCH_PATH}
                DOC "The directory where d3d10.h resides")