Просмотр исходного кода

gl_rasterizer: Implement AccelerateDisplay method from Citra.

bunnei 8 лет назад
Родитель
Сommit
a0b1235f82

+ 33 - 1
src/video_core/renderer_opengl/gl_rasterizer.cpp

@@ -229,7 +229,39 @@ bool RasterizerOpenGL::AccelerateFill(const void* config) {
 bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& framebuffer,
                                          VAddr framebuffer_addr, u32 pixel_stride,
                                          ScreenInfo& screen_info) {
-    ASSERT_MSG(false, "Unimplemented");
+    if (framebuffer_addr == 0) {
+        return false;
+    }
+    MICROPROFILE_SCOPE(OpenGL_CacheManagement);
+
+    SurfaceParams src_params;
+    src_params.addr = framebuffer_addr;
+    src_params.width = std::min(framebuffer.width, pixel_stride);
+    src_params.height = framebuffer.height;
+    src_params.stride = pixel_stride;
+    src_params.is_tiled = false;
+    src_params.pixel_format =
+        SurfaceParams::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format);
+    src_params.UpdateParams();
+
+    MathUtil::Rectangle<u32> src_rect;
+    Surface src_surface;
+    std::tie(src_surface, src_rect) =
+        res_cache.GetSurfaceSubRect(src_params, ScaleMatch::Ignore, true);
+
+    if (src_surface == nullptr) {
+        return false;
+    }
+
+    u32 scaled_width = src_surface->GetScaledWidth();
+    u32 scaled_height = src_surface->GetScaledHeight();
+
+    screen_info.display_texcoords = MathUtil::Rectangle<float>(
+        (float)src_rect.bottom / (float)scaled_height, (float)src_rect.left / (float)scaled_width,
+        (float)src_rect.top / (float)scaled_height, (float)src_rect.right / (float)scaled_width);
+
+    screen_info.display_texture = src_surface->texture.handle;
+
     return true;
 }
 

+ 11 - 1
src/video_core/renderer_opengl/gl_rasterizer_cache.h

@@ -22,6 +22,7 @@
 #include "common/common_funcs.h"
 #include "common/common_types.h"
 #include "common/math_util.h"
+#include "video_core/gpu.h"
 #include "video_core/renderer_opengl/gl_resource_manager.h"
 
 struct CachedSurface;
@@ -115,6 +116,15 @@ struct SurfaceParams {
         return GetFormatBpp(pixel_format);
     }
 
+    static PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat format) {
+        switch (format) {
+        case Tegra::FramebufferConfig::PixelFormat::ABGR8:
+            return PixelFormat::RGBA8;
+        default:
+            UNREACHABLE();
+        }
+    }
+
     static bool CheckFormatsBlittable(PixelFormat pixel_format_a, PixelFormat pixel_format_b) {
         SurfaceType a_type = GetFormatType(pixel_format_a);
         SurfaceType b_type = GetFormatType(pixel_format_b);
@@ -257,7 +267,7 @@ struct CachedSurface : SurfaceParams {
     std::unique_ptr<u8[]> gl_buffer;
     size_t gl_buffer_size = 0;
 
-    // Read/Write data in 3DS memory to/from gl_buffer
+    // Read/Write data in Switch memory to/from gl_buffer
     void LoadGLBuffer(VAddr load_start, VAddr load_end);
     void FlushGLBuffer(VAddr flush_start, VAddr flush_end);