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