static void get_display_device_id(WCHAR *szIdentifierBuffer) { static const WCHAR szNA[] = {'n','/','a',0}; HRESULT hr = E_FAIL; HMODULE d3d9_handle; IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT) = NULL; IDirect3D9 *pD3d = NULL; D3DADAPTER_IDENTIFIER9 adapter_ident; /* Retrieves the display device identifier from the d3d9 implementation. */ d3d9_handle = LoadLibraryA("d3d9.dll"); if(d3d9_handle) pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9"); if(pDirect3DCreate9) pD3d = pDirect3DCreate9(D3D_SDK_VERSION); if(pD3d) hr = IDirect3D9_GetAdapterIdentifier(pD3d, D3DADAPTER_DEFAULT, 0, &adapter_ident); if(SUCCEEDED(hr)) { StringFromGUID2(&adapter_ident.DeviceIdentifier, szIdentifierBuffer, 39); } else { memcpy(szIdentifierBuffer, szNA, sizeof(szNA)); } if (pD3d) IDirect3D9_Release(pD3d); if (d3d9_handle) FreeLibrary(d3d9_handle); }
static void test_qi_base_to_ex(void) { IDirect3D9 *d3d9 = pDirect3DCreate9(D3D_SDK_VERSION); IDirect3D9Ex *d3d9ex = (void *) 0xdeadbeef; IDirect3DDevice9 *device; IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef; HRESULT hr; HWND window = create_window(); D3DPRESENT_PARAMETERS present_parameters; if (!d3d9) { skip("Direct3D9 is not available\n"); return; } hr = IDirect3D9_QueryInterface(d3d9, &IID_IDirect3D9Ex, (void **) &d3d9ex); ok(hr == E_NOINTERFACE, "IDirect3D9::QueryInterface for IID_IDirect3D9Ex returned %08x, expected E_NOINTERFACE\n", hr); ok(d3d9ex == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9ex); if(d3d9ex) IDirect3D9Ex_Release(d3d9ex); memset(&present_parameters, 0, sizeof(present_parameters)); present_parameters.Windowed = TRUE; present_parameters.hDeviceWindow = window; present_parameters.SwapEffect = D3DSWAPEFFECT_COPY; present_parameters.BackBufferWidth = 640; present_parameters.BackBufferHeight = 480; present_parameters.EnableAutoDepthStencil = FALSE; present_parameters.AutoDepthStencilFormat = D3DFMT_D16; hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device); if(FAILED(hr)) { skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n"); goto out; } hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx); ok(hr == E_NOINTERFACE, "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected E_NOINTERFACE\n", hr); ok(deviceEx == NULL, "QueryInterface returned interface %p, expected NULL\n", deviceEx); if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx); IDirect3DDevice9_Release(device); out: IDirect3D9_Release(d3d9); DestroyWindow(window); }
CString RageDisplay_D3D::Init( VideoModeParams p ) { GraphicsWindow::Initialize(); LOG->Trace( "RageDisplay_D3D::RageDisplay_D3D()" ); LOG->MapLog("renderer", "Current renderer: Direct3D"); typedef IDirect3D9 * (WINAPI * Direct3DCreate9_t) (UINT SDKVersion); Direct3DCreate9_t pDirect3DCreate9; #if defined(XBOX) pDirect3DCreate8 = Direct3DCreate8; #else g_D3D9_Module = LoadLibrary("D3D9.dll"); if(!g_D3D9_Module) return D3D_NOT_INSTALLED; pDirect3DCreate9 = (Direct3DCreate9_t) GetProcAddress(g_D3D9_Module, "Direct3DCreate9"); if(!pDirect3DCreate9) { LOG->Trace( "Direct3DCreate9 not found" ); return D3D_NOT_INSTALLED; } #endif g_pd3d = pDirect3DCreate9( D3D_SDK_VERSION ); if(!g_pd3d) { LOG->Trace( "Direct3DCreate9 failed" ); return D3D_NOT_INSTALLED; } if( FAILED( g_pd3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &g_DeviceCaps) ) ) return "Your system is reporting that Direct3D hardware acceleration is not available. " "Please obtain an updated driver from your video card manufacturer.\n\n"; D3DADAPTER_IDENTIFIER9 identifier; g_pd3d->GetAdapterIdentifier( D3DADAPTER_DEFAULT, 0, &identifier ); LOG->Trace( "Driver: %s\n" "Description: %s\n" "Max texture size: %d\n" "Alpha in palette: %s\n", identifier.Driver, identifier.Description, g_DeviceCaps.MaxTextureWidth, (g_DeviceCaps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE) ? "yes" : "no" ); LOG->Trace( "This display adaptor supports the following modes:" ); D3DDISPLAYMODE mode; UINT modeCount = g_pd3d->GetAdapterModeCount(D3DADAPTER_DEFAULT, g_DefaultAdapterFormat); for( UINT u=0; u<modeCount; u++ ) if( SUCCEEDED( g_pd3d->EnumAdapterModes( D3DADAPTER_DEFAULT, g_DefaultAdapterFormat, u, &mode ) ) ) LOG->Trace( " %ux%u %uHz, format %d", mode.Width, mode.Height, mode.RefreshRate, mode.Format ); g_PaletteIndex.clear(); for( int i = 0; i < 256; ++i ) g_PaletteIndex.push_back(i); // Save the original desktop format. g_pd3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &g_DesktopMode ); /* Up until now, all we've done is set up g_pd3d and do some queries. Now, * actually initialize the window. Do this after as many error conditions * as possible, because if we have to shut it down again we'll flash a window * briefly. */ bool bIgnore = false; return SetVideoMode( p, bIgnore ); }
HRESULT CDirect3D::InitD3D(void) { IDirect3D9 *(APIENTRY *pDirect3DCreate9)(UINT) = (IDirect3D9 *(APIENTRY *)(UINT))GetProcAddress(mhmodDX9, "Direct3DCreate9"); if(!pDirect3DCreate9) return E_FAIL; // create the IDirect3D9 object pD3D9 = pDirect3DCreate9(D3D_SDK_VERSION); if(pD3D9 == NULL) return E_FAIL; D3DCAPS9 d3dCaps; // get device capabilities ZeroMemory(&d3dCaps, sizeof(d3dCaps)); if(FAILED(pD3D9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps))) return E_FAIL; // get the display mode D3DDISPLAYMODE d3ddm; pD3D9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm); d3dpp.BackBufferFormat = d3ddm.Format; HRESULT hr; // Check if hardware vertex processing is available if(d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { // Create device with hardware vertex processing hr = pD3D9->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING|0x00000800L|D3DCREATE_FPU_PRESERVE, &d3dpp, &pD3DDevice9); } else { // Create device with software vertex processing hr = pD3D9->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING|0x00000800L|D3DCREATE_FPU_PRESERVE, &d3dpp, &pD3DDevice9); } // Make sure device was created if(FAILED(hr)) { LOG_MSG("D3D:Unable to create D3D device!"); return E_FAIL; } if(FAILED(pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8))) { if(FAILED(pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R5G6B5))) { DestroyD3D(); LOG_MSG("Error: Cannot find a working texture color format!"); return E_FAIL; } bpp16 = true; LOG_MSG("D3D:Running in 16-bit color mode"); } if(d3dCaps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) { #if LOG_D3D LOG_MSG("D3D:Square-only textures"); #endif square = true; } else { #if LOG_D3D LOG_MSG("D3D:Non-square textures"); #endif square = false; } if(d3dCaps.TextureCaps & D3DPTEXTURECAPS_POW2) { if(d3dCaps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) { #if LOG_D3D LOG_MSG("D3D:Conditional non-pow2 texture size support"); #endif pow2 = false; } else { #if LOG_D3D LOG_MSG("D3D:Textures must be a power of 2 in size"); #endif pow2 = true; } } else { #if LOG_D3D LOG_MSG("D3D:Textures do not need to be a power of 2 in size"); #endif pow2 = false; } if(d3dCaps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) { #if LOG_D3D LOG_MSG("D3D:Dynamic textures supported"); #endif dynamic = true; } else { LOG_MSG("D3D:Dynamic textures NOT supported. Performance will suffer!"); dynamic = false; } #if LOG_D3D LOG_MSG("D3D:Max texture width: %d", d3dCaps.MaxTextureWidth); LOG_MSG("D3D:Max texture height: %d", d3dCaps.MaxTextureHeight); #endif if((d3dCaps.MaxTextureWidth < 1024) || (d3dCaps.MaxTextureHeight < 1024)) { DestroyD3D(); LOG_MSG("Error: Your card does not support large textures!"); return E_FAIL; } #if C_D3DSHADERS // allow scale2x_ps14.fx with 1.4 shaders, everything else requires 2.0 if(d3dCaps.PixelShaderVersion >= D3DPS_VERSION(1,4)) { #if LOG_D3D LOG_MSG("D3D:Hardware PS version %d.%d", D3DSHADER_VERSION_MAJOR(d3dCaps.PixelShaderVersion), D3DSHADER_VERSION_MINOR(d3dCaps.PixelShaderVersion)); #endif if(d3dCaps.PixelShaderVersion == D3DPS_VERSION(1,4)) LOG_MSG("D3D:Hardware PS version 1.4 detected. Most shaders probably won't work..."); if((d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && (dynamic)) { psEnabled = true; square = true; pow2 = true; // pow2 texture size has to be enabled as well } else { LOG_MSG("D3D:Error when initializing pixel shader support. Disabling shaders."); psEnabled = false; } } else { LOG_MSG("D3D:Hardware PS version too low. Disabling support for shaders."); psEnabled = false; } #endif DWORD dwNumAdapterModes; D3DDISPLAYMODE DisplayMode; DWORD m; dwNumModes = 0; if(bpp16) dwNumAdapterModes = pD3D9->GetAdapterModeCount(D3DADAPTER_DEFAULT, D3DFMT_R5G6B5); else dwNumAdapterModes = pD3D9->GetAdapterModeCount(D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8); if(dwNumAdapterModes == 0) { LOG_MSG("D3D:No display modes found"); return E_FAIL; } #if LOG_D3D LOG_MSG("D3D:Found %d display modes", dwNumAdapterModes); #endif modes = (D3DDISPLAYMODE*)malloc(sizeof(D3DDISPLAYMODE)*dwNumAdapterModes); if(!modes) { LOG_MSG("D3D:Error allocating memory!"); DestroyD3D(); return E_FAIL; } for(iMode=0;iMode<dwNumAdapterModes;iMode++) { // Get the display mode attributes if(bpp16) pD3D9->EnumAdapterModes(D3DADAPTER_DEFAULT, D3DFMT_R5G6B5, iMode, &DisplayMode); else pD3D9->EnumAdapterModes(D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8, iMode, &DisplayMode); // Check if the mode already exists for(m=0;m<dwNumModes;m++) { if((modes[m].Width == DisplayMode.Width) && (modes[m].Height == DisplayMode.Height) && (modes[m].Format == DisplayMode.Format)) break; } // If we found a new mode, add it to the list of modes if(m==dwNumModes) { #if LOG_D3D LOG_MSG("D3D:Display mode: %dx%dx%d", DisplayMode.Width, DisplayMode.Height, DisplayMode.Format); #endif // Try to sort resolutions if(dwNumModes>0) { if(((modes[m - 1].Width == DisplayMode.Width) && (modes[m - 1].Height > DisplayMode.Height)) || (modes[m - 1].Width > DisplayMode.Width)) { modes[m].Width = modes[m - 1].Width; modes[m].Height = modes[m - 1].Height; modes[m].Format = modes[m - 1].Format; m--; } } modes[m].Width = DisplayMode.Width; modes[m].Height = DisplayMode.Height; modes[m].Format = DisplayMode.Format; modes[m].RefreshRate = 0; ++dwNumModes; } } // Free some unused memory modes = (D3DDISPLAYMODE*)realloc(modes, sizeof(D3DDISPLAYMODE)*dwNumModes); if(!modes) { LOG_MSG("D3D:Error allocating memory!"); DestroyD3D(); return E_FAIL; } dwTexHeight = 0; dwTexWidth = 0; return S_OK; }