mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
Fixes the backend logic for setting/creating 3DTextures in D3D11
This commit is contained in:
parent
2b686bf713
commit
45d304ee31
|
|
@ -133,6 +133,11 @@ void GFXD3D11TextureManager::_innerCreateTexture( GFXD3D11TextureObject *retTex,
|
|||
AssertFatal(false, "GFXD3D11TextureManager::_createTexture - failed to create volume texture!");
|
||||
}
|
||||
|
||||
if (!retTex->mProfile->isSystemMemory())
|
||||
{
|
||||
createResourceView(height, width, depth, d3dTextureFormat, numMipLevels, bindFlags, retTex);
|
||||
}
|
||||
|
||||
retTex->mTextureSize.set(width, height, depth);
|
||||
retTex->get3DTex()->GetDesc(&desc);
|
||||
retTex->mMipLevels = numMipLevels;
|
||||
|
|
@ -588,4 +593,4 @@ void GFXD3D11TextureManager::createResourceView(U32 height, U32 width, U32 depth
|
|||
hr = D3D11DEVICE->CreateDepthStencilView(resource,&desc, tex->getDSViewPtr());
|
||||
AssertFatal(SUCCEEDED(hr), "CreateDepthStencilView:: failed to create view!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,9 +70,17 @@ GFXLockedRect *GFXD3D11TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect /
|
|||
|
||||
if( !mStagingTex ||
|
||||
mStagingTex->getWidth() != getWidth() ||
|
||||
mStagingTex->getHeight() != getHeight() )
|
||||
mStagingTex->getHeight() != getHeight() ||
|
||||
mStagingTex->getDepth() != getDepth())
|
||||
{
|
||||
mStagingTex.set( getWidth(), getHeight(), mFormat, &GFXSystemMemTextureProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__) );
|
||||
if (getDepth() != 0)
|
||||
{
|
||||
mStagingTex.set(getWidth(), getHeight(), getDepth(), mFormat, &GFXSystemMemTextureProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
mStagingTex.set(getWidth(), getHeight(), mFormat, &GFXSystemMemTextureProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__));
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11DeviceContext* pContext = D3D11DEVICECONTEXT;
|
||||
|
|
@ -82,13 +90,20 @@ GFXLockedRect *GFXD3D11TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect /
|
|||
GFXD3D11TextureObject* pD3DStagingTex = (GFXD3D11TextureObject*)&(*mStagingTex);
|
||||
|
||||
//map staging texture
|
||||
HRESULT hr = pContext->Map(pD3DStagingTex->get2DTex(), mLockedSubresource, D3D11_MAP_READ, 0, &mapInfo);
|
||||
HRESULT hr;
|
||||
|
||||
bool is3D = mStagingTex->getDepth() != 0;
|
||||
if (is3D) //3d texture
|
||||
hr = pContext->Map(pD3DStagingTex->get3DTex(), mLockedSubresource, D3D11_MAP_READ, 0, &mapInfo);
|
||||
else
|
||||
hr = pContext->Map(pD3DStagingTex->get2DTex(), mLockedSubresource, D3D11_MAP_READ, 0, &mapInfo);
|
||||
|
||||
if (FAILED(hr))
|
||||
AssertFatal(false, "GFXD3D11TextureObject:lock - failed to map render target resource!");
|
||||
|
||||
const U32 width = mTextureSize.x >> mipLevel;
|
||||
const U32 height = mTextureSize.y >> mipLevel;
|
||||
const U32 depth = is3D ? mTextureSize.z >> mipLevel : 1;
|
||||
|
||||
//calculate locked box region and offset
|
||||
if (inRect)
|
||||
|
|
@ -100,7 +115,7 @@ GFXLockedRect *GFXD3D11TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect /
|
|||
mLockBox.left = inRect->point.x;
|
||||
mLockBox.bottom = inRect->point.y + inRect->extent.y;
|
||||
mLockBox.right = inRect->point.x + inRect->extent.x;
|
||||
mLockBox.back = 1;
|
||||
mLockBox.back = depth;
|
||||
mLockBox.front = 0;
|
||||
|
||||
//calculate offset
|
||||
|
|
@ -112,7 +127,7 @@ GFXLockedRect *GFXD3D11TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect /
|
|||
mLockBox.left = 0;
|
||||
mLockBox.bottom = height;
|
||||
mLockBox.right = width;
|
||||
mLockBox.back = 1;
|
||||
mLockBox.back = depth;
|
||||
mLockBox.front = 0;
|
||||
}
|
||||
|
||||
|
|
@ -132,12 +147,27 @@ void GFXD3D11TextureObject::unlock(U32 mipLevel)
|
|||
|
||||
ID3D11DeviceContext* pContext = D3D11DEVICECONTEXT;
|
||||
GFXD3D11TextureObject* pD3DStagingTex = (GFXD3D11TextureObject*)&(*mStagingTex);
|
||||
ID3D11Texture2D *pStagingTex = pD3DStagingTex->get2DTex();
|
||||
|
||||
//unmap staging texture
|
||||
pContext->Unmap(pStagingTex, mLockedSubresource);
|
||||
//copy lock box region from the staging texture to our regular texture
|
||||
pContext->CopySubresourceRegion(mD3DTexture, mLockedSubresource, mLockBox.left, mLockBox.top, 0, pStagingTex, mLockedSubresource, &mLockBox);
|
||||
bool is3D = mStagingTex->getDepth() != 0;
|
||||
|
||||
if (is3D)
|
||||
{
|
||||
ID3D11Texture3D* pStagingTex = pD3DStagingTex->get3DTex();
|
||||
|
||||
//unmap staging texture
|
||||
pContext->Unmap(pStagingTex, mLockedSubresource);
|
||||
//copy lock box region from the staging texture to our regular texture
|
||||
pContext->CopySubresourceRegion(mD3DTexture, mLockedSubresource, mLockBox.left, mLockBox.top, mLockBox.front, pStagingTex, mLockedSubresource, &mLockBox);
|
||||
}
|
||||
else
|
||||
{
|
||||
ID3D11Texture2D* pStagingTex = pD3DStagingTex->get2DTex();
|
||||
|
||||
//unmap staging texture
|
||||
pContext->Unmap(pStagingTex, mLockedSubresource);
|
||||
//copy lock box region from the staging texture to our regular texture
|
||||
pContext->CopySubresourceRegion(mD3DTexture, mLockedSubresource, mLockBox.left, mLockBox.top, 0, pStagingTex, mLockedSubresource, &mLockBox);
|
||||
}
|
||||
|
||||
PROFILE_END();
|
||||
|
||||
|
|
|
|||
|
|
@ -161,14 +161,14 @@ bool GFXTexHandle::set( U32 width, U32 height, GFXFormat format, GFXTextureProfi
|
|||
return isValid();
|
||||
}
|
||||
|
||||
bool GFXTexHandle::set( U32 width, U32 height, U32 depth, void *pixels, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels )
|
||||
bool GFXTexHandle::set(U32 width, U32 height, U32 depth, GFXFormat format, GFXTextureProfile* profile, const String& desc, U32 numMipLevels)
|
||||
{
|
||||
// Clear the existing texture first, so that
|
||||
// its memory is free for the new allocation.
|
||||
free();
|
||||
|
||||
// Create and set the new texture.
|
||||
StrongObjectRef::set( TEXMGR->createTexture( width, height, depth, pixels, format, profile,numMipLevels ) );
|
||||
StrongObjectRef::set(TEXMGR->createTexture(width, height, depth, format, profile, numMipLevels));
|
||||
|
||||
#ifdef TORQUE_DEBUG
|
||||
if ( getPointer() )
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public:
|
|||
// Sized bitmap
|
||||
GFXTexHandle( U32 width, U32 height, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels = 1, S32 antialiasLevel = 0);
|
||||
bool set( U32 width, U32 height, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels = 1, S32 antialiasLevel = 0);
|
||||
bool set( U32 width, U32 height, U32 depth, void *pixels, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels = 1 );
|
||||
bool set( U32 width, U32 height, U32 depth, GFXFormat format, GFXTextureProfile* profile, const String& desc, U32 numMipLevels = 1);
|
||||
|
||||
/// Returns the width and height as a point.
|
||||
Point2I getWidthHeight() const { return getPointer() ? Point2I( getPointer()->getWidth(), getPointer()->getHeight() ) : Point2I::Zero; }
|
||||
|
|
|
|||
|
|
@ -815,7 +815,6 @@ GFXTextureObject *GFXTextureManager::createTexture( U32 width, U32 height, GFXFo
|
|||
GFXTextureObject *GFXTextureManager::createTexture( U32 width,
|
||||
U32 height,
|
||||
U32 depth,
|
||||
void *pixels,
|
||||
GFXFormat format,
|
||||
GFXTextureProfile *profile,
|
||||
U32 numMipLevels)
|
||||
|
|
@ -831,14 +830,6 @@ GFXTextureObject *GFXTextureManager::createTexture( U32 width,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// Call the internal load...
|
||||
if( !_loadTexture( ret, pixels ) )
|
||||
{
|
||||
Con::errorf("GFXTextureManager - failed to load volume texture" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// And do book-keeping...
|
||||
// - texture info
|
||||
ret->mBitmapSize.set( width, height, depth );
|
||||
|
|
|
|||
|
|
@ -119,7 +119,6 @@ public:
|
|||
virtual GFXTextureObject *createTexture( U32 width,
|
||||
U32 height,
|
||||
U32 depth,
|
||||
void *pixels,
|
||||
GFXFormat format,
|
||||
GFXTextureProfile *profile,
|
||||
U32 numMipLevels = 1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue