3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #define GL_GLEXT_PROTOTYPES
12 #include "texture3d.h"
19 Texture3D::Texture3D():
28 void Texture3D::storage(PixelFormat f, sizei w, sizei h, sizei d, int b)
31 throw InvalidState("Textures may only be created once");
32 if(w==0 || h==0 || d==0)
33 throw InvalidParameterValue("Invalid texture dimensions");
41 image(0, ifmt, GL_UNSIGNED_BYTE, 0);
44 void Texture3D::image(int level, PixelFormat fmt, GLenum type, const void *data)
47 glTexImage3D(target, level, ifmt, width, height, depth, border, fmt, type, data);
50 void Texture3D::load_image(const string &fn, int dp)
55 unsigned w=img.get_width();
56 unsigned h=img.get_height();
62 throw IncompatibleData("Image height is not divisible by its width");
68 for(d=h; d*d>h; d>>=2);
71 throw IncompatibleData("Could not find a square root of texture height");
77 PixelFormat fmt=img.get_format();
79 storage(fmt, w, h, d, 0);
80 else if(w!=width || h!=height || d!=depth)
81 throw IncompatibleData("Image does not match texture storage");
83 image(0, fmt, GL_UNSIGNED_INT, img.get_data());