Permalink
Browse files

Initial Windows OS support using OpenGL

XNA 4: Added IVertexType, VertextPositionColorTexture


git-svn-id: https://xnatouch.svn.codeplex.com/svn@59043 ffd33b8c-2492-42e0-bdc5-587b920b7d6d
  • Loading branch information...
1 parent c3bd4bf commit 6b60793b3e2a8bfa1fb049e1d8853acb2d95b9cc SND\taskbit_cp committed Mar 10, 2011
Showing with 4,730 additions and 0 deletions.
  1. +12 −0 MonoGame.Framework/Graphics/IVertexType.cs
  2. +41 −0 MonoGame.Framework/Graphics/VertexPositionColorTexture.cs
  3. +208 −0 MonoGame.Framework/MonoGame.Framework.Windows.csproj
  4. +220 −0 MonoGame.Framework/Windows/Content/ContentManager.cs
  5. +69 −0 MonoGame.Framework/Windows/Content/ContentReaders/SongReader.cs
  6. +74 −0 MonoGame.Framework/Windows/Content/ContentReaders/SoundEffectReader.cs
  7. +85 −0 MonoGame.Framework/Windows/Content/ContentReaders/SpriteFontReader.cs
  8. +114 −0 MonoGame.Framework/Windows/Content/ContentReaders/Texture2DReader.cs
  9. +431 −0 MonoGame.Framework/Windows/Game.cs
  10. +69 −0 MonoGame.Framework/Windows/Graphics/DisplayMode.cs
  11. +219 −0 MonoGame.Framework/Windows/Graphics/ESImage.cs
  12. +326 −0 MonoGame.Framework/Windows/Graphics/ESTexture2D.cs
  13. +193 −0 MonoGame.Framework/Windows/Graphics/Effect.cs
  14. +350 −0 MonoGame.Framework/Windows/Graphics/GraphicsDevice.cs
  15. +290 −0 MonoGame.Framework/Windows/Graphics/GraphicsDevice2D.cs
  16. +256 −0 MonoGame.Framework/Windows/Graphics/GraphicsDeviceManager.cs
  17. +236 −0 MonoGame.Framework/Windows/Graphics/PresentationParameters.cs
  18. +103 −0 MonoGame.Framework/Windows/Graphics/RenderState.cs
  19. +137 −0 MonoGame.Framework/Windows/Graphics/RenderTarget2D.cs
  20. +669 −0 MonoGame.Framework/Windows/Graphics/SpriteBatch.cs
  21. +196 −0 MonoGame.Framework/Windows/Graphics/SpriteBatcher.cs
  22. +250 −0 MonoGame.Framework/Windows/Graphics/Texture2D.cs
  23. +182 −0 MonoGame.Framework/Windows/WindowsGameWindow.cs
View
12 MonoGame.Framework/Graphics/IVertexType.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ public interface IVertexType
+ {
+ VertexDeclaration VertexDeclaration { get; }
+ }
+}
View
41 MonoGame.Framework/Graphics/VertexPositionColorTexture.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ [SerializableAttribute]
+ public struct VertexPositionColorTexture : IVertexType
+ {
+ public static readonly VertexDeclaration VertexDeclaration;
+
+ public Color Color;
+ public Vector3 Position;
+ public Vector2 TextureCoordinate;
+
+ public VertexPositionColorTexture(Vector3 position, Color color, Vector2 textureCoordinate)
+ {
+ Color = color;
+ Position = position;
+ TextureCoordinate = textureCoordinate;
+ }
+
+ public static bool operator !=(VertexPositionColorTexture left, VertexPositionColorTexture right)
+ {
+ return !(left == right);
+ }
+
+ public static bool operator ==(VertexPositionColorTexture left, VertexPositionColorTexture right)
+ {
+ return left.Color == right.Color && left.Position == right.Position &&
+ left.TextureCoordinate == right.TextureCoordinate;
+ }
+
+
+ VertexDeclaration IVertexType.VertexDeclaration
+ {
+ get { return VertexDeclaration; }
+ }
+ }
+}
View
208 MonoGame.Framework/MonoGame.Framework.Windows.csproj
@@ -0,0 +1,208 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{7DE47032-A904-4C29-BD22-2D235E8D91BA}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>MonoGame.Framework.Windows</RootNamespace>
+ <AssemblyName>MonoGame.Framework.Windows</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup>
+ <StartupObject />
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="OpenTK, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\..\OpenTK\1.0\Binaries\OpenTK\Release\OpenTK.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Drawing" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="GameWindow.cs" />
+ <Compile Include="Graphics\IVertexType.cs" />
+ <Compile Include="Graphics\RenderTarget.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="Graphics\VertexPositionColorTexture.cs" />
+ <Compile Include="Windows\Content\ContentManager.cs" />
+ <Compile Include="Windows\Content\ContentReaders\SongReader.cs" />
+ <Compile Include="Windows\Content\ContentReaders\SoundEffectReader.cs" />
+ <Compile Include="Windows\Content\ContentReaders\SpriteFontReader.cs" />
+ <Compile Include="Windows\Content\ContentReaders\Texture2DReader.cs" />
+ <Compile Include="Windows\Graphics\DisplayMode.cs" />
+ <Compile Include="Windows\Graphics\Effect.cs" />
+ <Compile Include="Windows\Graphics\ESImage.cs" />
+ <Compile Include="Windows\Graphics\ESTexture2D.cs" />
+ <Compile Include="Windows\Graphics\GraphicsDevice.cs" />
+ <Compile Include="Windows\Graphics\GraphicsDevice2D.cs" />
+ <Compile Include="Windows\Graphics\GraphicsDeviceManager.cs" />
+ <Compile Include="Windows\Graphics\PresentationParameters.cs" />
+ <Compile Include="Windows\Graphics\RenderState.cs" />
+ <Compile Include="Windows\Graphics\RenderTarget2D.cs" />
+ <Compile Include="Windows\Graphics\SpriteBatch.cs" />
+ <Compile Include="Windows\Graphics\SpriteBatcher.cs" />
+ <Compile Include="Windows\Graphics\Texture2D.cs" />
+ <Compile Include="Windows\WindowsGameWindow.cs" />
+ <Compile Include="Windows\Game.cs" />
+ <Compile Include="BatteryChargeStatus.cs" />
+ <Compile Include="BoundingBox.cs" />
+ <Compile Include="BoundingFrustum.cs" />
+ <Compile Include="BoundingSphere.cs" />
+ <Compile Include="ContainmentType.cs" />
+ <Compile Include="Curve.cs" />
+ <Compile Include="CurveContinuity.cs" />
+ <Compile Include="CurveKey.cs" />
+ <Compile Include="CurveKeyCollection.cs" />
+ <Compile Include="CurveLoopType.cs" />
+ <Compile Include="CurveTangent.cs" />
+ <Compile Include="DisplayOrientation.cs" />
+ <Compile Include="DrawableGameComponent.cs" />
+ <Compile Include="GameComponent.cs" />
+ <Compile Include="GameComponentCollection.cs" />
+ <Compile Include="GameComponentCollectionEventArgs.cs" />
+ <Compile Include="GameServiceContainer.cs" />
+ <Compile Include="GameTime.cs" />
+ <Compile Include="GraphicsDeviceInformation.cs" />
+ <Compile Include="Graphics\Texture.cs" />
+ <Compile Include="IDrawable.cs" />
+ <Compile Include="IGameComponent.cs" />
+ <Compile Include="IGraphicsDeviceManager.cs" />
+ <Compile Include="Input\ButtonDefinition.cs" />
+ <Compile Include="Input\Buttons.cs" />
+ <Compile Include="Input\ButtonState.cs" />
+ <Compile Include="Input\GamePadButtons.cs" />
+ <Compile Include="Input\GamePadCapabilities.cs" />
+ <Compile Include="Input\GamePadDPad.cs" />
+ <Compile Include="Input\GamePadState.cs" />
+ <Compile Include="Input\GamePadThumbSticks.cs" />
+ <Compile Include="Input\GamePadTriggers.cs" />
+ <Compile Include="Input\Keyboard.cs" />
+ <Compile Include="Input\KeyboardState.cs" />
+ <Compile Include="Input\Keys.cs" />
+ <Compile Include="Input\KeyState.cs" />
+ <Compile Include="Input\Mouse.cs" />
+ <Compile Include="Input\MouseState.cs" />
+ <Compile Include="Input\ThumbStickDefinition.cs" />
+ <Compile Include="IUpdateable.cs" />
+ <Compile Include="MathHelper.cs" />
+ <Compile Include="Matrix.cs" />
+ <Compile Include="PerformanceCounter.cs" />
+ <Compile Include="Plane.cs" />
+ <Compile Include="PlaneIntersectionType.cs" />
+ <Compile Include="PlayerIndex.cs" />
+ <Compile Include="Point.cs" />
+ <Compile Include="PowerLineStatus.cs" />
+ <Compile Include="PreparingDeviceSettingsEventArgs.cs" />
+ <Compile Include="Quaternion.cs" />
+ <Compile Include="Ray.cs" />
+ <Compile Include="Rectangle.cs" />
+ <Compile Include="ReusableItemList.cs" />
+ <Compile Include="Vector2.cs" />
+ <Compile Include="Vector3.cs" />
+ <Compile Include="Vector4.cs" />
+ <Compile Include="Content\ContentLoadException.cs" />
+ <Compile Include="Content\ContentReader.cs" />
+ <Compile Include="Content\ContentTypeReader.cs" />
+ <Compile Include="Content\ContentTypeReaderManager.cs" />
+ <Compile Include="Content\ContentReaders\CharReader.cs" />
+ <Compile Include="Content\ContentReaders\ListReader.cs" />
+ <Compile Include="Content\ContentReaders\RectangleReader.cs" />
+ <Compile Include="Content\ContentReaders\StringReader.cs" />
+ <Compile Include="Content\ContentReaders\Vector3Reader.cs" />
+ <Compile Include="Graphics\BasicEffect.cs" />
+ <Compile Include="Graphics\BatchItem.cs" />
+ <Compile Include="Graphics\Blend.cs" />
+ <Compile Include="Graphics\BlendFunction.cs" />
+ <Compile Include="Graphics\BlendState.cs" />
+ <Compile Include="Graphics\ClearOptions.cs" />
+ <Compile Include="Graphics\Color.cs" />
+ <Compile Include="Graphics\CompilerOptions.cs" />
+ <Compile Include="Graphics\DepthFormat.cs" />
+ <Compile Include="Graphics\DepthStencilState.cs" />
+ <Compile Include="Graphics\DeviceType.cs" />
+ <Compile Include="Graphics\EffectPool.cs" />
+ <Compile Include="Graphics\EffectTechnique.cs" />
+ <Compile Include="Graphics\GraphicsAdapter.cs" />
+ <Compile Include="Graphics\GraphicsDeviceCapabilities.cs" />
+ <Compile Include="Graphics\GraphicsDeviceInformation.cs" />
+ <Compile Include="Graphics\GraphicsDeviceStatus.cs" />
+ <Compile Include="Graphics\GraphicsProfile.cs" />
+ <Compile Include="Graphics\GraphicsResource.cs" />
+ <Compile Include="Graphics\IGraphicsDeviceService.cs" />
+ <Compile Include="Graphics\MultiSampleType.cs" />
+ <Compile Include="Graphics\PrimitiveType.cs" />
+ <Compile Include="Graphics\RasterizerState.cs" />
+ <Compile Include="Graphics\RenderTargetUsage.cs" />
+ <Compile Include="Graphics\ResolveTexture2D.cs" />
+ <Compile Include="Graphics\ResourceType.cs" />
+ <Compile Include="Graphics\SamplerState.cs" />
+ <Compile Include="Graphics\SaveStateMode.cs" />
+ <Compile Include="Graphics\SetDataOptions.cs" />
+ <Compile Include="Graphics\SpriteBatchItem.cs" />
+ <Compile Include="Graphics\SpriteBlendMode.cs" />
+ <Compile Include="Graphics\SpriteEffects.cs" />
+ <Compile Include="Graphics\SpriteFont.cs" />
+ <Compile Include="Graphics\SpriteSortMode.cs" />
+ <Compile Include="Graphics\SurfaceFormat.cs" />
+ <Compile Include="Graphics\SwapEffect.cs" />
+ <Compile Include="Graphics\TextureUsage.cs" />
+ <Compile Include="Graphics\VertexColorTexture.cs" />
+ <Compile Include="Graphics\VertexDeclaration.cs" />
+ <Compile Include="Graphics\VertexElement.cs" />
+ <Compile Include="Graphics\VertexPosition2ColorTexture.cs" />
+ <Compile Include="Graphics\VertexPositionColor.cs" />
+ <Compile Include="Graphics\Viewport.cs" />
+ <Compile Include="Input\Touch\GestureSample.cs" />
+ <Compile Include="Input\Touch\GestureType.cs" />
+ <Compile Include="Input\Touch\TouchCollection.cs" />
+ <Compile Include="Input\Touch\TouchLocation.cs" />
+ <Compile Include="Input\Touch\TouchLocationState.cs" />
+ <Compile Include="Input\Touch\TouchPanel.cs" />
+ <Compile Include="Input\Touch\TouchPanelCapabilities.cs" />
+ <Compile Include="Storage\StorageContainer.cs" />
+ <Compile Include="Storage\StorageDevice.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="GamerServices\" />
+ <Folder Include="Net\" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
220 MonoGame.Framework/Windows/Content/ContentManager.cs
@@ -0,0 +1,220 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+using System.Drawing;
+using System.IO;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Text;
+using Microsoft.Xna.Framework.Graphics;
+using Path = System.IO.Path;
+
+
+namespace Microsoft.Xna.Framework.Content
+{
+ public class ContentManager : IDisposable
+ {
+ private string _rootDirectory = string.Empty;
+ private IServiceProvider serviceProvider;
+ private IGraphicsDeviceService graphicsDeviceService;
+
+ public ContentManager(IServiceProvider serviceProvider)
+ {
+ if (serviceProvider == null)
+ {
+ throw new ArgumentNullException("serviceProvider");
+ }
+ this.serviceProvider = serviceProvider;
+ }
+
+ public ContentManager(IServiceProvider serviceProvider, string rootDirectory)
+ {
+ if (serviceProvider == null)
+ {
+ throw new ArgumentNullException("serviceProvider");
+ }
+ if (rootDirectory == null)
+ {
+ throw new ArgumentNullException("rootDirectory");
+ }
+ this.RootDirectory = rootDirectory;
+ this.serviceProvider = serviceProvider;
+ }
+
+ public void Dispose()
+ {
+ }
+
+ public T Load<T>(string assetName)
+ {
+ string originalAssetName = assetName;
+ object result = null;
+
+ if (this.graphicsDeviceService == null)
+ {
+ this.graphicsDeviceService = serviceProvider.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
+ if (this.graphicsDeviceService == null)
+ {
+ throw new InvalidOperationException("No Graphics Device Service");
+ }
+ }
+
+ // Check for windows-style directory separator character
+ //Lowercase assetName (monodroid specification all assests are lowercase)
+ assetName = Path.Combine(_rootDirectory, assetName.Replace('\\', Path.DirectorySeparatorChar)).ToLower();
+
+ // Get the real file name
+ if ((typeof(T) == typeof(Texture2D)))
+ {
+ assetName = Texture2DReader.Normalize(assetName);
+ }
+ else if ((typeof(T) == typeof(SpriteFont)))
+ {
+ assetName = SpriteFontReader.Normalize(assetName);
+ }
+ else if ((typeof(T) == typeof(Effect)))
+ {
+ assetName = Effect.Normalize(assetName);
+ }
+ /*else if ((typeof(T) == typeof(Song)))
+ {
+ assetName = SongReader.Normalize(assetName);
+ }
+ else if ((typeof(T) == typeof(SoundEffect)))
+ {
+ assetName = SoundEffectReader.Normalize(assetName);
+ }
+ else if ((typeof(T) == typeof(Video)))
+ {
+ assetName = Video.Normalize(assetName);
+ }*/
+ else {
+ throw new NotSupportedException("Format not supported");
+ }
+
+ if (string.IsNullOrEmpty(assetName))
+ {
+ throw new ContentLoadException("Could not load " + originalAssetName + " asset!");
+ }
+
+ if (Path.GetExtension(assetName).ToUpper() !=".XNB")
+ {
+ if ((typeof(T) == typeof(Texture2D))) {
+ //Basically the same as Texture2D.FromFile but loading from the assets instead of a filePath
+ Stream assetStream = File.Open(assetName, FileMode.Open, FileAccess.Read);
+ Bitmap image = (Bitmap)Bitmap.FromStream(assetStream);
+ ESImage theTexture = new ESImage(image, graphicsDeviceService.GraphicsDevice.PreferedFilter);
+ result = new Texture2D(theTexture) { Name = Path.GetFileNameWithoutExtension(assetName) };
+ }
+ if ((typeof(T) == typeof(SpriteFont)))
+ {
+ //result = new SpriteFont(Texture2D.FromFile(graphicsDeviceService.GraphicsDevice,assetName), null, null, null, 0, 0.0f, null, null);
+ throw new NotImplementedException();
+ }
+
+ /*if ((typeof(T) == typeof(Song)))
+ result = new Song(assetName);
+ if ((typeof(T) == typeof(SoundEffect)))
+ result = new SoundEffect(assetName);
+ if ((typeof(T) == typeof(Video)))
+ result = new Video(assetName);*/
+
+ }
+ else
+ {
+ // Load a XNB file
+ //Loads from Assets directory + /assetName
+ Stream assetStream = File.Open(assetName, FileMode.Open, FileAccess.Read);
+
+ ContentReader reader = new ContentReader(this, assetStream, this.graphicsDeviceService.GraphicsDevice);
+ ContentTypeReaderManager typeManager = new ContentTypeReaderManager(reader);
+ reader.TypeReaders = typeManager.LoadAssetReaders(reader);
+ foreach (ContentTypeReader r in reader.TypeReaders)
+ {
+ r.Initialize(typeManager);
+ }
+ // we need to read a byte here for things to work out, not sure why
+ reader.ReadByte();
+
+ // Get the 1-based index of the typereader we should use to start decoding with
+ int index = reader.ReadByte();
+ ContentTypeReader contentReader = reader.TypeReaders[index - 1];
+ result = reader.ReadObject<T>(contentReader);
+
+ reader.Close();
+ assetStream.Close();
+ }
+
+ if (result == null)
+ {
+ throw new ContentLoadException("Could not load " + originalAssetName + " asset!");
+ }
+
+ return (T) result;
+ }
+
+
+ public virtual void Unload()
+ {
+ }
+
+ public string RootDirectory
+ {
+ get
+ {
+ return _rootDirectory;
+ }
+ set
+ {
+ _rootDirectory = value;
+ }
+ }
+
+ public IServiceProvider ServiceProvider
+ {
+ get
+ {
+ return this.serviceProvider;
+ }
+ }
+ }
+}
+
View
69 MonoGame.Framework/Windows/Content/ContentReaders/SongReader.cs
@@ -0,0 +1,69 @@
+// #region License
+// /*
+// Microsoft Public License (Ms-PL)
+// MonoGame - Copyright © 2009 The MonoGame Team
+//
+// All rights reserved.
+//
+// This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+// accept the license, do not use the software.
+//
+// 1. Definitions
+// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+// U.S. copyright law.
+//
+// A "contribution" is the original software, or any additions or changes to the software.
+// A "contributor" is any person that distributes its contribution under this license.
+// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
+//
+// 2. Grant of Rights
+// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+// 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.
+// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+// 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.
+//
+// 3. Conditions and Limitations
+// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+// your patent license from such contributor to the software ends automatically.
+// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+// notices that are present in the software.
+// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+// code form, you may only do so under a license that complies with this license.
+// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+// permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+// purpose and non-infringement.
+// */
+// #endregion License
+//
+
+using System;
+using System.IO;
+using System.Linq;
+
+namespace Microsoft.Xna.Framework
+{
+ internal class SongReader
+ {
+ public static string Normalize(string FileName)
+ {
+ if (File.Exists(FileName))
+ return FileName;
+
+ // Check the file extension
+ if (!string.IsNullOrEmpty(Path.GetExtension(FileName)))
+ {
+ return null;
+ }
+
+ // Concat the file name with valid extensions
+ if (File.Exists(FileName + ".mp3"))
+ return FileName + ".mp3";
+
+ return null;
+ }
+
+ }
+}
View
74 MonoGame.Framework/Windows/Content/ContentReaders/SoundEffectReader.cs
@@ -0,0 +1,74 @@
+// #region License
+// /*
+// Microsoft Public License (Ms-PL)
+// MonoGame - Copyright © 2009 The MonoGame Team
+//
+// All rights reserved.
+//
+// This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+// accept the license, do not use the software.
+//
+// 1. Definitions
+// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+// U.S. copyright law.
+//
+// A "contribution" is the original software, or any additions or changes to the software.
+// A "contributor" is any person that distributes its contribution under this license.
+// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
+//
+// 2. Grant of Rights
+// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+// 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.
+// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+// 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.
+//
+// 3. Conditions and Limitations
+// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+// your patent license from such contributor to the software ends automatically.
+// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+// notices that are present in the software.
+// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+// code form, you may only do so under a license that complies with this license.
+// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+// permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+// purpose and non-infringement.
+// */
+// #endregion License
+//
+
+using System;
+using System.IO;
+using System.Linq;
+
+namespace Microsoft.Xna.Framework
+{
+ internal class SoundEffectReader
+ {
+ public static string Normalize(string FileName)
+ {
+ if (File.Exists(FileName))
+ return FileName;
+
+ // Check the file extension
+ if (!string.IsNullOrEmpty(Path.GetExtension(FileName)))
+ {
+ return null;
+ }
+
+ // Concat the file name with valid extensions
+ if (File.Exists(FileName + ".aiff"))
+ return FileName + ".aiff";
+ if (File.Exists(FileName + ".wav"))
+ return FileName + ".wav";
+ if (File.Exists(FileName + ".ac3"))
+ return FileName + ".ac3";
+ if (File.Exists(FileName + ".mp3"))
+ return FileName + ".mp3";
+
+ return null;
+ }
+ }
+}
View
85 MonoGame.Framework/Windows/Content/ContentReaders/SpriteFontReader.cs
@@ -0,0 +1,85 @@
+#region License
+/*
+MIT License
+Copyright © 2006 The Mono.Xna Team
+
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+#endregion License
+
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+using System.IO;
+
+namespace Microsoft.Xna.Framework.Content
+{
+ internal class SpriteFontReader : ContentTypeReader<SpriteFont>
+ {
+ internal SpriteFontReader()
+ {
+ }
+
+ public static string Normalize(string FileName)
+ {
+ if (File.Exists(FileName))
+ return FileName;
+
+ // Check the file extension
+ if (!string.IsNullOrEmpty(Path.GetExtension(FileName)))
+ {
+ return null;
+ }
+
+ // Concat the file name with valid extensions
+ if (File.Exists(FileName + ".xnb"))
+ return FileName + ".xnb";
+
+ // Concat the file name with valid extensions
+ if (File.Exists(FileName + ".spritefont"))
+ return FileName + ".spritefont";
+
+ return null;
+ }
+
+ protected internal override SpriteFont Read(ContentReader input, SpriteFont existingInstance)
+ {
+ Texture2D texture = input.ReadObject<Texture2D>();
+ texture.IsSpriteFontTexture = true;
+ List<Rectangle> glyphs = input.ReadObject<List<Rectangle>>();
+ List<Rectangle> cropping = input.ReadObject<List<Rectangle>>();
+ List<char> charMap = input.ReadObject<List<char>>();
+ int lineSpacing = input.ReadInt32();
+ float spacing = input.ReadSingle();
+ List<Vector3> kerning = input.ReadObject<List<Vector3>>();
+ char? defaultCharacter = null;
+ if (input.ReadBoolean())
+ {
+ defaultCharacter = new char?(input.ReadChar());
+ }
+ return new SpriteFont(texture, glyphs, cropping, charMap, lineSpacing, spacing, kerning, defaultCharacter);
+ }
+ }
+}
View
114 MonoGame.Framework/Windows/Content/ContentReaders/Texture2DReader.cs
@@ -0,0 +1,114 @@
+#region License
+/*
+MIT License
+Copyright © 2006 The Mono.Xna Team
+
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+#endregion License
+
+using System;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Drawing;
+using OpenTK.Graphics.OpenGL;
+
+using Microsoft.Xna;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace Microsoft.Xna.Framework.Content
+{
+ internal class Texture2DReader : ContentTypeReader<Texture2D>
+ {
+ internal Texture2DReader()
+ {
+ // Do nothing
+ }
+
+ public static string Normalize(string FileName)
+ {
+ if (File.Exists(FileName))
+ return FileName;
+
+ // Check the file extension
+ if (!string.IsNullOrEmpty(Path.GetExtension(FileName)))
+ {
+ return null;
+ }
+
+ // Concat the file name with valid extensions
+ if (File.Exists(FileName + ".xnb"))
+ return FileName + ".xnb";
+ if (File.Exists(FileName + ".jpg"))
+ return FileName + ".jpg";
+ if (File.Exists(FileName + ".bmp"))
+ return FileName + ".bmp";
+ if (File.Exists(FileName + ".jpeg"))
+ return FileName + ".jpeg";
+ if (File.Exists(FileName + ".png"))
+ return FileName + ".png";
+ if (File.Exists(FileName + ".gif"))
+ return FileName + ".gif";
+ if (File.Exists(FileName + ".pict"))
+ return FileName + ".pict";
+
+ return null;
+ }
+
+ protected internal override Texture2D Read(ContentReader reader, Texture2D existingInstance)
+ {
+ Texture2D texture = null;
+
+ SurfaceFormat surfaceFormat = (SurfaceFormat)reader.ReadInt32 ();
+ int width = (reader.ReadInt32 ());
+ int height = (reader.ReadInt32 ());
+ int levelCount = (reader.ReadInt32 ());
+ SetDataOptions compressionType = (SetDataOptions)reader.ReadInt32 ();
+ int imageLength = width * height * 4;
+
+ if (surfaceFormat == SurfaceFormat.Dxt3)
+ {
+ ESTexture2D temp = ESTexture2D.InitiFromDxt3File(reader,imageLength,width,height);
+ texture = new Texture2D (new ESImage (temp));
+ }
+ else {
+ byte[] imageBytes = reader.ReadBytes (imageLength);
+ IntPtr ptr = Marshal.AllocHGlobal (imageLength);
+ try
+ {
+ Marshal.Copy (imageBytes, 0, ptr, imageLength);
+ ESTexture2D temp = new ESTexture2D (ptr, SurfaceFormat.Rgba32, width, height, new Size (width, height), All.Linear);
+ texture = new Texture2D (new ESImage (temp));
+ }
+ finally
+ {
+ Marshal.FreeHGlobal (ptr);
+ }
+ }
+
+ return texture;
+ }
+ }
+}
View
431 MonoGame.Framework/Windows/Game.cs
@@ -0,0 +1,431 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+XnaTouch - Copyright © 2009 The XnaTouch Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+using System.IO;
+using OpenTK.Graphics;
+
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input;
+using Microsoft.Xna.Framework.Input.Touch;
+
+namespace Microsoft.Xna.Framework
+{
+ public class Game : IDisposable
+ {
+ private const float FramesPerSecond = 60.0f; // ~60 frames per second
+
+ private GameTime _updateGameTime;
+ private GameTime _drawGameTime;
+ private DateTime _lastUpdate;
+ private bool _initialized = false;
+ private bool _initializing = false;
+ private bool _isActive = true;
+ private GameComponentCollection _gameComponentCollection;
+ public GameServiceContainer _services;
+ private ContentManager _content;
+ private WindowsGameWindow _view;
+ private bool _isFixedTimeStep = true;
+ private TimeSpan _targetElapsedTime = TimeSpan.FromSeconds(1 / FramesPerSecond);
+
+ internal IGraphicsDeviceManager graphicsDeviceManager;
+ internal IGraphicsDeviceService graphicsDeviceService;
+ private bool _devicesLoaded;
+
+ internal static bool _playingVideo = false;
+ private SpriteBatch spriteBatch;
+ private Texture2D splashScreen;
+
+ delegate void InitialiseGameComponentsDelegate();
+
+
+ public Game()
+ {
+
+ // Initialize collections
+ _services = new GameServiceContainer();
+ _gameComponentCollection = new GameComponentCollection();
+
+ _view = new WindowsGameWindow();
+ _view.Game = this;
+
+ // Initialize GameTime
+ _updateGameTime = new GameTime();
+ _drawGameTime = new GameTime();
+ }
+
+ ~Game()
+ {
+
+ }
+
+ public void Dispose ()
+ {
+ // do nothing
+ }
+
+
+ public bool IsActive
+ {
+ get
+ {
+ return _isActive;
+ }
+ protected set
+ {
+ if (_isActive != value )
+ {
+ _isActive = value;
+ }
+ }
+ }
+
+ public bool IsMouseVisible
+ {
+ get
+ {
+ return false;
+ }
+ set
+ {
+ // do nothing; ignore
+ }
+ }
+
+ public TimeSpan TargetElapsedTime
+ {
+ get
+ {
+ return _targetElapsedTime;
+ }
+ set
+ {
+ _targetElapsedTime = value;
+ if(_initialized) {
+ throw new NotSupportedException();
+ }
+ }
+ }
+
+ public void Run()
+ {
+ _lastUpdate = DateTime.Now;
+
+ //Need to execute this on the rendering thread
+ _view.OpenTkGameWindow.RenderFrame += delegate
+ {
+ if (!_devicesLoaded)
+ {
+ Initialize();
+ _devicesLoaded = true;
+ }
+ };
+
+ _view.OpenTkGameWindow.Run(FramesPerSecond / (FramesPerSecond * TargetElapsedTime.TotalSeconds));
+ }
+
+ internal void DoUpdate(GameTime aGameTime)
+ {
+ if (!_devicesLoaded)
+ return;
+
+ if (_isActive)
+ {
+ Update(aGameTime);
+ }
+ }
+
+ internal void DoDraw(GameTime aGameTime)
+ {
+ if (!_devicesLoaded)
+ return;
+
+ if (_isActive)
+ {
+ Draw(aGameTime);
+ }
+ }
+
+ internal void DoStep()
+ {
+ var timeNow = DateTime.Now;
+
+ // Update the game
+ _updateGameTime.Update(timeNow - _lastUpdate);
+ Update(_updateGameTime);
+
+ // Draw the screen
+ _drawGameTime.Update(timeNow - _lastUpdate);
+ _lastUpdate = timeNow;
+ Draw(_drawGameTime);
+ }
+
+ public bool IsFixedTimeStep
+ {
+ get
+ {
+ return _isFixedTimeStep;
+ }
+ set
+ {
+ _isFixedTimeStep = value;
+ }
+ }
+
+ public GameWindow Window
+ {
+ get
+ {
+ return _view;
+ }
+ }
+
+ public void ResetElapsedTime()
+ {
+ _lastUpdate = DateTime.Now;
+ }
+
+
+ public GameServiceContainer Services
+ {
+ get
+ {
+ return _services;
+ }
+ }
+
+ public ContentManager Content
+ {
+ get
+ {
+ if (_content == null)
+ {
+ _content = new ContentManager(_services);
+ }
+ return _content;
+ }
+ }
+
+ public GraphicsDevice GraphicsDevice
+ {
+ get
+ {
+ if (this.graphicsDeviceService == null)
+ {
+ this.graphicsDeviceService = this.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
+ if (this.graphicsDeviceService == null)
+ {
+ throw new InvalidOperationException("No Graphics Device Service");
+ }
+ }
+ return this.graphicsDeviceService.GraphicsDevice;
+ }
+ }
+
+ public void EnterBackground()
+ {
+ _isActive = false;
+ if (Deactivated != null)
+ Deactivated.Invoke(this, null);
+ }
+
+ public void EnterForeground()
+ {
+ _isActive = true;
+ if (Activated != null)
+ Activated.Invoke(this, null);
+ }
+
+ protected virtual bool BeginDraw()
+ {
+ return true;
+ }
+
+ protected virtual void EndDraw()
+ {
+
+ }
+
+ protected virtual void LoadContent()
+ {
+ string DefaultPath = "Default.png";
+ if (File.Exists(DefaultPath))
+ {
+ // Store the RootDir for later
+ string backup = Content.RootDirectory;
+
+ try
+ {
+ // Clear the RootDirectory for this operation
+ Content.RootDirectory = string.Empty;
+
+ spriteBatch = new SpriteBatch(GraphicsDevice);
+ splashScreen = Content.Load<Texture2D>(DefaultPath);
+ }
+ finally
+ {
+ // Reset RootDir
+ Content.RootDirectory = backup;
+ }
+
+ }
+ else
+ {
+ spriteBatch = null;
+ splashScreen = null;
+ }
+ }
+
+ protected virtual void UnloadContent()
+ {
+ // do nothing
+ }
+
+ protected virtual void Initialize()
+ {
+ this.graphicsDeviceManager = this.Services.GetService(typeof(IGraphicsDeviceManager)) as IGraphicsDeviceManager;
+ this.graphicsDeviceService = this.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
+
+ if ((this.graphicsDeviceService != null) && (this.graphicsDeviceService.GraphicsDevice != null))
+ {
+ LoadContent();
+ }
+ }
+
+ private void InitializeGameComponents()
+ {
+ foreach (GameComponent gc in _gameComponentCollection)
+ {
+ gc.Initialize();
+ }
+ }
+
+ protected virtual void Update(GameTime gameTime)
+ {
+ if ( _initialized)
+ {
+ foreach (GameComponent gc in _gameComponentCollection)
+ {
+ if (gc.Enabled)
+ {
+ gc.Update(gameTime);
+ }
+ }
+ }
+ else
+ {
+ if (!_initializing)
+ {
+ _initializing = true;
+
+ // Use OpenGLES context switching as described here
+ // http://developer.apple.com/iphone/library/qa/qa2010/qa1612.html
+ InitialiseGameComponentsDelegate initD = new InitialiseGameComponentsDelegate(InitializeGameComponents);
+
+ // Invoke on thread from the pool
+ initD.BeginInvoke(
+ delegate (IAsyncResult iar)
+ {
+ // We must have finished initialising, so set our flag appropriately
+ // So that we enter the Update loop
+ _initialized = true;
+ _initializing = false;
+ },
+ initD);
+ }
+ }
+ }
+
+ protected virtual void Draw(GameTime gameTime)
+ {
+ if ( _initializing )
+ {
+ if ( spriteBatch != null )
+ {
+ spriteBatch.Begin();
+
+ // We need to turn this into a progress bar or animation to give better user feedback
+ spriteBatch.Draw(splashScreen, new Vector2(0, 0), Color.White );
+ spriteBatch.End();
+ }
+ }
+ else
+ {
+ if (!_playingVideo)
+ {
+ foreach (GameComponent gc in _gameComponentCollection)
+ {
+ if (gc.Enabled && gc is DrawableGameComponent)
+ {
+ DrawableGameComponent dc = gc as DrawableGameComponent;
+ if (dc.Visible)
+ {
+ dc.Draw(gameTime);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public void Exit()
+ {
+ if (!_view.OpenTkGameWindow.IsExiting)
+ _view.OpenTkGameWindow.Exit();
+ }
+
+ public GameComponentCollection Components
+ {
+ get
+ {
+ return _gameComponentCollection;
+ }
+ }
+
+ #region Events
+ public event EventHandler Activated;
+ public event EventHandler Deactivated;
+ public event EventHandler Disposed;
+ public event EventHandler Exiting;
+ #endregion
+ }
+}
+
View
69 MonoGame.Framework/Windows/Graphics/DisplayMode.cs
@@ -0,0 +1,69 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ public struct DisplayMode
+ {
+ private int _width;
+ private int _height;
+
+ internal DisplayMode(int width, int height)
+ {
+ _width = width;
+ _height = height;
+ }
+
+ public float AspectRatio
+ {
+ get
+ {
+ return Width / Height;
+ }
+ }
+
+ public int Width { get { return _width; } }
+
+ public int Height { get { return _height; } }
+
+ }
+}
View
219 MonoGame.Framework/Windows/Graphics/ESImage.cs
@@ -0,0 +1,219 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+using System.Drawing;
+using OpenTK.Graphics.OpenGL;
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ internal class ESImage
+ {
+ // The OpenGL texture to be used for this image
+ private ESTexture2D texture;
+ // The width of the image
+ private int imageWidth;
+ // The height of the image
+ private int imageHeight;
+ // The texture coordinate width to use to find the image
+ private int textureWidth;
+ // The texture coordinate height to use to find the image
+ private int textureHeight;
+ // The texture width to pixel ratio
+ private float texWidthRatio;
+ // The texture height to pixel ratio
+ private float texHeightRatio;
+ // The X offset to use when looking for our image
+ private int textureOffsetX;
+ // The Y offset to use when looking for our image
+ private int textureOffsetY;
+
+ public ESImage ()
+ {
+ imageWidth = 0;
+ imageHeight = 0;
+ textureWidth = 0;
+ textureHeight = 0;
+ texWidthRatio = 0.0f;
+ texHeightRatio = 0.0f;
+ textureOffsetX = 0;
+ textureOffsetY = 0;
+ }
+
+ private void Initialize( float scale )
+ {
+ imageWidth = texture.ContentSize.Width;
+ imageHeight = texture.ContentSize.Height;
+ textureWidth = (int)(texture.PixelsWide/scale);
+ textureHeight = (int)(texture.PixelsHigh/scale);
+ texWidthRatio = 1.0f / (float)textureWidth;
+ texHeightRatio = 1.0f / (float)textureHeight;
+ textureOffsetX = 0;
+ textureOffsetY = 0;
+ }
+
+ public ESImage(ESTexture2D tex)
+ {
+ texture = tex;
+ Initialize(1.0f);
+ }
+
+ public ESImage(ESTexture2D tex, float imageScale)
+ {
+ texture = tex;
+ Initialize(1.0f);
+ }
+
+ public ESImage(Bitmap image)
+ {
+ // By default set the scale to 1.0f and the filtering to GL_NEAREST
+ texture = new ESTexture2D(image,All.Nearest);
+ Initialize(1.0f);
+ }
+
+ public ESImage(Bitmap image, All filter)
+ {
+ // By default set the scale to 1.0f
+ texture = new ESTexture2D(image,filter);
+ Initialize(1.0f);
+ }
+
+ public ESImage(Bitmap image, float imageScale, All filter)
+ {
+ texture = new ESTexture2D(image,filter);
+ Initialize(imageScale);
+ }
+
+
+ public int TextureOffsetX
+ {
+ get
+ {
+ return textureOffsetX;
+ }
+ set
+ {
+ textureOffsetX = value;
+ }
+ }
+
+ public int TextureOffsetY
+ {
+ get
+ {
+ return textureOffsetY;
+ }
+ set
+ {
+ textureOffsetY = value;
+ }
+ }
+
+ public int ImageWidth
+ {
+ get
+ {
+ return imageWidth;
+ }
+ set
+ {
+ imageWidth = value;
+ }
+ }
+
+ public int ImageHeight
+ {
+ get
+ {
+ return imageHeight;
+ }
+ set
+ {
+ imageHeight = value;
+ }
+ }
+
+ public ESImage GetSubImageAtPoint(Vector2 point, int subImageWidth, int subImageHeight, float subImageScale)
+ {
+ //Create a new Image instance using the texture which has been assigned to the current instance
+ ESImage subImage = new ESImage(texture,subImageScale);
+ // Define the offset of the subimage we want using the point provided
+ subImage.TextureOffsetX = (int) point.X;
+ subImage.TextureOffsetY = (int) point.Y;
+
+ // Set the width and the height of the subimage
+ subImage.ImageWidth = subImageWidth;
+ subImage.ImageHeight = subImageHeight;
+
+ return subImage;
+ }
+ public Vector2 GetTextureCoord ( int x, int y )
+ {
+ return new Vector2(x*texWidthRatio,y*texHeightRatio);
+ }
+ public Vector2[] GetTextureCoordinates(Rectangle textureRect)
+ {
+ Vector2[] coordinates = new Vector2[4];
+
+ coordinates[0] = new Vector2(texWidthRatio * textureRect.Width + (texWidthRatio * textureRect.Left),texHeightRatio * textureRect.Top);
+ coordinates[1] = new Vector2(texWidthRatio * textureRect.Width + (texWidthRatio * textureRect.Left),texHeightRatio * textureRect.Height + (texHeightRatio * textureRect.Top));
+ coordinates[2] = new Vector2(texWidthRatio * textureRect.Left ,texHeightRatio * textureRect.Top);
+ coordinates[3] = new Vector2(texWidthRatio * textureRect.Left,texHeightRatio * textureRect.Height + (texHeightRatio * textureRect.Top));
+
+ return coordinates;
+ }
+
+ public uint Name
+ {
+ get
+ {
+ return texture.Name;
+ }
+ }
+
+ public SurfaceFormat Format
+ {
+ get
+ {
+ return texture.PixelFormat;
+ }
+ }
+ }
+}
View
326 MonoGame.Framework/Windows/Graphics/ESTexture2D.cs
@@ -0,0 +1,326 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.Runtime.InteropServices;
+using System.IO;
+using OpenTK.Graphics.OpenGL;
+using Buffer = System.Buffer;
+
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ internal class ESTexture2D : IDisposable
+ {
+ private uint _name;
+ private Size _size;
+ private int _width,_height;
+ private SurfaceFormat _format;
+ private float _maxS,_maxT;
+
+ public ESTexture2D (IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, All filter)
+ {
+ InitWithData(data,pixelFormat,width,height,size, filter);
+ }
+
+ public ESTexture2D(Bitmap image, All filter)
+ {
+ InitWithBitmap(image, filter);
+ }
+
+ public void InitWithBitmap(Bitmap image, All filter)
+ {
+ BitmapData bitmapData = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly,
+ System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+
+ _format = SurfaceFormat.Rgba32;
+ InitWithData(bitmapData.Scan0, _format, image.Width, image.Height, new Size(image.Width, image.Height), filter);
+ image.UnlockBits(bitmapData);
+ }
+
+ public void InitWithData(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, All filter)
+ {
+ GL.GenTextures(1, out _name);
+ GL.BindTexture(TextureTarget.Texture2D, _name);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)filter);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)filter);
+
+ int sz = 0;
+
+ switch (pixelFormat) {
+ case SurfaceFormat.Rgba32 /*kTexture2DPixelFormat_RGBA8888*/:
+ case SurfaceFormat.Dxt3:
+ sz = 4;
+ GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, data);
+ break;
+ case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/:
+ sz = 2;
+ GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedShort4444, data);
+ break;
+ case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/:
+ sz = 2;
+ GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedShort5551, data);
+ break;
+ case SurfaceFormat.Rgb32 /*kTexture2DPixelFormat_RGB565*/:
+ sz = 2;
+ GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, (int)width, (int)height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedShort565, data);
+ break;
+ case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/:
+ sz = 1;
+ GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Alpha, (int)width, (int)height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Alpha, PixelType.UnsignedByte, data);
+ break;
+ default:
+ throw new NotSupportedException("Texture format");
+ }
+
+ _size = size;
+ _width = width;
+ _height = height;
+ _format = pixelFormat;
+ _maxS = size.Width / (float)width;
+ _maxT = size.Height / (float)height;
+ }
+
+ public unsafe void Dispose ()
+ {
+ if(_name != 0)
+ {
+ GL.DeleteTextures(1, ref _name);
+ }
+ }
+
+ private static byte GetBits64(ulong source, int first, int length, int shift)
+ {
+ uint[] bitmasks = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
+ uint bitmask = bitmasks[length];
+ source = source >> first;
+ source = source & bitmask;
+ source = source << shift;
+ return (byte)source;
+ }
+
+ private static byte GetBits(uint source, int first, int length, int shift)
+ {
+ uint[] bitmasks = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
+
+ uint bitmask = bitmasks[length];
+ source = source >> first;
+ source = source & bitmask;
+ source = source << shift;
+ return (byte)source;
+ }
+
+
+ private static void SetColorFromPacked(byte[] data, int offset, byte alpha, uint packed)
+ {
+ byte r = (byte)(GetBits(packed, 0, 8, 0));
+ byte g = (byte)(GetBits(packed, 8, 8, 0));
+ byte b = (byte)(GetBits(packed, 16, 8, 0));
+ data[offset] = r;
+ data[offset + 1] = g;
+ data[offset + 2] = b;
+ data[offset + 3] = alpha;
+ }
+
+ private static void ColorsFromPacked(uint[] colors, uint c0, uint c1, bool flag)
+ {
+ uint rb0, rb1, rb2, rb3, g0, g1, g2, g3;
+
+ rb0 = (c0 << 3 | c0 << 8) & 0xf800f8;
+ rb1 = (c1 << 3 | c1 << 8) & 0xf800f8;
+ rb0 += (rb0 >> 5) & 0x070007;
+ rb1 += (rb1 >> 5) & 0x070007;
+ g0 = (c0 << 5) & 0x00fc00;
+ g1 = (c1 << 5) & 0x00fc00;
+ g0 += (g0 >> 6) & 0x000300;
+ g1 += (g1 >> 6) & 0x000300;
+
+ colors[0] = rb0 + g0;
+ colors[1] = rb1 + g1;
+
+ if (c0 > c1 || flag)
+ {
+ rb2 = (((2 * rb0 + rb1) * 21) >> 6) & 0xff00ff;
+ rb3 = (((2 * rb1 + rb0) * 21) >> 6) & 0xff00ff;
+ g2 = (((2 * g0 + g1) * 21) >> 6) & 0x00ff00;
+ g3 = (((2 * g1 + g0) * 21) >> 6) & 0x00ff00;
+ colors[3] = rb3 + g3;
+ }
+ else
+ {
+ rb2 = ((rb0 + rb1) >> 1) & 0xff00ff;
+ g2 = ((g0 + g1) >> 1) & 0x00ff00;
+ colors[3] = 0;
+ }
+
+ colors[2] = rb2 + g2;
+ }
+
+ static public ESTexture2D InitiFromDxt3File(BinaryReader rdr, int length, int width, int height)
+ {
+ byte [] b = GetBits (width, length, height, rdr);
+
+ // Copy bits
+ IntPtr pointer = Marshal.AllocHGlobal(length);
+ Marshal.Copy (b, 0, pointer, length);
+ ESTexture2D result = new ESTexture2D(pointer,SurfaceFormat.Dxt3,width,height,new Size(width,height),All.Linear);
+ Marshal.FreeHGlobal(pointer);
+ return result;
+ }
+
+ public static byte[] GetBits (int width, int length, int height, BinaryReader rdr)
+ {
+ int xoffset = 0;
+ int yoffset = 0;
+ int rowLength = width * 4;
+ byte[] b = new byte[length];
+ ulong alpha;
+ ushort c0, c1;
+ uint[] colors = new uint[4];
+ uint lu;
+ for (int y = 0; y < height / 4; y++) {
+ yoffset = y * 4;
+ for (int x = 0; x < width / 4; x++) {
+ xoffset = x * 4;
+ alpha = rdr.ReadUInt64 ();
+ c0 = rdr.ReadUInt16 ();
+ c1 = rdr.ReadUInt16 ();
+ ColorsFromPacked (colors, c0, c1, true);
+ lu = rdr.ReadUInt32 ();
+ for (int i = 0; i < 16; i++) {
+ int idx = GetBits (lu, 30 - i * 2, 2, 0);
+ uint ci = colors[idx];
+ int ii = 15 - i;
+ byte a = (byte)(GetBits64 (alpha, ii * 4, 4, 0));
+ a += (byte)(a << 4);
+ int yy = yoffset + (ii / 4);
+ int xx = xoffset + (ii % 4);
+ int offset = yy * rowLength + xx * 4;
+ SetColorFromPacked (b, offset, a, ci);
+ }
+ }
+ }
+ return b;
+ }
+
+ public unsafe void DrawAtPoint(Vector2 point)
+ {
+ float []coordinates = { 0, _maxT, _maxS, _maxT, 0, 0,_maxS, 0 };
+ float width = (float)_width * _maxS;
+ float height = (float)_height * _maxT;
+ float []vertices = { -width / 2.0f + point.X, -height / 2.0f + point.Y, 0.0f,
+ width / 2.0f + point.X, -height / 2.0f + point.Y, 0.0f,
+ -width / 2.0f + point.X, height / 2.0f + point.Y, 0.0f,
+ width / 2.0f + point.X, height / 2.0f + point.Y, 0.0f };
+
+ GL.BindTexture(TextureTarget.Texture2D, _name);
+ GL.VertexPointer(3, VertexPointerType.Float, 0, vertices);
+ GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, coordinates);
+ GL.DrawArrays(BeginMode.TriangleStrip, 0, 4);
+ }
+
+ public unsafe void DrawInRect(Rectangle rect)
+ {
+ float[] coordinates = { 0, _maxT,_maxS, _maxT,0, 0,_maxS, 0 };
+ float[] vertices = { rect.Left, rect.Top, 0.0f, rect.Right, rect.Top,0.0f,rect.Left,rect.Bottom,0.0f,rect.Right,rect.Bottom,0.0f };
+
+ GL.BindTexture(TextureTarget.Texture2D, _name);
+ GL.VertexPointer(3, VertexPointerType.Float, 0, vertices);
+ GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, coordinates);
+ GL.DrawArrays(BeginMode.TriangleStrip, 0, 4);
+ }
+
+ public Size ContentSize
+ {
+ get
+ {
+ return _size;
+ }
+ }
+
+ public SurfaceFormat PixelFormat
+ {
+ get
+ {
+ return _format;
+ }
+ }
+
+ public int PixelsWide
+ {
+ get
+ {
+ return _width;
+ }
+ }
+
+ public int PixelsHigh
+ {
+ get
+ {
+ return _height;
+ }
+ }
+
+ public uint Name
+ {
+ get { return _name; }
+ }
+
+ public float MaxS
+ {
+ get
+ {
+ return _maxS;
+ }
+ }
+
+ public float MaxT
+ {
+ get
+ {
+ return _maxT;
+ }
+ }
+
+ }
+}
View
193 MonoGame.Framework/Windows/Graphics/Effect.cs
@@ -0,0 +1,193 @@
+// #region License
+// /*
+// Microsoft Public License (Ms-PL)
+// MonoGame - Copyright © 2009 The MonoGame Team
+//
+// All rights reserved.
+//
+// This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+// accept the license, do not use the software.
+//
+// 1. Definitions
+// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+// U.S. copyright law.
+//
+// A "contribution" is the original software, or any additions or changes to the software.
+// A "contributor" is any person that distributes its contribution under this license.
+// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
+//
+// 2. Grant of Rights
+// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+// 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.
+// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+// 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.
+//
+// 3. Conditions and Limitations
+// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+// your patent license from such contributor to the software ends automatically.
+// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+// notices that are present in the software.
+// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+// code form, you may only do so under a license that complies with this license.
+// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+// permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+// purpose and non-infringement.
+// */
+// #endregion License
+//
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using OpenTK.Graphics.OpenGL;
+
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ public class Effect : IDisposable
+ {
+ private GraphicsDevice graphicsDevice;
+ private int fragment_handle;
+ private int vertex_handle;
+ private bool fragment;
+ private bool vertex;
+
+ public Effect (
+ GraphicsDevice graphicsDevice,
+ byte[] effectCode,
+ CompilerOptions options,
+ EffectPool pool)
+ {
+
+ if (graphicsDevice == null)
+ {
+ throw new ArgumentNullException("Graphics Device Cannot Be Null");
+ }
+ this.graphicsDevice = graphicsDevice;
+
+ if (pool == null)
+ {
+ return;
+ // TODO throw new ArgumentNullException("Effect Pool Cannot Be Null");
+ }
+
+ int fragmentblocklength = BitConverter.ToInt32(effectCode, 0);
+
+ int vertexblocklength = BitConverter.ToInt32(effectCode, fragmentblocklength + 4);
+
+ if (fragmentblocklength != 0)
+ {
+ fragment_handle = GL.CreateShader( ShaderType.FragmentShader );
+ fragment = true;
+ }
+
+ if (vertexblocklength != 0)
+ {
+ vertex_handle = GL.CreateShader( ShaderType.VertexShader );
+ vertex = true;
+ }
+
+ if (fragment)
+ {
+ string[] fragmentstring = new string[1] { Encoding.UTF8.GetString(effectCode, 4, fragmentblocklength) };
+ //int[] fragmentLength = new int[1] { fragmentstring[0].Length };
+ int fragmentLength = fragmentstring[0].Length;
+ GL.ShaderSource(fragment_handle, 1, fragmentstring, ref fragmentLength);
+ }
+
+ if (vertex)
+ {
+ string[] vertexstring = new string[1] { Encoding.UTF8.GetString(effectCode, fragmentblocklength + 8, vertexblocklength) };
+ // int[] vertexLength = new int[1] { vertexstring[0].Length };
+ int vertexLength = vertexstring[0].Length;
+ GL.ShaderSource(vertex_handle, 1, vertexstring, ref vertexLength);
+ }
+
+ int compiled = 0;
+
+ if (fragment)
+ {
+ GL.CompileShader(fragment_handle);
+
+ GL.GetShader(fragment_handle, ShaderParameter.CompileStatus, out compiled );
+ if (compiled == (int)All.False)
+ {
+ Console.Write("Fragment Compilation Failed!");
+ }
+ }
+
+ if (vertex)
+ {
+ GL.CompileShader(vertex_handle);
+ GL.GetShader(vertex_handle, ShaderParameter.CompileStatus, out compiled );
+ if (compiled == (int)All.False)
+ {
+ Console.Write("Vertex Compilation Failed!");
+ }
+ }
+
+ }
+
+ protected Effect(GraphicsDevice graphicsDevice, Effect cloneSource )
+ {
+ if (graphicsDevice == null)
+ {
+ throw new ArgumentNullException("Graphics Device Cannot Be Null");
+ }
+ this.graphicsDevice = graphicsDevice;
+ }
+
+ public void Begin()
+ {
+ }
+
+ public void Begin(SaveStateMode saveStateMode)
+ {
+
+ }
+
+ public virtual Effect Clone(GraphicsDevice device)
+ {
+ Effect f = new Effect( graphicsDevice, this );
+ return f;
+ }
+
+ public void Dispose()
+ {
+ }
+
+ public void End()
+ {
+ }
+
+ internal static string Normalize(string FileName)
+ {
+ if (File.Exists(FileName))
+ return FileName;
+
+ // Check the file extension
+ if (!string.IsNullOrEmpty(Path.GetExtension(FileName)))
+ {
+ return null;
+ }
+
+ // Concat the file name with valid extensions
+ if (File.Exists(FileName+".fsh"))
+ return FileName+".fsh";
+ if (File.Exists(FileName+".vsh"))
+ return FileName+".vsh";
+
+ return null;
+ }
+
+ public EffectTechnique CurrentTechnique
+ {
+ get; set;
+ }
+
+ }
+}
View
350 MonoGame.Framework/Windows/Graphics/GraphicsDevice.cs
@@ -0,0 +1,350 @@
+#region License
+/*
+Microsoft Public License (Ms-PL)
+MonoGame - Copyright © 2009 The MonoGame Team
+
+All rights reserved.
+
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+accept the license, do not use the software.
+
+1. Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+U.S. copyright law.
+
+A "contribution" is the original software, or any additions or changes to the software.
+A "contributor" is any person that distributes its contribution under this license.
+"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+
+2. Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+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.
+
+3. Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+your patent license from such contributor to the software ends automatically.
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
+notices that are present in the software.
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
+a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
+code form, you may only do so under a license that complies with this license.
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
+or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
+permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
+purpose and non-infringement.
+*/
+#endregion License
+
+using System;
+
+using OpenTK.Graphics.OpenGL;
+// using OpenTK.Graphics.ES11;
+
+using Microsoft.Xna.Framework;
+
+namespace Microsoft.Xna.Framework.Graphics
+{
+ public class GraphicsDevice : IDisposable
+ {
+ private All _preferedFilter;
+ private int _activeTexture = -1;
+ private Viewport _viewport;
+ private GraphicsDevice2D _spriteDevice;
+ private bool _isDisposed = false;
+ private readonly DisplayMode _displayMode;
+ private RenderState _renderState;
+
+ internal All PreferedFilter
+ {
+ get
+ {
+ return _preferedFilter;
+ }
+ set
+ {
+ _preferedFilter = value;
+ }
+
+ }
+
+ internal int ActiveTexture
+ {
+ get
+ {
+ return _activeTexture;
+ }
+ set
+ {
+ _activeTexture = value;
+ }
+ }
+
+ public bool IsDisposed
+ {
+ get
+ {
+ return _isDisposed;
+ }
+ }
+
+ internal GraphicsDevice(int width, int height)
+ {
+ _displayMode = new DisplayMode(width, height);
+
+ // Initialize the main viewport
+ _viewport = new Viewport();
+ _viewport.X = 0;
+ _viewport.Y = 0;
+ _viewport.Width = DisplayMode.Width;
+ _viewport.Height = DisplayMode.Height;
+ _viewport.TitleSafeArea = new Rectangle(0, 0, DisplayMode.Width, DisplayMode.Height);
+
+ // Create the Sprite Rendering engine
+ _spriteDevice = new GraphicsDevice2D(this);
+
+ // Init RenderState
+ _renderState = new RenderState();
+ }
+
+ public GraphicsDevice() :this(500, 500)
+ {
+ }
+
+ public void Clear(Color color)
+ {
+ Vector4 vector = color.ToEAGLColor();
+ GL.ClearColor (vector.X,vector.Y,vector.Z,1.0f);
+ GL.Clear(ClearBufferMask.ColorBufferBit);
+ }
+
+ public void Clear(ClearOptions options, Color color, float depth, int stencil)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Clear(ClearOptions options, Vector4 color, float depth, int stencil)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Clear(ClearOptions options, Color color, float depth, int stencil, Rectangle[] regions)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Clear(ClearOptions options, Vector4 color, float depth, int stencil, Rectangle[] regions)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Dispose()
+ {
+ _isDisposed = true;
+ }
+
+ protected virtual void Dispose(bool aReleaseEverything)
+ {
+ if (aReleaseEverything)
+ {
+
+ }
+
+ _isDisposed = true;
+ }
+
+ public void Present()
+ {
+ }
+
+ public void Present(Rectangle? sourceRectangle, Rectangle? destinationRectangle, IntPtr overrideWindowHandle)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Reset()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Reset(Microsoft.Xna.Framework.Graphics.PresentationParameters presentationParameters)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Reset(Microsoft.Xna.Framework.Graphics.PresentationParameters presentationParameters, GraphicsAdapter graphicsAdapter)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Microsoft.Xna.Framework.Graphics.DisplayMode DisplayMode
+ {
+ get
+ {
+ return _displayMode;
+ }
+ }
+
+ public Microsoft.Xna.Framework.Graphics.GraphicsDeviceCapabilities GraphicsDeviceCapabilities
+ {
+ get
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public Microsoft.Xna.Framework.Graphics.GraphicsDeviceStatus GraphicsDeviceStatus
+ {
+ get
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public Microsoft.Xna.Framework.Graphics.PresentationParameters PresentationParameters
+ {
+ get;
+ set;
+ }
+
+ public Microsoft.Xna.Framework.Graphics.Viewport Viewport
+ {
+ get
+ {
+ return _viewport;
+ }
+ set
+ {
+ _viewport = value;
+ }
+ }
+
+ public Microsoft.Xna.Framework.Graphics.GraphicsProfile GraphicsProfile
+ {
+ get;
+ set;
+ }
+
+ internal void StartSpriteBatch(SpriteBlendMode blendMode, SpriteSortMode sortMode)
+ {
+ _spriteDevice.StartSpriteBatch(blendMode,sortMode);
+ }
+
+ internal void EndSpriteBatch()
+ {
+ _spriteDevice.EndSpriteBatch();
+ }
+
+ internal void AddToSpriteBuffer(SpriteBatchRenderItem sbItem)
+ {
+ _spriteDevice.AddToSpriteBuffer(sbItem);
+ }
+
+ internal void RenderSprites(Vector2 point, float[] texCoords, float[] quadVertices, RenderMode renderMode)
+ {
+ if (texCoords.Length == 0) return;
+
+ int itemCount = texCoords.Length / 8;
+
+ // Enable Texture_2D
+ GL.Enable(EnableCap.Texture2D);
+
+ // Set the glColor to apply alpha to the image
+ Vector4 color = renderMode.FilterColor.ToEAGLColor();
+ GL.Color4(color.X, color.Y, color.Z, color.W);
+
+ // Set client states so that the Texture Coordinate Array will be used during rendering
+ GL.EnableClientState(ArrayCap.TextureCoordArray);
+
+ // Bind to the texture that is associated with this image
+ if (ActiveTexture != renderMode.Texture.Image.Name)
+ {
+ GL.BindTexture(TextureTarget.Texture2D, renderMode.Texture.Image.Name);
+ ActiveTexture = (int) renderMode.Texture.Image.Name;
+ }
+
+ // Set up the VertexPointer to point to the vertices we have defined
+ GL.VertexPointer(2, VertexPointerType.Float, 0, quadVertices);
+
+ // Set up the TexCoordPointer to point to the texture coordinates we want to use
+ GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, texCoords);
+
+ // Draw the vertices to the screen
+ if (itemCount > 1)
+ {
+ ushort[] indices = new ushort[itemCount*6];
+ for (int i=0;i<itemCount;i++)
+ {
+ indices[i*6+0] = (ushort) (i*4+0);
+ indices[i*6+1] = (ushort) (i*4+1);
+ indices[i*6+2] = (ushort) (i*4+2);
+ indices[i*6+5] = (ushort) (i*4+1);
+ indices[i*6+4] = (ushort) (i*4+2);
+ indices[i*6+3] = (ushort) (i*4+3);
+ }
+ // Draw triangles
+ GL.DrawElements(BeginMode.Triangles,itemCount*6,DrawElementsType.UnsignedShort,indices);
+ }
+ else {
+ // Draw the vertices to the screen
+ GL.DrawArrays(BeginMode.TriangleStrip, 0, 4);
+ }
+ // Disable as necessary
+ GL.DisableClientState(ArrayCap.TextureCoordArray);
+
+ // Disable 2D textures
+ GL.Disable(EnableCap.Texture2D);
+ }
+
+ public VertexDeclaration VertexDeclaration
+ {
+ get;
+ set;
+ }
+
+ public Rectangle ScissorRectangle
+ {
+ get;
+ set;
+ }
+
+ public RenderState RenderState
+ {
+ get
+ {
+ return _renderState;
+ }
+ set
+ {
+ if ( _renderState != value )
+ {
+ _renderState = value;
+ }
+ }
+ }
+
+ public void SetRenderTarget (
+ int renderTargetIndex,
+ RenderTarget2D renderTarget
+ )
+ {
+ throw new NotImplementedException();
+ }
+
+ public void ResolveBackBuffer( ResolveTexture2D resolveTexture )
+ {
+ }
+
+ public void DrawUserPrimitives<T> (
+ PrimitiveType primitiveType,
+ T[] vertexData,
+ int vertexOffset,
+ int primitiveCount)
+ {
+ }
+
+ }
+}
+
View
290 MonoGame.Framework/Windows/Graphics/GraphicsDevice2D.cs
@@ -0,0 +1,290 @@
+// #region License
+// /*
+// Microsoft Public License (Ms-PL)
+// MonoGame - Copyright © 2009 The MonoGame Team
+//
+// All rights reserved.
+//
+// This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
+// accept the license, do not use the software.
+//
+// 1. Definitions
+// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
+// U.S. copyright law.
+//
+// A "contribution" is the original software, or any additions or changes to the software.
+// A "contributor" is any person that distributes its contribution under this license.
+// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
+//
+// 2. Grant of Rights
+// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+// 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.
+// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
+// 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.
+//
+// 3. Conditions and Limitations
+// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
+// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
+// your patent license from such contributor to the software ends automatically.
+// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution