]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture.cpp
Refactor Framebuffer::update_attachment for less indentation
[libs/gl.git] / source / texture.cpp
index bda29f05cdd5a2c63f93f8cc334503c1c8e1ef97..4efa8ac998ad4ab80a3a6fa57a531b9d15422c18 100644 (file)
@@ -78,7 +78,7 @@ Texture::~Texture()
 
 DataType Texture::get_alloc_type(PixelFormat fmt)
 {
-       return (fmt==DEPTH_COMPONENT ? UNSIGNED_SHORT : UNSIGNED_BYTE);
+       return (get_base_pixelformat(fmt)==DEPTH_COMPONENT ? UNSIGNED_SHORT : UNSIGNED_BYTE);
 }
 
 void Texture::update_parameter(int mask) const
@@ -100,7 +100,7 @@ void Texture::update_parameter(int mask) const
        if(mask&MAG_FILTER)
                glTexParameteri(target, GL_TEXTURE_MAG_FILTER, mag_filter);
        if(mask&MAX_ANISOTROPY)
-               glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
+               glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
        if(mask&WRAP_S)
                glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap_s);
        if(mask&WRAP_T)
@@ -172,21 +172,18 @@ void Texture::set_wrap_r(TextureWrap w)
 
 void Texture::set_generate_mipmap(bool gm)
 {
-       if(gm)
+       if(gm && !EXT_framebuffer_object)
                static Require _req(SGIS_generate_mipmap);
        gen_mipmap = gm;
-       if(get_gl_api()!=OPENGL_ES2)
+       if(!EXT_framebuffer_object)
                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 is defined here
+       if(EXT_framebuffer_object)
                glGenerateMipmap(target);
-       }
 }
 
 void Texture::set_compare_enabled(bool c)
@@ -288,11 +285,12 @@ void Texture::Loader::init()
        else
                srgb = false;
 
+       add("external_image", &Loader::external_image);
        add("filter", &Loader::filter);
-       add("max_anisotropy", &Loader::max_anisotropy);
        add("generate_mipmap", &Loader::generate_mipmap);
        add("image_data", &Loader::image_data);
        add("mag_filter", &Loader::mag_filter);
+       add("max_anisotropy", &Loader::max_anisotropy);
        add("min_filter", &Loader::min_filter);
        add("wrap",       &Loader::wrap);
        add("wrap_r",     &Loader::wrap_r);
@@ -300,6 +298,15 @@ void Texture::Loader::init()
        add("wrap_t",     &Loader::wrap_t);
 }
 
+void Texture::Loader::external_image(const string &fn)
+{
+       Graphics::Image img;
+       RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
+       img.load_io(*io);
+
+       obj.image(img, srgb);
+}
+
 void Texture::Loader::filter(TextureFilter f)
 {
        obj.set_filter(f);
@@ -354,5 +361,12 @@ void Texture::Loader::wrap_t(TextureWrap w)
        obj.set_wrap_t(w);
 }
 
+
+bool is_mipmapped(TextureFilter filter)
+{
+       return (filter==NEAREST_MIPMAP_NEAREST || filter==NEAREST_MIPMAP_LINEAR ||
+               filter==LINEAR_MIPMAP_NEAREST || filter==LINEAR_MIPMAP_LINEAR);
+}
+
 } // namespace GL
 } // namespace Msp