PDA

View Full Version : In opengl ES 2.0 is it possible not to clear the depth buffer after each frame?



CalebK
09-02-2016, 02:00 PM
I have a simulation where objects leave trails. To simplify rendering and lower GPU load I do not do this the traditional way. Instead each frame I simply draw a line from where the object was to where it is.

To add the trails I never clear the color buffer I simply slightly fade it to black. As a result, the objects leave trails behind them that fade out.

All of this is done onto an offscreen FBO.

The only problem with this method is the z-order with the objects. I would like it to seem like the entirety of each object is above/below the other objects. However this does not work with my current strategy.

This is because I have to clear the depth buffer each frame, otherwise everything goes black. As a result the new frame is drawn on top of everything, so if I high z-order object crosses paths with a low z order objects trail it looks sorta weird.

In opengl ES 2.0 is it possible not to clear the depth buffer after each frame?