1 | #include <vector> |
1 | #include <vector> |
|
|
2 | |
|
|
3 | #include "salloc.h" |
2 | |
4 | |
3 | struct rc_key_t |
5 | struct rc_key_t |
4 | { |
6 | { |
5 | GLenum mode; |
7 | GLenum mode; |
6 | GLenum format; // 0, GL_T2F_V3F, GL_V2F |
8 | GLenum format; // 0, GL_T2F_V3F, GL_V2F |
… | |
… | |
37 | uint8_t u, v, w, h; |
39 | uint8_t u, v, w, h; |
38 | uint16_t x, y; |
40 | uint16_t x, y; |
39 | }; |
41 | }; |
40 | |
42 | |
41 | struct array_t |
43 | struct array_t |
42 | : std::vector<uint8_t> |
44 | : std::vector<uint8_t, slice_allocator<uint8_t>> |
43 | { |
45 | { |
44 | using std::vector<uint8_t>::vector; |
46 | using std::vector<uint8_t, slice_allocator<uint8_t>>::vector; |
45 | |
47 | |
46 | template<typename T> |
48 | template<typename T> |
47 | T &append () |
49 | T &append () |
48 | { |
50 | { |
49 | auto ofs = size (); |
51 | auto ofs = size (); |
… | |
… | |
52 | } |
54 | } |
53 | |
55 | |
54 | void v2f (float x, float y) |
56 | void v2f (float x, float y) |
55 | { |
57 | { |
56 | auto &vec = append<float[2]> (); |
58 | auto &vec = append<float[2]> (); |
57 | vec[0] = x; |
59 | vec[0] = x / 2; |
58 | vec[1] = y; |
60 | vec[1] = y / 2; |
59 | } |
61 | } |
60 | |
62 | |
61 | void t2f_v3f (float u, float v, float x, float y, float z) |
63 | void t2f_v3f (float u, float v, float x, float y, float z) |
62 | { |
64 | { |
63 | auto &vec = append<float[5]> (); |
65 | auto &vec = append<float[5]> (); |
… | |
… | |
82 | c.y = y + h; |
84 | c.y = y + h; |
83 | } |
85 | } |
84 | } |
86 | } |
85 | }; |
87 | }; |
86 | |
88 | |
|
|
89 | int drawcount = 0; |
87 | ska::flat_hash_map<rc_key_t, array_t> h; |
90 | ska::flat_hash_map<rc_key_t, array_t> h; |
88 | |
91 | |
89 | void clear () |
92 | void clear () |
90 | { |
93 | { |
|
|
94 | drawcount = 0; |
91 | h.clear (); |
95 | h.clear (); |
92 | } |
96 | } |
93 | |
97 | |
94 | array_t &array (const rc_key_t &k) |
98 | array_t &array (const rc_key_t &k) |
95 | { |
99 | { |
… | |
… | |
126 | //glUnlockArraysEXT (); |
130 | //glUnlockArraysEXT (); |
127 | } |
131 | } |
128 | else |
132 | else |
129 | { |
133 | { |
130 | // optimised character quad storage. slower but nice on memory. |
134 | // optimised character quad storage. slower but nice on memory. |
131 | // reduces storage requirements from 80 bytes/char to 6-8 |
135 | // reduces storage requirements from 80 bytes/char to 8 |
132 | auto *c = (glyph_data *) arr.data (); |
136 | auto *c = (glyph_data *) arr.data (); |
133 | auto *e = (glyph_data *)(arr.data () + arr.size ()); |
137 | auto *e = (glyph_data *)(arr.data () + arr.size ()); |
134 | |
138 | |
135 | glBegin (key.mode); // practically must be quads |
139 | glBegin (key.mode); // practically must be quads |
136 | |
140 | |
… | |
… | |
147 | glEnd (); |
151 | glEnd (); |
148 | } |
152 | } |
149 | } |
153 | } |
150 | |
154 | |
151 | glDisable (GL_TEXTURE_2D); |
155 | glDisable (GL_TEXTURE_2D); |
|
|
156 | |
|
|
157 | if (ecb_expect_false (++drawcount == 16)) |
|
|
158 | for (auto &&it = h.begin (); it != h.end (); ++it) |
|
|
159 | it->second.shrink_to_fit (); |
152 | } |
160 | } |
153 | }; |
161 | }; |
154 | |
162 | |