private void SetupFramebuffers(List <FrameBufferRef> mainBuffers) { if (_frameBuffer != null) { _platform.DisposeFrameBuffer(_frameBuffer); _frameBuffer = null; } var ssao = ClientSettings.SSAOQuality > 0; if (!ssao || !_enabled) { return; } var fbPrimary = mainBuffers[(int)EnumFrameBuffer.Primary]; var fbWidth = (int)(_platform.window.Width * ClientSettings.SSAA); var fbHeight = (int)(_platform.window.Height * ClientSettings.SSAA); if (fbWidth == 0 || fbHeight == 0) { return; } var fb = new FrameBufferRef { FboId = GL.GenFramebuffer(), Width = fbWidth, Height = fbHeight, ColorTextureIds = ArrayUtil.CreateFilled(2, _ => GL.GenTexture()) }; GL.BindFramebuffer(FramebufferTarget.Framebuffer, fb.FboId); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, fbPrimary.DepthTextureId, 0); fb.SetupColorTexture(0); fb.SetupColorTexture(1); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment2, TextureTarget.Texture2D, fbPrimary.ColorTextureIds[2], 0); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment3, TextureTarget.Texture2D, fbPrimary.ColorTextureIds[3], 0); GL.DrawBuffers(4, new [] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3 }); Framebuffers.CheckStatus(); _frameBuffer = fb; _screenQuad = _platform.GetScreenQuad(); }
public void SetupFramebuffers(List <FrameBufferRef> mainBuffers) { _mod.Mod.Logger.Event("Recreating framebuffers"); for (var i = 0; i < _framebuffers.Length; i++) { if (_framebuffers[i] == null) { continue; } _platform.DisposeFrameBuffer(_framebuffers[i]); _framebuffers[i] = null; } // create new framebuffer _fbWidth = (int)(_platform.window.Width * ClientSettings.SSAA); _fbHeight = (int)(_platform.window.Height * ClientSettings.SSAA); if (_fbWidth == 0 || _fbHeight == 0) { return; } var framebuffer = new FrameBufferRef { FboId = GL.GenFramebuffer(), Width = _fbWidth, Height = _fbHeight, DepthTextureId = GL.GenTexture() }; GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer.FboId); framebuffer.SetupDepthTexture(); // create our normal and position textures framebuffer.ColorTextureIds = ArrayUtil.CreateFilled(_refractionsEnabled ? 4 : 3, _ => GL.GenTexture()); // bind and setup textures framebuffer.SetupVertexTexture(0); framebuffer.SetupVertexTexture(1); framebuffer.SetupColorTexture(2); if (_refractionsEnabled) { framebuffer.SetupVertexTexture(3); } if (_refractionsEnabled) { GL.DrawBuffers(4, new[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3 }); } else { GL.DrawBuffers(3, new[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2 }); } Framebuffers.CheckStatus(); _framebuffers[(int)EnumSSRFB.SSR] = framebuffer; // setup output framebuffer framebuffer = new FrameBufferRef { FboId = GL.GenFramebuffer(), Width = _fbWidth, Height = _fbHeight }; GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer.FboId); framebuffer.ColorTextureIds = new[] { GL.GenTexture() }; framebuffer.SetupColorTexture(0); GL.DrawBuffer(DrawBufferMode.ColorAttachment0); Framebuffers.CheckStatus(); _framebuffers[(int)EnumSSRFB.Out] = framebuffer; if (_causticsEnabled) { framebuffer = new FrameBufferRef { FboId = GL.GenFramebuffer(), Width = _fbWidth, Height = _fbHeight }; GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer.FboId); framebuffer.ColorTextureIds = new[] { GL.GenTexture() }; framebuffer.SetupSingleColorTexture(0); GL.DrawBuffer(DrawBufferMode.ColorAttachment0); Framebuffers.CheckStatus(); _framebuffers[(int)EnumSSRFB.Caustics] = framebuffer; } _screenQuad = _platform.GetScreenQuad(); }