goat3dgfx

view src/texture.h @ 34:3eb6c8f89fe1

merge
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Mar 2014 17:41:10 +0200
parents dc5918c62a64
children
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;
20 static Image *default_img;
22 Texture(const Texture &tex) {}
23 Texture &operator =(const Texture &tex) { return *this; }
25 void set_image_2d(const Image &img);
26 bool set_image_cube(const Image &img, int idx);
27 bool set_image_cube(const Image &img);
29 bool load_cube(const char *fname);
31 /* for loading multiple cubemap faces from a single image */
32 bool set_cube_multi(const Image &img, const float *xoffsets, const float *yoffsets, float sz,
33 unsigned int rotmask = 0);
35 public:
36 Texture();
37 ~Texture();
39 void set_wrapping(unsigned int wrap);
40 void set_filtering(unsigned int filt);
41 void set_filtering(unsigned int min_filt, unsigned int mag_filt);
43 unsigned int get_format() const;
45 int get_size(int dim) const;
47 void create(int xsz, int ysz, TextureType type = TEX_2D, unsigned int ifmt = GL_RGBA);
48 void create_default(TextureType type = TEX_2D);
49 void set_image(const Image &img, int idx = -1);
51 bool load(const char *fname);
53 unsigned int get_id() const;
54 TextureType get_type() const;
56 void bind(int tex_unit = 0) const;
58 friend class TextureSet;
59 };
61 void bind_texture(Texture *tex, int tunit = 0);
63 class TextureSet : public DataSet<Texture*> {
64 private:
65 static Texture *create_tex();
66 static bool load_tex(Texture *tex, const char *fname);
67 static bool done_tex(Texture *tex);
68 static void free_tex(Texture *tex);
70 public:
71 TextureSet();
73 Texture *get_texture(const char *name, TextureType type = TEX_2D) const;
74 };
76 } // namespace goatgfx
78 #endif // TEXTURE_H_