Panda3D
depthOffsetAttrib.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 depthOffsetAttrib.h
10  * @author drose
11  * @date 2002-03-14
12  */
13 
14 #ifndef DEPTHOFFSETATTRIB_H
15 #define DEPTHOFFSETATTRIB_H
16 
17 #include "pandabase.h"
18 
19 #include "renderAttrib.h"
20 #include "luse.h"
21 
22 class FactoryParams;
23 
24 /**
25  * This is a special kind of attribute that instructs the graphics driver to
26  * apply an offset or bias to the generated depth values for rendered
27  * polygons, before they are written to the depth buffer.
28  *
29  * This can be used to shift polygons forward slightly, to resolve depth
30  * conflicts. The cull traverser may optionally use this, for instance, to
31  * implement decals. However, driver support for this feature seems to be
32  * spotty, so use with caution.
33  *
34  * The bias is always an integer number, and each integer increment represents
35  * the smallest possible increment in Z that is sufficient to completely
36  * resolve two coplanar polygons. Positive numbers are closer towards the
37  * camera.
38  *
39  * Nested DepthOffsetAttrib values accumulate; that is, a DepthOffsetAttrib
40  * with a value of 1 beneath another DepthOffsetAttrib with a value of 2
41  * presents a net offset of 3. (A DepthOffsetAttrib will not, however,
42  * combine with any other DepthOffsetAttribs with a lower override parameter.)
43  * The net value should probably not exceed 16 or drop below 0 for maximum
44  * portability.
45  *
46  * Also, and only tangentially related, the DepthOffsetAttrib can be used to
47  * constrain the Z output value to a subset of the usual [0, 1] range (or
48  * reversing its direction) by specifying a new min_value and max_value.
49  */
50 class EXPCL_PANDA_PGRAPH DepthOffsetAttrib : public RenderAttrib {
51 private:
52  INLINE DepthOffsetAttrib(int offset, PN_stdfloat min_value, PN_stdfloat max_value);
53 
54 PUBLISHED:
55  static CPT(RenderAttrib) make(int offset = 1);
56  static CPT(RenderAttrib) make(int offset, PN_stdfloat min_value, PN_stdfloat max_value);
57  static CPT(RenderAttrib) make_default();
58 
59  INLINE int get_offset() const;
60  INLINE PN_stdfloat get_min_value() const;
61  INLINE PN_stdfloat get_max_value() const;
62 
63 PUBLISHED:
64  MAKE_PROPERTY(offset, get_offset);
65  MAKE_PROPERTY(min_value, get_min_value);
66  MAKE_PROPERTY(max_value, get_max_value);
67 
68 public:
69  virtual void output(std::ostream &out) const;
70 
71 protected:
72  virtual int compare_to_impl(const RenderAttrib *other) const;
73  virtual size_t get_hash_impl() const;
74  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
75  virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
76 
77 private:
78  int _offset;
79  PN_stdfloat _min_value;
80  PN_stdfloat _max_value;
81 
82 PUBLISHED:
83  static int get_class_slot() {
84  return _attrib_slot;
85  }
86  virtual int get_slot() const {
87  return get_class_slot();
88  }
89  MAKE_PROPERTY(class_slot, get_class_slot);
90 
91 public:
92  static void register_with_read_factory();
93  virtual void write_datagram(BamWriter *manager, Datagram &dg);
94 
95 protected:
96  static TypedWritable *make_from_bam(const FactoryParams &params);
97  void fillin(DatagramIterator &scan, BamReader *manager);
98 
99 public:
100  static TypeHandle get_class_type() {
101  return _type_handle;
102  }
103  static void init_type() {
104  RenderAttrib::init_type();
105  register_type(_type_handle, "DepthOffsetAttrib",
106  RenderAttrib::get_class_type());
107  _attrib_slot = register_slot(_type_handle, 100,
108  new DepthOffsetAttrib(0, 0, 1));
109  }
110  virtual TypeHandle get_type() const {
111  return get_class_type();
112  }
113  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
114 
115 private:
116  static TypeHandle _type_handle;
117  static int _attrib_slot;
118 };
119 
120 #include "depthOffsetAttrib.I"
121 
122 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
This is a special kind of attribute that instructs the graphics driver to apply an offset or bias to ...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
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
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.