Cleaned up context profile selection

Added support for WGL_create_context profiles and added methods for the
selection of context flags and profile.
This commit is contained in:
Stefanos A. 2013-11-14 08:30:11 +01:00
parent 803c575201
commit 94e2649704
2 changed files with 23 additions and 4 deletions

View file

@ -5,13 +5,16 @@ namespace OpenTK.Platform.Windows
public enum ArbCreateContext
{
CoreProfileBit = 0x0001,
CompatibilityProfileBit = 0x0002,
DebugBit = 0x0001,
ForwardCompatibleBit = 0x0002,
MajorVersion = 0x2091,
MinorVersion = 0x2092,
LayerPlane = 0x2093,
Flags = 0x2094,
ContextFlags = 0x2094,
ErrorInvalidVersion = 0x2095,
ProfileMask = 0x9126
}
public enum WGL_ARB_buffer_region

View file

@ -122,9 +122,10 @@ namespace OpenTK.Platform.Windows
attributes.Add(minor);
if (flags != 0)
{
attributes.Add((int)ArbCreateContext.Flags);
#warning "This is not entirely correct: Embedded is not a valid flag! We need to add a GetARBContextFlags(GraphicsContextFlags) method."
attributes.Add((int)flags);
attributes.Add((int)ArbCreateContext.ContextFlags);
attributes.Add((int)GetARBContextFlags(flags));
attributes.Add((int)ArbCreateContext.ProfileMask);
attributes.Add((int)GetARBContextProfile(flags));
}
// According to the docs, " <attribList> specifies a list of attributes for the context.
// The list consists of a sequence of <name,value> pairs terminated by the
@ -181,6 +182,21 @@ namespace OpenTK.Platform.Windows
}
}
static ArbCreateContext GetARBContextFlags(GraphicsContextFlags flags)
{
ArbCreateContext result = 0;
result |= (flags & GraphicsContextFlags.ForwardCompatible) != 0 ?
ArbCreateContext.CoreProfileBit : ArbCreateContext.CompatibilityProfileBit;
return result;
}
static ArbCreateContext GetARBContextProfile(GraphicsContextFlags flags)
{
ArbCreateContext result = 0;
result |= (flags & GraphicsContextFlags.Debug) != 0 ? ArbCreateContext.DebugBit : 0;
return result;
}
public WinGLContext(ContextHandle handle, WinWindowInfo window, IGraphicsContext sharedContext,
int major, int minor, GraphicsContextFlags flags)
{