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