bool Blit::copy(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) { RenderTarget9 *renderTarget = NULL; IDirect3DSurface9 *source = NULL; gl::Renderbuffer *colorbuffer = framebuffer->getColorbuffer(0); if (colorbuffer) { renderTarget = RenderTarget9::makeRenderTarget9(colorbuffer->getRenderTarget()); } if (renderTarget) { source = renderTarget->getSurface(); } if (!source) { ERR("Failed to retrieve the render target."); return gl::error(GL_OUT_OF_MEMORY, false); } TextureStorage9_Cube *storage9 = TextureStorage9_Cube::makeTextureStorage9_Cube(storage->getStorageInstance()); IDirect3DSurface9 *destSurface = storage9->getCubeMapSurface(target, level, true); bool result = false; if (destSurface) { result = copy(source, sourceRect, destFormat, xoffset, yoffset, destSurface); destSurface->Release(); } source->Release(); return result; }
ImagePtr D3D9VideoBufferManager::CreateImage(int iWidth, int iHeight, FORMAT Format) { IDirect3DTexture9 * texture; HRESULT hr = D3DXCreateTexture(mD3D9Device, iWidth, iHeight, 1, 0, D3D9Mapping::GetD3DFormat(Format), D3DPOOL_SYSTEMMEM, &texture); D3DErrorExceptionFunction(D3DXCreateTexture, hr); IDirect3DSurface9 * surface; texture->GetSurfaceLevel(0, &surface); D3DSURFACE_DESC desc; surface->GetDesc(&desc); D3D9Image * image = new D3D9Image(); image->mWidth = desc.Width; image->mHeight = desc.Height; image->mSrcWidth = iWidth; image->mSrcHeight = iHeight; image->mFormat = D3D9Mapping::GetFormat(desc.Format); image->mMipmapLevel = texture->GetLevelCount(); image->mD3D9Texture = texture; surface->Release(); return ImagePtr(image); }
QByteArray MFTransform::dataFromBuffer(IMFMediaBuffer *buffer, int height, int *bytesPerLine) { QByteArray array; BYTE *bytes; DWORD length; HRESULT hr = buffer->Lock(&bytes, NULL, &length); if (SUCCEEDED(hr)) { array = QByteArray((const char *)bytes, (int)length); buffer->Unlock(); } else { // try to lock as Direct3DSurface IDirect3DSurface9 *surface = 0; do { if (FAILED(MFGetService(buffer, MR_BUFFER_SERVICE, IID_IDirect3DSurface9, (void**)&surface))) break; D3DLOCKED_RECT rect; if (FAILED(surface->LockRect(&rect, NULL, D3DLOCK_READONLY))) break; if (bytesPerLine) *bytesPerLine = (int)rect.Pitch; array = QByteArray((const char *)rect.pBits, rect.Pitch * height); surface->UnlockRect(); } while (false); if (surface) { surface->Release(); surface = 0; } } return array; }
GBitmap *AtlasTexChunk::loadDDSIntoGBitmap(const U8 *ddsBuffer, U32 ddsBufferSize) { D3DXIMAGE_INFO info; D3D9Assert(GFXD3DX.D3DXGetImageInfoFromFileInMemory(ddsBuffer, ddsBufferSize, &info), "AtlasTexChunk::loadDDSIntoGBitmap - failed to get image info."); IDirect3DSurface9 *surf = NULL; D3D9Assert(((GFXD3D9Device*)GFX)->getDevice()->CreateOffscreenPlainSurface( info.Width, info.Height, info.Format, D3DPOOL_SCRATCH, &surf, NULL), "AtlasTexChunk::loadDDSIntoGBitmap - failed to allocate scratch surface."); // We want JPEGs, let's convert it in a klunky way... D3D9Assert(GFXD3DX.D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, ddsBuffer, ddsBufferSize, NULL, D3DX_DEFAULT, 0, NULL), "AtlasTexChunk::loadDDSIntoGBitmap - D3DX failed to load from buffer."); ID3DXBuffer *buff = NULL; D3D9Assert(GFXD3DX.D3DXSaveSurfaceToFileInMemory(&buff, D3DXIFF_PNG, surf, NULL, NULL), "AtlasTexChunk::loadDDSIntoGBitmap - D3DX failed to save back to buffer."); MemStream ms(buff->GetBufferSize(), buff->GetBufferPointer(), true, false); GBitmap *bitmap = new GBitmap[1]; bitmap->readBitmap( "png", ms ); // Cleanup! buff->Release(); surf->Release(); return bitmap; }
void COverlayRenderer::DrawToTexture(OSDTexture* pOsdTexture, IDirect3DTexture9* pTexture, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { if (!pOsdTexture || !pTexture || !m_pD3DDevice) return; RECT sourceRect; sourceRect.left = 0; sourceRect.top = 0; sourceRect.right = w; sourceRect.bottom = h; RECT dstRect; dstRect.left = x; dstRect.top = y; dstRect.right = x + w; dstRect.bottom = y + h; IDirect3DSurface9* sourceSurface = NULL; IDirect3DSurface9* dstSurface = NULL; pTexture->GetSurfaceLevel(0, &sourceSurface); pOsdTexture->texture->GetSurfaceLevel(0, &dstSurface); m_pD3DDevice->StretchRect(sourceSurface, &sourceRect, dstSurface, &dstRect, D3DTEXF_NONE); sourceSurface->Release(); dstSurface->Release(); pTexture->Release(); }
LTRESULT CRenderTarget::InstallOnDevice() { if(m_pRenderTarget == NULL || m_pDepthStencilBuffer == NULL) { return LT_ERROR; } IDirect3DSurface9* pRTSurface; if(FAILED(m_pRenderTarget->GetSurfaceLevel(0, &pRTSurface))) { return LT_ERROR; } if(FAILED(PD3DDEVICE->SetRenderTarget(pRTSurface, m_pDepthStencilBuffer))) { dsi_ConsolePrint("Failed to set the new render target!"); pRTSurface->Release(); return LT_ERROR; } // We need to clear to make it a valid render target. if(FAILED(PD3DDEVICE->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DRGBA_255(0, 0, 0, 0), 1.0f, 0))) { PD3DDEVICE->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DRGBA_255(0, 0, 0, 0), 1.0f, 0); } pRTSurface->Release(); return LT_OK; }
HRESULT WINAPI D3D9ProxySwapChain::Present(CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) { #ifdef _DEBUG OutputDebugString(__FUNCTION__); OutputDebugString("\n"); #endif; // Test only, StereoView needs to be properly integrated as part of SwapChain. // This test allowed deus ex menus and videos to work correctly. Lots of model rendering issues in game though D3DProxyDevice* pD3DProxyDev = static_cast<D3DProxyDevice*>(m_pOwningDevice); IDirect3DSurface9* pWrappedBackBuffer; try { GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pWrappedBackBuffer); if (pD3DProxyDev->stereoView->initialized) pD3DProxyDev->stereoView->Draw(static_cast<D3D9ProxySurface*>(pWrappedBackBuffer)); pWrappedBackBuffer->Release(); } catch (std::out_of_range) { OutputDebugString("Present: No primary swap chain found. (Present probably called before device has been reset)"); } return m_pActualSwapChain->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags); }
void D3D9Sprite::RecoverFromBackup() { if (!m_pBackupTexture) return; m_texture = m_video.lock()->CreateRenderTargetTexture(static_cast<unsigned int>(m_size.x), static_cast<unsigned int>(m_size.y), m_targetFormat); IDirect3DTexture9* pBackup = m_pBackupTexture; IDirect3DTexture9* pActualTexture; try { pActualTexture = boost::any_cast<IDirect3DTexture9*>(m_texture->GetTextureObject()); } catch (const boost::bad_any_cast &) { std::wstringstream ss; ss << L"D3D9Sprite::RecoverFromBackup Invalid texture pointer" << std::endl; ShowMessage(ss, GSMT_ERROR); return; } IDirect3DSurface9* pActualSurface = NULL; IDirect3DSurface9* pBackupSurf = NULL; pActualTexture->GetSurfaceLevel(0, &pActualSurface); pBackup->GetSurfaceLevel(0, &pBackupSurf); m_pDevice->UpdateSurface(pBackupSurf, NULL, pActualSurface, NULL); pBackupSurf->Release(); pActualSurface->Release(); GetInternalData(); }
void DS_Basic_MRT::buildGBuffers() { HRESULT hr; //-- G-Buffsers SetRenderTarget SRT(m_pD3DDevice, m_posRT); IDirect3DSurface9 *pSurfaceZ = NULL; hr = m_posRT_Z->GetSurfaceLevel(0, &pSurfaceZ ); IDirect3DSurface9 *pSurfaceNormal = NULL; hr = m_normalRT->GetSurfaceLevel(0, &pSurfaceNormal ); IDirect3DSurface9 *pSurfaceDiffuse= NULL; hr = m_diffuseRT->GetSurfaceLevel(0, &pSurfaceDiffuse ); hr = m_pD3DDevice->SetRenderTarget(1, pSurfaceZ); hr = m_pD3DDevice->SetRenderTarget(2, pSurfaceNormal); hr = m_pD3DDevice->SetRenderTarget(3, pSurfaceDiffuse); pSurfaceZ->Release(); pSurfaceDiffuse->Release(); pSurfaceNormal->Release(); hr = m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1, 0); hr = m_pEffect->SetTechnique("init_mrt"); renderScene(); hr = m_pD3DDevice->SetRenderTarget(1, NULL); hr = m_pD3DDevice->SetRenderTarget(2, NULL); hr = m_pD3DDevice->SetRenderTarget(3, NULL); //hr = D3DXSaveTextureToFile("D:\\test.dds", D3DXIFF_DDS, m_posRT, NULL); }
//----------------------------------------------------------------------------- // unLock //----------------------------------------------------------------------------- void GFXD3D9TextureObject::unlock(U32 mipLevel) { AssertFatal( mLocked, "GFXD3D9TextureObject::unlock - Attempting to unlock a surface that has not been locked" ); #ifndef TORQUE_OS_XENON if( mProfile->isRenderTarget() ) { IDirect3DSurface9 *dest; GFXD3D9TextureObject *to = (GFXD3D9TextureObject *) &(*mLockTex); D3D9Assert( to->get2DTex()->GetSurfaceLevel( 0, &dest ), NULL ); dest->UnlockRect(); dest->Release(); mLocked = false; } else #endif { D3D9Assert( get2DTex()->UnlockRect(mipLevel), "GFXD3D9TextureObject::unlock - could not unlock non-RT texture." ); mLocked = false; } }
HRESULT VMRSurfaceAllocator::PresentToTexture( VMR9PresentationInfo *lpPresInfo ) { HRESULT hr; IDirect3DTexture9 *lpTexture; IDirect3DSurface9 *lpSurface; if ( m_alpDirect3DTexture[ 0 ] != NULL ) { clock->Lock(); lpTexture = m_alpDirect3DTexture[ m_nFilpTexNum ]; hr = lpTexture->GetSurfaceLevel( 0, &lpSurface ); if ( hr != S_OK ) { return hr; } hr = D3DDev->StretchRect( lpPresInfo->lpSurf, NULL, lpSurface, NULL, D3DTEXF_NONE ); if ( hr != S_OK ) { lpSurface->Release(); return hr; } lpSurface->Release(); texnum = m_nFilpTexNum; m_nFilpTexNum = m_nFilpTexNum ^ 0x01; clock->Unlock(); } else { m_nFilpTexNum = -1; } return S_OK; }
void RSManager::DoLimbo() { if (!(mainRT && zSurf && doLimbo && limbo)) return; IDirect3DSurface9 *oldRenderTarget; d3ddev->GetRenderTarget(0, &oldRenderTarget); if (oldRenderTarget == mainRT) { // final renderbuffer has to be from texture, just making sure here if (IDirect3DTexture9* tex = getSurfTexture(oldRenderTarget)) { // check size just to make even more sure D3DSURFACE_DESC desc; oldRenderTarget->GetDesc(&desc); if (desc.Width == Settings::get().getRenderWidth() && desc.Height == Settings::get().getRenderHeight()) { IDirect3DTexture9 *zTex = getSurfTexture(zSurf); storeRenderState(); d3ddev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); d3ddev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE); /// Draw zbuffer limbo->go(zTex, oldRenderTarget, limboZNear, limboZFar); SDLOG(0, "ZNear: %g, ZFar: %g\n", limboZNear, limboZFar); //d3ddev->StretchRect(zSurf, NULL, oldRenderTarget, NULL, D3DTEXF_NONE); restoreRenderState(); zTex->Release(); } tex->Release(); } } oldRenderTarget->Release(); }
void RenderController::CreateDepthBuffers() { IDirect3DSurface9 *pOldDS = NULL; D3DSURFACE_DESC desc; Renderer::theDevicePtr->GetDepthStencilSurface( &pOldDS ); pOldDS->GetDesc(&desc); pOldDS->Release(); Renderer::theDevicePtr->CreateDepthStencilSurface( thePointShadowSize, thePointShadowSize, desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pPointDSShadow, NULL ); Renderer::theDevicePtr->CreateDepthStencilSurface( theDirectionalShadowSize, theDirectionalShadowSize, desc.Format,D3DMULTISAMPLE_NONE, 0, TRUE, &m_pDirectionalDSShadow, NULL ); m_SpotDepths.Create(theSpotShadowSize, theSpotShadowSize); Renderer::theDevicePtr->CreateDepthStencilSurface( theSpotShadowSize, theSpotShadowSize, desc.Format,D3DMULTISAMPLE_NONE, 0, TRUE, &m_pSpotDSShadow, NULL ); Renderer::theDevicePtr->CreateDepthStencilSurface(desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pDSGBuffers, NULL ); }
void CCoherentViewListener::DrawFrameDX9SharedTexture( Coherent::UI::CoherentHandle handle, int width, int height ) { if ( gCoherentUISystem == NULL ) { return; } void* pNativeTexture = gCoherentUISystem->GetNativeTextureFromSharedHandle( handle ); if ( pNativeTexture == NULL ) { return; } IDirect3DTexture9* pD3DSrcTex = static_cast<IDirect3DTexture9*>( pNativeTexture ); IDirect3DSurface9* pSurfaceSource; pD3DSrcTex->GetSurfaceLevel( 0, &pSurfaceSource ); IDirect3DSurface9* pSurfaceDest; IDirect3DTexture9* pD3DDestTex = static_cast<IDirect3DTexture9*>( m_pTexture ); pD3DDestTex->GetSurfaceLevel( 0, &pSurfaceDest ); static_cast<IDirect3DDevice9*>( gD3DDevice )->StretchRect( pSurfaceSource, nullptr, pSurfaceDest, nullptr, D3DTEXF_NONE ); pSurfaceSource->Release(); pSurfaceDest->Release(); }
bool D3DFB::Wiper_Crossfade::Run(int ticks, D3DFB *fb) { Clock += ticks; // Put the initial screen back to the buffer, presumably with DMA. IDirect3DSurface9 *source = NULL, *target = NULL; if (SUCCEEDED(fb->InitialWipeScreen->GetSurfaceLevel(0, &source)) && SUCCEEDED(fb->D3DDevice->GetRenderTarget(0, &target))) { fb->D3DDevice->UpdateSurface(source, NULL, target, NULL); target->Release(); } if (source != NULL) { source->Release(); } // Draw the new screen on top of it. FBVERTEX verts[4]; fb->CalcFullscreenCoords(verts, false, false, D3DCOLOR_COLORVALUE(0,0,0,Clock / 32.f), D3DCOLOR_RGBA(255,255,255,0)); fb->D3DDevice->SetFVF(D3DFVF_FBVERTEX); fb->SetTexture(0, fb->FinalWipeScreen); fb->SetAlphaBlend(D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); fb->SetPixelShader(fb->PlainShader); fb->D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, verts, sizeof(FBVERTEX)); return Clock >= 32; }
HRESULT CSurfaceQueueDeviceD3D9::LockSurface(IUnknown* pSurface, DWORD flags) { ASSERT(pSurface); HRESULT hr = S_OK; IDirect3DSurface9* pSurf = NULL; DWORD d3d9flags = D3DLOCK_READONLY; D3DLOCKED_RECT region; if (flags & SURFACE_QUEUE_FLAG_DO_NOT_WAIT) { d3d9flags |= D3DLOCK_DONOTWAIT; } if (FAILED(hr = pSurface->QueryInterface(__uuidof(IDirect3DSurface9), (void**)&pSurf))) { goto end; } hr = pSurf->LockRect(®ion, NULL, d3d9flags); end: if (pSurf) { pSurf->Release(); } if (hr == D3DERR_WASSTILLDRAWING) { hr = DXGI_ERROR_WAS_STILL_DRAWING; } return hr; }
HRESULT Dump2Surface (void* pDst[3], void* pSurface, int iWidth, int iHeight, int iStride[2]) { HRESULT hResult = E_FAIL; if (!pDst[0] || !pDst[1] || !pDst[2] || !pSurface) return hResult; IDirect3DSurface9* pSurfaceData = (IDirect3DSurface9*)pSurface; D3DLOCKED_RECT sD3DLockedRect = {0}; hResult = pSurfaceData->LockRect (&sD3DLockedRect, NULL, 0); unsigned char* pInY = (unsigned char*)pDst[0]; unsigned char* pOutY = (unsigned char*)sD3DLockedRect.pBits; int iOutStride = sD3DLockedRect.Pitch; for (int j = 0; j < iHeight; j++) memcpy (pOutY + j * iOutStride, pInY + j * iStride[0], iWidth); //confirmed_safe_unsafe_usage unsigned char* pInU = (unsigned char*)pDst[1]; unsigned char* pInV = (unsigned char*)pDst[2]; unsigned char* pOutC = pOutY + iOutStride * iHeight; for (int i = 0; i < iHeight / 2; i++) { for (int j = 0; j < iWidth; j += 2) { pOutC[i * iOutStride + j ] = pInU[i * iStride[1] + j / 2]; pOutC[i * iOutStride + j + 1] = pInV[i * iStride[1] + j / 2]; } } pSurfaceData->UnlockRect(); return hResult; }
static image::Image * getRenderTargetImage(IDirect3DDevice9 *pDevice, IDirect3DSurface9 *pRenderTarget) { image::Image *image = NULL; D3DSURFACE_DESC Desc; IDirect3DSurface9 *pStagingSurface = NULL; HRESULT hr; if (!pRenderTarget) { return NULL; } hr = pRenderTarget->GetDesc(&Desc); assert(SUCCEEDED(hr)); hr = pDevice->CreateOffscreenPlainSurface(Desc.Width, Desc.Height, Desc.Format, D3DPOOL_SYSTEMMEM, &pStagingSurface, NULL); if (FAILED(hr)) { goto no_staging; } hr = pDevice->GetRenderTargetData(pRenderTarget, pStagingSurface); if (FAILED(hr)) { goto no_rendertargetdata; } image = getSurfaceImage(pDevice, pStagingSurface); no_rendertargetdata: pStagingSurface->Release(); no_staging: return image; }
void DirectX9Texture::setGrid(Grid<Color>* a_pGrid) { HRESULT hr=S_OK; Grid<Color>* pGrid=NULL; D3DSURFACE_DESC desc; m_pTexture->GetLevelDesc(0, &desc); //TODO: get texture format from color if(D3DFMT_A32B32G32R32F==desc.Format) { IDirect3DSurface9* offscreenSurface; hr = m_pRenderer->getDevice()->CreateOffscreenPlainSurface( desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &offscreenSurface, NULL ); if( FAILED(hr) ) return; IDirect3DSurface9* destinationSurface; m_pTexture->GetSurfaceLevel(0, &destinationSurface); m_iWidth=desc.Width; m_iHeight=desc.Height; D3DLOCKED_RECT lockedRect; HRESULT hr=S_OK; if(!FAILED(offscreenSurface->LockRect(&lockedRect, NULL, D3DLOCK_DISCARD))) { for(unsigned int y=0; y<m_iHeight; y++) { void* dst=((char*)lockedRect.pBits)+(y*lockedRect.Pitch); memcpy(dst, a_pGrid->getRawRowData(y), a_pGrid->getRawRowDataByteCount()); } offscreenSurface->UnlockRect(); } m_pRenderer->getDevice()->UpdateSurface(offscreenSurface, NULL, destinationSurface, NULL); offscreenSurface->Release(); } }
CDX9TextureManager::CDX9TextureManager( ) : m_pDefaultRT( NULL ) , m_pDefaultDT( NULL ) , m_pNULLTexture( NULL ) { // Create the default render target IDirect3DSurface9* pDefaultRT = NULL; CDX9Renderer::GetDevice( )->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pDefaultRT ); D3DSURFACE_DESC RTDesc; pDefaultRT->GetDesc( &RTDesc ); m_pDefaultRT = new CDX9Texture( pDefaultRT, CDX9Renderer::GetDevice( ) ); // Create the default depth target IDirect3DSurface9* pDefaultDT = NULL; CDX9Renderer::GetDevice( )->GetDepthStencilSurface( &pDefaultDT ); D3DSURFACE_DESC Desc; pDefaultDT->GetDesc( &Desc ); m_pDefaultDT = new CDX9Texture( pDefaultDT, CDX9Renderer::GetDevice( ), true ); // Create the null texture IDirect3DTexture9* p = NULL; m_pNULLTexture = new CDX9Texture( p, CDX9Renderer::GetDevice( ) ); }
D3D9ProxySwapChain::D3D9ProxySwapChain(IDirect3DSwapChain9* pActualSwapChain, D3DProxyDevice* pWrappedOwningDevice, bool isAdditionalChain) : BaseDirect3DSwapChain9(pActualSwapChain, pWrappedOwningDevice, isAdditionalChain), m_backBuffers() { // Get creation parameters for backbuffers. D3DPRESENT_PARAMETERS params; pActualSwapChain->GetPresentParameters(¶ms); UINT bbCount = params.BackBufferCount; if (bbCount == 0) bbCount = 1; m_backBuffers.reserve(bbCount); IDirect3DSurface9* pTempActualBackBuffer; pActualSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pTempActualBackBuffer); D3DSURFACE_DESC backDesc; pTempActualBackBuffer->GetDesc(&backDesc); pTempActualBackBuffer->Release(); pTempActualBackBuffer = NULL; // Create stereo backbuffers to use in place of actual backbuffers for (UINT i = 0; i < bbCount; i++) { IDirect3DSurface9* pTemp; pWrappedOwningDevice->CreateRenderTarget(backDesc.Width, backDesc.Height, backDesc.Format, backDesc.MultiSampleType, backDesc.MultiSampleQuality, false, &pTemp, NULL, true); m_backBuffers.push_back(static_cast<D3D9ProxySurface*>(pTemp)); } }
void RSManagerDX9::registerD3DXCreateTextureFromFileInMemory(LPCVOID pSrcData, UINT SrcDataSize, LPDIRECT3DTEXTURE9 pTexture) { SDLOG(1, "RenderstateManager: registerD3DXCreateTextureFromFileInMemory %p | %p (size %d)\n", pTexture, pSrcData, SrcDataSize); if(Settings::get().getEnableTextureDumping()) { UINT32 hash = SuperFastHash((char*)const_cast<void*>(pSrcData), SrcDataSize); SDLOG(1, " - size: %8u, hash: %8x\n", SrcDataSize, hash); IDirect3DSurface9* surf = NULL; ((IDirect3DTexture9*)pTexture)->GetSurfaceLevel(0, &surf); if(surf != NULL) { string directory = getInstalledFileName(format("textures\\%s\\dump\\", getExeFileName().c_str())); SDLOG(1, "%s\n", boost::filesystem::path(directory).string().c_str()) try { boost::filesystem::create_directories(boost::filesystem::path(directory)); string fn = format("%s%08x.tga", directory.c_str(), hash); SDLOG(1, " - dumping texture to %s\n", fn); if(SUCCEEDED(D3DXSaveSurfaceToFile(fn.c_str(), D3DXIFF_TGA, surf, NULL, NULL))) { SDLOG(1, " - texture dumped\n"); } else { SDLOG(-1, "ERROR while texture dumping (D3DX)\n"); } } catch(boost::filesystem::filesystem_error e) { SDLOG(-1, "ERROR - Filesystem error while trying to create directory:\n%s\n", e.what()); } surf->Release(); }
HRESULT DS2Plugin::redirectSetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) { // At this point, we can grab the z (RT1) and normal (RT0) RTs if(RenderTargetIndex == 1 && pRenderTarget == NULL && zBufferSurf == NULL) { SAFERELEASE(zBufferSurf); SAFERELEASE(normalSurf); d3ddev->GetRenderTarget(1, &zBufferSurf); d3ddev->GetRenderTarget(0, &normalSurf); } // If previous RT was D3DFMT_A16B16G16R16F, store RT else if(((doAO && ssao) || (doBloom && bloom)) && !aoDone && !hdrRT && RenderTargetIndex == 0 && zBufferSurf != NULL && defaultState != NULL) { IDirect3DSurface9* prevRT = NULL; d3ddev->GetRenderTarget(0, &prevRT); if(prevRT) { D3DSURFACE_DESC desc; prevRT->GetDesc(&desc); if(desc.Format == D3DFMT_A16B16G16R16F && (desc.Width == manager.getRenderWidth() || desc.Height == manager.getRenderHeight()) && !aoDone) { // store RT for later use hdrRT = prevRT; } else { SAFERELEASE(prevRT); } } } return GamePlugin::redirectSetRenderTarget(RenderTargetIndex, pRenderTarget); }
/** * * IFT = Into Final Texture. * The Radial Menu image is assembled by drawing into the Render Target. * But to render that image in-game, it must be copied to a texture. * This function copies the Render Target's surface to the Final Texture's surface. * * @author Jade Abbott * @return Void. * */ void CRadialMenu::CopyTargetSurfaceIFT() { assert(m_pRenderer); assert(m_iFinalTextureID != Utility::INVALID_ID); assert(m_uiRenderTargetID != Utility::INVALID_ID); // Get the render target's surface (which contains the assembled Radial Menu image). IDirect3DSurface9* pRenderTarget = m_pRenderer->GetSurfaceManager().GetSurface(m_uiRenderTargetID); assert(pRenderTarget); // Get the final texture. IDirect3DTexture9* pTexture = m_pRenderer->GetTextureManager().GetTexture(m_iFinalTextureID); assert(pTexture); // Get the surface from the texture, and copy the render target's surface into it. IDirect3DSurface9* pTextureSurface = 0; if (SUCCEEDED(pTexture->GetSurfaceLevel(0, &pTextureSurface))) { assert(pTextureSurface); D3DXLoadSurfaceFromSurface(pTextureSurface, 0, 0, pRenderTarget, 0, 0, D3DX_FILTER_NONE, 0); pTextureSurface->Release(); pTextureSurface = 0; } }
void D3DXCompressorDXT1::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alphaMode, uint w, uint h, uint d, void * data, const nvtt::CompressionOptions::Private & compressionOptions, const nvtt::OutputOptions::Private & outputOptions) { nvDebugCheck(d == 1); IDirect3D9 * d3d = Direct3DCreate9(D3D_SDK_VERSION); D3DPRESENT_PARAMETERS presentParams; ZeroMemory(&presentParams, sizeof(presentParams)); presentParams.Windowed = TRUE; presentParams.SwapEffect = D3DSWAPEFFECT_COPY; presentParams.BackBufferWidth = 8; presentParams.BackBufferHeight = 8; presentParams.BackBufferFormat = D3DFMT_UNKNOWN; HRESULT err; IDirect3DDevice9 * device = NULL; err = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, GetDesktopWindow(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParams, &device); IDirect3DTexture9 * texture = NULL; err = D3DXCreateTexture(device, w, h, 1, 0, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &texture); IDirect3DSurface9 * surface = NULL; err = texture->GetSurfaceLevel(0, &surface); RECT rect; rect.left = 0; rect.top = 0; rect.bottom = h; rect.right = w; if (inputFormat == nvtt::InputFormat_BGRA_8UB) { err = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, data, D3DFMT_A8R8G8B8, w * 4, NULL, &rect, D3DX_DEFAULT, 0); } else { err = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, data, D3DFMT_A32B32G32R32F, w * 16, NULL, &rect, D3DX_DEFAULT, 0); } if (err != D3DERR_INVALIDCALL && err != D3DXERR_INVALIDDATA) { D3DLOCKED_RECT rect; ZeroMemory(&rect, sizeof(rect)); err = surface->LockRect(&rect, NULL, D3DLOCK_READONLY); if (outputOptions.outputHandler != NULL) { int size = rect.Pitch * ((h + 3) / 4); outputOptions.outputHandler->writeData(rect.pBits, size); } err = surface->UnlockRect(); } surface->Release(); device->Release(); d3d->Release(); }
bool D3DFB::WipeStartScreen(int type) { IDirect3DSurface9 *tsurf; D3DSURFACE_DESC desc; if (!Accel2D) { return Super::WipeStartScreen(type); } switch (type) { case wipe_Melt: ScreenWipe = new Wiper_Melt; break; case wipe_Burn: ScreenWipe = new Wiper_Burn(this); break; case wipe_Fade: ScreenWipe = new Wiper_Crossfade; break; default: return false; } InitialWipeScreen = GetCurrentScreen(); // Create another texture to copy the final wipe screen to so // we can still gamma correct the wipe. Since this is just for // gamma correction, it's okay to fail (though not desirable.) if (PixelDoubling || (GammaFixerShader != NULL && Windowed)) { if (SUCCEEDED(TempRenderTexture->GetSurfaceLevel(0, &tsurf))) { if (FAILED(tsurf->GetDesc(&desc)) || FAILED(D3DDevice->CreateTexture(desc.Width, desc.Height, 1, D3DUSAGE_RENDERTARGET, desc.Format, D3DPOOL_DEFAULT, &FinalWipeScreen, NULL))) { FinalWipeScreen = TempRenderTexture; } tsurf->Release(); } } else { FinalWipeScreen = TempRenderTexture; } // Make even fullscreen model render to the TempRenderTexture, so // we can have a copy of the new screen readily available. GatheringWipeScreen = true; return true; }
void RenderTarget::useColorAsTexture(TextureUnit unit) { if (antialiasing) { IDirect3DSurface9* surface; colorTexture->GetSurfaceLevel(0, &surface); affirm(device->StretchRect(colorSurface, nullptr, surface, nullptr, D3DTEXF_NONE)); surface->Release(); } device->SetTexture(unit.unit, colorTexture); }
bool CDVDCodecUtils::CopyDXVA2Picture(YV12Image* pImage, DVDVideoPicture *pSrc) { #ifdef HAS_DX // TODO: Optimize this later using shaders/swscale/etc. switch (pSrc->extended_format) { case MAKEFOURCC('N','V','1','2'): { IDirect3DSurface9* surface = (IDirect3DSurface9*)pSrc->data[3]; D3DLOCKED_RECT rectangle; if (FAILED(surface->LockRect(&rectangle, NULL, 0))) return false; // Copy Y uint8_t* bits = (uint8_t*)(rectangle.pBits); uint8_t* d = pImage->plane[0]; for (unsigned y = 0; y < pSrc->iHeight; y++) { memcpy(d, bits, pSrc->iWidth); bits += rectangle.Pitch; d += pImage->stride[0]; } D3DSURFACE_DESC desc; if (FAILED(surface->GetDesc(&desc))) return false; // Copy packed UV uint8_t *s_uv = ((uint8_t*)(rectangle.pBits)) + desc.Height * rectangle.Pitch; uint8_t *d_uv = pImage->plane[1]; for (unsigned y = 0; y < pSrc->iHeight >> 1; y++) { memcpy(d_uv, s_uv, pSrc->iWidth); s_uv += rectangle.Pitch; d_uv += pImage->stride[1]; } if (FAILED(surface->UnlockRect())) return false; } return true; // Future... /*case MAKEFOURCC('Y','V','1','2'): return true;*/ /*case MAKEFOURCC('Y','V','V','Y'): return true;*/ default: CLog::Log(LOGWARNING, "CDVDCodecUtils::CopyDXVA2Picture colorspace not supported"); return false; } #endif return false; }
void Graphics4::RenderTarget::useDepthAsTexture(TextureUnit unit) { if (antialiasing) { IDirect3DSurface9* surface; depthTexture->GetSurfaceLevel(0, &surface); Microsoft::affirm(device->StretchRect(depthSurface, nullptr, surface, nullptr, D3DTEXF_NONE)); surface->Release(); } device->SetTexture(unit.unit, depthTexture); }
HRESULT virtual Update() { if (S_OK == this->ULib_BaseCanvas::Update() /*此处做静态绑定 etc.*/) { switch (m_typWrkMod) { case DataOutput: { //TODO. //See ULib_OpenGLCanvas.hpp. return S_OK; } case DataInput: { LPDIRECT3DDEVICE9 pDx9Device = GutGetGraphicsDeviceDX9(); if (pDx9Device) { //创建一个渲染表面 IDirect3DSurface9* pSurface; //此处参数与OpenGL不同, 由于Pixle对象为一个DWORD,而非BYTE,故宏定义使用ARGB表达,底层字节序按照小端存放为B,G,R,A, 依然与OpenGL相同(Win32平台下) pDx9Device->CreateOffscreenPlainSurface(m_canvasWidth, m_canvasHeight, (D3DFORMAT)m_dataFormat, D3DPOOL_DEFAULT, &pSurface,0); //上写锁 D3DLOCKED_RECT rc; memset(&rc,0,sizeof(rc)); pSurface->LockRect(&rc,NULL,D3DLOCK_DISCARD); DWORD* pBits = (DWORD*)rc.pBits; memcpy(pBits, m_pTargetTexturePixels, m_canvasWidth * m_canvasHeight * sizeof(DWORD)); //释放写锁 pSurface->UnlockRect(); //获取D3D默认交换链中的后台缓存 IDirect3DSurface9 *backBuffer = 0; pDx9Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer); //使用自定义渲染表面填充后台缓存 pDx9Device->StretchRect(pSurface, 0, backBuffer, 0, D3DTEXF_NONE); //GetBackBuffer所得的缓存需要被释放 backBuffer->Release(); pDx9Device->Present(NULL, NULL, NULL, NULL); return S_OK; }else { return E_FAIL; } } default: { return E_FAIL; } } }else { return E_FAIL; } }