コード例 #1
0
        /// <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();
            }
        }
コード例 #2
0
ファイル: TestRendering.cs プロジェクト: nogu3ira/essence-udk
        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();
        }
コード例 #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();
            }
        }
コード例 #4
0
ファイル: Element.cs プロジェクト: nogu3ira/essence-udk
        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();
            }
        }
コード例 #5
0
        public unsafe void Draw(DrawState state)
        {
            DeviceContext context = state.Context;

            context.PerformanceMonitor.StartTimer("World.Draw");

            state.PushCamera(_camera);

            float length = new Vector2(context.Viewport.Width, context.Viewport.Height).Length();

            Vector2 position;

            position.X = Player.Position.X;
            position.Y = Player.Position.Y;

            Vector2 offset = new Vector2(position.X % 8, position.Y % 8);

            int overCellX = (int)Math.Round(position.X, 0, MidpointRounding.AwayFromZero);
            int overCellY = (int)Math.Round(position.Y, 0, MidpointRounding.AwayFromZero);

            int cellNodeX = (int)overCellX / 8;
            int cellNodeY = (int)overCellY / 8;

            int nodesToDraw = (int)Math.Round(length / 44f / 8f, 0, MidpointRounding.AwayFromZero);

            if (nodesToDraw % 2 == 0)
            {
                nodesToDraw++;
            }

            int nodesOverTwo = (int)Math.Round(nodesToDraw / 2f, 0, MidpointRounding.AwayFromZero);

            //int startNodeX = cellNodeX - nodesOverTwo;
            //int startNodeY = cellNodeY - nodesOverTwo;

            //int endNodeX = cellNodeX + nodesOverTwo;
            //int endNodeY = cellNodeY + nodesOverTwo;

            //state.BeginEffect("ColorEffect");

            //if (_stream == null)
            //    _stream = new VertexStream<VertexPositionColor, short>(state.Context, streamSize, (streamSize / 4) * 6);

            //_stream.Begin(PrimitiveType.TriangleList);

            //for (int y = startNodeY; y < endNodeY; y++)
            //{
            //    for (int x = startNodeX; x < endNodeX; x++)
            //    {
            //        for (int ty = 0; ty < 8; ty++)
            //        {
            //            for (int tx = 0; tx < 8; tx++)
            //            {
            //                Vector2 p = new Vector2(x * 8 + tx, y * 8 + ty);
            //                Color4 color = new Color4(0,0,0,1);

            //                if (p.X == overCellX && p.Y == overCellY)
            //                    color.Red = 1;

            //                FragmentLocation location;
            //                _stream.Allocate(VertexFragment.Quad, out location);

            //                VertexPositionColor* vPtr = (VertexPositionColor*)location.Vertices;
            //                ushort* iPtr = (ushort*)location.Indices;

            //                *iPtr++ = (ushort)(location.BaseIndex + 0);
            //                *iPtr++ = (ushort)(location.BaseIndex + 1);
            //                *iPtr++ = (ushort)(location.BaseIndex + 2);
            //                *iPtr++ = (ushort)(location.BaseIndex + 2);
            //                *iPtr++ = (ushort)(location.BaseIndex + 1);
            //                *iPtr = (ushort)(location.BaseIndex + 3);

            //                vPtr->Position.X = p.X;
            //                vPtr->Position.Y = p.Y;
            //                vPtr->Position.Z = 0;
            //                vPtr->Color = color;
            //                vPtr++;
            //                vPtr->Position.X = p.X + 1;
            //                vPtr->Position.Y = p.Y;
            //                vPtr->Position.Z = 0;
            //                vPtr->Color = color;
            //                vPtr++;
            //                vPtr->Position.X = p.X;
            //                vPtr->Position.Y = p.Y + 1;
            //                vPtr->Position.Z = 0;
            //                vPtr->Color = color;
            //                vPtr++;
            //                vPtr->Position.X = p.X + 1;
            //                vPtr->Position.Y = p.Y + 1;
            //                vPtr->Position.Z = 0;
            //                vPtr->Color = color;
            //            }
            //        }
            //    }
            //}

            //state.SetStream(_stream);

            //int primitiveCount;

            //context.CalculatePrimitiveCount(_stream.PrimitiveType, _stream.IndexCount, out primitiveCount);
            //context.DrawIndexedPrimitive(_stream.PrimitiveType, 0, 0, _stream.VertexCount, 0, primitiveCount);

            //state.ReleaseStream();
            //_stream.End();

            //state.EndEffect();
            //state.PopProjectionMatrix();
            //state.PopViewMatrix();

            context.PerformanceMonitor.StopTimer("World.Draw");
        }