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

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

Open
enesaltinkaya opened this issue May 27, 2023 · 10 comments
Open

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

enesaltinkaya opened this issue May 27, 2023 · 10 comments
Labels
api Connected with imgui-java API bug Something isn't working

Comments

@enesaltinkaya
Copy link

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

@enesaltinkaya enesaltinkaya added the bug Something isn't working label May 27, 2023
@SpaiR SpaiR added the api Connected with imgui-java API label May 31, 2023
@Standinalone
Copy link

Standinalone commented Feb 15, 2024

@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
Copy link
Author

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
Copy link
Author

enesaltinkaya commented Feb 15, 2024

@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
Copy link

Standinalone commented Feb 15, 2024

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
Copy link

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
Copy link
Author

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
Copy link
Author

enesaltinkaya commented Feb 15, 2024

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
Copy link

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

@enesaltinkaya
Copy link
Author

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

@Standinalone
Copy link

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

ok, I sent a request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Connected with imgui-java API bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants