Panda3D
colorBlendAttrib.h
1 // Filename: colorBlendAttrib.h
2 // Created by: drose (29Mar02)
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 COLORBLENDATTRIB_H
16 #define COLORBLENDATTRIB_H
17 
18 #include "pandabase.h"
19 #include "luse.h"
20 #include "renderAttrib.h"
21 
22 class FactoryParams;
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : ColorBlendAttrib
26 // Description : This specifies how colors are blended into the frame
27 // buffer, for special effects. This overrides
28 // transparency if transparency is also specified.
29 ////////////////////////////////////////////////////////////////////
30 class EXPCL_PANDA_PGRAPH ColorBlendAttrib : public RenderAttrib {
31 PUBLISHED:
32  enum Mode {
33  M_none, // Blending is disabled
34  M_add, // incoming color * A + fbuffer color * B
35  M_subtract, // incoming color * A - fbuffer color * B
36  M_inv_subtract, // fbuffer color * B - incoming color * A
37  M_min, // min(incoming color, fbuffer color)
38  M_max // max(incoming color, fbuffer color)
39  };
40 
41  enum Operand {
42  O_zero,
43  O_one,
44  O_incoming_color,
45  O_one_minus_incoming_color,
46  O_fbuffer_color,
47  O_one_minus_fbuffer_color,
48  O_incoming_alpha,
49  O_one_minus_incoming_alpha,
50  O_fbuffer_alpha,
51  O_one_minus_fbuffer_alpha,
52  O_constant_color,
53  O_one_minus_constant_color,
54  O_constant_alpha,
55  O_one_minus_constant_alpha,
56  O_incoming_color_saturate, // valid only for operand a
57 
58  // If you set either of the operands to any of the below, the
59  // blend color is taken from the current ColorScaleAttrib. This
60  // also inhibits the normal behavior of the ColorScaleAttrib; it
61  // no longer directly scales the vertex colors, on the assumption
62  // that you will instead take care of the scale here, in the blend
63  // mode.
64  O_color_scale,
65  O_one_minus_color_scale,
66  O_alpha_scale,
67  O_one_minus_alpha_scale,
68  };
69 
70 private:
71  INLINE ColorBlendAttrib();
72  INLINE ColorBlendAttrib(Mode mode, Operand a, Operand b,
73  const LColor &color);
74 
75 PUBLISHED:
76  static CPT(RenderAttrib) make_off();
77  static CPT(RenderAttrib) make(Mode mode);
78  static CPT(RenderAttrib) make(Mode mode, Operand a, Operand b,
79  const LColor &color = LColor::zero());
80  static CPT(RenderAttrib) make_default();
81 
82  INLINE Mode get_mode() const;
83  INLINE Operand get_operand_a() const;
84  INLINE Operand get_operand_b() const;
85  INLINE LColor get_color() const;
86 
87  INLINE bool involves_constant_color() const;
88  INLINE bool involves_color_scale() const;
89 
90  INLINE static bool involves_constant_color(Operand operand);
91  INLINE static bool involves_color_scale(Operand operand);
92 
93 public:
94  virtual void output(ostream &out) const;
95 
96 protected:
97  virtual int compare_to_impl(const RenderAttrib *other) const;
98  virtual size_t get_hash_impl() const;
99  virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
100 
101 private:
102  Mode _mode;
103  Operand _a, _b;
104  LColor _color;
105  bool _involves_constant_color;
106  bool _involves_color_scale;
107 
108 PUBLISHED:
109  static int get_class_slot() {
110  return _attrib_slot;
111  }
112  virtual int get_slot() const {
113  return get_class_slot();
114  }
115 
116 public:
117  static void register_with_read_factory();
118  virtual void write_datagram(BamWriter *manager, Datagram &dg);
119 
120 protected:
121  static TypedWritable *make_from_bam(const FactoryParams &params);
122  void fillin(DatagramIterator &scan, BamReader *manager);
123 
124 public:
125  static TypeHandle get_class_type() {
126  return _type_handle;
127  }
128  static void init_type() {
129  RenderAttrib::init_type();
130  register_type(_type_handle, "ColorBlendAttrib",
131  RenderAttrib::get_class_type());
132  _attrib_slot = register_slot(_type_handle, 100, make_default);
133  }
134  virtual TypeHandle get_type() const {
135  return get_class_type();
136  }
137  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
138 
139 private:
140  static TypeHandle _type_handle;
141  static int _attrib_slot;
142 };
143 
144 ostream &operator << (ostream &out, ColorBlendAttrib::Mode mode);
145 ostream &operator << (ostream &out, ColorBlendAttrib::Operand operand);
146 
147 #include "colorBlendAttrib.I"
148 
149 #endif
150 
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
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
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This specifies how colors are blended into the frame buffer, for special effects. ...
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
static const LVecBase4f & zero()
Returns a zero-length vector.
Definition: lvecBase4.h:493