diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 0969b28018..e7bc4bfb39 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -47,11 +47,6 @@ #include "shader_glsl.h" #endif - -#ifdef HAVE_FREETYPE -#include "fonts.h" -#endif - // Used for the last pass when rendering to the back buffer. static const GLfloat vertexes_flipped[] = { 0, 0, @@ -155,17 +150,6 @@ typedef struct gl GLenum texture_type; // XBGR1555 or ARGB GLenum texture_fmt; unsigned base_size; // 2 or 4 - -#ifdef HAVE_FREETYPE - font_renderer_t *font; - GLuint font_tex; - int font_tex_w, font_tex_h; - void *font_tex_empty_buf; - char font_last_msg[256]; - int font_last_width, font_last_height; - GLfloat font_color[16]; -#endif - } gl_t; ////////////////// Shaders @@ -320,51 +304,6 @@ static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) #endif /////////////////// -//////////////// Message rendering -static inline void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) -{ -#ifdef HAVE_FREETYPE - if (!g_settings.video.font_enable) - return; - - const char *path = font_path; - if (!*path) - path = font_renderer_get_default_font(); - - if (path) - { - gl->font = font_renderer_new(path, font_size); - if (gl->font) - { - glGenTextures(1, &gl->font_tex); - glBindTexture(GL_TEXTURE_2D, gl->font_tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - } - else - SSNES_WARN("Couldn't init font renderer with font \"%s\"...\n", font_path); - } - else - SSNES_LOG("Did not find default font.\n"); - - for (unsigned i = 0; i < 4; i++) - { - gl->font_color[4 * i + 0] = g_settings.video.msg_color_r; - gl->font_color[4 * i + 1] = g_settings.video.msg_color_g; - gl->font_color[4 * i + 2] = g_settings.video.msg_color_b; - gl->font_color[4 * i + 3] = 1.0; - } - -#else - (void)gl; - (void)font_path; - (void)font_size; -#endif -} - // Horribly long and complex FBO init :D static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) { @@ -545,23 +484,6 @@ error: #endif } -static inline void gl_deinit_font(gl_t *gl) -{ -#ifdef HAVE_FREETYPE - if (gl->font) - { - font_renderer_free(gl->font); - glDeleteTextures(1, &gl->font_tex); - - if (gl->font_tex_empty_buf) - free(gl->font_tex_empty_buf); - } -#else - (void)gl; -#endif -} -//////////// - static inline unsigned get_alignment(unsigned pitch) { if (pitch & 1) @@ -624,192 +546,6 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_f //SSNES_LOG("Setting viewport @ %ux%u\n", width, height); } -#ifdef HAVE_FREETYPE - -// Somewhat overwhelming code just to render some damn fonts. -// We aim to use NPOT textures for compatibility with old and shitty cards. -// Also, we want to avoid reallocating a texture for each glyph (performance dips), so we -// contruct the whole texture using one call, and copy straight to it with -// glTexSubImage. - -struct font_rect -{ - int x, y; - int width, height; - int pot_width, pot_height; -}; - -static void calculate_msg_geometry(const struct font_output *head, struct font_rect *rect) -{ - int x_min = head->off_x; - int x_max = head->off_x + head->width; - int y_min = head->off_y; - int y_max = head->off_y + head->height; - - while ((head = head->next)) - { - int left = head->off_x; - int right = head->off_x + head->width; - int bottom = head->off_y; - int top = head->off_y + head->height; - - if (left < x_min) - x_min = left; - if (right > x_max) - x_max = right; - - if (bottom < y_min) - y_min = bottom; - if (top > y_max) - y_max = top; - } - - rect->x = x_min; - rect->y = y_min; - rect->width = x_max - x_min; - rect->height = y_max - y_min; -} - -static void adjust_power_of_two(gl_t *gl, struct font_rect *geom) -{ - // Some systems really hate NPOT textures. - geom->pot_width = next_pow2(geom->width); - geom->pot_height = next_pow2(geom->height); - - if ((geom->pot_width > gl->font_tex_w) || (geom->pot_height > gl->font_tex_h)) - { - gl->font_tex_empty_buf = realloc(gl->font_tex_empty_buf, geom->pot_width * geom->pot_height); - memset(gl->font_tex_empty_buf, 0, geom->pot_width * geom->pot_height); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 8); - glPixelStorei(GL_UNPACK_ROW_LENGTH, geom->pot_width); - glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY8, geom->pot_width, geom->pot_height, - 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, gl->font_tex_empty_buf); - - gl->font_tex_w = geom->pot_width; - gl->font_tex_h = geom->pot_height; - } -} - -// Old style "blitting", so we can render all the fonts in one go. -// TODO: Is it possible that fonts could overlap if we blit without alpha blending? -static void blit_fonts(gl_t *gl, const struct font_output *head, const struct font_rect *geom) -{ - // Clear out earlier fonts. - glPixelStorei(GL_UNPACK_ALIGNMENT, 8); - glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->font_tex_w); - glTexSubImage2D(GL_TEXTURE_2D, - 0, 0, 0, gl->font_tex_w, gl->font_tex_h, - GL_LUMINANCE, GL_UNSIGNED_BYTE, gl->font_tex_empty_buf); - - while (head) - { - // head has top-left oriented coords. - int x = head->off_x - geom->x; - int y = head->off_y - geom->y; - y = gl->font_tex_h - head->height - y - 1; - - glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(head->pitch)); - glPixelStorei(GL_UNPACK_ROW_LENGTH, head->pitch); - glTexSubImage2D(GL_TEXTURE_2D, - 0, x, y, head->width, head->height, - GL_LUMINANCE, GL_UNSIGNED_BYTE, head->output); - - head = head->next; - } -} - -static void calculate_font_coords(gl_t *gl, - GLfloat font_vertex[8], GLfloat font_tex_coords[8]) -{ - GLfloat lx = g_settings.video.msg_pos_x; - GLfloat hx = (GLfloat)gl->font_last_width / gl->vp_width + lx; - GLfloat ly = g_settings.video.msg_pos_y; - GLfloat hy = (GLfloat)gl->font_last_height / gl->vp_height + ly; - - font_vertex[0] = lx; - font_vertex[1] = ly; - font_vertex[2] = lx; - font_vertex[3] = hy; - font_vertex[4] = hx; - font_vertex[5] = hy; - font_vertex[6] = hx; - font_vertex[7] = ly; - - lx = 0.0f; - hx = (GLfloat)gl->font_last_width / gl->font_tex_w; - ly = 1.0f - (GLfloat)gl->font_last_height / gl->font_tex_h; - hy = 1.0f; - - font_tex_coords[0] = lx; - font_tex_coords[1] = hy; - font_tex_coords[2] = lx; - font_tex_coords[3] = ly; - font_tex_coords[4] = hx; - font_tex_coords[5] = ly; - font_tex_coords[6] = hx; - font_tex_coords[7] = hy; -} - -static void gl_render_msg(gl_t *gl, const char *msg) -{ - if (!gl->font) - return; - - GLfloat font_vertex[8]; - GLfloat font_tex_coords[8]; - - // Deactivate custom shaders. Enable the font texture. - gl_shader_use(0); - set_viewport(gl, gl->win_width, gl->win_height, false); - glBindTexture(GL_TEXTURE_2D, gl->font_tex); - glVertexPointer(2, GL_FLOAT, 0, font_vertex); - glTexCoordPointer(2, GL_FLOAT, 0, font_tex_coords); - glColorPointer(4, GL_FLOAT, 0, gl->font_color); - - // Need blending. - // Using fixed function pipeline here since we cannot guarantee presence of shaders (would be kinda overkill anyways). - glEnable(GL_BLEND); - - struct font_output_list out; - - // If we get the same message, there's obviously no need to render fonts again ... - if (strcmp(gl->font_last_msg, msg) != 0) - { - font_renderer_msg(gl->font, msg, &out); - struct font_output *head = out.head; - - struct font_rect geom; - calculate_msg_geometry(head, &geom); - adjust_power_of_two(gl, &geom); - blit_fonts(gl, head, &geom); - - font_renderer_free_output(&out); - strlcpy(gl->font_last_msg, msg, sizeof(gl->font_last_msg)); - - gl->font_last_width = geom.width; - gl->font_last_height = geom.height; - } - calculate_font_coords(gl, font_vertex, font_tex_coords); - - glDrawArrays(GL_QUADS, 0, 4); - - // Go back to old rendering path. - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); - glColorPointer(4, GL_FLOAT, 0, white_color); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - - glDisable(GL_BLEND); -} -#else -static void gl_render_msg(gl_t *gl, const char *msg) -{ - (void)gl; - (void)msg; -} -#endif - static inline void set_lut_texture_coords(const GLfloat *coords) { #if defined(HAVE_XML) || defined(HAVE_CG) @@ -1100,9 +836,6 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; #endif - if (msg) - gl_render_msg(gl, msg); - psglSwap(); return true; @@ -1131,7 +864,6 @@ static void gl_free(void *data) { gl_t *gl = data; - gl_deinit_font(gl); gl_shader_deinit(); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); @@ -1353,8 +1085,6 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords)); } - gl_init_font(gl, g_settings.video.font_path, g_settings.video.font_size); - if (!gl_check_error()) { psgl_deinit(gl);