6

I sometimes disable depth buffer writing via glDepthMask(GL_FALSE) during the rendering of a frame. That works perfectly fine on some GPUs (like the Motorola Droid's PowerVR), but on the HTC EVO with the Adreno GPU for example, I end up with the frame buffer being complete garbage (I see traces of the meshes I rendered somewhere, but the entire screen is mostly trashed).

If I force glDepthMask to be true the entire time, everything works fine.

I need glDepthMask to be off during parts of the alpha rendering. What can cause the framebuffer to get destroyed by turning the depth writing off?

EboMike
  • 76,846
  • 14
  • 164
  • 167
  • So what's your question? – Nick Banks Mar 01 '11 at 23:46
  • 1
    Ehm... why is the framebuffer trashed when I disable glDepthMask? – EboMike Mar 01 '11 at 23:46
  • Just happened to us too on every Adreno GPU we could get our hands on (Nexus One, HTC Incredible 2 and XPeria Play). Our solution was to do a glClear(GL_DEPTH_BUFFER_BIT) at the beginning of each frame. The funny thing is we don't even have a depth buffer! Android is so lovely... – hasvn Jul 23 '12 at 15:42
  • `glClear(0);` seemed to do the trick for me. – Thomas Nov 28 '13 at 14:27

3 Answers3

8

The problem was that glDepthMask needs to be true when calling glClearDepth. This apparently only applies to Adreno GPUs, not to PowerVR GPUs.

EboMike
  • 76,846
  • 14
  • 164
  • 167
  • 2
    I was having the same problem; but I never actually invoke glClearDepth(). Instead, I just made sure glDepthMask was true at the end of each frame, and the scene stopped getting trashed. This seems like a bug in either Android or the GPU driver; it's occurred on 3 different Android devices for me. – Raj Advani Oct 01 '11 at 04:17
1

Not sure if this will help, but me wonders if you still need to clear the depth buffer - especially before you disable glDepthMask. I believe that glDepthMask only enables/disable writes, not depth tests. Maybe the GL implementation is still testing against old depth buffer information from a previous render pass and thus only drawing to part of your screen. Then it looks trashed. Some implementations might clear the depth buffer, other might not? Feel to disregard if this suggestion totally misses the mark.

Anyways, hope that helps in some small way.

visualjc
  • 47
  • 1
  • 7
  • Yeah, I'm clearing it before I render the frame. I set everything to 1.0, begin rendering opaque objects with depth write enabled, then do alpha-blended objects with depth-write disabled. Depth tests are on almost all the time. – EboMike Mar 02 '11 at 05:38
0

iPhone4/iOS Simulator. If I do not put glDepthMask to true before the glClear, I get my rendering trashed. I spent two days with this problem, dumping framebuffers to disk, investigating the trace of the whole frame, stepping into the code... This was the only thing that worked.

NEVERMIND. I'm stupid. I was executing a glClear(COLOR | DEPTH) with depth mask = false, so the depth buffer wasn't cleared at all. My first reply was caused by a whole day of debugging :/

ffelagund
  • 121
  • 1
  • 4