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