Do proper rounding in set_viewport.

Avoids edge cases where viewport sizes are miscalculated with -1 pixel
due to rounding errors.
This commit is contained in:
Themaister 2013-09-12 22:23:56 +02:00
parent 04a1b4b652
commit 178dc692c7
2 changed files with 12 additions and 12 deletions

View File

@ -363,17 +363,17 @@ void D3DVideo::calculate_rect(unsigned width, unsigned height,
else
{
float device_aspect = static_cast<float>(width) / static_cast<float>(height);
if (fabs(device_aspect - desired_aspect) < 0.0001)
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
set_viewport(0, 0, width, height);
else if (device_aspect > desired_aspect)
{
float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
set_viewport(width * (0.5 - delta), 0, 2.0 * width * delta, height);
float delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
set_viewport(int(roundf(width * (0.5f - delta))), 0, unsigned(roundf(2.0f * width * delta)), height);
}
else
{
float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
set_viewport(0, height * (0.5 - delta), width, 2.0 * height * delta);
float delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
set_viewport(0, int(roundf(height * (0.5f - delta))), width, unsigned(roundf(2.0f * height * delta)));
}
}
}

View File

@ -783,22 +783,22 @@ void gl_set_viewport(void *data, unsigned width, unsigned height, bool force_ful
else
#endif
{
if (fabs(device_aspect - desired_aspect) < 0.0001)
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
{
// If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff),
// assume they are actually equal.
}
else if (device_aspect > desired_aspect)
{
delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
x = (unsigned)(width * (0.5 - delta));
width = (unsigned)(2.0 * width * delta);
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
x = (int)roundf(width * (0.5f - delta));
width = (unsigned)roundf(2.0f * width * delta);
}
else
{
delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
y = (unsigned)(height * (0.5 - delta));
height = (unsigned)(2.0 * height * delta);
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
y = (int)roundf(height * (0.5f - delta));
height = (unsigned)roundf(2.0f * height * delta);
}
}