From: Mikko Rasa Date: Mon, 3 Apr 2023 13:15:31 +0000 (+0300) Subject: Reset the default pipeline state when rendering ends X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=dc5e4500df3a184732b85f4aee2f4f5ae69472dd;p=libs%2Fgl.git Reset the default pipeline state when rendering ends This avoids invalid accesses to resources which get destroyed before the next frame, particularly with the OpenGL backend. --- diff --git a/source/core/pipelinestate.cpp b/source/core/pipelinestate.cpp index 6078db5d..374f8926 100644 --- a/source/core/pipelinestate.cpp +++ b/source/core/pipelinestate.cpp @@ -11,6 +11,30 @@ using namespace std; namespace Msp { namespace GL { +void PipelineState::reset() +{ + set(framebuffer, static_cast(0), FRAMEBUFFER); + set(viewport, Rect::max(), VIEWPORT); + set(scissor, Rect::max(), SCISSOR); + set(shprog, static_cast(0), SHPROG); + for(BoundResource &r: resources) + { + r.changed = (r.type!=NO_RESOURCE); + r.type = NO_RESOURCE; + r.used = false; + r.block = 0; + r.buffer = 0; + } + set(vertex_setup, static_cast(0), VERTEX_SETUP); + set(primitive_type, TRIANGLES, PRIMITIVE_TYPE); + set(patch_size, 0U, PATCH_SIZE); + set(front_face, COUNTERCLOCKWISE, FACE_CULL); + set(face_cull, NO_CULL, FACE_CULL); + set(depth_test, DepthTest(), DEPTH_TEST); + set(stencil_test, StencilTest(), STENCIL_TEST); + set(blend, Blend(), BLEND); +} + template void PipelineState::set(T &target, const T &value, unsigned flag) { diff --git a/source/core/pipelinestate.h b/source/core/pipelinestate.h index 9284f5d4..a7c1c82f 100644 --- a/source/core/pipelinestate.h +++ b/source/core/pipelinestate.h @@ -91,6 +91,10 @@ private: StencilTest stencil_test; Blend blend; +public: + void reset(); + +private: template void set(T &, const T &, unsigned); public: diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 97c492eb..34d18d09 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -58,6 +58,9 @@ void Renderer::end() state_stack.clear(); texture_stack.clear(); shdata_stack.clear(); + + RendererBackend::set_pipeline_key(0); + RendererBackend::get_pipeline_state().reset(); } void Renderer::push_state()