Sokol: State corruption issue with sokol_imgui.h + sokol_gl.h

Created on 9 Jul 2019  路  7Comments  路  Source: floooh/sokol

In some situations, sokol_imgui.h doesn't seem to properly bind its font texture when sgl_draw() is called before simgui_render(). Need to investigate.

"it seems to me that simgui_render binds its pipeline properly, so I'm guessing there's leaked state from sgl_draw that I might need to restore? As a test, I'm calling only drawTriangle from sgl-sapp.c, which works. If I don't call drawTriangle (but do invoke sgl_draw()) then simgui_render works."

...this might also be a hole in the sokol-gfx validation layer(?).

bug

All 7 comments

This fixes the issue in my test program, thanks so much!!

Update - it looks like it's not completely fixed - if I tweak the drawTriangle routine thus:

c static void draw_triangle(void) { sgl_defaults(); static float wut = 0.f; sgl_scale(1.f + wut, 1.f, 1.f); wut += 0.015f; sgl_begin_triangles(); sgl_v2f_c3b(0.0f, 0.5f, 255, 0, 0); sgl_v2f_c3b(-0.5f, -0.5f, 0, 0, 255); sgl_v2f_c3b(0.5f, -0.5f, 0, 255, 0); sgl_end(); }

The triangle becomes clipped as it passes the center of the window. Pretty sure it's a hidpi thing - as a hack/test I hacked the SGL_COMMAND_VIEWPORT to adjust the viewport there, and the triangle appears in the middle of the screen rather than upper left-ish.

...next issue might be the leaked scissor-rect from simgui_render(), when this exits, the scissor rect will be set to whatever the last one was during UI rendering, until the next begin-pass call.

I'll set the scissor-rect to "fullscreen" on exiting simgui_render(), so that there's at least a guaranteed state.

PS: reading your description of the issue it might still be some other unrelated thing... I'll try to look into this today.

Potential fix (set viewport and scissor to 'fullscreen' in simgui_render() entry and exit): https://github.com/floooh/sokol/commit/1dde6a20860e86c96572bb65d8145f1d0360f132

(even if it doesn't fix the specific issue it's the right thing to do IMHO)

I think everything is working properly now. My objects clip to the screen as expected, and are also the expected size. Thanks again!

Ok great :) Closing the issue again, for now ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

floooh picture floooh  路  3Comments

bqqbarbhg picture bqqbarbhg  路  3Comments

serkonda7 picture serkonda7  路  4Comments

ilar81 picture ilar81  路  7Comments

DomDumont picture DomDumont  路  6Comments