mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Adjusted OpenGL and Window example to request a 24-bit instead of a 32-bit depth buffer since it might not be supported on all systems.
This commit is contained in:
parent
1d16748ed7
commit
97bdf72ce1
@ -14,9 +14,9 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Request a 32-bits depth buffer when creating the window
|
// Request a 24-bits depth buffer when creating the window
|
||||||
sf::ContextSettings contextSettings;
|
sf::ContextSettings contextSettings;
|
||||||
contextSettings.depthBits = 32;
|
contextSettings.depthBits = 24;
|
||||||
|
|
||||||
// Create the main window
|
// Create the main window
|
||||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML graphics with OpenGL", sf::Style::Default, contextSettings);
|
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML graphics with OpenGL", sf::Style::Default, contextSettings);
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Request a 32-bits depth buffer when creating the window
|
// Request a 24-bits depth buffer when creating the window
|
||||||
sf::ContextSettings contextSettings;
|
sf::ContextSettings contextSettings;
|
||||||
contextSettings.depthBits = 32;
|
contextSettings.depthBits = 24;
|
||||||
|
|
||||||
// Create the main window
|
// Create the main window
|
||||||
sf::Window window(sf::VideoMode(640, 480), "SFML window with OpenGL", sf::Style::Default, contextSettings);
|
sf::Window window(sf::VideoMode(640, 480), "SFML window with OpenGL", sf::Style::Default, contextSettings);
|
||||||
|
@ -96,6 +96,11 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
// AMD drivers have issues with internal synchronization
|
||||||
|
// We need to make sure that no operating system context
|
||||||
|
// or pixel format operations are performed simultaneously
|
||||||
|
sf::Mutex mutex;
|
||||||
|
|
||||||
// This per-thread variable holds the current context for each thread
|
// This per-thread variable holds the current context for each thread
|
||||||
sf::ThreadLocalPtr<sf::priv::GlContext> currentContext(NULL);
|
sf::ThreadLocalPtr<sf::priv::GlContext> currentContext(NULL);
|
||||||
|
|
||||||
@ -141,6 +146,8 @@ namespace priv
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void GlContext::globalInit()
|
void GlContext::globalInit()
|
||||||
{
|
{
|
||||||
|
Lock lock(mutex);
|
||||||
|
|
||||||
// Create the shared context
|
// Create the shared context
|
||||||
sharedContext = new ContextType(NULL);
|
sharedContext = new ContextType(NULL);
|
||||||
sharedContext->initialize();
|
sharedContext->initialize();
|
||||||
@ -155,6 +162,8 @@ void GlContext::globalInit()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void GlContext::globalCleanup()
|
void GlContext::globalCleanup()
|
||||||
{
|
{
|
||||||
|
Lock lock(mutex);
|
||||||
|
|
||||||
// Destroy the shared context
|
// Destroy the shared context
|
||||||
delete sharedContext;
|
delete sharedContext;
|
||||||
sharedContext = NULL;
|
sharedContext = NULL;
|
||||||
@ -179,6 +188,9 @@ void GlContext::ensureContext()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
GlContext* GlContext::create()
|
GlContext* GlContext::create()
|
||||||
{
|
{
|
||||||
|
Lock lock(mutex);
|
||||||
|
|
||||||
|
// Create the context
|
||||||
GlContext* context = new ContextType(sharedContext);
|
GlContext* context = new ContextType(sharedContext);
|
||||||
context->initialize();
|
context->initialize();
|
||||||
|
|
||||||
@ -192,6 +204,8 @@ GlContext* GlContext::create(const ContextSettings& settings, const WindowImpl*
|
|||||||
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
|
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
|
||||||
ensureContext();
|
ensureContext();
|
||||||
|
|
||||||
|
Lock lock(mutex);
|
||||||
|
|
||||||
// Create the context
|
// Create the context
|
||||||
GlContext* context = new ContextType(sharedContext, settings, owner, bitsPerPixel);
|
GlContext* context = new ContextType(sharedContext, settings, owner, bitsPerPixel);
|
||||||
context->initialize();
|
context->initialize();
|
||||||
@ -207,6 +221,8 @@ GlContext* GlContext::create(const ContextSettings& settings, unsigned int width
|
|||||||
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
|
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
|
||||||
ensureContext();
|
ensureContext();
|
||||||
|
|
||||||
|
Lock lock(mutex);
|
||||||
|
|
||||||
// Create the context
|
// Create the context
|
||||||
GlContext* context = new ContextType(sharedContext, settings, width, height);
|
GlContext* context = new ContextType(sharedContext, settings, width, height);
|
||||||
context->initialize();
|
context->initialize();
|
||||||
@ -221,6 +237,8 @@ GlFunctionPointer GlContext::getFunction(const char* name)
|
|||||||
{
|
{
|
||||||
#if !defined(SFML_OPENGL_ES)
|
#if !defined(SFML_OPENGL_ES)
|
||||||
|
|
||||||
|
Lock lock(mutex);
|
||||||
|
|
||||||
return ContextType::getFunction(name);
|
return ContextType::getFunction(name);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -254,6 +272,8 @@ bool GlContext::setActive(bool active)
|
|||||||
{
|
{
|
||||||
if (this != currentContext)
|
if (this != currentContext)
|
||||||
{
|
{
|
||||||
|
Lock lock(mutex);
|
||||||
|
|
||||||
// Activate the context
|
// Activate the context
|
||||||
if (makeCurrent())
|
if (makeCurrent())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user