[[MESA]
[reactos.git] / reactos / dll / opengl / mesa / src / mesa / main / clear.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file clear.c
28 * glClearColor, glClearIndex, glClear() functions.
29 */
30
31
32
33 #include "glheader.h"
34 #include "clear.h"
35 #include "context.h"
36 #include "colormac.h"
37 #include "enums.h"
38 #include "macros.h"
39 #include "mtypes.h"
40 #include "state.h"
41
42
43
44 #if _HAVE_FULL_GL
45 void GLAPIENTRY
46 _mesa_ClearIndex( GLfloat c )
47 {
48 GET_CURRENT_CONTEXT(ctx);
49 ASSERT_OUTSIDE_BEGIN_END(ctx);
50
51 if (ctx->Color.ClearIndex == (GLuint) c)
52 return;
53
54 FLUSH_VERTICES(ctx, _NEW_COLOR);
55 ctx->Color.ClearIndex = (GLuint) c;
56 }
57 #endif
58
59
60 /**
61 * Specify the clear values for the color buffers.
62 *
63 * \param red red color component.
64 * \param green green color component.
65 * \param blue blue color component.
66 * \param alpha alpha component.
67 *
68 * \sa glClearColor().
69 *
70 * Clamps the parameters and updates gl_colorbuffer_attrib::ClearColor. On a
71 * change, flushes the vertices and notifies the driver via the
72 * dd_function_table::ClearColor callback.
73 */
74 void GLAPIENTRY
75 _mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
76 {
77 GLfloat tmp[4];
78 GET_CURRENT_CONTEXT(ctx);
79 ASSERT_OUTSIDE_BEGIN_END(ctx);
80
81 tmp[0] = red;
82 tmp[1] = green;
83 tmp[2] = blue;
84 tmp[3] = alpha;
85
86 if (TEST_EQ_4V(tmp, ctx->Color.ClearColor.f))
87 return; /* no change */
88
89 FLUSH_VERTICES(ctx, _NEW_COLOR);
90 COPY_4V(ctx->Color.ClearColor.f, tmp);
91
92 if (ctx->Driver.ClearColor) {
93 /* it's OK to call glClearColor in CI mode but it should be a NOP */
94 /* we pass the clamped color, since all drivers that need this don't
95 * support GL_ARB_color_buffer_float
96 */
97 (*ctx->Driver.ClearColor)(ctx, ctx->Color.ClearColor);
98 }
99 }
100
101
102 /**
103 * GL_EXT_texture_integer
104 */
105 void GLAPIENTRY
106 _mesa_ClearColorIiEXT(GLint r, GLint g, GLint b, GLint a)
107 {
108 GLint tmp[4];
109 GET_CURRENT_CONTEXT(ctx);
110 ASSERT_OUTSIDE_BEGIN_END(ctx);
111
112 tmp[0] = r;
113 tmp[1] = g;
114 tmp[2] = b;
115 tmp[3] = a;
116
117 if (TEST_EQ_4V(tmp, ctx->Color.ClearColor.i))
118 return; /* no change */
119
120 FLUSH_VERTICES(ctx, _NEW_COLOR);
121 COPY_4V(ctx->Color.ClearColor.i, tmp);
122
123 /* these should be NOP calls for drivers supporting EXT_texture_integer */
124 if (ctx->Driver.ClearColor) {
125 ctx->Driver.ClearColor(ctx, ctx->Color.ClearColor);
126 }
127 }
128
129
130 /**
131 * GL_EXT_texture_integer
132 */
133 void GLAPIENTRY
134 _mesa_ClearColorIuiEXT(GLuint r, GLuint g, GLuint b, GLuint a)
135 {
136 GLuint tmp[4];
137 GET_CURRENT_CONTEXT(ctx);
138 ASSERT_OUTSIDE_BEGIN_END(ctx);
139
140 tmp[0] = r;
141 tmp[1] = g;
142 tmp[2] = b;
143 tmp[3] = a;
144
145 if (TEST_EQ_4V(tmp, ctx->Color.ClearColor.ui))
146 return; /* no change */
147
148 FLUSH_VERTICES(ctx, _NEW_COLOR);
149 COPY_4V(ctx->Color.ClearColor.ui, tmp);
150
151 /* these should be NOP calls for drivers supporting EXT_texture_integer */
152 if (ctx->Driver.ClearColor) {
153 ctx->Driver.ClearColor(ctx, ctx->Color.ClearColor);
154 }
155 }
156
157
158 /**
159 * Clear buffers.
160 *
161 * \param mask bit-mask indicating the buffers to be cleared.
162 *
163 * Flushes the vertices and verifies the parameter. If __struct gl_contextRec::NewState
164 * is set then calls _mesa_update_state() to update gl_frame_buffer::_Xmin,
165 * etc. If the rasterization mode is set to GL_RENDER then requests the driver
166 * to clear the buffers, via the dd_function_table::Clear callback.
167 */
168 void GLAPIENTRY
169 _mesa_Clear( GLbitfield mask )
170 {
171 GET_CURRENT_CONTEXT(ctx);
172 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
173
174 FLUSH_CURRENT(ctx, 0);
175
176 if (MESA_VERBOSE & VERBOSE_API)
177 _mesa_debug(ctx, "glClear 0x%x\n", mask);
178
179 if (mask & ~(GL_COLOR_BUFFER_BIT |
180 GL_DEPTH_BUFFER_BIT |
181 GL_STENCIL_BUFFER_BIT |
182 GL_ACCUM_BUFFER_BIT)) {
183 /* invalid bit set */
184 _mesa_error( ctx, GL_INVALID_VALUE, "glClear(0x%x)", mask);
185 return;
186 }
187
188 if (ctx->NewState) {
189 _mesa_update_state( ctx ); /* update _Xmin, etc */
190 }
191
192 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
193 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
194 "glClear(incomplete framebuffer)");
195 return;
196 }
197
198 if (ctx->DrawBuffer->Width == 0 || ctx->DrawBuffer->Height == 0 ||
199 ctx->DrawBuffer->_Xmin >= ctx->DrawBuffer->_Xmax ||
200 ctx->DrawBuffer->_Ymin >= ctx->DrawBuffer->_Ymax)
201 return;
202
203 if (ctx->RasterDiscard)
204 return;
205
206 if (ctx->RenderMode == GL_RENDER) {
207 GLbitfield bufferMask;
208
209 /* don't clear depth buffer if depth writing disabled */
210 if (!ctx->Depth.Mask)
211 mask &= ~GL_DEPTH_BUFFER_BIT;
212
213 /* Build the bitmask to send to device driver's Clear function.
214 * Note that the GL_COLOR_BUFFER_BIT flag will expand to 0, 1, 2 or 4
215 * of the BUFFER_BIT_FRONT/BACK_LEFT/RIGHT flags, or one of the
216 * BUFFER_BIT_COLORn flags.
217 */
218 bufferMask = 0;
219 if (mask & GL_COLOR_BUFFER_BIT) {
220 GLuint i;
221 for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
222 bufferMask |= (1 << ctx->DrawBuffer->_ColorDrawBufferIndexes[i]);
223 }
224 }
225
226 if ((mask & GL_DEPTH_BUFFER_BIT)
227 && ctx->DrawBuffer->Visual.haveDepthBuffer) {
228 bufferMask |= BUFFER_BIT_DEPTH;
229 }
230
231 if ((mask & GL_STENCIL_BUFFER_BIT)
232 && ctx->DrawBuffer->Visual.haveStencilBuffer) {
233 bufferMask |= BUFFER_BIT_STENCIL;
234 }
235
236 if ((mask & GL_ACCUM_BUFFER_BIT)
237 && ctx->DrawBuffer->Visual.haveAccumBuffer) {
238 bufferMask |= BUFFER_BIT_ACCUM;
239 }
240
241 ASSERT(ctx->Driver.Clear);
242 ctx->Driver.Clear(ctx, bufferMask);
243 }
244 }
245
246
247 /** Returned by make_color_buffer_mask() for errors */
248 #define INVALID_MASK ~0x0
249
250
251 /**
252 * Convert the glClearBuffer 'drawbuffer' parameter into a bitmask of
253 * BUFFER_BIT_x values.
254 * Return INVALID_MASK if the drawbuffer value is invalid.
255 */
256 static GLbitfield
257 make_color_buffer_mask(struct gl_context *ctx, GLint drawbuffer)
258 {
259 const struct gl_renderbuffer_attachment *att = ctx->DrawBuffer->Attachment;
260 GLbitfield mask = 0x0;
261
262 switch (drawbuffer) {
263 case GL_FRONT:
264 if (att[BUFFER_FRONT_LEFT].Renderbuffer)
265 mask |= BUFFER_BIT_FRONT_LEFT;
266 if (att[BUFFER_FRONT_RIGHT].Renderbuffer)
267 mask |= BUFFER_BIT_FRONT_RIGHT;
268 break;
269 case GL_BACK:
270 if (att[BUFFER_BACK_LEFT].Renderbuffer)
271 mask |= BUFFER_BIT_BACK_LEFT;
272 if (att[BUFFER_BACK_RIGHT].Renderbuffer)
273 mask |= BUFFER_BIT_BACK_RIGHT;
274 break;
275 case GL_LEFT:
276 if (att[BUFFER_FRONT_LEFT].Renderbuffer)
277 mask |= BUFFER_BIT_FRONT_LEFT;
278 if (att[BUFFER_BACK_LEFT].Renderbuffer)
279 mask |= BUFFER_BIT_BACK_LEFT;
280 break;
281 case GL_RIGHT:
282 if (att[BUFFER_FRONT_RIGHT].Renderbuffer)
283 mask |= BUFFER_BIT_FRONT_RIGHT;
284 if (att[BUFFER_BACK_RIGHT].Renderbuffer)
285 mask |= BUFFER_BIT_BACK_RIGHT;
286 break;
287 case GL_FRONT_AND_BACK:
288 if (att[BUFFER_FRONT_LEFT].Renderbuffer)
289 mask |= BUFFER_BIT_FRONT_LEFT;
290 if (att[BUFFER_BACK_LEFT].Renderbuffer)
291 mask |= BUFFER_BIT_BACK_LEFT;
292 if (att[BUFFER_FRONT_RIGHT].Renderbuffer)
293 mask |= BUFFER_BIT_FRONT_RIGHT;
294 if (att[BUFFER_BACK_RIGHT].Renderbuffer)
295 mask |= BUFFER_BIT_BACK_RIGHT;
296 break;
297 default:
298 if (drawbuffer < 0 || drawbuffer >= (GLint)ctx->Const.MaxDrawBuffers) {
299 mask = INVALID_MASK;
300 }
301 else if (att[BUFFER_COLOR0 + drawbuffer].Renderbuffer) {
302 mask |= (BUFFER_BIT_COLOR0 << drawbuffer);
303 }
304 }
305
306 return mask;
307 }
308
309
310
311 /**
312 * New in GL 3.0
313 * Clear signed integer color buffer or stencil buffer (not depth).
314 */
315 void GLAPIENTRY
316 _mesa_ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *value)
317 {
318 GET_CURRENT_CONTEXT(ctx);
319 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
320
321 FLUSH_CURRENT(ctx, 0);
322
323 if (ctx->NewState) {
324 _mesa_update_state( ctx );
325 }
326
327 switch (buffer) {
328 case GL_STENCIL:
329 /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says:
330 *
331 * "ClearBuffer generates an INVALID VALUE error if buffer is
332 * COLOR and drawbuffer is less than zero, or greater than the
333 * value of MAX DRAW BUFFERS minus one; or if buffer is DEPTH,
334 * STENCIL, or DEPTH STENCIL and drawbuffer is not zero."
335 */
336 if (drawbuffer != 0) {
337 _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferiv(drawbuffer=%d)",
338 drawbuffer);
339 return;
340 }
341 else if (ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer && !ctx->RasterDiscard) {
342 /* Save current stencil clear value, set to 'value', do the
343 * stencil clear and restore the clear value.
344 * XXX in the future we may have a new ctx->Driver.ClearBuffer()
345 * hook instead.
346 */
347 const GLuint clearSave = ctx->Stencil.Clear;
348 ctx->Stencil.Clear = *value;
349 if (ctx->Driver.ClearStencil)
350 ctx->Driver.ClearStencil(ctx, *value);
351 ctx->Driver.Clear(ctx, BUFFER_BIT_STENCIL);
352 ctx->Stencil.Clear = clearSave;
353 if (ctx->Driver.ClearStencil)
354 ctx->Driver.ClearStencil(ctx, clearSave);
355 }
356 break;
357 case GL_COLOR:
358 {
359 const GLbitfield mask = make_color_buffer_mask(ctx, drawbuffer);
360 if (mask == INVALID_MASK) {
361 _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferiv(drawbuffer=%d)",
362 drawbuffer);
363 return;
364 }
365 else if (mask && !ctx->RasterDiscard) {
366 union gl_color_union clearSave;
367
368 /* save color */
369 clearSave = ctx->Color.ClearColor;
370 /* set color */
371 COPY_4V(ctx->Color.ClearColor.i, value);
372 if (ctx->Driver.ClearColor)
373 ctx->Driver.ClearColor(ctx, ctx->Color.ClearColor);
374 /* clear buffer(s) */
375 ctx->Driver.Clear(ctx, mask);
376 /* restore color */
377 ctx->Color.ClearColor = clearSave;
378 if (ctx->Driver.ClearColor)
379 ctx->Driver.ClearColor(ctx, clearSave);
380 }
381 }
382 break;
383 case GL_DEPTH:
384 /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says:
385 *
386 * "The result of ClearBuffer is undefined if no conversion between
387 * the type of the specified value and the type of the buffer being
388 * cleared is defined (for example, if ClearBufferiv is called for a
389 * fixed- or floating-point buffer, or if ClearBufferfv is called
390 * for a signed or unsigned integer buffer). This is not an error."
391 *
392 * In this case we take "undefined" and "not an error" to mean "ignore."
393 * Note that we still need to generate an error for the invalid
394 * drawbuffer case (see the GL_STENCIL case above).
395 */
396 if (drawbuffer != 0) {
397 _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferiv(drawbuffer=%d)",
398 drawbuffer);
399 return;
400 }
401 return;
402 default:
403 _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferiv(buffer=%s)",
404 _mesa_lookup_enum_by_nr(buffer));
405 return;
406 }
407 }
408
409
410 /**
411 * New in GL 3.0
412 * Clear unsigned integer color buffer (not depth, not stencil).
413 */
414 void GLAPIENTRY
415 _mesa_ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *value)
416 {
417 GET_CURRENT_CONTEXT(ctx);
418 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
419
420 FLUSH_CURRENT(ctx, 0);
421
422 if (ctx->NewState) {
423 _mesa_update_state( ctx );
424 }
425
426 switch (buffer) {
427 case GL_COLOR:
428 {
429 const GLbitfield mask = make_color_buffer_mask(ctx, drawbuffer);
430 if (mask == INVALID_MASK) {
431 _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferuiv(drawbuffer=%d)",
432 drawbuffer);
433 return;
434 }
435 else if (mask && !ctx->RasterDiscard) {
436 union gl_color_union clearSave;
437
438 /* save color */
439 clearSave = ctx->Color.ClearColor;
440 /* set color */
441 COPY_4V(ctx->Color.ClearColor.ui, value);
442 if (ctx->Driver.ClearColor)
443 ctx->Driver.ClearColor(ctx, ctx->Color.ClearColor);
444 /* clear buffer(s) */
445 ctx->Driver.Clear(ctx, mask);
446 /* restore color */
447 ctx->Color.ClearColor = clearSave;
448 if (ctx->Driver.ClearColor)
449 ctx->Driver.ClearColor(ctx, clearSave);
450 }
451 }
452 break;
453 case GL_DEPTH:
454 case GL_STENCIL:
455 /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says:
456 *
457 * "The result of ClearBuffer is undefined if no conversion between
458 * the type of the specified value and the type of the buffer being
459 * cleared is defined (for example, if ClearBufferiv is called for a
460 * fixed- or floating-point buffer, or if ClearBufferfv is called
461 * for a signed or unsigned integer buffer). This is not an error."
462 *
463 * In this case we take "undefined" and "not an error" to mean "ignore."
464 * Even though we could do something sensible for GL_STENCIL, page 263
465 * (page 279 of the PDF) says:
466 *
467 * "Only ClearBufferiv should be used to clear stencil buffers."
468 *
469 * Note that we still need to generate an error for the invalid
470 * drawbuffer case (see the GL_STENCIL case in _mesa_ClearBufferiv).
471 */
472 if (drawbuffer != 0) {
473 _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferuiv(drawbuffer=%d)",
474 drawbuffer);
475 return;
476 }
477 return;
478 default:
479 _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferuiv(buffer=%s)",
480 _mesa_lookup_enum_by_nr(buffer));
481 return;
482 }
483 }
484
485
486 /**
487 * New in GL 3.0
488 * Clear fixed-pt or float color buffer or depth buffer (not stencil).
489 */
490 void GLAPIENTRY
491 _mesa_ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *value)
492 {
493 GET_CURRENT_CONTEXT(ctx);
494 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
495
496 FLUSH_CURRENT(ctx, 0);
497
498 if (ctx->NewState) {
499 _mesa_update_state( ctx );
500 }
501
502 switch (buffer) {
503 case GL_DEPTH:
504 /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says:
505 *
506 * "ClearBuffer generates an INVALID VALUE error if buffer is
507 * COLOR and drawbuffer is less than zero, or greater than the
508 * value of MAX DRAW BUFFERS minus one; or if buffer is DEPTH,
509 * STENCIL, or DEPTH STENCIL and drawbuffer is not zero."
510 */
511 if (drawbuffer != 0) {
512 _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferfv(drawbuffer=%d)",
513 drawbuffer);
514 return;
515 }
516 else if (ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer && !ctx->RasterDiscard) {
517 /* Save current depth clear value, set to 'value', do the
518 * depth clear and restore the clear value.
519 * XXX in the future we may have a new ctx->Driver.ClearBuffer()
520 * hook instead.
521 */
522 const GLclampd clearSave = ctx->Depth.Clear;
523 ctx->Depth.Clear = *value;
524 if (ctx->Driver.ClearDepth)
525 ctx->Driver.ClearDepth(ctx, *value);
526 ctx->Driver.Clear(ctx, BUFFER_BIT_DEPTH);
527 ctx->Depth.Clear = clearSave;
528 if (ctx->Driver.ClearDepth)
529 ctx->Driver.ClearDepth(ctx, clearSave);
530 }
531 /* clear depth buffer to value */
532 break;
533 case GL_COLOR:
534 {
535 const GLbitfield mask = make_color_buffer_mask(ctx, drawbuffer);
536 if (mask == INVALID_MASK) {
537 _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferfv(drawbuffer=%d)",
538 drawbuffer);
539 return;
540 }
541 else if (mask && !ctx->RasterDiscard) {
542 union gl_color_union clearSave;
543
544 /* save color */
545 clearSave = ctx->Color.ClearColor;
546 /* set color */
547 COPY_4V_CAST(ctx->Color.ClearColor.f, value, GLclampf);
548 if (ctx->Driver.ClearColor)
549 ctx->Driver.ClearColor(ctx, ctx->Color.ClearColor);
550 /* clear buffer(s) */
551 ctx->Driver.Clear(ctx, mask);
552 /* restore color */
553 ctx->Color.ClearColor = clearSave;
554 if (ctx->Driver.ClearColor)
555 ctx->Driver.ClearColor(ctx, clearSave);
556 }
557 }
558 break;
559 case GL_STENCIL:
560 /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says:
561 *
562 * "The result of ClearBuffer is undefined if no conversion between
563 * the type of the specified value and the type of the buffer being
564 * cleared is defined (for example, if ClearBufferiv is called for a
565 * fixed- or floating-point buffer, or if ClearBufferfv is called
566 * for a signed or unsigned integer buffer). This is not an error."
567 *
568 * In this case we take "undefined" and "not an error" to mean "ignore."
569 * Note that we still need to generate an error for the invalid
570 * drawbuffer case (see the GL_DEPTH case above).
571 */
572 if (drawbuffer != 0) {
573 _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferfv(drawbuffer=%d)",
574 drawbuffer);
575 return;
576 }
577 return;
578 default:
579 _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferfv(buffer=%s)",
580 _mesa_lookup_enum_by_nr(buffer));
581 return;
582 }
583 }
584
585
586 /**
587 * New in GL 3.0
588 * Clear depth/stencil buffer only.
589 */
590 void GLAPIENTRY
591 _mesa_ClearBufferfi(GLenum buffer, GLint drawbuffer,
592 GLfloat depth, GLint stencil)
593 {
594 GET_CURRENT_CONTEXT(ctx);
595 GLbitfield mask = 0;
596
597 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
598
599 FLUSH_CURRENT(ctx, 0);
600
601 if (buffer != GL_DEPTH_STENCIL) {
602 _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferfi(buffer=%s)",
603 _mesa_lookup_enum_by_nr(buffer));
604 return;
605 }
606
607 /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says:
608 *
609 * "ClearBuffer generates an INVALID VALUE error if buffer is
610 * COLOR and drawbuffer is less than zero, or greater than the
611 * value of MAX DRAW BUFFERS minus one; or if buffer is DEPTH,
612 * STENCIL, or DEPTH STENCIL and drawbuffer is not zero."
613 */
614 if (drawbuffer != 0) {
615 _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferfi(drawbuffer=%d)",
616 drawbuffer);
617 return;
618 }
619
620 if (ctx->RasterDiscard)
621 return;
622
623 if (ctx->NewState) {
624 _mesa_update_state( ctx );
625 }
626
627 if (ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer)
628 mask |= BUFFER_BIT_DEPTH;
629 if (ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer)
630 mask |= BUFFER_BIT_STENCIL;
631
632 if (mask) {
633 /* save current clear values */
634 const GLclampd clearDepthSave = ctx->Depth.Clear;
635 const GLuint clearStencilSave = ctx->Stencil.Clear;
636
637 /* set new clear values */
638 ctx->Depth.Clear = depth;
639 ctx->Stencil.Clear = stencil;
640 if (ctx->Driver.ClearDepth)
641 ctx->Driver.ClearDepth(ctx, depth);
642 if (ctx->Driver.ClearStencil)
643 ctx->Driver.ClearStencil(ctx, stencil);
644
645 /* clear buffers */
646 ctx->Driver.Clear(ctx, mask);
647
648 /* restore */
649 ctx->Depth.Clear = clearDepthSave;
650 ctx->Stencil.Clear = clearStencilSave;
651 if (ctx->Driver.ClearDepth)
652 ctx->Driver.ClearDepth(ctx, clearDepthSave);
653 if (ctx->Driver.ClearStencil)
654 ctx->Driver.ClearStencil(ctx, clearStencilSave);
655 }
656 }