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

GameView Vulkan Impl #1371

Closed
LeonBrands opened this issue Oct 16, 2017 · 4 comments
Closed

GameView Vulkan Impl #1371

LeonBrands opened this issue Oct 16, 2017 · 4 comments
Labels

Comments

@LeonBrands
Copy link

Hi,

I am trying to implement Vulkan as an editor for our engine. I am currently trying to create a gameview, but am quite confused as how I should implement this. What is the best approach to render a scene and display it onto an imgui widget? Could someone provide an example please?

@ocornut
Copy link
Owner

ocornut commented Oct 16, 2017

Typically you'd render your game scene in an off-screen texture, and then use that texture in your render.
ImGui uses the opaque ImTextureID type (which is basically a void*) as a mechanism to allow you pass your texture identifiers to functions like ImGui::Image() or ImDrawList::AddImage(). Basically the system will just emit draw batches (vertices + texture id) that your rendering can use.

I suggest to look at the other examples (OpenGL/DX) to understand how ImTextureId are generally handled.

The current renderer in the Vulkan always uses the default font texture for rendering. There is a PR here that fixes it to be on par with the other renderer:
#914

Which is an attempt to use ImTextureId to store a VkDescriptorSet, which appears to be the closest thing to describe a texture in Vulkan world. However if you are building your own engine own Vulkan you may have your own type MyTexture* and then you can store.

The reason the PR above is unmerged is that VkDescriptorSet is always 64-bit and void* on 32-bit architecture is, well, 32-bits so it can't be stored with this mechanism. We need to make a modification to the size of ImTextureId to always be 64-bits. If you are targetting 64-bits (which probably you are) then it's a non-problem and you can merge this code.

@ocornut
Copy link
Owner

ocornut commented Oct 16, 2017

Another approach which is a little more optimal but trickier and less flexible, is to use ImDrawList::AddCallback() and use that callback render your game scene directly in-between the imgui draw calls, if you setup all your render state, including viewport/scissor then restore them.
The vast majority of people just render to an offscreen texture because it is simpler.

Also see:
#984
#1261
#1004

@ghost
Copy link

ghost commented Nov 4, 2017

Thanks for this thread! I'm learning both ImGui and OpenGL at the same time and these comments pulled me out of the rabbit hole I got sucked down trying to figure out why the mesh I was rendering was not showing in the second GLFWwindow I had created.

@ocornut
Copy link
Owner

ocornut commented Nov 19, 2017

Closing this thread as answered, even through in the case of Vulkan displaying texture requires the patch of #914 which doesn't work in 32-bits.

@ocornut ocornut closed this as completed Nov 19, 2017
@ocornut ocornut added the vulkan label Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants