Panda3D
depthWriteAttrib.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file depthWriteAttrib.cxx
10  * @author drose
11  * @date 2002-03-04
12  */
13 
14 #include "depthWriteAttrib.h"
16 #include "dcast.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19 #include "datagram.h"
20 #include "datagramIterator.h"
21 
22 TypeHandle DepthWriteAttrib::_type_handle;
23 int DepthWriteAttrib::_attrib_slot;
24 
25 /**
26  * Constructs a new DepthWriteAttrib object.
27  */
28 CPT(RenderAttrib) DepthWriteAttrib::
29 make(DepthWriteAttrib::Mode mode) {
30  DepthWriteAttrib *attrib = new DepthWriteAttrib(mode);
31  return return_new(attrib);
32 }
33 
34 /**
35  * Returns a RenderAttrib that corresponds to whatever the standard default
36  * properties for render attributes of this type ought to be.
37  */
38 CPT(RenderAttrib) DepthWriteAttrib::
39 make_default() {
40  return return_new(new DepthWriteAttrib);
41 }
42 
43 /**
44  *
45  */
46 void DepthWriteAttrib::
47 output(std::ostream &out) const {
48  out << get_type() << ":";
49  switch (get_mode()) {
50  case M_off:
51  out << "off";
52  break;
53  case M_on:
54  out << "on";
55  break;
56  }
57 }
58 
59 /**
60  * Intended to be overridden by derived DepthWriteAttrib types to return a
61  * unique number indicating whether this DepthWriteAttrib is equivalent to the
62  * other one.
63  *
64  * This should return 0 if the two DepthWriteAttrib objects are equivalent, a
65  * number less than zero if this one should be sorted before the other one,
66  * and a number greater than zero otherwise.
67  *
68  * This will only be called with two DepthWriteAttrib objects whose get_type()
69  * functions return the same.
70  */
71 int DepthWriteAttrib::
72 compare_to_impl(const RenderAttrib *other) const {
73  const DepthWriteAttrib *ta = (const DepthWriteAttrib *)other;
74 
75  return (int)_mode - (int)ta->_mode;
76 }
77 
78 /**
79  * Intended to be overridden by derived RenderAttrib types to return a unique
80  * hash for these particular properties. RenderAttribs that compare the same
81  * with compare_to_impl(), above, should return the same hash; RenderAttribs
82  * that compare differently should return a different hash.
83  */
84 size_t DepthWriteAttrib::
85 get_hash_impl() const {
86  size_t hash = 0;
87  hash = int_hash::add_hash(hash, (int)_mode);
88  return hash;
89 }
90 
91 /**
92  * Tells the BamReader how to create objects of type DepthWriteAttrib.
93  */
96  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
97 }
98 
99 /**
100  * Writes the contents of this object to the datagram for shipping out to a
101  * Bam file.
102  */
104 write_datagram(BamWriter *manager, Datagram &dg) {
105  RenderAttrib::write_datagram(manager, dg);
106 
107  dg.add_int8(_mode);
108 }
109 
110 /**
111  * This function is called by the BamReader's factory when a new object of
112  * type DepthWriteAttrib is encountered in the Bam file. It should create the
113  * DepthWriteAttrib and extract its information from the file.
114  */
115 TypedWritable *DepthWriteAttrib::
116 make_from_bam(const FactoryParams &params) {
117  DepthWriteAttrib *attrib = new DepthWriteAttrib;
118  DatagramIterator scan;
119  BamReader *manager;
120 
121  parse_params(params, scan, manager);
122  attrib->fillin(scan, manager);
123 
124  return attrib;
125 }
126 
127 /**
128  * This internal function is called by make_from_bam to read in all of the
129  * relevant data from the BamFile for the new DepthWriteAttrib.
130  */
131 void DepthWriteAttrib::
132 fillin(DatagramIterator &scan, BamReader *manager) {
133  RenderAttrib::fillin(scan, manager);
134 
135  _mode = (Mode)scan.get_int8();
136 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition: bamReader.I:275
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
A class to retrieve the individual data elements previously stored in a Datagram.
int8_t get_int8()
Extracts a signed 8-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
Definition: datagram.I:42
Enables or disables writing to the depth buffer.
static void register_with_read_factory()
Tells the BamReader how to create objects of type DepthWriteAttrib.
get_mode
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:36
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
Definition: stl_compares.I:101
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CPT(RenderAttrib) DepthWriteAttrib
Constructs a new DepthWriteAttrib object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.