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

Comparing deliantra/Deliantra-Client/pango-render.c (file contents):
Revision 1.10 by root, Sat Aug 11 12:07:54 2007 UTC vs.
Revision 1.19 by root, Sun Nov 18 00:52:22 2018 UTC

60 if (size > alloc) 60 if (size > alloc)
61 { 61 {
62 size = (size + 4095) & ~4095; 62 size = (size + 4095) & ~4095;
63 free (buffer); 63 free (buffer);
64 alloc = size; 64 alloc = size;
65 buffer = malloc (size); 65 buffer = (char *)malloc (size);
66 } 66 }
67 67
68 return buffer; 68 return buffer;
69} 69}
70 70
90 glyph->width = width; 90 glyph->width = width;
91 glyph->height = height; 91 glyph->height = height;
92 glyph->top = top; 92 glyph->top = top;
93 glyph->left = left; 93 glyph->left = left;
94 94
95 glyph->bitmap = temp_buffer (width * height); 95 glyph->bitmap = (uint8_t *)temp_buffer (width * height);
96 memset (glyph->bitmap, 0, glyph->stride * height); 96 memset (glyph->bitmap, 0, glyph->stride * height);
97 97
98 for (i = width; i--; ) 98 for (i = width; i--; )
99 glyph->bitmap [i] = glyph->bitmap [i + (height - 1) * glyph->stride] = 0xff; 99 glyph->bitmap [i] = glyph->bitmap [i + (height - 1) * glyph->stride] = 0xff;
100 100
159{ 159{
160 tc_put (&g->tex); 160 tc_put (&g->tex);
161 g_slice_free (glyph_info, g); 161 g_slice_free (glyph_info, g);
162} 162}
163 163
164static int apple_nvidia_bug_workaround;
165
166static void
167apple_nvidia_bug (int enable)
168{
169 apple_nvidia_bug_workaround = enable;
170}
171
172static void
173tex_update (int name, int x, int y, int w, int stride, int h, void *bm)
174{
175 glBindTexture (GL_TEXTURE_2D, name);
176
177 if (!apple_nvidia_bug_workaround)
178 {
179 glPixelStorei (GL_UNPACK_ROW_LENGTH, stride);
180 /*glPixelStorei (GL_UNPACK_ALIGNMENT, 1); expected cfplus default */
181 glTexSubImage2D (GL_TEXTURE_2D, 0, x, y, w, h, GL_ALPHA, GL_UNSIGNED_BYTE, bm);
182 /*glPixelStorei (GL_UNPACK_ALIGNMENT, 4);*/
183 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
184 }
185 else
186 {
187 /* starting with 10.5.5 (or 10.5.6), pple's nvidia driver corrupts textures */
188 /* when glTexSubImage is used, so do it the horribly slow way, */
189 /* reading/patching/uploading the full texture one each change */
190 int r;
191
192 glGetTexImage (GL_TEXTURE_2D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tc_temptile);
193
194 for (r = 0; r < h; ++r)
195 memcpy (tc_temptile + (y + r) * TC_WIDTH + x, (char *)bm + r * stride, w);
196
197 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tc_temptile);
198 }
199}
200
164static void 201static void
165draw_glyph (PangoRenderer *renderer_, PangoFont *font, PangoGlyph glyph, double x, double y) 202draw_glyph (PangoRenderer *renderer_, PangoFont *font, PangoGlyph glyph, double x, double y)
166{ 203{
167 PangoOpenGLRenderer *renderer = PANGO_OPENGL_RENDERER (renderer_); 204 PangoOpenGLRenderer *renderer = PANGO_OPENGL_RENDERER (renderer_);
168 glyph_info *g; 205 glyph_info *g;
169 float x1, y1, x2, y2;
170 206
171 if (glyph & PANGO_GLYPH_UNKNOWN_FLAG) 207 if (glyph & PANGO_GLYPH_UNKNOWN_FLAG)
172 { 208 {
173 glyph = pango_opengl_get_unknown_glyph (font); 209 glyph = pango_opengl_get_unknown_glyph (font);
174 210
175 if (glyph == PANGO_GLYPH_EMPTY) 211 if (glyph == PANGO_GLYPH_EMPTY)
176 glyph = PANGO_GLYPH_UNKNOWN_FLAG; 212 glyph = PANGO_GLYPH_UNKNOWN_FLAG;
177 } 213 }
178 214
179 g = _pango_opengl_font_get_cache_glyph_data (font, glyph); 215 g = (glyph_info *)_pango_opengl_font_get_cache_glyph_data (font, glyph);
180 216
181 if (!g || g->generation != tc_generation) 217 if (!g || g->generation != tc_generation)
182 { 218 {
183 Glyph bm; 219 Glyph bm;
184 font_render_glyph (&bm, font, glyph); 220 font_render_glyph (&bm, font, glyph);
185 221
186 if (g) 222 if (!g)
187 g->generation = tc_generation;
188 else
189 { 223 {
190 g = g_slice_new (glyph_info); 224 g = g_slice_new (glyph_info);
191 225
192 _pango_opengl_font_set_glyph_cache_destroy (font, (GDestroyNotify)free_glyph_info); 226 _pango_opengl_font_set_glyph_cache_destroy (font, (GDestroyNotify)free_glyph_info);
193 _pango_opengl_font_set_cache_glyph_data (font, glyph, g); 227 _pango_opengl_font_set_cache_glyph_data (font, glyph, g);
194 } 228 }
195 229
196 tc_get (&g->tex, bm.width, bm.height); 230 g->generation = tc_generation;
197 231
198 g->left = bm.left; 232 g->left = bm.left;
199 g->top = bm.top; 233 g->top = bm.top;
200 234
201 glBindTexture (GL_TEXTURE_2D, g->tex.name); 235 tc_get (&g->tex, bm.width, bm.height);
202 glPixelStorei (GL_UNPACK_ROW_LENGTH, bm.stride); 236
203 glPixelStorei (GL_UNPACK_ALIGNMENT, 1); 237 if (bm.width && bm.height)
204 glTexSubImage2D (GL_TEXTURE_2D, 0, g->tex.x, g->tex.y, bm.width, bm.height, GL_ALPHA, GL_UNSIGNED_BYTE, bm.bitmap); 238 tex_update (g->tex.name, g->tex.x, g->tex.y, bm.width, bm.stride, bm.height, bm.bitmap);
205 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
206 glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
207 } 239 }
208 240
209 x += g->left; 241 x += g->left;
210 y -= g->top; 242 y -= g->top;
211 243
212 x1 = g->tex.x * (1. / TC_WIDTH );
213 y1 = g->tex.y * (1. / TC_HEIGHT);
214 x2 = g->tex.w * (1. / TC_WIDTH ) + x1;
215 y2 = g->tex.h * (1. / TC_HEIGHT) + y1;
216
217 if (g->tex.name != renderer->key.texname) 244 if (g->tex.name != renderer->key.texname)
218 { 245 {
219 renderer->key.texname = g->tex.name; 246 renderer->key.texname = g->tex.name;
220 renderer->arr = rc_array (renderer->rc, &renderer->key); 247 renderer->arr = rc_array (renderer->rc, &renderer->key);
221 } 248 }
222 249
223 rc_t2f_v3f (renderer->arr, x1, y1, x , y , 0); 250 rc_glyph (renderer->arr, g->tex.x, g->tex.y, g->tex.w, g->tex.h, x, y);
224 rc_t2f_v3f (renderer->arr, x2, y1, x + g->tex.w, y , 0);
225 rc_t2f_v3f (renderer->arr, x2, y2, x + g->tex.w, y + g->tex.h, 0);
226 rc_t2f_v3f (renderer->arr, x1, y2, x , y + g->tex.h, 0);
227} 251}
228 252
229static void 253static void
230draw_trapezoid (PangoRenderer *renderer_, 254draw_trapezoid (PangoRenderer *renderer_,
231 PangoRenderPart part, 255 PangoRenderPart part,
285 int x, int y, 309 int x, int y,
286 float r, float g, float b, float a, 310 float r, float g, float b, float a,
287 int flags) 311 int flags)
288{ 312{
289 pango_opengl_render_layout_subpixel ( 313 pango_opengl_render_layout_subpixel (
290 layout, rc, x * PANGO_SCALE, y * PANGO_SCALE, r, g, b, a, flags 314 layout, rc, x * PANGO_SCALE, y * PANGO_SCALE, r, g, b, a, flags
291 ); 315 );
292} 316}
293 317
294static void 318static void
295pango_opengl_renderer_init (PangoOpenGLRenderer *renderer) 319pango_opengl_renderer_init (PangoOpenGLRenderer *renderer)
312 336
313 renderer->underline = PANGO_UNDERLINE_NONE; 337 renderer->underline = PANGO_UNDERLINE_NONE;
314 renderer->strikethrough = FALSE; 338 renderer->strikethrough = FALSE;
315 339
316 gl->key.mode = GL_QUADS; 340 gl->key.mode = GL_QUADS;
317 gl->key.format = GL_T2F_V3F; 341 gl->key.format = 0; // glyphs
318 gl->key.texname = 0; 342 gl->key.texname = 0;
319 343
320 for (l = run->item->analysis.extra_attrs; l; l = l->next) 344 for (l = run->item->analysis.extra_attrs; l; l = l->next)
321 { 345 {
322 PangoAttribute *attr = l->data; 346 PangoAttribute *attr = (PangoAttribute *)l->data;
323 347
324 switch (attr->klass->type) 348 switch (attr->klass->type)
325 { 349 {
326 case PANGO_ATTR_UNDERLINE: 350 case PANGO_ATTR_UNDERLINE:
327 renderer->underline = ((PangoAttrInt *)attr)->value; 351 renderer->underline = (PangoUnderline)((PangoAttrInt *)attr)->value;
328 break; 352 break;
329 353
330 case PANGO_ATTR_STRIKETHROUGH: 354 case PANGO_ATTR_STRIKETHROUGH:
331 renderer->strikethrough = ((PangoAttrInt *)attr)->value; 355 renderer->strikethrough = ((PangoAttrInt *)attr)->value;
332 break; 356 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines