vrshoot
view src/texture.h @ 1:e7ca128b8713
looks nice :)
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 02 Feb 2014 00:35:22 +0200 |
parents | |
children |
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 private:
55 bool load_multi(const Image &img, const float *xoffsets, const float *yoffsets, float sz,
56 unsigned int rotmask = 0);
58 public:
59 TextureCube();
61 virtual void create(int xsz, int ysz, unsigned int ifmt = GL_RGBA);
62 virtual void set_image(const Image &img, int idx = 0);
64 virtual bool load(const char *fname);
65 virtual bool save(const char *fname) const;
66 };
68 void set_texture(Texture *tex, int tunit = 0);
70 /** loads a texture autodetecting whether it's a 2D texture or
71 * cubemap and creating the correct Texture subclass instance.
72 */
73 Texture *load_texture(const char *fname);
75 class TextureSet : public DataSet<Texture*> {
76 public:
77 TextureSet();
78 };
80 #endif // TEXTURE_H_