public override void DrawSolidPolygon(b2Vec2[] vertices, int vertexCount, b2Color color)
 {
     b2Vec2[] alt = new b2Vec2[vertexCount];
     for (int i = 0; i < vertexCount; i++)
     {
         alt[i] = vertices[i] * PTMRatio + _Center;
     }
     CCDrawingPrimitives.DrawSolidPoly(alt, vertexCount, color);
 }
Exemple #2
0
        public override void DrawSolidPolygon(b2Vec2[] vertices, int vertexCount, b2Color color)
        {
            _list.Count = vertexCount;
            var alt = _list.Elements;

            for (int i = 0; i < vertexCount; i++)
            {
                alt[i] = vertices[i] * PTMRatio + _Center;
            }
            CCDrawingPrimitives.DrawSolidPoly(alt, vertexCount, color);
        }
        public static void Init(GraphicsDevice graphicsDevice)
        {
            CCDrawManager.graphicsDevice = graphicsDevice;

            spriteBatch = new SpriteBatch(graphicsDevice);

            m_defaultEffect = new BasicEffect(graphicsDevice);

            PrimitiveEffect = new BasicEffect(graphicsDevice)
            {
                TextureEnabled     = false,
                VertexColorEnabled = true
            };

            m_DepthEnableStencilState = new DepthStencilState
            {
                DepthBufferEnable      = true,
                DepthBufferWriteEnable = true,
                TwoSidedStencilMode    = true
            };

            m_DepthDisableStencilState = new DepthStencilState
            {
                DepthBufferEnable = false
            };
#if !WINDOWS_PHONE && !XBOX && !WINDOWS && !NETFX_CORE && !PSM
            List <string> extensions = CCUtils.GetGLExtensions();
            foreach (string s in extensions)
            {
                switch (s)
                {
                case "GL_OES_depth24":
                    m_PlatformDepthFormat = DepthFormat.Depth24;
                    break;

                case "GL_IMG_texture_npot":
                    m_AllowNonPower2Textures = true;
                    break;

                case "GL_NV_depth_nonlinear":     // nVidia Depth 16 non-linear
                    m_PlatformDepthFormat = DepthFormat.Depth16;
                    break;

                case "GL_NV_texture_npot_2D_mipmap":     // nVidia - nPot textures and mipmaps
                    m_AllowNonPower2Textures = true;
                    break;
                }
            }
#endif
            PresentationParameters pp = graphicsDevice.PresentationParameters;
            //pp.RenderTargetUsage = RenderTargetUsage.PreserveContents;
            //_renderTarget = new RenderTarget2D(graphicsDevice, pp.BackBufferWidth, (int)pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.PreserveContents);

            m_fScaleY           = 1.0f;
            m_fScaleX           = 1.0f;
            m_eResolutionPolicy = ResolutionPolicy.UnKnown;

            m_obViewPortRect = new CCRect(0, 0, pp.BackBufferWidth, pp.BackBufferHeight);
            m_obScreenSize   = m_obDesignResolutionSize = m_obViewPortRect.Size;

            CCDrawingPrimitives.Init(graphicsDevice);
        }
Exemple #4
0
 public override void DrawSegment(b2Vec2 p1, b2Vec2 p2, b2Color color)
 {
     CCDrawingPrimitives.DrawLine(p1 * PTMRatio + _Center, p2 * PTMRatio + _Center, color);
 }
Exemple #5
0
 public override void DrawCircle(b2Vec2 center, float radius, b2Color color)
 {
     CCDrawingPrimitives.DrawCircle(center * PTMRatio + _Center, radius * PTMRatio, color);
 }
Exemple #6
0
        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--;
        }