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