port from perforce
This commit is contained in:
147
aiwaz/Backup/Aiwaz.Resources/RenderTargetTexture.cs
Normal file
147
aiwaz/Backup/Aiwaz.Resources/RenderTargetTexture.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Aiwaz.Contracts;
|
||||
using Aiwaz.Core;
|
||||
using Aiwaz.Resources.Attributes;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Aiwaz.Resources
|
||||
{
|
||||
[CreationParameters("Create an empty RenderTarget texture")]
|
||||
public class RenderTargetTextureParams : ICreationParams
|
||||
{
|
||||
public int width;
|
||||
public int height;
|
||||
public SlimDX.DXGI.Format format;
|
||||
public int multiSampleCount;
|
||||
public int multiSampleQuality;
|
||||
|
||||
public RenderTargetTextureParams()
|
||||
{
|
||||
width = 512;
|
||||
height = 512;
|
||||
format = SlimDX.DXGI.Format.Unknown;
|
||||
multiSampleCount = 0;
|
||||
multiSampleQuality = 0;
|
||||
}
|
||||
}
|
||||
|
||||
[AiwazResource("RenderTarget texture", "An output target for render operations which could be used as texture input.")]
|
||||
public class RenderTargetTexture : RenderTarget
|
||||
{
|
||||
public RenderTargetTexture(RenderTargetTextureParams parameters)
|
||||
: base()
|
||||
{
|
||||
creationParams = parameters;
|
||||
Console.WriteLine(string.Format("Creating RenderTargetTexture ({0}x{1} {2})..", parameters.width, parameters.height, parameters.format.ToString()));
|
||||
|
||||
this.BuildRenderTargetTexture(parameters.width, parameters.height, parameters.format, parameters.multiSampleCount, parameters.multiSampleQuality);
|
||||
}
|
||||
|
||||
protected void BuildRenderTargetTexture(int width, int height, SlimDX.DXGI.Format format, int multiSampleCount, int multiSampleQuality)
|
||||
{
|
||||
if (this.Texture != null &&
|
||||
width == this.RenderTargetWidth &&
|
||||
height == this.RenderTargetHeight &&
|
||||
format == this.RenderTargetFormat &&
|
||||
this.multiSampleCount == multiSampleCount &&
|
||||
this.multiSampleQuality == multiSampleQuality)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.DisposeInternal();
|
||||
|
||||
// get missing information
|
||||
if (multiSampleCount == 0)
|
||||
multiSampleCount = 1;
|
||||
if (width == 0)
|
||||
width = 1;
|
||||
if (height == 0)
|
||||
height = 1;
|
||||
if (format == SlimDX.DXGI.Format.Unknown)
|
||||
format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
|
||||
|
||||
this.multiSampleCount = multiSampleCount;
|
||||
this.multiSampleQuality = multiSampleQuality;
|
||||
|
||||
if (this.Texture == null)
|
||||
this.Texture = new Texture(new EmptyTextureParams()
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
Elements = 1,
|
||||
MipLevels = 0,
|
||||
Format = format,
|
||||
AccessType = SlimDX.Direct3D10.ResourceUsage.Staging,
|
||||
RenderTarget = true,
|
||||
MultiSampleCount = multiSampleCount,
|
||||
MultiSampleQuality = multiSampleQuality
|
||||
});
|
||||
else if (this.Texture is Texture)
|
||||
((Texture)this.Texture).CreateRenderTargetTexture(width, height, format, multiSampleCount, multiSampleQuality);
|
||||
|
||||
this.DX10RenderTargetView = new SlimDX.Direct3D10.RenderTargetView(Engine.Device, this.Texture.Texture2D);
|
||||
|
||||
this.ViewPort = new ViewPort()
|
||||
{
|
||||
Width = width,
|
||||
Height = height
|
||||
};
|
||||
}
|
||||
|
||||
public override int RenderTargetWidth
|
||||
{
|
||||
get { return Texture.TextureWidth; }
|
||||
}
|
||||
|
||||
public override int RenderTargetHeight
|
||||
{
|
||||
get { return Texture.TextureHeight; }
|
||||
}
|
||||
|
||||
public override SlimDX.DXGI.Format RenderTargetFormat
|
||||
{
|
||||
get { return Texture.TextureFormat; }
|
||||
}
|
||||
|
||||
#region IRenderTargetTexture Members
|
||||
|
||||
public void Resize(int width, int height)
|
||||
{
|
||||
if (this.RenderTargetWidth == width || this.RenderTargetHeight == height)
|
||||
return;
|
||||
|
||||
var usedDepthStencilBuffer = this.HasDepthStencilBuffer;
|
||||
this.BuildRenderTargetTexture(width, height, RenderTargetFormat, multiSampleCount, multiSampleQuality);
|
||||
this.HasDepthStencilBuffer = usedDepthStencilBuffer;
|
||||
}
|
||||
|
||||
public Texture Texture { get; protected set; }
|
||||
|
||||
#endregion
|
||||
|
||||
private ICreationParams creationParams;
|
||||
public override ICreationParams CreationParams
|
||||
{
|
||||
get { return creationParams; }
|
||||
}
|
||||
|
||||
private ObservableCollection<IResource> children;
|
||||
[ReadOnly]
|
||||
public override ObservableCollection<IResource> Children
|
||||
{
|
||||
get
|
||||
{
|
||||
if (children == null)
|
||||
{
|
||||
children = new ObservableCollection<IResource>();
|
||||
children.Add(Texture);
|
||||
}
|
||||
return children;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user