From 75bc1693840129dfc079825cf8fa2d6dce4975eb Mon Sep 17 00:00:00 2001 From: cxgeorge <> Date: Tue, 14 May 2002 00:18:49 +0000 Subject: [PATCH] add alphatest attr, remove incorrect comments --- panda/src/pgraph/Sources.pp | 3 + panda/src/pgraph/alphaTestAttrib.I | 50 +++++++ panda/src/pgraph/alphaTestAttrib.cxx | 191 ++++++++++++++++++++++++ panda/src/pgraph/alphaTestAttrib.h | 92 ++++++++++++ panda/src/pgraph/colorBlendAttrib.cxx | 6 +- panda/src/pgraph/colorWriteAttrib.cxx | 6 +- panda/src/pgraph/depthTestAttrib.cxx | 6 +- panda/src/pgraph/depthWriteAttrib.cxx | 6 +- panda/src/pgraph/pgraph_composite1.cxx | 3 + panda/src/pgraph/textureApplyAttrib.cxx | 6 +- panda/src/pgraph/transparencyAttrib.cxx | 6 +- 11 files changed, 345 insertions(+), 30 deletions(-) create mode 100644 panda/src/pgraph/alphaTestAttrib.I create mode 100644 panda/src/pgraph/alphaTestAttrib.cxx create mode 100644 panda/src/pgraph/alphaTestAttrib.h diff --git a/panda/src/pgraph/Sources.pp b/panda/src/pgraph/Sources.pp index 238b81d5e8..3e705e1431 100644 --- a/panda/src/pgraph/Sources.pp +++ b/panda/src/pgraph/Sources.pp @@ -6,6 +6,7 @@ #define TARGET pgraph #define SOURCES \ + alphaTestAttrib.I alphaTestAttrib.h \ ambientLight.I ambientLight.h \ billboardEffect.I billboardEffect.h \ binCullHandler.I binCullHandler.h \ @@ -76,6 +77,7 @@ #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define INCLUDED_SOURCES \ + alphaTestAttrib.cxx \ ambientLight.cxx \ billboardEffect.cxx \ binCullHandler.cxx \ @@ -151,6 +153,7 @@ #endif #define INSTALL_HEADERS \ + alphaTestAttrib.I alphaTestAttrib.h \ ambientLight.I ambientLight.h \ billboardEffect.I billboardEffect.h \ binCullHandler.I binCullHandler.h \ diff --git a/panda/src/pgraph/alphaTestAttrib.I b/panda/src/pgraph/alphaTestAttrib.I new file mode 100644 index 0000000000..3b085bfee4 --- /dev/null +++ b/panda/src/pgraph/alphaTestAttrib.I @@ -0,0 +1,50 @@ +// Filename: alphaTestAttrib.I +// Created by: drose (04Mar02) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::Constructor +// Access: Private +// Description: Use AlphaTestAttrib::make() to construct a new +// AlphaTestAttrib object. +//////////////////////////////////////////////////////////////////// +INLINE AlphaTestAttrib:: +AlphaTestAttrib(AlphaTestAttrib::Mode mode,unsigned int reference_alpha) : + _mode(mode), _reference_alpha(reference_alpha) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::get_mode +// Access: Published +// Description: Returns the alpha write mode. +//////////////////////////////////////////////////////////////////// +INLINE AlphaTestAttrib::Mode AlphaTestAttrib:: +get_mode() const { + return _mode; +} + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::get_mode +// Access: Published +// Description: Returns the alpha reference value. +//////////////////////////////////////////////////////////////////// +INLINE unsigned int AlphaTestAttrib:: +get_reference_alpha(void) const { + return _reference_alpha; +} diff --git a/panda/src/pgraph/alphaTestAttrib.cxx b/panda/src/pgraph/alphaTestAttrib.cxx new file mode 100644 index 0000000000..3071e8334f --- /dev/null +++ b/panda/src/pgraph/alphaTestAttrib.cxx @@ -0,0 +1,191 @@ +// Filename: alphaTestAttrib.cxx +// Created by: drose (04Mar02) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "alphaTestAttrib.h" +#include "graphicsStateGuardianBase.h" +#include "dcast.h" +#include "bamReader.h" +#include "bamWriter.h" +#include "datagram.h" +#include "datagramIterator.h" + +TypeHandle AlphaTestAttrib::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::make +// Access: Published, Static +// Description: Constructs a new AlphaTestAttrib object. +//////////////////////////////////////////////////////////////////// +CPT(RenderAttrib) AlphaTestAttrib:: +make(AlphaTestAttrib::Mode mode, unsigned int reference_value) { + AlphaTestAttrib *attrib = new AlphaTestAttrib(mode,reference_value); + return return_new(attrib); +} + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::issue +// Access: Public, Virtual +// Description: Calls the appropriate method on the indicated GSG +// to issue the graphics commands appropriate to the +// given attribute. This is normally called +// (indirectly) only from +// GraphicsStateGuardian::set_state() or modify_state(). +//////////////////////////////////////////////////////////////////// +void AlphaTestAttrib:: +issue(GraphicsStateGuardianBase *gsg) const { + gsg->issue_alpha_test(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::output +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void AlphaTestAttrib:: +output(ostream &out) const { + out << get_type() << ":"; + switch (get_mode()) { + case M_always: + out << "always"; + break; + + case M_never: + out << "never"; + break; + + case M_less: + out << "less"; + break; + + case M_equal: + out << "equal"; + break; + + case M_less_equal: + out << "less_equal"; + break; + + case M_greater: + out << "greater"; + break; + + case M_not_equal: + out << "not_equal"; + break; + + case M_greater_equal: + out << "greater_equal"; + break; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::compare_to_impl +// Access: Protected, Virtual +// Description: Intended to be overridden by derived AlphaTestAttrib +// types to return a unique number indicating whether +// this AlphaTestAttrib is equivalent to the other one. +// +// This should return 0 if the two AlphaTestAttrib objects +// are equivalent, a number less than zero if this one +// should be sorted before the other one, and a number +// greater than zero otherwise. +// +// This will only be called with two AlphaTestAttrib +// objects whose get_type() functions return the same. +//////////////////////////////////////////////////////////////////// +int AlphaTestAttrib:: +compare_to_impl(const RenderAttrib *other) const { + const AlphaTestAttrib *ta; + DCAST_INTO_R(ta, other, 0); + return (int)_mode - (int)ta->_mode; +} + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::make_default_impl +// Access: Protected, Virtual +// Description: Intended to be overridden by derived AlphaTestAttrib +// types to specify what the default property for a +// AlphaTestAttrib of this type should be. +// +// This should return a newly-allocated AlphaTestAttrib of +// the same type that corresponds to whatever the +// standard default for this kind of AlphaTestAttrib is. +//////////////////////////////////////////////////////////////////// +RenderAttrib *AlphaTestAttrib:: +make_default_impl() const { + return new AlphaTestAttrib; +} + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::register_with_read_factory +// Access: Public, Static +// Description: Tells the BamReader how to create objects of type +// AlphaTestAttrib. +//////////////////////////////////////////////////////////////////// +void AlphaTestAttrib:: +register_with_read_factory() { + BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); +} + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::write_datagram +// Access: Public, Virtual +// Description: Writes the contents of this object to the datagram +// for shipping out to a Bam file. +//////////////////////////////////////////////////////////////////// +void AlphaTestAttrib:: +write_datagram(BamWriter *manager, Datagram &dg) { + RenderAttrib::write_datagram(manager, dg); + + dg.add_int8(_mode); +} + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::make_from_bam +// Access: Protected, Static +// Description: This function is called by the BamReader's factory +// when a new object of type AlphaTestAttrib is encountered +// in the Bam file. It should create the AlphaTestAttrib +// and extract its information from the file. +//////////////////////////////////////////////////////////////////// +TypedWritable *AlphaTestAttrib:: +make_from_bam(const FactoryParams ¶ms) { + AlphaTestAttrib *attrib = new AlphaTestAttrib; + DatagramIterator scan; + BamReader *manager; + + parse_params(params, scan, manager); + attrib->fillin(scan, manager); + + return attrib; +} + +//////////////////////////////////////////////////////////////////// +// Function: AlphaTestAttrib::fillin +// Access: Protected +// Description: This internal function is called by make_from_bam to +// read in all of the relevant data from the BamFile for +// the new AlphaTestAttrib. +//////////////////////////////////////////////////////////////////// +void AlphaTestAttrib:: +fillin(DatagramIterator &scan, BamReader *manager) { + RenderAttrib::fillin(scan, manager); + + _mode = (Mode)scan.get_int8(); +} diff --git a/panda/src/pgraph/alphaTestAttrib.h b/panda/src/pgraph/alphaTestAttrib.h new file mode 100644 index 0000000000..93bf062ff7 --- /dev/null +++ b/panda/src/pgraph/alphaTestAttrib.h @@ -0,0 +1,92 @@ +// Filename: alphaTestAttrib.h +// Created by: drose (04Mar02) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#ifndef ALPHATESTATTRIB_H +#define ALPHATESTATTRIB_H + +#include "pandabase.h" +#include "renderAttrib.h" + +//////////////////////////////////////////////////////////////////// +// Class : AlphaTestAttrib +// Description : Enables or disables writing of pixel to framebuffer +// based on its alpha value relative to a reference alpha value +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA AlphaTestAttrib : public RenderAttrib { +PUBLISHED: + enum Mode { // defined to match D3DCMPFUNC + M_never=1, // Never draw. + M_less, // incoming < reference_alpha + M_equal, // incoming == reference_alpha + M_less_equal, // incoming <= reference_alpha + M_greater, // incoming > reference_alpha + M_not_equal, // incoming != reference_alpha + M_greater_equal, // incoming >= reference_alpha + M_always // Always draw. + }; + +private: + INLINE AlphaTestAttrib(Mode mode = M_always,unsigned int reference_alpha = 0xFF); + +PUBLISHED: + static CPT(RenderAttrib) make(Mode mode,unsigned int reference_alpha); + INLINE unsigned int get_reference_alpha() const; + INLINE Mode get_mode() const; + +public: + virtual void issue(GraphicsStateGuardianBase *gsg) const; + virtual void output(ostream &out) const; + +protected: + virtual int compare_to_impl(const RenderAttrib *other) const; + virtual RenderAttrib *make_default_impl() const; + +private: + Mode _mode; + unsigned int _reference_alpha; + +public: + static void register_with_read_factory(); + virtual void write_datagram(BamWriter *manager, Datagram &dg); + +protected: + static TypedWritable *make_from_bam(const FactoryParams ¶ms); + void fillin(DatagramIterator &scan, BamReader *manager); + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + RenderAttrib::init_type(); + register_type(_type_handle, "AlphaTestAttrib", + RenderAttrib::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +private: + static TypeHandle _type_handle; +}; + +#include "alphaTestAttrib.I" + +#endif + diff --git a/panda/src/pgraph/colorBlendAttrib.cxx b/panda/src/pgraph/colorBlendAttrib.cxx index 1a66a714fd..95020b9790 100644 --- a/panda/src/pgraph/colorBlendAttrib.cxx +++ b/panda/src/pgraph/colorBlendAttrib.cxx @@ -29,11 +29,7 @@ TypeHandle ColorBlendAttrib::_type_handle; //////////////////////////////////////////////////////////////////// // Function: ColorBlendAttrib::make // Access: Published, Static -// Description: Constructs a new ColorBlendAttrib object that specifies -// how to cull geometry. By Panda convention, vertices -// are ordered counterclockwise when seen from the -// front, so the M_cull_clockwise will cull backfacing -// polygons. +// Description: Constructs a new ColorBlendAttrib object. //////////////////////////////////////////////////////////////////// CPT(RenderAttrib) ColorBlendAttrib:: make(ColorBlendAttrib::Mode mode) { diff --git a/panda/src/pgraph/colorWriteAttrib.cxx b/panda/src/pgraph/colorWriteAttrib.cxx index ca012fd98c..9ec8dffa93 100644 --- a/panda/src/pgraph/colorWriteAttrib.cxx +++ b/panda/src/pgraph/colorWriteAttrib.cxx @@ -29,11 +29,7 @@ TypeHandle ColorWriteAttrib::_type_handle; //////////////////////////////////////////////////////////////////// // Function: ColorWriteAttrib::make // Access: Published, Static -// Description: Constructs a new ColorWriteAttrib object that specifies -// how to cull geometry. By Panda convention, vertices -// are ordered counterclockwise when seen from the -// front, so the M_cull_clockwise will cull backfacing -// polygons. +// Description: Constructs a new ColorWriteAttrib object. //////////////////////////////////////////////////////////////////// CPT(RenderAttrib) ColorWriteAttrib:: make(ColorWriteAttrib::Mode mode) { diff --git a/panda/src/pgraph/depthTestAttrib.cxx b/panda/src/pgraph/depthTestAttrib.cxx index 488788a443..cafa2818b6 100644 --- a/panda/src/pgraph/depthTestAttrib.cxx +++ b/panda/src/pgraph/depthTestAttrib.cxx @@ -29,11 +29,7 @@ TypeHandle DepthTestAttrib::_type_handle; //////////////////////////////////////////////////////////////////// // Function: DepthTestAttrib::make // Access: Published, Static -// Description: Constructs a new DepthTestAttrib object that specifies -// how to cull geometry. By Panda convention, vertices -// are ordered counterclockwise when seen from the -// front, so the M_cull_clockwise will cull backfacing -// polygons. +// Description: Constructs a new DepthTestAttrib object. //////////////////////////////////////////////////////////////////// CPT(RenderAttrib) DepthTestAttrib:: make(DepthTestAttrib::Mode mode) { diff --git a/panda/src/pgraph/depthWriteAttrib.cxx b/panda/src/pgraph/depthWriteAttrib.cxx index 7779add63d..9d7d74b2bb 100644 --- a/panda/src/pgraph/depthWriteAttrib.cxx +++ b/panda/src/pgraph/depthWriteAttrib.cxx @@ -29,11 +29,7 @@ TypeHandle DepthWriteAttrib::_type_handle; //////////////////////////////////////////////////////////////////// // Function: DepthWriteAttrib::make // Access: Published, Static -// Description: Constructs a new DepthWriteAttrib object that specifies -// how to cull geometry. By Panda convention, vertices -// are ordered counterclockwise when seen from the -// front, so the M_cull_clockwise will cull backfacing -// polygons. +// Description: Constructs a new DepthWriteAttrib object. //////////////////////////////////////////////////////////////////// CPT(RenderAttrib) DepthWriteAttrib:: make(DepthWriteAttrib::Mode mode) { diff --git a/panda/src/pgraph/pgraph_composite1.cxx b/panda/src/pgraph/pgraph_composite1.cxx index 877818d8c9..6e09e891db 100644 --- a/panda/src/pgraph/pgraph_composite1.cxx +++ b/panda/src/pgraph/pgraph_composite1.cxx @@ -22,6 +22,7 @@ #include "depthOffsetAttrib.cxx" #include "depthTestAttrib.cxx" #include "depthWriteAttrib.cxx" +#include "alphaTestAttrib.cxx" #include "directionalLight.cxx" #include "drawCullHandler.cxx" #include "findApproxPath.cxx" @@ -31,3 +32,5 @@ #include "fogAttrib.cxx" #include "geomNode.cxx" #include "geomTransformer.cxx" + + diff --git a/panda/src/pgraph/textureApplyAttrib.cxx b/panda/src/pgraph/textureApplyAttrib.cxx index 64897fe8b3..7292f963ec 100644 --- a/panda/src/pgraph/textureApplyAttrib.cxx +++ b/panda/src/pgraph/textureApplyAttrib.cxx @@ -29,11 +29,7 @@ TypeHandle TextureApplyAttrib::_type_handle; //////////////////////////////////////////////////////////////////// // Function: TextureApplyAttrib::make // Access: Published, Static -// Description: Constructs a new TextureApplyAttrib object that specifies -// how to cull geometry. By Panda convention, vertices -// are ordered counterclockwise when seen from the -// front, so the M_cull_clockwise will cull backfacing -// polygons. +// Description: Constructs a new TextureApplyAttrib object. //////////////////////////////////////////////////////////////////// CPT(RenderAttrib) TextureApplyAttrib:: make(TextureApplyAttrib::Mode mode) { diff --git a/panda/src/pgraph/transparencyAttrib.cxx b/panda/src/pgraph/transparencyAttrib.cxx index 5a935462a2..b6044cd28d 100644 --- a/panda/src/pgraph/transparencyAttrib.cxx +++ b/panda/src/pgraph/transparencyAttrib.cxx @@ -29,11 +29,7 @@ TypeHandle TransparencyAttrib::_type_handle; //////////////////////////////////////////////////////////////////// // Function: TransparencyAttrib::make // Access: Published, Static -// Description: Constructs a new TransparencyAttrib object that specifies -// how to cull geometry. By Panda convention, vertices -// are ordered counterclockwise when seen from the -// front, so the M_cull_clockwise will cull backfacing -// polygons. +// Description: Constructs a new TransparencyAttrib object. //////////////////////////////////////////////////////////////////// CPT(RenderAttrib) TransparencyAttrib:: make(TransparencyAttrib::Mode mode) {