X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ftexture.cc;h=f4f7cfe2242e92a3925ee32afe8e6c994ef27e65;hb=ad052fc67fe4e76d2f4a01b2381a738da1708cdb;hp=dae0c7c46653491535bdca725aa4f255c59c2609;hpb=26c1717925471539b9745cce6275b218a47147cd;p=laserbrain_demo diff --git a/src/texture.cc b/src/texture.cc index dae0c7c..f4f7cfe 100644 --- a/src/texture.cc +++ b/src/texture.cc @@ -126,6 +126,16 @@ int Texture::get_size(int dim) const 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; @@ -245,6 +255,8 @@ void Texture::set_image_2d(const Image &img) 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); @@ -263,6 +275,7 @@ void Texture::set_image_2d(const Image &img) bool Texture::set_image_cube(const Image &img, int idx) { + unsigned int err; if(idx < 0 || idx >= 6) { return false; } @@ -276,7 +289,10 @@ bool Texture::set_image_cube(const Image &img, int idx) 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); @@ -301,15 +317,15 @@ bool Texture::set_image_cube(const Image &img) 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); }