Using a PR from Sando Mani for requestioning a specific GL version as a base, cleaned up formattating, made the new code paths simpler and added clean up of memory

This commit is contained in:
Robert Osfield 2017-08-21 11:40:45 +01:00
parent 70135d606e
commit 8926f0e9c2
3 changed files with 68 additions and 17 deletions

View File

@ -37,6 +37,7 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
_parent(0), _parent(0),
_window(0), _window(0),
_visualInfo(0), _visualInfo(0),
_fbConfig(0),
#ifdef OSG_USE_EGL #ifdef OSG_USE_EGL
_eglDisplay(0), _eglDisplay(0),
_eglSurface(0), _eglSurface(0),
@ -176,6 +177,7 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
Window _parent; Window _parent;
Window _window; Window _window;
XVisualInfo* _visualInfo; XVisualInfo* _visualInfo;
GLXFBConfig _fbConfig;
#ifdef OSG_USE_EGL #ifdef OSG_USE_EGL
EGLDisplay _eglDisplay; EGLDisplay _eglDisplay;

View File

@ -43,6 +43,7 @@
#endif #endif
#include <unistd.h> #include <unistd.h>
#include <cstdlib>
using namespace osgViewer; using namespace osgViewer;
@ -326,13 +327,10 @@ bool GraphicsWindowX11::createVisualInfo()
typedef std::vector<int> Attributes; typedef std::vector<int> Attributes;
Attributes attributes; Attributes attributes;
attributes.push_back(GLX_USE_GL); attributes.push_back(GLX_RENDER_TYPE); attributes.push_back(GLX_RGBA_BIT);
attributes.push_back(GLX_RGBA); if (_traits->doubleBuffer) { attributes.push_back(GLX_DOUBLEBUFFER); attributes.push_back(True); }
if (_traits->quadBufferStereo) { attributes.push_back(GLX_STEREO); attributes.push_back(True); }
if (_traits->doubleBuffer) attributes.push_back(GLX_DOUBLEBUFFER);
if (_traits->quadBufferStereo) attributes.push_back(GLX_STEREO);
attributes.push_back(GLX_RED_SIZE); attributes.push_back(_traits->red); attributes.push_back(GLX_RED_SIZE); attributes.push_back(_traits->red);
attributes.push_back(GLX_GREEN_SIZE); attributes.push_back(_traits->green); attributes.push_back(GLX_GREEN_SIZE); attributes.push_back(_traits->green);
@ -340,14 +338,11 @@ bool GraphicsWindowX11::createVisualInfo()
attributes.push_back(GLX_DEPTH_SIZE); attributes.push_back(_traits->depth); attributes.push_back(GLX_DEPTH_SIZE); attributes.push_back(_traits->depth);
if (_traits->alpha) { attributes.push_back(GLX_ALPHA_SIZE); attributes.push_back(_traits->alpha); } if (_traits->alpha) { attributes.push_back(GLX_ALPHA_SIZE); attributes.push_back(_traits->alpha); }
if (_traits->stencil) { attributes.push_back(GLX_STENCIL_SIZE); attributes.push_back(_traits->stencil); } if (_traits->stencil) { attributes.push_back(GLX_STENCIL_SIZE); attributes.push_back(_traits->stencil); }
#if defined(GLX_SAMPLE_BUFFERS) && defined (GLX_SAMPLES) #if defined(GLX_SAMPLE_BUFFERS) && defined (GLX_SAMPLES)
if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLE_BUFFERS); attributes.push_back(_traits->sampleBuffers); } if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLE_BUFFERS); attributes.push_back(_traits->sampleBuffers); }
if (_traits->samples) { attributes.push_back(GLX_SAMPLES); attributes.push_back(_traits->samples); } if (_traits->samples) { attributes.push_back(GLX_SAMPLES); attributes.push_back(_traits->samples); }
#endif #endif
// TODO // TODO
// GLX_AUX_BUFFERS // GLX_AUX_BUFFERS
@ -356,7 +351,16 @@ bool GraphicsWindowX11::createVisualInfo()
attributes.push_back(None); attributes.push_back(None);
_visualInfo = glXChooseVisual( _display, _traits->screenNum, &(attributes.front()) ); int numFbConfigs = 0;
GLXFBConfig* fbConfigs = glXChooseFBConfig(_display, _traits->screenNum, attributes.data(), &numFbConfigs);
if (numFbConfigs > 0)
{
_fbConfig = fbConfigs[0];
}
XFree(fbConfigs);
_visualInfo = glXGetVisualFromFBConfig(_display, _fbConfig);
#endif #endif
} }
@ -893,7 +897,58 @@ void GraphicsWindowX11::init()
#else #else
_context = glXCreateContext( _display, _visualInfo, sharedContext, True ); typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
const char* glx_str = glXQueryExtensionsString(_display, _traits->screenNum);
std::string glx_string; if (glx_str) glx_string = glx_str;
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
if (glx_string.find("GLX_ARB_create_context")!=std::string::npos)
{
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");
}
bool supportsProfiles = glx_string.find("GLX_ARB_create_context")!=std::string::npos;
if (glXCreateContextAttribsARB)
{
OSG_INFO << "Attempting to create GL context:" << std::endl;
OSG_INFO << " * version: " << _traits->glContextVersion << std::endl;
OSG_INFO << " * context flags: " << _traits->glContextFlags << std::endl;
OSG_INFO << " * profile: " << _traits->glContextProfileMask << std::endl;
std::vector<int> contextAttributes;
std::size_t pos = _traits->glContextVersion.find(".");
int majorVersion = std::atoi(_traits->glContextVersion.substr(0, pos).c_str());
int minorVersion = pos == std::string::npos ? 0 : std::atoi(_traits->glContextVersion.substr(pos + 1).c_str());
contextAttributes.push_back(GLX_CONTEXT_MAJOR_VERSION_ARB);
contextAttributes.push_back(majorVersion);
contextAttributes.push_back(GLX_CONTEXT_MINOR_VERSION_ARB);
contextAttributes.push_back(minorVersion);
// If asking for OpenGL 3.2 or newer we should also specify a profile
float glVersion = static_cast<float>(majorVersion)+static_cast<float>(minorVersion)*0.1f;
if (glVersion>=3.2 && supportsProfiles && _traits->glContextProfileMask != 0)
{
contextAttributes.push_back(GLX_CONTEXT_PROFILE_MASK_ARB);
contextAttributes.push_back(_traits->glContextProfileMask);
}
if (_traits->glContextFlags != 0)
{
contextAttributes.push_back(GLX_CONTEXT_FLAGS_ARB);
contextAttributes.push_back(_traits->glContextFlags);
}
contextAttributes.push_back(None);
_context = glXCreateContextAttribsARB( _display, _fbConfig, sharedContext, True, contextAttributes.data() );
}
else
{
_context = glXCreateContext( _display, _visualInfo, sharedContext, True );
}
if (!_context) if (!_context)
{ {

View File

@ -767,12 +767,6 @@ struct BlockDrawCallback : public virtual osg::Drawable::DrawCallback
vertices->dirty(); vertices->dirty();
osg::DrawArrays* drawArrays = dynamic_cast<osg::DrawArrays*>(geom->getPrimitiveSet(0));
if(drawArrays)
{
drawArrays->setCount(vi);
}
drawable->drawImplementation(renderInfo); drawable->drawImplementation(renderInfo);
} }