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 | |
6 | typedef struct { |
7 | typedef struct { |
7 | GLuint name; |
8 | GLuint name; |
8 | int x, y, w, h; |
9 | int x, y, w, h; |
9 | } tc_area; |
10 | } tc_area; |
10 | |
11 | |
|
|
12 | extern int tc_generation; |
|
|
13 | |
11 | void tc_get (tc_area *area, int width, int height); |
14 | void tc_get (tc_area *area, int width, int height); |
12 | void tc_put (tc_area *area); |
15 | void tc_put (tc_area *area); |
13 | void tc_clear (); |
16 | void tc_clear (); |
14 | |
17 | |
15 | ///////////////////////////////////////////////////////////////////////////// |
18 | ///////////////////////////////////////////////////////////////////////////// |
16 | |
19 | |
17 | #include <glib.h> |
20 | #include <glib.h> |
|
|
21 | |
|
|
22 | int tc_generation; |
18 | |
23 | |
19 | typedef struct tc_texture { |
24 | typedef struct tc_texture { |
20 | struct tc_texture *next; |
25 | struct tc_texture *next; |
21 | GLuint name; |
26 | GLuint name; |
22 | int avail; |
27 | int avail; |
… | |
… | |
39 | slices [i].name = 0; |
44 | slices [i].name = 0; |
40 | |
45 | |
41 | while (first_texture) |
46 | while (first_texture) |
42 | { |
47 | { |
43 | tc_texture *next = first_texture->next; |
48 | tc_texture *next = first_texture->next; |
44 | glDeleteTextures (1, &first_texture->name); |
49 | del_texture (first_texture->name); |
45 | g_slice_free (tc_texture, first_texture); |
50 | g_slice_free (tc_texture, first_texture); |
46 | first_texture = next; |
51 | first_texture = next; |
47 | } |
52 | } |
|
|
53 | |
|
|
54 | ++tc_generation; |
48 | } |
55 | } |
49 | |
56 | |
50 | void |
57 | void |
51 | tc_get (tc_area *area, int width, int height) |
58 | tc_get (tc_area *area, int width, int height) |
52 | { |
59 | { |
… | |
… | |
71 | if (!match) |
78 | if (!match) |
72 | { |
79 | { |
73 | match = g_slice_new (tc_texture); |
80 | match = g_slice_new (tc_texture); |
74 | match->next = first_texture; |
81 | match->next = first_texture; |
75 | first_texture = match; |
82 | first_texture = match; |
76 | glGenTextures (1, &match->name); |
83 | match->name = gen_texture (); |
77 | match->avail = TC_HEIGHT; |
84 | match->avail = TC_HEIGHT; |
78 | |
85 | |
79 | glBindTexture (GL_TEXTURE_2D, match->name); |
86 | glBindTexture (GL_TEXTURE_2D, match->name); |
80 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
87 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
81 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
88 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |