1 #ifndef MSP_GL_TEXTURE_H_
2 #define MSP_GL_TEXTURE_H_
4 #include <msp/datafile/objectloader.h>
16 /// Bilinear filtering
19 /// Mipmapping without filtering
20 NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
22 /// Linear filtering between two mipmap levels
23 NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
25 /// Bilinear filtering on the closest mipmap level
26 LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
28 /// Trilinear filtering between two mipmap levels
29 LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
35 /// Tile the texture infinitely
38 /// Extend the texels at the edge of the texture to infinity
39 CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
41 /// Tile the texture, with every other repetition mirrored
42 MIRRORED_REPEAT = GL_MIRRORED_REPEAT
47 Base class for textures. This class only defines operations common for all
48 texture types and is not instantiable. For specifying images for textures, see
49 one of the dimensioned texture classes.
51 A texture is generally rendered at a size that's either smaller or larger than
52 its native size, so that the texture coordinates do not exactly correspond to
53 the texels of the texture. The kind of filtering used, if any, is determined
54 by the minification and magnification filter parameters. The default is LINEAR
55 for magnification and NEAREST_MIPMAP_LINEAR for minification.
57 When a mipmapped filter is in use, the texture consists of a stack of mipmap
58 images. Level 0 is the base image. Each level above 0 has half the size of
59 the previous level, rounded down and clamped to 1. The level with size 1 in
60 all dimensions is the last mipmap level. All levels must be allocated for the
63 If texture coordinates fall outside of the principal range of the texture,
64 wrapping is applied. The default for all directions is REPEAT.
69 class Loader: public DataFile::ObjectLoader<Texture>
73 void generate_mipmap(bool);
74 void mag_filter(TextureFilter);
75 void min_filter(TextureFilter);
76 void wrap(TextureWrap);
77 void wrap_r(TextureWrap);
78 void wrap_s(TextureWrap);
79 void wrap_t(TextureWrap);
96 TextureFilter min_filter;
97 TextureFilter mag_filter;
104 mutable int dirty_params;
107 Texture(const Texture &);
108 Texture &operator=(const Texture &);
113 void update_parameter(int) const;
115 void set_min_filter(TextureFilter);
116 void set_mag_filter(TextureFilter);
118 /** Sets the wrapping mode for all coordinates. */
119 void set_wrap(TextureWrap);
121 void set_wrap_s(TextureWrap);
122 void set_wrap_t(TextureWrap);
123 void set_wrap_r(TextureWrap);
125 /** Sets automatic mipmap generation. If enabled, mipmaps are generated
126 when a texture image is uploaded. */
127 void set_generate_mipmap(bool);
129 /** Sets depth texture comparison. Has no effect on other formats. When
130 comparison is enabled, the third component of the texture coordinate is
131 compared against the texel value, and the result is returned as the texture
133 void set_compare_enabled(bool);
135 /** Sets the function to use for depth comparison. */
136 void set_compare_func(Predicate);
138 GLenum get_target() const { return target; }
139 unsigned get_id() const { return id; }
142 void bind_to(unsigned) const;
144 static const Texture *current();
145 static void unbind();
146 static void unbind_from(unsigned);