public void Bind() { if (DummyFrameBuffer == 0) { DummyFrameBuffer = GL.GenFramebuffer(); } GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, DummyFrameBuffer); ImageHandler CachedImage; for (int Attachment = 0; Attachment < RenderTargetsCount; Attachment++) { if (Attachments.Colors[Attachment] == OldAttachments.Colors[Attachment]) { continue; } int Handle = 0; if (Attachments.Colors[Attachment] != 0 && Texture.TryGetImageHandler(Attachments.Colors[Attachment], out CachedImage)) { Handle = CachedImage.Handle; } GL.FramebufferTexture( FramebufferTarget.DrawFramebuffer, FramebufferAttachment.ColorAttachment0 + Attachment, Handle, 0); } if (Attachments.Zeta != OldAttachments.Zeta) { if (Attachments.Zeta != 0 && Texture.TryGetImageHandler(Attachments.Zeta, out CachedImage)) { if (CachedImage.HasDepth && CachedImage.HasStencil) { GL.FramebufferTexture( FramebufferTarget.DrawFramebuffer, FramebufferAttachment.DepthStencilAttachment, CachedImage.Handle, 0); } else if (CachedImage.HasDepth) { GL.FramebufferTexture( FramebufferTarget.DrawFramebuffer, FramebufferAttachment.DepthAttachment, CachedImage.Handle, 0); GL.FramebufferTexture( FramebufferTarget.DrawFramebuffer, FramebufferAttachment.StencilAttachment, 0, 0); } else { throw new NotImplementedException(); } } else { GL.FramebufferTexture( FramebufferTarget.DrawFramebuffer, FramebufferAttachment.DepthStencilAttachment, 0, 0); } } if (OGLExtension.ViewportArray) { GL.ViewportArray(0, 8, Viewports); } else { GL.Viewport( (int)Viewports[0], (int)Viewports[1], (int)Viewports[2], (int)Viewports[3]); } if (Attachments.MapCount > 1) { GL.DrawBuffers(Attachments.MapCount, Attachments.Map); } else if (Attachments.MapCount == 1) { GL.DrawBuffer((DrawBufferMode)Attachments.Map[0]); } else { GL.DrawBuffer(DrawBufferMode.None); } OldAttachments.SetAndClear(Attachments); }
public void Bind() { if (DummyFrameBuffer == 0) { DummyFrameBuffer = GL.GenFramebuffer(); } GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, DummyFrameBuffer); ImageHandler CachedImage; for (int Attachment = 0; Attachment < RenderTargetsCount; Attachment++) { long Key = Attachments.Colors[Attachment]; int Handle = 0; if (Key != 0 && Texture.TryGetImageHandler(Key, out CachedImage)) { Handle = CachedImage.Handle; } if (Handle == ColorHandles[Attachment]) { continue; } GL.FramebufferTexture( FramebufferTarget.DrawFramebuffer, FramebufferAttachment.ColorAttachment0 + Attachment, Handle, 0); ColorHandles[Attachment] = Handle; } if (Attachments.Zeta != 0 && Texture.TryGetImageHandler(Attachments.Zeta, out CachedImage)) { if (CachedImage.Handle != ZetaHandle) { if (CachedImage.HasDepth && CachedImage.HasStencil) { GL.FramebufferTexture( FramebufferTarget.DrawFramebuffer, FramebufferAttachment.DepthStencilAttachment, CachedImage.Handle, 0); } else if (CachedImage.HasDepth) { GL.FramebufferTexture( FramebufferTarget.DrawFramebuffer, FramebufferAttachment.DepthAttachment, CachedImage.Handle, 0); GL.FramebufferTexture( FramebufferTarget.DrawFramebuffer, FramebufferAttachment.StencilAttachment, 0, 0); } else { throw new InvalidOperationException("Invalid image format \"" + CachedImage.Format + "\" used as Zeta!"); } ZetaHandle = CachedImage.Handle; } } else if (ZetaHandle != 0) { GL.FramebufferTexture( FramebufferTarget.DrawFramebuffer, FramebufferAttachment.DepthStencilAttachment, 0, 0); ZetaHandle = 0; } if (OGLExtension.ViewportArray) { GL.ViewportArray(0, RenderTargetsCount, Viewports); } else { GL.Viewport( (int)Viewports[0], (int)Viewports[1], (int)Viewports[2], (int)Viewports[3]); } if (Attachments.MapCount > 1) { GL.DrawBuffers(Attachments.MapCount, Attachments.Map); } else if (Attachments.MapCount == 1) { GL.DrawBuffer((DrawBufferMode)Attachments.Map[0]); } else { GL.DrawBuffer(DrawBufferMode.None); } OldAttachments.Update(Attachments); }