Panda3D
depthOffsetAttrib.h
1 // Filename: depthOffsetAttrib.h
2 // Created by: drose (14Mar02)
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 DEPTHOFFSETATTRIB_H
16 #define DEPTHOFFSETATTRIB_H
17 
18 #include "pandabase.h"
19 
20 #include "renderAttrib.h"
21 #include "luse.h"
22 
23 class FactoryParams;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : DepthOffsetAttrib
27 // Description : This is a special kind of attribute that instructs
28 // the graphics driver to apply an offset or bias to the
29 // generated depth values for rendered polygons, before
30 // they are written to the depth buffer.
31 //
32 // This can be used to shift polygons forward slightly,
33 // to resolve depth conflicts. The cull traverser may
34 // optionally use this, for instance, to implement
35 // decals. However, driver support for this feature
36 // seems to be spotty, so use with caution.
37 //
38 // The bias is always an integer number, and each
39 // integer increment represents the smallest possible
40 // increment in Z that is sufficient to completely
41 // resolve two coplanar polygons. Positive numbers are
42 // closer towards the camera.
43 //
44 // Nested DepthOffsetAttrib values accumulate; that is,
45 // a DepthOffsetAttrib with a value of 1 beneath another
46 // DepthOffsetAttrib with a value of 2 presents a net
47 // offset of 3. (A DepthOffsetAttrib will not, however,
48 // combine with any other DepthOffsetAttribs with a
49 // lower override parameter.) The net value should
50 // probably not exceed 16 or drop below 0 for maximum
51 // portability.
52 //
53 // Also, and only tangentially related, the
54 // DepthOffsetAttrib can be used to constrain the Z
55 // output value to a subset of the usual [0, 1] range
56 // (or reversing its direction) by specifying a new
57 // min_value and max_value.
58 ////////////////////////////////////////////////////////////////////
59 class EXPCL_PANDA_PGRAPH DepthOffsetAttrib : public RenderAttrib {
60 private:
61  INLINE DepthOffsetAttrib(int offset, PN_stdfloat min_value, PN_stdfloat max_value);
62 
63 PUBLISHED:
64  static CPT(RenderAttrib) make(int offset = 1);
65  static CPT(RenderAttrib) make(int offset, PN_stdfloat min_value, PN_stdfloat max_value);
66  static CPT(RenderAttrib) make_default();
67 
68  INLINE int get_offset() const;
69  INLINE PN_stdfloat get_min_value() const;
70  INLINE PN_stdfloat get_max_value() const;
71 
72 public:
73  virtual void output(ostream &out) const;
74 
75 protected:
76  virtual int compare_to_impl(const RenderAttrib *other) const;
77  virtual size_t get_hash_impl() const;
78  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
79  virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
80 
81 private:
82  int _offset;
83  PN_stdfloat _min_value;
84  PN_stdfloat _max_value;
85 
86 PUBLISHED:
87  static int get_class_slot() {
88  return _attrib_slot;
89  }
90  virtual int get_slot() const {
91  return get_class_slot();
92  }
93 
94 public:
95  static void register_with_read_factory();
96  virtual void write_datagram(BamWriter *manager, Datagram &dg);
97 
98 protected:
99  static TypedWritable *make_from_bam(const FactoryParams &params);
100  void fillin(DatagramIterator &scan, BamReader *manager);
101 
102 public:
103  static TypeHandle get_class_type() {
104  return _type_handle;
105  }
106  static void init_type() {
107  RenderAttrib::init_type();
108  register_type(_type_handle, "DepthOffsetAttrib",
109  RenderAttrib::get_class_type());
110  _attrib_slot = register_slot(_type_handle, 100, make_default);
111  }
112  virtual TypeHandle get_type() const {
113  return get_class_type();
114  }
115  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
116 
117 private:
118  static TypeHandle _type_handle;
119  static int _attrib_slot;
120 };
121 
122 #include "depthOffsetAttrib.I"
123 
124 #endif
125 
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 is a special kind of attribute that instructs the graphics driver to apply an offset or bias to ...
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