From df1f49462f49f5b94d9205372914c5906bd0ec79 Mon Sep 17 00:00:00 2001 From: Glatzemann Date: Fri, 14 Sep 2012 06:19:05 +0000 Subject: [PATCH] renamed ANX.RenderSystem.Windows.GL3 to ANX.RenderSystem.GL3 as it is not windows specific (it runs on MacOs X, Linux and Windows) --- .../ANX.Framework.Content.Pipeline.csproj | 4 +- .../Processors/EffectProcessor.cs | 2 +- ...ramework.ContentPipeline.Extensions.csproj | 8 +- .../GL3_EffectProcessor.cs | 2 +- ANX.Framework.sln | 26 +- ANX.Framework/Properties/AssemblyInfo.cs | 2 +- Installer/anx.wxs | 4 +- .../ANX.RenderSystem.GL3.csproj | 90 +++ .../ANX.Framework.GL3/BlendStateGL3.cs | 353 +++++++++++ RenderSystems/ANX.Framework.GL3/Creator.cs | 347 +++++++++++ .../ANX.Framework.GL3/DepthStencilStateGL3.cs | 400 ++++++++++++ RenderSystems/ANX.Framework.GL3/EffectGL3.cs | 298 +++++++++ .../ANX.Framework.GL3/EffectParameterGL3.cs | 569 ++++++++++++++++++ .../ANX.Framework.GL3/EffectPassGL3.cs | 20 + .../ANX.Framework.GL3/EffectTechniqueGL3.cs | 88 +++ .../ANX.Framework.GL3/ErrorHelper.cs | 30 + .../GraphicsDeviceWindowsGL3.cs | 458 ++++++++++++++ .../Helpers/DatatypesMapping.cs | 299 +++++++++ .../Helpers/GraphicsResourceManager.cs | 195 ++++++ .../ANX.Framework.GL3/Helpers/LinuxInterop.cs | 118 ++++ .../Helpers/WindowsInterop.cs | 69 +++ .../ANX.Framework.GL3/IndexBufferGL3.cs | 264 ++++++++ .../ANX.Framework.GL3/OcclusionQueryGL3.cs | 73 +++ .../Properties/AssemblyInfo.cs | 38 ++ .../ANX.Framework.GL3/RasterizerStateGL3.cs | 218 +++++++ .../ANX.Framework.GL3/RenderTarget2DGL3.cs | 144 +++++ .../ANX.Framework.GL3/SamplerStateGL3.cs | 139 +++++ .../ANX.Framework.GL3/ShaderAttributeGL3.cs | 81 +++ .../ANX.Framework.GL3/ShaderByteCode.cs | 437 ++++++++++++++ RenderSystems/ANX.Framework.GL3/ShaderData.cs | 30 + .../ANX.Framework.GL3/ShaderHelper.cs | 362 +++++++++++ .../SupportedPlatformsImpl.cs | 28 + .../ANX.Framework.GL3/Texture2DGL3.cs | 339 +++++++++++ .../ANX.Framework.GL3/VertexBufferGL3.cs | 307 ++++++++++ .../BasicEffectSample.csproj | 4 - .../DualTextureSample.csproj | 4 - .../ModelSample/ModelSample.csproj | 4 - .../ModelSample/Properties/AssemblyInfo.cs | 2 +- Samples/Primitives/Primitives.csproj | 4 - Samples/RenderTarget/RenderTarget.csproj | 4 - Samples/SimpleSprite/SimpleSprite.csproj | 4 - Samples/TextRendering/TextRendering.csproj | 4 - .../WindowsFormsEditor.csproj | 4 - Samples/WindowsGame/WindowsGame.csproj | 4 - Samples/WpfEditor/WpfEditor.csproj | 4 - Support/WaveUtils/ALFormat.cs | 10 + Support/WaveUtils/ALaw.cs | 125 ++++ Support/WaveUtils/IEEEFloat.cs | 40 ++ Support/WaveUtils/MsAdpcm.cs | 141 +++++ Support/WaveUtils/MuLaw.cs | 114 ++++ Support/WaveUtils/Properties/AssemblyInfo.cs | 36 ++ Support/WaveUtils/WaveConverter.cs | 50 ++ Support/WaveUtils/WaveFile.cs | 162 +++++ Support/WaveUtils/WaveFormat.cs | 33 + Support/WaveUtils/WaveInfo.cs | 36 ++ Support/WaveUtils/WaveUtils.csproj | 65 ++ Support/WaveUtils/WaveUtils_Linux.csproj | 64 ++ Support/WaveUtils/WaveUtils_PSVita.csproj | 65 ++ .../WaveUtils/WaveUtils_WindowsMetro.csproj | 70 +++ .../ANX.ContentCompiler.GUI.csproj | 4 - .../Platforms/MetroConverter.cs | 2 +- Tools/StockShaderCodeGenerator/Compiler.cs | 4 +- .../StockShaderCodeGenerator.csproj | 8 +- shader/GL3/build.xml | 16 +- 64 files changed, 6845 insertions(+), 84 deletions(-) create mode 100644 RenderSystems/ANX.Framework.GL3/ANX.RenderSystem.GL3.csproj create mode 100644 RenderSystems/ANX.Framework.GL3/BlendStateGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/Creator.cs create mode 100644 RenderSystems/ANX.Framework.GL3/DepthStencilStateGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/EffectGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/EffectParameterGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/EffectPassGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/EffectTechniqueGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/ErrorHelper.cs create mode 100644 RenderSystems/ANX.Framework.GL3/GraphicsDeviceWindowsGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/Helpers/DatatypesMapping.cs create mode 100644 RenderSystems/ANX.Framework.GL3/Helpers/GraphicsResourceManager.cs create mode 100644 RenderSystems/ANX.Framework.GL3/Helpers/LinuxInterop.cs create mode 100644 RenderSystems/ANX.Framework.GL3/Helpers/WindowsInterop.cs create mode 100644 RenderSystems/ANX.Framework.GL3/IndexBufferGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/OcclusionQueryGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/Properties/AssemblyInfo.cs create mode 100644 RenderSystems/ANX.Framework.GL3/RasterizerStateGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/RenderTarget2DGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/SamplerStateGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/ShaderAttributeGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/ShaderByteCode.cs create mode 100644 RenderSystems/ANX.Framework.GL3/ShaderData.cs create mode 100644 RenderSystems/ANX.Framework.GL3/ShaderHelper.cs create mode 100644 RenderSystems/ANX.Framework.GL3/SupportedPlatformsImpl.cs create mode 100644 RenderSystems/ANX.Framework.GL3/Texture2DGL3.cs create mode 100644 RenderSystems/ANX.Framework.GL3/VertexBufferGL3.cs create mode 100644 Support/WaveUtils/ALFormat.cs create mode 100644 Support/WaveUtils/ALaw.cs create mode 100644 Support/WaveUtils/IEEEFloat.cs create mode 100644 Support/WaveUtils/MsAdpcm.cs create mode 100644 Support/WaveUtils/MuLaw.cs create mode 100644 Support/WaveUtils/Properties/AssemblyInfo.cs create mode 100644 Support/WaveUtils/WaveConverter.cs create mode 100644 Support/WaveUtils/WaveFile.cs create mode 100644 Support/WaveUtils/WaveFormat.cs create mode 100644 Support/WaveUtils/WaveInfo.cs create mode 100644 Support/WaveUtils/WaveUtils.csproj create mode 100644 Support/WaveUtils/WaveUtils_Linux.csproj create mode 100644 Support/WaveUtils/WaveUtils_PSVita.csproj create mode 100644 Support/WaveUtils/WaveUtils_WindowsMetro.csproj diff --git a/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline.csproj b/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline.csproj index 524d7b86..b6b467fa 100644 --- a/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline.csproj +++ b/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline.csproj @@ -192,9 +192,9 @@ {6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35} ANX.Framework - + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 + ANX.RenderSystem.GL3 {1986B0ED-3D28-4FEE-82D0-BCC39C87C18C} diff --git a/ANX.Framework.Content.Pipeline/Processors/EffectProcessor.cs b/ANX.Framework.Content.Pipeline/Processors/EffectProcessor.cs index b74d1a2d..d8d1fafc 100644 --- a/ANX.Framework.Content.Pipeline/Processors/EffectProcessor.cs +++ b/ANX.Framework.Content.Pipeline/Processors/EffectProcessor.cs @@ -6,7 +6,7 @@ using System.Text; using ANX.Framework.Content.Pipeline.Graphics; using System.IO; using System.ComponentModel; -using ANX.RenderSystem.Windows.GL3; +using ANX.RenderSystem.GL3; #endregion diff --git a/ANX.Framework.ContentPipeline/ANX.Framework.ContentPipeline.Extensions.csproj b/ANX.Framework.ContentPipeline/ANX.Framework.ContentPipeline.Extensions.csproj index 1da64fc0..9bf3b6c9 100644 --- a/ANX.Framework.ContentPipeline/ANX.Framework.ContentPipeline.Extensions.csproj +++ b/ANX.Framework.ContentPipeline/ANX.Framework.ContentPipeline.Extensions.csproj @@ -68,14 +68,14 @@ {A4D3AD34-E49C-4142-8620-2AFF44ED6719} ANX.BaseDirectX + + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} + ANX.RenderSystem.GL3 + {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - diff --git a/ANX.Framework.ContentPipeline/GL3_EffectProcessor.cs b/ANX.Framework.ContentPipeline/GL3_EffectProcessor.cs index 82fbe249..08a9adb8 100644 --- a/ANX.Framework.ContentPipeline/GL3_EffectProcessor.cs +++ b/ANX.Framework.ContentPipeline/GL3_EffectProcessor.cs @@ -16,7 +16,7 @@ using Microsoft.Xna.Framework.Content.Pipeline.Processors; using TInput = Microsoft.Xna.Framework.Content.Pipeline.Graphics.EffectContent; using TOutput = Microsoft.Xna.Framework.Content.Pipeline.Processors.CompiledEffectContent; -using ANX.RenderSystem.Windows.GL3; +using ANX.RenderSystem.GL3; using System.Text; namespace ANX.Framework.ContentPipeline diff --git a/ANX.Framework.sln b/ANX.Framework.sln index e42d01a6..376a9dbd 100644 --- a/ANX.Framework.sln +++ b/ANX.Framework.sln @@ -79,8 +79,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "XNA", "XNA", "{BD648BB8-EF2 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.RenderSystem.Windows.DX10", "RenderSystems\ANX.Framework.Windows.DX10\ANX.RenderSystem.Windows.DX10.csproj", "{5BE49183-2F6F-4527-AC90-D816911FCF90}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.RenderSystem.Windows.GL3", "RenderSystems\ANX.Framework.Windows.GL3\ANX.RenderSystem.Windows.GL3.csproj", "{EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.RenderSystem.Windows.DX11", "RenderSystems\ANX.RenderSystem.Windows.DX11\ANX.RenderSystem.Windows.DX11.csproj", "{B30DE9C2-0926-46B6-8351-9AF276C472D5}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{82CDEC51-2E62-4D6D-8A89-8E0F68A9722B}" @@ -195,6 +193,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Support", "Support", "{3E29 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaveUtils", "Support\WaveUtils\WaveUtils.csproj", "{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.RenderSystem.GL3", "RenderSystems\ANX.Framework.GL3\ANX.RenderSystem.GL3.csproj", "{EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -351,16 +351,6 @@ Global {5BE49183-2F6F-4527-AC90-D816911FCF90}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {5BE49183-2F6F-4527-AC90-D816911FCF90}.Release|Mixed Platforms.Build.0 = Release|Any CPU {5BE49183-2F6F-4527-AC90-D816911FCF90}.Release|x86.ActiveCfg = Release|Any CPU - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Debug|x86.ActiveCfg = Debug|Any CPU - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Release|Any CPU.Build.0 = Release|Any CPU - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Release|x86.ActiveCfg = Release|Any CPU {B30DE9C2-0926-46B6-8351-9AF276C472D5}.Debug|Any CPU.ActiveCfg = Debug|x86 {B30DE9C2-0926-46B6-8351-9AF276C472D5}.Debug|Any CPU.Build.0 = Debug|x86 {B30DE9C2-0926-46B6-8351-9AF276C472D5}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 @@ -758,6 +748,16 @@ Global {1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Release|Mixed Platforms.Build.0 = Release|Any CPU {1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Release|x86.ActiveCfg = Release|Any CPU + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Debug|x86.ActiveCfg = Debug|Any CPU + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Release|Any CPU.Build.0 = Release|Any CPU + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -774,11 +774,11 @@ Global {14B39F89-C9B0-407E-877A-B515C985E96E} = {B24A8593-562A-4A25-BB08-46C163F10F3F} {45DD7B40-C498-4DD2-A16B-FD6C4E6991B3} = {B24A8593-562A-4A25-BB08-46C163F10F3F} {5BE49183-2F6F-4527-AC90-D816911FCF90} = {D421509A-9AE3-4D7E-881B-EAFED598B028} - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} = {D421509A-9AE3-4D7E-881B-EAFED598B028} {B30DE9C2-0926-46B6-8351-9AF276C472D5} = {D421509A-9AE3-4D7E-881B-EAFED598B028} {FF0AB665-2796-4354-9630-76C2751DB3C2} = {D421509A-9AE3-4D7E-881B-EAFED598B028} {2B71A7C2-0D18-4E3D-AE5A-320641D1162A} = {D421509A-9AE3-4D7E-881B-EAFED598B028} {A4D3AD34-E49C-4142-8620-2AFF44ED6719} = {D421509A-9AE3-4D7E-881B-EAFED598B028} + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} = {D421509A-9AE3-4D7E-881B-EAFED598B028} {F945515B-394D-4ED4-80E0-98EB59B69D24} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9} {AAA20E99-A897-4C91-A23E-D02B8F08ACA5} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9} {BC79B021-10E4-4D01-945A-7048FFF53A22} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9} diff --git a/ANX.Framework/Properties/AssemblyInfo.cs b/ANX.Framework/Properties/AssemblyInfo.cs index 894496a2..6dc73635 100644 --- a/ANX.Framework/Properties/AssemblyInfo.cs +++ b/ANX.Framework/Properties/AssemblyInfo.cs @@ -37,7 +37,7 @@ using System.Runtime.InteropServices; [assembly: InternalsVisibleTo("ANX.RenderSystem.Windows.DX10")] [assembly: InternalsVisibleTo("ANX.RenderSystem.Windows.DX11")] [assembly: InternalsVisibleTo("ANX.RenderSystem.Windows.Metro")] -[assembly: InternalsVisibleTo("ANX.RenderSystem.Windows.GL3")] +[assembly: InternalsVisibleTo("ANX.RenderSystem.GL3")] [assembly: InternalsVisibleTo("ANX.RenderSystem.Windows.PsVita")] [assembly: InternalsVisibleTo("ANX.Framework.Windows.Kinect")] [assembly: InternalsVisibleTo("ANX.Framework.Windows.XInput")] diff --git a/Installer/anx.wxs b/Installer/anx.wxs index 8ecf101a..530e7364 100644 --- a/Installer/anx.wxs +++ b/Installer/anx.wxs @@ -106,8 +106,8 @@ - - + + diff --git a/RenderSystems/ANX.Framework.GL3/ANX.RenderSystem.GL3.csproj b/RenderSystems/ANX.Framework.GL3/ANX.RenderSystem.GL3.csproj new file mode 100644 index 00000000..36036e6b --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/ANX.RenderSystem.GL3.csproj @@ -0,0 +1,90 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} + Library + Properties + ANX.RenderSystem.GL3 + ANX.RenderSystem.GL3 + v4.0 + 512 + + + true + full + false + ..\..\bin\Debug\ + TRACE;DEBUG;XNAEXT + prompt + 4 + x86 + Auto + true + + + pdbonly + true + ..\bin\Release\ + TRACE;XNAEXT + prompt + 4 + x86 + true + + + + ..\..\lib\OpenTK\OpenTK.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35} + ANX.Framework + + + + + + + + + \ No newline at end of file diff --git a/RenderSystems/ANX.Framework.GL3/BlendStateGL3.cs b/RenderSystems/ANX.Framework.GL3/BlendStateGL3.cs new file mode 100644 index 00000000..d16b492a --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/BlendStateGL3.cs @@ -0,0 +1,353 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using ANX.Framework.NonXNA.Development; +using OpenTK.Graphics.OpenGL; +using ANX.RenderSystem.GL3.Helpers; +using ANX.Framework; + +// 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.GL3 +{ + /// + /// Native Blend State object for OpenGL. + /// + /// Basically this is a wrapper class for setting the different values all + /// at once, because OpenGL has no State objects like DirectX. + /// + /// For Information on OpenGL blending: http://www.opengl.org/wiki/Blending + /// + [PercentageComplete(90)] + [TestStateAttribute(TestStateAttribute.TestState.Untested)] + public class BlendStateGL3 : INativeBlendState + { + #region Private + internal static BlendStateGL3 Current + { + get; + private set; + } + #endregion + + #region Public + #region IsBound + /// + /// Flag if the blend state is bound to the device or not. + /// + public bool IsBound + { + get; + private set; + } + #endregion + + #region AlphaBlendFunction + public BlendFunction AlphaBlendFunction + { + set; + private get; + } + #endregion + + #region ColorBlendFunction + public BlendFunction ColorBlendFunction + { + set; + private get; + } + #endregion + + #region AlphaSourceBlend + public Blend AlphaSourceBlend + { + set; + private get; + } + #endregion + + #region AlphaDestinationBlend + public Blend AlphaDestinationBlend + { + set; + private get; + } + #endregion + + #region ColorSourceBlend + public Blend ColorSourceBlend + { + set; + private get; + } + #endregion + + #region ColorDestinationBlend + public Blend ColorDestinationBlend + { + set; + private get; + } + #endregion + + #region ColorWriteChannels + public ColorWriteChannels ColorWriteChannels + { + set; + private get; + } + #endregion + + #region ColorWriteChannels1 + public ColorWriteChannels ColorWriteChannels1 + { + set; + private get; + } + #endregion + + #region ColorWriteChannels2 + public ColorWriteChannels ColorWriteChannels2 + { + set; + private get; + } + #endregion + + #region ColorWriteChannels3 + public ColorWriteChannels ColorWriteChannels3 + { + set; + private get; + } + #endregion + + #region BlendFactor + public Color BlendFactor + { + set; + private get; + } + #endregion + + #region MultiSampleMask + public int MultiSampleMask + { + set; + private get; + } + #endregion + #endregion + + #region Constructor + /// + /// Create a new OpenGL Blend State wrapper object. + /// + internal BlendStateGL3() + { + IsBound = false; + } + #endregion + + #region Apply (TODO) + /// + /// Apply the blend state on the graphics device. + /// + /// The current graphics device. + public void Apply(GraphicsDevice graphicsDevice) + { + IsBound = true; + Current = this; + + GL.Enable(EnableCap.Blend); + + GL.BlendEquationSeparate( + TranslateBlendFunction(ColorBlendFunction), + TranslateBlendFunction(AlphaBlendFunction)); + ErrorHelper.Check("BlendEquationSeparate"); + + GL.BlendFuncSeparate( + TranslateBlendSrc(ColorSourceBlend), + TranslateBlendDest(ColorDestinationBlend), + TranslateBlendSrc(AlphaSourceBlend), + TranslateBlendDest(AlphaDestinationBlend)); + ErrorHelper.Check("BlendFuncSeparate"); + + SetColorWriteChannel(0, ColorWriteChannels); + SetColorWriteChannel(1, ColorWriteChannels1); + SetColorWriteChannel(2, ColorWriteChannels2); + SetColorWriteChannel(3, 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 + /// + /// Release the blend state. + /// + public void Release() + { + IsBound = false; + Current = null; + } + #endregion + + #region Dispose + /// + /// Dispose this blend state object. + /// + public void Dispose() + { + } + #endregion + + #region SetColorWriteChannel + /// + /// Set the color mask for the specified index. + /// + /// Index of the color mask. + /// Mask channels to enable. + private void SetColorWriteChannel(int index, ColorWriteChannels channels) + { + bool r = (channels | ColorWriteChannels.Red) == channels; + bool g = (channels | ColorWriteChannels.Green) == channels; + bool b = (channels | ColorWriteChannels.Blue) == channels; + bool a = (channels | ColorWriteChannels.Alpha) == channels; + + GL.ColorMask(index, r, g, b, a); + ErrorHelper.Check("ColorMask"); + } + #endregion + + #region TranslateBlendSrc + /// + /// Translate the ANX Blend mode to the OpenGL Blend Factor Source. + /// + /// ANX Blend Function. + /// OpenGL Blend Factor Source. + private BlendingFactorSrc TranslateBlendSrc(Blend blending) + { + switch (blending) + { + case Blend.SourceAlpha: + return BlendingFactorSrc.SrcAlpha; + + case Blend.DestinationAlpha: + return BlendingFactorSrc.DstAlpha; + + case Blend.DestinationColor: + return BlendingFactorSrc.DstColor; + + case Blend.InverseDestinationAlpha: + return BlendingFactorSrc.OneMinusDstAlpha; + + case Blend.InverseDestinationColor: + return BlendingFactorSrc.OneMinusDstColor; + + case Blend.InverseSourceAlpha: + return BlendingFactorSrc.OneMinusSrcAlpha; + + case Blend.One: + return BlendingFactorSrc.One; + + case Blend.SourceAlphaSaturation: + return BlendingFactorSrc.SrcAlphaSaturate; + + case Blend.Zero: + return BlendingFactorSrc.Zero; + + default: + throw new ArgumentException("Unable to translate SourceBlend '" + + blending + "' to OpenGL BlendingFactorSrc."); + } + } + #endregion + + #region TranslateBlendDest + /// + /// Translate the ANX Blend mode to the OpenGL Blend Factor Destination. + /// + /// ANX Blend Function. + /// OpenGL Blend Factor Destination. + private BlendingFactorDest TranslateBlendDest(Blend blending) + { + switch (blending) + { + case Blend.SourceAlpha: + return BlendingFactorDest.SrcAlpha; + + case Blend.DestinationAlpha: + return BlendingFactorDest.DstAlpha; + + case Blend.DestinationColor: + return BlendingFactorDest.DstColor; + + case Blend.InverseDestinationAlpha: + return BlendingFactorDest.OneMinusDstAlpha; + + case Blend.InverseDestinationColor: + return BlendingFactorDest.OneMinusDstColor; + + case Blend.InverseSourceAlpha: + return BlendingFactorDest.OneMinusSrcAlpha; + + case Blend.InverseSourceColor: + return BlendingFactorDest.OneMinusSrcColor; + + case Blend.One: + return BlendingFactorDest.One; + + case Blend.SourceColor: + return BlendingFactorDest.SrcColor; + + case Blend.Zero: + return BlendingFactorDest.Zero; + + default: + throw new ArgumentException("Unable to translate DestinationBlend '" + + blending + "' to OpenGL BlendingFactorDest."); + } + } + #endregion + + #region TranslateBlendFunction + /// + /// Translate the ANX Blend Function to the OpenGL Blend Equation Mode. + /// + /// ANX Blend Function. + /// OpenGL Blend Equation Mode. + private BlendEquationMode TranslateBlendFunction(BlendFunction func) + { + switch (func) + { + case BlendFunction.Add: + return BlendEquationMode.FuncAdd; + + case BlendFunction.Subtract: + return BlendEquationMode.FuncSubtract; + + case BlendFunction.ReverseSubtract: + return BlendEquationMode.FuncReverseSubtract; + + case BlendFunction.Min: + return BlendEquationMode.Min; + + case BlendFunction.Max: + return BlendEquationMode.Max; + } + + throw new ArgumentException("Unable to translate BlendFunction '" + + func + "' to OpenGL BlendEquationMode."); + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/Creator.cs b/RenderSystems/ANX.Framework.GL3/Creator.cs new file mode 100644 index 00000000..1bf675c5 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/Creator.cs @@ -0,0 +1,347 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using ANX.Framework; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using ANX.Framework.NonXNA.Development; +using ANX.Framework.NonXNA.RenderSystem; +using ANX.Framework.GL3; +using OpenTK; +using OpenTK.Graphics.OpenGL; + +// 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.GL3 +{ + [PercentageComplete(90)] + [TestState(TestStateAttribute.TestState.Untested)] + [Developer("AstrorEnales")] + public class Creator : IRenderSystemCreator + { + #region Public + public string Name + { + get + { + return "OpenGL3"; + } + } + + public int Priority + { + get + { + return 100; + } + } + + public bool IsSupported + { + get + { + //TODO: this is just a very basic version of test for support + PlatformName os = OSInformation.GetName(); + return OSInformation.IsWindows || + os == PlatformName.Linux || + os == PlatformName.MacOSX; + } + } + + public EffectSourceLanguage GetStockShaderSourceLanguage + { + get + { + return EffectSourceLanguage.GLSL_FX; + } + } + #endregion + + #region CreateEffect + public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, + Stream byteCode) + { + AddInSystemFactory.Instance.PreventSystemChange( + AddInType.RenderSystem); + + return new EffectGL3(managedEffect, byteCode); + } + + public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, + Stream vertexShaderByteCode, Stream pixelShaderByteCode) + { + AddInSystemFactory.Instance.PreventSystemChange( + AddInType.RenderSystem); + + return new EffectGL3(managedEffect, vertexShaderByteCode, pixelShaderByteCode); + } + #endregion + + #region CreateGraphicsDevice + INativeGraphicsDevice IRenderSystemCreator.CreateGraphicsDevice(PresentationParameters presentationParameters) + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + return new GraphicsDeviceWindowsGL3(presentationParameters); + } + #endregion + + #region CreateTexture + /// + /// Create a new native texture. + /// + /// Graphics device. + /// The format of the texture. + /// The width of the texture. + /// The height of the texture. + /// The number of mipmaps in the texture. + /// + public INativeTexture2D CreateTexture(GraphicsDevice graphics, + SurfaceFormat surfaceFormat, int width, int height, int mipCount) + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + return new Texture2DGL3(surfaceFormat, width, height, mipCount); + } + #endregion + + #region CreateIndexBuffer + /// + /// Create a native index buffer. + /// + /// The current graphics device. + /// The size of a single index element. + /// The number of indices stored in the buffer. + /// + /// The usage type of the buffer. + /// Native OpenGL index buffer. + public INativeIndexBuffer CreateIndexBuffer(GraphicsDevice graphics, + IndexBuffer managedBuffer, IndexElementSize size, int indexCount, + BufferUsage usage) + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + return new IndexBufferGL3(managedBuffer, size, indexCount, usage); + } + #endregion + + #region CreateVertexBuffer + /// + /// Create a native vertex buffer. + /// + /// The current graphics device. + /// The vertex declaration for the buffer. + /// The number of vertices stored in the buffer. + /// + /// The usage type of the buffer. + /// Native OpenGL vertex buffer. + public INativeVertexBuffer CreateVertexBuffer(GraphicsDevice graphics, + VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration, + int vertexCount, BufferUsage usage) + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + return new VertexBufferGL3(managedBuffer, vertexDeclaration, vertexCount, + usage); + } + #endregion + +#if XNAEXT + #region CreateConstantBuffer (TODO) + public INativeConstantBuffer CreateConstantBuffer(GraphicsDevice graphics, ConstantBuffer managedBuffer, + BufferUsage usage) + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + + throw new NotImplementedException(); + } + #endregion +#endif + + #region CreateBlendState + /// + /// Create a new native blend state. + /// + /// Native Blend State. + public INativeBlendState CreateBlendState() + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + return new BlendStateGL3(); + } + #endregion + + #region CreateBlendState + /// + /// Create a new native rasterizer state. + /// + /// Native Rasterizer State. + public INativeRasterizerState CreateRasterizerState() + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + return new RasterizerStateGL3(); + } + #endregion + + #region CreateDepthStencilState + /// + /// Create a new native Depth Stencil State. + /// + /// Native Depth Stencil State. + public INativeDepthStencilState CreateDepthStencilState() + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + return new DepthStencilStateGL3(); + } + #endregion + + #region CreateSamplerState + /// + /// Create a new native sampler state. + /// + /// Native Sampler State. + public INativeSamplerState CreateSamplerState() + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + return new SamplerStateGL3(); + } + #endregion + + #region GetShaderByteCode + /// + /// Get the byte code of a pre defined shader. + /// + /// Pre defined shader type. + /// Byte code of the shader. + public byte[] GetShaderByteCode(PreDefinedShader type) + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + + if (type == PreDefinedShader.SpriteBatch) + { + return ShaderByteCode.SpriteBatchByteCode; + } + else if (type == PreDefinedShader.AlphaTestEffect) + { + return ShaderByteCode.AlphaTestEffectByteCode; + } + else if (type == PreDefinedShader.BasicEffect) + { + return ShaderByteCode.BasicEffectByteCode; + } + else if (type == PreDefinedShader.DualTextureEffect) + { + return ShaderByteCode.DualTextureEffectByteCode; + } + else if (type == PreDefinedShader.EnvironmentMapEffect) + { + return ShaderByteCode.EnvironmentMapEffectByteCode; + } + else if (type == PreDefinedShader.SkinnedEffect) + { + return ShaderByteCode.SkinnedEffectByteCode; + } + + throw new NotImplementedException("ByteCode for '" + type.ToString() + "' is not yet available"); + } + #endregion + + #region GetAdapterList (TODO) + /// + /// Get a list of available graphics adapter information. + /// + /// List of graphics adapters. + public ReadOnlyCollection GetAdapterList() + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + + var result = new List(); + foreach (DisplayDevice device in DisplayDevice.AvailableDisplays) + { + var displayModeCollection = new DisplayModeCollection(); + foreach (string format in Enum.GetNames(typeof(SurfaceFormat))) + { + SurfaceFormat surfaceFormat = + (SurfaceFormat)Enum.Parse(typeof(SurfaceFormat), format); + + // TODO: device.BitsPerPixel + if (surfaceFormat != SurfaceFormat.Color)//adapter.Supports(surfaceFormat) == false) + { + continue; + } + + var modes = new List(); + + foreach (DisplayResolution res in device.AvailableResolutions) + { + float aspect = (float)res.Width / (float)res.Height; + modes.Add(new DisplayMode + { + AspectRatio = aspect, + Width = res.Width, + Height = res.Height, + TitleSafeArea = new Rectangle(0, 0, res.Width, res.Height), + Format = surfaceFormat, + }); + } + + displayModeCollection[surfaceFormat] = modes.ToArray(); + } + + GraphicsAdapter newAdapter = new GraphicsAdapter + { + SupportedDisplayModes = displayModeCollection, + IsDefaultAdapter = device.IsPrimary, + + // TODO: + DeviceId = 0, + DeviceName = "", + Revision = 0, + SubSystemId = 0, + VendorId = 0, + }; + + result.Add(newAdapter); + } + + return new ReadOnlyCollection(result); + } + #endregion + + #region CreateRenderTarget + public INativeRenderTarget2D CreateRenderTarget(GraphicsDevice graphics, + int width, int height, bool mipMap, SurfaceFormat preferredFormat, + DepthFormat preferredDepthFormat, int preferredMultiSampleCount, + RenderTargetUsage usage) + { + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + return new RenderTarget2DGL3(width, height, mipMap, preferredFormat, + preferredDepthFormat, preferredMultiSampleCount, usage); + } + #endregion + + #region IsLanguageSupported + public bool IsLanguageSupported(EffectSourceLanguage sourceLanguage) + { + return sourceLanguage == EffectSourceLanguage.GLSL_FX || sourceLanguage == EffectSourceLanguage.GLSL; + } + #endregion + + #region CreateOcclusionQuery + public IOcclusionQuery CreateOcclusionQuery() + { + return new OcclusionQueryGL3(); + } + #endregion + + #region SetTextureSampler (TODO) + public void SetTextureSampler(int index, Texture value) + { + TextureUnit textureUnit = TextureUnit.Texture0 + index; + GL.ActiveTexture(textureUnit); + int handle = (value.NativeTexture as Texture2DGL3).NativeHandle; + GL.BindTexture(TextureTarget.Texture2D, handle); + int unitIndex = (int)(textureUnit - TextureUnit.Texture0); + //GL.Uniform1(UniformIndex, 1, ref unitIndex); + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/DepthStencilStateGL3.cs b/RenderSystems/ANX.Framework.GL3/DepthStencilStateGL3.cs new file mode 100644 index 00000000..57e77bbe --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/DepthStencilStateGL3.cs @@ -0,0 +1,400 @@ +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using ANX.Framework.NonXNA.Development; +using OpenTK.Graphics.OpenGL; + +// 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.GL3 +{ + /// + /// Native Depth Stencil State object for OpenGL. + /// + /// Basically this is a wrapper class for setting the different values all + /// at once, because OpenGL has no State objects like DirectX. + /// + [PercentageComplete(100)] + [TestStateAttribute(TestStateAttribute.TestState.Untested)] + public class DepthStencilStateGL3 : INativeDepthStencilState + { + #region Private + internal static DepthStencilStateGL3 Current + { + get; + private set; + } + #endregion + + #region Public + #region IsBound + /// + /// Flag if the state object is bound to the device. + /// + public bool IsBound + { + get; + private set; + } + #endregion + + #region DepthBufferEnable + public bool DepthBufferEnable + { + set; + private get; + } + #endregion + + #region DepthBufferFunction + public CompareFunction DepthBufferFunction + { + set; + private get; + } + #endregion + + #region DepthBufferWriteEnable + public bool DepthBufferWriteEnable + { + set; + private get; + } + #endregion + + #region StencilEnable + public bool StencilEnable + { + set; + private get; + } + #endregion + + #region StencilFunction + public CompareFunction StencilFunction + { + set; + private get; + } + #endregion + + #region StencilMask + public int StencilMask + { + set; + private get; + } + #endregion + + #region StencilDepthBufferFail + public StencilOperation StencilDepthBufferFail + { + set; + private get; + } + #endregion + + #region StencilFail + public StencilOperation StencilFail + { + set; + private get; + } + #endregion + + #region StencilPass + public StencilOperation StencilPass + { + set; + private get; + } + #endregion + + #region CounterClockwiseStencilDepthBufferFail + public StencilOperation CounterClockwiseStencilDepthBufferFail + { + set; + private get; + } + #endregion + + #region CounterClockwiseStencilFail + public StencilOperation CounterClockwiseStencilFail + { + set; + private get; + } + #endregion + + #region CounterClockwiseStencilFunction + public CompareFunction CounterClockwiseStencilFunction + { + set; + private get; + } + #endregion + + #region CounterClockwiseStencilPass + public StencilOperation CounterClockwiseStencilPass + { + set; + private get; + } + #endregion + + #region TwoSidedStencilMode + public bool TwoSidedStencilMode + { + set; + private get; + } + #endregion + + #region ReferenceStencil + public int ReferenceStencil + { + set; + private get; + } + #endregion + + #region StencilWriteMask + public int StencilWriteMask + { + set; + private get; + } + #endregion + #endregion + + #region Constructor + /// + /// Create a new depth stencil state object. + /// + internal DepthStencilStateGL3() + { + IsBound = false; + } + #endregion + + #region Apply + /// + /// Apply the depth stencil state to the graphics device. + /// + /// The current graphics device. + public void Apply(GraphicsDevice graphicsDevice) + { + IsBound = true; + Current = this; + + #region Depth + if (DepthBufferEnable) + { + GL.Enable(EnableCap.DepthTest); + } + else + { + GL.Disable(EnableCap.DepthTest); + } + ErrorHelper.Check("DepthTest"); + + GL.DepthFunc(TranslateDepthFunction(DepthBufferFunction)); + ErrorHelper.Check("DepthFunc"); + + GL.DepthMask(DepthBufferWriteEnable); + ErrorHelper.Check("DepthMask"); + #endregion + + #region Stencil + if (StencilEnable) + { + GL.Enable(EnableCap.StencilTest); + } + else + { + GL.Disable(EnableCap.StencilTest); + } + ErrorHelper.Check("StencilTest"); + + GL.StencilMask(StencilWriteMask); + ErrorHelper.Check("StencilMask"); + + if (TwoSidedStencilMode) + { + GL.StencilOpSeparate(StencilFace.Front, + TranslateStencilOp(StencilFail), + TranslateStencilOp(StencilDepthBufferFail), + TranslateStencilOp(StencilPass)); + ErrorHelper.Check("StencilOpSeparate Front"); + + GL.StencilOpSeparate(StencilFace.Back, + TranslateStencilOp(CounterClockwiseStencilFail), + TranslateStencilOp(CounterClockwiseStencilDepthBufferFail), + TranslateStencilOp(CounterClockwiseStencilPass)); + ErrorHelper.Check("StencilOpSeparate Back"); + + GL.StencilFuncSeparate(StencilFace.Front, + TranslateStencilFunction(StencilFunction), + ReferenceStencil, StencilMask); + ErrorHelper.Check("StencilFuncSeparate Front"); + + GL.StencilFuncSeparate(StencilFace.Back, + TranslateStencilFunction(CounterClockwiseStencilFunction), + ReferenceStencil, StencilMask); + ErrorHelper.Check("StencilFuncSeparate Back"); + } + else + { + GL.StencilOp( + TranslateStencilOp(StencilFail), + TranslateStencilOp(StencilDepthBufferFail), + TranslateStencilOp(StencilPass)); + ErrorHelper.Check("StencilOp"); + + GL.StencilFunc(TranslateStencilFunction(StencilFunction), + ReferenceStencil, StencilMask); + ErrorHelper.Check("StencilFunc"); + } + #endregion + } + #endregion + + #region TranslateStencilOp + /// + /// Translate the ANX stencil operation to OpenGL. + /// + /// ANX stencil operation. + /// Translated OpenGL stencil operation. + private OpenTK.Graphics.OpenGL.StencilOp TranslateStencilOp( + StencilOperation operation) + { + switch (operation) + { + default: + case StencilOperation.Decrement: + return StencilOp.Decr; + + case StencilOperation.DecrementSaturation: + return StencilOp.DecrWrap; + + case StencilOperation.Increment: + return StencilOp.Incr; + + case StencilOperation.IncrementSaturation: + return StencilOp.IncrWrap; + + case StencilOperation.Invert: + return StencilOp.Invert; + + case StencilOperation.Keep: + return StencilOp.Keep; + + case StencilOperation.Replace: + return StencilOp.Replace; + + case StencilOperation.Zero: + return StencilOp.Zero; + } + } + #endregion + + #region TranslateDepthFunction + /// + /// Translate the ANX compare function to the OpenGL depth function. + /// + /// ANX compare function. + /// Translated OpenGL depth function. + private OpenTK.Graphics.OpenGL.DepthFunction TranslateDepthFunction( + CompareFunction func) + { + switch (func) + { + default: + case CompareFunction.Always: + return OpenTK.Graphics.OpenGL.DepthFunction.Always; + + case CompareFunction.Equal: + return OpenTK.Graphics.OpenGL.DepthFunction.Equal; + + case CompareFunction.Greater: + return OpenTK.Graphics.OpenGL.DepthFunction.Greater; + + case CompareFunction.GreaterEqual: + return OpenTK.Graphics.OpenGL.DepthFunction.Gequal; + + case CompareFunction.Less: + return OpenTK.Graphics.OpenGL.DepthFunction.Less; + + case CompareFunction.LessEqual: + return OpenTK.Graphics.OpenGL.DepthFunction.Lequal; + + case CompareFunction.Never: + return OpenTK.Graphics.OpenGL.DepthFunction.Never; + + case CompareFunction.NotEqual: + return OpenTK.Graphics.OpenGL.DepthFunction.Notequal; + } + } + #endregion + + #region TranslateStencilFunction + /// + /// Translate the ANX compare function to the OpenGL stencil function. + /// + /// ANX compare function. + /// Translated OpenGL stencil function. + private OpenTK.Graphics.OpenGL.StencilFunction TranslateStencilFunction( + CompareFunction func) + { + switch (func) + { + default: + case CompareFunction.Always: + return OpenTK.Graphics.OpenGL.StencilFunction.Always; + + case CompareFunction.Equal: + return OpenTK.Graphics.OpenGL.StencilFunction.Equal; + + case CompareFunction.Greater: + return OpenTK.Graphics.OpenGL.StencilFunction.Greater; + + case CompareFunction.GreaterEqual: + return OpenTK.Graphics.OpenGL.StencilFunction.Gequal; + + case CompareFunction.Less: + return OpenTK.Graphics.OpenGL.StencilFunction.Less; + + case CompareFunction.LessEqual: + return OpenTK.Graphics.OpenGL.StencilFunction.Lequal; + + case CompareFunction.Never: + return OpenTK.Graphics.OpenGL.StencilFunction.Never; + + case CompareFunction.NotEqual: + return OpenTK.Graphics.OpenGL.StencilFunction.Notequal; + } + } + #endregion + + #region Release + /// + /// Release the depth stencil state. + /// + public void Release() + { + IsBound = false; + Current = null; + } + #endregion + + #region Dispose + /// + /// Dispose the depth stencil state object. + /// + public void Dispose() + { + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/EffectGL3.cs b/RenderSystems/ANX.Framework.GL3/EffectGL3.cs new file mode 100644 index 00000000..212d56a7 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/EffectGL3.cs @@ -0,0 +1,298 @@ +using System; +using System.Collections.Generic; +using System.IO; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using ANX.RenderSystem.GL3.Helpers; +using OpenTK.Graphics.OpenGL; + +// 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.GL3 +{ + /// + /// Native OpenGL Effect implementation. + /// http://wiki.delphigl.com/index.php/Tutorial_glsl + /// + public class EffectGL3 : INativeEffect + { + #region Private + private Effect managedEffect; + private ShaderData shaderData; + private List parameters; + private List techniques; + internal bool IsDisposed; + + internal EffectTechniqueGL3 CurrentTechnique + { + get + { + if (managedEffect.CurrentTechnique == null) + return null; + + return managedEffect.CurrentTechnique.NativeTechnique as EffectTechniqueGL3; + } + } + #endregion + + #region Public + #region Techniques + public IEnumerable Techniques + { + get + { + if (techniques.Count == 0) + { + Compile(); + } + + return techniques; + } + } + #endregion + + #region Parameters + public IEnumerable Parameters + { + get + { + if (techniques.Count == 0) + { + Compile(); + } + + return parameters; + } + } + #endregion + #endregion + + #region Constructor + /// + /// Private helper constructor for the basic initialization. + /// + private EffectGL3(Effect setManagedEffect) + { + GraphicsResourceManager.UpdateResource(this, true); + + parameters = new List(); + techniques = new List(); + managedEffect = setManagedEffect; + } + + ~EffectGL3() + { + GraphicsResourceManager.UpdateResource(this, false); + } + + /// + /// Create a new effect instance of separate streams. + /// + /// The vertex shader code. + /// The fragment shader code. + public EffectGL3(Effect setManagedEffect, Stream vertexShaderByteCode, Stream pixelShaderByteCode) + : this(setManagedEffect) + { +// TODO: this is probably not right! + throw new NotImplementedException("TODO: implement effect constructor with vertex and fragment streams, check HOWTO..."); + //CreateShader(ShaderHelper.LoadShaderCode(vertexShaderByteCode), + // ShaderHelper.LoadShaderCode(pixelShaderByteCode)); + } + + /// + /// Create a new effect instance of one streams. + /// + /// The byte code of the shader. + public EffectGL3(Effect setManagedEffect, Stream byteCode) + : this(setManagedEffect) + { + string source = ShaderHelper.LoadShaderCode(byteCode); + shaderData = ShaderHelper.ParseShaderCode(source); + } + #endregion + + #region RecreateData + internal void RecreateData() + { + Compile(); + } + #endregion + + #region Compile + private void Compile() + { + parameters.Clear(); + techniques.Clear(); + Dictionary vertexShaders = new Dictionary(); + Dictionary fragmentShaders = new Dictionary(); + List parameterNames = new List(); + + #region Compile vertex shaders + foreach (string vertexName in shaderData.VertexShaderCodes.Keys) + { + string vertexSource = shaderData.VertexGlobalCode + shaderData.VertexShaderCodes[vertexName]; + + int vertexShader = GL.CreateShader(ShaderType.VertexShader); + string vertexError = CompileShader(vertexShader, vertexSource); + if (String.IsNullOrEmpty(vertexError) == false) + throw new InvalidDataException("Failed to compile the vertex shader '" + vertexName + "' cause of: " + + vertexError); + + vertexShaders.Add(vertexName, vertexShader); + } + #endregion + + #region Compile fragment shaders + foreach (string fragmentName in shaderData.FragmentShaderCodes.Keys) + { + string fragmentSource = shaderData.FragmentGlobalCode + shaderData.FragmentShaderCodes[fragmentName]; + + int fragmentShader = GL.CreateShader(ShaderType.FragmentShader); + string fragmentError = CompileShader(fragmentShader, fragmentSource); + if (String.IsNullOrEmpty(fragmentError) == false) + throw new InvalidDataException("Failed to compile the fragment shader '" + fragmentName + "' cause of: " + + fragmentError); + + fragmentShaders.Add(fragmentName, fragmentShader); + } + #endregion + + #region Compile programs + foreach (string programName in shaderData.Techniques.Keys) + { + string vertexName = shaderData.Techniques[programName].Key; + string fragmentName = shaderData.Techniques[programName].Value; + + int programHandle = GL.CreateProgram(); + ErrorHelper.Check("CreateProgram"); + GL.AttachShader(programHandle, vertexShaders[vertexName]); + ErrorHelper.Check("AttachShader vertexShader"); + GL.AttachShader(programHandle, fragmentShaders[fragmentName]); + ErrorHelper.Check("AttachShader fragmentShader"); + GL.LinkProgram(programHandle); + + int result; + GL.GetProgram(programHandle, ProgramParameter.LinkStatus, out result); + if (result == 0) + { + string programError; + GL.GetProgramInfoLog(programHandle, out programError); + throw new InvalidDataException("Failed to link the shader program '" + + programName + "' because of: " + programError); + } + + EffectTechniqueGL3 technique = new EffectTechniqueGL3(managedEffect, programName, programHandle); + techniques.Add(new EffectTechnique(managedEffect, technique)); + AddParametersFrom(programHandle, parameterNames, technique); + } + #endregion + } + #endregion + + #region CompileShader + private string CompileShader(int shader, string source) + { + GL.ShaderSource(shader, source); + GL.CompileShader(shader); + + int result; + GL.GetShader(shader, ShaderParameter.CompileStatus, out result); + if (result == 0) + { + string error = ""; + GL.GetShaderInfoLog(shader, out error); + + GL.DeleteShader(shader); + + return error; + } + + return null; + } + #endregion + + #region AddParametersFrom + private void AddParametersFrom(int programHandle, List parameterNames, + EffectTechniqueGL3 technique) + { + int uniformCount; + GL.GetProgram(programHandle, ProgramParameter.ActiveUniforms, + out uniformCount); + ErrorHelper.Check("GetProgram ActiveUniforms"); + + for (int index = 0; index < uniformCount; index++) + { + string name = GL.GetActiveUniformName(programHandle, index); + ErrorHelper.Check("GetActiveUniformName name=" + name); + + if (parameterNames.Contains(name) == false) + { + parameterNames.Add(name); + int uniformIndex = GL.GetUniformLocation(programHandle, name); + ErrorHelper.Check("GetUniformLocation name=" + name + + " uniformIndex=" + uniformIndex); + parameters.Add(new EffectParameter() + { + NativeParameter = + new EffectParameterGL3(technique, name, uniformIndex), + }); + } + } + } + #endregion + + #region Apply + public void Apply(GraphicsDevice graphicsDevice) + { + GL.UseProgram(CurrentTechnique.programHandle); + GraphicsDeviceWindowsGL3.activeEffect = this; + ErrorHelper.Check("UseProgram"); + } + #endregion + + #region Dispose + /// + /// Dispose the native shader data. + /// + public void Dispose() + { + if (IsDisposed == false) + { + IsDisposed = true; + DisposeResource(); + } + } + + internal void DisposeResource() + { + if (GraphicsDeviceWindowsGL3.IsContextCurrent == false) + { + return; + } + + foreach (EffectTechnique technique in techniques) + { + int programHandle = + (technique.NativeTechnique as EffectTechniqueGL3).programHandle; + + GL.DeleteProgram(programHandle); + ErrorHelper.Check("DeleteProgram"); + + int result; + GL.GetProgram(programHandle, ProgramParameter.DeleteStatus, out result); + if (result == 0) + { + string deleteError; + GL.GetProgramInfoLog(programHandle, out deleteError); + throw new Exception("Failed to delete the shader program '" + + technique.Name + "' because of: " + deleteError); + } + } + techniques.Clear(); + parameters.Clear(); + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/EffectParameterGL3.cs b/RenderSystems/ANX.Framework.GL3/EffectParameterGL3.cs new file mode 100644 index 00000000..e34f8549 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/EffectParameterGL3.cs @@ -0,0 +1,569 @@ +using System; +using ANX.Framework; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using OpenTK.Graphics.OpenGL; + +// 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.GL3 +{ + /// + /// Native OpenGL implementation of an effect parameter. + /// + public class EffectParameterGL3 : INativeEffectParameter + { + #region Private + private EffectTechniqueGL3 parentTechnique; + #endregion + + #region Public + /// + /// The name of the effect parameter. + /// + public string Name + { + get; + private set; + } + + /// + /// The index of the uniform. + /// + public int UniformIndex + { + get; + private set; + } + #endregion + + #region Constructor + /// + /// Create a ne effect parameter object. + /// + internal EffectParameterGL3(EffectTechniqueGL3 setParentTechnique, + string setName, int setUniformIndex) + { + parentTechnique = setParentTechnique; + Name = setName; + UniformIndex = setUniformIndex; + } + #endregion + + #region SetValue + #region SetValue (Matrix) + /// + /// Set a matrix value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Matrix value, bool transpose) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + + OpenTK.Matrix4 matrix = new OpenTK.Matrix4( + value.M11, value.M12, value.M13, value.M14, + value.M21, value.M22, value.M23, value.M24, + value.M31, value.M32, value.M33, value.M34, + value.M41, value.M42, value.M43, value.M44); + + GL.UniformMatrix4(UniformIndex, transpose, ref matrix); + ErrorHelper.Check("UniformMatrix4"); + } + #endregion + + #region SetValue (Matrix[]) + /// + /// Set a Matrix array value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Matrix[] value, bool transpose) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + float[] array = new float[value.Length * 16]; + for (int index = 0; index < value.Length; index++) + { + array[(index * 16)] = value[index].M11; + array[(index * 16) + 1] = value[index].M12; + array[(index * 16) + 2] = value[index].M13; + array[(index * 16) + 3] = value[index].M14; + array[(index * 16) + 4] = value[index].M21; + array[(index * 16) + 5] = value[index].M22; + array[(index * 16) + 6] = value[index].M23; + array[(index * 16) + 7] = value[index].M24; + array[(index * 16) + 8] = value[index].M31; + array[(index * 16) + 9] = value[index].M32; + array[(index * 16) + 10] = value[index].M33; + array[(index * 16) + 11] = value[index].M34; + array[(index * 16) + 12] = value[index].M41; + array[(index * 16) + 13] = value[index].M42; + array[(index * 16) + 14] = value[index].M43; + array[(index * 16) + 15] = value[index].M44; + } + GL.UniformMatrix4(UniformIndex, array.Length, transpose, array); + ErrorHelper.Check("UniformMatrix4v"); + } + #endregion + + #region SetValue (Texture) + private Texture textureCache = null; + /// + /// Set a texture value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Texture value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + if (textureCache == null || + textureCache != value) + { + textureCache = value; + // TODO: multiple texture units + TextureUnit textureUnit = TextureUnit.Texture0; + GL.ActiveTexture(textureUnit); + ErrorHelper.Check("ActiveTexture"); + int handle = (value.NativeTexture as Texture2DGL3).NativeHandle; + GL.BindTexture(TextureTarget.Texture2D, handle); + ErrorHelper.Check("BindTexture"); + int unitIndex = (int)(textureUnit - TextureUnit.Texture0); + GL.Uniform1(UniformIndex, 1, ref unitIndex); + ErrorHelper.Check("Uniform1"); + } + } + #endregion + + #region SetValue (int) + /// + /// Set an int value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(int value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + GL.Uniform1(UniformIndex, value); + ErrorHelper.Check("Uniform1i"); + } + #endregion + + #region SetValue (int[]) + /// + /// Set an int array value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(int[] value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + GL.Uniform1(UniformIndex, value.Length, value); + ErrorHelper.Check("Uniform1iv"); + } + #endregion + + #region SetValue (float) + /// + /// Set a float value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(float value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + GL.Uniform1(UniformIndex, value); + ErrorHelper.Check("Uniform1f"); + } + #endregion + + #region SetValue (float[]) + /// + /// Set a float array value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(float[] value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + GL.Uniform1(UniformIndex, value.Length, value); + ErrorHelper.Check("Uniform1fv"); + } + #endregion + + #region SetValue (Vector2) + /// + /// Set a Vector2 value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Vector2 value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + GL.Uniform2(UniformIndex, value.X, value.Y); + ErrorHelper.Check("Uniform2f"); + } + #endregion + + #region SetValue (Vector2[]) + /// + /// Set a Vector2 array value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Vector2[] value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + float[] array = new float[value.Length * 2]; + for(int index = 0; index < value.Length; index++) + { + array[(index * 2)] = value[index].X; + array[(index * 2) + 1] = value[index].Y; + } + GL.Uniform2(UniformIndex, array.Length, array); + ErrorHelper.Check("Uniform2fv"); + } + #endregion + + #region SetValue (Vector3) + /// + /// Set a Vector3 value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Vector3 value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + GL.Uniform3(UniformIndex, value.X, value.Y, value.Z); + ErrorHelper.Check("Uniform3f"); + } + #endregion + + #region SetValue (Vector3[]) + /// + /// Set a Vector3 array value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Vector3[] value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + float[] array = new float[value.Length * 3]; + for (int index = 0; index < value.Length; index++) + { + array[(index * 3)] = value[index].X; + array[(index * 3) + 1] = value[index].Y; + array[(index * 3) + 2] = value[index].Z; + } + GL.Uniform3(UniformIndex, array.Length, array); + ErrorHelper.Check("Uniform3fv"); + } + #endregion + + #region SetValue (Vector4) + /// + /// Set a Vector4 value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Vector4 value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + GL.Uniform4(UniformIndex, value.X, value.Y, value.Z, value.W); + ErrorHelper.Check("Uniform4f"); + } + #endregion + + #region SetValue (Vector4[]) + /// + /// Set a Vector4 array value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Vector4[] value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + float[] array = new float[value.Length * 4]; + for (int index = 0; index < value.Length; index++) + { + array[(index * 4)] = value[index].X; + array[(index * 4) + 1] = value[index].Y; + array[(index * 4) + 2] = value[index].Z; + array[(index * 4) + 3] = value[index].W; + } + GL.Uniform4(UniformIndex, array.Length, array); + ErrorHelper.Check("Uniform4fv"); + } + #endregion + + #region SetValue (bool) + /// + /// Set a bool value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(bool value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + GL.Uniform1(UniformIndex, value ? 1 : 0); + ErrorHelper.Check("Uniform4f"); + } + #endregion + + #region SetValue (bool[]) + /// + /// Set a bool array value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(bool[] value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + int[] glBooleans = new int[value.Length]; + for (int index = 0; index < value.Length; index++) + { + glBooleans[index] = value[index] ? 1 : 0; + } + GL.Uniform1(UniformIndex, value.Length, glBooleans); + ErrorHelper.Check("Uniform1iv"); + } + #endregion + + #region SetValue (Quaternion) + /// + /// Set a Quaternion value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Quaternion value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + GL.Uniform4(UniformIndex, value.X, value.Y, value.Z, value.W); + ErrorHelper.Check("Uniform4f"); + } + #endregion + + #region SetValue (Quaternion[]) + /// + /// Set a Quaternion array value to the effect parameter. + /// + /// Value for the parameter + public void SetValue(Quaternion[] value) + { + GL.UseProgram(parentTechnique.programHandle); + ErrorHelper.Check("UseProgram"); + float[] array = new float[value.Length * 4]; + for (int index = 0; index < value.Length; index++) + { + array[(index * 4)] = value[index].X; + array[(index * 4) + 1] = value[index].Y; + array[(index * 4) + 2] = value[index].Z; + array[(index * 4) + 3] = value[index].W; + } + GL.Uniform4(UniformIndex, array.Length, array); + ErrorHelper.Check("Uniform4fv"); + } + #endregion + + #region SetValue (string, TODO) + public void SetValue(string value) + { + throw new NotImplementedException(); + } + #endregion + #endregion + + #region GetValue + #region GetValueBoolean + public bool GetValueBoolean() + { + int result; + GL.GetUniform(parentTechnique.programHandle, UniformIndex, out result); + ErrorHelper.Check("GetUniform"); + return result == 1; + } + #endregion + + #region GetValueBooleanArray (TODO) + public bool[] GetValueBooleanArray(int count) + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueInt32 + public int GetValueInt32() + { + int result; + GL.GetUniform(parentTechnique.programHandle, UniformIndex, out result); + ErrorHelper.Check("GetUniform"); + return result; + } + #endregion + + #region GetValueInt32Array (TODO) + public int[] GetValueInt32Array(int count) + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueMatrix (TODO) + public Matrix GetValueMatrix() + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueMatrixArray (TODO) + public Matrix[] GetValueMatrixArray(int count) + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueMatrixTranspose (TODO) + public Matrix GetValueMatrixTranspose() + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueMatrixTransposeArray (TODO) + public Matrix[] GetValueMatrixTransposeArray(int count) + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueQuaternion (TODO) + public Quaternion GetValueQuaternion() + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueQuaternionArray (TODO) + public Quaternion[] GetValueQuaternionArray(int count) + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueSingle + public float GetValueSingle() + { + float result; + GL.GetUniform(parentTechnique.programHandle, UniformIndex, out result); + ErrorHelper.Check("GetUniform"); + return result; + } + #endregion + + #region GetValueSingleArray (TODO) + public float[] GetValueSingleArray(int count) + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueString (TODO) + public string GetValueString() + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueTexture2D (TODO) + public Texture2D GetValueTexture2D() + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueTexture3D (TODO) + public Texture3D GetValueTexture3D() + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueTextureCube (TODO) + public TextureCube GetValueTextureCube() + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueVector2 + public Vector2 GetValueVector2() + { + float[] result = new float[2]; + unsafe + { + fixed (float* ptr = &result[0]) + { + GL.GetUniform(parentTechnique.programHandle, UniformIndex, ptr); + } + } + ErrorHelper.Check("GetUniform"); + return new Vector2(result[0], result[1]); + } + #endregion + + #region GetValueVector2Array (TODO) + public Vector2[] GetValueVector2Array(int count) + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueVector3 + public Vector3 GetValueVector3() + { + float[] result = new float[3]; + unsafe + { + fixed (float* ptr = &result[0]) + { + GL.GetUniform(parentTechnique.programHandle, UniformIndex, ptr); + } + } + ErrorHelper.Check("GetUniform"); + return new Vector3(result[0], result[1], result[2]); + } + #endregion + + #region GetValueVector3Array (TODO) + public Vector3[] GetValueVector3Array(int count) + { + throw new NotImplementedException(); + } + #endregion + + #region GetValueVector4 + public Vector4 GetValueVector4() + { + float[] result = new float[4]; + unsafe + { + fixed (float* ptr = &result[0]) + { + GL.GetUniform(parentTechnique.programHandle, UniformIndex, ptr); + } + } + ErrorHelper.Check("GetUniform"); + return new Vector4(result[0], result[1], result[2], result[3]); + } + #endregion + + #region GetValueVector4Array (TODO) + public Vector4[] GetValueVector4Array(int count) + { + throw new NotImplementedException(); + } + #endregion + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/EffectPassGL3.cs b/RenderSystems/ANX.Framework.GL3/EffectPassGL3.cs new file mode 100644 index 00000000..c20735e7 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/EffectPassGL3.cs @@ -0,0 +1,20 @@ +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.GL3 +{ + public class EffectPassGL3 : INativeEffectPass + { + public string Name + { + get + { + return "p0"; + } + } + } +} diff --git a/RenderSystems/ANX.Framework.GL3/EffectTechniqueGL3.cs b/RenderSystems/ANX.Framework.GL3/EffectTechniqueGL3.cs new file mode 100644 index 00000000..0edd9882 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/EffectTechniqueGL3.cs @@ -0,0 +1,88 @@ +using System.Collections.Generic; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using OpenTK.Graphics.OpenGL; + +// 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.GL3 +{ + /// + /// Native OpenGL implementation of an effect technique. + /// + public class EffectTechniqueGL3 : INativeEffectTechnique + { + #region Private + /// + /// The native shader handle. + /// + internal int programHandle; + + /// + /// The active attributes of this technique. + /// + internal ShaderAttributeGL3[] activeAttributes; + + /// + /// We currently have only one pass per technique. + /// + private EffectPass pass; + + private Effect parentEffect; + #endregion + + #region Public + /// + /// The name of the effect technique. + /// + public string Name + { + get; + private set; + } + + /// + /// The passes of the technique. + /// + public IEnumerable Passes + { + get + { + yield return pass; + } + } + #endregion + + #region Constructor + /// + /// Create a ne effect technique object. + /// + internal EffectTechniqueGL3(Effect setParentEffect, string setName, int setProgramHandle) + { + parentEffect = setParentEffect; + Name = setName; + programHandle = setProgramHandle; + + GetAttributes(); + + pass = new EffectPass(parentEffect); + } + #endregion + + #region GetAttributes + private void GetAttributes() + { + int attributeCount; + GL.GetProgram(programHandle, ProgramParameter.ActiveAttributes, + out attributeCount); + activeAttributes = new ShaderAttributeGL3[attributeCount]; + for (int index = 0; index < attributeCount; index++) + { + activeAttributes[index] = new ShaderAttributeGL3(programHandle, index); + } + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/ErrorHelper.cs b/RenderSystems/ANX.Framework.GL3/ErrorHelper.cs new file mode 100644 index 00000000..a2697c5f --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/ErrorHelper.cs @@ -0,0 +1,30 @@ +using System.Diagnostics; +using System.Reflection; +using ANX.Framework.NonXNA; +using OpenTK.Graphics.OpenGL; + +namespace ANX.RenderSystem.GL3 +{ + internal static class ErrorHelper + { + public static void Check(string extraInformation = "") + { + ErrorCode code = GL.GetError(); + if (code != ErrorCode.NoError) + { + string frameInfo = ""; + foreach (StackFrame frame in new StackTrace().GetFrames()) + { + MethodBase method = frame.GetMethod(); + frameInfo += "\n\t" + "at " + method.DeclaringType + "." + + method + ":" + frame.GetFileLineNumber(); + } + + string message = "OpenGL Error '" + code + "' Checked at: '" + + extraInformation + "'" + frameInfo; + + Logger.Info(message); + } + } + } +} diff --git a/RenderSystems/ANX.Framework.GL3/GraphicsDeviceWindowsGL3.cs b/RenderSystems/ANX.Framework.GL3/GraphicsDeviceWindowsGL3.cs new file mode 100644 index 00000000..dd92c019 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/GraphicsDeviceWindowsGL3.cs @@ -0,0 +1,458 @@ +using System; +using ANX.Framework; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using ANX.RenderSystem.GL3.Helpers; +using OpenTK.Graphics; +using OpenTK.Graphics.OpenGL; +using OpenTK.Platform; + +// 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.GL3 +{ + public class GraphicsDeviceWindowsGL3 : INativeGraphicsDevice + { + #region Constants + private const float ColorMultiplier = 1f / 255f; + #endregion + + #region Private + private GraphicsContext nativeContext; + private IWindowInfo nativeWindowInfo; + private GraphicsMode graphicsMode; + + private int cachedVersionMinor = -1; + private int cachedVersionMajor = -1; + + internal static VertexBufferGL3[] boundVertexBuffers; + private static RenderTarget2DGL3[] boundRenderTargets; + internal static IndexBufferGL3 boundIndexBuffer; + internal static EffectGL3 activeEffect; + + internal static GraphicsDeviceWindowsGL3 Current + { + get; + private set; + } + + internal static bool IsContextCurrent + { + get + { + return (Current == null || Current.nativeContext == null) ? false : Current.nativeContext.IsCurrent; + } + } + #endregion + + #region Public + #region VSync + public bool VSync + { + get + { + return nativeContext.VSync; + } + set + { + nativeContext.VSync = value; + } + } + #endregion + #endregion + + #region Constructor + internal GraphicsDeviceWindowsGL3(PresentationParameters presentationParameters) + { + Current = this; + ResetDevice(presentationParameters); + } + #endregion + + #region ResetDevice + private void ResetDevice(PresentationParameters presentationParameters) + { + if (nativeContext != null) + Dispose(); + + boundVertexBuffers = new VertexBufferGL3[0]; + boundRenderTargets = new RenderTarget2DGL3[0]; + boundIndexBuffer = null; + activeEffect = null; + + int depth = 0; + int stencil = 0; + switch (presentationParameters.DepthStencilFormat) + { + case DepthFormat.None: + break; + + case DepthFormat.Depth16: + depth = 16; + break; + + case DepthFormat.Depth24: + depth = 24; + break; + + case DepthFormat.Depth24Stencil8: + depth = 24; + stencil = 8; + break; + } + + ResizeRenderWindow(presentationParameters); + + var colorFormat = DatatypesMapping.SurfaceToColorFormat(presentationParameters.BackBufferFormat); + graphicsMode = new GraphicsMode(colorFormat, depth, stencil, presentationParameters.MultiSampleCount); + + CreateWindowInfo(presentationParameters.DeviceWindowHandle, graphicsMode.Index.Value); + + nativeContext = new GraphicsContext(graphicsMode, nativeWindowInfo); + nativeContext.MakeCurrent(nativeWindowInfo); + nativeContext.LoadAll(); + + LogOpenGLInformation(); + + GL.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight); + + GraphicsResourceManager.RecreateAllResources(); + } + #endregion + + #region LogOpenGLInformation + private void LogOpenGLInformation() + { + string version = GL.GetString(StringName.Version); + string vendor = GL.GetString(StringName.Vendor); + string renderer = GL.GetString(StringName.Renderer); + string shadingLanguageVersion = GL.GetString(StringName.ShadingLanguageVersion); + Logger.Info("OpenGL version: " + version + " (" + vendor + " - " + renderer + ")"); + Logger.Info("GLSL version: " + shadingLanguageVersion); + string[] parts = version.Split(new char[] { '.', ' ' }); + cachedVersionMajor = int.Parse(parts[0]); + cachedVersionMinor = int.Parse(parts[1]); + } + #endregion + + #region CreateWindowInfo + private void CreateWindowInfo(IntPtr windowHandle, IntPtr graphicsModeHandle) + { + if (OpenTK.Configuration.RunningOnWindows) + nativeWindowInfo = Utilities.CreateWindowsWindowInfo(windowHandle); + else if (OpenTK.Configuration.RunningOnX11) + nativeWindowInfo = LinuxInterop.CreateX11WindowInfo(windowHandle, graphicsModeHandle); + else if (OpenTK.Configuration.RunningOnMacOS) + nativeWindowInfo = Utilities.CreateMacOSCarbonWindowInfo(windowHandle, false, true); + else + throw new NotImplementedException(); + + } + #endregion + + #region SetViewport + public void SetViewport(Viewport viewport) + { + GL.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height); + ErrorHelper.Check("SetViewport"); + } + #endregion + + #region Clear + private uint? lastClearColor; + /// + /// Clear the current screen by the specified clear color. + /// + /// Clear color. + public void Clear(ref Color color) + { + uint newClearColor = color.PackedValue; + if (lastClearColor.HasValue == false || + lastClearColor != newClearColor) + { + lastClearColor = newClearColor; + GL.ClearColor(color.R * ColorMultiplier, color.G * ColorMultiplier, + color.B * ColorMultiplier, color.A * ColorMultiplier); + ErrorHelper.Check("ClearColor"); + } + GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + ErrorHelper.Check("Clear"); + } + + /// + /// Clear the current screen by the specified clear color and options. + /// + /// Clear options defining which components + /// should be cleared. + /// Clear color. + /// Depth value. + /// Stencil value. + public void Clear(ClearOptions options, Vector4 color, float depth, + int stencil) + { + Color anxColor; + DatatypesMapping.Convert(ref color, out anxColor); + uint newClearColor = anxColor.PackedValue; + if (lastClearColor != newClearColor) + { + lastClearColor = newClearColor; + GL.ClearColor(anxColor.R * ColorMultiplier, anxColor.G * ColorMultiplier, + anxColor.B * ColorMultiplier, anxColor.A * ColorMultiplier); + ErrorHelper.Check("ClearColor"); + } + + ClearBufferMask mask = (ClearBufferMask)0; + if ((options | ClearOptions.Target) == options) + { + mask |= ClearBufferMask.ColorBufferBit; + } + if ((options | ClearOptions.Stencil) == options) + { + mask |= ClearBufferMask.StencilBufferBit; + } + if ((options | ClearOptions.DepthBuffer) == options) + { + mask |= ClearBufferMask.DepthBufferBit; + } + + GL.ClearDepth(depth); + ErrorHelper.Check("ClearDepth"); + GL.ClearStencil(stencil); + ErrorHelper.Check("ClearStencil"); + GL.Clear(mask); + ErrorHelper.Check("Clear"); + } + #endregion + + #region Present + /// + /// Swap the graphics buffers. + /// + public void Present() + { + if (nativeContext != null) + { + nativeContext.SwapBuffers(); + } + } + #endregion + + #region DrawIndexedPrimitives + public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, + int startIndex, int primitiveCount) + { + // TODO: baseVertex, minVertexIndex, numVertices, startIndex + DrawElementsType elementsType = boundIndexBuffer.elementSize == IndexElementSize.SixteenBits ? + DrawElementsType.UnsignedShort : + DrawElementsType.UnsignedInt; + + int count; + BeginMode mode = DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType, primitiveCount, out count); + + GL.DrawElements(mode, count, elementsType, 0); + ErrorHelper.Check("DrawElements"); + } + #endregion + + #region DrawInstancedPrimitives (TODO) + public void DrawInstancedPrimitives(PrimitiveType primitiveType, + int baseVertex, int minVertexIndex, int numVertices, int startIndex, + int primitiveCount, int instanceCount) + { + //GL.DrawArraysInstanced( + // DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType), + // baseVertex, numVertices, instanceCount); + throw new NotImplementedException(); + } + #endregion + + #region DrawUserIndexedPrimitives (TODO) + public void DrawUserIndexedPrimitives(PrimitiveType primitiveType, + T[] vertexData, int vertexOffset, int numVertices, Array indexData, + int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration, + IndexElementSize indexFormat) where T : struct, IVertexType + { + //BeginMode mode = DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType); + + //if (indexFormat == IndexElementSize.SixteenBits) + //{ + // ushort[] indices = new ushort[indexData.Length]; + // indexData.CopyTo(indices, 0); + // GL.DrawElements(mode, numVertices, DrawElementsType.UnsignedShort, + // indices); + //} + //else + //{ + // uint[] indices = new uint[indexData.Length]; + // indexData.CopyTo(indices, 0); + // GL.DrawElements(mode, numVertices, DrawElementsType.UnsignedInt, + // indices); + //} + + throw new NotImplementedException(); + } + #endregion + + #region DrawUserPrimitives (TODO) + public void DrawUserPrimitives(PrimitiveType primitiveType, + T[] vertexData, int vertexOffset, int primitiveCount, + VertexDeclaration vertexDeclaration) where T : struct, IVertexType + { + throw new NotImplementedException(); + } + #endregion + + #region DrawPrimitives (TODO: check) + public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, + int primitiveCount) + { + int count; + BeginMode mode = DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType, + primitiveCount, out count); + GL.DrawArrays(mode, vertexOffset, count); + ErrorHelper.Check("DrawArrays"); + } + #endregion + + #region SetConstantBuffer (TODO) +#if XNAEXT + public void SetConstantBuffer(int slot, ConstantBuffer constantBuffer) + { + if (constantBuffer == null) + throw new ArgumentNullException("constantBuffer"); + + throw new NotImplementedException(); + } +#endif + #endregion + + #region SetVertexBuffers + public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers) + { + boundVertexBuffers = new VertexBufferGL3[vertexBuffers.Length]; + for (int index = 0; index < vertexBuffers.Length; index++) + { + var nativeBuffer = (VertexBufferGL3)vertexBuffers[index].VertexBuffer.NativeVertexBuffer; + boundVertexBuffers[index] = nativeBuffer; + nativeBuffer.Bind(activeEffect); + } + } + #endregion + + #region SetIndexBuffer + public void SetIndexBuffer(IndexBuffer indexBuffer) + { + boundIndexBuffer = (IndexBufferGL3)indexBuffer.NativeIndexBuffer; + GL.BindBuffer(BufferTarget.ElementArrayBuffer, boundIndexBuffer.BufferHandle); + ErrorHelper.Check("BindBuffer"); + } + #endregion + + #region ResizeRenderWindow + private void ResizeRenderWindow(PresentationParameters presentationParameters) + { + if (OpenTK.Configuration.RunningOnWindows) + { + WindowsInterop.ResizeWindow(presentationParameters.DeviceWindowHandle, + presentationParameters.BackBufferWidth, + presentationParameters.BackBufferHeight); + } + else + { + LinuxInterop.ResizeWindow(presentationParameters.DeviceWindowHandle, + presentationParameters.BackBufferWidth, + presentationParameters.BackBufferHeight); + } + } + #endregion + + #region SetRenderTargets + public void SetRenderTargets(params RenderTargetBinding[] renderTargets) + { + if (renderTargets == null) + { + if (boundRenderTargets.Length > 0) + { + for (int index = 0; index < boundRenderTargets.Length; index++) + { + boundRenderTargets[index].Unbind(); + } + boundRenderTargets = new RenderTarget2DGL3[0]; + } + } + else + { + boundRenderTargets = new RenderTarget2DGL3[renderTargets.Length]; + for (int index = 0; index < renderTargets.Length; index++) + { + RenderTarget2D renderTarget = + renderTargets[index].RenderTarget as RenderTarget2D; + RenderTarget2DGL3 nativeRenderTarget = + renderTarget.NativeRenderTarget as RenderTarget2DGL3; + boundRenderTargets[index] = nativeRenderTarget; + + nativeRenderTarget.Bind(); + } + } + } + #endregion + + #region GetBackBufferData (TODO) + public void GetBackBufferData(Rectangle? rect, T[] data, + int startIndex, int elementCount) where T : struct + { + throw new NotImplementedException(); + } + + public void GetBackBufferData(T[] data) where T : struct + { + //glReadPixels(0, 0, nWidth, nHeight, GL_RGB, GL_UNSIGNED_BYTE, m_pPixelData) + throw new NotImplementedException(); + } + + public void GetBackBufferData(T[] data, int startIndex, + int elementCount) where T : struct + { + throw new NotImplementedException(); + } + #endregion + + #region ResizeBuffers + public void ResizeBuffers(PresentationParameters presentationParameters) + { + ResizeRenderWindow(presentationParameters); + + GL.Viewport(0, 0, presentationParameters.BackBufferWidth, + presentationParameters.BackBufferHeight); + + ResetDevice(presentationParameters); + } + #endregion + + #region Dispose + public void Dispose() + { + GraphicsResourceManager.DisposeAllResources(); + + lastClearColor = new uint?(); + boundVertexBuffers = null; + boundIndexBuffer = null; + activeEffect = null; + boundRenderTargets = null; + + if (nativeWindowInfo != null) + { + nativeWindowInfo.Dispose(); + nativeWindowInfo = null; + } + if (nativeContext != null) + { + nativeContext.Dispose(); + nativeContext = null; + } + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/Helpers/DatatypesMapping.cs b/RenderSystems/ANX.Framework.GL3/Helpers/DatatypesMapping.cs new file mode 100644 index 00000000..b8d96d80 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/Helpers/DatatypesMapping.cs @@ -0,0 +1,299 @@ +using System; +using ANX.Framework; +using ANX.Framework.Graphics; +using OpenTK.Graphics; +using OpenTK.Graphics.OpenGL; + +// 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.GL3.Helpers +{ + internal static class DatatypesMapping + { + #region Constants + public const float ColorMultiplier = 1f / 255f; + #endregion + + #region Convert ANX.Color -> OpenTK.Color4 + public static void Convert(ref Color anxColor, out Color4 otkColor) + { + otkColor.R = anxColor.R * ColorMultiplier; + otkColor.G = anxColor.G * ColorMultiplier; + otkColor.B = anxColor.B * ColorMultiplier; + otkColor.A = anxColor.A * ColorMultiplier; + } + #endregion + + #region Convert OpenTK.Color4 -> ANX.Color + public static void Convert(ref Color4 otkColor, out Color anxColor) + { + byte r = (byte)(otkColor.R * 255); + byte g = (byte)(otkColor.G * 255); + byte b = (byte)(otkColor.B * 255); + byte a = (byte)(otkColor.A * 255); + anxColor.packedValue = (uint)(r + (g << 8) + (b << 16) + (a << 24)); + } + #endregion + + #region Convert ANX.Vector4 -> ANX.Color + public static void Convert(ref Vector4 anxVector, out Color anxColor) + { + byte r = (byte)(anxVector.X * 255); + byte g = (byte)(anxVector.Y * 255); + byte b = (byte)(anxVector.Z * 255); + byte a = (byte)(anxVector.W * 255); + anxColor.packedValue = (uint)(r + (g << 8) + (b << 16) + (a << 24)); + } + #endregion + + #region SurfaceToColorFormat (TODO) + /// + /// Translate the XNA surface format to an OpenGL ColorFormat. + /// + /// XNA surface format. + /// Translated color format for OpenGL. + public static ColorFormat SurfaceToColorFormat(SurfaceFormat format) + { + switch (format) + { + // TODO + case SurfaceFormat.Dxt1: + case SurfaceFormat.Dxt3: + case SurfaceFormat.Dxt5: + case SurfaceFormat.HdrBlendable: + throw new NotImplementedException("Surface Format '" + format + + "' isn't implemented yet!"); + + // TODO: CHECK! + case SurfaceFormat.NormalizedByte2: + return new ColorFormat(8, 8, 0, 0); + + //DONE + default: + case SurfaceFormat.Color: + case SurfaceFormat.NormalizedByte4: + return new ColorFormat(8, 8, 8, 8); + + case SurfaceFormat.HalfVector2: + return new ColorFormat(16, 16, 0, 0); + + case SurfaceFormat.HalfVector4: + return new ColorFormat(16, 16, 16, 16); + + case SurfaceFormat.Bgra4444: + return new ColorFormat(4, 4, 4, 4); + + case SurfaceFormat.Bgra5551: + return new ColorFormat(5, 5, 5, 1); + + case SurfaceFormat.Alpha8: + return new ColorFormat(0, 0, 0, 8); + + case SurfaceFormat.Bgr565: + return new ColorFormat(5, 6, 5, 0); + + case SurfaceFormat.Rg32: + return new ColorFormat(16, 16, 0, 0); + + case SurfaceFormat.Rgba1010102: + return new ColorFormat(10, 10, 10, 2); + + case SurfaceFormat.Rgba64: + return new ColorFormat(16, 16, 16, 16); + + case SurfaceFormat.HalfSingle: + return new ColorFormat(16, 0, 0, 0); + + case SurfaceFormat.Single: + return new ColorFormat(32, 0, 0, 0); + + case SurfaceFormat.Vector2: + return new ColorFormat(32, 32, 0, 0); + + case SurfaceFormat.Vector4: + return new ColorFormat(32, 32, 32, 32); + } + } + #endregion + + #region SurfaceToPixelInternalFormat (TODO) + /// + /// Translate the XNA surface format to an OpenGL PixelInternalFormat. + /// + /// XNA surface format. + /// Translated format for OpenGL. + public static PixelInternalFormat SurfaceToPixelInternalFormat( + SurfaceFormat format) + { + switch (format) + { + // TODO + case SurfaceFormat.HdrBlendable: + case SurfaceFormat.Bgr565: + throw new NotImplementedException("Surface Format '" + format + + "' isn't implemented yet!"); + + // TODO: CHECK! + case SurfaceFormat.NormalizedByte2: + return PixelInternalFormat.Rg8; + + default: + case SurfaceFormat.Color: + case SurfaceFormat.NormalizedByte4: + return PixelInternalFormat.Rgba; + + case SurfaceFormat.Dxt1: + return PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; + + case SurfaceFormat.Dxt3: + return PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; + + case SurfaceFormat.Dxt5: + return PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; + + case SurfaceFormat.HalfVector2: + return PixelInternalFormat.Rg16; + + case SurfaceFormat.Rgba64: + case SurfaceFormat.HalfVector4: + return PixelInternalFormat.Rgba16f; + + case SurfaceFormat.Bgra4444: + return PixelInternalFormat.Rgba4; + + case SurfaceFormat.Bgra5551: + return PixelInternalFormat.Rgb5A1; + + case SurfaceFormat.Alpha8: + return PixelInternalFormat.Alpha8; + + case SurfaceFormat.Vector2: + case SurfaceFormat.Rg32: + return PixelInternalFormat.Rg32f; + + case SurfaceFormat.Rgba1010102: + return PixelInternalFormat.Rgb10A2; + + case SurfaceFormat.HalfSingle: + return PixelInternalFormat.R16f; + + case SurfaceFormat.Single: + return PixelInternalFormat.R32f; + + case SurfaceFormat.Vector4: + return PixelInternalFormat.Rgba32f; + } + } + #endregion + + #region PrimitiveTypeToBeginMode + /// + /// Translate the XNA PrimitiveType to an OpenGL BeginMode. + /// + /// XNA PrimitiveType. + /// Translated BeginMode for OpenGL. + public static BeginMode PrimitiveTypeToBeginMode(PrimitiveType type, int primitiveCount, out int count) + { + switch (type) + { + case PrimitiveType.LineList: + count = primitiveCount * 2; + return BeginMode.Lines; + + case PrimitiveType.LineStrip: + count = primitiveCount + 1; + return BeginMode.LineStrip; + + default: + case PrimitiveType.TriangleList: + count = primitiveCount * 3; + return BeginMode.Triangles; + + case PrimitiveType.TriangleStrip: + count = primitiveCount + 2; + return BeginMode.TriangleStrip; + } + } + #endregion + + #region Tests + private class Tests + { + #region TestConvertColorToOtkColor + public static void TestConvertColorToOtkColor() + { + Color anxColor = new Color(1f, 0.5f, 0.75f, 0f); + Color4 color; + DatatypesMapping.Convert(ref anxColor, out color); + Console.WriteLine(color.ToString()); + } + #endregion + + #region TestConvertOtkColorToColor + public static void TestConvertOtkColorToColor() + { + Color4 color = new Color4(1f, 0.5f, 0.75f, 0f); + Color anxColor; + DatatypesMapping.Convert(ref color, out anxColor); + Console.WriteLine(anxColor.ToString()); + } + #endregion + + #region TestConvertVector4ToColor + public static void TestConvertVector4ToColor() + { + Vector4 vector = new Vector4(1f, 0.5f, 0.75f, 0f); + Color color; + DatatypesMapping.Convert(ref vector, out color); + Console.WriteLine(color.ToString()); + } + #endregion + + #region TestPrimitiveTypeToBeginMode + public static void TestPrimitiveTypeToBeginMode() + { + PrimitiveType type = PrimitiveType.LineList; + int primitiveCount = 10; + int count = 0; + + BeginMode result = DatatypesMapping.PrimitiveTypeToBeginMode(type, + primitiveCount, out count); + AssetValues(result, BeginMode.Lines); + AssetValues(count, primitiveCount * 2); + + type = PrimitiveType.LineStrip; + result = DatatypesMapping.PrimitiveTypeToBeginMode(type, primitiveCount, + out count); + AssetValues(result, BeginMode.LineStrip); + AssetValues(count, primitiveCount + 1); + + type = PrimitiveType.TriangleList; + result = DatatypesMapping.PrimitiveTypeToBeginMode(type, primitiveCount, + out count); + AssetValues(result, BeginMode.Triangles); + AssetValues(count, primitiveCount * 3); + + type = PrimitiveType.TriangleStrip; + result = DatatypesMapping.PrimitiveTypeToBeginMode(type, primitiveCount, + out count); + AssetValues(result, BeginMode.TriangleStrip); + AssetValues(count, primitiveCount + 2); + } + #endregion + + #region AssetValues + private static void AssetValues(T first, T second) + { + if (first.Equals(second) == false) + { + throw new Exception("The two values are not equal:\n\t1: " + first + + "\n\t2: " + second); + } + } + #endregion + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/Helpers/GraphicsResourceManager.cs b/RenderSystems/ANX.Framework.GL3/Helpers/GraphicsResourceManager.cs new file mode 100644 index 00000000..6977bf04 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/Helpers/GraphicsResourceManager.cs @@ -0,0 +1,195 @@ +using System; +using System.Collections.Generic; + +// 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.GL3.Helpers +{ + internal static class GraphicsResourceManager + { + #region Private + private static List allTextures; + + private static List allEffects; + + private static List allVertexBuffers; + + private static List allIndexBuffers; + #endregion + + #region Constructor + static GraphicsResourceManager() + { + allTextures = new List(); + allEffects = new List(); + allVertexBuffers = new List(); + allIndexBuffers = new List(); + } + #endregion + + #region UpdateResource + public static void UpdateResource(T resource, bool register) + { + IList list = null; + + if (typeof(T) == typeof(Texture2DGL3)) + { + list = (IList)allTextures; + } + else if (typeof(T) == typeof(EffectGL3)) + { + list = (IList)allEffects; + } + else if (typeof(T) == typeof(VertexBufferGL3)) + { + list = (IList)allVertexBuffers; + } + else if (typeof(T) == typeof(IndexBufferGL3)) + { + list = (IList)allIndexBuffers; + } + + lock (list) + { + if (register) + { + list.Add(resource); + } + else + { + list.Remove(resource); + } + } + } + #endregion + + #region DisposeAllResources + public static void DisposeAllResources() + { + #region Textures + lock (allTextures) + { + foreach (Texture2DGL3 texture in allTextures) + { + if (texture.IsDisposed == false) + { + texture.DisposeResource(); + } + } + } + #endregion + + #region Effects + lock (allEffects) + { + foreach (EffectGL3 effect in allEffects) + { + if (effect.IsDisposed == false) + { + effect.DisposeResource(); + } + } + } + #endregion + + #region VertexBuffers + lock (allVertexBuffers) + { + foreach (VertexBufferGL3 buffer in allVertexBuffers) + { + if (buffer.IsDisposed == false) + { + buffer.DisposeResource(); + } + } + } + #endregion + + #region IndexBuffers + lock (allIndexBuffers) + { + foreach (IndexBufferGL3 buffer in allIndexBuffers) + { + if (buffer.IsDisposed == false) + { + buffer.DisposeResource(); + } + } + } + #endregion + } + #endregion + + #region RecreateAllResources + public static void RecreateAllResources() + { + #region Textures + lock (allTextures) + { + foreach (Texture2DGL3 texture in allTextures) + { + if (texture.IsDisposed == false) + { + texture.RecreateData(); + } + } + } + #endregion + + #region Effects + lock (allEffects) + { + foreach (EffectGL3 effect in allEffects) + { + if (effect.IsDisposed == false) + { + effect.RecreateData(); + } + } + } + #endregion + + #region VertexBuffers + lock (allVertexBuffers) + { + foreach (VertexBufferGL3 buffer in allVertexBuffers) + { + if (buffer.IsDisposed == false) + { + buffer.RecreateData(); + } + } + } + #endregion + + #region IndexBuffers + lock (allIndexBuffers) + { + foreach (IndexBufferGL3 buffer in allIndexBuffers) + { + if (buffer.IsDisposed == false) + { + buffer.RecreateData(); + } + } + } + #endregion + + if (BlendStateGL3.Current != null) + { + BlendStateGL3.Current.Apply(null); + } + if (RasterizerStateGL3.Current != null) + { + RasterizerStateGL3.Current.Apply(null); + } + if (DepthStencilStateGL3.Current != null) + { + DepthStencilStateGL3.Current.Apply(null); + } + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/Helpers/LinuxInterop.cs b/RenderSystems/ANX.Framework.GL3/Helpers/LinuxInterop.cs new file mode 100644 index 00000000..6d221ceb --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/Helpers/LinuxInterop.cs @@ -0,0 +1,118 @@ +using System; +using System.Reflection; +using System.Runtime.InteropServices; +using OpenTK.Platform; + +// 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.GL3.Helpers +{ + internal static class LinuxInterop + { + #region XVisualInfo (Helper struct) + [StructLayout(LayoutKind.Sequential)] + private struct XVisualInfo + { + public IntPtr Visual; + public IntPtr VisualID; + public int Screen; + public int Depth; + public int Class; + public long RedMask; + public long GreenMask; + public long blueMask; + public int ColormapSize; + public int BitsPerRgb; + + public override string ToString() + { + return String.Format("id ({0}), screen ({1}), depth ({2}), class ({3})", + VisualID, Screen, Depth, Class); + } + } + #endregion + + #region Invokes + [DllImport("libX11")] + private static extern IntPtr XCreateColormap(IntPtr display, IntPtr window, + IntPtr visual, int alloc); + + [DllImport("libX11", EntryPoint = "XGetVisualInfo")] + private static extern IntPtr XGetVisualInfoInternal(IntPtr display, + IntPtr vinfo_mask, ref XVisualInfo template, out int nitems); + + [DllImport("libX11")] + private static extern int XPending(IntPtr diplay); + + [DllImport("libX11")] + private static extern void XResizeWindow(IntPtr display, IntPtr window, + int width, int height); + #endregion + + #region GetStaticFieldValue + private static object GetStaticFieldValue(Type type, string fieldName) + { + return type.GetField(fieldName, + BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); + } + #endregion + + #region SetStaticFieldValue + private static void SetStaticFieldValue(Type type, string fieldName, + object value) + { + type.GetField(fieldName, + BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, value); + } + #endregion + + #region CreateX11WindowInfo + public static IWindowInfo CreateX11WindowInfo(IntPtr windowHandle, + IntPtr graphicsModeHandle) + { + // Use reflection to retrieve the necessary values from Mono's + // Windows.Forms implementation. + Type xplatui = Type.GetType( + "System.Windows.Forms.XplatUIX11, System.Windows.Forms"); + if (xplatui == null) + { + throw new PlatformNotSupportedException( + "System.Windows.Forms.XplatUIX11 missing. Unsupported platform " + + "or Mono runtime version, aborting."); + } + + // get the required handles from the X11 API. + IntPtr display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle"); + IntPtr rootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow"); + int screen = (int)GetStaticFieldValue(xplatui, "ScreenNo"); + + // get the XVisualInfo for this GraphicsMode + XVisualInfo info = new XVisualInfo() + { + VisualID = graphicsModeHandle, + }; + int dummy; + IntPtr infoPtr = XGetVisualInfoInternal(display, + (IntPtr)1 /* VisualInfoMask.ID */, ref info, out dummy); + info = (XVisualInfo)Marshal.PtrToStructure(infoPtr, typeof(XVisualInfo)); + + // set the X11 colormap. + SetStaticFieldValue(xplatui, "CustomVisual", info.Visual); + SetStaticFieldValue(xplatui, "CustomColormap", XCreateColormap(display, rootWindow, info.Visual, 0)); + + return Utilities.CreateX11WindowInfo(display, screen, windowHandle, + rootWindow, infoPtr); + } + #endregion + + #region ResizeWindow + public static void ResizeWindow(IntPtr windowHandle, int backBufferWidth, + int backBufferHeight) + { + XResizeWindow(IntPtr.Zero, windowHandle, backBufferWidth, backBufferHeight); + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/Helpers/WindowsInterop.cs b/RenderSystems/ANX.Framework.GL3/Helpers/WindowsInterop.cs new file mode 100644 index 00000000..7140c5c5 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/Helpers/WindowsInterop.cs @@ -0,0 +1,69 @@ +using System; +using System.Runtime.InteropServices; + +// 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.GL3.Helpers +{ + internal static class WindowsInterop + { + #region RECT (Helper struct) + [StructLayout(LayoutKind.Sequential)] + private struct RECT + { + /// + /// X position of upper-left corner. + /// + public int Left; + /// + /// Y position of upper-left corner. + /// + public int Top; + /// + /// X position of lower-right corner. + /// + public int Right; + /// + /// Y position of lower-right corner. + /// + public int Bottom; + } + #endregion + + #region Invokes + [DllImport("user32.dll")] + private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, + int x, int y, int width, int height, uint uFlags); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect); + #endregion + + #region ResizeWindow + public static void ResizeWindow(IntPtr windowHandle, int backBufferWidth, + int backBufferHeight) + { + RECT windowRect; + RECT clientRect; + if (GetWindowRect(windowHandle, out windowRect) && + GetClientRect(windowHandle, out clientRect)) + { + int width = backBufferWidth + (windowRect.Right - windowRect.Left) - + clientRect.Right; + int height = backBufferHeight + (windowRect.Bottom - windowRect.Top) - + clientRect.Bottom; + + SetWindowPos(windowHandle, IntPtr.Zero, windowRect.Left, windowRect.Top, + width, height, 0); + } + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/IndexBufferGL3.cs b/RenderSystems/ANX.Framework.GL3/IndexBufferGL3.cs new file mode 100644 index 00000000..a980d245 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/IndexBufferGL3.cs @@ -0,0 +1,264 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA.RenderSystem; +using OpenTK.Graphics.OpenGL; +using ANX.RenderSystem.GL3.Helpers; + +// 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.GL3 +{ + /// + /// Native OpenGL implementation of a Index Buffer. + /// + public class IndexBufferGL3 : INativeIndexBuffer + { + #region Private + private IndexBuffer managedBuffer; + + private int bufferHandle; + /// + /// Native index buffer handle. + /// + internal int BufferHandle + { + get + { + return bufferHandle; + } + } + + private int indexCount; + + internal IndexElementSize elementSize; + + private BufferUsage usage; + + private BufferUsageHint usageHint; + + internal bool IsDisposed; + #endregion + + #region Constructor + /// + /// Create a new Index Buffer object. + /// + internal IndexBufferGL3(IndexBuffer setManagedBuffer, + IndexElementSize setElementSize, int setIndexCount, BufferUsage setUsage) + { + GraphicsResourceManager.UpdateResource(this, true); + + managedBuffer = setManagedBuffer; + indexCount = setIndexCount; + elementSize = setElementSize; + usage = setUsage; + + bool isDynamicBuffer = managedBuffer is DynamicIndexBuffer; + + usageHint = isDynamicBuffer ? + BufferUsageHint.DynamicDraw : + BufferUsageHint.StaticDraw; + + CreateBuffer(); + } + + ~IndexBufferGL3() + { + GraphicsResourceManager.UpdateResource(this, false); + } + #endregion + + #region CreateBuffer + private void CreateBuffer() + { + GL.GenBuffers(1, out bufferHandle); + ErrorHelper.Check("GenBuffers"); + GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferHandle); + ErrorHelper.Check("BindBuffer"); + int size = indexCount * + (elementSize == IndexElementSize.SixteenBits ? 16 : 32); + GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)size, IntPtr.Zero, + usageHint); + ErrorHelper.Check("BufferData"); + + int setSize; + GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, + BufferParameterName.BufferSize, out setSize); + if (setSize != size) + { + throw new Exception("Failed to set the vertexBuffer data. DataSize=" + + size + " SetSize=" + setSize); + } + } + #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 + { + int size = (elementSize == IndexElementSize.SixteenBits ? + 2 : 4) * data.Length; + + GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferHandle); + ErrorHelper.Check("BindBuffer"); + + if (offset == 0) + { + GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)size, data, + usageHint); + ErrorHelper.Check("BufferData size=" + size); + } + else + { + GL.BufferSubData(BufferTarget.ElementArrayBuffer, (IntPtr)offset, + (IntPtr)size, data); + ErrorHelper.Check("BufferSubData offset=" + offset + " size=" + size); + } + + int setSize; + GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, + BufferParameterName.BufferSize, out setSize); + if (setSize != size) + { + throw new Exception("Failed to set the indexBuffer data. DataSize=" + + size + " SetSize=" + setSize); + } + } + #endregion + + #region GetData + public void GetData(T[] data) where T : struct + { + BufferData(data, 0); + } + #endregion + + #region GetData + public void GetData(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 GetData + public void GetData(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 GetBufferData (private helper) + private void GetBufferData(T[] data, int offset) where T : struct + { + int size = (elementSize == IndexElementSize.SixteenBits ? + 2 : 4) * data.Length; + + GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferHandle); + ErrorHelper.Check("BindBuffer"); + + GL.GetBufferSubData(BufferTarget.ElementArrayBuffer, (IntPtr)offset, + (IntPtr)size, data); + ErrorHelper.Check("GetBufferSubData"); + } + #endregion + + #region Dispose + /// + /// Dispose the native index buffer data. + /// + public void Dispose() + { + if (IsDisposed == false) + { + IsDisposed = true; + DisposeResource(); + } + } + + internal void DisposeResource() + { + if (bufferHandle != -1 && + GraphicsDeviceWindowsGL3.IsContextCurrent) + { + GL.DeleteBuffers(1, ref bufferHandle); + ErrorHelper.Check("DeleteBuffers"); + bufferHandle = -1; + } + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/OcclusionQueryGL3.cs b/RenderSystems/ANX.Framework.GL3/OcclusionQueryGL3.cs new file mode 100644 index 00000000..00a404dc --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/OcclusionQueryGL3.cs @@ -0,0 +1,73 @@ +using ANX.Framework.NonXNA.Development; +using ANX.Framework.NonXNA.RenderSystem; +using OpenTK.Graphics.OpenGL; + +// 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.GL3 +{ + [PercentageComplete(100)] + [TestState(TestStateAttribute.TestState.Untested)] + [Developer("AstrorEnales")] + public class OcclusionQueryGL3 : IOcclusionQuery + { + private uint[] handle; + + #region Public + public bool IsComplete + { + get + { + int state; + GL.GetQueryObject(handle[0], GetQueryObjectParam.QueryResultAvailable, out state); + return state != 0; + } + } + + public int PixelCount + { + get + { + int result; + GL.GetQueryObject(handle[0], GetQueryObjectParam.QueryResult, out result); + return result; + } + } + #endregion + + #region Constructor + public OcclusionQueryGL3() + { + handle = new uint[1]; + GL.GenQueries(1, handle); + } + #endregion + + #region Begin + public void Begin() + { + //GLCore.ColorMask(false, false, false, false); + //GLCore.DepthMask(false); + GL.BeginQuery(QueryTarget.SamplesPassed, handle[0]); + } + #endregion + + #region End + public void End() + { + GL.EndQuery(QueryTarget.SamplesPassed); + //GLCore.DepthMask(true); + //GLCore.ColorMask(true, true, true, true); + } + #endregion + + #region Dispose + public void Dispose() + { + GL.DeleteQueries(1, handle); + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/Properties/AssemblyInfo.cs b/RenderSystems/ANX.Framework.GL3/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..1fe10dd5 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/Properties/AssemblyInfo.cs @@ -0,0 +1,38 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die mit einer Assembly verknüpft sind. +[assembly: AssemblyTitle("ANX.RenderSystem.GL3")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("ANX.Framework Team")] +[assembly: AssemblyProduct("ANX.RenderSystem.GL3")] +[assembly: AssemblyCopyright("Copyright © ANX.Framework Team 2011 - 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("14d07c57-8b86-4f6e-bacb-69f65aba5633")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.5.12.0")] +[assembly: AssemblyFileVersion("0.5.12.0")] + +[assembly: InternalsVisibleTo("ANX.Framework.ContentPipeline")] diff --git a/RenderSystems/ANX.Framework.GL3/RasterizerStateGL3.cs b/RenderSystems/ANX.Framework.GL3/RasterizerStateGL3.cs new file mode 100644 index 00000000..2c744e4e --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/RasterizerStateGL3.cs @@ -0,0 +1,218 @@ +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using ANX.Framework.NonXNA.Development; +using OpenTK.Graphics.OpenGL; + +// 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.GL3 +{ + /// + /// Native Rasterizer State object for OpenGL. + /// + /// Basically this is a wrapper class for setting the different values all + /// at once, because OpenGL has no State objects like DirectX. + /// + [PercentageComplete(100)] + [TestStateAttribute(TestStateAttribute.TestState.Untested)] + public class RasterizerStateGL3 : INativeRasterizerState + { + #region Private + internal static RasterizerStateGL3 Current + { + get; + private set; + } + #endregion + + #region Public + #region IsBound + /// + /// Flag if the state object is bound to the device. + /// + public bool IsBound + { + get; + private set; + } + #endregion + + #region CullMode + /// + /// The cull mode of the state object. + /// + public CullMode CullMode + { + set; + private get; + } + #endregion + + #region ScissorTestEnable + /// + /// Flag if the state object has scissor test enabled. + /// + public bool ScissorTestEnable + { + set; + private get; + } + #endregion + + #region FillMode + /// + /// The fill mode of the state object. + /// + public FillMode FillMode + { + set; + private get; + } + #endregion + + #region SlopeScaleDepthBias + /// + /// The SlopeScaleDepthBias of the state object. + /// + public float SlopeScaleDepthBias + { + set; + private get; + } + #endregion + + #region DepthBias + /// + /// The depth bias of the state object. + /// + public float DepthBias + { + set; + private get; + } + #endregion + + #region MultiSampleAntiAlias + /// + /// Flag if the state object has MSAA enabled. + /// + public bool MultiSampleAntiAlias + { + set; + private get; + } + #endregion + #endregion + + #region Constructor + /// + /// Create a new rasterizer state object. + /// + internal RasterizerStateGL3() + { + IsBound = false; + } + #endregion + + #region Apply + /// + /// Apply the rasterizer state to the graphics device. + /// + /// The current graphics device. + public void Apply(GraphicsDevice graphicsDevice) + { + IsBound = true; + Current = this; + + #region Cull Mode + GL.FrontFace(FrontFaceDirection.Cw); + ErrorHelper.Check("FrontFace"); + if (CullMode == CullMode.None) + { + GL.Disable(EnableCap.CullFace); + GL.CullFace(CullFaceMode.FrontAndBack); + } + else + { + GL.Enable(EnableCap.CullFace); + GL.CullFace(CullMode == CullMode.None ? + CullFaceMode.FrontAndBack : + CullMode == CullMode.CullClockwiseFace ? + CullFaceMode.Front : + CullFaceMode.Back); + } + ErrorHelper.Check("Set CullMode"); + #endregion + + GL.PolygonMode(MaterialFace.FrontAndBack, + FillMode == FillMode.WireFrame ? PolygonMode.Line : PolygonMode.Fill); + ErrorHelper.Check("PolygonMode"); + + #region ScissorTestEnable + if (ScissorTestEnable) + { + GL.Enable(EnableCap.ScissorTest); + } + else + { + GL.Disable(EnableCap.ScissorTest); + } + ErrorHelper.Check("Set ScissorTest"); + #endregion + + #region DepthBias / SlopeScaleDepthBias (TODO: test!) + // NOTE: http://www.opengl.org/sdk/docs/man/xhtml/glPolygonOffset.xml + + // Good article about difference between OpenGL and DirectX concerning + // Depth Bias: http://aras-p.info/blog/2008/06/12/depth-bias-and-the-power-of-deceiving-yourself/ + + if (DepthBias != 0f && + SlopeScaleDepthBias != 0f) + { + GL.Enable(EnableCap.PolygonOffsetFill); + GL.PolygonOffset(SlopeScaleDepthBias, DepthBias); + } + else + { + GL.Disable(EnableCap.PolygonOffsetFill); + } + ErrorHelper.Check("Set DepthBias"); + #endregion + + #region MultiSampleAntiAlias + if (MultiSampleAntiAlias) + { + GL.Enable(EnableCap.Multisample); + } + else + { + GL.Disable(EnableCap.Multisample); + } + ErrorHelper.Check("Set Multisample"); + #endregion + } + #endregion + + #region Release + /// + /// Release the rasterizer state. + /// + public void Release() + { + IsBound = false; + Current = null; + } + #endregion + + #region Dispose + /// + /// Dispose the rasterizer state object. + /// + public void Dispose() + { + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/RenderTarget2DGL3.cs b/RenderSystems/ANX.Framework.GL3/RenderTarget2DGL3.cs new file mode 100644 index 00000000..874c39a0 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/RenderTarget2DGL3.cs @@ -0,0 +1,144 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA.RenderSystem; +using OpenTK.Graphics.OpenGL; +using ANX.RenderSystem.GL3.Helpers; + +namespace ANX.RenderSystem.GL3 +{ + public class RenderTarget2DGL3 : Texture2DGL3, INativeRenderTarget2D + { + #region Private + private int framebufferHandle; + private int renderbufferHandle; + + private bool generateMipmaps; + #endregion + + // TODO: usage, preferredMultiSampleCount + #region Constructor + public RenderTarget2DGL3(int width, int height, bool mipMap, + SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, + int preferredMultiSampleCount, RenderTargetUsage usage) + : base() + { + generateMipmaps = mipMap; + PixelInternalFormat nativeFormat = + DatatypesMapping.SurfaceToPixelInternalFormat(preferredFormat); + + #region Image creation + NativeHandle = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, NativeHandle); + GL.TexParameter(TextureTarget.Texture2D, + TextureParameterName.TextureMagFilter, (int)All.Linear); + GL.TexParameter(TextureTarget.Texture2D, + TextureParameterName.TextureWrapS, (int)All.ClampToEdge); + GL.TexParameter(TextureTarget.Texture2D, + TextureParameterName.TextureWrapT, (int)All.ClampToEdge); + if (generateMipmaps) + { + GL.TexParameter(TextureTarget.Texture2D, + TextureParameterName.GenerateMipmap, 1); + GL.TexParameter(TextureTarget.Texture2D, + TextureParameterName.TextureMinFilter, (int)All.LinearMipmapLinear); + } + else + { + GL.TexParameter(TextureTarget.Texture2D, + TextureParameterName.TextureMinFilter, (int)All.Linear); + } + + GL.TexImage2D(TextureTarget.Texture2D, 0, nativeFormat, + width, height, 0, (PixelFormat)nativeFormat, PixelType.UnsignedByte, + IntPtr.Zero); + GL.BindTexture(TextureTarget.Texture2D, 0); + #endregion + + // create a renderbuffer object to store depth info + GL.GenRenderbuffers(1, out renderbufferHandle); + GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderbufferHandle); + GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, + DepthFormatConversion(preferredDepthFormat), width, height); + GL.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, 0); + + // create a framebuffer object + GL.GenFramebuffers(1, out framebufferHandle); + GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebufferHandle); + + // attach the texture to FBO color attachment point + GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, + FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, + NativeHandle, 0); + + // attach the renderbuffer to depth attachment point + GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, + FramebufferAttachment.DepthAttachment, + RenderbufferTarget.Renderbuffer, renderbufferHandle); + + // check FBO status + FramebufferErrorCode status = GL.CheckFramebufferStatus( + FramebufferTarget.Framebuffer); + if (status != FramebufferErrorCode.FramebufferComplete) + { + throw new InvalidOperationException( + "Failed to create the render target! Error=" + status); + } + + // switch back to window-system-provided framebuffer + GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); + } + #endregion + + #region DepthFormatConversion + private RenderbufferStorage DepthFormatConversion(DepthFormat depthFormat) + { + switch(depthFormat) + { + default: + case DepthFormat.None: + // TODO + return RenderbufferStorage.DepthComponent16; + //return (RenderbufferStorage)All.DepthComponent; + + case DepthFormat.Depth16: + return RenderbufferStorage.DepthComponent16; + + case DepthFormat.Depth24: + return RenderbufferStorage.DepthComponent24; + + case DepthFormat.Depth24Stencil8: + return RenderbufferStorage.DepthComponent32; + } + } + #endregion + + #region Bind + public void Bind() + { + GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebufferHandle); + } + #endregion + + #region Unbind + public void Unbind() + { + GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); + if (generateMipmaps) + { + GL.BindTexture(TextureTarget.Texture2D, NativeHandle); + GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); + GL.BindTexture(TextureTarget.Texture2D, 0); + } + } + #endregion + + #region Dispose + public override void Dispose() + { + base.Dispose(); + GL.DeleteFramebuffers(1, ref framebufferHandle); + GL.DeleteRenderbuffers(1, ref renderbufferHandle); + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/SamplerStateGL3.cs b/RenderSystems/ANX.Framework.GL3/SamplerStateGL3.cs new file mode 100644 index 00000000..06f31314 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/SamplerStateGL3.cs @@ -0,0 +1,139 @@ +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using ANX.Framework.NonXNA.Development; + +// 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.GL3 +{ + /// + /// Native Sampler State object for OpenGL. + /// + /// Basically this is a wrapper class for setting the different values all + /// at once, because OpenGL has no State objects like DirectX. + /// + /// Info for OpenGL filter states: + /// http://gregs-blog.com/2008/01/17/opengl-texture-filter-parameters-explained/ + /// + /// Info for OGL 3.3 sampler objects (sadly not implemented in OpenTK yet): + /// http://www.sinanc.org/blog/?p=215 + /// + [PercentageComplete(10)] + [TestState(TestStateAttribute.TestState.Untested)] + public class SamplerStateGL3 : INativeSamplerState + { + #region Public + #region IsBound + /// + /// Flag if the state object is bound to the device. + /// + public bool IsBound + { + get; + private set; + } + #endregion + + #region AddressU + public TextureAddressMode AddressU + { + set; + private get; + } + #endregion + + #region AddressV + public TextureAddressMode AddressV + { + set; + private get; + } + #endregion + + #region AddressW + public TextureAddressMode AddressW + { + set; + private get; + } + #endregion + + #region Filter + public TextureFilter Filter + { + set; + private get; + } + #endregion + + #region MaxAnisotropy + public int MaxAnisotropy + { + set; + private get; + } + #endregion + + #region MaxMipLevel + public int MaxMipLevel + { + set; + private get; + } + #endregion + + #region MipMapLevelOfDetailBias + public float MipMapLevelOfDetailBias + { + set; + private get; + } + #endregion + #endregion + + #region Constructor + /// + /// Create a new sampler state object. + /// + internal SamplerStateGL3() + { + IsBound = false; + } + #endregion + + #region Apply + /// + /// Apply the sampler state. + /// + /// Graphics device. + /// The index of which sampler should be modified. + public void Apply(GraphicsDevice graphicsDevice, int index) + { + IsBound = true; + + // TODO: set stuff + } + #endregion + + #region Release + /// + /// Release the sampler state. + /// + public void Release() + { + IsBound = false; + } + #endregion + + #region Dispose + /// + /// Dispose the sampler state object. + /// + public void Dispose() + { + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/ShaderAttributeGL3.cs b/RenderSystems/ANX.Framework.GL3/ShaderAttributeGL3.cs new file mode 100644 index 00000000..d180e776 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/ShaderAttributeGL3.cs @@ -0,0 +1,81 @@ +using System; +using OpenTK.Graphics.OpenGL; +using ANX.Framework.Graphics; + +namespace ANX.RenderSystem.GL3 +{ + public struct ShaderAttributeGL3 + { + #region Public + public string Name; + public int Location; + public int Size; + public ActiveAttribType Type; + #endregion + + #region Constructor + public ShaderAttributeGL3(int programHandle, int index) + { + Name = GL.GetActiveAttrib(programHandle, index, out Size, out Type); + Location = GL.GetAttribLocation(programHandle, Name); + } + #endregion + + #region Bind + public void Bind(VertexElementUsage usage, int stride, int offset) + { + GL.EnableVertexAttribArray(Location); + ErrorHelper.Check("Failed to bind shader attribute " + Name); + + int size = 0; + VertexAttribPointerType type = VertexAttribPointerType.Float; + bool normalized = false; + + switch (usage) + { + case VertexElementUsage.Binormal: + case VertexElementUsage.Normal: + case VertexElementUsage.Tangent: + case VertexElementUsage.BlendIndices: + case VertexElementUsage.BlendWeight: + case VertexElementUsage.Position: + size = 3; + break; + + case VertexElementUsage.Color: + size = 4; + type = VertexAttribPointerType.UnsignedByte; + normalized = true; + break; + + case VertexElementUsage.TextureCoordinate: + size = 2; + break; + + case VertexElementUsage.Fog: + case VertexElementUsage.PointSize: + case VertexElementUsage.TessellateFactor: + size = 1; + break; + + // TODO + case VertexElementUsage.Depth: + case VertexElementUsage.Sample: + throw new NotImplementedException(); + } + + GL.VertexAttribPointer(Location, size, type, normalized, stride, (IntPtr)offset); + } + #endregion + + #region ToString + public override string ToString() + { + return "ShaderAttribute{Name: " + Name + + ", Location: " + Location + + ", Size: " + Size + + ", Type: " + Type + "}"; + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/ShaderByteCode.cs b/RenderSystems/ANX.Framework.GL3/ShaderByteCode.cs new file mode 100644 index 00000000..80d75f43 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/ShaderByteCode.cs @@ -0,0 +1,437 @@ +using System; + +// 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.Framework.GL3 +{ + internal static class ShaderByteCode + { + #region SpriteBatchShader + internal static byte[] SpriteBatchByteCode = new byte[] + { + 187, 004, 118, 101, 114, 116, 101, 120, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 083, 112, 114, 105, 116, 101, + 086, 101, 114, 116, 101, 120, 083, 104, 097, 100, 101, 114, 034, 123, 117, + 110, 105, 102, 111, 114, 109, 032, 109, 097, 116, 052, 032, 077, 097, 116, + 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, 059, 097, 116, + 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, + 115, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, + 052, 032, 099, 111, 108, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, + 032, 118, 101, 099, 050, 032, 116, 101, 120, 059, 118, 097, 114, 121, 105, + 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, + 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, + 111, 111, 114, 100, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, + 032, 041, 123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, + 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, + 042, 112, 111, 115, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, + 067, 111, 111, 114, 100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 061, 099, 111, 108, 059, 125, 125, 125, + 102, 114, 097, 103, 109, 101, 110, 116, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 083, 112, 114, 105, 116, 101, + 070, 114, 097, 103, 109, 101, 110, 116, 083, 104, 097, 100, 101, 114, 034, + 123, 117, 110, 105, 102, 111, 114, 109, 032, 115, 097, 109, 112, 108, 101, + 114, 050, 068, 032, 084, 101, 120, 116, 117, 114, 101, 059, 118, 097, 114, + 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 059, 118, 097, 114, 121, 105, 110, 103, + 032, 118, 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, + 120, 067, 111, 111, 114, 100, 059, 118, 111, 105, 100, 032, 109, 097, 105, + 110, 040, 032, 041, 123, 103, 108, 095, 070, 114, 097, 103, 067, 111, 108, + 111, 114, 061, 116, 101, 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, + 120, 116, 117, 114, 101, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, + 120, 067, 111, 111, 114, 100, 041, 042, 100, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 059, 125, 125, 125, 116, 101, 099, 104, 110, 105, + 113, 117, 101, 115, 123, 116, 101, 099, 104, 110, 105, 113, 117, 101, 032, + 034, 083, 112, 114, 105, 116, 101, 084, 101, 099, 104, 110, 105, 113, 117, + 101, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 083, 112, 114, 105, + 116, 101, 086, 101, 114, 116, 101, 120, 083, 104, 097, 100, 101, 114, 034, + 102, 114, 097, 103, 109, 101, 110, 116, 032, 034, 083, 112, 114, 105, 116, + 101, 070, 114, 097, 103, 109, 101, 110, 116, 083, 104, 097, 100, 101, 114, + 034, 125, 125, 085, 005, 093, 183, 066, 090, 070, 104, 093, 184, 253, 199, + 246, 081, 152, 083, 013, 048, 171, 074, 063, 021, 247, 182, 129, 011, 094, + 003, 189, 026, 178, 121, 230, 157, 193, 056, 001, 064, 136, 044, 054, 172, + 146, 241, 173, 160, 182, 034, 092, 221, 158, 045, 049, 229, 144, 171, 015, + 022, 089, 025, 248, 163, 175, 081 + }; + #endregion //SpriteBatchShader + + #region AlphaTestEffectShader + internal static byte[] AlphaTestEffectByteCode = new byte[] + { + 187, 004, 118, 101, 114, 116, 101, 120, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 083, 112, 114, 105, 116, 101, + 086, 101, 114, 116, 101, 120, 083, 104, 097, 100, 101, 114, 034, 123, 117, + 110, 105, 102, 111, 114, 109, 032, 109, 097, 116, 052, 032, 077, 097, 116, + 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, 059, 097, 116, + 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, + 115, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, + 052, 032, 099, 111, 108, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, + 032, 118, 101, 099, 050, 032, 116, 101, 120, 059, 118, 097, 114, 121, 105, + 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, + 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, + 111, 111, 114, 100, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, + 032, 041, 123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, + 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, + 042, 112, 111, 115, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, + 067, 111, 111, 114, 100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 061, 099, 111, 108, 059, 125, 125, 125, + 102, 114, 097, 103, 109, 101, 110, 116, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 083, 112, 114, 105, 116, 101, + 070, 114, 097, 103, 109, 101, 110, 116, 083, 104, 097, 100, 101, 114, 034, + 123, 117, 110, 105, 102, 111, 114, 109, 032, 115, 097, 109, 112, 108, 101, + 114, 050, 068, 032, 084, 101, 120, 116, 117, 114, 101, 059, 118, 097, 114, + 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 059, 118, 097, 114, 121, 105, 110, 103, + 032, 118, 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, + 120, 067, 111, 111, 114, 100, 059, 118, 111, 105, 100, 032, 109, 097, 105, + 110, 040, 032, 041, 123, 103, 108, 095, 070, 114, 097, 103, 067, 111, 108, + 111, 114, 061, 116, 101, 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, + 120, 116, 117, 114, 101, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, + 120, 067, 111, 111, 114, 100, 041, 042, 100, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 059, 125, 125, 125, 116, 101, 099, 104, 110, 105, + 113, 117, 101, 115, 123, 116, 101, 099, 104, 110, 105, 113, 117, 101, 032, + 034, 083, 112, 114, 105, 116, 101, 084, 101, 099, 104, 110, 105, 113, 117, + 101, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 083, 112, 114, 105, + 116, 101, 086, 101, 114, 116, 101, 120, 083, 104, 097, 100, 101, 114, 034, + 102, 114, 097, 103, 109, 101, 110, 116, 032, 034, 083, 112, 114, 105, 116, + 101, 070, 114, 097, 103, 109, 101, 110, 116, 083, 104, 097, 100, 101, 114, + 034, 125, 125, 085, 005, 093, 183, 066, 090, 070, 104, 093, 184, 253, 199, + 246, 081, 152, 083, 013, 048, 171, 074, 063, 021, 247, 182, 129, 011, 094, + 003, 189, 026, 178, 121, 230, 157, 193, 056, 001, 064, 136, 044, 054, 172, + 146, 241, 173, 160, 182, 034, 092, 221, 158, 045, 049, 229, 144, 171, 015, + 022, 089, 025, 248, 163, 175, 081 + }; + #endregion //AlphaTestEffectShader + + #region BasicEffectShader + internal static byte[] BasicEffectByteCode = new byte[] + { + 187, 004, 118, 101, 114, 116, 101, 120, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 083, 112, 114, 105, 116, 101, + 086, 101, 114, 116, 101, 120, 083, 104, 097, 100, 101, 114, 034, 123, 117, + 110, 105, 102, 111, 114, 109, 032, 109, 097, 116, 052, 032, 077, 097, 116, + 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, 059, 097, 116, + 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, + 115, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, + 052, 032, 099, 111, 108, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, + 032, 118, 101, 099, 050, 032, 116, 101, 120, 059, 118, 097, 114, 121, 105, + 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, + 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, + 111, 111, 114, 100, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, + 032, 041, 123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, + 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, + 042, 112, 111, 115, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, + 067, 111, 111, 114, 100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 061, 099, 111, 108, 059, 125, 125, 125, + 102, 114, 097, 103, 109, 101, 110, 116, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 083, 112, 114, 105, 116, 101, + 070, 114, 097, 103, 109, 101, 110, 116, 083, 104, 097, 100, 101, 114, 034, + 123, 117, 110, 105, 102, 111, 114, 109, 032, 115, 097, 109, 112, 108, 101, + 114, 050, 068, 032, 084, 101, 120, 116, 117, 114, 101, 059, 118, 097, 114, + 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 059, 118, 097, 114, 121, 105, 110, 103, + 032, 118, 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, + 120, 067, 111, 111, 114, 100, 059, 118, 111, 105, 100, 032, 109, 097, 105, + 110, 040, 032, 041, 123, 103, 108, 095, 070, 114, 097, 103, 067, 111, 108, + 111, 114, 061, 116, 101, 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, + 120, 116, 117, 114, 101, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, + 120, 067, 111, 111, 114, 100, 041, 042, 100, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 059, 125, 125, 125, 116, 101, 099, 104, 110, 105, + 113, 117, 101, 115, 123, 116, 101, 099, 104, 110, 105, 113, 117, 101, 032, + 034, 083, 112, 114, 105, 116, 101, 084, 101, 099, 104, 110, 105, 113, 117, + 101, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 083, 112, 114, 105, + 116, 101, 086, 101, 114, 116, 101, 120, 083, 104, 097, 100, 101, 114, 034, + 102, 114, 097, 103, 109, 101, 110, 116, 032, 034, 083, 112, 114, 105, 116, + 101, 070, 114, 097, 103, 109, 101, 110, 116, 083, 104, 097, 100, 101, 114, + 034, 125, 125, 085, 005, 093, 183, 066, 090, 070, 104, 093, 184, 253, 199, + 246, 081, 152, 083, 013, 048, 171, 074, 063, 021, 247, 182, 129, 011, 094, + 003, 189, 026, 178, 121, 230, 157, 193, 056, 001, 064, 136, 044, 054, 172, + 146, 241, 173, 160, 182, 034, 092, 221, 158, 045, 049, 229, 144, 171, 015, + 022, 089, 025, 248, 163, 175, 081 + }; + #endregion //BasicEffectShader + + #region DualTextureEffectShader + internal static byte[] DualTextureEffectByteCode = new byte[] + { + 228, 019, 118, 101, 114, 116, 101, 120, 103, 108, 111, 098, 097, 108, 123, + 117, 110, 105, 102, 111, 114, 109, 032, 118, 101, 099, 052, 032, 068, 105, + 102, 102, 117, 115, 101, 067, 111, 108, 111, 114, 059, 117, 110, 105, 102, + 111, 114, 109, 032, 118, 101, 099, 052, 032, 070, 111, 103, 086, 101, 099, + 116, 111, 114, 059, 117, 110, 105, 102, 111, 114, 109, 032, 109, 097, 116, + 052, 032, 087, 111, 114, 108, 100, 086, 105, 101, 119, 080, 114, 111, 106, + 059, 125, 118, 101, 114, 116, 101, 120, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 086, 083, 068, 117, 097, 108, + 084, 101, 120, 116, 117, 114, 101, 034, 123, 097, 116, 116, 114, 105, 098, + 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 097, 116, + 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, 101, + 120, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, + 050, 032, 116, 101, 120, 050, 059, 118, 097, 114, 121, 105, 110, 103, 032, + 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, 059, 118, 097, + 114, 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 115, 112, 101, 099, + 117, 108, 097, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, + 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, + 111, 114, 100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, + 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, + 114, 100, 050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032, + 041, 123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, 087, + 111, 114, 108, 100, 086, 105, 101, 119, 080, 114, 111, 106, 042, 112, 111, + 115, 059, 100, 105, 102, 102, 117, 115, 101, 061, 068, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 059, 115, 112, 101, 099, 117, 108, 097, + 114, 061, 118, 101, 099, 052, 040, 048, 044, 048, 044, 048, 044, 115, 097, + 116, 117, 114, 097, 116, 101, 040, 100, 111, 116, 040, 112, 111, 115, 044, + 070, 111, 103, 086, 101, 099, 116, 111, 114, 041, 041, 041, 059, 100, 105, + 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 061, 116, + 101, 120, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, + 111, 114, 100, 050, 061, 116, 101, 120, 050, 059, 125, 125, 115, 104, 097, + 100, 101, 114, 032, 034, 086, 083, 068, 117, 097, 108, 084, 101, 120, 116, + 117, 114, 101, 078, 111, 070, 111, 103, 034, 123, 097, 116, 116, 114, 105, + 098, 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 097, + 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, + 101, 120, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, + 099, 050, 032, 116, 101, 120, 050, 059, 118, 097, 114, 121, 105, 110, 103, + 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, 059, 118, + 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, 032, 100, 105, 102, + 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 059, 118, 097, + 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, 032, 100, 105, 102, 102, + 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 050, 059, 118, 111, + 105, 100, 032, 109, 097, 105, 110, 040, 032, 041, 123, 103, 108, 095, 080, + 111, 115, 105, 116, 105, 111, 110, 061, 087, 111, 114, 108, 100, 086, 105, + 101, 119, 080, 114, 111, 106, 042, 112, 111, 115, 059, 100, 105, 102, 102, + 117, 115, 101, 061, 068, 105, 102, 102, 117, 115, 101, 067, 111, 108, 111, + 114, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, + 114, 100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, 115, 101, 084, + 101, 120, 067, 111, 111, 114, 100, 050, 061, 116, 101, 120, 050, 059, 125, + 125, 115, 104, 097, 100, 101, 114, 032, 034, 086, 083, 068, 117, 097, 108, + 084, 101, 120, 116, 117, 114, 101, 086, 101, 114, 116, 101, 120, 067, 111, + 108, 111, 114, 034, 123, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, + 118, 101, 099, 052, 032, 112, 111, 115, 059, 097, 116, 116, 114, 105, 098, + 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, 101, 120, 059, 097, 116, + 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, 101, + 120, 050, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, + 099, 052, 032, 099, 111, 108, 059, 118, 097, 114, 121, 105, 110, 103, 032, + 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, 059, 118, 097, + 114, 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 115, 112, 101, 099, + 117, 108, 097, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, + 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, + 111, 114, 100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, + 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, + 114, 100, 050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032, + 041, 123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, 087, + 111, 114, 108, 100, 086, 105, 101, 119, 080, 114, 111, 106, 042, 112, 111, + 115, 059, 100, 105, 102, 102, 117, 115, 101, 061, 068, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 042, 099, 111, 108, 059, 115, 112, 101, + 099, 117, 108, 097, 114, 061, 118, 101, 099, 052, 040, 048, 044, 048, 044, + 048, 044, 115, 097, 116, 117, 114, 097, 116, 101, 040, 100, 111, 116, 040, + 112, 111, 115, 044, 070, 111, 103, 086, 101, 099, 116, 111, 114, 041, 041, + 041, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, + 114, 100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, 115, 101, 084, + 101, 120, 067, 111, 111, 114, 100, 050, 061, 116, 101, 120, 050, 059, 125, + 125, 115, 104, 097, 100, 101, 114, 032, 034, 086, 083, 068, 117, 097, 108, + 084, 101, 120, 116, 117, 114, 101, 086, 101, 114, 116, 101, 120, 067, 111, + 108, 111, 114, 078, 111, 070, 111, 103, 034, 123, 097, 116, 116, 114, 105, + 098, 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 097, + 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, + 101, 120, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, + 099, 050, 032, 116, 101, 120, 050, 059, 097, 116, 116, 114, 105, 098, 117, + 116, 101, 032, 118, 101, 099, 052, 032, 099, 111, 108, 059, 118, 097, 114, + 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, + 115, 101, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, + 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, + 100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, 032, + 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, + 050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032, 041, 123, + 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, 087, 111, 114, + 108, 100, 086, 105, 101, 119, 080, 114, 111, 106, 042, 112, 111, 115, 059, + 100, 105, 102, 102, 117, 115, 101, 061, 068, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 042, 099, 111, 108, 059, 100, 105, 102, 102, 117, + 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 061, 116, 101, 120, 059, + 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, + 050, 061, 116, 101, 120, 050, 059, 125, 125, 125, 102, 114, 097, 103, 109, + 101, 110, 116, 103, 108, 111, 098, 097, 108, 123, 117, 110, 105, 102, 111, + 114, 109, 032, 115, 097, 109, 112, 108, 101, 114, 050, 068, 032, 084, 101, + 120, 116, 117, 114, 101, 059, 117, 110, 105, 102, 111, 114, 109, 032, 115, + 097, 109, 112, 108, 101, 114, 050, 068, 032, 084, 101, 120, 116, 117, 114, + 101, 050, 059, 117, 110, 105, 102, 111, 114, 109, 032, 118, 101, 099, 051, + 032, 070, 111, 103, 067, 111, 108, 111, 114, 059, 125, 102, 114, 097, 103, + 109, 101, 110, 116, 115, 104, 097, 100, 101, 114, 115, 123, 115, 104, 097, + 100, 101, 114, 032, 034, 080, 083, 068, 117, 097, 108, 084, 101, 120, 116, + 117, 114, 101, 034, 123, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, + 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, 059, 118, 097, 114, 121, + 105, 110, 103, 032, 118, 101, 099, 052, 032, 115, 112, 101, 099, 117, 108, + 097, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, + 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, + 100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, 032, + 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, + 050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032, 041, 123, + 118, 101, 099, 052, 032, 099, 111, 108, 111, 114, 061, 116, 101, 120, 116, + 117, 114, 101, 050, 068, 040, 084, 101, 120, 116, 117, 114, 101, 044, 100, + 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 041, + 059, 118, 101, 099, 052, 032, 111, 118, 101, 114, 108, 097, 121, 061, 116, + 101, 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, 120, 116, 117, 114, + 101, 050, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, + 111, 114, 100, 050, 041, 059, 099, 111, 108, 111, 114, 046, 114, 103, 098, + 032, 042, 061, 032, 050, 059, 099, 111, 108, 111, 114, 032, 042, 061, 032, + 111, 118, 101, 114, 108, 097, 121, 042, 100, 105, 102, 102, 117, 115, 101, + 059, 099, 111, 108, 111, 114, 046, 114, 103, 098, 061, 108, 101, 114, 112, + 040, 099, 111, 108, 111, 114, 046, 114, 103, 098, 044, 070, 111, 103, 067, + 111, 108, 111, 114, 042, 099, 111, 108, 111, 114, 046, 097, 044, 115, 112, + 101, 099, 117, 108, 097, 114, 046, 119, 041, 059, 103, 108, 095, 070, 114, + 097, 103, 067, 111, 108, 111, 114, 061, 099, 111, 108, 111, 114, 059, 125, + 125, 115, 104, 097, 100, 101, 114, 032, 034, 080, 083, 068, 117, 097, 108, + 084, 101, 120, 116, 117, 114, 101, 078, 111, 070, 111, 103, 034, 123, 118, + 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, + 102, 117, 115, 101, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, + 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, + 111, 114, 100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, + 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, + 114, 100, 050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032, + 041, 123, 118, 101, 099, 052, 032, 099, 111, 108, 111, 114, 061, 116, 101, + 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, 120, 116, 117, 114, 101, + 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, + 100, 041, 059, 118, 101, 099, 052, 032, 111, 118, 101, 114, 108, 097, 121, + 061, 116, 101, 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, 120, 116, + 117, 114, 101, 050, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, + 067, 111, 111, 114, 100, 050, 041, 059, 099, 111, 108, 111, 114, 046, 114, + 103, 098, 032, 042, 061, 032, 050, 059, 099, 111, 108, 111, 114, 032, 042, + 061, 032, 111, 118, 101, 114, 108, 097, 121, 042, 100, 105, 102, 102, 117, + 115, 101, 059, 103, 108, 095, 070, 114, 097, 103, 067, 111, 108, 111, 114, + 061, 099, 111, 108, 111, 114, 059, 125, 125, 125, 116, 101, 099, 104, 110, + 105, 113, 117, 101, 115, 123, 116, 101, 099, 104, 110, 105, 113, 117, 101, + 032, 034, 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, 069, 102, + 102, 101, 099, 116, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 086, + 083, 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, 034, 102, 114, + 097, 103, 109, 101, 110, 116, 032, 034, 080, 083, 068, 117, 097, 108, 084, + 101, 120, 116, 117, 114, 101, 034, 125, 116, 101, 099, 104, 110, 105, 113, + 117, 101, 032, 034, 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, + 069, 102, 102, 101, 099, 116, 078, 111, 070, 111, 103, 034, 123, 118, 101, + 114, 116, 101, 120, 032, 034, 086, 083, 068, 117, 097, 108, 084, 101, 120, + 116, 117, 114, 101, 078, 111, 070, 111, 103, 034, 102, 114, 097, 103, 109, + 101, 110, 116, 032, 034, 080, 083, 068, 117, 097, 108, 084, 101, 120, 116, + 117, 114, 101, 078, 111, 070, 111, 103, 034, 125, 116, 101, 099, 104, 110, + 105, 113, 117, 101, 032, 034, 068, 117, 097, 108, 084, 101, 120, 116, 117, + 114, 101, 069, 102, 102, 101, 099, 116, 086, 101, 114, 116, 101, 120, 067, + 111, 108, 111, 114, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 086, + 083, 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, 086, 101, 114, + 116, 101, 120, 067, 111, 108, 111, 114, 034, 102, 114, 097, 103, 109, 101, + 110, 116, 032, 034, 080, 083, 068, 117, 097, 108, 084, 101, 120, 116, 117, + 114, 101, 034, 125, 116, 101, 099, 104, 110, 105, 113, 117, 101, 032, 034, + 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, 069, 102, 102, 101, + 099, 116, 078, 111, 070, 111, 103, 086, 101, 114, 116, 101, 120, 067, 111, + 108, 111, 114, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 086, 083, + 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, 086, 101, 114, 116, + 101, 120, 067, 111, 108, 111, 114, 078, 111, 070, 111, 103, 034, 102, 114, + 097, 103, 109, 101, 110, 116, 032, 034, 080, 083, 068, 117, 097, 108, 084, + 101, 120, 116, 117, 114, 101, 078, 111, 070, 111, 103, 034, 125, 125, 175, + 031, 128, 135, 091, 053, 148, 130, 202, 159, 176, 084, 033, 124, 189, 185, + 203, 176, 133, 157, 191, 216, 029, 170, 061, 255, 076, 118, 188, 098, 065, + 207, 215, 039, 153, 215, 233, 181, 035, 132, 019, 152, 136, 212, 164, 051, + 001, 074, 135, 233, 177, 169, 110, 009, 048, 124, 035, 141, 123, 034, 179, + 143, 110, 122 + }; + #endregion //DualTextureEffectShader + + #region EnvironmentMapEffectShader + internal static byte[] EnvironmentMapEffectByteCode = new byte[] + { + 187, 004, 118, 101, 114, 116, 101, 120, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 083, 112, 114, 105, 116, 101, + 086, 101, 114, 116, 101, 120, 083, 104, 097, 100, 101, 114, 034, 123, 117, + 110, 105, 102, 111, 114, 109, 032, 109, 097, 116, 052, 032, 077, 097, 116, + 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, 059, 097, 116, + 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, + 115, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, + 052, 032, 099, 111, 108, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, + 032, 118, 101, 099, 050, 032, 116, 101, 120, 059, 118, 097, 114, 121, 105, + 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, + 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, + 111, 111, 114, 100, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, + 032, 041, 123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, + 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, + 042, 112, 111, 115, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, + 067, 111, 111, 114, 100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 061, 099, 111, 108, 059, 125, 125, 125, + 102, 114, 097, 103, 109, 101, 110, 116, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 083, 112, 114, 105, 116, 101, + 070, 114, 097, 103, 109, 101, 110, 116, 083, 104, 097, 100, 101, 114, 034, + 123, 117, 110, 105, 102, 111, 114, 109, 032, 115, 097, 109, 112, 108, 101, + 114, 050, 068, 032, 084, 101, 120, 116, 117, 114, 101, 059, 118, 097, 114, + 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 059, 118, 097, 114, 121, 105, 110, 103, + 032, 118, 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, + 120, 067, 111, 111, 114, 100, 059, 118, 111, 105, 100, 032, 109, 097, 105, + 110, 040, 032, 041, 123, 103, 108, 095, 070, 114, 097, 103, 067, 111, 108, + 111, 114, 061, 116, 101, 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, + 120, 116, 117, 114, 101, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, + 120, 067, 111, 111, 114, 100, 041, 042, 100, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 059, 125, 125, 125, 116, 101, 099, 104, 110, 105, + 113, 117, 101, 115, 123, 116, 101, 099, 104, 110, 105, 113, 117, 101, 032, + 034, 083, 112, 114, 105, 116, 101, 084, 101, 099, 104, 110, 105, 113, 117, + 101, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 083, 112, 114, 105, + 116, 101, 086, 101, 114, 116, 101, 120, 083, 104, 097, 100, 101, 114, 034, + 102, 114, 097, 103, 109, 101, 110, 116, 032, 034, 083, 112, 114, 105, 116, + 101, 070, 114, 097, 103, 109, 101, 110, 116, 083, 104, 097, 100, 101, 114, + 034, 125, 125, 085, 005, 093, 183, 066, 090, 070, 104, 093, 184, 253, 199, + 246, 081, 152, 083, 013, 048, 171, 074, 063, 021, 247, 182, 129, 011, 094, + 003, 189, 026, 178, 121, 230, 157, 193, 056, 001, 064, 136, 044, 054, 172, + 146, 241, 173, 160, 182, 034, 092, 221, 158, 045, 049, 229, 144, 171, 015, + 022, 089, 025, 248, 163, 175, 081 + }; + #endregion //EnvironmentMapEffectShader + + #region SkinnedEffectShader + internal static byte[] SkinnedEffectByteCode = new byte[] + { + 187, 004, 118, 101, 114, 116, 101, 120, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 083, 112, 114, 105, 116, 101, + 086, 101, 114, 116, 101, 120, 083, 104, 097, 100, 101, 114, 034, 123, 117, + 110, 105, 102, 111, 114, 109, 032, 109, 097, 116, 052, 032, 077, 097, 116, + 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, 059, 097, 116, + 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, + 115, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, + 052, 032, 099, 111, 108, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, + 032, 118, 101, 099, 050, 032, 116, 101, 120, 059, 118, 097, 114, 121, 105, + 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, + 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, + 111, 111, 114, 100, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, + 032, 041, 123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, + 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, + 042, 112, 111, 115, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, + 067, 111, 111, 114, 100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 061, 099, 111, 108, 059, 125, 125, 125, + 102, 114, 097, 103, 109, 101, 110, 116, 115, 104, 097, 100, 101, 114, 115, + 123, 115, 104, 097, 100, 101, 114, 032, 034, 083, 112, 114, 105, 116, 101, + 070, 114, 097, 103, 109, 101, 110, 116, 083, 104, 097, 100, 101, 114, 034, + 123, 117, 110, 105, 102, 111, 114, 109, 032, 115, 097, 109, 112, 108, 101, + 114, 050, 068, 032, 084, 101, 120, 116, 117, 114, 101, 059, 118, 097, 114, + 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, + 115, 101, 067, 111, 108, 111, 114, 059, 118, 097, 114, 121, 105, 110, 103, + 032, 118, 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, + 120, 067, 111, 111, 114, 100, 059, 118, 111, 105, 100, 032, 109, 097, 105, + 110, 040, 032, 041, 123, 103, 108, 095, 070, 114, 097, 103, 067, 111, 108, + 111, 114, 061, 116, 101, 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, + 120, 116, 117, 114, 101, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, + 120, 067, 111, 111, 114, 100, 041, 042, 100, 105, 102, 102, 117, 115, 101, + 067, 111, 108, 111, 114, 059, 125, 125, 125, 116, 101, 099, 104, 110, 105, + 113, 117, 101, 115, 123, 116, 101, 099, 104, 110, 105, 113, 117, 101, 032, + 034, 083, 112, 114, 105, 116, 101, 084, 101, 099, 104, 110, 105, 113, 117, + 101, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 083, 112, 114, 105, + 116, 101, 086, 101, 114, 116, 101, 120, 083, 104, 097, 100, 101, 114, 034, + 102, 114, 097, 103, 109, 101, 110, 116, 032, 034, 083, 112, 114, 105, 116, + 101, 070, 114, 097, 103, 109, 101, 110, 116, 083, 104, 097, 100, 101, 114, + 034, 125, 125, 085, 005, 093, 183, 066, 090, 070, 104, 093, 184, 253, 199, + 246, 081, 152, 083, 013, 048, 171, 074, 063, 021, 247, 182, 129, 011, 094, + 003, 189, 026, 178, 121, 230, 157, 193, 056, 001, 064, 136, 044, 054, 172, + 146, 241, 173, 160, 182, 034, 092, 221, 158, 045, 049, 229, 144, 171, 015, + 022, 089, 025, 248, 163, 175, 081 + }; + #endregion //SkinnedEffectShader + + } +} diff --git a/RenderSystems/ANX.Framework.GL3/ShaderData.cs b/RenderSystems/ANX.Framework.GL3/ShaderData.cs new file mode 100644 index 00000000..5037c8c9 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/ShaderData.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using StringPair = System.Collections.Generic.KeyValuePair; + +// 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.GL3 +{ + public class ShaderData + { + public string VertexGlobalCode; + + public Dictionary VertexShaderCodes; + + public string FragmentGlobalCode; + + public Dictionary FragmentShaderCodes; + + public Dictionary Techniques; + + public ShaderData() + { + VertexShaderCodes = new Dictionary(); + FragmentShaderCodes = new Dictionary(); + Techniques = new Dictionary(); + } + } +} diff --git a/RenderSystems/ANX.Framework.GL3/ShaderHelper.cs b/RenderSystems/ANX.Framework.GL3/ShaderHelper.cs new file mode 100644 index 00000000..82730895 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/ShaderHelper.cs @@ -0,0 +1,362 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Security.Cryptography; +using StringPair = System.Collections.Generic.KeyValuePair; + +// 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.GL3 +{ + public static class ShaderHelper + { + #region SaveShaderCode (for external) + public static byte[] SaveShaderCode(string effectCode) + { + effectCode = CleanCode(effectCode); + + MemoryStream stream = new MemoryStream(); + BinaryWriter writer = new BinaryWriter(stream); + + // First of all writer the shader code (which is already preceeded + // by a length identifier, making it harder to manipulate the code) + writer.Write(effectCode); + + // And now we additionally generate a sha hash so it nearly becomes + // impossible to manipulate the shader. + using (SHA512Managed sha = new SHA512Managed()) + { + byte[] data = stream.ToArray(); + byte[] hash = sha.ComputeHash(data); + // The hash is added to the end of the stream. + writer.Write(hash); + writer.Flush(); + } + + return stream.ToArray(); + } + #endregion + + #region LoadShaderCode + public static string LoadShaderCode(Stream stream) + { + BinaryReader reader = new BinaryReader(stream); + // First load the source. + string source = reader.ReadString(); + byte[] hash; + // And now check if it was manipulated. + using (SHA512Managed sha = new SHA512Managed()) + { + int lengthRead = (int)stream.Position; + stream.Position = 0; + byte[] data = reader.ReadBytes(lengthRead); + hash = sha.ComputeHash(data); + } + byte[] loadedHash = reader.ReadBytes(64); + for (int index = 0; index < hash.Length; index++) + { + if (hash[index] != loadedHash[index]) + { + throw new InvalidDataException("Failed to load the shader " + + "because the data got manipulated!"); + } + } + + return source; + } + #endregion + + #region CleanCode + private static string CleanCode(string input) + { + // We wanna clean up the shader a little bit, so we remove + // empty lines, spaces and tabs at beginning and end and also + // remove comments. + List lines = new List(input.Split('\n')); + input = ""; + for (int index = lines.Count - 1; index >= 0; index--) + { + lines[index] = lines[index].Trim(); + if (String.IsNullOrEmpty(lines[index]) || + lines[index].StartsWith("//")) + { + lines.RemoveAt(index); + continue; + } + + input = lines[index] + input; + } + + #region Multiline comment removing + input = input.Replace("/*/*", "/* /*"); + input = input.Replace("*/*/", "*/ */"); + + int length = input.Length; + int foundStartIndex = -1; + int openCommentsCount = 0; + for (int index = 0; index < length - 1; index++) + { + if (input[index] == '/' && + input[index + 1] == '*') + { + if (openCommentsCount == 0) + { + foundStartIndex = index; + } + openCommentsCount++; + } + + if (input[index] == '*' && + input[index + 1] == '/') + { + openCommentsCount--; + if (openCommentsCount == 0) + { + int commentLength = index - foundStartIndex + 2; + length -= commentLength; + index = foundStartIndex - 1; + input = input.Remove(foundStartIndex, commentLength); + foundStartIndex = -1; + } + } + } + + if (openCommentsCount > 0) + { + throw new Exception("Unable to clean the shader code because it seems " + + "some multiline comments interfere with each other or with the code. " + + "Please make sure your shader code and comments are well formatted!"); + } + #endregion + + // Now to some additional cleanup + string[] minimizables = + { + " * ", " = ", " + ", " / ", " - ", ", ", + }; + + foreach (string mizable in minimizables) + { + input = input.Replace(mizable, mizable.Trim()); + } + + return input; + } + #endregion + + #region ParseShaderCode + public static ShaderData ParseShaderCode(string source) + { + ShaderData result = new ShaderData(); + + string[] partIdentifiers = + { + "vertexglobal", + "vertexshaders", + "fragmentglobal", + "fragmentshaders", + "techniques", + }; + + int index = 0; + while (index < source.Length) + { + for (int partIdsIndex = 0; partIdsIndex < partIdentifiers.Length; partIdsIndex++) + { + string partId = partIdentifiers[partIdsIndex]; + bool isValid = true; + for (int partIndex = 0; partIndex < partId.Length; partIndex++) + { + if (source[index + partIndex] != partId[partIndex]) + { + isValid = false; + break; + } + } + + if (isValid) + { + int startIndex = index + partId.Length; + startIndex = source.IndexOf('{', startIndex) + 1; + string area = ExtractArea(source, startIndex); + index = startIndex + area.Length - 1; + switch (partIdsIndex) + { + case 0: + result.VertexGlobalCode = area; + break; + case 2: + result.FragmentGlobalCode = area; + break; + case 1: + ExtractNamedAreas(area, "shader", 0, result); + break; + case 3: + ExtractNamedAreas(area, "shader", 1, result); + break; + case 4: + ExtractNamedAreas(area, "technique", 2, result); + break; + } + } + } + + index++; + } + + return result; + } + #endregion + + #region ExtractNamedAreas + private static void ExtractNamedAreas(string areaSource, string identifier, + int addToId, ShaderData result) + { + int index = 0; + while (index < areaSource.Length) + { + bool isValid = true; + for (int partIndex = 0; partIndex < identifier.Length; partIndex++) + { + if (areaSource[index + partIndex] != identifier[partIndex]) + { + isValid = false; + break; + } + } + + if (isValid) + { + int startIndex = index + identifier.Length; + startIndex = areaSource.IndexOf('"', startIndex) + 1; + + string name = areaSource.Substring(startIndex, + areaSource.IndexOf('"', startIndex) - startIndex); + + startIndex = areaSource.IndexOf('{', startIndex) + 1; + string area = ExtractArea(areaSource, startIndex); + + switch (addToId) + { + case 0: + result.VertexShaderCodes.Add(name, area); + break; + case 1: + result.FragmentShaderCodes.Add(name, area); + break; + case 2: + int vertexIndex = area.IndexOf("vertex"); + vertexIndex = area.IndexOf('"', vertexIndex) + 1; + string vertexName = area.Substring(vertexIndex, + area.IndexOf('"', vertexIndex) - vertexIndex); + + int fragmentIndex = area.IndexOf("fragment"); + fragmentIndex = area.IndexOf('"', fragmentIndex) + 1; + string fragmentName = area.Substring(fragmentIndex, + area.IndexOf('"', fragmentIndex) - fragmentIndex); + result.Techniques.Add(name, new StringPair(vertexName, fragmentName)); + break; + } + } + + index++; + } + } + #endregion + + #region ExtractArea + private static string ExtractArea(string source, int startIndex) + { + int endIndex = startIndex; + int openBraceCount = 0; + for (int index = startIndex; index < source.Length; index++) + { + if (source[index] == '{') + { + openBraceCount++; + } + if (source[index] == '}') + { + openBraceCount--; + } + if (openBraceCount == -1) + { + endIndex = index; + break; + } + } + return source.Substring(startIndex, endIndex - startIndex); + } + #endregion + + private class Tests + { + #region TestCleanCode + public static void TestCleanCode() + { + string input = File.ReadAllText(@"..\..\shader\GL3\SpriteBatch_GLSL.fx"); + Console.WriteLine(CleanCode(input)); + } + #endregion + + #region TestCleanCodeWithExtendedComments + public static void TestCleanCodeWithExtendedComments() + { + string input = +@"// This is a simple comment. + +/*Hello +im a multiline comment*/ + +/* Multiline on a single line */ + +/* And now the hardcore...a multiline comment +/*in a multiline comment/*in another one +*/*/ +Wow... +*/ +"; + Console.WriteLine(CleanCode(input)); + } + #endregion + + #region TestParseShaderCode + public static void TestParseShaderCode() + { + string input = CleanCode(File.ReadAllText( + @"..\..\shader\GL3\SpriteBatch_GLSL.fx")); + + ShaderData data = ParseShaderCode(input); + + Console.WriteLine("Vertex globals:"); + Console.WriteLine(data.VertexGlobalCode); + Console.WriteLine("-------------------------"); + Console.WriteLine("Fragment globals:"); + Console.WriteLine(data.FragmentGlobalCode); + Console.WriteLine("-------------------------"); + foreach (StringPair pair in data.VertexShaderCodes) + { + Console.WriteLine("vertex shader: " + pair.Key); + Console.WriteLine(pair.Value); + Console.WriteLine("-------------------------"); + } + foreach (StringPair pair in data.FragmentShaderCodes) + { + Console.WriteLine("fragment shader: " + pair.Key); + Console.WriteLine(pair.Value); + Console.WriteLine("-------------------------"); + } + foreach (KeyValuePair pair in data.Techniques) + { + Console.WriteLine("technique: " + pair.Key); + Console.WriteLine("vertex shader: " + pair.Value.Key); + Console.WriteLine("fragment shader: " + pair.Value.Value); + Console.WriteLine("-------------------------"); + } + } + #endregion + } + } +} diff --git a/RenderSystems/ANX.Framework.GL3/SupportedPlatformsImpl.cs b/RenderSystems/ANX.Framework.GL3/SupportedPlatformsImpl.cs new file mode 100644 index 00000000..79403bc5 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/SupportedPlatformsImpl.cs @@ -0,0 +1,28 @@ +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.GL3 +{ + public class SupportedPlatformsImpl : ISupportedPlatforms + { + public PlatformName[] Names + { + get + { + return new PlatformName[] + { + PlatformName.WindowsXP, + PlatformName.WindowsVista, + PlatformName.Windows7, + PlatformName.Windows8, + PlatformName.Linux, + PlatformName.MacOSX, + }; + } + } + } +} diff --git a/RenderSystems/ANX.Framework.GL3/Texture2DGL3.cs b/RenderSystems/ANX.Framework.GL3/Texture2DGL3.cs new file mode 100644 index 00000000..8bcf2f68 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/Texture2DGL3.cs @@ -0,0 +1,339 @@ +using System; +using System.IO; +using System.Runtime.InteropServices; +using ANX.Framework; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA.RenderSystem; +using ANX.RenderSystem.GL3.Helpers; +using OpenTK.Graphics.OpenGL; + +// 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.GL3 +{ + public class Texture2DGL3 : INativeTexture2D + { + #region Private + private PixelInternalFormat nativeFormat; + + /// + /// [1-n] + /// + private int numberOfMipMaps; + + private int width; + private int height; + private bool isCompressed; + internal bool IsDisposed; + private int uncompressedDataSize; + private byte[] texData; + private int maxSetDataSize; + #endregion + + #region Public + protected internal int NativeHandle { get; protected set; } + #endregion + + #region Constructor + internal Texture2DGL3() + { + GraphicsResourceManager.UpdateResource(this, true); + } + + internal Texture2DGL3(SurfaceFormat surfaceFormat, int setWidth, int setHeight, int mipCount) + { + GraphicsResourceManager.UpdateResource(this, true); + + width = setWidth; + height = setHeight; + numberOfMipMaps = mipCount; + nativeFormat = DatatypesMapping.SurfaceToPixelInternalFormat(surfaceFormat); + isCompressed = nativeFormat.ToString().StartsWith("Compressed"); + + uncompressedDataSize = GetUncompressedDataSize(); + + CreateTexture(); + } + + ~Texture2DGL3() + { + GraphicsResourceManager.UpdateResource(this, false); + } + #endregion + + #region CreateTexture + private void CreateTexture() + { + NativeHandle = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, NativeHandle); + + int wrapMode = (int)All.ClampToEdge; + All minFilter = numberOfMipMaps > 1 ? All.LinearMipmapLinear : All.Linear; + + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, wrapMode); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, wrapMode); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)minFilter); +#if DEBUG + ErrorHelper.Check("TexParameter"); +#endif + } + #endregion + + // TODO: offsetInBytes + // TODO: elementCount + #region SetData + public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct + { + SetData(graphicsDevice, 0, data, 0, data.Length); + } + + public void SetData(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct + { + SetData(graphicsDevice, 0, data, 0, data.Length); + } + + public void SetData(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct + { + int size = Marshal.SizeOf(typeof(T)) * data.Length; + if (size > maxSetDataSize) + maxSetDataSize = size; + + GL.BindTexture(TextureTarget.Texture2D, NativeHandle); + GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); + + try + { + IntPtr dataPointer = handle.AddrOfPinnedObject(); + // Go to the starting point. + dataPointer += startIndex; + + int mipmapWidth = Math.Max(width >> level, 1); + int mipmapHeight = Math.Max(height >> level, 1); + + if (isCompressed) + { + GL.CompressedTexImage2D(TextureTarget.Texture2D, level, nativeFormat, width, height, 0, data.Length, + dataPointer); +#if DEBUG + ErrorHelper.Check("CompressedTexImage2D Format=" + nativeFormat); +#endif + } + else + { + GL.TexImage2D(TextureTarget.Texture2D, level, nativeFormat, mipmapWidth, mipmapHeight, 0, + (PixelFormat)nativeFormat, PixelType.UnsignedByte, dataPointer); +#if DEBUG + ErrorHelper.Check("TexImage2D Format=" + nativeFormat); +#endif + } + } + finally + { + handle.Free(); + } + } + + public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) + where T : struct + { + int size = Marshal.SizeOf(typeof(T)) * data.Length; + if (size > maxSetDataSize) + maxSetDataSize = size; + + GL.BindTexture(TextureTarget.Texture2D, NativeHandle); + GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); + + try + { + IntPtr dataPointer = handle.AddrOfPinnedObject(); + dataPointer += startIndex; + + if (isCompressed) + { + GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, nativeFormat, width, height, 0, data.Length, dataPointer); +#if DEBUG + ErrorHelper.Check("CompressedTexImage2D Format=" + nativeFormat); +#endif + } + else + { + GL.TexImage2D(TextureTarget.Texture2D, 0, nativeFormat, width, height, 0, (PixelFormat)nativeFormat, + PixelType.UnsignedByte, dataPointer); +#if DEBUG + ErrorHelper.Check("TexImage2D Format=" + nativeFormat); +#endif + } + } + finally + { + handle.Free(); + } + } + #endregion + + #region GetData (TODO) + public void GetData(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct + { + throw new NotImplementedException(); + } + #endregion + + #region GetData + public void GetData(T[] data) where T : struct + { + GetData(data, 0, data.Length); + } + #endregion + + // TODO: compressed texture (see: http://www.bearisgaming.com/texture2d-getdata-and-dxt-compression/) + // TODO: elementCount + #region GetData + public void GetData(T[] data, int startIndex, int elementCount) where T : struct + { + if (isCompressed) + throw new NotImplementedException("GetData is currently not implemented for compressed texture format " + + nativeFormat + "."); + + if (data == null) + throw new ArgumentNullException("data"); + + int size = Marshal.SizeOf(typeof(T)) * data.Length; + + if (size < uncompressedDataSize) + throw new InvalidDataException("The size of the data passed in is too large or too small for this resource."); + + GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); + IntPtr ptr = handle.AddrOfPinnedObject(); + ptr += startIndex; + + GL.GetTexImage(TextureTarget.Texture2D, 0, (PixelFormat)nativeFormat, PixelType.UnsignedByte, ptr); + + handle.Free(); + } + #endregion + + #region GetTextureData + private void GetTextureData() + { + GL.BindTexture(TextureTarget.Texture2D, NativeHandle); + + if (isCompressed) + { + texData = new byte[maxSetDataSize]; + GCHandle handle = GCHandle.Alloc(texData, GCHandleType.Pinned); + + GL.GetCompressedTexImage(TextureTarget.Texture2D, 0, handle.AddrOfPinnedObject()); + + handle.Free(); + } + else + { + texData = new byte[uncompressedDataSize]; + GCHandle handle = GCHandle.Alloc(texData, GCHandleType.Pinned); + + GL.GetTexImage(TextureTarget.Texture2D, 0, (PixelFormat)nativeFormat, PixelType.UnsignedByte, + handle.AddrOfPinnedObject()); + + handle.Free(); + } + } + #endregion + + #region RecreateData + internal void RecreateData() + { + CreateTexture(); + SetData(null, texData); + texData = null; + } + #endregion + + #region GetUncompressedDataSize + private int GetUncompressedDataSize() + { + int size = width * height; + + switch (nativeFormat) + { + default: + case PixelInternalFormat.R32f: + case PixelInternalFormat.Rgb10A2: + case PixelInternalFormat.Rg16: + case PixelInternalFormat.Rgba: + size *= 4; + break; + + case PixelInternalFormat.Rg32f: + case PixelInternalFormat.Rgba16f: + size *= 8; + break; + + case PixelInternalFormat.R16f: + case PixelInternalFormat.Rgb5A1: + case PixelInternalFormat.Rgba4: + size *= 2; + break; + + case PixelInternalFormat.Alpha8: + //size *= 1; + break; + + case PixelInternalFormat.Rgba32f: + size *= 16; + break; + } + + return size; + } + #endregion + + #region SaveAsJpeg (TODO) + public void SaveAsJpeg(Stream stream, int width, int height) + { + throw new NotImplementedException(); + } + #endregion + + #region SaveAsPng (TODO) + public void SaveAsPng(Stream stream, int width, int height) + { + throw new NotImplementedException(); + } + #endregion + + #region Dispose + /// + /// Dispose the native OpenGL texture handle. + /// + public virtual void Dispose() + { + if (IsDisposed == false) + { + IsDisposed = true; + DisposeResource(); + } + } + + internal void DisposeResource() + { + if (IsDisposed == false) + { + GetTextureData(); + } + + if (NativeHandle != -1 && + GraphicsDeviceWindowsGL3.IsContextCurrent) + { + GL.DeleteTexture(NativeHandle); + NativeHandle = -1; +#if DEBUG + ErrorHelper.Check("DeleteTexture"); +#endif + } + } + #endregion + } +} diff --git a/RenderSystems/ANX.Framework.GL3/VertexBufferGL3.cs b/RenderSystems/ANX.Framework.GL3/VertexBufferGL3.cs new file mode 100644 index 00000000..302fb8cf --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/VertexBufferGL3.cs @@ -0,0 +1,307 @@ +using System; +using System.Runtime.InteropServices; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA.RenderSystem; +using OpenTK.Graphics.OpenGL; +using ANX.RenderSystem.GL3.Helpers; + +// 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.GL3 +{ + /// + /// Native OpenGL implementation of a Vertex Buffer. + /// + /// Great tutorial about VBO/IBO directly for OpenTK: + /// http://www.opentk.com/doc/graphics/geometry/vertex-buffer-objects + /// + public class VertexBufferGL3 : INativeVertexBuffer + { + #region Private + private VertexBuffer managedBuffer; + + /// + /// Native vertex buffer handle. + /// + private int bufferHandle; + internal int BufferHandle + { + get + { + return bufferHandle; + } + } + + private VertexDeclaration vertexDeclaration; + + private BufferUsage usage; + + private int vertexCount; + + private BufferUsageHint usageHint; + + internal bool IsDisposed; + #endregion + + #region Constructor + /// + /// Create a new Vertex Buffer object. + /// + internal VertexBufferGL3(VertexBuffer setManagedBuffer, + VertexDeclaration setVertexDeclaration, int setVertexCount, + BufferUsage setUsage) + { + GraphicsResourceManager.UpdateResource(this, true); + + managedBuffer = setManagedBuffer; + vertexDeclaration = setVertexDeclaration; + usage = setUsage; + vertexCount = setVertexCount; + + bool isDynamicBuffer = managedBuffer is DynamicVertexBuffer; + + usageHint = isDynamicBuffer ? + BufferUsageHint.DynamicDraw : + BufferUsageHint.StaticDraw; + + CreateBuffer(); + } + + ~VertexBufferGL3() + { + GraphicsResourceManager.UpdateResource(this, false); + } + #endregion + + #region CreateBuffer + private void CreateBuffer() + { + GL.GenBuffers(1, out bufferHandle); + ErrorHelper.Check("GenBuffers"); + GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle); + ErrorHelper.Check("BindBuffer"); + int size = vertexDeclaration.VertexStride * vertexCount; + GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)size, IntPtr.Zero, + usageHint); + ErrorHelper.Check("BufferData"); + + int setSize; + GL.GetBufferParameter(BufferTarget.ArrayBuffer, + BufferParameterName.BufferSize, out setSize); + if (setSize != size) + { + throw new Exception("Failed to set the vertexBuffer data. DataSize=" + + size + " SetSize=" + setSize); + } + } + #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 SetData + public void SetData(GraphicsDevice graphicsDevice, int offsetInBytes, + T[] data, int startIndex, int elementCount, int vertexStride) where T : struct + { + T[] elements; + if (startIndex != 0 || + elementCount != data.Length) + { + elements = new T[elementCount]; + Array.Copy(data, startIndex, elements, 0, elementCount); + } + else + { + elements = data; + } + + int size = Marshal.SizeOf(typeof(T)); + + GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle); + ErrorHelper.Check("BindBuffer"); + + for (int index = 0; index < elementCount; index++) + { + GL.BufferSubData(BufferTarget.ArrayBuffer, + (IntPtr)offsetInBytes + (index * vertexStride), + (IntPtr)size, ref elements[index]); + ErrorHelper.Check("BufferSubData"); + } + } + #endregion + + #region BufferData (private helper) + private void BufferData(T[] data, int offset) where T : struct + { + int size = Marshal.SizeOf(typeof(T)) * data.Length; + + GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle); + ErrorHelper.Check("BindBuffer"); + + GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)offset, + (IntPtr)size, data); + ErrorHelper.Check("BufferSubData"); + } + #endregion + + #region GetData + public void GetData(T[] data) where T : struct + { + int size = Marshal.SizeOf(typeof(T)) * data.Length; + + GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle); + ErrorHelper.Check("BindBuffer"); + + GL.GetBufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero, + (IntPtr)size, data); + ErrorHelper.Check("GetBufferSubData"); + } + #endregion + + #region GetData + public void GetData(T[] data, int startIndex, int elementCount) + where T : struct + { + T[] copyElements = new T[elementCount]; + int size = Marshal.SizeOf(typeof(T)) * elementCount; + + GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle); + ErrorHelper.Check("BindBuffer"); + + GL.GetBufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, + (IntPtr)size, copyElements); + ErrorHelper.Check("GetBufferSubData"); + + Array.Copy(copyElements, 0, data, startIndex, elementCount); + } + #endregion + + #region GetData + public void GetData(int offsetInBytes, T[] data, int startIndex, + int elementCount, int vertexStride) where T : struct + { + T[] copyElements = new T[elementCount]; + int size = Marshal.SizeOf(typeof(T)); + + GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle); + ErrorHelper.Check("BindBuffer"); + + for (int index = 0; index < elementCount; index++) + { + GL.GetBufferSubData(BufferTarget.ArrayBuffer, + (IntPtr)offsetInBytes + (index * vertexStride), + (IntPtr)size, + ref copyElements[index]); + ErrorHelper.Check("GetBufferSubData"); + } + + Array.Copy(copyElements, 0, data, startIndex, elementCount); + } + #endregion + + #region Bind + public void Bind(EffectGL3 activeEffect) + { + GL.BindBuffer(BufferTarget.ArrayBuffer, BufferHandle); + ErrorHelper.Check("BindBuffer"); + MapVertexDeclaration(activeEffect); + } + #endregion + + #region MapVertexDeclaration + private void MapVertexDeclaration(EffectGL3 effect) + { + EffectTechniqueGL3 currentTechnique = effect.CurrentTechnique; + ShaderAttributeGL3[] attributes = currentTechnique.activeAttributes; + VertexElement[] elements = vertexDeclaration.GetVertexElements(); + + if (elements.Length != attributes.Length) + throw new InvalidOperationException("Mapping the VertexDeclaration onto the glsl attributes failed because " + + "we have " + attributes.Length + " Shader Attributes and " + elements.Length + " elements in the vertex " + + "declaration which doesn't fit!"); + + for (int index = 0; index < attributes.Length; index++) + { + int location = attributes[index].Location; + attributes[index].Bind(elements[location].VertexElementUsage, vertexDeclaration.VertexStride, + elements[location].Offset); + } + } + #endregion + + #region Dispose + /// + /// Dispose the native index buffer data. + /// + public void Dispose() + { + if (IsDisposed == false) + { + IsDisposed = true; + DisposeResource(); + } + } + + internal void DisposeResource() + { + if (bufferHandle != -1 && + GraphicsDeviceWindowsGL3.IsContextCurrent) + { + GL.DeleteBuffers(1, ref bufferHandle); + ErrorHelper.Check("DeleteBuffers"); + bufferHandle = -1; + } + } + #endregion + } +} diff --git a/Samples/BasicEffectSample/BasicEffectSample.csproj b/Samples/BasicEffectSample/BasicEffectSample.csproj index 1bbc322d..cb6e5838 100644 --- a/Samples/BasicEffectSample/BasicEffectSample.csproj +++ b/Samples/BasicEffectSample/BasicEffectSample.csproj @@ -121,10 +121,6 @@ {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {B30DE9C2-0926-46B6-8351-9AF276C472D5} ANX.RenderSystem.Windows.DX11 diff --git a/Samples/DualTextureSample/DualTextureSample.csproj b/Samples/DualTextureSample/DualTextureSample.csproj index 64456858..718b8f0f 100644 --- a/Samples/DualTextureSample/DualTextureSample.csproj +++ b/Samples/DualTextureSample/DualTextureSample.csproj @@ -97,10 +97,6 @@ {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {B30DE9C2-0926-46B6-8351-9AF276C472D5} ANX.RenderSystem.Windows.DX11 diff --git a/Samples/ModelSample/ModelSample/ModelSample.csproj b/Samples/ModelSample/ModelSample/ModelSample.csproj index bc2d6b83..e6f771ec 100644 --- a/Samples/ModelSample/ModelSample/ModelSample.csproj +++ b/Samples/ModelSample/ModelSample/ModelSample.csproj @@ -146,10 +146,6 @@ {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {FA6E229D-4504-47B1-8A23-2D3FCC13F778} SampleContent diff --git a/Samples/ModelSample/ModelSample/Properties/AssemblyInfo.cs b/Samples/ModelSample/ModelSample/Properties/AssemblyInfo.cs index 78893fb6..9bb45b84 100644 --- a/Samples/ModelSample/ModelSample/Properties/AssemblyInfo.cs +++ b/Samples/ModelSample/ModelSample/Properties/AssemblyInfo.cs @@ -31,4 +31,4 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("1.0.1.0")] +[assembly: AssemblyVersion("1.0.1.0")] \ No newline at end of file diff --git a/Samples/Primitives/Primitives.csproj b/Samples/Primitives/Primitives.csproj index 24af6f9d..b19ddb66 100644 --- a/Samples/Primitives/Primitives.csproj +++ b/Samples/Primitives/Primitives.csproj @@ -120,10 +120,6 @@ {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {6A582788-C4D2-410C-96CD-177F75712D65} ANX.SoundSystem.Windows.XAudio diff --git a/Samples/RenderTarget/RenderTarget.csproj b/Samples/RenderTarget/RenderTarget.csproj index d6d40ea6..8541ef2e 100644 --- a/Samples/RenderTarget/RenderTarget.csproj +++ b/Samples/RenderTarget/RenderTarget.csproj @@ -121,10 +121,6 @@ {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {6A582788-C4D2-410C-96CD-177F75712D65} ANX.SoundSystem.Windows.XAudio diff --git a/Samples/SimpleSprite/SimpleSprite.csproj b/Samples/SimpleSprite/SimpleSprite.csproj index ac8fc5c8..86e2b727 100644 --- a/Samples/SimpleSprite/SimpleSprite.csproj +++ b/Samples/SimpleSprite/SimpleSprite.csproj @@ -99,10 +99,6 @@ {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {B30DE9C2-0926-46B6-8351-9AF276C472D5} ANX.RenderSystem.Windows.DX11 diff --git a/Samples/TextRendering/TextRendering.csproj b/Samples/TextRendering/TextRendering.csproj index 86365787..c58504e6 100644 --- a/Samples/TextRendering/TextRendering.csproj +++ b/Samples/TextRendering/TextRendering.csproj @@ -121,10 +121,6 @@ {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {6A582788-C4D2-410C-96CD-177F75712D65} ANX.SoundSystem.Windows.XAudio diff --git a/Samples/WindowsFormsEditor/WindowsFormsEditor.csproj b/Samples/WindowsFormsEditor/WindowsFormsEditor.csproj index bb5e2b3f..82c16f40 100644 --- a/Samples/WindowsFormsEditor/WindowsFormsEditor.csproj +++ b/Samples/WindowsFormsEditor/WindowsFormsEditor.csproj @@ -66,10 +66,6 @@ {49066074-3B7B-4A55-B122-6BD33AB73558} ANX.InputSystem.Standard - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {14EF49AB-6D3F-458D-9D5C-D120B86EDD7A} ANX.SoundSystem.OpenAL diff --git a/Samples/WindowsGame/WindowsGame.csproj b/Samples/WindowsGame/WindowsGame.csproj index e5521603..450b1adc 100644 --- a/Samples/WindowsGame/WindowsGame.csproj +++ b/Samples/WindowsGame/WindowsGame.csproj @@ -145,10 +145,6 @@ {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {B30DE9C2-0926-46B6-8351-9AF276C472D5} ANX.RenderSystem.Windows.DX11 diff --git a/Samples/WpfEditor/WpfEditor.csproj b/Samples/WpfEditor/WpfEditor.csproj index c5401f81..5e16f426 100644 --- a/Samples/WpfEditor/WpfEditor.csproj +++ b/Samples/WpfEditor/WpfEditor.csproj @@ -107,10 +107,6 @@ {49066074-3B7B-4A55-B122-6BD33AB73558} ANX.InputSystem.Standard - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {14EF49AB-6D3F-458D-9D5C-D120B86EDD7A} ANX.SoundSystem.OpenAL diff --git a/Support/WaveUtils/ALFormat.cs b/Support/WaveUtils/ALFormat.cs new file mode 100644 index 00000000..fadffd1a --- /dev/null +++ b/Support/WaveUtils/ALFormat.cs @@ -0,0 +1,10 @@ +namespace WaveUtils +{ + public enum ALFormat + { + Mono8 = 4352, + Mono16 = 4353, + Stereo8 = 4354, + Stereo16 = 4355, + } +} diff --git a/Support/WaveUtils/ALaw.cs b/Support/WaveUtils/ALaw.cs new file mode 100644 index 00000000..983e02f9 --- /dev/null +++ b/Support/WaveUtils/ALaw.cs @@ -0,0 +1,125 @@ +using System; +using System.IO; + +// This file is part of the ANX.Framework and originally taken from +// the AC.AL OpenAL library, released under the MIT License. +// For details see: http://acal.codeplex.com/license + +namespace WaveUtils +{ + /// + /// http://www.threejacks.com/?q=node/176 + /// + internal static class ALaw + { + #region Decode Table + private static readonly short[] DecodeTable = + { + -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736, + -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784, + -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368, + -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392, + -22016,-20992,-24064,-23040,-17920,-16896,-19968,-18944, + -30208,-29184,-32256,-31232,-26112,-25088,-28160,-27136, + -11008,-10496,-12032,-11520,-8960, -8448, -9984, -9472, + -15104,-14592,-16128,-15616,-13056,-12544,-14080,-13568, + -344, -328, -376, -360, -280, -264, -312, -296, + -472, -456, -504, -488, -408, -392, -440, -424, + -88, -72, -120, -104, -24, -8, -56, -40, + -216, -200, -248, -232, -152, -136, -184, -168, + -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184, + -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696, + -688, -656, -752, -720, -560, -528, -624, -592, + -944, -912, -1008, -976, -816, -784, -880, -848, + 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736, + 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784, + 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368, + 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392, + 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944, + 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136, + 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472, + 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568, + 344, 328, 376, 360, 280, 264, 312, 296, + 472, 456, 504, 488, 408, 392, 440, 424, + 88, 72, 120, 104, 24, 8, 56, 40, + 216, 200, 248, 232, 152, 136, 184, 168, + 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184, + 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696, + 688, 656, 752, 720, 560, 528, 624, 592, + 944, 912, 1008, 976, 816, 784, 880, 848 + }; + #endregion + + #region Encode Table + private static readonly byte[] EncodeTable = + { + 1, 1, 2, 2, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7 + }; + #endregion + + #region ConvertToALaw (TODO) + private static void ConvertToALaw(WaveInfo info) + { + //int sign; + //int exponent; + //int mantissa; + //unsigned char compressedByte; + + //sign = ((~sample) >> 8) & 0x80; + //if (!sign) + // sample = (short)-sample; + //if (sample > cClip) + // sample = cClip; + //if (sample >= 256) + //{ + // exponent = (int)ALawCompressTable[(sample >> 8) & 0x7F]; + // mantissa = (sample >> (exponent + 3) ) & 0x0F; + // compressedByte = ((exponent << 4) | mantissa); + //} + //else + //{ + // compressedByte = (unsigned char)(sample >> 4); + //} + //compressedByte ^= (sign ^ 0x55); + //return compressedByte; + } + #endregion + + #region ConvertToPcm + public static void ConvertToPcm(WaveInfo info, int resultChannelCount) + { + using (MemoryStream destStream = new MemoryStream()) + { + BinaryWriter destWriter = new BinaryWriter(destStream); + + int increment = 1; + if (info.Channels == 2 && resultChannelCount == 1) + increment = 2; + + info.Channels = resultChannelCount; + info.ALFormat = info.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16; + + for (int index = 0; index < info.Data.Length; index += increment) + destWriter.Write(DecodeTable[info.Data[index]]); + + info.Data = destStream.ToArray(); + } + } + #endregion + } +} diff --git a/Support/WaveUtils/IEEEFloat.cs b/Support/WaveUtils/IEEEFloat.cs new file mode 100644 index 00000000..bf4165cd --- /dev/null +++ b/Support/WaveUtils/IEEEFloat.cs @@ -0,0 +1,40 @@ +using System; +using System.IO; + +// This file is part of the ANX.Framework and originally taken from +// the AC.AL OpenAL library, released under the MIT License. +// For details see: http://acal.codeplex.com/license + +namespace WaveUtils +{ + public static class IEEEFloat + { + public static void ConvertToPcm(WaveInfo data, int resultChannelCount) + { + bool is64BitFloat = data.BitsPerSample == 64; + + using (BinaryReader sourceReader = new BinaryReader(new MemoryStream(data.Data))) + { + MemoryStream destStream = new MemoryStream(); + BinaryWriter destWriter = new BinaryWriter(destStream); + + int length = data.Data.Length / (is64BitFloat ? 8 : 4); + + int increment = 1; + if (data.Channels == 2 && resultChannelCount == 1) + increment = 2; + + data.Channels = resultChannelCount; + data.ALFormat = data.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16; + + for (int index = 0; index < length; index += increment) + { + double value = is64BitFloat ? sourceReader.ReadDouble() : sourceReader.ReadSingle(); + destWriter.Write((short)(value * 32767)); + } + + data.Data = destStream.ToArray(); + } + } + } +} diff --git a/Support/WaveUtils/MsAdpcm.cs b/Support/WaveUtils/MsAdpcm.cs new file mode 100644 index 00000000..d3ad6b69 --- /dev/null +++ b/Support/WaveUtils/MsAdpcm.cs @@ -0,0 +1,141 @@ +using System; +using System.IO; + +// This file is part of the ANX.Framework and originally taken from +// the AC.AL OpenAL library, released under the MIT License. +// For details see: http://acal.codeplex.com/license + +namespace WaveUtils +{ + /// + /// http://wiki.multimedia.cx/index.php?title=Microsoft_ADPCM + /// + /// http://dslinux.gits.kiev.ua/trunk/lib/audiofile/src/libaudiofile/modules/msadpcm.c + /// + /// http://netghost.narod.ru/gff/vendspec/micriff/ms_riff.txt + /// + internal static class MsAdpcm + { + #region Decoding Tables + private static readonly int[] AdaptationTable = + { + 230, 230, 230, 230, 307, 409, 512, 614, + 768, 614, 512, 409, 307, 230, 230, 230 + }; + + private static readonly int[] AdaptCoeff1 = + { + 256, 512, 0, 192, 240, 460, 392 + }; + + private static readonly int[] AdaptCoeff2 = + { + 0, -256, 0, 64, 0, -208, -232 + }; + #endregion + + #region StateObject (helper class) + private class StateObject + { + /// + /// Indices in the aCoef array to define the predictor + /// used to encode this block. + /// + public byte predicator; + /// + /// Initial Delta value to use. + /// + public short delta; + /// + /// The second sample value of the block. When decoding this will be + /// used as the previous sample to start decoding with. + /// + public short sample1; + /// + /// The first sample value of the block. When decoding this will be + /// used as the previous' previous sample to start decoding with. + /// + public short sample2; + } + #endregion + + #region ConvertToPcm + public static void ConvertToPcm(WaveInfo info) + { + BinaryReader reader = new BinaryReader(new MemoryStream(info.Data)); + MemoryStream result = new MemoryStream(); + BinaryWriter writer = new BinaryWriter(result); + + StateObject first = new StateObject(); + StateObject second = info.Channels > 1 ? new StateObject() : first; + StateObject[] states = { first, second }; + + int numSamples = (info.ExtSamplesPerBlock - 2) * info.Channels; + int numberOfBlocks = info.Data.Length / info.BlockAlign; + for (int blockIndex = 0; blockIndex < numberOfBlocks; blockIndex++) + { + for (int index = 0; index < info.Channels; index++) + { + states[index].predicator = reader.ReadByte(); + } + for (int index = 0; index < info.Channels; index++) + { + states[index].delta = reader.ReadInt16(); + } + for (int index = 0; index < info.Channels; index++) + { + states[index].sample1 = reader.ReadInt16(); + } + for (int index = 0; index < info.Channels; index++) + { + states[index].sample2 = reader.ReadInt16(); + // Write first samples directly from preamble + writer.Write(states[index].sample2); + } + + // Write first samples directly from preamble + for (int index = 0; index < info.Channels; index++) + { + writer.Write(states[index].sample1); + } + + // We decode the samples two at a time + for (int index = 0; index < numSamples; index += 2) + { + byte code = reader.ReadByte(); + DecodeSample(first, code >> 4, writer); + DecodeSample(second, code & 0x0f, writer); + } + } + + reader.Close(); + writer.Close(); + info.Data = result.ToArray(); + result.Dispose(); + } + #endregion + + #region DecodeSample + private static void DecodeSample(StateObject state, int code, + BinaryWriter writer) + { + int linearSample = + ((state.sample1 * AdaptCoeff1[state.predicator]) + + (state.sample2 * AdaptCoeff2[state.predicator])) / 256; + + linearSample = linearSample + (state.delta * + ((code & 0x08) == 0x08 ? (code - 0x10) : code)); + + state.sample2 = state.sample1; + // clamp predictor within signed 16-bit range + state.sample1 = (short)Math.Min(short.MaxValue, + Math.Max(short.MinValue, linearSample)); + + state.delta = (short)Math.Max( + (state.delta * AdaptationTable[code]) / 256, 16); + + writer.Write(state.sample1); + } + #endregion + } +} diff --git a/Support/WaveUtils/MuLaw.cs b/Support/WaveUtils/MuLaw.cs new file mode 100644 index 00000000..cef2238d --- /dev/null +++ b/Support/WaveUtils/MuLaw.cs @@ -0,0 +1,114 @@ +using System; +using System.IO; + +// This file is part of the ANX.Framework and originally taken from +// the AC.AL OpenAL library, released under the MIT License. +// For details see: http://acal.codeplex.com/license + +namespace WaveUtils +{ + /// + /// http://www.threejacks.com/?q=node/176 + /// + internal static class MuLaw + { + #region Decode Table + private static readonly short[] DecodeTable = + { + -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956, + -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764, + -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412, + -11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316, + -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140, + -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092, + -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004, + -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980, + -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436, + -1372, -1308, -1244, -1180, -1116, -1052, -988, -924, + -876, -844, -812, -780, -748, -716, -684, -652, + -620, -588, -556, -524, -492, -460, -428, -396, + -372, -356, -340, -324, -308, -292, -276, -260, + -244, -228, -212, -196, -180, -164, -148, -132, + -120, -112, -104, -96, -88, -80, -72, -64, + -56, -48, -40, -32, -24, -16, -8, -1, + 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956, + 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764, + 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412, + 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316, + 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140, + 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092, + 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004, + 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980, + 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436, + 1372, 1308, 1244, 1180, 1116, 1052, 988, 924, + 876, 844, 812, 780, 748, 716, 684, 652, + 620, 588, 556, 524, 492, 460, 428, 396, + 372, 356, 340, 324, 308, 292, 276, 260, + 244, 228, 212, 196, 180, 164, 148, 132, + 120, 112, 104, 96, 88, 80, 72, 64, + 56, 48, 40, 32, 24, 16, 8, 0 + }; + #endregion + + #region Encode Table + private static readonly byte[] EncodeTable = + { + 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 + }; + #endregion + + #region ConvertToMuLaw (TODO) + private static void ConvertToMuLaw(WaveInfo info) + { + //int sign = (sample >> 8) & 0x80; + //if (sign) + // sample = (short)-sample; + //if (sample > cClip) + // sample = cClip; + //sample = (short)(sample + cBias); + //int exponent = (int)MuLawCompressTable[(sample>>7) & 0xFF]; + //int mantissa = (sample >> (exponent+3)) & 0x0F; + //int compressedByte = ~ (sign | (exponent << 4) | mantissa); + + //return (unsigned char)compressedByte; + } + #endregion + + #region ConvertToPcm + public static void ConvertToPcm(WaveInfo info, int resultChannelCount) + { + using (MemoryStream destStream = new MemoryStream()) + { + BinaryWriter destWriter = new BinaryWriter(destStream); + + int increment = 1; + if (info.Channels == 2 && resultChannelCount == 1) + increment = 2; + + info.Channels = resultChannelCount; + info.ALFormat = info.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16; + + for (int index = 0; index < info.Data.Length; index += increment) + destWriter.Write(DecodeTable[info.Data[index]]); + + info.Data = destStream.ToArray(); + } + } + #endregion + } +} diff --git a/Support/WaveUtils/Properties/AssemblyInfo.cs b/Support/WaveUtils/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..6d4088a4 --- /dev/null +++ b/Support/WaveUtils/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die mit einer Assembly verknüpft sind. +[assembly: AssemblyTitle("WaveUtils")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("ANX.Framework Team")] +[assembly: AssemblyProduct("WaveUtils")] +[assembly: AssemblyCopyright("Copyright © ANX.Framework Team 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("fae37998-9305-495a-a72f-005a3ab28746")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Support/WaveUtils/WaveConverter.cs b/Support/WaveUtils/WaveConverter.cs new file mode 100644 index 00000000..7d4947b6 --- /dev/null +++ b/Support/WaveUtils/WaveConverter.cs @@ -0,0 +1,50 @@ +using System; +using System.IO; + +// This file is part of the ANX.Framework and originally taken from +// the AC.AL OpenAL library, released under the MIT License. +// For details see: http://acal.codeplex.com/license + +namespace WaveUtils +{ + public class WaveConverter + { + private WaveInfo loadedData; + + public WaveConverter(WaveInfo setLoadedData) + { + setLoadedData = loadedData; + } + + public void ConvertToPcm() + { + ConvertToPcm(loadedData.Channels); + } + + public void ConvertToPcm(int resultChannelCount) + { + switch (loadedData.WaveFormat) + { + case WaveFormat.ALAW: + ALaw.ConvertToPcm(loadedData, resultChannelCount); + break; + + case WaveFormat.MULAW: + MuLaw.ConvertToPcm(loadedData, resultChannelCount); + break; + + case WaveFormat.IEEE_FLOAT: + IEEEFloat.ConvertToPcm(loadedData, resultChannelCount); + break; + + case WaveFormat.MS_ADPCM: + MsAdpcm.ConvertToPcm(loadedData); + break; + + default: + throw new NotSupportedException("The WAVE format " + loadedData.WaveFormat + + " is not supported yet. Unable to load!"); + } + } + } +} diff --git a/Support/WaveUtils/WaveFile.cs b/Support/WaveUtils/WaveFile.cs new file mode 100644 index 00000000..6874e13e --- /dev/null +++ b/Support/WaveUtils/WaveFile.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; +using System.IO; +using ANX.Framework.NonXNA; + +// This file is part of the ANX.Framework and originally taken from +// the AC.AL OpenAL library, released under the MIT License. +// For details see: http://acal.codeplex.com/license + +namespace WaveUtils +{ + /// + /// This class contains all the loading process of a wave file. + /// + /// http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/wave.html + /// + /// Chunk information: http://www.sonicspot.com/guide/wavefiles.html + /// + /// Audio Codecs: http://wiki.multimedia.cx/index.php?title=Category:Audio_Codecs + /// + /// http://netghost.narod.ru/gff/vendspec/micriff/ms_riff.txt + /// + /// Most interesting file about many formats: + /// http://icculus.org/SDL_sound/downloads/external_documentation/wavecomp.htm + /// + /// http://sharkysoft.com/archive/lava/docs/javadocs/lava/riff/wave/doc-files/riffwave-content.htm + /// + public static class WaveFile + { + #region LoadData + public static WaveInfo LoadData(Stream stream, bool rememberUnloadedChunks = false) + { + WaveInfo result = new WaveInfo(); + + using (BinaryReader reader = new BinaryReader(stream)) + { + if (CheckHeader(reader) == false) + { + throw new FormatException("The provided stream is not a valid WAVE file. Unable to load!"); + } + + #region Read Chunks + while (stream.Position < stream.Length - 8) + { + string identifier = new string(reader.ReadChars(4)); + int chunkLength = reader.ReadInt32(); + + if (stream.Position + chunkLength > stream.Length) + { + break; + } + + int startPosition = (int)reader.BaseStream.Position; + + switch (identifier.ToLower()) + { + case "fmt ": + { + #region Load fmt chunk + result.WaveFormat = (WaveFormat)reader.ReadInt16(); + result.Channels = reader.ReadInt16(); + result.SampleRate = reader.ReadInt32(); + int avgBytesPerSec = reader.ReadInt32(); + result.BlockAlign = reader.ReadInt16(); + result.BitsPerSample = reader.ReadInt16(); + + if (chunkLength > 16) + { + short extensionSize = reader.ReadInt16(); + + if (chunkLength > 18) + { + result.ExtSamplesPerBlock = reader.ReadInt16(); + int speakerPositionMask = reader.ReadInt32(); + WaveFormat extFormat = (WaveFormat)reader.ReadInt16(); + if (result.WaveFormat < 0) + { + result.WaveFormat = extFormat; + } + byte[] subFormat = reader.ReadBytes(14); + } + } + + result.ALFormat = (result.Channels == 1 ? + (result.BitsPerSample == 8 ? + ALFormat.Mono8 : + ALFormat.Mono16) : + (result.BitsPerSample == 8 ? + ALFormat.Stereo8 : + ALFormat.Stereo16)); + #endregion + } + break; + + case "fact": + { + #region Load fact chunk + // per channel + int numberOfSamples = reader.ReadInt32(); + // TODO: more + #endregion + } + break; + + case "data": + result.Data = reader.ReadBytes(chunkLength); + break; + + default: + if (rememberUnloadedChunks) + { + var value = new KeyValuePair(identifier, reader.ReadBytes(chunkLength)); + result.UnloadedChunks.Add(value); + } + break; + } + + // If some chunks are incorrect in data length, we ensure that we + // end up in the right position. + int lengthRead = (int)reader.BaseStream.Position - startPosition; + if (lengthRead != chunkLength) + { + reader.BaseStream.Seek(chunkLength - lengthRead, + SeekOrigin.Current); + } + } + #endregion + } + + if (result.Data == null) + { + Logger.Error("There was no data chunk available. Unable to load!"); + return null; + } + + return result; + } + #endregion + + #region CheckHeader + private static bool CheckHeader(BinaryReader reader) + { + string RIFFmagic = new string(reader.ReadChars(4)); + if(RIFFmagic != "RIFF") + { + return false; + } + + // filesize + reader.ReadInt32(); + + string identifierWAVE = new string(reader.ReadChars(4)); + if(identifierWAVE != "WAVE") + { + return false; + } + + return true; + } + #endregion + } +} diff --git a/Support/WaveUtils/WaveFormat.cs b/Support/WaveUtils/WaveFormat.cs new file mode 100644 index 00000000..9818134f --- /dev/null +++ b/Support/WaveUtils/WaveFormat.cs @@ -0,0 +1,33 @@ +using System; + +// This file is part of the ANX.Framework and originally taken from +// the AC.AL OpenAL library, released under the MIT License. +// For details see: http://acal.codeplex.com/license + +namespace WaveUtils +{ + public enum WaveFormat + { + PCM = 1, + /// + /// http://wiki.multimedia.cx/index.php?title=Microsoft_ADPCM + /// + MS_ADPCM = 2, + IEEE_FLOAT = 3, + /// + /// 8-bit ITU-T G.711 A-law + /// http://hazelware.luggle.com/tutorials/mulawcompression.html + /// + ALAW = 6, + /// + /// 8-bit ITU-T G.711 µ-law + /// http://hazelware.luggle.com/tutorials/mulawcompression.html + /// + MULAW = 7, + + /// + /// Determined by SubFormat + /// + WAVE_FORMAT_EXTENSIBLE = 0xFFFE, + } +} diff --git a/Support/WaveUtils/WaveInfo.cs b/Support/WaveUtils/WaveInfo.cs new file mode 100644 index 00000000..5bd66ca4 --- /dev/null +++ b/Support/WaveUtils/WaveInfo.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; + +// This file is part of the ANX.Framework and originally taken from +// the AC.AL OpenAL library, released under the MIT License. +// For details see: http://acal.codeplex.com/license + +namespace WaveUtils +{ + public class WaveInfo + { + public List> UnloadedChunks { get; internal set; } + public WaveFormat WaveFormat { get; internal set; } + public byte[] Data { get; internal set; } + public ALFormat ALFormat { get; internal set; } + public int SampleRate { get; internal set; } + public short BitsPerSample { get; internal set; } + public short BlockAlign { get; internal set; } + public int Channels { get; internal set; } + public short ExtSamplesPerBlock { get; internal set; } + + /// + /// NOTE: This only works with standard PCM data! + /// + public TimeSpan CalculateDuration() + { + float sizeMulBlockAlign = Data.Length / ((int)Channels * 2); + return TimeSpan.FromMilliseconds((double)(sizeMulBlockAlign * 1000f / (float)SampleRate)); + } + + public WaveInfo() + { + UnloadedChunks = new List>(); + } + } +} diff --git a/Support/WaveUtils/WaveUtils.csproj b/Support/WaveUtils/WaveUtils.csproj new file mode 100644 index 00000000..07f0614d --- /dev/null +++ b/Support/WaveUtils/WaveUtils.csproj @@ -0,0 +1,65 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {1986B0ED-3D28-4FEE-82D0-BCC39C87C18C} + Library + Properties + WaveUtils + WaveUtils + v4.0 + 512 + Client + + + true + full + false + ..\..\bin\Debug\ + DEBUG;TRACE + prompt + 4 + x86 + + + pdbonly + true + ..\..\bin\Release\ + TRACE + prompt + 4 + x86 + + + + + + + + + + + + + + + + + + + {6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35} + ANX.Framework + + + + + \ No newline at end of file diff --git a/Support/WaveUtils/WaveUtils_Linux.csproj b/Support/WaveUtils/WaveUtils_Linux.csproj new file mode 100644 index 00000000..99f15b1a --- /dev/null +++ b/Support/WaveUtils/WaveUtils_Linux.csproj @@ -0,0 +1,64 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {1986B0ED-3D28-4FEE-82D0-BCC39C87C18C} + Library + Properties + WaveUtils + WaveUtils + v4.0 + 512 + + + true + full + false + bin\Debug\ + TRACE;DEBUG;LINUX; + prompt + 4 + x86 + + + pdbonly + true + bin\Release\ + TRACE;LINUX; + prompt + 4 + x86 + + + + + + + + + + + + + + + + + + + {6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35} + ANX.Framework + + + + + \ No newline at end of file diff --git a/Support/WaveUtils/WaveUtils_PSVita.csproj b/Support/WaveUtils/WaveUtils_PSVita.csproj new file mode 100644 index 00000000..360a38ec --- /dev/null +++ b/Support/WaveUtils/WaveUtils_PSVita.csproj @@ -0,0 +1,65 @@ + + + + Debug + AnyCPU + 10.0.0 + 2.0 + {1986B0ED-3D28-4FEE-82D0-BCC39C87C18C} + Library + Properties + WaveUtils + WaveUtils + 512 + {69878862-DA7D-4DC6-B0A1-50D8FAB4242F};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + TRACE;DEBUG;PSVITA; + prompt + 4 + x86 + + + pdbonly + true + bin\Release\ + TRACE;PSVITA; + prompt + 4 + x86 + + + + + + + + + + + + + + + + + + + + {6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35} + ANX.Framework + + + + + \ No newline at end of file diff --git a/Support/WaveUtils/WaveUtils_WindowsMetro.csproj b/Support/WaveUtils/WaveUtils_WindowsMetro.csproj new file mode 100644 index 00000000..ec5899f1 --- /dev/null +++ b/Support/WaveUtils/WaveUtils_WindowsMetro.csproj @@ -0,0 +1,70 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {1986B0ED-3D28-4FEE-82D0-BCC39C87C18C} + Library + Properties + WaveUtils + WaveUtils + 512 + {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + en-US + Test_TemporaryKey.pfx + + + true + full + false + bin\Debug\ + TRACE;DEBUG;WINDOWSMETRO; + prompt + 4 + x86 + + + pdbonly + true + bin\Release\ + TRACE;WINDOWSMETRO; + prompt + 4 + x86 + + + + + + + + + + + + + + + + + + + {6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35} + ANX.Framework + + + + + + 11.0 + + + \ No newline at end of file diff --git a/Tools/ANXContentCompilerGUI/ANX.ContentCompiler.GUI.csproj b/Tools/ANXContentCompilerGUI/ANX.ContentCompiler.GUI.csproj index c356e3a7..b95fe1f3 100644 --- a/Tools/ANXContentCompilerGUI/ANX.ContentCompiler.GUI.csproj +++ b/Tools/ANXContentCompilerGUI/ANX.ContentCompiler.GUI.csproj @@ -217,10 +217,6 @@ {5be49183-2f6f-4527-ac90-d816911fcf90} ANX.RenderSystem.Windows.DX10 - - {eb8258e0-6741-4db9-b756-1ebdf67b1ed6} - ANX.RenderSystem.Windows.GL3 - {b30de9c2-0926-46b6-8351-9af276c472d5} ANX.RenderSystem.Windows.DX11 diff --git a/Tools/ProjectConverter/Platforms/MetroConverter.cs b/Tools/ProjectConverter/Platforms/MetroConverter.cs index 6b7353f5..375170ac 100644 --- a/Tools/ProjectConverter/Platforms/MetroConverter.cs +++ b/Tools/ProjectConverter/Platforms/MetroConverter.cs @@ -53,7 +53,7 @@ namespace ProjectConverter.Platforms { string value = includeAttribute.Value; if (value.Contains("ANX.RenderSystem.Windows.DX10") || - value.Contains("ANX.RenderSystem.Windows.GL3") || + value.Contains("ANX.RenderSystem.GL3") || value.Contains("ANX.PlatformSystem.Windows") || value.Contains("ANX.RenderSystem.Windows.DX11") || value.Contains("ANX.SoundSystem.OpenAL")) diff --git a/Tools/StockShaderCodeGenerator/Compiler.cs b/Tools/StockShaderCodeGenerator/Compiler.cs index b092d60e..6a736b81 100644 --- a/Tools/StockShaderCodeGenerator/Compiler.cs +++ b/Tools/StockShaderCodeGenerator/Compiler.cs @@ -3,7 +3,7 @@ using System; using System.IO; using ANX.RenderSystem.Windows.DX10; using ANX.RenderSystem.Windows.DX11; -using ANX.RenderSystem.Windows.GL3; +using ANX.RenderSystem.GL3; using DX11MetroShaderGenerator; using System.Diagnostics; @@ -76,7 +76,7 @@ namespace StockShaderCodeGenerator byteCode = metroGenerator.ResultByteCode; break; - case "ANX.RenderSystem.Windows.GL3": + case "ANX.RenderSystem.GL3": byteCode = ShaderHelper.SaveShaderCode(sourceCode); break; diff --git a/Tools/StockShaderCodeGenerator/StockShaderCodeGenerator.csproj b/Tools/StockShaderCodeGenerator/StockShaderCodeGenerator.csproj index 4a1fa642..c8c87cbd 100644 --- a/Tools/StockShaderCodeGenerator/StockShaderCodeGenerator.csproj +++ b/Tools/StockShaderCodeGenerator/StockShaderCodeGenerator.csproj @@ -56,14 +56,14 @@ {A4D3AD34-E49C-4142-8620-2AFF44ED6719} ANX.BaseDirectX + + {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} + ANX.RenderSystem.GL3 + {5BE49183-2F6F-4527-AC90-D816911FCF90} ANX.RenderSystem.Windows.DX10 - - {EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} - ANX.RenderSystem.Windows.GL3 - {B30DE9C2-0926-46B6-8351-9AF276C472D5} ANX.RenderSystem.Windows.DX11 diff --git a/shader/GL3/build.xml b/shader/GL3/build.xml index d5ddb97c..711b57b2 100644 --- a/shader/GL3/build.xml +++ b/shader/GL3/build.xml @@ -1,29 +1,29 @@ + Target="../RenderSystems/ANX.Framework.GL3/ShaderByteCode.cs" + Namespace="ANX.Framework.GL3">