Пример #1
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="context">レンダーコンテキスト</param>
        /// <param name="width">描画に利用するテクスチャの解像度の幅</param>
        /// <param name="height">描画に利用するテクスチャの解像度の高さ</param>
        public GDISpriteBatch(RenderContext context, int width, int height)
        {
            this.Context = context;
            Resize(width, height);
            SpriteEffect      = CGHelper.CreateEffectFx5("Shader\\sprite.fx", context.DeviceManager.Device);
            renderPass        = SpriteEffect.GetTechniqueByIndex(0).GetPassByIndex(0);
            VertexInputLayout = new InputLayout(context.DeviceManager.Device, SpriteEffect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature, SpriteVertexLayout.InputElements);
            SamplerDescription desc = new SamplerDescription();

            desc.Filter   = Filter.MinMagMipLinear;
            desc.AddressU = TextureAddressMode.Wrap;
            desc.AddressV = TextureAddressMode.Wrap;
            desc.AddressW = TextureAddressMode.Wrap;
            sampler       = SamplerState.FromDescription(context.DeviceManager.Device, desc);
            mapedGraphic  = Graphics.FromImage(mapedBitmap);
            BlendStateDescription blendDesc = new BlendStateDescription();

            blendDesc.AlphaToCoverageEnable  = false;
            blendDesc.IndependentBlendEnable = false;
            for (int i = 0; i < blendDesc.RenderTargets.Length; i++)
            {
                blendDesc.RenderTargets[i].BlendEnable           = true;
                blendDesc.RenderTargets[i].SourceBlend           = BlendOption.SourceAlpha;
                blendDesc.RenderTargets[i].DestinationBlend      = BlendOption.InverseSourceAlpha;
                blendDesc.RenderTargets[i].BlendOperation        = BlendOperation.Add;
                blendDesc.RenderTargets[i].SourceBlendAlpha      = BlendOption.One;
                blendDesc.RenderTargets[i].DestinationBlendAlpha = BlendOption.Zero;
                blendDesc.RenderTargets[i].BlendOperationAlpha   = BlendOperation.Add;
                blendDesc.RenderTargets[i].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            }
            ViewMatrix = Matrix.LookAtLH(new Vector3(0, 0, -1), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            state      = BlendState.FromDescription(context.DeviceManager.Device, blendDesc);
            NeedRedraw = true;
            Update();
        }
Пример #2
0
        public D2DSpriteBatch(RenderContext context)
        {
            this.context      = context;
            DeviceManager     = context.DeviceManager;
            SpriteEffect      = CGHelper.CreateEffectFx5FromResource("MMF.Resource.Shader.SpriteShader.fx", DeviceManager.Device);
            renderPass        = SpriteEffect.GetTechniqueByIndex(0).GetPassByIndex(1);
            VertexInputLayout = new InputLayout(DeviceManager.Device, SpriteEffect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature, SpriteVertexLayout.InputElements);
            SamplerDescription desc = new SamplerDescription();

            desc.Filter   = Filter.MinMagMipLinear;
            desc.AddressU = TextureAddressMode.Wrap;
            desc.AddressV = TextureAddressMode.Wrap;
            desc.AddressW = TextureAddressMode.Wrap;
            sampler       = SamplerState.FromDescription(DeviceManager.Device, desc);
            BlendStateDescription blendDesc = new BlendStateDescription();

            blendDesc.AlphaToCoverageEnable  = false;
            blendDesc.IndependentBlendEnable = false;
            for (int i = 0; i < blendDesc.RenderTargets.Length; i++)
            {
                blendDesc.RenderTargets[i].BlendEnable           = true;
                blendDesc.RenderTargets[i].SourceBlend           = BlendOption.SourceAlpha;
                blendDesc.RenderTargets[i].DestinationBlend      = BlendOption.InverseSourceAlpha;
                blendDesc.RenderTargets[i].BlendOperation        = BlendOperation.Add;
                blendDesc.RenderTargets[i].SourceBlendAlpha      = BlendOption.One;
                blendDesc.RenderTargets[i].DestinationBlendAlpha = BlendOption.Zero;
                blendDesc.RenderTargets[i].BlendOperationAlpha   = BlendOperation.Add;
                blendDesc.RenderTargets[i].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            }
            state = BlendState.FromDescription(DeviceManager.Device, blendDesc);

            BlendStateDescription bsd = new BlendStateDescription();

            bsd.RenderTargets[0].BlendEnable           = true;
            bsd.RenderTargets[0].SourceBlend           = BlendOption.SourceAlpha;
            bsd.RenderTargets[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
            bsd.RenderTargets[0].BlendOperation        = BlendOperation.Add;
            bsd.RenderTargets[0].SourceBlendAlpha      = BlendOption.One;
            bsd.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
            bsd.RenderTargets[0].BlendOperationAlpha   = BlendOperation.Add;
            bsd.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            TransParentBlendState = BlendState.FromDescription(DeviceManager.Device, bsd);
            Resize();
        }