X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ftexture.cc;h=cbbd11dc455c7a0ca87ac8d579e128382293a8a8;hb=9802d969be55668e4dcc10fe427b0dcdeb6302be;hp=a787abd380d3f10c829c654e611af6f4d6f91311;hpb=ccc1a688b59e25bb934a0d3e2bbf477960068d4f;p=laserbrain_demo diff --git a/src/texture.cc b/src/texture.cc index a787abd..cbbd11d 100644 --- a/src/texture.cc +++ b/src/texture.cc @@ -1,8 +1,10 @@ #include +#include #include "texture.h" #include "image.h" #include "opengl.h" #include "imago2.h" +#include "logger.h" static int glifmt_from_ifmt(unsigned int ifmt); static int glfmt_from_ifmt(unsigned int ifmt); @@ -35,6 +37,7 @@ void bind_texture(Texture *tex, int tunit) } else { glActiveTexture(GL_TEXTURE0 + tunit); glBindTexture(cur_target[tunit], 0); + assert(glGetError() == GL_NO_ERROR); glActiveTexture(GL_TEXTURE0); } } @@ -69,6 +72,7 @@ void Texture::set_wrapping(unsigned int wrap) } glBindTexture(target, id); + assert(glGetError() == GL_NO_ERROR); glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap); glTexParameteri(target, GL_TEXTURE_WRAP_T, wrap); glTexParameteri(target, GL_TEXTURE_WRAP_R, wrap); @@ -103,6 +107,7 @@ void Texture::set_filtering(unsigned int filt) void Texture::set_filtering(unsigned int min_filt, unsigned int mag_filt) { glBindTexture(target, id); + assert(glGetError() == GL_NO_ERROR); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, min_filt); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, mag_filt); } @@ -134,6 +139,7 @@ void Texture::bind(int tex_unit) const { glActiveTexture(GL_TEXTURE0 + tex_unit); glBindTexture(target, id); + assert(glGetError() == GL_NO_ERROR); glActiveTexture(GL_TEXTURE0); cur_target[tex_unit] = target; @@ -143,7 +149,7 @@ void Texture::bind(int tex_unit) const void Texture::create(int xsz, int ysz, TextureType textype, unsigned int ifmt) { if(textype == TEX_CUBE && xsz != ysz) { - fprintf(stderr, "trying to create cubemap with different width and height (%dx%d)\n", xsz, ysz); + error_log("trying to create cubemap with different width and height (%dx%d)\n", xsz, ysz); return; } @@ -153,6 +159,7 @@ void Texture::create(int xsz, int ysz, TextureType textype, unsigned int ifmt) target = type_to_target(textype); glBindTexture(target, id); + assert(glGetError() == GL_NO_ERROR); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -191,8 +198,10 @@ void Texture::create_default(TextureType type) pixels[1] = 64; pixels[2] = chess ? 32 : 255; pixels[3] = 255; + pixels += 4; } } + default_img->save("/tmp/foo.png"); } switch(type) { @@ -230,6 +239,7 @@ void Texture::set_image_2d(const Image &img) target = GL_TEXTURE_2D; glBindTexture(target, id); + assert(glGetError() == GL_NO_ERROR); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -266,6 +276,7 @@ bool Texture::set_image_cube(const Image &img, int idx) target = GL_TEXTURE_CUBE_MAP; glBindTexture(target, id); + assert(glGetError() == 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); @@ -311,12 +322,12 @@ bool Texture::load(const char *fname) { Image img; if(!img.load(fname)) { - fprintf(stderr, "failed to load 2D texture: %s\n", fname); + error_log("failed to load 2D texture: %s\n", fname); return false; } set_image(img); - printf("loaded 2D texture: %s\n", fname); + info_log("loaded 2D texture: %s\n", fname); return true; } @@ -381,14 +392,17 @@ static int glfmt_from_ifmt(unsigned int ifmt) switch(ifmt) { case GL_LUMINANCE16F_ARB: case GL_LUMINANCE32F_ARB: + case GL_SLUMINANCE: return GL_LUMINANCE; case GL_RGB16F: case GL_RGB32F: + case GL_SRGB: return GL_RGB; case GL_RGBA16F: case GL_RGBA32F: + case GL_SRGB_ALPHA: return GL_RGBA; default: @@ -421,15 +435,15 @@ static int glifmt_from_imgfmt(Image::Format fmt) { switch(fmt) { case Image::FMT_GREY: - return GL_LUMINANCE; + return GL_SLUMINANCE; case Image::FMT_GREY_FLOAT: return GL_LUMINANCE16F_ARB; case Image::FMT_RGB: - return GL_RGB; + return GL_SRGB; case Image::FMT_RGB_FLOAT: return GL_RGB16F; case Image::FMT_RGBA: - return GL_RGBA; + return GL_SRGB_ALPHA; case Image::FMT_RGBA_FLOAT: return GL_RGBA16F; default: @@ -456,12 +470,13 @@ TextureSet::TextureSet() Texture *TextureSet::get_texture(const char *name, TextureType type) const { - typename std::map::const_iterator iter = data.find(name); + std::map::const_iterator iter = data.find(name); if(iter != data.end()) { return iter->second; } Texture *res = create(); + data[name] = res; res->create_default(type); resman_lookup(rman, name, res); return res;