Some game engines allow access to the "screen" texture in fragment shaders, which allows for some really cool effects.
For example, GODOT allows this. Having read the documentation, I see it says:
Detect when shaders read from screen texture and automatically copy screen to back-buffer on demand.
I use Libgdx, and would like to do something similar. However, I want to be sure that I'm doing it in the most performant way possible.
Currently, the only way I can think to do this is as follows:
- Create an additional two screen-sized FBOs (FBO1, FBO2)
- Instead of rendering the game to the screen, render everything to FBO1
- When I want to use a shader that needs access to the screen texture, before using the shader, copy FBO1 to FBO2. Pass FBO2 to the shader as a varying.
- Finally, render FBO1 to the screen.
However, this seems like rather a lot of extra copying/rendering.
Is there a better way? - for example, is there some way to access the screen buffer itself, so that I don't have to create FBO1, and can then skip step 4?