Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1999-2007 Brian Paul 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 "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
Kenneth Graunke | 3d8d5b2 | 2013-04-21 13:46:48 -0700 | [diff] [blame] | 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * \file clear.c |
| 28 | * glClearColor, glClearIndex, glClear() functions. |
| 29 | */ |
| 30 | |
| 31 | |
| 32 | |
Nanley Chery | d47cb41 | 2020-11-02 09:02:42 -0800 | [diff] [blame^] | 33 | #include "glformats.h" |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 34 | #include "glheader.h" |
| 35 | #include "clear.h" |
| 36 | #include "context.h" |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 37 | #include "enums.h" |
Laura Ekstrand | 6236c47 | 2015-02-05 13:24:43 -0800 | [diff] [blame] | 38 | #include "fbobject.h" |
| 39 | #include "get.h" |
Vinson Lee | 3fdd9fa | 2010-07-30 00:41:08 -0700 | [diff] [blame] | 40 | #include "macros.h" |
Vinson Lee | 0117da4 | 2011-01-05 23:11:54 -0800 | [diff] [blame] | 41 | #include "mtypes.h" |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 42 | #include "state.h" |
| 43 | |
| 44 | |
| 45 | |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 46 | void GLAPIENTRY |
| 47 | _mesa_ClearIndex( GLfloat c ) |
| 48 | { |
| 49 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 50 | |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 51 | ctx->Color.ClearIndex = (GLuint) c; |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 52 | } |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 53 | |
| 54 | |
| 55 | /** |
| 56 | * Specify the clear values for the color buffers. |
| 57 | * |
| 58 | * \param red red color component. |
| 59 | * \param green green color component. |
| 60 | * \param blue blue color component. |
| 61 | * \param alpha alpha component. |
| 62 | * |
| 63 | * \sa glClearColor(). |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 64 | */ |
| 65 | void GLAPIENTRY |
| 66 | _mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) |
| 67 | { |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 68 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 69 | |
Marek Olšák | 3140d13 | 2013-04-15 03:41:43 +0200 | [diff] [blame] | 70 | ctx->Color.ClearColor.f[0] = red; |
| 71 | ctx->Color.ClearColor.f[1] = green; |
| 72 | ctx->Color.ClearColor.f[2] = blue; |
| 73 | ctx->Color.ClearColor.f[3] = alpha; |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | |
| 77 | /** |
Brian Paul | a0bc8ee | 2010-10-23 09:26:10 -0600 | [diff] [blame] | 78 | * GL_EXT_texture_integer |
| 79 | */ |
| 80 | void GLAPIENTRY |
| 81 | _mesa_ClearColorIiEXT(GLint r, GLint g, GLint b, GLint a) |
| 82 | { |
Brian Paul | a0bc8ee | 2010-10-23 09:26:10 -0600 | [diff] [blame] | 83 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | a0bc8ee | 2010-10-23 09:26:10 -0600 | [diff] [blame] | 84 | |
Marek Olšák | 3140d13 | 2013-04-15 03:41:43 +0200 | [diff] [blame] | 85 | ctx->Color.ClearColor.i[0] = r; |
| 86 | ctx->Color.ClearColor.i[1] = g; |
| 87 | ctx->Color.ClearColor.i[2] = b; |
| 88 | ctx->Color.ClearColor.i[3] = a; |
Brian Paul | a0bc8ee | 2010-10-23 09:26:10 -0600 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | |
| 92 | /** |
| 93 | * GL_EXT_texture_integer |
| 94 | */ |
| 95 | void GLAPIENTRY |
| 96 | _mesa_ClearColorIuiEXT(GLuint r, GLuint g, GLuint b, GLuint a) |
| 97 | { |
Brian Paul | a0bc8ee | 2010-10-23 09:26:10 -0600 | [diff] [blame] | 98 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | a0bc8ee | 2010-10-23 09:26:10 -0600 | [diff] [blame] | 99 | |
Marek Olšák | 3140d13 | 2013-04-15 03:41:43 +0200 | [diff] [blame] | 100 | ctx->Color.ClearColor.ui[0] = r; |
| 101 | ctx->Color.ClearColor.ui[1] = g; |
| 102 | ctx->Color.ClearColor.ui[2] = b; |
| 103 | ctx->Color.ClearColor.ui[3] = a; |
Brian Paul | a0bc8ee | 2010-10-23 09:26:10 -0600 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | |
| 107 | /** |
Kenneth Graunke | 630bf28 | 2014-03-21 15:58:02 -0700 | [diff] [blame] | 108 | * Returns true if color writes are enabled for the given color attachment. |
| 109 | * |
| 110 | * Beyond checking ColorMask, this uses _mesa_format_has_color_component to |
| 111 | * ignore components that don't actually exist in the format (such as X in |
| 112 | * XRGB). |
| 113 | */ |
| 114 | static bool |
| 115 | color_buffer_writes_enabled(const struct gl_context *ctx, unsigned idx) |
| 116 | { |
| 117 | struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[idx]; |
| 118 | GLuint c; |
Kenneth Graunke | 630bf28 | 2014-03-21 15:58:02 -0700 | [diff] [blame] | 119 | |
| 120 | if (rb) { |
| 121 | for (c = 0; c < 4; c++) { |
Marek Olšák | af3685d | 2018-01-31 03:03:25 +0100 | [diff] [blame] | 122 | if (GET_COLORMASK_BIT(ctx->Color.ColorMask, idx, c) && |
Brian Paul | 6b60153 | 2017-04-27 08:52:30 -0600 | [diff] [blame] | 123 | _mesa_format_has_color_component(rb->Format, c)) { |
| 124 | return true; |
| 125 | } |
Kenneth Graunke | 630bf28 | 2014-03-21 15:58:02 -0700 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
Brian Paul | 6b60153 | 2017-04-27 08:52:30 -0600 | [diff] [blame] | 129 | return false; |
Kenneth Graunke | 630bf28 | 2014-03-21 15:58:02 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
| 133 | /** |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 134 | * Clear buffers. |
Brian Paul | e725dc0 | 2014-12-12 16:45:33 -0700 | [diff] [blame] | 135 | * |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 136 | * \param mask bit-mask indicating the buffers to be cleared. |
| 137 | * |
Brian Paul | e725dc0 | 2014-12-12 16:45:33 -0700 | [diff] [blame] | 138 | * Flushes the vertices and verifies the parameter. |
Jakob Bornecrantz | 0917170 | 2018-09-19 15:21:26 +0100 | [diff] [blame] | 139 | * If __struct gl_contextRec::NewState is set then calls _mesa_update_state() |
| 140 | * to update gl_frame_buffer::_Xmin, etc. If the rasterization mode is set to |
| 141 | * GL_RENDER then requests the driver to clear the buffers, via the |
| 142 | * dd_function_table::Clear callback. |
Brian Paul | e725dc0 | 2014-12-12 16:45:33 -0700 | [diff] [blame] | 143 | */ |
Samuel Pitoiset | 34e8d0e | 2017-06-26 17:44:44 +0200 | [diff] [blame] | 144 | static ALWAYS_INLINE void |
| 145 | clear(struct gl_context *ctx, GLbitfield mask, bool no_error) |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 146 | { |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 147 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 148 | |
Samuel Pitoiset | 34e8d0e | 2017-06-26 17:44:44 +0200 | [diff] [blame] | 149 | if (!no_error) { |
| 150 | if (mask & ~(GL_COLOR_BUFFER_BIT | |
| 151 | GL_DEPTH_BUFFER_BIT | |
| 152 | GL_STENCIL_BUFFER_BIT | |
| 153 | GL_ACCUM_BUFFER_BIT)) { |
| 154 | _mesa_error( ctx, GL_INVALID_VALUE, "glClear(0x%x)", mask); |
| 155 | return; |
| 156 | } |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 157 | |
Samuel Pitoiset | 34e8d0e | 2017-06-26 17:44:44 +0200 | [diff] [blame] | 158 | /* Accumulation buffers were removed in core contexts, and they never |
| 159 | * existed in OpenGL ES. |
| 160 | */ |
| 161 | if ((mask & GL_ACCUM_BUFFER_BIT) != 0 |
| 162 | && (ctx->API == API_OPENGL_CORE || _mesa_is_gles(ctx))) { |
| 163 | _mesa_error( ctx, GL_INVALID_VALUE, "glClear(GL_ACCUM_BUFFER_BIT)"); |
| 164 | return; |
| 165 | } |
Ian Romanick | e58c19a | 2011-09-20 16:39:30 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Jakob Bornecrantz | 0917170 | 2018-09-19 15:21:26 +0100 | [diff] [blame] | 168 | if (ctx->NewState) { |
| 169 | _mesa_update_state( ctx ); /* update _Xmin, etc */ |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 170 | } |
| 171 | |
Samuel Pitoiset | 34e8d0e | 2017-06-26 17:44:44 +0200 | [diff] [blame] | 172 | if (!no_error && ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 173 | _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, |
| 174 | "glClear(incomplete framebuffer)"); |
| 175 | return; |
| 176 | } |
| 177 | |
Paul Berry | aee9680 | 2011-12-20 16:18:39 -0800 | [diff] [blame] | 178 | if (ctx->RasterDiscard) |
Eric Anholt | e7c2b71 | 2011-09-29 23:13:44 -0700 | [diff] [blame] | 179 | return; |
| 180 | |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 181 | if (ctx->RenderMode == GL_RENDER) { |
| 182 | GLbitfield bufferMask; |
| 183 | |
| 184 | /* don't clear depth buffer if depth writing disabled */ |
| 185 | if (!ctx->Depth.Mask) |
| 186 | mask &= ~GL_DEPTH_BUFFER_BIT; |
| 187 | |
| 188 | /* Build the bitmask to send to device driver's Clear function. |
| 189 | * Note that the GL_COLOR_BUFFER_BIT flag will expand to 0, 1, 2 or 4 |
| 190 | * of the BUFFER_BIT_FRONT/BACK_LEFT/RIGHT flags, or one of the |
| 191 | * BUFFER_BIT_COLORn flags. |
| 192 | */ |
| 193 | bufferMask = 0; |
| 194 | if (mask & GL_COLOR_BUFFER_BIT) { |
| 195 | GLuint i; |
| 196 | for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) { |
Brian Paul | f8bae52 | 2017-11-08 22:18:40 -0700 | [diff] [blame] | 197 | gl_buffer_index buf = ctx->DrawBuffer->_ColorDrawBufferIndexes[i]; |
Marek Olšák | 9bf9578 | 2014-01-08 01:23:43 +0100 | [diff] [blame] | 198 | |
Brian Paul | f8bae52 | 2017-11-08 22:18:40 -0700 | [diff] [blame] | 199 | if (buf != BUFFER_NONE && color_buffer_writes_enabled(ctx, i)) { |
Marek Olšák | 9bf9578 | 2014-01-08 01:23:43 +0100 | [diff] [blame] | 200 | bufferMask |= 1 << buf; |
| 201 | } |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | if ((mask & GL_DEPTH_BUFFER_BIT) |
Adam Jackson | 78e0fa6 | 2019-09-06 11:51:23 -0400 | [diff] [blame] | 206 | && ctx->DrawBuffer->Visual.depthBits > 0) { |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 207 | bufferMask |= BUFFER_BIT_DEPTH; |
| 208 | } |
| 209 | |
| 210 | if ((mask & GL_STENCIL_BUFFER_BIT) |
Adam Jackson | 78e0fa6 | 2019-09-06 11:51:23 -0400 | [diff] [blame] | 211 | && ctx->DrawBuffer->Visual.stencilBits > 0) { |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 212 | bufferMask |= BUFFER_BIT_STENCIL; |
| 213 | } |
| 214 | |
| 215 | if ((mask & GL_ACCUM_BUFFER_BIT) |
Adam Jackson | 78e0fa6 | 2019-09-06 11:51:23 -0400 | [diff] [blame] | 216 | && ctx->DrawBuffer->Visual.accumRedBits > 0) { |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 217 | bufferMask |= BUFFER_BIT_ACCUM; |
| 218 | } |
| 219 | |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 220 | assert(ctx->Driver.Clear); |
Brian Paul | 5ab1d0a | 2008-06-09 15:01:02 -0600 | [diff] [blame] | 221 | ctx->Driver.Clear(ctx, bufferMask); |
| 222 | } |
| 223 | } |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 224 | |
| 225 | |
Samuel Pitoiset | 34e8d0e | 2017-06-26 17:44:44 +0200 | [diff] [blame] | 226 | void GLAPIENTRY |
Samuel Pitoiset | e529ade | 2017-06-26 17:46:39 +0200 | [diff] [blame] | 227 | _mesa_Clear_no_error(GLbitfield mask) |
| 228 | { |
| 229 | GET_CURRENT_CONTEXT(ctx); |
| 230 | clear(ctx, mask, true); |
| 231 | } |
| 232 | |
| 233 | |
| 234 | void GLAPIENTRY |
Samuel Pitoiset | 34e8d0e | 2017-06-26 17:44:44 +0200 | [diff] [blame] | 235 | _mesa_Clear(GLbitfield mask) |
| 236 | { |
| 237 | GET_CURRENT_CONTEXT(ctx); |
| 238 | |
| 239 | if (MESA_VERBOSE & VERBOSE_API) |
| 240 | _mesa_debug(ctx, "glClear 0x%x\n", mask); |
| 241 | |
| 242 | clear(ctx, mask, false); |
| 243 | } |
| 244 | |
| 245 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 246 | /** Returned by make_color_buffer_mask() for errors */ |
Jan Vesely | 3cb10cc | 2015-01-15 13:41:04 -0500 | [diff] [blame] | 247 | #define INVALID_MASK ~0x0U |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 248 | |
| 249 | |
| 250 | /** |
| 251 | * Convert the glClearBuffer 'drawbuffer' parameter into a bitmask of |
| 252 | * BUFFER_BIT_x values. |
| 253 | * Return INVALID_MASK if the drawbuffer value is invalid. |
| 254 | */ |
| 255 | static GLbitfield |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 256 | make_color_buffer_mask(struct gl_context *ctx, GLint drawbuffer) |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 257 | { |
| 258 | const struct gl_renderbuffer_attachment *att = ctx->DrawBuffer->Attachment; |
| 259 | GLbitfield mask = 0x0; |
| 260 | |
Marek Olšák | 03d848e | 2013-12-04 00:27:20 +0100 | [diff] [blame] | 261 | /* From the GL 4.0 specification: |
| 262 | * If buffer is COLOR, a particular draw buffer DRAW_BUFFERi is |
| 263 | * specified by passing i as the parameter drawbuffer, and value |
| 264 | * points to a four-element vector specifying the R, G, B, and A |
| 265 | * color to clear that draw buffer to. If the draw buffer is one |
| 266 | * of FRONT, BACK, LEFT, RIGHT, or FRONT_AND_BACK, identifying |
| 267 | * multiple buffers, each selected buffer is cleared to the same |
| 268 | * value. |
| 269 | * |
| 270 | * Note that "drawbuffer" and "draw buffer" have different meaning. |
| 271 | * "drawbuffer" specifies DRAW_BUFFERi, while "draw buffer" is what's |
| 272 | * assigned to DRAW_BUFFERi. It could be COLOR_ATTACHMENT0, FRONT, BACK, |
| 273 | * etc. |
| 274 | */ |
| 275 | if (drawbuffer < 0 || drawbuffer >= (GLint)ctx->Const.MaxDrawBuffers) { |
| 276 | return INVALID_MASK; |
| 277 | } |
| 278 | |
| 279 | switch (ctx->DrawBuffer->ColorDrawBuffer[drawbuffer]) { |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 280 | case GL_FRONT: |
| 281 | if (att[BUFFER_FRONT_LEFT].Renderbuffer) |
| 282 | mask |= BUFFER_BIT_FRONT_LEFT; |
| 283 | if (att[BUFFER_FRONT_RIGHT].Renderbuffer) |
| 284 | mask |= BUFFER_BIT_FRONT_RIGHT; |
| 285 | break; |
| 286 | case GL_BACK: |
Gurchetan Singh | 2e6d358 | 2016-06-30 15:20:34 -0700 | [diff] [blame] | 287 | /* For GLES contexts with a single buffered configuration, we actually |
| 288 | * only have a front renderbuffer, so any clear calls to GL_BACK should |
| 289 | * affect that buffer. See draw_buffer_enum_to_bitmask for details. |
| 290 | */ |
| 291 | if (_mesa_is_gles(ctx)) |
| 292 | if (!ctx->DrawBuffer->Visual.doubleBufferMode) |
| 293 | if (att[BUFFER_FRONT_LEFT].Renderbuffer) |
| 294 | mask |= BUFFER_BIT_FRONT_LEFT; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 295 | if (att[BUFFER_BACK_LEFT].Renderbuffer) |
| 296 | mask |= BUFFER_BIT_BACK_LEFT; |
| 297 | if (att[BUFFER_BACK_RIGHT].Renderbuffer) |
| 298 | mask |= BUFFER_BIT_BACK_RIGHT; |
| 299 | break; |
| 300 | case GL_LEFT: |
| 301 | if (att[BUFFER_FRONT_LEFT].Renderbuffer) |
| 302 | mask |= BUFFER_BIT_FRONT_LEFT; |
| 303 | if (att[BUFFER_BACK_LEFT].Renderbuffer) |
| 304 | mask |= BUFFER_BIT_BACK_LEFT; |
| 305 | break; |
| 306 | case GL_RIGHT: |
| 307 | if (att[BUFFER_FRONT_RIGHT].Renderbuffer) |
| 308 | mask |= BUFFER_BIT_FRONT_RIGHT; |
| 309 | if (att[BUFFER_BACK_RIGHT].Renderbuffer) |
| 310 | mask |= BUFFER_BIT_BACK_RIGHT; |
| 311 | break; |
| 312 | case GL_FRONT_AND_BACK: |
| 313 | if (att[BUFFER_FRONT_LEFT].Renderbuffer) |
| 314 | mask |= BUFFER_BIT_FRONT_LEFT; |
| 315 | if (att[BUFFER_BACK_LEFT].Renderbuffer) |
| 316 | mask |= BUFFER_BIT_BACK_LEFT; |
| 317 | if (att[BUFFER_FRONT_RIGHT].Renderbuffer) |
| 318 | mask |= BUFFER_BIT_FRONT_RIGHT; |
| 319 | if (att[BUFFER_BACK_RIGHT].Renderbuffer) |
| 320 | mask |= BUFFER_BIT_BACK_RIGHT; |
| 321 | break; |
| 322 | default: |
Marek Olšák | 03d848e | 2013-12-04 00:27:20 +0100 | [diff] [blame] | 323 | { |
Brian Paul | f8bae52 | 2017-11-08 22:18:40 -0700 | [diff] [blame] | 324 | gl_buffer_index buf = |
| 325 | ctx->DrawBuffer->_ColorDrawBufferIndexes[drawbuffer]; |
Marek Olšák | 03d848e | 2013-12-04 00:27:20 +0100 | [diff] [blame] | 326 | |
Brian Paul | f8bae52 | 2017-11-08 22:18:40 -0700 | [diff] [blame] | 327 | if (buf != BUFFER_NONE && att[buf].Renderbuffer) { |
Marek Olšák | 03d848e | 2013-12-04 00:27:20 +0100 | [diff] [blame] | 328 | mask |= 1 << buf; |
| 329 | } |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
| 333 | return mask; |
| 334 | } |
| 335 | |
| 336 | |
| 337 | |
| 338 | /** |
| 339 | * New in GL 3.0 |
| 340 | * Clear signed integer color buffer or stencil buffer (not depth). |
| 341 | */ |
Samuel Pitoiset | 54bd9a1 | 2017-07-21 14:27:23 +0200 | [diff] [blame] | 342 | static ALWAYS_INLINE void |
| 343 | clear_bufferiv(struct gl_context *ctx, GLenum buffer, GLint drawbuffer, |
| 344 | const GLint *value, bool no_error) |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 345 | { |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 346 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 347 | |
Jakob Bornecrantz | 0917170 | 2018-09-19 15:21:26 +0100 | [diff] [blame] | 348 | if (ctx->NewState) { |
| 349 | _mesa_update_state( ctx ); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Lionel Landwerlin | 88d6658 | 2019-11-01 19:43:00 +0200 | [diff] [blame] | 352 | if (!no_error && ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { |
| 353 | _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, |
| 354 | "glClearBufferiv(incomplete framebuffer)"); |
| 355 | return; |
| 356 | } |
| 357 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 358 | switch (buffer) { |
| 359 | case GL_STENCIL: |
Ian Romanick | 295e07e | 2011-11-01 15:11:12 -0700 | [diff] [blame] | 360 | /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says: |
| 361 | * |
| 362 | * "ClearBuffer generates an INVALID VALUE error if buffer is |
| 363 | * COLOR and drawbuffer is less than zero, or greater than the |
| 364 | * value of MAX DRAW BUFFERS minus one; or if buffer is DEPTH, |
| 365 | * STENCIL, or DEPTH STENCIL and drawbuffer is not zero." |
| 366 | */ |
Samuel Pitoiset | 54bd9a1 | 2017-07-21 14:27:23 +0200 | [diff] [blame] | 367 | if (!no_error && drawbuffer != 0) { |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 368 | _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferiv(drawbuffer=%d)", |
| 369 | drawbuffer); |
| 370 | return; |
| 371 | } |
Brian Paul | e725dc0 | 2014-12-12 16:45:33 -0700 | [diff] [blame] | 372 | else if (ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer |
| 373 | && !ctx->RasterDiscard) { |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 374 | /* Save current stencil clear value, set to 'value', do the |
| 375 | * stencil clear and restore the clear value. |
| 376 | * XXX in the future we may have a new ctx->Driver.ClearBuffer() |
| 377 | * hook instead. |
| 378 | */ |
| 379 | const GLuint clearSave = ctx->Stencil.Clear; |
| 380 | ctx->Stencil.Clear = *value; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 381 | ctx->Driver.Clear(ctx, BUFFER_BIT_STENCIL); |
| 382 | ctx->Stencil.Clear = clearSave; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 383 | } |
| 384 | break; |
| 385 | case GL_COLOR: |
| 386 | { |
| 387 | const GLbitfield mask = make_color_buffer_mask(ctx, drawbuffer); |
Samuel Pitoiset | 54bd9a1 | 2017-07-21 14:27:23 +0200 | [diff] [blame] | 388 | if (!no_error && mask == INVALID_MASK) { |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 389 | _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferiv(drawbuffer=%d)", |
| 390 | drawbuffer); |
| 391 | return; |
| 392 | } |
Paul Berry | aee9680 | 2011-12-20 16:18:39 -0800 | [diff] [blame] | 393 | else if (mask && !ctx->RasterDiscard) { |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 394 | union gl_color_union clearSave; |
| 395 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 396 | /* save color */ |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 397 | clearSave = ctx->Color.ClearColor; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 398 | /* set color */ |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 399 | COPY_4V(ctx->Color.ClearColor.i, value); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 400 | /* clear buffer(s) */ |
| 401 | ctx->Driver.Clear(ctx, mask); |
| 402 | /* restore color */ |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 403 | ctx->Color.ClearColor = clearSave; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | break; |
| 407 | default: |
Samuel Pitoiset | 54bd9a1 | 2017-07-21 14:27:23 +0200 | [diff] [blame] | 408 | if (!no_error) { |
| 409 | /* Page 498 of the PDF, section '17.4.3.1 Clearing Individual Buffers' |
| 410 | * of the OpenGL 4.5 spec states: |
| 411 | * |
| 412 | * "An INVALID_ENUM error is generated by ClearBufferiv and |
| 413 | * ClearNamedFramebufferiv if buffer is not COLOR or STENCIL." |
| 414 | */ |
| 415 | _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferiv(buffer=%s)", |
| 416 | _mesa_enum_to_string(buffer)); |
| 417 | } |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 418 | return; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | |
Samuel Pitoiset | 54bd9a1 | 2017-07-21 14:27:23 +0200 | [diff] [blame] | 423 | void GLAPIENTRY |
Samuel Pitoiset | da0ecda | 2017-07-21 14:28:52 +0200 | [diff] [blame] | 424 | _mesa_ClearBufferiv_no_error(GLenum buffer, GLint drawbuffer, const GLint *value) |
| 425 | { |
| 426 | GET_CURRENT_CONTEXT(ctx); |
| 427 | clear_bufferiv(ctx, buffer, drawbuffer, value, true); |
| 428 | } |
| 429 | |
| 430 | |
| 431 | void GLAPIENTRY |
Samuel Pitoiset | 54bd9a1 | 2017-07-21 14:27:23 +0200 | [diff] [blame] | 432 | _mesa_ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *value) |
| 433 | { |
| 434 | GET_CURRENT_CONTEXT(ctx); |
| 435 | clear_bufferiv(ctx, buffer, drawbuffer, value, false); |
| 436 | } |
| 437 | |
| 438 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 439 | /** |
Laura Ekstrand | 6236c47 | 2015-02-05 13:24:43 -0800 | [diff] [blame] | 440 | * The ClearBuffer framework is so complicated and so riddled with the |
| 441 | * assumption that the framebuffer is bound that, for now, we will just fake |
| 442 | * direct state access clearing for the user. |
| 443 | */ |
| 444 | void GLAPIENTRY |
| 445 | _mesa_ClearNamedFramebufferiv(GLuint framebuffer, GLenum buffer, |
| 446 | GLint drawbuffer, const GLint *value) |
| 447 | { |
| 448 | GLint oldfb; |
| 449 | |
| 450 | _mesa_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldfb); |
| 451 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer); |
| 452 | _mesa_ClearBufferiv(buffer, drawbuffer, value); |
| 453 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, (GLuint) oldfb); |
| 454 | } |
| 455 | |
| 456 | |
| 457 | /** |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 458 | * New in GL 3.0 |
| 459 | * Clear unsigned integer color buffer (not depth, not stencil). |
| 460 | */ |
Samuel Pitoiset | b18b1fa | 2017-07-21 14:23:35 +0200 | [diff] [blame] | 461 | static ALWAYS_INLINE void |
| 462 | clear_bufferuiv(struct gl_context *ctx, GLenum buffer, GLint drawbuffer, |
| 463 | const GLuint *value, bool no_error) |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 464 | { |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 465 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 466 | |
Jakob Bornecrantz | 0917170 | 2018-09-19 15:21:26 +0100 | [diff] [blame] | 467 | if (ctx->NewState) { |
| 468 | _mesa_update_state( ctx ); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Dmitriy Nester | 58bb817 | 2020-04-30 16:25:04 +0300 | [diff] [blame] | 471 | if (!no_error && ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE) { |
| 472 | _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION, |
| 473 | "glClearBufferuiv(incomplete framebuffer)"); |
| 474 | return; |
| 475 | } |
| 476 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 477 | switch (buffer) { |
| 478 | case GL_COLOR: |
| 479 | { |
| 480 | const GLbitfield mask = make_color_buffer_mask(ctx, drawbuffer); |
Samuel Pitoiset | b18b1fa | 2017-07-21 14:23:35 +0200 | [diff] [blame] | 481 | if (!no_error && mask == INVALID_MASK) { |
Brian Paul | 197b1d7 | 2010-11-19 14:34:07 -0700 | [diff] [blame] | 482 | _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferuiv(drawbuffer=%d)", |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 483 | drawbuffer); |
| 484 | return; |
| 485 | } |
Paul Berry | aee9680 | 2011-12-20 16:18:39 -0800 | [diff] [blame] | 486 | else if (mask && !ctx->RasterDiscard) { |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 487 | union gl_color_union clearSave; |
| 488 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 489 | /* save color */ |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 490 | clearSave = ctx->Color.ClearColor; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 491 | /* set color */ |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 492 | COPY_4V(ctx->Color.ClearColor.ui, value); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 493 | /* clear buffer(s) */ |
| 494 | ctx->Driver.Clear(ctx, mask); |
| 495 | /* restore color */ |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 496 | ctx->Color.ClearColor = clearSave; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | break; |
| 500 | default: |
Samuel Pitoiset | b18b1fa | 2017-07-21 14:23:35 +0200 | [diff] [blame] | 501 | if (!no_error) { |
| 502 | /* Page 498 of the PDF, section '17.4.3.1 Clearing Individual Buffers' |
| 503 | * of the OpenGL 4.5 spec states: |
| 504 | * |
| 505 | * "An INVALID_ENUM error is generated by ClearBufferuiv and |
| 506 | * ClearNamedFramebufferuiv if buffer is not COLOR." |
| 507 | */ |
| 508 | _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferuiv(buffer=%s)", |
| 509 | _mesa_enum_to_string(buffer)); |
| 510 | } |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 511 | return; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | |
Samuel Pitoiset | b18b1fa | 2017-07-21 14:23:35 +0200 | [diff] [blame] | 516 | void GLAPIENTRY |
Samuel Pitoiset | 11e0542 | 2017-07-21 14:25:03 +0200 | [diff] [blame] | 517 | _mesa_ClearBufferuiv_no_error(GLenum buffer, GLint drawbuffer, |
| 518 | const GLuint *value) |
| 519 | { |
| 520 | GET_CURRENT_CONTEXT(ctx); |
| 521 | clear_bufferuiv(ctx, buffer, drawbuffer, value, true); |
| 522 | } |
| 523 | |
| 524 | |
| 525 | void GLAPIENTRY |
Samuel Pitoiset | b18b1fa | 2017-07-21 14:23:35 +0200 | [diff] [blame] | 526 | _mesa_ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *value) |
| 527 | { |
| 528 | GET_CURRENT_CONTEXT(ctx); |
| 529 | clear_bufferuiv(ctx, buffer, drawbuffer, value, false); |
| 530 | } |
| 531 | |
| 532 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 533 | /** |
Laura Ekstrand | 43db4b8 | 2015-02-05 13:30:50 -0800 | [diff] [blame] | 534 | * The ClearBuffer framework is so complicated and so riddled with the |
| 535 | * assumption that the framebuffer is bound that, for now, we will just fake |
| 536 | * direct state access clearing for the user. |
| 537 | */ |
| 538 | void GLAPIENTRY |
| 539 | _mesa_ClearNamedFramebufferuiv(GLuint framebuffer, GLenum buffer, |
| 540 | GLint drawbuffer, const GLuint *value) |
| 541 | { |
| 542 | GLint oldfb; |
| 543 | |
| 544 | _mesa_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldfb); |
| 545 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer); |
| 546 | _mesa_ClearBufferuiv(buffer, drawbuffer, value); |
| 547 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, (GLuint) oldfb); |
| 548 | } |
| 549 | |
| 550 | |
| 551 | /** |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 552 | * New in GL 3.0 |
| 553 | * Clear fixed-pt or float color buffer or depth buffer (not stencil). |
| 554 | */ |
Samuel Pitoiset | 33b4730 | 2017-07-21 14:02:20 +0200 | [diff] [blame] | 555 | static ALWAYS_INLINE void |
| 556 | clear_bufferfv(struct gl_context *ctx, GLenum buffer, GLint drawbuffer, |
| 557 | const GLfloat *value, bool no_error) |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 558 | { |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 559 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 560 | |
Jakob Bornecrantz | 0917170 | 2018-09-19 15:21:26 +0100 | [diff] [blame] | 561 | if (ctx->NewState) { |
| 562 | _mesa_update_state( ctx ); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Dmitriy Nester | 58bb817 | 2020-04-30 16:25:04 +0300 | [diff] [blame] | 565 | if (!no_error && ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE) { |
| 566 | _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION, |
| 567 | "glClearBufferfv(incomplete framebuffer)"); |
| 568 | return; |
| 569 | } |
| 570 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 571 | switch (buffer) { |
| 572 | case GL_DEPTH: |
Ian Romanick | 295e07e | 2011-11-01 15:11:12 -0700 | [diff] [blame] | 573 | /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says: |
| 574 | * |
| 575 | * "ClearBuffer generates an INVALID VALUE error if buffer is |
| 576 | * COLOR and drawbuffer is less than zero, or greater than the |
| 577 | * value of MAX DRAW BUFFERS minus one; or if buffer is DEPTH, |
| 578 | * STENCIL, or DEPTH STENCIL and drawbuffer is not zero." |
| 579 | */ |
Samuel Pitoiset | 33b4730 | 2017-07-21 14:02:20 +0200 | [diff] [blame] | 580 | if (!no_error && drawbuffer != 0) { |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 581 | _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferfv(drawbuffer=%d)", |
| 582 | drawbuffer); |
| 583 | return; |
| 584 | } |
Brian Paul | e725dc0 | 2014-12-12 16:45:33 -0700 | [diff] [blame] | 585 | else if (ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer |
| 586 | && !ctx->RasterDiscard) { |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 587 | /* Save current depth clear value, set to 'value', do the |
| 588 | * depth clear and restore the clear value. |
| 589 | * XXX in the future we may have a new ctx->Driver.ClearBuffer() |
| 590 | * hook instead. |
| 591 | */ |
Karl Schultz | b30898f | 2010-02-13 17:31:58 -0700 | [diff] [blame] | 592 | const GLclampd clearSave = ctx->Depth.Clear; |
Nanley Chery | d47cb41 | 2020-11-02 09:02:42 -0800 | [diff] [blame^] | 593 | |
| 594 | /* Page 263 (page 279 of the PDF) of the OpenGL 3.0 spec says: |
| 595 | * |
| 596 | * "If buffer is DEPTH, drawbuffer must be zero, and value points |
| 597 | * to the single depth value to clear the depth buffer to. |
| 598 | * Clamping and type conversion for fixed-point depth buffers are |
| 599 | * performed in the same fashion as for ClearDepth." |
| 600 | */ |
| 601 | const struct gl_renderbuffer *rb = |
| 602 | ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; |
| 603 | const bool is_float_depth = |
| 604 | _mesa_has_depth_float_channel(rb->InternalFormat); |
| 605 | ctx->Depth.Clear = is_float_depth ? *value : SATURATE(*value); |
| 606 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 607 | ctx->Driver.Clear(ctx, BUFFER_BIT_DEPTH); |
| 608 | ctx->Depth.Clear = clearSave; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 609 | } |
| 610 | /* clear depth buffer to value */ |
| 611 | break; |
| 612 | case GL_COLOR: |
| 613 | { |
| 614 | const GLbitfield mask = make_color_buffer_mask(ctx, drawbuffer); |
Samuel Pitoiset | 33b4730 | 2017-07-21 14:02:20 +0200 | [diff] [blame] | 615 | if (!no_error && mask == INVALID_MASK) { |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 616 | _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferfv(drawbuffer=%d)", |
| 617 | drawbuffer); |
| 618 | return; |
| 619 | } |
Paul Berry | aee9680 | 2011-12-20 16:18:39 -0800 | [diff] [blame] | 620 | else if (mask && !ctx->RasterDiscard) { |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 621 | union gl_color_union clearSave; |
| 622 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 623 | /* save color */ |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 624 | clearSave = ctx->Color.ClearColor; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 625 | /* set color */ |
Brian Paul | cf41d7c | 2012-08-25 06:43:37 -0600 | [diff] [blame] | 626 | COPY_4V(ctx->Color.ClearColor.f, value); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 627 | /* clear buffer(s) */ |
| 628 | ctx->Driver.Clear(ctx, mask); |
| 629 | /* restore color */ |
Dave Airlie | 093dc9e | 2011-09-12 10:57:40 +0100 | [diff] [blame] | 630 | ctx->Color.ClearColor = clearSave; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | break; |
| 634 | default: |
Samuel Pitoiset | 33b4730 | 2017-07-21 14:02:20 +0200 | [diff] [blame] | 635 | if (!no_error) { |
| 636 | /* Page 498 of the PDF, section '17.4.3.1 Clearing Individual Buffers' |
| 637 | * of the OpenGL 4.5 spec states: |
| 638 | * |
| 639 | * "An INVALID_ENUM error is generated by ClearBufferfv and |
| 640 | * ClearNamedFramebufferfv if buffer is not COLOR or DEPTH." |
| 641 | */ |
| 642 | _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferfv(buffer=%s)", |
| 643 | _mesa_enum_to_string(buffer)); |
| 644 | } |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 645 | return; |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | |
Samuel Pitoiset | 33b4730 | 2017-07-21 14:02:20 +0200 | [diff] [blame] | 650 | void GLAPIENTRY |
Samuel Pitoiset | 5e05e7d | 2017-07-21 14:04:15 +0200 | [diff] [blame] | 651 | _mesa_ClearBufferfv_no_error(GLenum buffer, GLint drawbuffer, |
| 652 | const GLfloat *value) |
| 653 | { |
| 654 | GET_CURRENT_CONTEXT(ctx); |
| 655 | clear_bufferfv(ctx, buffer, drawbuffer, value, true); |
| 656 | } |
| 657 | |
| 658 | |
| 659 | void GLAPIENTRY |
Samuel Pitoiset | 33b4730 | 2017-07-21 14:02:20 +0200 | [diff] [blame] | 660 | _mesa_ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *value) |
| 661 | { |
| 662 | GET_CURRENT_CONTEXT(ctx); |
| 663 | clear_bufferfv(ctx, buffer, drawbuffer, value, false); |
| 664 | } |
| 665 | |
| 666 | |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 667 | /** |
Laura Ekstrand | bbd9c55 | 2015-02-05 13:38:39 -0800 | [diff] [blame] | 668 | * The ClearBuffer framework is so complicated and so riddled with the |
| 669 | * assumption that the framebuffer is bound that, for now, we will just fake |
| 670 | * direct state access clearing for the user. |
| 671 | */ |
| 672 | void GLAPIENTRY |
| 673 | _mesa_ClearNamedFramebufferfv(GLuint framebuffer, GLenum buffer, |
| 674 | GLint drawbuffer, const GLfloat *value) |
| 675 | { |
| 676 | GLint oldfb; |
| 677 | |
| 678 | _mesa_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldfb); |
| 679 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer); |
| 680 | _mesa_ClearBufferfv(buffer, drawbuffer, value); |
| 681 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, (GLuint) oldfb); |
| 682 | } |
| 683 | |
| 684 | |
| 685 | /** |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 686 | * New in GL 3.0 |
| 687 | * Clear depth/stencil buffer only. |
| 688 | */ |
Samuel Pitoiset | 1ed61e0 | 2017-07-21 14:19:27 +0200 | [diff] [blame] | 689 | static ALWAYS_INLINE void |
| 690 | clear_bufferfi(struct gl_context *ctx, GLenum buffer, GLint drawbuffer, |
| 691 | GLfloat depth, GLint stencil, bool no_error) |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 692 | { |
Dave Airlie | 092cf9a | 2012-01-10 12:48:26 +0000 | [diff] [blame] | 693 | GLbitfield mask = 0; |
| 694 | |
Eric Anholt | a975479 | 2013-01-16 16:20:38 -0800 | [diff] [blame] | 695 | FLUSH_VERTICES(ctx, 0); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 696 | |
Samuel Pitoiset | 1ed61e0 | 2017-07-21 14:19:27 +0200 | [diff] [blame] | 697 | if (!no_error) { |
| 698 | if (buffer != GL_DEPTH_STENCIL) { |
| 699 | _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferfi(buffer=%s)", |
| 700 | _mesa_enum_to_string(buffer)); |
| 701 | return; |
| 702 | } |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 703 | |
Samuel Pitoiset | 1ed61e0 | 2017-07-21 14:19:27 +0200 | [diff] [blame] | 704 | /* Page 264 (page 280 of the PDF) of the OpenGL 3.0 spec says: |
| 705 | * |
| 706 | * "ClearBuffer generates an INVALID VALUE error if buffer is |
| 707 | * COLOR and drawbuffer is less than zero, or greater than the |
| 708 | * value of MAX DRAW BUFFERS minus one; or if buffer is DEPTH, |
| 709 | * STENCIL, or DEPTH STENCIL and drawbuffer is not zero." |
| 710 | */ |
| 711 | if (drawbuffer != 0) { |
| 712 | _mesa_error(ctx, GL_INVALID_VALUE, "glClearBufferfi(drawbuffer=%d)", |
| 713 | drawbuffer); |
| 714 | return; |
| 715 | } |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Paul Berry | aee9680 | 2011-12-20 16:18:39 -0800 | [diff] [blame] | 718 | if (ctx->RasterDiscard) |
Eric Anholt | e7c2b71 | 2011-09-29 23:13:44 -0700 | [diff] [blame] | 719 | return; |
| 720 | |
Jakob Bornecrantz | 0917170 | 2018-09-19 15:21:26 +0100 | [diff] [blame] | 721 | if (ctx->NewState) { |
| 722 | _mesa_update_state( ctx ); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Lionel Landwerlin | f93bb90 | 2019-11-11 12:32:50 +0200 | [diff] [blame] | 725 | if (!no_error && ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { |
| 726 | _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, |
| 727 | "glClearBufferfi(incomplete framebuffer)"); |
| 728 | return; |
| 729 | } |
| 730 | |
Dave Airlie | 092cf9a | 2012-01-10 12:48:26 +0000 | [diff] [blame] | 731 | if (ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer) |
| 732 | mask |= BUFFER_BIT_DEPTH; |
| 733 | if (ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer) |
| 734 | mask |= BUFFER_BIT_STENCIL; |
| 735 | |
| 736 | if (mask) { |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 737 | /* save current clear values */ |
Karl Schultz | b30898f | 2010-02-13 17:31:58 -0700 | [diff] [blame] | 738 | const GLclampd clearDepthSave = ctx->Depth.Clear; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 739 | const GLuint clearStencilSave = ctx->Stencil.Clear; |
| 740 | |
| 741 | /* set new clear values */ |
| 742 | ctx->Depth.Clear = depth; |
| 743 | ctx->Stencil.Clear = stencil; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 744 | |
| 745 | /* clear buffers */ |
Dave Airlie | 092cf9a | 2012-01-10 12:48:26 +0000 | [diff] [blame] | 746 | ctx->Driver.Clear(ctx, mask); |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 747 | |
| 748 | /* restore */ |
| 749 | ctx->Depth.Clear = clearDepthSave; |
| 750 | ctx->Stencil.Clear = clearStencilSave; |
Brian Paul | 2b5ece5 | 2009-12-30 09:25:24 -0700 | [diff] [blame] | 751 | } |
| 752 | } |
Laura Ekstrand | a0329c7 | 2015-02-05 13:43:12 -0800 | [diff] [blame] | 753 | |
| 754 | |
Samuel Pitoiset | 1ed61e0 | 2017-07-21 14:19:27 +0200 | [diff] [blame] | 755 | void GLAPIENTRY |
Samuel Pitoiset | 73c5e75 | 2017-07-21 14:21:10 +0200 | [diff] [blame] | 756 | _mesa_ClearBufferfi_no_error(GLenum buffer, GLint drawbuffer, |
| 757 | GLfloat depth, GLint stencil) |
| 758 | { |
| 759 | GET_CURRENT_CONTEXT(ctx); |
| 760 | clear_bufferfi(ctx, buffer, drawbuffer, depth, stencil, true); |
| 761 | } |
| 762 | |
| 763 | |
| 764 | void GLAPIENTRY |
Samuel Pitoiset | 1ed61e0 | 2017-07-21 14:19:27 +0200 | [diff] [blame] | 765 | _mesa_ClearBufferfi(GLenum buffer, GLint drawbuffer, |
| 766 | GLfloat depth, GLint stencil) |
| 767 | { |
| 768 | GET_CURRENT_CONTEXT(ctx); |
| 769 | clear_bufferfi(ctx, buffer, drawbuffer, depth, stencil, false); |
| 770 | } |
| 771 | |
| 772 | |
Laura Ekstrand | a0329c7 | 2015-02-05 13:43:12 -0800 | [diff] [blame] | 773 | /** |
| 774 | * The ClearBuffer framework is so complicated and so riddled with the |
| 775 | * assumption that the framebuffer is bound that, for now, we will just fake |
| 776 | * direct state access clearing for the user. |
| 777 | */ |
| 778 | void GLAPIENTRY |
| 779 | _mesa_ClearNamedFramebufferfi(GLuint framebuffer, GLenum buffer, |
Ilia Mirkin | 7d7e015 | 2016-06-09 23:45:22 -0400 | [diff] [blame] | 780 | GLint drawbuffer, GLfloat depth, GLint stencil) |
Laura Ekstrand | a0329c7 | 2015-02-05 13:43:12 -0800 | [diff] [blame] | 781 | { |
| 782 | GLint oldfb; |
| 783 | |
| 784 | _mesa_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldfb); |
| 785 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer); |
Ilia Mirkin | 7d7e015 | 2016-06-09 23:45:22 -0400 | [diff] [blame] | 786 | _mesa_ClearBufferfi(buffer, drawbuffer, depth, stencil); |
Laura Ekstrand | a0329c7 | 2015-02-05 13:43:12 -0800 | [diff] [blame] | 787 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, (GLuint) oldfb); |
| 788 | } |