aboutsummaryrefslogtreecommitdiff
path: root/src/citra_qt/debugger/graphics_framebuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt/debugger/graphics_framebuffer.cpp')
-rw-r--r--src/citra_qt/debugger/graphics_framebuffer.cpp86
1 files changed, 35 insertions, 51 deletions
diff --git a/src/citra_qt/debugger/graphics_framebuffer.cpp b/src/citra_qt/debugger/graphics_framebuffer.cpp
index 1ba60021f..5bd6c0235 100644
--- a/src/citra_qt/debugger/graphics_framebuffer.cpp
+++ b/src/citra_qt/debugger/graphics_framebuffer.cpp
@@ -9,8 +9,10 @@
#include <QPushButton>
#include <QSpinBox>
+#include "core/hw/gpu.h"
#include "video_core/color.h"
#include "video_core/pica.h"
+#include "video_core/utils.h"
#include "graphics_framebuffer.h"
@@ -44,7 +46,7 @@ GraphicsFramebufferWidget::GraphicsFramebufferWidget(std::shared_ptr<Pica::Debug
framebuffer_format_control = new QComboBox;
framebuffer_format_control->addItem(tr("RGBA8"));
framebuffer_format_control->addItem(tr("RGB8"));
- framebuffer_format_control->addItem(tr("RGBA5551"));
+ framebuffer_format_control->addItem(tr("RGB5A1"));
framebuffer_format_control->addItem(tr("RGB565"));
framebuffer_format_control->addItem(tr("RGBA4"));
@@ -195,60 +197,42 @@ void GraphicsFramebufferWidget::OnUpdate()
// TODO: Implement a good way to visualize alpha components!
// TODO: Unify this decoding code with the texture decoder
- switch (framebuffer_format) {
- case Format::RGBA8:
- {
- QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
- u32* color_buffer = (u32*)Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address));
- for (unsigned int y = 0; y < framebuffer_height; ++y) {
- for (unsigned int x = 0; x < framebuffer_width; ++x) {
- u32 value = *(color_buffer + x + y * framebuffer_width);
-
- decoded_image.setPixel(x, y, qRgba((value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF, 255/*value >> 24*/));
+ u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(framebuffer_format));
+
+ QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
+ u8* color_buffer = Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address));
+ for (unsigned int y = 0; y < framebuffer_height; ++y) {
+ for (unsigned int x = 0; x < framebuffer_width; ++x) {
+ const u32 coarse_y = y & ~7;
+ u32 offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * framebuffer_width * bytes_per_pixel;
+ const u8* pixel = color_buffer + offset;
+ Math::Vec4<u8> color = { 0, 0, 0, 0 };
+
+ switch (framebuffer_format) {
+ case Format::RGBA8:
+ color = Color::DecodeRGBA8(pixel);
+ break;
+ case Format::RGB8:
+ color = Color::DecodeRGB8(pixel);
+ break;
+ case Format::RGB5A1:
+ color = Color::DecodeRGB5A1(pixel);
+ break;
+ case Format::RGB565:
+ color = Color::DecodeRGB565(pixel);
+ break;
+ case Format::RGBA4:
+ color = Color::DecodeRGBA4(pixel);
+ break;
+ default:
+ qDebug() << "Unknown fb color format " << static_cast<int>(framebuffer_format);
+ break;
}
- }
- pixmap = QPixmap::fromImage(decoded_image);
- break;
- }
- case Format::RGB8:
- {
- QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
- u8* color_buffer = Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address));
- for (unsigned int y = 0; y < framebuffer_height; ++y) {
- for (unsigned int x = 0; x < framebuffer_width; ++x) {
- u8* pixel_pointer = color_buffer + x * 3 + y * 3 * framebuffer_width;
-
- decoded_image.setPixel(x, y, qRgba(pixel_pointer[0], pixel_pointer[1], pixel_pointer[2], 255/*value >> 24*/));
- }
+ decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), 255));
}
- pixmap = QPixmap::fromImage(decoded_image);
- break;
- }
-
- case Format::RGBA5551:
- {
- QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
- u32* color_buffer = (u32*)Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address));
- for (unsigned int y = 0; y < framebuffer_height; ++y) {
- for (unsigned int x = 0; x < framebuffer_width; ++x) {
- u16 value = *(u16*)(((u8*)color_buffer) + x * 2 + y * framebuffer_width * 2);
- u8 r = Color::Convert5To8((value >> 11) & 0x1F);
- u8 g = Color::Convert5To8((value >> 6) & 0x1F);
- u8 b = Color::Convert5To8((value >> 1) & 0x1F);
- u8 a = Color::Convert1To8(value & 1);
-
- decoded_image.setPixel(x, y, qRgba(r, g, b, 255/*a*/));
- }
- }
- pixmap = QPixmap::fromImage(decoded_image);
- break;
- }
-
- default:
- qDebug() << "Unknown fb color format " << static_cast<int>(framebuffer_format);
- break;
}
+ pixmap = QPixmap::fromImage(decoded_image);
framebuffer_address_control->SetValue(framebuffer_address);
framebuffer_width_control->setValue(framebuffer_width);