diff --git a/PlatformSystems/ANX.PlatformSystem.PsVita/Properties/AssemblyInfo.cs b/PlatformSystems/ANX.PlatformSystem.PsVita/Properties/AssemblyInfo.cs index 48d743b3..0ce9b0aa 100644 --- a/PlatformSystems/ANX.PlatformSystem.PsVita/Properties/AssemblyInfo.cs +++ b/PlatformSystems/ANX.PlatformSystem.PsVita/Properties/AssemblyInfo.cs @@ -8,9 +8,9 @@ using System.Runtime.InteropServices; [assembly: AssemblyTitle("ANX.PlatformSystem.PsVita")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("ANX Developer Team")] [assembly: AssemblyProduct("ANX.PlatformSystem.PsVita")] -[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyCopyright("Copyright © ANX Developer Team 2012")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita.csproj b/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita.csproj index 640d946b..ee1f5270 100644 --- a/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita.csproj +++ b/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita.csproj @@ -38,8 +38,17 @@ + + + + + + + + + diff --git a/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_Linux.csproj b/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_Linux.csproj index ab5bf1aa..de315e9b 100644 --- a/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_Linux.csproj +++ b/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_Linux.csproj @@ -38,8 +38,17 @@ + + + + + + + + + diff --git a/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_PSVita.csproj b/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_PSVita.csproj index a7527b74..4810b106 100644 --- a/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_PSVita.csproj +++ b/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_PSVita.csproj @@ -38,8 +38,17 @@ + + + + + + + + + diff --git a/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_WindowsMetro.csproj b/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_WindowsMetro.csproj index b7c4e6a5..1924eabf 100644 --- a/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_WindowsMetro.csproj +++ b/RenderSystems/ANX.RenderSystem.PsVita/ANX.RenderSystem.PsVita_WindowsMetro.csproj @@ -40,8 +40,17 @@ + + + + + + + + + diff --git a/RenderSystems/ANX.RenderSystem.PsVita/Creator.cs b/RenderSystems/ANX.RenderSystem.PsVita/Creator.cs index 9d1eefd2..74fa8e1f 100644 --- a/RenderSystems/ANX.RenderSystem.PsVita/Creator.cs +++ b/RenderSystems/ANX.RenderSystem.PsVita/Creator.cs @@ -13,6 +13,7 @@ namespace ANX.RenderSystem.PsVita { public class Creator : IRenderSystemCreator { + #region Public public string Name { get @@ -36,6 +37,7 @@ namespace ANX.RenderSystem.PsVita return OSInformation.GetName() == PlatformName.PSVita; } } + #endregion #region RegisterCreator public void RegisterCreator(AddInSystemFactory factory) @@ -44,73 +46,93 @@ namespace ANX.RenderSystem.PsVita } #endregion - #region IRenderSystemCreator Member - + #region CreateGraphicsDevice public INativeGraphicsDevice CreateGraphicsDevice( PresentationParameters presentationParameters) { return new PsVitaGraphicsDevice(presentationParameters); } + #endregion + #region CreateIndexBuffer + public INativeIndexBuffer CreateIndexBuffer(GraphicsDevice graphics, + IndexBuffer managedBuffer, IndexElementSize size, int indexCount, + BufferUsage usage) + { + return new PsVitaIndexBuffer(managedBuffer, size, indexCount, usage); + } + #endregion + + #region CreateVertexBuffer + public INativeVertexBuffer CreateVertexBuffer(GraphicsDevice graphics, + VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration, + int vertexCount, BufferUsage usage) + { + return new PsVitaVertexBuffer(managedBuffer, vertexDeclaration, + vertexCount, usage); + } + #endregion + + #region CreateTexture public INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount) { - throw new NotImplementedException(); + return new PsVitaTexture2D(surfaceFormat, width, height, mipCount); } + #endregion + #region CreateRenderTarget public INativeRenderTarget2D CreateRenderTarget(GraphicsDevice graphics, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) { - throw new NotImplementedException(); - } - - public INativeIndexBuffer CreateIndexBuffer(GraphicsDevice graphics, - IndexBuffer managedBuffer, IndexElementSize size, int indexCount, - BufferUsage usage) - { - throw new NotImplementedException(); - } - - public INativeVertexBuffer CreateVertexBuffer(GraphicsDevice graphics, - VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration, - int vertexCount, BufferUsage usage) - { - throw new NotImplementedException(); + return new PsVitaRenderTarget2D(); } + #endregion + #region CreateEffect public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream byteCode) { - throw new NotImplementedException(); + return new PsVitaEffect(managedEffect, byteCode); } - + public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream vertexShaderByteCode, Stream pixelShaderByteCode) { - throw new NotImplementedException(); + return new PsVitaEffect(managedEffect, vertexShaderByteCode, + pixelShaderByteCode); } + #endregion + #region CreateBlendState public INativeBlendState CreateBlendState() { - throw new NotImplementedException(); + return new PsVitaBlendState(); } + #endregion + #region CreateRasterizerState public INativeRasterizerState CreateRasterizerState() { - throw new NotImplementedException(); + return new PsVitaRasterizerState(); } + #endregion + #region CreateDepthStencilState public INativeDepthStencilState CreateDepthStencilState() { - throw new NotImplementedException(); + return new PsVitaDepthStencilState(); } + #endregion + #region CreateSamplerState public INativeSamplerState CreateSamplerState() { - throw new NotImplementedException(); + return new PsVitaSamplerState(); } + #endregion public byte[] GetShaderByteCode(PreDefinedShader type) { @@ -121,7 +143,5 @@ namespace ANX.RenderSystem.PsVita { throw new NotImplementedException(); } - - #endregion } } diff --git a/RenderSystems/ANX.RenderSystem.PsVita/DatatypesMapping.cs b/RenderSystems/ANX.RenderSystem.PsVita/DatatypesMapping.cs new file mode 100644 index 00000000..49fc5489 --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.PsVita/DatatypesMapping.cs @@ -0,0 +1,37 @@ +using System; +using Sce.PlayStation.Core.Graphics; +using ANX.Framework.Graphics; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace ANX.RenderSystem.PsVita +{ + internal static class DatatypesMapping + { + #region SurfaceFormatToVitaPixelFormat + public static PixelFormat SurfaceFormatToVitaPixelFormat(SurfaceFormat format) + { + switch (format) + { + case SurfaceFormat.Color: + return PixelFormat.Rgba; + + case SurfaceFormat.Bgra4444: + return PixelFormat.Rgba4444; + + case SurfaceFormat.Bgr565: + return PixelFormat.Rgb565; + + case SurfaceFormat.Bgra5551: + return PixelFormat.Rgba5551; + + default: + throw new Exception("Can't convert surface format '" + format + + "' to psvita pixel format!"); + } + } + #endregion + } +} diff --git a/RenderSystems/ANX.RenderSystem.PsVita/PsVitaBlendState.cs b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaBlendState.cs new file mode 100644 index 00000000..ed57bae2 --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaBlendState.cs @@ -0,0 +1,231 @@ +using System; +using ANX.Framework; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using SceGraphics = Sce.PlayStation.Core.Graphics; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace ANX.RenderSystem.PsVita +{ + public class PsVitaBlendState : INativeBlendState + { + #region Public + public bool IsBound + { + get; + private set; + } + + public BlendFunction AlphaBlendFunction + { + set; + private get; + } + + public BlendFunction ColorBlendFunction + { + set; + private get; + } + + public Blend AlphaSourceBlend + { + set; + private get; + } + + public Blend AlphaDestinationBlend + { + set; + private get; + } + + public Blend ColorSourceBlend + { + set; + private get; + } + + public Blend ColorDestinationBlend + { + set; + private get; + } + + public ColorWriteChannels ColorWriteChannels + { + set; + private get; + } + + public ColorWriteChannels ColorWriteChannels1 + { + set; + private get; + } + + public ColorWriteChannels ColorWriteChannels2 + { + set; + private get; + } + + public ColorWriteChannels ColorWriteChannels3 + { + set; + private get; + } + + public Color BlendFactor + { + set; + private get; + } + + public int MultiSampleMask + { + set; + private get; + } + #endregion + + #region Constructor + internal PsVitaBlendState() + { + IsBound = false; + } + #endregion + + #region Apply (TODO) + public void Apply(GraphicsDevice graphicsDevice) + { + IsBound = true; + + var context = PsVitaGraphicsDevice.Current.NativeContext; + context.Enable(SceGraphics.EnableMode.Blend); + + context.SetBlendFuncRgb(TranslateBlendFunction(ColorBlendFunction), + TranslateBlend(ColorSourceBlend), TranslateBlend(ColorDestinationBlend)); + + context.SetBlendFuncAlpha(TranslateBlendFunction(AlphaBlendFunction), + TranslateBlend(AlphaSourceBlend), TranslateBlend(AlphaDestinationBlend)); + + SetColorWriteChannel(context, ColorWriteChannels); + + // TODO + //SetColorWriteChannel(context, ColorWriteChannels1); + //SetColorWriteChannel(context, ColorWriteChannels2); + //SetColorWriteChannel(context, ColorWriteChannels3); + + //GL.BlendColor(BlendFactor.R * DatatypesMapping.ColorMultiplier, + // BlendFactor.G * DatatypesMapping.ColorMultiplier, + // BlendFactor.B * DatatypesMapping.ColorMultiplier, + // BlendFactor.A * DatatypesMapping.ColorMultiplier); + //ErrorHelper.Check("BlendColor"); + + // TODO: multi sample mask + } + #endregion + + #region Release + public void Release() + { + IsBound = false; + } + #endregion + + #region Dispose + public void Dispose() + { + } + #endregion + + #region SetColorWriteChannel + private void SetColorWriteChannel(SceGraphics.GraphicsContext context, + ColorWriteChannels channels) + { + var mask = SceGraphics.ColorMask.None; + if((channels & ColorWriteChannels.Red) != 0) + { + mask |= SceGraphics.ColorMask.R; + } + if((channels & ColorWriteChannels.Green) != 0) + { + mask |= SceGraphics.ColorMask.G; + } + if((channels & ColorWriteChannels.Blue) != 0) + { + mask |= SceGraphics.ColorMask.B; + } + if((channels & ColorWriteChannels.Alpha) != 0) + { + mask |= SceGraphics.ColorMask.A; + } + + context.SetColorMask(mask); + } + #endregion + + #region TranslateBlend + private SceGraphics.BlendFuncFactor TranslateBlend(Blend blending) + { + switch (blending) + { + case Blend.SourceAlpha: + return SceGraphics.BlendFuncFactor.SrcAlpha; + + case Blend.DestinationAlpha: + return SceGraphics.BlendFuncFactor.DstAlpha; + + case Blend.DestinationColor: + return SceGraphics.BlendFuncFactor.DstColor; + + case Blend.InverseDestinationAlpha: + return SceGraphics.BlendFuncFactor.OneMinusDstAlpha; + + case Blend.InverseDestinationColor: + return SceGraphics.BlendFuncFactor.OneMinusDstColor; + + case Blend.InverseSourceAlpha: + return SceGraphics.BlendFuncFactor.OneMinusSrcAlpha; + + case Blend.One: + return SceGraphics.BlendFuncFactor.One; + + case Blend.SourceAlphaSaturation: + return SceGraphics.BlendFuncFactor.SrcAlphaSaturate; + + case Blend.Zero: + return SceGraphics.BlendFuncFactor.Zero; + + default: + throw new ArgumentException("Unable to translate SourceBlend '" + + blending + "' to PsVita BlendFuncFactor."); + } + } + #endregion + + #region TranslateBlendFunction + private SceGraphics.BlendFuncMode TranslateBlendFunction(BlendFunction func) + { + switch (func) + { + case BlendFunction.Add: + return SceGraphics.BlendFuncMode.Add; + + case BlendFunction.Subtract: + return SceGraphics.BlendFuncMode.Subtract; + + case BlendFunction.ReverseSubtract: + return SceGraphics.BlendFuncMode.ReverseSubtract; + } + + throw new ArgumentException("Unable to translate BlendFunction '" + + func + "' to PsVita BlendFuncMode."); + } + #endregion + } +} diff --git a/RenderSystems/ANX.RenderSystem.PsVita/PsVitaDepthStencilState.cs b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaDepthStencilState.cs new file mode 100644 index 00000000..3cdab377 --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaDepthStencilState.cs @@ -0,0 +1,298 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using SceGraphics = Sce.PlayStation.Core.Graphics; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace ANX.RenderSystem.PsVita +{ + public class PsVitaDepthStencilState : INativeDepthStencilState + { + #region Public + public bool IsBound + { + get; + private set; + } + + public bool DepthBufferEnable + { + set; + private get; + } + + public CompareFunction DepthBufferFunction + { + set; + private get; + } + + public bool DepthBufferWriteEnable + { + set; + private get; + } + + public bool StencilEnable + { + set; + private get; + } + + public CompareFunction StencilFunction + { + set; + private get; + } + + public int StencilMask + { + set; + private get; + } + + public StencilOperation StencilDepthBufferFail + { + set; + private get; + } + + public StencilOperation StencilFail + { + set; + private get; + } + + public StencilOperation StencilPass + { + set; + private get; + } + + public StencilOperation CounterClockwiseStencilDepthBufferFail + { + set; + private get; + } + + public StencilOperation CounterClockwiseStencilFail + { + set; + private get; + } + + public CompareFunction CounterClockwiseStencilFunction + { + set; + private get; + } + + public StencilOperation CounterClockwiseStencilPass + { + set; + private get; + } + + public bool TwoSidedStencilMode + { + set; + private get; + } + + public int ReferenceStencil + { + set; + private get; + } + + public int StencilWriteMask + { + set; + private get; + } + #endregion + + #region Constructor + internal PsVitaDepthStencilState() + { + IsBound = false; + } + #endregion + + #region Apply + public void Apply(GraphicsDevice graphicsDevice) + { + IsBound = true; + var context = PsVitaGraphicsDevice.Current.NativeContext; + + #region Depth + if (DepthBufferEnable) + { + context.Enable(SceGraphics.EnableMode.DepthTest); + } + else + { + context.Disable(SceGraphics.EnableMode.DepthTest); + } + + context.SetDepthFunc(TranslateDepthFunction(DepthBufferFunction), + DepthBufferWriteEnable); + #endregion + + #region Stencil + if (StencilEnable) + { + context.Enable(SceGraphics.EnableMode.StencilTest); + } + else + { + context.Disable(SceGraphics.EnableMode.StencilTest); + } + + if (TwoSidedStencilMode) + { + context.SetStencilOpFront(TranslateStencilOp(StencilFail), + TranslateStencilOp(StencilDepthBufferFail), + TranslateStencilOp(StencilPass)); + + context.SetStencilOpBack(TranslateStencilOp(CounterClockwiseStencilFail), + TranslateStencilOp(CounterClockwiseStencilDepthBufferFail), + TranslateStencilOp(CounterClockwiseStencilPass)); + + context.SetStencilFuncFront( + TranslateStencilFunction(StencilFunction), + ReferenceStencil, StencilMask, StencilWriteMask); + + context.SetStencilFuncBack( + TranslateStencilFunction(CounterClockwiseStencilFunction), + ReferenceStencil, StencilMask, StencilWriteMask); + } + else + { + context.SetStencilOp(TranslateStencilOp(StencilFail), + TranslateStencilOp(StencilDepthBufferFail), + TranslateStencilOp(StencilPass)); + + context.SetStencilFunc(TranslateStencilFunction(StencilFunction), + ReferenceStencil, StencilMask, StencilWriteMask); + } + #endregion + } + #endregion + + #region TranslateStencilOp + private SceGraphics.StencilOpMode TranslateStencilOp(StencilOperation operation) + { + switch (operation) + { + default: + case StencilOperation.Decrement: + return SceGraphics.StencilOpMode.Decr; + + case StencilOperation.DecrementSaturation: + return SceGraphics.StencilOpMode.DecrWrap; + + case StencilOperation.Increment: + return SceGraphics.StencilOpMode.Incr; + + case StencilOperation.IncrementSaturation: + return SceGraphics.StencilOpMode.IncrWrap; + + case StencilOperation.Invert: + return SceGraphics.StencilOpMode.Invert; + + case StencilOperation.Keep: + return SceGraphics.StencilOpMode.Keep; + + case StencilOperation.Replace: + return SceGraphics.StencilOpMode.Replace; + + case StencilOperation.Zero: + return SceGraphics.StencilOpMode.Zero; + } + } + #endregion + + #region TranslateDepthFunction + private SceGraphics.DepthFuncMode TranslateDepthFunction(CompareFunction func) + { + switch (func) + { + default: + case CompareFunction.Always: + return SceGraphics.DepthFuncMode.Always; + + case CompareFunction.Equal: + return SceGraphics.DepthFuncMode.Equal; + + case CompareFunction.Greater: + return SceGraphics.DepthFuncMode.Greater; + + case CompareFunction.GreaterEqual: + return SceGraphics.DepthFuncMode.GEqual; + + case CompareFunction.Less: + return SceGraphics.DepthFuncMode.Less; + + case CompareFunction.LessEqual: + return SceGraphics.DepthFuncMode.LEqual; + + case CompareFunction.Never: + return SceGraphics.DepthFuncMode.Never; + + case CompareFunction.NotEqual: + return SceGraphics.DepthFuncMode.NotEequal; + } + } + #endregion + + #region TranslateStencilFunction + private SceGraphics.StencilFuncMode TranslateStencilFunction(CompareFunction func) + { + switch (func) + { + default: + case CompareFunction.Always: + return SceGraphics.StencilFuncMode.Always; + + case CompareFunction.Equal: + return SceGraphics.StencilFuncMode.Equal; + + case CompareFunction.Greater: + return SceGraphics.StencilFuncMode.Greater; + + case CompareFunction.GreaterEqual: + return SceGraphics.StencilFuncMode.GEqual; + + case CompareFunction.Less: + return SceGraphics.StencilFuncMode.Less; + + case CompareFunction.LessEqual: + return SceGraphics.StencilFuncMode.LEqual; + + case CompareFunction.Never: + return SceGraphics.StencilFuncMode.Never; + + case CompareFunction.NotEqual: + return SceGraphics.StencilFuncMode.NotEequal; + } + } + #endregion + + #region Release + public void Release() + { + IsBound = false; + } + #endregion + + #region Dispose + public void Dispose() + { + } + #endregion + } +} diff --git a/RenderSystems/ANX.RenderSystem.PsVita/PsVitaEffect.cs b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaEffect.cs new file mode 100644 index 00000000..b67b2563 --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaEffect.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.IO; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using Sce.PlayStation.Core.Graphics; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace ANX.RenderSystem.PsVita +{ + public class PsVitaEffect : INativeEffect + { + #region Private + private ShaderProgram nativeShader; + #endregion + + #region Public + public IEnumerable Techniques + { + get + { + throw new NotImplementedException(); + } + } + + public IEnumerable Parameters + { + get + { + throw new NotImplementedException(); + } + } + #endregion + + #region Constructor + public PsVitaEffect(Effect managedEffect, Stream shaderByteStream) + { + int length = (int)(shaderByteStream.Length - shaderByteStream.Position); + byte[] shaderByteData = new byte[length]; + shaderByteStream.Read(shaderByteData, 0, length); + nativeShader = new ShaderProgram(shaderByteData); + } + + public PsVitaEffect(Effect managedEffect, Stream vertexShaderByteStream, + Stream pixelShaderByteStream) + { + int vertexBytesLength = (int)(vertexShaderByteStream.Length - + vertexShaderByteStream.Position); + byte[] vertexShaderByteData = new byte[vertexBytesLength]; + vertexShaderByteStream.Read(vertexShaderByteData, 0, vertexBytesLength); + + int fragmentBytesLength = (int)(pixelShaderByteStream.Length - + pixelShaderByteStream.Position); + byte[] fragmentShaderByteData = new byte[fragmentBytesLength]; + pixelShaderByteStream.Read(fragmentShaderByteData, 0, fragmentBytesLength); + + nativeShader = new ShaderProgram(vertexShaderByteData, fragmentShaderByteData); + } + #endregion + + #region Apply + public void Apply(GraphicsDevice graphicsDevice) + { + throw new NotImplementedException(); + } + #endregion + + #region Dispose + public void Dispose() + { + if (nativeShader != null) + { + nativeShader.Dispose(); + nativeShader = null; + } + } + #endregion + } +} diff --git a/RenderSystems/ANX.RenderSystem.PsVita/PsVitaGraphicsDevice.cs b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaGraphicsDevice.cs index 0431f1f5..3c7dc70b 100644 --- a/RenderSystems/ANX.RenderSystem.PsVita/PsVitaGraphicsDevice.cs +++ b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaGraphicsDevice.cs @@ -4,13 +4,28 @@ using ANX.Framework.Graphics; using ANX.Framework.NonXNA; using Sce.PlayStation.Core.Graphics; +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + namespace ANX.RenderSystem.PsVita { public class PsVitaGraphicsDevice : INativeGraphicsDevice { - private GraphicsContext context; + internal static PsVitaGraphicsDevice Current + { + get; + private set; + } + private uint? lastClearColor; + internal GraphicsContext NativeContext + { + get; + private set; + } + public bool VSync { get @@ -25,8 +40,9 @@ namespace ANX.RenderSystem.PsVita public PsVitaGraphicsDevice(PresentationParameters presentationParameters) { + Current = this; // TODO - context = new GraphicsContext(presentationParameters.BackBufferWidth, + NativeContext = new GraphicsContext(presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight, PixelFormat.Rgba, PixelFormat.Depth24Stencil8, MultiSampleMode.None); } @@ -41,15 +57,15 @@ namespace ANX.RenderSystem.PsVita lastClearColor != newClearColor) { lastClearColor = newClearColor; - context.SetClearColor(color.R, color.G, color.B, color.A); + NativeContext.SetClearColor(color.R, color.G, color.B, color.A); } - context.Clear(ClearMask.Color | ClearMask.Depth); + NativeContext.Clear(ClearMask.Color | ClearMask.Depth); } public void Clear(ClearOptions options, Vector4 color, float depth, int stencil) { - context.SetClearColor(color.X, color.Y, color.Z, color.W); + NativeContext.SetClearColor(color.X, color.Y, color.Z, color.W); ClearMask mask = ClearMask.None; if ((options | ClearOptions.Target) == options) @@ -65,16 +81,16 @@ namespace ANX.RenderSystem.PsVita mask |= ClearMask.Depth; } - context.SetClearDepth(depth); - context.SetClearStencil(stencil); - context.Clear(mask); + NativeContext.SetClearDepth(depth); + NativeContext.SetClearStencil(stencil); + NativeContext.Clear(mask); } #endregion #region Present public void Present() { - context.SwapBuffers(); + NativeContext.SwapBuffers(); } #endregion @@ -126,7 +142,7 @@ namespace ANX.RenderSystem.PsVita #region SetViewport public void SetViewport(Viewport viewport) { - context.SetViewport(viewport.X, viewport.Y, viewport.Width, viewport.Height); + NativeContext.SetViewport(viewport.X, viewport.Y, viewport.Width, viewport.Height); } #endregion @@ -161,8 +177,8 @@ namespace ANX.RenderSystem.PsVita #region Dispose public void Dispose() { - context.Dispose(); - context = null; + NativeContext.Dispose(); + NativeContext = null; } #endregion } diff --git a/RenderSystems/ANX.RenderSystem.PsVita/PsVitaIndexBuffer.cs b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaIndexBuffer.cs new file mode 100644 index 00000000..c16fc628 --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaIndexBuffer.cs @@ -0,0 +1,169 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA.RenderSystem; +using VitaIndexBuffer = Sce.PlayStation.Core.Graphics.VertexBuffer; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace ANX.RenderSystem.PsVita +{ + public class PsVitaIndexBuffer : INativeIndexBuffer + { + #region Private + private IndexBuffer managedBuffer; + private VitaIndexBuffer nativeBuffer; + + private int indexCount; + + internal IndexElementSize elementSize; + + internal bool IsDisposed; + #endregion + + #region Constructor + internal PsVitaIndexBuffer(IndexBuffer setManagedBuffer, + IndexElementSize setElementSize, int setIndexCount, BufferUsage setUsage) + { + managedBuffer = setManagedBuffer; + indexCount = setIndexCount; + elementSize = setElementSize; + + CreateBuffer(); + } + #endregion + + #region CreateBuffer + private void CreateBuffer() + { + nativeBuffer = new VitaIndexBuffer(0, indexCount); + } + #endregion + + #region RecreateData + internal void RecreateData() + { + CreateBuffer(); + } + #endregion + + #region SetData + public void SetData(GraphicsDevice graphicsDevice, T[] data) + where T : struct + { + BufferData(data, 0); + } + #endregion + + #region SetData + public void SetData(GraphicsDevice graphicsDevice, T[] data, + int startIndex, int elementCount) where T : struct + { + if (startIndex != 0 || + elementCount != data.Length) + { + T[] subArray = new T[elementCount]; + Array.Copy(data, startIndex, subArray, 0, elementCount); + BufferData(subArray, 0); + } + else + { + BufferData(data, 0); + } + } + #endregion + + #region SetData + public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, + T[] data, int startIndex, int elementCount) where T : struct + { + if (startIndex != 0 || + elementCount != data.Length) + { + T[] subArray = new T[elementCount]; + Array.Copy(data, startIndex, subArray, 0, elementCount); + BufferData(subArray, offsetInBytes); + } + else + { + BufferData(data, offsetInBytes); + } + } + #endregion + + #region BufferData (private helper) + private void BufferData(T[] data, int offset) where T : struct + { + if(data is uint == false && + data is ushort == false) + { + throw new InvalidOperationException( + "The index buffer data can only be uint or ushort!"); + } + + if(data is ushort) + { + nativeBuffer.SetIndices(data as ushort[], offset, 0, data.Length); + } + else if (data is uint) + { + uint[] convertData = data as uint[]; + ushort[] newIndices = new ushort[convertData.Length]; + for (int index = 0; index < convertData.Length; index++) + { + newIndices[index] = (ushort)convertData[index]; + } + + nativeBuffer.SetIndices(newIndices, offset, 0, data.Length); + } + } + #endregion + + #region GetData + public void GetData(T[] data) where T : struct + { + throw new NotImplementedException(); + } + #endregion + + #region GetData + public void GetData(T[] data, int startIndex, int elementCount) + where T : struct + { + throw new NotImplementedException(); + } + #endregion + + #region GetData + public void GetData(int offsetInBytes, T[] data, int startIndex, + int elementCount) where T : struct + { + throw new NotImplementedException(); + } + #endregion + + #region Dispose + /// + /// Dispose the native index buffer data. + /// + public void Dispose() + { + if (IsDisposed == false) + { + IsDisposed = true; + DisposeResource(); + } + } + + internal void DisposeResource() + { + if (nativeBuffer != null) + { + nativeBuffer.Dispose(); + nativeBuffer = null; + } + } + #endregion + } +} diff --git a/RenderSystems/ANX.RenderSystem.PsVita/PsVitaRasterizerState.cs b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaRasterizerState.cs new file mode 100644 index 00000000..b3b37358 --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaRasterizerState.cs @@ -0,0 +1,70 @@ +using System; +using ANX.Framework.NonXNA; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace ANX.RenderSystem.PsVita +{ + public class PsVitaRasterizerState : INativeRasterizerState + { + #region INativeRasterizerState Member + + public void Apply(Framework.Graphics.GraphicsDevice graphicsDevice) + { + throw new NotImplementedException(); + } + + public void Release() + { + throw new NotImplementedException(); + } + + public bool IsBound + { + get { throw new NotImplementedException(); } + } + + public Framework.Graphics.CullMode CullMode + { + set { throw new NotImplementedException(); } + } + + public float DepthBias + { + set { throw new NotImplementedException(); } + } + + public Framework.Graphics.FillMode FillMode + { + set { throw new NotImplementedException(); } + } + + public bool MultiSampleAntiAlias + { + set { throw new NotImplementedException(); } + } + + public bool ScissorTestEnable + { + set { throw new NotImplementedException(); } + } + + public float SlopeScaleDepthBias + { + set { throw new NotImplementedException(); } + } + + #endregion + + #region IDisposable Member + + public void Dispose() + { + throw new NotImplementedException(); + } + + #endregion + } +} diff --git a/RenderSystems/ANX.RenderSystem.PsVita/PsVitaRenderTarget2D.cs b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaRenderTarget2D.cs new file mode 100644 index 00000000..56ce3403 --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaRenderTarget2D.cs @@ -0,0 +1,23 @@ +using System; +using ANX.Framework.NonXNA.RenderSystem; +using VitaRenderTarget = Sce.PlayStation.Core.Graphics.RenderTarget; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace ANX.RenderSystem.PsVita +{ + public class PsVitaRenderTarget2D : PsVitaTexture2D, INativeRenderTarget2D + { + // TODO + public PsVitaRenderTarget2D() + : base(Framework.Graphics.SurfaceFormat.Color, 100, 100, 0) + { + } + + public override void Dispose() + { + } + } +} diff --git a/RenderSystems/ANX.RenderSystem.PsVita/PsVitaSamplerState.cs b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaSamplerState.cs new file mode 100644 index 00000000..adecb9be --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaSamplerState.cs @@ -0,0 +1,75 @@ +using System; +using ANX.Framework.NonXNA; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace ANX.RenderSystem.PsVita +{ + public class PsVitaSamplerState : INativeSamplerState + { + #region INativeSamplerState Member + + public void Apply(Framework.Graphics.GraphicsDevice graphicsDevice, int index) + { + throw new NotImplementedException(); + } + + public void Release() + { + throw new NotImplementedException(); + } + + public bool IsBound + { + get { throw new NotImplementedException(); } + } + + public Framework.Graphics.TextureAddressMode AddressU + { + set { throw new NotImplementedException(); } + } + + public Framework.Graphics.TextureAddressMode AddressV + { + set { throw new NotImplementedException(); } + } + + public Framework.Graphics.TextureAddressMode AddressW + { + set { throw new NotImplementedException(); } + } + + public Framework.Graphics.TextureFilter Filter + { + set { throw new NotImplementedException(); } + } + + public int MaxAnisotropy + { + set { throw new NotImplementedException(); } + } + + public int MaxMipLevel + { + set { throw new NotImplementedException(); } + } + + public float MipMapLevelOfDetailBias + { + set { throw new NotImplementedException(); } + } + + #endregion + + #region IDisposable Member + + public void Dispose() + { + throw new NotImplementedException(); + } + + #endregion + } +} diff --git a/RenderSystems/ANX.RenderSystem.PsVita/PsVitaTexture2D.cs b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaTexture2D.cs new file mode 100644 index 00000000..c39ede4d --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.PsVita/PsVitaTexture2D.cs @@ -0,0 +1,113 @@ +using System; +using System.IO; +using ANX.Framework; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA.RenderSystem; +using VitaTexture2D = Sce.PlayStation.Core.Graphics.Texture2D; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace ANX.RenderSystem.PsVita +{ + public class PsVitaTexture2D : INativeTexture2D + { + #region Private + private VitaTexture2D nativeTexture; + #endregion + + #region Constructor + public PsVitaTexture2D(SurfaceFormat surfaceFormat, int width, int height, + int mipCount) + { + nativeTexture = new VitaTexture2D(width, height, mipCount > 0, + DatatypesMapping.SurfaceFormatToVitaPixelFormat(surfaceFormat)); + } + #endregion + + #region SaveAsJpeg + public void SaveAsJpeg(Stream stream, int width, int height) + { + throw new NotImplementedException(); + } + #endregion + + #region SaveAsPng + public void SaveAsPng(Stream stream, int width, int height) + { + throw new NotImplementedException(); + } + #endregion + + #region GetData + public void GetData(int level, Rectangle? rect, T[] data, int startIndex, + int elementCount) where T : struct + { + throw new NotImplementedException(); + } + + public void GetData(T[] data) where T : struct + { + throw new NotImplementedException(); + } + + public void GetData(T[] data, int startIndex, int elementCount) where T : struct + { + throw new NotImplementedException(); + } + #endregion + + #region SetData + public void SetData(int level, Framework.Rectangle? rect, T[] data, + int startIndex, int elementCount) where T : struct + { + T[] subArray = new T[elementCount]; + Array.Copy(data, startIndex, subArray, 0, elementCount); + + if(rect.HasValue) + { + nativeTexture.SetPixels(level, subArray, rect.Value.X, rect.Value.Y, + rect.Value.Width, rect.Value.Height); + } + else + { + nativeTexture.SetPixels(level, subArray); + } + } + + public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct + { + nativeTexture.SetPixels(0, data); + } + + public void SetData(GraphicsDevice graphicsDevice, T[] data, + int startIndex, int elementCount) where T : struct + { + T[] subArray = new T[elementCount]; + Array.Copy(data, startIndex, subArray, 0, elementCount); + nativeTexture.SetPixels(0, subArray); + } + + public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, + T[] data, int startIndex, int elementCount) where T : struct + { + T[] subArray = new T[elementCount]; + Array.Copy(data, startIndex, subArray, 0, elementCount); + // TODO: is 0 okay for pitch? + nativeTexture.SetPixels(0, subArray, offsetInBytes, 0); + } + #endregion + + #region Dispose + public virtual void Dispose() + { + if (nativeTexture != null) + { + nativeTexture.Dispose(); + nativeTexture = null; + } + } + #endregion + } +}