#include "StdAfx.h" #include "HighResolutionCapture.h" #include #include #include "shlobj.h" #include #include #ifdef _DEBUG #define new new(_NORMAL_BLOCK,__FILE__,__LINE__) #endif CHighResolutionCapture::CHighResolutionCapture() : m_bCapture( false ) , m_pColorAdjFilter( NULL ) , m_dwClearColor( 0xFF000000 ) , m_fTempAspectRatio( 0.0f ) { } CHighResolutionCapture::~CHighResolutionCapture() { SAFE_DELETE( m_pColorAdjFilter ); } void CHighResolutionCapture::Capture( const char *szFilePrefix, int nWidth, int nHeight ) { if( !m_pColorAdjFilter ) { // ¼¼ÀÎÆ® ÇìÀ̺첨 °¡Á®¿Í ¾´´Ù. m_pColorAdjFilter = (CEtColorAdjustTexFilter*)EternityEngine::CreateFilter( SF_COLORADJUSTTEX ); m_pColorAdjFilter->SetParam( EtVector4(-0.071f, -0.107f, -0.107f, 0.0f), EtVector4(0.25f, 0.286f, 0.357f, 0.0f), EtVector4(0.357f, 0.357f, 0.536f, 0.0f), 0.9f ); m_pColorAdjFilter->Enable( false ); } if( m_bCapture ) return; if( nWidth <= 0 || nWidth == INT_MAX ) nWidth = GetEtDevice()->GetMaxTextureWidth(); if( nHeight <= 0 || nHeight == INT_MAX ) nHeight = GetEtDevice()->GetMaxTextureHeight(); // ºñµð¿ÀÄ«µå ¸Þ¸ð¸® ¹®Á¦Àΰ¡.. ÅØ½ºÃ³ »ý¼ºÀº ¹®Á¦¾ø´Âµ¥ SaveÇÒ¶§ ¾Æ¿ô¿Àºê¸Þ¸ð¸®¶°¼­ ÃÖ´ëÄ¡ Á¦ÇÑ °É¾îµÐ´Ù. if( nWidth > 7200 ) nWidth = 7200; if( nHeight > 7200 ) nHeight = 7200; m_hRenderTarget = CEtTexture::CreateRenderTargetTexture( nWidth, nHeight, FMT_X8R8G8B8 ); m_hDepthTarget = CEtDepth::CreateDepthStencil( nWidth, nHeight, FMT_D24S8 ); m_hTempTarget = CEtTexture::CreateRenderTargetTexture( nWidth, nHeight, FMT_X8R8G8B8 ); m_szFilePrefix = szFilePrefix; // ¹é±×¶ó¿îµå Ä÷¯¿¡ 0x0À¸·Î Ŭ¸®¾îÇØ¼­ ¾ËÆÄÆÇ¿¡ ·»´õÇØÁÙ ¼ö ÀÖ³Ä°í ¿äûÀÌ ¿Ô¾ú´Ù. // ±×·¡¼­ FMT_A8R8G8B8·Î Ÿ°Ù ¼³Á¤ÇÏ°í ·»´õ·çƾÀ» ±âº» ±×´ë·Î Ÿ°Ô Çß´õ´Ï, // ¾ËÆÄ·»´õÇÒ¶§ ¹öÆÛ¿¡ ¾ËÆÄ ±â·ÏÇÏ´Â ºÎºÐ¿¡¼­ a°ªÀÌ ÀÌ»óÇÏ°Ô ±â·ÏµÇ¾ú´Ù.(³ªÁß¿¡ ±×·ÁÁö´Â a¸¦ ±×´ë·Î ¹öÆÛ¿¡ ±â·Ï) // ±×·¡¼­ ºÒÅõ¸íÀ§¿¡ Âï´Â ¾ËÆÄºÎºÐÀÇ a°ªÀÌ 255º¸´Ù ³·¾ÆÁö´Â Çö»óÀÌ ¹ß»ýÇß´Ù. // ¾Æ¹«·¡µµ ·»´õ·çƾÀÌ X8R8G8B8¿¡ ±×·ÁÁö´Â°É ±â¹ÝÀ¸·Î ÀÛ¼ºµÇ¼­ ±×·±µí.. // ±×·¸´Ù°í ½¦ÀÌ´õ¸¦ ¶âÀ»¼öµµ ¾ø°í, // D3DRS_SEPARATEALPHABLENDENABLE»ç¿ëÇÏ´õ¶óµµ ´©ÀûÇØ¼­ ¾ËÆÄºí·»µù ÇÒ °æ¿ì ±ò²ûÇÏ°Ô ±×¸± ¹æ¹ýÀÌ ¾ø¾î¼­, ºÒÅõ¸í ÆÇ¿¡´Ù¸¸ ±×¸®µµ·Ï Çß´Ù. // »ç½Ç, ¿£ÁøÀÇ ·»´õ·çƾÀ» ±×´ë·Î »ç¿ëÇϸ鼭 ¾ËÆÄ¹é¹öÆÛ¿¡ ±×¸®·Á´ø°Å ÀÚü°¡ À߸øµÈ°Å °°¾Ò´Ù. m_bCapture = true; } void CHighResolutionCapture::BeginCapture() { if( !m_bCapture ) return; EtCameraHandle hCamera = CEtCamera::GetActiveCamera(); if( hCamera ) { m_fTempAspectRatio = hCamera->GetAspectRatio(); hCamera->SetAspectRatio( (float)m_hRenderTarget->Width() / (float)m_hRenderTarget->Height() ); } GetEtDevice()->SetRenderTarget( m_hRenderTarget->GetSurfaceLevel() ); GetEtDevice()->SetDepthStencilSurface( m_hDepthTarget->GetDepthBuffer() ); GetEtDevice()->ClearBuffer( m_dwClearColor, 1.0f, 0 ); } void CHighResolutionCapture::EndCapture() { if( !m_bCapture ) return; GetEtDevice()->RestoreDepthStencil(); GetEtDevice()->RestoreRenderTarget(); EtCameraHandle hCamera = CEtCamera::GetActiveCamera(); if( hCamera ) { hCamera->SetAspectRatio( m_fTempAspectRatio ); } if( m_pColorAdjFilter && 0 ) { // ÀÓ½ÃÅØ½ºÃ³¿¡ ÇöÀç RTT ³»¿ëÀ» º¹»çÇÑ ÈÄ m_hTempTarget->Copy( m_hRenderTarget ); // ÇÁ·¹¸®¿¡¼­ ¾²´Â°É·Î ÅëÀÏÇØ¼­ »ç¿ëÇÑ´Ù. float fSat = 0.f; fSat = m_pColorAdjFilter->GetSceneSaturation(); m_pColorAdjFilter->SetSceneSaturation( 1.0f ); bool bEnableZ = GetEtDevice()->EnableZ( false ); bool bAlphaEnable = GetEtDevice()->EnableAlphaBlend( true ); GetEtDevice()->SetDepthStencilSurface( NULL ); m_pColorAdjFilter->SetTexture( m_hTempTarget->GetMyIndex() ); m_pColorAdjFilter->DrawFilter( m_hRenderTarget, 1, EtVector2(0, 0), EtVector2(1, 1) , true ); GetEtDevice()->RestoreRenderTarget(); GetEtDevice()->RestoreDepthStencil(); GetEtDevice()->EnableZ( bEnableZ ); GetEtDevice()->EnableAlphaBlend( bAlphaEnable ); m_pColorAdjFilter->SetSceneSaturation( fSat ); } char szPath[MAX_PATH]={0,}; SHGetSpecialFolderPath(GetEtDevice()->GetHWnd(), szPath, CSIDL_PERSONAL, 0); __time64_t ltime; char szBuf[256] = { 0, }, szFile[256] = { 0, }; struct tm *tm_ptr; time(<ime); tm_ptr = localtime(<ime); strftime(szBuf, 256, "%Y-%m-%d %H-%M-%S %a", tm_ptr); sprintf(szFile, "%s %s.tga", m_szFilePrefix.c_str(), szBuf); char szResultName[MAX_PATH] = { 0, }; sprintf( szResultName, "%s\\ToolScreenshot", szPath ); if( !PathFileExists( szResultName ) ) _mkdir( szResultName ); sprintf( szResultName, "%s\\ToolScreenshot\\%s", szPath, szFile ); HRESULT hr = D3DXSaveSurfaceToFile( szResultName, D3DXIFF_TGA, m_hRenderTarget->GetSurfaceLevel(), NULL, NULL ); SAFE_RELEASE_SPTR( m_hRenderTarget ); SAFE_RELEASE_SPTR( m_hDepthTarget ); SAFE_RELEASE_SPTR( m_hTempTarget ); m_bCapture = false; }