@@ -271,6 +271,7 @@ end)(jit.status()))
271271
272272 s_this = this ;
273273 glfwSetDropCallback (m_window, drop_callback);
274+ glfwSetWindowSizeCallback (m_window, [](GLFWwindow*, int , int ) { s_this->m_setupScreenSize = true ; });
274275
275276 Resources::loadIcon ([this ](const uint8_t * data, uint32_t size) {
276277 int x, y, comp;
@@ -467,6 +468,8 @@ end)(jit.status()))
467468 m_biosEditor.title = []() { return _ (" BIOS" ); };
468469 m_biosEditor.show = false ;
469470
471+ m_offscreenShaderEditor.init ();
472+ m_outputShaderEditor.init ();
470473 m_offscreenShaderEditor.compile (this );
471474 m_outputShaderEditor.compile (this );
472475
@@ -510,7 +513,7 @@ end)(jit.status()))
510513 });
511514
512515 startFrame ();
513- m_currentTexture = 1 ;
516+ m_currentTexture ^ = 1 ;
514517 flip ();
515518}
516519
@@ -549,6 +552,29 @@ void PCSX::GUI::startFrame() {
549552 if (glfwWindowShouldClose (m_window)) g_system->quit ();
550553 glfwPollEvents ();
551554
555+ if (m_setupScreenSize) {
556+ constexpr float renderRatio = 3 .0f / 4 .0f ;
557+ int w, h;
558+
559+ glfwGetFramebufferSize (m_window, &w, &h);
560+ // Make width/height be 1 at minimum
561+ w = std::max<int >(w, 1 );
562+ h = std::max<int >(h, 1 );
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+
552578 auto & io = ImGui::GetIO ();
553579
554580 if (m_reloadFonts) {
@@ -623,12 +649,10 @@ void PCSX::GUI::flip() {
623649 glBindFramebuffer (GL_FRAMEBUFFER , m_offscreenFrameBuffer);
624650 glBindTexture (GL_TEXTURE_2D , m_offscreenTextures[m_currentTexture]);
625651
626- glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA , m_renderSize.x , m_renderSize.y , 0 , GL_RGBA , GL_UNSIGNED_BYTE , 0 );
627652 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST );
628653 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST );
629654
630655 glBindRenderbuffer (GL_RENDERBUFFER , m_offscreenDepthBuffer);
631- glRenderbufferStorage (GL_RENDERBUFFER , GL_DEPTH_COMPONENT24 , m_renderSize.x , m_renderSize.y );
632656 glFramebufferRenderbuffer (GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_RENDERBUFFER , m_offscreenDepthBuffer);
633657 GLuint texture = m_offscreenTextures[m_currentTexture];
634658 glFramebufferTexture2D (GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , texture, 0 );
@@ -639,8 +663,6 @@ void PCSX::GUI::flip() {
639663
640664 assert (glCheckFramebufferStatus (GL_FRAMEBUFFER ) == GL_FRAMEBUFFER_COMPLETE );
641665
642- glViewport (0 , 0 , m_renderSize.x , m_renderSize.y );
643-
644666 glClearColor (0 , 0 , 0 , 0 );
645667 glClearDepthf (0 .f );
646668 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
@@ -650,17 +672,16 @@ void PCSX::GUI::flip() {
650672}
651673
652674void PCSX::GUI::endFrame () {
675+ 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, m_renderRatio);
663-
664685 bool changed = false ;
665686
666687 m_offscreenShaderEditor.configure (this );
@@ -692,7 +713,7 @@ void PCSX::GUI::endFrame() {
692713 _ (" Output" ), &outputShown,
693714 ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse)) {
694715 ImVec2 textureSize = ImGui::GetContentRegionAvail ();
695- normalizeDimensions (textureSize, m_renderRatio );
716+ normalizeDimensions (textureSize, renderRatio );
696717 ImTextureID texture = reinterpret_cast <ImTextureID*>(m_offscreenTextures[m_currentTexture]);
697718 m_outputShaderEditor.renderWithImgui (this , texture, m_renderSize, textureSize);
698719 }
0 commit comments