public virtual void OnPreDraw() { if (Settings.EnabledGameObjects == RenderRequestGameObject.None) { return; } var gridView = GridView; // The value might have changed if (Settings.EnabledGameObjects.HasFlag(RenderRequestGameObject.TileLayers)) { // Start asynchronous copying of tile types int tileCount = gridView.Size.Size(); for (int i = 0; i < m_toRender.Length; i++) { // Store data directly to device memory m_tileTypesBuffer.Bind(); IntPtr bufferPtr = GL.MapBuffer(m_tileTypesBuffer.Target, BufferAccess.WriteOnly); m_toRender[i].GetTileTypesAt(gridView, bufferPtr, tileCount, i * tileCount); GL.UnmapBuffer(m_tileTypesBuffer.Target); // Start async copying to the texture m_tileTypesBuffer.Bind(BufferTarget.PixelUnpackBuffer); TileTypesTexure.Update1D(tileCount, dataType: PixelType.UnsignedShort, offset: i * tileCount, byteDataOffset: i * tileCount * sizeof(ushort)); } } }
public override void Draw(RendererBase <ToyWorld> renderer, ToyWorld world) { if (Settings.CopyMode == RenderRequestImageCopyingMode.None) { return; } // Gather data to host mem Owner.FrontFbo.Bind(); switch (Settings.CopyMode) { case RenderRequestImageCopyingMode.DefaultFbo: GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0); GL.BlitFramebuffer( 0, 0, Owner.FrontFbo.Size.X, Owner.FrontFbo.Size.Y, 0, 0, renderer.Width, renderer.Height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest); break; case RenderRequestImageCopyingMode.OpenglPbo: Pbo.Bind(); GL.ReadBuffer(ReadBufferMode.ColorAttachment0); // Works for fbo bound to Framebuffer (not DrawFramebuffer) //Owner.FrontFbo[FramebufferAttachment.ColorAttachment0].Copy2D(PixelType.UnsignedByte); // This is half as fast as ReadPixels for color data GL.ReadPixels(0, 0, Owner.Resolution.Width, Owner.Resolution.Height, PixelFormat.Bgra, PixelType.UnsignedByte, default(IntPtr)); if (Settings.CopyDepth) { DepthPbo.Bind(); Owner.FrontFbo[FramebufferAttachment.DepthAttachment].Copy2D(PixelType.Float); // This is twice as fast as ReadPixels for depth texture //GL.ReadPixels(0, 0, Owner.Resolution.Width, Owner.Resolution.Height, PixelFormat.DepthComponent, PixelType.UnsignedInt, default(IntPtr)); } break; case RenderRequestImageCopyingMode.Cpu: GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); GL.ReadBuffer(ReadBufferMode.ColorAttachment0); // Works for fbo bound to Framebuffer (not DrawFramebuffer) GL.ReadPixels(0, 0, Owner.Resolution.Width, Owner.Resolution.Height, PixelFormat.Bgra, PixelType.UnsignedByte, RenderedScene); if (Settings.CopyDepth) { Owner.FrontFbo[FramebufferAttachment.DepthAttachment].Copy2D(PixelType.Float, RenderedSceneDepth); } break; } }