|
OpenCoD2-Plus
Call of Duty 2 client & server, rebuilt
|
src/PC/gfx_d3d: the reconstruction of gfx_d3d_mp_x86_s.dll 1.3, linked into the client (no separate DLL: ADR 0007).
| Build | Device | Shaders |
|---|---|---|
| Windows client (default, COD2_WIN32_REAL_D3D9=ON, GFX_REAL_D3D9) | real IDirect3DDevice9 | the game's materials/shaders/*.hlsl, compiled with the system's d3dx9 (d3dx9_43 down to d3dx9_24), // comments blanked first (Wine's compiler rejects one after an #include) |
| Linux client cod2_linux (default, COD2_LINUX_DXVK=ON, GFX_REAL_D3D9) | DXVK native's IDirect3DDevice9, over Vulkan | the game's shaders, compiled with vkd3d-shader |
| Windows client with COD2_WIN32_REAL_D3D9=OFF, Linux client with COD2_LINUX_DXVK=OFF | Mac port's GL layer behind a Direct3D interface (src/Mac) | hand-written ARB programs picked by HLSL keywords: no sun, no specular, white world |
Decisions: ADR 0008, ADR 0009.
The GL device's window (MacDisplay_CreateScreenContext, src/stubs/macos_compat.c) is full screen with r_fullscreen, read only and so always 1 as in 1.3: the display switches to r_mode's size (SDL_WINDOW_FULLSCREEN), as 1.3's full-screen device does, since the GL layer draws straight to a drawable of that size. A mode the display does not list leaves a window.
| Item | Detail |
|---|---|
| Window | an SDL window (Sys_CreateD3DWindow, src/stubs/macos_compat.c) so IN_Frame keeps the input; size from r_mode; r_fullscreen 1 covers the desktop and the frame of r_mode's size is stretched over it |
| Modes | r_mode lists the display's modes (Sys_EnumDisplayModes, via SDL), as the original lists the adapter's |
| Aspect | r_aspectRatio (0x10011610): 4:3, 16:10, 16:9; auto rounds the window's shape, or the monitor's when full screen |
| Screenshots | GetRenderTargetData of the back buffer before Present |
| COM calls | through D3DVTCC (stdcall on a real device, empty for the GL device) |
| Picmip | by texture memory, as 0x1000d6a0; Windows system info from GlobalMemoryStatusEx, the processor's registry key and the primary display device; Linux's CPU speed is cpufreq's rated maximum (cpuinfo_max_freq), not /proc/cpuinfo's current clock, which moved past the 10% Sys_HasInfoChanged allows and reset the profile's settings (r_mode among them) every start |
| vid_restart | refused while a local server runs ("Listen server cannot video restart"), as the original |
The DXVK Linux client runs the same GFX_REAL_D3D9 renderer code; only three seams differ from Windows, each #if defined(GFX_REAL_D3D9) && !defined(_WIN32):
| Seam | Linux |
|---|---|
| Device (RealD3D9_Direct3DCreate9, src/Mac/DirectX_9/d3d9_real.c) | dlopen of libdxvk_d3d9.so.0, next to the executable first; DXVK_WSI_DRIVER=SDL2; SDL's video initialised first. DXVK ends the process when Vulkan has no device it can use (none, or none with Vulkan 1.3), so Direct3DCreate9 is tried first in a forked child; no library, no usable device or a failed CreateDevice is a fatal renderer error |
| Window (Sys_CreateD3DWindow, src/stubs/macos_compat.c) | the SDL window with SDL_WINDOW_VULKAN, passed as the HWND (DXVK's SDL2 window system takes the SDL_Window*) |
| Shaders (src/Mac/DirectX_9/d3dx_vkd3d.c) | D3DXCompileShader through libvkd3d-shader.so.1 (HLSL to Direct3D 9 bytecode, the include object as callbacks); D3DXGetShaderConstantTable reads the bytecode's CTAB comment |
COM calls are cdecl there (D3DVTCC is stdcall on Windows only), as DXVK native declares them. scripts/build_linux_vk_deps.sh builds both libraries (DXVK v2.7.1, vkd3d 1.19, 32-bit) into third_party/linux-vk/, and with x64 64-bit into third_party/linux-vk64/ for the x64 client; neither is in git; the build copies them next to cod2_linux. Under WSL the only Vulkan device is llvmpipe (the processor): correct pictures, slow.
| Table | Address in the 1.3 dll | Without it |
|---|---|---|
| light grid basis, cube face axes ($lightgridweights) | 0x100104c0, 0x10010180 | view weapon and players black |
| particle cloud quad indices and corners | 0x10011c40 | every quad a point |
| particle cloud draw counts (RB_TessParticleCloud) | 0x10041405 | no cloud drawn |
| outdoor map size {512, 512, 256} | 0x10190398 | nothing outdoors |
A water material (techset water, texture semantic 5) carries the parameters of a wave simulation: RB_UploadWaterTexture (r_water.c) runs an FFT of them each frame into its height map, as 1.3 does when it binds the map (gfx_d3d_mp_x86_s.dll 0x1003a2db), behind r_drawWater. Until 2026-11-02 nothing called it, so every water surface stood still and flat.
r_water 1 (the default; 0 is 1.3's, after vid_restart) gives the real Direct3D 9 path our text for the game's lib/water.hlsl (r_water_hlsl.h, served by RealInclude_Open in D3DXShader.c): two layers of that height map drifting with gameTime, Schlick's fresnel between the water's color and the reflection of the map's own sky (skySampler, a default code sampler of ours on sampler.sky; the material's generic cube keeps only its alpha as reflectivity), and a sharper sun highlight. A map without a sky gives that sampler $watercolor instead of 1.3's error. Same inputs and material arguments; its pixel shader compiles as ps_2_a (512 slots): Microsoft's compiler counts 91 arithmetic slots, past ps_2_0's 64.
With r_water on the real Direct3D 9 path, no antialiasing and a card that takes it, the frame buffer's depth is an INTZ texture (r_rendertarget.c), which floatZ binds (1.3 binds nothing there on PC). The water's shader reads the scene's depth behind each pixel: under 1.3's infinite far plane a depth d is 1 - near / z, so each water pixel finds near from its own depth and turns the scene's into a distance. Shallow water foams at the shore; water materials draw without writing depth while they read it. Without INTZ floatZ reads 0, which the shader takes as deep water.
With that depth the water also refracts: before the first water surface of a draw list, RB_EndSurface copies the scene drawn so far into resolvedScene (renderTargets[2], which 1.3 fills only for its late post effects), bound by name as sceneColorSampler. The shader shows it under the water, bent by the waves' normal (a bent sample that lands on something in front of the water takes the straight one), clear at the shore and fading into the water's color 160 units down; the water is then opaque, as its vertex alpha says. Over the void (mp_harbor's open sea) it is the water's color, as before. Without INTZ there is no copy and water fades by alpha; sceneColorSampler then gets black (1.3 never binds resolvedScene without a copy: techFlags & 2 skips the technique, which a sampler bound by name does not set). floatZ gets the INTZ depth only for water materials, the ones that stop writing it. Techniques with sampler.resolvedScene drawn after the water see its copy for the rest of the frame, where 1.3 would skip them.
The sky's surfaces are the ones whose material has bit 8 in gameFlags (1.3 0x10002cb0); until 2026-11-02 the loader read surfaceFlags, found none, so sampler.sky had no image and the visibility pass never added the sky past the far plane, as 1.3 does. The GL device keeps its stand-in shaders. Stock maps with this water: mp_harbor only; custom maps reuse its materials (water_duhoc in sps_island).
src/PC/gfx_d3d/r_outdoor.c: a 512×512 height map of the world, traced from above the world's bounds (max z + 1) down to min z − 1 (0x10020790); each texel is the hit height scaled to 0..255. particle_cloud_outdoor hides a cloud particle below it (indoors). Under Wine that shader does not compile (see ../roadmap/debt.md).
*smodel_lighting is a volume texture; Image_UploadData writes volumes and R_CacheStaticModelLighting writes texels as B, G, R, A (A8R8G8B8). The GL device's volumes cannot be locked, so that path is unchanged.