From 4814634f95a3c88434a5523fc159c2e3bf0fe399 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Tue, 29 Jan 2008 17:05:24 +0000 Subject: [PATCH] Fixed an end_scene related bug (failure to clean up shader data) --- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 16 ++++++ .../glstuff/glGraphicsStateGuardian_src.cxx | 50 +++++++++++++++++++ .../src/glstuff/glGraphicsStateGuardian_src.h | 2 + 3 files changed, 68 insertions(+) diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index f877e033a2..4332852fe9 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -1093,6 +1093,22 @@ void DXGraphicsStateGuardian9:: end_scene() { GraphicsStateGuardian::end_scene(); + if (_vertex_array_shader_context != 0) { + _vertex_array_shader_context->disable_shader_vertex_arrays(this); + _vertex_array_shader = (Shader *)NULL; + _vertex_array_shader_context = (CLP(ShaderContext) *)NULL; + } + if (_texture_binding_shader_context != 0) { + _texture_binding_shader_context->disable_shader_texture_bindings(this); + _texture_binding_shader = (Shader *)NULL; + _texture_binding_shader_context = (CLP(ShaderContext) *)NULL; + } + if (_current_shader_context != 0) { + _current_shader_context->unbind(this); + _current_shader = (Shader *)NULL; + _current_shader_context = (CLP(ShaderContext) *)NULL; + } + DBG_S dxgsg9_cat.debug ( ) << "DXGraphicsStateGuardian9::end_scene\n"; DBG_E /* diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 96982175da..432b64c495 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -1414,6 +1414,56 @@ begin_frame(Thread *current_thread) { return true; } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::begin_scene +// Access: Public, Virtual +// Description: Called between begin_frame() and end_frame() to mark +// the beginning of drawing commands for a "scene" +// (usually a particular DisplayRegion) within a frame. +// All 3-D drawing commands, except the clear operation, +// must be enclosed within begin_scene() .. end_scene(). +// +// The return value is true if successful (in which case +// the scene will be drawn and end_scene() will be +// called later), or false if unsuccessful (in which +// case nothing will be drawn and end_scene() will not +// be called). +//////////////////////////////////////////////////////////////////// +bool CLP(GraphicsStateGuardian):: +begin_scene() { + return GraphicsStateGuardian::begin_scene(); +} + +//////////////////////////////////////////////////////////////////// +// Function: GLGraphicsStateGuardian::end_scene +// Access: Protected, Virtual +// Description: Called between begin_frame() and end_frame() to mark +// the end of drawing commands for a "scene" (usually a +// particular DisplayRegion) within a frame. All 3-D +// drawing commands, except the clear operation, must be +// enclosed within begin_scene() .. end_scene(). +//////////////////////////////////////////////////////////////////// +void CLP(GraphicsStateGuardian):: +end_scene() { + GraphicsStateGuardian::end_scene(); + + if (_vertex_array_shader_context != 0) { + _vertex_array_shader_context->disable_shader_vertex_arrays(this); + _vertex_array_shader = (Shader *)NULL; + _vertex_array_shader_context = (CLP(ShaderContext) *)NULL; + } + if (_texture_binding_shader_context != 0) { + _texture_binding_shader_context->disable_shader_texture_bindings(this); + _texture_binding_shader = (Shader *)NULL; + _texture_binding_shader_context = (CLP(ShaderContext) *)NULL; + } + if (_current_shader_context != 0) { + _current_shader_context->unbind(); + _current_shader = (Shader *)NULL; + _current_shader_context = (CLP(ShaderContext) *)NULL; + } +} + //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::end_frame // Access: Public, Virtual diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 11f2674453..0d05c5f58e 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -124,6 +124,8 @@ public: virtual bool prepare_lens(); virtual bool begin_frame(Thread *current_thread); + virtual bool begin_scene(); + virtual void end_scene(); virtual void end_frame(Thread *current_thread); virtual bool begin_draw_primitives(const GeomPipelineReader *geom_reader,