Example #1
0
 public void Write(SlimDX.Matrix data)
 {
     unsafe
     {
         SlimDX.Matrix *pPtr = &data;
         Write((IntPtr)pPtr, sizeof(SlimDX.Matrix));
     }
 }
Example #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;
                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();
            }
        }