goat3dgfx

view src/texture.h @ 29:9d581abd0bfb

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Mar 2014 02:18:15 +0200
parents 7d6b667821cf
children 253542d715f4
line source
1 #ifndef TEXTURE_H_
2 #define TEXTURE_H_
4 #include "dataset.h"
5 #include "opengl.h"
7 namespace goatgfx {
9 class Image;
11 enum TextureType { TEX_2D, TEX_CUBE };
13 class Texture {
14 private:
15 unsigned int id;
16 unsigned int target;
17 unsigned int texfmt;
18 int sz[3];
19 Image *img;
21 Texture(const Texture &tex) {}
22 Texture &operator =(const Texture &tex) { return *this; }
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);
28 bool load_cube(const char *fname);
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);
34 public:
35 Texture();
36 ~Texture();
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);
42 unsigned int get_format() const;
44 int get_size(int dim) const;
46 void create(int xsz, int ysz, TextureType type = TEX_2D, unsigned int ifmt = GL_RGBA);
47 void set_image(const Image &img, int idx = -1);
49 bool load(const char *fname);
51 unsigned int get_id() const;
52 TextureType get_type() const;
54 void bind(int tex_unit = 0) const;
56 friend class TextureSet;
57 };
59 void bind_texture(Texture *tex, int tunit = 0);
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);
68 public:
69 TextureSet();
70 };
72 } // namespace goatgfx
74 #endif // TEXTURE_H_