Panda3D
colorAttrib.h
1 // Filename: colorAttrib.h
2 // Created by: drose (22Feb02)
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 COLORATTRIB_H
16 #define COLORATTRIB_H
17 
18 #include "pandabase.h"
19 
20 #include "renderAttrib.h"
21 #include "luse.h"
22 
23 class FactoryParams;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : ColorAttrib
27 // Description : Indicates what color should be applied to renderable
28 // geometry.
29 ////////////////////////////////////////////////////////////////////
30 class EXPCL_PANDA_PGRAPH ColorAttrib : public RenderAttrib {
31 PUBLISHED:
32  enum Type {
33  T_vertex, T_flat, T_off
34  };
35 
36 private:
37  INLINE ColorAttrib(Type type, const LColor &color);
38 
39 PUBLISHED:
40  static CPT(RenderAttrib) make_vertex();
41  static CPT(RenderAttrib) make_flat(const LColor &color);
42  static CPT(RenderAttrib) make_off();
43  static CPT(RenderAttrib) make_default();
44 
45  INLINE Type get_color_type() const;
46  INLINE const LColor &get_color() const;
47 
48 public:
49  virtual void output(ostream &out) const;
50 
51 protected:
52  virtual int compare_to_impl(const RenderAttrib *other) const;
53  virtual size_t get_hash_impl() const;
54  virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
55 
56 private:
57  void quantize_color();
58 
59 private:
60  Type _type;
61  LColor _color;
62  static CPT(RenderAttrib) _off;
63  static CPT(RenderAttrib) _vertex;
64 
65 PUBLISHED:
66  static int get_class_slot() {
67  return _attrib_slot;
68  }
69  virtual int get_slot() const {
70  return get_class_slot();
71  }
72 
73 public:
74  static void register_with_read_factory();
75  virtual void write_datagram(BamWriter *manager, Datagram &dg);
76 
77 protected:
78  static TypedWritable *make_from_bam(const FactoryParams &params);
79  void fillin(DatagramIterator &scan, BamReader *manager);
80 
81 public:
82  static TypeHandle get_class_type() {
83  return _type_handle;
84  }
85  static void init_type() {
86  RenderAttrib::init_type();
87  register_type(_type_handle, "ColorAttrib",
88  RenderAttrib::get_class_type());
89  _attrib_slot = register_slot(_type_handle, 100, make_default);
90  }
91  virtual TypeHandle get_type() const {
92  return get_class_type();
93  }
94  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
95 
96 private:
97  static TypeHandle _type_handle;
98  static int _attrib_slot;
99 };
100 
101 #include "colorAttrib.I"
102 
103 #endif
104 
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
Indicates what color should be applied to renderable geometry.
Definition: colorAttrib.h:30
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