Panda3D
textureReference.h
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 textureReference.h
10  * @author drose
11  * @date 2000-11-28
12  */
13 
14 #ifndef TEXTUREREFERENCE_H
15 #define TEXTUREREFERENCE_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "textureProperties.h"
20 #include "palettizer.h"
21 
22 #include "luse.h"
23 #include "typedWritable.h"
24 
25 class TextureImage;
26 class SourceTextureImage;
27 class Filename;
28 class EggFile;
29 class EggData;
30 class EggTexture;
31 class EggGroupNode;
32 class EggPrimitive;
33 class TexturePlacement;
34 
35 /**
36  * This is the particular reference of a texture filename by an egg file. It
37  * also includes information about the way in which the egg file uses the
38  * texture; e.g. does it repeat.
39  */
41 public:
44 
45  void from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex);
46  void from_egg_quick(const TextureReference &other);
47  void release_egg_data();
48  void rebind_egg_data(EggData *data, EggTexture *egg_tex);
49 
50  EggFile *get_egg_file() const;
52  TextureImage *get_texture() const;
53  const std::string &get_tref_name() const;
54 
55  bool operator < (const TextureReference &other) const;
56 
57  bool has_uvs() const;
58  const LTexCoordd &get_min_uv() const;
59  const LTexCoordd &get_max_uv() const;
60 
61  EggTexture::WrapMode get_wrap_u() const;
62  EggTexture::WrapMode get_wrap_v() const;
63 
64  bool is_equivalent(const TextureReference &other) const;
65 
66  void set_placement(TexturePlacement *placement);
67  void clear_placement();
69 
70  void mark_egg_stale();
71  void update_egg();
73 
74  void output(std::ostream &out) const;
75  void write(std::ostream &out, int indent_level = 0) const;
76 
77 
78 private:
79  bool get_uv_range(EggGroupNode *group, Palettizer::RemapUV remap);
80  void update_uv_range(EggGroupNode *group, Palettizer::RemapUV remap);
81 
82  bool get_geom_uvs(EggPrimitive *geom,
83  LTexCoordd &geom_min_uv, LTexCoordd &geom_max_uv);
84  void translate_geom_uvs(EggPrimitive *geom, const LTexCoordd &trans) const;
85  void collect_nominal_uv_range();
86  static void collect_uv(bool &any_uvs, LTexCoordd &min_uv, LTexCoordd &max_uv,
87  const LTexCoordd &got_min_uv,
88  const LTexCoordd &got_max_uv);
89  static LVector2d translate_uv(const LTexCoordd &min_uv,
90  const LTexCoordd &max_uv);
91 
92  EggFile *_egg_file;
93  EggTexture *_egg_tex;
94  EggData *_egg_data;
95 
96  std::string _tref_name;
97  LMatrix3d _tex_mat, _inv_tex_mat;
98  SourceTextureImage *_source_texture;
99  TexturePlacement *_placement;
100 
101  bool _uses_alpha;
102 
103  bool _any_uvs;
104  LTexCoordd _min_uv, _max_uv;
105  EggTexture::WrapMode _wrap_u, _wrap_v;
106 
107  TextureProperties _properties;
108 
109  // The TypedWritable interface follows.
110 public:
111  static void register_with_read_factory();
112  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
113  virtual int complete_pointers(TypedWritable **p_list,
114  BamReader *manager);
115 
116 protected:
117  static TypedWritable *make_TextureReference(const FactoryParams &params);
118  void fillin(DatagramIterator &scan, BamReader *manager);
119 
120 public:
121  static TypeHandle get_class_type() {
122  return _type_handle;
123  }
124  static void init_type() {
125  TypedWritable::init_type();
126  register_type(_type_handle, "TextureReference",
127  TypedWritable::get_class_type());
128  }
129  virtual TypeHandle get_type() const {
130  return get_class_type();
131  }
132 
133 private:
134  static TypeHandle _type_handle;
135 };
136 
137 INLINE std::ostream &
138 operator << (std::ostream &out, const TextureReference &ref) {
139  ref.output(out);
140  return out;
141 }
142 
143 #endif
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
Definition: eggPrimitive.h:47
bool is_equivalent(const TextureReference &other) const
Returns true if all essential properties of this TextureReference are the same as that of the other,...
void from_egg_quick(const TextureReference &other)
Sets up the pointers within the TextureReference to the same egg file pointers indicated by the other...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_placement(TexturePlacement *placement)
Sets the particular TexturePlacement that is appropriate for this egg file.
void update_egg()
Updates the egg file with all the relevant information to reference the texture in its new home,...
void apply_properties_to_source()
Applies the texture properties as read from the egg file to the source image's properties.
EggTexture::WrapMode get_wrap_u() const
Returns the specification for the wrapping in the U direction.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void clear_placement()
Removes any reference to a TexturePlacement.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the particular reference of a texture filename by an egg file.
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:46
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
EggFile * get_egg_file() const
Returns the EggFile that references this texture.
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:30
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
const LTexCoordd & get_min_uv() const
Returns the minimum UV coordinate in use for the texture by this reference.
const LTexCoordd & get_max_uv() const
Returns the maximum UV coordinate in use for the texture by this reference.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This is the primary interface into all the egg data, and the root of the egg file structure.
Definition: eggData.h:37
EggTexture::WrapMode get_wrap_v() const
Returns the specification for the wrapping in the V direction.
SourceTextureImage * get_source() const
Returns the SourceTextureImage that this object refers to.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TextureImage * get_texture() const
Returns the TextureImage that this object refers to.
const std::string & get_tref_name() const
Returns the name of the EggTexture entry that references this texture.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
void rebind_egg_data(EggData *data, EggTexture *egg_tex)
After an EggData has previously been released via release_egg_data(), this can be called to indicate ...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
bool operator<(const TextureReference &other) const
Defines an ordering of TextureReference pointers in alphabetical order by their tref name.
This corresponds to a particular assignment of a TextureImage with a PaletteGroup,...
void from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex)
Sets up the TextureReference using information extracted from an egg file.
This is a texture image reference as it appears in an egg file: the source image of the texture.
void mark_egg_stale()
Marks the egg file that shares this reference as stale.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
bool has_uvs() const
Returns true if this TextureReference actually uses the texture on geometry, with UV's and everything...
A class to retrieve the individual data elements previously stored in a Datagram.
This represents a single source texture that is referenced by one or more egg files.
Definition: textureImage.h:46
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
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function's job is to store...
TexturePlacement * get_placement() const
Returns the particular TexturePlacement that is appropriate for this egg file.
void release_egg_data()
Called to indicate that the EggData previously passed to from_egg() is about to be deallocated,...
This represents a single egg file known to the palettizer.
Definition: eggFile.h:36
This is the set of characteristics of a texture that, if different from another texture,...