Panda3D
 All Classes Functions Variables Enumerations
textureReference.h
1 // Filename: textureReference.h
2 // Created by: drose (28Nov00)
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 #ifndef TEXTUREREFERENCE_H
16 #define TEXTUREREFERENCE_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "textureProperties.h"
21 #include "palettizer.h"
22 
23 #include "luse.h"
24 #include "typedWritable.h"
25 
26 class TextureImage;
27 class SourceTextureImage;
28 class Filename;
29 class EggFile;
30 class EggData;
31 class EggTexture;
32 class EggGroupNode;
33 class EggPrimitive;
34 class TexturePlacement;
35 
36 ////////////////////////////////////////////////////////////////////
37 // Class : TextureReference
38 // Description : This is the particular reference of a texture
39 // filename by an egg file. It also includes
40 // information about the way in which the egg file uses
41 // the texture; e.g. does it repeat.
42 ////////////////////////////////////////////////////////////////////
44 public:
47 
48  void from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex);
49  void from_egg_quick(const TextureReference &other);
50  void release_egg_data();
51  void rebind_egg_data(EggData *data, EggTexture *egg_tex);
52 
53  EggFile *get_egg_file() const;
55  TextureImage *get_texture() const;
56  const string &get_tref_name() const;
57 
58  bool operator < (const TextureReference &other) const;
59 
60  bool has_uvs() const;
61  const LTexCoordd &get_min_uv() const;
62  const LTexCoordd &get_max_uv() const;
63 
64  EggTexture::WrapMode get_wrap_u() const;
65  EggTexture::WrapMode get_wrap_v() const;
66 
67  bool is_equivalent(const TextureReference &other) const;
68 
69  void set_placement(TexturePlacement *placement);
70  void clear_placement();
72 
73  void mark_egg_stale();
74  void update_egg();
76 
77  void output(ostream &out) const;
78  void write(ostream &out, int indent_level = 0) const;
79 
80 
81 private:
82  bool get_uv_range(EggGroupNode *group, Palettizer::RemapUV remap);
83  void update_uv_range(EggGroupNode *group, Palettizer::RemapUV remap);
84 
85  bool get_geom_uvs(EggPrimitive *geom,
86  LTexCoordd &geom_min_uv, LTexCoordd &geom_max_uv);
87  void translate_geom_uvs(EggPrimitive *geom, const LTexCoordd &trans) const;
88  void collect_nominal_uv_range();
89  static void collect_uv(bool &any_uvs, LTexCoordd &min_uv, LTexCoordd &max_uv,
90  const LTexCoordd &got_min_uv,
91  const LTexCoordd &got_max_uv);
92  static LVector2d translate_uv(const LTexCoordd &min_uv,
93  const LTexCoordd &max_uv);
94 
95  EggFile *_egg_file;
96  EggTexture *_egg_tex;
97  EggData *_egg_data;
98 
99  string _tref_name;
100  LMatrix3d _tex_mat, _inv_tex_mat;
101  SourceTextureImage *_source_texture;
102  TexturePlacement *_placement;
103 
104  bool _uses_alpha;
105 
106  bool _any_uvs;
107  LTexCoordd _min_uv, _max_uv;
108  EggTexture::WrapMode _wrap_u, _wrap_v;
109 
110  TextureProperties _properties;
111 
112  // The TypedWritable interface follows.
113 public:
114  static void register_with_read_factory();
115  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
116  virtual int complete_pointers(TypedWritable **p_list,
117  BamReader *manager);
118 
119 protected:
120  static TypedWritable *make_TextureReference(const FactoryParams &params);
121  void fillin(DatagramIterator &scan, BamReader *manager);
122 
123 public:
124  static TypeHandle get_class_type() {
125  return _type_handle;
126  }
127  static void init_type() {
128  TypedWritable::init_type();
129  register_type(_type_handle, "TextureReference",
130  TypedWritable::get_class_type());
131  }
132  virtual TypeHandle get_type() const {
133  return get_class_type();
134  }
135 
136 private:
137  static TypeHandle _type_handle;
138 };
139 
140 INLINE ostream &
141 operator << (ostream &out, const TextureReference &ref) {
142  ref.output(out);
143  return out;
144 }
145 
146 #endif
147 
148 
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
Definition: eggPrimitive.h:51
void from_egg_quick(const TextureReference &other)
Sets up the pointers within the TextureReference to the same egg file pointers indicated by the other...
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&#39;s properties.
void clear_placement()
Removes any reference to a TexturePlacement.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This is a two-component vector offset.
Definition: lvector2.h:416
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:51
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:33
EggFile * get_egg_file() const
Returns the EggFile that references this texture.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is a two-component point in space.
Definition: lpoint2.h:411
SourceTextureImage * get_source() const
Returns the SourceTextureImage that this object refers to.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is the primary interface into all the egg data, and the root of the egg file structure...
Definition: eggData.h:41
bool operator<(const TextureReference &other) const
Defines an ordering of TextureReference pointers in alphabetical order by their tref name...
const LTexCoordd & get_min_uv() const
Returns the minimum UV coordinate in use for the texture by this reference.
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:4375
bool is_equivalent(const TextureReference &other) const
Returns true if all essential properties of this TextureReference are the same as that of the other...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
const LTexCoordd & get_max_uv() const
Returns the maximum UV coordinate in use for the texture by this reference.
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 ...
TextureImage * get_texture() const
Returns the TextureImage that this object refers to.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This corresponds to a particular assignment of a TextureImage with a PaletteGroup, and specifically describes which PaletteImage (if any), and where on the PaletteImage, the TextureImage has been assigned to.
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...
const string & get_tref_name() const
Returns the name of the EggTexture entry that references this texture.
void mark_egg_stale()
Marks the egg file that shares this reference as stale.
EggTexture::WrapMode get_wrap_u() const
Returns the specification for the wrapping in the U direction.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
EggTexture::WrapMode get_wrap_v() const
Returns the specification for the wrapping in the V direction.
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:51
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
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function&#39;s job is to store...
bool has_uvs() const
Returns true if this TextureReference actually uses the texture on geometry, with UV&#39;s and everything...
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:39
TexturePlacement * get_placement() const
Returns the particular TexturePlacement that is appropriate for this egg file.
This is the set of characteristics of a texture that, if different from another texture, prevent the two textures from sharing a PaletteImage.