mosra / magnum-examples

Examples for the Magnum C++11 graphics engine
https://magnum.graphics/
The Unlicense
282 stars 95 forks source link

ImGui Rendering State Features #68

Closed hofstee closed 5 years ago

hofstee commented 5 years ago

In the imgui example, there's a set of comments here that say it's sufficient to do this in the renderer constructor if you're only drawing imgui elements.

    /* Set appropriate states. If you only draw imgui UI, it is sufficient to
       do this once in the constructor. */
    GL::Renderer::enable(GL::Renderer::Feature::Blending);
    GL::Renderer::disable(GL::Renderer::Feature::FaceCulling);
    GL::Renderer::disable(GL::Renderer::Feature::DepthTest);
    GL::Renderer::enable(GL::Renderer::Feature::ScissorTest);

Which suggests you can just comment out these lines:

    // /* Reset state. Only needed if you want to draw something else with
    //    different state next frame. */
    // GL::Renderer::disable(GL::Renderer::Feature::ScissorTest);
    // GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
    // GL::Renderer::enable(GL::Renderer::Feature::FaceCulling);
    // GL::Renderer::disable(GL::Renderer::Feature::Blending);

While this comment seems valid on Emscripten, at least when I build locally with SDL2 this doesn't work. By doing nothing other than commenting out the line disabling the scissor test, I get those solitaire card effects or glitchy Windows95 things being dragged and I get a trail of the old imgui windows.

Frankly, I'm somewhat baffled.

That being said, I probably have an odd setup. I'll just list what I think would be relevant.

libsdl2-dev/oldstable,now 2.0.5+dfsg1-2 amd64 [installed] Simple DirectMedia Layer development files

- Info from Magnum

Renderer: virgl by Red Hat OpenGL version: 4.3 (Core Profile) Mesa 19.2.0-devel Using optional features: GL_ARB_ES2_compatibility GL_ARB_direct_state_access GL_ARB_get_texture_sub_image GL_ARB_invalidate_subdata GL_ARB_multi_bind GL_ARB_robustness GL_ARB_separate_shader_objects GL_ARB_texture_filter_anisotropic GL_ARB_texture_storage GL_ARB_texture_storage_multisample GL_ARB_vertex_array_object GL_KHR_debug Using driver workarounds: no-layout-qualifiers-on-old-glsl mesa-forward-compatible-line-width-range

hofstee commented 5 years ago

I poked around a bit more and found an imgui issue about something similar: https://github.com/ocornut/imgui/issues/874

If that's accurate, then the line resetting the scissor test back to its initial state is required to be there, but the others can be omitted.

mosra commented 5 years ago

Hi!

You're right -- thinking about it, what happens there is the framebuffer clear at the beginning of drawEvent() being affected by the enabled scissor test from previous frame, clearing only a very tiny part of the screen and leaving the Solitaire trail when you drag windows :)

I'll clarify that in the example code.

mosra commented 5 years ago

While attempting to document this, I realized it's easier and simpler to just reset the scissor back in the renderer itself. So that's done in mosra/magnum-integration@e0d2e38bbd69f50042c9838a631be1cf4f5839d0.

Thanks for the report!