From 0bf509dc1a762f11c364f995663dcb403e0520a3 Mon Sep 17 00:00:00 2001 From: Garux Date: Mon, 5 Mar 2018 13:48:48 +0300 Subject: [PATCH] * fix: FBO creation was random * disable MSAA with samples = 0, even if more is forced via driver --- libs/gtkutil/xorrectangle.h | 3 --- libs/render.h | 34 +++++++++++++++++++++------------- radiant/camwindow.cpp | 19 +++++++++++-------- radiant/texwindow.cpp | 3 --- radiant/xywindow.cpp | 23 +++++++++++++---------- radiant/xywindow.h | 1 + 6 files changed, 46 insertions(+), 37 deletions(-) diff --git a/libs/gtkutil/xorrectangle.h b/libs/gtkutil/xorrectangle.h index 01b0b34c..fc1965df 100644 --- a/libs/gtkutil/xorrectangle.h +++ b/libs/gtkutil/xorrectangle.h @@ -120,9 +120,6 @@ public: glVertex2f( rectangle.x, rectangle.y ); glEnd(); - if( GlobalOpenGL().GL_1_3() ) { - glEnable( GL_MULTISAMPLE ); - } GlobalOpenGL_debugAssertNoErrors(); } } diff --git a/libs/render.h b/libs/render.h index e9f7ea25..c6fbe827 100644 --- a/libs/render.h +++ b/libs/render.h @@ -1278,12 +1278,10 @@ public: _constructed = false; } virtual void start(){ -// if ( GlobalOpenGL().GL_1_3() ) { -// glDisable( GL_MULTISAMPLE ); -// } if( !_constructed ){ construct(); } + setMultisample(); glBindFramebuffer( GL_FRAMEBUFFER, _fbo ); } virtual void save(){ @@ -1306,6 +1304,14 @@ protected: GLuint _tex; GLuint _depth; GLuint _color; + void setMultisample(){ + if( GlobalOpenGL().GL_1_3() ) { + if( _samples ) + glEnable( GL_MULTISAMPLE ); + else + glDisable( GL_MULTISAMPLE ); + } + } virtual void construct() { int curSamples; glGetIntegerv( GL_SAMPLES, &curSamples ); @@ -1319,6 +1325,8 @@ protected: _samples = maxSamples; } } +// globalErrorStream() << _samples << " samples\n"; + setMultisample(); glGenFramebuffers( 1, &_fbo ); glBindFramebuffer( GL_FRAMEBUFFER, _fbo ); @@ -1381,7 +1389,7 @@ public: glMatrixMode( GL_PROJECTION ); glLoadIdentity(); - glOrtho( 0, _width, 0, _height, -100, 100 ); + glOrtho( 0, 1, 0, 1, -100, 100 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); @@ -1405,17 +1413,17 @@ public: glBindTexture( GL_TEXTURE_2D, _tex ); - glColor4f( 1.0, 1.0, 1.0, 1.0 ); + glColor4f( 1.f, 1.f, 1.f, 1.f ); glBegin( GL_QUADS ); - glTexCoord2f( 0, 0 ); - glVertex3f( 0, 0, 0 ); - glTexCoord2f( 0, 1 ); - glVertex3f( 0, _height, 0 ); - glTexCoord2f( 1, 1 ); - glVertex3f( _width, _height, 0 ); - glTexCoord2f( 1, 0 ); - glVertex3f( _width, 0, 0 ); + glTexCoord2i( 0, 0 ); + glVertex2i( 0, 0 ); + glTexCoord2i( 0, 1 ); + glVertex2i( 0, 1 ); + glTexCoord2i( 1, 1 ); + glVertex2i( 1, 1 ); + glTexCoord2i( 1, 0 ); + glVertex2i( 1, 0 ); glEnd(); glBindTexture( GL_TEXTURE_2D, 0 ); } diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index 48ecb83e..aa4f7b8a 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -717,6 +717,9 @@ FreezePointer m_freezePointer; public: FBO* m_fbo; +FBO* fbo_get(){ + return m_fbo = m_fbo? m_fbo : GlobalOpenGL().support_ARB_framebuffer_object? new FBO : new FBO_fallback; +} GtkWidget* m_gl_widget; GtkWindow* m_parent; @@ -952,7 +955,7 @@ void camwnd_update_xor_rectangle( CamWnd& self, rect_t area ){ GlobalOpenGL_debugAssertNoErrors(); glDrawBuffer( GL_FRONT ); - self.m_fbo->blit(); + self.fbo_get()->blit(); self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.getCamera().width, self.getCamera().height ), self.getCamera().width, self.getCamera().height ); @@ -1070,7 +1073,7 @@ gboolean wheelmove_scroll( GtkWidget* widget, GdkEventScroll* event, CamWnd* cam } gboolean camera_size_allocate( GtkWidget* widget, GtkAllocation* allocation, CamWnd* camwnd ){ - camwnd->m_fbo->reset( allocation->width, allocation->height, g_camwindow_globals_private.m_MSAA, true ); + camwnd->fbo_get()->reset( allocation->width, allocation->height, g_camwindow_globals_private.m_MSAA, true ); camwnd->getCamera().width = allocation->width; camwnd->getCamera().height = allocation->height; Camera_updateProjection( camwnd->getCamera() ); @@ -1378,9 +1381,9 @@ CamWnd::CamWnd() : m_selection_motion_handler( 0 ), m_freelook_button_press_handler( 0 ), m_freelook_button_release_handler( 0 ), - m_drawing( false ){ - m_fbo = GlobalOpenGL().support_ARB_framebuffer_object? new FBO : new FBO_fallback; - + m_drawing( false ), + m_fbo( 0 ) +{ m_bFreeMove = false; GlobalWindowObservers_add( m_window_observer ); @@ -1663,7 +1666,7 @@ void ShowStatsToggle(){ void CamWnd::Cam_Draw(){ // globalOutputStream() << "Cam_Draw()\n"; - m_fbo->start(); + fbo_get()->start(); glViewport( 0, 0, m_Camera.width, m_Camera.height ); #if 0 @@ -1831,7 +1834,7 @@ void CamWnd::Cam_Draw(){ // elsewhere using/modifying texture maps between contexts glBindTexture( GL_TEXTURE_2D, 0 ); - m_fbo->save(); + fbo_get()->save(); } void CamWnd::draw(){ @@ -2123,7 +2126,7 @@ typedef FreeCaller1 RenderModeExport void CamMSAAImport( int value ){ g_camwindow_globals_private.m_MSAA = value ? 1 << value : value; if ( g_camwnd != 0 ) { - g_camwnd->m_fbo->reset( g_camwnd->getCamera().width, g_camwnd->getCamera().height, g_camwindow_globals_private.m_MSAA, true ); + g_camwnd->fbo_get()->reset( g_camwnd->getCamera().width, g_camwnd->getCamera().height, g_camwindow_globals_private.m_MSAA, true ); } } typedef FreeCaller1 MSAAImportCaller; diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 4e5ea523..8886eda0 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -1269,9 +1269,6 @@ void Texture_Draw( TextureBrowser& textureBrowser ){ // reset the current texture glBindTexture( GL_TEXTURE_2D, 0 ); - if( GlobalOpenGL().GL_1_3() ) { - glEnable( GL_MULTISAMPLE ); - } glDisable( GL_BLEND ); //qglFinish(); } diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 055bd75d..1126602a 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -768,7 +768,7 @@ bool XYWnd::XY_Draw_Overlay_start(){ if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) { GlobalOpenGL_debugAssertNoErrors(); glDrawBuffer( GL_FRONT ); - m_fbo->blit(); + fbo_get()->blit(); return true; } } @@ -852,7 +852,7 @@ gboolean xywnd_wheel_scroll( GtkWidget* widget, GdkEventScroll* event, XYWnd* xy } gboolean xywnd_size_allocate( GtkWidget* widget, GtkAllocation* allocation, XYWnd* xywnd ){ - xywnd->m_fbo->reset( allocation->width, allocation->height, g_xywindow_globals_private.m_MSAA, false ); + xywnd->fbo_get()->reset( allocation->width, allocation->height, g_xywindow_globals_private.m_MSAA, false ); xywnd->m_nWidth = allocation->width; xywnd->m_nHeight = allocation->height; xywnd->updateProjection(); @@ -888,10 +888,9 @@ XYWnd::XYWnd() : m_deferred_motion( xywnd_motion, this ), m_parent( 0 ), m_window_observer( NewWindowObserver() ), - m_chasemouse_handler( 0 ) + m_chasemouse_handler( 0 ), + m_fbo( 0 ) { - m_fbo = GlobalOpenGL().support_ARB_framebuffer_object? new FBO : new FBO_fallback; - m_cursorCurrent = 0; m_bActive = false; @@ -999,6 +998,10 @@ void XYWnd::Scroll( int x, int y ){ queueDraw(); } +FBO* XYWnd::fbo_get(){ + return m_fbo = m_fbo? m_fbo : GlobalOpenGL().support_ARB_framebuffer_object? new FBO : new FBO_fallback; +} + unsigned int Clipper_buttons(){ return RAD_LBUTTON; } @@ -2702,7 +2705,7 @@ void XYWnd::XY_Draw(){ glGetIntegerv(GL_SAMPLES,&curSamples); globalOutputStream() << curSamples << " GL_SAMPLES\n"; */ - m_fbo->start(); + fbo_get()->start(); // // clear // @@ -2903,7 +2906,7 @@ void XYWnd::XY_Draw(){ m_render_time.start(); } - m_fbo->save(); + fbo_get()->save(); { // reset modelview @@ -3302,13 +3305,13 @@ void ToggleShowGrid(){ void MSAAImport( int value ){ g_xywindow_globals_private.m_MSAA = value ? 1 << value : value; if ( g_pParentWnd->GetXYWnd() ) { - g_pParentWnd->GetXYWnd()->m_fbo->reset( g_pParentWnd->GetXYWnd()->Width(), g_pParentWnd->GetXYWnd()->Height(), g_xywindow_globals_private.m_MSAA, false ); + g_pParentWnd->GetXYWnd()->fbo_get()->reset( g_pParentWnd->GetXYWnd()->Width(), g_pParentWnd->GetXYWnd()->Height(), g_xywindow_globals_private.m_MSAA, false ); } if ( g_pParentWnd->GetXZWnd() ) { - g_pParentWnd->GetXZWnd()->m_fbo->reset( g_pParentWnd->GetXZWnd()->Width(), g_pParentWnd->GetXZWnd()->Height(), g_xywindow_globals_private.m_MSAA, false ); + g_pParentWnd->GetXZWnd()->fbo_get()->reset( g_pParentWnd->GetXZWnd()->Width(), g_pParentWnd->GetXZWnd()->Height(), g_xywindow_globals_private.m_MSAA, false ); } if ( g_pParentWnd->GetYZWnd() ) { - g_pParentWnd->GetYZWnd()->m_fbo->reset( g_pParentWnd->GetYZWnd()->Width(), g_pParentWnd->GetYZWnd()->Height(), g_xywindow_globals_private.m_MSAA, false ); + g_pParentWnd->GetYZWnd()->fbo_get()->reset( g_pParentWnd->GetYZWnd()->Width(), g_pParentWnd->GetYZWnd()->Height(), g_xywindow_globals_private.m_MSAA, false ); } } typedef FreeCaller1 MSAAImportCaller; diff --git a/radiant/xywindow.h b/radiant/xywindow.h index eca14b2b..73c8a45a 100644 --- a/radiant/xywindow.h +++ b/radiant/xywindow.h @@ -78,6 +78,7 @@ DeferredDraw m_deferredDraw; DeferredMotion m_deferred_motion; public: FBO* m_fbo; +FBO* fbo_get(); GtkWindow* m_parent; XYWnd(); ~XYWnd();