Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Hardware cursor support #106

Merged
merged 5 commits into from

1 participant

@thefiddler
Owner

This PR introduces partial support for hardware cursors:

using (var gw = new GameWindow())
{
    gw.Cursor = MouseCursor.Default;
}

Due to issues with byte order on different platforms, for now only two predefined cursors are supported:

MouseCursor.Default
MouseCursor.Empty

A future PR will introduce support for defining custom cursors.

Affects issue #9

thefiddler added some commits
@thefiddler thefiddler [OpenTK] Only init X11 if SDL2 is not used c40115e
@thefiddler thefiddler [GL] Added GetPName.Max*ImageUniforms
These tokens were introduced in OpenGL 4.2 and 4.3.
168713a
@thefiddler thefiddler [X11] Fixed SGI_swap_control query
GLX can return valid function pointer to unsupported functions.
We need to check for extension support in addition to the
function pointer.

Fixes crash on OpenSUSE 13.1 in VirtualBox.
0f920fb
@thefiddler thefiddler Merge branch 'cursor' of https://github.com/thefiddler/opentk into th…
…efiddler-cursor
4f9a2f7
@thefiddler thefiddler [Win] Fixed MouseCursor.Default
It is now possible to switch from a custom cursor back to
MouseCursor.Default.
509f356
@thefiddler thefiddler merged commit 509f356 into opentk:develop

1 check was pending

Details continuous-integration/travis-ci The Travis CI build is in progress
@thefiddler
Owner

Tested and merged. Many thanks @Frassle!

@thefiddler thefiddler deleted the thefiddler:cursor branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 27, 2014
  1. @thefiddler
  2. @thefiddler

    [GL] Added GetPName.Max*ImageUniforms

    thefiddler authored
    These tokens were introduced in OpenGL 4.2 and 4.3.
  3. @thefiddler

    [X11] Fixed SGI_swap_control query

    thefiddler authored
    GLX can return valid function pointer to unsupported functions.
    We need to check for extension support in addition to the
    function pointer.
    
    Fixes crash on OpenSUSE 13.1 in VirtualBox.
Commits on Apr 28, 2014
  1. @thefiddler
  2. @thefiddler

    [Win] Fixed MouseCursor.Default

    thefiddler authored
    It is now possible to switch from a custom cursor back to
    MouseCursor.Default.
This page is out of date. Refresh to see the latest.
View
7 Source/Bind/Specifications/GL2/overrides.xml
@@ -3561,6 +3561,13 @@
<use enum="VERSION_4_1" token="VIEWPORT_BOUNDS_RANGE" />
<use enum="VERSION_4_1" token="LAYER_PROVOKING_VERTEX" />
<use enum="VERSION_4_1" token="VIEWPORT_INDEX_PROVOKING_VERTEX" />
+ <use enum="VERSION_4_2" token="MAX_VERTEX_IMAGE_UNIFORMS" />
+ <use enum="VERSION_4_2" token="MAX_TESS_CONTROL_IMAGE_UNIFORMS" />
+ <use enum="VERSION_4_2" token="MAX_TESS_EVALUATION_IMAGE_UNIFORMS" />
+ <use enum="VERSION_4_2" token="MAX_GEOMETRY_IMAGE_UNIFORMS" />
+ <use enum="VERSION_4_2" token="MAX_FRAGMENT_IMAGE_UNIFORMS" />
+ <use enum="VERSION_4_2" token="MAX_COMBINED_IMAGE_UNIFORMS" />
+ <use enum="VERSION_4_3" token="MAX_COMPUTE_IMAGE_UNIFORMS" />
</enum>
<enum name="GetPointervPName">
<token name="FOG_COORD_ARRAY_POINTER" value="0x8456" />
View
2  Source/OpenTK/Configuration.cs
@@ -306,7 +306,7 @@ internal static void Init(ToolkitOptions options)
RunningOnSdl2 = DetectSdl2();
}
- if (runningOnLinux || options.Backend == PlatformBackend.PreferX11)
+ if ((runningOnLinux && !RunningOnSdl2) || options.Backend == PlatformBackend.PreferX11)
{
runningOnX11 = DetectX11();
}
View
28 Source/OpenTK/Graphics/OpenGL/GLEnums.cs
@@ -38329,6 +38329,30 @@ public enum GetPName : int
/// </summary>
DrawIndirectBufferBinding = ((int)0x8F43) ,
/// <summary>
+ /// Original was GL_MAX_VERTEX_IMAGE_UNIFORMS = 0x90CA
+ /// </summary>
+ MaxVertexImageUniforms = ((int)0x90CA) ,
+ /// <summary>
+ /// Original was GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS = 0x90CB
+ /// </summary>
+ MaxTessControlImageUniforms = ((int)0x90CB) ,
+ /// <summary>
+ /// Original was GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS = 0x90CC
+ /// </summary>
+ MaxTessEvaluationImageUniforms = ((int)0x90CC) ,
+ /// <summary>
+ /// Original was GL_MAX_GEOMETRY_IMAGE_UNIFORMS = 0x90CD
+ /// </summary>
+ MaxGeometryImageUniforms = ((int)0x90CD) ,
+ /// <summary>
+ /// Original was GL_MAX_FRAGMENT_IMAGE_UNIFORMS = 0x90CE
+ /// </summary>
+ MaxFragmentImageUniforms = ((int)0x90CE) ,
+ /// <summary>
+ /// Original was GL_MAX_COMBINED_IMAGE_UNIFORMS = 0x90CF
+ /// </summary>
+ MaxCombinedImageUniforms = ((int)0x90CF) ,
+ /// <summary>
/// Original was GL_TEXTURE_BINDING_2D_MULTISAMPLE = 0x9104
/// </summary>
TextureBinding2DMultisample = ((int)0x9104) ,
@@ -38364,6 +38388,10 @@ public enum GetPName : int
/// Original was GL_MAX_FRAGMENT_INPUT_COMPONENTS = 0x9125
/// </summary>
MaxFragmentInputComponents = ((int)0x9125) ,
+ /// <summary>
+ /// Original was GL_MAX_COMPUTE_IMAGE_UNIFORMS = 0x91BD
+ /// </summary>
+ MaxComputeImageUniforms = ((int)0x91BD) ,
}
/// <summary>
View
28 Source/OpenTK/Graphics/OpenGL4/GL4Enums.cs
@@ -19864,6 +19864,30 @@ public enum GetPName : int
/// </summary>
DrawIndirectBufferBinding = ((int)0x8F43) ,
/// <summary>
+ /// Original was GL_MAX_VERTEX_IMAGE_UNIFORMS = 0x90CA
+ /// </summary>
+ MaxVertexImageUniforms = ((int)0x90CA) ,
+ /// <summary>
+ /// Original was GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS = 0x90CB
+ /// </summary>
+ MaxTessControlImageUniforms = ((int)0x90CB) ,
+ /// <summary>
+ /// Original was GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS = 0x90CC
+ /// </summary>
+ MaxTessEvaluationImageUniforms = ((int)0x90CC) ,
+ /// <summary>
+ /// Original was GL_MAX_GEOMETRY_IMAGE_UNIFORMS = 0x90CD
+ /// </summary>
+ MaxGeometryImageUniforms = ((int)0x90CD) ,
+ /// <summary>
+ /// Original was GL_MAX_FRAGMENT_IMAGE_UNIFORMS = 0x90CE
+ /// </summary>
+ MaxFragmentImageUniforms = ((int)0x90CE) ,
+ /// <summary>
+ /// Original was GL_MAX_COMBINED_IMAGE_UNIFORMS = 0x90CF
+ /// </summary>
+ MaxCombinedImageUniforms = ((int)0x90CF) ,
+ /// <summary>
/// Original was GL_TEXTURE_BINDING_2D_MULTISAMPLE = 0x9104
/// </summary>
TextureBinding2DMultisample = ((int)0x9104) ,
@@ -19899,6 +19923,10 @@ public enum GetPName : int
/// Original was GL_MAX_FRAGMENT_INPUT_COMPONENTS = 0x9125
/// </summary>
MaxFragmentInputComponents = ((int)0x9125) ,
+ /// <summary>
+ /// Original was GL_MAX_COMPUTE_IMAGE_UNIFORMS = 0x91BD
+ /// </summary>
+ MaxComputeImageUniforms = ((int)0x91BD) ,
}
/// <summary>
View
73 Source/OpenTK/Platform/Windows/WinGLNative.cs
@@ -1203,48 +1203,59 @@ public MouseCursor Cursor
{
if (value != cursor)
{
- var stride = value.Width *
- (Bitmap.GetPixelFormatSize(System.Drawing.Imaging.PixelFormat.Format32bppArgb) / 8);
+ bool destoryOld = cursor != MouseCursor.Default;
+ IntPtr oldCursor = IntPtr.Zero;
- Bitmap bmp;
- unsafe
+ if (value == MouseCursor.Default)
{
- fixed (byte* pixels = value.Rgba)
- {
- bmp = new Bitmap(value.Width, value.Height, stride,
- System.Drawing.Imaging.PixelFormat.Format32bppArgb,
- new IntPtr(pixels));
- }
+ oldCursor = Functions.SetCursor(Functions.LoadCursor(CursorName.Arrow));
+ cursor = value;
}
-
- var iconInfo = new IconInfo();
- var bmpIcon = bmp.GetHicon();
- var success = Functions.GetIconInfo(bmpIcon, out iconInfo);
-
- if (success)
+ else
{
- iconInfo.xHotspot = value.X;
- iconInfo.yHotspot = value.Y;
- iconInfo.fIcon = false;
-
- var icon = Functions.CreateIconIndirect(ref iconInfo);
+ var stride = value.Width *
+ (Bitmap.GetPixelFormatSize(System.Drawing.Imaging.PixelFormat.Format32bppArgb) / 8);
- if (icon != IntPtr.Zero)
+ Bitmap bmp;
+ unsafe
{
- // Currently using a custom cursor so destroy it
- // once replaced
- bool destoryOld = cursor != MouseCursor.Default;
-
- cursor = value;
- curson_handle = icon;
- var oldCursor = Functions.SetCursor(icon);
+ fixed (byte* pixels = value.Rgba)
+ {
+ bmp = new Bitmap(value.Width, value.Height, stride,
+ System.Drawing.Imaging.PixelFormat.Format32bppArgb,
+ new IntPtr(pixels));
+ }
+ }
+ using (bmp)
+ {
+ var iconInfo = new IconInfo();
+ var bmpIcon = bmp.GetHicon();
+ var success = Functions.GetIconInfo(bmpIcon, out iconInfo);
- if (destoryOld)
+ if (success)
{
- Functions.DestroyIcon(oldCursor);
+ iconInfo.xHotspot = value.X;
+ iconInfo.yHotspot = value.Y;
+ iconInfo.fIcon = false;
+
+ var icon = Functions.CreateIconIndirect(ref iconInfo);
+
+ if (icon != IntPtr.Zero)
+ {
+ // Currently using a custom cursor so destroy it
+ // once replaced
+ cursor = value;
+ curson_handle = icon;
+ oldCursor = Functions.SetCursor(icon);
+ }
}
}
}
+
+ if (destoryOld && oldCursor != IntPtr.Zero)
+ {
+ Functions.DestroyIcon(oldCursor);
+ }
}
}
}
View
4 Source/OpenTK/Platform/X11/X11GLContext.cs
@@ -380,7 +380,9 @@ public override int SwapInterval
public override void LoadAll()
{
- vsync_supported = Glx.SupportsFunction("glXSwapIntervalSGI");
+ vsync_supported =
+ SupportsExtension(display, currentWindow, "SupportsExtension") &&
+ Glx.SupportsFunction("glXSwapIntervalSGI");
Debug.Print("Context supports vsync: {0}.", vsync_supported);
base.LoadAll();
Something went wrong with that request. Please try again.