case "gl3":
case "gl4":
- mode = GeneratorMode.GL4;
+ mode = GeneratorMode.GL4;
break;
case "es10":
var entry_points = type.Fields.FirstOrDefault(f => f.Name == "EntryPoints");
if (entry_points != null)
{
- // Build list of entry point signatures (one per entry point)
+ // Build list of entry point signatures (one per entry point)
var entry_signatures = new List<MethodDefinition>();
entry_signatures.AddRange(type.Methods
.Where(t => t.CustomAttributes.Any(a => a.AttributeType.Name == "SlotAttribute")));
DebugVariables vars = null;
if (il.Body.Method.Name != "GetError")
{
- // Pull out the namespace name, method fullname will look
+ // Pull out the namespace name, method fullname will look
// something like "type namespace.class::method(type arg)"
var module = il.Body.Method.FullName;
module = module.Substring(module.IndexOf(' ') + 1);
}
}
- static void EmitParameterEpilogues(MethodDefinition wrapper, MethodDefinition native, MethodBody body, ILProcessor il,
+ static void EmitParameterEpilogues(MethodDefinition wrapper, MethodDefinition native, MethodBody body, ILProcessor il,
List<GeneratedVariableIdentifier> generatedVariables)
{
- foreach (var p in wrapper.Parameters)
+ foreach (var p in wrapper.Parameters)
{
if (p.ParameterType.Name == "StringBuilder")
{
}
/// <summary>
- /// Retrieves a generated variable by searching the given list by the variable's name and associated method body.
+ /// Retrieves a generated variable by searching the given list by the variable's name and associated method body.
/// </summary>
/// <param name="variableIdentifiers"></param>
/// <param name="name"></param>
return stringBuilderPtrVar;
}
- static void EmitStringBuilderEpilogue(MethodDefinition wrapper, MethodDefinition native,
+ static void EmitStringBuilderEpilogue(MethodDefinition wrapper, MethodDefinition native,
ParameterDefinition parameter, MethodBody body, ILProcessor il, GeneratedVariableIdentifier generatedPtrVar)
{
if (generatedPtrVar == null)
{
throw new ArgumentNullException(nameof(generatedPtrVar));
}
-
+
var p = parameter.ParameterType;
if (p.Name == "StringBuilder")
{
}
}
- static GeneratedVariableIdentifier EmitStringParameter(MethodDefinition wrapper, ParameterDefinition parameter, MethodBody body,
+ static GeneratedVariableIdentifier EmitStringParameter(MethodDefinition wrapper, ParameterDefinition parameter, MethodBody body,
ILProcessor il)
{
var p = parameter.ParameterType;
var variableDefinition = new VariableDefinition(TypeIntPtr);
body.Variables.Add(variableDefinition);
int generatedPointerVarIndex = body.Variables.Count - 1;
-
+
GeneratedVariableIdentifier stringPtrVar = new GeneratedVariableIdentifier(body, variableDefinition, parameter.Name + "_string_ptr");
// ptr = Marshal.StringToHGlobalAnsi(str);
return stringPtrVar;
}
- static void EmitStringEpilogue(MethodDefinition wrapper, ParameterDefinition parameter, MethodBody body,
+ static void EmitStringEpilogue(MethodDefinition wrapper, ParameterDefinition parameter, MethodBody body,
ILProcessor il, GeneratedVariableIdentifier generatedPtrVar)
{
var p = parameter.ParameterType;
var variableDefinition = new VariableDefinition(TypeIntPtr);
body.Variables.Add(variableDefinition);
int generatedPointerVarIndex = body.Variables.Count - 1;
-
+
GeneratedVariableIdentifier stringArrayPtrVar = new GeneratedVariableIdentifier(body, variableDefinition, parameter.Name + "_string_array_ptr");
// ptr = MarshalStringArrayToPtr(strings);
return stringArrayPtrVar;
}
- static void EmitStringArrayEpilogue(MethodDefinition wrapper, ParameterDefinition parameter, MethodBody body,
+ static void EmitStringArrayEpilogue(MethodDefinition wrapper, ParameterDefinition parameter, MethodBody body,
ILProcessor il, GeneratedVariableIdentifier generatedPtrVar)
{
if (generatedPtrVar == null)
{
throw new ArgumentNullException(nameof(generatedPtrVar));
}
-
+
// Note: only works for string vectors (1d arrays).
// We do not (and will probably never) support 2d or higher string arrays
var p = parameter.ParameterType;
// return result;
// }
body.Variables.Add(new VariableDefinition(wrapper.ReturnType));
-
+
generatedVariables = EmitParameters(wrapper, native, body, il);
il.Emit(OpCodes.Ldloca, body.Variables.Count - 1);
}
public static unsafe IntPtr CreateContext(ContextProperties[] properties, uint num_devices, IntPtr[] devices, IntPtr pfn_notify, IntPtr user_data, OpenTK.Compute.CL10.ErrorCode[] errcode_ret)
{
IntPtr[] properties_correct = properties != null ? new IntPtr[properties.Length] : null;
- for (int i = 0; i < properties_correct.Length; i++)
- properties_correct[i] = new IntPtr((int)properties[i]);
+ for (int i = 0; i < properties_correct.Length; i++)
+ properties_correct[i] = new IntPtr((int)properties[i]);
return CreateContext(properties_correct, num_devices, devices, pfn_notify, user_data, errcode_ret);
}
return CreateContext(ref properties_correct, num_devices, ref devices, pfn_notify, user_data, out errcode_ret);
}
- public static unsafe IntPtr CreateContext<T4>(ContextProperties* properties, uint num_devices, IntPtr* devices, IntPtr pfn_notify, ref T4 user_data, OpenTK.Compute.CL10.ErrorCode* errcode_ret)
- where T4 : struct
+ public static unsafe IntPtr CreateContext<T4>(ContextProperties* properties, uint num_devices, IntPtr* devices, IntPtr pfn_notify, ref T4 user_data, OpenTK.Compute.CL10.ErrorCode* errcode_ret)
+ where T4 : struct
{
return CreateContext((IntPtr*)properties, num_devices, devices, pfn_notify, ref user_data, errcode_ret);
}
public static unsafe IntPtr CreateContext<T4>(ContextProperties[] properties, uint num_devices, IntPtr[] devices, IntPtr pfn_notify, ref T4 user_data, OpenTK.Compute.CL10.ErrorCode[] errcode_ret)
- where T4 : struct
+ where T4 : struct
{
IntPtr[] properties_correct = properties != null ? new IntPtr[properties.Length] : null;
- for (int i = 0; i < properties_correct.Length; i++)
- properties_correct[i] = new IntPtr((int)properties[i]);
+ for (int i = 0; i < properties_correct.Length; i++)
+ properties_correct[i] = new IntPtr((int)properties[i]);
return CreateContext(properties_correct, num_devices, devices, pfn_notify, ref user_data, errcode_ret);
}
public static unsafe IntPtr CreateContext<T4>(ref ContextProperties properties, uint num_devices, ref IntPtr devices, IntPtr pfn_notify, ref T4 user_data, out OpenTK.Compute.CL10.ErrorCode errcode_ret)
- where T4 : struct
+ where T4 : struct
{
IntPtr properties_correct = new IntPtr((int)properties);
return CreateContext(ref properties_correct, num_devices, ref devices, pfn_notify, ref user_data, out errcode_ret);
public static unsafe IntPtr CreateContextFromType(ContextProperties[] properties, DeviceTypeFlags device_type, IntPtr pfn_notify, IntPtr user_data, OpenTK.Compute.CL10.ErrorCode[] errcode_ret)
{
- IntPtr[] properties_correct = properties != null ? new IntPtr[properties.Length] : null;
- for (int i = 0; i < properties_correct.Length; i++)
- properties_correct[i] = new IntPtr((int)properties[i]);
+ IntPtr[] properties_correct = properties != null ? new IntPtr[properties.Length] : null;
+ for (int i = 0; i < properties_correct.Length; i++)
+ properties_correct[i] = new IntPtr((int)properties[i]);
return CreateContextFromType(properties_correct, device_type, pfn_notify, user_data, errcode_ret);
}
public static unsafe IntPtr CreateContextFromType(ref ContextProperties properties, DeviceTypeFlags device_type, IntPtr pfn_notify, IntPtr user_data, out OpenTK.Compute.CL10.ErrorCode errcode_ret)
{
- IntPtr properties_correct = new IntPtr((int)properties);
+ IntPtr properties_correct = new IntPtr((int)properties);
return CreateContextFromType(ref properties_correct, device_type, pfn_notify, user_data, out errcode_ret);
}
- public static unsafe IntPtr CreateContextFromType<T4>(ContextProperties* properties, DeviceTypeFlags device_type, IntPtr pfn_notify, ref T4 user_data, OpenTK.Compute.CL10.ErrorCode* errcode_ret)
- where T4 : struct
+ public static unsafe IntPtr CreateContextFromType<T4>(ContextProperties* properties, DeviceTypeFlags device_type, IntPtr pfn_notify, ref T4 user_data, OpenTK.Compute.CL10.ErrorCode* errcode_ret)
+ where T4 : struct
{
return CreateContextFromType((IntPtr*)properties, device_type, pfn_notify, ref user_data, errcode_ret);
}
public static unsafe IntPtr CreateContextFromType<T4>(ContextProperties[] properties, DeviceTypeFlags device_type, IntPtr pfn_notify, ref T4 user_data, OpenTK.Compute.CL10.ErrorCode[] errcode_ret)
- where T4 : struct
+ where T4 : struct
{
- IntPtr[] properties_correct = properties != null ? new IntPtr[properties.Length] : null;
- for (int i = 0; i < properties_correct.Length; i++)
- properties_correct[i] = new IntPtr((int)properties[i]);
+ IntPtr[] properties_correct = properties != null ? new IntPtr[properties.Length] : null;
+ for (int i = 0; i < properties_correct.Length; i++)
+ properties_correct[i] = new IntPtr((int)properties[i]);
return CreateContextFromType(properties_correct, device_type, pfn_notify, ref user_data, errcode_ret);
}
public static unsafe IntPtr CreateContextFromType<T4>(ref ContextProperties properties, DeviceTypeFlags device_type, IntPtr pfn_notify, ref T4 user_data, out OpenTK.Compute.CL10.ErrorCode errcode_ret)
- where T4 : struct
+ where T4 : struct
{
- IntPtr properties_correct = new IntPtr((int)properties);
+ IntPtr properties_correct = new IntPtr((int)properties);
return CreateContextFromType(ref properties_correct, device_type, pfn_notify, ref user_data, out errcode_ret);
}
}
public static string GetActiveAttrib(int program, int index, out int size, out ActiveAttribType type)
{
int length;
- GetProgram(program, GetProgramParameterName.ActiveAttributeMaxLength, out length);
+ GetProgram(program, GetProgramParameterName.ActiveAttributeMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);
GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb);
public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type)
{
int length;
- GetProgram(program, GetProgramParameterName.ActiveUniformMaxLength, out length);
+ GetProgram(program, GetProgramParameterName.ActiveUniformMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length);
GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb);
unsafe
{
int length;
- GL.GetProgram(program, GetProgramParameterName.InfoLogLength, out length); if (length == 0)
+ GL.GetProgram(program, GetProgramParameterName.InfoLogLength, out length); if (length == 0)
{
info = String.Empty;
return;
public static string GetActiveAttrib(int program, int index, out int size, out ActiveAttribType type)
{
int length;
- GetProgram(program, ES30.GetProgramParameterName.ActiveAttributeMaxLength, out length);
+ GetProgram(program, ES30.GetProgramParameterName.ActiveAttributeMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);
- GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb);
+ GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb);
return sb.ToString();
}
public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type)
{
int length;
- GetProgram(program, ES30.GetProgramParameterName.ActiveUniformMaxLength, out length);
+ GetProgram(program, ES30.GetProgramParameterName.ActiveUniformMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length);
GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb);
unsafe
{
int length;
- GL.GetProgram(program, ES30.GetProgramParameterName.InfoLogLength, out length); if (length == 0)
+ GL.GetProgram(program, ES30.GetProgramParameterName.InfoLogLength, out length); if (length == 0)
{
info = String.Empty;
return;
public static void Color3(Color color)
{
- GL.Color3(color.R, color.G, color.B);
+ GL.Color3(color.R, color.G, color.B);
}
public static void Color4(Color color)
public static string GetActiveAttrib(int program, int index, out int size, out ActiveAttribType type)
{
int length;
- GetProgram(program, OpenGL4.GetProgramParameterName.ActiveAttributeMaxLength, out length);
+ GetProgram(program, OpenGL4.GetProgramParameterName.ActiveAttributeMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);
GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb);
public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type)
{
int length;
- GetProgram(program, OpenGL4.GetProgramParameterName.ActiveUniformMaxLength, out length);
+ GetProgram(program, OpenGL4.GetProgramParameterName.ActiveUniformMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length);
GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb);
unsafe
{
int length;
- GL.GetProgram(program, OpenGL4.GetProgramParameterName.InfoLogLength, out length); if (length == 0)
+ GL.GetProgram(program, OpenGL4.GetProgramParameterName.InfoLogLength, out length); if (length == 0)
{
info = String.Empty;
return;
return Math.Max(Math.Min(n, max), min);
}
- private static unsafe int FloatToInt32Bits(float f) {
- return *((int*) &f);
- }
-
- /// <summary>
- /// Approximates floating point equality with a maximum number of different bits.
- /// This is typically used in place of an epsilon comparison.
- /// see: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
- /// see: https://stackoverflow.com/questions/3874627/floating-point-comparison-functions-for-c-sharp
- /// </summary>
- /// <param name="a">the first value to compare</param>
- /// <param name="b">>the second value to compare</param>
- /// <param name="maxDeltaBits">the number of floating point bits to check</param>
- /// <returns></returns>
- public static bool ApproximatelyEqual(float a, float b, int maxDeltaBits) {
- // we use longs here, otherwise we run into a two's complement problem, causing this to fail with -2 and 2.0
- long aInt = FloatToInt32Bits(a);
- if (aInt < 0)
- aInt = Int32.MinValue - aInt;
-
- long bInt = FloatToInt32Bits(b);
- if (bInt < 0)
- bInt = Int32.MinValue - bInt;
-
- long intDiff = Math.Abs(aInt - bInt);
- return intDiff <= (1 << maxDeltaBits);
- }
+ private static unsafe int FloatToInt32Bits(float f) {
+ return *((int*) &f);
+ }
+
+ /// <summary>
+ /// Approximates floating point equality with a maximum number of different bits.
+ /// This is typically used in place of an epsilon comparison.
+ /// see: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
+ /// see: https://stackoverflow.com/questions/3874627/floating-point-comparison-functions-for-c-sharp
+ /// </summary>
+ /// <param name="a">the first value to compare</param>
+ /// <param name="b">>the second value to compare</param>
+ /// <param name="maxDeltaBits">the number of floating point bits to check</param>
+ /// <returns></returns>
+ public static bool ApproximatelyEqual(float a, float b, int maxDeltaBits) {
+ // we use longs here, otherwise we run into a two's complement problem, causing this to fail with -2 and 2.0
+ long aInt = FloatToInt32Bits(a);
+ if (aInt < 0)
+ aInt = Int32.MinValue - aInt;
+
+ long bInt = FloatToInt32Bits(b);
+ if (bInt < 0)
+ bInt = Int32.MinValue - bInt;
+
+ long intDiff = Math.Abs(aInt - bInt);
+ return intDiff <= (1 << maxDeltaBits);
+ }
/// <summary>
/// Approximates double-precision floating point equality by an epsilon (maximum error) value.
}
- }
+ }
}
public void CreateWindowSurface(IntPtr config)
{
Surface = Egl.CreateWindowSurface(Display, config, Handle, IntPtr.Zero);
- if (Surface==IntPtr.Zero)
- {
+ if (Surface==IntPtr.Zero)
+ {
throw new GraphicsContextException(String.Format(
"[EGL] Failed to create window surface, error {0}.", Egl.GetError()));
- }
+ }
}
//public void CreatePixmapSurface(EGLConfig config)
namespace OpenTK.Platform.MacOS
{
- //
- // http://web.archive.org/web/20100501161453/http://www.classicteck.com/rbarticles/mackeyboard.php
+ //
+ // http://web.archive.org/web/20100501161453/http://www.classicteck.com/rbarticles/mackeyboard.php
enum MacOSKeyCode
{
public static readonly IntPtr Release = Selector.Get("release");
public static readonly IntPtr Autorelease = Selector.Get("autorelease");
- [DllImport ("/usr/lib/libobjc.dylib", EntryPoint="sel_registerName")]
- public extern static IntPtr Get(string name);
- }
+ [DllImport ("/usr/lib/libobjc.dylib", EntryPoint="sel_registerName")]
+ public extern static IntPtr Get(string name);
+ }
}
namespace OpenTK
{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
- class RewrittenAttribute : Attribute
+ [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
+ class RewrittenAttribute : Attribute
{
- internal bool Rewritten;
+ internal bool Rewritten;
- public RewrittenAttribute(bool rewritten)
+ public RewrittenAttribute(bool rewritten)
{
- Rewritten = rewritten;
+ Rewritten = rewritten;
}
}
}
namespace OpenTK
{
- /// <summary>
- /// Defines the slot index for a wrapper function.
- /// This type supports OpenTK and should not be
- /// used in user code.
- /// </summary>
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
- public class SlotAttribute : Attribute
+ /// <summary>
+ /// Defines the slot index for a wrapper function.
+ /// This type supports OpenTK and should not be
+ /// used in user code.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
+ public class SlotAttribute : Attribute
{
- /// <summary>
- /// Defines the slot index for a wrapper function.
- /// </summary>
- internal int Slot;
+ /// <summary>
+ /// Defines the slot index for a wrapper function.
+ /// </summary>
+ internal int Slot;
- /// <summary>
- /// Constructs a new instance.
- /// </summary>
- /// <param name="index">The slot index for a wrapper function.</param>
- public SlotAttribute(int index)
+ /// <summary>
+ /// Constructs a new instance.
+ /// </summary>
+ /// <param name="index">The slot index for a wrapper function.</param>
+ public SlotAttribute(int index)
{
- Slot = index;
+ Slot = index;
}
}
}