3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
9 #include <msp/gbase/image.h>
11 #include "extension.h"
12 #include "texture3d.h"
13 #include "version_1_2.h"
20 Texture3D::Texture3D():
25 static RequireVersion _ver(1, 3);
31 void Texture3D::storage(PixelFormat f, unsigned w, unsigned h, unsigned d, int b)
34 throw InvalidState("Textures may only be created once");
35 if(w==0 || h==0 || d==0)
36 throw InvalidParameterValue("Invalid texture dimensions");
44 image(0, ifmt, UNSIGNED_BYTE, 0);
47 void Texture3D::image(int level, PixelFormat fmt, DataType type, const void *data)
50 glTexImage3D(target, level, ifmt, width, height, depth, border, fmt, type, data);
53 void Texture3D::load_image(const string &fn, int dp)
58 unsigned w=img.get_width();
59 unsigned h=img.get_height();
65 throw IncompatibleData("Image height is not divisible by its width");
71 for(d=h; d*d>h; d>>=2) ;
74 throw IncompatibleData("Could not find a square root of texture height");
80 PixelFormat fmt=pixelformat_from_graphics(img.get_format());
82 storage(fmt, w, h, d, 0);
83 else if(w!=width || h!=height || d!=depth)
84 throw IncompatibleData("Image does not match texture storage");
86 image(0, fmt, UNSIGNED_INT, img.get_data());