mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
The version returned by Window::GetSettings() is now the actual version of the context
This commit is contained in:
parent
6eac4256f3
commit
49c0208b2e
@ -102,7 +102,7 @@ namespace sf
|
|||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void GlContext::Initialize()
|
void GlContext::GlobalInit()
|
||||||
{
|
{
|
||||||
// Create the shared context
|
// Create the shared context
|
||||||
sharedContext = new ContextType(NULL);
|
sharedContext = new ContextType(NULL);
|
||||||
@ -115,7 +115,7 @@ void GlContext::Initialize()
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void GlContext::Cleanup()
|
void GlContext::GlobalCleanup()
|
||||||
{
|
{
|
||||||
// Destroy the shared context
|
// Destroy the shared context
|
||||||
delete sharedContext;
|
delete sharedContext;
|
||||||
@ -141,7 +141,10 @@ void GlContext::EnsureContext()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
GlContext* GlContext::New()
|
GlContext* GlContext::New()
|
||||||
{
|
{
|
||||||
return new ContextType(sharedContext);
|
GlContext* context = new ContextType(sharedContext);
|
||||||
|
context->Initialize();
|
||||||
|
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -153,10 +156,7 @@ GlContext* GlContext::New(const ContextSettings& settings, const WindowImpl* own
|
|||||||
|
|
||||||
// Create the context
|
// Create the context
|
||||||
GlContext* context = new ContextType(sharedContext, settings, owner, bitsPerPixel);
|
GlContext* context = new ContextType(sharedContext, settings, owner, bitsPerPixel);
|
||||||
|
context->Initialize();
|
||||||
// Enable antialiasing if needed
|
|
||||||
if (context->GetSettings().AntialiasingLevel > 0)
|
|
||||||
glEnable(GL_MULTISAMPLE_ARB);
|
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
@ -170,10 +170,7 @@ GlContext* GlContext::New(const ContextSettings& settings, unsigned int width, u
|
|||||||
|
|
||||||
// Create the context
|
// Create the context
|
||||||
GlContext* context = new ContextType(sharedContext, settings, width, height);
|
GlContext* context = new ContextType(sharedContext, settings, width, height);
|
||||||
|
context->Initialize();
|
||||||
// Enable antialiasing if needed
|
|
||||||
if (context->GetSettings().AntialiasingLevel > 0)
|
|
||||||
glEnable(GL_MULTISAMPLE_ARB);
|
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
@ -253,6 +250,33 @@ int GlContext::EvaluateFormat(unsigned int bitsPerPixel, const ContextSettings&
|
|||||||
std::abs(static_cast<int>(settings.AntialiasingLevel - antialiasing));
|
std::abs(static_cast<int>(settings.AntialiasingLevel - antialiasing));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void GlContext::Initialize()
|
||||||
|
{
|
||||||
|
// Activate the context
|
||||||
|
SetActive(true);
|
||||||
|
|
||||||
|
// Retrieve the context version number
|
||||||
|
const GLubyte* version = glGetString(GL_VERSION);
|
||||||
|
if (version)
|
||||||
|
{
|
||||||
|
// The beginning of the returned string is "major.minor" (this is standard)
|
||||||
|
mySettings.MajorVersion = version[0] - '0';
|
||||||
|
mySettings.MinorVersion = version[2] - '0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Can't get the version number, assume 2.0
|
||||||
|
mySettings.MajorVersion = 2;
|
||||||
|
mySettings.MinorVersion = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable antialiasing if needed
|
||||||
|
if (mySettings.AntialiasingLevel > 0)
|
||||||
|
glEnable(GL_MULTISAMPLE_ARB);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
@ -57,7 +57,7 @@ public :
|
|||||||
/// can be called only once.
|
/// can be called only once.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void Initialize();
|
static void GlobalInit();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Perform the global cleanup
|
/// \brief Perform the global cleanup
|
||||||
@ -69,7 +69,7 @@ public :
|
|||||||
/// can be called only once.
|
/// can be called only once.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void Cleanup();
|
static void GlobalCleanup();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Ensures that an OpenGL context is active in the current thread
|
/// \brief Ensures that an OpenGL context is active in the current thread
|
||||||
@ -217,6 +217,14 @@ protected :
|
|||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
ContextSettings mySettings; ///< Creation settings of the context
|
ContextSettings mySettings; ///< Creation settings of the context
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Perform various initializations after the context construction
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void Initialize();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
@ -54,7 +54,7 @@ GlResource::GlResource()
|
|||||||
|
|
||||||
// If this is the very first resource, trigger the global context initialization
|
// If this is the very first resource, trigger the global context initialization
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
priv::GlContext::Initialize();
|
priv::GlContext::GlobalInit();
|
||||||
|
|
||||||
// Increment the resources counter
|
// Increment the resources counter
|
||||||
count++;
|
count++;
|
||||||
@ -76,7 +76,7 @@ GlResource::~GlResource()
|
|||||||
|
|
||||||
// If there's no more resource alive, we can trigger the global context cleanup
|
// If there's no more resource alive, we can trigger the global context cleanup
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
priv::GlContext::Cleanup();
|
priv::GlContext::GlobalCleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,9 +60,6 @@ myOwnsWindow(true)
|
|||||||
|
|
||||||
// Create the context
|
// Create the context
|
||||||
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings());
|
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings());
|
||||||
|
|
||||||
// Activate the context
|
|
||||||
SetActive(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -81,9 +78,6 @@ myOwnsWindow(false)
|
|||||||
// Create the context
|
// Create the context
|
||||||
if (myWindow)
|
if (myWindow)
|
||||||
CreateContext(shared, bitsPerPixel, settings);
|
CreateContext(shared, bitsPerPixel, settings);
|
||||||
|
|
||||||
// Activate the context
|
|
||||||
SetActive(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -110,9 +104,6 @@ myOwnsWindow(true)
|
|||||||
|
|
||||||
// Create the context
|
// Create the context
|
||||||
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, settings);
|
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, settings);
|
||||||
|
|
||||||
// Activate the context
|
|
||||||
SetActive(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,13 +150,6 @@ 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
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -57,12 +57,6 @@ SFContext::SFContext(SFContext* shared)
|
|||||||
|
|
||||||
// Create the context
|
// Create the context
|
||||||
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings(0, 0, 0));
|
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings(0, 0, 0));
|
||||||
|
|
||||||
// Activate the context
|
|
||||||
SetActive(true);
|
|
||||||
|
|
||||||
// Finish updating settings.
|
|
||||||
UpdateOpenGLVersion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -79,12 +73,6 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
|||||||
// Apply context.
|
// Apply context.
|
||||||
WindowImplCocoa const * ownerCocoa = static_cast<WindowImplCocoa const *>(owner);
|
WindowImplCocoa const * ownerCocoa = static_cast<WindowImplCocoa const *>(owner);
|
||||||
ownerCocoa->ApplyContext(myContext);
|
ownerCocoa->ApplyContext(myContext);
|
||||||
|
|
||||||
// Activate the context
|
|
||||||
SetActive(true);
|
|
||||||
|
|
||||||
// Finish updating settings.
|
|
||||||
UpdateOpenGLVersion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -109,12 +97,6 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
|||||||
[myWindow setContentView:myView];
|
[myWindow setContentView:myView];
|
||||||
[myView setOpenGLContext:myContext];
|
[myView setOpenGLContext:myContext];
|
||||||
[myContext setView:myView];
|
[myContext setView:myView];
|
||||||
|
|
||||||
// Activate the context
|
|
||||||
SetActive(true);
|
|
||||||
|
|
||||||
// Finish updating settings.
|
|
||||||
UpdateOpenGLVersion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -224,33 +206,6 @@ void SFContext::CreateContext(SFContext* shared,
|
|||||||
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
|
||||||
|
@ -56,9 +56,6 @@ myOwnsWindow (true)
|
|||||||
// Create the context
|
// Create the context
|
||||||
if (myDeviceContext)
|
if (myDeviceContext)
|
||||||
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings());
|
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings());
|
||||||
|
|
||||||
// Activate the context
|
|
||||||
SetActive(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -76,9 +73,6 @@ myOwnsWindow (false)
|
|||||||
// Create the context
|
// Create the context
|
||||||
if (myDeviceContext)
|
if (myDeviceContext)
|
||||||
CreateContext(shared, bitsPerPixel, settings);
|
CreateContext(shared, bitsPerPixel, settings);
|
||||||
|
|
||||||
// Activate the context
|
|
||||||
SetActive(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -102,9 +96,6 @@ myOwnsWindow (true)
|
|||||||
// Create the context
|
// Create the context
|
||||||
if (myDeviceContext)
|
if (myDeviceContext)
|
||||||
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, settings);
|
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, settings);
|
||||||
|
|
||||||
// Activate the context
|
|
||||||
SetActive(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user