}
}
+int next_pow2(int x)
+{
+ x--;
+ x = (x >> 1) | x;
+ x = (x >> 2) | x;
+ x = (x >> 4) | x;
+ x = (x >> 8) | x;
+ x = (x >> 16) | x;
+ return x + 1;
+}
+
Image *Texture::default_img;
return sz[dim];
}
+int Texture::get_width() const
+{
+ return sz[0];
+}
+
+int Texture::get_height() const
+{
+ return sz[1];
+}
+
unsigned int Texture::get_id() const
{
return id;
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- switch(type) {
+ switch(textype) {
case TEX_2D:
glTexImage2D(GL_TEXTURE_2D, 0, glifmt_from_ifmt(ifmt), xsz, ysz, 0, fmt, type, 0);
break;
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
#ifdef __GLEW_H__
if(GLEW_SGIS_generate_mipmap) {
glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
bool Texture::set_image_cube(const Image &img, int idx)
{
+ unsigned int err;
if(idx < 0 || idx >= 6) {
return false;
}
target = GL_TEXTURE_CUBE_MAP;
glBindTexture(target, id);
- assert(glGetError() == GL_NO_ERROR);
+ if((err = glGetError()) == GL_INVALID_OPERATION) {
+ return false; // probably not a cubemap
+ }
+ assert(err == GL_NO_ERROR);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
int xsz = img.get_width();
int ysz = img.get_height();
- if(xsz / 4 == ysz / 3) {
+ if((xsz << 8) / 4 == (ysz << 8) / 3) {
// horizontal cross, assume the vertical bit is center-left
return set_cube_multi(img, hcross[0], hcross[1], xsz / 4);
}
- if(xsz / 3 == ysz / 4) {
+ if((xsz << 8) / 3 == (ysz << 8) / 4) {
// vertical cross, assume the horizontal bit is center-top (180-rotated image 5)
return set_cube_multi(img, vcross[0], vcross[1], ysz / 4, (1 << 5));
}
- if(xsz / 3 == ysz / 2) {
+ if((xsz << 8) / 3 == (ysz << 8) / 2) {
// horizontal sixpack
return set_cube_multi(img, hsix[0], hsix[1], ysz / 2);
}
Texture *res = create();
data[fname] = res;
res->create_default(type);
- resman_lookup(rman, fname, res);
+ resman_add(rman, fname, res);
return res;
}