ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/texcache.c
(Generate patch)

Comparing deliantra/Deliantra-Client/texcache.c (file contents):
Revision 1.6 by root, Tue Dec 25 19:08:31 2007 UTC vs.
Revision 1.8 by root, Sun Nov 29 14:45:12 2009 UTC

16static void tc_clear (void); 16static void tc_clear (void);
17static void tc_backup (void); 17static void tc_backup (void);
18static void tc_restore (void); 18static void tc_restore (void);
19 19
20///////////////////////////////////////////////////////////////////////////// 20/////////////////////////////////////////////////////////////////////////////
21
22// required as bug-workaround for apple/ati/...
23static unsigned char tc_temptile [TC_WIDTH * TC_HEIGHT];
21 24
22#include <glib.h> 25#include <glib.h>
23 26
24int tc_generation; 27int tc_generation;
25 28
56 59
57 ++tc_generation; 60 ++tc_generation;
58} 61}
59 62
60void 63void
64tex_backup (tc_texture *tex)
65{
66 tex->saved = g_slice_alloc (TC_WIDTH * TC_HEIGHT);
67
68 glBindTexture (GL_TEXTURE_2D, tex->name);
69 glGetTexImage (GL_TEXTURE_2D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved);
70}
71
72void
73tex_restore (tc_texture *tex)
74{
75 glBindTexture (GL_TEXTURE_2D, tex->name);
76 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
77 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
78 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved);
79
80 g_slice_free1 (TC_WIDTH * TC_HEIGHT, tex->saved);
81 tex->saved = 0;
82}
83
84void
61tc_backup (void) 85tc_backup (void)
62{ 86{
63 tc_texture *tex = first_texture; 87 tc_texture *tex;
64 while (tex) 88
65 { 89 for (tex = first_texture; tex; tex = tex->next)
66 tex->saved = g_slice_alloc (TC_WIDTH * TC_HEIGHT); 90 tex_backup (tex);
67
68 glBindTexture (GL_TEXTURE_2D, tex->name);
69 glGetTexImage (GL_TEXTURE_2D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved);
70
71 tex = tex->next;
72 }
73} 91}
74 92
75void 93void
76tc_restore (void) 94tc_restore (void)
77{ 95{
78 tc_texture *tex = first_texture; 96 tc_texture *tex;
79 97
80 while (tex) 98 for (tex = first_texture; tex; tex = tex->next)
81 { 99 tex_restore (tex);
82 glBindTexture (GL_TEXTURE_2D, tex->name);
83 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
84 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
85 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved);
86
87 g_slice_free1 (TC_WIDTH * TC_HEIGHT, tex->saved);
88 tex->saved = 0;
89
90 tex = tex->next;
91 }
92} 100}
93 101
94void 102void
95tc_get (tc_area *area, int width, int height) 103tc_get (tc_area *area, int width, int height)
96{ 104{
122 match->saved = 0; 130 match->saved = 0;
123 131
124 glBindTexture (GL_TEXTURE_2D, match->name); 132 glBindTexture (GL_TEXTURE_2D, match->name);
125 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 133 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
126 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 134 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
127 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0); 135
136 // the last parameter should be NULL, but way too amny drivers (ATI, Mesa) crash,
137 // so we better provide some random garbage data for them.
138 glTexImage2D (GL_TEXTURE_2D,
139 0, GL_ALPHA,
140 TC_WIDTH, TC_HEIGHT,
141 0, GL_ALPHA,
142 GL_UNSIGNED_BYTE, tc_temptile);
128 } 143 }
129 144
130 match->avail -= slice_height; 145 match->avail -= slice_height;
131 146
132 slice->name = match->name; 147 slice->name = match->name;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines