Beispiel #1
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 #2
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();
            }
        }
Beispiel #3
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();
            }
        }
        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();
            }
        }