X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=ld42_outofspace;a=blobdiff_plain;f=src%2Ftexture.h;fp=src%2Ftexture.h;h=5f74e985d907d1ab2ba4b91d1db4a690c1b6b530;hp=0000000000000000000000000000000000000000;hb=b8200afc389ccca3e86463eb48c0563c0e093552;hpb=cf0e9a55d004e5339adc265b7ea6f41bae5c3cfe diff --git a/src/texture.h b/src/texture.h new file mode 100644 index 0000000..5f74e98 --- /dev/null +++ b/src/texture.h @@ -0,0 +1,61 @@ +#ifndef TEXTURE_H_ +#define TEXTURE_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); + void set_anisotropy(int aniso); + + unsigned int get_format() const; + + int get_size(int dim) const; + int get_width() const; + int get_height() 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; +}; + +void bind_texture(Texture *tex, int tunit = 0); + +#endif // TEXTURE_H_