Skip to content

Commit

Permalink
Faker: Don't clear new Pbuffer if drawing to FBO
Browse files Browse the repository at this point in the history
Since the beginning, VirtualGL has cleared new "virtual window" Pbuffers
(Pbuffers that it creates to emulate OpenGL windows) when the Pbuffers
are made current for the first time.  Unlike new X windows, the contents
of new Pbuffers are undefined, and "back in the day", some OpenGL
implementations did not clear new Pbuffers.  Applications were
particularly economical with their 3D rendering back then, and some of
them relied on the fact that new X windows start out blank.  Thus,
VirtualGL had to clear new virtual window Pbuffers, particularly ones
that it created in midstream (in response to a window resize that
occurred between glXSwapBuffers() or glXMakeCurrent() calls.)  Since the
Pbuffer clearing code was introduced before VirtualGL was open sourced,
information about the specific OpenGL implementations and 3D
applications that necessitated it has been lost to history.  Clearing
new virtual window Pbuffers is likely never necessary in 2024, and it
definitely isn't necessary unless the default framebuffer is bound to
the GL_DRAW_FRAMEBUFFER target.  (FBOs weren't a thing "back in the
day.")

VirtualGL handles midstream window resizes in the body of glViewport(),
but because FBOs and their bindings are attached to a specific context
rather than a specific drawable, the first glViewport() call that a 3D
application makes after its window is resized might be made while an FBO
is bound to the GL_DRAW_FRAMEBUFFER target.  That is the case with
Firefox, so VirtualGL's attempt to clear the new virtual window Pbuffer
that it created in the body of glViewport() cleared part of an FBO
instead, resulting in the disappearance of random characters or other
elements of the Firefox window.

Modern OpenGL implementations seem to clear new Pbuffers, at least in my
limited testing, so we could probably get away with jettisoning the
Pbuffer clearing code altogether.  However, the minimally invasive fix
is simply to forego clearing a new virtual window Pbuffer if an FBO is
bound to the GL_DRAW_FRAMEBUFFER target.

Note that this appears to have been the "update issue" that I observed
in certain versions of Firefox and documented in
#228 (comment)
In fact, the issue was always reproducible with either back end.  I
didn't always observe it because it didn't always occur unless you
resized the Firefox window repeatedly, and it was more likely to occur
with the GLX back end than with the EGL back end.
  • Loading branch information
dcommander committed Feb 21, 2024
1 parent 26d713e commit ac29587
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ display manager was restarted.
3. Fixed an issue whereby the VirtualGL Configuration dialog did not pop up if
the X keyboard extension was enabled on the 2D X server.

4. Fixed an issue in the VirtualGL Faker that caused random characters and
other elements of the Firefox browser window to disappear when the window was
resized.


2.6.6 ESR
=========
Expand Down
5 changes: 4 additions & 1 deletion server/VirtualDrawable.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C)2004 Landmark Graphics Corporation
// Copyright (C)2005, 2006 Sun Microsystems, Inc.
// Copyright (C)2009-2015, 2017-2020 D. R. Commander
// Copyright (C)2009-2015, 2017-2020, 2024 D. R. Commander
//
// This library is free software and may be redistributed and/or modified under
// the terms of the wxWindows Library License, Version 3.1 or (at your option)
Expand Down Expand Up @@ -169,6 +169,9 @@ void VirtualDrawable::OGLDrawable::clear(void)
{
if(cleared) return;
cleared = true;
int drawFBO = -1;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFBO);
if(drawFBO != 0) return;
GLfloat params[4];
_glGetFloatv(GL_COLOR_CLEAR_VALUE, params);
_glClearColor(0, 0, 0, 0);
Expand Down

0 comments on commit ac29587

Please sign in to comment.