static bool xdk_d3d_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { if (!frame) return true; xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data; #ifdef HAVE_FBO D3DSurface* pRenderTarget0; #endif bool menu_enabled = g_console.menu_enable; if (d3d->last_width != width || d3d->last_height != height) { D3DLOCKED_RECT d3dlr; d3d->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); d3d->lpTexture->UnlockRect(0); float tex_w = width / 512.0f; float tex_h = height / 512.0f; DrawVerticeFormats verts[] = { { -1.0f, -1.0f, 0.0f, tex_h }, { 1.0f, -1.0f, tex_w, tex_h }, { -1.0f, 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, tex_w, 0.0f }, }; // Align texels and vertices (D3D9 quirk). for (unsigned i = 0; i < 4; i++) { verts[i].x -= 0.5f / 512.0f; verts[i].y += 0.5f / 512.0f; } void *verts_ptr; d3d->vertex_buf->Lock(0, 0, &verts_ptr, 0); memcpy(verts_ptr, verts, sizeof(verts)); d3d->vertex_buf->Unlock(); d3d->last_width = width; d3d->last_height = height; } #ifdef HAVE_FBO if (d3d->fbo_enabled) { d3d->d3d_render_device->GetRenderTarget(0, &pRenderTarget0); d3d->d3d_render_device->SetRenderTarget(0, d3d->lpSurface); } #endif if (d3d->should_resize) xdk_d3d_set_viewport(false); d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); d3d->frame_count++; d3d->d3d_render_device->SetTexture(0, d3d->lpTexture); #ifdef HAVE_HLSL hlsl_use(1); #endif #ifdef HAVE_FBO if(d3d->fbo_enabled) { #ifdef HAVE_HLSL hlsl_set_params(width, height, 512, 512, g_settings.video.fbo_scale_x * width, g_settings.video.fbo_scale_y * height, d3d->frame_count); #endif D3DVIEWPORT vp = {0}; vp.Width = g_settings.video.fbo_scale_x * width; vp.Height = g_settings.video.fbo_scale_y * height; vp.X = 0; vp.Y = 0; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; d3d->d3d_render_device->SetViewport(&vp); } else #endif { #ifdef HAVE_HLSL hlsl_set_params(width, height, 512, 512, d3d->d3dpp.BackBufferWidth, d3d->d3dpp.BackBufferHeight, d3d->frame_count); #endif } D3DLOCKED_RECT d3dlr; d3d->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); 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)); } d3d->lpTexture->UnlockRect(0); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); d3d->d3d_render_device->SetVertexDeclaration(d3d->v_decl); d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf, 0, sizeof(DrawVerticeFormats)); d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); #ifdef HAVE_FBO if(d3d->fbo_enabled) { d3d->d3d_render_device->Resolve(D3DRESOLVE_RENDERTARGET0, NULL, d3d->lpTexture_ot, NULL, 0, 0, NULL, 0, 0, NULL); d3d->d3d_render_device->SetRenderTarget(0, pRenderTarget0); pRenderTarget0->Release(); d3d->d3d_render_device->SetTexture(0, &d3d->lpTexture_ot_as16srgb); #ifdef HAVE_HLSL hlsl_use(2); hlsl_set_params(g_settings.video.fbo_scale_x * width, g_settings.video.fbo_scale_y * height, g_settings.video.fbo_scale_x * 512, g_settings.video.fbo_scale_y * 512, d3d->d3dpp.BackBufferWidth, d3d->d3dpp.BackBufferHeight, d3d->frame_count); #endif xdk_d3d_set_viewport(false); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); d3d->d3d_render_device->SetVertexDeclaration(d3d->v_decl); d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf, 0, sizeof(DrawVerticeFormats)); d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); } #endif /* XBox 360 specific font code */ if (msg && !menu_enabled) { if(IS_TIMER_EXPIRED(d3d)) { xdk360_console_format(msg); SET_TIMER_EXPIRATION(d3d, 30); } xdk360_console_draw(); } if(!d3d->block_swap) gfx_ctx_swap_buffers(); return true; }
static bool xdk_d3d_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data; #ifdef HAVE_FBO D3DSurface* pRenderTarget0; #endif bool fps_enable = g_extern.console.rmenu.state.msg_fps.enable; #ifdef _XBOX1 unsigned flicker_filter = g_extern.console.screen.state.flicker_filter.value; bool soft_filter_enable = g_extern.console.screen.state.soft_filter.enable; #endif if (d3d->last_width != width || d3d->last_height != height) { D3DLOCKED_RECT d3dlr; d3d->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); memset(d3dlr.pBits, 0, d3d->tex_w * d3dlr.Pitch); d3d->lpTexture->UnlockRect(0); #if defined(_XBOX1) float tex_w = width; // / 512.0f; float tex_h = height; // / 512.0f; DrawVerticeFormats verts[] = { { -1.0f, -1.0f, 1.0f, 0.0f, tex_h }, { 1.0f, -1.0f, 1.0f, tex_w, tex_h }, { -1.0f, 1.0f, 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 1.0f, tex_w, 0.0f }, }; #elif defined(_XBOX360) float tex_w = width / ((float)d3d->tex_w); float tex_h = height / ((float)d3d->tex_h); DrawVerticeFormats verts[] = { { -1.0f, -1.0f, 0.0f, tex_h }, { 1.0f, -1.0f, tex_w, tex_h }, { -1.0f, 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, tex_w, 0.0f }, }; #endif // Align texels and vertices (D3D9 quirk). for (unsigned i = 0; i < 4; i++) { verts[i].x -= 0.5f / ((float)d3d->tex_w); verts[i].y += 0.5f / ((float)d3d->tex_h); } #if defined(_XBOX1) BYTE *verts_ptr; #elif defined(_XBOX360) void *verts_ptr; #endif d3d->vertex_buf->Lock(0, 0, &verts_ptr, 0); memcpy(verts_ptr, verts, sizeof(verts)); d3d->vertex_buf->Unlock(); d3d->last_width = width; d3d->last_height = height; } #ifdef HAVE_FBO if (d3d->fbo_inited) { d3d->d3d_render_device->GetRenderTarget(0, &pRenderTarget0); d3d->d3d_render_device->SetRenderTarget(0, d3d->lpSurface); } #endif if (d3d->should_resize) xdk_d3d_set_viewport(false); d3d->d3d_render_device->SetTexture(0, d3d->lpTexture); #ifdef HAVE_HLSL hlsl_use(1); #endif #ifdef HAVE_FBO if(d3d->fbo_inited) { #ifdef HAVE_HLSL hlsl_set_params(width, height, d3d->tex_w, d3d->tex_h, g_settings.video.fbo.scale_x * width, g_settings.video.fbo.scale_y * height, g_extern.frame_count); #endif D3DVIEWPORT vp = {0}; vp.Width = g_settings.video.fbo.scale_x * width; vp.Height = g_settings.video.fbo.scale_y * height; vp.X = 0; vp.Y = 0; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; d3d->d3d_render_device->SetViewport(&vp); } else #endif { #ifdef HAVE_HLSL hlsl_set_params(width, height, d3d->tex_w, d3d->tex_h, d3d->win_width, d3d->win_height, g_extern.frame_count); #endif } if(frame) { D3DLOCKED_RECT d3dlr; d3d->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); 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 * d3d->base_size); } d3d->lpTexture->UnlockRect(0); } d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); #if defined(_XBOX1) d3d->d3d_render_device->SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1); d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf, sizeof(DrawVerticeFormats)); d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); d3d->d3d_render_device->BeginScene(); d3d->d3d_render_device->SetFlickerFilter(flicker_filter); d3d->d3d_render_device->SetSoftDisplayFilter(soft_filter_enable); d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); d3d->d3d_render_device->EndScene(); #elif defined(_XBOX360) d3d->d3d_render_device->SetVertexDeclaration(d3d->v_decl); d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf, 0, sizeof(DrawVerticeFormats)); d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); #endif #ifdef HAVE_FBO if(d3d->fbo_inited) { d3d->d3d_render_device->Resolve(D3DRESOLVE_RENDERTARGET0, NULL, d3d->lpTexture_ot, NULL, 0, 0, NULL, 0, 0, NULL); d3d->d3d_render_device->SetRenderTarget(0, pRenderTarget0); pRenderTarget0->Release(); d3d->d3d_render_device->SetTexture(0, &d3d->lpTexture_ot_as16srgb); #ifdef HAVE_HLSL hlsl_use(2); hlsl_set_params(g_settings.video.fbo.scale_x * width, g_settings.video.fbo.scale_y * height, g_settings.video.fbo.scale_x * d3d->tex_w, g_settings.video.fbo.scale_y * d3d->tex_h, d3d->win_width, d3d->win_height, g_extern.frame_count); #endif xdk_d3d_set_viewport(false); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); d3d->d3d_render_device->SetVertexDeclaration(d3d->v_decl); d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf, 0, sizeof(DrawVerticeFormats)); d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); } #endif #if defined(_XBOX1) float mem_width = font_x + 30; float mem_height = font_y + 50; float msg_width = 60; float msg_height = 365; #elif defined(_XBOX360) float mem_width = g_extern.console.rmenu.state.rmenu_hd.enable ? 160 : 100; float mem_height = 70; float msg_width = mem_width; float msg_height = mem_height + 50; #endif if(fps_enable) { MEMORYSTATUS stat; GlobalMemoryStatus(&stat); char fps_txt[128]; char buf[128]; snprintf(buf, sizeof(buf), "%.2f MB free / %.2f MB total", stat.dwAvailPhys/(1024.0f*1024.0f), stat.dwTotalPhys/(1024.0f*1024.0f)); if (d3d->font_ctx) d3d->font_ctx->render_msg_place(d3d, mem_width, mem_height, 0, 0, buf); gfx_get_fps(fps_txt, sizeof(fps_txt), true); if (d3d->font_ctx) d3d->font_ctx->render_msg_place(d3d, mem_width, mem_height + 30, 0, 0, fps_txt); } if (msg) d3d->font_ctx->render_msg_place(d3d, msg_width, msg_height, 0.0f, 0, msg); #ifdef _XBOX360 if(g_extern.draw_menu) { app.Render(); XuiTimersRun(); } else #endif gfx_ctx_xdk_swap_buffers(); return true; }