2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
28 * glClearColor, glClearIndex, glClear() functions.
46 _mesa_ClearIndex( GLfloat c
)
48 GET_CURRENT_CONTEXT(ctx
);
49 ASSERT_OUTSIDE_BEGIN_END(ctx
);
51 if (ctx
->Color
.ClearIndex
== (GLuint
) c
)
54 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
55 ctx
->Color
.ClearIndex
= (GLuint
) c
;
61 * Specify the clear values for the color buffers.
63 * \param red red color component.
64 * \param green green color component.
65 * \param blue blue color component.
66 * \param alpha alpha component.
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.
75 _mesa_ClearColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
78 GET_CURRENT_CONTEXT(ctx
);
79 ASSERT_OUTSIDE_BEGIN_END(ctx
);
86 if (TEST_EQ_4V(tmp
, ctx
->Color
.ClearColor
.f
))
87 return; /* no change */
89 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
90 COPY_4V(ctx
->Color
.ClearColor
.f
, tmp
);
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
97 (*ctx
->Driver
.ClearColor
)(ctx
, ctx
->Color
.ClearColor
);
103 * GL_EXT_texture_integer
106 _mesa_ClearColorIiEXT(GLint r
, GLint g
, GLint b
, GLint a
)
109 GET_CURRENT_CONTEXT(ctx
);
110 ASSERT_OUTSIDE_BEGIN_END(ctx
);
117 if (TEST_EQ_4V(tmp
, ctx
->Color
.ClearColor
.i
))
118 return; /* no change */
120 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
121 COPY_4V(ctx
->Color
.ClearColor
.i
, tmp
);
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
);
131 * GL_EXT_texture_integer
134 _mesa_ClearColorIuiEXT(GLuint r
, GLuint g
, GLuint b
, GLuint a
)
137 GET_CURRENT_CONTEXT(ctx
);
138 ASSERT_OUTSIDE_BEGIN_END(ctx
);
145 if (TEST_EQ_4V(tmp
, ctx
->Color
.ClearColor
.ui
))
146 return; /* no change */
148 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
149 COPY_4V(ctx
->Color
.ClearColor
.ui
, tmp
);
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
);
161 * \param mask bit-mask indicating the buffers to be cleared.
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.
169 _mesa_Clear( GLbitfield mask
)
171 GET_CURRENT_CONTEXT(ctx
);
172 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
174 FLUSH_CURRENT(ctx
, 0);
176 if (MESA_VERBOSE
& VERBOSE_API
)
177 _mesa_debug(ctx
, "glClear 0x%x\n", mask
);
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
);
189 _mesa_update_state( ctx
); /* update _Xmin, etc */
192 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
193 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
194 "glClear(incomplete framebuffer)");
198 if (ctx
->DrawBuffer
->Width
== 0 || ctx
->DrawBuffer
->Height
== 0 ||
199 ctx
->DrawBuffer
->_Xmin
>= ctx
->DrawBuffer
->_Xmax
||
200 ctx
->DrawBuffer
->_Ymin
>= ctx
->DrawBuffer
->_Ymax
)
203 if (ctx
->RasterDiscard
)
206 if (ctx
->RenderMode
== GL_RENDER
) {
207 GLbitfield bufferMask
;
209 /* don't clear depth buffer if depth writing disabled */
210 if (!ctx
->Depth
.Mask
)
211 mask
&= ~GL_DEPTH_BUFFER_BIT
;
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.
219 if (mask
& GL_COLOR_BUFFER_BIT
) {
221 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
222 bufferMask
|= (1 << ctx
->DrawBuffer
->_ColorDrawBufferIndexes
[i
]);
226 if ((mask
& GL_DEPTH_BUFFER_BIT
)
227 && ctx
->DrawBuffer
->Visual
.haveDepthBuffer
) {
228 bufferMask
|= BUFFER_BIT_DEPTH
;
231 if ((mask
& GL_STENCIL_BUFFER_BIT
)
232 && ctx
->DrawBuffer
->Visual
.haveStencilBuffer
) {
233 bufferMask
|= BUFFER_BIT_STENCIL
;
236 if ((mask
& GL_ACCUM_BUFFER_BIT
)
237 && ctx
->DrawBuffer
->Visual
.haveAccumBuffer
) {
238 bufferMask
|= BUFFER_BIT_ACCUM
;
241 ASSERT(ctx
->Driver
.Clear
);
242 ctx
->Driver
.Clear(ctx
, bufferMask
);