public void AllocateRenderTarget() { GL.GenFramebuffers(1, out m_frameBuffer); GLWrapper.BindFramebuffer(m_frameBuffer); GL.FramebufferTexture2D(All.Framebuffer, All.ColorAttachment0, All.Texture2D, m_texture, 0); if (DepthFormat != 0) { GL.GenRenderbuffers(1, out m_depthBuffer); GL.BindRenderbuffer(All.Renderbuffer, m_depthBuffer); GL.RenderbufferStorage(All.Renderbuffer, GLWrapper.TranslateDepthFormat(DepthFormat), base.Width, base.Height); GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment, All.Renderbuffer, m_depthBuffer); GL.FramebufferRenderbuffer(All.Framebuffer, All.StencilAttachment, All.Renderbuffer, 0); } else { GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment, All.Renderbuffer, 0); GL.FramebufferRenderbuffer(All.Framebuffer, All.StencilAttachment, All.Renderbuffer, 0); } FramebufferErrorCode framebufferErrorCode = (FramebufferErrorCode)GL.CheckFramebufferStatus(All.Framebuffer); if (framebufferErrorCode != FramebufferErrorCode.FramebufferComplete) { throw new InvalidOperationException($"Error creating framebuffer ({framebufferErrorCode.ToString()})."); } }
public void GetData <T>(T[] target, int targetStartIndex, Rectangle sourceRectangle) where T : struct { VerifyParametersGetData(target, targetStartIndex, sourceRectangle); GCHandle gCHandle = GCHandle.Alloc(target, GCHandleType.Pinned); try { GLWrapper.BindFramebuffer(m_frameBuffer); GL.ReadPixels(sourceRectangle.Left, sourceRectangle.Top, sourceRectangle.Width, sourceRectangle.Height, All.Rgba, All.UnsignedByte, gCHandle.AddrOfPinnedObject()); } finally { gCHandle.Free(); } }