Panda3D
 All Classes Functions Variables Enumerations
depthWriteAttrib.cxx
1 // Filename: depthWriteAttrib.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 "depthWriteAttrib.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 DepthWriteAttrib::_type_handle;
24 int DepthWriteAttrib::_attrib_slot;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: DepthWriteAttrib::make
28 // Access: Published, Static
29 // Description: Constructs a new DepthWriteAttrib object.
30 ////////////////////////////////////////////////////////////////////
32 make(DepthWriteAttrib::Mode mode) {
33  DepthWriteAttrib *attrib = new DepthWriteAttrib(mode);
34  return return_new(attrib);
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: DepthWriteAttrib::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 DepthWriteAttrib);
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: DepthWriteAttrib::output
51 // Access: Public, Virtual
52 // Description:
53 ////////////////////////////////////////////////////////////////////
54 void DepthWriteAttrib::
55 output(ostream &out) const {
56  out << get_type() << ":";
57  switch (get_mode()) {
58  case M_off:
59  out << "off";
60  break;
61  case M_on:
62  out << "on";
63  break;
64  }
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: DepthWriteAttrib::compare_to_impl
69 // Access: Protected, Virtual
70 // Description: Intended to be overridden by derived DepthWriteAttrib
71 // types to return a unique number indicating whether
72 // this DepthWriteAttrib is equivalent to the other one.
73 //
74 // This should return 0 if the two DepthWriteAttrib objects
75 // are equivalent, a number less than zero if this one
76 // should be sorted before the other one, and a number
77 // greater than zero otherwise.
78 //
79 // This will only be called with two DepthWriteAttrib
80 // objects whose get_type() functions return the same.
81 ////////////////////////////////////////////////////////////////////
82 int DepthWriteAttrib::
83 compare_to_impl(const RenderAttrib *other) const {
84  const DepthWriteAttrib *ta;
85  DCAST_INTO_R(ta, other, 0);
86  return (int)_mode - (int)ta->_mode;
87 }
88 
89 ////////////////////////////////////////////////////////////////////
90 // Function: DepthWriteAttrib::get_hash_impl
91 // Access: Protected, Virtual
92 // Description: Intended to be overridden by derived RenderAttrib
93 // types to return a unique hash for these particular
94 // properties. RenderAttribs that compare the same with
95 // compare_to_impl(), above, should return the same
96 // hash; RenderAttribs that compare differently should
97 // return a different hash.
98 ////////////////////////////////////////////////////////////////////
99 size_t DepthWriteAttrib::
100 get_hash_impl() const {
101  size_t hash = 0;
102  hash = int_hash::add_hash(hash, (int)_mode);
103  return hash;
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: DepthWriteAttrib::register_with_read_factory
108 // Access: Public, Static
109 // Description: Tells the BamReader how to create objects of type
110 // DepthWriteAttrib.
111 ////////////////////////////////////////////////////////////////////
114  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: DepthWriteAttrib::write_datagram
119 // Access: Public, Virtual
120 // Description: Writes the contents of this object to the datagram
121 // for shipping out to a Bam file.
122 ////////////////////////////////////////////////////////////////////
125  RenderAttrib::write_datagram(manager, dg);
126 
127  dg.add_int8(_mode);
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: DepthWriteAttrib::make_from_bam
132 // Access: Protected, Static
133 // Description: This function is called by the BamReader's factory
134 // when a new object of type DepthWriteAttrib is encountered
135 // in the Bam file. It should create the DepthWriteAttrib
136 // and extract its information from the file.
137 ////////////////////////////////////////////////////////////////////
138 TypedWritable *DepthWriteAttrib::
139 make_from_bam(const FactoryParams &params) {
140  DepthWriteAttrib *attrib = new DepthWriteAttrib;
141  DatagramIterator scan;
142  BamReader *manager;
143 
144  parse_params(params, scan, manager);
145  attrib->fillin(scan, manager);
146 
147  return attrib;
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: DepthWriteAttrib::fillin
152 // Access: Protected
153 // Description: This internal function is called by make_from_bam to
154 // read in all of the relevant data from the BamFile for
155 // the new DepthWriteAttrib.
156 ////////////////////////////////////////////////////////////////////
157 void DepthWriteAttrib::
158 fillin(DatagramIterator &scan, BamReader *manager) {
159  RenderAttrib::fillin(scan, manager);
160 
161  _mode = (Mode)scan.get_int8();
162 }
PN_int8 get_int8()
Extracts a signed 8-bit integer.
static void register_with_read_factory()
Tells the BamReader how to create objects of type DepthWriteAttrib.
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
Enables or disables writing to the depth buffer.
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
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
Definition: stl_compares.I:122
Mode get_mode() const
Returns the depth write mode.
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
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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