Browse Source

Added a fast function to obtain the default material

Josh Yelon 18 years ago
parent
commit
7625c2cfa2
3 changed files with 18 additions and 0 deletions
  1. 13 0
      panda/src/gobj/material.I
  2. 1 0
      panda/src/gobj/material.cxx
  3. 4 0
      panda/src/gobj/material.h

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

@@ -51,6 +51,19 @@ INLINE Material::
 ~Material() {
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: Material::get_default
+//       Access: Published, Static
+//  Description: Returns the default material.
+////////////////////////////////////////////////////////////////////
+INLINE Material *Material::
+get_default() {
+  if (_default == 0) {
+    _default = new Material("default");
+  }
+  return _default;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Material::has_ambient
 //       Access: Published

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

@@ -25,6 +25,7 @@
 #include "bamWriter.h"
 
 TypeHandle Material::_type_handle;
+PT(Material) Material::_default;
 
 ////////////////////////////////////////////////////////////////////
 //     Function: Material::Copy Assignment Operator

+ 4 - 0
panda/src/gobj/material.h

@@ -40,6 +40,8 @@ PUBLISHED:
   void operator = (const Material &copy);
   INLINE ~Material();
 
+  INLINE static Material *get_default();
+  
   INLINE bool has_ambient() const;
   INLINE const Colorf &get_ambient() const;
   void set_ambient(const Colorf &color);
@@ -84,6 +86,8 @@ private:
   Colorf _emission;
   float _shininess;
 
+  static PT(Material) _default;
+  
   enum Flags {
     F_ambient   = 0x001,
     F_diffuse   = 0x002,