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.5 by root, Tue Dec 25 18:58:32 2007 UTC vs.
Revision 1.8 by root, Sun Nov 29 14:45:12 2009 UTC

9 int x, y, w, h; 9 int x, y, w, h;
10} tc_area; 10} tc_area;
11 11
12extern int tc_generation; 12extern int tc_generation;
13 13
14void tc_get (tc_area *area, int width, int height); 14static void tc_get (tc_area *area, int width, int height);
15void tc_put (tc_area *area); 15static void tc_put (tc_area *area);
16void tc_clear (); 16static void tc_clear (void);
17static void tc_backup (void);
18static void tc_restore (void);
17 19
18///////////////////////////////////////////////////////////////////////////// 20/////////////////////////////////////////////////////////////////////////////
21
22// required as bug-workaround for apple/ati/...
23static unsigned char tc_temptile [TC_WIDTH * TC_HEIGHT];
19 24
20#include <glib.h> 25#include <glib.h>
21 26
22int tc_generation; 27int tc_generation;
23 28
54 59
55 ++tc_generation; 60 ++tc_generation;
56} 61}
57 62
58void 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
59tc_backup (void) 85tc_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
73void 93void
74tc_restore (void) 94tc_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
92void 102void
93tc_get (tc_area *area, int width, int height) 103tc_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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines