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