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