Panda3D
rescaleNormalAttrib.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 rescaleNormalAttrib.h
10  * @author drose
11  * @date 2004-12-30
12  */
13 
14 #ifndef RESCALENORMALATTRIB_H
15 #define RESCALENORMALATTRIB_H
16 
17 #include "pandabase.h"
18 
19 #include "renderAttrib.h"
20 
21 class FactoryParams;
22 
23 /**
24  * Specifies how polygons are to be drawn.
25  */
26 class EXPCL_PANDA_PGRAPH RescaleNormalAttrib : public RenderAttrib {
27 PUBLISHED:
28  enum Mode {
29  // No adjustments are made to normals.
30  M_none,
31 
32  // Normals are counterscaled by the transform's uniform scale, if
33  // supported by the graphics API.
34  M_rescale,
35 
36  // Normals are scaled to unit length; potentially expensive.
37  M_normalize,
38 
39  // Normals are counterscaled in the presence of a uniform scale transform,
40  // or normalized in the presence of a non-uniform scale transform.
41  M_auto,
42  };
43 
44 private:
45  INLINE RescaleNormalAttrib(Mode mode);
46 
47 PUBLISHED:
48  static CPT(RenderAttrib) make(Mode mode);
49  INLINE static CPT(RenderAttrib) make_default();
50 
51  INLINE Mode get_mode() const;
52  MAKE_PROPERTY(mode, get_mode);
53 
54 public:
55  virtual void output(std::ostream &out) const;
56 
57 protected:
58  virtual int compare_to_impl(const RenderAttrib *other) const;
59  virtual size_t get_hash_impl() const;
60 
61 private:
62  Mode _mode;
63 
64  // There are so few possible combinations, and it's used fairly often, so we
65  // keep an array of the possible attributes.
66  static CPT(RenderAttrib) _attribs[M_auto + 1];
67 
68 PUBLISHED:
69  static int get_class_slot() {
70  return _attrib_slot;
71  }
72  virtual int get_slot() const {
73  return get_class_slot();
74  }
75  MAKE_PROPERTY(class_slot, get_class_slot);
76 
77 public:
78  static void register_with_read_factory();
79  virtual void write_datagram(BamWriter *manager, Datagram &dg);
80 
81 protected:
82  static TypedWritable *make_from_bam(const FactoryParams &params);
83  void fillin(DatagramIterator &scan, BamReader *manager);
84 
85 public:
86  static TypeHandle get_class_type() {
87  return _type_handle;
88  }
89  static void init_type();
90  virtual TypeHandle get_type() const {
91  return get_class_type();
92  }
93  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
94 
95 private:
96  static TypeHandle _type_handle;
97  static int _attrib_slot;
98 };
99 
100 EXPCL_PANDA_PGRAPH std::ostream &operator << (std::ostream &out, RescaleNormalAttrib::Mode mode);
101 EXPCL_PANDA_PGRAPH std::istream &operator >> (std::istream &in, RescaleNormalAttrib::Mode &mode);
102 
103 #include "rescaleNormalAttrib.I"
104 
105 #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
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
Specifies how polygons are to be drawn.
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