… | |
… | |
16 | static void tc_clear (void); |
16 | static void tc_clear (void); |
17 | static void tc_backup (void); |
17 | static void tc_backup (void); |
18 | static void tc_restore (void); |
18 | static void tc_restore (void); |
19 | |
19 | |
20 | ///////////////////////////////////////////////////////////////////////////// |
20 | ///////////////////////////////////////////////////////////////////////////// |
|
|
21 | |
|
|
22 | // required as bug-workaround for apple/ati/... |
|
|
23 | static unsigned char tc_temptile [TC_WIDTH * TC_HEIGHT]; |
21 | |
24 | |
22 | #include <glib.h> |
25 | #include <glib.h> |
23 | |
26 | |
24 | int tc_generation; |
27 | int tc_generation; |
25 | |
28 | |
… | |
… | |
56 | |
59 | |
57 | ++tc_generation; |
60 | ++tc_generation; |
58 | } |
61 | } |
59 | |
62 | |
60 | void |
63 | void |
|
|
64 | tex_backup (tc_texture *tex) |
|
|
65 | { |
|
|
66 | tex->saved = (char *)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 | |
|
|
72 | void |
|
|
73 | tex_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 | |
|
|
84 | void |
61 | tc_backup (void) |
85 | tc_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 | |
75 | void |
93 | void |
76 | tc_restore (void) |
94 | tc_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 | |
94 | void |
102 | void |
95 | tc_get (tc_area *area, int width, int height) |
103 | tc_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; |