Skip to content

Commit

Permalink
Backends: Using SetTexID() consistently instead of assigning to ->Tex…
Browse files Browse the repository at this point in the history
…ID. May make the later obsolete eventually.
  • Loading branch information
ocornut committed Feb 3, 2021
1 parent 82a9b59 commit 58a0a70
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 24 deletions.
5 changes: 3 additions & 2 deletions backends/imgui_impl_allegro5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ bool ImGui_ImplAllegro5_CreateDeviceObjects()
return false;

// Store our identifier
io.Fonts->TexID = (void*)cloned_img;
io.Fonts->SetTexID((void*)cloned_img);
g_Texture = cloned_img;

// Create an invisible mouse cursor
Expand All @@ -222,8 +222,9 @@ void ImGui_ImplAllegro5_InvalidateDeviceObjects()
{
if (g_Texture)
{
ImGuiIO& io = ImGui::GetIO();
io.Fonts->SetTexID(NULL);
al_destroy_bitmap(g_Texture);
ImGui::GetIO().Fonts->TexID = NULL;
g_Texture = NULL;
}
if (g_MouseCursorInvisible)
Expand Down
4 changes: 2 additions & 2 deletions backends/imgui_impl_dx10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static void ImGui_ImplDX10_CreateFontsTexture()
}

// Store our identifier
io.Fonts->TexID = (ImTextureID)g_pFontTextureView;
io.Fonts->SetTexID((ImTextureID)g_pFontTextureView);

// Create texture sampler
{
Expand Down Expand Up @@ -482,7 +482,7 @@ void ImGui_ImplDX10_InvalidateDeviceObjects()
return;

if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; }
if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->SetTexID(NULL); } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }

Expand Down
4 changes: 2 additions & 2 deletions backends/imgui_impl_dx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static void ImGui_ImplDX11_CreateFontsTexture()
}

// Store our identifier
io.Fonts->TexID = (ImTextureID)g_pFontTextureView;
io.Fonts->SetTexID((ImTextureID)g_pFontTextureView);

// Create texture sampler
{
Expand Down Expand Up @@ -494,7 +494,7 @@ void ImGui_ImplDX11_InvalidateDeviceObjects()
return;

if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; }
if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->SetTexID(NULL); } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }

Expand Down
4 changes: 2 additions & 2 deletions backends/imgui_impl_dx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ static void ImGui_ImplDX12_CreateFontsTexture()

// Store our identifier
static_assert(sizeof(ImTextureID) >= sizeof(g_hFontSrvGpuDescHandle.ptr), "Can't pack descriptor handle into TexID, 32-bit not supported yet.");
io.Fonts->TexID = (ImTextureID)g_hFontSrvGpuDescHandle.ptr;
io.Fonts->SetTexID((ImTextureID)g_hFontSrvGpuDescHandle.ptr);
}

bool ImGui_ImplDX12_CreateDeviceObjects()
Expand Down Expand Up @@ -640,7 +640,7 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
SafeRelease(g_pFontTextureResource);

ImGuiIO& io = ImGui::GetIO();
io.Fonts->TexID = NULL; // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
io.Fonts->SetTexID(NULL); // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.

for (UINT i = 0; i < g_numFramesInFlight; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions backends/imgui_impl_dx9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static bool ImGui_ImplDX9_CreateFontsTexture()
g_FontTexture->UnlockRect(0);

// Store our identifier
io.Fonts->TexID = (ImTextureID)g_FontTexture;
io.Fonts->SetTexID((ImTextureID)g_FontTexture);

return true;
}
Expand All @@ -273,7 +273,7 @@ void ImGui_ImplDX9_InvalidateDeviceObjects()
return;
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
if (g_FontTexture) { g_FontTexture->Release(); g_FontTexture = NULL; ImGui::GetIO().Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
if (g_FontTexture) { g_FontTexture->Release(); g_FontTexture = NULL; ImGui::GetIO().Fonts->SetTexID(NULL); } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
}

void ImGui_ImplDX9_NewFrame()
Expand Down
4 changes: 2 additions & 2 deletions backends/imgui_impl_marmalade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool ImGui_Marmalade_CreateDeviceObjects()
g_FontTexture->Upload();

// Store our identifier
io.Fonts->TexID = (ImTextureID)g_FontTexture;
io.Fonts->SetTexID((ImTextureID)g_FontTexture);

return true;
}
Expand All @@ -209,8 +209,8 @@ void ImGui_Marmalade_InvalidateDeviceObjects()

if (g_FontTexture)
{
ImGui::GetIO().Fonts->SetTexID(0);
delete g_FontTexture;
ImGui::GetIO().Fonts->TexID = 0;
g_FontTexture = NULL;
}
}
Expand Down
4 changes: 2 additions & 2 deletions backends/imgui_impl_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool ImGui_ImplMetal_CreateFontsTexture(id<MTLDevice> device)
[g_sharedMetalContext makeFontTextureWithDevice:device];

ImGuiIO& io = ImGui::GetIO();
io.Fonts->TexID = (__bridge void *)g_sharedMetalContext.fontTexture; // ImTextureID == void*
io.Fonts->SetTexID((__bridge void *)g_sharedMetalContext.fontTexture); // ImTextureID == void*

return (g_sharedMetalContext.fontTexture != nil);
}
Expand All @@ -123,7 +123,7 @@ void ImGui_ImplMetal_DestroyFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
g_sharedMetalContext.fontTexture = nil;
io.Fonts->TexID = nullptr;
io.Fonts->SetTexID(nullptr);
}

bool ImGui_ImplMetal_CreateDeviceObjects(id<MTLDevice> device)
Expand Down
4 changes: 2 additions & 2 deletions backends/imgui_impl_opengl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bool ImGui_ImplOpenGL2_CreateFontsTexture()
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

// Store our identifier
io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontTexture;
io.Fonts->SetTexID((ImTextureID)(intptr_t)g_FontTexture);

// Restore state
glBindTexture(GL_TEXTURE_2D, last_texture);
Expand All @@ -241,7 +241,7 @@ void ImGui_ImplOpenGL2_DestroyFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
glDeleteTextures(1, &g_FontTexture);
io.Fonts->TexID = 0;
io.Fonts->SetTexID(0);
g_FontTexture = 0;
}
}
Expand Down
4 changes: 2 additions & 2 deletions backends/imgui_impl_opengl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture()
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

// Store our identifier
io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontTexture;
io.Fonts->SetTexID((ImTextureID)(intptr_t)g_FontTexture);

// Restore state
glBindTexture(GL_TEXTURE_2D, last_texture);
Expand All @@ -484,7 +484,7 @@ void ImGui_ImplOpenGL3_DestroyFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
glDeleteTextures(1, &g_FontTexture);
io.Fonts->TexID = 0;
io.Fonts->SetTexID(0);
g_FontTexture = 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion backends/imgui_impl_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
}

// Store our identifier
io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontImage;
io.Fonts->SetTexID((ImTextureID)(intptr_t)g_FontImage);

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions backends/imgui_impl_wgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ static void ImGui_ImplWGPU_CreateFontsTexture()

// Store our identifier
static_assert(sizeof(ImTextureID) >= sizeof(g_resources.FontTexture), "Can't pack descriptor handle into TexID, 32-bit not supported yet.");
io.Fonts->TexID = (ImTextureID)g_resources.FontTextureView;
io.Fonts->SetTexID((ImTextureID)g_resources.FontTextureView);
}

static void ImGui_ImplWGPU_CreateUniformBuffer()
Expand Down Expand Up @@ -722,7 +722,7 @@ void ImGui_ImplWGPU_InvalidateDeviceObjects()
SafeRelease(g_resources);

ImGuiIO& io = ImGui::GetIO();
io.Fonts->TexID = NULL; // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
io.Fonts->SetTexID(NULL); // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.

for (unsigned int i = 0; i < g_numFramesInFlight; i++)
SafeRelease(g_pFrameResources[i]);
Expand Down
6 changes: 3 additions & 3 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ CODE
// After we have created the texture, store its pointer/identifier (_in whichever format your engine uses_) in 'io.Fonts->TexID'.
// This will be passed back to your via the renderer. Basically ImTextureID == void*. Read FAQ for details about ImTextureID.
MyTexture* texture = MyEngine::CreateTextureFromMemoryPixels(pixels, width, height, TEXTURE_TYPE_RGBA32)
io.Fonts->TexID = (void*)texture;
io.Fonts->SetTexID((void*)texture);

// Application main loop
while (true)
Expand Down Expand Up @@ -622,9 +622,9 @@ CODE
- 2015/01/11 (1.30) - big font/image API change! now loads TTF file. allow for multiple fonts. no need for a PNG loader.
- 2015/01/11 (1.30) - removed GetDefaultFontData(). uses io.Fonts->GetTextureData*() API to retrieve uncompressed pixels.
- old: const void* png_data; unsigned int png_size; ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); [..Upload texture to GPU..];
- new: unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); [..Upload texture to GPU..]; io.Fonts->TexId = YourTexIdentifier;
- new: unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); [..Upload texture to GPU..]; io.Fonts->SetTexID(YourTexIdentifier);
you now have more flexibility to load multiple TTF fonts and manage the texture buffer for internal needs. It is now recommended that you sample the font texture with bilinear interpolation.
- 2015/01/11 (1.30) - added texture identifier in ImDrawCmd passed to your render function (we can now render images). make sure to set io.Fonts->TexID.
- 2015/01/11 (1.30) - added texture identifier in ImDrawCmd passed to your render function (we can now render images). make sure to call io.Fonts->SetTexID()
- 2015/01/11 (1.30) - removed IO.PixelCenterOffset (unnecessary, can be handled in user projection matrix)
- 2015/01/11 (1.30) - removed ImGui::IsItemFocused() in favor of ImGui::IsItemActive() which handles all widgets
- 2014/12/10 (1.18) - removed SetNewWindowDefaultPos() in favor of new generic API SetNextWindowPos(pos, ImGuiSetCondition_FirstUseEver)
Expand Down

0 comments on commit 58a0a70

Please sign in to comment.