SpaiR / imgui-java

JNI based binding for Dear ImGui
MIT License
587 stars 90 forks source link

ImGui.image() should expect long instead of int for textureId. #185

Closed enesaltinkaya closed 1 month ago

enesaltinkaya commented 1 year ago

Version

1.86.10

What happened?

While using with Vulkan, ImGui::Image expects a VkDescriptorSet as it's first parameter, which is a pointer, which is 64bits.

Our ImGui.image() expects an int which is 32bits. So it is not possible to render an image if using Vulkan at the moment.

If I'm mistaken and there is a way to render images while using Vulkan please let me know. Thanks.

Reproduction

Simply casting wont work as you can see.

image

Relevant log output

No response

Standinalone commented 7 months ago

@enesaltinkaya, did you find a solution? Maybe you have a code snippet to use openGl here to display images while it's still an issue?

enesaltinkaya commented 7 months ago

I downloaded the repo, changed these to accept long;

    public static native void image(long textureID, float sizeX, float sizeY); /*
        ImGui::Image((ImTextureID)(intptr_t)textureID, ImVec2(sizeX, sizeY));
    */

    public static native void image(long textureID, float sizeX, float sizeY, float uv0X, float uv0Y); /*
        ImGui::Image((ImTextureID)(intptr_t)textureID, ImVec2(sizeX, sizeY), ImVec2(uv0X, uv0Y));
    */

    public static native void image(long textureID, float sizeX, float sizeY, float uv0X, float uv0Y, float uv1X, float uv1Y); /*
        ImGui::Image((ImTextureID)(intptr_t)textureID, ImVec2(sizeX, sizeY), ImVec2(uv0X, uv0Y), ImVec2(uv1X, uv1Y));
    */

    public static native void image(long textureID, float sizeX, float sizeY, float uv0X, float uv0Y, float uv1X, float uv1Y, float tintColorR, float tintColorG, float tintColorB, float tintColorA); /*
        ImGui::Image((ImTextureID)(intptr_t)textureID, ImVec2(sizeX, sizeY), ImVec2(uv0X, uv0Y), ImVec2(uv1X, uv1Y), ImVec4(tintColorR, tintColorG, tintColorB, tintColorA));
    */

    public static native void image(long textureID, float sizeX, float sizeY, float uv0X, float uv0Y, float uv1X, float uv1Y, float tintColorR, float tintColorG, float tintColorB, float tintColorA, float borderR, float borderG, float borderB, float borderA); /*
        ImGui::Image((ImTextureID)(intptr_t)textureID, ImVec2(sizeX, sizeY), ImVec2(uv0X, uv0Y), ImVec2(uv1X, uv1Y), ImVec4(tintColorR, tintColorG, tintColorB, tintColorA), ImVec4(borderR, borderG, borderB, borderA));
    */

Then i searched for corresponding calls (ImGui::Image((ImTextureID)... calls) in .cpp or .c files in the project, changed those too to accept 64bit ints. Compiled these two, imgui-java64.dll, libimgui-java64.so. And it worked.

But then i dropped java altogether and went back to C. :)

I have those dll and so files, and java files if you want them.

enesaltinkaya commented 7 months ago

@enesaltinkaya, did you find a solution? Maybe you have a code snippet to use openGl here to display images while it's still an issue?

Displaying OpenGL textures using ImGui.image(...) should work without any issues. This issue is about displaying them using Vulkan.

Standinalone commented 7 months ago

I have those dll and so files, and java files if you want them.

Thank you! I will try to follow your steps but if it doesn't work it'd be usefull to have working files. Why C? :) Have you encountered more problems with everything ported to Java?

Standinalone commented 7 months ago

This issue is about displaying them using Vulkan.

Yeah, of course. Just thought it was possible to use openGl along with Vulkan specifically to render image in ImGui. Well, maybe it sounds silly, sorry, this is too new for me.

enesaltinkaya commented 7 months ago

Yeah, of course. Just thought it was possible to use openGl along with Vulkan specifically to render image in ImGui. Well, maybe it sounds silly, sorry, this is too new for me.

Original C++ function ImGui::Image(..) wants an 32bit integer type if we are using OpenGL. Because glGenTextures outputs an unsigned int.

But the same functions wants an 64bit integer type if we are using Vulkan. Address of the VkDescriptorSet.

But we can't pass 64bit integer (long) in this repo, so we can't display images using Vulkan.

enesaltinkaya commented 7 months ago

Thank you! I will try to follow your steps but if it doesn't work it'd be usefull to have working files. Why C? :) Have you encountered more problems with everything ported to Java?

My vulkan-image-display-working set of files :) https://drive.google.com/file/d/1-ispK2iK3NHiacRQvPVmkahNcufqFrZN/view?usp=sharing

As for C vs Java; Mainly the project output/release size.

Java project, with all those lwjgl jar files, after proguard, jlink, jpackage, release directory is 125mb for linux. It is big because it contains a subset of jdk, jlink does that. And dynamic libraries that are in lwjgl jar files (.so and .dll files).

Same project using C, output is 6.5mb :) Using 13 libraries all statically linked. When we use statically linked libraries in c or c++ only used portion of libraries included in the final executable. But if we use dynamic libraries the whole .so or .dll files needs to reside beside the executable.

I also kind of like manual memory management, no more garbage collection for me :) C apps start very fast. And even tho java has JIT compiler that makes the application run as fast as native applications I could not see the same performance in my project.

Although this is a simple scene, i tested with busy scenes as well. These stats were always slower on Java. image

Standinalone commented 7 months ago

@enesaltinkaya, thank you. I've been trying to render an image in ImGui with Vulkan for 3 days btw

enesaltinkaya commented 7 months ago

If it still wont work you can add me on Discord, username is gnu4493.

Standinalone commented 7 months ago

If it still wont work you can add me on Discord, username is gnu4493.

ok, I sent a request