Exemple #1
0
static void render_pass(void *data, const void *frame, unsigned width, unsigned height,
                        unsigned pitch, unsigned rotation)
{
   d3d_video_t *d3d = (d3d_video_t*)data;
   LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev;
#ifndef _XBOX1
   DWORD fetchConstant;
   UINT64 pendingMask3;
#endif
#ifdef _XBOX1
   d3dr->SetFlickerFilter(g_extern.console.screen.flicker_filter_index);
   d3dr->SetSoftDisplayFilter(g_extern.lifecycle_state & (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE));
#endif
   blit_to_texture(d3d, frame, width, height, pitch);
   set_vertices(d3d, 1, width, height);

#ifdef _XBOX
   if (g_extern.frame_count)
   {
#ifdef _XBOX1
      d3dr->SwitchTexture(0, d3d->tex);
#elif defined _XBOX360
      d3dr->SetTextureFetchConstant(0, d3d->tex);
#endif
   }
   else if (d3d->tex)
#endif
   RD3DDevice_SetTexture(d3dr, 0, d3d->tex);
   RD3DDevice_SetViewport(d3d->dev, &d3d->final_viewport);
   RD3DDevice_SetSamplerState_MinFilter(d3dr, 0, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
   RD3DDevice_SetSamplerState_MagFilter(d3dr, 0, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
   RD3DDevice_SetSamplerState_AddressU(d3dr, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
   RD3DDevice_SetSamplerState_AddressV(d3dr, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);

#if defined(_XBOX1)
   RD3DDevice_SetVertexShader(d3dr, D3DFVF_XYZ | D3DFVF_TEX1);
   IDirect3DDevice8_SetStreamSource(d3dr, 0, d3d->vertex_buf, sizeof(DrawVerticeFormats));
#elif defined(_XBOX360)
   D3DDevice_SetVertexDeclaration(d3dr, d3d->vertex_decl);
   D3DDevice_SetStreamSource_Inline(d3dr, 0, d3d->vertex_buf, 0, sizeof(DrawVerticeFormats));
#endif

#ifdef _XBOX
   d3dr->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
#else
   if (SUCCEEDED(d3dr->BeginScene()))
   {
      d3dr->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
      d3dr->EndScene();
   }
#endif

   g_extern.frame_count++;

   set_mvp(d3d, d3d->screen_width, d3d->screen_height, d3d->dev_rotation);
}
Exemple #2
0
static bool xdk_d3d_frame(void *data, const void *frame,
      unsigned width, unsigned height, unsigned pitch, const char *msg)
{
#ifndef _XBOX1
   DWORD fetchConstant;
   UINT64 pendingMask3;
#endif
   xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
   LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->d3d_render_device;
   uint64_t lifecycle_mode_state = g_extern.lifecycle_mode_state;
#if 0 /* ifdef HAVE_FBO */
   D3DSurface* pRenderTarget0;
#endif

   if (d3d->last_width != width || d3d->last_height != height)
   {
      D3DLOCKED_RECT d3dlr;

      D3DTexture_LockRect(d3d->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
      memset(d3dlr.pBits, 0, d3d->tex_w * d3dlr.Pitch);

#if defined(_XBOX1)
      float tex_w = width;
      float tex_h = height;

      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
      RD3DVertexBuffer_Lock(d3d->vertex_buf, 0, 0, &verts_ptr, 0);
      memcpy(verts_ptr, verts, sizeof(verts));
      RD3DVertexBuffer_Unlock(d3d->vertex_buf);

      d3d->last_width = width;
      d3d->last_height = height;
   }

#if 0 /* ifdef HAVE_FBO */
   if (d3d->fbo_inited)
   {
      d3dr->GetRenderTarget(0, &pRenderTarget0);
      d3dr->SetRenderTarget(0, d3d->lpSurface);
   }
#endif

   if (d3d->should_resize)
   {
#ifdef _XBOX1
      d3dr->SetFlickerFilter(g_extern.console.screen.flicker_filter_index);
      d3dr->SetSoftDisplayFilter(g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE));
#endif
      xdk_d3d_set_viewport(false);
      d3d->should_resize = false;
   }

#ifdef HAVE_HLSL
   if (d3d->shader)
      d3d->shader->set_mvp(NULL);
#endif

   RD3DDevice_SetTexture(d3dr, 0, d3d->lpTexture);

#ifdef HAVE_HLSL
   if (d3d->shader)
      d3d->shader->use(1);
#endif

#if 0 /* ifdef HAVE_FBO */
   if (d3d->fbo_inited)
   {
#ifdef HAVE_HLSL
      if (d3d->shader)
         d3d->shader->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;
      RD3DDevice_SetViewport(d3dr, &vp);
   }
   else
#endif
   {
#ifdef HAVE_HLSL

      if (d3d->shader)
         d3d->shader->set_params(width, height, d3d->tex_w, d3d->tex_h, d3d->win_width,
               d3d->win_height, g_extern.frame_count,
      /* TODO - missing a bunch of params at the end */
NULL, NULL, NULL, 0);
#endif
   }

   if (frame)
   {
      unsigned base_size = d3d->base_size;
      D3DLOCKED_RECT d3dlr;
      D3DTexture_LockRect(d3d->lpTexture, 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 * base_size);
      }
   }

   unsigned filter = g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT;

   RD3DDevice_SetSamplerState_MinFilter(d3dr, 0, filter);
   RD3DDevice_SetSamplerState_MagFilter(d3dr, 0, filter);
   RD3DDevice_SetSamplerState_AddressU(d3dr, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
   RD3DDevice_SetSamplerState_AddressV(d3dr, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);

#if defined(_XBOX1)
   RD3DDevice_SetVertexShader(d3dr, D3DFVF_XYZ | D3DFVF_TEX1);
   IDirect3DDevice8_SetStreamSource(d3dr, 0, d3d->vertex_buf, sizeof(DrawVerticeFormats));
#elif defined(_XBOX360)
   D3DDevice_SetVertexDeclaration(d3dr, d3d->v_decl);
   D3DDevice_SetStreamSource_Inline(d3dr, 0, d3d->vertex_buf, 0, sizeof(DrawVerticeFormats));
#endif
   RD3DDevice_DrawPrimitive(d3dr, D3DPT_TRIANGLESTRIP, 0, 2);

#if 0 /* ifdef HAVE_FBO */
   if (d3d->fbo_inited)
   {
      d3dr->Resolve(D3DRESOLVE_RENDERTARGET0, NULL, d3d->lpTexture_ot,
            NULL, 0, 0, NULL, 0, 0, NULL);

      d3dr->SetRenderTarget(0, pRenderTarget0);
      pRenderTarget0->Release();
      RD3DDevice_SetTexture(d3dr, 0, &d3d->lpTexture_ot_as16srgb);

#ifdef HAVE_HLSL
      hlsl_use(2);

      if (d3d->shader)
         d3d->shader->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);

      RD3DDevice_SetSamplerState_MinFilter(d3dr, D3DSAMP_MINFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
      RD3DDevice_SetSamplerState_MagFilter(d3dr, D3DSAMP_MAGFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
      RD3DDevice_SetSamplerState_AddressU(d3dr, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
      RD3DDevice_SetSamplerState_AddressV(d3dr, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
      D3DDevice_SetVertexDeclaration(d3dr, d3d->v_decl);
      Direct3DDevice_SetStreamSource_Inline(d3dr, 0, d3d->vertex_buf, 0, sizeof(DrawVerticeFormats));
      RD3DDevice_DrawPrimitive(d3dr, D3DPT_TRIANGLESTRIP, 0, 2);
   }
#endif

#if defined(HAVE_RGUI) || defined(HAVE_RMENU) || defined(HAVE_RMENU_XUI)

#if defined(HAVE_RMENU_XUI) || defined(HAVE_RGUI)
   if (d3d->rgui_texture_enable)
#endif
      xdk_d3d_draw_texture(d3d);
#endif

#if defined(_XBOX1)
   float msg_width  = 60;
   float msg_height = 365;
#elif defined(_XBOX360)
   float msg_width  = (lifecycle_mode_state & (1ULL << MODE_MENU_HD)) ? 160 : 100;
   float msg_height = 120;
#endif

#if 0
   if (msg)
   {
      font_parms.x = msg_width;
      font_parms.y = msg_height;
      d3d->font_ctx->render_msg(d3d, msg, &font_parms);
   }
#endif

   d3d->ctx_driver->update_window_title();

   gfx_ctx_xdk_swap_buffers();

   g_extern.frame_count++;

   return true;
}