00001 /********************************************************************** 00002 * texture.H 00003 **********************************************************************/ 00004 #ifndef __TEXTURE_H 00005 #define __TEXTURE_H 00006 00007 #include "std/fstream.H" 00008 #include "std/ref.H" 00009 #include "std/support.H" 00010 #include "mlib/points.H" 00011 #include "geom/image.H" 00012 #include "disp/bbox.H" 00013 00014 MAKE_PTR_BASEC(TEXTURE); 00015 #define CTEXTUREptr const TEXTUREptr 00016 00017 /********************************************************************** 00018 * TEXTURE: 00019 **********************************************************************/ 00020 class TEXTURE : public REFcounter { 00021 public: 00022 //******** MANAGERS ******** 00023 TEXTURE() : _image_not_available(false), _expand_image(true) {} 00024 TEXTURE(Cstr_ptr &file) : _file(file), _image_not_available(false), 00025 _expand_image(true) { 00026 // we don't load the image from file 00027 // until we actually need it 00028 } 00029 virtual ~TEXTURE() {} 00030 00031 //******** ACCESSORS ******** 00032 Cstr_ptr& file() const { return _file; } 00033 const Image& image() const { return _img; } 00034 Image& image() { return _img; } 00035 00036 bool load_attempt_failed() const { return _image_not_available; } 00037 00038 /** 00039 * Resizes an image to the least powers of 2 greater than width and height. 00040 */ 00041 // expand image so dimensions are powers of two: 00042 // also computes the scale factors so texture coordinates 00043 // in [0,1]x[0,1] map to the real image, not the padded 00044 // extra parts that are added to reach a full power of 2 size: 00045 void expand_image(); 00046 00047 public: 00048 00049 virtual int load_image(); 00050 virtual int set_image(unsigned char *data, int w, int h, uint bpp=3); 00051 00052 virtual bool load_texture (unsigned char **copy=0) = 0; 00053 virtual void apply_texture(mlib::CWtransf *xf=0) = 0; 00054 00055 void set_expand_image(bool expand) { _expand_image = expand;} 00056 00057 // 2D or 3D texture 00058 virtual int dimension() const { return 2; } 00059 00060 protected: 00061 str_ptr _file; 00062 Image _img; 00063 mlib::Wtransf _scale; 00064 bool _image_not_available; // true if load attempt failed 00065 bool _expand_image; 00066 00067 // this method leaves out the scaling, so is probably not 00068 // what callers want: 00069 void expand_power2(int width, int height); 00070 }; 00071 00072 #endif // __TEXTURE_H 00073 00074 // end of file texture.H