|
|
@ -191,8 +191,8 @@ void RendererOpenGL::DrawSingleScreenRotated(const TextureInfo& texture, float x
|
|
|
|
* Draws the emulated screens to the emulator window.
|
|
|
|
* Draws the emulated screens to the emulator window.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void RendererOpenGL::DrawScreens() {
|
|
|
|
void RendererOpenGL::DrawScreens() {
|
|
|
|
UpdateViewportExtent();
|
|
|
|
auto viewport_extent = GetViewportExtent();
|
|
|
|
glViewport(viewport_extent.x, viewport_extent.y, viewport_extent.width, viewport_extent.height);
|
|
|
|
glViewport(viewport_extent.left, viewport_extent.top, viewport_extent.GetWidth(), viewport_extent.GetHeight()); // TODO: Or bottom?
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(program_id);
|
|
|
|
glUseProgram(program_id);
|
|
|
@ -229,37 +229,32 @@ void RendererOpenGL::SetWindow(EmuWindow* window) {
|
|
|
|
render_window = window;
|
|
|
|
render_window = window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RendererOpenGL::UpdateViewportExtent() {
|
|
|
|
MathUtil::Rectangle<unsigned> RendererOpenGL::GetViewportExtent() {
|
|
|
|
unsigned width_in_pixels;
|
|
|
|
unsigned framebuffer_width;
|
|
|
|
unsigned height_in_pixels;
|
|
|
|
unsigned framebuffer_height;
|
|
|
|
|
|
|
|
std::tie(framebuffer_width, framebuffer_height) = render_window->GetFramebufferSize();
|
|
|
|
|
|
|
|
|
|
|
|
std::tie(width_in_pixels, height_in_pixels) = render_window->GetFramebufferSize();
|
|
|
|
float window_aspect_ratio = static_cast<float>(framebuffer_height) / framebuffer_width;
|
|
|
|
|
|
|
|
|
|
|
|
// No update needed if framebuffer size hasn't changed
|
|
|
|
|
|
|
|
if (width_in_pixels == framebuffer_size.width && height_in_pixels == framebuffer_size.height) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
framebuffer_size.width = width_in_pixels;
|
|
|
|
|
|
|
|
framebuffer_size.height = height_in_pixels;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float window_aspect_ratio = static_cast<float>(height_in_pixels) / width_in_pixels;
|
|
|
|
|
|
|
|
float emulation_aspect_ratio = static_cast<float>(resolution_height) / resolution_width;
|
|
|
|
float emulation_aspect_ratio = static_cast<float>(resolution_height) / resolution_width;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathUtil::Rectangle<unsigned> viewport_extent;
|
|
|
|
if (window_aspect_ratio > emulation_aspect_ratio) {
|
|
|
|
if (window_aspect_ratio > emulation_aspect_ratio) {
|
|
|
|
// If the window is more narrow than the emulation content, borders are applied on the
|
|
|
|
// Window is narrower than the emulation content => apply borders to the top and bottom
|
|
|
|
// top and bottom of the window.
|
|
|
|
unsigned viewport_height = emulation_aspect_ratio * framebuffer_width;
|
|
|
|
viewport_extent.width = width_in_pixels;
|
|
|
|
viewport_extent.left = 0;
|
|
|
|
viewport_extent.height = emulation_aspect_ratio * viewport_extent.width;
|
|
|
|
viewport_extent.top = (framebuffer_height - viewport_height) / 2;
|
|
|
|
viewport_extent.x = 0;
|
|
|
|
viewport_extent.right = viewport_extent.left + framebuffer_width;
|
|
|
|
viewport_extent.y = (height_in_pixels - viewport_extent.height) / 2;
|
|
|
|
viewport_extent.bottom = viewport_extent.top + viewport_height;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Otherwise, borders are applied on the left and right sides of the window.
|
|
|
|
// Otherwise, apply borders to the left and right sides of the window.
|
|
|
|
viewport_extent.height = height_in_pixels;
|
|
|
|
unsigned viewport_width = framebuffer_height / emulation_aspect_ratio;
|
|
|
|
viewport_extent.width = (1 / emulation_aspect_ratio) * viewport_extent.height;
|
|
|
|
viewport_extent.left = (framebuffer_width - viewport_width) / 2;
|
|
|
|
viewport_extent.x = (width_in_pixels - viewport_extent.width) / 2;
|
|
|
|
viewport_extent.top = 0;
|
|
|
|
viewport_extent.y = 0;
|
|
|
|
viewport_extent.right = viewport_extent.left + viewport_width;
|
|
|
|
|
|
|
|
viewport_extent.bottom = viewport_extent.top + framebuffer_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return viewport_extent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Initialize the renderer
|
|
|
|
/// Initialize the renderer
|
|
|
|