Skip to content

Commit

Permalink
#5231: Avoid flickering during map load, caused by buffer swapping ev…
Browse files Browse the repository at this point in the history
…en though no rendering is happening
  • Loading branch information
codereader committed Jun 28, 2020
1 parent fb542d8 commit cceb7dc
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 38 deletions.
11 changes: 7 additions & 4 deletions libs/wxutil/GLWidget.cpp
Expand Up @@ -15,7 +15,7 @@ const int ATTRIBS [] = {
0
};

GLWidget::GLWidget(wxWindow *parent, const std::function<void()>& renderCallback, const std::string& name) :
GLWidget::GLWidget(wxWindow *parent, const std::function<bool()>& renderCallback, const std::string& name) :
wxGLCanvas(parent, wxID_ANY, ATTRIBS, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE | wxWANTS_CHARS,
wxString(name.c_str(), *wxConvCurrent)),
Expand Down Expand Up @@ -88,9 +88,12 @@ void GLWidget::OnPaint(wxPaintEvent& WXUNUSED(event))
SetCurrent(GlobalOpenGL().getwxGLContext());
}

_renderCallback();

SwapBuffers();
if (_renderCallback())
{
// Render callback returned true, so drawing took place
// and we can swap the buffers
SwapBuffers();
}
}

} // namespace
4 changes: 2 additions & 2 deletions libs/wxutil/GLWidget.h
Expand Up @@ -20,14 +20,14 @@ class GLWidget :
bool _registered;

// The attached client method to invoke to render this view
std::function<void()> _renderCallback;
std::function<bool()> _renderCallback;

// Some widgets have their own openGL context,
// If it is non-NULL _privateContext will be used.
wxGLContext* _privateContext;

public:
GLWidget(wxWindow *parent, const std::function<void()>& renderCallback, const std::string& name);
GLWidget(wxWindow *parent, const std::function<bool()>& renderCallback, const std::string& name);

// Call this to enable/disable the private GL context of this widget
void SetHasPrivateContext(bool hasPrivateContext);
Expand Down
6 changes: 4 additions & 2 deletions libs/wxutil/preview/GuiView.cpp
Expand Up @@ -78,9 +78,9 @@ void GuiView::setGLViewPort()
debug::assertNoGlErrors();
}

void GuiView::draw()
bool GuiView::draw()
{
if (_gui == NULL) return;
if (!_gui) return false;

debug::assertNoGlErrors();

Expand Down Expand Up @@ -117,6 +117,8 @@ void GuiView::draw()
debug::assertNoGlErrors();

_renderer.render();

return true;
}

void GuiView::onSizeAllocate(wxSizeEvent& ev)
Expand Down
2 changes: 1 addition & 1 deletion libs/wxutil/preview/GuiView.h
Expand Up @@ -51,7 +51,7 @@ class GuiView :

protected:
// Performs the actual GL setup and drawing
virtual void draw();
virtual bool draw();

// Calculates the visible area
virtual void setGLViewPort();
Expand Down
8 changes: 5 additions & 3 deletions libs/wxutil/preview/RenderPreview.cpp
Expand Up @@ -419,9 +419,9 @@ RenderStateFlags RenderPreview::getRenderFlagsWireframe()
RENDER_PROGRAM;
}

void RenderPreview::drawPreview()
bool RenderPreview::drawPreview()
{
if (_renderingInProgress) return; // avoid double-entering this method
if (_renderingInProgress) return false; // avoid double-entering this method

if (!_initialised)
{
Expand Down Expand Up @@ -451,7 +451,7 @@ void RenderPreview::drawPreview()
{
// a return value of false means to cancel rendering
drawTime();
return;
return true; // swap buffers
}

// Set up the camera
Expand Down Expand Up @@ -489,6 +489,8 @@ void RenderPreview::drawPreview()

// Draw the render time
drawTime();

return true;
}

void RenderPreview::renderWireFrame()
Expand Down
2 changes: 1 addition & 1 deletion libs/wxutil/preview/RenderPreview.h
Expand Up @@ -41,7 +41,7 @@ class RenderPreview :
{
private:
void connectToolbarSignals();
void drawPreview();
bool drawPreview();
void onGLScroll(wxMouseEvent& ev);
void onGLMouseClick(wxMouseEvent& ev);
void onGLMouseRelease(wxMouseEvent& ev);
Expand Down
13 changes: 6 additions & 7 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -780,14 +780,9 @@ void CamWnd::Cam_Draw()
glBindTexture( GL_TEXTURE_2D, 0 );
}

void CamWnd::onRender()
bool CamWnd::onRender()
{
draw();
}

void CamWnd::draw()
{
if (_drawing) return;
if (_drawing) return false;

util::ScopedBoolLock lock(_drawing);

Expand All @@ -798,7 +793,11 @@ void CamWnd::draw()
Cam_Draw();

debug::assertNoGlErrors();

return true;
}

return false;
}

void CamWnd::benchmark()
Expand Down
3 changes: 1 addition & 2 deletions radiant/camera/CamWnd.h
Expand Up @@ -95,7 +95,6 @@ class CamWnd :
void queueDraw() override;
void forceRedraw() override;

void draw();
void update();

// The callback when the scene gets changed
Expand Down Expand Up @@ -166,7 +165,7 @@ class CamWnd :
void updateToolbarVisibility();

void Cam_Draw();
void onRender();
bool onRender();
void drawTime();

CameraMouseToolEvent createMouseEvent(const Vector2& point, const Vector2& delta = Vector2(0, 0));
Expand Down
13 changes: 8 additions & 5 deletions radiant/textool/TexTool.cpp
Expand Up @@ -737,11 +737,11 @@ void TexTool::drawGrid()
}
}

void TexTool::onGLDraw()
bool TexTool::onGLDraw()
{
if (_updateNeeded)
{
return; // stop here, wait for the next idle event to refresh
return false; // stop here, wait for the next idle event to refresh
}

// Initialise the viewport
Expand All @@ -761,14 +761,15 @@ void TexTool::onGLDraw()
// Do nothing, if the shader name is empty
if (_shader == NULL || _shader->getName().empty())
{
return;
return true;
}

AABB& selAABB = getExtents();

// Is there a valid selection?
if (!selAABB.isValid()) {
return;
if (!selAABB.isValid())
{
return true;
}

AABB& texSpaceAABB = getVisibleTexSpace();
Expand Down Expand Up @@ -845,6 +846,8 @@ void TexTool::onGLDraw()
glEnd();
glDisable(GL_BLEND);
}

return true;
}

void TexTool::onGLResize(wxSizeEvent& ev)
Expand Down
2 changes: 1 addition & 1 deletion radiant/textool/TexTool.h
Expand Up @@ -184,7 +184,7 @@ class TexTool :
*/
Vector2 getTextureCoords(const double& x, const double& y);

void onGLDraw();
bool onGLDraw();
void onGLResize(wxSizeEvent& ev);

// The callbacks for capturing the mouse events
Expand Down
6 changes: 4 additions & 2 deletions radiant/ui/common/ShaderSelector.cpp
Expand Up @@ -250,12 +250,12 @@ void ShaderSelector::updateInfoTable()
}

// Callback to redraw the GL widget
void ShaderSelector::onPreviewRender()
bool ShaderSelector::onPreviewRender()
{
// Get the viewport size from the GL widget
wxSize req = _glWidget->GetClientSize();

if (req.GetWidth() == 0 || req.GetHeight() == 0) return;
if (req.GetWidth() == 0 || req.GetHeight() == 0) return false;

glViewport(0, 0, req.GetWidth(), req.GetHeight());

Expand Down Expand Up @@ -325,6 +325,8 @@ void ShaderSelector::onPreviewRender()
glVertex2f(0.5*req.GetWidth() - hfWidth, 0.5*req.GetHeight() + hfHeight);
glEnd();
}

return true;
}

namespace
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/common/ShaderSelector.h
Expand Up @@ -156,7 +156,7 @@ class ShaderSelector :
void updateInfoTable();

// callbacks
void onPreviewRender();
bool onPreviewRender();
void _onSelChange(wxDataViewEvent& ev);
};

Expand Down
6 changes: 4 additions & 2 deletions radiant/ui/common/TexturePreviewCombo.cpp
Expand Up @@ -99,12 +99,12 @@ void TexturePreviewCombo::_onContextMenu(wxDataViewEvent& ev)
}

// CALLBACKS
void TexturePreviewCombo::_onRender()
bool TexturePreviewCombo::_onRender()
{
// Get the viewport size from the GL widget
wxSize req = _glWidget->GetClientSize();

if (req.GetWidth() == 0 || req.GetHeight() == 0) return;
if (req.GetWidth() == 0 || req.GetHeight() == 0) return false;

glPushAttrib(GL_ALL_ATTRIB_BITS);

Expand Down Expand Up @@ -167,6 +167,8 @@ void TexturePreviewCombo::_onRender()
}

glPopAttrib();

return true;
}

}
2 changes: 1 addition & 1 deletion radiant/ui/common/TexturePreviewCombo.h
Expand Up @@ -52,7 +52,7 @@ class TexturePreviewCombo :
void _onCopyTexName();

// render callback
void _onRender();
bool _onRender();

// Refresh info table utility function
void refreshInfoTable();
Expand Down
10 changes: 9 additions & 1 deletion radiant/ui/texturebrowser/TextureBrowser.cpp
Expand Up @@ -3,6 +3,7 @@
#include "i18n.h"
#include "ieventmanager.h"
#include "itextstream.h"
#include "imainframe.h"
#include "iuimanager.h"
#include "igroupdialog.h"
#include "iradiant.h"
Expand Down Expand Up @@ -940,8 +941,13 @@ void TextureBrowser::onIdle(wxIdleEvent& ev)
}
}

void TextureBrowser::onRender()
bool TextureBrowser::onRender()
{
if (!GlobalMainFrame().screenUpdatesEnabled())
{
return false;
}

debug::assertNoGlErrors();

if (_updateNeeded)
Expand All @@ -952,6 +958,8 @@ void TextureBrowser::onRender()
draw();

debug::assertNoGlErrors();

return true;
}

} // namespace ui
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/texturebrowser/TextureBrowser.h
Expand Up @@ -226,7 +226,7 @@ class TextureBrowser :

// wx callbacks
void onIdle(wxIdleEvent& ev);
void onRender();
bool onRender();
void onScrollChanged(wxScrollEvent& ev);
void onGLResize(wxSizeEvent& ev);
void onGLMouseScroll(wxMouseEvent& ev);
Expand Down
7 changes: 6 additions & 1 deletion radiant/xyview/XYWnd.cpp
Expand Up @@ -1540,14 +1540,19 @@ void XYWnd::onGLResize(wxSizeEvent& ev)
ev.Skip();
}

void XYWnd::onRender()
bool XYWnd::onRender()
{
if (GlobalMainFrame().screenUpdatesEnabled())
{
util::ScopedBoolLock drawLock(_drawing);

draw();

return true;
}


return false; // nothing rendered
}

void XYWnd::onGLWindowScroll(wxMouseEvent& ev)
Expand Down
2 changes: 1 addition & 1 deletion radiant/xyview/XYWnd.h
Expand Up @@ -185,7 +185,7 @@ class XYWnd :
void handleGLCapturedMouseMotion(const MouseToolPtr& tool, int x, int y, unsigned int state);

// wxGLWidget-attached render method
void onRender();
bool onRender();
void onGLResize(wxSizeEvent& ev);
void onGLWindowScroll(wxMouseEvent& ev);

Expand Down

0 comments on commit cceb7dc

Please sign in to comment.