Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for context creation flags and texture/shader native handles #116

Merged
merged 1 commit into from May 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Graphics/Shader.cs
Expand Up @@ -85,6 +85,21 @@ public class CurrentTextureType {}
throw new LoadingFailedException("shader");
}

////////////////////////////////////////////////////////////
/// <summary>
/// Get the underlying OpenGL handle of the shader.
/// </summary>
/// <remarks>
/// You shouldn't need to use this handle, unless you have
/// very specific stuff to implement that SFML doesn't support,
/// or implement a temporary workaround until a bug is fixed.
/// </remarks>
////////////////////////////////////////////////////////////
public uint NativeHandle
{
get { return sfShader_getNativeHandle(CPointer); }
}

////////////////////////////////////////////////////////////
/// <summary>
/// Load both the vertex and fragment shaders from source codes in memory
Expand Down Expand Up @@ -379,6 +394,9 @@ protected override void Destroy(bool disposing)
[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern void sfShader_setCurrentTextureParameter(IntPtr shader, string name);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern uint sfShader_getNativeHandle(IntPtr shader);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern void sfShader_bind(IntPtr shader);

Expand Down
18 changes: 18 additions & 0 deletions src/Graphics/Texture.cs
Expand Up @@ -153,6 +153,21 @@ public class Texture : ObjectBase
{
}

////////////////////////////////////////////////////////////
/// <summary>
/// Get the underlying OpenGL handle of the texture.
/// </summary>
/// <remarks>
/// You shouldn't need to use this handle, unless you have
/// very specific stuff to implement that SFML doesn't support,
/// or implement a temporary workaround until a bug is fixed.
/// </remarks>
////////////////////////////////////////////////////////////
public uint NativeHandle
{
get { return sfTexture_getNativeHandle(CPointer); }
}

////////////////////////////////////////////////////////////
/// <summary>
/// Copy a texture's pixels to an image
Expand Down Expand Up @@ -425,6 +440,9 @@ protected override void Destroy(bool disposing)
[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern bool sfTexture_isRepeated(IntPtr texture);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern uint sfTexture_getNativeHandle(IntPtr shader);

[DllImport("csfml-graphics-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
static extern FloatRect sfTexture_getTexCoords(IntPtr texture, IntRect rectangle);

Expand Down
30 changes: 27 additions & 3 deletions src/Window/ContextSettings.cs
Expand Up @@ -13,6 +13,24 @@ namespace Window
[StructLayout(LayoutKind.Sequential)]
public struct ContextSettings
{
////////////////////////////////////////////////////////////
/// <summary>
/// Enumeration of the context attribute flags
/// </summary>
////////////////////////////////////////////////////////////
[Flags]
public enum Attribute
{
/// <summary>Non-debug, compatibility context (this and the core attribute are mutually exclusive)</summary>
Default = 0,

/// <summary>Core attribute</summary>
Core = 1 << 0,

/// <summary>Debug attribute</summary>
Debug = 1 << 2
}

////////////////////////////////////////////////////////////
/// <summary>
/// Construct the settings from depth / stencil bits
Expand All @@ -34,7 +52,7 @@ public struct ContextSettings
/// <param name="antialiasingLevel">Antialiasing level</param>
////////////////////////////////////////////////////////////
public ContextSettings(uint depthBits, uint stencilBits, uint antialiasingLevel) :
this(depthBits, stencilBits, antialiasingLevel, 2, 0)
this(depthBits, stencilBits, antialiasingLevel, 2, 0, Attribute.Default)
{
}

Expand All @@ -47,14 +65,16 @@ public struct ContextSettings
/// <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>
/// <param name="attributes">Attribute flags of the context</param>
////////////////////////////////////////////////////////////
public ContextSettings(uint depthBits, uint stencilBits, uint antialiasingLevel, uint majorVersion, uint minorVersion)
public ContextSettings(uint depthBits, uint stencilBits, uint antialiasingLevel, uint majorVersion, uint minorVersion, Attribute attributes)
{
DepthBits = depthBits;
StencilBits = stencilBits;
AntialiasingLevel = antialiasingLevel;
MajorVersion = majorVersion;
MinorVersion = minorVersion;
AttributeFlags = attributes;
}

////////////////////////////////////////////////////////////
Expand All @@ -70,7 +90,8 @@ public override string ToString()
" StencilBits(" + StencilBits + ")" +
" AntialiasingLevel(" + AntialiasingLevel + ")" +
" MajorVersion(" + MajorVersion + ")" +
" MinorVersion(" + MinorVersion + ")";
" MinorVersion(" + MinorVersion + ")" +
" AttributeFlags" + AttributeFlags + ")";
}

/// <summary>Depth buffer bits (0 is disabled)</summary>
Expand All @@ -87,6 +108,9 @@ public override string ToString()

/// <summary>Minor number of the context version</summary>
public uint MinorVersion;

/// <summary>The attribute flags to create the context with</summary>
public Attribute AttributeFlags;
}
}
}