Пример #1
0
        public override void Draw()
        {
            if (TextureAtlas.TotalQuads == 0)
            {
                return;
            }

            CCDrawManager.BlendFunc(m_tBlendFunc);

            TextureAtlas.DrawQuads();
        }
Пример #2
0
        public override void Draw(GameTime gameTime)
        {
            GameTime = gameTime;

            CCDrawManager.BeginDraw();

            CCDirector.SharedDirector.MainLoop(gameTime);

            base.Draw(gameTime);

            CCDrawManager.EndDraw();
        }
Пример #3
0
        public override void Draw()
        {
            if (m_bDirty)
            {
                //TODO: Set vertices to buffer
                m_bDirty = false;
            }

            CCDrawManager.TextureEnabled = false;
            CCDrawManager.BlendFunc(m_sBlendFunc);
            CCDrawManager.DrawPrimitives(PrimitiveType.TriangleList, m_pVertices.Elements, 0, m_pVertices.Count / 3);
        }
Пример #4
0
 protected virtual void ServiceDeviceCreated(object sender, EventArgs e)
 {
     try
     {
         Game.Services.AddService(typeof(IGraphicsDeviceService), m_graphicsService);
     }
     catch (ArgumentException)
     {
         // Already contains the graphics device service.
     }
     CCDrawManager.Init(m_graphicsService.GraphicsDevice);
 }
Пример #5
0
        /// <summary>
        ///  Sets the camera using gluLookAt using its eye, center and up_vector
        /// </summary>
        public void Locate()
        {
            if (m_bDirty)
            {
                m_lookupMatrix = Matrix.CreateLookAt(new Vector3(m_fEyeX, m_fEyeY, m_fEyeZ),
                                                     new Vector3(m_fCenterX, m_fCenterY, m_fCenterZ),
                                                     new Vector3(m_fUpX, m_fUpY, m_fUpZ));
                m_bDirty = false;
            }

            CCDrawManager.MultMatrix(ref m_lookupMatrix);
        }
Пример #6
0
        public override void Blit()
        {
            if (m_bDirty)
            {
                m_pVertexBuffer.UpdateBuffer();
            }

            bool save = CCDrawManager.VertexColorEnabled;

            CCDrawManager.VertexColorEnabled = false;
            CCDrawManager.DrawBuffer(m_pVertexBuffer, m_pIndexBuffer, 0, m_pIndices.Length / 3);
            CCDrawManager.VertexColorEnabled = save;
        }
Пример #7
0
        public override void Draw()
        {
            var alphaTest = CCDrawManager.AlphaTestEffect;

            alphaTest.AlphaFunction  = CompareFunction.Greater;
            alphaTest.ReferenceAlpha = 0;

            CCDrawManager.PushEffect(alphaTest);

            base.Draw();

            CCDrawManager.PopEffect();
        }
Пример #8
0
        public void Set2DProjection()
        {
            CCSize size = m_pTexture.ContentSizeInPixels;

            CCDrawManager.SetViewPort(0, 0,
                                      (int)(size.Width * CCMacros.CCContentScaleFactor()),
                                      (int)(size.Height * CCMacros.CCContentScaleFactor())
                                      );

            /*
             * CCDrawManager.ProjectionMatrix = Matrix.Identity;
             *
             * Matrix orthoMatrix = Matrix.CreateOrthographicOffCenter(
             *  0, size.width * ccMacros.CC_CONTENT_SCALE_FACTOR(),
             *  0, size.height * ccMacros.CC_CONTENT_SCALE_FACTOR(),
             *  -1, 1
             *  );
             *
             * CCDrawManager.MultMatrix(ref orthoMatrix);
             */

            CCDrawManager.ViewMatrix       = Matrix.Identity;
            CCDrawManager.ProjectionMatrix = Matrix.Identity;

            Matrix projection      = Matrix.CreateOrthographicOffCenter(0, size.Width, 0, size.Height, -1024.0f, 1024.0f);
            Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);

            CCDrawManager.WorldMatrix = (halfPixelOffset * projection);


            /*
             * CCDirector *director = CCDirector::sharedDirector();
             *
             * CCSize    size = director->getWinSizeInPixels();
             *
             * glViewport(0, 0, (GLsizei)(size.width * CC_CONTENT_SCALE_FACTOR()), (GLsizei)(size.height * CC_CONTENT_SCALE_FACTOR()) );
             * kmGLMatrixMode(KM_GL_PROJECTION);
             * kmGLLoadIdentity();
             *
             * kmMat4 orthoMatrix;
             * kmMat4OrthographicProjection(&orthoMatrix, 0, size.width * CC_CONTENT_SCALE_FACTOR(), 0, size.height * CC_CONTENT_SCALE_FACTOR(), -1, 1);
             * kmGLMultMatrix( &orthoMatrix );
             *
             * kmGLMatrixMode(KM_GL_MODELVIEW);
             * kmGLLoadIdentity();
             *
             *
             * ccSetProjectionMatrixDirty();
             */
        }
Пример #9
0
        public void Set2DProjection()
        {
            CCSize size = m_pTexture.ContentSizeInPixels;

            CCDrawManager.SetViewPort(0, 0, (int)size.Width, (int)size.Height);

            CCDrawManager.ViewMatrix       = Matrix.Identity;
            CCDrawManager.ProjectionMatrix = Matrix.Identity;

            Matrix projection      = Matrix.CreateOrthographicOffCenter(0, size.Width, 0, size.Height, -1024.0f, 1024.0f);
            Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);

            CCDrawManager.WorldMatrix = (halfPixelOffset * projection);
        }
Пример #10
0
        /**
         * retract what's done in beforeDraw so that there's no side effect to
         * other nodes.
         */

        private void AfterDraw()
        {
            if (m_bClippingToBounds)
            {
                if (m_bScissorRestored)
                {
                    CCDrawManager.SetScissorInPoints(m_tParentScissorRect.Origin.X, m_tParentScissorRect.Origin.Y, m_tParentScissorRect.Size.Width, m_tParentScissorRect.Size.Height);
                }
                else
                {
                    CCDrawManager.ScissorRectEnabled = false;
                }
            }
        }
Пример #11
0
        private void BeforeDraw()
        {
            CCDirector director = CCDirector.SharedDirector;
            // TODO: Add the RenderTarget support here
            CCPoint screenPos = Parent.ConvertToWorldSpace(Position);

            if (screenPos.X < 0f || screenPos.X > director.WinSize.Width || screenPos.Y < 0f || screenPos.Y > director.WinSize.Height)
            {
                // ScissorRect can not be applied outside of the viewport.
                return;
            }
            float s = Scale;

            s *= director.ContentScaleFactor;

            CCSize winSize = CCDirector.SharedDirector.WinSize;

            CCRect m_tViewSize = BoundingBox; // We always clip to the bounding box
            float  x           = screenPos.X;
            float  y           = winSize.Height - (screenPos.Y + m_tViewSize.Size.Height * s);
            float  scissorW    = m_tViewSize.Size.Width * s;
            float  scissorH    = m_tViewSize.Size.Height * s;

            if (x < 0)
            {
                x = 0f;
            }
            if (y < 0)
            {
                y = 0f;
            }
            if (x + scissorW > winSize.Width)
            {
                scissorW = winSize.Width - x;
            }
            if (y + scissorH > winSize.Height)
            {
                scissorH = winSize.Height - y;
            }
            if (scissorW < 0f || scissorH < 0f)
            {
                return;
            }
            if (x < 0 || y < 0 || (x + scissorW) > winSize.Width || (y + scissorH) > winSize.Height)
            {
            }
            CCDrawManager.ScissorRectEnabled = true;
            CCDrawManager.SetScissorInPoints(x, y, scissorW, scissorH);
        }
Пример #12
0
        public override void Draw()
        {
            Debug.Assert(m_pobBatchNode == null);

            CCDrawManager.BlendFunc(m_sBlendFunc);
            CCDrawManager.BindTexture(Texture);
            CCDrawManager.DrawQuad(ref m_sQuad);

            /*
             * var sb = DrawManager.spriteBatch;
             * sb.Begin(SpriteSortMode.Deferred, null, null, null, null, null, DrawManager.basicEffect.World);
             * sb.Draw(Texture.getTexture2D(), new Vector2(0, 0), new Color(this.Color.r, this.Color.g, this.Color.b, Opacity));
             * sb.End();
             */
        }
Пример #13
0
        public override void Draw()
        {
            if (m_pVertexBuffer == null)
            {
                m_pVertexBuffer = new VertexBuffer(CCDrawManager.graphicsDevice, typeof(VertexPositionColor), 4, BufferUsage.WriteOnly);
            }

            if (m_bChanged)
            {
                m_pVertexBuffer.SetData(m_pVertices);
                m_bChanged = false;
            }

            CCDrawManager.BindTexture((CCTexture2D)null);
            CCDrawManager.BlendFunc(m_tBlendFunc);
            CCDrawManager.DrawQuadsBuffer(m_pVertexBuffer, 0, 1);
        }
Пример #14
0
        private void MakeTexture()
        {
            m_pTexture               = new CCTexture2D();
            m_pTexture.OnReInit      = TextureReInit;
            m_pTexture.IsAntialiased = false;

            m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(m_Width, m_Height, m_ColorFormat, m_DepthFormat, m_Usage);
            m_pTexture.InitWithTexture(m_pRenderTarget2D, m_ColorFormat, true, false);

            m_bFirstUsage = true;

            m_pSprite = new CCSprite(m_pTexture);
            //m_pSprite.scaleY = -1;
            m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend;

            AddChild(m_pSprite);
        }
Пример #15
0
        /// <summary>
        /// draws n quads from an index (offset).
        /// n + start can't be greater than the capacity of the atlas
        /// @since v1.0
        /// </summary>
        public void DrawNumberOfQuads(int n, int start)
        {
            if (n == 0)
            {
                return;
            }

            CCDrawManager.BindTexture(Texture);

            if (Dirty)
            {
                m_pVertexBuffer.UpdateBuffer();
                Dirty = false;
            }

            CCDrawManager.DrawQuadsBuffer(m_pVertexBuffer, start, n);
        }
Пример #16
0
        /// <summary>
        /// draws n quads from an index (offset).
        /// n + start can't be greater than the capacity of the atlas
        /// @since v1.0
        /// </summary>
        public void DrawNumberOfQuads(int n, int start)
        {
            if (n == 0)
            {
                return;
            }

            CCDrawManager.BindTexture(Texture);

            if (Dirty)
            {
                CCDrawManager.SetQuadsToBuffer(m_pVertexBuffer, m_pQuads, 0, m_pQuads.count);
                Dirty = false;
            }

            CCDrawManager.DrawQuadsBuffer(m_pVertexBuffer, start, n);
        }
Пример #17
0
        /**
         * clip this view so that outside of the visible bounds can be hidden.
         */

        private void BeforeDraw()
        {
            if (m_bClippingToBounds)
            {
                CCPoint screenPos = Parent.ConvertToWorldSpace(Position);

                float s = Scale;

                CCDirector director = CCDirector.SharedDirector;
                s *= director.ContentScaleFactor;

                CCSize winSize = CCDirector.SharedDirector.WinSize;

                CCDrawManager.ScissorRectEnabled = true;
                CCDrawManager.SetScissorInPoints(screenPos.X, winSize.Height - (screenPos.Y + m_tViewSize.Height * s), m_tViewSize.Width * s,
                                                 m_tViewSize.Height * s);
            }
        }
Пример #18
0
        /// <summary>
        /// draws n quads from an index (offset).
        /// n + start can't be greater than the capacity of the atlas
        /// @since v1.0
        /// </summary>
        public void DrawNumberOfQuads(int n, int start)
        {
            if (n == 0)
            {
                return;
            }

            CCDrawManager.BindTexture(Texture);
            //CCDrawManager.BlendFunc(new ccBlendFunc(ccMacros.CCDefaultSourceBlending, ccMacros.CCDefaultDestinationBlending));

            if (Dirty)
            {
                CCDrawManager.SetQuadsToBuffer(m_pVertexBuffer, m_pQuads, 0, m_pQuads.count);
                Dirty = false;
            }

            CCDrawManager.DrawQuadsBuffer(m_pVertexBuffer, start, n);
        }
Пример #19
0
        public override void Draw(GameTime gameTime)
        {
            GameTime = gameTime;

            // Begin measuring our Draw method
            //DebugSystem.Instance.TimeRuler.BeginMark("Draw", Color.Red);

            CCDrawManager.BeginDraw();

            CCDirector.SharedDirector.MainLoop(gameTime);

            base.Draw(gameTime);

            CCDrawManager.EndDraw();

            // End measuring our Draw method
            //DebugSystem.Instance.TimeRuler.EndMark("Draw");
        }
Пример #20
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;
            }
        }
Пример #21
0
        protected void PurgeDirector()
        {
            // cleanup scheduler
            Scheduler.UnscheduleAll();

            // don't release the event handlers
            // They are needed in case the director is run again
            m_pTouchDispatcher.RemoveAllDelegates();

            if (m_pRunningScene != null)
            {
                m_pRunningScene.OnExitTransitionDidStart();
                m_pRunningScene.OnExit();
                m_pRunningScene.Cleanup();
            }

            m_pRunningScene = null;
            m_pNextScene    = null;

            // remove all objects, but don't release it.
            // runWithScene might be executed after 'end'.
            m_pobScenesStack.Clear();

            StopAnimation();

            // purge bitmap cache
            CCLabelBMFont.PurgeCachedData();

            // purge all managed caches
            CCAnimationCache.PurgeSharedAnimationCache();
            CCSpriteFrameCache.PurgeSharedSpriteFrameCache();
            CCTextureCache.PurgeSharedTextureCache();
            // CCFileUtils.PurgeFileUtils();
            // CCConfiguration.purgeConfiguration();

            // cocos2d-x specific data structures
            CCUserDefault.PurgeSharedUserDefault();
            // CCNotificationCenter.purgeNotificationCenter();

            CCDrawManager.PurgeDrawManager();

            m_NeedsInit = true;
        }
Пример #22
0
        private Texture2D ConvertSurfaceFormat(Texture2D texture, SurfaceFormat format)
        {
            if (texture.Format == format)
            {
                return(texture);
            }

            var renderTarget = new RenderTarget2D(
                CCDrawManager.GraphicsDevice,
                PixelsWide, PixelsHigh, m_bHasMipmaps, format,
                DepthFormat.None, 0, RenderTargetUsage.DiscardContents
                );

            CCDrawManager.SetRenderTarget(renderTarget);
            CCDrawManager.spriteBatch.Begin();
            CCDrawManager.spriteBatch.Draw(m_Texture2D, new Vector2(0, 0), Color.White);
            CCDrawManager.SetRenderTarget((CCTexture2D)null);

            return(renderTarget);
        }
Пример #23
0
        public override void Draw()
        {
            // Optimization: Fast Dispatch
            if (m_pobTextureAtlas.TotalQuads == 0)
            {
                return;
            }

            if (m_pChildren != null && m_pChildren.count > 0)
            {
                CCNode[] elements = m_pChildren.Elements;
                for (int i = 0, count = m_pChildren.count; i < count; i++)
                {
                    ((CCSprite)elements[i]).UpdateTransform();
                }
            }

            CCDrawManager.BlendFunc(m_blendFunc);

            m_pobTextureAtlas.DrawQuads();
        }
Пример #24
0
        public CCApplication(Game game, IGraphicsDeviceService service)
            : base(game)
        {
            if (Game.Services.GetService(typeof(IGraphicsDeviceService)) == null)
            {
                Game.Services.AddService(typeof(IGraphicsDeviceService), service);
            }

            CCDrawManager.Init(service);

            Content = game.Content;
            HandleMediaStateAutomatically = true;

            game.IsFixedTimeStep = true;

            TouchPanel.EnabledGestures = GestureType.Tap;

            game.Activated   += GameActivated;
            game.Deactivated += GameDeactivated;
            game.Exiting     += GameExiting;
        }
Пример #25
0
        protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage)
        {
            w = (int)Math.Ceiling(w * CCMacros.CCContentScaleFactor());
            h = (int)Math.Ceiling(h * CCMacros.CCContentScaleFactor());

            m_pTexture = new CCTexture2D();
            m_pTexture.IsAntialiased = false;

            m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage);
            m_pTexture.InitWithTexture(m_pRenderTarget2D, colorFormat, true, false);

            m_bFirstUsage = true;

            m_pSprite = new CCSprite(m_pTexture);
            //m_pSprite.scaleY = -1;
            m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend;

            AddChild(m_pSprite);

            return(true);
        }
Пример #26
0
        protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage)
        {
            w = (w * CCMacros.CCContentScaleFactor());
            h = (h * CCMacros.CCContentScaleFactor());

            m_pTexture = new CCTexture2D();
            m_pTexture.SetAliasTexParameters();

            m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage);
            m_pTexture.InitWithTexture(m_pRenderTarget2D);

            m_bFirstUsage = true;

            m_pSprite = new CCSprite(m_pTexture);
            //m_pSprite.scaleY = -1;
            m_pSprite.BlendFunc = new CCBlendFunc(CCMacros.CCDefaultSourceBlending, CCMacros.CCDefaultDestinationBlending); // OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA);

            AddChild(m_pSprite);

            return(true);
        }
        public override void Draw()
        {
            CCDrawManager.BlendFunc(CCBlendFunc.AlphaBlend);
            CCDrawManager.BindTexture(Texture);
            CCDrawManager.DrawQuad(ref m_sQuad);

            //    /*
            //    CC_NODE_DRAW_SETUP();

            //    ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);
            //    ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            //    getShaderProgram()->setUniformForModelViewProjectionMatrix();

            //    glActiveTexture(GL_TEXTURE0);
            //    glBindTexture( GL_TEXTURE_2D, getTexture()->getName());
            //    glUniform1i(m_uTextureLocation, 0);

            //    glActiveTexture(GL_TEXTURE1);
            //    glBindTexture( GL_TEXTURE_2D, m_pMaskTexture->getName() );
            //    glUniform1i(m_uMaskLocation, 1);

            //#define kQuadSize sizeof(m_sQuad.bl)
            //    long offset = (long)&m_sQuad;

            //    // vertex
            //    int diff = offsetof( ccV3F_C4B_T2F, vertices);
            //    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));

            //    // texCoods
            //    diff = offsetof( ccV3F_C4B_T2F, texCoords);
            //    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));

            //    // color
            //    diff = offsetof( ccV3F_C4B_T2F, colors);
            //    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));

            //    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
            //    glActiveTexture(GL_TEXTURE0);
            //    */
        }
Пример #28
0
        private Texture2D ConvertSurfaceFormat(Texture2D texture, SurfaceFormat format)
        {
            if (texture.Format == format)
            {
                return(texture);
            }

            var renderTarget = new RenderTarget2D(
                CCDrawManager.GraphicsDevice,
                texture.Width, texture.Height, m_bHasMipmaps, format,
                DepthFormat.None, 0, RenderTargetUsage.DiscardContents
                );

            CCDrawManager.SetRenderTarget(renderTarget);
            CCDrawManager.Clear(Color.Transparent);
            CCDrawManager.spriteBatch.Begin(SpriteSortMode.Immediate, HasPremultipliedAlpha ? BlendState.AlphaBlend : BlendState.NonPremultiplied);
            CCDrawManager.spriteBatch.Draw(texture, new Vector2(0, 0), Color.White);
            CCDrawManager.spriteBatch.End();
            CCDrawManager.SetRenderTarget((CCTexture2D)null);

            return(renderTarget);
        }
Пример #29
0
        public void Transform()
        {
            CCDrawManager.MultMatrix(NodeToParentTransform(), m_fVertexZ);

            // XXX: Expensive calls. Camera should be integrated into the cached affine matrix
            if (m_pCamera != null && !(m_pGrid != null && m_pGrid.Active))
            {
                bool translate = (m_obAnchorPointInPoints.X != 0.0f || m_obAnchorPointInPoints.Y != 0.0f);

                if (translate)
                {
                    CCDrawManager.Translate(m_obAnchorPointInPoints.X, m_obAnchorPointInPoints.Y, 0);
                }

                m_pCamera.Locate();

                if (translate)
                {
                    CCDrawManager.Translate(-m_obAnchorPointInPoints.X, -m_obAnchorPointInPoints.Y, 0);
                }
            }
        }
Пример #30
0
        public override void Draw()
        {
            if (m_bDirty)
            {
                m_bDirty = false;
                if (FilterPrimitivesByAlpha)
                {
                    _toDraw = m_pVertices.Elements.Where(x => x.Color.A > 0).ToArray();
                }
                else
                {
                    _toDraw = m_pVertices.Elements;
                }
            }

            if (_toDraw != null)
            {
                CCDrawManager.TextureEnabled = false;
                CCDrawManager.BlendFunc(m_sBlendFunc);
                CCDrawManager.DrawPrimitives(PrimitiveType.TriangleList, _toDraw, 0, _toDraw.Length / 3);
            }
        }