From bdc97fd5c3c8b66888a649b790e3e2a9614e6282 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 6 Apr 2015 21:32:49 +0200 Subject: [PATCH] (D3D) Combine deinit functions into one --- gfx/d3d/d3d.cpp | 4 --- gfx/d3d/render_chain_cg.cpp | 48 ++++++++++++++++++----------------- gfx/d3d/render_chain_driver.h | 2 -- gfx/d3d/render_chain_null.cpp | 6 ----- gfx/d3d/render_chain_xdk.cpp | 24 ++++++++++-------- 5 files changed, 38 insertions(+), 46 deletions(-) diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index 29662f0078..8d6bb63fb4 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -96,11 +96,7 @@ static unsigned monitor_count; static void d3d_deinit_chain(d3d_video_t *d3d) { - d3d->renderchain_driver->deinit_shader(); - d3d->renderchain_driver->deinit(d3d->renderchain_data); -#ifdef _XBOX d3d->renderchain_driver->chain_free(d3d); -#endif d3d->renderchain_driver = NULL; d3d->renderchain_data = NULL; diff --git a/gfx/d3d/render_chain_cg.cpp b/gfx/d3d/render_chain_cg.cpp index b74272cc0d..7d7a0e89ca 100644 --- a/gfx/d3d/render_chain_cg.cpp +++ b/gfx/d3d/render_chain_cg.cpp @@ -247,7 +247,7 @@ static void renderchain_set_shaders(void *data, void *fragment_data, void *verte cgD3D9BindProgram(*vPrg); } -static void renderchain_destroy_stock_shader(void *data) +static void cg_d3d9_renderchain_destroy_stock_shader(void *data) { cg_renderchain_t *chain = (cg_renderchain_t*)data; @@ -708,7 +708,7 @@ static void renderchain_bind_pass(void *data, void *pass_data, unsigned pass_ind } } -static void renderchain_clear(void *data) +static void cg_d3d9_renderchain_clear(void *data) { unsigned i; cg_renderchain_t *chain = (cg_renderchain_t*)data; @@ -741,6 +741,25 @@ static void renderchain_clear(void *data) chain->luts.clear(); } +static void cg_d3d9_renderchain_deinit_shader(void) +{ + if (!cgCtx) + return; + + cgD3D9UnloadAllPrograms(); + cgD3D9SetDevice(NULL); + cgDestroyContext(cgCtx); + cgCtx = NULL; +} + +static void cg_d3d9_renderchain_deinit(void *data) +{ + cg_renderchain_t *renderchain = (cg_renderchain_t*)data; + + if (renderchain) + free(renderchain); +} + void cg_d3d9_renderchain_free(void *data) { cg_renderchain_t *chain = (cg_renderchain_t*)data; @@ -748,10 +767,12 @@ void cg_d3d9_renderchain_free(void *data) if (!chain) return; - renderchain_clear(chain); - renderchain_destroy_stock_shader(chain); + cg_d3d9_renderchain_deinit_shader(); + cg_d3d9_renderchain_clear(chain); + cg_d3d9_renderchain_destroy_stock_shader(chain); if (chain->tracker) state_tracker_free(chain->tracker); + cg_d3d9_renderchain_deinit(); } void *cg_d3d9_renderchain_new(void) @@ -763,16 +784,6 @@ void *cg_d3d9_renderchain_new(void) return renderchain; } -static void cg_d3d9_renderchain_deinit_shader(void) -{ - if (!cgCtx) - return; - - cgD3D9UnloadAllPrograms(); - cgD3D9SetDevice(NULL); - cgDestroyContext(cgCtx); - cgCtx = NULL; -} static bool cg_d3d9_renderchain_init_shader(void *data) { @@ -793,13 +804,6 @@ static bool cg_d3d9_renderchain_init_shader(void *data) return true; } -static void cg_d3d9_renderchain_deinit(void *data) -{ - cg_renderchain_t *renderchain = (cg_renderchain_t*)data; - - if (renderchain) - free(renderchain); -} static void renderchain_log_info(void *data, const void *info_data) { @@ -1485,8 +1489,6 @@ static bool cg_d3d9_renderchain_render(void *chain_data, const void *data, renderchain_driver_t cg_d3d9_renderchain = { cg_d3d9_renderchain_free, cg_d3d9_renderchain_new, - cg_d3d9_renderchain_deinit, - cg_d3d9_renderchain_deinit_shader, cg_d3d9_renderchain_init_shader, cg_d3d9_renderchain_init_shader_fvf, cg_d3d9_renderchain_init, diff --git a/gfx/d3d/render_chain_driver.h b/gfx/d3d/render_chain_driver.h index 7c6f6fce9a..4d9a13fc90 100644 --- a/gfx/d3d/render_chain_driver.h +++ b/gfx/d3d/render_chain_driver.h @@ -39,8 +39,6 @@ typedef struct renderchain_driver { void (*chain_free)(void *data); void *(*chain_new)(void); - void (*deinit)(void *data); - void (*deinit_shader)(void); bool (*init_shader)(void *data); bool (*init_shader_fvf)(void *data, void *pass_data); bool (*init)(void *data, diff --git a/gfx/d3d/render_chain_null.cpp b/gfx/d3d/render_chain_null.cpp index 3a9853c649..55c6d61a03 100644 --- a/gfx/d3d/render_chain_null.cpp +++ b/gfx/d3d/render_chain_null.cpp @@ -44,10 +44,6 @@ static void *null_renderchain_new(void) return renderchain; } -static void null_renderchain_deinit_shader(void) -{ -} - static bool null_renderchain_init_shader(void *data) { (void)data; @@ -146,8 +142,6 @@ static void null_renderchain_convert_geometry( renderchain_driver_t null_renderchain = { null_renderchain_free, null_renderchain_new, - null_renderchain_deinit, - null_renderchain_deinit_shader, null_renderchain_init_shader, null_renderchain_init_shader_fvf, null_renderchain_init, diff --git a/gfx/d3d/render_chain_xdk.cpp b/gfx/d3d/render_chain_xdk.cpp index 8037e28ecc..84a1ec666d 100644 --- a/gfx/d3d/render_chain_xdk.cpp +++ b/gfx/d3d/render_chain_xdk.cpp @@ -45,7 +45,7 @@ static void renderchain_set_mvp(void *data, unsigned vp_width, #endif } -static void renderchain_clear(void *data) +static void xdk_renderchain_clear(void *data) { d3d_video_t *d3d = (d3d_video_t*)data; @@ -227,6 +227,14 @@ static void renderchain_blit_to_texture(void *data, const void *frame, &d3dlr, frame, width, height, pitch); } +static void xdk_renderchain_deinit(void *data) +{ + xdk_renderchain_t *renderchain = (xdk_renderchain_t*)data; + + if (renderchain) + free(renderchain); +} + static void xdk_renderchain_free(void *data) { d3d_video_t *chain = (d3d_video_t*)data; @@ -234,7 +242,10 @@ static void xdk_renderchain_free(void *data) if (!chain) return; - renderchain_clear(chain); + xdk_renderchain_deinit_shader(chain); + xdk_renderchain_deinit(chain->renderchain_data); + xdk_renderchain_clear(chain); + #ifndef DONT_HAVE_STATE_TRACKER #ifndef _XBOX if (chain->tracker) @@ -243,13 +254,6 @@ static void xdk_renderchain_free(void *data) #endif } -void xdk_renderchain_deinit(void *data) -{ - xdk_renderchain_t *renderchain = (xdk_renderchain_t*)data; - - if (renderchain) - free(renderchain); -} void *xdk_renderchain_new(void) { @@ -413,8 +417,6 @@ static void xdk_renderchain_convert_geometry( renderchain_driver_t xdk_renderchain = { xdk_renderchain_free, xdk_renderchain_new, - xdk_renderchain_deinit, - xdk_renderchain_deinit_shader, xdk_renderchain_init_shader, xdk_renderchain_init_shader_fvf, xdk_renderchain_init,