Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,9 @@ void W3DDisplay::init()
}
}

// TheSuperHackers @feature Mauller 13/03/2026 Add native MSAA support, must be set before creating render device
WW3D::Set_MSAA_Mode(WW3D::MULTISAMPLE_MODE_NONE);

renderDeviceError = WW3D::Set_Render_Device(
0,
getWidth(),
Expand Down
39 changes: 37 additions & 2 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const int DEFAULT_RESOLUTION_WIDTH = 640;
const int DEFAULT_RESOLUTION_HEIGHT = 480;
const int DEFAULT_BIT_DEPTH = 32;
const int DEFAULT_TEXTURE_BIT_DEPTH = 16;
const D3DMULTISAMPLE_TYPE DEFAULT_MSAA = D3DMULTISAMPLE_NONE;

bool DX8Wrapper_IsWindowed = true;

Expand All @@ -110,6 +111,7 @@ int DX8Wrapper::BitDepth = DEFAULT_BIT_DEPTH;
int DX8Wrapper::TextureBitDepth = DEFAULT_TEXTURE_BIT_DEPTH;
bool DX8Wrapper::IsWindowed = false;
D3DFORMAT DX8Wrapper::DisplayFormat = D3DFMT_UNKNOWN;
D3DMULTISAMPLE_TYPE DX8Wrapper::MultiSampleAntiAliasing = DEFAULT_MSAA;

D3DMATRIX DX8Wrapper::old_world;
D3DMATRIX DX8Wrapper::old_view;
Expand Down Expand Up @@ -951,7 +953,6 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
_PresentParameters.BackBufferHeight = ResolutionHeight;
_PresentParameters.BackBufferCount = IsWindowed ? 1 : 2;

_PresentParameters.MultiSampleType = D3DMULTISAMPLE_NONE;
_PresentParameters.SwapEffect = IsWindowed ? D3DSWAPEFFECT_DISCARD : D3DSWAPEFFECT_FLIP; // Shouldn't this be D3DSWAPEFFECT_FLIP?
_PresentParameters.hDeviceWindow = _Hwnd;
_PresentParameters.Windowed = IsWindowed;
Expand Down Expand Up @@ -1024,7 +1025,7 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
}

/*
** Time to actually create the device.
** Set default for depth stencil format if auto Z buffer failed.
*/
if (_PresentParameters.AutoDepthStencilFormat==D3DFMT_UNKNOWN) {
if (BitDepth==32) {
Expand All @@ -1035,6 +1036,40 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
}
}

/*
** Check the devices support for the requested MSAA mode then setup the multi sample type
*/
if (MultiSampleAntiAliasing > D3DMULTISAMPLE_NONE) {

HRESULT hrBack = D3DInterface->CheckDeviceMultiSampleType(
CurRenderDevice,
D3DDEVTYPE_HAL,
_PresentParameters.BackBufferFormat,
IsWindowed,
MultiSampleAntiAliasing
);

HRESULT hrDepth = D3DInterface->CheckDeviceMultiSampleType(
CurRenderDevice,
D3DDEVTYPE_HAL,
_PresentParameters.AutoDepthStencilFormat,
IsWindowed,
MultiSampleAntiAliasing
);

if (FAILED(hrBack) || FAILED(hrDepth)) {
// IF we fail then disable MSAA entirely.
// External code needs to retrieve the configured MSAA mode after device creation
WWDEBUG_SAY(("Requested MSAA Mode Not Supported"));
MultiSampleAntiAliasing = D3DMULTISAMPLE_NONE;
}
}

_PresentParameters.MultiSampleType = MultiSampleAntiAliasing;

/*
** Time to actually create the device.
*/
StringClass displayFormat;
StringClass backbufferFormat;

Expand Down
4 changes: 4 additions & 0 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@ class DX8Wrapper
static void Set_Texture_Bitdepth(int depth) { WWASSERT(depth==16 || depth==32); TextureBitDepth = depth; }
static int Get_Texture_Bitdepth() { return TextureBitDepth; }

static void Set_MSAA_Mode(D3DMULTISAMPLE_TYPE mode) { MultiSampleAntiAliasing = mode; }
static D3DMULTISAMPLE_TYPE Get_MSAA_Mode() { return MultiSampleAntiAliasing; }

static void Set_Swap_Interval(int swap);
static int Get_Swap_Interval();
static void Set_Polygon_Mode(int mode);
Expand Down Expand Up @@ -628,6 +631,7 @@ class DX8Wrapper
static int TextureBitDepth;
static bool IsWindowed;
static D3DFORMAT DisplayFormat;
static D3DMULTISAMPLE_TYPE MultiSampleAntiAliasing;

static D3DMATRIX old_world;
static D3DMATRIX old_view;
Expand Down
46 changes: 46 additions & 0 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
**
***********************************************************************************/

float WW3D::LogicFrameTimeMs = 1000.0f / WWSyncPerSecond; // initialized to something to avoid division by zero on first use

Check warning on line 163 in Generals/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-debug+t+e

operator '/': deprecated between enumerations and floating-point types

Check warning on line 163 in Generals/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32+t+e

operator '/': deprecated between enumerations and floating-point types

Check warning on line 163 in Generals/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-profile+t+e

operator '/': deprecated between enumerations and floating-point types

Check warning on line 163 in Generals/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-vcpkg-debug+t+e

operator '/': deprecated between enumerations and floating-point types

Check warning on line 163 in Generals/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-vcpkg-profile+t+e

operator '/': deprecated between enumerations and floating-point types

Check warning on line 163 in Generals/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-vcpkg+t+e

operator '/': deprecated between enumerations and floating-point types
float WW3D::FractionalSyncMs = 0.0f;
unsigned int WW3D::SyncTime = 0;
unsigned int WW3D::PreviousSyncTime = 0;
Expand Down Expand Up @@ -2014,6 +2014,52 @@
return DX8Wrapper::Get_Texture_Bitdepth();
}

void WW3D::Set_MSAA_Mode(MultiSampleModeEnum mode)
{
switch (mode) {

default:
case MULTISAMPLE_MODE_NONE:
DX8Wrapper::Set_MSAA_Mode(D3DMULTISAMPLE_NONE);
break;

case MULTISAMPLE_MODE_2X:
DX8Wrapper::Set_MSAA_Mode(D3DMULTISAMPLE_2_SAMPLES);
break;

case MULTISAMPLE_MODE_4X:
DX8Wrapper::Set_MSAA_Mode(D3DMULTISAMPLE_4_SAMPLES);
break;

case MULTISAMPLE_MODE_8X:
DX8Wrapper::Set_MSAA_Mode(D3DMULTISAMPLE_8_SAMPLES);
break;

}
}

WW3D::MultiSampleModeEnum WW3D::Get_MSAA_Mode()
{
D3DMULTISAMPLE_TYPE type = DX8Wrapper::Get_MSAA_Mode();

switch (type) {

default:
case D3DMULTISAMPLE_NONE:
return MULTISAMPLE_MODE_NONE;

case D3DMULTISAMPLE_2_SAMPLES:
return MULTISAMPLE_MODE_2X;

case D3DMULTISAMPLE_4_SAMPLES:
return MULTISAMPLE_MODE_4X;

case D3DMULTISAMPLE_8_SAMPLES:
return MULTISAMPLE_MODE_8X;

}
}

void WW3D::Add_To_Static_Sort_List(RenderObjClass *robj, unsigned int sort_level)
{
CurrentStaticSortLists->Add_To_List(robj, sort_level);
Expand Down
10 changes: 10 additions & 0 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/ww3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class WW3D
{
public:

enum MultiSampleModeEnum {
MULTISAMPLE_MODE_NONE,
MULTISAMPLE_MODE_2X,
MULTISAMPLE_MODE_4X,
MULTISAMPLE_MODE_8X
};

enum PrelitModeEnum {
PRELIT_MODE_VERTEX,
PRELIT_MODE_LIGHTMAP_MULTI_PASS,
Expand Down Expand Up @@ -259,6 +266,9 @@ class WW3D
static void Set_Texture_Bitdepth(int bitdepth);
static int Get_Texture_Bitdepth();

static void Set_MSAA_Mode(MultiSampleModeEnum mode);
static MultiSampleModeEnum Get_MSAA_Mode();

static void Set_Mesh_Draw_Mode (MeshDrawModeEnum mode) { MeshDrawMode = mode; }
static MeshDrawModeEnum Get_Mesh_Draw_Mode () { return (MeshDrawMode); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,9 @@ void W3DDisplay::init()
}
}

// TheSuperHackers @feature Mauller 13/03/2026 Add native MSAA support, must be set before creating render device
WW3D::Set_MSAA_Mode(WW3D::MULTISAMPLE_MODE_NONE);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where #2375 will plug in right? Right now this line does nothing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this will be where external code will set the MSAA level, likewise external code also needs to call get_MSAA_Mode after the display is created to check what mode was set etc.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps set this to DEFAULT_MSAA ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a Direct3D enumeration within directx wrapper, im going to follow this up soon with the changes needed to link it into options.ini.

i can also add in defaults for MSAA based on the presets too.

Medium 2x. High 4x seem reasonable? leave 8x as a custom option since it can be quite taxing.


renderDeviceError = WW3D::Set_Render_Device(
0,
getWidth(),
Expand Down
39 changes: 37 additions & 2 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const int DEFAULT_RESOLUTION_WIDTH = 640;
const int DEFAULT_RESOLUTION_HEIGHT = 480;
const int DEFAULT_BIT_DEPTH = 32;
const int DEFAULT_TEXTURE_BIT_DEPTH = 16;
const D3DMULTISAMPLE_TYPE DEFAULT_MSAA = D3DMULTISAMPLE_NONE;

bool DX8Wrapper_IsWindowed = true;

Expand All @@ -114,6 +115,7 @@ int DX8Wrapper::BitDepth = DEFAULT_BIT_DEPTH;
int DX8Wrapper::TextureBitDepth = DEFAULT_TEXTURE_BIT_DEPTH;
bool DX8Wrapper::IsWindowed = false;
D3DFORMAT DX8Wrapper::DisplayFormat = D3DFMT_UNKNOWN;
D3DMULTISAMPLE_TYPE DX8Wrapper::MultiSampleAntiAliasing = DEFAULT_MSAA;

D3DMATRIX DX8Wrapper::old_world;
D3DMATRIX DX8Wrapper::old_view;
Expand Down Expand Up @@ -1025,7 +1027,6 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
_PresentParameters.BackBufferHeight = ResolutionHeight;
_PresentParameters.BackBufferCount = IsWindowed ? 1 : 2;

_PresentParameters.MultiSampleType = D3DMULTISAMPLE_NONE;
//I changed this to discard all the time (even when full-screen) since that the most efficient. 07-16-03 MW:
_PresentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;//IsWindowed ? D3DSWAPEFFECT_DISCARD : D3DSWAPEFFECT_FLIP; // Shouldn't this be D3DSWAPEFFECT_FLIP?
_PresentParameters.hDeviceWindow = _Hwnd;
Expand Down Expand Up @@ -1099,7 +1100,7 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
}

/*
** Time to actually create the device.
** Set default for depth stencil format if auto Z buffer failed.
*/
if (_PresentParameters.AutoDepthStencilFormat==D3DFMT_UNKNOWN) {
if (BitDepth==32) {
Expand All @@ -1110,6 +1111,40 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
}
}

/*
** Check the devices support for the requested MSAA mode then setup the multi sample type
*/
if (MultiSampleAntiAliasing > D3DMULTISAMPLE_NONE) {

HRESULT hrBack = D3DInterface->CheckDeviceMultiSampleType(
CurRenderDevice,
D3DDEVTYPE_HAL,
_PresentParameters.BackBufferFormat,
IsWindowed,
MultiSampleAntiAliasing
);

HRESULT hrDepth = D3DInterface->CheckDeviceMultiSampleType(
CurRenderDevice,
D3DDEVTYPE_HAL,
_PresentParameters.AutoDepthStencilFormat,
IsWindowed,
MultiSampleAntiAliasing
);

if (FAILED(hrBack) || FAILED(hrDepth)) {
// IF we fail then disable MSAA entirely.
// External code needs to retrieve the configured MSAA mode after device creation
WWDEBUG_SAY(("Requested MSAA Mode Not Supported"));
MultiSampleAntiAliasing = D3DMULTISAMPLE_NONE;
}
}

_PresentParameters.MultiSampleType = MultiSampleAntiAliasing;

/*
** Time to actually create the device.
*/
StringClass displayFormat;
StringClass backbufferFormat;

Expand Down
4 changes: 4 additions & 0 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ class DX8Wrapper
static void Set_Texture_Bitdepth(int depth) { WWASSERT(depth==16 || depth==32); TextureBitDepth = depth; }
static int Get_Texture_Bitdepth() { return TextureBitDepth; }

static void Set_MSAA_Mode(D3DMULTISAMPLE_TYPE mode) { MultiSampleAntiAliasing = mode; }
static D3DMULTISAMPLE_TYPE Get_MSAA_Mode() { return MultiSampleAntiAliasing; }

static void Set_Swap_Interval(int swap);
static int Get_Swap_Interval();
static void Set_Polygon_Mode(int mode);
Expand Down Expand Up @@ -637,6 +640,7 @@ class DX8Wrapper
static int TextureBitDepth;
static bool IsWindowed;
static D3DFORMAT DisplayFormat;
static D3DMULTISAMPLE_TYPE MultiSampleAntiAliasing;

static D3DMATRIX old_world;
static D3DMATRIX old_view;
Expand Down
46 changes: 46 additions & 0 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
**
***********************************************************************************/

float WW3D::LogicFrameTimeMs = 1000.0f / WWSyncPerSecond; // initialized to something to avoid division by zero on first use

Check warning on line 164 in GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-debug+t+e

operator '/': deprecated between enumerations and floating-point types

Check warning on line 164 in GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-vcpkg-profile+t+e

operator '/': deprecated between enumerations and floating-point types

Check warning on line 164 in GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32+t+e

operator '/': deprecated between enumerations and floating-point types

Check warning on line 164 in GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-profile+t+e

operator '/': deprecated between enumerations and floating-point types

Check warning on line 164 in GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-vcpkg+t+e

operator '/': deprecated between enumerations and floating-point types

Check warning on line 164 in GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-vcpkg-debug+t+e

operator '/': deprecated between enumerations and floating-point types
float WW3D::FractionalSyncMs = 0.0f;
unsigned int WW3D::SyncTime = 0;
unsigned int WW3D::PreviousSyncTime = 0;
Expand Down Expand Up @@ -2017,6 +2017,52 @@
return DX8Wrapper::Get_Texture_Bitdepth();
}

void WW3D::Set_MSAA_Mode(MultiSampleModeEnum mode)
{
switch (mode) {

default:
case MULTISAMPLE_MODE_NONE:
DX8Wrapper::Set_MSAA_Mode(D3DMULTISAMPLE_NONE);
break;

case MULTISAMPLE_MODE_2X:
DX8Wrapper::Set_MSAA_Mode(D3DMULTISAMPLE_2_SAMPLES);
break;

case MULTISAMPLE_MODE_4X:
DX8Wrapper::Set_MSAA_Mode(D3DMULTISAMPLE_4_SAMPLES);
break;

case MULTISAMPLE_MODE_8X:
DX8Wrapper::Set_MSAA_Mode(D3DMULTISAMPLE_8_SAMPLES);
break;

}
}

WW3D::MultiSampleModeEnum WW3D::Get_MSAA_Mode()
{
D3DMULTISAMPLE_TYPE type = DX8Wrapper::Get_MSAA_Mode();

switch (type) {

default:
case D3DMULTISAMPLE_NONE:
return MULTISAMPLE_MODE_NONE;

case D3DMULTISAMPLE_2_SAMPLES:
return MULTISAMPLE_MODE_2X;

case D3DMULTISAMPLE_4_SAMPLES:
return MULTISAMPLE_MODE_4X;

case D3DMULTISAMPLE_8_SAMPLES:
return MULTISAMPLE_MODE_8X;

}
}

void WW3D::Add_To_Static_Sort_List(RenderObjClass *robj, unsigned int sort_level)
{
CurrentStaticSortLists->Add_To_List(robj, sort_level);
Expand Down
10 changes: 10 additions & 0 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class WW3D
{
public:

enum MultiSampleModeEnum {
MULTISAMPLE_MODE_NONE,
MULTISAMPLE_MODE_2X,
MULTISAMPLE_MODE_4X,
MULTISAMPLE_MODE_8X
};

enum PrelitModeEnum {
PRELIT_MODE_VERTEX,
PRELIT_MODE_LIGHTMAP_MULTI_PASS,
Expand Down Expand Up @@ -259,6 +266,9 @@ class WW3D
static void Set_Texture_Bitdepth(int bitdepth);
static int Get_Texture_Bitdepth();

static void Set_MSAA_Mode(MultiSampleModeEnum mode);
static MultiSampleModeEnum Get_MSAA_Mode();

static void Set_Mesh_Draw_Mode (MeshDrawModeEnum mode) { MeshDrawMode = mode; }
static MeshDrawModeEnum Get_Mesh_Draw_Mode () { return (MeshDrawMode); }

Expand Down
Loading