Panda3D
paramTexture.cxx
1 // Filename: paramTexture.cxx
2 // Created by: rdb (11Dec14)
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 "paramTexture.h"
16 #include "dcast.h"
17 
18 TypeHandle ParamTextureSampler::_type_handle;
19 TypeHandle ParamTextureImage::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: ParamTextureSampler::output
23 // Access: Published, Virtual
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 void ParamTextureSampler::
27 output(ostream &out) const {
28  out << "texture ";
29 
30  if (_texture != (Texture *)NULL) {
31  out << _texture->get_name();
32  } else {
33  out << "(empty)";
34  }
35  out << ", ";
36 
37  _sampler.output(out);
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: ParamTextureSampler::register_with_read_factory
42 // Access: Public, Static
43 // Description: Tells the BamReader how to create objects of type
44 // ParamValue.
45 ////////////////////////////////////////////////////////////////////
48  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: ParamTextureSampler::write_datagram
53 // Access: Public, Virtual
54 // Description: Writes the contents of this object to the datagram
55 // for shipping out to a Bam file.
56 ////////////////////////////////////////////////////////////////////
59  ParamValueBase::write_datagram(manager, dg);
60  manager->write_pointer(dg, _texture);
61  _sampler.write_datagram(dg);
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: ParamTextureSampler::complete_pointers
66 // Access: Public, Virtual
67 // Description: Receives an array of pointers, one for each time
68 // manager->read_pointer() was called in fillin().
69 // Returns the number of pointers processed.
70 ////////////////////////////////////////////////////////////////////
73  int pi = ParamValueBase::complete_pointers(p_list, manager);
74  _texture = DCAST(Texture, p_list[pi++]);
75  return pi;
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: ParamTextureSampler::make_from_bam
80 // Access: Protected, Static
81 // Description: This function is called by the BamReader's factory
82 // when a new object of type ParamValue is encountered
83 // in the Bam file. It should create the ParamValue
84 // and extract its information from the file.
85 ////////////////////////////////////////////////////////////////////
86 TypedWritable *ParamTextureSampler::
87 make_from_bam(const FactoryParams &params) {
89  DatagramIterator scan;
90  BamReader *manager;
91 
92  parse_params(params, scan, manager);
93  param->fillin(scan, manager);
94 
95  return param;
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: ParamTextureSampler::fillin
100 // Access: Protected
101 // Description: This internal function is called by make_from_bam to
102 // read in all of the relevant data from the BamFile for
103 // the new ParamValue.
104 ////////////////////////////////////////////////////////////////////
105 void ParamTextureSampler::
106 fillin(DatagramIterator &scan, BamReader *manager) {
107  ParamValueBase::fillin(scan, manager);
108  manager->read_pointer(scan);
109  _sampler.read_datagram(scan, manager);
110 }
111 
112 ////////////////////////////////////////////////////////////////////
113 // Function: ParamTextureImage::output
114 // Access: Published, Virtual
115 // Description:
116 ////////////////////////////////////////////////////////////////////
117 void ParamTextureImage::
118 output(ostream &out) const {
119  out << "texture ";
120 
121  if (_texture != (Texture *)NULL) {
122  out << _texture->get_name();
123  } else {
124  out << "(empty)";
125  }
126 
127  if (_access & A_read) {
128  if (_access & A_write) {
129  out << ", read-write";
130  } else {
131  out << ", read-only";
132  }
133  } else if (_access & A_write) {
134  out << ", write-only";
135  }
136 
137  if (_access & A_layered) {
138  out << ", all layers";
139  } else {
140  out << ", layer " << _bind_layer;
141  }
142 
143  out << ", level " << _bind_level;
144 }
145 
146 ////////////////////////////////////////////////////////////////////
147 // Function: ParamTextureImage::register_with_read_factory
148 // Access: Public, Static
149 // Description: Tells the BamReader how to create objects of type
150 // ParamValue.
151 ////////////////////////////////////////////////////////////////////
154  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: ParamTextureImage::write_datagram
159 // Access: Public, Virtual
160 // Description: Writes the contents of this object to the datagram
161 // for shipping out to a Bam file.
162 ////////////////////////////////////////////////////////////////////
165  ParamValueBase::write_datagram(manager, dg);
166  manager->write_pointer(dg, _texture);
167  dg.add_uint8(_access);
168  dg.add_int8(_bind_level);
169  dg.add_int32(_bind_layer);
170 }
171 
172 ////////////////////////////////////////////////////////////////////
173 // Function: ParamTextureImage::complete_pointers
174 // Access: Public, Virtual
175 // Description: Receives an array of pointers, one for each time
176 // manager->read_pointer() was called in fillin().
177 // Returns the number of pointers processed.
178 ////////////////////////////////////////////////////////////////////
181  int pi = ParamValueBase::complete_pointers(p_list, manager);
182  _texture = DCAST(Texture, p_list[pi++]);
183  return pi;
184 }
185 
186 ////////////////////////////////////////////////////////////////////
187 // Function: ParamTextureImage::make_from_bam
188 // Access: Protected, Static
189 // Description: This function is called by the BamReader's factory
190 // when a new object of type ParamValue is encountered
191 // in the Bam file. It should create the ParamValue
192 // and extract its information from the file.
193 ////////////////////////////////////////////////////////////////////
194 TypedWritable *ParamTextureImage::
195 make_from_bam(const FactoryParams &params) {
197  DatagramIterator scan;
198  BamReader *manager;
199 
200  parse_params(params, scan, manager);
201  param->fillin(scan, manager);
202 
203  return param;
204 }
205 
206 ////////////////////////////////////////////////////////////////////
207 // Function: ParamTextureImage::fillin
208 // Access: Protected
209 // Description: This internal function is called by make_from_bam to
210 // read in all of the relevant data from the BamFile for
211 // the new ParamValue.
212 ////////////////////////////////////////////////////////////////////
213 void ParamTextureImage::
214 fillin(DatagramIterator &scan, BamReader *manager) {
215  ParamValueBase::fillin(scan, manager);
216  manager->read_pointer(scan);
217  _access = scan.get_uint8();
218  _bind_level = scan.get_int8();
219  _bind_layer = scan.get_int32();
220 }
PN_int8 get_int8()
Extracts a signed 8-bit integer.
void add_uint8(PN_uint8 value)
Adds an unsigned 8-bit integer to the datagram.
Definition: datagram.I:138
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
void add_int8(PN_int8 value)
Adds a signed 8-bit integer to the datagram.
Definition: datagram.I:128
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
string get_name(TypedObject *object=(TypedObject *) NULL) const
Returns the name of the type.
Definition: typeHandle.I:132
void read_datagram(DatagramIterator &source, BamReader *manager)
Reads the sampler state from the datagram that has been previously written using write_datagram.
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.
PN_uint8 get_uint8()
Extracts an unsigned 8-bit integer.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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 write_datagram(Datagram &destination) const
Encodes the sampler state into a datagram.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
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 object for storing a pointer to a Texture along with a set of properties that indicates which...
Definition: paramTexture.h:83
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
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 object for storing a pointer to a Texture along with a sampler state that indicates how to to...
Definition: paramTexture.h:29
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. ...
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
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
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:279
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:658