RefPtr<GL::Texture2D> tex = new GL::Texture2D(resource_manager);
- if(default_tex_filter==NEAREST_MIPMAP_NEAREST || default_tex_filter==NEAREST_MIPMAP_LINEAR ||
- default_tex_filter==LINEAR_MIPMAP_NEAREST || default_tex_filter==LINEAR_MIPMAP_LINEAR)
+ if(is_mipmapped(default_tex_filter))
{
tex->set_generate_mipmap(true);
tex->set_mag_filter(LINEAR);
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
virtual UInt64 get_data_size() const { return 0; }
};
+
+bool is_mipmapped(TextureFilter);
+
} // namespace GL
} // namespace Msp
if(gen_mipmap && level==0)
{
auto_generate_mipmap();
- for(; w; w>>=1, ++level) ;
- allocated |= (1<<level)-1;
+ allocated |= (1<<get_n_levels())-1;
}
}
image(0, fmt, UNSIGNED_BYTE, img.get_data());
}
-unsigned Texture1D::get_level_size(unsigned level)
+unsigned Texture1D::get_n_levels() const
+{
+ unsigned n = 0;
+ for(unsigned s=width; s; s>>=1, ++n) ;
+ return n;
+}
+
+unsigned Texture1D::get_level_size(unsigned level) const
{
return width>>level;
}
unsigned get_width() const { return width; }
private:
- unsigned get_level_size(unsigned);
+ unsigned get_n_levels() const;
+ unsigned get_level_size(unsigned) const;
public:
virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
if(gen_mipmap && level==0)
{
auto_generate_mipmap();
- for(; (w || h); w>>=1, h>>=1, ++level) ;
- allocated |= (1<<level)-1;
+ allocated |= (1<<get_n_levels())-1;
}
}
image(0, fmt, UNSIGNED_BYTE, from_buffer ? 0 : img.get_data());
}
-void Texture2D::get_level_size(unsigned level, unsigned &w, unsigned &h)
+unsigned Texture2D::get_n_levels() const
+{
+ unsigned n = 0;
+ for(unsigned s=max(width, height); s; s>>=1, ++n) ;
+ return n;
+}
+
+void Texture2D::get_level_size(unsigned level, unsigned &w, unsigned &h) const
{
w >>= level;
h >>= level;
unsigned get_height() const { return height; }
private:
- void get_level_size(unsigned, unsigned &, unsigned &);
+ unsigned get_n_levels() const;
+ void get_level_size(unsigned, unsigned &, unsigned &) const;
public:
virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);
if(gen_mipmap && level==0)
{
auto_generate_mipmap();
- for(; (w || h || d); w>>=1, h>>=1, d>>=1, ++level) ;
- allocated |= (1<<level)-1;
+ allocated |= (1<<get_n_levels())-1;
}
}
image(0, fmt, UNSIGNED_BYTE, img.get_data());
}
-void Texture3D::get_level_size(unsigned level, unsigned &w, unsigned &h, unsigned &d)
+unsigned Texture3D::get_n_levels() const
+{
+ unsigned s = max(width, height);
+ if(target!=GL_TEXTURE_2D_ARRAY)
+ s = max(s, depth);
+ unsigned n = 0;
+ for(; s; s>>=1, ++n) ;
+ return n;
+}
+
+void Texture3D::get_level_size(unsigned level, unsigned &w, unsigned &h, unsigned &d) const
{
w >>= level;
h >>= level;
unsigned get_height() const { return height; }
unsigned get_depth() const { return depth; }
protected:
- void get_level_size(unsigned, unsigned &, unsigned &, unsigned &);
+ unsigned get_n_levels() const;
+ void get_level_size(unsigned, unsigned &, unsigned &, unsigned &) const;
public:
virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
{
// TODO Only do this once all faces are created
auto_generate_mipmap();
- for(; s; s>>=1, ++level) ;
- allocated |= (1<<level)-1;
+ allocated |= (1<<get_n_levels())-1;
}
}
image(enumerate_faces(i), 0, fmt, UNSIGNED_BYTE, cdata+i*face_size);
}
-unsigned TextureCube::get_level_size(unsigned level)
+unsigned TextureCube::get_n_levels() const
+{
+ unsigned n = 0;
+ for(unsigned s=size; s; s>>=1, ++n) ;
+ return n;
+}
+
+unsigned TextureCube::get_level_size(unsigned level) const
{
return size>>level;
}
unsigned get_size() const { return size; }
private:
- unsigned get_level_size(unsigned);
+ unsigned get_n_levels() const;
+ unsigned get_level_size(unsigned) const;
public:
/** Translates indices into face constants. Valid indices are between 0