Merge pull request #575 from Nihlus/cleanup-5-enforce-braces

Enforce the use of braces for conditional statements
This commit is contained in:
Jarl Gullberg 2017-07-20 21:22:18 +02:00 committed by GitHub
commit 5b03732763
158 changed files with 2592 additions and 294 deletions

View file

@ -60,7 +60,9 @@ namespace Bind
public void Unindent()
{
if (indent_level > 0)
{
--indent_level;
}
}
public void Write(WriteOptions options, string value)
@ -144,7 +146,9 @@ namespace Bind
if (options != WriteOptions.NoIndent)
{
for (int i = indent_level; i > 0; i--)
{
sw.Write(" ");
}
}
}

View file

@ -54,7 +54,9 @@ namespace Bind
int top = Console.CursorTop;
Console.Write(text);
for (int i = text.Length; i < 80; i++)
{
Console.Write(" ");
}
Console.WriteLine();
Console.SetCursorPosition(left, top);
}
@ -63,7 +65,9 @@ namespace Bind
{
Console.WriteLine("Writing bindings to {0}", Settings.OutputPath);
if (!Directory.Exists(Settings.OutputPath))
{
Directory.CreateDirectory(Settings.OutputPath);
}
string temp_enums_file = Path.GetTempFileName();
string temp_wrappers_file = Path.GetTempFileName();
@ -84,7 +88,9 @@ namespace Bind
sw.WriteLine("static partial class {0}", Settings.OutputClass);
}
else
{
sw.WriteLine("namespace {0}", Settings.EnumsOutput);
}
sw.WriteLine("{");
@ -124,10 +130,22 @@ namespace Bind
string output_core = Path.Combine(Settings.OutputPath, Settings.ImportsFile);
string output_wrappers = Path.Combine(Settings.OutputPath, Settings.WrappersFile);
if (File.Exists(output_enums)) File.Delete(output_enums);
if (File.Exists(output_delegates)) File.Delete(output_delegates);
if (File.Exists(output_core)) File.Delete(output_core);
if (File.Exists(output_wrappers)) File.Delete(output_wrappers);
if (File.Exists(output_enums))
{
File.Delete(output_enums);
}
if (File.Exists(output_delegates))
{
File.Delete(output_delegates);
}
if (File.Exists(output_core))
{
File.Delete(output_core);
}
if (File.Exists(output_wrappers))
{
File.Delete(output_wrappers);
}
File.Move(temp_enums_file, output_enums);
File.Move(temp_wrappers_file, output_wrappers);
@ -296,9 +314,13 @@ namespace Bind
else if (!String.IsNullOrEmpty(f.Version))
{
if (f.Category.StartsWith("VERSION"))
{
category = String.Format("[requires: {0}]", "v" + f.Version);
}
else
{
category = String.Format("[requires: {0}]", "v" + f.Version + " or " + f.Category);
}
}
// Write function summary
@ -413,7 +435,9 @@ namespace Bind
sw.Write(str);
if (!String.IsNullOrEmpty(str))
{
sw.WriteLine(",");
}
}
}
@ -424,9 +448,13 @@ namespace Bind
//sw.WriteLine();
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
{
Trace.WriteLine(String.Format("Writing enums to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.NestedEnumsClass));
}
else
{
Trace.WriteLine(String.Format("Writing enums to:\t{0}", Settings.EnumsOutput));
}
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) == Settings.Legacy.None)
{
@ -480,11 +508,17 @@ namespace Bind
}
if (@enum.IsObsolete)
{
sw.WriteLine("[Obsolete(\"{0}\")]", @enum.Obsolete);
}
if (!@enum.CLSCompliant)
{
sw.WriteLine("[CLSCompliant(false)]");
}
if (@enum.IsFlagCollection)
{
sw.WriteLine("[Flags]");
}
sw.WriteLine("public enum " + @enum.Name + " : " + @enum.Type);
sw.WriteLine("{");
sw.Indent();
@ -561,7 +595,9 @@ namespace Bind
sb.Append(d.Unsafe ? "unsafe " : "");
if (is_delegate)
{
sb.Append("delegate ");
}
sb.Append(GetDeclarationString(d.ReturnType, Settings.Legacy.ConstIntEnums));
sb.Append(" ");
sb.Append(Settings.FunctionPrefix);
@ -579,12 +615,16 @@ namespace Bind
{
int ret = String.Compare(c1.Value, c2.Value);
if (ret == 0)
{
return String.Compare(c1.Name, c2.Name);
}
return ret;
});
if (e.IsFlagCollection)
{
sb.AppendLine("[Flags]");
}
sb.Append("public enum ");
sb.Append(e.Name);
sb.Append(" : ");
@ -597,7 +637,9 @@ namespace Bind
sb.Append(" ");
sb.Append(declaration);
if (!String.IsNullOrEmpty(declaration))
{
sb.AppendLine(",");
}
}
sb.Append("}");
@ -640,7 +682,9 @@ namespace Bind
foreach (Parameter p in f.Parameters)
{
if (p.Generic)
{
sb.AppendLine(String.Format(" where {0} : struct", p.CurrentType));
}
}
}
@ -652,16 +696,24 @@ namespace Bind
StringBuilder sb = new StringBuilder();
if (p.Flow == FlowDirection.Out)
{
sb.Append("[OutAttribute] ");
}
else if (p.Flow == FlowDirection.Undefined)
{
sb.Append("[InAttribute, OutAttribute] ");
}
if (p.Reference)
{
if (p.Flow == FlowDirection.Out)
{
sb.Append("out ");
}
else
{
sb.Append("ref ");
}
}
if (!override_unsafe_setting && ((Settings.Compatibility & Settings.Legacy.NoPublicUnsafeFunctions) != Settings.Legacy.None))

View file

@ -42,7 +42,9 @@ namespace Bind
public DocProcessor(IBind generator)
{
if (generator == null)
{
throw new ArgumentNullException();
}
Generator = generator;
foreach (string file in Directory.GetFiles(Settings.DocPath).Concat(
@ -68,9 +70,13 @@ namespace Bind
{
var file = Settings.FunctionPrefix + f.WrappedDelegate.Name + ".xml";
if (!DocumentationFiles.ContainsKey(file))
{
file = Settings.FunctionPrefix + f.TrimmedName + ".xml";
}
if (!DocumentationFiles.ContainsKey(file))
{
file = Settings.FunctionPrefix + f.TrimmedName.TrimEnd(numbers) + ".xml";
}
docs =
(DocumentationFiles.ContainsKey(file) ? ProcessFile(DocumentationFiles[file], processor) : null) ??
@ -96,7 +102,9 @@ namespace Bind
string text;
if (LastFile == file)
{
return Cached;
}
LastFile = file;
text = File.ReadAllText(file);
@ -155,7 +163,9 @@ namespace Bind
private Documentation ToInlineDocs(XDocument doc, EnumProcessor enum_processor)
{
if (doc == null || enum_processor == null)
{
throw new ArgumentNullException();
}
var no_const_processing = Settings.Legacy.NoAdvancedEnumProcessing | Settings.Legacy.ConstIntEnums;
if (!Generator.Settings.IsEnabled(no_const_processing))

View file

@ -45,9 +45,13 @@ namespace Bind
public EnumProcessor(IBind generator, IEnumerable<string> overrides)
{
if (generator == null)
{
throw new ArgumentNullException("generator");
}
if (overrides == null)
{
throw new ArgumentNullException("overrides");
}
Generator = generator;
Overrides = overrides;
@ -69,7 +73,9 @@ namespace Bind
public static string GetOverridesPath(string apiname, string enumeration)
{
if (enumeration == null)
{
throw new ArgumentNullException("enumeration");
}
var path = new StringBuilder();
path.Append("/signatures/replace");
@ -149,15 +155,21 @@ namespace Bind
public string TranslateEnumName(string name)
{
if (String.IsNullOrEmpty(name))
{
return name;
}
if (Utilities.CSharpKeywords.Contains(name))
{
return name;
}
if (!IsAlreadyProcessed(name))
{
if (Char.IsDigit(name[0]))
{
name = Settings.ConstantPrefix + name;
}
StringBuilder translator = new StringBuilder(name);
@ -194,11 +206,17 @@ namespace Bind
}
if (is_after_underscore_or_number)
{
char_to_add = Char.ToUpper(c);
}
else if (is_previous_uppercase)
{
char_to_add = Char.ToLower(c);
}
else
{
char_to_add = c;
}
translator.Append(char_to_add);
@ -219,7 +237,9 @@ namespace Bind
name = translator.ToString();
if (name.StartsWith(Settings.EnumPrefix))
{
name = name.Substring(Settings.EnumPrefix.Length);
}
}
return name;
@ -282,7 +302,9 @@ namespace Bind
public string TranslateConstantName(string s, bool isValue)
{
if (String.IsNullOrEmpty(s))
{
return s;
}
StringBuilder translator = new StringBuilder(s.Length);
@ -302,7 +324,9 @@ namespace Bind
bool is_after_digit = false;
if (!isValue && Char.IsDigit(s[0]))
{
s = Settings.ConstantPrefix + s;
}
foreach (char c in s)
{
@ -333,7 +357,9 @@ namespace Bind
translator[0] = Char.ToUpper(translator[0]);
}
else
{
translator.Append(s);
}
}
return translator.ToString();
@ -346,14 +372,20 @@ namespace Bind
{
// Trim the unsigned or long specifiers used in C constants ('u' or 'ull').
if (value.ToLower().EndsWith("ull"))
{
value = value.Substring(0, value.Length - 3);
}
if (value.ToLower().EndsWith("u"))
{
value = value.Substring(0, value.Length - 1);
}
}
// Strip the prefix, if any.
if (value.StartsWith(Settings.ConstantPrefix))
{
value = value.Substring(Settings.ConstantPrefix.Length);
}
return TranslateConstantName(value, IsValue(value));
}

View file

@ -62,9 +62,13 @@ namespace Bind
public FuncProcessor(IBind generator, IEnumerable<string> overrides)
{
if (generator == null)
{
throw new ArgumentNullException("generator");
}
if (overrides == null)
{
throw new ArgumentNullException("overrides");
}
Generator = generator;
Overrides = overrides;
@ -351,15 +355,23 @@ namespace Bind
{
// For consistency - many overrides use string instead of String.
if (enum_override.Value == "string")
{
type.QualifiedType = "String";
}
else if (enum_override.Value == "StringBuilder")
{
type.QualifiedType = "StringBuilder";
}
else
{
type.CurrentType = enum_override.Value;
}
}
if (type.CurrentType == "IntPtr" && String.IsNullOrEmpty(type.PreviousType))
{
type.Pointer = 0;
}
if (type.Pointer >= 3)
{
@ -455,13 +467,19 @@ namespace Bind
string extensionless_name = GetTrimmedExtension(d.Name, ext);
function_overload = nav.Select(GetOverloadsPath(apiname, apiversion, d.Name, ext));
if (function_overload.Count != 0)
{
break;
}
function_overload = nav.Select(GetOverloadsPath(apiname, apiversion, extensionless_name, ext));
if (function_overload.Count != 0)
{
break;
}
function_overload = nav.Select(GetOverloadsPath(apiname, apiversion, trimmed_name, ext));
if (function_overload.Count != 0)
{
break;
}
}
return function_overload;
}
@ -522,7 +540,9 @@ namespace Bind
case "count":
int count;
if (Int32.TryParse(node.Value, out count))
{
d.Parameters[i].ElementCount = count;
}
break;
}
}
@ -583,10 +603,14 @@ namespace Bind
if (d.ReturnType.CurrentType.Contains("GLenum"))
{
if ((Settings.Compatibility & Settings.Legacy.ConstIntEnums) == Settings.Legacy.None)
{
d.ReturnType.QualifiedType = String.Format("{0}{1}{2}",
Settings.EnumsOutput, Settings.NamespaceSeparator, Settings.CompleteEnumName);
}
else
{
d.ReturnType.QualifiedType = "int";
}
}
if (d.ReturnType.CurrentType.ToLower().Contains("bool"))
@ -623,7 +647,9 @@ namespace Bind
{
TranslateParameter(d.Parameters[i], function_override, nav, enum_processor, enums, d.Category, apiname);
if (d.Parameters[i].CurrentType == "UInt16" && d.Name.Contains("LineStipple"))
{
d.Parameters[i].WrapperType |= WrapperTypes.UncheckedParameter;
}
}
}
@ -693,7 +719,9 @@ namespace Bind
}
if (Utilities.CSharpKeywords.Contains(p.Name))
{
p.Name = Settings.KeywordEscapeCharacter + p.Name;
}
// This causes problems with bool arrays
//if (CurrentType.ToLower().Contains("bool"))
@ -793,7 +821,9 @@ namespace Bind
{
cls.Parameters[i].CurrentType = GetCLSCompliantType(cls.Parameters[i]);
if (cls.Parameters[i].CurrentType != f.Parameters[i].CurrentType)
{
modified = true;
}
}
// Only add a cls-compliant overload if we have
@ -840,21 +870,33 @@ namespace Bind
for (k = 0; k < wrappers[i].Parameters.Count; k++)
{
if (wrappers[i].Parameters[k].CurrentType != wrappers[j].Parameters[k].CurrentType)
{
break;
}
if (wrappers[i].Parameters[k].DiffersOnlyOnReference(wrappers[j].Parameters[k]))
{
if (wrappers[i].Parameters[k].Reference)
{
function_i_is_problematic = true;
}
else
{
function_j_is_problematic = true;
}
}
}
if (k == wrappers[i].Parameters.Count)
{
if (function_i_is_problematic)
{
must_remove.Add(i);
}
if (function_j_is_problematic)
{
must_remove.Add(j);
}
}
}
}
@ -879,7 +921,9 @@ namespace Bind
if (!type.CLSCompliant)
{
if (type.Pointer != 0 && Settings.Compatibility == Settings.Legacy.Tao)
{
return "IntPtr";
}
switch (type.CurrentType)
{

View file

@ -55,7 +55,9 @@ namespace Bind.GL2
public Generator(Settings settings)
{
if (settings == null)
{
throw new ArgumentNullException("settings");
}
Settings = settings.Clone();

View file

@ -99,7 +99,9 @@ namespace Bind
val = val.ToLower();
bool enable = !opt.StartsWith("-");
if (val.StartsWith("+") || val.StartsWith("-"))
{
val = val.Substring(1);
}
var settings = Settings.Legacy.None;
switch (val)

View file

@ -84,9 +84,13 @@ namespace Bind
get
{
if ((Compatibility & Legacy.NestedEnums) != Legacy.None)
{
return OutputNamespace + NamespaceSeparator + OutputClass + NamespaceSeparator + NestedEnumsClass;
}
else
{
return String.IsNullOrEmpty(EnumsNamespace) ? OutputNamespace : OutputNamespace + NamespaceSeparator + EnumsNamespace;
}
}
}
@ -95,9 +99,13 @@ namespace Bind
get
{
if ((Compatibility & Legacy.NestedEnums) != Legacy.None)
{
return OutputNamespace + NamespaceSeparator + GLClass + NamespaceSeparator + NestedEnumsClass;
}
else
{
return OutputNamespace + NamespaceSeparator + EnumsNamespace;
}
}
}
@ -199,7 +207,15 @@ namespace Bind
public bool DropMultipleTokens
{
get { return (Compatibility & Legacy.NoDropMultipleTokens) == Legacy.None; }
set { if (value) Compatibility |= Legacy.NoDropMultipleTokens; else Compatibility &= ~Legacy.NoDropMultipleTokens; }
set { if (value)
{
Compatibility |= Legacy.NoDropMultipleTokens;
}
else
{
Compatibility &= ~Legacy.NoDropMultipleTokens;
}
}
}
public string WindowsGDI = "OpenTK.Platform.Windows.API";

View file

@ -32,10 +32,14 @@ namespace Bind.Structures
set
{
if (String.IsNullOrEmpty(value))
{
throw new ArgumentNullException("value");
}
if (OriginalName == null)
{
OriginalName = _name;
}
_name = value;
}
@ -55,7 +59,9 @@ namespace Bind.Structures
set
{
if (String.IsNullOrEmpty(value))
{
throw new ArgumentNullException("value");
}
_value = value;
}
@ -108,9 +114,13 @@ namespace Bind.Structures
public static bool TranslateConstantWithReference(Constant c, EnumCollection enums)
{
if (c == null)
{
throw new ArgumentNullException("c");
}
if (enums == null)
{
throw new ArgumentNullException("enums");
}
if (!String.IsNullOrEmpty(c.Reference))
{
@ -165,7 +175,9 @@ namespace Bind.Structures
{
int ret = Value.CompareTo(other.Value);
if (ret == 0)
{
return Name.CompareTo(other.Name);
}
return ret;
}
}

View file

@ -61,18 +61,26 @@ namespace Bind.Structures
get
{
if (cls_compliance_overriden != null)
{
return (bool)cls_compliance_overriden;
}
if (Unsafe)
{
return false;
}
if (!ReturnType.CLSCompliant)
{
return false;
}
foreach (Parameter p in Parameters)
{
if (!p.CLSCompliant)
{
return false;
}
}
return true;
}
@ -96,12 +104,16 @@ namespace Bind.Structures
// TODO: Add special cases for (Get)ShaderSource.
if (ReturnType.WrapperType != WrapperTypes.None)
{
return true;
}
foreach (Parameter p in Parameters)
{
if (p.WrapperType != WrapperTypes.None)
{
return true;
}
}
return false;
@ -121,7 +133,9 @@ namespace Bind.Structures
// return false;
if (ReturnType.Pointer != 0)
{
return true;
}
foreach (Parameter p in Parameters)
{
@ -198,9 +212,13 @@ namespace Bind.Structures
{
int ret = Name.CompareTo(other.Name);
if (ret == 0)
{
ret = Parameters.CompareTo(other.Parameters);
}
if (ret == 0)
{
ret = ReturnType.CompareTo(other.ReturnType);
}
return ret;
}

View file

@ -47,7 +47,9 @@ namespace Bind.Structures
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
_constant_collection.Clear();
foreach (var item in value)
@ -89,12 +91,16 @@ namespace Bind.Structures
// empty check, let's try to remove first Arb, then Ext from the strings.
int ret = PreferEmpty(ext1, ext2);
if (ret != 0)
{
return ret;
}
ext1 = ext1.Replace("Arb", ""); ext2 = ext2.Replace("Arb", "");
ret = PreferEmpty(ext1, ext2);
if (ret != 0)
{
return ret;
}
ext1 = ext1.Replace("Ext", ""); ext2 = ext2.Replace("Ext", "");
return PreferEmpty(ext1, ext2);
@ -104,11 +110,17 @@ namespace Bind.Structures
private int PreferEmpty(string ext1, string ext2)
{
if (String.IsNullOrEmpty(ext1) && !String.IsNullOrEmpty(ext2))
{
return -1;
}
else if (String.IsNullOrEmpty(ext2) && !String.IsNullOrEmpty(ext1))
{
return 1;
}
else
{
return 0;
}
}
public void Add(Enum e)

View file

@ -81,9 +81,13 @@ namespace Bind.Structures
{
int ret = Name.CompareTo(other.Name);
if (ret == 0)
{
ret = Parameters.CompareTo(other.Parameters);
}
if (ret == 0)
{
ret = ReturnType.CompareTo(other.ReturnType);
}
return ret;
}
}
@ -112,9 +116,13 @@ namespace Bind.Structures
public void Unindent()
{
if (indent.Length > 4)
{
indent = indent.Substring(4);
}
else
{
indent = String.Empty;
}
}
new public void Add(string s)
@ -133,7 +141,9 @@ namespace Bind.Structures
public override string ToString()
{
if (Count == 0)
{
return String.Empty;
}
StringBuilder sb = new StringBuilder(Count);

View file

@ -33,7 +33,9 @@ namespace Bind.Structures
: base(p)
{
if (p == null)
{
return;
}
Name = p.Name;
Unchecked = p.Unchecked;
@ -164,7 +166,9 @@ namespace Bind.Structures
{
int result = base.CompareTo(other);
if (result == 0)
{
result = Name.CompareTo(other.Name);
}
return result;
}
@ -218,7 +222,9 @@ namespace Bind.Structures
public ParameterCollection(IEnumerable<Parameter> parameters)
{
foreach (Parameter p in parameters)
{
Add(new Parameter(p));
}
}
private void BuildCache()
@ -285,16 +291,24 @@ namespace Bind.Structures
foreach (Parameter p in this)
{
if (p.Pointer != 0 || p.CurrentType.Contains("IntPtr"))
{
hasPointerParameters = true;
}
if (p.Reference)
{
hasReferenceParameters = true;
}
if (p.Unsigned)
{
hasUnsignedParameters = true;
}
if (p.Generic)
{
hasGenericParameters = true;
}
}
}
@ -313,7 +327,9 @@ namespace Bind.Structures
sb.Replace(", ", ")", sb.Length - 2, 2);
}
else
{
sb.Append(")");
}
return sb.ToString();
}
@ -321,8 +337,12 @@ namespace Bind.Structures
public bool ContainsType(string type)
{
foreach (Parameter p in this)
{
if (p.CurrentType == type)
{
return true;
}
}
return false;
}
@ -423,7 +443,9 @@ namespace Bind.Structures
{
int result = this[i].CompareTo(other[i]);
if (result != 0)
{
return result;
}
}
return 0;
}
@ -432,7 +454,9 @@ namespace Bind.Structures
public bool Equals(ParameterCollection other)
{
if (Count != other.Count)
{
return false;
}
bool result = true;
for (int i = 0; i < Count && result; i++)

View file

@ -54,7 +54,9 @@ namespace Bind.Structures
set
{
if (String.IsNullOrEmpty(value))
{
throw new ArgumentNullException();
}
int qualifier_end = value.LastIndexOf('.');
if (qualifier_end > -1)
@ -83,12 +85,18 @@ namespace Bind.Structures
set
{
if (String.IsNullOrEmpty(value))
{
throw new ArgumentException();
}
if (!String.IsNullOrEmpty(type))
{
PreviousType = type;
}
if (!String.IsNullOrEmpty(value))
{
type = value.Trim();
}
while (type.EndsWith("*"))
{
@ -228,19 +236,29 @@ namespace Bind.Structures
// DelegateCollection.Add that depends on this fact.
int result = this.CurrentType.CompareTo(other.CurrentType);
if (result == 0)
{
result = Pointer.CompareTo(other.Pointer); // Must come after array/ref, see issue [#1098]
}
if (result == 0)
{
result = Reference.CompareTo(other.Reference);
}
if (result == 0)
{
result = Array.CompareTo(other.Array);
}
// Note: CLS-compliance and element counts
// are used for comparison calculations, in order
// to maintain a stable sorting order, even though
// they are not used in equality calculations.
if (result == 0)
{
result = CLSCompliant.CompareTo(other.CLSCompliant);
}
if (result == 0)
{
result = ElementCount.CompareTo(other.ElementCount);
}
return result;
}

View file

@ -146,7 +146,9 @@ namespace Bind
internal static StreamReader OpenSpecFile(string folder, string file)
{
if (String.IsNullOrEmpty(folder) || String.IsNullOrEmpty(file))
{
return null;
}
Console.WriteLine(folder);
Console.WriteLine(file);

View file

@ -44,7 +44,9 @@ namespace Bind
public XmlSpecReader(Settings settings)
{
if (settings == null)
{
throw new ArgumentNullException("settings");
}
Settings = settings;
}
@ -71,7 +73,9 @@ namespace Bind
foreach (XPathNavigator nav in specs.CreateNavigator().Select(xpath_delete))
{
foreach (XPathNavigator node in nav.SelectChildren("function", String.Empty))
{
delegates.Remove(node.GetAttribute("name", String.Empty));
}
}
foreach (XPathNavigator nav in specs.CreateNavigator().Select(xpath_add))
{
@ -105,7 +109,9 @@ namespace Bind
foreach (XPathNavigator nav in specs.CreateNavigator().Select(xpath_delete))
{
foreach (XPathNavigator node in nav.SelectChildren("enum", String.Empty))
{
enums.Remove(node.GetAttribute("name", String.Empty));
}
}
foreach (XPathNavigator nav in specs.CreateNavigator().Select(xpath_add))
{
@ -122,14 +128,18 @@ namespace Bind
Dictionary<string, string> GLTypes = new Dictionary<string, string>();
if (sr == null)
{
return GLTypes;
}
do
{
string line = sr.ReadLine();
if (String.IsNullOrEmpty(line) || line.StartsWith("#"))
{
continue;
}
string[] words = line.Split(" ,*\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
@ -190,14 +200,20 @@ namespace Bind
{
string line = sr.ReadLine();
if (String.IsNullOrEmpty(line) || line.StartsWith("#"))
{
continue;
}
string[] words = line.Split(" ,\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (words.Length < 2)
{
continue;
}
if (((Settings.Compatibility & Settings.Legacy.NoBoolParameters) != Settings.Legacy.None) && words[1] == "bool")
{
words[1] = "Int32";
}
CSTypes.Add(words[0], words[1]);
}
@ -257,7 +273,9 @@ namespace Bind
// so we add them anyway (which is desirable).
if (!String.IsNullOrEmpty(version) && !String.IsNullOrEmpty(apiversion) &&
Decimal.Parse(version) > Decimal.Parse(apiversion))
{
continue;
}
// Check whether we are adding to an existing delegate or creating a new one.
var d = new Delegate
@ -272,7 +290,9 @@ namespace Bind
Obsolete = node.GetAttribute("obsolete", String.Empty).Trim()
};
if (!extensions.Contains(d.Extension))
{
extensions.Add(d.Extension);
}
foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
{
@ -344,7 +364,9 @@ namespace Bind
e.Obsolete = node.GetAttribute("obsolete", String.Empty).Trim();
if (String.IsNullOrEmpty(e.Name))
{
throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString()));
}
// It seems that all flag collections contain "Mask" in their names.
// This looks like a heuristic, but it holds 100% in practice

View file

@ -61,9 +61,13 @@ namespace OpenTK.Convert
var version = (e.Attribute("version") ?? new XAttribute("version", String.Empty)).Value;
var key = name + version;
if (!elements.ContainsKey(key))
{
elements.Add(key, e);
}
else
{
elements[key].Add(e.Elements());
}
}
return elements.Values;
@ -124,7 +128,9 @@ namespace OpenTK.Convert
{
var api = (e.Attribute("api") ?? new XAttribute("api", "default")).Value;
if (!enums.ContainsKey(api))
{
enums.Add(api, new SortedDictionary<string, string>());
}
enums[api].Add(
TrimName(e.Attribute("name").Value),
@ -151,12 +157,14 @@ namespace OpenTK.Convert
{
var key = apiname + version;
if (!APIs.ContainsKey(key))
{
APIs.Add(
key,
new XElement(
"api",
new XAttribute("name", apiname),
String.IsNullOrEmpty(version) ? null : new XAttribute("version", version)));
}
var api = APIs[key];
var enum_name = TrimName(feature.Attribute("name").Value);
@ -267,12 +275,14 @@ namespace OpenTK.Convert
var key = apiname + cmd_version;
if (!APIs.ContainsKey(key))
{
APIs.Add(
key,
new XElement(
"api",
new XAttribute("name", apiname),
new XAttribute("version", cmd_version)));
"api",
new XAttribute("name", apiname),
new XAttribute("version", cmd_version)));
}
var api = APIs[key];
foreach (var command in feature.Elements("require").Elements("command"))
@ -282,13 +292,17 @@ namespace OpenTK.Convert
ExtensionRegex.Match(cmd_name).Value ??
(feature.Name == "extension" ? category.Substring(0, category.IndexOf("_")) : "Core");
if (String.IsNullOrEmpty(cmd_extension))
{
cmd_extension = "Core";
}
XElement function = TranslateCommand(commands[cmd_name]);
function.Add(new XAttribute("category", cmd_category));
function.Add(new XAttribute("extension", cmd_extension));
if (!String.IsNullOrEmpty(cmd_version))
{
function.Add(new XAttribute("version", cmd_version));
}
Merge(api, function);
}
@ -345,8 +359,9 @@ namespace OpenTK.Convert
// Sanity check: one function cannot belong to two different extensions
if (f.Attribute("extension").Value != function.Attribute("extension").Value)
{
throw new InvalidOperationException("Different extensions for the same function");
}
}
else
{
@ -434,9 +449,13 @@ namespace OpenTK.Convert
{
var words = ret.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (words[0] == "struct" || words[0] == "const")
{
words[1] = group.Value;
}
else
{
words[0] = group.Value;
}
ret = String.Join(" ", words);
}
@ -447,13 +466,21 @@ namespace OpenTK.Convert
private static string Join(string left, string right)
{
if (!String.IsNullOrEmpty(left) && !String.IsNullOrEmpty(right))
{
return left + "|" + right;
}
else if (!String.IsNullOrEmpty(left))
{
return left;
}
else if (!String.IsNullOrEmpty(right))
{
return right;
}
else
{
return String.Empty;
}
}
private static XAttribute Lookup(IDictionary<string, XElement> categories, string cmd_name, string attribute)

View file

@ -136,7 +136,9 @@ namespace OpenTK.Convert
foreach (var e in entries)
{
if (e.Value.Name.LocalName != "enum")
{
continue;
}
var tokens = e.Value.Elements()
.OrderBy(t => (string)t.Attribute("name"))
.ToList();

View file

@ -85,11 +85,17 @@ namespace OpenTK.Convert
public string TrimName(string name)
{
if (name.StartsWith(EnumPrefix))
{
return name.Remove(0, EnumPrefix.Length);
}
else if (name.StartsWith(FuncPrefix))
{
return name.Remove(0, FuncPrefix.Length);
}
else
{
return name;
}
}
}
}

View file

@ -182,7 +182,9 @@ namespace OpenTK.Rewrite
{
// Pretend there is no slots if we want to force everything to work through DllImport (Android & iOS)
if (dllimport)
{
return -1;
}
var slot_attribute = signature.CustomAttributes
.FirstOrDefault(a => a.AttributeType.Name == "SlotAttribute");

View file

@ -355,9 +355,13 @@ namespace OpenTK.Platform.MacOS
byte retval = _aglSetCurrentContext(context);
if (retval != 0)
{
return true;
}
else
{
return false;
}
}
[DllImport(agl)] internal static extern AGLContext aglGetCurrentContext();

View file

@ -143,13 +143,21 @@ namespace OpenTK.Platform.MacOS
int[] glrect = new int[4];
if (XOffset != null)
{
glrect[0] = rect.X + XOffset();
}
else
{
glrect[0] = rect.X;
}
if (YOffset != null)
{
glrect[1] = rect.Y + YOffset();
}
else
{
glrect[1] = rect.Y;
}
glrect[2] = rect.Width;
glrect[3] = rect.Height;
@ -190,9 +198,11 @@ namespace OpenTK.Platform.MacOS
Agl.AglError err = Agl.GetError();
if (err != Agl.AglError.NoError)
{
throw new Exception(String.Format(
"AGL Error from function {0}: {1} {2}",
function, err, Agl.ErrorString(err)));
}
}
private bool firstSwap = true;
@ -215,7 +225,9 @@ namespace OpenTK.Platform.MacOS
public void MakeCurrent(IWindowInfo window)
{
if (Agl.aglSetCurrentContext(Context.Handle) == false)
{
MyAGLReportError("aglSetCurrentContext");
}
}
public bool IsCurrent
@ -241,7 +253,9 @@ namespace OpenTK.Platform.MacOS
set
{
if (!Agl.aglSetInteger(Context.Handle, Agl.ParameterNames.AGL_SWAP_INTERVAL, ref value))
{
MyAGLReportError("aglSetInteger");
}
}
}
@ -289,7 +303,9 @@ namespace OpenTK.Platform.MacOS
private void Dispose(bool disposing)
{
if (IsDisposed || Context.Handle == IntPtr.Zero)
{
return;
}
Debug.Print("Disposing of AGL context.");
Agl.aglSetCurrentContext(IntPtr.Zero);

View file

@ -88,7 +88,9 @@ namespace OpenTK
public GLControl(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
{
if (mode == null)
{
throw new ArgumentNullException("mode");
}
// SDL does not currently support embedding
// on external windows. If Open.Toolkit is not yet
@ -144,13 +146,19 @@ namespace OpenTK
private void ValidateState()
{
if (IsDisposed)
{
throw new ObjectDisposedException(GetType().Name);
}
if (!IsHandleCreated)
{
CreateControl();
}
if (implementation == null || context == null || context.IsDisposed)
{
RecreateHandle();
}
}
/// <summary>
@ -179,21 +187,31 @@ namespace OpenTK
protected override void OnHandleCreated(EventArgs e)
{
if (context != null)
{
context.Dispose();
}
if (implementation != null)
{
implementation.WindowInfo.Dispose();
}
if (design_mode)
{
implementation = new DummyGLControl();
}
else
{
implementation = new GLControlFactory().CreateGLControl(format, this);
}
context = implementation.CreateContext(major, minor, flags);
MakeCurrent();
if (!design_mode)
{
((IGraphicsContextInternal)Context).LoadAll();
}
// Deferred setting of vsync mode. See VSync property for more information.
if (initial_vsync_value.HasValue)
@ -242,7 +260,9 @@ namespace OpenTK
ValidateState();
if (design_mode)
{
e.Graphics.Clear(BackColor);
}
base.OnPaint(e);
}
@ -268,7 +288,9 @@ namespace OpenTK
BeginInvoke(delay); //Need the native window to resize first otherwise our control will be in the wrong place.
}
else if (context != null)
{
context.Update (Implementation.WindowInfo);
}
base.OnResize(e);
}
@ -283,7 +305,9 @@ namespace OpenTK
public void PerformContextUpdate()
{
if (context != null)
{
context.Update (Implementation.WindowInfo);
}
}
/// <summary>
@ -293,7 +317,9 @@ namespace OpenTK
protected override void OnParentChanged(EventArgs e)
{
if (context != null)
{
context.Update(Implementation.WindowInfo);
}
base.OnParentChanged(e);
}

View file

@ -37,15 +37,34 @@ namespace OpenTK
public IGLControl CreateGLControl(GraphicsMode mode, Control control)
{
if (mode == null)
{
throw new ArgumentNullException("mode");
}
if (control == null)
{
throw new ArgumentNullException("control");
}
if (Configuration.RunningOnSdl2) return new Sdl2GLControl(mode, control);
else if (Configuration.RunningOnWindows) return new WinGLControl(mode, control);
else if (Configuration.RunningOnMacOS) return new CarbonGLControl(mode, control);
else if (Configuration.RunningOnX11) return new X11GLControl(mode, control);
else throw new PlatformNotSupportedException();
if (Configuration.RunningOnSdl2)
{
return new Sdl2GLControl(mode, control);
}
else if (Configuration.RunningOnWindows)
{
return new WinGLControl(mode, control);
}
else if (Configuration.RunningOnMacOS)
{
return new CarbonGLControl(mode, control);
}
else if (Configuration.RunningOnX11)
{
return new X11GLControl(mode, control);
}
else
{
throw new PlatformNotSupportedException();
}
}
}
}

View file

@ -85,7 +85,9 @@ namespace OpenTK.Platform.MacOS
{
symbol = NSLookupAndBindSymbol(function);
if (symbol != IntPtr.Zero)
{
symbol = NSAddressOfSymbol(symbol);
}
}
return symbol;
}

View file

@ -62,9 +62,13 @@ namespace OpenTK
internal X11GLControl(GraphicsMode mode, Control control)
{
if (mode == null)
{
throw new ArgumentNullException("mode");
}
if (control == null)
{
throw new ArgumentNullException("control");
}
// Note: the X11 window is created with a default XVisualInfo,
// that is not necessarily compatible with the desired GraphicsMode.
@ -83,8 +87,11 @@ namespace OpenTK
mode.Buffers,
mode.Stereo);
if (xplatui == null) throw new PlatformNotSupportedException(
if (xplatui == null)
{
throw new PlatformNotSupportedException(
"System.Windows.Forms.XplatUIX11 missing. Unsupported platform or Mono runtime version, aborting.");
}
// get the required handles from the X11 API.
display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");

View file

@ -191,7 +191,9 @@ namespace OpenTK
private static void OnGraphicsContextInitialized()
{
if (GraphicsContextInitialized != null)
{
GraphicsContextInitialized(null, EventArgs.Empty);
}
}
/// <summary>
@ -206,7 +208,9 @@ namespace OpenTK
private static void OnGraphicsContextShuttingDown()
{
if (GraphicsContextShuttingDown != null)
{
GraphicsContextShuttingDown(null, EventArgs.Empty);
}
}
/// <summary>
@ -221,7 +225,9 @@ namespace OpenTK
protected virtual void OnInitialized()
{
if (Initialized != null)
{
Initialized(this, EventArgs.Empty);
}
}
/// <summary>
@ -235,7 +241,9 @@ namespace OpenTK
protected virtual void OnRenderFrame()
{
if (RenderFrame != null)
{
RenderFrame(this, EventArgs.Empty);
}
}
/// <summary>
@ -249,7 +257,9 @@ namespace OpenTK
protected virtual void OnShuttingDown()
{
if (ShuttingDown != null)
{
ShuttingDown(this, EventArgs.Empty);
}
}
#if GTK3
@ -269,9 +279,13 @@ namespace OpenTK
#endif
{
if (!_Initialized)
{
Initialize();
}
else
{
_GraphicsContext.MakeCurrent(_WindowInfo);
}
#if GTK3
var result = base.OnDrawn(cr);
@ -300,7 +314,9 @@ namespace OpenTK
bool result = base.OnConfigureEvent(evnt);
if (_GraphicsContext != null)
{
_GraphicsContext.Update(_WindowInfo);
}
return result;
}
@ -318,7 +334,9 @@ namespace OpenTK
ColorBPP = 32;
if (DepthBPP == 0)
{
DepthBPP = 16;
}
}
ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP);
@ -327,16 +345,24 @@ namespace OpenTK
int buffers = 2;
if (SingleBuffer)
{
buffers--;
}
GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);
if (Configuration.RunningOnWindows)
{
Console.WriteLine("OpenTK running on windows");
}
else if (Configuration.RunningOnMacOS)
{
Console.WriteLine("OpenTK running on OSX");
}
else
{
Console.WriteLine("OpenTK running on X11");
}
#if GTK3
IntPtr widgetWindowHandle = this.Window.Handle;
@ -346,11 +372,17 @@ namespace OpenTK
// IWindowInfo
if (Configuration.RunningOnWindows)
{
_WindowInfo = WinWindowsInfoInitializer.Initialize(widgetWindowHandle);
}
else if (Configuration.RunningOnMacOS)
{
_WindowInfo = OSXWindowInfoInitializer.Initialize(widgetWindowHandle);
}
else
{
_WindowInfo = XWindowInfoInitializer.Initialize(graphicsMode, this.Display.Handle, this.Screen.Number, widgetWindowHandle, this.Screen.RootWindow.Handle);
}
// GraphicsContext
_GraphicsContext = new GraphicsContext(graphicsMode, _WindowInfo, GlVersionMajor, GlVersionMinor, GraphicsContextFlags);

View file

@ -69,11 +69,17 @@ namespace OpenTK.Audio
public AudioCapture(string deviceName, int frequency, ALFormat sampleFormat, int bufferSize)
{
if (!AudioDeviceEnumerator.IsOpenALSupported)
{
throw new DllNotFoundException("openal32.dll");
}
if (frequency <= 0)
{
throw new ArgumentOutOfRangeException("frequency");
}
if (bufferSize <= 0)
{
throw new ArgumentOutOfRangeException("bufferSize");
}
// Try to open specified device. If it fails, try to open default device.
CurrentDevice = deviceName;
@ -205,7 +211,9 @@ namespace OpenTK.Audio
where TBuffer : struct
{
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
int buffer_size = BlittableValueType<TBuffer>.Stride * buffer.Length;
// This is more of a heuristic than a 100% valid check. However, it will work
@ -214,7 +222,9 @@ namespace OpenTK.Audio
// be produced with compressed sample formats (which are very rare).
// Still, this is better than no check at all.
if (sampleCount * GetSampleSize(SampleFormat) > buffer_size)
{
throw new ArgumentOutOfRangeException("sampleCount");
}
GCHandle buffer_ptr = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try { ReadSamples(buffer_ptr.AddrOfPinnedObject(), sampleCount); }
@ -320,7 +330,9 @@ namespace OpenTK.Audio
if (this.Handle != IntPtr.Zero)
{
if (this.IsRunning)
{
this.Stop();
}
Alc.CaptureCloseDevice(this.Handle);
}

View file

@ -205,13 +205,26 @@ namespace OpenTK.Audio
private void CreateContext(string device, int freq, int refresh, bool sync, bool enableEfx, MaxAuxiliarySends efxAuxiliarySends)
{
if (!AudioDeviceEnumerator.IsOpenALSupported)
{
throw new DllNotFoundException("openal32.dll");
}
if (AudioDeviceEnumerator.Version == AudioDeviceEnumerator.AlcVersion.Alc1_1 && AudioDeviceEnumerator.AvailablePlaybackDevices.Count == 0) // Alc 1.0 does not support device enumeration.
{
throw new NotSupportedException("No audio hardware is available.");
if (context_exists) throw new NotSupportedException("Multiple AudioContexts are not supported.");
if (freq < 0) throw new ArgumentOutOfRangeException("freq", freq, "Should be greater than zero.");
if (refresh < 0) throw new ArgumentOutOfRangeException("refresh", refresh, "Should be greater than zero.");
}
if (context_exists)
{
throw new NotSupportedException("Multiple AudioContexts are not supported.");
}
if (freq < 0)
{
throw new ArgumentOutOfRangeException("freq", freq, "Should be greater than zero.");
}
if (refresh < 0)
{
throw new ArgumentOutOfRangeException("refresh", refresh, "Should be greater than zero.");
}
if (!String.IsNullOrEmpty(device))
@ -292,7 +305,9 @@ namespace OpenTK.Audio
// an old OpenAL version is detect - it may affect outdated OpenAL versions different than OpenAL SI,
// but it looks like a good compromise for now.
if (AudioDeviceEnumerator.AvailablePlaybackDevices.Count > 0)
{
MakeCurrent();
}
CheckErrors();
@ -320,9 +335,11 @@ namespace OpenTK.Audio
lock (audio_context_lock)
{
if (!Alc.MakeContextCurrent(context != null ? context.context_handle : ContextHandle.Zero))
{
throw new AudioContextException(String.Format("ALC {0} error detected at {1}.",
Alc.GetError(context != null ? (IntPtr)context.context_handle : IntPtr.Zero).ToString(),
context != null ? context.ToString() : "null"));
}
}
}
@ -341,7 +358,9 @@ namespace OpenTK.Audio
lock (audio_context_lock)
{
if (available_contexts.Count == 0)
{
return false;
}
else
{
return AudioContext.CurrentContext == this;
@ -350,8 +369,14 @@ namespace OpenTK.Audio
}
set
{
if (value) AudioContext.MakeCurrent(this);
else AudioContext.MakeCurrent(null);
if (value)
{
AudioContext.MakeCurrent(this);
}
else
{
AudioContext.MakeCurrent(null);
}
}
}
@ -367,7 +392,9 @@ namespace OpenTK.Audio
public void CheckErrors()
{
if (disposed)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
new AudioDeviceErrorChecker(Device).Dispose();
}
@ -380,7 +407,9 @@ namespace OpenTK.Audio
get
{
if (disposed)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
return Alc.GetError(Device);
}
@ -400,7 +429,9 @@ namespace OpenTK.Audio
public void MakeCurrent()
{
if (disposed)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
AudioContext.MakeCurrent(this);
}
@ -416,7 +447,9 @@ namespace OpenTK.Audio
get
{
if (disposed)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
return is_processing;
}
@ -433,7 +466,9 @@ namespace OpenTK.Audio
get
{
if (disposed)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
return is_synchronized;
}
@ -461,7 +496,9 @@ namespace OpenTK.Audio
public void Process()
{
if (disposed)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
Alc.ProcessContext(this.context_handle);
IsProcessing = true;
@ -490,7 +527,9 @@ namespace OpenTK.Audio
public void Suspend()
{
if (disposed)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
Alc.SuspendContext(this.context_handle);
IsProcessing = false;
@ -504,7 +543,9 @@ namespace OpenTK.Audio
public bool SupportsExtension(string extension)
{
if (disposed)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
return Alc.IsExtensionPresent(this.Device, extension);
}
@ -517,7 +558,9 @@ namespace OpenTK.Audio
get
{
if (disposed)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
return device_name;
}
@ -537,7 +580,9 @@ namespace OpenTK.Audio
lock (audio_context_lock)
{
if (available_contexts.Count == 0)
{
return null;
}
else
{
AudioContext context;
@ -585,7 +630,9 @@ namespace OpenTK.Audio
if (!disposed)
{
if (this.IsCurrent)
{
this.IsCurrent = false;
}
if (context_handle != ContextHandle.Zero)
{
@ -594,7 +641,9 @@ namespace OpenTK.Audio
}
if (Device != IntPtr.Zero)
{
Alc.CloseDevice(Device);
}
if (manual)
{

View file

@ -112,7 +112,9 @@ namespace OpenTK.Audio
}
AlcError playback_err = Alc.GetError(dummy_device);
if (playback_err != AlcError.NoError)
{
throw new AudioContextException("Alc Error occured when querying available playback devices. " + playback_err.ToString());
}
// Get a list of all known recording devices, at least ALC_ENUMERATION_EXT is needed too
if (Version == AlcVersion.Alc1_1 && Alc.IsExtensionPresent(IntPtr.Zero, "ALC_EXT_CAPTURE"))
@ -126,18 +128,24 @@ namespace OpenTK.Audio
}
AlcError record_err = Alc.GetError(dummy_device);
if (record_err != AlcError.NoError)
{
throw new AudioContextException("Alc Error occured when querying available recording devices. " + record_err.ToString());
}
#if DEBUG
Debug.WriteLine("Found playback devices:");
foreach (string s in available_playback_devices)
{
Debug.WriteLine(s);
}
Debug.WriteLine("Default playback device: " + DefaultPlaybackDevice);
Debug.WriteLine("Found recording devices:");
foreach (string s in available_recording_devices)
{
Debug.WriteLine(s);
}
Debug.WriteLine("Default recording device: " + DefaultRecordingDevice);
#endif
@ -163,9 +171,13 @@ namespace OpenTK.Audio
// clean up the dummy context
Alc.MakeContextCurrent(ContextHandle.Zero);
if (dummy_context != ContextHandle.Zero && dummy_context.Handle != IntPtr.Zero)
{
Alc.DestroyContext(dummy_context);
}
if (dummy_device != IntPtr.Zero)
{
Alc.CloseDevice(dummy_device);
}
}
catch
{

View file

@ -39,7 +39,9 @@ namespace OpenTK.Audio
public AudioDeviceErrorChecker(IntPtr device)
{
if (device == IntPtr.Zero)
{
throw new AudioDeviceException();
}
Device = device;
}

View file

@ -461,8 +461,14 @@ namespace OpenTK.Audio.OpenAL
[CLSCompliant(false)]
public static void DeleteSources(uint[] sources)
{
if (sources == null) throw new ArgumentNullException();
if (sources.Length == 0) throw new ArgumentOutOfRangeException();
if (sources == null)
{
throw new ArgumentNullException();
}
if (sources.Length == 0)
{
throw new ArgumentOutOfRangeException();
}
DeleteBuffers(sources.Length, ref sources[0]);
}
@ -470,8 +476,14 @@ namespace OpenTK.Audio.OpenAL
/// <param name="sources">An array of source names identifying the sources to be deleted.</param>
public static void DeleteSources(int[] sources)
{
if (sources == null) throw new ArgumentNullException();
if (sources.Length == 0) throw new ArgumentOutOfRangeException();
if (sources == null)
{
throw new ArgumentNullException();
}
if (sources.Length == 0)
{
throw new ArgumentOutOfRangeException();
}
DeleteBuffers(sources.Length, ref sources[0]);
}
@ -1107,7 +1119,10 @@ namespace OpenTK.Audio.OpenAL
/// <param name="numEntries">The number of buffers to be unqueued.</param>
public static int[] SourceUnqueueBuffers(int sid, int numEntries)
{
if (numEntries <= 0) throw new ArgumentOutOfRangeException("numEntries", "Must be greater than zero.");
if (numEntries <= 0)
{
throw new ArgumentOutOfRangeException("numEntries", "Must be greater than zero.");
}
int[] buf = new int[numEntries];
SourceUnqueueBuffers(sid, numEntries, buf);
return buf;
@ -1247,8 +1262,14 @@ namespace OpenTK.Audio.OpenAL
[CLSCompliant(false)]
public static void DeleteBuffers(uint[] buffers)
{
if (buffers == null) throw new ArgumentNullException();
if (buffers.Length == 0) throw new ArgumentOutOfRangeException();
if (buffers == null)
{
throw new ArgumentNullException();
}
if (buffers.Length == 0)
{
throw new ArgumentOutOfRangeException();
}
DeleteBuffers(buffers.Length, ref buffers[0]);
}
@ -1256,8 +1277,14 @@ namespace OpenTK.Audio.OpenAL
/// <param name="buffers">Pointer to an array of buffer names identifying the buffers to be deleted.</param>
public static void DeleteBuffers(int[] buffers)
{
if (buffers == null) throw new ArgumentNullException();
if (buffers.Length == 0) throw new ArgumentOutOfRangeException();
if (buffers == null)
{
throw new ArgumentNullException();
}
if (buffers.Length == 0)
{
throw new ArgumentOutOfRangeException();
}
DeleteBuffers(buffers.Length, ref buffers[0]);
}
@ -1323,7 +1350,9 @@ namespace OpenTK.Audio.OpenAL
where TBuffer : struct
{
if (!BlittableValueType.Check(buffer))
{
throw new ArgumentException("buffer");
}
GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try { BufferData(bid, format, handle.AddrOfPinnedObject(), size, freq); }

View file

@ -141,7 +141,10 @@ namespace OpenTK.Audio.OpenAL
/// </remarks>
public int[] GenEffects(int n)
{
if (n <= 0) throw new ArgumentOutOfRangeException("n", "Must be higher than 0.");
if (n <= 0)
{
throw new ArgumentOutOfRangeException("n", "Must be higher than 0.");
}
int[] effects = new int[n];
GenEffects(n, out effects[0]);
return effects;
@ -216,7 +219,10 @@ namespace OpenTK.Audio.OpenAL
/// <param name="effects">Pointer to n Effect object identifiers.</param>
public void DeleteEffects(int[] effects)
{
if (effects == null) throw new ArgumentNullException("effects");
if (effects == null)
{
throw new ArgumentNullException("effects");
}
DeleteEffects(effects.Length, ref effects[0]);
}
@ -225,7 +231,10 @@ namespace OpenTK.Audio.OpenAL
[CLSCompliant(false)]
public void DeleteEffects(uint[] effects)
{
if (effects == null) throw new ArgumentNullException("effects");
if (effects == null)
{
throw new ArgumentNullException("effects");
}
DeleteEffects(effects.Length, ref effects[0]);
}
@ -516,7 +525,10 @@ namespace OpenTK.Audio.OpenAL
public int[] GenFilters(int n)
{
if (n <= 0) throw new ArgumentOutOfRangeException("n", "Must be higher than 0.");
if (n <= 0)
{
throw new ArgumentOutOfRangeException("n", "Must be higher than 0.");
}
int[] filters = new int[n];
GenFilters(filters.Length, out filters[0]);
return filters;
@ -587,7 +599,10 @@ namespace OpenTK.Audio.OpenAL
[CLSCompliant(false)]
public void DeleteFilters(uint[] filters)
{
if (filters == null) throw new ArgumentNullException("filters");
if (filters == null)
{
throw new ArgumentNullException("filters");
}
DeleteFilters(filters.Length, ref filters[0]);
}
@ -595,7 +610,10 @@ namespace OpenTK.Audio.OpenAL
/// <param name="filters">Pointer to an filter name/handle identifying the Filter Object to be deleted.</param>
public void DeleteFilters(int[] filters)
{
if (filters == null) throw new ArgumentNullException("filters");
if (filters == null)
{
throw new ArgumentNullException("filters");
}
DeleteFilters(filters.Length, ref filters[0]);
}
@ -817,7 +835,10 @@ namespace OpenTK.Audio.OpenAL
/// <returns>Pointer addressing sufficient memory to store n Effect Slot object identifiers.</returns>
public int[] GenAuxiliaryEffectSlots(int n)
{
if (n <= 0) throw new ArgumentOutOfRangeException("n", "Must be higher than 0.");
if (n <= 0)
{
throw new ArgumentOutOfRangeException("n", "Must be higher than 0.");
}
int[] slots = new int[n];
GenAuxiliaryEffectSlots(slots.Length, out slots[0]);
return slots;
@ -885,7 +906,10 @@ namespace OpenTK.Audio.OpenAL
/// <param name="slots">Pointer to n Effect Slot object identifiers.</param>
public void DeleteAuxiliaryEffectSlots(int[] slots)
{
if (slots == null) throw new ArgumentNullException("slots");
if (slots == null)
{
throw new ArgumentNullException("slots");
}
DeleteAuxiliaryEffectSlots(slots.Length, ref slots[0]);
}
@ -894,7 +918,10 @@ namespace OpenTK.Audio.OpenAL
[CLSCompliant(false)]
public void DeleteAuxiliaryEffectSlots(uint[] slots)
{
if (slots == null) throw new ArgumentNullException("slots");
if (slots == null)
{
throw new ArgumentNullException("slots");
}
DeleteAuxiliaryEffectSlots(slots.Length, ref slots[0]);
}
@ -1081,7 +1108,9 @@ namespace OpenTK.Audio.OpenAL
IsInitialized = false;
if (AudioContext.CurrentContext == null)
{
throw new InvalidOperationException("AL.LoadAll() needs a current AudioContext.");
}
if (!AudioContext.CurrentContext.SupportsExtension("ALC_EXT_EFX"))
{

View file

@ -45,7 +45,9 @@ namespace OpenTK.Audio.OpenAL
{ // Query if Extension supported and retrieve Tokens/Pointers if it is.
IsInitialized = false;
if (AL.IsExtensionPresent("EAX-RAM") == false)
{
return;
}
AL_EAX_RAM_SIZE = AL.GetEnumValue("AL_EAX_RAM_SIZE");
AL_EAX_RAM_FREE = AL.GetEnumValue("AL_EAX_RAM_FREE");
@ -150,9 +152,13 @@ namespace OpenTK.Audio.OpenAL
int tempresult = Imported_GetBufferMode(buffer, IntPtr.Zero); // IntPtr.Zero due to the parameter being unused/reserved atm
if (tempresult == AL_STORAGE_ACCESSIBLE)
{
return XRamStorage.Accessible;
}
if (tempresult == AL_STORAGE_HARDWARE)
{
return XRamStorage.Hardware;
}
// default:
return XRamStorage.Automatic;
}

View file

@ -83,9 +83,13 @@ namespace OpenTK
protected static void MarshalPtrToStringBuilder(IntPtr ptr, StringBuilder sb)
{
if (ptr == IntPtr.Zero)
{
throw new ArgumentException("ptr");
}
if (sb == null)
{
throw new ArgumentNullException("sb");
}
sb.Length = 0;
for (int i = 0; ; i++)

View file

@ -80,7 +80,9 @@ namespace OpenTK
public static bool Check(Type type)
{
if (!CheckStructLayoutAttribute(type))
{
Debug.Print("Warning: type {0} does not specify a StructLayoutAttribute with Pack=1. The memory layout of the struct may change between platforms.", type.Name);
}
return CheckType(type);
}
@ -91,17 +93,23 @@ namespace OpenTK
{
//Debug.Print("Checking type {0} (size: {1} bytes).", type.Name, Marshal.SizeOf(type));
if (type.IsPrimitive)
{
return true;
}
if (!type.IsValueType)
{
return false;
}
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
Debug.Indent();
foreach (FieldInfo field in fields)
{
if (!CheckType(field.FieldType))
{
return false;
}
}
Debug.Unindent();
@ -117,7 +125,9 @@ namespace OpenTK
if ((attr == null) ||
(attr != null && attr.Length > 0 && attr[0].Value != LayoutKind.Explicit && attr[0].Pack != 1))
{
return false;
}
return true;
}
@ -196,7 +206,9 @@ namespace OpenTK
public static int StrideOf<T>(T type)
{
if (!Check(type))
{
throw new ArgumentException("type");
}
return BlittableValueType<T>.Stride;
}
@ -212,7 +224,9 @@ namespace OpenTK
public static int StrideOf<T>(T[] type)
{
if (!Check(type))
{
throw new ArgumentException("type");
}
return BlittableValueType<T>.Stride;
}
@ -228,7 +242,9 @@ namespace OpenTK
public static int StrideOf<T>(T[,] type)
{
if (!Check(type))
{
throw new ArgumentException("type");
}
return BlittableValueType<T>.Stride;
}
@ -244,7 +260,9 @@ namespace OpenTK
public static int StrideOf<T>(T[, ,] type)
{
if (!Check(type))
{
throw new ArgumentException("type");
}
return BlittableValueType<T>.Stride;
}

View file

@ -48,7 +48,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (obj is ContextHandle)
{
return this.Equals((ContextHandle)obj);
}
return false;
}

View file

@ -122,13 +122,17 @@ namespace OpenTK
internal set
{
if (value && primary_display != null && primary_display != this)
{
primary_display.IsPrimary = false;
}
lock (display_lock)
{
primary = value;
if (value)
{
primary_display = this;
}
}
}
}
@ -153,11 +157,17 @@ namespace OpenTK
{
DisplayResolution resolution = FindResolution(width, height, bitsPerPixel, refreshRate);
if (resolution == null)
{
resolution = FindResolution(width, height, bitsPerPixel, 0);
}
if (resolution == null)
{
resolution = FindResolution(width, height, 0, 0);
}
if (resolution == null)
{
return current_resolution;
}
return resolution;
}
@ -181,21 +191,30 @@ namespace OpenTK
public void ChangeResolution(DisplayResolution resolution)
{
if (resolution == null)
{
this.RestoreResolution();
}
if (resolution == current_resolution)
{
return;
}
//effect.FadeOut();
if (implementation.TryChangeResolution(this, resolution))
{
if (OriginalResolution == null)
{
OriginalResolution = current_resolution;
}
current_resolution = resolution;
}
else throw new Graphics.GraphicsModeException(String.Format("Device {0}: Failed to change resolution to {1}.",
else
{
throw new Graphics.GraphicsModeException(String.Format("Device {0}: Failed to change resolution to {1}.",
this, resolution));
}
//effect.FadeIn();
}
@ -224,7 +243,10 @@ namespace OpenTK
current_resolution = OriginalResolution;
OriginalResolution = null;
}
else throw new Graphics.GraphicsModeException(String.Format("Device {0}: Failed to restore resolution.", this));
else
{
throw new Graphics.GraphicsModeException(String.Format("Device {0}: Failed to restore resolution.", this));
}
//effect.FadeIn();
}

View file

@ -25,10 +25,22 @@ namespace OpenTK
internal DisplayResolution(int x, int y, int width, int height, int bitsPerPixel, float refreshRate)
{
// Refresh rate may be zero, since this information may not be available on some platforms.
if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
if (bitsPerPixel <= 0) throw new ArgumentOutOfRangeException("bitsPerPixel", "Must be greater than zero.");
if (refreshRate < 0) throw new ArgumentOutOfRangeException("refreshRate", "Must be greater than, or equal to zero.");
if (width <= 0)
{
throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
}
if (height <= 0)
{
throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
}
if (bitsPerPixel <= 0)
{
throw new ArgumentOutOfRangeException("bitsPerPixel", "Must be greater than zero.");
}
if (refreshRate < 0)
{
throw new ArgumentOutOfRangeException("refreshRate", "Must be greater than, or equal to zero.");
}
this.bounds = new Rectangle(x, y, width, height);
this.BitsPerPixel = bitsPerPixel;
@ -112,7 +124,10 @@ namespace OpenTK
/// <returns>True if the System.Object is an equal DisplayResolution; false otherwise.</returns>
public override bool Equals(object obj)
{
if (obj == null) return false;
if (obj == null)
{
return false;
}
if (this.GetType() == obj.GetType())
{
DisplayResolution res = (DisplayResolution)obj;
@ -144,10 +159,14 @@ namespace OpenTK
public static bool operator== (DisplayResolution left, DisplayResolution right)
{
if (((object)left) == null && ((object)right) == null)
{
return true;
}
else if ((((object)left) == null && ((object)right) != null) ||
(((object)left) != null && ((object)right) == null))
{
return false;
}
return left.Equals(right);
}

View file

@ -60,7 +60,9 @@ namespace OpenTK
internal set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException();
}
elapsed = value;
}
}

View file

@ -310,11 +310,15 @@ namespace OpenTK
try
{
if (updates_per_second < 0.0 || updates_per_second > 200.0)
{
throw new ArgumentOutOfRangeException("updates_per_second", updates_per_second,
"Parameter should be inside the range [0.0, 200.0]");
"Parameter should be inside the range [0.0, 200.0]");
}
if (frames_per_second < 0.0 || frames_per_second > 200.0)
{
throw new ArgumentOutOfRangeException("frames_per_second", frames_per_second,
"Parameter should be inside the range [0.0, 200.0]");
"Parameter should be inside the range [0.0, 200.0]");
}
if (updates_per_second != 0)
{
@ -342,9 +346,13 @@ namespace OpenTK
{
ProcessEvents();
if (Exists && !IsExiting)
{
DispatchUpdateAndRenderFrame(this, EventArgs.Empty);
}
else
{
return;
}
}
}
finally
@ -494,7 +502,9 @@ namespace OpenTK
{
EnsureUndisposed();
if (render_period == 0.0)
{
return 1.0;
}
return 1.0 / render_period;
}
}
@ -541,7 +551,9 @@ namespace OpenTK
{
EnsureUndisposed();
if (TargetRenderPeriod == 0.0)
{
return 0.0;
}
return 1.0 / TargetRenderPeriod;
}
set
@ -555,7 +567,10 @@ namespace OpenTK
{
TargetRenderPeriod = 1.0 / value;
}
else Debug.Print("Target render frequency clamped to {0}Hz.", MaxFrequency);
else
{
Debug.Print("Target render frequency clamped to {0}Hz.", MaxFrequency);
}
}
}
@ -584,7 +599,10 @@ namespace OpenTK
{
target_render_period = value;
}
else Debug.Print("Target render period clamped to 1.0 seconds.");
else
{
Debug.Print("Target render period clamped to 1.0 seconds.");
}
}
}
@ -601,7 +619,9 @@ namespace OpenTK
{
EnsureUndisposed();
if (TargetUpdatePeriod == 0.0)
{
return 0.0;
}
return 1.0 / TargetUpdatePeriod;
}
set
@ -615,7 +635,10 @@ namespace OpenTK
{
TargetUpdatePeriod = 1.0 / value;
}
else Debug.Print("Target render frequency clamped to {0}Hz.", MaxFrequency);
else
{
Debug.Print("Target render frequency clamped to {0}Hz.", MaxFrequency);
}
}
}
@ -644,7 +667,10 @@ namespace OpenTK
{
target_update_period = value;
}
else Debug.Print("Target update period clamped to 1.0 seconds.");
else
{
Debug.Print("Target update period clamped to 1.0 seconds.");
}
}
}
@ -657,7 +683,9 @@ namespace OpenTK
{
EnsureUndisposed();
if (update_period == 0.0)
{
return 1.0;
}
return 1.0 / update_period;
}
}
@ -744,7 +772,9 @@ namespace OpenTK
Debug.Print("Updating Context after setting WindowState to {0}", value);
if (Context != null)
{
Context.Update(WindowInfo);
}
}
}
/// <summary>
@ -823,11 +853,26 @@ namespace OpenTK
OnLoad(e);
}
private void OnRenderFrameInternal(FrameEventArgs e) { if (Exists && !isExiting) OnRenderFrame(e); }
private void OnRenderFrameInternal(FrameEventArgs e)
{
if (Exists && !isExiting)
{
OnRenderFrame(e);
}
}
private void OnUnloadInternal(EventArgs e) { OnUnload(e); }
private void OnUnloadInternal(EventArgs e)
{
OnUnload(e);
}
private void OnUpdateFrameInternal(FrameEventArgs e) { if (Exists && !isExiting) OnUpdateFrame(e); }
private void OnUpdateFrameInternal(FrameEventArgs e)
{
if (Exists && !isExiting)
{
OnUpdateFrame(e);
}
}
private void OnWindowInfoChangedInternal(EventArgs e)
{

View file

@ -159,7 +159,9 @@ namespace OpenTK.Graphics
public override bool Equals(object obj)
{
if (!(obj is Color4))
{
return false;
}
return Equals((Color4)obj);
}

View file

@ -45,7 +45,9 @@ namespace OpenTK.Graphics
public ColorFormat(int bpp)
{
if (bpp < 0)
{
throw new ArgumentOutOfRangeException("bpp", "Must be greater or equal to zero.");
}
red = green = blue = alpha = 0;
BitsPerPixel = bpp;
IsIndexed = false;
@ -96,7 +98,9 @@ namespace OpenTK.Graphics
public ColorFormat(int red, int green, int blue, int alpha)
{
if (red < 0 || green < 0 || blue < 0 || alpha < 0)
{
throw new ArgumentOutOfRangeException("Arguments must be greater or equal to zero.");
}
this.red = (byte)red;
this.green = (byte)green;
this.blue = (byte)blue;
@ -104,7 +108,9 @@ namespace OpenTK.Graphics
this.BitsPerPixel = red + green + blue + alpha;
this.IsIndexed = false;
if (this.BitsPerPixel < 15 && this.BitsPerPixel != 0)
{
this.IsIndexed = true;
}
}
/// <summary>Gets the bits per pixel for the Red channel.</summary>
@ -154,10 +160,14 @@ namespace OpenTK.Graphics
{
int result = BitsPerPixel.CompareTo(other.BitsPerPixel);
if (result != 0)
{
return result;
}
result = IsIndexed.CompareTo(other.IsIndexed);
if (result != 0)
{
return result;
}
result = Alpha.CompareTo(other.Alpha);
return result;
}

View file

@ -52,13 +52,17 @@ namespace OpenTK.Graphics.ES10
public ErrorHelper(IGraphicsContext context)
{
if (context == null)
{
throw new GraphicsContextMissingException();
}
Context = (GraphicsContext)context;
lock (SyncRoot)
{
if (!ContextErrors.ContainsKey(Context))
{
ContextErrors.Add(Context, new List<ErrorCode>());
}
}
ResetErrors();
}
@ -101,7 +105,9 @@ namespace OpenTK.Graphics.ES10
sb.Append(", ");
}
else
{
break;
}
}
sb.Remove(sb.Length - 2, 2); // Remove the last comma

View file

@ -52,13 +52,17 @@ namespace OpenTK.Graphics.ES11
public ErrorHelper(IGraphicsContext context)
{
if (context == null)
{
throw new GraphicsContextMissingException();
}
Context = (GraphicsContext)context;
lock (SyncRoot)
{
if (!ContextErrors.ContainsKey(Context))
{
ContextErrors.Add(Context, new List<ErrorCode>());
}
}
ResetErrors();
}
@ -101,7 +105,9 @@ namespace OpenTK.Graphics.ES11
sb.Append(", ");
}
else
{
break;
}
}
sb.Remove(sb.Length - 2, 2); // Remove the last comma

View file

@ -52,13 +52,17 @@ namespace OpenTK.Graphics.ES20
public ErrorHelper(IGraphicsContext context)
{
if (context == null)
{
throw new GraphicsContextMissingException();
}
Context = (GraphicsContext)context;
lock (SyncRoot)
{
if (!ContextErrors.ContainsKey(Context))
{
ContextErrors.Add(Context, new List<ErrorCode>());
}
}
ResetErrors();
}
@ -101,7 +105,9 @@ namespace OpenTK.Graphics.ES20
sb.Append(", ");
}
else
{
break;
}
}
sb.Remove(sb.Length - 2, 2); // Remove the last comma

View file

@ -302,7 +302,9 @@ namespace OpenTK.Graphics.ES20
unsafe
{
fixed (Vector2* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -311,7 +313,9 @@ namespace OpenTK.Graphics.ES20
unsafe
{
fixed (Vector3* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -320,7 +324,9 @@ namespace OpenTK.Graphics.ES20
unsafe
{
fixed (Vector4* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -329,7 +335,9 @@ namespace OpenTK.Graphics.ES20
unsafe
{
fixed (Matrix4* ptr = &matrix)
{
GetFloat(pname, (float*)ptr);
}
}
}

View file

@ -52,13 +52,17 @@ namespace OpenTK.Graphics.ES30
public ErrorHelper(IGraphicsContext context)
{
if (context == null)
{
throw new GraphicsContextMissingException();
}
Context = (GraphicsContext)context;
lock (SyncRoot)
{
if (!ContextErrors.ContainsKey(Context))
{
ContextErrors.Add(Context, new List<ErrorCode>());
}
}
ResetErrors();
}
@ -101,7 +105,9 @@ namespace OpenTK.Graphics.ES30
sb.Append(", ");
}
else
{
break;
}
}
sb.Remove(sb.Length - 2, 2); // Remove the last comma

View file

@ -297,7 +297,9 @@ namespace OpenTK.Graphics.ES30
unsafe
{
fixed (Vector2* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -306,7 +308,9 @@ namespace OpenTK.Graphics.ES30
unsafe
{
fixed (Vector3* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -315,7 +319,9 @@ namespace OpenTK.Graphics.ES30
unsafe
{
fixed (Vector4* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -324,7 +330,9 @@ namespace OpenTK.Graphics.ES30
unsafe
{
fixed (Matrix4* ptr = &matrix)
{
GetFloat(pname, (float*)ptr);
}
}
}

View file

@ -57,7 +57,9 @@ namespace OpenTK.Graphics
{
var context = GraphicsContext.CurrentContext as IGraphicsContextInternal;
if (context == null)
{
throw new GraphicsContextMissingException();
}
return context != null ? context.GetAddress(funcname) : IntPtr.Zero;
}
@ -71,7 +73,9 @@ namespace OpenTK.Graphics
IGraphicsContext context = GraphicsContext.CurrentContext;
if (context == null)
{
throw new GraphicsContextMissingException();
}
IGraphicsContextInternal context_internal = context as IGraphicsContextInternal;
unsafe

View file

@ -110,15 +110,27 @@ namespace OpenTK.Graphics
{
bool designMode = false;
if (mode == null && window == null)
{
designMode = true;
else if (mode == null) throw new ArgumentNullException("mode", "Must be a valid GraphicsMode.");
else if (window == null) throw new ArgumentNullException("window", "Must point to a valid window.");
}
else if (mode == null)
{
throw new ArgumentNullException("mode", "Must be a valid GraphicsMode.");
}
else if (window == null)
{
throw new ArgumentNullException("window", "Must point to a valid window.");
}
// Silently ignore invalid major and minor versions.
if (major <= 0)
{
major = 1;
}
if (minor < 0)
{
minor = 0;
}
// Angle needs an embedded context
const GraphicsContextFlags useAngleFlag = GraphicsContextFlags.Angle
@ -209,7 +221,9 @@ namespace OpenTK.Graphics
public GraphicsContext(ContextHandle handle, GetAddressDelegate getAddress, GetCurrentContextDelegate getCurrent)
{
if (getAddress == null || getCurrent == null)
{
throw new ArgumentNullException();
}
// Make sure OpenTK has been initialized.
// Fixes https://github.com/opentk/opentk/issues/52
@ -334,7 +348,9 @@ namespace OpenTK.Graphics
// making this return null even if another valid context exists.
// The workaround is to simply ignore null targets.
if (target != null)
{
return target;
}
}
}
return null;
@ -347,7 +363,9 @@ namespace OpenTK.Graphics
public static void Assert()
{
if (GraphicsContext.CurrentContext == null)
{
throw new GraphicsContextMissingException();
}
}
internal static GetCurrentContextDelegate GetCurrentContext;
@ -377,7 +395,9 @@ namespace OpenTK.Graphics
{
ContextHandle handle = CurrentContextHandle;
if (handle.Handle != IntPtr.Zero)
{
return (IGraphicsContext)available_contexts[handle];
}
}
return null;
}
@ -483,7 +503,9 @@ namespace OpenTK.Graphics
public void LoadAll()
{
if (GraphicsContext.CurrentContext != this)
{
throw new GraphicsContextException();
}
implementation.LoadAll();
}
@ -578,7 +600,9 @@ namespace OpenTK.Graphics
{
Debug.Print("Disposing context {0}.", (this as IGraphicsContextInternal).Context.ToString());
if (implementation != null)
{
implementation.Dispose();
}
}
else
{

View file

@ -53,9 +53,13 @@ namespace OpenTK.Graphics
set
{
if (value && SwapInterval <= 0)
{
SwapInterval = 1;
}
else if (!value && SwapInterval > 0)
{
SwapInterval = 0;
}
}
}

View file

@ -28,10 +28,22 @@ namespace OpenTK.Graphics
internal GraphicsMode(IntPtr? index, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum,
int buffers, bool stereo)
{
if (depth < 0) throw new ArgumentOutOfRangeException("depth", "Must be greater than, or equal to zero.");
if (stencil < 0) throw new ArgumentOutOfRangeException("stencil", "Must be greater than, or equal to zero.");
if (buffers < 0) throw new ArgumentOutOfRangeException("buffers", "Must be greater than, or equal to zero.");
if (samples < 0) throw new ArgumentOutOfRangeException("samples", "Must be greater than, or equal to zero.");
if (depth < 0)
{
throw new ArgumentOutOfRangeException("depth", "Must be greater than, or equal to zero.");
}
if (stencil < 0)
{
throw new ArgumentOutOfRangeException("stencil", "Must be greater than, or equal to zero.");
}
if (buffers < 0)
{
throw new ArgumentOutOfRangeException("buffers", "Must be greater than, or equal to zero.");
}
if (samples < 0)
{
throw new ArgumentOutOfRangeException("samples", "Must be greater than, or equal to zero.");
}
this.Index = index;
this.ColorFormat = color;

View file

@ -35,22 +35,34 @@ namespace OpenTK.Graphics
{
int result = x.ColorFormat.CompareTo(y.ColorFormat);
if (result != 0)
{
return result;
}
result = x.Depth.CompareTo(y.Depth);
if (result != 0)
{
return result;
}
result = x.Stencil.CompareTo(y.Stencil);
if (result != 0)
{
return result;
}
result = x.Samples.CompareTo(y.Samples);
if (result != 0)
{
return result;
}
result = x.Stereo.CompareTo(y.Stereo);
if (result != 0)
{
return result;
}
result = x.Buffers.CompareTo(y.Buffers);
if (result != 0)
{
return result;
}
return x.AccumulatorFormat.CompareTo(y.AccumulatorFormat);
}
}

View file

@ -52,13 +52,17 @@ namespace OpenTK.Graphics.OpenGL
public ErrorHelper(IGraphicsContext context)
{
if (context == null)
{
throw new GraphicsContextMissingException();
}
Context = (GraphicsContext)context;
lock (SyncRoot)
{
if (!ContextErrors.ContainsKey(Context))
{
ContextErrors.Add(Context, new List<ErrorCode>());
}
}
ResetErrors();
}
@ -101,7 +105,9 @@ namespace OpenTK.Graphics.OpenGL
sb.Append(", ");
}
else
{
break;
}
}
sb.Remove(sb.Length - 2, 2); // Remove the last comma

View file

@ -2628,7 +2628,9 @@ namespace OpenTK.Graphics.OpenGL
unsafe
{
fixed (Vector2* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -2647,7 +2649,9 @@ namespace OpenTK.Graphics.OpenGL
unsafe
{
fixed (Vector3* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -2666,7 +2670,9 @@ namespace OpenTK.Graphics.OpenGL
unsafe
{
fixed (Vector4* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -2685,7 +2691,9 @@ namespace OpenTK.Graphics.OpenGL
unsafe
{
fixed (Matrix4* ptr = &matrix)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -2704,7 +2712,9 @@ namespace OpenTK.Graphics.OpenGL
unsafe
{
fixed (Vector2d* ptr = &vector)
{
GetDouble(pname, (double*)ptr);
}
}
}
@ -2723,7 +2733,9 @@ namespace OpenTK.Graphics.OpenGL
unsafe
{
fixed (Vector3d* ptr = &vector)
{
GetDouble(pname, (double*)ptr);
}
}
}
@ -2742,7 +2754,9 @@ namespace OpenTK.Graphics.OpenGL
unsafe
{
fixed (Vector4d* ptr = &vector)
{
GetDouble(pname, (double*)ptr);
}
}
}
@ -2761,7 +2775,9 @@ namespace OpenTK.Graphics.OpenGL
unsafe
{
fixed (Matrix4d* ptr = &matrix)
{
GetDouble(pname, (double*)ptr);
}
}
}

View file

@ -52,13 +52,17 @@ namespace OpenTK.Graphics.OpenGL4
public ErrorHelper(IGraphicsContext context)
{
if (context == null)
{
throw new GraphicsContextMissingException();
}
Context = (GraphicsContext)context;
lock (SyncRoot)
{
if (!ContextErrors.ContainsKey(Context))
{
ContextErrors.Add(Context, new List<ErrorCode>());
}
}
ResetErrors();
}
@ -101,7 +105,9 @@ namespace OpenTK.Graphics.OpenGL4
sb.Append(", ");
}
else
{
break;
}
}
sb.Remove(sb.Length - 2, 2); // Remove the last comma

View file

@ -373,7 +373,9 @@ namespace OpenTK.Graphics.OpenGL4
unsafe
{
fixed (Vector2* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -382,7 +384,9 @@ namespace OpenTK.Graphics.OpenGL4
unsafe
{
fixed (Vector3* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -391,7 +395,9 @@ namespace OpenTK.Graphics.OpenGL4
unsafe
{
fixed (Vector4* ptr = &vector)
{
GetFloat(pname, (float*)ptr);
}
}
}
@ -400,7 +406,9 @@ namespace OpenTK.Graphics.OpenGL4
unsafe
{
fixed (Matrix4* ptr = &matrix)
{
GetFloat(pname, (float*)ptr);
}
}
}

View file

@ -59,7 +59,9 @@ namespace OpenTK.Input
public static GamePadCapabilities GetCapabilities(int index)
{
if (index < 0)
{
throw new IndexOutOfRangeException();
}
return driver.GetCapabilities(index);
}

View file

@ -171,29 +171,53 @@ namespace OpenTK.Input
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (A == ButtonState.Pressed)
{
sb.Append("A");
}
if (B == ButtonState.Pressed)
{
sb.Append("B");
}
if (X == ButtonState.Pressed)
{
sb.Append("X");
}
if (Y == ButtonState.Pressed)
{
sb.Append("Y");
}
if (Back == ButtonState.Pressed)
{
sb.Append("Bk");
}
if (Start == ButtonState.Pressed)
{
sb.Append("St");
}
if (BigButton == ButtonState.Pressed)
{
sb.Append("Gd");
}
if (Back == ButtonState.Pressed)
{
sb.Append("Bk");
}
if (LeftShoulder == ButtonState.Pressed)
{
sb.Append("L");
}
if (RightShoulder == ButtonState.Pressed)
{
sb.Append("R");
}
if (LeftStick == ButtonState.Pressed)
{
sb.Append("Ls");
}
if (RightStick == ButtonState.Pressed)
{
sb.Append("Rs");
}
return sb.ToString();
}

View file

@ -44,14 +44,20 @@ namespace OpenTK.Input
internal JoystickCapabilities(int axis_count, int button_count, int hat_count, bool is_connected)
{
if (axis_count < 0 || axis_count > JoystickState.MaxAxes)
{
Debug.Print("[{0}] Axis count {1} out of range (0, {2})",
typeof(JoystickCapabilities).Name, axis_count, JoystickState.MaxAxes);
}
if (button_count < 0 || button_count > JoystickState.MaxButtons)
{
Debug.Print("[{0}] Button count {1} out of range (0, {2})",
typeof(JoystickCapabilities).Name, button_count, JoystickState.MaxButtons);
}
if (hat_count < 0 || hat_count > JoystickState.MaxHats)
{
Debug.Print("[{0}] Hat count {1} out of range (0, {2})",
typeof(JoystickCapabilities).Name, hat_count, JoystickState.MaxHats);
}
axis_count = MathHelper.Clamp(axis_count, 0, JoystickState.MaxAxes);
button_count = MathHelper.Clamp(button_count, 0, JoystickState.MaxButtons);

View file

@ -39,10 +39,14 @@ namespace OpenTK.Input
internal JoystickDevice(int id, int axes, int buttons)
{
if (axes < 0)
{
throw new ArgumentOutOfRangeException("axes");
}
if (buttons < 0)
{
throw new ArgumentOutOfRangeException("buttons");
}
Id = id;
Axis = new JoystickAxisCollection(axes);
@ -112,9 +116,13 @@ namespace OpenTK.Input
button_args.Button = button;
Button[button] = button_args.Pressed = @value;
if (@value)
{
ButtonDown(this, button_args);
}
else
{
ButtonUp(this, button_args);
}
}
}
}
@ -211,7 +219,9 @@ namespace OpenTK.Input
internal JoystickButtonCollection(int numButtons)
{
if (numButtons < 0)
{
throw new ArgumentOutOfRangeException("numButtons");
}
button_state = new bool[numButtons];
}
@ -246,7 +256,9 @@ namespace OpenTK.Input
internal JoystickAxisCollection(int numAxes)
{
if (numAxes < 0)
{
throw new ArgumentOutOfRangeException("numAxes");
}
axis_state = new float[numAxes];
}

View file

@ -204,7 +204,9 @@ namespace OpenTK.Input
{
int index = axis;
if (index < 0 || index >= MaxAxes)
{
throw new ArgumentOutOfRangeException("axis");
}
unsafe
{
@ -223,7 +225,9 @@ namespace OpenTK.Input
internal void SetButton(int button, bool value)
{
if (button < 0 || button >= MaxButtons)
{
throw new ArgumentOutOfRangeException("button");
}
if (value)
{

View file

@ -59,7 +59,9 @@ namespace OpenTK.Input
public static KeyboardState GetState(int index)
{
if (index < 0)
{
throw new ArgumentOutOfRangeException("index");
}
lock (SyncRoot)
{

View file

@ -215,7 +215,9 @@ namespace OpenTK.Input
{
int hashcode = 0;
for (int i = 0; i < NumInts; i++)
{
hashcode ^= (k + i)->GetHashCode();
}
return hashcode;
}
}
@ -277,7 +279,9 @@ namespace OpenTK.Input
fixed (int* k1 = Keys)
{
for (int i = 0; i < NumInts; i++)
{
*(k1 + i) |= *(k2 + i);
}
}
}
IsConnected |= other.IsConnected;
@ -291,7 +295,9 @@ namespace OpenTK.Input
private static void ValidateOffset(int offset)
{
if (offset < 0 || offset >= NumInts * IntSize)
{
throw new ArgumentOutOfRangeException();
}
}
/// <summary>
@ -308,7 +314,9 @@ namespace OpenTK.Input
fixed (int* k1 = Keys)
{
for (int i = 0; equal && i < NumInts; i++)
{
equal &= *(k1 + i) == *(k2 + i);
}
}
}
return equal;

View file

@ -71,7 +71,9 @@ namespace OpenTK.Input
public static MouseState GetState(int index)
{
if (index < 0)
{
throw new ArgumentOutOfRangeException("index");
}
lock (SyncRoot)
{

View file

@ -78,7 +78,9 @@ namespace OpenTK.Input
internal void SetButton(MouseButton button, ButtonState state)
{
if (button < 0 || button > MouseButton.LastButton)
{
throw new ArgumentOutOfRangeException();
}
switch (state)
{
@ -95,7 +97,9 @@ namespace OpenTK.Input
internal ButtonState GetButton(MouseButton button)
{
if (button < 0 || button > MouseButton.LastButton)
{
throw new ArgumentOutOfRangeException();
}
return
state.ReadBit((int)button) ?

View file

@ -51,9 +51,13 @@ namespace OpenTK.Input
internal set
{
if (value)
{
EnableBit((int)button);
}
else
{
DisableBit((int)button);
}
}
}
@ -322,7 +326,9 @@ namespace OpenTK.Input
private static void ValidateOffset(int offset)
{
if (offset < 0 || offset >= 16)
{
throw new ArgumentOutOfRangeException("offset");
}
}
/// <summary>

View file

@ -48,7 +48,9 @@ namespace OpenTK
public BezierCurve(IEnumerable<Vector2> points)
{
if (points == null)
{
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
}
this.points = new List<Vector2>(points);
this.Parallel = 0.0f;
@ -61,7 +63,9 @@ namespace OpenTK
public BezierCurve(params Vector2[] points)
{
if (points == null)
{
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
}
this.points = new List<Vector2>(points);
this.Parallel = 0.0f;
@ -75,7 +79,9 @@ namespace OpenTK
public BezierCurve(float parallel, params Vector2[] points)
{
if (points == null)
{
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
}
this.Parallel = parallel;
this.points = new List<Vector2>(points);
@ -89,7 +95,9 @@ namespace OpenTK
public BezierCurve(float parallel, IEnumerable<Vector2> points)
{
if (points == null)
{
throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures.");
}
this.Parallel = parallel;
this.points = new List<Vector2>(points);
@ -198,14 +206,20 @@ namespace OpenTK
}
if (parallel == 0.0f)
{
return r;
}
Vector2 perpendicular = new Vector2();
if (t != 0.0f)
{
perpendicular = r - BezierCurve.CalculatePointOfDerivative(points, t);
}
else
{
perpendicular = points[1] - points[0];
}
return r + Vector2.Normalize(perpendicular).PerpendicularRight * parallel;
}

View file

@ -96,14 +96,20 @@ namespace OpenTK
+ EndAnchor.Y * t * t * t;
if (Parallel == 0.0f)
{
return r;
}
Vector2 perpendicular = new Vector2();
if (t == 0.0f)
{
perpendicular = FirstControlPoint - StartAnchor;
}
else
{
perpendicular = r - CalculatePointOfDerivative(t);
}
return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel;
}

View file

@ -85,14 +85,20 @@ namespace OpenTK
r.Y = (c * c * StartAnchor.Y) + (2 * t * c * ControlPoint.Y) + (t * t * EndAnchor.Y);
if (Parallel == 0.0f)
{
return r;
}
Vector2 perpendicular = new Vector2();
if (t == 0.0f)
{
perpendicular = ControlPoint - StartAnchor;
}
else
{
perpendicular = r - CalculatePointOfDerivative(t);
}
return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel;
}

View file

@ -114,13 +114,28 @@ namespace OpenTK
if (throwOnError)
{
// handle cases that cause overflow rather than silently ignoring it
if (f > Half.MaxValue) throw new ArithmeticException("Half: Positive maximum value exceeded.");
if (f < -Half.MaxValue) throw new ArithmeticException("Half: Negative minimum value exceeded.");
if (f > Half.MaxValue)
{
throw new ArithmeticException("Half: Positive maximum value exceeded.");
}
if (f < -Half.MaxValue)
{
throw new ArithmeticException("Half: Negative minimum value exceeded.");
}
// handle cases that make no sense
if (Single.IsNaN(f)) throw new ArithmeticException("Half: Input is not a number (NaN).");
if (Single.IsPositiveInfinity(f)) throw new ArithmeticException("Half: Input is positive infinity.");
if (Single.IsNegativeInfinity(f)) throw new ArithmeticException("Half: Input is negative infinity.");
if (Single.IsNaN(f))
{
throw new ArithmeticException("Half: Input is not a number (NaN).");
}
if (Single.IsPositiveInfinity(f))
{
throw new ArithmeticException("Half: Input is positive infinity.");
}
if (Single.IsNegativeInfinity(f))
{
throw new ArithmeticException("Half: Input is negative infinity.");
}
}
}
@ -219,7 +234,10 @@ namespace OpenTK
}
// exponent overflow
if (exponent > 30) throw new ArithmeticException("Half: Hardware floating-point overflow.");
if (exponent > 30)
{
throw new ArithmeticException("Half: Hardware floating-point overflow.");
}
// Assemble the half from S, E and M.
@ -412,16 +430,22 @@ namespace OpenTK
// Make aInt lexicographically ordered as a twos-complement int
if (aInt < 0)
{
aInt = (short)(0x8000 - aInt);
}
// Make bInt lexicographically ordered as a twos-complement int
if (bInt < 0)
{
bInt = (short)(0x8000 - bInt);
}
short intDiff = System.Math.Abs((short)(aInt - bInt));
if (intDiff <= maxUlps)
{
return true;
}
return false;
}

View file

@ -75,7 +75,10 @@ namespace OpenTK
/// <returns>The next power of two.</returns>
public static long NextPowerOfTwo(long n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
if (n < 0)
{
throw new ArgumentOutOfRangeException("n", "Must be positive.");
}
return (long)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
@ -86,7 +89,10 @@ namespace OpenTK
/// <returns>The next power of two.</returns>
public static int NextPowerOfTwo(int n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
if (n < 0)
{
throw new ArgumentOutOfRangeException("n", "Must be positive.");
}
return (int)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
@ -97,7 +103,10 @@ namespace OpenTK
/// <returns>The next power of two.</returns>
public static float NextPowerOfTwo(float n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
if (n < 0)
{
throw new ArgumentOutOfRangeException("n", "Must be positive.");
}
return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
@ -108,7 +117,10 @@ namespace OpenTK
/// <returns>The next power of two.</returns>
public static double NextPowerOfTwo(double n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
if (n < 0)
{
throw new ArgumentOutOfRangeException("n", "Must be positive.");
}
return System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
@ -121,7 +133,9 @@ namespace OpenTK
long result = 1;
for (; n > 1; n--)
{
result *= n;
}
return result;
}
@ -311,11 +325,15 @@ namespace OpenTK
// 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);

View file

@ -156,15 +156,30 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -483,7 +498,9 @@ namespace OpenTK
float det = mat.Determinant;
if (det == 0)
{
throw new InvalidOperationException("Matrix is singular and cannot be inverted.");
}
float invDet = 1f / det;
@ -660,7 +677,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix2))
{
return false;
}
return this.Equals((Matrix2)obj);
}

View file

@ -156,15 +156,30 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -483,7 +498,9 @@ namespace OpenTK
double det = mat.Determinant;
if (det == 0)
{
throw new InvalidOperationException("Matrix is singular and cannot be inverted.");
}
double invDet = 1f / det;
@ -659,7 +676,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix2d))
{
return false;
}
return this.Equals((Matrix2d)obj);
}

View file

@ -158,15 +158,30 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -630,7 +645,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix2x3))
{
return false;
}
return this.Equals((Matrix2x3)obj);
}

View file

@ -158,15 +158,30 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -630,7 +645,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix2x3d))
{
return false;
}
return this.Equals((Matrix2x3d)obj);
}

View file

@ -179,15 +179,30 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -670,7 +685,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix2x4))
{
return false;
}
return this.Equals((Matrix2x4)obj);
}

View file

@ -179,15 +179,30 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -670,7 +685,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix2x4d))
{
return false;
}
return this.Equals((Matrix2x4d)obj);
}

View file

@ -223,17 +223,38 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -284,7 +305,9 @@ namespace OpenTK
{
Matrix3 m = this;
if (m.Determinant != 0)
{
m.Invert();
}
return m;
}
@ -774,7 +797,9 @@ namespace OpenTK
float oneOverPivot = 1.0f / pivot;
inverse[icol, icol] = 1.0f;
for (int k = 0; k < 3; ++k)
{
inverse[icol, k] *= oneOverPivot;
}
for (int j = 0; j < 3; ++j)
{
@ -783,7 +808,9 @@ namespace OpenTK
float f = inverse[j, icol];
inverse[j, icol] = 0.0f;
for (int k = 0; k < 3; ++k)
{
inverse[j, k] -= inverse[icol, k] * f;
}
}
}
}
@ -929,7 +956,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix3))
{
return false;
}
return this.Equals((Matrix3)obj);
}

View file

@ -217,17 +217,38 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -278,7 +299,9 @@ namespace OpenTK
{
Matrix3d m = this;
if (m.Determinant != 0)
{
m.Invert();
}
return m;
}
@ -769,7 +792,9 @@ namespace OpenTK
double oneOverPivot = 1.0 / pivot;
inverse[icol, icol] = 1.0;
for (int k = 0; k < 3; ++k)
{
inverse[icol, k] *= oneOverPivot;
}
for (int j = 0; j < 3; ++j)
{
@ -778,7 +803,9 @@ namespace OpenTK
double f = inverse[j, icol];
inverse[j, icol] = 0.0;
for (int k = 0; k < 3; ++k)
{
inverse[j, k] -= inverse[icol, k] * f;
}
}
}
}
@ -918,7 +945,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix3d))
{
return false;
}
return this.Equals((Matrix3d)obj);
}

View file

@ -158,17 +158,38 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -644,7 +665,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix3x2))
{
return false;
}
return this.Equals((Matrix3x2)obj);
}

View file

@ -158,17 +158,38 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -644,7 +665,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix3x2d))
{
return false;
}
return this.Equals((Matrix3x2d)obj);
}

View file

@ -211,17 +211,38 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -887,7 +908,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix3x4))
{
return false;
}
return this.Equals((Matrix3x4)obj);
}

View file

@ -211,17 +211,38 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -887,7 +908,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix3x4d))
{
return false;
}
return this.Equals((Matrix3x4d)obj);
}

View file

@ -301,19 +301,46 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
else if (rowIndex == 3) return Row3[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
else if (rowIndex == 3)
{
return Row3[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else if (rowIndex == 3) Row3[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else if (rowIndex == 3)
{
Row3[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -362,7 +389,9 @@ namespace OpenTK
{
Matrix4 m = this;
if (m.Determinant != 0)
{
m.Invert();
}
return m;
}
@ -887,13 +916,21 @@ namespace OpenTK
public static void CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar, out Matrix4 result)
{
if (fovy <= 0 || fovy > Math.PI)
{
throw new ArgumentOutOfRangeException("fovy");
}
if (aspect <= 0)
{
throw new ArgumentOutOfRangeException("aspect");
}
if (zNear <= 0)
{
throw new ArgumentOutOfRangeException("zNear");
}
if (zFar <= 0)
{
throw new ArgumentOutOfRangeException("zFar");
}
float yMax = zNear * (float)System.Math.Tan(0.5f * fovy);
float yMin = -yMax;
@ -949,11 +986,17 @@ namespace OpenTK
public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result)
{
if (zNear <= 0)
{
throw new ArgumentOutOfRangeException("zNear");
}
if (zFar <= 0)
{
throw new ArgumentOutOfRangeException("zFar");
}
if (zNear >= zFar)
{
throw new ArgumentOutOfRangeException("zNear");
}
float x = (2.0f * zNear) / (right - left);
float y = (2.0f * zNear) / (top - bottom);
@ -1262,7 +1305,9 @@ namespace OpenTK
float oneOverPivot = 1.0f / pivot;
inverse[icol, icol] = 1.0f;
for (int k = 0; k < 4; ++k)
{
inverse[icol, k] *= oneOverPivot;
}
// Do elimination of non-diagonal elements
for (int j = 0; j < 4; ++j)
@ -1273,7 +1318,9 @@ namespace OpenTK
float f = inverse[j, icol];
inverse[j, icol] = 0.0f;
for (int k = 0; k < 4; ++k)
{
inverse[j, k] -= inverse[icol, k] * f;
}
}
}
}
@ -1444,7 +1491,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix4))
{
return false;
}
return this.Equals((Matrix4)obj);
}

View file

@ -288,19 +288,46 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
else if (rowIndex == 3) return Row3[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
else if (rowIndex == 3)
{
return Row3[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else if (rowIndex == 3) Row3[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else if (rowIndex == 3)
{
Row3[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -349,7 +376,9 @@ namespace OpenTK
{
Matrix4d m = this;
if (m.Determinant != 0)
{
m.Invert();
}
return m;
}
@ -765,13 +794,21 @@ namespace OpenTK
public static void CreatePerspectiveFieldOfView(double fovy, double aspect, double zNear, double zFar, out Matrix4d result)
{
if (fovy <= 0 || fovy > Math.PI)
{
throw new ArgumentOutOfRangeException("fovy");
}
if (aspect <= 0)
{
throw new ArgumentOutOfRangeException("aspect");
}
if (zNear <= 0)
{
throw new ArgumentOutOfRangeException("zNear");
}
if (zFar <= 0)
{
throw new ArgumentOutOfRangeException("zFar");
}
double yMax = zNear * System.Math.Tan(0.5 * fovy);
double yMin = -yMax;
@ -827,11 +864,17 @@ namespace OpenTK
public static void CreatePerspectiveOffCenter(double left, double right, double bottom, double top, double zNear, double zFar, out Matrix4d result)
{
if (zNear <= 0)
{
throw new ArgumentOutOfRangeException("zNear");
}
if (zFar <= 0)
{
throw new ArgumentOutOfRangeException("zFar");
}
if (zNear >= zFar)
{
throw new ArgumentOutOfRangeException("zNear");
}
double x = (2.0 * zNear) / (right - left);
double y = (2.0 * zNear) / (top - bottom);
@ -1305,7 +1348,9 @@ namespace OpenTK
double oneOverPivot = 1.0 / pivot;
inverse[icol, icol] = 1.0;
for (int k = 0; k < 4; ++k)
{
inverse[icol, k] *= oneOverPivot;
}
// Do elimination of non-diagonal elements
for (int j = 0; j < 4; ++j)
@ -1316,7 +1361,9 @@ namespace OpenTK
double f = inverse[j, icol];
inverse[j, icol] = 0.0;
for (int k = 0; k < 4; ++k)
{
inverse[j, k] -= inverse[icol, k] * f;
}
}
}
}
@ -1463,7 +1510,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix4d))
{
return false;
}
return this.Equals((Matrix4d)obj);
}

View file

@ -180,19 +180,46 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
else if (rowIndex == 3) return Row3[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
else if (rowIndex == 3)
{
return Row3[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else if (rowIndex == 3) Row3[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else if (rowIndex == 3)
{
Row3[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -697,7 +724,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix4x2))
{
return false;
}
return this.Equals((Matrix4x2)obj);
}

View file

@ -180,19 +180,46 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
else if (rowIndex == 3) return Row3[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
else if (rowIndex == 3)
{
return Row3[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else if (rowIndex == 3) Row3[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else if (rowIndex == 3)
{
Row3[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -697,7 +724,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix4x2d))
{
return false;
}
return this.Equals((Matrix4x2d)obj);
}

View file

@ -212,19 +212,46 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
else if (rowIndex == 3) return Row3[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
else if (rowIndex == 3)
{
return Row3[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else if (rowIndex == 3) Row3[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else if (rowIndex == 3)
{
Row3[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -896,7 +923,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix4x3))
{
return false;
}
return this.Equals((Matrix4x3)obj);
}

View file

@ -212,19 +212,46 @@ namespace OpenTK
{
get
{
if (rowIndex == 0) return Row0[columnIndex];
else if (rowIndex == 1) return Row1[columnIndex];
else if (rowIndex == 2) return Row2[columnIndex];
else if (rowIndex == 3) return Row3[columnIndex];
if (rowIndex == 0)
{
return Row0[columnIndex];
}
else if (rowIndex == 1)
{
return Row1[columnIndex];
}
else if (rowIndex == 2)
{
return Row2[columnIndex];
}
else if (rowIndex == 3)
{
return Row3[columnIndex];
}
throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
set
{
if (rowIndex == 0) Row0[columnIndex] = value;
else if (rowIndex == 1) Row1[columnIndex] = value;
else if (rowIndex == 2) Row2[columnIndex] = value;
else if (rowIndex == 3) Row3[columnIndex] = value;
else throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
if (rowIndex == 0)
{
Row0[columnIndex] = value;
}
else if (rowIndex == 1)
{
Row1[columnIndex] = value;
}
else if (rowIndex == 2)
{
Row2[columnIndex] = value;
}
else if (rowIndex == 3)
{
Row3[columnIndex] = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
}
}
}
@ -896,7 +923,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Matrix4x3d))
{
return false;
}
return this.Equals((Matrix4x3d)obj);
}

View file

@ -137,7 +137,9 @@ namespace OpenTK
{
Quaternion q = this;
if (Math.Abs(q.W) > 1.0f)
{
q.Normalize();
}
Vector4 result = new Vector4();
@ -414,7 +416,9 @@ namespace OpenTK
public static Quaternion FromAxisAngle(Vector3 axis, float angle)
{
if (axis.LengthSquared == 0.0f)
{
return Identity;
}
Quaternion result = Identity;
@ -594,9 +598,13 @@ namespace OpenTK
Quaternion result = new Quaternion(blendA * q1.Xyz + blendB * q2.Xyz, blendA * q1.W + blendB * q2.W);
if (result.LengthSquared > 0.0f)
{
return Normalize(result);
}
else
{
return Identity;
}
}
/// <summary>
@ -698,8 +706,11 @@ namespace OpenTK
/// <returns>True if both objects are Quaternions of equal value. Otherwise it returns false.</returns>
public override bool Equals(object other)
{
if (other is Quaternion == false) return false;
return this == (Quaternion)other;
if (other is Quaternion == false)
{
return false;
}
return this == (Quaternion)other;
}
/// <summary>

View file

@ -137,7 +137,9 @@ namespace OpenTK
{
Quaterniond q = this;
if (Math.Abs(q.W) > 1.0f)
{
q.Normalize();
}
Vector4d result = new Vector4d();
@ -414,7 +416,9 @@ namespace OpenTK
public static Quaterniond FromAxisAngle(Vector3d axis, double angle)
{
if (axis.LengthSquared == 0.0f)
{
return Identity;
}
Quaterniond result = Identity;
@ -594,9 +598,13 @@ namespace OpenTK
Quaterniond result = new Quaterniond(blendA * q1.Xyz + blendB * q2.Xyz, blendA * q1.W + blendB * q2.W);
if (result.LengthSquared > 0.0f)
{
return Normalize(result);
}
else
{
return Identity;
}
}
/// <summary>
@ -698,7 +706,10 @@ namespace OpenTK
/// <returns>True if both objects are Quaternions of equal value. Otherwise it returns false.</returns>
public override bool Equals(object other)
{
if (other is Quaterniond == false) return false;
if (other is Quaterniond == false)
{
return false;
}
return this == (Quaterniond)other;
}

View file

@ -70,13 +70,28 @@ namespace OpenTK
/// </summary>
public float this[int index] {
get{
if(index == 0) return X;
else if(index == 1) return Y;
if(index == 0)
{
return X;
}
else if(index == 1)
{
return Y;
}
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
} set{
if(index == 0) X = value;
else if(index == 1) Y = value;
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
if(index == 0)
{
X = value;
}
else if(index == 1)
{
Y = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
}
}
}
@ -828,7 +843,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Vector2))
{
return false;
}
return this.Equals((Vector2)obj);
}

View file

@ -86,13 +86,28 @@ namespace OpenTK
/// </summary>
public double this[int index] {
get{
if(index == 0) return X;
else if(index == 1) return Y;
if(index == 0)
{
return X;
}
else if(index == 1)
{
return Y;
}
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
} set{
if(index == 0) X = value;
else if(index == 1) Y = value;
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
if(index == 0)
{
X = value;
}
else if(index == 1)
{
Y = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
}
}
}
@ -815,7 +830,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Vector2d))
{
return false;
}
return this.Equals((Vector2d)obj);
}

View file

@ -114,15 +114,36 @@ namespace OpenTK
/// </summary>
public float this[int index] {
get{
if(index == 0) return X;
else if(index == 1) return Y;
else if(index == 2) return Z;
if(index == 0)
{
return X;
}
else if(index == 1)
{
return Y;
}
else if(index == 2)
{
return Z;
}
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
} set{
if(index == 0) X = value;
else if(index == 1) Y = value;
else if(index == 2) Z = value;
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
if(index == 0)
{
X = value;
}
else if(index == 1)
{
Y = value;
}
else if(index == 2)
{
Z = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
}
}
}
@ -1329,7 +1350,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Vector3))
{
return false;
}
return this.Equals((Vector3)obj);
}

View file

@ -111,15 +111,36 @@ namespace OpenTK
/// </summary>
public double this[int index] {
get{
if(index == 0) return X;
else if(index == 1) return Y;
else if(index == 2) return Z;
if(index == 0)
{
return X;
}
else if(index == 1)
{
return Y;
}
else if(index == 2)
{
return Z;
}
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
} set{
if(index == 0) X = value;
else if(index == 1) Y = value;
else if(index == 2) Z = value;
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
if(index == 0)
{
X = value;
}
else if(index == 1)
{
Y = value;
}
else if(index == 2)
{
Z = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
}
}
}
@ -1170,7 +1191,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Vector3d))
{
return false;
}
return this.Equals((Vector3d)obj);
}

View file

@ -172,17 +172,44 @@ namespace OpenTK
/// </summary>
public float this[int index] {
get{
if(index == 0) return X;
else if(index == 1) return Y;
else if(index == 2) return Z;
else if(index == 3) return W;
if(index == 0)
{
return X;
}
else if(index == 1)
{
return Y;
}
else if(index == 2)
{
return Z;
}
else if(index == 3)
{
return W;
}
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
} set{
if(index == 0) X = value;
else if(index == 1) Y = value;
else if(index == 2) Z = value;
else if(index == 3) W = value;
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
if(index == 0)
{
X = value;
}
else if(index == 1)
{
Y = value;
}
else if(index == 2)
{
Z = value;
}
else if(index == 3)
{
W = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
}
}
}
@ -1433,7 +1460,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Vector4))
{
return false;
}
return this.Equals((Vector4)obj);
}

View file

@ -169,17 +169,44 @@ namespace OpenTK
/// </summary>
public double this[int index] {
get{
if(index == 0) return X;
else if(index == 1) return Y;
else if(index == 2) return Z;
else if(index == 3) return W;
if(index == 0)
{
return X;
}
else if(index == 1)
{
return Y;
}
else if(index == 2)
{
return Z;
}
else if(index == 3)
{
return W;
}
throw new IndexOutOfRangeException("You tried to access this vector at index: " + index);
} set{
if(index == 0) X = value;
else if(index == 1) Y = value;
else if(index == 2) Z = value;
else if(index == 3) W = value;
else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
if(index == 0)
{
X = value;
}
else if(index == 1)
{
Y = value;
}
else if(index == 2)
{
Z = value;
}
else if(index == 3)
{
W = value;
}
else
{
throw new IndexOutOfRangeException("You tried to set this vector at index: " + index);
}
}
}
@ -1379,7 +1406,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Vector4d))
{
return false;
}
return this.Equals((Vector4d)obj);
}

View file

@ -62,7 +62,9 @@ namespace OpenTK
: base(width, height, data)
{
if (hotx < 0 || hotx >= Width || hoty < 0 || hoty >= Height)
{
throw new ArgumentOutOfRangeException();
}
X = hotx;
Y = hoty;
@ -91,7 +93,9 @@ namespace OpenTK
: base(width, height, data)
{
if (hotx < 0 || hotx >= Width || hoty < 0 || hoty >= Height)
{
throw new ArgumentOutOfRangeException();
}
X = hotx;
Y = hoty;

Some files were not shown because too many files have changed in this diff Show more