Skip to content

Commit 8e5bb95

Browse files
authored
[GEN] Backport WW3D2's TextureClass dimension functions from Zero Hour (#710)
1 parent 72610ea commit 8e5bb95

File tree

6 files changed

+53
-20
lines changed

6 files changed

+53
-20
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ Bitmap2DObjClass::Bitmap2DObjClass
213213
//Set_Aspect(resh/(float)resw);
214214

215215
// Find the dimensions of the texture:
216-
SurfaceClass::SurfaceDescription sd;
217-
texture->Get_Level_Description(sd);
216+
// SurfaceClass::SurfaceDescription sd;
217+
// texture->Get_Level_Description(sd);
218218

219219
// convert image width and image height to normalized values
220-
float vw = (float) sd.Width / (float)resw;
221-
float vh = (float) sd.Height / (float)resh;
220+
float vw = (float) texture->Get_Width() / (float)resw;
221+
float vh = (float) texture->Get_Height() / (float)resh;
222222

223223
// if we requested the image to be centered around a point adjust the
224224
// coordinates accordingly.
@@ -236,7 +236,7 @@ Bitmap2DObjClass::Bitmap2DObjClass
236236
if (additive) {
237237
shader = ShaderClass::_PresetAdditive2DShader;
238238
} else {
239-
if (ignore_alpha == false && Has_Alpha(sd.Format)) {
239+
if (ignore_alpha == false && Has_Alpha(texture->Get_Texture_Format())) {
240240
shader = ShaderClass::_PresetAlpha2DShader;
241241
} else {
242242
shader = ShaderClass::_PresetOpaque2DShader;

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,10 @@ void DecalGeneratorClass::Set_Mesh_Transform(const Matrix3D & mesh_transform)
279279
TextureClass * tex = Material->Peek_Texture();
280280
WWASSERT(tex != NULL);
281281
if (tex) {
282-
SurfaceClass::SurfaceDescription surface_desc;
283-
tex->Get_Level_Description(surface_desc);
284-
texsize = surface_desc.Width;
282+
// SurfaceClass::SurfaceDescription surface_desc;
283+
// tex->Get_Level_Description(surface_desc);
284+
// texsize = surface_desc.Width;
285+
texsize = tex->Get_Width();
285286
}
286287

287288
Mapper->Set_Texture_Transform(mesh_to_texture,texsize);

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,11 @@ ParticleEmitterDefClass::Convert_To_Ver2 (void)
465465
if (ptexture != NULL) {
466466
// If texture has an alpha channel do alpha blending instead of additive
467467
// (which is the default for point groups):
468-
SurfaceClass::SurfaceDescription surf_desc;
469-
::ZeroMemory(&surf_desc, sizeof(SurfaceClass::SurfaceDescription));
470-
ptexture->Get_Level_Description(surf_desc);
471-
if (Has_Alpha(surf_desc.Format)) {
468+
// SurfaceClass::SurfaceDescription surf_desc;
469+
// ::ZeroMemory(&surf_desc, sizeof(SurfaceClass::SurfaceDescription));
470+
// ptexture->Get_Level_Description(surf_desc);
471+
// if (Has_Alpha(surf_desc.Format)) {
472+
if (Has_Alpha(ptexture->Get_Texture_Format())) {
472473
shader = ShaderClass::_PresetAlphaSpriteShader;
473474
}
474475
ptexture->Release_Ref();

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,6 @@ void TexProjectClass::Set_Texture(TextureClass * texture)
734734
texture->Get_Filter().Set_U_Addr_Mode(TextureFilterClass::TEXTURE_ADDRESS_CLAMP);
735735
texture->Get_Filter().Set_V_Addr_Mode(TextureFilterClass::TEXTURE_ADDRESS_CLAMP);
736736
MaterialPass->Set_Texture(texture);
737-
738-
SurfaceClass::SurfaceDescription surface_desc;
739-
texture->Get_Level_Description(surface_desc);
740-
Set_Texture_Size(surface_desc.Width);
741737
}
742738
}
743739

@@ -1319,6 +1315,14 @@ void TexProjectClass::Pre_Render_Update(const Matrix3D & camera)
13191315
} else {
13201316
Mapper->Set_Type(MatrixMapperClass::ORTHO_PROJECTION);
13211317
}
1318+
1319+
if (Get_Texture_Size() == 0) {
1320+
// SurfaceClass::SurfaceDescription surface_desc;
1321+
// MaterialPass->Peek_Texture()->Get_Level_Description(surface_desc);
1322+
Set_Texture_Size(MaterialPass->Peek_Texture()->Get_Width());
1323+
WWASSERT(Get_Texture_Size() != 0);
1324+
}
1325+
13221326
Mapper->Set_Texture_Transform(view_to_texture,Get_Texture_Size());
13231327
if (Mapper1) {
13241328
Mapper1->Set_Texture_Transform(view_to_texture,Get_Texture_Size());

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

+18-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ TextureClass::TextureClass(unsigned width, unsigned height, WW3DFormat format, M
9494
Name(""),
9595
TextureFormat(format),
9696
IsCompressionAllowed(false),
97-
TextureLoadTask(NULL)
97+
TextureLoadTask(NULL),
98+
Width(width),
99+
Height(height)
98100
{
99101
switch (format)
100102
{
@@ -155,7 +157,9 @@ TextureClass::TextureClass
155157
IsProcedural(false),
156158
TextureFormat(texture_format),
157159
IsCompressionAllowed(allow_compression),
158-
TextureLoadTask(NULL)
160+
TextureLoadTask(NULL),
161+
Width(0),
162+
Height(0)
159163
{
160164
switch (TextureFormat)
161165
{
@@ -241,10 +245,14 @@ TextureClass::TextureClass(SurfaceClass *surface, MipCountType mip_level_count)
241245
IsProcedural(true),
242246
TextureFormat(surface->Get_Surface_Format()),
243247
IsCompressionAllowed(false),
244-
TextureLoadTask(NULL)
248+
TextureLoadTask(NULL),
249+
Width(0),
250+
Height(0)
245251
{
246252
SurfaceClass::SurfaceDescription sd;
247253
surface->Get_Description(sd);
254+
Width=sd.Width;
255+
Height=sd.Height;
248256
switch (sd.Format)
249257
{
250258
case WW3D_FORMAT_DXT1:
@@ -276,14 +284,18 @@ TextureClass::TextureClass(IDirect3DTexture8* d3d_texture)
276284
Name(""),
277285
IsProcedural(true),
278286
IsCompressionAllowed(false),
279-
TextureLoadTask(NULL)
287+
TextureLoadTask(NULL),
288+
Width(0),
289+
Height(0)
280290
{
281291
D3DTexture->AddRef();
282292
IDirect3DSurface8* surface;
283293
DX8_ErrorCode(D3DTexture->GetSurfaceLevel(0,&surface));
284294
D3DSURFACE_DESC d3d_desc;
285295
::ZeroMemory(&d3d_desc, sizeof(D3DSURFACE_DESC));
286296
DX8_ErrorCode(surface->GetDesc(&d3d_desc));
297+
Width=d3d_desc.Width;
298+
Height=d3d_desc.Height;
287299
TextureFormat=D3DFormat_To_WW3DFormat(d3d_desc.Format);
288300
switch (TextureFormat)
289301
{
@@ -514,6 +526,8 @@ void TextureClass::Apply_New_Surface(bool initialized)
514526
DX8_ErrorCode(surface->GetDesc(&d3d_desc));
515527
// if (TextureFormat==WW3D_FORMAT_UNKNOWN) {
516528
TextureFormat=D3DFormat_To_WW3DFormat(d3d_desc.Format);
529+
Width=d3d_desc.Width;
530+
Height=d3d_desc.Height;
517531
// }
518532
// else {
519533
// WWASSERT(D3DFormat_To_WW3DFormat(d3d_desc.Format)==TextureFormat);

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

+13
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ class TextureClass : public W3DMPO, public RefCountClass
120120

121121
// The number of Mip levels in the texture
122122
unsigned int Get_Mip_Level_Count(void);
123+
124+
// Note! Width and Height may be zero and may change if texture uses mipmaps
125+
int Get_Width() const
126+
{
127+
return Width;
128+
}
129+
int Get_Height() const
130+
{
131+
return Height;
132+
}
123133

124134
// Get surface description of a Mip level (defaults to the highest-resolution one)
125135
void Get_Level_Description(SurfaceClass::SurfaceDescription &surface_desc, unsigned int level = 0);
@@ -208,6 +218,9 @@ class TextureClass : public W3DMPO, public RefCountClass
208218
unsigned LastAccessed;
209219
WW3DFormat TextureFormat;
210220

221+
int Width;
222+
int Height;
223+
211224
// Support for self-managed textures
212225

213226
PoolType Pool;

0 commit comments

Comments
 (0)