本文整理汇总了C#中Texture2D.AsSurface方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.AsSurface方法的具体用法?C# Texture2D.AsSurface怎么用?C# Texture2D.AsSurface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture2D
的用法示例。
在下文中一共展示了Texture2D.AsSurface方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Texture
public Texture(Texture2D texture)
{
InternalTexture2D = texture;
/* Cache the description for perf reasons */
Description = texture.Description;
InternalDevice = InternalTexture2D.Device;
/* SlimDX will only let us pull out the surface once until it is disposed.
* We will do that here as it is the logic place to store ref to the DXGI surface */
InternalDxgiSurface = InternalTexture2D.AsSurface();
}
示例2: ResizeDevice
public void ResizeDevice(int width, int height)
{
lock (this)
{
if (width < 0)
{
throw new ArgumentOutOfRangeException("width", "Value must be positive.");
}
if (height < 0)
{
throw new ArgumentOutOfRangeException("height", "Value must be positive.");
}
if ((width <= this.width) && (height <= this.height)) return;
// Recreate the render target
// Assign result to temporary variable in case CreateTexture2D throws an exception.
var texture = CreateTexture(Math.Max(width, this.width), Math.Max(height, this.height), true);
if (this.texture != null)
{
this.texture.Dispose();
}
this.texture = texture;
var shareableTexture = CreateTexture(Math.Max(width, this.width), Math.Max(height, this.height), false);
if (this.shareableTexture != null)
{
this.shareableTexture.Dispose();
}
this.shareableTexture = shareableTexture;
//if (renderTargetView != null) renderTargetView.Dispose();
//this.renderTargetView = new RenderTargetView(device, shareableTexture);
this.width = texture.Description.Width;
this.height = texture.Description.Height;
SlimDX.DXGI.Surface surface = texture.AsSurface();
CreateRenderTarget(surface);
if (DeviceResized != null)
DeviceResized(this, EventArgs.Empty);
}
}
示例3: OnResourceLoad
protected override void OnResourceLoad()
{
base.OnResourceLoad();
m_Imposter.LoadResources();
m_Texture = new Texture2D(GameEnvironment.Device, new Texture2DDescription()
{
Format = SlimDX.DXGI.Format.R32_Float,
Width = 640,
Height = 480,
MipLevels = 1,
ArraySize = 1,
BindFlags = BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Dynamic,
SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0)
});
m_TextureSurface = m_Texture.AsSurface();
DataRectangle data = m_TextureSurface.Map(SlimDX.DXGI.MapFlags.Discard | SlimDX.DXGI.MapFlags.Write);
//int rowSize = (m_Texture.Description.Width * 4);
int stride = data.Pitch / 4;
int stripeWidth = 16;
int stripeValue = 0;
bool stripeOn = false;
for (int i = 0, ie = m_Texture.Description.Height; i < ie; i++)
{
stripeValue = 0;
stripeOn = false;
for (int p = 0; p < stride; p++)
{
if (stripeValue++ >= stripeWidth)
{
stripeOn = !stripeOn;
stripeValue = 0;
}
if (stripeOn == true)
{
data.Data.Write(1f);
}
else
{
data.Data.Write(0f);
}
}
}
m_TextureSurface.Unmap();
m_TextureResourceView = new ShaderResourceView(GameEnvironment.Device, m_Texture, new ShaderResourceViewDescription()
{
Dimension = ShaderResourceViewDimension.Texture2D,
Format = SlimDX.DXGI.Format.R32_Float,
ArraySize = 1,
MipLevels = 1,
MostDetailedMip = 0,
});
m_TestImage.TextureView = m_TextureResourceView;
m_TestImage.LoadResources();
}
示例4: LoadResources
public override void LoadResources()
{
if (m_Source != null && m_Source.Device.DepthResolution != ImageResolution.Invalid)
{
if (Disposed == true)
{
m_Buffer = new float[KinectHelper.GetSizeForResolution(m_Source.Device.DepthResolution) * 4];
m_Texture = new Texture2D(GameEnvironment.Device, new Texture2DDescription()
{
Format = SlimDX.DXGI.Format.R32_Float,
Width = KinectHelper.GetWidthForResolution(m_Source.Device.DepthResolution),
Height = KinectHelper.GetHeightForResolution(m_Source.Device.DepthResolution),
MipLevels = 1,
ArraySize = 1,
BindFlags = BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Dynamic,
SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0)
});
m_TextureSurface = m_Texture.AsSurface();
DataRectangle data = m_TextureSurface.Map(SlimDX.DXGI.MapFlags.Discard | SlimDX.DXGI.MapFlags.Write);
int stride = data.Pitch / 4;
for (int i = 0, ie = m_Texture.Description.Height; i < ie; i++)
{
for (int p = 0; p < stride; p++)
{
data.Data.Write(0f);
}
}
m_TextureSurface.Unmap();
m_TextureResourceView = new ShaderResourceView(GameEnvironment.Device, m_Texture, new ShaderResourceViewDescription()
{
Dimension = ShaderResourceViewDimension.Texture2D,
Format = SlimDX.DXGI.Format.R32_Float,
ArraySize = 1,
MipLevels = 1,
MostDetailedMip = 0,
});
m_Image.TextureView = m_TextureResourceView;
m_Image.LoadResources();
Disposed = false;
}
}
}
示例5: LoadResources
public void LoadResources()
{
if (m_Disposed == true)
{
m_ScanBytes = new byte[m_Description.Width * 4];
m_Bytes = new byte[m_Description.Width * m_Description.Height * m_PixelSizeInBytes];
m_CaptureTexture = new Texture2D(GameEnvironment.Device, m_Description);
m_CaptureSurface = m_CaptureTexture.AsSurface();
m_Bitmap = new System.Drawing.Bitmap(m_Description.Width, m_Description.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
m_Disposed = false;
}
}
示例6: RenderToTexture
public void RenderToTexture(Bitmap bmp)
{
BitmapData data = null;
try
{
data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
byte[] dest = new byte[data.Stride * bmp.Height];
Marshal.Copy(data.Scan0, dest, 0, dest.Length);
m_Texture = new Texture2D(GameEnvironment.Device, new Texture2DDescription()
{
Format = SlimDX.DXGI.Format.R16G16B16A16_Float, // .R16_Float,
Width = bmp.Width,
Height = bmp.Height,
MipLevels = 1,
ArraySize = 1,
BindFlags = BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Dynamic,
SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0)
});
//DataRectangle dataRect = m_Texture.Map(0, MapMode.WriteDiscard, MapFlags.None);
SlimDX.DXGI.Surface surface = m_Texture.AsSurface();
DataRectangle dataRect = surface.Map(SlimDX.DXGI.MapFlags.Write | SlimDX.DXGI.MapFlags.Discard); ;
float cScale = 1f / 255f;
for (int i = 0; i < bmp.Width * bmp.Height * 4; i += 4)
{
dataRect.Data.Write(new Half4(new Half((float)dest[i + 0] * cScale), new Half((float)dest[i + 1] * cScale), new Half((float)dest[i + 2] * cScale), new Half((float)dest[i + 3] * cScale)));
}
//m_Texture.Unmap(0);
surface.Unmap();
surface.Dispose();
m_TextureView = new ShaderResourceView(GameEnvironment.Device, m_Texture, new ShaderResourceViewDescription()
{
Dimension = ShaderResourceViewDimension.Texture2D,
Format = SlimDX.DXGI.Format.R16G16B16A16_Float, //.R16_Float,
ArraySize = 1,
MipLevels = 1,
MostDetailedMip = 0,
});
}
finally
{
if (data != null) { bmp.UnlockBits(data); }
}
}