├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── question.md └── labeler.yml ├── .gitignore ├── LICENSE.txt ├── MonoVision ├── Audio │ ├── AudioChannels.cs │ ├── InstancePlayLimitException.cs │ ├── NoAudioHardwareException.cs │ ├── SoundEffect.cs │ ├── SoundEffectInstance.cs │ ├── SoundEffectInstancePool.cs │ └── SoundState.cs ├── Color.cs ├── Dependencies │ ├── SDL2.dll │ ├── libSDL2-2.0.0.dylib │ ├── libSDL2-2.0.so.0 │ ├── libopenal.1.dylib │ ├── libopenal.so.1 │ └── soft_oal.dll ├── EventHelpers.cs ├── Game.cs ├── GamePlatform.cs ├── GameTime.cs ├── GameWindow.cs ├── Graphics │ ├── DisplayMode.cs │ ├── Effect │ │ ├── Effect.cs │ │ ├── EffectParameter.cs │ │ ├── EffectParameterClass.cs │ │ ├── EffectParameterCollection.cs │ │ ├── EffectParameterType.cs │ │ ├── EffectPass.cs │ │ ├── EffectPassCollection.cs │ │ ├── EffectResource.cs │ │ ├── EffectTechnique.cs │ │ ├── EffectTechniqueCollection.cs │ │ └── SpriteEffect.cs │ ├── GraphicsCapabilities.cs │ ├── GraphicsDevice.cs │ ├── GraphicsExtensions.cs │ ├── GraphicsResource.cs │ ├── IGraphicsDeviceService.cs │ ├── NoSuitableGraphicsDeviceException.cs │ ├── PresentationEventArgs.cs │ ├── PresentationParameters.cs │ ├── SamplerStateCollection.cs │ ├── SetDataOptions.cs │ ├── Shader │ │ ├── ConstantBuffer.cs │ │ ├── ConstantBufferCollection.cs │ │ ├── Shader.cs │ │ └── ShaderStage.cs │ ├── SpriteBatch.cs │ ├── SpriteBatchItem.cs │ ├── SpriteBatcher.cs │ ├── SpriteSortMode.cs │ ├── States │ │ └── SamplerState.cs │ ├── SurfaceFormat.cs │ ├── Texture.cs │ ├── Texture2D.cs │ ├── TextureCollection.cs │ ├── Vertices │ │ ├── IVertexType.cs │ │ ├── PrimitiveType.cs │ │ ├── VertexBuffer.cs │ │ ├── VertexBufferBinding.cs │ │ ├── VertexBufferBindings.cs │ │ ├── VertexDeclaration.cs │ │ ├── VertexDeclarationCache.cs │ │ ├── VertexElement.cs │ │ ├── VertexElementFormat.cs │ │ ├── VertexElementUsage.cs │ │ ├── VertexInputLayout.cs │ │ ├── VertexPosition.cs │ │ ├── VertexPositionColor.cs │ │ ├── VertexPositionColorTexture.cs │ │ ├── VertexPositionNormalTexture.cs │ │ └── VertexPositionTexture.cs │ └── Viewport.cs ├── GraphicsDeviceInformation.cs ├── GraphicsDeviceManager.cs ├── IGraphicsDeviceManager.cs ├── Input │ ├── ButtonState.cs │ ├── Buttons.cs │ ├── GamePad.cs │ ├── GamePadButtons.cs │ ├── GamePadCapabilities.cs │ ├── GamePadDPad.cs │ ├── GamePadDeadZone.cs │ ├── GamePadState.cs │ ├── GamePadThumbSticks.cs │ ├── GamePadTriggers.cs │ ├── GamePadType.cs │ ├── Joystick.cs │ ├── JoystickCapabilities.cs │ ├── JoystickHat.cs │ ├── JoystickState.cs │ ├── KeyState.cs │ ├── Keyboard.cs │ ├── KeyboardState.cs │ ├── Keys.cs │ ├── Mouse.cs │ ├── MouseCursor.cs │ └── MouseState.cs ├── MathHelper.cs ├── Matrix.cs ├── Platform │ ├── Audio │ │ ├── AudioLoader.cs │ │ ├── OALSoundBuffer.cs │ │ ├── OpenAL.cs │ │ ├── OpenALSoundController.cs │ │ ├── SoundEffect.OpenAL.cs │ │ └── SoundEffectInstance.OpenAL.cs │ ├── GamePlatform.Desktop.cs │ ├── Graphics │ │ ├── Effect │ │ │ ├── EffectResource.OpenGL.cs │ │ │ └── Resources │ │ │ │ ├── SpriteEffect.fx │ │ │ │ └── SpriteEffect.ogl.mgfxo │ │ ├── GraphicsAdapter.Legacy.cs │ │ ├── GraphicsCapabilities.OpenGL.cs │ │ ├── GraphicsContext.SDL.cs │ │ ├── GraphicsDevice.OpenGL.FramebufferHelper.cs │ │ ├── GraphicsDevice.OpenGL.cs │ │ ├── IGraphicsContext.OpenGL.cs │ │ ├── IWindowInfo.OpenGL.cs │ │ ├── OpenGL.Common.cs │ │ ├── OpenGL.SDL.cs │ │ ├── OpenGL.cs │ │ ├── SamplerStateCollection.OpenGL.cs │ │ ├── Shader │ │ │ ├── ConstantBuffer.OpenGL.cs │ │ │ ├── Shader.OpenGL.cs │ │ │ └── ShaderProgramCache.cs │ │ ├── States │ │ │ └── SamplerState.OpenGL.cs │ │ ├── Texture.OpenGL.cs │ │ ├── Texture2D.OpenGL.cs │ │ ├── TextureCollection.OpenGL.cs │ │ ├── Vertices │ │ │ ├── VertexBuffer.OpenGL.cs │ │ │ └── VertexDeclaration.OpenGL.cs │ │ └── WindowInfo.SDL.cs │ ├── GraphicsDeviceManager.SDL.cs │ ├── Input │ │ ├── GamePad.SDL.cs │ │ ├── InputKeyEventArgs.cs │ │ ├── Joystick.SDL.cs │ │ ├── Keyboard.SDL.cs │ │ ├── KeyboardUtil.SDL.cs │ │ ├── KeysHelper.cs │ │ ├── Mouse.SDL.cs │ │ └── MouseCursor.SDL.cs │ ├── PrimaryThreadLoader.cs │ ├── SDL │ │ ├── SDL2.cs │ │ ├── SDLGamePlatform.cs │ │ └── SDLGameWindow.cs │ ├── Threading.cs │ └── Utilities │ │ ├── AssemblyHelper.cs │ │ ├── CurrentPlatform.cs │ │ ├── FuncLoader.Desktop.cs │ │ ├── InteropHelpers.cs │ │ └── ReflectionHelpers.Default.cs ├── PlayerIndex.cs ├── Point.cs ├── Rectangle.cs ├── TextInputEventArgs.cs ├── Utilities │ ├── BinaryReaderEx.cs │ ├── Hash.cs │ └── ReflectionHelpers.cs ├── Vector2.cs └── Vector3.cs ├── PixelVision8.MonoVision.csproj └── README.md /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | :+1: Thanks for offering to contribute to this project. Every contribution is greatly appreciated. 4 | 5 | ### Code of Conduct 6 | 7 | Everyone contributing to this project must adhere to the [Code of Conduct](./CODE_OF_CONDUCT.md). 8 | 9 | If you feel that someone is not upholding this code, please reach out via [email](mailto:makegames@pixelvision8.com) to open a discussion. 10 | 11 | ### Issues & Bounties 12 | 13 | You can help by search for an existing issue or opening a new issue to help find bugs that need to be fixed. If you are interested in working on a specific issue, reach out via [email](mailto:makegames@pixelvision8.com) to be added to the repo and have the issue assigned to you. You can still work on an issue on your own but letting us know first helps avoid multiple people working on fixing the same bug. 14 | 15 | Do open issues for questions, feature requests, proposals, bug reports, etc. Please do not open an issue for typos or other simple fixes; open a pull request instead. 16 | 17 | Finally, we offer [bounties](https://github.com/PixelVision8/PixelVision8/labels/bounty) for specific issues we are unable to directly fix due to time or knowledge. Bounties have the following 3 rules: 18 | 19 | **1: All source code written is yours to keep.** This is NOT a [work for hire](https://en.wikipedia.org/wiki/Work_for_hire); you retain full copyright ownership of the code you write. All I am asking is that Pixel Vision 8 gets the right to use/publish that code under the license used by the project. For example, if you release your code under MIT, but Pixel Vision 8 uses MS-PL, the code you contribute goes into the main project under MS-PL with a credit to you as the original creator. The Pixel Vision 8 license may change in the future, so any contributed code adopts the new license where applicable. If you use open-source code with a different license, please make that clear so the correct license and contributor are included. In the end, you can do whatever you want with the code you create after it is accepted. Feel free to continue to work on it, release it under your license, or use it in proprietary projects. 20 | 21 | **2: You are free to work on the project however you like.** If you do a lot of programming on Twitch, for example, you can stream the whole process, and you can publish anything about the project you want, including technical write-ups and example projects. You can also work in whatever environment you want, as long as the final product works on the expected platforms with the expected languages/dependencies. Note, however, that the bounties state a schedule/timeline/budget and those are unlikely to change without a very detailed assessment explaining, for example, why a project could take longer than expected. If you contribute, feel free to put that contribution down on your resume or what have you. If we end up establishing a regular working relationship I am also happy to act as a professional reference for job applications. 22 | 23 | **3: You are responsible for taxable income made from these bounties.** This one's pretty obvious but for those who aren't familiar, this is effectively non-employee income, and you need to pay taxes (depending on where you live). In the United States, for example, this is simply ["Other Income" on line 21 of Form 1040](https://www.irs.gov/pub/irs-pdf/f1040.pdf). The exception to this rule is if you live in the United States and make more than $600 from my projects, at which point I need a [Form W-9](https://www.irs.gov/pub/irs-pdf/fw9.pdf) sent to me so I can send you a 1099-MISC next year. 24 | 25 | If you have any further questions, feel free to [email me](mailto:makegames@pixelvision8.com). 26 | 27 | ### Pull Requests 28 | 29 | All fixes and bounties should be submitted via pull requests. Each pull request should follow a few simple rules listed below: 30 | 31 | * The title must clearly define the work. 32 | - This allows maintainers to prioritize pull requests at a high level 33 | - This saves time because maintainers don't need to traverse the list of pull requests to read descriptions of the work 34 | - **Caveat** Pull requests with vague titles may be closed without commit (e.g. Use `Fix typo of 'excldue'` rather than `Fix typo`) 35 | * The description should expand on the work if it is not clearly represented in the title. 36 | - Linking to related issues and providing inputs/outputs of new behaviors helps maintainers and future users understand the contribution 37 | * Commit messages must be clear and concise, but not _too_ concise. 38 | - Writing [good commit messages](https://thoughtbot.com/blog/5-useful-tips-for-a-better-commit-message) results in quality history in every repository 39 | - Explain why the commit was created, how it functions at a high level, and who/what this may affect 40 | - There are some times when a commit may be subject-only, but these are rare. Examples may include `Bump version to 1.0` or `Add X as contributor` 41 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: jessefreeman 2 | patreon: jessefreeman 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Found a bug? Submit and issue and we'll look into it. 4 | title: "" 5 | labels: bug 6 | assignees: jessefreeman 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is, including version(s) affected. 12 | 13 | **To reproduce** 14 | Steps to reproduce the behavior: 15 | 1. 16 | 2. 17 | 3. 18 | 19 | **Expected behavior** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Screenshots** 23 | If applicable, [add screenshots from PV8](https://docs.pixelvision8.com/pixelvisionos/screenshots) to help explain your problem. 24 | 25 | **Additional notes** 26 | Add any other details about the problem here. 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: We'd love to hear any ideas you may have to help make Pixel Vision 8 better. 4 | title: '' 5 | labels: enhancement 6 | assignees: jessefreeman 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Open an issue to ask a question 4 | title: "" 5 | labels: question 6 | assignees: jessefreeman 7 | 8 | --- 9 | 10 | **What is your question?** 11 | Enter one or two sentences at most here. Provide details later. 12 | 13 | **Where did you look before asking here?** 14 | This helps to understand where documentation may be lacking. 15 | 16 | **Additional context** 17 | Add any other context about the problem here. 18 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | # labeler "full" schema 2 | # See my other project, https://github.com/jimschubert/labeler-action 3 | enable: 4 | issues: true 5 | prs: true 6 | 7 | comments: 8 | issues: | 9 | Thanks for opening this issue! 10 | I have applied any labels matching special text in your title and description. 11 | prs: | 12 | Thanks for the contribution! 13 | I have applied any labels matching special text in your title and description. 14 | 15 | labels: 16 | 'bug': 17 | include: 18 | - '\bbug[s]?\b' 19 | - '\bfix(es)?\b' 20 | exclude: [] 21 | 'help wanted': 22 | include: 23 | - '\bhelp( me)?\b' 24 | exclude: 25 | - '\b\[test(ing)?\]\b' 26 | 'enhancement': 27 | include: 28 | - '\bfeat\b' 29 | exclude: [] 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Make sure we don't copy the runner files in the OS disk while debugging 2 | Content/Runners/ 3 | 4 | 5 | Thumbs.db 6 | Desktop.ini 7 | .DS_Store 8 | 9 | # Download this file using PowerShell v3 under Windows with the following comand: 10 | # Invoke-WebRequest https://gist.githubusercontent.com/kmorcinek/2710267/raw/ -OutFile .gitignore 11 | # or wget: 12 | # wget --no-check-certificate http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore 13 | 14 | # User-specific files 15 | *.suo 16 | *.user 17 | *.sln.docstates 18 | 19 | saves.json 20 | 21 | # Build results 22 | [Dd]ebug/ 23 | [Rr]elease/ 24 | [Bb]uilds/ 25 | [Rr]eleases/ 26 | [Ar]tifacts/ 27 | [Bb]in/ 28 | [Oo]bj/ 29 | 30 | # build folder is nowadays used for build scripts and should not be ignored 31 | #build/ 32 | 33 | # NuGet Packages 34 | *.nupkg 35 | # The packages folder can be ignored because of Package Restore 36 | **/packages/* 37 | # except build/, which is used as an MSBuild target. 38 | !**/packages/build/ 39 | # Uncomment if necessary however generally it will be regenerated when needed 40 | #!**/packages/repositories.config 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | *_i.c 47 | *_p.c 48 | *.ilk 49 | *.meta 50 | *.obj 51 | *.pch 52 | *.pdb 53 | *.pgc 54 | *.pgd 55 | *.rsp 56 | *.sbr 57 | *.tlb 58 | *.tli 59 | *.tlh 60 | *.tmp 61 | *.tmp_proj 62 | *.log 63 | *.vspscc 64 | *.vssscc 65 | .builds 66 | *.pidb 67 | *.log 68 | *.scc 69 | 70 | # OS generated files # 71 | .DS_Store* 72 | Icon? 73 | 74 | # Visual C++ cache files 75 | ipch/ 76 | *.aps 77 | *.ncb 78 | *.opensdf 79 | *.sdf 80 | *.cachefile 81 | 82 | # Visual Studio profiler 83 | *.psess 84 | *.vsp 85 | *.vspx 86 | 87 | # Guidance Automation Toolkit 88 | *.gpState 89 | 90 | # ReSharper is a .NET coding add-in 91 | _ReSharper*/ 92 | *.[Rr]e[Ss]harper 93 | 94 | # TeamCity is a build add-in 95 | _TeamCity* 96 | 97 | # DotCover is a Code Coverage Tool 98 | *.dotCover 99 | 100 | # NCrunch 101 | *.ncrunch* 102 | .*crunch*.local.xml 103 | 104 | # Installshield output folder 105 | [Ee]xpress/ 106 | 107 | # DocProject is a documentation generator add-in 108 | DocProject/buildhelp/ 109 | DocProject/Help/*.HxT 110 | DocProject/Help/*.HxC 111 | DocProject/Help/*.hhc 112 | DocProject/Help/*.hhk 113 | DocProject/Help/*.hhp 114 | DocProject/Help/Html2 115 | DocProject/Help/html 116 | 117 | # Click-Once directory 118 | publish/ 119 | 120 | # Publish Web Output 121 | *.Publish.xml 122 | 123 | # Windows Azure Build Output 124 | csx 125 | *.build.csdef 126 | 127 | # Windows Store app package directory 128 | AppPackages/ 129 | 130 | # Others 131 | *.Cache 132 | ClientBin/ 133 | [Ss]tyle[Cc]op.* 134 | ~$* 135 | *~ 136 | *.dbmdl 137 | *.[Pp]ublish.xml 138 | *.pfx 139 | *.publishsettings 140 | modulesbin/ 141 | tempbin/ 142 | 143 | # EPiServer Site file (VPP) 144 | AppData/ 145 | 146 | # RIA/Silverlight projects 147 | Generated_Code/ 148 | 149 | # Backup & report files from converting an old project file to a newer 150 | # Visual Studio version. Backup files are not needed, because we have git ;-) 151 | _UpgradeReport_Files/ 152 | Backup*/ 153 | UpgradeLog*.XML 154 | UpgradeLog*.htm 155 | 156 | # vim 157 | *.txt~ 158 | *.swp 159 | *.swo 160 | 161 | # Temp files when opening LibreOffice on ubuntu 162 | .~lock.* 163 | 164 | # svn 165 | .svn 166 | 167 | # CVS - Source Control 168 | **/CVS/ 169 | 170 | # Remainings from resolving conflicts in Source Control 171 | *.orig 172 | 173 | # SQL Server files 174 | **/App_Data/*.mdf 175 | **/App_Data/*.ldf 176 | **/App_Data/*.sdf 177 | 178 | 179 | #LightSwitch generated files 180 | GeneratedArtifacts/ 181 | _Pvt_Extensions/ 182 | ModelManifest.xml 183 | 184 | # ========================= 185 | # Windows detritus 186 | # ========================= 187 | 188 | # Windows image file caches 189 | Thumbs.db 190 | ehthumbs.db 191 | 192 | # Folder config file 193 | Desktop.ini 194 | 195 | # Recycle Bin used on file shares 196 | $RECYCLE.BIN/ 197 | 198 | # Mac desktop service store files 199 | .DS_Store 200 | 201 | # SASS Compiler cache 202 | .sass-cache 203 | 204 | # Visual Studio 2014 CTP 205 | **/*.sln.ide 206 | 207 | # Visual Studio temp something 208 | .vs/ 209 | 210 | # dotnet stuff 211 | project.lock.json 212 | 213 | # VS 2015+ 214 | *.vc.vc.opendb 215 | *.vc.db 216 | 217 | # Rider 218 | .idea/ 219 | .run/ 220 | 221 | # Visual Studio Code 222 | .vscode/ 223 | 224 | # Output folder used by Webpack or other FE stuff 225 | node_modules/** 226 | **/node_modules/* 227 | **/wwwroot/* 228 | **/package-lock.json 229 | 230 | # SpecFlow specific 231 | *.feature.cs 232 | *.feature.xlsx.* 233 | *.Specs_*.html 234 | 235 | Properties/** 236 | **/saves.json 237 | **/*saves.json 238 | ##### 239 | # End of core ignore list, below put you custom 'per project' settings (patterns or path) 240 | ##### 241 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Microsoft Public License (MS-PL) 2 | 3 | This license governs use of the accompanying software. If you use the software, you accept this 4 | license. If you do not accept the license, do not use the software. 5 | 6 | 1. Definitions 7 | 8 | The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning 9 | here as under U.S. copyright law. 10 | 11 | A "contribution" is the original software, or any additions or changes to the software. 12 | 13 | A "contributor" is any person that distributes its contribution under this license. 14 | 15 | "Licensed patents are a contributor's patent claims that read directly on its contribution. 16 | 17 | 2. Grant of Rights 18 | 19 | (A) Copyright Grant- Subject to the terms of this license, including the license conditions and 20 | (limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free 21 | (copyright license to reproduce its contribution, prepare derivative works of its contribution, and 22 | (distribute its contribution or any derivative works that you create. 23 | 24 | (B) Patent Grant- Subject to the terms of this license, including the license conditions and 25 | (limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free 26 | (license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or 27 | (otherwise dispose of its contribution in the software or derivative works of the contribution in 28 | (the software. 29 | 30 | 3. Conditions and Limitations 31 | 32 | (A) No Trademark License- This license does not grant you rights to use any contributors' name, 33 | (logo, or trademarks. 34 | 35 | (B) If you bring a patent claim against any contributor over patents that you claim are infringed by 36 | (the software, your patent license from such contributor to the software ends automatically. 37 | 38 | (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, 39 | (and attribution notices that are present in the software. 40 | 41 | (D) If you distribute any portion of the software in source code form, you may do so only under this 42 | (license by including a complete copy of this license with your distribution. If you distribute any 43 | (portion of the software in compiled or object code form, you may only do so under a license that 44 | (complies with this license. 45 | 46 | (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no 47 | (express warranties, guarantees or conditions. You may have additional consumer rights under your 48 | (local laws which this license cannot change. To the extent permitted under your local laws, the 49 | (contributors exclude the implied warranties of merchantability, fitness for a particular purpose 50 | (and non-infringement. -------------------------------------------------------------------------------- /MonoVision/Audio/AudioChannels.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework.Audio 8 | { 9 | /// 10 | /// Represents how many channels are used in the audio data. 11 | /// 12 | public enum AudioChannels 13 | { 14 | /// Single channel. 15 | Mono = 1, 16 | /// Two channels. 17 | Stereo = 2 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /MonoVision/Audio/InstancePlayLimitException.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Runtime.InteropServices; 7 | using System.Runtime.Serialization; 8 | 9 | namespace Microsoft.Xna.Framework.Audio 10 | { 11 | /// 12 | /// The exception thrown when the system attempts to play more SoundEffectInstances than allotted. 13 | /// 14 | /// 15 | /// Most platforms have a hard limit on how many sounds can be played simultaneously. This exception is thrown when that limit is exceeded. 16 | /// 17 | [DataContract] 18 | #if WINDOWS_UAP 19 | public sealed class InstancePlayLimitException : Exception 20 | #else 21 | public sealed class InstancePlayLimitException : ExternalException 22 | #endif 23 | { 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /MonoVision/Audio/NoAudioHardwareException.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Runtime.InteropServices; 7 | using System.Runtime.Serialization; 8 | 9 | namespace Microsoft.Xna.Framework.Audio 10 | { 11 | 12 | /// 13 | /// The exception thrown when no audio hardware is present, or driver issues are detected. 14 | /// 15 | [DataContract] 16 | #if WINDOWS_UAP 17 | public sealed class NoAudioHardwareException : Exception 18 | #else 19 | public sealed class NoAudioHardwareException : ExternalException 20 | #endif 21 | { 22 | /// A message describing the error. 23 | public NoAudioHardwareException(string msg) 24 | : base(msg) 25 | { 26 | } 27 | 28 | /// A message describing the error. 29 | /// The exception that is the underlying cause of the current exception. If not null, the current exception is raised in a try/catch block that handled the innerException. 30 | public NoAudioHardwareException(string msg, Exception innerException) 31 | : base(msg, innerException) 32 | { 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /MonoVision/Audio/SoundState.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | Microsoft Public License (Ms-PL) 4 | MonoGame - Copyright © 2009 The MonoGame Team 5 | 6 | All rights reserved. 7 | 8 | This license governs use of the accompanying software. If you use the software, you accept this license. If you do not 9 | accept the license, do not use the software. 10 | 11 | 1. Definitions 12 | The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under 13 | U.S. copyright law. 14 | 15 | A "contribution" is the original software, or any additions or changes to the software. 16 | A "contributor" is any person that distributes its contribution under this license. 17 | "Licensed patents" are a contributor's patent claims that read directly on its contribution. 18 | 19 | 2. Grant of Rights 20 | (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, 21 | each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. 22 | (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, 23 | each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. 24 | 25 | 3. Conditions and Limitations 26 | (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. 27 | (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, 28 | your patent license from such contributor to the software ends automatically. 29 | (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution 30 | notices that are present in the software. 31 | (D) If you distribute any portion of the software in source code form, you may do so only under this license by including 32 | a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object 33 | code form, you may only do so under a license that complies with this license. 34 | (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees 35 | or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent 36 | permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular 37 | purpose and non-infringement. 38 | */ 39 | #endregion License 40 | 41 | using System; 42 | 43 | namespace Microsoft.Xna.Framework.Audio 44 | { 45 | /// Described the playback state of a SoundEffectInstance. 46 | public enum SoundState 47 | { 48 | /// The SoundEffectInstance is currently playing. 49 | Playing, 50 | /// The SoundEffectInstance is currently paused. 51 | Paused, 52 | /// The SoundEffectInstance is currently stopped. 53 | Stopped 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /MonoVision/Dependencies/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelVision8/MonoVision/0032b1de6f8c48d5fe50a1af79c2f663a84ff9bc/MonoVision/Dependencies/SDL2.dll -------------------------------------------------------------------------------- /MonoVision/Dependencies/libSDL2-2.0.0.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelVision8/MonoVision/0032b1de6f8c48d5fe50a1af79c2f663a84ff9bc/MonoVision/Dependencies/libSDL2-2.0.0.dylib -------------------------------------------------------------------------------- /MonoVision/Dependencies/libSDL2-2.0.so.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelVision8/MonoVision/0032b1de6f8c48d5fe50a1af79c2f663a84ff9bc/MonoVision/Dependencies/libSDL2-2.0.so.0 -------------------------------------------------------------------------------- /MonoVision/Dependencies/libopenal.1.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelVision8/MonoVision/0032b1de6f8c48d5fe50a1af79c2f663a84ff9bc/MonoVision/Dependencies/libopenal.1.dylib -------------------------------------------------------------------------------- /MonoVision/Dependencies/libopenal.so.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelVision8/MonoVision/0032b1de6f8c48d5fe50a1af79c2f663a84ff9bc/MonoVision/Dependencies/libopenal.so.1 -------------------------------------------------------------------------------- /MonoVision/Dependencies/soft_oal.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelVision8/MonoVision/0032b1de6f8c48d5fe50a1af79c2f663a84ff9bc/MonoVision/Dependencies/soft_oal.dll -------------------------------------------------------------------------------- /MonoVision/EventHelpers.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework 8 | { 9 | /// 10 | /// Provides helper methods to make it easier 11 | /// to safely raise events. 12 | /// 13 | internal static class EventHelpers 14 | { 15 | /// 16 | /// Safely raises an event by storing a copy of the event's delegate 17 | /// in the parameter and checking it for 18 | /// null before invoking it. 19 | /// 20 | /// 21 | /// The object raising the event. 22 | /// to be invoked 23 | /// The passed to 24 | internal static void Raise(object sender, EventHandler handler, TEventArgs e) 25 | { 26 | if (handler != null) 27 | handler(sender, e); 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MonoVision/GameTime.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework 8 | { 9 | public class GameTime 10 | { 11 | public TimeSpan TotalGameTime { get; set; } 12 | 13 | public TimeSpan ElapsedGameTime { get; set; } 14 | 15 | public bool IsRunningSlowly { get; set; } 16 | 17 | public GameTime() 18 | { 19 | TotalGameTime = TimeSpan.Zero; 20 | ElapsedGameTime = TimeSpan.Zero; 21 | IsRunningSlowly = false; 22 | } 23 | 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /MonoVision/Graphics/DisplayMode.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | MIT License 4 | Copyright © 2006 The Mono.Xna Team 5 | 6 | All rights reserved. 7 | 8 | Authors: 9 | * Rob Loach 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | SOFTWARE. 28 | */ 29 | #endregion License 30 | 31 | using System; 32 | using System.Globalization; 33 | using System.Runtime.Serialization; 34 | 35 | namespace Microsoft.Xna.Framework.Graphics 36 | { 37 | [DataContract] 38 | public class DisplayMode 39 | { 40 | #region Fields 41 | 42 | // private SurfaceFormat format; 43 | private int height; 44 | private int width; 45 | 46 | #endregion Fields 47 | 48 | #region Properties 49 | 50 | public float AspectRatio { 51 | get { return (float)width / (float)height; } 52 | } 53 | 54 | // public SurfaceFormat Format { 55 | // get { return format; } 56 | // } 57 | 58 | public int Height { 59 | get { return this.height; } 60 | } 61 | 62 | public int Width { 63 | get { return this.width; } 64 | } 65 | 66 | #endregion Properties 67 | 68 | #region Constructors 69 | 70 | internal DisplayMode(int width, int height/*, SurfaceFormat format*/) 71 | { 72 | this.width = width; 73 | this.height = height; 74 | // this.format = format; 75 | } 76 | 77 | #endregion Constructors 78 | 79 | #region Operators 80 | 81 | public static bool operator !=(DisplayMode left, DisplayMode right) 82 | { 83 | return !(left == right); 84 | } 85 | 86 | public static bool operator ==(DisplayMode left, DisplayMode right) 87 | { 88 | if (ReferenceEquals(left, right)) //Same object or both are null 89 | { 90 | return true; 91 | } 92 | if (ReferenceEquals(left, null) || ReferenceEquals(right, null)) 93 | { 94 | return false; 95 | } 96 | return /*(left.format == right.format) &&*/ 97 | (left.height == right.height) && 98 | (left.width == right.width); 99 | } 100 | 101 | #endregion Operators 102 | 103 | #region Public Methods 104 | 105 | public override bool Equals(object obj) 106 | { 107 | return obj is DisplayMode && this == (DisplayMode)obj; 108 | } 109 | 110 | public override int GetHashCode() 111 | { 112 | return (this.width.GetHashCode() ^ this.height.GetHashCode() /*^ this.format.GetHashCode()*/); 113 | } 114 | 115 | public override string ToString() 116 | { 117 | return "{Width:" + this.width + " Height:" + this.height + /*" Format:" + this.Format +*/ " AspectRatio:" + this.AspectRatio + "}"; 118 | } 119 | 120 | #endregion Public Methods 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Effect/EffectParameterClass.cs: -------------------------------------------------------------------------------- 1 | // // MonoGame - Copyright (C) The MonoGame Team 2 | // // This file is subject to the terms and conditions defined in 3 | // // file 'LICENSE.txt', which is part of this source code package. 4 | // 5 | // namespace Microsoft.Xna.Framework.Graphics 6 | // { 7 | // /// 8 | // /// Defines classes for effect parameters and shader constants. 9 | // /// 10 | // public enum EffectParameterClass 11 | // { 12 | // /// 13 | // /// Scalar class type. 14 | // /// 15 | // // Scalar, 16 | // // /// 17 | // // /// Vector class type. 18 | // // /// 19 | // // Vector, 20 | // /// 21 | // /// Matrix class type. 22 | // /// 23 | // // Matrix, 24 | // } 25 | // } 26 | // 27 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Effect/EffectParameterCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Microsoft.Xna.Framework.Graphics 4 | { 5 | public class EffectParameterCollection : IEnumerable 6 | { 7 | internal static readonly EffectParameterCollection Empty = new EffectParameterCollection(new EffectParameter[0]); 8 | 9 | private readonly EffectParameter[] _parameters; 10 | private readonly Dictionary _indexLookup; 11 | 12 | internal EffectParameterCollection(EffectParameter[] parameters) 13 | { 14 | _parameters = parameters; 15 | _indexLookup = new Dictionary(_parameters.Length); 16 | for (int i = 0; i < _parameters.Length; i++) 17 | { 18 | string name = _parameters[i].Name; 19 | if(!string.IsNullOrWhiteSpace(name)) 20 | _indexLookup.Add(name, i); 21 | } 22 | } 23 | 24 | private EffectParameterCollection(EffectParameter[] parameters, Dictionary indexLookup) 25 | { 26 | _parameters = parameters; 27 | _indexLookup = indexLookup; 28 | } 29 | 30 | internal EffectParameterCollection Clone() 31 | { 32 | if (_parameters.Length == 0) 33 | return Empty; 34 | 35 | var parameters = new EffectParameter[_parameters.Length]; 36 | for (var i = 0; i < _parameters.Length; i++) 37 | parameters[i] = new EffectParameter(_parameters[i]); 38 | 39 | return new EffectParameterCollection(parameters, _indexLookup); 40 | } 41 | 42 | public int Count 43 | { 44 | get { return _parameters.Length; } 45 | } 46 | 47 | public EffectParameter this[int index] 48 | { 49 | get { return _parameters[index]; } 50 | } 51 | 52 | public EffectParameter this[string name] 53 | { 54 | get 55 | { 56 | int index; 57 | if (_indexLookup.TryGetValue(name, out index)) 58 | return _parameters[index]; 59 | return null; 60 | } 61 | } 62 | 63 | public IEnumerator GetEnumerator() 64 | { 65 | return ((IEnumerable)_parameters).GetEnumerator(); 66 | } 67 | 68 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 69 | { 70 | return _parameters.GetEnumerator(); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Effect/EffectParameterType.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | /// 8 | /// Defines types for effect parameters and shader constants. 9 | /// 10 | public enum EffectParameterType 11 | { 12 | /// 13 | /// Pointer to void type. 14 | /// 15 | Void, 16 | /// 17 | /// Boolean type. Any non-zero will be true; false otherwise. 18 | /// 19 | Bool, 20 | /// 21 | /// 32-bit integer type. 22 | /// 23 | Int32, 24 | /// 25 | /// Float type. 26 | /// 27 | Single, 28 | /// 29 | /// String type. 30 | /// 31 | String, 32 | // /// 33 | // /// Any texture type. 34 | // /// 35 | // Texture, 36 | // /// 37 | // /// 1D-texture type. 38 | // /// 39 | // Texture1D, 40 | // /// 41 | // /// 2D-texture type. 42 | // /// 43 | // Texture2D, 44 | // /// 45 | // /// 3D-texture type. 46 | // /// 47 | // Texture3D, 48 | // /// 49 | // /// Cubic texture type. 50 | // /// 51 | // TextureCube 52 | } 53 | } -------------------------------------------------------------------------------- /MonoVision/Graphics/Effect/EffectPassCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Microsoft.Xna.Framework.Graphics 5 | { 6 | public class EffectPassCollection : IEnumerable 7 | { 8 | private readonly EffectPass[] _passes; 9 | 10 | internal EffectPassCollection(EffectPass [] passes) 11 | { 12 | _passes = passes; 13 | } 14 | 15 | internal EffectPassCollection Clone(Effect effect) 16 | { 17 | var passes = new EffectPass[_passes.Length]; 18 | for (var i = 0; i < _passes.Length; i++) 19 | passes[i] = new EffectPass(effect, _passes[i]); 20 | 21 | return new EffectPassCollection(passes); 22 | } 23 | 24 | public EffectPass this[int index] 25 | { 26 | get { return _passes[index]; } 27 | } 28 | 29 | public EffectPass this[string name] 30 | { 31 | get 32 | { 33 | // TODO: Add a name to pass lookup table. 34 | foreach (var pass in _passes) 35 | { 36 | if (pass.Name == name) 37 | return pass; 38 | } 39 | return null; 40 | } 41 | } 42 | 43 | public int Count 44 | { 45 | get { return _passes.Length; } 46 | } 47 | 48 | public Enumerator GetEnumerator() 49 | { 50 | return new Enumerator(_passes); 51 | } 52 | 53 | IEnumerator IEnumerable.GetEnumerator() 54 | { 55 | return ((IEnumerable)_passes).GetEnumerator(); 56 | } 57 | 58 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 59 | { 60 | return _passes.GetEnumerator(); 61 | } 62 | 63 | public struct Enumerator : IEnumerator 64 | { 65 | private readonly EffectPass[] _array; 66 | private int _index; 67 | private EffectPass _current; 68 | 69 | internal Enumerator(EffectPass[] array) 70 | { 71 | _array = array; 72 | _index = 0; 73 | _current = null; 74 | } 75 | 76 | public bool MoveNext() 77 | { 78 | if (_index < _array.Length) 79 | { 80 | _current = _array[_index]; 81 | _index++; 82 | return true; 83 | } 84 | _index = _array.Length + 1; 85 | _current = null; 86 | return false; 87 | } 88 | 89 | public EffectPass Current 90 | { 91 | get { return _current; } 92 | } 93 | 94 | public void Dispose() 95 | { 96 | 97 | } 98 | 99 | object System.Collections.IEnumerator.Current 100 | { 101 | get 102 | { 103 | if (_index == _array.Length + 1) 104 | throw new InvalidOperationException(); 105 | return Current; 106 | } 107 | } 108 | 109 | void System.Collections.IEnumerator.Reset() 110 | { 111 | _index = 0; 112 | _current = null; 113 | } 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Effect/EffectResource.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.IO; 7 | using MonoGame.Utilities; 8 | 9 | namespace Microsoft.Xna.Framework.Graphics 10 | { 11 | /// 12 | /// Internal helper for accessing the bytecode for stock effects. 13 | /// 14 | internal partial class EffectResource 15 | { 16 | // public static readonly EffectResource AlphaTestEffect = new EffectResource(AlphaTestEffectName); 17 | // public static readonly EffectResource BasicEffect = new EffectResource(BasicEffectName); 18 | // public static readonly EffectResource DualTextureEffect = new EffectResource(DualTextureEffectName); 19 | // public static readonly EffectResource EnvironmentMapEffect = new EffectResource(EnvironmentMapEffectName); 20 | // public static readonly EffectResource SkinnedEffect = new EffectResource(SkinnedEffectName); 21 | public static readonly EffectResource SpriteEffect = new EffectResource(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content", "Effects", "SpriteEffect.ogl.mgfxo")); 22 | 23 | private readonly object _locker = new object(); 24 | private readonly string _name; 25 | private volatile byte[] _bytecode; 26 | 27 | private EffectResource(string name) 28 | { 29 | _name = name; 30 | } 31 | 32 | public byte[] Bytecode 33 | { 34 | get 35 | { 36 | if (_bytecode == null) 37 | { 38 | lock (_locker) 39 | { 40 | if (_bytecode != null) 41 | return _bytecode; 42 | 43 | // var assembly = ReflectionHelpers.GetAssembly(typeof(EffectResource)); 44 | _bytecode = File.ReadAllBytes(_name); 45 | // var stream = assembly.GetManifestResourceStream(_name); 46 | // using (var ms = new MemoryStream()) 47 | // { 48 | // stream.CopyTo(ms); 49 | // _bytecode = ms.ToArray(); 50 | // } 51 | } 52 | } 53 | 54 | return _bytecode; 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Effect/EffectTechnique.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Microsoft.Xna.Framework.Graphics 3 | { 4 | public class EffectTechnique 5 | { 6 | public EffectPassCollection Passes { get; private set; } 7 | 8 | // public EffectAnnotationCollection Annotations { get; private set; } 9 | 10 | public string Name { get; private set; } 11 | 12 | internal EffectTechnique(Effect effect, EffectTechnique cloneSource) 13 | { 14 | // Share all the immutable types. 15 | Name = cloneSource.Name; 16 | // Annotations = cloneSource.Annotations; 17 | 18 | // Clone the mutable types. 19 | Passes = cloneSource.Passes.Clone(effect); 20 | } 21 | 22 | internal EffectTechnique(string name, EffectPassCollection passes) 23 | { 24 | Name = name; 25 | Passes = passes; 26 | // Annotations = annotations; 27 | } 28 | } 29 | 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Effect/EffectTechniqueCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Microsoft.Xna.Framework.Graphics 4 | { 5 | public class EffectTechniqueCollection : IEnumerable 6 | { 7 | private readonly EffectTechnique[] _techniques; 8 | 9 | public int Count { get { return _techniques.Length; } } 10 | 11 | internal EffectTechniqueCollection(EffectTechnique[] techniques) 12 | { 13 | _techniques = techniques; 14 | } 15 | 16 | internal EffectTechniqueCollection Clone(Effect effect) 17 | { 18 | var techniques = new EffectTechnique[_techniques.Length]; 19 | for (var i = 0; i < _techniques.Length; i++) 20 | techniques[i] = new EffectTechnique(effect, _techniques[i]); 21 | 22 | return new EffectTechniqueCollection(techniques); 23 | } 24 | 25 | public EffectTechnique this[int index] 26 | { 27 | get { return _techniques [index]; } 28 | } 29 | 30 | // public EffectTechnique this[string name] 31 | // { 32 | // get 33 | // { 34 | // // TODO: Add a name to technique lookup table. 35 | // foreach (var technique in _techniques) 36 | // { 37 | // if (technique.Name == name) 38 | // return technique; 39 | // } 40 | // 41 | // return null; 42 | // } 43 | // } 44 | 45 | public IEnumerator GetEnumerator() 46 | { 47 | return ((IEnumerable)_techniques).GetEnumerator(); 48 | } 49 | 50 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 51 | { 52 | return _techniques.GetEnumerator(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Effect/SpriteEffect.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | // Microsoft XNA Community Game Platform 6 | // Copyright (C) Microsoft Corporation. All rights reserved. 7 | 8 | namespace Microsoft.Xna.Framework.Graphics 9 | { 10 | /// 11 | /// The default effect used by SpriteBatch. 12 | /// 13 | public class SpriteEffect : Effect 14 | { 15 | private EffectParameter _matrixParam; 16 | private Viewport _lastViewport; 17 | private Matrix _projection; 18 | 19 | /// 20 | /// Creates a new SpriteEffect. 21 | /// 22 | public SpriteEffect(GraphicsDevice device) 23 | : base(device, EffectResource.SpriteEffect.Bytecode) 24 | { 25 | CacheEffectParameters(); 26 | } 27 | 28 | /// 29 | /// An optional matrix used to transform the sprite geometry. Uses if null. 30 | /// 31 | public Matrix? TransformMatrix { get; set; } 32 | 33 | /// 34 | /// Creates a new SpriteEffect by cloning parameter settings from an existing instance. 35 | /// 36 | protected SpriteEffect(SpriteEffect cloneSource) 37 | : base(cloneSource) 38 | { 39 | CacheEffectParameters(); 40 | } 41 | 42 | 43 | /// 44 | /// Creates a clone of the current SpriteEffect instance. 45 | /// 46 | public override Effect Clone() 47 | { 48 | return new SpriteEffect(this); 49 | } 50 | 51 | 52 | /// 53 | /// Looks up shortcut references to our effect parameters. 54 | /// 55 | void CacheEffectParameters() 56 | { 57 | _matrixParam = Parameters["MatrixTransform"]; 58 | } 59 | 60 | /// 61 | /// Lazily computes derived parameter values immediately before applying the effect. 62 | /// 63 | protected internal override void OnApply() 64 | { 65 | var vp = GraphicsDevice.Viewport; 66 | if ((vp.Width != _lastViewport.Width) || (vp.Height != _lastViewport.Height)) 67 | { 68 | // Normal 3D cameras look into the -z direction (z = 1 is in front of z = 0). The 69 | // sprite batch layer depth is the opposite (z = 0 is in front of z = 1). 70 | // --> We get the correct matrix with near plane 0 and far plane -1. 71 | Matrix.CreateOrthographicOffCenter(0, vp.Width, vp.Height, 0, 0, -1, out _projection); 72 | 73 | // if (GraphicsDevice.UseHalfPixelOffset) 74 | // { 75 | // _projection.M41 += -0.5f * _projection.M11; 76 | // _projection.M42 += -0.5f * _projection.M22; 77 | // } 78 | 79 | _lastViewport = vp; 80 | } 81 | 82 | if (TransformMatrix.HasValue) 83 | _matrixParam.SetValue(TransformMatrix.GetValueOrDefault() * _projection); 84 | else 85 | _matrixParam.SetValue(_projection); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /MonoVision/Graphics/GraphicsCapabilities.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | 8 | namespace Microsoft.Xna.Framework.Graphics 9 | { 10 | /// 11 | /// Provides information about the capabilities of the 12 | /// current graphics device. A very useful thread for investigating GL extenion names 13 | /// http://stackoverflow.com/questions/3881197/opengl-es-2-0-extensions-on-android-devices 14 | /// 15 | internal partial class GraphicsCapabilities 16 | { 17 | internal void Initialize(GraphicsDevice device) 18 | { 19 | PlatformInitialize(device); 20 | } 21 | 22 | /// 23 | /// Whether the device fully supports non power-of-two textures, including 24 | /// mip maps and wrap modes other than CLAMP_TO_EDGE 25 | /// 26 | internal bool SupportsNonPowerOfTwo { get; private set; } 27 | 28 | /// 29 | /// Whether the device supports anisotropic texture filtering 30 | /// 31 | internal bool SupportsTextureFilterAnisotropic { get; private set; } 32 | 33 | internal bool SupportsDepth24 { get; private set; } 34 | 35 | internal bool SupportsPackedDepthStencil { get; private set; } 36 | 37 | internal bool SupportsDepthNonLinear { get; private set; } 38 | 39 | /// 40 | /// Gets the support for DXT1 41 | /// 42 | internal bool SupportsDxt1 { get; private set; } 43 | 44 | /// 45 | /// Gets the support for S3TC (DXT1, DXT3, DXT5) 46 | /// 47 | internal bool SupportsS3tc { get; private set; } 48 | 49 | /// 50 | /// Gets the support for PVRTC 51 | /// 52 | internal bool SupportsPvrtc { get; private set; } 53 | 54 | /// 55 | /// Gets the support for ETC1 56 | /// 57 | internal bool SupportsEtc1 { get; private set; } 58 | 59 | /// 60 | /// Gets the support for ETC2 61 | /// 62 | internal bool SupportsEtc2 { get; private set; } 63 | 64 | /// 65 | /// Gets the support for ATITC 66 | /// 67 | internal bool SupportsAtitc { get; private set; } 68 | 69 | internal bool SupportsTextureMaxLevel { get; private set; } 70 | 71 | /// 72 | /// True, if sRGB is supported. On Direct3D platforms, this is always true. 73 | /// On OpenGL platforms, it is true if both framebuffer sRGB 74 | /// and texture sRGB are supported. 75 | /// 76 | internal bool SupportsSRgb { get; private set; } 77 | 78 | internal bool SupportsTextureArrays { get; private set; } 79 | 80 | internal bool SupportsDepthClamp { get; private set; } 81 | 82 | internal bool SupportsVertexTextures { get; private set; } 83 | 84 | /// 85 | /// True, if the underlying platform supports floating point textures. 86 | /// For Direct3D platforms this is always true. 87 | /// For OpenGL Desktop platforms it is always true. 88 | /// For OpenGL Mobile platforms it requires `GL_EXT_color_buffer_float`. 89 | /// If the requested format is not supported an NotSupportedException 90 | /// will be thrown. 91 | /// 92 | internal bool SupportsFloatTextures { get; private set; } 93 | 94 | /// 95 | /// True, if the underlying platform supports half floating point textures. 96 | /// For Direct3D platforms this is always true. 97 | /// For OpenGL Desktop platforms it is always true. 98 | /// For OpenGL Mobile platforms it requires `GL_EXT_color_buffer_half_float`. 99 | /// If the requested format is not supported an NotSupportedException 100 | /// will be thrown. 101 | /// 102 | internal bool SupportsHalfFloatTextures { get; private set; } 103 | 104 | internal bool SupportsNormalized { get; private set; } 105 | 106 | /// 107 | /// Gets the max texture anisotropy. This value typically lies 108 | /// between 0 and 16, where 0 means anisotropic filtering is not 109 | /// supported. 110 | /// 111 | internal int MaxTextureAnisotropy { get; private set; } 112 | 113 | // The highest possible MSCount 114 | // private const int MultiSampleCountLimit = 32; 115 | 116 | private int _maxMultiSampleCount; 117 | 118 | internal int MaxMultiSampleCount 119 | { 120 | get { return _maxMultiSampleCount; } 121 | } 122 | 123 | internal bool SupportsInstancing { get; private set; } 124 | 125 | internal bool SupportsBaseIndexInstancing { get; private set; } 126 | 127 | internal bool SupportsSeparateBlendStates { get; private set; } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /MonoVision/Graphics/IGraphicsDeviceService.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | Microsoft Public License (Ms-PL) 4 | MonoGame - Copyright © 2009 The MonoGame Team 5 | 6 | All rights reserved. 7 | 8 | This license governs use of the accompanying software. If you use the software, you accept this license. If you do not 9 | accept the license, do not use the software. 10 | 11 | 1. Definitions 12 | The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under 13 | U.S. copyright law. 14 | 15 | A "contribution" is the original software, or any additions or changes to the software. 16 | A "contributor" is any person that distributes its contribution under this license. 17 | "Licensed patents" are a contributor's patent claims that read directly on its contribution. 18 | 19 | 2. Grant of Rights 20 | (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, 21 | each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. 22 | (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, 23 | each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. 24 | 25 | 3. Conditions and Limitations 26 | (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. 27 | (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, 28 | your patent license from such contributor to the software ends automatically. 29 | (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution 30 | notices that are present in the software. 31 | (D) If you distribute any portion of the software in source code form, you may do so only under this license by including 32 | a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object 33 | code form, you may only do so under a license that complies with this license. 34 | (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees 35 | or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent 36 | permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular 37 | purpose and non-infringement. 38 | */ 39 | #endregion License 40 | 41 | using System; 42 | 43 | namespace Microsoft.Xna.Framework.Graphics 44 | { 45 | public interface IGraphicsDeviceService 46 | { 47 | GraphicsDevice GraphicsDevice { get; } 48 | 49 | // event EventHandler DeviceCreated; 50 | // event EventHandler DeviceDisposing; 51 | // event EventHandler DeviceReset; 52 | // event EventHandler DeviceResetting; 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /MonoVision/Graphics/NoSuitableGraphicsDeviceException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace Microsoft.Xna.Framework.Graphics 5 | { 6 | [DataContract] 7 | public sealed class NoSuitableGraphicsDeviceException : Exception 8 | { 9 | // public NoSuitableGraphicsDeviceException() 10 | // : base() 11 | // { 12 | // 13 | // } 14 | 15 | public NoSuitableGraphicsDeviceException(string message) 16 | : base(message) 17 | { 18 | 19 | } 20 | 21 | public NoSuitableGraphicsDeviceException(string message, Exception inner) 22 | : base(message, inner) 23 | { 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MonoVision/Graphics/PresentationEventArgs.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework.Graphics 8 | { 9 | internal class PresentationEventArgs : EventArgs 10 | { 11 | public PresentationParameters PresentationParameters { get; private set; } 12 | 13 | public PresentationEventArgs(PresentationParameters presentationParameters) 14 | { 15 | PresentationParameters = presentationParameters; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MonoVision/Graphics/PresentationParameters.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | public class PresentationParameters 8 | { 9 | #region Constants 10 | 11 | #endregion Constants 12 | 13 | #region Private Fields 14 | 15 | private int backBufferHeight = GraphicsDeviceManager.DefaultBackBufferHeight; 16 | private int backBufferWidth = GraphicsDeviceManager.DefaultBackBufferWidth; 17 | private bool isFullScreen; 18 | private bool hardwareModeSwitch = true; 19 | 20 | #endregion Private Fields 21 | 22 | #region Constructors 23 | 24 | /// 25 | /// Create a instance with default values for all properties. 26 | /// 27 | public PresentationParameters() 28 | { 29 | Clear(); 30 | } 31 | 32 | #endregion Constructors 33 | 34 | #region Properties 35 | 36 | /// 37 | /// Get or set the height of the back buffer. 38 | /// 39 | public int BackBufferHeight 40 | { 41 | get { return backBufferHeight; } 42 | set { backBufferHeight = value; } 43 | } 44 | 45 | /// 46 | /// Get or set the width of the back buffer. 47 | /// 48 | public int BackBufferWidth 49 | { 50 | get { return backBufferWidth; } 51 | set { backBufferWidth = value; } 52 | } 53 | 54 | /// 55 | /// Get or set a value indicating if we are in full screen mode. 56 | /// 57 | public bool IsFullScreen 58 | { 59 | get 60 | { 61 | return isFullScreen; 62 | } 63 | set 64 | { 65 | isFullScreen = value; 66 | } 67 | } 68 | 69 | /// 70 | /// If true the will do a mode switch 71 | /// when going to full screen mode. If false it will instead do a 72 | /// soft full screen by maximizing the window and making it borderless. 73 | /// 74 | public bool HardwareModeSwitch 75 | { 76 | get { return hardwareModeSwitch; } 77 | set { hardwareModeSwitch = value; } 78 | } 79 | 80 | /// 81 | /// Get or set the presentation interval. 82 | /// 83 | // public PresentInterval PresentationInterval { get; set; } 84 | 85 | #endregion Properties 86 | 87 | 88 | #region Methods 89 | 90 | /// 91 | /// Reset all properties to their default values. 92 | /// 93 | public void Clear() 94 | { 95 | backBufferWidth = GraphicsDeviceManager.DefaultBackBufferWidth; 96 | backBufferHeight = GraphicsDeviceManager.DefaultBackBufferHeight; 97 | // PresentationInterval = PresentInterval.Default; 98 | } 99 | 100 | #endregion Methods 101 | 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /MonoVision/Graphics/SamplerStateCollection.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | // 5 | // Author: Kenneth James Pouncey 6 | 7 | using System; 8 | 9 | namespace Microsoft.Xna.Framework.Graphics 10 | { 11 | public sealed partial class SamplerStateCollection 12 | { 13 | private readonly GraphicsDevice _graphicsDevice; 14 | 15 | // private readonly SamplerState _samplerStateAnisotropicClamp; 16 | // private readonly SamplerState _samplerStateAnisotropicWrap; 17 | // private readonly SamplerState _samplerStateLinearClamp; 18 | // private readonly SamplerState _samplerStateLinearWrap; 19 | private readonly SamplerState _samplerStatePointClamp; 20 | // private readonly SamplerState _samplerStatePointWrap; 21 | 22 | private readonly SamplerState[] _samplers; 23 | private readonly SamplerState[] _actualSamplers; 24 | // private readonly bool _applyToVertexStage; 25 | 26 | internal SamplerStateCollection(GraphicsDevice device, int maxSamplers, bool applyToVertexStage) 27 | { 28 | _graphicsDevice = device; 29 | 30 | // _samplerStateAnisotropicClamp = SamplerState.AnisotropicClamp.Clone(); 31 | // _samplerStateAnisotropicWrap = SamplerState.AnisotropicWrap.Clone(); 32 | // _samplerStateLinearClamp = SamplerState.LinearClamp.Clone(); 33 | // _samplerStateLinearWrap = SamplerState.LinearWrap.Clone(); 34 | _samplerStatePointClamp = SamplerState.PointClamp.Clone(); 35 | // _samplerStatePointWrap = SamplerState.PointWrap.Clone(); 36 | 37 | _samplers = new SamplerState[maxSamplers]; 38 | _actualSamplers = new SamplerState[maxSamplers]; 39 | // _applyToVertexStage = applyToVertexStage; 40 | 41 | Clear(); 42 | } 43 | 44 | public SamplerState this [int index] 45 | { 46 | get 47 | { 48 | return _samplers[index]; 49 | } 50 | 51 | set 52 | { 53 | if (value == null) 54 | throw new ArgumentNullException("value"); 55 | 56 | if (_samplers[index] == value) 57 | return; 58 | 59 | _samplers[index] = value; 60 | 61 | // Static state properties never actually get bound; 62 | // instead we use our GraphicsDevice-specific version of them. 63 | // var newSamplerState = value; 64 | // if (ReferenceEquals(value, SamplerState.AnisotropicClamp)) 65 | // newSamplerState = _samplerStateAnisotropicClamp; 66 | // else if (ReferenceEquals(value, SamplerState.AnisotropicWrap)) 67 | // newSamplerState = _samplerStateAnisotropicWrap; 68 | // else if (ReferenceEquals(value, SamplerState.LinearClamp)) 69 | // newSamplerState = _samplerStateLinearClamp; 70 | // else if (ReferenceEquals(value, SamplerState.LinearWrap)) 71 | // newSamplerState = _samplerStateLinearWrap; 72 | // else if (ReferenceEquals(value, SamplerState.PointClamp)) 73 | // newSamplerState = _samplerStatePointClamp; 74 | // else if (ReferenceEquals(value, SamplerState.PointWrap)) 75 | // newSamplerState = _samplerStatePointWrap; 76 | 77 | // _samplerStatePointClamp.BindToGraphicsDevice(_graphicsDevice); 78 | 79 | _actualSamplers[index] = _samplerStatePointClamp; 80 | 81 | PlatformSetSamplerState(index); 82 | } 83 | } 84 | 85 | internal void Clear() 86 | { 87 | // for (var i = 0; i < _samplers.Length; i++) 88 | // { 89 | // _samplers[i] = SamplerState.LinearWrap; 90 | // 91 | // _samplerStateLinearWrap.BindToGraphicsDevice(_graphicsDevice); 92 | // _actualSamplers[i] = _samplerStateLinearWrap; 93 | // } 94 | 95 | PlatformClear(); 96 | } 97 | 98 | /// 99 | /// Mark all the sampler slots as dirty. 100 | /// 101 | internal void Dirty() 102 | { 103 | PlatformDirty(); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /MonoVision/Graphics/SetDataOptions.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | /// 8 | /// Defines how vertex or index buffer data will be flushed during a SetData operation. 9 | /// 10 | public enum SetDataOptions 11 | { 12 | /// 13 | /// The SetData can overwrite the portions of existing data. 14 | /// 15 | None, 16 | /// 17 | /// The SetData will discard the entire buffer. A pointer to a new memory area is returned and rendering from the previous area do not stall. 18 | /// 19 | Discard, 20 | /// 21 | /// The SetData operation will not overwrite existing data. This allows the driver to return immediately from a SetData operation and continue rendering. 22 | /// 23 | NoOverwrite 24 | } 25 | } -------------------------------------------------------------------------------- /MonoVision/Graphics/Shader/ConstantBufferCollection.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | internal sealed class ConstantBufferCollection 8 | { 9 | private readonly ConstantBuffer[] _buffers; 10 | 11 | // private ShaderStage _stage; 12 | // private ShaderStage Stage { get { return this._stage; } } 13 | 14 | private int _valid; 15 | 16 | internal ConstantBufferCollection(int maxBuffers) 17 | { 18 | // _stage = stage; 19 | _buffers = new ConstantBuffer[maxBuffers]; 20 | _valid = 0; 21 | } 22 | 23 | public ConstantBuffer this[int index] 24 | { 25 | get { return _buffers[index]; } 26 | set 27 | { 28 | if (_buffers[index] == value) 29 | return; 30 | 31 | if (value != null) 32 | { 33 | _buffers[index] = value; 34 | _valid |= 1 << index; 35 | } 36 | else 37 | { 38 | _buffers[index] = null; 39 | _valid &= ~(1 << index); 40 | } 41 | } 42 | } 43 | 44 | internal void Clear() 45 | { 46 | for (var i = 0; i < _buffers.Length; i++) 47 | _buffers[i] = null; 48 | 49 | _valid = 0; 50 | } 51 | 52 | #if WEB 53 | internal void SetConstantBuffers(GraphicsDevice device, int shaderProgram) 54 | #elif OPENGL 55 | internal void SetConstantBuffers(GraphicsDevice device, ShaderProgram shaderProgram) 56 | #else 57 | internal void SetConstantBuffers(GraphicsDevice device) 58 | #endif 59 | { 60 | // If there are no constant buffers then skip it. 61 | if (_valid == 0) 62 | return; 63 | 64 | var valid = _valid; 65 | 66 | for (var i = 0; i < _buffers.Length; i++) 67 | { 68 | var buffer = _buffers[i]; 69 | if (buffer != null && !buffer.IsDisposed) 70 | { 71 | #if OPENGL || WEB 72 | buffer.PlatformApply(device, shaderProgram); 73 | #else 74 | buffer.PlatformApply(device, _stage, i); 75 | #endif 76 | } 77 | 78 | // Early out if this is the last one. 79 | valid &= ~(1 << i); 80 | if (valid == 0) 81 | return; 82 | } 83 | } 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Shader/Shader.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.IO; 7 | 8 | namespace Microsoft.Xna.Framework.Graphics 9 | { 10 | 11 | // TODO: We should convert the types below 12 | // into the start of a Shader reflection API. 13 | 14 | internal enum SamplerType 15 | { 16 | Sampler2D = 0, 17 | SamplerCube = 1, 18 | SamplerVolume = 2, 19 | Sampler1D = 3, 20 | } 21 | 22 | internal struct SamplerInfo 23 | { 24 | public SamplerType type; 25 | public int textureSlot; 26 | public int samplerSlot; 27 | public string name; 28 | public SamplerState state; 29 | 30 | // TODO: This should be moved to EffectPass. 31 | public int parameter; 32 | } 33 | 34 | internal struct VertexAttribute 35 | { 36 | public VertexElementUsage usage; 37 | public int index; 38 | public string name; 39 | public int location; 40 | } 41 | 42 | internal partial class Shader : GraphicsResource 43 | { 44 | /// 45 | /// Returns the platform specific shader profile identifier. 46 | /// 47 | public static int Profile { get { return PlatformProfile(); } } 48 | 49 | /// 50 | /// A hash value which can be used to compare shaders. 51 | /// 52 | internal int HashKey { get; private set; } 53 | 54 | public SamplerInfo[] Samplers { get; private set; } 55 | 56 | public int[] CBuffers { get; private set; } 57 | 58 | public ShaderStage Stage { get; private set; } 59 | 60 | public VertexAttribute[] Attributes { get; private set; } 61 | 62 | internal Shader(GraphicsDevice device, BinaryReader reader) 63 | { 64 | GraphicsDevice = device; 65 | 66 | var isVertexShader = reader.ReadBoolean(); 67 | Stage = isVertexShader ? ShaderStage.Vertex : ShaderStage.Pixel; 68 | 69 | var shaderLength = reader.ReadInt32(); 70 | var shaderBytecode = reader.ReadBytes(shaderLength); 71 | 72 | var samplerCount = (int)reader.ReadByte(); 73 | Samplers = new SamplerInfo[samplerCount]; 74 | for (var s = 0; s < samplerCount; s++) 75 | { 76 | Samplers[s].type = (SamplerType)reader.ReadByte(); 77 | Samplers[s].textureSlot = reader.ReadByte(); 78 | Samplers[s].samplerSlot = reader.ReadByte(); 79 | 80 | if (reader.ReadBoolean()) 81 | { 82 | // Samplers[s].state = new SamplerState(); 83 | // Samplers[s].state.AddressU = (TextureAddressMode)reader.ReadByte(); 84 | // Samplers[s].state.AddressV = (TextureAddressMode)reader.ReadByte(); 85 | // Samplers[s].state.AddressW = (TextureAddressMode)reader.ReadByte(); 86 | Samplers[s].state.BorderColor = new Color( 87 | reader.ReadByte(), 88 | reader.ReadByte(), 89 | reader.ReadByte(), 90 | reader.ReadByte()); 91 | // Samplers[s].state.Filter = (TextureFilter)reader.ReadByte(); 92 | // Samplers[s].state.MaxAnisotropy = reader.ReadInt32(); 93 | // Samplers[s].state.MaxMipLevel = reader.ReadInt32(); 94 | // Samplers[s].state.MipMapLevelOfDetailBias = reader.ReadSingle(); 95 | } 96 | 97 | Samplers[s].name = reader.ReadString(); 98 | Samplers[s].parameter = reader.ReadByte(); 99 | } 100 | 101 | var cbufferCount = (int)reader.ReadByte(); 102 | CBuffers = new int[cbufferCount]; 103 | for (var c = 0; c < cbufferCount; c++) 104 | CBuffers[c] = reader.ReadByte(); 105 | 106 | var attributeCount = (int)reader.ReadByte(); 107 | Attributes = new VertexAttribute[attributeCount]; 108 | for (var a = 0; a < attributeCount; a++) 109 | { 110 | Attributes[a].name = reader.ReadString(); 111 | Attributes[a].usage = (VertexElementUsage)reader.ReadByte(); 112 | Attributes[a].index = reader.ReadByte(); 113 | Attributes[a].location = reader.ReadInt16(); 114 | } 115 | 116 | PlatformConstruct(Stage, shaderBytecode); 117 | } 118 | 119 | // internal protected override void GraphicsDeviceResetting() 120 | // { 121 | // PlatformGraphicsDeviceResetting(); 122 | // } 123 | } 124 | } 125 | 126 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Shader/ShaderStage.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Xna.Framework.Graphics 2 | { 3 | internal enum ShaderStage 4 | { 5 | Vertex, 6 | Pixel, 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MonoVision/Graphics/SpriteBatchItem.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework.Graphics 8 | { 9 | internal class SpriteBatchItem : IComparable 10 | { 11 | public Texture2D Texture; 12 | public float SortKey; 13 | 14 | public VertexPositionColorTexture vertexTL; 15 | public VertexPositionColorTexture vertexTR; 16 | public VertexPositionColorTexture vertexBL; 17 | public VertexPositionColorTexture vertexBR; 18 | public SpriteBatchItem () 19 | { 20 | vertexTL = new VertexPositionColorTexture(); 21 | vertexTR = new VertexPositionColorTexture(); 22 | vertexBL = new VertexPositionColorTexture(); 23 | vertexBR = new VertexPositionColorTexture(); 24 | } 25 | 26 | public void Set(float x, float y, float w, float h, Color color, Vector2 texCoordTL, Vector2 texCoordBR) 27 | { 28 | vertexTL.Position.X = x; 29 | vertexTL.Position.Y = y; 30 | // vertexTL.Position.Z = depth; 31 | vertexTL.Color = color; 32 | vertexTL.TextureCoordinate.X = texCoordTL.X; 33 | vertexTL.TextureCoordinate.Y = texCoordTL.Y; 34 | 35 | vertexTR.Position.X = x + w; 36 | vertexTR.Position.Y = y; 37 | // vertexTR.Position.Z = depth; 38 | vertexTR.Color = color; 39 | vertexTR.TextureCoordinate.X = texCoordBR.X; 40 | vertexTR.TextureCoordinate.Y = texCoordTL.Y; 41 | 42 | vertexBL.Position.X = x; 43 | vertexBL.Position.Y = y + h; 44 | // vertexBL.Position.Z = depth; 45 | vertexBL.Color = color; 46 | vertexBL.TextureCoordinate.X = texCoordTL.X; 47 | vertexBL.TextureCoordinate.Y = texCoordBR.Y; 48 | 49 | vertexBR.Position.X = x + w; 50 | vertexBR.Position.Y = y + h; 51 | // vertexBR.Position.Z = depth; 52 | vertexBR.Color = color; 53 | vertexBR.TextureCoordinate.X = texCoordBR.X; 54 | vertexBR.TextureCoordinate.Y = texCoordBR.Y; 55 | } 56 | 57 | #region Implement IComparable 58 | public int CompareTo(SpriteBatchItem other) 59 | { 60 | return SortKey.CompareTo(other.SortKey); 61 | } 62 | #endregion 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /MonoVision/Graphics/SpriteSortMode.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | /// 8 | /// Defines sprite sort rendering options. 9 | /// 10 | public enum SpriteSortMode 11 | { 12 | /// 13 | /// All sprites are drawing when invokes, in order of draw call sequence. Depth is ignored. 14 | /// 15 | Deferred, 16 | /// 17 | /// Each sprite is drawing at individual draw call, instead of . Depth is ignored. 18 | /// 19 | Immediate, 20 | /// 21 | /// Same as , except sprites are sorted by texture prior to drawing. Depth is ignored. 22 | /// 23 | Texture, 24 | /// 25 | /// Same as , except sprites are sorted by depth in back-to-front order prior to drawing. 26 | /// 27 | BackToFront, 28 | /// 29 | /// Same as , except sprites are sorted by depth in front-to-back order prior to drawing. 30 | /// 31 | FrontToBack 32 | } 33 | } -------------------------------------------------------------------------------- /MonoVision/Graphics/States/SamplerState.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework.Graphics 8 | { 9 | public partial class SamplerState : GraphicsResource 10 | { 11 | static SamplerState() 12 | { 13 | PointClamp = new SamplerState("SamplerState.PointClamp"); 14 | } 15 | 16 | public static readonly SamplerState PointClamp; 17 | // private readonly bool _defaultStateObject; 18 | private Color _borderColor; 19 | // private int _maxAnisotropy; 20 | // private int _maxMipLevel; 21 | // private float _mipMapLevelOfDetailBias; 22 | // private CompareFunction _comparisonFunction; 23 | 24 | public Color BorderColor 25 | { 26 | get { return _borderColor; } 27 | set 28 | { 29 | // ThrowIfBound(); 30 | _borderColor = value; 31 | } 32 | } 33 | 34 | // public int MaxAnisotropy 35 | // { 36 | // get { return _maxAnisotropy; } 37 | // set 38 | // { 39 | // ThrowIfBound(); 40 | // _maxAnisotropy = value; 41 | // } 42 | // } 43 | 44 | // public int MaxMipLevel 45 | // { 46 | // get { return _maxMipLevel; } 47 | // set 48 | // { 49 | // ThrowIfBound(); 50 | // _maxMipLevel = value; 51 | // } 52 | // } 53 | 54 | // public float MipMapLevelOfDetailBias 55 | // { 56 | // get { return _mipMapLevelOfDetailBias; } 57 | // set 58 | // { 59 | // ThrowIfBound(); 60 | // _mipMapLevelOfDetailBias = value; 61 | // } 62 | // } 63 | 64 | /// 65 | /// When using comparison sampling, also set to . 66 | /// 67 | // public CompareFunction ComparisonFunction 68 | // { 69 | // get { return _comparisonFunction; } 70 | // set 71 | // { 72 | // ThrowIfBound(); 73 | // _comparisonFunction = value; 74 | // } 75 | // } 76 | 77 | // internal void BindToGraphicsDevice(GraphicsDevice device) 78 | // { 79 | // if (_defaultStateObject) 80 | // throw new InvalidOperationException("You cannot bind a default state object."); 81 | // if (GraphicsDevice != null && GraphicsDevice != device) 82 | // throw new InvalidOperationException("This sampler state is already bound to a different graphics device."); 83 | // GraphicsDevice = device; 84 | // } 85 | 86 | // internal void ThrowIfBound() 87 | // { 88 | // if (_defaultStateObject) 89 | // throw new InvalidOperationException("You cannot modify a default sampler state object."); 90 | // if (GraphicsDevice != null) 91 | // throw new InvalidOperationException("You cannot modify the sampler state after it has been bound to the graphics device!"); 92 | // } 93 | 94 | public SamplerState() 95 | { 96 | BorderColor = Color.White; 97 | // MaxAnisotropy = 4; 98 | // MaxMipLevel = 0; 99 | // MipMapLevelOfDetailBias = 0.0f; 100 | // ComparisonFunction = CompareFunction.Never; 101 | } 102 | 103 | private SamplerState(string name/*, TextureFilter filter, TextureAddressMode addressMode*/) 104 | : this() 105 | { 106 | Name = name; 107 | 108 | // _defaultStateObject = true; 109 | } 110 | 111 | private SamplerState(SamplerState cloneSource) 112 | { 113 | Name = cloneSource.Name; 114 | 115 | _borderColor = cloneSource._borderColor; 116 | // _maxAnisotropy = cloneSource._maxAnisotropy; 117 | // _maxMipLevel = cloneSource._maxMipLevel; 118 | // _mipMapLevelOfDetailBias = cloneSource._mipMapLevelOfDetailBias; 119 | // _comparisonFunction = cloneSource._comparisonFunction; 120 | } 121 | 122 | internal SamplerState Clone() 123 | { 124 | return new SamplerState(this); 125 | } 126 | 127 | partial void PlatformDispose(); 128 | 129 | protected override void Dispose(bool disposing) 130 | { 131 | if (!IsDisposed) 132 | { 133 | PlatformDispose(); 134 | } 135 | base.Dispose(disposing); 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /MonoVision/Graphics/SurfaceFormat.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | /// 8 | /// Defines types of surface formats. 9 | /// 10 | public enum SurfaceFormat 11 | { 12 | 13 | Color, 14 | 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Texture.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Threading; 7 | 8 | namespace Microsoft.Xna.Framework.Graphics 9 | { 10 | public abstract partial class Texture : GraphicsResource 11 | { 12 | internal SurfaceFormat _format; 13 | internal int _levelCount; 14 | 15 | private readonly int _sortingKey = Interlocked.Increment(ref _lastSortingKey); 16 | private static int _lastSortingKey; 17 | 18 | /// 19 | /// Gets a unique identifier of this texture for sorting purposes. 20 | /// 21 | /// 22 | /// For example, this value is used by when drawing with . 23 | /// The value is an implementation detail and may change between application launches or MonoGame versions. 24 | /// It is only guaranteed to stay consistent during application lifetime. 25 | /// 26 | internal int SortingKey 27 | { 28 | get { return _sortingKey; } 29 | } 30 | 31 | public SurfaceFormat Format 32 | { 33 | get { return _format; } 34 | } 35 | 36 | public int LevelCount 37 | { 38 | get { return _levelCount; } 39 | } 40 | 41 | internal static int CalculateMipLevels(int width, int height = 0, int depth = 0) 42 | { 43 | int levels = 1; 44 | int size = Math.Max(Math.Max(width, height), depth); 45 | while (size > 1) 46 | { 47 | size = size / 2; 48 | levels++; 49 | } 50 | return levels; 51 | } 52 | 53 | internal static void GetSizeForLevel(int width, int height, int level, out int w, out int h) 54 | { 55 | w = width; 56 | h = height; 57 | while (level > 0) 58 | { 59 | --level; 60 | w /= 2; 61 | h /= 2; 62 | } 63 | if (w == 0) 64 | w = 1; 65 | if (h == 0) 66 | h = 1; 67 | } 68 | 69 | // internal static void GetSizeForLevel(int width, int height, int depth, int level, out int w, out int h, out int d) 70 | // { 71 | // w = width; 72 | // h = height; 73 | // d = depth; 74 | // while (level > 0) 75 | // { 76 | // --level; 77 | // w /= 2; 78 | // h /= 2; 79 | // d /= 2; 80 | // } 81 | // if (w == 0) 82 | // w = 1; 83 | // if (h == 0) 84 | // h = 1; 85 | // if (d == 0) 86 | // d = 1; 87 | // } 88 | 89 | // internal int GetPitch(int width) 90 | // { 91 | // Debug.Assert(width > 0, "The width is negative!"); 92 | // 93 | // int pitch; 94 | // 95 | // switch (_format) 96 | // { 97 | // case SurfaceFormat.Dxt1: 98 | // case SurfaceFormat.Dxt1SRgb: 99 | // case SurfaceFormat.Dxt1a: 100 | // case SurfaceFormat.RgbPvrtc2Bpp: 101 | // case SurfaceFormat.RgbaPvrtc2Bpp: 102 | // case SurfaceFormat.RgbEtc1: 103 | // case SurfaceFormat.Rgb8Etc2: 104 | // case SurfaceFormat.Srgb8Etc2: 105 | // case SurfaceFormat.Rgb8A1Etc2: 106 | // case SurfaceFormat.Srgb8A1Etc2: 107 | // case SurfaceFormat.Dxt3: 108 | // case SurfaceFormat.Dxt3SRgb: 109 | // case SurfaceFormat.Dxt5: 110 | // case SurfaceFormat.Dxt5SRgb: 111 | // case SurfaceFormat.RgbPvrtc4Bpp: 112 | // case SurfaceFormat.RgbaPvrtc4Bpp: 113 | // pitch = ((width + 3) / 4) * _format.GetSize(); 114 | // break; 115 | // 116 | // default: 117 | // pitch = width * _format.GetSize(); 118 | // break; 119 | // }; 120 | // 121 | // return pitch; 122 | // } 123 | 124 | // internal protected override void GraphicsDeviceResetting() 125 | // { 126 | // PlatformGraphicsDeviceResetting(); 127 | // } 128 | } 129 | } 130 | 131 | -------------------------------------------------------------------------------- /MonoVision/Graphics/TextureCollection.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework.Graphics 8 | { 9 | public sealed partial class TextureCollection 10 | { 11 | private readonly GraphicsDevice _graphicsDevice; 12 | private readonly Texture[] _textures; 13 | private readonly bool _applyToVertexStage; 14 | private int _dirty; 15 | 16 | internal TextureCollection(GraphicsDevice graphicsDevice, int maxTextures, bool applyToVertexStage) 17 | { 18 | _graphicsDevice = graphicsDevice; 19 | _textures = new Texture[maxTextures]; 20 | _applyToVertexStage = applyToVertexStage; 21 | _dirty = int.MaxValue; 22 | PlatformInit(); 23 | } 24 | 25 | public Texture this[int index] 26 | { 27 | get 28 | { 29 | return _textures[index]; 30 | } 31 | set 32 | { 33 | if (_applyToVertexStage && !_graphicsDevice.GraphicsCapabilities.SupportsVertexTextures) 34 | throw new NotSupportedException("Vertex textures are not supported on this device."); 35 | 36 | if (_textures[index] == value) 37 | return; 38 | 39 | _textures[index] = value; 40 | _dirty |= 1 << index; 41 | } 42 | } 43 | 44 | internal void Clear() 45 | { 46 | for (var i = 0; i < _textures.Length; i++) 47 | _textures[i] = null; 48 | 49 | PlatformClear(); 50 | _dirty = int.MaxValue; 51 | } 52 | 53 | /// 54 | /// Marks all texture slots as dirty. 55 | /// 56 | internal void Dirty() 57 | { 58 | _dirty = int.MaxValue; 59 | } 60 | 61 | internal void SetTextures(GraphicsDevice device) 62 | { 63 | if (_applyToVertexStage && !device.GraphicsCapabilities.SupportsVertexTextures) 64 | return; 65 | PlatformSetTextures(device); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/IVertexType.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Xna.Framework.Graphics 2 | { 3 | public interface IVertexType 4 | { 5 | VertexDeclaration VertexDeclaration 6 | { 7 | get; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/PrimitiveType.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | /// 8 | /// Defines how vertex data is ordered. 9 | /// 10 | public enum PrimitiveType 11 | { 12 | /// 13 | /// Renders the specified vertices as a sequence of isolated triangles. Each group of three vertices defines a separate triangle. Back-face culling is affected by the current winding-order render state. 14 | /// 15 | TriangleList, 16 | 17 | /// 18 | /// Renders the vertices as a triangle strip. The back-face culling flag is flipped automatically on even-numbered triangles. 19 | /// 20 | TriangleStrip, 21 | 22 | /// 23 | /// Renders the vertices as a list of isolated straight line segments; the count may be any positive integer. 24 | /// 25 | LineList, 26 | 27 | /// 28 | /// Renders the vertices as a single polyline; the count may be any positive integer. 29 | /// 30 | LineStrip, 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/VertexBufferBinding.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework.Graphics 8 | { 9 | /// 10 | /// Defines how a vertex buffer is bound to the graphics device for rendering. 11 | /// 12 | public struct VertexBufferBinding 13 | { 14 | private readonly VertexBuffer _vertexBuffer; 15 | private readonly int _vertexOffset; 16 | private readonly int _instanceFrequency; 17 | 18 | /// 19 | /// Gets the vertex buffer. 20 | /// 21 | /// The vertex buffer. 22 | public VertexBuffer VertexBuffer 23 | { 24 | get { return _vertexBuffer; } 25 | } 26 | 27 | /// 28 | /// Gets the index of the first vertex in the vertex buffer to use. 29 | /// 30 | /// The index of the first vertex in the vertex buffer to use. 31 | public int VertexOffset 32 | { 33 | get { return _vertexOffset; } 34 | } 35 | 36 | /// 37 | /// Gets the number of instances to draw using the same per-instance data before advancing 38 | /// in the buffer by one element. 39 | /// 40 | /// 41 | /// The number of instances to draw using the same per-instance data before advancing in the 42 | /// buffer by one element. This value must be 0 for an element that contains per-vertex 43 | /// data and greater than 0 for per-instance data. 44 | /// 45 | public int InstanceFrequency 46 | { 47 | get { return _instanceFrequency; } 48 | } 49 | 50 | /// 51 | /// Creates an instance of . 52 | /// 53 | /// The vertex buffer to bind. 54 | public VertexBufferBinding(VertexBuffer vertexBuffer) 55 | : this(vertexBuffer, 0, 0) 56 | { 57 | } 58 | 59 | /// 60 | /// Creates an instance of . 61 | /// 62 | /// The vertex buffer to bind. 63 | /// 64 | /// The index of the first vertex in the vertex buffer to use. 65 | /// 66 | public VertexBufferBinding(VertexBuffer vertexBuffer, int vertexOffset) 67 | : this(vertexBuffer, vertexOffset, 0) 68 | { 69 | } 70 | 71 | /// 72 | /// Creates an instance of VertexBufferBinding. 73 | /// 74 | /// The vertex buffer to bind. 75 | /// 76 | /// The index of the first vertex in the vertex buffer to use. 77 | /// 78 | /// 79 | /// The number of instances to draw using the same per-instance data before advancing in the 80 | /// buffer by one element. This value must be 0 for an element that contains per-vertex data 81 | /// and greater than 0 for per-instance data. 82 | /// 83 | /// 84 | /// is . 85 | /// 86 | /// 87 | /// or is invalid. 88 | /// 89 | public VertexBufferBinding(VertexBuffer vertexBuffer, int vertexOffset, int instanceFrequency) 90 | { 91 | if (vertexBuffer == null) 92 | throw new ArgumentNullException("vertexBuffer"); 93 | if (vertexOffset < 0 || vertexOffset >= vertexBuffer.VertexCount) 94 | throw new ArgumentOutOfRangeException("vertexOffset"); 95 | if (instanceFrequency < 0) 96 | throw new ArgumentOutOfRangeException("instanceFrequency"); 97 | 98 | _vertexBuffer = vertexBuffer; 99 | _vertexOffset = vertexOffset; 100 | _instanceFrequency = instanceFrequency; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/VertexDeclarationCache.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Xna.Framework.Graphics 2 | { 3 | /// 4 | /// Helper class which ensures we only lookup a vertex 5 | /// declaration for a particular type once. 6 | /// 7 | /// A vertex structure which implements IVertexType. 8 | internal class VertexDeclarationCache 9 | where T : struct, IVertexType 10 | { 11 | static private VertexDeclaration _cached; 12 | 13 | static public VertexDeclaration VertexDeclaration 14 | { 15 | get 16 | { 17 | if (_cached == null) 18 | _cached = VertexDeclaration.FromType(typeof(T)); 19 | 20 | return _cached; 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/VertexElementFormat.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | /// 8 | /// Defines vertex element formats. 9 | /// 10 | public enum VertexElementFormat 11 | { 12 | /// 13 | /// Single 32-bit floating point number. 14 | /// 15 | Single, 16 | /// 17 | /// Two component 32-bit floating point number. 18 | /// 19 | Vector2, 20 | /// 21 | /// Three component 32-bit floating point number. 22 | /// 23 | Vector3, 24 | /// 25 | /// Four component 32-bit floating point number. 26 | /// 27 | Vector4, 28 | /// 29 | /// Four component, packed unsigned byte, mapped to 0 to 1 range. 30 | /// 31 | Color, 32 | /// 33 | /// Four component unsigned byte. 34 | /// 35 | Byte4, 36 | /// 37 | /// Two component signed 16-bit integer. 38 | /// 39 | Short2, 40 | /// 41 | /// Four component signed 16-bit integer. 42 | /// 43 | Short4, 44 | /// 45 | /// Normalized, two component signed 16-bit integer. 46 | /// 47 | NormalizedShort2, 48 | /// 49 | /// Normalized, four component signed 16-bit integer. 50 | /// 51 | NormalizedShort4, 52 | /// 53 | /// Two component 16-bit floating point number. 54 | /// 55 | HalfVector2, 56 | /// 57 | /// Four component 16-bit floating point number. 58 | /// 59 | HalfVector4 60 | } 61 | } -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/VertexElementUsage.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | /// 8 | /// Defines usage for vertex elements. 9 | /// 10 | public enum VertexElementUsage 11 | { 12 | /// 13 | /// Position data. 14 | /// 15 | Position, 16 | /// 17 | /// Color data. 18 | /// 19 | Color, 20 | /// 21 | /// Texture coordinate data or can be used for user-defined data. 22 | /// 23 | TextureCoordinate, 24 | /// 25 | /// Normal data. 26 | /// 27 | Normal, 28 | /// 29 | /// Binormal data. 30 | /// 31 | Binormal, 32 | /// 33 | /// Tangent data. 34 | /// 35 | Tangent, 36 | /// 37 | /// Blending indices data. 38 | /// 39 | BlendIndices, 40 | /// 41 | /// Blending weight data. 42 | /// 43 | BlendWeight, 44 | /// 45 | /// Depth data. 46 | /// 47 | Depth, 48 | /// 49 | /// Fog data. 50 | /// 51 | Fog, 52 | /// 53 | /// Point size data. Usable for drawing point sprites. 54 | /// 55 | PointSize, 56 | /// 57 | /// Sampler data for specifies the displacement value to look up. 58 | /// 59 | Sample, 60 | /// 61 | /// Single, positive float value, specifies a tessellation factor used in the tessellation unit to control the rate of tessellation. 62 | /// 63 | TessellateFactor 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/VertexPosition.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System.Runtime.Serialization; 6 | using System.Runtime.InteropServices; 7 | 8 | namespace Microsoft.Xna.Framework.Graphics 9 | { 10 | [DataContract] 11 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 12 | public struct VertexPosition : IVertexType 13 | { 14 | [DataMember] 15 | public Vector3 Position; 16 | 17 | public static readonly VertexDeclaration VertexDeclaration; 18 | 19 | public VertexPosition(Vector3 position) 20 | { 21 | Position = position; 22 | } 23 | 24 | VertexDeclaration IVertexType.VertexDeclaration 25 | { 26 | get { return VertexDeclaration; } 27 | } 28 | 29 | public override int GetHashCode() 30 | { 31 | return Position.GetHashCode(); 32 | } 33 | 34 | public override string ToString() 35 | { 36 | return "{{Position:" + Position + "}}"; 37 | } 38 | 39 | public static bool operator == (VertexPosition left, VertexPosition right) 40 | { 41 | return left.Position == right.Position; 42 | } 43 | 44 | public static bool operator != (VertexPosition left, VertexPosition right) 45 | { 46 | return !(left == right); 47 | } 48 | 49 | public override bool Equals(object obj) 50 | { 51 | if (obj == null) 52 | { 53 | return false; 54 | } 55 | if (obj.GetType() != GetType()) 56 | { 57 | return false; 58 | } 59 | return this == (VertexPosition) obj; 60 | } 61 | 62 | static VertexPosition() 63 | { 64 | VertexElement[] elements = { new VertexElement (0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0) }; 65 | VertexDeclaration declaration = new VertexDeclaration(elements); 66 | VertexDeclaration = declaration; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/VertexPositionColor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | [DataContract] 8 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 9 | public struct VertexPositionColor : IVertexType 10 | { 11 | [DataMember] 12 | public Vector3 Position; 13 | 14 | [DataMember] 15 | public Color Color; 16 | 17 | public static readonly VertexDeclaration VertexDeclaration; 18 | 19 | public VertexPositionColor(Vector3 position, Color color) 20 | { 21 | this.Position = position; 22 | Color = color; 23 | } 24 | 25 | VertexDeclaration IVertexType.VertexDeclaration 26 | { 27 | get 28 | { 29 | return VertexDeclaration; 30 | } 31 | } 32 | 33 | public override int GetHashCode() 34 | { 35 | unchecked 36 | { 37 | return (Position.GetHashCode() * 397) ^ Color.GetHashCode(); 38 | } 39 | } 40 | 41 | public override string ToString() 42 | { 43 | return "{{Position:" + this.Position + " Color:" + this.Color + "}}"; 44 | } 45 | 46 | public static bool operator == (VertexPositionColor left, VertexPositionColor right) 47 | { 48 | return ((left.Color == right.Color) && (left.Position == right.Position)); 49 | } 50 | 51 | public static bool operator != (VertexPositionColor left, VertexPositionColor right) 52 | { 53 | return !(left == right); 54 | } 55 | 56 | public override bool Equals(object obj) 57 | { 58 | if (obj == null) { 59 | return false; 60 | } 61 | if (obj.GetType () != base.GetType ()) { 62 | return false; 63 | } 64 | return (this == ((VertexPositionColor)obj)); 65 | } 66 | 67 | static VertexPositionColor() 68 | { 69 | VertexElement[] elements = new VertexElement[] { new VertexElement (0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement (12, VertexElementFormat.Color, VertexElementUsage.Color, 0) }; 70 | VertexDeclaration declaration = new VertexDeclaration (elements); 71 | VertexDeclaration = declaration; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/VertexPositionColorTexture.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace Microsoft.Xna.Framework.Graphics 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 6 | public struct VertexPositionColorTexture : IVertexType 7 | { 8 | public Vector3 Position; 9 | public Color Color; 10 | public Vector2 TextureCoordinate; 11 | public static readonly VertexDeclaration VertexDeclaration; 12 | 13 | public VertexPositionColorTexture(Vector3 position, Color color, Vector2 textureCoordinate) 14 | { 15 | Position = position; 16 | Color = color; 17 | TextureCoordinate = textureCoordinate; 18 | } 19 | 20 | VertexDeclaration IVertexType.VertexDeclaration 21 | { 22 | get 23 | { 24 | return VertexDeclaration; 25 | } 26 | } 27 | 28 | public override int GetHashCode() 29 | { 30 | unchecked 31 | { 32 | var hashCode = Position.GetHashCode(); 33 | hashCode = (hashCode * 397) ^ Color.GetHashCode(); 34 | hashCode = (hashCode * 397) ^ TextureCoordinate.GetHashCode(); 35 | return hashCode; 36 | } 37 | } 38 | 39 | public override string ToString() 40 | { 41 | return "{{Position:" + this.Position + " Color:" + this.Color + " TextureCoordinate:" + this.TextureCoordinate + "}}"; 42 | } 43 | 44 | public static bool operator ==(VertexPositionColorTexture left, VertexPositionColorTexture right) 45 | { 46 | return (((left.Position == right.Position) && (left.Color == right.Color)) && (left.TextureCoordinate == right.TextureCoordinate)); 47 | } 48 | 49 | public static bool operator !=(VertexPositionColorTexture left, VertexPositionColorTexture right) 50 | { 51 | return !(left == right); 52 | } 53 | 54 | public override bool Equals(object obj) 55 | { 56 | if (obj == null) 57 | return false; 58 | 59 | if (obj.GetType() != base.GetType()) 60 | return false; 61 | 62 | return (this == ((VertexPositionColorTexture)obj)); 63 | } 64 | 65 | static VertexPositionColorTexture() 66 | { 67 | var elements = new VertexElement[] 68 | { 69 | new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), 70 | new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0), 71 | new VertexElement(16, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) 72 | }; 73 | VertexDeclaration = new VertexDeclaration(elements); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/VertexPositionNormalTexture.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace Microsoft.Xna.Framework.Graphics 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 6 | public struct VertexPositionNormalTexture : IVertexType 7 | { 8 | public Vector3 Position; 9 | public Vector3 Normal; 10 | public Vector2 TextureCoordinate; 11 | public static readonly VertexDeclaration VertexDeclaration; 12 | public VertexPositionNormalTexture(Vector3 position, Vector3 normal, Vector2 textureCoordinate) 13 | { 14 | this.Position = position; 15 | this.Normal = normal; 16 | this.TextureCoordinate = textureCoordinate; 17 | } 18 | 19 | VertexDeclaration IVertexType.VertexDeclaration 20 | { 21 | get 22 | { 23 | return VertexDeclaration; 24 | } 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | unchecked 30 | { 31 | var hashCode = Position.GetHashCode(); 32 | hashCode = (hashCode * 397) ^ Normal.GetHashCode(); 33 | hashCode = (hashCode * 397) ^ TextureCoordinate.GetHashCode(); 34 | return hashCode; 35 | } 36 | } 37 | 38 | public override string ToString() 39 | { 40 | return "{{Position:" + this.Position + " Normal:" + this.Normal + " TextureCoordinate:" + this.TextureCoordinate + "}}"; 41 | } 42 | 43 | public static bool operator ==(VertexPositionNormalTexture left, VertexPositionNormalTexture right) 44 | { 45 | return (((left.Position == right.Position) && (left.Normal == right.Normal)) && (left.TextureCoordinate == right.TextureCoordinate)); 46 | } 47 | 48 | public static bool operator !=(VertexPositionNormalTexture left, VertexPositionNormalTexture right) 49 | { 50 | return !(left == right); 51 | } 52 | 53 | public override bool Equals(object obj) 54 | { 55 | if (obj == null) 56 | { 57 | return false; 58 | } 59 | if (obj.GetType() != base.GetType()) 60 | { 61 | return false; 62 | } 63 | return (this == ((VertexPositionNormalTexture)obj)); 64 | } 65 | 66 | static VertexPositionNormalTexture() 67 | { 68 | VertexElement[] elements = new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0), new VertexElement(0x18, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) }; 69 | VertexDeclaration declaration = new VertexDeclaration(elements); 70 | VertexDeclaration = declaration; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /MonoVision/Graphics/Vertices/VertexPositionTexture.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace Microsoft.Xna.Framework.Graphics 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack=1)] 6 | public struct VertexPositionTexture : IVertexType 7 | { 8 | public Vector3 Position; 9 | public Vector2 TextureCoordinate; 10 | public static readonly VertexDeclaration VertexDeclaration; 11 | public VertexPositionTexture(Vector3 position, Vector2 textureCoordinate) 12 | { 13 | this.Position = position; 14 | this.TextureCoordinate = textureCoordinate; 15 | } 16 | 17 | VertexDeclaration IVertexType.VertexDeclaration 18 | { 19 | get 20 | { 21 | return VertexDeclaration; 22 | } 23 | } 24 | 25 | public override int GetHashCode() 26 | { 27 | unchecked 28 | { 29 | return (Position.GetHashCode() * 397) ^ TextureCoordinate.GetHashCode(); 30 | } 31 | } 32 | 33 | public override string ToString() 34 | { 35 | return "{{Position:" + this.Position + " TextureCoordinate:" + this.TextureCoordinate + "}}"; 36 | } 37 | 38 | public static bool operator ==(VertexPositionTexture left, VertexPositionTexture right) 39 | { 40 | return ((left.Position == right.Position) && (left.TextureCoordinate == right.TextureCoordinate)); 41 | } 42 | 43 | public static bool operator !=(VertexPositionTexture left, VertexPositionTexture right) 44 | { 45 | return !(left == right); 46 | } 47 | 48 | public override bool Equals(object obj) 49 | { 50 | if (obj == null) 51 | { 52 | return false; 53 | } 54 | if (obj.GetType() != base.GetType()) 55 | { 56 | return false; 57 | } 58 | return (this == ((VertexPositionTexture)obj)); 59 | } 60 | 61 | static VertexPositionTexture() 62 | { 63 | VertexElement[] elements = new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) }; 64 | VertexDeclaration declaration = new VertexDeclaration(elements); 65 | VertexDeclaration = declaration; 66 | } 67 | 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /MonoVision/GraphicsDeviceInformation.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using Microsoft.Xna.Framework.Graphics; 6 | 7 | namespace Microsoft.Xna.Framework 8 | { 9 | /// 10 | /// The settings used in creation of the graphics device. 11 | /// See . 12 | /// 13 | public class GraphicsDeviceInformation 14 | { 15 | /// 16 | /// The graphics adapter on which the graphics device will be created. 17 | /// 18 | /// 19 | /// This is only valid on desktop systems where multiple graphics 20 | /// adapters are possible. Defaults to . 21 | /// 22 | public GraphicsAdapter Adapter { get; set; } 23 | 24 | /// 25 | /// The settings that define how graphics will be presented to the display. 26 | /// 27 | public PresentationParameters PresentationParameters { get; set; } 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /MonoVision/IGraphicsDeviceManager.cs: -------------------------------------------------------------------------------- 1 | // // MIT License - Copyright (C) The Mono.Xna Team 2 | // // This file is subject to the terms and conditions defined in 3 | // // file 'LICENSE.txt', which is part of this source code package. 4 | // 5 | // namespace Microsoft.Xna.Framework 6 | // { 7 | // /// 8 | // /// Used by the platform code to control the graphics device. 9 | // /// 10 | // public interface IGraphicsDeviceManager 11 | // { 12 | // /// 13 | // /// Called at the start of rendering a frame. 14 | // /// 15 | // /// Returns true if the frame should be rendered. 16 | // bool BeginDraw(); 17 | // 18 | // /// 19 | // /// Called to create the graphics device. 20 | // /// 21 | // /// Does nothing if the graphics device is already created. 22 | // void CreateDevice(); 23 | // 24 | // /// 25 | // /// Called after rendering to present the frame to the screen. 26 | // /// 27 | // void EndDraw(); 28 | // } 29 | // } 30 | // 31 | -------------------------------------------------------------------------------- /MonoVision/Input/ButtonState.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Input 6 | { 7 | /// 8 | /// Defines a button state for buttons of mouse, gamepad or joystick. 9 | /// 10 | public enum ButtonState 11 | { 12 | /// 13 | /// The button is released. 14 | /// 15 | Released, 16 | 17 | /// 18 | /// The button is pressed. 19 | /// 20 | Pressed 21 | } 22 | } -------------------------------------------------------------------------------- /MonoVision/Input/Buttons.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework.Input 8 | { 9 | /// 10 | /// Defines the buttons on gamepad. 11 | /// 12 | [Flags] 13 | public enum Buttons 14 | { 15 | /// 16 | /// Directional pad up. 17 | /// 18 | DPadUp = 1, 19 | 20 | /// 21 | /// Directional pad down. 22 | /// 23 | DPadDown = 2, 24 | 25 | /// 26 | /// Directional pad left. 27 | /// 28 | DPadLeft = 4, 29 | 30 | /// 31 | /// Directional pad right. 32 | /// 33 | DPadRight = 8, 34 | 35 | /// 36 | /// START button. 37 | /// 38 | Start = 16, 39 | 40 | /// 41 | /// BACK button. 42 | /// 43 | Back = 32, 44 | 45 | /// 46 | /// Left stick button (pressing the left stick). 47 | /// 48 | LeftStick = 64, 49 | 50 | /// 51 | /// Right stick button (pressing the right stick). 52 | /// 53 | RightStick = 128, 54 | 55 | /// 56 | /// Left bumper (shoulder) button. 57 | /// 58 | LeftShoulder = 256, 59 | 60 | /// 61 | /// Right bumper (shoulder) button. 62 | /// 63 | RightShoulder = 512, 64 | 65 | /// 66 | /// Big button. 67 | /// 68 | BigButton = 2048, 69 | 70 | /// 71 | /// A button. 72 | /// 73 | A = 4096, 74 | 75 | /// 76 | /// B button. 77 | /// 78 | B = 8192, 79 | 80 | /// 81 | /// X button. 82 | /// 83 | X = 16384, 84 | 85 | /// 86 | /// Y button. 87 | /// 88 | Y = 32768, 89 | 90 | /// 91 | /// Left stick is towards the left. 92 | /// 93 | LeftThumbstickLeft = 2097152, 94 | 95 | /// 96 | /// Right trigger. 97 | /// 98 | RightTrigger = 4194304, 99 | 100 | /// 101 | /// Left trigger. 102 | /// 103 | LeftTrigger = 8388608, 104 | 105 | /// 106 | /// Right stick is towards up. 107 | /// 108 | RightThumbstickUp = 16777216, 109 | 110 | /// 111 | /// Right stick is towards down. 112 | /// 113 | RightThumbstickDown = 33554432, 114 | 115 | /// 116 | /// Right stick is towards the right. 117 | /// 118 | RightThumbstickRight = 67108864, 119 | 120 | /// 121 | /// Right stick is towards the left. 122 | /// 123 | RightThumbstickLeft = 134217728, 124 | 125 | /// 126 | /// Left stick is towards up. 127 | /// 128 | LeftThumbstickUp = 268435456, 129 | 130 | /// 131 | /// Left stick is towards down. 132 | /// 133 | LeftThumbstickDown = 536870912, 134 | 135 | /// 136 | /// Left stick is towards the right. 137 | /// 138 | LeftThumbstickRight = 1073741824 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /MonoVision/Input/GamePadDeadZone.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Microsoft.Xna.Framework.Input 3 | { 4 | /// 5 | /// Specifies a type of dead zone processing to apply to Xbox 360 Controller 6 | /// analog sticks when calling GetState. 7 | /// 8 | public enum GamePadDeadZone 9 | { 10 | /// 11 | /// The values of each stick are not processed and are returned by GetState as 12 | /// "raw" values. This is best if you intend to implement your own dead zone 13 | /// processing. 14 | /// 15 | None, 16 | 17 | /// 18 | /// The X and Y positions of each stick are compared against the dead zone independently. 19 | /// This setting is the default when calling GetState. 20 | /// 21 | IndependentAxes, 22 | 23 | /// 24 | /// The combined X and Y position of each stick is compared to the dead zone. 25 | /// This provides better control than IndependentAxes when the stick is used 26 | /// as a two-dimensional control surface, such as when controlling a character's 27 | /// view in a first-person game. 28 | /// 29 | Circular 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MonoVision/Input/GamePadTriggers.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Input 6 | { 7 | /// 8 | /// A struct that countains information on the left and the right trigger buttons. 9 | /// 10 | public struct GamePadTriggers 11 | { 12 | /// 13 | /// Gets the position of the left trigger. 14 | /// 15 | /// A value from 0.0f to 1.0f representing left trigger. 16 | public float Left { get; private set; } 17 | 18 | /// 19 | /// Gets the position of the right trigger. 20 | /// 21 | /// A value from 0.0f to 1.0f representing right trigger. 22 | public float Right { get; private set; } 23 | 24 | /// 25 | /// Initializes a new instance of the struct. 26 | /// 27 | /// The position of the left trigger, the value will get clamped between 0.0f and 1.0f. 28 | /// The position of the right trigger, the value will get clamped between 0.0f and 1.0f. 29 | public GamePadTriggers(float leftTrigger, float rightTrigger) : this() 30 | { 31 | Left = MathHelper.Clamp(leftTrigger, 0f, 1f); 32 | Right = MathHelper.Clamp(rightTrigger, 0f, 1f); 33 | } 34 | 35 | /// 36 | /// Determines whether two specified instances of are equal. 37 | /// 38 | /// The first object to compare. 39 | /// The second object to compare. 40 | /// true if and are equal; otherwise, false. 41 | public static bool operator ==(GamePadTriggers left, GamePadTriggers right) 42 | { 43 | return (left.Left == right.Left) && (left.Right == right.Right); 44 | } 45 | 46 | /// 47 | /// Determines whether two specified instances of are not equal. 48 | /// 49 | /// The first object to compare. 50 | /// The second object to compare. 51 | /// true if and are not equal; otherwise, false. 52 | public static bool operator !=(GamePadTriggers left, GamePadTriggers right) 53 | { 54 | return !(left == right); 55 | } 56 | 57 | /// 58 | /// Returns a value indicating whether this instance is equal to a specified object. 59 | /// 60 | /// An object to compare to this instance. 61 | /// true if is a and has the same value as this instance; otherwise, false. 62 | public override bool Equals(object obj) 63 | { 64 | return (obj is GamePadTriggers) && (this == (GamePadTriggers)obj); 65 | } 66 | 67 | /// 68 | /// Serves as a hash function for a object. 69 | /// 70 | /// A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a 71 | /// hash table. 72 | public override int GetHashCode() 73 | { 74 | unchecked 75 | { 76 | return (Left.GetHashCode() * 397) ^ Right.GetHashCode(); 77 | } 78 | } 79 | 80 | /// 81 | /// Returns a that represents the current . 82 | /// 83 | /// A that represents the current . 84 | public override string ToString() 85 | { 86 | return "[GamePadTriggers: Left=" + Left + ", Right=" + Right + "]"; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /MonoVision/Input/GamePadType.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Input 6 | { 7 | /// 8 | /// Defines a type of gamepad. 9 | /// 10 | public enum GamePadType 11 | { 12 | /// 13 | /// Unknown. 14 | /// 15 | Unknown, 16 | 17 | /// 18 | /// GamePad is the XBOX controller. 19 | /// 20 | GamePad, 21 | 22 | /// 23 | /// GamePad is a wheel. 24 | /// 25 | Wheel, 26 | 27 | /// 28 | /// GamePad is an arcade stick. 29 | /// 30 | ArcadeStick, 31 | 32 | /// 33 | /// GamePad is a flight stick. 34 | /// 35 | FlightStick, 36 | 37 | /// 38 | /// GamePad is a dance pad. 39 | /// 40 | DancePad, 41 | 42 | /// 43 | /// GamePad is a guitar. 44 | /// 45 | Guitar, 46 | 47 | /// 48 | /// GamePad is an alternate guitar. 49 | /// 50 | AlternateGuitar, 51 | 52 | /// 53 | /// GamePad is a drum kit. 54 | /// 55 | DrumKit, 56 | 57 | /// 58 | /// GamePad is a big button pad. 59 | /// 60 | BigButtonPad = 768 61 | } 62 | } -------------------------------------------------------------------------------- /MonoVision/Input/Joystick.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Input 6 | { 7 | /// 8 | /// Allows interaction with joysticks. Unlike the number of Buttons/Axes/DPads is not limited. 9 | /// 10 | public static partial class Joystick 11 | { 12 | /// 13 | /// A default . 14 | /// 15 | private static JoystickState _defaultJoystickState = new JoystickState 16 | { 17 | IsConnected = false, 18 | Axes = new int[0], 19 | Buttons = new ButtonState[0], 20 | Hats = new JoystickHat[0] 21 | }; 22 | 23 | /// 24 | /// Gets a value indicating whether the current platform supports reading raw joystick data. 25 | /// 26 | /// true if the current platform supports reading raw joystick data; otherwise, false. 27 | public static bool IsSupported 28 | { 29 | get { return PlatformIsSupported; } 30 | } 31 | 32 | /// 33 | /// Gets a value indicating the last joystick index connected to the system. If this value is less than 0, no joysticks are connected. 34 | /// The order joysticks are connected and disconnected determines their index. 35 | /// As such, this value may be larger than 0 even if only one joystick is connected. 36 | /// 37 | /// 38 | public static int LastConnectedIndex 39 | { 40 | get { return PlatformLastConnectedIndex; } 41 | } 42 | 43 | /// 44 | /// Gets the capabilites of the joystick. 45 | /// 46 | /// Index of the joystick you want to access. 47 | /// The capabilites of the joystick. 48 | public static JoystickCapabilities GetCapabilities(int index) 49 | { 50 | return PlatformGetCapabilities(index); 51 | } 52 | 53 | /// 54 | /// Gets the current state of the joystick. 55 | /// 56 | /// Index of the joystick you want to access. 57 | /// The state of the joystick. 58 | public static JoystickState GetState(int index) 59 | { 60 | return PlatformGetState(index); 61 | } 62 | 63 | /// 64 | /// Gets the current state of the joystick by updating an existing . 65 | /// 66 | /// The to update. 67 | /// Index of the joystick you want to access. 68 | public static void GetState(ref JoystickState joystickState, int index) 69 | { 70 | PlatformGetState(ref joystickState, index); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /MonoVision/Input/KeyState.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // /* 3 | // Microsoft Public License (Ms-PL) 4 | // MonoGame - Copyright © 2009 The MonoGame Team 5 | // 6 | // All rights reserved. 7 | // 8 | // This license governs use of the accompanying software. If you use the software, you accept this license. If you do not 9 | // accept the license, do not use the software. 10 | // 11 | // 1. Definitions 12 | // The terms "reproduce, " "reproduction, " "derivative works, " and "distribution" have the same meaning here as under 13 | // U.S. copyright law. 14 | // 15 | // A "contribution" is the original software, or any additions or changes to the software. 16 | // A "contributor" is any person that distributes its contribution under this license. 17 | // "Licensed patents" are a contributor's patent claims that read directly on its contribution. 18 | // 19 | // 2. Grant of Rights 20 | // (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, 21 | // each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. 22 | // (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, 23 | // each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. 24 | // 25 | // 3. Conditions and Limitations 26 | // (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. 27 | // (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, 28 | // your patent license from such contributor to the software ends automatically. 29 | // (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution 30 | // notices that are present in the software. 31 | // (D) If you distribute any portion of the software in source code form, you may do so only under this license by including 32 | // a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object 33 | // code form, you may only do so under a license that complies with this license. 34 | // (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees 35 | // or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent 36 | // permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular 37 | // purpose and non-infringement. 38 | // */ 39 | #endregion License 40 | 41 | namespace Microsoft.Xna.Framework.Input 42 | { 43 | /// 44 | /// Identifies the state of a keyboard key. 45 | /// 46 | public enum KeyState 47 | { 48 | /// 49 | /// Key is released. 50 | /// 51 | Up, 52 | 53 | /// 54 | /// Key is pressed. 55 | /// 56 | Down, 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /MonoVision/Input/Keyboard.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework.Input 8 | { 9 | /// 10 | /// Allows getting keystrokes from keyboard. 11 | /// 12 | public static partial class Keyboard 13 | { 14 | /// 15 | /// Returns the current keyboard state. 16 | /// 17 | /// Current keyboard state. 18 | public static KeyboardState GetState() 19 | { 20 | return PlatformGetState(); 21 | } 22 | 23 | /// 24 | /// Returns the current keyboard state for a given player. 25 | /// 26 | /// Player index of the keyboard. 27 | /// Current keyboard state. 28 | [Obsolete("Use GetState() instead. In future versions this method can be removed.")] 29 | public static KeyboardState GetState(PlayerIndex playerIndex) 30 | { 31 | return PlatformGetState(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /MonoVision/Input/Mouse.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework.Input 8 | { 9 | /// 10 | /// Allows reading position and button click information from mouse. 11 | /// 12 | public static partial class Mouse 13 | { 14 | internal static GameWindow PrimaryWindow; 15 | 16 | private static readonly MouseState _defaultState = new MouseState(); 17 | 18 | /// 19 | /// Gets or sets the window handle for current mouse processing. 20 | /// 21 | public static IntPtr WindowHandle 22 | { 23 | get { return PlatformGetWindowHandle(); } 24 | set { PlatformSetWindowHandle(value); } 25 | } 26 | 27 | /// 28 | /// This API is an extension to XNA. 29 | /// Gets mouse state information that includes position and button 30 | /// presses for the provided window 31 | /// 32 | /// Current state of the mouse. 33 | public static MouseState GetState(GameWindow window) 34 | { 35 | return PlatformGetState(window); 36 | } 37 | 38 | /// 39 | /// Gets mouse state information that includes position and button presses 40 | /// for the primary window 41 | /// 42 | /// Current state of the mouse. 43 | public static MouseState GetState() 44 | { 45 | if (PrimaryWindow != null) 46 | return GetState(PrimaryWindow); 47 | 48 | return _defaultState; 49 | } 50 | 51 | /// 52 | /// Sets mouse cursor's relative position to game-window. 53 | /// 54 | /// Relative horizontal position of the cursor. 55 | /// Relative vertical position of the cursor. 56 | public static void SetPosition(int x, int y) 57 | { 58 | PlatformSetPosition(x, y); 59 | } 60 | 61 | /// 62 | /// Sets the cursor image to the specified MouseCursor. 63 | /// 64 | /// Mouse cursor to use for the cursor image. 65 | public static void SetCursor(MouseCursor cursor) 66 | { 67 | PlatformSetCursor(cursor); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /MonoVision/Input/MouseCursor.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using Microsoft.Xna.Framework.Graphics; 7 | 8 | namespace Microsoft.Xna.Framework.Input 9 | { 10 | /// 11 | /// Describes a mouse cursor. 12 | /// 13 | public partial class MouseCursor : IDisposable 14 | { 15 | /// 16 | /// Gets the default arrow cursor. 17 | /// 18 | public static MouseCursor Arrow { get; private set; } 19 | 20 | /// 21 | /// Gets the cursor that appears when the mouse is over text editing regions. 22 | /// 23 | public static MouseCursor IBeam { get; private set; } 24 | 25 | /// 26 | /// Gets the waiting cursor that appears while the application/system is busy. 27 | /// 28 | public static MouseCursor Wait { get; private set; } 29 | 30 | /// 31 | /// Gets the crosshair ("+") cursor. 32 | /// 33 | public static MouseCursor Crosshair { get; private set; } 34 | 35 | /// 36 | /// Gets the cross between Arrow and Wait cursors. 37 | /// 38 | public static MouseCursor WaitArrow { get; private set; } 39 | 40 | /// 41 | /// Gets the northwest/southeast ("\") cursor. 42 | /// 43 | public static MouseCursor SizeNWSE { get; private set; } 44 | 45 | /// 46 | /// Gets the northeast/southwest ("/") cursor. 47 | /// 48 | public static MouseCursor SizeNESW { get; private set; } 49 | 50 | /// 51 | /// Gets the horizontal west/east ("-") cursor. 52 | /// 53 | public static MouseCursor SizeWE { get; private set; } 54 | 55 | /// 56 | /// Gets the vertical north/south ("|") cursor. 57 | /// 58 | public static MouseCursor SizeNS { get; private set; } 59 | 60 | /// 61 | /// Gets the size all cursor which points in all directions. 62 | /// 63 | public static MouseCursor SizeAll { get; private set; } 64 | 65 | /// 66 | /// Gets the cursor that points that something is invalid, usually a cross. 67 | /// 68 | public static MouseCursor No { get; private set; } 69 | 70 | /// 71 | /// Gets the hand cursor, usually used for web links. 72 | /// 73 | public static MouseCursor Hand { get; private set; } 74 | 75 | /// 76 | /// Creates a mouse cursor from the specified texture. 77 | /// 78 | /// Texture to use as the cursor image. 79 | /// X cordinate of the image that will be used for mouse position. 80 | /// Y cordinate of the image that will be used for mouse position. 81 | // public static MouseCursor FromTexture2D(Texture2D texture, int originx, int originy) 82 | // { 83 | // if (texture.Format != SurfaceFormat.Color && texture.Format != SurfaceFormat.ColorSRgb) 84 | // throw new ArgumentException("Only Color or ColorSrgb textures are accepted for mouse cursors", "texture"); 85 | // 86 | // return PlatformFromTexture2D(texture, originx, originy); 87 | // } 88 | 89 | public IntPtr Handle { get; private set; } 90 | 91 | private bool _disposed; 92 | 93 | static MouseCursor() 94 | { 95 | PlatformInitalize(); 96 | } 97 | 98 | private MouseCursor(IntPtr handle) 99 | { 100 | Handle = handle; 101 | } 102 | 103 | public void Dispose() 104 | { 105 | if (_disposed) 106 | return; 107 | 108 | PlatformDispose(); 109 | _disposed = true; 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /MonoVision/MathHelper.cs: -------------------------------------------------------------------------------- 1 | // MIT License - Copyright (C) The Mono.Xna Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework 8 | { 9 | /// 10 | /// Contains commonly used precalculated values and mathematical operations. 11 | /// 12 | public static class MathHelper 13 | { 14 | 15 | /// 16 | /// Restricts a value to be within a specified range. 17 | /// 18 | /// The value to clamp. 19 | /// The minimum value. If value is less than min, min will be returned. 20 | /// The maximum value. If value is greater than max, max will be returned. 21 | /// The clamped value. 22 | public static float Clamp(float value, float min, float max) 23 | { 24 | // First we check to see if we're greater than the max 25 | value = (value > max) ? max : value; 26 | 27 | // Then we check to see if we're less than the min. 28 | value = (value < min) ? min : value; 29 | 30 | // There's no check to see if min > max. 31 | return value; 32 | } 33 | 34 | /// 35 | /// Restricts a value to be within a specified range. 36 | /// 37 | /// The value to clamp. 38 | /// The minimum value. If value is less than min, min will be returned. 39 | /// The maximum value. If value is greater than max, max will be returned. 40 | /// The clamped value. 41 | public static int Clamp(int value, int min, int max) 42 | { 43 | value = (value > max) ? max : value; 44 | value = (value < min) ? min : value; 45 | return value; 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /MonoVision/Platform/Audio/OALSoundBuffer.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using MonoGame.OpenAL; 7 | 8 | namespace Microsoft.Xna.Framework.Audio 9 | { 10 | internal class OALSoundBuffer : IDisposable 11 | { 12 | int openALDataBuffer; 13 | ALFormat openALFormat; 14 | int dataSize; 15 | bool _isDisposed; 16 | 17 | public OALSoundBuffer() 18 | { 19 | AL.GenBuffers(1, out openALDataBuffer); 20 | ALHelper.CheckError("Failed to generate OpenAL data buffer."); 21 | } 22 | 23 | ~OALSoundBuffer() 24 | { 25 | Dispose(false); 26 | } 27 | 28 | public int OpenALDataBuffer 29 | { 30 | get 31 | { 32 | return openALDataBuffer; 33 | } 34 | } 35 | 36 | public double Duration 37 | { 38 | get; 39 | set; 40 | } 41 | 42 | public void BindDataBuffer(byte[] dataBuffer, ALFormat format, int size, int sampleRate, int sampleAlignment = 0) 43 | { 44 | if ((format == ALFormat.MonoMSAdpcm || format == ALFormat.StereoMSAdpcm) && !OpenALSoundController.Instance.SupportsAdpcm) 45 | throw new InvalidOperationException("MS-ADPCM is not supported by this OpenAL driver"); 46 | if ((format == ALFormat.MonoIma4 || format == ALFormat.StereoIma4) && !OpenALSoundController.Instance.SupportsIma4) 47 | throw new InvalidOperationException("IMA/ADPCM is not supported by this OpenAL driver"); 48 | 49 | openALFormat = format; 50 | dataSize = size; 51 | int unpackedSize = 0; 52 | 53 | if (sampleAlignment > 0) 54 | { 55 | AL.Bufferi(openALDataBuffer, ALBufferi.UnpackBlockAlignmentSoft, sampleAlignment); 56 | ALHelper.CheckError("Failed to fill buffer."); 57 | } 58 | 59 | AL.BufferData(openALDataBuffer, openALFormat, dataBuffer, size, sampleRate); 60 | ALHelper.CheckError("Failed to fill buffer."); 61 | 62 | int bits, channels; 63 | Duration = -1; 64 | AL.GetBuffer(openALDataBuffer, ALGetBufferi.Bits, out bits); 65 | ALHelper.CheckError("Failed to get buffer bits"); 66 | AL.GetBuffer(openALDataBuffer, ALGetBufferi.Channels, out channels); 67 | ALHelper.CheckError("Failed to get buffer channels"); 68 | AL.GetBuffer(openALDataBuffer, ALGetBufferi.Size, out unpackedSize); 69 | ALHelper.CheckError("Failed to get buffer size"); 70 | Duration = (float)(unpackedSize / ((bits / 8) * channels)) / (float)sampleRate; 71 | } 72 | 73 | public void Dispose() 74 | { 75 | Dispose(true); 76 | GC.SuppressFinalize(this); 77 | } 78 | 79 | protected virtual void Dispose(bool disposing) 80 | { 81 | if (!_isDisposed) 82 | { 83 | if (disposing) 84 | { 85 | // Clean up managed objects 86 | } 87 | // Release unmanaged resources 88 | if (AL.IsBuffer(openALDataBuffer)) 89 | { 90 | ALHelper.CheckError("Failed to fetch buffer state."); 91 | AL.DeleteBuffers(1, ref openALDataBuffer); 92 | ALHelper.CheckError("Failed to delete buffer."); 93 | } 94 | 95 | _isDisposed = true; 96 | } 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /MonoVision/Platform/GamePlatform.Desktop.cs: -------------------------------------------------------------------------------- 1 | // // MonoGame - Copyright (C) The MonoGame Team 2 | // // This file is subject to the terms and conditions defined in 3 | // // file 'LICENSE.txt', which is part of this source code package. 4 | // 5 | // // using System; 6 | // // 7 | // // #if WINDOWS_UAP 8 | // // using Windows.UI.ViewManagement; 9 | // // #endif 10 | // 11 | // namespace Microsoft.Xna.Framework 12 | // { 13 | // partial class GamePlatform 14 | // { 15 | // internal static GamePlatform PlatformCreate(Game game) 16 | // { 17 | // // #if DESKTOPGL || ANGLE 18 | // return new SdlGamePlatform(game); 19 | // // #elif WINDOWS && DIRECTX 20 | // // return new MonoGame.Framework.WinFormsGamePlatform(game); 21 | // // #elif WINDOWS_UAP 22 | // // return new UAPGamePlatform(game); 23 | // // #endif 24 | // } 25 | // } 26 | // } 27 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/Effect/EffectResource.OpenGL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework.Graphics 6 | { 7 | internal partial class EffectResource 8 | { 9 | // const string AlphaTestEffectName = "Microsoft.Xna.Framework.Platform.Graphics.Effect.Resources.AlphaTestEffect.ogl.mgfxo"; 10 | // const string BasicEffectName = "Microsoft.Xna.Framework.Platform.Graphics.Effect.Resources.BasicEffect.ogl.mgfxo"; 11 | // const string DualTextureEffectName = "Microsoft.Xna.Framework.Platform.Graphics.Effect.Resources.DualTextureEffect.ogl.mgfxo"; 12 | // const string EnvironmentMapEffectName = "Microsoft.Xna.Framework.Platform.Graphics.Effect.Resources.EnvironmentMapEffect.ogl.mgfxo"; 13 | // const string SkinnedEffectName = "Microsoft.Xna.Framework.Platform.Graphics.Effect.Resources.SkinnedEffect.ogl.mgfxo"; 14 | const string SpriteEffectName = "Microsoft.Xna.Framework.Platform.Graphics.Effect.Resources.SpriteEffect.ogl.mgfxo"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/Effect/Resources/SpriteEffect.fx: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // SpriteEffect.fx 3 | // 4 | // Microsoft XNA Community Game Platform 5 | // Copyright (C) Microsoft Corporation. All rights reserved. 6 | //----------------------------------------------------------------------------- 7 | 8 | #include "Macros.fxh" 9 | 10 | 11 | DECLARE_TEXTURE(Texture, 0); 12 | 13 | 14 | BEGIN_CONSTANTS 15 | MATRIX_CONSTANTS 16 | 17 | float4x4 MatrixTransform _vs(c0) _cb(c0); 18 | 19 | END_CONSTANTS 20 | 21 | 22 | struct VSOutput 23 | { 24 | float4 position : SV_Position; 25 | float4 color : COLOR0; 26 | float2 texCoord : TEXCOORD0; 27 | }; 28 | 29 | VSOutput SpriteVertexShader( float4 position : POSITION0, 30 | float4 color : COLOR0, 31 | float2 texCoord : TEXCOORD0) 32 | { 33 | VSOutput output; 34 | output.position = mul(position, MatrixTransform); 35 | output.color = color; 36 | output.texCoord = texCoord; 37 | return output; 38 | } 39 | 40 | 41 | float4 SpritePixelShader(VSOutput input) : SV_Target0 42 | { 43 | return SAMPLE_TEXTURE(Texture, input.texCoord) * input.color; 44 | } 45 | 46 | TECHNIQUE( SpriteBatch, SpriteVertexShader, SpritePixelShader ); -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/Effect/Resources/SpriteEffect.ogl.mgfxo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PixelVision8/MonoVision/0032b1de6f8c48d5fe50a1af79c2f663a84ff9bc/MonoVision/Platform/Graphics/Effect/Resources/SpriteEffect.ogl.mgfxo -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/GraphicsContext.SDL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using Microsoft.Xna.Framework.Graphics; 7 | 8 | namespace MonoGame.OpenGL 9 | { 10 | internal class GraphicsContext : IGraphicsContext, IDisposable 11 | { 12 | private IntPtr _context; 13 | private IntPtr _winHandle; 14 | private bool _disposed; 15 | 16 | // public int SwapInterval 17 | // { 18 | // get 19 | // { 20 | // return Sdl.GL.GetSwapInterval(); 21 | // } 22 | // set 23 | // { 24 | // Sdl.GL.SetSwapInterval(value); 25 | // } 26 | // } 27 | 28 | public bool IsDisposed 29 | { 30 | get { return _disposed; } 31 | } 32 | 33 | public bool IsCurrent 34 | { 35 | get { return true; } 36 | } 37 | 38 | public GraphicsContext(WindowInfo info) 39 | { 40 | if (_disposed) 41 | return; 42 | 43 | SetWindowHandle(info); 44 | _context = Sdl.GL.CreateContext(_winHandle); 45 | 46 | // GL entry points must be loaded after the GL context creation, otherwise some Windows drivers will return only GL 1.3 compatible functions 47 | try 48 | { 49 | OpenGL.GL.LoadEntryPoints(); 50 | } 51 | catch (EntryPointNotFoundException) 52 | { 53 | throw new PlatformNotSupportedException( 54 | "MonoGame requires OpenGL 3.0 compatible drivers, or either ARB_framebuffer_object or EXT_framebuffer_object extensions. " + 55 | "Try updating your graphics drivers."); 56 | } 57 | } 58 | 59 | public void MakeCurrent(WindowInfo info) 60 | { 61 | if (_disposed) 62 | return; 63 | 64 | SetWindowHandle(info); 65 | Sdl.GL.MakeCurrent(_winHandle, _context); 66 | } 67 | 68 | public void SwapBuffers() 69 | { 70 | if (_disposed) 71 | return; 72 | 73 | Sdl.GL.SwapWindow(_winHandle); 74 | } 75 | 76 | public void Dispose() 77 | { 78 | if (_disposed) 79 | return; 80 | 81 | GraphicsDevice.DisposeContext(_context); 82 | _context = IntPtr.Zero; 83 | _disposed = true; 84 | } 85 | 86 | private void SetWindowHandle(WindowInfo info) 87 | { 88 | if (info == null) 89 | _winHandle = IntPtr.Zero; 90 | else 91 | _winHandle = info.Handle; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/GraphicsDevice.OpenGL.FramebufferHelper.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Diagnostics; 10 | using System.Runtime.InteropServices; 11 | using MonoGame.OpenGL; 12 | 13 | using System.Security; 14 | 15 | namespace Microsoft.Xna.Framework.Graphics 16 | { 17 | // ARB_framebuffer_object implementation 18 | partial class GraphicsDevice 19 | { 20 | internal class FramebufferHelper 21 | { 22 | private static FramebufferHelper _instance; 23 | 24 | public static FramebufferHelper Create(GraphicsDevice gd) 25 | { 26 | if (gd.GraphicsCapabilities.SupportsFramebufferObjectARB || gd.GraphicsCapabilities.SupportsFramebufferObjectEXT) 27 | { 28 | _instance = new FramebufferHelper(gd); 29 | } 30 | else 31 | { 32 | throw new PlatformNotSupportedException( 33 | "MonoGame requires either ARB_framebuffer_object or EXT_framebuffer_object." + 34 | "Try updating your graphics drivers."); 35 | } 36 | 37 | return _instance; 38 | } 39 | 40 | public bool SupportsInvalidateFramebuffer { get; private set; } 41 | 42 | public bool SupportsBlitFramebuffer { get; private set; } 43 | 44 | internal FramebufferHelper(GraphicsDevice graphicsDevice) 45 | { 46 | this.SupportsBlitFramebuffer = GL.BlitFramebuffer != null; 47 | this.SupportsInvalidateFramebuffer = GL.InvalidateFramebuffer != null; 48 | } 49 | 50 | internal virtual void BindFramebuffer(int framebuffer) 51 | { 52 | GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer); 53 | GraphicsExtensions.CheckGLError(); 54 | } 55 | 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/IGraphicsContext.OpenGL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace MonoGame.OpenGL 8 | { 9 | internal interface IGraphicsContext : IDisposable 10 | { 11 | // int SwapInterval { get; set; } 12 | bool IsDisposed { get; } 13 | void MakeCurrent(WindowInfo info); 14 | void SwapBuffers(); 15 | bool IsCurrent { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/IWindowInfo.OpenGL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | // 5 | // using System; 6 | // 7 | // namespace MonoGame.OpenGL 8 | // { 9 | // public interface IWindowInfo 10 | // { 11 | // IntPtr Handle { get; } 12 | // } 13 | // } 14 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/OpenGL.Common.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MonoGame.OpenGL 4 | { 5 | // Required to allow platforms other than iOS use the same code. 6 | // just don't include this on iOS 7 | [AttributeUsage (AttributeTargets.Delegate)] 8 | internal sealed class MonoNativeFunctionWrapper : Attribute 9 | { 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/OpenGL.SDL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Runtime.InteropServices; 7 | 8 | namespace MonoGame.OpenGL 9 | { 10 | partial class GL 11 | { 12 | static partial void LoadPlatformEntryPoints() 13 | { 14 | BoundApi = RenderApi.GL; 15 | } 16 | 17 | private static T LoadFunction(string function, bool throwIfNotFound = false) 18 | { 19 | var ret = Sdl.GL.GetProcAddress(function); 20 | 21 | if (ret == IntPtr.Zero) 22 | { 23 | if (throwIfNotFound) 24 | throw new EntryPointNotFoundException(function); 25 | 26 | return default(T); 27 | } 28 | 29 | #if NETSTANDARD 30 | return Marshal.GetDelegateForFunctionPointer(ret); 31 | #else 32 | return (T)(object)Marshal.GetDelegateForFunctionPointer(ret, typeof(T)); 33 | #endif 34 | } 35 | 36 | private static IGraphicsContext PlatformCreateContext (WindowInfo info) 37 | { 38 | return new GraphicsContext(info); 39 | } 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/SamplerStateCollection.OpenGL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | // 5 | // Author: Kenneth James Pouncey 6 | 7 | using MonoGame.OpenGL; 8 | 9 | namespace Microsoft.Xna.Framework.Graphics 10 | { 11 | public sealed partial class SamplerStateCollection 12 | { 13 | private void PlatformSetSamplerState(int index) 14 | { 15 | } 16 | 17 | private void PlatformClear() 18 | { 19 | } 20 | 21 | private void PlatformDirty() 22 | { 23 | } 24 | 25 | internal void PlatformSetSamplers(GraphicsDevice device) 26 | { 27 | for (var i = 0; i < _actualSamplers.Length; i++) 28 | { 29 | var sampler = _actualSamplers[i]; 30 | var texture = device.Textures[i]; 31 | 32 | if (sampler != null && texture != null && sampler != texture.glLastSamplerState) 33 | { 34 | // TODO: Avoid doing this redundantly (see TextureCollection.SetTextures()) 35 | // However, I suspect that rendering from the same texture with different sampling modes 36 | // is a relatively rare occurrence... 37 | GL.ActiveTexture(TextureUnit.Texture0 + i); 38 | GraphicsExtensions.CheckGLError(); 39 | 40 | // NOTE: We don't have to bind the texture here because it is already bound in 41 | // TextureCollection.SetTextures(). This, of course, assumes that SetTextures() is called 42 | // before this method is called. If that ever changes this code will misbehave. 43 | // GL.BindTexture(texture.glTarget, texture.glTexture); 44 | // GraphicsExtensions.CheckGLError(); 45 | 46 | sampler.Activate(device, texture.glTarget, texture.LevelCount > 1); 47 | texture.glLastSamplerState = sampler; 48 | } 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/Shader/ConstantBuffer.OpenGL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using MonoGame.OpenGL; 7 | 8 | namespace Microsoft.Xna.Framework.Graphics 9 | { 10 | internal partial class ConstantBuffer 11 | { 12 | private ShaderProgram _shaderProgram = null; 13 | private int _location; 14 | 15 | static ConstantBuffer _lastConstantBufferApplied = null; 16 | 17 | /// 18 | /// A hash value which can be used to compare constant buffers. 19 | /// 20 | internal int HashKey { get; private set; } 21 | 22 | private void PlatformInitialize() 23 | { 24 | var data = new byte[_parameters.Length]; 25 | for (var i = 0; i < _parameters.Length; i++) 26 | { 27 | unchecked 28 | { 29 | data[i] = (byte)(_parameters[i] | _offsets[i]); 30 | } 31 | } 32 | 33 | HashKey = MonoGame.Utilities.Hash.ComputeHash(data); 34 | } 35 | 36 | private void PlatformClear() 37 | { 38 | // Force the uniform location to be looked up again 39 | _shaderProgram = null; 40 | } 41 | 42 | public unsafe void PlatformApply(GraphicsDevice device, ShaderProgram program) 43 | { 44 | // NOTE: We assume here the program has 45 | // already been set on the device. 46 | 47 | // If the program changed then lookup the 48 | // uniform again and apply the state. 49 | if (_shaderProgram != program) 50 | { 51 | var location = program.GetUniformLocation(_name); 52 | if (location == -1) 53 | return; 54 | 55 | _shaderProgram = program; 56 | _location = location; 57 | _dirty = true; 58 | } 59 | 60 | // If the shader program is the same, the effect may still be different and have different values in the buffer 61 | if (!Object.ReferenceEquals(this, _lastConstantBufferApplied)) 62 | _dirty = true; 63 | 64 | // If the buffer content hasn't changed then we're 65 | // done... use the previously set uniform state. 66 | if (!_dirty) 67 | return; 68 | 69 | fixed (byte* bytePtr = _buffer) 70 | { 71 | // TODO: We need to know the type of buffer float/int/bool 72 | // and cast this correctly... else it doesn't work as i guess 73 | // GL is checking the type of the uniform. 74 | 75 | GL.Uniform4(_location, _buffer.Length / 16, (float*)bytePtr); 76 | GraphicsExtensions.CheckGLError(); 77 | } 78 | 79 | // Clear the dirty flag. 80 | _dirty = false; 81 | 82 | _lastConstantBufferApplied = this; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/Shader/Shader.OpenGL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.IO; 7 | using System.Diagnostics; 8 | using MonoGame.OpenGL; 9 | 10 | namespace Microsoft.Xna.Framework.Graphics 11 | { 12 | internal partial class Shader 13 | { 14 | // The shader handle. 15 | private int _shaderHandle = -1; 16 | 17 | // We keep this around for recompiling on context lost and debugging. 18 | private string _glslCode; 19 | 20 | private static int PlatformProfile() 21 | { 22 | return 0; 23 | } 24 | 25 | private void PlatformConstruct(ShaderStage stage, byte[] shaderBytecode) 26 | { 27 | _glslCode = System.Text.Encoding.ASCII.GetString(shaderBytecode); 28 | 29 | HashKey = MonoGame.Utilities.Hash.ComputeHash(shaderBytecode); 30 | } 31 | 32 | internal int GetShaderHandle() 33 | { 34 | // If the shader has already been created then return it. 35 | if (_shaderHandle != -1) 36 | return _shaderHandle; 37 | 38 | // 39 | _shaderHandle = GL.CreateShader(Stage == ShaderStage.Vertex ? ShaderType.VertexShader : ShaderType.FragmentShader); 40 | GraphicsExtensions.CheckGLError(); 41 | GL.ShaderSource(_shaderHandle, _glslCode); 42 | GraphicsExtensions.CheckGLError(); 43 | GL.CompileShader(_shaderHandle); 44 | GraphicsExtensions.CheckGLError(); 45 | int compiled = 0; 46 | GL.GetShader(_shaderHandle, ShaderParameter.CompileStatus, out compiled); 47 | GraphicsExtensions.CheckGLError(); 48 | if (compiled != (int)Bool.True) 49 | { 50 | var log = GL.GetShaderInfoLog(_shaderHandle); 51 | Debug.WriteLine(log); 52 | 53 | GraphicsDevice.DisposeShader(_shaderHandle); 54 | _shaderHandle = -1; 55 | 56 | throw new InvalidOperationException("Shader Compilation Failed"); 57 | } 58 | 59 | return _shaderHandle; 60 | } 61 | 62 | internal void GetVertexAttributeLocations(int program) 63 | { 64 | for (int i = 0; i < Attributes.Length; ++i) 65 | { 66 | Attributes[i].location = GL.GetAttribLocation(program, Attributes[i].name); 67 | GraphicsExtensions.CheckGLError(); 68 | } 69 | } 70 | 71 | internal int GetAttribLocation(VertexElementUsage usage, int index) 72 | { 73 | for (int i = 0; i < Attributes.Length; ++i) 74 | { 75 | if ((Attributes[i].usage == usage) && (Attributes[i].index == index)) 76 | return Attributes[i].location; 77 | } 78 | return -1; 79 | } 80 | 81 | internal void ApplySamplerTextureUnits(int program) 82 | { 83 | // Assign the texture unit index to the sampler uniforms. 84 | foreach (var sampler in Samplers) 85 | { 86 | var loc = GL.GetUniformLocation(program, sampler.name); 87 | GraphicsExtensions.CheckGLError(); 88 | if (loc != -1) 89 | { 90 | GL.Uniform1(loc, sampler.textureSlot); 91 | GraphicsExtensions.CheckGLError(); 92 | } 93 | } 94 | } 95 | 96 | private void PlatformGraphicsDeviceResetting() 97 | { 98 | if (_shaderHandle != -1) 99 | { 100 | GraphicsDevice.DisposeShader(_shaderHandle); 101 | _shaderHandle = -1; 102 | } 103 | } 104 | 105 | protected override void Dispose(bool disposing) 106 | { 107 | if (!IsDisposed && _shaderHandle != -1) 108 | { 109 | GraphicsDevice.DisposeShader(_shaderHandle); 110 | _shaderHandle = -1; 111 | } 112 | 113 | base.Dispose(disposing); 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/Shader/ShaderProgramCache.cs: -------------------------------------------------------------------------------- 1 | #if OPENGL 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using MonoGame.OpenGL; 6 | 7 | namespace Microsoft.Xna.Framework.Graphics 8 | { 9 | 10 | internal class ShaderProgram 11 | { 12 | public readonly int Program; 13 | 14 | private readonly Dictionary _uniformLocations = new Dictionary(); 15 | 16 | public ShaderProgram(int program) 17 | { 18 | Program = program; 19 | } 20 | 21 | public int GetUniformLocation(string name) 22 | { 23 | if (_uniformLocations.ContainsKey(name)) 24 | return _uniformLocations[name]; 25 | 26 | var location = GL.GetUniformLocation(Program, name); 27 | GraphicsExtensions.CheckGLError(); 28 | _uniformLocations[name] = location; 29 | return location; 30 | } 31 | } 32 | 33 | /// 34 | /// This class is used to Cache the links between Vertex/Pixel Shaders and Constant Buffers. 35 | /// It will be responsible for linking the programs under OpenGL if they have not been linked 36 | /// before. If an existing link exists it will be resused. 37 | /// 38 | internal class ShaderProgramCache : IDisposable 39 | { 40 | private readonly Dictionary _programCache = new Dictionary(); 41 | GraphicsDevice _graphicsDevice; 42 | bool disposed; 43 | 44 | public ShaderProgramCache(GraphicsDevice graphicsDevice) 45 | { 46 | _graphicsDevice = graphicsDevice; 47 | } 48 | 49 | ~ShaderProgramCache() 50 | { 51 | Dispose(false); 52 | } 53 | 54 | /// 55 | /// Clear the program cache releasing all shader programs. 56 | /// 57 | public void Clear() 58 | { 59 | foreach (var pair in _programCache) 60 | { 61 | _graphicsDevice.DisposeProgram(pair.Value.Program); 62 | } 63 | _programCache.Clear(); 64 | } 65 | 66 | public ShaderProgram GetProgram(Shader vertexShader, Shader pixelShader) 67 | { 68 | // TODO: We should be hashing in the mix of constant 69 | // buffers here as well. This would allow us to optimize 70 | // setting uniforms to only when a constant buffer changes. 71 | 72 | var key = vertexShader.HashKey | pixelShader.HashKey; 73 | if (!_programCache.ContainsKey(key)) 74 | { 75 | // the key does not exist so we need to link the programs 76 | _programCache.Add(key, Link(vertexShader, pixelShader)); 77 | } 78 | 79 | return _programCache[key]; 80 | } 81 | 82 | private ShaderProgram Link(Shader vertexShader, Shader pixelShader) 83 | { 84 | // NOTE: No need to worry about background threads here 85 | // as this is only called at draw time when we're in the 86 | // main drawing thread. 87 | var program = GL.CreateProgram(); 88 | GraphicsExtensions.CheckGLError(); 89 | 90 | GL.AttachShader(program, vertexShader.GetShaderHandle()); 91 | GraphicsExtensions.CheckGLError(); 92 | 93 | GL.AttachShader(program, pixelShader.GetShaderHandle()); 94 | GraphicsExtensions.CheckGLError(); 95 | 96 | //vertexShader.BindVertexAttributes(program); 97 | 98 | GL.LinkProgram(program); 99 | GraphicsExtensions.CheckGLError(); 100 | 101 | GL.UseProgram(program); 102 | GraphicsExtensions.CheckGLError(); 103 | 104 | vertexShader.GetVertexAttributeLocations(program); 105 | 106 | pixelShader.ApplySamplerTextureUnits(program); 107 | 108 | var linked = 0; 109 | 110 | GL.GetProgram(program, GetProgramParameterName.LinkStatus, out linked); 111 | GraphicsExtensions.LogGLError("VertexShaderCache.Link(), GL.GetProgram"); 112 | if (linked == (int)Bool.False) 113 | { 114 | var log = GL.GetProgramInfoLog(program); 115 | Console.WriteLine(log); 116 | GL.DetachShader(program, vertexShader.GetShaderHandle()); 117 | GL.DetachShader(program, pixelShader.GetShaderHandle()); 118 | _graphicsDevice.DisposeProgram(program); 119 | throw new InvalidOperationException("Unable to link effect program"); 120 | } 121 | 122 | return new ShaderProgram(program); 123 | } 124 | 125 | 126 | public void Dispose() 127 | { 128 | Dispose(true); 129 | GC.SuppressFinalize(this); 130 | } 131 | 132 | protected virtual void Dispose(bool disposing) 133 | { 134 | if (!disposed) 135 | { 136 | if (disposing) 137 | Clear(); 138 | disposed = true; 139 | } 140 | } 141 | } 142 | } 143 | 144 | #endif // OPENGL 145 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/States/SamplerState.OpenGL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Diagnostics; 7 | using MonoGame.OpenGL; 8 | using ExtTextureFilterAnisotropic = MonoGame.OpenGL.TextureParameterName; 9 | 10 | namespace Microsoft.Xna.Framework.Graphics 11 | { 12 | public partial class SamplerState 13 | { 14 | 15 | internal const TextureParameterName TextureParameterNameTextureMaxAnisotropy = (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt; 16 | internal const TextureParameterName TextureParameterNameTextureMaxLevel = TextureParameterName.TextureMaxLevel; 17 | 18 | internal void Activate(GraphicsDevice device, TextureTarget target, bool useMipmaps = false) 19 | { 20 | if (GraphicsDevice == null) 21 | { 22 | // We're now bound to a device... no one should 23 | // be changing the state of this object now! 24 | GraphicsDevice = device; 25 | } 26 | Debug.Assert(GraphicsDevice == device, "The state was created for a different device!"); 27 | 28 | if (GraphicsDevice.GraphicsCapabilities.SupportsTextureFilterAnisotropic) 29 | { 30 | GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, 1.0f); 31 | GraphicsExtensions.CheckGLError(); 32 | } 33 | GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)(useMipmaps ? TextureMinFilter.NearestMipmapNearest : TextureMinFilter.Nearest)); 34 | GraphicsExtensions.CheckGLError(); 35 | GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); 36 | GraphicsExtensions.CheckGLError(); 37 | 38 | } 39 | 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/Texture.OpenGL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using MonoGame.OpenGL; 6 | 7 | namespace Microsoft.Xna.Framework.Graphics 8 | { 9 | public abstract partial class Texture 10 | { 11 | internal int glTexture = -1; 12 | internal TextureTarget glTarget; 13 | internal TextureUnit glTextureUnit = TextureUnit.Texture0; 14 | internal PixelInternalFormat glInternalFormat; 15 | internal PixelFormat glFormat; 16 | internal PixelType glType; 17 | internal SamplerState glLastSamplerState; 18 | 19 | private void PlatformGraphicsDeviceResetting() 20 | { 21 | DeleteGLTexture(); 22 | glLastSamplerState = null; 23 | } 24 | 25 | protected override void Dispose(bool disposing) 26 | { 27 | if (!IsDisposed) 28 | { 29 | DeleteGLTexture(); 30 | glLastSamplerState = null; 31 | } 32 | 33 | base.Dispose(disposing); 34 | } 35 | 36 | private void DeleteGLTexture() 37 | { 38 | if (glTexture > 0) 39 | { 40 | GraphicsDevice.DisposeTexture(glTexture); 41 | } 42 | glTexture = -1; 43 | } 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/TextureCollection.OpenGL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using MonoGame.OpenGL; 6 | 7 | namespace Microsoft.Xna.Framework.Graphics 8 | { 9 | public sealed partial class TextureCollection 10 | { 11 | private TextureTarget[] _targets; 12 | 13 | void PlatformInit() 14 | { 15 | _targets = new TextureTarget[_textures.Length]; 16 | } 17 | 18 | void PlatformClear() 19 | { 20 | for (var i = 0; i < _targets.Length; i++) 21 | _targets[i] = 0; 22 | } 23 | 24 | void PlatformSetTextures(GraphicsDevice device) 25 | { 26 | // Skip out if nothing has changed. 27 | if (_dirty == 0) 28 | return; 29 | 30 | for (var i = 0; i < _textures.Length; i++) 31 | { 32 | var mask = 1 << i; 33 | if ((_dirty & mask) == 0) 34 | continue; 35 | 36 | var tex = _textures[i]; 37 | 38 | GL.ActiveTexture(TextureUnit.Texture0 + i); 39 | GraphicsExtensions.CheckGLError(); 40 | 41 | // Clear the previous binding if the 42 | // target is different from the new one. 43 | if (_targets[i] != 0 && (tex == null || _targets[i] != tex.glTarget)) 44 | { 45 | GL.BindTexture(_targets[i], 0); 46 | _targets[i] = 0; 47 | GraphicsExtensions.CheckGLError(); 48 | } 49 | 50 | if (tex != null) 51 | { 52 | _targets[i] = tex.glTarget; 53 | GL.BindTexture(tex.glTarget, tex.glTexture); 54 | GraphicsExtensions.CheckGLError(); 55 | // 56 | // unchecked 57 | // { 58 | // _graphicsDevice._graphicsMetrics._textureCount++; 59 | // } 60 | } 61 | 62 | _dirty &= ~mask; 63 | if (_dirty == 0) 64 | break; 65 | } 66 | 67 | _dirty = 0; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/Vertices/VertexDeclaration.OpenGL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | using MonoGame.OpenGL; 8 | 9 | namespace Microsoft.Xna.Framework.Graphics 10 | { 11 | public partial class VertexDeclaration 12 | { 13 | private readonly Dictionary _shaderAttributeInfo = new Dictionary(); 14 | 15 | internal VertexDeclarationAttributeInfo GetAttributeInfo(Shader shader, int programHash) 16 | { 17 | VertexDeclarationAttributeInfo attrInfo; 18 | if (_shaderAttributeInfo.TryGetValue(programHash, out attrInfo)) 19 | return attrInfo; 20 | 21 | // Get the vertex attribute info and cache it 22 | attrInfo = new VertexDeclarationAttributeInfo(GraphicsDevice.MaxVertexAttributes); 23 | 24 | foreach (var ve in InternalVertexElements) 25 | { 26 | var attributeLocation = shader.GetAttribLocation(ve.VertexElementUsage, ve.UsageIndex); 27 | // XNA appears to ignore usages it can't find a match for, so we will do the same 28 | if (attributeLocation < 0) 29 | continue; 30 | 31 | attrInfo.Elements.Add(new VertexDeclarationAttributeInfo.Element 32 | { 33 | Offset = ve.Offset, 34 | AttributeLocation = attributeLocation, 35 | NumberOfElements = ve.VertexElementFormat.OpenGLNumberOfElements(), 36 | VertexAttribPointerType = ve.VertexElementFormat.OpenGLVertexAttribPointerType(), 37 | Normalized = ve.OpenGLVertexAttribNormalized(), 38 | }); 39 | attrInfo.EnabledAttributes[attributeLocation] = true; 40 | } 41 | 42 | _shaderAttributeInfo.Add(programHash, attrInfo); 43 | return attrInfo; 44 | } 45 | 46 | 47 | internal void Apply(Shader shader, IntPtr offset, int programHash) 48 | { 49 | var attrInfo = GetAttributeInfo(shader, programHash); 50 | 51 | // Apply the vertex attribute info 52 | foreach (var element in attrInfo.Elements) 53 | { 54 | GL.VertexAttribPointer(element.AttributeLocation, 55 | element.NumberOfElements, 56 | element.VertexAttribPointerType, 57 | element.Normalized, 58 | VertexStride, 59 | (IntPtr)(offset.ToInt64() + element.Offset)); 60 | #if !(GLES || MONOMAC) 61 | if (GraphicsDevice.GraphicsCapabilities.SupportsInstancing) 62 | GL.VertexAttribDivisor(element.AttributeLocation, 0); 63 | #endif 64 | GraphicsExtensions.CheckGLError(); 65 | } 66 | GraphicsDevice.SetVertexAttributeArray(attrInfo.EnabledAttributes); 67 | GraphicsDevice._attribsDirty = true; 68 | } 69 | 70 | /// 71 | /// Vertex attribute information for a particular shader/vertex declaration combination. 72 | /// 73 | internal class VertexDeclarationAttributeInfo 74 | { 75 | internal bool[] EnabledAttributes; 76 | 77 | internal class Element 78 | { 79 | public int Offset; 80 | public int AttributeLocation; 81 | public int NumberOfElements; 82 | public VertexAttribPointerType VertexAttribPointerType; 83 | public bool Normalized; 84 | } 85 | 86 | internal List Elements; 87 | 88 | internal VertexDeclarationAttributeInfo(int maxVertexAttributes) 89 | { 90 | EnabledAttributes = new bool[maxVertexAttributes]; 91 | Elements = new List(); 92 | } 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /MonoVision/Platform/Graphics/WindowInfo.SDL.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MonoGame.OpenGL 4 | { 5 | internal class WindowInfo 6 | { 7 | public IntPtr Handle { get; private set; } 8 | 9 | public WindowInfo(IntPtr handle) 10 | { 11 | Handle = handle; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MonoVision/Platform/GraphicsDeviceManager.SDL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using Microsoft.Xna.Framework.Graphics; 6 | using MonoGame.OpenGL; 7 | 8 | namespace Microsoft.Xna.Framework 9 | { 10 | public partial class GraphicsDeviceManager 11 | { 12 | partial void PlatformInitialize(/*PresentationParameters presentationParameters*/) 13 | { 14 | var surfaceFormat = new ColorFormat(8, 8, 8, 8); 15 | 16 | // TODO Need to get this data from the Presentation Parameters 17 | Sdl.GL.SetAttribute(Sdl.GL.Attribute.RedSize, surfaceFormat.R); 18 | Sdl.GL.SetAttribute(Sdl.GL.Attribute.GreenSize, surfaceFormat.G); 19 | Sdl.GL.SetAttribute(Sdl.GL.Attribute.BlueSize, surfaceFormat.B); 20 | Sdl.GL.SetAttribute(Sdl.GL.Attribute.AlphaSize, surfaceFormat.A); 21 | Sdl.GL.SetAttribute(Sdl.GL.Attribute.DoubleBuffer, 1); 22 | Sdl.GL.SetAttribute(Sdl.GL.Attribute.ContextMajorVersion, 2); 23 | Sdl.GL.SetAttribute(Sdl.GL.Attribute.ContextMinorVersion, 1); 24 | 25 | ((SdlGameWindow)SdlGameWindow.Instance).CreateWindow(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /MonoVision/Platform/Input/InputKeyEventArgs.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using Microsoft.Xna.Framework.Input; 7 | 8 | namespace Microsoft.Xna.Framework 9 | { 10 | public struct InputKeyEventArgs 11 | { 12 | /// 13 | /// The key that was either pressed or released. 14 | /// 15 | public readonly Keys Key; 16 | 17 | /// 18 | /// Create a new keyboard input event 19 | /// 20 | /// The key involved in this event 21 | public InputKeyEventArgs(Keys key = Keys.None) 22 | { 23 | Key = key; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MonoVision/Platform/Input/Keyboard.SDL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System.Collections.Generic; 6 | 7 | namespace Microsoft.Xna.Framework.Input 8 | { 9 | public static partial class Keyboard 10 | { 11 | static List _keys; 12 | 13 | private static KeyboardState PlatformGetState() 14 | { 15 | var modifiers = Sdl.Keyboard.GetModState(); 16 | return new KeyboardState(_keys, 17 | (modifiers & Sdl.Keyboard.Keymod.CapsLock) == Sdl.Keyboard.Keymod.CapsLock, 18 | (modifiers & Sdl.Keyboard.Keymod.NumLock) == Sdl.Keyboard.Keymod.NumLock); 19 | } 20 | 21 | internal static void SetKeys(List keys) 22 | { 23 | _keys = keys; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MonoVision/Platform/Input/KeysHelper.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | 8 | namespace Microsoft.Xna.Framework.Input 9 | { 10 | internal static class KeysHelper 11 | { 12 | static HashSet _map; 13 | 14 | static KeysHelper() 15 | { 16 | _map = new HashSet(); 17 | var allKeys = (Keys[])Enum.GetValues(typeof(Keys)); 18 | foreach (var key in allKeys) 19 | { 20 | _map.Add((int)key); 21 | } 22 | } 23 | 24 | /// 25 | /// Checks if specified value is valid Key. 26 | /// 27 | /// Keys base value 28 | /// Returns true if value is valid Key, false otherwise 29 | public static bool IsKey(int value) 30 | { 31 | return _map.Contains(value); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /MonoVision/Platform/Input/Mouse.SDL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | 7 | namespace Microsoft.Xna.Framework.Input 8 | { 9 | public static partial class Mouse 10 | { 11 | internal static int ScrollX; 12 | internal static int ScrollY; 13 | 14 | private static IntPtr PlatformGetWindowHandle() 15 | { 16 | return PrimaryWindow.Handle; 17 | } 18 | 19 | private static void PlatformSetWindowHandle(IntPtr windowHandle) 20 | { 21 | } 22 | 23 | private static MouseState PlatformGetState(GameWindow window) 24 | { 25 | int x, y; 26 | var winFlags = Sdl.Window.GetWindowFlags(window.Handle); 27 | var state = Sdl.Mouse.GetGlobalState(out x, out y); 28 | 29 | if ((winFlags & Sdl.Window.State.MouseFocus) != 0) 30 | { 31 | // Window has mouse focus, position will be set from the motion event 32 | window.MouseState.LeftButton = (state & Sdl.Mouse.Button.Left) != 0 ? ButtonState.Pressed : ButtonState.Released; 33 | window.MouseState.MiddleButton = (state & Sdl.Mouse.Button.Middle) != 0 ? ButtonState.Pressed : ButtonState.Released; 34 | window.MouseState.RightButton = (state & Sdl.Mouse.Button.Right) != 0 ? ButtonState.Pressed : ButtonState.Released; 35 | window.MouseState.XButton1 = (state & Sdl.Mouse.Button.X1Mask) != 0 ? ButtonState.Pressed : ButtonState.Released; 36 | window.MouseState.XButton2 = (state & Sdl.Mouse.Button.X2Mask) != 0 ? ButtonState.Pressed : ButtonState.Released; 37 | 38 | window.MouseState.HorizontalScrollWheelValue = ScrollX; 39 | window.MouseState.ScrollWheelValue = ScrollY; 40 | } 41 | else 42 | { 43 | // Window does not have mouse focus, we need to manually get the position 44 | var clientBounds = window.ClientBounds; 45 | window.MouseState.X = x - clientBounds.X; 46 | window.MouseState.Y = y - clientBounds.Y; 47 | } 48 | 49 | return window.MouseState; 50 | } 51 | 52 | private static void PlatformSetPosition(int x, int y) 53 | { 54 | PrimaryWindow.MouseState.X = x; 55 | PrimaryWindow.MouseState.Y = y; 56 | 57 | Sdl.Mouse.WarpInWindow(PrimaryWindow.Handle, x, y); 58 | } 59 | 60 | private static void PlatformSetCursor(MouseCursor cursor) 61 | { 62 | Sdl.Mouse.SetCursor(cursor.Handle); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /MonoVision/Platform/Input/MouseCursor.SDL.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.IO; 7 | using Microsoft.Xna.Framework.Graphics; 8 | using MonoGame.Utilities; 9 | 10 | namespace Microsoft.Xna.Framework.Input 11 | { 12 | public partial class MouseCursor 13 | { 14 | private MouseCursor(Sdl.Mouse.SystemCursor cursor) 15 | { 16 | Handle = Sdl.Mouse.CreateSystemCursor(cursor); 17 | } 18 | 19 | private static void PlatformInitalize() 20 | { 21 | Arrow = new MouseCursor(Sdl.Mouse.SystemCursor.Arrow); 22 | IBeam = new MouseCursor(Sdl.Mouse.SystemCursor.IBeam); 23 | Wait = new MouseCursor(Sdl.Mouse.SystemCursor.Wait); 24 | Crosshair = new MouseCursor(Sdl.Mouse.SystemCursor.Crosshair); 25 | WaitArrow = new MouseCursor(Sdl.Mouse.SystemCursor.WaitArrow); 26 | SizeNWSE = new MouseCursor(Sdl.Mouse.SystemCursor.SizeNWSE); 27 | SizeNESW = new MouseCursor(Sdl.Mouse.SystemCursor.SizeNESW); 28 | SizeWE = new MouseCursor(Sdl.Mouse.SystemCursor.SizeWE); 29 | SizeNS = new MouseCursor(Sdl.Mouse.SystemCursor.SizeNS); 30 | SizeAll = new MouseCursor(Sdl.Mouse.SystemCursor.SizeAll); 31 | No = new MouseCursor(Sdl.Mouse.SystemCursor.No); 32 | Hand = new MouseCursor(Sdl.Mouse.SystemCursor.Hand); 33 | } 34 | 35 | private static MouseCursor PlatformFromTexture2D(Texture2D texture, int originx, int originy) 36 | { 37 | IntPtr surface = IntPtr.Zero; 38 | IntPtr handle = IntPtr.Zero; 39 | try 40 | { 41 | var bytes = new byte[texture.Width * texture.Height * 4]; 42 | texture.GetData(bytes); 43 | surface = Sdl.CreateRGBSurfaceFrom(bytes, texture.Width, texture.Height, 32, texture.Width * 4, 0x000000ff, 0x0000FF00, 0x00FF0000, 0xFF000000); 44 | if (surface == IntPtr.Zero) 45 | throw new InvalidOperationException("Failed to create surface for mouse cursor: " + Sdl.GetError()); 46 | 47 | handle = Sdl.Mouse.CreateColorCursor(surface, originx, originy); 48 | if (handle == IntPtr.Zero) 49 | throw new InvalidOperationException("Failed to set surface for mouse cursor: " + Sdl.GetError()); 50 | } 51 | finally 52 | { 53 | if (surface != IntPtr.Zero) 54 | Sdl.FreeSurface(surface); 55 | } 56 | 57 | return new MouseCursor(handle); 58 | } 59 | 60 | private void PlatformDispose() 61 | { 62 | if (Handle == IntPtr.Zero) 63 | return; 64 | 65 | Sdl.Mouse.FreeCursor(Handle); 66 | Handle = IntPtr.Zero; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /MonoVision/Platform/PrimaryThreadLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Microsoft.Xna.Framework 5 | { 6 | /// 7 | /// Interface used to add an object to be loaded on the primary thread 8 | /// 9 | interface IPrimaryThreadLoaded 10 | { 11 | bool Load(); 12 | } 13 | 14 | /// 15 | /// Static class that is called before every draw to load resources that need to finish loading on the primary thread 16 | /// 17 | internal static class PrimaryThreadLoader 18 | { 19 | private static readonly object ListLockObject = new object(); 20 | private static readonly List NeedToLoad = new List(); 21 | private static readonly List RemoveList = new List(); 22 | private static DateTime _lastUpdate = DateTime.UtcNow; 23 | 24 | public static void AddToList(IPrimaryThreadLoaded primaryThreadLoaded) 25 | { 26 | lock (ListLockObject) 27 | { 28 | NeedToLoad.Add(primaryThreadLoaded); 29 | } 30 | } 31 | 32 | public static void RemoveFromList(IPrimaryThreadLoaded primaryThreadLoaded) 33 | { 34 | lock (ListLockObject) 35 | { 36 | NeedToLoad.Remove(primaryThreadLoaded); 37 | } 38 | } 39 | 40 | public static void RemoveFromList(List primaryThreadLoadeds) 41 | { 42 | lock (ListLockObject) 43 | { 44 | foreach (var primaryThreadLoaded in primaryThreadLoadeds) 45 | { 46 | NeedToLoad.Remove(primaryThreadLoaded); 47 | } 48 | } 49 | } 50 | 51 | public static void Clear() 52 | { 53 | lock(ListLockObject) 54 | { 55 | NeedToLoad.Clear(); 56 | } 57 | } 58 | 59 | /// 60 | /// Loops through list and loads the item. If successful, it is removed from the list. 61 | /// 62 | public static void DoLoads() 63 | { 64 | if((DateTime.UtcNow - _lastUpdate).Milliseconds < 250) return; 65 | 66 | _lastUpdate = DateTime.UtcNow; 67 | lock (ListLockObject) 68 | { 69 | for (int i = 0; i < NeedToLoad.Count; i++) 70 | { 71 | var primaryThreadLoaded = NeedToLoad[i]; 72 | if (primaryThreadLoaded.Load()) 73 | { 74 | RemoveList.Add(primaryThreadLoaded); 75 | } 76 | } 77 | 78 | for (int i = 0; i < RemoveList.Count; i++) 79 | { 80 | var primaryThreadLoaded = RemoveList[i]; 81 | NeedToLoad.Remove(primaryThreadLoaded); 82 | } 83 | 84 | RemoveList.Clear(); 85 | } 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /MonoVision/Platform/Threading.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Diagnostics; 8 | using System.Threading; 9 | using Microsoft.Xna.Framework.Graphics; 10 | #if IOS 11 | using Foundation; 12 | using OpenGLES; 13 | #endif 14 | #if DESKTOPGL || ANGLE || GLES 15 | using MonoGame.OpenGL; 16 | #endif 17 | 18 | namespace Microsoft.Xna.Framework 19 | { 20 | internal class Threading 21 | { 22 | public const int kMaxWaitForUIThread = 750; // In milliseconds 23 | 24 | static int mainThreadId; 25 | 26 | #if ANDROID || WINDOWS || DESKTOPGL || ANGLE || IOS 27 | static List actions = new List(); 28 | //static Mutex actionsMutex = new Mutex(); 29 | #endif 30 | 31 | #if IOS 32 | public static EAGLContext BackgroundContext; 33 | #endif 34 | 35 | static Threading() 36 | { 37 | mainThreadId = Thread.CurrentThread.ManagedThreadId; 38 | } 39 | #if ANDROID 40 | internal static void ResetThread (int id) 41 | { 42 | mainThreadId = id; 43 | } 44 | #endif 45 | /// 46 | /// Checks if the code is currently running on the UI thread. 47 | /// 48 | /// true if the code is currently running on the UI thread. 49 | public static bool IsOnUIThread() 50 | { 51 | return mainThreadId == Thread.CurrentThread.ManagedThreadId; 52 | } 53 | 54 | /// 55 | /// Throws an exception if the code is not currently running on the UI thread. 56 | /// 57 | /// Thrown if the code is not currently running on the UI thread. 58 | public static void EnsureUIThread() 59 | { 60 | if (!IsOnUIThread()) 61 | throw new InvalidOperationException("Operation not called on UI thread."); 62 | } 63 | 64 | /// 65 | /// Runs the given action on the UI thread and blocks the current thread while the action is running. 66 | /// If the current thread is the UI thread, the action will run immediately. 67 | /// 68 | /// The action to be run on the UI thread 69 | internal static void BlockOnUIThread(Action action) 70 | { 71 | if (action == null) 72 | throw new ArgumentNullException("action"); 73 | 74 | #if DIRECTX || PSM 75 | action(); 76 | #else 77 | // If we are already on the UI thread, just call the action and be done with it 78 | if (IsOnUIThread()) 79 | { 80 | action(); 81 | return; 82 | } 83 | 84 | ManualResetEventSlim resetEvent = new ManualResetEventSlim(false); 85 | Add(() => 86 | { 87 | #if ANDROID 88 | //if (!Game.Instance.Window.GraphicsContext.IsCurrent) 89 | ((AndroidGameWindow)Game.Instance.Window).GameView.MakeCurrent(); 90 | #endif 91 | action(); 92 | resetEvent.Set(); 93 | }); 94 | resetEvent.Wait(); 95 | #endif 96 | } 97 | 98 | #if ANDROID || WINDOWS || DESKTOPGL || ANGLE || IOS 99 | static void Add(Action action) 100 | { 101 | lock (actions) 102 | { 103 | actions.Add(action); 104 | } 105 | } 106 | 107 | /// 108 | /// Runs all pending actions. Must be called from the UI thread. 109 | /// 110 | internal static void Run() 111 | { 112 | EnsureUIThread(); 113 | 114 | #if IOS 115 | lock (BackgroundContext) 116 | { 117 | // Make the context current on this thread if it is not already 118 | if (!Object.ReferenceEquals(EAGLContext.CurrentContext, BackgroundContext)) 119 | EAGLContext.SetCurrentContext(BackgroundContext); 120 | #endif 121 | 122 | lock (actions) 123 | { 124 | foreach (Action action in actions) 125 | { 126 | action(); 127 | } 128 | actions.Clear(); 129 | } 130 | 131 | #if IOS 132 | // Must flush the GL calls so the GPU asset is ready for the main context to use it 133 | GL.Flush(); 134 | GraphicsExtensions.CheckGLError(); 135 | } 136 | #endif 137 | } 138 | #endif 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /MonoVision/Platform/Utilities/AssemblyHelper.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Reflection; 7 | 8 | namespace MonoGame.Utilities 9 | { 10 | internal static class AssemblyHelper 11 | { 12 | public static string GetDefaultWindowTitle() 13 | { 14 | // Set the window title. 15 | string windowTitle = string.Empty; 16 | 17 | // When running unit tests this can return null. 18 | var assembly = Assembly.GetEntryAssembly(); 19 | if (assembly != null) 20 | { 21 | // Use the Title attribute of the Assembly if possible. 22 | try 23 | { 24 | var assemblyTitleAtt = ((AssemblyTitleAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyTitleAttribute))); 25 | if (assemblyTitleAtt != null) 26 | windowTitle = assemblyTitleAtt.Title; 27 | } 28 | catch 29 | { 30 | // Nope, wasn't possible :/ 31 | } 32 | 33 | // Otherwise, fallback to the Name of the assembly. 34 | if (string.IsNullOrEmpty(windowTitle)) 35 | windowTitle = assembly.GetName().Name; 36 | } 37 | 38 | return windowTitle; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MonoVision/Platform/Utilities/CurrentPlatform.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System.Runtime.InteropServices; 6 | using System; 7 | 8 | namespace MonoGame.Utilities 9 | { 10 | internal enum OS 11 | { 12 | Windows, 13 | Linux, 14 | MacOSX, 15 | Unknown 16 | } 17 | 18 | internal static class CurrentPlatform 19 | { 20 | private static bool _init = false; 21 | private static OS _os; 22 | 23 | [DllImport("libc")] 24 | static extern int uname(IntPtr buf); 25 | 26 | private static void Init() 27 | { 28 | if (_init) 29 | return; 30 | 31 | var pid = Environment.OSVersion.Platform; 32 | 33 | switch (pid) 34 | { 35 | case PlatformID.Win32NT: 36 | case PlatformID.Win32S: 37 | case PlatformID.Win32Windows: 38 | case PlatformID.WinCE: 39 | _os = OS.Windows; 40 | break; 41 | case PlatformID.MacOSX: 42 | _os = OS.MacOSX; 43 | break; 44 | case PlatformID.Unix: 45 | _os = OS.MacOSX; 46 | 47 | var buf = IntPtr.Zero; 48 | 49 | try 50 | { 51 | buf = Marshal.AllocHGlobal(8192); 52 | 53 | if (uname(buf) == 0 && Marshal.PtrToStringAnsi(buf) == "Linux") 54 | _os = OS.Linux; 55 | } 56 | catch 57 | { 58 | } 59 | finally 60 | { 61 | if (buf != IntPtr.Zero) 62 | Marshal.FreeHGlobal(buf); 63 | } 64 | 65 | break; 66 | default: 67 | _os = OS.Unknown; 68 | break; 69 | } 70 | 71 | _init = true; 72 | } 73 | 74 | public static OS OS 75 | { 76 | get 77 | { 78 | Init(); 79 | return _os; 80 | } 81 | } 82 | 83 | public static string Rid 84 | { 85 | get 86 | { 87 | if (CurrentPlatform.OS == OS.Windows && Environment.Is64BitProcess) 88 | return "win-x64"; 89 | else if (CurrentPlatform.OS == OS.Windows && !Environment.Is64BitProcess) 90 | return "win-x86"; 91 | else if (CurrentPlatform.OS == OS.Linux) 92 | return "linux-x64"; 93 | else if (CurrentPlatform.OS == OS.MacOSX) 94 | return "osx"; 95 | else 96 | return "unknown"; 97 | } 98 | } 99 | } 100 | } 101 | 102 | -------------------------------------------------------------------------------- /MonoVision/Platform/Utilities/FuncLoader.Desktop.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MonoGame.Utilities 6 | { 7 | internal class FuncLoader 8 | { 9 | private class Windows 10 | { 11 | [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] 12 | public static extern IntPtr GetProcAddress(IntPtr hModule, string procName); 13 | 14 | [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)] 15 | public static extern IntPtr LoadLibraryW(string lpszLib); 16 | } 17 | 18 | private class Linux 19 | { 20 | [DllImport("libdl.so.2")] 21 | public static extern IntPtr dlopen(string path, int flags); 22 | 23 | [DllImport("libdl.so.2")] 24 | public static extern IntPtr dlsym(IntPtr handle, string symbol); 25 | } 26 | 27 | private class OSX 28 | { 29 | [DllImport("/usr/lib/libSystem.dylib")] 30 | public static extern IntPtr dlopen(string path, int flags); 31 | 32 | [DllImport("/usr/lib/libSystem.dylib")] 33 | public static extern IntPtr dlsym(IntPtr handle, string symbol); 34 | } 35 | 36 | private const int RTLD_LAZY = 0x0001; 37 | 38 | public static IntPtr LoadLibraryExt(string libname) 39 | { 40 | var ret = IntPtr.Zero; 41 | 42 | // TODO this is now hardcoded to libraries/sdl/ 43 | var assemblyLocation = Path.GetDirectoryName(typeof(FuncLoader).Assembly.Location) + "/libraries/sdl/" ?? "./"; 44 | 45 | // Try .NET Framework / mono locations 46 | if (CurrentPlatform.OS == OS.MacOSX) 47 | { 48 | ret = LoadLibrary(Path.Combine(assemblyLocation, libname)); 49 | 50 | // Look in Frameworks for .app bundles 51 | if (ret == IntPtr.Zero) 52 | ret = LoadLibrary(Path.Combine(assemblyLocation, "..", "Frameworks", libname)); 53 | } 54 | else 55 | { 56 | if (Environment.Is64BitProcess) 57 | ret = LoadLibrary(Path.Combine(assemblyLocation, "x64", libname)); 58 | else 59 | ret = LoadLibrary(Path.Combine(assemblyLocation, "x86", libname)); 60 | } 61 | 62 | // Try .NET Core development locations 63 | if (ret == IntPtr.Zero) 64 | ret = LoadLibrary(Path.Combine(assemblyLocation, "sdl", CurrentPlatform.Rid, "native", libname)); 65 | 66 | // Try current folder (.NET Core will copy it there after publish) 67 | if (ret == IntPtr.Zero) 68 | ret = LoadLibrary(Path.Combine(assemblyLocation, libname)); 69 | 70 | // Try loading system library 71 | if (ret == IntPtr.Zero) 72 | ret = LoadLibrary(libname); 73 | 74 | // Welp, all failed, PANIC!!! 75 | if (ret == IntPtr.Zero) 76 | throw new Exception("Failed to load library: " + libname); 77 | 78 | return ret; 79 | } 80 | 81 | public static IntPtr LoadLibrary(string libname) 82 | { 83 | if (CurrentPlatform.OS == OS.Windows) 84 | return Windows.LoadLibraryW(libname); 85 | 86 | if (CurrentPlatform.OS == OS.MacOSX) 87 | return OSX.dlopen(libname, RTLD_LAZY); 88 | 89 | return Linux.dlopen(libname, RTLD_LAZY); 90 | } 91 | 92 | public static T LoadFunction(IntPtr library, string function, bool throwIfNotFound = false) 93 | { 94 | var ret = IntPtr.Zero; 95 | 96 | if (CurrentPlatform.OS == OS.Windows) 97 | ret = Windows.GetProcAddress(library, function); 98 | else if (CurrentPlatform.OS == OS.MacOSX) 99 | ret = OSX.dlsym(library, function); 100 | else 101 | ret = Linux.dlsym(library, function); 102 | 103 | if (ret == IntPtr.Zero) 104 | { 105 | if (throwIfNotFound) 106 | throw new EntryPointNotFoundException(function); 107 | 108 | return default(T); 109 | } 110 | 111 | #if NETSTANDARD 112 | return Marshal.GetDelegateForFunctionPointer(ret); 113 | #else 114 | return (T)(object)Marshal.GetDelegateForFunctionPointer(ret, typeof(T)); 115 | #endif 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /MonoVision/Platform/Utilities/InteropHelpers.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | 9 | namespace MonoGame.Utilities 10 | { 11 | internal static class InteropHelpers 12 | { 13 | /// 14 | /// Convert a pointer to a Utf8 null-terminated string to a .NET System.String 15 | /// 16 | public static unsafe string Utf8ToString(IntPtr handle) 17 | { 18 | if (handle == IntPtr.Zero) 19 | return string.Empty; 20 | 21 | var ptr = (byte*) handle; 22 | while (*ptr != 0) 23 | ptr++; 24 | 25 | var len = ptr - (byte*) handle; 26 | if (len == 0) 27 | return string.Empty; 28 | 29 | var bytes = new byte[len]; 30 | Marshal.Copy(handle, bytes, 0, bytes.Length); 31 | 32 | return Encoding.UTF8.GetString(bytes); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /MonoVision/Platform/Utilities/ReflectionHelpers.Default.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace MonoGame.Utilities 7 | { 8 | internal static partial class ReflectionHelpers 9 | { 10 | /// 11 | /// Generics handler for Marshal.SizeOf 12 | /// 13 | internal static class SizeOf 14 | { 15 | static int _sizeOf; 16 | 17 | static SizeOf() 18 | { 19 | _sizeOf = Marshal.SizeOf(); 20 | } 21 | 22 | static public int Get() 23 | { 24 | return _sizeOf; 25 | } 26 | } 27 | 28 | /// 29 | /// Fallback handler for Marshal.SizeOf(type) 30 | /// 31 | internal static int ManagedSizeOf(Type type) 32 | { 33 | return Marshal.SizeOf(type); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /MonoVision/PlayerIndex.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | namespace Microsoft.Xna.Framework 6 | { 7 | /// 8 | /// Defines the index of player for various MonoGame components. 9 | /// 10 | public enum PlayerIndex 11 | { 12 | /// 13 | /// The first player index. 14 | /// 15 | One = 0, 16 | /// 17 | /// The second player index. 18 | /// 19 | Two = 1, 20 | /// 21 | /// The third player index. 22 | /// 23 | Three = 2, 24 | /// 25 | /// The fourth player index. 26 | /// 27 | Four = 3 28 | } 29 | } -------------------------------------------------------------------------------- /MonoVision/TextInputEventArgs.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System; 6 | using Microsoft.Xna.Framework.Input; 7 | 8 | namespace Microsoft.Xna.Framework 9 | { 10 | /// 11 | /// This class is used for the game window's TextInput event as EventArgs. 12 | /// 13 | public struct TextInputEventArgs 14 | { 15 | public TextInputEventArgs(char character, Keys key = Keys.None) 16 | { 17 | Character = character; 18 | Key = key; 19 | } 20 | public readonly char Character; 21 | public readonly Keys Key; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MonoVision/Utilities/BinaryReaderEx.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System.IO; 6 | using System.Text; 7 | 8 | namespace Microsoft.Xna.Framework.Utilities 9 | { 10 | public class BinaryReaderEx : BinaryReader 11 | { 12 | public BinaryReaderEx(Stream input) : base(input) 13 | { 14 | } 15 | 16 | public BinaryReaderEx(Stream input, Encoding encoding) : base(input, encoding) 17 | { 18 | } 19 | 20 | public BinaryReaderEx(Stream input, Encoding encoding, bool leaveOpen) : base(input, encoding, leaveOpen) 21 | { 22 | } 23 | 24 | public new int Read7BitEncodedInt() 25 | { 26 | return base.Read7BitEncodedInt(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /MonoVision/Utilities/Hash.cs: -------------------------------------------------------------------------------- 1 | // MonoGame - Copyright (C) The MonoGame Team 2 | // This file is subject to the terms and conditions defined in 3 | // file 'LICENSE.txt', which is part of this source code package. 4 | 5 | using System.IO; 6 | 7 | namespace MonoGame.Utilities 8 | { 9 | internal static class Hash 10 | { 11 | /// 12 | /// Compute a hash from a byte array. 13 | /// 14 | /// 15 | /// Modified FNV Hash in C# 16 | /// http://stackoverflow.com/a/468084 17 | /// 18 | internal static int ComputeHash(params byte[] data) 19 | { 20 | unchecked 21 | { 22 | const int p = 16777619; 23 | var hash = (int)2166136261; 24 | 25 | for (var i = 0; i < data.Length; i++) 26 | hash = (hash ^ data[i]) * p; 27 | 28 | hash += hash << 13; 29 | hash ^= hash >> 7; 30 | hash += hash << 3; 31 | hash ^= hash >> 17; 32 | hash += hash << 5; 33 | return hash; 34 | } 35 | } 36 | 37 | /// 38 | /// Compute a hash from the content of a stream and restore the position. 39 | /// 40 | /// 41 | /// Modified FNV Hash in C# 42 | /// http://stackoverflow.com/a/468084 43 | /// 44 | internal static int ComputeHash(Stream stream) 45 | { 46 | System.Diagnostics.Debug.Assert(stream.CanSeek); 47 | 48 | unchecked 49 | { 50 | const int p = 16777619; 51 | var hash = (int)2166136261; 52 | 53 | var prevPosition = stream.Position; 54 | stream.Position = 0; 55 | 56 | var data = new byte[1024]; 57 | int length; 58 | while((length = stream.Read(data, 0, data.Length)) != 0) 59 | { 60 | for (var i = 0; i < length; i++) 61 | hash = (hash ^ data[i]) * p; 62 | } 63 | 64 | // Restore stream position. 65 | stream.Position = prevPosition; 66 | 67 | hash += hash << 13; 68 | hash ^= hash >> 7; 69 | hash += hash << 3; 70 | hash ^= hash >> 17; 71 | hash += hash << 5; 72 | return hash; 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /PixelVision8.MonoVision.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | OPENGL;OPENAL;XNADESIGNPROVIDED;LINUX;DESKTOPGL;SUPPORTS_EFX;NETSTANDARD;STBSHARP_INTERNAL 5 | net5.0 6 | true 7 | PixelVision8.MonoVision 8 | PixelVision8.MonoVision 9 | 0.1.0-alpha 10 | Jesse Freeman 11 | Pixel Vision 8 12 | true 13 | MS-PL 14 | 15 | 16 | 17 | 18 | 19 | sdl\win-x64\soft_oal.dll 20 | sdl\win-x64\native 21 | PreserveNewest 22 | 23 | 24 | sdl\win-x64\SDL2.dll 25 | sdl\win-x64\native 26 | PreserveNewest 27 | 28 | 29 | sdl\linux-x64\libopenal.so.1 30 | sdl\linux-x64\native 31 | PreserveNewest 32 | 33 | 34 | sdl\linux-x64\libSDL2-2.0.so.0 35 | sdl\linux-x64\native 36 | PreserveNewest 37 | 38 | 39 | sdl\osx\libopenal.1.dylib 40 | sdl\osx\native 41 | PreserveNewest 42 | 43 | 44 | sdl\osx\libSDL2-2.0.0.dylib 45 | sdl\osx\native 46 | PreserveNewest 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pixel Vision 8: MonoVision 2 | 3 | MonoVision is a stripped down version of ([MonoGame](https://github.com/MonoGame/MonoGame)) designed specifically for Pixel Vision 8. It is optimized to run 2D games and removes a lot of the overhead of the MonoGame Framework in favor of stripping the game engine down to its SDL2 code. Currently, MonoVision runs on desktops (Win, Mac, and Linux). 4 | 5 | ### Credits 6 | 7 | Pixel Vision 8 and MonoVision were created by Jesse Freeman ([@jessefreeman](http://twitter.com/jessefreeman)) in collaboration with Christina-Antoinette Neofotistou ([@CastPixel](http://twitter.com/CastPixel)) for art and Christer Kaitila ([@McFunkypants](http://twitter.com/McFunkypants)) for music. 8 | 9 | MonoGame was created by its own contributors. 10 | 11 | ### License 12 | 13 | Licensed under the [Microsoft Public License (MS-PL) License](https://opensource.org/licenses/MS-PL). See LICENSE file in the project root for full license information. 14 | 15 | Pixel Vision 8 is Copyright (c) 2021 Jesse Freeman. All rights reserved. --------------------------------------------------------------------------------