Exemple #1
0
 /// <summary>
 /// 今のレンダーターゲットを取得します
 /// </summary>
 /// <returns></returns>
 internal WorkspaceTexture GetRenderTarget()
 {
     if (renderTarget == null)
     {
         renderTarget = Workspace.Get();
     }
     return(renderTarget);
 }
Exemple #2
0
 /// <summary>
 /// ワークスペースのテクスチャの使用をやめます。
 /// </summary>
 /// <param name="texture"></param>
 public void Unuse(WorkspaceTexture texture)
 {
     lock (textures)
     {
         if (usingTextures.Remove(texture))
         {
             textures.Push(texture);
         }
     }
 }
Exemple #3
0
 /// <summary>
 /// コンストラクタです。
 /// </summary>
 /// <param name="device"></param>
 public Workspace(PPDDevice device)
 {
     Device   = device;
     textures = new Stack <WorkspaceTexture>();
     primal   = new WorkspaceTexture(device, this);
     for (var i = 0; i < 8; i++)
     {
         textures.Push(new WorkspaceTexture(device, this));
     }
     usingTextures = new HashSet <WorkspaceTexture>();
 }
Exemple #4
0
 /// <summary>
 /// 破棄します。
 /// </summary>
 protected override void DisposeResource()
 {
     while (textures.Count > 0)
     {
         textures.Pop().DisposeInternal();
     }
     foreach (var texture in usingTextures)
     {
         texture.DisposeInternal();
     }
     usingTextures.Clear();
     if (primal != null)
     {
         primal.Dispose();
         primal = null;
     }
 }
Exemple #5
0
 /// <summary>
 /// ワークスペースのテクスチャを取得します。
 /// </summary>
 /// <returns></returns>
 public WorkspaceTexture Get()
 {
     lock (textures)
     {
         WorkspaceTexture ret;
         if (textures.Count == 0)
         {
             ret = new WorkspaceTexture(Device, this);
         }
         else
         {
             ret = textures.Pop();
         }
         ret.Use();
         usingTextures.Add(ret);
         return(ret);
     }
 }
Exemple #6
0
        internal void DrawInternal(AlphaBlendContext alphaBlendContext, int depth)
        {
            if (Clip != null)
            {
                Clip.GameHost.SetClipping(Clip.PositionX, Clip.PositionY, Clip.Width, Clip.Height);
            }
            if (preScreenFilters.Count > 0)
            {
                device.GetModule <AlphaBlend>().Flush();
                foreach (var filter in preScreenFilters)
                {
                    filter.Filter(device);
                }
            }
            if (BlendMode != BlendMode.None)
            {
                alphaBlendContext.BlendMode = BlendMode;
            }
            alphaBlendContext.SetSRT(Matrix.Transformation2D(ScaleCenter, 0, Scale, RotationCenter, Rotation, Position + Offset), depth);
            alphaBlendContext.SRTDepth = depth;
            for (var i = colorFilters.Count - 1; i >= 0; i--)
            {
                alphaBlendContext.SetFilter(colorFilters[i], alphaBlendContext.FilterCount++);
            }
            var currentAlpha       = alphaBlendContext.Alpha;
            var currentBlendMode   = alphaBlendContext.BlendMode;
            var currentFilterCount = alphaBlendContext.FilterCount;
            var enabledRenderMask  = renderMasks.Where(m => m.Enabled).ToArray();

            WorkspaceTexture renderMaskTexture = null;

            if (enabledRenderMask.Length > 0 && !PPDSetting.Setting.ShaderDisabled)
            {
                device.GetModule <AlphaBlend>().Flush();
                var renderTarget = device.GetRenderTarget();
                renderMaskTexture = device.Workspace.Get();
                device.SetRenderTarget(renderMaskTexture);
                device.Clear();
                DrawImpl(alphaBlendContext);
                device.GetModule <AlphaBlend>().Flush();
                device.SetRenderTarget(renderTarget);
            }
            WorkspaceTexture maskTexture = null;

            if (Mask != null && !PPDSetting.Setting.ShaderDisabled)
            {
                device.GetModule <AlphaBlend>().Flush();
                maskTexture = device.Workspace.Get();
                var renderTarget = device.GetRenderTarget();
                device.SetRenderTarget(maskTexture);
                device.Clear(MaskType == MaskType.Include ? new Color4(0, 0, 0, 0) : new Color4(0, 0, 0, 1));
                using (var handler = device.GetModule <AlphaBlend>().StartMaskGeneration(MaskType))
                {
                    Mask.Draw(device.GetModule <AlphaBlendContextCache>().Clone(alphaBlendContext), depth + 1, 0);
                }
                device.SetRenderTarget(renderTarget);
                alphaBlendContext.MaskTexture = maskTexture.Texture;
            }
            WorkspaceTexture filterTargetTexture = null;
            WorkspaceTexture prevRenderTarget    = null;

            if (currentFilterCount >= 2 && !PPDSetting.Setting.ShaderDisabled)
            {
                device.GetModule <AlphaBlend>().Flush();
                alphaBlendContext.Alpha     = 1;
                alphaBlendContext.BlendMode = BlendMode.Normal;
                filterTargetTexture         = device.Workspace.Get();
                prevRenderTarget            = device.GetRenderTarget();
                device.SetRenderTarget(filterTargetTexture);
                device.Clear(new Color4(0, 0, 0, 0));
            }
            DrawImpl(alphaBlendContext);
            if (currentFilterCount >= 2 && !PPDSetting.Setting.ShaderDisabled)
            {
                device.GetModule <AlphaBlend>().Flush();
                var context = device.GetModule <AlphaBlendContextCache>().Get();
                context.Alpha     = 1;
                context.BlendMode = BlendMode.Normal;
                context.Vertex    = device.GetModule <ShaderCommon>().ScreenVertex;
                context.SetSRT(Matrix.Identity, 0);
                WorkspaceTexture renderedTexture = filterTargetTexture;
                for (var i = currentFilterCount - 2; i >= 0; i--)
                {
                    context.Texture = renderedTexture.Texture;
                    var newRenderTarget = device.Workspace.Get();
                    device.SetRenderTarget(newRenderTarget);
                    context.SetFilter(alphaBlendContext.Filters[i], 0);
                    context.FilterCount = 1;
                    device.GetModule <AlphaBlend>().Draw(device, context);
                    renderedTexture.Dispose();
                    renderedTexture = newRenderTarget;
                    if (i == 0)
                    {
                        context.Alpha       = currentAlpha;
                        context.BlendMode   = currentBlendMode;
                        context.Texture     = renderedTexture.Texture;
                        context.FilterCount = 0;
                        device.SetRenderTarget(prevRenderTarget);
                        device.GetModule <AlphaBlend>().Draw(device, context);
                    }
                }
                if (renderedTexture != null)
                {
                    renderedTexture.Dispose();
                }
            }
            if (enabledRenderMask.Length > 0 && !PPDSetting.Setting.ShaderDisabled)
            {
                device.GetModule <AlphaBlend>().Flush();
                foreach (var renderMask in enabledRenderMask)
                {
                    renderMask.Draw(device, renderMaskTexture);
                }
                if (renderMaskTexture != null)
                {
                    renderMaskTexture.Dispose();
                }
            }
            DrawChildrenImpl(alphaBlendContext, currentAlpha, currentBlendMode, currentFilterCount, depth + 1);
            if (Mask != null && !PPDSetting.Setting.ShaderDisabled)
            {
                alphaBlendContext.MaskTexture = null;
                if (maskTexture != null)
                {
                    maskTexture.Dispose();
                }
            }
            alphaBlendContext.SRTDepth    = depth;
            alphaBlendContext.Alpha       = currentAlpha;
            alphaBlendContext.BlendMode   = currentBlendMode;
            alphaBlendContext.FilterCount = currentFilterCount;
            AfterChildenDraw(alphaBlendContext);
            if (postScreenFilters.Count > 0)
            {
                device.GetModule <AlphaBlend>().Flush();
                foreach (var filter in postScreenFilters)
                {
                    filter.Filter(device);
                }
            }
            if (Clip != null)
            {
                Clip.GameHost.RestoreClipping();
            }
        }
Exemple #7
0
 /// <summary>
 /// サーフェースをコピーします。
 /// </summary>
 /// <param name="src"></param>
 /// <param name="dest"></param>
 internal abstract void StretchRectangle(WorkspaceTexture src, WorkspaceTexture dest);
Exemple #8
0
 /// <summary>
 /// 現在のレンダーターゲットを設定します。
 /// </summary>
 /// <param name="workSpaceTexture"></param>
 internal abstract void SetRenderTarget(WorkspaceTexture workSpaceTexture);
Exemple #9
0
 /// <summary>
 /// リセットします
 /// </summary>
 internal void Reset()
 {
     Workspace.Reset();
     renderTarget = null;
 }