--- deliantra/Deliantra-Client/texcache.c 2007/12/25 19:08:31 1.6 +++ deliantra/Deliantra-Client/texcache.c 2018/11/18 00:52:22 1.9 @@ -19,6 +19,9 @@ ///////////////////////////////////////////////////////////////////////////// +// required as bug-workaround for apple/ati/... +static unsigned char tc_temptile [TC_WIDTH * TC_HEIGHT]; + #include int tc_generation; @@ -58,37 +61,42 @@ } void -tc_backup (void) +tex_backup (tc_texture *tex) { - tc_texture *tex = first_texture; - while (tex) - { - tex->saved = g_slice_alloc (TC_WIDTH * TC_HEIGHT); + tex->saved = (char *)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; - } + glBindTexture (GL_TEXTURE_2D, tex->name); + glGetTexImage (GL_TEXTURE_2D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved); } void -tc_restore (void) +tex_restore (tc_texture *tex) { - tc_texture *tex = first_texture; + 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); - 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; +} - g_slice_free1 (TC_WIDTH * TC_HEIGHT, tex->saved); - tex->saved = 0; +void +tc_backup (void) +{ + tc_texture *tex; + + for (tex = first_texture; tex; tex = tex->next) + tex_backup (tex); +} - tex = tex->next; - } +void +tc_restore (void) +{ + tc_texture *tex; + + for (tex = first_texture; tex; tex = tex->next) + tex_restore (tex); } void @@ -124,7 +132,14 @@ glBindTexture (GL_TEXTURE_2D, match->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, 0); + + // the last parameter should be NULL, but way too amny drivers (ATI, Mesa) crash, + // so we better provide some random garbage data for them. + glTexImage2D (GL_TEXTURE_2D, + 0, GL_ALPHA, + TC_WIDTH, TC_HEIGHT, + 0, GL_ALPHA, + GL_UNSIGNED_BYTE, tc_temptile); } match->avail -= slice_height;