Browse Source

Added per-pixel lighting support

Josh Yelon 18 years ago
parent
commit
ef0189651e

+ 10 - 0
panda/src/framework/pandaFramework.I

@@ -143,6 +143,16 @@ get_lighting() const {
   return _lighting_enabled;
   return _lighting_enabled;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PandaFramework::get_perpixel
+//       Access: Public
+//  Description: Returns the current state of the perpixel flag.
+////////////////////////////////////////////////////////////////////
+INLINE bool PandaFramework::
+get_perpixel() const {
+  return _perpixel_enabled;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PandaFramework::get_background_type
 //     Function: PandaFramework::get_background_type
 //       Access: Public
 //       Access: Public

+ 34 - 0
panda/src/framework/pandaFramework.cxx

@@ -377,6 +377,7 @@ open_window(const WindowProperties &props, GraphicsPipe *pipe,
   wf->set_texture(get_texture());
   wf->set_texture(get_texture());
   wf->set_two_sided(get_two_sided());
   wf->set_two_sided(get_two_sided());
   wf->set_lighting(get_lighting());
   wf->set_lighting(get_lighting());
+  wf->set_perpixel(get_perpixel());
   wf->set_background_type(get_background_type());
   wf->set_background_type(get_background_type());
 
 
   GraphicsWindow *win = wf->open_window(props, get_graphics_engine(), 
   GraphicsWindow *win = wf->open_window(props, get_graphics_engine(), 
@@ -617,6 +618,22 @@ set_lighting(bool enable) {
   _lighting_enabled = enable;
   _lighting_enabled = enable;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PandaFramework::set_perpixel
+//       Access: Public
+//  Description: Sets the perpixel state on all windows.
+////////////////////////////////////////////////////////////////////
+void PandaFramework::
+set_perpixel(bool enable) {
+  Windows::iterator wi;
+  for (wi = _windows.begin(); wi != _windows.end(); ++wi) {
+    WindowFramework *wf = (*wi);
+    wf->set_perpixel(enable);
+  }
+
+  _perpixel_enabled = enable;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: BackgroundFramework::set_background_type
 //     Function: BackgroundFramework::set_background_type
 //       Access: Public
 //       Access: Public
@@ -843,6 +860,7 @@ do_enable_default_keys() {
   define_key("b", "toggle backface (double-sided) rendering", event_b, this);
   define_key("b", "toggle backface (double-sided) rendering", event_b, this);
   define_key("i", "invert (reverse) single-sided faces", event_i, this);
   define_key("i", "invert (reverse) single-sided faces", event_i, this);
   define_key("l", "toggle lighting", event_l, this);
   define_key("l", "toggle lighting", event_l, this);
+  define_key("p", "toggle per-pixel lighting", event_p, this);
   define_key("c", "recenter view on object", event_c, this);
   define_key("c", "recenter view on object", event_c, this);
   define_key("a", "toggle animation controls", event_a, this);
   define_key("a", "toggle animation controls", event_a, this);
   define_key("shift-c", "toggle collision surfaces", event_C, this);
   define_key("shift-c", "toggle collision surfaces", event_C, this);
@@ -1017,6 +1035,22 @@ event_l(const Event *event, void *) {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PandaFramework::event_p
+//       Access: Public, Static
+//  Description: Default handler for p key: toggle per-pixel lighting.
+////////////////////////////////////////////////////////////////////
+void PandaFramework::
+event_p(const Event *event, void *) {
+  if (event->get_num_parameters() == 1) {
+    EventParameter param = event->get_parameter(0);
+    WindowFramework *wf;
+    DCAST_INTO_V(wf, param.get_ptr());
+
+    wf->set_perpixel(!wf->get_perpixel());
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PandaFramework::event_c
 //     Function: PandaFramework::event_c
 //       Access: Public, Static
 //       Access: Public, Static

+ 4 - 0
panda/src/framework/pandaFramework.h

@@ -87,12 +87,14 @@ public:
   void set_texture(bool enable);
   void set_texture(bool enable);
   void set_two_sided(bool enable);
   void set_two_sided(bool enable);
   void set_lighting(bool enable);
   void set_lighting(bool enable);
+  void set_perpixel(bool enable);
   void set_background_type(WindowFramework::BackgroundType type);
   void set_background_type(WindowFramework::BackgroundType type);
 
 
   INLINE bool get_wireframe() const;
   INLINE bool get_wireframe() const;
   INLINE bool get_texture() const;
   INLINE bool get_texture() const;
   INLINE bool get_two_sided() const;
   INLINE bool get_two_sided() const;
   INLINE bool get_lighting() const;
   INLINE bool get_lighting() const;
+  INLINE bool get_perpixel() const;
   INLINE WindowFramework::BackgroundType get_background_type() const;
   INLINE WindowFramework::BackgroundType get_background_type() const;
 
 
   static int hide_collision_solids(NodePath node);
   static int hide_collision_solids(NodePath node);
@@ -131,6 +133,7 @@ public:
   static void event_b(const Event *, void *data);
   static void event_b(const Event *, void *data);
   static void event_i(const Event *, void *data);
   static void event_i(const Event *, void *data);
   static void event_l(const Event *, void *data);
   static void event_l(const Event *, void *data);
+  static void event_p(const Event *, void *data);
   static void event_c(const Event *, void *data);
   static void event_c(const Event *, void *data);
   static void event_a(const Event *, void *data);
   static void event_a(const Event *, void *data);
   static void event_C(const Event *, void *data);
   static void event_C(const Event *, void *data);
@@ -177,6 +180,7 @@ private:
   bool _texture_enabled;
   bool _texture_enabled;
   bool _two_sided_enabled;
   bool _two_sided_enabled;
   bool _lighting_enabled;
   bool _lighting_enabled;
+  bool _perpixel_enabled;
   WindowFramework::BackgroundType _background_type;
   WindowFramework::BackgroundType _background_type;
 
 
   NodePath _highlight;
   NodePath _highlight;

+ 10 - 0
panda/src/framework/windowFramework.I

@@ -123,6 +123,16 @@ get_lighting() const {
   return _lighting_enabled;
   return _lighting_enabled;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: WindowFramework::get_perpixel
+//       Access: Public
+//  Description: Returns the current state of the perpixel flag.
+////////////////////////////////////////////////////////////////////
+INLINE bool WindowFramework::
+get_perpixel() const {
+  return _perpixel_enabled;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: WindowFramework::get_background_type
 //     Function: WindowFramework::get_background_type
 //       Access: Public
 //       Access: Public

+ 25 - 0
panda/src/framework/windowFramework.cxx

@@ -97,6 +97,7 @@ WindowFramework(PandaFramework *panda_framework) :
   _two_sided_enabled = false;
   _two_sided_enabled = false;
   _one_sided_reverse_enabled = false;
   _one_sided_reverse_enabled = false;
   _lighting_enabled = false;
   _lighting_enabled = false;
+  _perpixel_enabled = false;
   _background_type = BT_default;
   _background_type = BT_default;
 }
 }
 
 
@@ -123,6 +124,7 @@ WindowFramework(const WindowFramework &copy, DisplayRegion *display_region) :
   _two_sided_enabled = false;
   _two_sided_enabled = false;
   _one_sided_reverse_enabled = false;
   _one_sided_reverse_enabled = false;
   _lighting_enabled = false;
   _lighting_enabled = false;
+  _perpixel_enabled = false;
   _background_type = BT_default;
   _background_type = BT_default;
 
 
   set_background_type(copy._background_type);
   set_background_type(copy._background_type);
@@ -223,6 +225,7 @@ close_window() {
   _two_sided_enabled = false;
   _two_sided_enabled = false;
   _one_sided_reverse_enabled = false;
   _one_sided_reverse_enabled = false;
   _lighting_enabled = false;
   _lighting_enabled = false;
+  _perpixel_enabled = false;
 
 
   if (_frame_rate_meter != (FrameRateMeter *)NULL) {
   if (_frame_rate_meter != (FrameRateMeter *)NULL) {
     _frame_rate_meter->clear_window();
     _frame_rate_meter->clear_window();
@@ -966,6 +969,28 @@ set_lighting(bool enable) {
   _lighting_enabled = enable;
   _lighting_enabled = enable;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: WindowFramework::set_perpixel
+//       Access: Public
+//  Description: Turns per-pixel lighting on (true) or off (false).
+////////////////////////////////////////////////////////////////////
+void WindowFramework::
+set_perpixel(bool enable) {
+  if (enable == _perpixel_enabled) {
+    return;
+  }
+
+  NodePath render = get_render();
+
+  if (enable) {
+    render.set_shader_auto();
+  } else {
+    render.set_shader_off();
+  }
+
+  _perpixel_enabled = enable;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: WindowFramework::set_background_type
 //     Function: WindowFramework::set_background_type
 //       Access: Public
 //       Access: Public

+ 3 - 0
panda/src/framework/windowFramework.h

@@ -120,6 +120,7 @@ public:
   void set_two_sided(bool enable);
   void set_two_sided(bool enable);
   void set_one_sided_reverse(bool enable);
   void set_one_sided_reverse(bool enable);
   void set_lighting(bool enable);
   void set_lighting(bool enable);
+  void set_perpixel(bool enable);
   void set_background_type(BackgroundType type);
   void set_background_type(BackgroundType type);
 
 
   INLINE bool get_wireframe() const;
   INLINE bool get_wireframe() const;
@@ -127,6 +128,7 @@ public:
   INLINE bool get_two_sided() const;
   INLINE bool get_two_sided() const;
   INLINE bool get_one_sided_reverse() const;
   INLINE bool get_one_sided_reverse() const;
   INLINE bool get_lighting() const;
   INLINE bool get_lighting() const;
+  INLINE bool get_perpixel() const;
   INLINE BackgroundType get_background_type() const;
   INLINE BackgroundType get_background_type() const;
 
 
   static TextFont *get_shuttle_controls_font();
   static TextFont *get_shuttle_controls_font();
@@ -192,6 +194,7 @@ private:
   bool _two_sided_enabled;
   bool _two_sided_enabled;
   bool _one_sided_reverse_enabled;
   bool _one_sided_reverse_enabled;
   bool _lighting_enabled;
   bool _lighting_enabled;
+  bool _perpixel_enabled;
 
 
   PT(FrameRateMeter) _frame_rate_meter;
   PT(FrameRateMeter) _frame_rate_meter;