Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement X11 HW-synced swapping using glXJoinSwapGroupNV, glXBindSwa… #1336

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/osgViewer/api/X11/GraphicsWindowX11
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
/** Set mouse cursor to a specific shape.*/
virtual void setCursor(MouseCursor cursor);

/** Set swap group. */
virtual void setSwapGroup(bool on, GLuint group, GLuint barrier);

/** WindowData is used to pass in the X11 window handle attached the GraphicsContext::Traits structure. */
struct WindowData : public osg::Referenced
{
Expand Down
40 changes: 40 additions & 0 deletions src/osgViewer/GraphicsWindowX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,12 @@ void GraphicsWindowX11::swapBuffersImplementation()
glXWaitVideoSyncSGI(1, 0, &counter);
}
#endif
static bool init = false;
if (_traits.valid() && _traits->swapGroupEnabled && !init) {
setSwapGroup(_traits->swapGroupEnabled, _traits->swapGroup, _traits->swapBarrier);
init = true;
}

glXSwapBuffers( _display, _window );
#endif

Expand Down Expand Up @@ -1767,6 +1773,40 @@ void GraphicsWindowX11::transformMouseXY(float& x, float& y)
}
}

#ifndef OSG_USE_EGL
void GraphicsWindowX11::setSwapGroup(bool on, GLuint group, GLuint barrier)
{
if (_traits.valid())
{
_traits->swapGroupEnabled = on;
_traits->swapGroup = group;
_traits->swapBarrier = barrier;
}

typedef Bool (GL_APIENTRY *PFNGLXJOINSWAPGROUPNVPROC) (Display *dpy, GLXDrawable drawable, GLuint group);
PFNGLXJOINSWAPGROUPNVPROC glXJoinSwapGroupNV = (PFNGLXJOINSWAPGROUPNVPROC)glXGetProcAddress( (GLubyte *)"glXJoinSwapGroupNV" );

typedef Bool (GL_APIENTRY *PFNGLXBINDSWAPBARRIERNVPROC) (Display *dpy, GLuint group, GLuint barrier);
PFNGLXBINDSWAPBARRIERNVPROC glXBindSwapBarrierNV = (PFNGLXBINDSWAPBARRIERNVPROC)glXGetProcAddress( (GLubyte *)"glXBindSwapBarrierNV" );

if ((!glXJoinSwapGroupNV) || (!glXBindSwapBarrierNV))
{
OSG_INFO << "GraphicsWindowX11::setSwapGroup(bool, GLuint, GLuint) not supported" << std::endl;
return;
}

int swapGroup = (on ? group : 0);
Bool resultJoin = glXJoinSwapGroupNV(_display, _window, swapGroup);
OSG_INFO << "GraphicsWindowX11::glXJoinSwapGroupNV (" << swapGroup
<< ") returned " << resultJoin << std::endl;

int swapBarrier = (on ? barrier : 0);
Bool resultBind = glXBindSwapBarrierNV(_display, swapGroup, swapBarrier);
OSG_INFO << "GraphicsWindowX11::glXBindSwapBarrierNV (" << swapGroup << ", "
<< swapBarrier << ") returned " << resultBind << std::endl;
}
#endif

void GraphicsWindowX11::adaptKey(XKeyEvent& keyevent, int& keySymbol, int& unmodifiedKeySymbol)
{
unsigned char buffer_return[32];
Expand Down