Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backends: DX9: programmable rendering pipeline version implement (Dear @Demonese) #3844

Closed
wants to merge 6 commits into from
Prev Previous commit
Next Next commit
Backends: DX9: programmable rendering pipeline: 5.automatically enable
  • Loading branch information
Kuanlan authored and Kuanlan committed Mar 4, 2021
commit b8693b51b05f915b61078480e3c1486328f1e7b5
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