Changed the GlxContext implementation to always try to use glXCreateContextAttribsARB if it is available (was already done in the WGL implementation), specification of the context version attributes now only takes place when a context version greater than 1.1 is requested, requesting version 1.0 or 1.1 (default) will hint the driver to provide the most recent context version they support.

This commit is contained in:
binary1248 2015-05-04 12:39:43 +02:00
parent 2752bbcfb0
commit c4be28bd0f
2 changed files with 52 additions and 56 deletions

View File

@ -31,6 +31,7 @@
#include <SFML/System/Mutex.hpp> #include <SFML/System/Mutex.hpp>
#include <SFML/System/Lock.hpp> #include <SFML/System/Lock.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <vector>
#if !defined(GLX_DEBUGGING) && defined(SFML_DEBUG) #if !defined(GLX_DEBUGGING) && defined(SFML_DEBUG)
// Enable this to print messages to err() everytime GLX produces errors // Enable this to print messages to err() everytime GLX produces errors
@ -418,16 +419,8 @@ void GlxContext::createContext(GlxContext* shared, unsigned int bitsPerPixel, co
// Check if glXCreateContextAttribsARB is available (requires GLX 1.3 or greater) // Check if glXCreateContextAttribsARB is available (requires GLX 1.3 or greater)
bool hasCreateContextArb = (sfglx_ext_ARB_create_context == sfglx_LOAD_SUCCEEDED) && ((major > 1) || (minor >= 3)); bool hasCreateContextArb = (sfglx_ext_ARB_create_context == sfglx_LOAD_SUCCEEDED) && ((major > 1) || (minor >= 3));
// Check if we need to use glXCreateContextAttribsARB // Create the OpenGL context -- first try using glXCreateContextAttribsARB
bool needCreateContextArb = false; if (hasCreateContextArb)
if (m_settings.attributeFlags)
needCreateContextArb = true;
else if (m_settings.majorVersion >= 3)
needCreateContextArb = true;
// Create the OpenGL context -- first try using glXCreateContextAttribsARB if we need to
if (hasCreateContextArb && needCreateContextArb)
{ {
// Get a GLXFBConfig that matches the the window's visual, for glXCreateContextAttribsARB // Get a GLXFBConfig that matches the the window's visual, for glXCreateContextAttribsARB
GLXFBConfig* config = NULL; GLXFBConfig* config = NULL;
@ -457,27 +450,27 @@ void GlxContext::createContext(GlxContext* shared, unsigned int bitsPerPixel, co
while (config && !m_context && m_settings.majorVersion) while (config && !m_context && m_settings.majorVersion)
{ {
std::vector<int> attributes;
// Check if the user requested a specific context version (anything > 1.1)
if ((m_settings.majorVersion > 1) || ((m_settings.majorVersion == 1) && (m_settings.minorVersion > 1)))
{
attributes.push_back(GLX_CONTEXT_MAJOR_VERSION_ARB);
attributes.push_back(m_settings.majorVersion);
attributes.push_back(GLX_CONTEXT_MINOR_VERSION_ARB);
attributes.push_back(m_settings.minorVersion);
}
// Check if setting the profile is supported // Check if setting the profile is supported
if (sfglx_ext_ARB_create_context_profile == sfglx_LOAD_SUCCEEDED) if (sfglx_ext_ARB_create_context_profile == sfglx_LOAD_SUCCEEDED)
{ {
int profile = (m_settings.attributeFlags & ContextSettings::Core) ? GLX_CONTEXT_CORE_PROFILE_BIT_ARB : GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; int profile = (m_settings.attributeFlags & ContextSettings::Core) ? GLX_CONTEXT_CORE_PROFILE_BIT_ARB : GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
int debug = (m_settings.attributeFlags & ContextSettings::Debug) ? GLX_CONTEXT_DEBUG_BIT_ARB : 0; int debug = (m_settings.attributeFlags & ContextSettings::Debug) ? GLX_CONTEXT_DEBUG_BIT_ARB : 0;
// Create the context attributes.push_back(GLX_CONTEXT_PROFILE_MASK_ARB);
int attributes[] = attributes.push_back(profile);
{ attributes.push_back(GLX_CONTEXT_FLAGS_ARB);
GLX_CONTEXT_MAJOR_VERSION_ARB, static_cast<int>(m_settings.majorVersion), attributes.push_back(debug);
GLX_CONTEXT_MINOR_VERSION_ARB, static_cast<int>(m_settings.minorVersion),
GLX_CONTEXT_PROFILE_MASK_ARB, profile,
GLX_CONTEXT_FLAGS_ARB, debug,
0, 0
};
// RAII GLX error handler (we simply ignore errors here)
// On an error, glXCreateContextAttribsARB will return 0 anyway
GlxErrorHandler handler(m_display);
m_context = glXCreateContextAttribsARB(m_display, *config, toShare, true, attributes);
} }
else else
{ {
@ -486,22 +479,19 @@ void GlxContext::createContext(GlxContext* shared, unsigned int bitsPerPixel, co
<< "disabling comptibility and debug" << std::endl; << "disabling comptibility and debug" << std::endl;
m_settings.attributeFlags = ContextSettings::Default; m_settings.attributeFlags = ContextSettings::Default;
// Create the context
int attributes[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, static_cast<int>(m_settings.majorVersion),
GLX_CONTEXT_MINOR_VERSION_ARB, static_cast<int>(m_settings.minorVersion),
0, 0
};
// RAII GLX error handler (we simply ignore errors here)
// On an error, glXCreateContextAttribsARB will return 0 anyway
GlxErrorHandler handler(m_display);
m_context = glXCreateContextAttribsARB(m_display, *config, toShare, true, attributes);
} }
// Append the terminating 0
attributes.push_back(0);
attributes.push_back(0);
// RAII GLX error handler (we simply ignore errors here)
// On an error, glXCreateContextAttribsARB will return 0 anyway
GlxErrorHandler handler(m_display);
// Create the context
m_context = glXCreateContextAttribsARB(m_display, *config, toShare, true, &attributes[0]);
if (!m_context) if (!m_context)
{ {
// If we couldn't create the context, first try disabling flags, // If we couldn't create the context, first try disabling flags,

View File

@ -32,6 +32,7 @@
#include <SFML/System/Mutex.hpp> #include <SFML/System/Mutex.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <sstream> #include <sstream>
#include <vector>
namespace sf namespace sf
@ -403,21 +404,27 @@ void WglContext::createContext(WglContext* shared, unsigned int bitsPerPixel, co
{ {
if (sfwgl_ext_ARB_create_context == sfwgl_LOAD_SUCCEEDED) if (sfwgl_ext_ARB_create_context == sfwgl_LOAD_SUCCEEDED)
{ {
std::vector<int> attributes;
// Check if the user requested a specific context version (anything > 1.1)
if ((m_settings.majorVersion > 1) || ((m_settings.majorVersion == 1) && (m_settings.minorVersion > 1)))
{
attributes.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB);
attributes.push_back(m_settings.majorVersion);
attributes.push_back(WGL_CONTEXT_MINOR_VERSION_ARB);
attributes.push_back(m_settings.minorVersion);
}
// Check if setting the profile is supported // Check if setting the profile is supported
if (sfwgl_ext_ARB_create_context_profile == sfwgl_LOAD_SUCCEEDED) if (sfwgl_ext_ARB_create_context_profile == sfwgl_LOAD_SUCCEEDED)
{ {
int profile = (m_settings.attributeFlags & ContextSettings::Core) ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; int profile = (m_settings.attributeFlags & ContextSettings::Core) ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
int debug = (m_settings.attributeFlags & ContextSettings::Debug) ? WGL_CONTEXT_DEBUG_BIT_ARB : 0; int debug = (m_settings.attributeFlags & ContextSettings::Debug) ? WGL_CONTEXT_DEBUG_BIT_ARB : 0;
int attributes[] = attributes.push_back(WGL_CONTEXT_PROFILE_MASK_ARB);
{ attributes.push_back(profile);
WGL_CONTEXT_MAJOR_VERSION_ARB, static_cast<int>(m_settings.majorVersion), attributes.push_back(WGL_CONTEXT_FLAGS_ARB);
WGL_CONTEXT_MINOR_VERSION_ARB, static_cast<int>(m_settings.minorVersion), attributes.push_back(debug);
WGL_CONTEXT_PROFILE_MASK_ARB, profile,
WGL_CONTEXT_FLAGS_ARB, debug,
0, 0
};
m_context = wglCreateContextAttribsARB(m_deviceContext, sharedContext, attributes);
} }
else else
{ {
@ -426,15 +433,14 @@ void WglContext::createContext(WglContext* shared, unsigned int bitsPerPixel, co
<< "disabling comptibility and debug" << std::endl; << "disabling comptibility and debug" << std::endl;
m_settings.attributeFlags = ContextSettings::Default; m_settings.attributeFlags = ContextSettings::Default;
int attributes[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, static_cast<int>(m_settings.majorVersion),
WGL_CONTEXT_MINOR_VERSION_ARB, static_cast<int>(m_settings.minorVersion),
0, 0
};
m_context = wglCreateContextAttribsARB(m_deviceContext, sharedContext, attributes);
} }
// Append the terminating 0
attributes.push_back(0);
attributes.push_back(0);
// Create the context
m_context = wglCreateContextAttribsARB(m_deviceContext, sharedContext, &attributes[0]);
} }
else else
{ {