|
|
@@ -79,6 +79,9 @@ void Texture2D::Release()
|
|
|
renderSurface_->Release();
|
|
|
|
|
|
URHO3D_SAFE_RELEASE(object_.ptr_);
|
|
|
+
|
|
|
+ resolveDirty_ = false;
|
|
|
+ levelsDirty_ = false;
|
|
|
}
|
|
|
|
|
|
bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, const void* data)
|
|
|
@@ -351,6 +354,9 @@ bool Texture2D::GetData(unsigned level, void* dest) const
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if (resolveDirty_)
|
|
|
+ graphics_->ResolveToTexture(const_cast<Texture2D*>(this));
|
|
|
+
|
|
|
int levelWidth = GetLevelWidth(level);
|
|
|
int levelHeight = GetLevelHeight(level);
|
|
|
|
|
|
@@ -371,22 +377,43 @@ bool Texture2D::GetData(unsigned level, void* dest) const
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ // If multisampled, must copy the surface of the resolve texture instead of the multisampled surface
|
|
|
+ IDirect3DSurface9* resolveSurface = 0;
|
|
|
+ if (multiSample_ > 1)
|
|
|
+ {
|
|
|
+ HRESULT hr = ((IDirect3DTexture9*)object_.ptr_)->GetSurfaceLevel(0, (IDirect3DSurface9**)&resolveSurface);
|
|
|
+ if (FAILED(hr))
|
|
|
+ {
|
|
|
+ URHO3D_LOGD3DERROR("Could not get surface of the resolve texture", hr);
|
|
|
+ URHO3D_SAFE_RELEASE(resolveSurface);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
|
|
|
HRESULT hr = device->CreateOffscreenPlainSurface((UINT)width_, (UINT)height_, (D3DFORMAT)format_,
|
|
|
D3DPOOL_SYSTEMMEM, &offscreenSurface, 0);
|
|
|
if (FAILED(hr))
|
|
|
{
|
|
|
URHO3D_LOGD3DERROR("Could not create surface for getting rendertarget data", hr);
|
|
|
- URHO3D_SAFE_RELEASE(offscreenSurface);
|
|
|
+ URHO3D_SAFE_RELEASE(offscreenSurface)
|
|
|
+ URHO3D_SAFE_RELEASE(resolveSurface);
|
|
|
return false;
|
|
|
}
|
|
|
- hr = device->GetRenderTargetData((IDirect3DSurface9*)renderSurface_->GetSurface(), offscreenSurface);
|
|
|
+
|
|
|
+ if (resolveSurface)
|
|
|
+ hr = device->GetRenderTargetData(resolveSurface, offscreenSurface);
|
|
|
+ else
|
|
|
+ hr = device->GetRenderTargetData((IDirect3DSurface9*)renderSurface_->GetSurface(), offscreenSurface);
|
|
|
+ URHO3D_SAFE_RELEASE(resolveSurface);
|
|
|
+
|
|
|
if (FAILED(hr))
|
|
|
{
|
|
|
URHO3D_LOGD3DERROR("Could not get rendertarget data", hr);
|
|
|
URHO3D_SAFE_RELEASE(offscreenSurface);
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
hr = offscreenSurface->LockRect(&d3dLockedRect, &d3dRect, D3DLOCK_READONLY);
|
|
|
if (FAILED(hr))
|
|
|
{
|
|
|
@@ -459,13 +486,11 @@ bool Texture2D::GetData(unsigned level, void* dest) const
|
|
|
}
|
|
|
|
|
|
if (offscreenSurface)
|
|
|
- {
|
|
|
offscreenSurface->UnlockRect();
|
|
|
- URHO3D_SAFE_RELEASE(offscreenSurface);
|
|
|
- }
|
|
|
else
|
|
|
((IDirect3DTexture9*)object_.ptr_)->UnlockRect(level);
|
|
|
|
|
|
+ URHO3D_SAFE_RELEASE(offscreenSurface);
|
|
|
return true;
|
|
|
}
|
|
|
|