Skip to content

Commit

Permalink
Backends: DX9: programmable rendering pipeline: 5.automatically enable
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuanlan authored and Kuanlan committed Mar 4, 2021
1 parent d0566a8 commit b8693b5
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions backends/imgui_impl_dx9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ static IDirect3DVertexDeclaration9* g_pInputLayout = NULL;
static IDirect3DVertexShader9* g_pVertexShader = NULL;
static IDirect3DPixelShader9* g_pPixelShader = NULL;

// Backend names (in order to identify and debug easier)
static const char* IMGUI_IMPL_D3D9_BACKEND_NAME = "imgui_impl_dx9";
static const char* IMGUI_IMPL_D3D9_BACKEND_NAME_FIXED = "imgui_impl_dx9 (fixed)";
static const char* IMGUI_IMPL_D3D9_BACKEND_NAME_SHADER = "imgui_impl_dx9 (shader)";

// Setup render state
static void ImGui_ImplDX9_SetupRenderState(ImDrawData* draw_data)
{
Expand Down Expand Up @@ -424,6 +429,16 @@ static bool ImGui_ImplDX9_CreateBuffers(ImDrawData* draw_data)

return true;
}
static bool ImGui_ImplDX9_CreateShaderPipeline()
{
if (D3D_OK != g_pd3dDevice->CreateVertexDeclaration(g_InputLayoutData, &g_pInputLayout))
return false;
if (D3D_OK != g_pd3dDevice->CreateVertexShader((DWORD*)g_VertexShaderData, &g_pVertexShader))
return false;
if (D3D_OK != g_pd3dDevice->CreatePixelShader((DWORD*)g_PixelShaderData, &g_pPixelShader))
return false;
return true;
}
static bool ImGui_ImplDX9_CreateFontsTexture()
{
// Build texture atlas
Expand Down Expand Up @@ -464,16 +479,6 @@ static bool ImGui_ImplDX9_CreateFontsTexture()

return true;
}
static bool ImGui_ImplDX9_CreateShaderPipeline()
{
if (D3D_OK != g_pd3dDevice->CreateVertexDeclaration(g_InputLayoutData, &g_pInputLayout))
return false;
if (D3D_OK != g_pd3dDevice->CreateVertexShader((DWORD*)g_VertexShaderData, &g_pVertexShader))
return false;
if (D3D_OK != g_pd3dDevice->CreatePixelShader((DWORD*)g_PixelShaderData, &g_pPixelShader))
return false;
return true;
}

// Render function.
void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
Expand Down Expand Up @@ -552,7 +557,7 @@ bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)

// Setup backend capabilities flags
ImGuiIO& io = ImGui::GetIO();
io.BackendRendererName = "imgui_impl_dx9";
io.BackendRendererName = IMGUI_IMPL_D3D9_BACKEND_NAME;
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.

return true;
Expand All @@ -570,7 +575,12 @@ bool ImGui_ImplDX9_CreateDeviceObjects()
return false;
if (!ImGui_ImplDX9_CreateFontsTexture())
return false;
ImGui_ImplDX9_CreateShaderPipeline(); // Shader pipeline is optional
g_IsShaderPipeline = ImGui_ImplDX9_CreateShaderPipeline(); // Shader pipeline is optional
// g_IsShaderPipeline = false; // still want to disable it
if (!g_IsShaderPipeline)
ImGui::GetIO().BackendRendererName = IMGUI_IMPL_D3D9_BACKEND_NAME_FIXED;
else
ImGui::GetIO().BackendRendererName = IMGUI_IMPL_D3D9_BACKEND_NAME_SHADER;
return true;
}

Expand Down

0 comments on commit b8693b5

Please sign in to comment.