Skip to content

feat(texturefilter): Extend texture filtering to support; none, point, bilinear, trilinear and anisitropic filtering#2423

Open
Mauller wants to merge 7 commits intoTheSuperHackers:mainfrom
Mauller:Mauller/feat-improve-filtering-support
Open

feat(texturefilter): Extend texture filtering to support; none, point, bilinear, trilinear and anisitropic filtering#2423
Mauller wants to merge 7 commits intoTheSuperHackers:mainfrom
Mauller:Mauller/feat-improve-filtering-support

Conversation

@Mauller
Copy link

@Mauller Mauller commented Mar 8, 2026

This PR cleans up the texture filtering class and extends its functionality.

This can be squash merged, i seperated it into commits to make it easier to follow the changes when reviewing.

By default the game was stuck with Bilinear filtering, as they never added options to allow texture filtering to be altered within the game. This PR cleans up the original code and extends the support for more filtering modes.

At the moment this does nothing new. we still need to add the external code to set a different filtering mode, so the game still defaults to bilinear mode.

But now we have the following modes:

No filtering - Point filtering when minifying or maximising textures, mipmaps have no filtering
Point Filtering - The same as no filtering but mip maps now have point filtering
Bilinear - Default, Minifying and maximising now has linear filtering, mipmaps retain point filtering
Trilinear - The same as Bilinear but mipmaps now gain linear filtering
Anisotropic - Minifying and maximising now has anisotropic filtering and mip maps retain linear filtering.

Anisotropic filtering is defaulted to 2x which is the minimum and has a new static function to change the filtering mode.


If you want to test the changes, alter the int WW3D::TextureFilter variable in ww3d.cpp

@Mauller Mauller self-assigned this Mar 8, 2026
@Mauller Mauller added Enhancement Is new feature or request Gen Relates to Generals ZH Relates to Zero Hour labels Mar 8, 2026
@greptile-apps
Copy link

greptile-apps bot commented Mar 8, 2026

Greptile Summary

This PR extends TextureFilterClass to support five distinct texture filtering modes — None, Point, Bilinear, Trilinear, and Anisotropic — replacing the previous hard-wired bilinear default and the removed Xbox branch. The WW3D::TextureFilter default is updated in both Generals/ and GeneralsMD/ from a raw 0 to the explicit TEXTURE_FILTER_BILINEAR enum value, correctly preserving the retail game's behaviour while making the intent clear.

Key changes:

  • TextureFilterMode enum gains TEXTURE_FILTER_NONE and TEXTURE_FILTER_POINT; a new AnisotropicFilterMode enum exposes 2×/4×/8×/16× levels.
  • _Init_Filters is rewritten as a capability-checked switch, with a default that crashes in debug and falls through to no-filtering in release (now properly annotated with FALLTHROUGH).
  • A new _Set_Max_Anisotropy static function centralises D3DTSS_MAXANISOTROPY updates across all texture stages, replacing the previous hard-coded 2 set unconditionally in the propagation loop.
  • Stage propagation is simplified from [i-1] chaining to direct copies from stage 0, making the intent unambiguous and fixing a latent chaining bug.

The implementation is sound, capability checks are thorough, and existing retail behaviour is preserved by default.

Confidence Score: 5/5

  • Safe to merge — logic is sound, capability checks are thorough, and existing retail behaviour is correctly preserved.
  • The refactoring is well-structured and the switch-based design correctly handles all five filter modes with hardware capability fallbacks. The removal of the Xbox branch and the simplification of the stage-propagation loop are both improvements. The code passes all functional and safety verification.
  • No files require special attention.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["_Init_Filters(filter_type)"] --> B["Set stage-0 defaults\n(NONE=POINT, FAST=LINEAR/POINT, BEST=ANISO/LINEAR)"]
    B --> C{filter_type}

    C -->|default / invalid| D["DEBUG_CRASH\nFALLTHROUGH"]
    D --> E

    C -->|TEXTURE_FILTER_NONE| E["FAST & BEST → POINT\nMip → D3DTEXF_NONE"]
    C -->|TEXTURE_FILTER_POINT| F["FAST & BEST → POINT\nMip → POINT"]
    C -->|TEXTURE_FILTER_BILINEAR| G{"LINEAR caps\nsupported?"}
    C -->|TEXTURE_FILTER_TRILINEAR| H{"LINEAR caps\nsupported?"}
    C -->|TEXTURE_FILTER_ANISOTROPIC| I{"ANISO caps\nsupported?"}

    G -->|Yes| G1["BEST min/mag → LINEAR\nMip → POINT"]
    G -->|No| G2["BEST min/mag → POINT\nMip → POINT"]

    H -->|Yes| H1["BEST min/mag → LINEAR"]
    H -->|No| H2["BEST min/mag → POINT"]
    H1 & H2 --> H3{"MIPFLINEAR\nsupported?"}
    H3 -->|Yes| H4["Mip → LINEAR (Trilinear)"]
    H3 -->|No| H5["Mip → POINT (fallback Bilinear)"]

    I -->|Yes| I1["BEST min/mag → ANISO\n_Set_Max_Anisotropy(2×)"]
    I -->|No| I2["BEST min/mag → POINT"]
    I1 & I2 --> I3{"MIPFLINEAR\nsupported?"}
    I3 -->|Yes| I4["Mip → LINEAR"]
    I3 -->|No| I5["Mip → POINT"]

    E & F & G1 & G2 & H4 & H5 & I4 & I5 --> J["Propagate stage 0 → stages 1..N\n(ANISO stages use LINEAR instead)"]
    J --> K["Copy BEST → DEFAULT for all stages"]
Loading

Last reviewed commit: 2df4a8a

@Mauller Mauller force-pushed the Mauller/feat-improve-filtering-support branch 2 times, most recently from 67a9d46 to 57753f7 Compare March 8, 2026 12:39
@Mauller Mauller force-pushed the Mauller/feat-improve-filtering-support branch from 57753f7 to 2df4a8a Compare March 8, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Is new feature or request Gen Relates to Generals ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant