X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=antikythera;a=blobdiff_plain;f=src%2Ftexture.h;fp=src%2Ftexture.h;h=09b2c916ede20141bf4f65d342bccad59fd525e0;hp=0000000000000000000000000000000000000000;hb=ccc1a688b59e25bb934a0d3e2bbf477960068d4f;hpb=080d7a779d43f549fc16c44e709cbf5989180fdf diff --git a/src/texture.h b/src/texture.h new file mode 100644 index 0000000..09b2c91 --- /dev/null +++ b/src/texture.h @@ -0,0 +1,74 @@ +#ifndef TEXTURE_H_ +#define TEXTURE_H_ + +#include "dataset.h" +#include "opengl.h" + +class Image; + +enum TextureType { TEX_2D, TEX_CUBE }; + +class Texture { +private: + unsigned int id; + unsigned int target; + unsigned int texfmt; + int sz[3]; + Image *img; + static Image *default_img; + + Texture(const Texture &tex) {} + Texture &operator =(const Texture &tex) { return *this; } + + void set_image_2d(const Image &img); + bool set_image_cube(const Image &img, int idx); + bool set_image_cube(const Image &img); + + bool load_cube(const char *fname); + + /* for loading multiple cubemap faces from a single image */ + bool set_cube_multi(const Image &img, const float *xoffsets, const float *yoffsets, float sz, + unsigned int rotmask = 0); + +public: + Texture(); + ~Texture(); + + void set_wrapping(unsigned int wrap); + void set_filtering(unsigned int filt); + void set_filtering(unsigned int min_filt, unsigned int mag_filt); + + unsigned int get_format() const; + + int get_size(int dim) const; + + void create(int xsz, int ysz, TextureType type = TEX_2D, unsigned int ifmt = GL_RGBA); + void create_default(TextureType type = TEX_2D); + void set_image(const Image &img, int idx = -1); + + bool load(const char *fname); + + unsigned int get_id() const; + TextureType get_type() const; + + void bind(int tex_unit = 0) const; + + friend class TextureSet; +}; + +void bind_texture(Texture *tex, int tunit = 0); + +class TextureSet : public DataSet { +private: + static Texture *create_tex(); + static bool load_tex(Texture *tex, const char *fname); + static bool done_tex(Texture *tex); + static void free_tex(Texture *tex); + +public: + TextureSet(); + + Texture *get_texture(const char *name, TextureType type = TEX_2D) const; +}; + +#endif // TEXTURE_H_