From a682b720e1e78c017148fd1338b34d3f0c660e69 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 11 Apr 2020 18:54:09 +1000 Subject: [PATCH] Qt: Fix software renderer image uploads in OpenGL --- src/duckstation-qt/opengldisplaywidget.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/duckstation-qt/opengldisplaywidget.cpp b/src/duckstation-qt/opengldisplaywidget.cpp index c27965906..c0131ab5b 100644 --- a/src/duckstation-qt/opengldisplaywidget.cpp +++ b/src/duckstation-qt/opengldisplaywidget.cpp @@ -153,14 +153,21 @@ void OpenGLDisplayWidget::UpdateTexture(HostDisplayTexture* texture, u32 x, u32 const void* texture_data, u32 texture_data_stride) { OpenGLDisplayWidgetTexture* tex = static_cast(texture); - Assert(texture_data_stride == (width * sizeof(u32))); + Assert((texture_data_stride % sizeof(u32)) == 0); - GLint old_texture_binding = 0; + GLint old_texture_binding = 0, old_alignment = 0, old_row_length = 0; glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_texture_binding); + glGetIntegerv(GL_UNPACK_ALIGNMENT, &old_alignment); + glGetIntegerv(GL_UNPACK_ROW_LENGTH, &old_row_length); glBindTexture(GL_TEXTURE_2D, tex->GetGLID()); + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + glPixelStorei(GL_UNPACK_ROW_LENGTH, texture_data_stride / sizeof(u32)); + glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, texture_data); + glPixelStorei(GL_UNPACK_ALIGNMENT, old_alignment); + glPixelStorei(GL_UNPACK_ROW_LENGTH, old_row_length); glBindTexture(GL_TEXTURE_2D, old_texture_binding); }