diff options
author | Ixtli <cg@325i.org> | 2010-04-01 17:03:25 +0900 |
---|---|---|
committer | Enne Walker <ennewalker@users.sourceforge.net> | 2010-04-24 10:19:47 -0400 |
commit | aec2b3cc4236f6fc7e2701d3564e54c562537a1c (patch) | |
tree | 67361c3b3dcd6cc999aed7cea910c6415ac4e162 /crawl-ref/source/tiletex.cc | |
parent | 024c5583f5ff9cccba54004b47529ed9e9b03d60 (diff) | |
download | crawl-ref-aec2b3cc4236f6fc7e2701d3564e54c562537a1c.tar.gz crawl-ref-aec2b3cc4236f6fc7e2701d3564e54c562537a1c.zip |
Merged cgcontext into uiwrapper-sdl
Diffstat (limited to 'crawl-ref/source/tiletex.cc')
-rw-r--r-- | crawl-ref/source/tiletex.cc | 175 |
1 files changed, 3 insertions, 172 deletions
diff --git a/crawl-ref/source/tiletex.cc b/crawl-ref/source/tiletex.cc index 461cdb4429..86d29e1b84 100644 --- a/crawl-ref/source/tiletex.cc +++ b/crawl-ref/source/tiletex.cc @@ -6,7 +6,6 @@ #include "tiletex.h" #include "uiwrapper.h" -#include "cgcontext.h" #include "glwrapper.h" GenericTexture::GenericTexture() : @@ -36,177 +35,9 @@ bool GenericTexture::load_texture(const char *filename, tex_proc_func proc, bool force_power_of_two) { - char acBuffer[512]; - - std::string tex_path = datafile_path(filename); - - if (tex_path.c_str()[0] == 0) - { - fprintf(stderr, "Couldn't find texture '%s'.\n", filename); - return (false); - } - - GraphicsContext *img = GraphicsContext::create(); - if ( !img ) - { - fprintf(stderr, "Could not create context for texture '%s'.\n", - tex_path.c_str()); - return (false); - } - - if ( img->load_image(tex_path.c_str()) ) - { - fprintf(stderr, "Couldn't load texture '%s'.\n", tex_path.c_str()); - return (false); - } - - unsigned int bpp = img->bytes_per_pixel(); - glmanager->pixelstore_unpack_alignment(bpp); - - // Determine texture format - unsigned char *pixels = (unsigned char*)img->pixels(); - - int new_width; - int new_height; - if (force_power_of_two) - { - new_width = 1; - while (new_width < img->width()) - new_width *= 2; - - new_height = 1; - while (new_height < img->height()) - new_height *= 2; - } - else - { - new_width = img->width(); - new_height = img->height(); - } - - if (bpp == 4) - { - // Even if the size is the same, still go through - // SDL_get_rgba to put the image in the right format. - img->lock(); - pixels = new unsigned char[4 * new_width * new_height]; - memset(pixels, 0, 4 * new_width * new_height); - - int dest = 0; - for (int y = 0; y < img->height(); y++) - { - for (int x = 0; x < img->width(); x++) - { - unsigned char *p = ((unsigned char*)img->pixels() - + y * img->pitch() + x * bpp); - unsigned int pixel = *(unsigned int*)p; - img->get_rgba(pixel, &pixels[dest], &pixels[dest+1], - &pixels[dest+2], &pixels[dest+3]); - dest += 4; - } - dest += 4 * (new_width - img->width()); - } - - img->unlock(); - } - else if (bpp == 3) - { - if (new_width != img->width() || new_height != img->height()) - { - img->lock(); - pixels = new unsigned char[4 * new_width * new_height]; - memset(pixels, 0, 4 * new_width * new_height); - - int dest = 0; - for (int y = 0; y < img->height(); y++) - { - for (int x = 0; x < img->width(); x++) - { - unsigned char *p = ((unsigned char*)img->pixels() - + y * img->pitch() + x * bpp); - unsigned int pixel; - if (wrapper->byte_order() == UI_BIG_ENDIAN) - pixel = p[0] << 16 | p[1] << 8 | p[2]; - else - pixel = p[0] | p[1] << 8 | p[2]; - img->get_rgba(pixel, &pixels[dest], &pixels[dest+1], - &pixels[dest+2], &pixels[dest+3]); - dest += 4; - } - dest += 4 * (new_width - img->width()); - } - - img->unlock(); - } - } - else if (bpp == 1) - { - // need to depalettize - img->lock(); - - pixels = new unsigned char[4 * new_width * new_height]; - - ui_palette* pal = img->palette; - ASSERT(pal); - ASSERT(pal->colors); - - int src = 0; - int dest = 0; - for (int y = 0; y < img->height(); y++) - { - int x; - for (x = 0; x < img->width(); x++) - { - unsigned int index = ((unsigned char*)img->pixels())[src++]; - pixels[dest*4 ] = pal->colors[index].r; - pixels[dest*4 + 1] = pal->colors[index].g; - pixels[dest*4 + 2] = pal->colors[index].b; - pixels[dest*4 + 3] = (index != img->color_key() ? 255 : 0); - dest++; - } - while (x++ < new_width) - { - // Extend to the right with transparent pixels - pixels[dest*4 ] = 0; - pixels[dest*4 + 1] = 0; - pixels[dest*4 + 2] = 0; - pixels[dest*4 + 3] = 0; - dest++; - } - } - while (dest < new_width * new_height) - { - // Extend down with transparent pixels - pixels[dest*4 ] = 0; - pixels[dest*4 + 1] = 0; - pixels[dest*4 + 2] = 0; - pixels[dest*4 + 3] = 0; - dest++; - } - - img->unlock(); - - bpp = 4; - } - else - { - printf("Warning: unsupported format, bpp = %d for '%s'\n", - bpp, acBuffer); - return (false); - } - bool success = false; - if (!proc || proc(pixels, new_width, new_height)) - success |= load_texture(pixels, new_width, new_height, mip_opt); - - // If conversion has occurred, delete converted data. - if (pixels != img->pixels()) - delete[] pixels; - - m_orig_width = img->width(); - m_orig_height = img->height(); - - delete img; + success = wrapper->load_texture(this, filename, mip_opt, m_orig_width, + m_orig_height, proc, force_power_of_two); return (success); } @@ -222,7 +53,7 @@ bool GenericTexture::load_texture(unsigned char *pixels, unsigned int new_width, m_height = new_height; glmanager->generate_textures(1, &m_handle); - glmanager->bind_texture(m_handle); + bind(); glmanager->load_texture(pixels, m_width, m_height, mip_opt); return (true); |