Panda3D
transparencyAttrib.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file transparencyAttrib.h
10  * @author drose
11  * @date 2002-02-28
12  */
13 
14 #ifndef TRANSPARENCYATTRIB_H
15 #define TRANSPARENCYATTRIB_H
16 
17 #include "pandabase.h"
18 
19 #include "renderAttrib.h"
20 
21 class FactoryParams;
22 
23 /**
24  * This controls the enabling of transparency. Simply setting an alpha
25  * component to non-1 does not in itself make an object transparent; you must
26  * also enable transparency mode with a suitable TransparencyAttrib.
27  * Similarly, it is wasteful to render an object with a TransparencyAttrib in
28  * effect unless you actually want it to be at least partially transparent
29  * (and it has alpha components less than 1).
30  */
31 class EXPCL_PANDA_PGRAPH TransparencyAttrib : public RenderAttrib {
32 PUBLISHED:
33  enum Mode {
34  // The first two should be specifically 0 and 1, for historical reasons
35  // (NodePath::set_transparency() used to accept a boolean value, which
36  // corresponded to M_none or M_alpha).
37  M_none = 0, // No transparency.
38  M_alpha = 1, // Normal transparency, panda will sort back-to-front.
39  M_premultiplied_alpha, // Assume textures use premultiplied alpha.
40  M_multisample, // Uses ms buffer, alpha values modified to 1.0.
41  M_multisample_mask, // Uses ms buffer, alpha values not modified.
42  M_binary, // Only writes pixels with alpha >= 0.5.
43  M_dual, // opaque parts first, then sorted transparent parts.
44  };
45 
46 private:
47  INLINE TransparencyAttrib(Mode mode = M_none);
48 
49 PUBLISHED:
50  static CPT(RenderAttrib) make(Mode mode);
51  static CPT(RenderAttrib) make_default();
52 
53  INLINE Mode get_mode() const;
54  MAKE_PROPERTY(mode, get_mode);
55 
56 public:
57  virtual void output(std::ostream &out) const;
58 
59 protected:
60  virtual int compare_to_impl(const RenderAttrib *other) const;
61  virtual size_t get_hash_impl() const;
62 
63 private:
64  Mode _mode;
65 
66 PUBLISHED:
67  static int get_class_slot() {
68  return _attrib_slot;
69  }
70  virtual int get_slot() const {
71  return get_class_slot();
72  }
73  MAKE_PROPERTY(class_slot, get_class_slot);
74 
75 public:
76  static void register_with_read_factory();
77  virtual void write_datagram(BamWriter *manager, Datagram &dg);
78 
79 protected:
80  static TypedWritable *make_from_bam(const FactoryParams &params);
81  void fillin(DatagramIterator &scan, BamReader *manager);
82 
83 public:
84  static TypeHandle get_class_type() {
85  return _type_handle;
86  }
87  static void init_type() {
88  RenderAttrib::init_type();
89  register_type(_type_handle, "TransparencyAttrib",
90  RenderAttrib::get_class_type());
91  _attrib_slot = register_slot(_type_handle, 100, new TransparencyAttrib);
92  }
93  virtual TypeHandle get_type() const {
94  return get_class_type();
95  }
96  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
97 
98 private:
99  static TypeHandle _type_handle;
100  static int _attrib_slot;
101 };
102 
103 #include "transparencyAttrib.I"
104 
105 #endif
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This controls the enabling of transparency.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
static int register_slot(TypeHandle type_handle, int sort, RenderAttrib *default_attrib)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Definition: renderAttrib.I:101
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38