Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3 | * |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 4 | * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 5 | * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 6 | * |
| 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: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
| 16 | * |
| 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 |
Kenneth Graunke | 3d8d5b2 | 2013-04-21 13:46:48 -0700 | [diff] [blame] | 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 21 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 22 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 | * OTHER DEALINGS IN THE SOFTWARE. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 27 | /* |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 28 | * GL_EXT/ARB_framebuffer_object extensions |
| 29 | * |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 30 | * Authors: |
| 31 | * Brian Paul |
| 32 | */ |
| 33 | |
Kenneth Graunke | c6ed42a | 2012-11-17 23:23:06 -0800 | [diff] [blame] | 34 | #include <stdbool.h> |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 35 | |
Roland Scheidegger | a1bc0d0 | 2007-07-18 20:17:14 +0200 | [diff] [blame] | 36 | #include "buffers.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 37 | #include "context.h" |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 38 | #include "debug_output.h" |
Brian Paul | 9b50cea | 2009-10-23 11:34:14 -0600 | [diff] [blame] | 39 | #include "enums.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 40 | #include "fbobject.h" |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 41 | #include "formats.h" |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 42 | #include "framebuffer.h" |
Brian Paul | a1287f5 | 2012-07-22 11:20:00 -0600 | [diff] [blame] | 43 | #include "glformats.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 44 | #include "hash.h" |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 45 | #include "macros.h" |
Chris Forbes | 90b5a24 | 2013-02-06 20:42:53 +1300 | [diff] [blame] | 46 | #include "multisample.h" |
Vinson Lee | 0117da4 | 2011-01-05 23:11:54 -0800 | [diff] [blame] | 47 | #include "mtypes.h" |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 48 | #include "renderbuffer.h" |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 49 | #include "state.h" |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 50 | #include "teximage.h" |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 51 | #include "texobj.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 52 | |
| 53 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 54 | /** |
| 55 | * Notes: |
| 56 | * |
| 57 | * None of the GL_EXT_framebuffer_object functions are compiled into |
| 58 | * display lists. |
| 59 | */ |
| 60 | |
| 61 | |
| 62 | |
Brian Paul | 923b6fc | 2005-02-08 04:08:56 +0000 | [diff] [blame] | 63 | /* |
| 64 | * When glGenRender/FramebuffersEXT() is called we insert pointers to |
| 65 | * these placeholder objects into the hash table. |
| 66 | * Later, when the object ID is first bound, we replace the placeholder |
| 67 | * with the real frame/renderbuffer. |
| 68 | */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 69 | static struct gl_framebuffer DummyFramebuffer; |
| 70 | static struct gl_renderbuffer DummyRenderbuffer; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 71 | |
Kristian Høgsberg | 144356f | 2010-09-09 17:08:12 -0400 | [diff] [blame] | 72 | /* We bind this framebuffer when applications pass a NULL |
| 73 | * drawable/surface in make current. */ |
| 74 | static struct gl_framebuffer IncompleteFramebuffer; |
| 75 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 76 | |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 77 | static void |
Brian Paul | c732458 | 2012-11-30 10:04:48 -0700 | [diff] [blame] | 78 | delete_dummy_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb) |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 79 | { |
| 80 | /* no op */ |
| 81 | } |
| 82 | |
| 83 | static void |
| 84 | delete_dummy_framebuffer(struct gl_framebuffer *fb) |
| 85 | { |
| 86 | /* no op */ |
| 87 | } |
| 88 | |
| 89 | |
| 90 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 91 | _mesa_init_fbobjects(struct gl_context *ctx) |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 92 | { |
Timothy Arceri | f0857fe | 2017-10-16 11:59:31 +1100 | [diff] [blame] | 93 | simple_mtx_init(&DummyFramebuffer.Mutex, mtx_plain); |
| 94 | simple_mtx_init(&DummyRenderbuffer.Mutex, mtx_plain); |
| 95 | simple_mtx_init(&IncompleteFramebuffer.Mutex, mtx_plain); |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 96 | DummyFramebuffer.Delete = delete_dummy_framebuffer; |
| 97 | DummyRenderbuffer.Delete = delete_dummy_renderbuffer; |
Kristian Høgsberg | 144356f | 2010-09-09 17:08:12 -0400 | [diff] [blame] | 98 | IncompleteFramebuffer.Delete = delete_dummy_framebuffer; |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 99 | } |
| 100 | |
Kristian Høgsberg | 9456e22 | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 101 | struct gl_framebuffer * |
| 102 | _mesa_get_incomplete_framebuffer(void) |
| 103 | { |
Kristian Høgsberg | 144356f | 2010-09-09 17:08:12 -0400 | [diff] [blame] | 104 | return &IncompleteFramebuffer; |
Kristian Høgsberg | 9456e22 | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 105 | } |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 106 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 107 | /** |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 108 | * Helper routine for getting a gl_renderbuffer. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 109 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 110 | struct gl_renderbuffer * |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 111 | _mesa_lookup_renderbuffer(struct gl_context *ctx, GLuint id) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 112 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 113 | struct gl_renderbuffer *rb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 114 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 115 | if (id == 0) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 116 | return NULL; |
| 117 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 118 | rb = (struct gl_renderbuffer *) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 119 | _mesa_HashLookup(ctx->Shared->RenderBuffers, id); |
| 120 | return rb; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | /** |
Laura Ekstrand | 2bb138e | 2015-01-23 16:38:36 -0800 | [diff] [blame] | 125 | * A convenience function for direct state access that throws |
| 126 | * GL_INVALID_OPERATION if the renderbuffer doesn't exist. |
| 127 | */ |
| 128 | struct gl_renderbuffer * |
| 129 | _mesa_lookup_renderbuffer_err(struct gl_context *ctx, GLuint id, |
| 130 | const char *func) |
| 131 | { |
| 132 | struct gl_renderbuffer *rb; |
| 133 | |
| 134 | rb = _mesa_lookup_renderbuffer(ctx, id); |
| 135 | if (!rb || rb == &DummyRenderbuffer) { |
| 136 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 137 | "%s(non-existent renderbuffer %u)", func, id); |
| 138 | return NULL; |
| 139 | } |
| 140 | |
| 141 | return rb; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | /** |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 146 | * Helper routine for getting a gl_framebuffer. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 147 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 148 | struct gl_framebuffer * |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 149 | _mesa_lookup_framebuffer(struct gl_context *ctx, GLuint id) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 150 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 151 | struct gl_framebuffer *fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 152 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 153 | if (id == 0) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 154 | return NULL; |
| 155 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 156 | fb = (struct gl_framebuffer *) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 157 | _mesa_HashLookup(ctx->Shared->FrameBuffers, id); |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 158 | |
| 159 | return fb; |
| 160 | } |
| 161 | |
| 162 | |
| 163 | struct gl_framebuffer * |
| 164 | _mesa_lookup_framebuffer_dsa(struct gl_context *ctx, GLuint id, |
| 165 | const char* func) |
| 166 | { |
| 167 | struct gl_framebuffer *fb; |
| 168 | |
| 169 | if (id == 0) |
| 170 | return NULL; |
| 171 | |
| 172 | fb = _mesa_lookup_framebuffer(ctx, id); |
| 173 | |
| 174 | /* Name exists but buffer is not initialized */ |
| 175 | if (fb == &DummyFramebuffer) { |
| 176 | fb = ctx->Driver.NewFramebuffer(ctx, id); |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 177 | _mesa_HashInsert(ctx->Shared->FrameBuffers, id, fb, true); |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 178 | } |
| 179 | /* Name doesn't exist */ |
| 180 | else if (!fb) { |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 181 | fb = ctx->Driver.NewFramebuffer(ctx, id); |
| 182 | if (!fb) { |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 183 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); |
| 184 | return NULL; |
| 185 | } |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 186 | _mesa_HashInsert(ctx->Shared->FrameBuffers, id, fb, false); |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 187 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 188 | return fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | |
| 192 | /** |
Laura Ekstrand | 6d8eff4 | 2015-01-22 10:23:35 -0800 | [diff] [blame] | 193 | * A convenience function for direct state access that throws |
| 194 | * GL_INVALID_OPERATION if the framebuffer doesn't exist. |
| 195 | */ |
| 196 | struct gl_framebuffer * |
| 197 | _mesa_lookup_framebuffer_err(struct gl_context *ctx, GLuint id, |
| 198 | const char *func) |
| 199 | { |
| 200 | struct gl_framebuffer *fb; |
| 201 | |
| 202 | fb = _mesa_lookup_framebuffer(ctx, id); |
| 203 | if (!fb || fb == &DummyFramebuffer) { |
| 204 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 205 | "%s(non-existent framebuffer %u)", func, id); |
| 206 | return NULL; |
| 207 | } |
| 208 | |
| 209 | return fb; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /** |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 214 | * Mark the given framebuffer as invalid. This will force the |
| 215 | * test for framebuffer completeness to be done before the framebuffer |
| 216 | * is used. |
| 217 | */ |
| 218 | static void |
| 219 | invalidate_framebuffer(struct gl_framebuffer *fb) |
| 220 | { |
| 221 | fb->_Status = 0; /* "indeterminate" */ |
| 222 | } |
| 223 | |
| 224 | |
| 225 | /** |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 226 | * Return the gl_framebuffer object which corresponds to the given |
| 227 | * framebuffer target, such as GL_DRAW_FRAMEBUFFER. |
| 228 | * Check support for GL_EXT_framebuffer_blit to determine if certain |
| 229 | * targets are legal. |
| 230 | * \return gl_framebuffer pointer or NULL if target is illegal |
| 231 | */ |
| 232 | static struct gl_framebuffer * |
| 233 | get_framebuffer_target(struct gl_context *ctx, GLenum target) |
| 234 | { |
Ian Romanick | a672973 | 2013-11-13 13:30:37 -0800 | [diff] [blame] | 235 | bool have_fb_blit = _mesa_is_gles3(ctx) || _mesa_is_desktop_gl(ctx); |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 236 | switch (target) { |
| 237 | case GL_DRAW_FRAMEBUFFER: |
Kenneth Graunke | c6ed42a | 2012-11-17 23:23:06 -0800 | [diff] [blame] | 238 | return have_fb_blit ? ctx->DrawBuffer : NULL; |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 239 | case GL_READ_FRAMEBUFFER: |
Kenneth Graunke | c6ed42a | 2012-11-17 23:23:06 -0800 | [diff] [blame] | 240 | return have_fb_blit ? ctx->ReadBuffer : NULL; |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 241 | case GL_FRAMEBUFFER_EXT: |
| 242 | return ctx->DrawBuffer; |
| 243 | default: |
| 244 | return NULL; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | |
| 249 | /** |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 250 | * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 251 | * gl_renderbuffer_attachment object. |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 252 | * This function is only used for user-created FB objects, not the |
| 253 | * default / window-system FB object. |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 254 | * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to |
| 255 | * the depth buffer attachment point. |
Alejandro Piñeiro | c6eb3ae | 2017-01-12 16:03:00 -0200 | [diff] [blame] | 256 | * Returns if the attachment is a GL_COLOR_ATTACHMENTm_EXT on |
| 257 | * is_color_attachment, because several callers would return different errors |
| 258 | * if they don't find the attachment. |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 259 | */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 260 | static struct gl_renderbuffer_attachment * |
| 261 | get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb, |
Alejandro Piñeiro | c6eb3ae | 2017-01-12 16:03:00 -0200 | [diff] [blame] | 262 | GLenum attachment, bool *is_color_attachment) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 263 | { |
| 264 | GLuint i; |
| 265 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 266 | assert(_mesa_is_user_fbo(fb)); |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 267 | |
Alejandro Piñeiro | c6eb3ae | 2017-01-12 16:03:00 -0200 | [diff] [blame] | 268 | if (is_color_attachment) |
| 269 | *is_color_attachment = false; |
| 270 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 271 | switch (attachment) { |
| 272 | case GL_COLOR_ATTACHMENT0_EXT: |
| 273 | case GL_COLOR_ATTACHMENT1_EXT: |
| 274 | case GL_COLOR_ATTACHMENT2_EXT: |
| 275 | case GL_COLOR_ATTACHMENT3_EXT: |
| 276 | case GL_COLOR_ATTACHMENT4_EXT: |
| 277 | case GL_COLOR_ATTACHMENT5_EXT: |
| 278 | case GL_COLOR_ATTACHMENT6_EXT: |
| 279 | case GL_COLOR_ATTACHMENT7_EXT: |
| 280 | case GL_COLOR_ATTACHMENT8_EXT: |
| 281 | case GL_COLOR_ATTACHMENT9_EXT: |
| 282 | case GL_COLOR_ATTACHMENT10_EXT: |
| 283 | case GL_COLOR_ATTACHMENT11_EXT: |
| 284 | case GL_COLOR_ATTACHMENT12_EXT: |
| 285 | case GL_COLOR_ATTACHMENT13_EXT: |
| 286 | case GL_COLOR_ATTACHMENT14_EXT: |
| 287 | case GL_COLOR_ATTACHMENT15_EXT: |
Alejandro Piñeiro | c6eb3ae | 2017-01-12 16:03:00 -0200 | [diff] [blame] | 288 | if (is_color_attachment) |
| 289 | *is_color_attachment = true; |
Ian Romanick | 2e3a4ab | 2011-10-02 15:03:07 -0700 | [diff] [blame] | 290 | /* Only OpenGL ES 1.x forbids color attachments other than |
| 291 | * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the |
| 292 | * hardware is used. |
| 293 | */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 294 | i = attachment - GL_COLOR_ATTACHMENT0_EXT; |
Ian Romanick | 7e4cb32 | 2011-10-02 14:50:21 -0700 | [diff] [blame] | 295 | if (i >= ctx->Const.MaxColorAttachments |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 296 | || (i > 0 && ctx->API == API_OPENGLES)) { |
| 297 | return NULL; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 298 | } |
Marcin Ślusarz | c3a251f | 2020-07-24 19:51:30 +0200 | [diff] [blame] | 299 | assert(BUFFER_COLOR0 + i < ARRAY_SIZE(fb->Attachment)); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 300 | return &fb->Attachment[BUFFER_COLOR0 + i]; |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 301 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Matt Turner | ec8ee91 | 2012-11-15 22:13:48 -0800 | [diff] [blame] | 302 | if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 303 | return NULL; |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 304 | /* fall-through */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 305 | case GL_DEPTH_ATTACHMENT_EXT: |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 306 | return &fb->Attachment[BUFFER_DEPTH]; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 307 | case GL_STENCIL_ATTACHMENT_EXT: |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 308 | return &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 309 | default: |
| 310 | return NULL; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | |
| 315 | /** |
| 316 | * As above, but only used for getting attachments of the default / |
| 317 | * window-system framebuffer (not user-created framebuffer objects). |
| 318 | */ |
| 319 | static struct gl_renderbuffer_attachment * |
Timothy Arceri | e618761 | 2017-05-05 15:02:20 +1000 | [diff] [blame] | 320 | get_fb0_attachment(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 321 | GLenum attachment) |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 322 | { |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 323 | assert(_mesa_is_winsys_fbo(fb)); |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 324 | |
Kenneth Graunke | e6ca6e5 | 2019-10-14 10:07:30 -0700 | [diff] [blame] | 325 | attachment = _mesa_back_to_front_if_single_buffered(fb, attachment); |
| 326 | |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 327 | if (_mesa_is_gles3(ctx)) { |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 328 | switch (attachment) { |
| 329 | case GL_BACK: |
| 330 | /* Since there is no stereo rendering in ES 3.0, only return the |
| 331 | * LEFT bits. |
| 332 | */ |
Kenneth Graunke | e6ca6e5 | 2019-10-14 10:07:30 -0700 | [diff] [blame] | 333 | return &fb->Attachment[BUFFER_BACK_LEFT]; |
| 334 | case GL_FRONT: |
| 335 | /* We might get this if back_to_front triggers above */ |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 336 | return &fb->Attachment[BUFFER_FRONT_LEFT]; |
| 337 | case GL_DEPTH: |
Timothy Arceri | a754e4c | 2017-05-05 15:09:37 +1000 | [diff] [blame] | 338 | return &fb->Attachment[BUFFER_DEPTH]; |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 339 | case GL_STENCIL: |
| 340 | return &fb->Attachment[BUFFER_STENCIL]; |
Kenneth Graunke | e6ca6e5 | 2019-10-14 10:07:30 -0700 | [diff] [blame] | 341 | default: |
| 342 | unreachable("invalid attachment"); |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 346 | switch (attachment) { |
Erik Faye-Lund | 9e13a16 | 2020-09-22 12:18:30 +0200 | [diff] [blame] | 347 | case GL_FRONT: |
Kristian Høgsberg | 80dfec3 | 2010-06-15 13:07:01 -0400 | [diff] [blame] | 348 | case GL_FRONT_LEFT: |
Marek Olšák | d58a390 | 2016-09-08 21:02:29 +0200 | [diff] [blame] | 349 | /* Front buffers can be allocated on the first use, but |
| 350 | * glGetFramebufferAttachmentParameteriv must work even if that |
| 351 | * allocation hasn't happened yet. In such case, use the back buffer, |
| 352 | * which should be the same. |
| 353 | */ |
| 354 | if (fb->Attachment[BUFFER_FRONT_LEFT].Type == GL_NONE) |
| 355 | return &fb->Attachment[BUFFER_BACK_LEFT]; |
| 356 | else |
| 357 | return &fb->Attachment[BUFFER_FRONT_LEFT]; |
Kristian Høgsberg | 80dfec3 | 2010-06-15 13:07:01 -0400 | [diff] [blame] | 358 | case GL_FRONT_RIGHT: |
Marek Olšák | d58a390 | 2016-09-08 21:02:29 +0200 | [diff] [blame] | 359 | /* Same as above. */ |
| 360 | if (fb->Attachment[BUFFER_FRONT_RIGHT].Type == GL_NONE) |
| 361 | return &fb->Attachment[BUFFER_BACK_RIGHT]; |
| 362 | else |
| 363 | return &fb->Attachment[BUFFER_FRONT_RIGHT]; |
Kristian Høgsberg | 80dfec3 | 2010-06-15 13:07:01 -0400 | [diff] [blame] | 364 | case GL_BACK_LEFT: |
| 365 | return &fb->Attachment[BUFFER_BACK_LEFT]; |
| 366 | case GL_BACK_RIGHT: |
| 367 | return &fb->Attachment[BUFFER_BACK_RIGHT]; |
Kenneth Graunke | 4f538c3 | 2017-10-26 11:44:09 -0700 | [diff] [blame] | 368 | case GL_BACK: |
| 369 | /* The ARB_ES3_1_compatibility spec says: |
| 370 | * |
| 371 | * "Since this command can only query a single framebuffer |
| 372 | * attachment, BACK is equivalent to BACK_LEFT." |
| 373 | */ |
| 374 | if (ctx->Extensions.ARB_ES3_1_compatibility) |
| 375 | return &fb->Attachment[BUFFER_BACK_LEFT]; |
| 376 | return NULL; |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 377 | case GL_AUX0: |
| 378 | if (fb->Visual.numAuxBuffers == 1) { |
| 379 | return &fb->Attachment[BUFFER_AUX0]; |
| 380 | } |
| 381 | return NULL; |
Ian Romanick | a8328cc | 2011-10-03 12:02:18 -0700 | [diff] [blame] | 382 | |
| 383 | /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says: |
| 384 | * |
| 385 | * "If the default framebuffer is bound to target, then attachment must |
| 386 | * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi, |
| 387 | * identifying a color buffer; DEPTH, identifying the depth buffer; or |
| 388 | * STENCIL, identifying the stencil buffer." |
| 389 | * |
| 390 | * Revision #34 of the ARB_framebuffer_object spec has essentially the same |
| 391 | * language. However, revision #33 of the ARB_framebuffer_object spec |
| 392 | * says: |
| 393 | * |
| 394 | * "If the default framebuffer is bound to <target>, then <attachment> |
| 395 | * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi, |
| 396 | * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the |
| 397 | * depth buffer, or the stencil buffer, and <pname> may be |
| 398 | * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or |
| 399 | * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME." |
| 400 | * |
| 401 | * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed |
| 402 | * from glext.h, so shipping apps should not use those values. |
| 403 | * |
| 404 | * Note that neither EXT_framebuffer_object nor OES_framebuffer_object |
| 405 | * support queries of the window system FBO. |
| 406 | */ |
| 407 | case GL_DEPTH: |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 408 | return &fb->Attachment[BUFFER_DEPTH]; |
Ian Romanick | a8328cc | 2011-10-03 12:02:18 -0700 | [diff] [blame] | 409 | case GL_STENCIL: |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 410 | return &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 411 | default: |
| 412 | return NULL; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 417 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 418 | /** |
| 419 | * Remove any texture or renderbuffer attached to the given attachment |
| 420 | * point. Update reference counts, etc. |
| 421 | */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 422 | static void |
| 423 | remove_attachment(struct gl_context *ctx, |
| 424 | struct gl_renderbuffer_attachment *att) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 425 | { |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 426 | struct gl_renderbuffer *rb = att->Renderbuffer; |
| 427 | |
| 428 | /* tell driver that we're done rendering to this texture. */ |
| 429 | if (rb && rb->NeedsFinishRenderTexture) |
Eric Anholt | a5b0452 | 2013-05-10 12:17:52 -0700 | [diff] [blame] | 430 | ctx->Driver.FinishRenderTexture(ctx, rb); |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 431 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 432 | if (att->Type == GL_TEXTURE) { |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 433 | assert(att->Texture); |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 434 | _mesa_reference_texobj(&att->Texture, NULL); /* unbind */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 435 | assert(!att->Texture); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 436 | } |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 437 | if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) { |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 438 | assert(!att->Texture); |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 439 | _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 440 | assert(!att->Renderbuffer); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 441 | } |
| 442 | att->Type = GL_NONE; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 443 | att->Complete = GL_TRUE; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 446 | /** |
Ian Romanick | fb49713 | 2013-07-27 12:04:20 -0700 | [diff] [blame] | 447 | * Verify a couple error conditions that will lead to an incomplete FBO and |
| 448 | * may cause problems for the driver's RenderTexture path. |
| 449 | */ |
| 450 | static bool |
| 451 | driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment *att) |
| 452 | { |
| 453 | const struct gl_texture_image *const texImage = |
| 454 | att->Texture->Image[att->CubeMapFace][att->TextureLevel]; |
| 455 | |
Marek Olšák | 8a10192 | 2016-05-30 16:29:18 +0200 | [diff] [blame] | 456 | if (!texImage || |
| 457 | texImage->Width == 0 || texImage->Height == 0 || texImage->Depth == 0) |
Ian Romanick | fb49713 | 2013-07-27 12:04:20 -0700 | [diff] [blame] | 458 | return false; |
| 459 | |
Ian Romanick | 41485fe | 2013-07-27 12:16:56 -0700 | [diff] [blame] | 460 | if ((texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY |
| 461 | && att->Zoffset >= texImage->Height) |
| 462 | || (texImage->TexObject->Target != GL_TEXTURE_1D_ARRAY |
| 463 | && att->Zoffset >= texImage->Depth)) |
| 464 | return false; |
| 465 | |
Ian Romanick | fb49713 | 2013-07-27 12:04:20 -0700 | [diff] [blame] | 466 | return true; |
| 467 | } |
| 468 | |
| 469 | /** |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 470 | * Create a renderbuffer which will be set up by the driver to wrap the |
| 471 | * texture image slice. |
| 472 | * |
| 473 | * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get |
| 474 | * to share most of their framebuffer rendering code between winsys, |
| 475 | * renderbuffer, and texture attachments. |
| 476 | * |
| 477 | * The allocated renderbuffer uses a non-zero Name so that drivers can check |
| 478 | * it for determining vertical orientation, but we use ~0 to make it fairly |
| 479 | * unambiguous with actual user (non-texture) renderbuffers. |
| 480 | */ |
| 481 | void |
| 482 | _mesa_update_texture_renderbuffer(struct gl_context *ctx, |
| 483 | struct gl_framebuffer *fb, |
| 484 | struct gl_renderbuffer_attachment *att) |
| 485 | { |
| 486 | struct gl_texture_image *texImage; |
| 487 | struct gl_renderbuffer *rb; |
| 488 | |
Eric Anholt | e98c39c | 2013-05-10 11:51:01 -0700 | [diff] [blame] | 489 | texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel]; |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 490 | |
| 491 | rb = att->Renderbuffer; |
| 492 | if (!rb) { |
| 493 | rb = ctx->Driver.NewRenderbuffer(ctx, ~0); |
| 494 | if (!rb) { |
| 495 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()"); |
| 496 | return; |
| 497 | } |
Timothy Arceri | 8046a94 | 2017-04-07 07:55:17 +1000 | [diff] [blame] | 498 | att->Renderbuffer = rb; |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 499 | |
| 500 | /* This can't get called on a texture renderbuffer, so set it to NULL |
| 501 | * for clarity compared to user renderbuffers. |
| 502 | */ |
| 503 | rb->AllocStorage = NULL; |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 504 | |
| 505 | rb->NeedsFinishRenderTexture = ctx->Driver.FinishRenderTexture != NULL; |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Ian Romanick | 2f9fe2d | 2013-07-28 13:08:27 -0700 | [diff] [blame] | 508 | if (!texImage) |
| 509 | return; |
| 510 | |
Eric Anholt | 77a405d | 2013-04-22 11:04:21 -0700 | [diff] [blame] | 511 | rb->_BaseFormat = texImage->_BaseFormat; |
| 512 | rb->Format = texImage->TexFormat; |
| 513 | rb->InternalFormat = texImage->InternalFormat; |
| 514 | rb->Width = texImage->Width2; |
| 515 | rb->Height = texImage->Height2; |
Marek Olšák | a3969aa | 2013-11-20 01:47:36 +0100 | [diff] [blame] | 516 | rb->Depth = texImage->Depth2; |
Eric Anholt | 77a405d | 2013-04-22 11:04:21 -0700 | [diff] [blame] | 517 | rb->NumSamples = texImage->NumSamples; |
Marek Olšák | 328c1c8 | 2018-06-11 17:24:16 -0400 | [diff] [blame] | 518 | rb->NumStorageSamples = texImage->NumSamples; |
Eric Anholt | e98c39c | 2013-05-10 11:51:01 -0700 | [diff] [blame] | 519 | rb->TexImage = texImage; |
Eric Anholt | 77a405d | 2013-04-22 11:04:21 -0700 | [diff] [blame] | 520 | |
Ian Romanick | fb49713 | 2013-07-27 12:04:20 -0700 | [diff] [blame] | 521 | if (driver_RenderTexture_is_safe(att)) |
| 522 | ctx->Driver.RenderTexture(ctx, fb, att); |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 523 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 524 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 525 | /** |
| 526 | * Bind a texture object to an attachment point. |
| 527 | * The previous binding, if any, will be removed first. |
| 528 | */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 529 | static void |
| 530 | set_texture_attachment(struct gl_context *ctx, |
| 531 | struct gl_framebuffer *fb, |
| 532 | struct gl_renderbuffer_attachment *att, |
| 533 | struct gl_texture_object *texObj, |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 534 | GLenum texTarget, GLuint level, GLsizei samples, |
| 535 | GLuint layer, GLboolean layered) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 536 | { |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 537 | struct gl_renderbuffer *rb = att->Renderbuffer; |
| 538 | |
| 539 | if (rb && rb->NeedsFinishRenderTexture) |
Eric Anholt | a5b0452 | 2013-05-10 12:17:52 -0700 | [diff] [blame] | 540 | ctx->Driver.FinishRenderTexture(ctx, rb); |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 541 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 542 | if (att->Texture == texObj) { |
| 543 | /* re-attaching same texture */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 544 | assert(att->Type == GL_TEXTURE); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 545 | } |
| 546 | else { |
| 547 | /* new attachment */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 548 | remove_attachment(ctx, att); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 549 | att->Type = GL_TEXTURE; |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 550 | assert(!att->Texture); |
| 551 | _mesa_reference_texobj(&att->Texture, texObj); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 552 | } |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 553 | invalidate_framebuffer(fb); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 554 | |
| 555 | /* always update these fields */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 556 | att->TextureLevel = level; |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 557 | att->NumSamples = samples; |
Brian Paul | 26f1ad6 | 2009-10-23 18:15:55 -0600 | [diff] [blame] | 558 | att->CubeMapFace = _mesa_tex_target_to_face(texTarget); |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 559 | att->Zoffset = layer; |
Jordan Justen | a628080 | 2013-04-18 10:08:50 -0700 | [diff] [blame] | 560 | att->Layered = layered; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 561 | att->Complete = GL_FALSE; |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 562 | |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 563 | _mesa_update_texture_renderbuffer(ctx, fb, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 567 | /** |
| 568 | * Bind a renderbuffer to an attachment point. |
| 569 | * The previous binding, if any, will be removed first. |
| 570 | */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 571 | static void |
| 572 | set_renderbuffer_attachment(struct gl_context *ctx, |
| 573 | struct gl_renderbuffer_attachment *att, |
| 574 | struct gl_renderbuffer *rb) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 575 | { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 576 | /* XXX check if re-doing same attachment, exit early */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 577 | remove_attachment(ctx, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 578 | att->Type = GL_RENDERBUFFER_EXT; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 579 | att->Texture = NULL; /* just to be safe */ |
James Legg | 1581e12 | 2015-02-07 23:33:15 +0000 | [diff] [blame] | 580 | att->Layered = GL_FALSE; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 581 | att->Complete = GL_FALSE; |
Brian | dccd9c4 | 2007-04-02 09:56:28 -0600 | [diff] [blame] | 582 | _mesa_reference_renderbuffer(&att->Renderbuffer, rb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 583 | } |
| 584 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 585 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 586 | /** |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 587 | * Fallback for ctx->Driver.FramebufferRenderbuffer() |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 588 | * Attach a renderbuffer object to a framebuffer object. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 589 | */ |
| 590 | void |
Laura Ekstrand | 3d10037 | 2015-02-27 17:23:59 -0800 | [diff] [blame] | 591 | _mesa_FramebufferRenderbuffer_sw(struct gl_context *ctx, |
| 592 | struct gl_framebuffer *fb, |
| 593 | GLenum attachment, |
| 594 | struct gl_renderbuffer *rb) |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 595 | { |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 596 | struct gl_renderbuffer_attachment *att; |
| 597 | |
Timothy Arceri | f0857fe | 2017-10-16 11:59:31 +1100 | [diff] [blame] | 598 | simple_mtx_lock(&fb->Mutex); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 599 | |
Alejandro Piñeiro | c6eb3ae | 2017-01-12 16:03:00 -0200 | [diff] [blame] | 600 | att = get_attachment(ctx, fb, attachment, NULL); |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 601 | assert(att); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 602 | if (rb) { |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 603 | set_renderbuffer_attachment(ctx, att, rb); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 604 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 605 | /* do stencil attachment here (depth already done above) */ |
Alejandro Piñeiro | c6eb3ae | 2017-01-12 16:03:00 -0200 | [diff] [blame] | 606 | att = get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT, NULL); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 607 | assert(att); |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 608 | set_renderbuffer_attachment(ctx, att, rb); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 609 | } |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 610 | rb->AttachedAnytime = GL_TRUE; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 611 | } |
| 612 | else { |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 613 | remove_attachment(ctx, att); |
James Legg | 846c715 | 2014-05-23 12:25:37 +0100 | [diff] [blame] | 614 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 615 | /* detach stencil (depth was detached above) */ |
Alejandro Piñeiro | c6eb3ae | 2017-01-12 16:03:00 -0200 | [diff] [blame] | 616 | att = get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT, NULL); |
James Legg | 846c715 | 2014-05-23 12:25:37 +0100 | [diff] [blame] | 617 | assert(att); |
| 618 | remove_attachment(ctx, att); |
| 619 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 620 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 621 | |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 622 | invalidate_framebuffer(fb); |
| 623 | |
Timothy Arceri | f0857fe | 2017-10-16 11:59:31 +1100 | [diff] [blame] | 624 | simple_mtx_unlock(&fb->Mutex); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | |
| 628 | /** |
Brian Paul | 62c66b3 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 629 | * Fallback for ctx->Driver.ValidateFramebuffer() |
| 630 | * Check if the renderbuffer's formats are supported by the software |
| 631 | * renderer. |
| 632 | * Drivers should probably override this. |
| 633 | */ |
| 634 | void |
| 635 | _mesa_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb) |
| 636 | { |
| 637 | gl_buffer_index buf; |
| 638 | for (buf = 0; buf < BUFFER_COUNT; buf++) { |
| 639 | const struct gl_renderbuffer *rb = fb->Attachment[buf].Renderbuffer; |
| 640 | if (rb) { |
| 641 | switch (rb->_BaseFormat) { |
| 642 | case GL_ALPHA: |
| 643 | case GL_LUMINANCE_ALPHA: |
| 644 | case GL_LUMINANCE: |
| 645 | case GL_INTENSITY: |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 646 | case GL_RED: |
| 647 | case GL_RG: |
Brian Paul | 62c66b3 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 648 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
| 649 | return; |
Marek Olšák | a3ac28a | 2011-05-14 04:42:29 +0200 | [diff] [blame] | 650 | |
| 651 | default: |
Marek Olšák | 9d7698c | 2011-04-26 02:18:24 +0200 | [diff] [blame] | 652 | switch (rb->Format) { |
Marek Olšák | a3ac28a | 2011-05-14 04:42:29 +0200 | [diff] [blame] | 653 | /* XXX This list is likely incomplete. */ |
Mark Mueller | eeed49f | 2014-01-26 15:12:56 -0800 | [diff] [blame] | 654 | case MESA_FORMAT_R9G9B9E5_FLOAT: |
Marek Olšák | 9d7698c | 2011-04-26 02:18:24 +0200 | [diff] [blame] | 655 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
| 656 | return; |
| 657 | default:; |
Marek Olšák | a3ac28a | 2011-05-14 04:42:29 +0200 | [diff] [blame] | 658 | /* render buffer format is supported by software rendering */ |
Marek Olšák | 9d7698c | 2011-04-26 02:18:24 +0200 | [diff] [blame] | 659 | } |
Brian Paul | 62c66b3 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | |
| 666 | /** |
Marek Olšák | f8855a4 | 2013-03-14 14:22:56 +0100 | [diff] [blame] | 667 | * Return true if the framebuffer has a combined depth/stencil |
| 668 | * renderbuffer attached. |
| 669 | */ |
| 670 | GLboolean |
| 671 | _mesa_has_depthstencil_combined(const struct gl_framebuffer *fb) |
| 672 | { |
| 673 | const struct gl_renderbuffer_attachment *depth = |
| 674 | &fb->Attachment[BUFFER_DEPTH]; |
| 675 | const struct gl_renderbuffer_attachment *stencil = |
| 676 | &fb->Attachment[BUFFER_STENCIL]; |
| 677 | |
| 678 | if (depth->Type == stencil->Type) { |
| 679 | if (depth->Type == GL_RENDERBUFFER_EXT && |
| 680 | depth->Renderbuffer == stencil->Renderbuffer) |
| 681 | return GL_TRUE; |
| 682 | |
| 683 | if (depth->Type == GL_TEXTURE && |
| 684 | depth->Texture == stencil->Texture) |
| 685 | return GL_TRUE; |
| 686 | } |
| 687 | |
| 688 | return GL_FALSE; |
| 689 | } |
| 690 | |
| 691 | |
| 692 | /** |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 693 | * For debug only. |
| 694 | */ |
| 695 | static void |
| 696 | att_incomplete(const char *msg) |
| 697 | { |
Brian Paul | 93bcf78 | 2012-05-09 12:09:21 -0600 | [diff] [blame] | 698 | if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) { |
| 699 | _mesa_debug(NULL, "attachment incomplete: %s\n", msg); |
| 700 | } |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | |
| 704 | /** |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 705 | * For debug only. |
| 706 | */ |
| 707 | static void |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 708 | fbo_incomplete(struct gl_context *ctx, const char *msg, int index) |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 709 | { |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 710 | static GLuint msg_id; |
| 711 | |
Mark Janes | b8a1a32 | 2018-12-06 16:35:43 -0800 | [diff] [blame] | 712 | _mesa_gl_debugf(ctx, &msg_id, |
| 713 | MESA_DEBUG_SOURCE_API, |
| 714 | MESA_DEBUG_TYPE_OTHER, |
| 715 | MESA_DEBUG_SEVERITY_MEDIUM, |
| 716 | "FBO incomplete: %s [%d]\n", msg, index); |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 717 | |
Brian Paul | 93bcf78 | 2012-05-09 12:09:21 -0600 | [diff] [blame] | 718 | if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) { |
| 719 | _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index); |
| 720 | } |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 724 | /** |
| 725 | * Is the given base format a legal format for a color renderbuffer? |
| 726 | */ |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 727 | GLboolean |
| 728 | _mesa_is_legal_color_format(const struct gl_context *ctx, GLenum baseFormat) |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 729 | { |
| 730 | switch (baseFormat) { |
| 731 | case GL_RGB: |
| 732 | case GL_RGBA: |
| 733 | return GL_TRUE; |
Marek Olšák | 6e61853 | 2010-10-02 21:53:03 +0200 | [diff] [blame] | 734 | case GL_LUMINANCE: |
| 735 | case GL_LUMINANCE_ALPHA: |
| 736 | case GL_INTENSITY: |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 737 | case GL_ALPHA: |
Jordan Justen | cf300ea | 2012-12-27 12:41:10 -0800 | [diff] [blame] | 738 | return ctx->API == API_OPENGL_COMPAT && |
| 739 | ctx->Extensions.ARB_framebuffer_object; |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 740 | case GL_RED: |
| 741 | case GL_RG: |
| 742 | return ctx->Extensions.ARB_texture_rg; |
| 743 | default: |
| 744 | return GL_FALSE; |
| 745 | } |
| 746 | } |
| 747 | |
Tapani Pälli | 331e5f1 | 2020-08-28 13:04:21 +0300 | [diff] [blame] | 748 | static GLboolean |
| 749 | is_float_format(GLenum internalFormat) |
| 750 | { |
| 751 | switch (internalFormat) { |
| 752 | case GL_R16F: |
| 753 | case GL_RG16F: |
| 754 | case GL_RGB16F: |
| 755 | case GL_RGBA16F: |
| 756 | case GL_R32F: |
| 757 | case GL_RG32F: |
| 758 | case GL_RGB32F: |
| 759 | case GL_RGBA32F: |
| 760 | return true; |
| 761 | default: |
| 762 | return false; |
| 763 | } |
| 764 | } |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 765 | |
| 766 | /** |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 767 | * Is the given base format a legal format for a color renderbuffer? |
| 768 | */ |
| 769 | static GLboolean |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 770 | is_format_color_renderable(const struct gl_context *ctx, mesa_format format, |
| 771 | GLenum internalFormat) |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 772 | { |
| 773 | const GLenum baseFormat = |
| 774 | _mesa_get_format_base_format(format); |
| 775 | GLboolean valid; |
| 776 | |
| 777 | valid = _mesa_is_legal_color_format(ctx, baseFormat); |
| 778 | if (!valid || _mesa_is_desktop_gl(ctx)) { |
| 779 | return valid; |
| 780 | } |
| 781 | |
| 782 | /* Reject additional cases for GLES */ |
| 783 | switch (internalFormat) { |
Tapani Pälli | 0d356cf | 2018-05-24 14:05:27 +0300 | [diff] [blame] | 784 | case GL_R8_SNORM: |
| 785 | case GL_RG8_SNORM: |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 786 | case GL_RGBA8_SNORM: |
Tapani Pälli | 0d356cf | 2018-05-24 14:05:27 +0300 | [diff] [blame] | 787 | return _mesa_has_EXT_render_snorm(ctx); |
| 788 | case GL_R16_SNORM: |
| 789 | case GL_RG16_SNORM: |
| 790 | case GL_RGBA16_SNORM: |
| 791 | return _mesa_has_EXT_texture_norm16(ctx) && |
| 792 | _mesa_has_EXT_render_snorm(ctx); |
Tapani Pälli | 331e5f1 | 2020-08-28 13:04:21 +0300 | [diff] [blame] | 793 | case GL_R: |
| 794 | case GL_RG: |
| 795 | return _mesa_has_EXT_texture_rg(ctx); |
| 796 | case GL_R16F: |
| 797 | case GL_RG16F: |
Tapani Pälli | 8447b0f | 2020-09-01 14:20:27 +0300 | [diff] [blame] | 798 | return _mesa_is_gles3(ctx) || |
| 799 | (_mesa_has_EXT_color_buffer_half_float(ctx) && |
| 800 | _mesa_has_EXT_texture_rg(ctx)); |
Tapani Pälli | 331e5f1 | 2020-08-28 13:04:21 +0300 | [diff] [blame] | 801 | case GL_RGBA16F: |
| 802 | case GL_RGBA32F: |
| 803 | return _mesa_has_EXT_color_buffer_float(ctx); |
Tapani Pälli | 8447b0f | 2020-09-01 14:20:27 +0300 | [diff] [blame] | 804 | case GL_RGB16F: |
| 805 | return _mesa_has_EXT_color_buffer_half_float(ctx) && |
| 806 | _mesa_has_OES_texture_half_float(ctx); |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 807 | case GL_RGB32F: |
| 808 | case GL_RGB32I: |
| 809 | case GL_RGB32UI: |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 810 | case GL_RGB16I: |
| 811 | case GL_RGB16UI: |
| 812 | case GL_RGB8_SNORM: |
| 813 | case GL_RGB8I: |
| 814 | case GL_RGB8UI: |
| 815 | case GL_SRGB8: |
Eric Anholt | c16a744 | 2017-05-01 09:28:33 -0700 | [diff] [blame] | 816 | case GL_RGB10: |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 817 | case GL_RGB9_E5: |
Marek Olšák | 32a3347 | 2018-11-09 16:47:46 -0500 | [diff] [blame] | 818 | case GL_SR8_EXT: |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 819 | return GL_FALSE; |
| 820 | default: |
| 821 | break; |
| 822 | } |
| 823 | |
Nicolai Hähnle | d2b60e4 | 2017-09-27 15:25:10 +0200 | [diff] [blame] | 824 | if (internalFormat != GL_RGB10_A2 && |
| 825 | (format == MESA_FORMAT_B10G10R10A2_UNORM || |
| 826 | format == MESA_FORMAT_B10G10R10X2_UNORM || |
| 827 | format == MESA_FORMAT_R10G10B10A2_UNORM || |
| 828 | format == MESA_FORMAT_R10G10B10X2_UNORM)) { |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 829 | return GL_FALSE; |
| 830 | } |
| 831 | |
| 832 | return GL_TRUE; |
| 833 | } |
| 834 | |
Tapani Pälli | 331e5f1 | 2020-08-28 13:04:21 +0300 | [diff] [blame] | 835 | /** |
| 836 | * Check that implements various limitations of floating point |
| 837 | * rendering extensions on OpenGL ES. |
| 838 | * |
| 839 | * Check passes if texture format is not floating point or |
| 840 | * is floating point and is color renderable. |
| 841 | * |
| 842 | * Check fails if texture format is floating point and cannot |
| 843 | * be rendered to with current context and set of supported |
| 844 | * extensions. |
| 845 | */ |
| 846 | static GLboolean |
| 847 | gles_check_float_renderable(const struct gl_context *ctx, |
| 848 | struct gl_renderbuffer_attachment *att) |
| 849 | { |
| 850 | /* Only check floating point texture cases. */ |
| 851 | if (!att->Texture || !is_float_format(att->Renderbuffer->InternalFormat)) |
| 852 | return true; |
| 853 | |
| 854 | /* GL_RGBA with unsized GL_FLOAT type, no extension can make this |
| 855 | * color renderable. |
| 856 | */ |
| 857 | if (att->Texture->_IsFloat && att->Renderbuffer->_BaseFormat == GL_RGBA) |
| 858 | return false; |
| 859 | |
| 860 | /* Unsized GL_HALF_FLOAT supported only with EXT_color_buffer_half_float. */ |
Tapani Pälli | 8447b0f | 2020-09-01 14:20:27 +0300 | [diff] [blame] | 861 | if (att->Texture->_IsHalfFloat && !_mesa_has_EXT_color_buffer_half_float(ctx)) |
Tapani Pälli | 331e5f1 | 2020-08-28 13:04:21 +0300 | [diff] [blame] | 862 | return false; |
| 863 | |
| 864 | const struct gl_texture_object *texObj = att->Texture; |
| 865 | const struct gl_texture_image *texImage = |
| 866 | texObj->Image[att->CubeMapFace][att->TextureLevel]; |
| 867 | |
| 868 | return is_format_color_renderable(ctx, texImage->TexFormat, |
| 869 | att->Renderbuffer->InternalFormat); |
| 870 | } |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 871 | |
| 872 | /** |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 873 | * Is the given base format a legal format for a depth/stencil renderbuffer? |
| 874 | */ |
| 875 | static GLboolean |
| 876 | is_legal_depth_format(const struct gl_context *ctx, GLenum baseFormat) |
| 877 | { |
| 878 | switch (baseFormat) { |
| 879 | case GL_DEPTH_COMPONENT: |
| 880 | case GL_DEPTH_STENCIL_EXT: |
| 881 | return GL_TRUE; |
| 882 | default: |
| 883 | return GL_FALSE; |
| 884 | } |
| 885 | } |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 886 | |
| 887 | |
| 888 | /** |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 889 | * Test if an attachment point is complete and update its Complete field. |
| 890 | * \param format if GL_COLOR, this is a color attachment point, |
| 891 | * if GL_DEPTH, this is a depth component attachment point, |
| 892 | * if GL_STENCIL, this is a stencil component attachment point. |
| 893 | */ |
| 894 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 895 | test_attachment_completeness(const struct gl_context *ctx, GLenum format, |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 896 | struct gl_renderbuffer_attachment *att) |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 897 | { |
| 898 | assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL); |
| 899 | |
| 900 | /* assume complete */ |
| 901 | att->Complete = GL_TRUE; |
| 902 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 903 | /* Look for reasons why the attachment might be incomplete */ |
| 904 | if (att->Type == GL_TEXTURE) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 905 | const struct gl_texture_object *texObj = att->Texture; |
Brian Paul | b2c3fd9 | 2017-12-04 21:27:54 -0700 | [diff] [blame] | 906 | const struct gl_texture_image *texImage; |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 907 | GLenum baseFormat; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 908 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 909 | if (!texObj) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 910 | att_incomplete("no texobj"); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 911 | att->Complete = GL_FALSE; |
| 912 | return; |
| 913 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 914 | |
| 915 | texImage = texObj->Image[att->CubeMapFace][att->TextureLevel]; |
| 916 | if (!texImage) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 917 | att_incomplete("no teximage"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 918 | att->Complete = GL_FALSE; |
| 919 | return; |
| 920 | } |
| 921 | if (texImage->Width < 1 || texImage->Height < 1) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 922 | att_incomplete("teximage width/height=0"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 923 | att->Complete = GL_FALSE; |
| 924 | return; |
| 925 | } |
Ian Romanick | 25281fe | 2013-07-27 12:27:45 -0700 | [diff] [blame] | 926 | |
| 927 | switch (texObj->Target) { |
| 928 | case GL_TEXTURE_3D: |
| 929 | if (att->Zoffset >= texImage->Depth) { |
| 930 | att_incomplete("bad z offset"); |
| 931 | att->Complete = GL_FALSE; |
| 932 | return; |
| 933 | } |
| 934 | break; |
| 935 | case GL_TEXTURE_1D_ARRAY: |
| 936 | if (att->Zoffset >= texImage->Height) { |
| 937 | att_incomplete("bad 1D-array layer"); |
| 938 | att->Complete = GL_FALSE; |
| 939 | return; |
| 940 | } |
| 941 | break; |
| 942 | case GL_TEXTURE_2D_ARRAY: |
| 943 | if (att->Zoffset >= texImage->Depth) { |
| 944 | att_incomplete("bad 2D-array layer"); |
| 945 | att->Complete = GL_FALSE; |
| 946 | return; |
| 947 | } |
| 948 | break; |
| 949 | case GL_TEXTURE_CUBE_MAP_ARRAY: |
| 950 | if (att->Zoffset >= texImage->Depth) { |
| 951 | att_incomplete("bad cube-array layer"); |
| 952 | att->Complete = GL_FALSE; |
| 953 | return; |
| 954 | } |
| 955 | break; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Ilia Mirkin | 68c4af1 | 2016-02-17 20:31:38 -0500 | [diff] [blame] | 958 | baseFormat = texImage->_BaseFormat; |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 959 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 960 | if (format == GL_COLOR) { |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 961 | if (!_mesa_is_legal_color_format(ctx, baseFormat)) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 962 | att_incomplete("bad format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 963 | att->Complete = GL_FALSE; |
| 964 | return; |
| 965 | } |
Brian Paul | 1f7c914 | 2009-09-30 20:28:45 -0600 | [diff] [blame] | 966 | if (_mesa_is_format_compressed(texImage->TexFormat)) { |
Eric Anholt | 957f3c8 | 2009-05-15 16:24:59 -0700 | [diff] [blame] | 967 | att_incomplete("compressed internalformat"); |
| 968 | att->Complete = GL_FALSE; |
| 969 | return; |
| 970 | } |
Tapani Pälli | e333035 | 2015-02-12 14:33:53 +0200 | [diff] [blame] | 971 | |
| 972 | /* OES_texture_float allows creation and use of floating point |
| 973 | * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow |
| 974 | * these textures to be used as a render target, this is done via |
| 975 | * GL_EXT_color_buffer(_half)_float with set of new sized types. |
| 976 | */ |
Tapani Pälli | 331e5f1 | 2020-08-28 13:04:21 +0300 | [diff] [blame] | 977 | if (_mesa_is_gles(ctx) && !gles_check_float_renderable(ctx, att)) { |
Tapani Pälli | e333035 | 2015-02-12 14:33:53 +0200 | [diff] [blame] | 978 | att_incomplete("bad internal format"); |
| 979 | att->Complete = GL_FALSE; |
| 980 | return; |
| 981 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 982 | } |
| 983 | else if (format == GL_DEPTH) { |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 984 | if (baseFormat == GL_DEPTH_COMPONENT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 985 | /* OK */ |
| 986 | } |
Ian Romanick | a92b9e6 | 2013-11-13 14:10:34 -0800 | [diff] [blame] | 987 | else if (ctx->Extensions.ARB_depth_texture && |
Ian Romanick | 4949322 | 2013-11-13 14:15:11 -0800 | [diff] [blame] | 988 | baseFormat == GL_DEPTH_STENCIL) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 989 | /* OK */ |
| 990 | } |
| 991 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 992 | att->Complete = GL_FALSE; |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 993 | att_incomplete("bad depth format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 994 | return; |
| 995 | } |
| 996 | } |
| 997 | else { |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 998 | assert(format == GL_STENCIL); |
Ian Romanick | a92b9e6 | 2013-11-13 14:10:34 -0800 | [diff] [blame] | 999 | if (ctx->Extensions.ARB_depth_texture && |
Ian Romanick | 4949322 | 2013-11-13 14:15:11 -0800 | [diff] [blame] | 1000 | baseFormat == GL_DEPTH_STENCIL) { |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 1001 | /* OK */ |
Dave Airlie | 782e71c | 2015-04-05 13:19:18 +1000 | [diff] [blame] | 1002 | } else if (ctx->Extensions.ARB_texture_stencil8 && |
| 1003 | baseFormat == GL_STENCIL_INDEX) { |
| 1004 | /* OK */ |
| 1005 | } else { |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 1006 | /* no such thing as stencil-only textures */ |
| 1007 | att_incomplete("illegal stencil texture"); |
| 1008 | att->Complete = GL_FALSE; |
| 1009 | return; |
| 1010 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1011 | } |
| 1012 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1013 | else if (att->Type == GL_RENDERBUFFER_EXT) { |
Ilia Mirkin | 68c4af1 | 2016-02-17 20:31:38 -0500 | [diff] [blame] | 1014 | const GLenum baseFormat = att->Renderbuffer->_BaseFormat; |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1015 | |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 1016 | assert(att->Renderbuffer); |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 1017 | if (!att->Renderbuffer->InternalFormat || |
| 1018 | att->Renderbuffer->Width < 1 || |
| 1019 | att->Renderbuffer->Height < 1) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 1020 | att_incomplete("0x0 renderbuffer"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1021 | att->Complete = GL_FALSE; |
| 1022 | return; |
| 1023 | } |
| 1024 | if (format == GL_COLOR) { |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 1025 | if (!_mesa_is_legal_color_format(ctx, baseFormat)) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 1026 | att_incomplete("bad renderbuffer color format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1027 | att->Complete = GL_FALSE; |
| 1028 | return; |
| 1029 | } |
| 1030 | } |
| 1031 | else if (format == GL_DEPTH) { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1032 | if (baseFormat == GL_DEPTH_COMPONENT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 1033 | /* OK */ |
| 1034 | } |
Ian Romanick | 4949322 | 2013-11-13 14:15:11 -0800 | [diff] [blame] | 1035 | else if (baseFormat == GL_DEPTH_STENCIL) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 1036 | /* OK */ |
| 1037 | } |
| 1038 | else { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 1039 | att_incomplete("bad renderbuffer depth format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1040 | att->Complete = GL_FALSE; |
| 1041 | return; |
| 1042 | } |
| 1043 | } |
| 1044 | else { |
| 1045 | assert(format == GL_STENCIL); |
Ian Romanick | 4949322 | 2013-11-13 14:15:11 -0800 | [diff] [blame] | 1046 | if (baseFormat == GL_STENCIL_INDEX || |
| 1047 | baseFormat == GL_DEPTH_STENCIL) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 1048 | /* OK */ |
| 1049 | } |
| 1050 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1051 | att->Complete = GL_FALSE; |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 1052 | att_incomplete("bad renderbuffer stencil format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1053 | return; |
| 1054 | } |
| 1055 | } |
| 1056 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1057 | else { |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 1058 | assert(att->Type == GL_NONE); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1059 | /* complete */ |
| 1060 | return; |
| 1061 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | |
| 1065 | /** |
| 1066 | * Test if the given framebuffer object is complete and update its |
| 1067 | * Status field with the results. |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1068 | * Calls the ctx->Driver.ValidateFramebuffer() function to allow the |
| 1069 | * driver to make hardware-specific validation/completeness checks. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1070 | * Also update the framebuffer's Width and Height fields if the |
| 1071 | * framebuffer is complete. |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1072 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1073 | void |
Brian Paul | f928854 | 2010-10-22 11:25:14 -0600 | [diff] [blame] | 1074 | _mesa_test_framebuffer_completeness(struct gl_context *ctx, |
| 1075 | struct gl_framebuffer *fb) |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1076 | { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1077 | GLuint numImages; |
| 1078 | GLenum intFormat = GL_NONE; /* color buffers' internal format */ |
| 1079 | GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0; |
Marek Olšák | 459f05c | 2018-06-11 18:30:34 -0400 | [diff] [blame] | 1080 | GLint numColorSamples = -1; |
| 1081 | GLint numColorStorageSamples = -1; |
| 1082 | GLint numDepthSamples = -1; |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1083 | GLint fixedSampleLocations = -1; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1084 | GLint i; |
Brian Paul | 28b014e | 2006-04-05 03:05:17 +0000 | [diff] [blame] | 1085 | GLuint j; |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1086 | /* Covers max_layer_count, is_layered, and layer_tex_target */ |
| 1087 | bool layer_info_valid = false; |
| 1088 | GLuint max_layer_count = 0, att_layer_count; |
Brian Paul | 5306ee7 | 2014-01-22 10:02:28 -0800 | [diff] [blame] | 1089 | bool is_layered = false; |
Paul Berry | 28af1dc | 2013-11-19 19:01:37 -0800 | [diff] [blame] | 1090 | GLenum layer_tex_target = 0; |
Iago Toral Quiroga | d42e090 | 2014-12-12 15:14:32 +0100 | [diff] [blame] | 1091 | bool has_depth_attachment = false; |
| 1092 | bool has_stencil_attachment = false; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1093 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 1094 | assert(_mesa_is_user_fbo(fb)); |
Brian Paul | c726441 | 2005-06-01 00:50:23 +0000 | [diff] [blame] | 1095 | |
Marek Olšák | e06d616 | 2012-08-04 13:37:03 +0200 | [diff] [blame] | 1096 | /* we're changing framebuffer fields here */ |
| 1097 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 1098 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1099 | numImages = 0; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1100 | fb->Width = 0; |
| 1101 | fb->Height = 0; |
Marek Olšák | 21d407c | 2013-03-28 01:50:21 +0100 | [diff] [blame] | 1102 | fb->_AllColorBuffersFixedPoint = GL_TRUE; |
Marek Olšák | 755648c | 2013-03-28 01:56:01 +0100 | [diff] [blame] | 1103 | fb->_HasSNormOrFloatColorBuffer = GL_FALSE; |
Kevin Rogovin | da81999 | 2015-06-17 13:29:50 +0300 | [diff] [blame] | 1104 | fb->_HasAttachments = true; |
Brian Paul | ff00ab7 | 2016-10-10 11:29:14 -0600 | [diff] [blame] | 1105 | fb->_IntegerBuffers = 0; |
Kenneth Graunke | 5b51d75 | 2018-07-21 23:40:16 -0700 | [diff] [blame] | 1106 | fb->_RGBBuffers = 0; |
Ilia Mirkin | 070a5e5 | 2019-02-12 21:32:27 -0500 | [diff] [blame] | 1107 | fb->_FP32Buffers = 0; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1108 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1109 | /* Start at -2 to more easily loop over all attachment points. |
| 1110 | * -2: depth buffer |
| 1111 | * -1: stencil buffer |
| 1112 | * >=0: color buffer |
| 1113 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1114 | for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1115 | struct gl_renderbuffer_attachment *att; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1116 | GLenum f; |
Kenneth Graunke | 6921588 | 2019-02-22 01:16:41 -0800 | [diff] [blame] | 1117 | GLenum baseFormat; |
Mark Mueller | 71fe943 | 2014-01-04 14:11:43 -0800 | [diff] [blame] | 1118 | mesa_format attFormat; |
Paul Berry | 9514074 | 2013-11-19 15:55:51 -0800 | [diff] [blame] | 1119 | GLenum att_tex_target = GL_NONE; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1120 | |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 1121 | /* |
| 1122 | * XXX for ARB_fbo, only check color buffers that are named by |
| 1123 | * GL_READ_BUFFER and GL_DRAW_BUFFERi. |
| 1124 | */ |
| 1125 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1126 | /* check for attachment completeness |
| 1127 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1128 | if (i == -2) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1129 | att = &fb->Attachment[BUFFER_DEPTH]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1130 | test_attachment_completeness(ctx, GL_DEPTH, att); |
| 1131 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1132 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1133 | fbo_incomplete(ctx, "depth attachment incomplete", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1134 | return; |
Iago Toral Quiroga | d42e090 | 2014-12-12 15:14:32 +0100 | [diff] [blame] | 1135 | } else if (att->Type != GL_NONE) { |
| 1136 | has_depth_attachment = true; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | else if (i == -1) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1140 | att = &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1141 | test_attachment_completeness(ctx, GL_STENCIL, att); |
| 1142 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1143 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1144 | fbo_incomplete(ctx, "stencil attachment incomplete", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1145 | return; |
Iago Toral Quiroga | d42e090 | 2014-12-12 15:14:32 +0100 | [diff] [blame] | 1146 | } else if (att->Type != GL_NONE) { |
| 1147 | has_stencil_attachment = true; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1151 | att = &fb->Attachment[BUFFER_COLOR0 + i]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1152 | test_attachment_completeness(ctx, GL_COLOR, att); |
| 1153 | if (!att->Complete) { |
Tapani Pälli | 8447b0f | 2020-09-01 14:20:27 +0300 | [diff] [blame] | 1154 | /* With EXT_color_buffer_half_float, check if attachment was incomplete |
| 1155 | * due to invalid format. This is special case for the extension where |
| 1156 | * CTS tests expect unsupported framebuffer status instead of incomplete. |
| 1157 | */ |
| 1158 | if ((_mesa_is_gles(ctx) && _mesa_has_EXT_color_buffer_half_float(ctx)) && |
| 1159 | !gles_check_float_renderable(ctx, att)) { |
| 1160 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
| 1161 | return; |
| 1162 | } |
| 1163 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1164 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1165 | fbo_incomplete(ctx, "color attachment incomplete", i); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1166 | return; |
| 1167 | } |
| 1168 | } |
| 1169 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1170 | /* get width, height, format of the renderbuffer/texture |
| 1171 | */ |
Marek Olšák | 459f05c | 2018-06-11 18:30:34 -0400 | [diff] [blame] | 1172 | unsigned attNumSamples, attNumStorageSamples; |
| 1173 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1174 | if (att->Type == GL_TEXTURE) { |
Eric Anholt | e98c39c | 2013-05-10 11:51:01 -0700 | [diff] [blame] | 1175 | const struct gl_texture_image *texImg = att->Renderbuffer->TexImage; |
Paul Berry | 9514074 | 2013-11-19 15:55:51 -0800 | [diff] [blame] | 1176 | att_tex_target = att->Texture->Target; |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1177 | minWidth = MIN2(minWidth, texImg->Width); |
| 1178 | maxWidth = MAX2(maxWidth, texImg->Width); |
| 1179 | minHeight = MIN2(minHeight, texImg->Height); |
| 1180 | maxHeight = MAX2(maxHeight, texImg->Height); |
Brian Paul | a9fc8ba | 2005-10-05 01:48:07 +0000 | [diff] [blame] | 1181 | f = texImg->_BaseFormat; |
Kenneth Graunke | 6921588 | 2019-02-22 01:16:41 -0800 | [diff] [blame] | 1182 | baseFormat = f; |
Brian Paul | ca1b551 | 2011-02-28 18:23:23 -0700 | [diff] [blame] | 1183 | attFormat = texImg->TexFormat; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1184 | numImages++; |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1185 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1186 | if (!is_format_color_renderable(ctx, attFormat, |
| 1187 | texImg->InternalFormat) && |
Dave Airlie | 782e71c | 2015-04-05 13:19:18 +1000 | [diff] [blame] | 1188 | !is_legal_depth_format(ctx, f) && |
| 1189 | f != GL_STENCIL_INDEX) { |
Iago Toral Quiroga | b6819cd | 2014-12-15 09:29:55 +0100 | [diff] [blame] | 1190 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1191 | fbo_incomplete(ctx, "texture attachment incomplete", -1); |
Brian Paul | ed7f3ae | 2005-06-07 15:03:40 +0000 | [diff] [blame] | 1192 | return; |
| 1193 | } |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1194 | |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1195 | if (fixedSampleLocations < 0) |
| 1196 | fixedSampleLocations = texImg->FixedSampleLocations; |
| 1197 | else if (fixedSampleLocations != texImg->FixedSampleLocations) { |
| 1198 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1199 | fbo_incomplete(ctx, "inconsistent fixed sample locations", -1); |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1200 | return; |
| 1201 | } |
Marek Olšák | 459f05c | 2018-06-11 18:30:34 -0400 | [diff] [blame] | 1202 | |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 1203 | if (att->NumSamples > 0) |
| 1204 | attNumSamples = att->NumSamples; |
| 1205 | else |
| 1206 | attNumSamples = texImg->NumSamples; |
| 1207 | attNumStorageSamples = attNumSamples; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1208 | } |
| 1209 | else if (att->Type == GL_RENDERBUFFER_EXT) { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1210 | minWidth = MIN2(minWidth, att->Renderbuffer->Width); |
| 1211 | maxWidth = MAX2(minWidth, att->Renderbuffer->Width); |
| 1212 | minHeight = MIN2(minHeight, att->Renderbuffer->Height); |
| 1213 | maxHeight = MAX2(minHeight, att->Renderbuffer->Height); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1214 | f = att->Renderbuffer->InternalFormat; |
Kenneth Graunke | 6921588 | 2019-02-22 01:16:41 -0800 | [diff] [blame] | 1215 | baseFormat = att->Renderbuffer->_BaseFormat; |
Brian Paul | ca1b551 | 2011-02-28 18:23:23 -0700 | [diff] [blame] | 1216 | attFormat = att->Renderbuffer->Format; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1217 | numImages++; |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1218 | |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1219 | /* RENDERBUFFER has fixedSampleLocations implicitly true */ |
| 1220 | if (fixedSampleLocations < 0) |
| 1221 | fixedSampleLocations = GL_TRUE; |
| 1222 | else if (fixedSampleLocations != GL_TRUE) { |
| 1223 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1224 | fbo_incomplete(ctx, "inconsistent fixed sample locations", -1); |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1225 | return; |
| 1226 | } |
Marek Olšák | 459f05c | 2018-06-11 18:30:34 -0400 | [diff] [blame] | 1227 | |
| 1228 | attNumSamples = att->Renderbuffer->NumSamples; |
| 1229 | attNumStorageSamples = att->Renderbuffer->NumStorageSamples; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1230 | } |
| 1231 | else { |
| 1232 | assert(att->Type == GL_NONE); |
| 1233 | continue; |
| 1234 | } |
| 1235 | |
Marek Olšák | 459f05c | 2018-06-11 18:30:34 -0400 | [diff] [blame] | 1236 | if (i >= 0) { |
| 1237 | /* Color buffers. */ |
| 1238 | if (numColorSamples < 0) { |
| 1239 | assert(numColorStorageSamples < 0); |
| 1240 | numColorSamples = attNumSamples; |
| 1241 | numColorStorageSamples = attNumStorageSamples; |
| 1242 | } else if (numColorSamples != attNumSamples || |
| 1243 | numColorStorageSamples != attNumStorageSamples) { |
| 1244 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| 1245 | fbo_incomplete(ctx, "inconsistent sample counts", -1); |
| 1246 | return; |
| 1247 | } |
| 1248 | } else { |
| 1249 | /* Depth/stencil buffers. */ |
| 1250 | if (numDepthSamples < 0) { |
| 1251 | numDepthSamples = attNumSamples; |
| 1252 | } else if (numDepthSamples != attNumSamples) { |
| 1253 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| 1254 | fbo_incomplete(ctx, "inconsistent sample counts", -1); |
| 1255 | return; |
| 1256 | } |
| 1257 | } |
| 1258 | |
Brian Paul | ff00ab7 | 2016-10-10 11:29:14 -0600 | [diff] [blame] | 1259 | /* Update flags describing color buffer datatypes */ |
Marek Olšák | 21d407c | 2013-03-28 01:50:21 +0100 | [diff] [blame] | 1260 | if (i >= 0) { |
| 1261 | GLenum type = _mesa_get_format_datatype(attFormat); |
| 1262 | |
Brian Paul | ff00ab7 | 2016-10-10 11:29:14 -0600 | [diff] [blame] | 1263 | /* check if integer color */ |
| 1264 | if (_mesa_is_format_integer_color(attFormat)) |
| 1265 | fb->_IntegerBuffers |= (1 << i); |
| 1266 | |
Kenneth Graunke | 6921588 | 2019-02-22 01:16:41 -0800 | [diff] [blame] | 1267 | if (baseFormat == GL_RGB) |
Kenneth Graunke | 5b51d75 | 2018-07-21 23:40:16 -0700 | [diff] [blame] | 1268 | fb->_RGBBuffers |= (1 << i); |
| 1269 | |
Ilia Mirkin | 070a5e5 | 2019-02-12 21:32:27 -0500 | [diff] [blame] | 1270 | if (type == GL_FLOAT && _mesa_get_format_max_bits(attFormat) > 16) |
| 1271 | fb->_FP32Buffers |= (1 << i); |
| 1272 | |
Marek Olšák | 21d407c | 2013-03-28 01:50:21 +0100 | [diff] [blame] | 1273 | fb->_AllColorBuffersFixedPoint = |
| 1274 | fb->_AllColorBuffersFixedPoint && |
| 1275 | (type == GL_UNSIGNED_NORMALIZED || type == GL_SIGNED_NORMALIZED); |
Marek Olšák | 755648c | 2013-03-28 01:56:01 +0100 | [diff] [blame] | 1276 | |
| 1277 | fb->_HasSNormOrFloatColorBuffer = |
| 1278 | fb->_HasSNormOrFloatColorBuffer || |
| 1279 | type == GL_SIGNED_NORMALIZED || type == GL_FLOAT; |
Marek Olšák | 21d407c | 2013-03-28 01:50:21 +0100 | [diff] [blame] | 1280 | } |
| 1281 | |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1282 | /* Error-check width, height, format */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1283 | if (numImages == 1) { |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1284 | /* save format */ |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1285 | if (i >= 0) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1286 | intFormat = f; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1287 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1288 | } |
| 1289 | else { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1290 | if (!ctx->Extensions.ARB_framebuffer_object) { |
| 1291 | /* check that width, height, format are same */ |
| 1292 | if (minWidth != maxWidth || minHeight != maxHeight) { |
| 1293 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1294 | fbo_incomplete(ctx, "width or height mismatch", -1); |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1295 | return; |
| 1296 | } |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 1297 | /* check that all color buffers are the same format */ |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1298 | if (intFormat != GL_NONE && f != intFormat) { |
| 1299 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1300 | fbo_incomplete(ctx, "format mismatch", -1); |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1301 | return; |
| 1302 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1303 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1304 | } |
Marek Olšák | a82227c | 2012-06-15 17:21:05 +0200 | [diff] [blame] | 1305 | |
| 1306 | /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported) |
| 1307 | */ |
| 1308 | if (att->Type == GL_RENDERBUFFER && |
| 1309 | att->Renderbuffer->Format == MESA_FORMAT_NONE) { |
| 1310 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1311 | fbo_incomplete(ctx, "unsupported renderbuffer format", i); |
Marek Olšák | a82227c | 2012-06-15 17:21:05 +0200 | [diff] [blame] | 1312 | return; |
| 1313 | } |
Jordan Justen | 5da8288 | 2013-04-18 10:20:05 -0700 | [diff] [blame] | 1314 | |
| 1315 | /* Check that layered rendering is consistent. */ |
Paul Berry | 9514074 | 2013-11-19 15:55:51 -0800 | [diff] [blame] | 1316 | if (att->Layered) { |
| 1317 | if (att_tex_target == GL_TEXTURE_CUBE_MAP) |
| 1318 | att_layer_count = 6; |
Kenneth Graunke | 5c399ca | 2014-05-07 14:35:42 -0700 | [diff] [blame] | 1319 | else if (att_tex_target == GL_TEXTURE_1D_ARRAY) |
| 1320 | att_layer_count = att->Renderbuffer->Height; |
Paul Berry | 9514074 | 2013-11-19 15:55:51 -0800 | [diff] [blame] | 1321 | else |
| 1322 | att_layer_count = att->Renderbuffer->Depth; |
| 1323 | } else { |
| 1324 | att_layer_count = 0; |
| 1325 | } |
Paul Berry | 28af1dc | 2013-11-19 19:01:37 -0800 | [diff] [blame] | 1326 | if (!layer_info_valid) { |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1327 | is_layered = att->Layered; |
| 1328 | max_layer_count = att_layer_count; |
Paul Berry | 28af1dc | 2013-11-19 19:01:37 -0800 | [diff] [blame] | 1329 | layer_tex_target = att_tex_target; |
| 1330 | layer_info_valid = true; |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1331 | } else if (max_layer_count > 0 && layer_tex_target != att_tex_target) { |
Paul Berry | 28af1dc | 2013-11-19 19:01:37 -0800 | [diff] [blame] | 1332 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS; |
| 1333 | fbo_incomplete(ctx, "layered framebuffer has mismatched targets", i); |
| 1334 | return; |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1335 | } else if (is_layered != att->Layered) { |
| 1336 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS; |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1337 | fbo_incomplete(ctx, |
| 1338 | "framebuffer attachment layer mode is inconsistent", |
| 1339 | i); |
Jordan Justen | 5da8288 | 2013-04-18 10:20:05 -0700 | [diff] [blame] | 1340 | return; |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1341 | } else if (att_layer_count > max_layer_count) { |
| 1342 | max_layer_count = att_layer_count; |
Jordan Justen | 5da8288 | 2013-04-18 10:20:05 -0700 | [diff] [blame] | 1343 | } |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1344 | |
| 1345 | /* |
| 1346 | * The extension GL_ARB_framebuffer_no_attachments places additional |
| 1347 | * requirement on each attachment. Those additional requirements are |
| 1348 | * tighter that those of previous versions of GL. In interest of better |
| 1349 | * compatibility, we will not enforce these restrictions. For the record |
| 1350 | * those additional restrictions are quoted below: |
| 1351 | * |
| 1352 | * "The width and height of image are greater than zero and less than or |
| 1353 | * equal to the values of the implementation-dependent limits |
| 1354 | * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively." |
| 1355 | * |
| 1356 | * "If <image> is a three-dimensional texture or a one- or two-dimensional |
| 1357 | * array texture and the attachment is layered, the depth or layer count |
| 1358 | * of the texture is less than or equal to the implementation-dependent |
| 1359 | * limit MAX_FRAMEBUFFER_LAYERS." |
| 1360 | * |
| 1361 | * "If image has multiple samples, its sample count is less than or equal |
| 1362 | * to the value of the implementation-dependent limit |
| 1363 | * MAX_FRAMEBUFFER_SAMPLES." |
| 1364 | * |
| 1365 | * The same requirements are also in place for GL 4.5, |
| 1366 | * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311 |
| 1367 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
Marek Olšák | 459f05c | 2018-06-11 18:30:34 -0400 | [diff] [blame] | 1370 | if (ctx->Extensions.AMD_framebuffer_multisample_advanced) { |
| 1371 | /* See if non-matching sample counts are supported. */ |
| 1372 | if (numColorSamples >= 0 && numDepthSamples >= 0) { |
| 1373 | bool found = false; |
| 1374 | |
| 1375 | assert(numColorStorageSamples != -1); |
| 1376 | |
| 1377 | numColorSamples = MAX2(numColorSamples, 1); |
| 1378 | numColorStorageSamples = MAX2(numColorStorageSamples, 1); |
| 1379 | numDepthSamples = MAX2(numDepthSamples, 1); |
| 1380 | |
| 1381 | if (numColorSamples == 1 && numColorStorageSamples == 1 && |
| 1382 | numDepthSamples == 1) { |
| 1383 | found = true; |
| 1384 | } else { |
| 1385 | for (i = 0; i < ctx->Const.NumSupportedMultisampleModes; i++) { |
| 1386 | GLint *counts = |
| 1387 | &ctx->Const.SupportedMultisampleModes[i].NumColorSamples; |
| 1388 | |
| 1389 | if (counts[0] == numColorSamples && |
| 1390 | counts[1] == numColorStorageSamples && |
| 1391 | counts[2] == numDepthSamples) { |
| 1392 | found = true; |
| 1393 | break; |
| 1394 | } |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | if (!found) { |
| 1399 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| 1400 | fbo_incomplete(ctx, "unsupported sample counts", -1); |
| 1401 | return; |
| 1402 | } |
| 1403 | } |
| 1404 | } else { |
| 1405 | /* If the extension is unsupported, all sample counts must be equal. */ |
| 1406 | if (numColorSamples >= 0 && |
| 1407 | (numColorSamples != numColorStorageSamples || |
| 1408 | (numDepthSamples >= 0 && numColorSamples != numDepthSamples))) { |
| 1409 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| 1410 | fbo_incomplete(ctx, "inconsistent sample counts", -1); |
| 1411 | return; |
| 1412 | } |
| 1413 | } |
| 1414 | |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1415 | fb->MaxNumLayers = max_layer_count; |
Jordan Justen | 5da8288 | 2013-04-18 10:20:05 -0700 | [diff] [blame] | 1416 | |
Chris Forbes | a419a1c | 2014-03-23 22:41:28 +1300 | [diff] [blame] | 1417 | if (numImages == 0) { |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1418 | fb->_HasAttachments = false; |
| 1419 | |
| 1420 | if (!ctx->Extensions.ARB_framebuffer_no_attachments) { |
| 1421 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT; |
| 1422 | fbo_incomplete(ctx, "no attachments", -1); |
| 1423 | return; |
| 1424 | } |
| 1425 | |
| 1426 | if (fb->DefaultGeometry.Width == 0 || fb->DefaultGeometry.Height == 0) { |
| 1427 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT; |
| 1428 | fbo_incomplete(ctx, "no attachments and default width or height is 0", -1); |
| 1429 | return; |
| 1430 | } |
Chris Forbes | a419a1c | 2014-03-23 22:41:28 +1300 | [diff] [blame] | 1431 | } |
| 1432 | |
Jordan Justen | 09714c0 | 2012-07-19 11:27:16 -0700 | [diff] [blame] | 1433 | if (_mesa_is_desktop_gl(ctx) && !ctx->Extensions.ARB_ES2_compatibility) { |
Kristian Høgsberg | e88cef3 | 2010-05-24 16:56:12 -0400 | [diff] [blame] | 1434 | /* Check that all DrawBuffers are present */ |
| 1435 | for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1436 | if (fb->ColorDrawBuffer[j] != GL_NONE) { |
| 1437 | const struct gl_renderbuffer_attachment *att |
Alejandro Piñeiro | c6eb3ae | 2017-01-12 16:03:00 -0200 | [diff] [blame] | 1438 | = get_attachment(ctx, fb, fb->ColorDrawBuffer[j], NULL); |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1439 | assert(att); |
| 1440 | if (att->Type == GL_NONE) { |
| 1441 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT; |
| 1442 | fbo_incomplete(ctx, "missing drawbuffer", j); |
| 1443 | return; |
| 1444 | } |
| 1445 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1446 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1447 | |
Kristian Høgsberg | e88cef3 | 2010-05-24 16:56:12 -0400 | [diff] [blame] | 1448 | /* Check that the ReadBuffer is present */ |
| 1449 | if (fb->ColorReadBuffer != GL_NONE) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1450 | const struct gl_renderbuffer_attachment *att |
Alejandro Piñeiro | c6eb3ae | 2017-01-12 16:03:00 -0200 | [diff] [blame] | 1451 | = get_attachment(ctx, fb, fb->ColorReadBuffer, NULL); |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1452 | assert(att); |
| 1453 | if (att->Type == GL_NONE) { |
| 1454 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1455 | fbo_incomplete(ctx, "missing readbuffer", -1); |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1456 | return; |
| 1457 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
Iago Toral Quiroga | d42e090 | 2014-12-12 15:14:32 +0100 | [diff] [blame] | 1461 | /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says: |
| 1462 | * |
| 1463 | * "Depth and stencil attachments, if present, are the same image." |
| 1464 | * |
| 1465 | * This restriction is not present in the OpenGL ES2 spec. |
| 1466 | */ |
| 1467 | if (_mesa_is_gles3(ctx) && |
| 1468 | has_stencil_attachment && has_depth_attachment && |
| 1469 | !_mesa_has_depthstencil_combined(fb)) { |
| 1470 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
| 1471 | fbo_incomplete(ctx, "Depth and stencil attachments must be the same image", -1); |
| 1472 | return; |
| 1473 | } |
| 1474 | |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1475 | /* Provisionally set status = COMPLETE ... */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1476 | fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT; |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1477 | |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1478 | /* ... but the driver may say the FB is incomplete. |
| 1479 | * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED |
| 1480 | * if anything. |
| 1481 | */ |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1482 | if (ctx->Driver.ValidateFramebuffer) { |
| 1483 | ctx->Driver.ValidateFramebuffer(ctx, fb); |
Brian Paul | 1f32c41 | 2009-01-19 17:34:19 -0700 | [diff] [blame] | 1484 | if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1485 | fbo_incomplete(ctx, "driver marked FBO as incomplete", -1); |
Erik Faye-Lund | 395b53d | 2015-12-16 17:09:50 +0100 | [diff] [blame] | 1486 | return; |
Brian Paul | 1f32c41 | 2009-01-19 17:34:19 -0700 | [diff] [blame] | 1487 | } |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Erik Faye-Lund | 395b53d | 2015-12-16 17:09:50 +0100 | [diff] [blame] | 1490 | /* |
| 1491 | * Note that if ARB_framebuffer_object is supported and the attached |
| 1492 | * renderbuffers/textures are different sizes, the framebuffer |
| 1493 | * width/height will be set to the smallest width/height. |
| 1494 | */ |
| 1495 | if (numImages != 0) { |
| 1496 | fb->Width = minWidth; |
| 1497 | fb->Height = minHeight; |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1498 | } |
Erik Faye-Lund | 395b53d | 2015-12-16 17:09:50 +0100 | [diff] [blame] | 1499 | |
| 1500 | /* finally, update the visual info for the framebuffer */ |
| 1501 | _mesa_update_framebuffer_visual(ctx, fb); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1502 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1503 | |
| 1504 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1505 | GLboolean GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1506 | _mesa_IsRenderbuffer(GLuint renderbuffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1507 | { |
Samuel Pitoiset | 7839243 | 2017-04-06 18:05:36 +0200 | [diff] [blame] | 1508 | struct gl_renderbuffer *rb; |
| 1509 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1510 | GET_CURRENT_CONTEXT(ctx); |
Samuel Pitoiset | 7839243 | 2017-04-06 18:05:36 +0200 | [diff] [blame] | 1511 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1512 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
Samuel Pitoiset | 7839243 | 2017-04-06 18:05:36 +0200 | [diff] [blame] | 1513 | |
| 1514 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
| 1515 | return rb != NULL && rb != &DummyRenderbuffer; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1519 | static struct gl_renderbuffer * |
Matt Turner | 015f220 | 2015-07-30 14:31:04 -0700 | [diff] [blame] | 1520 | allocate_renderbuffer_locked(struct gl_context *ctx, GLuint renderbuffer, |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 1521 | bool isGenName, |
Matt Turner | 015f220 | 2015-07-30 14:31:04 -0700 | [diff] [blame] | 1522 | const char *func) |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1523 | { |
| 1524 | struct gl_renderbuffer *newRb; |
| 1525 | |
| 1526 | /* create new renderbuffer object */ |
| 1527 | newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer); |
| 1528 | if (!newRb) { |
| 1529 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); |
| 1530 | return NULL; |
| 1531 | } |
| 1532 | assert(newRb->AllocStorage); |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 1533 | _mesa_HashInsertLocked(ctx->Shared->RenderBuffers, renderbuffer, |
| 1534 | newRb, isGenName); |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1535 | |
| 1536 | return newRb; |
| 1537 | } |
| 1538 | |
| 1539 | |
Ian Romanick | 97965e8 | 2013-07-18 17:38:16 -0700 | [diff] [blame] | 1540 | static void |
Timothy Arceri | b54a231 | 2018-09-08 14:20:17 +1000 | [diff] [blame] | 1541 | bind_renderbuffer(GLenum target, GLuint renderbuffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1542 | { |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 1543 | struct gl_renderbuffer *newRb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1544 | GET_CURRENT_CONTEXT(ctx); |
| 1545 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1546 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | 4de18fb | 2009-11-02 15:30:51 -0700 | [diff] [blame] | 1547 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1548 | return; |
| 1549 | } |
| 1550 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1551 | /* No need to flush here since the render buffer binding has no |
| 1552 | * effect on rendering state. |
| 1553 | */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1554 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1555 | if (renderbuffer) { |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 1556 | bool isGenName = false; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1557 | newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1558 | if (newRb == &DummyRenderbuffer) { |
| 1559 | /* ID was reserved, but no real renderbuffer object made yet */ |
| 1560 | newRb = NULL; |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 1561 | isGenName = true; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1562 | } |
Timothy Arceri | b54a231 | 2018-09-08 14:20:17 +1000 | [diff] [blame] | 1563 | else if (!newRb && ctx->API == API_OPENGL_CORE) { |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 1564 | /* All RB IDs must be Gen'd */ |
Timothy Arceri | b54a231 | 2018-09-08 14:20:17 +1000 | [diff] [blame] | 1565 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1566 | "glBindRenderbuffer(non-gen name)"); |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 1567 | return; |
| 1568 | } |
| 1569 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1570 | if (!newRb) { |
Matt Turner | 015f220 | 2015-07-30 14:31:04 -0700 | [diff] [blame] | 1571 | _mesa_HashLockMutex(ctx->Shared->RenderBuffers); |
| 1572 | newRb = allocate_renderbuffer_locked(ctx, renderbuffer, |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 1573 | isGenName, "glBindRenderbufferEXT"); |
Matt Turner | 015f220 | 2015-07-30 14:31:04 -0700 | [diff] [blame] | 1574 | _mesa_HashUnlockMutex(ctx->Shared->RenderBuffers); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1575 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1576 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1577 | else { |
| 1578 | newRb = NULL; |
| 1579 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1580 | |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 1581 | assert(newRb != &DummyRenderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1582 | |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 1583 | _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
Ian Romanick | 97965e8 | 2013-07-18 17:38:16 -0700 | [diff] [blame] | 1586 | void GLAPIENTRY |
| 1587 | _mesa_BindRenderbuffer(GLenum target, GLuint renderbuffer) |
| 1588 | { |
Ian Romanick | 97965e8 | 2013-07-18 17:38:16 -0700 | [diff] [blame] | 1589 | /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same |
| 1590 | * entry point, but they allow the use of user-generated names. |
| 1591 | */ |
Timothy Arceri | b54a231 | 2018-09-08 14:20:17 +1000 | [diff] [blame] | 1592 | bind_renderbuffer(target, renderbuffer); |
Ian Romanick | 97965e8 | 2013-07-18 17:38:16 -0700 | [diff] [blame] | 1593 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1594 | |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 1595 | void GLAPIENTRY |
| 1596 | _mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer) |
| 1597 | { |
Timothy Arceri | b54a231 | 2018-09-08 14:20:17 +1000 | [diff] [blame] | 1598 | bind_renderbuffer(target, renderbuffer); |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 1599 | } |
| 1600 | |
Edward O'Callaghan | b40375a | 2016-02-17 19:15:49 +1100 | [diff] [blame] | 1601 | /** |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 1602 | * ARB_framebuffer_no_attachment and ARB_sample_locations - Application passes |
| 1603 | * requested param's here. NOTE: NumSamples requested need not be _NumSamples |
| 1604 | * which is what the hw supports. |
Edward O'Callaghan | b40375a | 2016-02-17 19:15:49 +1100 | [diff] [blame] | 1605 | */ |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1606 | static void |
| 1607 | framebuffer_parameteri(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 1608 | GLenum pname, GLint param, const char *func) |
| 1609 | { |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 1610 | bool cannot_be_winsys_fbo = false; |
| 1611 | |
| 1612 | switch (pname) { |
| 1613 | case GL_FRAMEBUFFER_DEFAULT_WIDTH: |
| 1614 | case GL_FRAMEBUFFER_DEFAULT_HEIGHT: |
| 1615 | case GL_FRAMEBUFFER_DEFAULT_LAYERS: |
| 1616 | case GL_FRAMEBUFFER_DEFAULT_SAMPLES: |
| 1617 | case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 1618 | if (!ctx->Extensions.ARB_framebuffer_no_attachments) |
| 1619 | goto invalid_pname_enum; |
| 1620 | cannot_be_winsys_fbo = true; |
| 1621 | break; |
| 1622 | case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB: |
| 1623 | case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB: |
| 1624 | if (!ctx->Extensions.ARB_sample_locations) |
| 1625 | goto invalid_pname_enum; |
| 1626 | break; |
Fritz Koenig | 318c265 | 2018-07-23 10:10:54 -0700 | [diff] [blame] | 1627 | case GL_FRAMEBUFFER_FLIP_Y_MESA: |
| 1628 | if (!ctx->Extensions.MESA_framebuffer_flip_y) |
| 1629 | goto invalid_pname_enum; |
| 1630 | cannot_be_winsys_fbo = true; |
Fritz Koenig | 60d0c0d | 2018-09-14 11:40:49 -0700 | [diff] [blame] | 1631 | break; |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 1632 | default: |
| 1633 | goto invalid_pname_enum; |
| 1634 | } |
| 1635 | |
| 1636 | if (cannot_be_winsys_fbo && _mesa_is_winsys_fbo(fb)) { |
| 1637 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1638 | "%s(invalid pname=0x%x for default framebuffer)", func, pname); |
| 1639 | return; |
| 1640 | } |
| 1641 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1642 | switch (pname) { |
| 1643 | case GL_FRAMEBUFFER_DEFAULT_WIDTH: |
| 1644 | if (param < 0 || param > ctx->Const.MaxFramebufferWidth) |
| 1645 | _mesa_error(ctx, GL_INVALID_VALUE, "%s", func); |
| 1646 | else |
| 1647 | fb->DefaultGeometry.Width = param; |
| 1648 | break; |
| 1649 | case GL_FRAMEBUFFER_DEFAULT_HEIGHT: |
| 1650 | if (param < 0 || param > ctx->Const.MaxFramebufferHeight) |
| 1651 | _mesa_error(ctx, GL_INVALID_VALUE, "%s", func); |
| 1652 | else |
| 1653 | fb->DefaultGeometry.Height = param; |
| 1654 | break; |
| 1655 | case GL_FRAMEBUFFER_DEFAULT_LAYERS: |
Marta Lofstedt | f8a9388 | 2015-08-24 13:01:53 +0200 | [diff] [blame] | 1656 | /* |
| 1657 | * According to the OpenGL ES 3.1 specification section 9.2.1, the |
| 1658 | * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported. |
| 1659 | */ |
Ilia Mirkin | 82d756f | 2016-05-21 20:26:47 -0400 | [diff] [blame] | 1660 | if (_mesa_is_gles31(ctx) && !ctx->Extensions.OES_geometry_shader) { |
Marta Lofstedt | f8a9388 | 2015-08-24 13:01:53 +0200 | [diff] [blame] | 1661 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname); |
| 1662 | break; |
| 1663 | } |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1664 | if (param < 0 || param > ctx->Const.MaxFramebufferLayers) |
Marta Lofstedt | f8a9388 | 2015-08-24 13:01:53 +0200 | [diff] [blame] | 1665 | _mesa_error(ctx, GL_INVALID_VALUE, "%s", func); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1666 | else |
| 1667 | fb->DefaultGeometry.Layers = param; |
| 1668 | break; |
| 1669 | case GL_FRAMEBUFFER_DEFAULT_SAMPLES: |
| 1670 | if (param < 0 || param > ctx->Const.MaxFramebufferSamples) |
| 1671 | _mesa_error(ctx, GL_INVALID_VALUE, "%s", func); |
| 1672 | else |
| 1673 | fb->DefaultGeometry.NumSamples = param; |
| 1674 | break; |
| 1675 | case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 1676 | fb->DefaultGeometry.FixedSampleLocations = param; |
| 1677 | break; |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 1678 | case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB: |
| 1679 | fb->ProgrammableSampleLocations = !!param; |
| 1680 | break; |
| 1681 | case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB: |
| 1682 | fb->SampleLocationPixelGrid = !!param; |
| 1683 | break; |
Fritz Koenig | 318c265 | 2018-07-23 10:10:54 -0700 | [diff] [blame] | 1684 | case GL_FRAMEBUFFER_FLIP_Y_MESA: |
| 1685 | fb->FlipY = param; |
| 1686 | break; |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1687 | } |
Ilia Mirkin | 095da3b | 2016-01-23 09:27:22 -0500 | [diff] [blame] | 1688 | |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 1689 | switch (pname) { |
| 1690 | case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB: |
| 1691 | case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB: |
| 1692 | if (fb == ctx->DrawBuffer) |
| 1693 | ctx->NewDriverState |= ctx->DriverFlags.NewSampleLocations; |
| 1694 | break; |
| 1695 | default: |
| 1696 | invalidate_framebuffer(fb); |
| 1697 | ctx->NewState |= _NEW_BUFFERS; |
| 1698 | break; |
| 1699 | } |
| 1700 | |
| 1701 | return; |
| 1702 | |
| 1703 | invalid_pname_enum: |
| 1704 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1705 | } |
| 1706 | |
Fritz Koenig | 66937ab | 2019-07-30 14:53:30 -0700 | [diff] [blame] | 1707 | static bool |
| 1708 | validate_framebuffer_parameter_extensions(GLenum pname, const char *func) |
| 1709 | { |
| 1710 | GET_CURRENT_CONTEXT(ctx); |
| 1711 | |
| 1712 | if (!ctx->Extensions.ARB_framebuffer_no_attachments && |
| 1713 | !ctx->Extensions.ARB_sample_locations && |
| 1714 | !ctx->Extensions.MESA_framebuffer_flip_y) { |
| 1715 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1716 | "%s not supported " |
| 1717 | "(none of ARB_framebuffer_no_attachments," |
| 1718 | " ARB_sample_locations, or" |
| 1719 | " MESA_framebuffer_flip_y extensions are available)", |
| 1720 | func); |
| 1721 | return false; |
| 1722 | } |
| 1723 | |
| 1724 | /* |
| 1725 | * If only the MESA_framebuffer_flip_y extension is enabled |
| 1726 | * pname can only be GL_FRAMEBUFFER_FLIP_Y_MESA |
| 1727 | */ |
| 1728 | if (ctx->Extensions.MESA_framebuffer_flip_y && |
| 1729 | pname != GL_FRAMEBUFFER_FLIP_Y_MESA && |
| 1730 | !(ctx->Extensions.ARB_framebuffer_no_attachments || |
| 1731 | ctx->Extensions.ARB_sample_locations)) { |
| 1732 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname); |
| 1733 | return false; |
| 1734 | } |
| 1735 | |
| 1736 | return true; |
| 1737 | } |
| 1738 | |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1739 | void GLAPIENTRY |
| 1740 | _mesa_FramebufferParameteri(GLenum target, GLenum pname, GLint param) |
| 1741 | { |
| 1742 | GET_CURRENT_CONTEXT(ctx); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1743 | struct gl_framebuffer *fb; |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1744 | |
Fritz Koenig | 66937ab | 2019-07-30 14:53:30 -0700 | [diff] [blame] | 1745 | if (!validate_framebuffer_parameter_extensions(pname, |
| 1746 | "glFramebufferParameteri")) { |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1747 | return; |
| 1748 | } |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1749 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1750 | fb = get_framebuffer_target(ctx, target); |
| 1751 | if (!fb) { |
| 1752 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1753 | "glFramebufferParameteri(target=0x%x)", target); |
| 1754 | return; |
| 1755 | } |
| 1756 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1757 | framebuffer_parameteri(ctx, fb, pname, param, "glFramebufferParameteri"); |
| 1758 | } |
| 1759 | |
Fritz Koenig | 66937ab | 2019-07-30 14:53:30 -0700 | [diff] [blame] | 1760 | void GLAPIENTRY |
| 1761 | _mesa_FramebufferParameteriMESA(GLenum target, GLenum pname, GLint param) |
| 1762 | { |
| 1763 | _mesa_FramebufferParameteri(target, pname, param); |
| 1764 | } |
| 1765 | |
Alejandro Piñeiro | dfb1b54 | 2017-01-13 15:53:13 -0200 | [diff] [blame] | 1766 | static bool |
Rhys Perry | 5ac16ed | 2018-05-04 23:27:51 +0100 | [diff] [blame] | 1767 | validate_get_framebuffer_parameteriv_pname(struct gl_context *ctx, |
| 1768 | struct gl_framebuffer *fb, |
| 1769 | GLuint pname, const char *func) |
Alejandro Piñeiro | dfb1b54 | 2017-01-13 15:53:13 -0200 | [diff] [blame] | 1770 | { |
Rhys Perry | 5ac16ed | 2018-05-04 23:27:51 +0100 | [diff] [blame] | 1771 | bool cannot_be_winsys_fbo = true; |
Alejandro Piñeiro | dfb1b54 | 2017-01-13 15:53:13 -0200 | [diff] [blame] | 1772 | |
| 1773 | switch (pname) { |
Rhys Perry | 5ac16ed | 2018-05-04 23:27:51 +0100 | [diff] [blame] | 1774 | case GL_FRAMEBUFFER_DEFAULT_LAYERS: |
| 1775 | /* |
| 1776 | * According to the OpenGL ES 3.1 specification section 9.2.3, the |
| 1777 | * GL_FRAMEBUFFER_LAYERS parameter name is not supported. |
| 1778 | */ |
| 1779 | if (_mesa_is_gles31(ctx) && !ctx->Extensions.OES_geometry_shader) { |
| 1780 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname); |
| 1781 | return false; |
| 1782 | } |
| 1783 | break; |
| 1784 | case GL_FRAMEBUFFER_DEFAULT_WIDTH: |
| 1785 | case GL_FRAMEBUFFER_DEFAULT_HEIGHT: |
| 1786 | case GL_FRAMEBUFFER_DEFAULT_SAMPLES: |
| 1787 | case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 1788 | break; |
Alejandro Piñeiro | dfb1b54 | 2017-01-13 15:53:13 -0200 | [diff] [blame] | 1789 | case GL_DOUBLEBUFFER: |
| 1790 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1791 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1792 | case GL_SAMPLES: |
| 1793 | case GL_SAMPLE_BUFFERS: |
| 1794 | case GL_STEREO: |
Rhys Perry | 5ac16ed | 2018-05-04 23:27:51 +0100 | [diff] [blame] | 1795 | /* From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries: |
| 1796 | * |
| 1797 | * "An INVALID_OPERATION error is generated by GetFramebufferParameteriv |
| 1798 | * if the default framebuffer is bound to target and pname is not one |
| 1799 | * of the accepted values from table 23.73, other than |
| 1800 | * SAMPLE_POSITION." |
| 1801 | * |
| 1802 | * For OpenGL ES, using default framebuffer raises INVALID_OPERATION |
| 1803 | * for any pname. |
| 1804 | */ |
| 1805 | cannot_be_winsys_fbo = !_mesa_is_desktop_gl(ctx); |
| 1806 | break; |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 1807 | case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB: |
| 1808 | case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB: |
| 1809 | if (!ctx->Extensions.ARB_sample_locations) |
| 1810 | goto invalid_pname_enum; |
| 1811 | cannot_be_winsys_fbo = false; |
| 1812 | break; |
Fritz Koenig | 318c265 | 2018-07-23 10:10:54 -0700 | [diff] [blame] | 1813 | case GL_FRAMEBUFFER_FLIP_Y_MESA: |
| 1814 | if (!ctx->Extensions.MESA_framebuffer_flip_y) { |
| 1815 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname); |
| 1816 | return false; |
| 1817 | } |
| 1818 | break; |
Alejandro Piñeiro | dfb1b54 | 2017-01-13 15:53:13 -0200 | [diff] [blame] | 1819 | default: |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 1820 | goto invalid_pname_enum; |
Alejandro Piñeiro | dfb1b54 | 2017-01-13 15:53:13 -0200 | [diff] [blame] | 1821 | } |
Rhys Perry | 5ac16ed | 2018-05-04 23:27:51 +0100 | [diff] [blame] | 1822 | |
| 1823 | if (cannot_be_winsys_fbo && _mesa_is_winsys_fbo(fb)) { |
| 1824 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1825 | "%s(invalid pname=0x%x for default framebuffer)", func, pname); |
| 1826 | return false; |
| 1827 | } |
| 1828 | |
| 1829 | return true; |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 1830 | |
| 1831 | invalid_pname_enum: |
| 1832 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname); |
| 1833 | return false; |
Alejandro Piñeiro | dfb1b54 | 2017-01-13 15:53:13 -0200 | [diff] [blame] | 1834 | } |
| 1835 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1836 | static void |
| 1837 | get_framebuffer_parameteriv(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 1838 | GLenum pname, GLint *params, const char *func) |
| 1839 | { |
Rhys Perry | 5ac16ed | 2018-05-04 23:27:51 +0100 | [diff] [blame] | 1840 | if (!validate_get_framebuffer_parameteriv_pname(ctx, fb, pname, func)) |
Alejandro Piñeiro | dfb1b54 | 2017-01-13 15:53:13 -0200 | [diff] [blame] | 1841 | return; |
Alejandro Piñeiro | dfb1b54 | 2017-01-13 15:53:13 -0200 | [diff] [blame] | 1842 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1843 | switch (pname) { |
| 1844 | case GL_FRAMEBUFFER_DEFAULT_WIDTH: |
| 1845 | *params = fb->DefaultGeometry.Width; |
| 1846 | break; |
| 1847 | case GL_FRAMEBUFFER_DEFAULT_HEIGHT: |
| 1848 | *params = fb->DefaultGeometry.Height; |
| 1849 | break; |
| 1850 | case GL_FRAMEBUFFER_DEFAULT_LAYERS: |
| 1851 | *params = fb->DefaultGeometry.Layers; |
| 1852 | break; |
| 1853 | case GL_FRAMEBUFFER_DEFAULT_SAMPLES: |
| 1854 | *params = fb->DefaultGeometry.NumSamples; |
| 1855 | break; |
| 1856 | case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 1857 | *params = fb->DefaultGeometry.FixedSampleLocations; |
| 1858 | break; |
Alejandro Piñeiro | 0fb0c57 | 2017-01-13 16:23:05 -0200 | [diff] [blame] | 1859 | case GL_DOUBLEBUFFER: |
| 1860 | *params = fb->Visual.doubleBufferMode; |
| 1861 | break; |
| 1862 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1863 | *params = _mesa_get_color_read_format(ctx, fb, func); |
| 1864 | break; |
| 1865 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1866 | *params = _mesa_get_color_read_type(ctx, fb, func); |
| 1867 | break; |
| 1868 | case GL_SAMPLES: |
| 1869 | *params = _mesa_geometric_samples(fb); |
| 1870 | break; |
| 1871 | case GL_SAMPLE_BUFFERS: |
| 1872 | *params = _mesa_geometric_samples(fb) > 0; |
| 1873 | break; |
| 1874 | case GL_STEREO: |
| 1875 | *params = fb->Visual.stereoMode; |
| 1876 | break; |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 1877 | case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB: |
| 1878 | *params = fb->ProgrammableSampleLocations; |
| 1879 | break; |
| 1880 | case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB: |
| 1881 | *params = fb->SampleLocationPixelGrid; |
| 1882 | break; |
Fritz Koenig | 318c265 | 2018-07-23 10:10:54 -0700 | [diff] [blame] | 1883 | case GL_FRAMEBUFFER_FLIP_Y_MESA: |
| 1884 | *params = fb->FlipY; |
| 1885 | break; |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1886 | } |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | void GLAPIENTRY |
| 1890 | _mesa_GetFramebufferParameteriv(GLenum target, GLenum pname, GLint *params) |
| 1891 | { |
| 1892 | GET_CURRENT_CONTEXT(ctx); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1893 | struct gl_framebuffer *fb; |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1894 | |
Fritz Koenig | 66937ab | 2019-07-30 14:53:30 -0700 | [diff] [blame] | 1895 | if (!validate_framebuffer_parameter_extensions(pname, |
| 1896 | "glGetFramebufferParameteriv")) { |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1897 | return; |
| 1898 | } |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1899 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1900 | fb = get_framebuffer_target(ctx, target); |
| 1901 | if (!fb) { |
| 1902 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1903 | "glGetFramebufferParameteriv(target=0x%x)", target); |
| 1904 | return; |
| 1905 | } |
| 1906 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1907 | get_framebuffer_parameteriv(ctx, fb, pname, params, |
| 1908 | "glGetFramebufferParameteriv"); |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1909 | } |
| 1910 | |
Fritz Koenig | 66937ab | 2019-07-30 14:53:30 -0700 | [diff] [blame] | 1911 | void GLAPIENTRY |
| 1912 | _mesa_GetFramebufferParameterivMESA(GLenum target, GLenum pname, GLint *params) |
| 1913 | { |
| 1914 | _mesa_GetFramebufferParameteriv(target, pname, params); |
| 1915 | } |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 1916 | |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1917 | /** |
Ian Romanick | ef83bd2 | 2013-08-08 15:41:36 -0700 | [diff] [blame] | 1918 | * Remove the specified renderbuffer or texture from any attachment point in |
| 1919 | * the framebuffer. |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1920 | * |
| 1921 | * \returns |
| 1922 | * \c true if the renderbuffer was detached from an attachment point. \c |
| 1923 | * false otherwise. |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1924 | */ |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1925 | bool |
| 1926 | _mesa_detach_renderbuffer(struct gl_context *ctx, |
| 1927 | struct gl_framebuffer *fb, |
| 1928 | const void *att) |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1929 | { |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1930 | unsigned i; |
| 1931 | bool progress = false; |
| 1932 | |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1933 | for (i = 0; i < BUFFER_COUNT; i++) { |
Ian Romanick | ef83bd2 | 2013-08-08 15:41:36 -0700 | [diff] [blame] | 1934 | if (fb->Attachment[i].Texture == att |
| 1935 | || fb->Attachment[i].Renderbuffer == att) { |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 1936 | remove_attachment(ctx, &fb->Attachment[i]); |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1937 | progress = true; |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1938 | } |
| 1939 | } |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1940 | |
| 1941 | /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer |
| 1942 | * Completeness," of the OpenGL 3.1 spec says: |
| 1943 | * |
| 1944 | * "Performing any of the following actions may change whether the |
| 1945 | * framebuffer is considered complete or incomplete: |
| 1946 | * |
| 1947 | * ... |
| 1948 | * |
| 1949 | * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object |
| 1950 | * containing an image that is attached to a framebuffer object |
| 1951 | * that is bound to the framebuffer." |
| 1952 | */ |
| 1953 | if (progress) |
| 1954 | invalidate_framebuffer(fb); |
| 1955 | |
| 1956 | return progress; |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1960 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1961 | _mesa_DeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1962 | { |
| 1963 | GLint i; |
| 1964 | GET_CURRENT_CONTEXT(ctx); |
| 1965 | |
Eduardo Lima Mitev | 2012f62 | 2014-12-11 23:34:18 +0100 | [diff] [blame] | 1966 | if (n < 0) { |
| 1967 | _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteRenderbuffers(n < 0)"); |
| 1968 | return; |
| 1969 | } |
| 1970 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1971 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1972 | |
| 1973 | for (i = 0; i < n; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1974 | if (renderbuffers[i] > 0) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1975 | struct gl_renderbuffer *rb; |
| 1976 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]); |
| 1977 | if (rb) { |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1978 | /* check if deleting currently bound renderbuffer object */ |
| 1979 | if (rb == ctx->CurrentRenderbuffer) { |
| 1980 | /* bind default */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 1981 | assert(rb->RefCount >= 2); |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1982 | _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT, 0); |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
Ian Romanick | ef83bd2 | 2013-08-08 15:41:36 -0700 | [diff] [blame] | 1985 | /* Section 4.4.2 (Attaching Images to Framebuffer Objects), |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1986 | * subsection "Attaching Renderbuffer Images to a Framebuffer," |
| 1987 | * of the OpenGL 3.1 spec says: |
Ian Romanick | ef83bd2 | 2013-08-08 15:41:36 -0700 | [diff] [blame] | 1988 | * |
| 1989 | * "If a renderbuffer object is deleted while its image is |
| 1990 | * attached to one or more attachment points in the currently |
| 1991 | * bound framebuffer, then it is as if FramebufferRenderbuffer |
| 1992 | * had been called, with a renderbuffer of 0, for each |
| 1993 | * attachment point to which this image was attached in the |
| 1994 | * currently bound framebuffer. In other words, this |
| 1995 | * renderbuffer image is first detached from all attachment |
| 1996 | * points in the currently bound framebuffer. Note that the |
| 1997 | * renderbuffer image is specifically not detached from any |
| 1998 | * non-bound framebuffers. Detaching the image from any |
| 1999 | * non-bound framebuffers is the responsibility of the |
| 2000 | * application. |
| 2001 | */ |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 2002 | if (_mesa_is_user_fbo(ctx->DrawBuffer)) { |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 2003 | _mesa_detach_renderbuffer(ctx, ctx->DrawBuffer, rb); |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 2004 | } |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 2005 | if (_mesa_is_user_fbo(ctx->ReadBuffer) |
Brian Paul | fc8c4a3 | 2011-06-16 07:31:58 -0600 | [diff] [blame] | 2006 | && ctx->ReadBuffer != ctx->DrawBuffer) { |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 2007 | _mesa_detach_renderbuffer(ctx, ctx->ReadBuffer, rb); |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 2010 | /* Remove from hash table immediately, to free the ID. |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 2011 | * But the object will not be freed until it's no longer |
| 2012 | * referenced anywhere else. |
| 2013 | */ |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 2014 | _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2015 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2016 | if (rb != &DummyRenderbuffer) { |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 2017 | /* no longer referenced by hash table */ |
| 2018 | _mesa_reference_renderbuffer(&rb, NULL); |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 2019 | } |
| 2020 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | } |
| 2024 | |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 2025 | static void |
| 2026 | create_render_buffers(struct gl_context *ctx, GLsizei n, GLuint *renderbuffers, |
| 2027 | bool dsa) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2028 | { |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 2029 | const char *func = dsa ? "glCreateRenderbuffers" : "glGenRenderbuffers"; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2030 | GLint i; |
| 2031 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2032 | if (!renderbuffers) |
| 2033 | return; |
| 2034 | |
Matt Turner | 015f220 | 2015-07-30 14:31:04 -0700 | [diff] [blame] | 2035 | _mesa_HashLockMutex(ctx->Shared->RenderBuffers); |
| 2036 | |
Pierre-Eric Pelloux-Prayer | a56849d | 2020-08-17 15:12:03 +0200 | [diff] [blame] | 2037 | _mesa_HashFindFreeKeys(ctx->Shared->RenderBuffers, renderbuffers, n); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2038 | |
| 2039 | for (i = 0; i < n; i++) { |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 2040 | if (dsa) { |
Pierre-Eric Pelloux-Prayer | a56849d | 2020-08-17 15:12:03 +0200 | [diff] [blame] | 2041 | allocate_renderbuffer_locked(ctx, renderbuffers[i], true, func); |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 2042 | } else { |
Martin Peres | fa38321 | 2015-03-25 16:28:03 +0200 | [diff] [blame] | 2043 | /* insert a dummy renderbuffer into the hash table */ |
Pierre-Eric Pelloux-Prayer | a56849d | 2020-08-17 15:12:03 +0200 | [diff] [blame] | 2044 | _mesa_HashInsertLocked(ctx->Shared->RenderBuffers, renderbuffers[i], |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 2045 | &DummyRenderbuffer, true); |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 2046 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2047 | } |
Matt Turner | 015f220 | 2015-07-30 14:31:04 -0700 | [diff] [blame] | 2048 | |
| 2049 | _mesa_HashUnlockMutex(ctx->Shared->RenderBuffers); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | |
Samuel Pitoiset | beb74c9 | 2017-06-26 18:25:10 +0200 | [diff] [blame] | 2053 | static void |
| 2054 | create_render_buffers_err(struct gl_context *ctx, GLsizei n, |
| 2055 | GLuint *renderbuffers, bool dsa) |
| 2056 | { |
| 2057 | const char *func = dsa ? "glCreateRenderbuffers" : "glGenRenderbuffers"; |
| 2058 | |
| 2059 | if (n < 0) { |
| 2060 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(n<0)", func); |
| 2061 | return; |
| 2062 | } |
| 2063 | |
| 2064 | create_render_buffers(ctx, n, renderbuffers, dsa); |
| 2065 | } |
| 2066 | |
| 2067 | |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 2068 | void GLAPIENTRY |
Samuel Pitoiset | b87a2cb | 2017-06-26 18:27:49 +0200 | [diff] [blame] | 2069 | _mesa_GenRenderbuffers_no_error(GLsizei n, GLuint *renderbuffers) |
| 2070 | { |
| 2071 | GET_CURRENT_CONTEXT(ctx); |
| 2072 | create_render_buffers(ctx, n, renderbuffers, false); |
| 2073 | } |
| 2074 | |
| 2075 | |
| 2076 | void GLAPIENTRY |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 2077 | _mesa_GenRenderbuffers(GLsizei n, GLuint *renderbuffers) |
| 2078 | { |
| 2079 | GET_CURRENT_CONTEXT(ctx); |
Samuel Pitoiset | beb74c9 | 2017-06-26 18:25:10 +0200 | [diff] [blame] | 2080 | create_render_buffers_err(ctx, n, renderbuffers, false); |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | |
| 2084 | void GLAPIENTRY |
Samuel Pitoiset | b87a2cb | 2017-06-26 18:27:49 +0200 | [diff] [blame] | 2085 | _mesa_CreateRenderbuffers_no_error(GLsizei n, GLuint *renderbuffers) |
| 2086 | { |
| 2087 | GET_CURRENT_CONTEXT(ctx); |
| 2088 | create_render_buffers(ctx, n, renderbuffers, true); |
| 2089 | } |
| 2090 | |
| 2091 | |
| 2092 | void GLAPIENTRY |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 2093 | _mesa_CreateRenderbuffers(GLsizei n, GLuint *renderbuffers) |
| 2094 | { |
| 2095 | GET_CURRENT_CONTEXT(ctx); |
Samuel Pitoiset | beb74c9 | 2017-06-26 18:25:10 +0200 | [diff] [blame] | 2096 | create_render_buffers_err(ctx, n, renderbuffers, true); |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 2100 | /** |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2101 | * Given an internal format token for a render buffer, return the |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2102 | * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, |
| 2103 | * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE, |
| 2104 | * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc). |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2105 | * |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2106 | * This is similar to _mesa_base_tex_format() but the set of valid |
| 2107 | * internal formats is different. |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2108 | * |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2109 | * Note that even if a format is determined to be legal here, validation |
Brian Paul | b3cfcdf | 2011-01-28 20:25:26 -0700 | [diff] [blame] | 2110 | * of the FBO may fail if the format is not supported by the driver/GPU. |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2111 | * |
| 2112 | * \param internalFormat as passed to glRenderbufferStorage() |
| 2113 | * \return the base internal format, or 0 if internalFormat is illegal |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 2114 | */ |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 2115 | GLenum |
Brian Paul | ca78b6b | 2017-12-05 12:05:18 -0700 | [diff] [blame] | 2116 | _mesa_base_fbo_format(const struct gl_context *ctx, GLenum internalFormat) |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2117 | { |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2118 | /* |
| 2119 | * Notes: some formats such as alpha, luminance, etc. were added |
| 2120 | * with GL_ARB_framebuffer_object. |
| 2121 | */ |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2122 | switch (internalFormat) { |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2123 | case GL_ALPHA: |
| 2124 | case GL_ALPHA4: |
| 2125 | case GL_ALPHA8: |
| 2126 | case GL_ALPHA12: |
| 2127 | case GL_ALPHA16: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 2128 | return (ctx->API == API_OPENGL_COMPAT && |
| 2129 | ctx->Extensions.ARB_framebuffer_object) ? GL_ALPHA : 0; |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2130 | case GL_LUMINANCE: |
| 2131 | case GL_LUMINANCE4: |
| 2132 | case GL_LUMINANCE8: |
| 2133 | case GL_LUMINANCE12: |
| 2134 | case GL_LUMINANCE16: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 2135 | return (ctx->API == API_OPENGL_COMPAT && |
| 2136 | ctx->Extensions.ARB_framebuffer_object) ? GL_LUMINANCE : 0; |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2137 | case GL_LUMINANCE_ALPHA: |
| 2138 | case GL_LUMINANCE4_ALPHA4: |
| 2139 | case GL_LUMINANCE6_ALPHA2: |
| 2140 | case GL_LUMINANCE8_ALPHA8: |
| 2141 | case GL_LUMINANCE12_ALPHA4: |
| 2142 | case GL_LUMINANCE12_ALPHA12: |
| 2143 | case GL_LUMINANCE16_ALPHA16: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 2144 | return (ctx->API == API_OPENGL_COMPAT && |
| 2145 | ctx->Extensions.ARB_framebuffer_object) ? GL_LUMINANCE_ALPHA : 0; |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2146 | case GL_INTENSITY: |
| 2147 | case GL_INTENSITY4: |
| 2148 | case GL_INTENSITY8: |
| 2149 | case GL_INTENSITY12: |
| 2150 | case GL_INTENSITY16: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 2151 | return (ctx->API == API_OPENGL_COMPAT && |
| 2152 | ctx->Extensions.ARB_framebuffer_object) ? GL_INTENSITY : 0; |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2153 | case GL_RGB8: |
| 2154 | return GL_RGB; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2155 | case GL_RGB: |
| 2156 | case GL_R3_G3_B2: |
| 2157 | case GL_RGB4: |
| 2158 | case GL_RGB5: |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2159 | case GL_RGB10: |
| 2160 | case GL_RGB12: |
| 2161 | case GL_RGB16: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2162 | return _mesa_is_desktop_gl(ctx) ? GL_RGB : 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2163 | case GL_SRGB8_EXT: |
Matt Turner | cbef537 | 2012-11-20 13:45:03 -0800 | [diff] [blame] | 2164 | return _mesa_is_desktop_gl(ctx) ? GL_RGB : 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2165 | case GL_RGBA4: |
| 2166 | case GL_RGB5_A1: |
| 2167 | case GL_RGBA8: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2168 | return GL_RGBA; |
| 2169 | case GL_RGBA: |
| 2170 | case GL_RGBA2: |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2171 | case GL_RGBA12: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2172 | return _mesa_is_desktop_gl(ctx) ? GL_RGBA : 0; |
Tapani Pälli | ce80abb | 2018-07-24 08:58:20 +0300 | [diff] [blame] | 2173 | case GL_RGBA16: |
| 2174 | return _mesa_is_desktop_gl(ctx) || _mesa_has_EXT_texture_norm16(ctx) |
| 2175 | ? GL_RGBA : 0; |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2176 | case GL_RGB10_A2: |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2177 | case GL_SRGB8_ALPHA8_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2178 | return _mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx) ? GL_RGBA : 0; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 2179 | case GL_STENCIL_INDEX: |
| 2180 | case GL_STENCIL_INDEX1_EXT: |
| 2181 | case GL_STENCIL_INDEX4_EXT: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 2182 | case GL_STENCIL_INDEX16_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2183 | /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in |
| 2184 | * OpenGL ES, but Mesa does not currently support them. |
| 2185 | */ |
| 2186 | return _mesa_is_desktop_gl(ctx) ? GL_STENCIL_INDEX : 0; |
| 2187 | case GL_STENCIL_INDEX8_EXT: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 2188 | return GL_STENCIL_INDEX; |
| 2189 | case GL_DEPTH_COMPONENT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2190 | case GL_DEPTH_COMPONENT32: |
| 2191 | return _mesa_is_desktop_gl(ctx) ? GL_DEPTH_COMPONENT : 0; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 2192 | case GL_DEPTH_COMPONENT16: |
| 2193 | case GL_DEPTH_COMPONENT24: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 2194 | return GL_DEPTH_COMPONENT; |
Ian Romanick | 4949322 | 2013-11-13 14:15:11 -0800 | [diff] [blame] | 2195 | case GL_DEPTH_STENCIL: |
| 2196 | return _mesa_is_desktop_gl(ctx) ? GL_DEPTH_STENCIL : 0; |
| 2197 | case GL_DEPTH24_STENCIL8: |
| 2198 | return GL_DEPTH_STENCIL; |
Marek Olšák | 1165280 | 2011-06-01 15:48:51 +0200 | [diff] [blame] | 2199 | case GL_DEPTH_COMPONENT32F: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2200 | return ctx->Version >= 30 |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 2201 | || (ctx->API == API_OPENGL_COMPAT && |
| 2202 | ctx->Extensions.ARB_depth_buffer_float) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2203 | ? GL_DEPTH_COMPONENT : 0; |
Marek Olšák | 1165280 | 2011-06-01 15:48:51 +0200 | [diff] [blame] | 2204 | case GL_DEPTH32F_STENCIL8: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2205 | return ctx->Version >= 30 |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 2206 | || (ctx->API == API_OPENGL_COMPAT && |
| 2207 | ctx->Extensions.ARB_depth_buffer_float) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2208 | ? GL_DEPTH_STENCIL : 0; |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2209 | case GL_RED: |
Tapani Pälli | ce80abb | 2018-07-24 08:58:20 +0300 | [diff] [blame] | 2210 | return _mesa_has_ARB_texture_rg(ctx) ? GL_RED : 0; |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2211 | case GL_R16: |
Tapani Pälli | ce80abb | 2018-07-24 08:58:20 +0300 | [diff] [blame] | 2212 | return _mesa_has_ARB_texture_rg(ctx) || _mesa_has_EXT_texture_norm16(ctx) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2213 | ? GL_RED : 0; |
| 2214 | case GL_R8: |
| 2215 | return ctx->API != API_OPENGLES && ctx->Extensions.ARB_texture_rg |
| 2216 | ? GL_RED : 0; |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2217 | case GL_RG: |
Tapani Pälli | ce80abb | 2018-07-24 08:58:20 +0300 | [diff] [blame] | 2218 | return _mesa_has_ARB_texture_rg(ctx) ? GL_RG : 0; |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2219 | case GL_RG16: |
Tapani Pälli | ce80abb | 2018-07-24 08:58:20 +0300 | [diff] [blame] | 2220 | return _mesa_has_ARB_texture_rg(ctx) || _mesa_has_EXT_texture_norm16(ctx) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2221 | ? GL_RG : 0; |
| 2222 | case GL_RG8: |
| 2223 | return ctx->API != API_OPENGLES && ctx->Extensions.ARB_texture_rg |
| 2224 | ? GL_RG : 0; |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 2225 | /* signed normalized texture formats */ |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 2226 | case GL_R8_SNORM: |
Tapani Pälli | 0d356cf | 2018-05-24 14:05:27 +0300 | [diff] [blame] | 2227 | return _mesa_has_EXT_texture_snorm(ctx) || _mesa_has_EXT_render_snorm(ctx) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2228 | ? GL_RED : 0; |
Tapani Pälli | 0d356cf | 2018-05-24 14:05:27 +0300 | [diff] [blame] | 2229 | case GL_RED_SNORM: |
| 2230 | return _mesa_has_EXT_texture_snorm(ctx) ? GL_RED : 0; |
| 2231 | case GL_R16_SNORM: |
| 2232 | return _mesa_has_EXT_texture_snorm(ctx) || |
| 2233 | (_mesa_has_EXT_render_snorm(ctx) && |
| 2234 | _mesa_has_EXT_texture_norm16(ctx)) |
| 2235 | ? GL_RED : 0; |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 2236 | case GL_RG8_SNORM: |
Tapani Pälli | 0d356cf | 2018-05-24 14:05:27 +0300 | [diff] [blame] | 2237 | return _mesa_has_EXT_texture_snorm(ctx) || _mesa_has_EXT_render_snorm(ctx) |
| 2238 | ? GL_RG : 0; |
| 2239 | case GL_RG_SNORM: |
Danylo Piliaiev | 2b98a02 | 2018-09-06 17:01:07 +0300 | [diff] [blame] | 2240 | return _mesa_has_EXT_texture_snorm(ctx) ? GL_RG : 0; |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 2241 | case GL_RG16_SNORM: |
Tapani Pälli | 0d356cf | 2018-05-24 14:05:27 +0300 | [diff] [blame] | 2242 | return _mesa_has_EXT_texture_snorm(ctx) || |
| 2243 | (_mesa_has_EXT_render_snorm(ctx) && |
| 2244 | _mesa_has_EXT_texture_norm16(ctx)) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2245 | ? GL_RG : 0; |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2246 | case GL_RGB_SNORM: |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 2247 | case GL_RGB8_SNORM: |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 2248 | case GL_RGB16_SNORM: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2249 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 2250 | ? GL_RGB : 0; |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 2251 | case GL_RGBA8_SNORM: |
Tapani Pälli | 0d356cf | 2018-05-24 14:05:27 +0300 | [diff] [blame] | 2252 | return _mesa_has_EXT_texture_snorm(ctx) || _mesa_has_EXT_render_snorm(ctx) |
| 2253 | ? GL_RGBA : 0; |
| 2254 | case GL_RGBA_SNORM: |
| 2255 | return _mesa_has_EXT_texture_snorm(ctx) ? GL_RGBA : 0; |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 2256 | case GL_RGBA16_SNORM: |
Tapani Pälli | 0d356cf | 2018-05-24 14:05:27 +0300 | [diff] [blame] | 2257 | return _mesa_has_EXT_texture_snorm(ctx) || |
| 2258 | (_mesa_has_EXT_render_snorm(ctx) && |
| 2259 | _mesa_has_EXT_texture_norm16(ctx)) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2260 | ? GL_RGBA : 0; |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 2261 | case GL_ALPHA_SNORM: |
| 2262 | case GL_ALPHA8_SNORM: |
| 2263 | case GL_ALPHA16_SNORM: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 2264 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2265 | ctx->Extensions.EXT_texture_snorm && |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 2266 | ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0; |
Brian Paul | 513a324 | 2014-01-08 09:05:29 -0700 | [diff] [blame] | 2267 | case GL_LUMINANCE_SNORM: |
| 2268 | case GL_LUMINANCE8_SNORM: |
| 2269 | case GL_LUMINANCE16_SNORM: |
| 2270 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 2271 | ? GL_LUMINANCE : 0; |
| 2272 | case GL_LUMINANCE_ALPHA_SNORM: |
| 2273 | case GL_LUMINANCE8_ALPHA8_SNORM: |
| 2274 | case GL_LUMINANCE16_ALPHA16_SNORM: |
| 2275 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 2276 | ? GL_LUMINANCE_ALPHA : 0; |
| 2277 | case GL_INTENSITY_SNORM: |
| 2278 | case GL_INTENSITY8_SNORM: |
| 2279 | case GL_INTENSITY16_SNORM: |
| 2280 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 2281 | ? GL_INTENSITY : 0; |
| 2282 | |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 2283 | case GL_R16F: |
| 2284 | case GL_R32F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 2285 | return ((_mesa_is_desktop_gl(ctx) && |
| 2286 | ctx->Extensions.ARB_texture_rg && |
| 2287 | ctx->Extensions.ARB_texture_float) || |
| 2288 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
| 2289 | ? GL_RED : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 2290 | case GL_RG16F: |
| 2291 | case GL_RG32F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 2292 | return ((_mesa_is_desktop_gl(ctx) && |
| 2293 | ctx->Extensions.ARB_texture_rg && |
| 2294 | ctx->Extensions.ARB_texture_float) || |
| 2295 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
| 2296 | ? GL_RG : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 2297 | case GL_RGB16F: |
Tapani Pälli | 8447b0f | 2020-09-01 14:20:27 +0300 | [diff] [blame] | 2298 | return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_float) || |
| 2299 | (_mesa_is_gles(ctx) && _mesa_has_EXT_color_buffer_half_float(ctx)) |
| 2300 | ? GL_RGB : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 2301 | case GL_RGB32F: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2302 | return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_float) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2303 | ? GL_RGB : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 2304 | case GL_RGBA16F: |
| 2305 | case GL_RGBA32F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 2306 | return ((_mesa_is_desktop_gl(ctx) && |
| 2307 | ctx->Extensions.ARB_texture_float) || |
| 2308 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2309 | ? GL_RGBA : 0; |
Juan A. Suarez Romero | e1623b3 | 2018-01-15 10:58:50 +0000 | [diff] [blame] | 2310 | case GL_RGB9_E5: |
| 2311 | return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_shared_exponent) |
| 2312 | ? GL_RGB: 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 2313 | case GL_ALPHA16F_ARB: |
| 2314 | case GL_ALPHA32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 2315 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2316 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 2317 | ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0; |
| 2318 | case GL_LUMINANCE16F_ARB: |
| 2319 | case GL_LUMINANCE32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 2320 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2321 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 2322 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0; |
| 2323 | case GL_LUMINANCE_ALPHA16F_ARB: |
| 2324 | case GL_LUMINANCE_ALPHA32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 2325 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2326 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 2327 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0; |
| 2328 | case GL_INTENSITY16F_ARB: |
| 2329 | case GL_INTENSITY32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 2330 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2331 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 2332 | ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0; |
Marek Olšák | 631d23d | 2011-04-26 02:27:25 +0200 | [diff] [blame] | 2333 | case GL_R11F_G11F_B10F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 2334 | return ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_packed_float) || |
| 2335 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
Matt Turner | cbef537 | 2012-11-20 13:45:03 -0800 | [diff] [blame] | 2336 | ? GL_RGB : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 2337 | |
| 2338 | case GL_RGBA8UI_EXT: |
| 2339 | case GL_RGBA16UI_EXT: |
| 2340 | case GL_RGBA32UI_EXT: |
| 2341 | case GL_RGBA8I_EXT: |
| 2342 | case GL_RGBA16I_EXT: |
| 2343 | case GL_RGBA32I_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2344 | return ctx->Version >= 30 |
| 2345 | || (_mesa_is_desktop_gl(ctx) && |
| 2346 | ctx->Extensions.EXT_texture_integer) ? GL_RGBA : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 2347 | |
| 2348 | case GL_RGB8UI_EXT: |
| 2349 | case GL_RGB16UI_EXT: |
| 2350 | case GL_RGB32UI_EXT: |
| 2351 | case GL_RGB8I_EXT: |
| 2352 | case GL_RGB16I_EXT: |
| 2353 | case GL_RGB32I_EXT: |
Ian Romanick | a86d629 | 2012-12-03 11:55:12 -0800 | [diff] [blame] | 2354 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_integer |
| 2355 | ? GL_RGB : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 2356 | case GL_R8UI: |
| 2357 | case GL_R8I: |
| 2358 | case GL_R16UI: |
| 2359 | case GL_R16I: |
| 2360 | case GL_R32UI: |
| 2361 | case GL_R32I: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2362 | return ctx->Version >= 30 |
| 2363 | || (_mesa_is_desktop_gl(ctx) && |
| 2364 | ctx->Extensions.ARB_texture_rg && |
| 2365 | ctx->Extensions.EXT_texture_integer) ? GL_RED : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 2366 | |
| 2367 | case GL_RG8UI: |
| 2368 | case GL_RG8I: |
| 2369 | case GL_RG16UI: |
| 2370 | case GL_RG16I: |
| 2371 | case GL_RG32UI: |
| 2372 | case GL_RG32I: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2373 | return ctx->Version >= 30 |
| 2374 | || (_mesa_is_desktop_gl(ctx) && |
| 2375 | ctx->Extensions.ARB_texture_rg && |
| 2376 | ctx->Extensions.EXT_texture_integer) ? GL_RG : 0; |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 2377 | |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 2378 | case GL_INTENSITY8I_EXT: |
| 2379 | case GL_INTENSITY8UI_EXT: |
| 2380 | case GL_INTENSITY16I_EXT: |
| 2381 | case GL_INTENSITY16UI_EXT: |
| 2382 | case GL_INTENSITY32I_EXT: |
| 2383 | case GL_INTENSITY32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 2384 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2385 | ctx->Extensions.EXT_texture_integer && |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 2386 | ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0; |
| 2387 | |
| 2388 | case GL_LUMINANCE8I_EXT: |
| 2389 | case GL_LUMINANCE8UI_EXT: |
| 2390 | case GL_LUMINANCE16I_EXT: |
| 2391 | case GL_LUMINANCE16UI_EXT: |
| 2392 | case GL_LUMINANCE32I_EXT: |
| 2393 | case GL_LUMINANCE32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 2394 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2395 | ctx->Extensions.EXT_texture_integer && |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 2396 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0; |
| 2397 | |
| 2398 | case GL_LUMINANCE_ALPHA8I_EXT: |
| 2399 | case GL_LUMINANCE_ALPHA8UI_EXT: |
| 2400 | case GL_LUMINANCE_ALPHA16I_EXT: |
| 2401 | case GL_LUMINANCE_ALPHA16UI_EXT: |
| 2402 | case GL_LUMINANCE_ALPHA32I_EXT: |
| 2403 | case GL_LUMINANCE_ALPHA32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 2404 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2405 | ctx->Extensions.EXT_texture_integer && |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 2406 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0; |
Dave Airlie | f449be6 | 2011-11-27 16:21:02 +0000 | [diff] [blame] | 2407 | |
Marek Olšák | 636802f | 2012-01-22 20:21:36 +0100 | [diff] [blame] | 2408 | case GL_ALPHA8I_EXT: |
| 2409 | case GL_ALPHA8UI_EXT: |
| 2410 | case GL_ALPHA16I_EXT: |
| 2411 | case GL_ALPHA16UI_EXT: |
| 2412 | case GL_ALPHA32I_EXT: |
| 2413 | case GL_ALPHA32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 2414 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2415 | ctx->Extensions.EXT_texture_integer && |
Marek Olšák | 636802f | 2012-01-22 20:21:36 +0100 | [diff] [blame] | 2416 | ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0; |
| 2417 | |
Dave Airlie | f449be6 | 2011-11-27 16:21:02 +0000 | [diff] [blame] | 2418 | case GL_RGB10_A2UI: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2419 | return (_mesa_is_desktop_gl(ctx) && |
| 2420 | ctx->Extensions.ARB_texture_rgb10_a2ui) |
| 2421 | || _mesa_is_gles3(ctx) ? GL_RGBA : 0; |
Marek Olšák | 1a06e84 | 2012-07-12 14:07:41 +0200 | [diff] [blame] | 2422 | |
| 2423 | case GL_RGB565: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 2424 | return _mesa_is_gles(ctx) || ctx->Extensions.ARB_ES2_compatibility |
| 2425 | ? GL_RGB : 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2426 | default: |
Eric Anholt | 65c41d5 | 2011-01-13 10:05:50 -0800 | [diff] [blame] | 2427 | return 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 2428 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 2432 | /** |
| 2433 | * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk(). |
| 2434 | */ |
| 2435 | static void |
Ian Romanick | cc6dcc6 | 2020-10-12 16:52:09 -0700 | [diff] [blame^] | 2436 | invalidate_rb(void *data, void *userData) |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 2437 | { |
| 2438 | struct gl_framebuffer *fb = (struct gl_framebuffer *) data; |
| 2439 | struct gl_renderbuffer *rb = (struct gl_renderbuffer *) userData; |
| 2440 | |
| 2441 | /* If this is a user-created FBO */ |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 2442 | if (_mesa_is_user_fbo(fb)) { |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 2443 | GLuint i; |
| 2444 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 2445 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
| 2446 | if (att->Type == GL_RENDERBUFFER && |
| 2447 | att->Renderbuffer == rb) { |
| 2448 | /* Mark fb status as indeterminate to force re-validation */ |
| 2449 | fb->_Status = 0; |
Marek Olšák | a674ef7 | 2011-03-07 23:33:36 +0100 | [diff] [blame] | 2450 | return; |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2457 | /** sentinal value, see below */ |
| 2458 | #define NO_SAMPLES 1000 |
| 2459 | |
Ian Romanick | eb5bc62 | 2015-11-12 09:11:20 -0800 | [diff] [blame] | 2460 | void |
| 2461 | _mesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, |
| 2462 | GLenum internalFormat, GLsizei width, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2463 | GLsizei height, GLsizei samples, |
| 2464 | GLsizei storageSamples) |
Ian Romanick | eb5bc62 | 2015-11-12 09:11:20 -0800 | [diff] [blame] | 2465 | { |
| 2466 | const GLenum baseFormat = _mesa_base_fbo_format(ctx, internalFormat); |
| 2467 | |
| 2468 | assert(baseFormat != 0); |
| 2469 | assert(width >= 0 && width <= (GLsizei) ctx->Const.MaxRenderbufferSize); |
| 2470 | assert(height >= 0 && height <= (GLsizei) ctx->Const.MaxRenderbufferSize); |
| 2471 | assert(samples != NO_SAMPLES); |
| 2472 | if (samples != 0) { |
| 2473 | assert(samples > 0); |
| 2474 | assert(_mesa_check_sample_count(ctx, GL_RENDERBUFFER, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2475 | internalFormat, samples, |
| 2476 | storageSamples) == GL_NO_ERROR); |
Ian Romanick | eb5bc62 | 2015-11-12 09:11:20 -0800 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 2480 | |
| 2481 | if (rb->InternalFormat == internalFormat && |
| 2482 | rb->Width == (GLuint) width && |
| 2483 | rb->Height == (GLuint) height && |
Marek Olšák | 328c1c8 | 2018-06-11 17:24:16 -0400 | [diff] [blame] | 2484 | rb->NumSamples == samples && |
| 2485 | rb->NumStorageSamples == storageSamples) { |
Ian Romanick | eb5bc62 | 2015-11-12 09:11:20 -0800 | [diff] [blame] | 2486 | /* no change in allocation needed */ |
| 2487 | return; |
| 2488 | } |
| 2489 | |
| 2490 | /* These MUST get set by the AllocStorage func */ |
| 2491 | rb->Format = MESA_FORMAT_NONE; |
| 2492 | rb->NumSamples = samples; |
Marek Olšák | 328c1c8 | 2018-06-11 17:24:16 -0400 | [diff] [blame] | 2493 | rb->NumStorageSamples = storageSamples; |
Ian Romanick | eb5bc62 | 2015-11-12 09:11:20 -0800 | [diff] [blame] | 2494 | |
| 2495 | /* Now allocate the storage */ |
| 2496 | assert(rb->AllocStorage); |
| 2497 | if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) { |
| 2498 | /* No error - check/set fields now */ |
| 2499 | /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */ |
| 2500 | assert(rb->Width == (GLuint) width); |
| 2501 | assert(rb->Height == (GLuint) height); |
| 2502 | rb->InternalFormat = internalFormat; |
| 2503 | rb->_BaseFormat = baseFormat; |
| 2504 | assert(rb->_BaseFormat != 0); |
| 2505 | } |
| 2506 | else { |
| 2507 | /* Probably ran out of memory - clear the fields */ |
| 2508 | rb->Width = 0; |
| 2509 | rb->Height = 0; |
| 2510 | rb->Format = MESA_FORMAT_NONE; |
| 2511 | rb->InternalFormat = GL_NONE; |
| 2512 | rb->_BaseFormat = GL_NONE; |
| 2513 | rb->NumSamples = 0; |
Marek Olšák | 328c1c8 | 2018-06-11 17:24:16 -0400 | [diff] [blame] | 2514 | rb->NumStorageSamples = 0; |
Ian Romanick | eb5bc62 | 2015-11-12 09:11:20 -0800 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | /* Invalidate the framebuffers the renderbuffer is attached in. */ |
| 2518 | if (rb->AttachedAnytime) { |
| 2519 | _mesa_HashWalk(ctx->Shared->FrameBuffers, invalidate_rb, rb); |
| 2520 | } |
| 2521 | } |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2522 | |
| 2523 | /** |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2524 | * Helper function used by renderbuffer_storage_direct() and |
| 2525 | * renderbuffer_storage_target(). |
| 2526 | * samples will be NO_SAMPLES if called by a non-multisample function. |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2527 | */ |
| 2528 | static void |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2529 | renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, |
| 2530 | GLenum internalFormat, GLsizei width, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2531 | GLsizei height, GLsizei samples, GLsizei storageSamples, |
| 2532 | const char *func) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2533 | { |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2534 | GLenum baseFormat; |
Chris Forbes | 90b5a24 | 2013-02-06 20:42:53 +1300 | [diff] [blame] | 2535 | GLenum sample_count_error; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2536 | |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 2537 | baseFormat = _mesa_base_fbo_format(ctx, internalFormat); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2538 | if (baseFormat == 0) { |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 2539 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat=%s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2540 | func, _mesa_enum_to_string(internalFormat)); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2541 | return; |
| 2542 | } |
| 2543 | |
Yuanhan Liu | 49f8447 | 2011-10-25 15:36:59 +0800 | [diff] [blame] | 2544 | if (width < 0 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) { |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2545 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid width %d)", func, |
| 2546 | width); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2547 | return; |
| 2548 | } |
| 2549 | |
Yuanhan Liu | 49f8447 | 2011-10-25 15:36:59 +0800 | [diff] [blame] | 2550 | if (height < 0 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) { |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2551 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid height %d)", func, |
| 2552 | height); |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2553 | return; |
| 2554 | } |
| 2555 | |
| 2556 | if (samples == NO_SAMPLES) { |
| 2557 | /* NumSamples == 0 indicates non-multisampling */ |
| 2558 | samples = 0; |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2559 | storageSamples = 0; |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2560 | } |
Chris Forbes | 21a2dfa | 2013-03-25 23:19:07 +1300 | [diff] [blame] | 2561 | else { |
| 2562 | /* check the sample count; |
| 2563 | * note: driver may choose to use more samples than what's requested |
| 2564 | */ |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2565 | sample_count_error = _mesa_check_sample_count(ctx, GL_RENDERBUFFER, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2566 | internalFormat, samples, storageSamples); |
Timothy Arceri | 46684d3 | 2015-08-13 18:44:51 +1000 | [diff] [blame] | 2567 | |
| 2568 | /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16: |
| 2569 | * |
| 2570 | * "If a negative number is provided where an argument of type sizei or |
| 2571 | * sizeiptr is specified, the error INVALID VALUE is generated." |
| 2572 | */ |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2573 | if (samples < 0 || storageSamples < 0) { |
Timothy Arceri | 46684d3 | 2015-08-13 18:44:51 +1000 | [diff] [blame] | 2574 | sample_count_error = GL_INVALID_VALUE; |
| 2575 | } |
| 2576 | |
Chris Forbes | 21a2dfa | 2013-03-25 23:19:07 +1300 | [diff] [blame] | 2577 | if (sample_count_error != GL_NO_ERROR) { |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2578 | _mesa_error(ctx, sample_count_error, |
| 2579 | "%s(samples=%d, storageSamples=%d)", func, samples, |
| 2580 | storageSamples); |
Chris Forbes | 21a2dfa | 2013-03-25 23:19:07 +1300 | [diff] [blame] | 2581 | return; |
| 2582 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2583 | } |
| 2584 | |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2585 | _mesa_renderbuffer_storage(ctx, rb, internalFormat, width, height, samples, |
| 2586 | storageSamples); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2589 | /** |
| 2590 | * Helper function used by _mesa_NamedRenderbufferStorage*(). |
| 2591 | * samples will be NO_SAMPLES if called by a non-multisample function. |
| 2592 | */ |
| 2593 | static void |
| 2594 | renderbuffer_storage_named(GLuint renderbuffer, GLenum internalFormat, |
| 2595 | GLsizei width, GLsizei height, GLsizei samples, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2596 | GLsizei storageSamples, const char *func) |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2597 | { |
| 2598 | GET_CURRENT_CONTEXT(ctx); |
| 2599 | |
| 2600 | if (MESA_VERBOSE & VERBOSE_API) { |
| 2601 | if (samples == NO_SAMPLES) |
| 2602 | _mesa_debug(ctx, "%s(%u, %s, %d, %d)\n", |
| 2603 | func, renderbuffer, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2604 | _mesa_enum_to_string(internalFormat), |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2605 | width, height); |
| 2606 | else |
| 2607 | _mesa_debug(ctx, "%s(%u, %s, %d, %d, %d)\n", |
| 2608 | func, renderbuffer, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2609 | _mesa_enum_to_string(internalFormat), |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2610 | width, height, samples); |
| 2611 | } |
| 2612 | |
| 2613 | struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
| 2614 | if (!rb || rb == &DummyRenderbuffer) { |
| 2615 | /* ID was reserved, but no real renderbuffer object made yet */ |
| 2616 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid renderbuffer %u)", |
| 2617 | func, renderbuffer); |
| 2618 | return; |
| 2619 | } |
| 2620 | |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2621 | renderbuffer_storage(ctx, rb, internalFormat, width, height, samples, |
| 2622 | storageSamples, func); |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | /** |
| 2626 | * Helper function used by _mesa_RenderbufferStorage() and |
| 2627 | * _mesa_RenderbufferStorageMultisample(). |
| 2628 | * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage(). |
| 2629 | */ |
| 2630 | static void |
| 2631 | renderbuffer_storage_target(GLenum target, GLenum internalFormat, |
| 2632 | GLsizei width, GLsizei height, GLsizei samples, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2633 | GLsizei storageSamples, const char *func) |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2634 | { |
| 2635 | GET_CURRENT_CONTEXT(ctx); |
| 2636 | |
| 2637 | if (MESA_VERBOSE & VERBOSE_API) { |
| 2638 | if (samples == NO_SAMPLES) |
| 2639 | _mesa_debug(ctx, "%s(%s, %s, %d, %d)\n", |
| 2640 | func, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2641 | _mesa_enum_to_string(target), |
| 2642 | _mesa_enum_to_string(internalFormat), |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2643 | width, height); |
| 2644 | else |
| 2645 | _mesa_debug(ctx, "%s(%s, %s, %d, %d, %d)\n", |
| 2646 | func, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2647 | _mesa_enum_to_string(target), |
| 2648 | _mesa_enum_to_string(internalFormat), |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2649 | width, height, samples); |
| 2650 | } |
| 2651 | |
| 2652 | if (target != GL_RENDERBUFFER_EXT) { |
| 2653 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func); |
| 2654 | return; |
| 2655 | } |
| 2656 | |
| 2657 | if (!ctx->CurrentRenderbuffer) { |
| 2658 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no renderbuffer bound)", |
| 2659 | func); |
| 2660 | return; |
| 2661 | } |
| 2662 | |
| 2663 | renderbuffer_storage(ctx, ctx->CurrentRenderbuffer, internalFormat, width, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2664 | height, samples, storageSamples, func); |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2665 | } |
| 2666 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2667 | |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2668 | void GLAPIENTRY |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2669 | _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2670 | { |
Brian Paul | 51b7992 | 2010-02-24 11:57:26 -0700 | [diff] [blame] | 2671 | struct gl_renderbuffer *rb; |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2672 | GET_CURRENT_CONTEXT(ctx); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2673 | |
Chia-I Wu | 2002e4d0 | 2010-04-06 17:46:17 +0800 | [diff] [blame] | 2674 | if (!ctx->Extensions.OES_EGL_image) { |
| 2675 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2676 | "glEGLImageTargetRenderbufferStorageOES(unsupported)"); |
| 2677 | return; |
| 2678 | } |
| 2679 | |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2680 | if (target != GL_RENDERBUFFER) { |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2681 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2682 | "EGLImageTargetRenderbufferStorageOES"); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2683 | return; |
| 2684 | } |
| 2685 | |
| 2686 | rb = ctx->CurrentRenderbuffer; |
| 2687 | if (!rb) { |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2688 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2689 | "EGLImageTargetRenderbufferStorageOES"); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2690 | return; |
| 2691 | } |
| 2692 | |
| 2693 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 2694 | |
| 2695 | ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image); |
| 2696 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2697 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2698 | |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2699 | /** |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2700 | * Helper function for _mesa_GetRenderbufferParameteriv() and |
| 2701 | * _mesa_GetFramebufferAttachmentParameteriv() |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2702 | * We have to be careful to respect the base format. For example, if a |
| 2703 | * renderbuffer/texture was created with internalFormat=GL_RGB but the |
| 2704 | * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE |
| 2705 | * we need to return zero. |
| 2706 | */ |
| 2707 | static GLint |
Mark Mueller | 71fe943 | 2014-01-04 14:11:43 -0800 | [diff] [blame] | 2708 | get_component_bits(GLenum pname, GLenum baseFormat, mesa_format format) |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2709 | { |
Brian Paul | f0b6e9a | 2011-11-23 15:33:45 -0700 | [diff] [blame] | 2710 | if (_mesa_base_format_has_channel(baseFormat, pname)) |
| 2711 | return _mesa_get_format_bits(format, pname); |
| 2712 | else |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2713 | return 0; |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | |
| 2717 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2718 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2719 | _mesa_RenderbufferStorage(GLenum target, GLenum internalFormat, |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2720 | GLsizei width, GLsizei height) |
| 2721 | { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2722 | /* GL_ARB_fbo says calling this function is equivalent to calling |
| 2723 | * glRenderbufferStorageMultisample() with samples=0. We pass in |
| 2724 | * a token value here just for error reporting purposes. |
| 2725 | */ |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2726 | renderbuffer_storage_target(target, internalFormat, width, height, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2727 | NO_SAMPLES, 0, "glRenderbufferStorage"); |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | |
| 2731 | void GLAPIENTRY |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 2732 | _mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples, |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2733 | GLenum internalFormat, |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 2734 | GLsizei width, GLsizei height) |
| 2735 | { |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2736 | renderbuffer_storage_target(target, internalFormat, width, height, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2737 | samples, samples, |
| 2738 | "glRenderbufferStorageMultisample"); |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 2739 | } |
| 2740 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2741 | |
Marek Olšák | 3d6900d | 2018-06-28 02:05:12 -0400 | [diff] [blame] | 2742 | void GLAPIENTRY |
| 2743 | _mesa_RenderbufferStorageMultisampleAdvancedAMD( |
| 2744 | GLenum target, GLsizei samples, GLsizei storageSamples, |
| 2745 | GLenum internalFormat, GLsizei width, GLsizei height) |
| 2746 | { |
| 2747 | renderbuffer_storage_target(target, internalFormat, width, height, |
| 2748 | samples, storageSamples, |
| 2749 | "glRenderbufferStorageMultisampleAdvancedAMD"); |
| 2750 | } |
| 2751 | |
| 2752 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2753 | /** |
| 2754 | * OpenGL ES version of glRenderBufferStorage. |
| 2755 | */ |
Kristian Høgsberg | 61d94dd | 2010-04-22 21:11:56 -0400 | [diff] [blame] | 2756 | void GLAPIENTRY |
| 2757 | _es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat, |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 2758 | GLsizei width, GLsizei height) |
Kristian Høgsberg | 61d94dd | 2010-04-22 21:11:56 -0400 | [diff] [blame] | 2759 | { |
| 2760 | switch (internalFormat) { |
| 2761 | case GL_RGB565: |
| 2762 | /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */ |
| 2763 | /* choose a closest format */ |
| 2764 | internalFormat = GL_RGB5; |
| 2765 | break; |
| 2766 | default: |
| 2767 | break; |
| 2768 | } |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 2769 | |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2770 | renderbuffer_storage_target(target, internalFormat, width, height, 0, 0, |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2771 | "glRenderbufferStorageEXT"); |
| 2772 | } |
| 2773 | |
| 2774 | void GLAPIENTRY |
| 2775 | _mesa_NamedRenderbufferStorage(GLuint renderbuffer, GLenum internalformat, |
| 2776 | GLsizei width, GLsizei height) |
| 2777 | { |
| 2778 | /* GL_ARB_fbo says calling this function is equivalent to calling |
| 2779 | * glRenderbufferStorageMultisample() with samples=0. We pass in |
| 2780 | * a token value here just for error reporting purposes. |
| 2781 | */ |
| 2782 | renderbuffer_storage_named(renderbuffer, internalformat, width, height, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2783 | NO_SAMPLES, 0, "glNamedRenderbufferStorage"); |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | void GLAPIENTRY |
Pierre-Eric Pelloux-Prayer | 01666ad | 2019-05-23 16:34:16 +0200 | [diff] [blame] | 2787 | _mesa_NamedRenderbufferStorageEXT(GLuint renderbuffer, GLenum internalformat, |
| 2788 | GLsizei width, GLsizei height) |
| 2789 | { |
| 2790 | GET_CURRENT_CONTEXT(ctx); |
| 2791 | struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
| 2792 | if (!rb || rb == &DummyRenderbuffer) { |
| 2793 | _mesa_HashLockMutex(ctx->Shared->RenderBuffers); |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 2794 | rb = allocate_renderbuffer_locked(ctx, renderbuffer, rb != NULL, |
| 2795 | "glNamedRenderbufferStorageEXT"); |
Pierre-Eric Pelloux-Prayer | 01666ad | 2019-05-23 16:34:16 +0200 | [diff] [blame] | 2796 | _mesa_HashUnlockMutex(ctx->Shared->RenderBuffers); |
| 2797 | } |
| 2798 | renderbuffer_storage(ctx, rb, internalformat, width, height, NO_SAMPLES, |
| 2799 | 0, "glNamedRenderbufferStorageEXT"); |
| 2800 | } |
| 2801 | |
| 2802 | |
| 2803 | void GLAPIENTRY |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2804 | _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer, GLsizei samples, |
| 2805 | GLenum internalformat, |
| 2806 | GLsizei width, GLsizei height) |
| 2807 | { |
| 2808 | renderbuffer_storage_named(renderbuffer, internalformat, width, height, |
Marek Olšák | 2d11505 | 2018-06-11 15:26:41 -0400 | [diff] [blame] | 2809 | samples, samples, |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2810 | "glNamedRenderbufferStorageMultisample"); |
Kristian Høgsberg | 61d94dd | 2010-04-22 21:11:56 -0400 | [diff] [blame] | 2811 | } |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 2812 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2813 | |
Marek Olšák | 3d6900d | 2018-06-28 02:05:12 -0400 | [diff] [blame] | 2814 | void GLAPIENTRY |
Pierre-Eric Pelloux-Prayer | da21435 | 2019-09-11 10:13:21 +0200 | [diff] [blame] | 2815 | _mesa_NamedRenderbufferStorageMultisampleEXT(GLuint renderbuffer, GLsizei samples, |
| 2816 | GLenum internalformat, |
| 2817 | GLsizei width, GLsizei height) |
| 2818 | { |
| 2819 | GET_CURRENT_CONTEXT(ctx); |
| 2820 | struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
| 2821 | if (!rb || rb == &DummyRenderbuffer) { |
| 2822 | _mesa_HashLockMutex(ctx->Shared->RenderBuffers); |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 2823 | rb = allocate_renderbuffer_locked(ctx, renderbuffer, rb != NULL, |
Pierre-Eric Pelloux-Prayer | da21435 | 2019-09-11 10:13:21 +0200 | [diff] [blame] | 2824 | "glNamedRenderbufferStorageMultisampleEXT"); |
| 2825 | _mesa_HashUnlockMutex(ctx->Shared->RenderBuffers); |
| 2826 | } |
| 2827 | renderbuffer_storage(ctx, rb, internalformat, width, height, |
| 2828 | samples, samples, |
| 2829 | "glNamedRenderbufferStorageMultisample"); |
| 2830 | } |
| 2831 | |
| 2832 | |
| 2833 | void GLAPIENTRY |
Marek Olšák | 3d6900d | 2018-06-28 02:05:12 -0400 | [diff] [blame] | 2834 | _mesa_NamedRenderbufferStorageMultisampleAdvancedAMD( |
| 2835 | GLuint renderbuffer, GLsizei samples, GLsizei storageSamples, |
| 2836 | GLenum internalformat, GLsizei width, GLsizei height) |
| 2837 | { |
| 2838 | renderbuffer_storage_named(renderbuffer, internalformat, width, height, |
| 2839 | samples, storageSamples, |
| 2840 | "glNamedRenderbufferStorageMultisampleAdvancedAMD"); |
| 2841 | } |
| 2842 | |
| 2843 | |
Martin Peres | 245e5c4 | 2015-02-13 15:46:55 +0200 | [diff] [blame] | 2844 | static void |
| 2845 | get_render_buffer_parameteriv(struct gl_context *ctx, |
| 2846 | struct gl_renderbuffer *rb, GLenum pname, |
| 2847 | GLint *params, const char *func) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2848 | { |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 2849 | /* No need to flush here since we're just quering state which is |
| 2850 | * not effected by rendering. |
| 2851 | */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 2852 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2853 | switch (pname) { |
| 2854 | case GL_RENDERBUFFER_WIDTH_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2855 | *params = rb->Width; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2856 | return; |
| 2857 | case GL_RENDERBUFFER_HEIGHT_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2858 | *params = rb->Height; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2859 | return; |
| 2860 | case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2861 | *params = rb->InternalFormat; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2862 | return; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2863 | case GL_RENDERBUFFER_RED_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2864 | case GL_RENDERBUFFER_GREEN_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2865 | case GL_RENDERBUFFER_BLUE_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2866 | case GL_RENDERBUFFER_ALPHA_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2867 | case GL_RENDERBUFFER_DEPTH_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2868 | case GL_RENDERBUFFER_STENCIL_SIZE_EXT: |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2869 | *params = get_component_bits(pname, rb->_BaseFormat, rb->Format); |
Marek Olšák | 328c1c8 | 2018-06-11 17:24:16 -0400 | [diff] [blame] | 2870 | return; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2871 | case GL_RENDERBUFFER_SAMPLES: |
Ian Romanick | ae86ebf | 2012-07-27 07:49:49 -0700 | [diff] [blame] | 2872 | if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_framebuffer_object) |
| 2873 | || _mesa_is_gles3(ctx)) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2874 | *params = rb->NumSamples; |
Marek Olšák | 328c1c8 | 2018-06-11 17:24:16 -0400 | [diff] [blame] | 2875 | return; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2876 | } |
Marek Olšák | 328c1c8 | 2018-06-11 17:24:16 -0400 | [diff] [blame] | 2877 | break; |
| 2878 | case GL_RENDERBUFFER_STORAGE_SAMPLES_AMD: |
| 2879 | if (ctx->Extensions.AMD_framebuffer_multisample_advanced) { |
| 2880 | *params = rb->NumStorageSamples; |
| 2881 | return; |
| 2882 | } |
| 2883 | break; |
Martin Peres | 245e5c4 | 2015-02-13 15:46:55 +0200 | [diff] [blame] | 2884 | } |
Marek Olšák | 328c1c8 | 2018-06-11 17:24:16 -0400 | [diff] [blame] | 2885 | |
| 2886 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid pname=%s)", func, |
| 2887 | _mesa_enum_to_string(pname)); |
Martin Peres | 245e5c4 | 2015-02-13 15:46:55 +0200 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | |
| 2891 | void GLAPIENTRY |
| 2892 | _mesa_GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params) |
| 2893 | { |
| 2894 | GET_CURRENT_CONTEXT(ctx); |
| 2895 | |
| 2896 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2897 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2898 | "glGetRenderbufferParameterivEXT(target)"); |
| 2899 | return; |
| 2900 | } |
Martin Peres | 245e5c4 | 2015-02-13 15:46:55 +0200 | [diff] [blame] | 2901 | |
| 2902 | if (!ctx->CurrentRenderbuffer) { |
| 2903 | _mesa_error(ctx, GL_INVALID_OPERATION, "glGetRenderbufferParameterivEXT" |
| 2904 | "(no renderbuffer bound)"); |
| 2905 | return; |
| 2906 | } |
| 2907 | |
| 2908 | get_render_buffer_parameteriv(ctx, ctx->CurrentRenderbuffer, pname, |
| 2909 | params, "glGetRenderbufferParameteriv"); |
| 2910 | } |
| 2911 | |
| 2912 | |
| 2913 | void GLAPIENTRY |
| 2914 | _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer, GLenum pname, |
| 2915 | GLint *params) |
| 2916 | { |
| 2917 | GET_CURRENT_CONTEXT(ctx); |
| 2918 | |
| 2919 | struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
| 2920 | if (!rb || rb == &DummyRenderbuffer) { |
| 2921 | /* ID was reserved, but no real renderbuffer object made yet */ |
| 2922 | _mesa_error(ctx, GL_INVALID_OPERATION, "glGetNamedRenderbufferParameteriv" |
| 2923 | "(invalid renderbuffer %i)", renderbuffer); |
| 2924 | return; |
| 2925 | } |
| 2926 | |
| 2927 | get_render_buffer_parameteriv(ctx, rb, pname, params, |
| 2928 | "glGetNamedRenderbufferParameteriv"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | |
Pierre-Eric Pelloux-Prayer | 01666ad | 2019-05-23 16:34:16 +0200 | [diff] [blame] | 2932 | void GLAPIENTRY |
| 2933 | _mesa_GetNamedRenderbufferParameterivEXT(GLuint renderbuffer, GLenum pname, |
| 2934 | GLint *params) |
| 2935 | { |
| 2936 | GET_CURRENT_CONTEXT(ctx); |
| 2937 | |
| 2938 | struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
| 2939 | if (!rb || rb == &DummyRenderbuffer) { |
| 2940 | _mesa_HashLockMutex(ctx->Shared->RenderBuffers); |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 2941 | rb = allocate_renderbuffer_locked(ctx, renderbuffer, rb != NULL, |
| 2942 | "glGetNamedRenderbufferParameterivEXT"); |
Pierre-Eric Pelloux-Prayer | 01666ad | 2019-05-23 16:34:16 +0200 | [diff] [blame] | 2943 | _mesa_HashUnlockMutex(ctx->Shared->RenderBuffers); |
| 2944 | } |
| 2945 | |
| 2946 | get_render_buffer_parameteriv(ctx, rb, pname, params, |
| 2947 | "glGetNamedRenderbufferParameterivEXT"); |
| 2948 | } |
| 2949 | |
| 2950 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2951 | GLboolean GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2952 | _mesa_IsFramebuffer(GLuint framebuffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2953 | { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2954 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2955 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 2956 | if (framebuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2957 | struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 2958 | if (rb != NULL && rb != &DummyFramebuffer) |
| 2959 | return GL_TRUE; |
| 2960 | } |
| 2961 | return GL_FALSE; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | |
brian | a492ab7 | 2009-11-10 15:33:31 -0700 | [diff] [blame] | 2965 | /** |
| 2966 | * Check if any of the attachments of the given framebuffer are textures |
| 2967 | * (render to texture). Call ctx->Driver.RenderTexture() for such |
| 2968 | * attachments. |
| 2969 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2970 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 2971 | check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb) |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2972 | { |
| 2973 | GLuint i; |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 2974 | assert(ctx->Driver.RenderTexture); |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2975 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 2976 | if (_mesa_is_winsys_fbo(fb)) |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2977 | return; /* can't render to texture with winsys framebuffers */ |
| 2978 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2979 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 2980 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
Ian Romanick | fb49713 | 2013-07-27 12:04:20 -0700 | [diff] [blame] | 2981 | if (att->Texture && att->Renderbuffer->TexImage |
| 2982 | && driver_RenderTexture_is_safe(att)) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2983 | ctx->Driver.RenderTexture(ctx, fb, att); |
| 2984 | } |
| 2985 | } |
| 2986 | } |
| 2987 | |
| 2988 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 2989 | /** |
| 2990 | * Examine all the framebuffer's attachments to see if any are textures. |
| 2991 | * If so, call ctx->Driver.FinishRenderTexture() for each texture to |
| 2992 | * notify the device driver that the texture image may have changed. |
| 2993 | */ |
| 2994 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 2995 | check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb) |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 2996 | { |
Eric Anholt | 7ccb26f | 2014-03-03 09:16:48 -0800 | [diff] [blame] | 2997 | /* Skip if we know NeedsFinishRenderTexture won't be set. */ |
| 2998 | if (_mesa_is_winsys_fbo(fb) && !ctx->Driver.BindRenderbufferTexImage) |
| 2999 | return; |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 3000 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 3001 | if (ctx->Driver.FinishRenderTexture) { |
| 3002 | GLuint i; |
| 3003 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 3004 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 3005 | struct gl_renderbuffer *rb = att->Renderbuffer; |
| 3006 | if (rb && rb->NeedsFinishRenderTexture) { |
Eric Anholt | a5b0452 | 2013-05-10 12:17:52 -0700 | [diff] [blame] | 3007 | ctx->Driver.FinishRenderTexture(ctx, rb); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 3008 | } |
| 3009 | } |
| 3010 | } |
| 3011 | } |
| 3012 | |
| 3013 | |
Ian Romanick | 4a9522a | 2013-07-18 17:39:22 -0700 | [diff] [blame] | 3014 | static void |
Timothy Arceri | b54a231 | 2018-09-08 14:20:17 +1000 | [diff] [blame] | 3015 | bind_framebuffer(GLenum target, GLuint framebuffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3016 | { |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 3017 | struct gl_framebuffer *newDrawFb, *newReadFb; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3018 | GLboolean bindReadBuf, bindDrawBuf; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3019 | GET_CURRENT_CONTEXT(ctx); |
| 3020 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3021 | switch (target) { |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3022 | case GL_DRAW_FRAMEBUFFER_EXT: |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3023 | bindDrawBuf = GL_TRUE; |
| 3024 | bindReadBuf = GL_FALSE; |
| 3025 | break; |
| 3026 | case GL_READ_FRAMEBUFFER_EXT: |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3027 | bindDrawBuf = GL_FALSE; |
| 3028 | bindReadBuf = GL_TRUE; |
| 3029 | break; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3030 | case GL_FRAMEBUFFER_EXT: |
| 3031 | bindDrawBuf = GL_TRUE; |
| 3032 | bindReadBuf = GL_TRUE; |
| 3033 | break; |
| 3034 | default: |
Brian Paul | eba4ff6 | 2005-09-06 21:22:16 +0000 | [diff] [blame] | 3035 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3036 | return; |
| 3037 | } |
| 3038 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3039 | if (framebuffer) { |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 3040 | bool isGenName = false; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 3041 | /* Binding a user-created framebuffer object */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 3042 | newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer); |
| 3043 | if (newDrawFb == &DummyFramebuffer) { |
Brian Paul | 923b6fc | 2005-02-08 04:08:56 +0000 | [diff] [blame] | 3044 | /* ID was reserved, but no real framebuffer object made yet */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 3045 | newDrawFb = NULL; |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 3046 | isGenName = true; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 3047 | } |
Timothy Arceri | b54a231 | 2018-09-08 14:20:17 +1000 | [diff] [blame] | 3048 | else if (!newDrawFb && ctx->API == API_OPENGL_CORE) { |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3049 | /* All FBO IDs must be Gen'd */ |
Timothy Arceri | b54a231 | 2018-09-08 14:20:17 +1000 | [diff] [blame] | 3050 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3051 | "glBindFramebuffer(non-gen name)"); |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3052 | return; |
| 3053 | } |
| 3054 | |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 3055 | if (!newDrawFb) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3056 | /* create new framebuffer object */ |
| 3057 | newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer); |
| 3058 | if (!newDrawFb) { |
| 3059 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT"); |
| 3060 | return; |
| 3061 | } |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 3062 | _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb, isGenName); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3063 | } |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 3064 | newReadFb = newDrawFb; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3065 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 3066 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 3067 | /* Binding the window system framebuffer (which was originally set |
| 3068 | * with MakeCurrent). |
| 3069 | */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 3070 | newDrawFb = ctx->WinSysDrawBuffer; |
| 3071 | newReadFb = ctx->WinSysReadBuffer; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3072 | } |
| 3073 | |
Ian Romanick | fed9b0e | 2015-11-13 10:46:40 -0800 | [diff] [blame] | 3074 | _mesa_bind_framebuffers(ctx, |
| 3075 | bindDrawBuf ? newDrawFb : ctx->DrawBuffer, |
| 3076 | bindReadBuf ? newReadFb : ctx->ReadBuffer); |
| 3077 | } |
| 3078 | |
| 3079 | void |
| 3080 | _mesa_bind_framebuffers(struct gl_context *ctx, |
| 3081 | struct gl_framebuffer *newDrawFb, |
| 3082 | struct gl_framebuffer *newReadFb) |
| 3083 | { |
| 3084 | struct gl_framebuffer *const oldDrawFb = ctx->DrawBuffer; |
| 3085 | struct gl_framebuffer *const oldReadFb = ctx->ReadBuffer; |
| 3086 | const bool bindDrawBuf = oldDrawFb != newDrawFb; |
| 3087 | const bool bindReadBuf = oldReadFb != newReadFb; |
| 3088 | |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 3089 | assert(newDrawFb); |
| 3090 | assert(newDrawFb != &DummyFramebuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 3091 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3092 | /* |
Brian Paul | 1614463 | 2009-02-26 14:49:24 -0700 | [diff] [blame] | 3093 | * OK, now bind the new Draw/Read framebuffers, if they're changing. |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 3094 | * |
| 3095 | * We also check if we're beginning and/or ending render-to-texture. |
| 3096 | * When a framebuffer with texture attachments is unbound, call |
| 3097 | * ctx->Driver.FinishRenderTexture(). |
| 3098 | * When a framebuffer with texture attachments is bound, call |
| 3099 | * ctx->Driver.RenderTexture(). |
| 3100 | * |
| 3101 | * Note that if the ReadBuffer has texture attachments we don't consider |
| 3102 | * that a render-to-texture case. |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3103 | */ |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3104 | if (bindReadBuf) { |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 3105 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
brian | bc569cd | 2009-11-10 16:00:35 -0700 | [diff] [blame] | 3106 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 3107 | /* check if old readbuffer was render-to-texture */ |
| 3108 | check_end_texture_render(ctx, oldReadFb); |
| 3109 | |
| 3110 | _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb); |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | if (bindDrawBuf) { |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 3114 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 3115 | ctx->NewDriverState |= ctx->DriverFlags.NewSampleLocations; |
Brian | 32d86eb | 2007-08-16 18:52:48 +0100 | [diff] [blame] | 3116 | |
Eric Anholt | a1fd13f | 2012-02-10 12:05:16 -0800 | [diff] [blame] | 3117 | /* check if old framebuffer had any texture attachments */ |
| 3118 | if (oldDrawFb) |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 3119 | check_end_texture_render(ctx, oldDrawFb); |
brian | bc569cd | 2009-11-10 16:00:35 -0700 | [diff] [blame] | 3120 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 3121 | /* check if newly bound framebuffer has any texture attachments */ |
| 3122 | check_begin_texture_render(ctx, newDrawFb); |
| 3123 | |
| 3124 | _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb); |
Marek Olšák | 8c053e5 | 2020-01-30 18:56:22 -0500 | [diff] [blame] | 3125 | _mesa_update_allow_draw_out_of_order(ctx); |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3126 | } |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 3127 | |
Brian Paul | 1614463 | 2009-02-26 14:49:24 -0700 | [diff] [blame] | 3128 | if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) { |
Ian Romanick | fed9b0e | 2015-11-13 10:46:40 -0800 | [diff] [blame] | 3129 | /* The few classic drivers that actually hook this function really only |
| 3130 | * want to know if the draw framebuffer changed. |
| 3131 | */ |
| 3132 | ctx->Driver.BindFramebuffer(ctx, |
| 3133 | bindDrawBuf ? GL_FRAMEBUFFER : GL_READ_FRAMEBUFFER, |
| 3134 | newDrawFb, newReadFb); |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 3135 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3136 | } |
| 3137 | |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 3138 | void GLAPIENTRY |
Ian Romanick | 4a9522a | 2013-07-18 17:39:22 -0700 | [diff] [blame] | 3139 | _mesa_BindFramebuffer(GLenum target, GLuint framebuffer) |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 3140 | { |
Ian Romanick | 4a9522a | 2013-07-18 17:39:22 -0700 | [diff] [blame] | 3141 | /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry |
| 3142 | * point, but they allow the use of user-generated names. |
| 3143 | */ |
Timothy Arceri | b54a231 | 2018-09-08 14:20:17 +1000 | [diff] [blame] | 3144 | bind_framebuffer(target, framebuffer); |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 3145 | } |
| 3146 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3147 | |
Ian Romanick | 4a9522a | 2013-07-18 17:39:22 -0700 | [diff] [blame] | 3148 | void GLAPIENTRY |
| 3149 | _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer) |
| 3150 | { |
Timothy Arceri | b54a231 | 2018-09-08 14:20:17 +1000 | [diff] [blame] | 3151 | bind_framebuffer(target, framebuffer); |
Ian Romanick | 4a9522a | 2013-07-18 17:39:22 -0700 | [diff] [blame] | 3152 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3153 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3154 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 3155 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 3156 | _mesa_DeleteFramebuffers(GLsizei n, const GLuint *framebuffers) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3157 | { |
| 3158 | GLint i; |
| 3159 | GET_CURRENT_CONTEXT(ctx); |
| 3160 | |
Eduardo Lima Mitev | f77a473 | 2014-12-11 23:34:17 +0100 | [diff] [blame] | 3161 | if (n < 0) { |
| 3162 | _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteFramebuffers(n < 0)"); |
| 3163 | return; |
| 3164 | } |
| 3165 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 3166 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3167 | |
| 3168 | for (i = 0; i < n; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 3169 | if (framebuffers[i] > 0) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3170 | struct gl_framebuffer *fb; |
| 3171 | fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]); |
| 3172 | if (fb) { |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 3173 | assert(fb == &DummyFramebuffer || fb->Name == framebuffers[i]); |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 3174 | |
| 3175 | /* check if deleting currently bound framebuffer object */ |
Ian Romanick | 764be9f | 2013-11-13 14:00:06 -0800 | [diff] [blame] | 3176 | if (fb == ctx->DrawBuffer) { |
| 3177 | /* bind default */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 3178 | assert(fb->RefCount >= 2); |
Ian Romanick | 764be9f | 2013-11-13 14:00:06 -0800 | [diff] [blame] | 3179 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); |
| 3180 | } |
| 3181 | if (fb == ctx->ReadBuffer) { |
| 3182 | /* bind default */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 3183 | assert(fb->RefCount >= 2); |
Ian Romanick | 764be9f | 2013-11-13 14:00:06 -0800 | [diff] [blame] | 3184 | _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, 0); |
| 3185 | } |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 3186 | |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3187 | /* remove from hash table immediately, to free the ID */ |
| 3188 | _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3189 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 3190 | if (fb != &DummyFramebuffer) { |
| 3191 | /* But the object will not be freed until it's no longer |
| 3192 | * bound in any context. |
| 3193 | */ |
Brian Paul | d522944 | 2009-02-09 08:30:55 -0700 | [diff] [blame] | 3194 | _mesa_reference_framebuffer(&fb, NULL); |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3195 | } |
| 3196 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3197 | } |
| 3198 | } |
| 3199 | } |
| 3200 | |
| 3201 | |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 3202 | /** |
| 3203 | * This is the implementation for glGenFramebuffers and glCreateFramebuffers. |
| 3204 | * It is not exposed to the rest of Mesa to encourage the use of |
| 3205 | * nameless buffers in driver internals. |
| 3206 | */ |
| 3207 | static void |
| 3208 | create_framebuffers(GLsizei n, GLuint *framebuffers, bool dsa) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3209 | { |
| 3210 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3211 | GLint i; |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 3212 | struct gl_framebuffer *fb; |
| 3213 | |
| 3214 | const char *func = dsa ? "glCreateFramebuffers" : "glGenFramebuffers"; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3215 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3216 | if (n < 0) { |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 3217 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3218 | return; |
| 3219 | } |
| 3220 | |
| 3221 | if (!framebuffers) |
| 3222 | return; |
| 3223 | |
Matt Turner | 015f220 | 2015-07-30 14:31:04 -0700 | [diff] [blame] | 3224 | _mesa_HashLockMutex(ctx->Shared->FrameBuffers); |
| 3225 | |
Pierre-Eric Pelloux-Prayer | a56849d | 2020-08-17 15:12:03 +0200 | [diff] [blame] | 3226 | _mesa_HashFindFreeKeys(ctx->Shared->FrameBuffers, framebuffers, n); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3227 | |
| 3228 | for (i = 0; i < n; i++) { |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 3229 | if (dsa) { |
| 3230 | fb = ctx->Driver.NewFramebuffer(ctx, framebuffers[i]); |
| 3231 | if (!fb) { |
Matt Turner | bdc9c20 | 2016-05-22 07:00:34 -0700 | [diff] [blame] | 3232 | _mesa_HashUnlockMutex(ctx->Shared->FrameBuffers); |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 3233 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); |
| 3234 | return; |
| 3235 | } |
| 3236 | } |
| 3237 | else |
| 3238 | fb = &DummyFramebuffer; |
| 3239 | |
Pierre-Eric Pelloux-Prayer | a56849d | 2020-08-17 15:12:03 +0200 | [diff] [blame] | 3240 | _mesa_HashInsertLocked(ctx->Shared->FrameBuffers, framebuffers[i], |
| 3241 | fb, true); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3242 | } |
Matt Turner | 015f220 | 2015-07-30 14:31:04 -0700 | [diff] [blame] | 3243 | |
| 3244 | _mesa_HashUnlockMutex(ctx->Shared->FrameBuffers); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 3248 | void GLAPIENTRY |
| 3249 | _mesa_GenFramebuffers(GLsizei n, GLuint *framebuffers) |
| 3250 | { |
| 3251 | create_framebuffers(n, framebuffers, false); |
| 3252 | } |
| 3253 | |
| 3254 | |
| 3255 | void GLAPIENTRY |
| 3256 | _mesa_CreateFramebuffers(GLsizei n, GLuint *framebuffers) |
| 3257 | { |
| 3258 | create_framebuffers(n, framebuffers, true); |
| 3259 | } |
| 3260 | |
| 3261 | |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 3262 | GLenum |
| 3263 | _mesa_check_framebuffer_status(struct gl_context *ctx, |
| 3264 | struct gl_framebuffer *buffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3265 | { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 3266 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3267 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 3268 | if (_mesa_is_winsys_fbo(buffer)) { |
Matt Turner | 8dd15e6 | 2013-07-26 16:36:19 -0700 | [diff] [blame] | 3269 | /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */ |
| 3270 | if (buffer != &IncompleteFramebuffer) { |
| 3271 | return GL_FRAMEBUFFER_COMPLETE_EXT; |
| 3272 | } else { |
| 3273 | return GL_FRAMEBUFFER_UNDEFINED; |
| 3274 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 3277 | /* No need to flush here */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 3278 | |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 3279 | if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) { |
| 3280 | _mesa_test_framebuffer_completeness(ctx, buffer); |
| 3281 | } |
| 3282 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3283 | return buffer->_Status; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3284 | } |
| 3285 | |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 3286 | |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 3287 | GLenum GLAPIENTRY |
Samuel Pitoiset | 78d3510 | 2017-06-26 14:16:41 +0200 | [diff] [blame] | 3288 | _mesa_CheckFramebufferStatus_no_error(GLenum target) |
| 3289 | { |
| 3290 | GET_CURRENT_CONTEXT(ctx); |
| 3291 | |
| 3292 | struct gl_framebuffer *fb = get_framebuffer_target(ctx, target); |
| 3293 | return _mesa_check_framebuffer_status(ctx, fb); |
| 3294 | } |
| 3295 | |
| 3296 | |
| 3297 | GLenum GLAPIENTRY |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 3298 | _mesa_CheckFramebufferStatus(GLenum target) |
| 3299 | { |
| 3300 | struct gl_framebuffer *fb; |
| 3301 | GET_CURRENT_CONTEXT(ctx); |
| 3302 | |
| 3303 | if (MESA_VERBOSE & VERBOSE_API) |
| 3304 | _mesa_debug(ctx, "glCheckFramebufferStatus(%s)\n", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3305 | _mesa_enum_to_string(target)); |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 3306 | |
| 3307 | fb = get_framebuffer_target(ctx, target); |
| 3308 | if (!fb) { |
| 3309 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3310 | "glCheckFramebufferStatus(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3311 | _mesa_enum_to_string(target)); |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 3312 | return 0; |
| 3313 | } |
| 3314 | |
| 3315 | return _mesa_check_framebuffer_status(ctx, fb); |
| 3316 | } |
| 3317 | |
| 3318 | |
| 3319 | GLenum GLAPIENTRY |
| 3320 | _mesa_CheckNamedFramebufferStatus(GLuint framebuffer, GLenum target) |
| 3321 | { |
| 3322 | struct gl_framebuffer *fb; |
| 3323 | GET_CURRENT_CONTEXT(ctx); |
| 3324 | |
| 3325 | /* Validate the target (for conformance's sake) and grab a reference to the |
| 3326 | * default framebuffer in case framebuffer = 0. |
| 3327 | * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec |
| 3328 | * (30.10.2014, PDF page 336) says: |
| 3329 | * "If framebuffer is zero, then the status of the default read or |
| 3330 | * draw framebuffer (as determined by target) is returned." |
| 3331 | */ |
| 3332 | switch (target) { |
| 3333 | case GL_DRAW_FRAMEBUFFER: |
| 3334 | case GL_FRAMEBUFFER: |
| 3335 | fb = ctx->WinSysDrawBuffer; |
| 3336 | break; |
| 3337 | case GL_READ_FRAMEBUFFER: |
| 3338 | fb = ctx->WinSysReadBuffer; |
| 3339 | break; |
| 3340 | default: |
| 3341 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3342 | "glCheckNamedFramebufferStatus(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3343 | _mesa_enum_to_string(target)); |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 3344 | return 0; |
| 3345 | } |
| 3346 | |
| 3347 | if (framebuffer) { |
| 3348 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 3349 | "glCheckNamedFramebufferStatus"); |
| 3350 | if (!fb) |
| 3351 | return 0; |
| 3352 | } |
| 3353 | |
| 3354 | return _mesa_check_framebuffer_status(ctx, fb); |
| 3355 | } |
| 3356 | |
| 3357 | |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 3358 | GLenum GLAPIENTRY |
| 3359 | _mesa_CheckNamedFramebufferStatusEXT(GLuint framebuffer, GLenum target) |
| 3360 | { |
| 3361 | struct gl_framebuffer *fb; |
| 3362 | GET_CURRENT_CONTEXT(ctx); |
| 3363 | |
| 3364 | switch (target) { |
| 3365 | case GL_DRAW_FRAMEBUFFER: |
| 3366 | case GL_FRAMEBUFFER: |
| 3367 | case GL_READ_FRAMEBUFFER: |
| 3368 | break; |
| 3369 | default: |
| 3370 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3371 | "glCheckNamedFramebufferStatusEXT(invalid target %s)", |
| 3372 | _mesa_enum_to_string(target)); |
| 3373 | return 0; |
| 3374 | } |
| 3375 | |
| 3376 | if (framebuffer == 0) { |
| 3377 | return _mesa_CheckNamedFramebufferStatus(0, target); |
| 3378 | } |
| 3379 | |
| 3380 | fb = _mesa_lookup_framebuffer_dsa(ctx, framebuffer, |
| 3381 | "glCheckNamedFramebufferStatusEXT"); |
| 3382 | if (!fb) |
| 3383 | return 0; |
| 3384 | |
| 3385 | return _mesa_check_framebuffer_status(ctx, fb); |
| 3386 | } |
| 3387 | |
| 3388 | |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3389 | /** |
| 3390 | * Replicate the src attachment point. Used by framebuffer_texture() when |
| 3391 | * the same texture is attached at GL_DEPTH_ATTACHMENT and |
| 3392 | * GL_STENCIL_ATTACHMENT. |
| 3393 | */ |
| 3394 | static void |
| 3395 | reuse_framebuffer_texture_attachment(struct gl_framebuffer *fb, |
| 3396 | gl_buffer_index dst, |
| 3397 | gl_buffer_index src) |
| 3398 | { |
| 3399 | struct gl_renderbuffer_attachment *dst_att = &fb->Attachment[dst]; |
| 3400 | struct gl_renderbuffer_attachment *src_att = &fb->Attachment[src]; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3401 | |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3402 | assert(src_att->Texture != NULL); |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 3403 | assert(src_att->Renderbuffer != NULL); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3404 | |
| 3405 | _mesa_reference_texobj(&dst_att->Texture, src_att->Texture); |
| 3406 | _mesa_reference_renderbuffer(&dst_att->Renderbuffer, src_att->Renderbuffer); |
| 3407 | dst_att->Type = src_att->Type; |
| 3408 | dst_att->Complete = src_att->Complete; |
| 3409 | dst_att->TextureLevel = src_att->TextureLevel; |
Nanley Chery | 63318d3 | 2016-11-15 16:42:23 -0800 | [diff] [blame] | 3410 | dst_att->CubeMapFace = src_att->CubeMapFace; |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3411 | dst_att->Zoffset = src_att->Zoffset; |
Dave Airlie | 35859d5 | 2016-02-29 17:16:10 +1000 | [diff] [blame] | 3412 | dst_att->Layered = src_att->Layered; |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3413 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3414 | |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 3415 | |
Timothy Arceri | 304058a | 2017-05-05 16:25:11 +1000 | [diff] [blame] | 3416 | static struct gl_texture_object * |
| 3417 | get_texture_for_framebuffer(struct gl_context *ctx, GLuint texture) |
| 3418 | { |
| 3419 | if (!texture) |
| 3420 | return NULL; |
| 3421 | |
| 3422 | return _mesa_lookup_texture(ctx, texture); |
| 3423 | } |
| 3424 | |
| 3425 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3426 | /** |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3427 | * Common code called by gl*FramebufferTexture*() to retrieve the correct |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3428 | * texture object pointer. |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3429 | * |
| 3430 | * \param texObj where the pointer to the texture object is returned. Note |
| 3431 | * that a successful call may return texObj = NULL. |
| 3432 | * |
| 3433 | * \return true if no errors, false if errors |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3434 | */ |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3435 | static bool |
Timothy Arceri | 304058a | 2017-05-05 16:25:11 +1000 | [diff] [blame] | 3436 | get_texture_for_framebuffer_err(struct gl_context *ctx, GLuint texture, |
| 3437 | bool layered, const char *caller, |
| 3438 | struct gl_texture_object **texObj) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3439 | { |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3440 | *texObj = NULL; /* This will get returned if texture = 0. */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3441 | |
Laura Ekstrand | a9f73f7 | 2015-03-02 13:41:13 -0800 | [diff] [blame] | 3442 | if (!texture) |
| 3443 | return true; |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3444 | |
Laura Ekstrand | a9f73f7 | 2015-03-02 13:41:13 -0800 | [diff] [blame] | 3445 | *texObj = _mesa_lookup_texture(ctx, texture); |
| 3446 | if (*texObj == NULL || (*texObj)->Target == 0) { |
| 3447 | /* Can't render to a non-existent texture object. |
| 3448 | * |
| 3449 | * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and |
| 3450 | * Managing Framebuffer Objects specifies a different error |
| 3451 | * depending upon the calling function (PDF pages 325-328). |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3452 | * *FramebufferTexture (where layered = GL_TRUE) throws invalid |
Laura Ekstrand | a9f73f7 | 2015-03-02 13:41:13 -0800 | [diff] [blame] | 3453 | * value, while the other commands throw invalid operation (where |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3454 | * layered = GL_FALSE). |
Laura Ekstrand | a9f73f7 | 2015-03-02 13:41:13 -0800 | [diff] [blame] | 3455 | */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3456 | const GLenum error = layered ? GL_INVALID_VALUE : |
Laura Ekstrand | a9f73f7 | 2015-03-02 13:41:13 -0800 | [diff] [blame] | 3457 | GL_INVALID_OPERATION; |
| 3458 | _mesa_error(ctx, error, |
| 3459 | "%s(non-existent texture %u)", caller, texture); |
| 3460 | return false; |
| 3461 | } |
| 3462 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3463 | return true; |
| 3464 | } |
| 3465 | |
| 3466 | |
| 3467 | /** |
| 3468 | * Common code called by gl*FramebufferTexture() to verify the texture target |
| 3469 | * and decide whether or not the attachment should truly be considered |
| 3470 | * layered. |
| 3471 | * |
| 3472 | * \param layered true if attachment should be considered layered, false if |
| 3473 | * not |
| 3474 | * |
| 3475 | * \return true if no errors, false if errors |
| 3476 | */ |
| 3477 | static bool |
| 3478 | check_layered_texture_target(struct gl_context *ctx, GLenum target, |
| 3479 | const char *caller, GLboolean *layered) |
| 3480 | { |
| 3481 | *layered = GL_TRUE; |
| 3482 | |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 3483 | switch (target) { |
| 3484 | case GL_TEXTURE_3D: |
| 3485 | case GL_TEXTURE_1D_ARRAY_EXT: |
| 3486 | case GL_TEXTURE_2D_ARRAY_EXT: |
| 3487 | case GL_TEXTURE_CUBE_MAP: |
| 3488 | case GL_TEXTURE_CUBE_MAP_ARRAY: |
| 3489 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: |
| 3490 | return true; |
| 3491 | case GL_TEXTURE_1D: |
| 3492 | case GL_TEXTURE_2D: |
| 3493 | case GL_TEXTURE_RECTANGLE: |
| 3494 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 3495 | /* These texture types are valid to pass to |
| 3496 | * glFramebufferTexture(), but since they aren't layered, it |
| 3497 | * is equivalent to calling glFramebufferTexture{1D,2D}(). |
| 3498 | */ |
| 3499 | *layered = GL_FALSE; |
| 3500 | return true; |
| 3501 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3502 | |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 3503 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3504 | "%s(invalid texture target %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3505 | _mesa_enum_to_string(target)); |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 3506 | return false; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | |
| 3510 | /** |
| 3511 | * Common code called by gl*FramebufferTextureLayer() to verify the texture |
| 3512 | * target. |
| 3513 | * |
| 3514 | * \return true if no errors, false if errors |
| 3515 | */ |
| 3516 | static bool |
| 3517 | check_texture_target(struct gl_context *ctx, GLenum target, |
| 3518 | const char *caller) |
| 3519 | { |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3520 | /* We're being called by glFramebufferTextureLayer(). |
| 3521 | * The only legal texture types for that function are 3D, |
| 3522 | * cube-map, and 1D/2D/cube-map array textures. |
Ian Romanick | 832ea23 | 2015-05-20 17:19:29 -0700 | [diff] [blame] | 3523 | * |
| 3524 | * We don't need to check for GL_ARB_texture_cube_map_array because the |
| 3525 | * application wouldn't have been able to create a texture with a |
| 3526 | * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled. |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 3527 | */ |
| 3528 | switch (target) { |
| 3529 | case GL_TEXTURE_3D: |
| 3530 | case GL_TEXTURE_1D_ARRAY: |
| 3531 | case GL_TEXTURE_2D_ARRAY: |
| 3532 | case GL_TEXTURE_CUBE_MAP_ARRAY: |
| 3533 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: |
| 3534 | return true; |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3535 | case GL_TEXTURE_CUBE_MAP: |
Timothy Arceri | 781a789 | 2018-08-29 12:40:12 +1000 | [diff] [blame] | 3536 | /* GL_TEXTURE_CUBE_MAP is only allowed by OpenGL 4.5 here, which |
| 3537 | * includes the DSA API. |
| 3538 | * |
| 3539 | * Because DSA is only enabled for GL 3.1+ and this can be called |
| 3540 | * from _mesa_FramebufferTextureLayer in compatibility profile, |
| 3541 | * we need to check the version. |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3542 | */ |
Timothy Arceri | 781a789 | 2018-08-29 12:40:12 +1000 | [diff] [blame] | 3543 | return _mesa_is_desktop_gl(ctx) && ctx->Version >= 31; |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 3544 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3545 | |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 3546 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3547 | "%s(invalid texture target %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3548 | _mesa_enum_to_string(target)); |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 3549 | return false; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | |
| 3553 | /** |
| 3554 | * Common code called by glFramebufferTexture*D() to verify the texture |
| 3555 | * target. |
| 3556 | * |
| 3557 | * \return true if no errors, false if errors |
| 3558 | */ |
| 3559 | static bool |
| 3560 | check_textarget(struct gl_context *ctx, int dims, GLenum target, |
| 3561 | GLenum textarget, const char *caller) |
| 3562 | { |
| 3563 | bool err = false; |
| 3564 | |
Kenneth Graunke | aecdb21 | 2016-10-03 16:37:25 -0700 | [diff] [blame] | 3565 | switch (textarget) { |
| 3566 | case GL_TEXTURE_1D: |
| 3567 | err = dims != 1; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3568 | break; |
Kenneth Graunke | aecdb21 | 2016-10-03 16:37:25 -0700 | [diff] [blame] | 3569 | case GL_TEXTURE_1D_ARRAY: |
| 3570 | err = dims != 1 || !ctx->Extensions.EXT_texture_array; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3571 | break; |
Kenneth Graunke | aecdb21 | 2016-10-03 16:37:25 -0700 | [diff] [blame] | 3572 | case GL_TEXTURE_2D: |
| 3573 | err = dims != 2; |
| 3574 | break; |
| 3575 | case GL_TEXTURE_2D_ARRAY: |
| 3576 | err = dims != 2 || !ctx->Extensions.EXT_texture_array || |
| 3577 | (_mesa_is_gles(ctx) && ctx->Version < 30); |
| 3578 | break; |
| 3579 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 3580 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: |
| 3581 | err = dims != 2 || |
| 3582 | !ctx->Extensions.ARB_texture_multisample || |
| 3583 | (_mesa_is_gles(ctx) && ctx->Version < 31); |
| 3584 | break; |
| 3585 | case GL_TEXTURE_RECTANGLE: |
| 3586 | err = dims != 2 || _mesa_is_gles(ctx) || |
| 3587 | !ctx->Extensions.NV_texture_rectangle; |
| 3588 | break; |
| 3589 | case GL_TEXTURE_CUBE_MAP: |
| 3590 | case GL_TEXTURE_CUBE_MAP_ARRAY: |
| 3591 | err = true; |
| 3592 | break; |
| 3593 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 3594 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 3595 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 3596 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 3597 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 3598 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 3599 | err = dims != 2 || !ctx->Extensions.ARB_texture_cube_map; |
| 3600 | break; |
| 3601 | case GL_TEXTURE_3D: |
| 3602 | err = dims != 3; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3603 | break; |
| 3604 | default: |
Kenneth Graunke | a40640f | 2016-10-03 16:37:26 -0700 | [diff] [blame] | 3605 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3606 | "%s(unknown textarget 0x%x)", caller, textarget); |
| 3607 | return false; |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3608 | } |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3609 | |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3610 | if (err) { |
| 3611 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3612 | "%s(invalid textarget %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3613 | caller, _mesa_enum_to_string(textarget)); |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3614 | return false; |
| 3615 | } |
| 3616 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3617 | /* Make sure textarget is consistent with the texture's type */ |
| 3618 | err = (target == GL_TEXTURE_CUBE_MAP) ? |
| 3619 | !_mesa_is_cube_face(textarget): (target != textarget); |
| 3620 | |
| 3621 | if (err) { |
| 3622 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3623 | "%s(mismatched texture target)", caller); |
| 3624 | return false; |
| 3625 | } |
| 3626 | |
| 3627 | return true; |
| 3628 | } |
| 3629 | |
| 3630 | |
| 3631 | /** |
| 3632 | * Common code called by gl*FramebufferTextureLayer() and |
| 3633 | * glFramebufferTexture3D() to validate the layer. |
| 3634 | * |
| 3635 | * \return true if no errors, false if errors |
| 3636 | */ |
| 3637 | static bool |
| 3638 | check_layer(struct gl_context *ctx, GLenum target, GLint layer, |
| 3639 | const char *caller) |
| 3640 | { |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3641 | /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile) |
| 3642 | * spec says: |
| 3643 | * |
| 3644 | * "An INVALID_VALUE error is generated if texture is non-zero |
| 3645 | * and layer is negative." |
| 3646 | */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3647 | if (layer < 0) { |
Brian Paul | 08ba4a1 | 2017-12-05 09:57:23 -0700 | [diff] [blame] | 3648 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(layer %d < 0)", caller, layer); |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3649 | return false; |
| 3650 | } |
| 3651 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3652 | if (target == GL_TEXTURE_3D) { |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3653 | const GLuint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3654 | if (layer >= maxSize) { |
Fredrik Höglund | 8ba7ad8 | 2015-05-09 15:31:45 +0200 | [diff] [blame] | 3655 | _mesa_error(ctx, GL_INVALID_VALUE, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3656 | "%s(invalid layer %u)", caller, layer); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3657 | return false; |
Fredrik Höglund | 8ba7ad8 | 2015-05-09 15:31:45 +0200 | [diff] [blame] | 3658 | } |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3659 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3660 | else if ((target == GL_TEXTURE_1D_ARRAY) || |
| 3661 | (target == GL_TEXTURE_2D_ARRAY) || |
| 3662 | (target == GL_TEXTURE_CUBE_MAP_ARRAY) || |
| 3663 | (target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)) { |
| 3664 | if (layer >= ctx->Const.MaxArrayTextureLayers) { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3665 | _mesa_error(ctx, GL_INVALID_VALUE, |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3666 | "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)", |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3667 | caller, layer); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3668 | return false; |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3669 | } |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3670 | } |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3671 | else if (target == GL_TEXTURE_CUBE_MAP) { |
| 3672 | if (layer >= 6) { |
| 3673 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 3674 | "%s(layer %u >= 6)", caller, layer); |
| 3675 | return false; |
| 3676 | } |
| 3677 | } |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3678 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3679 | return true; |
| 3680 | } |
| 3681 | |
| 3682 | |
| 3683 | /** |
| 3684 | * Common code called by all gl*FramebufferTexture*() entry points to verify |
| 3685 | * the level. |
| 3686 | * |
| 3687 | * \return true if no errors, false if errors |
| 3688 | */ |
| 3689 | static bool |
Kenneth Graunke | 37e128b | 2017-10-07 11:19:42 -0700 | [diff] [blame] | 3690 | check_level(struct gl_context *ctx, struct gl_texture_object *texObj, |
| 3691 | GLenum target, GLint level, const char *caller) |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3692 | { |
Kenneth Graunke | 37e128b | 2017-10-07 11:19:42 -0700 | [diff] [blame] | 3693 | /* Section 9.2.8 of the OpenGL 4.6 specification says: |
| 3694 | * |
| 3695 | * "If texture refers to an immutable-format texture, level must be |
| 3696 | * greater than or equal to zero and smaller than the value of |
| 3697 | * TEXTURE_VIEW_NUM_LEVELS for texture." |
| 3698 | */ |
| 3699 | const int max_levels = texObj->Immutable ? texObj->ImmutableLevels : |
| 3700 | _mesa_max_texture_levels(ctx, target); |
| 3701 | |
| 3702 | if (level < 0 || level >= max_levels) { |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3703 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 3704 | "%s(invalid level %d)", caller, level); |
| 3705 | return false; |
| 3706 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3707 | |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3708 | return true; |
| 3709 | } |
| 3710 | |
| 3711 | |
Timothy Arceri | d90ced4 | 2017-05-05 16:46:03 +1000 | [diff] [blame] | 3712 | struct gl_renderbuffer_attachment * |
| 3713 | _mesa_get_and_validate_attachment(struct gl_context *ctx, |
| 3714 | struct gl_framebuffer *fb, |
| 3715 | GLenum attachment, const char *caller) |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3716 | { |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3717 | /* The window-system framebuffer object is immutable */ |
| 3718 | if (_mesa_is_winsys_fbo(fb)) { |
| 3719 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(window-system framebuffer)", |
| 3720 | caller); |
Timothy Arceri | d90ced4 | 2017-05-05 16:46:03 +1000 | [diff] [blame] | 3721 | return NULL; |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | /* Not a hash lookup, so we can afford to get the attachment here. */ |
Timothy Arceri | d90ced4 | 2017-05-05 16:46:03 +1000 | [diff] [blame] | 3725 | bool is_color_attachment; |
| 3726 | struct gl_renderbuffer_attachment *att = |
| 3727 | get_attachment(ctx, fb, attachment, &is_color_attachment); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3728 | if (att == NULL) { |
Ilia Mirkin | 62b8f49 | 2017-01-24 00:26:29 -0500 | [diff] [blame] | 3729 | if (is_color_attachment) { |
| 3730 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3731 | "%s(invalid color attachment %s)", caller, |
| 3732 | _mesa_enum_to_string(attachment)); |
| 3733 | } else { |
| 3734 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3735 | "%s(invalid attachment %s)", caller, |
| 3736 | _mesa_enum_to_string(attachment)); |
| 3737 | } |
Timothy Arceri | d90ced4 | 2017-05-05 16:46:03 +1000 | [diff] [blame] | 3738 | return NULL; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3739 | } |
| 3740 | |
Timothy Arceri | d90ced4 | 2017-05-05 16:46:03 +1000 | [diff] [blame] | 3741 | return att; |
| 3742 | } |
| 3743 | |
| 3744 | |
| 3745 | void |
| 3746 | _mesa_framebuffer_texture(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 3747 | GLenum attachment, |
Timothy Arceri | 69ca1ef | 2017-05-05 17:00:34 +1000 | [diff] [blame] | 3748 | struct gl_renderbuffer_attachment *att, |
Timothy Arceri | d90ced4 | 2017-05-05 16:46:03 +1000 | [diff] [blame] | 3749 | struct gl_texture_object *texObj, GLenum textarget, |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 3750 | GLint level, GLsizei samples, |
| 3751 | GLuint layer, GLboolean layered) |
Timothy Arceri | d90ced4 | 2017-05-05 16:46:03 +1000 | [diff] [blame] | 3752 | { |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 3753 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 3754 | |
Timothy Arceri | f0857fe | 2017-10-16 11:59:31 +1100 | [diff] [blame] | 3755 | simple_mtx_lock(&fb->Mutex); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3756 | if (texObj) { |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3757 | if (attachment == GL_DEPTH_ATTACHMENT && |
Paul Berry | b9819a0 | 2012-04-13 21:50:08 -0700 | [diff] [blame] | 3758 | texObj == fb->Attachment[BUFFER_STENCIL].Texture && |
| 3759 | level == fb->Attachment[BUFFER_STENCIL].TextureLevel && |
| 3760 | _mesa_tex_target_to_face(textarget) == |
| 3761 | fb->Attachment[BUFFER_STENCIL].CubeMapFace && |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 3762 | samples == fb->Attachment[BUFFER_STENCIL].NumSamples && |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3763 | layer == fb->Attachment[BUFFER_STENCIL].Zoffset) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3764 | /* The texture object is already attached to the stencil attachment |
| 3765 | * point. Don't create a new renderbuffer; just reuse the stencil |
| 3766 | * attachment's. This is required to prevent a GL error in |
| 3767 | * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL). |
| 3768 | */ |
| 3769 | reuse_framebuffer_texture_attachment(fb, BUFFER_DEPTH, |
| 3770 | BUFFER_STENCIL); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3771 | } else if (attachment == GL_STENCIL_ATTACHMENT && |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3772 | texObj == fb->Attachment[BUFFER_DEPTH].Texture && |
Paul Berry | b9819a0 | 2012-04-13 21:50:08 -0700 | [diff] [blame] | 3773 | level == fb->Attachment[BUFFER_DEPTH].TextureLevel && |
| 3774 | _mesa_tex_target_to_face(textarget) == |
| 3775 | fb->Attachment[BUFFER_DEPTH].CubeMapFace && |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 3776 | samples == fb->Attachment[BUFFER_DEPTH].NumSamples && |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3777 | layer == fb->Attachment[BUFFER_DEPTH].Zoffset) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3778 | /* As above, but with depth and stencil transposed. */ |
| 3779 | reuse_framebuffer_texture_attachment(fb, BUFFER_STENCIL, |
| 3780 | BUFFER_DEPTH); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3781 | } else { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3782 | set_texture_attachment(ctx, fb, att, texObj, textarget, |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 3783 | level, samples, layer, layered); |
Laura Ekstrand | 8f78c68 | 2015-01-27 14:11:13 -0800 | [diff] [blame] | 3784 | |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3785 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 3786 | /* Above we created a new renderbuffer and attached it to the |
| 3787 | * depth attachment point. Now attach it to the stencil attachment |
| 3788 | * point too. |
| 3789 | */ |
| 3790 | assert(att == &fb->Attachment[BUFFER_DEPTH]); |
| 3791 | reuse_framebuffer_texture_attachment(fb,BUFFER_STENCIL, |
| 3792 | BUFFER_DEPTH); |
| 3793 | } |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3794 | } |
| 3795 | |
Brian Paul | 2897cee | 2009-01-29 09:20:18 -0700 | [diff] [blame] | 3796 | /* Set the render-to-texture flag. We'll check this flag in |
| 3797 | * glTexImage() and friends to determine if we need to revalidate |
| 3798 | * any FBOs that might be rendering into this texture. |
| 3799 | * This flag never gets cleared since it's non-trivial to determine |
| 3800 | * when all FBOs might be done rendering to this texture. That's OK |
| 3801 | * though since it's uncommon to render to a texture then repeatedly |
| 3802 | * call glTexImage() to change images in the texture. |
| 3803 | */ |
| 3804 | texObj->_RenderToTexture = GL_TRUE; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3805 | } |
| 3806 | else { |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 3807 | remove_attachment(ctx, att); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3808 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3809 | assert(att == &fb->Attachment[BUFFER_DEPTH]); |
| 3810 | remove_attachment(ctx, &fb->Attachment[BUFFER_STENCIL]); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3811 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3812 | } |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 3813 | |
| 3814 | invalidate_framebuffer(fb); |
| 3815 | |
Timothy Arceri | f0857fe | 2017-10-16 11:59:31 +1100 | [diff] [blame] | 3816 | simple_mtx_unlock(&fb->Mutex); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3820 | static void |
Timothy Arceri | 20cabc2 | 2017-05-08 10:59:15 +1000 | [diff] [blame] | 3821 | framebuffer_texture_with_dims_no_error(GLenum target, GLenum attachment, |
| 3822 | GLenum textarget, GLuint texture, |
| 3823 | GLint level, GLint layer) |
| 3824 | { |
| 3825 | GET_CURRENT_CONTEXT(ctx); |
| 3826 | |
| 3827 | /* Get the framebuffer object */ |
| 3828 | struct gl_framebuffer *fb = get_framebuffer_target(ctx, target); |
| 3829 | |
| 3830 | /* Get the texture object */ |
| 3831 | struct gl_texture_object *texObj = |
| 3832 | get_texture_for_framebuffer(ctx, texture); |
| 3833 | |
| 3834 | struct gl_renderbuffer_attachment *att = |
| 3835 | get_attachment(ctx, fb, attachment, NULL); |
| 3836 | |
| 3837 | _mesa_framebuffer_texture(ctx, fb, attachment, att, texObj, textarget, |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 3838 | level, 0, layer, GL_FALSE); |
Timothy Arceri | 20cabc2 | 2017-05-08 10:59:15 +1000 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | |
| 3842 | static void |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 3843 | framebuffer_texture_with_dims(int dims, GLenum target, GLuint framebuffer, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3844 | GLenum attachment, GLenum textarget, |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 3845 | GLuint texture, GLint level, GLsizei samples, |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 3846 | GLint layer, const char *caller, bool dsa) |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3847 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3848 | GET_CURRENT_CONTEXT(ctx); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3849 | struct gl_framebuffer *fb; |
| 3850 | struct gl_texture_object *texObj; |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3851 | |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3852 | /* Get the framebuffer object */ |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 3853 | if (dsa) { |
| 3854 | fb = _mesa_lookup_framebuffer_dsa(ctx, framebuffer, caller); |
| 3855 | } else { |
| 3856 | fb = get_framebuffer_target(ctx, target); |
| 3857 | } |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3858 | if (!fb) { |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3859 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid target %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3860 | _mesa_enum_to_string(target)); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3861 | return; |
| 3862 | } |
| 3863 | |
| 3864 | /* Get the texture object */ |
Timothy Arceri | 304058a | 2017-05-05 16:25:11 +1000 | [diff] [blame] | 3865 | if (!get_texture_for_framebuffer_err(ctx, texture, false, caller, &texObj)) |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3866 | return; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3867 | |
| 3868 | if (texObj) { |
| 3869 | if (!check_textarget(ctx, dims, texObj->Target, textarget, caller)) |
| 3870 | return; |
| 3871 | |
| 3872 | if ((dims == 3) && !check_layer(ctx, texObj->Target, layer, caller)) |
| 3873 | return; |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3874 | |
Kenneth Graunke | 37e128b | 2017-10-07 11:19:42 -0700 | [diff] [blame] | 3875 | if (!check_level(ctx, texObj, textarget, level, caller)) |
Marek Olšák | 04a7806 | 2016-05-27 21:40:19 +0200 | [diff] [blame] | 3876 | return; |
| 3877 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3878 | |
Timothy Arceri | 69ca1ef | 2017-05-05 17:00:34 +1000 | [diff] [blame] | 3879 | struct gl_renderbuffer_attachment *att = |
| 3880 | _mesa_get_and_validate_attachment(ctx, fb, attachment, caller); |
| 3881 | if (!att) |
| 3882 | return; |
| 3883 | |
| 3884 | _mesa_framebuffer_texture(ctx, fb, attachment, att, texObj, textarget, |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 3885 | level, samples, layer, GL_FALSE); |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | |
| 3889 | void GLAPIENTRY |
Timothy Arceri | 276166c | 2017-05-08 11:10:58 +1000 | [diff] [blame] | 3890 | _mesa_FramebufferTexture1D_no_error(GLenum target, GLenum attachment, |
| 3891 | GLenum textarget, GLuint texture, |
| 3892 | GLint level) |
| 3893 | { |
| 3894 | framebuffer_texture_with_dims_no_error(target, attachment, textarget, |
| 3895 | texture, level, 0); |
| 3896 | } |
| 3897 | |
| 3898 | |
| 3899 | void GLAPIENTRY |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3900 | _mesa_FramebufferTexture1D(GLenum target, GLenum attachment, |
| 3901 | GLenum textarget, GLuint texture, GLint level) |
| 3902 | { |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 3903 | framebuffer_texture_with_dims(1, target, 0, attachment, textarget, texture, |
| 3904 | level, 0, 0, "glFramebufferTexture1D", false); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 3908 | void GLAPIENTRY |
Timothy Arceri | 276166c | 2017-05-08 11:10:58 +1000 | [diff] [blame] | 3909 | _mesa_FramebufferTexture2D_no_error(GLenum target, GLenum attachment, |
| 3910 | GLenum textarget, GLuint texture, |
| 3911 | GLint level) |
| 3912 | { |
| 3913 | framebuffer_texture_with_dims_no_error(target, attachment, textarget, |
| 3914 | texture, level, 0); |
| 3915 | } |
| 3916 | |
| 3917 | |
| 3918 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 3919 | _mesa_FramebufferTexture2D(GLenum target, GLenum attachment, |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3920 | GLenum textarget, GLuint texture, GLint level) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3921 | { |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 3922 | framebuffer_texture_with_dims(2, target, 0, attachment, textarget, texture, |
| 3923 | level, 0, 0, "glFramebufferTexture2D", false); |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | |
| 3927 | void GLAPIENTRY |
| 3928 | _mesa_FramebufferTexture2DMultisampleEXT(GLenum target, GLenum attachment, |
| 3929 | GLenum textarget, GLuint texture, |
| 3930 | GLint level, GLsizei samples) |
| 3931 | { |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 3932 | framebuffer_texture_with_dims(2, target, 0, attachment, textarget, texture, |
| 3933 | level, samples, 0, |
| 3934 | "glFramebufferTexture2DMultisampleEXT", |
| 3935 | false); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 3939 | void GLAPIENTRY |
Timothy Arceri | 276166c | 2017-05-08 11:10:58 +1000 | [diff] [blame] | 3940 | _mesa_FramebufferTexture3D_no_error(GLenum target, GLenum attachment, |
| 3941 | GLenum textarget, GLuint texture, |
| 3942 | GLint level, GLint layer) |
| 3943 | { |
| 3944 | framebuffer_texture_with_dims_no_error(target, attachment, textarget, |
| 3945 | texture, level, layer); |
| 3946 | } |
| 3947 | |
| 3948 | |
| 3949 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 3950 | _mesa_FramebufferTexture3D(GLenum target, GLenum attachment, |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3951 | GLenum textarget, GLuint texture, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3952 | GLint level, GLint layer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3953 | { |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 3954 | framebuffer_texture_with_dims(3, target, 0, attachment, textarget, texture, |
| 3955 | level, 0, layer, "glFramebufferTexture3D", false); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | |
Timothy Arceri | 01081c6 | 2017-05-10 11:22:47 +1000 | [diff] [blame] | 3959 | static ALWAYS_INLINE void |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 3960 | frame_buffer_texture(GLuint framebuffer, GLenum target, |
| 3961 | GLenum attachment, GLuint texture, |
| 3962 | GLint level, GLint layer, const char *func, |
| 3963 | bool dsa, bool no_error, bool check_layered) |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 3964 | { |
| 3965 | GET_CURRENT_CONTEXT(ctx); |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 3966 | GLboolean layered = GL_FALSE; |
| 3967 | |
| 3968 | if (!no_error && check_layered) { |
| 3969 | if (!_mesa_has_geometry_shaders(ctx)) { |
| 3970 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3971 | "unsupported function (%s) called", func); |
| 3972 | return; |
| 3973 | } |
| 3974 | } |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 3975 | |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3976 | /* Get the framebuffer object */ |
Timothy Arceri | 01081c6 | 2017-05-10 11:22:47 +1000 | [diff] [blame] | 3977 | struct gl_framebuffer *fb; |
Timothy Arceri | f6198e9 | 2017-05-11 15:43:44 +1000 | [diff] [blame] | 3978 | if (no_error) { |
| 3979 | if (dsa) { |
| 3980 | fb = _mesa_lookup_framebuffer(ctx, framebuffer); |
| 3981 | } else { |
| 3982 | fb = get_framebuffer_target(ctx, target); |
| 3983 | } |
Timothy Arceri | 01081c6 | 2017-05-10 11:22:47 +1000 | [diff] [blame] | 3984 | } else { |
Timothy Arceri | f6198e9 | 2017-05-11 15:43:44 +1000 | [diff] [blame] | 3985 | if (dsa) { |
| 3986 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, func); |
| 3987 | if (!fb) |
| 3988 | return; |
| 3989 | } else { |
| 3990 | fb = get_framebuffer_target(ctx, target); |
| 3991 | if (!fb) { |
| 3992 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid target %s)", |
| 3993 | func, _mesa_enum_to_string(target)); |
| 3994 | return; |
| 3995 | } |
Timothy Arceri | 01081c6 | 2017-05-10 11:22:47 +1000 | [diff] [blame] | 3996 | } |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3997 | } |
| 3998 | |
Timothy Arceri | f6198e9 | 2017-05-11 15:43:44 +1000 | [diff] [blame] | 3999 | /* Get the texture object and framebuffer attachment*/ |
| 4000 | struct gl_renderbuffer_attachment *att; |
Timothy Arceri | 01081c6 | 2017-05-10 11:22:47 +1000 | [diff] [blame] | 4001 | struct gl_texture_object *texObj; |
Timothy Arceri | f6198e9 | 2017-05-11 15:43:44 +1000 | [diff] [blame] | 4002 | if (no_error) { |
| 4003 | texObj = get_texture_for_framebuffer(ctx, texture); |
| 4004 | att = get_attachment(ctx, fb, attachment, NULL); |
| 4005 | } else { |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4006 | if (!get_texture_for_framebuffer_err(ctx, texture, check_layered, func, |
Timothy Arceri | f6198e9 | 2017-05-11 15:43:44 +1000 | [diff] [blame] | 4007 | &texObj)) |
| 4008 | return; |
| 4009 | |
| 4010 | att = _mesa_get_and_validate_attachment(ctx, fb, attachment, func); |
| 4011 | if (!att) |
| 4012 | return; |
| 4013 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 4014 | |
Timothy Arceri | 01081c6 | 2017-05-10 11:22:47 +1000 | [diff] [blame] | 4015 | GLenum textarget = 0; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 4016 | if (texObj) { |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4017 | if (check_layered) { |
| 4018 | /* We do this regardless of no_error because this sets layered */ |
| 4019 | if (!check_layered_texture_target(ctx, texObj->Target, func, |
| 4020 | &layered)) |
Timothy Arceri | f6198e9 | 2017-05-11 15:43:44 +1000 | [diff] [blame] | 4021 | return; |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4022 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 4023 | |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4024 | if (!no_error) { |
| 4025 | if (!check_layered) { |
| 4026 | if (!check_texture_target(ctx, texObj->Target, func)) |
| 4027 | return; |
| 4028 | |
| 4029 | if (!check_layer(ctx, texObj->Target, layer, func)) |
| 4030 | return; |
| 4031 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 4032 | |
Kenneth Graunke | 37e128b | 2017-10-07 11:19:42 -0700 | [diff] [blame] | 4033 | if (!check_level(ctx, texObj, texObj->Target, level, func)) |
Timothy Arceri | f6198e9 | 2017-05-11 15:43:44 +1000 | [diff] [blame] | 4034 | return; |
| 4035 | } |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 4036 | |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4037 | if (!check_layered && texObj->Target == GL_TEXTURE_CUBE_MAP) { |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 4038 | assert(layer >= 0 && layer < 6); |
| 4039 | textarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; |
| 4040 | layer = 0; |
| 4041 | } |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 4042 | } |
| 4043 | |
Timothy Arceri | 69ca1ef | 2017-05-05 17:00:34 +1000 | [diff] [blame] | 4044 | _mesa_framebuffer_texture(ctx, fb, attachment, att, texObj, textarget, |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 4045 | level, 0, layer, layered); |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 4046 | } |
| 4047 | |
Timothy Arceri | e75e8d6 | 2017-05-08 11:24:07 +1000 | [diff] [blame] | 4048 | void GLAPIENTRY |
| 4049 | _mesa_FramebufferTextureLayer_no_error(GLenum target, GLenum attachment, |
| 4050 | GLuint texture, GLint level, |
| 4051 | GLint layer) |
| 4052 | { |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4053 | frame_buffer_texture(0, target, attachment, texture, level, layer, |
| 4054 | "glFramebufferTextureLayer", false, true, false); |
Timothy Arceri | e75e8d6 | 2017-05-08 11:24:07 +1000 | [diff] [blame] | 4055 | } |
| 4056 | |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 4057 | |
| 4058 | void GLAPIENTRY |
Timothy Arceri | 01081c6 | 2017-05-10 11:22:47 +1000 | [diff] [blame] | 4059 | _mesa_FramebufferTextureLayer(GLenum target, GLenum attachment, |
| 4060 | GLuint texture, GLint level, GLint layer) |
| 4061 | { |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4062 | frame_buffer_texture(0, target, attachment, texture, level, layer, |
| 4063 | "glFramebufferTextureLayer", false, false, false); |
Timothy Arceri | 01081c6 | 2017-05-10 11:22:47 +1000 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | |
| 4067 | void GLAPIENTRY |
Timothy Arceri | 4e125c4 | 2017-05-08 11:37:33 +1000 | [diff] [blame] | 4068 | _mesa_NamedFramebufferTextureLayer_no_error(GLuint framebuffer, |
| 4069 | GLenum attachment, |
| 4070 | GLuint texture, GLint level, |
| 4071 | GLint layer) |
| 4072 | { |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4073 | frame_buffer_texture(framebuffer, 0, attachment, texture, level, layer, |
| 4074 | "glNamedFramebufferTextureLayer", true, true, false); |
Timothy Arceri | 4e125c4 | 2017-05-08 11:37:33 +1000 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | |
| 4078 | void GLAPIENTRY |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 4079 | _mesa_NamedFramebufferTextureLayer(GLuint framebuffer, GLenum attachment, |
| 4080 | GLuint texture, GLint level, GLint layer) |
| 4081 | { |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4082 | frame_buffer_texture(framebuffer, 0, attachment, texture, level, layer, |
| 4083 | "glNamedFramebufferTextureLayer", true, false, false); |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | |
| 4087 | void GLAPIENTRY |
Timothy Arceri | 4e8aa4b | 2017-05-08 11:52:45 +1000 | [diff] [blame] | 4088 | _mesa_FramebufferTexture_no_error(GLenum target, GLenum attachment, |
| 4089 | GLuint texture, GLint level) |
| 4090 | { |
| 4091 | frame_buffer_texture(0, target, attachment, texture, level, 0, |
| 4092 | "glFramebufferTexture", false, true, true); |
| 4093 | } |
| 4094 | |
| 4095 | |
| 4096 | void GLAPIENTRY |
Jordan Justen | 02f2bce | 2013-04-18 10:46:12 -0700 | [diff] [blame] | 4097 | _mesa_FramebufferTexture(GLenum target, GLenum attachment, |
| 4098 | GLuint texture, GLint level) |
| 4099 | { |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4100 | frame_buffer_texture(0, target, attachment, texture, level, 0, |
| 4101 | "glFramebufferTexture", false, false, true); |
Jordan Justen | 02f2bce | 2013-04-18 10:46:12 -0700 | [diff] [blame] | 4102 | } |
| 4103 | |
Timothy Arceri | 3336d24 | 2017-05-08 12:01:33 +1000 | [diff] [blame] | 4104 | void GLAPIENTRY |
| 4105 | _mesa_NamedFramebufferTexture_no_error(GLuint framebuffer, GLenum attachment, |
| 4106 | GLuint texture, GLint level) |
| 4107 | { |
| 4108 | frame_buffer_texture(framebuffer, 0, attachment, texture, level, 0, |
| 4109 | "glNamedFramebufferTexture", true, true, true); |
| 4110 | } |
| 4111 | |
Jordan Justen | 02f2bce | 2013-04-18 10:46:12 -0700 | [diff] [blame] | 4112 | |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 4113 | void GLAPIENTRY |
| 4114 | _mesa_NamedFramebufferTexture(GLuint framebuffer, GLenum attachment, |
| 4115 | GLuint texture, GLint level) |
| 4116 | { |
Timothy Arceri | f622928 | 2017-05-10 11:44:54 +1000 | [diff] [blame] | 4117 | frame_buffer_texture(framebuffer, 0, attachment, texture, level, 0, |
| 4118 | "glNamedFramebufferTexture", true, false, true); |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 4119 | } |
| 4120 | |
| 4121 | |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 4122 | void GLAPIENTRY |
| 4123 | _mesa_NamedFramebufferTexture1DEXT(GLuint framebuffer, GLenum attachment, |
| 4124 | GLenum textarget, GLuint texture, GLint level) |
| 4125 | { |
| 4126 | framebuffer_texture_with_dims(1, GL_FRAMEBUFFER, framebuffer, attachment, |
| 4127 | textarget, texture, level, 0, 0, |
| 4128 | "glNamedFramebufferTexture1DEXT", true); |
| 4129 | } |
| 4130 | |
| 4131 | |
| 4132 | void GLAPIENTRY |
| 4133 | _mesa_NamedFramebufferTexture2DEXT(GLuint framebuffer, GLenum attachment, |
| 4134 | GLenum textarget, GLuint texture, GLint level) |
| 4135 | { |
| 4136 | framebuffer_texture_with_dims(2, GL_FRAMEBUFFER, framebuffer, attachment, |
| 4137 | textarget, texture, level, 0, 0, |
| 4138 | "glNamedFramebufferTexture2DEXT", true); |
| 4139 | } |
| 4140 | |
| 4141 | |
| 4142 | void GLAPIENTRY |
| 4143 | _mesa_NamedFramebufferTexture3DEXT(GLuint framebuffer, GLenum attachment, |
| 4144 | GLenum textarget, GLuint texture, |
| 4145 | GLint level, GLint zoffset) |
| 4146 | { |
| 4147 | framebuffer_texture_with_dims(3, GL_FRAMEBUFFER, framebuffer, attachment, |
| 4148 | textarget, texture, level, 0, zoffset, |
| 4149 | "glNamedFramebufferTexture3DEXT", true); |
| 4150 | } |
| 4151 | |
| 4152 | |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 4153 | void |
| 4154 | _mesa_framebuffer_renderbuffer(struct gl_context *ctx, |
| 4155 | struct gl_framebuffer *fb, |
| 4156 | GLenum attachment, |
Ian Romanick | 9ae42ab | 2015-11-11 16:30:41 -0800 | [diff] [blame] | 4157 | struct gl_renderbuffer *rb) |
| 4158 | { |
| 4159 | assert(!_mesa_is_winsys_fbo(fb)); |
| 4160 | |
| 4161 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 4162 | |
| 4163 | assert(ctx->Driver.FramebufferRenderbuffer); |
| 4164 | ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb); |
| 4165 | |
| 4166 | /* Some subsequent GL commands may depend on the framebuffer's visual |
| 4167 | * after the binding is updated. Update visual info now. |
| 4168 | */ |
| 4169 | _mesa_update_framebuffer_visual(ctx, fb); |
| 4170 | } |
| 4171 | |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4172 | static ALWAYS_INLINE void |
Samuel Pitoiset | 1ebe430 | 2017-07-20 11:53:03 +0200 | [diff] [blame] | 4173 | framebuffer_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 4174 | GLenum attachment, GLenum renderbuffertarget, |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4175 | GLuint renderbuffer, const char *func, bool no_error) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4176 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 4177 | struct gl_renderbuffer_attachment *att; |
Samuel Pitoiset | 1ebe430 | 2017-07-20 11:53:03 +0200 | [diff] [blame] | 4178 | struct gl_renderbuffer *rb; |
Alejandro Piñeiro | 84e3e12 | 2017-01-12 16:09:17 -0200 | [diff] [blame] | 4179 | bool is_color_attachment; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4180 | |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4181 | if (!no_error && renderbuffertarget != GL_RENDERBUFFER) { |
Samuel Pitoiset | 1ebe430 | 2017-07-20 11:53:03 +0200 | [diff] [blame] | 4182 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 4183 | "%s(renderbuffertarget is not GL_RENDERBUFFER)", func); |
| 4184 | return; |
| 4185 | } |
| 4186 | |
| 4187 | if (renderbuffer) { |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4188 | if (!no_error) { |
| 4189 | rb = _mesa_lookup_renderbuffer_err(ctx, renderbuffer, func); |
| 4190 | if (!rb) |
| 4191 | return; |
| 4192 | } else { |
| 4193 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
| 4194 | } |
Samuel Pitoiset | 1ebe430 | 2017-07-20 11:53:03 +0200 | [diff] [blame] | 4195 | } else { |
| 4196 | /* remove renderbuffer attachment */ |
| 4197 | rb = NULL; |
| 4198 | } |
| 4199 | |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4200 | if (!no_error) { |
| 4201 | if (_mesa_is_winsys_fbo(fb)) { |
| 4202 | /* Can't attach new renderbuffers to a window system framebuffer */ |
Alejandro Piñeiro | 84e3e12 | 2017-01-12 16:09:17 -0200 | [diff] [blame] | 4203 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4204 | "%s(window-system framebuffer)", func); |
| 4205 | return; |
Alejandro Piñeiro | 84e3e12 | 2017-01-12 16:09:17 -0200 | [diff] [blame] | 4206 | } |
| 4207 | |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4208 | att = get_attachment(ctx, fb, attachment, &is_color_attachment); |
| 4209 | if (att == NULL) { |
| 4210 | /* |
| 4211 | * From OpenGL 4.5 spec, section 9.2.7 "Attaching Renderbuffer Images |
| 4212 | * to a Framebuffer": |
| 4213 | * |
| 4214 | * "An INVALID_OPERATION error is generated if attachment is |
| 4215 | * COLOR_- ATTACHMENTm where m is greater than or equal to the |
| 4216 | * value of MAX_COLOR_- ATTACHMENTS ." |
| 4217 | * |
| 4218 | * If we are at this point, is because the attachment is not valid, so |
| 4219 | * if is_color_attachment is true, is because of the previous reason. |
| 4220 | */ |
| 4221 | if (is_color_attachment) { |
| 4222 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 4223 | "%s(invalid color attachment %s)", func, |
| 4224 | _mesa_enum_to_string(attachment)); |
| 4225 | } else { |
| 4226 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 4227 | "%s(invalid attachment %s)", func, |
| 4228 | _mesa_enum_to_string(attachment)); |
| 4229 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4230 | |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 4231 | return; |
| 4232 | } |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4233 | |
| 4234 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT && |
| 4235 | rb && rb->Format != MESA_FORMAT_NONE) { |
| 4236 | /* make sure the renderbuffer is a depth/stencil format */ |
| 4237 | const GLenum baseFormat = _mesa_get_format_base_format(rb->Format); |
| 4238 | if (baseFormat != GL_DEPTH_STENCIL) { |
| 4239 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 4240 | "%s(renderbuffer is not DEPTH_STENCIL format)", func); |
| 4241 | return; |
| 4242 | } |
| 4243 | } |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 4244 | } |
| 4245 | |
Ian Romanick | 9ae42ab | 2015-11-11 16:30:41 -0800 | [diff] [blame] | 4246 | _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4247 | } |
| 4248 | |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4249 | static void |
| 4250 | framebuffer_renderbuffer_error(struct gl_context *ctx, |
| 4251 | struct gl_framebuffer *fb, GLenum attachment, |
| 4252 | GLenum renderbuffertarget, |
| 4253 | GLuint renderbuffer, const char *func) |
| 4254 | { |
| 4255 | framebuffer_renderbuffer(ctx, fb, attachment, renderbuffertarget, |
| 4256 | renderbuffer, func, false); |
| 4257 | } |
| 4258 | |
Samuel Pitoiset | 0a20e43 | 2017-07-19 12:28:21 +0200 | [diff] [blame] | 4259 | static void |
| 4260 | framebuffer_renderbuffer_no_error(struct gl_context *ctx, |
| 4261 | struct gl_framebuffer *fb, GLenum attachment, |
| 4262 | GLenum renderbuffertarget, |
| 4263 | GLuint renderbuffer, const char *func) |
| 4264 | { |
| 4265 | framebuffer_renderbuffer(ctx, fb, attachment, renderbuffertarget, |
| 4266 | renderbuffer, func, true); |
| 4267 | } |
| 4268 | |
| 4269 | void GLAPIENTRY |
| 4270 | _mesa_FramebufferRenderbuffer_no_error(GLenum target, GLenum attachment, |
| 4271 | GLenum renderbuffertarget, |
| 4272 | GLuint renderbuffer) |
| 4273 | { |
| 4274 | GET_CURRENT_CONTEXT(ctx); |
| 4275 | |
| 4276 | struct gl_framebuffer *fb = get_framebuffer_target(ctx, target); |
| 4277 | framebuffer_renderbuffer_no_error(ctx, fb, attachment, renderbuffertarget, |
| 4278 | renderbuffer, "glFramebufferRenderbuffer"); |
| 4279 | } |
| 4280 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 4281 | void GLAPIENTRY |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 4282 | _mesa_FramebufferRenderbuffer(GLenum target, GLenum attachment, |
| 4283 | GLenum renderbuffertarget, |
| 4284 | GLuint renderbuffer) |
| 4285 | { |
| 4286 | struct gl_framebuffer *fb; |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 4287 | GET_CURRENT_CONTEXT(ctx); |
| 4288 | |
| 4289 | fb = get_framebuffer_target(ctx, target); |
| 4290 | if (!fb) { |
| 4291 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 4292 | "glFramebufferRenderbuffer(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4293 | _mesa_enum_to_string(target)); |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 4294 | return; |
| 4295 | } |
| 4296 | |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4297 | framebuffer_renderbuffer_error(ctx, fb, attachment, renderbuffertarget, |
| 4298 | renderbuffer, "glFramebufferRenderbuffer"); |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 4299 | } |
| 4300 | |
Samuel Pitoiset | 7bc50df | 2017-07-19 12:32:42 +0200 | [diff] [blame] | 4301 | void GLAPIENTRY |
| 4302 | _mesa_NamedFramebufferRenderbuffer_no_error(GLuint framebuffer, |
| 4303 | GLenum attachment, |
| 4304 | GLenum renderbuffertarget, |
| 4305 | GLuint renderbuffer) |
| 4306 | { |
| 4307 | GET_CURRENT_CONTEXT(ctx); |
| 4308 | |
| 4309 | struct gl_framebuffer *fb = _mesa_lookup_framebuffer(ctx, framebuffer); |
| 4310 | framebuffer_renderbuffer_no_error(ctx, fb, attachment, renderbuffertarget, |
| 4311 | renderbuffer, |
| 4312 | "glNamedFramebufferRenderbuffer"); |
| 4313 | } |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 4314 | |
| 4315 | void GLAPIENTRY |
| 4316 | _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer, GLenum attachment, |
| 4317 | GLenum renderbuffertarget, |
| 4318 | GLuint renderbuffer) |
| 4319 | { |
| 4320 | struct gl_framebuffer *fb; |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 4321 | GET_CURRENT_CONTEXT(ctx); |
| 4322 | |
| 4323 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 4324 | "glNamedFramebufferRenderbuffer"); |
Fredrik Höglund | 5a55f68 | 2015-05-16 19:43:39 +0200 | [diff] [blame] | 4325 | if (!fb) |
| 4326 | return; |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 4327 | |
Samuel Pitoiset | 55188f7 | 2017-07-19 12:24:31 +0200 | [diff] [blame] | 4328 | framebuffer_renderbuffer_error(ctx, fb, attachment, renderbuffertarget, |
| 4329 | renderbuffer, |
| 4330 | "glNamedFramebufferRenderbuffer"); |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 4334 | void GLAPIENTRY |
| 4335 | _mesa_NamedFramebufferRenderbufferEXT(GLuint framebuffer, GLenum attachment, |
| 4336 | GLenum renderbuffertarget, |
| 4337 | GLuint renderbuffer) |
| 4338 | { |
| 4339 | struct gl_framebuffer *fb; |
| 4340 | GET_CURRENT_CONTEXT(ctx); |
| 4341 | |
| 4342 | fb = _mesa_lookup_framebuffer_dsa(ctx, framebuffer, |
| 4343 | "glNamedFramebufferRenderbufferEXT"); |
| 4344 | if (!fb) |
| 4345 | return; |
| 4346 | |
| 4347 | framebuffer_renderbuffer_error(ctx, fb, attachment, renderbuffertarget, |
| 4348 | renderbuffer, |
| 4349 | "glNamedFramebufferRenderbuffer"); |
| 4350 | } |
| 4351 | |
| 4352 | |
Timothy Arceri | 8b00630 | 2017-05-05 15:21:22 +1000 | [diff] [blame] | 4353 | static void |
| 4354 | get_framebuffer_attachment_parameter(struct gl_context *ctx, |
| 4355 | struct gl_framebuffer *buffer, |
| 4356 | GLenum attachment, GLenum pname, |
| 4357 | GLint *params, const char *caller) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4358 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 4359 | const struct gl_renderbuffer_attachment *att; |
Robert Foss | 88becf7 | 2017-03-01 19:14:39 -0500 | [diff] [blame] | 4360 | bool is_color_attachment = false; |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 4361 | GLenum err; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4362 | |
Kenneth Graunke | 19f13b2 | 2016-03-07 16:43:35 -0800 | [diff] [blame] | 4363 | /* The error code for an attachment type of GL_NONE differs between APIs. |
| 4364 | * |
| 4365 | * From the ES 2.0.25 specification, page 127: |
| 4366 | * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then |
| 4367 | * querying any other pname will generate INVALID_ENUM." |
| 4368 | * |
| 4369 | * From the OpenGL 3.0 specification, page 337, or identically, |
| 4370 | * the OpenGL ES 3.0.4 specification, page 240: |
| 4371 | * |
| 4372 | * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no |
| 4373 | * framebuffer is bound to target. In this case querying pname |
| 4374 | * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other |
| 4375 | * queries will generate an INVALID_OPERATION error." |
| 4376 | */ |
| 4377 | err = ctx->API == API_OPENGLES2 && ctx->Version < 30 ? |
| 4378 | GL_INVALID_ENUM : GL_INVALID_OPERATION; |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 4379 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 4380 | if (_mesa_is_winsys_fbo(buffer)) { |
Ian Romanick | da2e41c | 2011-10-03 12:04:09 -0700 | [diff] [blame] | 4381 | /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec |
| 4382 | * says: |
| 4383 | * |
| 4384 | * "If the framebuffer currently bound to target is zero, then |
| 4385 | * INVALID_OPERATION is generated." |
| 4386 | * |
| 4387 | * The EXT_framebuffer_object spec has the same wording, and the |
| 4388 | * OES_framebuffer_object spec refers to the EXT_framebuffer_object |
| 4389 | * spec. |
| 4390 | */ |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 4391 | if ((!_mesa_is_desktop_gl(ctx) || |
| 4392 | !ctx->Extensions.ARB_framebuffer_object) |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 4393 | && !_mesa_is_gles3(ctx)) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 4394 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4395 | "%s(window-system framebuffer)", caller); |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 4396 | return; |
Ian Romanick | da2e41c | 2011-10-03 12:04:09 -0700 | [diff] [blame] | 4397 | } |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 4398 | |
| 4399 | if (_mesa_is_gles3(ctx) && attachment != GL_BACK && |
| 4400 | attachment != GL_DEPTH && attachment != GL_STENCIL) { |
Samuel Iglesias Gonsalvez | 284bd1e | 2015-01-16 16:00:13 +0100 | [diff] [blame] | 4401 | _mesa_error(ctx, GL_INVALID_ENUM, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4402 | "%s(invalid attachment %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4403 | _mesa_enum_to_string(attachment)); |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 4404 | return; |
| 4405 | } |
Kenneth Graunke | 789e096 | 2016-03-08 23:59:37 -0800 | [diff] [blame] | 4406 | |
| 4407 | /* The specs are not clear about how to handle |
| 4408 | * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer, |
| 4409 | * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been |
| 4410 | * discussed in: |
| 4411 | * |
| 4412 | * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1 |
| 4413 | * and https://bugs.freedesktop.org/show_bug.cgi?id=31947 |
| 4414 | */ |
| 4415 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { |
| 4416 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 4417 | "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME " |
| 4418 | "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is " |
| 4419 | "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller); |
| 4420 | return; |
| 4421 | } |
| 4422 | |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 4423 | /* the default / window-system FBO */ |
Timothy Arceri | e618761 | 2017-05-05 15:02:20 +1000 | [diff] [blame] | 4424 | att = get_fb0_attachment(ctx, buffer, attachment); |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 4425 | } |
| 4426 | else { |
| 4427 | /* user-created framebuffer FBO */ |
Alejandro Piñeiro | 84e3e12 | 2017-01-12 16:09:17 -0200 | [diff] [blame] | 4428 | att = get_attachment(ctx, buffer, attachment, &is_color_attachment); |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 4429 | } |
| 4430 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4431 | if (att == NULL) { |
Alejandro Piñeiro | 84e3e12 | 2017-01-12 16:09:17 -0200 | [diff] [blame] | 4432 | /* |
| 4433 | * From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries": |
| 4434 | * |
| 4435 | * "An INVALID_OPERATION error is generated if a framebuffer object |
| 4436 | * is bound to target and attachment is COLOR_ATTACHMENTm where m is |
| 4437 | * greater than or equal to the value of MAX_COLOR_ATTACHMENTS." |
| 4438 | * |
| 4439 | * If we are at this point, is because the attachment is not valid, so |
| 4440 | * if is_color_attachment is true, is because of the previous reason. |
| 4441 | */ |
| 4442 | if (is_color_attachment) { |
| 4443 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid color attachment %s)", |
| 4444 | caller, _mesa_enum_to_string(attachment)); |
| 4445 | } else { |
| 4446 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid attachment %s)", caller, |
| 4447 | _mesa_enum_to_string(attachment)); |
| 4448 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4449 | return; |
| 4450 | } |
| 4451 | |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 4452 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
Brian Paul | e959274 | 2014-04-21 13:24:25 -0600 | [diff] [blame] | 4453 | const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt; |
Anuj Phogat | bd1880d | 2014-03-11 17:04:11 -0700 | [diff] [blame] | 4454 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE) { |
| 4455 | /* This behavior is first specified in OpenGL 4.4 specification. |
| 4456 | * |
| 4457 | * From the OpenGL 4.4 spec page 275: |
| 4458 | * "This query cannot be performed for a combined depth+stencil |
| 4459 | * attachment, since it does not have a single format." |
| 4460 | */ |
| 4461 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4462 | "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE" |
| 4463 | " is invalid for depth+stencil attachment)", caller); |
Anuj Phogat | bd1880d | 2014-03-11 17:04:11 -0700 | [diff] [blame] | 4464 | return; |
| 4465 | } |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 4466 | /* the depth and stencil attachments must point to the same buffer */ |
Alejandro Piñeiro | c6eb3ae | 2017-01-12 16:03:00 -0200 | [diff] [blame] | 4467 | depthAtt = get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT, NULL); |
| 4468 | stencilAtt = get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT, NULL); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 4469 | if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) { |
| 4470 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4471 | "%s(DEPTH/STENCIL attachments differ)", caller); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 4472 | return; |
| 4473 | } |
| 4474 | } |
| 4475 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 4476 | /* No need to flush here */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 4477 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4478 | switch (pname) { |
| 4479 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT: |
Iago Toral Quiroga | cf43995 | 2015-02-24 19:02:56 +0100 | [diff] [blame] | 4480 | /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects: |
| 4481 | * |
| 4482 | * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then |
| 4483 | * either no framebuffer is bound to target; or the default framebuffer |
| 4484 | * is bound, attachment is DEPTH or STENCIL, and the number of depth or |
| 4485 | * stencil bits, respectively, is zero." |
Alejandro Piñeiro | 9059614 | 2017-01-13 11:39:24 -0200 | [diff] [blame] | 4486 | * |
| 4487 | * Note that we don't need explicit checks on DEPTH and STENCIL, because |
| 4488 | * on the case the spec is pointing, att->Type is already NONE, so we |
| 4489 | * just need to check att->Type. |
Iago Toral Quiroga | cf43995 | 2015-02-24 19:02:56 +0100 | [diff] [blame] | 4490 | */ |
Alejandro Piñeiro | 9059614 | 2017-01-13 11:39:24 -0200 | [diff] [blame] | 4491 | *params = (_mesa_is_winsys_fbo(buffer) && att->Type != GL_NONE) ? |
| 4492 | GL_FRAMEBUFFER_DEFAULT : att->Type; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4493 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4494 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4495 | if (att->Type == GL_RENDERBUFFER_EXT) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 4496 | *params = att->Renderbuffer->Name; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4497 | } |
| 4498 | else if (att->Type == GL_TEXTURE) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 4499 | *params = att->Texture->Name; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4500 | } |
| 4501 | else { |
Brian Paul | 20cf185 | 2010-12-03 08:23:31 -0700 | [diff] [blame] | 4502 | assert(att->Type == GL_NONE); |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4503 | if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) { |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 4504 | *params = 0; |
| 4505 | } else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4506 | goto invalid_pname_enum; |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 4507 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4508 | } |
| 4509 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4510 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4511 | if (att->Type == GL_TEXTURE) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 4512 | *params = att->TextureLevel; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4513 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 4514 | else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4515 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4516 | _mesa_enum_to_string(pname)); |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 4517 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4518 | else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4519 | goto invalid_pname_enum; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4520 | } |
| 4521 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4522 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4523 | if (att->Type == GL_TEXTURE) { |
Brian Paul | f1e4ca7 | 2008-08-06 08:39:54 -0600 | [diff] [blame] | 4524 | if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) { |
| 4525 | *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace; |
| 4526 | } |
| 4527 | else { |
| 4528 | *params = 0; |
| 4529 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4530 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 4531 | else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4532 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4533 | _mesa_enum_to_string(pname)); |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 4534 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4535 | else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4536 | goto invalid_pname_enum; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4537 | } |
| 4538 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4539 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT: |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4540 | if (ctx->API == API_OPENGLES) { |
| 4541 | goto invalid_pname_enum; |
| 4542 | } else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4543 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4544 | _mesa_enum_to_string(pname)); |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4545 | } else if (att->Type == GL_TEXTURE) { |
Samuel Iglesias Gonsalvez | 8e49a3e | 2014-12-11 23:34:13 +0100 | [diff] [blame] | 4546 | if (att->Texture && (att->Texture->Target == GL_TEXTURE_3D || |
| 4547 | att->Texture->Target == GL_TEXTURE_2D_ARRAY)) { |
Brian Paul | f1e4ca7 | 2008-08-06 08:39:54 -0600 | [diff] [blame] | 4548 | *params = att->Zoffset; |
| 4549 | } |
| 4550 | else { |
| 4551 | *params = 0; |
| 4552 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4553 | } |
| 4554 | else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4555 | goto invalid_pname_enum; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 4556 | } |
| 4557 | return; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4558 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 4559 | if ((!_mesa_is_desktop_gl(ctx) || |
| 4560 | !ctx->Extensions.ARB_framebuffer_object) |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4561 | && !_mesa_is_gles3(ctx)) { |
| 4562 | goto invalid_pname_enum; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4563 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 4564 | else if (att->Type == GL_NONE) { |
Kenneth Graunke | 713cd23 | 2016-12-09 16:16:53 -0800 | [diff] [blame] | 4565 | if (_mesa_is_winsys_fbo(buffer) && |
| 4566 | (attachment == GL_DEPTH || attachment == GL_STENCIL)) { |
| 4567 | *params = GL_LINEAR; |
| 4568 | } else { |
| 4569 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
| 4570 | _mesa_enum_to_string(pname)); |
| 4571 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 4572 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4573 | else { |
Gert Wollny | 76c3f6f | 2018-11-14 10:58:40 +0100 | [diff] [blame] | 4574 | if (ctx->Extensions.EXT_sRGB) { |
Eric Anholt | 4d23157 | 2019-07-01 15:43:19 -0700 | [diff] [blame] | 4575 | *params = (_mesa_is_format_srgb(att->Renderbuffer->Format) ? |
| 4576 | GL_SRGB : GL_LINEAR); |
Marek Olšák | 81ae8c6 | 2011-01-23 13:26:43 +0100 | [diff] [blame] | 4577 | } |
| 4578 | else { |
| 4579 | /* According to ARB_framebuffer_sRGB, we should return LINEAR |
| 4580 | * if the sRGB conversion is unsupported. */ |
| 4581 | *params = GL_LINEAR; |
| 4582 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4583 | } |
| 4584 | return; |
| 4585 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 4586 | if ((ctx->API != API_OPENGL_COMPAT || |
| 4587 | !ctx->Extensions.ARB_framebuffer_object) |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4588 | && ctx->API != API_OPENGL_CORE |
| 4589 | && !_mesa_is_gles3(ctx)) { |
| 4590 | goto invalid_pname_enum; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4591 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 4592 | else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4593 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4594 | _mesa_enum_to_string(pname)); |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 4595 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4596 | else { |
Mark Mueller | 71fe943 | 2014-01-04 14:11:43 -0800 | [diff] [blame] | 4597 | mesa_format format = att->Renderbuffer->Format; |
Ian Romanick | d7475c7 | 2013-01-18 17:25:57 -0800 | [diff] [blame] | 4598 | |
| 4599 | /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES |
| 4600 | * 3.0.1 spec says: |
| 4601 | * |
| 4602 | * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If |
| 4603 | * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and |
| 4604 | * generate an INVALID_OPERATION error. |
| 4605 | */ |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 4606 | if (_mesa_is_gles3(ctx) && |
| 4607 | attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
Ian Romanick | d7475c7 | 2013-01-18 17:25:57 -0800 | [diff] [blame] | 4608 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4609 | "%s(cannot query " |
Ian Romanick | d7475c7 | 2013-01-18 17:25:57 -0800 | [diff] [blame] | 4610 | "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of " |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4611 | "GL_DEPTH_STENCIL_ATTACHMENT)", caller); |
Ian Romanick | d7475c7 | 2013-01-18 17:25:57 -0800 | [diff] [blame] | 4612 | return; |
| 4613 | } |
| 4614 | |
Mark Mueller | 50a01d2 | 2014-01-20 19:08:54 -0800 | [diff] [blame] | 4615 | if (format == MESA_FORMAT_S_UINT8) { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 4616 | /* special cases */ |
| 4617 | *params = GL_INDEX; |
| 4618 | } |
Mark Mueller | eeed49f | 2014-01-26 15:12:56 -0800 | [diff] [blame] | 4619 | else if (format == MESA_FORMAT_Z32_FLOAT_S8X24_UINT) { |
Marek Olšák | 1165280 | 2011-06-01 15:48:51 +0200 | [diff] [blame] | 4620 | /* depends on the attachment parameter */ |
| 4621 | if (attachment == GL_STENCIL_ATTACHMENT) { |
| 4622 | *params = GL_INDEX; |
| 4623 | } |
| 4624 | else { |
| 4625 | *params = GL_FLOAT; |
| 4626 | } |
| 4627 | } |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 4628 | else { |
| 4629 | *params = _mesa_get_format_datatype(format); |
| 4630 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4631 | } |
| 4632 | return; |
| 4633 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4634 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4635 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4636 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4637 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4638 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 4639 | if ((!_mesa_is_desktop_gl(ctx) || |
| 4640 | !ctx->Extensions.ARB_framebuffer_object) |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4641 | && !_mesa_is_gles3(ctx)) { |
| 4642 | goto invalid_pname_enum; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4643 | } |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 4644 | else if (att->Texture) { |
| 4645 | const struct gl_texture_image *texImage = |
Brian Paul | f262ed6 | 2015-01-02 16:56:12 -0700 | [diff] [blame] | 4646 | _mesa_select_tex_image(att->Texture, att->Texture->Target, |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 4647 | att->TextureLevel); |
| 4648 | if (texImage) { |
| 4649 | *params = get_component_bits(pname, texImage->_BaseFormat, |
| 4650 | texImage->TexFormat); |
| 4651 | } |
| 4652 | else { |
| 4653 | *params = 0; |
| 4654 | } |
| 4655 | } |
| 4656 | else if (att->Renderbuffer) { |
| 4657 | *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat, |
| 4658 | att->Renderbuffer->Format); |
| 4659 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4660 | else { |
Timothy Arceri | 786b9ad | 2017-05-05 15:39:15 +1000 | [diff] [blame] | 4661 | assert(att->Type == GL_NONE); |
| 4662 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
| 4663 | _mesa_enum_to_string(pname)); |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 4664 | } |
| 4665 | return; |
Paul Berry | ec79c05 | 2013-11-19 21:17:19 -0800 | [diff] [blame] | 4666 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED: |
| 4667 | if (!_mesa_has_geometry_shaders(ctx)) { |
| 4668 | goto invalid_pname_enum; |
| 4669 | } else if (att->Type == GL_TEXTURE) { |
| 4670 | *params = att->Layered; |
| 4671 | } else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4672 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4673 | _mesa_enum_to_string(pname)); |
Paul Berry | ec79c05 | 2013-11-19 21:17:19 -0800 | [diff] [blame] | 4674 | } else { |
| 4675 | goto invalid_pname_enum; |
| 4676 | } |
| 4677 | return; |
Kristian H. Kristensen | 1b331ae | 2018-11-05 21:19:21 -0800 | [diff] [blame] | 4678 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT: |
| 4679 | if (!ctx->Extensions.EXT_multisampled_render_to_texture) { |
| 4680 | goto invalid_pname_enum; |
| 4681 | } else if (att->Type == GL_TEXTURE) { |
| 4682 | *params = att->NumSamples; |
| 4683 | } else if (att->Type == GL_NONE) { |
| 4684 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
| 4685 | _mesa_enum_to_string(pname)); |
| 4686 | } else { |
| 4687 | goto invalid_pname_enum; |
| 4688 | } |
| 4689 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4690 | default: |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4691 | goto invalid_pname_enum; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4692 | } |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4693 | |
| 4694 | return; |
| 4695 | |
| 4696 | invalid_pname_enum: |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4697 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4698 | _mesa_enum_to_string(pname)); |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 4699 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4703 | void GLAPIENTRY |
| 4704 | _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, |
| 4705 | GLenum pname, GLint *params) |
| 4706 | { |
| 4707 | GET_CURRENT_CONTEXT(ctx); |
| 4708 | struct gl_framebuffer *buffer; |
| 4709 | |
| 4710 | buffer = get_framebuffer_target(ctx, target); |
| 4711 | if (!buffer) { |
| 4712 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 4713 | "glGetFramebufferAttachmentParameteriv(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4714 | _mesa_enum_to_string(target)); |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4715 | return; |
| 4716 | } |
| 4717 | |
Timothy Arceri | 8b00630 | 2017-05-05 15:21:22 +1000 | [diff] [blame] | 4718 | get_framebuffer_attachment_parameter(ctx, buffer, attachment, pname, |
| 4719 | params, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4720 | "glGetFramebufferAttachmentParameteriv"); |
| 4721 | } |
| 4722 | |
| 4723 | |
| 4724 | void GLAPIENTRY |
| 4725 | _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer, |
| 4726 | GLenum attachment, |
| 4727 | GLenum pname, GLint *params) |
| 4728 | { |
| 4729 | GET_CURRENT_CONTEXT(ctx); |
| 4730 | struct gl_framebuffer *buffer; |
| 4731 | |
| 4732 | if (framebuffer) { |
| 4733 | buffer = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 4734 | "glGetNamedFramebufferAttachmentParameteriv"); |
| 4735 | if (!buffer) |
| 4736 | return; |
| 4737 | } |
| 4738 | else { |
| 4739 | /* |
| 4740 | * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL |
| 4741 | * 4.5 core spec (30.10.2014, PDF page 314): |
| 4742 | * "If framebuffer is zero, then the default draw framebuffer is |
| 4743 | * queried." |
| 4744 | */ |
| 4745 | buffer = ctx->WinSysDrawBuffer; |
| 4746 | } |
| 4747 | |
Timothy Arceri | 8b00630 | 2017-05-05 15:21:22 +1000 | [diff] [blame] | 4748 | get_framebuffer_attachment_parameter(ctx, buffer, attachment, pname, |
| 4749 | params, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 4750 | "glGetNamedFramebufferAttachmentParameteriv"); |
| 4751 | } |
| 4752 | |
| 4753 | |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 4754 | void GLAPIENTRY |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 4755 | _mesa_GetNamedFramebufferAttachmentParameterivEXT(GLuint framebuffer, |
| 4756 | GLenum attachment, |
| 4757 | GLenum pname, GLint *params) |
| 4758 | { |
| 4759 | GET_CURRENT_CONTEXT(ctx); |
| 4760 | struct gl_framebuffer *buffer; |
| 4761 | |
| 4762 | if (framebuffer) { |
| 4763 | buffer = _mesa_lookup_framebuffer_dsa(ctx, framebuffer, |
| 4764 | "glGetNamedFramebufferAttachmentParameterivEXT"); |
| 4765 | if (!buffer) |
| 4766 | return; |
| 4767 | } |
| 4768 | else { |
| 4769 | /* |
| 4770 | * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL |
| 4771 | * 4.5 core spec (30.10.2014, PDF page 314): |
| 4772 | * "If framebuffer is zero, then the default draw framebuffer is |
| 4773 | * queried." |
| 4774 | */ |
| 4775 | buffer = ctx->WinSysDrawBuffer; |
| 4776 | } |
| 4777 | |
| 4778 | get_framebuffer_attachment_parameter(ctx, buffer, attachment, pname, |
| 4779 | params, |
| 4780 | "glGetNamedFramebufferAttachmentParameterivEXT"); |
| 4781 | } |
| 4782 | |
| 4783 | |
| 4784 | void GLAPIENTRY |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 4785 | _mesa_NamedFramebufferParameteri(GLuint framebuffer, GLenum pname, |
| 4786 | GLint param) |
| 4787 | { |
| 4788 | GET_CURRENT_CONTEXT(ctx); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 4789 | struct gl_framebuffer *fb = NULL; |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 4790 | |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 4791 | if (!ctx->Extensions.ARB_framebuffer_no_attachments && |
| 4792 | !ctx->Extensions.ARB_sample_locations) { |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 4793 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 4794 | "glNamedFramebufferParameteri(" |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 4795 | "neither ARB_framebuffer_no_attachments nor " |
| 4796 | "ARB_sample_locations is available)"); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 4797 | return; |
| 4798 | } |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 4799 | |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 4800 | if (framebuffer) { |
| 4801 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 4802 | "glNamedFramebufferParameteri"); |
| 4803 | } else { |
| 4804 | fb = ctx->WinSysDrawBuffer; |
| 4805 | } |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 4806 | |
| 4807 | if (fb) { |
| 4808 | framebuffer_parameteri(ctx, fb, pname, param, |
| 4809 | "glNamedFramebufferParameteriv"); |
| 4810 | } |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 4811 | } |
| 4812 | |
| 4813 | |
Pierre-Eric Pelloux-Prayer | 8cfb3e4 | 2019-11-05 14:47:53 +0100 | [diff] [blame] | 4814 | /* Helper function for ARB_framebuffer_no_attachments functions interacting with EXT_direct_state_access */ |
| 4815 | static struct gl_framebuffer * |
| 4816 | lookup_named_framebuffer_ext_dsa(struct gl_context *ctx, GLuint framebuffer, const char* caller) |
| 4817 | { |
| 4818 | struct gl_framebuffer *fb = NULL; |
| 4819 | |
| 4820 | if (framebuffer) { |
| 4821 | /* The ARB_framebuffer_no_attachments spec says: |
| 4822 | * |
| 4823 | * "The error INVALID_VALUE is generated if <framebuffer> is not |
| 4824 | * a name returned by GenFramebuffers. If a framebuffer object |
| 4825 | * named <framebuffer> does not yet exist, it will be created." |
| 4826 | * |
| 4827 | * This is different from the EXT_direct_state_access spec which says: |
| 4828 | * |
| 4829 | * "If the framebuffer object named by the framebuffer parameter has not |
| 4830 | * been previously bound or has been deleted since the last binding, |
| 4831 | * the GL first creates a new state vector in the same manner as when |
| 4832 | * BindFramebuffer creates a new framebuffer object" |
| 4833 | * |
| 4834 | * So first we verify that the name exists. |
| 4835 | */ |
| 4836 | fb = _mesa_lookup_framebuffer(ctx, framebuffer); |
| 4837 | if (!fb) { |
| 4838 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(frameBuffer)", caller); |
| 4839 | return NULL; |
| 4840 | } |
| 4841 | /* Then, make sure it's initialized */ |
| 4842 | if (fb == &DummyFramebuffer) { |
| 4843 | fb = ctx->Driver.NewFramebuffer(ctx, framebuffer); |
Pierre-Eric Pelloux-Prayer | 3485212 | 2020-09-04 14:07:04 +0200 | [diff] [blame] | 4844 | _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, fb, true); |
Pierre-Eric Pelloux-Prayer | 8cfb3e4 | 2019-11-05 14:47:53 +0100 | [diff] [blame] | 4845 | } |
| 4846 | } |
| 4847 | else |
| 4848 | fb = ctx->WinSysDrawBuffer; |
| 4849 | |
| 4850 | return fb; |
| 4851 | } |
| 4852 | |
| 4853 | |
| 4854 | void GLAPIENTRY |
| 4855 | _mesa_NamedFramebufferParameteriEXT(GLuint framebuffer, GLenum pname, |
| 4856 | GLint param) |
| 4857 | { |
| 4858 | GET_CURRENT_CONTEXT(ctx); |
| 4859 | struct gl_framebuffer *fb = |
| 4860 | lookup_named_framebuffer_ext_dsa(ctx, framebuffer, |
| 4861 | "glNamedFramebufferParameteriEXT"); |
| 4862 | |
| 4863 | if (!fb) |
| 4864 | return; |
| 4865 | |
| 4866 | framebuffer_parameteri(ctx, fb, pname, param, |
| 4867 | "glNamedFramebufferParameteriEXT"); |
| 4868 | } |
| 4869 | |
| 4870 | |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 4871 | void GLAPIENTRY |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 4872 | _mesa_GetFramebufferParameterivEXT(GLuint framebuffer, GLenum pname, |
| 4873 | GLint *param) |
| 4874 | { |
| 4875 | GET_CURRENT_CONTEXT(ctx); |
| 4876 | struct gl_framebuffer *fb; |
| 4877 | |
| 4878 | if (framebuffer) |
| 4879 | fb = _mesa_lookup_framebuffer_dsa(ctx, framebuffer, |
| 4880 | "glGetFramebufferParameterivEXT"); |
| 4881 | else |
| 4882 | fb = ctx->WinSysDrawBuffer; |
| 4883 | |
| 4884 | if (fb) { |
| 4885 | /* The GL_EXT_direct_state_access says: |
| 4886 | * |
| 4887 | * The pname parameter must be one of framebuffer dependent values |
| 4888 | * listed in either table 4.nnn (namely DRAW_BUFFER, READ_BUFFER, |
| 4889 | * or DRAW_BUFFER0 through DRAW_BUFFER15). |
| 4890 | */ |
| 4891 | if (pname == GL_DRAW_BUFFER) { |
| 4892 | *param = fb->ColorDrawBuffer[0]; |
| 4893 | |
| 4894 | } |
| 4895 | else if (pname == GL_READ_BUFFER) { |
| 4896 | *param = fb->ColorReadBuffer; |
| 4897 | } |
| 4898 | else if (GL_DRAW_BUFFER0 <= pname && pname <= GL_DRAW_BUFFER15) { |
Marcin Ślusarz | 0906d5d | 2020-07-24 19:19:07 +0200 | [diff] [blame] | 4899 | unsigned buffer = pname - GL_DRAW_BUFFER0; |
| 4900 | if (buffer < ARRAY_SIZE(fb->ColorDrawBuffer)) |
| 4901 | *param = fb->ColorDrawBuffer[buffer]; |
| 4902 | else |
| 4903 | _mesa_error(ctx, GL_INVALID_ENUM, "glGetFramebufferParameterivEXT(pname)"); |
Pierre-Eric Pelloux-Prayer | 7534c53 | 2019-04-29 13:53:29 +0200 | [diff] [blame] | 4904 | } |
| 4905 | else { |
| 4906 | _mesa_error(ctx, GL_INVALID_ENUM, "glGetFramebufferParameterivEXT(pname)"); |
| 4907 | } |
| 4908 | } |
| 4909 | } |
| 4910 | |
| 4911 | |
| 4912 | void GLAPIENTRY |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 4913 | _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer, GLenum pname, |
| 4914 | GLint *param) |
| 4915 | { |
| 4916 | GET_CURRENT_CONTEXT(ctx); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 4917 | struct gl_framebuffer *fb; |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 4918 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 4919 | if (!ctx->Extensions.ARB_framebuffer_no_attachments) { |
| 4920 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 4921 | "glNamedFramebufferParameteriv(" |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 4922 | "neither ARB_framebuffer_no_attachments nor ARB_sample_locations" |
| 4923 | " is available)"); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 4924 | return; |
| 4925 | } |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 4926 | |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 4927 | if (framebuffer) |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 4928 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 4929 | "glGetNamedFramebufferParameteriv"); |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 4930 | else |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 4931 | fb = ctx->WinSysDrawBuffer; |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 4932 | |
| 4933 | if (fb) { |
| 4934 | get_framebuffer_parameteriv(ctx, fb, pname, param, |
| 4935 | "glGetNamedFramebufferParameteriv"); |
| 4936 | } |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | |
Pierre-Eric Pelloux-Prayer | 8cfb3e4 | 2019-11-05 14:47:53 +0100 | [diff] [blame] | 4940 | void GLAPIENTRY |
| 4941 | _mesa_GetNamedFramebufferParameterivEXT(GLuint framebuffer, GLenum pname, |
| 4942 | GLint *param) |
| 4943 | { |
| 4944 | GET_CURRENT_CONTEXT(ctx); |
| 4945 | struct gl_framebuffer *fb = |
| 4946 | lookup_named_framebuffer_ext_dsa(ctx, framebuffer, |
| 4947 | "glGetNamedFramebufferParameterivEXT"); |
| 4948 | |
| 4949 | if (!fb) |
| 4950 | return; |
| 4951 | |
| 4952 | get_framebuffer_parameteriv(ctx, fb, pname, param, |
| 4953 | "glGetNamedFramebufferParameterivEXT"); |
| 4954 | } |
| 4955 | |
| 4956 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4957 | static void |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 4958 | invalidate_framebuffer_storage(struct gl_context *ctx, |
| 4959 | struct gl_framebuffer *fb, |
| 4960 | GLsizei numAttachments, |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4961 | const GLenum *attachments, GLint x, GLint y, |
| 4962 | GLsizei width, GLsizei height, const char *name) |
| 4963 | { |
| 4964 | int i; |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4965 | |
Laura Ekstrand | b4368ac | 2015-02-04 14:21:17 -0800 | [diff] [blame] | 4966 | /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core |
| 4967 | * Spec (2.2.2015, PDF page 522) says: |
| 4968 | * "An INVALID_VALUE error is generated if numAttachments, width, or |
| 4969 | * height is negative." |
| 4970 | */ |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4971 | if (numAttachments < 0) { |
| 4972 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 4973 | "%s(numAttachments < 0)", name); |
| 4974 | return; |
| 4975 | } |
| 4976 | |
Laura Ekstrand | b4368ac | 2015-02-04 14:21:17 -0800 | [diff] [blame] | 4977 | if (width < 0) { |
| 4978 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 4979 | "%s(width < 0)", name); |
| 4980 | return; |
| 4981 | } |
| 4982 | |
| 4983 | if (height < 0) { |
| 4984 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 4985 | "%s(height < 0)", name); |
| 4986 | return; |
| 4987 | } |
| 4988 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4989 | /* The GL_ARB_invalidate_subdata spec says: |
| 4990 | * |
| 4991 | * "If an attachment is specified that does not exist in the |
| 4992 | * framebuffer bound to <target>, it is ignored." |
| 4993 | * |
| 4994 | * It also says: |
| 4995 | * |
| 4996 | * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than |
| 4997 | * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error |
| 4998 | * INVALID_OPERATION is generated." |
| 4999 | * |
| 5000 | * No mention is made of GL_AUXi being out of range. Therefore, we allow |
| 5001 | * any enum that can be allowed by the API (OpenGL ES 3.0 has a different |
| 5002 | * set of retrictions). |
| 5003 | */ |
| 5004 | for (i = 0; i < numAttachments; i++) { |
| 5005 | if (_mesa_is_winsys_fbo(fb)) { |
| 5006 | switch (attachments[i]) { |
| 5007 | case GL_ACCUM: |
| 5008 | case GL_AUX0: |
| 5009 | case GL_AUX1: |
| 5010 | case GL_AUX2: |
| 5011 | case GL_AUX3: |
| 5012 | /* Accumulation buffers and auxilary buffers were removed in |
| 5013 | * OpenGL 3.1, and they never existed in OpenGL ES. |
| 5014 | */ |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 5015 | if (ctx->API != API_OPENGL_COMPAT) |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5016 | goto invalid_enum; |
| 5017 | break; |
| 5018 | case GL_COLOR: |
| 5019 | case GL_DEPTH: |
| 5020 | case GL_STENCIL: |
| 5021 | break; |
| 5022 | case GL_BACK_LEFT: |
| 5023 | case GL_BACK_RIGHT: |
| 5024 | case GL_FRONT_LEFT: |
| 5025 | case GL_FRONT_RIGHT: |
| 5026 | if (!_mesa_is_desktop_gl(ctx)) |
| 5027 | goto invalid_enum; |
| 5028 | break; |
| 5029 | default: |
| 5030 | goto invalid_enum; |
| 5031 | } |
| 5032 | } else { |
| 5033 | switch (attachments[i]) { |
| 5034 | case GL_DEPTH_ATTACHMENT: |
| 5035 | case GL_STENCIL_ATTACHMENT: |
| 5036 | break; |
Eduardo Lima Mitev | 242ad32 | 2014-11-18 16:28:18 +0100 | [diff] [blame] | 5037 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 5038 | /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only |
| 5039 | * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil |
| 5040 | * extension does not make this attachment point valid on ES 2.0. |
| 5041 | */ |
| 5042 | if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) |
| 5043 | break; |
| 5044 | /* fallthrough */ |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5045 | case GL_COLOR_ATTACHMENT0: |
| 5046 | case GL_COLOR_ATTACHMENT1: |
| 5047 | case GL_COLOR_ATTACHMENT2: |
| 5048 | case GL_COLOR_ATTACHMENT3: |
| 5049 | case GL_COLOR_ATTACHMENT4: |
| 5050 | case GL_COLOR_ATTACHMENT5: |
| 5051 | case GL_COLOR_ATTACHMENT6: |
| 5052 | case GL_COLOR_ATTACHMENT7: |
| 5053 | case GL_COLOR_ATTACHMENT8: |
| 5054 | case GL_COLOR_ATTACHMENT9: |
| 5055 | case GL_COLOR_ATTACHMENT10: |
| 5056 | case GL_COLOR_ATTACHMENT11: |
| 5057 | case GL_COLOR_ATTACHMENT12: |
| 5058 | case GL_COLOR_ATTACHMENT13: |
| 5059 | case GL_COLOR_ATTACHMENT14: |
| 5060 | case GL_COLOR_ATTACHMENT15: { |
Brian Paul | 859c387 | 2012-11-04 16:43:44 -0700 | [diff] [blame] | 5061 | unsigned k = attachments[i] - GL_COLOR_ATTACHMENT0; |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5062 | if (k >= ctx->Const.MaxColorAttachments) { |
| 5063 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 5064 | "%s(attachment >= max. color attachments)", name); |
| 5065 | return; |
| 5066 | } |
Constantin Baranov | 53904c6 | 2013-10-13 01:17:15 +0300 | [diff] [blame] | 5067 | break; |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5068 | } |
| 5069 | default: |
| 5070 | goto invalid_enum; |
| 5071 | } |
| 5072 | } |
| 5073 | } |
| 5074 | |
| 5075 | /* We don't actually do anything for this yet. Just return after |
| 5076 | * validating the parameters and generating the required errors. |
| 5077 | */ |
| 5078 | return; |
| 5079 | |
| 5080 | invalid_enum: |
Laura Ekstrand | b4368ac | 2015-02-04 14:21:17 -0800 | [diff] [blame] | 5081 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid attachment %s)", name, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 5082 | _mesa_enum_to_string(attachments[i])); |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5083 | return; |
| 5084 | } |
| 5085 | |
Rob Clark | 0c42b5f | 2018-11-01 11:10:46 -0400 | [diff] [blame] | 5086 | static struct gl_renderbuffer_attachment * |
| 5087 | get_fb_attachment(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 5088 | const GLenum attachment) |
| 5089 | { |
| 5090 | switch (attachment) { |
| 5091 | case GL_COLOR: |
| 5092 | return &fb->Attachment[BUFFER_BACK_LEFT]; |
| 5093 | case GL_COLOR_ATTACHMENT0: |
| 5094 | case GL_COLOR_ATTACHMENT1: |
| 5095 | case GL_COLOR_ATTACHMENT2: |
| 5096 | case GL_COLOR_ATTACHMENT3: |
| 5097 | case GL_COLOR_ATTACHMENT4: |
| 5098 | case GL_COLOR_ATTACHMENT5: |
| 5099 | case GL_COLOR_ATTACHMENT6: |
| 5100 | case GL_COLOR_ATTACHMENT7: |
| 5101 | case GL_COLOR_ATTACHMENT8: |
| 5102 | case GL_COLOR_ATTACHMENT9: |
| 5103 | case GL_COLOR_ATTACHMENT10: |
| 5104 | case GL_COLOR_ATTACHMENT11: |
| 5105 | case GL_COLOR_ATTACHMENT12: |
| 5106 | case GL_COLOR_ATTACHMENT13: |
| 5107 | case GL_COLOR_ATTACHMENT14: |
Tapani Pälli | 9762a9f | 2019-02-14 09:02:31 +0200 | [diff] [blame] | 5108 | case GL_COLOR_ATTACHMENT15: { |
| 5109 | const unsigned i = attachment - GL_COLOR_ATTACHMENT0; |
| 5110 | if (i >= ctx->Const.MaxColorAttachments) |
| 5111 | return NULL; |
Marcin Ślusarz | c3a251f | 2020-07-24 19:51:30 +0200 | [diff] [blame] | 5112 | assert(BUFFER_COLOR0 + i < ARRAY_SIZE(fb->Attachment)); |
Tapani Pälli | 9762a9f | 2019-02-14 09:02:31 +0200 | [diff] [blame] | 5113 | return &fb->Attachment[BUFFER_COLOR0 + i]; |
| 5114 | } |
Rob Clark | 0c42b5f | 2018-11-01 11:10:46 -0400 | [diff] [blame] | 5115 | case GL_DEPTH: |
| 5116 | case GL_DEPTH_ATTACHMENT: |
| 5117 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 5118 | return &fb->Attachment[BUFFER_DEPTH]; |
| 5119 | case GL_STENCIL: |
| 5120 | case GL_STENCIL_ATTACHMENT: |
| 5121 | return &fb->Attachment[BUFFER_STENCIL]; |
| 5122 | default: |
| 5123 | return NULL; |
| 5124 | } |
| 5125 | } |
| 5126 | |
| 5127 | static void |
| 5128 | discard_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 5129 | GLsizei numAttachments, const GLenum *attachments) |
| 5130 | { |
| 5131 | if (!ctx->Driver.DiscardFramebuffer) |
| 5132 | return; |
| 5133 | |
| 5134 | for (int i = 0; i < numAttachments; i++) { |
| 5135 | struct gl_renderbuffer_attachment *att = |
| 5136 | get_fb_attachment(ctx, fb, attachments[i]); |
| 5137 | |
| 5138 | if (!att) |
| 5139 | continue; |
| 5140 | |
Eric Anholt | db2ae51 | 2019-01-30 09:33:53 -0800 | [diff] [blame] | 5141 | /* If we're asked to invalidate just depth or just stencil, but the |
| 5142 | * attachment is packed depth/stencil, then we can only use |
| 5143 | * Driver.DiscardFramebuffer if the attachments list includes both depth |
| 5144 | * and stencil and they both point at the same renderbuffer. |
| 5145 | */ |
| 5146 | if ((attachments[i] == GL_DEPTH_ATTACHMENT || |
| 5147 | attachments[i] == GL_STENCIL_ATTACHMENT) && |
| 5148 | (!att->Renderbuffer || |
| 5149 | att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL)) { |
| 5150 | GLenum other_format = (attachments[i] == GL_DEPTH_ATTACHMENT ? |
| 5151 | GL_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT); |
| 5152 | bool has_both = false; |
| 5153 | for (int j = 0; j < numAttachments; j++) { |
Eric Anholt | 3be4b89 | 2020-01-13 13:06:01 -0800 | [diff] [blame] | 5154 | if (attachments[j] == other_format) { |
Eric Anholt | db2ae51 | 2019-01-30 09:33:53 -0800 | [diff] [blame] | 5155 | has_both = true; |
Eric Anholt | 3be4b89 | 2020-01-13 13:06:01 -0800 | [diff] [blame] | 5156 | break; |
| 5157 | } |
Eric Anholt | db2ae51 | 2019-01-30 09:33:53 -0800 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | if (fb->Attachment[BUFFER_DEPTH].Renderbuffer != |
| 5161 | fb->Attachment[BUFFER_STENCIL].Renderbuffer || !has_both) |
| 5162 | continue; |
| 5163 | } |
| 5164 | |
Rob Clark | 0c42b5f | 2018-11-01 11:10:46 -0400 | [diff] [blame] | 5165 | ctx->Driver.DiscardFramebuffer(ctx, fb, att); |
| 5166 | } |
| 5167 | } |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 5168 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5169 | void GLAPIENTRY |
Samuel Pitoiset | c886492 | 2017-07-18 18:02:51 +0200 | [diff] [blame] | 5170 | _mesa_InvalidateSubFramebuffer_no_error(GLenum target, GLsizei numAttachments, |
| 5171 | const GLenum *attachments, GLint x, |
| 5172 | GLint y, GLsizei width, GLsizei height) |
| 5173 | { |
| 5174 | /* no-op */ |
| 5175 | } |
| 5176 | |
| 5177 | |
| 5178 | void GLAPIENTRY |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5179 | _mesa_InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, |
| 5180 | const GLenum *attachments, GLint x, GLint y, |
| 5181 | GLsizei width, GLsizei height) |
| 5182 | { |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 5183 | struct gl_framebuffer *fb; |
| 5184 | GET_CURRENT_CONTEXT(ctx); |
| 5185 | |
| 5186 | fb = get_framebuffer_target(ctx, target); |
| 5187 | if (!fb) { |
| 5188 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 5189 | "glInvalidateSubFramebuffer(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 5190 | _mesa_enum_to_string(target)); |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 5191 | return; |
| 5192 | } |
| 5193 | |
| 5194 | invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments, |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5195 | x, y, width, height, |
| 5196 | "glInvalidateSubFramebuffer"); |
| 5197 | } |
| 5198 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 5199 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5200 | void GLAPIENTRY |
Laura Ekstrand | d890fc7 | 2015-02-04 14:21:48 -0800 | [diff] [blame] | 5201 | _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer, |
| 5202 | GLsizei numAttachments, |
| 5203 | const GLenum *attachments, |
| 5204 | GLint x, GLint y, |
| 5205 | GLsizei width, GLsizei height) |
| 5206 | { |
| 5207 | struct gl_framebuffer *fb; |
| 5208 | GET_CURRENT_CONTEXT(ctx); |
| 5209 | |
| 5210 | /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole |
| 5211 | * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the |
| 5212 | * default draw framebuffer is affected." |
| 5213 | */ |
| 5214 | if (framebuffer) { |
| 5215 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 5216 | "glInvalidateNamedFramebufferSubData"); |
| 5217 | if (!fb) |
| 5218 | return; |
| 5219 | } |
| 5220 | else |
| 5221 | fb = ctx->WinSysDrawBuffer; |
| 5222 | |
| 5223 | invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments, |
| 5224 | x, y, width, height, |
| 5225 | "glInvalidateNamedFramebufferSubData"); |
| 5226 | } |
| 5227 | |
Laura Ekstrand | d890fc7 | 2015-02-04 14:21:48 -0800 | [diff] [blame] | 5228 | void GLAPIENTRY |
Samuel Pitoiset | c886492 | 2017-07-18 18:02:51 +0200 | [diff] [blame] | 5229 | _mesa_InvalidateFramebuffer_no_error(GLenum target, GLsizei numAttachments, |
| 5230 | const GLenum *attachments) |
| 5231 | { |
Rob Clark | 0c42b5f | 2018-11-01 11:10:46 -0400 | [diff] [blame] | 5232 | struct gl_framebuffer *fb; |
| 5233 | GET_CURRENT_CONTEXT(ctx); |
| 5234 | |
| 5235 | fb = get_framebuffer_target(ctx, target); |
| 5236 | if (!fb) |
| 5237 | return; |
| 5238 | |
| 5239 | discard_framebuffer(ctx, fb, numAttachments, attachments); |
Samuel Pitoiset | c886492 | 2017-07-18 18:02:51 +0200 | [diff] [blame] | 5240 | } |
| 5241 | |
| 5242 | |
| 5243 | void GLAPIENTRY |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5244 | _mesa_InvalidateFramebuffer(GLenum target, GLsizei numAttachments, |
| 5245 | const GLenum *attachments) |
| 5246 | { |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 5247 | struct gl_framebuffer *fb; |
| 5248 | GET_CURRENT_CONTEXT(ctx); |
| 5249 | |
| 5250 | fb = get_framebuffer_target(ctx, target); |
| 5251 | if (!fb) { |
| 5252 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 5253 | "glInvalidateFramebuffer(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 5254 | _mesa_enum_to_string(target)); |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 5255 | return; |
| 5256 | } |
| 5257 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5258 | /* The GL_ARB_invalidate_subdata spec says: |
| 5259 | * |
| 5260 | * "The command |
| 5261 | * |
| 5262 | * void InvalidateFramebuffer(enum target, |
| 5263 | * sizei numAttachments, |
| 5264 | * const enum *attachments); |
| 5265 | * |
| 5266 | * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>, |
| 5267 | * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>, |
| 5268 | * <MAX_VIEWPORT_DIMS[1]> respectively." |
| 5269 | */ |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 5270 | invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments, |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 5271 | 0, 0, |
Samuel Iglesias Gonsálvez | aa849d9 | 2016-03-01 12:02:27 +0100 | [diff] [blame] | 5272 | ctx->Const.MaxViewportWidth, |
| 5273 | ctx->Const.MaxViewportHeight, |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5274 | "glInvalidateFramebuffer"); |
Rob Clark | 0c42b5f | 2018-11-01 11:10:46 -0400 | [diff] [blame] | 5275 | |
| 5276 | discard_framebuffer(ctx, fb, numAttachments, attachments); |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 5277 | } |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 5278 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 5279 | |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 5280 | void GLAPIENTRY |
Laura Ekstrand | d890fc7 | 2015-02-04 14:21:48 -0800 | [diff] [blame] | 5281 | _mesa_InvalidateNamedFramebufferData(GLuint framebuffer, |
| 5282 | GLsizei numAttachments, |
| 5283 | const GLenum *attachments) |
| 5284 | { |
| 5285 | struct gl_framebuffer *fb; |
| 5286 | GET_CURRENT_CONTEXT(ctx); |
| 5287 | |
| 5288 | /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole |
| 5289 | * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the |
| 5290 | * default draw framebuffer is affected." |
| 5291 | */ |
| 5292 | if (framebuffer) { |
| 5293 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 5294 | "glInvalidateNamedFramebufferData"); |
| 5295 | if (!fb) |
| 5296 | return; |
| 5297 | } |
| 5298 | else |
| 5299 | fb = ctx->WinSysDrawBuffer; |
| 5300 | |
| 5301 | /* The GL_ARB_invalidate_subdata spec says: |
| 5302 | * |
| 5303 | * "The command |
| 5304 | * |
| 5305 | * void InvalidateFramebuffer(enum target, |
| 5306 | * sizei numAttachments, |
| 5307 | * const enum *attachments); |
| 5308 | * |
| 5309 | * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>, |
| 5310 | * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>, |
| 5311 | * <MAX_VIEWPORT_DIMS[1]> respectively." |
| 5312 | */ |
| 5313 | invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments, |
| 5314 | 0, 0, |
Samuel Iglesias Gonsálvez | aa849d9 | 2016-03-01 12:02:27 +0100 | [diff] [blame] | 5315 | ctx->Const.MaxViewportWidth, |
| 5316 | ctx->Const.MaxViewportHeight, |
Laura Ekstrand | d890fc7 | 2015-02-04 14:21:48 -0800 | [diff] [blame] | 5317 | "glInvalidateNamedFramebufferData"); |
| 5318 | } |
| 5319 | |
| 5320 | |
| 5321 | void GLAPIENTRY |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 5322 | _mesa_DiscardFramebufferEXT(GLenum target, GLsizei numAttachments, |
| 5323 | const GLenum *attachments) |
| 5324 | { |
| 5325 | struct gl_framebuffer *fb; |
| 5326 | GLint i; |
| 5327 | |
| 5328 | GET_CURRENT_CONTEXT(ctx); |
| 5329 | |
| 5330 | fb = get_framebuffer_target(ctx, target); |
| 5331 | if (!fb) { |
| 5332 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 5333 | "glDiscardFramebufferEXT(target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 5334 | _mesa_enum_to_string(target)); |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 5335 | return; |
| 5336 | } |
| 5337 | |
| 5338 | if (numAttachments < 0) { |
| 5339 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 5340 | "glDiscardFramebufferEXT(numAttachments < 0)"); |
| 5341 | return; |
| 5342 | } |
| 5343 | |
| 5344 | for (i = 0; i < numAttachments; i++) { |
| 5345 | switch (attachments[i]) { |
| 5346 | case GL_COLOR: |
| 5347 | case GL_DEPTH: |
| 5348 | case GL_STENCIL: |
| 5349 | if (_mesa_is_user_fbo(fb)) |
| 5350 | goto invalid_enum; |
| 5351 | break; |
| 5352 | case GL_COLOR_ATTACHMENT0: |
| 5353 | case GL_DEPTH_ATTACHMENT: |
| 5354 | case GL_STENCIL_ATTACHMENT: |
| 5355 | if (_mesa_is_winsys_fbo(fb)) |
| 5356 | goto invalid_enum; |
| 5357 | break; |
| 5358 | default: |
| 5359 | goto invalid_enum; |
| 5360 | } |
| 5361 | } |
| 5362 | |
Rob Clark | 0c42b5f | 2018-11-01 11:10:46 -0400 | [diff] [blame] | 5363 | discard_framebuffer(ctx, fb, numAttachments, attachments); |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 5364 | |
| 5365 | return; |
| 5366 | |
| 5367 | invalid_enum: |
| 5368 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 5369 | "glDiscardFramebufferEXT(attachment %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 5370 | _mesa_enum_to_string(attachments[i])); |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 5371 | } |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 5372 | |
| 5373 | static void |
| 5374 | sample_locations(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 5375 | GLuint start, GLsizei count, const GLfloat *v, bool no_error, |
| 5376 | const char *name) |
| 5377 | { |
| 5378 | GLsizei i; |
| 5379 | |
| 5380 | if (!no_error) { |
| 5381 | if (!ctx->Extensions.ARB_sample_locations) { |
| 5382 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 5383 | "%s not supported " |
| 5384 | "(ARB_sample_locations not available)", name); |
| 5385 | return; |
| 5386 | } |
| 5387 | |
| 5388 | if (start + count > MAX_SAMPLE_LOCATION_TABLE_SIZE) { |
| 5389 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 5390 | "%s(start+size > sample location table size)", name); |
| 5391 | return; |
| 5392 | } |
| 5393 | } |
| 5394 | |
| 5395 | if (!fb->SampleLocationTable) { |
| 5396 | size_t size = MAX_SAMPLE_LOCATION_TABLE_SIZE * 2 * sizeof(GLfloat); |
| 5397 | fb->SampleLocationTable = malloc(size); |
Eric Engestrom | 9a4bd6b | 2018-06-18 11:39:05 +0100 | [diff] [blame] | 5398 | if (!fb->SampleLocationTable) { |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 5399 | _mesa_error(ctx, GL_OUT_OF_MEMORY, |
| 5400 | "Cannot allocate sample location table"); |
Eric Engestrom | 9a4bd6b | 2018-06-18 11:39:05 +0100 | [diff] [blame] | 5401 | return; |
| 5402 | } |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 5403 | for (i = 0; i < MAX_SAMPLE_LOCATION_TABLE_SIZE * 2; i++) |
| 5404 | fb->SampleLocationTable[i] = 0.5f; |
| 5405 | } |
| 5406 | |
| 5407 | for (i = 0; i < count * 2; i++) { |
| 5408 | /* The ARB_sample_locations spec says: |
| 5409 | * |
| 5410 | * Sample locations outside of [0,1] result in undefined |
| 5411 | * behavior. |
| 5412 | * |
| 5413 | * To simplify driver implementations, we choose to clamp to |
| 5414 | * [0,1] and change NaN into 0.5. |
| 5415 | */ |
| 5416 | if (isnan(v[i]) || v[i] < 0.0f || v[i] > 1.0f) { |
| 5417 | static GLuint msg_id = 0; |
| 5418 | static const char* msg = "Invalid sample location specified"; |
| 5419 | _mesa_debug_get_id(&msg_id); |
| 5420 | |
| 5421 | _mesa_log_msg(ctx, MESA_DEBUG_SOURCE_API, MESA_DEBUG_TYPE_UNDEFINED, |
| 5422 | msg_id, MESA_DEBUG_SEVERITY_HIGH, strlen(msg), msg); |
| 5423 | } |
| 5424 | |
| 5425 | if (isnan(v[i])) |
| 5426 | fb->SampleLocationTable[start * 2 + i] = 0.5f; |
| 5427 | else |
Alyssa Rosenzweig | 05bacdb | 2020-05-19 11:08:51 -0400 | [diff] [blame] | 5428 | fb->SampleLocationTable[start * 2 + i] = SATURATE(v[i]); |
Rhys Perry | 67f40da | 2018-06-14 19:56:28 -0600 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | if (fb == ctx->DrawBuffer) |
| 5432 | ctx->NewDriverState |= ctx->DriverFlags.NewSampleLocations; |
| 5433 | } |
| 5434 | |
| 5435 | void GLAPIENTRY |
| 5436 | _mesa_FramebufferSampleLocationsfvARB(GLenum target, GLuint start, |
| 5437 | GLsizei count, const GLfloat *v) |
| 5438 | { |
| 5439 | struct gl_framebuffer *fb; |
| 5440 | |
| 5441 | GET_CURRENT_CONTEXT(ctx); |
| 5442 | |
| 5443 | fb = get_framebuffer_target(ctx, target); |
| 5444 | if (!fb) { |
| 5445 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 5446 | "glFramebufferSampleLocationsfvARB(target %s)", |
| 5447 | _mesa_enum_to_string(target)); |
| 5448 | return; |
| 5449 | } |
| 5450 | |
| 5451 | sample_locations(ctx, fb, start, count, v, false, |
| 5452 | "glFramebufferSampleLocationsfvARB"); |
| 5453 | } |
| 5454 | |
| 5455 | void GLAPIENTRY |
| 5456 | _mesa_NamedFramebufferSampleLocationsfvARB(GLuint framebuffer, GLuint start, |
| 5457 | GLsizei count, const GLfloat *v) |
| 5458 | { |
| 5459 | struct gl_framebuffer *fb; |
| 5460 | |
| 5461 | GET_CURRENT_CONTEXT(ctx); |
| 5462 | |
| 5463 | if (framebuffer) { |
| 5464 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 5465 | "glNamedFramebufferSampleLocationsfvARB"); |
| 5466 | if (!fb) |
| 5467 | return; |
| 5468 | } |
| 5469 | else |
| 5470 | fb = ctx->WinSysDrawBuffer; |
| 5471 | |
| 5472 | sample_locations(ctx, fb, start, count, v, false, |
| 5473 | "glNamedFramebufferSampleLocationsfvARB"); |
| 5474 | } |
| 5475 | |
| 5476 | void GLAPIENTRY |
| 5477 | _mesa_FramebufferSampleLocationsfvARB_no_error(GLenum target, GLuint start, |
| 5478 | GLsizei count, const GLfloat *v) |
| 5479 | { |
| 5480 | GET_CURRENT_CONTEXT(ctx); |
| 5481 | sample_locations(ctx, get_framebuffer_target(ctx, target), start, |
| 5482 | count, v, true, "glFramebufferSampleLocationsfvARB"); |
| 5483 | } |
| 5484 | |
| 5485 | void GLAPIENTRY |
| 5486 | _mesa_NamedFramebufferSampleLocationsfvARB_no_error(GLuint framebuffer, |
| 5487 | GLuint start, GLsizei count, |
| 5488 | const GLfloat *v) |
| 5489 | { |
| 5490 | GET_CURRENT_CONTEXT(ctx); |
| 5491 | sample_locations(ctx, _mesa_lookup_framebuffer(ctx, framebuffer), start, |
| 5492 | count, v, true, "glNamedFramebufferSampleLocationsfvARB"); |
| 5493 | } |
| 5494 | |
| 5495 | void GLAPIENTRY |
| 5496 | _mesa_EvaluateDepthValuesARB(void) |
| 5497 | { |
| 5498 | GET_CURRENT_CONTEXT(ctx); |
| 5499 | |
| 5500 | if (!ctx->Extensions.ARB_sample_locations) { |
| 5501 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 5502 | "EvaluateDepthValuesARB not supported (neither " |
| 5503 | "ARB_sample_locations nor NV_sample_locations is available)"); |
| 5504 | return; |
| 5505 | } |
| 5506 | |
| 5507 | if (ctx->Driver.EvaluateDepthValues) |
| 5508 | ctx->Driver.EvaluateDepthValues(ctx); |
| 5509 | } |