1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
33 #include "pipe/p_defines.h"
35 #include "sp_context.h"
36 #include "sp_surface.h"
42 color_value(GLuint format
, const GLfloat color
[4])
46 UNCLAMPED_FLOAT_TO_UBYTE(r
, color
[0]);
47 UNCLAMPED_FLOAT_TO_UBYTE(g
, color
[1]);
48 UNCLAMPED_FLOAT_TO_UBYTE(b
, color
[2]);
49 UNCLAMPED_FLOAT_TO_UBYTE(a
, color
[3]);
52 case PIPE_FORMAT_U_R8_G8_B8_A8
:
53 return (r
<< 24) | (g
<< 16) | (b
<< 8) | a
;
54 case PIPE_FORMAT_U_A8_R8_G8_B8
:
55 return (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
56 case PIPE_FORMAT_U_R5_G6_B5
:
57 return ((r
& 0xf8) << 8) | ((g
& 0xfc) << 3) | (b
>> 3);
65 softpipe_clear(struct pipe_context
*pipe
, GLboolean color
, GLboolean depth
,
66 GLboolean stencil
, GLboolean accum
)
68 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
71 softpipe_update_derived(softpipe
); /* not needed?? */
75 w
= softpipe
->framebuffer
.cbufs
[0]->width
;
76 h
= softpipe
->framebuffer
.cbufs
[0]->height
;
80 for (i
= 0; i
< softpipe
->framebuffer
.num_cbufs
; i
++) {
81 struct pipe_surface
*ps
= softpipe
->framebuffer
.cbufs
[i
];
82 GLuint clearVal
= color_value(ps
->format
,
83 softpipe
->clear_color
.color
);
84 pipe
->region_fill(pipe
, ps
->region
, 0, x
, y
, w
, h
, clearVal
, ~0);
88 if (depth
&& stencil
&&
89 softpipe
->framebuffer
.zbuf
== softpipe
->framebuffer
.sbuf
) {
90 /* clear Z and stencil together */
91 struct pipe_surface
*ps
= softpipe
->framebuffer
.zbuf
;
92 if (ps
->format
== PIPE_FORMAT_S8_Z24
) {
93 GLuint mask
= (softpipe
->stencil
.write_mask
[0] << 8) | 0xffffff;
94 GLuint clearVal
= (GLuint
) (softpipe
->depth_test
.clear
* 0xffffff);
98 clearVal
|= (softpipe
->stencil
.clear_value
<< 24);
99 pipe
->region_fill(pipe
, ps
->region
, 0, x
, y
, w
, h
, clearVal
, ~0);
102 /* XXX Z24_S8 format? */
107 /* separate Z and stencil */
109 struct pipe_surface
*ps
= softpipe
->framebuffer
.zbuf
;
112 switch (ps
->format
) {
113 case PIPE_FORMAT_U_Z16
:
114 clearVal
= (GLuint
) (softpipe
->depth_test
.clear
* 65535.0);
116 case PIPE_FORMAT_U_Z32
:
117 clearVal
= (GLuint
) (softpipe
->depth_test
.clear
* 0xffffffff);
119 case PIPE_FORMAT_S8_Z24
:
120 clearVal
= (GLuint
) (softpipe
->depth_test
.clear
* 0xffffff);
126 pipe
->region_fill(pipe
, ps
->region
, 0, x
, y
, w
, h
, clearVal
, ~0);
130 struct pipe_surface
*ps
= softpipe
->framebuffer
.sbuf
;
131 GLuint clearVal
= softpipe
->stencil
.clear_value
;
133 /* If this is not ~0, we shouldn't get here - clear should be
134 * done with geometry instead.
136 GLuint mask
= softpipe
->stencil
.write_mask
[0];
138 assert((mask
& 0xff) == 0xff);
140 switch (ps
->format
) {
141 case PIPE_FORMAT_S8_Z24
:
142 clearVal
= clearVal
<< 24;
145 case PIPE_FORMAT_U_S8
:
152 pipe
->region_fill(pipe
, ps
->region
, 0, x
, y
, w
, h
, clearVal
, mask
);
157 /* XXX there might be no notion of accum buffers in 'pipe'.
158 * Just implement them with a deep RGBA surface format...
160 struct pipe_surface
*ps
= softpipe
->framebuffer
.abuf
;
161 GLuint clearVal
= 0x0; /* XXX FIX */
164 pipe
->region_fill(pipe
, ps
->region
, 0, x
, y
, w
, h
, clearVal
, mask
);