Skip to content

Commit af2f0aa

Browse files
committed
Update integer scaling.
This fixes a scaling issue where xemu scales the framebuffer against the size of the window. Uneven scaling would cause the texture to become blurry, or misaligned. Instead, we just render the framebuffer at a single size and adjust the position using offsets.
1 parent e7f4263 commit af2f0aa

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

ui/xui/gl-helpers.cc

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -884,14 +884,14 @@ void ScaleDimensions(int src_width, int src_height, int max_width, int max_heigh
884884
}
885885
}
886886

887-
void RenderFramebuffer(GLint tex, int width, int height, bool flip, float scale[2])
887+
void RenderFramebuffer(GLint tex, int offset_x, int offset_y, int width, int height, bool flip, float scale[2])
888888
{
889889
glActiveTexture(GL_TEXTURE0);
890890
glBindTexture(GL_TEXTURE_2D, tex);
891891

892892
DecalShader *s = g_framebuffer_shader;
893893
s->flip = flip;
894-
glViewport(0, 0, width, height);
894+
glViewport(offset_x, offset_y, width, height);
895895
glUseProgram(s->prog);
896896
glBindVertexArray(s->vao);
897897
glUniform1i(s->flipy_loc, s->flip);
@@ -933,6 +933,7 @@ void RenderFramebuffer(GLint tex, int width, int height, bool flip)
933933
{
934934
int tw, th;
935935
float scale[2];
936+
int offset_x = 0, offset_y = 0;
936937

937938
glActiveTexture(GL_TEXTURE0);
938939
glBindTexture(GL_TEXTURE_2D, tex);
@@ -952,12 +953,18 @@ void RenderFramebuffer(GLint tex, int width, int height, bool flip)
952953
} else if (g_config.display.ui.fit == CONFIG_DISPLAY_UI_FIT_INTEGER) {
953954
// Integer scaling
954955
float t_ratio = GetDisplayAspectRatio(tw, th);
955-
int s_factor = (float)width/(float)tw;
956-
int s_height = (float)height/(float)th;
957-
if (s_height < s_factor) s_factor = s_height;
958-
if (s_factor < 1) s_factor = 1;
959-
scale[0] = s_factor*t_ratio*(int)th/(float)width;
960-
scale[1] = s_factor*(int)th/(float)height;
956+
int factor = width / (th * t_ratio);
957+
int factor_h = height / th;
958+
factor = (factor_h < factor) ? factor_h : factor;
959+
factor = (factor <= 1) ? 1 : factor;
960+
int fb_height = th * factor;
961+
int fb_width = (int)(fb_height * t_ratio);
962+
offset_x = (width - fb_width) / 2;
963+
offset_y = (height - fb_height) / 2;
964+
width = fb_width;
965+
height = fb_height;
966+
scale[0] = 1.0;
967+
scale[1] = 1.0;
961968
} else {
962969
float t_ratio = GetDisplayAspectRatio(tw, th);
963970
float w_ratio = (float)width/(float)height;
@@ -970,12 +977,13 @@ void RenderFramebuffer(GLint tex, int width, int height, bool flip)
970977
}
971978
}
972979

973-
RenderFramebuffer(tex, width, height, flip, scale);
980+
RenderFramebuffer(tex, offset_x, offset_y, width, height, flip, scale);
974981
}
975982

976983
bool RenderFramebufferToPng(GLuint tex, bool flip, std::vector<uint8_t> &png, int max_width, int max_height)
977984
{
978985
int width, height;
986+
int offset_x = 0, offset_y = 0;
979987

980988
glActiveTexture(GL_TEXTURE0);
981989
glBindTexture(GL_TEXTURE_2D, tex);
@@ -996,7 +1004,7 @@ bool RenderFramebufferToPng(GLuint tex, bool flip, std::vector<uint8_t> &png, in
9961004
bool blend = glIsEnabled(GL_BLEND);
9971005
if (blend) glDisable(GL_BLEND);
9981006
float scale[2] = {1.0, 1.0};
999-
RenderFramebuffer(tex, width, height, !flip, scale);
1007+
RenderFramebuffer(tex, offset_x, offset_y, width, height, !flip, scale);
10001008
if (blend) glEnable(GL_BLEND);
10011009
glPixelStorei(GL_PACK_ROW_LENGTH, width);
10021010
glPixelStorei(GL_PACK_IMAGE_HEIGHT, height);

ui/xui/gl-helpers.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void RenderControllerPort(float frame_x, float frame_y, int i,
5050
void RenderXmu(float frame_x, float frame_y, uint32_t primary_color,
5151
uint32_t secondary_color);
5252
void RenderFramebuffer(GLint tex, int width, int height, bool flip);
53-
void RenderFramebuffer(GLint tex, int width, int height, bool flip, float scale[2]);
53+
void RenderFramebuffer(GLint tex, int offset_x, int offset_y, int width, int height, bool flip, float scale[2]);
5454
bool RenderFramebufferToPng(GLuint tex, bool flip, std::vector<uint8_t> &png, int max_width = 0, int max_height = 0);
5555
void SaveScreenshot(GLuint tex, bool flip);
5656
void ScaleDimensions(int src_width, int src_height, int max_width, int max_height, int *out_width, int *out_height);

0 commit comments

Comments
 (0)