Skip to content

10. Creating a framebuffer

theproadam edited this page Apr 24, 2020 · 7 revisions

Initializing the framebuffer

To create a framebuffer, renderXF needs two things: the main renderXF instance (GL) and the stride (myStride) for each pixel of the frame buffer.

GLFrameBuffer myFrameBuffer = new GLFrameBuffer(GL, myStride);

As GLFrameBuffers take the renderXF instance, the framebuffer is resized automatically whenever the viewport is resized via SetViewportSize().

Getting the raw memory address

It is also possible to get the true memory address via the GetAddress() function.

IntPtr addr = myFrameBuffer.GetAddress();

//Please Ensure The Correct Type Is Used (float, int, char, byte)!
void* vaddr = (void*)myFrameBuffer.GetAddress();
WARNING: THIS ADDRESS CHANGES WHENEVER THE FRAMEBUFFER IS RESIZED BY Resize() OR SetViewportSize(). It will have to be retaken everytime the framebuffer size is changed.

Clearing the framebuffer

To clear a GLFrameBuffer, just the the Clear() function from the renderX instance:

GL.Clear(myFrameBuffer);

Resizing the framebuffer

If for whatever reason, the framebuffer needs to be a different size than the viewport, the Resize() function can change the resolution of the framebuffer. However, it cannot change the stride.

myFrameBuffer.Resize(Width, Height);
WARNING: Unless the framebuffer is first unlinked from the renderX instance, it will automatically be resized upon viewport size change.

Linking and Unlinking the framebuffer

If for whatever reason, the framebuffer needs to be independent of the main renderX instance, it can be unlinked from the main instance through the main instance's UnBindFrameBuffer() function. It can be relinked via the BindFrameBuffer() function.

//Unlinking The Framebuffer:
GL.UnBindFrameBuffer(myFrameBuffer);

//Linking The Framebuffer:
GL.BindFrameBuffer(myFrameBuffer);
Clone this wiki locally