rev |
line source |
nuclear@0
|
1 #ifndef TEXTURE_H_
|
nuclear@0
|
2 #define TEXTURE_H_
|
nuclear@0
|
3
|
nuclear@0
|
4 #include "dataset.h"
|
nuclear@0
|
5 #include "opengl.h"
|
nuclear@0
|
6
|
nuclear@0
|
7 class Image;
|
nuclear@0
|
8
|
nuclear@0
|
9 class Texture {
|
nuclear@0
|
10 protected:
|
nuclear@0
|
11 unsigned int id;
|
nuclear@0
|
12 unsigned int target;
|
nuclear@0
|
13 unsigned int texfmt;
|
nuclear@0
|
14 int sz[3];
|
nuclear@0
|
15
|
nuclear@0
|
16 Texture(const Texture &tex) {}
|
nuclear@0
|
17 Texture &operator =(const Texture &tex) { return *this; }
|
nuclear@0
|
18
|
nuclear@0
|
19 public:
|
nuclear@0
|
20 Texture();
|
nuclear@0
|
21 virtual ~Texture();
|
nuclear@0
|
22
|
nuclear@0
|
23 void set_wrapping(unsigned int wrap);
|
nuclear@0
|
24 void set_filtering(unsigned int filt);
|
nuclear@0
|
25 void set_filtering(unsigned int min_filt, unsigned int mag_filt);
|
nuclear@0
|
26
|
nuclear@0
|
27 unsigned int get_format() const;
|
nuclear@0
|
28
|
nuclear@0
|
29 virtual int get_size(int dim) const;
|
nuclear@0
|
30
|
nuclear@0
|
31 virtual void create(int xsz, int ysz, unsigned int ifmt = GL_RGBA) = 0;
|
nuclear@0
|
32 virtual void set_image(const Image &img, int idx = 0) = 0;
|
nuclear@0
|
33
|
nuclear@0
|
34 virtual bool load(const char *fname) = 0;
|
nuclear@0
|
35 virtual bool save(const char *fname) const = 0;
|
nuclear@0
|
36
|
nuclear@0
|
37 virtual unsigned int get_id() const;
|
nuclear@0
|
38
|
nuclear@0
|
39 virtual void bind(int tex_unit = 0) const;
|
nuclear@0
|
40 };
|
nuclear@0
|
41
|
nuclear@0
|
42 class Texture2D : public Texture {
|
nuclear@0
|
43 public:
|
nuclear@0
|
44 Texture2D();
|
nuclear@0
|
45
|
nuclear@0
|
46 virtual void create(int xsz, int ysz, unsigned int ifmt = GL_RGBA);
|
nuclear@0
|
47 virtual void set_image(const Image &img, int idx = 0);
|
nuclear@0
|
48
|
nuclear@0
|
49 virtual bool load(const char *fname);
|
nuclear@0
|
50 virtual bool save(const char *fname) const;
|
nuclear@0
|
51 };
|
nuclear@0
|
52
|
nuclear@0
|
53 class TextureCube : public Texture {
|
nuclear@0
|
54 private:
|
nuclear@0
|
55 bool load_multi(const Image &img, const float *xoffsets, const float *yoffsets, float sz,
|
nuclear@0
|
56 unsigned int rotmask = 0);
|
nuclear@0
|
57
|
nuclear@0
|
58 public:
|
nuclear@0
|
59 TextureCube();
|
nuclear@0
|
60
|
nuclear@0
|
61 virtual void create(int xsz, int ysz, unsigned int ifmt = GL_RGBA);
|
nuclear@0
|
62 virtual void set_image(const Image &img, int idx = 0);
|
nuclear@0
|
63
|
nuclear@0
|
64 virtual bool load(const char *fname);
|
nuclear@0
|
65 virtual bool save(const char *fname) const;
|
nuclear@0
|
66 };
|
nuclear@0
|
67
|
nuclear@0
|
68 void set_texture(Texture *tex, int tunit = 0);
|
nuclear@0
|
69
|
nuclear@0
|
70 /** loads a texture autodetecting whether it's a 2D texture or
|
nuclear@0
|
71 * cubemap and creating the correct Texture subclass instance.
|
nuclear@0
|
72 */
|
nuclear@0
|
73 Texture *load_texture(const char *fname);
|
nuclear@0
|
74
|
nuclear@0
|
75 class TextureSet : public DataSet<Texture*> {
|
nuclear@0
|
76 public:
|
nuclear@0
|
77 TextureSet();
|
nuclear@0
|
78 };
|
nuclear@0
|
79
|
nuclear@0
|
80 #endif // TEXTURE_H_
|