コード例 #1
0
ファイル: Screen.cs プロジェクト: Hamsand/Swf2XNA
        protected override void DrawChild(DisplayObject d, SpriteBatch batch)
        {
            shaderEffect = shaderMap.ContainsKey(d.DepthGroup) ? shaderMap[d.DepthGroup] : defaultShader;

            if (shaderEffect != lastShader)
            {
                //if (lastShader != null)
                //{
                //    lastShader.End(batch);
                //}

                batch.End();

                lastShader = shaderEffect;
                if (shaderEffect != null)
                {
                    shaderEffect.Begin(batch);
                    shaderEffect = null;
                }
                else
                {
                    batch.Begin(
                         SpriteSortMode.Deferred,
                         BlendState.AlphaBlend, //BlendState.NonPremultiplied,
                         null, //SamplerState.AnisotropicClamp,
                         null, //DepthStencilState.None,
                         null, //RasterizerState.CullNone,
                         null,
                         Stage.SpriteBatchMatrix);
                }
            }

            base.DrawChild(d, batch);
        }
コード例 #2
0
ファイル: Screen.cs プロジェクト: Hamsand/Swf2XNA
        private void SetAttributes()
        {
            System.Reflection.MemberInfo inf = this.GetType();
            System.Attribute[] attrs = System.Attribute.GetCustomAttributes(inf);  // reflection
            foreach (System.Attribute attr in attrs)
            {
                if (attr is ScreenAttribute)
                {
                    ScreenAttribute sa = (ScreenAttribute)attr;
                    if (sa.backgroundColor != 0x000000)
                    {
                        this.color = new Color(
                            ((sa.backgroundColor & 0xFF0000) >> 16) / 255f,
                            ((sa.backgroundColor & 0x00FF00) >> 8) / 255f,
                            ((sa.backgroundColor & 0x0000FF) >> 0) / 255f);
                    }

                    if (sa.depthGroup != 0)
                    {
                        DepthGroup = sa.depthGroup;
                    }

                    if (sa.isPersistantScreen != false)
                    {
                        isPersistantScreen = sa.isPersistantScreen;
                    }
                }
                if (attr is V2DShaderAttribute)
                {
                    V2DShaderAttribute sa = (V2DShaderAttribute)attr;

                    float[] parameters = new float[] { };
                    ConstructorInfo ci = sa.shaderType.GetConstructor(new Type[] { parameters.GetType() });
                    this.defaultShader = (V2DShader)ci.Invoke(
                        new object[]
                            {
                                new float[]{sa.param0, sa.param1, sa.param2, sa.param3, sa.param4}
                            });
                }
            }
        }
コード例 #3
0
ファイル: Screen.cs プロジェクト: Hamsand/Swf2XNA
        public override void Draw(SpriteBatch batch)
        {
            if (defaultShader != null)
            {
                defaultShader.Begin(batch);
            }
            else
            {
                batch.Begin(
                   SpriteSortMode.Deferred,
                   BlendState.AlphaBlend, //BlendState.NonPremultiplied,
                   null, //SamplerState.AnisotropicClamp,
                   null, //DepthStencilState.None,
                   null, //RasterizerState.CullNone,
                   null,
                   Stage.SpriteBatchMatrix);
            }

            base.Draw(batch);

            // this needs to happen for screen (class) level shaders (vs depth group shaders)
            if (lastShader != null)
            {
                lastShader.End(batch);
                lastShader = null;
            }
            else if (defaultShader != null)
            {
                defaultShader.End(batch);
            }
            else
            {
                batch.End();
            }
        }