/// <summary> /// Draw the scene. /// This method is called every frame. Don't call it manually. /// </summary> protected void DrawScene(GameTime gameTime) { CCDrawManager.PushMatrix(); // draw the scene if (m_pRunningScene != null) { m_pRunningScene.Visit(); } // draw the notifications node if (m_pNotificationNode != null) { NotificationNode.Visit(); } ShowStats(); CCDrawManager.PopMatrix(); m_uTotalFrames++; if (m_bDisplayStats) { CalculateMPF(); } }
/** * retract what's done in beforeDraw so that there's no side effect to * other nodes. */ private void AfterDraw() { if (m_childClippingMode != CCClipMode.None) { if (m_childClippingMode == CCClipMode.BoundsWithRenderTarget) { m_pRenderTexture.End(); CCDrawManager.PopMatrix(); } if (m_bRestoreScissor) { CCDrawManager.SetScissorInPoints( m_tSaveScissorRect.Origin.X, m_tSaveScissorRect.Origin.Y, m_tSaveScissorRect.Size.Width, m_tSaveScissorRect.Size.Height); CCDrawManager.ScissorRectEnabled = true; m_bRestoreScissor = false; } else { CCDrawManager.ScissorRectEnabled = false; } if (m_childClippingMode == CCClipMode.BoundsWithRenderTarget) { m_pRenderTexture.Sprite.Visit(); } } }
// CCParticleBatchNode - composition // override visit. // Don't call visit on it's children public override void Visit() { // CAREFUL: // This visit is almost identical to CCNode#visit // with the exception that it doesn't call visit on it's children // // The alternative is to have a void CCSprite#visit, but // although this is less mantainable, is faster // if (!m_bVisible) { return; } //kmGLPushMatrix(); CCDrawManager.PushMatrix(); if (m_pGrid != null && m_pGrid.Active) { m_pGrid.BeforeDraw(); TransformAncestors(); } Transform(); Draw(); if (m_pGrid != null && m_pGrid.Active) { m_pGrid.AfterDraw(this); } //kmGLPopMatrix(); CCDrawManager.PopMatrix(); }
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(); } }
public virtual void End() { CCDrawManager.PopMatrix(); CCDirector director = CCDirector.SharedDirector; CCDrawManager.SetRenderTarget((CCTexture2D)null); director.Projection = director.Projection; }
/// <summary> /// Draw the scene. /// This method is called every frame. Don't call it manually. /// </summary> protected void DrawScene(GameTime gameTime) { if (m_NeedsInit) { return; } float startTime = 0; if (m_bDisplayStats) { startTime = (float)m_pStopwatch.Elapsed.TotalMilliseconds; } CCDrawManager.PushMatrix(); // draw the scene if (m_pRunningScene != null) { GraphIndex = 0; m_pRunningScene.Visit(); } // draw the notifications node if (m_pNotificationNode != null) { NotificationNode.Visit(); } if (m_bDisplayStats) { ShowStats(); } CCDrawManager.PopMatrix(); m_uTotalFrames++; if (m_bDisplayStats) { m_uDrawCount++; m_fAccumDraw += (float)m_pStopwatch.Elapsed.TotalMilliseconds - startTime; } }
/// <summary> /// This is called with every call to the MainLoop on the CCDirector class. In XNA, this is the same as the Draw() call. /// </summary> public virtual void Visit() { // quick return if not visible. children won't be drawn. if (!m_bVisible) { return; } CCDrawManager.PushMatrix(); if (m_pGrid != null && m_pGrid.Active) { m_pGrid.BeforeDraw(); //TransformAncestors(); } else { Transform(); } int i = 0; if ((m_pChildren != null) && (m_pChildren.count > 0)) { SortAllChildren(); CCNode[] elements = m_pChildren.Elements; int count = m_pChildren.count; // draw children zOrder < 0 for (; i < count; ++i) { if (elements[i].Visible && elements[i].m_nZOrder < 0) { elements[i].Visit(); } else { break; } } // self draw Draw(); // draw the children for (; i < count; ++i) { // Draw the z >= 0 order children next. if (elements[i].Visible /* && elements[i].m_nZOrder >= 0*/) { elements[i].Visit(); } } } else { // self draw Draw(); } m_uOrderOfArrival = 0; if (m_pGrid != null && m_pGrid.Active) { m_pGrid.AfterDraw(this); Transform(); m_pGrid.Blit(); } //kmGLPopMatrix(); CCDrawManager.PopMatrix(); }
/** * 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--; }