/// <summary> /// Deserializes the object and populates it from the input. /// </summary> /// <param name="input">Savable input</param> /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying state implementation fails or the render /// system is not set.</exception> public override void Read(Content.ISavableReader input) { IRenderSystemProvider renderSystem = input.RenderSystem; if (renderSystem == null) { Dispose(); throw new TeslaException("Render system provider not set, cannot create graphics resource implementation."); } base.RenderSystem = renderSystem; try { _impl = renderSystem.CreateBlendStateImplementation(); } catch (Exception e) { Dispose(); throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e); } _impl.AlphaBlendFunction = input.ReadEnum <BlendFunction>(); _impl.AlphaSourceBlend = input.ReadEnum <Blend>(); _impl.AlphaDestinationBlend = input.ReadEnum <Blend>(); _impl.ColorBlendFunction = input.ReadEnum <BlendFunction>(); _impl.ColorSourceBlend = input.ReadEnum <Blend>(); _impl.ColorDestinationBlend = input.ReadEnum <Blend>(); _impl.BlendFactor = input.ReadColor(); _impl.MultiSampleMask = input.ReadInt(); int numBlends = _impl.BlendEnableCount; int numMasks = _impl.ColorWriteChannelsCount; //Need to be careful here, this can change across different implementations. Just read in what we can and move on. int readNumBlends = input.ReadInt(); for (int i = 0; i < numBlends; i++) { _impl.SetBlendEnable(i, input.ReadBoolean()); } int readNumMasks = input.ReadInt(); for (int i = 0; i < numMasks; i++) { _impl.SetWriteChannels(i, (ColorWriteChannels)input.ReadInt()); } }
/// <summary> /// Creates a new instance of <see cref="BlendState"/> with default values. /// </summary> /// <param name="renderSystem">Render system used to create the underlying implementation.</param> /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception> /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying state implementation fails.</exception> public BlendState(IRenderSystemProvider renderSystem) { if (renderSystem == null) { Dispose(); throw new ArgumentNullException("renderSystem", "Render system cannot be null."); } base.RenderSystem = renderSystem; try { _impl = renderSystem.CreateBlendStateImplementation(); } catch (Exception e) { Dispose(); throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e); } SetDefaults(); }
/// <summary> /// Creates a new instance of <see cref="BlendState"/> with default values. /// </summary> /// <exception cref="Tesla.Core.TeslaException">Thrown if creating the underlying state implementation fails.</exception> public BlendState() { IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>(); if (renderSystem == null) { Dispose(); throw new TeslaException("Render system provider not set, cannot create graphics resource implementation."); } base.RenderSystem = renderSystem; try { _impl = renderSystem.CreateBlendStateImplementation(); } catch (Exception e) { Dispose(); throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e); } SetDefaults(); }