Skip to content

Commit 63bd300

Browse files
authored
[GEN] Bring texture related code in WW3D2 closer to Zero Hour (#726)
1 parent acda56d commit 63bd300

File tree

17 files changed

+197
-99
lines changed

17 files changed

+197
-99
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ int TerrainTextureClass::update(WorldHeightMap *htMap)
8888
IDirect3DSurface8 *surface_level;
8989
D3DSURFACE_DESC surface_desc;
9090
D3DLOCKED_RECT locked_rect;
91-
DX8_ErrorCode(D3DTexture->GetSurfaceLevel(0, &surface_level));
91+
DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0, &surface_level));
9292
DX8_ErrorCode(surface_level->GetDesc(&surface_desc));
9393
if (surface_desc.Width < TEXTURE_WIDTH) {
9494
surface_level->Release();
@@ -186,9 +186,9 @@ int TerrainTextureClass::update(WorldHeightMap *htMap)
186186
}
187187
surface_level->UnlockRect();
188188
surface_level->Release();
189-
DX8_ErrorCode(D3DXFilterTexture(D3DTexture, NULL, 0, D3DX_FILTER_BOX));
189+
DX8_ErrorCode(D3DXFilterTexture(Peek_D3D_Texture(), NULL, 0, D3DX_FILTER_BOX));
190190
if (TheWritableGlobalData->m_textureReductionFactor) {
191-
D3DTexture->SetLOD(TheWritableGlobalData->m_textureReductionFactor);
191+
Peek_D3D_Texture()->SetLOD(TheWritableGlobalData->m_textureReductionFactor);
192192
}
193193
return(surface_desc.Height);
194194
}
@@ -362,7 +362,7 @@ int TerrainTextureClass::update256(WorldHeightMap *htMap)
362362
IDirect3DSurface8 *surface_level;
363363
D3DSURFACE_DESC surface_desc;
364364
D3DLOCKED_RECT locked_rect;
365-
DX8_ErrorCode(D3DTexture->GetSurfaceLevel(0, &surface_level));
365+
DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0, &surface_level));
366366
DX8_ErrorCode(surface_level->GetDesc(&surface_desc));
367367
if (surface_desc.Width != 256) {
368368
surface_level->Release();
@@ -499,7 +499,7 @@ int TerrainTextureClass::update256(WorldHeightMap *htMap)
499499
}
500500
surface_level->UnlockRect();
501501
surface_level->Release();
502-
DX8_ErrorCode(D3DXFilterTexture(D3DTexture, NULL, 0, D3DX_FILTER_BOX));
502+
DX8_ErrorCode(D3DXFilterTexture(Peek_D3D_Texture(), NULL, 0, D3DX_FILTER_BOX));
503503
// Note - normal width for the terrain texture is 1024. We are at 256
504504
// probably running on a voodoo. The height we return is scaled up
505505
// to match the expected width of 1024. jba.
@@ -565,14 +565,9 @@ AlphaTerrainTextureClass::AlphaTerrainTextureClass( TextureClass *pBaseTex ):
565565
TextureClass(8, 8,
566566
WW3D_FORMAT_A1R5G5B5, MIP_LEVELS_1 )
567567
{
568-
if (D3DTexture) {
569-
// Release the 8x8 texture.
570-
D3DTexture->Release();
571-
D3DTexture = NULL;
572-
}
573568
// Attach the base texture's d3d texture.
574-
D3DTexture = pBaseTex->Peek_D3D_Texture();
575-
D3DTexture->AddRef();
569+
IDirect3DTexture8 * d3d_tex = pBaseTex->Peek_D3D_Texture();
570+
Set_D3D_Base_Texture(d3d_tex);
576571
}
577572

578573

@@ -849,7 +844,7 @@ int AlphaEdgeTextureClass::update(WorldHeightMap *htMap)
849844
IDirect3DSurface8 *surface_level;
850845
D3DSURFACE_DESC surface_desc;
851846
D3DLOCKED_RECT locked_rect;
852-
DX8_ErrorCode(D3DTexture->GetSurfaceLevel(0, &surface_level));
847+
DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0, &surface_level));
853848
DX8_ErrorCode(surface_level->LockRect(&locked_rect, NULL, 0));
854849
DX8_ErrorCode(surface_level->GetDesc(&surface_desc));
855850

@@ -912,7 +907,7 @@ int AlphaEdgeTextureClass::update(WorldHeightMap *htMap)
912907
}
913908
surface_level->UnlockRect();
914909
surface_level->Release();
915-
DX8_ErrorCode(D3DXFilterTexture(D3DTexture, NULL, 0, D3DX_FILTER_BOX));
910+
DX8_ErrorCode(D3DXFilterTexture(Peek_D3D_Texture(), NULL, 0, D3DX_FILTER_BOX));
916911
return(surface_desc.Height);
917912
}
918913

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ void W3DDisplay::init( void )
670670
WW3D::Set_Prelit_Mode( WW3D::PRELIT_MODE_LIGHTMAP_MULTI_PASS );
671671
WW3D::Set_Collision_Box_Display_Mask(0x00); ///<set to 0xff to make collision boxes visible
672672
WW3D::Enable_Static_Sort_Lists(true);
673-
WW3D::Set_Texture_Compression_Mode(WW3D::TEXTURE_COMPRESSION_ENABLE);
674673
WW3D::Set_Thumbnail_Enabled(false);
675674
WW3D::Set_Screen_UV_Bias( TRUE ); ///< this makes text look good :)
676675

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,11 +1095,21 @@ TextureClass * WW3DAssetManager::Get_Texture
10951095
const char * filename,
10961096
MipCountType mip_level_count,
10971097
WW3DFormat texture_format,
1098-
bool allow_compression
1098+
bool allow_compression,
1099+
TextureBaseClass::TexAssetType type,
1100+
bool allow_reduction
10991101
)
11001102
{
11011103
WWPROFILE( "WW3DAssetManager::Get_Texture 1" );
11021104

1105+
/*
1106+
** We cannot currently mip-map bumpmaps
1107+
*/
1108+
if (texture_format==WW3D_FORMAT_U8V8)
1109+
{
1110+
mip_level_count=MIP_LEVELS_1;
1111+
}
1112+
11031113
/*
11041114
** Bail if the user isn't really asking for anything
11051115
*/
@@ -1114,19 +1124,21 @@ TextureClass * WW3DAssetManager::Get_Texture
11141124
/*
11151125
** See if the texture has already been loaded.
11161126
*/
1117-
11181127
TextureClass* tex = TextureHash.Get(lower_case_name);
11191128
if (tex && texture_format!=WW3D_FORMAT_UNKNOWN)
11201129
{
1121-
WWASSERT_PRINT(tex->Get_Texture_Format()==texture_format,("Texture %s has already been loaded witt different format",filename));
1130+
WWASSERT_PRINT(tex->Get_Texture_Format()==texture_format,("Texture %s has already been loaded with different format",filename));
11221131
}
11231132

11241133
/*
11251134
** Didn't have it so we have to create a new texture
11261135
*/
11271136
if (!tex)
11281137
{
1129-
tex = NEW_REF (TextureClass, (lower_case_name, NULL, mip_level_count, texture_format, allow_compression));
1138+
if (type==TextureBaseClass::TEX_REGULAR)
1139+
{
1140+
tex = NEW_REF (TextureClass, (lower_case_name, NULL, mip_level_count, texture_format, allow_compression));
1141+
}
11301142
TextureHash.Insert(tex->Get_Texture_Name(),tex);
11311143
}
11321144

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

Lines changed: 6 additions & 4 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.h 15 7/24/01 6:28p Jani_p $ */
19+
/* $Header: /Commando/Code/ww3d2/assetmgr.h 19 12/17/01 7:55p Jani_p $ */
2020
/***********************************************************************************************
2121
*** Confidential - Westwood Studios ***
2222
***********************************************************************************************
@@ -27,9 +27,9 @@
2727
* *
2828
* Author:: Greg_h *
2929
* *
30-
* $Modtime:: 7/17/01 5:52p $*
30+
* $Modtime:: 12/15/01 4:14p $*
3131
* *
32-
* $Revision:: 15 $*
32+
* $Revision:: 19 $*
3333
* *
3434
*---------------------------------------------------------------------------------------------*
3535
* Functions: *
@@ -267,7 +267,9 @@ class WW3DAssetManager
267267
const char * filename,
268268
MipCountType mip_level_count=MIP_LEVELS_ALL,
269269
WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN,
270-
bool allow_compression=true
270+
bool allow_compression=true,
271+
TextureBaseClass::TexAssetType type=TextureBaseClass::TEX_REGULAR,
272+
bool allow_reduction=true
271273
);
272274
TextureClass* Get_Bumpmap_Based_On_Texture(TextureClass* texture);
273275

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ DDSFileClass::DDSFileClass(const char* name,unsigned reduction_factor)
9999
if (MipLevels==0) MipLevels=1;
100100

101101
//Adjust the reduction factor to keep textures above some minimum dimensions
102-
if (MipLevels <= WW3D::Get_Texture_Min_Mip_Levels())
102+
if (MipLevels <= WW3D::Get_Texture_Min_Dimension())
103103
ReductionFactor=0;
104104
else
105-
{ int mipToDrop=MipLevels-WW3D::Get_Texture_Min_Mip_Levels();
105+
{ int mipToDrop=MipLevels-WW3D::Get_Texture_Min_Dimension();
106106
if (ReductionFactor >= mipToDrop)
107107
ReductionFactor=mipToDrop;
108108
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,9 +2248,9 @@ void DX8Wrapper::_Update_Texture(TextureClass *system, TextureClass *video)
22482248
{
22492249
WWASSERT(system);
22502250
WWASSERT(video);
2251-
WWASSERT(system->Pool==TextureClass::POOL_SYSTEMMEM);
2252-
WWASSERT(video->Pool==TextureClass::POOL_DEFAULT);
2253-
DX8CALL(UpdateTexture(system->D3DTexture,video->D3DTexture));
2251+
WWASSERT(system->Get_Pool()==TextureClass::POOL_SYSTEMMEM);
2252+
WWASSERT(video->Get_Pool()==TextureClass::POOL_DEFAULT);
2253+
DX8CALL(UpdateTexture(system->Peek_D3D_Base_Texture(),video->Peek_D3D_Base_Texture()));
22542254
}
22552255

22562256
void DX8Wrapper::Compute_Caps(WW3DFormat display_format)
@@ -2504,7 +2504,7 @@ DX8Wrapper::Create_Render_Target (int width, int height, bool alpha)
25042504

25052505
// 3dfx drivers are lying in the CheckDeviceFormat call and claiming
25062506
// that they support render targets!
2507-
if (tex->Peek_D3D_Texture() == NULL)
2507+
if (tex->Peek_D3D_Base_Texture() == NULL)
25082508
{
25092509
WWDEBUG_SAY(("DX8Wrapper - Render target creation failed!\r\n"));
25102510
REF_PTR_RELEASE(tex);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ class DX8Wrapper
239239
*/
240240
static void Do_Onetime_Device_Dependent_Inits(void);
241241
static void Do_Onetime_Device_Dependent_Shutdowns(void);
242+
243+
static bool Is_Initted(void) { return IsInitted; }
244+
242245
static bool Has_Stencil (void);
243246
static void Get_Format_Name(unsigned int format, StringClass *tex_format);
244247

@@ -329,6 +332,7 @@ class DX8Wrapper
329332
/*
330333
** Resources
331334
*/
335+
332336
static IDirect3DTexture8 * _Create_DX8_Texture
333337
(
334338
unsigned int width,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ ParticleEmitterClass::Create_From_Definition (const ParticleEmitterDefClass &def
212212
(
213213
ptexture_filename,
214214
MIP_LEVELS_ALL,
215-
WW3D_FORMAT_UNKNOWN,
216-
false); // no compression for particle textures!
215+
WW3D_FORMAT_UNKNOWN
216+
);
217+
// false); // no compression for particle textures!
217218
}
218219

219220
ShaderClass shader;

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
* *
2323
* Project Name : WW3D *
2424
* *
25-
* $Archive:: /VSS_Sync/ww3d2/surfaceclass.cpp $*
25+
* $Archive:: /Commando/Code/ww3d2/surfaceclass.cpp $*
2626
* *
2727
* Original Author:: Nathaniel Hoffman *
2828
* *
29-
* $Author:: Vss_sync $*
29+
* $Author:: Greg_h2 $*
3030
* *
31-
* $Modtime:: 8/29/01 7:29p $*
31+
* $Modtime:: 8/30/01 2:01p $*
3232
* *
33-
* $Revision:: 24 $*
33+
* $Revision:: 25 $*
3434
* *
3535
*---------------------------------------------------------------------------------------------*
3636
* Functions: *
@@ -921,15 +921,44 @@ bool SurfaceClass::Is_Monochrome(void)
921921
unsigned int x,y;
922922
SurfaceDescription sd;
923923
Get_Description(sd);
924+
bool is_compressed = false;
924925

925926
switch (sd.Format)
926927
{
928+
// these formats are always monochrome
927929
case WW3D_FORMAT_A8L8:
928930
case WW3D_FORMAT_A8:
929931
case WW3D_FORMAT_L8:
930932
case WW3D_FORMAT_A4L4:
931933
return true;
932934
break;
935+
// these formats cannot be determined to be monochrome or not
936+
case WW3D_FORMAT_UNKNOWN:
937+
case WW3D_FORMAT_A8P8:
938+
case WW3D_FORMAT_P8:
939+
case WW3D_FORMAT_U8V8: // Bumpmap
940+
case WW3D_FORMAT_L6V5U5: // Bumpmap
941+
case WW3D_FORMAT_X8L8V8U8: // Bumpmap
942+
return false;
943+
break;
944+
// these formats need decompression first
945+
case WW3D_FORMAT_DXT1:
946+
case WW3D_FORMAT_DXT2:
947+
case WW3D_FORMAT_DXT3:
948+
case WW3D_FORMAT_DXT4:
949+
case WW3D_FORMAT_DXT5:
950+
is_compressed = true;
951+
break;
952+
}
953+
954+
// if it's in some compressed texture format, be sure to decompress first
955+
if (is_compressed) {
956+
WW3DFormat new_format = Get_Valid_Texture_Format(sd.Format, false);
957+
SurfaceClass *new_surf = NEW_REF( SurfaceClass, (sd.Width, sd.Height, new_format) );
958+
new_surf->Copy(0, 0, 0, 0, sd.Width, sd.Height, this);
959+
bool result = new_surf->Is_Monochrome();
960+
REF_PTR_RELEASE(new_surf);
961+
return result;
933962
}
934963

935964
int pitch,size;

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ TextureClass::TextureClass(IDirect3DTexture8* d3d_texture)
290290
{
291291
D3DTexture->AddRef();
292292
IDirect3DSurface8* surface;
293-
DX8_ErrorCode(D3DTexture->GetSurfaceLevel(0,&surface));
293+
DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0,&surface));
294294
D3DSURFACE_DESC d3d_desc;
295295
::ZeroMemory(&d3d_desc, sizeof(D3DSURFACE_DESC));
296296
DX8_ErrorCode(surface->GetDesc(&d3d_desc));
@@ -370,6 +370,35 @@ void TextureClass::Invalidate()
370370
}
371371
}
372372

373+
//**********************************************************************************************
374+
//! Returns a pointer to the d3d texture
375+
/*!
376+
*/
377+
IDirect3DBaseTexture8 * TextureClass::Peek_D3D_Base_Texture() const
378+
{
379+
LastAccessed=WW3D::Get_Sync_Time();
380+
return D3DTexture;
381+
}
382+
383+
//**********************************************************************************************
384+
//! Set the d3d texture pointer. Handles ref counts properly.
385+
/*!
386+
*/
387+
void TextureClass::Set_D3D_Base_Texture(IDirect3DBaseTexture8* tex)
388+
{
389+
// (gth) Generals does stuff directly with the D3DTexture pointer so lets
390+
// reset the access timer whenever someon messes with this pointer.
391+
LastAccessed=WW3D::Get_Sync_Time();
392+
393+
if (D3DTexture != NULL) {
394+
D3DTexture->Release();
395+
}
396+
D3DTexture = tex;
397+
if (D3DTexture != NULL) {
398+
D3DTexture->AddRef();
399+
}
400+
}
401+
373402
// ----------------------------------------------------------------------------
374403

375404
void TextureClass::Load_Locked_Surface()
@@ -424,7 +453,7 @@ void TextureClass::Get_Level_Description(SurfaceClass::SurfaceDescription &surfa
424453
}
425454

426455
D3DSURFACE_DESC d3d_surf_desc;
427-
DX8_ErrorCode(D3DTexture->GetLevelDesc(level, &d3d_surf_desc));
456+
DX8_ErrorCode(Peek_D3D_Texture()->GetLevelDesc(level, &d3d_surf_desc));
428457
surface_desc.Format = D3DFormat_To_WW3DFormat(d3d_surf_desc.Format);
429458
surface_desc.Height = d3d_surf_desc.Height;
430459
surface_desc.Width = d3d_surf_desc.Width;
@@ -435,7 +464,7 @@ void TextureClass::Get_Level_Description(SurfaceClass::SurfaceDescription &surfa
435464
SurfaceClass *TextureClass::Get_Surface_Level(unsigned int level)
436465
{
437466
IDirect3DSurface8 *d3d_surface = NULL;
438-
DX8_ErrorCode(D3DTexture->GetSurfaceLevel(level, &d3d_surface));
467+
DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(level, &d3d_surface));
439468
SurfaceClass *surface = W3DNEW SurfaceClass(d3d_surface);
440469
d3d_surface->Release();
441470
return surface;
@@ -520,7 +549,7 @@ void TextureClass::Apply_New_Surface(bool initialized)
520549

521550
WWASSERT(D3DTexture);
522551
IDirect3DSurface8* surface;
523-
DX8_ErrorCode(D3DTexture->GetSurfaceLevel(0,&surface));
552+
DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0,&surface));
524553
D3DSURFACE_DESC d3d_desc;
525554
::ZeroMemory(&d3d_desc, sizeof(D3DSURFACE_DESC));
526555
DX8_ErrorCode(surface->GetDesc(&d3d_desc));

0 commit comments

Comments
 (0)