Panda3D
 All Classes Functions Variables Enumerations
depthTestAttrib.cxx
1 // Filename: depthTestAttrib.cxx
2 // Created by: drose (04Mar02)
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 #include "depthTestAttrib.h"
16 #include "graphicsStateGuardianBase.h"
17 #include "dcast.h"
18 #include "bamReader.h"
19 #include "bamWriter.h"
20 #include "datagram.h"
21 #include "datagramIterator.h"
22 
23 TypeHandle DepthTestAttrib::_type_handle;
24 int DepthTestAttrib::_attrib_slot;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: DepthTestAttrib::make
28 // Access: Published, Static
29 // Description: Constructs a new DepthTestAttrib object.
30 ////////////////////////////////////////////////////////////////////
32 make(DepthTestAttrib::PandaCompareFunc mode) {
33  DepthTestAttrib *attrib = new DepthTestAttrib(mode);
34  return return_new(attrib);
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: DepthTestAttrib::make_default
39 // Access: Published, Static
40 // Description: Returns a RenderAttrib that corresponds to whatever
41 // the standard default properties for render attributes
42 // of this type ought to be.
43 ////////////////////////////////////////////////////////////////////
45 make_default() {
46  return return_new(new DepthTestAttrib);
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: DepthTestAttrib::output
51 // Access: Public, Virtual
52 // Description:
53 ////////////////////////////////////////////////////////////////////
54 void DepthTestAttrib::
55 output(ostream &out) const {
56  out << get_type() << ":";
57  output_comparefunc(out,_mode);
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: DepthTestAttrib::compare_to_impl
62 // Access: Protected, Virtual
63 // Description: Intended to be overridden by derived DepthTestAttrib
64 // types to return a unique number indicating whether
65 // this DepthTestAttrib is equivalent to the other one.
66 //
67 // This should return 0 if the two DepthTestAttrib objects
68 // are equivalent, a number less than zero if this one
69 // should be sorted before the other one, and a number
70 // greater than zero otherwise.
71 //
72 // This will only be called with two DepthTestAttrib
73 // objects whose get_type() functions return the same.
74 ////////////////////////////////////////////////////////////////////
75 int DepthTestAttrib::
76 compare_to_impl(const RenderAttrib *other) const {
77  const DepthTestAttrib *ta;
78  DCAST_INTO_R(ta, other, 0);
79  return (int)_mode - (int)ta->_mode;
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: DepthTestAttrib::get_hash_impl
84 // Access: Protected, Virtual
85 // Description: Intended to be overridden by derived RenderAttrib
86 // types to return a unique hash for these particular
87 // properties. RenderAttribs that compare the same with
88 // compare_to_impl(), above, should return the same
89 // hash; RenderAttribs that compare differently should
90 // return a different hash.
91 ////////////////////////////////////////////////////////////////////
92 size_t DepthTestAttrib::
93 get_hash_impl() const {
94  size_t hash = 0;
95  hash = int_hash::add_hash(hash, (int)_mode);
96  return hash;
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: DepthTestAttrib::register_with_read_factory
101 // Access: Public, Static
102 // Description: Tells the BamReader how to create objects of type
103 // DepthTestAttrib.
104 ////////////////////////////////////////////////////////////////////
107  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: DepthTestAttrib::write_datagram
112 // Access: Public, Virtual
113 // Description: Writes the contents of this object to the datagram
114 // for shipping out to a Bam file.
115 ////////////////////////////////////////////////////////////////////
118  RenderAttrib::write_datagram(manager, dg);
119 
120  dg.add_int8(_mode);
121 }
122 
123 ////////////////////////////////////////////////////////////////////
124 // Function: DepthTestAttrib::make_from_bam
125 // Access: Protected, Static
126 // Description: This function is called by the BamReader's factory
127 // when a new object of type DepthTestAttrib is encountered
128 // in the Bam file. It should create the DepthTestAttrib
129 // and extract its information from the file.
130 ////////////////////////////////////////////////////////////////////
131 TypedWritable *DepthTestAttrib::
132 make_from_bam(const FactoryParams &params) {
133  DepthTestAttrib *attrib = new DepthTestAttrib;
134  DatagramIterator scan;
135  BamReader *manager;
136 
137  parse_params(params, scan, manager);
138  attrib->fillin(scan, manager);
139 
140  return attrib;
141 }
142 
143 ////////////////////////////////////////////////////////////////////
144 // Function: DepthTestAttrib::fillin
145 // Access: Protected
146 // Description: This internal function is called by make_from_bam to
147 // read in all of the relevant data from the BamFile for
148 // the new DepthTestAttrib.
149 ////////////////////////////////////////////////////////////////////
150 void DepthTestAttrib::
151 fillin(DatagramIterator &scan, BamReader *manager) {
152  RenderAttrib::fillin(scan, manager);
153 
154  _mode = (PandaCompareFunc)scan.get_int8();
155 }
PN_int8 get_int8()
Extracts a signed 8-bit integer.
Enables or disables writing to the depth buffer.
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
void add_int8(PN_int8 value)
Adds a signed 8-bit integer to the datagram.
Definition: datagram.I:128
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
static void register_with_read_factory()
Tells the BamReader how to create objects of type DepthTestAttrib.
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
Definition: stl_compares.I:122
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
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
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