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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Modified 2025-2026 by Olcay Seygan for Zero Hour Reforged; see the git history.
// Modified 2026 by İlyas Akın for the macOS/Linux port; see NOTICE.md and the git history.
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: W3DShaderManager.h /////////////////////////////////////////////////////////
//
// Custom shader system that allows more options and easier device validation than
// possible with W3D2.
//
// Author: Mark Wilczynski, August 2001
//
///////////////////////////////////////////////////////////////////////////////
#pragma once
#ifndef __W3DSHADERMANAGER_H_
#define __W3DSHADERMANAGER_H_
#include "WW3D2/texture.h"
enum FilterTypes : Int;
enum FilterModes : Int;
#include "W3DDevice/GameClient/W3DCustomScene.h" // CustomScenePassModes, which ISO C++ cannot forward-declare
enum StaticGameLODLevel : Int;
enum ChipsetType : Int;
enum CpuType : Int;
enum GraphicsVenderID : int; // defined in W3DShaderManager.cpp with the same int, as MSVC's is
#include <d3d9.h>
#include "Platform/RenderTypes.h"
class TextureClass; ///forward reference
/** System for managing complex rendering settings which are either not handled by
WW3D2 or need custom paths depending on the video card. This system will determine
the proper shader given video card limitations and also allow the app to query the
hardware for specific features.
*/
class W3DShaderManager
{
public:
//put any custom shaders (not going through W3D) in here.
enum ShaderTypes
{ ST_INVALID, //invalid shader type.
ST_TERRAIN_BASE, //shader to apply base terrain texture only
ST_TERRAIN_BASE_NOISE1, //shader to apply base texture and cloud/noise 1.
ST_TERRAIN_BASE_NOISE2, //shader to apply base texture and cloud/noise 2.
ST_TERRAIN_BASE_NOISE12,//shader to apply base texture and both cloud/noise
ST_SHROUD_TEXTURE, //shader to apply shroud texture projection.
ST_MASK_TEXTURE, //shader to apply alpha mask texture projection.
ST_ROAD_BASE, //shader to apply base terrain texture only
ST_ROAD_BASE_NOISE1, //shader to apply base texture and cloud/noise 1.
ST_ROAD_BASE_NOISE2, //shader to apply base texture and cloud/noise 2.
ST_ROAD_BASE_NOISE12,//shader to apply base texture and both cloud/noise
ST_CLOUD_TEXTURE, //shader to project clouds.
ST_FLAT_TERRAIN_BASE, //shader to apply base terrain texture only
ST_FLAT_TERRAIN_BASE_NOISE1, //shader to apply base texture and cloud/noise 1.
ST_FLAT_TERRAIN_BASE_NOISE2, //shader to apply base texture and cloud/noise 2.
ST_FLAT_TERRAIN_BASE_NOISE12,//shader to apply base texture and both cloud/noise
ST_FLAT_SHROUD_TEXTURE, //shader to apply shroud texture projection.
ST_MAX
};
W3DShaderManager(void); ///<constructor
static void init( void ); ///<determine optimal shaders for current device.
static void shutdown(void); ///<release resources used by shaders
static ChipsetType getChipset(void); ///<return current device chipset.
static GraphicsVenderID getCurrentVendor(void) {return m_currentVendor;} ///<return current card vendor.
static Int64 getCurrentDriverVersion(void) {return m_driverVersion; } ///<return current driver version.
static Int getShaderPasses(ShaderTypes shader); ///<rendering passes required for shader
static Int setShader(ShaderTypes shader, Int pass); ///<enable specific shader pass.
static Int setShroudTex(Int stage); ///<Set shroud in a texture stage.
static void resetShader(ShaderTypes shader); ///<make sure W3D2 gets restored to normal
///Specify all textures (up to 8) which can be accessed by the shaders.
static void setTexture(Int stage,TextureClass* texture) {m_Textures[stage]=texture;}
///Return current texture available to shaders.
static inline TextureClass *getShaderTexture(Int stage) { return m_Textures[stage];} ///<returns currently selected texture for given stage
///Return last activated shader.
static inline ShaderTypes getCurrentShader(void) {return m_currentShader;}
/// Loads a .pso file, translates its D3D8 bytecode and creates the pixel shader.
static RenderResult LoadAndCreateD3DPixelShader(const char* strFilePath, IDirect3DPixelShader9** shader);
/// Loads a .vso file with the D3D8 declaration array that belongs to it, and creates
/// both the vertex shader and the D3D9 declaration that has to be bound beside it.
static RenderResult LoadAndCreateD3DVertexShader(const char* strFilePath, const RenderUInt32* pDeclaration,
IDirect3DVertexShader9** shader, IDirect3DVertexDeclaration9** declaration);
static Bool testMinimumRequirements(ChipsetType *videoChipType, CpuType *cpuType, Int *cpuFreq, Int *numRAM, Real *intBenchIndex, Real *floatBenchIndex, Real *memBenchIndex);
static StaticGameLODLevel getGPUPerformanceIndex(void);
static Real GetCPUBenchTime(void);
// Filter methods
static Bool filterPreRender(FilterTypes filter, Bool &skipRender, CustomScenePassModes &scenePassMode); ///< Set up at start of render. Only applies to screen filter shaders.
static Bool filterPostRender(FilterTypes filter, enum FilterModes mode, Coord2D &scrollDelta, Bool &doExtraRender); ///< Called after render. Only applies to screen filter shaders.
static Bool filterSetup(FilterTypes filter, enum FilterModes mode);
/// The Warm Light haze for this frame (levels, sun, shroud), once a frame from
/// W3DDisplay::draw before the views render, whatever screen filter is running.
static void pushProtoHaze(void);
// Support routines for filter methods.
static Bool canRenderToTexture(void) { return (m_oldRenderSurface && m_newRenderSurface);}
/// Sets render target to texture. sceneStandIn: the texture is only sampled while the scene goes
/// into it (heat haze) and never shown afterwards, so Direct3D 11 may keep the scene in its own
/// float target (Direct3D11_Set_Scene_Stand_In). A filter that shows the texture on a later
/// frame (motion blur, cross fade) needs the real copy and passes FALSE.
static void startRenderToTexture(Bool sceneStandIn = FALSE);
static IDirect3DTexture9 * endRenderToTexture(void); ///< Ends render to texture, & returns texture.
static IDirect3DTexture9 * getRenderTexture(void); ///< returns last used render target texture
static Bool isRenderingToTexture(void) {return m_renderingToTexture; }
static void drawViewport(Int color); ///<draws 2 triangles covering the current tactical viewport
protected:
static TextureClass *m_Textures[8]; ///textures assigned to each of the possible stages
static ChipsetType m_currentChipset; ///<last video card chipset that was detected.
static GraphicsVenderID m_currentVendor; ///<last video card vendor
static Int64 m_driverVersion; ///<driver version of last chipset.
static ShaderTypes m_currentShader; ///<last shader that was set.
static Int m_currentShaderPass; ///<pass of last shader that was set.
static FilterTypes m_currentFilter; ///< Last filter that was set.
// Info for a render to texture surface for special effects.
static Bool m_renderingToTexture;
static IDirect3DSurface9 *m_oldRenderSurface; ///<previous render target
static IDirect3DTexture9 *m_renderTexture; ///<texture into which rendering will be redirected.
static IDirect3DSurface9 *m_newRenderSurface; ///<new render target inside m_renderTexture
static IDirect3DSurface9 *m_oldDepthSurface; ///<previous depth buffer surface
};
class W3DFilterInterface
{
public:
virtual Int init(void) = 0; ///<perform any one time initialization and validation
virtual Int shutdown(void) { return TRUE;}; ///<release resources used by shader
virtual Bool preRender(Bool &skipRender, CustomScenePassModes &scenePassMode) {skipRender=false; return false;} ///< Set up at start of render. Only applies to screen filter shaders.
virtual Bool postRender(enum FilterModes mode, Coord2D &scrollDelta, Bool &doExtraRender){return false;} ///< Called after render. Only applies to screen filter shaders.
virtual Bool setup(enum FilterModes mode){return false;} ///< Called when the filter is started, one time before the first prerender.
protected:
virtual Int set(enum FilterModes mode) = 0; ///<setup shader for the specified rendering pass.
///do any custom resetting necessary to bring W3D in sync.
virtual void reset(void) = 0;
};
/*========= ScreenMotionBlurFilter =============================================================*/
///applies motion blur to viewport.
class ScreenMotionBlurFilter : public W3DFilterInterface
{
public:
virtual Int set(enum FilterModes mode); ///<setup shader for the specified rendering pass.
virtual Int init(void); ///<perform any one time initialization and validation
virtual void reset(void); ///<do any custom resetting necessary to bring W3D in sync.
virtual Int shutdown(void); ///<release resources used by shader
virtual Bool preRender(Bool &skipRender, CustomScenePassModes &scenePassMode); ///< Set up at start of render. Only applies to screen filter shaders.
virtual Bool postRender(enum FilterModes mode, Coord2D &scrollDelta, Bool &doExtraRender); ///< Called after render. Only applies to screen filter shaders.
virtual Bool setup(enum FilterModes mode); ///< Called when the filter is started, one time before the first prerender.
ScreenMotionBlurFilter();
static void setZoomToPos(const Coord3D *pos) {m_zoomToPos = *pos; m_zoomToValid = true;}
protected:
enum {MAX_COUNT = 60,
MAX_LIMIT = 30,
COUNT_STEP = 5,
DEFAULT_PAN_FACTOR = 30};
Int m_maxCount;
Int m_lastFrame;
Bool m_decrement;
Bool m_skipRender;
Bool m_additive;
Bool m_doZoomTo;
Coord2D m_priorDelta;
Int m_panFactor;
static Coord3D m_zoomToPos;
static Bool m_zoomToValid;
} ;
/*========= ScreenBWFilter =============================================================*/
///converts viewport to black & white.
class ScreenBWFilter : public W3DFilterInterface
{
IDirect3DPixelShader9 * m_dwBWPixelShader; ///<pixel shader which tints texture to black & white.
public:
virtual Int init(void); ///<perform any one time initialization and validation
virtual Int shutdown(void); ///<release resources used by shader
virtual Bool preRender(Bool &skipRender, CustomScenePassModes &scenePassMode); ///< Set up at start of render. Only applies to screen filter shaders.
virtual Bool postRender(enum FilterModes mode, Coord2D &scrollDelta,Bool &doExtraRender); ///< Called after render. Only applies to screen filter shaders.
virtual Bool setup(enum FilterModes mode){return true;} ///< Called when the filter is started, one time before the first prerender.
static void setFadeParameters(Int fadeFrames, Int direction)
{
m_curFadeFrame = 0;
m_fadeFrames = fadeFrames;
m_fadeDirection = direction;
}
protected:
virtual Int set(enum FilterModes mode); ///<setup shader for the specified rendering pass.
virtual void reset(void); ///<do any custom resetting necessary to bring W3D in sync.
static Int m_fadeFrames;
static Int m_fadeDirection;
static Int m_curFadeFrame;
static Real m_curFadeValue;
};
class ScreenBWFilterDOT3 : public ScreenBWFilter
{
public:
virtual Int init(void); ///<perform any one time initialization and validation
virtual Int shutdown(void); ///<release resources used by shader
virtual Bool preRender(Bool &skipRender, CustomScenePassModes &scenePassMode); ///< Set up at start of render. Only applies to screen filter shaders.
virtual Bool postRender(enum FilterModes mode, Coord2D &scrollDelta,Bool &doExtraRender); ///< Called after render. Only applies to screen filter shaders.
virtual Bool setup(enum FilterModes mode){return true;} ///< Called when the filter is started, one time before the first prerender.
protected:
virtual Int set(enum FilterModes mode); ///<setup shader for the specified rendering pass.
virtual void reset(void); ///<do any custom resetting necessary to bring W3D in sync.
};
/*========= ScreenCrossFadeFilter =============================================================*/
///Fades between 2 different rendered frames.
class ScreenCrossFadeFilter : public W3DFilterInterface
{
public:
virtual Int init(void); ///<perform any one time initialization and validation
virtual Int shutdown(void); ///<release resources used by shader
virtual Bool preRender(Bool &skipRender, CustomScenePassModes &scenePassMode); ///< Set up at start of render. Only applies to screen filter shaders.
virtual Bool postRender(enum FilterModes mode, Coord2D &scrollDelta,Bool &doExtraRender); ///< Called after render. Only applies to screen filter shaders.
virtual Bool setup(enum FilterModes mode){return true;} ///< Called when the filter is started, one time before the first prerender.
static void setFadeParameters(Int fadeFrames, Int direction)
{
m_curFadeFrame = 0;
m_fadeFrames = fadeFrames;
m_fadeDirection = direction;
}
static Real getCurrentFadeValue(void) { return m_curFadeValue;}
static TextureClass *getCurrentMaskTexture(void) { return m_fadePatternTexture;}
protected:
virtual Int set(enum FilterModes mode); ///<setup shader for the specified rendering pass.
virtual void reset(void); ///<do any custom resetting necessary to bring W3D in sync.
Bool updateFadeLevel(void); ///<updated current state of fade and return true if not finished.
static Int m_fadeFrames;
static Int m_fadeDirection;
static Int m_curFadeFrame;
static Real m_curFadeValue;
static Bool m_skipRender;
static TextureClass *m_fadePatternTexture; ///<shape/pattern of the fade
};
#endif //__W3DSHADERMANAGER_H_