Panda3D
colorBlendAttrib.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 colorBlendAttrib.h
10  * @author drose
11  * @date 2002-03-29
12  */
13 
14 #ifndef COLORBLENDATTRIB_H
15 #define COLORBLENDATTRIB_H
16 
17 #include "pandabase.h"
18 #include "luse.h"
19 #include "renderAttrib.h"
20 
21 class FactoryParams;
22 
23 /**
24  * This specifies how colors are blended into the frame buffer, for special
25  * effects. This overrides transparency if transparency is also specified.
26  */
27 class EXPCL_PANDA_PGRAPH ColorBlendAttrib : public RenderAttrib {
28 PUBLISHED:
29  enum Mode {
30  M_none, // Blending is disabled
31  M_add, // incoming color * A + fbuffer color * B
32  M_subtract, // incoming color * A - fbuffer color * B
33  M_inv_subtract, // fbuffer color * B - incoming color * A
34  M_min, // min(incoming color, fbuffer color)
35  M_max // max(incoming color, fbuffer color)
36  };
37 
38  enum Operand {
39  O_zero,
40  O_one,
41  O_incoming_color,
42  O_one_minus_incoming_color,
43  O_fbuffer_color,
44  O_one_minus_fbuffer_color,
45  O_incoming_alpha,
46  O_one_minus_incoming_alpha,
47  O_fbuffer_alpha,
48  O_one_minus_fbuffer_alpha,
49  O_constant_color,
50  O_one_minus_constant_color,
51  O_constant_alpha,
52  O_one_minus_constant_alpha,
53  O_incoming_color_saturate, // valid only for operand a
54 
55  // The following are used for dual-source blending, where the fragment
56  // shader outputs a second color that will be used for blending.
57  O_incoming1_color,
58  O_one_minus_incoming1_color,
59  O_incoming1_alpha,
60  O_one_minus_incoming1_alpha,
61 
62  // If you set any of the operands to any of the below, the blend color is
63  // taken from the current ColorScaleAttrib. This also inhibits the normal
64  // behavior of the ColorScaleAttrib; it no longer directly scales the
65  // vertex colors, on the assumption that you will instead take care of the
66  // scale here, in the blend mode.
67  //
68  // These modes are being considered for deprecation.
69  O_color_scale,
70  O_one_minus_color_scale,
71  O_alpha_scale,
72  O_one_minus_alpha_scale,
73  };
74 
75 private:
76  INLINE ColorBlendAttrib();
77  INLINE ColorBlendAttrib(Mode mode, Operand a, Operand b,
78  Mode alpha_mode, Operand alpha_a, Operand alpha_b,
79  const LColor &color);
80 
81 PUBLISHED:
82  static CPT(RenderAttrib) make_off();
83  static CPT(RenderAttrib) make(Mode mode);
84  static CPT(RenderAttrib) make(Mode mode, Operand a, Operand b,
85  const LColor &color = LColor::zero());
86  static CPT(RenderAttrib) make(Mode rgb_mode, Operand rgb_a, Operand rgb_b,
87  Mode alpha_mode, Operand alpha_a, Operand alpha_b,
88  const LColor &color = LColor::zero());
89  static CPT(RenderAttrib) make_default();
90 
91  INLINE Mode get_mode() const;
92  INLINE Operand get_operand_a() const;
93  INLINE Operand get_operand_b() const;
94 
95  INLINE Mode get_alpha_mode() const;
96  INLINE Operand get_alpha_operand_a() const;
97  INLINE Operand get_alpha_operand_b() const;
98 
99  INLINE LColor get_color() const;
100 
101  INLINE bool involves_constant_color() const;
102  INLINE bool involves_color_scale() const;
103 
104  INLINE static bool involves_constant_color(Operand operand);
105  INLINE static bool involves_color_scale(Operand operand);
106 
107 PUBLISHED:
108  MAKE_PROPERTY(rgb_mode, get_mode);
109  MAKE_PROPERTY(rgb_operand_a, get_operand_a);
110  MAKE_PROPERTY(rgb_operand_b, get_operand_b);
111 
112  MAKE_PROPERTY(alpha_mode, get_alpha_mode);
113  MAKE_PROPERTY(alpha_operand_a, get_alpha_operand_a);
114  MAKE_PROPERTY(alpha_operand_b, get_alpha_operand_b);
115 
116  MAKE_PROPERTY(color, get_color);
117 
118 public:
119  virtual void output(std::ostream &out) const;
120 
121 protected:
122  virtual int compare_to_impl(const RenderAttrib *other) const;
123  virtual size_t get_hash_impl() const;
124 
125 private:
126  Mode _mode;
127  Operand _a, _b;
128  Mode _alpha_mode;
129  Operand _alpha_a, _alpha_b;
130  LColor _color;
131  bool _involves_constant_color;
132  bool _involves_color_scale;
133 
134 PUBLISHED:
135  static int get_class_slot() {
136  return _attrib_slot;
137  }
138  virtual int get_slot() const {
139  return get_class_slot();
140  }
141  MAKE_PROPERTY(class_slot, get_class_slot);
142 
143 public:
144  static void register_with_read_factory();
145  virtual void write_datagram(BamWriter *manager, Datagram &dg);
146 
147 protected:
148  static TypedWritable *make_from_bam(const FactoryParams &params);
149  void fillin(DatagramIterator &scan, BamReader *manager);
150 
151 public:
152  static TypeHandle get_class_type() {
153  return _type_handle;
154  }
155  static void init_type() {
156  RenderAttrib::init_type();
157  register_type(_type_handle, "ColorBlendAttrib",
158  RenderAttrib::get_class_type());
159  _attrib_slot = register_slot(_type_handle, 100, new ColorBlendAttrib);
160  }
161  virtual TypeHandle get_type() const {
162  return get_class_type();
163  }
164  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
165 
166 private:
167  static TypeHandle _type_handle;
168  static int _attrib_slot;
169 };
170 
171 EXPCL_PANDA_PGRAPH std::ostream &operator << (std::ostream &out, ColorBlendAttrib::Mode mode);
172 EXPCL_PANDA_PGRAPH std::ostream &operator << (std::ostream &out, ColorBlendAttrib::Operand operand);
173 
174 #include "colorBlendAttrib.I"
175 
176 #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.
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
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:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.