public static SamplerState New(GraphicsDevice graphicsDevice, SamplerStateDescription samplerStateDescription) { // Store SamplerState in a cache (D3D seems to have quite bad concurrency when using CreateSampler while rendering) SamplerState samplerState; lock (graphicsDevice.CachedSamplerStates) { if (graphicsDevice.CachedSamplerStates.TryGetValue(samplerStateDescription, out samplerState)) { // TODO: Appropriate destroy samplerState.AddReferenceInternal(); } else { samplerState = new SamplerState(graphicsDevice, samplerStateDescription); graphicsDevice.CachedSamplerStates.Add(samplerStateDescription, samplerState); } } return(samplerState); }
/// <summary> /// Initializes a new instance of the <see cref="SamplerState"/> class. /// </summary> /// <param name="device">The device.</param> /// <param name="name">The name.</param> /// <param name="samplerStateDescription">The sampler state description.</param> private SamplerState(GraphicsDevice device, SamplerStateDescription samplerStateDescription) : base(device) { Description = samplerStateDescription; CreateNativeSampler(); }
private SamplerState(GraphicsDevice graphicsDevice, SamplerStateDescription samplerStateDescription) { throw new NotImplementedException(); }
private SamplerState(GraphicsDevice device, SamplerStateDescription samplerStateDescription) : base(device) { Description = samplerStateDescription; textureWrapS = samplerStateDescription.AddressU.ToOpenGL(); textureWrapT = samplerStateDescription.AddressV.ToOpenGL(); textureWrapR = samplerStateDescription.AddressW.ToOpenGL(); compareMode = TextureCompareMode.None; // ComparisonPoint can act as a mask for Comparison filters (0x80) if ((samplerStateDescription.Filter & ComparisonMask) != 0) { compareMode = TextureCompareMode.CompareRefToTexture; } compareFunc = samplerStateDescription.CompareFunction.ToOpenGLDepthFunction(); borderColor = samplerStateDescription.BorderColor.ToArray(); // TODO: How to do MipLinear vs MipPoint? switch (samplerStateDescription.Filter & ~(ComparisonMask | AnisotropicMask)) // Ignore comparison (128) and anisotropic (64) part { case TextureFilter.MinMagLinearMipPoint: minFilter = TextureMinFilter.LinearMipmapNearest; magFilter = TextureMagFilter.Linear; break; case TextureFilter.Linear: minFilter = TextureMinFilter.LinearMipmapLinear; magFilter = TextureMagFilter.Linear; break; case TextureFilter.MinPointMagMipLinear: minFilter = TextureMinFilter.NearestMipmapLinear; magFilter = TextureMagFilter.Linear; break; case TextureFilter.Point: minFilter = TextureMinFilter.NearestMipmapNearest; magFilter = TextureMagFilter.Nearest; break; case TextureFilter.MinPointMagLinearMipPoint: minFilter = TextureMinFilter.NearestMipmapNearest; magFilter = TextureMagFilter.Linear; break; case TextureFilter.MinLinearMagMipPoint: minFilter = TextureMinFilter.LinearMipmapNearest; magFilter = TextureMagFilter.Nearest; break; case TextureFilter.MinMagPointMipLinear: minFilter = TextureMinFilter.NearestMipmapLinear; magFilter = TextureMagFilter.Nearest; break; case TextureFilter.MinLinearMagPointMipLinear: minFilter = TextureMinFilter.LinearMipmapLinear; magFilter = TextureMagFilter.Nearest; break; default: throw new NotImplementedException(); } maxAnisotropy = ((samplerStateDescription.Filter & AnisotropicMask) != 0) ? Description.MaxAnisotropy : 1; #if STRIDE_GRAPHICS_API_OPENGLES // On OpenGL ES, we need to choose the appropriate min filter ourself if the texture doesn't contain mipmaps (done at PreDraw) minFilterNoMipmap = minFilter; if (minFilterNoMipmap == TextureMinFilter.LinearMipmapLinear) { minFilterNoMipmap = TextureMinFilter.Linear; } else if (minFilterNoMipmap == TextureMinFilter.NearestMipmapLinear) { minFilterNoMipmap = TextureMinFilter.Nearest; } #endif }
/// <summary> /// Create a new fake sampler state for serialization. /// </summary> /// <param name="description">The description of the sampler state</param> /// <returns>The fake sampler state</returns> public static SamplerState NewFake(SamplerStateDescription description) { return(new SamplerState(description)); }
// For FakeSamplerState. private SamplerState(SamplerStateDescription description) { Description = description; }