X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture2d.cpp;h=0e9b40c6320d0a5514a9bde091abffe5cb131d69;hb=ae9abd6be3e556d0a202cc5ab05668da715382c9;hp=8935933f995117322069ad1652b6b1d9ffc87d0c;hpb=7e9e15a12fb398798f2719545cc8553354c1e389;p=libs%2Fgl.git diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 8935933f..0e9b40c6 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -1,12 +1,6 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - +#include #include "bindable.h" -#include "except.h" +#include "error.h" #include "texture2d.h" using namespace std; @@ -17,35 +11,57 @@ namespace GL { Texture2D::Texture2D(): Texture(GL_TEXTURE_2D), width(0), - height(0) + height(0), + allocated(0) { } -void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, int brd) +void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht) { if(width>0) - throw InvalidState("Texture storage may only be specified once"); + throw invalid_operation("Texture2D::storage"); if(wd==0 || ht==0) - throw InvalidParameterValue("Invalid texture dimensions"); + throw invalid_argument("Texture2D::storage"); + require_pixelformat(fmt); ifmt = fmt; width = wd; height = ht; - border = brd; } -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"); + 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) + DataFile::DerivedObjectLoader(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) { Graphics::Image img; - img.load_memory(data.data(), data.size()); + IO::Memory mem(data.data(), data.size()); + img.load_io(mem); - static_cast(obj).image(img); + obj.image(img); } void Texture2D::Loader::raw_data(const string &data) { - Texture2D &t2d = static_cast(obj); - t2d.image(0, t2d.ifmt, UNSIGNED_BYTE, data.data()); + obj.image(0, obj.ifmt, UNSIGNED_BYTE, data.data()); +} + +void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h) +{ + 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(obj).storage(fmt, w, h, b); + storage(fmt, w, h); } } // namespace GL