nuclear@0: #ifndef TEXTURE_H_ nuclear@0: #define TEXTURE_H_ nuclear@0: nuclear@0: #include "dataset.h" nuclear@0: #include "opengl.h" nuclear@0: nuclear@15: namespace goatgfx { nuclear@15: nuclear@0: class Image; nuclear@0: nuclear@24: enum TextureType { TEX_2D, TEX_CUBE }; nuclear@24: nuclear@0: class Texture { nuclear@24: private: nuclear@0: unsigned int id; nuclear@0: unsigned int target; nuclear@0: unsigned int texfmt; nuclear@0: int sz[3]; nuclear@24: Image *img; nuclear@33: static Image *default_img; nuclear@0: nuclear@0: Texture(const Texture &tex) {} nuclear@0: Texture &operator =(const Texture &tex) { return *this; } nuclear@0: nuclear@24: void set_image_2d(const Image &img); nuclear@24: bool set_image_cube(const Image &img, int idx); nuclear@24: bool set_image_cube(const Image &img); nuclear@24: nuclear@24: bool load_cube(const char *fname); nuclear@24: nuclear@24: /* for loading multiple cubemap faces from a single image */ nuclear@24: bool set_cube_multi(const Image &img, const float *xoffsets, const float *yoffsets, float sz, nuclear@24: unsigned int rotmask = 0); nuclear@24: nuclear@0: public: nuclear@0: Texture(); nuclear@24: ~Texture(); nuclear@0: nuclear@0: void set_wrapping(unsigned int wrap); nuclear@0: void set_filtering(unsigned int filt); nuclear@0: void set_filtering(unsigned int min_filt, unsigned int mag_filt); nuclear@0: nuclear@0: unsigned int get_format() const; nuclear@0: nuclear@24: int get_size(int dim) const; nuclear@0: nuclear@24: void create(int xsz, int ysz, TextureType type = TEX_2D, unsigned int ifmt = GL_RGBA); nuclear@33: void create_default(TextureType type = TEX_2D); nuclear@24: void set_image(const Image &img, int idx = -1); nuclear@0: nuclear@24: bool load(const char *fname); nuclear@0: nuclear@24: unsigned int get_id() const; nuclear@24: TextureType get_type() const; nuclear@0: nuclear@24: void bind(int tex_unit = 0) const; nuclear@24: nuclear@24: friend class TextureSet; nuclear@0: }; nuclear@0: nuclear@24: void bind_texture(Texture *tex, int tunit = 0); nuclear@0: nuclear@0: class TextureSet : public DataSet { nuclear@24: private: nuclear@24: static Texture *create_tex(); nuclear@24: static bool load_tex(Texture *tex, const char *fname); nuclear@24: static bool done_tex(Texture *tex); nuclear@24: static void free_tex(Texture *tex); nuclear@24: nuclear@0: public: nuclear@0: TextureSet(); nuclear@33: nuclear@33: Texture *get_texture(const char *name, TextureType type = TEX_2D) const; nuclear@0: }; nuclear@0: nuclear@15: } // namespace goatgfx nuclear@15: nuclear@0: #endif // TEXTURE_H_