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.3 by root, Fri Apr 27 21:27:51 2007 UTC vs.
Revision 1.5 by root, Tue Dec 25 18:58:32 2007 UTC

1// all these must be powers of two 1// all these must be powers of two
2// width and height better be <=256 as we use bytes in the rendercache
2#define TC_WIDTH 256 3#define TC_WIDTH 256
3#define TC_HEIGHT 256 4#define TC_HEIGHT 256
4#define TC_ROUND 4 5#define TC_ROUND 4
5 6
6typedef struct { 7typedef struct {
22 23
23typedef struct tc_texture { 24typedef struct tc_texture {
24 struct tc_texture *next; 25 struct tc_texture *next;
25 GLuint name; 26 GLuint name;
26 int avail; 27 int avail;
28 char *saved; /* stores saved texture data */
27} tc_texture; 29} tc_texture;
28 30
29typedef struct tc_slice { 31typedef struct tc_slice {
30 GLuint name; 32 GLuint name;
31 int avail, y; 33 int avail, y;
33 35
34static tc_slice slices[TC_HEIGHT / TC_ROUND]; 36static tc_slice slices[TC_HEIGHT / TC_ROUND];
35static tc_texture *first_texture; 37static tc_texture *first_texture;
36 38
37void 39void
38tc_clear () 40tc_clear (void)
39{ 41{
40 int i; 42 int i;
41 43
42 for (i = TC_HEIGHT / TC_ROUND; i--; ) 44 for (i = TC_HEIGHT / TC_ROUND; i--; )
43 slices [i].name = 0; 45 slices [i].name = 0;
49 g_slice_free (tc_texture, first_texture); 51 g_slice_free (tc_texture, first_texture);
50 first_texture = next; 52 first_texture = next;
51 } 53 }
52 54
53 ++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 }
54} 90}
55 91
56void 92void
57tc_get (tc_area *area, int width, int height) 93tc_get (tc_area *area, int width, int height)
58{ 94{
75 111
76 // create a new texture if necessary 112 // create a new texture if necessary
77 if (!match) 113 if (!match)
78 { 114 {
79 match = g_slice_new (tc_texture); 115 match = g_slice_new (tc_texture);
80 match->next = first_texture; 116 match->next = first_texture;
81 first_texture = match; 117 first_texture = match;
82 match->name = gen_texture (); 118 match->name = gen_texture ();
83 match->avail = TC_HEIGHT; 119 match->avail = TC_HEIGHT;
120 match->saved = 0;
84 121
85 glBindTexture (GL_TEXTURE_2D, match->name); 122 glBindTexture (GL_TEXTURE_2D, match->name);
86 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 123 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
87 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 124 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
88 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