Exemplo n.º 1
0
        public override void draw()
        {
            base.draw();
            CCApplication application = CCApplication.sharedApplication();

            CCDirector.sharedDirector().getWinSize();
            bool       flag       = (this.m_sBlendFunc.src != ccMacros.CC_BLEND_SRC) || (this.m_sBlendFunc.dst != ccMacros.CC_BLEND_DST);
            BlendState blendState = application.GraphicsDevice.BlendState;

            if (flag)
            {
                BlendState state = new BlendState
                {
                    ColorSourceBlend      = OGLES.GetXNABlend(this.m_sBlendFunc.src),
                    AlphaSourceBlend      = OGLES.GetXNABlend(this.m_sBlendFunc.src),
                    ColorDestinationBlend = OGLES.GetXNABlend(this.m_sBlendFunc.dst),
                    AlphaDestinationBlend = OGLES.GetXNABlend(this.m_sBlendFunc.dst)
                };
                application.GraphicsDevice.BlendState = state;
            }
            if (this.Texture != null)
            {
                application.basicEffect.Texture            = this.Texture.getTexture2D();
                application.basicEffect.TextureEnabled     = true;
                application.basicEffect.Alpha              = ((float)this.Opacity) / 255f;
                application.basicEffect.VertexColorEnabled = true;
            }
            VertexPositionColorTexture[] vertexData = this.m_sQuad.getVertices(ccDirectorProjection.kCCDirectorProjection3D);
            short[] indexData = this.m_sQuad.getIndexes(ccDirectorProjection.kCCDirectorProjection3D);
            foreach (EffectPass pass in application.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                application.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);
            }
            application.basicEffect.VertexColorEnabled = false;
            if (flag)
            {
                BlendState state2 = new BlendState
                {
                    ColorSourceBlend      = OGLES.GetXNABlend(ccMacros.CC_BLEND_SRC),
                    AlphaSourceBlend      = OGLES.GetXNABlend(ccMacros.CC_BLEND_SRC),
                    ColorDestinationBlend = OGLES.GetXNABlend(ccMacros.CC_BLEND_DST),
                    AlphaDestinationBlend = OGLES.GetXNABlend(ccMacros.CC_BLEND_DST)
                };
                application.GraphicsDevice.BlendState = state2;
            }
        }
Exemplo n.º 2
0
        public override void draw()
        {
            base.draw();

            Debug.Assert(!m_bUsesBatchNode);

            CCApplication app  = CCApplication.sharedApplication();
            CCSize        size = CCDirector.sharedDirector().getWinSize();

            bool       newBlend = m_sBlendFunc.src != ccMacros.CC_BLEND_SRC || m_sBlendFunc.dst != ccMacros.CC_BLEND_DST;
            BlendState origin   = app.GraphicsDevice.BlendState;

            if (newBlend)
            {
                BlendState bs = new BlendState();

                bs.ColorSourceBlend      = OGLES.GetXNABlend(m_sBlendFunc.src);
                bs.AlphaSourceBlend      = OGLES.GetXNABlend(m_sBlendFunc.src);
                bs.ColorDestinationBlend = OGLES.GetXNABlend(m_sBlendFunc.dst);
                bs.AlphaDestinationBlend = OGLES.GetXNABlend(m_sBlendFunc.dst);

                app.GraphicsDevice.BlendState = bs;
                //glBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
            }

            if (this.Texture != null)
            {
                app.basicEffect.Texture        = this.Texture.getTexture2D();
                app.basicEffect.TextureEnabled = true;
                if (!newBlend) // @@ TotallyEvil
                {
                    // app.GraphicsDevice.BlendState = BlendState.AlphaBlend;
                }
                app.basicEffect.Alpha = (float)this.Opacity / 255.0f;
                app.basicEffect.VertexColorEnabled = true;
            }

            VertexPositionColorTexture[] vertices = this.m_sQuad.getVertices(ccDirectorProjection.CCDirectorProjection3D);
            short[] indexes = this.m_sQuad.getIndexes(ccDirectorProjection.CCDirectorProjection3D);

            //VertexDeclaration vertexDeclaration = new VertexDeclaration(new VertexElement[]
            //    {
            //        new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
            //        new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Color, 0),
            //        new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
            //    });

            foreach (var pass in app.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                app.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(
                    PrimitiveType.TriangleList,
                    vertices, 0, 4,
                    indexes, 0, 2);
            }

            app.basicEffect.VertexColorEnabled = false;

            if (newBlend)
            {
                BlendState bs = new BlendState();

                bs.ColorSourceBlend      = OGLES.GetXNABlend(ccMacros.CC_BLEND_SRC);
                bs.AlphaSourceBlend      = OGLES.GetXNABlend(ccMacros.CC_BLEND_SRC);
                bs.ColorDestinationBlend = OGLES.GetXNABlend(ccMacros.CC_BLEND_DST);
                bs.AlphaDestinationBlend = OGLES.GetXNABlend(ccMacros.CC_BLEND_DST);

                app.GraphicsDevice.BlendState = bs;

                //glBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
            }
        }