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


C# PixelFormat.SizeInBytes方法代码示例

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


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

示例1: InitCountAndViewFormat

 private void InitCountAndViewFormat(out int count, ref PixelFormat viewFormat)
 {
     if (Description.StructureByteStride == 0)
     {
         // TODO: The way to calculate the count is not always correct depending on the ViewFlags...etc.
         if ((ViewFlags & BufferFlags.RawBuffer) != 0)
         {
             count = Description.SizeInBytes / sizeof(int);
         }
         else if ((ViewFlags & BufferFlags.ShaderResource) != 0)
         {
             count = Description.SizeInBytes / viewFormat.SizeInBytes();
         }
         else
         {
             count = 0;
         }
     }
     else
     {
         // For structured buffer
         count = Description.SizeInBytes / Description.StructureByteStride;
         viewFormat = PixelFormat.None;
     }
 }
开发者ID:Powerino73,项目名称:paradox,代码行数:25,代码来源:Buffer.Direct3D.cs

示例2: GetRenderTargetView

        /// <summary>
        /// Gets a <see cref="RenderTargetView" /> for a particular <see cref="PixelFormat" />.
        /// </summary>
        /// <param name="pixelFormat">The view format.</param>
        /// <param name="width">The width in pixels of the render target.</param>
        /// <returns>A <see cref="RenderTargetView" /> for the particular view format.</returns>
        /// <remarks>The buffer must have been declared with <see cref="Graphics.BufferFlags.RenderTarget" />.
        /// The RenderTargetView instance is kept by this buffer and will be disposed when this buffer is disposed.</remarks>
        internal RenderTargetView GetRenderTargetView(PixelFormat pixelFormat, int width)
        {
            RenderTargetView srv = null;
            if ((nativeDescription.BindFlags & BindFlags.RenderTarget) != 0)
            {
                var description = new RenderTargetViewDescription()
                {
                    Format = (SharpDX.DXGI.Format)pixelFormat,
                    Dimension = RenderTargetViewDimension.Buffer,
                    Buffer =
                    {
                        ElementWidth = pixelFormat.SizeInBytes() * width,
                        ElementOffset = 0
                    }
                };

                srv = new RenderTargetView(this.GraphicsDevice.NativeDevice, NativeBuffer, description);
            }
            return srv;
        }
开发者ID:Powerino73,项目名称:paradox,代码行数:28,代码来源:Buffer.Direct3D.cs

示例3: CreateDebugTexture

        private unsafe Texture CreateDebugTexture(GraphicsDevice device, byte[] data, int width, int height, int mipmaps, int arraySize, PixelFormat format, TextureFlags flags, GraphicsResourceUsage usage)
        {
            fixed (byte* pData = data)
            {
                var sizeInBytes = format.SizeInBytes();

                var offset = 0;
                var dataBoxes = new DataBox[arraySize * mipmaps];
                for (int array = 0; array < arraySize; array++)
                {
                    for (int mip = 0; mip < mipmaps; mip++)
                    {
                        var w = width >> mip;
                        var h = height >> mip;
                        var rowStride = w * sizeInBytes;
                        var sliceStride = rowStride * h;

                        dataBoxes[array * mipmaps + mip] = new DataBox((IntPtr)pData + offset, rowStride, sliceStride);

                        offset += sliceStride;
                    }
                }

                return Texture.New2D(device, width, height, mipmaps, format, dataBoxes, flags, arraySize, usage);
            }
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:26,代码来源:TestTexture.cs

示例4: CheckDebugTextureData

        private void CheckDebugTextureData(GraphicsContext graphicsContext, Texture debugTexture, int width, int height, int mipmaps, int arraySize,
            PixelFormat format, TextureFlags flags, GraphicsResourceUsage usage, Func<int, int, int, int, int, byte> dataComputer)
        {
            var pixelSize = format.SizeInBytes();

            for (int arraySlice = 0; arraySlice < arraySize; arraySlice++)
            {
                for (int mipSlice = 0; mipSlice < mipmaps; mipSlice++)
                {
                    var w = width >> mipSlice;
                    var h = height >> mipSlice;

                    var readData = debugTexture.GetData<byte>(graphicsContext.CommandList, arraySlice, mipSlice);

                    for (int r = 0; r < h; r++)
                    {
                        for (int c = 0; c < w; c++)
                        {
                            for (int i = 0; i < pixelSize; i++)
                            {
                                var value = readData[(r * w + c) * pixelSize + i];
                                var expectedValue = dataComputer(c, r, mipSlice, arraySlice, i);

                                if (!expectedValue.Equals(value))
                                    Assert.Fail("The texture data get at [{0}, {1}] for mipmap level '{2}' and slice '{3}' with flags '{4}', usage '{5}' and format '{6}' is not valid. " +
                                                "Expected '{7}' but was '{8}' at index '{9}'",
                                                c, r, mipSlice, arraySlice, flags, usage, format, expectedValue, value, i);
                            }
                        }
                    }
                }
            }
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:33,代码来源:TestTexture.cs

示例5: CreateDebugTextureData

        private byte[] CreateDebugTextureData(int width, int height, int mipmaps, int arraySize, PixelFormat format, Func<int, int, int, int, int, byte> dataComputer)
        {
            var formatSize = format.SizeInBytes();

            var mipmapSize = 0;
            for (int i = 0; i < mipmaps; i++)
                mipmapSize += (width >> i) * (height >> i);

            var dataSize = arraySize * mipmapSize;
            var data = new byte[dataSize * formatSize];
            {
                var offset = 0;
                for (int array = 0; array < arraySize; array++)
                {
                    for (int mip = 0; mip < mipmaps; mip++)
                    {
                        var w = width >> mip;
                        var h = height >> mip;

                        for (int r = 0; r < h; r++)
                        {
                            for (int c = 0; c < w; c++)
                            {
                                for (int i = 0; i < formatSize; i++)
                                {
                                    data[offset + (r * w + c) * formatSize + i] = dataComputer(c, r, mip, array, i);
                                }
                            }
                        }
                        offset += w * h * formatSize;
                    }
                }
            }

            return data;
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:36,代码来源:TestTexture.cs


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