]> git.tdb.fi Git - libs/gl.git/commitdiff
Use explicit mipmap generation if necessary
authorMikko Rasa <tdb@tdb.fi>
Wed, 10 Dec 2014 17:39:38 +0000 (19:39 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 10 Dec 2014 17:39:38 +0000 (19:39 +0200)
source/resources.cpp
source/texture.cpp
source/texture.h
source/texture1d.cpp
source/texture2d.cpp
source/texture3d.cpp
source/texturecube.cpp

index 2fd6950370df6580fe08cdf54139bef9b6d50316..afb84b27ae8689612ea068a9289cbb61a92910b6 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/fs/utils.h>
+#include <msp/gl/extensions/sgis_generate_mipmap.h>
 #include "animation.h"
 #include "armature.h"
 #include "font.h"
@@ -20,7 +21,7 @@ namespace Msp {
 namespace GL {
 
 Resources::Resources():
-       default_tex_filter(LINEAR_MIPMAP_LINEAR),
+       default_tex_filter(SGIS_generate_mipmap ? LINEAR_MIPMAP_LINEAR : LINEAR),
        srgb_conversion(false),
        resource_manager(0)
 {
index 81373c97b8793bb99f66c5669e6bc7f761c5d7d9..22bdebdfd2a02eca284a0183c29a2f942b7a1631 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/gl/extensions/arb_shadow.h>
+#include <msp/gl/extensions/ext_framebuffer_object.h>
 #include <msp/gl/extensions/ext_texture3d.h>
 #include <msp/gl/extensions/ext_texture_filter_anisotropic.h>
 #include <msp/gl/extensions/sgis_generate_mipmap.h>
@@ -168,7 +169,18 @@ 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)
index 79d79dbd68fbc8c8908b04f180501c6335b783ab..db6165fed82628206f29d69b39036d2160edefca 100644 (file)
@@ -144,6 +144,10 @@ public:
        when a texture image is uploaded. */
        void set_generate_mipmap(bool);
 
+protected:
+       void auto_generate_mipmap();
+
+public:
        /** Sets depth texture comparison.  Has no effect on other formats.  When
        comparison is enabled, the third component of the texture coordinate is
        compared against the texel value, and the result is returned as the texture
index a0876aced2d57f987d06f45660de8d8f9f456078..accd0e0c06c76a4bfe0b91f828cc840c5becff49 100644 (file)
@@ -50,6 +50,7 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void
        allocated |= 1<<level;
        if(gen_mipmap && level==0)
        {
+               auto_generate_mipmap();
                for(; w; w>>=1, ++level) ;
                allocated |= (1<<level)-1;
        }
index 2ea713eb3a539c9705e13f90b2775ff9b643fdfd..7cad81d92a5e44e2717bbaf88f1c35d166fa8dc3 100644 (file)
@@ -74,6 +74,7 @@ void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void
        allocated |= 1<<level;
        if(gen_mipmap && level==0)
        {
+               auto_generate_mipmap();
                for(; (w || h); w>>=1, h>>=1, ++level) ;
                allocated |= (1<<level)-1;
        }
index 61c745bb95bf4d8ae3df56c1c94c7aec43a686f7..7b9c3590ef6bc7eb8e936e20816c36549bbdec2c 100644 (file)
@@ -60,6 +60,7 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
        allocated |= 1<<level;
        if(gen_mipmap && level==0)
        {
+               auto_generate_mipmap();
                for(; (w || h || d); w>>=1, h>>=1, d>>=1, ++level) ;
                allocated |= (1<<level)-1;
        }
index 7f5250ee99e1381195977b1a40e12b77a8220839..37390a853612523e503889230f030f2a70d2b73d 100644 (file)
@@ -67,6 +67,8 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D
        allocated |= 1<<level;
        if(gen_mipmap && level==0)
        {
+               // TODO Only do this once all faces are created
+               auto_generate_mipmap();
                for(; s; s>>=1, ++level) ;
                allocated |= (1<<level)-1;
        }