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