15 #include "fltTexture.h" 16 #include "fltRecordReader.h" 17 #include "fltRecordWriter.h" 18 #include "fltHeader.h" 19 #include "pathReplace.h" 20 #include "config_util.h" 37 _real_world_size_u = 0;
38 _real_world_size_v = 0;
41 _file_format = FF_none;
42 _min_filter = MN_point;
43 _mag_filter = MG_point;
45 _repeat_u = RT_repeat;
46 _repeat_v = RT_repeat;
50 _env_type = ET_modulate;
51 _intensity_is_alpha =
false;
52 _float_real_world_size_u = 0.0;
53 _float_real_world_size_v = 0.0;
54 _imported_origin_code = 0;
55 _kernel_version = 1520;
56 _internal_format = IF_default;
57 _external_format = EF_default;
58 _use_mipmap_kernel =
false;
59 memset(_mipmap_kernel, 0,
sizeof(_mipmap_kernel));
60 _use_lod_scale =
false;
61 memset(_lod_scale, 0,
sizeof(_lod_scale));
63 _mag_filter_alpha = MG_point;
64 _mag_filter_color = MG_point;
65 _lambert_conic_central_meridian = 0.0;
66 _lambert_conic_upper_latitude = 0.0;
67 _lambert_conic_lower_latitude = 0.0;
75 _tile_lower_left_u = 0.0;
76 _tile_lower_left_v = 0.0;
77 _tile_upper_right_u = 0.0;
78 _tile_upper_right_v = 0.0;
79 _projection = PT_flat_earth;
80 _earth_model = EM_wgs84;
82 _image_origin = IO_lower_left;
83 _geospecific_points_units = PU_degrees;
84 _geospecific_hemisphere = H_southern;
110 return _converted_filename;
120 _converted_filename = filename;
142 return Filename::binary_filename(texture_filename +
".attr");
159 return FE_could_not_open;
164 attr.seekg(0, ios::end);
166 return FE_read_error;
168 streampos length = attr.tellg();
170 char *buffer =
new char[length];
172 attr.seekg(0, ios::beg);
173 attr.read(buffer, length);
175 return FE_read_error;
181 return unpack_attr(datagram);
205 FltError result = pack_attr(datagram);
206 if (result != FE_ok) {
213 return FE_could_not_open;
218 return FE_write_error;
233 if (!FltRecord::extract_record(reader)) {
237 nassertr(reader.
get_opcode() == FO_texture,
false);
240 if (_header->get_flt_version() < 1420) {
241 _orig_filename = iterator.get_fixed_string(80);
243 _orig_filename = iterator.get_fixed_string(200);
246 _pattern_index = iterator.get_be_int32();
247 _x_location = iterator.get_be_int32();
248 _y_location = iterator.get_be_int32();
268 if (!FltRecord::build_record(writer)) {
280 if (_header->get_auto_attr_update() == FltHeader::AU_always ||
281 (_header->get_auto_attr_update() == FltHeader::AU_if_missing &&
296 FltError FltTexture::
297 unpack_attr(
const Datagram &datagram) {
323 _internal_format = (InternalFormat)iterator.
get_be_int32();
324 _external_format = (ExternalFormat)iterator.
get_be_int32();
327 for (i = 0; i < 8; i++) {
331 for (i = 0; i < 8; i++) {
336 _mag_filter_alpha = (Magnification)iterator.
get_be_int32();
337 _mag_filter_color = (Magnification)iterator.
get_be_int32();
359 _geospecific_points_units = (PointsUnits)iterator.
get_be_int32();
360 _geospecific_hemisphere = (Hemisphere)iterator.
get_be_int32();
371 _geospecific_control_points.clear();
373 if (num_points > 0) {
376 while (num_points > 0) {
387 while (num_defs > 0) {
407 FltError FltTexture::
408 pack_attr(
Datagram &datagram)
const {
436 for (i = 0; i < 8; i++) {
440 for (i = 0; i < 8; i++) {
478 datagram.
add_be_int32(_geospecific_control_points.size());
479 if (!_geospecific_control_points.empty()) {
481 GeospecificControlPoints::const_iterator pi;
482 for (pi = _geospecific_control_points.begin();
483 pi != _geospecific_control_points.end();
495 SubtextureDefs::const_iterator di;
496 for (di = _subtexture_defs.begin();
497 di != _subtexture_defs.end();
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly...
bool open_write(ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
PN_float64 get_be_float64()
Extracts a 64-bit big-endian floating-point number.
Filename get_texture_filename() const
Returns the name of the texture image file.
void add_int8(PN_int8 value)
Adds a signed 8-bit integer to the datagram.
void set_texture_filename(const Filename &filename)
Changes the name of the texture image file.
void set_binary()
Indicates that the filename represents a binary file.
virtual void apply_converted_filenames()
Walks the hierarchy at this record and below and copies the _converted_filename record into the _orig...
PN_float32 get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
void check_remaining_size(const DatagramIterator &di, const string &name=string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record...
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
bool open_read(ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
string to_os_generic() const
This is similar to to_os_specific(), but it is designed to generate a filename that can be understood...
FltError write_attr_data() const
Writes the texture's .attr file.
void add_be_float64(PN_float64 value)
Adds a 64-bit big-endian floating-point number to the datagram.
virtual void apply_converted_filenames()
Walks the hierarchy at this record and below and copies the _converted_filename record into the _orig...
void add_be_float32(PN_float32 value)
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
The name of a file, such as a texture file or an Egg file.
int get_remaining_size() const
Return the bytes left in the datagram.
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
The base class for all kinds of records in a MultiGen OpenFlight file.
FltError read_attr_data()
Opens up the texture's .attr file and reads its data into the extra FltTexture fields.
void add_be_int32(PN_int32 value)
Adds a signed 32-bit big-endian integer to the datagram.
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
void add_fixed_string(const string &str, size_t size)
Adds a fixed-length string to the datagram.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Filename get_attr_filename() const
Returns the name of the texture's associated .attr file.
void set_opcode(FltOpcode opcode)
Sets the opcode associated with the current record.
Datagram & update_datagram()
Returns a modifiable reference to the datagram associated with the current record.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
PN_int32 get_be_int32()
Extracts a signed 32-bit big-endian integer.
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
size_t get_length() const
Returns the number of bytes in the datagram.
const void * get_data() const
Returns a pointer to the beginning of the datagram's data.
string get_fixed_string(size_t size)
Extracts a fixed-length string.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).