Merge branch 'GarageGames/master' into ueberengine-dev

Conflicts:
	Engine/source/windowManager/sdl/sdlWindowMgr.cpp
	Tools/CMake/torque3d.cmake

3.10 final update
This commit is contained in:
Duion 2017-03-23 20:36:21 +01:00
commit aff033dd0d
1003 changed files with 53039 additions and 82707 deletions

View file

@ -47,12 +47,27 @@ void GFXD3D11CardProfiler::init()
mCardDescription = adapter.description;
mChipSet = adapter.chipSet;
mVersionString = adapter.driverVersion;
mVersionString = _getFeatureLevelStr();
mVideoMemory = adapter.vram;
}
Parent::init();
}
String GFXD3D11CardProfiler::_getFeatureLevelStr()
{
switch (D3D11->getFeatureLevel())
{
case D3D_FEATURE_LEVEL_11_0:
return String("Feature level 11.0");
case D3D_FEATURE_LEVEL_10_1:
return String("Feature level 10.1");
case D3D_FEATURE_LEVEL_10_0:
return String("Feature level 10.0");
default:
return String("Unknown feature level");
}
}
void GFXD3D11CardProfiler::setupCardCapabilities()
{
setCapability("maxTextureWidth", D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION);

View file

@ -41,6 +41,7 @@ protected:
void setupCardCapabilities();
bool _queryCardCap(const String &query, U32 &foundResult);
bool _queryFormat(const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips);
String _getFeatureLevelStr();
};
#endif

View file

@ -37,6 +37,7 @@
#include "windowManager/platformWindow.h"
#include "gfx/D3D11/screenshotD3D11.h"
#include "materials/shaderData.h"
#include <d3d9.h> //ok now stressing out folks, this is just for debug events(D3DPER) :)
#ifdef TORQUE_DEBUG
#include "d3d11sdklayers.h"
@ -53,6 +54,133 @@ GFXDevice *GFXD3D11Device::createInstance(U32 adapterIndex)
return dev;
}
class GFXPCD3D11RegisterDevice
{
public:
GFXPCD3D11RegisterDevice()
{
GFXInit::getRegisterDeviceSignal().notify(&GFXD3D11Device::enumerateAdapters);
}
};
static GFXPCD3D11RegisterDevice pPCD3D11RegisterDevice;
//-----------------------------------------------------------------------------
/// Parse command line arguments for window creation
//-----------------------------------------------------------------------------
static void sgPCD3D11DeviceHandleCommandLine(S32 argc, const char **argv)
{
// useful to pass parameters by command line for d3d (e.g. -dx9 -dx11)
for (U32 i = 1; i < argc; i++)
{
argv[i];
}
}
// Register the command line parsing hook
static ProcessRegisterCommandLine sgCommandLine(sgPCD3D11DeviceHandleCommandLine);
GFXD3D11Device::GFXD3D11Device(U32 index)
{
mDeviceSwizzle32 = &Swizzles::bgra;
GFXVertexColor::setSwizzle(mDeviceSwizzle32);
mDeviceSwizzle24 = &Swizzles::bgr;
mAdapterIndex = index;
mD3DDevice = NULL;
mVolatileVB = NULL;
mCurrentPB = NULL;
mDynamicPB = NULL;
mLastVertShader = NULL;
mLastPixShader = NULL;
mCanCurrentlyRender = false;
mTextureManager = NULL;
mCurrentStateBlock = NULL;
mResourceListHead = NULL;
mPixVersion = 0.0;
mVertexShaderTarget = String::EmptyString;
mPixelShaderTarget = String::EmptyString;
mShaderModel = String::EmptyString;
mDrawInstancesCount = 0;
mCardProfiler = NULL;
mDeviceDepthStencil = NULL;
mDeviceBackbuffer = NULL;
mDeviceBackBufferView = NULL;
mDeviceDepthStencilView = NULL;
mCreateFenceType = -1; // Unknown, test on first allocate
mCurrentConstBuffer = NULL;
mOcclusionQuerySupported = false;
mDebugLayers = false;
for (U32 i = 0; i < GS_COUNT; ++i)
mModelViewProjSC[i] = NULL;
// Set up the Enum translation tables
GFXD3D11EnumTranslate::init();
}
GFXD3D11Device::~GFXD3D11Device()
{
// Release our refcount on the current stateblock object
mCurrentStateBlock = NULL;
releaseDefaultPoolResources();
mD3DDeviceContext->ClearState();
mD3DDeviceContext->Flush();
// Free the sampler states
SamplerMap::Iterator sampIter = mSamplersMap.begin();
for (; sampIter != mSamplersMap.end(); ++sampIter)
SAFE_RELEASE(sampIter->value);
// Free the vertex declarations.
VertexDeclMap::Iterator iter = mVertexDecls.begin();
for (; iter != mVertexDecls.end(); iter++)
delete iter->value;
// Forcibly clean up the pools
mVolatileVBList.setSize(0);
mDynamicPB = NULL;
// And release our D3D resources.
SAFE_RELEASE(mDeviceDepthStencilView);
SAFE_RELEASE(mDeviceBackBufferView);
SAFE_RELEASE(mDeviceDepthStencil);
SAFE_RELEASE(mDeviceBackbuffer);
SAFE_RELEASE(mD3DDeviceContext);
SAFE_DELETE(mCardProfiler);
SAFE_DELETE(gScreenShot);
#ifdef TORQUE_DEBUG
if (mDebugLayers)
{
ID3D11Debug *pDebug = NULL;
mD3DDevice->QueryInterface(IID_PPV_ARGS(&pDebug));
AssertFatal(pDebug, "~GFXD3D11Device- Failed to get debug layer");
pDebug->ReportLiveDeviceObjects(D3D11_RLDO_DETAIL);
SAFE_RELEASE(pDebug);
}
#endif
SAFE_RELEASE(mSwapChain);
SAFE_RELEASE(mD3DDevice);
}
GFXFormat GFXD3D11Device::selectSupportedFormat(GFXTextureProfile *profile, const Vector<GFXFormat> &formats, bool texture, bool mustblend, bool mustfilter)
{
U32 features = 0;
@ -186,10 +314,47 @@ void GFXD3D11Device::enumerateAdapters(Vector<GFXAdapter*> &adapterList)
toAdd->mAvailableModes.push_back(vmAdd);
}
//Check adapater can handle feature level 10
D3D_FEATURE_LEVEL deviceFeature;
ID3D11Device *pTmpDevice = nullptr;
// Create temp Direct3D11 device.
bool suitable = true;
UINT createDeviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_BGRA_SUPPORT;
hr = D3D11CreateDevice(EnumAdapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, createDeviceFlags, NULL, 0, D3D11_SDK_VERSION, &pTmpDevice, &deviceFeature, NULL);
if (FAILED(hr))
suitable = false;
if (deviceFeature < D3D_FEATURE_LEVEL_10_0)
suitable = false;
//double check we support required bgra format for LEVEL_10_0 & LEVEL_10_1
if (deviceFeature == D3D_FEATURE_LEVEL_10_0 || deviceFeature == D3D_FEATURE_LEVEL_10_1)
{
U32 formatSupported = 0;
pTmpDevice->CheckFormatSupport(DXGI_FORMAT_B8G8R8A8_UNORM, &formatSupported);
U32 flagsRequired = D3D11_FORMAT_SUPPORT_RENDER_TARGET | D3D11_FORMAT_SUPPORT_DISPLAY;
if (!(formatSupported && flagsRequired))
{
Con::printf("DXGI adapter: %s does not support BGRA", Description.c_str());
suitable = false;
}
}
delete[] displayModes;
SAFE_RELEASE(pTmpDevice);
SAFE_RELEASE(pOutput);
SAFE_RELEASE(EnumAdapter);
adapterList.push_back(toAdd);
if (suitable)
{
adapterList.push_back(toAdd);
}
else
{
Con::printf("DXGI adapter: %s does not support D3D11 feature level 10 or better", Description.c_str());
delete toAdd;
}
}
SAFE_RELEASE(DXGIFactory);
@ -261,16 +426,11 @@ void GFXD3D11Device::enumerateVideoModes()
SAFE_RELEASE(DXGIFactory);
}
IDXGISwapChain* GFXD3D11Device::getSwapChain()
{
return mSwapChain;
}
void GFXD3D11Device::init(const GFXVideoMode &mode, PlatformWindow *window)
{
AssertFatal(window, "GFXD3D11Device::init - must specify a window!");
HWND winHwnd = (HWND)window->getSystemWindow( PlatformWindow::WindowSystem_Windows );
HWND hwnd = (HWND)window->getSystemWindow(PlatformWindow::WindowSystem_Windows);
SetFocus(hwnd);//ensure window has focus
UINT createDeviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifdef TORQUE_DEBUG
@ -278,66 +438,77 @@ void GFXD3D11Device::init(const GFXVideoMode &mode, PlatformWindow *window)
mDebugLayers = true;
#endif
DXGI_SWAP_CHAIN_DESC d3dpp = setupPresentParams(mode, winHwnd);
D3D_FEATURE_LEVEL deviceFeature;
D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_HARDWARE;// use D3D_DRIVER_TYPE_REFERENCE for reference device
// create a device, device context and swap chain using the information in the d3dpp struct
HRESULT hres = D3D11CreateDeviceAndSwapChain(NULL,
driverType,
NULL,
createDeviceFlags,
NULL,
0,
D3D11_SDK_VERSION,
&d3dpp,
&mSwapChain,
&mD3DDevice,
&deviceFeature,
&mD3DDeviceContext);
// create a device & device context
HRESULT hres = D3D11CreateDevice(NULL,
driverType,
NULL,
createDeviceFlags,
NULL,
0,
D3D11_SDK_VERSION,
&mD3DDevice,
&mFeatureLevel,
&mD3DDeviceContext);
if(FAILED(hres))
{
#ifdef TORQUE_DEBUG
//try again without debug device layer enabled
createDeviceFlags &= ~D3D11_CREATE_DEVICE_DEBUG;
HRESULT hres = D3D11CreateDeviceAndSwapChain(NULL, driverType,NULL,createDeviceFlags,NULL, 0,
D3D11_SDK_VERSION,
&d3dpp,
&mSwapChain,
&mD3DDevice,
&deviceFeature,
&mD3DDeviceContext);
//if we failed again than we definitely have a problem
if (FAILED(hres))
AssertFatal(false, "GFXD3D11Device::init - D3D11CreateDeviceAndSwapChain failed!");
//try again without debug device layer enabled
createDeviceFlags &= ~D3D11_CREATE_DEVICE_DEBUG;
hres = D3D11CreateDevice(NULL,
driverType,
NULL,
createDeviceFlags,
NULL,
0,
D3D11_SDK_VERSION,
&mD3DDevice,
&mFeatureLevel,
&mD3DDeviceContext);
//if we failed again than we definitely have a problem
if (FAILED(hres))
AssertFatal(false, "GFXD3D11Device::init - D3D11CreateDeviceAndSwapChain failed!");
Con::warnf("GFXD3D11Device::init - Debug layers not detected!");
mDebugLayers = false;
Con::warnf("GFXD3D11Device::init - Debug layers not detected!");
mDebugLayers = false;
#else
AssertFatal(false, "GFXD3D11Device::init - D3D11CreateDeviceAndSwapChain failed!");
AssertFatal(false, "GFXD3D11Device::init - D3D11CreateDeviceAndSwapChain failed!");
#endif
}
//set the fullscreen state here if we need to
if(mode.fullScreen)
{
hres = mSwapChain->SetFullscreenState(TRUE, NULL);
if(FAILED(hres))
{
AssertFatal(false, "GFXD3D11Device::init- Failed to set fullscreen state!");
}
}
#ifdef TORQUE_DEBUG
_suppressDebugMessages();
#endif
mTextureManager = new GFXD3D11TextureManager();
// Now reacquire all the resources we trashed earlier
reacquireDefaultPoolResources();
//TODO implement feature levels?
if (deviceFeature >= D3D_FEATURE_LEVEL_11_0)
//set vert/pixel shader targets
switch (mFeatureLevel)
{
case D3D_FEATURE_LEVEL_11_0:
mVertexShaderTarget = "vs_5_0";
mPixelShaderTarget = "ps_5_0";
mPixVersion = 5.0f;
else
AssertFatal(false, "GFXD3D11Device::init - We don't support anything below feature level 11.");
mShaderModel = "50";
break;
case D3D_FEATURE_LEVEL_10_1:
mVertexShaderTarget = "vs_4_1";
mPixelShaderTarget = "ps_4_1";
mPixVersion = 4.1f;
mShaderModel = "41";
break;
case D3D_FEATURE_LEVEL_10_0:
mVertexShaderTarget = "vs_4_0";
mPixelShaderTarget = "ps_4_0";
mPixVersion = 4.0f;
mShaderModel = "40";
break;
default:
AssertFatal(false, "GFXD3D11Device::init - We don't support this feature level");
}
D3D11_QUERY_DESC queryDesc;
queryDesc.Query = D3D11_QUERY_OCCLUSION;
@ -355,68 +526,6 @@ void GFXD3D11Device::init(const GFXVideoMode &mode, PlatformWindow *window)
mCardProfiler = new GFXD3D11CardProfiler();
mCardProfiler->init();
D3D11_TEXTURE2D_DESC desc;
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
desc.CPUAccessFlags = 0;
desc.Format = GFXD3D11TextureFormat[GFXFormatD24S8];
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.Width = mode.resolution.x;
desc.Height = mode.resolution.y;
desc.SampleDesc.Count =1;
desc.SampleDesc.Quality =0;
desc.MiscFlags = 0;
HRESULT hr = mD3DDevice->CreateTexture2D(&desc, NULL, &mDeviceDepthStencil);
if(FAILED(hr))
{
AssertFatal(false, "GFXD3D11Device::init - couldn't create device's depth-stencil surface.");
}
D3D11_DEPTH_STENCIL_VIEW_DESC depthDesc;
depthDesc.Format = GFXD3D11TextureFormat[GFXFormatD24S8];
depthDesc.Flags =0 ;
depthDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthDesc.Texture2D.MipSlice = 0;
hr = mD3DDevice->CreateDepthStencilView(mDeviceDepthStencil, &depthDesc, &mDeviceDepthStencilView);
if(FAILED(hr))
{
AssertFatal(false, "GFXD3D11Device::init - couldn't create depth stencil view");
}
hr = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mDeviceBackbuffer);
if(FAILED(hr))
AssertFatal(false, "GFXD3D11Device::init - coudln't retrieve backbuffer ref");
//create back buffer view
D3D11_RENDER_TARGET_VIEW_DESC RTDesc;
RTDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
RTDesc.Texture2D.MipSlice = 0;
RTDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
hr = mD3DDevice->CreateRenderTargetView(mDeviceBackbuffer, &RTDesc, &mDeviceBackBufferView);
if(FAILED(hr))
AssertFatal(false, "GFXD3D11Device::init - couldn't create back buffer target view");
#ifdef TORQUE_DEBUG
String backBufferName = "MainBackBuffer";
String depthSteniclName = "MainDepthStencil";
String backBuffViewName = "MainBackBuffView";
String depthStencViewName = "MainDepthView";
mDeviceBackbuffer->SetPrivateData(WKPDID_D3DDebugObjectName, backBufferName.size(), backBufferName.c_str());
mDeviceDepthStencil->SetPrivateData(WKPDID_D3DDebugObjectName, depthSteniclName.size(), depthSteniclName.c_str());
mDeviceDepthStencilView->SetPrivateData(WKPDID_D3DDebugObjectName, depthStencViewName.size(), depthStencViewName.c_str());
mDeviceBackBufferView->SetPrivateData(WKPDID_D3DDebugObjectName, backBuffViewName.size(), backBuffViewName.c_str());
_suppressDebugMessages();
#endif
gScreenShot = new ScreenShotD3D11;
mInitialized = true;
@ -466,14 +575,35 @@ GFXWindowTarget * GFXD3D11Device::allocWindowTarget(PlatformWindow *window)
{
AssertFatal(window,"GFXD3D11Device::allocWindowTarget - no window provided!");
// Allocate the device.
init(window->getVideoMode(), window);
// Set up a new window target...
GFXD3D11WindowTarget *gdwt = new GFXD3D11WindowTarget();
gdwt->mWindow = window;
gdwt->mSize = window->getClientExtent();
gdwt->initPresentationParams();
if (!mInitialized)
{
gdwt->mSecondaryWindow = false;
// Allocate the device.
init(window->getVideoMode(), window);
gdwt->initPresentationParams();
gdwt->createSwapChain();
gdwt->createBuffersAndViews();
mSwapChain = gdwt->getSwapChain();
mDeviceBackbuffer = gdwt->getBackBuffer();
mDeviceDepthStencil = gdwt->getDepthStencil();
mDeviceBackBufferView = gdwt->getBackBufferView();
mDeviceDepthStencilView = gdwt->getDepthStencilView();
}
else //additional window/s
{
gdwt->mSecondaryWindow = true;
gdwt->initPresentationParams();
gdwt->createSwapChain();
gdwt->createBuffersAndViews();
}
gdwt->registerResourceWithDevice(this);
return gdwt;
@ -487,13 +617,15 @@ GFXTextureTarget* GFXD3D11Device::allocRenderToTextureTarget()
return targ;
}
void GFXD3D11Device::reset(DXGI_SWAP_CHAIN_DESC &d3dpp)
void GFXD3D11Device::beginReset()
{
if (!mD3DDevice)
return;
mInitialized = false;
releaseDefaultPoolResources();
// Clean up some commonly dangling state. This helps prevents issues with
// items that are destroyed by the texture manager callbacks and recreated
// later, but still left bound.
@ -504,239 +636,30 @@ void GFXD3D11Device::reset(DXGI_SWAP_CHAIN_DESC &d3dpp)
mD3DDeviceContext->ClearState();
DXGI_MODE_DESC displayModes;
displayModes.Format = d3dpp.BufferDesc.Format;
displayModes.Height = d3dpp.BufferDesc.Height;
displayModes.Width = d3dpp.BufferDesc.Width;
displayModes.RefreshRate = d3dpp.BufferDesc.RefreshRate;
displayModes.Scaling = d3dpp.BufferDesc.Scaling;
displayModes.ScanlineOrdering = d3dpp.BufferDesc.ScanlineOrdering;
HRESULT hr;
if (!d3dpp.Windowed)
{
hr = mSwapChain->ResizeTarget(&displayModes);
if (FAILED(hr))
{
AssertFatal(false, "D3D11Device::reset - failed to resize target!");
}
}
// First release all the stuff we allocated from D3DPOOL_DEFAULT
releaseDefaultPoolResources();
//release the backbuffer, depthstencil, and their views
SAFE_RELEASE(mDeviceBackBufferView);
SAFE_RELEASE(mDeviceBackbuffer);
//release old buffers and views
SAFE_RELEASE(mDeviceDepthStencilView);
SAFE_RELEASE(mDeviceBackBufferView);
SAFE_RELEASE(mDeviceDepthStencil);
SAFE_RELEASE(mDeviceBackbuffer);
}
hr = mSwapChain->ResizeBuffers(d3dpp.BufferCount, d3dpp.BufferDesc.Width, d3dpp.BufferDesc.Height, d3dpp.BufferDesc.Format, d3dpp.Windowed ? 0 : DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH);
if (FAILED(hr))
{
AssertFatal(false, "D3D11Device::reset - failed to resize back buffer!");
}
//recreate backbuffer view. depth stencil view and texture
D3D11_TEXTURE2D_DESC desc;
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
desc.CPUAccessFlags = 0;
desc.Format = GFXD3D11TextureFormat[GFXFormatD24S8];
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.Width = d3dpp.BufferDesc.Width;
desc.Height = d3dpp.BufferDesc.Height;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.MiscFlags = 0;
hr = mD3DDevice->CreateTexture2D(&desc, NULL, &mDeviceDepthStencil);
if (FAILED(hr))
{
AssertFatal(false, "GFXD3D11Device::reset - couldn't create device's depth-stencil surface.");
}
D3D11_DEPTH_STENCIL_VIEW_DESC depthDesc;
depthDesc.Format = GFXD3D11TextureFormat[GFXFormatD24S8];
depthDesc.Flags = 0;
depthDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthDesc.Texture2D.MipSlice = 0;
hr = mD3DDevice->CreateDepthStencilView(mDeviceDepthStencil, &depthDesc, &mDeviceDepthStencilView);
if (FAILED(hr))
{
AssertFatal(false, "GFXD3D11Device::reset - couldn't create depth stencil view");
}
hr = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mDeviceBackbuffer);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11Device::reset - coudln't retrieve backbuffer ref");
//create back buffer view
D3D11_RENDER_TARGET_VIEW_DESC RTDesc;
RTDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
RTDesc.Texture2D.MipSlice = 0;
RTDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
hr = mD3DDevice->CreateRenderTargetView(mDeviceBackbuffer, &RTDesc, &mDeviceBackBufferView);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11Device::reset - couldn't create back buffer target view");
void GFXD3D11Device::endReset(GFXD3D11WindowTarget *windowTarget)
{
//grab new references
mDeviceBackbuffer = windowTarget->getBackBuffer();
mDeviceDepthStencil = windowTarget->getDepthStencil();
mDeviceBackBufferView = windowTarget->getBackBufferView();
mDeviceDepthStencilView = windowTarget->getDepthStencilView();
mD3DDeviceContext->OMSetRenderTargets(1, &mDeviceBackBufferView, mDeviceDepthStencilView);
hr = mSwapChain->SetFullscreenState(!d3dpp.Windowed, NULL);
if (FAILED(hr))
{
AssertFatal(false, "D3D11Device::reset - failed to change screen states!");
}
//Microsoft recommend this, see DXGI documentation
if (!d3dpp.Windowed)
{
displayModes.RefreshRate.Numerator = 0;
displayModes.RefreshRate.Denominator = 0;
hr = mSwapChain->ResizeTarget(&displayModes);
if (FAILED(hr))
{
AssertFatal(false, "D3D11Device::reset - failed to resize target!");
}
}
mInitialized = true;
// Now re aquire all the resources we trashed earlier
// Now reacquire all the resources we trashed earlier
reacquireDefaultPoolResources();
mInitialized = true;
// Mark everything dirty and flush to card, for sanity.
updateStates(true);
}
class GFXPCD3D11RegisterDevice
{
public:
GFXPCD3D11RegisterDevice()
{
GFXInit::getRegisterDeviceSignal().notify(&GFXD3D11Device::enumerateAdapters);
}
};
static GFXPCD3D11RegisterDevice pPCD3D11RegisterDevice;
//-----------------------------------------------------------------------------
/// Parse command line arguments for window creation
//-----------------------------------------------------------------------------
static void sgPCD3D11DeviceHandleCommandLine(S32 argc, const char **argv)
{
// useful to pass parameters by command line for d3d (e.g. -dx9 -dx11)
for (U32 i = 1; i < argc; i++)
{
argv[i];
}
}
// Register the command line parsing hook
static ProcessRegisterCommandLine sgCommandLine( sgPCD3D11DeviceHandleCommandLine );
GFXD3D11Device::GFXD3D11Device(U32 index)
{
mDeviceSwizzle32 = &Swizzles::bgra;
GFXVertexColor::setSwizzle( mDeviceSwizzle32 );
mDeviceSwizzle24 = &Swizzles::bgr;
mAdapterIndex = index;
mD3DDevice = NULL;
mVolatileVB = NULL;
mCurrentPB = NULL;
mDynamicPB = NULL;
mLastVertShader = NULL;
mLastPixShader = NULL;
mCanCurrentlyRender = false;
mTextureManager = NULL;
mCurrentStateBlock = NULL;
mResourceListHead = NULL;
mPixVersion = 0.0;
mDrawInstancesCount = 0;
mCardProfiler = NULL;
mDeviceDepthStencil = NULL;
mDeviceBackbuffer = NULL;
mDeviceBackBufferView = NULL;
mDeviceDepthStencilView = NULL;
mCreateFenceType = -1; // Unknown, test on first allocate
mCurrentConstBuffer = NULL;
mOcclusionQuerySupported = false;
mDebugLayers = false;
for(U32 i = 0; i < GS_COUNT; ++i)
mModelViewProjSC[i] = NULL;
// Set up the Enum translation tables
GFXD3D11EnumTranslate::init();
}
GFXD3D11Device::~GFXD3D11Device()
{
// Release our refcount on the current stateblock object
mCurrentStateBlock = NULL;
releaseDefaultPoolResources();
mD3DDeviceContext->ClearState();
mD3DDeviceContext->Flush();
// Free the vertex declarations.
VertexDeclMap::Iterator iter = mVertexDecls.begin();
for ( ; iter != mVertexDecls.end(); iter++ )
delete iter->value;
// Forcibly clean up the pools
mVolatileVBList.setSize(0);
mDynamicPB = NULL;
// And release our D3D resources.
SAFE_RELEASE(mDeviceDepthStencilView);
SAFE_RELEASE(mDeviceBackBufferView);
SAFE_RELEASE(mDeviceDepthStencil);
SAFE_RELEASE(mDeviceBackbuffer);
SAFE_RELEASE(mD3DDeviceContext);
SAFE_DELETE(mCardProfiler);
SAFE_DELETE(gScreenShot);
#ifdef TORQUE_DEBUG
if (mDebugLayers)
{
ID3D11Debug *pDebug = NULL;
mD3DDevice->QueryInterface(IID_PPV_ARGS(&pDebug));
AssertFatal(pDebug, "~GFXD3D11Device- Failed to get debug layer");
pDebug->ReportLiveDeviceObjects(D3D11_RLDO_DETAIL);
SAFE_RELEASE(pDebug);
}
#endif
SAFE_RELEASE(mSwapChain);
SAFE_RELEASE(mD3DDevice);
}
void GFXD3D11Device::setupGenericShaders(GenericShaderType type)
{
AssertFatal(type != GSTargetRestore, ""); //not used
@ -744,11 +667,12 @@ void GFXD3D11Device::setupGenericShaders(GenericShaderType type)
if(mGenericShader[GSColor] == NULL)
{
ShaderData *shaderData;
//shader model 4.0 is enough for the generic shaders
const char* shaderModel = "4.0";
shaderData = new ShaderData();
shaderData->setField("DXVertexShaderFile", "shaders/common/fixedFunction/colorV.hlsl");
shaderData->setField("DXPixelShaderFile", "shaders/common/fixedFunction/colorP.hlsl");
shaderData->setField("pixVersion", "5.0");
shaderData->setField("pixVersion", shaderModel);
shaderData->registerObject();
mGenericShader[GSColor] = shaderData->getShader();
mGenericShaderBuffer[GSColor] = mGenericShader[GSColor]->allocConstBuffer();
@ -758,7 +682,7 @@ void GFXD3D11Device::setupGenericShaders(GenericShaderType type)
shaderData = new ShaderData();
shaderData->setField("DXVertexShaderFile", "shaders/common/fixedFunction/modColorTextureV.hlsl");
shaderData->setField("DXPixelShaderFile", "shaders/common/fixedFunction/modColorTextureP.hlsl");
shaderData->setField("pixVersion", "5.0");
shaderData->setField("pixVersion", shaderModel);
shaderData->registerObject();
mGenericShader[GSModColorTexture] = shaderData->getShader();
mGenericShaderBuffer[GSModColorTexture] = mGenericShader[GSModColorTexture]->allocConstBuffer();
@ -768,7 +692,7 @@ void GFXD3D11Device::setupGenericShaders(GenericShaderType type)
shaderData = new ShaderData();
shaderData->setField("DXVertexShaderFile", "shaders/common/fixedFunction/addColorTextureV.hlsl");
shaderData->setField("DXPixelShaderFile", "shaders/common/fixedFunction/addColorTextureP.hlsl");
shaderData->setField("pixVersion", "5.0");
shaderData->setField("pixVersion", shaderModel);
shaderData->registerObject();
mGenericShader[GSAddColorTexture] = shaderData->getShader();
mGenericShaderBuffer[GSAddColorTexture] = mGenericShader[GSAddColorTexture]->allocConstBuffer();
@ -778,7 +702,7 @@ void GFXD3D11Device::setupGenericShaders(GenericShaderType type)
shaderData = new ShaderData();
shaderData->setField("DXVertexShaderFile", "shaders/common/fixedFunction/textureV.hlsl");
shaderData->setField("DXPixelShaderFile", "shaders/common/fixedFunction/textureP.hlsl");
shaderData->setField("pixVersion", "5.0");
shaderData->setField("pixVersion", shaderModel);
shaderData->registerObject();
mGenericShader[GSTexture] = shaderData->getShader();
mGenericShaderBuffer[GSTexture] = mGenericShader[GSTexture]->allocConstBuffer();
@ -1759,4 +1683,32 @@ GFXCubemap * GFXD3D11Device::createCubemap()
GFXD3D11Cubemap* cube = new GFXD3D11Cubemap();
cube->registerResourceWithDevice(this);
return cube;
}
//------------------------------------------------------------------------------
void GFXD3D11Device::enterDebugEvent(ColorI color, const char *name)
{
// BJGFIX
WCHAR eventName[260];
MultiByteToWideChar(CP_ACP, 0, name, -1, eventName, 260);
D3DPERF_BeginEvent(D3DCOLOR_ARGB(color.alpha, color.red, color.green, color.blue),
(LPCWSTR)&eventName);
}
//------------------------------------------------------------------------------
void GFXD3D11Device::leaveDebugEvent()
{
D3DPERF_EndEvent();
}
//------------------------------------------------------------------------------
void GFXD3D11Device::setDebugMarker(ColorI color, const char *name)
{
// BJGFIX
WCHAR eventName[260];
MultiByteToWideChar(CP_ACP, 0, name, -1, eventName, 260);
D3DPERF_SetMarker(D3DCOLOR_ARGB(color.alpha, color.red, color.green, color.blue),
(LPCWSTR)&eventName);
}

View file

@ -49,6 +49,10 @@ class D3D11OculusTexture;
class GFXD3D11Device : public GFXDevice
{
public:
typedef Map<U32, ID3D11SamplerState*> SamplerMap;
private:
friend class GFXResource;
friend class GFXD3D11PrimitiveBuffer;
friend class GFXD3D11VertexBuffer;
@ -66,9 +70,9 @@ class GFXD3D11Device : public GFXDevice
virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window);
virtual GFXTextureTarget *allocRenderToTextureTarget();
virtual void enterDebugEvent(ColorI color, const char *name){};
virtual void leaveDebugEvent(){};
virtual void setDebugMarker(ColorI color, const char *name){};
virtual void enterDebugEvent(ColorI color, const char *name);
virtual void leaveDebugEvent();
virtual void setDebugMarker(ColorI color, const char *name);
protected:
@ -98,6 +102,9 @@ protected:
typedef Map<String,D3D11VertexDecl*> VertexDeclMap;
VertexDeclMap mVertexDecls;
/// Used to lookup sampler state for a given hash key
SamplerMap mSamplersMap;
ID3D11RenderTargetView* mDeviceBackBufferView;
ID3D11DepthStencilView* mDeviceDepthStencilView;
@ -129,6 +136,13 @@ protected:
F32 mPixVersion;
D3D_FEATURE_LEVEL mFeatureLevel;
// Shader Model targers
String mVertexShaderTarget;
String mPixelShaderTarget;
// String for use with shader macros in the form of shader model version * 10
String mShaderModel;
bool mDebugLayers;
DXGI_SAMPLE_DESC mMultisampleDesc;
@ -146,7 +160,6 @@ protected:
virtual GFXD3D11VertexBuffer* findVBPool( const GFXVertexFormat *vertexFormat, U32 numVertsNeeded );
virtual GFXD3D11VertexBuffer* createVBPool( const GFXVertexFormat *vertexFormat, U32 vertSize );
IDXGISwapChain* getSwapChain();
// State overrides
// {
@ -197,8 +210,6 @@ public:
static void enumerateAdapters( Vector<GFXAdapter*> &adapterList );
GFXTextureObject* createRenderSurface( U32 width, U32 height, GFXFormat format, U32 mipLevel );
ID3D11DepthStencilView* getDepthStencilView() { return mDeviceDepthStencilView; }
ID3D11RenderTargetView* getRenderTargetView() { return mDeviceBackBufferView; }
ID3D11Texture2D* getBackBufferTexture() { return mDeviceBackbuffer; }
@ -281,7 +292,8 @@ public:
ID3D11Device* getDevice(){ return mD3DDevice; }
/// Reset
void reset( DXGI_SWAP_CHAIN_DESC &d3dpp );
void beginReset();
void endReset(GFXD3D11WindowTarget *windowTarget);
virtual void setupGenericShaders( GenericShaderType type = GSColor );
@ -294,6 +306,17 @@ public:
// Default multisample parameters
DXGI_SAMPLE_DESC getMultisampleType() const { return mMultisampleDesc; }
// Get feature level this gfx device supports
D3D_FEATURE_LEVEL getFeatureLevel() const { return mFeatureLevel; }
// Shader Model targers
const String &getVertexShaderTarget() const { return mVertexShaderTarget; }
const String &getPixelShaderTarget() const { return mPixelShaderTarget; }
const String &getShaderModel() const { return mShaderModel; }
// grab the sampler map
const SamplerMap &getSamplersMap() const { return mSamplersMap; }
SamplerMap &getSamplersMap() { return mSamplersMap; }
};
#endif

View file

@ -206,7 +206,6 @@ bool GFXD3D11ConstBufferLayout::setMatrix(const ParamDesc& pd, const GFXShaderCo
}
else if (pd.constType == GFXSCT_Float4x3)
{
F32 buffer[4 * 4];
const U32 csize = 48;
// Loop through and copy
@ -791,9 +790,8 @@ bool GFXD3D11Shader::_init()
d3dMacros[i+smGlobalMacros.size()].Definition = mMacros[i].value.c_str();
}
//TODO support D3D_FEATURE_LEVEL properly with shaders instead of hard coding at hlsl 5
d3dMacros[macroCount - 2].Name = "TORQUE_SM";
d3dMacros[macroCount - 2].Definition = "50";
d3dMacros[macroCount - 2].Definition = D3D11->getShaderModel().c_str();
memset(&d3dMacros[macroCount - 1], 0, sizeof(D3D_SHADER_MACRO));
@ -811,18 +809,21 @@ bool GFXD3D11Shader::_init()
mSamplerDescriptions.clear();
mShaderConsts.clear();
String vertTarget = D3D11->getVertexShaderTarget();
String pixTarget = D3D11->getPixelShaderTarget();
if ( !Con::getBoolVariable( "$shaders::forceLoadCSF", false ) )
{
if (!mVertexFile.isEmpty() && !_compileShader( mVertexFile, "vs_5_0", d3dMacros, mVertexConstBufferLayout, mSamplerDescriptions ) )
if (!mVertexFile.isEmpty() && !_compileShader( mVertexFile, vertTarget, d3dMacros, mVertexConstBufferLayout, mSamplerDescriptions ) )
return false;
if (!mPixelFile.isEmpty() && !_compileShader( mPixelFile, "ps_5_0", d3dMacros, mPixelConstBufferLayout, mSamplerDescriptions ) )
if (!mPixelFile.isEmpty() && !_compileShader( mPixelFile, pixTarget, d3dMacros, mPixelConstBufferLayout, mSamplerDescriptions ) )
return false;
}
else
{
if ( !_loadCompiledOutput( mVertexFile, "vs_5_0", mVertexConstBufferLayout, mSamplerDescriptions ) )
if ( !_loadCompiledOutput( mVertexFile, vertTarget, mVertexConstBufferLayout, mSamplerDescriptions ) )
{
if ( smLogErrors )
Con::errorf( "GFXD3D11Shader::init - Unable to load precompiled vertex shader for '%s'.", mVertexFile.getFullPath().c_str() );
@ -830,7 +831,7 @@ bool GFXD3D11Shader::_init()
return false;
}
if ( !_loadCompiledOutput( mPixelFile, "ps_5_0", mPixelConstBufferLayout, mSamplerDescriptions ) )
if ( !_loadCompiledOutput( mPixelFile, pixTarget, mPixelConstBufferLayout, mSamplerDescriptions ) )
{
if ( smLogErrors )
Con::errorf( "GFXD3D11Shader::init - Unable to load precompiled pixel shader for '%s'.", mPixelFile.getFullPath().c_str() );
@ -1053,20 +1054,20 @@ bool GFXD3D11Shader::_compileShader( const Torque::Path &filePath,
return result;
}
void GFXD3D11Shader::_getShaderConstants( ID3D11ShaderReflection *table,
void GFXD3D11Shader::_getShaderConstants( ID3D11ShaderReflection *pTable,
GenericConstBufferLayout *bufferLayoutIn,
Vector<GFXShaderConstDesc> &samplerDescriptions )
{
PROFILE_SCOPE( GFXD3D11Shader_GetShaderConstants );
AssertFatal(table, "NULL constant table not allowed, is this an assembly shader?");
AssertFatal(pTable, "NULL constant table not allowed, is this an assembly shader?");
GFXD3D11ConstBufferLayout *bufferLayout = (GFXD3D11ConstBufferLayout*)bufferLayoutIn;
Vector<ConstSubBufferDesc> &subBuffers = bufferLayout->getSubBufferDesc();
subBuffers.clear();
D3D11_SHADER_DESC tableDesc;
HRESULT hr = table->GetDesc(&tableDesc);
HRESULT hr = pTable->GetDesc(&tableDesc);
if (FAILED(hr))
{
AssertFatal(false, "Shader Reflection table unable to be created");
@ -1076,7 +1077,7 @@ void GFXD3D11Shader::_getShaderConstants( ID3D11ShaderReflection *table,
U32 bufferOffset = 0;
for (U32 i = 0; i < tableDesc.ConstantBuffers; i++)
{
ID3D11ShaderReflectionConstantBuffer* constantBuffer = table->GetConstantBufferByIndex(i);
ID3D11ShaderReflectionConstantBuffer* constantBuffer = pTable->GetConstantBufferByIndex(i);
D3D11_SHADER_BUFFER_DESC constantBufferDesc;
if (constantBuffer->GetDesc(&constantBufferDesc) == S_OK)
@ -1161,7 +1162,7 @@ void GFXD3D11Shader::_getShaderConstants( ID3D11ShaderReflection *table,
{
GFXShaderConstDesc desc;
D3D11_SHADER_INPUT_BIND_DESC bindDesc;
table->GetResourceBindingDesc(i, &bindDesc);
pTable->GetResourceBindingDesc(i, &bindDesc);
switch (bindDesc.Type)
{

View file

@ -434,7 +434,7 @@ protected:
GenericConstBufferLayout *bufferLayout,
Vector<GFXShaderConstDesc> &samplerDescriptions );
void _getShaderConstants( ID3D11ShaderReflection* table,
void _getShaderConstants( ID3D11ShaderReflection* pTable,
GenericConstBufferLayout *bufferLayout,
Vector<GFXShaderConstDesc> &samplerDescriptions );

View file

@ -23,130 +23,172 @@
#include "gfx/gfxDevice.h"
#include "gfx/D3D11/gfxD3D11StateBlock.h"
#include "gfx/D3D11/gfxD3D11EnumTranslate.h"
#include "core/crc.h"
namespace DictHash
{
inline U32 hash(const GFXSamplerStateDesc &data)
{
return CRC::calculateCRC(&data, sizeof(GFXSamplerStateDesc));;
}
}
GFXD3D11StateBlock::GFXD3D11StateBlock(const GFXStateBlockDesc& desc)
{
AssertFatal(D3D11DEVICE, "Invalid D3DDevice!");
mDesc = desc;
mCachedHashValue = desc.getHashValue();
AssertFatal(D3D11DEVICE, "Invalid D3DDevice!");
PROFILE_SCOPE(GFXD3D11StateBlock_CreateStateBlock);
// Color writes
mColorMask = 0;
mColorMask |= (mDesc.colorWriteRed ? D3D11_COLOR_WRITE_ENABLE_RED : 0);
mColorMask |= (mDesc.colorWriteGreen ? D3D11_COLOR_WRITE_ENABLE_GREEN : 0);
mColorMask |= (mDesc.colorWriteBlue ? D3D11_COLOR_WRITE_ENABLE_BLUE : 0);
mColorMask |= (mDesc.colorWriteAlpha ? D3D11_COLOR_WRITE_ENABLE_ALPHA : 0);
mDesc = desc;
mCachedHashValue = desc.getHashValue();
mBlendState = NULL;
for (U32 i = 0; i < GFX->getNumSamplers(); i++)
{
mSamplerStates[i] = NULL;
}
// Color writes
mColorMask = 0;
mColorMask |= (mDesc.colorWriteRed ? D3D11_COLOR_WRITE_ENABLE_RED : 0);
mColorMask |= (mDesc.colorWriteGreen ? D3D11_COLOR_WRITE_ENABLE_GREEN : 0);
mColorMask |= (mDesc.colorWriteBlue ? D3D11_COLOR_WRITE_ENABLE_BLUE : 0);
mColorMask |= (mDesc.colorWriteAlpha ? D3D11_COLOR_WRITE_ENABLE_ALPHA : 0);
mBlendState = NULL;
for (U32 i = 0; i < 16; i++)
{
mSamplerStates[i] = NULL;
}
mDepthStencilState = NULL;
mRasterizerState = NULL;
mBlendDesc.AlphaToCoverageEnable = false;
mBlendDesc.IndependentBlendEnable = false;
ZeroMemory(&mBlendDesc, sizeof(D3D11_BLEND_DESC));
mBlendDesc.AlphaToCoverageEnable = false;
mBlendDesc.IndependentBlendEnable = mDesc.separateAlphaBlendEnable;
mBlendDesc.RenderTarget[0].BlendEnable = mDesc.blendEnable;
mBlendDesc.RenderTarget[0].BlendOp = GFXD3D11BlendOp[mDesc.blendOp];
mBlendDesc.RenderTarget[0].BlendOpAlpha = GFXD3D11BlendOp[mDesc.separateAlphaBlendOp];
mBlendDesc.RenderTarget[0].DestBlend = GFXD3D11Blend[mDesc.blendDest];
mBlendDesc.RenderTarget[0].DestBlendAlpha = GFXD3D11Blend[mDesc.separateAlphaBlendDest];
mBlendDesc.RenderTarget[0].SrcBlend = GFXD3D11Blend[mDesc.blendSrc];
mBlendDesc.RenderTarget[0].SrcBlendAlpha = GFXD3D11Blend[mDesc.separateAlphaBlendSrc];
mBlendDesc.RenderTarget[0].RenderTargetWriteMask = mColorMask;
mBlendDesc.RenderTarget[0].BlendEnable = mDesc.blendEnable;
mBlendDesc.RenderTarget[0].BlendOp = GFXD3D11BlendOp[mDesc.blendOp];
mBlendDesc.RenderTarget[0].BlendOpAlpha = GFXD3D11BlendOp[mDesc.separateAlphaBlendOp];
mBlendDesc.RenderTarget[0].DestBlend = GFXD3D11Blend[mDesc.blendDest];
mBlendDesc.RenderTarget[0].DestBlendAlpha = GFXD3D11Blend[mDesc.separateAlphaBlendDest];
mBlendDesc.RenderTarget[0].SrcBlend = GFXD3D11Blend[mDesc.blendSrc];
mBlendDesc.RenderTarget[0].SrcBlendAlpha = GFXD3D11Blend[mDesc.separateAlphaBlendSrc];
mBlendDesc.RenderTarget[0].RenderTargetWriteMask = mColorMask;
HRESULT hr = D3D11DEVICE->CreateBlendState(&mBlendDesc, &mBlendState);
HRESULT hr = D3D11DEVICE->CreateBlendState(&mBlendDesc, &mBlendState);
if(FAILED(hr))
{
AssertFatal(false, "GFXD3D11StateBlock::GFXD3D11StateBlock - CreateBlendState call failure.");
}
if (FAILED(hr))
{
AssertFatal(false, "GFXD3D11StateBlock::GFXD3D11StateBlock - CreateBlendState call failure.");
}
mDepthStencilDesc.DepthWriteMask = mDesc.zWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
mDepthStencilDesc.DepthEnable = mDesc.zEnable;
mDepthStencilDesc.DepthFunc = GFXD3D11CmpFunc[mDesc.zFunc];
mDepthStencilDesc.StencilWriteMask = mDesc.stencilWriteMask;
mDepthStencilDesc.StencilReadMask = mDesc.stencilMask;
mDepthStencilDesc.StencilEnable = mDesc.stencilEnable;
ZeroMemory(&mDepthStencilDesc, sizeof(D3D11_DEPTH_STENCIL_DESC));
mDepthStencilDesc.DepthWriteMask = mDesc.zWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
mDepthStencilDesc.DepthEnable = mDesc.zEnable;
mDepthStencilDesc.DepthFunc = GFXD3D11CmpFunc[mDesc.zFunc];
mDepthStencilDesc.StencilWriteMask = mDesc.stencilWriteMask;
mDepthStencilDesc.StencilReadMask = mDesc.stencilMask;
mDepthStencilDesc.StencilEnable = mDesc.stencilEnable;
mDepthStencilDesc.FrontFace.StencilFunc = GFXD3D11CmpFunc[mDesc.stencilFunc];
mDepthStencilDesc.FrontFace.StencilFailOp = GFXD3D11StencilOp[mDesc.stencilFailOp];
mDepthStencilDesc.FrontFace.StencilDepthFailOp = GFXD3D11StencilOp[mDesc.stencilZFailOp];
mDepthStencilDesc.FrontFace.StencilPassOp = GFXD3D11StencilOp[mDesc.stencilPassOp];
mDepthStencilDesc.BackFace = mDepthStencilDesc.FrontFace;
mDepthStencilDesc.FrontFace.StencilFunc = GFXD3D11CmpFunc[mDesc.stencilFunc];
mDepthStencilDesc.FrontFace.StencilFailOp = GFXD3D11StencilOp[mDesc.stencilFailOp];
mDepthStencilDesc.FrontFace.StencilDepthFailOp = GFXD3D11StencilOp[mDesc.stencilZFailOp];
mDepthStencilDesc.FrontFace.StencilPassOp = GFXD3D11StencilOp[mDesc.stencilPassOp];
hr = D3D11DEVICE->CreateDepthStencilState(&mDepthStencilDesc, &mDepthStencilState);
if (mDesc.stencilEnable)
mDepthStencilDesc.BackFace = mDepthStencilDesc.FrontFace;
else
{
mDepthStencilDesc.BackFace.StencilFunc = GFXD3D11CmpFunc[GFXCmpAlways];
mDepthStencilDesc.BackFace.StencilFailOp = GFXD3D11StencilOp[GFXStencilOpKeep];
mDepthStencilDesc.BackFace.StencilDepthFailOp = GFXD3D11StencilOp[GFXStencilOpKeep];
mDepthStencilDesc.BackFace.StencilPassOp = GFXD3D11StencilOp[GFXStencilOpKeep];
}
if(FAILED(hr))
{
AssertFatal(false, "GFXD3D11StateBlock::GFXD3D11StateBlock - CreateDepthStencilState call failure.");
}
hr = D3D11DEVICE->CreateDepthStencilState(&mDepthStencilDesc, &mDepthStencilState);
mRasterizerDesc.CullMode = GFXD3D11CullMode[mDesc.cullMode];
mRasterizerDesc.FillMode = GFXD3D11FillMode[mDesc.fillMode];
mRasterizerDesc.DepthBias = mDesc.zBias;
mRasterizerDesc.SlopeScaledDepthBias = mDesc.zSlopeBias;
mRasterizerDesc.AntialiasedLineEnable = FALSE;
mRasterizerDesc.MultisampleEnable = FALSE;
mRasterizerDesc.ScissorEnable = FALSE;
mRasterizerDesc.DepthClipEnable = TRUE;
mRasterizerDesc.FrontCounterClockwise = FALSE;
mRasterizerDesc.DepthBiasClamp = D3D11_DEFAULT_DEPTH_BIAS_CLAMP;
if (FAILED(hr))
{
AssertFatal(false, "GFXD3D11StateBlock::GFXD3D11StateBlock - CreateDepthStencilState call failure.");
}
hr = D3D11DEVICE->CreateRasterizerState(&mRasterizerDesc, &mRasterizerState);
ZeroMemory(&mRasterizerDesc, sizeof(D3D11_RASTERIZER_DESC));
mRasterizerDesc.CullMode = GFXD3D11CullMode[mDesc.cullMode];
mRasterizerDesc.FillMode = GFXD3D11FillMode[mDesc.fillMode];
mRasterizerDesc.DepthBias = mDesc.zBias;
mRasterizerDesc.SlopeScaledDepthBias = mDesc.zSlopeBias;
mRasterizerDesc.AntialiasedLineEnable = FALSE;
mRasterizerDesc.MultisampleEnable = FALSE;
mRasterizerDesc.ScissorEnable = FALSE;
mRasterizerDesc.FrontCounterClockwise = FALSE;
mRasterizerDesc.DepthBiasClamp = D3D11_DEFAULT_DEPTH_BIAS_CLAMP;
if(FAILED(hr))
{
AssertFatal(false, "GFXD3D11StateBlock::GFXD3D11StateBlock - CreateDepthStencilState call failure.");
}
if (mDesc.zEnable)
mRasterizerDesc.DepthClipEnable = true;
else
mRasterizerDesc.DepthClipEnable = false;
for ( U32 i = 0; i < GFX->getNumSamplers(); i++ )
{
mSamplerDesc[i].AddressU = GFXD3D11TextureAddress[mDesc.samplers[i].addressModeU];
mSamplerDesc[i].AddressV = GFXD3D11TextureAddress[mDesc.samplers[i].addressModeV];
mSamplerDesc[i].AddressW = GFXD3D11TextureAddress[mDesc.samplers[i].addressModeW];
mSamplerDesc[i].MaxAnisotropy = mDesc.samplers[i].maxAnisotropy;
hr = D3D11DEVICE->CreateRasterizerState(&mRasterizerDesc, &mRasterizerState);
mSamplerDesc[i].MipLODBias = mDesc.samplers[i].mipLODBias;
mSamplerDesc[i].MinLOD = 0;
mSamplerDesc[i].MaxLOD = FLT_MAX;
if (FAILED(hr))
{
AssertFatal(false, "GFXD3D11StateBlock::GFXD3D11StateBlock - CreateDepthStencilState call failure.");
}
if(mDesc.samplers[i].magFilter == GFXTextureFilterPoint && mDesc.samplers[i].minFilter == GFXTextureFilterPoint && mDesc.samplers[i].mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterPoint && mDesc.samplers[i].minFilter == GFXTextureFilterPoint && mDesc.samplers[i].mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterLinear && mDesc.samplers[i].minFilter == GFXTextureFilterPoint && mDesc.samplers[i].mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterLinear && mDesc.samplers[i].minFilter == GFXTextureFilterPoint && mDesc.samplers[i].mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterPoint && mDesc.samplers[i].minFilter == GFXTextureFilterLinear && mDesc.samplers[i].mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterPoint && mDesc.samplers[i].minFilter == GFXTextureFilterLinear && mDesc.samplers[i].mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterLinear && mDesc.samplers[i].minFilter == GFXTextureFilterLinear && mDesc.samplers[i].mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterLinear && mDesc.samplers[i].minFilter == GFXTextureFilterLinear && mDesc.samplers[i].mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
else
mSamplerDesc[i].Filter = D3D11_FILTER_ANISOTROPIC;
mSamplerDesc[i].BorderColor[0] = 1.0f;
mSamplerDesc[i].BorderColor[1] = 1.0f;
mSamplerDesc[i].BorderColor[2] = 1.0f;
mSamplerDesc[i].BorderColor[3] = 1.0f;
mSamplerDesc[i].ComparisonFunc = D3D11_COMPARISON_NEVER;
ZeroMemory(&mSamplerDesc, sizeof(D3D11_SAMPLER_DESC) * 16);
hr = D3D11DEVICE->CreateSamplerState(&mSamplerDesc[i], &mSamplerStates[i]);
GFXD3D11Device::SamplerMap &dx11SamplerMap = D3D11->getSamplersMap();
if(FAILED(hr))
{
AssertFatal(false, "GFXD3D11StateBlock::GFXD3D11StateBlock - CreateSamplerState call failure.");
}
}
for (U32 i = 0; i < GFX->getNumSamplers(); i++)
{
GFXSamplerStateDesc &gfxSamplerState = mDesc.samplers[i];
U32 hash = DictHash::hash(gfxSamplerState);
GFXD3D11Device::SamplerMap::Iterator itr = dx11SamplerMap.find(hash);
if (itr == dx11SamplerMap.end())
{
mSamplerDesc[i].AddressU = GFXD3D11TextureAddress[gfxSamplerState.addressModeU];
mSamplerDesc[i].AddressV = GFXD3D11TextureAddress[gfxSamplerState.addressModeV];
mSamplerDesc[i].AddressW = GFXD3D11TextureAddress[gfxSamplerState.addressModeW];
mSamplerDesc[i].MaxAnisotropy = gfxSamplerState.maxAnisotropy;
mSamplerDesc[i].MipLODBias = gfxSamplerState.mipLODBias;
mSamplerDesc[i].MinLOD = 0;
mSamplerDesc[i].MaxLOD = FLT_MAX;
if (gfxSamplerState.magFilter == GFXTextureFilterPoint && gfxSamplerState.minFilter == GFXTextureFilterPoint && gfxSamplerState.mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
else if (gfxSamplerState.magFilter == GFXTextureFilterPoint && gfxSamplerState.minFilter == GFXTextureFilterPoint && gfxSamplerState.mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
else if (gfxSamplerState.magFilter == GFXTextureFilterLinear && gfxSamplerState.minFilter == GFXTextureFilterPoint && gfxSamplerState.mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
else if (gfxSamplerState.magFilter == GFXTextureFilterLinear && gfxSamplerState.minFilter == GFXTextureFilterPoint && gfxSamplerState.mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
else if (gfxSamplerState.magFilter == GFXTextureFilterPoint && gfxSamplerState.minFilter == GFXTextureFilterLinear && gfxSamplerState.mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
else if (gfxSamplerState.magFilter == GFXTextureFilterPoint && gfxSamplerState.minFilter == GFXTextureFilterLinear && gfxSamplerState.mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
else if (gfxSamplerState.magFilter == GFXTextureFilterLinear && gfxSamplerState.minFilter == GFXTextureFilterLinear && gfxSamplerState.mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
else if (gfxSamplerState.magFilter == GFXTextureFilterLinear && gfxSamplerState.minFilter == GFXTextureFilterLinear && mDesc.samplers[i].mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
else
mSamplerDesc[i].Filter = D3D11_FILTER_ANISOTROPIC;
mSamplerDesc[i].BorderColor[0] = 1.0f;
mSamplerDesc[i].BorderColor[1] = 1.0f;
mSamplerDesc[i].BorderColor[2] = 1.0f;
mSamplerDesc[i].BorderColor[3] = 1.0f;
hr = D3D11DEVICE->CreateSamplerState(&mSamplerDesc[i], &mSamplerStates[i]);
if (FAILED(hr))
{
AssertFatal(false, "GFXD3D11StateBlock::GFXD3D11StateBlock - CreateSamplerState call failure.");
}
// add sampler state to the map
dx11SamplerMap.insert(hash, mSamplerStates[i]);
}
else
{
mSamplerStates[i] = itr->value;
}
}
}
GFXD3D11StateBlock::~GFXD3D11StateBlock()
@ -155,10 +197,9 @@ GFXD3D11StateBlock::~GFXD3D11StateBlock()
SAFE_RELEASE(mRasterizerState);
SAFE_RELEASE(mDepthStencilState);
//Use TEXTURE_STAGE_COUNT here, not safe to rely on GFX pointer
for (U32 i = 0; i < TEXTURE_STAGE_COUNT; ++i)
for (U32 i = 0; i < 16; ++i)
{
SAFE_RELEASE(mSamplerStates[i]);
mSamplerStates[i] = NULL;
}
}
@ -171,115 +212,57 @@ U32 GFXD3D11StateBlock::getHashValue() const
/// Returns a GFXStateBlockDesc that this block represents
const GFXStateBlockDesc& GFXD3D11StateBlock::getDesc() const
{
return mDesc;
return mDesc;
}
/// Called by D3D11 device to active this state block.
/// @param oldState The current state, used to make sure we don't set redundant states on the device. Pass NULL to reset all states.
void GFXD3D11StateBlock::activate(GFXD3D11StateBlock* oldState)
{
PROFILE_SCOPE( GFXD3D11StateBlock_Activate );
PROFILE_SCOPE(GFXD3D11StateBlock_Activate);
ID3D11DeviceContext* pDevCxt = D3D11DEVICECONTEXT;
if (!oldState || (mBlendState != oldState->mBlendState))
{
F32 blendFactor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
D3D11DEVICECONTEXT->OMSetBlendState(mBlendState, blendFactor, 0xFFFFFFFF);
}
mBlendDesc.AlphaToCoverageEnable = false;
mBlendDesc.IndependentBlendEnable = mDesc.separateAlphaBlendEnable;
if (!oldState || (mDepthStencilState != oldState->mDepthStencilState))
D3D11DEVICECONTEXT->OMSetDepthStencilState(mDepthStencilState, mDesc.stencilRef);
mBlendDesc.RenderTarget[0].BlendEnable = mDesc.blendEnable;
mBlendDesc.RenderTarget[0].BlendOp = GFXD3D11BlendOp[mDesc.blendOp];
mBlendDesc.RenderTarget[0].BlendOpAlpha = GFXD3D11BlendOp[mDesc.separateAlphaBlendOp];
mBlendDesc.RenderTarget[0].DestBlend = GFXD3D11Blend[mDesc.blendDest];
mBlendDesc.RenderTarget[0].DestBlendAlpha = GFXD3D11Blend[mDesc.separateAlphaBlendDest];
mBlendDesc.RenderTarget[0].SrcBlend = GFXD3D11Blend[mDesc.blendSrc];
mBlendDesc.RenderTarget[0].SrcBlendAlpha = GFXD3D11Blend[mDesc.separateAlphaBlendSrc];
mBlendDesc.RenderTarget[0].RenderTargetWriteMask = mColorMask;
float blendFactor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
pDevCxt->OMSetBlendState(mBlendState, blendFactor, 0xFFFFFFFF);
mDepthStencilDesc.DepthWriteMask = mDesc.zWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
mDepthStencilDesc.DepthEnable = mDesc.zEnable;
mDepthStencilDesc.DepthFunc = GFXD3D11CmpFunc[mDesc.zFunc];
mDepthStencilDesc.StencilWriteMask = mDesc.stencilWriteMask;
mDepthStencilDesc.StencilReadMask = mDesc.stencilMask;
mDepthStencilDesc.StencilEnable = mDesc.stencilEnable;
mDepthStencilDesc.FrontFace.StencilFunc = GFXD3D11CmpFunc[mDesc.stencilFunc];
mDepthStencilDesc.FrontFace.StencilFailOp = GFXD3D11StencilOp[mDesc.stencilFailOp];
mDepthStencilDesc.FrontFace.StencilDepthFailOp = GFXD3D11StencilOp[mDesc.stencilZFailOp];
mDepthStencilDesc.FrontFace.StencilPassOp = GFXD3D11StencilOp[mDesc.stencilPassOp];
if (mDesc.stencilEnable)
mDepthStencilDesc.BackFace = mDepthStencilDesc.FrontFace;
else
{
mDepthStencilDesc.BackFace.StencilFunc = GFXD3D11CmpFunc[GFXCmpAlways];
mDepthStencilDesc.BackFace.StencilFailOp = GFXD3D11StencilOp[GFXStencilOpKeep];
mDepthStencilDesc.BackFace.StencilDepthFailOp = GFXD3D11StencilOp[GFXStencilOpKeep];
mDepthStencilDesc.BackFace.StencilPassOp = GFXD3D11StencilOp[GFXStencilOpKeep];
}
pDevCxt->OMSetDepthStencilState(mDepthStencilState, mDesc.stencilRef);
mRasterizerDesc.CullMode = GFXD3D11CullMode[mDesc.cullMode];
mRasterizerDesc.FillMode = GFXD3D11FillMode[mDesc.fillMode];
mRasterizerDesc.DepthBias = mDesc.zBias;
mRasterizerDesc.SlopeScaledDepthBias = mDesc.zSlopeBias;
mRasterizerDesc.AntialiasedLineEnable = FALSE;
mRasterizerDesc.MultisampleEnable = FALSE;
mRasterizerDesc.ScissorEnable = FALSE;
if (mDesc.zEnable)
mRasterizerDesc.DepthClipEnable = true;
else
mRasterizerDesc.DepthClipEnable = false;
mRasterizerDesc.FrontCounterClockwise = FALSE;
mRasterizerDesc.DepthBiasClamp = 0.0f;
pDevCxt->RSSetState(mRasterizerState);
if (!oldState || (mRasterizerState != oldState->mRasterizerState))
D3D11DEVICECONTEXT->RSSetState(mRasterizerState);
U32 numSamplersChanged = 0;
U32 numSamplers = GFX->getNumSamplers();
for (U32 i = 0; i < numSamplers; i++)
{
mSamplerDesc[i].AddressU = GFXD3D11TextureAddress[mDesc.samplers[i].addressModeU];
mSamplerDesc[i].AddressV = GFXD3D11TextureAddress[mDesc.samplers[i].addressModeV];
mSamplerDesc[i].AddressW = GFXD3D11TextureAddress[mDesc.samplers[i].addressModeW];
mSamplerDesc[i].MaxAnisotropy = mDesc.samplers[i].maxAnisotropy;
U32 samplerUpdateStartSlot = 0;
mSamplerDesc[i].MipLODBias = mDesc.samplers[i].mipLODBias;
mSamplerDesc[i].MinLOD = 0;
mSamplerDesc[i].MaxLOD = FLT_MAX;
if(mDesc.samplers[i].magFilter == GFXTextureFilterPoint && mDesc.samplers[i].minFilter == GFXTextureFilterPoint && mDesc.samplers[i].mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterPoint && mDesc.samplers[i].minFilter == GFXTextureFilterPoint && mDesc.samplers[i].mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterLinear && mDesc.samplers[i].minFilter == GFXTextureFilterPoint && mDesc.samplers[i].mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterLinear && mDesc.samplers[i].minFilter == GFXTextureFilterPoint && mDesc.samplers[i].mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterPoint && mDesc.samplers[i].minFilter == GFXTextureFilterLinear && mDesc.samplers[i].mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterPoint && mDesc.samplers[i].minFilter == GFXTextureFilterLinear && mDesc.samplers[i].mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterLinear && mDesc.samplers[i].minFilter == GFXTextureFilterLinear && mDesc.samplers[i].mipFilter == GFXTextureFilterPoint)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
else if(mDesc.samplers[i].magFilter == GFXTextureFilterLinear && mDesc.samplers[i].minFilter == GFXTextureFilterLinear && mDesc.samplers[i].mipFilter == GFXTextureFilterLinear)
mSamplerDesc[i].Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
else
mSamplerDesc[i].Filter = D3D11_FILTER_ANISOTROPIC;
//figure out which range of samplers changed.
for (U32 samplerSlot = 0; samplerSlot < numSamplers; samplerSlot++)
{
if (oldState && (oldState->mSamplerStates[samplerSlot] == mSamplerStates[samplerSlot]))
{
//only change the update start slot when there hasn't been any samplers changed so far
if (numSamplersChanged == 0) {
samplerUpdateStartSlot++;
}
continue;
}
numSamplersChanged = (samplerSlot - samplerUpdateStartSlot) + 1;
}
mSamplerDesc[i].BorderColor[0] = 0.0f;
mSamplerDesc[i].BorderColor[1] = 0.0f;
mSamplerDesc[i].BorderColor[2] = 0.0f;
mSamplerDesc[i].BorderColor[3] = 0.0f;
mSamplerDesc[i].ComparisonFunc = D3D11_COMPARISON_NEVER;
}
//TODO samplers for vertex shader
// Set all the samplers with one call
//pDevCxt->VSSetSamplers(0, numSamplers, &mSamplerStates[0]);
pDevCxt->PSSetSamplers(0, numSamplers, &mSamplerStates[0]);
//D3D11DEVICECONTEXT->VSSetSamplers(0, numSamplers, &mSamplerStates[0]);
if (numSamplersChanged > 0)
D3D11DEVICECONTEXT->PSSetSamplers(samplerUpdateStartSlot, numSamplersChanged, &mSamplerStates[samplerUpdateStartSlot]);
}

View file

@ -26,6 +26,11 @@
#include "gfx/D3D11/gfxD3D11Device.h"
#include "gfx/gfxStateBlock.h"
namespace DictHash
{
U32 hash(const GFXSamplerStateDesc &data);
}
class GFXD3D11StateBlock : public GFXStateBlock
{
public:

View file

@ -314,21 +314,34 @@ void GFXD3D11TextureTarget::resurrect()
GFXD3D11WindowTarget::GFXD3D11WindowTarget()
{
mWindow = NULL;
mBackbuffer = NULL;
mWindow = NULL;
mBackBuffer = NULL;
mDepthStencilView = NULL;
mDepthStencil = NULL;
mBackBufferView = NULL;
mSecondaryWindow = false;
}
GFXD3D11WindowTarget::~GFXD3D11WindowTarget()
{
SAFE_RELEASE(mBackbuffer);
SAFE_RELEASE(mDepthStencilView)
SAFE_RELEASE(mDepthStencil);
SAFE_RELEASE(mBackBufferView);
SAFE_RELEASE(mBackBuffer);
SAFE_RELEASE(mSwapChain);
}
void GFXD3D11WindowTarget::initPresentationParams()
{
// Get some video mode related info.
GFXVideoMode vm = mWindow->getVideoMode();
Win32Window* win = static_cast<Win32Window*>(mWindow);
HWND hwnd = win->getHWND();
const GFXVideoMode &vm = mWindow->getVideoMode();
HWND hwnd = (HWND)mWindow->getSystemWindow(PlatformWindow::WindowSystem_Windows);
// Do some validation...
if (vm.fullScreen && mSecondaryWindow)
{
AssertFatal(false, "GFXD3D11WindowTarget::initPresentationParams - Cannot go fullscreen with secondary window!");
}
mPresentationParams = D3D11->setupPresentParams(vm, hwnd);
}
@ -347,40 +360,178 @@ GFXFormat GFXD3D11WindowTarget::getFormat()
bool GFXD3D11WindowTarget::present()
{
return (D3D11->getSwapChain()->Present(!D3D11->smDisableVSync, 0) == S_OK);
return (mSwapChain->Present(!D3D11->smDisableVSync, 0) == S_OK);
}
void GFXD3D11WindowTarget::setImplicitSwapChain()
void GFXD3D11WindowTarget::createSwapChain()
{
if (!mBackbuffer)
D3D11->mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackbuffer);
//create dxgi factory & swapchain
IDXGIFactory1* DXGIFactory;
HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&DXGIFactory));
if (FAILED(hr))
AssertFatal(false, "GFXD3D11WindowTarget::createSwapChain - couldn't create dxgi factory.");
hr = DXGIFactory->CreateSwapChain(D3D11DEVICE, &mPresentationParams, &mSwapChain);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11WindowTarget::createSwapChain - couldn't create swap chain.");
SAFE_RELEASE(DXGIFactory);
}
void GFXD3D11WindowTarget::createBuffersAndViews()
{
//release old if they exist
SAFE_RELEASE(mDepthStencilView);
SAFE_RELEASE(mDepthStencil);
SAFE_RELEASE(mBackBufferView);
SAFE_RELEASE(mBackBuffer);
//grab video mode
const GFXVideoMode &vm = mWindow->getVideoMode();
//create depth/stencil
D3D11_TEXTURE2D_DESC desc;
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
desc.CPUAccessFlags = 0;
desc.Format = GFXD3D11TextureFormat[GFXFormatD24S8];
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.Width = vm.resolution.x;
desc.Height = vm.resolution.y;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.MiscFlags = 0;
HRESULT hr = D3D11DEVICE->CreateTexture2D(&desc, NULL, &mDepthStencil);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11WindowTarget::createBuffersAndViews - couldn't create device's depth-stencil surface.");
D3D11_DEPTH_STENCIL_VIEW_DESC depthDesc;
depthDesc.Format = GFXD3D11TextureFormat[GFXFormatD24S8];
depthDesc.Flags = 0;
depthDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthDesc.Texture2D.MipSlice = 0;
hr = D3D11DEVICE->CreateDepthStencilView(mDepthStencil, &depthDesc, &mDepthStencilView);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11WindowTarget::createBuffersAndViews - couldn't create depth stencil view");
setBackBuffer();
//create back buffer view
D3D11_RENDER_TARGET_VIEW_DESC RTDesc;
RTDesc.Format = GFXD3D11TextureFormat[GFXFormatR8G8B8A8];
RTDesc.Texture2D.MipSlice = 0;
RTDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
hr = D3D11DEVICE->CreateRenderTargetView(mBackBuffer, &RTDesc, &mBackBufferView);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11WindowTarget::createBuffersAndViews - couldn't create back buffer target view");
//debug names
#ifdef TORQUE_DEBUG
if (!mSecondaryWindow)
{
String backBufferName = "MainBackBuffer";
String depthSteniclName = "MainDepthStencil";
String backBuffViewName = "MainBackBuffView";
String depthStencViewName = "MainDepthView";
mBackBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, backBufferName.size(), backBufferName.c_str());
mDepthStencil->SetPrivateData(WKPDID_D3DDebugObjectName, depthSteniclName.size(), depthSteniclName.c_str());
mDepthStencilView->SetPrivateData(WKPDID_D3DDebugObjectName, depthStencViewName.size(), depthStencViewName.c_str());
mBackBufferView->SetPrivateData(WKPDID_D3DDebugObjectName, backBuffViewName.size(), backBuffViewName.c_str());
}
#endif
}
void GFXD3D11WindowTarget::resetMode()
{
HRESULT hr;
if (mSwapChain)
{
// The current video settings.
DXGI_SWAP_CHAIN_DESC desc;
hr = mSwapChain->GetDesc(&desc);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11WindowTarget::resetMode - failed to get swap chain description!");
bool fullscreen = !desc.Windowed;
Point2I backbufferSize(desc.BufferDesc.Width, desc.BufferDesc.Height);
// The settings we are now applying.
const GFXVideoMode &vm = mWindow->getVideoMode();
// Early out if none of the settings which require a device reset
// have changed.
if (backbufferSize == vm.resolution &&
fullscreen == vm.fullScreen)
return;
}
//release old buffers and views
SAFE_RELEASE(mDepthStencilView)
SAFE_RELEASE(mDepthStencil);
SAFE_RELEASE(mBackBufferView);
SAFE_RELEASE(mBackBuffer);
if(!mSecondaryWindow)
D3D11->beginReset();
mWindow->setSuppressReset(true);
// Setup our presentation params.
initPresentationParams();
// Otherwise, we have to reset the device, if we're the implicit swapchain.
D3D11->reset(mPresentationParams);
if (!mPresentationParams.Windowed)
{
mPresentationParams.BufferDesc.RefreshRate.Numerator = 0;
mPresentationParams.BufferDesc.RefreshRate.Denominator = 0;
hr = mSwapChain->ResizeTarget(&mPresentationParams.BufferDesc);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11WindowTarget::resetMode - failed to resize target!");
}
hr = mSwapChain->ResizeBuffers(mPresentationParams.BufferCount, mPresentationParams.BufferDesc.Width, mPresentationParams.BufferDesc.Height,
mPresentationParams.BufferDesc.Format, mPresentationParams.Windowed ? 0 : DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11WindowTarget::resetMode - failed to resize back buffer!");
hr = mSwapChain->SetFullscreenState(!mPresentationParams.Windowed, NULL);
if (FAILED(hr))
AssertFatal(false, "GFXD3D11WindowTarget::resetMode - failed to change screen states!");
// Update our size, too.
mSize = Point2I(mPresentationParams.BufferDesc.Width, mPresentationParams.BufferDesc.Height);
mWindow->setSuppressReset(false);
GFX->beginReset();
//re-create buffers and views
createBuffersAndViews();
if (!mSecondaryWindow)
D3D11->endReset(this);
}
void GFXD3D11WindowTarget::zombify()
{
SAFE_RELEASE(mBackbuffer);
SAFE_RELEASE(mBackBuffer);
}
void GFXD3D11WindowTarget::resurrect()
{
setImplicitSwapChain();
setBackBuffer();
}
void GFXD3D11WindowTarget::setBackBuffer()
{
if (!mBackBuffer)
mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBuffer);
}
void GFXD3D11WindowTarget::activate()
@ -391,10 +542,10 @@ void GFXD3D11WindowTarget::activate()
ID3D11RenderTargetView* rtViews[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
D3D11DEVICECONTEXT->OMSetRenderTargets(8, rtViews, NULL);
D3D11DEVICECONTEXT->OMSetRenderTargets(1, &D3D11->mDeviceBackBufferView, D3D11->mDeviceDepthStencilView);
D3D11DEVICECONTEXT->OMSetRenderTargets(1, &mBackBufferView, mDepthStencilView);
DXGI_SWAP_CHAIN_DESC pp;
D3D11->mSwapChain->GetDesc(&pp);
mSwapChain->GetDesc(&pp);
// Update our video mode here, too.
GFXVideoMode vm;
@ -412,5 +563,35 @@ void GFXD3D11WindowTarget::resolveTo(GFXTextureObject *tex)
D3D11_TEXTURE2D_DESC desc;
ID3D11Texture2D* surf = ((GFXD3D11TextureObject*)(tex))->get2DTex();
surf->GetDesc(&desc);
D3D11DEVICECONTEXT->ResolveSubresource(surf, 0, D3D11->mDeviceBackbuffer, 0, desc.Format);
D3D11DEVICECONTEXT->ResolveSubresource(surf, 0, mBackBuffer, 0, desc.Format);
}
IDXGISwapChain *GFXD3D11WindowTarget::getSwapChain()
{
mSwapChain->AddRef();
return mSwapChain;
}
ID3D11Texture2D *GFXD3D11WindowTarget::getBackBuffer()
{
mBackBuffer->AddRef();
return mBackBuffer;
}
ID3D11Texture2D *GFXD3D11WindowTarget::getDepthStencil()
{
mDepthStencil->AddRef();
return mDepthStencil;
}
ID3D11RenderTargetView* GFXD3D11WindowTarget::getBackBufferView()
{
mBackBufferView->AddRef();
return mBackBufferView;
}
ID3D11DepthStencilView* GFXD3D11WindowTarget::getDepthStencilView()
{
mDepthStencilView->AddRef();
return mDepthStencilView;
}

View file

@ -76,17 +76,22 @@ class GFXD3D11WindowTarget : public GFXWindowTarget
friend class GFXD3D11Device;
/// Our backbuffer
ID3D11Texture2D *mBackbuffer;
ID3D11Texture2D *mBackBuffer;
ID3D11Texture2D *mDepthStencil;
ID3D11RenderTargetView* mBackBufferView;
ID3D11DepthStencilView* mDepthStencilView;
IDXGISwapChain *mSwapChain;
/// Maximum size we can render to.
Point2I mSize;
/// D3D presentation info.
DXGI_SWAP_CHAIN_DESC mPresentationParams;
/// Internal interface that notifies us we need to reset our video mode.
void resetMode();
/// Is this a secondary window
bool mSecondaryWindow;
public:
GFXD3D11WindowTarget();
@ -97,7 +102,9 @@ public:
virtual bool present();
void initPresentationParams();
void setImplicitSwapChain();
void createSwapChain();
void createBuffersAndViews();
void setBackBuffer();
virtual void activate();
@ -105,6 +112,13 @@ public:
void resurrect();
virtual void resolveTo( GFXTextureObject *tex );
// These are all reference counted and must be released by whomever uses the get* function
IDXGISwapChain *getSwapChain();
ID3D11Texture2D *getBackBuffer();
ID3D11Texture2D *getDepthStencil();
ID3D11RenderTargetView* getBackBufferView();
ID3D11DepthStencilView* getDepthStencilView();
};
#endif

View file

@ -327,7 +327,10 @@ void GBitmap::allocateBitmap(const U32 in_width, const U32 in_height, const bool
mNumMipLevels++;
allocPixels += currWidth * currHeight * mBytesPerPixel;
} while (currWidth != 1 && currHeight != 1);
} while (currWidth != 1 || currHeight != 1);
U32 expectedMips = mFloor(mLog2(mMax(in_width, in_height))) + 1;
AssertFatal(mNumMipLevels == expectedMips, "GBitmap::allocateBitmap: mipmap count wrong");
}
AssertFatal(mNumMipLevels <= c_maxMipLevels, "GBitmap::allocateBitmap: too many miplevels");

View file

@ -178,7 +178,7 @@ void GFXShader::_unlinkBuffer( GFXShaderConstBuffer *buf )
DefineEngineFunction( addGlobalShaderMacro, void,
( const char *name, const char *value ), ( NULL ),
( const char *name, const char *value ), ( nullAsType<const char*>() ),
"Adds a global shader macro which will be merged with the script defined "
"macros on every shader. The macro will replace the value of an existing "
"macro of the same name. For the new macro to take effect all the shaders "

View file

@ -1085,21 +1085,7 @@ void GFXTextureManager::_validateTexParams( const U32 width, const U32 height,
// NOTE: Does this belong here?
if( inOutNumMips == 0 && !autoGenSupp )
{
U32 currWidth = width;
U32 currHeight = height;
inOutNumMips = 1;
do
{
currWidth >>= 1;
currHeight >>= 1;
if( currWidth == 0 )
currWidth = 1;
if( currHeight == 0 )
currHeight = 1;
inOutNumMips++;
} while ( currWidth != 1 && currHeight != 1 );
inOutNumMips = mFloor(mLog2(mMax(width, height))) + 1;
}
}
}

View file

@ -172,12 +172,21 @@ void GFXGLDevice::initGLState()
PlatformGL::setVSync(smDisableVSync ? 0 : 1);
//install vsync callback
Con::NotifyDelegate clbk(this, &GFXGLDevice::vsyncCallback);
Con::addVariableNotify("$pref::Video::disableVerticalSync", clbk);
//OpenGL 3 need a binded VAO for render
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
}
void GFXGLDevice::vsyncCallback()
{
PlatformGL::setVSync(smDisableVSync ? 0 : 1);
}
GFXGLDevice::GFXGLDevice(U32 adapterIndex) :
mAdapterIndex(adapterIndex),
mNeedUpdateVertexAttrib(false),

View file

@ -256,6 +256,8 @@ private:
GFXVertexBuffer* findVolatileVBO(U32 numVerts, const GFXVertexFormat *vertexFormat, U32 vertSize); ///< Returns an existing volatile VB which has >= numVerts and the same vert flags/size, or creates a new VB if necessary
GFXPrimitiveBuffer* findVolatilePBO(U32 numIndices, U32 numPrimitives); ///< Returns an existing volatile PB which has >= numIndices, or creates a new PB if necessary
void vsyncCallback(); ///< Vsync callback
void initGLState(); ///< Guaranteed to be called after all extensions have been loaded, use to init card profiler, shader version, max samplers, etc.

View file

@ -40,32 +40,32 @@ GFXGLStateBlock::GFXGLStateBlock(const GFXStateBlockDesc& desc) :
mCachedHashValue(desc.getHashValue())
{
if( !GFXGL->mCapabilities.samplerObjects )
return;
return;
static Map<GFXSamplerStateDesc, U32> mSamplersMap;
for(int i = 0; i < TEXTURE_STAGE_COUNT; ++i)
{
GLuint &id = mSamplerObjects[i];
GFXSamplerStateDesc &ssd = mDesc.samplers[i];
for(int i = 0; i < TEXTURE_STAGE_COUNT; ++i)
{
GLuint &id = mSamplerObjects[i];
GFXSamplerStateDesc &ssd = mDesc.samplers[i];
Map<GFXSamplerStateDesc, U32>::Iterator itr = mSamplersMap.find(ssd);
if(itr == mSamplersMap.end())
{
glGenSamplers(1, &id);
glGenSamplers(1, &id);
glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, minificationFilter(ssd.minFilter, ssd.mipFilter, 1) );
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GFXGLTextureFilter[ssd.magFilter]);
glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GFXGLTextureAddress[ssd.addressModeU]);
glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GFXGLTextureAddress[ssd.addressModeV]);
glSamplerParameteri(id, GL_TEXTURE_WRAP_R, GFXGLTextureAddress[ssd.addressModeW]);
if(static_cast< GFXGLDevice* >( GFX )->supportsAnisotropic() )
glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, ssd.maxAnisotropy);
glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, minificationFilter(ssd.minFilter, ssd.mipFilter, 1) );
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GFXGLTextureFilter[ssd.magFilter]);
glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GFXGLTextureAddress[ssd.addressModeU]);
glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GFXGLTextureAddress[ssd.addressModeV]);
glSamplerParameteri(id, GL_TEXTURE_WRAP_R, GFXGLTextureAddress[ssd.addressModeW]);
if(static_cast< GFXGLDevice* >( GFX )->supportsAnisotropic() )
glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, ssd.maxAnisotropy);
mSamplersMap[ssd] = id;
}
else
id = itr->value;
}
}
}
GFXGLStateBlock::~GFXGLStateBlock()
@ -99,7 +99,7 @@ void GFXGLStateBlock::activate(const GFXGLStateBlock* oldState)
#define STATE_CHANGE(state) (!oldState || oldState->mDesc.state != mDesc.state)
#define TOGGLE_STATE(state, enum) if(mDesc.state) glEnable(enum); else glDisable(enum)
#define CHECK_TOGGLE_STATE(state, enum) if(!oldState || oldState->mDesc.state != mDesc.state) if(mDesc.state) glEnable(enum); else glDisable(enum)
#define CHECK_TOGGLE_STATE(state, enum) if(!oldState || oldState->mDesc.state != mDesc.state) {if(mDesc.state) glEnable(enum); else glDisable(enum);}
// Blending
CHECK_TOGGLE_STATE(blendEnable, GL_BLEND);
@ -171,9 +171,9 @@ void GFXGLStateBlock::activate(const GFXGLStateBlock* oldState)
for (U32 i = 0; i < getMin(getOwningDevice()->getNumSamplers(), (U32) TEXTURE_STAGE_COUNT); i++)
{
if(!oldState || oldState->mSamplerObjects[i] != mSamplerObjects[i])
glBindSampler(i, mSamplerObjects[i] );
glBindSampler(i, mSamplerObjects[i] );
}
}
}
// TODO: states added for detail blend
}

View file

@ -316,7 +316,7 @@ bool GFXGLTextureManager::_loadTexture(GFXTextureObject *aTexture, DDSFile *dds)
if(isCompressedFormat(dds->mFormat))
{
if((!isPow2(dds->getWidth()) || !isPow2(dds->getHeight())) && GFX->getCardProfiler()->queryProfile("GL::Workaround::noCompressedNPoTTextures"))
if((!isPow2(dds->getWidth()) || !isPow2(dds->getHeight())))
{
U32 squishFlag = squish::kDxt1;
switch (dds->mFormat)

View file

@ -37,7 +37,7 @@ GFX_ImplementTextureProfile( BackBufferDepthProfile,
GFXGLWindowTarget::GFXGLWindowTarget(PlatformWindow *win, GFXDevice *d)
: GFXWindowTarget(win), mDevice(d), mContext(NULL), mFullscreenContext(NULL)
, mCopyFBO(0), mBackBufferFBO(0)
, mCopyFBO(0), mBackBufferFBO(0), mSecondaryWindow(false)
{
win->appEvent.notify(this, &GFXGLWindowTarget::_onAppSignal);
}
@ -52,7 +52,14 @@ GFXGLWindowTarget::~GFXGLWindowTarget()
void GFXGLWindowTarget::resetMode()
{
if(mWindow->getVideoMode().fullScreen != mWindow->isFullscreen())
// Do some validation...
bool fullscreen = mWindow->getVideoMode().fullScreen;
if (fullscreen && mSecondaryWindow)
{
AssertFatal(false, "GFXGLWindowTarget::resetMode - Cannot go fullscreen with secondary window!");
}
if(fullscreen != mWindow->isFullscreen())
{
_teardownCurrentMode();
_setupNewMode();

View file

@ -50,6 +50,9 @@ public:
virtual void resolveTo(GFXTextureObject* obj);
void _onAppSignal(WindowId wnd, S32 event);
// create pixel format for the window
void createPixelFormat();
private:
friend class GFXGLDevice;
@ -58,6 +61,8 @@ private:
GFXTexHandle mBackBufferColorTex, mBackBufferDepthTex;
Point2I size;
GFXDevice* mDevice;
/// Is this a secondary window
bool mSecondaryWindow;
void* mContext;
void* mFullscreenContext;
void _teardownCurrentMode();
@ -66,6 +71,7 @@ private:
void _WindowPresent();
//set this windows context to be current
void _makeContextCurrent();
};
#endif

View file

@ -191,19 +191,21 @@ U32 GFXGLDevice::getTotalVideoMemory()
GFXWindowTarget *GFXGLDevice::allocWindowTarget( PlatformWindow *window )
{
AssertFatal(!mContext, "This GFXGLDevice is already assigned to a window");
GFXGLWindowTarget* ggwt = 0;
if( !mContext )
{
// no context, init the device now
init(window->getVideoMode(), window);
ggwt = new GFXGLWindowTarget(window, this);
ggwt->registerResourceWithDevice(this);
ggwt->mContext = mContext;
}
GFXGLWindowTarget* ggwt = new GFXGLWindowTarget(window, this);
return ggwt;
//first window
if (!mContext)
{
init(window->getVideoMode(), window);
ggwt->mSecondaryWindow = false;
}
else
ggwt->mSecondaryWindow = true;
ggwt->registerResourceWithDevice(this);
ggwt->mContext = mContext;
return ggwt;
}
GFXFence* GFXGLDevice::_createPlatformSpecificFence()

View file

@ -41,7 +41,12 @@ namespace GL
void gglPerformExtensionBinds(void *context)
{
#ifdef TORQUE_OS_WIN
if (!gladLoadWGL(wglGetCurrentDC()))
{
AssertFatal(false, "Unable to load GLAD WGL extensions. Make sure your OpenGL drivers are up to date!");
}
#endif
}
}

View file

@ -30,7 +30,7 @@
#include "tGL.h"
#include <glad/glad_wgl.h>
#define gglHasWExtension(window, EXTENSION) GLAD_WGL_##EXTENSION
#define gglHasWExtension(EXTENSION) GLAD_WGL_##EXTENSION
#endif //TORQUE_OPENGL

View file

@ -255,14 +255,6 @@ void GFXGLDevice::init( const GFXVideoMode &mode, PlatformWindow *window )
HDC hdcGL = GetDC( hwnd );
AssertFatal( hdcGL != NULL, "Failed to create device context" );
// Create pixel format descriptor...
PIXELFORMATDESCRIPTOR pfd;
CreatePixelFormat( &pfd, 32, 0, 0, false ); // 32 bit color... We do not need depth or stencil, OpenGL renders into a FBO and then copy the image to window
if( !SetPixelFormat( hdcGL, ChoosePixelFormat( hdcGL, &pfd ), &pfd ) )
{
AssertFatal( false, "GFXGLDevice::init - cannot get the one and only pixel format we check for." );
}
int OGL_MAJOR = 3;
int OGL_MINOR = 2;
@ -277,7 +269,7 @@ void GFXGLDevice::init( const GFXVideoMode &mode, PlatformWindow *window )
if (!wglMakeCurrent(hdcGL, tempGLRC))
AssertFatal(false, "Couldn't make temp GL context.");
if( gglHasWExtension(hdcGL, ARB_create_context) )
if( gglHasWExtension( ARB_create_context) )
{
int const create_attribs[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, OGL_MAJOR,
@ -330,13 +322,21 @@ U32 GFXGLDevice::getTotalVideoMemory()
//------------------------------------------------------------------------------
GFXWindowTarget *GFXGLDevice::allocWindowTarget( PlatformWindow *window )
GFXWindowTarget *GFXGLDevice::allocWindowTarget(PlatformWindow *window)
{
AssertFatal(!mContext, "");
init(window->getVideoMode(), window);
GFXGLWindowTarget *ggwt = new GFXGLWindowTarget(window, this);
ggwt->registerResourceWithDevice(this);
ggwt->createPixelFormat();
//first window
if (!mContext)
{
init(window->getVideoMode(), window);
ggwt->mSecondaryWindow = false;
}
else
ggwt->mSecondaryWindow = true;
ggwt->mContext = mContext;
AssertFatal(ggwt->mContext, "GFXGLDevice::allocWindowTarget - failed to allocate window target!");
@ -364,15 +364,32 @@ void GFXGLWindowTarget::_setupNewMode()
{
}
void GFXGLWindowTarget::createPixelFormat()
{
HWND hwnd = GETHWND(mWindow);
// Create a device context
HDC hdcGL = GetDC(hwnd);
AssertFatal(hdcGL != NULL, "GFXGLWindowTarget::createPixelFormat() - Failed to create device context");
// Create pixel format descriptor...
PIXELFORMATDESCRIPTOR pfd;
CreatePixelFormat(&pfd, 32, 0, 0, false); // 32 bit color... We do not need depth or stencil, OpenGL renders into a FBO and then copy the image to window
if (!SetPixelFormat(hdcGL, ChoosePixelFormat(hdcGL, &pfd), &pfd))
{
AssertFatal(false, "GFXGLWindowTarget::createPixelFormat() - cannot get the one and only pixel format we check for.");
}
}
void GFXGLWindowTarget::_makeContextCurrent()
{
HWND hwnd = GETHWND(getWindow());
HDC hdc = GetDC(hwnd);
if (!wglMakeCurrent(hdc, (HGLRC)mContext))
{
//HRESULT if needed for debug
//HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
AssertFatal(false, "GFXGLWindowTarget::_makeContextCurrent() - cannot make our context current.");
}
}
}

View file

@ -314,6 +314,9 @@ DefineEngineFunction( startVideoCapture, void,
"@see stopVideoCapture\n"
"@ingroup Rendering\n" )
{
#ifdef TORQUE_DEBUG
Con::errorf("Recording video is disabled in debug!");
#else
if ( !canvas )
{
Con::errorf("startVideoCapture -Please specify a GuiCanvas object to record from!");
@ -328,6 +331,7 @@ DefineEngineFunction( startVideoCapture, void,
VIDCAP->setResolution(resolution);
VIDCAP->begin(canvas);
#endif
}
DefineEngineFunction( stopVideoCapture, void, (),,
@ -340,7 +344,7 @@ DefineEngineFunction( stopVideoCapture, void, (),,
DefineEngineFunction( playJournalToVideo, void,
( const char *journalFile, const char *videoFile, const char *encoder, F32 framerate, Point2I resolution ),
( NULL, "THEORA", 30.0f, Point2I::Zero ),
( nullAsType<const char*>(), "THEORA", 30.0f, Point2I::Zero ),
"Load a journal file and capture it video.\n"
"@ingroup Rendering\n" )
{
@ -357,4 +361,4 @@ DefineEngineFunction( playJournalToVideo, void,
VIDCAP->waitForCanvas();
Journal::Play( journalFile );
}
}