]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture.h
Use explicit mipmap generation if necessary
[libs/gl.git] / source / texture.h
index af0844c55e26938f00b2201e2f10abd576ece537..db6165fed82628206f29d69b39036d2160edefca 100644 (file)
@@ -4,6 +4,7 @@
 #include <msp/datafile/objectloader.h>
 #include "gl.h"
 #include "predicate.h"
+#include "resource.h"
 
 namespace Msp {
 namespace GL {
@@ -63,14 +64,21 @@ texture to be usable.
 If texture coordinates fall outside of the principal range of the texture,
 wrapping is applied.  The default for all directions is REPEAT.
 */
-class Texture
+class Texture: public Resource
 {
 protected:
-       class Loader: public DataFile::ObjectLoader<Texture>
+       class Loader: public DataFile::CollectionObjectLoader<Texture>
        {
+       protected:
+               bool srgb;
+
        public:
                Loader(Texture &);
+               Loader(Texture &, Collection &);
        private:
+               void init();
+
+               void filter(TextureFilter);
                void generate_mipmap(bool);
                void mag_filter(TextureFilter);
                void max_anisotropy(float);
@@ -107,7 +115,7 @@ protected:
        Predicate cmp_func;
        mutable int dirty_params;
 
-       Texture(GLenum);
+       Texture(GLenum, ResourceManager * = 0);
        Texture(const Texture &);
        Texture &operator=(const Texture &);
 public:
@@ -118,6 +126,11 @@ protected:
 public:
        void set_min_filter(TextureFilter);
        void set_mag_filter(TextureFilter);
+
+       /** Sets filter for both minification and magnification.  Since mipmapping
+       is not applicable to magnification, LINEAR is used instead. */
+       void set_filter(TextureFilter);
+
        void set_max_anisotropy(float);
 
        /** Sets the wrapping mode for all coordinates. */
@@ -131,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
@@ -143,12 +160,14 @@ public:
        GLenum get_target() const { return target; }
        unsigned get_id() const { return id; }
 
-       void bind() const;
+       void bind() const { bind_to(0); }
        void bind_to(unsigned) const;
 
-       static const Texture *current();
-       static void unbind();
+       static const Texture *current(unsigned = 0);
+       static void unbind() { unbind_from(0); }
        static void unbind_from(unsigned);
+
+       virtual UInt64 get_data_size() const { return 0; }
 };
 
 } // namespace GL