1 #ifndef MSP_GL_TEXTURE_H_
2 #define MSP_GL_TEXTURE_H_
4 #include <msp/datafile/objectloader.h>
17 /// Bilinear filtering
20 /// Mipmapping without filtering
21 NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
23 /// Linear filtering between two mipmap levels
24 NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
26 /// Bilinear filtering on the closest mipmap level
27 LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
29 /// Trilinear filtering between two mipmap levels
30 LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
36 /// Tile the texture infinitely
39 /// Extend the texels at the edge of the texture to infinity
40 CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
42 /// Tile the texture, with every other repetition mirrored
43 MIRRORED_REPEAT = GL_MIRRORED_REPEAT
48 Base class for textures. This class only defines operations common for all
49 texture types and is not instantiable. For specifying images for textures, see
50 one of the dimensioned texture classes.
52 A texture is generally rendered at a size that's either smaller or larger than
53 its native size, so that the texture coordinates do not exactly correspond to
54 the texels of the texture. The kind of filtering used, if any, is determined
55 by the minification and magnification filter parameters. The default is LINEAR
56 for magnification and NEAREST_MIPMAP_LINEAR for minification.
58 When a mipmapped filter is in use, the texture consists of a stack of mipmap
59 images. Level 0 is the base image. Each level above 0 has half the size of
60 the previous level, rounded down and clamped to 1. The level with size 1 in
61 all dimensions is the last mipmap level. All levels must be allocated for the
64 If texture coordinates fall outside of the principal range of the texture,
65 wrapping is applied. The default for all directions is REPEAT.
67 class Texture: public Resource
70 class Loader: public DataFile::CollectionObjectLoader<Texture>
77 Loader(Texture &, Collection &);
81 void filter(TextureFilter);
82 void generate_mipmap(bool);
83 void mag_filter(TextureFilter);
84 void max_anisotropy(float);
85 void min_filter(TextureFilter);
86 void wrap(TextureWrap);
87 void wrap_r(TextureWrap);
88 void wrap_s(TextureWrap);
89 void wrap_t(TextureWrap);
107 TextureFilter min_filter;
108 TextureFilter mag_filter;
109 float max_anisotropy;
116 mutable int dirty_params;
118 Texture(GLenum, ResourceManager * = 0);
119 Texture(const Texture &);
120 Texture &operator=(const Texture &);
125 void update_parameter(int) const;
127 void set_min_filter(TextureFilter);
128 void set_mag_filter(TextureFilter);
130 /** Sets filter for both minification and magnification. Since mipmapping
131 is not applicable to magnification, LINEAR is used instead. */
132 void set_filter(TextureFilter);
134 void set_max_anisotropy(float);
136 /** Sets the wrapping mode for all coordinates. */
137 void set_wrap(TextureWrap);
139 void set_wrap_s(TextureWrap);
140 void set_wrap_t(TextureWrap);
141 void set_wrap_r(TextureWrap);
143 /** Sets automatic mipmap generation. If enabled, mipmaps are generated
144 when a texture image is uploaded. */
145 void set_generate_mipmap(bool);
147 /** Sets depth texture comparison. Has no effect on other formats. When
148 comparison is enabled, the third component of the texture coordinate is
149 compared against the texel value, and the result is returned as the texture
151 void set_compare_enabled(bool);
153 /** Sets the function to use for depth comparison. */
154 void set_compare_func(Predicate);
156 GLenum get_target() const { return target; }
157 unsigned get_id() const { return id; }
159 void bind() const { bind_to(0); }
160 void bind_to(unsigned) const;
162 static const Texture *current(unsigned = 0);
163 static void unbind() { unbind_from(0); }
164 static void unbind_from(unsigned);
166 virtual UInt64 get_data_size() const { return 0; }