public virtual void Begin() { // Save the current matrix CCDrawManager.PushMatrix(); CCSize texSize = m_pTexture.ContentSizeInPixels; // Calculate the adjustment ratios based on the old and new projections CCDirector director = CCDirector.SharedDirector; CCSize size = director.WinSizeInPixels; float widthRatio = size.Width / texSize.Width; float heightRatio = size.Height / texSize.Height; CCDrawManager.SetRenderTarget(m_pTexture); CCDrawManager.SetViewPort(0, 0, (int)texSize.Width, (int)texSize.Height); Matrix projection = Matrix.CreateOrthographicOffCenter( -1.0f / widthRatio, 1.0f / widthRatio, -1.0f / heightRatio, 1.0f / heightRatio, -1, 1 ); CCDrawManager.MultMatrix(ref projection); if (m_bFirstUsage) { CCDrawManager.Clear(Color.Transparent); m_bFirstUsage = false; } }
/// <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(); } }
// 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(); } }
private void BeforeDraw() { m_bNoDrawChildren = false; if (m_childClippingMode == CCClipMode.Bounds) { // We always clip to the bounding box var rect = new CCRect(0, 0, m_obContentSize.Width, m_obContentSize.Height); var bounds = CCAffineTransform.Transform(rect, NodeToWorldTransform()); var winSize = CCDirector.SharedDirector.WinSize; CCRect prevScissorRect; if (CCDrawManager.ScissorRectEnabled) { prevScissorRect = CCDrawManager.ScissorRect; } else { prevScissorRect = new CCRect(0, 0, winSize.Width, winSize.Height); } if (!bounds.IntersectsRect(prevScissorRect)) { m_bNoDrawChildren = true; return; } float minX = Math.Max(bounds.MinX, prevScissorRect.MinX); float minY = Math.Max(bounds.MinY, prevScissorRect.MinY); float maxX = Math.Min(bounds.MaxX, prevScissorRect.MaxX); float maxY = Math.Min(bounds.MaxY, prevScissorRect.MaxY); if (CCDrawManager.ScissorRectEnabled) { m_bRestoreScissor = true; } else { CCDrawManager.ScissorRectEnabled = true; } m_tSaveScissorRect = prevScissorRect; CCDrawManager.SetScissorInPoints(minX, minY, maxX - minX, maxY - minY); } else if (m_childClippingMode == CCClipMode.BoundsWithRenderTarget) { m_tSaveScissorRect = CCDrawManager.ScissorRect; m_bRestoreScissor = CCDrawManager.ScissorRectEnabled; CCDrawManager.ScissorRectEnabled = false; CCDrawManager.PushMatrix(); CCDrawManager.SetIdentityMatrix(); m_pRenderTexture.BeginWithClear(0, 0, 0, 0); } }
/// <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--; }