Skip to content

Commit

Permalink
Merge branch 'develop3d' into stable_ARMED!
Browse files Browse the repository at this point in the history
  • Loading branch information
tomspilman committed Nov 13, 2012
2 parents 3e26f74 + c918d9f commit b1368a2
Show file tree
Hide file tree
Showing 22 changed files with 1,397 additions and 72 deletions.
26 changes: 26 additions & 0 deletions MonoGame.Framework.WindowsPhone.sln
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.WindowsPhone", "MonoGame.Framework\MonoGame.Framework.WindowsPhone.csproj", "{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|x86 = Debug|x86
Release|ARM = Release|ARM
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Debug|ARM.ActiveCfg = Debug|ARM
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Debug|ARM.Build.0 = Debug|ARM
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Debug|x86.ActiveCfg = Debug|x86
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Debug|x86.Build.0 = Debug|x86
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Release|ARM.ActiveCfg = Release|ARM
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Release|ARM.Build.0 = Release|ARM
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Release|x86.ActiveCfg = Release|x86
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
11 changes: 7 additions & 4 deletions MonoGame.Framework/Game.cs
Expand Up @@ -143,9 +143,9 @@ public Game()
Platform.Deactivated += OnDeactivated;
_services.AddService(typeof(GamePlatform), Platform);

#if WINRT
#if WINDOWS_STOREAPP
Platform.ViewStateChanged += Platform_ApplicationViewChanged;
#endif //WINRT
#endif

#if MONOMAC || WINDOWS || LINUX
// Set the window title.
Expand Down Expand Up @@ -349,8 +349,11 @@ internal bool Initialized
public event EventHandler<EventArgs> Disposed;
public event EventHandler<EventArgs> Exiting;

#if WINRT
#if WINDOWS_STOREAPP
public event EventHandler<ViewStateChangedEventArgs> ApplicationViewChanged;
#endif

#if WINRT
public ApplicationExecutionState PreviousExecutionState { get; internal set; }
#endif

Expand Down Expand Up @@ -627,7 +630,7 @@ private void Platform_AsyncRunLoopEnded(object sender, EventArgs e)
DoExiting();
}

#if WINRT
#if WINDOWS_STOREAPP
private void Platform_ApplicationViewChanged(object sender, ViewStateChangedEventArgs e)
{
AssertNotDisposed();
Expand Down
6 changes: 4 additions & 2 deletions MonoGame.Framework/GamePlatform.cs
Expand Up @@ -98,6 +98,8 @@ public static GamePlatform Create(Game game)
return new AndroidGamePlatform(game);
#elif PSM
return new PSSGamePlatform(game);
#elif WINDOWS_PHONE
return new MonoGame.Framework.WindowsPhone.WindowsPhoneGamePlatform(game);
#elif WINRT
return new MetroGamePlatform(game);
#endif
Expand Down Expand Up @@ -161,7 +163,7 @@ public bool IsMouseVisible
}
}

#if WINRT
#if WINDOWS_STOREAPP
private ApplicationViewState _viewState;
public ApplicationViewState ViewState
{
Expand Down Expand Up @@ -213,7 +215,7 @@ public virtual bool VSyncEnabled
public event EventHandler<EventArgs> Activated;
public event EventHandler<EventArgs> Deactivated;

#if WINRT
#if WINDOWS_STOREAPP
public event EventHandler<ViewStateChangedEventArgs> ViewStateChanged;
#endif

Expand Down
5 changes: 5 additions & 0 deletions MonoGame.Framework/GameTimer.cs
Expand Up @@ -6,8 +6,13 @@
using System.Threading.Tasks;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;

#if WINDOWS_PHONE

#elif WINRT
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#endif

namespace Microsoft.Xna.Framework
{
Expand Down
176 changes: 145 additions & 31 deletions MonoGame.Framework/Graphics/GraphicsDevice.cs
Expand Up @@ -52,12 +52,18 @@ 1. Definitions
using OpenTK.Graphics.OpenGL;
#elif WINRT
using SharpDX;
using SharpDX.DXGI;
using SharpDX.Direct3D;
using Windows.Graphics.Display;
using Windows.UI.Core;
#if WINDOWS_PHONE
using SharpDX.Direct3D11;
using Windows.Foundation;
using MonoGame.Framework.WindowsPhone;
#else
using Windows.UI.Xaml.Controls;
#elif PSM
using Windows.Graphics.Display;
using Windows.UI.Core;
using SharpDX.DXGI;
#endif
#elif PSM
using Sce.PlayStation.Core.Graphics;
using PssVertexBuffer = Sce.PlayStation.Core.Graphics.VertexBuffer;
#elif GLES
Expand Down Expand Up @@ -134,6 +140,15 @@ public class GraphicsDevice : IDisposable

#if DIRECTX

// Core Direct3D Objects
internal SharpDX.Direct3D11.Device _d3dDevice;
internal SharpDX.Direct3D11.DeviceContext _d3dContext;
protected FeatureLevel _featureLevel;
protected SharpDX.Direct3D11.RenderTargetView _renderTargetView;
protected SharpDX.Direct3D11.DepthStencilView _depthStencilView;

#if !WINDOWS_PHONE

// Declare Direct2D Objects
protected SharpDX.Direct2D1.Factory1 _d2dFactory;
protected SharpDX.Direct2D1.Device _d2dDevice;
Expand All @@ -143,26 +158,21 @@ public class GraphicsDevice : IDisposable
protected SharpDX.DirectWrite.Factory _dwriteFactory;
protected SharpDX.WIC.ImagingFactory2 _wicFactory;

// Direct3D Objects
internal SharpDX.Direct3D11.Device1 _d3dDevice;
internal SharpDX.Direct3D11.DeviceContext1 _d3dContext;
protected FeatureLevel _featureLevel;

// The backbuffer resources.
protected SharpDX.Direct3D11.RenderTargetView _renderTargetView;
protected SharpDX.Direct3D11.DepthStencilView _depthStencilView;
// The swap chain resources.
protected SharpDX.Direct2D1.Bitmap1 _bitmapTarget;
protected SharpDX.DXGI.SwapChain1 _swapChain;
protected SwapChainBackgroundPanel _swapChainPanel;

protected float _dpi;

#endif

// The active render targets.
protected SharpDX.Direct3D11.RenderTargetView[] _currentRenderTargets = new SharpDX.Direct3D11.RenderTargetView[4];

// The active depth view.
protected SharpDX.Direct3D11.DepthStencilView _currentDepthStencilView;

protected float _dpi;

private readonly Dictionary<ulong, SharpDX.Direct3D11.InputLayout> _inputLayouts = new Dictionary<ulong, SharpDX.Direct3D11.InputLayout>();

private readonly Dictionary<int, DynamicVertexBuffer> _userVertexBuffers = new Dictionary<int, DynamicVertexBuffer>();
Expand Down Expand Up @@ -229,7 +239,7 @@ public class GraphicsDevice : IDisposable

internal int MaxTextureSlots;

#if DIRECTX
#if DIRECTX && !WINDOWS_PHONE

internal float Dpi
{
Expand Down Expand Up @@ -360,10 +370,23 @@ internal void Initialize()

#if DIRECTX

#if WINDOWS_PHONE

UpdateDevice(DrawingSurfaceState.Device, DrawingSurfaceState.Context);
UpdateTarget(DrawingSurfaceState.RenderTargetView);

DrawingSurfaceState.Device = null;
DrawingSurfaceState.Context = null;
DrawingSurfaceState.RenderTargetView = null;

#else

CreateDeviceIndependentResources();
CreateDeviceResources();
Dpi = DisplayProperties.LogicalDpi;
CreateSizeDependentResources();

#endif

#elif PSM
_graphics = new GraphicsContext();
Expand Down Expand Up @@ -411,7 +434,72 @@ internal void Initialize()
#endif
}

#if DIRECTX
#if DIRECTX

#if WINDOWS_PHONE

internal void UpdateDevice(Device device, DeviceContext context)
{
// TODO: Lost device logic!

if (_d3dDevice != null)
{
_d3dDevice.Dispose();
_d3dDevice = null;
}
_d3dDevice = device;

if (_d3dContext != null)
{
_d3dContext.Dispose();
_d3dContext = null;
}
_d3dContext = context;
}

internal void UpdateTarget(RenderTargetView renderTargetView)
{
_renderTargetView = renderTargetView;
_currentRenderTargets[0] = _renderTargetView;
_currentDepthStencilView = _depthStencilView;

var resource = _renderTargetView.Resource;
using (var texture2D = new SharpDX.Direct3D11.Texture2D(resource.NativePointer))
{
var currentWidth = PresentationParameters.BackBufferWidth;
var currentHeight = PresentationParameters.BackBufferHeight;

if (currentWidth != texture2D.Description.Width &&
currentHeight != texture2D.Description.Height)
{
PresentationParameters.BackBufferWidth = texture2D.Description.Width;
PresentationParameters.BackBufferHeight = texture2D.Description.Height;

ComObject.Dispose(ref _depthStencilView);

using (var depthTexture = new SharpDX.Direct3D11.Texture2D(
_d3dDevice,
new Texture2DDescription()
{
Width = PresentationParameters.BackBufferWidth,
Height = PresentationParameters.BackBufferHeight,
ArraySize = 1,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
Format = SharpDX.DXGI.Format.D24_UNorm_S8_UInt,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = ResourceUsage.Default
}))
_depthStencilView = new DepthStencilView(_d3dDevice, depthTexture);

Viewport = new Viewport(0, 0, PresentationParameters.BackBufferWidth, PresentationParameters.BackBufferHeight);
}
}
}

#else

/// <summary>
/// Creates resources not tied the active graphics device.
Expand Down Expand Up @@ -693,7 +781,9 @@ internal void CreateSizeDependentResources()
_d2dContext.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Grayscale;
}

#endif // WINRT
#endif // !WINDOWS_PHONE

#endif // DIRECTX

public RasterizerState RasterizerState
{
Expand Down Expand Up @@ -887,11 +977,7 @@ protected virtual void Dispose(bool disposing)
GraphicsResource.DisposeAll();

#if DIRECTX
if (_swapChain != null)
{
_swapChain.Dispose();
_swapChain = null;
}

if (_renderTargetView != null)
{
_renderTargetView.Dispose();
Expand All @@ -902,11 +988,6 @@ protected virtual void Dispose(bool disposing)
_depthStencilView.Dispose();
_depthStencilView = null;
}
if (_bitmapTarget != null)
{
_bitmapTarget.Dispose();
_depthStencilView = null;
}

if (_d3dDevice != null)
{
Expand All @@ -918,6 +999,18 @@ protected virtual void Dispose(bool disposing)
_d3dContext.Dispose();
_d3dContext = null;
}

#if !WINDOWS_PHONE
if (_swapChain != null)
{
_swapChain.Dispose();
_swapChain = null;
}
if (_bitmapTarget != null)
{
_bitmapTarget.Dispose();
_depthStencilView = null;
}
if (_d2dDevice != null)
{
_d2dDevice.Dispose();
Expand All @@ -944,6 +1037,7 @@ protected virtual void Dispose(bool disposing)
_wicFactory.Dispose();
_wicFactory = null;
}
#endif

#endif // DIRECTX

Expand Down Expand Up @@ -991,7 +1085,7 @@ static internal void AddDisposeAction(Action disposeAction)

public void Present()
{
#if DIRECTX
#if DIRECTX && !WINDOWS_PHONE
// The application may optionally specify "dirty" or "scroll" rects to improve efficiency
// in certain scenarios. In this sample, however, we do not utilize those features.
var parameters = new SharpDX.DXGI.PresentParameters();
Expand All @@ -1003,7 +1097,8 @@ public void Present()
// The first argument instructs DXGI to block until VSync, putting the application
// to sleep until the next VSync. This ensures we don't waste any cycles rendering
// frames that will never be displayed to the screen.
_swapChain.Present(1, SharpDX.DXGI.PresentFlags.None, parameters);
lock (_d3dContext)
_swapChain.Present(1, PresentFlags.None, parameters);
}
catch (SharpDX.SharpDXException)
{
Expand Down Expand Up @@ -1334,9 +1429,28 @@ internal void ApplyRenderTargets(RenderTargetBinding[] renderTargets)
#if WINRT
internal void ResetRenderTargets()
{
if ( _d3dContext != null )
if (_d3dContext != null)
{
lock (_d3dContext)
_d3dContext.OutputMerger.SetTargets(_currentDepthStencilView, _currentRenderTargets);
{
var viewport = new SharpDX.Direct3D11.Viewport( _viewport.X, _viewport.Y,
_viewport.Width, _viewport.Height,
_viewport.MinDepth, _viewport.MaxDepth);
_d3dContext.Rasterizer.SetViewports(viewport);
_d3dContext.OutputMerger.SetTargets(_currentDepthStencilView, _currentRenderTargets);
}
}

Textures.Dirty();
SamplerStates.Dirty();
_depthStencilStateDirty = true;
_blendStateDirty = true;
_indexBufferDirty = true;
_vertexBufferDirty = true;
_pixelShaderDirty = true;
_vertexShaderDirty = true;
_rasterizerStateDirty = true;
_scissorRectangleDirty = true;
}
#endif

Expand Down

0 comments on commit b1368a2

Please sign in to comment.