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


C# SharpDX.LockRectangle方法代码示例

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


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

示例1: InternalDDSFromStream

        //loads the data from a stream in to a texture object.
        private static void InternalDDSFromStream(Stream stream, Device device, int streamOffset, bool loadMipMap, int offsetMipMaps, out SharpDX.Direct3D9.Texture texture)
        {
            stream.Position = 0;
            if (offsetMipMaps == 0)
            {
                texture = SharpDX.Direct3D9.Texture.FromStream(device, stream, 0, 0, 0, Usage.None, Format.Unknown, Pool.Default, Filter.None, Filter.None, 0);
            }
            else
            {
                texture = SharpDX.Direct3D9.Texture.FromStream(device, stream, 0, 0, 0, Usage.Dynamic, Format.Unknown, Pool.Default, Filter.None, Filter.None, 0);

                int width = MipMapSize(offsetMipMaps, texture.GetLevelDescription(0).Width);
                int height = MipMapSize(offsetMipMaps, texture.GetLevelDescription(0).Height);
                int maxLevels = Math.Min(MaxMipMapLevels(width), MaxMipMapLevels(height));
                int actualLevels = Math.Min(maxLevels, texture.LevelCount - offsetMipMaps);

                Format format = texture.GetLevelDescription(0).Format;
                Texture offsetedTexture = new Texture(device, width, height, actualLevels, Usage.Dynamic, format, Pool.Default);
                for (int i = offsetMipMaps, j = 0; j < actualLevels; i++, j++)
                {
                    int levelWidth = MipMapSize(j, width);
                    int levelHeight = MipMapSize(j, height);

                    SharpDX.DataStream ds;
                    texture.LockRectangle(i, LockFlags.ReadOnly, out ds);
                    texture.UnlockRectangle(i);

                    SharpDX.DataStream ds2;
                    offsetedTexture.LockRectangle(j, LockFlags.None, out ds2);
                    ds2.Position = 0;
                    ds2.Write(ds.DataPointer, 0, (int)MipMapSizeInBytes(levelWidth, levelHeight, format));
                    offsetedTexture.UnlockRectangle(j);
                }

                texture.Dispose();
                texture = offsetedTexture;
            }
        }
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:39,代码来源:MyDDSFile.cs

示例2: InternalDDSFromStream

        private static void InternalDDSFromStream(Stream stream, Device device, int streamOffset, bool loadMipMap, int offsetMipMaps, out SharpDX.Direct3D9.Texture texture)
        {
            var fileStream = stream as FileStream;
            byte[] data = fileStream != null ? null : SharpDX.Utilities.ReadStream(stream);

            int maxTextureDimension = MyRender.GraphicsDevice.Capabilities.MaxTextureWidth;
            if (IntPtr.Size == 4 || MyRender.GraphicsDevice.AvailableTextureMemory < 1024 * 1024 * 600)
            {
                maxTextureDimension = 2048;
            }

            ImageInformation imageInfo;
            if (fileStream != null)
            {
                //imageInfo = GetImageInfoFromFileW(fileStream.Name);
				imageInfo = (ImageInformation)GetImageInfoFromFileWMethodInfo.Invoke(null, new object[] { fileStream.Name });
            }
            else
            {
                imageInfo = ImageInformation.FromMemory(data);
            }
            var textureWidth = imageInfo.Width;
            var textureHeight = imageInfo.Height;

            textureWidth = Math.Max(1, textureWidth >> offsetMipMaps);
            textureHeight = Math.Max(1, textureHeight >> offsetMipMaps);
            int loadMipmapOffset = offsetMipMaps;
            while (textureWidth > maxTextureDimension || textureHeight > maxTextureDimension)
            {
                loadMipmapOffset++;
                textureWidth = Math.Max(1, textureWidth >> 1);
                textureHeight = Math.Max(1, textureHeight >> 1);
            }

            if (offsetMipMaps == 0 && loadMipmapOffset == 0)
            {
                if (fileStream != null)
                {
                    texture = SharpDX.Direct3D9.Texture.FromFile(device, fileStream.Name, 0, 0, 0, Usage.None, Format.Unknown, Pool.Default, Filter.None, Filter.Linear, 0);
                }
                else
                {
                    texture = SharpDX.Direct3D9.Texture.FromMemory(device, data, 0, 0, 0, Usage.None, Format.Unknown, Pool.Default, Filter.None, Filter.Linear, 0);
                }
            }
            else if (loadMipmapOffset > 0)
            {
                var skipFilter = (Filter)D3DXSkipDDSMipLevels((uint)loadMipmapOffset);

                if (fileStream != null)
                {
                    texture = SharpDX.Direct3D9.Texture.FromFile(device, fileStream.Name, 0, 0, 0, Usage.None, Format.Unknown, Pool.Default, Filter.None, skipFilter, 0);
                }
                else
                {
                    texture = SharpDX.Direct3D9.Texture.FromMemory(device, data, 0, 0, 0, Usage.None, Format.Unknown, Pool.Default, Filter.None, skipFilter, 0);
                }
            }
            else
            {
                if (fileStream != null)
                {
                    texture = SharpDX.Direct3D9.Texture.FromFile(device, fileStream.Name, 0, 0, 0, Usage.None, Format.Unknown, Pool.Default, Filter.None, Filter.None, 0);
                }
                else
                {
                    texture = SharpDX.Direct3D9.Texture.FromMemory(device, data, 0, 0, 0, Usage.None, Format.Unknown, Pool.Default, Filter.None, Filter.None, 0);
                }

                int width = MipMapSize(offsetMipMaps, texture.GetLevelDescription(0).Width);
                int height = MipMapSize(offsetMipMaps, texture.GetLevelDescription(0).Height);
                int maxLevels = Math.Min(MaxMipMapLevels(width), MaxMipMapLevels(height));
                int actualLevels = Math.Min(maxLevels, texture.LevelCount - offsetMipMaps);

                Format format = texture.GetLevelDescription(0).Format;
                Texture offsetedTexture = new Texture(device, width, height, actualLevels, Usage.Dynamic, format, Pool.Default);
                for (int i = offsetMipMaps, j = 0; j < actualLevels; i++, j++)
                {
                    int levelWidth = MipMapSize(j, width);
                    int levelHeight = MipMapSize(j, height);

                    SharpDX.DataStream ds;
                    texture.LockRectangle(i, LockFlags.ReadOnly, out ds);
                    texture.UnlockRectangle(i);

                    SharpDX.DataStream ds2;
                    offsetedTexture.LockRectangle(j, LockFlags.None, out ds2);
                    ds2.Position = 0;
                    ds2.Write(ds.DataPointer, 0, (int)MipMapSizeInBytes(levelWidth, levelHeight, format));
                    offsetedTexture.UnlockRectangle(j);
                }

                texture.Dispose();
                texture = offsetedTexture;
            }
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:96,代码来源:MyDDSFile.cs


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