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>
12 #include "extension.h"
13 #include "texture3d.h"
14 #include "version_1_2.h"
21 Texture3D::Texture3D():
22 Texture(GL_TEXTURE_3D),
27 static RequireVersion _ver(1, 2);
30 void Texture3D::storage(PixelFormat f, unsigned w, unsigned h, unsigned d, int b)
33 throw InvalidState("Textures storage may only be specified once");
34 if(w==0 || h==0 || d==0)
35 throw InvalidParameterValue("Invalid texture dimensions");
43 image(0, ifmt, UNSIGNED_BYTE, 0);
46 void Texture3D::image(int level, PixelFormat fmt, DataType type, const void *data)
49 throw InvalidState("Texture storage has not been specified");
51 Bind _bind(this, true);
52 glTexImage3D(target, level, ifmt, width, height, depth, border, fmt, type, data);
55 void Texture3D::load_image(const string &fn, int dp)
60 unsigned w = img.get_width();
61 unsigned h = img.get_height();
67 throw IncompatibleData("Image height is not divisible by its width");
73 for(d=h; d*d>h; d>>=2) ;
76 throw IncompatibleData("Could not find a square root of texture height");
82 PixelFormat fmt = pixelformat_from_graphics(img.get_format());
84 storage(fmt, w, h, d, 0);
85 else if(w!=width || h!=height || d!=depth)
86 throw IncompatibleData("Image does not match texture storage");
88 image(0, fmt, UNSIGNED_INT, img.get_data());