00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef TEXTUREREFERENCE_H
00020 #define TEXTUREREFERENCE_H
00021
00022 #include "pandatoolbase.h"
00023
00024 #include "textureProperties.h"
00025 #include "palettizer.h"
00026
00027 #include "luse.h"
00028 #include "typedWritable.h"
00029
00030 class TextureImage;
00031 class SourceTextureImage;
00032 class Filename;
00033 class EggFile;
00034 class EggData;
00035 class EggTexture;
00036 class EggGroupNode;
00037 class EggPrimitive;
00038 class TexturePlacement;
00039
00040
00041
00042
00043
00044
00045
00046
00047 class TextureReference : public TypedWritable {
00048 public:
00049 TextureReference();
00050 ~TextureReference();
00051
00052 void from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex);
00053
00054 EggFile *get_egg_file() const;
00055 SourceTextureImage *get_source() const;
00056 TextureImage *get_texture() const;
00057
00058 bool has_uvs() const;
00059 const TexCoordd &get_min_uv() const;
00060 const TexCoordd &get_max_uv() const;
00061
00062 EggTexture::WrapMode get_wrap_u() const;
00063 EggTexture::WrapMode get_wrap_v() const;
00064
00065 void set_placement(TexturePlacement *placement);
00066 void clear_placement();
00067 TexturePlacement *get_placement() const;
00068
00069 void mark_egg_stale();
00070 void update_egg();
00071 void apply_properties_to_source();
00072
00073 void output(ostream &out) const;
00074 void write(ostream &out, int indent_level = 0) const;
00075
00076 private:
00077 void get_uv_range(EggGroupNode *group, Palettizer::RemapUV remap);
00078 void update_uv_range(EggGroupNode *group, Palettizer::RemapUV remap);
00079
00080 bool get_geom_uvs(EggPrimitive *geom,
00081 TexCoordd &geom_min_uv, TexCoordd &geom_max_uv);
00082 void translate_geom_uvs(EggPrimitive *geom, const TexCoordd &trans) const;
00083 static void collect_uv(bool &any_uvs, TexCoordd &min_uv, TexCoordd &max_uv,
00084 const TexCoordd &got_min_uv,
00085 const TexCoordd &got_max_uv);
00086 static LVector2d translate_uv(const TexCoordd &min_uv,
00087 const TexCoordd &max_uv);
00088
00089 EggFile *_egg_file;
00090 EggTexture *_egg_tex;
00091 EggData *_egg_data;
00092
00093 LMatrix3d _tex_mat, _inv_tex_mat;
00094 SourceTextureImage *_source_texture;
00095 TexturePlacement *_placement;
00096
00097 bool _uses_alpha;
00098
00099 bool _any_uvs;
00100 TexCoordd _min_uv, _max_uv;
00101 EggTexture::WrapMode _wrap_u, _wrap_v;
00102
00103 TextureProperties _properties;
00104
00105
00106 public:
00107 static void register_with_read_factory();
00108 virtual void write_datagram(BamWriter *writer, Datagram &datagram);
00109 virtual int complete_pointers(TypedWritable **p_list,
00110 BamReader *manager);
00111
00112 protected:
00113 static TypedWritable *make_TextureReference(const FactoryParams ¶ms);
00114 void fillin(DatagramIterator &scan, BamReader *manager);
00115
00116 public:
00117 static TypeHandle get_class_type() {
00118 return _type_handle;
00119 }
00120 static void init_type() {
00121 TypedWritable::init_type();
00122 register_type(_type_handle, "TextureReference",
00123 TypedWritable::get_class_type());
00124 }
00125 virtual TypeHandle get_type() const {
00126 return get_class_type();
00127 }
00128
00129 private:
00130 static TypeHandle _type_handle;
00131 };
00132
00133 INLINE ostream &
00134 operator << (ostream &out, const TextureReference &ref) {
00135 ref.output(out);
00136 return out;
00137 }
00138
00139 #endif
00140
00141