Created
May 7, 2022 11:33
-
-
Save En3Tho/f469dfc9e18a87c3ef1707ccc7e00ca0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Gists.FSharp.SilkNetSdl | |
open System.Runtime.CompilerServices | |
open Gists.CSharp | |
open Microsoft.FSharp.NativeInterop | |
open Silk.NET.SDL | |
open Silk.NET.Maths | |
let fillRect (api: Sdl) (screen: nativeptr<Surface>) color = | |
let nullref = &Unsafe.NullRef<Rectangle<int>>() | |
api.FillRect(screen, &nullref, color) // picks byref overload | |
//public static unsafe class NativePtr | |
//{ | |
// public static T* toValuePtr<T>(void* ptr) | |
// where T: unmanaged | |
// => (T*) ptr; | |
//} | |
let fillRect2 (api: Sdl) (screen: nativeptr<Surface>) color = | |
let nullref = &Unsafe.NullRef<Rectangle<int>>() | |
let ptr2 = NativePtr.toValuePtr<Rectangle<int>> (Unsafe.AsPointer &nullref) | |
api.FillRect(screen, ptr2, color) | |
//public static T* zero<T>() | |
// where T: unmanaged | |
// => (T*) IntPtr.Zero; | |
let fillRect3 (api: Sdl) (screen: nativeptr<Surface>) color = | |
let ptr = NativePtr.zero<Rectangle<int>>() | |
api.FillRect(screen, ptr, color) | |
// define C# to F# helpers if needed | |
module NativePtr = | |
let zeroFSharp<'a when 'a: (new: unit -> 'a) and 'a : struct and 'a :> System.ValueType> = NativePtr.zero<'a>() | |
let fillRect4 (api: Sdl) (screen: nativeptr<Surface>) color = | |
let ptr = NativePtr.zeroFSharp<Rectangle<int>> | |
api.FillRect(screen, ptr, color) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment