#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);
}
}
{
Graphics::Image img;
RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
+ if(!io)
+ throw IO::file_not_found(fn);
img.load_io(*io);
obj.image(img, srgb);
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)