Skip to content

Commit

Permalink
Move no-mipmapping from actor renderflag/particle flag, to a material…
Browse files Browse the repository at this point in the history
… property in GLDEFS, where it makes more sense. The feature was introduced in the short-lived engine version of 4.13 which was deemed too broken and needed to be replaced with a newer version anyway, so might as well perform an API-breaking change at this point in time. Note that this currently only works for sprites (its primary targeted use case) -- walls, flats and models can be patched in later.
  • Loading branch information
nashmuhandes authored and madame-rachelle committed Oct 19, 2024
1 parent 5fb83d4 commit a45bf49
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/common/textures/gametexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum EGameTexFlags
GTexf_OffsetsNotForFont = 512, // The offsets must be ignored when using this texture in a font.
GTexf_NoTrim = 1024, // Don't perform trimming on this texture.
GTexf_Seen = 2048, // Set to true when the texture is being used for rendering. Must be cleared manually if the check is needed.
GTexf_NoMipmap = 4096, // Disable mipmapping for this texture
};

struct FMaterialLayers
Expand Down Expand Up @@ -265,6 +266,9 @@ class FGameTexture
void SetGlowing(PalEntry color) { flags = (flags & ~GTexf_AutoGlowing) | GTexf_Glowing; GlowColor = color; }
void SetDisableBrightmap() { flags |= GTexf_BrightmapChecked; Brightmap = nullptr; }

bool isNoMipmap() const { return !!(flags & GTexf_NoMipmap); }
void SetNoMipmap(bool set) { if (set) flags |= GTexf_NoMipmap; else flags &= ~GTexf_NoMipmap; }

bool isUserContent() const;
int CheckRealHeight() { return xs_RoundToInt(Base->CheckRealHeight() / ScaleY); }
void SetSize(int x, int y)
Expand Down
7 changes: 3 additions & 4 deletions src/playsim/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,9 @@ enum ActorRenderFlag2
RF2_FLIPSPRITEOFFSETX = 0x0010,
RF2_FLIPSPRITEOFFSETY = 0x0020,
RF2_CAMFOLLOWSPLAYER = 0x0040, // Matches the cam's base position and angles to the main viewpoint.
RF2_NOMIPMAP = 0x0080, // [Nash] forces no mipmapping on sprites. Useful for tiny sprites that need to remain visually crisp
RF2_ISOMETRICSPRITES = 0x0100,
RF2_SQUAREPIXELS = 0x0200, // apply +ROLLSPRITE scaling math so that non rolling sprites get the same scaling
RF2_STRETCHPIXELS = 0x0400, // don't apply SQUAREPIXELS for ROLLSPRITES
RF2_ISOMETRICSPRITES = 0x0080,
RF2_SQUAREPIXELS = 0x0100, // apply +ROLLSPRITE scaling math so that non rolling sprites get the same scaling
RF2_STRETCHPIXELS = 0x0200, // don't apply SQUAREPIXELS for ROLLSPRITES
};

// This translucency value produces the closest match to Heretic's TINTTAB.
Expand Down
3 changes: 1 addition & 2 deletions src/playsim/p_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ enum EParticleFlags
SPF_FACECAMERA = 1 << 11,
SPF_NOFACECAMERA = 1 << 12,
SPF_ROLLCENTER = 1 << 13,
SPF_NOMIPMAP = 1 << 14,
SPF_STRETCHPIXELS = 1 << 15,
SPF_STRETCHPIXELS = 1 << 14,
};

class DVisualThinker;
Expand Down
14 changes: 14 additions & 0 deletions src/r_data/gldefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@ class GLDefsParser
bool disable_fullbright_specified = false;
bool thiswad = false;
bool iwad = false;
bool no_mipmap = false;

UserShaderDesc usershader;
TArray<FString> texNameList;
Expand Down Expand Up @@ -1319,6 +1320,10 @@ class GLDefsParser
// only affects textures defined in the IWAD.
iwad = true;
}
else if (sc.Compare("nomipmap"))
{
no_mipmap = true;
}
else if (sc.Compare("glossiness"))
{
sc.MustGetFloat();
Expand Down Expand Up @@ -1422,6 +1427,8 @@ class GLDefsParser
if (!useme) return;
}

tex->SetNoMipmap(no_mipmap);

FGameTexture **bindings[6] =
{
&mlay.Brightmap,
Expand Down Expand Up @@ -1681,6 +1688,7 @@ class GLDefsParser
bool disable_fullbright = false;
bool thiswad = false;
bool iwad = false;
bool no_mipmap = false;
int maplump = -1;
UserShaderDesc desc;
desc.shaderType = SHADER_Default;
Expand Down Expand Up @@ -1723,6 +1731,10 @@ class GLDefsParser
if (!found)
sc.ScriptError("Unknown material type '%s' specified\n", sc.String);
}
else if (sc.Compare("nomipmap"))
{
no_mipmap = true;
}
else if (sc.Compare("speed"))
{
sc.MustGetFloat();
Expand Down Expand Up @@ -1784,6 +1796,8 @@ class GLDefsParser
return;
}

tex->SetNoMipmap(no_mipmap);

int firstUserTexture;
switch (desc.shaderType)
{
Expand Down
2 changes: 0 additions & 2 deletions src/rendering/hwrenderer/scene/hw_drawstructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,6 @@ class HWSprite
TArray<lightlist_t> *lightlist;
DRotator Angles;

bool nomipmap; // force the sprite to have no mipmaps (ensures tiny sprites in the distance stay crisp)

void SplitSprite(HWDrawInfo *di, sector_t * frontsector, bool translucent);
void PerformSpriteClipAdjustment(AActor *thing, const DVector2 &thingpos, float spriteheight);
bool CalculateVertices(HWDrawInfo *di, FVector3 *v, DVector3 *vp);
Expand Down
10 changes: 6 additions & 4 deletions src/rendering/hwrenderer/scene/hw_sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
state.SetFog(0, 0);
}

int clampmode = nomipmap ? CLAMP_XY_NOMIP : CLAMP_XY;
int clampmode = CLAMP_XY;

if (texture && texture->isNoMipmap())
{
clampmode = CLAMP_XY_NOMIP;
}

uint32_t spritetype = actor? uint32_t(actor->renderflags & RF_SPRITETYPEMASK) : 0;
if (texture) state.SetMaterial(texture, UF_Sprite, (spritetype == RF_FACESPRITE) ? CTF_Expand : 0, clampmode, translation, OverrideShader);
Expand Down Expand Up @@ -786,8 +791,6 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
return;
}

nomipmap = (thing->renderflags2 & RF2_NOMIPMAP);

// check renderrequired vs ~r_rendercaps, if anything matches we don't support that feature,
// check renderhidden vs r_rendercaps, if anything matches we do support that feature and should hide it.
if ((!r_debug_disable_vis_filter && !!(thing->RenderRequired & ~r_renderercaps)) ||
Expand Down Expand Up @@ -1420,7 +1423,6 @@ void HWSprite::ProcessParticle(HWDrawInfo *di, particle_t *particle, sector_t *s
actor = nullptr;
this->particle = particle;
fullbright = particle->flags & SPF_FULLBRIGHT;
nomipmap = particle->flags & SPF_NOMIPMAP;

if (di->isFullbrightScene())
{
Expand Down
1 change: 0 additions & 1 deletion src/scripting/thingdef_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ static FFlagDef ActorFlagDefs[]=
DEFINE_FLAG(RF2, FLIPSPRITEOFFSETX, AActor, renderflags2),
DEFINE_FLAG(RF2, FLIPSPRITEOFFSETY, AActor, renderflags2),
DEFINE_FLAG(RF2, CAMFOLLOWSPLAYER, AActor, renderflags2),
DEFINE_FLAG(RF2, NOMIPMAP, AActor, renderflags2),
DEFINE_FLAG(RF2, ISOMETRICSPRITES, AActor, renderflags2),
DEFINE_FLAG(RF2, SQUAREPIXELS, AActor, renderflags2),

Expand Down
3 changes: 1 addition & 2 deletions wadsrc/static/zscript/constants.zs
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,7 @@ enum EParticleFlags
SPF_FACECAMERA = 1 << 11,
SPF_NOFACECAMERA = 1 << 12,
SPF_ROLLCENTER = 1 << 13,
SPF_NOMIPMAP = 1 << 14,
SPF_STRETCHPIXELS = 1 << 15,
SPF_STRETCHPIXELS = 1 << 14,

SPF_RELATIVE = SPF_RELPOS|SPF_RELVEL|SPF_RELACCEL|SPF_RELANG
};
Expand Down

0 comments on commit a45bf49

Please sign in to comment.