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.4 by root, Sun Aug 12 08:44:22 2007 UTC vs.
Revision 1.5 by root, Tue Dec 25 18:58:32 2007 UTC

23 23
24typedef struct tc_texture { 24typedef struct tc_texture {
25 struct tc_texture *next; 25 struct tc_texture *next;
26 GLuint name; 26 GLuint name;
27 int avail; 27 int avail;
28 char *saved; /* stores saved texture data */
28} tc_texture; 29} tc_texture;
29 30
30typedef struct tc_slice { 31typedef struct tc_slice {
31 GLuint name; 32 GLuint name;
32 int avail, y; 33 int avail, y;
34 35
35static tc_slice slices[TC_HEIGHT / TC_ROUND]; 36static tc_slice slices[TC_HEIGHT / TC_ROUND];
36static tc_texture *first_texture; 37static tc_texture *first_texture;
37 38
38void 39void
39tc_clear () 40tc_clear (void)
40{ 41{
41 int i; 42 int i;
42 43
43 for (i = TC_HEIGHT / TC_ROUND; i--; ) 44 for (i = TC_HEIGHT / TC_ROUND; i--; )
44 slices [i].name = 0; 45 slices [i].name = 0;
50 g_slice_free (tc_texture, first_texture); 51 g_slice_free (tc_texture, first_texture);
51 first_texture = next; 52 first_texture = next;
52 } 53 }
53 54
54 ++tc_generation; 55 ++tc_generation;
56}
57
58void
59tc_backup (void)
60{
61 tc_texture *tex = first_texture;
62 while (tex)
63 {
64 tex->saved = g_slice_alloc (TC_WIDTH * TC_HEIGHT);
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}
72
73void
74tc_restore (void)
75{
76 tc_texture *tex = first_texture;
77
78 while (tex)
79 {
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 }
55} 90}
56 91
57void 92void
58tc_get (tc_area *area, int width, int height) 93tc_get (tc_area *area, int width, int height)
59{ 94{
76 111
77 // create a new texture if necessary 112 // create a new texture if necessary
78 if (!match) 113 if (!match)
79 { 114 {
80 match = g_slice_new (tc_texture); 115 match = g_slice_new (tc_texture);
81 match->next = first_texture; 116 match->next = first_texture;
82 first_texture = match; 117 first_texture = match;
83 match->name = gen_texture (); 118 match->name = gen_texture ();
84 match->avail = TC_HEIGHT; 119 match->avail = TC_HEIGHT;
120 match->saved = 0;
85 121
86 glBindTexture (GL_TEXTURE_2D, match->name); 122 glBindTexture (GL_TEXTURE_2D, match->name);
87 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 123 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
88 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 124 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
89 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0); 125 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines