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