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


C# Texture.SetData方法代码示例

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


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

示例1: Import

        public override Asset Import(string path)
        {
            Texture texture = new Texture();
            texture.FileName = path;

            if (string.Compare(Path.GetExtension(path), ".tdx", true) == 0)
            {
                TDX tdx = TDX.Load(path);
                texture.SetData(tdx.Name, tdx.Format.ToString(), tdx.MipMaps[0].Width, tdx.MipMaps[0].Height, tdx.MipMaps[0].Data);
                texture.SupportingDocuments["Source"] = tdx;
            }
            else
            {
                texture = (Texture)(new IMGImporter()).Import(path);
            }

            return texture;
        }
开发者ID:DevilboxGames,项目名称:Flummery,代码行数:18,代码来源:TDXImporter.cs

示例2: CheckTexture

        private void CheckTexture(GraphicsContext graphicsContext, Texture texture, byte[] data)
        {
            // Get back the data from the gpu
            var data2 = texture.GetData<byte>(graphicsContext.CommandList);

            // Assert that data are the same
            Assert.That(Utilities.Compare(data, data2), Is.True);

            // Sets new data on the gpu
            data[0] = 1;
            data[31] = 255;
            texture.SetData(graphicsContext.CommandList, data);

            // Get back the data from the gpu
            data2 = texture.GetData<byte>(graphicsContext.CommandList);

            // Assert that data are the same
            Assert.That(Utilities.Compare(data, data2), Is.True);
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:19,代码来源:TestTexture.cs

示例3: LoadNewHeightMap

        public void LoadNewHeightMap(float[,] heightmap, float heightmapPixelPerWorldUnit, GraphicsDevice graphicsDevice)
        {
            this.heightmapPixelPerWorldUnit = heightmapPixelPerWorldUnit;

            // remove old textures
            terrainShader.Effect.Parameters["Heightmap"].SetResource<ShaderResourceViewSelector>((ShaderResourceViewSelector)null);
            if (heightmapTexture != null)
                heightmapTexture.Dispose();
            #if CONEMAPPING_RAYMARCH

            computeRelaxedConeShader.Effect.Parameters["HeightInput"].SetResource<ShaderResourceViewSelector>((ShaderResourceViewSelector)null);
            computeRelaxedConeShader.Effect.Parameters["ConesOutput"].SetResource<ShaderResourceViewSelector>((ShaderResourceViewSelector)null);
            computeRelaxedConeShader.Effect.Parameters["CombinedOutput"].SetResource<ShaderResourceViewSelector>((ShaderResourceViewSelector)null);
            if (tempSingleChannelHeightmap != null)
                tempSingleChannelHeightmap.Dispose();
            if (tempSingleChannelCones != null)
                tempSingleChannelCones.Dispose();

            // generate jobs
            conemapProcessingWorkItems.Clear();
            const int TILE_SIZE = 32;   // if you change this value, you also have to change " AreaPerCall in computerelaxedconemap.fx
            for (int x = 0; x < heightmap.GetLength(0); x += TILE_SIZE)
            {
                for (int y = 0; y < heightmap.GetLength(1); y += TILE_SIZE)
                    conemapProcessingWorkItems.Push(new Vector2(x, y));
            }

            // create temp-textures
            tempSingleChannelHeightmap = Texture2D.New(GraphicsDevice, heightmap.GetLength(0), heightmap.GetLength(1), 0, PixelFormat.R32.Float, TextureFlags.ShaderResource);
            tempSingleChannelHeightmap.SetData<float>(heightmap.Cast<float>().ToArray());
            tempSingleChannelCones = Texture2D.New(GraphicsDevice, heightmap.GetLength(0), heightmap.GetLength(1), 0, PixelFormat.R32.Float, TextureFlags.ShaderResource | TextureFlags.UnorderedAccess);
            GraphicsDevice.Clear(tempSingleChannelCones, new Color4(2.0f));

            // compose to heightmap texture
            heightmapTexture = Texture2D.New(GraphicsDevice, heightmap.GetLength(0), heightmap.GetLength(1), 0, PixelFormat.R16G16.Float, TextureFlags.ShaderResource | TextureFlags.UnorderedAccess);
            CombineTempMapsToCombined();
            #else
            // Create new heightmap.
            heightmapTexture = RenderTarget2D.New(graphicsDevice, heightmap.GetLength(0), heightmap.GetLength(1), MipMapCount.Auto, PixelFormat.R32.Float,
                                                                TextureFlags.RenderTarget | TextureFlags.ShaderResource);
            unsafe
            {
                fixed (float* p = heightmap)
                {
                    heightmapTexture.SetData(new DataPointer(p, heightmap.GetLength(0) * heightmap.GetLength(1) * sizeof(float)), 0, 0);
                }
            }

            GenerateMaxMap((RenderTarget2D)heightmapTexture, graphicsDevice);
            #endif

            Translation = new Vector3(-heightmapTexture.Width * 0.5f / heightmapPixelPerWorldUnit, 0, -heightmapTexture.Height * 0.5f / heightmapPixelPerWorldUnit);

            // setup heightmap cbuffer
            SetupTerrainConstants(graphicsDevice);
        }
开发者ID:Wumpf,项目名称:mstbasedheightmapgen,代码行数:56,代码来源:TerrainRaymarcher.cs

示例4: load

        private void load(OsuConfigManager config)
        {
            snakingIn = config.GetBindable<bool>(OsuConfig.SnakingInSliders);
            snakingOut = config.GetBindable<bool>(OsuConfig.SnakingOutSliders);

            int textureWidth = (int)PathWidth * 2;

            //initialise background
            var upload = new TextureUpload(textureWidth * 4);
            var bytes = upload.Data;

            const float aa_portion = 0.02f;
            const float border_portion = 0.18f;
            const float gradient_portion = 1 - border_portion;

            const float opacity_at_centre = 0.3f;
            const float opacity_at_edge = 0.8f;

            for (int i = 0; i < textureWidth; i++)
            {
                float progress = (float)i / (textureWidth - 1);

                if (progress <= border_portion)
                {
                    bytes[i * 4] = 255;
                    bytes[i * 4 + 1] = 255;
                    bytes[i * 4 + 2] = 255;
                    bytes[i * 4 + 3] = (byte)(Math.Min(progress / aa_portion, 1) * 255);
                }
                else
                {
                    progress -= border_portion;

                    bytes[i * 4] = (byte)(slider.Colour.R * 255);
                    bytes[i * 4 + 1] = (byte)(slider.Colour.G * 255);
                    bytes[i * 4 + 2] = (byte)(slider.Colour.B * 255);
                    bytes[i * 4 + 3] = (byte)((opacity_at_edge - (opacity_at_edge - opacity_at_centre) * progress / gradient_portion) * (slider.Colour.A * 255));
                }
            }

            var texture = new Texture(textureWidth, 1);
            texture.SetData(upload);
            path.Texture = texture;
        }
开发者ID:yheno,项目名称:osu,代码行数:44,代码来源:SliderBody.cs


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