Panda3D

transparencyAttrib.h

00001 // Filename: transparencyAttrib.h
00002 // Created by:  drose (28Feb02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef TRANSPARENCYATTRIB_H
00016 #define TRANSPARENCYATTRIB_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "renderAttrib.h"
00021 
00022 class FactoryParams;
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : TransparencyAttrib
00026 // Description : This controls the enabling of transparency.  Simply
00027 //               setting an alpha component to non-1 does not in
00028 //               itself make an object transparent; you must also
00029 //               enable transparency mode with a suitable
00030 //               TransparencyAttrib.  Similarly, it is wasteful to
00031 //               render an object with a TransparencyAttrib in
00032 //               effect unless you actually want it to be at least
00033 //               partially transparent (and it has alpha components
00034 //               less than 1).
00035 ////////////////////////////////////////////////////////////////////
00036 class EXPCL_PANDA_PGRAPH TransparencyAttrib : public RenderAttrib {
00037 PUBLISHED:
00038   enum Mode {
00039     // The first two should be specifically 0 and 1, for historical
00040     // reasons (NodePath::set_transparency() used to accept a boolean
00041     // value, which corresponded to M_none or M_alpha).
00042     M_none = 0,         // No transparency.
00043     M_alpha = 1,        // Normal transparency, panda will sort back-to-front.
00044     M_notused,          // Unused placeholder.  Do not use this.
00045     M_multisample,      // Uses ms buffer, alpha values modified to 1.0.
00046     M_multisample_mask, // Uses ms buffer, alpha values not modified.
00047     M_binary,           // Only writes pixels with alpha >= 0.5.
00048     M_dual,             // opaque parts first, then sorted transparent parts.
00049   };
00050 
00051 private:
00052   INLINE TransparencyAttrib(Mode mode = M_none);
00053 
00054 PUBLISHED:
00055   static CPT(RenderAttrib) make(Mode mode);
00056   static CPT(RenderAttrib) make_default();
00057 
00058   INLINE Mode get_mode() const;
00059 
00060 public:
00061   virtual void output(ostream &out) const;
00062 
00063 protected:
00064   virtual int compare_to_impl(const RenderAttrib *other) const;
00065   virtual size_t get_hash_impl() const;
00066   virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
00067 
00068 private:
00069   Mode _mode;
00070 
00071 PUBLISHED:
00072   static int get_class_slot() {
00073     return _attrib_slot;
00074   }
00075   virtual int get_slot() const {
00076     return get_class_slot();
00077   }
00078 
00079 public:
00080   static void register_with_read_factory();
00081   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00082 
00083 protected:
00084   static TypedWritable *make_from_bam(const FactoryParams &params);
00085   void fillin(DatagramIterator &scan, BamReader *manager);
00086   
00087 public:
00088   static TypeHandle get_class_type() {
00089     return _type_handle;
00090   }
00091   static void init_type() {
00092     RenderAttrib::init_type();
00093     register_type(_type_handle, "TransparencyAttrib",
00094                   RenderAttrib::get_class_type());
00095     _attrib_slot = register_slot(_type_handle, 100, make_default);
00096   }
00097   virtual TypeHandle get_type() const {
00098     return get_class_type();
00099   }
00100   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00101 
00102 private:
00103   static TypeHandle _type_handle;
00104   static int _attrib_slot;
00105 };
00106 
00107 #include "transparencyAttrib.I"
00108 
00109 #endif
00110 
 All Classes Functions Variables Enumerations