X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture2d.cpp;h=be4e1a112d08e8c02f189fbcd951dce4dfcdcf2c;hb=ab83db6f1e31d44ced585119a57fd10896e469cb;hp=197e04df63830269f92a04ed4279636319ef4344;hpb=b617c5d7b5283ad260a77f01e42e6170cabbc03d;p=libs%2Fgl.git diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 197e04df..be4e1a11 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -1,11 +1,5 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include "except.h" +#include "bindable.h" +#include "error.h" #include "texture2d.h" using namespace std; @@ -14,43 +8,60 @@ 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, 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"); 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) @@ -82,6 +104,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) @@ -98,9 +121,14 @@ void Texture2D::Loader::raw_data(const string &data) 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