本文整理汇总了C#中Vector2I.Size方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2I.Size方法的具体用法?C# Vector2I.Size怎么用?C# Vector2I.Size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector2I
的用法示例。
在下文中一共展示了Vector2I.Size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetScreenData
private unsafe static byte[] GetScreenData(Vector2I resolution, byte[] screenData = null)
{
const uint headerPadding = 256; // Need to allocate some space for the bitmap headers
const uint bytesPerPixel = 4;
uint imageSizeInBytes = (uint)(resolution.Size() * bytesPerPixel);
uint dataSizeInBytes = imageSizeInBytes + headerPadding;
byte[] returnData = null;
if(screenData == null)
screenData = new byte[imageSizeInBytes];
else if(screenData.Length != imageSizeInBytes)
{
Debug.Fail("Preallocated buffer for GetScreenData incorrect size: " + imageSizeInBytes.ToString() + " expected, " + screenData.Length * bytesPerPixel + " received");
return returnData;
}
MyBindableResource imageSource = Backbuffer;
if (imageSource == null)
return returnData;
if(imageSizeInBytes > int.MaxValue)
{
Debug.Fail("Image size too large to read!");
return returnData;
}
MyBindableResource imageResource = imageSource;
if (resolution.X != imageResource.GetSize().X || resolution.Y != imageResource.GetSize().Y)
{
imageResource = m_lastScreenDataResource;
if (imageResource == null || (imageResource.GetSize().X != resolution.X || imageResource.GetSize().Y != resolution.Y))
{
if (m_lastScreenDataResource != null && m_lastScreenDataResource != Backbuffer)
{
m_lastScreenDataResource.Release();
}
m_lastScreenDataResource = null;
imageResource = new MyRenderTarget(resolution.X, resolution.Y, MyRender11Constants.DX11_BACKBUFFER_FORMAT, 0, 0);
}
MyCopyToRT.Run(imageResource, imageSource, new MyViewport(resolution));
}
m_lastScreenDataResource = imageResource;
Stream dataStream = m_lastDataStream;
if (m_lastDataStream == null || m_lastDataStream.Length != dataSizeInBytes)
{
if (m_lastDataStream != null)
{
m_lastDataStream.Dispose();
m_lastDataStream = null;
}
dataStream = new DataStream((int)dataSizeInBytes, true, true);
}
m_lastDataStream = dataStream;
Resource.ToStream(MyRenderContext.Immediate.DeviceContext, imageResource.m_resource, ImageFileFormat.Bmp, dataStream);
if (!(dataStream.CanRead && dataStream.CanSeek))
{
Debug.Fail("Screen data stream does not support the necessary operations to get the data");
return returnData;
}
fixed (byte* dataPointer = screenData)
{
GetBmpDataFromStream(dataStream, dataPointer, imageSizeInBytes);
}
returnData = screenData;
if (m_lastDataStream != null)
m_lastDataStream.Seek(0, SeekOrigin.Begin);
return returnData;
}
示例2: GetScreenData
private unsafe static byte[] GetScreenData(Vector2I resolution, byte[] screenData = null)
{
const uint headerPadding = 256; // Need to allocate some space for the bitmap headers
const uint bytesPerPixel = 4;
uint imageSizeInBytes = (uint)(resolution.Size() * bytesPerPixel);
uint dataSizeInBytes = imageSizeInBytes + headerPadding;
byte[] returnData = null;
if(screenData == null)
screenData = new byte[imageSizeInBytes];
else if(screenData.Length != imageSizeInBytes)
{
Debug.Fail("Preallocated buffer for GetScreenData incorrect size: " + imageSizeInBytes.ToString() + " expected, " + screenData.Length + " received");
return returnData;
}
MyBindableResource imageSource = Backbuffer;
MyBindableResource imageSourceResourceView = null;
if (imageSource != null && (resolution.X != imageSource.GetSize().X || resolution.Y != imageSource.GetSize().Y))
{
MyViewKey viewKey = new MyViewKey { View = MyViewEnum.SrvView, Fmt = MyRender11Constants.DX11_BACKBUFFER_FORMAT };
if(m_backbufferCopyResource == null)
{
m_backbufferCopyResource = new MyCustomTexture(m_resolution.X, m_resolution.Y, BindFlags.ShaderResource, MyRender11Constants.DX11_BACKBUFFER_FORMAT);
m_backbufferCopyResource.AddView(viewKey);
}
MyRenderContext.Immediate.DeviceContext.CopyResource(imageSource.m_resource, m_backbufferCopyResource.m_resource);
imageSource = m_backbufferCopyResource;
imageSourceResourceView = m_backbufferCopyResource.GetView(viewKey);
}
if (imageSource == null)
return returnData;
if(imageSizeInBytes > int.MaxValue)
{
Debug.Fail("Image size too large to read!");
return returnData;
}
MyBindableResource imageResource = imageSource;
bool shouldResize = imageSourceResourceView != null;
if (shouldResize)
{
imageResource = m_lastScreenDataResource;
if (imageResource == null || (imageResource.GetSize().X != resolution.X || imageResource.GetSize().Y != resolution.Y))
{
if (m_lastScreenDataResource != null && (m_lastScreenDataResource != m_backbufferCopyResource && m_lastScreenDataResource != Backbuffer))
{
m_lastScreenDataResource.Release();
}
m_lastScreenDataResource = null;
imageResource = new MyRenderTarget(resolution.X, resolution.Y, MyRender11Constants.DX11_BACKBUFFER_FORMAT, 1, 0);
}
var RC = MyRenderContext.Immediate;
var deviceContext = RC.DeviceContext;
deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
deviceContext.Rasterizer.SetViewport(0, 0, resolution.X, resolution.Y);
deviceContext.PixelShader.Set(MyDebugRenderer.BlitTextureShader);
deviceContext.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, imageResource);
RC.BindSRV(0, imageSourceResourceView);
MyDebugRenderer.DrawQuad(0, 0, resolution.X, resolution.Y, MyScreenPass.QuadVS);
//MyCopyToRT.Run(imageResource, imageSourceResourceView, new MyViewport(resolution));
}
m_lastScreenDataResource = imageResource;
Stream dataStream = m_lastDataStream;
if (m_lastDataStream == null || m_lastDataStream.Length != dataSizeInBytes)
{
if (m_lastDataStream != null)
{
m_lastDataStream.Dispose();
m_lastDataStream = null;
}
dataStream = new DataStream((int)dataSizeInBytes, true, true);
dataStream.Seek(0, SeekOrigin.Begin);
}
m_lastDataStream = dataStream;
Resource.ToStream(MyRenderContext.Immediate.DeviceContext, imageResource.m_resource, ImageFileFormat.Bmp, dataStream);
if (!(dataStream.CanRead && dataStream.CanSeek))
{
Debug.Fail("Screen data stream does not support the necessary operations to get the data");
return returnData;
}
fixed (byte* dataPointer = screenData)
{
GetBmpDataFromStream(dataStream, dataPointer, imageSizeInBytes);
}
returnData = screenData;
//.........这里部分代码省略.........
示例3: BasicTexture1D
public BasicTexture1D(Vector2I size)
: this(size.Size())
{ }