Panda3D
auxBitplaneAttrib.cxx
1 // Filename: auxBitplaneAttrib.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 "auxBitplaneAttrib.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 AuxBitplaneAttrib::_type_handle;
24 int AuxBitplaneAttrib::_attrib_slot;
25 CPT(RenderAttrib) AuxBitplaneAttrib::_default;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: AuxBitplaneAttrib::make
29 // Access: Published, Static
30 // Description: Constructs a default AuxBitplaneAttrib object.
31 ////////////////////////////////////////////////////////////////////
32 CPT(RenderAttrib) AuxBitplaneAttrib::
33 make() {
34  if (_default == 0) {
35  AuxBitplaneAttrib *attrib = new AuxBitplaneAttrib(0);
36  _default = return_new(attrib);
37  }
38  return _default;
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: AuxBitplaneAttrib::make
43 // Access: Published, Static
44 // Description: Constructs a specified AuxBitplaneAttrib object.
45 ////////////////////////////////////////////////////////////////////
46 CPT(RenderAttrib) AuxBitplaneAttrib::
47 make(int outputs) {
48  AuxBitplaneAttrib *attrib = new AuxBitplaneAttrib(outputs);
49  return return_new(attrib);
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: AuxBitplaneAttrib::make_default
54 // Access: Published, Static
55 // Description: Returns a RenderAttrib that corresponds to whatever
56 // the standard default properties for render attributes
57 // of this type ought to be.
58 ////////////////////////////////////////////////////////////////////
59 CPT(RenderAttrib) AuxBitplaneAttrib::
60 make_default() {
61  return return_new(new AuxBitplaneAttrib(0));
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: AuxBitplaneAttrib::output
66 // Access: Public, Virtual
67 // Description:
68 ////////////////////////////////////////////////////////////////////
69 void AuxBitplaneAttrib::
70 output(ostream &out) const {
71  out << get_type() << "(" << _outputs << ")";
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: AuxBitplaneAttrib::compare_to_impl
76 // Access: Protected, Virtual
77 // Description: Intended to be overridden by derived AuxBitplaneAttrib
78 // types to return a unique number indicating whether
79 // this AuxBitplaneAttrib is equivalent to the other one.
80 //
81 // This should return 0 if the two AuxBitplaneAttrib objects
82 // are equivalent, a number less than zero if this one
83 // should be sorted before the other one, and a number
84 // greater than zero otherwise.
85 //
86 // This will only be called with two AuxBitplaneAttrib
87 // objects whose get_type() functions return the same.
88 ////////////////////////////////////////////////////////////////////
89 int AuxBitplaneAttrib::
90 compare_to_impl(const RenderAttrib *other) const {
91  const AuxBitplaneAttrib *ta;
92  DCAST_INTO_R(ta, other, 0);
93  int compare_result = _outputs - ta->_outputs;
94  if (compare_result != 0) {
95  return compare_result;
96  }
97  return 0;
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: AuxBitplaneAttrib::get_hash_impl
102 // Access: Protected, Virtual
103 // Description: Intended to be overridden by derived RenderAttrib
104 // types to return a unique hash for these particular
105 // properties. RenderAttribs that compare the same with
106 // compare_to_impl(), above, should return the same
107 // hash; RenderAttribs that compare differently should
108 // return a different hash.
109 ////////////////////////////////////////////////////////////////////
110 size_t AuxBitplaneAttrib::
111 get_hash_impl() const {
112  size_t hash = 0;
113  hash = int_hash::add_hash(hash, _outputs);
114  return hash;
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: AuxBitplaneAttrib::get_auto_shader_attrib_impl
119 // Access: Protected, Virtual
120 // Description:
121 ////////////////////////////////////////////////////////////////////
122 CPT(RenderAttrib) AuxBitplaneAttrib::
123 get_auto_shader_attrib_impl(const RenderState *state) const {
124  return this;
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: AuxBitplaneAttrib::register_with_read_factory
129 // Access: Public, Static
130 // Description: Tells the BamReader how to create objects of type
131 // AuxBitplaneAttrib.
132 ////////////////////////////////////////////////////////////////////
133 void AuxBitplaneAttrib::
134 register_with_read_factory() {
135  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
136 }
137 
138 ////////////////////////////////////////////////////////////////////
139 // Function: AuxBitplaneAttrib::write_datagram
140 // Access: Public, Virtual
141 // Description: Writes the contents of this object to the datagram
142 // for shipping out to a Bam file.
143 ////////////////////////////////////////////////////////////////////
146  RenderAttrib::write_datagram(manager, dg);
147 
148  dg.add_int32(_outputs);
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: AuxBitplaneAttrib::make_from_bam
153 // Access: Protected, Static
154 // Description: This function is called by the BamReader's factory
155 // when a new object of type AuxBitplaneAttrib is encountered
156 // in the Bam file. It should create the AuxBitplaneAttrib
157 // and extract its information from the file.
158 ////////////////////////////////////////////////////////////////////
159 TypedWritable *AuxBitplaneAttrib::
160 make_from_bam(const FactoryParams &params) {
161  AuxBitplaneAttrib *attrib = new AuxBitplaneAttrib(0);
162  DatagramIterator scan;
163  BamReader *manager;
164 
165  parse_params(params, scan, manager);
166  attrib->fillin(scan, manager);
167 
168  return attrib;
169 }
170 
171 ////////////////////////////////////////////////////////////////////
172 // Function: AuxBitplaneAttrib::fillin
173 // Access: Protected
174 // Description: This internal function is called by make_from_bam to
175 // read in all of the relevant data from the BamFile for
176 // the new AuxBitplaneAttrib.
177 ////////////////////////////////////////////////////////////////////
178 void AuxBitplaneAttrib::
179 fillin(DatagramIterator &scan, BamReader *manager) {
180  RenderAttrib::fillin(scan, manager);
181 
182  _outputs = scan.get_int32();
183 }
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
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
PN_int32 get_int32()
Extracts a signed 32-bit integer.
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
Definition: stl_compares.I:122
Modern frame buffers can have &#39;aux&#39; bitplanes, which are additional bitplanes above and beyond the st...
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
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
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
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 add_int32(PN_int32 value)
Adds a signed 32-bit integer to the datagram.
Definition: datagram.I:159
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