//------------------------------------------------------------------------------------- // Name: InitD3D() // Desc: Initializes Direct3D //------------------------------------------------------------------------------------- HRESULT InitD3D() { // Create the D3D object. Direct3D* pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if( !pD3D ) return E_FAIL; // Set up the structure used to create the D3DDevice. D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); XVIDEO_MODE VideoMode; XGetVideoMode( &VideoMode ); g_bWidescreen = VideoMode.fIsWideScreen; d3dpp.BackBufferWidth = min( VideoMode.dwDisplayWidth, 1280 ); d3dpp.BackBufferHeight = min( VideoMode.dwDisplayHeight, 720 ); d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // Create the Direct3D device. if( FAILED( pD3D->CreateDevice( 0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) ) return E_FAIL; return S_OK; }
//------------------------------------------------------------------------------------- // Get screen size //------------------------------------------------------------------------------------- void XDKGlGetScreenSize(int * width, int * height) { XVIDEO_MODE VideoMode; XGetVideoMode( &VideoMode ); //*width = VideoMode.dwDisplayWidth; //*height = VideoMode.dwDisplayHeight; *width = 1280; *height = 720; }
//----------------------------------------------------------------------------- // Purpose: Begins playback of a movie // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool VideoPanel::BeginPlayback( const char *pFilename ) { #ifdef _X360 XVIDEO_MODE videoMode; XGetVideoMode( &videoMode ); // for 50Hz PAL, load a 25Hz version of the ep1_recap movie. if( ( videoMode.RefreshRate < 59.0f ) && ( Q_stricmp( pFilename, "media/ep1_recap.bik" ) == 0 ) ) { pFilename = "media/ep1_recap_25fps.bik"; } #endif // Destroy any previously allocated video if ( m_BIKHandle != BIKHANDLE_INVALID ) { bik->DestroyMaterial( m_BIKHandle ); m_BIKHandle = BIKHANDLE_INVALID; } // Load and create our BINK video m_BIKHandle = bik->CreateMaterial( "VideoBIKMaterial", pFilename, "GAME" ); if ( m_BIKHandle == BIKHANDLE_INVALID ) return false; // We want to be the sole audio source // FIXME: This may not always be true! enginesound->NotifyBeginMoviePlayback(); int nWidth, nHeight; bik->GetFrameSize( m_BIKHandle, &nWidth, &nHeight ); bik->GetTexCoordRange( m_BIKHandle, &m_flU, &m_flV ); m_pMaterial = bik->GetMaterial( m_BIKHandle ); float flFrameRatio = ( (float) GetWide() / (float) GetTall() ); float flVideoRatio = ( (float) nWidth / (float) nHeight ); if ( flVideoRatio > flFrameRatio ) { m_nPlaybackWidth = GetWide(); m_nPlaybackHeight = ( GetWide() / flVideoRatio ); } else if ( flVideoRatio < flFrameRatio ) { m_nPlaybackWidth = ( GetTall() * flVideoRatio ); m_nPlaybackHeight = GetTall(); } else { m_nPlaybackWidth = GetWide(); m_nPlaybackHeight = GetTall(); } return true; }
static void gfx_ctx_d3d_get_video_size(void *data, unsigned *width, unsigned *height) { #ifdef _XBOX d3d_video_t *d3d = (d3d_video_t*)data; (void)width; (void)height; #if defined(_XBOX360) XVIDEO_MODE video_mode; XGetVideoMode(&video_mode); *width = video_mode.dwDisplayWidth; *height = video_mode.dwDisplayHeight; d3d->resolution_hd_enable = false; if(video_mode.fIsHiDef) { *width = 1280; *height = 720; d3d->resolution_hd_enable = true; } else { *width = 640; *height = 480; } widescreen_mode = video_mode.fIsWideScreen; #elif defined(_XBOX1) DWORD video_mode = XGetVideoFlags(); *width = 640; *height = 480; widescreen_mode = false; /* Only valid in PAL mode, not valid for HDTV modes! */ if(XGetVideoStandard() == XC_VIDEO_STANDARD_PAL_I) { /* Check for 16:9 mode (PAL REGION) */ if(video_mode & XC_VIDEO_FLAGS_WIDESCREEN) { *width = 720; //60 Hz, 720x480i if(video_mode & XC_VIDEO_FLAGS_PAL_60Hz) *height = 480; else //50 Hz, 720x576i *height = 576; widescreen_mode = true; } } else { /* Check for 16:9 mode (NTSC REGIONS) */ if(video_mode & XC_VIDEO_FLAGS_WIDESCREEN) { *width = 720; *height = 480; widescreen_mode = true; } } if(XGetAVPack() == XC_AV_PACK_HDTV) { if(video_mode & XC_VIDEO_FLAGS_HDTV_480p) { *width = 640; *height = 480; widescreen_mode = false; d3d->resolution_hd_enable = true; } else if(video_mode & XC_VIDEO_FLAGS_HDTV_720p) { *width = 1280; *height = 720; widescreen_mode = true; d3d->resolution_hd_enable = true; } else if(video_mode & XC_VIDEO_FLAGS_HDTV_1080i) { *width = 1920; *height = 1080; widescreen_mode = true; d3d->resolution_hd_enable = true; } } #endif #endif }
//-------------------------------------------------------------------------------------- // Name: Create() // Desc: Initialize the class, create D3D and the font texture //-------------------------------------------------------------------------------------- HRESULT Console::Create( LPCSTR strFontFileName, D3DCOLOR colBackColor, D3DCOLOR colTextColor, UINT nLines ) { // Create Direct3D LPDIRECT3D9 pD3D = Direct3DCreate9( D3D_SDK_VERSION ); // Check video mode settings XVIDEO_MODE VideoMode; ZeroMemory( &VideoMode, sizeof( VideoMode ) ); XGetVideoMode( &VideoMode ); BOOL bEnable720p = VideoMode.dwDisplayWidth >= 1280; m_d3dpp.BackBufferWidth = bEnable720p ? SCREEN_SIZE_X_720p : SCREEN_SIZE_X_DEFAULT; m_d3dpp.BackBufferHeight = bEnable720p ? SCREEN_SIZE_Y_720p : SCREEN_SIZE_Y_DEFAULT; // Calculate the safe area UINT uiSafeAreaPct = bEnable720p ? SAFE_AREA_PCT_HDTV : SAFE_AREA_PCT_4x3; m_cxSafeArea = ( m_d3dpp.BackBufferWidth * uiSafeAreaPct ) / 100; m_cySafeArea = ( m_d3dpp.BackBufferHeight * uiSafeAreaPct ) / 100; m_cxSafeAreaOffset = ( m_d3dpp.BackBufferWidth - m_cxSafeArea ) / 2; m_cySafeAreaOffset = ( m_d3dpp.BackBufferHeight - m_cySafeArea ) / 2; // Create the D3D device HRESULT hr = pD3D->CreateDevice( 0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_d3dpp, ( ::D3DDevice** )&m_pd3dDevice ); if( FAILED( hr ) ) { ATG_PrintError( "Could not create D3D device!\n" ); DebugBreak(); } // Allow global access to the device g_pd3dDevice = m_pd3dDevice; // Create the font hr = m_Font.Create( strFontFileName ); if( FAILED( hr ) ) { ATG_PrintError( "Could not create font.\n" ); DebugBreak(); } // Save the colors m_colBackColor = colBackColor; m_colTextColor = colTextColor; // Calculate the number of lines on the screen FLOAT fCharWidth, fCharHeight; m_Font.GetTextExtent( L"i", &fCharWidth, &fCharHeight, FALSE ); m_cScreenHeight = ( UINT )( m_cySafeArea / fCharHeight ); m_cScreenWidth = ( UINT )( m_cxSafeArea / fCharWidth ); m_cScreenHeightVirtual = max( m_cScreenHeight, nLines ); m_fLineHeight = fCharHeight; // Allocate memory to hold the lines m_Buffer = new WCHAR[ m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) ]; m_Lines = new WCHAR*[ m_cScreenHeightVirtual ]; // Set the line pointers as indexes into the buffer for( UINT i = 0; i < m_cScreenHeightVirtual; i++ ) { m_Lines[ i ] = m_Buffer + ( m_cScreenWidth + 1 ) * i; } m_bSuspendFlag = FALSE; // Clear the screen Clear(); return hr; }
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; }
static void gfx_ctx_xdk_get_video_size(unsigned *width, unsigned *height) { #if defined(_XBOX360) XVIDEO_MODE video_mode; XGetVideoMode(&video_mode); *width = video_mode.dwDisplayWidth; *height = video_mode.dwDisplayHeight; if(video_mode.fIsHiDef) { *width = 1280; *height = 720; g_extern.lifecycle_state |= (1ULL << MODE_MENU_HD); } else { *width = 640; *height = 480; g_extern.lifecycle_state &= ~(1ULL << MODE_MENU_HD); } if(video_mode.fIsWideScreen) g_extern.lifecycle_state |= (1ULL << MODE_MENU_WIDESCREEN); else g_extern.lifecycle_state &= ~(1ULL << MODE_MENU_WIDESCREEN); #elif defined(_XBOX1) DWORD video_mode = XGetVideoFlags(); *width = 640; *height = 480; // Only valid in PAL mode, not valid for HDTV modes! if(XGetVideoStandard() == XC_VIDEO_STANDARD_PAL_I) { // Check for 16:9 mode (PAL REGION) if(video_mode & XC_VIDEO_FLAGS_WIDESCREEN) { if(video_mode & XC_VIDEO_FLAGS_PAL_60Hz) { //60 Hz, 720x480i *width = 720; *height = 480; } else { //50 Hz, 720x576i *width = 720; *height = 576; } g_extern.lifecycle_state |= (1ULL << MODE_MENU_WIDESCREEN); } else g_extern.lifecycle_state &= ~(1ULL << MODE_MENU_WIDESCREEN); } else { // Check for 16:9 mode (NTSC REGIONS) if(video_mode & XC_VIDEO_FLAGS_WIDESCREEN) { *width = 720; *height = 480; g_extern.lifecycle_state |= (1ULL << MODE_MENU_WIDESCREEN); } else g_extern.lifecycle_state &= ~(1ULL << MODE_MENU_WIDESCREEN); } if(XGetAVPack() == XC_AV_PACK_HDTV) { if(video_mode & XC_VIDEO_FLAGS_HDTV_480p) { *width = 640; *height = 480; g_extern.lifecycle_state &= ~(1ULL << MODE_MENU_WIDESCREEN); g_extern.lifecycle_state |= (1ULL << MODE_MENU_HD); } else if(video_mode & XC_VIDEO_FLAGS_HDTV_720p) { *width = 1280; *height = 720; g_extern.lifecycle_state |= (1ULL << MODE_MENU_WIDESCREEN); g_extern.lifecycle_state |= (1ULL << MODE_MENU_HD); } else if(video_mode & XC_VIDEO_FLAGS_HDTV_1080i) { *width = 1920; *height = 1080; g_extern.lifecycle_state |= (1ULL << MODE_MENU_WIDESCREEN); g_extern.lifecycle_state |= (1ULL << MODE_MENU_HD); } } #else /* TODO: implement */ (void)width; (void)height; #endif }