Panda3D

Loading...
Searching...
No Matches
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::
24output(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 */
40 void ParamTextureSampler::
41 register_with_read_factory() {
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 */
49 void ParamTextureSampler::
50 write_datagram(BamWriter *manager, Datagram &dg) {
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 */
60 int ParamTextureSampler::
61 complete_pointers(TypedWritable **p_list, BamReader *manager) {
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::
73make_from_bam(const FactoryParams &params) {
74 ParamTextureSampler *param = new ParamTextureSampler;
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::
89fillin(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::
99output(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 */
130 void ParamTextureImage::
131 register_with_read_factory() {
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 */
139 void ParamTextureImage::
140 write_datagram(BamWriter *manager, Datagram &dg) {
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 */
152 int ParamTextureImage::
153 complete_pointers(TypedWritable **p_list, BamReader *manager) {
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::
165make_from_bam(const FactoryParams &params) {
166 ParamTextureImage *param = new ParamTextureImage;
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::
181fillin(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}
parse_params
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
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
BamReader::read_pointer
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition bamReader.cxx:610
BamReader::get_factory
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
BamWriter::write_pointer
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
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
DatagramIterator::get_uint8
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
Definition datagramIterator.I:72
DatagramIterator::get_int8
int8_t get_int8()
Extracts a signed 8-bit integer.
Definition datagramIterator.I:56
DatagramIterator::get_int32
int32_t get_int32()
Extracts a signed 32-bit integer.
Definition datagramIterator.I:107
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
Datagram::add_int32
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
Definition datagram.I:67
Datagram::add_uint8
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
Definition datagram.I:50
Datagram::add_int8
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
Definition datagram.I:42
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition factoryParams.h:36
Factory::register_factory
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
ParamTextureImage
A class object for storing a pointer to a Texture along with a set of properties that indicates which...
Definition paramTexture.h:81
ParamTextureImage::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition paramTexture.cxx:140
ParamTextureImage::complete_pointers
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Definition paramTexture.cxx:153
ParamTextureImage::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
Definition paramTexture.cxx:131
ParamTextureSampler
A class object for storing a pointer to a Texture along with a sampler state that indicates how to to...
Definition paramTexture.h:26
ParamTextureSampler::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition paramTexture.cxx:50
ParamTextureSampler::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
Definition paramTexture.cxx:41
ParamTextureSampler::complete_pointers
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Definition paramTexture.cxx:61
Texture
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition texture.h:72
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition typedWritable.h:35
TypedWritable::fillin
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...
Definition typedWritable.cxx:103
TypedWritable::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition typedWritable.cxx:54
TypedWritable::complete_pointers
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().
Definition typedWritable.cxx:81
dcast.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
paramTexture.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.