1 | typedef struct { |
1 | typedef struct { |
2 | GLenum mode; |
2 | GLenum mode; |
3 | GLenum format; // GL_T2F_V3F, GL_V2F |
3 | GLenum format; // 0, GL_T2F_V3F, GL_V2F |
4 | GLint texname; |
4 | GLuint texname; |
5 | unsigned char r, g, b, a; |
5 | unsigned char r, g, b, a; |
6 | } rc_key_t; |
6 | } rc_key_t; |
7 | |
7 | |
8 | typedef struct { |
8 | typedef struct { |
9 | HV *hv; |
9 | HV *hv; |
10 | } rc_t; |
10 | } rc_t; |
11 | |
11 | |
12 | typedef SV rc_array_t; |
12 | typedef SV rc_array_t; |
13 | |
13 | |
14 | static rc_t * |
14 | static rc_t * |
15 | rc_alloc () |
15 | rc_alloc (void) |
16 | { |
16 | { |
17 | rc_t *rc = g_slice_new0 (rc_t); |
17 | rc_t *rc = g_slice_new0 (rc_t); |
18 | rc->hv = newHV (); |
18 | rc->hv = newHV (); |
19 | |
19 | |
20 | return rc; |
20 | return rc; |
… | |
… | |
40 | |
40 | |
41 | if (SvTYPE (sv) != SVt_PV) |
41 | if (SvTYPE (sv) != SVt_PV) |
42 | { |
42 | { |
43 | sv_upgrade (sv, SVt_PV); |
43 | sv_upgrade (sv, SVt_PV); |
44 | SvPOK_only (sv); |
44 | SvPOK_only (sv); |
|
|
45 | sv_grow (sv, 512); |
45 | } |
46 | } |
46 | |
47 | |
47 | return sv; |
48 | return sv; |
48 | } |
49 | } |
49 | |
50 | |
50 | static void |
51 | static void |
51 | rc_v2f (rc_array_t *arr, float x, float y) |
52 | rc_v2f (rc_array_t *arr, float x, float y) |
52 | { |
53 | { |
53 | STRLEN len = SvCUR (arr) + sizeof (float) * 5; |
54 | char *end = fast_sv_grow (arr, sizeof (float) * 2); |
54 | SvGROW (arr, len); |
|
|
55 | |
55 | |
56 | ((float *)SvEND (arr))[0] = x; |
56 | ((float *)end)[0] = x; |
57 | ((float *)SvEND (arr))[1] = y; |
57 | ((float *)end)[1] = y; |
58 | |
|
|
59 | SvCUR_set (arr, len); |
|
|
60 | } |
58 | } |
61 | |
59 | |
62 | static void |
60 | static void |
63 | rc_t2f_v3f (rc_array_t *arr, float u, float v, float x, float y, float z) |
61 | rc_t2f_v3f (rc_array_t *arr, float u, float v, float x, float y, float z) |
64 | { |
62 | { |
65 | STRLEN len = SvCUR (arr) + sizeof (float) * 5; |
63 | char *end = fast_sv_grow (arr, sizeof (float) * 5); |
66 | SvGROW (arr, len); |
|
|
67 | |
64 | |
68 | ((float *)SvEND (arr))[0] = u; |
65 | ((float *)end)[0] = u; |
69 | ((float *)SvEND (arr))[1] = v; |
66 | ((float *)end)[1] = v; |
70 | |
67 | |
71 | ((float *)SvEND (arr))[2] = x; |
68 | ((float *)end)[2] = x; |
72 | ((float *)SvEND (arr))[3] = y; |
69 | ((float *)end)[3] = y; |
73 | ((float *)SvEND (arr))[4] = z; |
70 | ((float *)end)[4] = z; |
|
|
71 | } |
74 | |
72 | |
75 | SvCUR_set (arr, len); |
73 | static void |
|
|
74 | rc_glyph (rc_array_t *arr, int u, int v, int w, int h, int x, int y) |
|
|
75 | { |
|
|
76 | if (w && h) |
|
|
77 | { |
|
|
78 | U8 *c = (U8 *)fast_sv_grow (arr, 4 + 4); |
|
|
79 | |
|
|
80 | x += w; |
|
|
81 | y += h; |
|
|
82 | |
|
|
83 | *c++ = u; |
|
|
84 | *c++ = v; |
|
|
85 | *c++ = w; |
|
|
86 | *c++ = h; |
|
|
87 | |
|
|
88 | // use ber-encoding for up to 14 bits (16k) |
|
|
89 | *c = 0x80 | (x >> 7); c += (x >> 7) ? 1 : 0; *c++ = x & 0x7f; |
|
|
90 | *c = 0x80 | (y >> 7); c += (y >> 7) ? 1 : 0; *c++ = y & 0x7f; |
|
|
91 | |
|
|
92 | SvCUR_set (arr, c - (U8 *)SvPVX (arr)); |
|
|
93 | } |
76 | } |
94 | } |
77 | |
95 | |
78 | static void |
96 | static void |
79 | rc_draw (rc_t *rc) |
97 | rc_draw (rc_t *rc) |
80 | { |
98 | { |
… | |
… | |
87 | rc_array_t *arr = HeVAL (he); |
105 | rc_array_t *arr = HeVAL (he); |
88 | STRLEN len; |
106 | STRLEN len; |
89 | char *arr_pv = SvPV (arr, len); |
107 | char *arr_pv = SvPV (arr, len); |
90 | GLsizei stride; |
108 | GLsizei stride; |
91 | |
109 | |
92 | stride = key->format == GL_T2F_V3F ? sizeof (float) * 5 |
|
|
93 | : key->format == GL_V2F ? sizeof (float) * 2 |
|
|
94 | : 65536; |
|
|
95 | |
|
|
96 | if (key->texname) |
110 | if (key->texname) |
97 | { |
111 | { |
98 | glBindTexture (GL_TEXTURE_2D, key->texname); |
112 | glBindTexture (GL_TEXTURE_2D, key->texname); |
99 | glEnable (GL_TEXTURE_2D); |
113 | glEnable (GL_TEXTURE_2D); |
100 | } |
114 | } |
101 | else |
115 | else |
102 | glDisable (GL_TEXTURE_2D); |
116 | glDisable (GL_TEXTURE_2D); |
103 | |
117 | |
104 | glColor4ub (key->r, key->g, key->b, key->a); |
118 | glColor4ub (key->r, key->g, key->b, key->a); |
|
|
119 | |
|
|
120 | if (key->format) |
|
|
121 | { |
|
|
122 | stride = key->format == GL_T2F_V3F ? sizeof (float) * 5 |
|
|
123 | : key->format == GL_V2F ? sizeof (float) * 2 |
|
|
124 | : 65536; |
|
|
125 | |
105 | glInterleavedArrays (key->format, 0, (void *)arr_pv); |
126 | glInterleavedArrays (key->format, 0, (void *)arr_pv); |
|
|
127 | //glLockArraysEXT (0, len / stride); |
106 | glDrawArrays (key->mode, 0, len / stride); |
128 | glDrawArrays (key->mode, 0, len / stride); |
|
|
129 | //glUnlockArraysEXT (); |
|
|
130 | } |
|
|
131 | else |
|
|
132 | { |
|
|
133 | // optimised character quad storage. slower but nice on memory. |
|
|
134 | // reduces storage requirements from 80 bytes/char to 6-8 |
|
|
135 | U8 *c = (U8 *)arr_pv; |
|
|
136 | U8 *e = c + len; |
|
|
137 | |
|
|
138 | glBegin (key->mode); // practically must be quads |
|
|
139 | |
|
|
140 | while (c < e) |
|
|
141 | { |
|
|
142 | int u, v, x, y, w, h; |
|
|
143 | |
|
|
144 | u = *c++; |
|
|
145 | v = *c++; |
|
|
146 | w = *c++; |
|
|
147 | h = *c++; |
|
|
148 | |
|
|
149 | x = *c++; if (x > 0x7f) x = ((x & 0x7f) << 7) | *c++; |
|
|
150 | y = *c++; if (y > 0x7f) y = ((y & 0x7f) << 7) | *c++; |
|
|
151 | |
|
|
152 | x -= w; |
|
|
153 | y -= h; |
|
|
154 | |
|
|
155 | glTexCoord2f ( u * (1.f / TC_WIDTH), v * (1.f / TC_HEIGHT)); glVertex2i (x , y ); |
|
|
156 | glTexCoord2f ((u + w) * (1.f / TC_WIDTH), v * (1.f / TC_HEIGHT)); glVertex2i (x + w, y ); |
|
|
157 | glTexCoord2f ((u + w) * (1.f / TC_WIDTH), (v + h) * (1.f / TC_HEIGHT)); glVertex2i (x + w, y + h); |
|
|
158 | glTexCoord2f ( u * (1.f / TC_WIDTH), (v + h) * (1.f / TC_HEIGHT)); glVertex2i (x , y + h); |
|
|
159 | } |
|
|
160 | |
|
|
161 | glEnd (); |
|
|
162 | } |
107 | } |
163 | } |
108 | |
164 | |
109 | glDisable (GL_TEXTURE_2D); |
165 | glDisable (GL_TEXTURE_2D); |
110 | } |
166 | } |
111 | |
167 | |