4 #include "texturecube.h"
10 // An array to facilitate looping through the cube faces
11 Msp::GL::TextureCubeFace faces[6] =
27 TextureCube::TextureCube():
28 Texture(GL_TEXTURE_CUBE_MAP),
32 static RequireVersion _ver(1, 3);
35 void TextureCube::storage(PixelFormat fmt, unsigned sz)
38 throw invalid_operation("TextureCube::storage");
40 throw invalid_argument("TextureCube::storage");
46 void TextureCube::allocate(unsigned level)
48 if(allocated&(1<<level))
51 for(unsigned i=0; i<6; ++i)
52 image(faces[i], level, get_base_pixelformat(ifmt), UNSIGNED_BYTE, 0);
55 void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, DataType type, const void *data)
58 throw invalid_operation("TextureCube::image");
60 unsigned s = get_level_size(level);
62 throw invalid_argument("TextureCube::image");
64 Bind _bind(this, true);
65 glTexImage2D(face, level, ifmt, s, s, 0, fmt, type, data);
67 // XXX Allocation should be tracked per-face, but we'll run out of bits
68 allocated |= 1<<level;
69 if(gen_mipmap && level==0)
71 for(; s; s>>=1, ++level) ;
72 allocated |= (1<<level)-1;
76 unsigned TextureCube::get_level_size(unsigned level)