ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.81k stars 298 forks source link

Image only displays default font image #422

Closed ScottKane closed 11 months ago

ScottKane commented 11 months ago

No matter what texture pointer I pass in, the output just shows the default font texture.

image image image

I'm not sure what's going on here but I did notice that I get the font texture even when I send in nint.Zero.

zaafar commented 11 months ago

I'm not sure what's going on here but I did notice that I get the font texture even when I send in nint.Zero.

Font texture is stored at zero index/location so it make sense that u get font texture when you send intptr.zero.

Now about your texture issue, have you printed the value of "(uint) texture.RawTexture" to see if it's zero or something else?

In any case, I feel like the issue is in Component.Texture.Load function, rather than in imgui.net Library code.

ScottKane commented 11 months ago

I was using that specific method for a quick test, it is used to upload the bytes of a texture to a GPU buffer with WebGPU. The handle is actually returning 0 however the actual texture I am trying to get to render (the current swapchain view/framebuffer) with the following:

image image image

I also directly loaded the bytes and took a pointer to them and still I get the font:

image image

zaafar commented 11 months ago

I also directly loaded the bytes and took a pointer to them and still I get the font:

This is a cool example since in this example everything is clear.

so, in this example, where are you taking that byte pointer (bytes) and uploading it to the GPU device via the GPU API (directX, openGL, WebGPU, etc)?

ScottKane commented 11 months ago

The above sample showing NextView does that. You basically get a texture back from the graphics device that you pass into a render pass. It's basically the back buffer. So when I pass it into ImGui.Image it should render the entire previous frame into the ImGui window.

In the second I simplified the code for that example to just directly load the image from embedded resources and pass a pointer directly to ImGui.Image which as far as I'm aware, shouldn't be producing the font image.

zaafar commented 11 months ago

You basically get a texture back from the graphics device that you pass into a render pass.

I see, in that case, I don't know why it would fail from displaying the texture. Maybe go to the discord and sharing your issue over there to see if someone have solved this issue.

ScottKane commented 11 months ago

Ok from looking through some of the sample ImGui renderers, it looks like submitting the texture is deferred until the ImGui render. I think that might be my issue here so I will look into that. It's a bit more complicated to do with WebGPU than how it's done in Veldrid

zaafar commented 11 months ago

In the second I simplified the code for that example to just directly load the image from embedded resources and pass a pointer directly to ImGui.Image which as far as I'm aware, shouldn't be producing the font image.

~i did some test, i think it's an imgui feature where if the caller passes an invalid pointer (invalid from imgui point of view), it just ignore that and defaults to zero (so basically font texture).~ i did some test, i can reproduce this behaviour for any invalid/random pointer value that caller send to image function.

some additional references:

1: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples 2: https://github.com/ocornut/imgui/issues/1840 3: https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_wgpu.cpp

ScottKane commented 11 months ago

Thanks for those resources, the imgui_impl_wgpu is actually super helpful.

ScottKane commented 11 months ago

Ok I got it working with a test texture, my bind group had the font texture bound and never actually passed in the ImGui command buffer texture.