Forráskód Böngészése

Examples: DirectX10: Minor tweaks, updated to latest example changes (#424)

ocornut 9 éve
szülő
commit
9596e6f794

+ 4 - 0
examples/README.txt

@@ -41,6 +41,10 @@ opengl3_example/
 directx9_example/
     DirectX9 example, Windows only.
 	
+directx10_example/
+    DirectX10 example, Windows only.
+    This is quite long and tedious, because: DirectX10.
+
 directx11_example/
     DirectX11 example, Windows only.
     This is quite long and tedious, because: DirectX11.

+ 18 - 18
examples/directx10_example/imgui_impl_dx10.cpp

@@ -1,7 +1,7 @@
 // ImGui Win32 + DirectX10 binding
-// You can copy and use unmodified imgui_impl_* files in your project. 
+// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
 // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
-// See main.cpp for an example of using this.
+// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
 // https://github.com/ocornut/imgui
 
 #include "imgui.h"
@@ -44,8 +44,6 @@ struct VERTEX_CONSTANT_BUFFER
 // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
 void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
 {
-    void* vtx_resourceData;
-    void* idx_resourceData;
     // Create and grow vertex/index buffers if needed
     if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount)
     {
@@ -58,7 +56,7 @@ void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
         desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
         desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
         desc.MiscFlags = 0;
-        if (g_pd3dDevice->CreateBuffer(&desc, nullptr, &g_pVB) < 0)
+        if (g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVB) < 0)
             return;
     }
 
@@ -72,14 +70,16 @@ void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
         bufferDesc.ByteWidth = g_IndexBufferSize * sizeof(ImDrawIdx);
         bufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
         bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
-        if (g_pd3dDevice->CreateBuffer(&bufferDesc, nullptr, &g_pIB) < 0)
+        if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pIB) < 0)
             return;
     }
 
-    g_pVB->Map(D3D10_MAP_WRITE_DISCARD, 0, &vtx_resourceData);
-    g_pIB->Map(D3D10_MAP_WRITE_DISCARD, 0, &idx_resourceData);
-    ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resourceData;
-    ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resourceData;
+    // Copy and convert all vertices into a single contiguous buffer
+    ImDrawVert* vtx_dst = NULL;
+    ImDrawIdx* idx_dst = NULL;
+    g_pVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&vtx_dst);
+    g_pIB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&idx_dst);
+
     for (int n = 0; n < draw_data->CmdListsCount; n++)
     {
         const ImDrawList* cmd_list = draw_data->CmdLists[n];
@@ -88,26 +88,26 @@ void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
         vtx_dst += cmd_list->VtxBuffer.size();
         idx_dst += cmd_list->IdxBuffer.size();
     }
-
     g_pVB->Unmap();
     g_pIB->Unmap();
 
     // Setup orthographic projection matrix into our constant buffer
     {
-        void* pmappedResource;
-        g_pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pmappedResource);
+        void* mappedResource;
+        if (g_pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK)
+            return;
 
-        VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)pmappedResource;
+        VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)mappedResource;
         const float L = 0.0f;
         const float R = ImGui::GetIO().DisplaySize.x;
         const float B = ImGui::GetIO().DisplaySize.y;
         const float T = 0.0f;
         const float mvp[4][4] =
         {
-            { 2.0f / (R - L),   0.0f,           0.0f,       0.0f },
-            { 0.0f,         2.0f / (T - B),     0.0f,       0.0f, },
+            { 2.0f/(R-L),   0.0f,           0.0f,       0.0f },
+            { 0.0f,         2.0f/(T-B),     0.0f,       0.0f },
             { 0.0f,         0.0f,           0.5f,       0.0f },
-            { (R + L) / (L - R),  (T + B) / (B - T),    0.5f,       1.0f },
+            { (R+L)/(L-R),  (T+B)/(B-T),    0.5f,       1.0f },
         };
         memcpy(&pConstantBuffer->mvp, mvp, sizeof(mvp));
         g_pVertexConstantBuffer->Unmap();
@@ -346,7 +346,7 @@ bool    ImGui_ImplDX10_CreateDeviceObjects()
             cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
             cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
             cbDesc.MiscFlags = 0;
-            g_pd3dDevice->CreateBuffer(&cbDesc, nullptr, &g_pVertexConstantBuffer);
+            g_pd3dDevice->CreateBuffer(&cbDesc, NULL, &g_pVertexConstantBuffer);
         }
     }
 

+ 2 - 2
examples/directx10_example/imgui_impl_dx10.h

@@ -1,7 +1,7 @@
 // ImGui Win32 + DirectX10 binding
-// You can copy and use unmodified imgui_impl_* files in your project. 
+// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
 // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
-// See main.cpp for an example of using this.
+// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
 // https://github.com/ocornut/imgui
 
 struct ID3D10Device;

+ 2 - 7
examples/directx10_example/main.cpp

@@ -1,4 +1,5 @@
 // ImGui - standalone example application for DirectX 10
+// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
 
 #include <imgui.h>
 #include "imgui_impl_dx10.h"
@@ -147,7 +148,7 @@ int main(int, char**)
     ImGui_ImplDX10_Init(hwnd, g_pd3dDevice);
 
     // Load Fonts
-    // (see extra_fonts/README.txt for more details)
+    // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
     //ImGuiIO& io = ImGui::GetIO();
     //io.Fonts->AddFontDefault();
     //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
@@ -156,12 +157,6 @@ int main(int, char**)
     //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
     //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
 
-    // Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
-    //static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
-    //ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
-    //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
-    //io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
-
     bool show_test_window = true;
     bool show_another_window = false;
     ImVec4 clear_col = ImColor(114, 144, 154);

+ 12 - 12
examples/directx11_example/imgui_impl_dx11.cpp

@@ -103,10 +103,10 @@ void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data)
         const float R = ImGui::GetIO().DisplaySize.x;
         const float B = ImGui::GetIO().DisplaySize.y;
         const float T = 0.0f;
-        const float mvp[4][4] = 
+        const float mvp[4][4] =
         {
-            { 2.0f/(R-L),   0.0f,           0.0f,       0.0f},
-            { 0.0f,         2.0f/(T-B),     0.0f,       0.0f,},
+            { 2.0f/(R-L),   0.0f,           0.0f,       0.0f },
+            { 0.0f,         2.0f/(T-B),     0.0f,       0.0f },
             { 0.0f,         0.0f,           0.5f,       0.0f },
             { (R+L)/(L-R),  (T+B)/(B-T),    0.5f,       1.0f },
         };
@@ -184,26 +184,26 @@ IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND, UINT msg, WPARAM wParam, L
         io.MouseDown[0] = true;
         return true;
     case WM_LBUTTONUP:
-        io.MouseDown[0] = false; 
+        io.MouseDown[0] = false;
         return true;
     case WM_RBUTTONDOWN:
-        io.MouseDown[1] = true; 
+        io.MouseDown[1] = true;
         return true;
     case WM_RBUTTONUP:
-        io.MouseDown[1] = false; 
+        io.MouseDown[1] = false;
         return true;
     case WM_MBUTTONDOWN:
-        io.MouseDown[2] = true; 
+        io.MouseDown[2] = true;
         return true;
     case WM_MBUTTONUP:
-        io.MouseDown[2] = false; 
+        io.MouseDown[2] = false;
         return true;
     case WM_MOUSEWHEEL:
         io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
         return true;
     case WM_MOUSEMOVE:
         io.MousePos.x = (signed short)(lParam);
-        io.MousePos.y = (signed short)(lParam >> 16); 
+        io.MousePos.y = (signed short)(lParam >> 16);
         return true;
     case WM_KEYDOWN:
         if (wParam < 256)
@@ -348,7 +348,7 @@ bool    ImGui_ImplDX11_CreateDeviceObjects()
 
     // Create the pixel shader
     {
-        static const char* pixelShader = 
+        static const char* pixelShader =
             "struct PS_INPUT\
             {\
             float4 pos : SV_POSITION;\
@@ -429,7 +429,7 @@ bool    ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContex
     g_pd3dDevice = device;
     g_pd3dDeviceContext = device_context;
 
-    if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond)) 
+    if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond))
         return false;
     if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time))
         return false;
@@ -484,7 +484,7 @@ void ImGui_ImplDX11_NewFrame()
 
     // Setup time step
     INT64 current_time;
-    QueryPerformanceCounter((LARGE_INTEGER *)&current_time); 
+    QueryPerformanceCounter((LARGE_INTEGER *)&current_time);
     io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond;
     g_Time = current_time;