… | |
… | |
9 | int x, y, w, h; |
9 | int x, y, w, h; |
10 | } tc_area; |
10 | } tc_area; |
11 | |
11 | |
12 | extern int tc_generation; |
12 | extern int tc_generation; |
13 | |
13 | |
14 | void tc_get (tc_area *area, int width, int height); |
14 | static void tc_get (tc_area *area, int width, int height); |
15 | void tc_put (tc_area *area); |
15 | static void tc_put (tc_area *area); |
16 | void tc_clear (); |
16 | static void tc_clear (void); |
|
|
17 | static void tc_backup (void); |
|
|
18 | static void tc_restore (void); |
17 | |
19 | |
18 | ///////////////////////////////////////////////////////////////////////////// |
20 | ///////////////////////////////////////////////////////////////////////////// |
|
|
21 | |
|
|
22 | // required as bug-workaround for apple/ati/... |
|
|
23 | static unsigned char tc_temptile [TC_WIDTH * TC_HEIGHT]; |
19 | |
24 | |
20 | #include <glib.h> |
25 | #include <glib.h> |
21 | |
26 | |
22 | int tc_generation; |
27 | int tc_generation; |
23 | |
28 | |
… | |
… | |
54 | |
59 | |
55 | ++tc_generation; |
60 | ++tc_generation; |
56 | } |
61 | } |
57 | |
62 | |
58 | void |
63 | void |
|
|
64 | tex_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 | |
|
|
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 |
59 | tc_backup (void) |
85 | tc_backup (void) |
60 | { |
86 | { |
61 | tc_texture *tex = first_texture; |
87 | tc_texture *tex; |
62 | while (tex) |
88 | |
63 | { |
89 | for (tex = first_texture; tex; tex = tex->next) |
64 | tex->saved = g_slice_alloc (TC_WIDTH * TC_HEIGHT); |
90 | tex_backup (tex); |
65 | |
|
|
66 | glBindTexture (GL_TEXTURE_2D, tex->name); |
|
|
67 | glGetTexImage (GL_TEXTURE_2D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved); |
|
|
68 | |
|
|
69 | tex = tex->next; |
|
|
70 | } |
|
|
71 | } |
91 | } |
72 | |
92 | |
73 | void |
93 | void |
74 | tc_restore (void) |
94 | tc_restore (void) |
75 | { |
95 | { |
76 | tc_texture *tex = first_texture; |
96 | tc_texture *tex; |
77 | |
97 | |
78 | while (tex) |
98 | for (tex = first_texture; tex; tex = tex->next) |
79 | { |
99 | tex_restore (tex); |
80 | glBindTexture (GL_TEXTURE_2D, tex->name); |
|
|
81 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
|
82 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
|
83 | glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved); |
|
|
84 | |
|
|
85 | g_slice_free1 (TC_WIDTH * TC_HEIGHT, tex->saved); |
|
|
86 | tex->saved = 0; |
|
|
87 | |
|
|
88 | tex = tex->next; |
|
|
89 | } |
|
|
90 | } |
100 | } |
91 | |
101 | |
92 | void |
102 | void |
93 | tc_get (tc_area *area, int width, int height) |
103 | tc_get (tc_area *area, int width, int height) |
94 | { |
104 | { |
… | |
… | |
120 | match->saved = 0; |
130 | match->saved = 0; |
121 | |
131 | |
122 | glBindTexture (GL_TEXTURE_2D, match->name); |
132 | glBindTexture (GL_TEXTURE_2D, match->name); |
123 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
133 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
124 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
134 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
125 | 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); |
126 | } |
143 | } |
127 | |
144 | |
128 | match->avail -= slice_height; |
145 | match->avail -= slice_height; |
129 | |
146 | |
130 | slice->name = match->name; |
147 | slice->name = match->name; |