diff --git a/360/menu.cpp b/360/menu.cpp index 270260109f..0c7b79f387 100644 --- a/360/menu.cpp +++ b/360/menu.cpp @@ -495,9 +495,9 @@ void menu_loop(void) if(g_console.emulator_initialized) ssnes_render_cached_frame(); else - vid->xdk360_render_device->Clear(0, NULL, + D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_STENCIL | D3DCLEAR_ZBUFFER, - D3DCOLOR_ARGB(255, 32, 32, 64), 1.0, 0); + D3DCOLOR_ARGB(255, 32, 32, 64), 1.0, 0, FALSE); XINPUT_STATE state; XInputGetState(0, &state); diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index c6dc3e8b02..206900ca4f 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -78,19 +78,20 @@ static void xdk360_gfx_free(void * data) if (!vid) return; - vid->lpTexture->Release(); - vid->vertex_buf->Release(); - vid->pVertexDecl->Release(); - vid->pPixelShader->Release(); - vid->pVertexShader->Release(); - vid->xdk360_render_device->Release(); - vid->xdk360_device->Release(); + D3DResource_Release((D3DResource *)vid->lpTexture); + D3DResource_Release((D3DResource *)vid->vertex_buf); + D3DResource_Release((D3DResource *)vid->pVertexDecl); + D3DResource_Release((D3DResource *)vid->pPixelShader); + D3DResource_Release((D3DResource *)vid->pVertexShader); + D3DDevice_Release(vid->xdk360_render_device); + Direct3D_Release(); free(vid); } static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { + HRESULT ret; if (g_d3d) return g_d3d; @@ -130,8 +131,8 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i vid->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; vid->d3dpp.PresentationInterval = video->vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; - vid->xdk360_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &vid->d3dpp, - &vid->xdk360_render_device); + // D3DCREATE_HARDWARE_VERTEXPROCESSING is ignored on 360 + ret = Direct3D_CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &vid->d3dpp, &vid->xdk360_render_device); ID3DXBuffer* pShaderCodeV = NULL; ID3DXBuffer* pShaderCodeP = NULL; @@ -149,32 +150,29 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i if (FAILED(hr)) { OutputDebugString(pErrorMsg ? (char*)pErrorMsg->GetBufferPointer() : ""); - vid->xdk360_render_device->Release(); - vid->xdk360_device->Release(); + D3DDevice_Release(vid->xdk360_render_device); + Direct3D_Release(); free(vid); return NULL; } - - vid->xdk360_render_device->CreateVertexShader((const DWORD*)pShaderCodeV->GetBufferPointer(), &vid->pVertexShader); - vid->xdk360_render_device->CreatePixelShader((const DWORD*)pShaderCodeP->GetBufferPointer(), &vid->pPixelShader); + + vid->pVertexShader = D3DDevice_CreateVertexShader((const DWORD*)pShaderCodeV->GetBufferPointer()); + vid->pPixelShader = D3DDevice_CreatePixelShader((const DWORD*)pShaderCodeP->GetBufferPointer()); pShaderCodeV->Release(); pShaderCodeP->Release(); - vid->xdk360_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5, - 0, &vid->lpTexture, NULL); + vid->lpTexture = (D3DTexture*) D3DDevice_CreateTexture(512, 512, 1, 1, 0, D3DFMT_LIN_X1R5G5B5, + 0, D3DRTYPE_TEXTURE); D3DLOCKED_RECT d3dlr; - if (SUCCEEDED(vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK))) - { - memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); - vid->lpTexture->UnlockRect(0); - } + D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); + memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); + D3DTexture_UnlockRect(vid->lpTexture, 0); vid->last_width = 512; vid->last_height = 512; - vid->xdk360_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), 0, - 0, 0, &vid->vertex_buf, NULL); + vid->vertex_buf = D3DDevice_CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), 0, 0); static const DrawVerticeFormats init_verts[] = { { -1.0f, -1.0f, 0.0f, 1.0f }, @@ -182,11 +180,10 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i { -1.0f, 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 1.0f, 0.0f }, }; - - void *verts_ptr; - vid->vertex_buf->Lock(0, 0, &verts_ptr, 0); + + void *verts_ptr = (BYTE*)D3DVertexBuffer_Lock(vid->vertex_buf, 0, 0, 0); memcpy(verts_ptr, init_verts, sizeof(init_verts)); - vid->vertex_buf->Unlock(); + D3DVertexBuffer_Unlock(vid->vertex_buf); static const D3DVERTEXELEMENT9 VertexElements[] = { @@ -195,20 +192,20 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i D3DDECL_END() }; - vid->xdk360_render_device->CreateVertexDeclaration(VertexElements, &vid->pVertexDecl); + vid->pVertexDecl = D3DDevice_CreateVertexDeclaration(VertexElements); + + D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, D3DCLEAR_TARGET, + 0xff000000, 1.0f, 0, FALSE); - vid->xdk360_render_device->Clear(0, NULL, D3DCLEAR_TARGET, - 0xff000000, 1.0f, 0); - - vid->xdk360_render_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - vid->xdk360_render_device->SetRenderState(D3DRS_ZENABLE, FALSE); + D3DDevice_SetRenderState_CullMode(vid->xdk360_render_device, D3DCULL_NONE); + D3DDevice_SetRenderState_ZEnable(vid->xdk360_render_device, FALSE); D3DVIEWPORT9 vp = {0}; vp.Width = vid->video_mode.fIsHiDef ? 1280 : 640; vp.Height = vid->video_mode.fIsHiDef ? 720 : 480; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; - vid->xdk360_render_device->SetViewport(&vp); + D3DDevice_SetViewport(vid->xdk360_render_device, &vp); return vid; } @@ -219,17 +216,16 @@ static bool xdk360_gfx_frame(void *data, const void *frame, xdk360_video_t *vid = (xdk360_video_t*)data; g_frame_count++; - vid->xdk360_render_device->Clear(0, NULL, D3DCLEAR_TARGET, - 0xff000000, 1.0f, 0); + D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, D3DCLEAR_TARGET, + 0xff000000, 1.0f, 0, FALSE); if (vid->last_width != width || vid->last_height != height || g_console.force_resize_enable) { D3DLOCKED_RECT d3dlr; - if (SUCCEEDED(vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK))) - { - memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); - vid->lpTexture->UnlockRect(0); - } + + D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); + memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); + D3DTexture_UnlockRect(vid->lpTexture, 0); float tex_w = width / 512.0f; float tex_h = height / 512.0f; @@ -266,8 +262,7 @@ static bool xdk360_gfx_frame(void *data, const void *frame, { 1.0f, 1.0f, tex_w, tex_h }, }; - void *verts_ptr; - vid->vertex_buf->Lock(0, 0, &verts_ptr, 0); + void *verts_ptr = (BYTE*)D3DVertexBuffer_Lock(vid->vertex_buf, 0, 0, 0); switch(g_console.screen_orientation) { case ORIENTATION_NORMAL: @@ -283,7 +278,7 @@ static bool xdk360_gfx_frame(void *data, const void *frame, memcpy(verts_ptr, vertexes_flipped_vertical, sizeof(vertexes_flipped_vertical)); break; } - vid->vertex_buf->Unlock(); + D3DVertexBuffer_Unlock(vid->vertex_buf); vid->last_width = width; vid->last_height = height; @@ -291,30 +286,29 @@ static bool xdk360_gfx_frame(void *data, const void *frame, } D3DLOCKED_RECT d3dlr; - if (SUCCEEDED(vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK))) + D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); + for (unsigned y = 0; y < height; y++) { - for (unsigned y = 0; y < height; y++) - { - const uint8_t *in = (const uint8_t*)frame + y * pitch; - uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch; - memcpy(out, in, width * sizeof(uint16_t)); - } - vid->lpTexture->UnlockRect(0); + const uint8_t *in = (const uint8_t*)frame + y * pitch; + uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch; + memcpy(out, in, width * sizeof(uint16_t)); } + D3DTexture_UnlockRect(vid->lpTexture, 0); - vid->xdk360_render_device->SetTexture(0, vid->lpTexture); - vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); - vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + D3DDevice_SetTexture_Inline(vid->xdk360_render_device, 0, vid->lpTexture); + D3DDevice_SetSamplerState(vid->xdk360_render_device, 0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); + D3DDevice_SetSamplerState(vid->xdk360_render_device, 0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); + D3DDevice_SetSamplerState(vid->xdk360_render_device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + D3DDevice_SetSamplerState(vid->xdk360_render_device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); - vid->xdk360_render_device->SetVertexShader(vid->pVertexShader); - vid->xdk360_render_device->SetPixelShader(vid->pPixelShader); + D3DDevice_SetVertexShader(vid->xdk360_render_device, vid->pVertexShader); + D3DDevice_SetPixelShader(vid->xdk360_render_device, vid->pPixelShader); - vid->xdk360_render_device->SetVertexDeclaration(vid->pVertexDecl); - vid->xdk360_render_device->SetStreamSource(0, vid->vertex_buf, 0, sizeof(DrawVerticeFormats)); + D3DDevice_SetVertexDeclaration(vid->xdk360_render_device, vid->pVertexDecl); + D3DDevice_SetStreamSource_Inline(vid->xdk360_render_device, 0, vid->vertex_buf, 0, + sizeof(DrawVerticeFormats)); - vid->xdk360_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); + D3DDevice_DrawVertices(vid->xdk360_render_device, D3DPT_TRIANGLESTRIP, 0, D3DVERTEXCOUNT(D3DPT_TRIANGLESTRIP, 2)); if (msg) { if(IS_TIMER_EXPIRED() || g_first_msg) @@ -328,7 +322,7 @@ static bool xdk360_gfx_frame(void *data, const void *frame, } if(!vid->block_swap) - vid->xdk360_render_device->Present(NULL, NULL, NULL, NULL); + D3DDevice_Present(vid->xdk360_render_device); return true; } @@ -349,7 +343,7 @@ static void xdk360_swap (void * data) { (void)data; xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - vid->xdk360_render_device->Present(NULL, NULL, NULL, NULL); + D3DDevice_Present(vid->xdk360_render_device); } static void xdk360_gfx_set_nonblock_state(void *data, bool state) @@ -357,11 +351,9 @@ static void xdk360_gfx_set_nonblock_state(void *data, bool state) xdk360_video_t *vid = (xdk360_video_t*)data; SSNES_LOG("D3D Vsync => %s\n", state ? "off" : "on"); if(state) - vid->xdk360_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, - D3DPRESENT_INTERVAL_IMMEDIATE); + D3DDevice_SetRenderState_PresentInterval(vid->xdk360_render_device, D3DPRESENT_INTERVAL_IMMEDIATE); else - vid->xdk360_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, - D3DPRESENT_INTERVAL_ONE); + D3DDevice_SetRenderState_PresentInterval(vid->xdk360_render_device, D3DPRESENT_INTERVAL_ONE); } static bool xdk360_gfx_alive(void *data)