X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Ftexture.cpp;h=b40046705b32bdfbecd459b56ce5e9b7c81ae4d9;hb=7b569bbfcfb65d8d88b47ac42ee1df6a7d27e784;hp=ea503ed1f9d4414f28f200c89be286fdc49f6190;hpb=dbc91b65728ab9c0e574bb1127cfe4d2da55de7f;p=libs%2Fgl.git diff --git a/source/core/texture.cpp b/source/core/texture.cpp index ea503ed1..b4004670 100644 --- a/source/core/texture.cpp +++ b/source/core/texture.cpp @@ -3,12 +3,10 @@ #include #include #include -#include "bindable.h" #include "error.h" #include "resourcemanager.h" #include "resources.h" #include "texture.h" -#include "texunit.h" using namespace std; @@ -23,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), @@ -36,13 +36,19 @@ Texture::Texture(GLenum t, ResourceManager *m): set_manager(m); else generate_id(); + + static bool alignment_init = false; + if(!alignment_init) + { + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + alignment_init = true; + } } Texture::~Texture() { - while(TexUnit *unit = TexUnit::find_unit(this)) - unbind_from(unit->get_index()); - + if(this==scratch_binding) + unbind_scratch(); if(id) glDeleteTextures(1, &id); } @@ -141,7 +147,7 @@ void Texture::generate_mipmap() glGenerateTextureMipmap(id); else { - BindRestore _bind(this); + bind_scratch(); glGenerateMipmap(target); } } @@ -172,56 +178,6 @@ void Texture::image(const Graphics::Image &img, bool) image(img, 0U); } -void Texture::bind_to(unsigned i) const -{ - if(!id) - { - if(manager) - manager->resource_used(*this); - if(!id) - { - unbind_from(i); - return; - } - } - - TexUnit &unit = TexUnit::get_unit(i); - if(unit.set_texture(this)) - { - if(manager) - manager->resource_used(*this); - - if(ARB_direct_state_access) - glBindTextureUnit(i, id); - else - { - unit.bind(); - glBindTexture(target, id); - } - } -} - -const Texture *Texture::current(unsigned i) -{ - return TexUnit::get_unit(i).get_texture(); -} - -void Texture::unbind_from(unsigned i) -{ - TexUnit &unit = TexUnit::get_unit(i); - const Texture *cur = unit.get_texture(); - if(unit.set_texture(0)) - { - if(ARB_direct_state_access) - glBindTextureUnit(i, 0); - else - { - unit.bind(); - glBindTexture(cur->target, 0); - } - } -} - void Texture::set_debug_name(const string &name) { #ifdef DEBUG @@ -233,6 +189,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)