LPDIRECT3DTEXTURE9 DX9RenderSystem::GetTextureCache( Texture* tex ) { TextureRC*& rc = (TextureRC*&)tex->mCache; if( !rc ) rc = new TextureRC( ); if( tex->IsDirty( ) ) { if( mCacheCount >= DX9MAXFRAMECACHE ) return 0; mCacheCount++; if( FAILED(D3DXCreateTexture( mDevice, tex->GetWidth( ), tex->GetHeight( ), 1, D3DUSAGE_DYNAMIC, (D3DFORMAT)tex->GetFormat( ), D3DPOOL_DEFAULT, &rc->mData )) ) { printf( "Failed to create Texture Cache :: Couldn't create surface\n" ); return 0; } LPDIRECT3DSURFACE9 surf; rc->mData->GetSurfaceLevel( 0, &surf ); D3DLOCKED_RECT rect; surf->LockRect( &rect, 0, 0 ); char* data = (char*)rect.pBits; memcpy( data, tex->GetBuffer( ), tex->GetBufferSize( ) ); surf->UnlockRect( ); D3DXSaveTextureToFile( "c:\\texdebug.png", D3DXIFF_PNG, rc->mData, 0 ); tex->SetDirty( false ); } return rc->mData; };
//------------------------------------------------------------------------ int r3dTexture::Save(const char* Name, bool bFullMipChain/* = false*/) { D3DXIMAGE_FILEFORMAT Format = D3DXIFF_TGA; char drive[ 16 ], path[ 512 ], name[ 512 ], ext[ 128 ]; _splitpath( Name, drive, path, name, ext ); if ( !stricmp(ext,".BMP") ) Format = D3DXIFF_BMP; if ( !stricmp(ext,".DDS") ) Format = D3DXIFF_DDS; HRESULT hres = 0 ; if ( bFullMipChain ) hres = D3DXSaveTextureToFile ( Name, Format, AsTex2D(), NULL ) ; else { IDirect3DSurface9 *L0 = NULL; AsTex2D()->GetSurfaceLevel(0, &L0); hres = D3DXSaveSurfaceToFile(Name, Format, L0, NULL, NULL) ; L0->Release(); } if( hres != S_OK ) { r3dOutToLog( "r3dTexture::Save: Couldn't save to : %s\n", Name ) ; return 0 ; } return 1 ; }
void D3D9VideoBufferManager::SaveImage(ImagePtr image, const TString128 & sImageFile, IMAGE_FILE_FORMAT Format) { D3D9Image * img = (D3D9Image*)image.c_ptr(); D3DXSaveTextureToFile(sImageFile.c_str(), D3D9Mapping::GetD3DXImageFileFormat(Format), img->_MyTexture(), NULL); }
bool GSTexture9::Save(CString fn, bool dds) { CComPtr<IDirect3DResource9> res; if(m_desc.Usage & D3DUSAGE_DEPTHSTENCIL) { HRESULT hr; D3DSURFACE_DESC desc; m_surface->GetDesc(&desc); if(desc.Format != D3DFMT_D32F_LOCKABLE) return false; CComPtr<IDirect3DSurface9> surface; hr = m_dev->CreateOffscreenPlainSurface(desc.Width, desc.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL); D3DLOCKED_RECT slr, dlr; hr = m_surface->LockRect(&slr, NULL, 0); hr = surface->LockRect(&dlr, NULL, 0); BYTE* s = (BYTE*)slr.pBits; BYTE* d = (BYTE*)dlr.pBits; for(UINT y = 0; y < desc.Height; y++, s += slr.Pitch, d += dlr.Pitch) { for(UINT x = 0; x < desc.Width; x++) { ((float*)d)[x] = ((float*)s)[x]; } } m_surface->UnlockRect(); surface->UnlockRect(); res = surface; } else { res = m_surface; } if(CComQIPtr<IDirect3DSurface9> surface = res) { return SUCCEEDED(D3DXSaveSurfaceToFile(fn, dds ? D3DXIFF_DDS : D3DXIFF_BMP, surface, NULL, NULL)); } if(CComQIPtr<IDirect3DTexture9> texture = res) { return SUCCEEDED(D3DXSaveTextureToFile(fn, dds ? D3DXIFF_DDS : D3DXIFF_BMP, texture, NULL)); } return false; }
void DumpTexture(IDirect3DTexture8* const ptexture) { static int count = 0; char buf[BUFLEN]; sprintf(buf,"%s\\%03d_tex_%08x.bmp", GetPESInfo()->mydir, count++, (DWORD)ptexture); if (FAILED(D3DXSaveTextureToFile(buf, D3DXIFF_BMP, ptexture, NULL))) { LogWithString(&k_boot, "DumpTexture: failed to save texture to %s", buf); } }
int l_Image_Save( lua_State* L ) { ImageData* imgData = lua_checkimage( L, 1 ); const char* fileName = lua_tostring( L, 2 ); if( !imgData || !fileName ) { lua_pushstring( L, "Wrong parameters to Image_Save functions" ); lua_error( L ); return 0; } LPDIRECT3DTEXTURE9 texture; D3DLOCKED_RECT rect; D3DFORMAT dxFormat = (D3DFORMAT)imgData->format->d3dformat; if( dxFormat == D3DFMT_DXT1 || dxFormat == D3DFMT_DXT3 || dxFormat == D3DFMT_DXT5 ) dxFormat = D3DFMT_A8R8G8B8; g_pd3dDevice->CreateTexture( imgData->width, imgData->height, 1, 0, dxFormat, D3DPOOL_MANAGED, &texture, 0 ); texture->LockRect(0, &rect, 0, 0 ); memcpy( rect.pBits, imgData->imgData, imgData->width * imgData->height * imgData->format->bytesPerPixel ); texture->UnlockRect( 0 ); if( imgData->format->d3dformat == D3DFMT_DXT1 || imgData->format->d3dformat == D3DFMT_DXT3 || imgData->format->d3dformat == D3DFMT_DXT5 ) { ID3DXBuffer* dxBuffer; LPDIRECT3DTEXTURE9 outTexture; D3DXSaveTextureToFileInMemory( &dxBuffer, D3DXIFF_BMP, texture, 0 ); D3DXCreateTextureFromFileInMemoryEx( g_pd3dDevice, dxBuffer->GetBufferPointer(), dxBuffer->GetBufferSize(), imgData->width, imgData->height, 0, 0, (D3DFORMAT)imgData->format->d3dformat, D3DPOOL_SCRATCH, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, 0, &outTexture ); D3DXSaveTextureToFile( fileName, extToFormat(fileName), outTexture, 0 ); outTexture->Release(); }else { D3DXSaveTextureToFile( fileName, extToFormat(fileName), texture, 0 ); } texture->Release(); return 0; }
void TW_Save (ID3DTexture2D* T, LPCSTR name, LPCSTR prefix, LPCSTR postfix) { string256 fn; strconcat (sizeof(fn),fn,name,"_",prefix,"-",postfix); for (int it=0; it<int(xr_strlen(fn)); it++) if ('\\'==fn[it]) fn[it] = '_'; string256 fn2; strconcat (sizeof(fn2),fn2,"debug\\",fn,".dds"); Log ("* debug texture save: ",fn2); R_CHK (D3DXSaveTextureToFile (fn2,D3DXIFF_DDS,T,0)); }
void SaveSourceDDS(NiSourceTexture * pkSrcTexture, const char * pcFileName) { if(!pkSrcTexture) return; LPDIRECT3DTEXTURE9 pkD3DTexture = NULL; D3DLOCKED_RECT pkLockedTexture; UInt32 uiWidth = pkSrcTexture->GetWidth(); UInt32 uiHeight = pkSrcTexture->GetHeight(); LPDIRECT3DDEVICE9 pkD3DDevice9 = (LPDIRECT3DDEVICE9)NiDX9Renderer::GetSingleton()->m_pkD3DDevice9; if (D3DXCreateTexture(pkD3DDevice9, uiWidth, uiHeight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pkD3DTexture) != -1) { if(!pkD3DTexture) { // Failed to create texture return; } if (pkSrcTexture) { NiPixelData * pkPixelData = pkSrcTexture->pixelData; if(pkPixelData) { if (pkD3DTexture->LockRect(0, &pkLockedTexture, 0, 0) != -1) { UInt8 * pucSrc = pkPixelData->GetPixels(); UInt8 * pucDest = (UInt8 *)pkLockedTexture.pBits; for (UInt32 y = 0; y < uiHeight; y++) { for (UInt32 x = 0; x < uiWidth; x++) { pucDest[0] = pucSrc[0]; // A pucDest[1] = pucSrc[1]; // R pucDest[2] = pucSrc[2]; // G pucDest[3] = pucSrc[3]; // B pucDest+=4; pucSrc+=4; } } } pkD3DTexture->UnlockRect(0); D3DXSaveTextureToFile(pcFileName, D3DXIFF_DDS, pkD3DTexture, 0); } } pkD3DTexture->Release(); } }
void ShadowMapRenderer::EndShadowTexPass() { mShadowTexEffect->EndPass(); mShadowTexEffect->End(); gEngine->GetDriver()->GetD3DDevice()->SetRenderTarget(0, mPrevRenderTarget); gEngine->GetDriver()->GetD3DDevice()->SetDepthStencilSurface(mPrevDepthStencil); SAFE_RELEASE(mPrevRenderTarget); // GetRenderTarget方法会增加引用计数, 需要release, 否则设备无法恢复 SAFE_RELEASE(mPrevDepthStencil); bool shouldSaveToFile = false; if(shouldSaveToFile && mShadowTex->GetD3DTexture() != NULL) D3DXSaveTextureToFile(L"E:/Temp/shadowTex.jpg", D3DXIFF_JPG, mShadowTex->GetD3DTexture(), NULL); }
BOOL CDxtexDoc::OnSaveDocument(LPCTSTR lpszPathName) { LPDIRECT3DBASETEXTURE9 ptex; ptex = (m_ptexNew == NULL ? m_ptexOrig : m_ptexNew); if( FAILED( D3DXSaveTextureToFile( lpszPathName, D3DXIFF_DDS, ptex, NULL ) ) ) { AfxMessageBox(ID_ERROR_COULDNTSAVEFILE); return FALSE; } SetModifiedFlag(FALSE); return TRUE; }
//-------------------------------------------------------------------------------------------- // 알파맵들 일괄저장 void HSplatting::SaveAlphaMaps(std::string FolderName) { for(int i=0; i< MAXTEXNUM ; i++) { std::stringstream sstr; sstr<< i ; std::string FilePath = FolderName + "\\" + "AlphaMap" + sstr.str() + ".png"; if( FAILED( D3DXSaveTextureToFile( FilePath.c_str() , D3DXIFF_PNG, m_Texture[i].pAlphamap, NULL ) ) ) { TCHAR *temp = TEXT("SaveAlphaMaps FAILED"); MessageBox(NULL, temp, temp, 0 ); return; } } }
void fbo_resolve(FBO *fbo) { if (fbo && fbo->tex) { #ifdef _XBOX pD3Ddevice->Resolve( D3DRESOLVE_RENDERTARGET0|D3DRESOLVE_ALLFRAGMENTS, NULL, fbo->tex, NULL, 0, 0, NULL, 0.0f, 0, NULL ); #else // TODO? #endif } #if 0 // Hack save to disk ... char fname[256]; static int f = 0; sprintf(fname, "game:\\rtt.%08x.%d.png", fbo->id, f++); D3DXSaveTextureToFile(fname, D3DXIFF_PNG, fbo->tex, NULL); //strcat(fname, "\n"); OutputDebugString(fname); #endif }
void fbo_bind_color_as_texture(FBO *fbo, int color) { #if 0 // Hack save to disk ... char fname[256]; static int f = 0; sprintf(fname, "game:\\rtt.%08x.%d.png", fbo->id, f++); D3DXSaveTextureToFile(fname, D3DXIFF_PNG, fbo->tex, NULL); //strcat(fname, "\n"); OutputDebugString(fname); #endif //pD3Ddevice->SetRenderTarget(0, workingRtt); //pD3Ddevice->Resolve( D3DRESOLVE_RENDERTARGET0|D3DRESOLVE_ALLFRAGMENTS, NULL, fbo->tex, NULL, 0, 0, NULL, 0.0f, 0, NULL ); //pD3Ddevice->SetRenderTarget(0, currentRtt); //OutputDebugStringA("fbo_bind_color_as_texture: Fix me\r\n"); pD3Ddevice->SetTexture(0, fbo->tex); //pD3Ddevice->SetTexture(0, NULL); }
bool JRenderServer::SaveTexture( int texID, const char* fname ) { if (texID < 0 || texID >= (int)m_Textures.size()) return false; DXTexture* pTex = (DXTexture*)m_Textures[texID].m_pTexture; if (!pTex) return false; char drive[_MAX_PATH]; char dir [_MAX_PATH]; char file [_MAX_PATH]; char ext [_MAX_PATH]; _splitpath( fname, drive, dir, file, ext ); D3DXIMAGE_FILEFORMAT type = D3DXIFF_DDS; if (!strcmp( ext, ".bmp" )) type = D3DXIFF_BMP; if (!strcmp( ext, ".tga" )) type = D3DXIFF_TGA; if (!strcmp( ext, ".dds" )) type = D3DXIFF_DDS; HRESULT hRes = D3DXSaveTextureToFile( fname, type, pTex, 0 ); return (hRes == S_OK); } // JRenderServer::SaveTexture
void ShadowMapRenderer::EndShadowMapPass() { IDirect3DDevice9* d3dDevice = gEngine->GetDriver()->GetD3DDevice(); mShadowMapEffect->EndPass(); mShadowMapEffect->End(); d3dDevice->SetRenderTarget(0, mPrevRenderTarget); d3dDevice->SetDepthStencilSurface(mPrevDepthStencil); SAFE_RELEASE(mPrevRenderTarget); // GetRenderTarget方法会增加引用计数, 需要release, 否则设备无法恢复 SAFE_RELEASE(mPrevDepthStencil); IDirect3DSurface9* shadowTexSurface = NULL; mShadowMapTex->GetD3DTexture()->GetSurfaceLevel(0, &shadowTexSurface); d3dDevice->StretchRect(mShadowMapRTSurface, NULL, shadowTexSurface, NULL, D3DTEXF_NONE); bool shouldSaveToFile = false; if(shouldSaveToFile && mShadowMapTex->GetD3DTexture() != NULL) D3DXSaveTextureToFile(L"E:/Temp/shadowMap.jpg", D3DXIFF_JPG, mShadowMapTex->GetD3DTexture(), NULL); SAFE_RELEASE(shadowTexSurface); }
bool CTexture::Save(const std::string &FileName) { return D3DXSaveTextureToFile(FileName.c_str(), D3DXIFF_BMP, m_Texture, NULL)==S_OK; }
HRESULT KG3DSelector::OnRender() { HRESULT hRetCode = E_FAIL; HRESULT hResult = E_FAIL; D3DLOCKED_RECT Rect; LPDIRECT3DSURFACE9 pResultColor = NULL; LPDIRECT3DSURFACE9 pStencilRT = NULL; D3DVIEWPORT9 vp; D3DVIEWPORT9 vpNew; KG3DRenderState RenderState; DWORD dwSelectIndex = 0xff; g_pd3dDevice->GetViewport(&vp); vpNew = vp; vpNew.X /= m_nScale; vpNew.Y /= m_nScale; vpNew.Width /= m_nScale; vpNew.Height /= m_nScale; m_dwIndex = 0;//Stencil Index清零 KG_PROCESS_SUCCESS(!m_vecModels.size()); hResult = g_pd3dDevice->GetRenderTarget(0, &m_pRTSave); KG_COM_PROCESS_ERROR(hResult); hResult = g_pd3dDevice->GetDepthStencilSurface(&m_pDepthSave); KG_COM_PROCESS_ERROR(hResult); hResult = m_pStencilRT->GetSurfaceLevel(0, &pStencilRT); KG_COM_PROCESS_ERROR(hResult); hResult = g_pd3dDevice->SetRenderTarget(0, pStencilRT); KG_COM_PROCESS_ERROR(hResult); hResult = g_pd3dDevice->SetDepthStencilSurface(m_pStencilDepth); KG_COM_PROCESS_ERROR(hResult); hResult = g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 1L); KG_COM_PROCESS_ERROR(hResult); g_pd3dDevice->SetViewport(&vpNew); RenderModelList(); if (0) { D3DXSaveTextureToFile("d:\\test.tga", D3DXIFF_TGA, m_pStencilRT, NULL); } hResult = g_pd3dDevice->SetTexture(0, m_pStencilRT); KG_COM_PROCESS_ERROR(hResult); g_pd3dDevice->SetTexture(1, NULL); hResult = g_pd3dDevice->SetDepthStencilSurface(NULL); KG_COM_PROCESS_ERROR(hResult); hResult = g_pd3dDevice->SetRenderTarget(0, m_pRT); KG_COM_PROCESS_ERROR(hResult); RenderState.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); float fU = float(m_MousePoint.x) / m_nWidth ; float fV = float(m_MousePoint.y) / m_nHeight; ScreenRect[0].vec2UV = D3DXVECTOR2(fU, fV); ScreenRect[1].vec2UV = D3DXVECTOR2(fU, fV); ScreenRect[2].vec2UV = D3DXVECTOR2(fU, fV); ScreenRect[3].vec2UV = D3DXVECTOR2(fU, fV); hResult = g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1.0f, 1L); KG_COM_PROCESS_ERROR(hResult); hResult = g_pd3dDevice->SetFVF(SelectorVertex::dwFVF); KG_COM_PROCESS_ERROR(hResult); RenderState.SetRenderState(D3DRS_FOGENABLE, FALSE); RenderState.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); RenderState.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); RenderState.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); RenderState.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); hResult = g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, ScreenRect, sizeof(SelectorVertex)); KG_COM_PROCESS_ERROR(hResult); hResult = m_pResult->GetSurfaceLevel(0, &pResultColor); KG_COM_PROCESS_ERROR(hResult); hResult = g_pd3dDevice->GetRenderTargetData(m_pRT, pResultColor); KG_COM_PROCESS_ERROR(hResult); hResult = pResultColor->LockRect(&Rect, NULL, 0); KG_COM_PROCESS_ERROR(hResult); BYTE *pBit = (BYTE*)Rect.pBits; dwSelectIndex = *(pBit + 2); pResultColor->UnlockRect(); KG_COM_PROCESS_ERROR(hResult); if (dwSelectIndex != 0xff) { _ASSERTE(dwSelectIndex < m_vecModels.size()); m_pSelectedModel = m_vecModels[dwSelectIndex]; } else { //模糊选择, 在所有的模型都没有精确选中的时候, 选中离镜头最近的那一个 D3DXVECTOR3 vec3CamPos; float fNear = 9999999999.f; DWORD dwNear = 0xffffffff; g_cGraphicsTool.GetCamera()->GetPosition(&vec3CamPos); for (size_t i = 0; i < m_vecModels.size(); i++) { D3DXVECTOR3 vec3Length = vec3CamPos - D3DXVECTOR3(m_vecModels[i]->m_matWorld._41, m_vecModels[i]->m_matWorld._42, m_vecModels[i]->m_matWorld._43); float fLength = vec3Length.x * vec3Length.x + vec3Length.y * vec3Length.y + vec3Length.z * vec3Length.z; if (fLength < fNear) { fNear = fLength; dwNear = static_cast<DWORD>(i); } } m_pSelectedModel = m_vecModels[dwNear]; } m_bSelected = TRUE; Exit1: hRetCode = S_OK; Exit0: if (!m_bSelected) { m_pSelectedModel = NULL; } m_vecModels.clear(); SAFE_RELEASE(pStencilRT); SAFE_RELEASE(pResultColor); if (m_pRTSave) { g_pd3dDevice->SetRenderTarget(0, m_pRTSave); } if (m_pDepthSave) { g_pd3dDevice->SetDepthStencilSurface(m_pDepthSave); g_pd3dDevice->SetViewport(&vp); } SAFE_RELEASE(pResultColor); SAFE_RELEASE(m_pRTSave); SAFE_RELEASE(m_pDepthSave); return hRetCode; }
void logTexture(IDirect3DDevice9* pd3dDevice, IDirect3DTexture9* pTexture, char* filename) { D3DXSaveTextureToFile(filename, D3DXIFF_JPG, pTexture, NULL); }
void D3D9texture::saveToFile(const String& filename) { String ospath = g_fileSystem->modPathToOsPath(filename); HRESULT hr; V(D3DXSaveTextureToFile(u2w(ospath).c_str(), D3DXIFF_DDS, m_object, 0)); }
bool eae6320::cTextureBuilder::Build( const std::vector<std::string>& ) { bool wereThereErrors = false; if ( !Initialize( m_path_source ) ) { wereThereErrors = true; goto OnExit; } // Get information about the source image D3DXIMAGE_INFO imageInfo_source; { if ( FAILED( D3DXGetImageInfoFromFile( m_path_source, &imageInfo_source ) ) ) { wereThereErrors = true; OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source ); goto OnExit; } } // Load the source image and do any necessary processing (compress, generate MIP maps, change resolution, etc.) { // Try to match the original image's format as closely as possible D3DFORMAT format = D3DFMT_UNKNOWN; { if ( imageInfo_source.ImageFileFormat == D3DXIFF_DDS ) { // DDS files will remain unchanged // (this could cause problems in the simplistic OpenGL texture loading code that I provide) format = imageInfo_source.Format; } else { // The decision of which DXT format to use is simplistic: // * If it can easily be determined that the source image doesn't have an alpha channel then DXT1 is used // * DXT5 is used for everything else const D3DFORMAT format_original = imageInfo_source.Format; const bool isAlphaChannelUnnecessary = ( format_original == D3DFMT_R8G8B8 ) || ( format_original == D3DFMT_X8R8G8B8 ) || ( format_original == D3DFMT_R5G6B5 ) || ( format_original == D3DFMT_X1R5G5B5 ) || ( format_original == D3DFMT_X4R4G4B4 ) || ( format_original == D3DFMT_X8B8G8R8 ); if ( isAlphaChannelUnnecessary ) { format = D3DFMT_DXT1; } else { format = D3DFMT_DXT5; } } } // The source width and height could be used, but ensuring that the dimensions are always a power-of-2 is more compatible // (and the image will probably end up taking the same amount of space anyway because of alignment issues) const unsigned int roundUpToAPowerOf2 = D3DX_DEFAULT; unsigned int requestedMipMapCount; { const bool doMipMapsExist = imageInfo_source.MipLevels > 1; if ( doMipMapsExist ) { requestedMipMapCount = D3DX_FROM_FILE; } else { // This will generate all of the potential MIP map levels (down to the smallest 1x1) requestedMipMapCount = D3DX_DEFAULT; } } const DWORD staticTexture = 0; const D3DPOOL letD3dManageMemory = D3DPOOL_MANAGED; const DWORD useDefaultFiltering = D3DX_DEFAULT; const D3DCOLOR noColorKey = 0; PALETTEENTRY* noColorPalette = NULL; switch( imageInfo_source.ResourceType ) { case D3DRTYPE_TEXTURE: { const HRESULT result = D3DXCreateTextureFromFileEx( s_direct3dDevice, m_path_source, roundUpToAPowerOf2, roundUpToAPowerOf2, requestedMipMapCount, staticTexture, format, letD3dManageMemory, useDefaultFiltering, useDefaultFiltering, noColorKey, &imageInfo_source, noColorPalette, reinterpret_cast<IDirect3DTexture9**>( &s_texture ) ); if ( FAILED( result ) ) { wereThereErrors = true; OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source ); goto OnExit; } } break; case D3DRTYPE_CUBETEXTURE: { const HRESULT result = D3DXCreateCubeTextureFromFileEx( s_direct3dDevice, m_path_source, roundUpToAPowerOf2, requestedMipMapCount, staticTexture, format, letD3dManageMemory, useDefaultFiltering, useDefaultFiltering, noColorKey, &imageInfo_source, noColorPalette, reinterpret_cast<IDirect3DCubeTexture9**>( &s_texture ) ); if ( FAILED( result ) ) { wereThereErrors = true; OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source ); goto OnExit; } } break; case D3DRTYPE_VOLUMETEXTURE: { const HRESULT result = D3DXCreateVolumeTextureFromFileEx( s_direct3dDevice, m_path_source, roundUpToAPowerOf2, roundUpToAPowerOf2, imageInfo_source.Depth, requestedMipMapCount, staticTexture, format, letD3dManageMemory, useDefaultFiltering, useDefaultFiltering, noColorKey, &imageInfo_source, noColorPalette, reinterpret_cast<IDirect3DVolumeTexture9**>( &s_texture ) ); if ( FAILED( result ) ) { wereThereErrors = true; OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source ); goto OnExit; } } break; default: { wereThereErrors = true; std::stringstream errorMessage; errorMessage << "Unsupported texture resource type " << imageInfo_source.ResourceType; OutputErrorMessage( errorMessage.str().c_str(), m_path_source ); goto OnExit; } } } // Save the texture { const D3DXIMAGE_FILEFORMAT ddsFormat = D3DXIFF_DDS; PALETTEENTRY* noColorPalette = NULL; HRESULT result = D3DXSaveTextureToFile( m_path_target, ddsFormat, s_texture, noColorPalette ); if ( FAILED( result ) ) { wereThereErrors = true; OutputErrorMessage( "DirectX failed to save the texture", m_path_target ); goto OnExit; } } OnExit: if ( !ShutDown() ) { wereThereErrors = true; } return !wereThereErrors; }
void TextureLoader::Save( const char * dstFile, ImageFileFormat format, LPD3DTEXTURE texture ) { D3DXSaveTextureToFile(dstFile, (D3DXIMAGE_FILEFORMAT)format,texture, NULL); }
// this function is obsoleted, use ParaMovie::TakeScreenShot3 instead. bool ParaMovie::RenderToTexture(const char* filename, int width, int height) { // code no longer used. it just provides an example of calling render to texture. #if 0 //#include "AutoCamera.h" //#include "SceneObject.h" //#include "FrameRateController.h" LPDIRECT3DDEVICE9 pd3dDevice = CGlobals::GetRenderDevice(); if(pd3dDevice == 0) return false; CSceneObject* pScene = CGlobals::GetScene(); LPDIRECT3DTEXTURE9 m_pRenderTarget = NULL; LPDIRECT3DSURFACE9 m_pRenderTargetSurface = NULL; LPDIRECT3DSURFACE9 m_pDepthSurface = NULL; D3DVIEWPORT9 oldViewport; D3DFORMAT colorFormat = D3DFMT_A8R8G8B8; D3DFORMAT zFormat = D3DFMT_D24S8; // render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { if(FAILED(pd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, colorFormat, D3DPOOL_DEFAULT, &m_pRenderTarget, NULL))) return false; if(FAILED(m_pRenderTarget->GetSurfaceLevel(0, &m_pRenderTargetSurface))) return false; if(FAILED(pd3dDevice->CreateDepthStencilSurface(width, height, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, FALSE, &m_pDepthSurface, NULL))) return false; ////////////////////////////////////////////////////////////////////////// // Render to the reflection map LPDIRECT3DSURFACE9 pOldRenderTarget = CGlobals::GetDirectXEngine().GetRenderTarget(); CGlobals::GetDirectXEngine().SetRenderTarget(0, m_pRenderTargetSurface); CBaseCamera* pCamera = pScene->GetCurrentCamera(); float fOldAspectRatio = pCamera->GetAspectRatio(); pCamera->SetAspectRatio((float)width/(float)height); pd3dDevice->GetViewport(&oldViewport); D3DVIEWPORT9 newViewport; newViewport.X = 0; newViewport.Y = 0; newViewport.Width = width; newViewport.Height = height; newViewport.MinZ = 0.0f; newViewport.MaxZ = 1.0f; pd3dDevice->SetViewport(&newViewport); // set depth surface LPDIRECT3DSURFACE9 pOldZBuffer = NULL; if(FAILED(pd3dDevice->GetDepthStencilSurface(&pOldZBuffer))) { OUTPUT_LOG("GetDepthStencilSurface failed\r\n"); return false; } pd3dDevice->SetDepthStencilSurface( m_pDepthSurface ); ///////////////////////////////////////////////////////////////////////// /// render /// clear to scene pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L ); if(pScene->IsSceneEnabled()) { ///-- set up effects parameters ((CAutoCamera*)pCamera)->UpdateViewProjMatrix(); pScene->AdvanceScene(0); } ////////////////////////////////////////////////////////////////////////// // Restore to old settings D3DXIMAGE_FILEFORMAT FileFormat = D3DXIFF_JPG; D3DXSaveTextureToFile(filename, FileFormat, m_pRenderTarget, NULL); // restore old view port pd3dDevice->SetViewport(&oldViewport); pCamera->SetAspectRatio(fOldAspectRatio); pd3dDevice->SetDepthStencilSurface( pOldZBuffer); SAFE_RELEASE(pOldZBuffer); CGlobals::GetDirectXEngine().SetRenderTarget(0, pOldRenderTarget); SAFE_RELEASE(m_pRenderTargetSurface); SAFE_RELEASE(m_pDepthSurface); SAFE_RELEASE(m_pRenderTarget); pd3dDevice->EndScene(); } #endif return true; }
void save_texture( char * path, LPTEXTURE texture ) { #ifndef __WINE__ D3DXSaveTextureToFile(path, D3DXIFF_PNG, (LPDIRECT3DTEXTURE9)texture, 0); #endif }
void RSManager::dumpTexture(const char* name, IDirect3DTexture9* tex) { char fullname[128]; sprintf_s(fullname, 128, "dump%03d_%s_%p.tga", dumpCaptureIndex++, name, tex); SDLOG(1, "!! dumped Tex %p to %s\n", tex, fullname); D3DXSaveTextureToFile(fullname, D3DXIFF_TGA, tex, NULL); }
bool SUIPictureList::SaveBaseAsFile( SPString path ) { D3DXSaveTextureToFile((path+L".bmp").c_str(), D3DXIFF_BMP, baseImage->GetD3DTexture(), NULL); return true; }
bool UpdateD3DAntiCheat_ScreenHelpers2( bool lastAttempt ) { if( !g_AntiCheat_PrePresentPixels.Count() ) return false; bool result = false; HDC windowDC = GetWindowDC( r3dRenderer->HLibWin ); WINDOWINFO winfo; memset( &winfo, 0, sizeof winfo ); winfo.cbSize = sizeof winfo; GetWindowInfo( r3dRenderer->HLibWin, &winfo ); // put window at 0 0 for convenience winfo.rcClient.left -= winfo.rcWindow.left; winfo.rcClient.right -= winfo.rcWindow.left; winfo.rcClient.top -= winfo.rcWindow.top; winfo.rcClient.bottom -= winfo.rcWindow.top; winfo.rcWindow.bottom -= winfo.rcWindow.top; winfo.rcWindow.top = 0; winfo.rcWindow.right -= winfo.rcWindow.left; winfo.rcWindow.left = 0; int nTotalWid = winfo.rcWindow.right - winfo.rcWindow.left, nTotalHeight = winfo.rcWindow.bottom - winfo.rcWindow.top; int nClientWid = winfo.rcClient.right - winfo.rcClient.left, nClientHt = winfo.rcClient.bottom - winfo.rcClient.top; if( r_fullscreen->GetInt() ) { nTotalWid = g_AntiCheat_PrePresentPixels_Width; nTotalHeight = g_AntiCheat_PrePresentPixels_Height; nClientWid = g_AntiCheat_PrePresentPixels_Width; nClientHt = g_AntiCheat_PrePresentPixels_Height; } /*if( g_AntiCheat_PrePresentPixels_Width != nClientWid || g_AntiCheat_PrePresentPixels_Height != nClientHt ) { return false; }*/ HDC hBitmapdc; HBITMAP hBitmap, hOriginal; if( windowDC || r_fullscreen->GetInt() ) { DWORD* pixel = NULL; if( !r_fullscreen->GetInt() ) { hBitmap = CreateCompatibleBitmap(windowDC,nTotalWid,nTotalHeight); hBitmapdc = CreateCompatibleDC(windowDC); hOriginal = (HBITMAP)SelectBitmap(hBitmapdc, hBitmap); BitBlt( hBitmapdc, 0, 0, nTotalWid, nTotalHeight, windowDC, 0, 0, SRCCOPY ); BITMAPINFO bmpInfo; memset( &bmpInfo, 0, sizeof bmpInfo ); bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmpInfo.bmiHeader.biWidth = nTotalWid; bmpInfo.bmiHeader.biHeight = nTotalHeight; bmpInfo.bmiHeader.biPlanes = 1; bmpInfo.bmiHeader.biBitCount = 32; bmpInfo.bmiHeader.biCompression = BI_RGB; bmpInfo.bmiHeader.biSizeImage = 0; GetDIBits( hBitmapdc, hBitmap, 0, nTotalHeight, NULL, &bmpInfo, DIB_RGB_COLORS ); r3d_assert( nTotalWid * nTotalHeight * sizeof( DWORD ) <= bmpInfo.bmiHeader.biSizeImage ); pixel = (DWORD*)malloc( bmpInfo.bmiHeader.biSizeImage ); GetDIBits( hBitmapdc, hBitmap, 0, nTotalHeight, pixel, &bmpInfo, DIB_RGB_COLORS ); //#if 0 IDirect3DSurface9 *sysmemBB = r3dRenderer->GetTempSurfaceForScreenShots(); D3DLOCKED_RECT lrect; D3D_V( sysmemBB->LockRect( &lrect, NULL, 0 ) ); D3DSURFACE_DESC smbbDesc; sysmemBB->GetDesc( &smbbDesc ); r3d_assert( lrect.Pitch * smbbDesc.Height == nClientWid * nClientHt * sizeof( DWORD ) ); for( int i = 0, e = nClientHt; i < e ; i ++ ) { memcpy( (char*)lrect.pBits + lrect.Pitch * i, pixel + ( nTotalHeight - 1 - ( i + winfo.rcClient.top ) ) * nTotalWid + winfo.rcClient.left, lrect.Pitch ); } D3D_V( sysmemBB->UnlockRect() ); D3DXSaveSurfaceToFile( "test1.bmp", D3DXIFF_BMP, sysmemBB, NULL, NULL ); //#endif DeleteDC( hBitmapdc ); DeleteObject( hBitmap ); } else { int pixelDataSize = g_AntiCheat_PrePresentPixels_Width * g_AntiCheat_PrePresentPixels_Height * sizeof( DWORD ); pixel = (DWORD*)malloc( pixelDataSize ); struct Locals { Locals() { BBuf = 0; } ~Locals() { if( BBuf ) BBuf->Release(); } IDirect3DSurface9 *BBuf; } locals; (void)locals; r3dRenderer->GetRT(0, &locals.BBuf); IDirect3DDevice9 *d = r3dRenderer->pd3ddev; IDirect3DSurface9 *sysmemBB = r3dRenderer->GetTempSurfaceForScreenShots(); if (!SUCCEEDED(d->GetRenderTargetData(locals.BBuf, sysmemBB))) { r3dOutToLog("SUCCEEDED(d->GetRenderTargetData(locals.BBuf, sysmemBB))\n"); InvalidateScreenHelperAnticheat(); return false; } D3DSURFACE_DESC sdesc; sysmemBB->GetDesc( &sdesc ); D3DLOCKED_RECT lrect; sysmemBB->LockRect( &lrect, NULL, D3DLOCK_READONLY ); r3d_assert( lrect.Pitch * sdesc.Height == pixelDataSize ); memcpy( pixel, lrect.pBits, lrect.Pitch * sdesc.Height ); sysmemBB->UnlockRect(); #if 0 D3DXSaveSurfaceToFile( "test1.jpg", D3DXIFF_JPG, sysmemBB, NULL, NULL ); #endif } int subAreaHeight = int( nClientHt * 0.8f ); int subAreaWidth = int( nClientWid * 0.8f ); int yStart = ( nClientHt - subAreaHeight ) / 2; int yEnd = nClientHt - yStart; int xStart = ( nClientWid - subAreaWidth ) / 2; int xEnd = nClientWid - yStart; xStart += winfo.rcClient.left; xEnd += winfo.rcClient.left; yStart += nTotalHeight - winfo.rcClient.bottom; yEnd += nTotalHeight - winfo.rcClient.bottom; int totalSubArea = ( xEnd - xStart ) * ( yEnd - yStart ); int unequalCount = 0; //------------------------------------------------------------------------ #if 0 FILE * fout = fopen( "test0.raw", "wb" ); for( int y = 0, e = nTotalHeight; y < e; y ++ ) { for( int x = 0, e = nTotalWid; x < e; x ++ ) { fputc( pixel[ x + y * nTotalWid ], fout ); } } fclose( fout ); FILE * fout1 = fopen( "test1.raw", "wb" ); for( int y = 0, e = nClientHt; y < e; y ++ ) { for( int x = 0, e = nClientWid; x < e; x ++ ) { fputc( g_AntiCheat_PrePresentPixels[ x + y * nClientWid ], fout1 ); } } fclose( fout1 ); #endif //------------------------------------------------------------------------ for( int y = yStart, e = yEnd; y < e; y ++ ) { for( int x = xStart, e = xEnd; x < e; x ++ ) { int localX = x - winfo.rcClient.left; int localY = r_fullscreen->GetInt() ? y - winfo.rcClient.top : ( nTotalHeight - y - 1 ) - winfo.rcClient.top; DWORD pixel0 = pixel[ x + y * nTotalWid ] & 0xffffff; DWORD pixel1 = g_AntiCheat_PrePresentPixels[ localX + localY * g_AntiCheat_PrePresentPixels_Width ] & 0xffffff; if( pixel0 != pixel1 ) { unequalCount ++; } } } //#if 0 r3dOutToLog( "unequalCount %d\n", unequalCount ); //#endif if( !unequalCount ) { result = true; } else if( lastAttempt ) { result = true; // caught some significant extra stuff on screen D3DCheaters[ ANTICHEAT_SCREEN_HELPERS2 ] = true; r3dOutToLog("ScreenHelper\n"); int texWidth = 386; int texHeight = 256; if( !g_TempSaveDataS ) { D3D_V( r3dRenderer->pd3ddev->CreateTexture( texWidth, texHeight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &g_TempSaveDataS, NULL ) ); } if( g_TempSaveDataS ) { D3DLOCKED_RECT lrect; g_TempSaveDataS->LockRect( 0, &lrect, NULL, 0 ); r3d_assert( lrect.Pitch == texWidth * sizeof( DWORD ) ); memset( lrect.pBits, 0, lrect.Pitch * texHeight ); for( int y=0, yy=0; y < texHeight; y++, yy = y * nClientHt / texHeight ) { for( int x=0, xx=0; x < texWidth; x++, xx = x * nClientWid / texWidth ) { int src_idx = ( nTotalHeight - winfo.rcClient.top - yy - 1 ) * nTotalWid + xx + winfo.rcClient.left; if( src_idx < nTotalWid * nTotalHeight ) { if(r_fullscreen->GetInt()) // in fullscreen image in inverted, so write it upside down to correct for that *((DWORD*)lrect.pBits + (texHeight-y-1) * texWidth + x) = pixel[ src_idx ]; else *((DWORD*)lrect.pBits + y * texWidth + x) = pixel[ src_idx ]; } else { #ifndef FINAL_BUILD r3d_assert(false); #endif } } } g_TempSaveDataS->UnlockRect( 0 ); //#if 0 D3DXSaveTextureToFile( "test_final.jpg", D3DXIFF_JPG, g_TempSaveDataS, NULL ); //#endif } } free( pixel ); ReleaseDC( r3dRenderer->HLibWin, windowDC ); } return result; }
//-------------------------------------------------------------------------------------- void CP3DRenderer::SaveSceneIntoCubeMap(float fX, float fY, float fZ) { IDirect3DCubeTexture9* pCubeMap=NULL; P3DXVector3D pos; // kontrola zda je co renderovat if (!g_pBSPMap) return; // vytvor cubemapu g_pD3DDevice->CreateCubeTexture( 256/*=size*/, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeMap, NULL ); // The projection matrix has a FOV of 90 degrees and asp ratio of 1 D3DXMATRIXA16 mProj; D3DXMatrixPerspectiveFovLH( &mProj, D3DX_PI * 0.5f, 1.0f, 5.00f, 100000.0f ); D3DXMATRIXA16 mViewDir; D3DXMatrixIdentity(&mViewDir); mViewDir._41 = fX; mViewDir._42 = fY; mViewDir._43 = fZ; pos.x = fX; pos.y = fY; pos.z = fZ; LPDIRECT3DSURFACE9 pRTOld = NULL; if (FAILED(g_pD3DDevice->GetRenderTarget(0, &pRTOld ))) { CON(MSG_CON_ERR, "CP3DRenderer::RenderSceneIntoCubeMap: Can't get render target!"); return; } IDirect3DSurface9* g_pDepthCube = NULL; g_pD3DDevice->CreateDepthStencilSurface( 256, 256, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &g_pDepthCube, NULL ); LPDIRECT3DSURFACE9 pDSOld = NULL; if( SUCCEEDED( g_pD3DDevice->GetDepthStencilSurface( &pDSOld ) ) ) { // If the device has a depth-stencil buffer, use // the depth stencil buffer created for the cube textures. g_pD3DDevice->SetDepthStencilSurface( g_pDepthCube ); } g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &mProj); // pro fixed pipe g_matProj=mProj; // pro material managera D3DXMatrixMultiply (&g_matViewProj, &g_matView, &g_matProj); g_pMaterialManager->OnProjectionMatrixChange(); D3DXMATRIXA16 mWorld; D3DXMatrixIdentity(&mWorld); g_pD3DDevice->SetTransform(D3DTS_WORLD, &mWorld); for( int nFace = 0; nFace < 6; nFace++ ) { LPDIRECT3DSURFACE9 pSurf=NULL; pCubeMap->GetCubeMapSurface( (D3DCUBEMAP_FACES)nFace, 0, &pSurf ); g_pD3DDevice->SetRenderTarget( 0, pSurf ); SAFE_RELEASE( pSurf ); g_pD3DDevice->Clear( 0L, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0x000000ff, 1.0f, 0L ); // Begin the scene if( SUCCEEDED( g_pD3DDevice->BeginScene() ) ) { D3DXVECTOR3 vec; vec.x = fX; vec.y = fY; vec.z = fZ; D3DXMATRIXA16 mView = GetCubeMapViewMatrix( nFace, vec); g_pD3DDevice->SetTransform(D3DTS_VIEW, &mView); // pro fixed pipe g_matView=mView; // pro material managera D3DXMatrixMultiply (&g_matViewProj, &g_matView, &g_matProj); g_pMaterialManager->OnViewMatrixChange(); g_pFrustum->CalculateFrustum (g_matView, g_matProj); // Vsechno co je potreba vyrenderovat do cubemapy g_pBSPMap->Render(); //g_pBSPMap->RenderCollisionGeometry(); // End the scene. g_pD3DDevice->EndScene(); } } // Restore depth-stencil buffer and render target if( pDSOld ) { g_pD3DDevice->SetDepthStencilSurface( pDSOld ); SAFE_RELEASE( pDSOld ); } //DEBUG: Pouze pro pokusne ulozeni na disk, pak nejak vracet texturu // Restore render target g_pD3DDevice->SetRenderTarget( 0, pRTOld ); SAFE_RELEASE( pRTOld ); D3DXSaveTextureToFile("C:\\myCube.dds", D3DXIFF_DDS, pCubeMap, NULL ); SAFE_RELEASE(pCubeMap); SAFE_RELEASE(g_pDepthCube); }