Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
0.8.3:fbo [2021/01/03 18:15] – admin | 0.8.3:fbo [2021/01/03 18:36] (current) – admin | ||
---|---|---|---|
Line 12: | Line 12: | ||
[...] | [...] | ||
// create the buffer and link to a context | // create the buffer and link to a context | ||
- | FDefaultFrameBuf | + | FFBO := TFrameBufferObject.Create(AContext); |
// in case you need a depth and stencil buffer | // in case you need a depth and stencil buffer | ||
- | FDefaultFrameBuf.CreateDepthBuffer(Width, | + | FFBO.CreateDepthBuffer(Width, |
+ | </ | ||
+ | |||
+ | When working with framebuffer objects, you have to bind them before and to unbind afterwards. | ||
+ | <file pascal> | ||
+ | FFBO.Bind(AContext); | ||
+ | try | ||
+ | FFBO.Clear(TRenderTarget.Color_0, | ||
+ | finally | ||
+ | FFBO.Unbind(AContext); | ||
+ | end; | ||
</ | </ | ||
Line 69: | Line 79: | ||
__Caution: | __Caution: | ||
- | The following snippet shows how to attach | + | The following snippet shows how to attach |
<file pascal> | <file pascal> | ||
procedure TMyRenderPass.DoSetupTexturesByViewport(const AContext : TContext3D; | procedure TMyRenderPass.DoSetupTexturesByViewport(const AContext : TContext3D; | ||
const AWidth, AHeight : Integer); | const AWidth, AHeight : Integer); | ||
- | var LCtx : TCustomContextOpenGL; | ||
begin | begin | ||
[...] | [...] | ||
- | | + | |
- | LCtx.DefaultFrameBuf.AttachTexture(AContext, | + | |
end; | end; | ||
</ | </ | ||
Line 83: | Line 92: | ||
=== Using multiple targets === | === Using multiple targets === | ||
- | To use a render target from the framebuffer object, we need to clear it on each rendering step. | + | To use the framebuffer object |
- | After that, we have to activate it for shader usage by the Prepare() method. | + | If you forget to execute |
- | The prepare method will activate all supplied render targets for shader computation. | + | Only color attachments need to be prepared, not stencil or depth buffers. |
- | If you forget to execute | + | |
- | We do this all in the render-pass callback method (DoOnRenderPass), when state is " | + | Notice: when working with render-passes and the embedded TRenderer, this is already done for you. |
+ | But in case you established your own FBO, you enable it the following way. | ||
<file pascal> | <file pascal> | ||
- | [...] | + | procedure TMyRenderPass.DoOnBeginRenderPassSetup( |
- | case AState of | + | |
- | | + | begin |
- | begin | + | |
- | [...] | + | |
- | | + | // bind your framebuffer to use in shaders |
+ | FFBO.Bind(Renderer.SharedContext); | ||
| | ||
- | | + | |
- | FFBO.Clear(Point(AContext.Width, AContext.Height), | + | FFBO.Clear([TRenderTarget.Color_0, TRenderTarget.Depth], |
- | | + | TAlphaColorF.Create(0, |
| | ||
- | | + | |
- | FFBO.Prepare([LTarget]); | + | FFBO.Prepare([TRenderTarget.Color_0]); |
- | end; | + | end; |
- | + | ||
- | [...] | + | |
- | </ | + | |
- | On " | + | procedure TMyRenderPass.DoOnEndRenderPassSetup( |
- | + | | |
- | <file pascal> | + | begin |
- | TRenderPassEventState.OnPassEnd : | + | FFBO.Unbind(Renderer.SharedContext); |
- | begin | + | |
- | [...] | + | inherited; |
- | end; | + | end; |
</ | </ | ||