/// <summary>
        /// End the modifier (This method is called by the DrawTarget)
        /// </summary>
        /// <param name="state"></param>
        public void End(DrawState state)
        {
            if (enabledBuffer)
            {
                state.PopPostCuller();
            }

            if (cubes.Count > 0 ||
                spheres.Count > 0)
            {
                state.PushCamera(camera);

                state.PushRenderState();
                state.RenderState.DepthColourCull.DepthWriteEnabled = false;
                state.RenderState.AlphaBlend = AlphaBlendState.Alpha;

                Xen.Ex.Shaders.FillSolidColour shader = state.GetShader <Xen.Ex.Shaders.FillSolidColour>();
                shader.FillColour = new Vector4(1, 1, 1, 0.25f);
                shader.Bind(state);

                GenCubeVS(state);
                GenSphereVS(state);

                Matrix mat;
                for (int i = 0; i < cubes.Count; i++)
                {
                    mat = cubes[i];
                    state.PushWorldMatrix(ref mat);

                    cubeVS.Draw(state, null, PrimitiveType.LineList);

                    state.PopWorldMatrix();
                }

                mat = Matrix.Identity;
                Vector4 v;
                for (int i = 0; i < spheres.Count; i++)
                {
                    v = spheres[i];

                    mat.M11 = v.W;
                    mat.M22 = v.W;
                    mat.M33 = v.W;
                    mat.M41 = v.X;
                    mat.M42 = v.Y;
                    mat.M43 = v.Z;

                    state.PushWorldMatrix(ref mat);

                    sphereVS.Draw(state, null, PrimitiveType.LineList);

                    state.PopWorldMatrix();
                }

                state.PopRenderState();
                state.PopCamera();
            }
        }
Beispiel #2
0
        private void Render(DrawState state)
        {
            SimpleTextureEffect shader = state.GetShader <SimpleTextureEffect>();

            state.PushCamera(camera);

            shader.Texture = _texture;
            shader.Bind(state);

            _vertices.Draw(state, null, PrimitiveType.TriangleStrip);

            state.PopCamera();
        }
Beispiel #3
0
        private void Draw(DrawState state, Vector2 scale, byte clipDepth)
        {
            Element parent = this.parent;


            Matrix         matrix;
            GraphicsDevice device = null;

            if (parent == null)
            {
                if (state.DrawTarget.MultiSampleType != MultiSampleType.None)
                {
                    device = state.BeginGetGraphicsDevice(StateFlag.None);
                    device.RenderState.MultiSampleAntiAlias = false;
                }

                this.clipTestActive = false;

                DeviceRenderState rstate = new DeviceRenderState();
                rstate.DepthColourCull.DepthWriteEnabled = false;
                rstate.DepthColourCull.DepthTestEnabled  = false;

                state.PushRenderState(ref rstate);

                if (camera == null)
                {
                    camera = state.UserValues[cameraID] as Xen.Camera.Camera2D;
                    if (camera == null)
                    {
                        camera = new Xen.Camera.Camera2D(true);
                        state.UserValues[cameraID] = camera;
                    }
                }

                state.PushCamera(camera);
            }
            else
            {
                this.clipTestActive = parent.clipTestActive | parent.ClipsChildren;
            }

            StencilTestState stencilState = new StencilTestState();

            if (clipTestActive)
            {
                stencilState.Enabled              = true;
                stencilState.ReferenceValue       = clipDepth;
                stencilState.StencilFunction      = CompareFunction.Equal;
                stencilState.StencilPassOperation = StencilOperation.Keep;
            }

            bool clearStencil = false;

            if (this.ClipsChildren)
            {
                clearStencil = clipDepth == 255;
                clipDepth--;

                if (!clipTestActive)
                {
                    //check there actually is a stencil buffer
#if DEBUG
                    DepthFormat format = state.DrawTarget.SurfaceDepthFormat ?? DepthFormat.Unknown;

                    if (format != DepthFormat.Depth24Stencil8)
                    {
                        throw new InvalidOperationException("ElementRect.ClipChildren requires the DrawTarget has a valid Depth Buffer with an 8bit Stencil Buffer");
                    }
#endif

                    stencilState.Enabled              = true;
                    stencilState.ReferenceValue       = clipDepth;
                    stencilState.StencilPassOperation = StencilOperation.Replace;
                }
                else
                {
                    stencilState.StencilPassOperation = StencilOperation.Decrement;
                }
            }

            if ((scale.X != 0 && scale.Y != 0))
            {
                Vector2 size = ElementSize;
                GetDisplayMatrix(out matrix, scale, ref size);

                state.PushWorldMatrixMultiply(ref matrix);

                BindShader(state, false);

                state.RenderState.AlphaBlend  = blend;
                state.RenderState.StencilTest = stencilState;


                if (!UseSize)
                {
                    size = new Vector2(1, 1);
                }
                else
                if (IsNormalised)
                {
                    size *= scale;
                }

                PreDraw(size);

                DrawElement(state);

                List <Element> children = Children;
                if (children != null)
                {
                    foreach (Element child in children)
                    {
                        if (((IDraw)child).CullTest(state))
                        {
                            child.Draw(state, size, clipDepth);
                        }
                    }
                }

                if (clearStencil)
                {
                    BindShader(state, true);
                    stencilState                      = new StencilTestState();
                    stencilState.Enabled              = true;
                    stencilState.StencilFunction      = CompareFunction.Never;
                    stencilState.StencilFailOperation = StencilOperation.Zero;
                    state.RenderState.StencilTest     = stencilState;

                    DrawElement(state);
                }

                state.PopWorldMatrix();
            }


            if (parent == null)
            {
                state.PopRenderState();
                state.PopCamera();
            }

            if (device != null)
            {
                device.RenderState.MultiSampleAntiAlias = true;
                state.EndGetGraphicsDevice();
            }
        }
Beispiel #4
0
        public void Render(DrawState state, byte clipDepth)
        {
            Element       parent = _parent;
            Matrix        matrix;
            DeviceContext context = state.Context;

            if (parent == null)
            {
                _clipTest = false;

                DeviceRenderState rstate = new DeviceRenderState();

                rstate.DepthColourCull.DepthWriteEnabled = false;
                rstate.DepthColourCull.DepthTestEnabled  = false;

                state.PushRenderState(ref rstate);

                if (_camera == null)
                {
                    _camera = new ElementCamera(true);
                }

                state.PushCamera(_camera);
            }
            else
            {
                _clipTest = parent._clipTest | parent.ClipsChildren;
            }

            StencilTestState stencilState = new StencilTestState();

            if (_clipTest)
            {
                stencilState.Enabled              = true;
                stencilState.ReferenceValue       = clipDepth;
                stencilState.StencilFunction      = Compare.Equal;
                stencilState.StencilPassOperation = StencilOperation.Keep;
            }

            bool clearStencil = false;

            if (ClipsChildren)
            {
                clearStencil = clipDepth == 255;
                clipDepth--;

                if (!_clipTest)
                {
                    stencilState.Enabled              = true;
                    stencilState.ReferenceValue       = clipDepth;
                    stencilState.StencilPassOperation = StencilOperation.Replace;
                }
                else
                {
                    stencilState.StencilPassOperation = StencilOperation.Decrement;
                }
            }

            Viewport viewport = context.Viewport;
            Vector2  scale    = new Vector2(viewport.Width, viewport.Height);

            if ((scale.X != 0 && scale.Y != 0))
            {
                Vector2 size = ElementSize;
                GetDisplayMatrix(out matrix, scale, ref size);

                state.PushWorldMatrixMultiply(ref matrix);

                BindShader(state, false);

                state.RenderState.AlphaBlend  = _blendState;
                state.RenderState.StencilTest = stencilState;

                if (!UseSize)
                {
                    size = new Vector2(1, 1);
                }
                else if (IsNormalised)
                {
                    size.X *= scale.X;
                    size.Y *= scale.Y;
                }

                PreDraw(state.Context, size);

                DrawElement(state);

                List <Element> children = Children;
                if (children != null)
                {
                    foreach (Element child in children)
                    {
                        if (child.CullTest(state))
                        {
                            child.Render(state, clipDepth);
                        }
                    }
                }

                if (clearStencil)
                {
                    BindShader(state, true);

                    stencilState                      = new StencilTestState();
                    stencilState.Enabled              = true;
                    stencilState.StencilFunction      = Compare.Never;
                    stencilState.StencilFailOperation = StencilOperation.Zero;
                    state.RenderState.StencilTest     = stencilState;

                    DrawElement(state);
                }

                state.PopWorldMatrix();
            }

            if (parent == null)
            {
                state.PopRenderState();
                state.PopCamera();
            }
        }