Skip to content

Commit

Permalink
* Minor MiniMap code cleaning
Browse files Browse the repository at this point in the history
* Retain minimap sharpness in case of SSAA (non-zero MinSampleShadingRate)
* Alternative to #1897
  • Loading branch information
lhog committed Feb 8, 2025
1 parent 7989d26 commit 8839f73
Showing 1 changed file with 19 additions and 77 deletions.
96 changes: 19 additions & 77 deletions rts/Game/UI/MiniMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ CONFIG(bool, MiniMapCanFlip).defaultValue(false).description("Whether minimap in
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

#define USE_CLIP_PLANES 0

CMiniMap* minimap = nullptr;

CMiniMap::CMiniMap()
Expand Down Expand Up @@ -1071,16 +1069,16 @@ void CMiniMap::ResizeTextureCache()
{
RECOIL_DETAILED_TRACY_ZONE;
minimapTexSize = curDim;
multisampledFBO = (FBO::GetMaxSamples() > 1);
multisampledFBO = (globalRendering->msaaLevel > 1);

if (multisampledFBO) {
// multisampled FBO we are render to
fbo.Detach(GL_COLOR_ATTACHMENT0_EXT); // delete old RBO
fbo.CreateRenderBufferMultisample(GL_COLOR_ATTACHMENT0_EXT, GL_RGBA8, minimapTexSize.x, minimapTexSize.y, 4);
//fbo.CreateRenderBuffer(GL_DEPTH_ATTACHMENT_EXT, GL_DEPTH_COMPONENT16, minimapTexSize.x, minimapTexSize.y);
fbo.Detach(GL_COLOR_ATTACHMENT0); // will delete old RBO as well
fbo.CreateRenderBufferMultisample(GL_COLOR_ATTACHMENT0, GL_RGBA8, minimapTexSize.x, minimapTexSize.y, globalRendering->msaaLevel);
//fbo.CreateRenderBuffer(GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT16, minimapTexSize.x, minimapTexSize.y);

if (!fbo.CheckStatus("MINIMAP")) {
fbo.Detach(GL_COLOR_ATTACHMENT0_EXT);
fbo.Detach(GL_COLOR_ATTACHMENT0);
multisampledFBO = false;
}
}
Expand All @@ -1091,8 +1089,10 @@ void CMiniMap::ResizeTextureCache()
glBindTexture(GL_TEXTURE_2D, minimapTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

// GL_LINEAR makes no sense for both below, because sampling is always pixel perfect and minimapTex is not exposed outside
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, minimapTexSize.x, minimapTexSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);

if (multisampledFBO) {
Expand Down Expand Up @@ -1149,7 +1149,7 @@ void CMiniMap::UpdateTextureCache()
// resolve multisampled FBO if there is one
if (multisampledFBO) {
const std::array rect = { 0, 0, minimapTexSize.x, minimapTexSize.y };
FBO::Blit(fbo.fboId, fboResolve.fboId, rect, rect, GL_COLOR_BUFFER_BIT, GL_LINEAR);
FBO::Blit(fbo.fboId, fboResolve.fboId, rect, rect, GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
}

Expand Down Expand Up @@ -1299,24 +1299,10 @@ void CMiniMap::DrawForReal(bool useNormalizedCoors, bool updateTex, bool luaCall

cursorIcons.Enable(false);

#if USE_CLIP_PLANES
// clip everything outside of the minimap box
SetClipPlanes(false);
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3);
#endif
DrawBackground();

// allow Lua scripts to overdraw the background image
#if USE_CLIP_PLANES
SetClipPlanes(true);
#endif
eventHandler.DrawInMiniMapBackground();
#if USE_CLIP_PLANES
SetClipPlanes(false);
#endif

DrawUnitIcons();
DrawWorldStuff();
Expand Down Expand Up @@ -1348,13 +1334,6 @@ void CMiniMap::DrawForReal(bool useNormalizedCoors, bool updateTex, bool luaCall
if (useNormalizedCoors && globalRendering->dualScreenMode)
globalRendering->LoadViewport();

// disable ClipPlanes
#if USE_CLIP_PLANES
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
#endif
cursorIcons.Enable(true);
}

Expand Down Expand Up @@ -1384,32 +1363,8 @@ void CMiniMap::DrawCameraFrustumAndMouseSelection()

if (!minimap->maximized) {
// draw the camera frustum lines
// CCamera* cam = CCameraHandler::GetCamera(CCamera::CAMTYPE_SHADOW);
CCamera* cam = CCameraHandler::GetCamera(CCamera::CAMTYPE_PLAYER);

//this one is bugged, probably because CalcFrustumLines is bugged as well
// TODO: Investigate
#if 0
cam->CalcFrustumLines(readMap->GetCurrAvgHeight(), readMap->GetCurrAvgHeight(), 1.0f, true);
cam->ClipFrustumLines(-100.0f, mapDims.mapy * SQUARE_SIZE + 100.0f, true);

const CCamera::FrustumLine* negLines = cam->GetNegFrustumLines();

CVertexArray* va = GetVertexArray();
va->Initialize();
va->EnlargeArrays(4 * 2, 0, VA_SIZE_2D0);


for (int idx = 0; idx < /*negLines[*/4/*].sign*/; idx++) {
const CCamera::FrustumLine& fl = negLines[idx];

if (fl.minz >= fl.maxz)
continue;

va->AddVertexQ2d0((fl.dir * fl.minz) + fl.base, fl.minz);
va->AddVertexQ2d0((fl.dir * fl.maxz) + fl.base, fl.maxz);
}
#else
const auto& pos = cam->GetPos();
const auto& dir = cam->GetForward();

Expand Down Expand Up @@ -1477,7 +1432,6 @@ void CMiniMap::DrawCameraFrustumAndMouseSelection()
sh.Disable();

glLineWidth(1.0f);
#endif
}


Expand All @@ -1497,6 +1451,7 @@ void CMiniMap::DrawCameraFrustumAndMouseSelection()
{newMapPos.x, newMapPos.z},
{oldMapPos.x, newMapPos.z}
});

sh.Enable();
sh.SetUniform("ucolor", cmdColors.mouseBox[0], cmdColors.mouseBox[1], cmdColors.mouseBox[2], cmdColors.mouseBox[3]);
rb.DrawArrays(GL_LINE_LOOP);
Expand All @@ -1508,15 +1463,6 @@ void CMiniMap::DrawCameraFrustumAndMouseSelection()

DrawNotes();


// disable ClipPlanes
#if USE_CLIP_PLANES
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
#endif

glPopMatrix();

glDisable(GL_SCISSOR_TEST);
Expand Down Expand Up @@ -1825,16 +1771,20 @@ void CMiniMap::DrawBackground() const
glLoadMatrixf(projMats[0]);

// draw the map
glDisable(GL_BLEND);
auto state = GL::SubState(
Blending(GL_FALSE),
SampleShading(GL_FALSE) // sample shading is detrimental for minimap background sharpness
);

if (globalRendering->minSampleShadingRate > 0)
glDisable(GL_SAMPLE_SHADING);

readMap->BindMiniMapTextures();
bgShader->Enable();
bgShader->SetUniform("infotexMul", static_cast<float>(infoTextureHandler->IsEnabled()));
rb.DrawElements(GL_TRIANGLES);
bgShader->Disable();

glEnable(GL_BLEND);

//glMatrixMode(GL_PROJECTION);
glPopMatrix();

Expand All @@ -1845,10 +1795,7 @@ void CMiniMap::DrawBackground() const
void CMiniMap::DrawUnitIcons() const
{
ZoneScopedN("MiniMap::DrawUnitIcons");
#if USE_CLIP_PLANES
for (int i = 0; i < 4; ++i)
glDisable(GL_CLIP_PLANE0 + i);
#endif

glEnable(GL_SCISSOR_TEST);
glScissor(curPos.x, curPos.y, curDim.x, curDim.y);

Expand All @@ -1864,11 +1811,6 @@ void CMiniMap::DrawUnitIcons() const
glPopMatrix();

glDisable(GL_SCISSOR_TEST);

#if USE_CLIP_PLANES
for (int i = 0; i < 4; ++i)
glEnable(GL_CLIP_PLANE0 + i);
#endif
}


Expand Down

0 comments on commit 8839f73

Please sign in to comment.