- static CompileShader method of GL3 render system now returns simply the shader source provided by the ContentImporter. This should be enough to compile a shader during runtime.

- added a SpriteEffect_GLSL effect file, but it still contains HLSL code
- started translate function for Keys in ANX.InputSystem.Windows.XInput. Still many keys to do
- fixed issue #449 ("debug GetCurrentState of Keyboard"). Keyboard input now working (see WindowsGame sample, Escape to exit)
This commit is contained in:
Glatzemann 2011-11-15 05:46:08 +00:00
parent 904ab0c529
commit 91a7451f97
8 changed files with 131 additions and 112 deletions

View File

@ -115,108 +115,6 @@ namespace ANX.Framework.Windows.DX10
//return texture;
}
/*
public Texture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount, byte[] colorData)
{
if (mipCount > 1)
{
throw new Exception("creating textures with mip map not yet implemented");
}
GraphicsDeviceWindowsDX10 graphicsDX10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice;
Texture2D_DX10 texture = new Texture2D_DX10(graphics, width, height);
SharpDX.Direct3D10.Texture2DDescription description = new SharpDX.Direct3D10.Texture2DDescription()
{
Width = width,
Height = height,
MipLevels = mipCount,
ArraySize = mipCount,
Format = FormatConverter.Translate(surfaceFormat),
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = SharpDX.Direct3D10.ResourceUsage.Dynamic,
BindFlags = SharpDX.Direct3D10.BindFlags.ShaderResource,
CpuAccessFlags = SharpDX.Direct3D10.CpuAccessFlags.Write,
OptionFlags = SharpDX.Direct3D10.ResourceOptionFlags.None,
};
texture.NativeTexture = new SharpDX.Direct3D10.Texture2D(graphicsDX10.NativeDevice, description);
texture.NativeShaderResourceView = new SharpDX.Direct3D10.ShaderResourceView(graphicsDX10.NativeDevice, texture.NativeTexture);
// description of texture formats of DX10: http://msdn.microsoft.com/en-us/library/bb694531(v=VS.85).aspx
// more helpfull information on DX10 textures: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx
int formatSize = FormatConverter.FormatSize(surfaceFormat);
if (surfaceFormat == SurfaceFormat.Color)
{
int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubresourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = texture.NativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None);
int rowPitch = rectangle.Pitch;
unsafe
{
byte* pTexels = (byte*)rectangle.DataPointer;
int srcIndex = 0;
for (int row = 0; row < height; row++)
{
int rowStart = row * rowPitch;
for (int col = 0; col < width; col++)
{
int colStart = col * formatSize;
pTexels[rowStart + colStart + 0] = colorData[srcIndex++];
pTexels[rowStart + colStart + 1] = colorData[srcIndex++];
pTexels[rowStart + colStart + 2] = colorData[srcIndex++];
pTexels[rowStart + colStart + 3] = colorData[srcIndex++];
}
}
}
texture.NativeTexture.Unmap(subresource);
}
else if (surfaceFormat == SurfaceFormat.Dxt5 || surfaceFormat == SurfaceFormat.Dxt3 || surfaceFormat == SurfaceFormat.Dxt1)
{
int w = (width + 3) >> 2;
int h = (height + 3) >> 2;
formatSize = (surfaceFormat == SurfaceFormat.Dxt1) ? 8 : 16;
int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubresourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = texture.NativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None);
SharpDX.DataStream ds = new SharpDX.DataStream(rectangle.DataPointer, width * height * 4 * 2, true, true);
int pitch = rectangle.Pitch;
int col = 0;
int index = 0; // startIndex
int count = colorData.Length; // elementCount
int actWidth = w * formatSize;
for (int i = 0; i < h; i++)
{
ds.Position = (i * pitch) + (col * formatSize);
if (count <= 0)
{
break;
}
else if (count < actWidth)
{
ds.WriteRange<byte>(colorData, index, count);
break;
}
ds.WriteRange<byte>(colorData, index, actWidth);
index += actWidth;
count -= actWidth;
}
texture.NativeTexture.Unmap(subresource);
}
else
{
throw new Exception(string.Format("creating textures of format {0} not yet implemented...", surfaceFormat.ToString()));
}
return texture;
}
*/
public INativeBlendState CreateBlendState()
{
return new BlendState_DX10();

View File

@ -34,3 +34,5 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.7.3.0")]
[assembly: AssemblyFileVersion("0.7.3.0")]
[assembly: InternalsVisibleTo("ANX.Framework.ContentPipeline")]

View File

@ -144,6 +144,15 @@ namespace ANX.Framework.Windows.GL3
return null;
}
public static byte[] CompileShader(string effectCode)
{
//TODO: pre-compiled shaders are supported in GL 4.1 and newer only ?!?
//TODO: encode string somehow to protect shader source
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
return enc.GetBytes(effectCode);
}
#endregion
#region INativeEffect Member
@ -200,11 +209,5 @@ namespace ANX.Framework.Windows.GL3
}
}
#endregion
public static byte[] CompileShader(string effectCode)
{
//TODO: implement to be used by ContentPipeline
throw new NotImplementedException();
}
}
}

View File

@ -34,3 +34,5 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.1.0")]
[assembly: AssemblyFileVersion("0.5.1.0")]
[assembly: InternalsVisibleTo("ANX.Framework.ContentPipeline")]

View File

@ -56,6 +56,22 @@ namespace ANX.InputSystem.Windows.XInput
{
internal class FormatConverter
{
public static ANX.Framework.Input.Keys Translate(SharpDX.DirectInput.Key key)
{
//TODO: implement all keys
//TODO: test if a array with the mapping which is constructed once is faster
switch (key)
{
case SharpDX.DirectInput.Key.A:
return Keys.A;
case SharpDX.DirectInput.Key.Escape:
return Keys.Escape;
}
throw new NotImplementedException();
}
public static KeyboardState Translate(SharpDX.DirectInput.KeyboardState keyboardState)
{
int keyCount = keyboardState.PressedKeys.Count;
@ -63,7 +79,7 @@ namespace ANX.InputSystem.Windows.XInput
for (int i = 0; i < keyCount; i++)
{
keys[i] = (ANX.Framework.Input.Keys)((int)keyboardState.PressedKeys[i]);
keys[i] = Translate(keyboardState.PressedKeys[i]);
}
KeyboardState ks = new KeyboardState(keys);

View File

@ -78,12 +78,15 @@ namespace ANX.InputSystem.Windows.XInput
this.nativeState = new KeyboardState();
}
public Framework.Input.KeyboardState GetState()
public Framework.Input.KeyboardState GetState(Framework.PlayerIndex playerIndex)
{
return GetState(Framework.PlayerIndex.One);
//TODO: prevent new
// only available on XBox, behaviour regarding MSDN: empty keystate
return new Framework.Input.KeyboardState();
}
public Framework.Input.KeyboardState GetState(Framework.PlayerIndex playerIndex)
public Framework.Input.KeyboardState GetState()
{
if (this.nativeKeyboard == null && this.WindowHandle != null && this.WindowHandle != IntPtr.Zero)
{

View File

@ -0,0 +1,87 @@
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
uniform extern float4x4 MatrixTransform;
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
struct VertexShaderInput
{
float4 pos : POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
PixelShaderInput SpriteVertexShader( VertexShaderInput input )
{
PixelShaderInput output = (PixelShaderInput)0;
output.pos = mul(input.pos, MatrixTransform);
output.col = input.col;
output.tex = input.tex;
return output;
}
float4 SpritePixelShader( PixelShaderInput input ) : SV_Target
{
return Texture.Sample(TextureSampler, input.tex) * input.col;
}
technique10 SpriteTechnique
{
pass SpriteColorPass
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, SpriteVertexShader() ) );
SetPixelShader( CompileShader( ps_4_0, SpritePixelShader() ) );
}
}

View File

@ -84,6 +84,14 @@
<Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Effects\SpriteEffect_GLSL.fx">
<Name>SpriteEffect_GLSL</Name>
<Importer>EffectImporter</Importer>
<Processor>AnxEffectProcessor</Processor>
<ProcessorParameters_OutputFormat>OPEN_GL3_GLSL</ProcessorParameters_OutputFormat>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.