Finish up conversions of shaders to immutable objects.
[mesa.git] / src / mesa / state_tracker / st_cb_clear.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 * Brian Paul
32 */
33
34 #include "main/glheader.h"
35 #include "main/macros.h"
36 #include "shader/prog_instruction.h"
37 #include "st_atom.h"
38 #include "st_cache.h"
39 #include "st_context.h"
40 #include "st_cb_clear.h"
41 #include "st_cb_fbo.h"
42 #include "st_draw.h"
43 #include "st_program.h"
44 #include "st_public.h"
45
46 #include "pipe/p_context.h"
47 #include "pipe/p_state.h"
48 #include "pipe/p_defines.h"
49 #include "pipe/p_winsys.h"
50
51 #include "pipe/tgsi/mesa/mesa_to_tgsi.h"
52
53 #include "vf/vf.h"
54
55
56
57
58 static GLuint
59 color_value(GLuint pipeFormat, const GLfloat color[4])
60 {
61 GLubyte r, g, b, a;
62
63 UNCLAMPED_FLOAT_TO_UBYTE(r, color[0]);
64 UNCLAMPED_FLOAT_TO_UBYTE(g, color[1]);
65 UNCLAMPED_FLOAT_TO_UBYTE(b, color[2]);
66 UNCLAMPED_FLOAT_TO_UBYTE(a, color[3]);
67
68 switch (pipeFormat) {
69 case PIPE_FORMAT_U_R8_G8_B8_A8:
70 return (r << 24) | (g << 16) | (b << 8) | a;
71 case PIPE_FORMAT_U_A8_R8_G8_B8:
72 return (a << 24) | (r << 16) | (g << 8) | b;
73 case PIPE_FORMAT_U_R5_G6_B5:
74 return ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
75 default:
76 return 0;
77 }
78 }
79
80
81 static GLuint
82 depth_value(GLuint pipeFormat, GLfloat value)
83 {
84 GLuint val;
85 switch (pipeFormat) {
86 case PIPE_FORMAT_U_Z16:
87 val = (GLuint) (value * 0xffffff);
88 break;
89 case PIPE_FORMAT_U_Z32:
90 val = (GLuint) (value * 0xffffffff);
91 break;
92 case PIPE_FORMAT_S8_Z24:
93 /*case PIPE_FORMAT_Z24_S8:*/
94 val = (GLuint) (value * 0xffffff);
95 break;
96 default:
97 val = 0;
98 assert(0);
99 }
100 return val;
101 }
102
103
104 static GLboolean
105 is_depth_stencil_format(GLuint pipeFormat)
106 {
107 switch (pipeFormat) {
108 case PIPE_FORMAT_S8_Z24:
109 /*case PIPE_FORMAT_Z24_S8:*/
110 return GL_TRUE;
111 default:
112 return GL_FALSE;
113 }
114 }
115
116
117
118 /**
119 * Create a simple fragment shader that just passes through the fragment color.
120 */
121 static struct st_fragment_program *
122 make_frag_shader(struct st_context *st)
123 {
124 static const GLuint outputMapping[] = { 1, 0 };
125 GLcontext *ctx = st->ctx;
126 struct st_fragment_program *stfp;
127 struct gl_program *p;
128 GLboolean b;
129 GLuint interpMode[16];
130 GLuint i;
131
132 /* XXX temporary */
133 for (i = 0; i < 16; i++)
134 interpMode[i] = TGSI_INTERPOLATE_LINEAR;
135
136 p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
137 if (!p)
138 return NULL;
139
140 p->NumInstructions = 2;
141 p->Instructions = _mesa_alloc_instructions(2);
142 if (!p->Instructions) {
143 ctx->Driver.DeleteProgram(ctx, p);
144 return NULL;
145 }
146 _mesa_init_instructions(p->Instructions, 2);
147 /* MOV result.color, fragment.color; */
148 p->Instructions[0].Opcode = OPCODE_MOV;
149 p->Instructions[0].DstReg.File = PROGRAM_OUTPUT;
150 p->Instructions[0].DstReg.Index = FRAG_RESULT_COLR;
151 p->Instructions[0].SrcReg[0].File = PROGRAM_INPUT;
152 p->Instructions[0].SrcReg[0].Index = FRAG_ATTRIB_COL0;
153 /* END; */
154 p->Instructions[1].Opcode = OPCODE_END;
155
156 p->InputsRead = FRAG_BIT_COL0;
157 p->OutputsWritten = (1 << FRAG_RESULT_COLR);
158
159 stfp = (struct st_fragment_program *) p;
160 /* compile into tgsi format */
161 b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode,
162 outputMapping,
163 stfp->tokens, ST_FP_MAX_TOKENS);
164 assert(b);
165
166 return stfp;
167 }
168
169
170 /**
171 * Create a simple vertex shader that just passes through the
172 * vertex position and color.
173 */
174 static struct st_vertex_program *
175 make_vertex_shader(struct st_context *st)
176 {
177 /* Map VERT_ATTRIB_POS to 0, VERT_ATTRIB_COLOR0 to 1 */
178 static const GLuint inputMapping[4] = { 0, 0, 0, 1 };
179 /* Map VERT_RESULT_HPOS to 0, VERT_RESULT_COL0 to 1 */
180 static const GLuint outputMapping[2] = { 0, 1 };
181
182 GLcontext *ctx = st->ctx;
183 struct st_vertex_program *stvp;
184 struct gl_program *p;
185 GLboolean b;
186
187 p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
188 if (!p)
189 return NULL;
190
191 p->NumInstructions = 3;
192 p->Instructions = _mesa_alloc_instructions(3);
193 if (!p->Instructions) {
194 ctx->Driver.DeleteProgram(ctx, p);
195 return NULL;
196 }
197 _mesa_init_instructions(p->Instructions, 3);
198 /* MOV result.pos, vertex.pos; */
199 p->Instructions[0].Opcode = OPCODE_MOV;
200 p->Instructions[0].DstReg.File = PROGRAM_OUTPUT;
201 p->Instructions[0].DstReg.Index = VERT_RESULT_HPOS;
202 p->Instructions[0].SrcReg[0].File = PROGRAM_INPUT;
203 p->Instructions[0].SrcReg[0].Index = VERT_ATTRIB_POS;
204 /* MOV result.color, vertex.color; */
205 p->Instructions[1].Opcode = OPCODE_MOV;
206 p->Instructions[1].DstReg.File = PROGRAM_OUTPUT;
207 p->Instructions[1].DstReg.Index = VERT_RESULT_COL0;
208 p->Instructions[1].SrcReg[0].File = PROGRAM_INPUT;
209 p->Instructions[1].SrcReg[0].Index = VERT_ATTRIB_COLOR0;
210 /* END; */
211 p->Instructions[2].Opcode = OPCODE_END;
212
213 p->InputsRead = VERT_BIT_POS | VERT_BIT_COLOR0;
214 p->OutputsWritten = ((1 << VERT_RESULT_COL0) |
215 (1 << VERT_RESULT_HPOS));
216
217 stvp = (struct st_vertex_program *) p;
218 /* compile into tgsi format */
219 b = tgsi_mesa_compile_vp_program(&stvp->Base,
220 inputMapping,
221 outputMapping,
222 stvp->tokens, ST_FP_MAX_TOKENS);
223 assert(b);
224
225 return stvp;
226 }
227
228
229
230 /**
231 * Draw a screen-aligned quadrilateral.
232 * Coords are window coords with y=0=bottom. These coords will be transformed
233 * by the vertex shader and viewport transform (which will flip Y if needed).
234 */
235 static void
236 draw_quad(GLcontext *ctx,
237 float x0, float y0, float x1, float y1, GLfloat z,
238 const GLfloat color[4])
239 {
240 static const GLuint attribs[2] = {
241 0, /* pos */
242 3 /* color */
243 };
244 GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */
245 GLuint i;
246
247 /* positions */
248 verts[0][0][0] = x0;
249 verts[0][0][1] = y0;
250
251 verts[1][0][0] = x1;
252 verts[1][0][1] = y0;
253
254 verts[2][0][0] = x1;
255 verts[2][0][1] = y1;
256
257 verts[3][0][0] = x0;
258 verts[3][0][1] = y1;
259
260 /* same for all verts: */
261 for (i = 0; i < 4; i++) {
262 verts[i][0][2] = z;
263 verts[i][0][3] = 1.0;
264 verts[i][1][0] = color[0];
265 verts[i][1][1] = color[1];
266 verts[i][1][2] = color[2];
267 verts[i][1][3] = color[3];
268 }
269
270 st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, attribs);
271 }
272
273
274
275 /**
276 * Do glClear by drawing a quadrilateral.
277 * The vertices of the quad will be computed from the
278 * ctx->DrawBuffer->_X/Ymin/max fields.
279 */
280 static void
281 clear_with_quad(GLcontext *ctx,
282 GLboolean color, GLboolean depth, GLboolean stencil)
283 {
284 struct st_context *st = ctx->st;
285 struct pipe_context *pipe = ctx->st->pipe;
286 const GLfloat x0 = ctx->DrawBuffer->_Xmin;
287 const GLfloat y0 = ctx->DrawBuffer->_Ymin;
288 const GLfloat x1 = ctx->DrawBuffer->_Xmax;
289 const GLfloat y1 = ctx->DrawBuffer->_Ymax;
290
291 /* alpha state: disabled */
292 {
293 struct pipe_alpha_test_state alpha_test;
294 memset(&alpha_test, 0, sizeof(alpha_test));
295 pipe->set_alpha_test_state(pipe, &alpha_test);
296 }
297
298 /* blend state: RGBA masking */
299 {
300 struct pipe_blend_state blend;
301 const struct pipe_blend_state *state;
302 memset(&blend, 0, sizeof(blend));
303 if (color) {
304 if (ctx->Color.ColorMask[0])
305 blend.colormask |= PIPE_MASK_R;
306 if (ctx->Color.ColorMask[1])
307 blend.colormask |= PIPE_MASK_G;
308 if (ctx->Color.ColorMask[2])
309 blend.colormask |= PIPE_MASK_B;
310 if (ctx->Color.ColorMask[3])
311 blend.colormask |= PIPE_MASK_A;
312 if (st->ctx->Color.DitherFlag)
313 blend.dither = 1;
314 }
315 state = st_cached_blend_state(st, &blend);
316 pipe->bind_blend_state(pipe, state);
317 }
318
319 /* depth_stencil state: always pass/set to ref value */
320 {
321 struct pipe_depth_stencil_state depth_stencil;
322 struct pipe_depth_stencil_state *cached;
323 memset(&depth_stencil, 0, sizeof(depth_stencil));
324 if (depth) {
325 depth_stencil.depth.enabled = 1;
326 depth_stencil.depth.writemask = 1;
327 depth_stencil.depth.func = PIPE_FUNC_ALWAYS;
328 }
329
330 if (stencil) {
331 depth_stencil.stencil.front_enabled = 1;
332 depth_stencil.stencil.front_func = PIPE_FUNC_ALWAYS;
333 depth_stencil.stencil.front_fail_op = PIPE_STENCIL_OP_REPLACE;
334 depth_stencil.stencil.front_zpass_op = PIPE_STENCIL_OP_REPLACE;
335 depth_stencil.stencil.front_zfail_op = PIPE_STENCIL_OP_REPLACE;
336 depth_stencil.stencil.ref_value[0] = ctx->Stencil.Clear;
337 depth_stencil.stencil.value_mask[0] = 0xff;
338 depth_stencil.stencil.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff;
339 }
340 cached =
341 st_cached_depth_stencil_state(ctx->st, &depth_stencil);
342 pipe->bind_depth_stencil_state(pipe, cached);
343 }
344
345 /* setup state: nothing */
346 {
347 struct pipe_rasterizer_state raster;
348 const struct pipe_rasterizer_state *cached;
349 memset(&raster, 0, sizeof(raster));
350 #if 0
351 /* don't do per-pixel scissor; we'll just draw a PIPE_PRIM_QUAD
352 * that matches the scissor bounds.
353 */
354 if (ctx->Scissor.Enabled)
355 raster.scissor = 1;
356 #endif
357 cached = st_cached_rasterizer_state(ctx->st, &raster);
358 pipe->bind_rasterizer_state(pipe, cached);
359 }
360
361 /* fragment shader state: color pass-through program */
362 {
363 static struct st_fragment_program *stfp = NULL;
364 struct pipe_shader_state fs;
365 const struct pipe_shader_state *cached;
366 if (!stfp) {
367 stfp = make_frag_shader(st);
368 }
369 memset(&fs, 0, sizeof(fs));
370 fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead);
371 fs.outputs_written = tgsi_mesa_translate_fragment_output_mask(stfp->Base.Base.OutputsWritten);
372 fs.tokens = &stfp->tokens[0];
373 cached = st_cached_fs_state(st, &fs);
374 pipe->bind_fs_state(pipe, cached);
375 }
376
377 /* vertex shader state: color/position pass-through */
378 {
379 static struct st_vertex_program *stvp = NULL;
380 struct pipe_shader_state vs;
381 const struct pipe_shader_state *cached;
382 if (!stvp) {
383 stvp = make_vertex_shader(st);
384 }
385 memset(&vs, 0, sizeof(vs));
386 vs.inputs_read = stvp->Base.Base.InputsRead;
387 vs.outputs_written = stvp->Base.Base.OutputsWritten;
388 vs.tokens = &stvp->tokens[0];
389 cached = st_cached_vs_state(st, &vs);
390 pipe->bind_vs_state(pipe, cached);
391 }
392
393 /* viewport state: viewport matching window dims */
394 {
395 const float width = ctx->DrawBuffer->Width;
396 const float height = ctx->DrawBuffer->Height;
397 struct pipe_viewport_state vp;
398 vp.scale[0] = 0.5 * width;
399 vp.scale[1] = -0.5 * height;
400 vp.scale[2] = 0.5;
401 vp.scale[3] = 1.0;
402 vp.translate[0] = 0.5 * width;
403 vp.translate[1] = 0.5 * height;
404 vp.translate[2] = 0.5;
405 vp.translate[3] = 0.0;
406 pipe->set_viewport_state(pipe, &vp);
407 }
408
409 /* draw quad matching scissor rect (XXX verify coord round-off) */
410 draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor);
411
412 /* Restore pipe state */
413 pipe->set_alpha_test_state(pipe, &st->state.alpha_test);
414 pipe->bind_blend_state(pipe, st->state.blend);
415 pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil);
416 pipe->bind_fs_state(pipe, st->state.fs);
417 pipe->bind_vs_state(pipe, st->state.vs);
418 pipe->bind_rasterizer_state(pipe, st->state.rasterizer);
419 pipe->set_viewport_state(pipe, &ctx->st->state.viewport);
420 /* OR:
421 st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL);
422 */
423 }
424
425
426 /**
427 * Determine if we need to clear the depth buffer by drawing a quad.
428 */
429 static INLINE GLboolean
430 check_clear_color_with_quad(GLcontext *ctx)
431 {
432 return !(ctx->Color.ColorMask[0] &&
433 ctx->Color.ColorMask[1] &&
434 ctx->Color.ColorMask[2] &&
435 ctx->Color.ColorMask[3] &&
436 !ctx->Scissor.Enabled);
437 }
438
439
440 /**
441 * Determine if we need to clear the depth buffer by drawing a quad.
442 */
443 static INLINE GLboolean
444 check_clear_depth_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
445 {
446 const struct st_renderbuffer *strb = st_renderbuffer(rb);
447 const GLboolean isDS = is_depth_stencil_format(strb->surface->format);
448 return ctx->Scissor.Enabled
449 || (isDS && ctx->DrawBuffer->Visual.stencilBits > 0);
450 }
451
452
453 /**
454 * Determine if we need to clear the stencil buffer by drawing a quad.
455 */
456 static INLINE GLboolean
457 check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
458 {
459 const struct st_renderbuffer *strb = st_renderbuffer(rb);
460 const GLboolean isDS = is_depth_stencil_format(strb->surface->format);
461 const GLuint stencilMax = (1 << rb->StencilBits) - 1;
462 const GLboolean maskStencil
463 = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
464 return maskStencil
465 || ctx->Scissor.Enabled
466 || (isDS && ctx->DrawBuffer->Visual.depthBits > 0);
467 }
468
469
470
471
472 static void
473 clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
474 {
475 struct st_renderbuffer *strb = st_renderbuffer(rb);
476
477 if (ctx->Color.ColorMask[0] &&
478 ctx->Color.ColorMask[1] &&
479 ctx->Color.ColorMask[2] &&
480 ctx->Color.ColorMask[3] &&
481 !ctx->Scissor.Enabled)
482 {
483 /* clear whole buffer w/out masking */
484 GLuint clearValue
485 = color_value(strb->surface->format, ctx->Color.ClearColor);
486 ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
487 }
488 else {
489 /* masking or scissoring */
490 clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE);
491 }
492 }
493
494
495 static void
496 clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
497 {
498 struct st_renderbuffer *strb = st_renderbuffer(rb);
499
500 if (!ctx->Scissor.Enabled) {
501 /* clear whole buffer w/out masking */
502 GLuint clearValue
503 = color_value(strb->surface->format, ctx->Accum.ClearColor);
504 /* Note that clearValue is 32 bits but the accum buffer will
505 * typically be 64bpp...
506 */
507 ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
508 }
509 else {
510 /* scissoring */
511 /* XXX point framebuffer.cbufs[0] at the accum buffer */
512 clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE);
513 }
514 }
515
516
517 static void
518 clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
519 {
520 struct st_renderbuffer *strb = st_renderbuffer(rb);
521 const GLboolean isDS = is_depth_stencil_format(strb->surface->format);
522
523 assert(strb->surface->format);
524
525 if (ctx->Scissor.Enabled ||
526 (isDS && ctx->DrawBuffer->Visual.stencilBits > 0)) {
527 /* scissoring or we have a combined depth/stencil buffer */
528 clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE);
529 }
530 else {
531 /* simple clear of whole buffer */
532 GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear);
533 ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
534 }
535 }
536
537
538 static void
539 clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
540 {
541 struct st_renderbuffer *strb = st_renderbuffer(rb);
542 const GLboolean isDS = is_depth_stencil_format(strb->surface->format);
543 const GLuint stencilMax = (1 << rb->StencilBits) - 1;
544 GLboolean maskStencil
545 = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
546
547 if (maskStencil ||
548 ctx->Scissor.Enabled ||
549 (isDS && ctx->DrawBuffer->Visual.depthBits > 0)) {
550 /* masking or scissoring or combined depth/stencil buffer */
551 clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE);
552 }
553 else {
554 /* simple clear of whole buffer */
555 GLuint clearValue = ctx->Stencil.Clear;
556 ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
557 }
558 }
559
560
561 static void
562 clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
563 {
564 struct st_renderbuffer *strb = st_renderbuffer(rb);
565 const GLuint stencilMax = (1 << rb->StencilBits) - 1;
566 GLboolean maskStencil
567 = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
568
569 assert(is_depth_stencil_format(strb->surface->format));
570
571 if (!maskStencil && !ctx->Scissor.Enabled) {
572 /* clear whole buffer w/out masking */
573 GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear);
574
575 switch (strb->surface->format) {
576 case PIPE_FORMAT_S8_Z24:
577 clearValue |= ctx->Stencil.Clear << 24;
578 break;
579 #if 0
580 case PIPE_FORMAT_Z24_S8:
581 clearValue = (clearValue << 8) | clearVal;
582 break;
583 #endif
584 default:
585 assert(0);
586 }
587
588 ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
589 }
590 else {
591 /* masking or scissoring */
592 clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE);
593 }
594 }
595
596
597
598 /**
599 * Called via ctx->Driver.Clear()
600 * XXX: doesn't pick up the differences between front/back/left/right
601 * clears. Need to sort that out...
602 */
603 static void st_clear(GLcontext *ctx, GLbitfield mask)
604 {
605 static const GLbitfield BUFFER_BITS_DS
606 = (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL);
607 struct st_context *st = ctx->st;
608 struct gl_renderbuffer *depthRb
609 = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
610 struct gl_renderbuffer *stencilRb
611 = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
612 GLbitfield cmask = mask & BUFFER_BITS_COLOR;
613
614 /* This makes sure the softpipe has the latest scissor, etc values */
615 st_validate_state( st );
616
617 /*
618 * XXX TO-DO:
619 * If we're going to use clear_with_quad() for any reason, use it to
620 * clear as many other buffers as possible.
621 * As it is now, we sometimes call clear_with_quad() three times to clear
622 * color/depth/stencil individually...
623 */
624
625 if (cmask) {
626 GLuint b;
627 for (b = 0; cmask; b++) {
628 if (cmask & (1 << b)) {
629 struct gl_renderbuffer *rb
630 = ctx->DrawBuffer->Attachment[b].Renderbuffer;
631 assert(rb);
632 clear_color_buffer(ctx, rb);
633 cmask &= ~(1 << b); /* turn off bit */
634 }
635 assert(b < BUFFER_COUNT);
636 }
637 }
638
639 if (mask & BUFFER_BIT_ACCUM) {
640 clear_accum_buffer(ctx,
641 ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
642 }
643
644 if ((mask & BUFFER_BITS_DS) == BUFFER_BITS_DS && depthRb == stencilRb) {
645 /* clearing combined depth + stencil */
646 clear_depth_stencil_buffer(ctx, depthRb);
647 }
648 else {
649 /* separate depth/stencil clears */
650 if (mask & BUFFER_BIT_DEPTH) {
651 clear_depth_buffer(ctx, depthRb);
652 }
653 if (mask & BUFFER_BIT_STENCIL) {
654 clear_stencil_buffer(ctx, stencilRb);
655 }
656 }
657 }
658
659
660 void st_init_clear_functions(struct dd_function_table *functions)
661 {
662 functions->Clear = st_clear;
663 }