mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
Engine directory for ticket #1
This commit is contained in:
parent
352279af7a
commit
7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions
87
Engine/source/gfx/D3D9/pc/gfxD3D9Device.pc.cpp
Normal file
87
Engine/source/gfx/D3D9/pc/gfxD3D9Device.pc.cpp
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 );
|
||||
}
|
||||
376
Engine/source/gfx/D3D9/pc/gfxD3D9EnumTranslate.pc.cpp
Normal file
376
Engine/source/gfx/D3D9/pc/gfxD3D9EnumTranslate.pc.cpp
Normal file
|
|
@ -0,0 +1,376 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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( int i = enumprefix##_FIRST; i < enumprefix##_COUNT; i++ ) \
|
||||
tablearray##[i] = (##type##)GFX_UNINIT_VAL;
|
||||
|
||||
#define VALIDATE_LOOKUPTABLE( tablearray, enumprefix ) \
|
||||
for( int i = enumprefix##_FIRST; i < enumprefix##_COUNT; i++ ) \
|
||||
if( (int)tablearray##[i] == GFX_UNINIT_VAL ) \
|
||||
Con::warnf( "GFXD3D9EnumTranslate: Unassigned value in " #tablearray ": %i", i ); \
|
||||
else if( (int)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[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;
|
||||
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;
|
||||
GFXD3D9PrimType[GFXTriangleFan] = D3DPT_TRIANGLEFAN;
|
||||
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;
|
||||
VALIDATE_LOOKUPTABLE( GFXD3D9DeclType, GFXDeclType );
|
||||
}
|
||||
|
||||
94
Engine/source/gfx/D3D9/pc/gfxD3D9PrimitiveBuffer.pc.cpp
Normal file
94
Engine/source/gfx/D3D9/pc/gfxD3D9PrimitiveBuffer.pc.cpp
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 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
|
||||
}
|
||||
|
||||
1176
Engine/source/gfx/D3D9/pc/gfxPCD3D9Device.cpp
Normal file
1176
Engine/source/gfx/D3D9/pc/gfxPCD3D9Device.cpp
Normal file
File diff suppressed because it is too large
Load diff
81
Engine/source/gfx/D3D9/pc/gfxPCD3D9Device.h
Normal file
81
Engine/source/gfx/D3D9/pc/gfxPCD3D9Device.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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
|
||||
587
Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.cpp
Normal file
587
Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.cpp
Normal file
|
|
@ -0,0 +1,587 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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"
|
||||
|
||||
|
||||
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( D3DADAPTER_DEFAULT,
|
||||
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(int 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!");
|
||||
}
|
||||
|
||||
Win32Window *win = dynamic_cast<Win32Window*>(mWindow);
|
||||
AssertISV(win, "GFXPCD3D9WindowTarget::initPresentationParams() - got a non Win32Window window passed in! Did DX go crossplatform?");
|
||||
|
||||
HWND hwnd = win->getHWND();
|
||||
|
||||
// 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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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( D3DADAPTER_DEFAULT,
|
||||
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();
|
||||
}
|
||||
130
Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.h
Normal file
130
Engine/source/gfx/D3D9/pc/gfxPCD3D9Target.h
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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_
|
||||
Loading…
Add table
Add a link
Reference in a new issue