X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftexture2d.cpp;h=94224147c70434b53bcb8ef9ea78328e9f81284b;hp=fbf86a43b77fe79dc2f81120a98b516aeea05b85;hb=HEAD;hpb=a80b074c70ec991f27114efd13686038cf42c493 diff --git a/source/texture2d.cpp b/source/texture2d.cpp deleted file mode 100644 index fbf86a43..00000000 --- a/source/texture2d.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include "except.h" -#include "ilwrap.h" -#include "texture2d.h" - -using namespace std; - -namespace Msp { -namespace GL { - -Texture2D::Texture2D(): - width(0), - height(0) -{ - target=GL_TEXTURE_2D; - bind(); -} - -void Texture2D::storage(PixelFormat fmt, sizei wd, sizei ht, int brd) -{ - 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; -} - -void Texture2D::image(int level, PixelFormat fmt, GLenum type, const void *data) -{ - if(width==0) - throw InvalidState("Texture storage has not been specified"); - - maybe_bind(); - - glTexImage2D(target, level, ifmt, width, height, border, fmt, type, data); -} - -void Texture2D::sub_image(int level, int x, int y, sizei wd, sizei ht, PixelFormat fmt, GLenum type, const void *data) -{ - if(width==0) - throw InvalidState("Texture storage has not been specified"); - - maybe_bind(); - - glTexSubImage2D(target, level, x, y, wd, ht, fmt, type, data); -} - -void Texture2D::load_image(const string &fn) -{ - Image img; - img.load_file(fn); - - image(img); -} - -void Texture2D::image(const Image &img) -{ - unsigned w=img.get_width(); - unsigned h=img.get_height(); - PixelFormat fmt=img.get_format(); - if(width==0) - storage(fmt, w, h, 0); - else if(w!=width || h!=height) - throw IncompatibleData("Image does not match texture storage"); - - image(0, fmt, GL_UNSIGNED_BYTE, img.get_data()); -} - - -Texture2D::Loader::Loader(Texture2D &t): - Texture::Loader(t) -{ - add("image_data", &Loader::image_data); -} - -void Texture2D::Loader::image_data(const string &data) -{ - Image img; - img.load_lump(data.data(), data.size()); - - static_cast(tex).image(img); -} - -} // namespace GL -} // namespace Msp