ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/rendercache.c
(Generate patch)

Comparing deliantra/Deliantra-Client/rendercache.c (file contents):
Revision 1.2 by root, Sat Aug 11 11:41:24 2007 UTC vs.
Revision 1.6 by root, Sun Aug 12 12:14:01 2007 UTC

1typedef struct { 1typedef 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 GLint 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
8typedef struct { 8typedef struct {
74 74
75 SvCUR_set (arr, len); 75 SvCUR_set (arr, len);
76} 76}
77 77
78static void 78static void
79rc_glyph (rc_array_t *arr, int u, int v, int w, int h, int x, int y)
80{
81 U8 *c;
82 STRLEN len = SvCUR (arr);
83 SvGROW (arr, len + 2 * 2 + 1 * 4);
84 c = (U8 *)SvEND (arr);
85
86 x += w;
87 y += h;
88
89 *c++ = u;
90 *c++ = v;
91 *c++ = w;
92 *c++ = h;
93
94 // use ber-encoding for up to 14 bits (16k)
95 *c = 0x80 | (x >> 7); c += (x >> 7) ? 1 : 0; *c++ = x & 0x7f;
96 *c = 0x80 | (y >> 7); c += (y >> 7) ? 1 : 0; *c++ = y & 0x7f;
97
98 SvCUR_set (arr, c - (U8 *)SvPVX (arr));
99}
100
101static void
79rc_draw (rc_t *rc) 102rc_draw (rc_t *rc)
80{ 103{
81 HE *he; 104 HE *he;
82 105
83 hv_iterinit (rc->hv); 106 hv_iterinit (rc->hv);
87 rc_array_t *arr = HeVAL (he); 110 rc_array_t *arr = HeVAL (he);
88 STRLEN len; 111 STRLEN len;
89 char *arr_pv = SvPV (arr, len); 112 char *arr_pv = SvPV (arr, len);
90 GLsizei stride; 113 GLsizei stride;
91 114
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) 115 if (key->texname)
97 { 116 {
98 glBindTexture (GL_TEXTURE_2D, key->texname); 117 glBindTexture (GL_TEXTURE_2D, key->texname);
99 glEnable (GL_TEXTURE_2D); 118 glEnable (GL_TEXTURE_2D);
100 } 119 }
101 else 120 else
102 glDisable (GL_TEXTURE_2D); 121 glDisable (GL_TEXTURE_2D);
103 122
104 glColor4ub (key->r, key->g, key->b, key->a); 123 glColor4ub (key->r, key->g, key->b, key->a);
124
125 if (key->format)
126 {
127 stride = key->format == GL_T2F_V3F ? sizeof (float) * 5
128 : key->format == GL_V2F ? sizeof (float) * 2
129 : 65536;
130
105 glInterleavedArrays (key->format, 0, (void *)arr_pv); 131 glInterleavedArrays (key->format, 0, (void *)arr_pv);
132 //glLockArraysEXT (0, len / stride);
106 glDrawArrays (key->mode, 0, len / stride); 133 glDrawArrays (key->mode, 0, len / stride);
134 //glUnlockArraysEXT ();
135 }
136 else
137 {
138 // optimised character quad storage. slower but nice on memory.
139 // reduces storage requirements from 80 bytes/char to 6-8
140 U8 *c = (U8 *)arr_pv;
141 U8 *e = c + len;
142
143 glBegin (key->mode); // practically must be quads
144
145 while (c < e)
146 {
147 int u, v, x, y, w, h;
148
149 u = *c++;
150 v = *c++;
151 w = *c++;
152 h = *c++;
153
154 x = *c++; if (x > 0x7f) x = ((x & 0x7f) << 7) | *c++;
155 y = *c++; if (y > 0x7f) y = ((y & 0x7f) << 7) | *c++;
156
157 x -= w;
158 y -= h;
159
160 glTexCoord2f ( u * (1.f / TC_WIDTH), v * (1.f / TC_HEIGHT)); glVertex2i (x , y );
161 glTexCoord2f ((u + w) * (1.f / TC_WIDTH), v * (1.f / TC_HEIGHT)); glVertex2i (x + w, y );
162 glTexCoord2f ((u + w) * (1.f / TC_WIDTH), (v + h) * (1.f / TC_HEIGHT)); glVertex2i (x + w, y + h);
163 glTexCoord2f ( u * (1.f / TC_WIDTH), (v + h) * (1.f / TC_HEIGHT)); glVertex2i (x , y + h);
164 }
165
166 glEnd ();
167 }
107 } 168 }
108 169
109 glDisable (GL_TEXTURE_2D); 170 glDisable (GL_TEXTURE_2D);
110} 171}
111 172

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines