Skip to content

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.

fix(w3ddevice): keep modern water on linux until a mac has drawn it

Olcay Seygan21969b53dbe9
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
index c104f4ddd..400ac768a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -295,13 +295,7 @@ Bool OptionsHotkeysKey( UnsignedByte key, Int state );
void OptionsHotkeysSave( void );
void OptionsHotkeysClose( void );
-//-------------------------------------------------------------------------------------------------
-/** Show one page and hide the rest.
- *
- * The page you are on is the disabled button, which is the one piece of tab feedback available
- * without drawing new artwork: a pressed-looking tab would need a second image per button, and
- * the buttons are cloned from one that already exists. */
-//-------------------------------------------------------------------------------------------------
+// The Water page's rows drive the SDL Modern water, which only Linux draws.
static Bool modernWaterSettingsSupported( void )
{
return WaterScreenReflection::Supported();
@@ -332,7 +326,7 @@ static void fitWaterOptionsTabCaption( GameWindow *tab )
TheDisplayStringManager->freeDisplayString( caption );
}
-// Hide the SDL water page elsewhere and give the remaining tabs their original width. Derive
+// Hide the Water page off Linux and give the remaining tabs their original width. Derive
// the bounds from the loaded layout so shell scaling and reopening an existing layout both work.
static void layoutOptionsTabs( void )
{
@@ -363,6 +357,13 @@ static void layoutOptionsTabs( void )
}
}
+//-------------------------------------------------------------------------------------------------
+/** Show one page and hide the rest.
+ *
+ * The page you are on is the disabled button, which is the one piece of tab feedback available
+ * without drawing new artwork: a pressed-looking tab would need a second image per button, and
+ * the buttons are cloned from one that already exists. */
+//-------------------------------------------------------------------------------------------------
static void showOptionsPage( Int which )
{
if( which == OPTIONS_WATER_PAGE && !modernWaterSettingsSupported() )
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h
index 24318870c..9eae2de4e 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h
@@ -130,8 +130,8 @@ public:
void update( void ); ///< update phase of the water
#if ZH_MODERN_WATER
void takeReadsForRender(void);
- void prewarmStaticMapData(void);
#endif
+ void prewarmStaticMapData(void);
void enableWaterGrid(Bool state); ///< used to active custom water for special maps. (i.e DAM). The grid is TerrainLogic's WaterGrid; this builds its buffers
void updateMapOverrides(void); ///< used to update any map specific map overrides for water appearance.
void setTimeOfDay(TimeOfDay tod); ///<change sky/water for time of day
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
index d7a1883c9..58d5f8401 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
@@ -1001,25 +1001,28 @@ bool Supported()
{
#if defined(_WIN32)
return Direct3D11_Is_Active() && Direct3D11_Present_Is_Enabled();
-#else
+#elif ZH_MODERN_WATER
return PosixWaterGpuAvailable(DX8Wrapper::_Get_D3D_Device());
+#else
+ return false;
#endif
}
} // namespace ModernWater
-#if ZH_MODERN_WATER
+// The SDL water's reflections, tiers and Water page: Linux only, the one SDL host that draws Modern water.
namespace WaterScreenReflection {
bool Supported()
{
-#ifdef _WIN32
- return false;
-#else
+#if ZH_MODERN_WATER && !defined(_WIN32)
return PosixWaterGpuAvailable(DX8Wrapper::_Get_D3D_Device());
+#else
+ return false;
#endif
}
}
+#if ZH_MODERN_WATER
/** The Modern style is asked for and a device draws it. Classic graphics is the 2003 picture, so it
keeps EA's water whatever WaterStyle says, as it keeps the old clouds and drops the foam. The
quality slider and its presets leave WaterStyle alone: Modern is the player's own pick. */
@@ -2818,6 +2821,7 @@ void WaterRenderObjClass::loadSetting( Setting *setting, TimeOfDay timeOfDay )
}
+#if ZH_MODERN_WATER
void WaterRenderObjClass::synchronizeWaterReflection(void)
{
if (!WaterScreenReflection::Supported()) return;
@@ -2848,6 +2852,7 @@ void WaterRenderObjClass::synchronizeWaterReflection(void)
m_reflectionAreaMax.Set(0.0f,0.0f);
}
}
+#endif
//-------------------------------------------------------------------------------------------------
/** Our water may use effects that require run-time rendered textures. These
diff --git a/GeneralsMD/Code/Libraries/Include/Platform/ModernWaterBuild.h b/GeneralsMD/Code/Libraries/Include/Platform/ModernWaterBuild.h
index 994fc333a..532edaf23 100644
--- a/GeneralsMD/Code/Libraries/Include/Platform/ModernWaterBuild.h
+++ b/GeneralsMD/Code/Libraries/Include/Platform/ModernWaterBuild.h
@@ -1,9 +1,9 @@
-// Modern water is compiled for SDL GPU and Direct3D 11. Runtime capability queries
-// decide which features the current device supports.
+// Where the Modern water is compiled in: the SDL GPU device on Linux and the Direct3D 11 backend on
+// Windows. macOS, -d3d9 and -headless stay on the Classic water.
// Distributed under the repository's GPL-3.0 terms; see LICENSE.md.
#pragma once
-#if defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
+#if defined(__linux__) || defined(_WIN32)
#define ZH_MODERN_WATER 1
#else
#define ZH_MODERN_WATER 0
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.cpp
index 177ee9d39..aafb9f68b 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.cpp
@@ -1609,12 +1609,14 @@ bool EngineShader_Pixel_Program(EngineShaderProgram program,
}
const bool modern_water = EngineShader_Is_Modern_Water(program);
if (target == COMBINER_SHADER_TARGET_SDL3_GPU) {
+#if defined(__linux__)
if (modern_water) {
write_modern_water(hlsl, program == ENGINE_SHADER_WATER_RIVER, true);
if (!CombinerShader_Append_Pixel_Pipeline(pipeline, hlsl)) return false;
hlsl += " return current;\n}\n";
return SDL3_Shader_Retarget(hlsl, false);
}
+#endif // __linux__
return write_engine_pixel_program(program, pipeline, hlsl, EngineShader_Paints_Ground(program))
&& SDL3_Shader_Retarget(hlsl, false);
}
diff --git a/GeneralsMD/Code/Tests/test_shader_sdl.cpp b/GeneralsMD/Code/Tests/test_shader_sdl.cpp
index 6257dcba8..753fc2047 100644
--- a/GeneralsMD/Code/Tests/test_shader_sdl.cpp
+++ b/GeneralsMD/Code/Tests/test_shader_sdl.cpp
@@ -1440,6 +1440,8 @@ TEST(fft_low_tier_preserves_energy_reality_and_filtering)
CHECK(filtering.find("level,6)")!=std::string::npos);
}
+#if defined(__linux__)
+// The SDL water tiers and reflections exist only where the Linux Modern water runtime draws them.
TEST(water_performance_tiers_compile_both_materials_and_preserve_shared_defaults)
{
struct Restore { WaterPerformanceSettings::Configuration saved=WaterPerformanceSettings::Applied();
@@ -1510,6 +1512,7 @@ TEST(screen_reflection_modes_are_bounded_and_selected_per_draw)
CHECK(MirrorSize(Mirror) == 512 && MirrorSize(Hybrid) == 1024);
CHECK(MirrorSize(Mirror, 0) == 256 && MirrorSize(Hybrid, 0) == 512);
}
+#endif // __linux__
TEST(direct3d11_modern_water_source_matches_the_upstream_baseline)
{