Merge branch 'development' into EngineAPI-Refactor

This commit is contained in:
Areloch 2018-12-09 14:48:50 -06:00 committed by GitHub
commit 6cf0c9e360
1933 changed files with 102328 additions and 70545 deletions

View file

@ -65,59 +65,56 @@ GFXLockedRect *GFXD3D11TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect /
{
AssertFatal( !mLocked, "GFXD3D11TextureObject::lock - The texture is already locked!" );
D3D11_MAPPED_SUBRESOURCE mapInfo;
if( mProfile->isRenderTarget() )
if( !mStagingTex ||
mStagingTex->getWidth() != getWidth() ||
mStagingTex->getHeight() != getHeight() )
{
//AssertFatal( 0, "GFXD3D11TextureObject::lock - Need to handle mapping render targets" );
if( !mLockTex ||
mLockTex->getWidth() != getWidth() ||
mLockTex->getHeight() != getHeight() )
{
mLockTex.set( getWidth(), getHeight(), mFormat, &GFXSystemMemTextureProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__) );
}
mStagingTex.set( getWidth(), getHeight(), mFormat, &GFXSystemMemTextureProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__) );
}
PROFILE_START(GFXD3D11TextureObject_lockRT);
ID3D11DeviceContext* pContext = D3D11DEVICECONTEXT;
D3D11_MAPPED_SUBRESOURCE mapInfo;
U32 offset = 0;
mLockedSubresource = D3D11CalcSubresource(mipLevel, 0, getMipLevels());
GFXD3D11TextureObject* pD3DStagingTex = (GFXD3D11TextureObject*)&(*mStagingTex);
GFXD3D11Device* dev = D3D11;
//map staging texture
HRESULT hr = pContext->Map(pD3DStagingTex->get2DTex(), mLockedSubresource, D3D11_MAP_READ, 0, &mapInfo);
GFXD3D11TextureObject* to = (GFXD3D11TextureObject*) &(*mLockTex);
dev->getDeviceContext()->CopyResource(to->get2DTex(), mD3DTexture);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11TextureObject:lock - failed to map render target resource!");
mLockedSubresource = D3D11CalcSubresource(0, 0, 1);
HRESULT hr = dev->getDeviceContext()->Map(to->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;
mLocked = true;
//calculate locked box region and offset
if (inRect)
{
if ((inRect->point.x + inRect->extent.x > width) || (inRect->point.y + inRect->extent.y > height))
AssertFatal(false, "GFXD3D11TextureObject::lock - Rectangle too big!");
mLockBox.top = inRect->point.y;
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.front = 0;
PROFILE_END();
//calculate offset
offset = inRect->point.x * getFormatByteSize() + inRect->point.y * mapInfo.RowPitch;
}
else
{
RECT r;
if(inRect)
{
r.top = inRect->point.y;
r.left = inRect->point.x;
r.bottom = inRect->point.y + inRect->extent.y;
r.right = inRect->point.x + inRect->extent.x;
}
mLockedSubresource = D3D11CalcSubresource(mipLevel, 0, getMipLevels());
HRESULT hr = D3D11DEVICECONTEXT->Map(mD3DTexture, mLockedSubresource, D3D11_MAP_WRITE_DISCARD, 0, &mapInfo);
if ( FAILED(hr) )
AssertFatal(false, "GFXD3D11TextureObject::lock - Failed to map subresource.");
mLocked = true;
mLockBox.top = 0;
mLockBox.left = 0;
mLockBox.bottom = height;
mLockBox.right = width;
mLockBox.back = 1;
mLockBox.front = 0;
}
mLockRect.pBits = static_cast<U8*>(mapInfo.pData);
mLocked = true;
mLockRect.pBits = static_cast<U8*>(mapInfo.pData) + offset;
mLockRect.Pitch = mapInfo.RowPitch;
return (GFXLockedRect*)&mLockRect;
@ -127,22 +124,22 @@ void GFXD3D11TextureObject::unlock(U32 mipLevel)
{
AssertFatal( mLocked, "GFXD3D11TextureObject::unlock - Attempting to unlock a surface that has not been locked" );
if( mProfile->isRenderTarget() )
{
//AssertFatal( 0, "GFXD3D11TextureObject::unlock - Need to handle mapping render targets" );
GFXD3D11TextureObject* to = (GFXD3D11TextureObject*)&(*mLockTex);
D3D11->getDeviceContext()->Unmap(to->get2DTex(), mLockedSubresource);
mLockedSubresource = 0;
mLocked = false;
}
else
{
D3D11DEVICECONTEXT->Unmap(get2DTex(), mLockedSubresource);
mLockedSubresource = 0;
mLocked = false;
}
//profile in the unlock function because all the heavy lifting is done here
PROFILE_START(GFXD3D11TextureObject_lockRT);
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);
PROFILE_END();
mLockedSubresource = 0;
mLocked = false;
}
void GFXD3D11TextureObject::release()
@ -186,10 +183,10 @@ bool GFXD3D11TextureObject::copyToBmp(GBitmap* bmp)
PROFILE_START(GFXD3D11TextureObject_copyToBmp);
AssertFatal(bmp->getWidth() == getWidth(), "doh");
AssertFatal(bmp->getHeight() == getHeight(), "doh");
U32 width = getWidth();
U32 height = getHeight();
AssertFatal(bmp->getWidth() == getWidth(), "GFXD3D11TextureObject::copyToBmp - source/dest width does not match");
AssertFatal(bmp->getHeight() == getHeight(), "GFXD3D11TextureObject::copyToBmp - source/dest height does not match");
const U32 width = getWidth();
const U32 height = getHeight();
bmp->setHasTransparency(mHasTransparency);
@ -204,21 +201,45 @@ bool GFXD3D11TextureObject::copyToBmp(GBitmap* bmp)
destBytesPerPixel = 3;
else
// unsupported
AssertFatal(false, "unsupported bitmap format");
AssertFatal(false, "GFXD3D11TextureObject::copyToBmp - unsupported bitmap format");
//create temp staging texture
D3D11_TEXTURE2D_DESC desc;
static_cast<ID3D11Texture2D*>(mD3DTexture)->GetDesc(&desc);
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
desc.Usage = D3D11_USAGE_STAGING;
ID3D11Texture2D* pStagingTexture = NULL;
HRESULT hr = D3D11DEVICE->CreateTexture2D(&desc, NULL, &pStagingTexture);
if (FAILED(hr))
{
Con::errorf("GFXD3D11TextureObject::copyToBmp - Failed to create staging texture");
return false;
}
// lock the texture
DXGI_MAPPED_RECT* lockRect = (DXGI_MAPPED_RECT*) lock();
//copy the classes texture to the staging texture
D3D11DEVICECONTEXT->CopyResource(pStagingTexture, mD3DTexture);
//map the staging resource
D3D11_MAPPED_SUBRESOURCE mappedRes;
hr = D3D11DEVICECONTEXT->Map(pStagingTexture, 0, D3D11_MAP_READ, 0, &mappedRes);
if (FAILED(hr))
{
//cleanup
SAFE_RELEASE(pStagingTexture);
Con::errorf("GFXD3D11TextureObject::copyToBmp - Failed to map staging texture");
return false;
}
// set pointers
U8* srcPtr = (U8*)lockRect->pBits;
const U8* srcPtr = (U8*)mappedRes.pData;
U8* destPtr = bmp->getWritableBits();
// we will want to skip over any D3D cache data in the source texture
const S32 sourceCacheSize = lockRect->Pitch - width * sourceBytesPerPixel;
AssertFatal(sourceCacheSize >= 0, "copyToBmp: cache size is less than zero?");
const S32 sourceCacheSize = mappedRes.RowPitch - width * sourceBytesPerPixel;
AssertFatal(sourceCacheSize >= 0, "GFXD3D11TextureObject::copyToBmp - cache size is less than zero?");
PROFILE_START(GFXD3D11TextureObject_copyToBmp_pixCopy);
// copy data into bitmap
for (U32 row = 0; row < height; ++row)
{
@ -239,15 +260,14 @@ bool GFXD3D11TextureObject::copyToBmp(GBitmap* bmp)
// skip past the cache data for this row (if any)
srcPtr += sourceCacheSize;
}
PROFILE_END();
// assert if we stomped or underran memory
AssertFatal(U32(destPtr - bmp->getWritableBits()) == width * height * destBytesPerPixel, "copyToBmp: doh, memory error");
AssertFatal(U32(srcPtr - (U8*)lockRect->pBits) == height * lockRect->Pitch, "copyToBmp: doh, memory error");
AssertFatal(U32(destPtr - bmp->getWritableBits()) == width * height * destBytesPerPixel, "GFXD3D11TextureObject::copyToBmp - memory error");
AssertFatal(U32(srcPtr - (U8*)mappedRes.pData) == height * mappedRes.RowPitch, "GFXD3D11TextureObject::copyToBmp - memory error");
// unlock
unlock();
D3D11DEVICECONTEXT->Unmap(pStagingTexture, 0);
SAFE_RELEASE(pStagingTexture);
PROFILE_END();
return true;

View file

@ -31,8 +31,9 @@ class GFXD3D11TextureObject : public GFXTextureObject
{
protected:
static U32 mTexCount;
GFXTexHandle mLockTex;
GFXTexHandle mStagingTex;
DXGI_MAPPED_RECT mLockRect;
D3D11_BOX mLockBox;
bool mLocked;
U32 mLockedSubresource;

View file

@ -1041,9 +1041,9 @@ void GFXDrawUtil::_drawSolidPolyhedron( const GFXStateBlockDesc &desc, const Any
continue;
}
U32 numPoints = poly.extractFace( i, &indices[ idx ], numIndices - idx );
numIndicesForPoly[ numPolys ] = numPoints;
idx += numPoints;
U32 polyIDx = poly.extractFace( i, &indices[ idx ], numIndices - idx );
numIndicesForPoly[ numPolys ] = polyIDx;
idx += polyIDx;
numPolys ++;
}
@ -1083,11 +1083,11 @@ void GFXDrawUtil::drawObjectBox( const GFXStateBlockDesc &desc, const Point3F &s
PrimBuild::color( color );
PrimBuild::begin( GFXLineList, 48 );
static const Point3F cubePoints[8] =
Point3F cubePts[8];
for (U32 i = 0; i < 8; i++)
{
Point3F(-0.5, -0.5, -0.5), Point3F(-0.5, -0.5, 0.5), Point3F(-0.5, 0.5, -0.5), Point3F(-0.5, 0.5, 0.5),
Point3F( 0.5, -0.5, -0.5), Point3F( 0.5, -0.5, 0.5), Point3F( 0.5, 0.5, -0.5), Point3F( 0.5, 0.5, 0.5)
};
cubePts[i] = cubePoints[i]/2;
}
// 8 corner points of the box
for ( U32 i = 0; i < 8; i++ )
@ -1382,7 +1382,7 @@ void GFXDrawUtil::drawCylinder( const GFXStateBlockDesc &desc, const Point3F &ba
mDevice->popWorldMatrix();
}
void GFXDrawUtil::drawArrow( const GFXStateBlockDesc &desc, const Point3F &start, const Point3F &end, const ColorI &color )
void GFXDrawUtil::drawArrow( const GFXStateBlockDesc &desc, const Point3F &start, const Point3F &end, const ColorI &color, F32 baseRad )
{
GFXTransformSaver saver;
@ -1398,8 +1398,8 @@ void GFXDrawUtil::drawArrow( const GFXStateBlockDesc &desc, const Point3F &start
// Calculate the radius of the cone given that we want the cone to have
// an angle of 25 degrees (just because it looks good).
F32 coneLen = ( end - coneBase ).len();
F32 coneDiameter = mTan( mDegToRad(25.0f) ) * coneLen;
F32 coneLen = (baseRad != 0.0f) ? baseRad * 4.0 :( end - coneBase ).len();
F32 coneDiameter = (baseRad != 0.0f) ? baseRad*4.0f : mTan( mDegToRad(25.0f) ) * coneLen;
// Draw the cone on at the arrow's tip.
drawCone( desc, coneBase, end, coneDiameter / 2.0f, color );
@ -1412,7 +1412,7 @@ void GFXDrawUtil::drawArrow( const GFXStateBlockDesc &desc, const Point3F &start
Point3F coneDiff = end - coneBase;
// Draw the cylinder.
F32 stickRadius = len * 0.025f;
F32 stickRadius = (baseRad != 0.0f) ? baseRad : len * 0.025f;
drawCylinder( desc, start, end - coneDiff, stickRadius, color );
}

View file

@ -115,7 +115,7 @@ public:
void drawCapsule( const GFXStateBlockDesc &desc, const Point3F &center, F32 radius, F32 height, const ColorI &color, const MatrixF *xfm = NULL );
void drawCone( const GFXStateBlockDesc &desc, const Point3F &basePnt, const Point3F &tipPnt, F32 baseRadius, const ColorI &color );
void drawCylinder( const GFXStateBlockDesc &desc, const Point3F &basePnt, const Point3F &tipPnt, F32 baseRadius, const ColorI &color );
void drawArrow( const GFXStateBlockDesc &desc, const Point3F &start, const Point3F &end, const ColorI &color );
void drawArrow( const GFXStateBlockDesc &desc, const Point3F &start, const Point3F &end, const ColorI &color, F32 baseRad = 0.0f);
void drawFrustum( const Frustum& f, const ColorI &color );
/// Draw a solid or wireframe (depending on fill mode of @a desc) polyhedron with the given color.

View file

@ -84,28 +84,15 @@ inline static void _GFXInitReportAdapters(Vector<GFXAdapter*> &adapters)
}
}
inline static void _GFXInitGetInitialRes(GFXVideoMode &vm, const Point2I &initialSize)
inline static void _GFXInitGetInitialRes(GFXVideoMode &vm)
{
const U32 kDefaultWindowSizeX = 800;
const U32 kDefaultWindowSizeY = 600;
const bool kDefaultFullscreen = false;
const U32 kDefaultBitDepth = 32;
const U32 kDefaultRefreshRate = 60;
// cache the desktop size of the main screen
GFXVideoMode desktopVm = GFXInit::getDesktopResolution();
// load pref variables, properly choose windowed / fullscreen
const String resString = Con::getVariable("$pref::Video::mode");
// Set defaults into the video mode, then have it parse the user string.
vm.resolution.x = kDefaultWindowSizeX;
vm.resolution.y = kDefaultWindowSizeY;
vm.fullScreen = kDefaultFullscreen;
vm.bitDepth = kDefaultBitDepth;
vm.refreshRate = kDefaultRefreshRate;
vm.wideScreen = false;
// Parse video mode settings from pref string
vm.parseFromString(resString);
}
@ -365,7 +352,7 @@ GFXAdapter *GFXInit::getBestAdapterChoice()
GFXVideoMode GFXInit::getInitialVideoMode()
{
GFXVideoMode vm;
_GFXInitGetInitialRes(vm, Point2I(800,600));
_GFXInitGetInitialRes(vm);
return vm;
}

View file

@ -49,7 +49,9 @@ void GFXVideoMode::parseFromString( const char *str )
PARSE_ELEM(S32, resolution.x, dAtoi, tempBuf, " x\0")
PARSE_ELEM(S32, resolution.y, dAtoi, NULL, " x\0")
PARSE_ELEM(S32, fullScreen, dAtob, NULL, " \0")
const char *boolptr = dStrtok(NULL, " \0");
if (boolptr)
fullScreen = dAtob(boolptr);
PARSE_ELEM(S32, bitDepth, dAtoi, NULL, " \0")
PARSE_ELEM(S32, refreshRate, dAtoi, NULL, " \0")
PARSE_ELEM(S32, antialiasLevel, dAtoi, NULL, " \0")