doing stuff
[ld42_outofspace] / src / texture.h
1 #ifndef TEXTURE_H_
2 #define TEXTURE_H_
3
4 #include "opengl.h"
5
6 class Image;
7
8 enum TextureType { TEX_2D, TEX_CUBE };
9
10 class Texture {
11 private:
12         unsigned int id;
13         unsigned int target;
14         unsigned int texfmt;
15         int sz[3];
16         Image *img;
17         static Image *default_img;
18
19         Texture(const Texture &tex) {}
20         Texture &operator =(const Texture &tex) { return *this; }
21
22         void set_image_2d(const Image &img);
23         bool set_image_cube(const Image &img, int idx);
24         bool set_image_cube(const Image &img);
25
26         bool load_cube(const char *fname);
27
28         /* for loading multiple cubemap faces from a single image */
29         bool set_cube_multi(const Image &img, const float *xoffsets, const float *yoffsets, float sz,
30                 unsigned int rotmask = 0);
31
32 public:
33         Texture();
34         ~Texture();
35
36         void set_wrapping(unsigned int wrap);
37         void set_filtering(unsigned int filt);
38         void set_filtering(unsigned int min_filt, unsigned int mag_filt);
39         void set_anisotropy(int aniso);
40
41         unsigned int get_format() const;
42
43         int get_size(int dim) const;
44         int get_width() const;
45         int get_height() const;
46
47         void create(int xsz, int ysz, TextureType type = TEX_2D, unsigned int ifmt = GL_RGBA);
48         void create_default(TextureType type = TEX_2D);
49         void set_image(const Image &img, int idx = -1);
50
51         bool load(const char *fname);
52
53         unsigned int get_id() const;
54         TextureType get_type() const;
55
56         void bind(int tex_unit = 0) const;
57 };
58
59 void bind_texture(Texture *tex, int tunit = 0);
60
61 #endif  // TEXTURE_H_