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

ImTextureID casting to VkDescriptorSet* is not always FontAtlas set or a valid set #5168

Closed
Pikachuxxxx opened this issue Apr 5, 2022 · 1 comment

Comments

@Pikachuxxxx
Copy link

Pikachuxxxx commented Apr 5, 2022

Version/Branch of Dear ImGui:

Version: 1.83 WIP
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_ImplGlfw_InitForVulkan.cpp + custom renderering engine
Compiler: MSVC
Operating System: Windows 11

My Issue/Question:

I've been trying to make my custom Vulkan backend for ImGui and have been successful in issuing drawcalls myself using ImDrawData, the problem is when I pass the VkDescriptorSet* casted as ImTexturteID for ImGui::Image()

I use the ImTextureID curreTexID = pcmd->GetTexID() to the pointer I passed, but it looks like that it doesn't always point to the Font (I did use ImFontAtlas::SetTexID)or the Image DescriptorSet that I have set, it's not a nullptr or FontAtlas by default which is causing my application to crash, If I manullay verify using If statement for the font Atlas Set by comparing the pointers the descriptorset and ImTextureID it get bound properly, I don't know why it spits out unset values in addition to these, isn't ImTextureID supposed be a nullptr or set to FontAtlas by default which would make using ImTextureID more safe?

for (uint32_t i = 0; i < imDrawData->CmdListsCount; ++i) {
            const ImDrawList* cmd_list = imDrawData->CmdLists[i];
            for (int32_t j = 0; j < cmd_list->CmdBuffer.Size; j++) {
                const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[j];
                ImTextureID curreTexID = pcmd->GetTexID(); // How to know it isn't Image or Font TexID?
                vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_ImGuiPipelineLayout, 0, 1, (VkDescriptorSet*) (curreTexID), 0, NULL);
                VkRect2D scissorRect{};
                scissorRect.offset.x = std::max((int32_t) (pcmd->ClipRect.x), 0);
                scissorRect.offset.y = std::max((int32_t) (pcmd->ClipRect.y), 0);
                scissorRect.extent.width = (uint32_t) (pcmd->ClipRect.z - pcmd->ClipRect.x);
                scissorRect.extent.height = (uint32_t) (pcmd->ClipRect.w - pcmd->ClipRect.y);
                vkCmdSetScissor(commandBuffer, 0, 1, &scissorRect);
                vkCmdDrawIndexed(commandBuffer, pcmd->ElemCount, 1, indexOffset, vertexOffset, 0);
                indexOffset += pcmd->ElemCount;
            }
            vertexOffset += cmd_list->VtxBuffer.Size;
        }

Also I found this and was wondering what's the workaround for this because currently I can't use more than one ImGui::Image with Vulkan (I manually store the current Image Set and check while binding to either use font or this one)

// Since 1.83: returns ImTextureID associated with this draw call. Warning: DO NOT assume this is always same as 'TextureId' (we will change this function for an upcoming feature)
inline ImTextureID GetTexID() const { return TextureId; }
@Pikachuxxxx Pikachuxxxx changed the title ImTextureID casting to VkDescriptorSet* is not always true ImTextureID casting to VkDescriptorSet* is not always FontAtlas set or a valid set Apr 5, 2022
@Pikachuxxxx
Copy link
Author

from #914 and #1641

 #ifndef ImTextureID
typedef void* ImTextureID;          // user data to identify a texture (this is whatever to you want it to be! read the FAQ about ImTextureID in imgui.cpp)
#endif

modifying imconfig.h resolved the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant