goat3dgfx
view src/texture.h @ 0:1873dfd13f2d
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 14 Nov 2013 05:27:09 +0200 |
parents | |
children | 3d96734fd477 |
line source
1 #ifndef TEXTURE_H_
2 #define TEXTURE_H_
4 #include "dataset.h"
5 #include "opengl.h"
7 class Image;
9 class Texture {
10 protected:
11 unsigned int id;
12 unsigned int target;
13 unsigned int texfmt;
14 int sz[3];
16 Texture(const Texture &tex) {}
17 Texture &operator =(const Texture &tex) { return *this; }
19 public:
20 Texture();
21 virtual ~Texture();
23 void set_wrapping(unsigned int wrap);
24 void set_filtering(unsigned int filt);
25 void set_filtering(unsigned int min_filt, unsigned int mag_filt);
27 unsigned int get_format() const;
29 virtual int get_size(int dim) const;
31 virtual void create(int xsz, int ysz, unsigned int ifmt = GL_RGBA) = 0;
32 virtual void set_image(const Image &img, int idx = 0) = 0;
34 virtual bool load(const char *fname) = 0;
35 virtual bool save(const char *fname) const = 0;
37 virtual unsigned int get_id() const;
39 virtual void bind(int tex_unit = 0) const;
40 };
42 class Texture2D : public Texture {
43 public:
44 Texture2D();
46 virtual void create(int xsz, int ysz, unsigned int ifmt = GL_RGBA);
47 virtual void set_image(const Image &img, int idx = 0);
49 virtual bool load(const char *fname);
50 virtual bool save(const char *fname) const;
51 };
53 class TextureCube : public Texture {
54 public:
55 TextureCube();
57 virtual void create(int xsz, int ysz, unsigned int ifmt = GL_RGBA);
58 virtual void set_image(const Image &img, int idx = 0);
60 virtual bool load(const char *fname);
61 virtual bool save(const char *fname) const;
62 };
64 void set_texture(Texture *tex, int tunit = 0);
66 /** loads a texture autodetecting whether it's a 2D texture or
67 * cubemap and creating the correct Texture subclass instance.
68 */
69 Texture *load_texture(const char *fname);
71 class TextureSet : public DataSet<Texture*> {
72 public:
73 TextureSet();
74 };
76 #endif // TEXTURE_H_