From 2efc3afaf2dc0725d313d4a634b662c4e30a8d1e 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 | 6 ++++-- source/TextRectangle.cpp | 4 ++++ source/WindowScreen.cpp | 28 +++++++++++++++++++--------- 4 files changed, 28 insertions(+), 12 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..7a8b731 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; + VideoOutputData* conv_buf; ScreenInfo loaded_info; ScreenOperations future_operations; ScreenOperations loaded_operations; @@ -356,7 +358,7 @@ 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); + 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, VideoOutputData* selected_buf); void execute_single_update_texture(bool &manually_converted, bool do_full, bool is_top = false, bool is_second = false); void update_texture(); int _choose_base_input_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..f4e039d 100755 --- a/source/WindowScreen.cpp +++ b/source/WindowScreen.cpp @@ -123,6 +123,7 @@ WindowScreen::WindowScreen(ScreenType stype, CaptureStatus* capture_status, Disp WindowScreen::reset_operations(future_operations); this->done_display = true; this->saved_buf = new VideoOutputData; + this->conv_buf = new VideoOutputData; this->win_title = NAME; if(this->m_stype == ScreenType::TOP) { this->win_title += "_top"; @@ -169,6 +170,7 @@ WindowScreen::~WindowScreen() { this->possible_files.clear(); this->possible_resolutions.clear(); delete this->saved_buf; + delete this->conv_buf; delete this->notification; this->destroy_menus(); delete this->text_rectangle_pool; @@ -377,6 +379,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,8 +613,8 @@ 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) { - if(!(this->saved_buf && m_texture)) +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, VideoOutputData* selected_buf) { + if(!(selected_buf && m_texture)) return false; this->opengl_error_check("Previous OpenGL Error"); @@ -638,13 +643,15 @@ bool WindowScreen::single_update_texture(unsigned int m_texture, InputVideoDataT } this->opengl_error_check("BindTexture OpenGL Error"); - glTexSubImage2D(GL_TEXTURE_2D, 0, static_cast(this->curr_frame_texture_pos * MAX_IN_VIDEO_WIDTH), static_cast(0), static_cast(width), static_cast(height), format, type, ((uint8_t*)this->saved_buf) + (pos_y_data * width * format_size)); + glTexSubImage2D(GL_TEXTURE_2D, 0, static_cast(this->curr_frame_texture_pos * MAX_IN_VIDEO_WIDTH), static_cast(0), static_cast(width), static_cast(height), format, type, ((uint8_t*)selected_buf) + (pos_y_data * width * format_size)); GLenum glCheckInternalError = glGetError(); while (glCheckInternalError != GL_NO_ERROR) { 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 +659,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; @@ -752,24 +761,25 @@ void WindowScreen::execute_single_update_texture(bool &manually_converted, bool unsigned int m_texture = target_texture->getNativeHandle(); bool retry = true; + VideoOutputData* target_buffer = this->saved_buf; 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)); if(software_based_conv) { if(!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); + manualConvertOutputToRGB(this->saved_buf, this->conv_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); + manualConvertOutputToRGBA(this->saved_buf, this->conv_buf, pos_x_conv, pos_y_conv, full_width, full_height, video_data_type); } + target_buffer = this->conv_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, manually_converted, target_buffer); } }