From 4864adc7b1d6c58ecd416e1162abae911ffe59ee Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 15 Dec 2012 03:35:04 +0100 Subject: [PATCH] (XDK) Rewrote Xbox font code --- gfx/context/xdk_ctx.c | 7 ++--- gfx/fonts/{xdk360_fonts.h => d3d_font.c} | 28 ++++++++++++----- gfx/fonts/{xdk1_xfonts.h => d3d_font.h} | 26 ++++++++++++---- gfx/fonts/gl_font.c | 1 + gfx/fonts/xdk1_xfonts.c | 32 ++++++++++++++++---- gfx/fonts/xdk360_fonts.cpp | 38 +++++++++++++----------- xdk/xdk_d3d.cpp | 8 +---- 7 files changed, 93 insertions(+), 47 deletions(-) rename gfx/fonts/{xdk360_fonts.h => d3d_font.c} (61%) rename gfx/fonts/{xdk1_xfonts.h => d3d_font.h} (53%) diff --git a/gfx/context/xdk_ctx.c b/gfx/context/xdk_ctx.c index 010842366c..2977bfe4c6 100644 --- a/gfx/context/xdk_ctx.c +++ b/gfx/context/xdk_ctx.c @@ -32,12 +32,11 @@ #include "../../screenshot.h" +#include "../fonts/d3d_fonts.h" + #if defined(_XBOX1) -#include "../fonts/xdk1_xfonts.h" -// for Xbox 1 #define XBOX_PRESENTATIONINTERVAL D3DRS_PRESENTATIONINTERVAL -#else -// for Xbox 360 +#elif defined(_XBOX360) #define XBOX_PRESENTATIONINTERVAL D3DRS_PRESENTINTERVAL #endif diff --git a/gfx/fonts/xdk360_fonts.h b/gfx/fonts/d3d_font.c similarity index 61% rename from gfx/fonts/xdk360_fonts.h rename to gfx/fonts/d3d_font.c index 1e6ae01965..28dbb8a32c 100644 --- a/gfx/fonts/xdk360_fonts.h +++ b/gfx/fonts/d3d_font.c @@ -14,13 +14,25 @@ * If not, see . */ -#ifndef RARCH_360_FONTS_H -#define RARCH_360_FONTS_H - -HRESULT d3d9_init_font(const char *font_path); -void d3d9_deinit_font(void); - -void xdk_render_msg(void *driver, const char *str); -void xdk_render_msg_place(void *driver, float x, float y, const char *str_msg); +#include "d3d_font.h" +#include "../../general.h" +static const d3d_font_renderer_t *d3d_font_backends[] = { +#if defined(_XBOX1) + &d3d_xdk1_font, +#elif defined(_XBOX360 + &d3d_xbox360_font, #endif +}; + +const d3d_font_renderer_t *d3d_font_init_first(void *data, const char *font_path, unsigned font_size) +{ + for (unsigned i = 0; i < ARRAY_SIZE(d3d_font_backends); i++) + { + if (d3d_font_backends[i]->init(data, font_path, font_size)) + return d3d_font_backends[i]; + } + + return NULL; +} + diff --git a/gfx/fonts/xdk1_xfonts.h b/gfx/fonts/d3d_font.h similarity index 53% rename from gfx/fonts/xdk1_xfonts.h rename to gfx/fonts/d3d_font.h index a90c5be0b0..f62601b8fe 100644 --- a/gfx/fonts/xdk1_xfonts.h +++ b/gfx/fonts/d3d_font.h @@ -1,6 +1,5 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * Copyright (C) 2011-2012 - Daniel De Matteis * * 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- @@ -14,10 +13,27 @@ * If not, see . */ -#ifndef RARCH_XDK1_FONTS_H -#define RARCH_XDK1_FONTS_H +#ifndef GL_FONT_H__ +#define GL_FONT_H__ -void xfonts_deinit_font(void); -void xfonts_render_msg_place(void *data, float x, float y, float scale, const char *msg); +#include +#include "../../boolean.h" + +typedef struct d3d_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; +} d3d_font_renderer_t; + +extern const d3d_font_renderer_t d3d_xbox360_font; +extern const d3d_font_renderer_t d3d_xdk1_font; + +const d3d_font_renderer_t *d3d_font_init_first(void *data, + const char *font_path, unsigned font_size); #endif + diff --git a/gfx/fonts/gl_font.c b/gfx/fonts/gl_font.c index feadda24ec..8d9a227cb3 100644 --- a/gfx/fonts/gl_font.c +++ b/gfx/fonts/gl_font.c @@ -1,5 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis * * 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- diff --git a/gfx/fonts/xdk1_xfonts.c b/gfx/fonts/xdk1_xfonts.c index 70777296e4..05bdd93c9c 100644 --- a/gfx/fonts/xdk1_xfonts.c +++ b/gfx/fonts/xdk1_xfonts.c @@ -15,25 +15,45 @@ */ #include -#include "xdk1_xfonts.h" +#include "d3d_font.h" #include "../../general.h" -void xfonts_deinit_font(void) +static bool xfonts_init_font(void *data, const char *font_path, unsigned font_size) { + (void)data; + (void)font_path; + (void)font_size; + + return true; } -void xfonts_render_msg_place(void *data, float x, float y, float scale, const char *msg) +static void xfonts_deinit_font(void *data) +{ + (void)data; +} + +static void xfonts_render_msg(void *data, const char *msg) +{ + xfonts_render_msg_place(data, g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 0, msg); +} + +static void xfonts_render_msg_place(void *data, float x, float y, float scale, const char *msg) { xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data; d3d->d3d_render_device->GetBackBuffer(-1, D3DBACKBUFFER_TYPE_MONO, &d3d->pFrontBuffer); - //d3d->d3d_render_device->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &d3d->pBackBuffer); wchar_t str[256]; convert_char_to_wchar(str, msg, sizeof(str)); d3d->debug_font->TextOut(d3d->pFrontBuffer, str, (unsigned)-1, x, y); - //d3d->debug_font->TextOut(d3d->pBackBuffer, str, (unsigned)-1, x, y); d3d->pFrontBuffer->Release(); - //d3d->pBackBuffer->Release(); } + +const d3d_font_renderer_t d3d_xdk1_font = { + xfonts_init_font, + xfonts_deinit_font, + xfonts_render_msg, + xfonts_render_msg_place, + "XDK1 Xfonts", +}; diff --git a/gfx/fonts/xdk360_fonts.cpp b/gfx/fonts/xdk360_fonts.cpp index e1cb846f26..2403dc1af7 100644 --- a/gfx/fonts/xdk360_fonts.cpp +++ b/gfx/fonts/xdk360_fonts.cpp @@ -15,6 +15,7 @@ */ #include +#include "d3d_font.h" #include "../../general.h" #include "../../xdk/xdk_resources.h" @@ -175,7 +176,7 @@ static HRESULT xdk360_video_font_create_shaders (xdk360_video_font_t * font) return hr; } -HRESULT d3d9_init_font(const char *path) +static bool xdk_init_font(void *data, const char *font_path, unsigned font_size) { // Create the font xdk360_video_font_t *font = &m_Font; @@ -238,7 +239,7 @@ error: return E_FAIL; } -void d3d9_deinit_font(void) +static void xdk_deinit_font(void *data) { xdk360_video_font_t *font = &m_Font; @@ -261,18 +262,15 @@ void d3d9_deinit_font(void) void xdk_render_msg_post(xdk360_video_font_t * font) { - // Restore state - { - // Cache the global pointer into a register - xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; - D3DDevice *pD3dDevice = d3d->d3d_render_device; + // Cache the global pointer into a register + xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; + D3DDevice *pD3dDevice = d3d->d3d_render_device; - pD3dDevice->SetTexture(0, NULL); - pD3dDevice->SetVertexDeclaration(NULL); - D3DDevice_SetVertexShader(pD3dDevice, NULL ); - D3DDevice_SetPixelShader(pD3dDevice, NULL ); - pD3dDevice->SetRenderState( D3DRS_VIEWPORTENABLE, font->m_dwSavedState ); - } + pD3dDevice->SetTexture(0, NULL); + pD3dDevice->SetVertexDeclaration(NULL); + D3DDevice_SetVertexShader(pD3dDevice, NULL ); + D3DDevice_SetPixelShader(pD3dDevice, NULL ); + pD3dDevice->SetRenderState( D3DRS_VIEWPORTENABLE, font->m_dwSavedState ); } static void xdk_render_msg_pre(xdk360_video_font_t * font) @@ -430,7 +428,7 @@ static void xdk_video_font_draw_text(xdk360_video_font_t *font, pd3dDevice->EndVertices(); } -void xdk_render_msg_place(void *driver, float x, float y, const char *str_msg) +static void xdk_render_msg_place(void *driver, float x, float y, const char *str_msg) { xdk_d3d_video_t *vid = (xdk_d3d_video_t*)driver; @@ -445,14 +443,20 @@ void xdk_render_msg_place(void *driver, float x, float y, const char *str_msg) } } -void xdk_render_msg(void *driver, const char *str_msg) +static void xdk_render_msg(void *driver, const char *msg) { xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver; float x = g_extern.console.rmenu.state.rmenu_hd.enable ? 160 : 100; float y = 120; - xdk_render_msg_place(d3d, x, y, str_msg); + xdk_render_msg_place(d3d, x, y, msg); } - +const d3d_font_renderer_t d3d_xbox360_font = { + xdk_init_font, + xdk_deinit_font, + xdk_render_msg, + xdk_render_msg_place, + "Xbox 360 fonts", +}; diff --git a/xdk/xdk_d3d.cpp b/xdk/xdk_d3d.cpp index 3c33cda800..64a9238ad7 100644 --- a/xdk/xdk_d3d.cpp +++ b/xdk/xdk_d3d.cpp @@ -26,10 +26,6 @@ #include "../gfx/shader_hlsl.h" #endif -#ifdef _XBOX1 -#include "./../gfx/fonts/xdk1_xfonts.h" -#endif - #include "./../gfx/gfx_context.h" #include "../general.h" #include "../message.h" @@ -38,9 +34,7 @@ #include "config.h" #endif -#ifdef _XBOX360 -#include "../gfx/fonts/xdk360_fonts.h" -#endif +#include "../gfx/fonts/d3d_fonts.h" #include "../xdk/xdk_resources.h"