From ebd417ce5f1faca85c41fe248beb88adf1b8691f Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Sat, 16 May 2026 20:01:06 +0200 Subject: [PATCH] Fix issues with bad graphics with manual conversions --- CMakeLists.txt | 2 +- include/frontend.hpp | 8 +++++--- source/TextRectangle.cpp | 4 ++++ source/WindowScreen.cpp | 44 ++++++++++++++++++++++++---------------- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70fac3e..e53d258 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,7 @@ endif() include(FetchContent) set(SFML_REPO_AUTHOR "SFML") -set(SFML_REPO_BRANCH "bugfix/macos_joystick_unplugging") +set(SFML_REPO_BRANCH "master") # Git shallow clone isn't shallow in cmake... This is bad. :/ # Replace this if they ever fix it. if(SFML_CLONE_USE_GIT_SHALLOW) diff --git a/include/frontend.hpp b/include/frontend.hpp index e28e417..cfa750b 100755 --- a/include/frontend.hpp +++ b/include/frontend.hpp @@ -132,6 +132,7 @@ private: InputVideoDataType curr_video_data_type; InputVideoDataType last_update_texture_data_type; PossibleSoftwareConvTypes texture_software_based_conv; + bool reported_software_conv = false; CaptureStatus* capture_status; std::string win_title; sf::RenderWindow m_win; @@ -270,7 +271,8 @@ private: ConsumerMutex display_lock; ConsumerMutex *draw_lock; bool done_display; - VideoOutputData *saved_buf; + VideoOutputData* saved_buf; + bool saved_buf_manually_converted; ScreenInfo loaded_info; ScreenOperations future_operations; ScreenOperations loaded_operations; @@ -356,8 +358,8 @@ private: void window_factory(bool is_main_thread); void opengl_error_out(std::string error_base, std::string error_str); void opengl_error_check(std::string error_base); - bool single_update_texture(unsigned int m_texture, InputVideoDataType video_data_type, size_t pos_x_data, size_t pos_y_data, size_t width, size_t height, bool manually_converted); - void execute_single_update_texture(bool &manually_converted, bool do_full, bool is_top = false, bool is_second = false); + bool single_update_texture(unsigned int m_texture, InputVideoDataType video_data_type, size_t pos_x_data, size_t pos_y_data, size_t width, size_t height); + void execute_single_update_texture(bool do_full, bool is_top = false, bool is_second = false); void update_texture(); int _choose_base_input_shader(bool is_top); int _choose_color_emulation_shader(bool is_top); diff --git a/source/TextRectangle.cpp b/source/TextRectangle.cpp index 87fa472..2284b28 100755 --- a/source/TextRectangle.cpp +++ b/source/TextRectangle.cpp @@ -332,6 +332,10 @@ void TextRectangle::setTextWithLineWrapping(int x_limit) { } void TextRectangle::setRealSize(int width, int height, bool check_previous) { + if (width < 1) + width = 1; + if (height < 1) + height = 1; this->loaded_data.width = width; this->loaded_data.height = height; this->pos_x_center_contrib = 0; diff --git a/source/WindowScreen.cpp b/source/WindowScreen.cpp index 0b9d2a7..05d6ea1 100755 --- a/source/WindowScreen.cpp +++ b/source/WindowScreen.cpp @@ -333,6 +333,7 @@ void WindowScreen::draw(double frame_time, VideoOutputData* out_buf, InputVideoD this->was_last_frame_null = true; } this->curr_video_data_type = video_data_type; + this->saved_buf_manually_converted = false; } loaded_info = m_info; m_info.initial_pos_x = DEFAULT_NO_POS_WINDOW_VALUE; @@ -377,6 +378,9 @@ void WindowScreen::update_connection() { } void WindowScreen::print_notification(std::string text, TextKind kind) { + if (text == "") + return; + this->notification->setText(text); this->notification->setRectangleKind(kind); this->notification->startTimer(true); @@ -608,7 +612,7 @@ void WindowScreen::opengl_error_check(std::string error_base) { } } -bool WindowScreen::single_update_texture(unsigned int m_texture, InputVideoDataType video_data_type, size_t pos_x_data, size_t pos_y_data, size_t width, size_t height, bool manually_converted) { +bool WindowScreen::single_update_texture(unsigned int m_texture, InputVideoDataType video_data_type, size_t pos_x_data, size_t pos_y_data, size_t width, size_t height) { if(!(this->saved_buf && m_texture)) return false; @@ -619,10 +623,12 @@ bool WindowScreen::single_update_texture(unsigned int m_texture, InputVideoDataT GLenum type = GL_UNSIGNED_BYTE; size_t format_size = sizeof(VideoPixelRGB); - if(manually_converted && (this->texture_software_based_conv == TO_RGBA_SOFTWARE_CONV)) + if(this->saved_buf_manually_converted && (this->texture_software_based_conv == TO_RGBA_SOFTWARE_CONV)) { format = GL_RGBA; + format_size = sizeof(VideoPixelRGBA); + } - if(!manually_converted) { + if(!this->saved_buf_manually_converted) { if(video_data_type == VIDEO_DATA_BGR) { format = GL_BGR; format_size = sizeof(VideoPixelBGR); @@ -644,7 +650,9 @@ bool WindowScreen::single_update_texture(unsigned int m_texture, InputVideoDataT bool processed = false; if(glCheckInternalError == GL_INVALID_ENUM) { if((format != GL_RGB) || (type != GL_UNSIGNED_BYTE)) { - UpdateOutText(this->own_out_text_data, "Switching to software-based texture updating", "", TEXT_KIND_NORMAL); + if(!this->reported_software_conv) + UpdateOutText(this->own_out_text_data, "Switching to software-based texture updating", "", TEXT_KIND_NORMAL); + this->reported_software_conv = true; this->last_update_texture_data_type = video_data_type; this->texture_software_based_conv = TO_RGB_SOFTWARE_CONV; return true; @@ -652,7 +660,9 @@ bool WindowScreen::single_update_texture(unsigned int m_texture, InputVideoDataT } if(glCheckInternalError == GL_INVALID_OPERATION) { if((format != GL_RGBA) || (type != GL_UNSIGNED_BYTE)) { - UpdateOutText(this->own_out_text_data, "Switching to software-based texture updating", "", TEXT_KIND_NORMAL); + if (!this->reported_software_conv) + UpdateOutText(this->own_out_text_data, "Switching to software-based texture updating", "", TEXT_KIND_NORMAL); + this->reported_software_conv = true; this->last_update_texture_data_type = video_data_type; this->texture_software_based_conv = TO_RGBA_SOFTWARE_CONV; return true; @@ -674,7 +684,7 @@ bool WindowScreen::single_update_texture(unsigned int m_texture, InputVideoDataT return false; } -void WindowScreen::execute_single_update_texture(bool &manually_converted, bool do_full, bool is_top, bool is_second) { +void WindowScreen::execute_single_update_texture(bool do_full, bool is_top, bool is_second) { InputVideoDataType video_data_type = this->curr_video_data_type; size_t top_width = TOP_WIDTH_3DS; size_t top_height = HEIGHT_3DS; @@ -747,44 +757,44 @@ void WindowScreen::execute_single_update_texture(bool &manually_converted, bool } } - if(is_vertically_rotated(this->capture_status->device.base_rotation)) + if(is_vertically_rotated(this->capture_status->device.base_rotation)) { + std::swap(pos_x_conv, pos_y_conv); std::swap(pos_x_data, pos_y_data); + } unsigned int m_texture = target_texture->getNativeHandle(); bool retry = true; while(retry) { - bool software_based_conv = manually_converted || ((this->texture_software_based_conv != NO_SOFTWARE_CONV) && (video_data_type == this->last_update_texture_data_type)); + bool software_based_conv = this->saved_buf_manually_converted || ((this->texture_software_based_conv != NO_SOFTWARE_CONV) && (video_data_type == this->last_update_texture_data_type)); if(software_based_conv) { - if(!manually_converted) { + if(!this->saved_buf_manually_converted) { if(this->texture_software_based_conv == TO_RGB_SOFTWARE_CONV) manualConvertOutputToRGB(this->saved_buf, this->saved_buf, pos_x_conv, pos_y_conv, full_width, full_height, video_data_type); if(this->texture_software_based_conv == TO_RGBA_SOFTWARE_CONV) manualConvertOutputToRGBA(this->saved_buf, this->saved_buf, pos_x_conv, pos_y_conv, full_width, full_height, video_data_type); } - manually_converted = true; + this->saved_buf_manually_converted = true; } else { this->texture_software_based_conv = NO_SOFTWARE_CONV; this->last_update_texture_data_type = video_data_type; } - - retry = this->single_update_texture(m_texture, video_data_type, pos_x_data, pos_y_data, width, height, manually_converted); + retry = this->single_update_texture(m_texture, video_data_type, pos_x_data, pos_y_data, width, height); } } void WindowScreen::update_texture() { - bool manually_converted = false; if(this->shared_texture_available) - this->execute_single_update_texture(manually_converted, true); + this->execute_single_update_texture(true); else { if((this->m_stype == ScreenType::TOP) || (this->m_stype == ScreenType::JOINT)) { - this->execute_single_update_texture(manually_converted, false, true); + this->execute_single_update_texture(false, true); if(get_3d_enabled(this->capture_status)) - this->execute_single_update_texture(manually_converted, false, true, true); + this->execute_single_update_texture(false, true, true); } if((this->m_stype == ScreenType::BOTTOM) || (this->m_stype == ScreenType::JOINT)) - this->execute_single_update_texture(manually_converted, false, false); + this->execute_single_update_texture(false, false); } }