Update examples to use new framebuffer apis #1616
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1. Create the targets
There are two types of targets:
1. Buffer target : render to a buffer
To create this target you need to specify a valid format
2. Texture target : render to a texture
To create this target you need a valid texture, you might use an existing texture, or create a new one:
Note: we use this constructor to specify width,height and format, since those parameters are required by the renderer ( we cannot render on something of which we don't know sizes or format). You can also use the constructor that takes
int numSamples
, if you want to render on a multisample texture.You can then create a target
Note: the type differs from the previous one ( FrameBufferTextureTarget vs FrameBufferBufferTarget) as you can guess, there are two overloaded newTarget methods one that takes Texture and outputs FrameBufferTextureTarget and one that takes Format and outputs FrameBufferBufferTarget .
2. Attach everything to the framebuffer
Once you have your targets, you can attach them to the framebuffer
Firstly we create the framebuffer
Note: if we are using texture targets, they must be of the same size of the framebuffer and have the same number of samples (>1 for multisample textures), in this case we have 512x512 textures without multisample (=1 sample), that's why we are passing those params.
Then we attach the targets
We can have many color targets, just attach all of them with addColorTarget in the correct order.
3. Additional settings
A MRT compatible shader will now be able to render on multiple color targets at the same time
Everything that is rendered to this framebuffer will be converted from linear to sRGB space.