Removes Direct3D9 functionality.

This commit is contained in:
Areloch 2017-05-28 16:51:31 -05:00
parent 5ac6f6beb3
commit edd1e0a270
86 changed files with 382 additions and 10445 deletions

View file

@ -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 );

View file

@ -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 ) ); }
};

View file

@ -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);

View file

@ -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

View file

@ -37,7 +37,6 @@
#include "windowManager/platformWindow.h"
#include "gfx/D3D11/screenshotD3D11.h"
#include "materials/shaderData.h"
#include <d3d9.h> //ok now stressing out folks, this is just for debug events(D3DPER) :)
#ifdef TORQUE_DEBUG
#include "d3d11sdklayers.h"
@ -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);
}
}

View file

@ -23,7 +23,7 @@
#ifndef _GFXD3D11DEVICE_H_
#define _GFXD3D11DEVICE_H_
#include <d3d11.h>
#include <d3d11_1.h>
#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];

View file

@ -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" );
}
}

View file

@ -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) )

View file

@ -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<GFXD3D9Device *>(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<GFXD3D9Device *>(GFX)->getD3D();
D3DDISPLAYMODE displayMode = static_cast<GFXD3D9Device *>(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;
}

View file

@ -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

View file

@ -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<GFXD3D9Device *>(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<GFXD3D9Device *>(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<GFXD3D9Device *>(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<GFXD3D9TextureObject*>((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<GFXD3D9Device *>(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 );
}

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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 <d3dx9.h>
# 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 <DxErr.h>
#else
#include <dxerr9.h>
#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<GFXD3D9Device *>(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<GFXD3D9VertexBuffer> RPGDVB;
Vector<RPGDVB> 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<String,D3D9VertexDecl*> 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<GFXD3D9PrimitiveBuffer> 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<GFXD3D9ShaderConstBuffer> 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_

View file

@ -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 );
}
}
}

View file

@ -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; \
} \

View file

@ -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<GFXD3D9Device*>( mDevice )->getDevice()->CreateQueryTiled( D3DQUERYTYPE_OCCLUSION, 2, &mQuery );
#else
HRESULT hRes = static_cast<GFXD3D9Device*>( 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();
}

View file

@ -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_

View file

@ -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<GFXD3D9Device *>( 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<GFXD3D9Device *>(mDevice)->mD3DDevice))
{
reinterpret_cast<GFXD3D9Device *>(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<GFXD3D9Device*>(mDevice)->mD3DDevice->CreateIndexBuffer( sizeof(U16) * mIndexCount ,
usage , GFXD3D9IndexFormat[GFXIndexFormat16], pool, &ib, 0),
"GFXD3D9PrimitiveBuffer::resurrect - Failed to allocate an index buffer.");
}

View file

@ -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<GFXD3D9PrimitiveBuffer> 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

View file

@ -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<GFXD3D9Device *>( 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<GFXD3D9Device *>( 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();
}

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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<GFXD3D9Shader> 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<F32>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point2F>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point3F>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point4F>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<S32>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point2I>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point3I>& fv);
virtual void set(GFXShaderConstHandle* handle, const AlignedArray<Point4I>& 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<class T>
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<GFXD3D9Shader> 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<String, GFXD3D9ShaderConstHandle*> HandleMap;
GFXD3D9Shader();
virtual ~GFXD3D9Shader();
// GFXShader
virtual GFXShaderConstBufferRef allocConstBuffer();
virtual const Vector<GFXShaderConstDesc>& 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<GFXShaderConstDesc> mSamplerDescriptions;
/// Vector of descriptions (consolidated for the getShaderConstDesc call)
Vector<GFXShaderConstDesc> 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<GFXShaderConstDesc> &samplerDescriptions );
void _getShaderConstants( ID3DXConstantTable* table,
GenericConstBufferLayout *bufferLayoutF,
GenericConstBufferLayout *bufferLayoutI,
Vector<GFXShaderConstDesc> &samplerDescriptions );
bool _saveCompiledOutput( const Torque::Path &filePath,
ID3DXBuffer *buffer,
GenericConstBufferLayout *bufferLayoutF,
GenericConstBufferLayout *bufferLayoutI,
Vector<GFXShaderConstDesc> &samplerDescriptions );
// Loads precompiled shaders
bool _loadCompiledOutput( const Torque::Path &filePath,
const String &target,
GenericConstBufferLayout *bufferLayoutF,
GenericConstBufferLayout *bufferLayoutI,
Vector<GFXShaderConstDesc> &samplerDescriptions );
// This is used in both cases
virtual void _buildShaderConstantHandles( GenericConstBufferLayout *layout, bool vertexConst );
virtual void _buildSamplerShaderConstantHandles( Vector<GFXShaderConstDesc> &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_

View file

@ -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 <xtl.h>
#else
# include <d3d9.h>
#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
}

View file

@ -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<GFXD3D9StateBlock> GFXD3D9StateBlockRef;
#endif

View file

@ -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<GFXD3D9Device*>(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<GFXD3D9TextureObject*>( inTex ), "GFXD3D9TextureManager::_createTexture() - Bad inTex type!" );
retTex = static_cast<GFXD3D9TextureObject*>( 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<GFXD3D9TextureObject*>(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<GFXD3D9Device *>(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<U8> 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<void*>(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<GFXD3D9TextureObject *>( 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<GFXD3D9TextureObject *>(texture),"Not an actual d3d texture object!");
GFXD3D9TextureObject *tex = static_cast<GFXD3D9TextureObject *>( 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<GFXD3D9TextureObject*>(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<GFXD3D9Device *>(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; i<srcHeight; i++)
{
dMemcpy( dstBytes, srcBytes, srcPitch );
dstBytes += lockedRect.Pitch;
srcBytes += srcPitch;
}
surf->UnlockRect();
surf->Release();
return true;
}
dMemcpy( lockedRect.pBits, dds->mSurfaces[0]->mMips[i], dds->getSurfaceSize(i) );
surf->UnlockRect();
}
#endif
surf->Release();
}
return true;
}

View file

@ -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

View file

@ -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<GFXD3D9Device *>(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<GFXD3D9Device *>( GFX )->destroyD3DResource( mD3DTexture );
static_cast<GFXD3D9Device *>( 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<GFXD3D9TextureManager*>(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
}

View file

@ -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

View file

@ -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<GFXD3D9Device *>(getOwningDevice())->deallocVertexBuffer( this );
else if (mBufferType != GFXBufferTypeVolatile)
{
static_cast<GFXD3D9Device *>(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<GFXD3D9Device *>( 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<GFXD3D9Device*>(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" );
}
}

View file

@ -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<GFXD3D9VertexBuffer> 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_

View file

@ -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 );
}

View file

@ -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 <d3d9.h>
#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 );
}

View file

@ -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
}

File diff suppressed because it is too large Load diff

View file

@ -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<GFXFormat> &formats, bool texture, bool mustblend, bool mustfilter);
static void enumerateAdapters( Vector<GFXAdapter*> &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

View file

@ -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; i<MaxRenderSlotId; i++)
{
mTargets[i] = NULL;
mResolveTargets[i] = NULL;
}
}
GFXPCD3D9TextureTarget::~GFXPCD3D9TextureTarget()
{
// Release anything we might be holding.
for(S32 i=0; i<MaxRenderSlotId; i++)
{
mResolveTargets[i] = NULL;
if( GFXDevice::devicePresent() )
{
mDevice->destroyD3DResource( 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<GFXD3D9TextureObject*>(tex),
"GFXPCD3D9TextureTarget::attachTexture - invalid texture object.");
GFXD3D9TextureObject *d3dto = static_cast<GFXD3D9TextureObject*>(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<GFXD3D9Cubemap*>(tex),
"GFXD3DTextureTarget::attachTexture - invalid cubemap object.");
GFXD3D9Cubemap *cube = static_cast<GFXD3D9Cubemap*>(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<GFXPCD3D9Device*>(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<GFXPCD3D9WindowTarget*>(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();
}

View file

@ -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 <d3d9.h>
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_

View file

@ -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 <d3d9.h>
#include <d3dx9core.h>
#include <d3dx9tex.h>
GBitmap* ScreenShotD3D9::_captureBackBuffer()
{
#ifdef TORQUE_OS_XENON
return NULL;
#else
LPDIRECT3DDEVICE9 D3DDevice = dynamic_cast<GFXD3D9Device *>(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; i<size.y; i++)
{
const U8 *a = ((U8*)r.pBits) + i * size.x * 4;
for(S32 j=0; j<size.x; j++)
{
c.blue = *(a++);
c.green = *(a++);
c.red = *(a++);
a++; // Ignore X.
gb->setColor(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
}

View file

@ -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_

View file

@ -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 <d3d9.h>
#include <d3dx9core.h>
#include <d3dx9tex.h>
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<GFXD3D9Device *>(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; i<eNumStages; i++)
{
if (i == mCurrentCapture)
continue;
switch (mCapture[i].stage)
{
case eInVideoMemory:
copyToSystemMemory(mCapture[i]);
break;
case eInSystemMemory:
copyToBitmap(mCapture[i]);
break;
}
}
// Change the resource being used for backbuffer captures
mCurrentCapture = (mCurrentCapture + 1) % eNumStages;
AssertFatal( mCapture[mCurrentCapture].stage != eInSystemMemory, "Error! A capture resource with an invalid state was picked for making captures!" );
}
void VideoFrameGrabberD3D9::releaseTextures()
{
for (U32 i=0; i<eNumStages; i++)
{
mCapture[i].sysMemTex.free();
mCapture[i].vidMemTex.free();
mCapture[i].stage = eReadyToCapture;
}
}
void VideoFrameGrabberD3D9::copyToSystemMemory(CaptureResource &capture)
{
AssertFatal( capture.stage == eInVideoMemory, "Error! copyToSystemMemory() can only work in resources in 'eInVideoMemory' stage!" );
#ifndef TORQUE_OS_XENON
GFXTexHandle &vidMemTex = capture.vidMemTex;
GFXTexHandle &sysMemTex = capture.sysMemTex;
// Initialize system memory texture if necessary
Point2I size = vidMemTex.getWidthHeight();
if (sysMemTex.isNull() || sysMemTex.getWidthHeight() != size)
sysMemTex.set( size.x, size.y, GFXFormatR8G8B8X8, &GFXSystemMemProfile, avar("%s() - tex (line %d)", __FUNCTION__, __LINE__) );
// set up the 2 copy surfaces
IDirect3DSurface9 *surface[2];
// grab the top level surface of tex 0
GFXD3D9TextureObject *to = (GFXD3D9TextureObject *) &(*vidMemTex);
D3D9Assert( to->get2DTex()->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<GFXD3D9Device *>(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<pixels; i++)
{
U32 px = *src++;
*dst++ = px >> 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;
}

View file

@ -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_

View file

@ -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,

View file

@ -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();
}

View file

@ -284,9 +284,7 @@ enum GFXAdapterType
{
OpenGL = 0,
Direct3D11,
Direct3D9,
NullDevice,
Direct3D9_360,
GFXAdapterType_Count
};

View file

@ -68,9 +68,6 @@ inline static void _GFXInitReportAdapters(Vector<GFXAdapter*> &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; i<smAdapters.size(); i++)
{
@ -336,15 +333,6 @@ GFXAdapter *GFXInit::getBestAdapterChoice()
foundAdapter11 = currAdapter;
}
break;
case Direct3D9:
if (currAdapter->mShaderModel > 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<GFXAdapter*> adapters( __FILE__, __LINE__ );

View file

@ -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;

View file

@ -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;
}

View file

@ -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 );
}

View file

@ -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

View file

@ -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());

View file

@ -232,7 +232,6 @@ void DeferredBumpFeatGLSL::processVert( Vector<ShaderComponent*> &componentLis
getOutTexCoord( "texCoord",
"vec2",
true,
useTexAnim,
meta,
componentList );
@ -272,7 +271,7 @@ void DeferredBumpFeatGLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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();

View file

@ -41,7 +41,7 @@
void DeferredSpecMapGLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &componentList,
MultiLine *meta = new MultiLine;
getOutTexCoord( "texCoord",
"vec2",
true,
fd.features[MFT_TexAnim],
meta,
componentList );

View file

@ -145,7 +145,6 @@ void GBufferConditionerGLSL::processPix( Vector<ShaderComponent*> &componentLis
gbNormal->setName( "gbNormal" );
gbNormal->setStructName( "IN" );
gbNormal->setType( "float3" );
gbNormal->mapsToSampler = false;
gbNormal->uniform = false;
}

View file

@ -120,23 +120,18 @@ void DeferredRTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &componentLis
getOutTexCoord( "texCoord",
"float2",
true,
useTexAnim,
meta,
componentList );
@ -292,17 +278,10 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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 ) );

View file

@ -41,7 +41,7 @@
void DeferredSpecMapHLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &componentList,
MultiLine *meta = new MultiLine;
getOutTexCoord( "texCoord",
"float2",
true,
fd.features[MFT_TexAnim],
meta,
componentList );

View file

@ -145,7 +145,6 @@ void GBufferConditionerHLSL::processPix( Vector<ShaderComponent*> &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

View file

@ -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<GFXFormat> 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() );

View file

@ -234,8 +234,6 @@ GFXShader* ShaderData::_createShader( const Vector<GFXShaderMacro> &macros )
// Initialize the right shader type.
switch( GFX->getAdapterType() )
{
case Direct3D9_360:
case Direct3D9:
case Direct3D11:
{
success = shader->init( mDXVertexShaderName,

View file

@ -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 );
}

View file

@ -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");

View file

@ -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);
}

View file

@ -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 ||

View file

@ -37,7 +37,6 @@ void AccuTexFeatGLSL::processVert(Vector<ShaderComponent*> &componentList,
MultiLine *meta = new MultiLine;
getOutTexCoord( "texCoord",
"vec2",
true,
false,
meta,
componentList );
@ -130,8 +129,8 @@ void AccuTexFeatGLSL::processPix(Vector<ShaderComponent*> &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<ShaderComponent*> &componentList, Mul
outAccuVec->setName( "accuVec" );
outAccuVec->setStructName( "OUT" );
outAccuVec->setType( "float3" );
outAccuVec->mapsToSampler = false;
getAccuVec( meta, outAccuVec );
}

View file

@ -42,7 +42,6 @@ void BumpFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
// Output the texture coord.
getOutTexCoord( "texCoord",
"vec2",
true,
useTexAnim,
meta,
componentList );
@ -64,7 +63,7 @@ void BumpFeatGLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &componentList,
// Add the texture coords.
getOutTexCoord( "texCoord",
"vec2",
true,
fd.features[MFT_TexAnim],
meta,
componentList );
@ -312,7 +310,7 @@ void ParallaxFeatGLSL::processPix( Vector<ShaderComponent*> &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<ShaderConnector *>( componentList[C_CONNECTOR] );
@ -408,7 +406,6 @@ void NormalsOutFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
outNormal->setName( "wsNormal" );
outNormal->setStructName( "OUT" );
outNormal->setType( "vec3" );
outNormal->mapsToSampler = false;
// Find the incoming vertex normal.
Var *inNormal = (Var*)LangElement::find( "normal" );

View file

@ -67,7 +67,6 @@ void EyeSpaceDepthOutGLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &componentList,
depthVar->setName( "depth" );
depthVar->setStructName( "IN" );
depthVar->setType( "float" );
depthVar->mapsToSampler = false;
depthVar->uniform = false;
/*

View file

@ -118,7 +118,6 @@ void SpecularMapGLSL::processVert(Vector<ShaderComponent*> &componentList, const
// Add the texture coords.
getOutTexCoord("texCoord",
"vec2",
true,
fd.features[MFT_TexAnim],
meta,
componentList);
@ -129,7 +128,7 @@ void SpecularMapGLSL::processVert(Vector<ShaderComponent*> &componentList, const
void SpecularMapGLSL::processPix( Vector<ShaderComponent*> &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;

View file

@ -333,7 +333,6 @@ Var* ShaderFeatureGLSL::getOutViewToTangent( Vector<ShaderComponent*> &component
Var* ShaderFeatureGLSL::getOutTexCoord( const char *name,
const char *type,
bool mapsToSampler,
bool useTexAnim,
MultiLine *meta,
Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &compon
outTex->setName( "detCoord" );
outTex->setStructName( "OUT" );
outTex->setType( "vec2" );
outTex->mapsToSampler = true;
if ( useTexAnim )
{
@ -841,7 +834,6 @@ void DiffuseMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
MultiLine *meta = new MultiLine;
getOutTexCoord( "texCoord",
"vec2",
true,
fd.features[MFT_TexAnim],
meta,
componentList );
@ -857,7 +849,7 @@ void DiffuseMapFeatGLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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" );

View file

@ -39,7 +39,6 @@ public:
///
Var* getOutTexCoord( const char *name,
const char *type,
bool mapsToSampler,
bool useTexAnim,
MultiLine *meta,
Vector<ShaderComponent*> &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<ShaderComponent*> &componentList );
static Var* getInColor( const char *name,

View file

@ -37,7 +37,6 @@ void AccuTexFeatHLSL::processVert( Vector<ShaderComponent*> &componentList,
MultiLine *meta = new MultiLine;
getOutTexCoord( "texCoord",
"float2",
true,
false,
meta,
componentList );
@ -65,10 +64,7 @@ void AccuTexFeatHLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &componentList, Mu
outAccuVec->setName( "accuVec" );
outAccuVec->setStructName( "OUT" );
outAccuVec->setType( "float3" );
outAccuVec->mapsToSampler = false;
getAccuVec( meta, outAccuVec );
}

View file

@ -42,7 +42,6 @@ void BumpFeatHLSL::processVert( Vector<ShaderComponent*> &componentList,
// Output the texture coord.
getOutTexCoord( "texCoord",
"float2",
true,
useTexAnim,
meta,
componentList );
@ -64,18 +63,14 @@ void BumpFeatHLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &componentList,
// Add the texture coords.
getOutTexCoord( "texCoord",
"float2",
true,
fd.features[MFT_TexAnim],
meta,
componentList );
@ -344,7 +314,7 @@ void ParallaxFeatHLSL::processPix( Vector<ShaderComponent*> &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<ShaderConnector *>( componentList[C_CONNECTOR] );
@ -374,21 +344,13 @@ void ParallaxFeatHLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &componentList,
outNormal->setName( "wsNormal" );
outNormal->setStructName( "OUT" );
outNormal->setType( "float3" );
outNormal->mapsToSampler = false;
// Find the incoming vertex normal.
Var *inNormal = (Var*)LangElement::find( "normal" );

View file

@ -67,7 +67,6 @@ void EyeSpaceDepthOutHLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &componentList,
depthVar->setName( "depth" );
depthVar->setStructName( "IN" );
depthVar->setType( "float" );
depthVar->mapsToSampler = false;
depthVar->uniform = false;
/*

View file

@ -46,9 +46,7 @@ void ParaboloidVertTransformHLSL::processVert( Vector<ShaderComponent*> &compon
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( 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");

View file

@ -122,7 +122,6 @@ void SpecularMapHLSL::processVert(Vector<ShaderComponent*> &componentList, const
// Add the texture coords.
getOutTexCoord("texCoord",
"float2",
true,
fd.features[MFT_TexAnim],
meta,
componentList);
@ -133,31 +132,22 @@ void SpecularMapHLSL::processVert(Vector<ShaderComponent*> &componentList, const
void SpecularMapHLSL::processPix( Vector<ShaderComponent*> &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;

View file

@ -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<ShaderComponent*> &component
Var* ShaderFeatureHLSL::getOutTexCoord( const char *name,
const char *type,
bool mapsToSampler,
bool useTexAnim,
MultiLine *meta,
Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderConnector*>( componentList[C_CONNECTOR] );
ShaderConnector *connectComp = dynamic_cast<ShaderConnector*>(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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &compon
outTex->setName( "detCoord" );
outTex->setStructName( "OUT" );
outTex->setType( "float2" );
outTex->mapsToSampler = true;
if ( useTexAnim )
{
@ -864,7 +825,6 @@ void DiffuseMapFeatHLSL::processVert( Vector<ShaderComponent*> &componentList,
MultiLine *meta = new MultiLine;
getOutTexCoord( "texCoord",
"float2",
true,
fd.features[MFT_TexAnim],
meta,
componentList );
@ -880,7 +840,7 @@ void DiffuseMapFeatHLSL::processPix( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &componentList,
// grab connector position
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( 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<ShaderComponent*> &componentList,
void VertPositionHLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd)
{
if (mIsDirect3D11)
{
// grab connector position
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>(componentList[C_CONNECTOR]);
Var *outPosition = connectComp->getElement(RT_SVPOSITION);
outPosition->setName("vpos");
outPosition->setStructName("IN");
}
// grab connector position
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>(componentList[C_CONNECTOR]);
Var *outPosition = connectComp->getElement(RT_SVPOSITION);
outPosition->setName("vpos");
outPosition->setStructName("IN");
}
@ -1854,7 +1738,6 @@ void ReflectCubeFeatHLSL::processVert( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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" );

View file

@ -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<ShaderComponent*> &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<ShaderComponent*> &componentList );
static Var* getInColor( const char *name,

View file

@ -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");

View file

@ -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);
}

View file

@ -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;

View file

@ -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

View file

@ -103,7 +103,6 @@ Var* TerrainFeatGLSL::_getInDetailCoord( Vector<ShaderComponent*> &componentList
inDet->setName( name );
inDet->setStructName( "IN" );
inDet->setType( "vec4" );
inDet->mapsToSampler = true;
}
return inDet;
@ -122,7 +121,6 @@ Var* TerrainFeatGLSL::_getInMacroCoord( Vector<ShaderComponent*> &componentList
inDet->setName( name );
inDet->setStructName( "IN" );
inDet->setType( "vec4" );
inDet->mapsToSampler = true;
}
return inDet;
@ -219,7 +217,6 @@ void TerrainBaseMapFeatGLSL::processVert( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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;

View file

@ -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<ShaderComponent*> &componentList
inDet->setName( name );
inDet->setStructName( "IN" );
inDet->setType( "float4" );
inDet->mapsToSampler = true;
}
return inDet;
@ -121,7 +120,6 @@ Var* TerrainFeatHLSL::_getInMacroCoord( Vector<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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<ShaderComponent*> &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;
}

View file

@ -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

View file

@ -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;

View file

@ -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();