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.7 by root, Thu Nov 26 07:19:11 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/////////////////////////////////////////////////////////////////////////////
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
61tex_backup (tc_texture *tex)
62{
63 tex->saved = g_slice_alloc (TC_WIDTH * TC_HEIGHT);
64
65 glBindTexture (GL_TEXTURE_2D, tex->name);
66 glGetTexImage (GL_TEXTURE_2D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved);
67}
68
69void
70tex_restore (tc_texture *tex)
71{
72 glBindTexture (GL_TEXTURE_2D, tex->name);
73 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
74 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
75 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex->saved);
76
77 g_slice_free1 (TC_WIDTH * TC_HEIGHT, tex->saved);
78 tex->saved = 0;
79}
80
81void
82tc_backup (void)
83{
84 tc_texture *tex;
85
86 for (tex = first_texture; tex; tex = tex->next)
87 tex_backup (tex);
88}
89
90void
91tc_restore (void)
92{
93 tc_texture *tex;
94
95 for (tex = first_texture; tex; tex = tex->next)
96 tex_restore (tex);
55} 97}
56 98
57void 99void
58tc_get (tc_area *area, int width, int height) 100tc_get (tc_area *area, int width, int height)
59{ 101{
76 118
77 // create a new texture if necessary 119 // create a new texture if necessary
78 if (!match) 120 if (!match)
79 { 121 {
80 match = g_slice_new (tc_texture); 122 match = g_slice_new (tc_texture);
81 match->next = first_texture; 123 match->next = first_texture;
82 first_texture = match; 124 first_texture = match;
83 match->name = gen_texture (); 125 match->name = gen_texture ();
84 match->avail = TC_HEIGHT; 126 match->avail = TC_HEIGHT;
127 match->saved = 0;
85 128
86 glBindTexture (GL_TEXTURE_2D, match->name); 129 glBindTexture (GL_TEXTURE_2D, match->name);
87 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 130 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
88 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 131 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); 132 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