X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture2d.cpp;h=c92099cedb35e79c362ab6cab25acd0d7359bd25;hb=8ac93980ef87834fd431c97104baa441561a7ce0;hp=8a93d031b6fd36a781ab5916e7019ba6036b0388;hpb=d1800d7ea80290f4913d0203241cef1409656522;p=libs%2Fgl.git diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 8a93d031..c92099ce 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -5,8 +5,8 @@ Copyright © 2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include "bindable.h" #include "except.h" -#include "ilwrap.h" #include "texture2d.h" using namespace std; @@ -15,65 +15,96 @@ namespace Msp { namespace GL { Texture2D::Texture2D(): + Texture(GL_TEXTURE_2D), width(0), - height(0) -{ - target=GL_TEXTURE_2D; - bind(); -} + height(0), + allocated(0) +{ } -void Texture2D::storage(PixelFormat fmt, sizei wd, sizei ht, int brd) +void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht) { if(width>0) throw InvalidState("Texture storage may only be specified once"); if(wd==0 || ht==0) throw InvalidParameterValue("Invalid texture dimensions"); - ifmt=fmt; - width=wd; - height=ht; - border=brd; + ifmt = fmt; + width = wd; + height = ht; } -void Texture2D::image(int level, PixelFormat fmt, GLenum type, const void *data) +void Texture2D::allocate(unsigned level) { - if(width==0) - throw InvalidState("Texture storage has not been specified"); - - maybe_bind(); + if(allocated&(1<>=1, h>>=1, ++level) ; + allocated |= (1<>= level; + h >>= level; + + if(!w && h) + w = 1; + else if(!h && w) + h = 1; } @@ -83,25 +114,31 @@ Texture2D::Loader::Loader(Texture2D &t): add("image_data", &Loader::image_data); add("raw_data", &Loader::raw_data); add("storage", &Loader::storage); + add("storage", &Loader::storage_b); } void Texture2D::Loader::image_data(const string &data) { - Image img; - img.load_lump(data.data(), data.size()); + Graphics::Image img; + img.load_memory(data.data(), data.size()); - static_cast(tex).image(img); + static_cast(obj).image(img); } void Texture2D::Loader::raw_data(const string &data) { - Texture2D &t2d=static_cast(tex);; - t2d.image(0, t2d.ifmt, GL_UNSIGNED_BYTE, data.data()); + Texture2D &t2d = static_cast(obj); + t2d.image(0, t2d.ifmt, UNSIGNED_BYTE, data.data()); +} + +void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h) +{ + static_cast(obj).storage(fmt, w, h); } -void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned b) +void Texture2D::Loader::storage_b(PixelFormat fmt, unsigned w, unsigned h, unsigned) { - static_cast(tex).storage(fmt, w, h, b); + storage(fmt, w, h); } } // namespace GL