From f4f2ff386a00d7d54b6905dcb9021f523bf85a71 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Sat, 14 Apr 2012 22:05:56 +0200 Subject: [PATCH] (HLSL) D3D device ptr for shader_hlsl.c --- 360/xdk360_video.cpp | 6 +++--- gfx/shader_hlsl.c | 20 ++++++++++++++------ gfx/shader_hlsl.h | 6 +++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 37b6f252e9..59035bfa79 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -346,7 +346,7 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i // D3DCREATE_HARDWARE_VERTEXPROCESSING is ignored on 360 ret = Direct3D_CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &vid->d3dpp, &vid->xdk360_render_device); - hlsl_init(g_settings.video.cg_shader_path); + hlsl_init(g_settings.video.cg_shader_path, vid->xdk360_render_device); vid->lpTexture = (D3DTexture*) D3DDevice_CreateTexture(512, 512, 1, 1, 0, D3DFMT_LIN_X1R5G5B5, 0, D3DRTYPE_TEXTURE); @@ -434,8 +434,8 @@ static bool xdk360_gfx_frame(void *data, const void *frame, vid->last_height = height; } - hlsl_use(vid->xdk360_render_device, 0); - hlsl_set_params(vid->xdk360_render_device); + hlsl_use(0); + hlsl_set_params(); D3DLOCKED_RECT d3dlr; D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index c8557e9efb..52c9308816 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -32,6 +32,7 @@ struct hlsl_program XMMATRIX mvp; }; +static IDirect3DDevice9 * d3d_device_ptr; static struct hlsl_program prg[SSNES_HLSL_MAX_SHADERS] = {0}; static bool hlsl_active = false; static unsigned active_index = 0; @@ -76,12 +77,12 @@ void hlsl_set_proj_matrix(XMMATRIX rotation_value) prg[active_index].mvp = rotation_value; } -void hlsl_set_params(IDirect3DDevice9 * device) +void hlsl_set_params(void) { if (!hlsl_active) return; - device->SetVertexShaderConstantF(0, (FLOAT*)&prg[active_index].mvp, 4); + d3d_device_ptr->SetVertexShaderConstantF(0, (FLOAT*)&prg[active_index].mvp, 4); } static bool load_program(unsigned index, const char *prog, bool path_is_file) @@ -171,6 +172,8 @@ static void hlsl_deinit_state(void) { hlsl_active = false; + d3d_device_ptr = NULL; + hlsl_deinit_progs(); } @@ -179,8 +182,13 @@ static bool load_preset(const char *path) return false; } -bool hlsl_init(const char *path) +bool hlsl_init(const char *path, IDirect3DDevice9 * device_ptr) { + if (device_ptr != NULL) + d3d_device_ptr = device_ptr; + else + return false; + if (strstr(path, ".cgp")) { if (!load_preset(path)) @@ -197,13 +205,13 @@ bool hlsl_init(const char *path) return true; } -void hlsl_use(IDirect3DDevice9 * device, unsigned index) +void hlsl_use(unsigned index) { if (hlsl_active && prg[index].vprg && prg[index].fprg) { active_index = index; - D3DDevice_SetVertexShader(device, prg[index].vprg); - D3DDevice_SetPixelShader(device, prg[index].fprg); + D3DDevice_SetVertexShader(d3d_device_ptr, prg[index].vprg); + D3DDevice_SetPixelShader(d3d_device_ptr, prg[index].fprg); } } diff --git a/gfx/shader_hlsl.h b/gfx/shader_hlsl.h index 2ff3fac88e..39d7b51d6b 100644 --- a/gfx/shader_hlsl.h +++ b/gfx/shader_hlsl.h @@ -19,15 +19,15 @@ #include -bool hlsl_init(const char *path); +bool hlsl_init(const char *path, IDirect3DDevice9 * device_ptr); void hlsl_deinit(void); void hlsl_set_proj_matrix(XMMATRIX rotation_value); -void hlsl_set_params(IDirect3DDevice9 * device); +void hlsl_set_params(void); -void hlsl_use(IDirect3DDevice9 * device, unsigned index); +void hlsl_use(unsigned index); #define SSNES_HLSL_MAX_SHADERS 16