public void RenderInstances( GraphicsDevice Device, Shader Effect, Camera Camera, InstanceRenderer.RenderMode Mode) { int uniqueInstances = 0; RenderPass += 1; var frustrum = Camera.GetFrustrum(); foreach (var item in OctTree.EnumerateItems(frustrum)) { if (!item.Visible) { continue; } if (item.RenderPass < RenderPass) { uniqueInstances += 1; Renderer.RenderInstance(item, Device, Effect, Camera, Mode); } item.RenderPass = RenderPass; } Renderer.Flush(Device, Effect, Camera, Mode); GamePerformance.Instance.TrackValueType("Instances Drawn", uniqueInstances); }
/// <summary> /// Creates a screenshot of the game and saves it to a file. /// </summary> /// <param name="filename">The file to save the screenshot to</param> /// <param name="resolution">The width/height of the image</param> /// <returns>True if the screenshot could be taken, false otherwise</returns> public bool TakeScreenshot(string filename, Point resolution) { try { using ( RenderTarget2D renderTarget = new RenderTarget2D(GraphicsDevice, resolution.X, resolution.Y, false, SurfaceFormat.Color, DepthFormat.Depth24)) { var frustum = Camera.GetDrawFrustum(); var renderables = World.EnumerateIntersectingObjects(frustum) .Where(r => r.IsVisible && !World.ChunkManager.IsAboveCullPlane(r.GetBoundingBox())); var oldProjection = Camera.ProjectionMatrix; Matrix projectionMatrix = Matrix.CreatePerspectiveFieldOfView(Camera.FOV, ((float)resolution.X) / resolution.Y, Camera.NearPlane, Camera.FarPlane); Camera.ProjectionMatrix = projectionMatrix; GraphicsDevice.SetRenderTarget(renderTarget); DrawSky(new DwarfTime(), Camera.ViewMatrix, 1.0f, Color.CornflowerBlue); Draw3DThings(new DwarfTime(), DefaultShader, Camera.ViewMatrix); DefaultShader.View = Camera.ViewMatrix; DefaultShader.Projection = Camera.ProjectionMatrix; ComponentRenderer.Render(renderables, new DwarfTime(), World.ChunkManager, Camera, DwarfGame.SpriteBatch, GraphicsDevice, DefaultShader, ComponentRenderer.WaterRenderType.None, 0); InstanceRenderer.Flush(GraphicsDevice, DefaultShader, Camera, InstanceRenderMode.Normal); GraphicsDevice.SetRenderTarget(null); renderTarget.SaveAsPng(new FileStream(filename, FileMode.Create), resolution.X, resolution.Y); GraphicsDevice.Textures[0] = null; GraphicsDevice.Indices = null; GraphicsDevice.SetVertexBuffer(null); Camera.ProjectionMatrix = oldProjection; } } catch (IOException e) { Console.Error.WriteLine(e.Message); return(false); } return(true); }