public override void Draw(GameTime gameTime) { var rs = Game.GraphicsDevice; var cam = Game.GetService <Camera>(); var ls = Game.GetService <LayerService>(); constBuffer.Data.ViewProj = cam.ViewMatrix * cam.ProjMatrix; constBuffer.Data.Zoom = new Vector4(ls.MapLayer.Zoom); constBuffer.Data.Offset = new Vector4(ls.MapLayer.Offset, 0.0f, 0.0f); constBuffer.Data.ViewPosition = new Vector4(cam.CameraMatrix.TranslationVector, 0.0f); constBuffer.UpdateCBuffer(); string signature; drawShader.SetVertexShader((int)BuildingsFlags.BUILDINGS_DRAW, out signature); drawShader.SetGeometryShader((int)BuildingsFlags.BUILDINGS_DRAW); drawShader.SetPixelShader((int)BuildingsFlags.BUILDINGS_DRAW); constBuffer.SetCBufferVS(0); constBuffer.SetCBufferGS(0); constBuffer.SetCBufferPS(0); rs.SetupVertexInput(vertexBuffer, null, signature); rs.SetBlendState(BlendState.Opaque); rs.SetDepthStencilState(DepthStencilState.Default); rs.SetRasterizerState(RasterizerState.CullCCW); rs.Draw(Primitive.PointList, vertexBuffer.Capacity, 0); }
public void Draw3(GameTime gameTime) { var rs = Game.GraphicsDevice; var cam = Game.GetService <Camera>(); //var dr = rs.DebugRender; //dr.DrawBasis(Matrix.Translation(1.0f, 1.0f, 1.0f), 100.0f); //int w = rs.Viewport.Width; //int h = rs.Viewport.Height; //dr.DrawBox(new BoundingBox(new Vector3(0, 0, 0), new Vector3(w, 1000, h)), Color.Green); //dr.DrawPoint(new Vector3(w / 2, 0, h / 2), 2.0f, Color.Red); var numTiles = 1 << (int)Level; int x = (int)(numTiles * CenterPositionMercator.X); int y = (int)(numTiles * CenterPositionMercator.Y); vertexCount = 0; var srvs = new List <Texture2D>(); for (int row = -TilesCountOnLowLevel; row <= TilesCountOnLowLevel; row++) { for (int col = -TilesCountOnLowLevel; col <= TilesCountOnLowLevel; col++) { if (x + col < 0 || x + col > numTiles - 1 || y + row < 0 || y + row > numTiles - 1) { continue; } AddQuad(x + col, y + row, numTiles); srvs.Add(CurrentMapSource.GetTile(x + col, y + row, (int)Level).Tile); } } vertexBuffer.SetData(vertices, 0, vertexCount); constBuffer.Data.ViewProj = cam.GetViewMatrix(StereoEye.Mono) * cam.GetProjectionMatrix(StereoEye.Mono); constBuffer.Data.Zoom = new Vector4(Zoom); constBuffer.Data.Offset = new Vector4(Offset, 0.0f, 0.0f); constBuffer.Data.Padding = new Vector4(); constBuffer.Data.TesAmount = new Vector4(TesselationFactor); constBuffer.UpdateCBuffer(); string signature; shader.SetVertexShader((int)MapFlags.MAP_DRAW); shader.SetHullShader((int)MapFlags.MAP_DRAW); shader.SetDomainShader((int)MapFlags.MAP_DRAW); shader.SetPixelShader((int)MapFlags.MAP_DRAW); constBuffer.SetCBufferVS(0); constBuffer.SetCBufferHS(0); constBuffer.SetCBufferDS(0); constBuffer.SetCBufferPS(0); rs.SetPSSamplerState(0, SamplerState.LinearClamp); rs.SetDSSamplerState(0, SamplerState.LinearClamp); rs.SetupVertexInput(vertexBuffer, null); rs.SetBlendState(BlendState.Opaque); rs.SetDepthStencilState(DepthStencilState.Default); rs.SetRasterizerState(Game.InputDevice.IsKeyDown(Keys.NumPad1) ? RasterizerState.Wireframe : RasterizerState.CullCW); for (int i = 0; i < srvs.Count; i++) { srvs[i].SetPS(0); quads[i].SRV0.SetDS(1); quads[i].SRV1.SetDS(2); quads[i].SRV2.SetDS(3); quads[i].SRV3.SetDS(4); quads[i].SRV0.SetPS(1); quads[i].SRV1.SetPS(2); quads[i].SRV2.SetPS(3); quads[i].SRV3.SetPS(4); rs.Draw(4, 4 * i); //rs.DeviceContext.DomainShader.SetShaderResources(1, new ShaderResourceView[] { null, null, null, null }); //rs.DeviceContext.PixelShader.SetShaderResources(1, new ShaderResourceView[] { null, null, null, null }); } quads.Clear(); srvs.Clear(); //rs.DeviceContext.VertexShader.SetConstantBuffer(0, null); //rs.DeviceContext.HullShader.SetConstantBuffer(0, null); //rs.DeviceContext.DomainShader.SetConstantBuffer(0, null); //rs.DeviceContext.PixelShader.SetConstantBuffer(0, null); // //rs.DeviceContext.PixelShader.SetSampler(0, null); //rs.DeviceContext.DomainShader.SetSampler(0, null); //rs.DeviceContext.PixelShader.SetShaderResource(0, null); // //rs.DeviceContext.VertexShader.Set(null); //rs.DeviceContext.HullShader.Set(null); //rs.DeviceContext.DomainShader.Set(null); //rs.DeviceContext.PixelShader.Set(null); }