@@ -112,6 +112,10 @@ static void drop_callback(GLFWwindow* window, int count, const char** paths) {
112112 s_this->magicOpen (paths[0 ]);
113113}
114114
115+ static void resize_callback (GLFWwindow* window, int width, int height) {
116+ s_this->m_setupScreenSize = true ;
117+ }
118+
115119static void ShowHelpMarker (const char * desc) {
116120 ImGui::SameLine ();
117121 ImGui::TextDisabled (" (?)" );
@@ -271,6 +275,7 @@ end)(jit.status()))
271275
272276 s_this = this ;
273277 glfwSetDropCallback (m_window, drop_callback);
278+ glfwSetWindowSizeCallback (m_window, resize_callback);
274279
275280 Resources::loadIcon ([this ](const uint8_t * data, uint32_t size) {
276281 int x, y, comp;
@@ -511,7 +516,7 @@ end)(jit.status()))
511516 });
512517
513518 startFrame ();
514- m_currentTexture = 1 ;
519+ m_currentTexture ^ = 1 ;
515520 flip ();
516521}
517522
@@ -550,6 +555,26 @@ void PCSX::GUI::startFrame() {
550555 if (glfwWindowShouldClose (m_window)) g_system->quit ();
551556 glfwPollEvents ();
552557
558+ if (m_setupScreenSize) {
559+ constexpr float renderRatio = 3 .0f / 4 .0f ;
560+ int w, h;
561+
562+ glfwGetFramebufferSize (m_window, &w, &h);
563+ m_framebufferSize = ImVec2 (w, h);
564+ m_renderSize = ImVec2 (w, h);
565+ normalizeDimensions (m_renderSize, renderRatio);
566+
567+ // Reset texture and framebuffer storage
568+ glBindTexture (GL_TEXTURE_2D , m_offscreenTextures[0 ]);
569+ glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA , m_renderSize.x , m_renderSize.y , 0 , GL_RGBA , GL_UNSIGNED_BYTE , 0 );
570+ glBindTexture (GL_TEXTURE_2D , m_offscreenTextures[1 ]);
571+ glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA , m_renderSize.x , m_renderSize.y , 0 , GL_RGBA , GL_UNSIGNED_BYTE , 0 );
572+
573+ glBindRenderbuffer (GL_RENDERBUFFER , m_offscreenDepthBuffer);
574+ glRenderbufferStorage (GL_RENDERBUFFER , GL_DEPTH_COMPONENT24 , m_renderSize.x , m_renderSize.y );
575+ m_setupScreenSize = false ;
576+ }
577+
553578 auto & io = ImGui::GetIO ();
554579
555580 if (m_reloadFonts) {
@@ -624,12 +649,10 @@ void PCSX::GUI::flip() {
624649 glBindFramebuffer (GL_FRAMEBUFFER , m_offscreenFrameBuffer);
625650 glBindTexture (GL_TEXTURE_2D , m_offscreenTextures[m_currentTexture]);
626651
627- glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA , m_renderSize.x , m_renderSize.y , 0 , GL_RGBA , GL_UNSIGNED_BYTE , 0 );
628652 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST );
629653 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST );
630654
631655 glBindRenderbuffer (GL_RENDERBUFFER , m_offscreenDepthBuffer);
632- glRenderbufferStorage (GL_RENDERBUFFER , GL_DEPTH_COMPONENT24 , m_renderSize.x , m_renderSize.y );
633656 glFramebufferRenderbuffer (GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_RENDERBUFFER , m_offscreenDepthBuffer);
634657 GLuint texture = m_offscreenTextures[m_currentTexture];
635658 glFramebufferTexture2D (GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , texture, 0 );
@@ -650,17 +673,15 @@ void PCSX::GUI::flip() {
650673
651674void PCSX::GUI::endFrame () {
652675 constexpr float renderRatio = 3 .0f / 4 .0f ;
676+ const int w = m_framebufferSize.x ;
677+ const int h = m_framebufferSize.y ;
678+
653679 auto & io = ImGui::GetIO ();
654680 // bind back the output frame buffer
655681 glBindFramebuffer (GL_FRAMEBUFFER , 0 );
656682 auto & emuSettings = PCSX ::g_emulator->settings ;
657683 auto & debugSettings = emuSettings.get <Emulator::SettingDebugSettings>();
658684
659- int w, h;
660- glfwGetFramebufferSize (m_window, &w, &h);
661- m_renderSize = ImVec2 (w, h);
662- normalizeDimensions (m_renderSize, renderRatio);
663-
664685 bool changed = false ;
665686
666687 m_offscreenShaderEditor.configure (this );
0 commit comments