Exemplo n.º 1
0
 public ViewProjectionProvider(bool projection, DrawState state)
 {
     _proj = projection;
     #if DEBUG
     _state = state;
     #endif
 }
Exemplo n.º 2
0
        public void Combine(DrawState state)
        {
            CombineShader shader = state.GetShader<CombineShader>();

            shader.WorldTexture = _worldRenderTarget;
            shader.UITexture = _uiRenderTarget;
            shader.Bind(state);

            _vertices.Draw(state, null, PrimitiveType.TriangleStrip);
        }
        internal void QueueQuad(DrawState state, ref Vector2 tl, ref Vector2 tr, ref Vector2 bl, ref Vector2 br, Texture2D texture)
        {
            if (_currentVertex + 4 >= _vertices.Length)
                Flush(state);

            _vertices[_currentVertex + 0].Position.X = tl.X;
            _vertices[_currentVertex + 0].Position.Y = tl.Y;

            _vertices[_currentVertex + 1].Position.X = bl.X;
            _vertices[_currentVertex + 1].Position.Y = bl.Y;

            _vertices[_currentVertex + 2].Position.X = tr.X;
            _vertices[_currentVertex + 2].Position.Y = tr.Y;

            _vertices[_currentVertex + 3].Position.X = br.X;
            _vertices[_currentVertex + 3].Position.Y = br.Y;

            _currentVertex += 4;
            _textures.Add(texture);
        }
Exemplo n.º 4
0
 protected internal override void End(DrawState state)
 {
 }
Exemplo n.º 5
0
        public Engine(IKernel kernel)
        {
            _kernel = kernel;
            _resouces = new List<IResourceContainer>();
            _updatables = new List<IUpdatable>();
            _renderables = new List<IRenderable>();

            IDeviceProvider deviceProvider = kernel.Get<IDeviceProvider>();

            _form = deviceProvider.RenderForm;
            _form.ResizeBegin += OnResizeBegin;
            _form.ResizeEnd += OnResizeEnd;
            _form.FormClosed += OnFormClosed;
            _form.Resize += new EventHandler(OnFormResize);
            _form.KeyDown += new KeyEventHandler(_form_KeyDown);

            _device = new DeviceEx(deviceProvider.Device.NativePointer);
            _presentParameters = deviceProvider.PresentParameters;
            _totalGameTime = TimeSpan.Zero;
            _lastFrameElapsedGameTime = TimeSpan.Zero;
            _drawState = new DrawState();
            _updateState = new UpdateState();
            _clock = new GameClock();
        }
Exemplo n.º 6
0
 protected abstract void BindShader(DrawState state, bool maskOnly);
Exemplo n.º 7
0
 public void Render(DrawState state)
 {
     if (_enabled)
         Render(state, 255);
 }
Exemplo n.º 8
0
 internal abstract void WarmOverride(DrawState state);
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
 public void EndWorld(DrawState state)
 {
     state.Context.SetRenderTarget(null);
 }
Exemplo n.º 11
0
 public void BeginWorld(DrawState state)
 {
     state.Context.SetRenderTarget(_worldRenderTarget);
     state.Context.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.CornflowerBlue, 1.0f, 0);
 }
Exemplo n.º 12
0
 public void BeginUI(DrawState state)
 {
     state.Context.SetRenderTarget(_uiRenderTarget);
     state.Context.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(0, 0, 0, 0), 1.0f, 0);
 }
Exemplo n.º 13
0
 public abstract void Render(DrawState state);
Exemplo n.º 14
0
        public void Bind(DrawState state)
        {
            for (int i = 0; i < Parameters.Count; i++)
            {
                ShaderParameter parameter = Parameters[i];
                ISemantic semantic;

                if (!string.IsNullOrEmpty(parameter.Semantic) && state.SemanticMappings.TryGetValue(parameter.Semantic, out semantic))
                    semantic.Apply(parameter);
            }

            state.Context.ActivePass = CurrentTechnique.Passes[0];
        }
Exemplo n.º 15
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");
        }
Exemplo n.º 16
0
 internal override void WarmOverride(DrawState state)
 {
 }
Exemplo n.º 17
0
        internal void QueueQuad(DrawState state, Vector2 v1, Vector2 v2, Texture2D texture)
        {
            if (_currentVertex + 4 >= _vertices.Length)
                Flush(state);

            _vertices[_currentVertex + 0].Position.X = v1.X;
            _vertices[_currentVertex + 0].Position.Y = v1.Y;

            _vertices[_currentVertex + 1].Position.X = v1.X;
            _vertices[_currentVertex + 1].Position.Y = v2.Y;

            _vertices[_currentVertex + 2].Position.X = v2.X;
            _vertices[_currentVertex + 2].Position.Y = v1.Y;

            _vertices[_currentVertex + 3].Position.X = v2.X;
            _vertices[_currentVertex + 3].Position.Y = v2.Y;

            _currentVertex += 4;
            _textures.Add(texture);
        }
Exemplo n.º 18
0
        public override void Render(DrawState state)
        {
            if (_textures == null || !_isValid)
                return;

            IRenderer renderer = state.Renderer;

            Vector2 position = _positions[0];
            Vector2 size = _sizes[0];
            Vector2 texCoords = Vector2.One;

            renderer.RenderQuad(ref position, ref size, ref texCoords, _textures[0]);

            position = _positions[1];
            size = _sizes[1];
            texCoords = _texCoords[0];

            renderer.RenderQuad(ref position, ref size, ref texCoords, _textures[1]);

            position = _positions[2];
            size = _sizes[2];
            texCoords = Vector2.One;

            renderer.RenderQuad(ref position, ref size, ref texCoords, _textures[2]);

            position = _positions[3];
            size = _sizes[3];
            texCoords = _texCoords[1];

            renderer.RenderQuad(ref position, ref size, ref texCoords, _textures[3]);

            position = _positions[4];
            size = _sizes[4];
            texCoords = _texCoords[2];

            renderer.RenderQuad(ref position, ref size, ref texCoords, _textures[4]);

            position = _positions[5];
            size = _sizes[5];
            texCoords = _texCoords[1];

            renderer.RenderQuad(ref position, ref size, ref texCoords, _textures[5]);

            position = _positions[6];
            size = _sizes[6];
            texCoords = Vector2.One;

            renderer.RenderQuad(ref position, ref size, ref texCoords, _textures[6]);

            position = _positions[7];
            size = _sizes[7];
            texCoords = _texCoords[0];

            renderer.RenderQuad(ref position, ref size, ref texCoords, _textures[7]);

            position = _positions[8];
            size = _sizes[8];
            texCoords = Vector2.One;

            renderer.RenderQuad(ref position, ref size, ref texCoords, _textures[8]);
        }
Exemplo n.º 19
0
        internal void Flush(DrawState state)
        {
            if (_currentVertex == 0)
                return;

            GraphicsDevice device = state.GraphicsDevice;

            using (var vertexBuffer = new VertexBuffer(device, VertexPositionTexture.VertexDeclaration, _vertices.Length, BufferUsage.None))
            {
                using (var indexBuffer = new IndexBuffer(device, IndexElementSize.SixteenBits, _quadIndices.Length, BufferUsage.None))
                {
                    vertexBuffer.SetData(_vertices, 0, _vertices.Length);
                    indexBuffer.SetData(_quadIndices, 0, _quadIndices.Length);

                    device.Indices = indexBuffer;
                    device.SetVertexBuffer(vertexBuffer);

                    for (int i = 0; i < _textures.Count; i++)
                    {
                        device.Textures[0] = _textures[i];
                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList, i * 4, 0, 4, 0, 2);
                    }

                    device.SetVertexBuffer(null);
                    device.Indices = null;
                }
            }

            _currentVertex = 0;
            _textures.Clear();
        }
Exemplo n.º 20
0
 public void Warm(DrawState state)
 {
     lock (this)
         WarmOverride(state);
 }
Exemplo n.º 21
0
        internal void Begin(DrawState state)
        {
            int w = state.Context.Viewport.Width;
            int h = state.Context.Viewport.Height;

            _dirty |= w != _rtWidth;
            _dirty |= h != _rtHeight;

            _rtWidth = w;
            _rtHeight = h;
            _rtHeightf = (float)h;
            _rtWidthf = (float)w;
        }
Exemplo n.º 22
0
        private void Render(DrawState state)
        {
            if (!IsOpen)
                return;

            //DeviceContext context = state.Context;
            //Viewport viewport = context.Viewport;

            //_vertexStream.Begin(PrimitiveType.TriangleList);

            //float height = _fontFactory.GetFontHeight(FONT_INDEX);
            //float consoleHeight = height * 21;

            //AllocateQuad(0, 0, viewport.Width, consoleHeight);

            //ConsoleLine[] lines = GetHistory(20);
            //Texture2D[] textures = new Texture2D[lines.Length + 2];

            //for (int i = lines.Length - 1; i >= 0; i--)
            //{
            //    Texture2D texture = _fontFactory.GetText(FONT_INDEX, lines[0].Text, 0);

            //    const float x = 5;
            //    float y = consoleHeight - 5 - ((i + 2) * height);

            //    AllocateQuad(x, y, texture.Size.X, texture.Size.Y);

            //    textures[i + 1] = texture;
            //}

            //_vertexStream.Bind();

            //Matrix projection;
            //Matrix.OrthoOffCenterRH(0, viewport.Width, viewport.Height, 0, 0, 1, out projection);

            //state.Context.SetRenderState(RenderState.CullMode, Cull.Clockwise);

            //context.SetStreamSource(0, _vertexStream.VertexBuffer, 0, _vertexStream.VertexStride);
            //context.VertexDeclaration = _vertexStream.VertexDeclaration;
            //context.Indices = _vertexStream.IndexBuffer;

            //_shader.Bind(state);

            //for (int i = 0; i < textures.Length; i++)
            //{
            //    context.SetTexture(0, textures[i]);
            //    _shader.CommitChanges();
            //    context.DrawIndexedPrimitive(PrimitiveType.TriangleList, i * 4, 0, 4, 0, 2);
            //}

            //_vertexStream.End();

            //foreach (Texture texture in textures)
            //    if (texture != null)
            //        texture.Dispose();
        }
Exemplo n.º 23
0
        public void Render(DrawState state)
        {
            if (_projectionDirty)
            {
                _projectionDirty = false;
                Matrix.OrthoOffCenterLH(0, _device.Viewport.Width, _device.Viewport.Height, 0, 0, 1, out _projection);
            }

            state.PushRenderer(_renderer);

            state.Device.SetRenderState(RenderState.AlphaBlendEnable, true);
            state.Device.SetRenderState(RenderState.AlphaTestEnable, true);
            state.Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
            state.Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);

            state.PushProjection(_projection);

            _shader.Begin(state);

            foreach (Element element in _elements)
                element.Render(state);

            state.PopRenderer();
            state.PopProjection();

            _shader.End();
        }
Exemplo n.º 24
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();
            }
        }
Exemplo n.º 25
0
        protected internal override void Begin(DrawState state)
        {
            DeviceContext device = state.Context;

            state.ResetTextures();

            device.SetRenderTarget(0, null);

            Vector2 ws = new Vector2((float)Width, (float)Height);
            if (ws.X != windowSize.X || ws.Y != windowSize.Y)
            {
                windowSize = ws;
                windowSizeChangeIndex = System.Threading.Interlocked.Increment(ref DrawTarget.baseSizeIndex);
            }
        }
Exemplo n.º 26
0
 protected abstract void DrawElement(DrawState state);
Exemplo n.º 27
0
        private void Render(DrawState state)
        {
            _device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0);
            _device.BeginScene();

            foreach (IRenderable renderable in _renderables)
                renderable.Render(state);

            _device.EndScene();

            //state.Device.SetRenderState(RenderState.AlphaBlendEnable, true);
            //state.Device.SetRenderState(RenderState.AlphaTestEnable, true);
            //state.Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
            //state.Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);

            //state.PushProjection(_camera.Projection);

            //_shader.Begin(state);

            //Vector2 cameraOffset = new Vector2(0.5f, 0.5f);
            //Vector2 cameraPosition = state.Camera.Position + cameraOffset;
            //Vector2 viewSize = new Vector2(_presentParameters.BackBufferWidth, _presentParameters.BackBufferHeight);
            //Vector2 tileCounts = new Vector2(viewSize.X / 22, viewSize.Y / 22);

            //Tile centerTile = _maps.Felucca.Tiles.GetLandTile((int)cameraPosition.X, (int)cameraPosition.Y);
            //int centerTileZ = centerTile._z * 4;

            //tileCounts.X = 0.5f; //Math.Min(tileCounts.X, MaxTileDistanceTime2);
            //tileCounts.Y = 0.5f;// Math.Min(tileCounts.Y, MaxTileDistanceTime2);

            //int startX = (int)(cameraPosition.X - tileCounts.X);
            //int startY = (int)(cameraPosition.Y - tileCounts.Y);
            //int endX = (int)(cameraPosition.X + tileCounts.X);
            //int endY = (int)(cameraPosition.Y + tileCounts.Y);

            //Vector2 offset, northVector, eastVector, westVector, southVector, center;

            //float widthInPixels = tileCounts.X * TileStepX;
            //float heightInPixels = tileCounts.Y * TileStepY;

            //for (int y = startY; y < endY; y++)
            //{
            //    offset.X = widthInPixels + (((-tileCounts.X) + (startY - y)) * TileStepY);
            //    offset.Y = heightInPixels + ((tileCounts.Y) + (startY - y)) * TileStepY;

            //    BoundingBox bb;

            //    for (int x = startX; x < endX; x++)
            //    {
            //        Tile tile = _maps.Felucca.Tiles.GetLandTile(x, y);
            //        Tile eastTile = _maps.Felucca.Tiles.GetLandTile(x + 1, y);
            //        Tile southTile = _maps.Felucca.Tiles.GetLandTile(x, y + 1);
            //        Tile southEastTile = _maps.Felucca.Tiles.GetLandTile(x + 1, y + 1);

            //        int tileZ = (tile._z * 4) - centerTileZ;
            //        int eastTileZ = (eastTile._z * 4) - centerTileZ;
            //        int southTileZ = (southTile._z * 4) - centerTileZ;
            //        int southEastTileZ = (southEastTile._z * 4) - centerTileZ;

            //        center.X = offset.X;
            //        center.Y = offset.Y;

            //        northVector.X = center.X;
            //        northVector.Y = center.Y + TileSizeOver2 + tileZ;

            //        eastVector.X = center.X - TileSizeOver2;
            //        eastVector.Y = center.Y + southTileZ;

            //        westVector.X = center.X + TileSizeOver2;
            //        westVector.Y = center.Y + eastTileZ;

            //        southVector.X = center.X;
            //        southVector.Y = (center.Y - TileSizeOver2) + southEastTileZ;

            //        bb.Minimum = new Vector3(eastVector.X, southVector.Y, float.MinValue);
            //        bb.Maximum = new Vector3(westVector.X, northVector.Y, float.MaxValue);

            //        if (_camera.BoundingFrustum.Contains(bb) != ContainmentType.Disjoint)
            //            state.Renderer.RenderQuad(ref northVector, ref eastVector, ref westVector, ref southVector, _textureFactory.CreateLandTexture(tile._id));

            //        HuedTile[] statics = _maps.Felucca.Tiles.GetStaticTiles(x, y);

            //        for (int i = 0; i < statics.Length; i++)
            //        {
            //            HuedTile s = statics[i];
            //            Texture texture = _textureFactory.CreateStaticTexture(s._id);

            //            SurfaceDescription description = texture.GetLevelDescription(0);

            //            int staticHeight = s._z * 4 + centerTileZ - 22;

            //            int height = description.Height;
            //            int width = description.Width;
            //            int widthOver2 = width / 2;

            //            northVector.X = center.X - widthOver2;
            //            northVector.Y = center.Y + height + staticHeight;

            //            eastVector.X = center.X - widthOver2;
            //            eastVector.Y = center.Y + staticHeight;

            //            westVector.X = center.X + widthOver2;
            //            westVector.Y = center.Y + height + staticHeight;

            //            southVector.X = center.X + widthOver2;
            //            southVector.Y = center.Y + staticHeight;

            //            bb.Minimum = new Vector3(eastVector.X, southVector.Y, 0);
            //            bb.Maximum = new Vector3(westVector.X, northVector.Y, 0);

            //            if (_camera.BoundingFrustum.Contains(bb) != ContainmentType.Disjoint)
            //                state.Renderer.RenderQuad(ref northVector, ref eastVector, ref westVector, ref southVector, texture);
            //        }

            //        offset.X += TileStepX;
            //        offset.Y -= TileStepY;
            //    }
            //}

            //state.Flush();
            //state.PopProjection();

            //_shader.End();
            //_device.EndScene();
        }