X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture.cpp;h=8d43143c9d734c218211d070890bf4cd080b42ed;hb=b781d8d1d713e28ec21a66a9d78eb3fc01f327e5;hp=187c2533acbea6fc9e30c33370ffb99ca2a15a18;hpb=57de40e1e802e44ae5b4caa67b0bb8763828b5c3;p=libs%2Fgl.git diff --git a/source/texture.cpp b/source/texture.cpp index 187c2533..8d43143c 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -74,6 +75,11 @@ Texture::~Texture() glDeleteTextures(1, &id); } +DataType Texture::get_alloc_type(PixelFormat fmt) +{ + return (fmt==DEPTH_COMPONENT ? UNSIGNED_SHORT : UNSIGNED_BYTE); +} + void Texture::update_parameter(int mask) const { if(TexUnit::current().get_texture()!=this) @@ -168,12 +174,24 @@ void Texture::set_generate_mipmap(bool gm) if(gm) static Require _req(SGIS_generate_mipmap); gen_mipmap = gm; - update_parameter(GENERATE_MIPMAP); + if(get_gl_api()!=OPENGL_ES2) + update_parameter(GENERATE_MIPMAP); +} + +void Texture::auto_generate_mipmap() +{ + if(get_gl_api()==OPENGL_ES2) + { + // glGenerateMipmap is defined here + static Require _req(EXT_framebuffer_object); + glGenerateMipmap(target); + } } void Texture::set_compare_enabled(bool c) { - static Require _req(ARB_shadow); + if(c) + static Require _req(ARB_shadow); compare = c; update_parameter(COMPARE); } @@ -199,17 +217,20 @@ void Texture::bind_to(unsigned i) const } TexUnit &unit = TexUnit::get_unit(i); - const Texture *cur = unit.get_texture(); + const Texture *old = unit.get_texture(); if(unit.set_texture(this)) { if(manager) manager->resource_used(*this); unit.bind(); - if(cur && cur->target!=target) - glDisable(cur->target); - if(!cur || cur->target!=target) - glEnable(target); + if(unit.supports_legacy()) + { + if(old && old->target!=target) + glDisable(old->target); + if(!old || old->target!=target) + glEnable(target); + } glBindTexture(target, id); if(dirty_params) @@ -233,7 +254,8 @@ void Texture::unbind_from(unsigned i) { unit.bind(); glBindTexture(cur->target, 0); - glDisable(cur->target); + if(unit.supports_legacy()) + glDisable(cur->target); } }