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


C# Direct3D11.Texture2D类代码示例

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


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

示例1: Player

 public Player(Texture2D aTexture, Vector2 aLocation, Rectangle aGameBoundaries)
 {
     this._texture = aTexture;
     this.Location = aLocation;
     this.Velocity = Vector2.Zero;
     this.gameBoundaries = aGameBoundaries;
 }
开发者ID:SeanDunford,项目名称:Reduce-Reuse-Recycle,代码行数:7,代码来源:Player.cs

示例2: MyTextureArray

        internal MyTextureArray(TexId[] mergeList)
        {
            var srcDesc = MyTextures.GetView(mergeList[0]).Description;
            Size = MyTextures.GetSize(mergeList[0]);
            ArrayLen = mergeList.Length;

            Texture2DDescription desc = new Texture2DDescription();
            desc.ArraySize = ArrayLen;
            desc.BindFlags = BindFlags.ShaderResource;
            desc.CpuAccessFlags = CpuAccessFlags.None;
            desc.Format = srcDesc.Format;
            desc.Height = (int)Size.Y;
            desc.Width = (int)Size.X;
            desc.MipLevels = 0;
            desc.SampleDescription.Count = 1;
            desc.SampleDescription.Quality = 0;
            desc.Usage = ResourceUsage.Default;
            m_resource = new Texture2D(MyRender11.Device, desc);

            // foreach mip
            var mipmaps = (int)Math.Log(Size.X, 2) + 1;

            for (int a = 0; a < ArrayLen; a++)
            {
                for (int m = 0; m < mipmaps; m++)
                {
                    MyRender11.Context.CopySubresourceRegion(MyTextures.Textures.Data[mergeList[a].Index].Resource, Resource.CalculateSubResourceIndex(m, 0, mipmaps), null, Resource,
                        Resource.CalculateSubResourceIndex(m, a, mipmaps));
                }
            }

            ShaderView = new ShaderResourceView(MyRender11.Device, Resource);
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:33,代码来源:MyResource.cs

示例3: GraphicsResource

        /// <summary>
        /// Creates a new graphics resource.
        /// </summary>
        /// <param name="device">The graphics device to use.</param>
        /// <param name="dimensions">The resource dimensions.</param>
        /// <param name="format">The resource's DXGI format.</param>
        /// <param name="renderTargetView">Whether to bind as RTV.</param>
        /// <param name="shaderResourceView">Whether to bind as SRV.</param>
        /// <param name="hasMipMaps">Whether to enable mip-maps for this texture.</param>
        public GraphicsResource(Device device, Size dimensions, Format format, Boolean renderTargetView = true, Boolean shaderResourceView = true, Boolean hasMipMaps = false)
        {
            if ((!renderTargetView) && (!shaderResourceView))
                throw new ArgumentException("The requested resource cannot be bound at all to the pipeline.");

            if ((hasMipMaps) && ((!renderTargetView) || (!shaderResourceView)))
                throw new ArgumentException("A resource with mipmaps must be bound as both input and output.");

            BindFlags bindFlags = (renderTargetView ? BindFlags.RenderTarget : 0) | (shaderResourceView ? BindFlags.ShaderResource : 0);
            ResourceOptionFlags optionFlags = (hasMipMaps ? ResourceOptionFlags.GenerateMipMaps : 0);
            int mipLevels = (hasMipMaps ? MipLevels(dimensions) : 1);

            Resource = new Texture2D(device, new Texture2DDescription()
            {
                Format = format,
                BindFlags = bindFlags,
                Width = dimensions.Width,
                Height = dimensions.Height,

                ArraySize = 1,
                MipLevels = mipLevels,
                OptionFlags = optionFlags,
                Usage = ResourceUsage.Default,
                CpuAccessFlags = CpuAccessFlags.None,
                SampleDescription = new SampleDescription(1, 0),
            });

            RTV = (  renderTargetView ?   new RenderTargetView(device, Resource) : null);
            SRV = (shaderResourceView ? new ShaderResourceView(device, Resource) : null);
        }
开发者ID:TomCrypto,项目名称:Insight,代码行数:39,代码来源:GraphicsResource.cs

示例4: DepthBuffer

        public DepthBuffer(Dx11ChainedDevice device, int width, int height)
        {
            try
            {
                _device = device;
                _depthBuffer = new Texture2D(_device.Device, new Texture2DDescription
                {
                    Format = Format.D32_Float_S8X24_UInt,
                    ArraySize = 1,
                    MipLevels = 1,
                    Width = width,
                    Height = height,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage = ResourceUsage.Default,
                    BindFlags = BindFlags.DepthStencil,
                    CpuAccessFlags = CpuAccessFlags.None,
                    OptionFlags = ResourceOptionFlags.None
                });

                _depthView = new DepthStencilView(device.Device, _depthBuffer);
            }
            catch
            {
                Dispose();
                throw;
            }
        }
开发者ID:truongan012,项目名称:Pulse,代码行数:27,代码来源:DepthBuffer.cs

示例5: OnResize

        void OnResize(object sender, EventArgs args)
        {
            var texDesc = new Texture2DDescription
            {
                ArraySize = 1, BindFlags = BindFlags.None,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                Height = ClientSize.Height,
                Width = ClientSize.Width,
                Usage = ResourceUsage.Default,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                OptionFlags = ResourceOptionFlags.None,
                MipLevels = 1
            };

            if (mResolveTexture != null)
                mResolveTexture.Dispose();

            mResolveTexture = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc);

            if (mMapTexture != null) mMapTexture.Dispose();

            texDesc.CpuAccessFlags = CpuAccessFlags.Read;
            texDesc.Usage = ResourceUsage.Staging;
            mMapTexture = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc);

            mTarget.Resize(ClientSize.Width, ClientSize.Height, true);
            mCamera.SetAspect((float) ClientSize.Width / ClientSize.Height);
        }
开发者ID:Linrasis,项目名称:WoWEditor,代码行数:29,代码来源:ModelRenderControl.cs

示例6: RenderTexture

        public RenderTexture(Device device, Vector2I screenSize)
        {
            var textureDesc = new Texture2DDescription()
            {
                Width = screenSize.X,
                Height = screenSize.Y,
                MipLevels = 1,
                ArraySize = 1,
                Format = Format.R32G32B32A32_Float,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None
            };

            _renderTargetTexture = new Texture2D(device, textureDesc);

            _renderTargetView = new RenderTargetView(device, _renderTargetTexture,
                new RenderTargetViewDescription
                {
                    Format = textureDesc.Format,
                    Dimension = RenderTargetViewDimension.Texture2D,
                    Texture2D = {MipSlice = 0},
                });

            // Create the render target view.
            ShaderResourceView = new ShaderResourceView(device, _renderTargetTexture,
                new ShaderResourceViewDescription
                {
                    Format = textureDesc.Format,
                    Dimension = ShaderResourceViewDimension.Texture2D,
                    Texture2D = { MipLevels = 1, MostDetailedMip = 0 },
                });
        }
开发者ID:ndech,项目名称:PlaneSimulator,代码行数:35,代码来源:RenderTexture.cs

示例7: TextureCubeArray

		/// <summary>
		/// 
		/// </summary>
		/// <param name="device"></param>
		/// <param name="size"></param>
		/// <param name="count"></param>
		/// <param name="format"></param>
		/// <param name="mips"></param>
		public TextureCubeArray ( GraphicsDevice device, int size, int count, ColorFormat format, bool mips ) : base(device)
		{
			if (count>2048/6) {
				throw new GraphicsException("Too much elements in texture array");
			}

			this.Width		=	size;
			this.Depth		=	1;
			this.Height		=	size;
			this.MipCount	=	mips ? ShaderResource.CalculateMipLevels(Width,Height) : 1;

			var texDesc = new Texture2DDescription();

			texDesc.ArraySize		=	6 * count;
			texDesc.BindFlags		=	BindFlags.ShaderResource;
			texDesc.CpuAccessFlags	=	CpuAccessFlags.None;
			texDesc.Format			=	MakeTypeless( Converter.Convert( format ) );
			texDesc.Height			=	Height;
			texDesc.MipLevels		=	0;
			texDesc.OptionFlags		=	ResourceOptionFlags.TextureCube;
			texDesc.SampleDescription.Count	=	1;
			texDesc.SampleDescription.Quality	=	0;
			texDesc.Usage			=	ResourceUsage.Default;
			texDesc.Width			=	Width;


			texCubeArray	=	new D3D.Texture2D( device.Device, texDesc );
			SRV				=	new ShaderResourceView( device.Device, texCubeArray );
		}
开发者ID:demiurghg,项目名称:FusionEngine,代码行数:37,代码来源:TextureCubeArray.cs

示例8: Copy

        /// <summary>
        /// Copies the content of the specified texture.
        /// </summary>
        /// <param name="device">The Direct3D 11 device.</param>
        /// <param name="source">The source texture.</param>
        /// <param name="target">The target texture.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="device"/>, <paramref name="source"/> or <paramref name="target"/> is
        /// <see langword="null"/>.
        /// </exception>
        public static void Copy(Device device, Texture2D source, Texture2D target)
        {
            if (device == null)
            throw new ArgumentNullException("device");
              if (source == null)
            throw new ArgumentNullException("source");
              if (target == null)
            throw new ArgumentNullException("target");

              int sourceWidth = source.Description.Width;
              int sourceHeight = source.Description.Height;
              int targetWidth = target.Description.Width;
              int targetHeight = target.Description.Height;

              if (sourceWidth == targetWidth && sourceHeight == targetHeight)
              {
            device.ImmediateContext.CopyResource(source, target);
              }
              else
              {
            int width = Math.Min(sourceWidth, targetWidth);
            int height = Math.Min(sourceHeight, targetHeight);
            var region = new ResourceRegion(0, 0, 0, width, height, 1);
            device.ImmediateContext.CopySubresourceRegion(source, 0, region, target, 0);
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:36,代码来源:D3D11Helper.cs

示例9: InitializeInternal

        protected override void InitializeInternal()
        {
            var sourceTextures = _textures.Select(t =>
            {
                var view = t.ShaderResourceView;
                if(view == null)
                    throw new InvalidOperationException(string.Format("Texture array cannot be created because source texture '{0}' is not initialized", t.Id));
                return view.Resource.QueryInterface<Texture2D>();
            }).ToArray();

            var descr = sourceTextures[0].Description;
            descr.ArraySize = _textures.Length;
            _textureArray = new Texture2D(DeviceManager.Device, descr);
            ShaderResourceView = new ShaderResourceView(DeviceManager.Device, _textureArray);

            var mipLevels = descr.MipLevels;
            for(var i = 0; i < mipLevels; i++)
            {
                for(var j = 0; j < _textures.Length; j++)
                {
                    var texture = sourceTextures[j];
                    DeviceManager.Context.CopySubresourceRegion(texture, i, null, _textureArray, mipLevels * j + i);
                }
            }
        }
开发者ID:gitter-badger,项目名称:Grasshopper,代码行数:25,代码来源:TextureArrayResource.cs

示例10: RemoveTexture

 public void RemoveTexture(Texture2D texture)
 {
     if (m_textureMap.ContainsKey(texture))
     {
         m_textureMap.Remove(texture);
     }
 }
开发者ID:rolandsmeenk,项目名称:ModernApps,代码行数:7,代码来源:DxRenderer.SpriteBatch.cs

示例11: PlatformConstruct

        private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap,
            SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
        {
            // Setup the multisampling description.
            var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0);
            if (preferredMultiSampleCount > 1)
            {
                multisampleDesc.Count = preferredMultiSampleCount;
                multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern;
            }

            // Create a descriptor for the depth/stencil buffer.
            // Allocate a 2-D surface as the depth/stencil buffer.
            // Create a DepthStencil view on this surface to use on bind.
            using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription
            {
                Format = SharpDXHelper.ToFormat(preferredDepthFormat),
                ArraySize = 1,
                MipLevels = 1,
                Width = width,
                Height = height,
                SampleDescription = multisampleDesc,
                BindFlags = BindFlags.DepthStencil,
            }))
            {
                // Create the view for binding to the device.
                _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription()
                {
                    Format = SharpDXHelper.ToFormat(preferredDepthFormat),
                    Dimension = DepthStencilViewDimension.Texture2D
                });
            }
        }
开发者ID:KennethYap,项目名称:MonoGame,代码行数:33,代码来源:RenderTarget3D.DirectX.cs

示例12: DynamicColorRGBATexture

        /// <summary>
        /// Creates a dynamic color texture, allocates GPU resources
        /// </summary>
        /// <param name="device">Direct3D Device</param>
        public DynamicColorRGBATexture(Device device)
        {
            if (device == null)
                throw new ArgumentNullException("device");

            this.texture = new Texture2D(device, ColorTextureDescriptors.DynamicRGBAResource);
            this.rawView = new ShaderResourceView(device,this.texture);
        }
开发者ID:semihguresci,项目名称:kgp,代码行数:12,代码来源:DynamicColorRGBATexture.cs

示例13: DynamicDepthToColorTexture

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="device">Direct3D11 Device</param>
        public DynamicDepthToColorTexture(Device device)
        {
            if (device == null)
                throw new ArgumentNullException("device");

            this.texture = new Texture2D(device, CoordinateMapTextureDescriptors.DynamicDepthToColor);
            this.shaderView = new ShaderResourceView(device, this.texture);
        }
开发者ID:semihguresci,项目名称:kgp,代码行数:12,代码来源:DynamicDepthtoColorTexture.cs

示例14: DynamicLongExposureInfraredTexture

        /// <summary>
        /// Creates a dynamic depth texture, allocates GPU resources
        /// </summary>
        /// <param name="device">Direct3D Device</param>
        public DynamicLongExposureInfraredTexture(Device device)
        {
            if (device == null)
                throw new ArgumentNullException("device");

            this.texture = new Texture2D(device, InfraredTextureDescriptors.DynamicResource);
            this.shaderView = new ShaderResourceView(device, this.texture);
        }
开发者ID:semihguresci,项目名称:kgp,代码行数:12,代码来源:DynamicLongExposureInfraredTexture.cs

示例15: DepthStencilCube

        /// <summary>
        /// Creates render target
        /// </summary>
        /// <param name="rs"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="format"></param>
        public DepthStencilCube( GraphicsDevice device, DepthFormat format, int size, int samples, string debugName = "" )
            : base(device)
        {
            bool msaa	=	samples > 1;

            CheckSamplesCount( samples );

            SampleCount	=	samples;

            Format		=	format;
            SampleCount	=	samples;
            Width		=	size;
            Height		=	size;
            Depth		=	1;

            var	texDesc	=	new Texture2DDescription();
                texDesc.Width				=	Width;
                texDesc.Height				=	Height;
                texDesc.ArraySize			=	6;
                texDesc.BindFlags			=	BindFlags.RenderTarget | BindFlags.ShaderResource;
                texDesc.CpuAccessFlags		=	CpuAccessFlags.None;
                texDesc.Format				=	Converter.ConvertToTex( format );
                texDesc.MipLevels			=	1;
                texDesc.OptionFlags			=	ResourceOptionFlags.TextureCube;
                texDesc.SampleDescription	=	new DXGI.SampleDescription(samples, 0);
                texDesc.Usage				=	ResourceUsage.Default;

            texCube	=	new D3D.Texture2D( device.Device, texDesc );

            var srvDesc	=	new ShaderResourceViewDescription();
                srvDesc.Dimension			=	samples > 1 ? ShaderResourceViewDimension.Texture2DMultisampled : ShaderResourceViewDimension.Texture2D;
                srvDesc.Format				=	Converter.ConvertToSRV( format );
                srvDesc.Texture2D.MostDetailedMip	=	0;
                srvDesc.Texture2D.MipLevels			=	1;

            SRV		=	new ShaderResourceView( device.Device, texCube );

            //
            //	Create surfaces :
            //
            surfaces	=	new DepthStencilSurface[ 6 ];

            for ( int face=0; face<6; face++) {

                var rtvDesc = new DepthStencilViewDescription();
                    rtvDesc.Texture2DArray.MipSlice			=	0;
                    rtvDesc.Texture2DArray.FirstArraySlice	=	face;
                    rtvDesc.Texture2DArray.ArraySize		=	1;
                    rtvDesc.Dimension						=	msaa ? DepthStencilViewDimension.Texture2DMultisampledArray : DepthStencilViewDimension.Texture2DArray;
                    rtvDesc.Format							=	Converter.ConvertToDSV( format );

                var dsv	=	new DepthStencilView( device.Device, texCube, rtvDesc );

                int subResId	=	Resource.CalculateSubResourceIndex( 0, face, 1 );

                surfaces[face]	=	new DepthStencilSurface( dsv, format, Width, Height, SampleCount );
            }
        }
开发者ID:temik911,项目名称:audio,代码行数:65,代码来源:DepthStencilCube.cs


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