+#include "glformats.h"
#include "glheader.h"
#include "clear.h"
#include "context.h"
* hook instead.
*/
const GLclampd clearSave = ctx->Depth.Clear;
- ctx->Depth.Clear = *value;
+
+ /* Page 263 (page 279 of the PDF) of the OpenGL 3.0 spec says:
+ *
+ * "If buffer is DEPTH, drawbuffer must be zero, and value points
+ * to the single depth value to clear the depth buffer to.
+ * Clamping and type conversion for fixed-point depth buffers are
+ * performed in the same fashion as for ClearDepth."
+ */
+ const struct gl_renderbuffer *rb =
+ ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+ const bool is_float_depth =
+ _mesa_has_depth_float_channel(rb->InternalFormat);
+ ctx->Depth.Clear = is_float_depth ? *value : SATURATE(*value);
+
ctx->Driver.Clear(ctx, BUFFER_BIT_DEPTH);
ctx->Depth.Clear = clearSave;
}