diff --git a/Makefile b/Makefile
index b59085c929..7bd725ba55 100644
--- a/Makefile
+++ b/Makefile
@@ -162,7 +162,7 @@ ifeq ($(HAVE_SDL), 1)
endif
ifeq ($(HAVE_OPENGL), 1)
- OBJ += gfx/gl.o gfx/gfx_context.o gfx/fonts/gl_font.o gfx/math/matrix.o
+ OBJ += gfx/gl.o gfx/gfx_context.o gfx/gl_font.o gfx/fonts/gl_font.o gfx/math/matrix.o
ifeq ($(HAVE_KMS), 1)
OBJ += gfx/context/drm_egl_ctx.o
diff --git a/gfx/fonts/gl_font.c b/gfx/fonts/gl_font.c
index af7ecc0a77..f8e6b17186 100644
--- a/gfx/fonts/gl_font.c
+++ b/gfx/fonts/gl_font.c
@@ -16,10 +16,10 @@
#include "../gl_common.h"
-void gl_init_font(void *data, const char *font_path, unsigned font_size)
+static bool gl_init_font(void *data, const char *font_path, unsigned font_size)
{
if (!g_settings.video.font_enable)
- return;
+ return false;
gl_t *gl = (gl_t*)data;
@@ -34,7 +34,10 @@ void gl_init_font(void *data, const char *font_path, unsigned font_size)
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
}
else
+ {
RARCH_WARN("Couldn't init font renderer.\n");
+ return false;
+ }
for (unsigned i = 0; i < 4; i++)
{
@@ -50,6 +53,8 @@ void gl_init_font(void *data, const char *font_path, unsigned font_size)
gl->font_color_dark[4 * i + j] = 0.3 * gl->font_color[4 * i + j];
gl->font_color_dark[4 * i + 3] = 1.0;
}
+
+ return true;
}
void gl_deinit_font(void *data)
@@ -291,7 +296,7 @@ static void setup_font(void *data, const char *msg, GLfloat scale, GLfloat pos_x
gl_set_projection(gl, &ortho, true);
}
-void gl_render_msg(void *data, const char *msg)
+static void gl_render_msg(void *data, const char *msg)
{
(void)data;
(void)msg;
@@ -302,7 +307,7 @@ void gl_render_msg(void *data, const char *msg)
g_settings.video.msg_pos_x, g_settings.video.msg_pos_y);
}
-void gl_render_msg_place(void *data, float pos_x, float pos_y, float scale, uint32_t color, const char *msg)
+static void gl_render_msg_place(void *data, float pos_x, float pos_y, float scale, uint32_t color, const char *msg)
{
(void)data;
(void)msg;
@@ -312,3 +317,12 @@ void gl_render_msg_place(void *data, float pos_x, float pos_y, float scale, uint
setup_font(data, msg, scale, pos_x, pos_y);
#endif
}
+
+const gl_font_renderer_t gl_raster_font = {
+ gl_init_font,
+ gl_deinit_font,
+ gl_render_msg,
+ gl_render_msg_place,
+ "GL raster",
+};
+
diff --git a/gfx/gl.c b/gfx/gl.c
index 3a9b54c917..861ab0af01 100644
--- a/gfx/gl.c
+++ b/gfx/gl.c
@@ -1174,12 +1174,13 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
{
char fps_txt[128];
gfx_fps_title(fps_txt, sizeof(fps_txt));
- gl_render_msg_place(gl, g_settings.video.msg_pos_x, 0.56f, 1.04f, WHITE, fps_txt);
+ if (gl->font_ctx)
+ gl->font_ctx->render_msg_place(gl, g_settings.video.msg_pos_x, 0.56f, 1.04f, WHITE, fps_txt);
}
#endif
- if (msg)
- gl_render_msg(gl, msg);
+ if (msg && gl->font_ctx)
+ gl->font_ctx->render_msg(gl, msg);
#if !defined(RARCH_CONSOLE)
context_update_window_title_func(false);
@@ -1223,7 +1224,8 @@ static void gl_free(void *data)
gl_t *gl = (gl_t*)data;
- gl_deinit_font(gl);
+ if (gl->font_ctx)
+ gl->font_ctx->deinit(gl);
gl_shader_deinit(gl);
#ifndef NO_GL_FF_VERTEX
@@ -1541,7 +1543,8 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
gl_init_textures_data(gl);
context_input_driver_func(input, input_data);
- gl_init_font(gl, g_settings.video.font_path, g_settings.video.font_size);
+
+ gl->font_ctx = gl_font_init_first(gl, g_settings.video.font_path, g_settings.video.font_size);
gl_init_pbo_readback(gl);
diff --git a/gfx/gl_common.h b/gfx/gl_common.h
index 447c742f42..9e514bc0f1 100644
--- a/gfx/gl_common.h
+++ b/gfx/gl_common.h
@@ -21,6 +21,7 @@
#include "math/matrix.h"
#include "gfx_context.h"
#include "scaler/scaler.h"
+#include "gl_font.h"
#ifdef HAVE_CONFIG_H
#include "../config.h"
@@ -266,6 +267,7 @@ typedef struct gl
// Fonts
void *font;
+ const gl_font_renderer_t *font_ctx;
const font_renderer_driver_t *font_driver;
GLuint font_tex;
int font_tex_w, font_tex_h;
diff --git a/gfx/gl_font.c b/gfx/gl_font.c
new file mode 100644
index 0000000000..31a42c3042
--- /dev/null
+++ b/gfx/gl_font.c
@@ -0,0 +1,33 @@
+/* RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2012 - Hans-Kristian Arntzen
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+
+#include "gl_font.h"
+#include "../general.h"
+
+static const gl_font_renderer_t *backends[] = {
+ &gl_raster_font,
+};
+
+const gl_font_renderer_t *gl_font_init_first(void *data, const char *font_path, unsigned font_size)
+{
+ for (unsigned i = 0; i < ARRAY_SIZE(backends); i++)
+ {
+ if (backends[i]->init(data, font_path, font_size))
+ return backends[i];
+ }
+
+ return NULL;
+}
+
diff --git a/gfx/gl_font.h b/gfx/gl_font.h
index 32c5697279..0fb4b0794a 100644
--- a/gfx/gl_font.h
+++ b/gfx/gl_font.h
@@ -16,12 +16,23 @@
#ifndef GL_FONT_H__
#define GL_FONT_H__
-#include "gl_common.h"
+#include
+#include "../boolean.h"
-void gl_init_font(void *data, const char *font_path, unsigned font_size);
-void gl_deinit_font(void *data);
-void gl_render_msg(void *data, const char *msg);
-void gl_render_msg_place(void *data, float x, float y, float scale, uint32_t color, const char *msg);
+typedef struct gl_font_renderer
+{
+ bool (*init)(void *data, const char *font_path, unsigned font_size);
+ void (*deinit)(void *data);
+ void (*render_msg)(void *data, const char *msg);
+ void (*render_msg_place)(void *data, float x, float y,
+ float scale, uint32_t color, const char *msg);
+ const char *ident;
+} gl_font_renderer_t;
+
+extern const gl_font_renderer_t gl_raster_font;
+
+const gl_font_renderer_t *gl_font_init_first(void *data,
+ const char *font_path, unsigned font_size);
#endif