- some work on Texture2DWriter (not finished yet)

- fixed issue #1021 (RenderTarget issue with SpriteBatch)
This commit is contained in:
Glatzemann 2012-09-28 13:05:38 +00:00 committed by Konstantin Koch
parent 4c4b999b9c
commit 61ba3497f2
10 changed files with 172 additions and 24 deletions

View File

@ -149,6 +149,7 @@
<Compile Include="Serialization\Compiler\GenericContentTypeWriter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serialization\Compiler\GraphicTypeWriters\EffectWriter.cs" />
<Compile Include="Serialization\Compiler\GraphicTypeWriters\Texture2DWriter.cs" />
<Compile Include="Serialization\Compiler\GraphicTypeWriters\SpriteFontWriter.cs" />
<Compile Include="Serialization\Compiler\GraphicTypeWriters\TextureWriter.cs" />
<Compile Include="Serialization\Compiler\MathTypeWriters\BoundingBoxWriter.cs" />

View File

@ -1,7 +1,9 @@
#region Using Statements
using ANX.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
#endregion
@ -34,12 +36,26 @@ namespace ANX.Framework.Content.Pipeline.Graphics
public override byte[] GetPixelData()
{
throw new NotImplementedException();
int rowSize = Marshal.SizeOf(typeof(T)) * base.Width;
byte[] array = new byte[rowSize * base.Height];
for (int i = 0; i < base.Height; i++)
{
T[] row = GetRow(i);
BitCopier.Copy<T, byte>(this.GetRow(i), 0, PixelBitmapContent<T>.pixelSize, array, i * num, PixelBitmapContent<T>.pixelSize, PixelBitmapContent<T>.pixelSize, base.Width);
}
return array;
}
public T[] GetRow(int y)
{
throw new NotImplementedException();
T[] row = new T[Width];
for (int col = 0; col < Width; col++)
{
row[col] = pixels[col, y];
}
return row;
}
public void SetPixel(int x, int y, T value)
@ -67,9 +83,65 @@ namespace ANX.Framework.Content.Pipeline.Graphics
throw new NotImplementedException();
}
public override bool TryGetFormat(out Framework.Graphics.SurfaceFormat format)
public override bool TryGetFormat(out SurfaceFormat format)
{
throw new NotImplementedException();
string type = typeof(T).Name.ToLowerInvariant();
switch (type)
{
case "float":
format = SurfaceFormat.Single;
return true;
case "vector2":
format = SurfaceFormat.Single;
return true;
case "vector4":
format = SurfaceFormat.Vector4;
return true;
case "halfsingle":
format = SurfaceFormat.HalfVector2;
return true;
case "halfvector2":
format = SurfaceFormat.HalfVector2;
return true;
case "halfvector4":
format = SurfaceFormat.HalfVector4;
return true;
case "bgra5551":
format = SurfaceFormat.Bgra5551;
return true;
case "bgr565":
format = SurfaceFormat.Bgr565;
return true;
case "bgra4444":
format = SurfaceFormat.Bgra4444;
return true;
case "color":
format = SurfaceFormat.Color;
return true;
case "rg32":
format = SurfaceFormat.Rg32;
return true;
case "rgba64":
format = SurfaceFormat.Rgba64;
return true;
case "rgba1010102":
format = SurfaceFormat.Rgba1010102;
return true;
case "alpha8":
format = SurfaceFormat.Alpha8;
return true;
case "normalizedbyte2":
format = SurfaceFormat.NormalizedByte2;
return true;
case "normalizedbyte4":
format = SurfaceFormat.NormalizedByte4;
return true;
default:
format = Framework.Graphics.SurfaceFormat.Color;
return false;
}
}
}
}

View File

@ -0,0 +1,62 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.Content.Pipeline.Graphics;
using System.Reflection;
using ANX.Framework.Graphics;
#endregion
// 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.Content.Pipeline.Serialization.Compiler
{
[ContentTypeWriter]
internal class Texture2DWriter : BuiltinTypeWriter<Texture2DContent>
{
protected override Assembly RuntimeAssembly
{
get
{
return typeof(Texture).Assembly;
}
}
protected internal override void Write(ContentWriter output, Texture2DContent value)
{
System.Diagnostics.Debugger.Break();
BitmapContent bitmapContent = value.Faces[0][0];
SurfaceFormat format;
if (!bitmapContent.TryGetFormat(out format))
{
throw new InvalidContentException("bad texture type");
}
// write header
output.Write((int)format);
output.Write(bitmapContent.Width);
output.Write(bitmapContent.Height);
output.Write(value.Faces[0].Count);
foreach (MipmapChain current in value.Faces)
{
foreach (BitmapContent currentFace in current)
{
byte[] pixelData = currentFace.GetPixelData();
output.Write(pixelData.Length);
output.Write(pixelData);
}
}
}
public override string GetRuntimeType(TargetPlatform targetPlatform)
{
return ContentTypeWriter.GetStrongTypeName(typeof(Texture2D), targetPlatform);
}
}
}

View File

@ -12,13 +12,6 @@ namespace ANX.Framework.Content
{
protected internal override Texture2D Read(ContentReader input, Texture2D existingInstance)
{
//IServiceProvider service = input.ContentManager.ServiceProvider;
//var renderSystem = service.GetService(typeof(IRenderSystemCreator)) as IRenderSystemCreator;
//if (renderSystem == null)
// throw new ContentLoadException("Service not found IRenderSystemCreator");
//GraphicsDevice graphics = input.ResolveGraphicsDevice();
SurfaceFormat surfaceFormat = (SurfaceFormat)input.ReadInt32();
int width = input.ReadInt32();
int height = input.ReadInt32();

View File

@ -87,7 +87,15 @@ namespace ANX.Framework.Graphics
[MarshalAsAttribute(UnmanagedType.U1)] bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat)
: base(graphicsDevice)
{
this.depthStencilFormat = DepthFormat.None;
this.width = width;
this.height = height;
OneOverWidth = 1f / width;
OneOverHeight = 1f / height;
base.levelCount = 1;
base.format = preferredFormat;
this.depthStencilFormat = preferredDepthFormat;
this.multiSampleCount = 0;
this.usage = RenderTargetUsage.DiscardContents;
@ -102,6 +110,14 @@ namespace ANX.Framework.Graphics
int preferredMultiSampleCount, RenderTargetUsage usage)
: base(graphicsDevice)
{
this.width = width;
this.height = height;
OneOverWidth = 1f / width;
OneOverHeight = 1f / height;
base.levelCount = 1;
base.format = preferredFormat;
this.depthStencilFormat = preferredDepthFormat;
this.multiSampleCount = preferredMultiSampleCount;
this.usage = usage;

View File

@ -583,8 +583,8 @@ namespace ANX.Framework.Graphics
cachedTransformMatrix = new Matrix()
{
M11 = 2f * (this.viewportWidth > 0 ? 1f / (float)this.viewportWidth : 0f),
M22 = 2f * (this.viewportHeight > 0 ? -1f / (float)this.viewportHeight : 0f),
M11 = 2f * (this.viewportWidth > 0 ? 1f / ((float)this.viewportWidth - 1f) : 0f),
M22 = 2f * (this.viewportHeight > 0 ? -1f / ((float)this.viewportHeight - 1f) : 0f),
M33 = 1f,
M44 = 1f,
M41 = -1f,

View File

@ -58,6 +58,7 @@ namespace ANX.RenderSystem.Windows.DX10
{
backBuffer = Dx10.Texture2D.FromSwapChain<Dx10.Texture2D>(swapChain, 0);
renderView = new Dx10.RenderTargetView(nativeDevice, backBuffer);
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
}
#endregion
@ -112,6 +113,7 @@ namespace ANX.RenderSystem.Windows.DX10
this.depthStencilBuffer = new Dx10.Texture2D(nativeDevice, depthStencilTextureDesc);
this.depthStencilView = new Dx10.DepthStencilView(nativeDevice, this.depthStencilBuffer);
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
// this workaround is working but maybe not the best solution to issue #472
Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil, Vector4.Zero, 1.0f, 0);
@ -207,7 +209,7 @@ namespace ANX.RenderSystem.Windows.DX10
nativeDevice.InputAssembler.PrimitiveTopology = DxFormatConverter.Translate(primitiveType);
nativeDevice.Rasterizer.SetViewports(currentViewport);
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
//nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
if (indexBuffer != null)
{
@ -233,7 +235,7 @@ namespace ANX.RenderSystem.Windows.DX10
nativeDevice.InputAssembler.PrimitiveTopology = DxFormatConverter.Translate(primitiveType);
nativeDevice.Rasterizer.SetViewports(currentViewport);
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
//nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
@ -255,7 +257,7 @@ namespace ANX.RenderSystem.Windows.DX10
nativeDevice.InputAssembler.PrimitiveTopology = DxFormatConverter.Translate(primitiveType);
nativeDevice.Rasterizer.SetViewports(currentViewport);
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
//nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
if (indexBuffer != null)
{

View File

@ -32,7 +32,7 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.7.21.*")]
[assembly: AssemblyFileVersion("0.7.21.0")]
[assembly: AssemblyVersion("0.7.22.*")]
[assembly: AssemblyFileVersion("0.7.22.0")]
[assembly: InternalsVisibleTo("ANX.Framework.ContentPipeline")]

View File

@ -63,6 +63,7 @@ namespace ANX.RenderSystem.Windows.DX11
{
backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(swapChain, 0);
renderView = new RenderTargetView(nativeDevice.Device, backBuffer);
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
}
#endregion
@ -117,6 +118,7 @@ namespace ANX.RenderSystem.Windows.DX11
this.depthStencilBuffer = new SharpDX.Direct3D11.Texture2D(nativeDevice.Device, depthStencilTextureDesc);
this.depthStencilView = new DepthStencilView(nativeDevice.Device, this.depthStencilBuffer);
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil, ANX.Framework.Vector4.Zero, 1.0f, 0); //TODO: this workaround is working but maybe not the best solution to issue #472
}
@ -210,7 +212,7 @@ namespace ANX.RenderSystem.Windows.DX11
nativeDevice.InputAssembler.PrimitiveTopology = DxFormatConverter.Translate(primitiveType);
nativeDevice.Rasterizer.SetViewports(currentViewport);
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
//nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
if (indexBuffer != null)
{
@ -240,7 +242,7 @@ namespace ANX.RenderSystem.Windows.DX11
nativeDevice.InputAssembler.PrimitiveTopology = DxFormatConverter.Translate(primitiveType);
nativeDevice.Rasterizer.SetViewports(currentViewport);
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
//nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
@ -261,7 +263,7 @@ namespace ANX.RenderSystem.Windows.DX11
nativeDevice.InputAssembler.PrimitiveTopology = DxFormatConverter.Translate(primitiveType);
nativeDevice.Rasterizer.SetViewports(currentViewport);
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
//nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
if (indexBuffer != null)
{

View File

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Buildnummer
// Revision
//
[assembly: AssemblyVersion("0.7.13.*")]
[assembly: AssemblyFileVersion("0.7.13.0")]
[assembly: AssemblyVersion("0.7.14.*")]
[assembly: AssemblyFileVersion("0.7.14.0")]