示例#1
0
static void rmenu_xui_frame(void)
{
   XUIMessage msg;
   XUIMessageRender msgRender;
   D3DXMATRIX matOrigView;
   D3DVIEWPORT vp_full;
   LPDIRECT3DDEVICE d3dr;
   d3d_video_t *d3d = NULL;
   menu_handle_t *menu   = menu_driver_get_ptr();
   driver_t      *driver = driver_get_ptr();

   if (!menu)
      return;

   d3d = (d3d_video_t*)driver->video_data;
   
   if (!d3d)
      return;

   d3dr = (LPDIRECT3DDEVICE)d3d->dev;

   if (!d3dr)
      return;

   (void)menu;

   vp_full.X = 0;
   vp_full.Y = 0;
   vp_full.Width = d3d->screen_width;
   vp_full.Height = d3d->screen_height;
   vp_full.MinZ = 0.0f;
   vp_full.MaxZ = 1.0f;
   d3d_set_viewport(d3dr, &vp_full);

   app.RunFrame();
   XuiTimersRun();
   XuiRenderBegin( app.GetDC(), D3DCOLOR_ARGB( 255, 0, 0, 0 ) );

   XuiRenderGetViewTransform( app.GetDC(), &matOrigView );

   XuiMessageRender( &msg, &msgRender, app.GetDC(), 0xffffffff, XUI_BLEND_NORMAL );
   XuiSendMessage( app.GetRootObj(), &msg );

   XuiRenderSetViewTransform( app.GetDC(), &matOrigView );

   const char *message = rarch_main_msg_queue_pull();

   if (message)
      xui_render_message(message);
   else
   {
      const char *message = rarch_main_msg_queue_pull();
      if (message)
         xui_render_message(message);
   }

   XuiRenderEnd( app.GetDC() );

   d3d_set_viewport(d3dr, &d3d->final_viewport);
}
示例#2
0
static bool xdk_renderchain_render(void *data, const void *frame,
      unsigned width, unsigned height, unsigned pitch, unsigned rotation)
{
   unsigned i;
   d3d_video_t      *d3d    = (d3d_video_t*)data;
   LPDIRECT3DDEVICE d3dr    = (LPDIRECT3DDEVICE)d3d->dev;
   settings_t *settings     = config_get_ptr();
   global_t   *global       = global_get_ptr();
   xdk_renderchain_t *chain = (xdk_renderchain_t*)d3d->renderchain_data;

   renderchain_blit_to_texture(chain, frame, width, height, pitch);
   renderchain_set_vertices(d3d, 1, width, height);

   d3d_set_texture(d3dr, 0, chain->tex);
   d3d_set_viewport(chain->dev, &d3d->final_viewport);
   d3d_set_sampler_minfilter(d3dr, 0, settings->video.smooth ?
         D3DTEXF_LINEAR : D3DTEXF_POINT);
   d3d_set_sampler_magfilter(d3dr, 0, settings->video.smooth ?
         D3DTEXF_LINEAR : D3DTEXF_POINT);

   d3d_set_vertex_declaration(d3dr, chain->vertex_decl);
   for (i = 0; i < 4; i++)
      d3d_set_stream_source(d3dr, i, chain->vertex_buf, 0, sizeof(Vertex));

   d3d_draw_primitive(d3dr, D3DPT_TRIANGLESTRIP, 0, 2);
   renderchain_set_mvp(d3d, global->video_data.width,
	   global->video_data.height, d3d->dev_rotation);

   return true;
}
示例#3
0
static void rmenu_xui_frame(void)
{
   d3d_video_t *d3d = (d3d_video_t*)driver.video_data;
   LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev;

   D3DVIEWPORT vp_full;
   vp_full.X = 0;
   vp_full.Y = 0;
   vp_full.Width = d3d->screen_width;
   vp_full.Height = d3d->screen_height;
   vp_full.MinZ = 0.0f;
   vp_full.MaxZ = 1.0f;
   d3d_set_viewport(d3dr, &vp_full);

   app.RunFrame();
   XuiTimersRun();
   XuiRenderBegin( app.GetDC(), D3DCOLOR_ARGB( 255, 0, 0, 0 ) );

   D3DXMATRIX matOrigView;
   XuiRenderGetViewTransform( app.GetDC(), &matOrigView );

   XUIMessage msg;
   XUIMessageRender msgRender;
   XuiMessageRender( &msg, &msgRender,
         app.GetDC(), 0xffffffff, XUI_BLEND_NORMAL );
   XuiSendMessage( app.GetRootObj(), &msg );

   XuiRenderSetViewTransform( app.GetDC(), &matOrigView );

   const char *message = msg_queue_pull(xui_msg_queue);

   if (message)
      xui_render_message(message);
   else
   {
      const char *message = msg_queue_pull(g_extern.msg_queue);
      if (message)
         xui_render_message(message);
   }

   XuiRenderEnd( app.GetDC() );

   d3d_set_viewport(d3dr, &d3d->final_viewport);
}
示例#4
0
文件: d3d.cpp 项目: KitoHo/RetroArch
static bool d3d_initialize(d3d_video_t *d3d, const video_info_t *info)
{
   unsigned width, height;
   bool ret             = true;
   settings_t *settings = config_get_ptr();

   if (!d3d)
      return false;

   if (!g_pD3D)
      ret = d3d_init_base(d3d, info);
   else if (d3d->needs_restore)
   {
      D3DPRESENT_PARAMETERS d3dpp;

      d3d_make_d3dpp(d3d, info, &d3dpp);

      if (!d3d_reset(d3d->dev, &d3dpp))
      {
         d3d_deinitialize(d3d);
         d3d_device_free(NULL, g_pD3D);
         g_pD3D = NULL;

         ret = d3d_init_base(d3d, info);
         if (ret)
            RARCH_LOG("[D3D]: Recovered from dead state.\n");
      }
   }

   if (!ret)
      return ret;

   if (!d3d_init_chain(d3d, info))
   {
      RARCH_ERR("Failed to initialize render chain.\n");
      return false;
   }

   video_driver_get_size(&width, &height);
   d3d_set_viewport(d3d,
	   width, height, false, true);

#if defined(_XBOX360)
   strlcpy(settings->path.font, "game:\\media\\Arial_12.xpr",
         sizeof(settings->path.font));
#endif
   if (!font_driver_init_first(NULL, NULL,
            d3d, settings->path.font, 0, false,
            FONT_DRIVER_RENDER_DIRECT3D_API))
   {
      RARCH_ERR("[D3D]: Failed to initialize font renderer.\n");
      return false;
   }

   return true;
}
示例#5
0
static bool texture_image_render(d3d_video_t *d3d,
      struct texture_image *out_img,
      int x, int y, int w, int h, bool force_fullscreen)
{
   LPDIRECT3DTEXTURE d3dt;
   LPDIRECT3DVERTEXBUFFER d3dv;
   void *verts           = NULL;
   float fX              = (float)(x);
   float fY              = (float)(y);

   if (!d3d)
      return false;

   d3dt = (LPDIRECT3DTEXTURE)out_img->texture_buf;
   d3dv = (LPDIRECT3DVERTEXBUFFER)out_img->vertex_buf;

   if (!d3dt || !d3dv)
      return false;

   /* Create the new vertices. */
   Vertex newVerts[] =
   {
      // x,           y,              z,     color, u ,v
      {fX,            fY,             0.0f,  0,     0, 0},
      {fX + w,        fY,             0.0f,  0,     1, 0},
      {fX + w,        fY + h,         0.0f,  0,     1, 1},
      {fX,            fY + h,         0.0f,  0,     0, 1}
   };

   /* Load the existing vertices */
   verts = d3d_vertex_buffer_lock(d3dv);

   if (!verts)
      return false;

   /* Copy the new verts over the old verts */
   memcpy(verts, newVerts, sizeof(newVerts));
   d3d_vertex_buffer_unlock(d3dv);

   d3d_enable_blend_func(d3d->dev);
   d3d_enable_alpha_blend_texture_func(d3d->dev);

   /* Draw the quad. */
   d3d_set_texture(d3d->dev, 0, d3dt);
   d3d_set_stream_source(d3d->dev, 0,
         d3dv, 0, sizeof(Vertex));
   d3d_set_vertex_shader(d3d->dev, D3DFVF_CUSTOMVERTEX, NULL);

   if (force_fullscreen)
      d3d_set_viewport(d3d, w, h, force_fullscreen, false);
   d3d_draw_primitive(d3d->dev, D3DPT_QUADLIST, 0, 1);

   return true;
}
示例#6
0
static void menu_display_d3d_draw(
      unsigned x, unsigned y,
      unsigned width, unsigned height,
      struct gfx_coords *coords,
      void *matrix_data,
      uintptr_t texture,
      enum menu_display_prim_type prim_type
      )
{
   D3DVIEWPORT vp       = {0};
   driver_t     *driver = driver_get_ptr();
   d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(NULL);
   math_matrix_4x4 *mat = (math_matrix_4x4*)matrix_data;

   if (!d3d)
      return;

   /* TODO - edge case */
   if (height <= 0)
      height = 1;

   if (!mat)
      mat = (math_matrix_4x4*)menu_display_d3d_get_default_mvp();
   if (!coords->vertex)
      coords->vertex = &d3d_vertexes[0];
   if (!coords->tex_coord)
      coords->tex_coord = &d3d_tex_coords[0];
   if (!coords->lut_tex_coord)
      coords->lut_tex_coord = &d3d_tex_coords[0];

   vp.X      = x;
   vp.Y      = y;
   vp.Width  = width;
   vp.Height = height;
   vp.MinZ   = 0.0f;
   vp.MaxZ   = 1.0f;

   d3d_set_viewport(d3d->dev, &vp);
   d3d_set_texture(d3d->dev, 0, (LPDIRECT3DTEXTURE)texture);

#if 0
   gl->shader->set_coords(coords);
   gl->shader->set_mvp(driver->video_data, mat);
#endif

   d3d_draw_primitive(d3d->dev, (D3DPRIMITIVETYPE)menu_display_prim_to_d3d_enum(prim_type), 0, coords->vertices);

#if 0
   gl->coords.color     = gl->white_color_ptr;
#endif
}
示例#7
0
文件: d3d.cpp 项目: equil/RetroArch
static void d3d_calculate_rect(d3d_video_t *d3d,
      unsigned width, unsigned height,
   bool keep, float desired_aspect)
{
   settings_t *settings = config_get_ptr();
   global_t   *global   = global_get_ptr();

   if (settings->video.scale_integer)
   {
      struct video_viewport vp = {0};
      video_viewport_get_scaled_integer(&vp, width, height, desired_aspect, keep);
      d3d_set_viewport(d3d, vp.x, vp.y, vp.width, vp.height);
   }
   else if (!keep)
      d3d_set_viewport(d3d, 0, 0, width, height);
   else
   {
      if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
      {
         const video_viewport_t *custom = 
            &global->console.screen.viewports.custom_vp;

		 if (custom)
            d3d_set_viewport(d3d, custom->x, custom->y, 
                  custom->width, custom->height);
      }
      else
      {
         float device_aspect = ((float)width) / ((float)height);

         if (fabsf(device_aspect - desired_aspect) < 0.0001f)
            d3d_set_viewport(d3d, 0, 0, width, height);
         else if (device_aspect > desired_aspect)
         {
            float delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
            d3d_set_viewport(d3d, int(roundf(width * (0.5f - delta))),
                  0, unsigned(roundf(2.0f * width * delta)), height);
         }
         else
         {
            float delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
            d3d_set_viewport(d3d, 0, int(roundf(height * (0.5f - delta))),
                  width, unsigned(roundf(2.0f * height * delta)));
         }
      }
   }
}
示例#8
0
文件: d3d.cpp 项目: OV2/RetroArch
static void d3d_calculate_rect(void *data, unsigned width, unsigned height,
   bool keep, float desired_aspect)
{
   d3d_video_t *d3d = (d3d_video_t*)data;

   if (g_settings.video.scale_integer)
   {
      struct rarch_viewport vp = {0};
      gfx_scale_integer(&vp, width, height, desired_aspect, keep);
      d3d_set_viewport(d3d, vp.x, vp.y, vp.width, vp.height);
   }
   else if (!keep)
      d3d_set_viewport(d3d, 0, 0, width, height);
   else
   {
      if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
      {
         const rarch_viewport_t &custom = g_extern.console.screen.viewports.custom_vp;
         d3d_set_viewport(d3d, custom.x, custom.y, custom.width, custom.height);
      }
      else
      {
         float device_aspect = static_cast<float>(width) / static_cast<float>(height);
         if (fabsf(device_aspect - desired_aspect) < 0.0001f)
            d3d_set_viewport(d3d, 0, 0, width, height);
         else if (device_aspect > desired_aspect)
         {
            float delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
            d3d_set_viewport(d3d, int(roundf(width * (0.5f - delta))), 0, unsigned(roundf(2.0f * width * delta)), height);
         }
         else
         {
            float delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
            d3d_set_viewport(d3d, 0, int(roundf(height * (0.5f - delta))), width, unsigned(roundf(2.0f * height * delta)));
         }
      }
   }
}
示例#9
0
文件: d3d.cpp 项目: equil/RetroArch
static bool texture_image_render(d3d_video_t *d3d,
      struct texture_image *out_img,
      int x, int y, int w, int h, bool force_fullscreen)
{
   void *verts           = NULL;
   LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev;
   float fX              = (float)(x);
   float fY              = (float)(y);

   if (!d3d)
      return false;
   if (!out_img->pixels || !out_img->vertex_buf)
      return false;

   /* Create the new vertices. */
   Vertex newVerts[] =
   {
      // x,           y,              z,     color, u ,v
      {fX,            fY,             0.0f,  0,     0, 0},
      {fX + w,        fY,             0.0f,  0,     1, 0},
      {fX + w,        fY + h,         0.0f,  0,     1, 1},
      {fX,            fY + h,         0.0f,  0,     0, 1}
   };

   /* Load the existing vertices */
   verts = d3d_vertex_buffer_lock(out_img->vertex_buf);

   if (!verts)
      return false;

   /* Copy the new verts over the old verts */
   memcpy(verts, newVerts, sizeof(newVerts));
   d3d_vertex_buffer_unlock(out_img->vertex_buf);

   d3d_enable_blend_func(d3d->dev);

   /* Also blend the texture with the set alpha value. */
   d3d->dev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
   d3d->dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
   d3d->dev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);

   /* Draw the quad. */
   d3d_set_texture(d3dr, 0, out_img->texture_buf);
   d3d_set_stream_source(d3dr, 0,
         out_img->vertex_buf, 0, sizeof(Vertex));
   d3d_set_vertex_shader(d3dr, D3DFVF_CUSTOMVERTEX, NULL);

   if (force_fullscreen)
   {
      D3DVIEWPORT vp = {0};
      vp.Width       = w;
      vp.Height      = h;
      vp.X           = 0;
      vp.Y           = 0;
      vp.MinZ        = 0.0f;
      vp.MaxZ        = 1.0f;
      d3d_set_viewport(d3dr, &vp);
   }
   d3d_draw_primitive(d3dr, D3DPT_QUADLIST, 0, 1);

   return true;
}
示例#10
0
文件: d3d.cpp 项目: equil/RetroArch
static void d3d_overlay_render(d3d_video_t *d3d, overlay_t *overlay)
{
   void *verts;
   unsigned i;
   struct overlay_vertex
   {
      float x, y, z;
      float u, v;
      float r, g, b, a;
   } vert[4];
   float overlay_width, overlay_height;
#ifndef _XBOX1
   LPDIRECT3DVERTEXDECLARATION vertex_decl;
   /* set vertex declaration for overlay. */
   D3DVERTEXELEMENT vElems[4] = {
      {0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT,
         D3DDECLUSAGE_POSITION, 0},
      {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT,
         D3DDECLUSAGE_TEXCOORD, 0},
      {0, 20, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT,
         D3DDECLUSAGE_COLOR, 0},
      D3DDECL_END()
   };
#endif

   if (!d3d)
      return;
   if (!overlay || !overlay->tex)
      return;

   if (!overlay->vert_buf)
   {
      overlay->vert_buf = (LPDIRECT3DVERTEXBUFFER)d3d_vertex_buffer_new(
      d3d->dev, sizeof(vert), 0, 0, D3DPOOL_MANAGED, NULL);

	  if (!overlay->vert_buf)
		  return;
   }

   for (i = 0; i < 4; i++)
   {
      vert[i].z   = 0.5f;
      vert[i].r   = vert[i].g = vert[i].b = 1.0f;
      vert[i].a   = overlay->alpha_mod;
   }

   overlay_width  = d3d->final_viewport.Width;
   overlay_height = d3d->final_viewport.Height;

   vert[0].x      = overlay->vert_coords.x * overlay_width;
   vert[1].x      = (overlay->vert_coords.x + overlay->vert_coords.w)
      * overlay_width;
   vert[2].x      = overlay->vert_coords.x * overlay_width;
   vert[3].x      = (overlay->vert_coords.x + overlay->vert_coords.w)
      * overlay_width;
   vert[0].y      = overlay->vert_coords.y * overlay_height;
   vert[1].y      = overlay->vert_coords.y * overlay_height;
   vert[2].y      = (overlay->vert_coords.y + overlay->vert_coords.h)
      * overlay_height;
   vert[3].y      = (overlay->vert_coords.y + overlay->vert_coords.h)
      * overlay_height;

   vert[0].u      = overlay->tex_coords.x;
   vert[1].u      = overlay->tex_coords.x + overlay->tex_coords.w;
   vert[2].u      = overlay->tex_coords.x;
   vert[3].u      = overlay->tex_coords.x + overlay->tex_coords.w;
   vert[0].v      = overlay->tex_coords.y;
   vert[1].v      = overlay->tex_coords.y;
   vert[2].v      = overlay->tex_coords.y + overlay->tex_coords.h;
   vert[3].v      = overlay->tex_coords.y + overlay->tex_coords.h;

   /* Align texels and vertices. */
   for (i = 0; i < 4; i++)
   {
      vert[i].x  -= 0.5f;
      vert[i].y  += 0.5f;
   }

   overlay->vert_buf->Lock(0, sizeof(vert), &verts, 0);
   memcpy(verts, vert, sizeof(vert));
   d3d_vertex_buffer_unlock(overlay->vert_buf);

   d3d_enable_blend_func(d3d->dev);

#ifndef _XBOX1
   d3d->dev->CreateVertexDeclaration(vElems, &vertex_decl);
   d3d->dev->SetVertexDeclaration(vertex_decl);
   vertex_decl->Release();
#endif

   d3d_set_stream_source(d3d->dev, 0, overlay->vert_buf,
         0, sizeof(overlay_vertex));

   if (overlay->fullscreen)
   {
      /* Set viewport to full window. */
      D3DVIEWPORT vp_full = {0};

      vp_full.X           = 0;
      vp_full.Y           = 0;
      vp_full.Width       = d3d->screen_width;
      vp_full.Height      = d3d->screen_height;
      vp_full.MinZ        = 0.0f;
      vp_full.MaxZ        = 1.0f;
      d3d_set_viewport(d3d->dev, &vp_full);
   }

   /* Render overlay. */
   d3d_set_texture(d3d->dev, 0, overlay->tex);
   d3d_set_sampler_address_u(d3d->dev, 0, D3DTADDRESS_BORDER);
   d3d_set_sampler_address_v(d3d->dev, 0, D3DTADDRESS_BORDER);
   d3d_set_sampler_minfilter(d3d->dev, 0, D3DTEXF_LINEAR);
   d3d_set_sampler_magfilter(d3d->dev, 0, D3DTEXF_LINEAR);
   d3d_draw_primitive(d3d->dev, D3DPT_TRIANGLESTRIP, 0, 2);

   /* Restore previous state. */
   d3d_disable_blend_func(d3d->dev);
   d3d_set_viewport(d3d->dev, &d3d->final_viewport);
}