X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture2d.cpp;h=dfd93f57c42e811a9c15c199083c50bd49d5497b;hb=41b4cb3002f3551ce1bd6fdf15994ee7bc523788;hp=fbf86a43b77fe79dc2f81120a98b516aeea05b85;hpb=a80b074c70ec991f27114efd13686038cf42c493;p=libs%2Fgl.git diff --git a/source/texture2d.cpp b/source/texture2d.cpp index fbf86a43..dfd93f57 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -1,12 +1,5 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include "except.h" -#include "ilwrap.h" +#include "bindable.h" +#include "error.h" #include "texture2d.h" using namespace std; @@ -15,80 +8,127 @@ 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"); + 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; + 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"); + 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) { - Image img; - img.load_lump(data.data(), data.size()); + Graphics::Image img; + img.load_memory(data.data(), data.size()); + + obj.image(img); +} + +void Texture2D::Loader::raw_data(const string &data) +{ + obj.image(0, obj.ifmt, UNSIGNED_BYTE, data.data()); +} - static_cast(tex).image(img); +void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h) +{ + obj.storage(fmt, w, h); +} + +void Texture2D::Loader::storage_b(PixelFormat fmt, unsigned w, unsigned h, unsigned) +{ + storage(fmt, w, h); } } // namespace GL