Browse Source

Examples: added SDL3+DirectX11 example. Minor amends + fix both SDL2/SDL3+DirectX11 to allow WARP driver. (#8956, #8957)

ocornut 2 weeks ago
parent
commit
d701ffb478

+ 4 - 1
docs/CHANGELOG.txt

@@ -53,7 +53,10 @@ Other Changes:
   ClearRendererHandlers() on shutdown, so as not to leave function pointers
   ClearRendererHandlers() on shutdown, so as not to leave function pointers
   which may be dangling when using backend in e.g. DLL. (#8945, #2769)
   which may be dangling when using backend in e.g. DLL. (#8945, #2769)
 - Backends: OpenGL3: fixed GL loader to work on Haiku OS which does not support
 - Backends: OpenGL3: fixed GL loader to work on Haiku OS which does not support
-  `RTLD_NOLOAD`. (#8952) [@Xottab-DUTY]
+  `RTLD_NOLOAD`. (#8952) [@Xottab-DUTY, @threedeyes]
+- Examples: SDL2+DirectX11: Try WARP software driver if hardware driver is
+  not available. (#5924, #5562)
+- Examples: SDL3+DirectX11: Added SDL3+DirectX11 example. (#8956, #8957) [@tomaz82]
 
 
 
 
 -----------------------------------------------------------------------
 -----------------------------------------------------------------------

+ 5 - 1
docs/EXAMPLES.md

@@ -149,8 +149,12 @@ SDL2 (Win32, Mac, Linux, etc.) + Vulkan example. <BR>
 This is quite long and tedious, because: Vulkan. <BR>
 This is quite long and tedious, because: Vulkan. <BR>
 For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp.
 For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp.
 
 
+[example_sdl3_directx11/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_directx11/) <BR>
+SDL3 + DirectX11 examples, Windows only. <BR>
+= main.cpp + imgui_impl_sdl3.cpp + imgui_impl_dx11.cpp <BR>
+
 [example_sdl3_metal/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_metal/) <BR>
 [example_sdl3_metal/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_metal/) <BR>
-SDL3 + Metal example (Mac). <BR>
+SDL3 + Metal example, Mac only. <BR>
 = main.cpp + imgui_impl_sdl3.cpp + imgui_impl_metal.mm <BR>
 = main.cpp + imgui_impl_sdl3.cpp + imgui_impl_metal.mm <BR>
 
 
 [example_sdl3_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_opengl3/) <BR>
 [example_sdl3_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl3_opengl3/) <BR>

+ 4 - 1
examples/example_sdl2_directx11/main.cpp

@@ -230,7 +230,10 @@ bool CreateDeviceD3D(HWND hWnd)
     //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
     //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
     D3D_FEATURE_LEVEL featureLevel;
     D3D_FEATURE_LEVEL featureLevel;
     const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
     const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
-    if (D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK)
+    HRESULT res = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext);
+    if (res == DXGI_ERROR_UNSUPPORTED) // Try high-performance WARP software driver if hardware is not available.
+        res = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_WARP, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext);
+    if (res != S_OK)
         return false;
         return false;
 
 
     CreateRenderTarget();
     CreateRenderTarget();

+ 8 - 4
examples/example_sdl3_directx11/main.cpp

@@ -11,7 +11,7 @@
 #include "imgui_impl_sdl3.h"
 #include "imgui_impl_sdl3.h"
 #include "imgui_impl_dx11.h"
 #include "imgui_impl_dx11.h"
 #include <d3d11.h>
 #include <d3d11.h>
-#include <stdio.h>
+#include <stdio.h>              // printf
 #include <SDL3/SDL.h>
 #include <SDL3/SDL.h>
 
 
 // Data
 // Data
@@ -40,7 +40,7 @@ int main(int, char**)
     // Setup window
     // Setup window
     float main_scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
     float main_scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
     SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
     SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
-    SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL3+DirectX11 example", (int)(1280 * main_scale), (int)(720 * main_scale), window_flags);
+    SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL3+DirectX11 example", (int)(1280 * main_scale), (int)(800 * main_scale), window_flags);
     if (window == nullptr)
     if (window == nullptr)
     {
     {
         printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
         printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
@@ -54,7 +54,7 @@ int main(int, char**)
     if (!CreateDeviceD3D(hwnd))
     if (!CreateDeviceD3D(hwnd))
     {
     {
         CleanupDeviceD3D();
         CleanupDeviceD3D();
-        return 1;
+        return -1;
     }
     }
 
 
     SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
     SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
@@ -189,6 +189,7 @@ int main(int, char**)
     }
     }
 
 
     // Cleanup
     // Cleanup
+    // [If using SDL_MAIN_USE_CALLBACKS: all code below would likely be your SDL_AppQuit() function]
     ImGui_ImplDX11_Shutdown();
     ImGui_ImplDX11_Shutdown();
     ImGui_ImplSDL3_Shutdown();
     ImGui_ImplSDL3_Shutdown();
     ImGui::DestroyContext();
     ImGui::DestroyContext();
@@ -224,7 +225,10 @@ bool CreateDeviceD3D(HWND hWnd)
     //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
     //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
     D3D_FEATURE_LEVEL featureLevel;
     D3D_FEATURE_LEVEL featureLevel;
     const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
     const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
-    if (D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK)
+    HRESULT res = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext);
+    if (res == DXGI_ERROR_UNSUPPORTED) // Try high-performance WARP software driver if hardware is not available.
+        res = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_WARP, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext);
+    if (res != S_OK)
         return false;
         return false;
 
 
     CreateRenderTarget();
     CreateRenderTarget();

+ 1 - 1
examples/example_win32_directx10/main.cpp

@@ -1,4 +1,4 @@
-// Dear ImGui: standalone example application for DirectX 10
+// Dear ImGui: standalone example application for Windows API + DirectX 10
 
 
 // Learn about Dear ImGui:
 // Learn about Dear ImGui:
 // - FAQ                  https://dearimgui.com/faq
 // - FAQ                  https://dearimgui.com/faq

+ 1 - 1
examples/example_win32_directx11/main.cpp

@@ -1,4 +1,4 @@
-// Dear ImGui: standalone example application for DirectX 11
+// Dear ImGui: standalone example application for Windows API + DirectX 11
 
 
 // Learn about Dear ImGui:
 // Learn about Dear ImGui:
 // - FAQ                  https://dearimgui.com/faq
 // - FAQ                  https://dearimgui.com/faq

+ 1 - 1
examples/example_win32_directx12/main.cpp

@@ -1,4 +1,4 @@
-// Dear ImGui: standalone example application for DirectX 12
+// Dear ImGui: standalone example application for Windows API + DirectX 12
 
 
 // Learn about Dear ImGui:
 // Learn about Dear ImGui:
 // - FAQ                  https://dearimgui.com/faq
 // - FAQ                  https://dearimgui.com/faq

+ 1 - 1
examples/example_win32_directx9/main.cpp

@@ -1,4 +1,4 @@
-// Dear ImGui: standalone example application for DirectX 9
+// Dear ImGui: standalone example application for Windows API + DirectX 9
 
 
 // Learn about Dear ImGui:
 // Learn about Dear ImGui:
 // - FAQ                  https://dearimgui.com/faq
 // - FAQ                  https://dearimgui.com/faq

+ 1 - 1
examples/example_win32_opengl3/main.cpp

@@ -1,4 +1,4 @@
-// Dear ImGui: standalone example application for Win32 + OpenGL 3
+// Dear ImGui: standalone example application for Windows API + OpenGL
 
 
 // Learn about Dear ImGui:
 // Learn about Dear ImGui:
 // - FAQ                  https://dearimgui.com/faq
 // - FAQ                  https://dearimgui.com/faq

+ 1 - 1
examples/example_win32_vulkan/main.cpp

@@ -1,4 +1,4 @@
-// Dear ImGui: standalone example application for Win32 + Vulkan
+// Dear ImGui: standalone example application for Windows API + Vulkan
 
 
 // Learn about Dear ImGui:
 // Learn about Dear ImGui:
 // - FAQ                  https://dearimgui.com/faq
 // - FAQ                  https://dearimgui.com/faq