public Texture(RenderContext context, int width, int height, byte[] data, TextureSampleType sampleType) { uint w = (uint)width, h = (uint)height; uint numMips = 4; if (w < 16 || h < 16) { numMips = 1; } var device = context.Device; _texture = device.ResourceFactory.CreateTexture(TextureDescription.Texture2D( w, h, numMips, 1, PixelFormat.B8_G8_R8_A8_UNorm, TextureUsage.Sampled | TextureUsage.GenerateMipmaps )); try { device.UpdateTexture(_texture, data, 0, 0, 0, w, h, _texture.Depth, 0, 0); } catch { // Error updating texture, the texture may have been disposed } _mipsGenerated = false; var sampler = context.ResourceLoader.TextureSampler; if (sampleType == TextureSampleType.Point) { sampler = context.ResourceLoader.OverlaySampler; } _view = device.ResourceFactory.CreateTextureView(_texture); _set = device.ResourceFactory.CreateResourceSet(new ResourceSetDescription( context.ResourceLoader.TextureLayout, _view, sampler )); }
internal Texture UploadTexture(string name, int width, int height, byte[] data, TextureSampleType sampleType) { return(_textures.GetOrAdd(name, n => new Texture(_context, width, height, data, sampleType))); }