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