Browse Source

consolidate lights into display, pgraph

David Rose 24 years ago
parent
commit
b5a50285bd
69 changed files with 712 additions and 1701 deletions
  1. 0 2
      direct/src/showbase/showBase.cxx
  2. 1 1
      panda/src/collide/Sources.pp
  3. 0 4
      panda/src/collide/collisionSolid.cxx
  4. 1 1
      panda/src/crgsg/Sources.pp
  5. 23 0
      panda/src/display/graphicsStateGuardian.I
  6. 299 0
      panda/src/display/graphicsStateGuardian.cxx
  7. 27 0
      panda/src/display/graphicsStateGuardian.h
  8. 1 1
      panda/src/dxgsg/Sources.pp
  9. 0 14
      panda/src/dxgsg/dxGraphicsStateGuardian.I
  10. 31 214
      panda/src/dxgsg/dxGraphicsStateGuardian.cxx
  11. 3 10
      panda/src/dxgsg/dxGraphicsStateGuardian.h
  12. 1 1
      panda/src/dxgsg8/Sources.pp
  13. 10 198
      panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx
  14. 0 10
      panda/src/dxgsg8/dxGraphicsStateGuardian8.h
  15. 1 18
      panda/src/framework/framework.cxx
  16. 1 18
      panda/src/framework/framework_multimon.cxx
  17. 1 1
      panda/src/glgsg/Sources.pp
  18. 0 85
      panda/src/glgsg/glGraphicsStateGuardian.I
  19. 203 448
      panda/src/glgsg/glGraphicsStateGuardian.cxx
  20. 9 27
      panda/src/glgsg/glGraphicsStateGuardian.h
  21. 1 2
      panda/src/glutdisplay/Sources.pp
  22. 4 5
      panda/src/gsgbase/graphicsStateGuardianBase.h
  23. 0 56
      panda/src/light/Sources.pp
  24. 0 1
      panda/src/light/config_light.N
  25. 0 51
      panda/src/light/config_light.cxx
  26. 0 27
      panda/src/light/config_light.h
  27. 0 40
      panda/src/light/lightNameClass.h
  28. 0 30
      panda/src/light/lightTransition.I
  29. 0 119
      panda/src/light/lightTransition.cxx
  30. 0 86
      panda/src/light/lightTransition.h
  31. 0 11
      panda/src/light/light_composite1.cxx
  32. 0 7
      panda/src/light/light_composite2.cxx
  33. 0 24
      panda/src/light/pt_Light.cxx
  34. 0 47
      panda/src/light/pt_Light.h
  35. 0 31
      panda/src/light/vector_PT_Light.cxx
  36. 0 49
      panda/src/light/vector_PT_Light.h
  37. 25 1
      panda/src/pgraph/Sources.pp
  38. 0 0
      panda/src/pgraph/ambientLight.I
  39. 5 4
      panda/src/pgraph/ambientLight.cxx
  40. 1 1
      panda/src/pgraph/ambientLight.h
  41. 22 1
      panda/src/pgraph/config_pgraph.cxx
  42. 0 0
      panda/src/pgraph/directionalLight.I
  43. 4 4
      panda/src/pgraph/directionalLight.cxx
  44. 1 1
      panda/src/pgraph/directionalLight.h
  45. 0 0
      panda/src/pgraph/light.I
  46. 0 0
      panda/src/pgraph/light.cxx
  47. 2 2
      panda/src/pgraph/light.h
  48. 0 0
      panda/src/pgraph/lightAttrib.I
  49. 0 0
      panda/src/pgraph/lightAttrib.cxx
  50. 0 0
      panda/src/pgraph/lightAttrib.h
  51. 0 0
      panda/src/pgraph/lightLensNode.I
  52. 0 0
      panda/src/pgraph/lightLensNode.cxx
  53. 0 0
      panda/src/pgraph/lightLensNode.h
  54. 0 0
      panda/src/pgraph/lightNode.I
  55. 0 0
      panda/src/pgraph/lightNode.cxx
  56. 0 0
      panda/src/pgraph/lightNode.h
  57. 9 0
      panda/src/pgraph/pgraph_composite1.cxx
  58. 6 7
      panda/src/pgraph/pgraph_composite2.cxx
  59. 0 0
      panda/src/pgraph/pointLight.I
  60. 4 4
      panda/src/pgraph/pointLight.cxx
  61. 1 1
      panda/src/pgraph/pointLight.h
  62. 4 0
      panda/src/pgraph/qplensNode.cxx
  63. 0 0
      panda/src/pgraph/spotlight.I
  64. 7 26
      panda/src/pgraph/spotlight.cxx
  65. 1 2
      panda/src/pgraph/spotlight.h
  66. 1 1
      panda/src/ps2gsg/Sources.pp
  67. 1 1
      panda/src/ribgsg/Sources.pp
  68. 1 1
      panda/src/testbed/Sources.pp
  69. 0 5
      panda/src/testbed/demo.cxx

+ 0 - 2
direct/src/showbase/showBase.cxx

@@ -37,7 +37,6 @@
 #include "dataGraphTraversal.h"
 #include "depthTestTransition.h"
 #include "depthWriteTransition.h"
-#include "lightTransition.h"
 #include "materialTransition.h"
 #include "camera.h"
 #include "orthographicLens.h"
@@ -167,7 +166,6 @@ setup_panda_2d(GraphicsWindow *win, const string &graph_name) {
   // buffer.
   render2d_arc->set_transition(new DepthTestTransition(DepthTestProperty::M_none), 1);
   render2d_arc->set_transition(new DepthWriteTransition(DepthWriteTransition::off()), 1);
-  render2d_arc->set_transition(new LightTransition(LightTransition::all_off()), 1);
   render2d_arc->set_transition(new MaterialTransition(MaterialTransition::off()), 1);
   render2d_arc->set_transition(new CullFaceTransition(CullFaceProperty::M_cull_none), 1);
 

+ 1 - 1
panda/src/collide/Sources.pp

@@ -4,7 +4,7 @@
 #begin lib_target
   #define TARGET collide
   #define LOCAL_LIBS \
-    sgmanip light tform sgraphutil gobj graph putil \
+    sgmanip tform sgraphutil gobj graph putil \
     pstatclient
     
   #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx    

+ 0 - 4
panda/src/collide/collisionSolid.cxx

@@ -40,7 +40,6 @@
 #include "cullFaceTransition.h"
 #include "colorTransition.h"
 #include "renderModeTransition.h"
-#include "lightTransition.h"
 #include "transparencyTransition.h"
 #include "textureTransition.h"
 
@@ -280,7 +279,6 @@ add_solid_viz(Node *parent, GeomNode *viz) {
   RenderRelation *arc = new RenderRelation(parent, viz);
   arc->set_transition(new CullFaceTransition(CullFaceProperty::M_cull_clockwise));
   arc->set_transition(new RenderModeTransition(RenderModeProperty::M_filled));
-  arc->set_transition(new LightTransition(LightTransition::all_off()));
   arc->set_transition(new TextureTransition(TextureTransition::off()));
   arc->set_transition(new TransparencyTransition(TransparencyProperty::M_alpha));
 
@@ -303,7 +301,6 @@ add_wireframe_viz(Node *parent, GeomNode *viz) {
   RenderRelation *arc = new RenderRelation(parent, viz);
   arc->set_transition(new CullFaceTransition(CullFaceProperty::M_cull_none));
   arc->set_transition(new RenderModeTransition(RenderModeProperty::M_wireframe));
-  arc->set_transition(new LightTransition(LightTransition::all_off()));
   arc->set_transition(new TextureTransition(TextureTransition::off()));
   arc->set_transition(new TransparencyTransition(TransparencyProperty::M_none));
   float r,g,b;
@@ -353,7 +350,6 @@ add_other_viz(Node *parent, GeomNode *viz) {
   RenderRelation *arc = new RenderRelation(parent, viz);
   arc->set_transition(new CullFaceTransition(CullFaceProperty::M_cull_clockwise));
   arc->set_transition(new RenderModeTransition(RenderModeProperty::M_filled));
-  arc->set_transition(new LightTransition(LightTransition::all_off()));
   arc->set_transition(new TextureTransition(TextureTransition::off()));
   arc->set_transition(new TransparencyTransition(TransparencyProperty::M_alpha));
 

+ 1 - 1
panda/src/crgsg/Sources.pp

@@ -7,7 +7,7 @@
 #begin lib_target
   #define TARGET crgsg
   #define LOCAL_LIBS \
-    pandabase cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display light \
+    pandabase cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display \
     putil linmath sgraph mathutil pnmimage
 
   #define COMBINED_SOURCES $[TARGET]_composite1.cxx 

+ 23 - 0
panda/src/display/graphicsStateGuardian.I

@@ -60,6 +60,17 @@ operator < (const StateInfo &other) const {
   return _type < other._type;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::LightInfo::Constructor
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE GraphicsStateGuardian::LightInfo::
+LightInfo() {
+  _enabled = false;
+  _next_enabled = false;
+}
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsStateGuardian::set_render_traverser
@@ -411,6 +422,18 @@ get_coordinate_system() const {
   return _coordinate_system;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::get_light
+//       Access: Protected
+//  Description: Returns the Light object that is bound to the
+//               indicated id, or NULL if no Light is bound.
+////////////////////////////////////////////////////////////////////
+INLINE Light *GraphicsStateGuardian::
+get_light(int light_id) const {
+  nassertr(light_id >= 0 && light_id < _max_lights, (Light *)NULL);
+  return _light_info[light_id]._light;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: get_attribute_into
 //  Description: This external template function is handy for

+ 299 - 0
panda/src/display/graphicsStateGuardian.cxx

@@ -23,10 +23,14 @@
 #include "renderBuffer.h"
 #include "colorAttrib.h"
 #include "colorScaleAttrib.h"
+#include "lightAttrib.h"
 #include "renderState.h"
 #include "depthWriteAttrib.h"
 #include "colorWriteAttrib.h"
 #include "textureAttrib.h"
+#include "lightAttrib.h"
+#include "light.h"
+#include "ambientLight.h"
 
 #include "clockObject.h"
 #include "geomNode.h"
@@ -100,6 +104,10 @@ GraphicsStateGuardian(GraphicsWindow *win) {
   _coordinate_system = default_coordinate_system;
   _current_display_region = (DisplayRegion*)0L;
   _current_lens = (Lens *)NULL;
+
+  _light_info = (LightInfo *)NULL;
+  _max_lights = 0;
+
   reset();
 }
 
@@ -110,6 +118,7 @@ GraphicsStateGuardian(GraphicsWindow *win) {
 ////////////////////////////////////////////////////////////////////
 GraphicsStateGuardian::
 ~GraphicsStateGuardian() {
+  init_lights(0);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -146,6 +155,9 @@ reset() {
   _has_scene_graph_color = false;
   _issued_color_stale = false;
   _vertex_colors_enabled = true;
+  _lighting_enabled = false;
+
+  _lighting_enabled_this_frame = false;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -836,6 +848,15 @@ prepare_lens() {
   return false;
 }
 
+static CPT(RenderState) 
+get_unlit_state() {
+  static CPT(RenderState) state = NULL;
+  if (state == (const RenderState *)NULL) {
+    state = RenderState::make(LightAttrib::make_all_off());
+  }
+  return state;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsStateGuardian::reset_frame
 //       Access: Public, Virtual
@@ -845,6 +866,22 @@ prepare_lens() {
 ////////////////////////////////////////////////////////////////////
 void GraphicsStateGuardian::
 reset_frame() {
+  // Undo any lighting we had enabled last frame, to force the lights
+  // to be reissued, in case their parameters or positions have
+  // changed between frames.
+  if (_lighting_enabled_this_frame) {
+    for (int i = 0; i < _max_lights; i++) {
+      enable_light(i, false);
+      _light_info[i]._light = (Light *)NULL;
+    }
+
+    // Also force the lighting state to unlit, so that issue_light()
+    // will be guaranteed to be called next frame even if we have the
+    // same set of light pointers we had this frame.
+    modify_state(get_unlit_state());
+
+    _lighting_enabled_this_frame = false;
+  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -1110,6 +1147,268 @@ issue_color(const ColorAttrib *attrib) {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::issue_light
+//       Access: Public, Virtual
+//  Description: The default implementation of issue_light() assumes
+//               we have a limited number of equivalent hardware
+//               lights available (which were set up by the
+//               init_lights() call which should have been made in
+//               reset()).  This function assigns each light to a
+//               different hardware light id, trying to keep each
+//               light associated with the same id where possible, but
+//               reusing id's when necessary.
+//
+//               It will call apply_light() each time a light is
+//               assigned to a particular id for the first time in a
+//               given frame, and it will subsequently call
+//               enable_light() to enable or disable each light as the
+//               frame is rendered, as well as enable_lighting() to
+//               enable or disable overall lighting.
+//
+//               If this model of hardware lights with id's does not
+//               apply to a particular graphics engine, it should
+//               override this function to do something more
+//               appropriate instead.
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+issue_light(const LightAttrib *attrib) {
+  if (_max_lights == 0) {
+    // If we don't have any lights configured--no one called
+    // init_lights()--then forget it.
+    return;
+  }
+
+  // Initialize the current ambient light total and newly enabled
+  // light list
+  Colorf cur_ambient_light(0.0f, 0.0f, 0.0f, 1.0f);
+  int i;
+  for (i = 0; i < _max_lights; i++) {
+    _light_info[i]._next_enabled = false;
+  }
+
+  bool any_bound = false;
+
+  int num_enabled = 0;
+  int num_lights = attrib->get_num_lights();
+  if (attrib->get_operation() == LightAttrib::O_remove) {
+    num_lights = 0;
+  }
+  for (int li = 0; li < num_lights; li++) {
+    Light *light = attrib->get_light(li);
+    nassertv(light != (Light *)NULL);
+
+    num_enabled++;
+
+    // Lighting should be enabled before we apply any lights.
+    enable_lighting(true);
+    _lighting_enabled = true;
+    _lighting_enabled_this_frame = true;
+
+    if (light->get_type() == AmbientLight::get_class_type()) {
+      // Ambient lights don't require specific light ids; simply add
+      // in the ambient contribution to the current total
+      cur_ambient_light += light->get_color();
+        
+    } else {
+      // Check to see if this light has already been bound to an id
+      int cur_light_id = -1;
+      for (i = 0; i < _max_lights; i++) {
+        if (_light_info[i]._light == light) {
+          // Light has already been bound to an id, we only need to
+          // enable the light, not reapply it.
+          cur_light_id = -2;
+          enable_light(i, true);
+          _light_info[i]._next_enabled = true;
+          break;
+        }
+      }
+        
+      // See if there are any unbound light ids
+      if (cur_light_id == -1) {
+        for (i = 0; i < _max_lights; i++) {
+          if (_light_info[i]._light == (Light *)NULL) {
+            _light_info[i]._light = light;
+            cur_light_id = i;
+            break;
+          }
+        }
+      }
+        
+      // If there were no unbound light ids, see if we can replace
+      // a currently unused but previously bound id
+      if (cur_light_id == -1) {
+        for (i = 0; i < _max_lights; i++) {
+          if (!attrib->has_light(_light_info[i]._light)) {
+            _light_info[i]._light = light;
+            cur_light_id = i;
+            break;
+          }
+        }
+      }
+        
+      if (cur_light_id >= 0) {
+        enable_light(cur_light_id, true);
+        _light_info[cur_light_id]._next_enabled = true;
+        
+        if (!any_bound) {
+          begin_bind_lights();
+          any_bound = true;
+        }
+
+        // This is the first time this frame that this light has been
+        // bound to this particular id.
+        light->bind(this, cur_light_id);
+
+      } else if (cur_light_id == -1) {
+        display_cat.warning()
+          << "Failed to bind " << *light << " to id.\n";
+      }
+    }
+  }
+
+  // Disable all unused lights
+  for (i = 0; i < _max_lights; i++) {
+    if (!_light_info[i]._next_enabled) {
+      enable_light(i, false);
+    }
+  }
+
+  // If no lights were enabled, disable lighting
+  if (num_enabled == 0) {
+    enable_lighting(false);
+    _lighting_enabled = false;
+  } else {
+    set_ambient_light(cur_ambient_light);
+  }
+
+  if (any_bound) {
+    end_bind_lights();
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::bind_light
+//       Access: Public, Virtual
+//  Description: Called the first time a particular light has been
+//               bound to a given id within a frame, this should set
+//               up the associated hardware light with the light's
+//               properties.
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+bind_light(PointLight *light, int light_id) {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::bind_light
+//       Access: Public, Virtual
+//  Description: Called the first time a particular light has been
+//               bound to a given id within a frame, this should set
+//               up the associated hardware light with the light's
+//               properties.
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+bind_light(DirectionalLight *light, int light_id) {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::bind_light
+//       Access: Public, Virtual
+//  Description: Called the first time a particular light has been
+//               bound to a given id within a frame, this should set
+//               up the associated hardware light with the light's
+//               properties.
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+bind_light(Spotlight *light, int light_id) {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::init_lights
+//       Access: Protected
+//  Description: Should be called by a derived class, usually in the
+//               reset() function, to initialize the table of lights
+//               according to the number of hardware lights available.
+//               If the derived class overrides issue_light(), this
+//               function is not necessary.
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+init_lights(int num_lights) {
+  if (_light_info != (LightInfo *)NULL) {
+    delete[] _light_info;
+    _light_info = (LightInfo *)NULL;
+  }
+
+  _max_lights = num_lights;
+  if (_max_lights > 0) {
+    _light_info = new LightInfo[_max_lights];
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::enable_lighting
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by a derived class to
+//               enable or disable the use of lighting overall.  This
+//               is called by issue_light() according to whether any
+//               lights are in use or not.
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+enable_lighting(bool enable) {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::set_ambient_light
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by a derived class to
+//               indicate the color of the ambient light that should
+//               be in effect.  This is called by issue_light() after
+//               all other lights have been enabled or disabled.
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+set_ambient_light(const Colorf &color) {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::enable_light
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by a derived class to
+//               enable the indicated light id.  A specific Light will
+//               already have been bound to this id via bind_light().
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+enable_light(int light_id, bool enable) {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::begin_bind_lights
+//       Access: Protected, Virtual
+//  Description: Called immediately before bind_light() is called,
+//               this is intended to provide the derived class a hook
+//               in which to set up some state (like transform) that
+//               might apply to several lights.
+//
+//               The sequence is: begin_bind_lights() will be called,
+//               then one or more bind_light() calls, then
+//               end_bind_lights().
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+begin_bind_lights() {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::end_bind_lights
+//       Access: Protected, Virtual
+//  Description: Called after before bind_light() has been called one
+//               or more times (but before any geometry is issued or
+//               additional state is changed), this is intended to
+//               clean up any temporary changes to the state that may
+//               have been made by begin_bind_lights().
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+end_bind_lights() {
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsStateGuardian::mark_prepared_texture
 //       Access: Protected

+ 27 - 0
panda/src/display/graphicsStateGuardian.h

@@ -38,6 +38,7 @@
 #include "allTransitionsWrapper.h"
 #include "transformState.h"
 #include "renderState.h"
+#include "light.h"
 
 #include "notify.h"
 #include "pvector.h"
@@ -186,8 +187,21 @@ public:
   virtual void issue_transform(const TransformState *transform);
   virtual void issue_color_scale(const ColorScaleAttrib *attrib);
   virtual void issue_color(const ColorAttrib *attrib);
+  virtual void issue_light(const LightAttrib *attrib);
+
+  virtual void bind_light(PointLight *light, int light_id);
+  virtual void bind_light(DirectionalLight *light, int light_id);
+  virtual void bind_light(Spotlight *light, int light_id);
 
 protected:
+  INLINE Light *get_light(int light_id) const;
+  void init_lights(int num_lights);
+  virtual void enable_lighting(bool enable);
+  virtual void set_ambient_light(const Colorf &color);
+  virtual void enable_light(int light_id, bool enable);
+  virtual void begin_bind_lights();
+  virtual void end_bind_lights();
+
   virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
                                                  CPT(DisplayRegion) dr)=0;
   virtual void restore_frame_buffer(SavedFrameBuffer *frame_buffer)=0;
@@ -270,6 +284,7 @@ protected:
   bool _has_scene_graph_color;
   bool _issued_color_stale;
   bool _vertex_colors_enabled;
+  bool _lighting_enabled;
 
   bool _color_transform_enabled;
   bool _alpha_transform_enabled;
@@ -305,6 +320,18 @@ public:
   static PStatCollector _draw_primitive_pcollector;
 
 private:
+  class LightInfo {
+  public:
+    INLINE LightInfo();
+    PT(Light) _light;
+    bool _enabled;
+    bool _next_enabled;
+  };
+
+  int _max_lights;
+  LightInfo *_light_info;          // LightInfo[_max_lights]
+  bool _lighting_enabled_this_frame;
+
   // NOTE: on win32 another DLL (e.g. libpandadx.dll) cannot access
   // these sets directly due to exported template issue
   typedef pset<TextureContext *> Textures;

+ 1 - 1
panda/src/dxgsg/Sources.pp

@@ -8,7 +8,7 @@
 
   #define TARGET dxgsg
   #define LOCAL_LIBS \
-    cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display light \
+    cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display \
     putil linmath sgraph mathutil pnmimage event
     
   #define COMBINED_SOURCES $[TARGET]_composite1.cxx     

+ 0 - 14
panda/src/dxgsg/dxGraphicsStateGuardian.I

@@ -39,20 +39,6 @@ enable_line_smooth(bool val) {
   }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::enable_lighting
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void DXGraphicsStateGuardian::
-enable_lighting(bool val) {
-  if (_lighting_enabled != val) {
-    scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, (DWORD)val);
-    if(_lighting_enabled = val)
-      _lighting_enabled_this_frame = true;
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::enable_dither
 //       Access:

+ 31 - 214
panda/src/dxgsg/dxGraphicsStateGuardian.cxx

@@ -39,7 +39,6 @@
 #include <spotlight.h>
 #include <transformTransition.h>
 #include <colorTransition.h>
-#include <lightTransition.h>
 #include <textureTransition.h>
 #include <renderModeTransition.h>
 #include <materialTransition.h>
@@ -506,8 +505,6 @@ dx_init( void) {
     ZeroMemory(&_lmodel_ambient,sizeof(Colorf));
     scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, 0x0);
 
-    _light_enabled = (bool *)NULL;
-    _cur_light_enabled = (bool *)NULL;
     _clip_plane_enabled = (bool *)NULL;
     _cur_clip_plane_enabled = (bool *)NULL;
     scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , 0x0);
@@ -752,17 +749,7 @@ dx_init( void) {
     assert((scrn.D3DDevDesc.dwMaxActiveLights==0) ||  // 0 means infinite lights
            (DXGSG_MAX_LIGHTS <= scrn.D3DDevDesc.dwMaxActiveLights));
 
-    _max_lights = DXGSG_MAX_LIGHTS;
-
-    _available_light_ids = PTA(Light*)::empty_array(_max_lights);
-    _light_enabled = new bool[_max_lights];
-    _cur_light_enabled = new bool[_max_lights];
-
-    int i;
-    for (i = 0; i < _max_lights; i++) {
-        _available_light_ids[i] = NULL;
-        _light_enabled[i] = false;
-    }
+    init_lights(DXGSG_MAX_LIGHTS);
 
     if(dx_auto_normalize_lighting)
          scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_NORMALIZENORMALS, true);
@@ -968,13 +955,11 @@ dx_init( void) {
     PT(DepthTestTransition) dta = new DepthTestTransition;
     PT(DepthWriteTransition) dwa = new DepthWriteTransition;
     PT(CullFaceTransition) cfa = new CullFaceTransition;
-    PT(LightTransition) la = new LightTransition;
     PT(TextureTransition) ta = new TextureTransition;
 
     dta->issue(this);
     dwa->issue(this);
     cfa->issue(this);
-    la->issue(this);
     ta->issue(this); // no curtextcontext, this does nothing.  dx should already be properly inited above anyway
 }
 
@@ -1028,27 +1013,6 @@ clear(const RenderBuffer &buffer, const DisplayRegion *region) {
     pop_display_region(old_dr);
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::enable_light
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-bool DXGraphicsStateGuardian::
-enable_light(int light, bool val) {
-    if (_light_enabled[light] != val) {
-        _light_enabled[light] = val;
-        HRESULT res = scrn.pD3DDevice->LightEnable( light, val  );
-
-#ifdef GSG_VERBOSE
-        dxgsg_cat.debug()
-        << "LightEnable(" << light << "=" << val << ")" << endl;
-#endif
-
-        return(res == DD_OK);
-    }
-    return TRUE;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::prepare_display_region
 //       Access: Public, Virtual
@@ -1169,7 +1133,6 @@ render_frame() {
     return;
 
   _win->begin_frame();
-  _lighting_enabled_this_frame = false;
 
 #ifdef DO_PSTATS
   // For Pstats to track our current texture memory usage, we have to
@@ -1412,30 +1375,6 @@ render_frame() {
 
   // any GDI operations MUST occur after EndScene
 
-  // Now we're done with the frame processing.  Clean up.
-  if (_lighting_enabled_this_frame) {
-        // Let's turn off all the lights we had on, and clear the light
-        // cache--to force the lights to be reissued next frame, in case
-        // their parameters or positions have changed between frames.
-
-        for (int i = 0; i < _max_lights; i++) {
-            enable_light(i, false);
-            _available_light_ids[i] = NULL;
-        }
-
-        // Also force the lighting state to unlit, so that issue_light()
-        // will be guaranteed to be called next frame even if we have the
-        // same set of light pointers we had this frame.
-        NodeTransitions state;
-        state.set_transition(new LightTransition);
-        modify_state(state);
-
-        // All this work to undo the lighting state each frame doesn't seem
-        // ideal--there may be a better way.  Maybe if the lights were just
-        // more aware of whether their parameters or positions have changed
-        // at all?
-   }
-
   if(FAILED(hr)) {
     if((hr==DDERR_SURFACELOST)||(hr==DDERR_SURFACEBUSY)) {
           if(dxgsg_cat.is_debug())
@@ -4389,7 +4328,6 @@ draw_texture(TextureContext *tc, const DisplayRegion *dr) {
     TextureTransition *ta = new TextureTransition(tex);
     TextureApplyTransition *taa = new TextureApplyTransition(TextureApplyProperty::M_decal);
 
-    state.set_transition(new LightTransition);
     state.set_transition(new ColorMaskTransition);
     state.set_transition(new RenderModeTransition);
     state.set_transition(new TexMatrixTransition);
@@ -4570,7 +4508,6 @@ draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
     prepare_display_region();
 
     NodeTransitions state(na);
-    state.set_transition(new LightTransition);
     state.set_transition(new TextureTransition);
     state.set_transition(new TransformTransition);
     state.set_transition(new ColorBlendTransition);
@@ -4908,15 +4845,6 @@ void DXGraphicsStateGuardian::apply_light( Spotlight* light ) {
 #endif
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::apply_light
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian::apply_light( AmbientLight* light ) {
-    _cur_ambient_light = _cur_ambient_light + light->get_color();
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::issue_transform
 //       Access: Public, Virtual
@@ -4924,38 +4852,6 @@ void DXGraphicsStateGuardian::apply_light( AmbientLight* light ) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian::
 issue_transform(const TransformTransition *attrib) {
-#ifndef NDEBUG
-    if (dx_show_transforms) {
-
-        bool lighting_was_enabled = _lighting_enabled;
-        bool texturing_was_enabled = _texturing_enabled;
-        enable_lighting(false);
-        enable_texturing(false);
-
-        typedef struct {
-            D3DVALUE x,y,z;   // position
-            D3DVALUE nx,ny,nz; // normal
-            D3DCOLOR  diff;   // diffuse color
-        }        VERTFORMAT;
-
-        VERTFORMAT vert_buf[] = {
-            {0.0f, 0.0f, 0.0f,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(1.0f, 0.0f, 0.0f, 1.0f)},      // red
-            {3.0, 0.0f, 0.0f,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(1.0f, 0.0f, 0.0f, 1.0f)},       // red
-            {0.0f, 0.0f, 0.0f,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(0.0f, 1.0f, 0.0f, 1.0f)},      // grn
-            {0.0f, 3.0, 0.0f,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(0.0f, 1.0f, 0.0f, 1.0f)},       // grn
-            {0.0f, 0.0f, 0.0f,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(0.0f, 0.0f, 1.0f, 1.0f)},      // blu
-            {0.0f, 0.0f, 3.0,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(0.0f, 0.0f, 1.0f, 1.0f)},       // blu
-        };
-
-        HRESULT hr = scrn.pD3DDevice->DrawPrimitive(D3DPT_LINELIST, D3DFVF_DIFFUSE | D3DFVF_XYZ | D3DFVF_NORMAL,
-                                  vert_buf, 6, NULL);
-        TestDrawPrimFailure(DrawPrim,hr,scrn.pDD,6,0);
-
-        enable_lighting(lighting_was_enabled);
-        enable_texturing(texturing_was_enabled);
-    }
-#endif
-
     scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD/*VIEW*/,
                              (LPD3DMATRIX) attrib->get_matrix().get_data());
     _bTransformIssued = true;
@@ -5194,107 +5090,6 @@ issue_render_mode(const RenderModeTransition *attrib) {
     _current_fill_mode = mode;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::issue_light
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian::issue_light(const LightTransition *attrib ) {
-#if 0
-  nassertv(attrib->get_default_dir() != TD_on);
-
-  // Initialize the current ambient light total and currently enabled
-  // light list
-  _cur_ambient_light.set(0.0f, 0.0f, 0.0f, 1.0f);
-  int i;
-  for (i = 0; i < _max_lights; i++)
-    _cur_light_enabled[i] = false;
-
-  int num_enabled = 0;
-  LightTransition::const_iterator li;
-  for (li = attrib->begin(); li != attrib->end(); ++li) {
-    Light *light = (*li).first;
-    nassertv(light != (Light *)NULL);
-    TransitionDirection dir = (*li).second;
- 
-    if (dir == TD_on) {
-      num_enabled++;
-      enable_lighting(true);
-
-      _cur_light_id = -1;
-            
-      // Ambient lights don't require specific light ids
-      // Simply add in the ambient contribution to the current total
-      if (light->get_light_type() == AmbientLight::get_class_type()) {
-        light->apply(this);
-        // We need to indicate that no light id is necessary because
-        // it's an ambient light
-        _cur_light_id = -2;
-      }
-
-      // Check to see if this light has already been bound to an id
-      for (i = 0; i < _max_lights; i++) {
-        if (_available_light_ids[i] == light) {
-          // Light has already been bound to an id, we only need
-          // to enable the light, not apply it
-          _cur_light_id = -2;
-          if (enable_light(i, true))  _cur_light_enabled[i] = true;
-          break;
-        }
-      }
-
-      // See if there are any unbound light ids
-      if (_cur_light_id == -1) {
-        for (i = 0; i < _max_lights; i++) {
-          if (_available_light_ids[i] == NULL) {
-            _available_light_ids[i] = light;
-            _cur_light_id = i;
-            break;
-          }
-        }
-      }
-
-      // If there were no unbound light ids, see if we can replace
-      // a currently unused but previously bound id
-      if (_cur_light_id == -1) {
-        for (i = 0; i < _max_lights; i++) {
-          if (attrib->is_off(_available_light_ids[i])) {
-            _available_light_ids[i] = light;
-            _cur_light_id = i;
-            break;
-          }
-        }
-      }
-
-      if (_cur_light_id >= 0) {
-        if (enable_light(_cur_light_id, true))  _cur_light_enabled[_cur_light_id] = true;
-
-        // We need to do something different for each type of light
-        light->apply(this);
-      } else if (_cur_light_id == -1) {
-        dxgsg_cat.error()
-          << "issue_light() - failed to bind light to id" << endl;
-      }
-    }
-  }
-
-  // Disable all unused lights
-  for (i = 0; i < _max_lights; i++) {
-    if (!_cur_light_enabled[i])
-      enable_light(i, false);
-  }
-  
-  // If no lights were enabled, disable lighting
-  if (num_enabled == 0) {
-    enable_lighting(false);
-    enable_color_material(false);
-  } else {
-    call_dxLightModelAmbient(_cur_ambient_light);
-    enable_color_material(true);
-  }
-#endif
-}
-
 /*
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::reset_ambient
@@ -6119,6 +5914,36 @@ get_fog_mode_type(Fog::Mode m) const {
     return D3DFOG_EXP;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian::enable_lighting
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by a derived class to
+//               enable or disable the use of lighting overall.  This
+//               is called by issue_light() according to whether any
+//               lights are in use or not.
+////////////////////////////////////////////////////////////////////
+void DXGraphicsStateGuardian::
+enable_lighting(bool enable) {
+  scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, (DWORD)enable);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian::enable_light
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by a derived class to
+//               enable the indicated light id.  A specific Light will
+//               already have been bound to this id via bind_light().
+////////////////////////////////////////////////////////////////////
+void DXGraphicsStateGuardian::
+enable_light(int light_id, bool enable) {
+  HRESULT res = scrn.pD3DDevice->LightEnable(light_id, enable);
+
+#ifdef GSG_VERBOSE
+  dxgsg_cat.debug()
+    << "LightEnable(" << light << "=" << val << ")" << endl;
+#endif
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::free_pointers
 //       Access: Public
@@ -6127,14 +5952,6 @@ get_fog_mode_type(Fog::Mode m) const {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian::
 free_pointers() {
-    if (_light_enabled != (bool *)NULL) {
-        delete[] _light_enabled;
-        _light_enabled = (bool *)NULL;
-    }
-    if (_cur_light_enabled != (bool *)NULL) {
-        delete[] _cur_light_enabled;
-        _cur_light_enabled = (bool *)NULL;
-    }
     if (_clip_plane_enabled != (bool *)NULL) {
         delete[] _clip_plane_enabled;
         _clip_plane_enabled = (bool *)NULL;

+ 3 - 10
panda/src/dxgsg/dxGraphicsStateGuardian.h

@@ -141,7 +141,6 @@ public:
   virtual void issue_color_transform(const ColorMatrixTransition *);
   virtual void issue_alpha_transform(const AlphaTransformTransition *);
   virtual void issue_texture(const TextureTransition *attrib);
-  virtual void issue_light(const LightTransition *attrib);
   virtual void issue_material(const MaterialTransition *attrib);
   virtual void issue_render_mode(const RenderModeTransition *attrib);
   virtual void issue_color_blend(const ColorBlendTransition *attrib);
@@ -177,6 +176,9 @@ public:
 #endif
 
 protected:
+  virtual void enable_lighting(bool enable);
+  virtual void enable_light(int light_id, bool enable);
+
   void free_pointers();            // free local internal buffers
   void free_dxgsg_objects(void);   // free the DirectX objects we create
   virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
@@ -241,10 +243,8 @@ protected:
   INLINE void call_dxLightModelAmbient(const Colorf& color);
   INLINE void call_dxAlphaFunc(D3DCMPFUNC func, DWORD ref);
   INLINE void call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc);
-  INLINE void enable_lighting(bool val);
   INLINE void enable_dither(bool val);
   INLINE void enable_stencil_test(bool val);
-  bool enable_light(int light, bool val);
   void report_texmgr_stats();
   void draw_multitri(Geom *geom, D3DPRIMITIVETYPE tri_id);
 
@@ -315,8 +315,6 @@ protected:
   bool _line_smooth_enabled;
   bool* _light_enabled;      // bool[_max_lights]
   bool _color_material_enabled;
-  bool _lighting_enabled;
-  bool _lighting_enabled_this_frame;
   bool _texturing_enabled;
   bool  _clipping_enabled;
   bool _dither_enabled;
@@ -337,11 +335,6 @@ protected:
   DWORD _CurTexAnisoDegree;
   Texture::WrapMode _CurTexWrapModeU,_CurTexWrapModeV;
 
-  PTA(Light*) _available_light_ids;
-  int _max_lights;
-  bool* _cur_light_enabled;
-  int _cur_light_id;
-  Colorf _cur_ambient_light;
   LMatrix4f _current_projection_mat;
   int _projection_mat_stack_count;
 

+ 1 - 1
panda/src/dxgsg8/Sources.pp

@@ -7,7 +7,7 @@
 #begin lib_target
   #define TARGET dxgsg8
   #define LOCAL_LIBS \
-    cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display light \
+    cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display \
     putil linmath sgraph mathutil pnmimage event
     
   #define COMBINED_SOURCES $[TARGET]_composite1.cxx     

+ 10 - 198
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -37,7 +37,6 @@
 #include <spotlight.h>
 #include <transformTransition.h>
 #include <colorTransition.h>
-#include <lightTransition.h>
 #include <textureTransition.h>
 #include <renderModeTransition.h>
 #include <materialTransition.h>
@@ -460,8 +459,6 @@ DXGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) {
 
     _pFvfBufBasePtr = NULL;
     _index_buf=NULL;
-    _light_enabled = NULL;
-    _cur_light_enabled = NULL;
     _clip_plane_enabled = (bool *)NULL;
     _cur_clip_plane_enabled = (bool *)NULL;
 
@@ -749,8 +746,7 @@ dx_init(HCURSOR hMouseCursor) {
     }
 
     // Lighting, let's turn it off by default
-    _lighting_enabled = false;
-    scrn.pD3DDevice->SetRenderState(D3DRS_LIGHTING, _lighting_enabled);
+    scrn.pD3DDevice->SetRenderState(D3DRS_LIGHTING, false);
 
     // turn on dithering if the rendertarget is < 8bits/color channel
     _dither_enabled = ((!dx_no_dithering) && IS_16BPP_DISPLAY_FORMAT(scrn.PresParams.BackBufferFormat)
@@ -774,23 +770,9 @@ dx_init(HCURSOR hMouseCursor) {
 
     if(scrn.d3dcaps.MaxActiveLights==0) {  
         // 0 indicates no limit on # of lights, but we use DXGSG_MAX_LIGHTS anyway for now
-        _max_lights = DXGSG_MAX_LIGHTS;
+      init_lights(DXGSG_MAX_LIGHTS);
     } else {
-        _max_lights = min(DXGSG_MAX_LIGHTS,scrn.d3dcaps.MaxActiveLights);
-    }
-
-    if(_available_light_ids.is_null())
-        _available_light_ids = PTA(Light*)::empty_array(_max_lights);
-
-    if(_light_enabled==NULL)
-       _light_enabled = new bool[_max_lights];
-
-    if(_cur_light_enabled == NULL) 
-        _cur_light_enabled = new bool[_max_lights];
-
-    for (int i = 0; i < _max_lights; i++) {
-        _available_light_ids[i] = NULL;
-        _light_enabled[i] = false;
+      init_lights(min(DXGSG_MAX_LIGHTS,scrn.d3dcaps.MaxActiveLights));
     }
 
     if(dx_auto_normalize_lighting)
@@ -1001,13 +983,11 @@ dx_init(HCURSOR hMouseCursor) {
     PT(DepthTestTransition) dta = new DepthTestTransition;
     PT(DepthWriteTransition) dwa = new DepthWriteTransition;
     PT(CullFaceTransition) cfa = new CullFaceTransition;
-    PT(LightTransition) la = new LightTransition;
     PT(TextureTransition) ta = new TextureTransition;
 
     dta->issue(this);
     dwa->issue(this);
     cfa->issue(this);
-    la->issue(this);
     ta->issue(this); // no curtextcontext, this does nothing.  dx should already be properly inited above anyway
 }
 
@@ -1072,20 +1052,16 @@ clear(const RenderBuffer &buffer, const DisplayRegion *region) {
 ////////////////////////////////////////////////////////////////////
 bool DXGraphicsStateGuardian::
 enable_light(int light_id, bool val) {
-    if (_light_enabled[light_id] != val) {
-        _light_enabled[light_id] = val;
-        HRESULT hr = scrn.pD3DDevice->LightEnable( light_id, val  );
+  HRESULT hr = scrn.pD3DDevice->LightEnable( light_id, val  );
 
 #ifdef GSG_VERBOSE
-        dxgsg_cat.debug() << "LightEnable(" << light_id << "=" << val << ")" << endl;
+  dxgsg_cat.debug() << "LightEnable(" << light_id << "=" << val << ")" << endl;
 #endif
-
-        if (FAILED(hr)) {
-            dxgsg_cat.error() << "LightEnable(" << light_id << "=" << val << ") failed, " <<D3DERRORSTRING(hr);
-            return false;
-        }
-    }
-    return true;
+  
+  if (FAILED(hr)) {
+    dxgsg_cat.error() << "LightEnable(" << light_id << "=" << val << ") failed, " <<D3DERRORSTRING(hr);
+    return false;
+  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -1208,7 +1184,6 @@ render_frame() {
     return;
 
   _win->begin_frame();
-  _lighting_enabled_this_frame = false;
 
 #ifdef DO_PSTATS
   // For Pstats to track our current texture memory usage, we have to
@@ -1451,31 +1426,6 @@ render_frame() {
 
   // any GDI operations MUST occur after EndScene
 
-  // Now we're done with the frame processing.  Clean up.
-  if (_lighting_enabled_this_frame) {
-        // Let's turn off all the lights we had on, and clear the light
-        // cache--to force the lights to be reissued next frame, in case
-        // their parameters or positions have changed between frames.
-
-        for (int i = 0; i < _max_lights; i++) {
-            enable_light(i, false);
-            _available_light_ids[i] = NULL;
-        }
-
-        // Also force the lighting state to unlit, so that issue_light()
-        // will be guaranteed to be called next frame even if we have the
-        // same set of light pointers we had this frame.
-        NodeTransitions state;
-        state.set_transition(new LightTransition);
-        modify_state(state);
-
-        // All this work to undo the lighting state each frame doesn't seem
-        // ideal--there may be a better way.  Maybe if the lights were just
-        // more aware of whether their parameters or positions have changed
-        // at all?
-   }
-
-
    if(FAILED(hr)) {
     if(hr==D3DERR_DEVICELOST) {
           if(dxgsg_cat.is_debug())
@@ -3840,7 +3790,6 @@ draw_texture(TextureContext *tc, const DisplayRegion *dr) {
     TextureTransition *ta = new TextureTransition(tex);
     TextureApplyTransition *taa = new TextureApplyTransition(TextureApplyProperty::M_decal);
 
-    state.set_transition(new LightTransition);
     state.set_transition(new ColorMaskTransition);
     state.set_transition(new RenderModeTransition);
     state.set_transition(new TexMatrixTransition);
@@ -4089,7 +4038,6 @@ draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
     prepare_display_region();
 
     NodeTransitions state(na);
-    state.set_transition(new LightTransition);
     state.set_transition(new TextureTransition);
     state.set_transition(new TransformTransition);
     state.set_transition(new ColorBlendTransition);
@@ -4397,39 +4345,6 @@ void DXGraphicsStateGuardian::apply_light( AmbientLight* light ) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian::
 issue_transform(const TransformTransition *attrib) {
-#ifndef NDEBUG
-    if (dx_show_transforms) {
-
-        bool lighting_was_enabled = _lighting_enabled;
-        bool texturing_was_enabled = _texturing_enabled;
-        enable_lighting(false);
-        enable_texturing(false);
-
-        typedef struct {
-            float x,y,z;   // position
-            float nx,ny,nz; // normal
-            D3DCOLOR  diff;   // diffuse color
-        }        VERTFORMAT;
-
-        VERTFORMAT vert_buf[] = {
-            {0.0f, 0.0f, 0.0f,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(1.0f, 0.0f, 0.0f, 1.0f)},      // red
-            {3.0, 0.0f, 0.0f,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(1.0f, 0.0f, 0.0f, 1.0f)},       // red
-            {0.0f, 0.0f, 0.0f,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(0.0f, 1.0f, 0.0f, 1.0f)},      // grn
-            {0.0f, 3.0, 0.0f,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(0.0f, 1.0f, 0.0f, 1.0f)},       // grn
-            {0.0f, 0.0f, 0.0f,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(0.0f, 0.0f, 1.0f, 1.0f)},      // blu
-            {0.0f, 0.0f, 3.0,  0.0f, -1.0f, 0.0f,  MY_D3DRGBA(0.0f, 0.0f, 1.0f, 1.0f)},       // blu
-        };
-
-        set_vertex_format(D3DFVF_DIFFUSE | D3DFVF_XYZ | D3DFVF_NORMAL);
-
-        HRESULT hr = scrn.pD3DDevice->DrawPrimitiveUP(D3DPT_LINELIST,6, vert_buf, 6*sizeof(float)+sizeof(DWORD));
-        TestDrawPrimFailure(DrawPrim,hr,scrn.pD3DDevice,6,0);
-
-        enable_lighting(lighting_was_enabled);
-        enable_texturing(texturing_was_enabled);
-    }
-#endif
-
     scrn.pD3DDevice->SetTransform(D3DTS_WORLD/*VIEW*/,
                              (D3DMATRIX*) attrib->get_matrix().get_data());
     _bTransformIssued = true;
@@ -4668,107 +4583,6 @@ issue_render_mode(const RenderModeTransition *attrib) {
     _current_fill_mode = mode;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DXGraphicsStateGuardian::issue_light
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void DXGraphicsStateGuardian::issue_light(const LightTransition *attrib ) {
-#if 0
-  nassertv(attrib->get_default_dir() != TD_on);
-
-  // Initialize the current ambient light total and currently enabled
-  // light list
-  _cur_ambient_light.set(0.0f, 0.0f, 0.0f, 1.0f);
-  int i;
-  for (i = 0; i < _max_lights; i++)
-    _cur_light_enabled[i] = false;
-
-  int num_enabled = 0;
-  LightTransition::const_iterator li;
-  for (li = attrib->begin(); li != attrib->end(); ++li) {
-    Light *light = (*li).first;
-    nassertv(light != (Light *)NULL);
-    TransitionDirection dir = (*li).second;
- 
-    if (dir == TD_on) {
-      num_enabled++;
-      enable_lighting(true);
-
-      _cur_light_id = -1;
-            
-      // Ambient lights don't require specific light ids
-      // Simply add in the ambient contribution to the current total
-      if (light->get_light_type() == AmbientLight::get_class_type()) {
-        light->apply(this);
-        // We need to indicate that no light id is necessary because
-        // it's an ambient light
-        _cur_light_id = -2;
-      }
-
-      // Check to see if this light has already been bound to an id
-      for (i = 0; i < _max_lights; i++) {
-        if (_available_light_ids[i] == light) {
-          // Light has already been bound to an id, we only need
-          // to enable the light, not apply it
-          _cur_light_id = -2;
-          if (enable_light(i, true))  _cur_light_enabled[i] = true;
-          break;
-        }
-      }
-
-      // See if there are any unbound light ids
-      if (_cur_light_id == -1) {
-        for (i = 0; i < _max_lights; i++) {
-          if (_available_light_ids[i] == NULL) {
-            _available_light_ids[i] = light;
-            _cur_light_id = i;
-            break;
-          }
-        }
-      }
-
-      // If there were no unbound light ids, see if we can replace
-      // a currently unused but previously bound id
-      if (_cur_light_id == -1) {
-        for (i = 0; i < _max_lights; i++) {
-          if (attrib->is_off(_available_light_ids[i])) {
-            _available_light_ids[i] = light;
-            _cur_light_id = i;
-            break;
-          }
-        }
-      }
-
-      if (_cur_light_id >= 0) {
-        if (enable_light(_cur_light_id, true))  _cur_light_enabled[_cur_light_id] = true;
-
-        // We need to do something different for each type of light
-        light->apply(this);
-      } else if (_cur_light_id == -1) {
-        dxgsg_cat.error()
-          << "issue_light() - failed to bind light to id" << endl;
-      }
-    }
-  }
-
-  // Disable all unused lights
-  for (i = 0; i < _max_lights; i++) {
-    if (!_cur_light_enabled[i])
-      enable_light(i, false);
-  }
-  
-  // If no lights were enabled, disable lighting
-  if (num_enabled == 0) {
-    enable_lighting(false);
-    enable_color_material(false);
-  } else {
-    call_dxLightModelAmbient(_cur_ambient_light);
-    enable_color_material(true);
-  }
-#endif
-}
-
 /*
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::reset_ambient
@@ -5598,8 +5412,6 @@ free_pointers() {
 //    SAFE_DELETE_ARRAY(_fpsmeter_verts);
     SAFE_DELETE_ARRAY(_cur_clip_plane_enabled);
     SAFE_DELETE_ARRAY(_clip_plane_enabled);
-    SAFE_DELETE_ARRAY(_cur_light_enabled);
-    SAFE_DELETE_ARRAY(_light_enabled);
 }
 
 ////////////////////////////////////////////////////////////////////

+ 0 - 10
panda/src/dxgsg8/dxGraphicsStateGuardian8.h

@@ -149,7 +149,6 @@ public:
   virtual void issue_color_transform(const ColorMatrixTransition *);
   virtual void issue_alpha_transform(const AlphaTransformTransition *);
   virtual void issue_texture(const TextureTransition *attrib);
-  virtual void issue_light(const LightTransition *attrib);
   virtual void issue_material(const MaterialTransition *attrib);
   virtual void issue_render_mode(const RenderModeTransition *attrib);
   virtual void issue_color_blend(const ColorBlendTransition *attrib);
@@ -318,10 +317,7 @@ protected:
   D3DBLEND _blend_dest_func;
 
   bool _line_smooth_enabled;
-  bool* _light_enabled;      // bool[_max_lights]
   bool _color_material_enabled;
-  bool _lighting_enabled;
-  bool _lighting_enabled_this_frame;
   bool _texturing_enabled;
   bool  _clipping_enabled;
   bool _dither_enabled;
@@ -342,12 +338,6 @@ protected:
   DWORD _CurTexAnisoDegree;
   Texture::WrapMode _CurTexWrapModeU,_CurTexWrapModeV;
 
-  PTA(Light*) _available_light_ids;
-  int _max_lights;
-  bool* _cur_light_enabled;
-  int _cur_light_id;
-  float _max_light_range;
-  Colorf _cur_ambient_light;
   LMatrix4f _current_projection_mat;
   int _projection_mat_stack_count;
 

+ 1 - 18
panda/src/framework/framework.cxx

@@ -60,7 +60,6 @@
 #include "noninteractiveGraphicsPipe.h"
 #include "graphicsWindow.h"
 #include "plist.h"
-#include "lightTransition.h"
 #include "materialTransition.h"
 #include "animControl.h"
 #include "animControlCollection.h"
@@ -324,23 +323,7 @@ void display_func( void ) {
 }
 
 void set_lighting(bool enabled) {
-  if (enabled) {
-    cerr << "lighting is no longer supported in old scene graph.\n";
-    /*
-    // Enable the lights on the initial state.
-    PT(LightTransition) la = new LightTransition;
-    la->set_on(light.p());
-
-    if (have_dlight) {
-      la->set_on(dlight.p());
-    }
-    render_arc->set_transition(la);
-    */
-
-  } else {
-    // Remove the lights from the initial state.
-    render_arc->clear_transition(LightTransition::get_class_type());
-  }
+  cerr << "lighting is no longer supported in old scene graph.\n";
 }
 
 // to be used with new display callback system

+ 1 - 18
panda/src/framework/framework_multimon.cxx

@@ -60,7 +60,6 @@
 #include "noninteractiveGraphicsPipe.h"
 #include "graphicsWindow.h"
 #include "plist.h"
-#include "lightTransition.h"
 #include "materialTransition.h"
 #include "animControl.h"
 #include "animControlCollection.h"
@@ -342,23 +341,7 @@ void display_func( void ) {
 }
 
 void set_lighting(bool enabled) {
-  if (enabled) {
-    cerr << "lighting is no longer supported in old scene graph.\n";
-    /*
-    // Enable the lights on the initial state.
-    PT(LightTransition) la = new LightTransition;
-    la->set_on(light.p());
-
-    if (have_dlight) {
-      la->set_on(dlight.p());
-    }
-    render_arc->set_transition(la);
-    */
-
-  } else {
-    // Remove the lights from the initial state.
-    render_arc->clear_transition(LightTransition::get_class_type());
-  }
+  cerr << "lighting is no longer supported in old scene graph.\n";
 }
 
 // to be used with new display callback system

+ 1 - 1
panda/src/glgsg/Sources.pp

@@ -7,7 +7,7 @@
 #begin lib_target
   #define TARGET glgsg
   #define LOCAL_LIBS \
-    cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display light \
+    cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display \
     putil linmath sgraph mathutil pnmimage
     
   #define COMBINED_SOURCES $[TARGET]_composite1.cxx 

+ 0 - 85
panda/src/glgsg/glGraphicsStateGuardian.I

@@ -20,18 +20,6 @@
 
 #include <graphicsWindow.h>
 
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::LightInfo::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE GLGraphicsStateGuardian::LightInfo::
-LightInfo() {
-  _light = (Light *)NULL;
-  _enabled = false;
-  _next_enabled = false;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::activate
 //       Access: Public
@@ -227,24 +215,6 @@ call_glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
     }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::call_glLightModelAmbient
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void GLGraphicsStateGuardian::
-call_glLightModelAmbient( const Colorf& color )
-{
-  if (_lmodel_ambient != color) {
-    _lmodel_ambient = color;
-#ifdef GSG_VERBOSE
-    glgsg_cat.debug()
-      << "glLightModel(GL_LIGHT_MODEL_AMBIENT, " << color << ")" << endl;
-#endif
-    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color.get_data());
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::call_glLightModelLocal
 //       Access:
@@ -733,32 +703,6 @@ enable_point_smooth(bool val) {
   }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::enable_lighting
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void GLGraphicsStateGuardian::
-enable_lighting(bool val) {
-  if (_lighting_enabled != val) {
-    _lighting_enabled = val;
-    if (val) {
-#ifdef GSG_VERBOSE
-      glgsg_cat.debug()
-        << "glEnable(GL_LIGHTING)" << endl;
-#endif
-      glEnable(GL_LIGHTING);
-      _lighting_enabled_this_frame = true;
-    } else {
-#ifdef GSG_VERBOSE
-      glgsg_cat.debug()
-        << "glDisable(GL_LIGHTING)" << endl;
-#endif
-      glDisable(GL_LIGHTING);
-    }
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::enable_dither
 //       Access:
@@ -809,35 +753,6 @@ enable_stencil_test(bool val) {
   }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::enable_light
-//       Access:
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE void GLGraphicsStateGuardian::enable_light(int light, bool val)
-{
-    if ( _light_info[light]._enabled != val )
-    {
-        _light_info[light]._enabled = val;
-        if ( val )
-        {
-#ifdef GSG_VERBOSE
-          glgsg_cat.debug()
-            << "glEnable(GL_LIGHT" << light << ")" << endl;
-#endif
-            glEnable( get_light_id( light ) );
-        }
-        else
-        {
-#ifdef GSG_VERBOSE
-          glgsg_cat.debug()
-            << "glDisable(GL_LIGHT" << light << ")" << endl;
-#endif
-            glDisable( get_light_id( light ) );
-        }
-    }
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::enable_texturing
 //       Access:

+ 203 - 448
panda/src/glgsg/glGraphicsStateGuardian.cxx

@@ -36,7 +36,6 @@
 #include "lens.h"
 #include "get_rel_pos.h"
 #include "perspectiveLens.h"
-#include "ambientLight.h"
 #include "directionalLight.h"
 #include "pointLight.h"
 #include "spotlight.h"
@@ -46,7 +45,6 @@
 #include "colorMatrixTransition.h"
 #include "alphaTransformTransition.h"
 #include "colorTransition.h"
-#include "lightTransition.h"
 #include "textureTransition.h"
 #include "renderModeTransition.h"
 #include "materialTransition.h"
@@ -157,7 +155,6 @@ issue_transformed_color_gl(const Geom *geom, Geom::ColorIterator &citerator,
 ////////////////////////////////////////////////////////////////////
 GLGraphicsStateGuardian::
 GLGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) {
-  _light_info = (LightInfo *)NULL;
   _clip_plane_enabled = (bool *)NULL;
   _cur_clip_plane_enabled = (bool *)NULL;
 
@@ -261,8 +258,6 @@ reset() {
   _line_smooth_enabled = false;
   _point_smooth_enabled = false;
   _scissor_enabled = false;
-  _lighting_enabled = false;
-  _lighting_enabled_this_frame = false;
   _normals_enabled = false;
   _texturing_enabled = false;
   _multisample_alpha_one_enabled = false;
@@ -294,9 +289,8 @@ reset() {
 
   // Set up the light id map
   GLint max_lights;
-  glGetIntegerv( GL_MAX_LIGHTS, &max_lights );
-  _max_lights = max_lights;
-  _light_info = new LightInfo[_max_lights];
+  glGetIntegerv(GL_MAX_LIGHTS, &max_lights);
+  init_lights(max_lights);
 
   // Set up the clip plane id map
   GLint max_clip_planes;
@@ -319,13 +313,11 @@ reset() {
   PT(DepthTestTransition) dta = new DepthTestTransition;
   PT(DepthWriteTransition) dwa = new DepthWriteTransition;
   PT(CullFaceTransition) cfa = new CullFaceTransition;
-  PT(LightTransition) la = new LightTransition;
   PT(TextureTransition) ta = new TextureTransition;
 
   dta->issue(this);
   dwa->issue(this);
   cfa->issue(this);
-  la->issue(this);
   ta->issue(this);
 
   Material empty;
@@ -534,7 +526,6 @@ render_frame() {
   _win->begin_frame();
   report_errors();
   _decal_level = 0;
-  _lighting_enabled_this_frame = false;
 
 #ifdef DO_PSTATS
   // For Pstats to track our current texture memory usage, we have to
@@ -585,28 +576,6 @@ render_frame() {
 
   // Now we're done with the frame processing.  Clean up.
 
-  if (_lighting_enabled_this_frame) {
-
-    // Let's turn off all the lights we had on, and clear the light
-    // cache--to force the lights to be reissued next frame, in case
-    // their parameters or positions have changed between frames.
-
-    for (int i = 0; i < _max_lights; i++) {
-      enable_light(i, false);
-      _light_info[i]._light = (Light *)NULL;
-    }
-
-    // Also force the lighting state to unlit, so that issue_light()
-    // will be guaranteed to be called next frame even if we have the
-    // same set of light pointers we had this frame.
-    clear_attribute(LightTransition::get_class_type());
-
-    // All this work to undo the lighting state each frame doesn't seem
-    // ideal--there may be a better way.  Maybe if the lights were just
-    // more aware of whether their parameters or positions have changed
-    // at all?
-  }
-
 #ifndef NDEBUG
   report_errors();
 #endif
@@ -2083,7 +2052,6 @@ draw_texture(TextureContext *tc, const DisplayRegion *dr) {
   TextureApplyTransition *taa = new TextureApplyTransition;
   taa->set_mode(TextureApplyProperty::M_decal);
 
-  state.set_transition(new LightTransition);
   state.set_transition(new ColorMaskTransition);
   state.set_transition(new RenderModeTransition);
   state.set_transition(new TexMatrixTransition);
@@ -2299,7 +2267,6 @@ draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
   prepare_display_region();
 
   NodeTransitions state(na);
-  state.set_transition(new LightTransition);
   state.set_transition(new TextureTransition);
   state.set_transition(new TransformTransition);
   //state.set_transition(new ColorBlendTransition);
@@ -2518,155 +2485,6 @@ apply_fog(qpFog *fog) {
   report_errors();
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::apply_light
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void GLGraphicsStateGuardian::
-apply_light(PointLight *light) {
-  // We need to temporarily load a new matrix so we can define the
-  // light in a known coordinate system.  We pick the transform of the
-  // root.  (Alternatively, we could leave the current transform where
-  // it is and compute the light position relative to that transform
-  // instead of relative to the root, by composing with the matrix
-  // computed by _transform->invert_compose(render_transform).  But I
-  // think loading a completely new matrix is simpler.)
-  glMatrixMode(GL_MODELVIEW);
-  glPushMatrix();
-  glLoadMatrixf(_scene_setup->get_render_transform()->get_mat().get_data());
-
-  GLenum id = get_light_id(_cur_light_id);
-  static const Colorf black(0.0f, 0.0f, 0.0f, 1.0f);
-  glLightfv(id, GL_AMBIENT, black.get_data());
-  glLightfv(id, GL_DIFFUSE, light->get_color().get_data());
-  glLightfv(id, GL_SPECULAR, light->get_specular_color().get_data());
-
-  // Position needs to specify x, y, z, and w
-  // w == 1 implies non-infinite position
-  qpNodePath light_np(light);
-  const LMatrix4f &light_mat = light_np.get_mat(qpNodePath());
-  LPoint3f pos = light->get_point() * light_mat;
-
-  LPoint4f fpos(pos[0], pos[1], pos[2], 1.0f);
-  glLightfv(id, GL_POSITION, fpos.get_data());
-
-  // GL_SPOT_DIRECTION is not significant when cutoff == 180
-
-  // Exponent == 0 implies uniform light distribution
-  glLightf(id, GL_SPOT_EXPONENT, 0.0f);
-
-  // Cutoff == 180 means uniform point light source
-  glLightf(id, GL_SPOT_CUTOFF, 180.0f);
-
-  const LVecBase3f &att = light->get_attenuation();
-  glLightf(id, GL_CONSTANT_ATTENUATION, att[0]);
-  glLightf(id, GL_LINEAR_ATTENUATION, att[1]);
-  glLightf(id, GL_QUADRATIC_ATTENUATION, att[2]);
-
-  glPopMatrix();
-  report_errors();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::apply_light
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void GLGraphicsStateGuardian::
-apply_light(DirectionalLight *light) {
-  // See the comment about this transform change in PointLight, above.
-  glMatrixMode(GL_MODELVIEW);
-  glPushMatrix();
-  glLoadMatrixf(_scene_setup->get_render_transform()->get_mat().get_data());
-
-  GLenum id = get_light_id( _cur_light_id );
-  static const Colorf black(0.0f, 0.0f, 0.0f, 1.0f);
-  glLightfv(id, GL_AMBIENT, black.get_data());
-  glLightfv(id, GL_DIFFUSE, light->get_color().get_data());
-  glLightfv(id, GL_SPECULAR, light->get_specular_color().get_data());
-
-  // Position needs to specify x, y, z, and w.
-  // w == 0 implies light is at infinity
-  qpNodePath light_np(light);
-  const LMatrix4f &light_mat = light_np.get_mat(qpNodePath());
-  LVector3f dir = light->get_direction() * light_mat;
-  LPoint4f fdir(-dir[0], -dir[1], -dir[2], 0);
-  glLightfv(id, GL_POSITION, fdir.get_data());
-
-  // GL_SPOT_DIRECTION is not significant when cutoff == 180
-  // In this case, position x, y, z specifies direction
-
-  // Exponent == 0 implies uniform light distribution
-  glLightf(id, GL_SPOT_EXPONENT, 0.0f);
-
-  // Cutoff == 180 means uniform point light source
-  glLightf(id, GL_SPOT_CUTOFF, 180.0f);
-
-  // Default attenuation values (only spotlight and point light can
-  // modify these)
-  glLightf(id, GL_CONSTANT_ATTENUATION, 1.0f);
-  glLightf(id, GL_LINEAR_ATTENUATION, 0.0f);
-  glLightf(id, GL_QUADRATIC_ATTENUATION, 0.0f);
-
-  glPopMatrix();
-  report_errors();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::apply_light
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void GLGraphicsStateGuardian::
-apply_light(Spotlight *light) {
-  Lens *lens = light->get_lens();
-  nassertv(lens != (Lens *)NULL);
-
-  // See the comment about this transform change in PointLight, above.
-  glMatrixMode(GL_MODELVIEW);
-  glPushMatrix();
-  glLoadMatrixf(_scene_setup->get_render_transform()->get_mat().get_data());
-
-  GLenum id = get_light_id(_cur_light_id);
-  static const Colorf black(0.0f, 0.0f, 0.0f, 1.0f);
-  glLightfv(id, GL_AMBIENT, black.get_data());
-  glLightfv(id, GL_DIFFUSE, light->get_color().get_data());
-  glLightfv(id, GL_SPECULAR, light->get_specular_color().get_data());
-
-  // Position needs to specify x, y, z, and w
-  // w == 1 implies non-infinite position
-  qpNodePath light_np(light);
-  const LMatrix4f &light_mat = light_np.get_mat(qpNodePath());
-  LPoint3f pos = lens->get_nodal_point() * light_mat;
-  LVector3f dir = lens->get_view_vector() * light_mat;
-
-  LPoint4f fpos(pos[0], pos[1], pos[2], 1.0f);
-  glLightfv(id, GL_POSITION, fpos.get_data());
-  glLightfv(id, GL_SPOT_DIRECTION, dir.get_data());
-
-  glLightf(id, GL_SPOT_EXPONENT, light->get_exponent());
-  glLightf(id, GL_SPOT_CUTOFF, lens->get_hfov());
-
-  const LVecBase3f &att = light->get_attenuation();
-  glLightf(id, GL_CONSTANT_ATTENUATION, att[0]);
-  glLightf(id, GL_LINEAR_ATTENUATION, att[1]);
-  glLightf(id, GL_QUADRATIC_ATTENUATION, att[2]);
-
-  glPopMatrix();
-  report_errors();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::apply_light
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void GLGraphicsStateGuardian::
-apply_light(AmbientLight *) {
-  // Ambient lights are handled as a special case in issue_light().
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::issue_transform
 //       Access: Public, Virtual
@@ -2681,36 +2499,6 @@ issue_transform(const TransformTransition *attrib) {
 #endif
   glMatrixMode(GL_MODELVIEW);
   glLoadMatrixf(attrib->get_matrix().get_data());
-
-#ifndef NDEBUG
-  if (gl_show_transforms) {
-    bool lighting_was_enabled = _lighting_enabled;
-    bool texturing_was_enabled = _texturing_enabled;
-    enable_lighting(false);
-    enable_texturing(false);
-
-    glBegin(GL_LINES);
-
-    // X axis in red
-    glColor3f(1.0f, 0.0f, 0.0f);
-    glVertex3f(0.0f, 0.0f, 0.0f);
-    glVertex3f(1.0f, 0.0f, 0.0f);
-
-    // Y axis in green
-    glColor3f(0.0f, 1.0f, 0.0f);
-    glVertex3f(0.0f, 0.0f, 0.0f);
-    glVertex3f(0.0f, 1.0f, 0.0f);
-
-    // Z axis in blue
-    glColor3f(0.0f, 0.0f, 1.0f);
-    glVertex3f(0.0f, 0.0f, 0.0f);
-    glVertex3f(0.0f, 0.0f, 1.0f);
-
-    glEnd();
-    enable_lighting(lighting_was_enabled);
-    enable_texturing(texturing_was_enabled);
-  }
-#endif
   report_errors();
 }
 
@@ -2939,108 +2727,6 @@ issue_render_mode(const RenderModeTransition *attrib) {
   report_errors();
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::issue_light
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void GLGraphicsStateGuardian::issue_light(const LightTransition *attrib )
-{
-#if 0
-  nassertv(attrib->get_default_dir() != TD_on);
-  //  activate();
-
-  // Initialize the current ambient light total and newly enabled
-  // light list
-  Colorf cur_ambient_light(0.0f, 0.0f, 0.0f, 1.0f);
-  int i;
-  for (i = 0; i < _max_lights; i++) {
-    _light_info[i]._next_enabled = false;
-  }
-
-  int num_enabled = 0;
-  LightTransition::const_iterator li;
-  for (li = attrib->begin(); li != attrib->end(); ++li) {
-    Light *light = (*li).first;
-    nassertv(light != (Light *)NULL);
-    TransitionDirection dir = (*li).second;
-
-    if (dir == TD_on) {
-      num_enabled++;
-      enable_lighting(true);
-
-      if (light->get_light_type() == AmbientLight::get_class_type()) {
-        // Ambient lights don't require specific light ids; simply add
-        // in the ambient contribution to the current total
-        cur_ambient_light += light->get_color();
-        
-      } else {
-        // Check to see if this light has already been bound to an id
-        _cur_light_id = -1;
-        for (i = 0; i < _max_lights; i++) {
-          if (_light_info[i]._light == light) {
-            // Light has already been bound to an id, we only need
-            // to enable the light, not apply it
-            _cur_light_id = -2;
-            enable_light(i, true);
-            _light_info[i]._next_enabled = true;
-            break;
-          }
-        }
-        
-        // See if there are any unbound light ids
-        if (_cur_light_id == -1) {
-          for (i = 0; i < _max_lights; i++) {
-            if (_light_info[i]._light == (Light *)NULL) {
-              _light_info[i]._light = light;
-              _cur_light_id = i;
-              break;
-            }
-          }
-        }
-        
-        // If there were no unbound light ids, see if we can replace
-        // a currently unused but previously bound id
-        if (_cur_light_id == -1) {
-          for (i = 0; i < _max_lights; i++) {
-            if (attrib->is_off(_light_info[i]._light)) {
-              _light_info[i]._light = light;
-              _cur_light_id = i;
-              break;
-            }
-          }
-        }
-        
-        if (_cur_light_id >= 0) {
-          enable_light(_cur_light_id, true);
-          _light_info[i]._next_enabled = true;
-          
-          // We need to do something different for each type of light
-          light->apply(this);
-        } else if (_cur_light_id == -1) {
-          glgsg_cat.error()
-            << "issue_light() - failed to bind light to id" << endl;
-        }
-      }
-    }
-  }
-
-  // Disable all unused lights
-  for (i = 0; i < _max_lights; i++) {
-    if (!_light_info[i]._next_enabled)
-      enable_light(i, false);
-  }
-
-  // If no lights were enabled, disable lighting
-  if (num_enabled == 0) {
-    enable_lighting(false);
-  } else {
-    call_glLightModelAmbient(cur_ambient_light);
-  }
-  report_errors();
-#endif
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::issue_color_blend
 //       Access: Public, Virtual
@@ -3455,104 +3141,6 @@ issue_texture(const TextureAttrib *attrib) {
   report_errors();
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::issue_light
-//       Access: Public, Virtual
-//  Description:
-////////////////////////////////////////////////////////////////////
-void GLGraphicsStateGuardian::
-issue_light(const LightAttrib *attrib) {
-  // Initialize the current ambient light total and newly enabled
-  // light list
-  Colorf cur_ambient_light(0.0f, 0.0f, 0.0f, 1.0f);
-  int i;
-  for (i = 0; i < _max_lights; i++) {
-    _light_info[i]._next_enabled = false;
-  }
-
-  int num_enabled = 0;
-  int num_lights = attrib->get_num_lights();
-  if (attrib->get_operation() == LightAttrib::O_remove) {
-    num_lights = 0;
-  }
-  for (int li = 0; li < num_lights; li++) {
-    Light *light = attrib->get_light(li);
-    nassertv(light != (Light *)NULL);
-
-    num_enabled++;
-    enable_lighting(true);
-
-    if (light->get_type() == AmbientLight::get_class_type()) {
-      // Ambient lights don't require specific light ids; simply add
-      // in the ambient contribution to the current total
-      cur_ambient_light += light->get_color();
-        
-    } else {
-      // Check to see if this light has already been bound to an id
-      _cur_light_id = -1;
-      for (i = 0; i < _max_lights; i++) {
-        if (_light_info[i]._light == light) {
-          // Light has already been bound to an id, we only need to
-          // enable the light, not reapply it.
-          _cur_light_id = -2;
-          enable_light(i, true);
-          _light_info[i]._next_enabled = true;
-          break;
-        }
-      }
-        
-      // See if there are any unbound light ids
-      if (_cur_light_id == -1) {
-        for (i = 0; i < _max_lights; i++) {
-          if (_light_info[i]._light == (Light *)NULL) {
-            _light_info[i]._light = light;
-            _cur_light_id = i;
-            break;
-          }
-        }
-      }
-        
-      // If there were no unbound light ids, see if we can replace
-      // a currently unused but previously bound id
-      if (_cur_light_id == -1) {
-        for (i = 0; i < _max_lights; i++) {
-          if (!attrib->has_light(_light_info[i]._light)) {
-            _light_info[i]._light = light;
-            _cur_light_id = i;
-            break;
-          }
-        }
-      }
-        
-      if (_cur_light_id >= 0) {
-        enable_light(_cur_light_id, true);
-        _light_info[i]._next_enabled = true;
-        
-        // We need to do something different for each type of light
-        light->apply(this);
-      } else if (_cur_light_id == -1) {
-        glgsg_cat.error()
-          << "issue_light() - failed to bind light to id" << endl;
-      }
-    }
-  }
-
-  // Disable all unused lights
-  for (i = 0; i < _max_lights; i++) {
-    if (!_light_info[i]._next_enabled) {
-      enable_light(i, false);
-    }
-  }
-
-  // If no lights were enabled, disable lighting
-  if (num_enabled == 0) {
-    enable_lighting(false);
-  } else {
-    call_glLightModelAmbient(cur_ambient_light);
-  }
-  report_errors();
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::issue_material
 //       Access: Public, Virtual
@@ -3789,40 +3377,128 @@ issue_depth_offset(const DepthOffsetAttrib *attrib) {
   report_errors();
 }
 
-static CPT(RenderState) 
-get_unlit_state() {
-  static CPT(RenderState) state = NULL;
-  if (state == (const RenderState *)NULL) {
-    state = RenderState::make(LightAttrib::make_all_off());
-  }
-  return state;
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::bind_light
+//       Access: Public, Virtual
+//  Description: Called the first time a particular light has been
+//               bound to a given id within a frame, this should set
+//               up the associated hardware light with the light's
+//               properties.
+////////////////////////////////////////////////////////////////////
+void GLGraphicsStateGuardian::
+bind_light(PointLight *light, int light_id) {
+  GLenum id = get_light_id(light_id);
+  static const Colorf black(0.0f, 0.0f, 0.0f, 1.0f);
+  glLightfv(id, GL_AMBIENT, black.get_data());
+  glLightfv(id, GL_DIFFUSE, light->get_color().get_data());
+  glLightfv(id, GL_SPECULAR, light->get_specular_color().get_data());
+
+  // Position needs to specify x, y, z, and w
+  // w == 1 implies non-infinite position
+  qpNodePath light_np(light);
+  const LMatrix4f &light_mat = light_np.get_mat(_scene_setup->get_scene_root());
+  LPoint3f pos = light->get_point() * light_mat;
+
+  LPoint4f fpos(pos[0], pos[1], pos[2], 1.0f);
+  glLightfv(id, GL_POSITION, fpos.get_data());
+
+  // GL_SPOT_DIRECTION is not significant when cutoff == 180
+
+  // Exponent == 0 implies uniform light distribution
+  glLightf(id, GL_SPOT_EXPONENT, 0.0f);
+
+  // Cutoff == 180 means uniform point light source
+  glLightf(id, GL_SPOT_CUTOFF, 180.0f);
+
+  const LVecBase3f &att = light->get_attenuation();
+  glLightf(id, GL_CONSTANT_ATTENUATION, att[0]);
+  glLightf(id, GL_LINEAR_ATTENUATION, att[1]);
+  glLightf(id, GL_QUADRATIC_ATTENUATION, att[2]);
+
+  report_errors();
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::reset_frame
+//     Function: GLGraphicsStateGuardian::bind_light
 //       Access: Public, Virtual
-//  Description: Called before each frame is rendered, to allow the
-//               GSG a chance to do any internal cleanup before
-//               beginning the frame.
+//  Description: Called the first time a particular light has been
+//               bound to a given id within a frame, this should set
+//               up the associated hardware light with the light's
+//               properties.
 ////////////////////////////////////////////////////////////////////
 void GLGraphicsStateGuardian::
-reset_frame() {
-  // Undo any lighting we had enabled last frame, to force the lights
-  // to be reissued, in case their parameters or positions have
-  // changed between frames.
-  if (_lighting_enabled_this_frame) {
-    for (int i = 0; i < _max_lights; i++) {
-      enable_light(i, false);
-      _light_info[i]._light = (Light *)NULL;
-    }
+bind_light(DirectionalLight *light, int light_id) {
+  GLenum id = get_light_id( light_id );
+  static const Colorf black(0.0f, 0.0f, 0.0f, 1.0f);
+  glLightfv(id, GL_AMBIENT, black.get_data());
+  glLightfv(id, GL_DIFFUSE, light->get_color().get_data());
+  glLightfv(id, GL_SPECULAR, light->get_specular_color().get_data());
 
-    // Also force the lighting state to unlit, so that issue_light()
-    // will be guaranteed to be called next frame even if we have the
-    // same set of light pointers we had this frame.
-    modify_state(get_unlit_state());
+  // Position needs to specify x, y, z, and w.
+  // w == 0 implies light is at infinity
+  qpNodePath light_np(light);
+  const LMatrix4f &light_mat = light_np.get_mat(_scene_setup->get_scene_root());
+  LVector3f dir = light->get_direction() * light_mat;
+  LPoint4f fdir(-dir[0], -dir[1], -dir[2], 0);
+  glLightfv(id, GL_POSITION, fdir.get_data());
 
-    _lighting_enabled_this_frame = false;
-  }
+  // GL_SPOT_DIRECTION is not significant when cutoff == 180
+  // In this case, position x, y, z specifies direction
+
+  // Exponent == 0 implies uniform light distribution
+  glLightf(id, GL_SPOT_EXPONENT, 0.0f);
+
+  // Cutoff == 180 means uniform point light source
+  glLightf(id, GL_SPOT_CUTOFF, 180.0f);
+
+  // Default attenuation values (only spotlight and point light can
+  // modify these)
+  glLightf(id, GL_CONSTANT_ATTENUATION, 1.0f);
+  glLightf(id, GL_LINEAR_ATTENUATION, 0.0f);
+  glLightf(id, GL_QUADRATIC_ATTENUATION, 0.0f);
+
+  report_errors();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::bind_light
+//       Access: Public, Virtual
+//  Description: Called the first time a particular light has been
+//               bound to a given id within a frame, this should set
+//               up the associated hardware light with the light's
+//               properties.
+////////////////////////////////////////////////////////////////////
+void GLGraphicsStateGuardian::
+bind_light(Spotlight *light, int light_id) {
+  Lens *lens = light->get_lens();
+  nassertv(lens != (Lens *)NULL);
+
+  GLenum id = get_light_id(light_id);
+  static const Colorf black(0.0f, 0.0f, 0.0f, 1.0f);
+  glLightfv(id, GL_AMBIENT, black.get_data());
+  glLightfv(id, GL_DIFFUSE, light->get_color().get_data());
+  glLightfv(id, GL_SPECULAR, light->get_specular_color().get_data());
+
+  // Position needs to specify x, y, z, and w
+  // w == 1 implies non-infinite position
+  qpNodePath light_np(light);
+  const LMatrix4f &light_mat = light_np.get_mat(_scene_setup->get_scene_root());
+  LPoint3f pos = lens->get_nodal_point() * light_mat;
+  LVector3f dir = lens->get_view_vector() * light_mat;
+
+  LPoint4f fpos(pos[0], pos[1], pos[2], 1.0f);
+  glLightfv(id, GL_POSITION, fpos.get_data());
+  glLightfv(id, GL_SPOT_DIRECTION, dir.get_data());
+
+  glLightf(id, GL_SPOT_EXPONENT, light->get_exponent());
+  glLightf(id, GL_SPOT_CUTOFF, lens->get_hfov());
+
+  const LVecBase3f &att = light->get_attenuation();
+  glLightf(id, GL_CONSTANT_ATTENUATION, att[0]);
+  glLightf(id, GL_LINEAR_ATTENUATION, att[1]);
+  glLightf(id, GL_QUADRATIC_ATTENUATION, att[2]);
+
+  report_errors();
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -4862,6 +4538,93 @@ issue_transformed_color(const Colorf &color) const {
   glColor4fv(transformed.get_data());
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::enable_lighting
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by a derived class to
+//               enable or disable the use of lighting overall.  This
+//               is called by issue_light() according to whether any
+//               lights are in use or not.
+////////////////////////////////////////////////////////////////////
+void GLGraphicsStateGuardian::
+enable_lighting(bool enable) {
+  if (enable) {
+    glEnable(GL_LIGHTING);
+  } else {
+    glDisable(GL_LIGHTING);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::set_ambient_light
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by a derived class to
+//               indicate the color of the ambient light that should
+//               be in effect.  This is called by issue_light() after
+//               all other lights have been enabled or disabled.
+////////////////////////////////////////////////////////////////////
+void GLGraphicsStateGuardian::
+set_ambient_light(const Colorf &color) {
+  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color.get_data());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::enable_light
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by a derived class to
+//               enable the indicated light id.  A specific Light will
+//               already have been bound to this id via bind_light().
+////////////////////////////////////////////////////////////////////
+void GLGraphicsStateGuardian::
+enable_light(int light_id, bool enable) {
+  if (enable) {
+    glEnable(get_light_id(light_id));
+  } else {
+    glDisable(get_light_id(light_id));
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::begin_bind_lights
+//       Access: Protected, Virtual
+//  Description: Called immediately before bind_light() is called,
+//               this is intended to provide the derived class a hook
+//               in which to set up some state (like transform) that
+//               might apply to several lights.
+//
+//               The sequence is: begin_bind_lights() will be called,
+//               then one or more bind_light() calls, then
+//               end_bind_lights().
+////////////////////////////////////////////////////////////////////
+void GLGraphicsStateGuardian::
+begin_bind_lights() {
+  // We need to temporarily load a new matrix so we can define the
+  // light in a known coordinate system.  We pick the transform of the
+  // root.  (Alternatively, we could leave the current transform where
+  // it is and compute the light position relative to that transform
+  // instead of relative to the root, by composing with the matrix
+  // computed by _transform->invert_compose(render_transform).  But I
+  // think loading a completely new matrix is simpler.)
+  glMatrixMode(GL_MODELVIEW);
+  glPushMatrix();
+  glLoadMatrixf(_scene_setup->get_render_transform()->get_mat().get_data());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::end_bind_lights
+//       Access: Protected, Virtual
+//  Description: Called after before bind_light() has been called one
+//               or more times (but before any geometry is issued or
+//               additional state is changed), this is intended to
+//               clean up any temporary changes to the state that may
+//               have been made by begin_bind_lights().
+////////////////////////////////////////////////////////////////////
+void GLGraphicsStateGuardian::
+end_bind_lights() {
+  glMatrixMode(GL_MODELVIEW);
+  glPopMatrix();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::free_pointers
 //       Access: Protected
@@ -4870,10 +4633,6 @@ issue_transformed_color(const Colorf &color) const {
 ////////////////////////////////////////////////////////////////////
 void GLGraphicsStateGuardian::
 free_pointers() {
-  if (_light_info != (LightInfo *)NULL) {
-    delete[] _light_info;
-    _light_info = (LightInfo *)NULL;
-  }
   if (_clip_plane_enabled != (bool *)NULL) {
     delete[] _clip_plane_enabled;
     _clip_plane_enabled = (bool *)NULL;
@@ -5152,10 +4911,6 @@ dump_state(void)
       dump << "\t\t" << "GL_LINE_SMOOTH " << _line_smooth_enabled << " " << (bool)glIsEnabled(GL_LINE_SMOOTH) << "\n";
       dump << "\t\t" << "GL_POINT_SMOOTH " << _point_smooth_enabled << " " << (bool)glIsEnabled(GL_POINT_SMOOTH) << "\n";
       dump << "\t\t" << "GL_LIGHTING " << _lighting_enabled << " " << (bool)glIsEnabled(GL_LIGHTING) << "\n";
-      for(i = 0; i < _max_lights; i++)
-        {
-          dump << "\t\t\t\t" << "GL_LIGHT" << i << " " << _light_info[i]._enabled << " " << (bool)glIsEnabled(GL_LIGHT0+i) << "\n";
-        }
       dump << "\t\t" << "GL_SCISSOR_TEST " << _scissor_enabled << " " << (bool)glIsEnabled(GL_SCISSOR_TEST) << "\n";
       dump << "\t\t" << "GL_TEXTURE_2D " << _texturing_enabled << " " << (bool)glIsEnabled(GL_TEXTURE_2D) << "\n";
       dump << "\t\t" << "GL_DITHER " << _dither_enabled << " " << (bool)glIsEnabled(GL_DITHER) << "\n";

+ 9 - 27
panda/src/glgsg/glGraphicsStateGuardian.h

@@ -33,7 +33,6 @@
 #include "depthTestProperty.h"
 #include "stencilProperty.h"
 #include "fog.h"
-#include "pt_Light.h"
 #include "depthTestAttrib.h"
 #include "textureApplyAttrib.h"
 #include "pointerToArray.h"
@@ -130,18 +129,12 @@ public:
   virtual void apply_fog(Fog *fog);
   void apply_fog(qpFog *fog);
 
-  virtual void apply_light(PointLight* light);
-  virtual void apply_light(DirectionalLight* light);
-  virtual void apply_light(Spotlight* light);
-  virtual void apply_light(AmbientLight* light);
-
   virtual void issue_transform(const TransformTransition *attrib);
   virtual void issue_color_transform(const ColorMatrixTransition *attrib);
   virtual void issue_alpha_transform(const AlphaTransformTransition *attrib);
   virtual void issue_tex_matrix(const TexMatrixTransition *attrib);
   virtual void issue_color(const ColorTransition *attrib);
   virtual void issue_texture(const TextureTransition *attrib);
-  virtual void issue_light(const LightTransition *attrib);
   virtual void issue_material(const MaterialTransition *attrib);
   virtual void issue_render_mode(const RenderModeTransition *attrib);
   virtual void issue_color_blend(const ColorBlendTransition *attrib);
@@ -160,11 +153,8 @@ public:
   virtual void issue_polygon_offset(const PolygonOffsetTransition *attrib);
 
   virtual void issue_transform(const TransformState *transform);
-  //  virtual void issue_color_scale(const ColorScaleAttrib *attrib);
-  //  virtual void issue_color(const ColorAttrib *attrib);
   virtual void issue_tex_matrix(const TexMatrixAttrib *attrib);
   virtual void issue_texture(const TextureAttrib *attrib);
-  virtual void issue_light(const LightAttrib *attrib);
   virtual void issue_material(const MaterialAttrib *attrib);
   virtual void issue_render_mode(const RenderModeAttrib *attrib);
   virtual void issue_texture_apply(const TextureApplyAttrib *attrib);
@@ -180,7 +170,9 @@ public:
   //  virtual void issue_stencil(const StencilAttrib *attrib);
   //  virtual void issue_clip_plane(const ClipPlaneAttrib *attrib);
 
-  virtual void reset_frame();
+  virtual void bind_light(PointLight *light, int light_id);
+  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;
@@ -207,6 +199,12 @@ public:
   void issue_transformed_color(const Colorf &color) const;
 
 protected:
+  virtual void enable_lighting(bool enable);
+  virtual void set_ambient_light(const Colorf &color);
+  virtual void enable_light(int light_id, bool enable);
+  virtual void begin_bind_lights();
+  virtual void end_bind_lights();
+
   void free_pointers();
   virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
                                                  CPT(DisplayRegion) dr);
@@ -227,7 +225,6 @@ protected:
   INLINE void call_glCullFace(GLenum mode);
   INLINE void call_glScissor(GLint x, GLint y, GLsizei width, GLsizei height);
   INLINE void call_glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
-  INLINE void call_glLightModelAmbient(const Colorf& color);
   INLINE void call_glLightModelLocal(GLboolean local);
   INLINE void call_glLightModelTwoSide(GLboolean twoside);
   INLINE void call_glStencilFunc(GLenum func,GLint refval,GLuint mask);
@@ -249,8 +246,6 @@ protected:
   INLINE void enable_multisample(bool val);
   INLINE void enable_line_smooth(bool val);
   INLINE void enable_point_smooth(bool val);
-  INLINE void enable_lighting(bool val);
-  INLINE void enable_light(int light, bool val);
   INLINE void enable_texturing(bool val);
   INLINE void enable_scissor(bool val);
   INLINE void enable_dither(bool val);
@@ -314,7 +309,6 @@ protected:
   GLsizei _viewport_height;
   GLboolean _lmodel_local;
   GLboolean _lmodel_twoside;
-  Colorf _lmodel_ambient;
   Colorf _material_ambient;
   Colorf _material_diffuse;
   Colorf _material_specular;
@@ -343,8 +337,6 @@ protected:
   bool _line_smooth_enabled;
   bool _point_smooth_enabled;
   bool _scissor_enabled;
-  bool _lighting_enabled;
-  bool _lighting_enabled_this_frame;
   bool _texturing_enabled;
   bool _dither_enabled;
   bool _stencil_test_enabled;
@@ -358,16 +350,6 @@ protected:
   bool _polygon_offset_enabled;
   int _decal_level;
 
-  class LightInfo {
-  public:
-    INLINE LightInfo();
-    PT(Light) _light;
-    bool _enabled;
-    bool _next_enabled;
-  };
-
-  int _max_lights;
-  LightInfo *_light_info;          // LightInfo[_max_lights]
   int _cur_light_id;
 
   LMatrix4f _current_projection_mat;

+ 1 - 2
panda/src/glutdisplay/Sources.pp

@@ -9,8 +9,7 @@
 #begin lib_target
   #define TARGET glutdisplay
   #define LOCAL_LIBS \
-    glgsg display putil gobj gsgbase pnmimage mathutil graph sgraph \
-    light
+    glgsg display putil gobj gsgbase pnmimage mathutil graph sgraph
 
   #define SOURCES \
     config_glutdisplay.cxx config_glutdisplay.h glutGraphicsPipe.cxx \

+ 4 - 5
panda/src/gsgbase/graphicsStateGuardianBase.h

@@ -208,11 +208,6 @@ public:
   virtual void apply_material(const Material *material)=0;
   virtual void apply_fog(Fog *fog)=0;
 
-  virtual void apply_light(PointLight *light)=0;
-  virtual void apply_light(DirectionalLight *light)=0;
-  virtual void apply_light(Spotlight *light)=0;
-  virtual void apply_light(AmbientLight *light)=0;
-
   virtual void issue_transform(const TransformTransition *) { }
   virtual void issue_color_transform(const ColorMatrixTransition *) { }
   virtual void issue_alpha_transform(const AlphaTransformTransition *) { }
@@ -258,6 +253,10 @@ public:
   virtual void issue_stencil(const StencilAttrib *) { }
   virtual void issue_clip_plane(const ClipPlaneAttrib *) { }
 
+  virtual void bind_light(PointLight *light, int light_id) { }
+  virtual void bind_light(DirectionalLight *light, int light_id) { }
+  virtual void bind_light(Spotlight *light, int light_id) { }
+
 PUBLISHED:
   static TypeHandle get_class_type() {
     return _type_handle;

+ 0 - 56
panda/src/light/Sources.pp

@@ -1,56 +0,0 @@
-#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
-                   dtoolutil:c dtoolbase:c dtool:m
-
-#begin lib_target
-  #define TARGET light
-  #define LOCAL_LIBS \
-    putil display graph sgraph gobj sgattrib pnmimage mathutil gsgbase \
-    linmath
-    
-  #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx    
-  #define SOURCES \
-    ambientLight.I ambientLight.h \
-    config_light.h \
-    directionalLight.I directionalLight.h \
-    light.I light.h \
-    lightAttrib.I lightAttrib.h \
-    lightLensNode.I lightLensNode.h \
-    lightNode.I lightNode.h \
-    lightTransition.I lightTransition.h \
-    pointLight.I pointLight.h \
-    pt_Light.h \
-    spotlight.I spotlight.h \
-    vector_PT_Light.h 
-    
-  #define INCLUDED_SOURCES \
-    ambientLight.cxx \
-    config_light.cxx \
-    directionalLight.cxx \
-    light.cxx \
-    lightAttrib.cxx \
-    lightLensNode.cxx \
-    lightNode.cxx \
-    lightTransition.cxx \
-    pointLight.cxx \
-    pt_Light.cxx \
-    spotlight.cxx \
-    vector_PT_Light.cxx 
-
-  #define INSTALL_HEADERS \
-    ambientLight.I ambientLight.h \
-    directionalLight.I directionalLight.h \
-    light.I light.h \
-    lightAttrib.I lightAttrib.h \
-    lightLensNode.I lightLensNode.h \
-    lightNode.I lightNode.h \
-    lightNameClass.h \
-    lightTransition.I lightTransition.h \
-    pointLight.I pointLight.h \
-    pt_Light.h \
-    spotlight.I spotlight.h \
-    vector_PT_Light.h
-
-  #define IGATESCAN all
-
-#end lib_target
-

+ 0 - 1
panda/src/light/config_light.N

@@ -1 +0,0 @@
-forcetype MultiTransition<PT_Light, LightNameClass>

+ 0 - 51
panda/src/light/config_light.cxx

@@ -1,51 +0,0 @@
-// Filename: config_light.cxx
-// Created by:  drose (19Mar00)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
-//
-// All use of this software is subject to the terms of the Panda 3d
-// Software license.  You should have received a copy of this license
-// along with this source code; you will also find a current copy of
-// the license at http://www.panda3d.org/license.txt .
-//
-// To contact the maintainers of this program write to
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-#include "config_light.h"
-#include "ambientLight.h"
-#include "directionalLight.h"
-#include "light.h"
-#include "lightAttrib.h"
-#include "lightLensNode.h"
-#include "lightNode.h"
-#include "lightTransition.h"
-#include "pointLight.h"
-#include "spotlight.h"
-
-#include <dconfig.h>
-
-Configure(config_light);
-NotifyCategoryDef(light, "");
-
-ConfigureFn(config_light) {
-  AmbientLight::init_type();
-  DirectionalLight::init_type();
-  Light::init_type();
-  LightAttrib::init_type();
-  LightLensNode::init_type();
-  LightNode::init_type();
-  LightTransition::init_type();
-  PointLight::init_type();
-  Spotlight::init_type();
-
-  LightAttrib::register_with_read_factory();
-  AmbientLight::register_with_read_factory();
-  DirectionalLight::register_with_read_factory();
-  PointLight::register_with_read_factory();
-  Spotlight::register_with_read_factory();
-}

+ 0 - 27
panda/src/light/config_light.h

@@ -1,27 +0,0 @@
-// Filename: config_light.h
-// Created by:  drose (19Mar00)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
-//
-// All use of this software is subject to the terms of the Panda 3d
-// Software license.  You should have received a copy of this license
-// along with this source code; you will also find a current copy of
-// the license at http://www.panda3d.org/license.txt .
-//
-// To contact the maintainers of this program write to
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef CONFIG_LIGHT_H
-#define CONFIG_LIGHT_H
-
-#include <pandabase.h>
-#include <notifyCategoryProxy.h>
-
-NotifyCategoryDecl(light, EXPCL_PANDA, EXPTP_PANDA);
-
-#endif

+ 0 - 40
panda/src/light/lightNameClass.h

@@ -1,40 +0,0 @@
-// Filename: lightNameClass.h
-// Created by:  drose (24Mar00)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
-//
-// All use of this software is subject to the terms of the Panda 3d
-// Software license.  You should have received a copy of this license
-// along with this source code; you will also find a current copy of
-// the license at http://www.panda3d.org/license.txt .
-//
-// To contact the maintainers of this program write to
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef LIGHTNAMECLASS_H
-#define LIGHTNAMECLASS_H
-
-#include <pandabase.h>
-
-////////////////////////////////////////////////////////////////////
-//       Class : LightNameClass
-// Description : This is a stupid little class that's used by
-//               LightTransition to define the name of its
-//               PT(Light) class, so the MultiTransition it
-//               inherits from can initialize itself properly.
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDA LightNameClass {
-public:
-  static string get_class_name() {
-    return "PT(Light)";
-  }
-};
-
-#endif
-
-

+ 0 - 30
panda/src/light/lightTransition.I

@@ -1,30 +0,0 @@
-// Filename: lightTransition.I
-// Created by:  drose (24Mar00)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
-//
-// All use of this software is subject to the terms of the Panda 3d
-// Software license.  You should have received a copy of this license
-// along with this source code; you will also find a current copy of
-// the license at http://www.panda3d.org/license.txt .
-//
-// To contact the maintainers of this program write to
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////
-//     Function: LightTransition::all_off
-//       Access: Public
-//  Description: This named constructor returns a LightTransition
-//               that's preconfigured to disable all lights below it.
-////////////////////////////////////////////////////////////////////
-INLINE LightTransition LightTransition::
-all_off() {
-  LightTransition t;
-  t.set_default_dir(TD_off);
-  return t;
-}

+ 0 - 119
panda/src/light/lightTransition.cxx

@@ -1,119 +0,0 @@
-// Filename: lightTransition.cxx
-// Created by:  mike (06Feb99)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
-//
-// All use of this software is subject to the terms of the Panda 3d
-// Software license.  You should have received a copy of this license
-// along with this source code; you will also find a current copy of
-// the license at http://www.panda3d.org/license.txt .
-//
-// To contact the maintainers of this program write to
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-#include "lightTransition.h"
-
-#include <indent.h>
-
-TypeHandle LightTransition::_type_handle;
-
-
-////////////////////////////////////////////////////////////////////
-//     Function: LightTransition::Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-LightTransition::
-LightTransition() {
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: LightTransition::Copy Constructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-LightTransition::
-LightTransition(const LightTransition &copy) : MultiTransition<PT_Light, LightNameClass>(copy) {
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: LightTransition::Destructor
-//       Access: Public
-//  Description:
-////////////////////////////////////////////////////////////////////
-LightTransition::
-~LightTransition() {
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: LightTransition::make_copy
-//       Access: Public, Virtual
-//  Description: Returns a newly allocated LightTransition just like
-//               this one.
-////////////////////////////////////////////////////////////////////
-NodeTransition *LightTransition::
-make_copy() const {
-  return new LightTransition(*this);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: LightTransition::make_identity
-//       Access: Public, Virtual
-//  Description: Returns a newly allocated LightTransition in the
-//               initial state.
-////////////////////////////////////////////////////////////////////
-NodeTransition *LightTransition::
-make_identity() const {
-  return new LightTransition;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: LightTransition::make_initial
-//       Access: Public, Virtual
-//  Description: Returns a newly allocated LightTransition
-//               corresponding to the default initial state.
-////////////////////////////////////////////////////////////////////
-NodeTransition *LightTransition::
-make_initial() const {
-  return new LightTransition;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: LightTransition::issue
-//       Access: Public, Virtual
-//  Description: This is called on scene graph rendering attributes
-//               when it is time to issue the particular attribute to
-//               the graphics engine.  It should call the appropriate
-//               method on GraphicsStateGuardianBase.
-////////////////////////////////////////////////////////////////////
-void LightTransition::
-issue(GraphicsStateGuardianBase *gsgbase) {
-  gsgbase->issue_light(this);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: LightTransition::output_value
-//       Access: Protected, Virtual
-//  Description: Formats the value for human consumption on one line.
-////////////////////////////////////////////////////////////////////
-void LightTransition::
-output_property(ostream &out, const PT_Light &prop) const {
-  out << *prop;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: LightTransition::write_value
-//       Access: Protected, Virtual
-//  Description: Formats the value for human consumption on multiple
-//               lines if necessary.
-////////////////////////////////////////////////////////////////////
-void LightTransition::
-write_property(ostream &out, const PT_Light &prop,
-               int indent_level) const {
-  prop->write(out, indent_level);
-}

+ 0 - 86
panda/src/light/lightTransition.h

@@ -1,86 +0,0 @@
-// Filename: lightTransition.h
-// Created by:  mike (19Jan99)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
-//
-// All use of this software is subject to the terms of the Panda 3d
-// Software license.  You should have received a copy of this license
-// along with this source code; you will also find a current copy of
-// the license at http://www.panda3d.org/license.txt .
-//
-// To contact the maintainers of this program write to
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef LIGHTTRANSITION_H
-#define LIGHTTRANSITION_H
-
-#include <pandabase.h>
-
-#include "light.h"
-#include "pt_Light.h"
-#include "lightNameClass.h"
-
-#include <multiTransition.h>
-#include <pointerTo.h>
-
-// We need to define this temporary macro so we can pass a parameter
-// containing a comma through the macro.
-#define MULTITRANSITION_LIGHT MultiTransition<PT_Light, LightNameClass>
-EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, MULTITRANSITION_LIGHT);
-
-////////////////////////////////////////////////////////////////////
-//       Class : LightTransition
-// Description : The LightTransition allows specifying the set of
-//               lights that affect the geometry in the scene graph.
-//               If the set of lights is empty (e.g. under a
-//               LightTransition::all_off() transition), then lighting
-//               is disabled; otherwise, lighting is enabled with the
-//               indicated lights in effect.
-////////////////////////////////////////////////////////////////////
-class EXPCL_PANDA LightTransition : public MultiTransition<PT_Light, LightNameClass> {
-PUBLISHED:
-  LightTransition();
-  LightTransition(const LightTransition &copy);
-  ~LightTransition();
-  INLINE static LightTransition all_off();
-
-public:
-  virtual NodeTransition *make_copy() const;
-  virtual NodeTransition *make_identity() const;
-  virtual NodeTransition *make_initial() const;
-
-  virtual void issue(GraphicsStateGuardianBase *gsgbase);
-
-protected:
-  virtual void output_property(ostream &out, const PT_Light &prop) const;
-  virtual void write_property(ostream &out, const PT_Light &prop,
-                              int indent_level) const;
-
-public:
-  virtual TypeHandle get_type() const {
-    return get_class_type();
-  }
-  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
-  static TypeHandle get_class_type() {
-    return _type_handle;
-  }
-  static void init_type() {
-    MultiTransition<PT_Light, LightNameClass>::init_type();
-    register_type(_type_handle, "LightTransition",
-                  MultiTransition<PT_Light, LightNameClass>::get_class_type());
-  }
-
-private:
-  static TypeHandle _type_handle;
-};
-
-#include "lightTransition.I"
-
-#endif
-
-

+ 0 - 11
panda/src/light/light_composite1.cxx

@@ -1,11 +0,0 @@
-#include "light.cxx"
-#include "lightAttrib.cxx"
-#include "lightLensNode.cxx"
-#include "lightNode.cxx"
-#include "lightTransition.cxx"
-#include "pt_Light.cxx"
-#include "vector_PT_Light.cxx"
-
-
-
-

+ 0 - 7
panda/src/light/light_composite2.cxx

@@ -1,7 +0,0 @@
-#include "config_light.cxx"
-#include "ambientLight.cxx"
-#include "spotlight.cxx"
-#include "directionalLight.cxx"
-#include "pointLight.cxx"
-
-

+ 0 - 24
panda/src/light/pt_Light.cxx

@@ -1,24 +0,0 @@
-// Filename: pt_Light.cxx
-// Created by:  drose (16May00)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
-//
-// All use of this software is subject to the terms of the Panda 3d
-// Software license.  You should have received a copy of this license
-// along with this source code; you will also find a current copy of
-// the license at http://www.panda3d.org/license.txt .
-//
-// To contact the maintainers of this program write to
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-#include "pt_Light.h"
-
-// Tell GCC that we'll take care of the instantiation explicitly here.
-#ifdef __GNUC__
-#pragma implementation
-#endif

+ 0 - 47
panda/src/light/pt_Light.h

@@ -1,47 +0,0 @@
-// Filename: pt_Light.h
-// Created by:  drose (16May00)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
-//
-// All use of this software is subject to the terms of the Panda 3d
-// Software license.  You should have received a copy of this license
-// along with this source code; you will also find a current copy of
-// the license at http://www.panda3d.org/license.txt .
-//
-// To contact the maintainers of this program write to
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef PT_LIGHT_H
-#define PT_LIGHT_H
-
-#include <pandabase.h>
-
-#include "light.h"
-
-#include <pointerTo.h>
-
-////////////////////////////////////////////////////////////////////
-//       Class : PT_Light
-// Description : A PT(Light).  This is defined here solely we can
-//               explicitly export the template class.  It's not
-//               strictly necessary, but it doesn't hurt.
-////////////////////////////////////////////////////////////////////
-
-EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToBase<Light>)
-EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerTo<Light>)
-EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, ConstPointerTo<Light>)
-
-typedef PointerTo<Light> PT_Light;
-typedef ConstPointerTo<Light> CPT_Light;
-
-// Tell GCC that we'll take care of the instantiation explicitly here.
-#ifdef __GNUC__
-#pragma interface
-#endif
-
-#endif

+ 0 - 31
panda/src/light/vector_PT_Light.cxx

@@ -1,31 +0,0 @@
-// Filename: vector_PT_Light.cxx
-// Created by:  drose (16May00)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
-//
-// All use of this software is subject to the terms of the Panda 3d
-// Software license.  You should have received a copy of this license
-// along with this source code; you will also find a current copy of
-// the license at http://www.panda3d.org/license.txt .
-//
-// To contact the maintainers of this program write to
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-#include "vector_PT_Light.h"
-
-#define EXPCL EXPCL_PANDA
-#define EXPTP EXPTP_PANDA
-#define TYPE PT_Light
-#define NAME vector_PT_Light
-
-#include <vector_src.cxx>
-
-// Tell GCC that we'll take care of the instantiation explicitly here.
-#ifdef __GNUC__
-#pragma implementation
-#endif

+ 0 - 49
panda/src/light/vector_PT_Light.h

@@ -1,49 +0,0 @@
-// Filename: vector_PT_Light.h
-// Created by:  drose (16May00)
-//
-////////////////////////////////////////////////////////////////////
-//
-// PANDA 3D SOFTWARE
-// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
-//
-// All use of this software is subject to the terms of the Panda 3d
-// Software license.  You should have received a copy of this license
-// along with this source code; you will also find a current copy of
-// the license at http://www.panda3d.org/license.txt .
-//
-// To contact the maintainers of this program write to
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-#ifndef VECTOR_PT_LIGHT_H
-#define VECTOR_PT_LIGHT_H
-
-#include <pandabase.h>
-
-#include "pt_Light.h"
-
-#include "pvector.h"
-
-////////////////////////////////////////////////////////////////////
-//       Class : vector_PT_Light
-// Description : A vector of PT(Light)'s.  This class is defined once
-//               here, and exported to PANDA.DLL; other packages that
-//               want to use a vector of this type (whether they need
-//               to export it or not) should include this header file,
-//               rather than defining the vector again.
-////////////////////////////////////////////////////////////////////
-
-#define EXPCL EXPCL_PANDA
-#define EXPTP EXPTP_PANDA
-#define TYPE PT_Light
-#define NAME vector_PT_Light
-
-#include <vector_src.h>
-
-// Tell GCC that we'll take care of the instantiation explicitly here.
-#ifdef __GNUC__
-#pragma interface
-#endif
-
-#endif

+ 25 - 1
panda/src/pgraph/Sources.pp

@@ -6,6 +6,7 @@
   #define TARGET pgraph
   
   #define SOURCES \
+    ambientLight.I ambientLight.h \
     billboardEffect.I billboardEffect.h \
     binCullHandler.I binCullHandler.h \
     qpcamera.I qpcamera.h \
@@ -28,6 +29,7 @@
     depthOffsetAttrib.I depthOffsetAttrib.h \
     depthTestAttrib.I depthTestAttrib.h \
     depthWriteAttrib.I depthWriteAttrib.h \
+    directionalLight.I directionalLight.h \
     drawCullHandler.I drawCullHandler.h \
     qpfindApproxLevel.I qpfindApproxLevel.h \
     qpfindApproxLevelEntry.I qpfindApproxLevelEntry.h \
@@ -37,6 +39,10 @@
     qpgeomNode.I qpgeomNode.h \
     qpgeomTransformer.I qpgeomTransformer.h \
     qplensNode.I qplensNode.h \
+    light.I light.h \
+    lightAttrib.I lightAttrib.h \
+    lightLensNode.I lightLensNode.h \
+    lightNode.I lightNode.h \
     qplodNode.I qplodNode.h \
     materialAttrib.I materialAttrib.h \
     qpmodelNode.I qpmodelNode.h \
@@ -46,6 +52,7 @@
     qpnodePathComponent.I qpnodePathComponent.h \
     qpnodePathLerps.h \
     pandaNode.I pandaNode.h \
+    pointLight.I pointLight.h \
     renderAttrib.I renderAttrib.h \
     renderEffect.I renderEffect.h \
     renderEffects.I renderEffects.h \
@@ -56,6 +63,7 @@
     selectiveChildNode.I selectiveChildNode.h \
     qpsequenceNode.I qpsequenceNode.h \
     showBoundsEffect.I showBoundsEffect.h \
+    spotlight.I spotlight.h \
     texMatrixAttrib.I texMatrixAttrib.h \
     textureApplyAttrib.I textureApplyAttrib.h \
     textureAttrib.I textureAttrib.h \
@@ -64,8 +72,9 @@
     transparencyAttrib.I transparencyAttrib.h \
     workingNodePath.I workingNodePath.h
 
-  #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx    
+  #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx
   #define INCLUDED_SOURCES \
+    ambientLight.cxx \
     billboardEffect.cxx \
     binCullHandler.cxx \
     qpcamera.cxx \
@@ -88,6 +97,7 @@
     depthOffsetAttrib.cxx \
     depthTestAttrib.cxx \
     depthWriteAttrib.cxx \
+    directionalLight.cxx \
     drawCullHandler.cxx \
     qpfindApproxLevel.cxx \
     qpfindApproxLevelEntry.cxx \
@@ -97,6 +107,10 @@
     qpgeomNode.cxx \
     qpgeomTransformer.cxx \
     qplensNode.cxx \
+    light.cxx \
+    lightAttrib.cxx \
+    lightLensNode.cxx \
+    lightNode.cxx \
     qplodNode.cxx \
     materialAttrib.cxx \
     qpmodelNode.cxx \
@@ -106,6 +120,7 @@
     qpnodePathComponent.cxx \
     qpnodePathLerps.cxx \
     pandaNode.cxx \
+    pointLight.cxx \
     renderAttrib.cxx \
     renderEffect.cxx \
     renderEffects.cxx \
@@ -116,6 +131,7 @@
     selectiveChildNode.cxx \
     qpsequenceNode.cxx \
     showBoundsEffect.cxx \
+    spotlight.cxx \
     texMatrixAttrib.cxx \
     textureApplyAttrib.cxx \
     textureAttrib.cxx \
@@ -131,6 +147,7 @@
   #endif
 
   #define INSTALL_HEADERS \
+    ambientLight.I ambientLight.h \
     billboardEffect.I billboardEffect.h \
     binCullHandler.I binCullHandler.h \
     qpcamera.I qpcamera.h \
@@ -153,12 +170,17 @@
     depthOffsetAttrib.I depthOffsetAttrib.h \
     depthTestAttrib.I depthTestAttrib.h \
     depthWriteAttrib.I depthWriteAttrib.h \
+    directionalLight.I directionalLight.h \
     drawCullHandler.I drawCullHandler.h \
     qpfog.I qpfog.h \
     fogAttrib.I fogAttrib.h \
     qpgeomNode.I qpgeomNode.h \
     qpgeomTransformer.I qpgeomTransformer.h \
     qplensNode.I qplensNode.h \
+    light.I light.h \
+    lightAttrib.I lightAttrib.h \
+    lightLensNode.I lightLensNode.h \
+    lightNode.I lightNode.h \
     qplodNode.I qplodNode.h \
     materialAttrib.I materialAttrib.h \
     qpmodelNode.I qpmodelNode.h \
@@ -168,6 +190,7 @@
     qpnodePathComponent.I qpnodePathComponent.h \
     qpnodePathLerps.h \
     pandaNode.I pandaNode.h \
+    pointLight.I pointLight.h \
     renderAttrib.I renderAttrib.h \
     renderEffect.I renderEffect.h \
     renderEffects.I renderEffects.h \
@@ -178,6 +201,7 @@
     selectiveChildNode.I selectiveChildNode.h \
     qpsequenceNode.I qpsequenceNode.h \
     showBoundsEffect.I showBoundsEffect.h \
+    spotlight.I spotlight.h \
     texMatrixAttrib.I texMatrixAttrib.h \
     textureApplyAttrib.I textureApplyAttrib.h \
     textureAttrib.I textureAttrib.h \

+ 0 - 0
panda/src/light/ambientLight.I → panda/src/pgraph/ambientLight.I


+ 5 - 4
panda/src/light/ambientLight.cxx → panda/src/pgraph/ambientLight.cxx

@@ -17,7 +17,6 @@
 ////////////////////////////////////////////////////////////////////
 
 #include "ambientLight.h"
-#include "graphicsStateGuardian.h"
 #include "bamWriter.h"
 #include "bamReader.h"
 #include "datagram.h"
@@ -76,13 +75,15 @@ write(ostream &out, int indent_level) const {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: AmbientLight::apply
+//     Function: AmbientLight::bind
 //       Access: Public, Virtual
 //  Description:
 ////////////////////////////////////////////////////////////////////
 void AmbientLight::
-apply(GraphicsStateGuardian *gsg) {
-  gsg->apply_light(this);
+bind(GraphicsStateGuardianBase *, int) {
+  // AmbientLights aren't bound to light id's; this function should
+  // never be called.
+  nassertv(false);
 }
 
 ////////////////////////////////////////////////////////////////////

+ 1 - 1
panda/src/light/ambientLight.h → panda/src/pgraph/ambientLight.h

@@ -42,7 +42,7 @@ public:
   virtual void write(ostream &out, int indent_level) const;
   
 public:
-  virtual void apply(GraphicsStateGuardian *gsg);
+  virtual void bind(GraphicsStateGuardianBase *gsg, int light_id);
 
 public:
   static void register_with_read_factory();

+ 22 - 1
panda/src/pgraph/config_pgraph.cxx

@@ -18,6 +18,7 @@
 
 #include "config_pgraph.h"
 
+#include "ambientLight.h"
 #include "billboardEffect.h"
 #include "qpcamera.h"
 #include "colorAttrib.h"
@@ -34,10 +35,15 @@
 #include "depthOffsetAttrib.h"
 #include "depthTestAttrib.h"
 #include "depthWriteAttrib.h"
+#include "directionalLight.h"
 #include "qpfog.h"
 #include "fogAttrib.h"
 #include "qpgeomNode.h"
 #include "qplensNode.h"
+#include "light.h"
+#include "lightAttrib.h"
+#include "lightLensNode.h"
+#include "lightNode.h"
 #include "qplodNode.h"
 #include "materialAttrib.h"
 #include "qpmodelNode.h"
@@ -45,6 +51,7 @@
 #include "qpnodePath.h"
 #include "qpnodePathComponent.h"
 #include "pandaNode.h"
+#include "pointLight.h"
 #include "renderAttrib.h"
 #include "renderEffect.h"
 #include "renderEffects.h"
@@ -53,6 +60,7 @@
 #include "selectiveChildNode.h"
 #include "qpsequenceNode.h"
 #include "showBoundsEffect.h"
+#include "spotlight.h"
 #include "texMatrixAttrib.h"
 #include "textureApplyAttrib.h"
 #include "textureAttrib.h"
@@ -95,6 +103,7 @@ init_libpgraph() {
   }
   initialized = true;
 
+  AmbientLight::init_type();
   BillboardEffect::init_type();
   qpCamera::init_type();
   ColorAttrib::init_type();
@@ -111,10 +120,15 @@ init_libpgraph() {
   DepthOffsetAttrib::init_type();
   DepthTestAttrib::init_type();
   DepthWriteAttrib::init_type();
+  DirectionalLight::init_type();
   qpFog::init_type();
   FogAttrib::init_type();
   qpGeomNode::init_type();
   qpLensNode::init_type();
+  Light::init_type();
+  LightAttrib::init_type();
+  LightLensNode::init_type();
+  LightNode::init_type();
   qpLODNode::init_type();
   MaterialAttrib::init_type();
   qpModelNode::init_type();
@@ -122,6 +136,7 @@ init_libpgraph() {
   qpNodePath::init_type();
   qpNodePathComponent::init_type();
   PandaNode::init_type();
+  PointLight::init_type();
   RenderAttrib::init_type();
   RenderEffect::init_type();
   RenderEffects::init_type();
@@ -130,6 +145,7 @@ init_libpgraph() {
   SelectiveChildNode::init_type();
   qpSequenceNode::init_type();
   ShowBoundsEffect::init_type();
+  Spotlight::init_type();
   TexMatrixAttrib::init_type();
   TextureApplyAttrib::init_type();
   TextureAttrib::init_type();
@@ -144,6 +160,7 @@ init_libpgraph() {
   qpColorLerpFunctor::init_type();
   qpColorScaleLerpFunctor::init_type();
 
+  AmbientLight::register_with_read_factory();
   BillboardEffect::register_with_read_factory();
   qpCamera::register_with_read_factory();
   ColorAttrib::register_with_read_factory();
@@ -155,20 +172,24 @@ init_libpgraph() {
   DepthOffsetAttrib::register_with_read_factory();
   DepthTestAttrib::register_with_read_factory();
   DepthWriteAttrib::register_with_read_factory();
+  DirectionalLight::register_with_read_factory();
   qpFog::register_with_read_factory();
   FogAttrib::register_with_read_factory();
   qpGeomNode::register_with_read_factory();
   qpLensNode::register_with_read_factory();
+  LightAttrib::register_with_read_factory();
   qpLODNode::register_with_read_factory();
-  MaterialAttrib::register_with_read_factory();
+  MaterialAttrib::register_with_read_factory();  
   qpModelNode::register_with_read_factory();
   qpModelRoot::register_with_read_factory();
   PandaNode::register_with_read_factory();
+  PointLight::register_with_read_factory();
   RenderEffects::register_with_read_factory();
   RenderModeAttrib::register_with_read_factory();
   RenderState::register_with_read_factory();
   qpSequenceNode::register_with_read_factory();
   ShowBoundsEffect::register_with_read_factory();
+  Spotlight::register_with_read_factory();
   TexMatrixAttrib::register_with_read_factory();
   TextureApplyAttrib::register_with_read_factory();
   TextureAttrib::register_with_read_factory();

+ 0 - 0
panda/src/light/directionalLight.I → panda/src/pgraph/directionalLight.I


+ 4 - 4
panda/src/light/directionalLight.cxx → panda/src/pgraph/directionalLight.cxx

@@ -17,7 +17,7 @@
 ////////////////////////////////////////////////////////////////////
 
 #include "directionalLight.h"
-#include "graphicsStateGuardian.h"
+#include "graphicsStateGuardianBase.h"
 #include "bamWriter.h"
 #include "bamReader.h"
 #include "datagram.h"
@@ -134,13 +134,13 @@ write(ostream &out, int indent_level) const {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: DirectionalLight::apply
+//     Function: DirectionalLight::bind
 //       Access: Public, Virtual
 //  Description:
 ////////////////////////////////////////////////////////////////////
 void DirectionalLight::
-apply(GraphicsStateGuardian *gsg) {
-  gsg->apply_light(this);
+bind(GraphicsStateGuardianBase *gsg, int light_id) {
+  gsg->bind_light(this, light_id);
 }
 
 ////////////////////////////////////////////////////////////////////

+ 1 - 1
panda/src/light/directionalLight.h → panda/src/pgraph/directionalLight.h

@@ -51,7 +51,7 @@ PUBLISHED:
   INLINE void set_direction(const LVector3f &direction);
   
 public:
-  virtual void apply(GraphicsStateGuardian *gsg);
+  virtual void bind(GraphicsStateGuardianBase *gsg, int light_id);
 
 private:
   // This is the data that must be cycled between pipeline stages.

+ 0 - 0
panda/src/light/light.I → panda/src/pgraph/light.I


+ 0 - 0
panda/src/light/light.cxx → panda/src/pgraph/light.cxx


+ 2 - 2
panda/src/light/light.h → panda/src/pgraph/light.h

@@ -30,7 +30,7 @@
 #include "qpgeomNode.h"
 
 class PandaNode;
-class GraphicsStateGuardian;
+class GraphicsStateGuardianBase;
 
 ////////////////////////////////////////////////////////////////////
 //       Class : Light
@@ -58,7 +58,7 @@ PUBLISHED:
 public:
   virtual void output(ostream &out) const=0;
   virtual void write(ostream &out, int indent_level) const=0;
-  virtual void apply(GraphicsStateGuardian *gsg)=0;
+  virtual void bind(GraphicsStateGuardianBase *gsg, int light_id)=0;
 
   qpGeomNode *get_viz();
 

+ 0 - 0
panda/src/light/lightAttrib.I → panda/src/pgraph/lightAttrib.I


+ 0 - 0
panda/src/light/lightAttrib.cxx → panda/src/pgraph/lightAttrib.cxx


+ 0 - 0
panda/src/light/lightAttrib.h → panda/src/pgraph/lightAttrib.h


+ 0 - 0
panda/src/light/lightLensNode.I → panda/src/pgraph/lightLensNode.I


+ 0 - 0
panda/src/light/lightLensNode.cxx → panda/src/pgraph/lightLensNode.cxx


+ 0 - 0
panda/src/light/lightLensNode.h → panda/src/pgraph/lightLensNode.h


+ 0 - 0
panda/src/light/lightNode.I → panda/src/pgraph/lightNode.I


+ 0 - 0
panda/src/light/lightNode.cxx → panda/src/pgraph/lightNode.cxx


+ 0 - 0
panda/src/light/lightNode.h → panda/src/pgraph/lightNode.h


+ 9 - 0
panda/src/pgraph/pgraph_composite1.cxx

@@ -1,3 +1,4 @@
+#include "ambientLight.cxx"
 #include "billboardEffect.cxx"
 #include "binCullHandler.cxx"
 #include "qpcamera.cxx"
@@ -20,4 +21,12 @@
 #include "depthOffsetAttrib.cxx"
 #include "depthTestAttrib.cxx"
 #include "depthWriteAttrib.cxx"
+#include "directionalLight.cxx"
 #include "drawCullHandler.cxx"
+#include "qpfindApproxPath.cxx"
+#include "qpfindApproxLevel.cxx"
+#include "qpfindApproxLevelEntry.cxx"
+#include "qpfog.cxx"
+#include "fogAttrib.cxx"
+#include "qpgeomNode.cxx"
+#include "qpgeomTransformer.cxx"

+ 6 - 7
panda/src/pgraph/pgraph_composite2.cxx

@@ -1,11 +1,8 @@
-#include "qpfindApproxPath.cxx"
-#include "qpfindApproxLevel.cxx"
-#include "qpfindApproxLevelEntry.cxx"
-#include "qpfog.cxx"
-#include "fogAttrib.cxx"
-#include "qpgeomNode.cxx"
-#include "qpgeomTransformer.cxx"
 #include "qplensNode.cxx"
+#include "light.cxx"
+#include "lightAttrib.cxx"
+#include "lightLensNode.cxx"
+#include "lightNode.cxx"
 #include "qplodNode.cxx"
 #include "materialAttrib.cxx"
 #include "qpmodelNode.cxx"
@@ -14,6 +11,7 @@
 #include "qpnodePathComponent.cxx"
 #include "qpnodePathLerps.cxx"
 #include "pandaNode.cxx"
+#include "pointLight.cxx"
 #include "renderAttrib.cxx"
 #include "renderEffect.cxx"
 #include "renderEffects.cxx"
@@ -23,6 +21,7 @@
 #include "selectiveChildNode.cxx"
 #include "qpsequenceNode.cxx"
 #include "showBoundsEffect.cxx"
+#include "spotlight.cxx"
 #include "test_pgraph.cxx"
 #include "texMatrixAttrib.cxx"
 #include "textureApplyAttrib.cxx"

+ 0 - 0
panda/src/light/pointLight.I → panda/src/pgraph/pointLight.I


+ 4 - 4
panda/src/light/pointLight.cxx → panda/src/pgraph/pointLight.cxx

@@ -17,7 +17,7 @@
 ////////////////////////////////////////////////////////////////////
 
 #include "pointLight.h"
-#include "graphicsStateGuardian.h"
+#include "graphicsStateGuardianBase.h"
 #include "bamWriter.h"
 #include "bamReader.h"
 #include "datagram.h"
@@ -133,13 +133,13 @@ write(ostream &out, int indent_level) const {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: PointLight::apply
+//     Function: PointLight::bind
 //       Access: Public, Virtual
 //  Description:
 ////////////////////////////////////////////////////////////////////
 void PointLight::
-apply(GraphicsStateGuardian *gsg) {
-  gsg->apply_light(this);
+bind(GraphicsStateGuardianBase *gsg, int light_id) {
+  gsg->bind_light(this, light_id);
 }
 
 ////////////////////////////////////////////////////////////////////

+ 1 - 1
panda/src/light/pointLight.h → panda/src/pgraph/pointLight.h

@@ -51,7 +51,7 @@ PUBLISHED:
   INLINE void set_point(const LPoint3f &point);
   
 public:
-  virtual void apply(GraphicsStateGuardian *gsg);
+  virtual void bind(GraphicsStateGuardianBase *gsg, int light_id);
 
 private:
   // This is the data that must be cycled between pipeline stages.

+ 4 - 0
panda/src/pgraph/qplensNode.cxx

@@ -18,6 +18,10 @@
 
 #include "qplensNode.h"
 #include "geometricBoundingVolume.h"
+#include "bamWriter.h"
+#include "bamReader.h"
+#include "datagram.h"
+#include "datagramIterator.h"
 
 TypeHandle qpLensNode::_type_handle;
 

+ 0 - 0
panda/src/light/spotlight.I → panda/src/pgraph/spotlight.I


+ 7 - 26
panda/src/light/spotlight.cxx → panda/src/pgraph/spotlight.cxx

@@ -17,12 +17,13 @@
 ////////////////////////////////////////////////////////////////////
 
 #include "spotlight.h"
-#include "graphicsStateGuardian.h"
+#include "graphicsStateGuardianBase.h"
 #include "bamWriter.h"
 #include "bamReader.h"
 #include "datagram.h"
 #include "datagramIterator.h"
 #include "colorAttrib.h"
+#include "config_pgraph.h"
 
 TypeHandle Spotlight::_type_handle;
 
@@ -72,26 +73,6 @@ Spotlight::
 Spotlight(const string &name) : 
   LightLensNode(name) 
 {
-  cerr << "Creating " << *this << ", this = " << (int)this
-       << " node this = " << (int)(PandaNode *)this 
-       << " light this = " << (int)(Light *)this 
-       << " bounded this = " << (int)(BoundedObject *)this << "\n";
-  _internal_bound.get_bound();
-  cerr << "got bound 1\n";
-  get_internal_bound();
-  cerr << "got bound 2\n";
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: Spotlight::foo
-//       Access: Published
-//  Description:
-////////////////////////////////////////////////////////////////////
-void Spotlight::
-foo() {
-  cerr << "checking bound\n";
-  get_internal_bound();
-  cerr << "done\n";
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -159,13 +140,13 @@ write(ostream &out, int indent_level) const {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: Spotlight::apply
+//     Function: Spotlight::bind
 //       Access: Public, Virtual
 //  Description:
 ////////////////////////////////////////////////////////////////////
 void Spotlight::
-apply(GraphicsStateGuardian *gsg) {
-  gsg->apply_light(this);
+bind(GraphicsStateGuardianBase *gsg, int light_id) {
+  gsg->bind_light(this, light_id);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -185,14 +166,14 @@ apply(GraphicsStateGuardian *gsg) {
 bool Spotlight::
 make_image(Texture *texture, float radius) {
   if (texture == NULL) {
-    light_cat.error()
+    pgraph_cat.error()
       << "Spotlight::make_image() - NULL texture" << endl;
     return false;
   }
   PixelBuffer *pb = texture->_pbuffer;
   int size = pb->get_xsize();
   if (size == 0) {
-    light_cat.error()
+    pgraph_cat.error()
       << "Spotlight::make_image() - pixel buffer has size == 0" << endl;
     return false;
   }

+ 1 - 2
panda/src/light/spotlight.h → panda/src/pgraph/spotlight.h

@@ -40,7 +40,6 @@
 class EXPCL_PANDA Spotlight : public LightLensNode {
 PUBLISHED:
   Spotlight(const string &name);
-  void foo();
 
 protected:
   Spotlight(const Spotlight &copy);
@@ -61,7 +60,7 @@ PUBLISHED:
   INLINE void set_attenuation(const LVecBase3f &attenuation);
   
 public:
-  virtual void apply(GraphicsStateGuardian *gsg);
+  virtual void bind(GraphicsStateGuardianBase *gsg, int light_id);
 
   bool make_image(Texture *texture, float radius);
 

+ 1 - 1
panda/src/ps2gsg/Sources.pp

@@ -6,7 +6,7 @@
 #begin lib_target
   #define TARGET ps2gsg
   #define LOCAL_LIBS \
-    cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display light \
+    cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display \
     putil linmath sgraph mathutil pnmimage
 
   #define SOURCES \

+ 1 - 1
panda/src/ribgsg/Sources.pp

@@ -6,7 +6,7 @@
 #begin lib_target
   #define TARGET ribgsg
   #define LOCAL_LIBS \
-    gsgmisc display gobj sgattrib sgraph sgraphutil light
+    gsgmisc display gobj sgattrib sgraph sgraphutil
 
   #define SOURCES \
     config_ribgsg.cxx config_ribgsg.h ribGraphicsStateGuardian.I \

+ 1 - 1
panda/src/testbed/Sources.pp

@@ -4,7 +4,7 @@
 #define LOCAL_LIBS \
     framework putil collide loader sgmanip chan text chancfg cull \
     pnmimage pnmimagetypes event effects graph gobj display \
-    mathutil sgattrib putil express light dgraph device tform sgraph \
+    mathutil sgattrib putil express dgraph device tform sgraph \
     linmath sgraphutil pstatclient panda
 
 #if $[LINK_ALL_STATIC]

+ 0 - 5
panda/src/testbed/demo.cxx

@@ -29,7 +29,6 @@
 #include "depthWriteTransition.h"
 #include "textureTransition.h"
 #include "textureApplyTransition.h"
-#include "lightTransition.h"
 #include "materialTransition.h"
 #include "transformTransition.h"
 #include "transparencyTransition.h"
@@ -298,20 +297,16 @@ enable_highlight() {
       new CullFaceTransition(CullFaceProperty::M_cull_none);
     TextureTransition *tt =
       new TextureTransition;
-    LightTransition *lt =
-      new LightTransition;
 
     rmt->set_priority(100);
     ct->set_priority(100);
     cft->set_priority(100);
     tt->set_priority(100);
-    lt->set_priority(100);
 
     highlight_arc->set_transition(rmt);
     highlight_arc->set_transition(ct);
     highlight_arc->set_transition(cft);
     highlight_arc->set_transition(tt);
-    highlight_arc->set_transition(lt);
   }
 
   // Add a temporary arc from the highlight render node to the node we