void UIRender::SaveUIImage( std::string imagePath ) { LPDIRECT3DSURFACE9 pFrontSurface = NULL; UIDXInit::GetSingleton()->_pIDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pFrontSurface ); D3DXSaveSurfaceToFileA( imagePath.c_str(), D3DXIFF_PNG, pFrontSurface, NULL, NULL ); pFrontSurface->Release(); }
void surface_reset_target() { draw_batch_flush(batch_flush_deferred); LPDIRECT3DSURFACE9 pBackBuffer; d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer); d3ddev->SetRenderTarget(0, pBackBuffer); pBackBuffer->Release(); }
//************************************************************************************************************* void BlurTexture(LPDIRECT3DTEXTURE9 tex) { LPDIRECT3DSURFACE9 surface = NULL; LPDIRECT3DSURFACE9 blursurface = NULL; LPDIRECT3DTEXTURE9 blurtex = NULL; D3DXVECTOR4 texelsize(1.0f / SHADOWMAP_SIZE, 0, 0, 0); D3DSURFACE_DESC desc; tex->GetLevelDesc(0, &desc); if( desc.Format == D3DFMT_A8R8G8B8 ) blurtex = blurARGB8; // for convolution else blurtex = blurRGBA32F; // for others blurtex->GetSurfaceLevel(0, &blursurface); tex->GetSurfaceLevel(0, &surface); device->SetRenderTarget(0, blursurface); device->SetTexture(0, tex); device->SetVertexDeclaration(vertexdecl); boxblur5x5->SetVector("texelSize", &texelsize); boxblur5x5->Begin(NULL, 0); boxblur5x5->BeginPass(0); { device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &vertices[0], 6 * sizeof(float)); std::swap(texelsize.x, texelsize.y); boxblur5x5->SetVector("texelSize", &texelsize); boxblur5x5->CommitChanges(); device->SetRenderTarget(0, surface); device->SetTexture(0, blurtex); device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &vertices[0], 6 * sizeof(float)); } boxblur5x5->EndPass(); boxblur5x5->End(); surface->Release(); blursurface->Release(); }
LPDIRECT3DTEXTURE9 CShimmer::Render(LPDIRECT3DTEXTURE9 tex) { LPDIRECT3DSURFACE9 OldSurface = nullptr; LPDIRECT3DSURFACE9 OldDepth = nullptr; LPDIRECT3DDEVICE9 Device = Window::Instance()->Device(); //深度バッファはそのまま参照する Device->GetRenderTarget(0,&OldSurface); Device->SetRenderTarget(0,Surface); //陽炎マップをクリアする Device->Clear(0L,nullptr,(D3DCLEAR_TARGET | D3DCLEAR_STENCIL),0x80808080,1.0f,0); Effect->Begin(0,0); //陽炎パーティクルを描画 ShimmerParticle2D::DrawAll(); //背景を送る Effect->SetTexture(Param[BACK_BUFFER],tex); //陽炎マップを送る Effect->SetTexture(Param[SHIMMER_MAP],Texture); if (_BlurFlag) { //ブラーをかける ConductBlur(); } else { Device->SetRenderTarget(0,ResultSurface); } Device->Clear(0L,nullptr,(D3DCLEAR_TARGET | D3DCLEAR_STENCIL),D3DXCOLOR(0.0f,0,0,0),1.0f,0); //歪ませて描く Effect->BeginPass(0); Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); Effect->EndPass(); Effect->End(); //最初のサーフェイスに戻す Device->SetRenderTarget(0,OldSurface); //後始末 if (OldSurface != nullptr) { OldSurface->Release(); OldSurface = nullptr; } return Result; }
void cTexture::BltToTextureSurface(LPDIRECT3DTEXTURE9 pTempTex ) { SafeRelease( m_pTexture ); D3DSURFACE_DESC TexDesc; pTempTex->GetLevelDesc( 0, &TexDesc ); DWORD NumLevels = pTempTex->GetLevelCount(); D3DXCreateTexture( Graphics()->GetDevice(), TexDesc.Width, TexDesc.Height, NumLevels, 0, TexDesc.Format, D3DPOOL_MANAGED, &m_pTexture ); LPDIRECT3DSURFACE9 pSrcSurf = 0; LPDIRECT3DSURFACE9 pDestSurf = 0; for( int i = 0 ; i < NumLevels ; i++ ) { m_pTexture->GetSurfaceLevel( i, &pDestSurf ); pTempTex->GetSurfaceLevel( i, &pSrcSurf ); D3DXLoadSurfaceFromSurface( pDestSurf, 0, 0, pSrcSurf, 0, 0, D3DX_FILTER_NONE, 0 ); pDestSurf->Release(); pSrcSurf->Release(); } }
void cScreenShot::saveToFile(TCHAR const* fileName) { LPDIRECT3DSURFACE9 pbackbuffer; if (cD3DSystem::getD3DDevice()->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pbackbuffer) == D3D_OK) { D3DXSaveSurfaceToFile(fileName, (D3DXIMAGE_FILEFORMAT)cScreenShot::expType, pbackbuffer, NULL, NULL); pbackbuffer->Release(); trace(_T("screen shot: %s\n"), fileName); } }
//copies DirectX backbuffer to the render_texture structure //This can be slow.... //But, its needed to render framebuffer effects, due to the current implementation. void DXFrameBufferManager::CopyBackBufferToRenderTexture(int idx, RecentCIInfo &ciInfo, RECT* pDstRect) { LPDIRECT3DSURFACE9 pSavedBuffer; gRenderTextureInfos[idx].pRenderTexture->m_pTexture->GetTexture()->GetSurfaceLevel(0,&pSavedBuffer); HRESULT res; if( pSavedBuffer != NULL ) { LPDIRECT3DSURFACE9 pBackBufferToSave = NULL; g_pD3DDev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBufferToSave); if( pBackBufferToSave ) { if( pDstRect == NULL ) { res = g_pD3DDev->UpdateSurface(pBackBufferToSave,NULL,pSavedBuffer,NULL); } else { float scaleX = windowSetting.uDisplayWidth/(float)ciInfo.dwWidth; float scaleY = windowSetting.uDisplayHeight/(float)ciInfo.dwHeight; RECT srcr = { uint32(pDstRect->left*scaleX), uint32(pDstRect->top*scaleY), uint32(pDstRect->right*scaleX), uint32(pDstRect->bottom*scaleY) }; POINT srcp = {uint32(pDstRect->left*scaleX), uint32(pDstRect->top*scaleY)}; res = g_pD3DDev->UpdateSurface(pBackBufferToSave,&srcr,pSavedBuffer,&srcp); } if( res != S_OK ) { TRACE0("Cannot save back buffer"); } pBackBufferToSave->Release(); } pSavedBuffer->Release(); } else { TRACE0("Cannot save back buffer"); } }
// @brief : スクリーンショット // @param : スクリーンショット名 //-------------------------------------------------------------------- void DirectX9::ScreenShort( const std::string &_str ) const { // バックバッファを取得 LPDIRECT3DSURFACE9 pBackBuff; direct3d_device->GetRenderTarget( 0, &pBackBuff ); // スクショ出力 D3DXSaveSurfaceToFile( _str.c_str(), D3DXIFF_BMP, pBackBuff, NULL, NULL ); // 取得したものを解放 pBackBuff->Release(); }
void teTexture::UpdateSize() { LPDIRECT3DSURFACE9 surface; texture->GetSurfaceLevel(0, &surface); D3DSURFACE_DESC desc; surface->GetDesc(&desc); size.x = desc.Width; size.y = desc.Height; surface->Release(); }
bool Game_Init(HWND window) { Direct3D_Init(window, SCREENW, SCREENH, false); DirectInput_Init(window); //create a font font = MakeFont("Arial", 24); //load background LPDIRECT3DSURFACE9 image = NULL; image = LoadSurface("space2.bmp"); if (!image) return false; //create background HRESULT result = d3ddev->CreateOffscreenPlainSurface( BUFFERW, BUFFERH, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &background, NULL); if (result != D3D_OK) return false; //copy image to upper left corner of background RECT source_rect = {0, 0, 1024, 768 }; RECT dest_ul = { 0, 0, 1024, 768 }; d3ddev->StretchRect(image, &source_rect, background, &dest_ul, D3DTEXF_NONE); //copy image to upper right corner of background RECT dest_ur = { 1024, 0, 1024*2, 768 }; d3ddev->StretchRect(image, &source_rect, background, &dest_ur, D3DTEXF_NONE); //copy image to lower left corner of background RECT dest_ll = { 0, 768, 1024, 768*2 }; d3ddev->StretchRect(image, &source_rect, background, &dest_ll, D3DTEXF_NONE); //copy image to lower right corner of background RECT dest_lr = { 1024, 768, 1024*2, 768*2 }; d3ddev->StretchRect(image, &source_rect, background, &dest_lr, D3DTEXF_NONE); //get pointer to the back buffer d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); //remove image image->Release(); return true; }
//----------------------------------------------------------------------------// void Direct3D9TextureTarget::enableRenderTexture() { LPDIRECT3DSURFACE9 oldSurface = 0; d_device->GetRenderTarget(0, &oldSurface); if (oldSurface && oldSurface != d_surface) { d_prevColourSurface = oldSurface; d_device->SetRenderTarget(0, d_surface); } else if (oldSurface) oldSurface->Release(); }
bool restore_objects() { if ( retry_count ) { if ( --retry_count ) return false; release_objects(); if ( lpdev->Reset( &dpp ) != D3D_OK ) return false; } retry_count = 0; LPDIRECT3DSURFACE9 lpbb; HRESULT hr; if( SUCCEEDED( hr = lpdev->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, & lpbb ) ) ) { lpbb->GetDesc( & d3dsd ); lpbb->Release(); } lpdev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); lpdev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); lpdev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); lpdev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); lpdev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); lpdev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); lpdev->SetRenderState(D3DRS_LIGHTING, false); lpdev->SetRenderState(D3DRS_ZENABLE, false); lpdev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); lpdev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); lpdev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); lpdev->SetRenderState(D3DRS_ALPHABLENDENABLE, false); lpdev->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1); if ( lpdev->CreateVertexBuffer( sizeof(d3dvertex) * 4, flags.v_usage, D3DFVF_XYZRHW | D3DFVF_TEX1, (D3DPOOL)flags.v_pool, &lpvbuf, NULL ) != D3D_OK ) return false; update_filtering( 1 ); lpdev->SetRenderState( D3DRS_DITHERENABLE, TRUE ); if ( lpdev->CreateTexture( surface_width, surface_height, 1, flags.t_usage, D3DFMT_X8R8G8B8, (D3DPOOL)flags.t_pool, &lptex, NULL ) != D3D_OK ) return false; return true; }
bool CWinShader::Execute(std::vector<LPDIRECT3DSURFACE9> *vecRT, unsigned int vertexIndexStep) { LPDIRECT3DDEVICE9 pD3DDevice = g_Windowing.Get3DDevice(); LPDIRECT3DSURFACE9 oldRT = 0; // The render target will be overriden: save the caller's original RT if (vecRT != NULL && !vecRT->empty()) pD3DDevice->GetRenderTarget(0, &oldRT); pD3DDevice->SetFVF(m_FVF); pD3DDevice->SetStreamSource(0, m_vb.Get(), 0, m_vertsize); UINT cPasses, iPass; if (!m_effect.Begin( &cPasses, 0 )) { CLog::Log(LOGERROR, __FUNCTION__" - failed to begin d3d effect"); return false; } for( iPass = 0; iPass < cPasses; iPass++ ) { if (!m_effect.BeginPass( iPass )) { CLog::Log(LOGERROR, __FUNCTION__" - failed to begin d3d effect pass"); break; } if (vecRT != NULL && vecRT->size() > iPass) pD3DDevice->SetRenderTarget(0, (*vecRT)[iPass]); HRESULT hr = pD3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, iPass * vertexIndexStep, m_primitivesCount); if (FAILED(hr)) CLog::Log(LOGERROR, __FUNCTION__" - failed DrawPrimitive %08X", hr); if (!m_effect.EndPass()) CLog::Log(LOGERROR, __FUNCTION__" - failed to end d3d effect pass"); } if (!m_effect.End()) CLog::Log(LOGERROR, __FUNCTION__" - failed to end d3d effect"); if (oldRT != 0) { pD3DDevice->SetRenderTarget(0, oldRT); oldRT->Release(); } return true; }
// Kill off all POOL_DEFAULT device objects. void TeardownDeviceObjects() { if(ScreenShootMEMSurface) ScreenShootMEMSurface->Release(); ScreenShootMEMSurface = NULL; D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface()); D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface()); delete g_framebuffer_manager; D3D::font.Shutdown(); TextureCache::Invalidate(); VertexLoaderManager::Shutdown(); VertexShaderCache::Shutdown(); PixelShaderCache::Shutdown(); TextureConverter::Shutdown(); g_vertex_manager->DestroyDeviceObjects(); }
void D3DOverdrawWindow:: SetupViewport(void) { LPDIRECT3DSURFACE9 back; d3d->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &back); D3DSURFACE_DESC desc; back->GetDesc(&desc); back->Release(); D3DVIEWPORT9 full; full.X = full.Y = 0; full.Width = desc.Width; full.Height = desc.Height; full.MinZ = 0; full.MaxZ = 1; d3d->SetViewport(&full); }
void CMyGame::setTerrainFile() { if (m_isTerrainChanged=true) { LPDIRECT3DSURFACE9 image = NULL; m_Terrainename=MapEditorControllerSingleton::Instance().GetMapData()->GetTerrainFilePath(); image = myDirectx.LoadSurface(m_Terrainename); int nscreenWid=m_winRect.Width()*2; for (int i=0;i<=(m_winRect.Width()*2/MapSizeWidth);i++) { int nscreenHei=m_winRect.Height()*2; for (int j=0;j<=(m_winRect.Height()*2/MapSizeHeight);j++) { RECT source_rect={0,0,MapSizeWidth,MapSizeHeight}; RECT dest_ul={i*MapSizeWidth,j*MapSizeHeight,(i+1)*MapSizeWidth,(j+1)*MapSizeHeight}; if (nscreenWid<MapSizeWidth) { source_rect.right=nscreenWid; dest_ul.right=i*MapSizeWidth+nscreenWid; } if (nscreenHei<MapSizeHeight) { source_rect.bottom=nscreenHei; dest_ul.bottom=j*MapSizeHeight+nscreenHei; } myDirectx.d3ddev->StretchRect( image, &source_rect, background, &dest_ul, D3DTEXF_NONE); nscreenHei-=MapSizeHeight; } nscreenWid-=MapSizeWidth; } image->Release(); m_isTerrainChanged=false; } }
ErrorCode Texture::getSurface(uint level, Surface& surf) { if (level >= tex->GetLevelCount()) return ErrorHandle(mamain->err, ErrorInv); LPDIRECT3DSURFACE9 s; HRESULT res = tex->GetSurfaceLevel(level, &s); if (FAILED(res)) return ErrorHandleCritical(mamain->err, mamain->errCrit, ErrorD3D9, res, "GetSurfaceLevel"); ErrorCode ret = surf.createFromPointer(s); s->Release(); return ret; }
ErrorCode Surface::resetDepthBuffer() { if (DepthBuffers.empty()) return ErrorHandle(mamain->err, ErrorInv); LPDIRECT3DSURFACE9 surf = DepthBuffers.top(); DepthBuffers.pop(); surf->Release(); HRESULT res = mamain->d3ddev->SetDepthStencilSurface(surf); if (FAILED(res)) return ErrorHandle(mamain->err, ErrorD3D9, res, "SetDepthStencilSurface"); return ErrorOk; }
void XFBSource::CopyEFB(float Gamma) { g_renderer->ResetAPIState(); // reset any game specific settings // Copy EFB data to XFB and restore render target again LPDIRECT3DSURFACE9 Rendersurf = NULL; texture->GetSurfaceLevel(0, &Rendersurf); D3D::dev->SetDepthStencilSurface(NULL); D3D::dev->SetRenderTarget(0, Rendersurf); D3DVIEWPORT9 vp; vp.X = 0; vp.Y = 0; vp.Width = texWidth; vp.Height = texHeight; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; D3D::dev->SetViewport(&vp); D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); D3D::drawShadedTexQuad( FramebufferManager::GetEFBColorTexture(), nullptr, Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), texWidth, texHeight, PixelShaderCache::GetColorCopyProgram(0), VertexShaderCache::GetSimpleVertexShader(0), Gamma); D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER); D3D::RefreshSamplerState(0, D3DSAMP_MAGFILTER); D3D::SetTexture(0, NULL); D3D::dev->SetRenderTarget(0, FramebufferManager::GetEFBColorRTSurface()); D3D::dev->SetDepthStencilSurface(FramebufferManager::GetEFBDepthRTSurface()); Rendersurf->Release(); g_renderer->RestoreAPIState(); }
void release_objects() { if ( lpsurface ) { lpsurface->Release(); lpsurface = 0; } if ( lptex ) { lptex->Release(); lptex = 0; } if ( lpvbuf ) { lpvbuf->Release(); lpvbuf = 0; } }
virtual void clear() { if ( retry_count && !restore_objects() ) return; lptex->GetLevelDesc(0, &d3dsd); lptex->GetSurfaceLevel(0, &lpsurface); if ( lpsurface ) { lpdev->ColorFill( lpsurface, NULL, D3DCOLOR_XRGB(0x00, 0x00, 0x00) ); lpsurface->Release(); lpsurface = 0; } for ( unsigned i = 0; i < 3; i++ ) { lpdev->Clear( 0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0x00, 0x00, 0x00), 1.0f, 0 ); lpdev->Present( 0, 0, 0, 0 ); } }
void DirectXEngine::InitDeviceObjects(LPDIRECT3D9 pd3d, LPDIRECT3DDEVICE9 pd3dDevice, IDirect3DSwapChain9* pd3dSwapChain) { m_pD3D = pd3d; m_pd3dDevice = pd3dDevice; m_pd3dSwapChain = pd3dSwapChain; // Store render target surface desc LPDIRECT3DSURFACE9 pBackBuffer = NULL; if(m_pd3dSwapChain) { m_pd3dSwapChain->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); } else if(m_pd3dDevice) { m_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); } pBackBuffer->GetDesc( &m_d3dsdBackBuffer ); pBackBuffer->Release(); // Store device Caps m_pd3dDevice->GetDeviceCaps( &m_d3dCaps ); }
ErrorCode Surface::resetRenderTarget(uint level) { if (level > MaxRenderTargets || RenderTargets[level].empty()) return ErrorHandle(mamain->err, ErrorInv); LPDIRECT3DSURFACE9 surf = RenderTargets[level].top(); RenderTargets[level].pop(); surf->Release(); HRESULT res = mamain->d3ddev->SetRenderTarget(level, surf); mamain->d3ddev->SetViewport(&Viewports[level].top()); Viewports[level].pop(); if (FAILED(res)) return ErrorHandle(mamain->err, ErrorD3D9, res, "SetRenderTarget"); return ErrorOk; }
String screengrab(String filename) { if(filename=="" || filename == " () ") { filename.sprintf("%s_%5.5d_.png",(const char*)screengrabprefix,screengrabcount); screengrabcount++; } if(!IsOneOf('.',filename)) filename << ".png"; HRESULT hr; // get display dimensions // this will be the dimensions of the front buffer D3DDISPLAYMODE mode; if (FAILED(hr=g_pd3dDevice->GetDisplayMode(0,&mode))) { return "fail getdisplaymode"; } // create the image surface to store the front buffer image // note that call to GetFrontBuffer will always convert format to A8R8G8B8 static LPDIRECT3DSURFACE9 surf=NULL; if (!surf && FAILED(hr=g_pd3dDevice->CreateOffscreenPlainSurface(mode.Width,mode.Height, D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&surf,NULL))) { return "fail createimagesurface"; } // Next, this surface is passed to the GetFrontBuffer() method of the device, which will copy the entire screen into our image buffer: // read the front buffer into the image surface if (FAILED(hr=g_pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&surf))) { surf->Release(); return "fail getfrontbuffer"; } //Finally, we call D3DXSaveSurfaceToFile() to create the BMP file, and release the temporary image surface: // write the entire surface to the requested file hr=D3DXSaveSurfaceToFile(filename,D3DXIFF_PNG,surf,NULL,NULL); // release the image surface // surf->Release(); // return status of save operation to caller return (hr==D3D_OK)? filename + " exported!" : "something failed"; }
void RenderController::RenderDirectionalDepths() { // Change the stencil buffer surface LPDIRECT3DSURFACE9 pOldDS = NULL; Renderer::theDevicePtr->GetDepthStencilSurface( &pOldDS ); Renderer::theDevicePtr->SetDepthStencilSurface( m_pDirectionalDSShadow ); m_DirectionalLight.ActivateShadowTarget(m_SharedParameterContext.GetEffect(), 0); Renderer::theDevicePtr->Clear(0,0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1, 0); RenderShadowCasters(RenderContext::RS_DEPTH_DIR_LIGHT); m_DirectionalLight.RevertTarget(); // Change back the stencil buffer surface if( pOldDS ) { Renderer::theDevicePtr->SetDepthStencilSurface( pOldDS ); pOldDS->Release(); } }
LTRESULT CLTRenderMgr::StretchRectRenderTargetToBackBuffer(HRENDERTARGET hRenderTarget) { CRenderTarget* pRenderTarget = CRenderTargetMgr::GetSingleton().GetRenderTarget(hRenderTarget); if(pRenderTarget) { LPDIRECT3DSURFACE9 pBackBuffer = NULL; if (FAILED(PD3DDEVICE->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&pBackBuffer))) { return LT_ERROR; } LTRESULT hr = pRenderTarget->StretchRectToSurface(pBackBuffer); //g_Device.m_pDefaultRenderTarget pBackBuffer->Release(); return hr; } return LT_ERROR; }
//----------------------------------------------------------------------------- // Name: setFullscreenViewport // Desc: Initializes the rendering depth utilized for this layer. The layer will not // render beyond this Z range. Note that elements are positioned according to // a 'depth' value, which is not the same thing as the 'z' value. The depth value // ranges from 0.0f to 1.0f always (anything else is not rendered), and maps into // the range of Z values specified by this method when rendered. // This method fails silently if the layer has not been created successfully. //----------------------------------------------------------------------------- void GUILayer::setFullscreenViewport(float minZ, float maxZ) { // Store the Z-coordinates in the viewport myViewport.MinZ = minZ; myViewport.MaxZ = maxZ; // Fail here unless we have a device pointer if (!d3d_device_) return; // Get the device's size LPDIRECT3DSURFACE9 backBufferSurface; if (FAILED(d3d_device_->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBufferSurface))) return; // Get the back buffer description, and release the surface D3DSURFACE_DESC backBufferDesc; backBufferSurface->GetDesc(&backBufferDesc); backBufferSurface->Release(); // Initialize the rest of the viewport myViewport.X = 0; myViewport.Y = 0; myViewport.Width = backBufferDesc.Width; myViewport.Height = backBufferDesc.Height; // Make sure that the primary canvas mirrors this information myPrimaryCanvas.alignXLeft(0); myPrimaryCanvas.alignYTop(0); myPrimaryCanvas.absoluteWidth(backBufferDesc.Width); myPrimaryCanvas.absoluteHeight(backBufferDesc.Height); //myPrimaryCanvas.realign(); // Set up the projection matrix. This sets the bottom as the minimum Y-coordinate so that // the matrix will be created in the right Y-orientation (increasing Y coordinates from top to bottom) D3DXMatrixOrthoOffCenterLH(&myProjectionMatrix, 0.0f, (float)backBufferDesc.Width, (float)backBufferDesc.Height, 0.0f, 0.0f, 1.0f); }
bool CWinRenderer::CreateIntermediateRenderTarget() { // Initialize a render target for intermediate rendering - same size as the video source LPDIRECT3DDEVICE9 pD3DDevice = g_Windowing.Get3DDevice(); D3DFORMAT format = D3DFMT_X8R8G8B8; DWORD usage = D3DUSAGE_RENDERTARGET; if (g_Windowing.IsTextureFormatOk(D3DFMT_A2R10G10B10, usage)) format = D3DFMT_A2R10G10B10; else if (g_Windowing.IsTextureFormatOk(D3DFMT_A2B10G10R10, usage)) format = D3DFMT_A2B10G10R10; else if (g_Windowing.IsTextureFormatOk(D3DFMT_A8R8G8B8, usage)) format = D3DFMT_A8R8G8B8; else if (g_Windowing.IsTextureFormatOk(D3DFMT_A8B8G8R8, usage)) format = D3DFMT_A8B8G8R8; else if (g_Windowing.IsTextureFormatOk(D3DFMT_X8R8G8B8, usage)) format = D3DFMT_X8R8G8B8; else if (g_Windowing.IsTextureFormatOk(D3DFMT_X8B8G8R8, usage)) format = D3DFMT_X8B8G8R8; else if (g_Windowing.IsTextureFormatOk(D3DFMT_R8G8B8, usage)) format = D3DFMT_R8G8B8; CLog::Log(LOGDEBUG, __FUNCTION__": format %i", format); if(!m_IntermediateTarget.Create(m_sourceWidth, m_sourceHeight, 1, usage, format, D3DPOOL_DEFAULT)) { CLog::Log(LOGERROR, __FUNCTION__": render target creation failed. Going back to bilinear scaling.", format); return false; } //Pixel shaders need a matching depth-stencil surface. LPDIRECT3DSURFACE9 tmpSurface; D3DSURFACE_DESC tmpDesc; //Use the same depth stencil format as the backbuffer. pD3DDevice->GetDepthStencilSurface(&tmpSurface); tmpSurface->GetDesc(&tmpDesc); tmpSurface->Release(); if (!m_IntermediateStencilSurface.Create(m_sourceWidth, m_sourceHeight, 1, D3DUSAGE_DEPTHSTENCIL, tmpDesc.Format, D3DPOOL_DEFAULT)) { CLog::Log(LOGERROR, __FUNCTION__": Failed to create depth stencil. Going back to bilinear scaling."); m_IntermediateTarget.Release(); return false; } return true; }
//-------------------------------------------------------------------------------------- // RenderToTexture( ) // // DESC: // A simple utility function that draws, as a TL Quad, one texture to another // such that a pixel shader (configured before this function is called) can // operate on the texture. Used by MeasureLuminance() to perform the // downsampling and filtering. // // PARAMS: // pDevice : The currently active device // // NOTES: // n/a // //-------------------------------------------------------------------------------------- HRESULT RenderToTexture( IDirect3DDevice9* pDev ) { D3DSURFACE_DESC desc; LPDIRECT3DSURFACE9 pSurfRT; pDev->GetRenderTarget( 0, &pSurfRT ); pSurfRT->GetDesc( &desc ); pSurfRT->Release(); // To correctly map from texels->pixels we offset the coordinates // by -0.5f: float fWidth = static_cast< float >( desc.Width ) - 0.5f; float fHeight = static_cast< float >( desc.Height ) - 0.5f; // Now we can actually assemble the screen-space geometry PostProcess::TLVertex v[4]; v[0].p = D3DXVECTOR4( -0.5f, -0.5f, 0.0f, 1.0f ); v[0].t = D3DXVECTOR2( 0.0f, 0.0f ); v[1].p = D3DXVECTOR4( fWidth, -0.5f, 0.0f, 1.0f ); v[1].t = D3DXVECTOR2( 1.0f, 0.0f ); v[2].p = D3DXVECTOR4( -0.5f, fHeight, 0.0f, 1.0f ); v[2].t = D3DXVECTOR2( 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fWidth, fHeight, 0.0f, 1.0f ); v[3].t = D3DXVECTOR2( 1.0f, 1.0f ); // Configure the device and render.. pDev->SetVertexShader( NULL ); pDev->SetFVF( PostProcess::FVF_TLVERTEX ); pDev->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( PostProcess::TLVertex ) ); return S_OK; }
void DxFw::saveScreenshot(const char* fileName) { if (fileName == 0) return; //log("start save shot"); LPDIRECT3DSURFACE9 surface = 0; D3DDISPLAYMODE mode; mDevice->GetDisplayMode(0,&mode); if (FAILED( mDevice->CreateOffscreenPlainSurface(mode.Width,mode.Height,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&surface,0))) { MessageBox(0,"save screenshot failed","error",MB_OK); return; } if (FAILED(mDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&surface))) { MessageBox(0,"save screenshot failed","error",MB_OK); return; } D3DXSaveSurfaceToFile(fileName,D3DXIFF_PNG,surface,0,0); surface->Release(); }