Skip to content

Commit fa9cb0c

Browse files
committed
unify(texture): Merge W3DWater and WW3D2 texture code (#1989)
1 parent 746c017 commit fa9cb0c

File tree

29 files changed

+5861
-2033
lines changed

29 files changed

+5861
-2033
lines changed

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ W3DLaserDraw::W3DLaserDraw( Thing *thing, const ModuleData* moduleData ) :
124124
m_texture = WW3DAssetManager::Get_Instance()->Get_Texture( data->m_textureName.str() );
125125
if (m_texture)
126126
{
127+
if (!m_texture->Is_Initialized())
128+
m_texture->Init(); //make sure texture is actually loaded before accessing surface.
129+
127130
SurfaceClass::SurfaceDescription surfaceDesc;
128131
m_texture->Get_Level_Description(surfaceDesc);
129132
m_textureAspectRatio = (Real)surfaceDesc.Width/(Real)surfaceDesc.Height;

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Bool W3DProjectedShadowManager::ReAcquireResources(void)
261261
DEBUG_ASSERTCRASH(m_dynamicRenderTarget == NULL, ("Acquire of existing shadow render target"));
262262

263263
m_renderTargetHasAlpha=TRUE;
264-
if ((m_dynamicRenderTarget=DX8Wrapper::Create_Render_Target (DEFAULT_RENDER_TARGET_WIDTH, DEFAULT_RENDER_TARGET_HEIGHT, true)) == NULL)
264+
if ((m_dynamicRenderTarget=DX8Wrapper::Create_Render_Target (DEFAULT_RENDER_TARGET_WIDTH, DEFAULT_RENDER_TARGET_HEIGHT, WW3D_FORMAT_A8R8G8B8)) == NULL)
265265
{
266266
m_renderTargetHasAlpha=FALSE;
267267

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ TextureClass * W3DAssetManager::Recolor_Texture_One_Time(TextureClass *texture,
627627

628628
// make sure texture is loaded
629629
if (!texture->Is_Initialized())
630-
TextureLoader::Request_High_Priority_Loading(texture, (MipCountType)texture->Get_Mip_Level_Count());
630+
TextureLoader::Request_Foreground_Loading(texture);
631631

632632
SurfaceClass::SurfaceDescription desc;
633633
SurfaceClass *newsurf, *oldsurf;

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ W3DDisplay::~W3DDisplay()
402402

403403
// shutdown
404404
Debug_Statistics::Shutdown_Statistics();
405-
TextureLoadTaskClass::shutdown();
406405
if (!TheGlobalData->m_headless)
407406
W3DShaderManager::shutdown();
408407
m_assetManager->Free_Assets();

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ void WaterRenderObjClass::setupJbaWaterShader(void)
209209

210210
DX8Wrapper::Apply_Render_State_Changes(); //force update of view and projection matrices
211211
DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ALPHAOP, D3DTOP_ADD );
212+
if (!m_riverAlphaEdge->Is_Initialized())
213+
m_riverAlphaEdge->Init();
212214
DX8Wrapper::_Get_D3D_Device8()->SetTexture(3,m_riverAlphaEdge->Peek_D3D_Texture());
213215
DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
214216
DX8Wrapper::Set_DX8_Texture_Stage_State(3, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
@@ -219,7 +221,12 @@ void WaterRenderObjClass::setupJbaWaterShader(void)
219221
Bool doSparkles = true;
220222

221223
if (m_riverWaterPixelShader && doSparkles) {
224+
if (!m_waterSparklesTexture->Is_Initialized())
225+
m_waterSparklesTexture->Init();
222226
DX8Wrapper::_Get_D3D_Device8()->SetTexture(1,m_waterSparklesTexture->Peek_D3D_Texture());
227+
228+
if (!m_waterNoiseTexture->Is_Initialized())
229+
m_waterNoiseTexture->Init();
223230
DX8Wrapper::_Get_D3D_Device8()->SetTexture(2,m_waterNoiseTexture->Peek_D3D_Texture());
224231

225232
DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
@@ -526,7 +533,7 @@ HRESULT WaterRenderObjClass::initBumpMap(LPDIRECT3DTEXTURE8 *pTex, TextureClass
526533
pSrc=(unsigned char *)surf->Lock((int *)&dwSrcPitch);
527534

528535
// Create the bumpmap's surface and texture objects
529-
m_pBumpTexture[i]=DX8Wrapper::_Create_DX8_Texture(d3dsd.Width,d3dsd.Height,WW3D_FORMAT_U8V8,MIP_LEVELS_1,D3DPOOL_MANAGED,false);
536+
m_pBumpTexture[i]=DX8Wrapper::_Create_DX8_Texture(d3dsd.Width,d3dsd.Height,WW3D_FORMAT_U8V8,TextureClass::MIP_LEVELS_1,D3DPOOL_MANAGED,false);
530537

531538
// Fill the bits of the new texture surface with bits from
532539
// a private format.
@@ -944,6 +951,22 @@ void WaterRenderObjClass::ReAcquireResources(void)
944951
}
945952
}
946953

954+
//W3D Invalidate textures after losing the device and since we peek at the textures directly, it won't
955+
//know to reinit them for us. Do it here manually:
956+
if (m_riverTexture && !m_riverTexture->Is_Initialized())
957+
m_riverTexture->Init();
958+
if (m_waterNoiseTexture && !m_waterNoiseTexture->Is_Initialized())
959+
m_waterNoiseTexture->Init();
960+
if (m_riverAlphaEdge && !m_riverAlphaEdge->Is_Initialized())
961+
m_riverAlphaEdge->Init();
962+
if (m_waterSparklesTexture && !m_waterSparklesTexture->Is_Initialized())
963+
m_waterSparklesTexture->Init();
964+
if (m_whiteTexture && !m_whiteTexture->Is_Initialized())
965+
{ m_whiteTexture->Init();
966+
SurfaceClass *surface=m_whiteTexture->Get_Surface_Level();
967+
surface->DrawPixel(0,0,0xffffffff);
968+
REF_PTR_RELEASE(surface);
969+
}
947970
}
948971

949972
void WaterRenderObjClass::load(void)
@@ -1428,7 +1451,7 @@ void WaterRenderObjClass::renderMirror(CameraClass *cam)
14281451
Matrix3D reflectedTransform(rRight,rUp,rN,rPos);
14291452

14301453

1431-
DX8Wrapper::Set_Render_Target(m_pReflectionTexture);
1454+
DX8Wrapper::Set_Render_Target_With_Z((TextureClass*)m_pReflectionTexture);
14321455

14331456
// Clear the backbuffer
14341457
WW3D::Begin_Render(false,true,Vector3(0.0f,0.0f,0.0f)); //clearing only z-buffer since background always filled with clouds
@@ -1619,11 +1642,11 @@ void WaterRenderObjClass::Render(RenderInfoClass & rinfo)
16191642
DX8Wrapper::Set_DX8_Render_State(D3DRS_ALPHATESTENABLE, true); //test pixels if transparent(clipped) before rendering.
16201643

16211644
// Set clipping texture
1622-
m_alphaClippingTexture->Set_U_Addr_Mode(TextureFilterClass::TEXTURE_ADDRESS_CLAMP);
1623-
m_alphaClippingTexture->Set_V_Addr_Mode(TextureFilterClass::TEXTURE_ADDRESS_CLAMP);
1624-
m_alphaClippingTexture->Set_Min_Filter(TextureFilterClass::FILTER_TYPE_NONE);
1625-
m_alphaClippingTexture->Set_Mag_Filter(TextureFilterClass::FILTER_TYPE_NONE);
1626-
m_alphaClippingTexture->Set_Mip_Mapping(TextureFilterClass::FILTER_TYPE_NONE);
1645+
m_alphaClippingTexture->Set_U_Addr_Mode(TextureClass::TEXTURE_ADDRESS_CLAMP);
1646+
m_alphaClippingTexture->Set_V_Addr_Mode(TextureClass::TEXTURE_ADDRESS_CLAMP);
1647+
m_alphaClippingTexture->Set_Min_Filter(TextureClass::FILTER_TYPE_NONE);
1648+
m_alphaClippingTexture->Set_Mag_Filter(TextureClass::FILTER_TYPE_NONE);
1649+
m_alphaClippingTexture->Set_Mip_Mapping(TextureClass::FILTER_TYPE_NONE);
16271650

16281651
DX8Wrapper::Set_Texture(0,m_alphaClippingTexture);
16291652

@@ -2904,51 +2927,62 @@ void WaterRenderObjClass::drawRiverWater(PolygonTrigger *pTrig)
29042927

29052928
void WaterRenderObjClass::setupFlatWaterShader(void)
29062929
{
2930+
2931+
DX8Wrapper::Set_Texture(0,m_riverTexture);
2932+
if (!TheWaterTransparency->m_additiveBlend)
2933+
DX8Wrapper::Set_Shader(ShaderClass::_PresetAlphaShader);
2934+
else
2935+
DX8Wrapper::Set_Shader(ShaderClass::_PresetAdditiveShader);
2936+
2937+
VertexMaterialClass *vmat=VertexMaterialClass::Get_Preset(VertexMaterialClass::PRELIT_DIFFUSE);
2938+
DX8Wrapper::Set_Material(vmat);
2939+
REF_PTR_RELEASE(vmat);
2940+
m_riverTexture->Get_Filter().Set_Mag_Filter(TextureFilterClass::FILTER_TYPE_BEST);
2941+
m_riverTexture->Get_Filter().Set_Min_Filter(TextureFilterClass::FILTER_TYPE_BEST);
2942+
m_riverTexture->Get_Filter().Set_Mip_Mapping(TextureFilterClass::FILTER_TYPE_BEST);
2943+
2944+
DX8Wrapper::Apply_Render_State_Changes(); //force update of view and projection matrices
2945+
29072946
//Setup shroud to render in same pass as water
29082947
if (m_trapezoidWaterPixelShader)
29092948
{ if (TheTerrainRenderObject->getShroud())
29102949
{
29112950
W3DShaderManager::setTexture(0,TheTerrainRenderObject->getShroud()->getShroudTexture());
29122951
//Use stage 3 to apply the shroud
29132952
W3DShaderManager::setShader(W3DShaderManager::ST_SHROUD_TEXTURE, 3);
2914-
m_pDev->SetTextureStageState( 3, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
2915-
m_pDev->SetTextureStageState( 3, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
2916-
m_pDev->SetTextureStageState( 3, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
2917-
m_pDev->SetTextureStageState( 3, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
29182953
//Shroud shader uses z-compare of EQUAL which wouldn't work on water because it doesn't
29192954
//write to the zbuffer. Change to LESSEQUAL.
29202955
DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
29212956
}
29222957
else
29232958
{ //Assume no shroud, so stage 3 will be "NULL" texture but using actual white because
29242959
//pixel shader on GF4 generates random colors with SetTexture(3,NULL).
2960+
if (!m_whiteTexture->Is_Initialized())
2961+
{ m_whiteTexture->Init();
2962+
SurfaceClass *surface=m_whiteTexture->Get_Surface_Level();
2963+
surface->DrawPixel(0,0,0xffffffff);
2964+
REF_PTR_RELEASE(surface);
2965+
}
29252966
DX8Wrapper::_Get_D3D_Device8()->SetTexture(3,m_whiteTexture->Peek_D3D_Texture());
29262967
}
29272968
}
29282969

2929-
DX8Wrapper::Set_Texture(0,m_riverTexture);
2930-
if (!TheWaterTransparency->m_additiveBlend)
2931-
DX8Wrapper::Set_Shader(ShaderClass::_PresetAlphaShader);
2932-
else
2933-
DX8Wrapper::Set_Shader(ShaderClass::_PresetAdditiveShader);
2934-
2935-
VertexMaterialClass *vmat=VertexMaterialClass::Get_Preset(VertexMaterialClass::PRELIT_DIFFUSE);
2936-
DX8Wrapper::Set_Material(vmat);
2937-
REF_PTR_RELEASE(vmat);
2938-
m_riverTexture->Get_Filter().Set_Mag_Filter(TextureFilterClass::FILTER_TYPE_BEST);
2939-
m_riverTexture->Get_Filter().Set_Min_Filter(TextureFilterClass::FILTER_TYPE_BEST);
2940-
m_riverTexture->Get_Filter().Set_Mip_Mapping(TextureFilterClass::FILTER_TYPE_BEST);
2941-
2942-
DX8Wrapper::Apply_Render_State_Changes(); //force update of view and projection matrices
2943-
29442970
DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ALPHAOP, D3DTOP_ADD );
29452971
DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXCOORDINDEX, 0);
29462972
DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXCOORDINDEX, 0);
29472973

29482974
Bool doSparkles = true;
29492975

29502976
if (m_trapezoidWaterPixelShader && doSparkles) {
2977+
2978+
if (!m_waterSparklesTexture->Is_Initialized())
2979+
m_waterSparklesTexture->Init();
2980+
29512981
DX8Wrapper::_Get_D3D_Device8()->SetTexture(1,m_waterSparklesTexture->Peek_D3D_Texture());
2982+
2983+
if (!m_waterNoiseTexture->Is_Initialized())
2984+
m_waterNoiseTexture->Init();
2985+
29522986
DX8Wrapper::_Get_D3D_Device8()->SetTexture(2,m_waterNoiseTexture->Peek_D3D_Texture());
29532987

29542988
DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545

4646
#include "W3DDevice/GameClient/HeightMap.h"
4747
#include "W3DDevice/GameClient/W3DWaterTracks.h"
48+
#include "W3DDevice/GameClient/W3DShaderManager.h"
49+
#include "W3DDevice/GameClient/W3DShroud.h"
4850
#include "GameClient/InGameUI.h"
51+
#include "GameClient/Water.h"
4952
#include "GameLogic/TerrainLogic.h"
5053
#include "Common/FramePacer.h"
5154
#include "Common/GlobalData.h"
@@ -851,6 +854,9 @@ Try improving the fit to vertical surfaces like cliffs.
851854
*/
852855
Int diffuseLight;
853856

857+
if (!TheGlobalData->m_showSoftWaterEdge || TheWaterTransparency->m_transparentWaterDepth ==0 )
858+
return;
859+
854860
if (TheGlobalData->m_usingWaterTrackEditor)
855861
TestWaterUpdate();
856862

@@ -887,6 +893,24 @@ Try improving the fit to vertical surfaces like cliffs.
887893

888894
DX8Wrapper::Set_Vertex_Buffer(m_vertexBuffer);
889895
DX8Wrapper::Set_DX8_Render_State(D3DRS_ZBIAS,8);
896+
//Force apply of render states so we can override them.
897+
DX8Wrapper::Apply_Render_State_Changes();
898+
899+
if (TheTerrainRenderObject->getShroud())
900+
{
901+
W3DShaderManager::setTexture(0,TheTerrainRenderObject->getShroud()->getShroudTexture());
902+
W3DShaderManager::setShader(W3DShaderManager::ST_SHROUD_TEXTURE, 1);
903+
904+
//modulate with shroud texture
905+
DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); //stage 1 texture
906+
DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLORARG2, D3DTA_CURRENT ); //previous stage texture
907+
DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_COLOROP, D3DTOP_MODULATE );
908+
DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
909+
910+
//Shroud shader uses z-compare of EQUAL which wouldn't work on water because it doesn't
911+
//write to the zbuffer. Change to LESSEQUAL.
912+
DX8Wrapper::Set_DX8_Render_State(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
913+
}
890914

891915
Int LastTextureType=-1;
892916

@@ -905,6 +929,12 @@ Try improving the fit to vertical surfaces like cliffs.
905929
}
906930

907931
DX8Wrapper::Set_DX8_Render_State(D3DRS_ZBIAS,0);
932+
933+
if (TheTerrainRenderObject->getShroud())
934+
{ //we used the shroud shader, so reset it.
935+
DX8Wrapper::Set_DX8_Render_State(D3DRS_ZFUNC, D3DCMP_EQUAL);
936+
W3DShaderManager::resetShader(W3DShaderManager::ST_SHROUD_TEXTURE);
937+
}
908938
}
909939

910940
WaterTracksObj *WaterTracksRenderSystem::findTrack(Vector2 &start, Vector2 &end, waveType type)

Generals/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cpp

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
** along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
/* $Header: /Commando/Code/ww3d2/assetmgr.cpp 36 8/24/01 3:23p Jani_p $ */
19+
/* $Header: /Commando/Code/ww3d2/assetmgr.cpp 43 11/01/01 1:11a Jani_p $ */
2020
/***********************************************************************************************
2121
*** Confidential - Westwood Studios ***
2222
***********************************************************************************************
@@ -25,12 +25,16 @@
2525
* *
2626
* $Archive:: /Commando/Code/ww3d2/assetmgr.cpp $*
2727
* *
28-
* Author:: Greg_h *
28+
* Org Author:: Greg_h *
2929
* *
30-
* $Modtime:: 8/22/01 6:54p $*
30+
* Author : Kenny Mitchell *
3131
* *
32-
* $Revision:: 36 $*
32+
* $Modtime:: 08/05/02 10:14a $*
3333
* *
34+
* $Revision:: 46 $*
35+
* *
36+
* 06/27/02 KM Texture class abstraction *
37+
* 08/05/02 KM Texture class redesign (revisited)
3438
*---------------------------------------------------------------------------------------------*
3539
* Functions: *
3640
* WW3DAssetManager::WW3DAssetManager -- Constructor *
@@ -1040,46 +1044,6 @@ HTreeClass * WW3DAssetManager::Get_HTree(const char * name)
10401044
return htree;
10411045
}
10421046

1043-
/***********************************************************************************************
1044-
* WW3DAssetManager::Get_Bumpmap_Based_On_Texture -- Generate a bumpmap from texture. The *
1045-
* resulting texture is stored to the hash table so that any further requests will share it. *
1046-
* *
1047-
* INPUT: *
1048-
* *
1049-
* OUTPUT: *
1050-
* *
1051-
* WARNINGS: *
1052-
* *
1053-
* HISTORY: *
1054-
* 1/31/2001 NH : Created. *
1055-
*=============================================================================================*/
1056-
1057-
TextureClass* WW3DAssetManager::Get_Bumpmap_Based_On_Texture(TextureClass* texture)
1058-
{
1059-
WWASSERT(texture->Get_Texture_Name() && strlen(texture->Get_Texture_Name()));
1060-
StringClass bump_name="__Bumpmap-";
1061-
bump_name+=texture->Get_Texture_Name();
1062-
_strlwr(bump_name.Peek_Buffer()); // lower case
1063-
1064-
/*
1065-
** See if the texture has already been generated.
1066-
*/
1067-
1068-
TextureClass* tex = TextureHash.Get(bump_name);
1069-
1070-
/*
1071-
** Didn't have it so we have to create a new texture
1072-
*/
1073-
if (!tex) {
1074-
tex = NEW_REF(BumpmapTextureClass,(texture));
1075-
tex->Set_Texture_Name(bump_name);
1076-
TextureHash.Insert(tex->Get_Texture_Name(),tex);
1077-
}
1078-
1079-
tex->Add_Ref();
1080-
return tex;
1081-
}
1082-
10831047
/***********************************************************************************************
10841048
* WW3DAssetManager::Get_Texture -- get a TextureClass from the specified file *
10851049
* *
@@ -1127,7 +1091,7 @@ TextureClass * WW3DAssetManager::Get_Texture
11271091
** See if the texture has already been loaded.
11281092
*/
11291093
TextureClass* tex = TextureHash.Get(lower_case_name);
1130-
if (tex && texture_format!=WW3D_FORMAT_UNKNOWN)
1094+
if (tex && (tex->Is_Initialized() == true) && (texture_format!=WW3D_FORMAT_UNKNOWN))
11311095
{
11321096
WWASSERT_PRINT(tex->Get_Texture_Format()==texture_format,("Texture %s has already been loaded with different format",filename));
11331097
}
@@ -1139,7 +1103,15 @@ TextureClass * WW3DAssetManager::Get_Texture
11391103
{
11401104
if (type==TextureBaseClass::TEX_REGULAR)
11411105
{
1142-
tex = NEW_REF (TextureClass, (lower_case_name, NULL, mip_level_count, texture_format, allow_compression));
1106+
tex = NEW_REF (TextureClass, (lower_case_name, NULL, mip_level_count, texture_format, allow_compression, allow_reduction));
1107+
}
1108+
else if (type==TextureBaseClass::TEX_CUBEMAP)
1109+
{
1110+
tex = NEW_REF (CubeTextureClass, (lower_case_name, NULL, mip_level_count, texture_format, allow_compression, allow_reduction));
1111+
}
1112+
else if (type==TextureBaseClass::TEX_VOLUME)
1113+
{
1114+
tex = NEW_REF (VolumeTextureClass, (lower_case_name, NULL, mip_level_count, texture_format, allow_compression, allow_reduction));
11431115
}
11441116
else
11451117
{

Generals/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ class WW3DAssetManager
269269
TextureBaseClass::TexAssetType type=TextureBaseClass::TEX_REGULAR,
270270
bool allow_reduction=true
271271
);
272-
TextureClass* Get_Bumpmap_Based_On_Texture(TextureClass* texture);
273272

274273
virtual void Release_All_Textures(void);
275274
virtual void Release_Unused_Textures(void);

0 commit comments

Comments
 (0)