diff --git a/Engine/source/app/net/serverQuery.cpp b/Engine/source/app/net/serverQuery.cpp index 10b4c3ec5..a74117cfd 100644 --- a/Engine/source/app/net/serverQuery.cpp +++ b/Engine/source/app/net/serverQuery.cpp @@ -2113,12 +2113,6 @@ static void handleGameInfoResponse( const NetAddress* address, BitStream* stream return; } - if ( sActiveFilter.filterFlags & ServerFilter::NotXenon && si->isXenon() ) - { - Con::printf( "Server %s filtered out by no-xenon flag.", addrString ); - removeServerInfo( address ); - return; - } } si->status.set( ServerInfo::Status_Responded ); diff --git a/Engine/source/app/net/serverQuery.h b/Engine/source/app/net/serverQuery.h index 37d33b72e..bfa5b7381 100644 --- a/Engine/source/app/net/serverQuery.h +++ b/Engine/source/app/net/serverQuery.h @@ -43,7 +43,6 @@ struct ServerInfo Status_Dedicated = BIT(0), Status_Passworded = BIT(1), Status_Linux = BIT(2), - Status_Xenon = BIT(6), // Status flags: Status_New = 0, @@ -97,7 +96,7 @@ struct ServerInfo bool isDedicated() { return( status.test( Status_Dedicated ) ); } bool isPassworded() { return( status.test( Status_Passworded ) ); } bool isLinux() { return( status.test( Status_Linux ) ); } - bool isXenon() { return( status.test( Status_Xenon ) ); } + }; diff --git a/Engine/source/gfx/D3D11/gfxD3D11CardProfiler.cpp b/Engine/source/gfx/D3D11/gfxD3D11CardProfiler.cpp index cb843d353..14c37c63a 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11CardProfiler.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11CardProfiler.cpp @@ -47,27 +47,12 @@ void GFXD3D11CardProfiler::init() mCardDescription = adapter.description; mChipSet = adapter.chipSet; - mVersionString = _getFeatureLevelStr(); + mVersionString = adapter.driverVersion; 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); diff --git a/Engine/source/gfx/D3D11/gfxD3D11CardProfiler.h b/Engine/source/gfx/D3D11/gfxD3D11CardProfiler.h index 4a7ea9645..c26432928 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11CardProfiler.h +++ b/Engine/source/gfx/D3D11/gfxD3D11CardProfiler.h @@ -41,7 +41,6 @@ protected: void setupCardCapabilities(); bool _queryCardCap(const String &query, U32 &foundResult); bool _queryFormat(const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips); - String _getFeatureLevelStr(); }; #endif diff --git a/Engine/source/gfx/D3D11/gfxD3D11Device.cpp b/Engine/source/gfx/D3D11/gfxD3D11Device.cpp index 16440eb64..ba6b72523 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Device.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11Device.cpp @@ -37,7 +37,6 @@ #include "windowManager/platformWindow.h" #include "gfx/D3D11/screenshotD3D11.h" #include "materials/shaderData.h" -#include //ok now stressing out folks, this is just for debug events(D3DPER) :) #ifdef TORQUE_DEBUG #include "d3d11sdklayers.h" @@ -89,6 +88,7 @@ GFXD3D11Device::GFXD3D11Device(U32 index) mAdapterIndex = index; mD3DDevice = NULL; + mUserAnnotation = NULL; mVolatileVB = NULL; mCurrentPB = NULL; @@ -161,6 +161,7 @@ GFXD3D11Device::~GFXD3D11Device() SAFE_RELEASE(mDeviceBackBufferView); SAFE_RELEASE(mDeviceDepthStencil); SAFE_RELEASE(mDeviceBackbuffer); + SAFE_RELEASE(mUserAnnotation); SAFE_RELEASE(mD3DDeviceContext); SAFE_DELETE(mCardProfiler); @@ -1685,30 +1686,32 @@ GFXCubemap * GFXD3D11Device::createCubemap() return cube; } +// Debug events //------------------------------------------------------------------------------ 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); + if (mUserAnnotation) + { + WCHAR eventName[260]; + MultiByteToWideChar(CP_ACP, 0, name, -1, eventName, 260); + mUserAnnotation->BeginEvent(eventName); + } } //------------------------------------------------------------------------------ void GFXD3D11Device::leaveDebugEvent() { - D3DPERF_EndEvent(); + if (mUserAnnotation) + mUserAnnotation->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); + if (mUserAnnotation) + { + WCHAR eventName[260]; + MultiByteToWideChar(CP_ACP, 0, name, -1, eventName, 260); + mUserAnnotation->SetMarker(eventName); + } } \ No newline at end of file diff --git a/Engine/source/gfx/D3D11/gfxD3D11Device.h b/Engine/source/gfx/D3D11/gfxD3D11Device.h index 2936ac2af..07f1162fb 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Device.h +++ b/Engine/source/gfx/D3D11/gfxD3D11Device.h @@ -23,7 +23,7 @@ #ifndef _GFXD3D11DEVICE_H_ #define _GFXD3D11DEVICE_H_ -#include +#include #include "platform/tmm_off.h" #include "platformWin32/platformWin32.h" @@ -126,6 +126,7 @@ protected: IDXGISwapChain *mSwapChain; ID3D11Device* mD3DDevice; ID3D11DeviceContext* mD3DDeviceContext; + ID3DUserDefinedAnnotation* mUserAnnotation; GFXShader* mCurrentShader; GFXShaderRef mGenericShader[GS_COUNT]; diff --git a/Engine/source/gfx/D3D11/gfxD3D11OcclusionQuery.cpp b/Engine/source/gfx/D3D11/gfxD3D11OcclusionQuery.cpp index 6df92c68a..91ad042de 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11OcclusionQuery.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11OcclusionQuery.cpp @@ -166,7 +166,7 @@ void GFXD3D11OcclusionQuery::resurrect() HRESULT hRes = D3D11DEVICE->CreateQuery(&queryDesc, &mQuery); - AssertISV( hRes != E_OUTOFMEMORY, "GFXD3D9QueryFence::resurrect - Out of memory" ); + AssertISV( hRes != E_OUTOFMEMORY, "GFXD3D11QueryFence::resurrect - Out of memory" ); } } diff --git a/Engine/source/gfx/D3D9/d3dx9Functions.h b/Engine/source/gfx/D3D9/d3dx9Functions.h deleted file mode 100644 index 633faf935..000000000 --- a/Engine/source/gfx/D3D9/d3dx9Functions.h +++ /dev/null @@ -1,148 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -D3DX_FUNCTION( D3DXCreateBuffer, HRESULT, - (DWORD NumBytes, - LPD3DXBUFFER * ppBuffer) ) - -D3DX_FUNCTION( D3DXSaveSurfaceToFileA, HRESULT, - (LPCSTR pDestFile, - D3DXIMAGE_FILEFORMAT DestFormat, - LPDIRECT3DSURFACE9 pSrcSurface, - CONST PALETTEENTRY* pSrcPalette, - CONST RECT* pSrcRect) ) - -D3DX_FUNCTION( D3DXSaveSurfaceToFileW, HRESULT, - (LPCWSTR pDestFile, - D3DXIMAGE_FILEFORMAT DestFormat, - LPDIRECT3DSURFACE9 pSrcSurface, - CONST PALETTEENTRY* pSrcPalette, - CONST RECT* pSrcRect) ) - -D3DX_FUNCTION( D3DXCompileShader, HRESULT, - (LPCSTR pSrcData, - UINT srcDataLen, - CONST D3DXMACRO* pDefines, - LPD3DXINCLUDE pInclude, - LPCSTR pFunctionName, - LPCSTR pProfile, - DWORD Flags, - LPD3DXBUFFER* ppShader, - LPD3DXBUFFER* ppErrorMsgs, - LPD3DXCONSTANTTABLE * ppConstantTable) ) - -D3DX_FUNCTION( D3DXGetShaderConstantTable, HRESULT, - (CONST DWORD* pFunction, - LPD3DXCONSTANTTABLE* ppConstantTable) ) - - -D3DX_FUNCTION( D3DXLoadSurfaceFromSurface, HRESULT, - (LPDIRECT3DSURFACE9 pDestSurface, - CONST PALETTEENTRY* pDestPalette, - CONST RECT* pDestRect, - LPDIRECT3DSURFACE9 pSrcSurface, - CONST PALETTEENTRY* pSrcPalette, - CONST RECT* pSrcRect, - DWORD Filter, - D3DCOLOR ColorKey) ) - -D3DX_FUNCTION( D3DXCreateVolumeTexture, HRESULT, - (LPDIRECT3DDEVICE9 pDevice, - UINT Width, - UINT Height, - UINT Depth, - UINT MipLevels, - DWORD Usage, - D3DFORMAT Format, - D3DPOOL Pool, - LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture) ) - -D3DX_FUNCTION( D3DXCreateTexture, HRESULT, - (LPDIRECT3DDEVICE9 pDevice, - UINT Width, - UINT Height, - UINT MipLevels, - DWORD Usage, - D3DFORMAT Format, - D3DPOOL Pool, - LPDIRECT3DTEXTURE9* ppTexture) ) - -#ifdef TORQUE_OS_XENON -D3DX_FUNCTION( D3DXLoadVolumeFromMemory, HRESULT, - (LPDIRECT3DVOLUME9 pDestVolume, - CONST PALETTEENTRY* pDestPalette, - CONST D3DBOX* pDestBox, - LPCVOID pSrcMemory, - D3DFORMAT SrcFormat, - UINT SrcRowPitch, - UINT SrcSlicePitch, - CONST PALETTEENTRY* pSrcPalette, - CONST D3DBOX* pSrcBox, - BOOL SrcParentPacked, - UINT SrcParentWidth, - UINT SrcParentHeight, - UINT SrcParentDepth, - DWORD Filter, - D3DCOLOR ColorKey) ) -#else -D3DX_FUNCTION( D3DXLoadVolumeFromMemory, HRESULT, - (LPDIRECT3DVOLUME9 pDestVolume, - CONST PALETTEENTRY* pDestPalette, - CONST D3DBOX* pDestBox, - LPCVOID pSrcMemory, - D3DFORMAT SrcFormat, - UINT SrcRowPitch, - UINT SrcSlicePitch, - CONST PALETTEENTRY* pSrcPalette, - CONST D3DBOX* pSrcBox, - DWORD Filter, - D3DCOLOR ColorKey) ) -#endif - -D3DX_FUNCTION( D3DXSaveTextureToFileInMemory, HRESULT, - (LPD3DXBUFFER *ppDestBuf, - D3DXIMAGE_FILEFORMAT DestFormat, - LPDIRECT3DBASETEXTURE9 pSrcTexture, - const PALETTEENTRY *pSrcPalette) ) - -D3DX_FUNCTION( D3DXGetImageInfoFromFileInMemory, HRESULT, - (LPCVOID pSrcData, - UINT SrcDataSize, - D3DXIMAGE_INFO* pSrcInfo) ) - -D3DX_FUNCTION( D3DXLoadSurfaceFromFileInMemory, HRESULT, - (LPDIRECT3DSURFACE9 pDestSurface, - CONST PALETTEENTRY * pDestPalette, - CONST RECT * pDestRect, - LPCVOID pSrcData, - UINT SrcData, - CONST RECT * pSrcRect, - DWORD Filter, - D3DCOLOR ColorKey, - D3DXIMAGE_INFO * pSrcInfo) ) - -D3DX_FUNCTION( D3DXSaveSurfaceToFileInMemory, HRESULT, - (LPD3DXBUFFER* ppDestBuf, - D3DXIMAGE_FILEFORMAT DestFormat, - LPDIRECT3DSURFACE9 pSrcSurface, - CONST PALETTEENTRY* pSrcPalette, - CONST RECT* pSrcRect) ) diff --git a/Engine/source/gfx/D3D9/gfxD3D9CardProfiler.cpp b/Engine/source/gfx/D3D9/gfxD3D9CardProfiler.cpp deleted file mode 100644 index c6b169614..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9CardProfiler.cpp +++ /dev/null @@ -1,163 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/gfxD3D9Device.h" -#include "console/console.h" -#include "gfx/primBuilder.h" -#include "gfx/D3D9/gfxD3D9CardProfiler.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" -#ifdef TORQUE_OS_WIN -#include "platformWin32/videoInfo/wmiVideoInfo.h" -#endif - - -GFXD3D9CardProfiler::GFXD3D9CardProfiler(U32 adapterIndex) : GFXCardProfiler() -{ - mAdapterOrdinal = adapterIndex; -} - -GFXD3D9CardProfiler::~GFXD3D9CardProfiler() -{ - -} - -void GFXD3D9CardProfiler::init() -{ - mD3DDevice = dynamic_cast(GFX)->getDevice(); - AssertISV( mD3DDevice, "GFXD3D9CardProfiler::init() - No D3D9 Device found!"); - - // Grab the caps so we can get our adapter ordinal and look up our name. - D3DCAPS9 caps; - D3D9Assert(mD3DDevice->GetDeviceCaps(&caps), "GFXD3D9CardProfiler::init - failed to get device caps!"); - -#ifdef TORQUE_OS_XENON - mCardDescription = "Xbox360 GPU"; - mChipSet = "ATI"; - mVersionString = String::ToString(_XDK_VER); - mVideoMemory = 512 * 1024 * 1024; -#else - WMIVideoInfo wmiVidInfo; - if( wmiVidInfo.profileAdapters() ) - { - const PlatformVideoInfo::PVIAdapter &adapter = wmiVidInfo.getAdapterInformation( caps.AdapterOrdinal ); - - mCardDescription = adapter.description; - mChipSet = adapter.chipSet; - mVersionString = adapter.driverVersion; - mVideoMemory = adapter.vram; - } -#endif - - Parent::init(); -} - -void GFXD3D9CardProfiler::setupCardCapabilities() -{ - // Get the D3D device caps - D3DCAPS9 caps; - mD3DDevice->GetDeviceCaps(&caps); - - setCapability( "autoMipMapLevel", ( caps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP ? 1 : 0 ) ); - - setCapability( "maxTextureWidth", caps.MaxTextureWidth ); - setCapability( "maxTextureHeight", caps.MaxTextureHeight ); - setCapability( "maxTextureSize", getMin( (U32)caps.MaxTextureWidth, (U32)caps.MaxTextureHeight) ); - - bool canDoLERPDetailBlend = ( caps.TextureOpCaps & D3DTEXOPCAPS_LERP ) && ( caps.MaxTextureBlendStages > 1 ); - - bool canDoFourStageDetailBlend = ( caps.TextureOpCaps & D3DTEXOPCAPS_SUBTRACT ) && - ( caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP ) && - ( caps.MaxTextureBlendStages > 3 ); - bool canDoIndependentMrtBitDepth = (caps.PrimitiveMiscCaps & D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS ? 1 : 0 ); - - setCapability( "lerpDetailBlend", canDoLERPDetailBlend ); - setCapability( "fourStageDetailBlend", canDoFourStageDetailBlend ); - setCapability( "independentMrtBitDepth", canDoIndependentMrtBitDepth); -} - -bool GFXD3D9CardProfiler::_queryCardCap(const String &query, U32 &foundResult) -{ - return 0; -} - -bool GFXD3D9CardProfiler::_queryFormat( const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips ) -{ - LPDIRECT3D9 pD3D = static_cast(GFX)->getD3D(); - D3DDISPLAYMODE displayMode = static_cast(GFX)->getDisplayMode(); - - DWORD usage = 0; - D3DRESOURCETYPE rType = D3DRTYPE_TEXTURE; - D3DFORMAT adapterFormat = displayMode.Format; - - D3DFORMAT texFormat = GFXD3D9TextureFormat[fmt]; - -#if defined(TORQUE_OS_XENON) - inOutAutogenMips = false; - adapterFormat = D3DFMT_A8B8G8R8; - - if(profile->isRenderTarget()) - { - texFormat = (D3DFORMAT)MAKELEFMT(texFormat); - } -#else - if( profile->isRenderTarget() ) - usage |= D3DUSAGE_RENDERTARGET; - else if( profile->isZTarget() ) - { - usage |= D3DUSAGE_DEPTHSTENCIL; - rType = D3DRTYPE_SURFACE; - } - - if( inOutAutogenMips ) - usage |= D3DUSAGE_AUTOGENMIPMAP; -#endif - - // Early-check to see if the enum translation table has an unsupported value - if(texFormat == (_D3DFORMAT)GFX_UNSUPPORTED_VAL) - return false; - - HRESULT hr = pD3D->CheckDeviceFormat( mAdapterOrdinal, D3DDEVTYPE_HAL, - adapterFormat, usage, rType, texFormat ); - - bool retVal = SUCCEEDED( hr ); - -#if !defined(TORQUE_OS_XENON) - // If check device format failed, and auto gen mips were requested, try again - // without autogen mips. - if( !retVal && inOutAutogenMips ) - { - usage ^= D3DUSAGE_AUTOGENMIPMAP; - - hr = pD3D->CheckDeviceFormat( mAdapterOrdinal, D3DDEVTYPE_HAL, - adapterFormat, usage, D3DRTYPE_TEXTURE, GFXD3D9TextureFormat[fmt] ); - - retVal = SUCCEEDED( hr ); - - // If this one passed, auto gen mips are not supported with this format, - // so set the variable properly - if( retVal ) - inOutAutogenMips = false; - } -#endif - - return retVal; -} \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/gfxD3D9CardProfiler.h b/Engine/source/gfx/D3D9/gfxD3D9CardProfiler.h deleted file mode 100644 index f4bee1fee..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9CardProfiler.h +++ /dev/null @@ -1,51 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFXD3D9CARDPROFILER_H_ -#define _GFXD3D9CARDPROFILER_H_ - - -#include "gfx/gfxCardProfile.h" - -struct IDirect3DDevice9; -class GFXD3D9CardProfiler : public GFXCardProfiler -{ -private: - typedef GFXCardProfiler Parent; - - IDirect3DDevice9 *mD3DDevice; - UINT mAdapterOrdinal; - -public: - GFXD3D9CardProfiler(U32 adapterIndex); - ~GFXD3D9CardProfiler(); - void init(); - -protected: - const String &getRendererString() const { static String sRS("D3D9"); return sRS; } - - void setupCardCapabilities(); - bool _queryCardCap(const String &query, U32 &foundResult); - bool _queryFormat(const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips); -}; - -#endif diff --git a/Engine/source/gfx/D3D9/gfxD3D9Cubemap.cpp b/Engine/source/gfx/D3D9/gfxD3D9Cubemap.cpp deleted file mode 100644 index d7161ad9b..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9Cubemap.cpp +++ /dev/null @@ -1,253 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/gfxD3D9Cubemap.h" -#include "gfx/gfxTextureManager.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" - -_D3DCUBEMAP_FACES GFXD3D9Cubemap::faceList[6] = -{ - D3DCUBEMAP_FACE_POSITIVE_X, D3DCUBEMAP_FACE_NEGATIVE_X, - D3DCUBEMAP_FACE_POSITIVE_Y, D3DCUBEMAP_FACE_NEGATIVE_Y, - D3DCUBEMAP_FACE_POSITIVE_Z, D3DCUBEMAP_FACE_NEGATIVE_Z -}; - -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -GFXD3D9Cubemap::GFXD3D9Cubemap() -{ - mCubeTex = NULL; - mDynamic = false; - mFaceFormat = GFXFormatR8G8B8A8; -} - -//----------------------------------------------------------------------------- -// Destructor -//----------------------------------------------------------------------------- -GFXD3D9Cubemap::~GFXD3D9Cubemap() -{ - releaseSurfaces(); - - if ( mDynamic ) - GFXTextureManager::removeEventDelegate( this, &GFXD3D9Cubemap::_onTextureEvent ); -} - -//----------------------------------------------------------------------------- -// Release D3D surfaces -//----------------------------------------------------------------------------- -void GFXD3D9Cubemap::releaseSurfaces() -{ - if ( !mCubeTex ) - return; - - mCubeTex->Release(); - mCubeTex = NULL; -} - -void GFXD3D9Cubemap::_onTextureEvent( GFXTexCallbackCode code ) -{ - // Can this happen? - if ( !mDynamic ) - return; - - if ( code == GFXZombify ) - releaseSurfaces(); - else if ( code == GFXResurrect ) - initDynamic( mTexSize ); -} - -//----------------------------------------------------------------------------- -// Init Static -//----------------------------------------------------------------------------- -void GFXD3D9Cubemap::initStatic( GFXTexHandle *faces ) -{ - //if( mCubeTex ) - // return; - - if( faces ) - { - AssertFatal( faces[0], "empty texture passed to CubeMap::create" ); - - GFXD3D9Device *dev = static_cast(GFX); - - D3DPOOL pool = D3DPOOL_MANAGED; - - if (dev->isD3D9Ex()) - pool = D3DPOOL_DEFAULT; - - LPDIRECT3DDEVICE9 D3D9Device = dev->getDevice(); - - // NOTE - check tex sizes on all faces - they MUST be all same size - mTexSize = faces[0].getWidth(); - mFaceFormat = faces[0].getFormat(); - - U32 levels = faces->getPointer()->getMipLevels(); - if (levels >1) - { - D3D9Assert(D3D9Device->CreateCubeTexture(mTexSize, levels, 0, GFXD3D9TextureFormat[mFaceFormat], - pool, &mCubeTex, NULL), NULL); - fillCubeTextures(faces, D3D9Device); - } - else - { - D3D9Assert( D3D9Device->CreateCubeTexture( mTexSize, 0, D3DUSAGE_AUTOGENMIPMAP, GFXD3D9TextureFormat[mFaceFormat], - pool, &mCubeTex, NULL ), NULL ); - fillCubeTextures( faces, D3D9Device ); - mCubeTex->GenerateMipSubLevels(); - } - } -} - -void GFXD3D9Cubemap::initStatic( DDSFile *dds ) -{ - AssertFatal( dds, "GFXD3D9Cubemap::initStatic - Got null DDS file!" ); - AssertFatal( dds->isCubemap(), "GFXD3D9Cubemap::initStatic - Got non-cubemap DDS file!" ); - AssertFatal( dds->mSurfaces.size() == 6, "GFXD3D9Cubemap::initStatic - DDS has less than 6 surfaces!" ); - - GFXD3D9Device *dev = static_cast(GFX); - - D3DPOOL pool = D3DPOOL_MANAGED; - - if (dev->isD3D9Ex()) - pool = D3DPOOL_DEFAULT; - - LPDIRECT3DDEVICE9 D3D9Device = dev->getDevice(); - - // NOTE - check tex sizes on all faces - they MUST be all same size - mTexSize = dds->getWidth(); - mFaceFormat = dds->getFormat(); - U32 levels = dds->getMipLevels(); - - D3D9Assert( D3D9Device->CreateCubeTexture( mTexSize, levels, 0, GFXD3D9TextureFormat[mFaceFormat], - pool, &mCubeTex, NULL ), NULL ); - - for( U32 i=0; i < 6; i++ ) - { - if ( !dds->mSurfaces[i] ) - { - // TODO: The DDS can skip surfaces, but i'm unsure what i should - // do here when creating the cubemap. Ignore it for now. - continue; - } - - // Now loop thru the mip levels! - for( U32 l = 0; l < levels; l++ ) - { - IDirect3DSurface9 *cubeSurf = NULL; - D3D9Assert( mCubeTex->GetCubeMapSurface( faceList[i], l, &cubeSurf ), - "GFXD3D9Cubemap::initStatic - Get cubemap surface failed!" ); - - // Lock the dest surface. - D3DLOCKED_RECT lockedRect; - D3D9Assert( cubeSurf->LockRect( &lockedRect, NULL, 0 ), - "GFXD3D9Cubemap::initStatic - Failed to lock surface level for load!" ); - - dMemcpy( lockedRect.pBits, dds->mSurfaces[i]->mMips[l], dds->getSurfaceSize(l) ); - - cubeSurf->UnlockRect(); - cubeSurf->Release(); - } - } -} - -//----------------------------------------------------------------------------- -// Init Dynamic -//----------------------------------------------------------------------------- -void GFXD3D9Cubemap::initDynamic( U32 texSize, GFXFormat faceFormat ) -{ - if ( mCubeTex ) - return; - - if ( !mDynamic ) - GFXTextureManager::addEventDelegate( this, &GFXD3D9Cubemap::_onTextureEvent ); - - mDynamic = true; - mTexSize = texSize; - mFaceFormat = faceFormat; - - LPDIRECT3DDEVICE9 D3D9Device = reinterpret_cast(GFX)->getDevice(); - - // might want to try this as a 16 bit texture... - D3D9Assert( D3D9Device->CreateCubeTexture( texSize, - 1, -#ifdef TORQUE_OS_XENON - 0, -#else - D3DUSAGE_RENDERTARGET, -#endif - GFXD3D9TextureFormat[faceFormat], - D3DPOOL_DEFAULT, - &mCubeTex, - NULL ), NULL ); -} - -//----------------------------------------------------------------------------- -// Fills in face textures of cube map from existing textures -//----------------------------------------------------------------------------- -void GFXD3D9Cubemap::fillCubeTextures( GFXTexHandle *faces, LPDIRECT3DDEVICE9 D3DDevice) -{ - - U32 levels = faces->getPointer()->getMipLevels(); - for (U32 mip = 0; mip < levels; mip++) - { - for (U32 i = 0; i < 6; i++) - { - // get cube face surface - IDirect3DSurface9 *cubeSurf = NULL; - D3D9Assert(mCubeTex->GetCubeMapSurface(faceList[i], mip, &cubeSurf), NULL); - - // get incoming texture surface - GFXD3D9TextureObject *texObj = dynamic_cast((GFXTextureObject*)faces[i]); - IDirect3DSurface9 *inSurf; - D3D9Assert(texObj->get2DTex()->GetSurfaceLevel(mip, &inSurf), NULL); - - // copy incoming texture into cube face - D3D9Assert(GFXD3DX.D3DXLoadSurfaceFromSurface(cubeSurf, NULL, NULL, inSurf, NULL, - NULL, D3DX_FILTER_NONE, 0), NULL); - cubeSurf->Release(); - inSurf->Release(); - } - } -} - -//----------------------------------------------------------------------------- -// Set the cubemap to the specified texture unit num -//----------------------------------------------------------------------------- -void GFXD3D9Cubemap::setToTexUnit( U32 tuNum ) -{ - static_cast(GFX)->getDevice()->SetTexture( tuNum, mCubeTex ); -} - -void GFXD3D9Cubemap::zombify() -{ - // Static cubemaps are handled by D3D - if( mDynamic ) - releaseSurfaces(); -} - -void GFXD3D9Cubemap::resurrect() -{ - // Static cubemaps are handled by D3D - if( mDynamic ) - initDynamic( mTexSize, mFaceFormat ); -} diff --git a/Engine/source/gfx/D3D9/gfxD3D9Cubemap.h b/Engine/source/gfx/D3D9/gfxD3D9Cubemap.h deleted file mode 100644 index cf95bd0be..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9Cubemap.h +++ /dev/null @@ -1,72 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFXD3D9CUBEMAP_H_ -#define _GFXD3D9CUBEMAP_H_ - -#include "gfx/D3D9/gfxD3D9Device.h" -#include "gfx/gfxCubemap.h" -#include "gfx/gfxResource.h" -#include "gfx/gfxTarget.h" - -//************************************************************************** -// Cube map -//************************************************************************** -class GFXD3D9Cubemap : public GFXCubemap -{ -public: - virtual void initStatic( GFXTexHandle *faces ); - virtual void initStatic( DDSFile *dds ); - virtual void initDynamic( U32 texSize, GFXFormat faceFormat = GFXFormatR8G8B8A8 ); - virtual void setToTexUnit( U32 tuNum ); - virtual U32 getSize() const { return mTexSize; } - virtual GFXFormat getFormat() const { return mFaceFormat; } - - GFXD3D9Cubemap(); - virtual ~GFXD3D9Cubemap(); - - // GFXResource interface - virtual void zombify(); - virtual void resurrect(); - -protected: - - friend class GFXPCD3D9TextureTarget; - friend class GFX360TextureTarget; - friend class GFXD3D9Device; - - LPDIRECT3DCUBETEXTURE9 mCubeTex; - - static _D3DCUBEMAP_FACES faceList[6]; - bool mDynamic; - U32 mTexSize; - GFXFormat mFaceFormat; - - void fillCubeTextures( GFXTexHandle *faces, LPDIRECT3DDEVICE9 D3DDevice ); - void releaseSurfaces(); - - /// The callback used to get texture events. - /// @see GFXTextureManager::addEventDelegate - void _onTextureEvent( GFXTexCallbackCode code ); -}; - -#endif // GFXD3D9CUBEMAP diff --git a/Engine/source/gfx/D3D9/gfxD3D9Device.cpp b/Engine/source/gfx/D3D9/gfxD3D9Device.cpp deleted file mode 100644 index 05c3474dc..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9Device.cpp +++ /dev/null @@ -1,1213 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/gfxD3D9Device.h" - -#include "console/console.h" -#include "core/stream/fileStream.h" -#include "core/strings/unicode.h" -#include "gfx/D3D9/gfxD3D9CardProfiler.h" -#include "gfx/D3D9/gfxD3D9VertexBuffer.h" -#include "gfx/D3D9/screenShotD3D9.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" -#include "gfx/D3D9/gfxD3D9QueryFence.h" -#include "gfx/D3D9/gfxD3D9OcclusionQuery.h" -#include "gfx/D3D9/gfxD3D9Shader.h" -#include "windowManager/platformWindow.h" -#include "materials/shaderData.h" -#ifndef TORQUE_OS_XENON -# include "windowManager/win32/win32Window.h" -#endif - -D3DXFNTable GFXD3D9Device::smD3DX; - -GFXD3D9Device::GFXD3D9Device( LPDIRECT3D9 d3d, U32 index ) -{ - mDeviceSwizzle32 = &Swizzles::bgra; - GFXVertexColor::setSwizzle( mDeviceSwizzle32 ); - - mDeviceSwizzle24 = &Swizzles::bgr; - - mD3D = d3d; - mAdapterIndex = index; - mD3DDevice = NULL; - mVolatileVB = NULL; - - mCurrentPB = NULL; - mDynamicPB = NULL; - - mLastVertShader = NULL; - mLastPixShader = NULL; - - mCanCurrentlyRender = false; - mTextureManager = NULL; - mCurrentStateBlock = NULL; - mResourceListHead = NULL; - -#ifdef TORQUE_DEBUG - mVBListHead = NULL; - mNumAllocatedVertexBuffers = 0; -#endif - - mPixVersion = 0.0; - mNumSamplers = 0; - mNumRenderTargets = 0; - - mCardProfiler = NULL; - - mDeviceDepthStencil = NULL; - mDeviceBackbuffer = NULL; - mDeviceColor = NULL; - - mCreateFenceType = -1; // Unknown, test on first allocate - - mCurrentConstBuffer = NULL; - - mOcclusionQuerySupported = false; - - for (U32 i = 0; i < GS_COUNT; ++i) - mModelViewProjSC[i] = NULL; - - // Set up the Enum translation tables - GFXD3D9EnumTranslate::init(); - -#if !defined(TORQUE_OS_XENON) - mD3DEx = NULL; - mD3DDeviceEx = NULL; -#endif -} - -//----------------------------------------------------------------------------- - -GFXD3D9Device::~GFXD3D9Device() -{ - // Release our refcount on the current stateblock object - mCurrentStateBlock = NULL; - - releaseDefaultPoolResources(); - - // Free the vertex declarations. - VertexDeclMap::Iterator iter = mVertexDecls.begin(); - for ( ; iter != mVertexDecls.end(); iter++ ) - delete iter->value; - - // Check up on things - Con::printf("Cur. D3DDevice ref count=%d", mD3DDevice->AddRef() - 1); - mD3DDevice->Release(); - - // Forcibly clean up the pools - mVolatileVBList.setSize(0); - mDynamicPB = NULL; - - // And release our D3D resources. - SAFE_RELEASE( mDeviceDepthStencil ); - SAFE_RELEASE( mDeviceBackbuffer ) - SAFE_RELEASE( mDeviceColor ); - SAFE_RELEASE( mD3D ); - SAFE_RELEASE( mD3DDevice ); - -#ifdef TORQUE_DEBUG - logVertexBuffers(); -#endif - - if( mCardProfiler ) - { - delete mCardProfiler; - mCardProfiler = NULL; - } - - if( gScreenShot ) - { - delete gScreenShot; - gScreenShot = NULL; - } -} - -//------------------------------------------------------------------------------ -// setupGenericShaders -//------------------------------------------------------------------------------ -inline void GFXD3D9Device::setupGenericShaders( GenericShaderType type /* = GSColor */ ) -{ - AssertFatal(type != GSTargetRestore, ""); //not used - - if (mGenericShader[GSColor] == NULL) - { - ShaderData *shaderData; - - shaderData = new ShaderData(); - shaderData->setField("DXVertexShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/colorV.hlsl")); - shaderData->setField("DXPixelShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/colorP.hlsl")); - shaderData->setField("pixVersion", "3.0"); - shaderData->registerObject(); - mGenericShader[GSColor] = shaderData->getShader(); - mGenericShaderBuffer[GSColor] = mGenericShader[GSColor]->allocConstBuffer(); - mModelViewProjSC[GSColor] = mGenericShader[GSColor]->getShaderConstHandle("$modelView"); - Sim::getRootGroup()->addObject(shaderData); - - shaderData = new ShaderData(); - shaderData->setField("DXVertexShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/modColorTextureV.hlsl")); - shaderData->setField("DXPixelShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/modColorTextureP.hlsl")); - shaderData->setSamplerName("$diffuseMap", 0); - shaderData->setField("pixVersion", "3.0"); - shaderData->registerObject(); - mGenericShader[GSModColorTexture] = shaderData->getShader(); - mGenericShaderBuffer[GSModColorTexture] = mGenericShader[GSModColorTexture]->allocConstBuffer(); - mModelViewProjSC[GSModColorTexture] = mGenericShader[GSModColorTexture]->getShaderConstHandle("$modelView"); - Sim::getRootGroup()->addObject(shaderData); - - shaderData = new ShaderData(); - shaderData->setField("DXVertexShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/addColorTextureV.hlsl")); - shaderData->setField("DXPixelShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/addColorTextureP.hlsl")); - shaderData->setSamplerName("$diffuseMap", 0); - shaderData->setField("pixVersion", "3.0"); - shaderData->registerObject(); - mGenericShader[GSAddColorTexture] = shaderData->getShader(); - mGenericShaderBuffer[GSAddColorTexture] = mGenericShader[GSAddColorTexture]->allocConstBuffer(); - mModelViewProjSC[GSAddColorTexture] = mGenericShader[GSAddColorTexture]->getShaderConstHandle("$modelView"); - Sim::getRootGroup()->addObject(shaderData); - - shaderData = new ShaderData(); - shaderData->setField("DXVertexShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/textureV.hlsl")); - shaderData->setField("DXPixelShaderFile", String(Con::getVariable("$Core::CommonShaderPath")) + String("/fixedFunction/textureP.hlsl")); - shaderData->setSamplerName("$diffuseMap", 0); - shaderData->setField("pixVersion", "3.0"); - shaderData->registerObject(); - mGenericShader[GSTexture] = shaderData->getShader(); - mGenericShaderBuffer[GSTexture] = mGenericShader[GSTexture]->allocConstBuffer(); - mModelViewProjSC[GSTexture] = mGenericShader[GSTexture]->getShaderConstHandle("$modelView"); - Sim::getRootGroup()->addObject(shaderData); - - //Force an update - mViewportDirty = true; - } - - MatrixF tempMatrix = mProjectionMatrix * mViewMatrix * mWorldMatrix[mWorldStackSize]; - mGenericShaderBuffer[type]->setSafe(mModelViewProjSC[type], tempMatrix); - - setShader(mGenericShader[type]); - setShaderConstBuffer(mGenericShaderBuffer[type]); -} - -//----------------------------------------------------------------------------- -/// Creates a state block object based on the desc passed in. This object -/// represents an immutable state. -GFXStateBlockRef GFXD3D9Device::createStateBlockInternal(const GFXStateBlockDesc& desc) -{ - return GFXStateBlockRef(new GFXD3D9StateBlock(desc, mD3DDevice)); -} - -/// Activates a stateblock -void GFXD3D9Device::setStateBlockInternal(GFXStateBlock* block, bool force) -{ - AssertFatal(dynamic_cast(block), "Incorrect stateblock type for this device!"); - GFXD3D9StateBlock* d3dBlock = static_cast(block); - GFXD3D9StateBlock* d3dCurrent = static_cast(mCurrentStateBlock.getPointer()); - if (force) - d3dCurrent = NULL; - d3dBlock->activate(d3dCurrent); -} - -/// Called by base GFXDevice to actually set a const buffer -void GFXD3D9Device::setShaderConstBufferInternal(GFXShaderConstBuffer* buffer) -{ - if (buffer) - { - PROFILE_SCOPE(GFXD3D9Device_setShaderConstBufferInternal); - AssertFatal(dynamic_cast(buffer), "Incorrect shader const buffer type for this device!"); - GFXD3D9ShaderConstBuffer* d3dBuffer = static_cast(buffer); - - d3dBuffer->activate(mCurrentConstBuffer); - mCurrentConstBuffer = d3dBuffer; - } else { - mCurrentConstBuffer = NULL; - } -} - -//----------------------------------------------------------------------------- - -void GFXD3D9Device::clear( U32 flags, ColorI color, F32 z, U32 stencil ) -{ - // Make sure we have flushed our render target state. - _updateRenderTargets(); - - // Kind of a bummer we have to do this, there should be a better way made - DWORD realflags = 0; - - if( flags & GFXClearTarget ) - realflags |= D3DCLEAR_TARGET; - - if( flags & GFXClearZBuffer ) - realflags |= D3DCLEAR_ZBUFFER; - - if( flags & GFXClearStencil ) - realflags |= D3DCLEAR_STENCIL; - - mD3DDevice->Clear( 0, NULL, realflags, - D3DCOLOR_ARGB( color.alpha, color.red, color.green, color.blue ), - z, stencil ); -} - -//----------------------------------------------------------------------------- - -bool GFXD3D9Device::beginSceneInternal() -{ - HRESULT hr = mD3DDevice->BeginScene(); - D3D9Assert(hr, "GFXD3D9Device::beginSceneInternal - failed to BeginScene"); - mCanCurrentlyRender = SUCCEEDED(hr); - return mCanCurrentlyRender; -} - -//----------------------------------------------------------------------------- - -void GFXD3D9Device::endSceneInternal() -{ - mD3DDevice->EndScene(); - mCanCurrentlyRender = false; -} - -void GFXD3D9Device::_updateRenderTargets() -{ - if ( mRTDirty || ( mCurrentRT && mCurrentRT->isPendingState() ) ) - { - if ( mRTDeactivate ) - { - mRTDeactivate->deactivate(); - mRTDeactivate = NULL; - } - - // NOTE: The render target changes are not really accurate - // as the GFXTextureTarget supports MRT internally. So when - // we activate a GFXTarget it could result in multiple calls - // to SetRenderTarget on the actual device. - mDeviceStatistics.mRenderTargetChanges++; - - mCurrentRT->activate(); - - mRTDirty = false; - } - - if ( mViewportDirty ) - { - D3DVIEWPORT9 viewport; - viewport.X = mViewport.point.x; - viewport.Y = mViewport.point.y; - viewport.Width = mViewport.extent.x; - viewport.Height = mViewport.extent.y; - viewport.MinZ = 0.0; - viewport.MaxZ = 1.0; - - D3D9Assert( mD3DDevice->SetViewport( &viewport ), - "GFXD3D9Device::_updateRenderTargets() - Error setting viewport!" ); - - mViewportDirty = false; - } -} - - -#ifdef TORQUE_DEBUG - -void GFXD3D9Device::logVertexBuffers() -{ - - // NOTE: This function should be called on the destructor of this class and ONLY then - // otherwise it'll produce the wrong output - if( mNumAllocatedVertexBuffers == 0 ) - return; - - FileStream fs; - - fs.open( "vertexbuffer.log", Torque::FS::File::Write ); - - char buff[256]; - - fs.writeLine( (U8 *)avar("-- Vertex buffer memory leak report -- time = %d", Platform::getRealMilliseconds()) ); - dSprintf( (char *)&buff, sizeof( buff ), "%d un-freed vertex buffers", mNumAllocatedVertexBuffers ); - fs.writeLine( (U8 *)buff ); - - GFXD3D9VertexBuffer *walk = mVBListHead; - - while( walk != NULL ) - { - dSprintf( (char *)&buff, sizeof( buff ), "[Name: %s] Size: %d", walk->name, walk->mNumVerts ); - fs.writeLine( (U8 *)buff ); - - walk = walk->next; - } - - fs.writeLine( (U8 *)"-- End report --" ); - - fs.close(); -} - -//----------------------------------------------------------------------------- - -void GFXD3D9Device::addVertexBuffer( GFXD3D9VertexBuffer *buffer ) -{ - mNumAllocatedVertexBuffers++; - - if( mVBListHead == NULL ) - { - mVBListHead = buffer; - } - else - { - GFXD3D9VertexBuffer *walk = mVBListHead; - - while( walk->next != NULL ) - { - walk = walk->next; - } - - walk->next = buffer; - } - - buffer->next = NULL; -} - -//----------------------------------------------------------------------------- - -void GFXD3D9Device::removeVertexBuffer( GFXD3D9VertexBuffer *buffer ) -{ - mNumAllocatedVertexBuffers--; - - // Quick check to see if this is head of list - if( mVBListHead == buffer ) - { - mVBListHead = mVBListHead->next; - return; - } - - GFXD3D9VertexBuffer *walk = mVBListHead; - - while( walk->next != NULL ) - { - if( walk->next == buffer ) - { - walk->next = walk->next->next; - return; - } - - walk = walk->next; - } - - AssertFatal( false, "Vertex buffer not found in list." ); -} - -#endif - -//----------------------------------------------------------------------------- - -void GFXD3D9Device::releaseDefaultPoolResources() -{ - // Release all the dynamic vertex buffer arrays - // Forcibly clean up the pools - for( U32 i=0; ivb->AddRef() - 1, mVolatileVBList[i]->mRefCount); - // mVolatileVBList[i]->vb->Release(); - - mVolatileVBList[i]->vb->Release(); - mVolatileVBList[i]->vb = NULL; - mVolatileVBList[i] = NULL; - } - mVolatileVBList.setSize(0); - - // We gotta clear the current const buffer else the next - // activate may erroneously think the device is still holding - // this state and fail to set it. - mCurrentConstBuffer = NULL; - - // Set current VB to NULL and set state dirty - for ( U32 i=0; i < VERTEX_STREAM_COUNT; i++ ) - { - mCurrentVertexBuffer[i] = NULL; - mVertexBufferDirty[i] = true; - mVertexBufferFrequency[i] = 0; - mVertexBufferFrequencyDirty[i] = true; - } - - // Release dynamic index buffer - if( mDynamicPB != NULL ) - { - SAFE_RELEASE( mDynamicPB->ib ); - } - - // Set current PB/IB to NULL and set state dirty - mCurrentPrimitiveBuffer = NULL; - mCurrentPB = NULL; - mPrimitiveBufferDirty = true; - - // Zombify texture manager (for D3D this only modifies default pool textures) - if( mTextureManager ) - mTextureManager->zombify(); - - // Kill off other potentially dangling references... - SAFE_RELEASE( mDeviceDepthStencil ); - SAFE_RELEASE( mDeviceBackbuffer ); - mD3DDevice->SetDepthStencilSurface(NULL); - - // Set global dirty state so the IB/PB and VB get reset - mStateDirty = true; - - // Walk the resource list and zombify everything. - GFXResource *walk = mResourceListHead; - while(walk) - { - walk->zombify(); - walk = walk->getNextResource(); - } -} - -//----------------------------------------------------------------------------- - -void GFXD3D9Device::reacquireDefaultPoolResources() -{ - // Now do the dynamic index buffers - if( mDynamicPB == NULL ) - mDynamicPB = new GFXD3D9PrimitiveBuffer(this, 0, 0, GFXBufferTypeDynamic); - - D3D9Assert( mD3DDevice->CreateIndexBuffer( sizeof( U16 ) * MAX_DYNAMIC_INDICES, -#ifdef TORQUE_OS_XENON - D3DUSAGE_WRITEONLY, -#else - D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, -#endif - GFXD3D9IndexFormat[GFXIndexFormat16], D3DPOOL_DEFAULT, &mDynamicPB->ib, NULL ), "Failed to allocate dynamic IB" ); - - // Grab the depth-stencil... - SAFE_RELEASE(mDeviceDepthStencil); - D3D9Assert(mD3DDevice->GetDepthStencilSurface(&mDeviceDepthStencil), - "GFXD3D9Device::reacquireDefaultPoolResources - couldn't grab reference to device's depth-stencil surface."); - - SAFE_RELEASE(mDeviceBackbuffer); - mD3DDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &mDeviceBackbuffer ); - - // Store for query later. - mD3DDevice->GetDisplayMode( 0, &mDisplayMode ); - - // Walk the resource list and zombify everything. - GFXResource *walk = mResourceListHead; - while(walk) - { - walk->resurrect(); - walk = walk->getNextResource(); - } - - if(mTextureManager) - mTextureManager->resurrect(); -} - -GFXD3D9VertexBuffer* GFXD3D9Device::findVBPool( const GFXVertexFormat *vertexFormat, U32 vertsNeeded ) -{ - PROFILE_SCOPE( GFXD3D9Device_findVBPool ); - - // Verts needed is ignored on the base device, 360 is different - for( U32 i=0; imVertexFormat.isEqual( *vertexFormat ) ) - return mVolatileVBList[i]; - - return NULL; -} - -GFXD3D9VertexBuffer * GFXD3D9Device::createVBPool( const GFXVertexFormat *vertexFormat, U32 vertSize ) -{ - PROFILE_SCOPE( GFXD3D9Device_createVBPool ); - - // this is a bit funky, but it will avoid problems with (lack of) copy constructors - // with a push_back() situation - mVolatileVBList.increment(); - StrongRefPtr newBuff; - mVolatileVBList.last() = new GFXD3D9VertexBuffer(); - newBuff = mVolatileVBList.last(); - - newBuff->mNumVerts = 0; - newBuff->mBufferType = GFXBufferTypeVolatile; - newBuff->mVertexFormat.copy( *vertexFormat ); - newBuff->mVertexSize = vertSize; - newBuff->mDevice = this; - - // Requesting it will allocate it. - vertexFormat->getDecl(); - - // Con::printf("Created buff with type %x", vertFlags); - - D3D9Assert( mD3DDevice->CreateVertexBuffer( vertSize * MAX_DYNAMIC_VERTS, -#ifdef TORQUE_OS_XENON - D3DUSAGE_WRITEONLY, -#else - D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, -#endif - 0, - D3DPOOL_DEFAULT, - &newBuff->vb, - NULL ), - "Failed to allocate dynamic VB" ); - return newBuff; -} - -//----------------------------------------------------------------------------- - -void GFXD3D9Device::setClipRect( const RectI &inRect ) -{ - // We transform the incoming rect by the view - // matrix first, so that it can be used to pan - // and scale the clip rect. - // - // This is currently used to take tiled screenshots. - Point3F pos( inRect.point.x, inRect.point.y, 0.0f ); - Point3F extent( inRect.extent.x, inRect.extent.y, 0.0f ); - getViewMatrix().mulP( pos ); - getViewMatrix().mulV( extent ); - RectI rect( pos.x, pos.y, extent.x, extent.y ); - - // Clip the rect against the renderable size. - Point2I size = mCurrentRT->getSize(); - - RectI maxRect(Point2I(0,0), size); - rect.intersect(maxRect); - - mClipRect = rect; - - F32 l = F32( mClipRect.point.x ); - F32 r = F32( mClipRect.point.x + mClipRect.extent.x ); - F32 b = F32( mClipRect.point.y + mClipRect.extent.y ); - F32 t = F32( mClipRect.point.y ); - - // Set up projection matrix, - static Point4F pt; - pt.set(2.0f / (r - l), 0.0f, 0.0f, 0.0f); - mTempMatrix.setColumn(0, pt); - - pt.set(0.0f, 2.0f/(t - b), 0.0f, 0.0f); - mTempMatrix.setColumn(1, pt); - - pt.set(0.0f, 0.0f, 1.0f, 0.0f); - mTempMatrix.setColumn(2, pt); - - pt.set((l+r)/(l-r), (t+b)/(b-t), 1.0f, 1.0f); - mTempMatrix.setColumn(3, pt); - - setProjectionMatrix( mTempMatrix ); - - // Set up world/view matrix - mTempMatrix.identity(); - setWorldMatrix( mTempMatrix ); - - setViewport( mClipRect ); -} - -void GFXD3D9Device::setVertexStream( U32 stream, GFXVertexBuffer *buffer ) -{ - GFXD3D9VertexBuffer *d3dBuffer = static_cast( buffer ); - - if ( stream == 0 ) - { - // Set the volatile buffer which is used to - // offset the start index when doing draw calls. - if ( d3dBuffer && d3dBuffer->mVolatileStart > 0 ) - mVolatileVB = d3dBuffer; - else - mVolatileVB = NULL; - } - - U32 offset = d3dBuffer && stream != 0 ? d3dBuffer->mVolatileStart * d3dBuffer->mVertexSize : 0; - - // NOTE: We do not use the stream offset here for stream 0 - // as that feature is *supposedly* not as well supported as - // using the start index in drawPrimitive. - // - // If we can verify that this is not the case then we should - // start using this method exclusively for all streams. - - D3D9Assert( mD3DDevice->SetStreamSource( stream, - d3dBuffer ? d3dBuffer->vb : NULL, - offset, - d3dBuffer ? d3dBuffer->mVertexSize : 0 ), - "GFXD3D9Device::setVertexStream - Failed to set stream source." ); -} - -void GFXD3D9Device::setVertexStreamFrequency( U32 stream, U32 frequency ) -{ - if ( frequency == 0 ) - frequency = 1; - else - { - if ( stream == 0 ) - frequency = D3DSTREAMSOURCE_INDEXEDDATA | frequency; - else - frequency = D3DSTREAMSOURCE_INSTANCEDATA | frequency; - } - - D3D9Assert( mD3DDevice->SetStreamSourceFreq( stream, frequency ), - "GFXD3D9Device::setVertexStreamFrequency - Failed to set stream frequency." ); -} - -void GFXD3D9Device::_setPrimitiveBuffer( GFXPrimitiveBuffer *buffer ) -{ - mCurrentPB = static_cast( buffer ); - - D3D9Assert( mD3DDevice->SetIndices( mCurrentPB->ib ), "Failed to set indices" ); -} - -void GFXD3D9Device::drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount ) -{ - // This is done to avoid the function call overhead if possible - if( mStateDirty ) - updateStates(); - if (mCurrentShaderConstBuffer) - setShaderConstBufferInternal(mCurrentShaderConstBuffer); - - if ( mVolatileVB ) - vertexStart += mVolatileVB->mVolatileStart; - - D3D9Assert( mD3DDevice->DrawPrimitive( GFXD3D9PrimType[primType], vertexStart, primitiveCount ), "Failed to draw primitives" ); - - mDeviceStatistics.mDrawCalls++; - if ( mVertexBufferFrequency[0] > 1 ) - mDeviceStatistics.mPolyCount += primitiveCount * mVertexBufferFrequency[0]; - else - mDeviceStatistics.mPolyCount += primitiveCount; -} - -//----------------------------------------------------------------------------- - -void GFXD3D9Device::drawIndexedPrimitive( GFXPrimitiveType primType, - U32 startVertex, - U32 minIndex, - U32 numVerts, - U32 startIndex, - U32 primitiveCount ) -{ - // This is done to avoid the function call overhead if possible - if( mStateDirty ) - updateStates(); - if (mCurrentShaderConstBuffer) - setShaderConstBufferInternal(mCurrentShaderConstBuffer); - - AssertFatal( mCurrentPB != NULL, "Trying to call drawIndexedPrimitive with no current index buffer, call setIndexBuffer()" ); - - if ( mVolatileVB ) - startVertex += mVolatileVB->mVolatileStart; - - D3D9Assert( mD3DDevice->DrawIndexedPrimitive( GFXD3D9PrimType[primType], - startVertex, - /* mCurrentPB->mVolatileStart + */ minIndex, - numVerts, - mCurrentPB->mVolatileStart + startIndex, - primitiveCount ), "Failed to draw indexed primitive" ); - - mDeviceStatistics.mDrawCalls++; - if ( mVertexBufferFrequency[0] > 1 ) - mDeviceStatistics.mPolyCount += primitiveCount * mVertexBufferFrequency[0]; - else - mDeviceStatistics.mPolyCount += primitiveCount; -} - -GFXShader* GFXD3D9Device::createShader() -{ - GFXD3D9Shader* shader = new GFXD3D9Shader(); - shader->registerResourceWithDevice( this ); - return shader; -} - -void GFXD3D9Device::disableShaders(bool force) -{ - setShader( NULL, force ); - setShaderConstBuffer( NULL ); -} - -//----------------------------------------------------------------------------- -// Set shader - this function exists to make sure this is done in one place, -// and to make sure redundant shader states are not being -// sent to the card. -//----------------------------------------------------------------------------- -void GFXD3D9Device::setShader( GFXShader *shader, bool force ) -{ - GFXD3D9Shader *d3dShader = static_cast( shader ); - - IDirect3DPixelShader9 *pixShader = ( d3dShader != NULL ? d3dShader->mPixShader : NULL ); - IDirect3DVertexShader9 *vertShader = ( d3dShader ? d3dShader->mVertShader : NULL ); - - if( pixShader != mLastPixShader || force ) - { - mD3DDevice->SetPixelShader( pixShader ); - mLastPixShader = pixShader; - } - - if( vertShader != mLastVertShader || force ) - { - mD3DDevice->SetVertexShader( vertShader ); - mLastVertShader = vertShader; - } -} - -//----------------------------------------------------------------------------- -// allocPrimitiveBuffer -//----------------------------------------------------------------------------- -GFXPrimitiveBuffer * GFXD3D9Device::allocPrimitiveBuffer( U32 numIndices, - U32 numPrimitives, - GFXBufferType bufferType, - void* data ) -{ - // Allocate a buffer to return - GFXD3D9PrimitiveBuffer * res = new GFXD3D9PrimitiveBuffer(this, numIndices, numPrimitives, bufferType); - - // Determine usage flags - U32 usage = 0; - D3DPOOL pool = D3DPOOL_DEFAULT; - - // Assumptions: - // - static buffers are write rarely, use many - // - dynamic buffers are write many, use many - // - volatile buffers are write once, use once - // You may never read from a buffer. - switch(bufferType) - { - case GFXBufferTypeImmutable: - case GFXBufferTypeStatic: - pool = isD3D9Ex() ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED; - break; - - case GFXBufferTypeDynamic: - case GFXBufferTypeVolatile: -#ifndef TORQUE_OS_XENON - usage |= D3DUSAGE_DYNAMIC; -#endif - break; - } - - // Register resource - res->registerResourceWithDevice(this); - - // We never allow reading from a primitive buffer. - usage |= D3DUSAGE_WRITEONLY; - - // Create d3d index buffer - if(bufferType == GFXBufferTypeVolatile) - { - // Get it from the pool if it's a volatile... - AssertFatal( numIndices < MAX_DYNAMIC_INDICES, "Cannot allocate that many indices in a volatile buffer, increase MAX_DYNAMIC_INDICES." ); - - res->ib = mDynamicPB->ib; - // mDynamicPB->ib->AddRef(); - res->mVolatileBuffer = mDynamicPB; - } - else - { - // Otherwise, get it as a seperate buffer... - D3D9Assert(mD3DDevice->CreateIndexBuffer( sizeof(U16) * numIndices , usage, GFXD3D9IndexFormat[GFXIndexFormat16], pool, &res->ib, 0), - "Failed to allocate an index buffer."); - } - - if(data) - { - void* dest; - res->lock(0, numIndices, &dest); - dMemcpy(dest, data, sizeof(U16) * numIndices); - res->unlock(); - } - - return res; -} - -//----------------------------------------------------------------------------- -// allocVertexBuffer -//----------------------------------------------------------------------------- -GFXVertexBuffer * GFXD3D9Device::allocVertexBuffer( U32 numVerts, - const GFXVertexFormat *vertexFormat, - U32 vertSize, - GFXBufferType bufferType, - void* data) -{ - PROFILE_SCOPE( GFXD3D9Device_allocVertexBuffer ); - - GFXD3D9VertexBuffer *res = new GFXD3D9VertexBuffer( this, - numVerts, - vertexFormat, - vertSize, - bufferType ); - - // Determine usage flags - U32 usage = 0; - D3DPOOL pool = D3DPOOL_DEFAULT; - - res->mNumVerts = 0; - - // Assumptions: - // - static buffers are write rarely, use many - // - dynamic buffers are write many, use many - // - volatile buffers are write once, use once - // You may never read from a buffer. - - switch(bufferType) - { - case GFXBufferTypeImmutable: - case GFXBufferTypeStatic: - pool = isD3D9Ex() ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED; - break; - - case GFXBufferTypeDynamic: - case GFXBufferTypeVolatile: - pool = D3DPOOL_DEFAULT; - usage |= D3DUSAGE_WRITEONLY; -#ifndef TORQUE_OS_XENON - usage |= D3DUSAGE_DYNAMIC; -#endif - break; - } - - res->registerResourceWithDevice(this); - - // Create vertex buffer - if( bufferType == GFXBufferTypeVolatile ) - { - // NOTE: Volatile VBs are pooled and will be allocated at lock time. - - AssertFatal( numVerts <= MAX_DYNAMIC_VERTS, - "GFXD3D9Device::allocVertexBuffer - Volatile vertex buffer is too big... see MAX_DYNAMIC_VERTS!" ); - } - else - { - // Requesting it will allocate it. - vertexFormat->getDecl(); - - // Get a new buffer... - D3D9Assert( mD3DDevice->CreateVertexBuffer( vertSize * numVerts, usage, 0, pool, &res->vb, NULL ), - "Failed to allocate VB" ); - } - - res->mNumVerts = numVerts; - - if(data) - { - void* dest; - res->lock(0, numVerts, &dest); - dMemcpy(dest, data, vertSize * numVerts); - res->unlock(); - } - - return res; -} - -//----------------------------------------------------------------------------- -// deallocate vertex buffer -//----------------------------------------------------------------------------- -void GFXD3D9Device::deallocVertexBuffer( GFXD3D9VertexBuffer *vertBuff ) -{ - SAFE_RELEASE(vertBuff->vb); -} - -GFXVertexDecl* GFXD3D9Device::allocVertexDecl( const GFXVertexFormat *vertexFormat ) -{ - PROFILE_SCOPE( GFXD3D9Device_allocVertexDecl ); - - // First check the map... you shouldn't allocate VBs very often - // if you want performance. The map lookup should never become - // a performance bottleneck. - D3D9VertexDecl *decl = mVertexDecls[vertexFormat->getDescription()]; - if ( decl ) - return decl; - - // Setup the declaration struct. - U32 elemCount = vertexFormat->getElementCount(); - U32 offsets[4] = { 0 }; - U32 stream; - S32 i = 0; - S32 elemIdx = 0; - D3DVERTEXELEMENT9 *vd = new D3DVERTEXELEMENT9[ elemCount + 1 ]; - for ( i=0; elemIdx < elemCount; i++, elemIdx++ ) - { - const GFXVertexElement &element = vertexFormat->getElement( elemIdx ); - - stream = element.getStreamIndex(); - - vd[i].Stream = stream; - vd[i].Offset = offsets[stream]; - vd[i].Type = GFXD3D9DeclType[element.getType()]; - vd[i].Method = D3DDECLMETHOD_DEFAULT; - - // We force the usage index of 0 for everything but - // texture coords for now... this may change later. - vd[i].UsageIndex = 0; - - if ( element.isSemantic( GFXSemantic::POSITION ) ) - vd[i].Usage = D3DDECLUSAGE_POSITION; - else if ( element.isSemantic( GFXSemantic::NORMAL ) ) - vd[i].Usage = D3DDECLUSAGE_NORMAL; - else if ( element.isSemantic( GFXSemantic::COLOR ) ) - vd[i].Usage = D3DDECLUSAGE_COLOR; - else if ( element.isSemantic( GFXSemantic::TANGENT ) ) - vd[i].Usage = D3DDECLUSAGE_TANGENT; - else if ( element.isSemantic( GFXSemantic::BINORMAL ) ) - vd[i].Usage = D3DDECLUSAGE_BINORMAL; - else if ( element.isSemantic( GFXSemantic::BLENDINDICES ) ) - { - vd[i].Usage = D3DDECLUSAGE_BLENDINDICES; - vd[i].UsageIndex = element.getSemanticIndex(); - } - else if ( element.isSemantic( GFXSemantic::BLENDWEIGHT ) ) - { - vd[i].Usage = D3DDECLUSAGE_BLENDWEIGHT; - vd[i].UsageIndex = element.getSemanticIndex(); - } - else if ( element.isSemantic( GFXSemantic::PADDING ) ) - i--; - else - { - // Anything that falls thru to here will be a texture coord. - vd[i].Usage = D3DDECLUSAGE_TEXCOORD; - vd[i].UsageIndex = element.getSemanticIndex(); - } - - offsets[stream] += element.getSizeInBytes(); - } - - D3DVERTEXELEMENT9 declEnd = D3DDECL_END(); - vd[i] = declEnd; - - decl = new D3D9VertexDecl(); - D3D9Assert( mD3DDevice->CreateVertexDeclaration( vd, &decl->decl ), - "GFXD3D9Device::allocVertexDecl - Failed to create vertex declaration!" ); - - delete [] vd; - - // Store it in the cache. - mVertexDecls[vertexFormat->getDescription()] = decl; - - return decl; -} - -void GFXD3D9Device::setVertexDecl( const GFXVertexDecl *decl ) -{ - IDirect3DVertexDeclaration9 *dx9Decl = NULL; - if ( decl ) - dx9Decl = static_cast( decl )->decl; - D3D9Assert( mD3DDevice->SetVertexDeclaration( dx9Decl ), "GFXD3D9Device::setVertexDecl - Failed to set vertex declaration." ); -} - -//----------------------------------------------------------------------------- -// This function should ONLY be called from GFXDevice::updateStates() !!! -//----------------------------------------------------------------------------- -void GFXD3D9Device::setTextureInternal( U32 textureUnit, const GFXTextureObject *texture) -{ - if( texture == NULL ) - { - D3D9Assert(mD3DDevice->SetTexture( textureUnit, NULL ), "Failed to set texture to null!"); - return; - } - - GFXD3D9TextureObject *tex = (GFXD3D9TextureObject *) texture; - D3D9Assert(mD3DDevice->SetTexture( textureUnit, tex->getTex()), "Failed to set texture to valid value!"); -} - -//----------------------------------------------------------------------------- -// This function should ONLY be called from GFXDevice::updateStates() !!! -//----------------------------------------------------------------------------- -void GFXD3D9Device::setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable) -{ -#ifndef TORQUE_OS_XENON - if(!lightEnable) - { - mD3DDevice->LightEnable(lightStage, false); - return; - } - D3DLIGHT9 d3dLight; - switch (light.mType) - { - case GFXLightInfo::Ambient: - AssertFatal(false, "Instead of setting an ambient light you should set the global ambient color."); - return; - case GFXLightInfo::Vector: - d3dLight.Type = D3DLIGHT_DIRECTIONAL; - break; - - case GFXLightInfo::Point: - d3dLight.Type = D3DLIGHT_POINT; - break; - - case GFXLightInfo::Spot: - d3dLight.Type = D3DLIGHT_SPOT; - break; - - default : - AssertFatal(false, "Unknown light type!"); - }; - - dMemcpy(&d3dLight.Diffuse, &light.mColor, sizeof(light.mColor)); - dMemcpy(&d3dLight.Ambient, &light.mAmbient, sizeof(light.mAmbient)); - dMemcpy(&d3dLight.Specular, &light.mColor, sizeof(light.mColor)); - dMemcpy(&d3dLight.Position, &light.mPos, sizeof(light.mPos)); - dMemcpy(&d3dLight.Direction, &light.mDirection, sizeof(light.mDirection)); - - d3dLight.Range = light.mRadius; - - d3dLight.Falloff = 1.0; - - d3dLight.Attenuation0 = 1.0f; - d3dLight.Attenuation1 = 0.1f; - d3dLight.Attenuation2 = 0.0f; - - d3dLight.Theta = light.mInnerConeAngle; - d3dLight.Phi = light.mOuterConeAngle; - - mD3DDevice->SetLight(lightStage, &d3dLight); - mD3DDevice->LightEnable(lightStage, true); -#endif -} - -void GFXD3D9Device::setLightMaterialInternal(const GFXLightMaterial mat) -{ -#ifndef TORQUE_OS_XENON - D3DMATERIAL9 d3dmat; - dMemset(&d3dmat, 0, sizeof(D3DMATERIAL9)); - D3DCOLORVALUE col; - - col.r = mat.ambient.red; - col.g = mat.ambient.green; - col.b = mat.ambient.blue; - col.a = mat.ambient.alpha; - d3dmat.Ambient = col; - - col.r = mat.diffuse.red; - col.g = mat.diffuse.green; - col.b = mat.diffuse.blue; - col.a = mat.diffuse.alpha; - d3dmat.Diffuse = col; - - col.r = mat.specular.red; - col.g = mat.specular.green; - col.b = mat.specular.blue; - col.a = mat.specular.alpha; - d3dmat.Specular = col; - - col.r = mat.emissive.red; - col.g = mat.emissive.green; - col.b = mat.emissive.blue; - col.a = mat.emissive.alpha; - d3dmat.Emissive = col; - - d3dmat.Power = mat.shininess; - mD3DDevice->SetMaterial(&d3dmat); -#endif -} - -void GFXD3D9Device::setGlobalAmbientInternal(ColorF color) -{ -#ifndef TORQUE_OS_XENON - mD3DDevice->SetRenderState(D3DRS_AMBIENT, - D3DCOLOR_COLORVALUE(color.red, color.green, color.blue, color.alpha)); -#endif -} - -//------------------------------------------------------------------------------ -// Check for texture mis-match between GFX internal state and what is on the card -// This function is expensive because of the readbacks from DX, and additionally -// won't work unless it's a non-pure device. -// -// This function can crash or give false positives when the game -// is shutting down or returning to the main menu as some of the textures -// present in the mCurrentTexture array will have been freed. -// -// This function is best used as a quick check for mismatched state when it is -// suspected. -//------------------------------------------------------------------------------ -void GFXD3D9Device::doParanoidStateCheck() -{ -#ifdef TORQUE_DEBUG - // Read back all states and make sure they match what we think they should be. - - // For now just do texture binds. - for(U32 i = 0; i < getNumSamplers(); i++) - { - IDirect3DBaseTexture9 *b=NULL; - getDevice()->GetTexture(i, &b); - if ((mCurrentTexture[i].isNull()) && (mCurrentCubemap[i].isNull())) - { - AssertFatal(b == NULL, "GFXD3D9Device::doParanoidStateCheck - got non-null texture in expected NULL slot!"); - getDevice()->SetTexture(i, NULL); - } - else - { - AssertFatal(mCurrentTexture[i] || mCurrentCubemap[i], "GFXD3D9Device::doParanoidStateCheck - got null texture in expected non-null slot!"); - if (mCurrentCubemap[i]) - { - IDirect3DCubeTexture9 *cur= static_cast(mCurrentCubemap[i].getPointer())->mCubeTex; - AssertFatal(cur == b, "GFXD3D9Device::doParanoidStateCheck - mismatched cubemap!"); - } - else - { - IDirect3DBaseTexture9 *cur= static_cast(mCurrentTexture[i].getPointer())->getTex(); - AssertFatal(cur == b, "GFXD3D9Device::doParanoidStateCheck - mismatched 2d texture!"); - } - } - - SAFE_RELEASE(b); - } -#endif -} - -GFXFence *GFXD3D9Device::createFence() -{ - // Figure out what fence type we should be making if we don't know - if( mCreateFenceType == -1 ) - { - IDirect3DQuery9 *testQuery = NULL; - mCreateFenceType = ( mD3DDevice->CreateQuery( D3DQUERYTYPE_EVENT, &testQuery ) == D3DERR_NOTAVAILABLE ); - SAFE_RELEASE( testQuery ); - } - - // Cool, use queries - if( !mCreateFenceType ) - { - GFXFence* fence = new GFXD3D9QueryFence( this ); - fence->registerResourceWithDevice(this); - return fence; - } - - // CodeReview: At some point I would like a specialized D3D9 implementation of - // the method used by the general fence, only without the overhead incurred - // by using the GFX constructs. Primarily the lock() method on texture handles - // will do a data copy, and this method doesn't require a copy, just a lock - // [5/10/2007 Pat] - GFXFence* fence = new GFXGeneralFence( this ); - fence->registerResourceWithDevice(this); - return fence; -} - -GFXOcclusionQuery* GFXD3D9Device::createOcclusionQuery() -{ - GFXOcclusionQuery *query; - if (mOcclusionQuerySupported) - query = new GFXD3D9OcclusionQuery( this ); - else - return NULL; - - query->registerResourceWithDevice(this); - return query; -} - -GFXCubemap * GFXD3D9Device::createCubemap() -{ - GFXD3D9Cubemap* cube = new GFXD3D9Cubemap(); - cube->registerResourceWithDevice(this); - return cube; -} diff --git a/Engine/source/gfx/D3D9/gfxD3D9Device.h b/Engine/source/gfx/D3D9/gfxD3D9Device.h deleted file mode 100644 index dfb880915..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9Device.h +++ /dev/null @@ -1,363 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFXD3D9DEVICE_H_ -#define _GFXD3D9DEVICE_H_ - -#include "platform/tmm_off.h" - -#ifdef TORQUE_OS_XENON -# include "platformXbox/platformXbox.h" -#else -# include -# include "platformWin32/platformWin32.h" -#endif -#ifndef _GFXD3D9STATEBLOCK_H_ -#include "gfx/D3D9/gfxD3D9StateBlock.h" -#endif -#ifndef _GFXD3DTEXTUREMANAGER_H_ -#include "gfx/D3D9/gfxD3D9TextureManager.h" -#endif -#ifndef _GFXD3D9CUBEMAP_H_ -#include "gfx/D3D9/gfxD3D9Cubemap.h" -#endif -#ifndef _GFXD3D9PRIMITIVEBUFFER_H_ -#include "gfx/D3D9/gfxD3D9PrimitiveBuffer.h" -#endif -#ifndef _GFXINIT_H_ -#include "gfx/gfxInit.h" -#endif -#ifndef _PLATFORMDLIBRARY_H -#include "platform/platformDlibrary.h" -#endif - -#ifndef TORQUE_OS_XENON -#include -#else -#include -#define DXGetErrorStringA DXGetErrorString9A -#define DXGetErrorDescriptionA DXGetErrorDescription9A -#endif - -#include "platform/tmm_on.h" - -inline void D3D9Assert( HRESULT hr, const char *info ) -{ -#if defined( TORQUE_DEBUG ) - if( FAILED( hr ) ) - { - char buf[256]; - dSprintf( buf, 256, "%s\n%s\n%s", DXGetErrorStringA( hr ), DXGetErrorDescriptionA( hr ), info ); - AssertFatal( false, buf ); - // DXTrace( __FILE__, __LINE__, hr, info, true ); - } -#endif -} - - -// Typedefs -#define D3DX_FUNCTION(fn_name, fn_return, fn_args) \ - typedef fn_return (WINAPI *D3DXFNPTR##fn_name)fn_args; -#include "gfx/D3D9/d3dx9Functions.h" -#undef D3DX_FUNCTION - -// Function table -struct D3DXFNTable -{ - D3DXFNTable() : isLoaded( false ){}; - bool isLoaded; - DLibraryRef dllRef; - DLibraryRef compilerDllRef; -#define D3DX_FUNCTION(fn_name, fn_return, fn_args) \ - D3DXFNPTR##fn_name fn_name; -#include "gfx/D3D9/d3dx9Functions.h" -#undef D3DX_FUNCTION -}; - -#define GFXD3DX static_cast(GFX)->smD3DX - -class GFXResource; -class GFXD3D9ShaderConstBuffer; - -//------------------------------------------------------------------------------ - -class GFXD3D9Device : public GFXDevice -{ - friend class GFXResource; - friend class GFXD3D9PrimitiveBuffer; - friend class GFXD3D9VertexBuffer; - friend class GFXD3D9TextureObject; - friend class GFXPCD3D9TextureTarget; - friend class GFXPCD3D9WindowTarget; - - typedef GFXDevice Parent; - -protected: - - MatrixF mTempMatrix; ///< Temporary matrix, no assurances on value at all - RectI mClipRect; - - typedef StrongRefPtr RPGDVB; - Vector mVolatileVBList; - - class D3D9VertexDecl : public GFXVertexDecl - { - public: - virtual ~D3D9VertexDecl() - { - SAFE_RELEASE( decl ); - } - - IDirect3DVertexDeclaration9 *decl; - }; - - /// Used to lookup a vertex declaration for the vertex format. - /// @see allocVertexDecl - typedef Map VertexDeclMap; - VertexDeclMap mVertexDecls; - - IDirect3DSurface9 *mDeviceBackbuffer; - IDirect3DSurface9 *mDeviceDepthStencil; - IDirect3DSurface9 *mDeviceColor; - - /// The stream 0 vertex buffer used for volatile VB offseting. - GFXD3D9VertexBuffer *mVolatileVB; - - static void initD3DXFnTable(); - //----------------------------------------------------------------------- - StrongRefPtr mDynamicPB; ///< Dynamic index buffer - GFXD3D9PrimitiveBuffer *mCurrentPB; - - IDirect3DVertexShader9 *mLastVertShader; - IDirect3DPixelShader9 *mLastPixShader; - - GFXShaderRef mGenericShader[GS_COUNT]; - GFXShaderConstBufferRef mGenericShaderBuffer[GS_COUNT]; - GFXShaderConstHandle *mModelViewProjSC[GS_COUNT]; - - S32 mCreateFenceType; - - LPDIRECT3D9 mD3D; ///< D3D Handle - LPDIRECT3DDEVICE9 mD3DDevice; ///< Handle for D3DDevice - -#if !defined(TORQUE_OS_XENON) - LPDIRECT3D9EX mD3DEx; ///< D3D9Ex Handle - LPDIRECT3DDEVICE9EX mD3DDeviceEx; ///< Handle for D3DDevice9Ex -#endif - - U32 mAdapterIndex; ///< Adapter index because D3D supports multiple adapters - - F32 mPixVersion; - U32 mNumSamplers; ///< Profiled (via caps) - U32 mNumRenderTargets; ///< Profiled (via caps) - - D3DMULTISAMPLE_TYPE mMultisampleType; - DWORD mMultisampleLevel; - - bool mOcclusionQuerySupported; - - /// The current adapter display mode. - D3DDISPLAYMODE mDisplayMode; - - /// To manage creating and re-creating of these when device is aquired - void reacquireDefaultPoolResources(); - - /// To release all resources we control from D3DPOOL_DEFAULT - void releaseDefaultPoolResources(); - - /// This you will probably never, ever use, but it is used to generate the code for - /// the initStates() function - void regenStates(); - - virtual GFXD3D9VertexBuffer* findVBPool( const GFXVertexFormat *vertexFormat, U32 numVertsNeeded ); - virtual GFXD3D9VertexBuffer* createVBPool( const GFXVertexFormat *vertexFormat, U32 vertSize ); - -#ifdef TORQUE_DEBUG - /// @name Debug Vertex Buffer information/management - /// @{ - - /// - U32 mNumAllocatedVertexBuffers; ///< To keep track of how many are allocated and freed - GFXD3D9VertexBuffer *mVBListHead; - void addVertexBuffer( GFXD3D9VertexBuffer *buffer ); - void removeVertexBuffer( GFXD3D9VertexBuffer *buffer ); - void logVertexBuffers(); - /// @} -#endif - - // State overrides - // { - - /// - virtual void setTextureInternal(U32 textureUnit, const GFXTextureObject* texture); - - /// Called by GFXDevice to create a device specific stateblock - virtual GFXStateBlockRef createStateBlockInternal(const GFXStateBlockDesc& desc); - /// Called by GFXDevice to actually set a stateblock. - virtual void setStateBlockInternal(GFXStateBlock* block, bool force); - - /// Track the last const buffer we've used. Used to notify new constant buffers that - /// they should send all of their constants up - StrongRefPtr mCurrentConstBuffer; - /// Called by base GFXDevice to actually set a const buffer - virtual void setShaderConstBufferInternal(GFXShaderConstBuffer* buffer); - - // CodeReview - How exactly do we want to deal with this on the Xenon? - // Right now it's just in an #ifndef in gfxD3D9Device.cpp - AlexS 4/11/07 - virtual void setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable); - virtual void setLightMaterialInternal(const GFXLightMaterial mat); - virtual void setGlobalAmbientInternal(ColorF color); - - virtual void initStates()=0; - // } - - // Index buffer management - // { - virtual void _setPrimitiveBuffer( GFXPrimitiveBuffer *buffer ); - virtual void drawIndexedPrimitive( GFXPrimitiveType primType, - U32 startVertex, - U32 minIndex, - U32 numVerts, - U32 startIndex, - U32 primitiveCount ); - // } - - virtual GFXShader* createShader(); - void disableShaders(bool force = false); - - /// Device helper function - virtual D3DPRESENT_PARAMETERS setupPresentParams( const GFXVideoMode &mode, const HWND &hwnd ) const = 0; - -public: - static D3DXFNTable smD3DX; - - static GFXDevice *createInstance( U32 adapterIndex ); - - GFXTextureObject* createRenderSurface( U32 width, U32 height, GFXFormat format, U32 mipLevel ); - - const D3DDISPLAYMODE& getDisplayMode() const { return mDisplayMode; } - - /// Constructor - /// @param d3d Direct3D object to instantiate this device with - /// @param index Adapter index since D3D can use multiple graphics adapters - GFXD3D9Device( LPDIRECT3D9 d3d, U32 index ); - virtual ~GFXD3D9Device(); - - // Activate/deactivate - // { - virtual void init( const GFXVideoMode &mode, PlatformWindow *window = NULL ) = 0; - - virtual void preDestroy() { Parent::preDestroy(); if(mTextureManager) mTextureManager->kill(); } - - GFXAdapterType getAdapterType(){ return Direct3D9; } - - U32 getAdaterIndex() const { return mAdapterIndex; } - - virtual GFXCubemap *createCubemap(); - - virtual F32 getPixelShaderVersion() const { return mPixVersion; } - virtual void setPixelShaderVersion( F32 version ){ mPixVersion = version; } - virtual void setShader( GFXShader *shader, bool force = false ); - virtual U32 getNumSamplers() const { return mNumSamplers; } - virtual U32 getNumRenderTargets() const { return mNumRenderTargets; } - // } - - // Misc rendering control - // { - virtual void clear( U32 flags, ColorI color, F32 z, U32 stencil ); - virtual bool beginSceneInternal(); - virtual void endSceneInternal(); - - virtual void setClipRect( const RectI &rect ); - virtual const RectI& getClipRect() const { return mClipRect; } - - // } - - /// @name Render Targets - /// @{ - virtual void _updateRenderTargets(); - /// @} - - // Vertex/Index buffer management - // { - virtual GFXVertexBuffer* allocVertexBuffer( U32 numVerts, - const GFXVertexFormat *vertexFormat, - U32 vertSize, - GFXBufferType bufferType, - void* data = NULL ); - virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices, - U32 numPrimitives, - GFXBufferType bufferType, - void* data = NULL ); - virtual void deallocVertexBuffer( GFXD3D9VertexBuffer *vertBuff ); - virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat ); - virtual void setVertexDecl( const GFXVertexDecl *decl ); - - virtual void setVertexStream( U32 stream, GFXVertexBuffer *buffer ); - virtual void setVertexStreamFrequency( U32 stream, U32 frequency ); - // } - - virtual U32 getMaxDynamicVerts() { return MAX_DYNAMIC_VERTS; } - virtual U32 getMaxDynamicIndices() { return MAX_DYNAMIC_INDICES; } - - // Rendering - // { - virtual void drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount ); - // } - - virtual LPDIRECT3DDEVICE9 getDevice(){ return mD3DDevice; } - virtual LPDIRECT3D9 getD3D() { return mD3D; } - - /// Reset - virtual void reset( D3DPRESENT_PARAMETERS &d3dpp ) = 0; - - virtual void setupGenericShaders( GenericShaderType type = GSColor ); - - // Function only really used on the, however a centralized function for - // destroying resources is probably a good thing -patw - virtual void destroyD3DResource( IDirect3DResource9 *d3dResource ) { SAFE_RELEASE( d3dResource ); }; - - inline virtual F32 getFillConventionOffset() const { return 0.5f; } - virtual void doParanoidStateCheck(); - - GFXFence *createFence(); - - GFXOcclusionQuery* createOcclusionQuery(); - - // Default multisample parameters - D3DMULTISAMPLE_TYPE getMultisampleType() const { return mMultisampleType; } - DWORD getMultisampleLevel() const { return mMultisampleLevel; } - - // Whether or not the Direct3D device was created with Direct3D9Ex support -#if !defined(TORQUE_OS_XENON) - virtual bool isD3D9Ex() { return mD3DEx != NULL; } -#else - virtual bool isD3D9Ex() { return false; } -#endif - - // Get the backbuffer, currently only access for WPF support - virtual IDirect3DSurface9* getBackBuffer() { return mDeviceBackbuffer; } - -}; - - -#endif // _GFXD3D9DEVICE_H_ diff --git a/Engine/source/gfx/D3D9/gfxD3D9Device.regen-states.cpp b/Engine/source/gfx/D3D9/gfxD3D9Device.regen-states.cpp deleted file mode 100644 index 8160cc688..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9Device.regen-states.cpp +++ /dev/null @@ -1,92 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/gfxD3D9Device.h" -#include "console/console.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" - -// Cut and paste from console.log into GFXD3D9Device::initStates() -void GFXD3D9Device::regenStates() -{ - DWORD temp; - Con::printf( " //-------------------------------------" ); - Con::printf( " // Auto-generated default states, see regenStates() for details" ); - Con::printf( " //" ); - Con::printf( "" ); - Con::printf( " // Render states" ); - - for( U32 state = GFXRenderState_FIRST; state < GFXRenderState_COUNT; state++ ) - { - if( GFXD3D9RenderState[state] == GFX_UNSUPPORTED_VAL ) - continue; - - temp = 0; - mD3DDevice->GetRenderState( GFXD3D9RenderState[state], &temp ); - Con::printf( " mD3DDevice->SetRenderState( GFXD3D9RenderState[%d], %d );", state, temp ); - } - -#ifndef TORQUE_OS_XENON - Con::printf( "" ); - Con::printf( " // Texture Stage states" ); - - for( U32 stage = 0; stage < TEXTURE_STAGE_COUNT; stage++ ) - { - if( stage >= GFX->getNumSamplers() ) - { - Con::errorf( "Sampler %d out of range for this device, ignoring.", stage ); - break; - } - - for( U32 state = GFXTSS_FIRST; state < GFXTSS_COUNT; state++ ) - { - if( GFXD3D9TextureStageState[state] == GFX_UNSUPPORTED_VAL ) - continue; - - temp = 0; - mD3DDevice->GetTextureStageState( stage, GFXD3D9TextureStageState[state], &temp ); - Con::printf( " mD3DDevice->SetTextureStageState( %d, GFXD3D9TextureStageState[%d], %d );", stage, state, temp ); - } - } -#endif - - Con::printf( "" ); - Con::printf( " // Sampler states" ); - for( U32 stage = 0; stage < TEXTURE_STAGE_COUNT; stage++ ) - { - if( stage >= GFX->getNumSamplers() ) - { - Con::errorf( "Sampler %d out of range for this device, ignoring.", stage ); - break; - } - - for( U32 state = GFXSAMP_FIRST; state < GFXSAMP_COUNT; state++ ) - { - if( GFXD3D9SamplerState[state] == GFX_UNSUPPORTED_VAL ) - continue; - - temp = 0; - - mD3DDevice->GetSamplerState( stage, GFXD3D9SamplerState[state], &temp ); - Con::printf( " mD3DDevice->SetSamplerState( %d, GFXD3D9SamplerState[%d], %d );", stage, state, temp ); - } - } -} diff --git a/Engine/source/gfx/D3D9/gfxD3D9EnumTranslate.h b/Engine/source/gfx/D3D9/gfxD3D9EnumTranslate.h deleted file mode 100644 index a8ccc0496..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9EnumTranslate.h +++ /dev/null @@ -1,63 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/gfxD3D9Shader.h" - -#include "gfx/gfxEnums.h" - -//------------------------------------------------------------------------------ - -namespace GFXD3D9EnumTranslate -{ - void init(); -}; - -//------------------------------------------------------------------------------ - -extern _D3DFORMAT GFXD3D9IndexFormat[GFXIndexFormat_COUNT]; -extern _D3DSAMPLERSTATETYPE GFXD3D9SamplerState[GFXSAMP_COUNT]; -extern _D3DFORMAT GFXD3D9TextureFormat[GFXFormat_COUNT]; -#ifdef TORQUE_OS_XENON -extern _D3DFORMAT GFXD3D9RenderTargetFormat[GFXFormat_COUNT]; -#endif -extern _D3DRENDERSTATETYPE GFXD3D9RenderState[GFXRenderState_COUNT]; -extern _D3DTEXTUREFILTERTYPE GFXD3D9TextureFilter[GFXTextureFilter_COUNT]; -extern _D3DBLEND GFXD3D9Blend[GFXBlend_COUNT]; -extern _D3DBLENDOP GFXD3D9BlendOp[GFXBlendOp_COUNT]; -extern _D3DSTENCILOP GFXD3D9StencilOp[GFXStencilOp_COUNT]; -extern _D3DCMPFUNC GFXD3D9CmpFunc[GFXCmp_COUNT]; -extern _D3DCULL GFXD3D9CullMode[GFXCull_COUNT]; -extern _D3DFILLMODE GFXD3D9FillMode[GFXFill_COUNT]; -extern _D3DPRIMITIVETYPE GFXD3D9PrimType[GFXPT_COUNT]; -extern _D3DTEXTURESTAGESTATETYPE GFXD3D9TextureStageState[GFXTSS_COUNT]; -extern _D3DTEXTUREADDRESS GFXD3D9TextureAddress[GFXAddress_COUNT]; -extern _D3DTEXTUREOP GFXD3D9TextureOp[GFXTOP_COUNT]; -extern _D3DDECLTYPE GFXD3D9DeclType[GFXDeclType_COUNT]; - -#define GFXREVERSE_LOOKUP( tablearray, enumprefix, val ) \ - for( S32 i = enumprefix##_FIRST; i < enumprefix##_COUNT; i++ ) \ - if( (S32)tablearray[i] == val ) \ - { \ - val = i; \ - break; \ - } \ - diff --git a/Engine/source/gfx/D3D9/gfxD3D9OcclusionQuery.cpp b/Engine/source/gfx/D3D9/gfxD3D9OcclusionQuery.cpp deleted file mode 100644 index 8d36776ca..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9OcclusionQuery.cpp +++ /dev/null @@ -1,171 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/gfxD3D9Device.h" -#include "gfx/D3D9/gfxD3D9OcclusionQuery.h" - -#include "gui/3d/guiTSControl.h" - -#ifdef TORQUE_GATHER_METRICS -// For TickMs define -#include "T3D/gameBase/processList.h" -#endif - -GFXD3D9OcclusionQuery::GFXD3D9OcclusionQuery( GFXDevice *device ) - : GFXOcclusionQuery( device ), - mQuery( NULL ) -{ -#ifdef TORQUE_GATHER_METRICS - mTimer = PlatformTimer::create(); - mTimer->getElapsedMs(); - - mTimeSinceEnd = 0; - mBeginFrame = 0; -#endif -} - -GFXD3D9OcclusionQuery::~GFXD3D9OcclusionQuery() -{ - SAFE_RELEASE( mQuery ); - -#ifdef TORQUE_GATHER_METRICS - SAFE_DELETE( mTimer ); -#endif -} - -bool GFXD3D9OcclusionQuery::begin() -{ - if ( GFXDevice::getDisableOcclusionQuery() ) - return true; - - if ( mQuery == NULL ) - { -#ifdef TORQUE_OS_XENON - HRESULT hRes = static_cast( mDevice )->getDevice()->CreateQueryTiled( D3DQUERYTYPE_OCCLUSION, 2, &mQuery ); -#else - HRESULT hRes = static_cast( mDevice )->getDevice()->CreateQuery( D3DQUERYTYPE_OCCLUSION, &mQuery ); -#endif - - AssertFatal( hRes != D3DERR_NOTAVAILABLE, "GFXD3D9OcclusionQuery::begin - Hardware does not support D3D9 Occlusion-Queries, this should be caught before this type is created" ); - AssertISV( hRes != E_OUTOFMEMORY, "GFXD3D9OcclusionQuery::begin - Out of memory" ); - } - - // Add a begin marker to the command buffer queue. - mQuery->Issue( D3DISSUE_BEGIN ); - -#ifdef TORQUE_GATHER_METRICS - mBeginFrame = GuiTSCtrl::getFrameCount(); -#endif - - return true; -} - -void GFXD3D9OcclusionQuery::end() -{ - if ( GFXDevice::getDisableOcclusionQuery() ) - return; - - // Add an end marker to the command buffer queue. - mQuery->Issue( D3DISSUE_END ); - -#ifdef TORQUE_GATHER_METRICS - AssertFatal( mBeginFrame == GuiTSCtrl::getFrameCount(), "GFXD3D9OcclusionQuery::end - ended query on different frame than begin!" ); - mTimer->getElapsedMs(); - mTimer->reset(); -#endif -} - -GFXD3D9OcclusionQuery::OcclusionQueryStatus GFXD3D9OcclusionQuery::getStatus( bool block, U32 *data ) -{ - // If this ever shows up near the top of a profile then your system is - // GPU bound or you are calling getStatus too soon after submitting it. - // - // To test if you are GPU bound resize your window very small and see if - // this profile no longer appears at the top. - // - // To test if you are calling getStatus to soon after submitting it, - // check the value of mTimeSinceEnd in a debug build. If it is < half the length - // of time to render an individual frame you could have problems. - PROFILE_SCOPE(GFXD3D9OcclusionQuery_getStatus); - - if ( GFXDevice::getDisableOcclusionQuery() ) - return NotOccluded; - - if ( mQuery == NULL ) - return Unset; - -#ifdef TORQUE_GATHER_METRICS - //AssertFatal( mBeginFrame < GuiTSCtrl::getFrameCount(), "GFXD3D9OcclusionQuery::getStatus - called on the same frame as begin!" ); - - //U32 mTimeSinceEnd = mTimer->getElapsedMs(); - //AssertFatal( mTimeSinceEnd >= 5, "GFXD3DOcculsionQuery::getStatus - less than TickMs since called ::end!" ); -#endif - - HRESULT hRes; - DWORD dwOccluded = 0; - - if ( block ) - { - while( ( hRes = mQuery->GetData( &dwOccluded, sizeof(DWORD), D3DGETDATA_FLUSH ) ) == S_FALSE ) - { - //If we're stalled out, proceed with worst-case scenario -BJR - if(GFX->mFrameTime->getElapsedMs()>4) - { - this->begin(); - this->end(); - return NotOccluded; - } - } - } - else - { - hRes = mQuery->GetData( &dwOccluded, sizeof(DWORD), 0 ); - } - - if ( hRes == S_OK ) - { - if ( data != NULL ) - *data = dwOccluded; - - return dwOccluded > 0 ? NotOccluded : Occluded; - } - - if ( hRes == S_FALSE ) - return Waiting; - - return Error; -} - -void GFXD3D9OcclusionQuery::zombify() -{ - SAFE_RELEASE( mQuery ); -} - -void GFXD3D9OcclusionQuery::resurrect() -{ -} - -const String GFXD3D9OcclusionQuery::describeSelf() const -{ - // We've got nothing - return String(); -} \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/gfxD3D9OcclusionQuery.h b/Engine/source/gfx/D3D9/gfxD3D9OcclusionQuery.h deleted file mode 100644 index 062653b40..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9OcclusionQuery.h +++ /dev/null @@ -1,64 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFX_D3D9_OCCLUSIONQUERY_H_ -#define _GFX_D3D9_OCCLUSIONQUERY_H_ - -#ifndef _GFXOCCLUSIONQUERY_H_ -#include "gfx/gfxOcclusionQuery.h" -#endif - -#ifdef TORQUE_GATHER_METRICS - #ifndef _PLATFORM_PLATFORMTIMER_H_ - #include "platform/platformTimer.h" - #endif -#endif - -struct IDirect3DQuery9; - - -class GFXD3D9OcclusionQuery : public GFXOcclusionQuery -{ -private: - mutable IDirect3DQuery9 *mQuery; - -#ifdef TORQUE_GATHER_METRICS - U32 mBeginFrame; - U32 mTimeSinceEnd; - PlatformTimer *mTimer; -#endif - -public: - GFXD3D9OcclusionQuery( GFXDevice *device ); - virtual ~GFXD3D9OcclusionQuery(); - - virtual bool begin(); - virtual void end(); - virtual OcclusionQueryStatus getStatus( bool block, U32 *data = NULL ); - - // GFXResource - virtual void zombify(); - virtual void resurrect(); - virtual const String describeSelf() const; -}; - -#endif // _GFX_D3D9_OCCLUSIONQUERY_H_ \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/gfxD3D9PrimitiveBuffer.cpp b/Engine/source/gfx/D3D9/gfxD3D9PrimitiveBuffer.cpp deleted file mode 100644 index 473694b5e..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9PrimitiveBuffer.cpp +++ /dev/null @@ -1,115 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/gfxD3D9Device.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" -#include "gfx/D3D9/gfxD3D9PrimitiveBuffer.h" -#include "core/util/safeRelease.h" - -void GFXD3D9PrimitiveBuffer::prepare() -{ - static_cast( mDevice )->_setPrimitiveBuffer(this); -} - -void GFXD3D9PrimitiveBuffer::unlock() -{ - #ifdef TORQUE_DEBUG - - if ( mDebugGuardBuffer ) - { - const U32 guardSize = sizeof( _PBGuardString ); - - // First check the guard areas for overwrites. - AssertFatal( dMemcmp( mDebugGuardBuffer, _PBGuardString, guardSize ) == 0, - "GFXD3D9PrimitiveBuffer::unlock - Caught lock memory underrun!" ); - AssertFatal( dMemcmp( mDebugGuardBuffer + mLockedSize + guardSize, _PBGuardString, guardSize ) == 0, - "GFXD3D9PrimitiveBuffer::unlock - Caught lock memory overrun!" ); - - // Copy the debug content down to the real PB. - dMemcpy( mLockedBuffer, mDebugGuardBuffer + guardSize, mLockedSize ); - - // Cleanup. - delete [] mDebugGuardBuffer; - mDebugGuardBuffer = NULL; - mLockedBuffer = NULL; - mLockedSize = 0; - } - - #endif // TORQUE_DEBUG - - ib->Unlock(); - mLocked = false; - mIsFirstLock = false; - mVolatileBuffer = NULL; -} - -GFXD3D9PrimitiveBuffer::~GFXD3D9PrimitiveBuffer() -{ - if( mBufferType != GFXBufferTypeVolatile ) - { -#if defined(TORQUE_OS_XENON) - if(ib->IsSet(reinterpret_cast(mDevice)->mD3DDevice)) - { - reinterpret_cast(mDevice)->mD3DDevice->SetIndices(NULL); - } -#endif - SAFE_RELEASE( ib ); - } -} - -void GFXD3D9PrimitiveBuffer::zombify() -{ - if(mBufferType == GFXBufferTypeStatic) - return; - - AssertFatal(!mLocked, "GFXD3D9PrimitiveBuffer::zombify - Cannot zombify a locked buffer!"); - - if (mBufferType == GFXBufferTypeVolatile) - { - // We must null the volatile buffer else we're holding - // a dead pointer which can be set on the device. - ib = NULL; - return; - } - - // Dynamic buffers get released. - SAFE_RELEASE(ib); -} - -void GFXD3D9PrimitiveBuffer::resurrect() -{ - if ( mBufferType != GFXBufferTypeDynamic ) - return; - - U32 usage = D3DUSAGE_WRITEONLY; - -#ifndef TORQUE_OS_XENON - usage |= D3DUSAGE_DYNAMIC; -#endif - - D3DPOOL pool = D3DPOOL_DEFAULT; - - D3D9Assert(static_cast(mDevice)->mD3DDevice->CreateIndexBuffer( sizeof(U16) * mIndexCount , - usage , GFXD3D9IndexFormat[GFXIndexFormat16], pool, &ib, 0), - "GFXD3D9PrimitiveBuffer::resurrect - Failed to allocate an index buffer."); -} - diff --git a/Engine/source/gfx/D3D9/gfxD3D9PrimitiveBuffer.h b/Engine/source/gfx/D3D9/gfxD3D9PrimitiveBuffer.h deleted file mode 100644 index 34a1cd902..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9PrimitiveBuffer.h +++ /dev/null @@ -1,87 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFXD3D9PRIMITIVEBUFFER_H_ -#define _GFXD3D9PRIMITIVEBUFFER_H_ - -#ifndef _GFXPRIMITIVEBUFFER_H_ -#include "gfx/gfxPrimitiveBuffer.h" -#endif - - -struct IDirect3DIndexBuffer9; - -class GFXD3D9PrimitiveBuffer : public GFXPrimitiveBuffer -{ - public: - IDirect3DIndexBuffer9 *ib; - StrongRefPtr mVolatileBuffer; - -#ifdef TORQUE_DEBUG - #define _PBGuardString "GFX_PRIMTIVE_BUFFER_GUARD_STRING" - U8 *mDebugGuardBuffer; - void *mLockedBuffer; - U32 mLockedSize; -#endif TORQUE_DEBUG - - bool mLocked; - bool mIsFirstLock; - - GFXD3D9PrimitiveBuffer( GFXDevice *device, - U32 indexCount, - U32 primitiveCount, - GFXBufferType bufferType ); - - virtual ~GFXD3D9PrimitiveBuffer(); - - virtual void lock(U32 indexStart, U32 indexEnd, void **indexPtr); - virtual void unlock(); - - virtual void prepare(); - -#ifdef TORQUE_DEBUG - //GFXD3D9PrimitiveBuffer *next; -#endif - - // GFXResource interface - virtual void zombify(); - virtual void resurrect(); -}; - -inline GFXD3D9PrimitiveBuffer::GFXD3D9PrimitiveBuffer( GFXDevice *device, - U32 indexCount, - U32 primitiveCount, - GFXBufferType bufferType ) - : GFXPrimitiveBuffer( device, indexCount, primitiveCount, bufferType ) -{ - mVolatileStart = 0; - ib = NULL; - mIsFirstLock = true; - mLocked = false; -#ifdef TORQUE_DEBUG - mDebugGuardBuffer = NULL; - mLockedBuffer = NULL; - mLockedSize = 0; -#endif -} - -#endif diff --git a/Engine/source/gfx/D3D9/gfxD3D9QueryFence.cpp b/Engine/source/gfx/D3D9/gfxD3D9QueryFence.cpp deleted file mode 100644 index 7056e00b2..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9QueryFence.cpp +++ /dev/null @@ -1,106 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/gfxD3D9Device.h" -#include "gfx/D3D9/gfxD3D9QueryFence.h" - -GFXD3D9QueryFence::~GFXD3D9QueryFence() -{ - SAFE_RELEASE( mQuery ); -} - -//------------------------------------------------------------------------------ - -void GFXD3D9QueryFence::issue() -{ - PROFILE_START( GFXD3D9QueryFence_issue ); - - // Create the query if we need to - if( mQuery == NULL ) - { - HRESULT hRes = static_cast( mDevice )->getDevice()->CreateQuery( D3DQUERYTYPE_EVENT, &mQuery ); - - AssertFatal( hRes != D3DERR_NOTAVAILABLE, "Hardware does not support D3D9 Queries, this should be caught before this fence type is created" ); - AssertISV( hRes != E_OUTOFMEMORY, "Out of memory" ); - } - - // Issue the query - mQuery->Issue( D3DISSUE_END ); - - PROFILE_END(); -} - -//------------------------------------------------------------------------------ - -GFXFence::FenceStatus GFXD3D9QueryFence::getStatus() const -{ - if( mQuery == NULL ) - return GFXFence::Unset; - - HRESULT hRes = mQuery->GetData( NULL, 0, 0 ); - - return ( hRes == S_OK ? GFXFence::Processed : GFXFence::Pending ); -} - -//------------------------------------------------------------------------------ - -void GFXD3D9QueryFence::block() -{ - PROFILE_SCOPE(GFXD3D9QueryFence_block); - - // Calling block() before issue() is valid, catch this case - if( mQuery == NULL ) - return; - - HRESULT hRes; - while( ( hRes = mQuery->GetData( NULL, 0, D3DGETDATA_FLUSH ) ) == S_FALSE ) - ; - - // Check for D3DERR_DEVICELOST, if we lost the device, the fence will get - // re-created next issue() - if( hRes == D3DERR_DEVICELOST ) - SAFE_RELEASE( mQuery ); -} - -void GFXD3D9QueryFence::zombify() -{ - // Release our query - SAFE_RELEASE( mQuery ); -} - -void GFXD3D9QueryFence::resurrect() -{ - // Recreate the query - if( mQuery == NULL ) - { - HRESULT hRes = static_cast( mDevice )->getDevice()->CreateQuery( D3DQUERYTYPE_EVENT, &mQuery ); - - AssertFatal( hRes != D3DERR_NOTAVAILABLE, "GFXD3D9QueryFence::resurrect - Hardware does not support D3D9 Queries, this should be caught before this fence type is created" ); - AssertISV( hRes != E_OUTOFMEMORY, "GFXD3D9QueryFence::resurrect - Out of memory" ); - } -} - -const String GFXD3D9QueryFence::describeSelf() const -{ - // We've got nothing - return String(); -} \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/gfxD3D9QueryFence.h b/Engine/source/gfx/D3D9/gfxD3D9QueryFence.h deleted file mode 100644 index 9318283ac..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9QueryFence.h +++ /dev/null @@ -1,52 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFX_D3D9_QUERYFENCE_H_ -#define _GFX_D3D9_QUERYFENCE_H_ - -#include "gfx/gfxFence.h" -#include "gfx/gfxResource.h" - -struct IDirect3DQuery9; - -class GFXD3D9QueryFence : public GFXFence -{ -private: - mutable IDirect3DQuery9 *mQuery; - -public: - GFXD3D9QueryFence( GFXDevice *device ) : GFXFence( device ), mQuery( NULL ) {}; - virtual ~GFXD3D9QueryFence(); - - virtual void issue(); - virtual FenceStatus getStatus() const; - virtual void block(); - - - - // GFXResource interface - virtual void zombify(); - virtual void resurrect(); - virtual const String describeSelf() const; -}; - -#endif \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/gfxD3D9Shader.cpp b/Engine/source/gfx/D3D9/gfxD3D9Shader.cpp deleted file mode 100644 index e05e3f23c..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9Shader.cpp +++ /dev/null @@ -1,1557 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "platform/platform.h" - -#if defined(TORQUE_OS_XENON) -# include -#else -# include -#endif - -#include "gfx/D3D9/gfxD3D9Shader.h" -#include "gfx/D3D9/gfxD3D9Device.h" - -#include "core/frameAllocator.h" -#include "core/stream/fileStream.h" -#include "core/util/safeDelete.h" -#include "console/console.h" -#include "math/mMathFn.h" - - -using namespace Torque; - -extern bool gDisassembleAllShaders; - -/// D3DXInclude plugin -class _gfxD3DXInclude : public ID3DXInclude, public StrongRefBase -{ -private: - - Vector mLastPath; - -public: - - void setPath( const String &path ) - { - mLastPath.clear(); - mLastPath.push_back( path ); - } - - _gfxD3DXInclude() {} - virtual ~_gfxD3DXInclude() {} - - STDMETHOD(Close)(THIS_ LPCVOID pData); - - // 360 - STDMETHOD(Open)(THIS_ D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes, /* OUT */ LPSTR pFullPath, DWORD cbFullPath); - - // PC - STDMETHOD(Open)(THIS_ D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes) - { - return Open( IncludeType, pFileName, pParentData, ppData, pBytes, NULL, 0 ); - } -}; - -_gfxD3DXIncludeRef GFXD3D9Shader::smD3DXInclude = NULL; - -HRESULT _gfxD3DXInclude::Open(THIS_ D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, - LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes, - LPSTR pFullPath, DWORD cbFullPath) -{ - // First try making the path relative to the parent. - Torque::Path path = Torque::Path::Join( mLastPath.last(), '/', pFileName ); - path = Torque::Path::CompressPath( path ); - - if ( !Torque::FS::ReadFile( path, (void *&)*ppData, *pBytes, true ) ) - { - // Ok... now try using the path as is. - path = String( pFileName ); - path = Torque::Path::CompressPath( path ); - - if ( !Torque::FS::ReadFile( path, (void *&)*ppData, *pBytes, true ) ) - { - AssertISV(false, avar( "Failed to open include '%s'.", pFileName)); - return E_FAIL; - } - } - - // If the data was of zero size then we cannot recurse - // into this file and DX won't call Close() below. - // - // So in this case don't push on the path. - if ( *pBytes > 0 ) - mLastPath.push_back( path.getRootAndPath() ); - - return S_OK; -} - -HRESULT _gfxD3DXInclude::Close( THIS_ LPCVOID pData ) -{ - // Free the data file and pop its path off the stack. - delete [] (U8*)pData; - mLastPath.pop_back(); - - return S_OK; -} - -GFXD3D9ShaderConstHandle::GFXD3D9ShaderConstHandle() -{ - clear(); -} - -const String& GFXD3D9ShaderConstHandle::getName() const -{ - if ( mVertexConstant ) - return mVertexHandle.name; - else - return mPixelHandle.name; -} - -GFXShaderConstType GFXD3D9ShaderConstHandle::getType() const -{ - if ( mVertexConstant ) - return mVertexHandle.constType; - else - return mPixelHandle.constType; -} - -U32 GFXD3D9ShaderConstHandle::getArraySize() const -{ - if ( mVertexConstant ) - return mVertexHandle.arraySize; - else - return mPixelHandle.arraySize; -} - -S32 GFXD3D9ShaderConstHandle::getSamplerRegister() const -{ - if ( !mValid || !isSampler() ) - return -1; - - // We always store sampler type and register index in the pixelHandle, - // sampler registers are shared between vertex and pixel shaders anyway. - - return mPixelHandle.offset; -} - -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - - -bool GFXD3D9ShaderBufferLayout::setMatrix(const ParamDesc& pd, const GFXShaderConstType constType, const U32 size, const void* data, U8* basePointer) -{ - PROFILE_SCOPE(GFXD3D9ShaderBufferLayout_setMatrix); - - if (pd.constType == GFXSCT_Float4x4) - { - // Special case, we can just blast this guy. - AssertFatal(pd.size >= size, "Not enough room in the buffer for this data!"); - if (dMemcmp(basePointer+pd.offset, data, size) != 0) - { - dMemcpy(basePointer+pd.offset, data, size); - return true; - } - - return false; - } - else if (pd.constType == GFXSCT_Float4x3) - { - const U32 csize = 48; - - // Loop through and copy - bool ret = false; - U8* currDestPointer = basePointer + pd.offset; - const U8* currSourcePointer = static_cast(data); - const U8* endData = currSourcePointer + size; - while (currSourcePointer < endData) - { -#ifdef TORQUE_DOUBLE_CHECK_43MATS - Point4F col; - ((MatrixF*)currSourcePointer)->getRow(3, &col); - AssertFatal(col.x == 0.0f && col.y == 0.0f && col.z == 0.0f && col.w == 1.0f, "3rd row used"); -#endif - - if (dMemcmp(currDestPointer, currSourcePointer, csize) != 0) - { - dMemcpy(currDestPointer, currSourcePointer, csize); - ret = true; - } - else if (pd.constType == GFXSCT_Float4x3) - { - ret = true; - } - - currDestPointer += csize; - currSourcePointer += sizeof(MatrixF); - } - - return ret; - } - else - { - PROFILE_SCOPE(GFXD3D9ShaderBufferLayout_setMatrix_not4x4); - - // Figure out how big of a chunk we are copying. We're going to copy 4 columns by N rows of data - U32 csize; - switch (pd.constType) - { - case GFXSCT_Float2x2 : - csize = 32; - break; - case GFXSCT_Float3x3 : - csize = 48; - break; - case GFXSCT_Float3x4 : - csize = 64; - break; - default: - AssertFatal(false, "Unhandled case!"); - return false; - break; - } - - // Loop through and copy - bool ret = false; - U8* currDestPointer = basePointer+pd.offset; - const U8* currSourcePointer = static_cast(data); - const U8* endData = currSourcePointer + size; - while (currSourcePointer < endData) - { - if (dMemcmp(currDestPointer, currSourcePointer, csize) != 0) - { - dMemcpy(currDestPointer, currSourcePointer, csize); - ret = true; - } - else if (pd.constType == GFXSCT_Float4x3) - { - ret = true; - } - - currDestPointer += csize; - currSourcePointer += sizeof(MatrixF); - } - - return ret; - } -} - -//------------------------------------------------------------------------------ -GFXD3D9ShaderConstBuffer::GFXD3D9ShaderConstBuffer( GFXD3D9Shader* shader, - GFXD3D9ShaderBufferLayout* vertexLayoutF, - GFXD3D9ShaderBufferLayout* vertexLayoutI, - GFXD3D9ShaderBufferLayout* pixelLayoutF, - GFXD3D9ShaderBufferLayout* pixelLayoutI ) -{ - AssertFatal( shader, "GFXD3D9ShaderConstBuffer() - Got a null shader!" ); - - // We hold on to this so we don't have to call - // this virtual method during activation. - mDevice = static_cast( GFX )->getDevice(); - - mShader = shader; - - // TODO: Remove buffers and layouts that don't exist for performance? - - mVertexConstBufferLayoutF = vertexLayoutF; - mVertexConstBufferF = new GenericConstBuffer(vertexLayoutF); - mVertexConstBufferLayoutI = vertexLayoutI; - mVertexConstBufferI = new GenericConstBuffer(vertexLayoutI); - mPixelConstBufferLayoutF = pixelLayoutF; - mPixelConstBufferF = new GenericConstBuffer(pixelLayoutF); - mPixelConstBufferLayoutI = pixelLayoutI; - mPixelConstBufferI = new GenericConstBuffer(pixelLayoutI); -} - -GFXD3D9ShaderConstBuffer::~GFXD3D9ShaderConstBuffer() -{ - SAFE_DELETE(mVertexConstBufferF); - SAFE_DELETE(mPixelConstBufferF); - SAFE_DELETE(mVertexConstBufferI); - SAFE_DELETE(mPixelConstBufferI); - - if ( mShader ) - mShader->_unlinkBuffer( this ); -} - -GFXShader* GFXD3D9ShaderConstBuffer::getShader() -{ - return mShader; -} - -// This is kind of cheesy, but I don't think templates would work well here because -// these functions potentially need to be handled differently by other derived types -template -inline void GFXD3D9ShaderConstBuffer::SET_CONSTANT( GFXShaderConstHandle* handle, const T& fv, GenericConstBuffer *vBuffer, GenericConstBuffer *pBuffer ) -{ - AssertFatal(dynamic_cast(handle), "Incorrect const buffer type!"); - const GFXD3D9ShaderConstHandle* h = static_cast(handle); - AssertFatal(h, "Handle is NULL!" ); - AssertFatal(h->isValid(), "Handle is not valid!" ); - AssertFatal(!h->isSampler(), "Handle is sampler constant!" ); - AssertFatal(!mShader.isNull(), "Buffer's shader is null!" ); - AssertFatal(!h->mShader.isNull(), "Handle's shader is null!" ); - AssertFatal(h->mShader.getPointer() == mShader.getPointer(), "Mismatched shaders!"); - if ( h->mInstancingConstant ) - { - dMemcpy( mInstPtr+h->mPixelHandle.offset, &fv, sizeof( fv ) ); - return; - } - if (h->mVertexConstant) - vBuffer->set(h->mVertexHandle, fv); - if (h->mPixelConstant) - pBuffer->set(h->mPixelHandle, fv); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const F32 fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferF, mPixelConstBufferF); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point2F& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferF, mPixelConstBufferF); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point3F& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferF, mPixelConstBufferF); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point4F& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferF, mPixelConstBufferF); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const PlaneF& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferF, mPixelConstBufferF); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const ColorF& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferF, mPixelConstBufferF); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const S32 f) -{ - // This is the only type that is allowed to be used - // with a sampler shader constant type, but it is only - // allowed to be set from GLSL. - // - // So we ignore it here... all other cases will assert. - // - if ( ((GFXD3D9ShaderConstHandle*)handle)->isSampler() ) - return; - - SET_CONSTANT(handle, f, mVertexConstBufferI, mPixelConstBufferI); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point2I& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferI, mPixelConstBufferI); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point3I& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferI, mPixelConstBufferI); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const Point4I& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferI, mPixelConstBufferI); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferF, mPixelConstBufferF); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferF, mPixelConstBufferF); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferF, mPixelConstBufferF); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferF, mPixelConstBufferF); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferI, mPixelConstBufferI); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferI, mPixelConstBufferI); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferI, mPixelConstBufferI); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const AlignedArray& fv) -{ - SET_CONSTANT(handle, fv, mVertexConstBufferI, mPixelConstBufferI); -} -#undef SET_CONSTANT - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const MatrixF& mat, const GFXShaderConstType matrixType) -{ - AssertFatal(handle, "Handle is NULL!" ); - AssertFatal(handle->isValid(), "Handle is not valid!" ); - - AssertFatal(dynamic_cast(handle), "Incorrect const buffer type!"); - const GFXD3D9ShaderConstHandle* h = static_cast(handle); - AssertFatal(!h->isSampler(), "Handle is sampler constant!" ); - AssertFatal(h->mShader == mShader, "Mismatched shaders!"); - - MatrixF transposed; - if (matrixType == GFXSCT_Float4x3) - { - transposed = mat; - } - else - { - mat.transposeTo(transposed); - } - - if (h->mInstancingConstant) - { - if ( matrixType == GFXSCT_Float4x4 ) - dMemcpy( mInstPtr+h->mPixelHandle.offset, mat, sizeof( mat ) ); - - // TODO: Support 3x3 and 2x2 matricies? - return; - } - - if (h->mVertexConstant) - mVertexConstBufferF->set(h->mVertexHandle, transposed, matrixType); - if (h->mPixelConstant) - mPixelConstBufferF->set(h->mPixelHandle, transposed, matrixType); -} - -void GFXD3D9ShaderConstBuffer::set(GFXShaderConstHandle* handle, const MatrixF* mat, const U32 arraySize, const GFXShaderConstType matrixType) -{ - AssertFatal(handle, "Handle is NULL!" ); - AssertFatal(handle->isValid(), "Handle is not valid!" ); - - AssertFatal(dynamic_cast(handle), "Incorrect const buffer type!"); - const GFXD3D9ShaderConstHandle* h = static_cast(handle); - AssertFatal(!h->isSampler(), "Handle is sampler constant!" ); - AssertFatal(h->mShader == mShader, "Mismatched shaders!"); - - static Vector transposed; - if (arraySize > transposed.size()) - transposed.setSize(arraySize); - - if (matrixType == GFXSCT_Float4x3) - { - dMemcpy(transposed.address(), mat, arraySize * sizeof(MatrixF)); - } - else - { - for (U32 i = 0; i < arraySize; i++) - mat[i].transposeTo(transposed[i]); - } - - // TODO: Maybe support this in the future? - if (h->mInstancingConstant) - return; - - if (h->mVertexConstant) - mVertexConstBufferF->set(h->mVertexHandle, transposed.begin(), arraySize, matrixType); - if (h->mPixelConstant) - mPixelConstBufferF->set(h->mPixelHandle, transposed.begin(), arraySize, matrixType); -} - -const String GFXD3D9ShaderConstBuffer::describeSelf() const -{ - String ret; - ret = String(" GFXD3D9ShaderConstBuffer\n"); - - for (U32 i = 0; i < mVertexConstBufferLayoutF->getParameterCount(); i++) - { - GenericConstBufferLayout::ParamDesc pd; - mVertexConstBufferLayoutF->getDesc(i, pd); - - ret += String::ToString(" Constant name: %s", pd.name.c_str()); - } - - return ret; -} - -void GFXD3D9ShaderConstBuffer::zombify() -{ -} - -void GFXD3D9ShaderConstBuffer::resurrect() -{ -} - -bool GFXD3D9ShaderConstBuffer::isDirty() -{ - bool ret = mVertexConstBufferF->isDirty(); - ret |= mVertexConstBufferI->isDirty(); - ret |= mPixelConstBufferF->isDirty(); - ret |= mPixelConstBufferI->isDirty(); - return ret; -} - -void GFXD3D9ShaderConstBuffer::activate( GFXD3D9ShaderConstBuffer *prevShaderBuffer ) -{ - PROFILE_SCOPE(GFXD3D9ShaderConstBuffer_activate); - - // NOTE: This is a really critical function as it gets - // called between every draw call to update the constants. - // - // Alot of the calls here are inlined... be careful - // what you change. - - // If the buffer has changed we need to compare it - // with the new buffer to see if we can skip copying - // equal buffer content. - // - // If the buffer hasn't changed then we only will - // be copying the changes that have occured since - // the last activate call. - // - if ( prevShaderBuffer != this ) - { - // If the previous buffer is dirty, than we can't compare - // against it, because it hasn't sent its contents to the - // card yet and must be copied. - if ( prevShaderBuffer && !prevShaderBuffer->isDirty() ) - { - PROFILE_SCOPE(GFXD3D9ShaderConstBuffer_activate_dirty_check_1); - - // If the buffer content is equal then we set the dirty - // flag to false knowing the current state of the card matches - // the new buffer. - // - // If the content is not equal we set the dirty flag to - // true which causes the full content of the buffer to be - // copied to the card. - // - mVertexConstBufferF->setDirty( !prevShaderBuffer->mVertexConstBufferF->isEqual( mVertexConstBufferF ) ); - mPixelConstBufferF->setDirty( !prevShaderBuffer->mPixelConstBufferF->isEqual( mPixelConstBufferF ) ); - mVertexConstBufferI->setDirty( !prevShaderBuffer->mVertexConstBufferF->isEqual( mVertexConstBufferI ) ); - mPixelConstBufferI->setDirty( !prevShaderBuffer->mPixelConstBufferF->isEqual( mPixelConstBufferI ) ); - } - else - { - // This happens rarely... but it can happen. - // - // We copy the entire dirty state to the card. - - PROFILE_SCOPE(GFXD3D9ShaderConstBuffer_activate_dirty_check_2); - - mVertexConstBufferF->setDirty( true ); - mPixelConstBufferF->setDirty( true ); - mVertexConstBufferI->setDirty( true ); - mPixelConstBufferI->setDirty( true ); - } - } - - const U32 bytesToFloat4 = 16; - const U32 bytesToInt4 = 16; - U32 start, bufferSize; - const U8* buf; - - if ( mVertexConstBufferF->isDirty() ) - { - buf = mVertexConstBufferF->getDirtyBuffer( &start, &bufferSize ); - mDevice->SetVertexShaderConstantF( start / bytesToFloat4, (float*)buf, bufferSize / bytesToFloat4 ); - } - - if ( mPixelConstBufferF->isDirty() ) - { - buf = mPixelConstBufferF->getDirtyBuffer( &start, &bufferSize ); - mDevice->SetPixelShaderConstantF( start / bytesToFloat4, (float*)buf, bufferSize / bytesToFloat4 ); - } - - if ( mVertexConstBufferI->isDirty() ) - { - buf = mVertexConstBufferI->getDirtyBuffer( &start, &bufferSize ); - mDevice->SetVertexShaderConstantI( start / bytesToInt4, (int*)buf, bufferSize / bytesToInt4 ); - } - - if ( mPixelConstBufferI->isDirty() ) - { - buf = mPixelConstBufferI->getDirtyBuffer( &start, &bufferSize ); - mDevice->SetPixelShaderConstantI( start / bytesToInt4, (int*)buf, bufferSize / bytesToInt4 ); - } - - #ifdef TORQUE_DEBUG - - // Make sure all the constants for this buffer were assigned. - if ( mWasLost ) - { - mVertexConstBufferF->assertUnassignedConstants( mShader->getVertexShaderFile().c_str() ); - mVertexConstBufferI->assertUnassignedConstants( mShader->getVertexShaderFile().c_str() ); - mPixelConstBufferF->assertUnassignedConstants( mShader->getPixelShaderFile().c_str() ); - mPixelConstBufferI->assertUnassignedConstants( mShader->getPixelShaderFile().c_str() ); - } - - #endif - - // Clear the lost state. - mWasLost = false; -} - -void GFXD3D9ShaderConstBuffer::onShaderReload( GFXD3D9Shader *shader ) -{ - AssertFatal( shader == mShader, "GFXD3D9ShaderConstBuffer::onShaderReload is hosed!" ); - - SAFE_DELETE( mVertexConstBufferF ); - SAFE_DELETE( mPixelConstBufferF ); - SAFE_DELETE( mVertexConstBufferI ); - SAFE_DELETE( mPixelConstBufferI ); - - AssertFatal( mVertexConstBufferLayoutF == shader->mVertexConstBufferLayoutF, "GFXD3D9ShaderConstBuffer::onShaderReload is hosed!" ); - AssertFatal( mPixelConstBufferLayoutF == shader->mPixelConstBufferLayoutF, "GFXD3D9ShaderConstBuffer::onShaderReload is hosed!" ); - AssertFatal( mVertexConstBufferLayoutI == shader->mVertexConstBufferLayoutI, "GFXD3D9ShaderConstBuffer::onShaderReload is hosed!" ); - AssertFatal( mPixelConstBufferLayoutI == shader->mPixelConstBufferLayoutI, "GFXD3D9ShaderConstBuffer::onShaderReload is hosed!" ); - - mVertexConstBufferF = new GenericConstBuffer( mVertexConstBufferLayoutF ); - mVertexConstBufferI = new GenericConstBuffer( mVertexConstBufferLayoutI ); - mPixelConstBufferF = new GenericConstBuffer( mPixelConstBufferLayoutF ); - mPixelConstBufferI = new GenericConstBuffer( mPixelConstBufferLayoutI ); - - // Set the lost state. - mWasLost = true; -} - -//------------------------------------------------------------------------------ - -GFXD3D9Shader::GFXD3D9Shader() -{ - VECTOR_SET_ASSOCIATION( mShaderConsts ); - - mD3D9Device = dynamic_cast(GFX)->getDevice(); - AssertFatal(mD3D9Device, "Invalid device for shader."); - mVertShader = NULL; - mPixShader = NULL; - mVertexConstBufferLayoutF = NULL; - mPixelConstBufferLayoutF = NULL; - mVertexConstBufferLayoutI = NULL; - mPixelConstBufferLayoutI = NULL; - - if( smD3DXInclude == NULL ) - smD3DXInclude = new _gfxD3DXInclude; -} - -//------------------------------------------------------------------------------ - -GFXD3D9Shader::~GFXD3D9Shader() -{ - for (HandleMap::Iterator i = mHandles.begin(); i != mHandles.end(); i++) - delete i->value; - SAFE_DELETE(mVertexConstBufferLayoutF); - SAFE_DELETE(mPixelConstBufferLayoutF); - SAFE_DELETE(mVertexConstBufferLayoutI); - SAFE_DELETE(mPixelConstBufferLayoutI); - SAFE_RELEASE(mVertShader); - SAFE_RELEASE(mPixShader); -} - -bool GFXD3D9Shader::_init() -{ - PROFILE_SCOPE( GFXD3D9Shader_Init ); - - if ( mPixVersion > GFX->getPixelShaderVersion() ) - { - if ( smLogErrors ) - Con::errorf( "GFXD3D9Shader::init - Bad pixel shader version!" ); - - return false; - } - - if ( mPixVersion < 1.0f && mPixelFile.getFileName().isNotEmpty() ) - { - if ( smLogErrors ) - Con::errorf( "GFXD3D9Shader::init - Pixel shaders not supported on SM %.1f!", mPixVersion ); - - return false; - } - - SAFE_RELEASE(mVertShader); - SAFE_RELEASE(mPixShader); - - U32 mjVer = (U32)mFloor( mPixVersion ); - U32 mnVer = (U32)( ( mPixVersion - F32( mjVer ) ) * 10.01f ); // 10.01 instead of 10.0 because of floating point issues - - String vertTarget = String::ToString("vs_%d_%d", mjVer, mnVer); - String pixTarget = String::ToString("ps_%d_%d", mjVer, mnVer); - - // Adjust version for vertex shaders - if (mjVer == 2 && mnVer == 1) - { - pixTarget = "ps_2_a"; - vertTarget = "vs_2_0"; - } - else if ( mjVer == 2 && mnVer == 2 ) - { - pixTarget = "ps_2_b"; - vertTarget = "vs_2_0"; - } - else if ( ( mPixVersion < 2.0f ) && ( mPixVersion > 1.101f ) ) - vertTarget = "vs_1_1"; - - // Create the macro array including the system wide macros. - const U32 macroCount = smGlobalMacros.size() + mMacros.size() + 2; - FrameTemp d3dXMacros( macroCount ); - for ( U32 i=0; i < smGlobalMacros.size(); i++ ) - { - d3dXMacros[i].Name = smGlobalMacros[i].name.c_str(); - d3dXMacros[i].Definition = smGlobalMacros[i].value.c_str(); - } - for ( U32 i=0; i < mMacros.size(); i++ ) - { - d3dXMacros[i+smGlobalMacros.size()].Name = mMacros[i].name.c_str(); - d3dXMacros[i+smGlobalMacros.size()].Definition = mMacros[i].value.c_str(); - } - String smVersion = String::ToString( mjVer * 10 + mnVer ); - d3dXMacros[macroCount - 2].Name = "TORQUE_SM"; - d3dXMacros[macroCount - 2].Definition = smVersion.c_str(); - d3dXMacros[macroCount - 1].Name = NULL; - d3dXMacros[macroCount - 1].Definition = NULL; - - if ( !mVertexConstBufferLayoutF ) - mVertexConstBufferLayoutF = new GFXD3D9ShaderBufferLayout(); - else - mVertexConstBufferLayoutF->clear(); - - if ( !mVertexConstBufferLayoutI ) - mVertexConstBufferLayoutI = new GFXD3D9ShaderBufferLayout(); - else - mVertexConstBufferLayoutI->clear(); - - if ( !mPixelConstBufferLayoutF ) - mPixelConstBufferLayoutF = new GFXD3D9ShaderBufferLayout(); - else - mPixelConstBufferLayoutF->clear(); - - if ( !mPixelConstBufferLayoutI ) - mPixelConstBufferLayoutI = new GFXD3D9ShaderBufferLayout(); - else - mPixelConstBufferLayoutI->clear(); - - mSamplerDescriptions.clear(); - mShaderConsts.clear(); - - if ( GFXD3DX.isLoaded && !Con::getBoolVariable( "$shaders::forceLoadCSF", false ) ) - { - if ( !mVertexFile.isEmpty() && - !_compileShader( mVertexFile, vertTarget, d3dXMacros, mVertexConstBufferLayoutF, mVertexConstBufferLayoutI, mSamplerDescriptions ) ) - return false; - - if ( !mPixelFile.isEmpty() && - !_compileShader( mPixelFile, pixTarget, d3dXMacros, mPixelConstBufferLayoutF, mPixelConstBufferLayoutI, mSamplerDescriptions ) ) - return false; - } - else - { - if ( !_loadCompiledOutput( mVertexFile, vertTarget, mVertexConstBufferLayoutF, mVertexConstBufferLayoutI, mSamplerDescriptions ) ) - { - if ( smLogErrors ) - Con::errorf( "GFXD3D9Shader::init - Unable to load precompiled vertex shader for '%s'.", - mVertexFile.getFullPath().c_str() ); - - return false; - } - - if ( !_loadCompiledOutput( mPixelFile, pixTarget, mPixelConstBufferLayoutF, mPixelConstBufferLayoutI, mSamplerDescriptions ) ) - { - if ( smLogErrors ) - Con::errorf( "GFXD3D9Shader::init - Unable to load precompiled pixel shader for '%s'.", - mPixelFile.getFullPath().c_str() ); - - return false; - } - } - - // Existing handles are resored to an uninitialized state. - // Those that are found when parsing the layout parameters - // will then be re-initialized. - HandleMap::Iterator iter = mHandles.begin(); - for ( ; iter != mHandles.end(); iter++ ) - (iter->value)->clear(); - - _buildShaderConstantHandles(mVertexConstBufferLayoutF, true); - _buildShaderConstantHandles(mVertexConstBufferLayoutI, true); - _buildShaderConstantHandles(mPixelConstBufferLayoutF, false); - _buildShaderConstantHandles(mPixelConstBufferLayoutI, false); - _buildSamplerShaderConstantHandles( mSamplerDescriptions ); - _buildInstancingShaderConstantHandles(); - - // Notify any existing buffers that the buffer - // layouts have changed and they need to update. - Vector::iterator biter = mActiveBuffers.begin(); - for ( ; biter != mActiveBuffers.end(); biter++ ) - ((GFXD3D9ShaderConstBuffer*)(*biter))->onShaderReload( this ); - - return true; -} - -bool GFXD3D9Shader::_compileShader( const Torque::Path &filePath, - const String& target, - const D3DXMACRO *defines, - GenericConstBufferLayout* bufferLayoutF, - GenericConstBufferLayout* bufferLayoutI, - Vector &samplerDescriptions ) -{ - PROFILE_SCOPE( GFXD3D9Shader_CompileShader ); - - HRESULT res = D3DERR_INVALIDCALL; - LPD3DXBUFFER code = NULL; - LPD3DXBUFFER errorBuff = NULL; - -#ifdef TORQUE_DEBUG - U32 flags = D3DXSHADER_DEBUG; -#else - U32 flags = 0; -#endif - -#ifdef TORQUE_OS_XENON - flags |= D3DXSHADER_PREFER_FLOW_CONTROL; -#endif - -#ifdef D3DXSHADER_USE_LEGACY_D3DX9_31_DLL - if( D3DX_SDK_VERSION >= 32 ) - { - // will need to use old compiler for 1_1 shaders - check for pixel - // or vertex shader with appropriate version. - if ((target.compare("vs1", 3) == 0) || (target.compare("vs_1", 4) == 0)) - flags |= D3DXSHADER_USE_LEGACY_D3DX9_31_DLL; - - if ((target.compare("ps1", 3) == 0) || (target.compare("ps_1", 4) == 0)) - flags |= D3DXSHADER_USE_LEGACY_D3DX9_31_DLL; - } -#endif - -#if !defined(TORQUE_OS_XENON) && (D3DX_SDK_VERSION <= 40) -#error This version of the DirectX SDK is too old. Please install a newer version of the DirectX SDK: http://msdn.microsoft.com/en-us/directx/default.aspx -#endif - - ID3DXConstantTable* table = NULL; - - static String sHLSLStr( "hlsl" ); - static String sOBJStr( "obj" ); - - // Is it an HLSL shader? - if ( filePath.getExtension().equal(sHLSLStr, String::NoCase) ) - { - FrameAllocatorMarker fam; - char *buffer = NULL; - - // Set this so that the D3DXInclude::Open will have this - // information for relative paths. - smD3DXInclude->setPath( filePath.getRootAndPath() ); - - FileStream s; - if ( !s.open( filePath, Torque::FS::File::Read ) ) - { - AssertISV(false, avar("GFXD3D9Shader::initShader - failed to open shader '%s'.", filePath.getFullPath().c_str())); - - if ( smLogErrors ) - Con::errorf( "GFXD3D9Shader::_compileShader - Failed to open shader file '%s'.", - filePath.getFullPath().c_str() ); - - return false; - } - - // Convert the path which might have virtualized - // mount paths to a real file system path. - Torque::Path realPath; - if ( !FS::GetFSPath( filePath, realPath ) ) - realPath = filePath; - - // Add a #line pragma so that error and warning messages - // returned by the HLSL compiler report the right file. - String linePragma = String::ToString( "#line 1 \"%s\"\r\n", realPath.getFullPath().c_str() ); - U32 linePragmaLen = linePragma.length(); - - U32 bufSize = s.getStreamSize(); - buffer = (char *)fam.alloc( bufSize + linePragmaLen + 1 ); - dStrncpy( buffer, linePragma.c_str(), linePragmaLen ); - s.read( bufSize, buffer + linePragmaLen ); - buffer[bufSize+linePragmaLen] = 0; - - res = GFXD3DX.D3DXCompileShader( buffer, bufSize + linePragmaLen, defines, smD3DXInclude, "main", - target, flags, &code, &errorBuff, &table ); - } - - // Is it a precompiled obj shader? - else if ( filePath.getExtension().equal( sOBJStr, String::NoCase ) ) - { - FileStream s; - if(!s.open(filePath, Torque::FS::File::Read)) - { - AssertISV(false, avar("GFXD3D9Shader::initShader - failed to open shader '%s'.", filePath.getFullPath().c_str())); - - if ( smLogErrors ) - Con::errorf( "GFXD3D9Shader::_compileShader - Failed to open shader file '%s'.", - filePath.getFullPath().c_str() ); - - return false; - } - - res = GFXD3DX.D3DXCreateBuffer(s.getStreamSize(), &code); - AssertISV(res == D3D_OK, "Unable to create buffer!"); - s.read(s.getStreamSize(), code->GetBufferPointer()); - - if (res == D3D_OK) - { - DWORD* data = (DWORD*) code->GetBufferPointer(); - res = GFXD3DX.D3DXGetShaderConstantTable(data, &table); - } - } - else - { - if ( smLogErrors ) - Con::errorf( "GFXD3D9Shader::_compileShader - Unsupported shader file type '%s'.", - filePath.getFullPath().c_str() ); - - return false; - } - - if ( res != D3D_OK && smLogErrors ) - Con::errorf( "GFXD3D9Shader::_compileShader - Error compiling shader: %s: %s (%x)", - DXGetErrorStringA(res), DXGetErrorDescriptionA(res), res ); - - if ( errorBuff ) - { - // remove \n at end of buffer - U8 *buffPtr = (U8*) errorBuff->GetBufferPointer(); - U32 len = dStrlen( (const char*) buffPtr ); - buffPtr[len-1] = '\0'; - - if( res != D3D_OK ) - { - if ( smLogErrors ) - Con::errorf( " %s", (const char*) errorBuff->GetBufferPointer() ); - } - else - { - if ( smLogWarnings ) - Con::warnf( "%s", (const char*) errorBuff->GetBufferPointer() ); - } - } - else if ( code == NULL && smLogErrors ) - Con::errorf( "GFXD3D9Shader::_compileShader - no compiled code produced; possibly missing file '%s'.", - filePath.getFullPath().c_str() ); - - // Create the proper shader if we have code - if( code != NULL ) - { - #ifndef TORQUE_SHIPPING - - LPD3DXBUFFER disassem = NULL; - D3DXDisassembleShader( (DWORD*)code->GetBufferPointer(), false, NULL, &disassem ); - mDissasembly = (const char*)disassem->GetBufferPointer(); - SAFE_RELEASE( disassem ); - - if ( gDisassembleAllShaders ) - { - String filename = filePath.getFullPath(); - filename.replace( ".hlsl", "_dis.txt" ); - - FileStream *fstream = FileStream::createAndOpen( filename, Torque::FS::File::Write ); - if ( fstream ) - { - fstream->write( mDissasembly ); - fstream->close(); - delete fstream; - } - } - - #endif - - if (target.compare("ps_", 3) == 0) - res = mD3D9Device->CreatePixelShader( (DWORD*)code->GetBufferPointer(), &mPixShader ); - else - res = mD3D9Device->CreateVertexShader( (DWORD*)code->GetBufferPointer(), &mVertShader ); - - if (res == S_OK) - _getShaderConstants(table, bufferLayoutF, bufferLayoutI, samplerDescriptions); - -#ifdef TORQUE_ENABLE_CSF_GENERATION - - // Ok, we've got a valid shader and constants, let's write them all out. - if ( !_saveCompiledOutput(filePath, code, bufferLayoutF, bufferLayoutI) && smLogErrors ) - Con::errorf( "GFXD3D9Shader::_compileShader - Unable to save shader compile output for: %s", - filePath.getFullPath().c_str() ); - -#endif - - SAFE_RELEASE(table); - - if ( res != S_OK && smLogErrors ) - Con::errorf( "GFXD3D9Shader::_compileShader - Unable to create shader for '%s'.", - filePath.getFullPath().c_str() ); - } - - bool result = code != NULL && res == S_OK; - - SAFE_RELEASE( code ); - SAFE_RELEASE( errorBuff ); - - return result; -} - -void GFXD3D9Shader::_getShaderConstants( ID3DXConstantTable *table, - GenericConstBufferLayout *bufferLayoutF, - GenericConstBufferLayout* bufferLayoutI, - Vector &samplerDescriptions ) -{ - PROFILE_SCOPE( GFXD3D9Shader_GetShaderConstants ); - - AssertFatal(table, "NULL constant table not allowed, is this an assembly shader?"); - - D3DXCONSTANTTABLE_DESC tableDesc; - D3D9Assert(table->GetDesc(&tableDesc), "Unable to get constant table info."); - - for (U32 i = 0; i < tableDesc.Constants; i++) - { - D3DXHANDLE handle = table->GetConstant(0, i); - const U32 descSize=16; - D3DXCONSTANT_DESC constantDescArray[descSize]; - U32 size = descSize; - if (table->GetConstantDesc(handle, constantDescArray, &size) == S_OK) - { - D3DXCONSTANT_DESC& constantDesc = constantDescArray[0]; - GFXShaderConstDesc desc; - - desc.name = String(constantDesc.Name); - // Prepend a "$" if it doesn't exist. Just to make things consistent. - if (desc.name.find("$") != 0) - desc.name = String::ToString("$%s", desc.name.c_str()); - //Con::printf("name %s: , offset: %d, size: %d, constantDesc.Elements: %d", desc.name.c_str(), constantDesc.RegisterIndex, constantDesc.Bytes, constantDesc.Elements); - desc.arraySize = constantDesc.Elements; - - GenericConstBufferLayout* bufferLayout = NULL; - switch (constantDesc.RegisterSet) - { - case D3DXRS_INT4 : - { - bufferLayout = bufferLayoutI; - switch (constantDesc.Class) - { - case D3DXPC_SCALAR : - desc.constType = GFXSCT_Int; - break; - case D3DXPC_VECTOR : - { - switch (constantDesc.Columns) - { - case 1 : - desc.constType = GFXSCT_Int; - break; - case 2 : - desc.constType = GFXSCT_Int2; - break; - case 3 : - desc.constType = GFXSCT_Int3; - break; - case 4 : - desc.constType = GFXSCT_Int4; - break; - default: - AssertFatal(false, "Unknown int vector type!"); - break; - } - } - break; - } - desc.constType = GFXSCT_Int4; - break; - } - case D3DXRS_FLOAT4 : - { - bufferLayout = bufferLayoutF; - switch (constantDesc.Class) - { - case D3DXPC_SCALAR: - desc.constType = GFXSCT_Float; - break; - case D3DXPC_VECTOR : - { - switch (constantDesc.Columns) - { - case 1 : - desc.constType = GFXSCT_Float; - break; - case 2 : - desc.constType = GFXSCT_Float2; - break; - case 3 : - desc.constType = GFXSCT_Float3; - break; - case 4 : - desc.constType = GFXSCT_Float4; - break; - default: - AssertFatal(false, "Unknown float vector type!"); - break; - } - } - break; - case D3DXPC_MATRIX_ROWS : - case D3DXPC_MATRIX_COLUMNS : - { - S32 fd, sd; - fd = constantDesc.RegisterCount / constantDesc.Elements; - sd = constantDesc.Class == D3DXPC_MATRIX_ROWS ? constantDesc.Columns : constantDesc.Rows; - - switch (fd) - { - case 2 : - AssertFatal(sd == 2, "non-square 2x? mats not supported"); - desc.constType = GFXSCT_Float2x2; - break; - case 3 : - switch (sd) - { - case 3 : - desc.constType = GFXSCT_Float3x3; - break; - case 4 : - desc.constType = GFXSCT_Float4x3; - break; - default: - AssertFatal(false, "Unsupported matrix size"); - break; - } - break; - case 4 : - switch (sd) - { - case 3: - desc.constType = GFXSCT_Float3x4; - break; - case 4: - desc.constType = GFXSCT_Float4x4; - break; - default: - AssertFatal(false, "Unsupported matrix size"); - break; - } - break; - } - } - break; - case D3DXPC_OBJECT : - case D3DXPC_STRUCT : - bufferLayout = NULL; - break; - } - } - break; - case D3DXRS_SAMPLER : - { - AssertFatal( constantDesc.Elements == 1, "Sampler Arrays not yet supported!" ); - - switch (constantDesc.Type) - { - case D3DXPT_SAMPLER : - case D3DXPT_SAMPLER1D : - case D3DXPT_SAMPLER2D : - case D3DXPT_SAMPLER3D : - // Hi-jack the desc's arraySize to store the registerIndex. - desc.constType = GFXSCT_Sampler; - desc.arraySize = constantDesc.RegisterIndex; - samplerDescriptions.push_back( desc ); - mShaderConsts.push_back(desc); - break; - case D3DXPT_SAMPLERCUBE : - desc.constType = GFXSCT_SamplerCube; - desc.arraySize = constantDesc.RegisterIndex; - samplerDescriptions.push_back( desc ); - mShaderConsts.push_back(desc); - break; - } - } - break; - default: - AssertFatal(false, "Unknown shader constant class enum"); - break; - } - - if (bufferLayout) - { - mShaderConsts.push_back(desc); - - U32 alignBytes = getAlignmentValue(desc.constType); - U32 paramSize = alignBytes * desc.arraySize; - bufferLayout->addParameter( desc.name, - desc.constType, - constantDesc.RegisterIndex * sizeof(Point4F), - paramSize, - desc.arraySize, - alignBytes ); - } - } - else - AssertFatal(false, "Unable to get shader constant description! (may need more elements of constantDesc"); - } -} - -const U32 GFXD3D9Shader::smCompiledShaderTag = MakeFourCC('t','c','s','f'); - -bool GFXD3D9Shader::_saveCompiledOutput( const Torque::Path &filePath, - LPD3DXBUFFER buffer, - GenericConstBufferLayout *bufferLayoutF, - GenericConstBufferLayout *bufferLayoutI, - Vector &samplerDescriptions ) -{ - Torque::Path outputPath(filePath); - outputPath.setExtension("csf"); // "C"ompiled "S"hader "F"ile (fancy!) - - FileStream f; - if (!f.open(outputPath, Torque::FS::File::Write)) - return false; - if (!f.write(smCompiledShaderTag)) - return false; - // We could reverse engineer the structure in the compiled output, but this - // is a bit easier because we can just read it into the struct that we want. - if (!bufferLayoutF->write(&f)) - return false; - if (!bufferLayoutI->write(&f)) - return false; - U32 bufferSize = buffer->GetBufferSize(); - if (!f.write(bufferSize)) - return false; - if (!f.write(bufferSize, buffer->GetBufferPointer())) - return false; - - // Write out sampler descriptions. - - f.write( samplerDescriptions.size() ); - - for ( U32 i = 0; i < samplerDescriptions.size(); i++ ) - { - f.write( samplerDescriptions[i].name ); - f.write( (U32)(samplerDescriptions[i].constType) ); - f.write( samplerDescriptions[i].arraySize ); - } - - f.close(); - - return true; -} - -bool GFXD3D9Shader::_loadCompiledOutput( const Torque::Path &filePath, - const String &target, - GenericConstBufferLayout *bufferLayoutF, - GenericConstBufferLayout *bufferLayoutI, - Vector &samplerDescriptions ) -{ - Torque::Path outputPath(filePath); - outputPath.setExtension("csf"); // "C"ompiled "S"hader "F"ile (fancy!) - - FileStream f; - if (!f.open(outputPath, Torque::FS::File::Read)) - return false; - U32 fileTag; - if (!f.read(&fileTag)) - return false; - if (fileTag != smCompiledShaderTag) - return false; - if (!bufferLayoutF->read(&f)) - return false; - if (!bufferLayoutI->read(&f)) - return false; - U32 bufferSize; - if (!f.read(&bufferSize)) - return false; - U32 waterMark = FrameAllocator::getWaterMark(); - DWORD* buffer = static_cast(FrameAllocator::alloc(bufferSize)); - if (!f.read(bufferSize, buffer)) - return false; - - // Read sampler descriptions. - - U32 samplerCount; - f.read( &samplerCount ); - - for ( U32 i = 0; i < samplerCount; i++ ) - { - GFXShaderConstDesc samplerDesc; - f.read( &(samplerDesc.name) ); - f.read( (U32*)&(samplerDesc.constType) ); - f.read( &(samplerDesc.arraySize) ); - - samplerDescriptions.push_back( samplerDesc ); - } - - f.close(); - - HRESULT res; - if (target.compare("ps_", 3) == 0) - res = mD3D9Device->CreatePixelShader(buffer, &mPixShader ); - else - res = mD3D9Device->CreateVertexShader(buffer, &mVertShader ); - AssertFatal(SUCCEEDED(res), "Unable to load shader!"); - - FrameAllocator::setWaterMark(waterMark); - return SUCCEEDED(res); -} - -void GFXD3D9Shader::_buildShaderConstantHandles(GenericConstBufferLayout* layout, bool vertexConst) -{ - for (U32 i = 0; i < layout->getParameterCount(); i++) - { - GenericConstBufferLayout::ParamDesc pd; - layout->getDesc(i, pd); - - GFXD3D9ShaderConstHandle* handle; - HandleMap::Iterator j = mHandles.find(pd.name); - - if (j != mHandles.end()) - { - handle = j->value; - handle->mShader = this; - handle->setValid( true ); - } - else - { - handle = new GFXD3D9ShaderConstHandle(); - handle->mShader = this; - mHandles[pd.name] = handle; - handle->setValid( true ); - } - - if ( vertexConst ) - { - handle->mVertexConstant = true; - handle->mVertexHandle = pd; - } - else - { - handle->mPixelConstant = true; - handle->mPixelHandle = pd; - } - } -} - -void GFXD3D9Shader::_buildSamplerShaderConstantHandles( Vector &samplerDescriptions ) -{ - Vector::iterator iter = samplerDescriptions.begin(); - for ( ; iter != samplerDescriptions.end(); iter++ ) - { - const GFXShaderConstDesc &desc = *iter; - - AssertFatal( desc.constType == GFXSCT_Sampler || - desc.constType == GFXSCT_SamplerCube, - "GFXD3D9Shader::_buildSamplerShaderConstantHandles - Invalid samplerDescription type!" ); - - GFXD3D9ShaderConstHandle *handle; - HandleMap::Iterator j = mHandles.find(desc.name); - - if ( j != mHandles.end() ) - handle = j->value; - else - { - handle = new GFXD3D9ShaderConstHandle(); - mHandles[desc.name] = handle; - } - - handle->mShader = this; - handle->setValid( true ); - handle->mPixelConstant = true; - handle->mPixelHandle.name = desc.name; - handle->mPixelHandle.constType = desc.constType; - handle->mPixelHandle.offset = desc.arraySize; - } -} - -void GFXD3D9Shader::_buildInstancingShaderConstantHandles() -{ - // If we have no instancing than just return - if (!mInstancingFormat) - return; - - U32 offset = 0; - - for ( U32 i=0; i < mInstancingFormat->getElementCount(); i++ ) - { - const GFXVertexElement &element = mInstancingFormat->getElement( i ); - - String constName = String::ToString( "$%s", element.getSemantic().c_str() ); - - GFXD3D9ShaderConstHandle *handle; - HandleMap::Iterator j = mHandles.find( constName ); - - if ( j != mHandles.end() ) - handle = j->value; - else - { - handle = new GFXD3D9ShaderConstHandle(); - mHandles[ constName ] = handle; - } - - handle->mShader = this; - handle->setValid( true ); - handle->mInstancingConstant = true; - - // We shouldn't have an instancing constant that is also - // a vertex or pixel constant! This means the shader features - // are confused as to what is instanced. - // - AssertFatal( !handle->mVertexConstant && - !handle->mPixelConstant, - "GFXD3D9Shader::_buildInstancingShaderConstantHandles - Bad instanced constant!" ); - - // HACK: The GFXD3D9ShaderConstHandle will check mVertexConstant then - // fall back to reading the mPixelHandle values. We depend on this here - // and store the data we need in the mPixelHandle constant although its - // not a pixel shader constant. - // - handle->mPixelHandle.name = constName; - handle->mPixelHandle.offset = offset; - - // If this is a matrix we will have 2 or 3 more of these - // semantics with the same name after it. - for ( ; i < mInstancingFormat->getElementCount(); i++ ) - { - const GFXVertexElement &nextElement = mInstancingFormat->getElement( i ); - if ( nextElement.getSemantic() != element.getSemantic() ) - { - i--; - break; - } - offset += nextElement.getSizeInBytes(); - } - } -} - -GFXShaderConstBufferRef GFXD3D9Shader::allocConstBuffer() -{ - if (mVertexConstBufferLayoutF && mPixelConstBufferLayoutF) - { - GFXD3D9ShaderConstBuffer* buffer = new GFXD3D9ShaderConstBuffer(this, mVertexConstBufferLayoutF, mVertexConstBufferLayoutI, mPixelConstBufferLayoutF, mPixelConstBufferLayoutI); - mActiveBuffers.push_back( buffer ); - buffer->registerResourceWithDevice(getOwningDevice()); - return buffer; - } else { - return NULL; - } -} - -/// Returns a shader constant handle for name -GFXShaderConstHandle* GFXD3D9Shader::getShaderConstHandle(const String& name) -{ - HandleMap::Iterator i = mHandles.find(name); - if ( i != mHandles.end() ) - { - return i->value; - } - else - { - GFXD3D9ShaderConstHandle *handle = new GFXD3D9ShaderConstHandle(); - handle->setValid( false ); - handle->mShader = this; - mHandles[name] = handle; - - return handle; - } -} - -/// Returns a shader constant handle for name, if the variable doesn't exist NULL is returned. -GFXShaderConstHandle* GFXD3D9Shader::findShaderConstHandle(const String& name) -{ - HandleMap::Iterator i = mHandles.find(name); - if ( i != mHandles.end() ) - { - return i->value; - } - else - { - return NULL; - } -} - -const Vector& GFXD3D9Shader::getShaderConstDesc() const -{ - return mShaderConsts; -} - -U32 GFXD3D9Shader::getAlignmentValue(const GFXShaderConstType constType) const -{ - const U32 mRowSizeF = 16; - const U32 mRowSizeI = 16; - - switch (constType) - { - case GFXSCT_Float : - case GFXSCT_Float2 : - case GFXSCT_Float3 : - case GFXSCT_Float4 : - return mRowSizeF; - break; - // Matrices - case GFXSCT_Float2x2 : - return mRowSizeF * 2; - break; - case GFXSCT_Float3x3 : - return mRowSizeF * 3; - break; - case GFXSCT_Float3x4 : - return mRowSizeF * 4; - break; - case GFXSCT_Float4x4 : - return mRowSizeF * 4; - break; - case GFXSCT_Float4x3 : - return mRowSizeF * 3; - break; - //// Scalar - case GFXSCT_Int : - case GFXSCT_Int2 : - case GFXSCT_Int3 : - case GFXSCT_Int4 : - return mRowSizeI; - break; - default: - AssertFatal(false, "Unsupported type!"); - return 0; - break; - } -} - -void GFXD3D9Shader::zombify() -{ - // Shaders don't need zombification -} - -void GFXD3D9Shader::resurrect() -{ - // Shaders are never zombies, and therefore don't have to be brought back. -} diff --git a/Engine/source/gfx/D3D9/gfxD3D9Shader.h b/Engine/source/gfx/D3D9/gfxD3D9Shader.h deleted file mode 100644 index ccc3af282..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9Shader.h +++ /dev/null @@ -1,288 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFXD3D9SHADER_H_ -#define _GFXD3D9SHADER_H_ - -#ifndef _PATH_H_ -#include "core/util/path.h" -#endif -#ifndef _TDICTIONARY_H_ -#include "core/util/tDictionary.h" -#endif -#ifndef _GFXSHADER_H_ -#include "gfx/gfxShader.h" -#endif -#ifndef _GFXRESOURCE_H_ -#include "gfx/gfxResource.h" -#endif -#ifndef _GENERICCONSTBUFFER_H_ -#include "gfx/genericConstBuffer.h" -#endif - - -class GFXD3D9Shader; -struct IDirect3DVertexShader9; -struct IDirect3DPixelShader9; -struct IDirect3DDevice9; -struct ID3DXConstantTable; -struct ID3DXBuffer; -struct _D3DXMACRO; - - -class GFXD3D9ShaderBufferLayout : public GenericConstBufferLayout -{ -protected: - /// Set a matrix, given a base pointer - virtual bool setMatrix(const ParamDesc& pd, const GFXShaderConstType constType, const U32 size, const void* data, U8* basePointer); -}; - - -/// The D3D9 implementation of a shader constant handle. -class GFXD3D9ShaderConstHandle : public GFXShaderConstHandle -{ -public: - - // GFXShaderConstHandle - const String& getName() const; - GFXShaderConstType getType() const; - U32 getArraySize() const; - - WeakRefPtr mShader; - - bool mVertexConstant; - GenericConstBufferLayout::ParamDesc mVertexHandle; - bool mPixelConstant; - GenericConstBufferLayout::ParamDesc mPixelHandle; - - /// Is true if this constant is for hardware mesh instancing. - /// - /// Note: We currently store its settings in mPixelHandle. - /// - bool mInstancingConstant; - - void setValid( bool valid ) { mValid = valid; } - S32 getSamplerRegister() const; - - // Returns true if this is a handle to a sampler register. - bool isSampler() const - { - return ( mPixelConstant && mPixelHandle.constType >= GFXSCT_Sampler ) || - ( mVertexConstant && mVertexHandle.constType >= GFXSCT_Sampler ); - } - - /// Restore to uninitialized state. - void clear() - { - mShader = NULL; - mVertexConstant = false; - mPixelConstant = false; - mInstancingConstant = false; - mVertexHandle.clear(); - mPixelHandle.clear(); - mValid = false; - } - - GFXD3D9ShaderConstHandle(); -}; - - -/// The D3D9 implementation of a shader constant buffer. -class GFXD3D9ShaderConstBuffer : public GFXShaderConstBuffer -{ - friend class GFXD3D9Shader; - -public: - - GFXD3D9ShaderConstBuffer( GFXD3D9Shader* shader, - GFXD3D9ShaderBufferLayout* vertexLayoutF, - GFXD3D9ShaderBufferLayout* vertexLayoutI, - GFXD3D9ShaderBufferLayout* pixelLayoutF, - GFXD3D9ShaderBufferLayout* pixelLayoutI ); - virtual ~GFXD3D9ShaderConstBuffer(); - - /// Called by GFXD3D9Device to activate this buffer. - /// @param mPrevShaderBuffer The previously active buffer - void activate( GFXD3D9ShaderConstBuffer *prevShaderBuffer ); - - /// Used internally by GXD3D9ShaderConstBuffer to determine if it's dirty. - bool isDirty(); - - /// Called from GFXD3D9Shader when constants have changed and need - /// to be the shader this buffer references is reloaded. - void onShaderReload( GFXD3D9Shader *shader ); - - // GFXShaderConstBuffer - virtual GFXShader* getShader(); - virtual void set(GFXShaderConstHandle* handle, const F32 fv); - virtual void set(GFXShaderConstHandle* handle, const Point2F& fv); - virtual void set(GFXShaderConstHandle* handle, const Point3F& fv); - virtual void set(GFXShaderConstHandle* handle, const Point4F& fv); - virtual void set(GFXShaderConstHandle* handle, const PlaneF& fv); - virtual void set(GFXShaderConstHandle* handle, const ColorF& fv); - virtual void set(GFXShaderConstHandle* handle, const S32 f); - virtual void set(GFXShaderConstHandle* handle, const Point2I& fv); - virtual void set(GFXShaderConstHandle* handle, const Point3I& fv); - virtual void set(GFXShaderConstHandle* handle, const Point4I& fv); - virtual void set(GFXShaderConstHandle* handle, const AlignedArray& fv); - virtual void set(GFXShaderConstHandle* handle, const AlignedArray& fv); - virtual void set(GFXShaderConstHandle* handle, const AlignedArray& fv); - virtual void set(GFXShaderConstHandle* handle, const AlignedArray& fv); - virtual void set(GFXShaderConstHandle* handle, const AlignedArray& fv); - virtual void set(GFXShaderConstHandle* handle, const AlignedArray& fv); - virtual void set(GFXShaderConstHandle* handle, const AlignedArray& fv); - virtual void set(GFXShaderConstHandle* handle, const AlignedArray& fv); - virtual void set(GFXShaderConstHandle* handle, const MatrixF& mat, const GFXShaderConstType matType = GFXSCT_Float4x4); - virtual void set(GFXShaderConstHandle* handle, const MatrixF* mat, const U32 arraySize, const GFXShaderConstType matrixType = GFXSCT_Float4x4); - - // GFXResource - virtual const String describeSelf() const; - virtual void zombify(); - virtual void resurrect(); - -protected: - - template - inline void SET_CONSTANT( GFXShaderConstHandle* handle, - const T& fv, - GenericConstBuffer *vBuffer, - GenericConstBuffer *pBuffer ); - - /// A cached direct pointer to the device. - IDirect3DDevice9 *mDevice; - - /// We keep a weak reference to the shader - /// because it will often be deleted. - WeakRefPtr mShader; - - GFXD3D9ShaderBufferLayout* mVertexConstBufferLayoutF; - GenericConstBuffer* mVertexConstBufferF; - GFXD3D9ShaderBufferLayout* mPixelConstBufferLayoutF; - GenericConstBuffer* mPixelConstBufferF; - GFXD3D9ShaderBufferLayout* mVertexConstBufferLayoutI; - GenericConstBuffer* mVertexConstBufferI; - GFXD3D9ShaderBufferLayout* mPixelConstBufferLayoutI; - GenericConstBuffer* mPixelConstBufferI; -}; - - -class _gfxD3DXInclude; -typedef StrongRefPtr<_gfxD3DXInclude> _gfxD3DXIncludeRef; - -/// The D3D9 implementation of a shader. -class GFXD3D9Shader : public GFXShader -{ - friend class GFXD3D9Device; - friend class GFX360Device; - friend class GFXD3D9ShaderConstBuffer; - friend class GFX360ShaderConstBuffer; -public: - typedef Map HandleMap; - - GFXD3D9Shader(); - virtual ~GFXD3D9Shader(); - - // GFXShader - virtual GFXShaderConstBufferRef allocConstBuffer(); - virtual const Vector& getShaderConstDesc() const; - virtual GFXShaderConstHandle* getShaderConstHandle(const String& name); - virtual GFXShaderConstHandle* findShaderConstHandle(const String& name); - virtual U32 getAlignmentValue(const GFXShaderConstType constType) const; - virtual bool getDisassembly( String &outStr ) const; - - // GFXResource - virtual void zombify(); - virtual void resurrect(); - -protected: - - virtual bool _init(); - - static const U32 smCompiledShaderTag; - - IDirect3DDevice9 *mD3D9Device; - - IDirect3DVertexShader9 *mVertShader; - IDirect3DPixelShader9 *mPixShader; - - GFXD3D9ShaderBufferLayout* mVertexConstBufferLayoutF; - GFXD3D9ShaderBufferLayout* mPixelConstBufferLayoutF; - GFXD3D9ShaderBufferLayout* mVertexConstBufferLayoutI; - GFXD3D9ShaderBufferLayout* mPixelConstBufferLayoutI; - - static _gfxD3DXIncludeRef smD3DXInclude; - - HandleMap mHandles; - - /// The shader disassembly from DX when this shader is compiled. - /// We only store this data in non-release builds. - String mDissasembly; - - /// Vector of sampler type descriptions consolidated from _compileShader. - Vector mSamplerDescriptions; - - /// Vector of descriptions (consolidated for the getShaderConstDesc call) - Vector mShaderConsts; - - // These two functions are used when compiling shaders from hlsl - virtual bool _compileShader( const Torque::Path &filePath, - const String &target, - const _D3DXMACRO *defines, - GenericConstBufferLayout *bufferLayoutF, - GenericConstBufferLayout *bufferLayoutI, - Vector &samplerDescriptions ); - - void _getShaderConstants( ID3DXConstantTable* table, - GenericConstBufferLayout *bufferLayoutF, - GenericConstBufferLayout *bufferLayoutI, - Vector &samplerDescriptions ); - - bool _saveCompiledOutput( const Torque::Path &filePath, - ID3DXBuffer *buffer, - GenericConstBufferLayout *bufferLayoutF, - GenericConstBufferLayout *bufferLayoutI, - Vector &samplerDescriptions ); - - // Loads precompiled shaders - bool _loadCompiledOutput( const Torque::Path &filePath, - const String &target, - GenericConstBufferLayout *bufferLayoutF, - GenericConstBufferLayout *bufferLayoutI, - Vector &samplerDescriptions ); - - // This is used in both cases - virtual void _buildShaderConstantHandles( GenericConstBufferLayout *layout, bool vertexConst ); - - virtual void _buildSamplerShaderConstantHandles( Vector &samplerDescriptions ); - - /// Used to build the instancing shader constants from - /// the instancing vertex format. - void _buildInstancingShaderConstantHandles(); -}; - -inline bool GFXD3D9Shader::getDisassembly( String &outStr ) const -{ - outStr = mDissasembly; - return ( outStr.isNotEmpty() ); -} - -#endif // _GFXD3D9SHADER_H_ \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/gfxD3D9StateBlock.cpp b/Engine/source/gfx/D3D9/gfxD3D9StateBlock.cpp deleted file mode 100644 index b24a2c852..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9StateBlock.cpp +++ /dev/null @@ -1,203 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/gfxDevice.h" - -#if defined(TORQUE_OS_XENON) -# include -#else -# include -#endif - -#include "gfx/D3D9/gfxD3D9StateBlock.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" - -GFXD3D9StateBlock::GFXD3D9StateBlock(const GFXStateBlockDesc& desc, LPDIRECT3DDEVICE9 d3dDevice) -{ - AssertFatal(d3dDevice, "Invalid mD3DDevice!"); - - mDesc = desc; - mCachedHashValue = desc.getHashValue(); - mD3DDevice = d3dDevice; - - // Color writes - mColorMask = 0; - mColorMask |= ( mDesc.colorWriteRed ? GFXCOLORWRITEENABLE_RED : 0 ); - mColorMask |= ( mDesc.colorWriteGreen ? GFXCOLORWRITEENABLE_GREEN : 0 ); - mColorMask |= ( mDesc.colorWriteBlue ? GFXCOLORWRITEENABLE_BLUE : 0 ); - mColorMask |= ( mDesc.colorWriteAlpha ? GFXCOLORWRITEENABLE_ALPHA : 0 ); - - // Z*bias - mZBias = *((U32*)&mDesc.zBias); - mZSlopeBias = *((U32*)&mDesc.zSlopeBias); -} - -GFXD3D9StateBlock::~GFXD3D9StateBlock() -{ - -} - -/// Returns the hash value of the desc that created this block -U32 GFXD3D9StateBlock::getHashValue() const -{ - return mCachedHashValue; -} - -/// Returns a GFXStateBlockDesc that this block represents -const GFXStateBlockDesc& GFXD3D9StateBlock::getDesc() const -{ - return mDesc; -} - -/// Called by D3D9 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 GFXD3D9StateBlock::activate(GFXD3D9StateBlock* oldState) -{ - PROFILE_SCOPE( GFXD3D9StateBlock_Activate ); - - // Little macro to save some typing, SD = state diff, checks for null source state block, then - // checks to see if the states differ -#if defined(TORQUE_OS_XENON) - #define SD(x, y) if (!oldState || oldState->mDesc.x != mDesc.x) \ - mD3DDevice->SetRenderState_Inline(y, mDesc.x) - - // Same as above, but allows you to set the data - #define SDD(x, y, z) if (!oldState || oldState->mDesc.x != mDesc.x) \ - mD3DDevice->SetRenderState_Inline(y, z) -#else - #define SD(x, y) if (!oldState || oldState->mDesc.x != mDesc.x) \ - mD3DDevice->SetRenderState(y, mDesc.x) - - // Same as above, but allows you to set the data - #define SDD(x, y, z) if (!oldState || oldState->mDesc.x != mDesc.x) \ - mD3DDevice->SetRenderState(y, z) -#endif - - // Blending - SD(blendEnable, D3DRS_ALPHABLENDENABLE); - SDD(blendSrc, D3DRS_SRCBLEND, GFXD3D9Blend[mDesc.blendSrc]); - SDD(blendDest, D3DRS_DESTBLEND, GFXD3D9Blend[mDesc.blendDest]); - SDD(blendOp, D3DRS_BLENDOP, GFXD3D9BlendOp[mDesc.blendOp]); - - // Separate alpha blending - SD(separateAlphaBlendEnable, D3DRS_SEPARATEALPHABLENDENABLE); - SDD(separateAlphaBlendSrc, D3DRS_SRCBLENDALPHA, GFXD3D9Blend[mDesc.separateAlphaBlendSrc]); - SDD(separateAlphaBlendDest, D3DRS_DESTBLENDALPHA, GFXD3D9Blend[mDesc.separateAlphaBlendDest]); - SDD(separateAlphaBlendOp, D3DRS_BLENDOPALPHA, GFXD3D9BlendOp[mDesc.separateAlphaBlendOp]); - - // Alpha test - SD(alphaTestEnable, D3DRS_ALPHATESTENABLE); - SDD(alphaTestFunc, D3DRS_ALPHAFUNC, GFXD3D9CmpFunc[mDesc.alphaTestFunc]); - SD(alphaTestRef, D3DRS_ALPHAREF); - - // Color writes - if ((oldState == NULL) || (mColorMask != oldState->mColorMask)) - mD3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, mColorMask); - - // Culling - SDD(cullMode, D3DRS_CULLMODE, GFXD3D9CullMode[mDesc.cullMode]); - - // Depth - SD(zEnable, D3DRS_ZENABLE); - SD(zWriteEnable, D3DRS_ZWRITEENABLE); - SDD(zFunc, D3DRS_ZFUNC, GFXD3D9CmpFunc[mDesc.zFunc]); - if ((!oldState) || (mZBias != oldState->mZBias)) - mD3DDevice->SetRenderState(D3DRS_DEPTHBIAS, mZBias); - if ((!oldState) || (mZSlopeBias != oldState->mZSlopeBias)) - mD3DDevice->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, mZSlopeBias); - - // Stencil - SD(stencilEnable, D3DRS_STENCILENABLE); - SDD(stencilFailOp, D3DRS_STENCILFAIL, GFXD3D9StencilOp[mDesc.stencilFailOp]); - SDD(stencilZFailOp, D3DRS_STENCILZFAIL, GFXD3D9StencilOp[mDesc.stencilZFailOp]); - SDD(stencilPassOp, D3DRS_STENCILPASS, GFXD3D9StencilOp[mDesc.stencilPassOp]); - SDD(stencilFunc, D3DRS_STENCILFUNC, GFXD3D9CmpFunc[mDesc.stencilFunc]); - SD(stencilRef, D3DRS_STENCILREF); - SD(stencilMask, D3DRS_STENCILMASK); - SD(stencilWriteMask, D3DRS_STENCILWRITEMASK); - SDD(fillMode, D3DRS_FILLMODE, GFXD3D9FillMode[mDesc.fillMode]); -#if !defined(TORQUE_OS_XENON) - SD(ffLighting, D3DRS_LIGHTING); - SD(vertexColorEnable, D3DRS_COLORVERTEX); - - static DWORD swzTemp; - getOwningDevice()->getDeviceSwizzle32()->ToBuffer( &swzTemp, &mDesc.textureFactor, sizeof(ColorI) ); - SDD(textureFactor, D3DRS_TEXTUREFACTOR, swzTemp); -#endif -#undef SD -#undef SDD - - - // NOTE: Samplers and Stages are different things. - // - // The Stages were for fixed function blending. When using shaders - // calling SetTextureStageState() is a complete waste of time. In - // fact if this function rises to the top of profiles we should - // refactor stateblocks to seperate the two. - // - // Samplers are used by both fixed function and shaders, but the - // number of samplers is limited by shader model. -#if !defined(TORQUE_OS_XENON) - - #define TSS(x, y, z) if (!oldState || oldState->mDesc.samplers[i].x != mDesc.samplers[i].x) \ - mD3DDevice->SetTextureStageState(i, y, z) - for ( U32 i = 0; i < 8; i++ ) - { - TSS(textureColorOp, D3DTSS_COLOROP, GFXD3D9TextureOp[mDesc.samplers[i].textureColorOp]); - TSS(colorArg1, D3DTSS_COLORARG1, mDesc.samplers[i].colorArg1); - TSS(colorArg2, D3DTSS_COLORARG2, mDesc.samplers[i].colorArg2); - TSS(colorArg3, D3DTSS_COLORARG0, mDesc.samplers[i].colorArg3); - TSS(alphaOp, D3DTSS_ALPHAOP, GFXD3D9TextureOp[mDesc.samplers[i].alphaOp]); - TSS(alphaArg1, D3DTSS_ALPHAARG1, mDesc.samplers[i].alphaArg1); - TSS(alphaArg2, D3DTSS_ALPHAARG2, mDesc.samplers[i].alphaArg2); - TSS(alphaArg3, D3DTSS_ALPHAARG0, mDesc.samplers[i].alphaArg3); - TSS(textureTransform, D3DTSS_TEXTURETRANSFORMFLAGS, mDesc.samplers[i].textureTransform); - TSS(resultArg, D3DTSS_RESULTARG, mDesc.samplers[i].resultArg); - } - #undef TSS -#endif - -#if defined(TORQUE_OS_XENON) - #define SS(x, y, z) if (!oldState || oldState->mDesc.samplers[i].x != mDesc.samplers[i].x) \ - mD3DDevice->SetSamplerState_Inline(i, y, z) -#else - #define SS(x, y, z) if (!oldState || oldState->mDesc.samplers[i].x != mDesc.samplers[i].x) \ - mD3DDevice->SetSamplerState(i, y, z) -#endif - for ( U32 i = 0; i < getOwningDevice()->getNumSamplers(); i++ ) - { - SS(minFilter, D3DSAMP_MINFILTER, GFXD3D9TextureFilter[mDesc.samplers[i].minFilter]); - SS(magFilter, D3DSAMP_MAGFILTER, GFXD3D9TextureFilter[mDesc.samplers[i].magFilter]); - SS(mipFilter, D3DSAMP_MIPFILTER, GFXD3D9TextureFilter[mDesc.samplers[i].mipFilter]); - - F32 bias = mDesc.samplers[i].mipLODBias; - DWORD dwBias = *( (LPDWORD)(&bias) ); - SS(mipLODBias, D3DSAMP_MIPMAPLODBIAS, dwBias); - - SS(maxAnisotropy, D3DSAMP_MAXANISOTROPY, mDesc.samplers[i].maxAnisotropy); - - SS(addressModeU, D3DSAMP_ADDRESSU, GFXD3D9TextureAddress[mDesc.samplers[i].addressModeU]); - SS(addressModeV, D3DSAMP_ADDRESSV, GFXD3D9TextureAddress[mDesc.samplers[i].addressModeV]); - SS(addressModeW, D3DSAMP_ADDRESSW, GFXD3D9TextureAddress[mDesc.samplers[i].addressModeW]); - } - #undef SS -} diff --git a/Engine/source/gfx/D3D9/gfxD3D9StateBlock.h b/Engine/source/gfx/D3D9/gfxD3D9StateBlock.h deleted file mode 100644 index ea9044f88..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9StateBlock.h +++ /dev/null @@ -1,73 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- -#ifndef _GFXD3D9STATEBLOCK_H_ -#define _GFXD3D9STATEBLOCK_H_ - -#ifndef _GFXSTATEBLOCK_H_ -#include "gfx/gfxStateBlock.h" -#endif - -struct IDirect3DDevice9; -class GFXD3D9StateBlock : public GFXStateBlock -{ -public: - // - // GFXD3D9StateBlock interface - // - - GFXD3D9StateBlock(const GFXStateBlockDesc& desc, IDirect3DDevice9 *d3dDevice); - virtual ~GFXD3D9StateBlock(); - - /// Called by D3D9 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 activate(GFXD3D9StateBlock* oldState); - - - // - // GFXStateBlock interface - // - - /// Returns the hash value of the desc that created this block - virtual U32 getHashValue() const; - - /// Returns a GFXStateBlockDesc that this block represents - virtual const GFXStateBlockDesc& getDesc() const; - - // - // GFXResource - // - virtual void zombify() { } - /// When called the resource should restore all device sensitive information destroyed by zombify() - virtual void resurrect() { } -private: - GFXStateBlockDesc mDesc; - U32 mCachedHashValue; - IDirect3DDevice9 *mD3DDevice; ///< Handle for D3DDevice - // Cached D3D specific things, these are "calculated" from GFXStateBlock - U32 mColorMask; - U32 mZBias; - U32 mZSlopeBias; -}; - -typedef StrongRefPtr GFXD3D9StateBlockRef; - -#endif \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/gfxD3D9TextureManager.cpp b/Engine/source/gfx/D3D9/gfxD3D9TextureManager.cpp deleted file mode 100644 index 90939463f..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9TextureManager.cpp +++ /dev/null @@ -1,640 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifdef _MSC_VER -#pragma warning(disable: 4996) -#endif - -#include "gfx/D3D9/gfxD3D9Device.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" -#include "gfx/bitmap/bitmapUtils.h" -#include "gfx/gfxCardProfile.h" -#include "core/strings/unicode.h" -#include "core/util/swizzle.h" -#include "core/util/safeDelete.h" -#include "console/console.h" -#include "core/resourceManager.h" - -//----------------------------------------------------------------------------- -// Utility function, valid only in this file -#ifdef D3D_TEXTURE_SPEW -U32 GFXD3D9TextureObject::mTexCount = 0; -#endif - -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -GFXD3D9TextureManager::GFXD3D9TextureManager( LPDIRECT3DDEVICE9 d3ddevice, U32 adapterIndex ) -{ - mD3DDevice = d3ddevice; - mAdapterIndex = adapterIndex; - dMemset( mCurTexSet, 0, sizeof( mCurTexSet ) ); - mD3DDevice->GetDeviceCaps(&mDeviceCaps); -} - -//----------------------------------------------------------------------------- -// Destructor -//----------------------------------------------------------------------------- -GFXD3D9TextureManager::~GFXD3D9TextureManager() -{ - // Destroy texture table now so just in case some texture objects - // are still left, we don't crash on a pure virtual method call. - SAFE_DELETE_ARRAY( mHashTable ); -} - -//----------------------------------------------------------------------------- -// _innerCreateTexture -//----------------------------------------------------------------------------- -void GFXD3D9TextureManager::_innerCreateTexture( GFXD3D9TextureObject *retTex, - U32 height, - U32 width, - U32 depth, - GFXFormat format, - GFXTextureProfile *profile, - U32 numMipLevels, - bool forceMips, - S32 antialiasLevel) -{ - GFXD3D9Device* d3d = static_cast(GFX); - - // Some relevant helper information... - bool supportsAutoMips = GFX->getCardProfiler()->queryProfile("autoMipMapLevel", true); - - DWORD usage = 0; // 0, D3DUSAGE_RENDERTARGET, or D3DUSAGE_DYNAMIC - D3DPOOL pool = D3DPOOL_DEFAULT; - - retTex->mProfile = profile; - - D3DFORMAT d3dTextureFormat = GFXD3D9TextureFormat[format]; - -#ifndef TORQUE_OS_XENON - if( retTex->mProfile->isDynamic() ) - { - usage = D3DUSAGE_DYNAMIC; - } - else - { - usage = 0; - pool = d3d->isD3D9Ex() ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED; - } - - if( retTex->mProfile->isRenderTarget() ) - { - pool = D3DPOOL_DEFAULT; - usage |= D3DUSAGE_RENDERTARGET; - } - - if(retTex->mProfile->isZTarget()) - { - usage |= D3DUSAGE_DEPTHSTENCIL; - pool = D3DPOOL_DEFAULT; - } - - if( retTex->mProfile->isSystemMemory() ) - { - pool = D3DPOOL_SYSTEMMEM; - } - - if( supportsAutoMips && - !forceMips && - !retTex->mProfile->isSystemMemory() && - numMipLevels == 0 && - !(depth > 0) ) - { - usage |= D3DUSAGE_AUTOGENMIPMAP; - } -#else - if(retTex->mProfile->isRenderTarget()) - { - d3dTextureFormat = (D3DFORMAT)MAKELEFMT(d3dTextureFormat); - } -#endif - - // Set the managed flag... - retTex->isManaged = (pool == D3DPOOL_MANAGED) || d3d->isD3D9Ex(); - - if( depth > 0 ) - { -#ifdef TORQUE_OS_XENON - D3D9Assert( mD3DDevice->CreateVolumeTexture( width, height, depth, numMipLevels, 0 /* usage ignored on the 360 */, - d3dTextureFormat, pool, retTex->get3DTexPtr(), NULL), "Failed to create volume texture" ); -#else - D3D9Assert( - GFXD3DX.D3DXCreateVolumeTexture( - mD3DDevice, - width, - height, - depth, - numMipLevels, - usage, - d3dTextureFormat, - pool, - retTex->get3DTexPtr() - ), "GFXD3D9TextureManager::_createTexture - failed to create volume texture!" - ); -#endif - - retTex->mTextureSize.set( width, height, depth ); - retTex->mMipLevels = retTex->get3DTex()->GetLevelCount(); - // required for 3D texture support - John Kabus - retTex->mFormat = format; - } - else - { -#ifdef TORQUE_OS_XENON - D3D9Assert( mD3DDevice->CreateTexture(width, height, numMipLevels, usage, d3dTextureFormat, pool, retTex->get2DTexPtr(), NULL), "Failed to create texture" ); - retTex->mMipLevels = retTex->get2DTex()->GetLevelCount(); -#else - // Figure out AA settings for depth and render targets - D3DMULTISAMPLE_TYPE mstype; - DWORD mslevel; - - switch (antialiasLevel) - { - case 0 : - mstype = D3DMULTISAMPLE_NONE; - mslevel = 0; - break; - case AA_MATCH_BACKBUFFER : - mstype = d3d->getMultisampleType(); - mslevel = d3d->getMultisampleLevel(); - break; - default : - { - mstype = D3DMULTISAMPLE_NONMASKABLE; - mslevel = antialiasLevel; -#ifdef TORQUE_DEBUG - DWORD MaxSampleQualities; - d3d->getD3D()->CheckDeviceMultiSampleType(mAdapterIndex, D3DDEVTYPE_HAL, d3dTextureFormat, FALSE, D3DMULTISAMPLE_NONMASKABLE, &MaxSampleQualities); - AssertFatal(mslevel < MaxSampleQualities, "Invalid AA level!"); -#endif - } - break; - } - - bool fastCreate = true; - // Check for power of 2 textures - this is a problem with FX 5xxx cards - // with current drivers - 3/2/05 - if( !isPow2(width) || !isPow2(height) ) - { - fastCreate = false; - } - - if(retTex->mProfile->isZTarget()) - { - D3D9Assert(mD3DDevice->CreateDepthStencilSurface(width, height, d3dTextureFormat, - mstype, mslevel, retTex->mProfile->canDiscard(), retTex->getSurfacePtr(), NULL), "Failed to create Z surface" ); - - retTex->mFormat = format; // Assigning format like this should be fine. - } - else - { - // Try to create the texture directly - should gain us a bit in high - // performance cases where we know we're creating good stuff and we - // don't want to bother with D3DX - slow function. - HRESULT res = D3DERR_INVALIDCALL; - if( fastCreate ) - { - res = mD3DDevice->CreateTexture(width, height, numMipLevels, usage, d3dTextureFormat, pool, retTex->get2DTexPtr(), NULL); - } - - if( !fastCreate || (res != D3D_OK) ) - { - D3D9Assert( - GFXD3DX.D3DXCreateTexture( - mD3DDevice, - width, - height, - numMipLevels, - usage, - d3dTextureFormat, - pool, - retTex->get2DTexPtr() - ), "GFXD3D9TextureManager::_createTexture - failed to create texture!" - ); - } - - // If this is a render target, and it wants AA or wants to match the backbuffer (for example, to share the z) - // Check the caps though, if we can't stretchrect between textures, use the old RT method. (Which hopefully means - // that they can't force AA on us as well.) - if (retTex->mProfile->isRenderTarget() && mslevel != 0 && (mDeviceCaps.Caps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES)) - { - D3D9Assert(mD3DDevice->CreateRenderTarget(width, height, d3dTextureFormat, - mstype, mslevel, false, retTex->getSurfacePtr(), NULL), - "GFXD3D9TextureManager::_createTexture - unable to create render target"); - } - - // All done! - retTex->mMipLevels = retTex->get2DTex()->GetLevelCount(); - } -#endif - - // Get the actual size of the texture... - D3DSURFACE_DESC probeDesc; - ZeroMemory(&probeDesc, sizeof probeDesc); - - if( retTex->get2DTex() != NULL ) - D3D9Assert( retTex->get2DTex()->GetLevelDesc( 0, &probeDesc ), "Failed to get surface description"); - else if( retTex->getSurface() != NULL ) - D3D9Assert( retTex->getSurface()->GetDesc( &probeDesc ), "Failed to get surface description"); - - retTex->mTextureSize.set(probeDesc.Width, probeDesc.Height, 0); - - S32 fmt = probeDesc.Format; - -#if !defined(TORQUE_OS_XENON) - GFXREVERSE_LOOKUP( GFXD3D9TextureFormat, GFXFormat, fmt ); - retTex->mFormat = (GFXFormat)fmt; -#else - retTex->mFormat = format; -#endif - } -} - -//----------------------------------------------------------------------------- -// createTexture -//----------------------------------------------------------------------------- -GFXTextureObject *GFXD3D9TextureManager::_createTextureObject( U32 height, - U32 width, - U32 depth, - GFXFormat format, - GFXTextureProfile *profile, - U32 numMipLevels, - bool forceMips, - S32 antialiasLevel, - GFXTextureObject *inTex ) -{ - GFXD3D9TextureObject *retTex; - if ( inTex ) - { - AssertFatal( dynamic_cast( inTex ), "GFXD3D9TextureManager::_createTexture() - Bad inTex type!" ); - retTex = static_cast( inTex ); - retTex->release(); - } - else - { - retTex = new GFXD3D9TextureObject( GFX, profile ); - retTex->registerResourceWithDevice( GFX ); - } - - _innerCreateTexture(retTex, height, width, depth, format, profile, numMipLevels, forceMips, antialiasLevel); - - return retTex; -} - -//----------------------------------------------------------------------------- -// loadTexture - GBitmap -//----------------------------------------------------------------------------- -bool GFXD3D9TextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *pDL) -{ - PROFILE_SCOPE(GFXD3D9TextureManager_loadTexture); - - GFXD3D9TextureObject *texture = static_cast(aTexture); - -#ifdef TORQUE_OS_XENON - // If the texture is currently bound, it needs to be unbound before modifying it - if( texture->getTex() && texture->getTex()->IsSet( mD3DDevice ) ) - { - mD3DDevice->SetTexture( 0, NULL ); - mD3DDevice->SetTexture( 1, NULL ); - mD3DDevice->SetTexture( 2, NULL ); - mD3DDevice->SetTexture( 3, NULL ); - mD3DDevice->SetTexture( 4, NULL ); - mD3DDevice->SetTexture( 5, NULL ); - mD3DDevice->SetTexture( 6, NULL ); - mD3DDevice->SetTexture( 7, NULL ); - } -#endif - - // Check with profiler to see if we can do automatic mipmap generation. - const bool supportsAutoMips = GFX->getCardProfiler()->queryProfile("autoMipMapLevel", true); - - // Helper bool - const bool isCompressedTexFmt = aTexture->mFormat >= GFXFormatDXT1 && aTexture->mFormat <= GFXFormatDXT5; - - GFXD3D9Device* dev = static_cast(GFX); - - // Settings for mipmap generation - U32 maxDownloadMip = pDL->getNumMipLevels(); - U32 nbMipMapLevel = pDL->getNumMipLevels(); - - if( supportsAutoMips && !isCompressedTexFmt ) - { - maxDownloadMip = 1; - nbMipMapLevel = aTexture->mMipLevels; - } - - // Fill the texture... - for( int i = 0; i < maxDownloadMip; i++ ) - { - LPDIRECT3DSURFACE9 surf = NULL; - D3D9Assert(texture->get2DTex()->GetSurfaceLevel( i, &surf ), "Failed to get surface"); - - D3DLOCKED_RECT lockedRect; - -#ifdef TORQUE_OS_XENON - // On the 360, doing a LockRect doesn't work like it does with untiled memory - // so instead swizzle into some temporary memory, and then later use D3DX - // to do the upload properly. - FrameTemp swizzleMem(pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel()); - lockedRect.pBits = (void*)~swizzleMem; -#else - U32 waterMark = 0; - if (!dev->isD3D9Ex()) - surf->LockRect( &lockedRect, NULL, 0 ); - else - { - waterMark = FrameAllocator::getWaterMark(); - lockedRect.pBits = static_cast(FrameAllocator::alloc(pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel())); - } -#endif - - switch( texture->mFormat ) - { - case GFXFormatR8G8B8: - { - PROFILE_SCOPE(Swizzle24_Upload); - AssertFatal( pDL->getFormat() == GFXFormatR8G8B8, "Assumption failed" ); - GFX->getDeviceSwizzle24()->ToBuffer( lockedRect.pBits, pDL->getBits(i), - pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel() ); - } - break; - - case GFXFormatR8G8B8A8: - case GFXFormatR8G8B8X8: - { - PROFILE_SCOPE(Swizzle32_Upload); - GFX->getDeviceSwizzle32()->ToBuffer( lockedRect.pBits, pDL->getBits(i), - pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel() ); - } - break; - - default: - { - // Just copy the bits in no swizzle or padding - PROFILE_SCOPE(SwizzleNull_Upload); - AssertFatal( pDL->getFormat() == texture->mFormat, "Format mismatch" ); - dMemcpy( lockedRect.pBits, pDL->getBits(i), - pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel() ); - } - } - -#ifdef TORQUE_OS_XENON - RECT srcRect; - srcRect.bottom = pDL->getHeight(i); - srcRect.top = 0; - srcRect.left = 0; - srcRect.right = pDL->getWidth(i); - - D3DXLoadSurfaceFromMemory(surf, NULL, NULL, ~swizzleMem, (D3DFORMAT)MAKELINFMT(GFXD3D9TextureFormat[pDL->getFormat()]), - pDL->getWidth(i) * pDL->getBytesPerPixel(), NULL, &srcRect, false, 0, 0, D3DX_FILTER_NONE, 0); -#else - if (!dev->isD3D9Ex()) - surf->UnlockRect(); - else - { - RECT srcRect; - srcRect.top = 0; - srcRect.left = 0; - srcRect.right = pDL->getWidth(i); - srcRect.bottom = pDL->getHeight(i); - D3DXLoadSurfaceFromMemory(surf, NULL, NULL, lockedRect.pBits, GFXD3D9TextureFormat[pDL->getFormat()], pDL->getBytesPerPixel() * pDL->getWidth(i), NULL, &srcRect, D3DX_DEFAULT, 0); - FrameAllocator::setWaterMark(waterMark); - } -#endif - - surf->Release(); - } - - return true; -} - -//----------------------------------------------------------------------------- -// loadTexture - raw -//----------------------------------------------------------------------------- -bool GFXD3D9TextureManager::_loadTexture( GFXTextureObject *inTex, void *raw ) -{ - PROFILE_SCOPE(GFXD3D9TextureManager_loadTextureRaw); - - GFXD3D9TextureObject *texture = (GFXD3D9TextureObject *) inTex; - - // currently only for volume textures... - if( texture->getDepth() < 1 ) return false; - - - U32 bytesPerPix = 1; - - switch( texture->mFormat ) - { - case GFXFormatR8G8B8: - bytesPerPix = 3; - break; - case GFXFormatR8G8B8A8: - case GFXFormatR8G8B8X8: - case GFXFormatB8G8R8A8: - bytesPerPix = 4; - break; - } - - U32 rowPitch = texture->getWidth() * bytesPerPix; - U32 slicePitch = texture->getWidth() * texture->getHeight() * bytesPerPix; - - D3DBOX box; - box.Left = 0; - box.Right = texture->getWidth(); - box.Front = 0; - box.Back = texture->getDepth(); - box.Top = 0; - box.Bottom = texture->getHeight(); - - - LPDIRECT3DVOLUME9 volume = NULL; - D3D9Assert( texture->get3DTex()->GetVolumeLevel( 0, &volume ), "Failed to load volume" ); - -#ifdef TORQUE_OS_XENON - D3DLOCKED_BOX lockedBox; - volume->LockBox( &lockedBox, &box, 0 ); - - dMemcpy( lockedBox.pBits, raw, slicePitch * texture->getDepth() ); - - volume->UnlockBox(); -#else - D3D9Assert( - GFXD3DX.D3DXLoadVolumeFromMemory( - volume, - NULL, - NULL, - raw, - GFXD3D9TextureFormat[texture->mFormat], - rowPitch, - slicePitch, - NULL, - &box, -#ifdef TORQUE_OS_XENON - false, 0, 0, 0, // Unique to Xenon -pw -#endif - D3DX_FILTER_NONE, - 0 - ), - "Failed to load volume texture" - ); -#endif - - volume->Release(); - - - return true; -} - -//----------------------------------------------------------------------------- -// refreshTexture -//----------------------------------------------------------------------------- -bool GFXD3D9TextureManager::_refreshTexture(GFXTextureObject *texture) -{ - U32 usedStrategies = 0; - GFXD3D9TextureObject *realTex = static_cast( texture ); - - if(texture->mProfile->doStoreBitmap()) - { -// SAFE_RELEASE(realTex->mD3DTexture); -// _innerCreateTexture(realTex, texture->mTextureSize.x, texture->mTextureSize.y, texture->mFormat, texture->mProfile, texture->mMipLevels); - - if(texture->mBitmap) - _loadTexture(texture, texture->mBitmap); - - if(texture->mDDS) - _loadTexture(texture, texture->mDDS); - - usedStrategies++; - } - - if(texture->mProfile->isRenderTarget() || texture->mProfile->isDynamic() || - texture->mProfile->isZTarget()) - { - realTex->release(); - _innerCreateTexture(realTex, texture->getHeight(), texture->getWidth(), texture->getDepth(), texture->mFormat, - - texture->mProfile, texture->mMipLevels, false, texture->mAntialiasLevel); - usedStrategies++; - } - - AssertFatal(usedStrategies < 2, "GFXD3D9TextureManager::_refreshTexture - Inconsistent profile flags!"); - - return true; -} - - -//----------------------------------------------------------------------------- -// freeTexture -//----------------------------------------------------------------------------- -bool GFXD3D9TextureManager::_freeTexture(GFXTextureObject *texture, bool zombify) -{ - AssertFatal(dynamic_cast(texture),"Not an actual d3d texture object!"); - GFXD3D9TextureObject *tex = static_cast( texture ); - - // If it's a managed texture and we're zombifying, don't blast it, D3D allows - // us to keep it. - if(zombify && tex->isManaged) - return true; - - tex->release(); - - return true; -} - -/// Load a texture from a proper DDSFile instance. -bool GFXD3D9TextureManager::_loadTexture(GFXTextureObject *aTexture, DDSFile *dds) -{ - PROFILE_SCOPE(GFXD3D9TextureManager_loadTextureDDS); - - GFXD3D9TextureObject *texture = static_cast(aTexture); - - // Fill the texture... - for( S32 i = 0; i < aTexture->mMipLevels; i++ ) - { - PROFILE_SCOPE(GFXD3DTexMan_loadSurface); - - LPDIRECT3DSURFACE9 surf = NULL; - D3D9Assert(texture->get2DTex()->GetSurfaceLevel( i, &surf ), "Failed to get surface"); - -#if defined(TORQUE_OS_XENON) - XGTEXTURE_DESC surfDesc; - dMemset(&surfDesc, 0, sizeof(XGTEXTURE_DESC)); - XGGetSurfaceDesc(surf, &surfDesc); - - RECT srcRect; - srcRect.top = srcRect.left = 0; - srcRect.bottom = dds->getHeight(i); - srcRect.right = dds->getWidth(i); - - D3DXLoadSurfaceFromMemory(surf, NULL, NULL, dds->mSurfaces[0]->mMips[i], - (D3DFORMAT)MAKELINFMT(GFXD3D9TextureFormat[dds->mFormat]), dds->getSurfacePitch(i), - NULL, &srcRect, false, 0, 0, D3DX_FILTER_NONE, 0); -#else - - GFXD3D9Device* dev = static_cast(GFX); - - if (dev->isD3D9Ex()) - { - RECT r; - r.top = r.left = 0; - r.bottom = dds->getHeight(i); - r.right = dds->getWidth(i); - D3DXLoadSurfaceFromMemory(surf, NULL, NULL, dds->mSurfaces[0]->mMips[i], GFXD3D9TextureFormat[dds->mFormat], dds->getSurfacePitch(i), NULL, &r, D3DX_DEFAULT, 0); - } - else - { - D3DLOCKED_RECT lockedRect; - D3D9Assert( surf->LockRect( &lockedRect, NULL, 0 ), "Failed to lock surface level for load" ); - - AssertFatal( dds->mSurfaces.size() > 0, "Assumption failed. DDSFile has no surfaces." ); - - if ( dds->getSurfacePitch( i ) != lockedRect.Pitch ) - { - // Do a row-by-row copy. - U32 srcPitch = dds->getSurfacePitch( i ); - U32 srcHeight = dds->getHeight(); - U8* srcBytes = dds->mSurfaces[0]->mMips[i]; - U8* dstBytes = (U8*)lockedRect.pBits; - for (U32 i = 0; iUnlockRect(); - surf->Release(); - - return true; - } - - dMemcpy( lockedRect.pBits, dds->mSurfaces[0]->mMips[i], dds->getSurfaceSize(i) ); - - surf->UnlockRect(); - } -#endif - - surf->Release(); - } - - return true; -} \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/gfxD3D9TextureManager.h b/Engine/source/gfx/D3D9/gfxD3D9TextureManager.h deleted file mode 100644 index 528cc32ef..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9TextureManager.h +++ /dev/null @@ -1,74 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFXD3DTEXTUREMANAGER_H_ -#define _GFXD3DTEXTUREMANAGER_H_ - -#include "gfx/D3D9/gfxD3D9TextureObject.h" -#include "core/util/safeRelease.h" - -// #define D3D_TEXTURE_SPEW - - -//***************************************************************************** -// GFX D3D Texture Manager -//***************************************************************************** -class GFXD3D9TextureManager : public GFXTextureManager -{ - friend class GFXD3D9TextureObject; - - U32 mAdapterIndex; - -public: - GFXD3D9TextureManager( LPDIRECT3DDEVICE9 d3ddevice, U32 adapterIndex ); - virtual ~GFXD3D9TextureManager(); - -protected: - - // GFXTextureManager - GFXTextureObject *_createTextureObject( U32 height, - U32 width, - U32 depth, - GFXFormat format, - GFXTextureProfile *profile, - U32 numMipLevels, - bool forceMips = false, - S32 antialiasLevel = 0, - GFXTextureObject *inTex = NULL ); - bool _loadTexture(GFXTextureObject *texture, DDSFile *dds); - bool _loadTexture(GFXTextureObject *texture, GBitmap *bmp); - bool _loadTexture(GFXTextureObject *texture, void *raw); - bool _refreshTexture(GFXTextureObject *texture); - bool _freeTexture(GFXTextureObject *texture, bool zombify = false); - -private: - U32 mCurTexSet[TEXTURE_STAGE_COUNT]; - - LPDIRECT3DDEVICE9 mD3DDevice; - D3DCAPS9 mDeviceCaps; - - void _innerCreateTexture(GFXD3D9TextureObject *obj, U32 height, U32 width, - U32 depth, GFXFormat format, GFXTextureProfile *profile, U32 numMipLevels, - bool forceMips = false, S32 antialiasLevel = 0); -}; - -#endif diff --git a/Engine/source/gfx/D3D9/gfxD3D9TextureObject.cpp b/Engine/source/gfx/D3D9/gfxD3D9TextureObject.cpp deleted file mode 100644 index bdf0ef449..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9TextureObject.cpp +++ /dev/null @@ -1,277 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/gfxD3D9Device.h" -#include "gfx/D3D9/gfxD3D9TextureObject.h" -#include "platform/profiler.h" - -#ifdef TORQUE_OS_XENON -#include "gfx/D3D9/360/gfx360Device.h" -#include "gfx/D3D9/360/gfx360Target.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" -#endif - -U32 GFXD3D9TextureObject::mTexCount = 0; - -//***************************************************************************** -// GFX D3D Texture Object -//***************************************************************************** -GFXD3D9TextureObject::GFXD3D9TextureObject( GFXDevice * d, GFXTextureProfile *profile) - : GFXTextureObject( d, profile ) -{ -#ifdef D3D_TEXTURE_SPEW - mTexCount++; - Con::printf("+ texMake %d %x", mTexCount, this); -#endif - - isManaged = false; - mD3DTexture = NULL; - mLocked = false; - - mD3DSurface = NULL; -} - -//----------------------------------------------------------------------------- -// Destructor -//----------------------------------------------------------------------------- -GFXD3D9TextureObject::~GFXD3D9TextureObject() -{ - kill(); -#ifdef D3D_TEXTURE_SPEW - mTexCount--; - Con::printf("+ texkill %d %x", mTexCount, this); -#endif -} - -//----------------------------------------------------------------------------- -// lock -//----------------------------------------------------------------------------- -GFXLockedRect *GFXD3D9TextureObject::lock(U32 mipLevel /*= 0*/, RectI *inRect /*= NULL*/) -{ - AssertFatal( !mLocked, "GFXD3D9TextureObject::lock - The texture is already locked!" ); - - if( mProfile->isRenderTarget() ) - { - if( !mLockTex || - mLockTex->getWidth() != getWidth() || - mLockTex->getHeight() != getHeight() ) - { - mLockTex.set( getWidth(), getHeight(), mFormat, &GFXSystemMemProfile, avar("%s() - mLockTex (line %d)", __FUNCTION__, __LINE__) ); - } - - PROFILE_START(GFXD3D9TextureObject_lockRT); - - IDirect3DSurface9 *source; - D3D9Assert( get2DTex()->GetSurfaceLevel( 0, &source ), "GFXD3D9TextureObject::lock - failed to get our own texture's surface." ); - - IDirect3DSurface9 *dest; - GFXD3D9TextureObject *to = (GFXD3D9TextureObject *) &(*mLockTex); - D3D9Assert( to->get2DTex()->GetSurfaceLevel( 0, &dest ), "GFXD3D9TextureObject::lock - failed to get dest texture's surface." ); - -#ifndef TORQUE_OS_XENON - LPDIRECT3DDEVICE9 D3DDevice = dynamic_cast(GFX)->getDevice(); - HRESULT rtLockRes = D3DDevice->GetRenderTargetData( source, dest ); -#else - AssertFatal(false, "Use different functionality on the Xbox 360 to perform this task."); - HRESULT rtLockRes = E_FAIL; -#endif - source->Release(); - - if(!SUCCEEDED(rtLockRes)) - { - // This case generally occurs if the device is lost. The lock failed - // so clean up and return NULL. - dest->Release(); - PROFILE_END(); - return NULL; - } - - D3D9Assert( dest->LockRect( &mLockRect, NULL, D3DLOCK_READONLY ), NULL ); - dest->Release(); - mLocked = true; - - PROFILE_END(); - } - 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; - } - - D3D9Assert( get2DTex()->LockRect(mipLevel, &mLockRect, inRect ? &r : NULL, 0), - "GFXD3D9TextureObject::lock - could not lock non-RT texture!" ); - mLocked = true; - - } - - // GFXLockedRect is set up to correspond to D3DLOCKED_RECT, so this is ok. - return (GFXLockedRect*)&mLockRect; -} - -//----------------------------------------------------------------------------- -// unLock -//----------------------------------------------------------------------------- -void GFXD3D9TextureObject::unlock(U32 mipLevel) -{ - AssertFatal( mLocked, "GFXD3D9TextureObject::unlock - Attempting to unlock a surface that has not been locked" ); - -#ifndef TORQUE_OS_XENON - if( mProfile->isRenderTarget() ) - { - IDirect3DSurface9 *dest; - GFXD3D9TextureObject *to = (GFXD3D9TextureObject *) &(*mLockTex); - D3D9Assert( to->get2DTex()->GetSurfaceLevel( 0, &dest ), NULL ); - - dest->UnlockRect(); - dest->Release(); - - mLocked = false; - } - else -#endif - { - D3D9Assert( get2DTex()->UnlockRect(mipLevel), - "GFXD3D9TextureObject::unlock - could not unlock non-RT texture." ); - - mLocked = false; - } -} - -//------------------------------------------------------------------------------ - -void GFXD3D9TextureObject::release() -{ - static_cast( GFX )->destroyD3DResource( mD3DTexture ); - static_cast( GFX )->destroyD3DResource( mD3DSurface ); - mD3DTexture = NULL; - mD3DSurface = NULL; -} - -void GFXD3D9TextureObject::zombify() -{ - // Managed textures are managed by D3D - AssertFatal(!mLocked, "GFXD3D9TextureObject::zombify - Cannot zombify a locked texture!"); - if(isManaged) - return; - - release(); -} - -void GFXD3D9TextureObject::resurrect() -{ - // Managed textures are managed by D3D - if(isManaged) - return; - - static_cast(TEXMGR)->refreshTexture(this); -} - -//------------------------------------------------------------------------------ - -bool GFXD3D9TextureObject::copyToBmp(GBitmap* bmp) -{ -#ifdef TORQUE_OS_XENON - // TODO: Implement Xenon version -patw - return false; -#else - if (!bmp) - return false; - - // check format limitations - // at the moment we only support RGBA for the source (other 4 byte formats should - // be easy to add though) - AssertFatal(mFormat == GFXFormatR8G8B8A8 || mFormat == GFXFormatR8G8B8, "copyToBmp: invalid format"); - if (mFormat != GFXFormatR8G8B8A8 && mFormat != GFXFormatR8G8B8) - return false; - - PROFILE_START(GFXD3D9TextureObject_copyToBmp); - - AssertFatal(bmp->getWidth() == getWidth(), "doh"); - AssertFatal(bmp->getHeight() == getHeight(), "doh"); - U32 width = getWidth(); - U32 height = getHeight(); - - bmp->setHasTransparency(mHasTransparency); - - // set some constants - const U32 sourceBytesPerPixel = 4; - U32 destBytesPerPixel = 0; - if (bmp->getFormat() == GFXFormatR8G8B8A8) - destBytesPerPixel = 4; - else if (bmp->getFormat() == GFXFormatR8G8B8) - destBytesPerPixel = 3; - else - // unsupported - AssertFatal(false, "unsupported bitmap format"); - - // lock the texture - D3DLOCKED_RECT* lockRect = (D3DLOCKED_RECT*) lock(); - - // set pointers - U8* srcPtr = (U8*)lockRect->pBits; - 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?"); - - PROFILE_START(GFXD3D9TextureObject_copyToBmp_pixCopy); - // copy data into bitmap - for (S32 row = 0; row < height; ++row) - { - for (S32 col = 0; col < width; ++col) - { - destPtr[0] = srcPtr[2]; // red - destPtr[1] = srcPtr[1]; // green - destPtr[2] = srcPtr[0]; // blue - if (destBytesPerPixel == 4) - destPtr[3] = srcPtr[3]; // alpha - - // go to next pixel in src - srcPtr += sourceBytesPerPixel; - - // go to next pixel in dest - destPtr += destBytesPerPixel; - } - // 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"); - - // unlock - unlock(); - - PROFILE_END(); - - return true; -#endif -} diff --git a/Engine/source/gfx/D3D9/gfxD3D9TextureObject.h b/Engine/source/gfx/D3D9/gfxD3D9TextureObject.h deleted file mode 100644 index 34005194d..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9TextureObject.h +++ /dev/null @@ -1,80 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFXD3D9TEXTUREOBJECT_H_ -#define _GFXD3D9TEXTUREOBJECT_H_ - -#ifndef _GFXTEXTUREHANDLE_H_ -#include "gfx/gfxTextureHandle.h" -#endif - -#ifndef _GFXTEXTUREMANAGER_H_ -#include "gfx/gfxTextureManager.h" -#endif - - -class GFXD3D9TextureObject : public GFXTextureObject -{ -protected: - static U32 mTexCount; - GFXTexHandle mLockTex; - D3DLOCKED_RECT mLockRect; - bool mLocked; - - IDirect3DBaseTexture9 *mD3DTexture; - - // used for z buffers... - IDirect3DSurface9 *mD3DSurface; - -public: - - GFXD3D9TextureObject( GFXDevice * d, GFXTextureProfile *profile); - ~GFXD3D9TextureObject(); - - IDirect3DBaseTexture9 * getTex(){ return mD3DTexture; } - IDirect3DTexture9 * get2DTex(){ return (LPDIRECT3DTEXTURE9) mD3DTexture; } - IDirect3DTexture9 ** get2DTexPtr(){ return (LPDIRECT3DTEXTURE9*) &mD3DTexture; } - IDirect3DVolumeTexture9 * get3DTex(){ return (LPDIRECT3DVOLUMETEXTURE9) mD3DTexture; } - IDirect3DVolumeTexture9 ** get3DTexPtr(){ return (LPDIRECT3DVOLUMETEXTURE9*) &mD3DTexture; } - - void release(); - - bool isManaged; - - virtual GFXLockedRect * lock(U32 mipLevel = 0, RectI *inRect = NULL); - virtual void unlock(U32 mipLevel = 0 ); - - virtual bool copyToBmp(GBitmap* bmp); - IDirect3DSurface9 *getSurface() {return mD3DSurface;} - IDirect3DSurface9 **getSurfacePtr() {return &mD3DSurface;} - - // GFXResource - void zombify(); - void resurrect(); - -#ifdef TORQUE_DEBUG - virtual void pureVirtualCrash() {}; -#endif -}; - - -#endif diff --git a/Engine/source/gfx/D3D9/gfxD3D9VertexBuffer.cpp b/Engine/source/gfx/D3D9/gfxD3D9VertexBuffer.cpp deleted file mode 100644 index 9bcea80c7..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9VertexBuffer.cpp +++ /dev/null @@ -1,230 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "platform/platform.h" -#include "gfx/D3D9/gfxD3D9VertexBuffer.h" - -GFXD3D9VertexBuffer::~GFXD3D9VertexBuffer() -{ -#ifdef TORQUE_DEBUG - SAFE_DELETE( name ); -#endif - - if (getOwningDevice() != NULL) - { - if (mBufferType == GFXBufferTypeDynamic) - static_cast(getOwningDevice())->deallocVertexBuffer( this ); - else if (mBufferType != GFXBufferTypeVolatile) - { - static_cast(getOwningDevice())->destroyD3DResource( vb ); - } - } -} - -//----------------------------------------------------------------------------- -// Lock -//----------------------------------------------------------------------------- -void GFXD3D9VertexBuffer::lock(U32 vertexStart, U32 vertexEnd, void **vertexPtr) -{ - PROFILE_SCOPE(GFXD3D9VertexBuffer_lock); - - AssertFatal(lockedVertexStart == 0 && lockedVertexEnd == 0, "Cannot lock a buffer more than once!"); - - U32 flags = 0; - - GFXD3D9Device *d = static_cast( mDevice ); - - switch( mBufferType ) - { - case GFXBufferTypeImmutable: - case GFXBufferTypeStatic: - break; - - case GFXBufferTypeDynamic: -#ifndef TORQUE_OS_XENON - flags |= D3DLOCK_DISCARD; -#endif - break; - - case GFXBufferTypeVolatile: - - // Get or create the volatile buffer... - mVolatileBuffer = d->findVBPool( &mVertexFormat, vertexEnd ); - - if( !mVolatileBuffer ) - mVolatileBuffer = d->createVBPool( &mVertexFormat, mVertexSize ); - - vb = mVolatileBuffer->vb; - - // Get our range now... - AssertFatal(vertexStart == 0, "Cannot get a subrange on a volatile buffer."); - AssertFatal(vertexEnd <= MAX_DYNAMIC_VERTS, "Cannot get more than MAX_DYNAMIC_VERTS in a volatile buffer. Up the constant!"); - AssertFatal(mVolatileBuffer->lockedVertexStart == 0 && mVolatileBuffer->lockedVertexEnd == 0, "Got more than one lock on the volatile pool."); - - // We created the pool when we requested this volatile buffer, so assume it exists... - if( mVolatileBuffer->mNumVerts + vertexEnd > MAX_DYNAMIC_VERTS ) - { -#ifdef TORQUE_OS_XENON - AssertFatal( false, "This should never, ever happen. findVBPool should have returned NULL" ); -#else - flags |= D3DLOCK_DISCARD; -#endif - mVolatileStart = vertexStart = 0; - vertexEnd = vertexEnd; - } - else - { - flags |= D3DLOCK_NOOVERWRITE; - mVolatileStart = vertexStart = mVolatileBuffer->mNumVerts; - vertexEnd += mVolatileBuffer->mNumVerts; - } - - mVolatileBuffer->mNumVerts = vertexEnd+1; - - mVolatileBuffer->lockedVertexStart = vertexStart; - mVolatileBuffer->lockedVertexEnd = vertexEnd; - break; - } - - lockedVertexStart = vertexStart; - lockedVertexEnd = vertexEnd; - - // Con::printf("%x: Locking %s range (%d, %d)", this, (mBufferType == GFXBufferTypeVolatile ? "volatile" : "static"), lockedVertexStart, lockedVertexEnd); - -#ifdef TORQUE_OS_XENON - // If the vertex buffer which we are trying to lock is held by the D3D device - // on Xenon it will bomb. So if that is the case, then SetStreamSource to NULL - // and also call setVertexBuffer because otherwise the state-cache will be hosed - if( d->mCurrentVB != NULL && d->mCurrentVB->vb == vb ) - { - d->setVertexBuffer( NULL ); - d->mD3DDevice->SetStreamSource( 0, NULL, 0, 0 ); - } - - // As of October 2006 XDK, range locking is no longer supported. Lock the whole buffer - // and then manually offset the pointer to simulate the subrange. -patw - D3D9Assert( vb->Lock( 0, 0, vertexPtr, flags), - "Unable to lock vertex buffer."); - - U8 *tmp = (U8 *)(*vertexPtr); - tmp += ( vertexStart * mVertexSize ); - *vertexPtr = tmp; -#else - - U32 sizeToLock = (vertexEnd - vertexStart) * mVertexSize; - D3D9Assert( vb->Lock(vertexStart * mVertexSize, sizeToLock, vertexPtr, flags), - "Unable to lock vertex buffer."); - - #ifdef TORQUE_DEBUG - - // Allocate a debug buffer large enough for the lock - // plus space for over and under run guard strings. - const U32 guardSize = sizeof( _VBGuardString ); - mDebugGuardBuffer = new U8[sizeToLock+(guardSize*2)]; - - // Setup the guard strings. - dMemcpy( mDebugGuardBuffer, _VBGuardString, guardSize ); - dMemcpy( mDebugGuardBuffer + sizeToLock + guardSize, _VBGuardString, guardSize ); - - // Store the real lock pointer and return our debug pointer. - mLockedBuffer = *vertexPtr; - *vertexPtr = mDebugGuardBuffer + guardSize; - - #endif // TORQUE_DEBUG - -#endif -} - -void GFXD3D9VertexBuffer::unlock() -{ - PROFILE_SCOPE(GFXD3D9VertexBuffer_unlock); - - #ifdef TORQUE_DEBUG - - if ( mDebugGuardBuffer ) - { - const U32 guardSize = sizeof( _VBGuardString ); - const U32 sizeLocked = (lockedVertexEnd - lockedVertexStart) * mVertexSize; - - // First check the guard areas for overwrites. - AssertFatal( dMemcmp( mDebugGuardBuffer, _VBGuardString, guardSize ) == 0, - "GFXD3D9VertexBuffer::unlock - Caught lock memory underrun!" ); - AssertFatal( dMemcmp( mDebugGuardBuffer + sizeLocked + guardSize, _VBGuardString, guardSize ) == 0, - "GFXD3D9VertexBuffer::unlock - Caught lock memory overrun!" ); - - // Copy the debug content down to the real VB. - dMemcpy( mLockedBuffer, mDebugGuardBuffer + guardSize, sizeLocked ); - - // Cleanup. - delete [] mDebugGuardBuffer; - mDebugGuardBuffer = NULL; - mLockedBuffer = NULL; - } - - #endif // TORQUE_DEBUG - - D3D9Assert( vb->Unlock(), - "Unable to unlock vertex buffer."); - mIsFirstLock = false; - - // Con::printf("%x: Unlocking %s range (%d, %d)", this, (mBufferType == GFXBufferTypeVolatile ? "volatile" : "static"), lockedVertexStart, lockedVertexEnd); - - lockedVertexEnd = lockedVertexStart = 0; - - if(mVolatileBuffer.isValid()) - { - mVolatileBuffer->lockedVertexStart = 0; - mVolatileBuffer->lockedVertexEnd = 0; - mVolatileBuffer = NULL; - //vb->Release(); - //vb = NULL; - } -} - -void GFXD3D9VertexBuffer::zombify() -{ - AssertFatal(lockedVertexStart == 0 && lockedVertexEnd == 0, "GFXD3D9VertexBuffer::zombify - Cannot zombify a locked buffer!"); - // Static buffers are managed by D3D9 so we don't deal with them. - if(mBufferType == GFXBufferTypeDynamic || mBufferType == GFXBufferTypeImmutable) - { - SAFE_RELEASE(vb); - } -} - -void GFXD3D9VertexBuffer::resurrect() -{ - // Static buffers are managed by D3D9 so we don't deal with them. - if(mBufferType == GFXBufferTypeDynamic) - { - D3D9Assert(static_cast(mDevice)->mD3DDevice->CreateVertexBuffer( mVertexSize * mNumVerts, -#ifdef TORQUE_OS_XENON - D3DUSAGE_WRITEONLY, -#else - D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, -#endif - 0, - D3DPOOL_DEFAULT, - &vb, - NULL ), - "GFXD3D9VertexBuffer::resurrect - Failed to allocate VB" ); - } -} diff --git a/Engine/source/gfx/D3D9/gfxD3D9VertexBuffer.h b/Engine/source/gfx/D3D9/gfxD3D9VertexBuffer.h deleted file mode 100644 index 3be0e24b3..000000000 --- a/Engine/source/gfx/D3D9/gfxD3D9VertexBuffer.h +++ /dev/null @@ -1,136 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFXD3D_VERTEXBUFFER_H_ -#define _GFXD3D_VERTEXBUFFER_H_ - -#ifndef _GFXD3D9DEVICE_H_ -#include "gfx/D3D9/gfxD3D9Device.h" -#endif -#ifndef _SAFEDELETE_H_ -#include "core/util/safeDelete.h" -#endif - -//***************************************************************************** -// GFXD3D9VertexBuffer -//***************************************************************************** -class GFXD3D9VertexBuffer : public GFXVertexBuffer -{ -public: - IDirect3DVertexBuffer9 *vb; - StrongRefPtr mVolatileBuffer; - -#ifdef TORQUE_DEBUG - #define _VBGuardString "GFX_VERTEX_BUFFER_GUARD_STRING" - U8 *mDebugGuardBuffer; - void *mLockedBuffer; -#endif TORQUE_DEBUG - - bool mIsFirstLock; - bool mClearAtFrameEnd; - - GFXD3D9VertexBuffer(); - GFXD3D9VertexBuffer( GFXDevice *device, - U32 numVerts, - const GFXVertexFormat *vertexFormat, - U32 vertexSize, - GFXBufferType bufferType ); - virtual ~GFXD3D9VertexBuffer(); - - void lock(U32 vertexStart, U32 vertexEnd, void **vertexPtr); - void unlock(); - void prepare() {} - -#ifdef TORQUE_DEBUG - char *name; - - /// In debug compile, the verts will be chained together and the device - /// will examine the chain when it's destructor is called, this will - /// allow developers to see which vertex buffers are not destroyed - GFXD3D9VertexBuffer *next; -#endif - void setName( const char *n ); - - // GFXResource interface - virtual void zombify(); - virtual void resurrect(); -}; - -//----------------------------------------------------------------------------- -// This is for debugging vertex buffers and trying to track down which vbs -// aren't getting free'd - -inline GFXD3D9VertexBuffer::GFXD3D9VertexBuffer() -: GFXVertexBuffer(0,0,0,0,(GFXBufferType)0) -{ -#ifdef TORQUE_DEBUG - name = NULL; -#endif - vb = NULL; - mIsFirstLock = true; - lockedVertexEnd = lockedVertexStart = 0; - mClearAtFrameEnd = false; - -#ifdef TORQUE_DEBUG - mDebugGuardBuffer = NULL; - mLockedBuffer = NULL; -#endif -} - -inline GFXD3D9VertexBuffer::GFXD3D9VertexBuffer( GFXDevice *device, - U32 numVerts, - const GFXVertexFormat *vertexFormat, - U32 vertexSize, - GFXBufferType bufferType ) - : GFXVertexBuffer( device, numVerts, vertexFormat, vertexSize, bufferType ) -{ -#ifdef TORQUE_DEBUG - name = NULL; -#endif - vb = NULL; - mIsFirstLock = true; - mClearAtFrameEnd = false; - lockedVertexEnd = lockedVertexStart = 0; - -#ifdef TORQUE_DEBUG - mDebugGuardBuffer = NULL; - mLockedBuffer = NULL; -#endif -} - -#ifdef TORQUE_DEBUG - -inline void GFXD3D9VertexBuffer::setName( const char *n ) -{ - SAFE_DELETE( name ); - name = new char[dStrlen( n )]; - dStrcpy( name, n ); -} - -#else - -inline void GFXD3D9VertexBuffer::setName( const char *n ) { } - -#endif // !TORQUE_DEBUG - -#endif // _GFXD3D_VERTEXBUFFER_H_ - diff --git a/Engine/source/gfx/D3D9/pc/gfxD3D9Device.pc.cpp b/Engine/source/gfx/D3D9/pc/gfxD3D9Device.pc.cpp deleted file mode 100644 index 618a32117..000000000 --- a/Engine/source/gfx/D3D9/pc/gfxD3D9Device.pc.cpp +++ /dev/null @@ -1,87 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/pc/gfxPCD3D9Device.h" -#include "gfx/D3D9/gfxD3D9CardProfiler.h" -#include "gfx/D3D9/gfxD3D9Shader.h" -#include "gfx/D3D9/gfxD3D9VertexBuffer.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" -#include "core/strings/unicode.h" -#include "console/console.h" - -//------------------------------------------------------------------------------ -// D3DX Function binding -//------------------------------------------------------------------------------ - -bool d3dxBindFunction( DLibrary *dll, void *&fnAddress, const char *name ) -{ - fnAddress = dll->bind( name ); - - if (!fnAddress) - Con::warnf( "D3DX Loader: DLL bind failed for %s", name ); - - return fnAddress != 0; -} - -void GFXD3D9Device::initD3DXFnTable() -{ - if ( smD3DX.isLoaded ) - return; - - // We only load the d3dx version that we compiled - // and linked against which should keep unexpected - // problems from newer or older SDKs to a minimum. - String d3dxVersion = String::ToString( "d3dx9_%d.dll", (S32)D3DX_SDK_VERSION ); - smD3DX.dllRef = OsLoadLibrary( d3dxVersion ); - - // If the d3dx version we requested didn't load then we have - // a corrupt or old install of DirectX.... prompt them to update. - if ( !smD3DX.dllRef ) - { - Con::errorf( "Unsupported DirectX version!" ); - Platform::messageBox( Con::getVariable( "$appName" ), - "DirectX could not be started!\r\n" - "Please be sure you have the latest version of DirectX installed.", - MBOk, MIStop ); - Platform::forceShutdown( -1 ); - } - - smD3DX.isLoaded = true; - - #define D3DX_FUNCTION(fn_name, fn_return, fn_args) \ - smD3DX.isLoaded &= d3dxBindFunction(smD3DX.dllRef, *(void**)&smD3DX.fn_name, #fn_name); - # include "gfx/D3D9/d3dx9Functions.h" - #undef D3DX_FUNCTION - - AssertISV( smD3DX.isLoaded, "D3DX Failed to load all functions." ); - - // HACK: For some reason in the latest versions of - // the D3D SDK on the PC the shader compiler will load - // and unload the compiler DLL over and over with each - // shader compiled. - // - // By loading the DLL once ourselves we keep it from - // ever unloading it which makes shader compiling faster. - // - String compilerVersion = String::ToString( "D3DCompiler_%d.dll", (S32)D3DX_SDK_VERSION ); - smD3DX.compilerDllRef = OsLoadLibrary( compilerVersion ); -} diff --git a/Engine/source/gfx/D3D9/pc/gfxD3D9EnumTranslate.pc.cpp b/Engine/source/gfx/D3D9/pc/gfxD3D9EnumTranslate.pc.cpp deleted file mode 100644 index 1d51860c0..000000000 --- a/Engine/source/gfx/D3D9/pc/gfxD3D9EnumTranslate.pc.cpp +++ /dev/null @@ -1,380 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" -#include "console/console.h" - -//------------------------------------------------------------------------------ - -_D3DFORMAT GFXD3D9IndexFormat[GFXIndexFormat_COUNT]; -_D3DSAMPLERSTATETYPE GFXD3D9SamplerState[GFXSAMP_COUNT]; -_D3DFORMAT GFXD3D9TextureFormat[GFXFormat_COUNT]; -_D3DRENDERSTATETYPE GFXD3D9RenderState[GFXRenderState_COUNT]; -_D3DTEXTUREFILTERTYPE GFXD3D9TextureFilter[GFXTextureFilter_COUNT]; -_D3DBLEND GFXD3D9Blend[GFXBlend_COUNT]; -_D3DBLENDOP GFXD3D9BlendOp[GFXBlendOp_COUNT]; -_D3DSTENCILOP GFXD3D9StencilOp[GFXStencilOp_COUNT]; -_D3DCMPFUNC GFXD3D9CmpFunc[GFXCmp_COUNT]; -_D3DCULL GFXD3D9CullMode[GFXCull_COUNT]; -_D3DFILLMODE GFXD3D9FillMode[GFXFill_COUNT]; -_D3DPRIMITIVETYPE GFXD3D9PrimType[GFXPT_COUNT]; -_D3DTEXTURESTAGESTATETYPE GFXD3D9TextureStageState[GFXTSS_COUNT]; -_D3DTEXTUREADDRESS GFXD3D9TextureAddress[GFXAddress_COUNT]; -_D3DTEXTUREOP GFXD3D9TextureOp[GFXTOP_COUNT]; -_D3DDECLTYPE GFXD3D9DeclType[GFXDeclType_COUNT]; - -//------------------------------------------------------------------------------ - -#define INIT_LOOKUPTABLE( tablearray, enumprefix, type ) \ - for( S32 i = enumprefix##_FIRST; i < enumprefix##_COUNT; i++ ) \ - tablearray[i] = (type)GFX_UNINIT_VAL; - -#define VALIDATE_LOOKUPTABLE( tablearray, enumprefix ) \ - for( S32 i = enumprefix##_FIRST; i < enumprefix##_COUNT; i++ ) \ - if( (S32)tablearray[i] == GFX_UNINIT_VAL ) \ - Con::warnf( "GFXD3D9EnumTranslate: Unassigned value in " #tablearray ": %i", i ); \ - else if( (S32)tablearray[i] == GFX_UNSUPPORTED_VAL ) \ - Con::warnf( "GFXD3D9EnumTranslate: Unsupported value in " #tablearray ": %i", i ); - -//------------------------------------------------------------------------------ - -void GFXD3D9EnumTranslate::init() -{ - INIT_LOOKUPTABLE( GFXD3D9IndexFormat, GFXIndexFormat, _D3DFORMAT ); - GFXD3D9IndexFormat[GFXIndexFormat16] = D3DFMT_INDEX16; - GFXD3D9IndexFormat[GFXIndexFormat32] = D3DFMT_INDEX32; - VALIDATE_LOOKUPTABLE( GFXD3D9IndexFormat, GFXIndexFormat ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9SamplerState, GFXSAMP, _D3DSAMPLERSTATETYPE ); - GFXD3D9SamplerState[GFXSAMPAddressU] = D3DSAMP_ADDRESSU; - GFXD3D9SamplerState[GFXSAMPAddressV] = D3DSAMP_ADDRESSV; - GFXD3D9SamplerState[GFXSAMPAddressW] = D3DSAMP_ADDRESSW; - GFXD3D9SamplerState[GFXSAMPBorderColor] = D3DSAMP_BORDERCOLOR; - GFXD3D9SamplerState[GFXSAMPMagFilter] = D3DSAMP_MAGFILTER; - GFXD3D9SamplerState[GFXSAMPMinFilter] = D3DSAMP_MINFILTER; - GFXD3D9SamplerState[GFXSAMPMipFilter] = D3DSAMP_MIPFILTER; - GFXD3D9SamplerState[GFXSAMPMipMapLODBias] = D3DSAMP_MIPMAPLODBIAS; - GFXD3D9SamplerState[GFXSAMPMaxMipLevel] = D3DSAMP_MAXMIPLEVEL; - GFXD3D9SamplerState[GFXSAMPMaxAnisotropy] = D3DSAMP_MAXANISOTROPY; - GFXD3D9SamplerState[GFXSAMPSRGBTexture] = D3DSAMP_SRGBTEXTURE; - GFXD3D9SamplerState[GFXSAMPElementIndex] = D3DSAMP_ELEMENTINDEX; - GFXD3D9SamplerState[GFXSAMPDMapOffset] = D3DSAMP_DMAPOFFSET; - VALIDATE_LOOKUPTABLE( GFXD3D9SamplerState, GFXSAMP ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9TextureFormat, GFXFormat, _D3DFORMAT ); - GFXD3D9TextureFormat[GFXFormatR8G8B8] = D3DFMT_R8G8B8; - GFXD3D9TextureFormat[GFXFormatR8G8B8A8] = D3DFMT_A8R8G8B8; - GFXD3D9TextureFormat[GFXFormatR8G8B8X8] = D3DFMT_X8R8G8B8; - GFXD3D9TextureFormat[GFXFormatB8G8R8A8] = D3DFMT_A8R8G8B8; - GFXD3D9TextureFormat[GFXFormatR5G6B5] = D3DFMT_R5G6B5; - GFXD3D9TextureFormat[GFXFormatR5G5B5A1] = D3DFMT_A1R5G5B5; - GFXD3D9TextureFormat[GFXFormatR5G5B5X1] = D3DFMT_X1R5G5B5; - GFXD3D9TextureFormat[GFXFormatR32F] = D3DFMT_R32F; - GFXD3D9TextureFormat[GFXFormatA4L4] = D3DFMT_A4L4; - GFXD3D9TextureFormat[GFXFormatA8L8] = D3DFMT_A8L8; - GFXD3D9TextureFormat[GFXFormatA8] = D3DFMT_A8; - GFXD3D9TextureFormat[GFXFormatL8] = D3DFMT_L8; - GFXD3D9TextureFormat[GFXFormatDXT1] = D3DFMT_DXT1; - GFXD3D9TextureFormat[GFXFormatDXT2] = D3DFMT_DXT2; - GFXD3D9TextureFormat[GFXFormatDXT3] = D3DFMT_DXT3; - GFXD3D9TextureFormat[GFXFormatDXT4] = D3DFMT_DXT4; - GFXD3D9TextureFormat[GFXFormatDXT5] = D3DFMT_DXT5; - GFXD3D9TextureFormat[GFXFormatR32G32B32A32F] = D3DFMT_A32B32G32R32F; - GFXD3D9TextureFormat[GFXFormatR16G16B16A16F] = D3DFMT_A16B16G16R16F; - GFXD3D9TextureFormat[GFXFormatL16] = D3DFMT_L16; - GFXD3D9TextureFormat[GFXFormatR16G16B16A16] = D3DFMT_A16B16G16R16; - GFXD3D9TextureFormat[GFXFormatR16G16] = D3DFMT_G16R16; - GFXD3D9TextureFormat[GFXFormatR16F] = D3DFMT_R16F; - GFXD3D9TextureFormat[GFXFormatR16G16F] = D3DFMT_G16R16F; - GFXD3D9TextureFormat[GFXFormatR10G10B10A2] = D3DFMT_A2R10G10B10; - GFXD3D9TextureFormat[GFXFormatD32] = D3DFMT_D32; - GFXD3D9TextureFormat[GFXFormatD24X8] = D3DFMT_D24X8; - GFXD3D9TextureFormat[GFXFormatD24S8] = D3DFMT_D24S8; - GFXD3D9TextureFormat[GFXFormatD24FS8] = D3DFMT_D24FS8; - GFXD3D9TextureFormat[GFXFormatD16] = D3DFMT_D16; - GFXD3D9TextureFormat[GFXFormatR8G8B8A8_SRGB] = D3DFMT_UNKNOWN; - - GFXD3D9TextureFormat[GFXFormatR8G8B8A8_LINEAR_FORCE] = D3DFMT_A8R8G8B8; - VALIDATE_LOOKUPTABLE( GFXD3D9TextureFormat, GFXFormat); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9RenderState, GFXRenderState, _D3DRENDERSTATETYPE ); - GFXD3D9RenderState[GFXRSZEnable] = D3DRS_ZENABLE; - GFXD3D9RenderState[GFXRSFillMode] = D3DRS_FILLMODE; - GFXD3D9RenderState[GFXRSZWriteEnable] = D3DRS_ZWRITEENABLE; - GFXD3D9RenderState[GFXRSAlphaTestEnable] = D3DRS_ALPHATESTENABLE; - GFXD3D9RenderState[GFXRSSrcBlend] = D3DRS_SRCBLEND; - GFXD3D9RenderState[GFXRSDestBlend] = D3DRS_DESTBLEND; - GFXD3D9RenderState[GFXRSCullMode] = D3DRS_CULLMODE; - GFXD3D9RenderState[GFXRSZFunc] = D3DRS_ZFUNC; - GFXD3D9RenderState[GFXRSAlphaRef] = D3DRS_ALPHAREF; - GFXD3D9RenderState[GFXRSAlphaFunc] = D3DRS_ALPHAFUNC; - GFXD3D9RenderState[GFXRSAlphaBlendEnable] = D3DRS_ALPHABLENDENABLE; - GFXD3D9RenderState[GFXRSStencilEnable] = D3DRS_STENCILENABLE; - GFXD3D9RenderState[GFXRSStencilFail] = D3DRS_STENCILFAIL; - GFXD3D9RenderState[GFXRSStencilZFail] = D3DRS_STENCILZFAIL; - GFXD3D9RenderState[GFXRSStencilPass] = D3DRS_STENCILPASS; - GFXD3D9RenderState[GFXRSStencilFunc] = D3DRS_STENCILFUNC; - GFXD3D9RenderState[GFXRSStencilRef] = D3DRS_STENCILREF; - GFXD3D9RenderState[GFXRSStencilMask] = D3DRS_STENCILMASK; - GFXD3D9RenderState[GFXRSStencilWriteMask] = D3DRS_STENCILWRITEMASK; - GFXD3D9RenderState[GFXRSWrap0] = D3DRS_WRAP0; - GFXD3D9RenderState[GFXRSWrap1] = D3DRS_WRAP1; - GFXD3D9RenderState[GFXRSWrap2] = D3DRS_WRAP2; - GFXD3D9RenderState[GFXRSWrap3] = D3DRS_WRAP3; - GFXD3D9RenderState[GFXRSWrap4] = D3DRS_WRAP4; - GFXD3D9RenderState[GFXRSWrap5] = D3DRS_WRAP5; - GFXD3D9RenderState[GFXRSWrap6] = D3DRS_WRAP6; - GFXD3D9RenderState[GFXRSWrap7] = D3DRS_WRAP7; - GFXD3D9RenderState[GFXRSClipPlaneEnable] = D3DRS_CLIPPLANEENABLE; - GFXD3D9RenderState[GFXRSPointSize] = D3DRS_POINTSIZE; - GFXD3D9RenderState[GFXRSPointSizeMin] = D3DRS_POINTSIZE_MIN; - GFXD3D9RenderState[GFXRSPointSize_Max] = D3DRS_POINTSIZE_MAX; - GFXD3D9RenderState[GFXRSPointSpriteEnable] = D3DRS_POINTSPRITEENABLE; - GFXD3D9RenderState[GFXRSMultiSampleantiAlias] = D3DRS_MULTISAMPLEANTIALIAS; - GFXD3D9RenderState[GFXRSMultiSampleMask] = D3DRS_MULTISAMPLEMASK; - GFXD3D9RenderState[GFXRSShadeMode] = D3DRS_SHADEMODE; - GFXD3D9RenderState[GFXRSLastPixel] = D3DRS_LASTPIXEL; - GFXD3D9RenderState[GFXRSClipping] = D3DRS_CLIPPING; - GFXD3D9RenderState[GFXRSPointScaleEnable] = D3DRS_POINTSCALEENABLE; - GFXD3D9RenderState[GFXRSPointScale_A] = D3DRS_POINTSCALE_A; - GFXD3D9RenderState[GFXRSPointScale_B] = D3DRS_POINTSCALE_B; - GFXD3D9RenderState[GFXRSPointScale_C] = D3DRS_POINTSCALE_C; - GFXD3D9RenderState[GFXRSLighting] = D3DRS_LIGHTING; - GFXD3D9RenderState[GFXRSAmbient] = D3DRS_AMBIENT; - GFXD3D9RenderState[GFXRSFogVertexMode] = D3DRS_FOGVERTEXMODE; - GFXD3D9RenderState[GFXRSColorVertex] = D3DRS_COLORVERTEX; - GFXD3D9RenderState[GFXRSLocalViewer] = D3DRS_LOCALVIEWER; - GFXD3D9RenderState[GFXRSNormalizeNormals] = D3DRS_NORMALIZENORMALS; - GFXD3D9RenderState[GFXRSDiffuseMaterialSource] = D3DRS_DIFFUSEMATERIALSOURCE; - GFXD3D9RenderState[GFXRSSpecularMaterialSource] = D3DRS_SPECULARMATERIALSOURCE; - GFXD3D9RenderState[GFXRSAmbientMaterialSource] = D3DRS_AMBIENTMATERIALSOURCE; - GFXD3D9RenderState[GFXRSEmissiveMaterialSource] = D3DRS_EMISSIVEMATERIALSOURCE; - GFXD3D9RenderState[GFXRSVertexBlend] = D3DRS_VERTEXBLEND; - GFXD3D9RenderState[GFXRSFogEnable] = D3DRS_FOGENABLE; - GFXD3D9RenderState[GFXRSSpecularEnable] = D3DRS_SPECULARENABLE; - GFXD3D9RenderState[GFXRSFogColor] = D3DRS_FOGCOLOR; - GFXD3D9RenderState[GFXRSFogTableMode] = D3DRS_FOGTABLEMODE; - GFXD3D9RenderState[GFXRSFogStart] = D3DRS_FOGSTART; - GFXD3D9RenderState[GFXRSFogEnd] = D3DRS_FOGEND; - GFXD3D9RenderState[GFXRSFogDensity] = D3DRS_FOGDENSITY; - GFXD3D9RenderState[GFXRSRangeFogEnable] = D3DRS_RANGEFOGENABLE; - GFXD3D9RenderState[GFXRSDebugMonitorToken] = D3DRS_DEBUGMONITORTOKEN; - GFXD3D9RenderState[GFXRSIndexedVertexBlendEnable] = D3DRS_INDEXEDVERTEXBLENDENABLE; - GFXD3D9RenderState[GFXRSTweenFactor] = D3DRS_TWEENFACTOR; - GFXD3D9RenderState[GFXRSTextureFactor] = D3DRS_TEXTUREFACTOR; - GFXD3D9RenderState[GFXRSPatchEdgeStyle] = D3DRS_PATCHEDGESTYLE; - GFXD3D9RenderState[GFXRSPositionDegree] = D3DRS_POSITIONDEGREE; - GFXD3D9RenderState[GFXRSNormalDegree] = D3DRS_NORMALDEGREE; - GFXD3D9RenderState[GFXRSAntiAliasedLineEnable] = D3DRS_ANTIALIASEDLINEENABLE; - GFXD3D9RenderState[GFXRSAdaptiveTess_X] = D3DRS_ADAPTIVETESS_X; - GFXD3D9RenderState[GFXRSAdaptiveTess_Y] = D3DRS_ADAPTIVETESS_Y; - GFXD3D9RenderState[GFXRSdaptiveTess_Z] = D3DRS_ADAPTIVETESS_Z; - GFXD3D9RenderState[GFXRSAdaptiveTess_W] = D3DRS_ADAPTIVETESS_W; - GFXD3D9RenderState[GFXRSEnableAdaptiveTesselation] = D3DRS_ENABLEADAPTIVETESSELLATION; - GFXD3D9RenderState[GFXRSDitherEnable] = D3DRS_DITHERENABLE; - GFXD3D9RenderState[GFXRSColorWriteEnable] = D3DRS_COLORWRITEENABLE; - GFXD3D9RenderState[GFXRSBlendOp] = D3DRS_BLENDOP; - GFXD3D9RenderState[GFXRSScissorTestEnable] = D3DRS_SCISSORTESTENABLE; - GFXD3D9RenderState[GFXRSSlopeScaleDepthBias] = D3DRS_SLOPESCALEDEPTHBIAS; - GFXD3D9RenderState[GFXRSMinTessellationLevel] = D3DRS_MINTESSELLATIONLEVEL; - GFXD3D9RenderState[GFXRSMaxTessellationLevel] = D3DRS_MAXTESSELLATIONLEVEL; - GFXD3D9RenderState[GFXRSTwoSidedStencilMode] = D3DRS_TWOSIDEDSTENCILMODE; - GFXD3D9RenderState[GFXRSCCWStencilFail] = D3DRS_CCW_STENCILFAIL; - GFXD3D9RenderState[GFXRSCCWStencilZFail] = D3DRS_CCW_STENCILZFAIL; - GFXD3D9RenderState[GFXRSCCWStencilPass] = D3DRS_CCW_STENCILPASS; - GFXD3D9RenderState[GFXRSCCWStencilFunc] = D3DRS_CCW_STENCILFUNC; - GFXD3D9RenderState[GFXRSColorWriteEnable1] = D3DRS_COLORWRITEENABLE1; - GFXD3D9RenderState[GFXRSColorWriteEnable2] = D3DRS_COLORWRITEENABLE2; - GFXD3D9RenderState[GFXRSolorWriteEnable3] = D3DRS_COLORWRITEENABLE3; - GFXD3D9RenderState[GFXRSBlendFactor] = D3DRS_BLENDFACTOR; - GFXD3D9RenderState[GFXRSSRGBWriteEnable] = D3DRS_SRGBWRITEENABLE; - GFXD3D9RenderState[GFXRSDepthBias] = D3DRS_DEPTHBIAS; - GFXD3D9RenderState[GFXRSWrap8] = D3DRS_WRAP8; - GFXD3D9RenderState[GFXRSWrap9] = D3DRS_WRAP9; - GFXD3D9RenderState[GFXRSWrap10] = D3DRS_WRAP10; - GFXD3D9RenderState[GFXRSWrap11] = D3DRS_WRAP11; - GFXD3D9RenderState[GFXRSWrap12] = D3DRS_WRAP12; - GFXD3D9RenderState[GFXRSWrap13] = D3DRS_WRAP13; - GFXD3D9RenderState[GFXRSWrap14] = D3DRS_WRAP14; - GFXD3D9RenderState[GFXRSWrap15] = D3DRS_WRAP15; - GFXD3D9RenderState[GFXRSSeparateAlphaBlendEnable] = D3DRS_SEPARATEALPHABLENDENABLE; - GFXD3D9RenderState[GFXRSSrcBlendAlpha] = D3DRS_SRCBLENDALPHA; - GFXD3D9RenderState[GFXRSDestBlendAlpha] = D3DRS_DESTBLENDALPHA; - GFXD3D9RenderState[GFXRSBlendOpAlpha] = D3DRS_BLENDOPALPHA; - VALIDATE_LOOKUPTABLE( GFXD3D9RenderState, GFXRenderState ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9TextureFilter, GFXTextureFilter, _D3DTEXTUREFILTERTYPE ); - GFXD3D9TextureFilter[GFXTextureFilterNone] = D3DTEXF_NONE; - GFXD3D9TextureFilter[GFXTextureFilterPoint] = D3DTEXF_POINT; - GFXD3D9TextureFilter[GFXTextureFilterLinear] = D3DTEXF_LINEAR; - GFXD3D9TextureFilter[GFXTextureFilterAnisotropic] = D3DTEXF_ANISOTROPIC; - GFXD3D9TextureFilter[GFXTextureFilterPyramidalQuad] = D3DTEXF_PYRAMIDALQUAD; - GFXD3D9TextureFilter[GFXTextureFilterGaussianQuad] = D3DTEXF_GAUSSIANQUAD; - VALIDATE_LOOKUPTABLE( GFXD3D9TextureFilter, GFXTextureFilter ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9Blend, GFXBlend, _D3DBLEND ); - GFXD3D9Blend[GFXBlendZero] = D3DBLEND_ZERO; - GFXD3D9Blend[GFXBlendOne] = D3DBLEND_ONE; - GFXD3D9Blend[GFXBlendSrcColor] = D3DBLEND_SRCCOLOR; - GFXD3D9Blend[GFXBlendInvSrcColor] = D3DBLEND_INVSRCCOLOR; - GFXD3D9Blend[GFXBlendSrcAlpha] = D3DBLEND_SRCALPHA; - GFXD3D9Blend[GFXBlendInvSrcAlpha] = D3DBLEND_INVSRCALPHA; - GFXD3D9Blend[GFXBlendDestAlpha] = D3DBLEND_DESTALPHA; - GFXD3D9Blend[GFXBlendInvDestAlpha] = D3DBLEND_INVDESTALPHA; - GFXD3D9Blend[GFXBlendDestColor] = D3DBLEND_DESTCOLOR; - GFXD3D9Blend[GFXBlendInvDestColor] = D3DBLEND_INVDESTCOLOR; - GFXD3D9Blend[GFXBlendSrcAlphaSat] = D3DBLEND_SRCALPHASAT; - VALIDATE_LOOKUPTABLE( GFXD3D9Blend, GFXBlend ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9BlendOp, GFXBlendOp, _D3DBLENDOP ); - GFXD3D9BlendOp[GFXBlendOpAdd] = D3DBLENDOP_ADD; - GFXD3D9BlendOp[GFXBlendOpSubtract] = D3DBLENDOP_SUBTRACT; - GFXD3D9BlendOp[GFXBlendOpRevSubtract] = D3DBLENDOP_REVSUBTRACT; - GFXD3D9BlendOp[GFXBlendOpMin] = D3DBLENDOP_MIN; - GFXD3D9BlendOp[GFXBlendOpMax] = D3DBLENDOP_MAX; - VALIDATE_LOOKUPTABLE( GFXD3D9BlendOp, GFXBlendOp ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9StencilOp, GFXStencilOp, _D3DSTENCILOP ); - GFXD3D9StencilOp[GFXStencilOpKeep] = D3DSTENCILOP_KEEP; - GFXD3D9StencilOp[GFXStencilOpZero] = D3DSTENCILOP_ZERO; - GFXD3D9StencilOp[GFXStencilOpReplace] = D3DSTENCILOP_REPLACE; - GFXD3D9StencilOp[GFXStencilOpIncrSat] = D3DSTENCILOP_INCRSAT; - GFXD3D9StencilOp[GFXStencilOpDecrSat] = D3DSTENCILOP_DECRSAT; - GFXD3D9StencilOp[GFXStencilOpInvert] = D3DSTENCILOP_INVERT; - GFXD3D9StencilOp[GFXStencilOpIncr] = D3DSTENCILOP_INCR; - GFXD3D9StencilOp[GFXStencilOpDecr] = D3DSTENCILOP_DECR; - VALIDATE_LOOKUPTABLE( GFXD3D9StencilOp, GFXStencilOp ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9CmpFunc, GFXCmp, _D3DCMPFUNC ); - GFXD3D9CmpFunc[GFXCmpNever] = D3DCMP_NEVER; - GFXD3D9CmpFunc[GFXCmpLess] = D3DCMP_LESS; - GFXD3D9CmpFunc[GFXCmpEqual] = D3DCMP_EQUAL; - GFXD3D9CmpFunc[GFXCmpLessEqual] = D3DCMP_LESSEQUAL; - GFXD3D9CmpFunc[GFXCmpGreater] = D3DCMP_GREATER; - GFXD3D9CmpFunc[GFXCmpNotEqual] = D3DCMP_NOTEQUAL; - GFXD3D9CmpFunc[GFXCmpGreaterEqual] = D3DCMP_GREATEREQUAL; - GFXD3D9CmpFunc[GFXCmpAlways] = D3DCMP_ALWAYS; - VALIDATE_LOOKUPTABLE( GFXD3D9CmpFunc, GFXCmp ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9CullMode, GFXCull, _D3DCULL ); - GFXD3D9CullMode[GFXCullNone] = D3DCULL_NONE; - GFXD3D9CullMode[GFXCullCW] = D3DCULL_CW; - GFXD3D9CullMode[GFXCullCCW] = D3DCULL_CCW; - VALIDATE_LOOKUPTABLE( GFXD3D9CullMode, GFXCull ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9FillMode, GFXFill, _D3DFILLMODE ); - GFXD3D9FillMode[GFXFillPoint] = D3DFILL_POINT; - GFXD3D9FillMode[GFXFillWireframe] = D3DFILL_WIREFRAME; - GFXD3D9FillMode[GFXFillSolid] = D3DFILL_SOLID; - VALIDATE_LOOKUPTABLE( GFXD3D9FillMode, GFXFill ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9PrimType, GFXPT, _D3DPRIMITIVETYPE ); - GFXD3D9PrimType[GFXPointList] = D3DPT_POINTLIST; - GFXD3D9PrimType[GFXLineList] = D3DPT_LINELIST; - GFXD3D9PrimType[GFXLineStrip] = D3DPT_LINESTRIP; - GFXD3D9PrimType[GFXTriangleList] = D3DPT_TRIANGLELIST; - GFXD3D9PrimType[GFXTriangleStrip] = D3DPT_TRIANGLESTRIP; - VALIDATE_LOOKUPTABLE( GFXD3D9PrimType, GFXPT ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9TextureStageState, GFXTSS, _D3DTEXTURESTAGESTATETYPE ); - GFXD3D9TextureStageState[GFXTSSColorOp] = D3DTSS_COLOROP; - GFXD3D9TextureStageState[GFXTSSColorArg1] = D3DTSS_COLORARG1; - GFXD3D9TextureStageState[GFXTSSColorArg2] = D3DTSS_COLORARG2; - GFXD3D9TextureStageState[GFXTSSAlphaOp] = D3DTSS_ALPHAOP; - GFXD3D9TextureStageState[GFXTSSAlphaArg1] = D3DTSS_ALPHAARG1; - GFXD3D9TextureStageState[GFXTSSAlphaArg2] = D3DTSS_ALPHAARG2; - GFXD3D9TextureStageState[GFXTSSBumpEnvMat00] = D3DTSS_BUMPENVMAT00; - GFXD3D9TextureStageState[GFXTSSBumpEnvMat01] = D3DTSS_BUMPENVMAT01; - GFXD3D9TextureStageState[GFXTSSBumpEnvMat10] = D3DTSS_BUMPENVMAT10; - GFXD3D9TextureStageState[GFXTSSBumpEnvMat11] = D3DTSS_BUMPENVMAT11; - GFXD3D9TextureStageState[GFXTSSTexCoordIndex] = D3DTSS_TEXCOORDINDEX; - GFXD3D9TextureStageState[GFXTSSBumpEnvlScale] = D3DTSS_BUMPENVLSCALE; - GFXD3D9TextureStageState[GFXTSSBumpEnvlOffset] = D3DTSS_BUMPENVLOFFSET; - GFXD3D9TextureStageState[GFXTSSTextureTransformFlags] = D3DTSS_TEXTURETRANSFORMFLAGS; - GFXD3D9TextureStageState[GFXTSSColorArg0] = D3DTSS_COLORARG0; - GFXD3D9TextureStageState[GFXTSSAlphaArg0] = D3DTSS_ALPHAARG0; - GFXD3D9TextureStageState[GFXTSSResultArg] = D3DTSS_RESULTARG; - GFXD3D9TextureStageState[GFXTSSConstant] = D3DTSS_CONSTANT; - VALIDATE_LOOKUPTABLE( GFXD3D9TextureStageState, GFXTSS ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9TextureAddress, GFXAddress, _D3DTEXTUREADDRESS ); - GFXD3D9TextureAddress[GFXAddressWrap] = D3DTADDRESS_WRAP ; - GFXD3D9TextureAddress[GFXAddressMirror] = D3DTADDRESS_MIRROR; - GFXD3D9TextureAddress[GFXAddressClamp] = D3DTADDRESS_CLAMP; - GFXD3D9TextureAddress[GFXAddressBorder] = D3DTADDRESS_BORDER; - GFXD3D9TextureAddress[GFXAddressMirrorOnce] = D3DTADDRESS_MIRRORONCE; - VALIDATE_LOOKUPTABLE(GFXD3D9TextureAddress, GFXAddress ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9TextureOp, GFXTOP, _D3DTEXTUREOP ); - GFXD3D9TextureOp[GFXTOPDisable] = D3DTOP_DISABLE; - GFXD3D9TextureOp[GFXTOPSelectARG1] = D3DTOP_SELECTARG1; - GFXD3D9TextureOp[GFXTOPSelectARG2] = D3DTOP_SELECTARG2; - GFXD3D9TextureOp[GFXTOPModulate] = D3DTOP_MODULATE; - GFXD3D9TextureOp[GFXTOPModulate2X] = D3DTOP_MODULATE2X; - GFXD3D9TextureOp[GFXTOPModulate4X] = D3DTOP_MODULATE4X; - GFXD3D9TextureOp[GFXTOPAdd] = D3DTOP_ADD; - GFXD3D9TextureOp[GFXTOPAddSigned] = D3DTOP_ADDSIGNED; - GFXD3D9TextureOp[GFXTOPAddSigned2X] = D3DTOP_ADDSIGNED2X; - GFXD3D9TextureOp[GFXTOPSubtract] = D3DTOP_SUBTRACT; - GFXD3D9TextureOp[GFXTOPAddSmooth] = D3DTOP_ADDSMOOTH; - GFXD3D9TextureOp[GFXTOPBlendDiffuseAlpha] = D3DTOP_BLENDDIFFUSEALPHA; - GFXD3D9TextureOp[GFXTOPBlendTextureAlpha] = D3DTOP_BLENDTEXTUREALPHA; - GFXD3D9TextureOp[GFXTOPBlendFactorAlpha] = D3DTOP_BLENDFACTORALPHA; - GFXD3D9TextureOp[GFXTOPBlendTextureAlphaPM] = D3DTOP_BLENDTEXTUREALPHAPM; - GFXD3D9TextureOp[GFXTOPBlendCURRENTALPHA] = D3DTOP_BLENDCURRENTALPHA; - GFXD3D9TextureOp[GFXTOPPreModulate] = D3DTOP_PREMODULATE; - GFXD3D9TextureOp[GFXTOPModulateAlphaAddColor] = D3DTOP_MODULATEALPHA_ADDCOLOR; - GFXD3D9TextureOp[GFXTOPModulateColorAddAlpha] = D3DTOP_MODULATECOLOR_ADDALPHA; - GFXD3D9TextureOp[GFXTOPModulateInvAlphaAddColor] = D3DTOP_MODULATEINVALPHA_ADDCOLOR; - GFXD3D9TextureOp[GFXTOPModulateInvColorAddAlpha] = D3DTOP_MODULATEINVCOLOR_ADDALPHA; - GFXD3D9TextureOp[GFXTOPBumpEnvMap] = D3DTOP_BUMPENVMAP; - GFXD3D9TextureOp[GFXTOPBumpEnvMapLuminance] = D3DTOP_BUMPENVMAPLUMINANCE; - GFXD3D9TextureOp[GFXTOPDotProduct3] = D3DTOP_DOTPRODUCT3; - GFXD3D9TextureOp[GFXTOPLERP] = D3DTOP_LERP; - VALIDATE_LOOKUPTABLE( GFXD3D9TextureOp, GFXTOP ); -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - INIT_LOOKUPTABLE( GFXD3D9DeclType, GFXDeclType, _D3DDECLTYPE ); - GFXD3D9DeclType[GFXDeclType_Float] = D3DDECLTYPE_FLOAT1; - GFXD3D9DeclType[GFXDeclType_Float2] = D3DDECLTYPE_FLOAT2; - GFXD3D9DeclType[GFXDeclType_Float3] = D3DDECLTYPE_FLOAT3; - GFXD3D9DeclType[GFXDeclType_Float4] = D3DDECLTYPE_FLOAT4; - GFXD3D9DeclType[GFXDeclType_Color] = D3DDECLTYPE_D3DCOLOR; - GFXD3D9DeclType[GFXDeclType_UByte4] = D3DDECLTYPE_UBYTE4; - VALIDATE_LOOKUPTABLE( GFXD3D9DeclType, GFXDeclType ); -} - diff --git a/Engine/source/gfx/D3D9/pc/gfxD3D9PrimitiveBuffer.pc.cpp b/Engine/source/gfx/D3D9/pc/gfxD3D9PrimitiveBuffer.pc.cpp deleted file mode 100644 index c550d046a..000000000 --- a/Engine/source/gfx/D3D9/pc/gfxD3D9PrimitiveBuffer.pc.cpp +++ /dev/null @@ -1,96 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/gfxD3D9Device.h" -#include "gfx/D3D9/gfxD3D9PrimitiveBuffer.h" -#include "core/util/safeRelease.h" - -void GFXD3D9PrimitiveBuffer::lock(U32 indexStart, U32 indexEnd, void **indexPtr) -{ - AssertFatal(!mLocked, "GFXD3D9PrimitiveBuffer::lock - Can't lock a primitive buffer more than once!"); - - mLocked = true; - U32 flags=0; - switch(mBufferType) - { - case GFXBufferTypeImmutable: - case GFXBufferTypeStatic: - // flags |= D3DLOCK_DISCARD; - break; - - case GFXBufferTypeDynamic: - // Always discard the content within a locked region. - flags |= D3DLOCK_DISCARD; - break; - - case GFXBufferTypeVolatile: - // Get our range now... - AssertFatal(indexStart == 0, "Cannot get a subrange on a volatile buffer."); - AssertFatal(indexEnd < MAX_DYNAMIC_INDICES, "Cannot get more than MAX_DYNAMIC_INDICES in a volatile buffer. Up the constant!"); - - // Get the primtive buffer - mVolatileBuffer = ((GFXD3D9Device*)mDevice)->mDynamicPB; - - AssertFatal( mVolatileBuffer, "GFXD3D9PrimitiveBuffer::lock - No dynamic primitive buffer was available!"); - - // We created the pool when we requested this volatile buffer, so assume it exists... - if( mVolatileBuffer->mIndexCount + indexEnd > MAX_DYNAMIC_INDICES ) - { - flags |= D3DLOCK_DISCARD; - mVolatileStart = indexStart = 0; - indexEnd = indexEnd; - } - else - { - flags |= D3DLOCK_NOOVERWRITE; - mVolatileStart = indexStart = mVolatileBuffer->mIndexCount; - indexEnd += mVolatileBuffer->mIndexCount; - } - - mVolatileBuffer->mIndexCount = indexEnd + 1; - ib = mVolatileBuffer->ib; - - break; - } - - D3D9Assert( ib->Lock(indexStart * sizeof(U16), (indexEnd - indexStart) * sizeof(U16), indexPtr, flags), - "GFXD3D9PrimitiveBuffer::lock - Could not lock primitive buffer."); - - #ifdef TORQUE_DEBUG - - // Allocate a debug buffer large enough for the lock - // plus space for over and under run guard strings. - mLockedSize = (indexEnd - indexStart) * sizeof(U16); - const U32 guardSize = sizeof( _PBGuardString ); - mDebugGuardBuffer = new U8[mLockedSize+(guardSize*2)]; - - // Setup the guard strings. - dMemcpy( mDebugGuardBuffer, _PBGuardString, guardSize ); - dMemcpy( mDebugGuardBuffer + mLockedSize + guardSize, _PBGuardString, guardSize ); - - // Store the real lock pointer and return our debug pointer. - mLockedBuffer = *indexPtr; - *indexPtr = (U16*)( mDebugGuardBuffer + guardSize ); - - #endif // TORQUE_DEBUG -} - diff --git a/Engine/source/gfx/D3D9/pc/gfxPCD3D9Device.cpp b/Engine/source/gfx/D3D9/pc/gfxPCD3D9Device.cpp deleted file mode 100644 index d113bf70b..000000000 --- a/Engine/source/gfx/D3D9/pc/gfxPCD3D9Device.cpp +++ /dev/null @@ -1,1173 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "gfx/D3D9/pc/gfxPCD3D9Device.h" -#include "gfx/D3D9/pc/gfxPCD3D9Target.h" -#include "gfx/D3D9/gfxD3D9CardProfiler.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" -#include "platformWin32/platformWin32.h" -#include "windowManager/win32/win32Window.h" -#include "gfx/screenshot.h" -#include "gfx/D3D9/screenshotD3D9.h" -#include "gfx/D3D9/videoCaptureD3D9.h" -#include "core/util/journal/process.h" - - -bool GFXPCD3D9Device::mEnableNVPerfHUD = false; - -GFXAdapter::CreateDeviceInstanceDelegate GFXPCD3D9Device::mCreateDeviceInstance(GFXPCD3D9Device::createInstance); - -GFXPCD3D9Device::~GFXPCD3D9Device() -{ - if( mVideoFrameGrabber ) - { - if( ManagedSingleton< VideoCapture >::instanceOrNull() ) - VIDCAP->setFrameGrabber( NULL ); - delete mVideoFrameGrabber; - } -} - -void GFXPCD3D9Device::createDirect3D9(LPDIRECT3D9 &d3d9, LPDIRECT3D9EX &d3d9ex) -{ - d3d9 = NULL; - d3d9ex = NULL; - - if ( !Con::getBoolVariable( "$pref::Video::preferDirect3D9Ex", false ) ) - { - d3d9 = Direct3DCreate9(D3D_SDK_VERSION); - return; - } - - HMODULE hD3D = LoadLibrary(TEXT("d3d9.dll")); - - if (hD3D) - { - - HRESULT (WINAPI *pfnCreate9Ex)(UINT SDKVersion, IDirect3D9Ex**) = (HRESULT ( WINAPI *)(UINT SDKVersion, IDirect3D9Ex**)) GetProcAddress(hD3D, "Direct3DCreate9Ex"); - - if (pfnCreate9Ex) - { - if (d3d9ex && !FAILED(pfnCreate9Ex(D3D_SDK_VERSION, &d3d9ex))) - d3d9ex->QueryInterface(__uuidof(IDirect3D9), reinterpret_cast(&d3d9)); - } - - if (!pfnCreate9Ex || !d3d9) - { - if (d3d9ex) - { - SAFE_RELEASE(d3d9ex) - d3d9ex = NULL; - } - - d3d9 = Direct3DCreate9(D3D_SDK_VERSION); - } - - FreeLibrary(hD3D); - } -} - -GFXDevice *GFXPCD3D9Device::createInstance( U32 adapterIndex ) -{ - LPDIRECT3D9 d3d9; - LPDIRECT3D9EX d3d9ex; - - createDirect3D9(d3d9, d3d9ex); - - GFXPCD3D9Device* dev = new GFXPCD3D9Device( d3d9, adapterIndex ); - dev->mD3DEx = d3d9ex; - return dev; -} - -//----------------------------------------------------------------------------- - -GFXFormat GFXPCD3D9Device::selectSupportedFormat(GFXTextureProfile *profile, - const Vector &formats, bool texture, bool mustblend, bool mustfilter) -{ - DWORD usage = 0; - - if(profile->isDynamic()) - usage |= D3DUSAGE_DYNAMIC; - - if(profile->isRenderTarget()) - usage |= D3DUSAGE_RENDERTARGET; - - if(profile->isZTarget()) - usage |= D3DUSAGE_DEPTHSTENCIL; - - if(mustblend) - usage |= D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING; - - if(mustfilter) - usage |= D3DUSAGE_QUERY_FILTER; - - D3DDISPLAYMODE mode; - D3D9Assert(mD3D->GetAdapterDisplayMode(mAdapterIndex, &mode), "Unable to get adapter mode."); - - D3DRESOURCETYPE type; - if(texture) - type = D3DRTYPE_TEXTURE; - else - type = D3DRTYPE_SURFACE; - - for(U32 i=0; iCheckDeviceFormat(mAdapterIndex, D3DDEVTYPE_HAL, mode.Format, - usage, type, GFXD3D9TextureFormat[formats[i]]) == D3D_OK) - return formats[i]; - } - - return GFXFormatR8G8B8A8; -} - -HRESULT GFXPCD3D9Device::createDevice(U32 adapter, D3DDEVTYPE deviceType, HWND hFocusWindow, DWORD behaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters) -{ - HRESULT hres = E_FAIL; - - if (mD3DEx) - { - hres = mD3DEx->CreateDeviceEx( adapter, deviceType, - hFocusWindow, - behaviorFlags, - pPresentationParameters, NULL, &mD3DDeviceEx ); - - if (!FAILED(hres) && mD3DDeviceEx) - hres = mD3DDeviceEx->QueryInterface(__uuidof(IDirect3DDevice9), reinterpret_cast(&mD3DDevice)); - } - else - { - hres = mD3D->CreateDevice( adapter, deviceType, - hFocusWindow, - behaviorFlags, - pPresentationParameters, &mD3DDevice ); - } - - return hres; - -} - -//----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -// Setup D3D present parameters - init helper function -//----------------------------------------------------------------------------- -D3DPRESENT_PARAMETERS GFXPCD3D9Device::setupPresentParams( const GFXVideoMode &mode, const HWND &hwnd ) const -{ - // Create D3D Presentation params - D3DPRESENT_PARAMETERS d3dpp; - dMemset( &d3dpp, 0, sizeof( d3dpp ) ); - - D3DFORMAT fmt = D3DFMT_X8R8G8B8; // 32 bit - - if( mode.bitDepth == 16 ) - fmt = D3DFMT_R5G6B5; - - D3DMULTISAMPLE_TYPE aatype; - DWORD aalevel; - - // Setup the AA flags... If we've been ask to - // disable hardware AA then do that now. - if ( mode.antialiasLevel == 0 || Con::getBoolVariable( "$pref::Video::disableHardwareAA", false ) ) - { - aatype = D3DMULTISAMPLE_NONE; - aalevel = 0; - } - else - { - aatype = D3DMULTISAMPLE_NONMASKABLE; - aalevel = mode.antialiasLevel-1; - } - - _validateMultisampleParams(fmt, aatype, aalevel); - - d3dpp.BackBufferWidth = mode.resolution.x; - d3dpp.BackBufferHeight = mode.resolution.y; - d3dpp.BackBufferFormat = fmt; - d3dpp.BackBufferCount = 1; - d3dpp.MultiSampleType = aatype; - d3dpp.MultiSampleQuality = aalevel; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.hDeviceWindow = hwnd; - d3dpp.Windowed = !mode.fullScreen; - d3dpp.EnableAutoDepthStencil = TRUE; - d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; - d3dpp.Flags = 0; - d3dpp.FullScreen_RefreshRateInHz = (mode.refreshRate == 0 || !mode.fullScreen) ? - D3DPRESENT_RATE_DEFAULT : mode.refreshRate; - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - - if ( smDisableVSync ) - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // This does NOT wait for vsync - - return d3dpp; -} - -//----------------------------------------------------------------------------- -// Enumerate D3D adapters -//----------------------------------------------------------------------------- -void GFXPCD3D9Device::enumerateAdapters( Vector &adapterList ) -{ - // Grab a D3D9 handle here to first get the D3D9 devices - LPDIRECT3D9 d3d9; - LPDIRECT3D9EX d3d9ex; - createDirect3D9( d3d9, d3d9ex); - - // If we could not create the d3d9 object then either the system - // is corrupt or they need to update the directx runtime. - if ( !d3d9 ) - { - Con::errorf( "Unsupported DirectX version!" ); - Platform::messageBox( Con::getVariable( "$appName" ), - "DirectX could not be started!\r\n" - "Please be sure you have the latest version of DirectX installed.", - MBOk, MIStop ); - Platform::forceShutdown( -1 ); - } - - for( U32 adapterIndex = 0; adapterIndex < d3d9->GetAdapterCount(); adapterIndex++ ) - { - GFXAdapter *toAdd = new GFXAdapter; - toAdd->mType = Direct3D9; - toAdd->mIndex = adapterIndex; - toAdd->mCreateDeviceInstanceDelegate = mCreateDeviceInstance; - - // Grab the shader model. - D3DCAPS9 caps; - d3d9->GetDeviceCaps(adapterIndex, D3DDEVTYPE_HAL, &caps); - U8 *pxPtr = (U8*) &caps.PixelShaderVersion; - toAdd->mShaderModel = pxPtr[1] + pxPtr[0] * 0.1; - - // Get the device description string. - D3DADAPTER_IDENTIFIER9 temp; - d3d9->GetAdapterIdentifier( adapterIndex, NULL, &temp ); // The NULL is the flags which deal with WHQL - - dStrncpy(toAdd->mName, temp.Description, GFXAdapter::MaxAdapterNameLen); - dStrncat(toAdd->mName, " (D3D9)", GFXAdapter::MaxAdapterNameLen); - - // And the output display device name - dStrncpy(toAdd->mOutputName, temp.DeviceName, GFXAdapter::MaxAdapterNameLen); - - // Video mode enumeration. - Vector formats( __FILE__, __LINE__ ); - formats.push_back( D3DFMT_R5G6B5 ); // D3DFMT_R5G6B5 - 16bit format - formats.push_back( D3DFMT_X8R8G8B8 ); // D3DFMT_X8R8G8B8 - 32bit format - - for( S32 i = 0; i < formats.size(); i++ ) - { - DWORD MaxSampleQualities; - d3d9->CheckDeviceMultiSampleType(adapterIndex, D3DDEVTYPE_HAL, formats[i], FALSE, D3DMULTISAMPLE_NONMASKABLE, &MaxSampleQualities); - - for( U32 j = 0; j < d3d9->GetAdapterModeCount( adapterIndex, formats[i] ); j++ ) - { - D3DDISPLAYMODE mode; - d3d9->EnumAdapterModes( adapterIndex, formats[i], j, &mode ); - - GFXVideoMode vmAdd; - - vmAdd.bitDepth = ( i == 0 ? 16 : 32 ); // This will need to be changed later - vmAdd.fullScreen = true; - vmAdd.refreshRate = mode.RefreshRate; - vmAdd.resolution = Point2I( mode.Width, mode.Height ); - vmAdd.antialiasLevel = MaxSampleQualities; - - toAdd->mAvailableModes.push_back( vmAdd ); - } - } - - adapterList.push_back( toAdd ); - } - - d3d9->Release(); -} - -void GFXPCD3D9Device::enumerateVideoModes() -{ - Vector formats( __FILE__, __LINE__ ); - formats.push_back( D3DFMT_R5G6B5 ); // D3DFMT_R5G6B5 - 16bit format - formats.push_back( D3DFMT_X8R8G8B8 ); // D3DFMT_X8R8G8B8 - 32bit format - - for( S32 i = 0; i < formats.size(); i++ ) - { - for( U32 j = 0; j < mD3D->GetAdapterModeCount( mAdapterIndex, formats[i] ); j++ ) - { - D3DDISPLAYMODE mode; - mD3D->EnumAdapterModes( mAdapterIndex, formats[i], j, &mode ); - - GFXVideoMode toAdd; - - toAdd.bitDepth = ( i == 0 ? 16 : 32 ); // This will need to be changed later - toAdd.fullScreen = false; - toAdd.refreshRate = mode.RefreshRate; - toAdd.resolution = Point2I( mode.Width, mode.Height ); - - mVideoModes.push_back( toAdd ); - } - } -} - -//----------------------------------------------------------------------------- -// Initialize - create window, device, etc -//----------------------------------------------------------------------------- -void GFXPCD3D9Device::init( const GFXVideoMode &mode, PlatformWindow *window /* = NULL */ ) -{ - AssertFatal(window, "GFXPCD3D9Device::init - must specify a window!"); - - initD3DXFnTable(); - - HWND winHwnd = (HWND)window->getSystemWindow( PlatformWindow::WindowSystem_Windows ); - AssertISV(winHwnd, "GFXPCD3D9WindowTarget::initPresentationParams() - no HWND"); - - // Create D3D Presentation params - D3DPRESENT_PARAMETERS d3dpp = setupPresentParams( mode, winHwnd ); - mMultisampleType = d3dpp.MultiSampleType; - mMultisampleLevel = d3dpp.MultiSampleQuality; - -#ifndef TORQUE_SHIPPING - bool usePerfHud = GFXPCD3D9Device::mEnableNVPerfHUD || Con::getBoolVariable("$Video::useNVPerfHud", false); -#else - bool usePerfHud = false; -#endif - - HRESULT hres = E_FAIL; - if ( usePerfHud ) - { - hres = createDevice( mD3D->GetAdapterCount() - 1, D3DDEVTYPE_REF, winHwnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp); - } - else - { - // Vertex processing was changed from MIXED to HARDWARE because of the switch to a pure D3D device. - - // Set up device flags from our compile flags. - U32 deviceFlags = 0; - deviceFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; - - // Currently, offscreen rendering is only used by WPF apps and we need to create with D3DCREATE_MULTITHREAD for it - // In all other cases, you can do better by locking/creating resources in the primary thread - // and passing them to worker threads. - if (window->getOffscreenRender()) - { - deviceFlags |= D3DCREATE_MULTITHREADED; - d3dpp.Windowed = TRUE; - d3dpp.BackBufferHeight = 1; - d3dpp.BackBufferWidth = 1; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - } - - // DirectX will switch the floating poing control word to single precision - // and disable exceptions by default. There are a few issues with this... - // - // 1. It can cause rendering problems when running in WPF. - // 2. Firefox embedding issues. - // 3. Physics engines depend on the higher precision. - // - // Interestingly enough... DirectX 10 and 11 do not modifiy the floating point - // settings and are always in full precision. - // - // The down side is we supposedly loose some performance, but so far i've not - // seen a measurable impact. - // - deviceFlags |= D3DCREATE_FPU_PRESERVE; - - // Try to do pure, unless we're doing debug (and thus doing more paranoid checking). -#ifndef TORQUE_DEBUG_RENDER - deviceFlags |= D3DCREATE_PUREDEVICE; -#endif - - hres = createDevice( mAdapterIndex, D3DDEVTYPE_HAL, winHwnd, deviceFlags, &d3dpp); - - if (FAILED(hres) && hres != D3DERR_OUTOFVIDEOMEMORY) - { - Con::errorf(" Failed to create hardware device, trying mixed device"); - // turn off pure - deviceFlags &= (~D3DCREATE_PUREDEVICE); - - // try mixed mode - deviceFlags &= (~D3DCREATE_HARDWARE_VERTEXPROCESSING); - deviceFlags |= D3DCREATE_MIXED_VERTEXPROCESSING; - hres = createDevice( mAdapterIndex, D3DDEVTYPE_HAL, - winHwnd, deviceFlags, - &d3dpp); - - // try software - if (FAILED(hres) && hres != D3DERR_OUTOFVIDEOMEMORY) - { - Con::errorf(" Failed to create mixed mode device, trying software device"); - deviceFlags &= (~D3DCREATE_MIXED_VERTEXPROCESSING); - deviceFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; - hres = createDevice( mAdapterIndex, D3DDEVTYPE_HAL, - winHwnd, deviceFlags, - &d3dpp); - - if (FAILED(hres) && hres != D3DERR_OUTOFVIDEOMEMORY) - Con::errorf(" Failed to create software device, giving up"); - D3D9Assert(hres, "GFXPCD3D9Device::init - CreateDevice failed!"); - } - } - } - - // Gracefully die if they can't give us a device. - if(!mD3DDevice) - { - if (hres == D3DERR_OUTOFVIDEOMEMORY) - { - char errorMsg[4096]; - dSprintf(errorMsg, sizeof(errorMsg), - "Out of video memory. Close other windows, reboot, and/or upgrade your video card drivers. Your video card is: %s", getAdapter().getName()); - Platform::AlertOK("DirectX Error", errorMsg); - } - else - { - Platform::AlertOK("DirectX Error!", "Failed to initialize Direct3D! Make sure you have DirectX 9 installed, and " - "are running a graphics card that supports Pixel Shader 1.1."); - } - Platform::forceShutdown(1); - } - - // Check up on things - Con::printf(" Cur. D3DDevice ref count=%d", mD3DDevice->AddRef() - 1); - mD3DDevice->Release(); - - mTextureManager = new GFXD3D9TextureManager( mD3DDevice, mAdapterIndex ); - - // Now reacquire all the resources we trashed earlier - reacquireDefaultPoolResources(); - - // Setup default states - initStates(); - - //-------- Output init info --------- - D3DCAPS9 caps; - mD3DDevice->GetDeviceCaps( &caps ); - - U8 *pxPtr = (U8*) &caps.PixelShaderVersion; - mPixVersion = pxPtr[1] + pxPtr[0] * 0.1; - if (mPixVersion >= 2.0f && mPixVersion < 3.0f && caps.PS20Caps.NumTemps >= 32) - mPixVersion += 0.2f; - else if (mPixVersion >= 2.0f && mPixVersion < 3.0f && caps.PS20Caps.NumTemps >= 22) - mPixVersion += 0.1f; - Con::printf( " Pix version detected: %f", mPixVersion ); - - if ( smForcedPixVersion >= 0.0f && smForcedPixVersion < mPixVersion ) - { - mPixVersion = smForcedPixVersion; - Con::errorf( " Forced pix version: %f", mPixVersion ); - } - - U8 *vertPtr = (U8*) &caps.VertexShaderVersion; - F32 vertVersion = vertPtr[1] + vertPtr[0] * 0.1; - Con::printf( " Vert version detected: %f", vertVersion ); - - // The sampler count is based on the shader model and - // not found in the caps. - // - // MaxSimultaneousTextures is only valid for fixed - // function rendering. - // - if ( mPixVersion >= 2.0f ) - mNumSamplers = 16; - else if ( mPixVersion >= 1.4f ) - mNumSamplers = 6; - else if ( mPixVersion > 0.0f ) - mNumSamplers = 4; - else - mNumSamplers = caps.MaxSimultaneousTextures; - - // This shouldn't happen until SM5 or some other - // radical change in GPU hardware occurs. - AssertFatal( mNumSamplers <= TEXTURE_STAGE_COUNT, - "GFXPCD3D9Device::init - Sampler count greater than TEXTURE_STAGE_COUNT!" ); - - Con::printf( " Maximum number of simultaneous samplers: %d", mNumSamplers ); - - // detect max number of simultaneous render targets - mNumRenderTargets = caps.NumSimultaneousRTs; - Con::printf( " Number of simultaneous render targets: %d", mNumRenderTargets ); - - // detect occlusion query support - if (SUCCEEDED(mD3DDevice->CreateQuery( D3DQUERYTYPE_OCCLUSION, NULL ))) - mOcclusionQuerySupported = true; - - Con::printf( " Hardware occlusion query detected: %s", mOcclusionQuerySupported ? "Yes" : "No" ); - - Con::printf( " Using Direct3D9Ex: %s", isD3D9Ex() ? "Yes" : "No" ); - - mCardProfiler = new GFXD3D9CardProfiler(mAdapterIndex); - mCardProfiler->init(); - - gScreenShot = new ScreenShotD3D9; - - // Set the video capture frame grabber. - mVideoFrameGrabber = new VideoFrameGrabberD3D9(); - VIDCAP->setFrameGrabber( mVideoFrameGrabber ); - - // Grab the depth-stencil... - SAFE_RELEASE(mDeviceDepthStencil); - D3D9Assert(mD3DDevice->GetDepthStencilSurface(&mDeviceDepthStencil), "GFXD3D9Device::init - couldn't grab reference to device's depth-stencil surface."); - - mInitialized = true; - - deviceInited(); - - // Uncomment to dump out code needed in initStates, you may also need to enable the reference device (get rid of code in initStates first as well) - // regenStates(); -} - -//------------------------------------------------------------------------------ -void GFXPCD3D9Device::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 GFXPCD3D9Device::leaveDebugEvent() -{ - D3DPERF_EndEvent(); -} - -//------------------------------------------------------------------------------ -void GFXPCD3D9Device::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); -} - -//----------------------------------------------------------------------------- - -void GFXPCD3D9Device::setMatrix( GFXMatrixType mtype, const MatrixF &mat ) -{ - mat.transposeTo( mTempMatrix ); - - mD3DDevice->SetTransform( (_D3DTRANSFORMSTATETYPE)mtype, (D3DMATRIX *)&mTempMatrix ); -} - -//----------------------------------------------------------------------------- - -void GFXPCD3D9Device::_setTextureStageState( U32 stage, U32 state, U32 value ) -{ - switch( state ) - { - case GFXTSSColorOp: - case GFXTSSAlphaOp: - mD3DDevice->SetTextureStageState( stage, GFXD3D9TextureStageState[state], GFXD3D9TextureOp[value] ); - break; - - default: - mD3DDevice->SetTextureStageState( stage, GFXD3D9TextureStageState[state], value ); - break; - } -} - -//------------------------------------------------------------------------------ - -void GFXPCD3D9Device::initStates() -{ - //------------------------------------- - // Auto-generated default states, see regenStates() for details - // - - // Render states - mD3DDevice->SetRenderState( GFXD3D9RenderState[0], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[1], 3 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[2], 2 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[3], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[4], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[5], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[6], 2 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[7], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[8], 3 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[9], 4 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[10], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[11], 8 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[12], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[13], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[14], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[15], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[16], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[17], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[18], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[19], 1065353216 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[20], 1065353216 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[21], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[22], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[23], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[24], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[25], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[26], 8 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[27], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[28], -1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[29], -1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[30], -1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[31], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[32], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[33], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[34], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[35], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[36], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[37], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[38], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[39], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[40], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[41], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[42], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[43], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[44], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[45], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[46], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[47], 2 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[48], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[49], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[50], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[51], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[52], 1065353216 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[53], 1065353216 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[54], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[55], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[56], 1065353216 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[57], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[58], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[59], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[60], -1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[61], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[62], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[63], 1115684864 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[64], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[65], 15 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[66], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[67], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[68], 3 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[69], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[70], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[71], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[72], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[73], 1065353216 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[74], 1065353216 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[75], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[76], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[77], 1065353216 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[78], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[79], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[80], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[81], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[82], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[83], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[84], 8 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[85], 15 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[86], 15 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[87], 15 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[88], -1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[89], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[90], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[91], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[92], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[93], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[94], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[95], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[96], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[97], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[98], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[99], 0 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[100], 2 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[101], 1 ); - mD3DDevice->SetRenderState( GFXD3D9RenderState[102], 1 ); - - // Texture Stage states - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[0], 4 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[1], 2 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[2], 1 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[3], 2 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[4], 2 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[5], 1 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[6], 0 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[7], 0 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[8], 0 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[9], 0 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[10], 0 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[11], 0 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[12], 0 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[13], 0 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[14], 1 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[15], 1 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[16], 1 ); - mD3DDevice->SetTextureStageState( 0, GFXD3D9TextureStageState[17], 0 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[0], 1 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[1], 2 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[2], 1 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[3], 1 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[4], 2 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[5], 1 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[6], 0 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[7], 0 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[8], 0 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[9], 0 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[10], 1 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[11], 0 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[12], 0 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[13], 0 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[14], 1 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[15], 1 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[16], 1 ); - mD3DDevice->SetTextureStageState( 1, GFXD3D9TextureStageState[17], 0 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[0], 1 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[1], 2 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[2], 1 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[3], 1 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[4], 2 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[5], 1 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[6], 0 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[7], 0 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[8], 0 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[9], 0 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[10], 2 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[11], 0 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[12], 0 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[13], 0 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[14], 1 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[15], 1 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[16], 1 ); - mD3DDevice->SetTextureStageState( 2, GFXD3D9TextureStageState[17], 0 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[0], 1 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[1], 2 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[2], 1 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[3], 1 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[4], 2 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[5], 1 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[6], 0 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[7], 0 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[8], 0 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[9], 0 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[10], 3 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[11], 0 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[12], 0 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[13], 0 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[14], 1 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[15], 1 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[16], 1 ); - mD3DDevice->SetTextureStageState( 3, GFXD3D9TextureStageState[17], 0 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[0], 1 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[1], 2 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[2], 1 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[3], 1 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[4], 2 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[5], 1 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[6], 0 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[7], 0 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[8], 0 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[9], 0 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[10], 4 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[11], 0 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[12], 0 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[13], 0 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[14], 1 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[15], 1 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[16], 1 ); - mD3DDevice->SetTextureStageState( 4, GFXD3D9TextureStageState[17], 0 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[0], 1 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[1], 2 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[2], 1 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[3], 1 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[4], 2 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[5], 1 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[6], 0 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[7], 0 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[8], 0 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[9], 0 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[10], 5 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[11], 0 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[12], 0 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[13], 0 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[14], 1 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[15], 1 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[16], 1 ); - mD3DDevice->SetTextureStageState( 5, GFXD3D9TextureStageState[17], 0 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[0], 1 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[1], 2 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[2], 1 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[3], 1 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[4], 2 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[5], 1 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[6], 0 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[7], 0 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[8], 0 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[9], 0 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[10], 6 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[11], 0 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[12], 0 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[13], 0 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[14], 1 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[15], 1 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[16], 1 ); - mD3DDevice->SetTextureStageState( 6, GFXD3D9TextureStageState[17], 0 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[0], 1 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[1], 2 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[2], 1 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[3], 1 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[4], 2 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[5], 1 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[6], 0 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[7], 0 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[8], 0 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[9], 0 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[10], 7 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[11], 0 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[12], 0 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[13], 0 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[14], 1 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[15], 1 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[16], 1 ); - mD3DDevice->SetTextureStageState( 7, GFXD3D9TextureStageState[17], 0 ); - - // Sampler states - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[0], 1 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[1], 1 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[2], 1 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[3], 0 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[4], 1 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[5], 1 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[6], 0 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[7], 0 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[8], 0 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[9], 1 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[10], 0 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[11], 0 ); - mD3DDevice->SetSamplerState( 0, GFXD3D9SamplerState[12], 0 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[0], 1 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[1], 1 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[2], 1 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[3], 0 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[4], 1 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[5], 1 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[6], 0 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[7], 0 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[8], 0 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[9], 1 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[10], 0 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[11], 0 ); - mD3DDevice->SetSamplerState( 1, GFXD3D9SamplerState[12], 0 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[0], 1 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[1], 1 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[2], 1 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[3], 0 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[4], 1 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[5], 1 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[6], 0 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[7], 0 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[8], 0 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[9], 1 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[10], 0 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[11], 0 ); - mD3DDevice->SetSamplerState( 2, GFXD3D9SamplerState[12], 0 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[0], 1 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[1], 1 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[2], 1 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[3], 0 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[4], 1 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[5], 1 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[6], 0 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[7], 0 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[8], 0 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[9], 1 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[10], 0 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[11], 0 ); - mD3DDevice->SetSamplerState( 3, GFXD3D9SamplerState[12], 0 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[0], 1 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[1], 1 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[2], 1 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[3], 0 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[4], 1 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[5], 1 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[6], 0 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[7], 0 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[8], 0 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[9], 1 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[10], 0 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[11], 0 ); - mD3DDevice->SetSamplerState( 4, GFXD3D9SamplerState[12], 0 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[0], 1 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[1], 1 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[2], 1 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[3], 0 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[4], 1 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[5], 1 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[6], 0 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[7], 0 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[8], 0 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[9], 1 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[10], 0 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[11], 0 ); - mD3DDevice->SetSamplerState( 5, GFXD3D9SamplerState[12], 0 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[0], 1 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[1], 1 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[2], 1 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[3], 0 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[4], 1 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[5], 1 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[6], 0 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[7], 0 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[8], 0 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[9], 1 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[10], 0 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[11], 0 ); - mD3DDevice->SetSamplerState( 6, GFXD3D9SamplerState[12], 0 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[0], 1 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[1], 1 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[2], 1 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[3], 0 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[4], 1 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[5], 1 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[6], 0 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[7], 0 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[8], 0 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[9], 1 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[10], 0 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[11], 0 ); - mD3DDevice->SetSamplerState( 7, GFXD3D9SamplerState[12], 0 ); -} - -void GFXPCD3D9Device::_validateMultisampleParams(D3DFORMAT format, D3DMULTISAMPLE_TYPE & aatype, DWORD & aalevel) const -{ - if (aatype != D3DMULTISAMPLE_NONE) - { - DWORD MaxSampleQualities; - mD3D->CheckDeviceMultiSampleType(mAdapterIndex, D3DDEVTYPE_HAL, format, FALSE, D3DMULTISAMPLE_NONMASKABLE, &MaxSampleQualities); - aatype = D3DMULTISAMPLE_NONMASKABLE; - aalevel = getMin((U32)aalevel, (U32)MaxSampleQualities-1); - } -} - -bool GFXPCD3D9Device::beginSceneInternal() -{ - // Make sure we have a device - HRESULT res = mD3DDevice->TestCooperativeLevel(); - - S32 attempts = 0; - const S32 MaxAttempts = 40; - const S32 SleepMsPerAttempt = 50; - while(res == D3DERR_DEVICELOST && attempts < MaxAttempts) - { - // Lost device! Just keep querying - res = mD3DDevice->TestCooperativeLevel(); - - Con::warnf("GFXPCD3D9Device::beginScene - Device needs to be reset, waiting on device..."); - - Sleep(SleepMsPerAttempt); - attempts++; - } - - if (attempts >= MaxAttempts && res == D3DERR_DEVICELOST) - { - Con::errorf("GFXPCD3D9Device::beginScene - Device lost and reset wait time exceeded, skipping reset (will retry later)"); - mCanCurrentlyRender = false; - return false; - } - - // Trigger a reset if we can't get a good result from TestCooperativeLevel. - if(res == D3DERR_DEVICENOTRESET) - { - Con::warnf("GFXPCD3D9Device::beginScene - Device needs to be reset, resetting device..."); - - // Reset the device! - GFXResource *walk = mResourceListHead; - while(walk) - { - // Find the window target with implicit flag set and reset the device with its presentation params. - if(GFXPCD3D9WindowTarget *gdwt = dynamic_cast(walk)) - { - if(gdwt->mImplicit) - { - reset(gdwt->mPresentationParams); - break; - } - } - - walk = walk->getNextResource(); - } - } - - // Call parent - return Parent::beginSceneInternal(); -} - -GFXWindowTarget * GFXPCD3D9Device::allocWindowTarget( PlatformWindow *window ) -{ - AssertFatal(window,"GFXD3D9Device::allocWindowTarget - no window provided!"); - - // Set up a new window target... - GFXPCD3D9WindowTarget *gdwt = new GFXPCD3D9WindowTarget(); - gdwt->mWindow = window; - gdwt->mSize = window->getClientExtent(); - gdwt->mDevice = this; - gdwt->initPresentationParams(); - - // Now, we have to init & bind our device... we have basically two scenarios - // of which the first is: - if(mD3DDevice == NULL) - { - // Allocate the device. - init(window->getVideoMode(), window); - - // Cool, we have the device, grab back the depthstencil buffer as well - // as the swap chain. - gdwt->mImplicit = true; - gdwt->setImplicitSwapChain(); - } - else - { - // And the second case: - // Initialized device, create an additional swap chain. - gdwt->mImplicit = false; - gdwt->createAdditionalSwapChain(); - } - - gdwt->registerResourceWithDevice(this); - - return gdwt; -} - -GFXTextureTarget * GFXPCD3D9Device::allocRenderToTextureTarget() -{ - GFXPCD3D9TextureTarget *targ = new GFXPCD3D9TextureTarget(); - targ->mDevice = this; - - targ->registerResourceWithDevice(this); - - return targ; -} - -//----------------------------------------------------------------------------- -// Reset D3D device -//----------------------------------------------------------------------------- -void GFXPCD3D9Device::reset( D3DPRESENT_PARAMETERS &d3dpp ) -{ - if(!mD3DDevice) - return; - - mInitialized = false; - - mMultisampleType = d3dpp.MultiSampleType; - mMultisampleLevel = d3dpp.MultiSampleQuality; - _validateMultisampleParams(d3dpp.BackBufferFormat, mMultisampleType, mMultisampleLevel); - - // 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. - setVertexBuffer(NULL); - setPrimitiveBuffer(NULL); - for(S32 i=0; iAddRef()-1); - mDeviceDepthStencil->Release(); - } - - // First release all the stuff we allocated from D3DPOOL_DEFAULT - releaseDefaultPoolResources(); - - // reset device - Con::printf( "--- Resetting D3D Device ---" ); - HRESULT hres = S_OK; - hres = mD3DDevice->Reset( &d3dpp ); - - if( FAILED( hres ) ) - { - while( mD3DDevice->TestCooperativeLevel() == D3DERR_DEVICELOST ) - { - Sleep( 100 ); - } - - hres = mD3DDevice->Reset( &d3dpp ); - } - - D3D9Assert( hres, "GFXD3D9Device::reset - Failed to create D3D Device!" ); - mInitialized = true; - - // Setup default states - initStates(); - - // Now re aquire all the resources we trashed earlier - reacquireDefaultPoolResources(); - - // Mark everything dirty and flush to card, for sanity. - updateStates(true); -} - -// -// Register this device with GFXInit -// -class GFXPCD3D9RegisterDevice -{ -public: - GFXPCD3D9RegisterDevice() - { - GFXInit::getRegisterDeviceSignal().notify(&GFXPCD3D9Device::enumerateAdapters); - } -}; - -static GFXPCD3D9RegisterDevice pPCD3D9RegisterDevice; - -//----------------------------------------------------------------------------- -/// Parse command line arguments for window creation -//----------------------------------------------------------------------------- -static void sgPCD3D9DeviceHandleCommandLine( S32 argc, const char **argv ) -{ - for (U32 i = 1; i < argc; i++) - { - String s(argv[i]); - if (s.equal("-nvperfhud", String::NoCase)) - { - GFXPCD3D9Device::mEnableNVPerfHUD = true; - break; - } - } -} - -// Register the command line parsing hook -static ProcessRegisterCommandLine sgCommandLine( sgPCD3D9DeviceHandleCommandLine ); - -extern "C" HRESULT WINAPI D3D_GetBackBufferNoRef(IDirect3DSurface9 **ppSurface) -{ - HRESULT hr = S_OK; - - GFXD3D9Device *dev = static_cast(GFX); - - if (!dev) - { - *ppSurface = NULL; - return S_OK; - } - - *ppSurface = dev->getBackBuffer(); - - return hr; -} \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/pc/gfxPCD3D9Device.h b/Engine/source/gfx/D3D9/pc/gfxPCD3D9Device.h deleted file mode 100644 index e8270298f..000000000 --- a/Engine/source/gfx/D3D9/pc/gfxPCD3D9Device.h +++ /dev/null @@ -1,81 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFX_PC_D3D9DEVICE_H_ -#define _GFX_PC_D3D9DEVICE_H_ - -#include "gfx/D3D9/gfxD3D9Device.h" - -class PlatformWindow; -class VideoFrameGrabberD3D9; - - -class GFXPCD3D9Device : public GFXD3D9Device -{ - typedef GFXD3D9Device Parent; - -public: - // Set to true to force nvperfhud device creation - static bool mEnableNVPerfHUD; - - GFXPCD3D9Device( LPDIRECT3D9 d3d, U32 index ) - : GFXD3D9Device( d3d, index ), - mVideoFrameGrabber( NULL ) {}; - ~GFXPCD3D9Device(); - - static GFXDevice *createInstance( U32 adapterIndex ); - - virtual GFXFormat selectSupportedFormat(GFXTextureProfile *profile, - const Vector &formats, bool texture, bool mustblend, bool mustfilter); - - static void enumerateAdapters( Vector &adapterList ); - - virtual void enumerateVideoModes(); - - virtual GFXWindowTarget *allocWindowTarget(PlatformWindow *window); - virtual GFXTextureTarget *allocRenderToTextureTarget(); - virtual bool beginSceneInternal(); - - virtual void init( const GFXVideoMode &mode, PlatformWindow *window = NULL ); - - virtual void enterDebugEvent(ColorI color, const char *name); - virtual void leaveDebugEvent(); - virtual void setDebugMarker(ColorI color, const char *name); - - virtual void setMatrix( GFXMatrixType mtype, const MatrixF &mat ); - - virtual void initStates(); - virtual void reset( D3DPRESENT_PARAMETERS &d3dpp ); - virtual D3DPRESENT_PARAMETERS setupPresentParams( const GFXVideoMode &mode, const HWND &hwnd ) const; -protected: - - VideoFrameGrabberD3D9* mVideoFrameGrabber; - - static GFXAdapter::CreateDeviceInstanceDelegate mCreateDeviceInstance; - static void createDirect3D9(LPDIRECT3D9 &d3d9, LPDIRECT3D9EX &d3d9ex); - HRESULT createDevice(U32 adapter, D3DDEVTYPE deviceType, HWND hFocusWindow, DWORD behaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters); - - virtual void _setTextureStageState( U32 stage, U32 state, U32 value ); - void _validateMultisampleParams(D3DFORMAT format, D3DMULTISAMPLE_TYPE & aatype, DWORD & aalevel) const; -}; - -#endif \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.cpp b/Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.cpp deleted file mode 100644 index 415801263..000000000 --- a/Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.cpp +++ /dev/null @@ -1,590 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "platform/platform.h" -#include "gfx/D3D9/pc/gfxPCD3D9Target.h" - -#include "gfx/D3D9/gfxD3D9Device.h" -#include "gfx/D3D9/gfxD3D9TextureObject.h" -#include "gfx/D3D9/gfxD3D9Cubemap.h" -#include "gfx/D3D9/gfxD3D9EnumTranslate.h" -#include "gfx/D3D9/pc/gfxPCD3D9Device.h" -#include "gfx/gfxDebugEvent.h" -#include "windowManager/win32/win32Window.h" - -#ifndef _GFXDEVICE_H_ -#include "gfx/gfxDevice.h" -#endif - -GFXPCD3D9TextureTarget::GFXPCD3D9TextureTarget() - : mTargetSize( Point2I::Zero ), - mTargetFormat( GFXFormatR8G8B8A8 ) -{ - for(S32 i=0; idestroyD3DResource( mTargets[i] ); // SAFE_RELEASE - mTargets[i] = NULL; - } - else - SAFE_RELEASE( mTargets[i] ); - } - - zombify(); -} - -void GFXPCD3D9TextureTarget::attachTexture( RenderSlot slot, GFXTextureObject *tex, U32 mipLevel/*=0*/, U32 zOffset /*= 0*/ ) -{ - GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_attachTexture, ColorI::RED ); - - AssertFatal(slot < MaxRenderSlotId, "GFXPCD3D9TextureTarget::attachTexture - out of range slot."); - - // TODO: The way this is implemented... you can attach a texture - // object multiple times and it will release and reset it. - // - // We should rework this to detect when no change has occured - // and skip out early. - - // Mark state as dirty so device can know to update. - invalidateState(); - - // Release what we had, it's definitely going to change. - mDevice->destroyD3DResource( mTargets[slot] ); // SAFE_RELEASE - mTargets[slot] = NULL; - mResolveTargets[slot] = NULL; - - if(slot == Color0) - { - mTargetSize = Point2I::Zero; - mTargetFormat = GFXFormatR8G8B8A8; - } - - // Are we clearing? - if(!tex) - { - // Yup - just exit, it'll stay NULL. - return; - } - - - // Take care of default targets - if( tex == GFXTextureTarget::sDefaultDepthStencil ) - { - mTargets[slot] = mDevice->mDeviceDepthStencil; - mTargets[slot]->AddRef(); - } - else - { - // Cast the texture object to D3D... - AssertFatal(dynamic_cast(tex), - "GFXPCD3D9TextureTarget::attachTexture - invalid texture object."); - - GFXD3D9TextureObject *d3dto = static_cast(tex); - - // Grab the surface level. - if( slot == DepthStencil ) - { - mTargets[slot] = d3dto->getSurface(); - if ( mTargets[slot] ) - mTargets[slot]->AddRef(); - } - else - { - // getSurface will almost always return NULL. It will only return non-NULL - // if the surface that it needs to render to is different than the mip level - // in the actual texture. This will happen with MSAA. - if( d3dto->getSurface() == NULL ) - { - D3D9Assert(d3dto->get2DTex()->GetSurfaceLevel(mipLevel, &mTargets[slot]), - "GFXPCD3D9TextureTarget::attachTexture - could not get surface level for the passed texture!"); - } - else - { - mTargets[slot] = d3dto->getSurface(); - mTargets[slot]->AddRef(); - - // Only assign resolve target if d3dto has a surface to give us. - // - // That usually means there is an MSAA target involved, which is why - // the resolve is needed to get the data out of the target. - mResolveTargets[slot] = d3dto; - - if ( tex && slot == Color0 ) - { - mTargetSize.set( tex->getSize().x, tex->getSize().y ); - mTargetFormat = tex->getFormat(); - } - } - } - - // Update surface size - if(slot == Color0) - { - IDirect3DSurface9 *surface = mTargets[Color0]; - if ( surface ) - { - D3DSURFACE_DESC sd; - surface->GetDesc(&sd); - mTargetSize = Point2I(sd.Width, sd.Height); - - S32 format = sd.Format; - GFXREVERSE_LOOKUP( GFXD3D9TextureFormat, GFXFormat, format ); - mTargetFormat = (GFXFormat)format; - } - } - } -} - -void GFXPCD3D9TextureTarget::attachTexture( RenderSlot slot, GFXCubemap *tex, U32 face, U32 mipLevel/*=0*/ ) -{ - GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_attachTexture_Cubemap, ColorI::RED ); - - AssertFatal(slot < MaxRenderSlotId, "GFXPCD3D9TextureTarget::attachTexture - out of range slot."); - - // Mark state as dirty so device can know to update. - invalidateState(); - - // Release what we had, it's definitely going to change. - mDevice->destroyD3DResource( mTargets[slot] ); // SAFE_RELEASE - mTargets[slot] = NULL; - mResolveTargets[slot] = NULL; - - // Cast the texture object to D3D... - AssertFatal(!tex || dynamic_cast(tex), - "GFXD3DTextureTarget::attachTexture - invalid cubemap object."); - - GFXD3D9Cubemap *cube = static_cast(tex); - - if(slot == Color0) - { - mTargetSize = Point2I::Zero; - mTargetFormat = GFXFormatR8G8B8A8; - } - - // Are we clearing? - if(!tex) - { - // Yup - just exit, it'll stay NULL. - return; - } - - D3D9Assert(cube->mCubeTex->GetCubeMapSurface( (D3DCUBEMAP_FACES)face, mipLevel, &mTargets[slot] ), - "GFXD3DTextureTarget::attachTexture - could not get surface level for the passed texture!"); - - // Update surface size - if(slot == Color0) - { - IDirect3DSurface9 *surface = mTargets[Color0]; - if ( surface ) - { - D3DSURFACE_DESC sd; - surface->GetDesc(&sd); - mTargetSize = Point2I(sd.Width, sd.Height); - - S32 format = sd.Format; - GFXREVERSE_LOOKUP( GFXD3D9TextureFormat, GFXFormat, format ); - mTargetFormat = (GFXFormat)format; - } - } -} - -void GFXPCD3D9TextureTarget::activate() -{ - GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_activate, ColorI::RED ); - - AssertFatal( mTargets[GFXTextureTarget::Color0], - "GFXPCD3D9TextureTarget::activate() - You can never have a NULL primary render target!" ); - - const U32 NumRenderTargets = getMin( mDevice->getNumRenderTargets(), (U32)Color4 - Color0 ); - - LPDIRECT3DDEVICE9 d3dDevice = mDevice->getDevice(); - - // Clear the state indicator. - stateApplied(); - - IDirect3DSurface9 *depth = mTargets[GFXTextureTarget::DepthStencil]; - - // In debug lets do a complete test to be sure we don't - // have a bad depth format for this display mode. - #ifdef TORQUE_DEBUG - - if ( depth && mTargets[GFXTextureTarget::Color0] ) - { - D3DSURFACE_DESC desc; - D3D9Assert( mTargets[GFXTextureTarget::Color0]->GetDesc( &desc ), - "GFXPCD3D9TextureTarget::activate() - Failed to get surface description!"); - D3DFORMAT renderFormat = desc.Format; - - D3D9Assert( depth->GetDesc( &desc ), - "GFXPCD3D9TextureTarget::activate() - Failed to get surface description!"); - D3DFORMAT depthFormat = desc.Format; - - HRESULT hr = mDevice->getD3D()->CheckDepthStencilMatch( mDevice->getAdaterIndex(), - D3DDEVTYPE_HAL, - mDevice->mDisplayMode.Format, - renderFormat, - depthFormat ); - - D3D9Assert( hr, "GFXPCD3D9TextureTarget::activate() - Bad depth format for this target!" ); - } - - #endif - - // First clear the non-primary targets to make the debug DX runtime happy. - for(U32 i = 1; i < NumRenderTargets; i++) - D3D9Assert(d3dDevice->SetRenderTarget( i, NULL ), - avar("GFXPCD3D9TextureTarget::activate() - failed to clear texture target %d!", i) ); - - // Now set all the new surfaces into the appropriate slots. - for(U32 i = 0; i < NumRenderTargets; i++) - { - IDirect3DSurface9 *target = mTargets[GFXTextureTarget::Color0 + i]; - if ( target ) - { - D3D9Assert(d3dDevice->SetRenderTarget(i, target), - avar("GFXPCD3D9TextureTarget::activate() - failed to set slot %d for texture target!", i) ); - } - } - - // TODO: This is often the same shared depth buffer used by most - // render targets. Are we getting performance hit from setting it - // multiple times... aside from the function call? - - D3D9Assert(d3dDevice->SetDepthStencilSurface( depth ), - "GFXPCD3D9TextureTarget::activate() - failed to set depthstencil target!" ); -} - -void GFXPCD3D9TextureTarget::deactivate() -{ - // Nothing to do... the next activate() call will - // set all the targets correctly. -} - -void GFXPCD3D9TextureTarget::resolve() -{ - GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_resolve, ColorI::RED ); - - for (U32 i = 0; i < MaxRenderSlotId; i++) - { - // We use existance @ mResolveTargets as a flag that we need to copy - // data from the rendertarget into the texture. - if (mResolveTargets[i]) - { - IDirect3DSurface9 *surf; - D3D9Assert( mResolveTargets[i]->get2DTex()->GetSurfaceLevel( 0, &surf ), - "GFXPCD3D9TextureTarget::resolve() - GetSurfaceLevel failed!" ); - - D3D9Assert( mDevice->getDevice()->StretchRect( mTargets[i], NULL, surf, NULL, D3DTEXF_NONE ), - "GFXPCD3D9TextureTarget::resolve() - StretchRect failed!" ); - - surf->Release(); - } - } -} - -void GFXPCD3D9TextureTarget::resolveTo( GFXTextureObject *tex ) -{ - GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_resolveTo, ColorI::RED ); - - if ( mTargets[Color0] == NULL ) - return; - - IDirect3DSurface9 *surf; - D3D9Assert( ((GFXD3D9TextureObject*)(tex))->get2DTex()->GetSurfaceLevel( 0, &surf ), - "GFXPCD3D9TextureTarget::resolveTo() - GetSurfaceLevel failed!" ); - - D3D9Assert( mDevice->getDevice()->StretchRect( mTargets[Color0], NULL, surf, NULL, D3DTEXF_NONE ), - "GFXPCD3D9TextureTarget::resolveTo() - StretchRect failed!" ); - - surf->Release(); -} - -void GFXPCD3D9TextureTarget::zombify() -{ - for(S32 i = 0; i < MaxRenderSlotId; i++) - attachTexture(RenderSlot(i), NULL); -} - -void GFXPCD3D9TextureTarget::resurrect() -{ - -} - -//------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ - - -GFXPCD3D9WindowTarget::GFXPCD3D9WindowTarget() -{ - mSwapChain = NULL; - mDepthStencil = NULL; - mWindow = NULL; - mDevice = NULL; - mBackbuffer = NULL; - mImplicit = true; -} - -GFXPCD3D9WindowTarget::~GFXPCD3D9WindowTarget() -{ - SAFE_RELEASE(mSwapChain); - SAFE_RELEASE(mDepthStencil); - SAFE_RELEASE(mBackbuffer); -} - -void GFXPCD3D9WindowTarget::initPresentationParams() -{ - // Get some video mode related info. - GFXVideoMode vm = mWindow->getVideoMode(); - - // Do some validation... - if(vm.fullScreen == true && mImplicit == false) - { - AssertISV(false, - "GFXPCD3D9WindowTarget::initPresentationParams - Cannot go fullscreen with secondary window!"); - } - - HWND hwnd = (HWND)mWindow->getSystemWindow( PlatformWindow::WindowSystem_Windows ); - AssertISV(hwnd, "GFXPCD3D9WindowTarget::initPresentationParams() - no HWND"); - - // At some point, this will become GFXPCD3D9WindowTarget like trunk has, - // so this cast isn't as bad as it looks. ;) BTR - GFXPCD3D9Device* pcdevice = dynamic_cast(mDevice); - mPresentationParams = pcdevice->setupPresentParams(vm, hwnd); - - if (mImplicit) - { - pcdevice->mMultisampleType = mPresentationParams.MultiSampleType; - pcdevice->mMultisampleLevel = mPresentationParams.MultiSampleQuality; - } -} - -const Point2I GFXPCD3D9WindowTarget::getSize() -{ - return mWindow->getVideoMode().resolution; -} - -GFXFormat GFXPCD3D9WindowTarget::getFormat() -{ - S32 format = mPresentationParams.BackBufferFormat; - GFXREVERSE_LOOKUP( GFXD3D9TextureFormat, GFXFormat, format ); - return (GFXFormat)format; -} - -bool GFXPCD3D9WindowTarget::present() -{ - AssertFatal(mSwapChain, "GFXPCD3D9WindowTarget::present - no swap chain present to present!"); - HRESULT res = mSwapChain->Present(NULL, NULL, NULL, NULL, NULL); - - return (res == S_OK); -} - -void GFXPCD3D9WindowTarget::setImplicitSwapChain() -{ - AssertFatal(mImplicit, "Invalid swap chain type! Additional swap chains are created as needed"); - // Reacquire our swapchain & DS - if(!mSwapChain) - mDevice->getDevice()->GetSwapChain(0, &mSwapChain); - if(!mDepthStencil) - mDevice->getDevice()->GetDepthStencilSurface(&mDepthStencil); - if (!mBackbuffer) - mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mBackbuffer); -} - -void GFXPCD3D9WindowTarget::createAdditionalSwapChain() -{ - AssertFatal(!mImplicit, "Invalid swap chain type! Implicit swap chains use the device"); - - // Since we're not going to do a device reset for an additional swap - // chain, we can just release our resources and regrab them. - SAFE_RELEASE(mSwapChain); - SAFE_RELEASE(mDepthStencil); - SAFE_RELEASE(mBackbuffer); - - // If there's a fullscreen window active, don't try to create these additional swap chains. - // CodeReview, we need to store the window target with the implicit swap chain better, this line below - // could fail if the current render target isn't what we expect. - GFXPCD3D9WindowTarget* currTarget = dynamic_cast(mDevice->getActiveRenderTarget()); - if (currTarget && currTarget->getWindow()->getVideoMode().fullScreen) - return; - - // Setup our presentation params. - initPresentationParams(); - - // Create our resources! - D3D9Assert(mDevice->getDevice()->CreateAdditionalSwapChain(&mPresentationParams, &mSwapChain), - "GFXPCD3D9WindowTarget::createAdditionalSwapChain - couldn't reallocate additional swap chain!"); - D3D9Assert(mDevice->getDevice()->CreateDepthStencilSurface(mPresentationParams.BackBufferWidth, mPresentationParams.BackBufferHeight, - D3DFMT_D24S8, mPresentationParams.MultiSampleType, mPresentationParams.MultiSampleQuality, false, &mDepthStencil, NULL), - "GFXPCD3D9WindowTarget::createAdditionalSwapChain: Unable to create stencil/depth surface"); - D3D9Assert(mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mBackbuffer), - "GFXPCD3D9WindowTarget::createAdditionalSwapChain: Unable to get backbuffer!"); -} - -void GFXPCD3D9WindowTarget::resetMode() -{ - GFX->beginReset(); - mWindow->setSuppressReset(true); - - if (mSwapChain) - { - // The current video settings. - D3DPRESENT_PARAMETERS pp; - mSwapChain->GetPresentParameters(&pp); - bool ppFullscreen = !pp.Windowed; - Point2I backbufferSize(pp.BackBufferWidth, pp.BackBufferHeight); - - // The settings we are now applying. - const GFXVideoMode &mode = mWindow->getVideoMode(); - - // Convert the current multisample parameters into something - // we can compare with our GFXVideoMode.antialiasLevel value. - U32 ppAntiAliaseLevel = 0; - if ( pp.MultiSampleType != D3DMULTISAMPLE_NONE ) - ppAntiAliaseLevel = pp.MultiSampleQuality + 1; - - // Early out if none of the settings which require a device reset - // have changed. - if ( backbufferSize == getSize() && - ppFullscreen == mode.fullScreen && - ppAntiAliaseLevel == mode.antialiasLevel ) - return; - } - - // So, the video mode has changed - if we're an additional swap chain - // just kill the swapchain and reallocate to match new vid mode. - if(mImplicit == false) - { - createAdditionalSwapChain(); - } - else - { - // Setup our presentation params. - initPresentationParams(); - - // Otherwise, we have to reset the device, if we're the implicit swapchain. - mDevice->reset(mPresentationParams); - } - - // Update our size, too. - mSize = Point2I(mPresentationParams.BackBufferWidth, mPresentationParams.BackBufferHeight); - - mWindow->setSuppressReset(false); -} - -void GFXPCD3D9WindowTarget::zombify() -{ - // Release our resources - SAFE_RELEASE(mSwapChain); - SAFE_RELEASE(mDepthStencil); - SAFE_RELEASE(mBackbuffer); -} - -void GFXPCD3D9WindowTarget::resurrect() -{ - GFX->beginReset(); - if(mImplicit) - { - setImplicitSwapChain(); - } - else if(!mSwapChain) - { - createAdditionalSwapChain(); - } -} - -void GFXPCD3D9WindowTarget::activate() -{ - GFXDEBUGEVENT_SCOPE( GFXPCD3D9WindowTarget_activate, ColorI::RED ); - - LPDIRECT3DDEVICE9 d3dDevice = mDevice->getDevice(); - - // In debug lets do a complete test to be sure we don't - // have a bad depth format for this display mode. - #ifdef TORQUE_DEBUG - if ( mDepthStencil && mBackbuffer ) - { - - D3DSURFACE_DESC desc; - D3D9Assert( mBackbuffer->GetDesc( &desc ), - "GFXPCD3D9TextureTarget::activate() - Failed to get surface description!"); - D3DFORMAT renderFormat = desc.Format; - - D3D9Assert( mDepthStencil->GetDesc( &desc ), - "GFXPCD3D9TextureTarget::activate() - Failed to get surface description!"); - D3DFORMAT depthFormat = desc.Format; - - HRESULT hr = mDevice->getD3D()->CheckDepthStencilMatch( mDevice->getAdaterIndex(), - D3DDEVTYPE_HAL, - mDevice->mDisplayMode.Format, - renderFormat, - depthFormat ); - - D3D9Assert( hr, "GFXPCD3D9WindowTarget::activate() - Bad depth format for this back buffer!" ); - } - #endif - - D3D9Assert( d3dDevice->SetRenderTarget( 0, mBackbuffer ), - "GFXPCD3D9WindowTarget::activate() - Failed to set backbuffer target!" ); - - D3D9Assert( d3dDevice->SetDepthStencilSurface( mDepthStencil ), - "GFXPCD3D9WindowTarget::activate() - Failed to set depthstencil target!" ); - - D3DPRESENT_PARAMETERS pp; - - mSwapChain->GetPresentParameters(&pp); - - // Update our video mode here, too. - GFXVideoMode vm; - vm = mWindow->getVideoMode(); - vm.resolution.x = pp.BackBufferWidth; - vm.resolution.y = pp.BackBufferHeight; - vm.fullScreen = !pp.Windowed; - - mSize = vm.resolution; -} - -void GFXPCD3D9WindowTarget::resolveTo( GFXTextureObject *tex ) -{ - GFXDEBUGEVENT_SCOPE( GFXPCD3D9WindowTarget_resolveTo, ColorI::RED ); - - IDirect3DSurface9 *surf; - D3D9Assert( ((GFXD3D9TextureObject*)(tex))->get2DTex()->GetSurfaceLevel( 0, &surf ), - "GFXPCD3D9WindowTarget::resolveTo() - GetSurfaceLevel failed!" ); - - D3D9Assert( mDevice->getDevice()->StretchRect( mBackbuffer, NULL, surf, NULL, D3DTEXF_NONE ), - "GFXPCD3D9WindowTarget::resolveTo() - StretchRect failed!" ); - - surf->Release(); -} \ No newline at end of file diff --git a/Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.h b/Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.h deleted file mode 100644 index b766ec8ff..000000000 --- a/Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.h +++ /dev/null @@ -1,130 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- -#ifndef _GFX_D3D_GFXD3D9TARGET_H_ -#define _GFX_D3D_GFXD3D9TARGET_H_ - -#ifndef _GFXTARGET_H_ -#include "gfx/gfxTarget.h" -#endif -#ifndef _MPOINT3_H_ -#include "math/mPoint3.h" -#endif -#ifndef _MPOINT2_H_ -#include "math/mPoint2.h" -#endif -#include - -struct IDirect3DSurface9; -struct IDirect3DSwapChain9; -class GFXD3D9TextureObject; - - -class GFXPCD3D9TextureTarget : public GFXTextureTarget -{ - friend class GFXPCD3D9Device; - - // Array of target surfaces, this is given to us by attachTexture - IDirect3DSurface9 * mTargets[MaxRenderSlotId]; - - // Array of texture objects which correspond to the target surfaces above, - // needed for copy from RenderTarget to texture situations. Current only valid in those situations - GFXD3D9TextureObject* mResolveTargets[MaxRenderSlotId]; - - /// Owning d3d device. - GFXD3D9Device *mDevice; - - Point2I mTargetSize; - - GFXFormat mTargetFormat; - -public: - - GFXPCD3D9TextureTarget(); - ~GFXPCD3D9TextureTarget(); - - // Public interface. - virtual const Point2I getSize() { return mTargetSize; } - virtual GFXFormat getFormat() { return mTargetFormat; } - virtual void attachTexture(RenderSlot slot, GFXTextureObject *tex, U32 mipLevel=0, U32 zOffset = 0); - virtual void attachTexture(RenderSlot slot, GFXCubemap *tex, U32 face, U32 mipLevel=0); - virtual void resolve(); - - /// Note we always copy the Color0 RenderSlot. - virtual void resolveTo( GFXTextureObject *tex ); - - virtual void activate(); - virtual void deactivate(); - - void zombify(); - void resurrect(); -}; - -class GFXPCD3D9WindowTarget : public GFXWindowTarget -{ - friend class GFXPCD3D9Device; - - /// Our depth stencil buffer, if any. - IDirect3DSurface9 *mDepthStencil; - - /// Our backbuffer - IDirect3DSurface9 *mBackbuffer; - - /// Maximum size we can render to. - Point2I mSize; - - /// Our swap chain, potentially the implicit device swap chain. - IDirect3DSwapChain9 *mSwapChain; - - /// D3D presentation info. - D3DPRESENT_PARAMETERS mPresentationParams; - - /// Owning d3d device. - GFXD3D9Device *mDevice; - - /// Is this the implicit swap chain? - bool mImplicit; - - /// Internal interface that notifies us we need to reset our video mode. - void resetMode(); - -public: - - GFXPCD3D9WindowTarget(); - ~GFXPCD3D9WindowTarget(); - - virtual const Point2I getSize(); - virtual GFXFormat getFormat(); - virtual bool present(); - - void initPresentationParams(); - void setImplicitSwapChain(); - void createAdditionalSwapChain(); - - virtual void activate(); - - void zombify(); - void resurrect(); - - virtual void resolveTo( GFXTextureObject *tex ); -}; - -#endif // _GFX_D3D_GFXD3D9TARGET_H_ diff --git a/Engine/source/gfx/D3D9/screenshotD3D9.cpp b/Engine/source/gfx/D3D9/screenshotD3D9.cpp deleted file mode 100644 index c7d3ff3cb..000000000 --- a/Engine/source/gfx/D3D9/screenshotD3D9.cpp +++ /dev/null @@ -1,110 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "platform/platform.h" -#include "gfx/D3D9/screenshotD3D9.h" - -#include "gfx/D3D9/gfxD3D9Device.h" - -#include -#include -#include - - -GBitmap* ScreenShotD3D9::_captureBackBuffer() -{ -#ifdef TORQUE_OS_XENON - return NULL; -#else - LPDIRECT3DDEVICE9 D3DDevice = dynamic_cast(GFX)->getDevice(); - - IDirect3DSurface9 * backBuffer; - D3DDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer ); - - // Figure the size we're snagging. - D3DSURFACE_DESC desc; - backBuffer->GetDesc(&desc); - - Point2I size; - size.x = desc.Width; - size.y = desc.Height; - - // set up the 2 copy surfaces - GFXTexHandle tex[2]; - IDirect3DSurface9 *surface[2]; - - tex[0].set( size.x, size.y, GFXFormatR8G8B8X8, &GFXDefaultRenderTargetProfile, avar("%s() - tex[0] (line %d)", __FUNCTION__, __LINE__) ); - tex[1].set( size.x, size.y, GFXFormatR8G8B8X8, &GFXSystemMemProfile, avar("%s() - tex[1] (line %d)", __FUNCTION__, __LINE__) ); - - // grab the top level surface of tex 0 - GFXD3D9TextureObject *to = (GFXD3D9TextureObject *) &(*tex[0]); - D3D9Assert( to->get2DTex()->GetSurfaceLevel( 0, &surface[0] ), NULL ); - - // use StretchRect because it allows a copy from a multisample surface - // to a normal rendertarget surface - D3DDevice->StretchRect( backBuffer, NULL, surface[0], NULL, D3DTEXF_NONE ); - - // grab the top level surface of tex 1 - to = (GFXD3D9TextureObject *) &(*tex[1]); - D3D9Assert( to->get2DTex()->GetSurfaceLevel( 0, &surface[1] ), NULL ); - - // copy the data from the render target to the system memory texture - D3DDevice->GetRenderTargetData( surface[0], surface[1] ); - - // Allocate a GBitmap and copy into it. - GBitmap *gb = new GBitmap(size.x, size.y); - - D3DLOCKED_RECT r; - D3DSURFACE_DESC d; - surface[1]->GetDesc(&d); - surface[1]->LockRect( &r, NULL, D3DLOCK_READONLY); - - // We've got the X8 in there so we have to manually copy stuff. - ColorI c; - for(S32 i=0; isetColor(j, i, c); - } - } - - surface[1]->UnlockRect(); - - // Also save it out with D3DX - //D3DXSaveSurfaceToFile( dT( "testScreen.png" ), D3DXIFF_PNG, surface[1], NULL, NULL ); - - // release the COM pointers - surface[0]->Release(); - surface[1]->Release(); - backBuffer->Release(); - - return gb; -#endif -} - diff --git a/Engine/source/gfx/D3D9/screenshotD3D9.h b/Engine/source/gfx/D3D9/screenshotD3D9.h deleted file mode 100644 index 023fa1562..000000000 --- a/Engine/source/gfx/D3D9/screenshotD3D9.h +++ /dev/null @@ -1,39 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- -#ifndef _SCREENSHOTD3D9_H_ -#define _SCREENSHOTD3D9_H_ - -#include "gfx/screenshot.h" - -//************************************************************************** -// D3D implementation of screenshot -//************************************************************************** -class ScreenShotD3D9 : public ScreenShot -{ -protected: - - GBitmap* _captureBackBuffer(); - -}; - - -#endif // _SCREENSHOTD3D9_H_ diff --git a/Engine/source/gfx/D3D9/videoCaptureD3D9.cpp b/Engine/source/gfx/D3D9/videoCaptureD3D9.cpp deleted file mode 100644 index 39786a472..000000000 --- a/Engine/source/gfx/D3D9/videoCaptureD3D9.cpp +++ /dev/null @@ -1,210 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#include "videoCaptureD3D9.h" -#include "gfx/D3D9/gfxD3D9Device.h" - -#include "platform/tmm_off.h" - -#include -#include -#include - -VideoFrameGrabberD3D9::VideoFrameGrabberD3D9() -{ - GFXDevice::getDeviceEventSignal().notify( this, &VideoFrameGrabberD3D9::_handleGFXEvent ); - mCurrentCapture = 0; -} - -VideoFrameGrabberD3D9::~VideoFrameGrabberD3D9() -{ - GFXDevice::getDeviceEventSignal().remove( this, &VideoFrameGrabberD3D9::_handleGFXEvent ); -} - - -void VideoFrameGrabberD3D9::captureBackBuffer() -{ - AssertFatal( mCapture[mCurrentCapture].stage != eInSystemMemory, "Error! Trying to override a capture resource in \"SystemMemory\" stage!" ); - -#ifndef TORQUE_OS_XENON - LPDIRECT3DDEVICE9 D3DDevice = dynamic_cast(GFX)->getDevice(); - - IDirect3DSurface9 * backBuffer; - D3DDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer ); - - GFXTexHandle &vidMemTex = mCapture[mCurrentCapture].vidMemTex; - - // Re-init video memory texture if needed - if (vidMemTex.isNull() || vidMemTex.getWidthHeight() != mResolution) - vidMemTex.set(mResolution.x, mResolution.y,GFXFormatR8G8B8X8, &GFXDefaultRenderTargetProfile, avar("%s() - mVidMemTex (line %d)", __FUNCTION__, __LINE__) ); - - // set up the copy surface - IDirect3DSurface9 *surface; - - // grab the top level surface of tex 0 - GFXD3D9TextureObject *to = (GFXD3D9TextureObject *) &(*vidMemTex); - D3D9Assert( to->get2DTex()->GetSurfaceLevel( 0, &surface ), NULL ); - - // use StretchRect because it allows a copy from a multisample surface - // to a normal rendertarget surface - D3DDevice->StretchRect( backBuffer, NULL, surface, NULL, D3DTEXF_LINEAR ); - - // Reelase surfaces - backBuffer->Release(); - surface->Release(); - - // Update the stage - mCapture[mCurrentCapture].stage = eInVideoMemory; -#endif -} - -void VideoFrameGrabberD3D9::makeBitmap() -{ - // Advance the stages for all resources, except the one used for the last capture - for (U32 i=0; iget2DTex()->GetSurfaceLevel( 0, &surface[0] ), NULL ); - - // grab the top level surface of tex 1 - to = (GFXD3D9TextureObject *) &(*sysMemTex); - D3D9Assert( to->get2DTex()->GetSurfaceLevel( 0, &surface[1] ), NULL ); - - // copy the data from the render target to the system memory texture - LPDIRECT3DDEVICE9 D3DDevice = dynamic_cast(GFX)->getDevice(); - D3DDevice->GetRenderTargetData( surface[0], surface[1] ); - - // celease surfaces - surface[0]->Release(); - surface[1]->Release(); - - // Change the resource state - capture.stage = eInSystemMemory; -#endif -} - -void VideoFrameGrabberD3D9::copyToBitmap(CaptureResource &capture) -{ - AssertFatal( capture.stage == eInSystemMemory, "Error! copyToBitmap() can only work in resources in 'eInSystemMemory' stage!" ); - - GFXTexHandle &sysMemTex = capture.sysMemTex; - Point2I size = sysMemTex.getWidthHeight(); - - // Setup a surface - IDirect3DSurface9 *surface; - - GFXD3D9TextureObject *to = (GFXD3D9TextureObject *) &(*sysMemTex); - D3D9Assert( to->get2DTex()->GetSurfaceLevel( 0, &surface ), NULL ); - - // Lock the system memory surface - D3DLOCKED_RECT r; - D3DSURFACE_DESC d; - surface->GetDesc(&d); - surface->LockRect( &r, NULL, D3DLOCK_READONLY); - - // Allocate a GBitmap and copy into it. - GBitmap *gb = new GBitmap(size.x, size.y); - - // We've got the X8 in there so we have to manually copy stuff. - const U32* src = (const U32*)r.pBits; - U8* dst = gb->getWritableBits(); - S32 pixels = size.x*size.y; - for(S32 i=0; i> 16; - *dst++ = px >> 8; - *dst++ = px; - } - surface->UnlockRect(); - - // celease surfaces - surface->Release(); - - // Push this new bitmap - pushNewBitmap(gb); - - // Change the resource state - capture.stage = eReadyToCapture; -} - -bool VideoFrameGrabberD3D9::_handleGFXEvent( GFXDevice::GFXDeviceEventType event_ ) -{ - switch ( event_ ) - { - case GFXDevice::deDestroy : - releaseTextures(); - break; - - default: - break; - } - - return true; -} diff --git a/Engine/source/gfx/D3D9/videoCaptureD3D9.h b/Engine/source/gfx/D3D9/videoCaptureD3D9.h deleted file mode 100644 index eb3b7e19f..000000000 --- a/Engine/source/gfx/D3D9/videoCaptureD3D9.h +++ /dev/null @@ -1,87 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -//----------------------------------------------------------------------------- - -#ifndef _GFX_D3D_VIDEOCAPTURED3D9_H_ -#define _GFX_D3D_VIDEOCAPTURED3D9_H_ - -#ifndef _VIDEOCAPTURE_H_ -#include "gfx/video/videoCapture.h" -#endif - -#ifndef _GFXDEVICE_H_ -#include "gfx/gfxDevice.h" -#endif - - -class VideoFrameGrabberD3D9 : public VideoFrameGrabber -{ -protected: - enum CaptureStage { - eReadyToCapture, - eInVideoMemory, - eInSystemMemory, - eNumStages - }; - - // Contains all elements involved in single frame capture and - // is used to spread the multiple "stages" needed to capture a bitmap - // over various frames to keep GPU resources from locking the CPU. - struct CaptureResource { - GFXTexHandle vidMemTex; //Video memory texture - GFXTexHandle sysMemTex; //System memory texture - CaptureStage stage; //This resource's capture stage - - CaptureResource() : stage(eReadyToCapture) {}; - ~CaptureResource() - { - vidMemTex.free(); - sysMemTex.free(); - } - }; - - // Capture resource array. One item for each capture pipeline stage - CaptureResource mCapture[eNumStages]; - - // Current capture index - S32 mCurrentCapture; - - // Copies a capture's video memory content to system memory - void copyToSystemMemory(CaptureResource &capture); - - // Copies a capture's syste memory content to a new bitmap - void copyToBitmap(CaptureResource &capture); - - bool _handleGFXEvent(GFXDevice::GFXDeviceEventType event); - - //------------------------------------------------ - // Overloaded from VideoFrameGrabber - //------------------------------------------------ - void captureBackBuffer(); - void makeBitmap(); - void releaseTextures(); - -public: - VideoFrameGrabberD3D9(); - ~VideoFrameGrabberD3D9(); -}; - -#endif // _GFX_D3D_VIDEOCAPTURED3D9_H_ diff --git a/Engine/source/gfx/gfxAPI.cpp b/Engine/source/gfx/gfxAPI.cpp index b41b1297b..f2e480706 100644 --- a/Engine/source/gfx/gfxAPI.cpp +++ b/Engine/source/gfx/gfxAPI.cpp @@ -42,9 +42,7 @@ ImplementEnumType( GFXAdapterType, "@ingroup GFX" ) { OpenGL, "OpenGL", "OpenGL." }, { Direct3D11, "D3D11", "Direct3D 11." }, - { Direct3D9, "D3D9", "Direct3D 9." }, - { NullDevice, "NullDevice", "Null device for dedicated servers." }, - { Direct3D9_360, "Xenon", "Direct3D 9 on Xbox 360." } + { NullDevice, "NullDevice", "Null device for dedicated servers." } EndImplementEnumType; ImplementEnumType( GFXBlend, diff --git a/Engine/source/gfx/gfxCardProfile.cpp b/Engine/source/gfx/gfxCardProfile.cpp index 9bdb1f9f3..c223aca11 100644 --- a/Engine/source/gfx/gfxCardProfile.cpp +++ b/Engine/source/gfx/gfxCardProfile.cpp @@ -206,7 +206,7 @@ DefineEngineStaticMethod( GFXCardProfilerAPI, getVendor, String, (),, } DefineEngineStaticMethod( GFXCardProfilerAPI, getRenderer, String, (),, - "Returns the renderer name. For example D3D9 or OpenGL." ) + "Returns the renderer name. For example D3D11 or OpenGL." ) { return GFX->getCardProfiler()->getRendererString(); } diff --git a/Engine/source/gfx/gfxEnums.h b/Engine/source/gfx/gfxEnums.h index af0e1b920..ba5664b41 100644 --- a/Engine/source/gfx/gfxEnums.h +++ b/Engine/source/gfx/gfxEnums.h @@ -284,9 +284,7 @@ enum GFXAdapterType { OpenGL = 0, Direct3D11, - Direct3D9, NullDevice, - Direct3D9_360, GFXAdapterType_Count }; diff --git a/Engine/source/gfx/gfxInit.cpp b/Engine/source/gfx/gfxInit.cpp index be4389f73..21572b957 100644 --- a/Engine/source/gfx/gfxInit.cpp +++ b/Engine/source/gfx/gfxInit.cpp @@ -68,9 +68,6 @@ inline static void _GFXInitReportAdapters(Vector &adapters) { switch (adapters[i]->mType) { - case Direct3D9: - Con::printf(" Direct 3D (version 9.x) device found"); - break; case OpenGL: Con::printf(" OpenGL device found"); break; @@ -259,7 +256,7 @@ GFXAdapter* GFXInit::chooseAdapter(GFXAdapterType type, S32 outputDeviceIndex) const char* GFXInit::getAdapterNameFromType(GFXAdapterType type) { // must match GFXAdapterType order - static const char* _names[] = { "OpenGL", "D3D11", "D3D9", "NullDevice", "Xenon" }; + static const char* _names[] = { "OpenGL", "D3D11", "NullDevice" }; if( type < 0 || type >= GFXAdapterType_Count ) { @@ -281,8 +278,8 @@ GFXAdapterType GFXInit::getAdapterTypeFromName(const char* name) if( ret == -1 ) { - Con::errorf( "GFXInit::getAdapterTypeFromName - Invalid renderer name, defaulting to D3D9" ); - ret = Direct3D9; + Con::errorf( "GFXInit::getAdapterTypeFromName - Invalid renderer name, defaulting to D3D11" ); + ret = Direct3D11; } return (GFXAdapterType)ret; @@ -322,7 +319,7 @@ GFXAdapter *GFXInit::getBestAdapterChoice() // If D3D is unavailable, we're not on windows, so GL is de facto the // best choice! F32 highestSMDX = 0.f, highestSMGL = 0.f; - GFXAdapter *foundAdapter9 = NULL, *foundAdapterGL = NULL, *foundAdapter11 = NULL; + GFXAdapter *foundAdapterGL = NULL, *foundAdapter11 = NULL; for (S32 i = 0; imShaderModel > highestSMDX) - { - highestSMDX = currAdapter->mShaderModel; - foundAdapter9 = currAdapter; - } - break; - case OpenGL: if (currAdapter->mShaderModel > highestSMGL) { @@ -358,13 +346,10 @@ GFXAdapter *GFXInit::getBestAdapterChoice() } } - // Return best found in order DX11,DX9, GL + // Return best found in order DX11, GL if (foundAdapter11) return foundAdapter11; - if (foundAdapter9) - return foundAdapter9; - if (foundAdapterGL) return foundAdapterGL; @@ -486,7 +471,7 @@ DefineEngineStaticMethod( GFXInit, getAdapterOutputName, String, ( S32 index ),, } DefineEngineStaticMethod( GFXInit, getAdapterType, GFXAdapterType, ( S32 index ),, - "Returns the type (D3D9, D3D8, GL, Null) of a graphics adapter.\n" + "Returns the type (D3D11, GL, Null) of a graphics adapter.\n" "@param index The index of the adapter." ) { Vector adapters( __FILE__, __LINE__ ); diff --git a/Engine/source/gfx/gfxTarget.h b/Engine/source/gfx/gfxTarget.h index 88ce4040f..d0c7f47ad 100644 --- a/Engine/source/gfx/gfxTarget.h +++ b/Engine/source/gfx/gfxTarget.h @@ -52,8 +52,6 @@ class GFXTextureObject; /// tied to a window, or a set of surfaces or textures. class GFXTarget : public StrongRefBase, public GFXResource { - friend class GFXD3D9Device; - friend class GFX360Device; private: S32 mChangeToken; diff --git a/Engine/source/gfx/gl/gfxGLCardProfiler.cpp b/Engine/source/gfx/gl/gfxGLCardProfiler.cpp index a4fce21cb..7151bb002 100644 --- a/Engine/source/gfx/gl/gfxGLCardProfiler.cpp +++ b/Engine/source/gfx/gl/gfxGLCardProfiler.cpp @@ -74,7 +74,7 @@ void GFXGLCardProfiler::setupCardCapabilities() bool GFXGLCardProfiler::_queryCardCap(const String& query, U32& foundResult) { - // Just doing what the D3D9 layer does + // Just doing what the D3D11 layer does return 0; } diff --git a/Engine/source/gfx/util/screenspace.cpp b/Engine/source/gfx/util/screenspace.cpp index c6a159417..ce9d2b0ab 100644 --- a/Engine/source/gfx/util/screenspace.cpp +++ b/Engine/source/gfx/util/screenspace.cpp @@ -42,14 +42,6 @@ void ScreenSpace::RenderTargetParameters(const Point3I &targetSize, const RectI Point2F targetScale( (F32)targetViewport.extent.x / (F32)targetSize.x, (F32)targetViewport.extent.y / (F32)targetSize.y ); - const bool hasTexelPixelOffset = GFX->getAdapterType() == Direct3D9; - // Get the target half pixel size. - const Point2F halfPixel( hasTexelPixelOffset ? (0.5f / targetSize.x) : 0.0f, - hasTexelPixelOffset ? (0.5f / targetSize.y) : 0.0f ); - - rtParams.set( targetOffset.x + halfPixel.x, - targetOffset.y + halfPixel.y, - targetScale.x, - targetScale.y ); + rtParams.set( targetOffset.x, targetOffset.y, targetScale.x, targetScale.y ); } \ No newline at end of file diff --git a/Engine/source/gui/core/guiCanvas.cpp b/Engine/source/gui/core/guiCanvas.cpp index b2b6312f8..f00cf6cca 100644 --- a/Engine/source/gui/core/guiCanvas.cpp +++ b/Engine/source/gui/core/guiCanvas.cpp @@ -2367,7 +2367,7 @@ DefineEngineFunction(excludeOtherInstance, bool, (const char* appIdentifer),, "@ingroup Platform\n" "@ingroup GuiCore") { - // mac/360 can only run one instance in general. + // mac can only run one instance in general. #if !defined(TORQUE_OS_MAC) && !defined(TORQUE_DEBUG) && !defined(TORQUE_OS_LINUX) return Platform::excludeOtherInstances(appIdentifer); #else diff --git a/Engine/source/lighting/advanced/advancedLightManager.cpp b/Engine/source/lighting/advanced/advancedLightManager.cpp index de984894a..5842ec717 100644 --- a/Engine/source/lighting/advanced/advancedLightManager.cpp +++ b/Engine/source/lighting/advanced/advancedLightManager.cpp @@ -116,23 +116,23 @@ void AdvancedLightManager::activate( SceneManager *sceneManager ) mLightBinManager->assignName( "AL_LightBinMgr" ); // First look for the deferred bin... - RenderDeferredMgr *prePassBin = _findDeferredRenderBin(); + RenderDeferredMgr *deferredBin = _findDeferredRenderBin(); // If we didn't find the deferred bin then add one. - if ( !prePassBin ) + if ( !deferredBin ) { - prePassBin = new RenderDeferredMgr( true, blendTargetFormat ); - prePassBin->assignName( "AL_DeferredBin" ); - prePassBin->registerObject(); - getSceneManager()->getDefaultRenderPass()->addManager( prePassBin ); - mDeferredRenderBin = prePassBin; + deferredBin = new RenderDeferredMgr( true, blendTargetFormat ); + deferredBin->assignName( "AL_DeferredBin" ); + deferredBin->registerObject(); + getSceneManager()->getDefaultRenderPass()->addManager( deferredBin ); + mDeferredRenderBin = deferredBin; } // Tell the material manager that deferred is enabled. MATMGR->setDeferredEnabled( true ); // Insert our light bin manager. - mLightBinManager->setRenderOrder( prePassBin->getRenderOrder() + 0.01f ); + mLightBinManager->setRenderOrder( deferredBin->getRenderOrder() + 0.01f ); getSceneManager()->getDefaultRenderPass()->addManager( mLightBinManager ); AdvancedLightingFeatures::registerFeatures(mDeferredRenderBin->getTargetFormat(), mLightBinManager->getTargetFormat()); diff --git a/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp b/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp index 513b3e2af..f1223f7b0 100644 --- a/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp +++ b/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp @@ -232,7 +232,6 @@ void DeferredBumpFeatGLSL::processVert( Vector &componentLis getOutTexCoord( "texCoord", "vec2", - true, useTexAnim, meta, componentList ); @@ -272,7 +271,7 @@ void DeferredBumpFeatGLSL::processPix( Vector &componentList, // create texture var Var *bumpMap = getNormalMapTex(); - Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "vec2", componentList ); LangElement *texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord ); // create bump normal @@ -295,7 +294,7 @@ void DeferredBumpFeatGLSL::processPix( Vector &componentList, bumpMap->sampler = true; bumpMap->constNum = Var::getTexUnitNum(); - texCoord = getInTexCoord( "detCoord", "vec2", true, componentList ); + texCoord = getInTexCoord( "detCoord", "vec2", componentList ); texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord ); Var *detailBump = new Var; @@ -338,7 +337,7 @@ void DeferredBumpFeatGLSL::processPix( Vector &componentList, { MultiLine *meta = new MultiLine; - Var *texCoord = getInTexCoord("texCoord", "vec2", true, componentList); + Var *texCoord = getInTexCoord("texCoord", "vec2", componentList); Var *bumpMap = getNormalMapTex(); @@ -361,7 +360,7 @@ void DeferredBumpFeatGLSL::processPix( Vector &componentList, bumpMap->constNum = Var::getTexUnitNum(); } - texCoord = getInTexCoord("detCoord", "vec2", true, componentList); + texCoord = getInTexCoord("detCoord", "vec2", componentList); LangElement *texOp = new GenOp("tex2D(@, @)", bumpMap, texCoord); Var *detailBump = new Var; @@ -394,7 +393,7 @@ void DeferredBumpFeatGLSL::processPix( Vector &componentList, Var *bumpSample = (Var *)LangElement::find( "bumpSample" ); if( bumpSample == NULL ) { - Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "vec2", componentList ); Var *bumpMap = getNormalMapTex(); diff --git a/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp b/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp index b1f97722f..b4b82fb90 100644 --- a/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp +++ b/Engine/source/lighting/advanced/glsl/deferredShadingFeaturesGLSL.cpp @@ -41,7 +41,7 @@ void DeferredSpecMapGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // Get the texture coord. - Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "vec2", componentList ); // search for color var Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); @@ -98,7 +98,6 @@ void DeferredSpecMapGLSL::processVert( Vector &componentList, MultiLine *meta = new MultiLine; getOutTexCoord( "texCoord", "vec2", - true, fd.features[MFT_TexAnim], meta, componentList ); diff --git a/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp b/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp index 8e71aecfe..ae80df058 100644 --- a/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp +++ b/Engine/source/lighting/advanced/glsl/gBufferConditionerGLSL.cpp @@ -145,7 +145,6 @@ void GBufferConditionerGLSL::processPix( Vector &componentLis gbNormal->setName( "gbNormal" ); gbNormal->setStructName( "IN" ); gbNormal->setType( "float3" ); - gbNormal->mapsToSampler = false; gbNormal->uniform = false; } diff --git a/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp b/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp index 8065aae99..69fafdb66 100644 --- a/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp +++ b/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp @@ -120,23 +120,18 @@ void DeferredRTLightingFeatHLSL::processPix( Vector &component // create texture var Var *lightInfoBuffer = new Var; - lightInfoBuffer->setType( "sampler2D" ); + lightInfoBuffer->setType( "SamplerState" ); lightInfoBuffer->setName( "lightInfoBuffer" ); lightInfoBuffer->uniform = true; lightInfoBuffer->sampler = true; lightInfoBuffer->constNum = Var::getTexUnitNum(); // used as texture unit num here - Var* lightBufferTex = NULL; - if (mIsDirect3D11) - { - lightInfoBuffer->setType("SamplerState"); - lightBufferTex = new Var; - lightBufferTex->setName("lightInfoBufferTex"); - lightBufferTex->setType("Texture2D"); - lightBufferTex->uniform = true; - lightBufferTex->texture = true; - lightBufferTex->constNum = lightInfoBuffer->constNum; - } + Var* lightBufferTex = new Var; + lightBufferTex->setName("lightInfoBufferTex"); + lightBufferTex->setType("Texture2D"); + lightBufferTex->uniform = true; + lightBufferTex->texture = true; + lightBufferTex->constNum = lightInfoBuffer->constNum; // Declare the RTLighting variables in this feature, they will either be assigned // in this feature, or in the tonemap/lightmap feature @@ -152,12 +147,8 @@ void DeferredRTLightingFeatHLSL::processPix( Vector &component // Perform the uncondition here. String unconditionLightInfo = String::ToLower( AdvancedLightBinManager::smBufferName ) + "Uncondition"; - if (mIsDirect3D11) - meta->addStatement(new GenOp(avar(" %s(@.Sample(@, @), @, @, @);\r\n", - unconditionLightInfo.c_str()), lightBufferTex, lightInfoBuffer, uvScene, d_lightcolor, d_NL_Att, d_specular)); - else - meta->addStatement(new GenOp(avar(" %s(tex2D(@, @), @, @, @);\r\n", - unconditionLightInfo.c_str()), lightInfoBuffer, uvScene, d_lightcolor, d_NL_Att, d_specular)); + meta->addStatement(new GenOp(avar(" %s(@.Sample(@, @), @, @, @);\r\n", + unconditionLightInfo.c_str()), lightBufferTex, lightInfoBuffer, uvScene, d_lightcolor, d_NL_Att, d_specular)); // If this has an interlaced pre-pass, do averaging here if( fd.features[MFT_InterlacedDeferred] ) @@ -173,12 +164,8 @@ void DeferredRTLightingFeatHLSL::processPix( Vector &component } meta->addStatement( new GenOp( " float id_NL_Att, id_specular;\r\n float3 id_lightcolor;\r\n" ) ); - if (mIsDirect3D11) - meta->addStatement(new GenOp(avar(" %s(@.Sample(@, @ + float2(0.0, @.y)), id_lightcolor, id_NL_Att, id_specular);\r\n", - unconditionLightInfo.c_str()), lightBufferTex, lightInfoBuffer, uvScene, oneOverTargetSize)); - else - meta->addStatement(new GenOp(avar(" %s(tex2D(@, @ + float2(0.0, @.y)), id_lightcolor, id_NL_Att, id_specular);\r\n", - unconditionLightInfo.c_str()), lightInfoBuffer, uvScene, oneOverTargetSize)); + meta->addStatement(new GenOp(avar(" %s(@.Sample(@, @ + float2(0.0, @.y)), id_lightcolor, id_NL_Att, id_specular);\r\n", + unconditionLightInfo.c_str()), lightBufferTex, lightInfoBuffer, uvScene, oneOverTargetSize)); meta->addStatement( new GenOp(" @ = lerp(@, id_lightcolor, 0.5);\r\n", d_lightcolor, d_lightcolor ) ); meta->addStatement( new GenOp(" @ = lerp(@, id_NL_Att, 0.5);\r\n", d_NL_Att, d_NL_Att ) ); @@ -252,7 +239,6 @@ void DeferredBumpFeatHLSL::processVert( Vector &componentLis getOutTexCoord( "texCoord", "float2", - true, useTexAnim, meta, componentList ); @@ -292,17 +278,10 @@ void DeferredBumpFeatHLSL::processPix( Vector &componentList, // create texture var Var *bumpMap = getNormalMapTex(); - Var *texCoord = getInTexCoord("texCoord", "float2", true, componentList); + Var *texCoord = getInTexCoord("texCoord", "float2", componentList); - LangElement *texOp = NULL; - - if (mIsDirect3D11) - { - Var *bumpMapTex = (Var*)LangElement::find("bumpMapTex"); - texOp = new GenOp("@.Sample(@, @)", bumpMapTex, bumpMap, texCoord); - } - else - texOp = new GenOp("tex2D(@, @)", bumpMap, texCoord); + Var *bumpMapTex = (Var*)LangElement::find("bumpMapTex"); + LangElement *texOp = new GenOp("@.Sample(@, @)", bumpMapTex, bumpMap, texCoord); // create bump normal Var *bumpNorm = new Var; @@ -318,31 +297,22 @@ void DeferredBumpFeatHLSL::processPix( Vector &componentList, if ( fd.features.hasFeature( MFT_DetailNormalMap ) ) { bumpMap = new Var; - bumpMap->setType( "sampler2D" ); + bumpMap->setType( "SamplerState" ); bumpMap->setName( "detailBumpMap" ); bumpMap->uniform = true; bumpMap->sampler = true; bumpMap->constNum = Var::getTexUnitNum(); - Var* detailNormalTex = NULL; - if (mIsDirect3D11) - { - bumpMap->setType("SamplerState"); - detailNormalTex = new Var; - detailNormalTex->setName("detailBumpMapTex"); - detailNormalTex->setType("Texture2D"); - detailNormalTex->uniform = true; - detailNormalTex->texture = true; - detailNormalTex->constNum = bumpMap->constNum; - } + Var* detailNormalTex = new Var; + detailNormalTex->setName("detailBumpMapTex"); + detailNormalTex->setType("Texture2D"); + detailNormalTex->uniform = true; + detailNormalTex->texture = true; + detailNormalTex->constNum = bumpMap->constNum; + texCoord = getInTexCoord("detCoord", "float2", componentList); - texCoord = getInTexCoord("detCoord", "float2", true, componentList); - - if (mIsDirect3D11) - texOp = new GenOp("@.Sample(@, @)", detailNormalTex, bumpMap, texCoord); - else - texOp = new GenOp("tex2D(@, @)", bumpMap, texCoord); + texOp = new GenOp("@.Sample(@, @)", detailNormalTex, bumpMap, texCoord); Var *detailBump = new Var; detailBump->setName( "detailBump" ); @@ -383,7 +353,7 @@ void DeferredBumpFeatHLSL::processPix( Vector &componentList, { MultiLine *meta = new MultiLine; - Var *texCoord = getInTexCoord("texCoord", "float2", true, componentList); + Var *texCoord = getInTexCoord("texCoord", "float2", componentList); Var *bumpMap = getNormalMapTex(); @@ -392,13 +362,8 @@ void DeferredBumpFeatHLSL::processPix( Vector &componentList, bumpSample->setName("bumpSample"); LangElement *bumpSampleDecl = new DecOp(bumpSample); - if (mIsDirect3D11) - { - Var *bumpMapTex = (Var *)LangElement::find("bumpMapTex"); - output = new GenOp(" @ = @.Sample(@, @);\r\n", bumpSampleDecl, bumpMapTex, bumpMap, texCoord); - } - else - output = new GenOp(" @ = tex2D(@, @);\r\n", bumpSampleDecl, bumpMap, texCoord); + Var *bumpMapTex = (Var *)LangElement::find("bumpMapTex"); + output = new GenOp(" @ = @.Sample(@, @);\r\n", bumpSampleDecl, bumpMapTex, bumpMap, texCoord); if ( fd.features.hasFeature( MFT_DetailNormalMap ) ) { @@ -414,7 +379,7 @@ void DeferredBumpFeatHLSL::processPix( Vector &componentList, } Var* bumpMapTex = (Var*)LangElement::find("detailBumpMap"); - if (mIsDirect3D11 && !bumpMapTex) + if (!bumpMapTex) { bumpMap->setType("SamplerState"); bumpMapTex = new Var; @@ -425,12 +390,8 @@ void DeferredBumpFeatHLSL::processPix( Vector &componentList, bumpMapTex->constNum = bumpMap->constNum; } - texCoord = getInTexCoord( "detCoord", "float2", true, componentList ); - LangElement *texOp = NULL; - if (mIsDirect3D11) - texOp = new GenOp("@.Sample(@, @)", bumpMap, bumpMapTex, texCoord); - else - texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord ); + texCoord = getInTexCoord( "detCoord", "float2", componentList ); + LangElement *texOp = new GenOp("@.Sample(@, @)", bumpMap, bumpMapTex, texCoord); Var *detailBump = new Var; detailBump->setName( "detailBump" ); @@ -462,7 +423,7 @@ void DeferredBumpFeatHLSL::processPix( Vector &componentList, Var *bumpSample = (Var *)LangElement::find( "bumpSample" ); if( bumpSample == NULL ) { - Var *texCoord = getInTexCoord( "texCoord", "float2", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "float2", componentList ); Var *bumpMap = getNormalMapTex(); @@ -471,13 +432,8 @@ void DeferredBumpFeatHLSL::processPix( Vector &componentList, bumpSample->setName( "bumpSample" ); LangElement *bumpSampleDecl = new DecOp( bumpSample ); - if (mIsDirect3D11) - { - Var *bumpMapTex = (Var *)LangElement::find("bumpMapTex"); - output = new GenOp(" @ = @.Sample(@, @);\r\n", bumpSampleDecl, bumpMapTex, bumpMap, texCoord); - } - else - output = new GenOp(" @ = tex2D(@, @);\r\n", bumpSampleDecl, bumpMap, texCoord); + Var *bumpMapTex = (Var *)LangElement::find("bumpMapTex"); + output = new GenOp(" @ = @.Sample(@, @);\r\n", bumpSampleDecl, bumpMapTex, bumpMap, texCoord); return; } @@ -742,23 +698,18 @@ void DeferredMinnaertHLSL::processPix( Vector &componentList, // create texture var Var *deferredBuffer = new Var; - deferredBuffer->setType( "sampler2D" ); + deferredBuffer->setType( "SamplerState" ); deferredBuffer->setName( "deferredBuffer" ); deferredBuffer->uniform = true; deferredBuffer->sampler = true; deferredBuffer->constNum = Var::getTexUnitNum(); // used as texture unit num here - Var* prePassTex = NULL; - if (mIsDirect3D11) - { - deferredBuffer->setType("SamplerState"); - prePassTex = new Var; - prePassTex->setName("prePassTex"); - prePassTex->setType("Texture2D"); - prePassTex->uniform = true; - prePassTex->texture = true; - prePassTex->constNum = deferredBuffer->constNum; - } + Var* prePassTex = new Var; + prePassTex->setName("prePassTex"); + prePassTex->setType("Texture2D"); + prePassTex->uniform = true; + prePassTex->texture = true; + prePassTex->constNum = deferredBuffer->constNum; // Texture coord Var *uvScene = (Var*) LangElement::find( "uvScene" ); @@ -773,10 +724,7 @@ void DeferredMinnaertHLSL::processPix( Vector &componentList, Var *d_NL_Att = (Var*)LangElement::find( "d_NL_Att" ); - if (mIsDirect3D11) - meta->addStatement(new GenOp(avar(" float4 normalDepth = %s(@, ,@, @);\r\n", unconditionDeferredMethod.c_str()), deferredBuffer, prePassTex, uvScene)); - else - meta->addStatement(new GenOp(avar(" float4 normalDepth = %s(@, @);\r\n", unconditionDeferredMethod.c_str()), deferredBuffer, uvScene)); + meta->addStatement(new GenOp(avar(" float4 normalDepth = %s(@, ,@, @);\r\n", unconditionDeferredMethod.c_str()), deferredBuffer, prePassTex, uvScene)); meta->addStatement( new GenOp( " float vDotN = dot(normalDepth.xyz, @);\r\n", wsViewVec ) ); meta->addStatement( new GenOp( " float Minnaert = pow( @, @) * pow(vDotN, 1.0 - @);\r\n", d_NL_Att, minnaertConstant, minnaertConstant ) ); diff --git a/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp b/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp index f8934d443..19cae4fc4 100644 --- a/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp +++ b/Engine/source/lighting/advanced/hlsl/deferredShadingFeaturesHLSL.cpp @@ -41,7 +41,7 @@ void DeferredSpecMapHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // Get the texture coord. - Var *texCoord = getInTexCoord( "texCoord", "float2", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "float2", componentList ); // search for color var Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); @@ -57,23 +57,18 @@ void DeferredSpecMapHLSL::processPix( Vector &componentList, c // create texture var Var *specularMap = new Var; - specularMap->setType( "sampler2D" ); + specularMap->setType( "SamplerState" ); specularMap->setName( "specularMap" ); specularMap->uniform = true; specularMap->sampler = true; specularMap->constNum = Var::getTexUnitNum(); - Var* specularMapTex = NULL; - if (mIsDirect3D11) - { - specularMap->setType("SamplerState"); - specularMapTex = new Var; - specularMapTex->setName("specularMapTex"); - specularMapTex->setType("Texture2D"); - specularMapTex->uniform = true; - specularMapTex->texture = true; - specularMapTex->constNum = specularMap->constNum; - } + Var* specularMapTex = new Var; + specularMapTex->setName("specularMapTex"); + specularMapTex->setType("Texture2D"); + specularMapTex->uniform = true; + specularMapTex->texture = true; + specularMapTex->constNum = specularMap->constNum; //matinfo.g slot reserved for AO later Var* specColor = new Var; @@ -83,10 +78,7 @@ void DeferredSpecMapHLSL::processPix( Vector &componentList, c meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material)); //sample specular map - if (mIsDirect3D11) - meta->addStatement(new GenOp(" @ = @.Sample(@, @);\r\n", specColorElem, specularMapTex, specularMap, texCoord)); - else - meta->addStatement(new GenOp(" @ = tex2D(@, @);\r\n", specColorElem, specularMap, texCoord)); + meta->addStatement(new GenOp(" @ = @.Sample(@, @);\r\n", specColorElem, specularMapTex, specularMap, texCoord)); meta->addStatement(new GenOp(" @.b = dot(@.rgb, float3(0.3, 0.59, 0.11));\r\n", material, specColor)); meta->addStatement(new GenOp(" @.a = @.a;\r\n", material, specColor)); @@ -123,7 +115,6 @@ void DeferredSpecMapHLSL::processVert( Vector &componentList, MultiLine *meta = new MultiLine; getOutTexCoord( "texCoord", "float2", - true, fd.features[MFT_TexAnim], meta, componentList ); diff --git a/Engine/source/lighting/advanced/hlsl/gBufferConditionerHLSL.cpp b/Engine/source/lighting/advanced/hlsl/gBufferConditionerHLSL.cpp index 7c6d51a60..d4d14203f 100644 --- a/Engine/source/lighting/advanced/hlsl/gBufferConditionerHLSL.cpp +++ b/Engine/source/lighting/advanced/hlsl/gBufferConditionerHLSL.cpp @@ -145,7 +145,6 @@ void GBufferConditionerHLSL::processPix( Vector &componentLis gbNormal->setName( "gbNormal" ); gbNormal->setStructName( "IN" ); gbNormal->setType( "float3" ); - gbNormal->mapsToSampler = false; gbNormal->uniform = false; } @@ -222,7 +221,6 @@ Var* GBufferConditionerHLSL::printMethodHeader( MethodType methodType, const Str retVal = Parent::printMethodHeader( methodType, methodName, stream, meta ); else { - const bool isDirect3D11 = GFX->getAdapterType() == Direct3D11; Var *methodVar = new Var; methodVar->setName(methodName); methodVar->setType("inline float4"); @@ -230,7 +228,7 @@ Var* GBufferConditionerHLSL::printMethodHeader( MethodType methodType, const Str Var *deferredSampler = new Var; deferredSampler->setName("deferredSamplerVar"); - deferredSampler->setType("sampler2D"); + deferredSampler->setType("SamplerState"); DecOp *deferredSamplerDecl = new DecOp(deferredSampler); Var *screenUV = new Var; @@ -238,28 +236,21 @@ Var* GBufferConditionerHLSL::printMethodHeader( MethodType methodType, const Str screenUV->setType("float2"); DecOp *screenUVDecl = new DecOp(screenUV); - Var *deferredTex = NULL; DecOp *deferredTexDecl = NULL; - if (isDirect3D11) - { - deferredSampler->setType("SamplerState"); - deferredTex = new Var; - deferredTex->setName("deferredTexVar"); - deferredTex->setType("Texture2D"); - deferredTex->texture = true; - deferredTex->constNum = deferredSampler->constNum; - deferredTexDecl = new DecOp(deferredTex); - } + + Var *deferredTex = new Var; + deferredTex->setName("deferredTexVar"); + deferredTex->setType("Texture2D"); + deferredTex->texture = true; + deferredTex->constNum = deferredSampler->constNum; + deferredTexDecl = new DecOp(deferredTex); Var *bufferSample = new Var; bufferSample->setName("bufferSample"); bufferSample->setType("float4"); DecOp *bufferSampleDecl = new DecOp(bufferSample); - if (isDirect3D11) - meta->addStatement(new GenOp("@(@, @, @)\r\n", methodDecl, deferredSamplerDecl, deferredTexDecl, screenUVDecl)); - else - meta->addStatement( new GenOp( "@(@, @)\r\n", methodDecl, deferredSamplerDecl, screenUVDecl ) ); + meta->addStatement(new GenOp("@(@, @, @)\r\n", methodDecl, deferredSamplerDecl, deferredTexDecl, screenUVDecl)); meta->addStatement( new GenOp( "{\r\n" ) ); @@ -267,15 +258,7 @@ Var* GBufferConditionerHLSL::printMethodHeader( MethodType methodType, const Str // The gbuffer has no mipmaps, so use tex2dlod when // possible so that the shader compiler can optimize. - meta->addStatement( new GenOp( " #if TORQUE_SM >= 30\r\n" ) ); - if (isDirect3D11) - meta->addStatement(new GenOp(" @ = @.SampleLevel(@, @,0);\r\n", bufferSampleDecl, deferredTex, deferredSampler, screenUV)); - else - meta->addStatement(new GenOp(" @ = tex2Dlod(@, float4(@,0,0));\r\n", bufferSampleDecl, deferredSampler, screenUV)); - - meta->addStatement(new GenOp(" #else\r\n")); - meta->addStatement(new GenOp(" @ = tex2D(@, @);\r\n", bufferSampleDecl, deferredSampler, screenUV)); - meta->addStatement(new GenOp(" #endif\r\n\r\n")); + meta->addStatement(new GenOp(" @ = @.SampleLevel(@, @,0);\r\n", bufferSampleDecl, deferredTex, deferredSampler, screenUV)); // We don't use this way of passing var's around, so this should cause a crash // if something uses this improperly diff --git a/Engine/source/lighting/basic/basicLightManager.cpp b/Engine/source/lighting/basic/basicLightManager.cpp index f062cad48..d3385dfe8 100644 --- a/Engine/source/lighting/basic/basicLightManager.cpp +++ b/Engine/source/lighting/basic/basicLightManager.cpp @@ -185,12 +185,12 @@ void BasicLightManager::activate( SceneManager *sceneManager ) FEATUREMGR->unregisterFeature( MFT_SubSurface ); // First look for the deferred bin... - RenderDeferredMgr *prePassBin = _findDeferredRenderBin(); + RenderDeferredMgr *deferredBin = _findDeferredRenderBin(); /* // If you would like to use forward shading, and have a linear depth pre-pass // than un-comment this code block. - if ( !prePassBin ) + if ( !deferredBin ) { Vector formats; formats.push_back( GFXFormatR32F ); @@ -204,12 +204,12 @@ void BasicLightManager::activate( SceneManager *sceneManager ) // Uncomment this for a no-color-write z-fill pass. //linearDepthFormat = GFXFormat_COUNT; - prePassBin = new RenderDeferredMgr( linearDepthFormat != GFXFormat_COUNT, linearDepthFormat ); - prePassBin->registerObject(); - rpm->addManager( prePassBin ); + deferredBin = new RenderDeferredMgr( linearDepthFormat != GFXFormat_COUNT, linearDepthFormat ); + deferredBin->registerObject(); + rpm->addManager( deferredBin ); } */ - mDeferredRenderBin = prePassBin; + mDeferredRenderBin = deferredBin; // If there is a deferred bin MATMGR->setDeferredEnabled( mDeferredRenderBin.isValid() ); diff --git a/Engine/source/materials/shaderData.cpp b/Engine/source/materials/shaderData.cpp index 29c379ed7..3a80c0ac5 100644 --- a/Engine/source/materials/shaderData.cpp +++ b/Engine/source/materials/shaderData.cpp @@ -234,8 +234,6 @@ GFXShader* ShaderData::_createShader( const Vector ¯os ) // Initialize the right shader type. switch( GFX->getAdapterType() ) { - case Direct3D9_360: - case Direct3D9: case Direct3D11: { success = shader->init( mDXVertexShaderName, diff --git a/Engine/source/postFx/postEffect.cpp b/Engine/source/postFx/postEffect.cpp index b814f8c58..c407dec8f 100644 --- a/Engine/source/postFx/postEffect.cpp +++ b/Engine/source/postFx/postEffect.cpp @@ -666,15 +666,11 @@ void PostEffect::_setupConstants( const SceneRenderState *state ) Point2F offset((F32)viewport.point.x / (F32)targetSize.x, (F32)viewport.point.y / (F32)targetSize.y ); Point2F scale((F32)viewport.extent.x / (F32)targetSize.x, (F32)viewport.extent.y / (F32)targetSize.y ); - const bool hasTexelPixelOffset = GFX->getAdapterType() == Direct3D9; - const Point2F halfPixel( hasTexelPixelOffset ? (0.5f / targetSize.x) : 0.0f, - hasTexelPixelOffset ? (0.5f / targetSize.y) : 0.0f ); - Point4F targetParams; - targetParams.x = offset.x + halfPixel.x; - targetParams.y = offset.y + halfPixel.y; - targetParams.z = offset.x + scale.x - halfPixel.x; - targetParams.w = offset.y + scale.y - halfPixel.y; + targetParams.x = offset.x; + targetParams.y = offset.y; + targetParams.z = offset.x + scale.x; + targetParams.w = offset.y + scale.y; mShaderConsts->set( mTargetViewportSC, targetParams ); } diff --git a/Engine/source/renderInstance/renderDeferredMgr.cpp b/Engine/source/renderInstance/renderDeferredMgr.cpp index c49e8df20..f05d0630f 100644 --- a/Engine/source/renderInstance/renderDeferredMgr.cpp +++ b/Engine/source/renderInstance/renderDeferredMgr.cpp @@ -1029,7 +1029,21 @@ Var* LinearEyeDepthConditioner::printMethodHeader( MethodType methodType, const Var *deferredSampler = new Var; deferredSampler->setName("deferredSamplerVar"); deferredSampler->setType("sampler2D"); - DecOp *deferredSamplerDecl = new DecOp(deferredSampler); + DecOp *deferredSamplerDecl = NULL; + + Var *deferredTex = NULL; + DecOp *deferredTexDecl = NULL; + if (GFX->getAdapterType() == Direct3D11) + { + deferredSampler->setType("SamplerState"); + + deferredTex = new Var; + deferredTex->setName("deferredTexVar"); + deferredTex->setType("Texture2D"); + deferredTexDecl = new DecOp(deferredTex); + } + + deferredSamplerDecl = new DecOp(deferredSampler); Var *screenUV = new Var; screenUV->setName("screenUVVar"); diff --git a/Engine/source/renderInstance/renderParticleMgr.cpp b/Engine/source/renderInstance/renderParticleMgr.cpp index b8b795a8c..f9b0e3fc8 100644 --- a/Engine/source/renderInstance/renderParticleMgr.cpp +++ b/Engine/source/renderInstance/renderParticleMgr.cpp @@ -557,7 +557,7 @@ bool RenderParticleMgr::_initShader() mParticleShaderConsts.mAlphaFactorSC = mParticleShader->getShaderConstHandle( "$alphaFactor" ); mParticleShaderConsts.mAlphaScaleSC = mParticleShader->getShaderConstHandle( "$alphaScale" ); mParticleShaderConsts.mFSModelViewProjSC = mParticleShader->getShaderConstHandle( "$fsModelViewProj" ); - mParticleShaderConsts.mDeferredTargetParamsSC = mParticleShader->getShaderConstHandle( "$prePassTargetParams" ); + mParticleShaderConsts.mDeferredTargetParamsSC = mParticleShader->getShaderConstHandle( "$deferredTargetParams" ); //samplers mParticleShaderConsts.mSamplerDiffuse = mParticleShader->getShaderConstHandle("$diffuseMap"); @@ -596,13 +596,13 @@ void RenderParticleMgr::_onLMActivate( const char*, bool activate ) return; // Hunt for the pre-pass manager/target - RenderDeferredMgr *prePassBin = NULL; - for( U32 i = 0; i < rpm->getManagerCount(); i++ ) + RenderDeferredMgr *deferredBin = NULL; + for (U32 i = 0; i < rpm->getManagerCount(); i++) { RenderBinManager *bin = rpm->getManager(i); if( bin->getRenderInstType() == RenderDeferredMgr::RIT_Deferred ) { - prePassBin = (RenderDeferredMgr*)bin; + deferredBin = (RenderDeferredMgr*)bin; break; } } @@ -610,11 +610,11 @@ void RenderParticleMgr::_onLMActivate( const char*, bool activate ) // If we found the deferred bin, set this bin to render very shortly afterwards // and re-add this render-manager. If there is no pre-pass bin, or it doesn't // have a depth-texture, we can't render offscreen. - mOffscreenRenderEnabled = prePassBin && (prePassBin->getTargetChainLength() > 0); - if(mOffscreenRenderEnabled) + mOffscreenRenderEnabled = deferredBin && (deferredBin->getTargetChainLength() > 0); + if (mOffscreenRenderEnabled) { rpm->removeManager(this); - setRenderOrder( prePassBin->getRenderOrder() + 0.011f ); + setRenderOrder(deferredBin->getRenderOrder() + 0.011f); rpm->addManager(this); } diff --git a/Engine/source/scene/reflectionManager.cpp b/Engine/source/scene/reflectionManager.cpp index 5eb3a93d7..ac1b03021 100644 --- a/Engine/source/scene/reflectionManager.cpp +++ b/Engine/source/scene/reflectionManager.cpp @@ -282,18 +282,10 @@ GFXTextureObject* ReflectionManager::getRefractTex( bool forceUpdate ) GFXFormat targetFormat = target->getFormat(); const Point2I &targetSize = target->getSize(); - U32 desWidth, desHeight; // D3D11 needs to be the same size as the active target - if (GFX->getAdapterType() == Direct3D11) - { - desWidth = targetSize.x; - desHeight = targetSize.y; - } - else - { - desWidth = mFloor((F32)targetSize.x * smRefractTexScale); - desHeight = mFloor((F32)targetSize.y * smRefractTexScale); - } + U32 desWidth = targetSize.x; + U32 desHeight = targetSize.y; + if ( mRefractTex.isNull() || mRefractTex->getWidth() != desWidth || diff --git a/Engine/source/shaderGen/GLSL/accuFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/accuFeatureGLSL.cpp index aa2eda41d..7d172179e 100644 --- a/Engine/source/shaderGen/GLSL/accuFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/accuFeatureGLSL.cpp @@ -37,7 +37,6 @@ void AccuTexFeatGLSL::processVert(Vector &componentList, MultiLine *meta = new MultiLine; getOutTexCoord( "texCoord", "vec2", - true, false, meta, componentList ); @@ -130,8 +129,8 @@ void AccuTexFeatGLSL::processPix(Vector &componentList, accuSpecular->constSortPos = cspPotentialPrimitive; } - Var *inTex = getInTexCoord( "texCoord", "vec2", true, componentList ); - Var *accuVec = getInTexCoord( "accuVec", "vec3", true, componentList ); + Var *inTex = getInTexCoord( "texCoord", "vec2", componentList ); + Var *accuVec = getInTexCoord( "accuVec", "vec3", componentList ); Var *bumpNorm = (Var *)LangElement::find( "bumpSample" ); if( bumpNorm == NULL ) { bumpNorm = (Var *)LangElement::find( "bumpNormal" ); @@ -232,7 +231,6 @@ Var* AccuTexFeatGLSL::addOutAccuVec(Vector &componentList, Mul outAccuVec->setName( "accuVec" ); outAccuVec->setStructName( "OUT" ); outAccuVec->setType( "float3" ); - outAccuVec->mapsToSampler = false; getAccuVec( meta, outAccuVec ); } diff --git a/Engine/source/shaderGen/GLSL/bumpGLSL.cpp b/Engine/source/shaderGen/GLSL/bumpGLSL.cpp index 4706e96c7..0d14c84b3 100644 --- a/Engine/source/shaderGen/GLSL/bumpGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/bumpGLSL.cpp @@ -42,7 +42,6 @@ void BumpFeatGLSL::processVert( Vector &componentList, // Output the texture coord. getOutTexCoord( "texCoord", "vec2", - true, useTexAnim, meta, componentList ); @@ -64,7 +63,7 @@ void BumpFeatGLSL::processPix( Vector &componentList, output = meta; // Get the texture coord. - Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "vec2", componentList ); // Sample the bumpmap. Var *bumpMap = getNormalMapTex(); @@ -156,7 +155,7 @@ void BumpFeatGLSL::processPix( Vector &componentList, bumpMap->sampler = true; bumpMap->constNum = Var::getTexUnitNum(); - texCoord = getInTexCoord( "detCoord", "vec2", true, componentList ); + texCoord = getInTexCoord( "detCoord", "vec2", componentList ); texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord ); Var *detailBump = new Var; @@ -267,7 +266,6 @@ void ParallaxFeatGLSL::processVert( Vector &componentList, // Add the texture coords. getOutTexCoord( "texCoord", "vec2", - true, fd.features[MFT_TexAnim], meta, componentList ); @@ -312,7 +310,7 @@ void ParallaxFeatGLSL::processPix( Vector &componentList, MultiLine *meta = new MultiLine; // Order matters... get this first! - Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "vec2", componentList ); ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); @@ -408,7 +406,6 @@ void NormalsOutFeatGLSL::processVert( Vector &componentList, outNormal->setName( "wsNormal" ); outNormal->setStructName( "OUT" ); outNormal->setType( "vec3" ); - outNormal->mapsToSampler = false; // Find the incoming vertex normal. Var *inNormal = (Var*)LangElement::find( "normal" ); diff --git a/Engine/source/shaderGen/GLSL/depthGLSL.cpp b/Engine/source/shaderGen/GLSL/depthGLSL.cpp index f1e4b4d00..55ad964ef 100644 --- a/Engine/source/shaderGen/GLSL/depthGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/depthGLSL.cpp @@ -67,7 +67,6 @@ void EyeSpaceDepthOutGLSL::processPix( Vector &componentList, wsEyeVec->setName( "wsEyeVec" ); wsEyeVec->setStructName( "IN" ); wsEyeVec->setType( "float4" ); - wsEyeVec->mapsToSampler = false; wsEyeVec->uniform = false; // get shader constants @@ -153,7 +152,6 @@ void DepthOutGLSL::processPix( Vector &componentList, depthVar->setName( "depth" ); depthVar->setStructName( "IN" ); depthVar->setType( "float" ); - depthVar->mapsToSampler = false; depthVar->uniform = false; /* diff --git a/Engine/source/shaderGen/GLSL/pixSpecularGLSL.cpp b/Engine/source/shaderGen/GLSL/pixSpecularGLSL.cpp index 192641775..262efd451 100644 --- a/Engine/source/shaderGen/GLSL/pixSpecularGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/pixSpecularGLSL.cpp @@ -118,7 +118,6 @@ void SpecularMapGLSL::processVert(Vector &componentList, const // Add the texture coords. getOutTexCoord("texCoord", "vec2", - true, fd.features[MFT_TexAnim], meta, componentList); @@ -129,7 +128,7 @@ void SpecularMapGLSL::processVert(Vector &componentList, const void SpecularMapGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // Get the texture coord. - Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "vec2", componentList ); // create texture var Var *specularMap = new Var; diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index ee3b743c0..e66a16252 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -333,7 +333,6 @@ Var* ShaderFeatureGLSL::getOutViewToTangent( Vector &component Var* ShaderFeatureGLSL::getOutTexCoord( const char *name, const char *type, - bool mapsToSampler, bool useTexAnim, MultiLine *meta, Vector &componentList ) @@ -351,7 +350,6 @@ Var* ShaderFeatureGLSL::getOutTexCoord( const char *name, texCoord->setName( outTexName ); texCoord->setStructName( "OUT" ); texCoord->setType( type ); - texCoord->mapsToSampler = mapsToSampler; if( useTexAnim ) { @@ -386,7 +384,6 @@ Var* ShaderFeatureGLSL::getOutTexCoord( const char *name, Var* ShaderFeatureGLSL::getInTexCoord( const char *name, const char *type, - bool mapsToSampler, Vector &componentList ) { Var* texCoord = (Var*)LangElement::find( name ); @@ -397,7 +394,6 @@ Var* ShaderFeatureGLSL::getInTexCoord( const char *name, texCoord->setName( name ); texCoord->setStructName( "IN" ); texCoord->setType( type ); - texCoord->mapsToSampler = mapsToSampler; } AssertFatal( dStrcmp( type, (const char*)texCoord->type ) == 0, @@ -447,7 +443,6 @@ Var* ShaderFeatureGLSL::addOutVpos( MultiLine *meta, outVpos->setName( "outVpos" ); outVpos->setStructName( "OUT" ); outVpos->setType( "vec4" ); - outVpos->mapsToSampler = false; Var *outPosition = (Var*) LangElement::find( "gl_Position" ); AssertFatal( outPosition, "ShaderFeatureGLSL::addOutVpos - Didn't find the output position." ); @@ -725,7 +720,6 @@ Var* ShaderFeatureGLSL::addOutWsPosition( Vector &componentLis outWsPosition->setName( "outWsPosition" ); outWsPosition->setStructName( "OUT" ); outWsPosition->setType( "vec3" ); - outWsPosition->mapsToSampler = false; getWsPosition( componentList, useInstancing, meta, outWsPosition ); } @@ -797,7 +791,6 @@ Var* ShaderFeatureGLSL::addOutDetailTexCoord( Vector &compon outTex->setName( "detCoord" ); outTex->setStructName( "OUT" ); outTex->setType( "vec2" ); - outTex->mapsToSampler = true; if ( useTexAnim ) { @@ -841,7 +834,6 @@ void DiffuseMapFeatGLSL::processVert( Vector &componentList, MultiLine *meta = new MultiLine; getOutTexCoord( "texCoord", "vec2", - true, fd.features[MFT_TexAnim], meta, componentList ); @@ -857,7 +849,7 @@ void DiffuseMapFeatGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // grab connector texcoord register - Var *inTex = getInTexCoord( "texCoord", "vec2", true, componentList ); + Var *inTex = getInTexCoord( "texCoord", "vec2", componentList ); //determine output target ShaderFeature::OutputTarget targ = ShaderFeature::DefaultTarget; @@ -1023,7 +1015,6 @@ void OverlayTexFeatGLSL::processVert( Vector &componentList, outTex->setName( "outTexCoord2" ); outTex->setStructName( "OUT" ); outTex->setType( "vec2" ); - outTex->mapsToSampler = true; if( fd.features[MFT_TexAnim] ) { @@ -1058,7 +1049,6 @@ void OverlayTexFeatGLSL::processPix( Vector &componentList, inTex->setName( "texCoord2" ); inTex->setStructName( "IN" ); inTex->setType( "vec2" ); - inTex->mapsToSampler = true; // create texture var Var *diffuseMap = new Var; @@ -1219,7 +1209,6 @@ void LightmapFeatGLSL::processVert( Vector &componentList, outTex->setName( "texCoord2" ); outTex->setStructName( "OUT" ); outTex->setType( "vec2" ); - outTex->mapsToSampler = true; // setup language elements to output incoming tex coords to output output = new GenOp( " @ = @;\r\n", outTex, inTex ); @@ -1234,7 +1223,6 @@ void LightmapFeatGLSL::processPix( Vector &componentList, inTex->setName( "texCoord2" ); inTex->setStructName( "IN" ); inTex->setType( "vec2" ); - inTex->mapsToSampler = true; // create texture var Var *lightMap = new Var; @@ -1343,7 +1331,6 @@ void TonemapFeatGLSL::processVert( Vector &componentList, outTex2->setName( "texCoord2" ); outTex2->setStructName( "OUT" ); outTex2->setType( "vec2" ); - outTex2->mapsToSampler = true; output = new GenOp( " @ = @;\r\n", outTex2, inTex2 ); } @@ -1359,7 +1346,6 @@ void TonemapFeatGLSL::processPix( Vector &componentList, inTex2->setName( "texCoord2" ); inTex2->setStructName( "IN" ); inTex2->setType( "vec2" ); - inTex2->mapsToSampler = true; // create texture var Var *toneMap = new Var; @@ -1596,7 +1582,7 @@ void DetailFeatGLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // Get the detail texture coord. - Var *inTex = getInTexCoord( "detCoord", "vec2", true, componentList ); + Var *inTex = getInTexCoord( "detCoord", "vec2", componentList ); // create texture var Var *detailMap = new Var; @@ -1715,7 +1701,6 @@ void ReflectCubeFeatGLSL::processVert( Vector &componentList, outTex->setName( "texCoord" ); outTex->setStructName( "OUT" ); outTex->setType( "vec2" ); - outTex->mapsToSampler = true; // setup language elements to output incoming tex coords to output meta->addStatement( new GenOp( " @ = @;\r\n", outTex, inTex ) ); @@ -1771,7 +1756,6 @@ void ReflectCubeFeatGLSL::processVert( Vector &componentList, reflectVec->setName( "reflectVec" ); reflectVec->setStructName( "OUT" ); reflectVec->setType( "vec3" ); - reflectVec->mapsToSampler = true; meta->addStatement( new GenOp( " @ = reflect(@, @);\r\n", reflectVec, eyeToVert, cubeNormal ) ); @@ -1794,7 +1778,7 @@ void ReflectCubeFeatGLSL::processPix( Vector &componentList, fd.materialFeatures[MFT_NormalMap] ) { // grab connector texcoord register - Var *inTex = getInTexCoord( "texCoord", "vec2", true, componentList ); + Var *inTex = getInTexCoord( "texCoord", "vec2", componentList ); // create texture var Var *newMap = new Var; @@ -1833,7 +1817,6 @@ void ReflectCubeFeatGLSL::processPix( Vector &componentList, reflectVec->setName( "reflectVec" ); reflectVec->setStructName( "IN" ); reflectVec->setType( "vec3" ); - reflectVec->mapsToSampler = true; // create cubemap var Var *cubeMap = new Var; @@ -2007,7 +1990,6 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, outNormal->setName( "wsNormal" ); outNormal->setStructName( "OUT" ); outNormal->setType( "vec3" ); - outNormal->mapsToSampler = false; // Transform the normal to world space. meta->addStatement( new GenOp( " @ = normalize( @ - @.xyz );\r\n", outNormal, eyePos, inPosition ) ); @@ -2039,7 +2021,6 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, outNormal->setName( "wsNormal" ); outNormal->setStructName( "OUT" ); outNormal->setType( "vec3" ); - outNormal->mapsToSampler = false; // Get the transform to world space. Var *objTrans = getObjTrans( componentList, fd.features[MFT_UseInstancing], meta ); @@ -2228,7 +2209,6 @@ void FogFeatGLSL::processVert( Vector &componentList, fogAmount->setName( "fogAmount" ); fogAmount->setStructName( "OUT" ); fogAmount->setType( "float" ); - fogAmount->mapsToSampler = false; meta->addStatement( new GenOp( " @ = saturate( computeSceneFog( @, @, @.r, @.g, @.b ) );\r\n", fogAmount, eyePos, wsPosition, fogData, fogData, fogData ) ); @@ -2368,7 +2348,7 @@ void VisibilityFeatGLSL::processPix( Vector &componentList, // Get the visibility constant. Var *visibility = NULL; if ( fd.features[ MFT_UseInstancing ] ) - visibility = getInTexCoord( "visibility", "float", false, componentList ); + visibility = getInTexCoord( "visibility", "float", componentList ); else { visibility = (Var*)LangElement::find( "visibility" ); diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h index f890ec046..057be5191 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h @@ -39,7 +39,6 @@ public: /// Var* getOutTexCoord( const char *name, const char *type, - bool mapsToSampler, bool useTexAnim, MultiLine *meta, Vector &componentList ); @@ -48,7 +47,6 @@ public: /// to the input connector if it doesn't exist. static Var* getInTexCoord( const char *name, const char *type, - bool mapsToSampler, Vector &componentList ); static Var* getInColor( const char *name, diff --git a/Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp index ca1ee2702..3c0ec061f 100644 --- a/Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp @@ -37,7 +37,6 @@ void AccuTexFeatHLSL::processVert( Vector &componentList, MultiLine *meta = new MultiLine; getOutTexCoord( "texCoord", "float2", - true, false, meta, componentList ); @@ -65,10 +64,7 @@ void AccuTexFeatHLSL::processPix( Vector &componentList, // accu map Var *accuMap = new Var; - if (mIsDirect3D11) - accuMap->setType("SamplerState"); - else - accuMap->setType("sampler2D"); + accuMap->setType("SamplerState"); accuMap->setName( "accuMap" ); accuMap->uniform = true; @@ -139,8 +135,8 @@ void AccuTexFeatHLSL::processPix( Vector &componentList, accuSpecular->constSortPos = cspPotentialPrimitive; } - Var *inTex = getInTexCoord( "texCoord", "float2", true, componentList ); - Var *accuVec = getInTexCoord( "accuVec", "float3", true, componentList ); + Var *inTex = getInTexCoord( "texCoord", "float2", componentList ); + Var *accuVec = getInTexCoord( "accuVec", "float3", componentList ); Var *bumpNorm = (Var *)LangElement::find( "bumpSample" ); if( bumpNorm == NULL ) { @@ -150,18 +146,14 @@ void AccuTexFeatHLSL::processPix( Vector &componentList, } // get the accu pixel color - if (mIsDirect3D11) - { - Var *accuMapTex = new Var; - accuMapTex->setType("Texture2D"); - accuMapTex->setName("accuMapTex"); - accuMapTex->uniform = true; - accuMapTex->texture = true; - accuMapTex->constNum = accuMap->constNum; - meta->addStatement(new GenOp(" @ = @.Sample(@, @ * @);\r\n", colorAccuDecl, accuMapTex, accuMap, inTex, accuScale)); - } - else - meta->addStatement(new GenOp(" @ = tex2D(@, @ * @);\r\n", colorAccuDecl, accuMap, inTex, accuScale)); + + Var *accuMapTex = new Var; + accuMapTex->setType("Texture2D"); + accuMapTex->setName("accuMapTex"); + accuMapTex->uniform = true; + accuMapTex->texture = true; + accuMapTex->constNum = accuMap->constNum; + meta->addStatement(new GenOp(" @ = @.Sample(@, @ * @);\r\n", colorAccuDecl, accuMapTex, accuMap, inTex, accuScale)); // scale up normals meta->addStatement( new GenOp( " @.xyz = @.xyz * 2.0 - 0.5;\r\n", bumpNorm, bumpNorm ) ); @@ -250,7 +242,6 @@ Var* AccuTexFeatHLSL::addOutAccuVec( Vector &componentList, Mu outAccuVec->setName( "accuVec" ); outAccuVec->setStructName( "OUT" ); outAccuVec->setType( "float3" ); - outAccuVec->mapsToSampler = false; getAccuVec( meta, outAccuVec ); } diff --git a/Engine/source/shaderGen/HLSL/bumpHLSL.cpp b/Engine/source/shaderGen/HLSL/bumpHLSL.cpp index 646d434d6..c3cd97c94 100644 --- a/Engine/source/shaderGen/HLSL/bumpHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/bumpHLSL.cpp @@ -42,7 +42,6 @@ void BumpFeatHLSL::processVert( Vector &componentList, // Output the texture coord. getOutTexCoord( "texCoord", "float2", - true, useTexAnim, meta, componentList ); @@ -64,18 +63,14 @@ void BumpFeatHLSL::processPix( Vector &componentList, output = meta; // Get the texture coord. - Var *texCoord = getInTexCoord( "texCoord", "float2", true, componentList ); + Var *texCoord = getInTexCoord("texCoord", "float2", componentList); // Sample the bumpmap. Var *bumpMap = getNormalMapTex(); LangElement *texOp = NULL; //if it's D3D11 let's create the texture object - Var* bumpMapTex = NULL; - if (mIsDirect3D11) - { - bumpMapTex = (Var*)LangElement::find("bumpMapTex"); - } + Var* bumpMapTex = (Var*)LangElement::find("bumpMapTex"); // Handle atlased textures // http://www.infinity-universe.com/Infinity/index.php?option=com_content&task=view&id=65&Itemid=47 @@ -134,25 +129,11 @@ void BumpFeatHLSL::processPix( Vector &componentList, // Add a newline meta->addStatement( new GenOp( "\r\n" ) ); - if (mIsDirect3D11) - { - texOp = new GenOp("@.SampleLevel(@, @, mipLod_bump)", bumpMapTex, bumpMap, texCoord); - } - else if (is_sm3) - { - texOp = new GenOp("tex2Dlod(@, float4(@, 0.0, mipLod_bump))", bumpMap, texCoord); - } - else - { - texOp = new GenOp("tex2D(@, @)", bumpMap, texCoord); - } + texOp = new GenOp("@.SampleLevel(@, @, mipLod_bump)", bumpMapTex, bumpMap, texCoord); } else { - if (mIsDirect3D11) - texOp = new GenOp("@.Sample(@, @)", bumpMapTex, bumpMap, texCoord); - else - texOp = new GenOp("tex2D(@, @)", bumpMap, texCoord); + texOp = new GenOp("@.Sample(@, @)", bumpMapTex, bumpMap, texCoord); } Var *bumpNorm = new Var( "bumpNormal", "float4" ); @@ -164,32 +145,22 @@ void BumpFeatHLSL::processPix( Vector &componentList, if ( fd.features.hasFeature( MFT_DetailNormalMap ) ) { bumpMap = new Var; - bumpMap->setType( "sampler2D" ); + bumpMap->setType( "SamplerState" ); bumpMap->setName( "detailBumpMap" ); bumpMap->uniform = true; bumpMap->sampler = true; bumpMap->constNum = Var::getTexUnitNum(); - Var* detailBumpTex = NULL; - if (mIsDirect3D11) - { - bumpMap->setType("SamplerState"); - detailBumpTex = new Var; - detailBumpTex->setName("detailBumpTex"); - detailBumpTex->setType("Texture2D"); - detailBumpTex->uniform = true; - detailBumpTex->texture = true; - detailBumpTex->constNum = bumpMap->constNum; - } - else - bumpMap->setType("sampler2D"); + Var* detailBumpTex = new Var; + detailBumpTex->setName("detailBumpTex"); + detailBumpTex->setType("Texture2D"); + detailBumpTex->uniform = true; + detailBumpTex->texture = true; + detailBumpTex->constNum = bumpMap->constNum; - texCoord = getInTexCoord( "detCoord", "float2", true, componentList ); + texCoord = getInTexCoord( "detCoord", "float2", componentList ); - if (mIsDirect3D11) - texOp = new GenOp("@.Sample(@, @)", detailBumpTex, bumpMap, texCoord); - else - texOp = new GenOp("tex2D(@, @)", bumpMap, texCoord); + texOp = new GenOp("@.Sample(@, @)", detailBumpTex, bumpMap, texCoord); Var *detailBump = new Var; detailBump->setName( "detailBump" ); @@ -299,7 +270,6 @@ void ParallaxFeatHLSL::processVert( Vector &componentList, // Add the texture coords. getOutTexCoord( "texCoord", "float2", - true, fd.features[MFT_TexAnim], meta, componentList ); @@ -344,7 +314,7 @@ void ParallaxFeatHLSL::processPix( Vector &componentList, MultiLine *meta = new MultiLine; // Order matters... get this first! - Var *texCoord = getInTexCoord( "texCoord", "float2", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "float2", componentList ); ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); @@ -374,21 +344,13 @@ void ParallaxFeatHLSL::processPix( Vector &componentList, // Call the library function to do the rest. if (fd.features.hasFeature(MFT_IsDXTnm, getProcessIndex())) { - if (mIsDirect3D11) - meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @, @.xy, @, @ );\r\n", + meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @, @.xy, @, @ );\r\n", texCoord, bumpMapTexture, normalMap, texCoord, negViewTS, parallaxInfo)); - else - meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @.xy, @, @ );\r\n", - texCoord, normalMap, texCoord, negViewTS, parallaxInfo)); } else { - if (mIsDirect3D11) - meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @, @.xy, @, @ );\r\n", + meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @, @.xy, @, @ );\r\n", texCoord, bumpMapTexture, normalMap, texCoord, negViewTS, parallaxInfo)); - else - meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @.xy, @, @ );\r\n", - texCoord, normalMap, texCoord, negViewTS, parallaxInfo)); } // TODO: Fix second UV maybe? @@ -449,7 +411,6 @@ void NormalsOutFeatHLSL::processVert( Vector &componentList, outNormal->setName( "wsNormal" ); outNormal->setStructName( "OUT" ); outNormal->setType( "float3" ); - outNormal->mapsToSampler = false; // Find the incoming vertex normal. Var *inNormal = (Var*)LangElement::find( "normal" ); diff --git a/Engine/source/shaderGen/HLSL/depthHLSL.cpp b/Engine/source/shaderGen/HLSL/depthHLSL.cpp index 382245311..45d002c56 100644 --- a/Engine/source/shaderGen/HLSL/depthHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/depthHLSL.cpp @@ -67,7 +67,6 @@ void EyeSpaceDepthOutHLSL::processPix( Vector &componentList, wsEyeVec->setName( "wsEyeVec" ); wsEyeVec->setStructName( "IN" ); wsEyeVec->setType( "float4" ); - wsEyeVec->mapsToSampler = false; wsEyeVec->uniform = false; // get shader constants @@ -153,7 +152,6 @@ void DepthOutHLSL::processPix( Vector &componentList, depthVar->setName( "depth" ); depthVar->setStructName( "IN" ); depthVar->setType( "float" ); - depthVar->mapsToSampler = false; depthVar->uniform = false; /* diff --git a/Engine/source/shaderGen/HLSL/paraboloidHLSL.cpp b/Engine/source/shaderGen/HLSL/paraboloidHLSL.cpp index 105e3c100..2227ca933 100644 --- a/Engine/source/shaderGen/HLSL/paraboloidHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/paraboloidHLSL.cpp @@ -46,9 +46,7 @@ void ParaboloidVertTransformHLSL::processVert( Vector &compon ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); // Grab connector out position. - RegisterType type = RT_POSITION; - if (mIsDirect3D11) - type = RT_SVPOSITION; + RegisterType type = RT_SVPOSITION; Var *outPosition = connectComp->getElement(type); outPosition->setName("hpos"); diff --git a/Engine/source/shaderGen/HLSL/pixSpecularHLSL.cpp b/Engine/source/shaderGen/HLSL/pixSpecularHLSL.cpp index 3a794a394..021434447 100644 --- a/Engine/source/shaderGen/HLSL/pixSpecularHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/pixSpecularHLSL.cpp @@ -122,7 +122,6 @@ void SpecularMapHLSL::processVert(Vector &componentList, const // Add the texture coords. getOutTexCoord("texCoord", "float2", - true, fd.features[MFT_TexAnim], meta, componentList); @@ -133,31 +132,22 @@ void SpecularMapHLSL::processVert(Vector &componentList, const void SpecularMapHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // Get the texture coord. - Var *texCoord = getInTexCoord( "texCoord", "float2", true, componentList ); + Var *texCoord = getInTexCoord("texCoord", "float2", componentList); // create texture var Var *specularMap = new Var; - specularMap->setType( "sampler2D" ); + specularMap->setType( "SamplerState" ); specularMap->setName( "specularMap" ); specularMap->uniform = true; specularMap->sampler = true; specularMap->constNum = Var::getTexUnitNum(); - Var *specularMapTex = NULL; - if (mIsDirect3D11) - { - specularMap->setType("SamplerState"); - specularMapTex = new Var; - specularMapTex->setName("specularMapTex"); - specularMapTex->setType("Texture2D"); - specularMapTex->uniform = true; - specularMapTex->texture = true; - specularMapTex->constNum = specularMap->constNum; - } - else - { - specularMap->setType("sampler2D"); - } + Var *specularMapTex = new Var; + specularMapTex->setName("specularMapTex"); + specularMapTex->setType("Texture2D"); + specularMapTex->uniform = true; + specularMapTex->texture = true; + specularMapTex->constNum = specularMap->constNum; LangElement *texOp = NULL; diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index f997f2919..894e3bdfa 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -174,7 +174,6 @@ LangElement *ShaderFeatureHLSL::expandNormalMap( LangElement *sampleNormalOp, ShaderFeatureHLSL::ShaderFeatureHLSL() { output = NULL; - mIsDirect3D11 = GFX->getAdapterType() == Direct3D11; } Var * ShaderFeatureHLSL::getVertTexCoord( const String &name ) @@ -334,7 +333,6 @@ Var* ShaderFeatureHLSL::getOutViewToTangent( Vector &component Var* ShaderFeatureHLSL::getOutTexCoord( const char *name, const char *type, - bool mapsToSampler, bool useTexAnim, MultiLine *meta, Vector &componentList ) @@ -352,7 +350,6 @@ Var* ShaderFeatureHLSL::getOutTexCoord( const char *name, texCoord->setName( outTexName ); texCoord->setStructName( "OUT" ); texCoord->setType( type ); - texCoord->mapsToSampler = mapsToSampler; if ( useTexAnim ) { @@ -387,7 +384,6 @@ Var* ShaderFeatureHLSL::getOutTexCoord( const char *name, Var* ShaderFeatureHLSL::getInTexCoord( const char *name, const char *type, - bool mapsToSampler, Vector &componentList ) { Var* texCoord = (Var*)LangElement::find( name ); @@ -398,7 +394,6 @@ Var* ShaderFeatureHLSL::getInTexCoord( const char *name, texCoord->setName( name ); texCoord->setStructName( "IN" ); texCoord->setType( type ); - texCoord->mapsToSampler = mapsToSampler; } AssertFatal( dStrcmp( type, (const char*)texCoord->type ) == 0, @@ -446,7 +441,6 @@ Var* ShaderFeatureHLSL::addOutVpos( MultiLine *meta, outVpos->setName( "outVpos" ); outVpos->setStructName( "OUT" ); outVpos->setType( "float4" ); - outVpos->mapsToSampler = false; Var *outPosition = (Var*) LangElement::find( "hpos" ); AssertFatal( outPosition, "ShaderFeatureHLSL::addOutVpos - Didn't find the output position." ); @@ -464,36 +458,13 @@ Var* ShaderFeatureHLSL::getInVpos( MultiLine *meta, if ( inVpos ) return inVpos; - ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); + ShaderConnector *connectComp = dynamic_cast(componentList[C_CONNECTOR]); - F32 pixelShaderVer = GFX->getPixelShaderVersion(); - - if ( pixelShaderVer >= 4.0f ) - { - inVpos = connectComp->getElement( RT_SVPOSITION ); - inVpos->setName( "vpos" ); - inVpos->setStructName( "IN" ); - inVpos->setType( "float4" ); - return inVpos; - } - else if ( pixelShaderVer >= 3.0f ) - { - inVpos = connectComp->getElement( RT_VPOS ); - inVpos->setName( "vpos" ); - inVpos->setStructName( "IN" ); - inVpos->setType( "float2" ); - return inVpos; - } - - inVpos = connectComp->getElement( RT_TEXCOORD ); - inVpos->setName( "inVpos" ); + inVpos = connectComp->getElement( RT_SVPOSITION ); + inVpos->setName( "vpos" ); inVpos->setStructName( "IN" ); inVpos->setType( "float4" ); - - Var *vpos = new Var( "vpos", "float2" ); - meta->addStatement( new GenOp( " @ = @.xy / @.w;\r\n", new DecOp( vpos ), inVpos, inVpos ) ); - - return vpos; + return inVpos; } Var* ShaderFeatureHLSL::getInWorldToTangent( Vector &componentList ) @@ -532,26 +503,18 @@ Var* ShaderFeatureHLSL::getNormalMapTex() if (!normalMap) { normalMap = new Var; - normalMap->setType("sampler2D"); + normalMap->setType("SamplerState"); normalMap->setName("bumpMap"); normalMap->uniform = true; normalMap->sampler = true; normalMap->constNum = Var::getTexUnitNum(); - // D3D11 - Var* normalMapTex = NULL; - if (GFX->getAdapterType() == Direct3D11) - { - normalMap->setType("SamplerState"); - normalMapTex = new Var; - normalMapTex->setName("bumpMapTex"); - normalMapTex->setType("Texture2D"); - normalMapTex->uniform = true; - normalMapTex->texture = true; - normalMapTex->constNum = normalMap->constNum; - } - - + Var* normalMapTex = new Var; + normalMapTex->setName("bumpMapTex"); + normalMapTex->setType("Texture2D"); + normalMapTex->uniform = true; + normalMapTex->texture = true; + normalMapTex->constNum = normalMap->constNum; } return normalMap; @@ -749,7 +712,6 @@ Var* ShaderFeatureHLSL::addOutWsPosition( Vector &componentLis outWsPosition->setName( "outWsPosition" ); outWsPosition->setStructName( "OUT" ); outWsPosition->setType( "float3" ); - outWsPosition->mapsToSampler = false; getWsPosition( componentList, useInstancing, meta, outWsPosition ); } @@ -822,7 +784,6 @@ Var* ShaderFeatureHLSL::addOutDetailTexCoord( Vector &compon outTex->setName( "detCoord" ); outTex->setStructName( "OUT" ); outTex->setType( "float2" ); - outTex->mapsToSampler = true; if ( useTexAnim ) { @@ -864,7 +825,6 @@ void DiffuseMapFeatHLSL::processVert( Vector &componentList, MultiLine *meta = new MultiLine; getOutTexCoord( "texCoord", "float2", - true, fd.features[MFT_TexAnim], meta, componentList ); @@ -880,7 +840,7 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // grab connector texcoord register - Var *inTex = getInTexCoord( "texCoord", "float2", true, componentList ); + Var *inTex = getInTexCoord( "texCoord", "float2", componentList ); //determine output target ShaderFeature::OutputTarget targ = ShaderFeature::DefaultTarget; @@ -889,24 +849,18 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, // create texture var Var *diffuseMap = new Var; - diffuseMap->setType( "sampler2D" ); + diffuseMap->setType( "SamplerState" ); diffuseMap->setName( "diffuseMap" ); diffuseMap->uniform = true; diffuseMap->sampler = true; diffuseMap->constNum = Var::getTexUnitNum(); // used as texture unit num here - Var* diffuseMapTex = NULL; - if (mIsDirect3D11) - { - diffuseMap->setType("SamplerState"); - - diffuseMapTex = new Var; - diffuseMapTex->setName("diffuseMapTex"); - diffuseMapTex->setType("Texture2D"); - diffuseMapTex->uniform = true; - diffuseMapTex->texture = true; - diffuseMapTex->constNum = diffuseMap->constNum; - } + Var* diffuseMapTex = new Var; + diffuseMapTex->setName("diffuseMapTex"); + diffuseMapTex->setType("Texture2D"); + diffuseMapTex->uniform = true; + diffuseMapTex->texture = true; + diffuseMapTex->constNum = diffuseMap->constNum; // create sample color Var *diffColor = new Var; @@ -919,10 +873,7 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, if ( fd.features[MFT_CubeMap] ) { - if (mIsDirect3D11) - meta->addStatement(new GenOp(" @ = @.Sample(@, @);\r\n", colorDecl, diffuseMapTex, diffuseMap, inTex)); - else - meta->addStatement(new GenOp(" @ = tex2D(@, @);\r\n", colorDecl, diffuseMap, inTex)); + meta->addStatement(new GenOp(" @ = @.Sample(@, @);\r\n", colorDecl, diffuseMapTex, diffuseMap, inTex)); if (!fd.features[MFT_Imposter]) meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); @@ -940,14 +891,14 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, LangElement *atDecl = new DecOp(atlasedTex); // Parameters of the texture atlas - Var *atParams = new Var; + Var *atParams = new Var; atParams->setType("float4"); atParams->setName("diffuseAtlasParams"); atParams->uniform = true; atParams->constSortPos = cspPotentialPrimitive; // Parameters of the texture (tile) this object is using in the atlas - Var *tileParams = new Var; + Var *tileParams = new Var; tileParams->setType("float4"); tileParams->setName("diffuseAtlasTileParams"); tileParams->uniform = true; @@ -998,21 +949,9 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, return; } #endif - if (mIsDirect3D11) - { - meta->addStatement(new GenOp(" @ = @.SampleLevel(@,@,mipLod);\r\n", - new DecOp(diffColor), diffuseMapTex, diffuseMap, inTex)); - } - else if(is_sm3) - { - meta->addStatement(new GenOp( " @ = tex2Dlod(@, float4(@, 0.0, mipLod));\r\n", - new DecOp(diffColor), diffuseMap, inTex)); - } - else - { - meta->addStatement(new GenOp( " @ = tex2D(@, @);\r\n", - new DecOp(diffColor), diffuseMap, inTex)); - } + meta->addStatement(new GenOp(" @ = @.SampleLevel(@,@,mipLod);\r\n", + new DecOp(diffColor), diffuseMapTex, diffuseMap, inTex)); + if (!fd.features[MFT_Imposter]) meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); @@ -1020,10 +959,7 @@ void DiffuseMapFeatHLSL::processPix( Vector &componentList, } else { - if (mIsDirect3D11) - meta->addStatement(new GenOp("@ = @.Sample(@, @);\r\n", colorDecl, diffuseMapTex, diffuseMap, inTex)); - else - meta->addStatement(new GenOp("@ = tex2D(@, @);\r\n", colorDecl, diffuseMap, inTex)); + meta->addStatement(new GenOp("@ = @.Sample(@, @);\r\n", colorDecl, diffuseMapTex, diffuseMap, inTex)); if (!fd.features[MFT_Imposter]) meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor)); @@ -1070,7 +1006,6 @@ void OverlayTexFeatHLSL::processVert( Vector &componentList, outTex->setName( "outTexCoord2" ); outTex->setStructName( "OUT" ); outTex->setType( "float2" ); - outTex->mapsToSampler = true; if( fd.features[MFT_TexAnim] ) { @@ -1105,33 +1040,23 @@ void OverlayTexFeatHLSL::processPix( Vector &componentList, inTex->setName( "texCoord2" ); inTex->setStructName( "IN" ); inTex->setType( "float2" ); - inTex->mapsToSampler = true; // create texture var Var *diffuseMap = new Var; - diffuseMap->setType( "sampler2D" ); + diffuseMap->setType( "SamplerState" ); diffuseMap->setName( "overlayMap" ); diffuseMap->uniform = true; diffuseMap->sampler = true; diffuseMap->constNum = Var::getTexUnitNum(); // used as texture unit num here - Var* diffuseMapTex = NULL; - if (mIsDirect3D11) - { - diffuseMap->setType("SamplerState"); - diffuseMapTex = new Var; - diffuseMapTex->setName("overlayMapTex"); - diffuseMapTex->setType("Texture2D"); - diffuseMapTex->uniform = true; - diffuseMapTex->texture = true; - diffuseMapTex->constNum = diffuseMap->constNum; - } + Var* diffuseMapTex = new Var; + diffuseMapTex->setName("overlayMapTex"); + diffuseMapTex->setType("Texture2D"); + diffuseMapTex->uniform = true; + diffuseMapTex->texture = true; + diffuseMapTex->constNum = diffuseMap->constNum; - LangElement *statement = NULL; - if (mIsDirect3D11) - statement = new GenOp("@.Sample(@, @)", diffuseMapTex, diffuseMap, inTex); - else - statement = new GenOp("tex2D(@, @)", diffuseMap, inTex); + LangElement *statement = new GenOp("@.Sample(@, @)", diffuseMapTex, diffuseMap, inTex); output = new GenOp( " @;\r\n", assignColor( statement, Material::LerpAlpha ) ); } @@ -1283,7 +1208,6 @@ void LightmapFeatHLSL::processVert( Vector &componentList, outTex->setName( "texCoord2" ); outTex->setStructName( "OUT" ); outTex->setType( "float2" ); - outTex->mapsToSampler = true; // setup language elements to output incoming tex coords to output output = new GenOp( " @ = @;\r\n", outTex, inTex ); @@ -1298,27 +1222,21 @@ void LightmapFeatHLSL::processPix( Vector &componentList, inTex->setName( "texCoord2" ); inTex->setStructName( "IN" ); inTex->setType( "float2" ); - inTex->mapsToSampler = true; // create texture var Var *lightMap = new Var; - lightMap->setType( "sampler2D" ); + lightMap->setType( "SamplerState" ); lightMap->setName( "lightMap" ); lightMap->uniform = true; lightMap->sampler = true; lightMap->constNum = Var::getTexUnitNum(); // used as texture unit num here - Var *lightMapTex = NULL; - if (mIsDirect3D11) - { - lightMap->setType("SamplerState"); - lightMapTex->setName("lightMapTex"); - lightMapTex->setType("Texture2D"); - lightMapTex->uniform = true; - lightMapTex->texture = true; - lightMapTex->constNum = lightMap->constNum; - } - + Var *lightMapTex = new Var; + lightMapTex->setName("lightMapTex"); + lightMapTex->setType("Texture2D"); + lightMapTex->uniform = true; + lightMapTex->texture = true; + lightMapTex->constNum = lightMap->constNum; // argh, pixel specular should prob use this too if( fd.features[MFT_NormalMap] ) @@ -1328,10 +1246,8 @@ void LightmapFeatHLSL::processPix( Vector &componentList, lmColor->setType( "float4" ); LangElement *lmColorDecl = new DecOp( lmColor ); - if (mIsDirect3D11) - output = new GenOp(" @ = @.Sample(@, @);\r\n", lmColorDecl, lightMapTex, lightMap, inTex); - else - output = new GenOp(" @ = tex2D(@, @);\r\n", lmColorDecl, lightMap, inTex); + output = new GenOp(" @ = @.Sample(@, @);\r\n", lmColorDecl, lightMapTex, lightMap, inTex); + return; } @@ -1355,10 +1271,7 @@ void LightmapFeatHLSL::processPix( Vector &componentList, statement = new GenOp("float4(@, 1.0)", inColor); else { - if (mIsDirect3D11) - statement = new GenOp("@.Sample(@, @) + float4(@.rgb, 0.0)", lightMapTex, lightMap, inTex, inColor); - else - statement = new GenOp("tex2D(@, @) + float4(@.rgb, 0.0)", lightMap, inTex, inColor); + statement = new GenOp("@.Sample(@, @) + float4(@.rgb, 0.0)", lightMapTex, lightMap, inTex, inColor); } } } @@ -1366,10 +1279,7 @@ void LightmapFeatHLSL::processPix( Vector &componentList, // If we still don't have it... then just sample the lightmap. if (!statement) { - if (mIsDirect3D11) - statement = new GenOp("@.Sample(@, @)", lightMapTex, lightMap, inTex); - else - statement = new GenOp("tex2D(@, @)", lightMap, inTex); + statement = new GenOp("@.Sample(@, @)", lightMapTex, lightMap, inTex); } // Assign to proper render target @@ -1431,7 +1341,6 @@ void TonemapFeatHLSL::processVert( Vector &componentList, outTex2->setName( "texCoord2" ); outTex2->setStructName( "OUT" ); outTex2->setType( "float2" ); - outTex2->mapsToSampler = true; output = new GenOp( " @ = @;\r\n", outTex2, inTex2 ); } @@ -1447,27 +1356,21 @@ void TonemapFeatHLSL::processPix( Vector &componentList, inTex2->setName( "texCoord2" ); inTex2->setStructName( "IN" ); inTex2->setType( "float2" ); - inTex2->mapsToSampler = true; // create texture var Var *toneMap = new Var; - toneMap->setType( "sampler2D" ); + toneMap->setType( "SamplerState" ); toneMap->setName( "toneMap" ); toneMap->uniform = true; toneMap->sampler = true; toneMap->constNum = Var::getTexUnitNum(); // used as texture unit num here - Var *toneMapTex = NULL; - if (mIsDirect3D11) - { - toneMap->setType("SamplerState"); - toneMapTex = new Var; - toneMapTex->setName("toneMapTex"); - toneMapTex->setType("Texture2D"); - toneMapTex->uniform = true; - toneMapTex->texture = true; - toneMapTex->constNum = toneMap->constNum; - } + Var *toneMapTex = new Var; + toneMapTex->setName("toneMapTex"); + toneMapTex->setType("Texture2D"); + toneMapTex->uniform = true; + toneMapTex->texture = true; + toneMapTex->constNum = toneMap->constNum; MultiLine * meta = new MultiLine; @@ -1477,10 +1380,7 @@ void TonemapFeatHLSL::processPix( Vector &componentList, toneMapColor->setName( "toneMapColor" ); LangElement *toneMapColorDecl = new DecOp( toneMapColor ); - if (mIsDirect3D11) - meta->addStatement(new GenOp(" @ = @.Sample(@, @);\r\n", toneMapColorDecl, toneMapTex, toneMap, inTex2)); - else - meta->addStatement(new GenOp(" @ = tex2D(@, @);\r\n", toneMapColorDecl, toneMap, inTex2)); + meta->addStatement(new GenOp(" @ = @.Sample(@, @);\r\n", toneMapColorDecl, toneMapTex, toneMap, inTex2)); // We do a different calculation if there is a diffuse map or not Material::BlendOp blendOp = Material::Mul; @@ -1699,27 +1599,22 @@ void DetailFeatHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd ) { // Get the detail texture coord. - Var *inTex = getInTexCoord( "detCoord", "float2", true, componentList ); + Var *inTex = getInTexCoord( "detCoord", "float2", componentList ); // create texture var Var *detailMap = new Var; - detailMap->setType( "sampler2D" ); + detailMap->setType( "SamplerState" ); detailMap->setName( "detailMap" ); detailMap->uniform = true; detailMap->sampler = true; detailMap->constNum = Var::getTexUnitNum(); // used as texture unit num here - Var* detailMapTex = NULL; - if (mIsDirect3D11) - { - detailMap->setType("SamplerState"); - detailMapTex = new Var; - detailMapTex->setName("detailMapTex"); - detailMapTex->setType("Texture2D"); - detailMapTex->uniform = true; - detailMapTex->texture = true; - detailMapTex->constNum = detailMap->constNum; - } + Var* detailMapTex = new Var; + detailMapTex->setName("detailMapTex"); + detailMapTex->setType("Texture2D"); + detailMapTex->uniform = true; + detailMapTex->texture = true; + detailMapTex->constNum = detailMap->constNum; // We're doing the standard greyscale detail map // technique which can darken and lighten the @@ -1728,11 +1623,7 @@ void DetailFeatHLSL::processPix( Vector &componentList, // TODO: We could add a feature to toggle between this // and a simple multiplication with the detail map. - LangElement *statement = NULL; - if (mIsDirect3D11) - statement = new GenOp("( @.Sample(@, @) * 2.0 ) - 1.0", detailMapTex, detailMap, inTex); - else - statement = new GenOp("( tex2D(@, @) * 2.0 ) - 1.0", detailMap, inTex); + LangElement *statement = new GenOp("( @.Sample(@, @) * 2.0 ) - 1.0", detailMapTex, detailMap, inTex); if ( fd.features[MFT_isDeferred]) output = new GenOp( " @;\r\n", assignColor( statement, Material::Add, NULL, ShaderFeature::RenderTarget1 ) ); @@ -1789,11 +1680,7 @@ void VertPositionHLSL::processVert( Vector &componentList, // grab connector position ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); - Var *outPosition = NULL; - if (mIsDirect3D11) - outPosition = connectComp->getElement(RT_SVPOSITION); - else - outPosition = connectComp->getElement(RT_POSITION); + Var *outPosition = connectComp->getElement(RT_SVPOSITION); outPosition->setName( "hpos" ); outPosition->setStructName( "OUT" ); @@ -1811,14 +1698,11 @@ void VertPositionHLSL::processVert( Vector &componentList, void VertPositionHLSL::processPix( Vector &componentList, const MaterialFeatureData &fd) { - if (mIsDirect3D11) - { - // grab connector position - ShaderConnector *connectComp = dynamic_cast(componentList[C_CONNECTOR]); - Var *outPosition = connectComp->getElement(RT_SVPOSITION); - outPosition->setName("vpos"); - outPosition->setStructName("IN"); - } + // grab connector position + ShaderConnector *connectComp = dynamic_cast(componentList[C_CONNECTOR]); + Var *outPosition = connectComp->getElement(RT_SVPOSITION); + outPosition->setName("vpos"); + outPosition->setStructName("IN"); } @@ -1854,7 +1738,6 @@ void ReflectCubeFeatHLSL::processVert( Vector &componentList, outTex->setName( "texCoord" ); outTex->setStructName( "OUT" ); outTex->setType( "float2" ); - outTex->mapsToSampler = true; // setup language elements to output incoming tex coords to output meta->addStatement( new GenOp( " @ = @;\r\n", outTex, inTex ) ); @@ -1910,7 +1793,6 @@ void ReflectCubeFeatHLSL::processVert( Vector &componentList, reflectVec->setName( "reflectVec" ); reflectVec->setStructName( "OUT" ); reflectVec->setType( "float3" ); - reflectVec->mapsToSampler = true; meta->addStatement( new GenOp( " @ = reflect(@, @);\r\n", reflectVec, eyeToVert, cubeNormal ) ); @@ -1933,28 +1815,22 @@ void ReflectCubeFeatHLSL::processPix( Vector &componentList, fd.materialFeatures[MFT_NormalMap]) { // grab connector texcoord register - Var *inTex = getInTexCoord( "texCoord", "float2", true, componentList ); - + Var *inTex = getInTexCoord("texCoord", "float2", componentList); + // create texture var Var *newMap = new Var; - newMap->setType( "sampler2D" ); + newMap->setType( "SamplerState" ); newMap->setName( "glossMap" ); newMap->uniform = true; newMap->sampler = true; newMap->constNum = Var::getTexUnitNum(); // used as texture unit num here - Var* glowMapTex = NULL; - if (mIsDirect3D11) - { - newMap->setType("SamplerState"); - - glowMapTex = new Var; - glowMapTex->setName("glowMapTex"); - glowMapTex->setType("Texture2D"); - glowMapTex->uniform = true; - glowMapTex->texture = true; - glowMapTex->constNum = newMap->constNum; - } + Var* glowMapTex = new Var; + glowMapTex->setName("glowMapTex"); + glowMapTex->setType("Texture2D"); + glowMapTex->uniform = true; + glowMapTex->texture = true; + glowMapTex->constNum = newMap->constNum; // create sample color Var *color = new Var; @@ -1964,10 +1840,7 @@ void ReflectCubeFeatHLSL::processPix( Vector &componentList, glossColor = color; - if (mIsDirect3D11) - meta->addStatement(new GenOp(" @ = @.Sample( @, @ );\r\n", colorDecl, glowMapTex, newMap, inTex)); - else - meta->addStatement(new GenOp(" @ = tex2D( @, @ );\r\n", colorDecl, newMap, inTex)); + meta->addStatement(new GenOp(" @ = @.Sample( @, @ );\r\n", colorDecl, glowMapTex, newMap, inTex)); } } else @@ -1988,27 +1861,21 @@ void ReflectCubeFeatHLSL::processPix( Vector &componentList, reflectVec->setName( "reflectVec" ); reflectVec->setStructName( "IN" ); reflectVec->setType( "float3" ); - reflectVec->mapsToSampler = true; // create cubemap var Var *cubeMap = new Var; - cubeMap->setType( "samplerCUBE" ); + cubeMap->setType( "SamplerState" ); cubeMap->setName( "cubeMap" ); cubeMap->uniform = true; cubeMap->sampler = true; cubeMap->constNum = Var::getTexUnitNum(); // used as texture unit num here - Var* cubeMapTex = NULL; - if (mIsDirect3D11) - { - cubeMap->setType("SamplerState"); - cubeMapTex = new Var; - cubeMapTex->setName("cubeMapTex"); - cubeMapTex->setType("TextureCube"); // cubeMapTex->setType("TextureCube"); - cubeMapTex->uniform = true; - cubeMapTex->texture = true; - cubeMapTex->constNum = cubeMap->constNum; - } + Var* cubeMapTex = new Var; + cubeMapTex->setName("cubeMapTex"); + cubeMapTex->setType("TextureCube"); // cubeMapTex->setType("TextureCube"); + cubeMapTex->uniform = true; + cubeMapTex->texture = true; + cubeMapTex->constNum = cubeMap->constNum; // TODO: Restore the lighting attenuation here! Var *attn = NULL; @@ -2029,34 +1896,22 @@ void ReflectCubeFeatHLSL::processPix( Vector &componentList, if (fd.features[MFT_DeferredSpecMap]) { - if (mIsDirect3D11) - texCube = new GenOp("@.SampleLevel( @, @, @.a*5)", cubeMapTex, cubeMap, reflectVec, matinfo); - else - texCube = new GenOp("texCUBElod( @, float4(@, (@.a*5)) )", cubeMap, reflectVec, matinfo); + texCube = new GenOp("@.SampleLevel( @, @, @.a*5)", cubeMapTex, cubeMap, reflectVec, matinfo); } else { - if (mIsDirect3D11) - texCube = new GenOp("@.SampleLevel( @, @, (1.0-@.a)*6 )", cubeMapTex, cubeMap, reflectVec, matinfo); - else - texCube = new GenOp("texCUBElod( @, float4(@, ((1.0-@.a)*6)) )", cubeMap, reflectVec, matinfo); + texCube = new GenOp("@.SampleLevel( @, @, (1.0-@.a)*6 )", cubeMapTex, cubeMap, reflectVec, matinfo); } } else { if (glossColor) //failing that, rtry and find color data { - if (mIsDirect3D11) - texCube = new GenOp("@.SampleLevel( @, @, @.a*5)", cubeMapTex, cubeMap, reflectVec, glossColor); - else - texCube = new GenOp("texCUBElod( @, float4(@, @.a*5))", cubeMap, reflectVec, glossColor); + texCube = new GenOp("@.SampleLevel( @, @, @.a*5)", cubeMapTex, cubeMap, reflectVec, glossColor); } else //failing *that*, just draw the cubemap { - if (mIsDirect3D11) - texCube = new GenOp("@.Sample( @, @ )", cubeMapTex, cubeMap, reflectVec); - else - texCube = new GenOp("texCUBE( @, @ )", cubeMap, reflectVec); + texCube = new GenOp("@.Sample( @, @ )", cubeMapTex, cubeMap, reflectVec); } } @@ -2200,7 +2055,6 @@ void RTLightingFeatHLSL::processVert( Vector &componentList, outNormal->setName( "wsNormal" ); outNormal->setStructName( "OUT" ); outNormal->setType( "float3" ); - outNormal->mapsToSampler = false; // Transform the normal to world space. meta->addStatement( new GenOp( " @ = normalize( @ - @.xyz );\r\n", outNormal, eyePos, inPosition ) ); @@ -2232,7 +2086,6 @@ void RTLightingFeatHLSL::processVert( Vector &componentList, outNormal->setName( "wsNormal" ); outNormal->setStructName( "OUT" ); outNormal->setType( "float3" ); - outNormal->mapsToSampler = false; // Get the transform to world space. Var *objTrans = getObjTrans( componentList, fd.features[MFT_UseInstancing], meta ); @@ -2421,7 +2274,6 @@ void FogFeatHLSL::processVert( Vector &componentList, fogAmount->setName( "fogAmount" ); fogAmount->setStructName( "OUT" ); fogAmount->setType( "float" ); - fogAmount->mapsToSampler = false; meta->addStatement( new GenOp( " @ = saturate( computeSceneFog( @, @, @.r, @.g, @.b ) );\r\n", fogAmount, eyePos, wsPosition, fogData, fogData, fogData ) ); @@ -2561,7 +2413,7 @@ void VisibilityFeatHLSL::processPix( Vector &componentList, // Get the visibility constant. Var *visibility = NULL; if ( fd.features[ MFT_UseInstancing ] ) - visibility = getInTexCoord( "visibility", "float", false, componentList ); + visibility = getInTexCoord( "visibility", "float", componentList ); else { visibility = (Var*)LangElement::find( "visibility" ); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h index 960b9b491..b4739c42c 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h @@ -33,15 +33,12 @@ struct RenderPassData; class ShaderFeatureHLSL : public ShaderFeature { -protected: - bool mIsDirect3D11; public: ShaderFeatureHLSL(); /// Var* getOutTexCoord( const char *name, const char *type, - bool mapsToSampler, bool useTexAnim, MultiLine *meta, Vector &componentList ); @@ -50,7 +47,6 @@ public: /// to the input connector if it doesn't exist. static Var* getInTexCoord( const char *name, const char *type, - bool mapsToSampler, Vector &componentList ); static Var* getInColor( const char *name, diff --git a/Engine/source/shaderGen/HLSL/shaderGenHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderGenHLSL.cpp index 0e9a09eb2..3150bbef9 100644 --- a/Engine/source/shaderGen/HLSL/shaderGenHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderGenHLSL.cpp @@ -69,24 +69,14 @@ void ShaderGenPrinterHLSL::printPixelShaderOutputStruct(Stream& stream, const Ma WRITESTR("struct Fragout\r\n"); WRITESTR("{\r\n"); - if (GFX->getAdapterType() == Direct3D11) + + WRITESTR(" float4 col : SV_Target0;\r\n"); + for (U32 i = 1; i < 4; i++) { - WRITESTR(" float4 col : SV_Target0;\r\n"); - for (U32 i = 1; i < 4; i++) - { - if (numMRTs & 1 << i) - WRITESTR(avar(" float4 col%d : SV_Target%d;\r\n", i, i)); - } - } - else - { - WRITESTR(" float4 col : COLOR0;\r\n"); - for (U32 i = 1; i < 4; i++) - { - if (numMRTs & 1 << i) - WRITESTR(avar(" float4 col%d : COLOR%d;\r\n", i, i)); - } + if (numMRTs & 1 << i) + WRITESTR(avar(" float4 col%d : SV_Target%d;\r\n", i, i)); } + WRITESTR("};\r\n"); WRITESTR("\r\n"); WRITESTR("\r\n"); diff --git a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp index 0d2372b67..16cdf514d 100644 --- a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp +++ b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp @@ -117,8 +117,6 @@ MODULE_BEGIN( ShaderGenHLSL ) MODULE_INIT { sInitDelegate.bind(_initShaderGenHLSL); - SHADERGEN->registerInitDelegate(Direct3D9, sInitDelegate); - SHADERGEN->registerInitDelegate(Direct3D9_360, sInitDelegate); SHADERGEN->registerInitDelegate(Direct3D11, sInitDelegate); } diff --git a/Engine/source/shaderGen/langElement.cpp b/Engine/source/shaderGen/langElement.cpp index 9a38cdd31..59e9a3bde 100644 --- a/Engine/source/shaderGen/langElement.cpp +++ b/Engine/source/shaderGen/langElement.cpp @@ -97,7 +97,6 @@ Var::Var() vertData = false; connector = false; sampler = false; - mapsToSampler = false; arraySize = 1; texture = false; rank = 0; @@ -111,7 +110,6 @@ Var::Var( const char *inName, const char *inType ) vertData = false; connector = false; sampler = false; - mapsToSampler = false; texCoordNum = 0; constSortPos = cspUninit; arraySize = 1; diff --git a/Engine/source/shaderGen/langElement.h b/Engine/source/shaderGen/langElement.h index a1e8c96ad..34af7c3f9 100644 --- a/Engine/source/shaderGen/langElement.h +++ b/Engine/source/shaderGen/langElement.h @@ -121,7 +121,6 @@ struct Var : public LangElement bool connector; // variable that will be passed to pixel shader bool sampler; // texture bool texture; //for D3D11 texture variables - bool mapsToSampler; // for ps 1.x shaders - texcoords must be mapped to same sampler stage U32 arraySize; // 1 = no array, > 1 array of "type" U32 rank; // optional rank system to assist in sorting vars if needed diff --git a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp index abcbef014..42a1a5118 100644 --- a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp +++ b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp @@ -103,7 +103,6 @@ Var* TerrainFeatGLSL::_getInDetailCoord( Vector &componentList inDet->setName( name ); inDet->setStructName( "IN" ); inDet->setType( "vec4" ); - inDet->mapsToSampler = true; } return inDet; @@ -122,7 +121,6 @@ Var* TerrainFeatGLSL::_getInMacroCoord( Vector &componentList inDet->setName( name ); inDet->setStructName( "IN" ); inDet->setType( "vec4" ); - inDet->mapsToSampler = true; } return inDet; @@ -219,7 +217,6 @@ void TerrainBaseMapFeatGLSL::processVert( Vector &componentLis outTex->setName( "outTexCoord" ); outTex->setStructName( "OUT" ); outTex->setType( "vec3" ); - outTex->mapsToSampler = true; meta->addStatement( new GenOp( " @.xy = @.xy;\r\n", outTex, inTex ) ); // If this shader has a side projected layer then we @@ -253,7 +250,7 @@ void TerrainBaseMapFeatGLSL::processPix( Vector &componentLis const MaterialFeatureData &fd ) { // grab connector texcoord register - Var *texCoord = getInTexCoord( "texCoord", "vec3", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "vec3", componentList ); // create texture var Var *diffuseMap = new Var; @@ -363,7 +360,6 @@ void TerrainDetailMapFeatGLSL::processVert( Vector &component outTex->setName( String::ToString( "detCoord%d", detailIndex ) ); outTex->setStructName( "OUT" ); outTex->setType( "vec4" ); - outTex->mapsToSampler = true; // Get the detail scale and fade info. Var *detScaleAndFade = new Var; @@ -714,7 +710,6 @@ void TerrainMacroMapFeatGLSL::processVert( Vector &componentL outTex->setName( String::ToString( "macroCoord%d", detailIndex ) ); outTex->setStructName( "OUT" ); outTex->setType( "vec4" ); - outTex->mapsToSampler = true; // Get the detail scale and fade info. Var *detScaleAndFade = new Var; diff --git a/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp b/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp index 1cdc96ee6..8ebbd641f 100644 --- a/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp +++ b/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp @@ -38,7 +38,7 @@ namespace { void register_hlsl_shader_features_for_terrain(GFXAdapterType type) { - if (type != Direct3D9 && type != Direct3D9_360 && type != Direct3D11) + if (type != Direct3D11) return; FEATUREMGR->registerFeature( MFT_TerrainBaseMap, new TerrainBaseMapFeatHLSL ); @@ -102,7 +102,6 @@ Var* TerrainFeatHLSL::_getInDetailCoord( Vector &componentList inDet->setName( name ); inDet->setStructName( "IN" ); inDet->setType( "float4" ); - inDet->mapsToSampler = true; } return inDet; @@ -121,7 +120,6 @@ Var* TerrainFeatHLSL::_getInMacroCoord( Vector &componentList inDet->setName( name ); inDet->setStructName( "IN" ); inDet->setType( "float4" ); - inDet->mapsToSampler = true; } return inDet; @@ -135,11 +133,7 @@ Var* TerrainFeatHLSL::_getNormalMapTex() if (!normalMap) { normalMap = new Var; - if (mIsDirect3D11) - normalMap->setType("SamplerState"); - else - normalMap->setType("sampler2D"); - + normalMap->setType("SamplerState"); normalMap->setName(name); normalMap->uniform = true; normalMap->sampler = true; @@ -222,7 +216,6 @@ void TerrainBaseMapFeatHLSL::processVert( Vector &componentLis outTex->setName( "outTexCoord" ); outTex->setStructName( "OUT" ); outTex->setType( "float3" ); - outTex->mapsToSampler = true; meta->addStatement( new GenOp( " @.xy = @.xy;\r\n", outTex, inTex ) ); // If this shader has a side projected layer then we @@ -256,11 +249,11 @@ void TerrainBaseMapFeatHLSL::processPix( Vector &componentLis const MaterialFeatureData &fd ) { // grab connector texcoord register - Var *texCoord = getInTexCoord( "texCoord", "float3", true, componentList ); + Var *texCoord = getInTexCoord( "texCoord", "float3", componentList ); // create texture var Var *diffuseMap = new Var; - diffuseMap->setType( "sampler2D" ); + diffuseMap->setType( "SamplerState" ); diffuseMap->setName( "baseTexMap" ); diffuseMap->uniform = true; diffuseMap->sampler = true; @@ -271,21 +264,14 @@ void TerrainBaseMapFeatHLSL::processPix( Vector &componentLis Var *baseColor = new Var; baseColor->setType( "float4" ); baseColor->setName( "baseColor" ); - if (mIsDirect3D11) - { - diffuseMap->setType("SamplerState"); - Var *diffuseTex = new Var; - diffuseTex->setType("Texture2D"); - diffuseTex->setName("baseTexture"); - diffuseTex->uniform = true; - diffuseTex->texture = true; - diffuseTex->constNum = diffuseMap->constNum; - meta->addStatement(new GenOp(" @ = @.Sample( @, @.xy );\r\n", new DecOp(baseColor), diffuseTex, diffuseMap, texCoord)); - } - else - { - meta->addStatement(new GenOp(" @ = tex2D( @, @.xy );\r\n", new DecOp(baseColor), diffuseMap, texCoord)); - } + + Var *diffuseTex = new Var; + diffuseTex->setType("Texture2D"); + diffuseTex->setName("baseTexture"); + diffuseTex->uniform = true; + diffuseTex->texture = true; + diffuseTex->constNum = diffuseMap->constNum; + meta->addStatement(new GenOp(" @ = @.Sample( @, @.xy );\r\n", new DecOp(baseColor), diffuseTex, diffuseMap, texCoord)); meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", baseColor, baseColor)); @@ -381,7 +367,6 @@ void TerrainDetailMapFeatHLSL::processVert( Vector &component outTex->setName( String::ToString( "detCoord%d", detailIndex ) ); outTex->setStructName( "OUT" ); outTex->setType( "float4" ); - outTex->mapsToSampler = true; // Get the detail scale and fade info. Var *detScaleAndFade = new Var; @@ -446,31 +431,21 @@ void TerrainDetailMapFeatHLSL::processPix( Vector &component // Get the layer texture var Var *layerTex = new Var; - layerTex->setType( "sampler2D" ); + layerTex->setType( "SamplerState" ); layerTex->setName( "layerTex" ); layerTex->uniform = true; layerTex->sampler = true; layerTex->constNum = Var::getTexUnitNum(); - if (mIsDirect3D11) - { - layerTex->setType("SamplerState"); - Var* layerTexObj = new Var; - layerTexObj->setName("layerTexObj"); - layerTexObj->setType("Texture2D"); - layerTexObj->uniform = true; - layerTexObj->texture = true; - layerTexObj->constNum = layerTex->constNum; - // Read the layer texture to get the samples. - meta->addStatement(new GenOp(" @ = round( @.Sample( @, @.xy ) * 255.0f );\r\n", - new DecOp(layerSample), layerTexObj, layerTex, inTex)); - } - else - { - // Read the layer texture to get the samples. - meta->addStatement(new GenOp(" @ = round( tex2D( @, @.xy ) * 255.0f );\r\n", - new DecOp(layerSample), layerTex, inTex)); - } + Var* layerTexObj = new Var; + layerTexObj->setName("layerTexObj"); + layerTexObj->setType("Texture2D"); + layerTexObj->uniform = true; + layerTexObj->texture = true; + layerTexObj->constNum = layerTex->constNum; + // Read the layer texture to get the samples. + meta->addStatement(new GenOp(" @ = round( @.Sample( @, @.xy ) * 255.0f );\r\n", + new DecOp(layerSample), layerTexObj, layerTex, inTex)); } Var *layerSize = (Var*)LangElement::find( "layerSize" ); @@ -519,47 +494,29 @@ void TerrainDetailMapFeatHLSL::processPix( Vector &component // Get the rest of our inputs. Var *normalMap = _getNormalMapTex(); - if (mIsDirect3D11) + String name(String::ToString("normalMapTex%d", getProcessIndex())); + Var *normalMapTex = (Var*)LangElement::find(name); + + if (!normalMapTex) { - String name(String::ToString("normalMapTex%d", getProcessIndex())); - Var *normalMapTex = (Var*)LangElement::find(name); - - if (!normalMapTex) - { - normalMapTex = new Var; - normalMapTex->setName(String::ToString("normalMapTex%d", getProcessIndex())); - normalMapTex->setType("Texture2D"); - normalMapTex->uniform = true; - normalMapTex->texture = true; - normalMapTex->constNum = normalMap->constNum; - } - - // Call the library function to do the rest. - if (fd.features.hasFeature(MFT_IsDXTnm, detailIndex)) - { - meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @, @.xy, @, @.z * @ );\r\n", - inDet, normalMapTex, normalMap, inDet, negViewTS, detailInfo, detailBlend)); - } - else - { - meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @, @.xy, @, @.z * @ );\r\n", - inDet, normalMapTex, normalMap, inDet, negViewTS, detailInfo, detailBlend)); - } + normalMapTex = new Var; + normalMapTex->setName(String::ToString("normalMapTex%d", getProcessIndex())); + normalMapTex->setType("Texture2D"); + normalMapTex->uniform = true; + normalMapTex->texture = true; + normalMapTex->constNum = normalMap->constNum; + } + // Call the library function to do the rest. + if (fd.features.hasFeature(MFT_IsDXTnm, detailIndex)) + { + meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @, @.xy, @, @.z * @ );\r\n", + inDet, normalMapTex, normalMap, inDet, negViewTS, detailInfo, detailBlend)); } else { - // Call the library function to do the rest. - if (fd.features.hasFeature(MFT_IsDXTnm, detailIndex)) - { - meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n", - inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend)); - } - else - { - meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @.xy, @, @.z * @ );\r\n", - inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend)); - } + meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @, @.xy, @, @.z * @ );\r\n", + inDet, normalMapTex, normalMap, inDet, negViewTS, detailInfo, detailBlend)); } } @@ -574,7 +531,7 @@ void TerrainDetailMapFeatHLSL::processPix( Vector &component // Get the detail texture. Var *detailMap = new Var; - detailMap->setType( "sampler2D" ); + detailMap->setType( "SamplerState" ); detailMap->setName( String::ToString( "detailMap%d", detailIndex ) ); detailMap->uniform = true; detailMap->sampler = true; @@ -598,41 +555,23 @@ void TerrainDetailMapFeatHLSL::processPix( Vector &component // //Sampled detail texture that is not expanded - if (mIsDirect3D11) + Var* detailTex = new Var; + detailTex->setName(String::ToString("detailTex%d", detailIndex)); + detailTex->setType("Texture2D"); + detailTex->uniform = true; + detailTex->texture = true; + detailTex->constNum = detailMap->constNum; + + if (fd.features.hasFeature(MFT_TerrainSideProject, detailIndex)) { - detailMap->setType("SamplerState"); - Var* detailTex = new Var; - detailTex->setName(String::ToString("detailTex%d", detailIndex)); - detailTex->setType("Texture2D"); - detailTex->uniform = true; - detailTex->texture = true; - detailTex->constNum = detailMap->constNum; - if (fd.features.hasFeature(MFT_TerrainSideProject, detailIndex)) - { - - meta->addStatement(new GenOp(" @ = ( lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n", - detailColor, detailTex, detailMap, inDet, detailTex, detailMap, inDet, inTex)); - } - else - { - meta->addStatement(new GenOp(" @ = ( @.Sample( @, @.xy ) * 2.0 ) - 1.0;\r\n", - detailColor, detailTex, detailMap, inDet)); - } + meta->addStatement(new GenOp(" @ = ( lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n", + detailColor, detailTex, detailMap, inDet, detailTex, detailMap, inDet, inTex)); } else { - if (fd.features.hasFeature(MFT_TerrainSideProject, detailIndex)) - { - - meta->addStatement(new GenOp(" @ = ( lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n", - detailColor, detailMap, inDet, detailMap, inDet, inTex)); - } - else - { - meta->addStatement(new GenOp(" @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n", - detailColor, detailMap, inDet)); - } + meta->addStatement(new GenOp(" @ = ( @.Sample( @, @.xy ) * 2.0 ) - 1.0;\r\n", + detailColor, detailTex, detailMap, inDet)); } meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n", @@ -739,7 +678,6 @@ void TerrainMacroMapFeatHLSL::processVert( Vector &componentL outTex->setName( String::ToString( "macroCoord%d", detailIndex ) ); outTex->setStructName( "OUT" ); outTex->setType( "float4" ); - outTex->mapsToSampler = true; // Get the detail scale and fade info. Var *detScaleAndFade = new Var; @@ -797,28 +735,21 @@ void TerrainMacroMapFeatHLSL::processPix( Vector &componentL // Get the layer texture var Var *layerTex = new Var; - layerTex->setType( "sampler2D" ); + layerTex->setType( "SamplerState" ); layerTex->setName( "macrolayerTex" ); layerTex->uniform = true; layerTex->sampler = true; layerTex->constNum = Var::getTexUnitNum(); // Read the layer texture to get the samples. - if (mIsDirect3D11) - { - layerTex->setType("SamplerState"); - Var *layerTexObj = new Var; - layerTexObj->setType("Texture2D"); - layerTexObj->setName("macroLayerTexObj"); - layerTexObj->uniform = true; - layerTexObj->texture = true; - layerTexObj->constNum = layerTex->constNum; - meta->addStatement(new GenOp(" @ = round( @.Sample( @, @.xy ) * 255.0f );\r\n", - new DecOp(layerSample), layerTexObj, layerTex, inTex)); - } - else - meta->addStatement(new GenOp(" @ = round( tex2D( @, @.xy ) * 255.0f );\r\n", - new DecOp(layerSample), layerTex, inTex)); + Var *layerTexObj = new Var; + layerTexObj->setType("Texture2D"); + layerTexObj->setName("macroLayerTexObj"); + layerTexObj->uniform = true; + layerTexObj->texture = true; + layerTexObj->constNum = layerTex->constNum; + meta->addStatement(new GenOp(" @ = round( @.Sample( @, @.xy ) * 255.0f );\r\n", + new DecOp(layerSample), layerTexObj, layerTex, inTex)); } Var *layerSize = (Var*)LangElement::find( "layerSize" ); @@ -870,25 +801,19 @@ void TerrainMacroMapFeatHLSL::processPix( Vector &componentL // Get the detail texture. Var *detailMap = new Var; - detailMap->setType( "sampler2D" ); + detailMap->setType( "SamplerState" ); detailMap->setName( String::ToString( "macroMap%d", detailIndex ) ); detailMap->uniform = true; detailMap->sampler = true; detailMap->constNum = Var::getTexUnitNum(); // used as texture unit num here //Create texture object for directx 11 - Var *detailTex = NULL; - if (mIsDirect3D11) - { - detailMap->setType("SamplerState"); - detailTex = new Var; - detailTex->setName(String::ToString("macroMapTex%d", detailIndex)); - detailTex->setType("Texture2D"); - detailTex->uniform = true; - detailTex->texture = true; - detailTex->constNum = detailMap->constNum; - - } + Var *detailTex = new Var; + detailTex->setName(String::ToString("macroMapTex%d", detailIndex)); + detailTex->setType("Texture2D"); + detailTex->uniform = true; + detailTex->texture = true; + detailTex->constNum = detailMap->constNum; // If we're using SM 3.0 then take advantage of // dynamic branching to skip layers per-pixel. @@ -906,23 +831,13 @@ void TerrainMacroMapFeatHLSL::processPix( Vector &componentL // if (fd.features.hasFeature(MFT_TerrainSideProject, detailIndex)) { - if (mIsDirect3D11) - { - meta->addStatement(new GenOp(" @ = ( lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n", - detailColor, detailTex, detailMap, inDet, detailTex, detailMap, inDet, inTex)); - } - else - meta->addStatement(new GenOp(" @ = ( lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n", - detailColor, detailMap, inDet, detailMap, inDet, inTex)); + meta->addStatement(new GenOp(" @ = ( lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n", + detailColor, detailTex, detailMap, inDet, detailTex, detailMap, inDet, inTex)); } else { - if (mIsDirect3D11) - meta->addStatement(new GenOp(" @ = ( @.Sample( @, @.xy ) * 2.0 ) - 1.0;\r\n", + meta->addStatement(new GenOp(" @ = ( @.Sample( @, @.xy ) * 2.0 ) - 1.0;\r\n", detailColor, detailTex, detailMap, inDet)); - else - meta->addStatement(new GenOp(" @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n", - detailColor, detailMap, inDet)); } meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n", @@ -1027,39 +942,26 @@ void TerrainNormalMapFeatHLSL::processPix( Vector &component // We take two normal samples and lerp between them for // side projection layers... else a single sample. LangElement *texOp; - if (mIsDirect3D11) + + String name(String::ToString("normalMapTex%d", getProcessIndex())); + Var *normalMapTex = (Var*)LangElement::find(name); + if (!normalMapTex) { - String name(String::ToString("normalMapTex%d", getProcessIndex())); - Var *normalMapTex = (Var*)LangElement::find(name); - if (!normalMapTex) - { - normalMapTex = new Var; - normalMapTex->setName(String::ToString("normalMapTex%d", getProcessIndex())); - normalMapTex->setType("Texture2D"); - normalMapTex->uniform = true; - normalMapTex->texture = true; - normalMapTex->constNum = normalMap->constNum; - } - if (fd.features.hasFeature(MFT_TerrainSideProject, normalIndex)) - { - texOp = new GenOp("lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z )", - normalMapTex, normalMap, inDet, normalMapTex, normalMap, inDet, inTex); - } - else - texOp = new GenOp("@.Sample(@, @.xy)", normalMapTex, normalMap, inDet); - + normalMapTex = new Var; + normalMapTex->setName(String::ToString("normalMapTex%d", getProcessIndex())); + normalMapTex->setType("Texture2D"); + normalMapTex->uniform = true; + normalMapTex->texture = true; + normalMapTex->constNum = normalMap->constNum; } + if (fd.features.hasFeature(MFT_TerrainSideProject, normalIndex)) + { + texOp = new GenOp("lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z )", + normalMapTex, normalMap, inDet, normalMapTex, normalMap, inDet, inTex); + } else - { - if (fd.features.hasFeature(MFT_TerrainSideProject, normalIndex)) - { - texOp = new GenOp("lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )", - normalMap, inDet, normalMap, inDet, inTex); - } - else - texOp = new GenOp("tex2D(@, @.xy)", normalMap, inDet); - } + texOp = new GenOp("@.Sample(@, @.xy)", normalMapTex, normalMap, inDet); // create bump normal Var *bumpNorm = new Var; @@ -1116,7 +1018,7 @@ void TerrainLightMapFeatHLSL::processPix( Vector &componentLis // Get the lightmap texture. Var *lightMap = new Var; - lightMap->setType( "sampler2D" ); + lightMap->setType( "SamplerState" ); lightMap->setName( "lightMapTex" ); lightMap->uniform = true; lightMap->sampler = true; @@ -1137,19 +1039,13 @@ void TerrainLightMapFeatHLSL::processPix( Vector &componentLis meta->addStatement( new GenOp( " @ = 1;\r\n", new DecOp( lightMask ) ) ); } - if (mIsDirect3D11) - { - lightMap->setType("SamplerState"); - Var* lightMapTex = new Var; - lightMapTex->setName("lightMapTexObj"); - lightMapTex->setType("Texture2D"); - lightMapTex->uniform = true; - lightMapTex->texture = true; - lightMapTex->constNum = lightMap->constNum; - meta->addStatement(new GenOp(" @[0] = @.Sample( @, @.xy ).r;\r\n", lightMask, lightMapTex, lightMap, inTex)); - } - else - meta->addStatement(new GenOp(" @[0] = tex2D( @, @.xy ).r;\r\n", lightMask, lightMap, inTex)); + Var* lightMapTex = new Var; + lightMapTex->setName("lightMapTexObj"); + lightMapTex->setType("Texture2D"); + lightMapTex->uniform = true; + lightMapTex->texture = true; + lightMapTex->constNum = lightMap->constNum; + meta->addStatement(new GenOp(" @[0] = @.Sample( @, @.xy ).r;\r\n", lightMask, lightMapTex, lightMap, inTex)); output = meta; } diff --git a/Engine/source/windowManager/win32/win32Window.h b/Engine/source/windowManager/win32/win32Window.h index 22f6e92e5..0262917b7 100644 --- a/Engine/source/windowManager/win32/win32Window.h +++ b/Engine/source/windowManager/win32/win32Window.h @@ -36,10 +36,7 @@ class GFXGLDevice; class Win32Window : public PlatformWindow { friend class Win32WindowManager; - friend class GFXPCD3D9Device; friend class GFXGLDevice; - friend class GFXPCD3D9WindowTarget; - friend class GFXD3D8WindowTarget; public: struct Accelerator diff --git a/Templates/Full/game/core/scripts/client/defaults.cs b/Templates/Full/game/core/scripts/client/defaults.cs index d1805d337..20774856e 100644 --- a/Templates/Full/game/core/scripts/client/defaults.cs +++ b/Templates/Full/game/core/scripts/client/defaults.cs @@ -47,7 +47,7 @@ $sceneLighting::cacheSize = 20000; $sceneLighting::purgeMethod = "lastCreated"; $sceneLighting::cacheLighting = 1; -$pref::Video::displayDevice = "D3D9"; +$pref::Video::displayDevice = "D3D11"; $pref::Video::disableVerticalSync = 1; $pref::Video::mode = "1024 768 false 32 60 4"; $pref::Video::defaultFenceCount = 0; diff --git a/Templates/Full/game/core/scripts/client/lighting/advanced/init.cs b/Templates/Full/game/core/scripts/client/lighting/advanced/init.cs index d74aff69a..d6e98cd36 100644 --- a/Templates/Full/game/core/scripts/client/lighting/advanced/init.cs +++ b/Templates/Full/game/core/scripts/client/lighting/advanced/init.cs @@ -46,16 +46,7 @@ exec( "./shadowViz.gui" ); exec( "./deferredShading.cs" ); function onActivateAdvancedLM() -{ - // Don't allow the offscreen target on OSX. - if ( $platform $= "macos" ) - return; - - // On the Xbox360 we know what will be enabled so don't do any trickery to - // disable MSAA - if ( $platform $= "xenon" ) - return; - +{ // Enable the offscreen target so that AL will work // with MSAA back buffers and for HDR rendering. AL_FormatToken.enable();