Skip to content

Commit f5fd6db

Browse files
committed
fix: point-filter window for even DPI factors
We emulate DPI scaling by drawing to a smaller render target and scale it up with bilinear filtering to the desired DPI scale factor configured in the OS. Windows seems to do crisper point filtering (nearest neighbour) for scale factors that are multiples of 100%. This commit alters our behaviour to select the filter mode based on the DPI scale factor, opting for point filtering for non-fractional scaling.
1 parent b8503a5 commit f5fd6db

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

engine/render/r_main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ void r_renderer_c::BeginFrame()
11341134
auto& vid = sys->video->vid;
11351135
int wNew = VirtualScreenWidth();
11361136
int hNew = VirtualScreenHeight();
1137+
bool const wantIntegerScaling = fmodf(vid.dpiScale, 1.0f) < 0.0005f;
11371138
for (int i = 0; i < 2; ++i) {
11381139
auto& rtt = rttMain[i];
11391140
if (rtt.width != wNew || rtt.height != hNew) {
@@ -1144,8 +1145,9 @@ void r_renderer_c::BeginFrame()
11441145
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, wNew, hNew, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
11451146
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
11461147
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1147-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1148-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1148+
GLint const filterMode = wantIntegerScaling ? GL_NEAREST : GL_LINEAR;
1149+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filterMode);
1150+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filterMode);
11491151

11501152
rtt.width = wNew;
11511153
rtt.height = hNew;

0 commit comments

Comments
 (0)