X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftexture.cpp;h=f1689145c8af9c5754569213a7561b0505e63b2c;hp=820dd10fd90318c64278ae9b0aed66cf227d8743;hb=56beca9d8b4f7b4edac81411d31e24df88e84ac3;hpb=7af837734a28a14b3e24a421187d12ecd16572d0 diff --git a/source/texture.cpp b/source/texture.cpp index 820dd10f..f1689145 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "bindable.h" #include "error.h" #include "resourcemanager.h" #include "resources.h" @@ -63,11 +64,12 @@ Texture::Texture(GLenum t, ResourceManager *m): ifmt(RGB), min_filter(NEAREST_MIPMAP_LINEAR), mag_filter(LINEAR), + mipmap_levels(0), max_anisotropy(1.0f), wrap_s(REPEAT), wrap_t(REPEAT), wrap_r(REPEAT), - gen_mipmap(false), + auto_gen_mipmap(0), compare(false), cmp_func(LEQUAL), dirty_params(0) @@ -156,7 +158,7 @@ void Texture::update_parameter(int mask) const 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) @@ -178,6 +180,8 @@ void Texture::update_parameter(int mask) const glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle_orders+swizzle*4); } } + if(mask&MIPMAP_LEVELS) + set_parameter_i(GL_TEXTURE_MAX_LEVEL, (mipmap_levels ? mipmap_levels-1 : 1000)); } void Texture::set_parameter_i(GLenum param, int value) const @@ -214,6 +218,12 @@ void Texture::set_filter(TextureFilter f) set_mag_filter(f==NEAREST ? NEAREST : LINEAR); } +void Texture::set_mipmap_levels(unsigned l) +{ + mipmap_levels = l; + update_parameter(MIPMAP_LEVELS); +} + void Texture::set_max_anisotropy(float a) { if(a<1.0f) @@ -257,24 +267,31 @@ bool Texture::can_generate_mipmap() 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); } } @@ -403,6 +420,7 @@ void Texture::Loader::init() add("mag_filter", &Loader::mag_filter); add("max_anisotropy", &Loader::max_anisotropy); add("min_filter", &Loader::min_filter); + add("mipmap_levels", &Loader::mipmap_levels); add("wrap", &Loader::wrap); add("wrap_r", &Loader::wrap_r); add("wrap_s", &Loader::wrap_s); @@ -413,6 +431,8 @@ void Texture::Loader::external_image(const string &fn) { Graphics::Image img; RefPtr io = get_collection().open_raw(fn); + if(!io) + throw IO::file_not_found(fn); img.load_io(*io); obj.image(img, srgb); @@ -425,7 +445,7 @@ void Texture::Loader::filter(TextureFilter f) 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) @@ -452,6 +472,11 @@ void Texture::Loader::min_filter(TextureFilter f) obj.set_min_filter(f); } +void Texture::Loader::mipmap_levels(unsigned l) +{ + obj.set_mipmap_levels(l); +} + void Texture::Loader::wrap(TextureWrap w) { obj.set_wrap(w);