Panda3D
depthTestAttrib.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 depthTestAttrib.cxx
10  * @author drose
11  * @date 2002-03-04
12  */
13 
14 #include "depthTestAttrib.h"
16 #include "dcast.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19 #include "datagram.h"
20 #include "datagramIterator.h"
21 
22 TypeHandle DepthTestAttrib::_type_handle;
23 int DepthTestAttrib::_attrib_slot;
24 
25 /**
26  * Constructs a new DepthTestAttrib object.
27  */
28 CPT(RenderAttrib) DepthTestAttrib::
29 make(DepthTestAttrib::PandaCompareFunc mode) {
30  DepthTestAttrib *attrib = new DepthTestAttrib(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) DepthTestAttrib::
39 make_default() {
40  return return_new(new DepthTestAttrib);
41 }
42 
43 /**
44  *
45  */
46 void DepthTestAttrib::
47 output(std::ostream &out) const {
48  out << get_type() << ":";
49  output_comparefunc(out,_mode);
50 }
51 
52 /**
53  * Intended to be overridden by derived DepthTestAttrib types to return a
54  * unique number indicating whether this DepthTestAttrib is equivalent to the
55  * other one.
56  *
57  * This should return 0 if the two DepthTestAttrib objects are equivalent, a
58  * number less than zero if this one should be sorted before the other one,
59  * and a number greater than zero otherwise.
60  *
61  * This will only be called with two DepthTestAttrib objects whose get_type()
62  * functions return the same.
63  */
64 int DepthTestAttrib::
65 compare_to_impl(const RenderAttrib *other) const {
66  const DepthTestAttrib *ta = (const DepthTestAttrib *)other;
67 
68  return (int)_mode - (int)ta->_mode;
69 }
70 
71 /**
72  * Intended to be overridden by derived RenderAttrib types to return a unique
73  * hash for these particular properties. RenderAttribs that compare the same
74  * with compare_to_impl(), above, should return the same hash; RenderAttribs
75  * that compare differently should return a different hash.
76  */
77 size_t DepthTestAttrib::
78 get_hash_impl() const {
79  size_t hash = 0;
80  hash = int_hash::add_hash(hash, (int)_mode);
81  return hash;
82 }
83 
84 /**
85  * Tells the BamReader how to create objects of type DepthTestAttrib.
86  */
89  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
90 }
91 
92 /**
93  * Writes the contents of this object to the datagram for shipping out to a
94  * Bam file.
95  */
98  RenderAttrib::write_datagram(manager, dg);
99 
100  dg.add_int8(_mode);
101 }
102 
103 /**
104  * This function is called by the BamReader's factory when a new object of
105  * type DepthTestAttrib is encountered in the Bam file. It should create the
106  * DepthTestAttrib and extract its information from the file.
107  */
108 TypedWritable *DepthTestAttrib::
109 make_from_bam(const FactoryParams &params) {
110  DepthTestAttrib *attrib = new DepthTestAttrib;
111  DatagramIterator scan;
112  BamReader *manager;
113 
114  parse_params(params, scan, manager);
115  attrib->fillin(scan, manager);
116 
117  return attrib;
118 }
119 
120 /**
121  * This internal function is called by make_from_bam to read in all of the
122  * relevant data from the BamFile for the new DepthTestAttrib.
123  */
124 void DepthTestAttrib::
125 fillin(DatagramIterator &scan, BamReader *manager) {
126  RenderAttrib::fillin(scan, manager);
127 
128  _mode = (PandaCompareFunc)scan.get_int8();
129 }
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:51
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void register_with_read_factory()
Tells the BamReader how to create objects of type DepthTestAttrib.
CPT(RenderAttrib) DepthTestAttrib
Constructs a new DepthTestAttrib object.
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
Definition: stl_compares.I:101
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
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
Definition: datagram.I:42
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
A class to retrieve the individual data elements previously stored in a Datagram.
int8_t get_int8()
Extracts a signed 8-bit integer.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.