1 #ifndef MSP_GL_TEXTURE_H_
2 #define MSP_GL_TEXTURE_H_
4 #include <msp/datafile/objectloader.h>
7 #include "pixelformat.h"
19 /// Bilinear filtering
22 /// Mipmapping without filtering
23 NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
25 /// Linear filtering between two mipmap levels
26 NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
28 /// Bilinear filtering on the closest mipmap level
29 LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
31 /// Trilinear filtering between two mipmap levels
32 LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
38 /// Tile the texture infinitely
41 /// Extend the texels at the edge of the texture to infinity
42 CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
44 /// Tile the texture, with every other repetition mirrored
45 MIRRORED_REPEAT = GL_MIRRORED_REPEAT
50 Base class for textures. This class only defines operations common for all
51 texture types and is not instantiable. For specifying images for textures, see
52 one of the dimensioned texture classes.
54 A texture is generally rendered at a size that's either smaller or larger than
55 its native size, so that the texture coordinates do not exactly correspond to
56 the texels of the texture. The kind of filtering used, if any, is determined
57 by the minification and magnification filter parameters. The default is LINEAR
58 for magnification and NEAREST_MIPMAP_LINEAR for minification.
60 When a mipmapped filter is in use, the texture consists of a stack of mipmap
61 images. Level 0 is the base image. Each level above 0 has half the size of
62 the previous level, rounded down and clamped to 1. The level with size 1 in
63 all dimensions is the last mipmap level. All levels must be allocated for the
66 If texture coordinates fall outside of the principal range of the texture,
67 wrapping is applied. The default for all directions is REPEAT.
69 class Texture: public Resource
72 class Loader: public DataFile::CollectionObjectLoader<Texture>
79 Loader(Texture &, Collection &);
83 void filter(TextureFilter);
84 void generate_mipmap(bool);
85 void mag_filter(TextureFilter);
86 void max_anisotropy(float);
87 void min_filter(TextureFilter);
88 void wrap(TextureWrap);
89 void wrap_r(TextureWrap);
90 void wrap_s(TextureWrap);
91 void wrap_t(TextureWrap);
101 GENERATE_MIPMAP = 32,
109 TextureFilter min_filter;
110 TextureFilter mag_filter;
111 float max_anisotropy;
118 mutable int dirty_params;
120 Texture(GLenum, ResourceManager * = 0);
121 Texture(const Texture &);
122 Texture &operator=(const Texture &);
127 static DataType get_alloc_type(PixelFormat);
129 void update_parameter(int) const;
131 void set_min_filter(TextureFilter);
132 void set_mag_filter(TextureFilter);
134 /** Sets filter for both minification and magnification. Since mipmapping
135 is not applicable to magnification, LINEAR is used instead. */
136 void set_filter(TextureFilter);
138 void set_max_anisotropy(float);
140 /** Sets the wrapping mode for all coordinates. */
141 void set_wrap(TextureWrap);
143 void set_wrap_s(TextureWrap);
144 void set_wrap_t(TextureWrap);
145 void set_wrap_r(TextureWrap);
147 /** Sets automatic mipmap generation. If enabled, mipmaps are generated
148 when a texture image is uploaded. */
149 void set_generate_mipmap(bool);
152 void auto_generate_mipmap();
155 /** Sets depth texture comparison. Has no effect on other formats. When
156 comparison is enabled, the third component of the texture coordinate is
157 compared against the texel value, and the result is returned as the texture
159 void set_compare_enabled(bool);
161 /** Sets the function to use for depth comparison. */
162 void set_compare_func(Predicate);
164 GLenum get_target() const { return target; }
165 unsigned get_id() const { return id; }
167 void bind() const { bind_to(0); }
168 void bind_to(unsigned) const;
170 static const Texture *current(unsigned = 0);
171 static void unbind() { unbind_from(0); }
172 static void unbind_from(unsigned);
174 virtual UInt64 get_data_size() const { return 0; }