Browse Source

Add ConfigVariableColor

rdb 11 years ago
parent
commit
eaabc1bfa5

+ 3 - 0
dtool/src/prc/configFlags.cxx

@@ -52,6 +52,9 @@ operator << (ostream &out, ConfigFlags::ValueType type) {
 
   case ConfigFlags::VT_int64:
     return out << "int64";
+
+  case ConfigFlags::VT_color:
+    return out << "color";
   }
 
   return out << "**invalid(" << (int)type << ")**";

+ 1 - 1
dtool/src/prc/configFlags.h

@@ -39,6 +39,7 @@ PUBLISHED:
     VT_enum,
     VT_search_path,
     VT_int64,
+    VT_color,
   };
 
   enum VariableFlags {
@@ -75,4 +76,3 @@ ostream &operator << (ostream &out, ConfigFlags::ValueType type);
 #include "configFlags.I"
 
 #endif
-

+ 2 - 2
panda/src/display/config_display.cxx

@@ -451,8 +451,8 @@ ConfigVariableDouble pixel_zoom
 ("pixel-zoom", 1.0,
  PRC_DESC("The default pixel_zoom factor for new windows."));
 
-ConfigVariableDouble background_color
-("background-color", "0.41 0.41 0.41",
+ConfigVariableColor background_color
+("background-color", "0.41 0.41 0.41 0.0",
  PRC_DESC("Specifies the rgb(a) value of the default background color for a "
           "new window or offscreen buffer."));
 

+ 2 - 1
panda/src/display/config_display.h

@@ -24,6 +24,7 @@
 #include "configVariableInt.h"
 #include "configVariableEnum.h"
 #include "configVariableFilename.h"
+#include "configVariableColor.h"
 #include "coordinateSystem.h"
 #include "dconfig.h"
 
@@ -107,7 +108,7 @@ extern EXPCL_PANDA_DISPLAY ConfigVariableInt back_buffers;
 
 extern EXPCL_PANDA_DISPLAY ConfigVariableDouble pixel_zoom;
 
-extern EXPCL_PANDA_DISPLAY ConfigVariableDouble background_color;
+extern EXPCL_PANDA_DISPLAY ConfigVariableColor background_color;
 extern EXPCL_PANDA_DISPLAY ConfigVariableBool sync_video;
 extern EXPCL_PANDA_DISPLAY ConfigVariableBool basic_shaders_only;
 

+ 1 - 23
panda/src/display/graphicsOutput.cxx

@@ -163,29 +163,7 @@ GraphicsOutput(GraphicsEngine *engine, GraphicsPipe *pipe,
   set_clear_color_active(true);
   set_clear_depth_active(true);
   set_clear_stencil_active(true);
-
-  switch (background_color.get_num_words()) {
-  case 1:
-    set_clear_color(LColor(background_color[0], background_color[0], background_color[0], 0.0f));
-    break;
-
-  case 2:
-    set_clear_color(LColor(background_color[0], background_color[0], background_color[0], background_color[1]));
-    break;
-
-  case 3:
-    set_clear_color(LColor(background_color[0], background_color[1], background_color[2], 0.0f));
-    break;
-
-  case 4:
-    set_clear_color(LColor(background_color[0], background_color[1], background_color[2], background_color[3]));
-    break;
-
-  default:
-    display_cat.warning()
-      << "Invalid background-color specification: "
-      << background_color.get_string_value() << "\n";
-  }
+  set_clear_color(background_color.get_value());
 }
 
 ////////////////////////////////////////////////////////////////////

+ 6 - 3
panda/src/linmath/Sources.pp

@@ -12,6 +12,7 @@
      aa_luse.h \
      compose_matrix.h compose_matrix_src.I  \
      compose_matrix_src.cxx compose_matrix_src.h config_linmath.h  \
+     configVariableColor.h configVariableColor.I \
      coordinateSystem.h dbl2fltnames.h dblnames.h \
      deg_2_rad.h deg_2_rad.I \
      flt2dblnames.h fltnames.h intnames.h lcast_to.h lcast_to_src.h  \
@@ -43,8 +44,8 @@
      mathNumbers.h mathNumbers.I 
     
   #define INCLUDED_SOURCES \
-     compose_matrix.cxx config_linmath.cxx coordinateSystem.cxx  \
-     lmatrix.cxx \
+     compose_matrix.cxx config_linmath.cxx configVariableColor.cxx \
+     coordinateSystem.cxx lmatrix.cxx \
      lorientation.cxx lpoint2.cxx  \
      lpoint3.cxx lpoint4.cxx lquaternion.cxx lrotation.cxx  \
      luse.cxx lvecBase2.cxx lvecBase3.cxx lvecBase4.cxx  \
@@ -53,7 +54,9 @@
   #define INSTALL_HEADERS \
     aa_luse.h \
     compose_matrix.h compose_matrix_src.I \
-    compose_matrix_src.h config_linmath.h coordinateSystem.h \
+    compose_matrix_src.h config_linmath.h \
+    configVariableColor.h configVariableColor.I \
+    coordinateSystem.h \
     dbl2fltnames.h dblnames.h \
     deg_2_rad.h deg_2_rad.I \
     flt2dblnames.h fltnames.h intnames.h lcast_to.h lcast_to_src.I lcast_to_src.h \

+ 182 - 0
panda/src/linmath/configVariableColor.I

@@ -0,0 +1,182 @@
+// Filename: configVariableColor.I
+// Created by:  rdb (02Feb14)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableColor::Constructor
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE ConfigVariableColor::
+ConfigVariableColor(const string &name) :
+  ConfigVariable(name, VT_color),
+  _local_modified(initial_invalid_cache()),
+  _cache(0, 0, 0, 1)
+{
+  _core->set_used();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableColor::Constructor
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE ConfigVariableColor::
+ConfigVariableColor(const string &name, const LColor &default_value,
+                    const string &description, int flags) :
+#ifdef PRC_SAVE_DESCRIPTIONS
+  ConfigVariable(name, ConfigVariableCore::VT_color, description, flags),
+#else
+  ConfigVariable(name, ConfigVariableCore::VT_color, string(), flags),
+#endif
+  _local_modified(initial_invalid_cache()),
+  _cache(0, 0, 0, 1)
+{
+  set_default_value(default_value);
+  _core->set_used();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableColor::Constructor
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE ConfigVariableColor::
+ConfigVariableColor(const string &name, const string &default_value,
+                    const string &description, int flags) :
+#ifdef PRC_SAVE_DESCRIPTIONS
+  ConfigVariable(name, ConfigVariableCore::VT_color, description, flags),
+#else
+  ConfigVariable(name, ConfigVariableCore::VT_color, string(), flags),
+#endif
+  _local_modified(initial_invalid_cache()),
+  _cache(0, 0, 0, 1)
+{
+  _core->set_default_value(default_value);
+  _core->set_used();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableColor::operator =
+//       Access: Published
+//  Description: Reassigns the variable's local value.
+////////////////////////////////////////////////////////////////////
+INLINE void ConfigVariableColor::
+operator = (const LColor &value) {
+  set_value(value);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableColor::typecast operator
+//       Access: Published
+//  Description: Returns the variable's value.
+////////////////////////////////////////////////////////////////////
+INLINE ConfigVariableColor::
+operator const LColor & () const {
+  return get_value();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableColor::operator []
+//       Access: Published
+//  Description: Returns the value of the color's nth component
+//               (which is not necessarily the same thing as the
+//               variable's nth word).
+////////////////////////////////////////////////////////////////////
+INLINE PN_stdfloat ConfigVariableColor::
+operator [] (int n) const {
+  return get_value()[n];
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableColor::set_value
+//       Access: Published
+//  Description: Reassigns the variable's local value.
+////////////////////////////////////////////////////////////////////
+INLINE void ConfigVariableColor::
+set_value(const LColor &color) {
+  set_string_value("");
+  set_double_word(0, color[0]);
+  set_double_word(1, color[1]);
+  set_double_word(2, color[2]);
+  set_double_word(3, color[3]);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableColor::get_value
+//       Access: Published
+//  Description: Returns the variable's value.
+////////////////////////////////////////////////////////////////////
+INLINE const LColor &ConfigVariableColor::
+get_value() const {
+  TAU_PROFILE("const LColor &ConfigVariableColor::get_value() const", " ", TAU_USER);
+  if (!is_cache_valid(_local_modified)) {
+    mark_cache_valid(_local_modified);
+
+    switch (get_num_words()) {
+    case 1:
+      _cache.set(get_double_word(0), get_double_word(0), get_double_word(0), 1);
+      break;
+
+    case 2:
+      _cache.set(get_double_word(0), get_double_word(0), get_double_word(0), get_double_word(1));
+      break;
+
+    case 3:
+      _cache.set(get_double_word(0), get_double_word(1), get_double_word(2), 1);
+      break;
+
+    case 4:
+      _cache.set(get_double_word(0), get_double_word(1), get_double_word(2), get_double_word(3));
+      break;
+
+    default:
+      prc_cat->warning()
+        << "Invalid color value for ConfigVariable "
+        << get_name() << ": " << get_string_value() << "\n";
+    }
+  }
+  return _cache;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableColor::get_default_value
+//       Access: Published
+//  Description: Returns the variable's default value.
+////////////////////////////////////////////////////////////////////
+INLINE LColor ConfigVariableColor::
+get_default_value() const {
+  const ConfigDeclaration *decl = ConfigVariable::get_default_value();
+  if (decl != (ConfigDeclaration *)NULL) {
+    switch (decl->get_num_words()) {
+    case 1:
+      return LColor(decl->get_double_word(0), decl->get_double_word(0),
+                    decl->get_double_word(0), 1);
+    case 2:
+      return LColor(decl->get_double_word(0), decl->get_double_word(0),
+                    decl->get_double_word(0), decl->get_double_word(1));
+    case 3:
+      return LColor(decl->get_double_word(0), decl->get_double_word(1),
+                    decl->get_double_word(2), 1);
+    case 4:
+      return LColor(decl->get_double_word(0), decl->get_double_word(1),
+                    decl->get_double_word(2), decl->get_double_word(3));
+    default:
+      prc_cat->warning()
+        << "Invalid default color value for ConfigVariable "
+        << get_name() << ": " << decl->get_string_value() << "\n";
+    }
+  }
+  return LColor(0, 0, 0, 1);
+}

+ 28 - 0
panda/src/linmath/configVariableColor.cxx

@@ -0,0 +1,28 @@
+// Filename: configVariableColor.cxx
+// Created by:  rdb (02Feb14)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "configVariableColor.h"
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableColor::set_default_value
+//       Access: Private
+//  Description:
+////////////////////////////////////////////////////////////////////
+void ConfigVariableColor::
+set_default_value(const LColor &default_value) {
+  ostringstream strm;
+  strm << default_value;
+
+  _core->set_default_value(strm.str());
+}

+ 69 - 0
panda/src/linmath/configVariableColor.h

@@ -0,0 +1,69 @@
+// Filename: configVariableColor.h
+// Created by:  rdb (02Feb14)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CONFIGVARIABLECOLOR_H
+#define CONFIGVARIABLECOLOR_H
+
+#include "dtoolbase.h"
+#include "config_linmath.h"
+#include "config_prc.h"
+#include "configVariable.h"
+#include "luse.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : ConfigVariableColor
+// Description : This is a convenience class to specialize
+//               ConfigVariable as a set of floating-point types
+//               representing a color value.
+//
+//               It interprets the color differently depending on
+//               how many words were specified: if only one, it
+//               is interpreted as a shade of gray with alpha 1.
+//               If two values were specified, a grayscale and
+//               alpha pair.  If three, a set of R, G, B values
+//               with alpha 1, and if four, a complete RGBA color.
+//
+//               This isn't defined in dtool because it relies on
+//               the LColor class, which is defined in linmath.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA_LINMATH ConfigVariableColor : public ConfigVariable {
+PUBLISHED:
+  INLINE ConfigVariableColor(const string &name);
+  INLINE ConfigVariableColor(const string &name, const LColor &default_value,
+                             const string &description = string(),
+                             int flags = 0);
+  INLINE ConfigVariableColor(const string &name, const string &default_value,
+                             const string &description = string(),
+                             int flags = 0);
+
+  INLINE void operator = (const LColor &value);
+  INLINE operator const LColor & () const;
+
+  INLINE PN_stdfloat operator [] (int n) const;
+
+  INLINE void set_value(const LColor &value);
+  INLINE const LColor &get_value() const;
+  INLINE LColor get_default_value() const;
+
+private:
+  void set_default_value(const LColor &default_value);
+
+private:
+  mutable AtomicAdjust::Integer _local_modified;
+  mutable LColor _cache;
+};
+
+#include "configVariableColor.I"
+
+#endif

+ 1 - 0
panda/src/linmath/p3linmath_composite2.cxx

@@ -1,5 +1,6 @@
 
 #include "compose_matrix.cxx"
+#include "configVariableColor.cxx"
 #include "config_linmath.cxx"
 #include "coordinateSystem.cxx"
 #include "lmatrix.cxx"

+ 4 - 15
panda/src/pgraph/cullBinManager.cxx

@@ -17,7 +17,7 @@
 #include "cullResult.h"
 #include "config_pgraph.h"
 #include "string_utils.h"
-
+#include "configVariableColor.h"
 
 CullBinManager *CullBinManager::_global_ptr = (CullBinManager *)NULL;
 
@@ -111,24 +111,13 @@ add_bin(const string &name, BinType type, int sort) {
 
 #ifndef NDEBUG
   // Check if there was a flash color configured for this bin name.
-  ConfigVariableDouble flash_bin
+  ConfigVariableColor flash_bin
     ("flash-bin-" + name, "", "", ConfigVariable::F_dynamic);
   if (flash_bin.get_num_words() == 0) {
     def._flash_active = false;
-
-  } else if (flash_bin.get_num_words() == 3) {
-    def._flash_active = true;
-    def._flash_color.set(flash_bin[0], flash_bin[1], flash_bin[2], 1.0f);
-
-  } else if (flash_bin.get_num_words() == 4) {
-    def._flash_active = true;
-    def._flash_color.set(flash_bin[0], flash_bin[1], flash_bin[2], flash_bin[3]);
-
   } else {
-    def._flash_active = false;
-    pgraph_cat.warning()
-      << "Invalid value for flash-bin-" << name << ": "
-      << flash_bin.get_string_value() << "\n";
+    def._flash_active = true;
+    def._flash_color = flash_bin.get_value();
   }
 #endif
 

+ 3 - 2
panda/src/pstatclient/pStatProperties.cxx

@@ -17,6 +17,7 @@
 #include "pStatClient.h"
 #include "config_pstats.h"
 #include "configVariableBool.h"
+#include "configVariableColor.h"
 #include "configVariableDouble.h"
 #include "configVariableInt.h"
 #include "configVariableString.h"
@@ -339,8 +340,8 @@ initialize_collector_def(const PStatClient *client, PStatCollectorDef *def) {
     ("pstats-units-" + config_name, def->_level_units, "", ConfigVariable::F_dynamic);
   ConfigVariableDouble pstats_factor
     ("pstats-factor-" + config_name, 1.0, "", ConfigVariable::F_dynamic);
-  ConfigVariableDouble pstats_color
-    ("pstats-color-" + config_name, 0.0, "", ConfigVariable::F_dynamic);
+  ConfigVariableColor pstats_color
+    ("pstats-color-" + config_name, LColor::zero(), "", ConfigVariable::F_dynamic);
 
   if (pstats_active.has_value()) {
     def->_is_active = pstats_active;

+ 5 - 5
panda/src/speedtree/config_speedtree.cxx

@@ -116,11 +116,11 @@ ConfigVariableDouble speedtree_fog_distance
  PRC_DESC("Specifies the nearest and farthest distance of the fog on trees "
           "and terrain."));
 
-ConfigVariableDouble speedtree_fog_color
+ConfigVariableColor speedtree_fog_color
 ("speedtree-fog-color", "1.0 1.0 1.0",
  PRC_DESC("Specifies the r g b color of SpeedTree fog."));
 
-ConfigVariableDouble speedtree_sky_color
+ConfigVariableColor speedtree_sky_color
 ("speedtree-sky-color", "0.2 0.3 0.5",
  PRC_DESC("Specifies the r g b color of the SpeedTree sky, when the sky "
           "is enabled.  Currently unused."));
@@ -129,7 +129,7 @@ ConfigVariableDouble speedtree_sky_fog
 ("speedtree-sky-fog", "-0.5 1.0",
  PRC_DESC("Specifies the range of fog in the sky.  -1 is down, 1 is up."));
 
-ConfigVariableDouble speedtree_sun_color
+ConfigVariableColor speedtree_sun_color
 ("speedtree-sun-color", "1.0 1.0 0.85",
  PRC_DESC("Specifies the r g b color of the SpeedTree sun, when the sun "
           "is enabled.  Currently unused."));
@@ -146,12 +146,12 @@ ConfigVariableDouble speedtree_sun_fog_bloom
 ("speedtree-sun-fog-bloom", 0.0,
  PRC_DESC("Undocumented SpeedTree parameter."));
 
-ConfigVariableDouble speedtree_specular_color
+ConfigVariableColor speedtree_specular_color
 ("speedtree-specular-color", "1 1 1",
  PRC_DESC("Specifies the r g b color of the specular reflections on SpeedTree "
           "surfaces."));
 
-ConfigVariableDouble speedtree_emissive_color
+ConfigVariableColor speedtree_emissive_color
 ("speedtree-emissive-color", "0 0 0",
  PRC_DESC("Specifies the r g b color of the emissive light effect on SpeedTree "
           "surfaces."));

+ 6 - 5
panda/src/speedtree/config_speedtree.h

@@ -22,6 +22,7 @@
 #include "configVariableString.h"
 #include "configVariableInt.h"
 #include "configVariableFilename.h"
+#include "configVariableColor.h"
 
 NotifyCategoryDecl(speedtree, EXPCL_PANDASPEEDTREE, EXPTP_PANDASPEEDTREE);
 
@@ -43,16 +44,16 @@ extern ConfigVariableBool speedtree_detail_normal_mapping;
 extern ConfigVariableBool speedtree_ambient_contrast;
 extern ConfigVariableDouble speedtree_transmission_scalar;
 extern ConfigVariableDouble speedtree_fog_distance;
-extern ConfigVariableDouble speedtree_fog_color;
-extern ConfigVariableDouble speedtree_sky_color;
+extern ConfigVariableColor speedtree_fog_color;
+extern ConfigVariableColor speedtree_sky_color;
 extern ConfigVariableDouble speedtree_sky_fog_min;
 extern ConfigVariableDouble speedtree_sky_fog_max;
-extern ConfigVariableDouble speedtree_sun_color;
+extern ConfigVariableColor speedtree_sun_color;
 extern ConfigVariableDouble speedtree_sun_size;
 extern ConfigVariableDouble speedtree_sun_spread_exponent;
 extern ConfigVariableDouble speedtree_sun_fog_bloom;
-extern ConfigVariableDouble speedtree_specular_color;
-extern ConfigVariableDouble speedtree_emissive_color;
+extern ConfigVariableColor speedtree_specular_color;
+extern ConfigVariableColor speedtree_emissive_color;
 extern ConfigVariableInt speedtree_shadow_map_resolution;
 extern ConfigVariableDouble speedtree_cascading_shadow_splits;
 extern ConfigVariableBool speedtree_smooth_shadows;

+ 2 - 2
panda/src/speedtree/speedTreeNode.cxx

@@ -719,8 +719,8 @@ reload_config() {
   render_info.m_nMaxBillboardImagesByBase = speedtree_max_billboard_images_by_base;
   render_info.m_fVisibility = speedtree_visibility;
   render_info.m_fGlobalLightScalar = speedtree_global_light_scalar;
-  render_info.m_sLightMaterial.m_vSpecular = SpeedTree::Vec4(speedtree_specular_color[0], speedtree_specular_color[1], speedtree_specular_color[2], 1.0f);
-  render_info.m_sLightMaterial.m_vEmissive = SpeedTree::Vec4(speedtree_emissive_color[0], speedtree_emissive_color[1], speedtree_emissive_color[2], 1.0f);
+  render_info.m_sLightMaterial.m_vSpecular = SpeedTree::Vec4(speedtree_specular_color[0], speedtree_specular_color[1], speedtree_specular_color[2], speedtree_specular_color[3]);
+  render_info.m_sLightMaterial.m_vEmissive = SpeedTree::Vec4(speedtree_emissive_color[0], speedtree_emissive_color[1], speedtree_emissive_color[2], speedtree_emissive_color[3]);
   render_info.m_bSpecularLighting = speedtree_specular_lighting;
   render_info.m_bTransmissionLighting = speedtree_transmission_lighting;
   render_info.m_bDetailLayer = speedtree_detail_layer;