X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Ftexture2d.cpp;h=b6b5954837c2e8b2ca4d35a801bd28f199e75757;hb=f14435e58bfa0fa697a06ba9a454bb30cd37d9d8;hp=c1f6e0e9e7bd75f664cc682209b551746d3f4e48;hpb=927a1aa0a3a27e463ec0efc08bd08e7c4e969909;p=libs%2Fgl.git diff --git a/source/texture2d.cpp b/source/texture2d.cpp index c1f6e0e9..b6b59548 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -1,10 +1,4 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - +#include "bindable.h" #include "except.h" #include "texture2d.h" @@ -14,43 +8,57 @@ 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, DataType 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; +} + Texture2D::Loader::Loader(Texture2D &t): Texture::Loader(t) @@ -82,6 +107,7 @@ 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) @@ -94,13 +120,18 @@ void Texture2D::Loader::image_data(const string &data) void Texture2D::Loader::raw_data(const string &data) { - Texture2D &t2d=static_cast(obj); + Texture2D &t2d = static_cast(obj); t2d.image(0, t2d.ifmt, UNSIGNED_BYTE, data.data()); } -void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned b) +void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h) +{ + static_cast(obj).storage(fmt, w, h); +} + +void Texture2D::Loader::storage_b(PixelFormat fmt, unsigned w, unsigned h, unsigned) { - static_cast(obj).storage(fmt, w, h, b); + storage(fmt, w, h); } } // namespace GL