Sokol: Imgui integration issues with decoupled systems

Created on 9 Mar 2019  路  6Comments  路  Source: floooh/sokol

I'm trying to integrate sokol imgui debugger.
My design is very plugin based and decoupled. For example, imgui and all of it's drawing components are provided as a plugin. the core engine presents the sokol api (a structure like hooks) to the plugins.
The problem is sokol_gfx_imgui is very tightly coupled with sokol_gfx implementation (which I don't think it should be) and wants to access it's internal data. I can do workarounds for other stuff and install hooks and hack sg_install_trace_hooks inside sokol_gfx_imgui.h to point to my host app sokol_gfx.
But still remains all the _sg. state access inside the file.

Now I have to change all _sg references in the header to a _sg_state_t pointer that I pass to the plugin. which is not very elegant.

I suggest sokol_gfx_imgui moves to a more decoupled state where optionally it can receive a custom hook instead of calling sg_install_trace_hooks itself. and maybe receive a custom void* instead of _sg variable ?
because type declerations isn't that big of a problem, right now I'm including SOKOL_IMPL + sokol_gfx.h with SOKOL_DUMMY as the backend, so it can define it's internal structures and whatnot.

Thanks

EDIT: oh, I just realized that defining SOKOL_DUMMY_BACKEND for plugin implementation doesn't work, because their internal structures are different

enhancement

All 6 comments

Yeah, my intent was that sokol_gfx_imgui.h is an extension header, and must be included in the the same compilation unit as the sokol_gfx.h implementation (and thus has direct access to the internal _sg variable).

Providing a void* wouldn't help, because sokol_gfx_imgui.h also must know the private structure declarations which only exist in the sokol_gfx.h implementation.

Letting sokol_gfx_imgui.h only depend on the sokol_gfx.h implementation should be possible, but I need to add functions to sokol_gfx.h to query some setup parameters (at least the resource pool sizes, maybe a couple other things as well).

Cool.
there is also couple of stuff I'm experimenting with decoupling, like for example if sokol_gfx is initialized and submitted some commands (creating some objects) before sokol_imgui initialization. They are obviously not recorded inside imgui, thus some information are not available to sokol_imgui, that may cause some problems like crashes (I got one assertion in _sg_imgui_draw_uniforms_panel)

So I guess they have to be tagged or something similiar so sokol_imgui will be aware that they have missing data.

...I think I have removed most accesses to sokol_gfx.h internal structs and functions, still WIP, I haven't tested compiling sokol_gfx_imgui.h without the sokol_gfx.h implementation included before it, but it should be pretty close.

I have removed the sg_query_*_state() and sg_query_buffer_overflow() functions from the trace callbacks, because those functions are now called from sg_gfx_imgui.h, and since they don't change state in sokol_gfx.h they're not really relevant for debugging, so removing them from the 'trace-set' was the most simple solution for now. I'll finish up the work in the next couple of days (mainly testing and updating the docs).

...ok, a few final fixes, and now it works, I have changed the sokol-samples accordingly, sokol_gfx_imgui.h now only needs the sokol_gfx.h declaration included in front, not the implementation (and imgui.h of course).

I'll keep the ticket open until I have updated the documentation.

...all done now, since sokol_gfx_imgui.h is a "normal" util header now I have moved it to the util directory (I also changed the SOKOL_IMPL define to SOKOL_GFX_IMGUI_IMPL, planning to use separate defines for the util headers).

awesome! I've just merged it with my code and removed the sokol impl completely from my plugin. working as intended.

Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

floooh picture floooh  路  3Comments

bqqbarbhg picture bqqbarbhg  路  3Comments

datgame picture datgame  路  6Comments

mhalber picture mhalber  路  5Comments

floooh picture floooh  路  3Comments