(360) 360 port works with skeleton HLSL driver now

This commit is contained in:
TwinAphex51224 2012-04-14 21:45:43 +02:00
parent 6f56942d44
commit a50a9a6ba1
3 changed files with 75 additions and 60 deletions

View File

@ -19,7 +19,7 @@
#include "../driver.h"
#include "xdk360_video.h"
#include "xdk360_video_resources.h"
#include "../gfx/hlsl_shader.h"
#include "../gfx/shader_hlsl.h"
#include "../console/console_ext.h"
#include "../general.h"
#include "../message.h"
@ -204,7 +204,7 @@ static void set_viewport(bool force_full)
{
xdk360_video_t *vid = (xdk360_video_t*)g_d3d;
D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, D3DCLEAR_TARGET,
0xff000000, 1.0f, 0, FALSE);
0xff000000, 1.0f, 0, FALSE);
int width = vid->video_mode.fIsHiDef ? 1280 : 640;
int height = vid->video_mode.fIsHiDef ? 720 : 480;
@ -236,16 +236,16 @@ static void set_viewport(bool force_full)
if (device_aspect > desired_aspect)
{
delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
m_viewport_x_temp = (int)(width * (0.5 - delta));
m_viewport_width_temp = (int)(2.0 * width * delta);
width = (unsigned)(2.0 * width * delta);
m_viewport_x_temp = (int)(width * (0.5 - delta));
m_viewport_width_temp = (int)(2.0 * width * delta);
width = (unsigned)(2.0 * width * delta);
}
else
{
delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
m_viewport_y_temp = (int)(height * (0.5 - delta));
m_viewport_height_temp = (int)(2.0 * height * delta);
height = (unsigned)(2.0 * height * delta);
m_viewport_y_temp = (int)(height * (0.5 - delta));
m_viewport_height_temp = (int)(2.0 * height * delta);
height = (unsigned)(2.0 * height * delta);
}
}
@ -276,19 +276,19 @@ static void xdk360_set_orientation(void * data, uint32_t orientation)
{
case ORIENTATION_NORMAL:
angle = M_PI * 0 / 180;
break;
break;
case ORIENTATION_VERTICAL:
angle = M_PI * 270 / 180;
break;
angle = M_PI * 270 / 180;
break;
case ORIENTATION_FLIPPED:
angle = M_PI * 180 / 180;
break;
angle = M_PI * 180 / 180;
break;
case ORIENTATION_FLIPPED_ROTATED:
angle = M_PI * 90 / 180;
break;
angle = M_PI * 90 / 180;
break;
}
hlsl_use(vid->xdk360_render_device, 0);
//hlsl_use(vid->xdk360_render_device, 0);
hlsl_set_proj_matrix(XMMatrixRotationZ(angle));
}
@ -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(NULL);
hlsl_init(g_settings.video.cg_shader_path);
vid->lpTexture = (D3DTexture*) D3DDevice_CreateTexture(512, 512, 1, 1, 0, D3DFMT_LIN_X1R5G5B5,
0, D3DRTYPE_TEXTURE);

View File

@ -48,6 +48,7 @@ VIDEO
#include "../../ps3/ps3_video_psgl.c"
#include "../../ps3/image.c"
#elif defined(_XBOX)
#include "../../gfx/shader_hlsl.c"
#include "../../360/xdk360_video.cpp"
#elif defined(GEKKO)
#include "../../wii/video.c"

View File

@ -32,45 +32,47 @@ struct hlsl_program
XMMATRIX mvp;
};
static struct hlsl_program prg[SSNES_HLSL_MAX_SHADERS];
static struct hlsl_program prg[SSNES_HLSL_MAX_SHADERS] = {0};
static bool hlsl_active = false;
static unsigned active_index = 0;
static const char *stock_hlsl_program =
"void main_vertex"
"("
" float2 position : POSITION,"
" float2 texCoord : TEXCOORD0,"
" uniform float4x4 modelViewProj : register(c0),"
" out float4 oPosition : POSITION,"
" out float2 otexCoord : TEXCOORD"
")"
"{"
" oPosition = mul(modelViewProj, float4(position, 0.0, 1.0));"
" otexCoord = texCoord;"
"}"
""
"struct output"
"{"
" float4 color: COLOR;"
"}"
""
"struct input"
"{"
" float2 video_size;"
" float2 texture_size;"
" float2 output_size;"
"}"
""
"output main_fragment(float2 tex : TEXCOORD0, uniform sampler2D decal : register(s0), uniform input IN)"
"{"
" output OUT;"
" OUT.color = tex2D(decal, tex);"
" return OUT;"
"}";
static const char* stock_hlsl_program =
"void main_vertex "
"( "
" float2 position : POSITION, "
" float2 texCoord : TEXCOORD0, "
" uniform float4x4 modelViewProj : register(c0), "
" out float4 oPosition : POSITION, "
" out float2 otexCoord : TEXCOORD "
") "
"{ "
" oPosition = mul(modelViewProj, float4(position, 0.0, 1.0)); "
" otexCoord = texCoord; "
"} "
" "
"struct output "
"{ "
" float4 color: COLOR; "
"}; "
" "
"struct input "
"{ "
" float2 video_size; "
" float2 texture_size; "
" float2 output_size; "
"}; "
" "
"output main_fragment(float2 texCoord : TEXCOORD0, "
"uniform sampler2D decal : register(s0), uniform input IN) "
"{ "
" output OUT; "
" OUT.color = tex2D(decal, tex); "
" return OUT; "
"} ";
void hlsl_set_proj_matrix(XMMATRIX rotation_value)
{
if (hlsl_active && prg[active_index].mvp)
if (hlsl_active)
prg[active_index].mvp = rotation_value;
}
@ -79,12 +81,12 @@ void hlsl_set_params(IDirect3DDevice9 * device)
if (!hlsl_active)
return;
if (prg[active_index].mvp)
device->SetVertexShaderConstantF(0, (FLOAT*)&prg[active_index].mvp, 4);
device->SetVertexShaderConstantF(0, (FLOAT*)&prg[active_index].mvp, 4);
}
static bool load_program(unsigned index, const char *prog, bool path_is_file)
{
SSNES_LOG("test\n");
bool ret, ret_fp, ret_vp;
ID3DXBuffer *listing_f = NULL;
ID3DXBuffer *listing_v = NULL;
@ -92,6 +94,8 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file)
ID3DXBuffer *code_v = NULL;
ret = true;
ret_fp = false;
ret_vp = false;
if (path_is_file)
{
@ -100,8 +104,8 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file)
}
else
{
ret_fp = D3DXCompileShader(prog, sizeof(prog), NULL, NULL, "main_fragment", "ps_2_0", 0, &code_f, &listing_f, NULL );
ret_vp = D3DXCompileShader(prog, sizeof(prog), NULL, NULL, "main_vertex", "vs_2_0", 0, &code_v, &listing_v, NULL );
ret_fp = D3DXCompileShader(prog, (UINT)strlen(prog), NULL, NULL, "main_fragment", "ps_2_0", 0, &code_f, &listing_f, NULL );
ret_vp = D3DXCompileShader(prog, (UINT)strlen(prog), NULL, NULL, "main_vertex", "vs_2_0", 0, &code_v, &listing_v, NULL );
}
if (FAILED(ret_fp) || FAILED(ret_vp))
@ -140,23 +144,27 @@ static bool load_stock(void)
static bool load_plain(const char *path)
{
#if 0
if (!load_stock())
return false;
#endif
#if 0
SSNES_LOG("Loading HLSL file: %s\n", path);
if (!load_program(1, path, true))
if (!load_program(0, path, true))
return false;
#endif
return true;
}
static void hlsl_deinit_progs(void)
{
D3DResource_Release((D3DResource *)vid->pPixelShader);
D3DResource_Release((D3DResource *)vid->pVertexShader);
if (prg[0].fprg)
D3DResource_Release((D3DResource *)prg[0].fprg);
if (prg[0].vprg)
D3DResource_Release((D3DResource *)prg[0].vprg);
memset(prg, 0, sizeof(prg));
}
static void hlsl_deinit_state(void)
@ -166,6 +174,11 @@ static void hlsl_deinit_state(void)
hlsl_deinit_progs();
}
static bool load_preset(const char *path)
{
return false;
}
bool hlsl_init(const char *path)
{
if (strstr(path, ".cgp"))
@ -179,6 +192,7 @@ bool hlsl_init(const char *path)
return false;
}
active_index = 0;
hlsl_active = true;
return true;
}