Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(w3ddevice): render on a native Direct3D 9 device
Olcay Seygan171751c22eb2
diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txtindex 139736431..dfbd94899 100644--- a/GeneralsMD/Code/CMakeLists.txt+++ b/GeneralsMD/Code/CMakeLists.txt@@ -186,6 +186,16 @@ add_library(wwsaveload STATICtarget_include_directories(wwsaveload PUBLIC ${WW}/WWSaveLoad PRIVATE ${WW}/WWLib ${WW}/WWMath ${WW}/Wwutil)target_link_libraries(wwsaveload PRIVATE wwdebug wwlib wwmath)+# ---- d3dx9runtime ---------------------------------------------------------+# The D3DX9 entry points the renderer binds at run time, in a library of their own+# because GameEngine needs the math half without the renderer: BezierSegment carries+# D3DXMATRIX and DumbProjectileBehavior steers a shell with it.+add_library(d3dx9runtime STATIC+ ${WW}/WW3D2/d3dx9runtime.cpp ${WW}/WW3D2/d3d8shadertranslate.cpp)+set_target_properties(d3dx9runtime PROPERTIES CXX_STANDARD 17)+target_include_directories(d3dx9runtime PUBLIC ${WW}/WW3D2)+target_link_libraries(d3dx9runtime PUBLIC d3d9)+# ---- ww3d2 (renderer core) ------------------------------------------------# wwshade is header-only here on purpose: no .dsp links wwshade.lib and its# shd*bump* sources need shdpp/NVASM-generated headers. Revisit at exe link.@@ -233,17 +243,15 @@ add_library(ww3d2 STATICtarget_include_directories(ww3d2PUBLIC ${WW}/WW3D2PRIVATE ${WW}/WWLib ${WW}/WWMath ${WW}/WWDebug ${WW}/WWSaveLoad ${WW}/Wwutil- ${WW}/wwshade ${WW}/WWAudio ${WW}/Miles6/include- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Include)-target_link_directories(ww3d2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Lib)-# vfw32: FramGrab.cpp writes AVIs. legacy_stdio_definitions: d3dx8.lib calls-# _vsnprintf, which the modern CRT only provides as an inline.+ ${WW}/wwshade ${WW}/WWAudio ${WW}/Miles6/include)+# RENDERER-ROADMAP.md phase 1: d3d9.h and d3d9.lib come out of the Windows SDK, so+# the vendored DirectX 8 headers are off the include path entirely - a d3d8.h left+# reachable is a file that compiles against the wrong runtime without saying so.+# D3DX9 has no import library anywhere and is bound at runtime instead: see+# WW3D2/d3dx9runtime.h. vfw32 is FramGrab.cpp writing AVIs.target_link_libraries(ww3d2- PUBLIC d3d8 d3dx8 dxguid vfw32 legacy_stdio_definitions+ PUBLIC d3d9 dxguid vfw32 d3dx9runtimePRIVATE wwlib wwmath wwdebug wwsaveload)-# The 2001 d3dx8.lib predates SAFESEH and was built against the long-gone-# libci.lib CRT, so anything linking it has to opt out of both.-target_link_options(ww3d2 INTERFACE /SAFESEH:NO /NODEFAULTLIB:libci.lib)# dx8webbrowser.cpp is the one file /MP cannot have: MSVC rejects #import under# multi-process compilation (C2813) and finds the directive by a lexical scan, so# even though ENABLE_EMBEDDED_BROWSER's block is what holds it, disabling the block@@ -267,9 +275,8 @@ target_link_libraries(dx8_smoke PRIVATE d3d8 user32)# dll. d3d9.h and d3d9.lib come from the Windows SDK, so this target must not see# Libraries/DirectX/Include - d3d8.h would shadow nothing here, but keeping the two# header sets apart is what makes the native path native.-add_executable(dx9_smoke ${WW}/WW3D2/test_dx9_smoke.cpp ${WW}/WW3D2/d3dx9runtime.cpp)-target_include_directories(dx9_smoke PRIVATE ${WW}/WW3D2)-target_link_libraries(dx9_smoke PRIVATE d3d9 user32)+add_executable(dx9_smoke ${WW}/WW3D2/test_dx9_smoke.cpp)+target_link_libraries(dx9_smoke PRIVATE d3dx9runtime user32)# ===========================================================================# Phase 2 - remaining support libs. None of these touch DX8.@@ -404,7 +411,10 @@ target_include_directories(gameengine PUBLIC# The game includes "GameSpy/Peer/Peer.h", the SDK's own headers include each# other as "gscommon.h", so both levels have to be on the path.${LIBSRC}/GameSpy/include ${LIBSRC}/GameSpy/include/gamespy ${COMP}- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Include)+ # WW3D2 is here for d3dx9math.h alone: BezierSegment carries D3DXMATRIX, and+ # DumbProjectileBehavior steers a shell with it. dinput.h now comes out of the+ # Windows SDK like d3d9.h does.+ ${WW}/WW3D2)# _RELEASE/_DEBUG pick the game's own build flavour; IG_DEBUG_STACKTRACE and# Z_PREFIX are what GameEngine.dsp sets.target_compile_definitions(gameengine PUBLIC@@ -600,8 +610,7 @@ add_lib_test(test_compression compression)add_lib_test(test_ww3d2 ww3d2 wwsaveload wwlib wwmath wwdebug)target_include_directories(test_ww3d2 PRIVATE- ${WW}/WW3D2 ${WW}/WWLib ${WW}/WWMath ${WW}/WWDebug ${WW}/WWSaveLoad ${WW}/Wwutil- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Include)+ ${WW}/WW3D2 ${WW}/WWLib ${WW}/WWMath ${WW}/WWDebug ${WW}/WWSaveLoad ${WW}/Wwutil)add_lib_test(test_wwdownload wwdownload)target_include_directories(test_wwdownload PRIVATE ${WW}/WWDownload)diff --git a/GeneralsMD/Code/GameEngine/Include/Common/BezierSegment.h b/GeneralsMD/Code/GameEngine/Include/Common/BezierSegment.hindex 7edcd1e1d..aa26bc6a6 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/BezierSegment.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/BezierSegment.h@@ -31,7 +31,7 @@#ifndef __BEZIERSEGMENT_H__#define __BEZIERSEGMENT_H__-#include <D3DX8Math.h>+#include "d3dx9math.h"#include "Common/STLTypeDefs.h"#define USUAL_TOLERANCE 1.0fdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/Bezier/BezierSegment.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Bezier/BezierSegment.cppindex a17273df6..900653925 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Bezier/BezierSegment.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Bezier/BezierSegment.cpp@@ -27,7 +27,7 @@#include "Common/BezierSegment.h"#include "Common/BezFwdIterator.h"-#include <D3DX8Math.h>+#include "d3dx9math.h"//-------------------------------------------------------------------------------------------------BezierSegment::BezierSegment()diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cppindex b062486a7..8f786a3c9 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cpp@@ -709,7 +709,7 @@ static PoolSizeRec sizes[] ={ "SortingIndexBufferClass", 32, 32 },{ "DX8VertexBufferClass", 128, 32 },{ "SortingVertexBufferClass", 32, 32 },- { "DynD3DMATERIAL8", 8192, 32 },+ { "DynD3DMATERIAL9", 8192, 32 },{ "DynamicMatrix3D", 512, 32 },{ "MeshGeometryClass", 32, 32 },{ "DynamicMeshModel", 32, 32 },diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.hindex d24082bee..8771444a8 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h@@ -44,6 +44,8 @@ enum ChipsetType;enum CpuType;enum GraphicsVenderID;+#include <d3d9.h>+class TextureClass; ///forward reference/** System for managing complex rendering settings which are either not handled byWW3D2 or need custom paths depending on the video card. This system will determine@@ -93,8 +95,12 @@ public:static inline TextureClass *getShaderTexture(Int stage) { return m_Textures[stage];} ///<returns currently selected texture for given stage///Return last activated shader.static inline ShaderTypes getCurrentShader(void) {return m_currentShader;}- /// Loads a .vso file and creates a vertex shader for it- static HRESULT LoadAndCreateD3DShader(char* strFilePath, const DWORD* pDeclaration, DWORD Usage, Bool ShaderType, DWORD* pHandle);+ /// Loads a .pso file, translates its D3D8 bytecode and creates the pixel shader.+ static HRESULT LoadAndCreateD3DPixelShader(const char* strFilePath, IDirect3DPixelShader9** shader);+ /// Loads a .vso file with the D3D8 declaration array that belongs to it, and creates+ /// both the vertex shader and the D3D9 declaration that has to be bound beside it.+ static HRESULT LoadAndCreateD3DVertexShader(const char* strFilePath, const DWORD* pDeclaration,+ IDirect3DVertexShader9** shader, IDirect3DVertexDeclaration9** declaration);static Bool testMinimumRequirements(ChipsetType *videoChipType, CpuType *cpuType, Int *cpuFreq, Int *numRAM, Real *intBenchIndex, Real *floatBenchIndex, Real *memBenchIndex);static StaticGameLODLevel getGPUPerformanceIndex(void);@@ -108,8 +114,8 @@ public:// Support routines for filter methods.static Bool canRenderToTexture(void) { return (m_oldRenderSurface && m_newRenderSurface);}static void startRenderToTexture(void); ///< Sets render target to texture.- static IDirect3DTexture8 * endRenderToTexture(void); ///< Ends render to texture, & returns texture.- static IDirect3DTexture8 * getRenderTexture(void); ///< returns last used render target texture+ static IDirect3DTexture9 * endRenderToTexture(void); ///< Ends render to texture, & returns texture.+ static IDirect3DTexture9 * getRenderTexture(void); ///< returns last used render target texturestatic Bool isRenderingToTexture(void) {return m_renderingToTexture; }static void drawViewport(Int color); ///<draws 2 triangles covering the current tactical viewport@@ -125,10 +131,10 @@ protected:static FilterTypes m_currentFilter; ///< Last filter that was set.// Info for a render to texture surface for special effects.static Bool m_renderingToTexture;- static IDirect3DSurface8 *m_oldRenderSurface; ///<previous render target- static IDirect3DTexture8 *m_renderTexture; ///<texture into which rendering will be redirected.- static IDirect3DSurface8 *m_newRenderSurface; ///<new render target inside m_renderTexture- static IDirect3DSurface8 *m_oldDepthSurface; ///<previous depth buffer surface+ static IDirect3DSurface9 *m_oldRenderSurface; ///<previous render target+ static IDirect3DTexture9 *m_renderTexture; ///<texture into which rendering will be redirected.+ static IDirect3DSurface9 *m_newRenderSurface; ///<new render target inside m_renderTexture+ static IDirect3DSurface9 *m_oldDepthSurface; ///<previous depth buffer surface};@@ -187,7 +193,7 @@ protected:///converts viewport to black & white.class ScreenBWFilter : public W3DFilterInterface{- DWORD m_dwBWPixelShader; ///<D3D handle to pixel shader which tints texture to black & white.+ IDirect3DPixelShader9 * m_dwBWPixelShader; ///<pixel shader which tints texture to black & white.public:virtual Int init(void); ///<perform any one time initialization and validationvirtual Int shutdown(void); ///<release resources used by shaderdiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShroud.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShroud.hindex 06520a4af..d9149c567 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShroud.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShroud.h@@ -110,7 +110,7 @@ protected:Real m_cellWidth; ///<spacing between adjacent cellsReal m_cellHeight; ///<spacing between adjacent cellsByte *m_shroudData; ///<holds amount of shroud per cell.- IDirect3DSurface8 *m_pSrcTexture; ///<stores sysmem copy of visible shroud.+ IDirect3DSurface9 *m_pSrcTexture; ///<stores sysmem copy of visible shroud.void *m_srcTextureData; ///<pointer to shroud dataUnsignedInt m_srcTexturePitch; ///<width (in bytes) of shroud data buffer.TextureClass *m_pDstTexture; ///<stores vidmem copy of visible shroud.diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.hindex e926fb7f1..2346878e8 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h@@ -26,7 +26,7 @@class DX8IndexBufferClass;class RenderInfoClass;class TextureClass;-struct IDirect3DVertexBuffer8;+struct IDirect3DVertexBuffer9;class W3DSnowManager : public SnowManager{@@ -49,7 +49,7 @@ class W3DSnowManager : public SnowManagerprivate:DX8IndexBufferClass *m_indexBuffer;TextureClass *m_snowTexture;- IDirect3DVertexBuffer8* m_VertexBufferD3D;+ IDirect3DVertexBuffer9* m_VertexBufferD3D;Int m_dwBase; ///<index to beginning of unused vertex buffer space.Int m_dwFlush; ///<maximum amount of vertices to sumbit before rendering.Int m_dwDiscard; ///<maximum index allowed before needing to discard the buffer.diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.hindex 28a14aa27..f077f4778 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h@@ -256,8 +256,9 @@ private:MAX_SHADOW_BATCH_VERTEX = 8000}; ///< per texture, per frameDX8VertexBufferClass *m_vertexTree[MAX_BUFFERS]; ///<Tree vertex buffer.DX8IndexBufferClass *m_indexTree[MAX_BUFFERS]; ///<indices defining a triangles for the tree drawing.- DWORD m_dwTreePixelShader; ///<handle to D3D pixel shader- DWORD m_dwTreeVertexShader; ///<handle to D3D vertex shader+ IDirect3DPixelShader9 * m_dwTreePixelShader; ///<D3D pixel shader+ IDirect3DVertexShader9 * m_dwTreeVertexShader; ///<D3D vertex shader+ IDirect3DVertexDeclaration9 * m_treeVertexDeclaration; ///<what D3D8 carried beside the shaderShort m_areaPartition[PARTITION_WIDTH_HEIGHT*PARTITION_WIDTH_HEIGHT];Region2D m_bounds;diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.hindex eccef2079..7ffc6bb0e 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h@@ -159,16 +159,17 @@ protected:float tu, tv;};- LPDIRECT3DDEVICE8 m_pDev; ///<pointer to D3D Device- LPDIRECT3DVERTEXBUFFER8 m_vertexBufferD3D; ///<D3D vertex buffer- LPDIRECT3DINDEXBUFFER8 m_indexBufferD3D; ///<D3D index buffer+ LPDIRECT3DDEVICE9 m_pDev; ///<pointer to D3D Device+ LPDIRECT3DVERTEXBUFFER9 m_vertexBufferD3D; ///<D3D vertex buffer+ LPDIRECT3DINDEXBUFFER9 m_indexBufferD3D; ///<D3D index bufferInt m_vertexBufferD3DOffset; ///<location to start writing vertices- DWORD m_dwWavePixelShader; ///<handle to D3D pixel shader- DWORD m_dwWaveVertexShader; ///<handle to D3D vertex shader+ IDirect3DPixelShader9 * m_dwWavePixelShader; ///<D3D pixel shader+ IDirect3DVertexShader9 * m_dwWaveVertexShader; ///<D3D vertex shader+ IDirect3DVertexDeclaration9 * m_waveVertexDeclaration; ///<what D3D8 carried beside the shaderInt m_numVertices; ///<number of vertices in D3D vertex bufferInt m_numIndices; ///<number of indices in D3D index buffer- LPDIRECT3DTEXTURE8 m_pBumpTexture[NUM_BUMP_FRAMES]; ///<animation frames- LPDIRECT3DTEXTURE8 m_pBumpTexture2[NUM_BUMP_FRAMES]; ///<animation frames+ LPDIRECT3DTEXTURE9 m_pBumpTexture[NUM_BUMP_FRAMES]; ///<animation frames+ LPDIRECT3DTEXTURE9 m_pBumpTexture2[NUM_BUMP_FRAMES]; ///<animation framesInt m_iBumpFrame; ///<current animation frameReal m_bumpFrameAccum; ///<fractional carry, so the flipbook can run slower than one frame per tickReal m_fBumpScale; ///<scales bump map uv perturbation@@ -212,9 +213,9 @@ protected:TextureClass *m_riverTexture;TextureClass *m_whiteTexture; ///< a texture containing only white used for NULL pixel shader stages.TextureClass *m_waterNoiseTexture;- DWORD m_waterPixelShader; ///<D3D handle to pixel shader.- DWORD m_riverWaterPixelShader; ///<D3D handle to pixel shader.- DWORD m_trapezoidWaterPixelShader; ///<handle to D3D vertex shader+ IDirect3DPixelShader9 * m_waterPixelShader; ///<D3D pixel shader.+ IDirect3DPixelShader9 * m_riverWaterPixelShader; ///<D3D pixel shader.+ IDirect3DPixelShader9 * m_trapezoidWaterPixelShader; ///<D3D pixel shaderTextureClass *m_waterSparklesTexture;Real m_riverXOffset;Real m_riverYOffset;@@ -248,7 +249,7 @@ protected:void testCurvedWater(void); ///<draw the sky layer (clouds, stars, etc.)void renderSkyBody(Matrix3D *mat); ///<draw the sky body (sun, moon, etc.)void renderWaterMesh(void); ///<draw the water surface mesh (deformed 3d mesh).- HRESULT initBumpMap(LPDIRECT3DTEXTURE8 *pTex, TextureClass *pBumpSource); ///<copies data into bump-map format.+ HRESULT initBumpMap(LPDIRECT3DTEXTURE9 *pTex, TextureClass *pBumpSource); ///<copies data into bump-map format.void renderMirror(CameraClass *cam); ///< Draw reflected scene into texturevoid drawSea(RenderInfoClass & rinfo); ///< Draw the surface of the water///bounding box of frustum clipped polygon planediff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cppindex bed57084d..ed284a56b 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp@@ -56,7 +56,7 @@#include <coltest.h>#include <rinfo.h>#include <camera.h>-#include <d3dx8core.h>+#include "d3dx9runtime.h"#include "Common/GlobalData.h"#include "Common/PerfTimer.h"@@ -1498,7 +1498,7 @@ RenderObjClass * BaseHeightMapRenderObjClass::Clone(void) const//=============================================================================void BaseHeightMapRenderObjClass::loadRoadsAndBridges(W3DTerrainLogic *pTerrainLogic, Bool saveGame){- if (DX8Wrapper::_Get_D3D_Device8() && (DX8Wrapper::_Get_D3D_Device8()->TestCooperativeLevel()) != D3D_OK)+ if (DX8Wrapper::_Get_D3D_Device() && (DX8Wrapper::_Get_D3D_Device()->TestCooperativeLevel()) != D3D_OK)return; //device not ready to render anything#ifdef DO_ROADSdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/FlatHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/FlatHeightMap.cppindex 900d660a4..096f85cd6 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/FlatHeightMap.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/FlatHeightMap.cpp@@ -57,7 +57,7 @@#include <coltest.h>#include <rinfo.h>#include <camera.h>-#include <d3dx8core.h>+#include "d3dx9runtime.h"#include "Common/GlobalData.h"#include "Common/PerfTimer.h"diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cppindex 0c230822b..f03627a31 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp@@ -61,7 +61,7 @@#include <coltest.h>#include <rinfo.h>#include <camera.h>-#include <d3dx8core.h>+#include "d3dx9runtime.h"#include "Common/GlobalData.h"#include "Common/PerfTimer.h"@@ -2051,17 +2051,18 @@ void HeightMapRenderObjClass::Render(RenderInfoClass & rinfo)if (m_xformedVertexBuffer && pass==0) {// Note - m_xformedVertexBuffer should only be used for non T&L hardware. jba.DX8Wrapper::Apply_Render_State_Changes();- int code = DX8Wrapper::_Get_D3D_Device8()->ProcessVertices(0, 0, numVertex, m_xformedVertexBuffer[j*m_numVBTilesX+i], 0);+ int code = DX8Wrapper::_Get_D3D_Device()->ProcessVertices(0, 0, numVertex, m_xformedVertexBuffer[j*m_numVBTilesX+i], 0);::OutputDebugString("did process vertex\n");}if (m_xformedVertexBuffer) {// Note - m_xformedVertexBuffer should only be used for non T&L hardware. jba.DX8Wrapper::Apply_Render_State_Changes();- DX8Wrapper::_Get_D3D_Device8()->SetStreamSource(+ DX8Wrapper::_Get_D3D_Device()->SetStreamSource(0,m_xformedVertexBuffer[j*m_numVBTilesX+i],- D3DXGetFVFVertexSize(D3DFVF_XYZRHW |D3DFVF_DIFFUSE|D3DFVF_TEX2));- DX8Wrapper::_Get_D3D_Device8()->SetVertexShader(D3DFVF_XYZRHW |D3DFVF_DIFFUSE|D3DFVF_TEX2);+ 0,+ Get_FVF_Vertex_Size(D3DFVF_XYZRHW |D3DFVF_DIFFUSE|D3DFVF_TEX2));+ DX8Wrapper::_Get_D3D_Device()->SetFVF(D3DFVF_XYZRHW |D3DFVF_DIFFUSE|D3DFVF_TEX2);}#endifif (Is_Hidden() == 0) {@@ -2204,17 +2205,17 @@ void HeightMapRenderObjClass::renderTerrainPass(CameraClass *pCamera)if (m_xformedVertexBuffer && pass==0) {// Note - m_xformedVertexBuffer should only be used for non T&L hardware. jba.DX8Wrapper::Apply_Render_State_Changes();- int code = DX8Wrapper::_Get_D3D_Device8()->ProcessVertices(0, 0, numVertex, m_xformedVertexBuffer[j*m_numVBTilesX+i], 0);+ int code = DX8Wrapper::_Get_D3D_Device()->ProcessVertices(0, 0, numVertex, m_xformedVertexBuffer[j*m_numVBTilesX+i], 0);::OutputDebugString("did process vertex\n");}if (m_xformedVertexBuffer) {// Note - m_xformedVertexBuffer should only be used for non T&L hardware. jba.DX8Wrapper::Apply_Render_State_Changes();- DX8Wrapper::_Get_D3D_Device8()->SetStreamSource(+ DX8Wrapper::_Get_D3D_Device()->SetStreamSource(0,m_xformedVertexBuffer[j*m_numVBTilesX+i],- D3DXGetFVFVertexSize(D3DFVF_XYZRHW |D3DFVF_DIFFUSE|D3DFVF_TEX2));- DX8Wrapper::_Get_D3D_Device8()->SetVertexShader(D3DFVF_XYZRHW |D3DFVF_DIFFUSE|D3DFVF_TEX2);+ Get_FVF_Vertex_Size(D3DFVF_XYZRHW |D3DFVF_DIFFUSE|D3DFVF_TEX2));+ DX8Wrapper::_Get_D3D_Device()->SetFVF(D3DFVF_XYZRHW |D3DFVF_DIFFUSE|D3DFVF_TEX2);}#endifif (Is_Hidden() == 0) {diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cppindex a65ac5472..1642ac59f 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp@@ -46,7 +46,7 @@#include "Lib/BaseType.h"#include "W3DDevice/GameClient/W3DGranny.h"#include "W3DDevice/GameClient/Heightmap.h"-#include "D3dx8math.h"+#include "d3dx9math.h"#include "common/GlobalData.h"#include "W3DDevice/GameClient/W3DProjectedShadow.h"#include "WW3D2/statistics.h"@@ -85,8 +85,8 @@ W3DProjectedShadowManager *TheW3DProjectedShadowManager=NULL; //global singletonProjectedShadowManager *TheProjectedShadowManager; //global singleton with simpler interface.extern const FrustumClass *shadowCameraFrustum; //defined in W3DShadow.///@todo: Externs from volumetric shadow renderer - these need to be moved into W3DBufferManager-extern LPDIRECT3DVERTEXBUFFER8 shadowVertexBufferD3D; ///<D3D vertex buffer-extern LPDIRECT3DINDEXBUFFER8 shadowIndexBufferD3D; ///<D3D index buffer+extern LPDIRECT3DVERTEXBUFFER9 shadowVertexBufferD3D; ///<D3D vertex buffer+extern LPDIRECT3DINDEXBUFFER9 shadowIndexBufferD3D; ///<D3D index bufferextern int nShadowVertsInBuf; //model vetices in vertex bufferextern int nShadowStartBatchVertex;extern int nShadowIndicesInBuf; //model vetices in vertex buffer@@ -110,8 +110,8 @@ struct SHADOW_DECAL_VERTEX //vertex structure passed to D3D#define SHADOW_DECAL_FVF D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_DIFFUSE-LPDIRECT3DVERTEXBUFFER8 shadowDecalVertexBufferD3D=NULL; ///<D3D vertex buffer-LPDIRECT3DINDEXBUFFER8 shadowDecalIndexBufferD3D=NULL; ///<D3D index buffer+LPDIRECT3DVERTEXBUFFER9 shadowDecalVertexBufferD3D=NULL; ///<D3D vertex buffer+LPDIRECT3DINDEXBUFFER9 shadowDecalIndexBufferD3D=NULL; ///<D3D index bufferint nShadowDecalVertsInBuf=0; //model vetices in vertex bufferint nShadowDecalStartBatchVertex=0;int nShadowDecalIndicesInBuf=0; //model vetices in vertex buffer@@ -284,7 +284,7 @@ Bool W3DProjectedShadowManager::ReAcquireResources(void)m_dynamicRenderTarget=DX8Wrapper::Create_Render_Target (DEFAULT_RENDER_TARGET_WIDTH, DEFAULT_RENDER_TARGET_HEIGHT);}- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();DEBUG_ASSERTCRASH(m_pDev, ("Trying to ReAquireResources on W3DProjectedShadowManager without device"));DEBUG_ASSERTCRASH(shadowDecalIndexBufferD3D == NULL && shadowDecalIndexBufferD3D == NULL, ("ReAquireResources not released in W3DProjectedShadowManager"));@@ -294,8 +294,9 @@ Bool W3DProjectedShadowManager::ReAcquireResources(void)SHADOW_DECAL_INDEX_SIZE*sizeof(WORD),D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,D3DFMT_INDEX16,- D3DPOOL_DEFAULT,- &shadowDecalIndexBufferD3D+ D3DPOOL_DEFAULT,+ &shadowDecalIndexBufferD3D,+ NULL // pSharedHandle, D3D9's extra parameter, reserved and always null)))return FALSE;@@ -307,8 +308,9 @@ Bool W3DProjectedShadowManager::ReAcquireResources(void)SHADOW_DECAL_VERTEX_SIZE*sizeof(SHADOW_DECAL_VERTEX),D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,0,- D3DPOOL_DEFAULT,- &shadowDecalVertexBufferD3D+ D3DPOOL_DEFAULT,+ &shadowDecalVertexBufferD3D,+ NULL // pSharedHandle, D3D9's extra parameter, reserved and always null)))return FALSE;}@@ -382,7 +384,7 @@ Int W3DProjectedShadowManager::renderProjectedTerrainShadow(W3DProjectedShadow *Real mapScaleInv=1.0f/MAP_XY_FACTOR;SHADOW_VOLUME_VERTEX* pvVertices;UnsignedShort *pvIndices;- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev) return 0;@@ -408,13 +410,13 @@ Int W3DProjectedShadowManager::renderProjectedTerrainShadow(W3DProjectedShadow *if (nShadowVertsInBuf > (SHADOW_VERTEX_SIZE-numVerts)) //check if room for model verts{ //flush the buffer by drawing the contents and re-locking again- if (shadowVertexBufferD3D->Lock(0,numVerts*sizeof(SHADOW_VOLUME_VERTEX),(unsigned char**)&pvVertices,D3DLOCK_DISCARD) != D3D_OK)+ if (shadowVertexBufferD3D->Lock(0,numVerts*sizeof(SHADOW_VOLUME_VERTEX),(void**)&pvVertices,D3DLOCK_DISCARD) != D3D_OK)return 0;nShadowVertsInBuf=0;nShadowStartBatchVertex=0;}else- { if (shadowVertexBufferD3D->Lock(nShadowVertsInBuf*sizeof(SHADOW_VOLUME_VERTEX),numVerts*sizeof(SHADOW_VOLUME_VERTEX), (unsigned char**)&pvVertices,D3DLOCK_NOOVERWRITE) != D3D_OK)+ { if (shadowVertexBufferD3D->Lock(nShadowVertsInBuf*sizeof(SHADOW_VOLUME_VERTEX),numVerts*sizeof(SHADOW_VOLUME_VERTEX), (void**)&pvVertices,D3DLOCK_NOOVERWRITE) != D3D_OK)return 0;}@@ -441,13 +443,13 @@ Int W3DProjectedShadowManager::renderProjectedTerrainShadow(W3DProjectedShadow *if (nShadowIndicesInBuf > (SHADOW_INDEX_SIZE-numIndex)) //check if room for model verts{ //flush the buffer by drawing the contents and re-locking again- if (shadowIndexBufferD3D->Lock(0,numIndex*sizeof(short),(unsigned char**)&pvIndices,D3DLOCK_DISCARD) != D3D_OK)+ if (shadowIndexBufferD3D->Lock(0,numIndex*sizeof(short),(void**)&pvIndices,D3DLOCK_DISCARD) != D3D_OK)return 0;nShadowIndicesInBuf=0;nShadowStartBatchIndex=0;}else- { if (shadowIndexBufferD3D->Lock(nShadowIndicesInBuf*sizeof(short),numIndex*sizeof(short), (unsigned char**)&pvIndices,D3DLOCK_NOOVERWRITE) != D3D_OK)+ { if (shadowIndexBufferD3D->Lock(nShadowIndicesInBuf*sizeof(short),numIndex*sizeof(short), (void**)&pvIndices,D3DLOCK_NOOVERWRITE) != D3D_OK)return 0;}@@ -497,12 +499,13 @@ Int W3DProjectedShadowManager::renderProjectedTerrainShadow(W3DProjectedShadow *shadowIndexBufferD3D->Unlock();- m_pDev->SetIndices(shadowIndexBufferD3D,nShadowStartBatchVertex);+ // D3D9 takes the base vertex index on the draw call, not here.+ m_pDev->SetIndices(shadowIndexBufferD3D);m_pDev->SetTransform(D3DTS_WORLD,(_D3DMATRIX *)&mWorld);- m_pDev->SetStreamSource(0,shadowVertexBufferD3D,sizeof(SHADOW_VOLUME_VERTEX));- m_pDev->SetVertexShader(SHADOW_VOLUME_FVF);+ m_pDev->SetStreamSource(0,shadowVertexBufferD3D,0,sizeof(SHADOW_VOLUME_VERTEX));+ m_pDev->SetFVF(SHADOW_VOLUME_FVF);Int numPolys = (endX - startX)*(endY - startY)*2; //2 triangles per cell@@ -525,7 +528,7 @@ Int W3DProjectedShadowManager::renderProjectedTerrainShadow(W3DProjectedShadow *if (DX8Wrapper::_Is_Triangle_Draw_Enabled()){Debug_Statistics::Record_DX8_Polys_And_Vertices(numPolys,numVerts,ShaderClass::_PresetOpaqueShader);- m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,numVerts,nShadowStartBatchIndex,numPolys);+ m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,nShadowStartBatchVertex,0,numVerts,nShadowStartBatchIndex,numPolys);}m_pDev->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); //should reject background pixels@@ -696,7 +699,7 @@ void W3DProjectedShadowManager::flushDecals(W3DShadowTexture *texture, ShadowTypreturn;}- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev) return; //no D3D Device to renderVertexMaterialClass *vmat=VertexMaterialClass::Get_Preset(VertexMaterialClass::PRELIT_DIFFUSE);@@ -746,11 +749,12 @@ void W3DProjectedShadowManager::flushDecals(W3DShadowTexture *texture, ShadowTyp*/- m_pDev->SetIndices(shadowDecalIndexBufferD3D,nShadowDecalStartBatchVertex);+ // D3D9 takes the base vertex index on the draw call, not here.+ m_pDev->SetIndices(shadowDecalIndexBufferD3D);m_pDev->SetTransform(D3DTS_WORLD,(_D3DMATRIX *)&mWorld);- m_pDev->SetStreamSource(0,shadowDecalVertexBufferD3D,sizeof(SHADOW_DECAL_VERTEX));- m_pDev->SetVertexShader(SHADOW_DECAL_FVF);+ m_pDev->SetStreamSource(0,shadowDecalVertexBufferD3D,0,sizeof(SHADOW_DECAL_VERTEX));+ m_pDev->SetFVF(SHADOW_DECAL_FVF);//Hard Shadows using stencil/* m_pDev->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO);@@ -771,7 +775,7 @@ void W3DProjectedShadowManager::flushDecals(W3DShadowTexture *texture, ShadowTypif (DX8Wrapper::_Is_Triangle_Draw_Enabled()){Debug_Statistics::Record_DX8_Polys_And_Vertices(nShadowDecalPolysInBatch,nShadowDecalVertsInBatch,ShaderClass::_PresetOpaqueShader);- m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,nShadowDecalVertsInBatch,nShadowDecalStartBatchIndex,nShadowDecalPolysInBatch);+ m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,nShadowDecalStartBatchVertex,0,nShadowDecalVertsInBatch,nShadowDecalStartBatchIndex,nShadowDecalPolysInBatch);}// m_pDev->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); //should reject background pixels@@ -837,7 +841,7 @@ void W3DProjectedShadowManager::queueDecal(W3DProjectedShadow *shadow)if (TheTerrainRenderObject){- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev) return; //no D3D Device to render@@ -1023,7 +1027,7 @@ void W3DProjectedShadowManager::queueDecal(W3DProjectedShadow *shadow)if (nShadowDecalVertsInBuf > (SHADOW_DECAL_VERTEX_SIZE-numVerts)) //check if room for model verts{ //flush the buffer by drawing the contents and re-locking againflushDecals(shadow->m_shadowTexture[0], shadow->m_type);- if (shadowDecalVertexBufferD3D->Lock(0,numVerts*sizeof(SHADOW_DECAL_VERTEX),(unsigned char**)&pvVertices,D3DLOCK_DISCARD) != D3D_OK)+ if (shadowDecalVertexBufferD3D->Lock(0,numVerts*sizeof(SHADOW_DECAL_VERTEX),(void**)&pvVertices,D3DLOCK_DISCARD) != D3D_OK)return;nShadowDecalStartBatchVertex=0;@@ -1032,7 +1036,7 @@ void W3DProjectedShadowManager::queueDecal(W3DProjectedShadow *shadow)nShadowDecalVertsInBuf=0;}else- { if (shadowDecalVertexBufferD3D->Lock(nShadowDecalVertsInBuf*sizeof(SHADOW_DECAL_VERTEX),numVerts*sizeof(SHADOW_DECAL_VERTEX), (unsigned char**)&pvVertices,D3DLOCK_NOOVERWRITE) != D3D_OK)+ { if (shadowDecalVertexBufferD3D->Lock(nShadowDecalVertsInBuf*sizeof(SHADOW_DECAL_VERTEX),numVerts*sizeof(SHADOW_DECAL_VERTEX), (void**)&pvVertices,D3DLOCK_NOOVERWRITE) != D3D_OK)return;}@@ -1096,7 +1100,7 @@ void W3DProjectedShadowManager::queueDecal(W3DProjectedShadow *shadow){ //flush the buffer by drawing the contents and re-locking againflushDecals(shadow->m_shadowTexture[0], shadow->m_type);- if (shadowDecalIndexBufferD3D->Lock(0,numIndex*sizeof(short),(unsigned char**)&pvIndices,D3DLOCK_DISCARD) != D3D_OK)+ if (shadowDecalIndexBufferD3D->Lock(0,numIndex*sizeof(short),(void**)&pvIndices,D3DLOCK_DISCARD) != D3D_OK)return;nShadowDecalStartBatchIndex=0;@@ -1105,7 +1109,7 @@ void W3DProjectedShadowManager::queueDecal(W3DProjectedShadow *shadow)nShadowDecalIndicesInBuf=0;}else- { if (shadowDecalIndexBufferD3D->Lock(nShadowDecalIndicesInBuf*sizeof(short),numIndex*sizeof(short), (unsigned char**)&pvIndices,D3DLOCK_NOOVERWRITE) != D3D_OK)+ { if (shadowDecalIndexBufferD3D->Lock(nShadowDecalIndicesInBuf*sizeof(short),numIndex*sizeof(short), (void**)&pvIndices,D3DLOCK_NOOVERWRITE) != D3D_OK)return;}@@ -1172,7 +1176,7 @@ void W3DProjectedShadowManager::queueSimpleDecal(W3DProjectedShadow *shadow)if (TheTerrainRenderObject){- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev) return; //no D3D Device to render@@ -1199,7 +1203,7 @@ void W3DProjectedShadowManager::queueSimpleDecal(W3DProjectedShadow *shadow)if (nShadowDecalVertsInBuf > (SHADOW_DECAL_VERTEX_SIZE-numVerts)) //check if room for model verts{ //flush the buffer by drawing the contents and re-locking againflushDecals(shadow->m_shadowTexture[0], shadow->m_type);- if (shadowDecalVertexBufferD3D->Lock(0,numVerts*sizeof(SHADOW_DECAL_VERTEX),(unsigned char**)&pvVertices,D3DLOCK_DISCARD) != D3D_OK)+ if (shadowDecalVertexBufferD3D->Lock(0,numVerts*sizeof(SHADOW_DECAL_VERTEX),(void**)&pvVertices,D3DLOCK_DISCARD) != D3D_OK)return;nShadowDecalStartBatchVertex=0;@@ -1208,7 +1212,7 @@ void W3DProjectedShadowManager::queueSimpleDecal(W3DProjectedShadow *shadow)nShadowDecalVertsInBuf=0;}else- { if (shadowDecalVertexBufferD3D->Lock(nShadowDecalVertsInBuf*sizeof(SHADOW_DECAL_VERTEX),numVerts*sizeof(SHADOW_DECAL_VERTEX), (unsigned char**)&pvVertices,D3DLOCK_NOOVERWRITE) != D3D_OK)+ { if (shadowDecalVertexBufferD3D->Lock(nShadowDecalVertsInBuf*sizeof(SHADOW_DECAL_VERTEX),numVerts*sizeof(SHADOW_DECAL_VERTEX), (void**)&pvVertices,D3DLOCK_NOOVERWRITE) != D3D_OK)return;}@@ -1261,7 +1265,7 @@ void W3DProjectedShadowManager::queueSimpleDecal(W3DProjectedShadow *shadow){ //flush the buffer by drawing the contents and re-locking againflushDecals(shadow->m_shadowTexture[0],shadow->m_type);- if (shadowDecalIndexBufferD3D->Lock(0,numIndex*sizeof(short),(unsigned char**)&pvIndices,D3DLOCK_DISCARD) != D3D_OK)+ if (shadowDecalIndexBufferD3D->Lock(0,numIndex*sizeof(short),(void**)&pvIndices,D3DLOCK_DISCARD) != D3D_OK)return;nShadowDecalStartBatchIndex=0;@@ -1270,7 +1274,7 @@ void W3DProjectedShadowManager::queueSimpleDecal(W3DProjectedShadow *shadow)nShadowDecalIndicesInBuf=0;}else- { if (shadowDecalIndexBufferD3D->Lock(nShadowDecalIndicesInBuf*sizeof(short),numIndex*sizeof(short), (unsigned char**)&pvIndices,D3DLOCK_NOOVERWRITE) != D3D_OK)+ { if (shadowDecalIndexBufferD3D->Lock(nShadowDecalIndicesInBuf*sizeof(short),numIndex*sizeof(short), (void**)&pvIndices,D3DLOCK_NOOVERWRITE) != D3D_OK)return;}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cppindex f3dc9375d..1b762c5be 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp@@ -43,7 +43,7 @@#include "Lib/BaseType.h"#include "W3DDevice/GameClient/W3DGranny.h"#include "W3DDevice/GameClient/Heightmap.h"-#include "D3dx8math.h"+#include "d3dx9math.h"#include "common/GlobalData.h"#include "W3DDevice/GameClient/W3DVolumetricShadow.h"#include "W3DDevice/GameClient/W3DProjectedShadow.h"diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cppindex 1f478d8c0..d17dddf93 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp@@ -49,7 +49,7 @@#include "Lib/BaseType.h"#include "W3DDevice/GameClient/W3DGranny.h"#include "W3DDevice/GameClient/Heightmap.h"-#include "D3dx8math.h"+#include "d3dx9math.h"#include "common/GlobalData.h"#include "common/drawmodule.h"#include "W3DDevice/GameClient/W3DVolumetricShadow.h"@@ -112,8 +112,8 @@ struct SHADOW_STATIC_VOLUME_VERTEX //vertex structure passed to D3D#define SHADOW_DYNAMIC_VOLUME_FVF D3DFVF_XYZ#endif-LPDIRECT3DVERTEXBUFFER8 shadowVertexBufferD3D=NULL; ///<D3D vertex buffer-LPDIRECT3DINDEXBUFFER8 shadowIndexBufferD3D=NULL; ///<D3D index buffer+LPDIRECT3DVERTEXBUFFER9 shadowVertexBufferD3D=NULL; ///<D3D vertex buffer+LPDIRECT3DINDEXBUFFER9 shadowIndexBufferD3D=NULL; ///<D3D index bufferint nShadowVertsInBuf=0; //model vetices in vertex bufferint nShadowStartBatchVertex=0;int nShadowIndicesInBuf=0; //model vetices in vertex buffer@@ -130,7 +130,7 @@ static Real beX;static Real beY;static Real beZ;-static LPDIRECT3DVERTEXBUFFER8 lastActiveVertexBuffer=NULL;+static LPDIRECT3DVERTEXBUFFER9 lastActiveVertexBuffer=NULL;/** A simple structure to hold random geometry (vertices, polygons, etc.). We'll use this* to store shadow volumes. */@@ -1496,7 +1496,7 @@ void W3DVolumetricShadow::RenderMeshVolume(Int meshIndex, Int lightIndex, constInt numVerts, numPolys, numIndex;//Get D3D Device used by W3D for quicker access.- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev)return;@@ -1528,7 +1528,7 @@ void W3DVolumetricShadow::RenderMeshVolume(Int meshIndex, Int lightIndex, constreturn;if (vbSlot->m_VB->m_DX8VertexBuffer->Get_DX8_Vertex_Buffer() != lastActiveVertexBuffer){ lastActiveVertexBuffer=vbSlot->m_VB->m_DX8VertexBuffer->Get_DX8_Vertex_Buffer();- m_pDev->SetStreamSource(0,lastActiveVertexBuffer,+ m_pDev->SetStreamSource(0,lastActiveVertexBuffer,0,vbSlot->m_VB->m_DX8VertexBuffer->FVF_Info().Get_FVF_Size()); //12 bytes per vertex.}@@ -1540,12 +1540,13 @@ void W3DVolumetricShadow::RenderMeshVolume(Int meshIndex, Int lightIndex, constDEBUG_ASSERTCRASH(ibSlot->m_size >= numIndex,("Overflowing Shadow Index Buffer Slot"));- m_pDev->SetIndices(ibSlot->m_IB->m_DX8IndexBuffer->Get_DX8_Index_Buffer(),vbSlot->m_start);+ // D3D9 takes the base vertex index on the draw call, not here.+ m_pDev->SetIndices(ibSlot->m_IB->m_DX8IndexBuffer->Get_DX8_Index_Buffer());if (DX8Wrapper::_Is_Triangle_Draw_Enabled()){Debug_Statistics::Record_DX8_Polys_And_Vertices(numPolys,numVerts,ShaderClass::_PresetOpaqueShader);- m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,numVerts,ibSlot->m_start,numPolys);+ m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,vbSlot->m_start,0,numVerts,ibSlot->m_start,numPolys);}}@@ -1558,7 +1559,7 @@ void W3DVolumetricShadow::RenderDynamicMeshVolume(Int meshIndex, Int lightIndex,UnsignedShort *pvIndices;//Get D3D Device used by W3D for quicker access.- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev)return;@@ -1584,13 +1585,13 @@ void W3DVolumetricShadow::RenderDynamicMeshVolume(Int meshIndex, Int lightIndex,if (nShadowVertsInBuf > (SHADOW_VERTEX_SIZE-numVerts)) //check if room for model verts{ //flush the buffer by drawing the contents and re-locking again- if (shadowVertexBufferD3D->Lock(0,numVerts*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX),(unsigned char**)&pvVertices,D3DLOCK_DISCARD) != D3D_OK)+ if (shadowVertexBufferD3D->Lock(0,numVerts*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX),(void**)&pvVertices,D3DLOCK_DISCARD) != D3D_OK)return;nShadowVertsInBuf=0;nShadowStartBatchVertex=0;}else- { if (shadowVertexBufferD3D->Lock(nShadowVertsInBuf*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX),numVerts*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX), (unsigned char**)&pvVertices,D3DLOCK_NOOVERWRITE) != D3D_OK)+ { if (shadowVertexBufferD3D->Lock(nShadowVertsInBuf*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX),numVerts*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX), (void**)&pvVertices,D3DLOCK_NOOVERWRITE) != D3D_OK)return;}#ifdef SV_DEBUG@@ -1614,13 +1615,13 @@ void W3DVolumetricShadow::RenderDynamicMeshVolume(Int meshIndex, Int lightIndex,if (nShadowIndicesInBuf > (SHADOW_INDEX_SIZE-numIndex)) //check if room for model verts{ //flush the buffer by drawing the contents and re-locking again- if (shadowIndexBufferD3D->Lock(0,numIndex*sizeof(short),(unsigned char**)&pvIndices,D3DLOCK_DISCARD) != D3D_OK)+ if (shadowIndexBufferD3D->Lock(0,numIndex*sizeof(short),(void**)&pvIndices,D3DLOCK_DISCARD) != D3D_OK)return;nShadowIndicesInBuf=0;nShadowStartBatchIndex=0;}else- { if (shadowIndexBufferD3D->Lock(nShadowIndicesInBuf*sizeof(short),numIndex*sizeof(short), (unsigned char**)&pvIndices,D3DLOCK_NOOVERWRITE) != D3D_OK)+ { if (shadowIndexBufferD3D->Lock(nShadowIndicesInBuf*sizeof(short),numIndex*sizeof(short), (void**)&pvIndices,D3DLOCK_NOOVERWRITE) != D3D_OK)return;}@@ -1637,21 +1638,22 @@ void W3DVolumetricShadow::RenderDynamicMeshVolume(Int meshIndex, Int lightIndex,shadowIndexBufferD3D->Unlock();- m_pDev->SetIndices(shadowIndexBufferD3D,nShadowStartBatchVertex);+ // D3D9 takes the base vertex index on the draw call, not here.+ m_pDev->SetIndices(shadowIndexBufferD3D);Matrix4x4 mWorld(*meshXform);m_pDev->SetTransform(D3DTS_WORLD,(_D3DMATRIX *)&mWorld.Transpose());if (shadowVertexBufferD3D != lastActiveVertexBuffer)- { m_pDev->SetStreamSource(0,shadowVertexBufferD3D,sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX));+ { m_pDev->SetStreamSource(0,shadowVertexBufferD3D,0,sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX));lastActiveVertexBuffer = shadowVertexBufferD3D;}if (DX8Wrapper::_Is_Triangle_Draw_Enabled()){Debug_Statistics::Record_DX8_Polys_And_Vertices(numPolys,numVerts,ShaderClass::_PresetOpaqueShader);- m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,numVerts,nShadowStartBatchIndex,numPolys);+ m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,nShadowStartBatchVertex,0,numVerts,nShadowStartBatchIndex,numPolys);}nShadowVertsInBuf += numVerts;@@ -1701,7 +1703,7 @@ void W3DVolumetricShadow::RenderMeshVolumeBounds(Int meshIndex, Int lightIndex,static Vector3 verts[8];//Get D3D Device used by W3D for quicker access.- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev)return;@@ -1740,13 +1742,13 @@ void W3DVolumetricShadow::RenderMeshVolumeBounds(Int meshIndex, Int lightIndex,if (nShadowVertsInBuf > (SHADOW_VERTEX_SIZE-numVerts)) //check if room for model verts{ //flush the buffer by drawing the contents and re-locking again- if (shadowVertexBufferD3D->Lock(0,numVerts*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX),(unsigned char**)&pvVertices,D3DLOCK_DISCARD) != D3D_OK)+ if (shadowVertexBufferD3D->Lock(0,numVerts*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX),(void**)&pvVertices,D3DLOCK_DISCARD) != D3D_OK)return;nShadowVertsInBuf=0;nShadowStartBatchVertex=0;}else- { if (shadowVertexBufferD3D->Lock(nShadowVertsInBuf*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX),numVerts*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX), (unsigned char**)&pvVertices,D3DLOCK_NOOVERWRITE) != D3D_OK)+ { if (shadowVertexBufferD3D->Lock(nShadowVertsInBuf*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX),numVerts*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX), (void**)&pvVertices,D3DLOCK_NOOVERWRITE) != D3D_OK)return;}srand(0x1345465);@@ -1767,13 +1769,13 @@ void W3DVolumetricShadow::RenderMeshVolumeBounds(Int meshIndex, Int lightIndex,if (nShadowIndicesInBuf > (SHADOW_INDEX_SIZE-numIndex)) //check if room for model verts{ //flush the buffer by drawing the contents and re-locking again- if (shadowIndexBufferD3D->Lock(0,numIndex*sizeof(short),(unsigned char**)&pvIndices,D3DLOCK_DISCARD) != D3D_OK)+ if (shadowIndexBufferD3D->Lock(0,numIndex*sizeof(short),(void**)&pvIndices,D3DLOCK_DISCARD) != D3D_OK)return;;nShadowIndicesInBuf=0;nShadowStartBatchIndex=0;}else- { if (shadowIndexBufferD3D->Lock(nShadowIndicesInBuf*sizeof(short),numIndex*sizeof(short), (unsigned char**)&pvIndices,D3DLOCK_NOOVERWRITE) != D3D_OK)+ { if (shadowIndexBufferD3D->Lock(nShadowIndicesInBuf*sizeof(short),numIndex*sizeof(short), (void**)&pvIndices,D3DLOCK_NOOVERWRITE) != D3D_OK)return;}@@ -1790,7 +1792,8 @@ void W3DVolumetricShadow::RenderMeshVolumeBounds(Int meshIndex, Int lightIndex,shadowIndexBufferD3D->Unlock();- m_pDev->SetIndices(shadowIndexBufferD3D,nShadowStartBatchVertex);+ // D3D9 takes the base vertex index on the draw call, not here.+ m_pDev->SetIndices(shadowIndexBufferD3D);//todo: replace this with mesh transform@@ -1798,10 +1801,10 @@ void W3DVolumetricShadow::RenderMeshVolumeBounds(Int meshIndex, Int lightIndex,m_pDev->SetTransform(D3DTS_WORLD,(_D3DMATRIX *)&mWorld.Transpose());- m_pDev->SetStreamSource(0,shadowVertexBufferD3D,sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX));- m_pDev->SetVertexShader(SHADOW_DYNAMIC_VOLUME_FVF);+ m_pDev->SetStreamSource(0,shadowVertexBufferD3D,0,sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX));+ m_pDev->SetFVF(SHADOW_DYNAMIC_VOLUME_FVF);- m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,numVerts,nShadowStartBatchIndex,numPolys);+ m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,nShadowStartBatchVertex,0,numVerts,nShadowStartBatchIndex,numPolys);nShadowVertsInBuf += numVerts;nShadowStartBatchVertex=nShadowVertsInBuf;@@ -3610,7 +3613,7 @@ void W3DVolumetricShadow::resetSilhouette( Int meshIndex )// ============================================================================void W3DVolumetricShadowManager::renderStencilShadows( void ){- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev)return; //need device to render anything.@@ -3637,7 +3640,7 @@ void W3DVolumetricShadowManager::renderStencilShadows( void )//draw polygons like this is very inefficient but for only 2 triangles, it's//not worth bothering with index/vertex buffers.- m_pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);+ m_pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);// Use alpha blending to draw the transparent shadowm_pDev->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );@@ -3706,7 +3709,7 @@ void W3DVolumetricShadowManager::renderShadows( Bool forceStencilFill )if (m_shadowList && TheGlobalData->m_useShadowVolumes){- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev)return; //need device to render anything.@@ -3760,7 +3763,7 @@ void W3DVolumetricShadowManager::renderShadows( Bool forceStencilFill )#else//disable writes to color bufferif (DX8Wrapper::Get_Current_Caps()->Get_DX8_Caps().PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE)- { DX8Wrapper::_Get_D3D_Device8()->GetRenderState(D3DRS_COLORWRITEENABLE, &oldColorWriteEnable);+ { DX8Wrapper::_Get_D3D_Device()->GetRenderState(D3DRS_COLORWRITEENABLE, &oldColorWriteEnable);DX8Wrapper::Set_DX8_Render_State(D3DRS_COLORWRITEENABLE,0);}else@@ -3787,7 +3790,7 @@ void W3DVolumetricShadowManager::renderShadows( Bool forceStencilFill )m_pDev->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP );m_pDev->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_INCR );- m_pDev->SetVertexShader(SHADOW_DYNAMIC_VOLUME_FVF);+ m_pDev->SetFVF(SHADOW_DYNAMIC_VOLUME_FVF);m_pDev->SetRenderState(D3DRS_CULLMODE,D3DCULL_CW);// m_pDev->SetRenderState(D3DRS_ZBIAS,1); ///@todo: See if this helps or makes things worse.@@ -3836,7 +3839,7 @@ void W3DVolumetricShadowManager::renderShadows( Bool forceStencilFill )}// Set vertex format to that used by static shadow volumes- m_pDev->SetVertexShader(W3DBufferManager::getDX8Format(W3DBufferManager::VBM_FVF_XYZ));+ m_pDev->SetFVF(W3DBufferManager::getDX8Format(W3DBufferManager::VBM_FVF_XYZ));//Empty queue of static shadow volumes to render.W3DBufferManager::W3DVertexBuffer *nextVb;@@ -3872,7 +3875,7 @@ void W3DVolumetricShadowManager::renderShadows( Bool forceStencilFill )}}- m_pDev->SetVertexShader(SHADOW_DYNAMIC_VOLUME_FVF);+ m_pDev->SetFVF(SHADOW_DYNAMIC_VOLUME_FVF);//flush any dynamic shadow volumesshadowDynamicTask=m_dynamicShadowVolumesToRender;while (shadowDynamicTask)@@ -4040,7 +4043,7 @@ Bool W3DVolumetricShadowManager::ReAcquireResources(void){ReleaseResources();- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();DEBUG_ASSERTCRASH(m_pDev, ("Trying to ReAquireResources on W3DVolumetricShadowManager without device"));@@ -4049,8 +4052,9 @@ Bool W3DVolumetricShadowManager::ReAcquireResources(void)SHADOW_INDEX_SIZE*sizeof(WORD),D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,D3DFMT_INDEX16,- D3DPOOL_DEFAULT,- &shadowIndexBufferD3D+ D3DPOOL_DEFAULT,+ &shadowIndexBufferD3D,+ NULL // pSharedHandle, D3D9's extra parameter, reserved and always null)))return FALSE;@@ -4062,8 +4066,9 @@ Bool W3DVolumetricShadowManager::ReAcquireResources(void)SHADOW_VERTEX_SIZE*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX),D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,0,- D3DPOOL_DEFAULT,- &shadowVertexBufferD3D+ D3DPOOL_DEFAULT,+ &shadowVertexBufferD3D,+ NULL // pSharedHandle, D3D9's extra parameter, reserved and always null)))return FALSE;}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cppindex 17fada773..efc162758 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp@@ -52,7 +52,7 @@#include "W3DDevice/GameClient/TileData.h"#include "common/GlobalData.h"#include "WW3D2/dx8wrapper.h"-#include "d3dx8tex.h"+#include "d3dx9runtime.h"/******************************************************************************TerrainTextureClass@@ -103,7 +103,7 @@ int TerrainTextureClass::update(WorldHeightMap *htMap)return 0;}- IDirect3DSurface8 *surface_level;+ IDirect3DSurface9 *surface_level;D3DSURFACE_DESC surface_desc;D3DLOCKED_RECT locked_rect;DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0, &surface_level));@@ -225,7 +225,7 @@ int TerrainTextureClass::update(WorldHeightMap *htMap)return 0;}- IDirect3DSurface8 *surface_level;+ IDirect3DSurface9 *surface_level;D3DSURFACE_DESC surface_desc;D3DLOCKED_RECT locked_rect;DX8_ErrorCode(D3DTexture->GetSurfaceLevel(0, &surface_level));@@ -394,7 +394,7 @@ Bool TerrainTextureClass::updateFlat(WorldHeightMap *htMap, Int xCell, Int yCellreturn 0;}- IDirect3DSurface8 *surface_level;+ IDirect3DSurface9 *surface_level;D3DSURFACE_DESC surface_desc;D3DLOCKED_RECT locked_rect;DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0, &surface_level));@@ -458,21 +458,21 @@ void TerrainTextureClass::Apply(unsigned int stage)TextureClass::Apply(stage);#if 0 // obsolete [4/1/2003]if (TheGlobalData && TheGlobalData->m_bilinearTerrainTex || TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_POINT);}if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_POINT);}// Now setup the texture pipeline.if (stage==0) {- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );@@ -507,7 +507,7 @@ AlphaTerrainTextureClass::AlphaTerrainTextureClass( TextureClass *pBaseTex ):WW3D_FORMAT_A1R5G5B5, MIP_LEVELS_1 ){// Attach the base texture's d3d texture.- IDirect3DTexture8 * d3d_tex = pBaseTex->Peek_D3D_Texture();+ IDirect3DTexture9 * d3d_tex = pBaseTex->Peek_D3D_Texture();Set_D3D_Base_Texture(d3d_tex);}@@ -529,20 +529,20 @@ void AlphaTerrainTextureClass::Apply(unsigned int stage)// Set the bilinear or trilinear filtering.if (TheGlobalData && TheGlobalData->m_bilinearTerrainTex || TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_POINT);}if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_POINT);}// Since we are using multiple distinct tiles, the textures doesn't wrap, so clamp it.- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);// Now setup the texture pipeline.if (stage==0) {// Modulate the diffuse color with the texture as lighting comes from diffuse.@@ -696,13 +696,13 @@ void LightMapTerrainTextureClass::Apply(unsigned int stage)// Do the base apply./* previous setup */if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_POINT);}- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);// Disable 3rd stage just in case.DX8Wrapper::Set_DX8_Texture_Stage_State( 2, D3DTSS_COLOROP, D3DTOP_DISABLE );@@ -725,8 +725,8 @@ void LightMapTerrainTextureClass::Apply(unsigned int stage)DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);Matrix4x4 curView;DX8Wrapper::_Get_DX8_Transform(D3DTS_VIEW, curView);@@ -794,7 +794,7 @@ int AlphaEdgeTextureClass::update(WorldHeightMap *htMap)return 0;}- IDirect3DSurface8 *surface_level;+ IDirect3DSurface9 *surface_level;D3DSURFACE_DESC surface_desc;D3DLOCKED_RECT locked_rect;DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0, &surface_level));@@ -871,20 +871,20 @@ void AlphaEdgeTextureClass::Apply(unsigned int stage)#if 0 // obsolete [4/1/2003]if (TheGlobalData && TheGlobalData->m_bilinearTerrainTex || TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_POINT);}if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_POINT);}- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);// Now setup the texture pipeline.if (stage==0) {@@ -972,13 +972,13 @@ void CloudMapTerrainTextureClass::Apply(unsigned int stage)#if 0 // obsolete/* previous setup */if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_POINT);}- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);// Now setup the texture pipeline.DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);@@ -986,8 +986,8 @@ void CloudMapTerrainTextureClass::Apply(unsigned int stage)DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);Matrix4x4 curView;DX8Wrapper::_Get_DX8_Transform(D3DTS_VIEW, curView);@@ -1060,8 +1060,8 @@ void CloudMapTerrainTextureClass::restore(void)DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXCOORDINDEX, 0 );DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);@@ -1070,8 +1070,8 @@ void CloudMapTerrainTextureClass::restore(void)DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLOROP, D3DTOP_MODULATE );DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_TEXCOORDINDEX, 0 );DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);DX8Wrapper::Set_DX8_Render_State(D3DRS_ALPHABLENDENABLE,false);@@ -1133,21 +1133,21 @@ void ScorchTextureClass::Apply(unsigned int stage)TextureClass::Apply(stage);// Setup bilinear or trilinear filtering as specified in global data.if (TheGlobalData && TheGlobalData->m_bilinearTerrainTex || TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_POINT);}if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MIPFILTER, D3DTEXF_POINT);}DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);// Now setup the texture pipeline.DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex 31e820250..ab25eea7a 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -2117,7 +2117,7 @@ AGAIN:}// update all views of the world - recomputes data which will affect drawing- if (DX8Wrapper::_Get_D3D_Device8() && (DX8Wrapper::_Get_D3D_Device8()->TestCooperativeLevel()) == D3D_OK)+ if (DX8Wrapper::_Get_D3D_Device() && (DX8Wrapper::_Get_D3D_Device()->TestCooperativeLevel()) == D3D_OK){ //Checking if we have the device before updating views because the heightmap crashes otherwise while//trying to refresh the visible terrain geometry.// if(TheGlobalData->m_loadScreenRender != TRUE)@@ -3419,20 +3419,23 @@ static void CreateBMPFile(LPTSTR pszFile, char *image, Int width, Int height)// not possible. Taken at the end of draw(), before Present: the front-buffer path is a// desktop capture, and on the Direct3D 12 (9On12) runtime the window is presented through// a DXGI flip swap chain that desktop captures do not see - the old code saved black.-static IDirect3DSurface8 *captureBackBuffer(void)+static IDirect3DSurface9 *captureBackBuffer(void){- IDirect3DDevice8 *dev = DX8Wrapper::_Get_D3D_Device8();- IDirect3DSurface8 *bb = NULL;- if (dev == NULL || FAILED(dev->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &bb)) || bb == NULL)+ IDirect3DDevice9 *dev = DX8Wrapper::_Get_D3D_Device();+ IDirect3DSurface9 *bb = NULL;+ if (dev == NULL || FAILED(dev->GetBackBuffer(PRIMARY_SWAP_CHAIN, 0, D3DBACKBUFFER_TYPE_MONO, &bb)) || bb == NULL)return NULL;D3DSURFACE_DESC desc;bb->GetDesc(&desc);- IDirect3DSurface8 *copy = NULL;+ IDirect3DSurface9 *copy = NULL;if ((desc.Format == D3DFMT_X8R8G8B8 || desc.Format == D3DFMT_A8R8G8B8) && desc.MultiSampleType == D3DMULTISAMPLE_NONE){- if (SUCCEEDED(dev->CreateImageSurface(desc.Width, desc.Height, desc.Format, ©)) && copy != NULL- && FAILED(dev->CopyRects(bb, NULL, 0, copy, NULL)))+ // The back buffer is a render target, so the copy has to come off it with+ // GetRenderTargetData; UpdateSurface and StretchRect both refuse this direction.+ if (SUCCEEDED(dev->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format,+ D3DPOOL_SYSTEMMEM, ©, NULL)) && copy != NULL+ && FAILED(dev->GetRenderTargetData(bb, copy))){copy->Release();copy = NULL;@@ -3469,7 +3472,7 @@ static void saveScreenShot(void)}RECT bounds;- IDirect3DSurface8 *fb = captureBackBuffer();+ IDirect3DSurface9 *fb = captureBackBuffer();if (fb != NULL){D3DSURFACE_DESC desc;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cppindex 699452046..6157125f9 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp@@ -113,7 +113,7 @@ W3DMouse::W3DMouse( void )W3DMouse::~W3DMouse( void ){- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (m_pDev){@@ -392,7 +392,7 @@ void W3DMouse::setCursor( MouseCursor cursor ){SetCursor(NULL); //Kill Windows Cursor- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();Bool doImageChange=FALSE;if (m_pDev != NULL)@@ -488,7 +488,7 @@ void W3DMouse::draw(void){//called from upate thread or rendering loop. Tells D3D where//to draw the mouse cursor.- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (m_pDev){ m_pDev->ShowCursor(TRUE); //Enable DX8 cursordiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cppindex d9d5bf87f..2ec17f78c 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp@@ -994,7 +994,7 @@ void RTS3DScene::Render(RenderInfoClass & rinfo)//wireframe should be visible.///@todo: Clearing to black may not be needed if the scene already did the clear.DX8Wrapper::Set_DX8_Render_State(D3DRS_COLORWRITEENABLE,D3DCOLORWRITEENABLE_ALPHA);- DX8Wrapper::Set_DX8_Render_State (D3DRS_ZBIAS, 0);+ DX8Wrapper::Set_DX8_ZBias(0);//Since all objects will be rendered with same material, disable resetting until all are done.m_maskMaterialPass->setAllowUninstall(FALSE);@@ -1018,7 +1018,7 @@ void RTS3DScene::Render(RenderInfoClass & rinfo)///@todo: Clearing to black may not be needed if the scene already did the clear.DX8Wrapper::Clear(true, false, Vector3(0.0f,0.0f,0.0f),1.0f); // Clear color but not zDX8Wrapper::Set_DX8_Render_State(D3DRS_COLORWRITEENABLE,D3DCOLORWRITEENABLE_ALPHA);- DX8Wrapper::Set_DX8_Render_State (D3DRS_ZBIAS, 0);+ DX8Wrapper::Set_DX8_ZBias(0);//We're only filling the z-buffer so ignore normal textures and state changes to speed things up.m_customPassMode = SCENE_PASS_ALPHA_MASK;@@ -1050,7 +1050,7 @@ void RTS3DScene::Render(RenderInfoClass & rinfo)rinfo.Camera.Set_Zbuffer_Range(nearZ, farZ);rinfo.Camera.Apply();-// DX8Wrapper::Set_DX8_Render_State (D3DRS_ZBIAS, 0);+// DX8Wrapper::Set_DX8_ZBias(0);WW3D::Enable_Texturing(old_enable);WW3D::Enable_Coloring(0);@@ -1061,7 +1061,7 @@ void RTS3DScene::Render(RenderInfoClass & rinfo)//Disable writes to color buffer to save memory bandwidth - we only need Z.DX8Wrapper::Set_DX8_Render_State(D3DRS_COLORWRITEENABLE,0);- DX8Wrapper::Set_DX8_Render_State (D3DRS_ZBIAS, 0);+ DX8Wrapper::Set_DX8_ZBias(0);Customized_Render(rinfo);Flush(rinfo);//Re-enable writes to color buffer.@@ -1071,7 +1071,7 @@ void RTS3DScene::Render(RenderInfoClass & rinfo)case EXTRA_PASS_LINE:WW3D::Enable_Texturing(false);DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_WIREFRAME);- DX8Wrapper::Set_DX8_Render_State (D3DRS_ZBIAS, 7);+ DX8Wrapper::Set_DX8_ZBias(7);Customized_Render(rinfo);break;case EXTRA_PASS_CLEAR_LINE:@@ -1079,13 +1079,13 @@ void RTS3DScene::Render(RenderInfoClass & rinfo)WW3D::Enable_Texturing(false);WW3D::Enable_Coloring(0xff008000);DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_WIREFRAME);- DX8Wrapper::Set_DX8_Render_State (D3DRS_ZBIAS, 7);+ DX8Wrapper::Set_DX8_ZBias(7);Customized_Render(rinfo);break;}Flush(rinfo);DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_SOLID);- DX8Wrapper::Set_DX8_Render_State (D3DRS_ZBIAS, 0);+ DX8Wrapper::Set_DX8_ZBias(0);WW3D::Enable_Texturing(old_enable);WW3D::Enable_Coloring(0);ShaderClass::Invalidate();@@ -1276,14 +1276,14 @@ void renderStenciledPlayerColor( UnsignedInt color, UnsignedInt stencilRef, BoolREF_PTR_RELEASE(vmat);DX8Wrapper::Apply_Render_State_Changes(); //force update all renderstates- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev)return; //need device to render anything.//draw polygons like this is very inefficient but for only 2 triangles, it's//not worth bothering with index/vertex buffers.- m_pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);+ m_pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);// Set stencil statesDX8Wrapper::Set_DX8_Render_State(D3DRS_STENCILENABLE, TRUE );@@ -1303,7 +1303,7 @@ void renderStenciledPlayerColor( UnsignedInt color, UnsignedInt stencilRef, Bool//disable writes to color bufferif (DX8Wrapper::Get_Current_Caps()->Get_DX8_Caps().PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE)- { DX8Wrapper::_Get_D3D_Device8()->GetRenderState(D3DRS_COLORWRITEENABLE, &oldColorWriteEnable);+ { DX8Wrapper::_Get_D3D_Device()->GetRenderState(D3DRS_COLORWRITEENABLE, &oldColorWriteEnable);DX8Wrapper::Set_DX8_Render_State(D3DRS_COLORWRITEENABLE,0);}elsediff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cppindex ee9051ebb..4f4d5ddd9 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp@@ -71,7 +71,8 @@#include "GameLogic/GameLogic.h"#include "common/GlobalData.h"#include "common/GameLOD.h"-#include "d3dx8tex.h"+#include "d3dx9runtime.h"+#include "d3d8shadertranslate.h"#include "dx8caps.h"#include "common/gamelod.h"#include "Benchmark.h"@@ -109,8 +110,8 @@ public:///do any custom resetting necessary to bring W3D in sync.virtual void reset(void) {ShaderClass::Invalidate();- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, NULL);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1, NULL);};+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1, NULL);};virtual Int init(void) = 0; ///<perform any one time initialization and validationvirtual Int shutdown(void) { return TRUE;}; ///<release resources used by shaderprotected:@@ -130,10 +131,10 @@ GraphicsVenderID W3DShaderManager::m_currentVendor;__int64 W3DShaderManager::m_driverVersion;Bool W3DShaderManager::m_renderingToTexture = false;-IDirect3DSurface8 *W3DShaderManager::m_oldRenderSurface=NULL; ///<previous render target-IDirect3DTexture8 *W3DShaderManager::m_renderTexture=NULL; ///<texture into which rendering will be redirected.-IDirect3DSurface8 *W3DShaderManager::m_newRenderSurface=NULL; ///<new render target inside m_renderTexture-IDirect3DSurface8 *W3DShaderManager::m_oldDepthSurface=NULL; ///<previous depth buffer surface+IDirect3DSurface9 *W3DShaderManager::m_oldRenderSurface=NULL; ///<previous render target+IDirect3DTexture9 *W3DShaderManager::m_renderTexture=NULL; ///<texture into which rendering will be redirected.+IDirect3DSurface9 *W3DShaderManager::m_newRenderSurface=NULL; ///<new render target inside m_renderTexture+IDirect3DSurface9 *W3DShaderManager::m_oldDepthSurface=NULL; ///<previous depth buffer surface/*===========================================================================================*//*========= Screen Shaders =============================================================*//*===========================================================================================*/@@ -175,8 +176,8 @@ W3DFilterInterface *ScreenDefaultFilterList[]=#define BLOOM_DOWNSAMPLE 4 ///< bright pass and blur run at 1/4 of the screen in each axis-static IDirect3DTexture8 *s_bloomTexture[2]; ///< ping-pong render targets for the blur passes-static IDirect3DSurface8 *s_bloomSurface[2];+static IDirect3DTexture9 *s_bloomTexture[2]; ///< ping-pong render targets for the blur passes+static IDirect3DSurface9 *s_bloomSurface[2];static Int s_bloomWidth, s_bloomHeight;/** Bloom strength in percent - Options.ini's "Bloom" - 0 when it was never set. Read every@@ -212,7 +213,7 @@ static void releaseBloomTargets(void)/** Allocates the two quarter-size render targets, in the format of the scene texture they willbe downsampling. Lazily, because these live in D3DPOOL_DEFAULT and do not survive a devicereset - shutdown() drops them and the next frame builds them again. */-static Bool createBloomTargets(IDirect3DTexture8 *sceneTexture)+static Bool createBloomTargets(IDirect3DTexture9 *sceneTexture){if (s_bloomTexture[0] && s_bloomTexture[1]) return TRUE;@@ -222,11 +223,11 @@ static Bool createBloomTargets(IDirect3DTexture8 *sceneTexture)s_bloomHeight = desc.Height / BLOOM_DOWNSAMPLE;if (s_bloomWidth < 1 || s_bloomHeight < 1) return FALSE;- LPDIRECT3DDEVICE8 pDev = DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 pDev = DX8Wrapper::_Get_D3D_Device();for (Int i = 0; i < 2; i++){if (FAILED(pDev->CreateTexture(s_bloomWidth, s_bloomHeight, 1, D3DUSAGE_RENDERTARGET,- desc.Format, D3DPOOL_DEFAULT, &s_bloomTexture[i]))+ desc.Format, D3DPOOL_DEFAULT, &s_bloomTexture[i], NULL))|| FAILED(s_bloomTexture[i]->GetSurfaceLevel(0, &s_bloomSurface[i]))){releaseBloomTargets();@@ -258,8 +259,8 @@ static void drawBloomQuad(Real x, Real y, Real w, Real h,v[3].p = D3DXVECTOR4(x - 0.5f, y - 0.5f, 0.0f, 1.0f); v[3].u = u0; v[3].v = v0;for (Int i = 0; i < 4; i++) v[i].color = color;- LPDIRECT3DDEVICE8 pDev = DX8Wrapper::_Get_D3D_Device8();- pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);+ LPDIRECT3DDEVICE9 pDev = DX8Wrapper::_Get_D3D_Device();+ pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);pDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(_TRANS_LIT_TEX_VERTEX));}@@ -268,21 +269,21 @@ static void drawBloomQuad(Real x, Real y, Real w, Real h,[u0,v0]..[u1,v1] is the part of it the viewport occupies. Every state here is set straighton the device, like the rest of the filters do - ScreenDefaultFilter::reset() invalidates thewrapper's whole state cache afterwards, so nothing needs putting back by hand. */-static void renderBloom(IDirect3DTexture8 *sceneTexture, Real x, Real y, Real w, Real h,+static void renderBloom(IDirect3DTexture9 *sceneTexture, Real x, Real y, Real w, Real h,Real u0, Real v0, Real u1, Real v1){if (!createBloomTargets(sceneTexture)) return;- LPDIRECT3DDEVICE8 pDev = DX8Wrapper::_Get_D3D_Device8();- IDirect3DSurface8 *oldTarget = NULL, *oldDepth = NULL;- if (FAILED(pDev->GetRenderTarget(&oldTarget)) || oldTarget == NULL) return;+ LPDIRECT3DDEVICE9 pDev = DX8Wrapper::_Get_D3D_Device();+ IDirect3DSurface9 *oldTarget = NULL, *oldDepth = NULL;+ if (FAILED(pDev->GetRenderTarget(PRIMARY_RENDER_TARGET, &oldTarget)) || oldTarget == NULL) return;pDev->GetDepthStencilSurface(&oldDepth); //can legitimately be NULL//Bright pass. Anything darker than the threshold subtracts away to black and what survives//is how far above it the pixel was - a soft knee rather than a hard cut, which is what stops//sunlit sand from popping in and out of the effect as the camera moves.const Int t = bloomThreshold();- pDev->SetRenderTarget(s_bloomSurface[0], NULL); //no depth buffer: none of this is depth tested+ DX8Wrapper::_Set_DX8_Render_Target(s_bloomSurface[0], NULL); //no depth buffer: none of this is depth testedpDev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);pDev->SetRenderState(D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB(255, t, t, t));pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SUBTRACT);@@ -304,7 +305,7 @@ static void renderBloom(IDirect3DTexture8 *sceneTexture, Real x, Real y, Real w,const Int dst = (pass + 1) & 1;const Real ox = (pass ? 3.5f : 1.5f) / (Real)s_bloomWidth;const Real oy = (pass ? 3.5f : 1.5f) / (Real)s_bloomHeight;- pDev->SetRenderTarget(s_bloomSurface[dst], NULL);+ DX8Wrapper::_Set_DX8_Render_Target(s_bloomSurface[dst], NULL);pDev->SetTexture(0, s_bloomTexture[src]);for (Int tap = 0; tap < 4; tap++){@@ -318,7 +319,7 @@ static void renderBloom(IDirect3DTexture8 *sceneTexture, Real x, Real y, Real w,//Composite: add the blurred highlights back over the scene.const Int i = bloomIntensity() * 255 / 100;- pDev->SetRenderTarget(oldTarget, oldDepth);+ DX8Wrapper::_Set_DX8_Render_Target(oldTarget, oldDepth);pDev->SetTexture(0, s_bloomTexture[0]); //the second blur pass wrote target 0pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);drawBloomQuad(x, y, w, h, 0.0f, 0.0f, 1.0f, 1.0f, D3DCOLOR_ARGB(255, i, i, i));@@ -374,12 +375,12 @@ Bool ScreenDefaultFilter::preRender(Bool &skipRender, CustomScenePassModes &scenBool ScreenDefaultFilter::postRender(enum FilterModes mode, Coord2D &scrollDelta,Bool &doExtraRender){- IDirect3DTexture8 * tex = W3DShaderManager::endRenderToTexture();+ IDirect3DTexture9 * tex = W3DShaderManager::endRenderToTexture();DEBUG_ASSERTCRASH(tex, ("Require rendered texture."));if (!tex) return false;if (!set(mode)) return false;- LPDIRECT3DDEVICE8 pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 pDev=DX8Wrapper::_Get_D3D_Device();struct _TRANS_LIT_TEX_VERTEX {D3DXVECTOR4 p;@@ -390,7 +391,7 @@ Bool ScreenDefaultFilter::postRender(enum FilterModes mode, Coord2D &scrollDeltaInt xpos, ypos, width, height;- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0,tex); //previously rendered frame inside this texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0,tex); //previously rendered frame inside this textureTheTacticalView->getOrigin(&xpos,&ypos);width=TheTacticalView->getWidth();height=TheTacticalView->getHeight();@@ -414,7 +415,7 @@ Bool ScreenDefaultFilter::postRender(enum FilterModes mode, Coord2D &scrollDelta//draw polygons like this is very inefficient but for only 2 triangles, it's//not worth bothering with index/vertex buffers.- pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);+ pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);pDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(_TRANS_LIT_TEX_VERTEX));@@ -451,7 +452,7 @@ Int ScreenDefaultFilter::set(enum FilterModes mode)void ScreenDefaultFilter::reset(void){- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0,NULL); //previously rendered frame inside this texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0,NULL); //previously rendered frame inside this textureDX8Wrapper::Invalidate_Cached_Render_States();}@@ -503,7 +504,7 @@ Int ScreenBWFilter::init(void)};//Monochrome pixel shader.- hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\monochrome.pso", &Declaration[0], 0, false, &m_dwBWPixelShader);+ hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\monochrome.pso", &m_dwBWPixelShader);if (FAILED(hr))return FALSE;@@ -524,12 +525,12 @@ Bool ScreenBWFilter::preRender(Bool &skipRender, CustomScenePassModes &scenePassBool ScreenBWFilter::postRender(enum FilterModes mode, Coord2D &scrollDelta,Bool &doExtraRender){- IDirect3DTexture8 * tex = W3DShaderManager::endRenderToTexture();+ IDirect3DTexture9 * tex = W3DShaderManager::endRenderToTexture();DEBUG_ASSERTCRASH(tex, ("Require rendered texture."));if (!tex) return false;if (!set(mode)) return false;- LPDIRECT3DDEVICE8 pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 pDev=DX8Wrapper::_Get_D3D_Device();struct _TRANS_LIT_TEX_VERTEX {D3DXVECTOR4 p;@@ -540,7 +541,7 @@ Bool ScreenBWFilter::postRender(enum FilterModes mode, Coord2D &scrollDelta,BoolInt xpos, ypos, width, height;- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0,tex); //previously rendered frame inside this texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0,tex); //previously rendered frame inside this textureTheTacticalView->getOrigin(&xpos,&ypos);width=TheTacticalView->getWidth();height=TheTacticalView->getHeight();@@ -564,7 +565,7 @@ Bool ScreenBWFilter::postRender(enum FilterModes mode, Coord2D &scrollDelta,Bool//draw polygons like this is very inefficient but for only 2 triangles, it's//not worth bothering with index/vertex buffers.- pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);+ pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);pDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(_TRANS_LIT_TEX_VERTEX));@@ -624,8 +625,8 @@ Int ScreenBWFilter::set(enum FilterModes mode)DX8Wrapper::Set_DX8_Render_State(D3DRS_ZWRITEENABLE,FALSE);DX8Wrapper::Apply_Render_State_Changes(); //force update of view and projection matrices- hr=DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_dwBWPixelShader);- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(0, D3DXVECTOR4(0.3f, 0.59f, 0.11f, 1.0f), 1);+ hr=DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_dwBWPixelShader);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(0, D3DXVECTOR4(0.3f, 0.59f, 0.11f, 1.0f), 1);D3DXVECTOR4 color(1.0f,1.0f,1.0f,1.0f); //multiply color@@ -653,14 +654,14 @@ Int ScreenBWFilter::set(enum FilterModes mode)color.z = 0.0f;}- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(1, color, 1);- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(2, D3DXVECTOR4(m_curFadeValue, m_curFadeValue, m_curFadeValue, 1.0f), 1);-/* DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(2, D3DXVECTOR4(150.0f/255.0f, 150.0f/255.0f, 150.0f/255.0f, 0.0f), 1);- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(3, D3DXVECTOR4((765.0f/450.0f)/3, (765.0f/450.0f)/3, (765.0f/450.0f)/3, 1.0f), 1);- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(4, D3DXVECTOR4(0.5f, 0.5f, 0.5f, 0), 1);- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(5, D3DXVECTOR4((60.0f)/255.0f, (60.0f)/255.0f, (60.0f)/255.0f, 0), 1);- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(6, D3DXVECTOR4((157.0f)/255.0f, (157.0f)/255.0f, (157.0f)/255.0f, 0), 1);- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(7, D3DXVECTOR4((30.0f)/255.0f, (30.0f)/255.0f, (30.0f)/255.0f, 0), 1);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(1, color, 1);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(2, D3DXVECTOR4(m_curFadeValue, m_curFadeValue, m_curFadeValue, 1.0f), 1);+/* DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(2, D3DXVECTOR4(150.0f/255.0f, 150.0f/255.0f, 150.0f/255.0f, 0.0f), 1);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(3, D3DXVECTOR4((765.0f/450.0f)/3, (765.0f/450.0f)/3, (765.0f/450.0f)/3, 1.0f), 1);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(4, D3DXVECTOR4(0.5f, 0.5f, 0.5f, 0), 1);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(5, D3DXVECTOR4((60.0f)/255.0f, (60.0f)/255.0f, (60.0f)/255.0f, 0), 1);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(6, D3DXVECTOR4((157.0f)/255.0f, (157.0f)/255.0f, (157.0f)/255.0f, 0), 1);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(7, D3DXVECTOR4((30.0f)/255.0f, (30.0f)/255.0f, (30.0f)/255.0f, 0), 1);*/return true;}@@ -669,15 +670,15 @@ Int ScreenBWFilter::set(enum FilterModes mode)void ScreenBWFilter::reset(void){- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0,NULL); //previously rendered frame inside this texture- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(0); //turn off pixel shader+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0,NULL); //previously rendered frame inside this texture+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(0); //turn off pixel shaderDX8Wrapper::Invalidate_Cached_Render_States();}Int ScreenBWFilter::shutdown(void){if (m_dwBWPixelShader)- DX8Wrapper::_Get_D3D_Device8()->DeletePixelShader(m_dwBWPixelShader);+ m_dwBWPixelShader->Release();m_dwBWPixelShader=NULL;@@ -713,12 +714,12 @@ Bool ScreenBWFilterDOT3::preRender(Bool &skipRender, CustomScenePassModes &sceneBool ScreenBWFilterDOT3::postRender(enum FilterModes mode, Coord2D &scrollDelta,Bool &doExtraRender){- IDirect3DTexture8 * tex = W3DShaderManager::endRenderToTexture();+ IDirect3DTexture9 * tex = W3DShaderManager::endRenderToTexture();DEBUG_ASSERTCRASH(tex, ("Require rendered texture."));if (!tex) return false;if (!set(mode)) return false;- LPDIRECT3DDEVICE8 pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 pDev=DX8Wrapper::_Get_D3D_Device();struct _TRANS_LIT_TEX_VERTEX {D3DXVECTOR4 p;@@ -755,7 +756,7 @@ Bool ScreenBWFilterDOT3::postRender(enum FilterModes mode, Coord2D &scrollDelta,//draw polygons like this is very inefficient but for only 2 triangles, it's//not worth bothering with index/vertex buffers.- pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);+ pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);//Draw B&W version firstif (DX8Wrapper::Get_Current_Caps()->Support_Dot3())@@ -777,7 +778,7 @@ Bool ScreenBWFilterDOT3::postRender(enum FilterModes mode, Coord2D &scrollDelta,DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);}- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0,tex); //previously rendered frame inside this texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0,tex); //previously rendered frame inside this texturepDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(_TRANS_LIT_TEX_VERTEX));@@ -853,7 +854,7 @@ Int ScreenBWFilterDOT3::set(enum FilterModes mode)void ScreenBWFilterDOT3::reset(void){- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0,NULL); //previously rendered frame inside this texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0,NULL); //previously rendered frame inside this textureDX8Wrapper::Invalidate_Cached_Render_States();}@@ -962,7 +963,7 @@ Bool ScreenCrossFadeFilter::preRender(Bool &skipRender, CustomScenePassModes &scBool ScreenCrossFadeFilter::postRender(enum FilterModes mode, Coord2D &scrollDelta,Bool &doExtraRender){- IDirect3DTexture8 * tex;+ IDirect3DTexture9 * tex;if (m_skipRender){@@ -980,7 +981,7 @@ Bool ScreenCrossFadeFilter::postRender(enum FilterModes mode, Coord2D &scrollDelif (!tex) return false;if (!set(mode)) return false;- LPDIRECT3DDEVICE8 pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 pDev=DX8Wrapper::_Get_D3D_Device();struct _TRANS_LIT_TEX_VERTEX {D3DXVECTOR4 p;@@ -994,9 +995,9 @@ Bool ScreenCrossFadeFilter::postRender(enum FilterModes mode, Coord2D &scrollDelInt xpos, ypos, width, height;Real radius = 0.0f;- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0,tex); //previously rendered frame inside this texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0,tex); //previously rendered frame inside this textureif (mode == FM_VIEW_CROSSFADE_CIRCLE)- { DX8Wrapper::_Get_D3D_Device8()->SetTexture(1,m_fadePatternTexture->Peek_D3D_Texture());+ { DX8Wrapper::_Get_D3D_Device()->SetTexture(1,m_fadePatternTexture->Peek_D3D_Texture());//Use the current fade level to scale the mask texture, for other modes the texture//comes pre-scaled so doesn't require uv scaling.radius = (1.0f-m_curFadeValue)*2.0f;@@ -1040,10 +1041,10 @@ Bool ScreenCrossFadeFilter::postRender(enum FilterModes mode, Coord2D &scrollDel//draw polygons like this is very inefficient but for only 2 triangles, it's//not worth bothering with index/vertex buffers.- pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX2);+ pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX2);-// m_pDev->SetTextureStageState(0,D3DTSS_MAGFILTER,D3DTEXF_POINT);-// m_pDev->SetTextureStageState(0,D3DTSS_MINFILTER,D3DTEXF_POINT);+// m_pDev->SetTextureStageState(0,D3DSAMP_MAGFILTER,D3DTEXF_POINT);+// m_pDev->SetTextureStageState(0,D3DSAMP_MINFILTER,D3DTEXF_POINT);pDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(_TRANS_LIT_TEX_VERTEX));@@ -1063,8 +1064,8 @@ Int ScreenCrossFadeFilter::set(enum FilterModes mode)DX8Wrapper::Set_Texture(1,NULL);DX8Wrapper::Apply_Render_State_Changes(); //force update of view and projection matrices- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);if (mode == FM_VIEW_CROSSFADE_CIRCLE){ //cross-fading using circle mask stored in stage 1@@ -1075,9 +1076,9 @@ Int ScreenCrossFadeFilter::set(enum FilterModes mode)DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT );DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE );DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_TEXCOORDINDEX, 1 );- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_MIPFILTER, D3DTEXF_NONE);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_MIPFILTER, D3DTEXF_NONE);}DX8Wrapper::Set_DX8_Render_State(D3DRS_ZFUNC,D3DCMP_ALWAYS);@@ -1092,7 +1093,7 @@ void ScreenCrossFadeFilter::reset(void){DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0,NULL); //previously rendered frame inside this texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0,NULL); //previously rendered frame inside this textureDX8Wrapper::Invalidate_Cached_Render_States();}@@ -1144,12 +1145,12 @@ Bool ScreenMotionBlurFilter::preRender(Bool &skipRender, CustomScenePassModes &sBool ScreenMotionBlurFilter::postRender(enum FilterModes mode, Coord2D &scrollDelta,Bool &doExtraRender){- IDirect3DTexture8 * tex = W3DShaderManager::endRenderToTexture();+ IDirect3DTexture9 * tex = W3DShaderManager::endRenderToTexture();DEBUG_ASSERTCRASH(tex, ("Require rendered texture."));if (!tex) return false;if (!set(mode)) return false;- LPDIRECT3DDEVICE8 pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 pDev=DX8Wrapper::_Get_D3D_Device();Bool continueEffect = true;struct _TRANS_LIT_TEX_VERTEX {@@ -1161,7 +1162,7 @@ Bool ScreenMotionBlurFilter::postRender(enum FilterModes mode, Coord2D &scrollDeInt xpos, ypos, width, height;- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0,tex); //previously rendered frame inside this texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0,tex); //previously rendered frame inside this textureTheTacticalView->getOrigin(&xpos,&ypos);width=TheTacticalView->getWidth();height=TheTacticalView->getHeight();@@ -1195,7 +1196,7 @@ Bool ScreenMotionBlurFilter::postRender(enum FilterModes mode, Coord2D &scrollDe//draw polygons like this is very inefficient but for only 2 triangles, it's//not worth bothering with index/vertex buffers.DX8Wrapper::Apply_Render_State_Changes();- pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);+ pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);Coord2D center;center.x = 0.5f;@@ -1362,7 +1363,7 @@ Int ScreenMotionBlurFilter::set(enum FilterModes mode)void ScreenMotionBlurFilter::reset(void){- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0,NULL); //previously rendered frame inside this texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0,NULL); //previously rendered frame inside this textureDX8Wrapper::Invalidate_Cached_Render_States();}@@ -1706,10 +1707,10 @@ public:class FlatTerrainShaderPixelShader : public W3DShaderInterface{public:- DWORD m_dwBasePixelShader; ///<handle to terrain D3D pixel shader- DWORD m_dwBaseNoise1PixelShader; ///<handle to terrain/single noise D3D pixel shader- DWORD m_dwBaseNoise2PixelShader; ///<handle to terrain/double noise D3D pixel shader- DWORD m_dwBase0PixelShader; ///<handle to terrain only pixel shader+ IDirect3DPixelShader9 * m_dwBasePixelShader; ///<terrain D3D pixel shader+ IDirect3DPixelShader9 * m_dwBaseNoise1PixelShader; ///<terrain/single noise D3D pixel shader+ IDirect3DPixelShader9 * m_dwBaseNoise2PixelShader; ///<terrain/double noise D3D pixel shader+ IDirect3DPixelShader9 * m_dwBase0PixelShader; ///<terrain only pixel shadervirtual Int set(Int pass); ///<setup shader for the specified rendering pass.virtual Int init(void); ///<perform any one time initialization and validationvirtual void reset(void); ///<do any custom resetting necessary to bring W3D in sync.@@ -1730,9 +1731,9 @@ class TerrainShader8Stage : public W3DShaderInterface///Pixel shader based terrain shader - fastest method for the newest cards.class TerrainShaderPixelShader : public W3DShaderInterface{- DWORD m_dwBasePixelShader; ///<handle to terrain D3D pixel shader- DWORD m_dwBaseNoise1PixelShader; ///<handle to terrain/single noise D3D pixel shader- DWORD m_dwBaseNoise2PixelShader; ///<handle to terrain/double noise D3D pixel shader+ IDirect3DPixelShader9 * m_dwBasePixelShader; ///<terrain D3D pixel shader+ IDirect3DPixelShader9 * m_dwBaseNoise1PixelShader; ///<terrain/single noise D3D pixel shader+ IDirect3DPixelShader9 * m_dwBaseNoise2PixelShader; ///<terrain/double noise D3D pixel shadervirtual Int set(Int pass); ///<setup shader for the specified rendering pass.virtual void reset(void); ///<do any custom resetting necessary to bring W3D in sync.@@ -1786,8 +1787,8 @@ void TerrainShader2Stage::reset(void)ShaderClass::Invalidate();//Free references to textures- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, NULL);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1, NULL);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU|0);@@ -1845,30 +1846,30 @@ Int TerrainShader2Stage::set(Int pass)DX8Wrapper::Apply_Render_State_Changes();if (TheGlobalData && TheGlobalData->m_bilinearTerrainTex || TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);}if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MIPFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);}switch (pass){case 0:- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(0)->Peek_D3D_Texture());- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(0)->Peek_D3D_Texture());+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);// Modulate the diffuse color with the texture as lighting comes from diffuse.DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );@@ -1881,9 +1882,9 @@ Int TerrainShader2Stage::set(Int pass)DX8Wrapper::Set_DX8_Render_State(D3DRS_ALPHABLENDENABLE,false);break;case 1:- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(1)->Peek_D3D_Texture());- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(1)->Peek_D3D_Texture());+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);// Modulate the diffuse color with the texture as lighting comes from diffuse.DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );@@ -1913,8 +1914,8 @@ Int TerrainShader2Stage::set(Int pass)DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);//blend into frame bufferDX8Wrapper::Set_DX8_Render_State(D3DRS_ALPHABLENDENABLE,true);@@ -1930,22 +1931,22 @@ Int TerrainShader2Stage::set(Int pass)if (W3DShaderManager::getCurrentShader() == W3DShaderManager::ST_TERRAIN_BASE_NOISE12){//setup cloud pass- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());updateNoise1(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrixDX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE0, curView);//clouds always need bilinear filtering- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);//setup noise pass- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());updateNoise2(((D3DXMATRIX*)&curView),&inv);DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE1, curView);//noise always needs point/linear filtering. Why point!?- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );@@ -1955,26 +1956,26 @@ Int TerrainShader2Stage::set(Int pass)// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);} //ST_TERRAIN_BASE_NOISE12else{ //only 1 noise or cloud texture// Now setup the texture pipeline.if (W3DShaderManager::getCurrentShader() == W3DShaderManager::ST_TERRAIN_BASE_NOISE1){ //setup cloud pass- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());updateNoise1(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrix- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);}else{//setup noise pass- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());updateNoise2(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrix- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);}DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );@@ -2015,32 +2016,32 @@ Int TerrainShader8Stage::set(Int pass)//force WW3D2 system to set it's states so it won't later overwrite our custom settings.DX8Wrapper::Apply_Render_State_Changes();- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);if (TheGlobalData && TheGlobalData->m_bilinearTerrainTex || TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);}if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MIPFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);}- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(0)->Peek_D3D_Texture());- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1, W3DShaderManager::getShaderTexture(1)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(0)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1, W3DShaderManager::getShaderTexture(1)->Peek_D3D_Texture());DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXCOORDINDEX, 0);@@ -2134,21 +2135,23 @@ void TerrainShader8Stage::reset(void)DX8Wrapper::Set_DX8_Texture_Stage_State( 4, D3DTSS_COLOROP, D3DTOP_DISABLE);DX8Wrapper::Set_DX8_Texture_Stage_State( 4, D3DTSS_ALPHAOP, D3DTOP_DISABLE);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, NULL);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1, NULL);DX8Wrapper::Invalidate_Cached_Render_States();}Int TerrainShaderPixelShader::shutdown(void){+ // A D3D9 shader is a COM object the caller owns, where a D3D8 one was a device handle+ // the device deleted.if (m_dwBasePixelShader)- DX8Wrapper::_Get_D3D_Device8()->DeletePixelShader(m_dwBasePixelShader);+ m_dwBasePixelShader->Release();if (m_dwBaseNoise1PixelShader)- DX8Wrapper::_Get_D3D_Device8()->DeletePixelShader(m_dwBaseNoise1PixelShader);+ m_dwBaseNoise1PixelShader->Release();if (m_dwBaseNoise2PixelShader)- DX8Wrapper::_Get_D3D_Device8()->DeletePixelShader(m_dwBaseNoise2PixelShader);+ m_dwBaseNoise2PixelShader->Release();m_dwBasePixelShader=NULL;m_dwBaseNoise1PixelShader=NULL;@@ -2181,17 +2184,17 @@ Int TerrainShaderPixelShader::init( void )};//base version which doesn't apply any noise textures.- HRESULT hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\terrain.pso", &Declaration[0], 0, false, &m_dwBasePixelShader);+ HRESULT hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\terrain.pso", &m_dwBasePixelShader);if (FAILED(hr))return FALSE;//version which blends 1 noise texture.- hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\terrainnoise.pso", &Declaration[0], 0, false, &m_dwBaseNoise1PixelShader);+ hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\terrainnoise.pso", &m_dwBaseNoise1PixelShader);if (FAILED(hr))return FALSE;//version which blends 2 noise textures.- hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\terrainnoise2.pso", &Declaration[0], 0, false, &m_dwBaseNoise2PixelShader);+ hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\terrainnoise2.pso", &m_dwBaseNoise2PixelShader);if (FAILED(hr))return FALSE;@@ -2215,35 +2218,35 @@ Int TerrainShaderPixelShader::set(Int pass)DX8Wrapper::Apply_Render_State_Changes();//setup base pass- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(0)->Peek_D3D_Texture());- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1, W3DShaderManager::getShaderTexture(1)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(0)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1, W3DShaderManager::getShaderTexture(1)->Peek_D3D_Texture());- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);//tell pixel shader which UV set to use for each stageDX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXCOORDINDEX, 0 );DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_TEXCOORDINDEX, 1 );if (TheGlobalData && TheGlobalData->m_bilinearTerrainTex || TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);}if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MIPFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);}if (W3DShaderManager::getCurrentShader() >= W3DShaderManager::ST_TERRAIN_BASE_NOISE1)@@ -2259,22 +2262,22 @@ Int TerrainShaderPixelShader::set(Int pass)// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);if (W3DShaderManager::getCurrentShader() == W3DShaderManager::ST_TERRAIN_BASE_NOISE12){ //full shader- DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(2, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());- DX8Wrapper::_Get_D3D_Device8()->SetTexture(3, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_dwBaseNoise2PixelShader);+ DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(2, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(3, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_dwBaseNoise2PixelShader);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);terrainShader2Stage.updateNoise1(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrixDX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE2, curView);@@ -2288,28 +2291,28 @@ Int TerrainShaderPixelShader::set(Int pass)}else{ //single noise texture shader- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_dwBaseNoise1PixelShader);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_dwBaseNoise1PixelShader);if (W3DShaderManager::getCurrentShader() == W3DShaderManager::ST_TERRAIN_BASE_NOISE1){ //cloud map- DX8Wrapper::_Get_D3D_Device8()->SetTexture(2, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(2, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());terrainShader2Stage.updateNoise1(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrix- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);}else{ //light map- DX8Wrapper::_Get_D3D_Device8()->SetTexture(2, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(2, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());terrainShader2Stage.updateNoise2(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrix- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);}DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE2, curView);}}else{ //just base texturing- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_dwBasePixelShader);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_dwBasePixelShader);}return TRUE;@@ -2317,13 +2320,13 @@ Int TerrainShaderPixelShader::set(Int pass)void TerrainShaderPixelShader::reset(void){- DX8Wrapper::_Get_D3D_Device8()->SetTexture(2,NULL); //release reference to any texture- DX8Wrapper::_Get_D3D_Device8()->SetTexture(3,NULL); //release reference to any texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(2,NULL); //release reference to any texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(3,NULL); //release reference to any texture- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(0); //turn off pixel shader+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(0); //turn off pixel shader- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, NULL);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1, NULL);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU|0);@@ -2382,10 +2385,10 @@ Int CloudTextureShader::set(Int stage)DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);DX8Wrapper::_Set_DX8_Transform((D3DTRANSFORMSTATETYPE )(D3DTS_TEXTURE0+stage), curView);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DTSS_COLORARG1, D3DTA_TEXTURE );DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DTSS_COLORARG2, D3DTA_CURRENT );@@ -2394,7 +2397,7 @@ Int CloudTextureShader::set(Int stage)DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DTSS_ALPHAARG2, D3DTA_CURRENT );DX8Wrapper::Set_DX8_Texture_Stage_State( stage, D3DTSS_ALPHAOP, D3DTOP_MODULATE );- DX8Wrapper::_Get_D3D_Device8()->SetTexture(stage, W3DShaderManager::getShaderTexture(stage)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(stage, W3DShaderManager::getShaderTexture(stage)->Peek_D3D_Texture());m_stageOfSet=stage;return TRUE;@@ -2403,7 +2406,7 @@ Int CloudTextureShader::set(Int stage)void CloudTextureShader::reset(void){//Free reference to texture- DX8Wrapper::_Get_D3D_Device8()->SetTexture(m_stageOfSet, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(m_stageOfSet, NULL);//Turn off texture projectionDX8Wrapper::Set_DX8_Texture_Stage_State( m_stageOfSet, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);DX8Wrapper::Set_DX8_Texture_Stage_State( m_stageOfSet, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU|m_stageOfSet);@@ -2417,7 +2420,7 @@ void CloudTextureShader::reset(void)/*===========================================================================================*/class RoadShaderPixelShader : public W3DShaderInterface{- DWORD m_dwBaseNoise2PixelShader; ///<handle to road/double noise D3D pixel shader+ IDirect3DPixelShader9 * m_dwBaseNoise2PixelShader; ///<road/double noise D3D pixel shadervirtual Int set(Int pass); ///<setup shader for the specified rendering pass.virtual void reset(void); ///<do any custom resetting necessary to bring W3D in sync.@@ -2444,7 +2447,7 @@ W3DShaderInterface *RoadShaderList[]=Int RoadShaderPixelShader::shutdown(void){if (m_dwBaseNoise2PixelShader)- DX8Wrapper::_Get_D3D_Device8()->DeletePixelShader(m_dwBaseNoise2PixelShader);+ m_dwBaseNoise2PixelShader->Release();m_dwBaseNoise2PixelShader=NULL;@@ -2472,7 +2475,7 @@ Int RoadShaderPixelShader::init( void )};//version which blends 2 noise textures.- HRESULT hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\roadnoise2.pso", &Declaration[0], 0, false, &m_dwBaseNoise2PixelShader);+ HRESULT hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\roadnoise2.pso", &m_dwBaseNoise2PixelShader);if (FAILED(hr))return FALSE;@@ -2511,34 +2514,34 @@ Int RoadShaderPixelShader::set(Int pass)D3DXMatrixInverse(&inv, &det, (D3DXMATRIX*)&curView);if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex)- { DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ { DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);}else- { DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MIPFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ { DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_POINT);}DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);DX8Wrapper::Set_Texture(1,W3DShaderManager::getShaderTexture(1));DX8Wrapper::Set_Texture(2,W3DShaderManager::getShaderTexture(2));- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_dwBaseNoise2PixelShader);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_dwBaseNoise2PixelShader);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);terrainShader2Stage.updateNoise1(((D3DXMATRIX*)&curView),&inv, false); //get texture projection matrixDX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE1, curView);@@ -2556,7 +2559,7 @@ Int RoadShaderPixelShader::set(Int pass)void RoadShaderPixelShader::reset(void){- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(0); //turn off pixel shader+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(0); //turn off pixel shaderDX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU|0);@@ -2626,16 +2629,16 @@ Int RoadShader2Stage::set(Int pass)D3DXMatrixInverse(&inv, &det, (D3DXMATRIX*)&curView);if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex)- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);else- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_POINT);DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );@@ -2647,8 +2650,8 @@ Int RoadShader2Stage::set(Int pass)if (W3DShaderManager::getCurrentShader() == W3DShaderManager::ST_ROAD_BASE_NOISE12){ //full shader, apply noise 1 in pass 0.DX8Wrapper::Set_Texture(1,W3DShaderManager::getShaderTexture(1));- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);terrainShader2Stage.updateNoise1(((D3DXMATRIX*)&curView),&inv, false); //get texture projection matrixDX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE1, curView);@@ -2659,15 +2662,15 @@ Int RoadShader2Stage::set(Int pass){ //cloud mapDX8Wrapper::Set_Texture(1,W3DShaderManager::getShaderTexture(1));terrainShader2Stage.updateNoise1(((D3DXMATRIX*)&curView),&inv, false); //update curView with texture matrix- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);}else{ //light mapDX8Wrapper::Set_Texture(1,W3DShaderManager::getShaderTexture(2));terrainShader2Stage.updateNoise2(((D3DXMATRIX*)&curView),&inv, false); //update curView with texture matrix- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);}DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE1, curView);}@@ -2688,22 +2691,22 @@ Int RoadShader2Stage::set(Int pass)D3DXMatrixInverse(&inv, &det, (D3DXMATRIX*)&curView);if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex)- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);else- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_POINT);DX8Wrapper::Set_Texture(1,W3DShaderManager::getShaderTexture(2));terrainShader2Stage.updateNoise2(((D3DXMATRIX*)&curView),&inv, false); //update curView with texture matrix- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);//Copy alpha channel into stage 1 but mask out color channel by replacing with white.DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );@@ -2814,11 +2817,11 @@ void W3DShaderManager::init(void)m_currentChipset = res; //cache the current chipset.//Some of our effects require an offscreen render target, so try creating it here.- HRESULT hr=DX8Wrapper::_Get_D3D_Device8()->GetRenderTarget(&m_oldRenderSurface);+ HRESULT hr=DX8Wrapper::_Get_D3D_Device()->GetRenderTarget(PRIMARY_RENDER_TARGET, &m_oldRenderSurface);m_oldRenderSurface->GetDesc(&desc);- hr=DX8Wrapper::_Get_D3D_Device8()->CreateTexture(desc.Width,desc.Height,1,D3DUSAGE_RENDERTARGET,desc.Format,D3DPOOL_DEFAULT,&m_renderTexture);+ hr=DX8Wrapper::_Get_D3D_Device()->CreateTexture(desc.Width,desc.Height,1,D3DUSAGE_RENDERTARGET,desc.Format,D3DPOOL_DEFAULT,&m_renderTexture,NULL);if (hr != S_OK){@@ -2833,7 +2836,7 @@ void W3DShaderManager::init(void)m_renderTexture = NULL;m_newRenderSurface = NULL;} else {- hr = DX8Wrapper::_Get_D3D_Device8()->GetDepthStencilSurface(&m_oldDepthSurface);+ hr = DX8Wrapper::_Get_D3D_Device()->GetDepthStencilSurface(&m_oldDepthSurface);if (hr != S_OK){if (m_newRenderSurface) m_newRenderSurface->Release();@@ -3005,7 +3008,7 @@ static void rttComplain( const char *why )/*Draws 2 triangles covering the viewport given the current render states*/void W3DShaderManager::drawViewport(Int color){- LPDIRECT3DDEVICE8 pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 pDev=DX8Wrapper::_Get_D3D_Device();struct _TRANS_LIT_TEX_VERTEX {D3DXVECTOR4 p;@@ -3039,7 +3042,7 @@ void W3DShaderManager::drawViewport(Int color)//draw polygons like this is very inefficient but for only 2 triangles, it's//not worth bothering with index/vertex buffers.- pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);+ pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);pDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(_TRANS_LIT_TEX_VERTEX));}@@ -3064,9 +3067,10 @@ void W3DShaderManager::startRenderToTexture(void)//m_oldDepthSurface is the back buffer's depth surface, which is multisampled when the back//buffer is; D3D wants the depth buffer to match the render target, and ours is a plain//texture. Ask the wrapper for a matching one (NULL = not multisampling, nothing to do).- IDirect3DSurface8 *depthSurface = DX8Wrapper::_Get_Non_MultiSampled_Depth_Buffer();+ IDirect3DSurface9 *depthSurface = DX8Wrapper::_Get_Non_MultiSampled_Depth_Buffer();if (depthSurface == NULL) depthSurface = m_oldDepthSurface;- HRESULT hr = DX8Wrapper::_Get_D3D_Device8()->SetRenderTarget(m_newRenderSurface,depthSurface);+ DX8Wrapper::_Set_DX8_Render_Target(m_newRenderSurface,depthSurface);+ HRESULT hr = S_OK;DEBUG_ASSERTCRASH(hr==S_OK, ("Set target failed unexpectedly."));if (hr != S_OK){@@ -3085,7 +3089,7 @@ void W3DShaderManager::startRenderToTexture(void)DWORD clearFlags = D3DCLEAR_ZBUFFER;if (depthDesc.Format == D3DFMT_D24S8 || depthDesc.Format == D3DFMT_D24X4S4 || depthDesc.Format == D3DFMT_D15S1)clearFlags |= D3DCLEAR_STENCIL;- DX8Wrapper::_Get_D3D_Device8()->Clear(0, NULL, clearFlags, 0, 1.0f, 0);+ DX8Wrapper::_Get_D3D_Device()->Clear(0, NULL, clearFlags, 0, 1.0f, 0);}m_renderingToTexture = true;if (TheGlobalData->m_showSoftWaterEdge)@@ -3115,7 +3119,7 @@ void W3DShaderManager::startRenderToTexture(void)/** Ends rendering to a texture.*///=============================================================================-IDirect3DTexture8 *W3DShaderManager::endRenderToTexture(void)+IDirect3DTexture9 *W3DShaderManager::endRenderToTexture(void){DEBUG_ASSERTCRASH(m_renderingToTexture, ("Not rendering to texture."));if (!m_renderingToTexture)@@ -3123,7 +3127,8 @@ IDirect3DTexture8 *W3DShaderManager::endRenderToTexture(void)rttComplain( "end without a start" );return NULL;}- HRESULT hr = DX8Wrapper::_Get_D3D_Device8()->SetRenderTarget(m_oldRenderSurface,m_oldDepthSurface); //restore original render target+ DX8Wrapper::_Set_DX8_Render_Target(m_oldRenderSurface,m_oldDepthSurface); //restore original render target+ HRESULT hr = S_OK;DEBUG_ASSERTCRASH(hr==S_OK, ("Set target failed unexpectedly."));if (hr != S_OK)rttComplain( "SetRenderTarget(back buffer) failed - the frame is stuck in the texture" );@@ -3131,12 +3136,12 @@ IDirect3DTexture8 *W3DShaderManager::endRenderToTexture(void){//assume render target texure will be in stage 0. Most hardware has "conditional" support for//non-power-of-2 textures so we must force some required states:- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSW, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_MIPFILTER, D3DTEXF_NONE);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);m_renderingToTexture = false;}@@ -3146,7 +3151,7 @@ IDirect3DTexture8 *W3DShaderManager::endRenderToTexture(void)/**Returns texture containing the image that was last rendered using any of the effects requiring render targettextures. Used mostly for cross-fading effects that need an unmodified version of the view before the effectwas applied. NOTE: This texture does not survive device reset.. so quit effect on reset!*/-IDirect3DTexture8 *W3DShaderManager::getRenderTexture(void)+IDirect3DTexture9 *W3DShaderManager::getRenderTexture(void){return m_renderTexture;}@@ -3170,14 +3175,14 @@ ChipsetType W3DShaderManager::getChipset( void )return (ChipsetType)TheGlobalData->m_chipSetType;ChipsetType chip=DC_UNKNOWN;- IDirect3D8* d3d8Interface=DX8Wrapper::_Get_D3D8();+ IDirect3D9* d3d8Interface=DX8Wrapper::_Get_D3D();- if (d3d8Interface && DX8Wrapper::_Get_D3D_Device8())+ if (d3d8Interface && DX8Wrapper::_Get_D3D_Device()){- D3DADAPTER_IDENTIFIER8 did;- ::ZeroMemory(&did, sizeof(D3DADAPTER_IDENTIFIER8));- /* HRESULT res = */ d3d8Interface->GetAdapterIdentifier(0,D3DENUM_NO_WHQL_LEVEL,&did);+ D3DADAPTER_IDENTIFIER9 did;+ ::ZeroMemory(&did, sizeof(D3DADAPTER_IDENTIFIER9));+ /* HRESULT res = */ d3d8Interface->GetAdapterIdentifier(0,NO_ADAPTER_IDENTIFIER_FLAGS,&did);*((LARGE_INTEGER*)&m_driverVersion) = did.DriverVersion;if(did.VendorId == DC_NVIDIA_VENDOR_ID)@@ -3256,59 +3261,71 @@ ChipsetType W3DShaderManager::getChipset( void )//=============================================================================/** Loads and creates a D3D pixel or vertex shader.*///=============================================================================-HRESULT W3DShaderManager::LoadAndCreateD3DShader(char* strFilePath, const DWORD* pDeclaration, DWORD Usage, Bool ShaderType, DWORD* pHandle)+/** Reads a compiled shader out of the file system into a buffer the caller frees with+ HeapFree. Returns NULL and leaves nothing allocated if the file is not there. */+static const DWORD* readShaderBytecode(const char* strFilePath){- if (getChipset() < DC_GENERIC_PIXEL_SHADER_1_1)- return E_FAIL; //don't allow loading any shaders if hardware can't handle it.-- try+ File *file = TheFileSystem->openFile(strFilePath, File::READ | File::BINARY);+ if (file == NULL){- File *file = NULL;- HRESULT hr;-- file = TheFileSystem->openFile(strFilePath, File::READ | File::BINARY);- if (file == NULL)- {- OutputDebugString("Could not find file \n" );- return E_FAIL;- }-- FileInfo fileInfo;- TheFileSystem->getFileInfo(AsciiString(strFilePath), &fileInfo);- DWORD dwFileSize = fileInfo.sizeLow;+ DEBUG_LOG(("SHADER: %s is not in the file system\n", strFilePath));+ return NULL;+ }- const DWORD* pShader = (DWORD*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwFileSize);- if (!pShader)- {- OutputDebugString( "Failed to allocate memory to load shader\n " );- return E_FAIL;- }+ FileInfo fileInfo;+ TheFileSystem->getFileInfo(AsciiString(strFilePath), &fileInfo);+ const DWORD dwFileSize = fileInfo.sizeLow;+ const DWORD* pShader = (DWORD*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwFileSize);+ if (pShader != NULL)+ {file->read((void *)pShader, dwFileSize);+ }+ file->close();+ return pShader;+}- file->close();- file = NULL;+HRESULT W3DShaderManager::LoadAndCreateD3DPixelShader(const char* strFilePath, IDirect3DPixelShader9** shader)+{+ if (getChipset() < DC_GENERIC_PIXEL_SHADER_1_1)+ return E_FAIL; //don't allow loading any shaders if hardware can't handle it.- if (ShaderType == TRUE)//SHADERTYPE_VERTEX)- {- hr = DX8Wrapper::_Get_D3D_Device8()->CreateVertexShader(pDeclaration, pShader, pHandle, Usage);- }- else if (ShaderType == FALSE)//SHADERTYPE_PIXEL)- {- hr = DX8Wrapper::_Get_D3D_Device8()->CreatePixelShader(pShader, pHandle);- }+ const DWORD* pShader = readShaderBytecode(strFilePath);+ if (pShader == NULL)+ return E_FAIL;- HeapFree(GetProcessHeap(), 0, (void*)pShader);+ // The bytecode was compiled for D3D8 and does not load on a D3D9 device untouched;+ // see d3d8shadertranslate.h for what has to be repaired and why.+ const HRESULT hr = Create_Translated_Pixel_Shader(DX8Wrapper::_Get_D3D_Device(), pShader, shader);+ HeapFree(GetProcessHeap(), 0, (void*)pShader);- if (FAILED(hr))- {- OutputDebugString( "Failed to create shader\n ");- return E_FAIL;- }+ if (FAILED(hr))+ {+ DEBUG_LOG(("SHADER: %s did not translate to Direct3D 9, hr=0x%08lx\n",+ strFilePath, (unsigned long)hr));+ return E_FAIL;}- catch(...)+ return S_OK;+}++HRESULT W3DShaderManager::LoadAndCreateD3DVertexShader(const char* strFilePath, const DWORD* pDeclaration,+ IDirect3DVertexShader9** shader, IDirect3DVertexDeclaration9** declaration)+{+ if (getChipset() < DC_GENERIC_PIXEL_SHADER_1_1)+ return E_FAIL; //don't allow loading any shaders if hardware can't handle it.++ const DWORD* pShader = readShaderBytecode(strFilePath);+ if (pShader == NULL)+ return E_FAIL;++ const HRESULT hr = Create_Translated_Vertex_Shader(DX8Wrapper::_Get_D3D_Device(),+ pDeclaration, pShader, shader, declaration);+ HeapFree(GetProcessHeap(), 0, (void*)pShader);++ if (FAILED(hr)){- OutputDebugString( "Error opening file \n" );+ DEBUG_LOG(("SHADER: %s did not translate to Direct3D 9, hr=0x%08lx\n",+ strFilePath, (unsigned long)hr));return E_FAIL;}@@ -3512,8 +3529,8 @@ void FlatTerrainShader2Stage::reset(void)ShaderClass::Invalidate();//Free references to textures- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, NULL);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1, NULL);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU|0);@@ -3529,36 +3546,36 @@ Int FlatTerrainShader2Stage::set(Int pass)DX8Wrapper::Apply_Render_State_Changes();if (TheGlobalData && TheGlobalData->m_bilinearTerrainTex || TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);}if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MIPFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_POINT);}switch (pass){case 0:- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);// Modulate the diffuse color with the texture as lighting comes from diffuse.DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );if (W3DShaderManager::getShaderTexture(0)) {- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(0)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(0)->Peek_D3D_Texture());DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLORARG2, D3DTA_CURRENT );DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );@@ -3610,8 +3627,8 @@ Int FlatTerrainShader2Stage::set(Int pass)}DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);// Modulate the diffuse color with the texture as lighting comes from diffuse.DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );@@ -3637,8 +3654,8 @@ Int FlatTerrainShader2Stage::set(Int pass)DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);//blend into frame bufferDX8Wrapper::Set_DX8_Render_State(D3DRS_ALPHABLENDENABLE,true);@@ -3658,17 +3675,17 @@ Int FlatTerrainShader2Stage::set(Int pass)terrainShader2Stage.updateNoise1(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrixDX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE0, curView);//clouds always need bilinear filtering- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());//setup noise passterrainShader2Stage.updateNoise2(((D3DXMATRIX*)&curView),&inv);DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE1, curView);//noise always needs point/linear filtering. Why point!?- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );@@ -3678,27 +3695,27 @@ Int FlatTerrainShader2Stage::set(Int pass)// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());} //ST_TERRAIN_BASE_NOISE12else{ //only 1 noise or cloud texture// Now setup the texture pipeline.if (W3DShaderManager::getCurrentShader() == W3DShaderManager::ST_FLAT_TERRAIN_BASE_NOISE1){ //setup cloud pass- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());terrainShader2Stage.updateNoise1(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrix- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);}else{//setup noise pass- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());terrainShader2Stage.updateNoise2(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrix- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);}DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );@@ -3719,16 +3736,16 @@ Int FlatTerrainShader2Stage::set(Int pass)Int FlatTerrainShaderPixelShader::shutdown(void){if (m_dwBasePixelShader)- DX8Wrapper::_Get_D3D_Device8()->DeletePixelShader(m_dwBasePixelShader);+ m_dwBasePixelShader->Release();if (m_dwBase0PixelShader)- DX8Wrapper::_Get_D3D_Device8()->DeletePixelShader(m_dwBase0PixelShader);+ m_dwBase0PixelShader->Release();if (m_dwBaseNoise1PixelShader)- DX8Wrapper::_Get_D3D_Device8()->DeletePixelShader(m_dwBaseNoise1PixelShader);+ m_dwBaseNoise1PixelShader->Release();if (m_dwBaseNoise2PixelShader)- DX8Wrapper::_Get_D3D_Device8()->DeletePixelShader(m_dwBaseNoise2PixelShader);+ m_dwBaseNoise2PixelShader->Release();m_dwBasePixelShader=NULL;m_dwBase0PixelShader=NULL;@@ -3764,22 +3781,22 @@ Int FlatTerrainShaderPixelShader::init( void )};//base version which doesn't apply any noise textures.- HRESULT hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\fterrain.pso", &Declaration[0], 0, false, &m_dwBasePixelShader);+ HRESULT hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\fterrain.pso", &m_dwBasePixelShader);if (FAILED(hr))return FALSE;//base version which doesn't apply any shroud textures.- hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\fterrain0.pso", &Declaration[0], 0, false, &m_dwBase0PixelShader);+ hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\fterrain0.pso", &m_dwBase0PixelShader);if (FAILED(hr))return FALSE;//version which blends 1 noise texture.- hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\fterrainnoise.pso", &Declaration[0], 0, false, &m_dwBaseNoise1PixelShader);+ hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\fterrainnoise.pso", &m_dwBaseNoise1PixelShader);if (FAILED(hr))return FALSE;//version which blends 2 noise textures.- hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\fterrainnoise2.pso", &Declaration[0], 0, false, &m_dwBaseNoise2PixelShader);+ hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\fterrainnoise2.pso", &m_dwBaseNoise2PixelShader);if (FAILED(hr))return FALSE;@@ -3803,8 +3820,8 @@ Int FlatTerrainShaderPixelShader::set(Int pass)Int curStage = 1;// setup terrain [3/31/2003]- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);DX8Wrapper::Set_Texture(0, W3DShaderManager::getShaderTexture(2));DX8Wrapper::Set_Texture(1, W3DShaderManager::getShaderTexture(2));//force WW3D2 system to set it's states so it won't later overwrite our custom settings.@@ -3813,23 +3830,23 @@ Int FlatTerrainShaderPixelShader::set(Int pass)- DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);//tell pixel shader which UV set to use for each stageDX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DTSS_TEXCOORDINDEX, 0 );DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);if (TheGlobalData && TheGlobalData->m_bilinearTerrainTex || TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_MAGFILTER, D3DTEXF_POINT);}if (TheGlobalData && TheGlobalData->m_trilinearTerrainTex) {- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);} else {- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_MIPFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_MIPFILTER, D3DTEXF_POINT);}curStage = 0;@@ -3875,11 +3892,11 @@ Int FlatTerrainShaderPixelShader::set(Int pass)*((D3DXMATRIX *)&curView) = (inv * offset) * scale;DX8Wrapper::_Set_DX8_Transform((D3DTRANSFORMSTATETYPE )(D3DTS_TEXTURE0+curStage), *((Matrix4x4*)&curView));}- DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(curStage, shroud->getShroudTexture()->Peek_D3D_Texture());+ DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State( curStage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(curStage, shroud->getShroudTexture()->Peek_D3D_Texture());curStage++;if (curStage==1) curStage++;}@@ -3898,13 +3915,13 @@ Int FlatTerrainShaderPixelShader::set(Int pass)// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(curStage, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(curStage, W3DShaderManager::getShaderTexture(2)->Peek_D3D_Texture());terrainShader2Stage.updateNoise1(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrixDX8Wrapper::_Set_DX8_Transform((D3DTRANSFORMSTATETYPE )(D3DTS_TEXTURE0+curStage), *((Matrix4x4*)&curView));- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);curStage++;if (curStage==1) curStage++;@@ -3925,41 +3942,41 @@ Int FlatTerrainShaderPixelShader::set(Int pass)// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(curStage, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(curStage, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());terrainShader2Stage.updateNoise2(((D3DXMATRIX*)&curView),&inv); //update curView with texture matrixDX8Wrapper::_Set_DX8_Transform((D3DTRANSFORMSTATETYPE )(D3DTS_TEXTURE0+curStage), *((Matrix4x4*)&curView));- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(curStage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);curStage++;if (curStage==1) curStage++;}if (curStage<2) {- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_dwBase0PixelShader);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_dwBase0PixelShader);} else if (curStage==2) {- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_dwBasePixelShader);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_dwBasePixelShader);} else if (curStage==3) {- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_dwBaseNoise1PixelShader);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_dwBaseNoise1PixelShader);}else if (curStage==4) {- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_dwBaseNoise2PixelShader);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_dwBaseNoise2PixelShader);}- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_ALPHABLENDENABLE, false);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_ALPHABLENDENABLE, false);DX8Wrapper::Apply_Render_State_Changes();- DX8Wrapper::_Get_D3D_Device8()->SetTexture(curStage, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(curStage, W3DShaderManager::getShaderTexture(3)->Peek_D3D_Texture());return TRUE;}void FlatTerrainShaderPixelShader::reset(void){- DX8Wrapper::_Get_D3D_Device8()->SetTexture(2,NULL); //release reference to any texture- DX8Wrapper::_Get_D3D_Device8()->SetTexture(3,NULL); //release reference to any texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(2,NULL); //release reference to any texture+ DX8Wrapper::_Get_D3D_Device()->SetTexture(3,NULL); //release reference to any texture- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(0); //turn off pixel shader+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(0); //turn off pixel shader- DX8Wrapper::_Get_D3D_Device8()->SetTexture(0, NULL);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(0, NULL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1, NULL);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU|0);diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cppindex f88102079..3eca91419 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp@@ -554,7 +554,7 @@ void W3DShroud::render(CameraClass *cam)if (!m_pSrcTexture)return; //nothing to update from. Must be in reset state.- if (DX8Wrapper::_Get_D3D_Device8() && (DX8Wrapper::_Get_D3D_Device8()->TestCooperativeLevel()) != D3D_OK)+ if (DX8Wrapper::_Get_D3D_Device() && (DX8Wrapper::_Get_D3D_Device()->TestCooperativeLevel()) != D3D_OK)return; //device not ready to render anything#if defined(_DEBUG) || defined(_INTERNAL)diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSmudge.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSmudge.cppindex 908e5cee2..2400c5d9b 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSmudge.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSmudge.cpp@@ -38,6 +38,7 @@#include "WW3D2/texture.h"#include "WW3D2/dx8indexbuffer.h"#include "WW3D2/dx8wrapper.h"+#include "WW3D2/d3dx9runtime.h"#include "WW3D2/rinfo.h"#include "WW3D2/camera.h"#include "WW3D2/sortingrenderer.h"@@ -144,17 +145,18 @@ void W3DSmudgeManager::ReAcquireResources(void)/*Copies a portion of the current render target into a specified buffer*/Int copyRect(unsigned char *buf, Int bufSize, int oX, int oY, int width, int height){- IDirect3DSurface8 *surface=NULL; ///<previous render target- IDirect3DSurface8 *tempSurface=NULL;+ IDirect3DSurface9 *surface=NULL; ///<previous render target+ IDirect3DSurface9 *tempSurface=NULL;Int result = 0;HRESULT hr = S_OK;+ unsigned int surfaceSize = 0;- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();if (!m_pDev)goto error;- m_pDev->GetRenderTarget(&surface);+ m_pDev->GetRenderTarget(PRIMARY_RENDER_TARGET, &surface);if (!surface)goto error;@@ -173,12 +175,27 @@ Int copyRect(unsigned char *buf, Int bufSize, int oX, int oY, int width, int heidstPoint.x=0;dstPoint.y=0;- hr=m_pDev->CreateImageSurface( width, height, desc.Format, &tempSurface);+ hr=m_pDev->CreateOffscreenPlainSurface(width, height, desc.Format, D3DPOOL_SYSTEMMEM, &tempSurface, NULL);if (hr != S_OK)goto error;-- hr=m_pDev->CopyRects(surface,&srcRect,1,tempSurface,&dstPoint);++ // The source is the render target, so this is the one direction CopyRects had that+ // UpdateSurface and StretchRect cannot do. GetRenderTargetData takes no rectangle,+ // so the surface is the size of the piece being read back and the read starts there.+ {+ IDirect3DSurface9 *wholeTarget = NULL;+ hr=m_pDev->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format,+ D3DPOOL_SYSTEMMEM, &wholeTarget, NULL);+ if (hr == S_OK)+ {+ hr=m_pDev->GetRenderTargetData(surface, wholeTarget);+ if (hr == S_OK)+ hr=D3DXLoadSurfaceFromSurface(tempSurface, NULL, NULL, wholeTarget, NULL, &srcRect,+ D3DX_FILTER_NONE, 0);+ wholeTarget->Release();+ }+ }if (hr != S_OK)goto error;@@ -192,8 +209,12 @@ Int copyRect(unsigned char *buf, Int bufSize, int oX, int oY, int width, int heitempSurface->GetDesc(&desc);- if (desc.Size < bufSize)- bufSize = desc.Size;+ // D3D9's surface description dropped the byte size D3D8 carried, so the readback is+ // measured from the rows the lock reports instead.+ surfaceSize = (unsigned int)lrect.Pitch * desc.Height;++ if (surfaceSize < bufSize)+ bufSize = surfaceSize;memcpy(buf,lrect.pBits,bufSize);result = bufSize;@@ -215,7 +236,7 @@ Bool W3DSmudgeManager::testHardwareSupport(void)if (m_hardwareSupportStatus == SMUDGE_SUPPORT_UNKNOWN){ //we have not done the test yet.- IDirect3DTexture8 *backTexture=W3DShaderManager::getRenderTexture();+ IDirect3DTexture9 *backTexture=W3DShaderManager::getRenderTexture();if (!backTexture){ //do trivial test first to see if render target exists.m_hardwareSupportStatus = SMUDGE_SUPPORT_NO;@@ -261,11 +282,11 @@ Bool W3DSmudgeManager::testHardwareSupport(void)v[2].color = UNIQUE_COLOR;v[3].color = UNIQUE_COLOR;- LPDIRECT3DDEVICE8 pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 pDev=DX8Wrapper::_Get_D3D_Device();//draw polygons like this is very inefficient but for only 2 triangles, it's//not worth bothering with index/vertex buffers.- pDev->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);+ pDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);pDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(_TRANS_LIT_TEX_VERTEX));@@ -352,7 +373,7 @@ void W3DSmudgeManager::render(RenderInfoClass &rinfo)#elseD3DSURFACE_DESC D3DDesc;- IDirect3DTexture8 *backTexture=W3DShaderManager::getRenderTexture();+ IDirect3DTexture9 *backTexture=W3DShaderManager::getRenderTexture();if (!backTexture || !W3DShaderManager::isRenderingToTexture())return; //this card doesn't support render targets.@@ -473,12 +494,12 @@ void W3DSmudgeManager::render(RenderInfoClass &rinfo)#elseDX8Wrapper::Set_DX8_Texture(0,backTexture);//Need these states in case texture is non-power-of-2- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ADDRESSW, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);- DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_MIPFILTER, D3DTEXF_NONE);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);#endifVertexMaterialClass *vmat=VertexMaterialClass::Get_Preset(VertexMaterialClass::PRELIT_DIFFUSE);DX8Wrapper::Set_Material(vmat);@@ -558,12 +579,12 @@ flushSmudges:DX8Wrapper::Draw_Triangles( 0,smudgesInRenderBatch*4, 0, smudgesInRenderBatch*5);//Debug Code which draws outline around smudge-/* DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);+/* DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);DX8Wrapper::Set_DX8_Texture_Stage_State(0,D3DTSS_COLOROP,D3DTOP_SELECTARG2);DX8Wrapper::Draw_Triangles( 0,smudgesInRenderBatch*4, 0, smudgesInRenderBatch*5);- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);DX8Wrapper::Set_DX8_Texture_Stage_State(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);*/smudgesRemaining -= smudgesInRenderBatch;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cppindex dd449a01a..7ecfd181a 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp@@ -83,7 +83,7 @@ Bool W3DSnowManager::ReAcquireResources(void)if (TheWeatherSetting->m_usePointSprites && DX8Wrapper::Get_Current_Caps()->Support_PointSprites()){- LPDIRECT3DDEVICE8 m_pDev=DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();DEBUG_ASSERTCRASH(m_pDev, ("Trying to ReAquireResources on W3DSnowManager without device"));@@ -95,8 +95,9 @@ Bool W3DSnowManager::ReAcquireResources(void)SNOW_BUFFER_SIZE*sizeof(POINTVERTEX),D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC|D3DUSAGE_POINTS,D3DFVF_POINTVERTEX,- D3DPOOL_DEFAULT,- &m_VertexBufferD3D+ D3DPOOL_DEFAULT,+ &m_VertexBufferD3D,+ NULL // pSharedHandle, D3D9's extra parameter, reserved and always null)))return FALSE;}@@ -273,7 +274,7 @@ void W3DSnowManager::renderSubBox(RenderInfoClass &rinfo, Int originX, Int origiPOINTVERTEX* verts;if(m_VertexBufferD3D->Lock(m_dwBase * sizeof(POINTVERTEX), batchSize * sizeof(POINTVERTEX),- (unsigned char **) &verts, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD) != D3D_OK )+ (void **) &verts, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD) != D3D_OK )return; //couldn't lock buffer.Int numberInBatch=0;@@ -318,7 +319,7 @@ flush_particles:if (numberInBatch){Debug_Statistics::Record_DX8_Polys_And_Vertices(numberInBatch*2,numberInBatch*4,ShaderClass::_PresetOpaqueShader);- DX8Wrapper::_Get_D3D_Device8()->DrawPrimitive( D3DPT_POINTLIST, m_dwBase, numberInBatch);+ DX8Wrapper::_Get_D3D_Device()->DrawPrimitive( D3DPT_POINTLIST, m_dwBase, numberInBatch);totalPart -= numberInBatch;m_dwBase += numberInBatch;}@@ -434,8 +435,8 @@ void W3DSnowManager::render(RenderInfoClass &rinfo)DX8Wrapper::Set_DX8_Render_State( D3DRS_POINTSCALE_B, FtoDW(0.00f) );DX8Wrapper::Set_DX8_Render_State( D3DRS_POINTSCALE_C, FtoDW(1.00f) );- DX8Wrapper::_Get_D3D_Device8()->SetStreamSource( 0, m_VertexBufferD3D, sizeof(POINTVERTEX) );- DX8Wrapper::_Get_D3D_Device8()->SetVertexShader( D3DFVF_POINTVERTEX );+ DX8Wrapper::_Get_D3D_Device()->SetStreamSource( 0, m_VertexBufferD3D, 0, sizeof(POINTVERTEX) );+ DX8Wrapper::_Get_D3D_Device()->SetFVF( D3DFVF_POINTVERTEX );m_dwBase = SNOW_BUFFER_SIZE; //start with a new vertex buffer each frame.m_leafDim = 45; //cull boxes that are 20x20 emitters in size. Making them much smaller will result in too many draw calls.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cppindex 61e2d3c8e..a5a76d16d 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp@@ -89,7 +89,8 @@ enum#include "WW3D2/Mesh.h"#include "WW3D2/MeshMdl.h"#include "WW3D2/vertmaterial.h"-#include "d3dx8tex.h"+#include "d3dx9runtime.h"+#include "d3d8shadertranslate.h"#ifdef _INTERNAL// for occasional debugging...@@ -139,7 +140,7 @@ int W3DTreeBuffer::W3DTreeTextureClass::update(W3DTreeBuffer *buffer)Get_Filter().Set_U_Addr_Mode(TextureFilterClass::TEXTURE_ADDRESS_CLAMP);Get_Filter().Set_V_Addr_Mode(TextureFilterClass::TEXTURE_ADDRESS_CLAMP);- IDirect3DSurface8 *surface_level;+ IDirect3DSurface9 *surface_level;D3DSURFACE_DESC surface_desc;D3DLOCKED_RECT locked_rect;DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0, &surface_level));@@ -1205,11 +1206,15 @@ void W3DTreeBuffer::freeTreeBuffers(void)}if (m_dwTreePixelShader)- DX8Wrapper::_Get_D3D_Device8()->DeletePixelShader(m_dwTreePixelShader);+ m_dwTreePixelShader->Release();m_dwTreePixelShader = 0;if (m_dwTreeVertexShader)- DX8Wrapper::_Get_D3D_Device8()->DeleteVertexShader(m_dwTreeVertexShader);+ m_dwTreeVertexShader->Release();+ if (m_treeVertexDeclaration)+ { m_treeVertexDeclaration->Release();+ m_treeVertexDeclaration=NULL;+ }m_dwTreeVertexShader = 0;}@@ -1325,11 +1330,11 @@ void W3DTreeBuffer::allocateTreeBuffers(void)};HRESULT hr;- hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\Trees.vso", &Declaration[0], 0, true, &m_dwTreeVertexShader);+ hr = W3DShaderManager::LoadAndCreateD3DVertexShader("shaders\\Trees.vso", &Declaration[0], &m_dwTreeVertexShader, &m_treeVertexDeclaration);if (FAILED(hr))return;- hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\Trees.pso", &Declaration[0], 0, false, &m_dwTreePixelShader);+ hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\Trees.pso", &m_dwTreePixelShader);if (FAILED(hr))return;}@@ -1939,7 +1944,7 @@ same ones both times - a tree's shadow is that tree's triangles. *///=============================================================================void W3DTreeBuffer::drawTreeBuffers(Bool shadowPass){- LPDIRECT3DDEVICE8 dev = DX8Wrapper::_Get_D3D_Device8();+ LPDIRECT3DDEVICE9 dev = DX8Wrapper::_Get_D3D_Device();if (!dev) {return;}@@ -2287,14 +2292,14 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pDshadowMat._43 += TREE_SHADOW_LIFT * shadowMat._33;shadowMat._44 += TREE_SHADOW_LIFT * shadowMat._34;D3DXMatrixTranspose( &shadowMat, &shadowMat );- DX8Wrapper::_Get_D3D_Device8()->SetVertexShaderConstant( 4, &shadowMat, 4 );+ DX8Wrapper::_Get_D3D_Device()->SetVertexShaderConstantF( 4, (const float*)&shadowMat, 4 );// c8 is the entry a tree with no sway reads, c9 and up are the sway types.Vector4 flat(stretchX, stretchY, -1.0f, 0);- DX8Wrapper::_Get_D3D_Device8()->SetVertexShaderConstant( 8, &flat, 1 );+ DX8Wrapper::_Get_D3D_Device()->SetVertexShaderConstantF( 8, (const float*)&flat, 1 );for (i=0; i<MAX_SWAY_TYPES; i++) {Vector4 flatSway(stretchX + swayFactor[i].X, stretchY + swayFactor[i].Y, -1.0f, 0);- DX8Wrapper::_Get_D3D_Device8()->SetVertexShaderConstant( 9+i, &flatSway, 1 );+ DX8Wrapper::_Get_D3D_Device()->SetVertexShaderConstantF( 9+i, (const float*)&flatSway, 1 );}DX8Wrapper::Set_Shader(treeShadowShader);@@ -2320,7 +2325,7 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pDD3DXMatrixTranspose( &mat, &mat );// c4 - Composite World-View-Projection Matrix- DX8Wrapper::_Get_D3D_Device8()->SetVertexShaderConstant( 4, &mat, 4 );+ DX8Wrapper::_Get_D3D_Device()->SetVertexShaderConstantF( 4, (const float*)&mat, 4 );//// The matrix the trees are about to be drawn with, checked against the one the device is@@ -2352,12 +2357,12 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pD}}Vector4 noSway(0,0,0,0);- DX8Wrapper::_Get_D3D_Device8()->SetVertexShaderConstant( 8, &noSway, 1 );+ DX8Wrapper::_Get_D3D_Device()->SetVertexShaderConstantF( 8, (const float*)&noSway, 1 );// c8 - c8+MAX_SWAY_TYPES - the sway amount.for (i=0; i<MAX_SWAY_TYPES; i++) {Vector4 sway4(swayFactor[i].X, swayFactor[i].Y, swayFactor[i].Z, 0);- DX8Wrapper::_Get_D3D_Device8()->SetVertexShaderConstant( 9+i, &sway4, 1 );+ DX8Wrapper::_Get_D3D_Device()->SetVertexShaderConstantF( 9+i, (const float*)&sway4, 1 );}W3DShroud *shroud;@@ -2371,16 +2376,16 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pDxoffset = -(float)shroud->getDrawOriginX() + width;yoffset = -(float)shroud->getDrawOriginY() + height;Vector4 offset(xoffset, yoffset, 0, 0);- DX8Wrapper::_Get_D3D_Device8()->SetVertexShaderConstant( 32, &offset, 1 );+ DX8Wrapper::_Get_D3D_Device()->SetVertexShaderConstantF( 32, (const float*)&offset, 1 );width = 1.0f/(width*shroud->getTextureWidth());height = 1.0f/(height*shroud->getTextureHeight());offset.Set(width, height, 1, 1);- DX8Wrapper::_Get_D3D_Device8()->SetVertexShaderConstant( 33, &offset, 1 );+ DX8Wrapper::_Get_D3D_Device()->SetVertexShaderConstantF( 33, (const float*)&offset, 1 );} else {Vector4 offset(0,0,0,0);- DX8Wrapper::_Get_D3D_Device8()->SetVertexShaderConstant( 32, &offset, 1 );- DX8Wrapper::_Get_D3D_Device8()->SetVertexShaderConstant( 33, &offset, 1 );+ DX8Wrapper::_Get_D3D_Device()->SetVertexShaderConstantF( 32, (const float*)&offset, 1 );+ DX8Wrapper::_Get_D3D_Device()->SetVertexShaderConstantF( 33, (const float*)&offset, 1 );}DX8Wrapper::Set_Vertex_Shader(m_dwTreeVertexShader);@@ -2390,17 +2395,17 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pDReal mulTwoX = 0.5f;if(TheGlobalData && TheGlobalData->m_useOverbright)mulTwoX = 1.0f;- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(1, D3DXVECTOR4(mulTwoX, mulTwoX, mulTwoX, mulTwoX), 1);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstant(1, D3DXVECTOR4(mulTwoX, mulTwoX, mulTwoX, mulTwoX), 1);#endif} else {- DX8Wrapper::Set_Vertex_Shader(DX8_FVF_XYZNDUV1);+ DX8Wrapper::Set_Vertex_Format(DX8_FVF_XYZNDUV1);}drawTreeBuffers(false);- DX8Wrapper::Set_Vertex_Shader(DX8_FVF_XYZNDUV1);+ DX8Wrapper::Set_Vertex_Format(DX8_FVF_XYZNDUV1);DX8Wrapper::Set_Pixel_Shader(NULL);DX8Wrapper::Invalidate_Cached_Render_States(); //code above mucks around with W3D states so make sure we resetdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex d7d6d6b35..6657dc16b 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -80,7 +80,7 @@#include "W3DDevice/GameClient/W3DDisplay.h"#include "W3DDevice/GameClient/W3DScene.h"#include "W3DDevice/GameClient/W3DView.h"-#include "D3dx8math.h"+#include "d3dx9math.h"#include "W3DDevice/GameClient/W3DShaderManager.h"#include "W3DDevice/GameClient/Module/W3DModelDraw.h"#include "W3DDevice/GameClient/W3DCustomScene.h"diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DWebBrowser.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DWebBrowser.cppindex 0b12816e8..c7cc8afa6 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DWebBrowser.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DWebBrowser.cpp@@ -32,7 +32,7 @@#include "GameClient/Image.h"#include "GameClient/GameWindow.h"#include "vector2i.h"-#include <d3dx8.h>+#include "d3dx9runtime.h"#include "WW3D2/dx8wrapper.h"#include "WW3D2/dx8WebBrowser.h"diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cppindex 977a20f39..d18ddb1e7 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp@@ -44,7 +44,8 @@#include "scene.h"#include "dx8wrapper.h"#include "light.h"-#include "D3dx8math.h"+#include "d3dx9math.h"+#include "d3d8shadertranslate.h"#include "simplevec.h"#include "mesh.h"#include "matinfo.h"@@ -249,9 +250,9 @@ void WaterRenderObjClass::setupJbaWaterShader(void)DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ALPHAOP, D3DTOP_ADD );if (!m_riverAlphaEdge->Is_Initialized())m_riverAlphaEdge->Init();- DX8Wrapper::_Get_D3D_Device8()->SetTexture(3,m_riverAlphaEdge->Peek_D3D_Texture());- DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(3,m_riverAlphaEdge->Peek_D3D_Texture());+ DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXCOORDINDEX, 0);DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXCOORDINDEX, 0);DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DTSS_TEXCOORDINDEX, 1);@@ -261,20 +262,20 @@ void WaterRenderObjClass::setupJbaWaterShader(void)if (m_riverWaterPixelShader && doSparkles) {if (!m_waterSparklesTexture->Is_Initialized())m_waterSparklesTexture->Init();- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1,m_waterSparklesTexture->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1,m_waterSparklesTexture->Peek_D3D_Texture());if (!m_waterNoiseTexture->Is_Initialized())m_waterNoiseTexture->Init();- DX8Wrapper::_Get_D3D_Device8()->SetTexture(2,m_waterNoiseTexture->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(2,m_waterNoiseTexture->Peek_D3D_Texture());- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);D3DXMATRIX inv;float det;@@ -290,17 +291,17 @@ void WaterRenderObjClass::setupJbaWaterShader(void)DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE2, *(Matrix4x4*)&destMatrix);}- m_pDev->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 1, D3DTSS_MINFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 2, D3DTSS_MINFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 2, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 3, D3DTSS_MINFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 3, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 3, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );if (m_riverWaterPixelShader){- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(0, D3DXVECTOR4(REFLECTION_FACTOR, REFLECTION_FACTOR, REFLECTION_FACTOR, 1.0f), 1);- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_riverWaterPixelShader);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(0, D3DXVECTOR4(REFLECTION_FACTOR, REFLECTION_FACTOR, REFLECTION_FACTOR, 1.0f), 1);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_riverWaterPixelShader);}}@@ -462,7 +463,7 @@ RenderObjClass * WaterRenderObjClass::Clone(void) const/** Copies raw bits from pBumpSrc (a regular grayscale texture) into a D3D* bump-map format. *///--------------------------------------------------------------------------------------------------HRESULT WaterRenderObjClass::initBumpMap(LPDIRECT3DTEXTURE8 *pTex, TextureClass *pBumpSource)+HRESULT WaterRenderObjClass::initBumpMap(LPDIRECT3DTEXTURE9 *pTex, TextureClass *pBumpSource){SurfaceClass::SurfaceDescription d3dsd;SurfaceClass * surf;@@ -691,8 +692,9 @@ HRESULT WaterRenderObjClass::generateVertexBuffer( Int sizeX, Int sizeY, Int verm_numVertices*vertexSize,usage,fvf,- pool,- &m_vertexBufferD3D+ pool,+ &m_vertexBufferD3D,+ NULL // pSharedHandle, D3D9's extra parameter, reserved and always null)))return hr;}@@ -707,7 +709,7 @@ HRESULT WaterRenderObjClass::generateVertexBuffer( Int sizeX, Int sizeY, Int ver(0,m_numVertices*sizeof(SEA_PATCH_VERTEX),- (BYTE**)&pVertices,+ (void**)&pVertices,0//D3DLOCK_DISCARD)))return hr;@@ -756,8 +758,9 @@ HRESULT WaterRenderObjClass::generateIndexBuffer(Int sizeX, Int sizeY)(m_numIndices+2)*sizeof(WORD),D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,- D3DPOOL_MANAGED,- &m_indexBufferD3D+ D3DPOOL_MANAGED,+ &m_indexBufferD3D,+ NULL // pSharedHandle, D3D9's extra parameter, reserved and always null)))return hr;@@ -765,7 +768,7 @@ HRESULT WaterRenderObjClass::generateIndexBuffer(Int sizeX, Int sizeY)(0,m_numIndices*sizeof(WORD),- (BYTE**)&pIndices,+ (void**)&pIndices,0)))return hr;@@ -851,19 +854,23 @@ void WaterRenderObjClass::ReleaseResources(void)m_waterTrackSystem->ReleaseResources();if (m_dwWavePixelShader)- m_pDev->DeletePixelShader(m_dwWavePixelShader);+ m_dwWavePixelShader->Release();if (m_dwWaveVertexShader)- m_pDev->DeleteVertexShader(m_dwWaveVertexShader);+ m_dwWaveVertexShader->Release();+ if (m_waveVertexDeclaration)+ { m_waveVertexDeclaration->Release();+ m_waveVertexDeclaration=NULL;+ }if (m_waterPixelShader)- m_pDev->DeletePixelShader(m_waterPixelShader);+ m_waterPixelShader->Release();if (m_trapezoidWaterPixelShader)- m_pDev->DeletePixelShader(m_trapezoidWaterPixelShader);+ m_trapezoidWaterPixelShader->Release();if (m_riverWaterPixelShader)- m_pDev->DeletePixelShader(m_riverWaterPixelShader);+ m_riverWaterPixelShader->Release();m_dwWavePixelShader=0;m_dwWaveVertexShader=0;@@ -898,7 +905,7 @@ void WaterRenderObjClass::ReAcquireResources(void)ib[5]=1;}- m_pDev=DX8Wrapper::_Get_D3D_Device8();+ m_pDev=DX8Wrapper::_Get_D3D_Device();//We're using the same grid for either 3D Water Mesh or Pixel/Vertex shader. Just//allocate the right size depending on usage@@ -929,11 +936,11 @@ void WaterRenderObjClass::ReAcquireResources(void)(D3DVSD_END())};- hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\wave.pso", &Declaration[0], 0, false, &m_dwWavePixelShader);+ hr = W3DShaderManager::LoadAndCreateD3DPixelShader("shaders\\wave.pso", &m_dwWavePixelShader);if (FAILED(hr))return;- hr = W3DShaderManager::LoadAndCreateD3DShader("shaders\\wave.vso", &Declaration[0], 0, true, &m_dwWaveVertexShader);+ hr = W3DShaderManager::LoadAndCreateD3DVertexShader("shaders\\wave.vso", &Declaration[0], &m_dwWaveVertexShader, &m_waveVertexDeclaration);if (FAILED(hr))return;@@ -960,9 +967,9 @@ void WaterRenderObjClass::ReAcquireResources(void)mul r1.rgb, r1, v0.a ; sparkles and the edge glow do get darkened by the shroud. \n\+mul r0.a, r0, t3\n\add r0.rgb, r0, r1\n";- hr = D3DXAssembleShader( shader, strlen(shader), 0, NULL, &compiledShader, NULL);+ hr = D3DXAssembleShader( shader, (UINT)strlen(shader), NULL, NULL, 0, &compiledShader, NULL);if (hr==0) {- hr = DX8Wrapper::_Get_D3D_Device8()->CreatePixelShader((DWORD*)compiledShader->GetBufferPointer(), &m_riverWaterPixelShader);+ hr = DX8Wrapper::_Get_D3D_Device()->CreatePixelShader((DWORD*)compiledShader->GetBufferPointer(), &m_riverWaterPixelShader);compiledShader->Release();}shader =@@ -973,9 +980,9 @@ void WaterRenderObjClass::ReAcquireResources(void)mul r0,v0,t0 ; blend vertex color into t0. \n\mul r1.rgb,t2,c0 ; reduce t2 (environment mapped reflection) by constant\n\add r0.rgb, r0, r1";- hr = D3DXAssembleShader( shader, strlen(shader), 0, NULL, &compiledShader, NULL);+ hr = D3DXAssembleShader( shader, (UINT)strlen(shader), NULL, NULL, 0, &compiledShader, NULL);if (hr==0) {- hr = DX8Wrapper::_Get_D3D_Device8()->CreatePixelShader((DWORD*)compiledShader->GetBufferPointer(), &m_waterPixelShader);+ hr = DX8Wrapper::_Get_D3D_Device()->CreatePixelShader((DWORD*)compiledShader->GetBufferPointer(), &m_waterPixelShader);compiledShader->Release();}shader =@@ -988,9 +995,9 @@ void WaterRenderObjClass::ReAcquireResources(void)mad r0.rgb, t1, t2, r0 ; blend sparkles and noise \n\mul r0.rgb, r0, t3 ; blend in black shroud \n\;\n";- hr = D3DXAssembleShader( shader, strlen(shader), 0, NULL, &compiledShader, NULL);+ hr = D3DXAssembleShader( shader, (UINT)strlen(shader), NULL, NULL, 0, &compiledShader, NULL);if (hr==0) {- hr = DX8Wrapper::_Get_D3D_Device8()->CreatePixelShader((DWORD*)compiledShader->GetBufferPointer(), &m_trapezoidWaterPixelShader);+ hr = DX8Wrapper::_Get_D3D_Device()->CreatePixelShader((DWORD*)compiledShader->GetBufferPointer(), &m_trapezoidWaterPixelShader);compiledShader->Release();}}@@ -1089,7 +1096,7 @@ Int WaterRenderObjClass::init(Real waterLevel, Real dx, Real dy, SceneClass *par#if 0 //MD does not support the old bump-mapped water at all so no point loading textures. -MW 8-11-03if (type == WATER_TYPE_2_PVSHADER || (W3DShaderManager::getChipset() >= DC_GENERIC_PIXEL_SHADER_1_1)){ //geforce3 specific water requires some extra D3D assets- m_pDev=DX8Wrapper::_Get_D3D_Device8();+ m_pDev=DX8Wrapper::_Get_D3D_Device();//save previous thumbnail modebool thumbnails_enabled = WW3D::Get_Thumbnail_Enabled();WW3D::Set_Thumbnail_Enabled(false);@@ -1595,7 +1602,7 @@ void WaterRenderObjClass::renderMirror(CameraClass *cam)WW3D::End_Render(false);// Change the rendertarget back to the main backbuffer- DX8Wrapper::Set_Render_Target((IDirect3DSurface8 *)NULL);+ DX8Wrapper::Set_Render_Target((IDirect3DSurface9 *)NULL);}//-------------------------------------------------------------------------------------------------@@ -1721,8 +1728,8 @@ void WaterRenderObjClass::Render(RenderInfoClass & rinfo)inv *=clipMatrix;// Change texture wrapping mode to 'clamp' for texture stage 1- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);// Use CameraSpace vertices as input to matrix and use texture wrap mode from stage 1DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION|1);@@ -1733,8 +1740,8 @@ void WaterRenderObjClass::Render(RenderInfoClass & rinfo)DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE1, *((Matrix4*)&inv));// Disable bilinear filtering- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MINFILTER, D3DTEXF_POINT);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_MAGFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);// Pass stage 0 texture data untouched(by modulating with white)DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); //stage 1 texture@@ -1929,27 +1936,27 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)m_pDev->SetTextureStageState( 3, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);m_pDev->SetTextureStageState( 3, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU|3);-// m_pDev->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );-// m_pDev->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );-// m_pDev->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_POINT );+// m_pDev->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );+// m_pDev->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );+// m_pDev->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT );-// m_pDev->SetTextureStageState( 1, D3DTSS_MINFILTER, D3DTEXF_POINT );-// m_pDev->SetTextureStageState( 1, D3DTSS_MAGFILTER, D3DTEXF_POINT );-// m_pDev->SetTextureStageState( 1, D3DTSS_MIPFILTER, D3DTEXF_NONE );+// m_pDev->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_POINT );+// m_pDev->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_POINT );+// m_pDev->SetSamplerState( 1, D3DSAMP_MIPFILTER, D3DTEXF_NONE );//end of default setup- m_pDev->SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- m_pDev->SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ m_pDev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ m_pDev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);m_pDev->SetRenderState( D3DRS_WRAP0, D3DWRAP_U | D3DWRAP_V);- m_pDev->SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);- m_pDev->SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ m_pDev->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ m_pDev->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);m_pDev->SetTexture( 0, m_pBumpTexture[m_iBumpFrame]);#ifdef MIPMAP_BUMP_TEXTURE- m_pDev->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_POINT );- m_pDev->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT );+ m_pDev->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );#endifm_pDev->SetTextureStageState( 1, D3DTSS_BUMPENVMAT00, F2DW(m_fBumpScale) );m_pDev->SetTextureStageState( 1, D3DTSS_BUMPENVMAT01, F2DW(0.0f) );@@ -1971,11 +1978,11 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)mat._31 = 0.0f; mat._32 = 0.0f; mat._33 = 0.0f; mat._34=1.0f;mat._41 = 0.0f; mat._42 = 0.0f; mat._43 = 0.0f; mat._44=1.0f;- m_pDev->SetVertexShaderConstant(CV_TEXPROJ_0, &mat, 4);+ m_pDev->SetVertexShaderConstantF(CV_TEXPROJ_0, (const float*)&mat, 4);// Setup constants- m_pDev->SetVertexShaderConstant(CV_ZERO, D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f), 1);- m_pDev->SetVertexShaderConstant(CV_ONE, D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f), 1);+ m_pDev->SetVertexShaderConstantF(CV_ZERO, D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f), 1);+ m_pDev->SetVertexShaderConstantF(CV_ONE, D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f), 1);m_pDev->SetVertexShader(m_dwWaveVertexShader);m_pDev->SetPixelShader(m_dwWavePixelShader);@@ -2001,8 +2008,8 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)patchMatrix._33=PATCH_SCALE;patchMatrix._44=1.0f;- m_pDev->SetStreamSource(0,m_vertexBufferD3D,sizeof(WaterRenderObjClass::SEA_PATCH_VERTEX));- m_pDev->SetIndices(m_indexBufferD3D,0);+ m_pDev->SetStreamSource(0,m_vertexBufferD3D,0,sizeof(WaterRenderObjClass::SEA_PATCH_VERTEX));+ m_pDev->SetIndices(m_indexBufferD3D);for (startY=patchY=(seaBox.Center.Y-seaBox.Extent.Y)/(PATCH_WIDTH*PATCH_SCALE); (patchY*PATCH_WIDTH*PATCH_SCALE)<(seaBox.Center.Y+seaBox.Extent.Y); patchY++){@@ -2018,9 +2025,9 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)D3DXMatrixMultiply(&matWorldViewProj, &matTemp, &matProj);//matrices must be transposed before loading into vertex shader registersD3DXMatrixTranspose(&matWorldViewProj, &matWorldViewProj);- m_pDev->SetVertexShaderConstant(CV_WORLDVIEWPROJ_0, &matWorldViewProj, 4); //pass transform matrix into shader+ m_pDev->SetVertexShaderConstantF(CV_WORLDVIEWPROJ_0, (const float*)&matWorldViewProj, 4); //pass transform matrix into shader- m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,0,m_numVertices,0,m_numIndices);+ m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,0,0,m_numVertices,0,m_numIndices);}}// m_pDev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);@@ -2035,8 +2042,8 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)m_pDev->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU|1);m_pDev->SetRenderState(D3DRS_ZWRITEENABLE , TRUE);- m_pDev->SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- m_pDev->SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ m_pDev->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ m_pDev->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);m_pDev->SetRenderState( D3DRS_WRAP0, 0); //turn off texture wrapping@@ -2052,7 +2059,8 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)DX8Wrapper::_Set_DX8_Transform(D3DTS_PROJECTION, *(Matrix4x4*)&matProj);m_pDev->SetPixelShader(0); //turn off pixel shader- m_pDev->SetVertexShader(DX8_FVF_XYZDUV1); //turn off custom vertex shader+ m_pDev->SetVertexShader(NULL); //turn off custom vertex shader+ m_pDev->SetFVF(DX8_FVF_XYZDUV1);DX8Wrapper::Invalidate_Cached_Render_States();@@ -2061,8 +2069,8 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)//do second pass to apply the shroud on water planeW3DShaderManager::setTexture(0,TheTerrainRenderObject->getShroud()->getShroudTexture());W3DShaderManager::setShader(W3DShaderManager::ST_SHROUD_TEXTURE, 0);- m_pDev->SetStreamSource(0,m_vertexBufferD3D,sizeof(WaterRenderObjClass::SEA_PATCH_VERTEX));- m_pDev->SetIndices(m_indexBufferD3D,0);+ m_pDev->SetStreamSource(0,m_vertexBufferD3D,0,sizeof(WaterRenderObjClass::SEA_PATCH_VERTEX));+ m_pDev->SetIndices(m_indexBufferD3D);for (startY=patchY=(seaBox.Center.Y-seaBox.Extent.Y)/(PATCH_WIDTH*PATCH_SCALE); (patchY*PATCH_WIDTH*PATCH_SCALE)<(seaBox.Center.Y+seaBox.Extent.Y); patchY++){for (startX=patchX=(seaBox.Center.X-seaBox.Extent.X)/(PATCH_WIDTH*PATCH_SCALE); (patchX*PATCH_WIDTH*PATCH_SCALE)<(seaBox.Center.X+seaBox.Extent.X); patchX++)@@ -2075,7 +2083,7 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)DX8Wrapper::_Set_DX8_Transform(D3DTS_WORLD, *(Matrix4x4*)&matTemp);- m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,0,m_numVertices,0,m_numIndices);+ m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,0,0,m_numVertices,0,m_numIndices);}}W3DShaderManager::resetShader(W3DShaderManager::ST_SHROUD_TEXTURE);@@ -2390,12 +2398,12 @@ void WaterRenderObjClass::renderWaterMesh(void)MaterMeshVertexFormat *vb;if (m_vertexBufferD3DOffset < m_numVertices){ //we have room in current VB, append new verts- if(m_vertexBufferD3D->Lock(m_vertexBufferD3DOffset*sizeof(MaterMeshVertexFormat),mx*my*sizeof(MaterMeshVertexFormat),(unsigned char**)&vb,D3DLOCK_NOOVERWRITE) != D3D_OK)+ if(m_vertexBufferD3D->Lock(m_vertexBufferD3DOffset*sizeof(MaterMeshVertexFormat),mx*my*sizeof(MaterMeshVertexFormat),(void**)&vb,D3DLOCK_NOOVERWRITE) != D3D_OK)return;}else{ //ran out of room in last VB, request a substitute VB.- if(m_vertexBufferD3D->Lock(0,mx*my*sizeof(MaterMeshVertexFormat),(unsigned char**)&vb,D3DLOCK_DISCARD) != D3D_OK)+ if(m_vertexBufferD3D->Lock(0,mx*my*sizeof(MaterMeshVertexFormat),(void**)&vb,D3DLOCK_DISCARD) != D3D_OK)return;m_vertexBufferD3DOffset=0; //reset start of page to first vertex}@@ -2501,9 +2509,10 @@ void WaterRenderObjClass::renderWaterMesh(void)// m_pDev->SetRenderState(D3DRS_ZFUNC,D3DCMP_ALWAYS); //used to display grid under map.- m_pDev->SetIndices(m_indexBufferD3D,m_vertexBufferD3DOffset);- m_pDev->SetStreamSource(0,m_vertexBufferD3D,sizeof(MaterMeshVertexFormat));- m_pDev->SetVertexShader(WATER_MESH_FVF);+ // D3D9 takes the base vertex index on the draw call, not here.+ m_pDev->SetIndices(m_indexBufferD3D);+ m_pDev->SetStreamSource(0,m_vertexBufferD3D,0,sizeof(MaterMeshVertexFormat));+ m_pDev->SetFVF(WATER_MESH_FVF);if (TheTerrainRenderObject->getShroud() && !m_trapezoidWaterPixelShader)@@ -2520,19 +2529,19 @@ void WaterRenderObjClass::renderWaterMesh(void)//Shroud shader uses z-compare of EQUAL which wouldn't work on water because it doesn't//write to the zbuffer. Change to LESSEQUAL.- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);- m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,0,mx*my,0,m_numIndices-2);- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);+ m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,m_vertexBufferD3DOffset,0,mx*my,0,m_numIndices-2);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);W3DShaderManager::resetShader(W3DShaderManager::ST_SHROUD_TEXTURE);}else- m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,0,mx*my,0,m_numIndices-2);+ m_pDev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP,m_vertexBufferD3DOffset,0,mx*my,0,m_numIndices-2);Debug_Statistics::Record_DX8_Polys_And_Vertices(m_numIndices-2,mx*my,ShaderClass::_PresetOpaqueShader);// m_pDev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);- if (m_trapezoidWaterPixelShader) DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(NULL);+ if (m_trapezoidWaterPixelShader) DX8Wrapper::_Get_D3D_Device()->SetPixelShader(NULL);m_vertexBufferD3DOffset += mx*my; //advance past vertices already in buffer@@ -2999,22 +3008,22 @@ void WaterRenderObjClass::drawRiverWater(PolygonTrigger *pTrig)if (TheWaterTransparency->m_additiveBlend)DX8Wrapper::Set_DX8_Render_State(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );- if (m_riverWaterPixelShader) DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_riverWaterPixelShader);+ if (m_riverWaterPixelShader) DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_riverWaterPixelShader);DWORD cull;- DX8Wrapper::_Get_D3D_Device8()->GetRenderState(D3DRS_CULLMODE, &cull);- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);+ DX8Wrapper::_Get_D3D_Device()->GetRenderState(D3DRS_CULLMODE, &cull);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);if (wireframeForDebug) {- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);}DX8Wrapper::Draw_Triangles( 0,rectangleCount*2, 0, (rectangleCount+1)*2);if (wireframeForDebug) {- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);}- if (m_riverWaterPixelShader) DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(NULL);+ if (m_riverWaterPixelShader) DX8Wrapper::_Get_D3D_Device()->SetPixelShader(NULL);//restore blend mode to what W3D expects.if (TheWaterTransparency->m_additiveBlend)@@ -3022,7 +3031,7 @@ void WaterRenderObjClass::drawRiverWater(PolygonTrigger *pTrig)// the shroud is in the vertex colour now - see applyShroudToRiverDiffuse. The second pass that// used to apply it here darkened the banks twice.- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_CULLMODE, cull);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_CULLMODE, cull);}@@ -3054,7 +3063,7 @@ void WaterRenderObjClass::setupFlatWaterShader(void)W3DShaderManager::setShader(W3DShaderManager::ST_SHROUD_TEXTURE, 3);//Shroud shader uses z-compare of EQUAL which wouldn't work on water because it doesn't//write to the zbuffer. Change to LESSEQUAL.- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);}else{ //Assume no shroud, so stage 3 will be "NULL" texture but using actual white because@@ -3065,7 +3074,7 @@ void WaterRenderObjClass::setupFlatWaterShader(void)surface->DrawPixel(0,0,0xffffffff);REF_PTR_RELEASE(surface);}- DX8Wrapper::_Get_D3D_Device8()->SetTexture(3,m_whiteTexture->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(3,m_whiteTexture->Peek_D3D_Texture());}}@@ -3080,21 +3089,21 @@ void WaterRenderObjClass::setupFlatWaterShader(void)if (!m_waterSparklesTexture->Is_Initialized())m_waterSparklesTexture->Init();- DX8Wrapper::_Get_D3D_Device8()->SetTexture(1,m_waterSparklesTexture->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(1,m_waterSparklesTexture->Peek_D3D_Texture());if (!m_waterNoiseTexture->Is_Initialized())m_waterNoiseTexture->Init();- DX8Wrapper::_Get_D3D_Device8()->SetTexture(2,m_waterNoiseTexture->Peek_D3D_Texture());+ DX8Wrapper::_Get_D3D_Device()->SetTexture(2,m_waterNoiseTexture->Peek_D3D_Texture());- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);// Two output coordinates are used.DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);D3DXMATRIX inv;float det;@@ -3110,15 +3119,15 @@ void WaterRenderObjClass::setupFlatWaterShader(void)DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE2, *(Matrix4x4*)&destMatrix);}- m_pDev->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 1, D3DTSS_MINFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 2, D3DTSS_MINFILTER, D3DTEXF_LINEAR );- m_pDev->SetTextureStageState( 2, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );+ m_pDev->SetSamplerState( 2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );if (m_trapezoidWaterPixelShader){- DX8Wrapper::_Get_D3D_Device8()->SetPixelShaderConstant(0, D3DXVECTOR4(REFLECTION_FACTOR, REFLECTION_FACTOR, REFLECTION_FACTOR, 1.0f), 1);- DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(m_trapezoidWaterPixelShader);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(0, D3DXVECTOR4(REFLECTION_FACTOR, REFLECTION_FACTOR, REFLECTION_FACTOR, 1.0f), 1);+ DX8Wrapper::_Get_D3D_Device()->SetPixelShader(m_trapezoidWaterPixelShader);}}@@ -3368,8 +3377,8 @@ void WaterRenderObjClass::drawTrapezoidWater(Vector3 points[4])DWORD cull;- DX8Wrapper::_Get_D3D_Device8()->GetRenderState(D3DRS_CULLMODE, &cull);- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);+ DX8Wrapper::_Get_D3D_Device()->GetRenderState(D3DRS_CULLMODE, &cull);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);@@ -3398,14 +3407,14 @@ void WaterRenderObjClass::drawTrapezoidWater(Vector3 points[4])if (false) {- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);m_pDev->SetRenderState(D3DRS_ALPHABLENDENABLE , false);DX8Wrapper::Draw_Triangles( 0,rectangleCount*2, 0, (rectangleCount+1)*2);m_pDev->SetRenderState(D3DRS_ALPHABLENDENABLE , true);- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);}- if (m_riverWaterPixelShader) DX8Wrapper::_Get_D3D_Device8()->SetPixelShader(NULL);+ if (m_riverWaterPixelShader) DX8Wrapper::_Get_D3D_Device()->SetPixelShader(NULL);//Restore alpha blend to default values since we may have changed them to feather edges.if (!TheWaterTransparency->m_additiveBlend){ DX8Wrapper::Set_DX8_Render_State(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );@@ -3422,23 +3431,23 @@ void WaterRenderObjClass::drawTrapezoidWater(Vector3 points[4])if (m_trapezoidWaterPixelShader){ //shroud was applied in stage3 of main pass so just need to restore state here.W3DShaderManager::resetShader(W3DShaderManager::ST_SHROUD_TEXTURE);- DX8Wrapper::_Get_D3D_Device8()->SetTexture(3,NULL); //free possible reference to shroud texture- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);+ DX8Wrapper::_Get_D3D_Device()->SetTexture(3,NULL); //free possible reference to shroud texture+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);}else{ //do second pass to apply the shroud on water plane for cards that can't do it in main pass.W3DShaderManager::setTexture(0,TheTerrainRenderObject->getShroud()->getShroudTexture());W3DShaderManager::setShader(W3DShaderManager::ST_SHROUD_TEXTURE, 0);- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);//Shroud shader uses z-compare of EQUAL which wouldn't work on water because it doesn't//write to the zbuffer. Change to LESSEQUAL.- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);DX8Wrapper::Draw_Triangles( 0,rectangleCount*2, 0, (rectangleCount+1)*2);- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);W3DShaderManager::resetShader(W3DShaderManager::ST_SHROUD_TEXTURE);}}- DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_CULLMODE, cull);+ DX8Wrapper::_Get_D3D_Device()->SetRenderState(D3DRS_CULLMODE, cull);}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cppindex 59f85a9d1..b8f390126 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp@@ -320,12 +320,12 @@ Int WaterTracksObj::render(DX8VertexBufferClass *vertexBuffer, Int batchStart)if (batchStart < (WATER_VB_PAGES*WATER_STRIP_X*WATER_STRIP_Y-m_x*m_y)){ //we have room in current VB, append new verts- if(vertexBuffer->Get_DX8_Vertex_Buffer()->Lock(batchStart*vertexBuffer->FVF_Info().Get_FVF_Size(),m_x*m_y*vertexBuffer->FVF_Info().Get_FVF_Size(),(unsigned char**)&vb,D3DLOCK_NOOVERWRITE) != D3D_OK)+ if(vertexBuffer->Get_DX8_Vertex_Buffer()->Lock(batchStart*vertexBuffer->FVF_Info().Get_FVF_Size(),m_x*m_y*vertexBuffer->FVF_Info().Get_FVF_Size(),(void**)&vb,D3DLOCK_NOOVERWRITE) != D3D_OK)return batchStart;}else{ //ran out of room in last VB, request a substitute VB.- if(vertexBuffer->Get_DX8_Vertex_Buffer()->Lock(0,m_x*m_y*vertexBuffer->FVF_Info().Get_FVF_Size(),(unsigned char**)&vb,D3DLOCK_DISCARD) != D3D_OK)+ if(vertexBuffer->Get_DX8_Vertex_Buffer()->Lock(0,m_x*m_y*vertexBuffer->FVF_Info().Get_FVF_Size(),(void**)&vb,D3DLOCK_DISCARD) != D3D_OK)return batchStart;batchStart=0; //reset start of page to first vertex}@@ -933,7 +933,7 @@ Try improving the fit to vertical surfaces like cliffs.DX8Wrapper::Set_Shader(m_shaderClass);DX8Wrapper::Set_Vertex_Buffer(m_vertexBuffer);- DX8Wrapper::Set_DX8_Render_State(D3DRS_ZBIAS,8);+ DX8Wrapper::Set_DX8_ZBias(8);//Force apply of render states so we can override them.DX8Wrapper::Apply_Render_State_Changes();@@ -969,7 +969,7 @@ Try improving the fit to vertical surfaces like cliffs.mod = mod->m_nextSystem;} //while (mod)- DX8Wrapper::Set_DX8_Render_State(D3DRS_ZBIAS,0);+ DX8Wrapper::Set_DX8_ZBias(0);if (TheTerrainRenderObject->getShroud()){ //we used the shroud shader, so reset it.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/camerashakesystem.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/camerashakesystem.cppindex dfe56fe43..b5505b08b 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/camerashakesystem.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/camerashakesystem.cpp@@ -46,7 +46,7 @@#include <coltest.h>#include <rinfo.h>#include <camera.h>-#include <d3dx8core.h>+#include "d3dx9runtime.h"#include "Common/GlobalData.h"#include "Common/PerfTimer.h"diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cppindex 2adcaaf86..bd4f83356 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cpp@@ -114,7 +114,7 @@#include <ini.h>#include <windows.h>#include <stdio.h>-#include <D3dx8core.h>+#include "d3dx9runtime.h"#include "texture.h"#include "wwprofile.h"#include "assetstatus.h"@@ -318,7 +318,7 @@ static void Log_Textures(bool inited,unsigned& total_count, unsigned& total_mem)if (tex->Is_Initialized()!=inited) continue;D3DSURFACE_DESC desc;- IDirect3DTexture8* d3d_texture=tex->Peek_D3D_Texture();+ IDirect3DTexture9* d3d_texture=tex->Peek_D3D_Texture();if (!d3d_texture) continue;DX8_ErrorCode(d3d_texture->GetLevelDesc(0,&desc));@@ -345,7 +345,6 @@ static void Log_Textures(bool inited,unsigned& total_count, unsigned& total_mem)case D3DFMT_X8L8V8U8: tex_format="D3DFMT_X8L8V8U8"; break;case D3DFMT_Q8W8V8U8: tex_format="D3DFMT_Q8W8V8U8"; break;case D3DFMT_V16U16: tex_format="D3DFMT_V16U16"; break;- case D3DFMT_W11V11U10: tex_format="D3DFMT_W11V11U10"; break;case D3DFMT_UYVY: tex_format="D3DFMT_UYVY"; break;case D3DFMT_YUY2: tex_format="D3DFMT_YUY2"; break;case D3DFMT_DXT1: tex_format="D3DFMT_DXT1"; break;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cppindex 3caa21c5c..d07322555 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp@@ -724,7 +724,7 @@ void CameraClass::Apply(void)bool windowed;WW3D::Get_Render_Target_Resolution(width,height,bits,windowed);- D3DVIEWPORT8 vp;+ D3DVIEWPORT9 vp;vp.X = (DWORD)(Viewport.Min.X * (float)width);vp.Y = (DWORD)(Viewport.Min.Y * (float)height);vp.Width = (DWORD)((Viewport.Max.X - Viewport.Min.X) * (float)width);diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3d8shadertranslate.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3d8shadertranslate.cppnew file mode 100644index 000000000..b3518d6b3--- /dev/null+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3d8shadertranslate.cpp@@ -0,0 +1,405 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+**+** The assembly repairs below are taken from crosire's d3d8to9+** (https://github.com/crosire/d3d8to9, BSD 3-clause), vendored in this tree at+** Libraries/Source/d3d8to9, with its proxy-object plumbing removed.+*/++#include "d3d8shadertranslate.h"+#include "d3dx9runtime.h"++#include <regex>+#include <string>++// The register file a vs_1_1 shader can name, which bounds both the initialisation pass+// and the search for a spare register when an m*x* has to be unaliased.+static const size_t TEMPORARY_REGISTER_COUNT = 12;+static const size_t TEXTURE_OUTPUT_REGISTER_COUNT = 8;+static const size_t COLOUR_OUTPUT_REGISTER_COUNT = 2;+// vs_1_1's instruction budget. A repair that would push the shader past it is dropped+// rather than making the shader fail to assemble.+static const size_t MAX_VERTEX_INSTRUCTIONS = 128;+static const size_t MAX_DECLARATION_ELEMENTS = 32;++// The D3D8 data type of a declaration token, and the number of bytes it advances the+// stream offset by.+struct DeclarationType+{+ BYTE Type;+ BYTE Size;+};++static const DeclarationType DECLARATION_TYPES[] =+{+ { D3DDECLTYPE_FLOAT1, 4 },+ { D3DDECLTYPE_FLOAT2, 8 },+ { D3DDECLTYPE_FLOAT3, 12 },+ { D3DDECLTYPE_FLOAT4, 16 },+ { D3DDECLTYPE_D3DCOLOR, 4 },+ { D3DDECLTYPE_UBYTE4, 4 },+ { D3DDECLTYPE_SHORT2, 4 },+ { D3DDECLTYPE_SHORT4, 8 }+};++// D3D8 addressed vertex inputs by a fixed register number whose meaning was baked into+// the API; D3D9 names a usage and an index instead. This is that table.+struct DeclarationUsage+{+ BYTE Usage;+ BYTE UsageIndex;+};++static const DeclarationUsage DECLARATION_USAGES[] =+{+ { D3DDECLUSAGE_POSITION, 0 },+ { D3DDECLUSAGE_BLENDWEIGHT, 0 },+ { D3DDECLUSAGE_BLENDINDICES, 0 },+ { D3DDECLUSAGE_NORMAL, 0 },+ { D3DDECLUSAGE_PSIZE, 0 },+ { D3DDECLUSAGE_COLOR, 0 },+ { D3DDECLUSAGE_COLOR, 1 },+ { D3DDECLUSAGE_TEXCOORD, 0 },+ { D3DDECLUSAGE_TEXCOORD, 1 },+ { D3DDECLUSAGE_TEXCOORD, 2 },+ { D3DDECLUSAGE_TEXCOORD, 3 },+ { D3DDECLUSAGE_TEXCOORD, 4 },+ { D3DDECLUSAGE_TEXCOORD, 5 },+ { D3DDECLUSAGE_TEXCOORD, 6 },+ { D3DDECLUSAGE_TEXCOORD, 7 },+ { D3DDECLUSAGE_POSITION, 1 },+ { D3DDECLUSAGE_NORMAL, 1 }+};++static const size_t DECLARATION_TYPE_COUNT = sizeof(DECLARATION_TYPES)/sizeof(DECLARATION_TYPES[0]);+static const size_t DECLARATION_USAGE_COUNT = sizeof(DECLARATION_USAGES)/sizeof(DECLARATION_USAGES[0]);++// D3DXDisassembleShader's output carries the shader's own name and comment bytes, which+// can be anything at all; the assembler will not take a control character.+static std::string readable_disassembly(ID3DXBuffer * disassembly)+{+ const char * const raw = static_cast<const char *>(disassembly->GetBufferPointer());+ const size_t size = disassembly->GetBufferSize();++ std::string text;+ text.reserve(size);+ for (size_t index = 0; index < size; ++index) {+ const unsigned char character = static_cast<unsigned char>(raw[index]);+ const bool is_printable = character == '\t' || character == '\n' || character == '\r'+ || (character >= ' ' && character <= '~');+ if (is_printable) {+ text.push_back(static_cast<char>(character));+ }+ }+ return text;+}++static const char * usage_declaration_keyword(BYTE usage)+{+ switch (usage) {+ case D3DDECLUSAGE_POSITION: return "dcl_position";+ case D3DDECLUSAGE_BLENDWEIGHT: return "dcl_blendweight";+ case D3DDECLUSAGE_BLENDINDICES: return "dcl_blendindices";+ case D3DDECLUSAGE_NORMAL: return "dcl_normal";+ case D3DDECLUSAGE_PSIZE: return "dcl_psize";+ case D3DDECLUSAGE_COLOR: return "dcl_color";+ case D3DDECLUSAGE_TEXCOORD: return "dcl_texcoord";+ default: return NULL;+ }+}++// How many arithmetic instructions the disassembly says it used, which bounds how many+// repair instructions can still be inserted.+static size_t instruction_count_of(const std::string & source, const char * counter_word,+ size_t digit_count, size_t default_count)+{+ const size_t position = source.find(counter_word);+ if (position <= digit_count || position >= source.size()) {+ return default_count;+ }+ return strtoul(source.substr(position - digit_count - 1, digit_count).c_str(), NULL, 10);+}++HRESULT Create_Translated_Pixel_Shader(IDirect3DDevice9 * device, const DWORD * function,+ IDirect3DPixelShader9 ** shader)+{+ if (device == NULL || function == NULL || shader == NULL) {+ return D3DERR_INVALIDCALL;+ }+ *shader = NULL;++ if (D3DXDisassembleShader == NULL || D3DXAssembleShader == NULL) {+ return D3DERR_INVALIDCALL;+ }+ if (*function < D3DPS_VERSION(1, 0) || *function > D3DPS_VERSION(1, 4)) {+ return D3DERR_INVALIDCALL;+ }++ ID3DXBuffer * disassembly = NULL;+ HRESULT result = D3DXDisassembleShader(function, FALSE, NULL, &disassembly);+ if (FAILED(result)) {+ return result;+ }++ std::string source = readable_disassembly(disassembly);+ disassembly->Release();++ const size_t version_position = source.find("ps_1_");+ if (version_position == std::string::npos) {+ return D3DERR_INVALIDCALL;+ }+ if (source.at(version_position + 5) == '0') {+ source.replace(version_position, 6, "ps_1_1"); // D3D9 dropped ps_1_0+ }++ // The disassembler writes the original D3D8 source as a comment block and #line+ // directives; neither survives reassembly.+ source = std::regex_replace(source, std::regex(" \\/\\/ ps\\.1\\.[1-4]\\n((?! ).+\\n)+"), "");+ source = std::regex_replace(source, std::regex("([^\\n]\\n)[\\s]*#line [0123456789]+.*\\n"), "$1");++ // D3D9 refuses a negation modifier on a constant register in an add; the same+ // arithmetic written as a sub is accepted.+ source = std::regex_replace(source,+ std::regex("(add)([_satxd248]*) (r[0-9][\\.wxyz]*), ((1-|)[crtv][0-9][\\.wxyz_abdis2]*), (-)(c[0-9][\\.wxyz]*)(_bx2|_bias|_x2|_d[zbwa]|)(?![_\\.wxyz])"),+ "sub$2 $3, $4, $7$8");++ ID3DXBuffer * assembly = NULL;+ ID3DXBuffer * errors = NULL;+ result = D3DXAssembleShader(source.data(), static_cast<UINT>(source.size()), NULL, NULL, 0,+ &assembly, &errors);+ if (errors != NULL) {+ errors->Release();+ }+ if (FAILED(result)) {+ return result;+ }++ result = device->CreatePixelShader(static_cast<const DWORD *>(assembly->GetBufferPointer()), shader);+ assembly->Release();+ return result;+}++HRESULT Create_Translated_Vertex_Shader(IDirect3DDevice9 * device, const DWORD * d3d8_declaration,+ const DWORD * function, IDirect3DVertexShader9 ** shader,+ IDirect3DVertexDeclaration9 ** vertex_declaration)+{+ if (device == NULL || d3d8_declaration == NULL || function == NULL+ || shader == NULL || vertex_declaration == NULL) {+ return D3DERR_INVALIDCALL;+ }+ *shader = NULL;+ *vertex_declaration = NULL;++ if (D3DXDisassembleShader == NULL || D3DXAssembleShader == NULL) {+ return D3DERR_INVALIDCALL;+ }+ if (*function < D3DVS_VERSION(1, 0) || *function > D3DVS_VERSION(1, 1)) {+ return D3DERR_INVALIDCALL;+ }++ // Decode the D3D8 declaration into D3D9 elements, remembering which vN register each+ // element feeds so the dcl_ lines can name it.+ D3DVERTEXELEMENT9 elements[MAX_DECLARATION_ELEMENTS];+ DWORD input_registers[MAX_DECLARATION_ELEMENTS];+ size_t element_count = 0;+ WORD stream = 0;+ WORD offset = 0;++ for (const DWORD * token = d3d8_declaration; *token != D3DVSD_END(); ++token) {+ if (element_count + 1 >= MAX_DECLARATION_ELEMENTS) {+ return D3DERR_INVALIDCALL;+ }++ const DWORD token_type = (*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT;+ if (token_type == D3DVSD_TOKEN_STREAM) {+ stream = static_cast<WORD>((*token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT);+ offset = 0;+ }+ else if (token_type == D3DVSD_TOKEN_STREAMDATA && (*token & 0x10000000) != 0) {+ offset = static_cast<WORD>(offset+ + ((*token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT) * sizeof(DWORD));+ }+ else if (token_type == D3DVSD_TOKEN_STREAMDATA) {+ const DWORD type = (*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT;+ const DWORD address = (*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT;+ if (type >= DECLARATION_TYPE_COUNT || address >= DECLARATION_USAGE_COUNT) {+ return D3DERR_INVALIDCALL;+ }++ elements[element_count].Stream = stream;+ elements[element_count].Offset = offset;+ elements[element_count].Type = DECLARATION_TYPES[type].Type;+ elements[element_count].Method = D3DDECLMETHOD_DEFAULT;+ elements[element_count].Usage = DECLARATION_USAGES[address].Usage;+ elements[element_count].UsageIndex = DECLARATION_USAGES[address].UsageIndex;+ offset = static_cast<WORD>(offset + DECLARATION_TYPES[type].Size);++ input_registers[element_count] = address;+ ++element_count;+ }+ else {+ // Tessellator and constant-memory tokens; no shader this game ships uses one.+ return D3DERR_INVALIDCALL;+ }+ }++ const D3DVERTEXELEMENT9 terminator = D3DDECL_END();+ elements[element_count] = terminator;++ ID3DXBuffer * disassembly = NULL;+ HRESULT result = D3DXDisassembleShader(function, FALSE, NULL, &disassembly);+ if (FAILED(result)) {+ return result;+ }++ std::string source = readable_disassembly(disassembly);+ disassembly->Release();++ const size_t version_position = source.find("vs_1_");+ if (version_position == std::string::npos) {+ return D3DERR_INVALIDCALL;+ }+ if (source.at(version_position + 5) == '0') {+ source.replace(version_position, 6, "vs_1_1"); // D3D9 dropped vs_1_0+ }++ // D3D9 wants the inputs declared inside the shader.+ size_t insert_position = version_position + 7;+ for (size_t index = 0; index < element_count; ++index) {+ const char * const keyword = usage_declaration_keyword(elements[index].Usage);+ if (keyword == NULL) {+ return D3DERR_INVALIDCALL;+ }++ std::string declaration_line = " ";+ declaration_line += keyword;+ if (elements[index].UsageIndex > 0) {+ declaration_line += std::to_string(elements[index].UsageIndex);+ }+ declaration_line += " v" + std::to_string(input_registers[index]) + '\n';++ source.insert(insert_position, declaration_line);+ insert_position += declaration_line.length();+ }++ size_t instruction_count = instruction_count_of(source, "instruction", 3, 0);++ // D3D9 refuses to read a register that was never written. Writing c0 into every+ // register the shader mentions costs an instruction each and changes nothing the+ // shader goes on to compute, because anything it reads it also writes first.+ for (size_t index = 0; index < TEXTURE_OUTPUT_REGISTER_COUNT; ++index) {+ const std::string name = "oT" + std::to_string(index);+ if (source.find(name) != std::string::npos && instruction_count < MAX_VERTEX_INSTRUCTIONS) {+ ++instruction_count;+ source.insert(insert_position, " mov " + name + ", c0\n");+ }+ }+ for (size_t index = 0; index < COLOUR_OUTPUT_REGISTER_COUNT; ++index) {+ const std::string name = "oD" + std::to_string(index);+ if (source.find(name) != std::string::npos && instruction_count < MAX_VERTEX_INSTRUCTIONS) {+ ++instruction_count;+ source.insert(insert_position, " mov " + name + ", c0\n");+ }+ }+ for (size_t index = 0; index < TEMPORARY_REGISTER_COUNT; ++index) {+ const std::string name = "r" + std::to_string(index);+ if (source.find(name) != std::string::npos && instruction_count < MAX_VERTEX_INSTRUCTIONS) {+ ++instruction_count;+ source.insert(insert_position, " mov " + name + ", c0\n");+ }+ }++ source = std::regex_replace(source, std::regex(" \\/\\/ vs\\.1\\.1\\n((?! ).+\\n)+"), "");+ source = std::regex_replace(source, std::regex("([^\\n]\\n)[\\s]*#line [0123456789]+.*\\n"), "$1");++ // oFog and oPts take one component in D3D9 and took four in D3D8.+ source = std::regex_replace(source, std::regex("(oFog|oPts)\\.x"), "$1");+ source = std::regex_replace(source,+ std::regex("(add|sub|mul|min|max) (oFog|oPts), ([cr][0-9]+), (.+)\\n"), "$1 $2, $3.x, $4\n");+ source = std::regex_replace(source,+ std::regex("(add|sub|mul|min|max) (oFog|oPts), (.+), ([cr][0-9]+)\\n"), "$1 $2, $3, $4.x\n");+ source = std::regex_replace(source,+ std::regex("(mov|mad) (oFog|oPts)(.*), (-?)([crv][0-9]+(?![\\.0-9]))"), "$1 $2$3, $4$5.x");++ // An m3x3 or m4x4 may not read its own destination as its first source. Copy that+ // source into a register the shader does not use, and read it from there.+ if (std::regex_search(source, std::regex("m.x."))) {+ size_t spare_register = 0;+ while (spare_register < TEMPORARY_REGISTER_COUNT+ && source.find("r" + std::to_string(spare_register)) != std::string::npos) {+ ++spare_register;+ }++ for (size_t index = 0; index < TEMPORARY_REGISTER_COUNT; ++index) {+ const std::string aliased =+ "(m.x.) (r" + std::to_string(index) + "), ((-?)r" + std::to_string(index) + "([\\.xyzw]*))(?![0-9])";++ while (std::regex_search(source, std::regex(aliased))) {+ if (spare_register < TEMPORARY_REGISTER_COUNT && instruction_count < MAX_VERTEX_INSTRUCTIONS) {+ ++instruction_count;+ source = std::regex_replace(source, std::regex(aliased),+ "mov r" + std::to_string(spare_register) + ", $2\n $1 $2, $4r"+ + std::to_string(spare_register) + "$5",+ std::regex_constants::format_first_only);+ }+ else {+ // Nowhere to put the copy. Comment the instruction out rather than+ // leave an assembly the assembler will reject outright.+ source = std::regex_replace(source, std::regex("(.*" + aliased + ".*)"), "/*$1*/");+ break;+ }+ }+ }+ }++ // oPos must be written in full.+ if (std::regex_search(source, std::regex(" ([a-z2-4]*) oPos\\."))+ && !std::regex_search(source, std::regex(" ([a-z2-4]*) oPos,"))) {+ const bool writes_x = std::regex_search(source, std::regex(" ([a-z2-4]*) oPos\\.[y|z|w]*x"));+ const bool writes_y = std::regex_search(source, std::regex(" ([a-z2-4]*) oPos\\.[x|z|w]*y"));+ const bool writes_z = std::regex_search(source, std::regex(" ([a-z2-4]*) oPos\\.[x|y|w]*z"));+ const bool writes_w = std::regex_search(source, std::regex(" ([a-z2-4]*) oPos\\.[x|y|z]*w"));+ if (!writes_x || !writes_y || !writes_z || !writes_w) {+ source = std::regex_replace(source,+ std::regex(" ([a-z2-4]*) (oPos\\.[x|y|z|w]*,) ([^\\n]*)\\n"), " $1 oPos, $3\n");+ }+ }++ ID3DXBuffer * assembly = NULL;+ ID3DXBuffer * errors = NULL;+ result = D3DXAssembleShader(source.data(), static_cast<UINT>(source.size()), NULL, NULL, 0,+ &assembly, &errors);+ if (errors != NULL) {+ errors->Release();+ }+ if (FAILED(result)) {+ return result;+ }++ result = device->CreateVertexShader(static_cast<const DWORD *>(assembly->GetBufferPointer()), shader);+ assembly->Release();+ if (FAILED(result)) {+ return result;+ }++ result = device->CreateVertexDeclaration(elements, vertex_declaration);+ if (FAILED(result)) {+ (*shader)->Release();+ *shader = NULL;+ }+ return result;+}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3d8shadertranslate.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3d8shadertranslate.hnew file mode 100644index 000000000..faf404125--- /dev/null+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3d8shadertranslate.h@@ -0,0 +1,95 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++// Loading the shipped D3D8 shaders on a Direct3D 9 device. RENDERER-ROADMAP.md phase 1.+//+// The game reads six compiled shaders out of its big archives: Trees.vso and wave.vso+// are vs_1_1, terrain.pso, terrainnoise.pso, terrainnoise2.pso and monochrome.pso are+// ps_1_1. None of them loads on a D3D9 device as it stands, because D3D9 tightened+// rules that the D3D8 assembler allowed:+//+// - a vertex declaration travelled beside the shader as a DWORD array, and D3D9 wants+// dcl_ statements inside the shader text plus a separate declaration object;+// - a register could be read before it was written;+// - an m3x3 or m4x4 could name its destination as its own first source;+// - oFog and oPts could be written with more than one component.+//+// So a shader is disassembled, its assembly text repaired, and reassembled. The+// repairs are lifted from crosire's d3d8to9 (d3d8to9_device.cpp), which is BSD-licensed+// and vendored in this tree, and which is what has been translating these same six+// shaders under this renderer since the port. What is not lifted is that project's+// ps_1_4 rewriting path, which exists for shaders that put modifiers on constant+// registers; none of the six does, and a shader that trips it fails to load and says so+// rather than being half-translated. A failed pixel shader is not fatal to the game:+// W3DShaderManager falls back to its fixed-function two-stage terrain shader, the same+// path a card with no pixel shader support takes.++#ifndef D3D8SHADERTRANSLATE_H+#define D3D8SHADERTRANSLATE_H++#include <d3d9.h>++// The D3D8 vertex declaration tokens, so the declaration arrays the engine already+// writes keep compiling. D3D9 has no such tokens; Create_Translated_Vertex_Shader+// decodes them into a D3DVERTEXELEMENT9 array.+#define D3DVSD_TOKEN_STREAM 1+#define D3DVSD_TOKEN_STREAMDATA 2+#define D3DVSD_TOKENTYPESHIFT 29+#define D3DVSD_TOKENTYPEMASK (0x7 << D3DVSD_TOKENTYPESHIFT)+#define D3DVSD_STREAMNUMBERSHIFT 0+#define D3DVSD_STREAMNUMBERMASK (0xF << D3DVSD_STREAMNUMBERSHIFT)+#define D3DVSD_VERTEXREGSHIFT 0+#define D3DVSD_VERTEXREGMASK (0x1F << D3DVSD_VERTEXREGSHIFT)+#define D3DVSD_DATATYPESHIFT 16+#define D3DVSD_DATATYPEMASK (0xF << D3DVSD_DATATYPESHIFT)+#define D3DVSD_SKIPCOUNTSHIFT 16+#define D3DVSD_SKIPCOUNTMASK (0xF << D3DVSD_SKIPCOUNTSHIFT)++#define D3DVSD_MAKETOKENTYPE(token_type) (((token_type) << D3DVSD_TOKENTYPESHIFT) & D3DVSD_TOKENTYPEMASK)+#define D3DVSD_STREAM(stream_number) (D3DVSD_MAKETOKENTYPE(D3DVSD_TOKEN_STREAM) | (stream_number))+#define D3DVSD_REG(vertex_register, type) \+ (D3DVSD_MAKETOKENTYPE(D3DVSD_TOKEN_STREAMDATA) | \+ (((type) << D3DVSD_DATATYPESHIFT) & D3DVSD_DATATYPEMASK) | (vertex_register))+#define D3DVSD_SKIP(dword_count) \+ (D3DVSD_MAKETOKENTYPE(D3DVSD_TOKEN_STREAMDATA) | 0x10000000 | \+ (((dword_count) << D3DVSD_SKIPCOUNTSHIFT) & D3DVSD_SKIPCOUNTMASK))+#define D3DVSD_END() 0xFFFFFFFF++#define D3DVSDT_FLOAT1 0x00+#define D3DVSDT_FLOAT2 0x01+#define D3DVSDT_FLOAT3 0x02+#define D3DVSDT_FLOAT4 0x03+#define D3DVSDT_D3DCOLOR 0x04+#define D3DVSDT_UBYTE4 0x05+#define D3DVSDT_SHORT2 0x06+#define D3DVSDT_SHORT4 0x07++// Translates ps_1_x bytecode compiled for D3D8 and creates the shader. Returns+// D3DERR_INVALIDCALL for anything that is not ps_1_0 to ps_1_4.+HRESULT Create_Translated_Pixel_Shader(IDirect3DDevice9 * device, const DWORD * function,+ IDirect3DPixelShader9 ** shader);++// Translates vs_1_x bytecode and its D3D8 declaration array, and creates both the shader+// and the D3D9 vertex declaration that has to be bound with it. Either output may come+// back null only if the call failed; on success both are set and both are the caller's+// to release.+HRESULT Create_Translated_Vertex_Shader(IDirect3DDevice9 * device, const DWORD * d3d8_declaration,+ const DWORD * function, IDirect3DVertexShader9 ** shader,+ IDirect3DVertexDeclaration9 ** vertex_declaration);++#endif // D3D8SHADERTRANSLATE_Hdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9math.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9math.hindex 02bda7b29..9f30f154c 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9math.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9math.h@@ -90,6 +90,10 @@ public:FLOAT & operator()(UINT row, UINT column) { return m[row][column]; }FLOAT operator()(UINT row, UINT column) const { return m[row][column]; }++ // Defined below, once D3DXMatrixMultiply has been declared.+ D3DXMATRIX operator*(const D3DXMATRIX & right) const;+ D3DXMATRIX & operator*=(const D3DXMATRIX & right);};typedef HRESULT (WINAPI * D3DXMatrixInverseFunction)(D3DXMATRIX * out, FLOAT * determinant,@@ -127,6 +131,22 @@ extern D3DXVec3TransformFunction D3DXVec3Transform;// and shader entry points: one place decides whether D3DX9 is present, and one answer// covers all of it. Every pointer is null until it succeeds.+// The D3DX matrix product, which is D3DXMatrixMultiply and nothing else: writing the+// sixty-four multiplies out here instead would put a second, differently rounded matrix+// product in the same renderer.+inline D3DXMATRIX D3DXMATRIX::operator*(const D3DXMATRIX & right) const+{+ D3DXMATRIX product;+ D3DXMatrixMultiply(&product, this, &right);+ return product;+}++inline D3DXMATRIX & D3DXMATRIX::operator*=(const D3DXMATRIX & right)+{+ D3DXMatrixMultiply(this, this, &right);+ return *this;+}+// The two the DirectX SDK inlined, copied from d3dx8math.inl so the arithmetic that// reaches a replay CRC is the arithmetic that always reached it.inline FLOAT D3DXVec4Dot(const D3DXVECTOR4 * left, const D3DXVECTOR4 * right)diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9runtime.cppindex c44749e6d..03ca6764f 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9runtime.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9runtime.cpp@@ -190,6 +190,14 @@ static void release_module(void)}}+UINT Get_FVF_Vertex_Size(DWORD fvf)+{+ if (!Bind_D3DX9_Runtime()) {+ return 0;+ }+ return D3DXGetFVFVertexSize(fvf);+}+const char * Get_D3D_Error_String(HRESULT result){for (int index = 0; index < ERROR_NAME_COUNT; ++index) {diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9runtime.hindex 4b4690956..3ec8db94b 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9runtime.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/d3dx9runtime.h@@ -130,4 +130,10 @@ void Unbind_D3DX9_Runtime(void);// and falls back to the raw hex for anything else. Never returns null.const char * Get_D3D_Error_String(HRESULT result);+// The size in bytes of a vertex in the given FVF. This is the one D3DX call the engine+// makes before there is a device, from FVFInfoClass and from HeightMap's software+// transform path, so it binds the runtime itself rather than trusting the caller to have+// done it. Returns 0 if D3DX9 is not there at all.+UINT Get_FVF_Vertex_Size(DWORD fvf);+#endif // D3DX9RUNTIME_Hdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cppindex a711966e2..f0507e9c0 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp@@ -342,7 +342,7 @@ WWINLINE static unsigned short ARGB8888_To_RGB565(unsigned argb_)//// -----------------------------------------------------------------------------void DDSFileClass::Copy_Level_To_Surface(unsigned level,IDirect3DSurface8* d3d_surface,const Vector3& hsv_shift)+void DDSFileClass::Copy_Level_To_Surface(unsigned level,IDirect3DSurface9* d3d_surface,const Vector3& hsv_shift){WWASSERT(d3d_surface);// Verify that the destination surface size matches the source surface sizediff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.hindex 07bd8e80f..b70443a7e 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.h@@ -30,8 +30,8 @@#include "wwstring.h"#include "vector3.h"-struct IDirect3DSurface8;-struct IDirect3DVolume8;+struct IDirect3DSurface9;+struct IDirect3DVolume9;// ----------------------------------------------------------------------------//@@ -220,7 +220,7 @@ public:DDSType Get_Type() const { return Type; }// Copy pixels to the destination surface.- void Copy_Level_To_Surface(unsigned level,IDirect3DSurface8* d3d_surface,const Vector3& hsv_shift=Vector3(0.0f,0.0f,0.0f));+ void Copy_Level_To_Surface(unsigned level,IDirect3DSurface9* d3d_surface,const Vector3& hsv_shift=Vector3(0.0f,0.0f,0.0f));void Copy_Level_To_Surface(unsigned level,WW3DFormat dest_format,diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8caps.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8caps.cppindex cea81f2ed..06334fc94 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8caps.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8caps.cpp@@ -464,10 +464,10 @@ DX8Caps::DeviceTypeIntel DX8Caps::Get_Intel_Device(unsigned device_id)}DX8Caps::DX8Caps(- IDirect3D8* direct3d,- IDirect3DDevice8* D3DDevice,+ IDirect3D9* direct3d,+ IDirect3DDevice9* D3DDevice,WW3DFormat display_format,- const D3DADAPTER_IDENTIFIER8& adapter_id)+ const D3DADAPTER_IDENTIFIER9& adapter_id):Direct3D(direct3d),MaxDisplayWidth(0),@@ -478,10 +478,10 @@ DX8Caps::DX8Caps(}DX8Caps::DX8Caps(- IDirect3D8* direct3d,- const D3DCAPS8& caps,+ IDirect3D9* direct3d,+ const D3DCAPS9& caps,WW3DFormat display_format,- const D3DADAPTER_IDENTIFIER8& adapter_id)+ const D3DADAPTER_IDENTIFIER9& adapter_id):Direct3D(direct3d),Caps(caps),@@ -510,15 +510,18 @@ void DX8Caps::Shutdown(void)//// -----------------------------------------------------------------------------void DX8Caps::Init_Caps(IDirect3DDevice8* D3DDevice)+void DX8Caps::Init_Caps(IDirect3DDevice9* D3DDevice){- D3DDevice->SetRenderState(D3DRS_SOFTWAREVERTEXPROCESSING,TRUE);+ // D3D9 took software vertex processing off the render state list and gave it its own+ // pair of calls. The caps are read twice on purpose: a mixed device reports a+ // different set in each mode, and the hardware set is the one that has to stick.+ D3DDevice->SetSoftwareVertexProcessing(TRUE);DX8CALL(GetDeviceCaps(&Caps));if ((Caps.DevCaps&D3DDEVCAPS_HWTRANSFORMANDLIGHT)==D3DDEVCAPS_HWTRANSFORMANDLIGHT) {SupportTnL=true;- D3DDevice->SetRenderState(D3DRS_SOFTWAREVERTEXPROCESSING,FALSE);+ D3DDevice->SetSoftwareVertexProcessing(FALSE);DX8CALL(GetDeviceCaps(&Caps));} else {SupportTnL=false;@@ -530,7 +533,7 @@ void DX8Caps::Init_Caps(IDirect3DDevice8* D3DDevice)// Compute the caps bits//// -----------------------------------------------------------------------------void DX8Caps::Compute_Caps(WW3DFormat display_format, const D3DADAPTER_IDENTIFIER8& adapter_id)+void DX8Caps::Compute_Caps(WW3DFormat display_format, const D3DADAPTER_IDENTIFIER9& adapter_id){// Init_Caps(D3DDevice);@@ -632,7 +635,7 @@ void DX8Caps::Compute_Caps(WW3DFormat display_format, const D3DADAPTER_IDENTIFIESupportPointSprites = (Caps.MaxPointSize > 1.0f);SupportNPatches = ((Caps.DevCaps&D3DDEVCAPS_NPATCHES)==D3DDEVCAPS_NPATCHES);- SupportZBias = ((Caps.RasterCaps&D3DPRASTERCAPS_ZBIAS)==D3DPRASTERCAPS_ZBIAS);+ SupportZBias = ((Caps.RasterCaps&D3DPRASTERCAPS_DEPTHBIAS)==D3DPRASTERCAPS_DEPTHBIAS);supportGamma=((Caps.Caps2&D3DCAPS2_FULLSCREENGAMMA)==D3DCAPS2_FULLSCREENGAMMA);SupportModAlphaAddClr = (Caps.TextureOpCaps & D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR) == D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR;SupportDot3=(Caps.TextureOpCaps & D3DTEXOPCAPS_DOTPRODUCT3) == D3DTEXOPCAPS_DOTPRODUCT3;@@ -671,7 +674,7 @@ void DX8Caps::Compute_Caps(WW3DFormat display_format, const D3DADAPTER_IDENTIFIE//// -----------------------------------------------------------------------------void DX8Caps::Check_Bumpmap_Support(const D3DCAPS8& caps)+void DX8Caps::Check_Bumpmap_Support(const D3DCAPS9& caps){SupportBumpEnvmap=!!(caps.TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAP);SupportBumpEnvmapLuminance=!!(caps.TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAPLUMINANCE);@@ -685,7 +688,7 @@ void DX8Caps::Check_Bumpmap_Support(const D3DCAPS8& caps)//// -----------------------------------------------------------------------------void DX8Caps::Check_Texture_Compression_Support(const D3DCAPS8& caps)+void DX8Caps::Check_Texture_Compression_Support(const D3DCAPS9& caps){SupportDXTC=SupportTextureFormat[WW3D_FORMAT_DXT1]|SupportTextureFormat[WW3D_FORMAT_DXT2]|@@ -695,7 +698,7 @@ void DX8Caps::Check_Texture_Compression_Support(const D3DCAPS8& caps)DXLOG(("Texture compression support: %s\r\n",SupportDXTC ? "Yes" : "No"));}-void DX8Caps::Check_Texture_Format_Support(WW3DFormat display_format,const D3DCAPS8& caps)+void DX8Caps::Check_Texture_Format_Support(WW3DFormat display_format,const D3DCAPS9& caps){if (display_format==WW3D_FORMAT_UNKNOWN) {for (unsigned i=0;i<WW3D_FORMAT_COUNT;++i) {@@ -727,7 +730,7 @@ void DX8Caps::Check_Texture_Format_Support(WW3DFormat display_format,const D3DCA}}-void DX8Caps::Check_Render_To_Texture_Support(WW3DFormat display_format,const D3DCAPS8& caps)+void DX8Caps::Check_Render_To_Texture_Support(WW3DFormat display_format,const D3DCAPS9& caps){if (display_format==WW3D_FORMAT_UNKNOWN) {for (unsigned i=0;i<WW3D_FORMAT_COUNT;++i) {@@ -763,7 +766,7 @@ void DX8Caps::Check_Render_To_Texture_Support(WW3DFormat display_format,const D3//! Check Depth Stencil Format Support/*! KJM*/-void DX8Caps::Check_Depth_Stencil_Support(WW3DFormat display_format, const D3DCAPS8& caps)+void DX8Caps::Check_Depth_Stencil_Support(WW3DFormat display_format, const D3DCAPS9& caps){if (display_format==WW3D_FORMAT_UNKNOWN){@@ -808,12 +811,12 @@ void DX8Caps::Check_Depth_Stencil_Support(WW3DFormat display_format, const D3DCA}}-void DX8Caps::Check_Maximum_Texture_Support(const D3DCAPS8& caps)+void DX8Caps::Check_Maximum_Texture_Support(const D3DCAPS9& caps){MaxSimultaneousTextures=caps.MaxSimultaneousTextures;}-void DX8Caps::Check_Shader_Support(const D3DCAPS8& caps)+void DX8Caps::Check_Shader_Support(const D3DCAPS9& caps){VertexShaderVersion=caps.VertexShaderVersion;PixelShaderVersion=caps.PixelShaderVersion;@@ -1003,7 +1006,7 @@ bool DX8Caps::Is_Valid_Display_Format(int width, int height, WW3DFormat format)//// -----------------------------------------------------------------------------void DX8Caps::Vendor_Specific_Hacks(const D3DADAPTER_IDENTIFIER8& adapter_id)+void DX8Caps::Vendor_Specific_Hacks(const D3DADAPTER_IDENTIFIER9& adapter_id){if (VendorId==VENDOR_NVIDIA){diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8caps.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8caps.hindex 3f8c689b0..8256250b4 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8caps.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8caps.h@@ -46,7 +46,7 @@#include "always.h"#include "ww3dformat.h"-#include <d3d8.h>+#include <d3d9.h>class DX8Caps{@@ -207,11 +207,11 @@ public:};- DX8Caps(IDirect3D8* direct3d, const D3DCAPS8& caps,WW3DFormat display_format, const D3DADAPTER_IDENTIFIER8& adapter_id);- DX8Caps(IDirect3D8* direct3d, IDirect3DDevice8* D3DDevice,WW3DFormat display_format, const D3DADAPTER_IDENTIFIER8& adapter_id);+ DX8Caps(IDirect3D9* direct3d, const D3DCAPS9& caps,WW3DFormat display_format, const D3DADAPTER_IDENTIFIER9& adapter_id);+ DX8Caps(IDirect3D9* direct3d, IDirect3DDevice9* D3DDevice,WW3DFormat display_format, const D3DADAPTER_IDENTIFIER9& adapter_id);static void Shutdown(void);- void Compute_Caps(WW3DFormat display_format, const D3DADAPTER_IDENTIFIER8& adapter_id);+ void Compute_Caps(WW3DFormat display_format, const D3DADAPTER_IDENTIFIER9& adapter_id);bool Support_TnL() const { return SupportTnL; };bool Support_DXTC() const { return SupportDXTC; }bool Support_Gamma() const { return supportGamma; }@@ -248,7 +248,7 @@ public:bool Support_Render_To_Texture_Format(WW3DFormat format) const { return SupportRenderToTextureFormat[format]; }bool Support_Depth_Stencil_Format(WW3DZFormat format) const { return SupportDepthStencilFormat[format]; }- D3DCAPS8 const & Get_DX8_Caps() const { return Caps; }+ D3DCAPS9 const & Get_DX8_Caps() const { return Caps; }const StringClass& Get_Log() const { return CapsLog; }const StringClass& Get_Compact_Log() const { return CompactLog; }@@ -272,21 +272,21 @@ private:static DeviceTypeS3 Get_S3_Device(unsigned device_id);static DeviceTypeIntel Get_Intel_Device(unsigned device_id);- void Init_Caps(IDirect3DDevice8* D3DDevice);- void Check_Texture_Format_Support(WW3DFormat display_format,const D3DCAPS8& caps);- void Check_Render_To_Texture_Support(WW3DFormat display_format,const D3DCAPS8& caps);- void Check_Depth_Stencil_Support(WW3DFormat display_format, const D3DCAPS8& caps);- void Check_Texture_Compression_Support(const D3DCAPS8& caps);- void Check_Bumpmap_Support(const D3DCAPS8& caps);- void Check_Shader_Support(const D3DCAPS8& caps);- void Check_Maximum_Texture_Support(const D3DCAPS8& caps);+ void Init_Caps(IDirect3DDevice9* D3DDevice);+ void Check_Texture_Format_Support(WW3DFormat display_format,const D3DCAPS9& caps);+ void Check_Render_To_Texture_Support(WW3DFormat display_format,const D3DCAPS9& caps);+ void Check_Depth_Stencil_Support(WW3DFormat display_format, const D3DCAPS9& caps);+ void Check_Texture_Compression_Support(const D3DCAPS9& caps);+ void Check_Bumpmap_Support(const D3DCAPS9& caps);+ void Check_Shader_Support(const D3DCAPS9& caps);+ void Check_Maximum_Texture_Support(const D3DCAPS9& caps);void Check_Driver_Version_Status();- void Vendor_Specific_Hacks(const D3DADAPTER_IDENTIFIER8& adapter_id);+ void Vendor_Specific_Hacks(const D3DADAPTER_IDENTIFIER9& adapter_id);int MaxDisplayWidth;int MaxDisplayHeight;- D3DCAPS8 Caps;+ D3DCAPS9 Caps;bool SupportTnL;bool SupportDXTC;bool supportGamma;@@ -313,7 +313,7 @@ private:DriverVersionStatusType DriverVersionStatus;VendorIdType VendorId;StringClass DriverDLL;- IDirect3D8* Direct3D; // warning XDK name conflict KJM+ IDirect3D9* Direct3D; // warning XDK name conflict KJMStringClass CapsLog;StringClass CompactLog;};diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8fvf.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8fvf.cppindex d822f97fe..9a1c4b714 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8fvf.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8fvf.cpp@@ -41,14 +41,9 @@#include "dx8fvf.h"#include "wwstring.h"-#include <D3dx8core.h>+#include "d3dx9runtime.h"-static unsigned Get_FVF_Vertex_Size(unsigned FVF)-{- return D3DXGetFVFVertexSize(FVF);-}--FVFInfoClass::FVFInfoClass(unsigned FVF_, unsigned vertex_size)+FVFInfoClass::FVFInfoClass(unsigned FVF_, unsigned vertex_size):FVF(FVF_),fvf_size(FVF!=0 ? Get_FVF_Vertex_Size(FVF) : vertex_size)diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8fvf.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8fvf.hindex 1363ca705..00e91541f 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8fvf.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8fvf.h@@ -48,7 +48,7 @@#define DX8_FVF_H#include "always.h"-#include <d3d8.h>+#include <d3d9.h>#ifdef WWDEBUG#include "wwdebug.h"#endifdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cppindex 5f60ef114..00bba4e57 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp@@ -200,7 +200,7 @@ IndexBufferClass::WriteLockClass::WriteLockClass(IndexBufferClass* index_buffer_DX8_ErrorCode(static_cast<DX8IndexBufferClass*>(index_buffer)->Get_DX8_Index_Buffer()->Lock(0,index_buffer->Get_Index_Count()*sizeof(WORD),- (unsigned char**)&indices,+ (void**)&indices,flags));break;case BUFFER_TYPE_SORTING:@@ -256,7 +256,7 @@ IndexBufferClass::AppendLockClass::AppendLockClass(IndexBufferClass* index_buffeDX8_ErrorCode(static_cast<DX8IndexBufferClass*>(index_buffer)->index_buffer->Lock(start_index*sizeof(unsigned short),index_range*sizeof(unsigned short),- (unsigned char**)&indices,+ (void**)&indices,0));break;case BUFFER_TYPE_SORTING:@@ -304,7 +304,7 @@ DX8IndexBufferClass::DX8IndexBufferClass(unsigned short index_count_,UsageType uscratch_indices=NULL;// Same as the vertex buffer: no render device, no D3D buffer. See Create_Vertex_Buffer.- if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ if (DX8Wrapper::_Get_D3D_Device() == NULL) {scratch_indices=W3DNEWARRAY unsigned short[index_count];return;}@@ -318,12 +318,13 @@ DX8IndexBufferClass::DX8IndexBufferClass(unsigned short index_count_,UsageType uusage_flags|=D3DUSAGE_SOFTWAREPROCESSING;}- HRESULT ret=DX8Wrapper::_Get_D3D_Device8()->CreateIndexBuffer(+ HRESULT ret=DX8Wrapper::_Get_D3D_Device()->CreateIndexBuffer(sizeof(WORD)*index_count,usage_flags,D3DFMT_INDEX16,(usage&USAGE_DYNAMIC) ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED,- &index_buffer);+ &index_buffer,+ NULL); // pSharedHandle, D3D9's extra parameter, reserved and always nullif (SUCCEEDED(ret)) {return;@@ -340,12 +341,13 @@ DX8IndexBufferClass::DX8IndexBufferClass(unsigned short index_count_,UsageType uWW3D::_Invalidate_Mesh_Cache();// Try again...- ret=DX8Wrapper::_Get_D3D_Device8()->CreateIndexBuffer(+ ret=DX8Wrapper::_Get_D3D_Device()->CreateIndexBuffer(sizeof(WORD)*index_count,usage_flags,D3DFMT_INDEX16,(usage&USAGE_DYNAMIC) ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED,- &index_buffer);+ &index_buffer,+ NULL); // pSharedHandle, D3D9's extra parameter, reserved and always nullif (SUCCEEDED(ret)) {WWDEBUG_SAY(("...Index buffer creation succesful\n"));@@ -456,7 +458,7 @@ DynamicIBAccessClass::WriteLockClass::WriteLockClass(DynamicIBAccessClass* ib_acstatic_cast<DX8IndexBufferClass*>(DynamicIBAccess->IndexBuffer)->Get_DX8_Index_Buffer()->Lock(DynamicIBAccess->IndexBufferOffset*sizeof(WORD),DynamicIBAccess->Get_Index_Count()*sizeof(WORD),- (unsigned char**)&Indices,+ (void**)&Indices,!DynamicIBAccess->IndexBufferOffset ? D3DLOCK_DISCARD : D3DLOCK_NOOVERWRITE));break;case BUFFER_TYPE_DYNAMIC_SORTING:diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.hindex c018a43d5..572dd8eb1 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.h@@ -50,7 +50,7 @@class DX8Wrapper;class SortingRendererClass;-struct IDirect3DIndexBuffer8;+struct IDirect3DIndexBuffer9;class DX8IndexBufferClass;class SortingIndexBufferClass;@@ -179,7 +179,7 @@ public:void Copy(unsigned int* indices,unsigned start_index,unsigned index_count);void Copy(unsigned short* indices,unsigned start_index,unsigned index_count);- inline IDirect3DIndexBuffer8* Get_DX8_Index_Buffer() { return index_buffer; }+ inline IDirect3DIndexBuffer9* Get_DX8_Index_Buffer() { return index_buffer; }// Plain memory standing in for the D3D buffer when there is no render device. Everything that// fills a buffer does so through the lock classes, and a run with no picture still fills them -@@ -189,7 +189,7 @@ public:inline unsigned short* Get_Scratch_Indices() { return scratch_indices; }private:- IDirect3DIndexBuffer8* index_buffer; // actual dx8 index buffer+ IDirect3DIndexBuffer9* index_buffer; // actual dx8 index bufferunsigned short* scratch_indices; // used instead when there is no device};diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cppindex 85d8e07c4..b4ef6c411 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp@@ -2217,7 +2217,7 @@ void DX8MeshRendererClass::Render_Decal_Meshes(void)DecalMeshClass * decal_mesh = visible_decal_meshes;if (!decal_mesh) return;- DX8Wrapper::Set_DX8_Render_State(D3DRS_ZBIAS,8);+ DX8Wrapper::Set_DX8_ZBias(8);while (decal_mesh != NULL) {decal_mesh->Render();@@ -2225,7 +2225,7 @@ void DX8MeshRendererClass::Render_Decal_Meshes(void)}visible_decal_meshes = NULL;- DX8Wrapper::Set_DX8_Render_State(D3DRS_ZBIAS,0);+ DX8Wrapper::Set_DX8_ZBias(0);}// ----------------------------------------------------------------------------diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cppindex c92a21a06..a14dad509 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp@@ -45,7 +45,7 @@#include "dx8caps.h"#include "thread.h"#include "wwmemlog.h"-#include <D3dx8core.h>+#include "d3dx9runtime.h"#define DEFAULT_VB_SIZE 5000@@ -182,7 +182,7 @@ VertexBufferClass::WriteLockClass::WriteLockClass(VertexBufferClass* VertexBuffeDX8_ErrorCode(static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_DX8_Vertex_Buffer()->Lock(0,0,- (unsigned char**)&Vertices,+ (void**)&Vertices,flags)); //flagsbreak;case BUFFER_TYPE_SORTING:@@ -254,7 +254,7 @@ VertexBufferClass::AppendLockClass::AppendLockClass(VertexBufferClass* VertexBufDX8_ErrorCode(static_cast<DX8VertexBufferClass*>(VertexBuffer)->Get_DX8_Vertex_Buffer()->Lock(start_index*VertexBuffer->FVF_Info().Get_FVF_Size(),index_range*VertexBuffer->FVF_Info().Get_FVF_Size(),- (unsigned char**)&Vertices,+ (void**)&Vertices,0)); // Default (no) flagsbreak;case BUFFER_TYPE_SORTING:@@ -448,7 +448,7 @@ void DX8VertexBufferClass::Create_Vertex_Buffer(UsageType usage)// A run with no render device has nothing to put a vertex buffer on. Hand out a plain heap// block instead: the terrain, the trees and the bridges all fill their buffers while the map// loads, long before anything would be drawn, and they have to write somewhere.- if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ if (DX8Wrapper::_Get_D3D_Device() == NULL) {VertexBuffer=NULL;ScratchVertices=W3DNEWARRAY unsigned char[FVF_Info().Get_FVF_Size()*VertexCount];return;@@ -469,12 +469,13 @@ void DX8VertexBufferClass::Create_Vertex_Buffer(UsageType usage)usage_flags|=D3DUSAGE_SOFTWAREPROCESSING;}- HRESULT ret=DX8Wrapper::_Get_D3D_Device8()->CreateVertexBuffer(+ HRESULT ret=DX8Wrapper::_Get_D3D_Device()->CreateVertexBuffer(FVF_Info().Get_FVF_Size()*VertexCount,usage_flags,FVF_Info().Get_FVF(),(usage&USAGE_DYNAMIC) ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED,- &VertexBuffer);+ &VertexBuffer,+ NULL); // pSharedHandle, D3D9's extra parameter, reserved and always nullif (SUCCEEDED(ret)) {return;}@@ -490,15 +491,18 @@ void DX8VertexBufferClass::Create_Vertex_Buffer(UsageType usage)WW3D::_Invalidate_Mesh_Cache();//@todo: Find some way to invalidate the textures too- ret = DX8Wrapper::_Get_D3D_Device8()->ResourceManagerDiscardBytes(0);+ // D3D9 replaced ResourceManagerDiscardBytes with EvictManagedResources, which takes+ // no byte count and returns nothing useful to act on.+ DX8Wrapper::_Get_D3D_Device()->EvictManagedResources();// Try again...- ret=DX8Wrapper::_Get_D3D_Device8()->CreateVertexBuffer(+ ret=DX8Wrapper::_Get_D3D_Device()->CreateVertexBuffer(FVF_Info().Get_FVF_Size()*VertexCount,usage_flags,FVF_Info().Get_FVF(),(usage&USAGE_DYNAMIC) ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED,- &VertexBuffer);+ &VertexBuffer,+ NULL); // pSharedHandle, D3D9's extra parameter, reserved and always nullif (SUCCEEDED(ret)) {WWDEBUG_SAY(("...Vertex buffer creation succesful\n"));@@ -880,7 +884,7 @@ DynamicVBAccessClass::WriteLockClass::WriteLockClass(DynamicVBAccessClass* dynamDX8_ErrorCode(static_cast<DX8VertexBufferClass*>(DynamicVBAccess->VertexBuffer)->Get_DX8_Vertex_Buffer()->Lock(DynamicVBAccess->VertexBufferOffset*_DynamicDX8VertexBuffer->FVF_Info().Get_FVF_Size(),DynamicVBAccess->Get_Vertex_Count()*DynamicVBAccess->VertexBuffer->FVF_Info().Get_FVF_Size(),- (unsigned char**)&Vertices,+ (void**)&Vertices,D3DLOCK_NOSYSLOCK | (!DynamicVBAccess->VertexBufferOffset ? D3DLOCK_DISCARD : D3DLOCK_NOOVERWRITE)));break;case BUFFER_TYPE_DYNAMIC_SORTING:diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.hindex 156c84b41..19a90c738 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.h@@ -59,7 +59,7 @@ class Vector4;class StringClass;class DX8VertexBufferClass;class FVFInfoClass;-struct IDirect3DVertexBuffer8;+struct IDirect3DVertexBuffer9;class VertexBufferClass;struct VertexFormatXYZNDUV2;@@ -223,7 +223,7 @@ public:DX8VertexBufferClass(const Vector3* vertices, const Vector4* diffuse, const Vector2* tex_coords, unsigned short VertexCount,UsageType usage=USAGE_DEFAULT);DX8VertexBufferClass(const Vector3* vertices, const Vector2* tex_coords, unsigned short VertexCount,UsageType usage=USAGE_DEFAULT);- IDirect3DVertexBuffer8* Get_DX8_Vertex_Buffer() { return VertexBuffer; }+ IDirect3DVertexBuffer9* Get_DX8_Vertex_Buffer() { return VertexBuffer; }// Plain memory standing in for the D3D buffer when there is no render device - see// DX8IndexBufferClass::Get_Scratch_Indices for why a run with no picture still fills buffers.@@ -237,7 +237,7 @@ public:void Copy(const Vector3* loc, const Vector2* uv, const Vector4* diffuse, unsigned first_vertex, unsigned count);protected:- IDirect3DVertexBuffer8* VertexBuffer;+ IDirect3DVertexBuffer9* VertexBuffer;unsigned char* ScratchVertices; // used instead when there is no devicevoid Create_Vertex_Buffer(UsageType usage);diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8webbrowser.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8webbrowser.cppindex 9e6687b7f..dbc2f2d36 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8webbrowser.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8webbrowser.cpp@@ -79,7 +79,7 @@ bool DX8WebBrowser::Initialize( const char* badpageurl,if(hr == S_OK){hWnd = (HWND)WW3D::Get_Window();- pBrowser->Initialize(reinterpret_cast<long*>(DX8Wrapper::_Get_D3D_Device8()));+ pBrowser->Initialize(reinterpret_cast<long*>(DX8Wrapper::_Get_D3D_Device()));if(badpageurl)pBrowser->put_BadPageURL(_bstr_t(badpageurl));diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8webbrowser.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8webbrowser.hindex 6134daa64..6a0bfa76a 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8webbrowser.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8webbrowser.h@@ -34,7 +34,7 @@#define DX8_WEBBROWSER_H#include <windows.h>-#include "d3d8.h"+#include <d3d9.h>// ***********************************// Set this to 0 to remove all embedded browser code.@@ -50,7 +50,7 @@#define BROWSEROPTION_SCROLLBARS 0x0001#define BROWSEROPTION_3DBORDER 0x0002-struct IDirect3DDevice8;+struct IDirect3DDevice9;/**** DX8WebBrowserdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cppindex 3aa184aa3..2737d3e8f 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp@@ -71,7 +71,7 @@#include "missingtexture.h"#include "thread.h"#include <stdio.h>-#include <D3dx8core.h>+#include "d3dx9runtime.h"#include "pot.h"#include "wwprofile.h"#include "ffactory.h"@@ -116,8 +116,9 @@ D3DMATRIX DX8Wrapper::old_view;D3DMATRIX DX8Wrapper::old_prj;// shader system additions KJM v-DWORD DX8Wrapper::Vertex_Shader = 0;-DWORD DX8Wrapper::Pixel_Shader = 0;+DWORD DX8Wrapper::Vertex_Format = 0;+IDirect3DVertexShader9 * DX8Wrapper::Vertex_Shader = NULL;+IDirect3DPixelShader9 * DX8Wrapper::Pixel_Shader = NULL;Vector4 DX8Wrapper::Vertex_Shader_Constants[MAX_VERTEX_SHADER_CONSTANTS];Vector4 DX8Wrapper::Pixel_Shader_Constants[MAX_PIXEL_SHADER_CONSTANTS];@@ -134,19 +135,131 @@ Vector3 DX8Wrapper::Ambient_Color;bool DX8Wrapper::world_identity;unsigned DX8Wrapper::RenderStates[256];unsigned DX8Wrapper::TextureStageStates[MAX_TEXTURE_STAGES][32];-IDirect3DBaseTexture8 * DX8Wrapper::Textures[MAX_TEXTURE_STAGES];+unsigned DX8Wrapper::SamplerStates[MAX_TEXTURE_STAGES][MAX_SAMPLER_STATES];+float DX8Wrapper::DepthBufferEpsilon=0.0f;++// One depth-buffer level, negative, in the normalised range D3DRS_DEPTHBIAS reads. The+// 24 and 32 bit cases deliberately shift by 20 rather than by their own width: a float+// cannot hold 1/(2^24 - 1) accurately enough for the bias to come out where D3D8's+// integer ZBIAS put it. This is d3d8to9's CalcDepthBias, which is what has been running+// under this renderer since the port (d3d8types.cpp).+float DX8Wrapper::_Depth_Buffer_Epsilon(D3DFORMAT depth_stencil_format)+{+ const int USABLE_FLOAT_DEPTH_BITS=20;+ const int SHORT_DEPTH_BITS=16;+ const int PACKED_DEPTH_BITS=15;++ switch (depth_stencil_format) {+ case D3DFMT_D32:+ case D3DFMT_D24X4S4:+ case D3DFMT_D24S8:+ case D3DFMT_D24X8:+ return -1.0f/((1<<USABLE_FLOAT_DEPTH_BITS)-1);+ case D3DFMT_D15S1:+ return -1.0f/((1<<PACKED_DEPTH_BITS)-1);+ default:+ return -1.0f/((1<<SHORT_DEPTH_BITS)-1);+ }+}++void DX8Wrapper::_Set_DX8_Render_Target(IDirect3DSurface9 * render_target, IDirect3DSurface9 * depth_buffer)+{+ DX8CALL(SetRenderTarget(PRIMARY_RENDER_TARGET,render_target));+ DX8CALL(SetDepthStencilSurface(depth_buffer));+}++// D3D9 has no CopyRects. Which call replaces it depends on where the two surfaces live,+// so this asks them: a default-pool pair stretches, a system-memory source updates, and+// anything else goes through D3DX, which is the only one of the three that can cross a+// managed pool. The branch order is d3d8to9's (d3d8to9_device.cpp:447), because that is+// the routing the game's own copies have been taking.+void DX8Wrapper::_Copy_DX8_Rects(+ IDirect3DSurface9* pSourceSurface,+ CONST RECT* pSourceRectsArray,+ UINT cRects,+ IDirect3DSurface9* pDestinationSurface,+ CONST POINT* pDestPointsArray)+{+ if (pSourceSurface==NULL || pDestinationSurface==NULL || pSourceSurface==pDestinationSurface) {+ WWASSERT(0);+ return;+ }++ D3DSURFACE_DESC source_desc;+ D3DSURFACE_DESC destination_desc;+ if (FAILED(pSourceSurface->GetDesc(&source_desc))+ || FAILED(pDestinationSurface->GetDesc(&destination_desc))) {+ WWASSERT(0);+ return;+ }++ const UINT rect_count=cRects==0 ? 1 : cRects;+ for (UINT rect_index=0; rect_index<rect_count; ++rect_index) {+ RECT source_rect;+ if (pSourceRectsArray!=NULL) {+ source_rect=pSourceRectsArray[rect_index];+ }+ else {+ source_rect.left=0;+ source_rect.top=0;+ source_rect.right=source_desc.Width;+ source_rect.bottom=source_desc.Height;+ }++ RECT destination_rect;+ if (pDestPointsArray!=NULL) {+ destination_rect.left=pDestPointsArray[rect_index].x;+ destination_rect.top=pDestPointsArray[rect_index].y;+ destination_rect.right=destination_rect.left+(source_rect.right-source_rect.left);+ destination_rect.bottom=destination_rect.top+(source_rect.bottom-source_rect.top);+ }+ else {+ destination_rect=source_rect;+ }++ HRESULT hr;+ if (source_desc.Pool==D3DPOOL_MANAGED || destination_desc.Pool!=D3DPOOL_DEFAULT) {+ hr=D3DXLoadSurfaceFromSurface(pDestinationSurface,NULL,&destination_rect,+ pSourceSurface,NULL,&source_rect,D3DX_FILTER_NONE,0);+ if (SUCCEEDED(hr)) {+ // A surface written this way does not tell the texture that owns it, and+ // a managed texture that is never marked dirty is never uploaded again.+ IDirect3DTexture9* container=NULL;+ if (SUCCEEDED(pDestinationSurface->GetContainer(IID_IDirect3DTexture9,(void**)&container))+ && container!=NULL) {+ container->AddDirtyRect(&destination_rect);+ container->Release();+ }+ }+ }+ else if (source_desc.Pool==D3DPOOL_SYSTEMMEM) {+ const POINT destination_point={destination_rect.left,destination_rect.top};+ hr=D3DDevice->UpdateSurface(pSourceSurface,&source_rect,pDestinationSurface,&destination_point);+ }+ else {+ hr=D3DDevice->StretchRect(pSourceSurface,&source_rect,+ pDestinationSurface,&destination_rect,D3DTEXF_NONE);+ }++ if (FAILED(hr)) {+ Non_Fatal_Log_DX8_ErrorCode(hr,__FILE__,__LINE__);+ return;+ }+ }+}+IDirect3DBaseTexture9 * DX8Wrapper::Textures[MAX_TEXTURE_STAGES];RenderStateStruct DX8Wrapper::render_state;unsigned DX8Wrapper::render_state_changed;bool DX8Wrapper::FogEnable = false;D3DCOLOR DX8Wrapper::FogColor = 0;-IDirect3D8 * DX8Wrapper::D3DInterface = NULL;-IDirect3DDevice8 * DX8Wrapper::D3DDevice = NULL;-IDirect3DSurface8 * DX8Wrapper::CurrentRenderTarget = NULL;-IDirect3DSurface8 * DX8Wrapper::CurrentDepthBuffer = NULL;-IDirect3DSurface8 * DX8Wrapper::DefaultRenderTarget = NULL;-IDirect3DSurface8 * DX8Wrapper::DefaultDepthBuffer = NULL;+IDirect3D9 * DX8Wrapper::D3DInterface = NULL;+IDirect3DDevice9 * DX8Wrapper::D3DDevice = NULL;+IDirect3DSurface9 * DX8Wrapper::CurrentRenderTarget = NULL;+IDirect3DSurface9 * DX8Wrapper::CurrentDepthBuffer = NULL;+IDirect3DSurface9 * DX8Wrapper::DefaultRenderTarget = NULL;+IDirect3DSurface9 * DX8Wrapper::DefaultDepthBuffer = NULL;bool DX8Wrapper::IsRenderToTexture = false;unsigned DX8Wrapper::matrix_changes = 0;@@ -172,7 +285,7 @@ DX8Caps* DX8Wrapper::CurrentCaps = 0;// Hack test... this disables rendering of batches of too few polygons.unsigned DX8Wrapper::DrawPolygonLowBoundLimit=0;-D3DADAPTER_IDENTIFIER8 DX8Wrapper::CurrentAdapterIdentifier;+D3DADAPTER_IDENTIFIER9 DX8Wrapper::CurrentAdapterIdentifier;unsigned long DX8Wrapper::FrameCount = 0;@@ -214,14 +327,14 @@ void DX8Wrapper::Set_Requested_MultiSample_Level(unsigned samples)// into need a non-multisampled one of their own. (The retail runtime does not reject the// mismatch at bind time; the debug runtime and the docs do. dx8_smoke_msaa records both.)// NULL means "not multisampling, keep the depth buffer you already have".-static IDirect3DSurface8 * _RTTDepthBuffer = NULL;+static IDirect3DSurface9 * _RTTDepthBuffer = NULL;static DynamicVectorClass<StringClass> _RenderDeviceNameTable;static DynamicVectorClass<StringClass> _RenderDeviceShortNameTable;static DynamicVectorClass<RenderDeviceDescClass> _RenderDeviceDescriptionTable;-typedef IDirect3D8* (WINAPI *Direct3DCreate8Type) (UINT SDKVersion);+typedef IDirect3D9* (WINAPI *Direct3DCreate8Type) (UINT SDKVersion);Direct3DCreate8Type Direct3DCreate8Ptr = NULL;HINSTANCE D3D8Lib = NULL;@@ -235,34 +348,17 @@ DX8_Stats DX8Wrapper::stats;*************************************************************************************/+// D3DX9 dropped D3DXGetErrorStringA, which used to fill a caller's buffer and could+// fail; Get_D3D_Error_String names the code itself and always returns something.void Log_DX8_ErrorCode(unsigned res){- char tmp[256]="";-- HRESULT new_res=D3DXGetErrorStringA(- res,- tmp,- sizeof(tmp));-- if (new_res==D3D_OK) {- WWDEBUG_SAY((tmp));- }-+ WWDEBUG_SAY((Get_D3D_Error_String(res)));WWASSERT(0);}void Non_Fatal_Log_DX8_ErrorCode(unsigned res,const char * file,int line){- char tmp[256]="";-- HRESULT new_res=D3DXGetErrorStringA(- res,- tmp,- sizeof(tmp));-- if (new_res==D3D_OK) {- WWDEBUG_SAY(("DX8 Error: %s, File: %s, Line: %d\n",tmp,file,line));- }+ WWDEBUG_SAY(("DX8 Error: %s, File: %s, Line: %d\n",Get_D3D_Error_String(res),file,line));}@@ -272,14 +368,23 @@ bool DX8Wrapper::Init(void * hwnd, bool lite)WWASSERT(!IsInitted);// zero memory- memset(Textures,0,sizeof(IDirect3DBaseTexture8*)*MAX_TEXTURE_STAGES);+ memset(Textures,0,sizeof(IDirect3DBaseTexture9*)*MAX_TEXTURE_STAGES);memset(RenderStates,0,sizeof(unsigned)*256);memset(TextureStageStates,0,sizeof(unsigned)*32*MAX_TEXTURE_STAGES);+ memset(SamplerStates,0,sizeof(SamplerStates));memset(Vertex_Shader_Constants,0,sizeof(Vector4)*MAX_VERTEX_SHADER_CONSTANTS);memset(Pixel_Shader_Constants,0,sizeof(Vector4)*MAX_PIXEL_SHADER_CONSTANTS);memset(&render_state,0,sizeof(RenderStateStruct));memset(Shadow_Map,0,sizeof(ZTextureClass*)*MAX_SHADOW_MAPS);+ // D3DX9 has no import library and is bound by hand, so this has to happen before+ // anything reaches a D3DX entry point. A machine without d3dx9_43.dll gets a+ // renderer with no texture loading and no shaders rather than a null call, which is+ // why the failure is logged here and not left for the first caller to trip over.+ if (!Bind_D3DX9_Runtime()) {+ WWDEBUG_SAY(("DX8Wrapper: d3dx9_43.dll did not bind; textures and shaders will not load\n"));+ }+/*** Initialize all variables!*/@@ -349,7 +454,7 @@ void DX8Wrapper::Shutdown(void){if (D3DDevice) {- Set_Render_Target ((IDirect3DSurface8 *)NULL);+ Set_Render_Target ((IDirect3DSurface9 *)NULL);Release_Device();}@@ -359,6 +464,8 @@ void DX8Wrapper::Shutdown(void)}+ Unbind_D3DX9_Runtime();+if (CurrentCaps){int max=CurrentCaps->Get_Max_Textures_Per_Pass();@@ -437,14 +544,14 @@ inline DWORD F2DW(float f) { return *((unsigned*)&f); }void DX8Wrapper::Set_Default_Global_Render_States(void){DX8_THREAD_ASSERT();- const D3DCAPS8 &caps = Get_Current_Caps()->Get_DX8_Caps();+ const D3DCAPS9 &caps = Get_Current_Caps()->Get_DX8_Caps();Set_DX8_Render_State(D3DRS_RANGEFOGENABLE, (caps.RasterCaps & D3DPRASTERCAPS_FOGRANGE) ? TRUE : FALSE);Set_DX8_Render_State(D3DRS_FOGTABLEMODE, D3DFOG_NONE);Set_DX8_Render_State(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);Set_DX8_Render_State(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);Set_DX8_Render_State(D3DRS_COLORVERTEX, TRUE);- Set_DX8_Render_State(D3DRS_ZBIAS,0);+ Set_DX8_ZBias(0);Set_DX8_Texture_Stage_State(1, D3DTSS_BUMPENVLSCALE, F2DW(1.0f));Set_DX8_Texture_Stage_State(1, D3DTSS_BUMPENVLOFFSET, F2DW(0.0f));Set_DX8_Texture_Stage_State(0, D3DTSS_BUMPENVMAT00,F2DW(1.0f));@@ -461,7 +568,7 @@ bool DX8Wrapper::Validate_Device(void){ DWORD numPasses=0;HRESULT hRes;- hRes=_Get_D3D_Device8()->ValidateDevice(&numPasses);+ hRes=_Get_D3D_Device()->ValidateDevice(&numPasses);return (hRes == D3D_OK);}@@ -482,8 +589,8 @@ void DX8Wrapper::Invalidate_Cached_Render_States(void)}//Need to explicitly set texture to NULL, otherwise app will not be able to//set it to null because of redundant state checker. MW- if (_Get_D3D_Device8())- _Get_D3D_Device8()->SetTexture(a,NULL);+ if (_Get_D3D_Device())+ _Get_D3D_Device()->SetTexture(a,NULL);if (Textures[a] != NULL) {Textures[a]->Release();}@@ -545,7 +652,7 @@ bool DX8Wrapper::Create_Device(void){WWASSERT(D3DDevice==NULL); // for now, once you've created a device, you're stuck with it!- D3DCAPS8 caps;+ D3DCAPS9 caps;if(FAILED@@ -562,7 +669,7 @@ bool DX8Wrapper::Create_Device(void)return false;}- ::ZeroMemory(&CurrentAdapterIdentifier, sizeof(D3DADAPTER_IDENTIFIER8));+ ::ZeroMemory(&CurrentAdapterIdentifier, sizeof(D3DADAPTER_IDENTIFIER9));if(@@ -571,7 +678,7 @@ bool DX8Wrapper::Create_Device(void)D3DInterface->GetAdapterIdentifier(CurRenderDevice,- D3DENUM_NO_WHQL_LEVEL,+ NO_ADAPTER_IDENTIFIER_FLAGS,&CurrentAdapterIdentifier))@@ -647,12 +754,14 @@ bool DX8Wrapper::Create_Device(void)return false;}}- else+ else{return false;}}+ DepthBufferEpsilon=_Depth_Buffer_Epsilon(_PresentParameters.AutoDepthStencilFormat);+/*** Initialize all subsystems*/@@ -690,7 +799,7 @@ bool DX8Wrapper::Reset_Device(bool reload_assets)memset(Vertex_Shader_Constants,0,sizeof(Vector4)*MAX_VERTEX_SHADER_CONSTANTS);memset(Pixel_Shader_Constants,0,sizeof(Vector4)*MAX_PIXEL_SHADER_CONSTANTS);- HRESULT hr=_Get_D3D_Device8()->TestCooperativeLevel();+ HRESULT hr=_Get_D3D_Device()->TestCooperativeLevel();if (hr != D3DERR_DEVICELOST ){ DX8CALL_HRES(Reset(&_PresentParameters),hr)if (hr != D3D_OK)@@ -727,8 +836,8 @@ void DX8Wrapper::Release_Device(void)DX8CALL(SetTexture(a,NULL));}- DX8CALL(SetStreamSource(0, NULL, 0)); //release reference count on last rendered vertex buffer- DX8CALL(SetIndices(NULL,0)); //release reference count on last rendered index buffer+ DX8CALL(SetStreamSource(0, NULL, 0, 0)); //release reference count on last rendered vertex buffer+ DX8CALL(SetIndices(NULL)); //release reference count on last rendered index buffer/*@@ -763,9 +872,9 @@ void DX8Wrapper::Enumerate_Devices()int adapter_count = D3DInterface->GetAdapterCount();for (int adapter_index=0; adapter_index<adapter_count; adapter_index++) {- D3DADAPTER_IDENTIFIER8 id;- ::ZeroMemory(&id, sizeof(D3DADAPTER_IDENTIFIER8));- HRESULT res = D3DInterface->GetAdapterIdentifier(adapter_index,D3DENUM_NO_WHQL_LEVEL,&id);+ D3DADAPTER_IDENTIFIER9 id;+ ::ZeroMemory(&id, sizeof(D3DADAPTER_IDENTIFIER9));+ HRESULT res = D3DInterface->GetAdapterIdentifier(adapter_index,NO_ADAPTER_IDENTIFIER_FLAGS,&id);if (res == D3D_OK) {@@ -787,7 +896,7 @@ void DX8Wrapper::Enumerate_Devices()desc.set_driver_version(buf);D3DInterface->GetDeviceCaps(adapter_index,WW3D_DEVTYPE,&desc.Caps);- D3DInterface->GetAdapterIdentifier(adapter_index,D3DENUM_NO_WHQL_LEVEL,&desc.AdapterIdentifier);+ D3DInterface->GetAdapterIdentifier(adapter_index,NO_ADAPTER_IDENTIFIER_FLAGS,&desc.AdapterIdentifier);DX8Caps dx8caps(D3DInterface,desc.Caps,WW3D_FORMAT_UNKNOWN,desc.AdapterIdentifier);@@ -795,36 +904,35 @@ void DX8Wrapper::Enumerate_Devices()** Enumerate the resolutions*/desc.reset_resolution_list();- int mode_count = D3DInterface->GetAdapterModeCount(adapter_index);- for (int mode_index=0; mode_index<mode_count; mode_index++) {- D3DDISPLAYMODE d3dmode;- ::ZeroMemory(&d3dmode, sizeof(D3DDISPLAYMODE));- HRESULT res = D3DInterface->EnumAdapterModes(adapter_index,mode_index,&d3dmode);-- if (res == D3D_OK) {- int bits = 0;- switch (d3dmode.Format)- {- case D3DFMT_R8G8B8:- case D3DFMT_A8R8G8B8:- case D3DFMT_X8R8G8B8: bits = 32; break;-- case D3DFMT_R5G6B5:- case D3DFMT_X1R5G5B5: bits = 16; break;- }+ // D3D8 enumerated every display mode of an adapter in one list and left the+ // caller to read the format off each one. D3D9 enumerates per format, so the+ // formats the switch below used to recognise are the loop now, and the bit+ // depth comes from the format asked for rather than the mode returned.+ static const struct { D3DFORMAT Format; int Bits; } DISPLAY_FORMATS[] =+ {+ { D3DFMT_X8R8G8B8, 32 },+ { D3DFMT_A8R8G8B8, 32 },+ { D3DFMT_R8G8B8, 32 },+ { D3DFMT_R5G6B5, 16 },+ { D3DFMT_X1R5G5B5, 16 }+ };+ const int DISPLAY_FORMAT_COUNT = sizeof(DISPLAY_FORMATS)/sizeof(DISPLAY_FORMATS[0]);++ for (int format_index=0; format_index<DISPLAY_FORMAT_COUNT; format_index++) {+ const D3DFORMAT display_format = DISPLAY_FORMATS[format_index].Format;+ int mode_count = D3DInterface->GetAdapterModeCount(adapter_index,display_format);+ for (int mode_index=0; mode_index<mode_count; mode_index++) {+ D3DDISPLAYMODE d3dmode;+ ::ZeroMemory(&d3dmode, sizeof(D3DDISPLAYMODE));+ HRESULT res = D3DInterface->EnumAdapterModes(adapter_index,display_format,mode_index,&d3dmode);+ if (res != D3D_OK) continue;// Some cards fail in certain modes, DX8Caps keeps list of those.if (!dx8caps.Is_Valid_Display_Format(d3dmode.Width,d3dmode.Height,D3DFormat_To_WW3DFormat(d3dmode.Format))) {- bits=0;+ continue;}- /*- ** If we recognize the format, add it to the list- ** TODO: should we handle more formats? will any cards report more than 24 or 16 bit?- */- if (bits != 0) {- desc.add_resolution(d3dmode.Width,d3dmode.Height,bits);- }+ desc.add_resolution(d3dmode.Width,d3dmode.Height,DISPLAY_FORMATS[format_index].Bits);}}@@ -915,7 +1023,6 @@ void DX8Wrapper::Get_Format_Name(unsigned int format, StringClass *tex_format)case D3DFMT_X8L8V8U8: *tex_format="D3DFMT_X8L8V8U8"; break;case D3DFMT_Q8W8V8U8: *tex_format="D3DFMT_Q8W8V8U8"; break;case D3DFMT_V16U16: *tex_format="D3DFMT_V16U16"; break;- case D3DFMT_W11V11U10: *tex_format="D3DFMT_W11V11U10"; break;case D3DFMT_UYVY: *tex_format="D3DFMT_UYVY"; break;case D3DFMT_YUY2: *tex_format="D3DFMT_YUY2"; break;case D3DFMT_DXT1: *tex_format="D3DFMT_DXT1"; break;@@ -1035,7 +1142,7 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int// as soon as the frame is ready. (Windowed presents are unaffected: this field only applies// fullscreen, and the desktop compositor paces a windowed present regardless.)//- _PresentParameters.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;+ _PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;_PresentParameters.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;/*@@ -1121,9 +1228,9 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, intfor (unsigned samples = wanted; samples >= 2; --samples) {D3DMULTISAMPLE_TYPE type = (D3DMULTISAMPLE_TYPE)samples;if (FAILED(D3DInterface->CheckDeviceMultiSampleType(CurRenderDevice,D3DDEVTYPE_HAL,- _PresentParameters.BackBufferFormat,_PresentParameters.Windowed,type))) continue;+ _PresentParameters.BackBufferFormat,_PresentParameters.Windowed,type,NULL))) continue;if (FAILED(D3DInterface->CheckDeviceMultiSampleType(CurRenderDevice,D3DDEVTYPE_HAL,- _PresentParameters.AutoDepthStencilFormat,_PresentParameters.Windowed,type))) continue;+ _PresentParameters.AutoDepthStencilFormat,_PresentParameters.Windowed,type,NULL))) continue;_PresentParameters.MultiSampleType = type;break;}@@ -1209,11 +1316,11 @@ bool DX8Wrapper::Toggle_Windowed(void)void DX8Wrapper::Set_Swap_Interval(int swap){switch (swap) {- case 0: _PresentParameters.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; break;- case 1: _PresentParameters.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE ; break;- case 2: _PresentParameters.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_TWO; break;- case 3: _PresentParameters.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_THREE; break;- default: _PresentParameters.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE ; break;+ case 0: _PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; break;+ case 1: _PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_ONE ; break;+ case 2: _PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_TWO; break;+ case 3: _PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_THREE; break;+ default: _PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_ONE ; break;}Reset_Device();@@ -1221,7 +1328,7 @@ void DX8Wrapper::Set_Swap_Interval(int swap)int DX8Wrapper::Get_Swap_Interval(void){- return _PresentParameters.FullScreen_PresentationInterval;+ return _PresentParameters.PresentationInterval;}bool DX8Wrapper::Has_Stencil(void)@@ -1574,13 +1681,13 @@ bool DX8Wrapper::Find_Color_Mode(D3DFORMAT colorbuffer, int resx, int resy, UINTbool found=false;- modemax=D3DInterface->GetAdapterModeCount(D3DADAPTER_DEFAULT);+ modemax=D3DInterface->GetAdapterModeCount(D3DADAPTER_DEFAULT,colorbuffer);i=0;while (i<modemax && !found){- D3DInterface->EnumAdapterModes(D3DADAPTER_DEFAULT, i, &dmode);+ D3DInterface->EnumAdapterModes(D3DADAPTER_DEFAULT, colorbuffer, i, &dmode);if (dmode.Width==rx && dmode.Height==ry && dmode.Format==colorbuffer) {WWDEBUG_SAY(("Found valid color mode. Width = %d Height = %d Format = %d\r\n",dmode.Width,dmode.Height,dmode.Format));found=true;@@ -1602,7 +1709,7 @@ bool DX8Wrapper::Find_Color_Mode(D3DFORMAT colorbuffer, int resx, int resy, UINTj=i;while (j<modemax && stillok){- D3DInterface->EnumAdapterModes(D3DADAPTER_DEFAULT, j, &dmode);+ D3DInterface->EnumAdapterModes(D3DADAPTER_DEFAULT, colorbuffer, j, &dmode);if (dmode.Width==rx && dmode.Height==ry && dmode.Format==colorbuffer)stillok=true; else stillok=false;j++;@@ -1754,7 +1861,7 @@ unsigned long DX8Wrapper::Get_FrameCount(void) {return FrameCount;}void DX8_Assert(){- WWASSERT(DX8Wrapper::_Get_D3D8());+ WWASSERT(DX8Wrapper::_Get_D3D());DX8_THREAD_ASSERT();}@@ -1783,7 +1890,7 @@ void DX8Wrapper::End_Scene(bool flip_frames)HRESULT hr;{WWPROFILE("DX8Device::Present()");- hr=_Get_D3D_Device8()->Present(NULL, NULL, NULL, NULL);+ hr=_Get_D3D_Device()->Present(NULL, NULL, NULL, NULL);}number_of_DX8_calls++;@@ -1803,7 +1910,7 @@ void DX8Wrapper::End_Scene(bool flip_frames)// If the device was lost we need to check for cooperative level and possibly reset the deviceif (hr==D3DERR_DEVICELOST) {- hr=_Get_D3D_Device8()->TestCooperativeLevel();+ hr=_Get_D3D_Device()->TestCooperativeLevel();if (hr==D3DERR_DEVICENOTRESET) {Reset_Device();}@@ -1839,7 +1946,7 @@ void DX8Wrapper::Flip_To_Primary(void)int resetAttempts = 0;while ((flipCount > 0) && (resetAttempts < 3)) {- HRESULT hr = _Get_D3D_Device8()->TestCooperativeLevel();+ HRESULT hr = _Get_D3D_Device()->TestCooperativeLevel();if (FAILED(hr)) {WWDEBUG_SAY(("TestCooperativeLevel Failed!\n"));@@ -1858,7 +1965,7 @@ void DX8Wrapper::Flip_To_Primary(void)}} else {WWDEBUG_SAY(("Flipping: %ld\n", FrameCount));- hr = _Get_D3D_Device8()->Present(NULL, NULL, NULL, NULL);+ hr = _Get_D3D_Device()->Present(NULL, NULL, NULL, NULL);if (SUCCEEDED(hr)) {IsDeviceLost=false;@@ -1893,9 +2000,9 @@ void DX8Wrapper::Clear(bool clear_color, bool clear_z_stencil, const Vector3 &cobool has_stencil=false;// GetDepthStencilSurface leaves this alone when it fails - a lost device is how - and the test// below then reads whatever was on the stack and calls GetDesc through it.- IDirect3DSurface8* depthbuffer = NULL;+ IDirect3DSurface9* depthbuffer = NULL;- _Get_D3D_Device8()->GetDepthStencilSurface(&depthbuffer);+ _Get_D3D_Device()->GetDepthStencilSurface(&depthbuffer);number_of_DX8_calls++;if (depthbuffer)@@ -1923,7 +2030,7 @@ void DX8Wrapper::Clear(bool clear_color, bool clear_z_stencil, const Vector3 &co}}-void DX8Wrapper::Set_Viewport(CONST D3DVIEWPORT8* pViewport)+void DX8Wrapper::Set_Viewport(CONST D3DVIEWPORT9* pViewport){DX8_THREAD_ASSERT();DX8CALL(SetViewport(pViewport));@@ -2060,11 +2167,12 @@ void DX8Wrapper::Draw_Sorting_IB_VB(DX8CALL(SetStreamSource(0,static_cast<DX8VertexBufferClass*>(dyn_vb_access.VertexBuffer)->Get_DX8_Vertex_Buffer(),+ 0, // OffsetInBytes, D3D9's extra parameter; the offset is carried in the draw calldyn_vb_access.FVF_Info().Get_FVF_Size()));// If using FVF format VB, set the FVF as vertex shader (may not be needed here KM)unsigned fvf=dyn_vb_access.FVF_Info().Get_FVF();if (fvf!=0) {- DX8CALL(SetVertexShader(fvf));+ DX8CALL(SetFVF(fvf));}DX8_RECORD_VERTEX_BUFFER_CHANGE();@@ -2098,14 +2206,16 @@ void DX8Wrapper::Draw_Sorting_IB_VB(}}+ // D3D8 handed SetIndices the base vertex index; D3D9 takes it on the draw call+ // instead, so it travels with the DrawIndexedPrimitive below.DX8CALL(SetIndices(- static_cast<DX8IndexBufferClass*>(dyn_ib_access.IndexBuffer)->Get_DX8_Index_Buffer(),- dyn_vb_access.VertexBufferOffset));+ static_cast<DX8IndexBufferClass*>(dyn_ib_access.IndexBuffer)->Get_DX8_Index_Buffer()));DX8_RECORD_INDEX_BUFFER_CHANGE();DX8_RECORD_DRAW_CALLS();DX8CALL(DrawIndexedPrimitive(D3DPT_TRIANGLELIST,+ dyn_vb_access.VertexBufferOffset, // base vertex index, was SetIndices' second argument0, // start vertexvertex_count,dyn_ib_access.IndexBufferOffset,@@ -2220,6 +2330,7 @@ void DX8Wrapper::Draw(DX8_RECORD_DRAW_CALLS();DX8CALL(DrawIndexedPrimitive((D3DPRIMITIVETYPE)primitive_type,+ render_state.index_base_offset+render_state.vba_offset, // base vertex index, was SetIndices' second argumentmin_vertex_index,vertex_count,start_index+render_state.iba_offset,@@ -2363,7 +2474,7 @@ void DX8Wrapper::Apply_Render_State_Changes()if (render_state.LightEnable[index]) {#ifdef MESH_RENDER_SNAPSHOT_ENABLEDif ( WW3D::Is_Snapshot_Activated() ) {- D3DLIGHT8 * light = &(render_state.Lights[index]);+ D3DLIGHT9 * light = &(render_state.Lights[index]);static char * _light_types[] = { "Unknown", "Point","Spot", "Directional" };WWASSERT((light->Type >= 0) && (light->Type <= 3));@@ -2406,13 +2517,14 @@ void DX8Wrapper::Apply_Render_State_Changes()DX8CALL(SetStreamSource(i,static_cast<DX8VertexBufferClass*>(render_state.vertex_buffers[i])->Get_DX8_Vertex_Buffer(),+ 0, // OffsetInBytes, D3D9's extra parameterrender_state.vertex_buffers[i]->FVF_Info().Get_FVF_Size()));DX8_RECORD_VERTEX_BUFFER_CHANGE();{// If the VB format is FVF, set the FVF as a vertex shaderunsigned fvf=render_state.vertex_buffers[i]->FVF_Info().Get_FVF();if (fvf!=0) {- Set_Vertex_Shader(fvf);+ Set_Vertex_Format(fvf);}}break;@@ -2423,7 +2535,7 @@ void DX8Wrapper::Apply_Render_State_Changes()WWASSERT(0);}} else {- DX8CALL(SetStreamSource(i,NULL,0));+ DX8CALL(SetStreamSource(i,NULL,0,0));DX8_RECORD_VERTEX_BUFFER_CHANGE();}}@@ -2434,9 +2546,9 @@ void DX8Wrapper::Apply_Render_State_Changes()switch (render_state.index_buffer_type) {//->Type()) {case BUFFER_TYPE_DX8:case BUFFER_TYPE_DYNAMIC_DX8:+ // The base vertex index that used to travel here now goes on the draw call.DX8CALL(SetIndices(- static_cast<DX8IndexBufferClass*>(render_state.index_buffer)->Get_DX8_Index_Buffer(),- render_state.index_base_offset+render_state.vba_offset));+ static_cast<DX8IndexBufferClass*>(render_state.index_buffer)->Get_DX8_Index_Buffer()));DX8_RECORD_INDEX_BUFFER_CHANGE();break;case BUFFER_TYPE_SORTING:@@ -2447,9 +2559,7 @@ void DX8Wrapper::Apply_Render_State_Changes()}}else {- DX8CALL(SetIndices(- NULL,- 0));+ DX8CALL(SetIndices(NULL));DX8_RECORD_INDEX_BUFFER_CHANGE();}}@@ -2459,7 +2569,7 @@ void DX8Wrapper::Apply_Render_State_Changes()SNAPSHOT_SAY(("DX8Wrapper::Apply_Render_State_Changes() - finished\n"));}-IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture+IDirect3DTexture9 * DX8Wrapper::_Create_DX8_Texture(unsigned int width,unsigned int height,@@ -2471,7 +2581,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture{DX8_THREAD_ASSERT();DX8_Assert();- IDirect3DTexture8 *texture = NULL;+ IDirect3DTexture9 *texture = NULL;// Paletted textures not supported!WWASSERT(format!=D3DFMT_P8);@@ -2483,7 +2593,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture// which case we return NULL.if (rendertarget) {unsigned ret=D3DXCreateTexture(- DX8Wrapper::_Get_D3D_Device8(),+ DX8Wrapper::_Get_D3D_Device(),width,height,mip_level_count,@@ -2507,7 +2617,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_TextureWW3D::_Invalidate_Mesh_Cache();ret=D3DXCreateTexture(- DX8Wrapper::_Get_D3D_Device8(),+ DX8Wrapper::_Get_D3D_Device(),width,height,mip_level_count,@@ -2538,7 +2648,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture// However, it seems to happen sometimes when there are a lot of textures in memory and so// if it happens we'll release assets and try again (anything is better than crashing).unsigned ret=D3DXCreateTexture(- DX8Wrapper::_Get_D3D_Device8(),+ DX8Wrapper::_Get_D3D_Device(),width,height,mip_level_count,@@ -2557,7 +2667,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_TextureWW3D::_Invalidate_Mesh_Cache();ret=D3DXCreateTexture(- DX8Wrapper::_Get_D3D_Device8(),+ DX8Wrapper::_Get_D3D_Device(),width,height,mip_level_count,@@ -2580,7 +2690,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texturereturn texture;}-IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture+IDirect3DTexture9 * DX8Wrapper::_Create_DX8_Texture(const char *filename,MipCountType mip_level_count@@ -2588,7 +2698,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture{DX8_THREAD_ASSERT();DX8_Assert();- IDirect3DTexture8 *texture = NULL;+ IDirect3DTexture9 *texture = NULL;// NOTE: If the original image format is not supported as a texture format, it will// automatically be converted to an appropriate format.@@ -2596,7 +2706,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture// function as well, so if we later want to second-guess D3DX's format conversion decisions// we can do so after this function is called..unsigned result = D3DXCreateTextureFromFileExA(- _Get_D3D_Device8(),+ _Get_D3D_Device(),filename,D3DX_DEFAULT,D3DX_DEFAULT,@@ -2625,15 +2735,15 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texturereturn texture;}-IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture+IDirect3DTexture9 * DX8Wrapper::_Create_DX8_Texture(- IDirect3DSurface8 *surface,+ IDirect3DSurface9 *surface,MipCountType mip_level_count){DX8_THREAD_ASSERT();DX8_Assert();- IDirect3DTexture8 *texture = NULL;+ IDirect3DTexture9 *texture = NULL;D3DSURFACE_DESC surface_desc;::ZeroMemory(&surface_desc, sizeof(D3DSURFACE_DESC));@@ -2645,7 +2755,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texturetexture = _Create_DX8_Texture(surface_desc.Width, surface_desc.Height, format, mip_level_count);// Copy the surface to the texture- IDirect3DSurface8 *tex_surface = NULL;+ IDirect3DSurface9 *tex_surface = NULL;texture->GetSurfaceLevel(0, &tex_surface);DX8_ErrorCode(D3DXLoadSurfaceFromSurface(tex_surface, NULL, NULL, surface, NULL, NULL, D3DX_FILTER_BOX, 0));tex_surface->Release();@@ -2663,7 +2773,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture/*!* KJM create depth stencil texture*/-IDirect3DTexture8 * DX8Wrapper::_Create_DX8_ZTexture+IDirect3DTexture9 * DX8Wrapper::_Create_DX8_ZTexture(unsigned int width,unsigned int height,@@ -2674,19 +2784,20 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_ZTexture{DX8_THREAD_ASSERT();DX8_Assert();- IDirect3DTexture8* texture = NULL;+ IDirect3DTexture9* texture = NULL;D3DFORMAT zfmt=WW3DZFormat_To_D3DFormat(zformat);- unsigned ret=DX8Wrapper::_Get_D3D_Device8()->CreateTexture+ unsigned ret=DX8Wrapper::_Get_D3D_Device()->CreateTexture(width,height,mip_level_count,- D3DUSAGE_DEPTHSTENCIL,- zfmt,+ D3DUSAGE_DEPTHSTENCIL,+ zfmt,pool,- &texture+ &texture,+ NULL // pSharedHandle, D3D9's extra parameter, reserved and always null);if (ret==D3DERR_NOTAVAILABLE)@@ -2705,15 +2816,16 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_ZTexture// Invalidate the mesh cacheWW3D::_Invalidate_Mesh_Cache();- ret=DX8Wrapper::_Get_D3D_Device8()->CreateTexture+ ret=DX8Wrapper::_Get_D3D_Device()->CreateTexture(width,height,mip_level_count,- D3DUSAGE_DEPTHSTENCIL,- zfmt,+ D3DUSAGE_DEPTHSTENCIL,+ zfmt,pool,- &texture+ &texture,+ NULL // pSharedHandle, D3D9's extra parameter, reserved and always null);if (SUCCEEDED(ret))@@ -2744,7 +2856,7 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_ZTexture/*!* KJM create cube map texture*/-IDirect3DCubeTexture8* DX8Wrapper::_Create_DX8_Cube_Texture+IDirect3DCubeTexture9* DX8Wrapper::_Create_DX8_Cube_Texture(unsigned int width,unsigned int height,@@ -2757,7 +2869,7 @@ IDirect3DCubeTexture8* DX8Wrapper::_Create_DX8_Cube_TextureWWASSERT(width==height);DX8_THREAD_ASSERT();DX8_Assert();- IDirect3DCubeTexture8* texture=NULL;+ IDirect3DCubeTexture9* texture=NULL;// Paletted textures not supported!WWASSERT(format!=D3DFMT_P8);@@ -2771,7 +2883,7 @@ IDirect3DCubeTexture8* DX8Wrapper::_Create_DX8_Cube_Texture{unsigned ret=D3DXCreateCubeTexture(- DX8Wrapper::_Get_D3D_Device8(),+ DX8Wrapper::_Get_D3D_Device(),width,mip_level_count,D3DUSAGE_RENDERTARGET,@@ -2798,7 +2910,7 @@ IDirect3DCubeTexture8* DX8Wrapper::_Create_DX8_Cube_Textureret=D3DXCreateCubeTexture(- DX8Wrapper::_Get_D3D_Device8(),+ DX8Wrapper::_Get_D3D_Device(),width,mip_level_count,D3DUSAGE_RENDERTARGET,@@ -2833,7 +2945,7 @@ IDirect3DCubeTexture8* DX8Wrapper::_Create_DX8_Cube_Texture// if it happens we'll release assets and try again (anything is better than crashing).unsigned ret=D3DXCreateCubeTexture(- DX8Wrapper::_Get_D3D_Device8(),+ DX8Wrapper::_Get_D3D_Device(),width,mip_level_count,0,@@ -2854,7 +2966,7 @@ IDirect3DCubeTexture8* DX8Wrapper::_Create_DX8_Cube_Textureret=D3DXCreateCubeTexture(- DX8Wrapper::_Get_D3D_Device8(),+ DX8Wrapper::_Get_D3D_Device(),width,mip_level_count,0,@@ -2882,7 +2994,7 @@ IDirect3DCubeTexture8* DX8Wrapper::_Create_DX8_Cube_Texture/*!* KJM create volume texture*/-IDirect3DVolumeTexture8* DX8Wrapper::_Create_DX8_Volume_Texture+IDirect3DVolumeTexture9* DX8Wrapper::_Create_DX8_Volume_Texture(unsigned int width,unsigned int height,@@ -2894,7 +3006,7 @@ IDirect3DVolumeTexture8* DX8Wrapper::_Create_DX8_Volume_Texture{DX8_THREAD_ASSERT();DX8_Assert();- IDirect3DVolumeTexture8* texture=NULL;+ IDirect3DVolumeTexture9* texture=NULL;// Paletted textures not supported!WWASSERT(format!=D3DFMT_P8);@@ -2908,7 +3020,7 @@ IDirect3DVolumeTexture8* DX8Wrapper::_Create_DX8_Volume_Texture// if it happens we'll release assets and try again (anything is better than crashing).unsigned ret=D3DXCreateVolumeTexture(- DX8Wrapper::_Get_D3D_Device8(),+ DX8Wrapper::_Get_D3D_Device(),width,height,depth,@@ -2931,7 +3043,7 @@ IDirect3DVolumeTexture8* DX8Wrapper::_Create_DX8_Volume_Textureret=D3DXCreateVolumeTexture(- DX8Wrapper::_Get_D3D_Device8(),+ DX8Wrapper::_Get_D3D_Device(),width,height,depth,@@ -2959,28 +3071,30 @@ IDirect3DVolumeTexture8* DX8Wrapper::_Create_DX8_Volume_Texture}-IDirect3DSurface8 * DX8Wrapper::_Create_DX8_Surface(unsigned int width, unsigned int height, WW3DFormat format)+IDirect3DSurface9 * DX8Wrapper::_Create_DX8_Surface(unsigned int width, unsigned int height, WW3DFormat format){DX8_THREAD_ASSERT();DX8_Assert();- IDirect3DSurface8 *surface = NULL;+ IDirect3DSurface9 *surface = NULL;// Paletted surfaces not supported!WWASSERT(format!=D3DFMT_P8);// No device, no surface. SurfaceClass carries the null and the callers that matter in such a// run check it; the alternative is CreateImageSurface on a null device.- if (_Get_D3D_Device8() == NULL) {+ if (_Get_D3D_Device() == NULL) {return NULL;}- DX8CALL(CreateImageSurface(width, height, WW3DFormat_To_D3DFormat(format), &surface));+ // D3D9 replaced CreateImageSurface with CreateOffscreenPlainSurface, which names the+ // pool the D3D8 call always used implicitly.+ DX8CALL(CreateOffscreenPlainSurface(width, height, WW3DFormat_To_D3DFormat(format), D3DPOOL_SYSTEMMEM, &surface, NULL));return surface;}-IDirect3DSurface8 * DX8Wrapper::_Create_DX8_Surface(const char *filename_)+IDirect3DSurface9 * DX8Wrapper::_Create_DX8_Surface(const char *filename_){DX8_THREAD_ASSERT();DX8_Assert();@@ -2994,7 +3108,7 @@ IDirect3DSurface8 * DX8Wrapper::_Create_DX8_Surface(const char *filename_)// the file data and use D3DXLoadSurfaceFromFile. This is a horrible hack, but it saves us// having to write file loaders. Will fix this when D3DX provides us with the right functions.// Create a surface the size of the file image data- IDirect3DSurface8 *surface = NULL;+ IDirect3DSurface9 *surface = NULL;{@@ -3059,11 +3173,11 @@ void DX8Wrapper::Compute_Caps(WW3DFormat display_format)DX8_THREAD_ASSERT();DX8_Assert();delete CurrentCaps;- CurrentCaps=new DX8Caps(_Get_D3D8(),D3DDevice,display_format,Get_Current_Adapter_Identifier());+ CurrentCaps=new DX8Caps(_Get_D3D(),D3DDevice,display_format,Get_Current_Adapter_Identifier());}-void DX8Wrapper::Set_Light(unsigned index, const D3DLIGHT8* light)+void DX8Wrapper::Set_Light(unsigned index, const D3DLIGHT9* light){if (light) {render_state.Lights[index]=*light;@@ -3077,9 +3191,9 @@ void DX8Wrapper::Set_Light(unsigned index, const D3DLIGHT8* light)void DX8Wrapper::Set_Light(unsigned index,const LightClass &light){- D3DLIGHT8 dlight;+ D3DLIGHT9 dlight;Vector3 temp;- memset(&dlight,0,sizeof(D3DLIGHT8));+ memset(&dlight,0,sizeof(D3DLIGHT9));switch (light.Get_Type()){@@ -3172,11 +3286,11 @@ void DX8Wrapper::Set_Light_Environment(LightEnvironmentClass* light_env)#endif}- D3DLIGHT8 light;+ D3DLIGHT9 light;int l;for (l =0;l<light_count;++l) {- ::ZeroMemory(&light, sizeof(D3DLIGHT8));+ ::ZeroMemory(&light, sizeof(D3DLIGHT9));light.Type=D3DLIGHT_DIRECTIONAL;(Vector3&)light.Diffuse=light_env->Get_Light_Diffuse(l);@@ -3232,18 +3346,20 @@ void DX8Wrapper::Set_Light_Environment(LightEnvironmentClass* light_env)*/}-IDirect3DSurface8 * DX8Wrapper::_Get_DX8_Front_Buffer()+IDirect3DSurface9 * DX8Wrapper::_Get_DX8_Front_Buffer(){DX8_THREAD_ASSERT();D3DDISPLAYMODE mode;- DX8CALL(GetDisplayMode(&mode));+ DX8CALL(GetDisplayMode(PRIMARY_SWAP_CHAIN,&mode));- IDirect3DSurface8 * fb=NULL;+ IDirect3DSurface9 * fb=NULL;- DX8CALL(CreateImageSurface(mode.Width,mode.Height,D3DFMT_A8R8G8B8,&fb));+ // GetFrontBufferData insists on a system-memory A8R8G8B8 surface of display size,+ // which is exactly what this was already asking CreateImageSurface for.+ DX8CALL(CreateOffscreenPlainSurface(mode.Width,mode.Height,D3DFMT_A8R8G8B8,D3DPOOL_SYSTEMMEM,&fb,NULL));- DX8CALL(GetFrontBuffer(fb));+ DX8CALL(GetFrontBufferData(PRIMARY_SWAP_CHAIN,fb));return fb;}@@ -3251,9 +3367,9 @@ SurfaceClass * DX8Wrapper::_Get_DX8_Back_Buffer(unsigned int num){DX8_THREAD_ASSERT();- IDirect3DSurface8 * bb = NULL; // left untouched when the call fails; the test below is not+ IDirect3DSurface9 * bb = NULL; // left untouched when the call fails; the test below is notSurfaceClass *surf=NULL;- DX8CALL(GetBackBuffer(num,D3DBACKBUFFER_TYPE_MONO,&bb));+ DX8CALL(GetBackBuffer(PRIMARY_SWAP_CHAIN,num,D3DBACKBUFFER_TYPE_MONO,&bb));if (bb){surf=NEW_REF(SurfaceClass,(bb));@@ -3274,7 +3390,7 @@ DX8Wrapper::Create_Render_Target (int width, int height, WW3DFormat format)// Use the current display format if format isn't specifiedif (format==WW3D_FORMAT_UNKNOWN) {D3DDISPLAYMODE mode;- DX8CALL(GetDisplayMode(&mode));+ DX8CALL(GetDisplayMode(PRIMARY_SWAP_CHAIN,&mode));format=D3DFormat_To_WW3DFormat(mode.Format);}@@ -3287,7 +3403,7 @@ DX8Wrapper::Create_Render_Target (int width, int height, WW3DFormat format)//// Note: We're going to force the width and height to be powers of two and equal//- const D3DCAPS8& dx8caps=Get_Current_Caps()->Get_DX8_Caps();+ const D3DCAPS9& dx8caps=Get_Current_Caps()->Get_DX8_Caps();float poweroftwosize = width;if (height > 0 && height < width) {poweroftwosize = height;@@ -3344,7 +3460,7 @@ void DX8Wrapper::Create_Render_Target*depth_buffer=NULL;return;/* D3DDISPLAYMODE mode;- DX8CALL(GetDisplayMode(&mode));+ DX8CALL(GetDisplayMode(PRIMARY_SWAP_CHAIN,&mode));format=D3DFormat_To_WW3DFormat(mode.Format);*/}@@ -3357,7 +3473,7 @@ void DX8Wrapper::Create_Render_Target}// Note: We're going to force the width and height to be powers of two and equal- const D3DCAPS8& dx8caps=Get_Current_Caps()->Get_DX8_Caps();+ const D3DCAPS9& dx8caps=Get_Current_Caps()->Get_DX8_Caps();float poweroftwosize = width;if (height > 0 && height < width){@@ -3415,10 +3531,10 @@ void DX8Wrapper::Set_Render_Target_With_Z){WWASSERT(texture!=NULL);- IDirect3DSurface8 * d3d_surf = texture->Get_D3D_Surface_Level();+ IDirect3DSurface9 * d3d_surf = texture->Get_D3D_Surface_Level();WWASSERT(d3d_surf != NULL);- IDirect3DSurface8* d3d_zbuf=NULL;+ IDirect3DSurface9* d3d_zbuf=NULL;if (ztexture!=NULL){@@ -3449,13 +3565,17 @@ unsigned DX8Wrapper::Get_MultiSample_Level(void)return (unsigned)_PresentParameters.MultiSampleType;}-IDirect3DSurface8 * DX8Wrapper::_Get_Non_MultiSampled_Depth_Buffer(void)+IDirect3DSurface9 * DX8Wrapper::_Get_Non_MultiSampled_Depth_Buffer(void){if (_PresentParameters.MultiSampleType == D3DMULTISAMPLE_NONE) return NULL;if (_RTTDepthBuffer == NULL && D3DDevice != NULL) {if (FAILED(D3DDevice->CreateDepthStencilSurface(_PresentParameters.BackBufferWidth,_PresentParameters.BackBufferHeight,- _PresentParameters.AutoDepthStencilFormat,D3DMULTISAMPLE_NONE,&_RTTDepthBuffer))) {+ _PresentParameters.AutoDepthStencilFormat,D3DMULTISAMPLE_NONE,+ 0, // MultisampleQuality, meaningless without multisampling+ TRUE, // Discard, which is what a depth buffer nobody reads back wants+ &_RTTDepthBuffer,+ NULL))) {_RTTDepthBuffer = NULL;}}@@ -3463,7 +3583,7 @@ IDirect3DSurface8 * DX8Wrapper::_Get_Non_MultiSampled_Depth_Buffer(void)}void-DX8Wrapper::Set_Render_Target(IDirect3DSwapChain8 *swap_chain)+DX8Wrapper::Set_Render_Target(IDirect3DSwapChain9 *swap_chain){DX8_THREAD_ASSERT();WWASSERT (swap_chain != NULL);@@ -3471,7 +3591,7 @@ DX8Wrapper::Set_Render_Target(IDirect3DSwapChain8 *swap_chain)//// Get the back buffer for the swap chain//- LPDIRECT3DSURFACE8 render_target = NULL;+ LPDIRECT3DSURFACE9 render_target = NULL;swap_chain->GetBackBuffer (0, D3DBACKBUFFER_TYPE_MONO, &render_target);//@@ -3493,7 +3613,7 @@ DX8Wrapper::Set_Render_Target(IDirect3DSwapChain8 *swap_chain)}void-DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default_depth_buffer)+DX8Wrapper::Set_Render_Target(IDirect3DSurface9 *render_target, bool use_default_depth_buffer){//#ifndef _XBOXDX8_THREAD_ASSERT();@@ -3515,7 +3635,7 @@ DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default//if (DefaultRenderTarget != NULL){- DX8CALL(SetRenderTarget (DefaultRenderTarget, DefaultDepthBuffer));+ _Set_DX8_Render_Target(DefaultRenderTarget, DefaultDepthBuffer);DefaultRenderTarget->Release ();DefaultRenderTarget = NULL;if (DefaultDepthBuffer)@@ -3550,7 +3670,7 @@ DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default//if (DefaultDepthBuffer == NULL){-// IDirect3DSurface8 *depth_buffer = NULL;+// IDirect3DSurface9 *depth_buffer = NULL;DX8CALL(GetDepthStencilSurface (&DefaultDepthBuffer));}@@ -3559,7 +3679,7 @@ DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default//if (DefaultRenderTarget == NULL){- DX8CALL(GetRenderTarget (&DefaultRenderTarget));+ DX8CALL(GetRenderTarget (PRIMARY_RENDER_TARGET, &DefaultRenderTarget));}//@@ -3593,12 +3713,12 @@ DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default{// The default depth buffer is multisampled when the back buffer is; this// target is not, so it needs the plain one instead.- IDirect3DSurface8 * z = _Get_Non_MultiSampled_Depth_Buffer();- DX8CALL(SetRenderTarget (CurrentRenderTarget, z ? z : DefaultDepthBuffer));+ IDirect3DSurface9 * z = _Get_Non_MultiSampled_Depth_Buffer();+ _Set_DX8_Render_Target(CurrentRenderTarget, z ? z : DefaultDepthBuffer);}- else+ else{- DX8CALL(SetRenderTarget (CurrentRenderTarget, NULL));+ _Set_DX8_Render_Target(CurrentRenderTarget, NULL);}}}@@ -3623,8 +3743,8 @@ DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default*/void DX8Wrapper::Set_Render_Target(- IDirect3DSurface8* render_target,- IDirect3DSurface8* depth_buffer+ IDirect3DSurface9* render_target,+ IDirect3DSurface9* depth_buffer){//#ifndef _XBOX@@ -3647,7 +3767,7 @@ void DX8Wrapper::Set_Render_Target//if (DefaultRenderTarget != NULL){- DX8CALL(SetRenderTarget (DefaultRenderTarget, DefaultDepthBuffer));+ _Set_DX8_Render_Target(DefaultRenderTarget, DefaultDepthBuffer);DefaultRenderTarget->Release ();DefaultRenderTarget = NULL;if (DefaultDepthBuffer)@@ -3681,7 +3801,7 @@ void DX8Wrapper::Set_Render_Target//if (DefaultDepthBuffer == NULL){-// IDirect3DSurface8 *depth_buffer = NULL;+// IDirect3DSurface9 *depth_buffer = NULL;DX8CALL(GetDepthStencilSurface (&DefaultDepthBuffer));}@@ -3690,7 +3810,7 @@ void DX8Wrapper::Set_Render_Target//if (DefaultRenderTarget == NULL){- DX8CALL(GetRenderTarget (&DefaultRenderTarget));+ DX8CALL(GetRenderTarget (PRIMARY_RENDER_TARGET, &DefaultRenderTarget));}//@@ -3722,7 +3842,7 @@ void DX8Wrapper::Set_Render_Target//// Switch render targets//- DX8CALL(SetRenderTarget (CurrentRenderTarget, CurrentDepthBuffer));+ _Set_DX8_Render_Target(CurrentRenderTarget, CurrentDepthBuffer);}}@@ -3731,7 +3851,7 @@ void DX8Wrapper::Set_Render_Target}-IDirect3DSwapChain8 *+IDirect3DSwapChain9 *DX8Wrapper::Create_Additional_Swap_Chain (HWND render_window){DX8_Assert();@@ -3743,19 +3863,21 @@ DX8Wrapper::Create_Additional_Swap_Chain (HWND render_window)params.BackBufferFormat = _PresentParameters.BackBufferFormat;params.BackBufferCount = 1;params.MultiSampleType = D3DMULTISAMPLE_NONE;- params.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;+ // D3D9 dropped D3DSWAPEFFECT_COPY_VSYNC: the vsync half of it is a presentation+ // interval now, and the swap effect is only the copy.+ params.SwapEffect = D3DSWAPEFFECT_COPY;params.hDeviceWindow = render_window;params.Windowed = TRUE;params.EnableAutoDepthStencil = TRUE;params.AutoDepthStencilFormat = _PresentParameters.AutoDepthStencilFormat;params.Flags = 0;params.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;- params.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;+ params.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // the vsync half of the old COPY_VSYNC swap effect//// Create the swap chain//- IDirect3DSwapChain8 *swap_chain = NULL;+ IDirect3DSwapChain9 *swap_chain = NULL;DX8CALL(CreateAdditionalSwapChain(¶ms, &swap_chain));return swap_chain;}@@ -3763,14 +3885,17 @@ DX8Wrapper::Create_Additional_Swap_Chain (HWND render_window)void DX8Wrapper::Flush_DX8_Resource_Manager(unsigned int bytes){DX8_Assert();- DX8CALL(ResourceManagerDiscardBytes(bytes));+ // D3D9's EvictManagedResources takes no byte count and discards the lot; the argument+ // is kept because every caller passes 0, which meant the same thing to D3D8.+ WWASSERT(bytes==0);+ DX8CALL(EvictManagedResources());}unsigned int DX8Wrapper::Get_Free_Texture_RAM(){DX8_Assert();number_of_DX8_calls++;- return DX8Wrapper::_Get_D3D_Device8()->GetAvailableTextureMem();+ return DX8Wrapper::_Get_D3D_Device()->GetAvailableTextureMem();}// Converts a linear gamma ramp to one that is controlled by:@@ -3814,7 +3939,7 @@ void DX8Wrapper::Set_Gamma(float gamma,float bright,float contrast,bool calibrat}if (Get_Current_Caps()->Support_Gamma()) {- DX8Wrapper::_Get_D3D_Device8()->SetGammaRamp(flag,&ramp);+ DX8Wrapper::_Get_D3D_Device()->SetGammaRamp(PRIMARY_SWAP_CHAIN,flag,&ramp);} else {HWND hwnd = GetDesktopWindow();HDC hdc = GetDC(hwnd);@@ -3861,7 +3986,7 @@ void DX8Wrapper::Apply_Default_State()// Set_DX8_Render_State(D3DRS_FOGDENSITY, WWMath::Float_As_Int(1.0f));//Set_DX8_Render_State(D3DRS_EDGEANTIALIAS, FALSE);- Set_DX8_Render_State(D3DRS_ZBIAS, 0);+ Set_DX8_ZBias(0);// Set_DX8_Render_State(D3DRS_RANGEFOGENABLE, FALSE);Set_DX8_Render_State(D3DRS_STENCILENABLE, FALSE);Set_DX8_Render_State(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);@@ -3893,7 +4018,8 @@ void DX8Wrapper::Apply_Default_State()Set_DX8_Render_State(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);Set_DX8_Render_State(D3DRS_VERTEXBLEND, D3DVBF_DISABLE);*///Set_DX8_Render_State(D3DRS_CLIPPLANEENABLE, 0);- Set_DX8_Render_State(D3DRS_SOFTWAREVERTEXPROCESSING, FALSE);+ // D3D9 took this off the render state list; it has its own call now.+ DX8CALL(SetSoftwareVertexProcessing(FALSE));//Set_DX8_Render_State(D3DRS_POINTSIZE, 0x3f800000);//Set_DX8_Render_State(D3DRS_POINTSIZE_MIN, 0);//Set_DX8_Render_State(D3DRS_POINTSPRITEENABLE, FALSE);@@ -3936,16 +4062,16 @@ void DX8Wrapper::Apply_Default_State()Set_DX8_Texture_Stage_State(i, D3DTSS_TEXCOORDINDEX, i);- Set_DX8_Texture_Stage_State(i, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);- Set_DX8_Texture_Stage_State(i, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);- Set_DX8_Texture_Stage_State(i, D3DTSS_BORDERCOLOR, 0);-// Set_DX8_Texture_Stage_State(i, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);-// Set_DX8_Texture_Stage_State(i, D3DTSS_MINFILTER, D3DTEXF_LINEAR);-// Set_DX8_Texture_Stage_State(i, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);-// Set_DX8_Texture_Stage_State(i, D3DTSS_MIPMAPLODBIAS, 0);+ Set_DX8_Texture_Stage_State(i, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);+ Set_DX8_Texture_Stage_State(i, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);+ Set_DX8_Texture_Stage_State(i, D3DSAMP_BORDERCOLOR, 0);+// Set_DX8_Texture_Stage_State(i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+// Set_DX8_Texture_Stage_State(i, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+// Set_DX8_Texture_Stage_State(i, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);+// Set_DX8_Texture_Stage_State(i, D3DSAMP_MIPMAPLODBIAS, 0);// Set_DX8_Texture_Stage_State(i, D3DTSS_MAXMIPLEVEL, 0);-// Set_DX8_Texture_Stage_State(i, D3DTSS_MAXANISOTROPY, 1);- //Set_DX8_Texture_Stage_State(i, D3DTSS_ADDRESSW, D3DTADDRESS_WRAP);+// Set_DX8_Texture_Stage_State(i, D3DSAMP_MAXANISOTROPY, 1);+ //Set_DX8_Texture_Stage_State(i, D3DSAMP_ADDRESSW, D3DTADDRESS_WRAP);//Set_DX8_Texture_Stage_State(i, D3DTSS_COLORARG0, D3DTA_CURRENT);//Set_DX8_Texture_Stage_State(i, D3DTSS_ALPHAARG0, D3DTA_CURRENT);//Set_DX8_Texture_Stage_State(i, D3DTSS_RESULTARG, D3DTA_CURRENT);@@ -3971,8 +4097,8 @@ void DX8Wrapper::Apply_Default_State()memset(pconst,0,sizeof(Vector4)*MAX_PIXEL_SHADER_CONSTANTS);Set_Pixel_Shader_Constant(0, pconst, MAX_PIXEL_SHADER_CONSTANTS);- Set_Vertex_Shader(DX8_FVF_XYZNDUV2);- Set_Pixel_Shader(0);+ Set_Vertex_Format(DX8_FVF_XYZNDUV2);+ Set_Pixel_Shader(NULL);ShaderClass::Invalidate();}@@ -3983,7 +4109,6 @@ const char* DX8Wrapper::Get_DX8_Render_State_Name(D3DRENDERSTATETYPE state)case D3DRS_ZENABLE : return "D3DRS_ZENABLE";case D3DRS_FILLMODE : return "D3DRS_FILLMODE";case D3DRS_SHADEMODE : return "D3DRS_SHADEMODE";- case D3DRS_LINEPATTERN : return "D3DRS_LINEPATTERN";case D3DRS_ZWRITEENABLE : return "D3DRS_ZWRITEENABLE";case D3DRS_ALPHATESTENABLE : return "D3DRS_ALPHATESTENABLE";case D3DRS_LASTPIXEL : return "D3DRS_LASTPIXEL";@@ -3997,14 +4122,12 @@ const char* DX8Wrapper::Get_DX8_Render_State_Name(D3DRENDERSTATETYPE state)case D3DRS_ALPHABLENDENABLE : return "D3DRS_ALPHABLENDENABLE";case D3DRS_FOGENABLE : return "D3DRS_FOGENABLE";case D3DRS_SPECULARENABLE : return "D3DRS_SPECULARENABLE";- case D3DRS_ZVISIBLE : return "D3DRS_ZVISIBLE";case D3DRS_FOGCOLOR : return "D3DRS_FOGCOLOR";case D3DRS_FOGTABLEMODE : return "D3DRS_FOGTABLEMODE";case D3DRS_FOGSTART : return "D3DRS_FOGSTART";case D3DRS_FOGEND : return "D3DRS_FOGEND";case D3DRS_FOGDENSITY : return "D3DRS_FOGDENSITY";- case D3DRS_EDGEANTIALIAS : return "D3DRS_EDGEANTIALIAS";- case D3DRS_ZBIAS : return "D3DRS_ZBIAS";+ case D3DRS_DEPTHBIAS : return "D3DRS_DEPTHBIAS";case D3DRS_RANGEFOGENABLE : return "D3DRS_RANGEFOGENABLE";case D3DRS_STENCILENABLE : return "D3DRS_STENCILENABLE";case D3DRS_STENCILFAIL : return "D3DRS_STENCILFAIL";@@ -4036,7 +4159,6 @@ const char* DX8Wrapper::Get_DX8_Render_State_Name(D3DRENDERSTATETYPE state)case D3DRS_EMISSIVEMATERIALSOURCE : return "D3DRS_EMISSIVEMATERIALSOURCE";case D3DRS_VERTEXBLEND : return "D3DRS_VERTEXBLEND";case D3DRS_CLIPPLANEENABLE : return "D3DRS_CLIPPLANEENABLE";- case D3DRS_SOFTWAREVERTEXPROCESSING : return "D3DRS_SOFTWAREVERTEXPROCESSING";case D3DRS_POINTSIZE : return "D3DRS_POINTSIZE";case D3DRS_POINTSIZE_MIN : return "D3DRS_POINTSIZE_MIN";case D3DRS_POINTSPRITEENABLE : return "D3DRS_POINTSPRITEENABLE";@@ -4047,7 +4169,6 @@ const char* DX8Wrapper::Get_DX8_Render_State_Name(D3DRENDERSTATETYPE state)case D3DRS_MULTISAMPLEANTIALIAS : return "D3DRS_MULTISAMPLEANTIALIAS";case D3DRS_MULTISAMPLEMASK : return "D3DRS_MULTISAMPLEMASK";case D3DRS_PATCHEDGESTYLE : return "D3DRS_PATCHEDGESTYLE";- case D3DRS_PATCHSEGMENTS : return "D3DRS_PATCHSEGMENTS";case D3DRS_DEBUGMONITORTOKEN : return "D3DRS_DEBUGMONITORTOKEN";case D3DRS_POINTSIZE_MAX : return "D3DRS_POINTSIZE_MAX";case D3DRS_INDEXEDVERTEXBLENDENABLE : return "D3DRS_INDEXEDVERTEXBLENDENABLE";@@ -4074,19 +4195,9 @@ const char* DX8Wrapper::Get_DX8_Texture_Stage_State_Name(D3DTEXTURESTAGESTATETYPcase D3DTSS_BUMPENVMAT10 : return "D3DTSS_BUMPENVMAT10";case D3DTSS_BUMPENVMAT11 : return "D3DTSS_BUMPENVMAT11";case D3DTSS_TEXCOORDINDEX : return "D3DTSS_TEXCOORDINDEX";- case D3DTSS_ADDRESSU : return "D3DTSS_ADDRESSU";- case D3DTSS_ADDRESSV : return "D3DTSS_ADDRESSV";- case D3DTSS_BORDERCOLOR : return "D3DTSS_BORDERCOLOR";- case D3DTSS_MAGFILTER : return "D3DTSS_MAGFILTER";- case D3DTSS_MINFILTER : return "D3DTSS_MINFILTER";- case D3DTSS_MIPFILTER : return "D3DTSS_MIPFILTER";- case D3DTSS_MIPMAPLODBIAS : return "D3DTSS_MIPMAPLODBIAS";- case D3DTSS_MAXMIPLEVEL : return "D3DTSS_MAXMIPLEVEL";- case D3DTSS_MAXANISOTROPY : return "D3DTSS_MAXANISOTROPY";case D3DTSS_BUMPENVLSCALE : return "D3DTSS_BUMPENVLSCALE";case D3DTSS_BUMPENVLOFFSET : return "D3DTSS_BUMPENVLOFFSET";case D3DTSS_TEXTURETRANSFORMFLAGS : return "D3DTSS_TEXTURETRANSFORMFLAGS";- case D3DTSS_ADDRESSW : return "D3DTSS_ADDRESSW";case D3DTSS_COLORARG0 : return "D3DTSS_COLORARG0";case D3DTSS_ALPHAARG0 : return "D3DTSS_ALPHAARG0";case D3DTSS_RESULTARG : return "D3DTSS_RESULTARG";@@ -4094,6 +4205,24 @@ const char* DX8Wrapper::Get_DX8_Texture_Stage_State_Name(D3DTEXTURESTAGESTATETYP}}+// The half of the old texture stage state list that D3D9 moved onto the sampler.+const char* DX8Wrapper::Get_DX8_Sampler_State_Name(D3DSAMPLERSTATETYPE state)+{+ switch (state) {+ case D3DSAMP_ADDRESSU : return "D3DSAMP_ADDRESSU";+ case D3DSAMP_ADDRESSV : return "D3DSAMP_ADDRESSV";+ case D3DSAMP_ADDRESSW : return "D3DSAMP_ADDRESSW";+ case D3DSAMP_BORDERCOLOR : return "D3DSAMP_BORDERCOLOR";+ case D3DSAMP_MAGFILTER : return "D3DSAMP_MAGFILTER";+ case D3DSAMP_MINFILTER : return "D3DSAMP_MINFILTER";+ case D3DSAMP_MIPFILTER : return "D3DSAMP_MIPFILTER";+ case D3DSAMP_MIPMAPLODBIAS : return "D3DSAMP_MIPMAPLODBIAS";+ case D3DSAMP_MAXMIPLEVEL : return "D3DSAMP_MAXMIPLEVEL";+ case D3DSAMP_MAXANISOTROPY : return "D3DSAMP_MAXANISOTROPY";+ default : return "UNKNOWN";+ }+}+void DX8Wrapper::Get_DX8_Render_State_Value_Name(StringClass& name, D3DRENDERSTATETYPE state, unsigned value){switch (state) {@@ -4109,7 +4238,6 @@ void DX8Wrapper::Get_DX8_Render_State_Value_Name(StringClass& name, D3DRENDERSTAname=Get_DX8_Shade_Mode_Name(value);break;- case D3DRS_LINEPATTERN:case D3DRS_FOGCOLOR:case D3DRS_ALPHAREF:case D3DRS_STENCILMASK:@@ -4130,13 +4258,11 @@ void DX8Wrapper::Get_DX8_Render_State_Value_Name(StringClass& name, D3DRENDERSTAcase D3DRS_SPECULARENABLE:case D3DRS_STENCILENABLE:case D3DRS_RANGEFOGENABLE:- case D3DRS_EDGEANTIALIAS:case D3DRS_CLIPPING:case D3DRS_LIGHTING:case D3DRS_COLORVERTEX:case D3DRS_LOCALVIEWER:case D3DRS_NORMALIZENORMALS:- case D3DRS_SOFTWAREVERTEXPROCESSING:case D3DRS_POINTSPRITEENABLE:case D3DRS_POINTSCALEENABLE:case D3DRS_MULTISAMPLEANTIALIAS:@@ -4159,10 +4285,6 @@ void DX8Wrapper::Get_DX8_Render_State_Value_Name(StringClass& name, D3DRENDERSTAname=Get_DX8_Cmp_Func_Name(value);break;- case D3DRS_ZVISIBLE:- name="NOTSUPPORTED";- break;-case D3DRS_FOGTABLEMODE:case D3DRS_FOGVERTEXMODE:name=Get_DX8_Fog_Mode_Name(value);@@ -4176,13 +4298,12 @@ void DX8Wrapper::Get_DX8_Render_State_Value_Name(StringClass& name, D3DRENDERSTAcase D3DRS_POINTSCALE_A:case D3DRS_POINTSCALE_B:case D3DRS_POINTSCALE_C:- case D3DRS_PATCHSEGMENTS:case D3DRS_POINTSIZE_MAX:case D3DRS_TWEENFACTOR:+ case D3DRS_DEPTHBIAS:name.Format("%f",*(float*)&value);break;- case D3DRS_ZBIAS:case D3DRS_STENCILREF:name.Format("%d",value);break;@@ -4260,23 +4381,10 @@ void DX8Wrapper::Get_DX8_Texture_Stage_State_Value_Name(StringClass& name, D3DTEname=Get_DX8_Texture_Arg_Name(value);break;- case D3DTSS_ADDRESSU:- case D3DTSS_ADDRESSV:- case D3DTSS_ADDRESSW:- name=Get_DX8_Texture_Address_Name(value);- break;-- case D3DTSS_MAGFILTER:- case D3DTSS_MINFILTER:- case D3DTSS_MIPFILTER:- name=Get_DX8_Texture_Filter_Name(value);- break;-case D3DTSS_TEXTURETRANSFORMFLAGS:name=Get_DX8_Texture_Transform_Flag_Name(value);// Floating point values- case D3DTSS_MIPMAPLODBIAS:case D3DTSS_BUMPENVMAT00:case D3DTSS_BUMPENVMAT01:case D3DTSS_BUMPENVMAT10:@@ -4301,13 +4409,38 @@ void DX8Wrapper::Get_DX8_Texture_Stage_State_Value_Name(StringClass& name, D3DTE}break;- // Integer value- case D3DTSS_MAXMIPLEVEL:- case D3DTSS_MAXANISOTROPY:+ default:+ name.Format("UNKNOWN (%d)",value);+ break;+ }+}++// The value side of the states D3D9 moved onto the sampler.+void DX8Wrapper::Get_DX8_Sampler_State_Value_Name(StringClass& name, D3DSAMPLERSTATETYPE state, unsigned value)+{+ switch (state) {+ case D3DSAMP_ADDRESSU:+ case D3DSAMP_ADDRESSV:+ case D3DSAMP_ADDRESSW:+ name=Get_DX8_Texture_Address_Name(value);+ break;++ case D3DSAMP_MAGFILTER:+ case D3DSAMP_MINFILTER:+ case D3DSAMP_MIPFILTER:+ name=Get_DX8_Texture_Filter_Name(value);+ break;++ case D3DSAMP_MIPMAPLODBIAS:+ name.Format("%f",*(float*)&value);+ break;++ case D3DSAMP_MAXMIPLEVEL:+ case D3DSAMP_MAXANISOTROPY:name.Format("%d",value);break;- // Hex values- case D3DTSS_BORDERCOLOR:++ case D3DSAMP_BORDERCOLOR:name.Format("0x%x",value);break;@@ -4373,8 +4506,8 @@ const char* DX8Wrapper::Get_DX8_Texture_Filter_Name(unsigned value)case D3DTEXF_POINT : return "D3DTEXF_POINT";case D3DTEXF_LINEAR : return "D3DTEXF_LINEAR";case D3DTEXF_ANISOTROPIC : return "D3DTEXF_ANISOTROPIC";- case D3DTEXF_FLATCUBIC : return "D3DTEXF_FLATCUBIC";- case D3DTEXF_GAUSSIANCUBIC : return "D3DTEXF_GAUSSIANCUBIC";+ case D3DTEXF_PYRAMIDALQUAD : return "D3DTEXF_PYRAMIDALQUAD";+ case D3DTEXF_GAUSSIANQUAD : return "D3DTEXF_GAUSSIANQUAD";default : return "UNKNOWN";}}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.hindex 24cc0d527..a01e1d256 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h@@ -48,7 +48,9 @@#include "always.h"#include "dllist.h"-#include "d3d8.h"+#include <d3d9.h>+#include "d3dx9runtime.h"+#include "d3dx9math.h"#include "matrix4.h"#include "statistics.h"#include "wwstring.h"@@ -74,6 +76,22 @@#define VALUE_NAME_RENDER_DEVICE_TEXTURE_DEPTH "RenderDeviceTextureDepth"const unsigned MAX_TEXTURE_STAGES=8;+// D3D9 moved the filter, address and anisotropy states off the texture stage and onto+// the sampler, so they are cached separately: the two enums renumber from 1 and would+// otherwise collide in one array. D3DSAMP_DMAPOFFSET is 13, the last of them.+const unsigned MAX_SAMPLER_STATES=16;+// D3D8's D3DRS_ZBIAS clamped its level here, and the levels are what the engine's own+// callers still pass.+const int MAX_Z_BIAS_LEVEL=15;+// D3D9 added a swap chain index to GetDisplayMode, GetBackBuffer and GetFrontBufferData.+// This renderer creates one implicit swap chain and never asks about another.+const UINT PRIMARY_SWAP_CHAIN=0;+// D3D9 can bind several render targets at once and indexes them; this renderer binds one.+const DWORD PRIMARY_RENDER_TARGET=0;+// D3D8's GetAdapterIdentifier took D3DENUM_NO_WHQL_LEVEL to skip a slow WHQL signature+// check. D3D9 removed the flag and never does that check unless asked, so zero is what+// the old call was actually asking for.+const DWORD NO_ADAPTER_IDENTIFIER_FLAGS=0;const unsigned MAX_VERTEX_STREAMS=2;const unsigned MAX_VERTEX_SHADER_CONSTANTS=96;const unsigned MAX_PIXEL_SHADER_CONSTANTS=8;@@ -121,6 +139,7 @@ extern bool _DX8SingleThreaded;void DX8_Assert();void Log_DX8_ErrorCode(unsigned res);+void Non_Fatal_Log_DX8_ErrorCode(unsigned res,const char * file,int line);WWINLINE void DX8_ErrorCode(unsigned res){@@ -129,14 +148,14 @@ WWINLINE void DX8_ErrorCode(unsigned res)}#ifdef WWDEBUG-#define DX8CALL_HRES(x,res) DX8_Assert(); res = DX8Wrapper::_Get_D3D_Device8()->x; DX8_ErrorCode(res); number_of_DX8_calls++;-#define DX8CALL(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D_Device8()->x); number_of_DX8_calls++;-#define DX8CALL_D3D(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D8()->x); number_of_DX8_calls++;+#define DX8CALL_HRES(x,res) DX8_Assert(); res = DX8Wrapper::_Get_D3D_Device()->x; DX8_ErrorCode(res); number_of_DX8_calls++;+#define DX8CALL(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D_Device()->x); number_of_DX8_calls++;+#define DX8CALL_D3D(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D()->x); number_of_DX8_calls++;#define DX8_THREAD_ASSERT() if (_DX8SingleThreaded) { WWASSERT_PRINT(DX8Wrapper::_Get_Main_Thread_ID()==ThreadClass::_Get_Current_Thread_ID(),"DX8Wrapper::DX8 calls must be called from the main thread!"); }#else-#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++;-#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++;-#define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D8()->x; number_of_DX8_calls++;+#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device()->x; number_of_DX8_calls++;+#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device()->x; number_of_DX8_calls++;+#define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D()->x; number_of_DX8_calls++;#define DX8_THREAD_ASSERT() ;#endif@@ -182,7 +201,7 @@ struct RenderStateStructShaderClass shader;VertexMaterialClass* material;TextureBaseClass * Textures[MAX_TEXTURE_STAGES];- D3DLIGHT8 Lights[4];+ D3DLIGHT9 Lights[4];bool LightEnable[4];//unsigned lightsHash;Matrix4x4 world;@@ -287,7 +306,7 @@ public:static void Clear(bool clear_color, bool clear_z_stencil, const Vector3 &color, float dest_alpha=0.0f, float z=1.0f, unsigned int stencil=0);- static void Set_Viewport(CONST D3DVIEWPORT8* pViewport);+ static void Set_Viewport(CONST D3DVIEWPORT9* pViewport);static void Set_Vertex_Buffer(const VertexBufferClass* vb, unsigned stream=0);static void Set_Vertex_Buffer(const DynamicVBAccessClass& vba);@@ -299,7 +318,7 @@ public:static void Set_Render_State(const RenderStateStruct& state);static void Release_Render_State();- static void Set_DX8_Material(const D3DMATERIAL8* mat);+ static void Set_DX8_Material(const D3DMATERIAL9* mat);static void Set_Gamma(float gamma,float bright,float contrast,bool calibrate=true,bool uselimit=true);@@ -322,16 +341,17 @@ public:static void _Set_DX8_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix3D& m);static void _Get_DX8_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4& m);- static void Set_DX8_Light(int index,D3DLIGHT8* light);+ static void Set_DX8_Light(int index,D3DLIGHT9* light);static void Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value);static void Set_DX8_Clip_Plane(DWORD Index, CONST float* pPlane);static void Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTURESTAGESTATETYPE state, unsigned value);- static void Set_DX8_Texture(unsigned int stage, IDirect3DBaseTexture8* texture);+ static void Set_DX8_Texture_Stage_State(unsigned stage, D3DSAMPLERSTATETYPE state, unsigned value);+ static void Set_DX8_Texture(unsigned int stage, IDirect3DBaseTexture9* texture);static void Set_Light_Environment(LightEnvironmentClass* light_env);static LightEnvironmentClass* Get_Light_Environment() { return Light_Environment; }static void Set_Fog(bool enable, const Vector3 &color, float start, float end);- static WWINLINE const D3DLIGHT8& Peek_Light(unsigned index);+ static WWINLINE const D3DLIGHT9& Peek_Light(unsigned index);static WWINLINE bool Is_Light_Enabled(unsigned index);static bool Validate_Device(void);@@ -342,7 +362,7 @@ public:static void Get_Shader(ShaderClass& shader);static void Set_Texture(unsigned stage,TextureBaseClass* texture);static void Set_Material(const VertexMaterialClass* material);- static void Set_Light(unsigned index,const D3DLIGHT8* light);+ static void Set_Light(unsigned index,const D3DLIGHT9* light);static void Set_Light(unsigned index,const LightClass &light);static void Apply_Render_State_Changes(); // Apply deferred render state changes (will be called automatically by Draw...)@@ -368,7 +388,7 @@ public:** Resources*/- static IDirect3DVolumeTexture8* _Create_DX8_Volume_Texture+ static IDirect3DVolumeTexture9* _Create_DX8_Volume_Texture(unsigned int width,unsigned int height,@@ -378,7 +398,7 @@ public:D3DPOOL pool=D3DPOOL_MANAGED);- static IDirect3DCubeTexture8* _Create_DX8_Cube_Texture+ static IDirect3DCubeTexture9* _Create_DX8_Cube_Texture(unsigned int width,unsigned int height,@@ -389,7 +409,7 @@ public:);- static IDirect3DTexture8* _Create_DX8_ZTexture+ static IDirect3DTexture9* _Create_DX8_ZTexture(unsigned int width,unsigned int height,@@ -399,7 +419,7 @@ public:);- static IDirect3DTexture8 * _Create_DX8_Texture+ static IDirect3DTexture9 * _Create_DX8_Texture(unsigned int width,unsigned int height,@@ -408,19 +428,29 @@ public:D3DPOOL pool=D3DPOOL_MANAGED,bool rendertarget=false);- static IDirect3DTexture8 * _Create_DX8_Texture(const char *filename, MipCountType mip_level_count);- static IDirect3DTexture8 * _Create_DX8_Texture(IDirect3DSurface8 *surface, MipCountType mip_level_count);+ static IDirect3DTexture9 * _Create_DX8_Texture(const char *filename, MipCountType mip_level_count);+ static IDirect3DTexture9 * _Create_DX8_Texture(IDirect3DSurface9 *surface, MipCountType mip_level_count);- static IDirect3DSurface8 * _Create_DX8_Surface(unsigned int width, unsigned int height, WW3DFormat format);- static IDirect3DSurface8 * _Create_DX8_Surface(const char *filename);- static IDirect3DSurface8 * _Get_DX8_Front_Buffer();+ static IDirect3DSurface9 * _Create_DX8_Surface(unsigned int width, unsigned int height, WW3DFormat format);+ static IDirect3DSurface9 * _Create_DX8_Surface(const char *filename);+ static IDirect3DSurface9 * _Get_DX8_Front_Buffer();static SurfaceClass * _Get_DX8_Back_Buffer(unsigned int num=0);+ // One depth-buffer level of bias, negative, as D3DRS_DEPTHBIAS wants it. Set from+ // the depth stencil format when the device comes up; see Set_DX8_ZBias.+ static float Get_Depth_Buffer_Epsilon() { return DepthBufferEpsilon; }+ static float _Depth_Buffer_Epsilon(D3DFORMAT depth_stencil_format);++ // D3D8's SetRenderTarget bound the colour and depth surfaces in one call; D3D9 has+ // two, and the depth one is not indexed. A null depth surface means no depth at all,+ // which is what the D3D8 call meant by it too.+ static void _Set_DX8_Render_Target(IDirect3DSurface9 * render_target, IDirect3DSurface9 * depth_buffer);+static void _Copy_DX8_Rects(- IDirect3DSurface8* pSourceSurface,+ IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRectsArray,UINT cRects,- IDirect3DSurface8* pDestinationSurface,+ IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPointsArray);@@ -429,7 +459,7 @@ public:static unsigned int Get_Free_Texture_RAM();static unsigned _Get_Main_Thread_ID() { return _MainThreadID; }- static const D3DADAPTER_IDENTIFIER8& Get_Current_Adapter_Identifier() { return CurrentAdapterIdentifier; }+ static const D3DADAPTER_IDENTIFIER9& Get_Current_Adapter_Identifier() { return CurrentAdapterIdentifier; }/*** Statistics@@ -480,27 +510,27 @@ public:**** swap_chain_ptr->Present (NULL, NULL, NULL, NULL);**- ** DX8Wrapper::Set_Render_Target ((IDirect3DSurface8 *)NULL);+ ** DX8Wrapper::Set_Render_Target ((IDirect3DSurface9 *)NULL);***/- static IDirect3DSwapChain8 * Create_Additional_Swap_Chain (HWND render_window);+ static IDirect3DSwapChain9 * Create_Additional_Swap_Chain (HWND render_window);/*** Render target interface. If render target format is WW3D_FORMAT_UNKNOWN, current display format is used.*/static TextureClass * Create_Render_Target (int width, int height, WW3DFormat format = WW3D_FORMAT_UNKNOWN);- static void Set_Render_Target (IDirect3DSurface8 *render_target, bool use_default_depth_buffer = false);- static void Set_Render_Target (IDirect3DSurface8* render_target, IDirect3DSurface8* dpeth_buffer);+ static void Set_Render_Target (IDirect3DSurface9 *render_target, bool use_default_depth_buffer = false);+ static void Set_Render_Target (IDirect3DSurface9* render_target, IDirect3DSurface9* dpeth_buffer);- static void Set_Render_Target (IDirect3DSwapChain8 *swap_chain);+ static void Set_Render_Target (IDirect3DSwapChain9 *swap_chain);// Samples per pixel to ask the next device for; 0, or 2..16. Set this before Set_Render_Device// or the device is created without multisampling.static void Set_Requested_MultiSample_Level (unsigned samples);// Samples per pixel actually in use, 0 if not multisampling.static unsigned Get_MultiSample_Level (void);// Depth/stencil to use with a non-multisampled render target; NULL if not multisampling.- static IDirect3DSurface8 * _Get_Non_MultiSampled_Depth_Buffer (void);+ static IDirect3DSurface9 * _Get_Non_MultiSampled_Depth_Buffer (void);static bool Is_Render_To_Texture(void) { return IsRenderToTexture; }// for depth map support KJM V@@ -522,8 +552,11 @@ public:// shader system udpates KJM vstatic void Apply_Default_State();- static void Set_Vertex_Shader(DWORD vertex_shader);- static void Set_Pixel_Shader(DWORD pixel_shader);+ // D3D8's SetVertexShader took a DWORD that was either an FVF code or a shader+ // handle, and the engine used it both ways. D3D9 splits them, so these do too.+ static void Set_Vertex_Format(DWORD fvf);+ static void Set_Vertex_Shader(IDirect3DVertexShader9 * vertex_shader);+ static void Set_Pixel_Shader(IDirect3DPixelShader9 * pixel_shader);static void Set_Vertex_Shader_Constant(int reg, const void* data, int count);static void Set_Pixel_Shader_Constant(int reg, const void* data, int count);@@ -538,8 +571,8 @@ public:- static IDirect3DDevice8* _Get_D3D_Device8() { return D3DDevice; }- static IDirect3D8* _Get_D3D8() { return D3DInterface; }+ static IDirect3DDevice9* _Get_D3D_Device() { return D3DDevice; }+ static IDirect3D9* _Get_D3D() { return D3DInterface; }/// Returns the display format - added by TR for video playback - not part of W3Dstatic WW3DFormat getBackBufferFormat( void );static bool Reset_Device(bool reload_assets=true);@@ -551,10 +584,12 @@ public:static const char* Get_DX8_Render_State_Name(D3DRENDERSTATETYPE state);static const char* Get_DX8_Texture_Stage_State_Name(D3DTEXTURESTAGESTATETYPE state);+ static const char* Get_DX8_Sampler_State_Name(D3DSAMPLERSTATETYPE state);static unsigned Get_DX8_Render_State(D3DRENDERSTATETYPE state) { return RenderStates[state]; }// Names of the specific values of render states and texture stage statesstatic void Get_DX8_Texture_Stage_State_Value_Name(StringClass& name, D3DTEXTURESTAGESTATETYPE state, unsigned value);+ static void Get_DX8_Sampler_State_Value_Name(StringClass& name, D3DSAMPLERSTATETYPE state, unsigned value);static void Get_DX8_Render_State_Value_Name(StringClass& name, D3DRENDERSTATETYPE state, unsigned value);static const char* Get_DX8_Texture_Address_Name(unsigned value);@@ -660,8 +695,9 @@ protected:static D3DMATRIX old_prj;// shader system updates KJM v- static DWORD Vertex_Shader;- static DWORD Pixel_Shader;+ static DWORD Vertex_Format;+ static IDirect3DVertexShader9 * Vertex_Shader;+ static IDirect3DPixelShader9 * Pixel_Shader;static Vector4 Vertex_Shader_Constants[MAX_VERTEX_SHADER_CONSTANTS];static Vector4 Pixel_Shader_Constants[MAX_PIXEL_SHADER_CONSTANTS];@@ -679,7 +715,9 @@ protected:static bool world_identity;static unsigned RenderStates[256];static unsigned TextureStageStates[MAX_TEXTURE_STAGES][32];- static IDirect3DBaseTexture8 * Textures[MAX_TEXTURE_STAGES];+ static unsigned SamplerStates[MAX_TEXTURE_STAGES][MAX_SAMPLER_STATES];+ static float DepthBufferEpsilon;+ static IDirect3DBaseTexture9 * Textures[MAX_TEXTURE_STAGES];// These fog settings are constant for all objects in a given scene,// unlike the matching renderstates which vary based on shader settings.@@ -701,15 +739,15 @@ protected:static DX8Caps* CurrentCaps;- static D3DADAPTER_IDENTIFIER8 CurrentAdapterIdentifier;+ static D3DADAPTER_IDENTIFIER9 CurrentAdapterIdentifier;- static IDirect3D8 * D3DInterface; //d3d8;- static IDirect3DDevice8 * D3DDevice; //d3ddevice8;+ static IDirect3D9 * D3DInterface; //d3d8;+ static IDirect3DDevice9 * D3DDevice; //d3ddevice8;- static IDirect3DSurface8 * CurrentRenderTarget;- static IDirect3DSurface8 * CurrentDepthBuffer;- static IDirect3DSurface8 * DefaultRenderTarget;- static IDirect3DSurface8 * DefaultDepthBuffer;+ static IDirect3DSurface9 * CurrentRenderTarget;+ static IDirect3DSurface9 * CurrentDepthBuffer;+ static IDirect3DSurface9 * DefaultRenderTarget;+ static IDirect3DSurface9 * DefaultDepthBuffer;static unsigned DrawPolygonLowBoundLimit;@@ -727,18 +765,28 @@ protected:};// shader system updates KJM v-WWINLINE void DX8Wrapper::Set_Vertex_Shader(DWORD vertex_shader)+WWINLINE void DX8Wrapper::Set_Vertex_Format(DWORD fvf){#if 0 //(gth) some code is bypassing this acessor function so we can't count on this variable...// may be incorrect if shaders are created and destroyed dynamically- if (Vertex_Shader==vertex_shader) return;+ if (Vertex_Format==fvf) return;#endif+ Vertex_Format=fvf;+ // A vertex shader and an FVF are mutually exclusive in D3D9: whichever was set+ // last is the one that describes the stream, so setting a format clears the shader.+ Vertex_Shader=NULL;+ DX8CALL(SetVertexShader(NULL));+ DX8CALL(SetFVF(Vertex_Format));+}++WWINLINE void DX8Wrapper::Set_Vertex_Shader(IDirect3DVertexShader9 * vertex_shader)+{Vertex_Shader=vertex_shader;DX8CALL(SetVertexShader(Vertex_Shader));}-WWINLINE void DX8Wrapper::Set_Pixel_Shader(DWORD pixel_shader)+WWINLINE void DX8Wrapper::Set_Pixel_Shader(IDirect3DPixelShader9 * pixel_shader){// may be incorrect if shaders are created and destroyed dynamicallyif (Pixel_Shader==pixel_shader) return;@@ -755,7 +803,7 @@ WWINLINE void DX8Wrapper::Set_Vertex_Shader_Constant(int reg, const void* data,if (memcmp(data, &Vertex_Shader_Constants[reg],memsize)==0) return;memcpy(&Vertex_Shader_Constants[reg],data,memsize);- DX8CALL(SetVertexShaderConstant(reg,data,count));+ DX8CALL(SetVertexShaderConstantF(reg,(const float*)data,count));}WWINLINE void DX8Wrapper::Set_Pixel_Shader_Constant(int reg, const void* data, int count)@@ -766,7 +814,7 @@ WWINLINE void DX8Wrapper::Set_Pixel_Shader_Constant(int reg, const void* data, iif (memcmp(data, &Pixel_Shader_Constants[reg],memsize)==0) return;memcpy(&Pixel_Shader_Constants[reg],data,memsize);- DX8CALL(SetPixelShaderConstant(reg,data,count));+ DX8CALL(SetPixelShaderConstantF(reg,(const float*)data,count));}// shader system updates KJM ^@@ -857,7 +905,7 @@ WWINLINE void DX8Wrapper::Set_Ambient(const Vector3& color)//// -----------------------------------------------------------------------------WWINLINE void DX8Wrapper::Set_DX8_Material(const D3DMATERIAL8* mat)+WWINLINE void DX8Wrapper::Set_DX8_Material(const D3DMATERIAL9* mat){DX8_RECORD_MATERIAL_CHANGE();WWASSERT(mat);@@ -865,7 +913,7 @@ WWINLINE void DX8Wrapper::Set_DX8_Material(const D3DMATERIAL8* mat)DX8CALL(SetMaterial(mat));}-WWINLINE void DX8Wrapper::Set_DX8_Light(int index, D3DLIGHT8* light)+WWINLINE void DX8Wrapper::Set_DX8_Light(int index, D3DLIGHT9* light){if (light) {DX8_RECORD_LIGHT_CHANGE();@@ -932,7 +980,34 @@ WWINLINE void DX8Wrapper::Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTUREDX8_RECORD_TEXTURE_STAGE_STATE_CHANGE();}-WWINLINE void DX8Wrapper::Set_DX8_Texture(unsigned int stage, IDirect3DBaseTexture8* texture)+// The D3D9 half of the state D3D8 called a texture stage state. Overloaded rather than+// renamed so a call site says which kind it is by the constant it passes, which is the+// only thing that actually changed about it.+WWINLINE void DX8Wrapper::Set_DX8_Texture_Stage_State(unsigned stage, D3DSAMPLERSTATETYPE state, unsigned value)+{+ if (stage >= MAX_TEXTURE_STAGES || (unsigned)state >= MAX_SAMPLER_STATES)+ { DX8CALL(SetSamplerState( stage, state, value ));+ return;+ }++ if (SamplerStates[stage][(unsigned int)state]==value) return;+#ifdef MESH_RENDER_SNAPSHOT_ENABLED+ if (WW3D::Is_Snapshot_Activated()) {+ StringClass value_name(0,true);+ Get_DX8_Sampler_State_Value_Name(value_name,state,value);+ SNAPSHOT_SAY(("DX8 - SetSamplerState(stage: %d, state: %s, value: %s)\n",+ stage,+ Get_DX8_Sampler_State_Name(state),+ value_name));+ }+#endif++ SamplerStates[stage][(unsigned int)state]=value;+ DX8CALL(SetSamplerState( stage, state, value ));+ DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE();+}++WWINLINE void DX8Wrapper::Set_DX8_Texture(unsigned int stage, IDirect3DBaseTexture9* texture){if (stage >= MAX_TEXTURE_STAGES){ DX8CALL(SetTexture(stage, texture));@@ -950,22 +1025,6 @@ WWINLINE void DX8Wrapper::Set_DX8_Texture(unsigned int stage, IDirect3DBaseTextuDX8_RECORD_TEXTURE_CHANGE();}-WWINLINE void DX8Wrapper::_Copy_DX8_Rects(- IDirect3DSurface8* pSourceSurface,- CONST RECT* pSourceRectsArray,- UINT cRects,- IDirect3DSurface8* pDestinationSurface,- CONST POINT* pDestPointsArray-)-{- DX8CALL(CopyRects(- pSourceSurface,- pSourceRectsArray,- cRects,- pDestinationSurface,- pDestPointsArray));-}-WWINLINE Vector4 DX8Wrapper::Convert_Color(unsigned color){Vector4 col;@@ -1270,7 +1329,7 @@ WWINLINE void DX8Wrapper::Set_Projection_Transform_With_Z_Bias(const Matrix4x4&WWINLINE void DX8Wrapper::Set_DX8_ZBias(int zbias){if (zbias==ZBias) return;- if (zbias>15) zbias=15;+ if (zbias>MAX_Z_BIAS_LEVEL) zbias=MAX_Z_BIAS_LEVEL;if (zbias<0) zbias=0;ZBias=zbias;@@ -1283,7 +1342,13 @@ WWINLINE void DX8Wrapper::Set_DX8_ZBias(int zbias)DX8CALL(SetTransform(D3DTS_PROJECTION,(D3DMATRIX*)&tmp));}else {- Set_DX8_Render_State (D3DRS_ZBIAS, ZBias);+ // D3D8's D3DRS_ZBIAS took a level from 0 to 16; D3D9's D3DRS_DEPTHBIAS takes a+ // float in the depth buffer's own normalised range, passed through as a DWORD.+ // The conversion is the one d3d8to9 has been applying under this renderer all+ // along (d3d8types.cpp, CalcDepthBias), so the bias stays where the picture+ // already has it.+ const float depth_bias=ZBias*Get_Depth_Buffer_Epsilon();+ Set_DX8_Render_State(D3DRS_DEPTHBIAS,*(const DWORD*)&depth_bias);}}@@ -1383,7 +1448,7 @@ WWINLINE void DX8Wrapper::Get_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4}}-WWINLINE const D3DLIGHT8& DX8Wrapper::Peek_Light(unsigned index)+WWINLINE const D3DLIGHT9& DX8Wrapper::Peek_Light(unsigned index){return render_state.Lights[index];;}@@ -1526,7 +1591,7 @@ WWINLINE RenderStateStruct& RenderStateStruct::operator= (const RenderStateStruc}- //lightsHash = flimby((char*)(&Lights[0]), sizeof(D3DLIGHT8)-1 );+ //lightsHash = flimby((char*)(&Lights[0]), sizeof(D3DLIGHT9)-1 );}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/formconv.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/formconv.hindex 43e106db0..a057c1d41 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/formconv.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/formconv.h@@ -45,7 +45,7 @@#define FORMCONV_H#include "ww3dformat.h"-#include <d3d8.h>+#include <d3d9.h>/*** This file is used for conversions between D3DFORMAT and WW3DFormat.diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.cppindex b9715bc90..5a1151225 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.cpp@@ -20,7 +20,7 @@#include "missingtexture.h"#include "texture.h"#include "dx8wrapper.h"-#include <D3dx8core.h>+#include "d3dx9runtime.h"static unsigned missing_image_width=128;static unsigned missing_image_height=128;@@ -29,9 +29,9 @@ static unsigned missing_image_depth=24;extern unsigned int missing_image_palette[];extern unsigned int missing_image_pixels[];-static IDirect3DTexture8 * _MissingTexture = NULL;+static IDirect3DTexture9 * _MissingTexture = NULL;-IDirect3DTexture8* MissingTexture::_Get_Missing_Texture()+IDirect3DTexture9* MissingTexture::_Get_Missing_Texture(){// The stand-in checkerboard is a D3D texture built when the device was created. A run with no// device never built one, and every texture load in it ends up here, so hand back nothing@@ -44,25 +44,27 @@ IDirect3DTexture8* MissingTexture::_Get_Missing_Texture()return _MissingTexture;}-IDirect3DSurface8* MissingTexture::_Create_Missing_Surface()+IDirect3DSurface9* MissingTexture::_Create_Missing_Surface(){if (_MissingTexture == NULL) {return NULL;}- IDirect3DSurface8 *texture_surface = NULL;+ IDirect3DSurface9 *texture_surface = NULL;DX8_ErrorCode(_MissingTexture->GetSurfaceLevel(0, &texture_surface));D3DSURFACE_DESC texture_surface_desc;::ZeroMemory(&texture_surface_desc, sizeof(D3DSURFACE_DESC));DX8_ErrorCode(texture_surface->GetDesc(&texture_surface_desc));- IDirect3DSurface8 *surface = NULL;- DX8CALL(CreateImageSurface(- texture_surface_desc.Width,- texture_surface_desc.Height,- texture_surface_desc.Format,- &surface));- DX8CALL(CopyRects(texture_surface, NULL, 0, surface, NULL));+ IDirect3DSurface9 *surface = NULL;+ DX8CALL(CreateOffscreenPlainSurface(+ texture_surface_desc.Width,+ texture_surface_desc.Height,+ texture_surface_desc.Format,+ D3DPOOL_SYSTEMMEM,+ &surface,+ NULL));+ DX8Wrapper::_Copy_DX8_Rects(texture_surface, NULL, 0, surface, NULL);texture_surface->Release();return surface;}@@ -71,7 +73,7 @@ void MissingTexture::_Init(){WWASSERT(!_MissingTexture);- IDirect3DTexture8* tex=DX8Wrapper::_Create_DX8_Texture+ IDirect3DTexture9* tex=DX8Wrapper::_Create_DX8_Texture(missing_image_width,missing_image_height,@@ -108,7 +110,7 @@ void MissingTexture::_Init()DX8_ErrorCode(tex->UnlockRect(0));for (unsigned i=1;i<tex->GetLevelCount();++i) {- IDirect3DSurface8 *src,*dst;+ IDirect3DSurface9 *src,*dst;DX8_ErrorCode(tex->GetSurfaceLevel(i-1,&src));DX8_ErrorCode(tex->GetSurfaceLevel(i,&dst));diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.hindex 99c294980..05de0c78a 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/missingtexture.h@@ -25,8 +25,8 @@#include "always.h"-struct IDirect3DTexture8;-struct IDirect3DSurface8;+struct IDirect3DTexture9;+struct IDirect3DSurface9;class MissingTexture{@@ -34,8 +34,8 @@ public:static void _Init();static void _Deinit();- static IDirect3DTexture8* _Get_Missing_Texture(); // Return a reference to missing texture- static IDirect3DSurface8* _Create_Missing_Surface(); // Create new surface which contain missing texture image+ static IDirect3DTexture9* _Get_Missing_Texture(); // Return a reference to missing texture+ static IDirect3DSurface9* _Create_Missing_Surface(); // Create new surface which contain missing texture image};diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cppindex 7f8bb0139..4aa496467 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cpp@@ -86,7 +86,7 @@#include "rinfo.h"#include "camera.h"#include "dx8fvf.h"-#include "D3DXMath.h"+#include "d3dx9math.h"#include "sortingrenderer.h"// Upgraded to DX8 2/2/01 HYdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rddesc.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rddesc.hindex d1c6242aa..3426b3337 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rddesc.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rddesc.h@@ -44,8 +44,8 @@#include "vector.h"#include "wwstring.h"-#include <d3d8types.h>-#include <d3d8caps.h>+#include <d3d9types.h>+#include <d3d9caps.h>class ResolutionDescClass{@@ -110,8 +110,8 @@ public:const char * Get_Hardware_Chipset() const { return HardwareChipset; }const DynamicVectorClass<ResolutionDescClass> & Enumerate_Resolutions(void) const { return ResArray; }- const D3DCAPS8& Get_Caps() const { return Caps; }- const D3DADAPTER_IDENTIFIER8& Get_Adapter_Identifier() const { return AdapterIdentifier; }+ const D3DCAPS9& Get_Caps() const { return Caps; }+ const D3DADAPTER_IDENTIFIER9& Get_Adapter_Identifier() const { return AdapterIdentifier; }private:@@ -140,8 +140,8 @@ private:StringClass HardwareVendor;StringClass HardwareChipset;- D3DCAPS8 Caps;- D3DADAPTER_IDENTIFIER8 AdapterIdentifier;+ D3DCAPS9 Caps;+ D3DADAPTER_IDENTIFIER9 AdapterIdentifier;DynamicVectorClass<ResolutionDescClass> ResArray;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cppindex f28891a79..98d7a78f3 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp@@ -620,7 +620,7 @@ void Render2DClass::Render(void)int width, height, bits;bool windowed;WW3D::Get_Device_Resolution( width, height, bits, windowed );- D3DVIEWPORT8 vp = { 0 };+ D3DVIEWPORT9 vp = { 0 };vp.X = 0;vp.Y = 0;vp.Width = width;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cppindex b8b745397..2e48d37e0 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp@@ -1185,7 +1185,7 @@ Render2DSentenceClass::Build_Sentence (const WCHAR *text, int *hkX, int *hkY)// CreateImageSurface of a null device and take the process with it. Measure the text and stop// there, which is what justCalcExtents already exists to do - callers size their windows off// the extent and nothing is ever asked to draw the result.- if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ if (DX8Wrapper::_Get_D3D_Device() == NULL) {Build_Sentence_Not_Centered(text, hkX, hkY, true);return;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/scene.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/scene.cppindex 8bb0ddcc4..d965368e2 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/scene.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/scene.cpp@@ -223,20 +223,20 @@ void SceneClass::Render(RenderInfoClass & rinfo)else {bool old_enable=WW3D::Is_Texturing_Enabled();- DX8Wrapper::Set_DX8_Render_State (D3DRS_ZBIAS, 0);+ DX8Wrapper::Set_DX8_ZBias(0);Customized_Render(rinfo);switch (Get_Extra_Pass_Polygon_Mode()) {case EXTRA_PASS_LINE:WW3D::Enable_Texturing(false);DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_WIREFRAME);- DX8Wrapper::Set_DX8_Render_State (D3DRS_ZBIAS, 7);+ DX8Wrapper::Set_DX8_ZBias(7);Customized_Render(rinfo);break;case EXTRA_PASS_CLEAR_LINE:DX8Wrapper::Clear(true, false, Vector3(0.0f,0.0f,0.0f)); // Clear color but not zWW3D::Enable_Texturing(false);DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_WIREFRAME);- DX8Wrapper::Set_DX8_Render_State (D3DRS_ZBIAS, 7);+ DX8Wrapper::Set_DX8_ZBias(7);Customized_Render(rinfo);break;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/shader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/shader.cppindex 0d4ebfaa1..c242d2454 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/shader.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/shader.cpp@@ -1029,12 +1029,11 @@ void ShaderClass::Apply()// CULLMODEDX8Wrapper::Set_DX8_Render_State(D3DRS_CULLMODE,Get_Cull_Mode() ? _PolygonCullMode : D3DCULL_NONE);- // NPATCHES- if (diff&ShaderClass::MASK_NPATCHENABLE) {- float level=1.0f;- if (Get_NPatch_Enable()) level=float(WW3D::Get_NPatches_Level());- DX8Wrapper::Set_DX8_Render_State(D3DRS_PATCHSEGMENTS,*((DWORD*)&level));- }+ // NPATCHES. D3D9 dropped N-patch tessellation and D3DRS_PATCHSEGMENTS with it, and+ // the state was already inert under d3d8to9, which answered a read of it with 1 and+ // passed a write to a D3D9 runtime that has no such state. Nothing draws differently+ // for its removal; MASK_NPATCHENABLE and Get_NPatches_Level stay, because the shader+ // bit is serialised in W3D assets and the level is an option the menu still writes.// Enable/disable alpha testDX8Wrapper::Set_DX8_Render_State(D3DRS_ALPHATESTENABLE,BOOL(Get_Alpha_Test()));diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cppindex d5bfff458..cd90432e5 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp@@ -44,8 +44,8 @@#include "dx8wrapper.h"#include "vertmaterial.h"#include "texture.h"-#include "d3d8.h"-#include "D3dx8math.h"+#include <d3d9.h>+#include "d3dx9math.h"#include "statistics.h"#include <wwprofile.h>#include <algorithm>diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/surfaceclass.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/surfaceclass.cppindex 25db8c05e..db49e8fb6 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/surfaceclass.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/surfaceclass.cpp@@ -54,7 +54,7 @@#include "vector2i.h"#include "colorspace.h"#include "bound.h"-#include <d3dx8.h>+#include "d3dx9runtime.h"/************************************************************************************************ PixelSize -- Helper Function to find the size in bytes of a pixel *@@ -230,7 +230,7 @@ SurfaceClass::SurfaceClass(const char *filename):SurfaceFormat=desc.Format;}-SurfaceClass::SurfaceClass(IDirect3DSurface8 *d3d_surface) :+SurfaceClass::SurfaceClass(IDirect3DSurface9 *d3d_surface) :D3DSurface (NULL){Attach (d3d_surface);@@ -744,7 +744,7 @@ void SurfaceClass::Get_Pixel(Vector3 &rgb, int x,int y)* HISTORY: ** 3/27/2001 pds : Created. **=============================================================================================*/-void SurfaceClass::Attach (IDirect3DSurface8 *surface)+void SurfaceClass::Attach (IDirect3DSurface9 *surface){Detach ();D3DSurface = surface;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/surfaceclass.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/surfaceclass.hindex 0372ed5d5..d2a458488 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/surfaceclass.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/surfaceclass.h@@ -46,14 +46,14 @@#include "ww3dformat.h"#include "refcount.h"-struct IDirect3DSurface8;+struct IDirect3DSurface9;class Vector2i;class Vector3;/*************************************************************************** SurfaceClass**-** This is our surface class, which wraps IDirect3DSurface8.+** This is our surface class, which wraps IDirect3DSurface9.**** Hector Yee 2/12/01 - added in fills, blits etc for font3d class**@@ -76,7 +76,7 @@ class SurfaceClass : public W3DMPO, public RefCountClassSurfaceClass(const char *filename);// Create the surface from a D3D pointer- SurfaceClass(IDirect3DSurface8 *d3d_surface);+ SurfaceClass(IDirect3DSurface9 *d3d_surface);~SurfaceClass(void);@@ -120,10 +120,10 @@ class SurfaceClass : public W3DMPO, public RefCountClassunsigned char *CreateCopy(int *width,int *height,int*size,bool flip=false);// For use by TextureClass:- IDirect3DSurface8 *Peek_D3D_Surface(void) { return D3DSurface; }+ IDirect3DSurface9 *Peek_D3D_Surface(void) { return D3DSurface; }// Attaching and detaching a surface pointer- void Attach (IDirect3DSurface8 *surface);+ void Attach (IDirect3DSurface9 *surface);void Detach (void);// draws a horizontal line@@ -154,7 +154,7 @@ class SurfaceClass : public W3DMPO, public RefCountClassprivate:// Direct3D surface object- IDirect3DSurface8 *D3DSurface;+ IDirect3DSurface9 *D3DSurface;WW3DFormat SurfaceFormat;friend class TextureClass;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texproject.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texproject.cppindex 664738583..fc29f467f 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texproject.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texproject.cpp@@ -1163,7 +1163,7 @@ bool TexProjectClass::Compute_TextureWW3D::End_Render(false);WW3D::Activate_Snapshot(snapshot); // End_Render() ends the shapsnot, so restore the state- DX8Wrapper::Set_Render_Target((IDirect3DSurface8 *)NULL);+ DX8Wrapper::Set_Render_Target((IDirect3DSurface9 *)NULL);}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cppindex 5e9a3db60..7e3d25675 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cpp@@ -41,9 +41,9 @@#include "texture.h"-#include <d3d8.h>+#include <d3d9.h>#include <stdio.h>-#include <D3dx8core.h>+#include "d3dx9runtime.h"#include "dx8wrapper.h"#include "targa.h"#include <nstrdup.h>@@ -85,14 +85,14 @@ const unsigned MAX_TEXTURES_APPLIED_PER_FRAME=2;* uninitialized pointer. Three of them then never released the reference GetSurfaceLevel had* taken, so a procedural texture pinned its own surface for the life of the process.*/-static bool Describe_Texture_Level_0(IDirect3DTexture8 *texture, D3DSURFACE_DESC &desc)+static bool Describe_Texture_Level_0(IDirect3DTexture9 *texture, D3DSURFACE_DESC &desc){::ZeroMemory(&desc, sizeof(D3DSURFACE_DESC));if (texture == NULL)return false;- IDirect3DSurface8 *surface = NULL;+ IDirect3DSurface9 *surface = NULL;DX8_ErrorCode(texture->GetSurfaceLevel(0, &surface));if (surface == NULL)return false;@@ -283,7 +283,7 @@ void TextureBaseClass::Invalidate()//! Returns a pointer to the d3d texture/*!*/-IDirect3DBaseTexture8 * TextureBaseClass::Peek_D3D_Base_Texture() const+IDirect3DBaseTexture9 * TextureBaseClass::Peek_D3D_Base_Texture() const{LastAccessed=WW3D::Get_Sync_Time();return D3DTexture;@@ -293,7 +293,7 @@ IDirect3DBaseTexture8 * TextureBaseClass::Peek_D3D_Base_Texture() const//! Set the d3d texture pointer. Handles ref counts properly./*!*/-void TextureBaseClass::Set_D3D_Base_Texture(IDirect3DBaseTexture8* tex)+void TextureBaseClass::Set_D3D_Base_Texture(IDirect3DBaseTexture9* tex){// (gth) Generals does stuff directly with the D3DTexture pointer so lets// reset the access timer whenever someon messes with this pointer.@@ -330,7 +330,7 @@ void TextureBaseClass::Load_Locked_Surface()bool TextureBaseClass::Is_Missing_Texture(){bool flag = false;- IDirect3DBaseTexture8 *missing_texture = MissingTexture::_Get_Missing_Texture();+ IDirect3DBaseTexture9 *missing_texture = MissingTexture::_Get_Missing_Texture();if (D3DTexture == missing_texture)flag = true;@@ -832,7 +832,7 @@ TextureClass::TextureClass}// -----------------------------------------------------------------------------TextureClass::TextureClass(IDirect3DBaseTexture8* d3d_texture)+TextureClass::TextureClass(IDirect3DBaseTexture9* d3d_texture): TextureBaseClass(0,@@ -920,12 +920,12 @@ void TextureClass::Init()*/void TextureClass::Apply_New_Surface(- IDirect3DBaseTexture8* d3d_texture,+ IDirect3DBaseTexture9* d3d_texture,bool initialized,bool disable_auto_invalidation){- IDirect3DBaseTexture8* d3d_tex=Peek_D3D_Base_Texture();+ IDirect3DBaseTexture9* d3d_tex=Peek_D3D_Base_Texture();if (d3d_tex) d3d_tex->Release();@@ -1021,7 +1021,7 @@ SurfaceClass *TextureClass::Get_Surface_Level(unsigned int level)return 0;}- IDirect3DSurface8 *d3d_surface = NULL;+ IDirect3DSurface9 *d3d_surface = NULL;DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(level, &d3d_surface));SurfaceClass *surface = new SurfaceClass(d3d_surface);d3d_surface->Release();@@ -1046,7 +1046,7 @@ void TextureClass::Get_Level_Description( SurfaceClass::SurfaceDescription & des//! Get D3D surface from mip level/*!*/-IDirect3DSurface8 *TextureClass::Get_D3D_Surface_Level(unsigned int level)+IDirect3DSurface9 *TextureClass::Get_D3D_Surface_Level(unsigned int level){if (!Peek_D3D_Texture()){@@ -1054,7 +1054,7 @@ IDirect3DSurface8 *TextureClass::Get_D3D_Surface_Level(unsigned int level)return 0;}- IDirect3DSurface8 *d3d_surface = NULL;+ IDirect3DSurface9 *d3d_surface = NULL;DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(level, &d3d_surface));return d3d_surface;}@@ -1071,7 +1071,11 @@ unsigned TextureClass::Get_Texture_Memory_Usage() const{D3DSURFACE_DESC desc;DX8_ErrorCode(Peek_D3D_Texture()->GetLevelDesc(i,&desc));- size+=desc.Size;+ // D3D8's surface description carried a byte size; D3D9's does not, so the level+ // is measured the way it was allocated. A compressed format reports 0 bytes per+ // pixel here and contributes nothing, which is what this counter did for DXT+ // surfaces under D3D8 as well.+ size+=desc.Width*desc.Height*Get_Bytes_Per_Pixel(D3DFormat_To_WW3DFormat(desc.Format));}return size;}@@ -1304,12 +1308,12 @@ void ZTextureClass::Apply(unsigned int stage)*/void ZTextureClass::Apply_New_Surface(- IDirect3DBaseTexture8* d3d_texture,+ IDirect3DBaseTexture9* d3d_texture,bool initialized,bool disable_auto_invalidation){- IDirect3DBaseTexture8* d3d_tex=Peek_D3D_Base_Texture();+ IDirect3DBaseTexture9* d3d_tex=Peek_D3D_Base_Texture();if (d3d_tex) d3d_tex->Release();@@ -1333,7 +1337,7 @@ void ZTextureClass::Apply_New_Surface//! Get D3D surface from mip level/*!*/-IDirect3DSurface8* ZTextureClass::Get_D3D_Surface_Level(unsigned int level)+IDirect3DSurface9* ZTextureClass::Get_D3D_Surface_Level(unsigned int level){if (!Peek_D3D_Texture()){@@ -1341,7 +1345,7 @@ IDirect3DSurface8* ZTextureClass::Get_D3D_Surface_Level(unsigned int level)return 0;}- IDirect3DSurface8 *d3d_surface = NULL;+ IDirect3DSurface9 *d3d_surface = NULL;DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(level, &d3d_surface));return d3d_surface;}@@ -1358,7 +1362,11 @@ unsigned ZTextureClass::Get_Texture_Memory_Usage() const{D3DSURFACE_DESC desc;DX8_ErrorCode(Peek_D3D_Texture()->GetLevelDesc(i,&desc));- size+=desc.Size;+ // D3D8's surface description carried a byte size; D3D9's does not, so the level+ // is measured the way it was allocated. A compressed format reports 0 bytes per+ // pixel here and contributes nothing, which is what this counter did for DXT+ // surfaces under D3D8 as well.+ size+=desc.Width*desc.Height*Get_Bytes_Per_Pixel(D3DFormat_To_WW3DFormat(desc.Format));}return size;}@@ -1574,7 +1582,7 @@ CubeTextureClass::CubeTextureClass}// -----------------------------------------------------------------------------CubeTextureClass::CubeTextureClass(IDirect3DBaseTexture8* d3d_texture)+CubeTextureClass::CubeTextureClass(IDirect3DBaseTexture9* d3d_texture): TextureBaseClass(0,@@ -1617,12 +1625,12 @@ CubeTextureClass::CubeTextureClass(IDirect3DBaseTexture8* d3d_texture)*/void CubeTextureClass::Apply_New_Surface(- IDirect3DBaseTexture8* d3d_texture,+ IDirect3DBaseTexture9* d3d_texture,bool initialized,bool disable_auto_invalidation){- IDirect3DBaseTexture8* d3d_tex=Peek_D3D_Base_Texture();+ IDirect3DBaseTexture9* d3d_tex=Peek_D3D_Base_Texture();if (d3d_tex) d3d_tex->Release();@@ -1858,7 +1866,7 @@ CubeTextureClass::CubeTextureClass}// -----------------------------------------------------------------------------CubeTextureClass::CubeTextureClass(IDirect3DBaseTexture8* d3d_texture)+CubeTextureClass::CubeTextureClass(IDirect3DBaseTexture9* d3d_texture): TextureBaseClass(0,@@ -1904,12 +1912,12 @@ CubeTextureClass::CubeTextureClass(IDirect3DBaseTexture8* d3d_texture)*/void VolumeTextureClass::Apply_New_Surface(- IDirect3DBaseTexture8* d3d_texture,+ IDirect3DBaseTexture9* d3d_texture,bool initialized,bool disable_auto_invalidation){- IDirect3DBaseTexture8* d3d_tex=Peek_D3D_Base_Texture();+ IDirect3DBaseTexture9* d3d_tex=Peek_D3D_Base_Texture();if (d3d_tex) d3d_tex->Release();diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.hindex fe2b444b0..e61255acb 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.h@@ -56,10 +56,10 @@#include "vector3.h"#include "texturefilter.h"-struct IDirect3DBaseTexture8;-struct IDirect3DTexture8;-struct IDirect3DCubeTexture8;-struct IDirect3DVolumeTexture8;+struct IDirect3DBaseTexture9;+struct IDirect3DTexture9;+struct IDirect3DCubeTexture9;+struct IDirect3DVolumeTexture9;class DX8Wrapper;class TextureLoader;@@ -162,8 +162,8 @@ public:void Invalidate();// texture accessors (dx8)- IDirect3DBaseTexture8 *Peek_D3D_Base_Texture() const;- void Set_D3D_Base_Texture(IDirect3DBaseTexture8* tex);+ IDirect3DBaseTexture9 *Peek_D3D_Base_Texture() const;+ void Set_D3D_Base_Texture(IDirect3DBaseTexture9* tex);PoolType Get_Pool() const { return Pool; }@@ -182,7 +182,7 @@ public:unsigned Get_Reduction() const;// Background texture loader will call this when texture has been loaded- virtual void Apply_New_Surface(IDirect3DBaseTexture8* tex, bool initialized, bool disable_auto_invalidation = false)=0; // If the parameter is true, the texture will be flagged as initialised+ virtual void Apply_New_Surface(IDirect3DBaseTexture9* tex, bool initialized, bool disable_auto_invalidation = false)=0; // If the parameter is true, the texture will be flagged as initialisedMipCountType MipLevelCount;@@ -202,14 +202,14 @@ public:virtual CubeTextureClass* As_CubeTextureClass() { return NULL; }virtual VolumeTextureClass* As_VolumeTextureClass() { return NULL; }- IDirect3DTexture8* Peek_D3D_Texture() const { return (IDirect3DTexture8*)Peek_D3D_Base_Texture(); }- IDirect3DVolumeTexture8* Peek_D3D_VolumeTexture() const { return (IDirect3DVolumeTexture8*)Peek_D3D_Base_Texture(); }- IDirect3DCubeTexture8* Peek_D3D_CubeTexture() const { return (IDirect3DCubeTexture8*)Peek_D3D_Base_Texture(); }+ IDirect3DTexture9* Peek_D3D_Texture() const { return (IDirect3DTexture9*)Peek_D3D_Base_Texture(); }+ IDirect3DVolumeTexture9* Peek_D3D_VolumeTexture() const { return (IDirect3DVolumeTexture9*)Peek_D3D_Base_Texture(); }+ IDirect3DCubeTexture9* Peek_D3D_CubeTexture() const { return (IDirect3DCubeTexture9*)Peek_D3D_Base_Texture(); }protected:void Load_Locked_Surface();- void Poke_Texture(IDirect3DBaseTexture8* tex) { D3DTexture = tex; }+ void Poke_Texture(IDirect3DBaseTexture9* tex) { D3DTexture = tex; }bool Initialized;@@ -236,7 +236,7 @@ protected:private:// Direct3D texture object- IDirect3DBaseTexture8 *D3DTexture;+ IDirect3DBaseTexture9 *D3DTexture;// NameStringClass Name;@@ -306,7 +306,7 @@ public:MipCountType mip_level_count=MIP_LEVELS_ALL);- TextureClass(IDirect3DBaseTexture8* d3d_texture);+ TextureClass(IDirect3DBaseTexture9* d3d_texture);// defualt constructors for derived classes (cube & vol)TextureClass@@ -326,11 +326,11 @@ public:virtual void Init();// Background texture loader will call this when texture has been loaded- virtual void Apply_New_Surface(IDirect3DBaseTexture8* tex, bool initialized, bool disable_auto_invalidation = false); // If the parameter is true, the texture will be flagged as initialised+ virtual void Apply_New_Surface(IDirect3DBaseTexture9* tex, bool initialized, bool disable_auto_invalidation = false); // If the parameter is true, the texture will be flagged as initialised// Get the surface of one of the mipmap levels (defaults to highest-resolution one)SurfaceClass *Get_Surface_Level(unsigned int level = 0);- IDirect3DSurface8 *Get_D3D_Surface_Level(unsigned int level = 0);+ IDirect3DSurface9 *Get_D3D_Surface_Level(unsigned int level = 0);void Get_Level_Description( SurfaceClass::SurfaceDescription & desc, unsigned int level = 0 );TextureFilterClass& Get_Filter() { return Filter; }@@ -371,11 +371,11 @@ public:virtual void Init() {}// Background texture loader will call this when texture has been loaded- virtual void Apply_New_Surface(IDirect3DBaseTexture8* tex, bool initialized, bool disable_auto_invalidation = false); // If the parameter is true, the texture will be flagged as initialised+ virtual void Apply_New_Surface(IDirect3DBaseTexture9* tex, bool initialized, bool disable_auto_invalidation = false); // If the parameter is true, the texture will be flagged as initialisedvirtual void Apply(unsigned int stage);- IDirect3DSurface8 *Get_D3D_Surface_Level(unsigned int level = 0);+ IDirect3DSurface9 *Get_D3D_Surface_Level(unsigned int level = 0);virtual unsigned Get_Texture_Memory_Usage() const;private:@@ -418,9 +418,9 @@ public:MipCountType mip_level_count=MIP_LEVELS_ALL);- CubeTextureClass(IDirect3DBaseTexture8* d3d_texture);+ CubeTextureClass(IDirect3DBaseTexture9* d3d_texture);- virtual void Apply_New_Surface(IDirect3DBaseTexture8* tex, bool initialized, bool disable_auto_invalidation = false); // If the parameter is true, the texture will be flagged as initialised+ virtual void Apply_New_Surface(IDirect3DBaseTexture9* tex, bool initialized, bool disable_auto_invalidation = false); // If the parameter is true, the texture will be flagged as initialisedvirtual TexAssetType Get_Asset_Type() const { return TEX_CUBEMAP; }@@ -464,9 +464,9 @@ public:MipCountType mip_level_count=MIP_LEVELS_ALL);- VolumeTextureClass(IDirect3DBaseTexture8* d3d_texture);+ VolumeTextureClass(IDirect3DBaseTexture9* d3d_texture);- virtual void Apply_New_Surface(IDirect3DBaseTexture8* tex, bool initialized, bool disable_auto_invalidation = false); // If the parameter is true, the texture will be flagged as initialised+ virtual void Apply_New_Surface(IDirect3DBaseTexture9* tex, bool initialized, bool disable_auto_invalidation = false); // If the parameter is true, the texture will be flagged as initialisedvirtual TexAssetType Get_Asset_Type() const { return TEX_VOLUME; }diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texturefilter.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texturefilter.cppindex d3dfbfe54..255b2e53f 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texturefilter.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texturefilter.cpp@@ -83,29 +83,29 @@ TextureFilterClass::TextureFilterClass(MipCountType mip_level_count=MIP_LEVELS_1*/void TextureFilterClass::Apply(unsigned int stage){- DX8Wrapper::Set_DX8_Texture_Stage_State(stage,D3DTSS_MINFILTER,_MinTextureFilters[stage][TextureMinFilter]);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage,D3DTSS_MAGFILTER,_MagTextureFilters[stage][TextureMagFilter]);- DX8Wrapper::Set_DX8_Texture_Stage_State(stage,D3DTSS_MIPFILTER,_MipMapFilters[stage][MipMapFilter]);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage,D3DSAMP_MINFILTER,_MinTextureFilters[stage][TextureMinFilter]);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage,D3DSAMP_MAGFILTER,_MagTextureFilters[stage][TextureMagFilter]);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage,D3DSAMP_MIPFILTER,_MipMapFilters[stage][MipMapFilter]);switch (Get_U_Addr_Mode()){case TEXTURE_ADDRESS_REPEAT:- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);break;case TEXTURE_ADDRESS_CLAMP:- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);break;}switch (Get_V_Addr_Mode()){case TEXTURE_ADDRESS_REPEAT:- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);break;case TEXTURE_ADDRESS_CLAMP:- DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);break;}}@@ -116,7 +116,7 @@ void TextureFilterClass::Apply(unsigned int stage)*/void TextureFilterClass::_Init_Filters(TextureFilterMode filter_type){- const D3DCAPS8& dx8caps=DX8Wrapper::Get_Current_Caps()->Get_DX8_Caps();+ const D3DCAPS9& dx8caps=DX8Wrapper::Get_Current_Caps()->Get_DX8_Caps();#ifndef _XBOX_MinTextureFilters[0][FILTER_TYPE_NONE]=D3DTEXF_POINT;@@ -219,7 +219,7 @@ void TextureFilterClass::_Init_Filters(TextureFilterMode filter_type)_MagTextureFilters[i][FILTER_TYPE_DEFAULT]=_MagTextureFilters[i][FILTER_TYPE_BEST];_MipMapFilters[i][FILTER_TYPE_DEFAULT]=_MipMapFilters[i][FILTER_TYPE_BEST];- DX8Wrapper::Set_DX8_Texture_Stage_State(i,D3DTSS_MAXANISOTROPY,maxAnisotropy);+ DX8Wrapper::Set_DX8_Texture_Stage_State(i,D3DSAMP_MAXANISOTROPY,maxAnisotropy);}}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cppindex 113cefcd1..fcd13113b 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp@@ -53,7 +53,7 @@#include "dx8caps.h"#include "missingtexture.h"#include "targa.h"-#include <D3dx8tex.h>+#include "d3dx9runtime.h"#include <cstdio>#include "wwmemlog.h"#include "texture.h"@@ -254,7 +254,7 @@ public:// TODO: Legacy - remove this call!-IDirect3DTexture8* Load_Compressed_Texture(+IDirect3DTexture9* Load_Compressed_Texture(const StringClass& filename,unsigned reduction_factor,MipCountType mip_level_count,@@ -274,7 +274,7 @@ IDirect3DTexture8* Load_Compressed_Texture(// Note that the nearest valid format could be anything, even uncompressed.if (dest_format==WW3D_FORMAT_UNKNOWN) dest_format=Get_Valid_Texture_Format(dds_file.Get_Format(),true);- IDirect3DTexture8* d3d_texture = DX8Wrapper::_Create_DX8_Texture+ IDirect3DTexture9* d3d_texture = DX8Wrapper::_Create_DX8_Texture(width,height,@@ -283,7 +283,7 @@ IDirect3DTexture8* Load_Compressed_Texture();for (unsigned level=0;level<mips;++level) {- IDirect3DSurface8* d3d_surface=NULL;+ IDirect3DSurface9* d3d_surface=NULL;WWASSERT(d3d_texture);DX8_ErrorCode(d3d_texture->GetSurfaceLevel(level/*-reduction_factor*/,&d3d_surface));dds_file.Copy_Level_To_Surface(level,d3d_surface);@@ -386,11 +386,11 @@ void TextureLoader::Validate_Texture_Size// The whole of this is a clamp against what the device can hold, and with no device there is// nothing to clamp against - Get_Current_Caps has nothing to return. Leave the sizes as asked:// nothing in such a run allocates the surface they describe anyway.- if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ if (DX8Wrapper::_Get_D3D_Device() == NULL) {return;}- const D3DCAPS8& dx8caps=DX8Wrapper::Get_Current_Caps()->Get_DX8_Caps();+ const D3DCAPS9& dx8caps=DX8Wrapper::Get_Current_Caps()->Get_DX8_Caps();unsigned poweroftwowidth = 1;while (poweroftwowidth < width)@@ -451,7 +451,7 @@ void TextureLoader::Validate_Texture_Sizedepth=poweroftwodepth;}-IDirect3DTexture8* TextureLoader::Load_Thumbnail(const StringClass& filename, const Vector3& hsv_shift)//,WW3DFormat texture_format)+IDirect3DTexture9* TextureLoader::Load_Thumbnail(const StringClass& filename, const Vector3& hsv_shift)//,WW3DFormat texture_format){WWASSERT(Is_DX8_Thread());@@ -475,7 +475,7 @@ IDirect3DTexture8* TextureLoader::Load_Thumbnail(const StringClass& filename, coWWASSERT(dest_format==texture_format);}- IDirect3DTexture8* sysmem_texture = DX8Wrapper::_Create_DX8_Texture(+ IDirect3DTexture9* sysmem_texture = DX8Wrapper::_Create_DX8_Texture(thumb->Get_Width(),thumb->Get_Height(),dest_format,@@ -535,7 +535,7 @@ IDirect3DTexture8* TextureLoader::Load_Thumbnail(const StringClass& filename, co#ifdef USE_MANAGED_TEXTURESreturn sysmem_texture;#else- IDirect3DTexture8* d3d_texture = DX8Wrapper::_Create_DX8_Texture(+ IDirect3DTexture9* d3d_texture = DX8Wrapper::_Create_DX8_Texture(thumb->Get_Width(),thumb->Get_Height(),dest_format,@@ -557,7 +557,7 @@ IDirect3DTexture8* TextureLoader::Load_Thumbnail(const StringClass& filename, co// format and performs color space conversion.//// -----------------------------------------------------------------------------IDirect3DSurface8* TextureLoader::Load_Surface_Immediate(+IDirect3DSurface9* TextureLoader::Load_Surface_Immediate(const StringClass& filename,WW3DFormat texture_format,bool allow_compression)@@ -567,9 +567,9 @@ IDirect3DSurface8* TextureLoader::Load_Surface_Immediate(bool compressed=Is_Format_Compressed(texture_format,allow_compression);if (compressed) {- IDirect3DTexture8* comp_tex=Load_Compressed_Texture(filename,0,MIP_LEVELS_1,WW3D_FORMAT_UNKNOWN);+ IDirect3DTexture9* comp_tex=Load_Compressed_Texture(filename,0,MIP_LEVELS_1,WW3D_FORMAT_UNKNOWN);if (comp_tex) {- IDirect3DSurface8* d3d_surface=NULL;+ IDirect3DSurface9* d3d_surface=NULL;DX8_ErrorCode(comp_tex->GetSurfaceLevel(0,&d3d_surface));comp_tex->Release();return d3d_surface;@@ -634,7 +634,7 @@ IDirect3DSurface8* TextureLoader::Load_Surface_Immediate(unsigned src_pitch=src_width*src_bpp;- IDirect3DSurface8* d3d_surface = DX8Wrapper::_Create_DX8_Surface(width,height,dest_format);+ IDirect3DSurface9* d3d_surface = DX8Wrapper::_Create_DX8_Surface(width,height,dest_format);WWASSERT(d3d_surface);D3DLOCKED_RECT locked_rect;DX8_ErrorCode(@@ -669,7 +669,7 @@ IDirect3DSurface8* TextureLoader::Load_Surface_Immediate(void TextureLoader::Request_Thumbnail(TextureBaseClass *tc){// See Request_Foreground_Loading: nothing to load into without a device.- if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ if (DX8Wrapper::_Get_D3D_Device() == NULL) {return;}@@ -717,7 +717,7 @@ void TextureLoader::Request_Background_Loading(TextureBaseClass *tc)WWPROFILE(("TextureLoader::Request_Background_Loading()"));// See Request_Foreground_Loading: nothing to load into without a device.- if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ if (DX8Wrapper::_Get_D3D_Device() == NULL) {return;}@@ -756,7 +756,7 @@ void TextureLoader::Request_Foreground_Loading(TextureBaseClass *tc)// A run with no render device has nowhere to put a texture, and no missing-texture stand-in to// fall back on either - that one is built when the device is. Leaving the texture// uninitialised is correct here: nothing in such a run ever binds it.- if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ if (DX8Wrapper::_Get_D3D_Device() == NULL) {return;}@@ -1012,7 +1012,7 @@ void TextureLoader::Load_Thumbnail(TextureBaseClass *tc)WWASSERT(Is_DX8_Thread());// load thumbnail texture- IDirect3DTexture8 *d3d_texture = Load_Thumbnail(tc->Get_Full_Path(),tc->Get_HSV_Shift());+ IDirect3DTexture9 *d3d_texture = Load_Thumbnail(tc->Get_Full_Path(),tc->Get_HSV_Shift());// apply thumbnail to textureif (tc->Get_Asset_Type()==TextureBaseClass::TEX_REGULAR)@@ -1240,7 +1240,7 @@ bool TextureLoadTaskClass::Begin_Load(void)// With no render device there is nothing to load a texture into, and the caps this would size// it against were never filled in. Refusing here leaves the texture object in place with no// surface behind it, which is what a run that never draws needs.- if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ if (DX8Wrapper::_Get_D3D_Device() == NULL) {return false;}@@ -1332,7 +1332,7 @@ void TextureLoadTaskClass::Finish_Load(void){// No device, so no load and no missing-texture substitute either - that one is a D3D texture// built when the device was created, and without a device it was never built.- if (DX8Wrapper::_Get_D3D_Device8() == NULL) {+ if (DX8Wrapper::_Get_D3D_Device() == NULL) {return;}@@ -1905,7 +1905,7 @@ void TextureLoadTaskClass::Unlock_Surfaces(void)}#ifndef USE_MANAGED_TEXTURES- IDirect3DTexture8* tex = DX8Wrapper::_Create_DX8_Texture(Width, Height, Format, Texture->MipLevelCount,D3DPOOL_DEFAULT);+ IDirect3DTexture9* tex = DX8Wrapper::_Create_DX8_Texture(Width, Height, Format, Texture->MipLevelCount,D3DPOOL_DEFAULT);DX8CALL(UpdateTexture(Peek_D3D_Texture(),tex));Peek_D3D_Texture()->Release();D3DTexture=tex;@@ -2293,7 +2293,7 @@ void CubeTextureLoadTaskClass::Unlock_Surfaces(void)}#ifndef USE_MANAGED_TEXTURES- IDirect3DCubeTexture8* tex = DX8Wrapper::_Create_DX8_Cube_Texture+ IDirect3DCubeTexture9* tex = DX8Wrapper::_Create_DX8_Cube_Texture(Width,Height,@@ -2660,7 +2660,7 @@ void VolumeTextureLoadTaskClass::Unlock_Surfaces()}#ifndef USE_MANAGED_TEXTURES- IDirect3DTexture8* tex = DX8Wrapper::_Create_DX8_Volume_Texture(Width, Height, Depth, Format, Texture->MipLevelCount,D3DPOOL_DEFAULT);+ IDirect3DTexture9* tex = DX8Wrapper::_Create_DX8_Volume_Texture(Width, Height, Depth, Format, Texture->MipLevelCount,D3DPOOL_DEFAULT);DX8CALL(UpdateTexture(Peek_D3D_Volume_Texture(),tex));Peek_D3D_Volume_Texture()->Release();D3DTexture=tex;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.hindex b50628144..f425e06d7 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.h@@ -49,7 +49,7 @@#include "texture.h"class StringClass;-struct IDirect3DTexture8;+struct IDirect3DTexture9;class TextureLoadTaskClass;class TextureLoader@@ -61,11 +61,11 @@ public:// Modify given texture size to nearest valid size on current hardware.static void Validate_Texture_Size(unsigned& width, unsigned& height, unsigned& depth);- static IDirect3DTexture8 * Load_Thumbnail(+ static IDirect3DTexture9 * Load_Thumbnail(const StringClass& filename,const Vector3& hsv_shift);// WW3DFormat texture_format); // Pass WW3D_FORMAT_UNKNOWN if you don't care- static IDirect3DSurface8 * Load_Surface_Immediate(+ static IDirect3DSurface9 * Load_Surface_Immediate(const StringClass& filename,WW3DFormat surface_format, // Pass WW3D_FORMAT_UNKNOWN if you don't carebool allow_compression);@@ -230,7 +230,7 @@ class TextureLoadTaskClass : public TextureLoadTaskListNodeClassunsigned int Get_Locked_Surface_Pitch(unsigned int level) const;TextureBaseClass * Peek_Texture (void) { return Texture; }- IDirect3DTexture8 * Peek_D3D_Texture (void) { return (IDirect3DTexture8*)D3DTexture; }+ IDirect3DTexture9 * Peek_D3D_Texture (void) { return (IDirect3DTexture9*)D3DTexture; }void Set_Type (TaskType t) { Type = t; }void Set_Priority (PriorityType p) { Priority = p; }@@ -255,7 +255,7 @@ class TextureLoadTaskClass : public TextureLoadTaskListNodeClassvoid Apply (bool initialize);TextureBaseClass* Texture;- IDirect3DBaseTexture8* D3DTexture;+ IDirect3DBaseTexture9* D3DTexture;WW3DFormat Format;unsigned int Width;@@ -295,7 +295,7 @@ private:unsigned char* Get_Locked_CubeMap_Surface_Pointer(unsigned int face, unsigned int level);unsigned int Get_Locked_CubeMap_Surface_Pitch(unsigned int face, unsigned int level) const;- IDirect3DCubeTexture8* Peek_D3D_Cube_Texture(void) { return (IDirect3DCubeTexture8*)D3DTexture; }+ IDirect3DCubeTexture9* Peek_D3D_Cube_Texture(void) { return (IDirect3DCubeTexture9*)D3DTexture; }unsigned char* LockedCubeSurfacePtr[6][MIP_LEVELS_MAX];unsigned int LockedCubeSurfacePitch[6][MIP_LEVELS_MAX];@@ -324,7 +324,7 @@ private:unsigned int Get_Locked_Volume_Row_Pitch(unsigned int level);unsigned int Get_Locked_Volume_Slice_Pitch(unsigned int level);- IDirect3DVolumeTexture8* Peek_D3D_Volume_Texture(void) { return (IDirect3DVolumeTexture8*)D3DTexture; }+ IDirect3DVolumeTexture9* Peek_D3D_Volume_Texture(void) { return (IDirect3DVolumeTexture9*)D3DTexture; }unsigned int LockedSurfaceSlicePitch[MIP_LEVELS_MAX];diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/vertmaterial.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/vertmaterial.cppindex 18d6564d2..e5f29cfd8 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/vertmaterial.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/vertmaterial.cpp@@ -55,11 +55,11 @@ static unsigned int unique=1;VertexMaterialClass* VertexMaterialClass::Presets[VertexMaterialClass::PRESET_COUNT];#ifdef DYN_MAT8-class DynD3DMATERIAL8 : public W3DMPO+class DynD3DMATERIAL9 : public W3DMPO{- W3DMPO_GLUE(DynD3DMATERIAL8)+ W3DMPO_GLUE(DynD3DMATERIAL9)public:- D3DMATERIAL8 Mat;+ D3DMATERIAL9 Mat;};#define Material (&MaterialDyn->Mat)#define SRCMATPTR(src) (&(src)->MaterialDyn->Mat)@@ -94,11 +94,11 @@ VertexMaterialClass::VertexMaterialClass(void):}#ifdef DYN_MAT8- MaterialDyn=W3DNEW DynD3DMATERIAL8;+ MaterialDyn=W3DNEW DynD3DMATERIAL9;#else- MaterialOld=W3DNEW D3DMATERIAL8;+ MaterialOld=W3DNEW D3DMATERIAL9;#endif- memset(Material,0,sizeof(D3DMATERIAL8));+ memset(Material,0,sizeof(D3DMATERIAL9));Set_Ambient(1.0f,1.0f,1.0f);Set_Diffuse(1.0f,1.0f,1.0f);@@ -135,11 +135,11 @@ VertexMaterialClass::VertexMaterialClass(const VertexMaterialClass & src) :}#ifdef DYN_MAT8- MaterialDyn=W3DNEW DynD3DMATERIAL8;+ MaterialDyn=W3DNEW DynD3DMATERIAL9;#else- MaterialOld=W3DNEW D3DMATERIAL8;+ MaterialOld=W3DNEW D3DMATERIAL9;#endif- memcpy(Material, SRCMATPTR(&src), sizeof(D3DMATERIAL8));+ memcpy(Material, SRCMATPTR(&src), sizeof(D3DMATERIAL9));}void VertexMaterialClass::Make_Unique()@@ -209,7 +209,7 @@ unsigned long VertexMaterialClass::Compute_CRC(void) const// don't include the name when determining whether two vertex materials match// crc = CRC_Memory(reinterpret_cast<const unsigned char *>(Name.Peek_Buffer()),sizeof(char)*strlen(Name),crc);- crc = CRC_Memory(reinterpret_cast<const unsigned char *>(Material),sizeof(D3DMATERIAL8),crc);+ crc = CRC_Memory(reinterpret_cast<const unsigned char *>(Material),sizeof(D3DMATERIAL9),crc);crc = CRC_Memory(reinterpret_cast<const unsigned char *>(&Flags),sizeof(Flags),crc);crc = CRC_Memory(reinterpret_cast<const unsigned char *>(&DiffuseColorSource),sizeof(DiffuseColorSource),crc);crc = CRC_Memory(reinterpret_cast<const unsigned char *>(&AmbientColorSource),sizeof(AmbientColorSource),crc);@@ -974,7 +974,7 @@ void VertexMaterialClass::Apply(void) constvoid VertexMaterialClass::Apply_Null(void){int i;- static D3DMATERIAL8 default_settings =+ static D3DMATERIAL9 default_settings ={{ 1.0f, 1.0f, 1.0f, 1.0f }, // diffuse{ 1.0f, 1.0f, 1.0f, 1.0f }, // ambientdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/vertmaterial.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/vertmaterial.hindex c9dcd0d4f..c84bbf7d6 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/vertmaterial.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/vertmaterial.h@@ -59,9 +59,9 @@ class ChunkSaveClass;#define DYN_MAT8#ifdef DYN_MAT8-class DynD3DMATERIAL8;+class DynD3DMATERIAL9;#else-struct _D3DMATERIAL8;+struct _D3DMATERIAL9;#endif/**@@ -246,9 +246,9 @@ private:// We're using the pointer instead of the actual structure// so we don't have to include the d3d header - HY#ifdef DYN_MAT8- DynD3DMATERIAL8 * MaterialDyn;+ DynD3DMATERIAL9 * MaterialDyn;#else- _D3DMATERIAL8 * MaterialOld;+ _D3DMATERIAL9 * MaterialOld;#endifunsigned int Flags;unsigned int AmbientColorSource;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cppindex 8b24e25dc..a8d9cbc04 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp@@ -811,7 +811,7 @@ WW3DErrorType WW3D::Begin_Render(bool clear,bool clearz,const Vector3 & color, fSNAPSHOT_SAY(("========== WW3D::Begin_Render ============\r\n"));SNAPSHOT_SAY(("==========================================\r\n\r\n"));- if (DX8Wrapper::_Get_D3D_Device8() && (hr=DX8Wrapper::_Get_D3D_Device8()->TestCooperativeLevel()) != D3D_OK)+ if (DX8Wrapper::_Get_D3D_Device() && (hr=DX8Wrapper::_Get_D3D_Device()->TestCooperativeLevel()) != D3D_OK){// If the device was lost, do not render until we get it backif( D3DERR_DEVICELOST == hr )@@ -850,7 +850,7 @@ WW3DErrorType WW3D::Begin_Render(bool clear,bool clearz,const Vector3 & color, f// If we want to clear the screen, we need to set the viewport to include the entire screen:if (clear || clearz) {- D3DVIEWPORT8 vp;+ D3DVIEWPORT9 vp;int width, height, bits;bool windowed;WW3D::Get_Render_Target_Resolution(width, height, bits, windowed);@@ -1357,7 +1357,7 @@ void WW3D::Make_Screen_Shot( const char * filename_base , const float gamma, con// _Get_DX8_Front_Buffer hands back NULL when the surface it needs cannot be created, which is// what a device that has gone away does; there is no picture to take then.- IDirect3DSurface8 *fb=DX8Wrapper::_Get_DX8_Front_Buffer();+ IDirect3DSurface9 *fb=DX8Wrapper::_Get_DX8_Front_Buffer();if (fb == NULL)return;D3DSURFACE_DESC desc;@@ -1695,7 +1695,7 @@ void WW3D::Update_Movie_Capture( void )// _Get_DX8_Front_Buffer hands back NULL when the surface it needs cannot be created, which is// what a device that has gone away does; there is no picture to take then.- IDirect3DSurface8 *fb=DX8Wrapper::_Get_DX8_Front_Buffer();+ IDirect3DSurface9 *fb=DX8Wrapper::_Get_DX8_Front_Buffer();if (fb == NULL)return;D3DSURFACE_DESC desc;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3dformat.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3dformat.cppindex 16a1a95d8..06da2259b 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3dformat.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3dformat.cpp@@ -43,7 +43,7 @@#include "targa.h"#include "dx8wrapper.h"#include "dx8caps.h"-#include <d3d8.h>+#include <d3d9.h>/*WW3D_FORMAT_UNKNOWN=0,diff --git a/GeneralsMD/Code/Tests/test_ww3d2.cpp b/GeneralsMD/Code/Tests/test_ww3d2.cppindex b7bea5a02..66084c274 100644--- a/GeneralsMD/Code/Tests/test_ww3d2.cpp+++ b/GeneralsMD/Code/Tests/test_ww3d2.cpp@@ -1,7 +1,7 @@/** Device-free coverage for ww3d2.*- * ww3d2 is the DX8 renderer, so most of it needs a live IDirect3DDevice8.+ * ww3d2 is the DX8 renderer, so most of it needs a live IDirect3DDevice9.* The pieces below are pure computation - format tables, the shader bitfield,* the FVF offset arithmetic and the w3d-file <-> runtime converters - and* every one of them is reachable without a device. Anything that routes