Panda3D
paramTexture.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 paramTexture.cxx
10  * @author rdb
11  * @date 2014-12-11
12  */
13 
14 #include "paramTexture.h"
15 #include "dcast.h"
16 
17 TypeHandle ParamTextureSampler::_type_handle;
18 TypeHandle ParamTextureImage::_type_handle;
19 
20 /**
21  *
22  */
23 void ParamTextureSampler::
24 output(std::ostream &out) const {
25  out << "texture ";
26 
27  if (_texture != nullptr) {
28  out << _texture->get_name();
29  } else {
30  out << "(empty)";
31  }
32  out << ", ";
33 
34  _sampler.output(out);
35 }
36 
37 /**
38  * Tells the BamReader how to create objects of type ParamValue.
39  */
42  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
43 }
44 
45 /**
46  * Writes the contents of this object to the datagram for shipping out to a
47  * Bam file.
48  */
51  ParamValueBase::write_datagram(manager, dg);
52  manager->write_pointer(dg, _texture);
53  _sampler.write_datagram(dg);
54 }
55 
56 /**
57  * Receives an array of pointers, one for each time manager->read_pointer()
58  * was called in fillin(). Returns the number of pointers processed.
59  */
62  int pi = ParamValueBase::complete_pointers(p_list, manager);
63  _texture = DCAST(Texture, p_list[pi++]);
64  return pi;
65 }
66 
67 /**
68  * This function is called by the BamReader's factory when a new object of
69  * type ParamValue is encountered in the Bam file. It should create the
70  * ParamValue and extract its information from the file.
71  */
72 TypedWritable *ParamTextureSampler::
73 make_from_bam(const FactoryParams &params) {
75  DatagramIterator scan;
76  BamReader *manager;
77 
78  parse_params(params, scan, manager);
79  param->fillin(scan, manager);
80 
81  return param;
82 }
83 
84 /**
85  * This internal function is called by make_from_bam to read in all of the
86  * relevant data from the BamFile for the new ParamValue.
87  */
88 void ParamTextureSampler::
89 fillin(DatagramIterator &scan, BamReader *manager) {
90  ParamValueBase::fillin(scan, manager);
91  manager->read_pointer(scan);
92  _sampler.read_datagram(scan, manager);
93 }
94 
95 /**
96  *
97  */
98 void ParamTextureImage::
99 output(std::ostream &out) const {
100  out << "texture ";
101 
102  if (_texture != nullptr) {
103  out << _texture->get_name();
104  } else {
105  out << "(empty)";
106  }
107 
108  if (_access & A_read) {
109  if (_access & A_write) {
110  out << ", read-write";
111  } else {
112  out << ", read-only";
113  }
114  } else if (_access & A_write) {
115  out << ", write-only";
116  }
117 
118  if (_access & A_layered) {
119  out << ", all layers";
120  } else {
121  out << ", layer " << _bind_layer;
122  }
123 
124  out << ", level " << _bind_level;
125 }
126 
127 /**
128  * Tells the BamReader how to create objects of type ParamValue.
129  */
132  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
133 }
134 
135 /**
136  * Writes the contents of this object to the datagram for shipping out to a
137  * Bam file.
138  */
141  ParamValueBase::write_datagram(manager, dg);
142  manager->write_pointer(dg, _texture);
143  dg.add_uint8(_access);
144  dg.add_int8(_bind_level);
145  dg.add_int32(_bind_layer);
146 }
147 
148 /**
149  * Receives an array of pointers, one for each time manager->read_pointer()
150  * was called in fillin(). Returns the number of pointers processed.
151  */
154  int pi = ParamValueBase::complete_pointers(p_list, manager);
155  _texture = DCAST(Texture, p_list[pi++]);
156  return pi;
157 }
158 
159 /**
160  * This function is called by the BamReader's factory when a new object of
161  * type ParamValue is encountered in the Bam file. It should create the
162  * ParamValue and extract its information from the file.
163  */
164 TypedWritable *ParamTextureImage::
165 make_from_bam(const FactoryParams &params) {
167  DatagramIterator scan;
168  BamReader *manager;
169 
170  parse_params(params, scan, manager);
171  param->fillin(scan, manager);
172 
173  return param;
174 }
175 
176 /**
177  * This internal function is called by make_from_bam to read in all of the
178  * relevant data from the BamFile for the new ParamValue.
179  */
180 void ParamTextureImage::
181 fillin(DatagramIterator &scan, BamReader *manager) {
182  ParamValueBase::fillin(scan, manager);
183  manager->read_pointer(scan);
184  _access = scan.get_uint8();
185  _bind_level = scan.get_int8();
186  _bind_layer = scan.get_int32();
187 }
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
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:71
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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:63
int32_t get_int32()
Extracts a signed 32-bit integer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_name
Returns the name of the type.
Definition: typeHandle.h:136
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class'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.
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
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
Definition: datagram.I:42
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:81
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: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
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
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
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:610
A class object for storing a pointer to a Texture along with a sampler state that indicates how to to...
Definition: paramTexture.h:26
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
Definition: datagram.I:50
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().
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
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:317