3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
10 #include "texture2d.h"
19 Texture2D::Texture2D():
27 void Texture2D::storage(PixelFormat fmt, sizei wd, sizei ht, int brd)
30 throw InvalidState("Texture storage may only be specified once");
32 throw InvalidParameterValue("Invalid texture dimensions");
40 void Texture2D::image(int level, PixelFormat fmt, GLenum type, const void *data)
43 throw InvalidState("Texture storage has not been specified");
47 glTexImage2D(target, level, ifmt, width, height, border, fmt, type, data);
50 void Texture2D::sub_image(int level, int x, int y, sizei wd, sizei ht, PixelFormat fmt, GLenum type, const void *data)
53 throw InvalidState("Texture storage has not been specified");
57 glTexSubImage2D(target, level, x, y, wd, ht, fmt, type, data);
60 void Texture2D::load_image(const string &fn)
65 unsigned w=img.get_width();
66 unsigned h=img.get_height();
67 PixelFormat fmt=img.get_format();
69 storage(fmt, w, h, 0);
70 else if(w!=width || h!=height)
71 throw IncompatibleData("Image does not match texture storage");
73 image(0, fmt, GL_UNSIGNED_BYTE, img.get_data());