Beispiel #1
0
        public void Begin(SlimDX.Matrix vp, DX11RenderState shapes, DX11RenderState aabb)
        {
            this.shapesRenderState = shapes != null ? shapes : this.defaultRenderState;
            this.aabbRenderState   = aabb != null ? aabb : this.shapesRenderState;

            this.solidColorShader.ApplyCamera(vp);
            context.RenderStateStack.Push(shapesRenderState);
            context.CleanShaderStages();
        }
 public void Render(DX11RenderContext context, DX11RenderSettings settings)
 {
     if (this.FEnabled[0])
     {
         context.CleanShaderStages();
     }
     this.FLayerIn.RenderAll(context, settings);
 }
Beispiel #3
0
        public void Render(DX11RenderContext context)
        {
            if (this.lasthandle != this.Handle)
            {
                if (this.swapchain != null)
                {
                    if (this.swapchain.Contains(context))
                    {
                        this.swapchain.Dispose(context);
                    }
                }
                this.lasthandle = this.Handle;
            }

            if (!this.swapchain.Contains(context))
            {
                this.swapchain[context] = new DX11SwapChain(context, this.Handle,
                                                            SlimDX.DXGI.Format.R8G8B8A8_UNorm, new SampleDescription(1, 0), 60, 1);
            }

            if (this.resized)
            {
                this.swapchain[context].Resize();
            }

            if (this.FEnabled[0])
            {
                context.CurrentDeviceContext.ClearRenderTargetView(this.swapchain[context].RTV, new SlimDX.Color4(0, 0, 0, 0));
            }

            if (this.FIn.PluginIO.IsConnected && this.FEnabled[0])
            {
                int id = this.FIndex[0];
                if (this.FIn[id].Contains(context))
                {
                    context.RenderTargetStack.Push(this.swapchain[context]);
                    var rs = new DX11RenderState();

                    if (FAlpha[0])
                    {
                        rs.Blend = DX11BlendStates.Instance.GetState("Blend");
                        context.CurrentDeviceContext.ClearRenderTargetView(this.swapchain[context].RTV, FInBgColor[0].Color);
                    }
                    context.RenderStateStack.Push(rs);
                    context.CleanShaderStages();

                    context.Primitives.FullTriVS.GetVariableBySemantic("TEXTURE").AsResource().SetResource(this.FIn[id][context].SRV);
                    context.Primitives.FullScreenTriangle.Bind(null);
                    context.Primitives.ApplyFullTri();
                    context.Primitives.FullScreenTriangle.Draw();

                    context.RenderStateStack.Pop();
                    context.RenderTargetStack.Pop();
                    context.CleanUpPS();
                }
            }
        }
Beispiel #4
0
        private void Render(DX11RenderContext context, DX11RenderSettings settings)
        {
            if (this.spreadMax == 0)
            {
                return;
            }

            if (this.FInEnabled[0])
            {
                float w = (float)settings.RenderWidth;
                float h = (float)settings.RenderHeight;
                SharpDX.Direct3D11.DeviceContext shaprdxContext = new SharpDX.Direct3D11.DeviceContext(context.CurrentDeviceContext.ComPointer);

                FontWrapper fw = this.FTextRenderer.IsConnected ? this.FTextRenderer[0][context].FontWrapper : FontWrapperFactory.GetWrapper(context, this.dwFactory);

                var sView = settings.View;
                var sProj = settings.Projection;

                SharpDX.Matrix view       = *(SharpDX.Matrix *) & sView;
                SharpDX.Matrix projection = *(SharpDX.Matrix *) & sProj;


                var objectsettings = this.objectSettings[context];
                objectsettings.IterationCount = 1;
                objectsettings.Geometry       = null;

                for (int i = 0; i < this.textCache.objects.Length; i++)
                {
                    SharpDX.Matrix mat = SharpDX.Matrix.Scaling(1.0f, -1.0f, 1.0f);
                    mat = SharpDX.Matrix.Multiply(mat, view);
                    mat = SharpDX.Matrix.Multiply(mat, projection);

                    objectsettings.DrawCallIndex  = i;
                    objectsettings.WorldTransform = *(SlimDX.Matrix *) & mat;

                    if (settings.ValidateObject(objectsettings))
                    {
                        SlimDX.Color4 color = this.textCache.objects[i].Color;
                        color.Alpha *= SharpDX.MathUtil.Clamp(settings.LayerOpacity, 0.0f, 1.0f);
                        SharpDX.Color4 sdxColor = *(SharpDX.Color4 *) & color;

                        fw.DrawTextLayout(shaprdxContext, new SharpDX.DirectWrite.TextLayout(this.textCache.objects[i].TextLayout.ComPointer), SharpDX.Vector2.Zero,
                                          mat, sdxColor, TextFlags.None);
                    }
                }

                //Apply old states back
                context.RenderStateStack.Apply();
                context.CleanShaderStages();
            }
        }
Beispiel #5
0
 public void Render(IPluginIO pin, DX11RenderContext context, DX11RenderSettings settings)
 {
     if (this.FEnabled[0])
     {
         context.CleanShaderStages();
     }
     if (this.FLayerIn.IsConnected)
     {
         for (int i = 0; i < this.FLayerIn.SliceCount; i++)
         {
             this.FLayerIn[i][context].Render(this.FLayerIn.PluginIO, context, settings);
         }
     }
 }
Beispiel #6
0
        public void Render(IPluginIO pin, DX11RenderContext context, DX11RenderSettings settings)
        {
            if (this.spmax > 0)
            {
                if (this.FEnabled[0])
                {
                    context.CleanShaderStages();

                    quadshader.SetBySemantic("VIEWPROJECTION", settings.ViewProjection);

                    if (this.BeginQuery != null)
                    {
                        this.BeginQuery(context);
                    }

                    bool multisampler = this.FInSamplerState.SliceCount > 1 && this.FInTexture.PluginIO.IsConnected;

                    if (this.FInState.SliceCount > 1 || this.FInTexture.SliceCount > 1 || multisampler)
                    {
                        if (this.FInTexture.PluginIO.IsConnected)
                        {
                            this.RenderTextured(context);
                        }
                        else
                        {
                            this.RenderBasic(context);
                        }
                    }
                    else
                    {
                        if (this.FInTexture.PluginIO.IsConnected)
                        {
                            this.RenderInstancedTextured(context);
                        }
                        else
                        {
                            this.RenderInstanced(context);
                        }
                    }


                    if (this.EndQuery != null)
                    {
                        this.EndQuery(context);
                    }
                }
            }
        }
Beispiel #7
0
        public void Render(DX11RenderContext context)
        {
            if (this.lasthandle != this.Handle)
            {
                if (this.swapchain != null)
                {
                    if (this.swapchain.Contains(context))
                    {
                        this.swapchain.Dispose(context);
                    }
                }
                this.lasthandle = this.Handle;
            }

            if (!this.swapchain.Contains(context))
            {
                this.swapchain[context] = new DX11SwapChain(context, this.Handle,
                                                            SlimDX.DXGI.Format.R8G8B8A8_UNorm, new SampleDescription(1, 0), 60, 1);
            }

            if (this.resized)
            {
                this.swapchain[context].Resize();
            }

            if (this.FEnabled[0])
            {
                context.CurrentDeviceContext.ClearRenderTargetView(this.swapchain[context].RTV, new SlimDX.Color4(0, 0, 0, 0));
            }

            if (this.FIn.IsConnected && this.spreadMax > 0 && this.FEnabled[0])
            {
                int id = this.FIndex[0];
                if (this.FIn[id].Contains(context) && this.FIn[id][context] != null)
                {
                    context.RenderTargetStack.Push(this.swapchain[context]);
                    var rs = new DX11RenderState();

                    if (FAlpha[0])
                    {
                        rs.Blend = DX11BlendStates.Instance.GetState("Blend");
                        context.CurrentDeviceContext.ClearRenderTargetView(this.swapchain[context].RTV, FInBgColor[0].Color);
                    }
                    context.RenderStateStack.Push(rs);
                    context.CleanShaderStages();

                    context.Primitives.FullTriVS.GetVariableBySemantic("TEXTURE").AsResource().SetResource(this.FIn[id][context].SRV);

                    EffectSamplerVariable samplervariable = context.Primitives.FullTriVS.GetVariableByName("linSamp").AsSampler();
                    SamplerState          state           = null;
                    if (this.FInSamplerState.IsConnected)
                    {
                        state = SamplerState.FromDescription(context.Device, this.FInSamplerState[0]);
                        samplervariable.SetSamplerState(0, state);
                    }
                    else
                    {
                        samplervariable.UndoSetSamplerState(0);
                    }

                    context.Primitives.FullScreenTriangle.Bind(null);
                    context.Primitives.ApplyFullTri();
                    context.Primitives.FullScreenTriangle.Draw();

                    context.RenderStateStack.Pop();
                    context.RenderTargetStack.Pop();
                    context.CleanUpPS();
                    samplervariable.UndoSetSamplerState(0);  //undo as can be used in other places

                    if (state != null)
                    {
                        state.Dispose();
                    }
                }
            }
        }
Beispiel #8
0
        private void Render(DX11RenderContext context, DX11RenderSettings settings)
        {
            if (this.spreadMax == 0)
            {
                return;
            }

            if (this.FInEnabled[0])
            {
                float w = (float)settings.RenderWidth;
                float h = (float)settings.RenderHeight;
                SharpDX.Direct3D11.DeviceContext shaprdxContext = new SharpDX.Direct3D11.DeviceContext(context.CurrentDeviceContext.ComPointer);

                FontWrapper fw = this.FTextRenderer.IsConnected ? this.FTextRenderer[0][context].FontWrapper : FontWrapperFactory.GetWrapper(context, this.dwFactory);

                var renderStates = fw.RenderStates;

                float *rawMatPtr;
                int    transformCount;
                this.transformIn.GetMatrixPointer(out transformCount, out rawMatPtr);

                SharpDX.Matrix *matrixPointer       = (SharpDX.Matrix *)rawMatPtr;
                SlimDX.Matrix * slimDxmatrixPointer = (SlimDX.Matrix *)rawMatPtr;

                bool applyState = this.FStateIn.IsConnected;

                var sView = settings.View;
                var sProj = settings.Projection;

                SharpDX.Matrix view       = *(SharpDX.Matrix *) & sView;
                SharpDX.Matrix projection = *(SharpDX.Matrix *) & sProj;

                var objectsettings        = this.objectSettings[context];
                var orderedobjectsettings = this.orderedObjectSettings[context];
                objectsettings.IterationCount = 1;
                objectsettings.Geometry       = null;

                bool       doOrder       = false;
                List <int> orderedSlices = null;
                if (settings.LayerOrder != null && settings.LayerOrder.Enabled)
                {
                    orderedobjectsettings.Clear();
                    for (int i = 0; i < this.spreadMax; i++)
                    {
                        DX11ObjectRenderSettings objSettings = new DX11ObjectRenderSettings();
                        objSettings.DrawCallIndex  = i;
                        objSettings.Geometry       = null;
                        objSettings.IterationCount = 1;
                        objSettings.IterationIndex = 0;
                        objSettings.WorldTransform = slimDxmatrixPointer[i % transformCount];
                        objSettings.RenderStateTag = null;
                        orderedobjectsettings.Add(objSettings);
                    }

                    orderedSlices = settings.LayerOrder.Reorder(settings, orderedobjectsettings);
                    doOrder       = true;
                }

                int drawCount = doOrder ? orderedSlices.Count : this.spreadMax;

                for (int drawIdx = 0; drawIdx < drawCount; drawIdx++)
                {
                    int            idx      = doOrder ? orderedSlices[drawIdx] : drawIdx;
                    SharpDX.Matrix preScale = SharpDX.Matrix.Scaling(1.0f, -1.0f, 1.0f);

                    SharpDX.Matrix sm = matrixPointer[idx % transformCount];

                    SharpDX.Matrix mat = SharpDX.Matrix.Multiply(preScale, sm);
                    mat = SharpDX.Matrix.Multiply(mat, view);
                    mat = SharpDX.Matrix.Multiply(mat, projection);

                    SlimDX.Color4 color = this.FInColor[idx];
                    color.Alpha *= SharpDX.MathUtil.Clamp(settings.LayerOpacity, 0.0f, 1.0f);
                    SharpDX.Color4 sdxColor = *(SharpDX.Color4 *) & color;

                    objectsettings.DrawCallIndex  = idx;
                    objectsettings.WorldTransform = *(SlimDX.Matrix *) & mat;

                    if (settings.ValidateObject(objectsettings))
                    {
                        if (applyState)
                        {
                            var textLayout = this.FLayout[idx];

                            if (textLayout != null)
                            {
                                renderStates.SetStates(shaprdxContext, 0);

                                context.RenderStateStack.Push(this.FStateIn[idx]);

                                fw.DrawTextLayout(shaprdxContext, new SharpDX.DirectWrite.TextLayout(textLayout.ComPointer), SharpDX.Vector2.Zero,
                                                  mat, sdxColor, TextFlags.StatePrepared);

                                context.RenderStateStack.Pop();
                            }
                        }
                        else
                        {
                            var textLayout = this.FLayout[idx];

                            if (textLayout != null)
                            {
                                fw.DrawTextLayout(shaprdxContext, new SharpDX.DirectWrite.TextLayout(textLayout.ComPointer), SharpDX.Vector2.Zero,
                                                  mat, sdxColor, TextFlags.None);
                            }
                        }
                    }
                }

                //Apply old states back
                context.RenderStateStack.Apply();
                context.CleanShaderStages();
            }
        }
Beispiel #9
0
        private void Render(DX11RenderContext context, DX11RenderSettings settings)
        {
            if (this.spreadMax == 0)
            {
                return;
            }

            if (this.FInEnabled[0])
            {
                float w = (float)settings.RenderWidth;
                float h = (float)settings.RenderHeight;
                SharpDX.Direct3D11.DeviceContext shaprdxContext = new SharpDX.Direct3D11.DeviceContext(context.CurrentDeviceContext.ComPointer);

                FontWrapper fw = this.FTextRenderer.IsConnected ? this.FTextRenderer[0][context].FontWrapper : FontWrapperFactory.GetWrapper(context, this.dwFactory);

                var renderStates = fw.RenderStates;

                float *rawMatPtr;
                int    transformCount;
                this.transformIn.GetMatrixPointer(out transformCount, out rawMatPtr);

                SharpDX.Matrix *matrixPointer = (SharpDX.Matrix *)rawMatPtr;

                bool applyState = this.FStateIn.IsConnected;

                var sView = settings.View;
                var sProj = settings.Projection;

                SharpDX.Matrix view       = *(SharpDX.Matrix *) & sView;
                SharpDX.Matrix projection = *(SharpDX.Matrix *) & sProj;

                var objectsettings = this.objectSettings[context];
                objectsettings.IterationCount = 1;
                objectsettings.Geometry       = null;

                for (int i = 0; i < this.spreadMax; i++)
                {
                    SharpDX.Matrix preScale = SharpDX.Matrix.Scaling(1.0f, -1.0f, 1.0f);

                    SharpDX.Matrix sm = matrixPointer[i % transformCount];

                    SharpDX.Matrix mat = SharpDX.Matrix.Multiply(preScale, sm);
                    mat = SharpDX.Matrix.Multiply(mat, view);
                    mat = SharpDX.Matrix.Multiply(mat, projection);

                    SlimDX.Color4  color    = this.FInColor[i];
                    SharpDX.Color4 sdxColor = *(SharpDX.Color4 *) & color;

                    objectsettings.DrawCallIndex  = i;
                    objectsettings.WorldTransform = *(SlimDX.Matrix *) & mat;

                    if (settings.ValidateObject(objectsettings))
                    {
                        if (applyState)
                        {
                            var textLayout = this.FLayout[i];

                            if (textLayout != null)
                            {
                                renderStates.SetStates(shaprdxContext, 0);

                                context.RenderStateStack.Push(this.FStateIn[i]);

                                fw.DrawTextLayout(shaprdxContext, new SharpDX.DirectWrite.TextLayout(textLayout.ComPointer), SharpDX.Vector2.Zero,
                                                  mat, sdxColor, TextFlags.StatePrepared);

                                context.RenderStateStack.Pop();
                            }
                        }
                        else
                        {
                            var textLayout = this.FLayout[i];

                            if (textLayout != null)
                            {
                                fw.DrawTextLayout(shaprdxContext, new SharpDX.DirectWrite.TextLayout(textLayout.ComPointer), SharpDX.Vector2.Zero,
                                                  mat, sdxColor, TextFlags.None);
                            }
                        }
                    }
                }

                //Apply old states back
                context.RenderStateStack.Apply();
                context.CleanShaderStages();
            }
        }
        private void Render(DX11RenderContext context, DX11RenderSettings settings)
        {
            if (this.spreadMax == 0)
            {
                return;
            }

            if (this.FInEnabled[0])
            {
                float w = (float)settings.RenderWidth;
                float h = (float)settings.RenderHeight;

                if (shaprdxContext == null)
                {
                    shaprdxContext = new SharpDX.Direct3D11.DeviceContext(context.CurrentDeviceContext.ComPointer);
                }

                FontWrapper fw = this.FTextRenderer.IsConnected ? this.FTextRenderer[0][context].FontWrapper : FontWrapperFactory.GetWrapper(context, this.dwFactory);

                var renderStates = fw.RenderStates;

                float *rawMatPtr;
                int    transformCount;
                this.transformIn.GetMatrixPointer(out transformCount, out rawMatPtr);

                SharpDX.Matrix *matrixPointer = (SharpDX.Matrix *)rawMatPtr;

                bool applyState = this.FStateIn.IsConnected;

                var sView = settings.View;
                var sProj = settings.Projection;

                SharpDX.Matrix view       = *(SharpDX.Matrix *) & sView;
                SharpDX.Matrix projection = *(SharpDX.Matrix *) & sProj;

                var objectsettings = this.objectSettings[context];
                objectsettings.IterationCount = 1;
                objectsettings.Geometry       = null;

                for (int i = 0; i < this.spreadMax; i++)
                {
                    SharpDX.Matrix preScale = SharpDX.Matrix.Scaling(1.0f, -1.0f, 1.0f);

                    switch (this.FNormalizeInput[i].Index)
                    {
                    case 1: preScale = SharpDX.Matrix.Scaling(1.0f / w, -1.0f / w, 1.0f); break;

                    case 2: preScale = SharpDX.Matrix.Scaling(1.0f / h, -1.0f / h, 1.0f); break;

                    case 3: preScale = SharpDX.Matrix.Scaling(1.0f / w, -1.0f / h, 1.0f); break;
                    }
                    SharpDX.Matrix sm = matrixPointer[i % transformCount];

                    SharpDX.Matrix mat = SharpDX.Matrix.Multiply(preScale, sm);
                    mat = SharpDX.Matrix.Multiply(mat, view);
                    mat = SharpDX.Matrix.Multiply(mat, projection);

                    objectsettings.DrawCallIndex  = i;
                    objectsettings.WorldTransform = *(SlimDX.Matrix *) & mat;


                    if (settings.ValidateObject(objectsettings))
                    {
                        SlimDX.Color4 color = this.FInColor[i];
                        color.Alpha *= SharpDX.MathUtil.Clamp(settings.LayerOpacity, 0.0f, 1.0f);
                        SharpDX.Color4 sdxColor = *(SharpDX.Color4 *) & color;

                        TextFlags flag = TextFlags.NoWordWrapping;

                        if (this.FHorizontalAlignInput[i].Index == 0)
                        {
                            flag |= TextFlags.Left;
                        }
                        else if (this.FHorizontalAlignInput[i].Index == 1)
                        {
                            flag |= TextFlags.Center;
                        }
                        else if (this.FHorizontalAlignInput[i].Index == 2)
                        {
                            flag |= TextFlags.Right;
                        }

                        if (this.FVerticalAlignInput[i].Index == 0)
                        {
                            flag |= TextFlags.Top;
                        }
                        else if (this.FVerticalAlignInput[i].Index == 1)
                        {
                            flag |= TextFlags.VerticalCenter;
                        }
                        else if (this.FVerticalAlignInput[i].Index == 2)
                        {
                            flag |= TextFlags.Bottom;
                        }

                        string font = this.FFontInput[i].Name;

                        if (applyState)
                        {
                            renderStates.SetStates(shaprdxContext, 0);

                            context.RenderStateStack.Push(this.FStateIn[i]);

                            fw.DrawString(shaprdxContext, this.FInString[i], font, this.FInSize[i],
                                          mat, sdxColor, flag | TextFlags.StatePrepared);

                            context.RenderStateStack.Pop();
                        }
                        else
                        {
                            fw.DrawString(shaprdxContext, this.FInString[i], font, this.FInSize[i],
                                          mat, sdxColor, flag);
                        }
                    }
                }

                //Apply old states back
                context.RenderStateStack.Apply();
                context.CleanShaderStages();
            }
        }
Beispiel #11
0
        public void Render(DX11RenderContext context, DX11RenderSettings settings)
        {
            if (this.spmax == 0)
            {
                return;
            }

            if (this.BeginQuery != null)
            {
                this.BeginQuery(context);
            }

            context.CleanShaderStages();
            ShaderDeviceData deviceData = this.shaderData[context];

            context.Primitives.FullScreenTriangle.Bind(null);

            for (int i = 0; i < spmax; i++)
            {
                if (this.FEnabled[i])
                {
                    if (this.FInState.IsConnected)
                    {
                        context.RenderStateStack.Push(this.FInState[i]);
                    }
                    else
                    {
                        this.defaultState.Blend = DX11BlendStates.GetState(this.FInBlendState[i]);
                        context.RenderStateStack.Push(this.defaultState);
                    }

                    if (this.FInSamplerState.IsConnected)
                    {
                        SamplerState state = SamplerState.FromDescription(context.Device, this.FInSamplerState[i]);
                        deviceData.samplerVariable.SetSamplerState(0, state);
                    }
                    else
                    {
                        deviceData.samplerVariable.UndoSetSamplerState(0);
                    }

                    var color = this.FInColor[i];
                    color.Alpha *= settings.LayerOpacity;

                    deviceData.colorVariable.Set(color);
                    deviceData.texTransformVariable.SetMatrix(this.FInTexTransform[i]);

                    if (this.FInTexture.IsConnected)
                    {
                        if (this.FInTexture[i].Contains(context) && this.FInTexture[i][context] != null)
                        {
                            deviceData.inputTextureVariable.SetResource(this.FInTexture[i][context].SRV);
                        }
                        else
                        {
                            deviceData.inputTextureVariable.SetResource(null);
                        }
                    }
                    else
                    {
                        deviceData.inputTextureVariable.SetResource(context.DefaultTextures.WhiteTexture.SRV);
                    }


                    deviceData.pass.Apply(context.CurrentDeviceContext);
                    context.CurrentDeviceContext.Draw(3, 0);

                    context.RenderStateStack.Pop();
                }
            }

            if (this.EndQuery != null)
            {
                this.EndQuery(context);
            }
        }