diff --git a/panda/src/display/graphicsStateGuardian.I b/panda/src/display/graphicsStateGuardian.I index 542bae0428..4c86377384 100644 --- a/panda/src/display/graphicsStateGuardian.I +++ b/panda/src/display/graphicsStateGuardian.I @@ -161,6 +161,39 @@ clear(DisplayRegion *dr) { pop_display_region(old_dr); } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::force_normals +// Access: Public +// Description: Temporarily forces the GSG to issue normals to the +// graphics pipe. Normally, the GSG will issue normals +// only if lighting is on. +// +// This call must be matched with exactly one call to +// undo_force_normals(). +//////////////////////////////////////////////////////////////////// +INLINE int GraphicsStateGuardian:: +force_normals() { + nassertr(_force_normals >= 0, _force_normals); + _force_normals++; + return _force_normals; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::undo_force_normals +// Access: Public +// Description: Undoes the effect of a previous call to +// force_normals(). +// +// This call must be matched with one-to-one with a +// previous call to force_normals(). +//////////////////////////////////////////////////////////////////// +INLINE int GraphicsStateGuardian:: +undo_force_normals() { + _force_normals--; + nassertr(_force_normals >= 0, _force_normals); + return _force_normals; +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::reset_if_new // Access: Public diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index b35167df55..a13b9c7816 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -114,7 +114,7 @@ reset() { _depth_clear_value = 1.0f; _stencil_clear_value = 0.0f; _accum_clear_value.set(0.0f, 0.0f, 0.0f, 0.0f); - _normals_enabled = false; + _force_normals = 0; //Color and alpha transform variables _color_transform_enabled = 0; @@ -420,7 +420,7 @@ end_frame() { //////////////////////////////////////////////////////////////////// bool GraphicsStateGuardian:: wants_normals() const { - return _normals_enabled; + return (_lighting_enabled || (_force_normals != 0)); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 41c41be459..a43709a52f 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -107,7 +107,8 @@ public: virtual void prepare_display_region()=0; virtual bool prepare_lens(); - INLINE void enable_normals(bool val) { _normals_enabled = val; } + INLINE int force_normals(); + INLINE int undo_force_normals(); virtual bool begin_frame(); virtual bool begin_scene(); @@ -236,8 +237,10 @@ protected: CPT(DisplayRegion) _current_display_region; CPT(Lens) _current_lens; - // This is used by wants_normals() - bool _normals_enabled; + // This is used by wants_normals(). It's used as a semaphore: + // increment it to enable normals, and decrement it when you're + // done. The graphics engine will apply normals if it is nonzero. + int _force_normals; CoordinateSystem _coordinate_system; diff --git a/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx b/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx index 5b4e84c18f..918ffc4150 100644 --- a/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx +++ b/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx @@ -426,7 +426,6 @@ dx_init( void) { _pScrn->pD3DDevice->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS, false); _color_material_enabled = false; - _normals_enabled = false; _depth_test_enabled = D3DZB_FALSE; _pScrn->pD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_FALSE); @@ -4240,16 +4239,6 @@ end_frame() { GraphicsStateGuardian::end_frame(); } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::wants_normals -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool DXGraphicsStateGuardian7:: -wants_normals() const { - return (_lighting_enabled || _normals_enabled); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian7::wants_texcoords // Access: Public, Virtual diff --git a/panda/src/dxgsg7/dxGraphicsStateGuardian7.h b/panda/src/dxgsg7/dxGraphicsStateGuardian7.h index ce27c7e76c..7457a72a41 100644 --- a/panda/src/dxgsg7/dxGraphicsStateGuardian7.h +++ b/panda/src/dxgsg7/dxGraphicsStateGuardian7.h @@ -129,7 +129,6 @@ public: virtual void end_scene(); virtual void end_frame(); - virtual bool wants_normals(void) const; virtual bool wants_texcoords(void) const; virtual bool depth_offset_decals(); diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 197387143b..a437efabd7 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -555,7 +555,6 @@ dx_init(void) { _pD3DDevice->SetRenderState(D3DRS_EDGEANTIALIAS, false); _color_material_enabled = false; - _normals_enabled = false; _depth_test_enabled = D3DZB_FALSE; _pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); @@ -4065,16 +4064,6 @@ end_frame() { GraphicsStateGuardian::end_frame(); } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian8::wants_normals -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool DXGraphicsStateGuardian8:: -wants_normals() const { - return (_lighting_enabled || _normals_enabled); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian8::wants_texcoords // Access: Public, Virtual diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h index 887e15a613..54330d58fb 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h @@ -134,7 +134,6 @@ public: virtual void end_scene(); virtual void end_frame(); - virtual bool wants_normals(void) const; virtual bool wants_texcoords(void) const; virtual bool depth_offset_decals(); diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 8034e21747..fc782b7f4d 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -556,7 +556,6 @@ dx_init(void) { _pD3DDevice->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, false); _color_material_enabled = false; - _normals_enabled = false; _depth_test_enabled = D3DZB_FALSE; _pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); @@ -4069,16 +4068,6 @@ end_frame() { GraphicsStateGuardian::end_frame(); } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian9::wants_normals -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool DXGraphicsStateGuardian9:: -wants_normals() const { - return (_lighting_enabled || _normals_enabled); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian9::wants_texcoords // Access: Public, Virtual diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h index 6fab36a189..4af2fd6d93 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h @@ -134,7 +134,6 @@ public: virtual void end_scene(); virtual void end_frame(); - virtual bool wants_normals(void) const; virtual bool wants_texcoords(void) const; virtual bool depth_offset_decals(); diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index d957d31cab..2e00c9ace1 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -1418,7 +1418,6 @@ draw_tristrip(GeomTristrip *geom, GeomContext *gc) { return; } - #ifdef DO_PSTATS // PStatTimer timer(_draw_primitive_pcollector); // Using PStatTimer may cause a compiler crash. @@ -1500,6 +1499,7 @@ draw_tristrip(GeomTristrip *geom, GeomContext *gc) { } GLP(End)(); } + report_my_gl_errors(); DO_PSTATS_STUFF(_draw_primitive_pcollector.stop()); } @@ -1811,9 +1811,8 @@ prepare_geom(Geom *geom) { // We need to temporarily force normals and UV's on, so the display // list will have them built in. - bool old_normals_enabled = _normals_enabled; bool old_texturing_enabled = _texturing_enabled; - _normals_enabled = true; + force_normals(); _texturing_enabled = true; #ifdef DO_PSTATS @@ -1842,7 +1841,7 @@ prepare_geom(Geom *geom) { ggc->_num_verts = (int)(num_verts + 0.5); #endif - _normals_enabled = old_normals_enabled; + undo_force_normals(); _texturing_enabled = old_texturing_enabled; report_my_gl_errors(); @@ -2543,16 +2542,6 @@ bind_light(Spotlight *light, int light_id) { report_my_gl_errors(); } -//////////////////////////////////////////////////////////////////// -// Function: CLP(GraphicsStateGuardian)::wants_normals -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool CLP(GraphicsStateGuardian):: -wants_normals() const { - return (_lighting_enabled || _normals_enabled); -} - //////////////////////////////////////////////////////////////////// // Function: CLP(GraphicsStateGuardian)::wants_texcoords // Access: Public, Virtual diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 8324417c04..9999e663aa 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -110,7 +110,6 @@ public: virtual void bind_light(DirectionalLight *light, int light_id); virtual void bind_light(Spotlight *light, int light_id); - virtual bool wants_normals(void) const; virtual bool wants_texcoords(void) const; virtual bool depth_offset_decals(); diff --git a/panda/src/shader/spheretexShader.cxx b/panda/src/shader/spheretexShader.cxx index aec77a9622..c69de81d6c 100644 --- a/panda/src/shader/spheretexShader.cxx +++ b/panda/src/shader/spheretexShader.cxx @@ -99,7 +99,7 @@ apply(Node *node, const AllAttributesWrapper &init_state, // Turn lighting off - we still want to issue normals, though trans.set_transition(new LightTransition(LightTransition::all_off())); - gsg->enable_normals(true); + gsg->force_normals(); // Do some extra work if we're doing the 2-pass version (e.g. the // object we are shading is textured) @@ -124,7 +124,7 @@ apply(Node *node, const AllAttributesWrapper &init_state, DirectRenderTraverser drt(gsg, RenderRelation::get_class_type()); gsg->render_subgraph(&drt, node, init_state, trans); - gsg->enable_normals(false); + gsg->undo_force_normals(); }