Panda3D
auxBitplaneAttrib.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 auxBitplaneAttrib.cxx
10  * @author drose
11  * @date 2002-03-04
12  */
13 
14 #include "auxBitplaneAttrib.h"
16 #include "dcast.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19 #include "datagram.h"
20 #include "datagramIterator.h"
21 
22 TypeHandle AuxBitplaneAttrib::_type_handle;
23 int AuxBitplaneAttrib::_attrib_slot;
24 CPT(RenderAttrib) AuxBitplaneAttrib::_default;
25 
26 /**
27  * Constructs a default AuxBitplaneAttrib object.
28  */
29 CPT(RenderAttrib) AuxBitplaneAttrib::
30 make() {
31  if (_default == nullptr) {
32  AuxBitplaneAttrib *attrib = new AuxBitplaneAttrib(0);
33  _default = return_new(attrib);
34  }
35  return _default;
36 }
37 
38 /**
39  * Constructs a specified AuxBitplaneAttrib object.
40  */
41 CPT(RenderAttrib) AuxBitplaneAttrib::
42 make(int outputs) {
43  AuxBitplaneAttrib *attrib = new AuxBitplaneAttrib(outputs);
44  return return_new(attrib);
45 }
46 
47 /**
48  * Returns a RenderAttrib that corresponds to whatever the standard default
49  * properties for render attributes of this type ought to be.
50  */
51 CPT(RenderAttrib) AuxBitplaneAttrib::
52 make_default() {
53  return return_new(new AuxBitplaneAttrib(0));
54 }
55 
56 /**
57  *
58  */
59 void AuxBitplaneAttrib::
60 output(std::ostream &out) const {
61  out << get_type() << "(" << _outputs << ")";
62 }
63 
64 /**
65  * Intended to be overridden by derived AuxBitplaneAttrib types to return a
66  * unique number indicating whether this AuxBitplaneAttrib is equivalent to
67  * the other one.
68  *
69  * This should return 0 if the two AuxBitplaneAttrib objects are equivalent, a
70  * number less than zero if this one should be sorted before the other one,
71  * and a number greater than zero otherwise.
72  *
73  * This will only be called with two AuxBitplaneAttrib objects whose
74  * get_type() functions return the same.
75  */
76 int AuxBitplaneAttrib::
77 compare_to_impl(const RenderAttrib *other) const {
78  const AuxBitplaneAttrib *ta = (const AuxBitplaneAttrib *)other;
79 
80  int compare_result = _outputs - ta->_outputs;
81  if (compare_result != 0) {
82  return compare_result;
83  }
84  return 0;
85 }
86 
87 /**
88  * Intended to be overridden by derived RenderAttrib types to return a unique
89  * hash for these particular properties. RenderAttribs that compare the same
90  * with compare_to_impl(), above, should return the same hash; RenderAttribs
91  * that compare differently should return a different hash.
92  */
93 size_t AuxBitplaneAttrib::
94 get_hash_impl() const {
95  size_t hash = 0;
96  hash = int_hash::add_hash(hash, _outputs);
97  return hash;
98 }
99 
100 /**
101  * Tells the BamReader how to create objects of type AuxBitplaneAttrib.
102  */
105  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
106 }
107 
108 /**
109  * Writes the contents of this object to the datagram for shipping out to a
110  * Bam file.
111  */
114  RenderAttrib::write_datagram(manager, dg);
115 
116  dg.add_int32(_outputs);
117 }
118 
119 /**
120  * This function is called by the BamReader's factory when a new object of
121  * type AuxBitplaneAttrib is encountered in the Bam file. It should create
122  * the AuxBitplaneAttrib and extract its information from the file.
123  */
124 TypedWritable *AuxBitplaneAttrib::
125 make_from_bam(const FactoryParams &params) {
126  AuxBitplaneAttrib *attrib = new AuxBitplaneAttrib(0);
127  DatagramIterator scan;
128  BamReader *manager;
129 
130  parse_params(params, scan, manager);
131  attrib->fillin(scan, manager);
132 
133  return attrib;
134 }
135 
136 /**
137  * This internal function is called by make_from_bam to read in all of the
138  * relevant data from the BamFile for the new AuxBitplaneAttrib.
139  */
140 void AuxBitplaneAttrib::
141 fillin(DatagramIterator &scan, BamReader *manager) {
142  RenderAttrib::fillin(scan, manager);
143 
144  _outputs = scan.get_int32();
145 }
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
CPT(RenderAttrib) AuxBitplaneAttrib CPT(RenderAttrib) AuxBitplaneAttrib
Constructs a default AuxBitplaneAttrib object.
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
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
int32_t get_int32()
Extracts a signed 32-bit integer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
Definition: stl_compares.I:101
Modern frame buffers can have 'aux' bitplanes, which are additional bitplanes above and beyond the st...
static void register_with_read_factory()
Tells the BamReader how to create objects of type AuxBitplaneAttrib.
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
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.
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.
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
Definition: datagram.I:67
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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: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.