public override void Visit() { if (m_pStencil == null || !m_pStencil.Visible) { if (m_bInverted) { // draw everything base.Visit(); } return; } if (CCDrawManager.BeginDrawMask(m_bInverted, m_fAlphaThreshold)) { CCDrawManager.PushMatrix(); Transform(); m_pStencil.Visit(); CCDrawManager.PopMatrix(); CCDrawManager.EndDrawMask(); base.Visit(); CCDrawManager.EndMask(); } else { base.Visit(); } }
/** * Determines whether it clips its children or not. */ public override void Visit() { // quick return if not visible if (!Visible) { return; } CCDrawManager.PushMatrix(); //kmGLPushMatrix(); if (m_pGrid != null && m_pGrid.Active) { m_pGrid.BeforeDraw(); TransformAncestors(); } Transform(); BeforeDraw(); if (m_pChildren != null) { CCNode[] arrayData = m_pChildren.Elements; int count = m_pChildren.count; int i = 0; // draw children zOrder < 0 for (; i < count; i++) { CCNode child = arrayData[i]; if (child.m_nZOrder < 0) { child.Visit(); } else { break; } } // this draw Draw(); // draw children zOrder >= 0 for (; i < count; i++) { arrayData[i].Visit(); } } else { Draw(); } AfterDraw(); if (m_pGrid != null && m_pGrid.Active) { m_pGrid.AfterDraw(this); } CCDrawManager.PopMatrix(); //kmGLPopMatrix(); /* * // draw bounding box * CCRect box = m_pContainer.boundingBox; * var v = new[] * { * new CCPoint(box.origin.x, box.origin.y), * new CCPoint(box.origin.x + box.size.width, box.origin.y), * new CCPoint(box.origin.x + box.size.width, box.origin.y + box.size.height), * new CCPoint(box.origin.x, box.origin.y + box.size.height), * }; * CCDrawingPrimitives.ccDrawPoly(v, 4, true, new ccColor4F(255, 0, 0, 255)); */ }
/** * Determines whether it clips its children or not. */ public override void Visit() { // quick return if not visible if (!Visible) { return; } CCDrawManager.PushMatrix(); if (m_pGrid != null && m_pGrid.Active) { m_pGrid.BeforeDraw(); TransformAncestors(); } Transform(); BeforeDraw(); if (m_pChildren != null) { SortAllChildren(); CCNode[] arrayData = m_pChildren.Elements; int count = m_pChildren.count; int i = 0; // draw children zOrder < 0 for (; i < count; i++) { CCNode child = arrayData[i]; if (child.m_nZOrder < 0) { child.Visit(); } else { break; } } // this draw Draw(); // draw children zOrder >= 0 for (; i < count; i++) { arrayData[i].Visit(); } } else { Draw(); } AfterDraw(); if (m_pGrid != null && m_pGrid.Active) { m_pGrid.AfterDraw(this); } CCDrawManager.PopMatrix(); }
public override void Visit() { if (m_pStencil == null || !m_pStencil.Visible) { if (m_bInverted) { // draw everything base.Visit(); } return; } if (_layer + 1 == 8) //DepthFormat.Depth24Stencil8 { if (_once) { CCLog.Log( "Nesting more than 8 stencils is not supported. Everything will be drawn without stencil for this node and its childs." ); _once = false; } base.Visit(); return; } _layer++; int maskLayer = 1 << _layer; int maskLayerL = maskLayer - 1; int maskLayerLe = maskLayer | maskLayerL; var saveDepthStencilState = CCDrawManager.DepthStencilState; /////////////////////////////////// // CLEAR STENCIL BUFFER var stencilState = new DepthStencilState() { DepthBufferEnable = false, StencilEnable = true, StencilFunction = CompareFunction.Never, StencilMask = maskLayer, StencilWriteMask = maskLayer, ReferenceStencil = maskLayer, StencilFail = !m_bInverted ? StencilOperation.Zero : StencilOperation.Replace }; CCDrawManager.DepthStencilState = stencilState; // draw a fullscreen solid rectangle to clear the stencil buffer var size = CCDirector.SharedDirector.WinSize; CCDrawManager.PushMatrix(); CCDrawManager.SetIdentityMatrix(); CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawSolidRect(CCPoint.Zero, new CCPoint(size.Width, size.Height), new CCColor4B(255, 255, 255, 255)); CCDrawingPrimitives.End(); CCDrawManager.PopMatrix(); /////////////////////////////////// // DRAW CLIPPING STENCIL stencilState = new DepthStencilState() { DepthBufferEnable = false, StencilEnable = true, StencilFunction = CompareFunction.Never, StencilMask = maskLayer, StencilWriteMask = maskLayer, ReferenceStencil = maskLayer, StencilFail = !m_bInverted ? StencilOperation.Replace : StencilOperation.Zero, }; CCDrawManager.DepthStencilState = stencilState; if (m_fAlphaThreshold < 1) { if (_alphaTest == null) { _alphaTest = new AlphaTestEffect(CCDrawManager.GraphicsDevice); _alphaTest.AlphaFunction = CompareFunction.Greater; } _alphaTest.ReferenceAlpha = (byte)(255 * m_fAlphaThreshold); CCDrawManager.PushEffect(_alphaTest); } CCDrawManager.PushMatrix(); Transform(); m_pStencil.Visit(); CCDrawManager.PopMatrix(); if (m_fAlphaThreshold < 1) { CCDrawManager.PopEffect(); } /////////////////////////////////// // DRAW CONTENT stencilState = new DepthStencilState() { DepthBufferEnable = saveDepthStencilState.DepthBufferEnable, StencilEnable = true, StencilMask = maskLayerLe, StencilWriteMask = 0, ReferenceStencil = maskLayerLe, StencilFunction = CompareFunction.Equal, StencilPass = StencilOperation.Keep, StencilFail = StencilOperation.Keep, }; CCDrawManager.DepthStencilState = stencilState; base.Visit(); //Restore DepthStencilState CCDrawManager.DepthStencilState = saveDepthStencilState; _layer--; }