From f33032dd6ba71185f7204c3a4101a1744ae488b2 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 5 Jul 2009 15:40:55 +0000 Subject: [PATCH] Add setDepthOffset etc. --- panda/src/pgraph/nodePath.cxx | 69 +++++++++++++++++++++++++++++++++++ panda/src/pgraph/nodePath.h | 5 +++ 2 files changed, 74 insertions(+) diff --git a/panda/src/pgraph/nodePath.cxx b/panda/src/pgraph/nodePath.cxx index 2ff212c41e..499605ad4f 100644 --- a/panda/src/pgraph/nodePath.cxx +++ b/panda/src/pgraph/nodePath.cxx @@ -35,6 +35,7 @@ #include "alphaTestAttrib.h" #include "depthTestAttrib.h" #include "depthWriteAttrib.h" +#include "depthOffsetAttrib.h" #include "shaderAttrib.h" #include "billboardEffect.h" #include "compassEffect.h" @@ -5251,6 +5252,74 @@ get_depth_write() const { return true; } +//////////////////////////////////////////////////////////////////// +// Function: NodePath::set_depth_offset +// Access: Published +// Description: This instructs the graphics driver to apply an +// offset or bias to the generated depth values for +// rendered polygons, before they are written to the +// depth buffer. This can be used to shift polygons +// forward slightly, to resolve depth conflicts, or +// self-shadowing artifacts on thin objects. +// The bias is always an integer number, and each +// integer increment represents the smallest possible +// increment in Z that is sufficient to completely +// resolve two coplanar polygons. Positive numbers +// are closer towards the camera. +//////////////////////////////////////////////////////////////////// +void NodePath:: +set_depth_offset(int bias, int priority) { + nassertv_always(!is_empty()); + + node()->set_attrib(DepthOffsetAttrib::make(bias), priority); +} + +//////////////////////////////////////////////////////////////////// +// Function: NodePath::clear_depth_offset +// Access: Published +// Description: Completely removes any depth-offset adjustment that +// may have been set on this node via set_depth_offset(). +//////////////////////////////////////////////////////////////////// +void NodePath:: +clear_depth_offset() { + nassertv_always(!is_empty()); + node()->clear_attrib(DepthOffsetAttrib::get_class_slot()); +} + +//////////////////////////////////////////////////////////////////// +// Function: NodePath::has_depth_offset +// Access: Published +// Description: Returns true if a depth-offset adjustment has been +// explicitly set on this particular node via +// set_depth_offset(). If this returns true, then +// get_depth_offset() may be called to determine which has +// been set. +//////////////////////////////////////////////////////////////////// +bool NodePath:: +has_depth_offset() const { + nassertr_always(!is_empty(), false); + return node()->has_attrib(DepthOffsetAttrib::get_class_slot()); +} + +//////////////////////////////////////////////////////////////////// +// Function: NodePath::get_depth_offset +// Access: Published +// Description: Returns the depth offset value if it has been +// specified using set_depth_offset, or 0 if not. +//////////////////////////////////////////////////////////////////// +int NodePath:: +get_depth_offset() const { + nassertr_always(!is_empty(), 0); + const RenderAttrib *attrib = + node()->get_attrib(DepthOffsetAttrib::get_class_slot()); + if (attrib != (const RenderAttrib *)NULL) { + const DepthOffsetAttrib *doa = DCAST(DepthOffsetAttrib, attrib); + return doa->get_offset(); + } + + return 0; +} + //////////////////////////////////////////////////////////////////// // Function: NodePath::do_billboard_axis // Access: Published diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index e251ff524c..7471c7752a 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -743,6 +743,11 @@ PUBLISHED: bool has_depth_write() const; bool get_depth_write() const; + void set_depth_offset(int bias, int priority = 0); + void clear_depth_offset(); + bool has_depth_offset() const; + int get_depth_offset() const; + void do_billboard_axis(const NodePath &camera, float offset); void do_billboard_point_eye(const NodePath &camera, float offset); void do_billboard_point_world(const NodePath &camera, float offset);