/// <summary> /// <c>wGetCaps</c> /// </summary> /// <remarks> /// </remarks> /// <param name="d3dDevice7"></param> /// <param name="lpD3DHWDevDesc"></param> /// <returns></returns> HRESULT __stdcall wGetCaps( LPDIRECT3DDEVICE7 d3dDevice7, LPD3DDEVICEDESC7 lpD3DHWDevDesc) { PSTR pszErrorMessage; HRESULT hResult; InternalFunctionSpew("GameOS_Direct3D", "GetCaps(0x%x)", d3dDevice7); hResult = d3dDevice7->GetCaps(lpD3DHWDevDesc); if (FAILED(hResult)) { pszErrorMessage = ErrorNumberToMessage(hResult); if ( InternalFunctionPause("FAILED (0x%x - %s) - GetCaps(0x%x)", hResult, pszErrorMessage, d3dDevice7) ) ENTER_DEBUGGER; } return hResult; }
HRESULT CTextureHolder::Restore( LPDIRECT3DDEVICE7 pd3dDevice ) { // Release any previously created objects SAFE_RELEASE( m_pddsSurface ); // Check params if( NULL == pd3dDevice ) return DDERR_INVALIDPARAMS; // Get the device caps D3DDEVICEDESC7 ddDesc; if( FAILED( pd3dDevice->GetCaps( &ddDesc) ) ) return E_FAIL; // Setup the new surface desc DDSURFACEDESC2 ddsd; D3DUtil_InitSurfaceDesc( ddsd ); ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH| DDSD_PIXELFORMAT|DDSD_TEXTURESTAGE; ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.dwTextureStage = 0; //m_dwStage; ddsd.dwWidth = m_dwWidth; ddsd.dwHeight = m_dwHeight; // Turn on texture management for hardware devices if( ddDesc.deviceGUID == IID_IDirect3DHALDevice ) ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE; else if( ddDesc.deviceGUID == IID_IDirect3DTnLHalDevice ) ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE; else ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; // Adjust width and height to be powers of 2, if the device requires it if( ddDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2 ) { for( ddsd.dwWidth=1; m_dwWidth>ddsd.dwWidth; ddsd.dwWidth<<=1 ); for( ddsd.dwHeight=1; m_dwHeight>ddsd.dwHeight; ddsd.dwHeight<<=1 ); } // Limit max texture sizes, if the driver can't handle large textures DWORD dwMaxWidth = ddDesc.dwMaxTextureWidth; DWORD dwMaxHeight = ddDesc.dwMaxTextureHeight; ddsd.dwWidth = min( ddsd.dwWidth, ( dwMaxWidth ? dwMaxWidth : 256 ) ); ddsd.dwHeight = min( ddsd.dwHeight, ( dwMaxHeight ? dwMaxHeight : 256 ) ); // Make the texture square, if the driver requires it if( ddDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY ) { if( ddsd.dwWidth > ddsd.dwHeight ) ddsd.dwHeight = ddsd.dwWidth; else ddsd.dwWidth = ddsd.dwHeight; } // Setup the structure to be used for texture enumration. TEXTURESEARCHINFO tsi; tsi.bFoundGoodFormat = FALSE; tsi.pddpf = &ddsd.ddpfPixelFormat; tsi.dwDesiredBPP = m_dwBPP; tsi.bUsePalette = ( m_dwBPP <= 8 ); tsi.bUseAlpha = m_bHasMyAlpha; if( m_dwFlags & D3DTEXTR_16BITSPERPIXEL ) tsi.dwDesiredBPP = 16; else if( m_dwFlags & D3DTEXTR_32BITSPERPIXEL ) tsi.dwDesiredBPP = 32; if( m_dwFlags & (D3DTEXTR_TRANSPARENTWHITE|D3DTEXTR_TRANSPARENTBLACK) ) { if( tsi.bUsePalette ) { if( ddDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE ) { tsi.bUseAlpha = TRUE; tsi.bUsePalette = TRUE; } else { tsi.bUseAlpha = TRUE; tsi.bUsePalette = FALSE; } } } // Enumerate the texture formats, and find the closest device-supported // texture pixel format pd3dDevice->EnumTextureFormats( TextureSearchCallback, &tsi ); // If we couldn't find a format, let's try a default format if( FALSE == tsi.bFoundGoodFormat ) { tsi.bUsePalette = FALSE; tsi.dwDesiredBPP = 16; pd3dDevice->EnumTextureFormats( TextureSearchCallback, &tsi ); // If we still fail, we cannot create this texture if( FALSE == tsi.bFoundGoodFormat ) return E_FAIL; } // Get the DirectDraw interface for creating surfaces LPDIRECTDRAW7 pDD; LPDIRECTDRAWSURFACE7 pddsRender; pd3dDevice->GetRenderTarget( &pddsRender ); pddsRender->GetDDInterface( (VOID**)&pDD ); pddsRender->Release(); // Create a new surface for the texture HRESULT hr = pDD->CreateSurface( &ddsd, &m_pddsSurface, NULL ); // Done with DDraw pDD->Release(); if( FAILED(hr) ) return hr; // For bitmap-based textures, copy the bitmap image. if( m_hbmBitmap ) return CopyBitmapToSurface(); // At this point, code can be added to handle other file formats (such as // .dds files, .jpg files, etc.). return S_OK; }