glClear

I’m unable to find complete documentation about that.

My guess is that most tutorials show wrong usage of states:

my assumption:

only write masks enable/disable clearing a buffer

so to clear stencil:

glStencilMask(GL_TRUE);
glClear(GL_STENCIL_BUFFER_BIT);

to clear depth:

glDepthMask(GL_TRUE);
glClear(GL_DETPH_BUFFER_BIT);

to clear color:

glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT);

if that is true than it is NOT mandatory enabling tests right?

Most tutorials show

glEnable(GL_STENCIL_TEST);
glClear(GL_STENCIL_BUFFER_BIT);

or

glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);

Then the tutorials accidentaly work because MASKS by default are true right?

I’m unable to find complete documentation about that.

The OpenGL Wiki seems to cover it well enough.

if that is true than it is NOT mandatory enabling tests right?

Well, if you don’t enable the tests, it doesn’t matter if the buffer is cleared or not. Right? :wink:

Generally speaking, the tutorials aren’t saying that you need to enable the test before you clear the buffer. They’re saying that, if you want to actually do depth buffering, you need to both enable the depth test and clear the depth buffer to a known value. And since these are things that are usually done once-per-frame, as part of per-frame initialization, the lines have a tendency to be near one another.

Most tutorials will also put glClearColor/Depth/Stencil lines before glClear as well.

As for write masks, yes by default they’re on. But most tutorials don’t bother talking about them, because they’re only useful in a few specific circumstances.

MY RENDERING LOOP:

  1. clear all buffers at once (color,depth,stencil)
  2. Z pre-pass
  3. render regular stuff
  4. render to stencil holes (make holes for cave entrances)
  5. render entrances
  6. particles
  7. gui (color only)

as you see when I clear buffers I have both depth and stencil tests disabled.

Of course if later I need even more stenciling is possible I have to clear stencil in middle
of rendering loop but actually I don’t have those in same lines.

My doubt Is If I should enable Depth and stencil tests just for clearing the buffers, actually
my code works without enabling them, however it could be possible my videodrivers are just “permissive”
and the same code won’t work on a different machine. I always check specifications twice, however sometimes
they miss details like this one.

[QUOTE=DarioCiao!;1279469]MY RENDERING LOOP:

  1. clear all buffers at once (color,depth,stencil)
  2. Z pre-pass
  3. render regular stuff
  4. render to stencil holes (make holes for cave entrances)
  5. render entrances
  6. particles
  7. gui (color only)

as you see when I clear buffers I have both depth and stencil tests disabled.[/quote]

Actually, I don’t see that at all. You don’t say where tests are enabled or disabled. Indeed, depending on what some of those mean, I don’t see any rendering where you would disable the depth test. Even GUIs can benefit from depth testing.

No. You need to enable testing when rendering primitives where you want that testing.

[QUOTE=DarioCiao!;1279469]I always check specifications twice, however sometimes
they miss details like this one. [/quote]

The specification is quite clear; no detail has been missed. The assumed default case is that separate pieces of state are separate and therefore don’t interact.

Ergo, if the description of glClear does not say that it is affected by the enabling of various tests, then it is not affected by it. Note that the page there explicitly states that clearing is affected by write masks, the current clear colors, and so forth. But the enable states for tests are not mentioned.

Thus, they don’t affect the result.

Ok thanks that saves me few GL calls :o

[QUOTE=Alfonse Reinheart;1279470]Actually, I don’t see that at all. You don’t say where tests are enabled or disabled. Indeed, depending on what some of those mean, I don’t see any rendering where you would disable the depth test. Even GUIs can benefit from depth testing.
[/QUOTE]

If I don’t forgot anything here are main pipeline configurations:

  1. disableBlending
  2. clear buffers
  3. enableDepthTesting && enableDepthWrite && disableColorWriting
  4. disableDepthWrite && enableColorWrite
  5. disableDepthTesting && disableColorWrite && enableStencilTest && enableDepthWrite
  6. enableColorWrite && enableDepthTesting && disableDepthWrite
    7a) enableDepthWrite && disableStencilTest // solid particles
    7b) disableDepthWrite && enableBlending //transparent and additive particles
  7. enableBlending // transparent