]> git.tdb.fi Git - libs/gl.git/blob - source/texture.h
Use the lexical_cast framework instead of istreams
[libs/gl.git] / source / texture.h
1 #ifndef MSP_GL_TEXTURE_H_
2 #define MSP_GL_TEXTURE_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "gl.h"
6 #include "predicate.h"
7
8 namespace Msp {
9 namespace GL {
10
11 enum TextureFilter
12 {
13         NEAREST                = GL_NEAREST,
14         LINEAR                 = GL_LINEAR,
15         NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
16         NEAREST_MIPMAP_LINEAR  = GL_NEAREST_MIPMAP_LINEAR,
17         LINEAR_MIPMAP_NEAREST  = GL_LINEAR_MIPMAP_NEAREST,
18         LINEAR_MIPMAP_LINEAR   = GL_LINEAR_MIPMAP_LINEAR
19 };
20
21
22 enum TextureWrap
23 {
24         REPEAT          = GL_REPEAT,
25         CLAMP_TO_EDGE   = GL_CLAMP_TO_EDGE,
26         MIRRORED_REPEAT = GL_MIRRORED_REPEAT
27 };
28
29
30 /**
31 Base class for textures.  This class only defines operations common for all
32 texture types and is not instantiable.  For specifying images for textures, see
33 one of the dimensioned texture classes.
34 */
35 class Texture
36 {
37 protected:
38         class Loader: public DataFile::ObjectLoader<Texture>
39         {
40         public:
41                 Loader(Texture &);
42                 void generate_mipmap(bool);
43                 void mag_filter(TextureFilter);
44                 void min_filter(TextureFilter);
45                 void wrap(TextureWrap);
46                 void wrap_r(TextureWrap);
47                 void wrap_s(TextureWrap);
48                 void wrap_t(TextureWrap);
49         };
50
51         enum ParameterMask
52         {
53                 MIN_FILTER = 1,
54                 MAG_FILTER = 2,
55                 WRAP_S = 4,
56                 WRAP_T = 8,
57                 WRAP_R = 16,
58                 GENERATE_MIPMAP = 32,
59                 COMPARE = 64,
60                 COMPARE_FUNC = 128
61         };
62
63         unsigned id;
64         GLenum target;
65         TextureFilter min_filter;
66         TextureFilter mag_filter;
67         TextureWrap wrap_s;
68         TextureWrap wrap_t;
69         TextureWrap wrap_r;
70         bool gen_mipmap;
71         bool compare;
72         Predicate cmp_func;
73         mutable int dirty_params;
74
75         Texture(GLenum);
76         Texture(const Texture &);
77         Texture &operator=(const Texture &);
78 public:
79         ~Texture();
80
81 protected:
82         void update_parameter(int) const;
83 public:
84         void set_min_filter(TextureFilter);
85         void set_mag_filter(TextureFilter);
86         void set_wrap(TextureWrap);
87         void set_wrap_s(TextureWrap);
88         void set_wrap_t(TextureWrap);
89         void set_wrap_r(TextureWrap);
90         void set_generate_mipmap(bool);
91         void set_compare_enabled(bool);
92         void set_compare_func(Predicate);
93         GLenum get_target() const { return target; }
94         unsigned get_id() const { return id; }
95
96         void bind() const;
97         void bind_to(unsigned) const;
98
99         static const Texture *current();
100         static void unbind();
101         static void unbind_from(unsigned);
102 };
103
104 } // namespace GL
105 } // namespace Msp
106
107 #endif