2019-12-16 04:28:01 +01:00
|
|
|
#include "d3d9_texture.h"
|
|
|
|
|
|
|
|
#include "d3d9_util.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
// Direct3DTexture9
|
|
|
|
|
|
|
|
D3D9Texture2D::D3D9Texture2D(
|
|
|
|
D3D9DeviceEx* pDevice,
|
2020-01-17 11:54:41 +01:00
|
|
|
const D3D9_COMMON_TEXTURE_DESC* pDesc)
|
|
|
|
: D3D9Texture2DBase( pDevice, pDesc, D3DRTYPE_TEXTURE ) { }
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture2D::QueryInterface(REFIID riid, void** ppvObject) {
|
|
|
|
if (ppvObject == nullptr)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(IDirect3DResource9)
|
|
|
|
|| riid == __uuidof(IDirect3DBaseTexture9)
|
|
|
|
|| riid == __uuidof(IDirect3DTexture9)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger::warn("D3D9Texture2D::QueryInterface: Unknown interface query");
|
|
|
|
Logger::warn(str::format(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3DRESOURCETYPE STDMETHODCALLTYPE D3D9Texture2D::GetType() {
|
|
|
|
return D3DRTYPE_TEXTURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture2D::GetLevelDesc(UINT Level, D3DSURFACE_DESC *pDesc) {
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Level >= m_texture.ExposedMipLevels()))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
return GetSubresource(Level)->GetDesc(pDesc);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture2D::GetSurfaceLevel(UINT Level, IDirect3DSurface9** ppSurfaceLevel) {
|
|
|
|
InitReturnPtr(ppSurfaceLevel);
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Level >= m_texture.ExposedMipLevels()))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(ppSurfaceLevel == nullptr))
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
*ppSurfaceLevel = ref(GetSubresource(Level));
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture2D::LockRect(UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Level >= m_texture.ExposedMipLevels()))
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
return GetSubresource(Level)->LockRect(pLockedRect, pRect, Flags);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture2D::UnlockRect(UINT Level) {
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Level >= m_texture.ExposedMipLevels()))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
return GetSubresource(Level)->UnlockRect();
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture2D::AddDirtyRect(CONST RECT* pDirtyRect) {
|
2020-09-07 13:09:30 +02:00
|
|
|
if (pDirtyRect) {
|
|
|
|
D3DBOX box = { UINT(pDirtyRect->left), UINT(pDirtyRect->top), UINT(pDirtyRect->right), UINT(pDirtyRect->bottom), 0, 1 };
|
|
|
|
m_texture.AddUpdateDirtyBox(&box, 0);
|
|
|
|
} else {
|
|
|
|
m_texture.AddUpdateDirtyBox(nullptr, 0);
|
|
|
|
}
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Direct3DVolumeTexture9
|
|
|
|
|
|
|
|
|
|
|
|
D3D9Texture3D::D3D9Texture3D(
|
|
|
|
D3D9DeviceEx* pDevice,
|
2020-01-17 11:54:41 +01:00
|
|
|
const D3D9_COMMON_TEXTURE_DESC* pDesc)
|
|
|
|
: D3D9Texture3DBase( pDevice, pDesc, D3DRTYPE_VOLUMETEXTURE ) { }
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture3D::QueryInterface(REFIID riid, void** ppvObject) {
|
|
|
|
if (ppvObject == nullptr)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(IDirect3DResource9)
|
|
|
|
|| riid == __uuidof(IDirect3DBaseTexture9)
|
|
|
|
|| riid == __uuidof(IDirect3DVolumeTexture9)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger::warn("D3D9Texture3D::QueryInterface: Unknown interface query");
|
|
|
|
Logger::warn(str::format(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3DRESOURCETYPE STDMETHODCALLTYPE D3D9Texture3D::GetType() {
|
|
|
|
return D3DRTYPE_VOLUMETEXTURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture3D::GetLevelDesc(UINT Level, D3DVOLUME_DESC *pDesc) {
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Level >= m_texture.ExposedMipLevels()))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
return GetSubresource(Level)->GetDesc(pDesc);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture3D::GetVolumeLevel(UINT Level, IDirect3DVolume9** ppVolumeLevel) {
|
|
|
|
InitReturnPtr(ppVolumeLevel);
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Level >= m_texture.ExposedMipLevels()))
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
if (unlikely(ppVolumeLevel == nullptr))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
*ppVolumeLevel = ref(GetSubresource(Level));
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture3D::LockBox(UINT Level, D3DLOCKED_BOX* pLockedBox, CONST D3DBOX* pBox, DWORD Flags) {
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Level >= m_texture.ExposedMipLevels()))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
return GetSubresource(Level)->LockBox(pLockedBox, pBox, Flags);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture3D::UnlockBox(UINT Level) {
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Level >= m_texture.ExposedMipLevels()))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
return GetSubresource(Level)->UnlockBox();
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9Texture3D::AddDirtyBox(CONST D3DBOX* pDirtyBox) {
|
2020-09-07 13:09:30 +02:00
|
|
|
m_texture.AddUpdateDirtyBox(pDirtyBox, 0);
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Direct3DCubeTexture9
|
|
|
|
|
|
|
|
|
|
|
|
D3D9TextureCube::D3D9TextureCube(
|
|
|
|
D3D9DeviceEx* pDevice,
|
2020-01-17 11:54:41 +01:00
|
|
|
const D3D9_COMMON_TEXTURE_DESC* pDesc)
|
|
|
|
: D3D9TextureCubeBase( pDevice, pDesc, D3DRTYPE_CUBETEXTURE ) { }
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9TextureCube::QueryInterface(REFIID riid, void** ppvObject) {
|
|
|
|
if (ppvObject == nullptr)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(IDirect3DResource9)
|
|
|
|
|| riid == __uuidof(IDirect3DBaseTexture9)
|
|
|
|
|| riid == __uuidof(IDirect3DCubeTexture9)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger::warn("D3D9TextureCube::QueryInterface: Unknown interface query");
|
|
|
|
Logger::warn(str::format(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3DRESOURCETYPE STDMETHODCALLTYPE D3D9TextureCube::GetType() {
|
|
|
|
return D3DRTYPE_CUBETEXTURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9TextureCube::GetLevelDesc(UINT Level, D3DSURFACE_DESC *pDesc) {
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Level >= m_texture.ExposedMipLevels()))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
return GetSubresource(Level)->GetDesc(pDesc);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9TextureCube::GetCubeMapSurface(D3DCUBEMAP_FACES Face, UINT Level, IDirect3DSurface9** ppSurfaceLevel) {
|
|
|
|
InitReturnPtr(ppSurfaceLevel);
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Level >= m_texture.ExposedMipLevels() || Face >= D3DCUBEMAP_FACES(6)))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(ppSurfaceLevel == nullptr))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
*ppSurfaceLevel = ref(GetSubresource(m_texture.CalcSubresource(UINT(Face), Level)));
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9TextureCube::LockRect(D3DCUBEMAP_FACES Face, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Face > D3DCUBEMAP_FACE_NEGATIVE_Z || Level >= m_texture.ExposedMipLevels()))
|
|
|
|
return D3DERR_INVALIDCALL;
|
2019-12-16 04:28:01 +01:00
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
return GetSubresource(m_texture.CalcSubresource(UINT(Face), Level))->LockRect(pLockedRect, pRect, Flags);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9TextureCube::UnlockRect(D3DCUBEMAP_FACES Face, UINT Level) {
|
2020-05-26 14:11:24 +02:00
|
|
|
if (unlikely(Face > D3DCUBEMAP_FACE_NEGATIVE_Z || Level >= m_texture.ExposedMipLevels()))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2020-05-26 14:11:24 +02:00
|
|
|
return GetSubresource(m_texture.CalcSubresource(UINT(Face), Level))->UnlockRect();
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D9TextureCube::AddDirtyRect(D3DCUBEMAP_FACES Face, CONST RECT* pDirtyRect) {
|
2020-09-07 13:09:30 +02:00
|
|
|
if (pDirtyRect) {
|
|
|
|
D3DBOX box = { UINT(pDirtyRect->left), UINT(pDirtyRect->top), UINT(pDirtyRect->right), UINT(pDirtyRect->bottom), 0, 1 };
|
|
|
|
m_texture.AddUpdateDirtyBox(&box, Face);
|
|
|
|
} else {
|
|
|
|
m_texture.AddUpdateDirtyBox(nullptr, Face);
|
|
|
|
}
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|