diff --git a/360/media/shaders/stock.cg b/360/media/shaders/stock.cg index 5f3deebc22..7b8000c952 100644 --- a/360/media/shaders/stock.cg +++ b/360/media/shaders/stock.cg @@ -5,7 +5,7 @@ void main_vertex ( float2 position : POSITION, float2 texCoord : TEXCOORD0, - uniform float4x4 modelViewProj : register(c0), + uniform float4x4 modelViewProj, out float4 oPosition : POSITION, out float2 otexCoord : TEXCOORD ) @@ -31,11 +31,10 @@ struct input }; -output main_fragment(float2 texCoord : TEXCOORD0, uniform sampler2D decal : register(s0), uniform input IN) +output main_fragment(float2 texCoord : TEXCOORD0, uniform sampler2D decal : TEXUNIT0, uniform input IN) { output OUT; OUT.color = tex2D(decal, texCoord); - OUT.color *= IN.output_size.x; return OUT; } diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 922d96700f..083e5348e6 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -189,14 +189,15 @@ static void xdk360_gfx_free(void * data) if (!vid) return; - hlsl_deinit(); - D3DResource_Release((D3DResource *)vid->lpTexture); D3DResource_Release((D3DResource *)vid->vertex_buf); D3DResource_Release((D3DResource *)vid->v_decl); D3DDevice_Release(vid->xdk360_render_device); Direct3D_Release(); + //breaks right now + //hlsl_deinit(); + free(vid); } @@ -434,7 +435,8 @@ static bool xdk360_gfx_frame(void *data, const void *frame, } hlsl_use(0); - hlsl_set_params(); + hlsl_set_params(width, height, 512, 512, vid->d3dpp.BackBufferWidth, + vid->d3dpp.BackBufferHeight); D3DLOCKED_RECT d3dlr; D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); diff --git a/config.def.h b/config.def.h index 0113bc6f79..d803afba17 100644 --- a/config.def.h +++ b/config.def.h @@ -163,6 +163,10 @@ static const bool video_smooth = true; // On resize and fullscreen, rendering area will stay 4:3 static const bool force_aspect = true; +// Controls aspect ratio handling. +static const float aspect_ratio = -1.0; // Automatic +static const bool aspect_ratio_auto = false; // 1:1 PAR + // Crop overscanned frames (7/8 or 15/15 for interlaced frames). static const bool crop_overscan = true; diff --git a/driver.c b/driver.c index 96f50b19c4..268c44a156 100644 --- a/driver.c +++ b/driver.c @@ -532,7 +532,7 @@ void init_video_input(void) if (geom->aspect_ratio > 0.0f && g_settings.video.aspect_ratio_auto) g_settings.video.aspect_ratio = geom->aspect_ratio; else - g_settings.video.aspect_ratio = (float)geom->base_width / geom->base_height; + g_settings.video.aspect_ratio = (float)geom->base_width / geom->base_height; // 1:1 PAR. SSNES_LOG("Adjusting aspect ratio to %.2f\n", g_settings.video.aspect_ratio); } diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index 155522bcae..23d01b2061 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -33,9 +33,10 @@ struct hlsl_program D3DXHANDLE out_size_v; D3DXHANDLE frame_cnt_v; D3DXHANDLE frame_dir_v; + D3DXHANDLE mvp; LPD3DXCONSTANTTABLE v_ctable; LPD3DXCONSTANTTABLE f_ctable; - XMMATRIX mvp; + XMMATRIX mvp_val; }; static IDirect3DDevice9 * d3d_device_ptr; @@ -80,17 +81,32 @@ static const char* stock_hlsl_program = void hlsl_set_proj_matrix(XMMATRIX rotation_value) { if (hlsl_active) - prg[active_index].mvp = rotation_value; + prg[active_index].mvp_val = rotation_value; } -void hlsl_set_params(void) +#define set_param_2f(param, xy, constanttable) \ + if (param) constanttable->SetFloatArray(d3d_device_ptr, param, xy, 2); + +void hlsl_set_params(unsigned width, unsigned height, + unsigned tex_width, unsigned tex_height, + unsigned out_width, unsigned out_height) { if (!hlsl_active) return; - //const float val[2] = {2.5f, 2.5f}; - - d3d_device_ptr->SetVertexShaderConstantF(0, (FLOAT*)&prg[active_index].mvp, 4); + const float ori_size[2] = {(float)width, (float)height }; + const float out_size[2] = {(float)out_width, (float)out_height}; + const float tex_size[2] = {(float)tex_width, (float)tex_height}; + + set_param_2f(prg[active_index].vid_size_f, ori_size, prg[active_index].f_ctable); + set_param_2f(prg[active_index].tex_size_f, tex_size, prg[active_index].f_ctable); + set_param_2f(prg[active_index].out_size_f, out_size, prg[active_index].f_ctable); + + set_param_2f(prg[active_index].vid_size_v, ori_size, prg[active_index].v_ctable); + set_param_2f(prg[active_index].tex_size_v, tex_size, prg[active_index].v_ctable); + set_param_2f(prg[active_index].out_size_v, out_size, prg[active_index].v_ctable); + + prg[active_index].v_ctable->SetMatrix(d3d_device_ptr, prg[active_index].mvp, (D3DXMATRIX*)&prg[active_index].mvp_val); //prg[active_index].f_ctable->SetFloatArray(d3d_device_ptr, prg[active_index].out_size_f, val, 2); } @@ -106,6 +122,11 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file) ret_fp = false; ret_vp = false; + if(prg[index].f_ctable) + D3DResource_Release((D3DResource *)prg[index].f_ctable); + if(prg[index].v_ctable) + D3DResource_Release((D3DResource *)prg[0].v_ctable); + if (path_is_file) { ret_fp = D3DXCompileShaderFromFile(prog, NULL, NULL, "main_fragment", "ps_2_0", 0, &code_f, &listing_f, &prg[index].f_ctable); @@ -130,6 +151,11 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file) goto end; } + if(prg[index].fprg) + D3DResource_Release((D3DResource *)prg[0].fprg); + if(prg[index].vprg) + D3DResource_Release((D3DResource *)prg[0].vprg); + prg[index].fprg = D3DDevice_CreatePixelShader((const DWORD*)code_f->GetBufferPointer()); prg[index].vprg = D3DDevice_CreateVertexShader((const DWORD*)code_v->GetBufferPointer()); code_f->Release(); @@ -171,12 +197,6 @@ static bool load_plain(const char *path) static void hlsl_deinit_progs(void) { - if (prg[0].fprg) - D3DResource_Release((D3DResource *)prg[0].fprg); - if (prg[0].vprg) - D3DResource_Release((D3DResource *)prg[0].vprg); - D3DResource_Release((D3DResource *)prg[0].f_ctable); - D3DResource_Release((D3DResource *)prg[0].v_ctable); } static void hlsl_deinit_state(void) @@ -205,14 +225,15 @@ static void set_program_attributes(unsigned i) prg[i].out_size_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.output_size"); prg[i].frame_cnt_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.frame_count"); prg[i].frame_dir_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.frame_direction"); + prg[i].mvp = prg[i].v_ctable->GetConstantByName(NULL, "$modelViewProj"); } bool hlsl_init(const char *path, IDirect3DDevice9 * device_ptr) { - if (device_ptr != NULL) - d3d_device_ptr = device_ptr; - else - return false; + if(!device_ptr) + return false; + + d3d_device_ptr = device_ptr; if (strstr(path, ".cgp")) { diff --git a/gfx/shader_hlsl.h b/gfx/shader_hlsl.h index 163b53c7d4..90653d1c02 100644 --- a/gfx/shader_hlsl.h +++ b/gfx/shader_hlsl.h @@ -18,6 +18,7 @@ #ifndef __SSNES_HLSL_H #define __SSNES_HLSL_H +#include "../boolean.h" #include bool hlsl_init(const char *path, IDirect3DDevice9 * device_ptr); @@ -26,7 +27,9 @@ void hlsl_deinit(void); void hlsl_set_proj_matrix(XMMATRIX rotation_value); -void hlsl_set_params(void); +void hlsl_set_params(unsigned width, unsigned height, + unsigned tex_width, unsigned tex_height, + unsigned out_width, unsigned out_height); void hlsl_use(unsigned index); diff --git a/input/sdl_input.c b/input/sdl_input.c index e9c0e89cc7..48d36269a8 100644 --- a/input/sdl_input.c +++ b/input/sdl_input.c @@ -322,6 +322,10 @@ static int16_t sdl_lightgun_device_state(sdl_input_t *sdl, unsigned id) return sdl->mouse_m; case RETRO_DEVICE_ID_LIGHTGUN_TURBO: return sdl->mouse_r; + case RETRO_DEVICE_ID_LIGHTGUN_START: + return sdl->mouse_m && sdl->mouse_r; + case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: + return sdl->mouse_m && sdl->mouse_l; default: return 0; } diff --git a/libretro.h b/libretro.h index a21de790d1..d0f454a476 100755 --- a/libretro.h +++ b/libretro.h @@ -6,13 +6,15 @@ #ifdef __cplusplus extern "C" { -#elif defined(_MSC_VER) -typedef unsigned char bool; -typedef enum {false, true}; #else +#if defined(_MSC_VER) && !defined(__cplusplus) +#define bool unsigned char +#define true 1 +#define false 0 #else #include #endif +#endif #define RETRO_API_VERSION 1 @@ -52,6 +54,7 @@ typedef enum {false, true}; #define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3 #define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4 #define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5 +#define RETRO_DEVICE_ID_LIGHTGUN_START 6 #define RETRO_REGION_NTSC 0 #define RETRO_REGION_PAL 1 diff --git a/msvc-360/SSNES-360/SSNES-360.vcxproj b/msvc-360/SSNES-360/SSNES-360.vcxproj index a65d5b4430..feddcb3605 100644 --- a/msvc-360/SSNES-360/SSNES-360.vcxproj +++ b/msvc-360/SSNES-360/SSNES-360.vcxproj @@ -562,6 +562,7 @@ copy %(FullPath) $(OutDir)media\shaders\stock.cg copy %(FullPath) $(OutDir)media\shaders\stock.cg copy %(FullPath) $(OutDir)media\shaders\stock.cg + true @@ -644,4 +645,4 @@ - + \ No newline at end of file diff --git a/settings.c b/settings.c index b8345cffbe..1a761dfeda 100644 --- a/settings.c +++ b/settings.c @@ -160,7 +160,8 @@ void config_set_defaults(void) g_settings.video.smooth = video_smooth; g_settings.video.force_aspect = force_aspect; g_settings.video.crop_overscan = crop_overscan; - g_settings.video.aspect_ratio = -1.0f; // Automatic + g_settings.video.aspect_ratio = aspect_ratio; + g_settings.video.aspect_ratio_auto = aspect_ratio_auto; // Let implementation decide if automatic, or 1:1 PAR. g_settings.video.shader_type = SSNES_SHADER_AUTO; g_settings.video.allow_rotate = allow_rotate; @@ -361,6 +362,7 @@ bool config_load_file(const char *path) CONFIG_GET_BOOL(video.force_aspect, "video_force_aspect"); CONFIG_GET_BOOL(video.crop_overscan, "video_crop_overscan"); CONFIG_GET_FLOAT(video.aspect_ratio, "video_aspect_ratio"); + CONFIG_GET_BOOL(video.aspect_ratio_auto, "video_aspect_ratio_auto"); CONFIG_GET_FLOAT(video.refresh_rate, "video_refresh_rate"); CONFIG_GET_STRING(video.cg_shader_path, "video_cg_shader"); diff --git a/ssnes.cfg b/ssnes.cfg index 472432ce83..2aa582fc63 100644 --- a/ssnes.cfg +++ b/ssnes.cfg @@ -55,8 +55,15 @@ # Forces rendering area to stay equal to SNES aspect ratio 4:3 or as defined in video_aspect_ratio. # video_force_aspect = true -# A floating point value for video aspect ratio (width / height) -# video_aspect_ratio = 1.333 +# A floating point value for video aspect ratio (width / height). +# If this is not set, aspect ratio is assumed to be automatic. +# Behavior then is defined by video_aspect_ratio_auto. +# video_aspect_ratio = + +# If this is true and video_aspect_ratio is not set, +# aspect ratio is decided by libretro implementation. +# If this is false, 1:1 PAR will always be assumed if video_aspect_ratio is not set. +# video_aspect_ratio_auto = false # Forces cropping of overscanned frames. Crops away top 7 scanlines and 8 bottom scanlines. (15/15 for interlaced frames). # video_crop_overscan = false