/* Private Hashing Functions */ private static StateHash GetBlendHash( BlendFunction alphaBlendFunc, Blend alphaDestBlend, Blend alphaSrcBlend, BlendFunction colorBlendFunc, Blend colorDestBlend, Blend colorSrcBlend, ColorWriteChannels channels, ColorWriteChannels channels1, ColorWriteChannels channels2, ColorWriteChannels channels3, Color blendFactor, int multisampleMask ) { int funcs = ((int)alphaBlendFunc << 4) | ((int)colorBlendFunc); int blendsAndColorWriteChannels = ((int)alphaDestBlend << 28) | ((int)alphaSrcBlend << 24) | ((int)colorDestBlend << 20) | ((int)colorSrcBlend << 16) | ((int)channels << 12) | ((int)channels1 << 8) | ((int)channels2 << 4) | ((int)channels3); unchecked { return(new StateHash( ((ulong)funcs << 32) | ((ulong)blendsAndColorWriteChannels << 0), ((ulong)multisampleMask << 32) | ((ulong)blendFactor.PackedValue << 0) )); } }
internal unsafe BlendState(BlendStateDescription blendStateDescription, bool hasRenderTarget) { var renderTargets = &blendStateDescription.RenderTarget0; for (int i = 1; i < 8; ++i) { if (renderTargets[i].BlendEnable || renderTargets[i].ColorWriteChannels != ColorWriteChannels.All) { throw new NotSupportedException(); } } ColorWriteChannels = blendStateDescription.RenderTarget0.ColorWriteChannels; if (!hasRenderTarget) { ColorWriteChannels = 0; } blendEnable = blendStateDescription.RenderTarget0.BlendEnable; blendEquationModeColor = ToOpenGL(blendStateDescription.RenderTarget0.ColorBlendFunction); blendEquationModeAlpha = ToOpenGL(blendStateDescription.RenderTarget0.AlphaBlendFunction); blendFactorSrcColor = ToOpenGL(blendStateDescription.RenderTarget0.ColorSourceBlend); blendFactorSrcAlpha = ToOpenGL(blendStateDescription.RenderTarget0.AlphaSourceBlend); blendFactorDestColor = (BlendingFactorDest)ToOpenGL(blendStateDescription.RenderTarget0.ColorDestinationBlend); blendFactorDestAlpha = (BlendingFactorDest)ToOpenGL(blendStateDescription.RenderTarget0.AlphaDestinationBlend); blendEquationHash = (uint)blendStateDescription.RenderTarget0.ColorBlendFunction | ((uint)blendStateDescription.RenderTarget0.AlphaBlendFunction << 8); blendFuncHash = (uint)blendStateDescription.RenderTarget0.ColorSourceBlend | ((uint)blendStateDescription.RenderTarget0.AlphaSourceBlend << 8) | ((uint)blendStateDescription.RenderTarget0.ColorDestinationBlend << 16) | ((uint)blendStateDescription.RenderTarget0.AlphaDestinationBlend << 24); }
internal unsafe BlendState(BlendStateDescription blendStateDescription, bool hasRenderTarget) { var renderTargets = &blendStateDescription.RenderTarget0; for (int i = 1; i < 8; ++i) { if (renderTargets[i].BlendEnable || renderTargets[i].ColorWriteChannels != ColorWriteChannels.All) throw new NotSupportedException(); } ColorWriteChannels = blendStateDescription.RenderTarget0.ColorWriteChannels; if (!hasRenderTarget) ColorWriteChannels = 0; blendEnable = blendStateDescription.RenderTarget0.BlendEnable; blendEquationModeColor = ToOpenGL(blendStateDescription.RenderTarget0.ColorBlendFunction); blendEquationModeAlpha = ToOpenGL(blendStateDescription.RenderTarget0.AlphaBlendFunction); blendFactorSrcColor = ToOpenGL(blendStateDescription.RenderTarget0.ColorSourceBlend); blendFactorSrcAlpha = ToOpenGL(blendStateDescription.RenderTarget0.AlphaSourceBlend); blendFactorDestColor = (BlendingFactorDest)ToOpenGL(blendStateDescription.RenderTarget0.ColorDestinationBlend); blendFactorDestAlpha = (BlendingFactorDest)ToOpenGL(blendStateDescription.RenderTarget0.AlphaDestinationBlend); blendEquationHash = (uint)blendStateDescription.RenderTarget0.ColorBlendFunction | ((uint)blendStateDescription.RenderTarget0.AlphaBlendFunction << 8); blendFuncHash = (uint)blendStateDescription.RenderTarget0.ColorSourceBlend | ((uint)blendStateDescription.RenderTarget0.AlphaSourceBlend << 8) | ((uint)blendStateDescription.RenderTarget0.ColorDestinationBlend << 16) | ((uint)blendStateDescription.RenderTarget0.AlphaDestinationBlend << 24); }
void IBeginEndDraw.Begin(DrawState state) { if (enabled) { previous = state.RenderState.DepthColourCull.ColourWriteMask; ColorWriteChannels c = 0; if (red) { c |= ColorWriteChannels.Red; } if (green) { c |= ColorWriteChannels.Green; } if (blue) { c |= ColorWriteChannels.Blue; } if (alpha) { c |= ColorWriteChannels.Alpha; } state.RenderState.DepthColourCull.ColourWriteMask = c; currentlyEnabled = true; } }
public BlendState(string name, Blend colorSourceBlend = Blend.One, Blend alphaSourceBlend = Blend.One, Blend colorDestinationBlend = Blend.Zero, Blend alphaDestinationBlend = Blend.Zero, BlendFunction colorBlendFunction = BlendFunction.Add, BlendFunction alphaBlendFunction = BlendFunction.Add, ColorWriteChannels colorWriteChannels = ColorWriteChannels.All, ColorWriteChannels colorWriteChannels1 = ColorWriteChannels.All, ColorWriteChannels colorWriteChannels2 = ColorWriteChannels.All, ColorWriteChannels colorWriteChannels3 = ColorWriteChannels.All) { Name = name; ColorSourceBlend = colorSourceBlend; AlphaSourceBlend = alphaSourceBlend; ColorDestinationBlend = colorDestinationBlend; AlphaDestinationBlend = alphaDestinationBlend; ColorBlendFunction = colorBlendFunction; AlphaBlendFunction = alphaBlendFunction; ColorWriteChannels = colorWriteChannels; ColorWriteChannels1 = colorWriteChannels1; ColorWriteChannels2 = colorWriteChannels2; ColorWriteChannels3 = colorWriteChannels3; BlendFactor = Color.White; MultiSampleMask = unchecked ((int)0xffffffff); }
public GL10() { int num; this.color = new float[4]; this.clearColor = Color.Black; this.ColorWriteChannels = ColorWriteChannels.All; this.AlphaDestinationBlend = Blend.InverseSourceAlpha; this.depthFunc = CompareFunction.Always; this.textureFilter = TextureFilter.Linear; this.textureAddressU = TextureAddressMode.Clamp; this.textureAddressV = TextureAddressMode.Clamp; this.vertex = new Vertex[8]; this.texture = new Texture[0x100]; this.matrixStack = new Stack <Matrix>(); this.effect = new BasicEffect(GLEx.device); this.effect.VertexColorEnabled = true; this.alphaTestEffect = new AlphaTestEffect(GLEx.device); this.alphaTestEffect.VertexColorEnabled = true; for (num = 0; num < this.vertex.Length; num++) { this.vertex[num] = new Vertex(); } for (num = 0; num < 4; num++) { this.color[num] = 1f; } }
static private SharpDX.Direct3D11.ColorWriteMaskFlags GetColorWriteMask(ColorWriteChannels mask) { return(((mask & ColorWriteChannels.Red) != 0 ? SharpDX.Direct3D11.ColorWriteMaskFlags.Red : 0) | ((mask & ColorWriteChannels.Green) != 0 ? SharpDX.Direct3D11.ColorWriteMaskFlags.Green : 0) | ((mask & ColorWriteChannels.Blue) != 0 ? SharpDX.Direct3D11.ColorWriteMaskFlags.Blue : 0) | ((mask & ColorWriteChannels.Alpha) != 0 ? SharpDX.Direct3D11.ColorWriteMaskFlags.Alpha : 0)); }
/* Private Hashing Functions */ private static StateHash GetBlendHash( BlendFunction alphaBlendFunc, Blend alphaDestBlend, Blend alphaSrcBlend, BlendFunction colorBlendFunc, Blend colorDestBlend, Blend colorSrcBlend, ColorWriteChannels channels, ColorWriteChannels channels1, ColorWriteChannels channels2, ColorWriteChannels channels3, Color blendFactor, int multisampleMask ) { int funcs = ((int)alphaBlendFunc << 4) | ((int)colorBlendFunc); int blendsAndColorWriteChannels = ((int)alphaDestBlend << (32 - 4)) | ((int)alphaSrcBlend << (32 - 8)) | ((int)colorDestBlend << (32 - 12)) | ((int)colorSrcBlend << (32 - 16)) | ((int)channels << (32 - 20)) | ((int)channels1 << (32 - 24)) | ((int)channels2 << (32 - 28)) | ((int)channels3); return(new StateHash( funcs, blendsAndColorWriteChannels, (int)blendFactor.PackedValue, multisampleMask )); }
/// <summary> /// Sets the write mask used by the render target specified by its index. /// </summary> /// <param name="index">Render target index</param> /// <param name="mask">Color write mask to use</param> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if the index is less than zero or greater than <see cref="ColorWriteChannelsCount"/></exception> /// <exception cref="System.InvalidOperationException">Thrown if the implementation is bound. Once bound render states are read-only.</exception> public void SetWriteChannels(int index, ColorWriteChannels mask) { ThrowIfBound(); if (index < 0 || index > _writeChannels.Length) { throw new ArgumentOutOfRangeException("Index is out of range"); } _writeChannels[index] = mask; }
public BlendState() { _alphaBlendFunction = BlendEquationMode.FuncAdd; _alphaDestinationBlend = BlendingFactorDest.Zero; _alphaSourceBlend = BlendingFactorSrc.One; _colorBlendFunction = BlendEquationMode.FuncAdd; _colorDestinationBlend = BlendingFactorDest.Zero; _colorSourceBlend = BlendingFactorSrc.One; _colorWriteChannels = ColorWriteChannels.All; _blendColor = new Color4(0, 0, 0, 0); _dirty = true; }
private void ClearDepth(Mesh mesh) { bool depthWrites = mesh.DepthWrites; ColorWriteChannels colorWriteChannels = GraphicsDeviceExtensions.GetBlendCombiner(this.GraphicsDevice).ColorWriteChannels; mesh.DepthWrites = true; GraphicsDeviceExtensions.SetColorWriteChannels(this.GraphicsDevice, ColorWriteChannels.None); mesh.AlwaysOnTop = true; mesh.Position += this.CameraManager.InverseView.Forward * 2f; mesh.Draw(); mesh.AlwaysOnTop = false; mesh.Position -= this.CameraManager.InverseView.Forward * 2f; GraphicsDeviceExtensions.SetColorWriteChannels(this.GraphicsDevice, colorWriteChannels); mesh.DepthWrites = depthWrites; }
public void SetBlendState(BlendState state) { _AlphaBlendFunction = state.AlphaBlendFunction; _AlphaDestinationBlend = state.AlphaDestinationBlend; _AlphaSourceBlend = state.AlphaSourceBlend; _BlendFactor = state.BlendFactor; _ColorBlendFunction = state.ColorBlendFunction; _ColorDestinationBlend = state.ColorDestinationBlend; _ColorSourceBlend = state.ColorSourceBlend; _ColorWriteChannels = state.ColorWriteChannels; _ColorWriteChannels1 = state.ColorWriteChannels1; _ColorWriteChannels2 = state.ColorWriteChannels2; _ColorWriteChannels3 = state.ColorWriteChannels3; _MultiSampleMask = state.MultiSampleMask; blendStateDirty = true; }
public static Boolean TryUpdate(ref CachedColorMask current, ColorWriteChannels desired) { if (current.value == desired) { return(false); } current = desired; gl.ColorMask( (desired & ColorWriteChannels.Red) == ColorWriteChannels.Red, (desired & ColorWriteChannels.Green) == ColorWriteChannels.Green, (desired & ColorWriteChannels.Blue) == ColorWriteChannels.Blue, (desired & ColorWriteChannels.Alpha) == ColorWriteChannels.Alpha); gl.ThrowIfError(); return(true); }
private void processColorChannels(ref ColorWriteChannels channels, JsonObject jo, params string[] args) { var jv = findFirst(jo, args); if (jv.Type == JsonTypes.Array) { var ja = (JsonArray)jv; for (var i = 0; i < ja.Count; i++) { _processColorChannels(ref channels, ja[i]); } } else { _processColorChannels(ref channels, jv); } }
internal BS GetBlendState(VGBlendMode blendMode, ColorWriteChannels channels) { if (channels == ColorWriteChannels.All) return _blendStates[(int)blendMode]; var o = _blendStates[(int)blendMode]; return new BS() { AlphaBlendFunction = o.AlphaBlendFunction, AlphaDestinationBlend = o.AlphaDestinationBlend, AlphaSourceBlend = o.AlphaSourceBlend, ColorBlendFunction = o.ColorBlendFunction, ColorDestinationBlend = o.ColorDestinationBlend, ColorSourceBlend = o.ColorSourceBlend, ColorWriteChannels = channels, MultiSampleMask = o.MultiSampleMask }; }
private static BlendState ChangeColorWriteChannels(BlendState blendState, ColorWriteChannels colorWriteChannels) { return(new BlendState { AlphaBlendFunction = blendState.AlphaBlendFunction, AlphaDestinationBlend = blendState.AlphaDestinationBlend, AlphaSourceBlend = blendState.AlphaSourceBlend, BlendFactor = blendState.BlendFactor, ColorBlendFunction = blendState.ColorBlendFunction, ColorDestinationBlend = blendState.ColorDestinationBlend, ColorSourceBlend = blendState.ColorSourceBlend, ColorWriteChannels = colorWriteChannels, ColorWriteChannels1 = blendState.ColorWriteChannels1, ColorWriteChannels2 = blendState.ColorWriteChannels2, ColorWriteChannels3 = blendState.ColorWriteChannels3, MultiSampleMask = blendState.MultiSampleMask, Name = blendState.Name }); }
/* Public Functions */ public void BeginApplyBlend() { BlendState oldBlendState = device.BlendState; AlphaBlendFunction = oldBlendState.AlphaBlendFunction; AlphaDestinationBlend = oldBlendState.AlphaDestinationBlend; AlphaSourceBlend = oldBlendState.AlphaSourceBlend; ColorBlendFunction = oldBlendState.ColorBlendFunction; ColorDestinationBlend = oldBlendState.ColorDestinationBlend; ColorSourceBlend = oldBlendState.ColorSourceBlend; ColorWriteChannels = oldBlendState.ColorWriteChannels; ColorWriteChannels1 = oldBlendState.ColorWriteChannels1; ColorWriteChannels2 = oldBlendState.ColorWriteChannels2; ColorWriteChannels3 = oldBlendState.ColorWriteChannels3; BlendFactor = oldBlendState.BlendFactor; MultiSampleMask = oldBlendState.MultiSampleMask; SeparateAlphaBlend = ( ColorBlendFunction != AlphaBlendFunction || ColorDestinationBlend != AlphaDestinationBlend ); }
public void CopyToRenderTarget(RenderTarget2D target, Texture2D source, ColorWriteChannels channels, Rectangle? sourceRect, Rectangle? targetRect, Effect effect) { var device = Device.GraphicsDevice; if (target != null && device != target.GraphicsDevice) throw new InvalidOperationException("RenderTarget2D does not belong to this VGDevice!"); if (device != source.GraphicsDevice) throw new InvalidOperationException("Source does not belong to this VGDevice!"); if (!targetRect.HasValue) { if (target != null) targetRect = target.Bounds; else targetRect = source.GraphicsDevice.PresentationParameters.Bounds; } var rtts = device.GetRenderTargets(); var blend = new BlendState { AlphaDestinationBlend = Blend.Zero, AlphaSourceBlend = Blend.One, ColorDestinationBlend = Blend.Zero, ColorSourceBlend = Blend.One, ColorWriteChannels = channels }; try { device.SetRenderTarget(target); _spriteBatch.Begin(SpriteSortMode.Immediate, blend, null, null, null, effect, Matrix.Identity); _spriteBatch.Draw(source, targetRect.Value, sourceRect, Color.White); _spriteBatch.End(); } finally { device.SetRenderTargets(rtts); } }
private void _processColorChannels(ref ColorWriteChannels channels, JsonValue jv) { if (jv.Type == JsonTypes.Number) { var num = ((int)jv) & 0xf; channels |= (ColorWriteChannels)num; } else if (jv.Type == JsonTypes.String) { var name = (string)jv; switch (name.ToLower()) { case "none": channels |= ColorWriteChannels.None; break; case "red": channels |= ColorWriteChannels.Red; break; case "blue": channels |= ColorWriteChannels.Blue; break; case "green": channels |= ColorWriteChannels.Green; break; case "alpha": channels |= ColorWriteChannels.Alpha; break; } } }
public unsafe static ColorComponentFlags ConvertColorWriteChannels(ColorWriteChannels colorWriteChannels) { return *(ColorComponentFlags*)&colorWriteChannels; }
/// <summary> /// Sets the write mask used by the render target specified by its index. /// </summary> /// <param name="index">Render target index</param> /// <param name="mask">Color write mask to use</param> public void SetWriteChannels(int index, ColorWriteChannels mask) { _impl.SetWriteChannels(index, mask); }
public static void SetColorWriteChannels(this GraphicsDevice _, ColorWriteChannels channels) { GraphicsDeviceExtensions.blendCombiner.ColorWriteChannels = channels; }
public void GLColorMask(bool red, bool green, bool blue, bool alpha) { this.ColorWriteChannels = (((red ? ColorWriteChannels.Red : ColorWriteChannels.None) | (green ? ColorWriteChannels.Green : ColorWriteChannels.None)) | (blue ? ColorWriteChannels.Blue : ColorWriteChannels.None)) | (alpha ? ColorWriteChannels.Alpha : ColorWriteChannels.None); }
private void WriteBlendState(String name, BlendState value) { _writer.Write(TAB_BLOCK2); _writer.Write("BlendState"); WriteSpace(); _writer.Write(name); RenderStateKey key = value.RenderStateKey; if (key.Equals(BlendState.AdditiveBlend.RenderStateKey)) { WriteSeparator(); _writer.Write("AdditiveBlend"); WriteNewLine(); } else if (key.Equals(BlendState.AlphaBlendNonPremultiplied.RenderStateKey)) { WriteSeparator(); _writer.Write("AlphaBlendNonPremultiplied"); WriteNewLine(); } else if (key.Equals(BlendState.AlphaBlendPremultiplied.RenderStateKey)) { WriteSeparator(); _writer.Write("AlphaBlendPremultiplied"); WriteNewLine(); } else if (key.Equals(BlendState.Opaque.RenderStateKey)) { WriteSeparator(); _writer.Write("Opaque"); WriteNewLine(); } else { WriteOpenBrace(); if (value.AlphaBlendFunction != BlendFunction.Add) { _writer.Write(TAB_BLOCK3); _writer.Write("AlphaBlendFunction"); WriteSeparator(); _writer.Write(value.AlphaBlendFunction.ToString()); WriteNewLine(); } if (value.AlphaSourceBlend != Blend.One) { _writer.Write(TAB_BLOCK3); _writer.Write("AlphaSourceBlend"); WriteSeparator(); _writer.Write(value.AlphaSourceBlend.ToString()); WriteNewLine(); } if (value.AlphaDestinationBlend != Blend.Zero) { _writer.Write(TAB_BLOCK3); _writer.Write("AlphaDestinationBlend"); WriteSeparator(); _writer.Write(value.AlphaDestinationBlend.ToString()); WriteNewLine(); } if (value.ColorBlendFunction != BlendFunction.Add) { _writer.Write(TAB_BLOCK3); _writer.Write("ColorBlendFunction"); WriteSeparator(); _writer.Write(value.ColorBlendFunction.ToString()); WriteNewLine(); } if (value.ColorSourceBlend != Blend.One) { _writer.Write(TAB_BLOCK3); _writer.Write("ColorSourceBlend"); WriteSeparator(); _writer.Write(value.ColorSourceBlend.ToString()); WriteNewLine(); } if (value.ColorDestinationBlend != Blend.Zero) { _writer.Write(TAB_BLOCK3); _writer.Write("ColorDestinationBlend"); WriteSeparator(); _writer.Write(value.ColorDestinationBlend.ToString()); WriteNewLine(); } if (!value.BlendFactor.Equals(Color.White)) { _writer.Write(TAB_BLOCK3); _writer.Write("BlendFactor"); WriteSeparator(); Color c = value.BlendFactor; _writer.Write(c.R); WriteSpace(); _writer.Write(c.G); WriteSpace(); _writer.Write(c.B); WriteSpace(); _writer.Write(c.A); WriteNewLine(); } if (value.MultiSampleMask != int.MaxValue) { _writer.Write(TAB_BLOCK3); _writer.Write("MultiSampleMask"); WriteSeparator(); _writer.Write(value.MultiSampleMask); WriteNewLine(); } int beCount = value.BlendEnableCount; if (beCount > 0) { if (value.GetBlendEnable(0) == false) { _writer.Write(TAB_BLOCK3); _writer.Write("BlendEnable[0]"); WriteSeparator(); _writer.Write("false"); WriteNewLine(); } for (int i = 1; i < beCount; i++) { if (value.GetBlendEnable(i) == true) { _writer.Write(TAB_BLOCK3); _writer.Write("BlendEnable["); _writer.Write(i); _writer.Write("]"); WriteSeparator(); _writer.Write("true"); WriteNewLine(); } } } int cwCount = value.ColorWriteChannelsCount; if (cwCount > 0) { ColorWriteChannels cwc = value.GetWriteChannels(0); if (cwc != ColorWriteChannels.All) { _writer.Write(TAB_BLOCK3); _writer.Write("ColorWriteChannels[0]"); WriteSeparator(); _writer.Write(cwc.ToString().Replace(",", " |")); WriteNewLine(); } for (int i = 1; i < cwCount; i++) { cwc = value.GetWriteChannels(i); if (cwc != ColorWriteChannels.All) { _writer.Write(TAB_BLOCK3); _writer.Write("ColorWriteChannels["); _writer.Write(i); _writer.Write("]"); WriteSeparator(); _writer.Write(cwc.ToString().Replace(",", " |")); WriteNewLine(); } } } WriteCloseBrace(false, TAB_BLOCK2); } }
static private SharpDX.Direct3D11.ColorWriteMaskFlags GetColorWriteMask(ColorWriteChannels mask) { return ((mask & ColorWriteChannels.Red) != 0 ? SharpDX.Direct3D11.ColorWriteMaskFlags.Red : 0) | ((mask & ColorWriteChannels.Green) != 0 ? SharpDX.Direct3D11.ColorWriteMaskFlags.Green : 0) | ((mask & ColorWriteChannels.Blue) != 0 ? SharpDX.Direct3D11.ColorWriteMaskFlags.Blue : 0) | ((mask & ColorWriteChannels.Alpha) != 0 ? SharpDX.Direct3D11.ColorWriteMaskFlags.Alpha : 0); }
public static unsafe VkColorComponentFlags ConvertColorWriteChannels(ColorWriteChannels colorWriteChannels) { return(*(VkColorComponentFlags *)&colorWriteChannels); }
public void SetBlendState(BlendState blendState) { bool newEnable = ( !( blendState.ColorSourceBlend == Blend.One && blendState.ColorDestinationBlend == Blend.Zero && blendState.AlphaSourceBlend == Blend.One && blendState.AlphaDestinationBlend == Blend.Zero ) ); if (newEnable != alphaBlendEnable) { alphaBlendEnable = newEnable; ToggleGLState(GLenum.GL_BLEND, alphaBlendEnable); } if (alphaBlendEnable) { if (blendState.BlendFactor != blendColor) { blendColor = blendState.BlendFactor; glBlendColor( blendColor.R / 255.0f, blendColor.G / 255.0f, blendColor.B / 255.0f, blendColor.A / 255.0f ); } if ( blendState.ColorSourceBlend != srcBlend || blendState.ColorDestinationBlend != dstBlend || blendState.AlphaSourceBlend != srcBlendAlpha || blendState.AlphaDestinationBlend != dstBlendAlpha ) { srcBlend = blendState.ColorSourceBlend; dstBlend = blendState.ColorDestinationBlend; srcBlendAlpha = blendState.AlphaSourceBlend; dstBlendAlpha = blendState.AlphaDestinationBlend; glBlendFuncSeparate( XNAToGL.BlendMode[(int) srcBlend], XNAToGL.BlendMode[(int) dstBlend], XNAToGL.BlendMode[(int) srcBlendAlpha], XNAToGL.BlendMode[(int) dstBlendAlpha] ); } if ( blendState.ColorBlendFunction != blendOp || blendState.AlphaBlendFunction != blendOpAlpha ) { blendOp = blendState.ColorBlendFunction; blendOpAlpha = blendState.AlphaBlendFunction; glBlendEquationSeparate( XNAToGL.BlendEquation[(int) blendOp], XNAToGL.BlendEquation[(int) blendOpAlpha] ); } } if (blendState.ColorWriteChannels != colorWriteEnable) { colorWriteEnable = blendState.ColorWriteChannels; glColorMask( (colorWriteEnable & ColorWriteChannels.Red) != 0, (colorWriteEnable & ColorWriteChannels.Green) != 0, (colorWriteEnable & ColorWriteChannels.Blue) != 0, (colorWriteEnable & ColorWriteChannels.Alpha) != 0 ); } /* FIXME: So how exactly do we factor in * COLORWRITEENABLE for buffer 0? Do we just assume that * the default is just buffer 0, and all other calls * update the other write masks afterward? Or do we * assume that COLORWRITEENABLE only touches 0, and the * other 3 buffers are left alone unless we don't have * EXT_draw_buffers2? * -flibit */ if (blendState.ColorWriteChannels1 != colorWriteEnable1) { colorWriteEnable1 = blendState.ColorWriteChannels1; glColorMaskIndexedEXT( 1, (colorWriteEnable1 & ColorWriteChannels.Red) != 0, (colorWriteEnable1 & ColorWriteChannels.Green) != 0, (colorWriteEnable1 & ColorWriteChannels.Blue) != 0, (colorWriteEnable1 & ColorWriteChannels.Alpha) != 0 ); } if (blendState.ColorWriteChannels2 != colorWriteEnable2) { colorWriteEnable2 = blendState.ColorWriteChannels2; glColorMaskIndexedEXT( 2, (colorWriteEnable2 & ColorWriteChannels.Red) != 0, (colorWriteEnable2 & ColorWriteChannels.Green) != 0, (colorWriteEnable2 & ColorWriteChannels.Blue) != 0, (colorWriteEnable2 & ColorWriteChannels.Alpha) != 0 ); } if (blendState.ColorWriteChannels3 != colorWriteEnable3) { colorWriteEnable3 = blendState.ColorWriteChannels3; glColorMaskIndexedEXT( 3, (colorWriteEnable3 & ColorWriteChannels.Red) != 0, (colorWriteEnable3 & ColorWriteChannels.Green) != 0, (colorWriteEnable3 & ColorWriteChannels.Blue) != 0, (colorWriteEnable3 & ColorWriteChannels.Alpha) != 0 ); } if (blendState.MultiSampleMask != multisampleMask && supportsMultisampling) { if (blendState.MultiSampleMask == -1) { glDisable(GLenum.GL_SAMPLE_MASK); } else { if (multisampleMask == -1) { glEnable(GLenum.GL_SAMPLE_MASK); } // FIXME: index...? -flibit glSampleMaski(0, (uint) blendState.MultiSampleMask); } multisampleMask = blendState.MultiSampleMask; } }
private CachedColorMask(ColorWriteChannels value) { this.value = value; }
public GL10() { int num; this.color = new float[4]; this.clearColor = Color.Black; this.ColorWriteChannels = ColorWriteChannels.All; this.AlphaDestinationBlend = Blend.InverseSourceAlpha; this.depthFunc = CompareFunction.Always; this.textureFilter = TextureFilter.Linear; this.textureAddressU = TextureAddressMode.Clamp; this.textureAddressV = TextureAddressMode.Clamp; this.vertex = new Vertex[8]; this.texture = new Texture[0x100]; this.matrixStack = new Stack<Matrix>(); this.effect = new BasicEffect(GLEx.device); this.effect.VertexColorEnabled = true; this.alphaTestEffect = new AlphaTestEffect(GLEx.device); this.alphaTestEffect.VertexColorEnabled = true; for (num = 0; num < this.vertex.Length; num++) { this.vertex[num] = new Vertex(); } for (num = 0; num < 4; num++) { this.color[num] = 1f; } }
void IBeginEndDraw.Begin(DrawState state) { if (enabled) { previous = state.RenderState.CurrentRasterState.ColourWriteMask; ColorWriteChannels c = 0; if (red) c |= ColorWriteChannels.Red; if (green) c |= ColorWriteChannels.Green; if (blue) c |= ColorWriteChannels.Blue; if (alpha) c |= ColorWriteChannels.Alpha; state.RenderState.CurrentRasterState.ColourWriteMask = c; currentlyEnabled = true; } }