Panda3D
colorScaleAttrib.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 colorScaleAttrib.h
10  * @author drose
11  * @date 2002-03-14
12  */
13 
14 #ifndef COLORSCALEATTRIB_H
15 #define COLORSCALEATTRIB_H
16 
17 #include "pandabase.h"
18 
19 #include "renderAttrib.h"
20 #include "luse.h"
21 
22 class FactoryParams;
23 
24 /**
25  * Applies a scale to colors in the scene graph and on vertices.
26  */
27 class EXPCL_PANDA_PGRAPH ColorScaleAttrib : public RenderAttrib {
28 protected:
29  ColorScaleAttrib(bool off, const LVecBase4 &scale);
30  INLINE ColorScaleAttrib(const ColorScaleAttrib &copy);
31 
32 PUBLISHED:
33  static CPT(RenderAttrib) make_identity();
34  static CPT(RenderAttrib) make(const LVecBase4 &scale);
35  static CPT(RenderAttrib) make_off();
36  static CPT(RenderAttrib) make_default();
37 
38  INLINE bool is_off() const;
39  INLINE bool is_identity() const;
40  INLINE bool has_scale() const;
41  INLINE bool has_rgb_scale() const;
42  INLINE bool has_alpha_scale() const;
43  INLINE const LVecBase4 &get_scale() const;
44  CPT(RenderAttrib) set_scale(const LVecBase4 &scale) const;
45 
46 PUBLISHED:
47  MAKE_PROPERTY2(scale, has_scale, get_scale);
48 
49 public:
50  virtual bool lower_attrib_can_override() const;
51  virtual void output(std::ostream &out) const;
52 
53 protected:
54  virtual int compare_to_impl(const RenderAttrib *other) const;
55  virtual size_t get_hash_impl() const;
56  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
57  virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
58 
59 private:
60  void quantize_scale();
61 
62 private:
63  bool _off;
64  bool _has_scale;
65  bool _has_rgb_scale;
66  bool _has_alpha_scale;
67  LVecBase4 _scale;
68  static CPT(RenderAttrib) _identity_attrib;
69 
70 PUBLISHED:
71  static int get_class_slot() {
72  return _attrib_slot;
73  }
74  virtual int get_slot() const {
75  return get_class_slot();
76  }
77  MAKE_PROPERTY(class_slot, get_class_slot);
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, "ColorScaleAttrib",
94  RenderAttrib::get_class_type());
95  _attrib_slot = register_slot(_type_handle, 100,
96  new ColorScaleAttrib(false, LVecBase4(1, 1, 1, 1)));
97  }
98  virtual TypeHandle get_type() const {
99  return get_class_type();
100  }
101  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
102 
103 private:
104  static TypeHandle _type_handle;
105  static int _attrib_slot;
106 };
107 
108 #include "colorScaleAttrib.I"
109 
110 #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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Applies a scale to colors in the scene graph and on vertices.
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
virtual bool lower_attrib_can_override() const
Intended to be overridden by derived RenderAttrib types to specify how two consecutive RenderAttrib o...