Panda3D
|
00001 // Filename: depthOffsetAttrib.h 00002 // Created by: drose (14Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef DEPTHOFFSETATTRIB_H 00016 #define DEPTHOFFSETATTRIB_H 00017 00018 #include "pandabase.h" 00019 00020 #include "renderAttrib.h" 00021 #include "luse.h" 00022 00023 class FactoryParams; 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Class : DepthOffsetAttrib 00027 // Description : This is a special kind of attribute that instructs 00028 // the graphics driver to apply an offset or bias to the 00029 // generated depth values for rendered polygons, before 00030 // they are written to the depth buffer. 00031 // 00032 // This can be used to shift polygons forward slightly, 00033 // to resolve depth conflicts. The cull traverser may 00034 // optionally use this, for instance, to implement 00035 // decals. However, driver support for this feature 00036 // seems to be spotty, so use with caution. 00037 // 00038 // The bias is always an integer number, and each 00039 // integer increment represents the smallest possible 00040 // increment in Z that is sufficient to completely 00041 // resolve two coplanar polygons. Positive numbers are 00042 // closer towards the camera. 00043 // 00044 // Nested DepthOffsetAttrib values accumulate; that is, 00045 // a DepthOffsetAttrib with a value of 1 beneath another 00046 // DepthOffsetAttrib with a value of 2 presents a net 00047 // offset of 3. (A DepthOffsetAttrib will not, however, 00048 // combine with any other DepthOffsetAttribs with a 00049 // lower override parameter.) The net value should 00050 // probably not exceed 16 or drop below 0 for maximum 00051 // portability. 00052 //////////////////////////////////////////////////////////////////// 00053 class EXPCL_PANDA_PGRAPH DepthOffsetAttrib : public RenderAttrib { 00054 private: 00055 INLINE DepthOffsetAttrib(int offset); 00056 00057 PUBLISHED: 00058 static CPT(RenderAttrib) make(int offset = 1); 00059 static CPT(RenderAttrib) make_default(); 00060 00061 INLINE int get_offset() const; 00062 00063 public: 00064 virtual void output(ostream &out) const; 00065 00066 protected: 00067 virtual int compare_to_impl(const RenderAttrib *other) const; 00068 virtual size_t get_hash_impl() const; 00069 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const; 00070 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const; 00071 00072 private: 00073 int _offset; 00074 00075 PUBLISHED: 00076 static int get_class_slot() { 00077 return _attrib_slot; 00078 } 00079 virtual int get_slot() const { 00080 return get_class_slot(); 00081 } 00082 00083 public: 00084 static void register_with_read_factory(); 00085 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00086 00087 protected: 00088 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00089 void fillin(DatagramIterator &scan, BamReader *manager); 00090 00091 public: 00092 static TypeHandle get_class_type() { 00093 return _type_handle; 00094 } 00095 static void init_type() { 00096 RenderAttrib::init_type(); 00097 register_type(_type_handle, "DepthOffsetAttrib", 00098 RenderAttrib::get_class_type()); 00099 _attrib_slot = register_slot(_type_handle, 100, make_default); 00100 } 00101 virtual TypeHandle get_type() const { 00102 return get_class_type(); 00103 } 00104 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00105 00106 private: 00107 static TypeHandle _type_handle; 00108 static int _attrib_slot; 00109 }; 00110 00111 #include "depthOffsetAttrib.I" 00112 00113 #endif 00114