/// <summary> /// Loads a texture from a stream. /// </summary> /// <param name="device">The <see cref="GraphicsDevice" />.</param> /// <param name="image">The image.</param> /// <param name="textureFlags">True to load the texture with unordered access enabled. Default is false.</param> /// <param name="usage">Usage of the resource. Default is <see cref="GraphicsResourceUsage.Immutable" /></param> /// <returns>A texture</returns> /// <exception cref="System.InvalidOperationException">Dimension not supported</exception> public static Texture New(GraphicsDevice device, Image image, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) { if (device == null) { throw new ArgumentNullException("device"); } if (image == null) { throw new ArgumentNullException("image"); } switch (image.Description.Dimension) { case TextureDimension.Texture1D: return(Texture1D.New(device, image, textureFlags, usage)); case TextureDimension.Texture2D: return(Texture2D.New(device, image, textureFlags, usage)); case TextureDimension.Texture3D: return(Texture3D.New(device, image, textureFlags, usage)); case TextureDimension.TextureCube: return(TextureCube.New(device, image, textureFlags, usage)); } throw new InvalidOperationException("Dimension not supported"); }
/// <summary> /// Creates the depth stencil buffer. /// </summary> protected virtual void CreateDepthStencilBuffer() { // If no depth stencil buffer, just return if (Description.DepthStencilFormat == PixelFormat.None) { return; } // Creates the depth stencil buffer. var depthTexture = Texture2D.New(GraphicsDevice, Description.BackBufferWidth, Description.BackBufferHeight, Description.DepthStencilFormat, TextureFlags.DepthStencil | TextureFlags.ShaderResource).KeepAliveBy(this); DepthStencilBuffer = depthTexture.ToDepthStencilBuffer(false).KeepAliveBy(this); }
/// <summary> /// Creates a new instance of <see cref="UIBatch"/>. /// </summary> /// <param name="device">A valid instance of <see cref="GraphicsDevice"/>.</param> public UIBatch(GraphicsDevice device) : base(device, UIEffect.Bytecode, ResourceBufferInfo.CreateDynamicIndexBufferInfo("UIBatch.VertexIndexBuffers", MaxIndicesCount, MaxVerticesCount), VertexPositionColorTextureSwizzle.Layout) { // Create the two ui effects uiSeparateAlphaEffect = new Effect(GraphicsDevice, UIEffectSeparateAlpha.Bytecode) { Name = "SeparatedAlphaBatchEffect" }; // Create a 1x1 pixel white texture whiteTexture = Texture2D.New(GraphicsDevice, 1, 1, PixelFormat.R8G8B8A8_UNorm, new Byte[] { 255, 255, 255, 255 }); }