gallium: move clear paths from rgba to a pointer to a color union (v2)
[mesa.git] / src / gallium / drivers / cell / ppu / cell_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 * Brian Paul
31 */
32
33 #include <stdio.h>
34 #include <assert.h>
35 #include <stdint.h>
36 #include "util/u_inlines.h"
37 #include "util/u_memory.h"
38 #include "util/u_pack_color.h"
39 #include "cell/common.h"
40 #include "cell_clear.h"
41 #include "cell_context.h"
42 #include "cell_batch.h"
43 #include "cell_flush.h"
44 #include "cell_spu.h"
45 #include "cell_state.h"
46
47
48 /**
49 * Called via pipe->clear()
50 */
51 void
52 cell_clear(struct pipe_context *pipe, unsigned buffers,
53 const pipe_color_union *color,
54 double depth, unsigned stencil)
55 {
56 struct cell_context *cell = cell_context(pipe);
57
58 if (cell->dirty)
59 cell_update_derived(cell);
60
61 if (buffers & PIPE_CLEAR_COLOR) {
62 uint surfIndex = 0;
63 union util_color uc;
64
65 util_pack_color(color->f, cell->framebuffer.cbufs[0]->format, &uc);
66
67 /* Build a CLEAR command and place it in the current batch buffer */
68 STATIC_ASSERT(sizeof(struct cell_command_clear_surface) % 16 == 0);
69 struct cell_command_clear_surface *clr
70 = (struct cell_command_clear_surface *)
71 cell_batch_alloc16(cell, sizeof(*clr));
72 clr->opcode[0] = CELL_CMD_CLEAR_SURFACE;
73 clr->surface = surfIndex;
74 clr->value = uc.ui;
75 }
76
77 if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
78 uint surfIndex = 1;
79 uint clearValue;
80
81 clearValue = util_pack_z_stencil(cell->framebuffer.zsbuf->format,
82 depth, stencil);
83
84 /* Build a CLEAR command and place it in the current batch buffer */
85 STATIC_ASSERT(sizeof(struct cell_command_clear_surface) % 16 == 0);
86 struct cell_command_clear_surface *clr
87 = (struct cell_command_clear_surface *)
88 cell_batch_alloc16(cell, sizeof(*clr));
89 clr->opcode[0] = CELL_CMD_CLEAR_SURFACE;
90 clr->surface = surfIndex;
91 clr->value = clearValue;
92 }
93 }