浏览代码

Added material attrib lock

Josh Yelon 17 年之前
父节点
当前提交
5917243378
共有 5 个文件被更改,包括 83 次插入7 次删除
  1. 12 0
      panda/src/gobj/config_gobj.cxx
  2. 1 0
      panda/src/gobj/config_gobj.h
  3. 38 0
      panda/src/gobj/material.I
  4. 21 1
      panda/src/gobj/material.cxx
  5. 11 6
      panda/src/gobj/material.h

+ 12 - 0
panda/src/gobj/config_gobj.cxx

@@ -219,6 +219,18 @@ ConfigVariableBool dump_generated_shaders
           "to disk.  This is useful for debugging broken shader "
           "generators."));
 
+ConfigVariableBool enforce_attrib_lock
+("enforce-attrib-lock", true,
+ PRC_DESC("When a MaterialAttrib, TextureAttrib, or LightAttrib is "
+          "constructed, the corresponding Material, Texture, or Light "
+          "is 'attrib locked.'  The attrib lock prevents qualitative "
+          "changes to the object.  This makes it possible to hardwire "
+          "information about material, light, and texture properties "
+          "into generated shaders.  This config variable can disable "
+          "the attrib lock.  Disabling the lock will break the shader "
+          "generator, but doing so may be necessary for backward "
+          "compatibility with old code."));
+
 ConfigVariableEnum<AutoTextureScale> textures_power_2
 ("textures-power-2", ATS_down,
  PRC_DESC("Specify whether textures should automatically be constrained to "

+ 1 - 0
panda/src/gobj/config_gobj.h

@@ -67,6 +67,7 @@ extern EXPCL_PANDA_GOBJ ConfigVariableBool display_list_animation;
 extern EXPCL_PANDA_GOBJ ConfigVariableBool connect_triangle_strips;
 extern EXPCL_PANDA_GOBJ ConfigVariableBool preserve_triangle_strips;
 extern EXPCL_PANDA_GOBJ ConfigVariableBool dump_generated_shaders;
+extern EXPCL_PANDA_GOBJ ConfigVariableBool enforce_attrib_lock;
 
 extern EXPCL_PANDA_GOBJ ConfigVariableEnum<AutoTextureScale> textures_power_2;
 extern EXPCL_PANDA_GOBJ ConfigVariableEnum<AutoTextureScale> textures_square;

+ 38 - 0
panda/src/gobj/material.I

@@ -94,6 +94,9 @@ get_ambient() const {
 ////////////////////////////////////////////////////////////////////
 INLINE void Material::
 clear_ambient() {
+  if (enforce_attrib_lock) {
+    nassertv(!is_attrib_locked());
+  }
   _flags &= ~F_ambient;
   _ambient.set(0.0f, 0.0f, 0.0f, 0.0f);
 }
@@ -128,6 +131,9 @@ get_diffuse() const {
 ////////////////////////////////////////////////////////////////////
 INLINE void Material::
 clear_diffuse() {
+  if (enforce_attrib_lock) {
+    nassertv(!is_attrib_locked());
+  }
   _flags &= ~F_diffuse;
   _diffuse.set(1.0f, 1.0f, 1.0f, 1.0f);
 }
@@ -162,6 +168,9 @@ get_specular() const {
 ////////////////////////////////////////////////////////////////////
 INLINE void Material::
 clear_specular() {
+  if (enforce_attrib_lock) {
+    nassertv(!is_attrib_locked());
+  }
   _flags &= ~F_specular;
   _specular.set(0.0f, 0.0f, 0.0f, 0.0f);
 }
@@ -196,6 +205,9 @@ get_emission() const {
 ////////////////////////////////////////////////////////////////////
 INLINE void Material::
 clear_emission() {
+  if (enforce_attrib_lock) {
+    nassertv(!is_attrib_locked());
+  }
   _flags &= ~F_emission;
   _emission.set(0.0f, 0.0f, 0.0f, 0.0f);
 }
@@ -246,6 +258,9 @@ get_local() const {
 ////////////////////////////////////////////////////////////////////
 INLINE void Material::
 set_local(bool local) {
+  if (enforce_attrib_lock) {
+    nassertv(!is_attrib_locked());
+  }
   if (local) {
     _flags |= F_local;
   } else {
@@ -275,6 +290,9 @@ get_twoside() const {
 ////////////////////////////////////////////////////////////////////
 INLINE void Material::
 set_twoside(bool twoside) {
+  if (enforce_attrib_lock) {
+    nassertv(!is_attrib_locked());
+  }
   if (twoside) {
     _flags |= F_twoside;
   } else {
@@ -311,3 +329,23 @@ INLINE bool Material::
 operator < (const Material &other) const {
   return compare_to(other) < 0;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: Material::is_attrib_locked
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE bool Material::
+is_attrib_locked() const {
+  return (_flags & F_attrib_lock) != 0;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Material::set_attrib_lock
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void Material::
+set_attrib_lock() {
+  _flags |= F_attrib_lock;
+}

+ 21 - 1
panda/src/gobj/material.cxx

@@ -40,7 +40,7 @@ operator = (const Material &copy) {
   _specular = copy._specular;
   _emission = copy._emission;
   _shininess = copy._shininess;
-  _flags = copy._flags;
+  _flags = copy._flags & (~F_attrib_lock);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -57,6 +57,11 @@ operator = (const Material &copy) {
 ////////////////////////////////////////////////////////////////////
 void Material::
 set_ambient(const Colorf &color) {
+  if (enforce_attrib_lock) {
+    if ((_flags & F_ambient)==0) {
+      nassertv(!is_attrib_locked());
+    }
+  }
   _ambient = color;
   _flags |= F_ambient;
 }
@@ -77,6 +82,11 @@ set_ambient(const Colorf &color) {
 ////////////////////////////////////////////////////////////////////
 void Material::
 set_diffuse(const Colorf &color) {
+  if (enforce_attrib_lock) {
+    if ((_flags & F_diffuse)==0) {
+      nassertv(!is_attrib_locked());
+    }
+  }
   _diffuse = color;
   _flags |= F_diffuse;
 }
@@ -96,6 +106,11 @@ set_diffuse(const Colorf &color) {
 ////////////////////////////////////////////////////////////////////
 void Material::
 set_specular(const Colorf &color) {
+  if (enforce_attrib_lock) {
+    if ((_flags & F_specular)==0) {
+      nassertv(!is_attrib_locked());
+    }
+  }
   _specular = color;
   _flags |= F_specular;
 }
@@ -116,6 +131,11 @@ set_specular(const Colorf &color) {
 ////////////////////////////////////////////////////////////////////
 void Material::
 set_emission(const Colorf &color) {
+  if (enforce_attrib_lock) {
+    if ((_flags & F_emission)==0) {
+      nassertv(!is_attrib_locked());
+    }
+  }
   _emission = color;
   _flags |= F_emission;
 }

+ 11 - 6
panda/src/gobj/material.h

@@ -24,6 +24,7 @@
 #include "typedWritableReferenceCount.h"
 #include "namable.h"
 #include "luse.h"
+#include "config_gobj.h"
 
 class FactoryParams;
 
@@ -79,6 +80,9 @@ PUBLISHED:
   void output(ostream &out) const;
   void write(ostream &out, int indent) const;
 
+  INLINE bool is_attrib_locked() const;
+  INLINE void set_attrib_lock();
+
 private:
   Colorf _ambient;
   Colorf _diffuse;
@@ -89,12 +93,13 @@ private:
   static PT(Material) _default;
   
   enum Flags {
-    F_ambient   = 0x001,
-    F_diffuse   = 0x002,
-    F_specular  = 0x004,
-    F_emission  = 0x008,
-    F_local     = 0x010,
-    F_twoside   = 0x020,
+    F_ambient     = 0x001,
+    F_diffuse     = 0x002,
+    F_specular    = 0x004,
+    F_emission    = 0x008,
+    F_local       = 0x010,
+    F_twoside     = 0x020,
+    F_attrib_lock = 0x040
   };
   int _flags;