Closed voidware closed 5 months ago
For Q1: check out how it's done in the imgui-highdpi-sapp
sample:
If you switch to a different font you need to clean up everything yourself, e.g. call simgui_destroy_image()
, sg_destroy_image()
... you can re-use the sampler object for the next call to simgui_make_image()
though. It might also work to just switch out the texture without invaliding the simgui_image_t handle, e.g. just call sg_uninit_image()
and sg_init_image()
without calling simgui_destroy_image()
and simgui_make_image()
, this "switcheroo" is untested though.
My question is whether i am supposed to separately destroy the image and the sampler as well as the simgui_image or does simgui_destroy_image to that as wll for me?
Nope, simgui_destroy_image()
will not destroy the underlying sg_image
and sg_sampler
it will only 'destroy' the simgui_image_t handle, e.g. see:
Could i have used the same sampler, held globally somewhere?
Yes, you can share the same sampler object between multiple textures, and also use the same texture with different samplers (e.g. have one texture, but two samplers, one with linear and one with nearest filtering, and create two simgui_image_t handles to render the same texture with linear or nearest filtering). This ability to freely combine texture and sampler object was the main reason why 3D APIs other than OpenGL have separate texture and sampler objects.
It also makes a lot of sense to only create a handful of sampler objects with all the sampler state combinations you need, and re-use them for everything throughout the lifetime of your application. Samplers are 'cheap and small' though, so if it makes more sense in your code to have many of them (e.g. one per texture) that's not a problem either.
Thanks a lot for the clarification and answers. Looks like i was doing mostly the right thing, except for clearing the font texture when changing. Setup was ok.
Also, I'll probably now create one shared sampler, so things will be simpler anyhow. Good to know that will work.
Closing the ticket if that's ok.
Yes thanks, everything good. I fixed my leak when destroying the font atlas, everything else ok. Also use of shared samplers works fine.
Version changelog 7 Jan, 24;
I've just updated to this (latest version). Today, i've been battling with the the texture and sampler separation in the shaders.
I have it working, but can you verify/explain a few things for me...
Q1 Font Atlas
I make my own font atlas texture now like this:
So create a sampler. If i don't, the fonts look terrible. Perhaps default sampler is not LINEAR. Anyway, my question is, will sokol know to destroy the image and sampler when i clear the font for another one. when i do this:
Or do i manually need to do it? I think it used to delete the texture.
Q2 Using Textures
I have a custom control that draws images. I Create them like this:
This code is made more complex by the need to check the resource pool, but my question relates to the addition of the sampler above
because:
When i destroy the texture, do i do this;
My question is whether i am supposed to separately destroy the image and the sampler as well as the simgui_image or does
simgui_destroy_image
to that as wll for me?Q3 Samplers in general
In the examples above i created separate samplers for each texture image im using. Could i have used the same sampler, held globally somewhere? or would that cause a problem if two textures renders in the same scene?
Thanks for your help. much appreciated.