2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
28 * glClearColor, glClearIndex, glClear() functions.
46 _mesa_ClearIndex( GLfloat c
)
48 GET_CURRENT_CONTEXT(ctx
);
50 ctx
->Color
.ClearIndex
= (GLuint
) c
;
55 * Specify the clear values for the color buffers.
57 * \param red red color component.
58 * \param green green color component.
59 * \param blue blue color component.
60 * \param alpha alpha component.
65 _mesa_ClearColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
67 GET_CURRENT_CONTEXT(ctx
);
69 ctx
->Color
.ClearColor
.f
[0] = red
;
70 ctx
->Color
.ClearColor
.f
[1] = green
;
71 ctx
->Color
.ClearColor
.f
[2] = blue
;
72 ctx
->Color
.ClearColor
.f
[3] = alpha
;
77 * GL_EXT_texture_integer
80 _mesa_ClearColorIiEXT(GLint r
, GLint g
, GLint b
, GLint a
)
82 GET_CURRENT_CONTEXT(ctx
);
84 ctx
->Color
.ClearColor
.i
[0] = r
;
85 ctx
->Color
.ClearColor
.i
[1] = g
;
86 ctx
->Color
.ClearColor
.i
[2] = b
;
87 ctx
->Color
.ClearColor
.i
[3] = a
;
92 * GL_EXT_texture_integer
95 _mesa_ClearColorIuiEXT(GLuint r
, GLuint g
, GLuint b
, GLuint a
)
97 GET_CURRENT_CONTEXT(ctx
);
99 ctx
->Color
.ClearColor
.ui
[0] = r
;
100 ctx
->Color
.ClearColor
.ui
[1] = g
;
101 ctx
->Color
.ClearColor
.ui
[2] = b
;
102 ctx
->Color
.ClearColor
.ui
[3] = a
;
107 * Returns true if color writes are enabled for the given color attachment.
109 * Beyond checking ColorMask, this uses _mesa_format_has_color_component to
110 * ignore components that don't actually exist in the format (such as X in
114 color_buffer_writes_enabled(const struct gl_context
*ctx
, unsigned idx
)
116 struct gl_renderbuffer
*rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[idx
];
120 for (c
= 0; c
< 4; c
++) {
121 if (GET_COLORMASK_BIT(ctx
->Color
.ColorMask
, idx
, c
) &&
122 _mesa_format_has_color_component(rb
->Format
, c
)) {
135 * \param mask bit-mask indicating the buffers to be cleared.
137 * Flushes the vertices and verifies the parameter.
138 * If __struct gl_contextRec::NewState is set then calls _mesa_update_state()
139 * to update gl_frame_buffer::_Xmin, etc. If the rasterization mode is set to
140 * GL_RENDER then requests the driver to clear the buffers, via the
141 * dd_function_table::Clear callback.
143 static ALWAYS_INLINE
void
144 clear(struct gl_context
*ctx
, GLbitfield mask
, bool no_error
)
146 FLUSH_VERTICES(ctx
, 0);
147 FLUSH_CURRENT(ctx
, 0);
150 if (mask
& ~(GL_COLOR_BUFFER_BIT
|
151 GL_DEPTH_BUFFER_BIT
|
152 GL_STENCIL_BUFFER_BIT
|
153 GL_ACCUM_BUFFER_BIT
)) {
154 _mesa_error( ctx
, GL_INVALID_VALUE
, "glClear(0x%x)", mask
);
158 /* Accumulation buffers were removed in core contexts, and they never
159 * existed in OpenGL ES.
161 if ((mask
& GL_ACCUM_BUFFER_BIT
) != 0
162 && (ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles(ctx
))) {
163 _mesa_error( ctx
, GL_INVALID_VALUE
, "glClear(GL_ACCUM_BUFFER_BIT)");
169 _mesa_update_state( ctx
); /* update _Xmin, etc */
172 if (!no_error
&& ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
173 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
174 "glClear(incomplete framebuffer)");
178 if (ctx
->RasterDiscard
)
181 if (ctx
->RenderMode
== GL_RENDER
) {
182 GLbitfield bufferMask
;
184 /* don't clear depth buffer if depth writing disabled */
185 if (!ctx
->Depth
.Mask
)
186 mask
&= ~GL_DEPTH_BUFFER_BIT
;
188 /* Build the bitmask to send to device driver's Clear function.
189 * Note that the GL_COLOR_BUFFER_BIT flag will expand to 0, 1, 2 or 4
190 * of the BUFFER_BIT_FRONT/BACK_LEFT/RIGHT flags, or one of the
191 * BUFFER_BIT_COLORn flags.
194 if (mask
& GL_COLOR_BUFFER_BIT
) {
196 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
197 gl_buffer_index buf
= ctx
->DrawBuffer
->_ColorDrawBufferIndexes
[i
];
199 if (buf
!= BUFFER_NONE
&& color_buffer_writes_enabled(ctx
, i
)) {
200 bufferMask
|= 1 << buf
;
205 if ((mask
& GL_DEPTH_BUFFER_BIT
)
206 && ctx
->DrawBuffer
->Visual
.depthBits
> 0) {
207 bufferMask
|= BUFFER_BIT_DEPTH
;
210 if ((mask
& GL_STENCIL_BUFFER_BIT
)
211 && ctx
->DrawBuffer
->Visual
.stencilBits
> 0) {
212 bufferMask
|= BUFFER_BIT_STENCIL
;
215 if ((mask
& GL_ACCUM_BUFFER_BIT
)
216 && ctx
->DrawBuffer
->Visual
.accumRedBits
> 0) {
217 bufferMask
|= BUFFER_BIT_ACCUM
;
220 assert(ctx
->Driver
.Clear
);
221 ctx
->Driver
.Clear(ctx
, bufferMask
);
227 _mesa_Clear_no_error(GLbitfield mask
)
229 GET_CURRENT_CONTEXT(ctx
);
230 clear(ctx
, mask
, true);
235 _mesa_Clear(GLbitfield mask
)
237 GET_CURRENT_CONTEXT(ctx
);
239 if (MESA_VERBOSE
& VERBOSE_API
)
240 _mesa_debug(ctx
, "glClear 0x%x\n", mask
);
242 clear(ctx
, mask
, false);
246 /** Returned by make_color_buffer_mask() for errors */
247 #define INVALID_MASK ~0x0U
251 * Convert the glClearBuffer 'drawbuffer' parameter into a bitmask of
252 * BUFFER_BIT_x values.
253 * Return INVALID_MASK if the drawbuffer value is invalid.
256 make_color_buffer_mask(struct gl_context
*ctx
, GLint drawbuffer
)
258 const struct gl_renderbuffer_attachment
*att
= ctx
->DrawBuffer
->Attachment
;
259 GLbitfield mask
= 0x0;
261 /* From the GL 4.0 specification:
262 * If buffer is COLOR, a particular draw buffer DRAW_BUFFERi is
263 * specified by passing i as the parameter drawbuffer, and value
264 * points to a four-element vector specifying the R, G, B, and A
265 * color to clear that draw buffer to. If the draw buffer is one
266 * of FRONT, BACK, LEFT, RIGHT, or FRONT_AND_BACK, identifying
267 * multiple buffers, each selected buffer is cleared to the same
270 * Note that "drawbuffer" and "draw buffer" have different meaning.
271 * "drawbuffer" specifies DRAW_BUFFERi, while "draw buffer" is what's
272 * assigned to DRAW_BUFFERi. It could be COLOR_ATTACHMENT0, FRONT, BACK,
275 if (drawbuffer
< 0 || drawbuffer
>= (GLint
)ctx
->Const
.MaxDrawBuffers
) {
279 switch (ctx
->DrawBuffer
->ColorDrawBuffer
[drawbuffer
]) {
281 if (att
[BUFFER_FRONT_LEFT
].Renderbuffer
)
282 mask
|= BUFFER_BIT_FRONT_LEFT
;
283 if (att
[BUFFER_FRONT_RIGHT
].Renderbuffer
)
284 mask
|= BUFFER_BIT_FRONT_RIGHT
;
287 /* For GLES contexts with a single buffered configuration, we actually
288 * only have a front renderbuffer, so any clear calls to GL_BACK should
289 * affect that buffer. See draw_buffer_enum_to_bitmask for details.
291 if (_mesa_is_gles(ctx
))
292 if (!ctx
->DrawBuffer
->Visual
.doubleBufferMode
)
293 if (att
[BUFFER_FRONT_LEFT
].Renderbuffer
)
294 mask
|= BUFFER_BIT_FRONT_LEFT
;
295 if (att
[BUFFER_BACK_LEFT
].Renderbuffer
)
296 mask
|= BUFFER_BIT_BACK_LEFT
;
297 if (att
[BUFFER_BACK_RIGHT
].Renderbuffer
)
298 mask
|= BUFFER_BIT_BACK_RIGHT
;
301 if (att
[BUFFER_FRONT_LEFT
].Renderbuffer
)
302 mask
|= BUFFER_BIT_FRONT_LEFT
;
303 if (att
[BUFFER_BACK_LEFT
].Renderbuffer
)
304 mask
|= BUFFER_BIT_BACK_LEFT
;
307 if (att
[BUFFER_FRONT_RIGHT
].Renderbuffer
)
308 mask
|= BUFFER_BIT_FRONT_RIGHT
;
309 if (att
[BUFFER_BACK_RIGHT
].Renderbuffer
)
310 mask
|= BUFFER_BIT_BACK_RIGHT
;
312 case GL_FRONT_AND_BACK
:
313 if (att
[BUFFER_FRONT_LEFT
].Renderbuffer
)
314 mask
|= BUFFER_BIT_FRONT_LEFT
;
315 if (att
[BUFFER_BACK_LEFT
].Renderbuffer
)
316 mask
|= BUFFER_BIT_BACK_LEFT
;
317 if (att
[BUFFER_FRONT_RIGHT
].Renderbuffer
)
318 mask
|= BUFFER_BIT_FRONT_RIGHT
;
319 if (att
[BUFFER_BACK_RIGHT
].Renderbuffer
)
320 mask
|= BUFFER_BIT_BACK_RIGHT
;
324 gl_buffer_index buf
=
325 ctx
->DrawBuffer
->_ColorDrawBufferIndexes
[drawbuffer
];
327 if (buf
!= BUFFER_NONE
&& att
[buf
].Renderbuffer
) {
340 * Clear signed integer color buffer or stencil buffer (not depth).
342 static ALWAYS_INLINE
void
343 clear_bufferiv(struct gl_context
*ctx
, GLenum buffer
, GLint drawbuffer
,
344 const GLint
*value
, bool no_error
)
346 FLUSH_VERTICES(ctx
, 0);
347 FLUSH_CURRENT(ctx
, 0);
350 _mesa_update_state( ctx
);
353 if (!no_error
&& ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
354 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
355 "glClearBufferiv(incomplete framebuffer)");
361 /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says:
363 * "ClearBuffer generates an INVALID VALUE error if buffer is
364 * COLOR and drawbuffer is less than zero, or greater than the
365 * value of MAX DRAW BUFFERS minus one; or if buffer is DEPTH,
366 * STENCIL, or DEPTH STENCIL and drawbuffer is not zero."
368 if (!no_error
&& drawbuffer
!= 0) {
369 _mesa_error(ctx
, GL_INVALID_VALUE
, "glClearBufferiv(drawbuffer=%d)",
373 else if (ctx
->DrawBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
374 && !ctx
->RasterDiscard
) {
375 /* Save current stencil clear value, set to 'value', do the
376 * stencil clear and restore the clear value.
377 * XXX in the future we may have a new ctx->Driver.ClearBuffer()
380 const GLuint clearSave
= ctx
->Stencil
.Clear
;
381 ctx
->Stencil
.Clear
= *value
;
382 ctx
->Driver
.Clear(ctx
, BUFFER_BIT_STENCIL
);
383 ctx
->Stencil
.Clear
= clearSave
;
388 const GLbitfield mask
= make_color_buffer_mask(ctx
, drawbuffer
);
389 if (!no_error
&& mask
== INVALID_MASK
) {
390 _mesa_error(ctx
, GL_INVALID_VALUE
, "glClearBufferiv(drawbuffer=%d)",
394 else if (mask
&& !ctx
->RasterDiscard
) {
395 union gl_color_union clearSave
;
398 clearSave
= ctx
->Color
.ClearColor
;
400 COPY_4V(ctx
->Color
.ClearColor
.i
, value
);
401 /* clear buffer(s) */
402 ctx
->Driver
.Clear(ctx
, mask
);
404 ctx
->Color
.ClearColor
= clearSave
;
410 /* Page 498 of the PDF, section '17.4.3.1 Clearing Individual Buffers'
411 * of the OpenGL 4.5 spec states:
413 * "An INVALID_ENUM error is generated by ClearBufferiv and
414 * ClearNamedFramebufferiv if buffer is not COLOR or STENCIL."
416 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClearBufferiv(buffer=%s)",
417 _mesa_enum_to_string(buffer
));
425 _mesa_ClearBufferiv_no_error(GLenum buffer
, GLint drawbuffer
, const GLint
*value
)
427 GET_CURRENT_CONTEXT(ctx
);
428 clear_bufferiv(ctx
, buffer
, drawbuffer
, value
, true);
433 _mesa_ClearBufferiv(GLenum buffer
, GLint drawbuffer
, const GLint
*value
)
435 GET_CURRENT_CONTEXT(ctx
);
436 clear_bufferiv(ctx
, buffer
, drawbuffer
, value
, false);
441 * The ClearBuffer framework is so complicated and so riddled with the
442 * assumption that the framebuffer is bound that, for now, we will just fake
443 * direct state access clearing for the user.
446 _mesa_ClearNamedFramebufferiv(GLuint framebuffer
, GLenum buffer
,
447 GLint drawbuffer
, const GLint
*value
)
451 _mesa_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING
, &oldfb
);
452 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, framebuffer
);
453 _mesa_ClearBufferiv(buffer
, drawbuffer
, value
);
454 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, (GLuint
) oldfb
);
460 * Clear unsigned integer color buffer (not depth, not stencil).
462 static ALWAYS_INLINE
void
463 clear_bufferuiv(struct gl_context
*ctx
, GLenum buffer
, GLint drawbuffer
,
464 const GLuint
*value
, bool no_error
)
466 FLUSH_VERTICES(ctx
, 0);
467 FLUSH_CURRENT(ctx
, 0);
470 _mesa_update_state( ctx
);
476 const GLbitfield mask
= make_color_buffer_mask(ctx
, drawbuffer
);
477 if (!no_error
&& mask
== INVALID_MASK
) {
478 _mesa_error(ctx
, GL_INVALID_VALUE
, "glClearBufferuiv(drawbuffer=%d)",
482 else if (mask
&& !ctx
->RasterDiscard
) {
483 union gl_color_union clearSave
;
486 clearSave
= ctx
->Color
.ClearColor
;
488 COPY_4V(ctx
->Color
.ClearColor
.ui
, value
);
489 /* clear buffer(s) */
490 ctx
->Driver
.Clear(ctx
, mask
);
492 ctx
->Color
.ClearColor
= clearSave
;
498 /* Page 498 of the PDF, section '17.4.3.1 Clearing Individual Buffers'
499 * of the OpenGL 4.5 spec states:
501 * "An INVALID_ENUM error is generated by ClearBufferuiv and
502 * ClearNamedFramebufferuiv if buffer is not COLOR."
504 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClearBufferuiv(buffer=%s)",
505 _mesa_enum_to_string(buffer
));
513 _mesa_ClearBufferuiv_no_error(GLenum buffer
, GLint drawbuffer
,
516 GET_CURRENT_CONTEXT(ctx
);
517 clear_bufferuiv(ctx
, buffer
, drawbuffer
, value
, true);
522 _mesa_ClearBufferuiv(GLenum buffer
, GLint drawbuffer
, const GLuint
*value
)
524 GET_CURRENT_CONTEXT(ctx
);
525 clear_bufferuiv(ctx
, buffer
, drawbuffer
, value
, false);
530 * The ClearBuffer framework is so complicated and so riddled with the
531 * assumption that the framebuffer is bound that, for now, we will just fake
532 * direct state access clearing for the user.
535 _mesa_ClearNamedFramebufferuiv(GLuint framebuffer
, GLenum buffer
,
536 GLint drawbuffer
, const GLuint
*value
)
540 _mesa_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING
, &oldfb
);
541 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, framebuffer
);
542 _mesa_ClearBufferuiv(buffer
, drawbuffer
, value
);
543 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, (GLuint
) oldfb
);
549 * Clear fixed-pt or float color buffer or depth buffer (not stencil).
551 static ALWAYS_INLINE
void
552 clear_bufferfv(struct gl_context
*ctx
, GLenum buffer
, GLint drawbuffer
,
553 const GLfloat
*value
, bool no_error
)
555 FLUSH_VERTICES(ctx
, 0);
556 FLUSH_CURRENT(ctx
, 0);
559 _mesa_update_state( ctx
);
564 /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says:
566 * "ClearBuffer generates an INVALID VALUE error if buffer is
567 * COLOR and drawbuffer is less than zero, or greater than the
568 * value of MAX DRAW BUFFERS minus one; or if buffer is DEPTH,
569 * STENCIL, or DEPTH STENCIL and drawbuffer is not zero."
571 if (!no_error
&& drawbuffer
!= 0) {
572 _mesa_error(ctx
, GL_INVALID_VALUE
, "glClearBufferfv(drawbuffer=%d)",
576 else if (ctx
->DrawBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
577 && !ctx
->RasterDiscard
) {
578 /* Save current depth clear value, set to 'value', do the
579 * depth clear and restore the clear value.
580 * XXX in the future we may have a new ctx->Driver.ClearBuffer()
583 const GLclampd clearSave
= ctx
->Depth
.Clear
;
584 ctx
->Depth
.Clear
= *value
;
585 ctx
->Driver
.Clear(ctx
, BUFFER_BIT_DEPTH
);
586 ctx
->Depth
.Clear
= clearSave
;
588 /* clear depth buffer to value */
592 const GLbitfield mask
= make_color_buffer_mask(ctx
, drawbuffer
);
593 if (!no_error
&& mask
== INVALID_MASK
) {
594 _mesa_error(ctx
, GL_INVALID_VALUE
, "glClearBufferfv(drawbuffer=%d)",
598 else if (mask
&& !ctx
->RasterDiscard
) {
599 union gl_color_union clearSave
;
602 clearSave
= ctx
->Color
.ClearColor
;
604 COPY_4V(ctx
->Color
.ClearColor
.f
, value
);
605 /* clear buffer(s) */
606 ctx
->Driver
.Clear(ctx
, mask
);
608 ctx
->Color
.ClearColor
= clearSave
;
614 /* Page 498 of the PDF, section '17.4.3.1 Clearing Individual Buffers'
615 * of the OpenGL 4.5 spec states:
617 * "An INVALID_ENUM error is generated by ClearBufferfv and
618 * ClearNamedFramebufferfv if buffer is not COLOR or DEPTH."
620 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClearBufferfv(buffer=%s)",
621 _mesa_enum_to_string(buffer
));
629 _mesa_ClearBufferfv_no_error(GLenum buffer
, GLint drawbuffer
,
630 const GLfloat
*value
)
632 GET_CURRENT_CONTEXT(ctx
);
633 clear_bufferfv(ctx
, buffer
, drawbuffer
, value
, true);
638 _mesa_ClearBufferfv(GLenum buffer
, GLint drawbuffer
, const GLfloat
*value
)
640 GET_CURRENT_CONTEXT(ctx
);
641 clear_bufferfv(ctx
, buffer
, drawbuffer
, value
, false);
646 * The ClearBuffer framework is so complicated and so riddled with the
647 * assumption that the framebuffer is bound that, for now, we will just fake
648 * direct state access clearing for the user.
651 _mesa_ClearNamedFramebufferfv(GLuint framebuffer
, GLenum buffer
,
652 GLint drawbuffer
, const GLfloat
*value
)
656 _mesa_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING
, &oldfb
);
657 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, framebuffer
);
658 _mesa_ClearBufferfv(buffer
, drawbuffer
, value
);
659 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, (GLuint
) oldfb
);
665 * Clear depth/stencil buffer only.
667 static ALWAYS_INLINE
void
668 clear_bufferfi(struct gl_context
*ctx
, GLenum buffer
, GLint drawbuffer
,
669 GLfloat depth
, GLint stencil
, bool no_error
)
673 FLUSH_VERTICES(ctx
, 0);
674 FLUSH_CURRENT(ctx
, 0);
677 if (buffer
!= GL_DEPTH_STENCIL
) {
678 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClearBufferfi(buffer=%s)",
679 _mesa_enum_to_string(buffer
));
683 /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says:
685 * "ClearBuffer generates an INVALID VALUE error if buffer is
686 * COLOR and drawbuffer is less than zero, or greater than the
687 * value of MAX DRAW BUFFERS minus one; or if buffer is DEPTH,
688 * STENCIL, or DEPTH STENCIL and drawbuffer is not zero."
690 if (drawbuffer
!= 0) {
691 _mesa_error(ctx
, GL_INVALID_VALUE
, "glClearBufferfi(drawbuffer=%d)",
697 if (ctx
->RasterDiscard
)
701 _mesa_update_state( ctx
);
704 if (!no_error
&& ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
705 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
706 "glClearBufferfi(incomplete framebuffer)");
710 if (ctx
->DrawBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
)
711 mask
|= BUFFER_BIT_DEPTH
;
712 if (ctx
->DrawBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
)
713 mask
|= BUFFER_BIT_STENCIL
;
716 /* save current clear values */
717 const GLclampd clearDepthSave
= ctx
->Depth
.Clear
;
718 const GLuint clearStencilSave
= ctx
->Stencil
.Clear
;
720 /* set new clear values */
721 ctx
->Depth
.Clear
= depth
;
722 ctx
->Stencil
.Clear
= stencil
;
725 ctx
->Driver
.Clear(ctx
, mask
);
728 ctx
->Depth
.Clear
= clearDepthSave
;
729 ctx
->Stencil
.Clear
= clearStencilSave
;
735 _mesa_ClearBufferfi_no_error(GLenum buffer
, GLint drawbuffer
,
736 GLfloat depth
, GLint stencil
)
738 GET_CURRENT_CONTEXT(ctx
);
739 clear_bufferfi(ctx
, buffer
, drawbuffer
, depth
, stencil
, true);
744 _mesa_ClearBufferfi(GLenum buffer
, GLint drawbuffer
,
745 GLfloat depth
, GLint stencil
)
747 GET_CURRENT_CONTEXT(ctx
);
748 clear_bufferfi(ctx
, buffer
, drawbuffer
, depth
, stencil
, false);
753 * The ClearBuffer framework is so complicated and so riddled with the
754 * assumption that the framebuffer is bound that, for now, we will just fake
755 * direct state access clearing for the user.
758 _mesa_ClearNamedFramebufferfi(GLuint framebuffer
, GLenum buffer
,
759 GLint drawbuffer
, GLfloat depth
, GLint stencil
)
763 _mesa_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING
, &oldfb
);
764 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, framebuffer
);
765 _mesa_ClearBufferfi(buffer
, drawbuffer
, depth
, stencil
);
766 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, (GLuint
) oldfb
);