From ad4cbf36bc1cff3a20e636e535b51a84ecc6c8a8 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 14 Jun 2014 06:00:20 +0200 Subject: [PATCH] (XDK D3D) Split up more code into render_chain_xdk.cpp --- xdk/render_chain_xdk.cpp | 105 +++++++++++++++++++++++++++++++++++++++ xdk/xdk_d3d.cpp | 105 --------------------------------------- 2 files changed, 105 insertions(+), 105 deletions(-) diff --git a/xdk/render_chain_xdk.cpp b/xdk/render_chain_xdk.cpp index c0625a68af..c82e92ffbd 100644 --- a/xdk/render_chain_xdk.cpp +++ b/xdk/render_chain_xdk.cpp @@ -19,6 +19,111 @@ static void renderchain_set_vertices(void *data, unsigned pass, unsigned width, } #endif +static void renderchain_clear(void *data) +{ + d3d_video_t *d3d = (d3d_video_t*)data; + + if (d3d->tex) + d3d->tex->Release(); + d3d->tex = NULL; + if (d3d->vertex_buf) + d3d->vertex_buf->Release(); + d3d->vertex_buf = NULL; + +#ifdef _XBOX360 + if (d3d->vertex_decl) + d3d->vertex_decl->Release(); + d3d->vertex_decl = NULL; +#endif +} + +static void renderchain_free(void *data) +{ + d3d_video_t *chain = (d3d_video_t*)data; + + renderchain_clear(chain); + //renderchain_destroy_stock_shader(chain); +#ifndef DONT_HAVE_STATE_TRACKER + if (chain->tracker) + state_tracker_free(chain->tracker); +#endif +} + +bool renderchain_init_shader_fvf(void *data, void *pass_) +{ + d3d_video_t *chain = (d3d_video_t*)data; + d3d_video_t *pass = (d3d_video_t*)data; + LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev; + +#if defined(_XBOX360) + static const D3DVERTEXELEMENT VertexElements[] = + { + { 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, + { 0, 2 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, + D3DDECL_END() + }; + + if (FAILED(d3dr->CreateVertexDeclaration(VertexElements, &pass->vertex_decl))) + return false; +#endif + + return true; +} + +static bool renderchain_create_first_pass(void *data, const video_info_t *info) +{ + HRESULT ret; + d3d_video_t *chain = (d3d_video_t*)data; + LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev; + + ret = D3DDevice_CreateVertexBuffers(d3dr, 4 * sizeof(Vertex), + D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &chain->vertex_buf, NULL); + + if (FAILED(ret)) + return false; + + ret = d3dr->CreateTexture(chain->tex_w, chain->tex_h, 1, 0, info->rgb32 ? D3DFMT_LIN_X8R8G8B8 : D3DFMT_LIN_R5G6B5, + 0, &chain->tex +#ifdef _XBOX360 + , NULL +#endif + ); + + if (FAILED(ret)) + return false; + +#ifdef _XBOX1 + d3dr->SetRenderState(D3DRS_LIGHTING, FALSE); +#endif + d3dr->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); + d3dr->SetRenderState(D3DRS_ZENABLE, FALSE); + + if (!renderchain_init_shader_fvf(chain, chain)) + return false; + + return true; +} + + +static bool renderchain_init(void *data, const video_info_t *info) +{ + d3d_video_t *chain = (d3d_video_t*)data; + LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev; + + chain->pixel_size = info->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); + + if (!renderchain_create_first_pass(chain, info)) + return false; + + if (g_extern.console.screen.viewports.custom_vp.width == 0) + g_extern.console.screen.viewports.custom_vp.width = chain->screen_width; + + if (g_extern.console.screen.viewports.custom_vp.height == 0) + g_extern.console.screen.viewports.custom_vp.height = chain->screen_height; + + return true; +} + static void renderchain_render_pass(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, unsigned rotation) { d3d_video_t *d3d = (d3d_video_t*)data; diff --git a/xdk/xdk_d3d.cpp b/xdk/xdk_d3d.cpp index 442d8272bb..7e8f525e36 100644 --- a/xdk/xdk_d3d.cpp +++ b/xdk/xdk_d3d.cpp @@ -87,36 +87,6 @@ void d3d_deinit_shader(void *data) } #endif -static void renderchain_clear(void *data) -{ - d3d_video_t *d3d = (d3d_video_t*)data; - - if (d3d->tex) - d3d->tex->Release(); - d3d->tex = NULL; - if (d3d->vertex_buf) - d3d->vertex_buf->Release(); - d3d->vertex_buf = NULL; - -#ifdef _XBOX360 - if (d3d->vertex_decl) - d3d->vertex_decl->Release(); - d3d->vertex_decl = NULL; -#endif -} - -static void renderchain_free(void *data) -{ - d3d_video_t *chain = (d3d_video_t*)data; - - renderchain_clear(chain); - //renderchain_destroy_stock_shader(chain); -#ifndef DONT_HAVE_STATE_TRACKER - if (chain->tracker) - state_tracker_free(chain->tracker); -#endif -} - static void d3d_deinit_chain(void *data) { d3d_video_t *d3d = (d3d_video_t*)data; @@ -221,81 +191,6 @@ static bool d3d_set_shader(void *data, enum rarch_shader_type type, const char * return true; } -bool renderchain_init_shader_fvf(void *data, void *pass_) -{ - d3d_video_t *chain = (d3d_video_t*)data; - d3d_video_t *pass = (d3d_video_t*)data; - LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev; - -#if defined(_XBOX360) - static const D3DVERTEXELEMENT VertexElements[] = - { - { 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, - { 0, 2 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, - D3DDECL_END() - }; - - if (FAILED(d3dr->CreateVertexDeclaration(VertexElements, &pass->vertex_decl))) - return false; -#endif - - return true; -} - -static bool renderchain_create_first_pass(void *data, const video_info_t *info) -{ - HRESULT ret; - d3d_video_t *chain = (d3d_video_t*)data; - LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev; - - ret = D3DDevice_CreateVertexBuffers(d3dr, 4 * sizeof(Vertex), - D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &chain->vertex_buf, NULL); - - if (FAILED(ret)) - return false; - - ret = d3dr->CreateTexture(chain->tex_w, chain->tex_h, 1, 0, info->rgb32 ? D3DFMT_LIN_X8R8G8B8 : D3DFMT_LIN_R5G6B5, - 0, &chain->tex -#ifdef _XBOX360 - , NULL -#endif - ); - - if (FAILED(ret)) - return false; - -#ifdef _XBOX1 - d3dr->SetRenderState(D3DRS_LIGHTING, FALSE); -#endif - d3dr->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - d3dr->SetRenderState(D3DRS_ZENABLE, FALSE); - - if (!renderchain_init_shader_fvf(chain, chain)) - return false; - - return true; -} - - -static bool renderchain_init(void *data, const video_info_t *info) -{ - d3d_video_t *chain = (d3d_video_t*)data; - LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev; - - chain->pixel_size = info->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); - - if (!renderchain_create_first_pass(chain, info)) - return false; - - if (g_extern.console.screen.viewports.custom_vp.width == 0) - g_extern.console.screen.viewports.custom_vp.width = chain->screen_width; - - if (g_extern.console.screen.viewports.custom_vp.height == 0) - g_extern.console.screen.viewports.custom_vp.height = chain->screen_height; - - return true; -} - static bool d3d_init_chain(void *data, const video_info_t *info) { d3d_video_t *d3d = (d3d_video_t*)data;