Beispiel #1
0
static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{
   HRESULT ret;

   if (driver.video_data)
   {
      xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
      // Reinitialize textures as we might have changed pixel formats.
      xdk_d3d_reinit_textures(d3d, video);
      return driver.video_data;
   }

   //we'll just use driver.video_data throughout here because it needs to
   //exist when we delegate initing to the context file
   driver.video_data = (xdk_d3d_video_t*)calloc(1, sizeof(xdk_d3d_video_t));
   if (!driver.video_data)
      return NULL;

   xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;

   d3d->vsync = video->vsync;
   d3d->tex_w = RARCH_SCALE_BASE * video->input_scale;
   d3d->tex_h = RARCH_SCALE_BASE * video->input_scale;

#if defined(_XBOX1)
   d3d->ctx_driver = gfx_ctx_init_first(GFX_CTX_DIRECT3D8_API, 8, 0);
#elif defined(_XBOX360)
   d3d->ctx_driver = gfx_ctx_init_first(GFX_CTX_DIRECT3D9_API, 9, 0);
#endif
   if (d3d->ctx_driver)
   {
      D3DPRESENT_PARAMETERS d3dpp;
      xdk_d3d_generate_pp(&d3dpp, video);

      ret = d3d->d3d_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING,
            &d3dpp, &d3d->d3d_render_device);

      if (ret != S_OK)
         RARCH_ERR("Failed at CreateDevice.\n");
      RD3DDevice_Clear(d3d->d3d_render_device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0);
   }
   else
   {
      free(d3d);
      return NULL;
   }

   RARCH_LOG("Found D3D context: %s\n", d3d->ctx_driver->ident);

   xdk_d3d_init_textures(d3d, video);

#if defined(_XBOX1)
   // use an orthogonal matrix for the projection matrix
   D3DXMATRIX mat;
   D3DXMatrixOrthoOffCenterLH(&mat, 0,  d3d->win_width ,  d3d->win_height , 0, 0.0f, 1.0f);

   d3d->d3d_render_device->SetTransform(D3DTS_PROJECTION, &mat);

   // use an identity matrix for the world and view matrices
   D3DXMatrixIdentity(&mat);
   d3d->d3d_render_device->SetTransform(D3DTS_WORLD, &mat);
   d3d->d3d_render_device->SetTransform(D3DTS_VIEW, &mat);

   ret = d3d->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), 
         D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &d3d->vertex_buf);

   if (ret != S_OK)
   {
      RARCH_ERR("[xdk_d3d_init::] Failed at CreateVertexBuffer.\n");
      return NULL;
   }

   const DrawVerticeFormats init_verts[] = {
      { -1.0f, -1.0f, 1.0f, 0.0f, 1.0f },
      {  1.0f, -1.0f, 1.0f, 1.0f, 1.0f },
      { -1.0f,  1.0f, 1.0f, 0.0f, 0.0f },
      {  1.0f,  1.0f, 1.0f, 1.0f, 0.0f },
   };

   BYTE *verts_ptr;
   RD3DVertexBuffer_Lock(d3d->vertex_buf, 0, 0, &verts_ptr, 0);
   memcpy(verts_ptr, init_verts, sizeof(init_verts));
   RD3DVertexBuffer_Unlock(d3d->vertex_buf);

   RD3DDevice_SetVertexShader(d3d->d3d_render_device, D3DFVF_XYZ | D3DFVF_TEX1);
#elif defined(_XBOX360)
   ret = d3d->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), 
         0, 0, 0, &d3d->vertex_buf, NULL);

   if (ret != S_OK)
   {
      RARCH_ERR("[xdk_d3d_init::] Failed at CreateVertexBuffer.\n");
      return NULL;
   }

   static const DrawVerticeFormats init_verts[] = {
      { -1.0f, -1.0f, 0.0f, 1.0f },
      {  1.0f, -1.0f, 1.0f, 1.0f },
      { -1.0f,  1.0f, 0.0f, 0.0f },
      {  1.0f,  1.0f, 1.0f, 0.0f },
   };

   void *verts_ptr;
   RD3DVertexBuffer_Lock(d3d->vertex_buf, 0, 0, &verts_ptr, 0);
   memcpy(verts_ptr, init_verts, sizeof(init_verts));
   RD3DVertexBuffer_Unlock(d3d->vertex_buf);

   static const D3DVERTEXELEMENT VertexElements[] =
   {
      { 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
      { 0, 2 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
      D3DDECL_END()
   };

   ret = d3d->d3d_render_device->CreateVertexDeclaration(VertexElements, &d3d->v_decl);

   if (ret != S_OK)
   {
      RARCH_ERR("[xdk_d3d_init::] Failed at CreateVertexDeclaration.\n");
   }
#endif

   d3d->ctx_driver->get_video_size(&d3d->win_width, &d3d->win_height);
   RARCH_LOG("Detecting screen resolution: %ux%u.\n", d3d->win_width, d3d->win_height);

   d3d->ctx_driver->swap_interval(d3d->vsync ? 1 : 0);

#ifdef HAVE_HLSL
   if (!hlsl_shader_init())
   {
      RARCH_ERR("Shader init failed.\n");
      d3d->ctx_driver->destroy();
      free(d3d);
      return NULL;
   }

   RARCH_LOG("D3D: Loaded %u program(s).\n", d3d->shader->num_shaders());
#endif

#if 0 /* ifdef HAVE_FBO */
   xdk_d3d_init_fbo(d3d);
#endif

   xdk_d3d_set_rotation(d3d, g_settings.video.rotation);

   //really returns driver.video_data to driver.video_data - see comment above
   return d3d;
}
Beispiel #2
0
static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{
   if (driver.video_data)
      return driver.video_data;

   xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)calloc(1, sizeof(xdk_d3d_video_t));
   if (!d3d)
      return NULL;

   d3d->d3d_device = direct3d_create_ctx(D3D_SDK_VERSION);
   if (!d3d->d3d_device)
   {
      free(d3d);
      RARCH_ERR("Failed to create a D3D8 object.\n");
      return NULL;
   }

   memset(&d3d->d3dpp, 0, sizeof(d3d->d3dpp));

   // Get the "video mode"
   d3d->video_mode = XGetVideoFlags();

   // Check if we are able to use progressive mode
   if(d3d->video_mode & XC_VIDEO_FLAGS_HDTV_480p)
      d3d->d3dpp.Flags = D3DPRESENTFLAG_PROGRESSIVE;
   else
      d3d->d3dpp.Flags = D3DPRESENTFLAG_INTERLACED;

    // Safe mode
    d3d->d3dpp.BackBufferWidth = 640;
    d3d->d3dpp.BackBufferHeight = 480;
    g_console.menus_hd_enable = false;

   // Only valid in PAL mode, not valid for HDTV modes!
   if(XGetVideoStandard() == XC_VIDEO_STANDARD_PAL_I)
   {
      if(d3d->video_mode & XC_VIDEO_FLAGS_PAL_60Hz)
         d3d->d3dpp.FullScreen_RefreshRateInHz = 60;
      else
         d3d->d3dpp.FullScreen_RefreshRateInHz = 50;

      // Check for 16:9 mode (PAL REGION)
      if(d3d->video_mode & XC_VIDEO_FLAGS_WIDESCREEN)
      {
         if(d3d->video_mode & XC_VIDEO_FLAGS_PAL_60Hz)
	      {	//60 Hz, 720x480i
            d3d->d3dpp.BackBufferWidth = 720;
	         d3d->d3dpp.BackBufferHeight = 480;
	      }
	    else
	      {	//50 Hz, 720x576i
           d3d->d3dpp.BackBufferWidth = 720;
           d3d->d3dpp.BackBufferHeight = 576;
	      }
      }
   }
   else
   {
      // Check for 16:9 mode (NTSC REGIONS)
      if(d3d->video_mode & XC_VIDEO_FLAGS_WIDESCREEN)
      {
         d3d->d3dpp.BackBufferWidth = 720;
	      d3d->d3dpp.BackBufferHeight = 480;
      }
   }

   if(XGetAVPack() == XC_AV_PACK_HDTV)
   {
      if(d3d->video_mode & XC_VIDEO_FLAGS_HDTV_480p)
      {
         g_console.menus_hd_enable = false;
         d3d->d3dpp.BackBufferWidth	= 640;
         d3d->d3dpp.BackBufferHeight = 480;
         d3d->d3dpp.Flags = D3DPRESENTFLAG_PROGRESSIVE;
      }
	   else if(d3d->video_mode & XC_VIDEO_FLAGS_HDTV_720p)
	   {
         g_console.menus_hd_enable = true;
         d3d->d3dpp.BackBufferWidth	= 1280;
         d3d->d3dpp.BackBufferHeight = 720;
         d3d->d3dpp.Flags = D3DPRESENTFLAG_PROGRESSIVE;
	   }
	   else if(d3d->video_mode & XC_VIDEO_FLAGS_HDTV_1080i)
	   {
         g_console.menus_hd_enable = true;
         d3d->d3dpp.BackBufferWidth	= 1920;
         d3d->d3dpp.BackBufferHeight = 1080;
         d3d->d3dpp.Flags = D3DPRESENTFLAG_INTERLACED;
	   }
   }


   if(d3d->d3dpp.BackBufferWidth > 640 && ((float)d3d->d3dpp.BackBufferHeight / (float)d3d->d3dpp.BackBufferWidth != 0.75) ||
      ((d3d->d3dpp.BackBufferWidth == 720) && (d3d->d3dpp.BackBufferHeight == 576))) // 16:9
        d3d->d3dpp.Flags |= D3DPRESENTFLAG_WIDESCREEN;

   // no letterboxing in 4:3 mode (if widescreen is unsupported
   d3d->d3dpp.BackBufferFormat                     = D3DFMT_A8R8G8B8;
   d3d->d3dpp.FullScreen_PresentationInterval		= video->vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
   d3d->d3dpp.MultiSampleType                      = D3DMULTISAMPLE_NONE;
   d3d->d3dpp.BackBufferCount                      = 2;
   d3d->d3dpp.EnableAutoDepthStencil               = FALSE;
   d3d->d3dpp.SwapEffect                           = D3DSWAPEFFECT_COPY;

   d3d->d3d_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3d->d3dpp, &d3d->d3d_render_device);

   d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0);

   // use an orthogonal matrix for the projection matrix
   D3DXMATRIX mat;
   D3DXMatrixOrthoOffCenterLH(&mat, 0,  d3d->d3dpp.BackBufferWidth ,  d3d->d3dpp.BackBufferHeight , 0, 0.0f, 1.0f);

   d3d->d3d_render_device->SetTransform(D3DTS_PROJECTION, &mat);

   // use an identity matrix for the world and view matrices
   D3DXMatrixIdentity(&mat);
   d3d->d3d_render_device->SetTransform(D3DTS_WORLD, &mat);
   d3d->d3d_render_device->SetTransform(D3DTS_VIEW, &mat);

   d3d->d3d_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5, 0, &d3d->lpTexture);
   D3DLOCKED_RECT d3dlr;
   d3d->lpTexture->LockRect(0, &d3dlr, NULL, 0);
   memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch);
   d3d->lpTexture->UnlockRect(0);

   d3d->last_width = 512;
   d3d->last_height = 512;

   d3d->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), 
	   D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &d3d->vertex_buf);

   static const DrawVerticeFormats init_verts[] = {
      { -1.0f, -1.0f, 1.0f, 0.0f, 1.0f },
      {  1.0f, -1.0f, 1.0f, 1.0f, 1.0f },
      { -1.0f,  1.0f, 1.0f, 0.0f, 0.0f },
      {  1.0f,  1.0f, 1.0f, 1.0f, 0.0f },
   };

   BYTE *verts_ptr;
   d3d->vertex_buf->Lock(0, 0, &verts_ptr, 0);
   memcpy(verts_ptr, init_verts, sizeof(init_verts));
   d3d->vertex_buf->Unlock();

   d3d->d3d_render_device->SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1);

   // disable lighting
   d3d->d3d_render_device->SetRenderState(D3DRS_LIGHTING, FALSE);

   // disable culling
   d3d->d3d_render_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

   // disable z-buffer
   d3d->d3d_render_device->SetRenderState(D3DRS_ZENABLE, FALSE);

   D3DVIEWPORT vp = {0};
   vp.Width  = d3d->d3dpp.BackBufferWidth;
   vp.Height = d3d->d3dpp.BackBufferHeight;
   vp.MinZ   = 0.0f;
   vp.MaxZ   = 1.0f;
   d3d->d3d_render_device->SetViewport(&vp);

   if(g_console.viewports.custom_vp.width == 0)
      g_console.viewports.custom_vp.width = vp.Width;

   if(g_console.viewports.custom_vp.height == 0)
      g_console.viewports.custom_vp.height = vp.Height;

   xdk_d3d_set_rotation(d3d, g_console.screen_orientation);

   d3d->vsync = video->vsync;

   // load debug font (toggle option in later revisions ?)
   XFONT_OpenDefaultFont(&d3d->debug_font);
   d3d->debug_font->SetBkMode(XFONT_TRANSPARENT);
   d3d->debug_font->SetBkColor(D3DCOLOR_ARGB(100,0,0,0));
   d3d->debug_font->SetTextHeight(14);
   d3d->debug_font->SetTextAntialiasLevel(d3d->debug_font->GetTextAntialiasLevel());

   font_x = 0;
   font_y = 0;

   // TODO: place this somewhere else outside of xdk_d3d8.cpp
#ifdef SHOW_DEBUG_INFO
   g_console.fps_info_enable = true;
#endif

   return d3d;
}
Beispiel #3
0
static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{
   if (driver.video_data)
      return driver.video_data;

   xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)calloc(1, sizeof(xdk_d3d_video_t));
   if (!d3d)
      return NULL;

   d3d->d3d_device = direct3d_create_ctx(D3D_SDK_VERSION);
   if (!d3d->d3d_device)
   {
      free(d3d);
      return NULL;
   }

   memset(&d3d->d3dpp, 0, sizeof(d3d->d3dpp));

   // no letterboxing in 4:3 mode (if widescreen is
   // unsupported
   // Get video settings
   memset(&d3d->video_mode, 0, sizeof(d3d->video_mode));
   XGetVideoMode(&d3d->video_mode);

   if(!d3d->video_mode.fIsWideScreen)
      d3d->d3dpp.Flags |= D3DPRESENTFLAG_NO_LETTERBOX;

   g_console.menus_hd_enable = d3d->video_mode.fIsHiDef;
   
   d3d->d3dpp.BackBufferWidth         = d3d->video_mode.fIsHiDef ? 1280 : 640;
   d3d->d3dpp.BackBufferHeight        = d3d->video_mode.fIsHiDef ? 720 : 480;

   if(g_console.gamma_correction_enable)
   {
      d3d->d3dpp.BackBufferFormat        = g_console.color_format ? (D3DFORMAT)MAKESRGBFMT(D3DFMT_A8R8G8B8) : (D3DFORMAT)MAKESRGBFMT(D3DFMT_LIN_A1R5G5B5);
      d3d->d3dpp.FrontBufferFormat       = (D3DFORMAT)MAKESRGBFMT(D3DFMT_LE_X8R8G8B8);
   }
   else
   {
      d3d->d3dpp.BackBufferFormat        = g_console.color_format ? D3DFMT_A8R8G8B8 : D3DFMT_LIN_A1R5G5B5;
      d3d->d3dpp.FrontBufferFormat       = D3DFMT_LE_X8R8G8B8;
   }
   d3d->d3dpp.MultiSampleQuality      = 0;
   d3d->d3dpp.PresentationInterval    = video->vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;

   d3d->d3dpp.MultiSampleType         = D3DMULTISAMPLE_NONE;
   d3d->d3dpp.BackBufferCount         = 2;
   d3d->d3dpp.EnableAutoDepthStencil  = FALSE;
   d3d->d3dpp.SwapEffect              = D3DSWAPEFFECT_DISCARD;

   d3d->d3d_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING,
	   &d3d->d3dpp, &d3d->d3d_render_device);

#ifdef HAVE_HLSL
   hlsl_init(g_settings.video.cg_shader_path, d3d->d3d_render_device);
#endif

   d3d->d3d_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5,
      0, &d3d->lpTexture
   , NULL
   );

#ifdef HAVE_FBO
   xdk_d3d_init_fbo(d3d);
#endif

   D3DLOCKED_RECT d3dlr;
   d3d->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
   memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch);
   d3d->lpTexture->UnlockRect(0);

   d3d->last_width = 512;
   d3d->last_height = 512;

   d3d->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), 
	   0, 0, 0, &d3d->vertex_buf, NULL);

   static const DrawVerticeFormats init_verts[] = {
      { -1.0f, -1.0f, 0.0f, 1.0f },
      {  1.0f, -1.0f, 1.0f, 1.0f },
      { -1.0f,  1.0f, 0.0f, 0.0f },
      {  1.0f,  1.0f, 1.0f, 0.0f },
   };
   
   void *verts_ptr;
   d3d->vertex_buf->Lock(0, 0, &verts_ptr, 0);
   memcpy(verts_ptr, init_verts, sizeof(init_verts));
   d3d->vertex_buf->Unlock();

   static const D3DVERTEXELEMENT VertexElements[] =
   {
      { 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
      { 0, 2 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
      D3DDECL_END()
   };

   d3d->d3d_render_device->CreateVertexDeclaration(VertexElements, &d3d->v_decl);
   
   d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET,
	   0xff000000, 1.0f, 0);

   d3d->d3d_render_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
   d3d->d3d_render_device->SetRenderState(D3DRS_ZENABLE, FALSE);

   D3DVIEWPORT vp = {0};
   vp.Width  = d3d->video_mode.fIsHiDef ? 1280 : 640;
   vp.Height = d3d->video_mode.fIsHiDef ? 720 : 480;
   vp.MinZ   = 0.0f;
   vp.MaxZ   = 1.0f;
   d3d->d3d_render_device->SetViewport(&vp);

   if(g_console.viewports.custom_vp.width == 0)
      g_console.viewports.custom_vp.width = vp.Width;

   if(g_console.viewports.custom_vp.height == 0)
      g_console.viewports.custom_vp.height = vp.Height;

   xdk_d3d_set_rotation(d3d, g_console.screen_orientation);

   d3d->vsync = video->vsync;

   return d3d;
}