Added the context version to ContextSettings

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1261 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2009-11-03 15:13:11 +00:00
parent 9db63151e1
commit 8e4c61dd19
15 changed files with 216 additions and 68 deletions

View File

@ -18,7 +18,6 @@
/// ///
/// int main() /// int main()
/// { /// {
/// sfWindowSettings settings = {24, 8, 0};
/// sfVideoMode mode = {800, 600, 32}; /// sfVideoMode mode = {800, 600, 32};
/// sfRenderWindow* window; /// sfRenderWindow* window;
/// sfImage* image; /// sfImage* image;
@ -29,7 +28,7 @@
/// sfEvent event; /// sfEvent event;
/// ///
/// /* Create the main window */ /// /* Create the main window */
/// window = sfRenderWindow_Create(mode, "SFML window", sfResize | sfClose, settings); /// window = sfRenderWindow_Create(mode, "SFML window", sfResize | sfClose, NULL);
/// if (!window) /// if (!window)
/// return EXIT_FAILURE; /// return EXIT_FAILURE;
/// ///

View File

@ -44,19 +44,19 @@
/// \param mode : Video mode to use /// \param mode : Video mode to use
/// \param title : Title of the window /// \param title : Title of the window
/// \param style : Window style /// \param style : Window style
/// \param settings : Creation settings /// \param settings : Creation settings (pass NULL to use default values)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings settings); CSFML_API sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings* settings);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a renderwindow from an existing control /// Construct a renderwindow from an existing control
/// ///
/// \param handle : Platform-specific handle of the control /// \param handle : Platform-specific handle of the control
/// \param settings : Creation settings /// \param settings : Creation settings (pass NULL to use default values)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings settings); CSFML_API sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings* settings);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Destroy an existing renderwindow /// Destroy an existing renderwindow

View File

@ -57,6 +57,8 @@ typedef struct
unsigned int DepthBits; ///< Bits of the depth buffer unsigned int DepthBits; ///< Bits of the depth buffer
unsigned int StencilBits; ///< Bits of the stencil buffer unsigned int StencilBits; ///< Bits of the stencil buffer
unsigned int AntialiasingLevel; ///< Level of antialiasing unsigned int AntialiasingLevel; ///< Level of antialiasing
unsigned int MajorVersion; ///< Major number of the context version to create
unsigned int MinorVersion; ///< Minor number of the context version to create
} sfContextSettings; } sfContextSettings;
@ -66,19 +68,19 @@ typedef struct
/// \param mode : Video mode to use /// \param mode : Video mode to use
/// \param title : Title of the window /// \param title : Title of the window
/// \param style : Window style /// \param style : Window style
/// \param settings : Creation settings /// \param settings : Creation settings (pass NULL to use default values)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings settings); CSFML_API sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings* settings);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a window from an existing control /// Construct a window from an existing control
/// ///
/// \param handle : Platform-specific handle of the control /// \param handle : Platform-specific handle of the control
/// \param settings : Creation settings /// \param settings : Creation settings (pass NULL to use default values)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfWindow* sfWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings settings); CSFML_API sfWindow* sfWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings* settings);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Destroy an existing window /// Destroy an existing window

View File

@ -39,15 +39,25 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a new renderwindow /// Construct a new renderwindow
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings params) sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings* settings)
{ {
// Convert video mode // Convert video mode
sf::VideoMode videoMode(mode.Width, mode.Height, mode.BitsPerPixel); sf::VideoMode videoMode(mode.Width, mode.Height, mode.BitsPerPixel);
// Convert context settings
sf::ContextSettings params;
if (settings)
{
params.DepthBits = settings->DepthBits;
params.StencilBits = settings->StencilBits;
params.AntialiasingLevel = settings->AntialiasingLevel;
params.MajorVersion = settings->MajorVersion;
params.MinorVersion = settings->MinorVersion;
}
// Create the window // Create the window
sfRenderWindow* renderWindow = new sfRenderWindow; sfRenderWindow* renderWindow = new sfRenderWindow;
sf::ContextSettings settings(params.DepthBits, params.StencilBits, params.AntialiasingLevel); renderWindow->This.Create(videoMode, title, style, params);
renderWindow->This.Create(videoMode, title, style, settings);
renderWindow->Input.This = &renderWindow->This.GetInput(); renderWindow->Input.This = &renderWindow->This.GetInput();
renderWindow->DefaultView = new sfView(const_cast<sf::View*>(&renderWindow->This.GetDefaultView())); renderWindow->DefaultView = new sfView(const_cast<sf::View*>(&renderWindow->This.GetDefaultView()));
renderWindow->CurrentView = renderWindow->DefaultView; renderWindow->CurrentView = renderWindow->DefaultView;
@ -59,11 +69,22 @@ sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsig
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a renderwindow from an existing control /// Construct a renderwindow from an existing control
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings params) sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings* settings)
{ {
// Convert context settings
sf::ContextSettings params;
if (settings)
{
params.DepthBits = settings->DepthBits;
params.StencilBits = settings->StencilBits;
params.AntialiasingLevel = settings->AntialiasingLevel;
params.MajorVersion = settings->MajorVersion;
params.MinorVersion = settings->MinorVersion;
}
// Create the window
sfRenderWindow* renderWindow = new sfRenderWindow; sfRenderWindow* renderWindow = new sfRenderWindow;
sf::ContextSettings settings(params.DepthBits, params.StencilBits, params.AntialiasingLevel); renderWindow->This.Create(handle, params);
renderWindow->This.Create(handle, settings);
renderWindow->Input.This = &renderWindow->This.GetInput(); renderWindow->Input.This = &renderWindow->This.GetInput();
renderWindow->DefaultView = new sfView(const_cast<sf::View*>(&renderWindow->This.GetDefaultView())); renderWindow->DefaultView = new sfView(const_cast<sf::View*>(&renderWindow->This.GetDefaultView()));
renderWindow->CurrentView = renderWindow->DefaultView; renderWindow->CurrentView = renderWindow->DefaultView;

View File

@ -34,14 +34,24 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a new window /// Construct a new window
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings settings) sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings* settings)
{ {
// Convert video mode // Convert video mode
sf::VideoMode videoMode(mode.Width, mode.Height, mode.BitsPerPixel); sf::VideoMode videoMode(mode.Width, mode.Height, mode.BitsPerPixel);
// Convert context settings
sf::ContextSettings params;
if (settings)
{
params.DepthBits = settings->DepthBits;
params.StencilBits = settings->StencilBits;
params.AntialiasingLevel = settings->AntialiasingLevel;
params.MajorVersion = settings->MajorVersion;
params.MinorVersion = settings->MinorVersion;
}
// Create the window // Create the window
sfWindow* window = new sfWindow; sfWindow* window = new sfWindow;
sf::ContextSettings params(settings.DepthBits, settings.StencilBits, settings.AntialiasingLevel);
window->This.Create(videoMode, title, style, params); window->This.Create(videoMode, title, style, params);
window->Input.This = &window->This.GetInput(); window->Input.This = &window->This.GetInput();
@ -52,10 +62,21 @@ sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long sty
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a window from an existing control /// Construct a window from an existing control
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfWindow* sfWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings settings) sfWindow* sfWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings* settings)
{ {
// Convert context settings
sf::ContextSettings params;
if (settings)
{
params.DepthBits = settings->DepthBits;
params.StencilBits = settings->StencilBits;
params.AntialiasingLevel = settings->AntialiasingLevel;
params.MajorVersion = settings->MajorVersion;
params.MinorVersion = settings->MinorVersion;
}
// Create the window
sfWindow* window = new sfWindow; sfWindow* window = new sfWindow;
sf::ContextSettings params(settings.DepthBits, settings.StencilBits, settings.AntialiasingLevel);
window->This.Create(handle, params); window->This.Create(handle, params);
window->Input.This = &window->This.GetInput(); window->Input.This = &window->This.GetInput();

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -25,7 +25,7 @@ namespace SFML
/// <param name="title">Title of the window</param> /// <param name="title">Title of the window</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public RenderWindow(VideoMode mode, string title) : public RenderWindow(VideoMode mode, string title) :
this(mode, title, Styles.Resize | Styles.Close, new ContextSettings(24, 8, 0)) this(mode, title, Styles.Resize | Styles.Close, new ContextSettings(24, 8))
{ {
} }
@ -38,7 +38,7 @@ namespace SFML
/// <param name="style">Window style (Resize | Close by default)</param> /// <param name="style">Window style (Resize | Close by default)</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public RenderWindow(VideoMode mode, string title, Styles style) : public RenderWindow(VideoMode mode, string title, Styles style) :
this(mode, title, style, new ContextSettings(24, 8, 0)) this(mode, title, style, new ContextSettings(24, 8))
{ {
} }
@ -52,7 +52,7 @@ namespace SFML
/// <param name="settings">Creation parameters</param> /// <param name="settings">Creation parameters</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public RenderWindow(VideoMode mode, string title, Styles style, ContextSettings settings) : public RenderWindow(VideoMode mode, string title, Styles style, ContextSettings settings) :
base(sfRenderWindow_Create(mode, title, style, settings), 0) base(sfRenderWindow_Create(mode, title, style, ref settings), 0)
{ {
Initialize(); Initialize();
} }
@ -64,7 +64,7 @@ namespace SFML
/// <param name="handle">Platform-specific handle of the control</param> /// <param name="handle">Platform-specific handle of the control</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public RenderWindow(IntPtr handle) : public RenderWindow(IntPtr handle) :
this(handle, new ContextSettings(24, 8, 0)) this(handle, new ContextSettings(24, 8))
{ {
} }
@ -76,7 +76,7 @@ namespace SFML
/// <param name="settings">Creation parameters</param> /// <param name="settings">Creation parameters</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public RenderWindow(IntPtr handle, ContextSettings settings) : public RenderWindow(IntPtr handle, ContextSettings settings) :
base(sfRenderWindow_CreateFromHandle(handle, settings), 0) base(sfRenderWindow_CreateFromHandle(handle, ref settings), 0)
{ {
Initialize(); Initialize();
} }
@ -481,10 +481,10 @@ namespace SFML
#region Imports #region Imports
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfRenderWindow_Create(VideoMode Mode, string Title, Styles Style, ContextSettings Params); static extern IntPtr sfRenderWindow_Create(VideoMode Mode, string Title, Styles Style, ref ContextSettings Params);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfRenderWindow_CreateFromHandle(IntPtr Handle, ContextSettings Params); static extern IntPtr sfRenderWindow_CreateFromHandle(IntPtr Handle, ref ContextSettings Params);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_Destroy(IntPtr This); static extern void sfRenderWindow_Destroy(IntPtr This);

View File

@ -33,11 +33,28 @@ namespace SFML
/// <param name="stencilBits">Stencil buffer bits</param> /// <param name="stencilBits">Stencil buffer bits</param>
/// <param name="antialiasingLevel">Antialiasing level</param> /// <param name="antialiasingLevel">Antialiasing level</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public ContextSettings(uint depthBits, uint stencilBits, uint antialiasingLevel) public ContextSettings(uint depthBits, uint stencilBits, uint antialiasingLevel) :
this(depthBits, stencilBits, antialiasingLevel, 2, 0)
{
}
////////////////////////////////////////////////////////////
/// <summary>
/// Construct the settings from depth / stencil bits and antialiasing level
/// </summary>
/// <param name="depthBits">Depth buffer bits</param>
/// <param name="stencilBits">Stencil buffer bits</param>
/// <param name="antialiasingLevel">Antialiasing level</param>
/// <param name="majorVersion">Major number of the context version</param>
/// <param name="minorVersion">Minor number of the context version</param>
////////////////////////////////////////////////////////////
public ContextSettings(uint depthBits, uint stencilBits, uint antialiasingLevel, uint majorVersion, uint minorVersion)
{ {
DepthBits = depthBits; DepthBits = depthBits;
StencilBits = stencilBits; StencilBits = stencilBits;
AntialiasingLevel = antialiasingLevel; AntialiasingLevel = antialiasingLevel;
MajorVersion = majorVersion;
MinorVersion = minorVersion;
} }
/// <summary>Depth buffer bits (0 is disabled)</summary> /// <summary>Depth buffer bits (0 is disabled)</summary>
@ -48,6 +65,12 @@ namespace SFML
/// <summary>Antialiasing level (0 is disabled)</summary> /// <summary>Antialiasing level (0 is disabled)</summary>
public uint AntialiasingLevel; public uint AntialiasingLevel;
/// <summary>Major number of the context version</summary>
public uint MajorVersion;
/// <summary>Minor number of the context version</summary>
public uint MinorVersion;
} }
} }
} }

View File

@ -47,7 +47,7 @@ namespace SFML
/// <param name="title">Title of the window</param> /// <param name="title">Title of the window</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public Window(VideoMode mode, string title) : public Window(VideoMode mode, string title) :
this(mode, title, Styles.Resize | Styles.Close, new ContextSettings(24, 8, 0)) this(mode, title, Styles.Resize | Styles.Close, new ContextSettings(24, 8))
{ {
} }
@ -60,7 +60,7 @@ namespace SFML
/// <param name="style">Window style (Resize | Close by default)</param> /// <param name="style">Window style (Resize | Close by default)</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public Window(VideoMode mode, string title, Styles style) : public Window(VideoMode mode, string title, Styles style) :
this(mode, title, style, new ContextSettings(24, 8, 0)) this(mode, title, style, new ContextSettings(24, 8))
{ {
} }
@ -74,7 +74,7 @@ namespace SFML
/// <param name="settings">Creation parameters</param> /// <param name="settings">Creation parameters</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public Window(VideoMode mode, string title, Styles style, ContextSettings settings) : public Window(VideoMode mode, string title, Styles style, ContextSettings settings) :
base(sfWindow_Create(mode, title, style, settings)) base(sfWindow_Create(mode, title, style, ref settings))
{ {
myInput = new Input(sfWindow_GetInput(This)); myInput = new Input(sfWindow_GetInput(This));
} }
@ -86,7 +86,7 @@ namespace SFML
/// <param name="handle">Platform-specific handle of the control</param> /// <param name="handle">Platform-specific handle of the control</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public Window(IntPtr handle) : public Window(IntPtr handle) :
this(handle, new ContextSettings(24, 8, 0)) this(handle, new ContextSettings(24, 8))
{ {
} }
@ -98,7 +98,7 @@ namespace SFML
/// <param name="settings">Creation parameters</param> /// <param name="settings">Creation parameters</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public Window(IntPtr Handle, ContextSettings settings) : public Window(IntPtr Handle, ContextSettings settings) :
base(sfWindow_CreateFromHandle(Handle, settings)) base(sfWindow_CreateFromHandle(Handle, ref settings))
{ {
myInput = new Input(sfWindow_GetInput(This)); myInput = new Input(sfWindow_GetInput(This));
} }
@ -155,7 +155,7 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public virtual uint Width public virtual uint Width
{ {
get { return sfWindow_GetWidth(This); } get {return sfWindow_GetWidth(This);}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -165,7 +165,7 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public virtual uint Height public virtual uint Height
{ {
get { return sfWindow_GetHeight(This); } get {return sfWindow_GetHeight(This);}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -175,7 +175,7 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public virtual ContextSettings Settings public virtual ContextSettings Settings
{ {
get { return sfWindow_GetSettings(This); } get {return sfWindow_GetSettings(This);}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -555,10 +555,10 @@ namespace SFML
#region Imports #region Imports
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfWindow_Create(VideoMode Mode, string Title, Styles Style, ContextSettings Params); static extern IntPtr sfWindow_Create(VideoMode Mode, string Title, Styles Style, ref ContextSettings Params);
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfWindow_CreateFromHandle(IntPtr Handle, ContextSettings Params); static extern IntPtr sfWindow_CreateFromHandle(IntPtr Handle, ref ContextSettings Params);
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
static extern void sfWindow_Destroy(IntPtr This); static extern void sfWindow_Destroy(IntPtr This);

View File

@ -31,6 +31,7 @@ namespace sf
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Structure defining the settings of the OpenGL /// \brief Structure defining the settings of the OpenGL
/// context attached to a window /// context attached to a window
///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct ContextSettings struct ContextSettings
{ {
@ -40,12 +41,16 @@ struct ContextSettings
/// \param depth Depth buffer bits /// \param depth Depth buffer bits
/// \param stencil Stencil buffer bits /// \param stencil Stencil buffer bits
/// \param antialiasing Antialiasing level /// \param antialiasing Antialiasing level
/// \param major Major number of the context version
/// \param minor Minor number of the context version
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
explicit ContextSettings(unsigned int depth = 24, unsigned int stencil = 8, unsigned int antialiasing = 0) : explicit ContextSettings(unsigned int depth = 24, unsigned int stencil = 8, unsigned int antialiasing = 0, unsigned int major = 2, unsigned int minor = 0) :
DepthBits (depth), DepthBits (depth),
StencilBits (stencil), StencilBits (stencil),
AntialiasingLevel(antialiasing) AntialiasingLevel(antialiasing),
MajorVersion (major),
MinorVersion (minor)
{ {
} }
@ -55,9 +60,44 @@ struct ContextSettings
unsigned int DepthBits; ///< Bits of the depth buffer unsigned int DepthBits; ///< Bits of the depth buffer
unsigned int StencilBits; ///< Bits of the stencil buffer unsigned int StencilBits; ///< Bits of the stencil buffer
unsigned int AntialiasingLevel; ///< Level of antialiasing unsigned int AntialiasingLevel; ///< Level of antialiasing
unsigned int MajorVersion; ///< Major number of the context version to create
unsigned int MinorVersion; ///< Minor number of the context version to create
}; };
} // namespace sf } // namespace sf
#endif // SFML_CONTEXTSETTINGS_HPP #endif // SFML_CONTEXTSETTINGS_HPP
////////////////////////////////////////////////////////////
/// \class sf::ContextSettings
///
/// ContextSettings allows to define several advanced settings
/// of the OpenGL context attached to a window. All these
/// settings have no impact on the regular SFML rendering
/// (graphics module), so you may need to use this structure
/// only if you're using SFML as a windowing system for
/// custom OpenGL rendering.
///
/// The DepthBits and StencilBits members define the number
/// of bits per pixel requested for the (respectively) depth
/// and stencil buffers.
///
/// AntialiasingLevel represents the requested number of
/// multisampling levels for anti-aliasing.
///
/// MajorVersion and MinorVersion define the version of the
/// OpenGL context that you want. Only versions greater or
/// equal to 3.0 are relevant; versions lesser than 3.0 are
/// all handled the same way (i.e. you can use any version
/// < 3.0 if you don't want an OpenGL 3 context).
///
/// Please note that these values are only a hint.
/// No failure will be reported if one or more of these values
/// are not supported by the system; instead, SFML will try to
/// find the closest valid match. You can then retrieve the
/// settings that the window actually used to create its context,
/// with Window::GetSettings().
///
////////////////////////////////////////////////////////////

View File

@ -152,6 +152,8 @@ bool ContextGL::SetReferenceActive()
{ {
if (threadContext) if (threadContext)
return threadContext->SetActive(true); return threadContext->SetActive(true);
else
return false;
} }

View File

@ -246,30 +246,60 @@ void ContextGLX::CreateContext(ContextGLX* shared, unsigned int bitsPerPixel, co
// Get the context to share display lists with // Get the context to share display lists with
GLXContext toShare = shared ? shared->myContext : NULL; GLXContext toShare = shared ? shared->myContext : NULL;
// Create the context -- first try an OpenGL 3.0 context if it is supported // Create the OpenGL context -- first try an OpenGL 3.0 context if it is requested
/*const GLubyte* name = reinterpret_cast<const GLubyte*>("glXCreateContextAttribsARB"); if (settings.MajorVersion >= 3)
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = reinterpret_cast<PFNGLXCREATECONTEXTATTRIBSARBPROC>(glXGetProcAddress(name));
if (glXCreateContextAttribsARB)
{ {
int nbConfigs = 0; PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB"));
GLXFBConfig* configs = glXChooseFBConfig(myDisplay, DefaultScreen(myDisplay), NULL, &nbConfigs); if (wglCreateContextAttribsARB)
if (!configs || !nbConfigs)
{ {
std::cerr << "Failed to retrieve the framebuffer configuration" << std::endl; int attributes[] =
return; {
WGL_CONTEXT_MAJOR_VERSION_ARB, settings.MajorVersion,
WGL_CONTEXT_MINOR_VERSION_ARB, settings.MinorVersion,
0, 0
};
myContext = wglCreateContextAttribsARB(myDeviceContext, sharedContext, attributes);
} }
// Create the context // If we couldn't create an OpenGL 3 context, adjust the settings
int attributes[] = if (!myContext)
{ {
GLX_CONTEXT_MAJOR_VERSION_ARB, 3, mySettings.MajorVersion = 2;
GLX_CONTEXT_MINOR_VERSION_ARB, 0, mySettings.MinorVersion = 0;
0, 0 }
}; }
myContext = glXCreateContextAttribsARB(myDisplay, configs[0], toShare, true, attributes);
}*/
// If the OpenGL 3.0 context failed, create a regular OpenGL 1.x context // Create the OpenGL context -- first try an OpenGL 3.0 context if it is requested
if (settings.MajorVersion >= 3)
{
const GLubyte* name = reinterpret_cast<const GLubyte*>("glXCreateContextAttribsARB");
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = reinterpret_cast<PFNGLXCREATECONTEXTATTRIBSARBPROC>(glXGetProcAddress(name));
if (glXCreateContextAttribsARB)
{
int nbConfigs = 0;
GLXFBConfig* configs = glXChooseFBConfig(myDisplay, DefaultScreen(myDisplay), NULL, &nbConfigs);
if (configs && nbConfigs)
{
// Create the context
int attributes[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, settings.MajorVersion,
GLX_CONTEXT_MINOR_VERSION_ARB, settings.MinorVersion,
0, 0
};
myContext = glXCreateContextAttribsARB(myDisplay, configs[0], toShare, true, attributes);
}
}
// If we couldn't create an OpenGL 3 context, adjust the settings
if (!myContext)
{
mySettings.MajorVersion = 2;
mySettings.MinorVersion = 0;
}
}
// If the OpenGL 3.0 context failed or if we don't want one, create a regular OpenGL 1.x/2.x context
if (!myContext) if (!myContext)
{ {
myContext = glXCreateContext(myDisplay, bestVisual, toShare, true); myContext = glXCreateContext(myDisplay, bestVisual, toShare, true);

View File

@ -261,20 +261,30 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co
// Get the context to share display lists with // Get the context to share display lists with
HGLRC sharedContext = shared ? shared->myContext : NULL; HGLRC sharedContext = shared ? shared->myContext : NULL;
// Create the OpenGL context -- first try an OpenGL 3.0 context if it is supported // Create the OpenGL context -- first try an OpenGL 3.0 context if it is requested
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB")); if (settings.MajorVersion >= 3)
if (wglCreateContextAttribsARB)
{ {
int attributes[] = PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB"));
if (wglCreateContextAttribsARB)
{ {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3, int attributes[] =
WGL_CONTEXT_MINOR_VERSION_ARB, 0, {
0, 0 WGL_CONTEXT_MAJOR_VERSION_ARB, settings.MajorVersion,
}; WGL_CONTEXT_MINOR_VERSION_ARB, settings.MinorVersion,
myContext = wglCreateContextAttribsARB(myDeviceContext, sharedContext, attributes); 0, 0
};
myContext = wglCreateContextAttribsARB(myDeviceContext, sharedContext, attributes);
}
// If we couldn't create an OpenGL 3 context, adjust the settings
if (!myContext)
{
mySettings.MajorVersion = 2;
mySettings.MinorVersion = 0;
}
} }
// If the OpenGL 3.0 context failed, create a regular OpenGL 1.x context // If the OpenGL 3.0 context failed or if we don't want one, create a regular OpenGL 1.x/2.x context
if (!myContext) if (!myContext)
{ {
myContext = wglCreateContext(myDeviceContext); myContext = wglCreateContext(myDeviceContext);