当前位置: 首页>>代码示例>>C#>>正文


C# Texture2D.Unmap方法代码示例

本文整理汇总了C#中Texture2D.Unmap方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.Unmap方法的具体用法?C# Texture2D.Unmap怎么用?C# Texture2D.Unmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Texture2D的用法示例。


在下文中一共展示了Texture2D.Unmap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadBitmapInTexture

 private void LoadBitmapInTexture(Bitmap bitmap, Texture2D texture)
 {
   var rect = texture.Map(0, MapMode.WriteDiscard, MapFlags.None);
   if (rect.Data.CanWrite)
   {
     for (int j = 0; j < texture.Description.Height; j++)
     {
       int rowStart = j * rect.Pitch;
       rect.Data.Seek(rowStart, SeekOrigin.Begin);
       for (int i = 0; i < texture.Description.Width; i++)
       {
         var color = bitmap.GetPixel(i, j);
         rect.Data.WriteByte((byte)color.R);
         rect.Data.WriteByte((byte)color.G);
         rect.Data.WriteByte((byte)color.B);
         rect.Data.WriteByte((byte)color.A);
       }
     }
   }
   texture.Unmap(0);
 }
开发者ID:dgopena,项目名称:Starter3D.Base,代码行数:21,代码来源:Direct3DRenderer.cs

示例2: Make3D

        private static Texture2D Make3D(Texture2D stereoTexture)
        {
            NvStereoImageHeader header = new NvStereoImageHeader(0x4433564e, 3840, 1080, 4, 0x00000002);

            // stereoTexture contains a stereo image with the left eye image on the left half
            // and the right eye image on the right half
            // this staging texture will have an extra row to contain the stereo signature
            Texture2DDescription stagingDesc = new Texture2DDescription()
                                                   {
                                                       ArraySize = 1,
                                                       Width = 2*size.Width,
                                                       Height = size.Height + 1,
                                                       BindFlags = BindFlags.None,
                                                       CpuAccessFlags = CpuAccessFlags.Write,
                                                       Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                                                       OptionFlags = ResourceOptionFlags.None,
                                                       Usage = ResourceUsage.Staging,
                                                       MipLevels = 1,
                                                       SampleDescription = new SampleDescription(1, 0)
                                                   };
            Texture2D staging = new Texture2D(device, stagingDesc);

            // Identify the source texture region to copy (all of it)
            ResourceRegion stereoSrcBox = new ResourceRegion
                                              {Front = 0, Back = 1, Top = 0, Bottom = size.Height, Left = 0, Right = 2*size.Width};
            // Copy it to the staging texture
            device.CopySubresourceRegion(stereoTexture, 0, stereoSrcBox, staging, 0, 0, 0, 0);

            // Open the staging texture for reading
            DataRectangle box = staging.Map(0, MapMode.Write, SlimDX.Direct3D10.MapFlags.None);
            // Go to the last row
            //box.Data.Seek(stereoTexture.Description.Width*stereoTexture.Description.Height*4, System.IO.SeekOrigin.Begin);
            box.Data.Seek(box.Pitch*1080, System.IO.SeekOrigin.Begin);
            // Write the NVSTEREO header
            box.Data.Write(data, 0, data.Length);
            staging.Unmap(0);

            // Create the final stereoized texture
            Texture2DDescription finalDesc = new Texture2DDescription()
                                                 {
                                                     ArraySize = 1,
                                                     Width = 2 * size.Width,
                                                     Height = size.Height + 1,
                                                     BindFlags = BindFlags.ShaderResource,
                                                     CpuAccessFlags = CpuAccessFlags.Write,
                                                     Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                                                     OptionFlags = ResourceOptionFlags.None,
                                                     Usage = ResourceUsage.Dynamic,
                                                     MipLevels = 1,
                                                     SampleDescription = new SampleDescription(1, 0)
                                                 };

            // Copy the staging texture on a new texture to be used as a shader resource
            Texture2D final = new Texture2D(device, finalDesc);
            device.CopyResource(staging, final);
            staging.Dispose();
            return final;
        }
开发者ID:yong-ja,项目名称:starodyssey,代码行数:58,代码来源:Program.cs

示例3: ExtractRawBitmap

        public byte[] ExtractRawBitmap()
        {
            // use a cpu bound resource

            var textureDesc = new Texture2DDescription
            {
                MipLevels = 1,
                ArraySize = 1,
                BindFlags = BindFlags.None,
                CpuAccessFlags = CpuAccessFlags.Read,
                Format = Format.B8G8R8A8_UNorm,
                OptionFlags = ResourceOptionFlags.None,
                Width = _width,
                Height = _height,
                Usage = ResourceUsage.Staging,
                SampleDescription = new SampleDescription(1, 0)
            };

            using (var cpuTexture = new Texture2D(_device, textureDesc))
            {
            #if NETFX_CORE
                _device.ImmediateContext.CopyResource(_texture, cpuTexture);
            #else
                _device.CopyResource(_texture, cpuTexture);
            #endif
                var bytesPerLine = _width * 4;
                var res = new byte[bytesPerLine * _height];
            #if NETFX_CORE
                var data = _device.ImmediateContext.MapSubresource(cpuTexture, 0, MapMode.Read, MapFlags.None);
            #else
                var data = cpuTexture.Map(0, MapMode.Read, MapFlags.None);
            #endif
                try
                {
                    IntPtr sourcePtr = data.DataPointer;
                    int targetOffset = 0;
                    for (int i = 0; i != _height; ++i)
                    {
                        Marshal.Copy(sourcePtr, res, targetOffset, bytesPerLine);
            #if NETFX_CORE
                        sourcePtr += data.RowPitch;
            #else
                        sourcePtr += data.Pitch;
            #endif
                        targetOffset += bytesPerLine;
                    }

                    return res;
                }
                finally
                {
            #if NETFX_CORE
                    _device.ImmediateContext.UnmapSubresource(cpuTexture, 0);
            #else
                    cpuTexture.Unmap(0);
            #endif
                }
            }
        }
开发者ID:pragmatrix,项目名称:CrossUI,代码行数:59,代码来源:DrawingSurface.cs


注:本文中的Texture2D.Unmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。