void* DiD3D9TextureDrv::LockLevel(uint32 level, uint32 &pitch, uint32 surface) { void *buffer = nullptr; if (mTexture) { if (mParent->GetTextureType() == TEXTURE_2D) { DI_ASSERT(surface == 0); IDirect3DTexture9* tex2D = static_cast<IDirect3DTexture9*>(mTexture); D3DLOCKED_RECT lockedRect; HRESULT result = tex2D->LockRect((DWORD)level, &lockedRect, 0, D3DLOCK_NOSYSLOCK); DX9_CHKERR(result); if (result == D3D_OK) { buffer = lockedRect.pBits; pitch = (uint32)lockedRect.Pitch; } } else if (mParent->GetTextureType() == TEXTURE_CUBE) { DI_ASSERT(surface >= 0 && surface <= 5); IDirect3DCubeTexture9* texCUBE = static_cast<IDirect3DCubeTexture9*>(mTexture); D3DLOCKED_RECT lockedRect; HRESULT result = texCUBE->LockRect((D3DCUBEMAP_FACES)surface, (DWORD)level, &lockedRect, 0, D3DLOCK_NOSYSLOCK); DX9_CHKERR(result); if (result == D3D_OK) { buffer = lockedRect.pBits; pitch = (uint32)lockedRect.Pitch; } } } return buffer; }
void DiD3D9WindowTarget::Create(HWND hwnd) { mWndHandle = hwnd; RECT kRect; GetClientRect(hwnd, &kRect); mWidth = kRect.right - kRect.left; mHeight = kRect.bottom - kRect.top; DiD3D9Driver* d3d9Drv = static_cast<DiD3D9Driver*>(Driver); if (IsSwapChainWindow()) mSwapChain = d3d9Drv->CreateSwapChain(hwnd); else mSwapChain = d3d9Drv->GetSwapChain(0); HRESULT h = mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mSurface); DX9_CHKERR(h); mSwapChain->GetPresentParameters(&mParameters); h = DiD3D9Driver::Device->CreateDepthStencilSurface( mWidth, mHeight, mParameters.AutoDepthStencilFormat, mParameters.MultiSampleType, mParameters.MultiSampleQuality, (mParameters.Flags & D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL), &mD3D9DepthBuffer, NULL ); DX9_CHKERR(h); //DI_DEBUG("D3D9 Depth stencil buffer created: (%d,%d), ptr:%x", mWidth, mHeight, mD3D9DepthBuffer); if (mD3D9DepthBuffer) { DiDepthBuffer *depthBuf = d3d9Drv->AddManualDepthBuffer(mD3D9DepthBuffer); AttachDepthBuffer(depthBuf); } }
void DiD3D9WindowTarget::OnDeviceReset() { Driver->GetWindowSize(mWndHandle, mWidth, mHeight); DiD3D9Driver* d3d9Drv = static_cast<DiD3D9Driver*>(Driver); if (IsSwapChainWindow()) mSwapChain = d3d9Drv->CreateSwapChain(mWndHandle); else mSwapChain = d3d9Drv->GetSwapChain(0); HRESULT h = mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mSurface); DX9_CHKERR(h); mSwapChain->GetPresentParameters(&mParameters); }
void DiD3D9TextureDrv::BlitToMemory(const DiBox &srcBox, const DiPixelBox &dst) { if (mParent->GetTextureType() == TEXTURE_CUBE) { DI_WARNING("Cannot blit cube texture to memory."); return; } DI_ASSERT(mSurface); D3DLOCKED_RECT lrect; HRESULT res = mSurface->LockRect(&lrect, NULL, D3DLOCK_READONLY); DX9_CHKERR(res); DiPixelBox locked(dst.GetWidth(), dst.GetHeight(), mParent->GetFormat()); FromD3DLock(locked, lrect); DiPixelBox::BulkPixelConversion(locked, dst); mSurface->UnlockRect(); }