Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
0.8.3:fbo [2021/01/03 18:15] admin0.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 := TFrameBufferObject.Create(AContext);+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, Height);+FFBO.CreateDepthBuffer(Width, Height)
 +</file> 
 + 
 +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, TAlphaColorF.Create(0, 0, 0, 0), 1, 0); 
 +  finally 
 +    FFBO.Unbind(AContext); 
 +  end;
 </file> </file>
  
Line 69: Line 79:
 __Caution:__ Not all GPU's support all render targets. Some GPU's only support up to 8 targets or less. __Caution:__ Not all GPU's support all render targets. Some GPU's only support up to 8 targets or less.
  
-The following snippet shows how to attach texture / render-target to the default framebuffer object of a render-pass.+The following snippet shows how to attach the previously created texture to our framebuffer object. 
 <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 := Renderer.SharedContext as TCustomContextOpenGL; +  FFBO.AttachTexture(AContext, FMyRenderTargetTexture.GorillaTexture, TRenderTarget.Color_0);
-  LCtx.DefaultFrameBuf.AttachTexture(AContext, FMyRenderTargetTexture.GorillaTexture, TRenderTarget.Color_1);+
 end; end;
 </file> </file>
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 with its attached render-targets, we need to bind, clear and prepare it on each rendering step. 
-After that, we have to activate it for shader usage by the Prepare() method. +If you forget to execute Prepare() only the default target Color_0 will be available for computation
-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 prepare() only the default target Color_0 will be available for computation.+
  
-We do this all in the render-pass callback method (DoOnRenderPass)when state is "TRenderPassEventState.OnPassBegin":+Notice: when working with render-passes and the embedded TRendererthis 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 +  const ACount Integer; const APass : TRenderPass); 
-  TRenderPassEventState.OnPassBegin +begin 
-    begin +  inherited; 
-      [...] +   
-      LTarget := TRenderTarget.Color_1;+  // bind your framebuffer to use in shaders 
 +  FFBO.Bind(Renderer.SharedContext);
                  
-      // clear the specific render target buffer +  // clear the specific render target buffer 
-      FFBO.Clear(Point(AContext.WidthAContext.Height),  +  FFBO.Clear([TRenderTarget.Color_0TRenderTarget.Depth],  
-        LTarget, TAlphaColorF.Create(0, 0, 0, 0), 0, 0);+    TAlphaColorF.Create(0, 0, 0, 1), 1, 0);
              
-      // activate the specific render target buffer for shader +  // activate the specific render target buffer for shader 
-      FFBO.Prepare([LTarget]); +  FFBO.Prepare([TRenderTarget.Color_0]); 
-    end; +end;
-     +
-    [...] +
-</file>+
  
-On "OnPassEnd" state we need to unbind the framebuffer object: +procedure TMyRenderPass.DoOnEndRenderPassSetup( 
- +  const ACount : Integer; const APass : TRenderPass); 
-<file pascal> +begin 
-TRenderPassEventState.OnPassEnd : +  FFBO.Unbind(Renderer.SharedContext); 
-  begin +   
-    [...] +  inherited; 
-  end;+end;
 </file> </file>