From 1bcbaf5fbac5073a981ff5a1a4f5b46a2ee4ee6d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 9 Nov 2015 00:38:02 +0100 Subject: [PATCH] Add D3D support for video_texture_{load/unload} --- gfx/video_texture.c | 63 +++++++++++++++++++++++-- gfx/video_texture.h | 5 +- menu/drivers_display/menu_display_d3d.c | 4 +- menu/drivers_display/menu_display_gl.c | 2 +- 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/gfx/video_texture.c b/gfx/video_texture.c index bebe3afa5c..8788e3eee6 100644 --- a/gfx/video_texture.c +++ b/gfx/video_texture.c @@ -25,7 +25,7 @@ static void video_texture_png_load_gl(struct texture_image *ti, enum texture_filter_type filter_type, - unsigned *id) + uintptr_t *id) { /* Generate the OpenGL texture object */ glGenTextures(1, (GLuint*)id); @@ -38,11 +38,30 @@ static void video_texture_png_load_gl(struct texture_image *ti, } #endif +#ifdef HAVE_D3D +#include "d3d/d3d.h" + +static void video_texture_png_load_d3d(struct texture_image *ti, + enum texture_filter_type filter_type, + uintptr_t *id) +{ + d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(NULL); + + if (!d3d) + return; + + id = (uintptr_t*)d3d_texture_new(d3d->dev, NULL, + ti->width, ti->height, 1, + 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 0, 0, 0, + NULL, NULL); +} +#endif + static unsigned video_texture_png_load(void *data, enum texture_backend_type type, enum texture_filter_type filter_type) { - unsigned id = 0; + uintptr_t id = 0; if (!data) return 0; @@ -52,6 +71,11 @@ static unsigned video_texture_png_load(void *data, case TEXTURE_BACKEND_OPENGL: #ifdef HAVE_OPENGL video_texture_png_load_gl((struct texture_image*)data, filter_type, &id); +#endif + break; + case TEXTURE_BACKEND_DIRECT3D: +#ifdef HAVE_D3D + video_texture_png_load_d3d((struct texture_image*)data, filter_type, &id); #endif break; case TEXTURE_BACKEND_DEFAULT: @@ -80,6 +104,18 @@ static int video_texture_png_load_wrap_gl(void *data) TEXTURE_FILTER_LINEAR); } +static int video_texture_png_load_wrap_d3d_mipmap(void *data) +{ + return video_texture_png_load(data, TEXTURE_BACKEND_DIRECT3D, + TEXTURE_FILTER_MIPMAP_LINEAR); +} + +static int video_texture_png_load_wrap_d3d(void *data) +{ + return video_texture_png_load(data, TEXTURE_BACKEND_DIRECT3D, + TEXTURE_FILTER_LINEAR); +} + unsigned video_texture_load(void *data, enum texture_backend_type type, enum texture_filter_type filter_type) @@ -106,6 +142,13 @@ unsigned video_texture_load(void *data, else pkt.data.custom_command.method = video_texture_png_load_wrap_gl; break; + case TEXTURE_BACKEND_DIRECT3D: + if (filter_type == TEXTURE_FILTER_MIPMAP_LINEAR || + filter_type == TEXTURE_FILTER_MIPMAP_NEAREST) + pkt.data.custom_command.method = video_texture_png_load_wrap_d3d_mipmap; + else + pkt.data.custom_command.method = video_texture_png_load_wrap_d3d; + break; case TEXTURE_BACKEND_DEFAULT: default: pkt.data.custom_command.method = video_texture_png_load_wrap; @@ -131,9 +174,21 @@ static void video_texture_gl_unload(uintptr_t *id) } #endif -void video_texture_unload(uintptr_t *id) +void video_texture_unload(enum texture_backend_type type, uintptr_t *id) { + switch (type) + { + case TEXTURE_BACKEND_OPENGL: #ifdef HAVE_OPENGL - video_texture_gl_unload(id); + video_texture_gl_unload(id); #endif + break; + case TEXTURE_BACKEND_DIRECT3D: +#ifdef HAVE_D3D + d3d_texture_free((LPDIRECT3DTEXTURE)id); +#endif + break; + case TEXTURE_BACKEND_DEFAULT: + break; + } } diff --git a/gfx/video_texture.h b/gfx/video_texture.h index fd082cd34f..d26e02d391 100644 --- a/gfx/video_texture.h +++ b/gfx/video_texture.h @@ -22,7 +22,8 @@ enum texture_backend_type { TEXTURE_BACKEND_DEFAULT = 0, - TEXTURE_BACKEND_OPENGL + TEXTURE_BACKEND_OPENGL, + TEXTURE_BACKEND_DIRECT3D }; #ifdef __cplusplus @@ -33,7 +34,7 @@ unsigned video_texture_load(void *data, enum texture_backend_type type, enum texture_filter_type filter_type); -void video_texture_unload(uintptr_t *id); +void video_texture_unload(enum texture_backend_type type, uintptr_t *id); #ifdef __cplusplus } diff --git a/menu/drivers_display/menu_display_d3d.c b/menu/drivers_display/menu_display_d3d.c index 3f2296b0e2..44436cd8a1 100644 --- a/menu/drivers_display/menu_display_d3d.c +++ b/menu/drivers_display/menu_display_d3d.c @@ -219,14 +219,14 @@ static void menu_display_d3d_clear_color(float r, float g, float b, float a) static unsigned menu_display_d3d_texture_load(void *data, enum texture_filter_type type) { - return video_texture_load(data, TEXTURE_BACKEND_OPENGL, type); + return video_texture_load(data, TEXTURE_BACKEND_DIRECT3D, type); } static void menu_display_d3d_texture_unload(uintptr_t *id) { if (!id) return; - video_texture_unload(id); + video_texture_unload(TEXTURE_BACKEND_DIRECT3D, id); } static const float *menu_display_d3d_get_tex_coords(void) diff --git a/menu/drivers_display/menu_display_gl.c b/menu/drivers_display/menu_display_gl.c index 96ca59d905..417c28838a 100644 --- a/menu/drivers_display/menu_display_gl.c +++ b/menu/drivers_display/menu_display_gl.c @@ -199,7 +199,7 @@ static void menu_display_gl_texture_unload(uintptr_t *id) { if (!id) return; - video_texture_unload(id); + video_texture_unload(TEXTURE_BACKEND_OPENGL, id); } static const float *menu_display_gl_get_tex_coords(void)