shadows, textures, resource managers... shaders...
[antikythera] / src / texture.h
diff --git a/src/texture.h b/src/texture.h
new file mode 100644 (file)
index 0000000..09b2c91
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef TEXTURE_H_
+#define TEXTURE_H_
+
+#include "dataset.h"
+#include "opengl.h"
+
+class Image;
+
+enum TextureType { TEX_2D, TEX_CUBE };
+
+class Texture {
+private:
+       unsigned int id;
+       unsigned int target;
+       unsigned int texfmt;
+       int sz[3];
+       Image *img;
+       static Image *default_img;
+
+       Texture(const Texture &tex) {}
+       Texture &operator =(const Texture &tex) { return *this; }
+
+       void set_image_2d(const Image &img);
+       bool set_image_cube(const Image &img, int idx);
+       bool set_image_cube(const Image &img);
+
+       bool load_cube(const char *fname);
+
+       /* for loading multiple cubemap faces from a single image */
+       bool set_cube_multi(const Image &img, const float *xoffsets, const float *yoffsets, float sz,
+               unsigned int rotmask = 0);
+
+public:
+       Texture();
+       ~Texture();
+
+       void set_wrapping(unsigned int wrap);
+       void set_filtering(unsigned int filt);
+       void set_filtering(unsigned int min_filt, unsigned int mag_filt);
+
+       unsigned int get_format() const;
+
+       int get_size(int dim) const;
+
+       void create(int xsz, int ysz, TextureType type = TEX_2D, unsigned int ifmt = GL_RGBA);
+       void create_default(TextureType type = TEX_2D);
+       void set_image(const Image &img, int idx = -1);
+
+       bool load(const char *fname);
+
+       unsigned int get_id() const;
+       TextureType get_type() const;
+
+       void bind(int tex_unit = 0) const;
+
+       friend class TextureSet;
+};
+
+void bind_texture(Texture *tex, int tunit = 0);
+
+class TextureSet : public DataSet<Texture*> {
+private:
+       static Texture *create_tex();
+       static bool load_tex(Texture *tex, const char *fname);
+       static bool done_tex(Texture *tex);
+       static void free_tex(Texture *tex);
+
+public:
+       TextureSet();
+
+       Texture *get_texture(const char *name, TextureType type = TEX_2D) const;
+};
+
+#endif // TEXTURE_H_