if(is_mipmapped(default_tex_filter))
{
- tex->set_generate_mipmap(true);
+ tex->set_auto_generate_mipmap(true);
tex->set_mag_filter(LINEAR);
}
else
#include <msp/gl/extensions/sgis_generate_mipmap.h>
#include <msp/io/memory.h>
#include <msp/strings/format.h>
+#include "bindable.h"
#include "error.h"
#include "resourcemanager.h"
#include "resources.h"
wrap_s(REPEAT),
wrap_t(REPEAT),
wrap_r(REPEAT),
- gen_mipmap(false),
+ auto_gen_mipmap(0),
compare(false),
cmp_func(LEQUAL),
dirty_params(0)
if(mask&WRAP_R)
set_parameter_i(GL_TEXTURE_WRAP_R, wrap_r);
if(mask&GENERATE_MIPMAP)
- set_parameter_i(GL_GENERATE_MIPMAP, gen_mipmap);
+ set_parameter_i(GL_GENERATE_MIPMAP, auto_gen_mipmap!=0);
if(mask&COMPARE)
set_parameter_i(GL_TEXTURE_COMPARE_MODE, (compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE));
if(mask&COMPARE_FUNC)
return (EXT_framebuffer_object || SGIS_generate_mipmap);
}
-void Texture::set_generate_mipmap(bool gm)
+void Texture::generate_mipmap()
{
- if(gm && !EXT_framebuffer_object)
- static Require _req(SGIS_generate_mipmap);
- gen_mipmap = gm;
- if(!EXT_framebuffer_object)
- update_parameter(GENERATE_MIPMAP);
+ // glGenerateMipmap is defined here
+ static Require _req(EXT_framebuffer_object);
+
+ if(ARB_direct_state_access)
+ glGenerateTextureMipmap(id);
+ else
+ {
+ BindRestore _bind(this);
+ glGenerateMipmap(target);
+ }
}
-void Texture::auto_generate_mipmap()
+void Texture::set_auto_generate_mipmap(bool gm)
{
- // glGenerateMipmap is defined here
if(EXT_framebuffer_object)
+ auto_gen_mipmap = gm;
+ else
{
- if(ARB_direct_state_access)
- glGenerateTextureMipmap(id);
- else
- glGenerateMipmap(target);
+ if(gm)
+ static Require _req(SGIS_generate_mipmap);
+
+ auto_gen_mipmap = gm*2;
+ update_parameter(GENERATE_MIPMAP);
}
}
void Texture::Loader::generate_mipmap(bool gm)
{
- obj.set_generate_mipmap(gm);
+ obj.set_auto_generate_mipmap(gm);
}
void Texture::Loader::image_data(const string &data)
TextureWrap wrap_s;
TextureWrap wrap_t;
TextureWrap wrap_r;
- bool gen_mipmap;
+ Msp::UInt8 auto_gen_mipmap;
bool compare;
Predicate cmp_func;
mutable int dirty_params;
static bool can_generate_mipmap();
+ void generate_mipmap();
+
/** Sets automatic mipmap generation. If enabled, mipmaps are generated
when a texture image is uploaded. */
- void set_generate_mipmap(bool);
+ void set_auto_generate_mipmap(bool);
-protected:
- void auto_generate_mipmap();
+ /// Deprecated. Use set_auto_generate_mipmap instead.
+ void set_generate_mipmap(bool g) { set_auto_generate_mipmap(g); }
-public:
/** Sets depth texture comparison. Has no effect on other formats. When
comparison is enabled, the third component of the texture coordinate is
compared against the texel value, and the result is returned as the texture
glTexImage1D(target, level, ifmt, w, 0, get_upload_format(fmt), type, data);
allocated |= 1<<level;
- if(gen_mipmap && level==0)
+ if(auto_gen_mipmap==1 && level==0)
{
- auto_generate_mipmap();
+ generate_mipmap();
allocated |= (1<<get_n_levels())-1;
}
}
else
glTexSubImage1D(target, level, x, wd, fmt, type, data);
- if(gen_mipmap && level==0)
- auto_generate_mipmap();
+ if(auto_gen_mipmap==1 && level==0)
+ generate_mipmap();
}
void Texture1D::image(const Graphics::Image &img, bool srgb)
glTexImage2D(target, level, ifmt, w, h, 0, get_upload_format(fmt), type, data);
allocated |= 1<<level;
- if(gen_mipmap && level==0)
+ if(auto_gen_mipmap==1 && level==0)
{
- auto_generate_mipmap();
+ generate_mipmap();
allocated |= (1<<get_n_levels())-1;
}
}
else
glTexSubImage2D(target, level, x, y, wd, ht, fmt, type, data);
- if(gen_mipmap && level==0)
- auto_generate_mipmap();
+ if(auto_gen_mipmap==1 && level==0)
+ generate_mipmap();
}
void Texture2D::image(const Graphics::Image &img, bool srgb)
glTexImage3D(target, level, ifmt, width, height, depth, 0, get_upload_format(fmt), type, data);
allocated |= 1<<level;
- if(gen_mipmap && level==0)
+ if(auto_gen_mipmap==1 && level==0)
{
- auto_generate_mipmap();
+ generate_mipmap();
allocated |= (1<<get_n_levels())-1;
}
}
else
glTexSubImage3D(target, level, x, y, z, wd, ht, dp, fmt, type, data);
- if(gen_mipmap && level==0)
- auto_generate_mipmap();
+ if(auto_gen_mipmap==1 && level==0)
+ generate_mipmap();
}
void Texture3D::load_image(const string &fn, int dp)
// XXX Allocation should be tracked per-face, but we'll run out of bits
allocated |= 1<<level;
- if(gen_mipmap && level==0)
+ if(auto_gen_mipmap==1 && level==0)
{
// TODO Only do this once all faces are created
- auto_generate_mipmap();
+ generate_mipmap();
allocated |= (1<<get_n_levels())-1;
}
}
glTexSubImage2D(face, level, x, y, wd, ht, get_upload_format(fmt), type, data);
- if(gen_mipmap && level==0)
- auto_generate_mipmap();
+ if(auto_gen_mipmap==1 && level==0)
+ generate_mipmap();
}
void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool srgb)