00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TEXTURE_H
00019 #define TEXTURE_H
00020
00021 #include "pandabase.h"
00022
00023 #include "imageBuffer.h"
00024 #include "pixelBuffer.h"
00025 #include "graphicsStateGuardianBase.h"
00026 #include "pmap.h"
00027
00028 class PNMImage;
00029 class TextureContext;
00030 class FactoryParams;
00031
00032
00033
00034
00035
00036 class EXPCL_PANDA Texture : public ImageBuffer {
00037 PUBLISHED:
00038 enum FilterType {
00039
00040
00041
00042 FT_nearest,
00043
00044
00045 FT_linear,
00046
00047
00048
00049
00050 FT_nearest_mipmap_nearest,
00051
00052
00053 FT_linear_mipmap_nearest,
00054
00055
00056 FT_nearest_mipmap_linear,
00057
00058
00059
00060 FT_linear_mipmap_linear,
00061
00062
00063 FT_invalid
00064 };
00065
00066 enum WrapMode {
00067 WM_clamp,
00068 WM_repeat,
00069 WM_mirror,
00070 WM_mirror_once,
00071 WM_border_color,
00072
00073 WM_invalid
00074 };
00075
00076 PUBLISHED:
00077 Texture();
00078 Texture(int xsize, int ysize, int components, int component_width, PixelBuffer::Type type, PixelBuffer::Format format,
00079 bool bAllocateRAM);
00080 ~Texture();
00081
00082 bool read(const Filename &fullpath, int primary_file_num_channels = 0);
00083 bool read(const Filename &fullpath, const Filename &alpha_fullpath,
00084 int primary_file_num_channels = 0, int alpha_file_channel = 0);
00085 bool write(const Filename &fullpath = "") const;
00086
00087 void set_wrapu(WrapMode wrap);
00088 void set_wrapv(WrapMode wrap);
00089 void set_minfilter(FilterType filter);
00090 void set_magfilter(FilterType filter);
00091 void set_anisotropic_degree(int anisotropic_degree);
00092 void set_border_color(const Colorf &color);
00093
00094 INLINE WrapMode get_wrapu() const;
00095 INLINE WrapMode get_wrapv() const;
00096 INLINE FilterType get_minfilter() const;
00097 INLINE FilterType get_magfilter() const;
00098 INLINE int get_anisotropic_degree() const;
00099 INLINE bool uses_mipmaps() const;
00100
00101 public:
00102 bool load(const PNMImage &pnmimage);
00103 bool store(PNMImage &pnmimage) const;
00104
00105 static bool is_mipmap(FilterType type);
00106
00107 TextureContext *prepare(GraphicsStateGuardianBase *gsg);
00108 void unprepare();
00109 void unprepare(GraphicsStateGuardianBase *gsg);
00110 void clear_gsg(GraphicsStateGuardianBase *gsg);
00111
00112 INLINE bool has_ram_image() const;
00113 PixelBuffer *get_ram_image();
00114 INLINE void set_keep_ram_image(bool keep_ram_image);
00115 INLINE bool get_keep_ram_image() const;
00116
00117 INLINE void apply(GraphicsStateGuardianBase *gsg);
00118
00119 virtual void copy(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr);
00120 virtual void copy(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr,
00121 const RenderBuffer &rb);
00122
00123
00124
00125
00126 enum DirtyFlags {
00127 DF_image = 0x001,
00128 DF_wrap = 0x002,
00129 DF_filter = 0x004,
00130 DF_mipmap = 0x008,
00131 };
00132
00133 void mark_dirty(int flags_to_set);
00134
00135 static WrapMode string_wrap_mode(const string &string);
00136 static FilterType string_filter_type(const string &string);
00137
00138 private:
00139 WrapMode _wrapu;
00140 WrapMode _wrapv;
00141 FilterType _minfilter;
00142 FilterType _magfilter;
00143 int _anisotropic_degree;
00144 bool _keep_ram_image;
00145 Colorf _border_color;
00146
00147
00148
00149
00150
00151 typedef pmap<GraphicsStateGuardianBase *, TextureContext *> Contexts;
00152 Contexts _contexts;
00153
00154
00155
00156
00157 int _all_dirty_flags;
00158
00159 public:
00160
00161
00162 PT(PixelBuffer) _pbuffer;
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 public:
00177 static void register_with_read_factory(void);
00178 virtual void write_datagram(BamWriter* manager, Datagram &me);
00179
00180 static TypedWritable *make_Texture(const FactoryParams ¶ms);
00181
00182 protected:
00183 void fillin(DatagramIterator& scan, BamReader* manager);
00184
00185 public:
00186 static TypeHandle get_class_type() {
00187 return _type_handle;
00188 }
00189 static void init_type() {
00190 ImageBuffer::init_type();
00191 register_type(_type_handle, "Texture",
00192 ImageBuffer::get_class_type());
00193 }
00194 virtual TypeHandle get_type() const {
00195 return get_class_type();
00196 }
00197 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00198
00199 private:
00200
00201 static TypeHandle _type_handle;
00202
00203 friend class TextureContext;
00204 };
00205
00206 #include "texture.I"
00207
00208 #endif
00209