X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Ftexture.cpp;h=5c82dbe535d91a3036c4eed0f0f3e4d93a2e2fdb;hb=4e9fe48180c7b4646ac2591e172de61f7a693b32;hp=3adc511e23ca2640d0ed7e5a4fc6644b50a65c40;hpb=a92362ad19b65f66b98e0dc4d034da5e4eb5cf36;p=libs%2Fgl.git diff --git a/source/core/texture.cpp b/source/core/texture.cpp index 3adc511e..5c82dbe5 100644 --- a/source/core/texture.cpp +++ b/source/core/texture.cpp @@ -3,7 +3,6 @@ #include #include #include -#include "bindable.h" #include "error.h" #include "resourcemanager.h" #include "resources.h" @@ -22,6 +21,8 @@ int Texture::swizzle_orders[] = GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA }; +Texture *Texture::scratch_binding = 0; + Texture::Texture(GLenum t, ResourceManager *m): id(0), target(t), @@ -46,6 +47,8 @@ Texture::Texture(GLenum t, ResourceManager *m): Texture::~Texture() { + if(this==scratch_binding) + unbind_scratch(); if(id) glDeleteTextures(1, &id); } @@ -130,40 +133,18 @@ void Texture::set_parameter_i(GLenum param, int value) const glTexParameteri(target, param, value); } -bool Texture::can_generate_mipmap() -{ - return EXT_framebuffer_object; -} - void Texture::generate_mipmap() { // glGenerateMipmap is defined here static Require _req(EXT_framebuffer_object); - if(!ARB_direct_state_access) - { - glActiveTexture(GL_TEXTURE0); - glBindTexture(target, id); - } - generate_mipmap_(); - if(!ARB_direct_state_access) - glBindTexture(target, 0); -} - -void Texture::generate_mipmap_() -{ if(ARB_direct_state_access) glGenerateTextureMipmap(id); else + { + bind_scratch(); glGenerateMipmap(target); -} - -void Texture::set_auto_generate_mipmap(bool gm) -{ - if(gm) - static Require _req(EXT_framebuffer_object); - - auto_gen_mipmap = gm; + } } void Texture::load_image(const string &fn, bool) @@ -195,6 +176,28 @@ void Texture::set_debug_name(const string &name) #endif } +void Texture::bind_scratch() +{ + if(!scratch_binding) + glActiveTexture(GL_TEXTURE0); + if(scratch_binding!=this) + { + if(scratch_binding && scratch_binding->target!=target) + glBindTexture(scratch_binding->target, 0); + glBindTexture(target, id); + scratch_binding = this; + } +} + +void Texture::unbind_scratch() +{ + if(scratch_binding) + { + glBindTexture(scratch_binding->target, 0); + scratch_binding = 0; + } +} + Texture::Loader::Loader(Texture &t): DataFile::CollectionObjectLoader(t, 0) @@ -219,6 +222,12 @@ void Texture::Loader::init() add("mipmap_levels", &Loader::mipmap_levels); } +void Texture::Loader::finish() +{ + if(obj.auto_gen_mipmap) + obj.generate_mipmap(); +} + void Texture::Loader::load_external_image(Graphics::Image &img, const string &fn) { RefPtr io = get_collection().open_raw(fn); @@ -253,7 +262,7 @@ void Texture::Loader::external_image_common(const string &fn) void Texture::Loader::generate_mipmap(bool gm) { - obj.set_auto_generate_mipmap(gm); + obj.auto_gen_mipmap = gm; } void Texture::Loader::image_data(const string &data)