--- deliantra/Deliantra-Client/texcache.c 2007/08/12 08:44:22 1.4 +++ deliantra/Deliantra-Client/texcache.c 2007/12/25 18:58:32 1.5 @@ -25,6 +25,7 @@ struct tc_texture *next; GLuint name; int avail; + char *saved; /* stores saved texture data */ } tc_texture; typedef struct tc_slice { @@ -36,7 +37,7 @@ static tc_texture *first_texture; void -tc_clear () +tc_clear (void) { int i; @@ -55,6 +56,40 @@ } void +tc_backup (void) +{ + tc_texture *tex = first_texture; + while (tex) + { + tex->saved = g_slice_alloc (TC_WIDTH * TC_HEIGHT); + + glBindTexture (GL_TEXTURE_2D, tex->name); + glGetTexImage (GL_TEXTURE_2D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved); + + tex = tex->next; + } +} + +void +tc_restore (void) +{ + tc_texture *tex = first_texture; + + while (tex) + { + glBindTexture (GL_TEXTURE_2D, tex->name); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved); + + g_slice_free1 (TC_WIDTH * TC_HEIGHT, tex->saved); + tex->saved = 0; + + tex = tex->next; + } +} + +void tc_get (tc_area *area, int width, int height) { int slice_height = MIN (height + TC_ROUND - 1, TC_HEIGHT) & ~(TC_ROUND - 1); @@ -78,10 +113,11 @@ if (!match) { match = g_slice_new (tc_texture); - match->next = first_texture; + match->next = first_texture; first_texture = match; - match->name = gen_texture (); - match->avail = TC_HEIGHT; + match->name = gen_texture (); + match->avail = TC_HEIGHT; + match->saved = 0; glBindTexture (GL_TEXTURE_2D, match->name); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);