summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
authorGravatar bunnei2015-03-07 17:21:19 -0500
committerGravatar bunnei2015-03-07 17:21:19 -0500
commit9960c49c217d2c1ae202bdacd475c9a47cda39b9 (patch)
treea80e07b2ee63c3a081f3b3aec4eb45279b6f9b85 /src/video_core
parentMerge pull request #615 from Subv/services (diff)
downloadyuzu-9960c49c217d2c1ae202bdacd475c9a47cda39b9.tar.gz
yuzu-9960c49c217d2c1ae202bdacd475c9a47cda39b9.tar.xz
yuzu-9960c49c217d2c1ae202bdacd475c9a47cda39b9.zip
Set framebuffer layout from EmuWindow.
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp48
-rw-r--r--src/video_core/video_core.cpp3
-rw-r--r--src/video_core/video_core.h1
3 files changed, 9 insertions, 43 deletions
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 272695174..fc8af9d40 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -242,28 +242,26 @@ void RendererOpenGL::DrawSingleScreenRotated(const TextureInfo& texture, float x
242 * Draws the emulated screens to the emulator window. 242 * Draws the emulated screens to the emulator window.
243 */ 243 */
244void RendererOpenGL::DrawScreens() { 244void RendererOpenGL::DrawScreens() {
245 auto viewport_extent = GetViewportExtent(); 245 auto layout = render_window->GetFramebufferLayout();
246 glViewport(viewport_extent.left, viewport_extent.top, viewport_extent.GetWidth(), viewport_extent.GetHeight()); // TODO: Or bottom? 246
247 glViewport(0, 0, layout.width, layout.height);
247 glClear(GL_COLOR_BUFFER_BIT); 248 glClear(GL_COLOR_BUFFER_BIT);
248 249
249 glUseProgram(program_id); 250 glUseProgram(program_id);
250 251
251 // Set projection matrix 252 // Set projection matrix
252 std::array<GLfloat, 3*2> ortho_matrix = MakeOrthographicMatrix((float)resolution_width, (float)resolution_height); 253 std::array<GLfloat, 3 * 2> ortho_matrix = MakeOrthographicMatrix((float)layout.width,
254 (float)layout.height);
253 glUniformMatrix3x2fv(uniform_modelview_matrix, 1, GL_FALSE, ortho_matrix.data()); 255 glUniformMatrix3x2fv(uniform_modelview_matrix, 1, GL_FALSE, ortho_matrix.data());
254 256
255 // Bind texture in Texture Unit 0 257 // Bind texture in Texture Unit 0
256 glActiveTexture(GL_TEXTURE0); 258 glActiveTexture(GL_TEXTURE0);
257 glUniform1i(uniform_color_texture, 0); 259 glUniform1i(uniform_color_texture, 0);
258 260
259 const float max_width = std::max((float)VideoCore::kScreenTopWidth, (float)VideoCore::kScreenBottomWidth); 261 DrawSingleScreenRotated(textures[0], (float)layout.top_screen.left, (float)layout.top_screen.top,
260 const float top_x = 0.5f * (max_width - VideoCore::kScreenTopWidth); 262 (float)layout.top_screen.GetWidth(), (float)layout.top_screen.GetHeight());
261 const float bottom_x = 0.5f * (max_width - VideoCore::kScreenBottomWidth); 263 DrawSingleScreenRotated(textures[1], (float)layout.bottom_screen.left,(float)layout.bottom_screen.top,
262 264 (float)layout.bottom_screen.GetWidth(), (float)layout.bottom_screen.GetHeight());
263 DrawSingleScreenRotated(textures[0], top_x, 0,
264 (float)VideoCore::kScreenTopWidth, (float)VideoCore::kScreenTopHeight);
265 DrawSingleScreenRotated(textures[1], bottom_x, (float)VideoCore::kScreenTopHeight,
266 (float)VideoCore::kScreenBottomWidth, (float)VideoCore::kScreenBottomHeight);
267 265
268 m_current_frame++; 266 m_current_frame++;
269} 267}
@@ -280,34 +278,6 @@ void RendererOpenGL::SetWindow(EmuWindow* window) {
280 render_window = window; 278 render_window = window;
281} 279}
282 280
283MathUtil::Rectangle<unsigned> RendererOpenGL::GetViewportExtent() {
284 unsigned framebuffer_width;
285 unsigned framebuffer_height;
286 std::tie(framebuffer_width, framebuffer_height) = render_window->GetFramebufferSize();
287
288 float window_aspect_ratio = static_cast<float>(framebuffer_height) / framebuffer_width;
289 float emulation_aspect_ratio = static_cast<float>(resolution_height) / resolution_width;
290
291 MathUtil::Rectangle<unsigned> viewport_extent;
292 if (window_aspect_ratio > emulation_aspect_ratio) {
293 // Window is narrower than the emulation content => apply borders to the top and bottom
294 unsigned viewport_height = static_cast<unsigned>(std::round(emulation_aspect_ratio * framebuffer_width));
295 viewport_extent.left = 0;
296 viewport_extent.top = (framebuffer_height - viewport_height) / 2;
297 viewport_extent.right = viewport_extent.left + framebuffer_width;
298 viewport_extent.bottom = viewport_extent.top + viewport_height;
299 } else {
300 // Otherwise, apply borders to the left and right sides of the window.
301 unsigned viewport_width = static_cast<unsigned>(std::round(framebuffer_height / emulation_aspect_ratio));
302 viewport_extent.left = (framebuffer_width - viewport_width) / 2;
303 viewport_extent.top = 0;
304 viewport_extent.right = viewport_extent.left + viewport_width;
305 viewport_extent.bottom = viewport_extent.top + framebuffer_height;
306 }
307
308 return viewport_extent;
309}
310
311/// Initialize the renderer 281/// Initialize the renderer
312void RendererOpenGL::Init() { 282void RendererOpenGL::Init() {
313 render_window->MakeCurrent(); 283 render_window->MakeCurrent();
diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp
index 0a236595c..b9d4ede3a 100644
--- a/src/video_core/video_core.cpp
+++ b/src/video_core/video_core.cpp
@@ -18,7 +18,6 @@ namespace VideoCore {
18 18
19EmuWindow* g_emu_window = nullptr; ///< Frontend emulator window 19EmuWindow* g_emu_window = nullptr; ///< Frontend emulator window
20RendererBase* g_renderer = nullptr; ///< Renderer plugin 20RendererBase* g_renderer = nullptr; ///< Renderer plugin
21int g_current_frame = 0;
22 21
23/// Initialize the video core 22/// Initialize the video core
24void Init(EmuWindow* emu_window) { 23void Init(EmuWindow* emu_window) {
@@ -27,8 +26,6 @@ void Init(EmuWindow* emu_window) {
27 g_renderer->SetWindow(g_emu_window); 26 g_renderer->SetWindow(g_emu_window);
28 g_renderer->Init(); 27 g_renderer->Init();
29 28
30 g_current_frame = 0;
31
32 LOG_DEBUG(Render, "initialized OK"); 29 LOG_DEBUG(Render, "initialized OK");
33} 30}
34 31
diff --git a/src/video_core/video_core.h b/src/video_core/video_core.h
index b782f17bd..1b51d39bf 100644
--- a/src/video_core/video_core.h
+++ b/src/video_core/video_core.h
@@ -30,7 +30,6 @@ static const int kScreenBottomHeight = 240; ///< 3DS bottom screen height
30// --------------------- 30// ---------------------
31 31
32extern RendererBase* g_renderer; ///< Renderer plugin 32extern RendererBase* g_renderer; ///< Renderer plugin
33extern int g_current_frame; ///< Current frame
34extern EmuWindow* g_emu_window; ///< Emu window 33extern EmuWindow* g_emu_window; ///< Emu window
35 34
36/// Start the video core 35/// Start the video core