├── .gitignore ├── MiniTK.dll.config ├── src └── MiniTK │ ├── Graphics │ ├── GraphicsContextException.cs │ ├── ES10 │ │ ├── Helper.cs │ │ └── ErrorHelper.cs │ ├── GraphicsContextMissingException.cs │ ├── ES11 │ │ ├── Helper.cs │ │ └── ErrorHelper.cs │ ├── GraphicsExceptions.cs │ ├── GraphicsErrorException.cs │ ├── GraphicsContext.cs │ ├── GraphicsBindingsBase.cs │ ├── OpenGL │ │ └── ErrorHelper.cs │ └── ES20 │ │ ├── ErrorHelper.cs │ │ └── Helper.cs │ ├── Audio │ ├── AudioException.cs │ ├── AudioValueException.cs │ ├── AudioDeviceException.cs │ ├── AudioContextException.cs │ ├── AudioDeviceErrorChecker.cs │ ├── OpenAL │ │ ├── Alc │ │ │ └── AlcEnums.cs │ │ └── AL │ │ │ └── XRamExtension.cs │ └── AudioDeviceEnumerator.cs │ ├── AutoGeneratedAttribute.cs │ ├── Math │ ├── Box2.cs │ ├── BezierCurveQuadric.cs │ ├── BezierCurveCubic.cs │ ├── Size.cs │ ├── Point.cs │ ├── BezierCurve.cs │ ├── MathHelper.cs │ ├── Rectangle.cs │ ├── Vector2h.cs │ └── Functions.cs │ ├── ContextHandle.cs │ ├── BindingsBase.cs │ └── BlittableValueType.cs ├── README ├── LICENSE ├── opentk.LICENSE ├── MiniTK.sln ├── Makefile └── MiniTK.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | obj/ 3 | *.pidb 4 | *.userprefs 5 | *.suo 6 | -------------------------------------------------------------------------------- /MiniTK.dll.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/GraphicsContextException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace OpenTK.Graphics 6 | { 7 | /// 8 | /// Represents errors related to a GraphicsContext. 9 | /// 10 | public class GraphicsContextException : Exception 11 | { 12 | /// 13 | /// Constructs a new GraphicsContextException. 14 | /// 15 | public GraphicsContextException() : base() { } 16 | /// 17 | /// Constructs a new GraphicsContextException with the given error message. 18 | /// 19 | public GraphicsContextException(string message) : base(message) { } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/ES10/Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace OpenTK.Graphics.ES10 6 | { 7 | /// 8 | /// Provides access to OpenGL ES 1.0 methods. 9 | /// 10 | public sealed partial class GL : GraphicsBindingsBase 11 | { 12 | const string Library = "libGLES.dll"; 13 | static readonly object sync_root = new object(); 14 | 15 | #region --- Protected Members --- 16 | 17 | /// 18 | /// Returns a synchronization token unique for the GL class. 19 | /// 20 | protected override object SyncRoot 21 | { 22 | get { return sync_root; } 23 | } 24 | 25 | #endregion 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/GraphicsContextMissingException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace OpenTK.Graphics 6 | { 7 | /// 8 | /// Thrown when an operation that required GraphicsContext is performed, when no 9 | /// GraphicsContext is current in the calling thread. 10 | /// 11 | public class GraphicsContextMissingException : GraphicsContextException 12 | { 13 | /// 14 | /// Constructs a new GraphicsContextMissingException. 15 | /// 16 | public GraphicsContextMissingException() 17 | : base(String.Format( 18 | "No context is current in the calling thread (ThreadId: {0}).", 19 | System.Threading.Thread.CurrentThread.ManagedThreadId)) 20 | { } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is MiniTK, an easy to use set of OpenGL and OpenAL bindings for C#, based on OpenTK. It is designed for use with (and was originally part of) SDL2#, a C# wrapper for SDL2, but does not depend on that project. See https://github.com/flibitijibibo/SDL2-CS for more information. 2 | 3 | License 4 | ------- 5 | MiniTK is released under the zlib license. See LICENSE for details. 6 | 7 | MiniTK uses code from of OpenTK, which is released under the MIT license. 8 | See opentk.LICENSE for details. 9 | 10 | Using MiniTK 11 | ------------ 12 | To use the OpenGL/OpenAL bindings, simply use them as you were with OpenTK, 13 | but after calling SDL_GL_CreateContext, add the following lines: 14 | 15 | OpenTK.Graphics.GraphicsContext.CurrentContext = yourContextIntPtr; 16 | GL.LoadAll( SDL.SDL_GL_GetProcAddress ); 17 | 18 | This will load the OpenTK entry points. 19 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/ES11/Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace OpenTK.Graphics.ES11 8 | { 9 | /// 10 | /// Provides access to OpenGL ES 1.1 methods. 11 | /// 12 | 13 | public sealed partial class GL : GraphicsBindingsBase 14 | { 15 | const string Library = "libGLES.dll"; 16 | static readonly object sync_root = new object(); 17 | 18 | #region --- Protected Members --- 19 | 20 | /// 21 | /// Returns a synchronization token unique for the GL class. 22 | /// 23 | protected override object SyncRoot 24 | { 25 | get { return sync_root; } 26 | } 27 | 28 | #endregion 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/GraphicsExceptions.cs: -------------------------------------------------------------------------------- 1 | #region --- License --- 2 | /* Licensed under the MIT/X11 license. 3 | * Copyright (c) 2006-2008 the OpenTK team. 4 | * This notice may not be removed. 5 | * See license.txt for licensing detailed licensing details. 6 | */ 7 | #endregion 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace OpenTK 14 | { 15 | /// Represents errors related to Graphics operations. 16 | public class GraphicsException : Exception 17 | { 18 | /// Constructs a new GraphicsException. 19 | public GraphicsException() : base() { } 20 | /// Constructs a new GraphicsException with the specified excpetion message. 21 | /// 22 | public GraphicsException(string message) : base(message) { } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/GraphicsErrorException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace OpenTK.Graphics 6 | { 7 | /// 8 | /// Identifies a specific OpenGL or OpenGL|ES error. Such exceptions are only thrown 9 | /// when OpenGL or OpenGL|ES automatic error checking is enabled - 10 | /// property. 11 | /// Important: Do *not* catch this exception. Rather, fix the underlying issue that caused the error. 12 | /// 13 | public class GraphicsErrorException : GraphicsException 14 | { 15 | /// 16 | /// Constructs a new GraphicsErrorException instance with the specified error message. 17 | /// 18 | /// 19 | public GraphicsErrorException(string message) : base(message) { } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | /* SDL2# - C# Wrapper for SDL2 2 | * 3 | * Copyright (c) 2013-2016 Ethan Lee. 4 | * 5 | * This software is provided 'as-is', without any express or implied warranty. 6 | * In no event will the authors be held liable for any damages arising from 7 | * the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any purpose, 10 | * including commercial applications, and to alter it and redistribute it 11 | * freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software in a 15 | * product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and must not be 19 | * misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source distribution. 22 | * 23 | * Ethan "flibitijibibo" Lee 24 | * 25 | */ 26 | -------------------------------------------------------------------------------- /opentk.LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2006 - 2008 The Open Toolkit library. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/GraphicsContext.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* SDL2# - C# Wrapper for SDL2 3 | * 4 | * Copyright (c) 2013-2014 Ethan Lee. 5 | * 6 | * This software is provided 'as-is', without any express or implied warranty. 7 | * In no event will the authors be held liable for any damages arising from 8 | * the use of this software. 9 | * 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 14 | * 1. The origin of this software must not be misrepresented; you must not 15 | * claim that you wrote the original software. If you use this software in a 16 | * product, an acknowledgment in the product documentation would be 17 | * appreciated but is not required. 18 | * 19 | * 2. Altered source versions must be plainly marked as such, and must not be 20 | * misrepresented as being the original software. 21 | * 22 | * 3. This notice may not be removed or altered from any source distribution. 23 | * 24 | * Ethan "flibitijibibo" Lee 25 | * 26 | */ 27 | #endregion 28 | 29 | #region Using Statements 30 | using System; 31 | #endregion 32 | 33 | namespace OpenTK.Graphics 34 | { 35 | public class GraphicsContext 36 | { 37 | public static IntPtr CurrentContext 38 | { 39 | get; 40 | set; 41 | } 42 | 43 | public static bool ErrorChecking 44 | { 45 | get; 46 | set; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/GraphicsBindingsBase.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | 30 | namespace OpenTK.Graphics 31 | { 32 | /// 33 | /// Implements BindingsBase for the OpenTK.Graphics namespace (OpenGL and OpenGL|ES). 34 | /// 35 | public abstract class GraphicsBindingsBase : BindingsBase 36 | { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /MiniTK.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniTK", "MiniTK.csproj", "{0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x64 = Debug|x64 12 | Debug|x86 = Debug|x86 13 | Release|Any CPU = Release|Any CPU 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Debug|x64.ActiveCfg = Debug|x64 21 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Debug|x64.Build.0 = Debug|x64 22 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Debug|x86.ActiveCfg = Debug|x86 23 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Debug|x86.Build.0 = Debug|x86 24 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Release|x64.ActiveCfg = Release|x64 27 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Release|x64.Build.0 = Release|x64 28 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Release|x86.ActiveCfg = Release|x86 29 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603}.Release|x86.Build.0 = Release|x86 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(MonoDevelopProperties) = preSolution 35 | StartupItem = SDL2-CS.csproj 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /src/MiniTK/Audio/AudioException.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | 29 | using System; 30 | using System.Collections.Generic; 31 | using System.Text; 32 | 33 | namespace OpenTK.Audio 34 | { 35 | /// Represents exceptions related to the OpenTK.Audio subsystem. 36 | public class AudioException : Exception 37 | { 38 | /// Constructs a new AudioException. 39 | public AudioException() : base() { } 40 | /// Constructs a new AudioException with the specified error message. 41 | /// The error message of the AudioException. 42 | public AudioException(string message) : base(message) { } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/MiniTK/Audio/AudioValueException.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | 32 | namespace OpenTK.Audio 33 | { 34 | /// Represents exceptions related to invalid values. 35 | public class AudioValueException : AudioException 36 | { 37 | /// Constructs a new instance. 38 | public AudioValueException() : base() { } 39 | /// Constructs a new instance with the specified error message. 40 | /// The error message of the AudioContextException. 41 | public AudioValueException(string message) : base(message) { } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/MiniTK/Audio/AudioDeviceException.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | 29 | using System; 30 | using System.Collections.Generic; 31 | using System.Text; 32 | 33 | namespace OpenTK.Audio 34 | { 35 | /// Represents exceptions related to an OpenTK.Audio device. 36 | public class AudioDeviceException : AudioException 37 | { 38 | /// Constructs a new AudioDeviceException. 39 | public AudioDeviceException() : base() { } 40 | /// Constructs a new AudioDeviceException with the specified error message. 41 | /// The error message of the AudioDeviceException. 42 | public AudioDeviceException(string message) : base(message) { } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/MiniTK/Audio/AudioContextException.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | 29 | using System; 30 | using System.Collections.Generic; 31 | using System.Text; 32 | 33 | namespace OpenTK.Audio 34 | { 35 | /// Represents exceptions related to an OpenTK.Audio.AudioContext. 36 | public class AudioContextException : AudioException 37 | { 38 | /// Constructs a new AudioContextException. 39 | public AudioContextException() : base() { } 40 | /// Constructs a new AudioContextException with the specified error message. 41 | /// The error message of the AudioContextException. 42 | public AudioContextException(string message) : base(message) { } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/MiniTK/AutoGeneratedAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | 32 | namespace OpenTK 33 | { 34 | /// 35 | /// Indicates that this function is generated automatically by a tool. 36 | /// 37 | public sealed class AutoGeneratedAttribute : Attribute 38 | { 39 | /// 40 | /// Specifies the category of this OpenGL function. 41 | /// 42 | public string Category; 43 | 44 | /// 45 | /// Specifies the version of this OpenGL function. 46 | /// 47 | public string Version; 48 | 49 | /// 50 | /// Specifies the entry point of the OpenGL function. 51 | /// 52 | public string EntryPoint; 53 | 54 | /// 55 | /// Constructs a new AutoGeneratedAttribute instance. 56 | /// 57 | public AutoGeneratedAttribute() 58 | { 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/MiniTK/Audio/AudioDeviceErrorChecker.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | 32 | using OpenTK.Audio.OpenAL; 33 | 34 | namespace OpenTK.Audio 35 | { 36 | struct AudioDeviceErrorChecker : IDisposable 37 | { 38 | #region Fields 39 | 40 | readonly IntPtr Device; 41 | static readonly string ErrorString = "Device {0} reported {1}."; 42 | 43 | #endregion 44 | 45 | #region Constructors 46 | 47 | public AudioDeviceErrorChecker(IntPtr device) 48 | { 49 | if (device == IntPtr.Zero) 50 | throw new AudioDeviceException(); 51 | 52 | Device = device; 53 | } 54 | 55 | #endregion 56 | 57 | #region IDisposable Members 58 | 59 | public void Dispose() 60 | { 61 | AlcError err = Alc.GetError(Device); 62 | switch (err) 63 | { 64 | case AlcError.OutOfMemory: 65 | throw new OutOfMemoryException(String.Format(ErrorString, Device, err)); 66 | 67 | case AlcError.InvalidValue: 68 | throw new AudioValueException(String.Format(ErrorString, Device, err)); 69 | 70 | case AlcError.InvalidDevice: 71 | throw new AudioDeviceException(String.Format(ErrorString, Device, err)); 72 | 73 | case AlcError.InvalidContext: 74 | throw new AudioContextException(String.Format(ErrorString, Device, err)); 75 | 76 | case AlcError.NoError: 77 | default: 78 | // everything went fine, do nothing 79 | break; 80 | } 81 | } 82 | 83 | #endregion 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/MiniTK/Math/Box2.cs: -------------------------------------------------------------------------------- 1 | #region --- License --- 2 | /* Copyright (c) 2006, 2007 Stefanos Apostolopoulos 3 | * See license.txt for license info 4 | */ 5 | #endregion 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | using System.Runtime.InteropServices; 11 | namespace OpenTK 12 | { 13 | /// 14 | /// Defines a 2d box (rectangle). 15 | /// 16 | [StructLayout(LayoutKind.Sequential)] 17 | public struct Box2 18 | { 19 | /// 20 | /// The left boundary of the structure. 21 | /// 22 | public float Left; 23 | 24 | /// 25 | /// The right boundary of the structure. 26 | /// 27 | public float Right; 28 | 29 | /// 30 | /// The top boundary of the structure. 31 | /// 32 | public float Top; 33 | 34 | /// 35 | /// The bottom boundary of the structure. 36 | /// 37 | public float Bottom; 38 | 39 | /// 40 | /// Constructs a new Box2 with the specified dimensions. 41 | /// 42 | /// AnOpenTK.Vector2 describing the top-left corner of the Box2. 43 | /// An OpenTK.Vector2 describing the bottom-right corner of the Box2. 44 | public Box2(Vector2 topLeft, Vector2 bottomRight) 45 | { 46 | Left = topLeft.X; 47 | Top = topLeft.Y; 48 | Right = bottomRight.X; 49 | Bottom = bottomRight.Y; 50 | } 51 | 52 | /// 53 | /// Constructs a new Box2 with the specified dimensions. 54 | /// 55 | /// The position of the left boundary. 56 | /// The position of the top boundary. 57 | /// The position of the right boundary. 58 | /// The position of the bottom boundary. 59 | public Box2(float left, float top, float right, float bottom) 60 | { 61 | Left = left; 62 | Top = top; 63 | Right = right; 64 | Bottom = bottom; 65 | } 66 | 67 | /// 68 | /// Creates a new Box2 with the specified dimensions. 69 | /// 70 | /// The position of the top boundary. 71 | /// The position of the left boundary. 72 | /// The position of the right boundary. 73 | /// The position of the bottom boundary. 74 | /// A new OpenTK.Box2 with the specfied dimensions. 75 | public static Box2 FromTLRB(float top, float left, float right, float bottom) 76 | { 77 | return new Box2(left, top, right, bottom); 78 | } 79 | 80 | /// 81 | /// Gets a float describing the width of the Box2 structure. 82 | /// 83 | public float Width { get { return (float)System.Math.Abs(Right - Left); } } 84 | 85 | /// 86 | /// Gets a float describing the height of the Box2 structure. 87 | /// 88 | public float Height { get { return (float)System.Math.Abs(Bottom - Top); } } 89 | 90 | /// 91 | /// Returns a describing the current instance. 92 | /// 93 | /// 94 | public override string ToString() 95 | { 96 | return String.Format("({0},{1})-({2},{3})", Left, Top, Right, Bottom); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for MiniTK 2 | # Originally written for SDL2-CS by Ethan "flibitijibibo" Lee 3 | # Modified by Daniel Ratcliffe 4 | 5 | # Dependencies 6 | DEPS = \ 7 | -r:System \ 8 | -r:System.Drawing \ 9 | -r:System.Xml 10 | 11 | # Source Lists 12 | MINITK = \ 13 | src/MiniTK/BlittableValueType.cs \ 14 | src/MiniTK/Math/Quaterniond.cs \ 15 | src/MiniTK/Math/Vector4.cs \ 16 | src/MiniTK/Math/Vector3h.cs \ 17 | src/MiniTK/Math/Vector2.cs \ 18 | src/MiniTK/Math/Vector4h.cs \ 19 | src/MiniTK/Math/Functions.cs \ 20 | src/MiniTK/Math/BezierCurve.cs \ 21 | src/MiniTK/Math/Rectangle.cs \ 22 | src/MiniTK/Math/Quaternion.cs \ 23 | src/MiniTK/Math/Size.cs \ 24 | src/MiniTK/Math/Vector4d.cs \ 25 | src/MiniTK/Math/Point.cs \ 26 | src/MiniTK/Math/MathHelper.cs \ 27 | src/MiniTK/Math/Matrix4.cs \ 28 | src/MiniTK/Math/Box2.cs \ 29 | src/MiniTK/Math/Half.cs \ 30 | src/MiniTK/Math/Matrix4d.cs \ 31 | src/MiniTK/Math/Vector3d.cs \ 32 | src/MiniTK/Math/Vector2d.cs \ 33 | src/MiniTK/Math/BezierCurveQuadric.cs \ 34 | src/MiniTK/Math/Matrix3d.cs \ 35 | src/MiniTK/Math/Vector2h.cs \ 36 | src/MiniTK/Math/BezierCurveCubic.cs \ 37 | src/MiniTK/Math/Vector3.cs \ 38 | src/MiniTK/AutoGeneratedAttribute.cs \ 39 | src/MiniTK/ContextHandle.cs \ 40 | src/MiniTK/Graphics/GraphicsBindingsBase.cs \ 41 | src/MiniTK/Graphics/ES20/Core.cs \ 42 | src/MiniTK/Graphics/ES20/ErrorHelper.cs \ 43 | src/MiniTK/Graphics/ES20/Enums.cs \ 44 | src/MiniTK/Graphics/ES20/Delegates.cs \ 45 | src/MiniTK/Graphics/ES20/Helper.cs \ 46 | src/MiniTK/Graphics/ES20/ES.cs \ 47 | src/MiniTK/Graphics/GraphicsContextMissingException.cs \ 48 | src/MiniTK/Graphics/OpenGL/GLDelegates.cs \ 49 | src/MiniTK/Graphics/OpenGL/GLCore.cs \ 50 | src/MiniTK/Graphics/OpenGL/ErrorHelper.cs \ 51 | src/MiniTK/Graphics/OpenGL/GLHelper.cs \ 52 | src/MiniTK/Graphics/OpenGL/GL.cs \ 53 | src/MiniTK/Graphics/OpenGL/GLEnums.cs \ 54 | src/MiniTK/Graphics/ES10/Core.cs \ 55 | src/MiniTK/Graphics/ES10/ErrorHelper.cs \ 56 | src/MiniTK/Graphics/ES10/Enums.cs \ 57 | src/MiniTK/Graphics/ES10/Delegates.cs \ 58 | src/MiniTK/Graphics/ES10/Helper.cs \ 59 | src/MiniTK/Graphics/ES10/ES.cs \ 60 | src/MiniTK/Graphics/ES11/Core.cs \ 61 | src/MiniTK/Graphics/ES11/ErrorHelper.cs \ 62 | src/MiniTK/Graphics/ES11/Enums.cs \ 63 | src/MiniTK/Graphics/ES11/Delegates.cs \ 64 | src/MiniTK/Graphics/ES11/Helper.cs \ 65 | src/MiniTK/Graphics/ES11/ES.cs \ 66 | src/MiniTK/Graphics/GraphicsContext.cs \ 67 | src/MiniTK/Graphics/Color4.cs \ 68 | src/MiniTK/Graphics/GraphicsContextException.cs \ 69 | src/MiniTK/Graphics/GraphicsErrorException.cs \ 70 | src/MiniTK/Graphics/GraphicsExceptions.cs \ 71 | src/MiniTK/BindingsBase.cs \ 72 | src/MiniTK/Audio/AudioCapture.cs \ 73 | src/MiniTK/Audio/AudioContextException.cs \ 74 | src/MiniTK/Audio/AudioException.cs \ 75 | src/MiniTK/Audio/OpenAL/Alc/Alc.cs \ 76 | src/MiniTK/Audio/OpenAL/Alc/AlcEnums.cs \ 77 | src/MiniTK/Audio/OpenAL/AL/EffectsExtensionEnums.cs \ 78 | src/MiniTK/Audio/OpenAL/AL/EffectsExtension.cs \ 79 | src/MiniTK/Audio/OpenAL/AL/AL.cs \ 80 | src/MiniTK/Audio/OpenAL/AL/XRamExtension.cs \ 81 | src/MiniTK/Audio/OpenAL/AL/EffectsExtensionPresets.cs \ 82 | src/MiniTK/Audio/OpenAL/AL/ALEnums.cs \ 83 | src/MiniTK/Audio/AudioContext.cs \ 84 | src/MiniTK/Audio/AudioValueException.cs \ 85 | src/MiniTK/Audio/AudioDeviceErrorChecker.cs \ 86 | src/MiniTK/Audio/AudioDeviceEnumerator.cs \ 87 | src/MiniTK/Audio/AudioDeviceException.cs 88 | 89 | # Targets 90 | 91 | debug: clean-debug 92 | mkdir -p bin/debug 93 | cp MiniTK.dll.config bin/debug 94 | dmcs /unsafe -debug -out:bin/debug/MiniTK.dll -target:library $(MINITK) $(DEPS) 95 | 96 | clean-debug: 97 | rm -rf bin/debug 98 | 99 | release: clean-release 100 | mkdir -p bin/release 101 | cp MiniTK.dll.config bin/release 102 | dmcs /unsafe -optimize -out:bin/release/MiniTK.dll -target:library $(MINITK) $(DEPS) 103 | 104 | clean-release: 105 | rm -rf bin/release 106 | 107 | clean: clean-debug clean-release 108 | rm -rf bin 109 | 110 | all: debug release 111 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/OpenGL/ErrorHelper.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | using System.Diagnostics; 32 | 33 | /* flibit Changes GraphicsContext stuff to IntPtr, an SDL_GLContext. */ 34 | 35 | namespace OpenTK.Graphics.OpenGL 36 | { 37 | // Used in debug-mode only, for automatic OpenGL error-checking. 38 | // 39 | // Works like this: an instance is created before each OpenGL function is called. 40 | // The constructor resets the OpenGL error state. Once the native function returns, 41 | // the error state is checked again, raising the relevant exceptions. 42 | // 43 | // A using-region is used to ensure Dispose() is called. 44 | // 45 | // Make sure that no error checking is added to the GetError function, 46 | // as that would cause infinite recursion! 47 | struct ErrorHelper : IDisposable 48 | { 49 | #region Fields 50 | 51 | static readonly object SyncRoot = new object(); 52 | static readonly Dictionary> ContextErrors = 53 | new Dictionary>(); 54 | readonly IntPtr Context; 55 | 56 | #endregion 57 | 58 | #region Constructors 59 | 60 | public ErrorHelper(IntPtr context) 61 | { 62 | if (context == IntPtr.Zero) 63 | throw new GraphicsContextMissingException(); 64 | 65 | Context = context; 66 | lock (SyncRoot) 67 | { 68 | if (!ContextErrors.ContainsKey(Context)) 69 | ContextErrors.Add(Context, new List()); 70 | } 71 | ResetErrors(); 72 | } 73 | 74 | #endregion 75 | 76 | #region Public Members 77 | 78 | // Retrieve all OpenGL errors to clear the error list. 79 | // See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/geterror.html 80 | [Conditional("DEBUG")] 81 | internal void ResetErrors() 82 | { 83 | if (GraphicsContext.ErrorChecking) 84 | { 85 | while (GL.GetError() != ErrorCode.NoError) 86 | { } 87 | } 88 | } 89 | 90 | // Retrieve all OpenGL errors and throw an exception if anything other than NoError is returned. 91 | [Conditional("DEBUG")] 92 | internal void CheckErrors() 93 | { 94 | if (GraphicsContext.ErrorChecking) 95 | { 96 | List error_list = ContextErrors[Context]; 97 | error_list.Clear(); 98 | ErrorCode error; 99 | do 100 | { 101 | error = GL.GetError(); 102 | error_list.Add(error); 103 | } while (error != ErrorCode.NoError); 104 | 105 | if (error_list.Count != 1) 106 | { 107 | StringBuilder sb = new StringBuilder(); 108 | foreach (ErrorCode e in error_list) 109 | { 110 | if (e != ErrorCode.NoError) 111 | { 112 | sb.Append(e.ToString()); 113 | sb.Append(", "); 114 | } 115 | else 116 | break; 117 | } 118 | sb.Remove(sb.Length - 2, 2); // Remove the last comma 119 | 120 | throw new GraphicsErrorException(sb.ToString()); 121 | } 122 | } 123 | } 124 | 125 | #endregion 126 | 127 | #region IDisposable Members 128 | 129 | public void Dispose() 130 | { 131 | CheckErrors(); 132 | } 133 | 134 | #endregion 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/ES10/ErrorHelper.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | using System.Diagnostics; 32 | 33 | /* flibit Changes GraphicsContext stuff to IntPtr, an SDL_GLContext. */ 34 | 35 | namespace OpenTK.Graphics.ES10 36 | { 37 | // Used in debug-mode only, for automatic OpenGL error-checking. 38 | // 39 | // Works like this: an instance is created before each OpenGL function is called. 40 | // The constructor resets the OpenGL error state. Once the native function returns, 41 | // the error state is checked again, raising the relevant exceptions. 42 | // 43 | // A using-region is used to ensure Dispose() is called. 44 | // 45 | // Make sure that no error checking is added to the GetError function, 46 | // as that would cause infinite recursion! 47 | struct ErrorHelper : IDisposable 48 | { 49 | #region Fields 50 | 51 | static readonly object SyncRoot = new object(); 52 | static readonly Dictionary> ContextErrors = 53 | new Dictionary>(); 54 | readonly IntPtr Context; 55 | 56 | #endregion 57 | 58 | #region Constructors 59 | 60 | public ErrorHelper(IntPtr context) 61 | { 62 | if (context == IntPtr.Zero) 63 | throw new GraphicsContextMissingException(); 64 | 65 | Context = context; 66 | lock (SyncRoot) 67 | { 68 | if (!ContextErrors.ContainsKey(Context)) 69 | ContextErrors.Add(Context, new List()); 70 | } 71 | ResetErrors(); 72 | } 73 | 74 | #endregion 75 | 76 | #region Public Members 77 | 78 | // Retrieve all OpenGL errors to clear the error list. 79 | // See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/geterror.html 80 | [Conditional("DEBUG")] 81 | internal void ResetErrors() 82 | { 83 | if (GraphicsContext.ErrorChecking) 84 | { 85 | while ((ErrorCode)GL.GetError() != ErrorCode.NoError) 86 | { } 87 | } 88 | } 89 | 90 | // Retrieve all OpenGL errors and throw an exception if anything other than NoError is returned. 91 | [Conditional("DEBUG")] 92 | internal void CheckErrors() 93 | { 94 | if (GraphicsContext.ErrorChecking) 95 | { 96 | List error_list = ContextErrors[Context]; 97 | error_list.Clear(); 98 | ErrorCode error; 99 | do 100 | { 101 | error = (ErrorCode)GL.GetError(); 102 | error_list.Add(error); 103 | } while (error != ErrorCode.NoError); 104 | 105 | if (error_list.Count != 1) 106 | { 107 | StringBuilder sb = new StringBuilder(); 108 | foreach (ErrorCode e in error_list) 109 | { 110 | if (e != ErrorCode.NoError) 111 | { 112 | sb.Append(e.ToString()); 113 | sb.Append(", "); 114 | } 115 | else 116 | break; 117 | } 118 | sb.Remove(sb.Length - 2, 2); // Remove the last comma 119 | 120 | throw new GraphicsErrorException(sb.ToString()); 121 | } 122 | } 123 | } 124 | 125 | #endregion 126 | 127 | #region IDisposable Members 128 | 129 | public void Dispose() 130 | { 131 | CheckErrors(); 132 | } 133 | 134 | #endregion 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/ES11/ErrorHelper.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | using System.Diagnostics; 32 | 33 | /* flibit Changes GraphicsContext stuff to IntPtr, an SDL_GLContext. */ 34 | 35 | namespace OpenTK.Graphics.ES11 36 | { 37 | // Used in debug-mode only, for automatic OpenGL error-checking. 38 | // 39 | // Works like this: an instance is created before each OpenGL function is called. 40 | // The constructor resets the OpenGL error state. Once the native function returns, 41 | // the error state is checked again, raising the relevant exceptions. 42 | // 43 | // A using-region is used to ensure Dispose() is called. 44 | // 45 | // Make sure that no error checking is added to the GetError function, 46 | // as that would cause infinite recursion! 47 | struct ErrorHelper : IDisposable 48 | { 49 | #region Fields 50 | 51 | static readonly object SyncRoot = new object(); 52 | static readonly Dictionary> ContextErrors = 53 | new Dictionary>(); 54 | readonly IntPtr Context; 55 | 56 | #endregion 57 | 58 | #region Constructors 59 | 60 | public ErrorHelper(IntPtr context) 61 | { 62 | if (context == IntPtr.Zero) 63 | throw new GraphicsContextMissingException(); 64 | 65 | Context = context; 66 | lock (SyncRoot) 67 | { 68 | if (!ContextErrors.ContainsKey(Context)) 69 | ContextErrors.Add(Context, new List()); 70 | } 71 | ResetErrors(); 72 | } 73 | 74 | #endregion 75 | 76 | #region Public Members 77 | 78 | // Retrieve all OpenGL errors to clear the error list. 79 | // See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/geterror.html 80 | [Conditional("DEBUG")] 81 | internal void ResetErrors() 82 | { 83 | if (GraphicsContext.ErrorChecking) 84 | { 85 | while ((ErrorCode)GL.GetError() != ErrorCode.NoError) 86 | { } 87 | } 88 | } 89 | 90 | // Retrieve all OpenGL errors and throw an exception if anything other than NoError is returned. 91 | [Conditional("DEBUG")] 92 | internal void CheckErrors() 93 | { 94 | if (GraphicsContext.ErrorChecking) 95 | { 96 | List error_list = ContextErrors[Context]; 97 | error_list.Clear(); 98 | ErrorCode error; 99 | do 100 | { 101 | error = (ErrorCode)GL.GetError(); 102 | error_list.Add(error); 103 | } while (error != ErrorCode.NoError); 104 | 105 | if (error_list.Count != 1) 106 | { 107 | StringBuilder sb = new StringBuilder(); 108 | foreach (ErrorCode e in error_list) 109 | { 110 | if (e != ErrorCode.NoError) 111 | { 112 | sb.Append(e.ToString()); 113 | sb.Append(", "); 114 | } 115 | else 116 | break; 117 | } 118 | sb.Remove(sb.Length - 2, 2); // Remove the last comma 119 | 120 | throw new GraphicsErrorException(sb.ToString()); 121 | } 122 | } 123 | } 124 | 125 | #endregion 126 | 127 | #region IDisposable Members 128 | 129 | public void Dispose() 130 | { 131 | CheckErrors(); 132 | } 133 | 134 | #endregion 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/MiniTK/Graphics/ES20/ErrorHelper.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | using System.Diagnostics; 32 | 33 | /* flibit Changes GraphicsContext stuff to IntPtr, an SDL_GLContext. */ 34 | 35 | namespace OpenTK.Graphics.ES20 36 | { 37 | // Used in debug-mode only, for automatic OpenGL error-checking. 38 | // 39 | // Works like this: an instance is created before each OpenGL function is called. 40 | // The constructor resets the OpenGL error state. Once the native function returns, 41 | // the error state is checked again, raising the relevant exceptions. 42 | // 43 | // A using-region is used to ensure Dispose() is called. 44 | // 45 | // Make sure that no error checking is added to the GetError function, 46 | // as that would cause infinite recursion! 47 | struct ErrorHelper : IDisposable 48 | { 49 | #region Fields 50 | 51 | static readonly object SyncRoot = new object(); 52 | static readonly Dictionary> ContextErrors = 53 | new Dictionary>(); 54 | readonly IntPtr Context; 55 | 56 | #endregion 57 | 58 | #region Constructors 59 | 60 | public ErrorHelper(IntPtr context) 61 | { 62 | if (context == IntPtr.Zero) 63 | throw new GraphicsContextMissingException(); 64 | 65 | Context = context; 66 | lock (SyncRoot) 67 | { 68 | if (!ContextErrors.ContainsKey(Context)) 69 | ContextErrors.Add(Context, new List()); 70 | } 71 | ResetErrors(); 72 | } 73 | 74 | #endregion 75 | 76 | #region Public Members 77 | 78 | // Retrieve all OpenGL errors to clear the error list. 79 | // See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/geterror.html 80 | [Conditional("DEBUG")] 81 | internal void ResetErrors() 82 | { 83 | if (GraphicsContext.ErrorChecking) 84 | { 85 | while ((ErrorCode)GL.GetError() != ErrorCode.NoError) 86 | { } 87 | } 88 | } 89 | 90 | // Retrieve all OpenGL errors and throw an exception if anything other than NoError is returned. 91 | [Conditional("DEBUG")] 92 | internal void CheckErrors() 93 | { 94 | if (GraphicsContext.ErrorChecking) 95 | { 96 | List error_list = ContextErrors[Context]; 97 | error_list.Clear(); 98 | ErrorCode error; 99 | do 100 | { 101 | error = (ErrorCode)GL.GetError(); 102 | error_list.Add(error); 103 | } while (error != ErrorCode.NoError); 104 | 105 | if (error_list.Count != 1) 106 | { 107 | StringBuilder sb = new StringBuilder(); 108 | foreach (ErrorCode e in error_list) 109 | { 110 | if (e != ErrorCode.NoError) 111 | { 112 | sb.Append(e.ToString()); 113 | sb.Append(", "); 114 | } 115 | else 116 | break; 117 | } 118 | sb.Remove(sb.Length - 2, 2); // Remove the last comma 119 | 120 | throw new GraphicsErrorException(sb.ToString()); 121 | } 122 | } 123 | } 124 | 125 | #endregion 126 | 127 | #region IDisposable Members 128 | 129 | public void Dispose() 130 | { 131 | CheckErrors(); 132 | } 133 | 134 | #endregion 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/MiniTK/Math/BezierCurveQuadric.cs: -------------------------------------------------------------------------------- 1 | #region --- License --- 2 | /* Licensed under the MIT/X11 license. 3 | * Copyright (c) 2006-2008 the OpenTK Team. 4 | * This notice may not be removed from any source distribution. 5 | * See license.txt for licensing detailed licensing details. 6 | * 7 | * Contributions by Georg W�chter. 8 | */ 9 | #endregion 10 | 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Text; 14 | 15 | namespace OpenTK 16 | { 17 | /// 18 | /// Represents a quadric bezier curve with two anchor and one control point. 19 | /// 20 | [Serializable] 21 | public struct BezierCurveQuadric 22 | { 23 | #region Fields 24 | 25 | /// 26 | /// Start anchor point. 27 | /// 28 | public Vector2 StartAnchor; 29 | 30 | /// 31 | /// End anchor point. 32 | /// 33 | public Vector2 EndAnchor; 34 | 35 | /// 36 | /// Control point, controls the direction of both endings of the curve. 37 | /// 38 | public Vector2 ControlPoint; 39 | 40 | /// 41 | /// The parallel value. 42 | /// 43 | /// This value defines whether the curve should be calculated as a 44 | /// parallel curve to the original bezier curve. A value of 0.0f represents 45 | /// the original curve, 5.0f i.e. stands for a curve that has always a distance 46 | /// of 5.f to the orignal curve at any point. 47 | public float Parallel; 48 | 49 | #endregion 50 | 51 | #region Constructors 52 | 53 | /// 54 | /// Constructs a new . 55 | /// 56 | /// The start anchor. 57 | /// The end anchor. 58 | /// The control point. 59 | public BezierCurveQuadric(Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint) 60 | { 61 | this.StartAnchor = startAnchor; 62 | this.EndAnchor = endAnchor; 63 | this.ControlPoint = controlPoint; 64 | this.Parallel = 0.0f; 65 | } 66 | 67 | /// 68 | /// Constructs a new . 69 | /// 70 | /// The parallel value. 71 | /// The start anchor. 72 | /// The end anchor. 73 | /// The control point. 74 | public BezierCurveQuadric(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 controlPoint) 75 | { 76 | this.Parallel = parallel; 77 | this.StartAnchor = startAnchor; 78 | this.EndAnchor = endAnchor; 79 | this.ControlPoint = controlPoint; 80 | } 81 | 82 | #endregion 83 | 84 | #region Functions 85 | 86 | /// 87 | /// Calculates the point with the specified t. 88 | /// 89 | /// The t value, between 0.0f and 1.0f. 90 | /// Resulting point. 91 | public Vector2 CalculatePoint(float t) 92 | { 93 | Vector2 r = new Vector2(); 94 | float c = 1.0f - t; 95 | 96 | r.X = (c * c * StartAnchor.X) + (2 * t * c * ControlPoint.X) + (t * t * EndAnchor.X); 97 | r.Y = (c * c * StartAnchor.Y) + (2 * t * c * ControlPoint.Y) + (t * t * EndAnchor.Y); 98 | 99 | if (Parallel == 0.0f) 100 | return r; 101 | 102 | Vector2 perpendicular = new Vector2(); 103 | 104 | if (t == 0.0f) 105 | perpendicular = ControlPoint - StartAnchor; 106 | else 107 | perpendicular = r - CalculatePointOfDerivative(t); 108 | 109 | return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel; 110 | } 111 | 112 | /// 113 | /// Calculates the point with the specified t of the derivative of this function. 114 | /// 115 | /// The t, value between 0.0f and 1.0f. 116 | /// Resulting point. 117 | private Vector2 CalculatePointOfDerivative(float t) 118 | { 119 | Vector2 r = new Vector2(); 120 | 121 | r.X = (1.0f - t) * StartAnchor.X + t * ControlPoint.X; 122 | r.Y = (1.0f - t) * StartAnchor.Y + t * ControlPoint.Y; 123 | 124 | return r; 125 | } 126 | 127 | /// 128 | /// Calculates the length of this bezier curve. 129 | /// 130 | /// The precision. 131 | /// Length of curve. 132 | /// The precision gets better when the 133 | /// value gets smaller. 134 | public float CalculateLength(float precision) 135 | { 136 | float length = 0.0f; 137 | Vector2 old = CalculatePoint(0.0f); 138 | 139 | for (float i = precision; i < (1.0f + precision); i += precision) 140 | { 141 | Vector2 n = CalculatePoint(i); 142 | length += (n - old).Length; 143 | old = n; 144 | } 145 | 146 | return length; 147 | } 148 | 149 | #endregion 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/MiniTK/Math/BezierCurveCubic.cs: -------------------------------------------------------------------------------- 1 | #region --- License --- 2 | /* Licensed under the MIT/X11 license. 3 | * Copyright (c) 2006-2008 the OpenTK Team. 4 | * This notice may not be removed from any source distribution. 5 | * See license.txt for licensing detailed licensing details. 6 | * 7 | * Contributions by Georg W�chter. 8 | */ 9 | #endregion 10 | 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Text; 14 | 15 | namespace OpenTK 16 | { 17 | /// 18 | /// Represents a cubic bezier curve with two anchor and two control points. 19 | /// 20 | [Serializable] 21 | public struct BezierCurveCubic 22 | { 23 | #region Fields 24 | 25 | /// 26 | /// Start anchor point. 27 | /// 28 | public Vector2 StartAnchor; 29 | 30 | /// 31 | /// End anchor point. 32 | /// 33 | public Vector2 EndAnchor; 34 | 35 | /// 36 | /// First control point, controls the direction of the curve start. 37 | /// 38 | public Vector2 FirstControlPoint; 39 | 40 | /// 41 | /// Second control point, controls the direction of the curve end. 42 | /// 43 | public Vector2 SecondControlPoint; 44 | 45 | /// 46 | /// Gets or sets the parallel value. 47 | /// 48 | /// This value defines whether the curve should be calculated as a 49 | /// parallel curve to the original bezier curve. A value of 0.0f represents 50 | /// the original curve, 5.0f i.e. stands for a curve that has always a distance 51 | /// of 5.f to the orignal curve at any point. 52 | public float Parallel; 53 | 54 | #endregion 55 | 56 | #region Constructors 57 | 58 | /// 59 | /// Constructs a new . 60 | /// 61 | /// The start anchor point. 62 | /// The end anchor point. 63 | /// The first control point. 64 | /// The second control point. 65 | public BezierCurveCubic(Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint) 66 | { 67 | this.StartAnchor = startAnchor; 68 | this.EndAnchor = endAnchor; 69 | this.FirstControlPoint = firstControlPoint; 70 | this.SecondControlPoint = secondControlPoint; 71 | this.Parallel = 0.0f; 72 | } 73 | 74 | /// 75 | /// Constructs a new . 76 | /// 77 | /// The parallel value. 78 | /// The start anchor point. 79 | /// The end anchor point. 80 | /// The first control point. 81 | /// The second control point. 82 | public BezierCurveCubic(float parallel, Vector2 startAnchor, Vector2 endAnchor, Vector2 firstControlPoint, Vector2 secondControlPoint) 83 | { 84 | this.Parallel = parallel; 85 | this.StartAnchor = startAnchor; 86 | this.EndAnchor = endAnchor; 87 | this.FirstControlPoint = firstControlPoint; 88 | this.SecondControlPoint = secondControlPoint; 89 | } 90 | 91 | #endregion 92 | 93 | #region Functions 94 | 95 | /// 96 | /// Calculates the point with the specified t. 97 | /// 98 | /// The t value, between 0.0f and 1.0f. 99 | /// Resulting point. 100 | public Vector2 CalculatePoint(float t) 101 | { 102 | Vector2 r = new Vector2(); 103 | float c = 1.0f - t; 104 | 105 | r.X = (StartAnchor.X * c * c * c) + (FirstControlPoint.X * 3 * t * c * c) + (SecondControlPoint.X * 3 * t * t * c) 106 | + EndAnchor.X * t * t * t; 107 | r.Y = (StartAnchor.Y * c * c * c) + (FirstControlPoint.Y * 3 * t * c * c) + (SecondControlPoint.Y * 3 * t * t * c) 108 | + EndAnchor.Y * t * t * t; 109 | 110 | if (Parallel == 0.0f) 111 | return r; 112 | 113 | Vector2 perpendicular = new Vector2(); 114 | 115 | if (t == 0.0f) 116 | perpendicular = FirstControlPoint - StartAnchor; 117 | else 118 | perpendicular = r - CalculatePointOfDerivative(t); 119 | 120 | return r + Vector2.Normalize(perpendicular).PerpendicularRight * Parallel; 121 | } 122 | 123 | /// 124 | /// Calculates the point with the specified t of the derivative of this function. 125 | /// 126 | /// The t, value between 0.0f and 1.0f. 127 | /// Resulting point. 128 | private Vector2 CalculatePointOfDerivative(float t) 129 | { 130 | Vector2 r = new Vector2(); 131 | float c = 1.0f - t; 132 | 133 | r.X = (c * c * StartAnchor.X) + (2 * t * c * FirstControlPoint.X) + (t * t * SecondControlPoint.X); 134 | r.Y = (c * c * StartAnchor.Y) + (2 * t * c * FirstControlPoint.Y) + (t * t * SecondControlPoint.Y); 135 | 136 | return r; 137 | } 138 | 139 | /// 140 | /// Calculates the length of this bezier curve. 141 | /// 142 | /// The precision. 143 | /// Length of the curve. 144 | /// The precision gets better when the 145 | /// value gets smaller. 146 | public float CalculateLength(float precision) 147 | { 148 | float length = 0.0f; 149 | Vector2 old = CalculatePoint(0.0f); 150 | 151 | for (float i = precision; i < (1.0f + precision); i += precision) 152 | { 153 | Vector2 n = CalculatePoint(i); 154 | length += (n - old).Length; 155 | old = n; 156 | } 157 | 158 | return length; 159 | } 160 | 161 | #endregion 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/MiniTK/ContextHandle.cs: -------------------------------------------------------------------------------- 1 | #region --- License --- 2 | /* Licensed under the MIT/X11 license. 3 | * Copyright (c) 2006-2008 the OpenTK Team. 4 | * This notice may not be removed from any source distribution. 5 | * See license.txt for licensing detailed licensing details. 6 | */ 7 | #endregion 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace OpenTK 14 | { 15 | /// 16 | /// Represents a handle to an OpenGL or OpenAL context. 17 | /// 18 | public struct ContextHandle : IComparable, IEquatable 19 | { 20 | #region Fields 21 | 22 | IntPtr handle; 23 | 24 | /// 25 | /// Gets a System.IntPtr that represents the handle of this ContextHandle. 26 | /// 27 | public IntPtr Handle { get { return handle; } } 28 | 29 | /// A read-only field that represents a handle that has been initialized to zero. 30 | public static readonly ContextHandle Zero = new ContextHandle(IntPtr.Zero); 31 | 32 | #endregion 33 | 34 | #region Constructors 35 | 36 | /// 37 | /// Constructs a new instance with the specified handle. 38 | /// 39 | /// A System.IntPtr containing the value for this instance. 40 | public ContextHandle(IntPtr h) { handle = h; } 41 | 42 | #endregion 43 | 44 | #region Public Members 45 | 46 | #region ToString 47 | 48 | /// 49 | /// Converts this instance to its equivalent string representation. 50 | /// 51 | /// A System.String that contains the string representation of this instance. 52 | public override string ToString() 53 | { 54 | return Handle.ToString(); 55 | } 56 | 57 | #endregion 58 | 59 | #region Equals 60 | 61 | /// 62 | /// Compares this instance to the specified object. 63 | /// 64 | /// The System.Object to compare to. 65 | /// True if obj is a ContextHandle that is equal to this instance; false otherwise. 66 | public override bool Equals(object obj) 67 | { 68 | if (obj is ContextHandle) 69 | return this.Equals((ContextHandle)obj); 70 | return false; 71 | } 72 | 73 | #endregion 74 | 75 | #region GetHashCode 76 | 77 | /// 78 | /// Returns the hash code for this instance. 79 | /// 80 | /// A System.Int32 with the hash code of this instance. 81 | public override int GetHashCode() 82 | { 83 | return Handle.GetHashCode(); 84 | } 85 | 86 | #endregion 87 | 88 | #region public static explicit operator IntPtr(ContextHandle c) 89 | 90 | /// 91 | /// Converts the specified ContextHandle to the equivalent IntPtr. 92 | /// 93 | /// The ContextHandle to convert. 94 | /// A System.IntPtr equivalent to the specified ContextHandle. 95 | public static explicit operator IntPtr(ContextHandle c) 96 | { 97 | return c != ContextHandle.Zero ? c.handle : IntPtr.Zero; 98 | } 99 | 100 | #endregion 101 | 102 | #region public static explicit operator ContextHandle(IntPtr p) 103 | 104 | /// 105 | /// Converts the specified IntPtr to the equivalent ContextHandle. 106 | /// 107 | /// The System.IntPtr to convert. 108 | /// A ContextHandle equivalent to the specified IntPtr. 109 | public static explicit operator ContextHandle(IntPtr p) 110 | { 111 | return new ContextHandle(p); 112 | } 113 | 114 | #endregion 115 | 116 | #region public static bool operator ==(ContextHandle left, ContextHandle right) 117 | 118 | /// 119 | /// Compares two ContextHandles for equality. 120 | /// 121 | /// The ContextHandle to compare. 122 | /// The ContextHandle to compare to. 123 | /// True if left is equal to right; false otherwise. 124 | public static bool operator ==(ContextHandle left, ContextHandle right) 125 | { 126 | return left.Equals(right); 127 | } 128 | 129 | #endregion 130 | 131 | #region public static bool operator !=(ContextHandle left, ContextHandle right) 132 | 133 | /// 134 | /// Compares two ContextHandles for inequality. 135 | /// 136 | /// The ContextHandle to compare. 137 | /// The ContextHandle to compare to. 138 | /// True if left is not equal to right; false otherwise. 139 | public static bool operator !=(ContextHandle left, ContextHandle right) 140 | { 141 | return !left.Equals(right); 142 | } 143 | 144 | #endregion 145 | 146 | #endregion 147 | 148 | #region IComparable Members 149 | 150 | /// 151 | /// Compares the numerical value of this instance to the specified ContextHandle and 152 | /// returns a value indicating their relative order. 153 | /// 154 | /// The ContextHandle to compare to. 155 | /// Less than 0, if this instance is less than other; 0 if both are equal; Greater than 0 if other is greater than this instance. 156 | public int CompareTo(ContextHandle other) 157 | { 158 | unsafe { return (int)((int*)other.handle.ToPointer() - (int*)this.handle.ToPointer()); } 159 | } 160 | 161 | #endregion 162 | 163 | #region IEquatable Members 164 | 165 | /// 166 | /// Compares this instance to the specified ContextHandle for equality. 167 | /// 168 | /// The ContextHandle to compare to. 169 | /// True if this instance is equal to other; false otherwise. 170 | public bool Equals(ContextHandle other) 171 | { 172 | return Handle == other.Handle; 173 | } 174 | 175 | #endregion 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/MiniTK/Audio/OpenAL/Alc/AlcEnums.cs: -------------------------------------------------------------------------------- 1 | #region --- OpenTK.OpenAL License --- 2 | /* AlcTokens.cs 3 | * C header: \OpenAL 1.1 SDK\include\Alc.h 4 | * Spec: http://www.openal.org/openal_webstf/specs/OpenAL11Specification.pdf 5 | * Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos 6 | * See license.txt for license details 7 | * http://www.OpenTK.net */ 8 | #endregion 9 | 10 | using System; 11 | 12 | namespace OpenTK.Audio.OpenAL 13 | { 14 | /// 15 | /// Defines available context attributes. 16 | /// 17 | public enum AlcContextAttributes : int 18 | { 19 | ///Followed by System.Int32 Hz 20 | Frequency = 0x1007, 21 | 22 | ///Followed by System.Int32 Hz 23 | Refresh = 0x1008, 24 | 25 | ///Followed by AlBoolean.True, or AlBoolean.False 26 | Sync = 0x1009, 27 | 28 | ///Followed by System.Int32 Num of requested Mono (3D) Sources 29 | MonoSources = 0x1010, 30 | 31 | ///Followed by System.Int32 Num of requested Stereo Sources 32 | StereoSources = 0x1011, 33 | 34 | /// (EFX Extension) This Context property can be passed to OpenAL during Context creation (alcCreateContext) to request a maximum number of Auxiliary Sends desired on each Source. It is not guaranteed that the desired number of sends will be available, so an application should query this property after creating the context using alcGetIntergerv. Default: 2 35 | EfxMaxAuxiliarySends = 0x20003, 36 | } 37 | 38 | /// 39 | /// Defines OpenAL context errors. 40 | /// 41 | public enum AlcError : int 42 | { 43 | ///There is no current error. 44 | NoError = 0, 45 | 46 | ///No Device. The device handle or specifier names an inaccessible driver/server. 47 | InvalidDevice = 0xA001, 48 | 49 | ///Invalid context ID. The Context argument does not name a valid context. 50 | InvalidContext = 0xA002, 51 | 52 | ///Bad enum. A token used is not valid, or not applicable. 53 | InvalidEnum = 0xA003, 54 | 55 | ///Bad value. A value (e.g. Attribute) is not valid, or not applicable. 56 | InvalidValue = 0xA004, 57 | 58 | ///Out of memory. Unable to allocate memory. 59 | OutOfMemory = 0xA005, 60 | } 61 | 62 | /// 63 | /// Defines available parameters for . 64 | /// 65 | public enum AlcGetString : int 66 | { 67 | ///The specifier string for the default device. 68 | DefaultDeviceSpecifier = 0x1004, 69 | 70 | ///A list of available context extensions separated by spaces. 71 | Extensions = 0x1006, 72 | 73 | ///The name of the default capture device 74 | CaptureDefaultDeviceSpecifier = 0x311, // ALC_EXT_CAPTURE extension. 75 | 76 | /// a list of the default devices. 77 | DefaultAllDevicesSpecifier = 0x1012, 78 | 79 | // duplicates from AlcGetStringList: 80 | 81 | ///Will only return the first Device, not a list. Use AlcGetStringList.CaptureDeviceSpecifier. ALC_EXT_CAPTURE_EXT 82 | CaptureDeviceSpecifier = 0x310, 83 | 84 | ///Will only return the first Device, not a list. Use AlcGetStringList.DeviceSpecifier 85 | DeviceSpecifier = 0x1005, 86 | 87 | /// Will only return the first Device, not a list. Use AlcGetStringList.AllDevicesSpecifier 88 | AllDevicesSpecifier = 0x1013, 89 | } 90 | 91 | /// 92 | /// Defines available parameters for . 93 | /// 94 | public enum AlcGetStringList : int 95 | { 96 | ///The name of the specified capture device, or a list of all available capture devices if no capture device is specified. ALC_EXT_CAPTURE_EXT 97 | CaptureDeviceSpecifier = 0x310, 98 | 99 | ///The specifier strings for all available devices. ALC_ENUMERATION_EXT 100 | DeviceSpecifier = 0x1005, 101 | 102 | /// The specifier strings for all available devices. ALC_ENUMERATE_ALL_EXT 103 | AllDevicesSpecifier = 0x1013, 104 | } 105 | 106 | /// 107 | /// Defines available parameters for . 108 | /// 109 | public enum AlcGetInteger : int 110 | { 111 | ///The specification revision for this implementation (major version). NULL is an acceptable device. 112 | MajorVersion = 0x1000, 113 | 114 | ///The specification revision for this implementation (minor version). NULL is an acceptable device. 115 | MinorVersion = 0x1001, 116 | 117 | ///The size (number of ALCint values) required for a zero-terminated attributes list, for the current context. NULL is an invalid device. 118 | AttributesSize = 0x1002, 119 | 120 | ///Expects a destination of ALC_ATTRIBUTES_SIZE, and provides an attribute list for the current context of the specified device. NULL is an invalid device. 121 | AllAttributes = 0x1003, 122 | 123 | ///The number of capture samples available. NULL is an invalid device. 124 | CaptureSamples = 0x312, 125 | 126 | /// (EFX Extension) This property can be used by the application to retrieve the Major version number of the Effects Extension supported by this OpenAL implementation. As this is a Context property is should be retrieved using alcGetIntegerv. 127 | EfxMajorVersion = 0x20001, 128 | 129 | /// (EFX Extension) This property can be used by the application to retrieve the Minor version number of the Effects Extension supported by this OpenAL implementation. As this is a Context property is should be retrieved using alcGetIntegerv. 130 | EfxMinorVersion = 0x20002, 131 | 132 | /// (EFX Extension) This Context property can be passed to OpenAL during Context creation (alcCreateContext) to request a maximum number of Auxiliary Sends desired on each Source. It is not guaranteed that the desired number of sends will be available, so an application should query this property after creating the context using alcGetIntergerv. Default: 2 133 | EfxMaxAuxiliarySends = 0x20003, 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/MiniTK/Math/Size.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | 32 | namespace OpenTK 33 | { 34 | #if NO_SYSDRAWING 35 | /// 36 | /// Stores the width and height of a rectangle. 37 | /// 38 | public struct Size : IEquatable 39 | { 40 | #region Fields 41 | 42 | int width, height; 43 | 44 | #endregion 45 | 46 | #region Constructors 47 | 48 | /// 49 | /// Constructs a new Size instance. 50 | /// 51 | /// The width of this instance. 52 | /// The height of this instance. 53 | public Size(int width, int height) 54 | : this() 55 | { 56 | Width = width; 57 | Height = height; 58 | } 59 | 60 | #endregion 61 | 62 | #region Public Members 63 | 64 | /// 65 | /// Gets or sets the width of this instance. 66 | /// 67 | public int Width 68 | { 69 | get { return width; } 70 | set 71 | { 72 | if (width < 0) 73 | throw new ArgumentOutOfRangeException(); 74 | width = value; 75 | } 76 | } 77 | 78 | /// 79 | /// Gets or sets the height of this instance. 80 | /// 81 | public int Height 82 | { 83 | get { return height; } 84 | set 85 | { 86 | if (height < 0) 87 | throw new ArgumentOutOfRangeException(); 88 | height = value; 89 | } 90 | } 91 | 92 | /// 93 | /// Gets a that indicates whether this instance is empty or zero. 94 | /// 95 | public bool IsEmpty 96 | { 97 | get { return Width == 0 && Height == 0; } 98 | } 99 | 100 | /// 101 | /// Returns a Size instance equal to (0, 0). 102 | /// 103 | public static readonly Size Empty = new Size(); 104 | 105 | /// 106 | /// Returns a Size instance equal to (0, 0). 107 | /// 108 | public static readonly Size Zero = new Size(); 109 | 110 | /// 111 | /// Compares two instances for equality. 112 | /// 113 | /// The first instance. 114 | /// The second instance. 115 | /// True, if left is equal to right; false otherwise. 116 | public static bool operator ==(Size left, Size right) 117 | { 118 | return left.Equals(right); 119 | } 120 | 121 | /// 122 | /// Compares two instances for inequality. 123 | /// 124 | /// The first instance. 125 | /// The second instance. 126 | /// True, if left is not equal to right; false otherwise. 127 | public static bool operator !=(Size left, Size right) 128 | { 129 | return !left.Equals(right); 130 | } 131 | 132 | /// 133 | /// Converts an OpenTK.Size instance to a System.Drawing.Size. 134 | /// 135 | /// 136 | /// The instance to convert. 137 | /// 138 | /// 139 | /// A instance equivalent to size. 140 | /// 141 | public static implicit operator System.Drawing.Size(Size size) 142 | { 143 | return new System.Drawing.Size(size.Width, size.Height); 144 | } 145 | 146 | /// 147 | /// Converts a System.Drawing.Size instance to an OpenTK.Size. 148 | /// 149 | /// 150 | /// The instance to convert. 151 | /// 152 | /// 153 | /// A instance equivalent to size. 154 | /// 155 | public static implicit operator Size(System.Drawing.Size size) 156 | { 157 | return new Size(size.Width, size.Height); 158 | } 159 | 160 | /// 161 | /// Converts an OpenTK.Point instance to a System.Drawing.SizeF. 162 | /// 163 | /// 164 | /// The instance to convert. 165 | /// 166 | /// 167 | /// A instance equivalent to size. 168 | /// 169 | public static implicit operator System.Drawing.SizeF(Size size) 170 | { 171 | return new System.Drawing.SizeF(size.Width, size.Height); 172 | } 173 | 174 | /// 175 | /// Indicates whether this instance is equal to the specified object. 176 | /// 177 | /// The object instance to compare to. 178 | /// True, if both instances are equal; false otherwise. 179 | public override bool Equals(object obj) 180 | { 181 | if (obj is Size) 182 | return Equals((Size)obj); 183 | 184 | return false; 185 | } 186 | 187 | /// 188 | /// Returns the hash code for this instance. 189 | /// 190 | /// A that represents the hash code for this instance./> 191 | public override int GetHashCode() 192 | { 193 | return Width.GetHashCode() ^ Height.GetHashCode(); 194 | } 195 | 196 | /// 197 | /// Returns a that describes this instance. 198 | /// 199 | /// A that describes this instance. 200 | public override string ToString() 201 | { 202 | return String.Format("{{{0}, {1}}}", Width, Height); 203 | } 204 | 205 | #endregion 206 | 207 | #region IEquatable Members 208 | 209 | /// 210 | /// Indicates whether this instance is equal to the specified Size. 211 | /// 212 | /// The instance to compare to. 213 | /// True, if both instances are equal; false otherwise. 214 | public bool Equals(Size other) 215 | { 216 | return Width == other.Width && Height == other.Height; 217 | } 218 | 219 | #endregion 220 | } 221 | #endif 222 | } 223 | -------------------------------------------------------------------------------- /src/MiniTK/BindingsBase.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | using System.Reflection; 32 | using System.Runtime.InteropServices; 33 | using System.Diagnostics; 34 | 35 | namespace OpenTK 36 | { 37 | /// 38 | /// Provides a common foundation for all flat API bindings and implements the extension loading interface. 39 | /// 40 | public abstract class BindingsBase 41 | { 42 | #region Fields 43 | 44 | /// 45 | /// A reflection handle to the nested type that contains the function delegates. 46 | /// 47 | readonly protected Type DelegatesClass; 48 | 49 | /// 50 | /// A refection handle to the nested type that contains core functions (i.e. not extensions). 51 | /// 52 | readonly protected Type CoreClass; 53 | 54 | /// 55 | /// A mapping of core function names to MethodInfo handles. 56 | /// 57 | readonly protected SortedList CoreFunctionMap = new SortedList(); 58 | 59 | bool rebuildExtensionList = true; 60 | 61 | #endregion 62 | 63 | #region Constructors 64 | 65 | /// 66 | /// Constructs a new BindingsBase instance. 67 | /// 68 | public BindingsBase() 69 | { 70 | DelegatesClass = this.GetType().GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic); 71 | CoreClass = this.GetType().GetNestedType("Core", BindingFlags.Static | BindingFlags.NonPublic); 72 | 73 | if (CoreClass != null) 74 | { 75 | MethodInfo[] methods = CoreClass.GetMethods(BindingFlags.Static | BindingFlags.NonPublic); 76 | CoreFunctionMap = new SortedList(methods.Length); // Avoid resizing 77 | foreach (MethodInfo m in methods) 78 | { 79 | CoreFunctionMap.Add(m.Name, m); 80 | } 81 | } 82 | } 83 | 84 | #endregion 85 | 86 | #region Protected Members 87 | 88 | /// 89 | /// Gets or sets a that indicates whether the list of supported extensions may have changed. 90 | /// 91 | protected bool RebuildExtensionList 92 | { 93 | get { return rebuildExtensionList; } 94 | set { rebuildExtensionList = value; } 95 | } 96 | 97 | /// 98 | /// Gets an object that can be used to synchronize access to the bindings implementation. 99 | /// 100 | /// This object should be unique across bindings but consistent between bindings 101 | /// of the same type. For example, ES10.GL, OpenGL.GL and CL10.CL should all return 102 | /// unique objects, but all instances of ES10.GL should return the same object. 103 | protected abstract object SyncRoot { get; } 104 | 105 | #endregion 106 | 107 | #region Internal Members 108 | 109 | #region LoadEntryPoints 110 | 111 | internal void LoadEntryPoints(Func addressFinder) 112 | { 113 | // Using reflection is more than 3 times faster than directly loading delegates on the first 114 | // run, probably due to code generation overhead. Subsequent runs are faster with direct loading 115 | // than with reflection, but the first time is more significant. 116 | 117 | int supported = 0; 118 | 119 | FieldInfo[] delegates = DelegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); 120 | if (delegates == null) 121 | throw new InvalidOperationException("The specified type does not have any loadable extensions."); 122 | 123 | Debug.Write("Loading extensions for " + this.GetType().FullName + "... "); 124 | 125 | Stopwatch time = new Stopwatch(); 126 | time.Reset(); 127 | time.Start(); 128 | 129 | foreach (FieldInfo f in delegates) 130 | { 131 | Delegate d = LoadDelegate(f.Name, f.FieldType, addressFinder); 132 | if (d != null) 133 | ++supported; 134 | 135 | lock (SyncRoot) 136 | { 137 | f.SetValue(null, d); 138 | } 139 | } 140 | 141 | rebuildExtensionList = true; 142 | 143 | time.Stop(); 144 | Debug.Print("{0} extensions loaded in {1} ms.", supported, time.Elapsed.TotalMilliseconds); 145 | time.Reset(); 146 | } 147 | 148 | #endregion 149 | 150 | #region LoadEntryPoint 151 | 152 | internal bool LoadEntryPoint(string function, Func addressFinder) 153 | { 154 | FieldInfo f = DelegatesClass.GetField(function, BindingFlags.Static | BindingFlags.NonPublic); 155 | if (f == null) 156 | return false; 157 | 158 | Delegate old = f.GetValue(null) as Delegate; 159 | Delegate @new = LoadDelegate(f.Name, f.FieldType, addressFinder); 160 | lock (SyncRoot) 161 | { 162 | if (old.Target != @new.Target) 163 | { 164 | f.SetValue(null, @new); 165 | } 166 | } 167 | return @new != null; 168 | } 169 | 170 | #endregion 171 | 172 | #endregion 173 | 174 | #region Private Members 175 | 176 | #region LoadDelegate 177 | 178 | // Tries to load the specified core or extension function. 179 | Delegate LoadDelegate(string name, Type signature, Func addressFinder) 180 | { 181 | MethodInfo m; 182 | return 183 | GetExtensionDelegate(name, signature, addressFinder) ?? 184 | (CoreFunctionMap.TryGetValue((name.Substring(2)), out m) ? 185 | Delegate.CreateDelegate(signature, m) : null); 186 | } 187 | 188 | #endregion 189 | 190 | #region GetExtensionDelegate 191 | 192 | // Creates a System.Delegate that can be used to call a dynamically exported OpenGL function. 193 | internal Delegate GetExtensionDelegate(string name, Type signature, Func addressFinder) 194 | { 195 | IntPtr address = addressFinder.Invoke(name); 196 | 197 | if (address == IntPtr.Zero || 198 | address == new IntPtr(1) || // Workaround for buggy nvidia drivers which return 199 | address == new IntPtr(2)) // 1 or 2 instead of IntPtr.Zero for some extensions. 200 | { 201 | return null; 202 | } 203 | else 204 | { 205 | return Marshal.GetDelegateForFunctionPointer(address, signature); 206 | } 207 | } 208 | 209 | #endregion 210 | 211 | #endregion 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /MiniTK.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | 9.0.21022 7 | 2.0 8 | {0C7FC6CC-6A37-4776-B5B0-4B5A1327F603} 9 | Library 10 | OpenTK 11 | MiniTK 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\Debug 18 | DEBUG; 19 | prompt 20 | 4 21 | x86 22 | false 23 | true 24 | 25 | 26 | none 27 | false 28 | bin\Release 29 | prompt 30 | 4 31 | x86 32 | false 33 | true 34 | 35 | 36 | true 37 | full 38 | false 39 | bin\Debug 40 | DEBUG; 41 | prompt 42 | 4 43 | false 44 | true 45 | 46 | 47 | none 48 | false 49 | bin\Release 50 | prompt 51 | 4 52 | true 53 | false 54 | 55 | 56 | true 57 | full 58 | false 59 | bin\Debug 60 | DEBUG; 61 | prompt 62 | 4 63 | x64 64 | true 65 | false 66 | 67 | 68 | none 69 | false 70 | bin\Release 71 | prompt 72 | 4 73 | x64 74 | false 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | Always 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /src/MiniTK/Audio/AudioDeviceEnumerator.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Collections.ObjectModel; 31 | using System.Diagnostics; 32 | 33 | using OpenTK.Audio.OpenAL; 34 | 35 | namespace OpenTK.Audio 36 | { 37 | internal static class AudioDeviceEnumerator 38 | { 39 | #region All device strings 40 | 41 | private static readonly List available_playback_devices = new List(); 42 | private static readonly List available_recording_devices = new List(); 43 | 44 | internal static IList AvailablePlaybackDevices 45 | { 46 | get 47 | { 48 | return available_playback_devices.AsReadOnly(); 49 | } 50 | } 51 | internal static IList AvailableRecordingDevices 52 | { 53 | get 54 | { 55 | return available_recording_devices.AsReadOnly(); 56 | } 57 | } 58 | 59 | #endregion All device strings 60 | 61 | #region Default device strings 62 | 63 | private static string default_playback_device; 64 | internal static string DefaultPlaybackDevice 65 | { 66 | get 67 | { 68 | return default_playback_device; 69 | } 70 | } 71 | 72 | private static string default_recording_device; 73 | internal static string DefaultRecordingDevice 74 | { 75 | get 76 | { 77 | return default_recording_device; 78 | } 79 | } 80 | 81 | #endregion Default device strings 82 | 83 | #region Is OpenAL supported? 84 | 85 | private static bool openal_supported = true; 86 | internal static bool IsOpenALSupported 87 | { 88 | get 89 | { 90 | return openal_supported; 91 | } 92 | } 93 | 94 | #endregion Is OpenAL supported? 95 | 96 | #region Alc Version number 97 | 98 | internal enum AlcVersion 99 | { 100 | Alc1_0, 101 | Alc1_1 102 | } 103 | 104 | private static AlcVersion version; 105 | internal static AlcVersion Version 106 | { 107 | get 108 | { 109 | return version; 110 | } 111 | } 112 | 113 | #endregion Alc Version number 114 | 115 | #region Constructors 116 | 117 | // Loads all available audio devices into the available_*_devices lists. 118 | static AudioDeviceEnumerator() 119 | { 120 | IntPtr dummy_device = IntPtr.Zero; 121 | ContextHandle dummy_context = ContextHandle.Zero; 122 | 123 | try 124 | { 125 | Debug.WriteLine("Enumerating audio devices."); 126 | Debug.Indent(); 127 | 128 | // need a dummy context for correct results 129 | dummy_device = Alc.OpenDevice(null); 130 | dummy_context = Alc.CreateContext(dummy_device, (int[])null); 131 | bool dummy_success = Alc.MakeContextCurrent(dummy_context); 132 | AlcError dummy_error = Alc.GetError(dummy_device); 133 | if (!dummy_success || dummy_error != AlcError.NoError) 134 | { 135 | throw new AudioContextException("Failed to create dummy Context. Device (" + dummy_device.ToString() + 136 | ") Context (" + dummy_context.Handle.ToString() + 137 | ") MakeContextCurrent " + (dummy_success ? "succeeded" : "failed") + 138 | ", Alc Error (" + dummy_error.ToString() + ") " + Alc.GetString(IntPtr.Zero, (AlcGetString)dummy_error)); 139 | } 140 | 141 | // Get a list of all known playback devices, using best extension available 142 | if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT")) 143 | { 144 | version = AlcVersion.Alc1_1; 145 | if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATE_ALL_EXT")) 146 | { 147 | available_playback_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.AllDevicesSpecifier)); 148 | default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultAllDevicesSpecifier); 149 | } 150 | else 151 | { 152 | available_playback_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.DeviceSpecifier)); 153 | default_playback_device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier); 154 | } 155 | } 156 | else 157 | { 158 | version = AlcVersion.Alc1_0; 159 | Debug.Print("Device enumeration extension not available. Failed to enumerate playback devices."); 160 | } 161 | AlcError playback_err = Alc.GetError(dummy_device); 162 | if (playback_err != AlcError.NoError) 163 | throw new AudioContextException("Alc Error occured when querying available playback devices. " + playback_err.ToString()); 164 | 165 | // Get a list of all known recording devices, at least ALC_ENUMERATION_EXT is needed too 166 | if (version == AlcVersion.Alc1_1 && Alc.IsExtensionPresent(IntPtr.Zero, "ALC_EXT_CAPTURE")) 167 | { 168 | available_recording_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.CaptureDeviceSpecifier)); 169 | default_recording_device = Alc.GetString(IntPtr.Zero, AlcGetString.CaptureDefaultDeviceSpecifier); 170 | } 171 | else 172 | { 173 | Debug.Print("Capture extension not available. Failed to enumerate recording devices."); 174 | } 175 | AlcError record_err = Alc.GetError(dummy_device); 176 | if (record_err != AlcError.NoError) 177 | throw new AudioContextException("Alc Error occured when querying available recording devices. " + record_err.ToString()); 178 | 179 | #if DEBUG 180 | Debug.WriteLine("Found playback devices:"); 181 | foreach (string s in available_playback_devices) 182 | Debug.WriteLine(s); 183 | 184 | Debug.WriteLine("Default playback device: " + default_playback_device); 185 | 186 | Debug.WriteLine("Found recording devices:"); 187 | foreach (string s in available_recording_devices) 188 | Debug.WriteLine(s); 189 | 190 | Debug.WriteLine("Default recording device: " + default_recording_device); 191 | #endif 192 | } 193 | catch (DllNotFoundException e) 194 | { 195 | Trace.WriteLine(e.ToString()); 196 | openal_supported = false; 197 | } 198 | catch (AudioContextException ace) 199 | { 200 | Trace.WriteLine(ace.ToString()); 201 | openal_supported = false; 202 | } 203 | finally 204 | { 205 | Debug.Unindent(); 206 | 207 | // clean up the dummy context 208 | Alc.MakeContextCurrent(ContextHandle.Zero); 209 | if (dummy_context != ContextHandle.Zero && dummy_context.Handle != IntPtr.Zero) 210 | Alc.DestroyContext(dummy_context); 211 | if (dummy_device != IntPtr.Zero) 212 | Alc.CloseDevice(dummy_device); 213 | } 214 | } 215 | 216 | #endregion 217 | } 218 | } -------------------------------------------------------------------------------- /src/MiniTK/Math/Point.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | 32 | namespace OpenTK 33 | { 34 | #if NO_SYSDRAWING 35 | /// 36 | /// Defines a point on a two-dimensional plane. 37 | /// 38 | public struct Point : IEquatable 39 | { 40 | #region Fields 41 | 42 | int x, y; 43 | 44 | #endregion 45 | 46 | #region Constructors 47 | 48 | /// 49 | /// Constructs a new Point instance. 50 | /// 51 | /// The X coordinate of this instance. 52 | /// The Y coordinate of this instance. 53 | public Point(int x, int y) 54 | : this() 55 | { 56 | X = x; 57 | Y = y; 58 | } 59 | 60 | #endregion 61 | 62 | #region Public Members 63 | 64 | /// 65 | /// Gets a that indicates whether this instance is empty or zero. 66 | /// 67 | public bool IsEmpty { get { return X == 0 && Y == 0; } } 68 | 69 | /// 70 | /// Gets or sets the X coordinate of this instance. 71 | /// 72 | public int X { get { return x; } set { x = value; } } 73 | 74 | /// 75 | /// Gets or sets the Y coordinate of this instance. 76 | /// 77 | public int Y { get { return y; } set { y = value; } } 78 | 79 | /// 80 | /// Returns the Point (0, 0). 81 | /// 82 | public static readonly Point Zero = new Point(); 83 | 84 | /// 85 | /// Returns the Point (0, 0). 86 | /// 87 | public static readonly Point Empty = new Point(); 88 | 89 | /// 90 | /// Translates the specified Point by the specified Size. 91 | /// 92 | /// 93 | /// The instance to translate. 94 | /// 95 | /// 96 | /// The instance to translate point with. 97 | /// 98 | /// 99 | /// A new instance translated by size. 100 | /// 101 | public static Point operator +(Point point, Size size) 102 | { 103 | return new Point(point.X + size.Width, point.Y + size.Height); 104 | } 105 | 106 | /// 107 | /// Translates the specified Point by the negative of the specified Size. 108 | /// 109 | /// 110 | /// The instance to translate. 111 | /// 112 | /// 113 | /// The instance to translate point with. 114 | /// 115 | /// 116 | /// A new instance translated by size. 117 | /// 118 | public static Point operator -(Point point, Size size) 119 | { 120 | return new Point(point.X - size.Width, point.Y - size.Height); 121 | } 122 | 123 | /// 124 | /// Compares two instances for equality. 125 | /// 126 | /// The first instance. 127 | /// The second instance. 128 | /// True, if left is equal to right; false otherwise. 129 | public static bool operator ==(Point left, Point right) 130 | { 131 | return left.Equals(right); 132 | } 133 | 134 | /// 135 | /// Compares two instances for inequality. 136 | /// 137 | /// The first instance. 138 | /// The second instance. 139 | /// True, if left is not equal to right; false otherwise. 140 | public static bool operator !=(Point left, Point right) 141 | { 142 | return !left.Equals(right); 143 | } 144 | 145 | /// 146 | /// Converts an OpenTK.Point instance to a System.Drawing.Point. 147 | /// 148 | /// 149 | /// The instance to convert. 150 | /// 151 | /// 152 | /// A instance equivalent to point. 153 | /// 154 | public static implicit operator System.Drawing.Point(Point point) 155 | { 156 | return new System.Drawing.Point(point.X, point.Y); 157 | } 158 | 159 | /// 160 | /// Converts a System.Drawing.Point instance to an OpenTK.Point. 161 | /// 162 | /// 163 | /// The instance to convert. 164 | /// 165 | /// 166 | /// A instance equivalent to point. 167 | /// 168 | public static implicit operator Point(System.Drawing.Point point) 169 | { 170 | return new Point(point.X, point.Y); 171 | } 172 | 173 | /// 174 | /// Converts an OpenTK.Point instance to a System.Drawing.PointF. 175 | /// 176 | /// 177 | /// The instance to convert. 178 | /// 179 | /// 180 | /// A instance equivalent to point. 181 | /// 182 | public static implicit operator System.Drawing.PointF(Point point) 183 | { 184 | return new System.Drawing.PointF(point.X, point.Y); 185 | } 186 | 187 | /// 188 | /// Indicates whether this instance is equal to the specified object. 189 | /// 190 | /// The object instance to compare to. 191 | /// True, if both instances are equal; false otherwise. 192 | public override bool Equals(object obj) 193 | { 194 | if (obj is Point) 195 | return Equals((Point)obj); 196 | 197 | return false; 198 | } 199 | 200 | /// 201 | /// Returns the hash code for this instance. 202 | /// 203 | /// A that represents the hash code for this instance./> 204 | public override int GetHashCode() 205 | { 206 | return X.GetHashCode() ^ Y.GetHashCode(); 207 | } 208 | 209 | /// 210 | /// Returns a that describes this instance. 211 | /// 212 | /// A that describes this instance. 213 | public override string ToString() 214 | { 215 | return String.Format("{{{0}, {1}}}", X, Y); 216 | } 217 | 218 | #endregion 219 | 220 | #region IEquatable Members 221 | 222 | /// 223 | /// Indicates whether this instance is equal to the specified Point. 224 | /// 225 | /// The instance to compare to. 226 | /// True, if both instances are equal; false otherwise. 227 | public bool Equals(Point other) 228 | { 229 | return X == other.X && Y == other.Y; 230 | } 231 | 232 | #endregion 233 | } 234 | #endif 235 | } 236 | -------------------------------------------------------------------------------- /src/MiniTK/Audio/OpenAL/AL/XRamExtension.cs: -------------------------------------------------------------------------------- 1 | #region --- OpenTK.OpenAL License --- 2 | /* XRamExtension.cs 3 | * C header: \OpenAL 1.1 SDK\include\xram.h 4 | * Spec: ? 5 | * Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos 6 | * See license.txt for license details (MIT) 7 | * http://www.OpenTK.net */ 8 | #endregion 9 | 10 | using System; 11 | using System.Diagnostics; 12 | using System.Runtime.InteropServices; 13 | 14 | // flibit Added This!!! 15 | #pragma warning disable 3021 16 | #pragma warning disable 3014 17 | #pragma warning disable 3003 18 | 19 | namespace OpenTK.Audio.OpenAL 20 | { 21 | 22 | /// 23 | ///The X-Ram Extension is provided on the top-end Sound Blaster X-Fi solutions (Sound Blaster X-Fi Fatal1ty, Sound Blaster X-Fi Elite Pro, or later). 24 | ///These products feature 64MB of X-Ram that can only be used for audio purposes, which can be controlled by this Extension. 25 | /// 26 | [CLSCompliant(true)] 27 | public sealed class XRamExtension 28 | { 29 | #region Instance state 30 | 31 | private bool _valid = false; 32 | 33 | /// Returns True if the X-Ram Extension has been found and could be initialized. 34 | public bool IsInitialized 35 | { 36 | get { return _valid; } 37 | } 38 | 39 | #endregion Instance state 40 | 41 | #region X-RAM Function pointer definitions 42 | 43 | // [CLSCompliant(false)] 44 | private delegate bool Delegate_SetBufferMode(int n, ref uint buffers, int value); 45 | //typedef ALboolean (__cdecl *EAXSetBufferMode)(ALsizei n, ALuint *buffers, ALint value); 46 | 47 | // [CLSCompliant( false )] 48 | private delegate int Delegate_GetBufferMode(uint buffer, IntPtr value); 49 | //typedef ALenum (__cdecl *EAXGetBufferMode)(ALuint buffer, ALint *value); 50 | 51 | //[CLSCompliant(false)] 52 | private Delegate_SetBufferMode Imported_SetBufferMode; 53 | //[CLSCompliant(false)] 54 | private Delegate_GetBufferMode Imported_GetBufferMode; 55 | 56 | #endregion X-RAM Function pointer definitions 57 | 58 | #region X-RAM Tokens 59 | 60 | private int AL_EAX_RAM_SIZE, AL_EAX_RAM_FREE, 61 | AL_STORAGE_AUTOMATIC, AL_STORAGE_HARDWARE, AL_STORAGE_ACCESSIBLE; 62 | 63 | #endregion X-RAM Tokens 64 | 65 | #region Constructor / Extension Loading 66 | 67 | /// 68 | /// Constructs a new XRamExtension instance. 69 | /// 70 | public XRamExtension() 71 | { // Query if Extension supported and retrieve Tokens/Pointers if it is. 72 | _valid = false; 73 | if (AL.IsExtensionPresent("EAX-RAM") == false) 74 | return; 75 | 76 | AL_EAX_RAM_SIZE = AL.GetEnumValue("AL_EAX_RAM_SIZE"); 77 | AL_EAX_RAM_FREE = AL.GetEnumValue("AL_EAX_RAM_FREE"); 78 | AL_STORAGE_AUTOMATIC = AL.GetEnumValue("AL_STORAGE_AUTOMATIC"); 79 | AL_STORAGE_HARDWARE = AL.GetEnumValue("AL_STORAGE_HARDWARE"); 80 | AL_STORAGE_ACCESSIBLE = AL.GetEnumValue("AL_STORAGE_ACCESSIBLE"); 81 | 82 | // Console.WriteLine("RamSize: {0} RamFree: {1} StorageAuto: {2} StorageHW: {3} StorageAccess: {4}",AL_EAX_RAM_SIZE,AL_EAX_RAM_FREE,AL_STORAGE_AUTOMATIC,AL_STORAGE_HARDWARE,AL_STORAGE_ACCESSIBLE); 83 | 84 | if (AL_EAX_RAM_SIZE == 0 || 85 | AL_EAX_RAM_FREE == 0 || 86 | AL_STORAGE_AUTOMATIC == 0 || 87 | AL_STORAGE_HARDWARE == 0 || 88 | AL_STORAGE_ACCESSIBLE == 0) 89 | { 90 | Debug.WriteLine("X-Ram: Token values could not be retrieved."); 91 | return; 92 | } 93 | 94 | // Console.WriteLine("Free Ram: {0} / {1}",GetRamFree( ),GetRamSize( )); 95 | 96 | try 97 | { 98 | Imported_GetBufferMode = (Delegate_GetBufferMode)Marshal.GetDelegateForFunctionPointer(AL.GetProcAddress("EAXGetBufferMode"), typeof(Delegate_GetBufferMode)); 99 | Imported_SetBufferMode = (Delegate_SetBufferMode)Marshal.GetDelegateForFunctionPointer(AL.GetProcAddress("EAXSetBufferMode"), typeof(Delegate_SetBufferMode)); 100 | } 101 | catch (Exception e) 102 | { 103 | Debug.WriteLine("X-Ram: Attempt to marshal function pointers with AL.GetProcAddress failed. " + e.ToString()); 104 | return; 105 | } 106 | 107 | _valid = true; 108 | } 109 | 110 | #endregion Constructor / Extension Loading 111 | 112 | #region Public Methods 113 | 114 | /// Query total amount of X-RAM in bytes. 115 | public int GetRamSize 116 | { 117 | get 118 | { 119 | return AL.Get((ALGetInteger)AL_EAX_RAM_SIZE); 120 | } 121 | } 122 | 123 | /// Query free X-RAM available in bytes. 124 | public int GetRamFree 125 | { 126 | get 127 | { 128 | return AL.Get((ALGetInteger)AL_EAX_RAM_FREE); 129 | } 130 | } 131 | 132 | /// This enum is used to abstract the need of using AL.GetEnumValue() with the Extension. The values do NOT correspond to AL_STORAGE_* tokens! 133 | public enum XRamStorage : byte 134 | { 135 | /// Put an Open AL Buffer into X-RAM if memory is available, otherwise use host RAM. This is the default mode. 136 | Automatic = 0, 137 | /// Force an Open AL Buffer into X-RAM, good for non-streaming buffers. 138 | Hardware = 1, 139 | /// Force an Open AL Buffer into 'accessible' (currently host) RAM, good for streaming buffers. 140 | Accessible = 2, 141 | } 142 | 143 | /// This function is used to set the storage Mode of an array of OpenAL Buffers. 144 | /// The number of OpenAL Buffers pointed to by buffer. 145 | /// An array of OpenAL Buffer handles. 146 | /// The storage mode that should be used for all the given buffers. Should be the value of one of the following enum names: XRamStorage.Automatic, XRamStorage.Hardware, XRamStorage.Accessible 147 | /// True if all the Buffers were successfully set to the requested storage mode, False otherwise. 148 | [CLSCompliant(false)] 149 | public bool SetBufferMode(int n, ref uint buffer, XRamStorage mode) 150 | { 151 | switch (mode) 152 | { 153 | case XRamStorage.Accessible: 154 | return Imported_SetBufferMode(n, ref buffer, AL_STORAGE_ACCESSIBLE); 155 | case XRamStorage.Hardware: 156 | return Imported_SetBufferMode(n, ref buffer, AL_STORAGE_HARDWARE); 157 | default: 158 | return Imported_SetBufferMode(n, ref buffer, AL_STORAGE_AUTOMATIC); 159 | } 160 | } 161 | 162 | /// This function is used to set the storage Mode of an array of OpenAL Buffers. 163 | /// The number of OpenAL Buffers pointed to by buffer. 164 | /// An array of OpenAL Buffer handles. 165 | /// The storage mode that should be used for all the given buffers. Should be the value of one of the following enum names: XRamStorage.Automatic, XRamStorage.Hardware, XRamStorage.Accessible 166 | /// True if all the Buffers were successfully set to the requested storage mode, False otherwise. 167 | [CLSCompliant(true)] 168 | public bool SetBufferMode(int n, ref int buffer, XRamStorage mode) 169 | { 170 | uint temp = (uint)buffer; 171 | return SetBufferMode(n, ref temp, mode); 172 | } 173 | 174 | /// This function is used to retrieve the storage Mode of a single OpenAL Buffer. 175 | /// The handle of an OpenAL Buffer. 176 | /// The current Mode of the Buffer. 177 | [CLSCompliant(false)] 178 | public XRamStorage GetBufferMode(ref uint buffer) 179 | { 180 | int tempresult = Imported_GetBufferMode(buffer, IntPtr.Zero); // IntPtr.Zero due to the parameter being unused/reserved atm 181 | 182 | if (tempresult == AL_STORAGE_ACCESSIBLE) 183 | return XRamStorage.Accessible; 184 | if (tempresult == AL_STORAGE_HARDWARE) 185 | return XRamStorage.Hardware; 186 | // default: 187 | return XRamStorage.Automatic; 188 | } 189 | 190 | /// This function is used to retrieve the storage Mode of a single OpenAL Buffer. 191 | /// The handle of an OpenAL Buffer. 192 | /// The current Mode of the Buffer. 193 | [CLSCompliant(true)] 194 | public XRamStorage GetBufferMode(ref int buffer) 195 | { 196 | uint temp = (uint)buffer; 197 | return GetBufferMode(ref temp); 198 | } 199 | 200 | #endregion Public Methods 201 | } 202 | 203 | } 204 | 205 | // flibit Added This!!! 206 | #pragma warning restore 3021 207 | #pragma warning restore 3014 208 | #pragma warning restore 3003 -------------------------------------------------------------------------------- /src/MiniTK/Math/BezierCurve.cs: -------------------------------------------------------------------------------- 1 | #region --- License --- 2 | /* Licensed under the MIT/X11 license. 3 | * Copyright (c) 2006-2008 the OpenTK Team. 4 | * This notice may not be removed from any source distribution. 5 | * See license.txt for licensing detailed licensing details. 6 | * 7 | * Contributions by Georg W�chter. 8 | */ 9 | #endregion 10 | 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Text; 14 | 15 | namespace OpenTK 16 | { 17 | /// 18 | /// Represents a bezier curve with as many points as you want. 19 | /// 20 | [Serializable] 21 | public struct BezierCurve 22 | { 23 | #region Fields 24 | 25 | private List points; 26 | 27 | /// 28 | /// The parallel value. 29 | /// 30 | /// This value defines whether the curve should be calculated as a 31 | /// parallel curve to the original bezier curve. A value of 0.0f represents 32 | /// the original curve, 5.0f i.e. stands for a curve that has always a distance 33 | /// of 5.0f to the orignal curve at any point. 34 | public float Parallel; 35 | 36 | #endregion 37 | 38 | #region Properties 39 | 40 | /// 41 | /// Gets the points of this curve. 42 | /// 43 | /// The first point and the last points represent the anchor points. 44 | public IList Points 45 | { 46 | get 47 | { 48 | return points; 49 | } 50 | } 51 | 52 | #endregion 53 | 54 | #region Constructors 55 | 56 | /// 57 | /// Constructs a new . 58 | /// 59 | /// The points. 60 | public BezierCurve(IEnumerable points) 61 | { 62 | if (points == null) 63 | throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); 64 | 65 | this.points = new List(points); 66 | this.Parallel = 0.0f; 67 | } 68 | 69 | /// 70 | /// Constructs a new . 71 | /// 72 | /// The points. 73 | public BezierCurve(params Vector2[] points) 74 | { 75 | if (points == null) 76 | throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); 77 | 78 | this.points = new List(points); 79 | this.Parallel = 0.0f; 80 | } 81 | 82 | /// 83 | /// Constructs a new . 84 | /// 85 | /// The parallel value. 86 | /// The points. 87 | public BezierCurve(float parallel, params Vector2[] points) 88 | { 89 | if (points == null) 90 | throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); 91 | 92 | this.Parallel = parallel; 93 | this.points = new List(points); 94 | } 95 | 96 | /// 97 | /// Constructs a new . 98 | /// 99 | /// The parallel value. 100 | /// The points. 101 | public BezierCurve(float parallel, IEnumerable points) 102 | { 103 | if (points == null) 104 | throw new ArgumentNullException("points", "Must point to a valid list of Vector2 structures."); 105 | 106 | this.Parallel = parallel; 107 | this.points = new List(points); 108 | } 109 | 110 | #endregion 111 | 112 | #region Functions 113 | 114 | 115 | /// 116 | /// Calculates the point with the specified t. 117 | /// 118 | /// The t value, between 0.0f and 1.0f. 119 | /// Resulting point. 120 | public Vector2 CalculatePoint(float t) 121 | { 122 | return BezierCurve.CalculatePoint(points, t, Parallel); 123 | } 124 | 125 | /// 126 | /// Calculates the length of this bezier curve. 127 | /// 128 | /// The precision. 129 | /// Length of curve. 130 | /// The precision gets better as the 131 | /// value gets smaller. 132 | public float CalculateLength(float precision) 133 | { 134 | return BezierCurve.CalculateLength(points, precision, Parallel); 135 | } 136 | 137 | #region Static methods 138 | 139 | /// 140 | /// Calculates the length of the specified bezier curve. 141 | /// 142 | /// The points. 143 | /// The precision value. 144 | /// The precision gets better as the 145 | /// value gets smaller. 146 | public static float CalculateLength(IList points, float precision) 147 | { 148 | return BezierCurve.CalculateLength(points, precision, 0.0f); 149 | } 150 | 151 | /// 152 | /// Calculates the length of the specified bezier curve. 153 | /// 154 | /// The points. 155 | /// The precision value. 156 | /// The parallel value. 157 | /// Length of curve. 158 | /// The precision gets better as the 159 | /// value gets smaller. 160 | /// The parameter defines whether the curve should be calculated as a 161 | /// parallel curve to the original bezier curve. A value of 0.0f represents 162 | /// the original curve, 5.0f represents a curve that has always a distance 163 | /// of 5.0f to the orignal curve. 164 | public static float CalculateLength(IList points, float precision, float parallel) 165 | { 166 | float length = 0.0f; 167 | Vector2 old = BezierCurve.CalculatePoint(points, 0.0f, parallel); 168 | 169 | for (float i = precision; i < (1.0f + precision); i += precision) 170 | { 171 | Vector2 n = CalculatePoint(points, i, parallel); 172 | length += (n - old).Length; 173 | old = n; 174 | } 175 | 176 | return length; 177 | } 178 | 179 | /// 180 | /// Calculates the point on the given bezier curve with the specified t parameter. 181 | /// 182 | /// The points. 183 | /// The t parameter, a value between 0.0f and 1.0f. 184 | /// Resulting point. 185 | public static Vector2 CalculatePoint(IList points, float t) 186 | { 187 | return BezierCurve.CalculatePoint(points, t, 0.0f); 188 | } 189 | 190 | /// 191 | /// Calculates the point on the given bezier curve with the specified t parameter. 192 | /// 193 | /// The points. 194 | /// The t parameter, a value between 0.0f and 1.0f. 195 | /// The parallel value. 196 | /// Resulting point. 197 | /// The parameter defines whether the curve should be calculated as a 198 | /// parallel curve to the original bezier curve. A value of 0.0f represents 199 | /// the original curve, 5.0f represents a curve that has always a distance 200 | /// of 5.0f to the orignal curve. 201 | public static Vector2 CalculatePoint(IList points, float t, float parallel) 202 | { 203 | Vector2 r = new Vector2(); 204 | double c = 1.0d - (double)t; 205 | float temp; 206 | int i = 0; 207 | 208 | foreach (Vector2 pt in points) 209 | { 210 | temp = (float)MathHelper.BinomialCoefficient(points.Count - 1, i) * (float)(System.Math.Pow(t, i) * 211 | System.Math.Pow(c, (points.Count - 1) - i)); 212 | 213 | r.X += temp * pt.X; 214 | r.Y += temp * pt.Y; 215 | i++; 216 | } 217 | 218 | if (parallel == 0.0f) 219 | return r; 220 | 221 | Vector2 perpendicular = new Vector2(); 222 | 223 | if (t != 0.0f) 224 | perpendicular = r - BezierCurve.CalculatePointOfDerivative(points, t); 225 | else 226 | perpendicular = points[1] - points[0]; 227 | 228 | return r + Vector2.Normalize(perpendicular).PerpendicularRight * parallel; 229 | } 230 | 231 | /// 232 | /// Calculates the point with the specified t of the derivative of the given bezier function. 233 | /// 234 | /// The points. 235 | /// The t parameter, value between 0.0f and 1.0f. 236 | /// Resulting point. 237 | private static Vector2 CalculatePointOfDerivative(IList points, float t) 238 | { 239 | Vector2 r = new Vector2(); 240 | double c = 1.0d - (double)t; 241 | float temp; 242 | int i = 0; 243 | 244 | foreach (Vector2 pt in points) 245 | { 246 | temp = (float)MathHelper.BinomialCoefficient(points.Count - 2, i) * (float)(System.Math.Pow(t, i) * 247 | System.Math.Pow(c, (points.Count - 2) - i)); 248 | 249 | r.X += temp * pt.X; 250 | r.Y += temp * pt.Y; 251 | i++; 252 | } 253 | 254 | return r; 255 | } 256 | 257 | #endregion 258 | 259 | #endregion 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /src/MiniTK/BlittableValueType.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2010 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | using System.Runtime.InteropServices; 32 | using System.Diagnostics; 33 | using System.Reflection; 34 | 35 | // flibit Added This!!! 36 | #pragma warning disable 3021 37 | 38 | namespace OpenTK 39 | { 40 | #region BlittableValueType 41 | 42 | /// 43 | /// Checks whether the specified type parameter is a blittable value type. 44 | /// 45 | /// 46 | /// A blittable value type is a struct that only references other value types recursively, 47 | /// which allows it to be passed to unmanaged code directly. 48 | /// 49 | public static class BlittableValueType 50 | { 51 | #region Fields 52 | 53 | static readonly Type Type; 54 | static readonly int stride; 55 | 56 | #endregion 57 | 58 | #region Constructors 59 | 60 | static BlittableValueType() 61 | { 62 | Type = typeof(T); 63 | if (Type.IsValueType && !Type.IsGenericType) 64 | { 65 | // Does this support generic types? On Mono 2.4.3 it does 66 | // On .Net it doesn't. 67 | // http://msdn.microsoft.com/en-us/library/5s4920fa.aspx 68 | stride = Marshal.SizeOf(typeof(T)); 69 | } 70 | } 71 | 72 | #endregion 73 | 74 | #region Public Members 75 | 76 | /// 77 | /// Gets the size of the type in bytes or 0 for non-blittable types. 78 | /// 79 | /// 80 | /// This property returns 0 for non-blittable types. 81 | /// 82 | public static int Stride { get { return stride; } } 83 | 84 | #region Check 85 | 86 | /// 87 | /// Checks whether the current typename T is blittable. 88 | /// 89 | /// True if T is blittable; false otherwise. 90 | public static bool Check() 91 | { 92 | return Check(Type); 93 | } 94 | 95 | /// 96 | /// Checks whether type is a blittable value type. 97 | /// 98 | /// A System.Type to check. 99 | /// True if T is blittable; false otherwise. 100 | public static bool Check(Type type) 101 | { 102 | if (!CheckStructLayoutAttribute(type)) 103 | 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); 104 | 105 | return CheckType(type); 106 | } 107 | 108 | #endregion 109 | 110 | #endregion 111 | 112 | #region Private Members 113 | 114 | // Checks whether the parameter is a primitive type or consists of primitive types recursively. 115 | // Throws a NotSupportedException if it is not. 116 | static bool CheckType(Type type) 117 | { 118 | //Debug.Print("Checking type {0} (size: {1} bytes).", type.Name, Marshal.SizeOf(type)); 119 | if (type.IsPrimitive) 120 | return true; 121 | 122 | if (!type.IsValueType) 123 | return false; 124 | 125 | FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); 126 | Debug.Indent(); 127 | foreach (FieldInfo field in fields) 128 | { 129 | if (!CheckType(field.FieldType)) 130 | return false; 131 | } 132 | Debug.Unindent(); 133 | 134 | return Stride != 0; 135 | } 136 | 137 | // Checks whether the specified struct defines [StructLayout(LayoutKind.Sequential, Pack=1)] 138 | // or [StructLayout(LayoutKind.Explicit)] 139 | static bool CheckStructLayoutAttribute(Type type) 140 | { 141 | StructLayoutAttribute[] attr = (StructLayoutAttribute[]) 142 | type.GetCustomAttributes(typeof(StructLayoutAttribute), true); 143 | 144 | if ((attr == null) || 145 | (attr != null && attr.Length > 0 && attr[0].Value != LayoutKind.Explicit && attr[0].Pack != 1)) 146 | return false; 147 | 148 | return true; 149 | } 150 | 151 | #endregion 152 | } 153 | 154 | #endregion 155 | 156 | #region BlittableValueType 157 | 158 | /// 159 | /// Checks whether the specified type parameter is a blittable value type. 160 | /// 161 | /// 162 | /// A blittable value type is a struct that only references other value types recursively, 163 | /// which allows it to be passed to unmanaged code directly. 164 | /// 165 | public static class BlittableValueType 166 | { 167 | #region Check 168 | 169 | /// 170 | /// Checks whether type is a blittable value type. 171 | /// 172 | /// An instance of the type to check. 173 | /// True if T is blittable; false otherwise. 174 | public static bool Check(T type) 175 | { 176 | return BlittableValueType.Check(); 177 | } 178 | 179 | /// 180 | /// Checks whether type is a blittable value type. 181 | /// 182 | /// An instance of the type to check. 183 | /// True if T is blittable; false otherwise. 184 | public static bool Check(T[] type) 185 | { 186 | return BlittableValueType.Check(); 187 | } 188 | 189 | /// 190 | /// Checks whether type is a blittable value type. 191 | /// 192 | /// An instance of the type to check. 193 | /// True if T is blittable; false otherwise. 194 | public static bool Check(T[,] type) 195 | { 196 | return BlittableValueType.Check(); 197 | } 198 | 199 | /// 200 | /// Checks whether type is a blittable value type. 201 | /// 202 | /// An instance of the type to check. 203 | /// True if T is blittable; false otherwise. 204 | public static bool Check(T[, ,] type) 205 | { 206 | return BlittableValueType.Check(); 207 | } 208 | 209 | /// 210 | /// Checks whether type is a blittable value type. 211 | /// 212 | /// An instance of the type to check. 213 | /// True if T is blittable; false otherwise. 214 | [CLSCompliant(false)] 215 | public static bool Check(T[][] type) 216 | { 217 | return BlittableValueType.Check(); 218 | } 219 | 220 | #endregion 221 | 222 | #region StrideOf 223 | 224 | /// 225 | /// Returns the size of the specified value type in bytes or 0 if the type is not blittable. 226 | /// 227 | /// The value type. Must be blittable. 228 | /// An instance of the value type. 229 | /// An integer, specifying the size of the type in bytes. 230 | /// Occurs when type is not blittable. 231 | public static int StrideOf(T type) 232 | { 233 | if (!Check(type)) 234 | throw new ArgumentException("type"); 235 | 236 | return BlittableValueType.Stride; 237 | } 238 | 239 | /// 240 | /// Returns the size of a single array element in bytes or 0 if the element is not blittable. 241 | /// 242 | /// The value type. 243 | /// An instance of the value type. 244 | /// An integer, specifying the size of the type in bytes. 245 | /// Occurs when type is not blittable. 246 | public static int StrideOf(T[] type) 247 | { 248 | if (!Check(type)) 249 | throw new ArgumentException("type"); 250 | 251 | return BlittableValueType.Stride; 252 | } 253 | 254 | /// 255 | /// Returns the size of a single array element in bytes or 0 if the element is not blittable. 256 | /// 257 | /// The value type. 258 | /// An instance of the value type. 259 | /// An integer, specifying the size of the type in bytes. 260 | /// Occurs when type is not blittable. 261 | public static int StrideOf(T[,] type) 262 | { 263 | if (!Check(type)) 264 | throw new ArgumentException("type"); 265 | 266 | return BlittableValueType.Stride; 267 | } 268 | 269 | /// 270 | /// Returns the size of a single array element in bytes or 0 if the element is not blittable. 271 | /// 272 | /// The value type. 273 | /// An instance of the value type. 274 | /// An integer, specifying the size of the type in bytes. 275 | /// Occurs when type is not blittable. 276 | public static int StrideOf(T[, ,] type) 277 | { 278 | if (!Check(type)) 279 | throw new ArgumentException("type"); 280 | 281 | return BlittableValueType.Stride; 282 | } 283 | 284 | #endregion 285 | } 286 | 287 | #endregion 288 | } 289 | 290 | // flibit Added This!!! 291 | #pragma warning restore 3021 -------------------------------------------------------------------------------- /src/MiniTK/Math/MathHelper.cs: -------------------------------------------------------------------------------- 1 | #region --- License --- 2 | /* Licensed under the MIT/X11 license. 3 | * Copyright (c) 2006-2008 the OpenTK Team. 4 | * This notice may not be removed from any source distribution. 5 | * See license.txt for licensing detailed licensing details. 6 | * 7 | * Contributions by Andy Gill, James Talton and Georg Wächter. 8 | */ 9 | #endregion 10 | 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Text; 14 | 15 | namespace OpenTK 16 | { 17 | /// 18 | /// Contains common mathematical functions and constants. 19 | /// 20 | public static class MathHelper 21 | { 22 | #region Fields 23 | 24 | /// 25 | /// Defines the value of Pi as a . 26 | /// 27 | public const float Pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382f; 28 | 29 | /// 30 | /// Defines the value of Pi divided by two as a . 31 | /// 32 | public const float PiOver2 = Pi / 2; 33 | 34 | /// 35 | /// Defines the value of Pi divided by three as a . 36 | /// 37 | public const float PiOver3 = Pi / 3; 38 | 39 | /// 40 | /// Definesthe value of Pi divided by four as a . 41 | /// 42 | public const float PiOver4 = Pi / 4; 43 | 44 | /// 45 | /// Defines the value of Pi divided by six as a . 46 | /// 47 | public const float PiOver6 = Pi / 6; 48 | 49 | /// 50 | /// Defines the value of Pi multiplied by two as a . 51 | /// 52 | public const float TwoPi = 2 * Pi; 53 | 54 | /// 55 | /// Defines the value of Pi multiplied by 3 and divided by two as a . 56 | /// 57 | public const float ThreePiOver2 = 3 * Pi / 2; 58 | 59 | /// 60 | /// Defines the value of E as a . 61 | /// 62 | public const float E = 2.71828182845904523536f; 63 | 64 | /// 65 | /// Defines the base-10 logarithm of E. 66 | /// 67 | public const float Log10E = 0.434294482f; 68 | 69 | /// 70 | /// Defines the base-2 logarithm of E. 71 | /// 72 | public const float Log2E = 1.442695041f; 73 | 74 | #endregion 75 | 76 | #region Public Members 77 | 78 | #region NextPowerOfTwo 79 | 80 | /// 81 | /// Returns the next power of two that is larger than the specified number. 82 | /// 83 | /// The specified number. 84 | /// The next power of two. 85 | public static long NextPowerOfTwo(long n) 86 | { 87 | if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); 88 | return (long)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); 89 | } 90 | 91 | /// 92 | /// Returns the next power of two that is larger than the specified number. 93 | /// 94 | /// The specified number. 95 | /// The next power of two. 96 | public static int NextPowerOfTwo(int n) 97 | { 98 | if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); 99 | return (int)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); 100 | } 101 | 102 | /// 103 | /// Returns the next power of two that is larger than the specified number. 104 | /// 105 | /// The specified number. 106 | /// The next power of two. 107 | public static float NextPowerOfTwo(float n) 108 | { 109 | if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); 110 | return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); 111 | } 112 | 113 | /// 114 | /// Returns the next power of two that is larger than the specified number. 115 | /// 116 | /// The specified number. 117 | /// The next power of two. 118 | public static double NextPowerOfTwo(double n) 119 | { 120 | if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); 121 | return System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); 122 | } 123 | 124 | #endregion 125 | 126 | #region Factorial 127 | 128 | /// Calculates the factorial of a given natural number. 129 | /// 130 | /// The number. 131 | /// n! 132 | public static long Factorial(int n) 133 | { 134 | long result = 1; 135 | 136 | for (; n > 1; n--) 137 | result *= n; 138 | 139 | return result; 140 | } 141 | 142 | #endregion 143 | 144 | #region BinomialCoefficient 145 | 146 | /// 147 | /// Calculates the binomial coefficient above . 148 | /// 149 | /// The n. 150 | /// The k. 151 | /// n! / (k! * (n - k)!) 152 | public static long BinomialCoefficient(int n, int k) 153 | { 154 | return Factorial(n) / (Factorial(k) * Factorial(n - k)); 155 | } 156 | 157 | #endregion 158 | 159 | #region InverseSqrtFast 160 | 161 | /// 162 | /// Returns an approximation of the inverse square root of left number. 163 | /// 164 | /// A number. 165 | /// An approximation of the inverse square root of the specified number, with an upper error bound of 0.001 166 | /// 167 | /// This is an improved implementation of the the method known as Carmack's inverse square root 168 | /// which is found in the Quake III source code. This implementation comes from 169 | /// http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see 170 | /// http://www.beyond3d.com/content/articles/8/ 171 | /// 172 | public static float InverseSqrtFast(float x) 173 | { 174 | unsafe 175 | { 176 | float xhalf = 0.5f * x; 177 | int i = *(int*)&x; // Read bits as integer. 178 | i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation 179 | x = *(float*)&i; // Convert bits back to float 180 | x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step. 181 | return x; 182 | } 183 | } 184 | 185 | /// 186 | /// Returns an approximation of the inverse square root of left number. 187 | /// 188 | /// A number. 189 | /// An approximation of the inverse square root of the specified number, with an upper error bound of 0.001 190 | /// 191 | /// This is an improved implementation of the the method known as Carmack's inverse square root 192 | /// which is found in the Quake III source code. This implementation comes from 193 | /// http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see 194 | /// http://www.beyond3d.com/content/articles/8/ 195 | /// 196 | public static double InverseSqrtFast(double x) 197 | { 198 | return InverseSqrtFast((float)x); 199 | // TODO: The following code is wrong. Fix it, to improve precision. 200 | #if false 201 | unsafe 202 | { 203 | double xhalf = 0.5f * x; 204 | int i = *(int*)&x; // Read bits as integer. 205 | i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation 206 | x = *(float*)&i; // Convert bits back to float 207 | x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step. 208 | return x; 209 | } 210 | #endif 211 | } 212 | 213 | #endregion 214 | 215 | #region DegreesToRadians 216 | 217 | /// 218 | /// Convert degrees to radians 219 | /// 220 | /// An angle in degrees 221 | /// The angle expressed in radians 222 | public static float DegreesToRadians(float degrees) 223 | { 224 | const float degToRad = (float)System.Math.PI / 180.0f; 225 | return degrees * degToRad; 226 | } 227 | 228 | /// 229 | /// Convert radians to degrees 230 | /// 231 | /// An angle in radians 232 | /// The angle expressed in degrees 233 | public static float RadiansToDegrees(float radians) 234 | { 235 | const float radToDeg = 180.0f / (float)System.Math.PI; 236 | return radians * radToDeg; 237 | } 238 | 239 | /// 240 | /// Convert degrees to radians 241 | /// 242 | /// An angle in degrees 243 | /// The angle expressed in radians 244 | public static double DegreesToRadians(double degrees) 245 | { 246 | const double degToRad = System.Math.PI / 180.0; 247 | return degrees * degToRad; 248 | } 249 | 250 | /// 251 | /// Convert radians to degrees 252 | /// 253 | /// An angle in radians 254 | /// The angle expressed in degrees 255 | public static double RadiansToDegrees(double radians) 256 | { 257 | const double radToDeg = 180.0 / System.Math.PI; 258 | return radians * radToDeg; 259 | } 260 | 261 | #endregion 262 | 263 | #region Swap 264 | 265 | /// 266 | /// Swaps two double values. 267 | /// 268 | /// The first value. 269 | /// The second value. 270 | public static void Swap(ref double a, ref double b) 271 | { 272 | double temp = a; 273 | a = b; 274 | b = temp; 275 | } 276 | 277 | /// 278 | /// Swaps two float values. 279 | /// 280 | /// The first value. 281 | /// The second value. 282 | public static void Swap(ref float a, ref float b) 283 | { 284 | float temp = a; 285 | a = b; 286 | b = temp; 287 | } 288 | 289 | #endregion 290 | 291 | #endregion 292 | } 293 | } 294 | -------------------------------------------------------------------------------- /src/MiniTK/Math/Rectangle.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | 32 | namespace OpenTK 33 | { 34 | #if NO_SYSDRAWING 35 | /// 36 | /// Represents a rectangular region on a two-dimensional plane. 37 | /// 38 | public struct Rectangle : IEquatable 39 | { 40 | #region Fields 41 | 42 | Point location; 43 | Size size; 44 | 45 | #endregion 46 | 47 | #region Constructors 48 | 49 | /// 50 | /// Constructs a new Rectangle instance. 51 | /// 52 | /// The top-left corner of the Rectangle. 53 | /// The width and height of the Rectangle. 54 | public Rectangle(Point location, Size size) 55 | : this() 56 | { 57 | Location = location; 58 | Size = size; 59 | } 60 | 61 | /// 62 | /// Constructs a new Rectangle instance. 63 | /// 64 | /// The x coordinate of the Rectangle. 65 | /// The y coordinate of the Rectangle. 66 | /// The width coordinate of the Rectangle. 67 | /// The height coordinate of the Rectangle. 68 | public Rectangle(int x, int y, int width, int height) 69 | : this(new Point(x, y), new Size(width, height)) 70 | { } 71 | 72 | #endregion 73 | 74 | #region Public Members 75 | 76 | /// 77 | /// Gets or sets the x coordinate of the Rectangle. 78 | /// 79 | public int X 80 | { 81 | get { return Location.X; } 82 | set { Location = new Point (value, Y); } 83 | } 84 | 85 | /// 86 | /// Gets or sets the y coordinate of the Rectangle. 87 | /// 88 | public int Y 89 | { 90 | get { return Location.Y; } 91 | set { Location = new Point (X, value); } 92 | } 93 | 94 | /// 95 | /// Gets or sets the width of the Rectangle. 96 | /// 97 | public int Width 98 | { 99 | get { return Size.Width; } 100 | set { Size = new Size (value, Height); } 101 | } 102 | 103 | /// 104 | /// Gets or sets the height of the Rectangle. 105 | /// 106 | public int Height 107 | { 108 | get { return Size.Height; } 109 | set { Size = new Size(Width, value); } 110 | } 111 | 112 | /// 113 | /// Gets or sets a representing the x and y coordinates 114 | /// of the Rectangle. 115 | /// 116 | public Point Location 117 | { 118 | get { return location; } 119 | set { location = value; } 120 | } 121 | 122 | /// 123 | /// Gets or sets a representing the width and height 124 | /// of the Rectangle. 125 | /// 126 | public Size Size 127 | { 128 | get { return size; } 129 | set { size = value; } 130 | } 131 | 132 | /// 133 | /// Gets the y coordinate of the top edge of this Rectangle. 134 | /// 135 | public int Top { get { return Y; } } 136 | 137 | /// 138 | /// Gets the x coordinate of the right edge of this Rectangle. 139 | /// 140 | public int Right { get { return X + Width; } } 141 | 142 | /// 143 | /// Gets the y coordinate of the bottom edge of this Rectangle. 144 | /// 145 | public int Bottom { get { return Y + Height; } } 146 | 147 | /// 148 | /// Gets the x coordinate of the left edge of this Rectangle. 149 | /// 150 | public int Left { get { return X; } } 151 | 152 | /// 153 | /// Gets a that indicates whether this 154 | /// Rectangle is equal to the empty Rectangle. 155 | /// 156 | public bool IsEmpty 157 | { 158 | get { return Location.IsEmpty && Size.IsEmpty; } 159 | } 160 | 161 | /// 162 | /// Defines the empty Rectangle. 163 | /// 164 | public static readonly Rectangle Zero = new Rectangle(); 165 | 166 | /// 167 | /// Defines the empty Rectangle. 168 | /// 169 | public static readonly Rectangle Empty = new Rectangle(); 170 | 171 | /// 172 | /// Constructs a new instance with the specified edges. 173 | /// 174 | /// The left edge of the Rectangle. 175 | /// The top edge of the Rectangle. 176 | /// The right edge of the Rectangle. 177 | /// The bottom edge of the Rectangle. 178 | /// A new Rectangle instance with the specified edges. 179 | public static Rectangle FromLTRB(int left, int top, int right, int bottom) 180 | { 181 | return new Rectangle(new Point(left, top), new Size(right - left, bottom - top)); 182 | } 183 | 184 | /// 185 | /// Tests whether this instance contains the specified Point. 186 | /// 187 | /// The to test. 188 | /// True if this instance contains point; false otherwise. 189 | /// The left and top edges are inclusive. The right and bottom edges 190 | /// are exclusive. 191 | public bool Contains(Point point) 192 | { 193 | return point.X >= Left && point.X < Right && 194 | point.Y >= Top && point.Y < Bottom; 195 | } 196 | 197 | /// 198 | /// Tests whether this instance contains the specified Rectangle. 199 | /// 200 | /// The to test. 201 | /// True if this instance contains rect; false otherwise. 202 | /// The left and top edges are inclusive. The right and bottom edges 203 | /// are exclusive. 204 | public bool Contains(Rectangle rect) 205 | { 206 | return Contains(rect.Location) && Contains(rect.Location + rect.Size); 207 | } 208 | 209 | /// 210 | /// Compares two instances for equality. 211 | /// 212 | /// The first instance. 213 | /// The second instance. 214 | /// True, if left is equal to right; false otherwise. 215 | public static bool operator ==(Rectangle left, Rectangle right) 216 | { 217 | return left.Equals(right); 218 | } 219 | 220 | /// 221 | /// Compares two instances for inequality. 222 | /// 223 | /// The first instance. 224 | /// The second instance. 225 | /// True, if left is not equal to right; false otherwise. 226 | public static bool operator !=(Rectangle left, Rectangle right) 227 | { 228 | return !left.Equals(right); 229 | } 230 | 231 | /// 232 | /// Converts an OpenTK.Rectangle instance to a System.Drawing.Rectangle. 233 | /// 234 | /// 235 | /// The instance to convert. 236 | /// 237 | /// 238 | /// A instance equivalent to rect. 239 | /// 240 | public static implicit operator System.Drawing.Rectangle(Rectangle rect) 241 | { 242 | return new System.Drawing.Rectangle(rect.Location, rect.Size); 243 | } 244 | 245 | /// 246 | /// Converts a System.Drawing.Rectangle instance to an OpenTK.Rectangle. 247 | /// 248 | /// 249 | /// The instance to convert. 250 | /// 251 | /// 252 | /// A instance equivalent to point. 253 | /// 254 | public static implicit operator Rectangle(System.Drawing.Rectangle rect) 255 | { 256 | return new Rectangle(rect.Location, rect.Size); 257 | } 258 | 259 | /// 260 | /// Converts an OpenTK.Rectangle instance to a System.Drawing.RectangleF. 261 | /// 262 | /// 263 | /// The instance to convert. 264 | /// 265 | /// 266 | /// A instance equivalent to rect. 267 | /// 268 | public static implicit operator System.Drawing.RectangleF(Rectangle rect) 269 | { 270 | return new System.Drawing.RectangleF(rect.Location, rect.Size); 271 | } 272 | 273 | /// 274 | /// Indicates whether this instance is equal to the specified object. 275 | /// 276 | /// The object instance to compare to. 277 | /// True, if both instances are equal; false otherwise. 278 | public override bool Equals(object obj) 279 | { 280 | if (obj is Rectangle) 281 | return Equals((Rectangle)obj); 282 | 283 | return false; 284 | } 285 | 286 | /// 287 | /// Returns the hash code for this instance. 288 | /// 289 | /// A that represents the hash code for this instance./> 290 | public override int GetHashCode() 291 | { 292 | return Location.GetHashCode() & Size.GetHashCode(); 293 | } 294 | 295 | /// 296 | /// Returns a that describes this instance. 297 | /// 298 | /// A that describes this instance. 299 | public override string ToString() 300 | { 301 | return String.Format("{{{0}-{1}}}", Location, Location + Size); 302 | } 303 | 304 | 305 | #endregion 306 | 307 | #region IEquatable Members 308 | 309 | /// 310 | /// Indicates whether this instance is equal to the specified Rectangle. 311 | /// 312 | /// The instance to compare to. 313 | /// True, if both instances are equal; false otherwise. 314 | public bool Equals(Rectangle other) 315 | { 316 | return Location.Equals(other.Location) && 317 | Size.Equals(other.Size); 318 | } 319 | 320 | #endregion 321 | } 322 | #endif 323 | } 324 | -------------------------------------------------------------------------------- /src/MiniTK/Math/Vector2h.cs: -------------------------------------------------------------------------------- 1 | #region --- License --- 2 | /* 3 | Copyright (c) 2006 - 2008 The Open Toolkit library. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | #endregion 24 | 25 | using System; 26 | using System.IO; 27 | using System.Runtime.InteropServices; 28 | using System.Runtime.Serialization; 29 | 30 | // flibit Added This!!! 31 | #pragma warning disable 3021 32 | 33 | namespace OpenTK 34 | { 35 | 36 | /// 2-component Vector of the Half type. Occupies 4 Byte total. 37 | [Serializable, StructLayout(LayoutKind.Sequential)] 38 | public struct Vector2h : ISerializable, IEquatable 39 | { 40 | #region Fields 41 | 42 | /// The X component of the Half2. 43 | public Half X; 44 | 45 | /// The Y component of the Half2. 46 | public Half Y; 47 | 48 | #endregion 49 | 50 | #region Constructors 51 | 52 | /// 53 | /// Constructs a new instance. 54 | /// 55 | /// The value that will initialize this instance. 56 | public Vector2h(Half value) 57 | { 58 | X = value; 59 | Y = value; 60 | } 61 | 62 | /// 63 | /// Constructs a new instance. 64 | /// 65 | /// The value that will initialize this instance. 66 | public Vector2h(Single value) 67 | { 68 | X = new Half(value); 69 | Y = new Half(value); 70 | } 71 | 72 | /// 73 | /// The new Half2 instance will avoid conversion and copy directly from the Half parameters. 74 | /// 75 | /// An Half instance of a 16-bit half-precision floating-point number. 76 | /// An Half instance of a 16-bit half-precision floating-point number. 77 | public Vector2h(Half x, Half y) 78 | { 79 | X = x; 80 | Y = y; 81 | } 82 | 83 | /// 84 | /// The new Half2 instance will convert the 2 parameters into 16-bit half-precision floating-point. 85 | /// 86 | /// 32-bit single-precision floating-point number. 87 | /// 32-bit single-precision floating-point number. 88 | public Vector2h(Single x, Single y) 89 | { 90 | X = new Half(x); 91 | Y = new Half(y); 92 | } 93 | 94 | /// 95 | /// The new Half2 instance will convert the 2 parameters into 16-bit half-precision floating-point. 96 | /// 97 | /// 32-bit single-precision floating-point number. 98 | /// 32-bit single-precision floating-point number. 99 | /// Enable checks that will throw if the conversion result is not meaningful. 100 | public Vector2h(Single x, Single y, bool throwOnError) 101 | { 102 | X = new Half(x, throwOnError); 103 | Y = new Half(y, throwOnError); 104 | } 105 | 106 | /// 107 | /// The new Half2 instance will convert the Vector2 into 16-bit half-precision floating-point. 108 | /// 109 | /// OpenTK.Vector2 110 | [CLSCompliant(false)] 111 | public Vector2h(Vector2 v) 112 | { 113 | X = new Half(v.X); 114 | Y = new Half(v.Y); 115 | } 116 | 117 | /// 118 | /// The new Half2 instance will convert the Vector2 into 16-bit half-precision floating-point. 119 | /// 120 | /// OpenTK.Vector2 121 | /// Enable checks that will throw if the conversion result is not meaningful. 122 | [CLSCompliant(false)] 123 | public Vector2h(Vector2 v, bool throwOnError) 124 | { 125 | X = new Half(v.X, throwOnError); 126 | Y = new Half(v.Y, throwOnError); 127 | } 128 | 129 | /// 130 | /// The new Half2 instance will convert the Vector2 into 16-bit half-precision floating-point. 131 | /// This is the fastest constructor. 132 | /// 133 | /// OpenTK.Vector2 134 | public Vector2h(ref Vector2 v) 135 | { 136 | X = new Half(v.X); 137 | Y = new Half(v.Y); 138 | } 139 | 140 | /// 141 | /// The new Half2 instance will convert the Vector2 into 16-bit half-precision floating-point. 142 | /// 143 | /// OpenTK.Vector2 144 | /// Enable checks that will throw if the conversion result is not meaningful. 145 | public Vector2h(ref Vector2 v, bool throwOnError) 146 | { 147 | X = new Half(v.X, throwOnError); 148 | Y = new Half(v.Y, throwOnError); 149 | } 150 | 151 | /// 152 | /// The new Half2 instance will convert the Vector2d into 16-bit half-precision floating-point. 153 | /// 154 | /// OpenTK.Vector2d 155 | public Vector2h(Vector2d v) 156 | { 157 | X = new Half(v.X); 158 | Y = new Half(v.Y); 159 | } 160 | 161 | /// 162 | /// The new Half2 instance will convert the Vector2d into 16-bit half-precision floating-point. 163 | /// 164 | /// OpenTK.Vector2d 165 | /// Enable checks that will throw if the conversion result is not meaningful. 166 | public Vector2h(Vector2d v, bool throwOnError) 167 | { 168 | X = new Half(v.X, throwOnError); 169 | Y = new Half(v.Y, throwOnError); 170 | } 171 | 172 | /// 173 | /// The new Half2 instance will convert the Vector2d into 16-bit half-precision floating-point. 174 | /// This is the faster constructor. 175 | /// 176 | /// OpenTK.Vector2d 177 | [CLSCompliant(false)] 178 | public Vector2h(ref Vector2d v) 179 | { 180 | X = new Half(v.X); 181 | Y = new Half(v.Y); 182 | } 183 | 184 | /// 185 | /// The new Half2 instance will convert the Vector2d into 16-bit half-precision floating-point. 186 | /// 187 | /// OpenTK.Vector2d 188 | /// Enable checks that will throw if the conversion result is not meaningful. 189 | [CLSCompliant(false)] 190 | public Vector2h(ref Vector2d v, bool throwOnError) 191 | { 192 | X = new Half(v.X, throwOnError); 193 | Y = new Half(v.Y, throwOnError); 194 | } 195 | 196 | #endregion Constructors 197 | 198 | #region Half -> Single 199 | 200 | /// 201 | /// Returns this Half2 instance's contents as Vector2. 202 | /// 203 | /// OpenTK.Vector2 204 | public Vector2 ToVector2() 205 | { 206 | return new Vector2(X, Y); 207 | } 208 | 209 | /// 210 | /// Returns this Half2 instance's contents as Vector2d. 211 | /// 212 | public Vector2d ToVector2d() 213 | { 214 | return new Vector2d(X, Y); 215 | } 216 | 217 | #endregion Half -> Single 218 | 219 | #region Conversions 220 | 221 | /// Converts OpenTK.Vector2 to OpenTK.Half2. 222 | /// The Vector2 to convert. 223 | /// The resulting Half vector. 224 | public static explicit operator Vector2h(Vector2 v) 225 | { 226 | return new Vector2h(v); 227 | } 228 | 229 | /// Converts OpenTK.Vector2d to OpenTK.Half2. 230 | /// The Vector2d to convert. 231 | /// The resulting Half vector. 232 | public static explicit operator Vector2h(Vector2d v) 233 | { 234 | return new Vector2h(v); 235 | } 236 | 237 | /// Converts OpenTK.Half2 to OpenTK.Vector2. 238 | /// The Half2 to convert. 239 | /// The resulting Vector2. 240 | public static explicit operator Vector2(Vector2h h) 241 | { 242 | return new Vector2(h.X, h.Y); 243 | } 244 | 245 | /// Converts OpenTK.Half2 to OpenTK.Vector2d. 246 | /// The Half2 to convert. 247 | /// The resulting Vector2d. 248 | public static explicit operator Vector2d(Vector2h h) 249 | { 250 | return new Vector2d(h.X, h.Y); 251 | } 252 | 253 | #endregion Conversions 254 | 255 | #region Constants 256 | 257 | /// The size in bytes for an instance of the Half2 struct is 4. 258 | public static readonly int SizeInBytes = 4; 259 | 260 | #endregion Constants 261 | 262 | #region ISerializable 263 | 264 | /// Constructor used by ISerializable to deserialize the object. 265 | /// 266 | /// 267 | public Vector2h(SerializationInfo info, StreamingContext context) 268 | { 269 | this.X = (Half)info.GetValue("X", typeof(Half)); 270 | this.Y = (Half)info.GetValue("Y", typeof(Half)); 271 | } 272 | 273 | /// Used by ISerialize to serialize the object. 274 | /// 275 | /// 276 | public void GetObjectData(SerializationInfo info, StreamingContext context) 277 | { 278 | info.AddValue("X", this.X); 279 | info.AddValue("Y", this.Y); 280 | } 281 | 282 | #endregion ISerializable 283 | 284 | #region Binary dump 285 | 286 | /// Updates the X and Y components of this instance by reading from a Stream. 287 | /// A BinaryReader instance associated with an open Stream. 288 | public void FromBinaryStream(BinaryReader bin) 289 | { 290 | X.FromBinaryStream(bin); 291 | Y.FromBinaryStream(bin); 292 | } 293 | 294 | /// Writes the X and Y components of this instance into a Stream. 295 | /// A BinaryWriter instance associated with an open Stream. 296 | public void ToBinaryStream(BinaryWriter bin) 297 | { 298 | X.ToBinaryStream(bin); 299 | Y.ToBinaryStream(bin); 300 | } 301 | 302 | #endregion Binary dump 303 | 304 | #region IEquatable Members 305 | 306 | /// Returns a value indicating whether this instance is equal to a specified OpenTK.Half2 vector. 307 | /// OpenTK.Half2 to compare to this instance.. 308 | /// True, if other is equal to this instance; false otherwise. 309 | public bool Equals(Vector2h other) 310 | { 311 | return (this.X.Equals(other.X) && this.Y.Equals(other.Y)); 312 | } 313 | 314 | #endregion 315 | 316 | #region ToString() 317 | 318 | /// Returns a string that contains this Half2's numbers in human-legible form. 319 | public override string ToString() 320 | { 321 | return String.Format("({0}, {1})", X.ToString(), Y.ToString()); 322 | } 323 | 324 | #endregion ToString() 325 | 326 | #region BitConverter 327 | 328 | /// Returns the Half2 as an array of bytes. 329 | /// The Half2 to convert. 330 | /// The input as byte array. 331 | public static byte[] GetBytes(Vector2h h) 332 | { 333 | byte[] result = new byte[SizeInBytes]; 334 | 335 | byte[] temp = Half.GetBytes(h.X); 336 | result[0] = temp[0]; 337 | result[1] = temp[1]; 338 | temp = Half.GetBytes(h.Y); 339 | result[2] = temp[0]; 340 | result[3] = temp[1]; 341 | 342 | return result; 343 | } 344 | 345 | /// Converts an array of bytes into Half2. 346 | /// A Half2 in it's byte[] representation. 347 | /// The starting position within value. 348 | /// A new Half2 instance. 349 | public static Vector2h FromBytes(byte[] value, int startIndex) 350 | { 351 | Vector2h h2 = new Vector2h(); 352 | h2.X = Half.FromBytes(value, startIndex); 353 | h2.Y = Half.FromBytes(value, startIndex + 2); 354 | return h2; 355 | } 356 | 357 | #endregion BitConverter 358 | } 359 | } 360 | 361 | // flibit Added This!!! 362 | #pragma warning restore 3021 -------------------------------------------------------------------------------- /src/MiniTK/Graphics/ES20/Helper.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // 3 | // The Open Toolkit Library License 4 | // 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do 12 | // so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | // OTHER DEALINGS IN THE SOFTWARE. 25 | // 26 | #endregion 27 | 28 | // flibit added this! 29 | #pragma warning disable 3021 30 | 31 | using System; 32 | using System.Collections.Generic; 33 | #if !MINIMAL 34 | using System.Drawing; 35 | #endif 36 | using System.Text; 37 | 38 | namespace OpenTK.Graphics.ES20 39 | { 40 | /// 41 | /// Provides access to OpenGL ES 2.0 methods. 42 | /// 43 | public sealed partial class GL : GraphicsBindingsBase 44 | { 45 | const string Library = "libGLESv2.dll"; 46 | static readonly object sync_root = new object(); 47 | 48 | #region --- Protected Members --- 49 | 50 | /// 51 | /// Returns a synchronization token unique for the GL class. 52 | /// 53 | protected override object SyncRoot 54 | { 55 | get { return sync_root; } 56 | } 57 | 58 | #endregion 59 | 60 | #region Helper Overloads 61 | 62 | #pragma warning disable 3019 63 | #pragma warning disable 1591 64 | #pragma warning disable 1572 65 | #pragma warning disable 1573 66 | 67 | // Note: Mono 1.9.1 truncates StringBuilder results (for 'out string' parameters). 68 | // We work around this issue by doubling the StringBuilder capacity. 69 | 70 | #region public static void ClearColor() overloads 71 | 72 | public static void ClearColor(Color color) 73 | { 74 | GL.ClearColor(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f); 75 | } 76 | 77 | public static void ClearColor(Color4 color) 78 | { 79 | GL.ClearColor(color.R, color.G, color.B, color.A); 80 | } 81 | 82 | #endregion 83 | 84 | #region public static void BlendColor() overloads 85 | 86 | public static void BlendColor(Color color) 87 | { 88 | GL.BlendColor(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f); 89 | } 90 | 91 | public static void BlendColor(Color4 color) 92 | { 93 | GL.BlendColor(color.R, color.G, color.B, color.A); 94 | } 95 | 96 | #endregion 97 | 98 | #region Uniform 99 | 100 | [CLSCompliant(false)] 101 | public static void Uniform2(int location, ref Vector2 vector) 102 | { 103 | GL.Uniform2(location, vector.X, vector.Y); 104 | } 105 | 106 | [CLSCompliant(false)] 107 | public static void Uniform3(int location, ref Vector3 vector) 108 | { 109 | GL.Uniform3(location, vector.X, vector.Y, vector.Z); 110 | } 111 | 112 | [CLSCompliant(false)] 113 | public static void Uniform4(int location, ref Vector4 vector) 114 | { 115 | GL.Uniform4(location, vector.X, vector.Y, vector.Z, vector.W); 116 | } 117 | 118 | public static void Uniform2(int location, Vector2 vector) 119 | { 120 | GL.Uniform2(location, vector.X, vector.Y); 121 | } 122 | 123 | public static void Uniform3(int location, Vector3 vector) 124 | { 125 | GL.Uniform3(location, vector.X, vector.Y, vector.Z); 126 | } 127 | 128 | public static void Uniform4(int location, Vector4 vector) 129 | { 130 | GL.Uniform4(location, vector.X, vector.Y, vector.Z, vector.W); 131 | } 132 | 133 | public static void Uniform4(int location, Color4 color) 134 | { 135 | GL.Uniform4(location, color.R, color.G, color.B, color.A); 136 | } 137 | 138 | public static void Uniform4(int location, Quaternion quaternion) 139 | { 140 | GL.Uniform4(location, quaternion.X, quaternion.Y, quaternion.Z, quaternion.W); 141 | } 142 | 143 | public static void UniformMatrix4(int location, bool transpose, ref Matrix4 matrix) 144 | { 145 | unsafe 146 | { 147 | fixed (float* matrix_ptr = &matrix.Row0.X) 148 | { 149 | GL.UniformMatrix4(location, 1, transpose, matrix_ptr); 150 | } 151 | } 152 | } 153 | 154 | 155 | #endregion 156 | 157 | #region Shaders 158 | 159 | #region GetActiveAttrib 160 | 161 | public static string GetActiveAttrib(int program, int index, out int size, out ActiveAttribType type) 162 | { 163 | int length; 164 | GetProgram(program, ProgramParameter.ActiveAttributeMaxLength, out length); 165 | StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2); 166 | 167 | GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb); 168 | return sb.ToString(); 169 | } 170 | 171 | #endregion 172 | 173 | #region GetActiveUniform 174 | 175 | public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type) 176 | { 177 | int length; 178 | GetProgram(program, ProgramParameter.ActiveUniformMaxLength, out length); 179 | 180 | StringBuilder sb = new StringBuilder(length == 0 ? 1 : length); 181 | GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb); 182 | return sb.ToString(); 183 | } 184 | 185 | #endregion 186 | 187 | #region public static void ShaderSource(Int32 shader, System.String @string) 188 | 189 | public static void ShaderSource(Int32 shader, System.String @string) 190 | { 191 | unsafe 192 | { 193 | int length = @string.Length; 194 | GL.ShaderSource((UInt32)shader, 1, new string[] { @string }, &length); 195 | } 196 | } 197 | 198 | #endregion 199 | 200 | #region public static string GetShaderInfoLog(Int32 shader) 201 | 202 | public static string GetShaderInfoLog(Int32 shader) 203 | { 204 | string info; 205 | GetShaderInfoLog(shader, out info); 206 | return info; 207 | } 208 | 209 | #endregion 210 | 211 | #region public static void GetShaderInfoLog(Int32 shader, out string info) 212 | 213 | public static void GetShaderInfoLog(Int32 shader, out string info) 214 | { 215 | unsafe 216 | { 217 | int length; 218 | GL.GetShader(shader, ShaderParameter.InfoLogLength, out length); 219 | if (length == 0) 220 | { 221 | info = String.Empty; 222 | return; 223 | } 224 | StringBuilder sb = new StringBuilder(length * 2); 225 | GL.GetShaderInfoLog((UInt32)shader, sb.Capacity, &length, sb); 226 | info = sb.ToString(); 227 | } 228 | } 229 | 230 | #endregion 231 | 232 | #region public static string GetProgramInfoLog(Int32 program) 233 | 234 | public static string GetProgramInfoLog(Int32 program) 235 | { 236 | string info; 237 | GetProgramInfoLog(program, out info); 238 | return info; 239 | } 240 | 241 | #endregion 242 | 243 | #region public static void GetProgramInfoLog(Int32 program, out string info) 244 | 245 | public static void GetProgramInfoLog(Int32 program, out string info) 246 | { 247 | unsafe 248 | { 249 | int length; 250 | GL.GetProgram(program, ProgramParameter.InfoLogLength, out length); if (length == 0) 251 | { 252 | info = String.Empty; 253 | return; 254 | } 255 | StringBuilder sb = new StringBuilder(length * 2); 256 | GL.GetProgramInfoLog((UInt32)program, sb.Capacity, &length, sb); 257 | info = sb.ToString(); 258 | } 259 | } 260 | 261 | #endregion 262 | 263 | #endregion 264 | 265 | #region public static void VertexAttrib2(Int32 index, ref Vector2 v) 266 | 267 | [CLSCompliant(false)] 268 | public static void VertexAttrib2(Int32 index, ref Vector2 v) 269 | { 270 | GL.VertexAttrib2(index, v.X, v.Y); 271 | } 272 | 273 | #endregion 274 | 275 | #region public static void VertexAttrib3(Int32 index, ref Vector3 v) 276 | 277 | [CLSCompliant(false)] 278 | public static void VertexAttrib3(Int32 index, ref Vector3 v) 279 | { 280 | GL.VertexAttrib3(index, v.X, v.Y, v.Z); 281 | } 282 | 283 | #endregion 284 | 285 | #region public static void VertexAttrib4(Int32 index, ref Vector4 v) 286 | 287 | [CLSCompliant(false)] 288 | public static void VertexAttrib4(Int32 index, ref Vector4 v) 289 | { 290 | GL.VertexAttrib4(index, v.X, v.Y, v.Z, v.W); 291 | } 292 | 293 | #endregion 294 | 295 | #region public static void VertexAttrib2(Int32 index, Vector2 v) 296 | 297 | public static void VertexAttrib2(Int32 index, Vector2 v) 298 | { 299 | GL.VertexAttrib2(index, v.X, v.Y); 300 | } 301 | 302 | #endregion 303 | 304 | #region public static void VertexAttrib3(Int32 index, Vector3 v) 305 | 306 | public static void VertexAttrib3(Int32 index, Vector3 v) 307 | { 308 | GL.VertexAttrib3(index, v.X, v.Y, v.Z); 309 | } 310 | 311 | #endregion 312 | 313 | #region public static void VertexAttrib4(Int32 index, Vector4 v) 314 | 315 | public static void VertexAttrib4(Int32 index, Vector4 v) 316 | { 317 | GL.VertexAttrib4(index, v.X, v.Y, v.Z, v.W); 318 | } 319 | 320 | #endregion 321 | 322 | #region VertexAttribPointer 323 | 324 | public static void VertexAttribPointer(int index, int size, VertexAttribPointerType type, bool normalized, int stride, int offset) 325 | { 326 | VertexAttribPointer(index, size, type, normalized, stride, (IntPtr)offset); 327 | } 328 | 329 | [CLSCompliant(false)] 330 | public static void VertexAttribPointer(uint index, int size, VertexAttribPointerType type, bool normalized, int stride, int offset) 331 | { 332 | VertexAttribPointer(index, size, type, normalized, stride, (IntPtr)offset); 333 | } 334 | 335 | #endregion 336 | 337 | #region DrawElements 338 | 339 | public static void DrawElements(BeginMode mode, int count, DrawElementsType type, int offset) 340 | { 341 | DrawElements(mode, count, type, new IntPtr(offset)); 342 | } 343 | 344 | #endregion 345 | 346 | #region public static int GenTexture() 347 | 348 | public static int GenTexture() 349 | { 350 | int id; 351 | GenTextures(1, out id); 352 | return id; 353 | } 354 | 355 | #endregion 356 | 357 | #region public static void DeleteTexture(int id) 358 | 359 | public static void DeleteTexture(int id) 360 | { 361 | DeleteTextures(1, ref id); 362 | } 363 | 364 | #endregion 365 | 366 | #region Get[Float|Double] 367 | 368 | public static void GetFloat(GetPName pname, out Vector2 vector) 369 | { 370 | unsafe 371 | { 372 | fixed (Vector2* ptr = &vector) 373 | GetFloat(pname, (float*)ptr); 374 | } 375 | } 376 | 377 | public static void GetFloat(GetPName pname, out Vector3 vector) 378 | { 379 | unsafe 380 | { 381 | fixed (Vector3* ptr = &vector) 382 | GetFloat(pname, (float*)ptr); 383 | } 384 | } 385 | 386 | public static void GetFloat(GetPName pname, out Vector4 vector) 387 | { 388 | unsafe 389 | { 390 | fixed (Vector4* ptr = &vector) 391 | GetFloat(pname, (float*)ptr); 392 | } 393 | } 394 | 395 | public static void GetFloat(GetPName pname, out Matrix4 matrix) 396 | { 397 | unsafe 398 | { 399 | fixed (Matrix4* ptr = &matrix) 400 | GetFloat(pname, (float*)ptr); 401 | } 402 | } 403 | 404 | #endregion 405 | 406 | #region Viewport 407 | 408 | public static void Viewport(Size size) 409 | { 410 | GL.Viewport(0, 0, size.Width, size.Height); 411 | } 412 | 413 | public static void Viewport(Point location, Size size) 414 | { 415 | GL.Viewport(location.X, location.Y, size.Width, size.Height); 416 | } 417 | 418 | public static void Viewport(Rectangle rectangle) 419 | { 420 | GL.Viewport(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); 421 | } 422 | #if NO_SYSDRAWING 423 | public static void Viewport(OpenTK.Point location, OpenTK.Size size) 424 | { 425 | GL.Viewport(location.X, location.Y, size.Width, size.Height); 426 | } 427 | 428 | public static void Viewport(OpenTK.Rectangle rectangle) 429 | { 430 | GL.Viewport(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); 431 | } 432 | #endif 433 | #endregion 434 | 435 | #pragma warning restore 3019 436 | #pragma warning restore 1591 437 | #pragma warning restore 1572 438 | #pragma warning restore 1573 439 | 440 | #endregion 441 | } 442 | } 443 | 444 | // flibit added this! 445 | #pragma warning restore 3021 -------------------------------------------------------------------------------- /src/MiniTK/Math/Functions.cs: -------------------------------------------------------------------------------- 1 | #region --- License --- 2 | /* Licensed under the MIT/X11 license. 3 | * Copyright (c) 2006-2008 the OpenTK Team. 4 | * This notice may not be removed from any source distribution. 5 | * See license.txt for licensing detailed licensing details. 6 | * 7 | * Contributions by Andy Gill, James Talton and Georg Wächter. 8 | */ 9 | #endregion 10 | 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Text; 14 | 15 | namespace OpenTK 16 | { 17 | /// 18 | /// Contains mathematical functions for the OpenTK.Math toolkit. 19 | /// 20 | [Obsolete("Use OpenTK.MathHelper instead.")] 21 | public static class Functions 22 | { 23 | #region NextPowerOfTwo 24 | 25 | /// 26 | /// Returns the next power of two that is larger than the specified number. 27 | /// 28 | /// The specified number. 29 | /// The next power of two. 30 | public static long NextPowerOfTwo(long n) 31 | { 32 | if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); 33 | return (long)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); 34 | } 35 | 36 | /// 37 | /// Returns the next power of two that is larger than the specified number. 38 | /// 39 | /// The specified number. 40 | /// The next power of two. 41 | public static int NextPowerOfTwo(int n) 42 | { 43 | if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); 44 | return (int)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); 45 | } 46 | 47 | /// 48 | /// Returns the next power of two that is larger than the specified number. 49 | /// 50 | /// The specified number. 51 | /// The next power of two. 52 | public static float NextPowerOfTwo(float n) 53 | { 54 | if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); 55 | return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); 56 | } 57 | 58 | /// 59 | /// Returns the next power of two that is larger than the specified number. 60 | /// 61 | /// The specified number. 62 | /// The next power of two. 63 | public static double NextPowerOfTwo(double n) 64 | { 65 | if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); 66 | return System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); 67 | } 68 | 69 | #endregion 70 | 71 | #region Factorial 72 | 73 | /// Calculates the factorial of a given natural number. 74 | /// 75 | /// The number. 76 | /// n! 77 | public static long Factorial(int n) 78 | { 79 | long result = 1; 80 | 81 | for (; n > 1; n--) 82 | result *= n; 83 | 84 | return result; 85 | } 86 | 87 | #endregion 88 | 89 | #region BinomialCoefficient 90 | 91 | /// 92 | /// Calculates the binomial coefficient above . 93 | /// 94 | /// The n. 95 | /// The k. 96 | /// n! / (k! * (n - k)!) 97 | public static long BinomialCoefficient(int n, int k) 98 | { 99 | return Factorial(n) / (Factorial(k) * Factorial(n - k)); 100 | } 101 | 102 | #endregion 103 | 104 | #region InverseSqrtFast 105 | 106 | /// 107 | /// Returns an approximation of the inverse square root of left number. 108 | /// 109 | /// A number. 110 | /// An approximation of the inverse square root of the specified number, with an upper error bound of 0.001 111 | /// 112 | /// This is an improved implementation of the the method known as Carmack's inverse square root 113 | /// which is found in the Quake III source code. This implementation comes from 114 | /// http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see 115 | /// http://www.beyond3d.com/content/articles/8/ 116 | /// 117 | public static float InverseSqrtFast(float x) 118 | { 119 | unsafe 120 | { 121 | float xhalf = 0.5f * x; 122 | int i = *(int*)&x; // Read bits as integer. 123 | i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation 124 | x = *(float*)&i; // Convert bits back to float 125 | x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step. 126 | return x; 127 | } 128 | } 129 | 130 | /// 131 | /// Returns an approximation of the inverse square root of left number. 132 | /// 133 | /// A number. 134 | /// An approximation of the inverse square root of the specified number, with an upper error bound of 0.001 135 | /// 136 | /// This is an improved implementation of the the method known as Carmack's inverse square root 137 | /// which is found in the Quake III source code. This implementation comes from 138 | /// http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see 139 | /// http://www.beyond3d.com/content/articles/8/ 140 | /// 141 | public static double InverseSqrtFast(double x) 142 | { 143 | return InverseSqrtFast((float)x); 144 | // TODO: The following code is wrong. Fix it, to improve precision. 145 | #if false 146 | unsafe 147 | { 148 | double xhalf = 0.5f * x; 149 | int i = *(int*)&x; // Read bits as integer. 150 | i = 0x5f375a86 - (i >> 1); // Make an initial guess for Newton-Raphson approximation 151 | x = *(float*)&i; // Convert bits back to float 152 | x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step. 153 | return x; 154 | } 155 | #endif 156 | } 157 | 158 | #endregion 159 | 160 | #region DegreesToRadians 161 | 162 | /// 163 | /// Convert degrees to radians 164 | /// 165 | /// An angle in degrees 166 | /// The angle expressed in radians 167 | public static float DegreesToRadians(float degrees) 168 | { 169 | const float degToRad = (float)System.Math.PI / 180.0f; 170 | return degrees * degToRad; 171 | } 172 | 173 | /// 174 | /// Convert radians to degrees 175 | /// 176 | /// An angle in radians 177 | /// The angle expressed in degrees 178 | public static float RadiansToDegrees(float radians) 179 | { 180 | const float radToDeg = 180.0f / (float)System.Math.PI; 181 | return radians * radToDeg; 182 | } 183 | 184 | #endregion 185 | 186 | #region Mathematical constants 187 | 188 | /// 189 | /// Obsolete. Do not use. 190 | /// 191 | public static readonly float PIF = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382f; 192 | 193 | /// 194 | /// Obsolete. Do not use. 195 | /// 196 | public static readonly float RTODF = 180.0f / PIF; 197 | 198 | /// 199 | /// Obsolete. Do not use. 200 | /// 201 | public static readonly float DTORF = PIF / 180.0f; 202 | 203 | /// 204 | /// Obsolete. Do not use. 205 | /// 206 | public static readonly double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930382d; 207 | 208 | /// 209 | /// Obsolete. Do not use. 210 | /// 211 | public static readonly double RTOD = 180.0d / PIF; 212 | 213 | /// 214 | /// Obsolete. Do not use. 215 | /// 216 | public static readonly double DTOR = PIF / 180.0d; 217 | 218 | #endregion 219 | 220 | #region Swap 221 | 222 | /// 223 | /// Swaps two float values. 224 | /// 225 | /// The first value. 226 | /// The second value. 227 | public static void Swap(ref double a, ref double b) 228 | { 229 | double temp = a; 230 | a = b; 231 | b = temp; 232 | } 233 | 234 | /// 235 | /// Swaps two float values. 236 | /// 237 | /// The first value. 238 | /// The second value. 239 | public static void Swap(ref float a, ref float b) 240 | { 241 | float temp = a; 242 | a = b; 243 | b = temp; 244 | } 245 | 246 | #endregion 247 | } 248 | 249 | #if false 250 | public static partial class Math 251 | { 252 | #region --- Vectors --- 253 | 254 | #region --- Addition --- 255 | 256 | /// 257 | /// Adds the given Vector2 to the current Vector3. 258 | /// 259 | /// The right operand of the addition. 260 | /// A new Vector3 containing the result of the addition. 261 | public static Vector2 Add(Vector2 left, Vector2 right) 262 | { 263 | return new Vector2(left).Add(right); 264 | } 265 | 266 | /// 267 | /// Adds the given Vector3 to the current Vector3. 268 | /// 269 | /// The right operand of the addition. 270 | /// A new Vector3 containing the result of the addition. 271 | public static Vector3 Add(Vector2 left, Vector3 right) 272 | { 273 | return new Vector3(left).Add(right); 274 | } 275 | 276 | /// 277 | /// Adds the given Vector4 to the current Vector3. W-coordinate remains unaffected. 278 | /// 279 | /// The right operand of the addition. 280 | /// A new Vector4 containing the result of the addition. 281 | public static Vector4 Add(Vector2 left, Vector4 right) 282 | { 283 | return new Vector4(left).Add(right); 284 | } 285 | 286 | /// 287 | /// Adds the given Vector2 to the current Vector3. 288 | /// 289 | /// The right operand of the addition. 290 | /// A new Vector3 containing the result of the addition. 291 | public static Vector3 Add(Vector3 left, Vector2 right) 292 | { 293 | return new Vector3(left).Add(right); 294 | } 295 | 296 | /// 297 | /// Adds the given Vector3 to the current Vector3. 298 | /// 299 | /// The right operand of the addition. 300 | /// A new Vector3 containing the result of the addition. 301 | public static Vector3 Add(Vector3 left, Vector3 right) 302 | { 303 | return new Vector3(left).Add(right); 304 | } 305 | 306 | /// 307 | /// Adds the given Vector4 to the current Vector3. W-coordinate remains unaffected. 308 | /// 309 | /// The right operand of the addition. 310 | /// A new Vector4 containing the result of the addition. 311 | public static Vector4 Add(Vector3 left, Vector4 right) 312 | { 313 | return new Vector4(left).Add(right); 314 | } 315 | 316 | /// 317 | /// Adds the given Vector2 to the current Vector3. 318 | /// 319 | /// The right operand of the addition. 320 | /// A new Vector3 containing the result of the addition. 321 | public static Vector4 Add(Vector4 left, Vector2 right) 322 | { 323 | return new Vector4(left).Add(right); 324 | } 325 | 326 | /// 327 | /// Adds the given Vector3 to the current Vector3. 328 | /// 329 | /// The right operand of the addition. 330 | /// A new Vector3 containing the result of the addition. 331 | public static Vector4 Add(Vector4 left, Vector3 right) 332 | { 333 | return new Vector4(left).Add(right); 334 | } 335 | 336 | /// 337 | /// Adds the given Vector4 to the current Vector3. W-coordinate remains unaffected. 338 | /// 339 | /// The right operand of the addition. 340 | /// A new Vector4 containing the result of the addition. 341 | public static Vector4 Add(Vector4 left, Vector4 right) 342 | { 343 | return new Vector4(left).Add(right); 344 | } 345 | 346 | #endregion 347 | 348 | #region --- Subtraction --- 349 | 350 | 351 | 352 | #endregion 353 | 354 | #region --- Cross --- 355 | 356 | /// 357 | /// Computes the cross product between the current and the given Vector3. The current Vector3 is set to the result of the computation. 358 | /// 359 | /// The right operand of the cross product 360 | /// The current 361 | public static Vector3 Cross(Vector3 left, Vector3 right) 362 | { 363 | return new Vector3(left).Cross(right); 364 | } 365 | 366 | #endregion 367 | 368 | #endregion 369 | } 370 | #endif 371 | } 372 | --------------------------------------------------------------------------------