protected IndexBuffer( GraphicsDevice graphicsDevice, IndexElementType elementType, int capacity, BufferUsage bufferUsage, bool isDynamic) : base(graphicsDevice, capacity, bufferUsage, isDynamic) { if (elementType == IndexElementType.Int32) { if (graphicsDevice.GraphicsProfile == GraphicsProfile.Reach) { throw new NotSupportedException( $"The current graphics profile does not support an element type of " + $"{elementType}; use {IndexElementType.Int16} instead."); } } else if (elementType != IndexElementType.Int16) { throw new ArgumentOutOfRangeException(nameof(elementType)); } ElementType = elementType; if (IsValidThreadContext) { PlatformConstruct(); } else { Threading.BlockOnMainThread(PlatformConstruct); } }
protected VertexBuffer( GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int capacity, BufferUsage bufferUsage, bool isDynamic) : base(graphicsDevice, capacity, bufferUsage, isDynamic) { // Make sure the graphics device is assigned in the vertex declaration. if (vertexDeclaration.GraphicsDevice != graphicsDevice) { vertexDeclaration.GraphicsDevice = graphicsDevice; } VertexDeclaration = vertexDeclaration; if (IsValidThreadContext) { PlatformConstruct(); } else { Threading.BlockOnMainThread(PlatformConstruct); } }
protected Texture2D( GraphicsDevice graphicsDevice, int width, int height, bool mipmap, SurfaceFormat format, SurfaceType type, bool shared, int arraySize) : base(graphicsDevice) { if (arraySize > 1 && !graphicsDevice.Capabilities.SupportsTextureArrays) { throw new ArgumentException( "Texture arrays are not supported on this graphics device", nameof(arraySize)); } int maxTexSize = GraphicsDevice.Capabilities.MaxTexture2DSize; ArgumentGuard.AssertGreaterThanZero(width, nameof(width)); if (width > maxTexSize) { throw new ArgumentOutOfRangeException( nameof(width), "The width exceeds device capability."); } ArgumentGuard.AssertGreaterThanZero(height, nameof(height)); if (height > maxTexSize) { throw new ArgumentOutOfRangeException( nameof(height), "The height exceeds device capability."); } GraphicsDevice = graphicsDevice; Bounds = new Rectangle(0, 0, width, height); Format = format; LevelCount = mipmap ? CalculateMipLevels(width, height) : 1; ArraySize = arraySize; // Texture will be assigned by the swap chain. if (type == SurfaceType.SwapChainRenderTarget) { return; } void Construct() => PlatformConstruct(width, height, mipmap, format, type, shared); if (IsValidThreadContext) { Construct(); } else { Threading.BlockOnMainThread(Construct); } }
/// <summary> /// Changes the pixels of the texture. /// </summary> /// <typeparam name="T">The pixel type.</typeparam> /// <param name="data">New data for the texture.</param> /// <param name="rectangle">Area to modify; defaults to texture bounds.</param> /// <param name="level">Layer of the texture to modify.</param> /// <param name="arraySlice">Index inside the texture array.</param> /// <exception cref="ArgumentException"> /// <paramref name="arraySlice"/> is greater than 0 and the graphics device does not support texture arrays. /// </exception> public void SetData <T>( ReadOnlyMemory <T> data, Rectangle?rectangle = null, int level = 0, int arraySlice = 0) where T : unmanaged { if (rectangle.HasValue) { if (rectangle.Value.Width == 0 || rectangle.Value.Height == 0) { return; } } ValidateParams <T>(level, arraySlice, rectangle, data.Length, out Rectangle checkedRect); void SetData() { if (rectangle.HasValue) { PlatformSetData(level, arraySlice, checkedRect, data.Span); } else { PlatformSetData(level, arraySlice, rect: null, data.Span); } } if (IsValidThreadContext) { SetData(); } else { Threading.BlockOnMainThread(SetData); } }
internal TextureCube( GraphicsDevice graphicsDevice, int size, bool mipMap, SurfaceFormat format, bool renderTarget) : base(graphicsDevice) { if (size <= 0) { throw new ArgumentOutOfRangeException(nameof(size), "Cube size must be greater than zero"); } Size = size; Format = format; LevelCount = mipMap ? CalculateMipLevels(size) : 1; void Construct() => PlatformConstruct(graphicsDevice, size, mipMap, format, renderTarget); if (IsValidThreadContext) { Construct(); } else { Threading.BlockOnMainThread(Construct); } }