--- deliantra/Deliantra-Client/pango-render.c 2008/01/13 08:22:33 1.14 +++ deliantra/Deliantra-Client/pango-render.c 2009/12/21 23:52:34 1.18 @@ -161,6 +161,43 @@ g_slice_free (glyph_info, g); } +static int apple_nvidia_bug_workaround; + +static void +apple_nvidia_bug (int enable) +{ + apple_nvidia_bug_workaround = enable; +} + +static void +tex_update (int name, int x, int y, int w, int stride, int h, void *bm) +{ + glBindTexture (GL_TEXTURE_2D, name); + + if (!apple_nvidia_bug_workaround) + { + glPixelStorei (GL_UNPACK_ROW_LENGTH, stride); + /*glPixelStorei (GL_UNPACK_ALIGNMENT, 1); expected cfplus default */ + glTexSubImage2D (GL_TEXTURE_2D, 0, x, y, w, h, GL_ALPHA, GL_UNSIGNED_BYTE, bm); + /*glPixelStorei (GL_UNPACK_ALIGNMENT, 4);*/ + glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); + } + else + { + /* starting with 10.5.5 (or 10.5.6), pple's nvidia driver corrupts textures */ + /* when glTexSubImage is used, so do it the horribly slow way, */ + /* reading/patching/uploading the full texture one each change */ + int r; + + glGetTexImage (GL_TEXTURE_2D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tc_temptile); + + for (r = 0; r < h; ++r) + memcpy (tc_temptile + (y + r) * TC_WIDTH + x, (char *)bm + r * stride, w); + + glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tc_temptile); + } +} + static void draw_glyph (PangoRenderer *renderer_, PangoFont *font, PangoGlyph glyph, double x, double y) { @@ -191,20 +228,14 @@ } g->generation = tc_generation; - tc_get (&g->tex, bm.width, bm.height); g->left = bm.left; g->top = bm.top; + tc_get (&g->tex, bm.width, bm.height); + if (bm.width && bm.height) - { - glBindTexture (GL_TEXTURE_2D, g->tex.name); - glPixelStorei (GL_UNPACK_ROW_LENGTH, bm.stride); - glPixelStorei (GL_UNPACK_ALIGNMENT, 1); - glTexSubImage2D (GL_TEXTURE_2D, 0, g->tex.x, g->tex.y, bm.width, bm.height, GL_ALPHA, GL_UNSIGNED_BYTE, bm.bitmap); - glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei (GL_UNPACK_ALIGNMENT, 4); - } + tex_update (g->tex.name, g->tex.x, g->tex.y, bm.width, bm.stride, bm.height, bm.bitmap); } x += g->left; @@ -280,7 +311,7 @@ int flags) { pango_opengl_render_layout_subpixel ( - layout, rc, x * PANGO_SCALE, y * PANGO_SCALE, r, g, b, a, flags + layout, rc, x * PANGO_SCALE, y * PANGO_SCALE, r, g, b, a, flags ); }