Fixed issue 9 (update opengl version of a context on OS X)

This commit is contained in:
Marco Antognini 2011-04-27 22:44:55 +02:00
parent becf51572f
commit 6eac4256f3
2 changed files with 53 additions and 11 deletions

View File

@ -150,6 +150,13 @@ private:
unsigned int bitsPerPixel, unsigned int bitsPerPixel,
const ContextSettings& settings); const ContextSettings& settings);
////////////////////////////////////////////////////////////
/// \brief Finish updating our settings
/// \note The context must be active in order to get the OpenGL version.
///
////////////////////////////////////////////////////////////
void UpdateOpenGLVersion();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -60,6 +60,9 @@ SFContext::SFContext(SFContext* shared)
// Activate the context // Activate the context
SetActive(true); SetActive(true);
// Finish updating settings.
UpdateOpenGLVersion();
} }
@ -79,6 +82,9 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
// Activate the context // Activate the context
SetActive(true); SetActive(true);
// Finish updating settings.
UpdateOpenGLVersion();
} }
@ -106,8 +112,12 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
// Activate the context // Activate the context
SetActive(true); SetActive(true);
// Finish updating settings.
UpdateOpenGLVersion();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFContext::~SFContext() SFContext::~SFContext()
{ {
@ -210,12 +220,37 @@ void SFContext::CreateContext(SFContext* shared,
// Free up. // Free up.
[pixFmt release]; [pixFmt release];
#warning update settings with ogl version not yet implemented // Save the settings. (OpenGL version is updated elsewhere.)
// Save the creation settings
mySettings = settings; mySettings = settings;
} }
////////////////////////////////////////////////////////////
void SFContext::UpdateOpenGLVersion()
{
// Update the OpenGL version in the settings.
// NB : the context muste be active to get its version.
GLubyte const* versionString = glGetString(GL_VERSION);
if (versionString == 0) {
// (Warning) Couldn't get the OpenGL version of the context.
// This happens sometimes (but not always) when creating the first
// context for no apparent reason.
// We assume we can get at least a 2.0 valid context.
mySettings.MajorVersion = 2;
mySettings.MinorVersion = 0;
} else {
// versionString looks like "2.1 NVIDIA-1.6.26".
mySettings.MajorVersion = versionString[0];
mySettings.MinorVersion = versionString[2];
}
}
} // namespace priv } // namespace priv
} // namespace sf } // namespace sf