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" |
Brian Paul | 9b50cea | 2009-10-23 11:34:14 -0600 | [diff] [blame] | 38 | #include "enums.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 39 | #include "fbobject.h" |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 40 | #include "formats.h" |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 41 | #include "framebuffer.h" |
Brian Paul | a1287f5 | 2012-07-22 11:20:00 -0600 | [diff] [blame] | 42 | #include "glformats.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 43 | #include "hash.h" |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 44 | #include "macros.h" |
Chris Forbes | 90b5a24 | 2013-02-06 20:42:53 +1300 | [diff] [blame] | 45 | #include "multisample.h" |
Vinson Lee | 0117da4 | 2011-01-05 23:11:54 -0800 | [diff] [blame] | 46 | #include "mtypes.h" |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 47 | #include "renderbuffer.h" |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 48 | #include "state.h" |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 49 | #include "teximage.h" |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 50 | #include "texobj.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 51 | |
| 52 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 53 | /** |
| 54 | * Notes: |
| 55 | * |
| 56 | * None of the GL_EXT_framebuffer_object functions are compiled into |
| 57 | * display lists. |
| 58 | */ |
| 59 | |
| 60 | |
| 61 | |
Brian Paul | 923b6fc | 2005-02-08 04:08:56 +0000 | [diff] [blame] | 62 | /* |
| 63 | * When glGenRender/FramebuffersEXT() is called we insert pointers to |
| 64 | * these placeholder objects into the hash table. |
| 65 | * Later, when the object ID is first bound, we replace the placeholder |
| 66 | * with the real frame/renderbuffer. |
| 67 | */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 68 | static struct gl_framebuffer DummyFramebuffer; |
| 69 | static struct gl_renderbuffer DummyRenderbuffer; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 70 | |
Kristian Høgsberg | 144356f | 2010-09-09 17:08:12 -0400 | [diff] [blame] | 71 | /* We bind this framebuffer when applications pass a NULL |
| 72 | * drawable/surface in make current. */ |
| 73 | static struct gl_framebuffer IncompleteFramebuffer; |
| 74 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 75 | |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 76 | static void |
Brian Paul | c732458 | 2012-11-30 10:04:48 -0700 | [diff] [blame] | 77 | delete_dummy_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb) |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 78 | { |
| 79 | /* no op */ |
| 80 | } |
| 81 | |
| 82 | static void |
| 83 | delete_dummy_framebuffer(struct gl_framebuffer *fb) |
| 84 | { |
| 85 | /* no op */ |
| 86 | } |
| 87 | |
| 88 | |
| 89 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 90 | _mesa_init_fbobjects(struct gl_context *ctx) |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 91 | { |
Brian Paul | d129ea7 | 2014-03-01 10:21:07 -0700 | [diff] [blame] | 92 | mtx_init(&DummyFramebuffer.Mutex, mtx_plain); |
| 93 | mtx_init(&DummyRenderbuffer.Mutex, mtx_plain); |
| 94 | mtx_init(&IncompleteFramebuffer.Mutex, mtx_plain); |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 95 | DummyFramebuffer.Delete = delete_dummy_framebuffer; |
| 96 | DummyRenderbuffer.Delete = delete_dummy_renderbuffer; |
Kristian Høgsberg | 144356f | 2010-09-09 17:08:12 -0400 | [diff] [blame] | 97 | IncompleteFramebuffer.Delete = delete_dummy_framebuffer; |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 98 | } |
| 99 | |
Kristian Høgsberg | 9456e22 | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 100 | struct gl_framebuffer * |
| 101 | _mesa_get_incomplete_framebuffer(void) |
| 102 | { |
Kristian Høgsberg | 144356f | 2010-09-09 17:08:12 -0400 | [diff] [blame] | 103 | return &IncompleteFramebuffer; |
Kristian Høgsberg | 9456e22 | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 104 | } |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 105 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 106 | /** |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 107 | * Helper routine for getting a gl_renderbuffer. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 108 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 109 | struct gl_renderbuffer * |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 110 | _mesa_lookup_renderbuffer(struct gl_context *ctx, GLuint id) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 111 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 112 | struct gl_renderbuffer *rb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 113 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 114 | if (id == 0) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 115 | return NULL; |
| 116 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 117 | rb = (struct gl_renderbuffer *) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 118 | _mesa_HashLookup(ctx->Shared->RenderBuffers, id); |
| 119 | return rb; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /** |
Laura Ekstrand | 2bb138e | 2015-01-23 16:38:36 -0800 | [diff] [blame] | 124 | * A convenience function for direct state access that throws |
| 125 | * GL_INVALID_OPERATION if the renderbuffer doesn't exist. |
| 126 | */ |
| 127 | struct gl_renderbuffer * |
| 128 | _mesa_lookup_renderbuffer_err(struct gl_context *ctx, GLuint id, |
| 129 | const char *func) |
| 130 | { |
| 131 | struct gl_renderbuffer *rb; |
| 132 | |
| 133 | rb = _mesa_lookup_renderbuffer(ctx, id); |
| 134 | if (!rb || rb == &DummyRenderbuffer) { |
| 135 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 136 | "%s(non-existent renderbuffer %u)", func, id); |
| 137 | return NULL; |
| 138 | } |
| 139 | |
| 140 | return rb; |
| 141 | } |
| 142 | |
| 143 | |
| 144 | /** |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 145 | * Helper routine for getting a gl_framebuffer. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 146 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 147 | struct gl_framebuffer * |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 148 | _mesa_lookup_framebuffer(struct gl_context *ctx, GLuint id) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 149 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 150 | struct gl_framebuffer *fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 151 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 152 | if (id == 0) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 153 | return NULL; |
| 154 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 155 | fb = (struct gl_framebuffer *) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 156 | _mesa_HashLookup(ctx->Shared->FrameBuffers, id); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 157 | return fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
| 161 | /** |
Laura Ekstrand | 6d8eff4 | 2015-01-22 10:23:35 -0800 | [diff] [blame] | 162 | * A convenience function for direct state access that throws |
| 163 | * GL_INVALID_OPERATION if the framebuffer doesn't exist. |
| 164 | */ |
| 165 | struct gl_framebuffer * |
| 166 | _mesa_lookup_framebuffer_err(struct gl_context *ctx, GLuint id, |
| 167 | const char *func) |
| 168 | { |
| 169 | struct gl_framebuffer *fb; |
| 170 | |
| 171 | fb = _mesa_lookup_framebuffer(ctx, id); |
| 172 | if (!fb || fb == &DummyFramebuffer) { |
| 173 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 174 | "%s(non-existent framebuffer %u)", func, id); |
| 175 | return NULL; |
| 176 | } |
| 177 | |
| 178 | return fb; |
| 179 | } |
| 180 | |
| 181 | |
| 182 | /** |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 183 | * Mark the given framebuffer as invalid. This will force the |
| 184 | * test for framebuffer completeness to be done before the framebuffer |
| 185 | * is used. |
| 186 | */ |
| 187 | static void |
| 188 | invalidate_framebuffer(struct gl_framebuffer *fb) |
| 189 | { |
| 190 | fb->_Status = 0; /* "indeterminate" */ |
| 191 | } |
| 192 | |
| 193 | |
| 194 | /** |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 195 | * Return the gl_framebuffer object which corresponds to the given |
| 196 | * framebuffer target, such as GL_DRAW_FRAMEBUFFER. |
| 197 | * Check support for GL_EXT_framebuffer_blit to determine if certain |
| 198 | * targets are legal. |
| 199 | * \return gl_framebuffer pointer or NULL if target is illegal |
| 200 | */ |
| 201 | static struct gl_framebuffer * |
| 202 | get_framebuffer_target(struct gl_context *ctx, GLenum target) |
| 203 | { |
Ian Romanick | a672973 | 2013-11-13 13:30:37 -0800 | [diff] [blame] | 204 | 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] | 205 | switch (target) { |
| 206 | case GL_DRAW_FRAMEBUFFER: |
Kenneth Graunke | c6ed42a | 2012-11-17 23:23:06 -0800 | [diff] [blame] | 207 | return have_fb_blit ? ctx->DrawBuffer : NULL; |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 208 | case GL_READ_FRAMEBUFFER: |
Kenneth Graunke | c6ed42a | 2012-11-17 23:23:06 -0800 | [diff] [blame] | 209 | return have_fb_blit ? ctx->ReadBuffer : NULL; |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 210 | case GL_FRAMEBUFFER_EXT: |
| 211 | return ctx->DrawBuffer; |
| 212 | default: |
| 213 | return NULL; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | |
| 218 | /** |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 219 | * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 220 | * gl_renderbuffer_attachment object. |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 221 | * This function is only used for user-created FB objects, not the |
| 222 | * default / window-system FB object. |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 223 | * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to |
| 224 | * the depth buffer attachment point. |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 225 | */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 226 | static struct gl_renderbuffer_attachment * |
| 227 | get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 228 | GLenum attachment) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 229 | { |
| 230 | GLuint i; |
| 231 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 232 | assert(_mesa_is_user_fbo(fb)); |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 233 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 234 | switch (attachment) { |
| 235 | case GL_COLOR_ATTACHMENT0_EXT: |
| 236 | case GL_COLOR_ATTACHMENT1_EXT: |
| 237 | case GL_COLOR_ATTACHMENT2_EXT: |
| 238 | case GL_COLOR_ATTACHMENT3_EXT: |
| 239 | case GL_COLOR_ATTACHMENT4_EXT: |
| 240 | case GL_COLOR_ATTACHMENT5_EXT: |
| 241 | case GL_COLOR_ATTACHMENT6_EXT: |
| 242 | case GL_COLOR_ATTACHMENT7_EXT: |
| 243 | case GL_COLOR_ATTACHMENT8_EXT: |
| 244 | case GL_COLOR_ATTACHMENT9_EXT: |
| 245 | case GL_COLOR_ATTACHMENT10_EXT: |
| 246 | case GL_COLOR_ATTACHMENT11_EXT: |
| 247 | case GL_COLOR_ATTACHMENT12_EXT: |
| 248 | case GL_COLOR_ATTACHMENT13_EXT: |
| 249 | case GL_COLOR_ATTACHMENT14_EXT: |
| 250 | case GL_COLOR_ATTACHMENT15_EXT: |
Ian Romanick | 2e3a4ab | 2011-10-02 15:03:07 -0700 | [diff] [blame] | 251 | /* Only OpenGL ES 1.x forbids color attachments other than |
| 252 | * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the |
| 253 | * hardware is used. |
| 254 | */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 255 | i = attachment - GL_COLOR_ATTACHMENT0_EXT; |
Ian Romanick | 7e4cb32 | 2011-10-02 14:50:21 -0700 | [diff] [blame] | 256 | if (i >= ctx->Const.MaxColorAttachments |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 257 | || (i > 0 && ctx->API == API_OPENGLES)) { |
| 258 | return NULL; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 259 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 260 | return &fb->Attachment[BUFFER_COLOR0 + i]; |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 261 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Matt Turner | ec8ee91 | 2012-11-15 22:13:48 -0800 | [diff] [blame] | 262 | if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 263 | return NULL; |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 264 | /* fall-through */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 265 | case GL_DEPTH_ATTACHMENT_EXT: |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 266 | return &fb->Attachment[BUFFER_DEPTH]; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 267 | case GL_STENCIL_ATTACHMENT_EXT: |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 268 | return &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 269 | default: |
| 270 | return NULL; |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | |
| 275 | /** |
| 276 | * As above, but only used for getting attachments of the default / |
| 277 | * window-system framebuffer (not user-created framebuffer objects). |
| 278 | */ |
| 279 | static struct gl_renderbuffer_attachment * |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 280 | _mesa_get_fb0_attachment(struct gl_context *ctx, struct gl_framebuffer *fb, |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 281 | GLenum attachment) |
| 282 | { |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 283 | assert(_mesa_is_winsys_fbo(fb)); |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 284 | |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 285 | if (_mesa_is_gles3(ctx)) { |
| 286 | assert(attachment == GL_BACK || |
| 287 | attachment == GL_DEPTH || |
| 288 | attachment == GL_STENCIL); |
| 289 | switch (attachment) { |
| 290 | case GL_BACK: |
| 291 | /* Since there is no stereo rendering in ES 3.0, only return the |
| 292 | * LEFT bits. |
| 293 | */ |
| 294 | if (ctx->DrawBuffer->Visual.doubleBufferMode) |
| 295 | return &fb->Attachment[BUFFER_BACK_LEFT]; |
| 296 | return &fb->Attachment[BUFFER_FRONT_LEFT]; |
| 297 | case GL_DEPTH: |
| 298 | return &fb->Attachment[BUFFER_DEPTH]; |
| 299 | case GL_STENCIL: |
| 300 | return &fb->Attachment[BUFFER_STENCIL]; |
| 301 | } |
| 302 | } |
| 303 | |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 304 | switch (attachment) { |
Kristian Høgsberg | 80dfec3 | 2010-06-15 13:07:01 -0400 | [diff] [blame] | 305 | case GL_FRONT_LEFT: |
| 306 | return &fb->Attachment[BUFFER_FRONT_LEFT]; |
| 307 | case GL_FRONT_RIGHT: |
| 308 | return &fb->Attachment[BUFFER_FRONT_RIGHT]; |
| 309 | case GL_BACK_LEFT: |
| 310 | return &fb->Attachment[BUFFER_BACK_LEFT]; |
| 311 | case GL_BACK_RIGHT: |
| 312 | return &fb->Attachment[BUFFER_BACK_RIGHT]; |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 313 | case GL_AUX0: |
| 314 | if (fb->Visual.numAuxBuffers == 1) { |
| 315 | return &fb->Attachment[BUFFER_AUX0]; |
| 316 | } |
| 317 | return NULL; |
Ian Romanick | a8328cc | 2011-10-03 12:02:18 -0700 | [diff] [blame] | 318 | |
| 319 | /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says: |
| 320 | * |
| 321 | * "If the default framebuffer is bound to target, then attachment must |
| 322 | * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi, |
| 323 | * identifying a color buffer; DEPTH, identifying the depth buffer; or |
| 324 | * STENCIL, identifying the stencil buffer." |
| 325 | * |
| 326 | * Revision #34 of the ARB_framebuffer_object spec has essentially the same |
| 327 | * language. However, revision #33 of the ARB_framebuffer_object spec |
| 328 | * says: |
| 329 | * |
| 330 | * "If the default framebuffer is bound to <target>, then <attachment> |
| 331 | * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi, |
| 332 | * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the |
| 333 | * depth buffer, or the stencil buffer, and <pname> may be |
| 334 | * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or |
| 335 | * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME." |
| 336 | * |
| 337 | * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed |
| 338 | * from glext.h, so shipping apps should not use those values. |
| 339 | * |
| 340 | * Note that neither EXT_framebuffer_object nor OES_framebuffer_object |
| 341 | * support queries of the window system FBO. |
| 342 | */ |
| 343 | case GL_DEPTH: |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 344 | return &fb->Attachment[BUFFER_DEPTH]; |
Ian Romanick | a8328cc | 2011-10-03 12:02:18 -0700 | [diff] [blame] | 345 | case GL_STENCIL: |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 346 | return &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 347 | default: |
| 348 | return NULL; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 353 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 354 | /** |
| 355 | * Remove any texture or renderbuffer attached to the given attachment |
| 356 | * point. Update reference counts, etc. |
| 357 | */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 358 | static void |
| 359 | remove_attachment(struct gl_context *ctx, |
| 360 | struct gl_renderbuffer_attachment *att) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 361 | { |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 362 | struct gl_renderbuffer *rb = att->Renderbuffer; |
| 363 | |
| 364 | /* tell driver that we're done rendering to this texture. */ |
| 365 | if (rb && rb->NeedsFinishRenderTexture) |
Eric Anholt | a5b0452 | 2013-05-10 12:17:52 -0700 | [diff] [blame] | 366 | ctx->Driver.FinishRenderTexture(ctx, rb); |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 367 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 368 | if (att->Type == GL_TEXTURE) { |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 369 | assert(att->Texture); |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 370 | _mesa_reference_texobj(&att->Texture, NULL); /* unbind */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 371 | assert(!att->Texture); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 372 | } |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 373 | if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) { |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 374 | assert(!att->Texture); |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 375 | _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 376 | assert(!att->Renderbuffer); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 377 | } |
| 378 | att->Type = GL_NONE; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 379 | att->Complete = GL_TRUE; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 382 | /** |
Ian Romanick | fb49713 | 2013-07-27 12:04:20 -0700 | [diff] [blame] | 383 | * Verify a couple error conditions that will lead to an incomplete FBO and |
| 384 | * may cause problems for the driver's RenderTexture path. |
| 385 | */ |
| 386 | static bool |
| 387 | driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment *att) |
| 388 | { |
| 389 | const struct gl_texture_image *const texImage = |
| 390 | att->Texture->Image[att->CubeMapFace][att->TextureLevel]; |
| 391 | |
| 392 | if (texImage->Width == 0 || texImage->Height == 0 || texImage->Depth == 0) |
| 393 | return false; |
| 394 | |
Ian Romanick | 41485fe | 2013-07-27 12:16:56 -0700 | [diff] [blame] | 395 | if ((texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY |
| 396 | && att->Zoffset >= texImage->Height) |
| 397 | || (texImage->TexObject->Target != GL_TEXTURE_1D_ARRAY |
| 398 | && att->Zoffset >= texImage->Depth)) |
| 399 | return false; |
| 400 | |
Ian Romanick | fb49713 | 2013-07-27 12:04:20 -0700 | [diff] [blame] | 401 | return true; |
| 402 | } |
| 403 | |
| 404 | /** |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 405 | * Create a renderbuffer which will be set up by the driver to wrap the |
| 406 | * texture image slice. |
| 407 | * |
| 408 | * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get |
| 409 | * to share most of their framebuffer rendering code between winsys, |
| 410 | * renderbuffer, and texture attachments. |
| 411 | * |
| 412 | * The allocated renderbuffer uses a non-zero Name so that drivers can check |
| 413 | * it for determining vertical orientation, but we use ~0 to make it fairly |
| 414 | * unambiguous with actual user (non-texture) renderbuffers. |
| 415 | */ |
| 416 | void |
| 417 | _mesa_update_texture_renderbuffer(struct gl_context *ctx, |
| 418 | struct gl_framebuffer *fb, |
| 419 | struct gl_renderbuffer_attachment *att) |
| 420 | { |
| 421 | struct gl_texture_image *texImage; |
| 422 | struct gl_renderbuffer *rb; |
| 423 | |
Eric Anholt | e98c39c | 2013-05-10 11:51:01 -0700 | [diff] [blame] | 424 | texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel]; |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 425 | |
| 426 | rb = att->Renderbuffer; |
| 427 | if (!rb) { |
| 428 | rb = ctx->Driver.NewRenderbuffer(ctx, ~0); |
| 429 | if (!rb) { |
| 430 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()"); |
| 431 | return; |
| 432 | } |
| 433 | _mesa_reference_renderbuffer(&att->Renderbuffer, rb); |
| 434 | |
| 435 | /* This can't get called on a texture renderbuffer, so set it to NULL |
| 436 | * for clarity compared to user renderbuffers. |
| 437 | */ |
| 438 | rb->AllocStorage = NULL; |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 439 | |
| 440 | rb->NeedsFinishRenderTexture = ctx->Driver.FinishRenderTexture != NULL; |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Ian Romanick | 2f9fe2d | 2013-07-28 13:08:27 -0700 | [diff] [blame] | 443 | if (!texImage) |
| 444 | return; |
| 445 | |
Eric Anholt | 77a405d | 2013-04-22 11:04:21 -0700 | [diff] [blame] | 446 | rb->_BaseFormat = texImage->_BaseFormat; |
| 447 | rb->Format = texImage->TexFormat; |
| 448 | rb->InternalFormat = texImage->InternalFormat; |
| 449 | rb->Width = texImage->Width2; |
| 450 | rb->Height = texImage->Height2; |
Marek Olšák | a3969aa | 2013-11-20 01:47:36 +0100 | [diff] [blame] | 451 | rb->Depth = texImage->Depth2; |
Eric Anholt | 77a405d | 2013-04-22 11:04:21 -0700 | [diff] [blame] | 452 | rb->NumSamples = texImage->NumSamples; |
Eric Anholt | e98c39c | 2013-05-10 11:51:01 -0700 | [diff] [blame] | 453 | rb->TexImage = texImage; |
Eric Anholt | 77a405d | 2013-04-22 11:04:21 -0700 | [diff] [blame] | 454 | |
Ian Romanick | fb49713 | 2013-07-27 12:04:20 -0700 | [diff] [blame] | 455 | if (driver_RenderTexture_is_safe(att)) |
| 456 | ctx->Driver.RenderTexture(ctx, fb, att); |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 457 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 458 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 459 | /** |
| 460 | * Bind a texture object to an attachment point. |
| 461 | * The previous binding, if any, will be removed first. |
| 462 | */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 463 | static void |
| 464 | set_texture_attachment(struct gl_context *ctx, |
| 465 | struct gl_framebuffer *fb, |
| 466 | struct gl_renderbuffer_attachment *att, |
| 467 | struct gl_texture_object *texObj, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 468 | GLenum texTarget, GLuint level, GLuint layer, |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 469 | GLboolean layered) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 470 | { |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 471 | struct gl_renderbuffer *rb = att->Renderbuffer; |
| 472 | |
| 473 | if (rb && rb->NeedsFinishRenderTexture) |
Eric Anholt | a5b0452 | 2013-05-10 12:17:52 -0700 | [diff] [blame] | 474 | ctx->Driver.FinishRenderTexture(ctx, rb); |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 475 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 476 | if (att->Texture == texObj) { |
| 477 | /* re-attaching same texture */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 478 | assert(att->Type == GL_TEXTURE); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 479 | } |
| 480 | else { |
| 481 | /* new attachment */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 482 | remove_attachment(ctx, att); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 483 | att->Type = GL_TEXTURE; |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 484 | assert(!att->Texture); |
| 485 | _mesa_reference_texobj(&att->Texture, texObj); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 486 | } |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 487 | invalidate_framebuffer(fb); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 488 | |
| 489 | /* always update these fields */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 490 | att->TextureLevel = level; |
Brian Paul | 26f1ad6 | 2009-10-23 18:15:55 -0600 | [diff] [blame] | 491 | att->CubeMapFace = _mesa_tex_target_to_face(texTarget); |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 492 | att->Zoffset = layer; |
Jordan Justen | a628080 | 2013-04-18 10:08:50 -0700 | [diff] [blame] | 493 | att->Layered = layered; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 494 | att->Complete = GL_FALSE; |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 495 | |
Eric Anholt | 749a927 | 2013-04-22 10:38:41 -0700 | [diff] [blame] | 496 | _mesa_update_texture_renderbuffer(ctx, fb, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 500 | /** |
| 501 | * Bind a renderbuffer to an attachment point. |
| 502 | * The previous binding, if any, will be removed first. |
| 503 | */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 504 | static void |
| 505 | set_renderbuffer_attachment(struct gl_context *ctx, |
| 506 | struct gl_renderbuffer_attachment *att, |
| 507 | struct gl_renderbuffer *rb) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 508 | { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 509 | /* XXX check if re-doing same attachment, exit early */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 510 | remove_attachment(ctx, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 511 | att->Type = GL_RENDERBUFFER_EXT; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 512 | att->Texture = NULL; /* just to be safe */ |
James Legg | 1581e12 | 2015-02-07 23:33:15 +0000 | [diff] [blame] | 513 | att->Layered = GL_FALSE; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 514 | att->Complete = GL_FALSE; |
Brian | dccd9c4 | 2007-04-02 09:56:28 -0600 | [diff] [blame] | 515 | _mesa_reference_renderbuffer(&att->Renderbuffer, rb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 518 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 519 | /** |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 520 | * Fallback for ctx->Driver.FramebufferRenderbuffer() |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 521 | * Attach a renderbuffer object to a framebuffer object. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 522 | */ |
| 523 | void |
Laura Ekstrand | 3d10037 | 2015-02-27 17:23:59 -0800 | [diff] [blame] | 524 | _mesa_FramebufferRenderbuffer_sw(struct gl_context *ctx, |
| 525 | struct gl_framebuffer *fb, |
| 526 | GLenum attachment, |
| 527 | struct gl_renderbuffer *rb) |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 528 | { |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 529 | struct gl_renderbuffer_attachment *att; |
| 530 | |
Brian Paul | d129ea7 | 2014-03-01 10:21:07 -0700 | [diff] [blame] | 531 | mtx_lock(&fb->Mutex); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 532 | |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 533 | att = get_attachment(ctx, fb, attachment); |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 534 | assert(att); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 535 | if (rb) { |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 536 | set_renderbuffer_attachment(ctx, att, rb); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 537 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 538 | /* do stencil attachment here (depth already done above) */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 539 | att = get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 540 | assert(att); |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 541 | set_renderbuffer_attachment(ctx, att, rb); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 542 | } |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 543 | rb->AttachedAnytime = GL_TRUE; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 544 | } |
| 545 | else { |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 546 | remove_attachment(ctx, att); |
James Legg | 846c715 | 2014-05-23 12:25:37 +0100 | [diff] [blame] | 547 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 548 | /* detach stencil (depth was detached above) */ |
| 549 | att = get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT); |
| 550 | assert(att); |
| 551 | remove_attachment(ctx, att); |
| 552 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 553 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 554 | |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 555 | invalidate_framebuffer(fb); |
| 556 | |
Brian Paul | d129ea7 | 2014-03-01 10:21:07 -0700 | [diff] [blame] | 557 | mtx_unlock(&fb->Mutex); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | |
| 561 | /** |
Brian Paul | 62c66b3 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 562 | * Fallback for ctx->Driver.ValidateFramebuffer() |
| 563 | * Check if the renderbuffer's formats are supported by the software |
| 564 | * renderer. |
| 565 | * Drivers should probably override this. |
| 566 | */ |
| 567 | void |
| 568 | _mesa_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb) |
| 569 | { |
| 570 | gl_buffer_index buf; |
| 571 | for (buf = 0; buf < BUFFER_COUNT; buf++) { |
| 572 | const struct gl_renderbuffer *rb = fb->Attachment[buf].Renderbuffer; |
| 573 | if (rb) { |
| 574 | switch (rb->_BaseFormat) { |
| 575 | case GL_ALPHA: |
| 576 | case GL_LUMINANCE_ALPHA: |
| 577 | case GL_LUMINANCE: |
| 578 | case GL_INTENSITY: |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 579 | case GL_RED: |
| 580 | case GL_RG: |
Brian Paul | 62c66b3 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 581 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
| 582 | return; |
Marek Olšák | a3ac28a | 2011-05-14 04:42:29 +0200 | [diff] [blame] | 583 | |
| 584 | default: |
Marek Olšák | 9d7698c | 2011-04-26 02:18:24 +0200 | [diff] [blame] | 585 | switch (rb->Format) { |
Marek Olšák | a3ac28a | 2011-05-14 04:42:29 +0200 | [diff] [blame] | 586 | /* XXX This list is likely incomplete. */ |
Mark Mueller | eeed49f | 2014-01-26 15:12:56 -0800 | [diff] [blame] | 587 | case MESA_FORMAT_R9G9B9E5_FLOAT: |
Marek Olšák | 9d7698c | 2011-04-26 02:18:24 +0200 | [diff] [blame] | 588 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
| 589 | return; |
| 590 | default:; |
Marek Olšák | a3ac28a | 2011-05-14 04:42:29 +0200 | [diff] [blame] | 591 | /* render buffer format is supported by software rendering */ |
Marek Olšák | 9d7698c | 2011-04-26 02:18:24 +0200 | [diff] [blame] | 592 | } |
Brian Paul | 62c66b3 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | |
| 599 | /** |
Marek Olšák | f8855a4 | 2013-03-14 14:22:56 +0100 | [diff] [blame] | 600 | * Return true if the framebuffer has a combined depth/stencil |
| 601 | * renderbuffer attached. |
| 602 | */ |
| 603 | GLboolean |
| 604 | _mesa_has_depthstencil_combined(const struct gl_framebuffer *fb) |
| 605 | { |
| 606 | const struct gl_renderbuffer_attachment *depth = |
| 607 | &fb->Attachment[BUFFER_DEPTH]; |
| 608 | const struct gl_renderbuffer_attachment *stencil = |
| 609 | &fb->Attachment[BUFFER_STENCIL]; |
| 610 | |
| 611 | if (depth->Type == stencil->Type) { |
| 612 | if (depth->Type == GL_RENDERBUFFER_EXT && |
| 613 | depth->Renderbuffer == stencil->Renderbuffer) |
| 614 | return GL_TRUE; |
| 615 | |
| 616 | if (depth->Type == GL_TEXTURE && |
| 617 | depth->Texture == stencil->Texture) |
| 618 | return GL_TRUE; |
| 619 | } |
| 620 | |
| 621 | return GL_FALSE; |
| 622 | } |
| 623 | |
| 624 | |
| 625 | /** |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 626 | * For debug only. |
| 627 | */ |
| 628 | static void |
| 629 | att_incomplete(const char *msg) |
| 630 | { |
Brian Paul | 93bcf78 | 2012-05-09 12:09:21 -0600 | [diff] [blame] | 631 | if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) { |
| 632 | _mesa_debug(NULL, "attachment incomplete: %s\n", msg); |
| 633 | } |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | |
| 637 | /** |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 638 | * For debug only. |
| 639 | */ |
| 640 | static void |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 641 | fbo_incomplete(struct gl_context *ctx, const char *msg, int index) |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 642 | { |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 643 | static GLuint msg_id; |
| 644 | |
| 645 | _mesa_gl_debug(ctx, &msg_id, |
Matt Turner | 5b1e51b | 2014-11-13 17:35:58 -0800 | [diff] [blame] | 646 | MESA_DEBUG_SOURCE_API, |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 647 | MESA_DEBUG_TYPE_OTHER, |
| 648 | MESA_DEBUG_SEVERITY_MEDIUM, |
| 649 | "FBO incomplete: %s [%d]\n", msg, index); |
| 650 | |
Brian Paul | 93bcf78 | 2012-05-09 12:09:21 -0600 | [diff] [blame] | 651 | if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) { |
| 652 | _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index); |
| 653 | } |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 657 | /** |
| 658 | * Is the given base format a legal format for a color renderbuffer? |
| 659 | */ |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 660 | GLboolean |
| 661 | _mesa_is_legal_color_format(const struct gl_context *ctx, GLenum baseFormat) |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 662 | { |
| 663 | switch (baseFormat) { |
| 664 | case GL_RGB: |
| 665 | case GL_RGBA: |
| 666 | return GL_TRUE; |
Marek Olšák | 6e61853 | 2010-10-02 21:53:03 +0200 | [diff] [blame] | 667 | case GL_LUMINANCE: |
| 668 | case GL_LUMINANCE_ALPHA: |
| 669 | case GL_INTENSITY: |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 670 | case GL_ALPHA: |
Jordan Justen | cf300ea | 2012-12-27 12:41:10 -0800 | [diff] [blame] | 671 | return ctx->API == API_OPENGL_COMPAT && |
| 672 | ctx->Extensions.ARB_framebuffer_object; |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 673 | case GL_RED: |
| 674 | case GL_RG: |
| 675 | return ctx->Extensions.ARB_texture_rg; |
| 676 | default: |
| 677 | return GL_FALSE; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | |
| 682 | /** |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 683 | * Is the given base format a legal format for a color renderbuffer? |
| 684 | */ |
| 685 | static GLboolean |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 686 | is_format_color_renderable(const struct gl_context *ctx, mesa_format format, |
| 687 | GLenum internalFormat) |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 688 | { |
| 689 | const GLenum baseFormat = |
| 690 | _mesa_get_format_base_format(format); |
| 691 | GLboolean valid; |
| 692 | |
| 693 | valid = _mesa_is_legal_color_format(ctx, baseFormat); |
| 694 | if (!valid || _mesa_is_desktop_gl(ctx)) { |
| 695 | return valid; |
| 696 | } |
| 697 | |
| 698 | /* Reject additional cases for GLES */ |
| 699 | switch (internalFormat) { |
| 700 | case GL_RGBA8_SNORM: |
| 701 | case GL_RGB32F: |
| 702 | case GL_RGB32I: |
| 703 | case GL_RGB32UI: |
| 704 | case GL_RGB16F: |
| 705 | case GL_RGB16I: |
| 706 | case GL_RGB16UI: |
| 707 | case GL_RGB8_SNORM: |
| 708 | case GL_RGB8I: |
| 709 | case GL_RGB8UI: |
| 710 | case GL_SRGB8: |
| 711 | case GL_RGB9_E5: |
| 712 | case GL_RG8_SNORM: |
| 713 | case GL_R8_SNORM: |
| 714 | return GL_FALSE; |
| 715 | default: |
| 716 | break; |
| 717 | } |
| 718 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 719 | if (format == MESA_FORMAT_B10G10R10A2_UNORM && |
| 720 | internalFormat != GL_RGB10_A2) { |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 721 | return GL_FALSE; |
| 722 | } |
| 723 | |
| 724 | return GL_TRUE; |
| 725 | } |
| 726 | |
| 727 | |
| 728 | /** |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 729 | * Is the given base format a legal format for a depth/stencil renderbuffer? |
| 730 | */ |
| 731 | static GLboolean |
| 732 | is_legal_depth_format(const struct gl_context *ctx, GLenum baseFormat) |
| 733 | { |
| 734 | switch (baseFormat) { |
| 735 | case GL_DEPTH_COMPONENT: |
| 736 | case GL_DEPTH_STENCIL_EXT: |
| 737 | return GL_TRUE; |
| 738 | default: |
| 739 | return GL_FALSE; |
| 740 | } |
| 741 | } |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 742 | |
| 743 | |
| 744 | /** |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 745 | * Test if an attachment point is complete and update its Complete field. |
| 746 | * \param format if GL_COLOR, this is a color attachment point, |
| 747 | * if GL_DEPTH, this is a depth component attachment point, |
| 748 | * if GL_STENCIL, this is a stencil component attachment point. |
| 749 | */ |
| 750 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 751 | test_attachment_completeness(const struct gl_context *ctx, GLenum format, |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 752 | struct gl_renderbuffer_attachment *att) |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 753 | { |
| 754 | assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL); |
| 755 | |
| 756 | /* assume complete */ |
| 757 | att->Complete = GL_TRUE; |
| 758 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 759 | /* Look for reasons why the attachment might be incomplete */ |
| 760 | if (att->Type == GL_TEXTURE) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 761 | const struct gl_texture_object *texObj = att->Texture; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 762 | struct gl_texture_image *texImage; |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 763 | GLenum baseFormat; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 764 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 765 | if (!texObj) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 766 | att_incomplete("no texobj"); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 767 | att->Complete = GL_FALSE; |
| 768 | return; |
| 769 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 770 | |
| 771 | texImage = texObj->Image[att->CubeMapFace][att->TextureLevel]; |
| 772 | if (!texImage) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 773 | att_incomplete("no teximage"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 774 | att->Complete = GL_FALSE; |
| 775 | return; |
| 776 | } |
| 777 | if (texImage->Width < 1 || texImage->Height < 1) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 778 | att_incomplete("teximage width/height=0"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 779 | att->Complete = GL_FALSE; |
| 780 | return; |
| 781 | } |
Ian Romanick | 25281fe | 2013-07-27 12:27:45 -0700 | [diff] [blame] | 782 | |
| 783 | switch (texObj->Target) { |
| 784 | case GL_TEXTURE_3D: |
| 785 | if (att->Zoffset >= texImage->Depth) { |
| 786 | att_incomplete("bad z offset"); |
| 787 | att->Complete = GL_FALSE; |
| 788 | return; |
| 789 | } |
| 790 | break; |
| 791 | case GL_TEXTURE_1D_ARRAY: |
| 792 | if (att->Zoffset >= texImage->Height) { |
| 793 | att_incomplete("bad 1D-array layer"); |
| 794 | att->Complete = GL_FALSE; |
| 795 | return; |
| 796 | } |
| 797 | break; |
| 798 | case GL_TEXTURE_2D_ARRAY: |
| 799 | if (att->Zoffset >= texImage->Depth) { |
| 800 | att_incomplete("bad 2D-array layer"); |
| 801 | att->Complete = GL_FALSE; |
| 802 | return; |
| 803 | } |
| 804 | break; |
| 805 | case GL_TEXTURE_CUBE_MAP_ARRAY: |
| 806 | if (att->Zoffset >= texImage->Depth) { |
| 807 | att_incomplete("bad cube-array layer"); |
| 808 | att->Complete = GL_FALSE; |
| 809 | return; |
| 810 | } |
| 811 | break; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Ilia Mirkin | 68c4af1 | 2016-02-17 20:31:38 -0500 | [diff] [blame] | 814 | baseFormat = texImage->_BaseFormat; |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 815 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 816 | if (format == GL_COLOR) { |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 817 | if (!_mesa_is_legal_color_format(ctx, baseFormat)) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 818 | att_incomplete("bad format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 819 | att->Complete = GL_FALSE; |
| 820 | return; |
| 821 | } |
Brian Paul | 1f7c914 | 2009-09-30 20:28:45 -0600 | [diff] [blame] | 822 | if (_mesa_is_format_compressed(texImage->TexFormat)) { |
Eric Anholt | 957f3c8 | 2009-05-15 16:24:59 -0700 | [diff] [blame] | 823 | att_incomplete("compressed internalformat"); |
| 824 | att->Complete = GL_FALSE; |
| 825 | return; |
| 826 | } |
Tapani Pälli | e333035 | 2015-02-12 14:33:53 +0200 | [diff] [blame] | 827 | |
| 828 | /* OES_texture_float allows creation and use of floating point |
| 829 | * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow |
| 830 | * these textures to be used as a render target, this is done via |
| 831 | * GL_EXT_color_buffer(_half)_float with set of new sized types. |
| 832 | */ |
| 833 | if (_mesa_is_gles(ctx) && (texImage->TexObject->_IsFloat || |
| 834 | texImage->TexObject->_IsHalfFloat)) { |
| 835 | att_incomplete("bad internal format"); |
| 836 | att->Complete = GL_FALSE; |
| 837 | return; |
| 838 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 839 | } |
| 840 | else if (format == GL_DEPTH) { |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 841 | if (baseFormat == GL_DEPTH_COMPONENT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 842 | /* OK */ |
| 843 | } |
Ian Romanick | a92b9e6 | 2013-11-13 14:10:34 -0800 | [diff] [blame] | 844 | else if (ctx->Extensions.ARB_depth_texture && |
Ian Romanick | 4949322 | 2013-11-13 14:15:11 -0800 | [diff] [blame] | 845 | baseFormat == GL_DEPTH_STENCIL) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 846 | /* OK */ |
| 847 | } |
| 848 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 849 | att->Complete = GL_FALSE; |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 850 | att_incomplete("bad depth format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 851 | return; |
| 852 | } |
| 853 | } |
| 854 | else { |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 855 | assert(format == GL_STENCIL); |
Ian Romanick | a92b9e6 | 2013-11-13 14:10:34 -0800 | [diff] [blame] | 856 | if (ctx->Extensions.ARB_depth_texture && |
Ian Romanick | 4949322 | 2013-11-13 14:15:11 -0800 | [diff] [blame] | 857 | baseFormat == GL_DEPTH_STENCIL) { |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 858 | /* OK */ |
Dave Airlie | 782e71c | 2015-04-05 13:19:18 +1000 | [diff] [blame] | 859 | } else if (ctx->Extensions.ARB_texture_stencil8 && |
| 860 | baseFormat == GL_STENCIL_INDEX) { |
| 861 | /* OK */ |
| 862 | } else { |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 863 | /* no such thing as stencil-only textures */ |
| 864 | att_incomplete("illegal stencil texture"); |
| 865 | att->Complete = GL_FALSE; |
| 866 | return; |
| 867 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 868 | } |
| 869 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 870 | else if (att->Type == GL_RENDERBUFFER_EXT) { |
Ilia Mirkin | 68c4af1 | 2016-02-17 20:31:38 -0500 | [diff] [blame] | 871 | const GLenum baseFormat = att->Renderbuffer->_BaseFormat; |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 872 | |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 873 | assert(att->Renderbuffer); |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 874 | if (!att->Renderbuffer->InternalFormat || |
| 875 | att->Renderbuffer->Width < 1 || |
| 876 | att->Renderbuffer->Height < 1) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 877 | att_incomplete("0x0 renderbuffer"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 878 | att->Complete = GL_FALSE; |
| 879 | return; |
| 880 | } |
| 881 | if (format == GL_COLOR) { |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 882 | if (!_mesa_is_legal_color_format(ctx, baseFormat)) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 883 | att_incomplete("bad renderbuffer color format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 884 | att->Complete = GL_FALSE; |
| 885 | return; |
| 886 | } |
| 887 | } |
| 888 | else if (format == GL_DEPTH) { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 889 | if (baseFormat == GL_DEPTH_COMPONENT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 890 | /* OK */ |
| 891 | } |
Ian Romanick | 4949322 | 2013-11-13 14:15:11 -0800 | [diff] [blame] | 892 | else if (baseFormat == GL_DEPTH_STENCIL) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 893 | /* OK */ |
| 894 | } |
| 895 | else { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 896 | att_incomplete("bad renderbuffer depth format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 897 | att->Complete = GL_FALSE; |
| 898 | return; |
| 899 | } |
| 900 | } |
| 901 | else { |
| 902 | assert(format == GL_STENCIL); |
Ian Romanick | 4949322 | 2013-11-13 14:15:11 -0800 | [diff] [blame] | 903 | if (baseFormat == GL_STENCIL_INDEX || |
| 904 | baseFormat == GL_DEPTH_STENCIL) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 905 | /* OK */ |
| 906 | } |
| 907 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 908 | att->Complete = GL_FALSE; |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 909 | att_incomplete("bad renderbuffer stencil format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 910 | return; |
| 911 | } |
| 912 | } |
| 913 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 914 | else { |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 915 | assert(att->Type == GL_NONE); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 916 | /* complete */ |
| 917 | return; |
| 918 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | |
| 922 | /** |
| 923 | * Test if the given framebuffer object is complete and update its |
| 924 | * Status field with the results. |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 925 | * Calls the ctx->Driver.ValidateFramebuffer() function to allow the |
| 926 | * driver to make hardware-specific validation/completeness checks. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 927 | * Also update the framebuffer's Width and Height fields if the |
| 928 | * framebuffer is complete. |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 929 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 930 | void |
Brian Paul | f928854 | 2010-10-22 11:25:14 -0600 | [diff] [blame] | 931 | _mesa_test_framebuffer_completeness(struct gl_context *ctx, |
| 932 | struct gl_framebuffer *fb) |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 933 | { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 934 | GLuint numImages; |
| 935 | GLenum intFormat = GL_NONE; /* color buffers' internal format */ |
| 936 | GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 937 | GLint numSamples = -1; |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 938 | GLint fixedSampleLocations = -1; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 939 | GLint i; |
Brian Paul | 28b014e | 2006-04-05 03:05:17 +0000 | [diff] [blame] | 940 | GLuint j; |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 941 | /* Covers max_layer_count, is_layered, and layer_tex_target */ |
| 942 | bool layer_info_valid = false; |
| 943 | GLuint max_layer_count = 0, att_layer_count; |
Brian Paul | 5306ee7 | 2014-01-22 10:02:28 -0800 | [diff] [blame] | 944 | bool is_layered = false; |
Paul Berry | 28af1dc | 2013-11-19 19:01:37 -0800 | [diff] [blame] | 945 | GLenum layer_tex_target = 0; |
Iago Toral Quiroga | d42e090 | 2014-12-12 15:14:32 +0100 | [diff] [blame] | 946 | bool has_depth_attachment = false; |
| 947 | bool has_stencil_attachment = false; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 948 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 949 | assert(_mesa_is_user_fbo(fb)); |
Brian Paul | c726441 | 2005-06-01 00:50:23 +0000 | [diff] [blame] | 950 | |
Marek Olšák | e06d616 | 2012-08-04 13:37:03 +0200 | [diff] [blame] | 951 | /* we're changing framebuffer fields here */ |
| 952 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 953 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 954 | numImages = 0; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 955 | fb->Width = 0; |
| 956 | fb->Height = 0; |
Marek Olšák | 21d407c | 2013-03-28 01:50:21 +0100 | [diff] [blame] | 957 | fb->_AllColorBuffersFixedPoint = GL_TRUE; |
Marek Olšák | 755648c | 2013-03-28 01:56:01 +0100 | [diff] [blame] | 958 | fb->_HasSNormOrFloatColorBuffer = GL_FALSE; |
Kevin Rogovin | da81999 | 2015-06-17 13:29:50 +0300 | [diff] [blame] | 959 | fb->_HasAttachments = true; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 960 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 961 | /* Start at -2 to more easily loop over all attachment points. |
| 962 | * -2: depth buffer |
| 963 | * -1: stencil buffer |
| 964 | * >=0: color buffer |
| 965 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 966 | for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 967 | struct gl_renderbuffer_attachment *att; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 968 | GLenum f; |
Mark Mueller | 71fe943 | 2014-01-04 14:11:43 -0800 | [diff] [blame] | 969 | mesa_format attFormat; |
Paul Berry | 9514074 | 2013-11-19 15:55:51 -0800 | [diff] [blame] | 970 | GLenum att_tex_target = GL_NONE; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 971 | |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 972 | /* |
| 973 | * XXX for ARB_fbo, only check color buffers that are named by |
| 974 | * GL_READ_BUFFER and GL_DRAW_BUFFERi. |
| 975 | */ |
| 976 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 977 | /* check for attachment completeness |
| 978 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 979 | if (i == -2) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 980 | att = &fb->Attachment[BUFFER_DEPTH]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 981 | test_attachment_completeness(ctx, GL_DEPTH, att); |
| 982 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 983 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 984 | fbo_incomplete(ctx, "depth attachment incomplete", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 985 | return; |
Iago Toral Quiroga | d42e090 | 2014-12-12 15:14:32 +0100 | [diff] [blame] | 986 | } else if (att->Type != GL_NONE) { |
| 987 | has_depth_attachment = true; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | else if (i == -1) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 991 | att = &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 992 | test_attachment_completeness(ctx, GL_STENCIL, att); |
| 993 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 994 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 995 | fbo_incomplete(ctx, "stencil attachment incomplete", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 996 | return; |
Iago Toral Quiroga | d42e090 | 2014-12-12 15:14:32 +0100 | [diff] [blame] | 997 | } else if (att->Type != GL_NONE) { |
| 998 | has_stencil_attachment = true; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1002 | att = &fb->Attachment[BUFFER_COLOR0 + i]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1003 | test_attachment_completeness(ctx, GL_COLOR, att); |
| 1004 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1005 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1006 | fbo_incomplete(ctx, "color attachment incomplete", i); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1007 | return; |
| 1008 | } |
| 1009 | } |
| 1010 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1011 | /* get width, height, format of the renderbuffer/texture |
| 1012 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1013 | if (att->Type == GL_TEXTURE) { |
Eric Anholt | e98c39c | 2013-05-10 11:51:01 -0700 | [diff] [blame] | 1014 | const struct gl_texture_image *texImg = att->Renderbuffer->TexImage; |
Paul Berry | 9514074 | 2013-11-19 15:55:51 -0800 | [diff] [blame] | 1015 | att_tex_target = att->Texture->Target; |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1016 | minWidth = MIN2(minWidth, texImg->Width); |
| 1017 | maxWidth = MAX2(maxWidth, texImg->Width); |
| 1018 | minHeight = MIN2(minHeight, texImg->Height); |
| 1019 | maxHeight = MAX2(maxHeight, texImg->Height); |
Brian Paul | a9fc8ba | 2005-10-05 01:48:07 +0000 | [diff] [blame] | 1020 | f = texImg->_BaseFormat; |
Brian Paul | ca1b551 | 2011-02-28 18:23:23 -0700 | [diff] [blame] | 1021 | attFormat = texImg->TexFormat; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1022 | numImages++; |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1023 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1024 | if (!is_format_color_renderable(ctx, attFormat, |
| 1025 | texImg->InternalFormat) && |
Dave Airlie | 782e71c | 2015-04-05 13:19:18 +1000 | [diff] [blame] | 1026 | !is_legal_depth_format(ctx, f) && |
| 1027 | f != GL_STENCIL_INDEX) { |
Iago Toral Quiroga | b6819cd | 2014-12-15 09:29:55 +0100 | [diff] [blame] | 1028 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1029 | fbo_incomplete(ctx, "texture attachment incomplete", -1); |
Brian Paul | ed7f3ae | 2005-06-07 15:03:40 +0000 | [diff] [blame] | 1030 | return; |
| 1031 | } |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1032 | |
| 1033 | if (numSamples < 0) |
| 1034 | numSamples = texImg->NumSamples; |
| 1035 | else if (numSamples != texImg->NumSamples) { |
| 1036 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1037 | fbo_incomplete(ctx, "inconsistent sample count", -1); |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1038 | return; |
| 1039 | } |
| 1040 | |
| 1041 | if (fixedSampleLocations < 0) |
| 1042 | fixedSampleLocations = texImg->FixedSampleLocations; |
| 1043 | else if (fixedSampleLocations != texImg->FixedSampleLocations) { |
| 1044 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1045 | fbo_incomplete(ctx, "inconsistent fixed sample locations", -1); |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1046 | return; |
| 1047 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1048 | } |
| 1049 | else if (att->Type == GL_RENDERBUFFER_EXT) { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1050 | minWidth = MIN2(minWidth, att->Renderbuffer->Width); |
| 1051 | maxWidth = MAX2(minWidth, att->Renderbuffer->Width); |
| 1052 | minHeight = MIN2(minHeight, att->Renderbuffer->Height); |
| 1053 | maxHeight = MAX2(minHeight, att->Renderbuffer->Height); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1054 | f = att->Renderbuffer->InternalFormat; |
Brian Paul | ca1b551 | 2011-02-28 18:23:23 -0700 | [diff] [blame] | 1055 | attFormat = att->Renderbuffer->Format; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1056 | numImages++; |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1057 | |
| 1058 | if (numSamples < 0) |
| 1059 | numSamples = att->Renderbuffer->NumSamples; |
| 1060 | else if (numSamples != att->Renderbuffer->NumSamples) { |
| 1061 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1062 | fbo_incomplete(ctx, "inconsistent sample count", -1); |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1063 | return; |
| 1064 | } |
| 1065 | |
| 1066 | /* RENDERBUFFER has fixedSampleLocations implicitly true */ |
| 1067 | if (fixedSampleLocations < 0) |
| 1068 | fixedSampleLocations = GL_TRUE; |
| 1069 | else if (fixedSampleLocations != GL_TRUE) { |
| 1070 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1071 | fbo_incomplete(ctx, "inconsistent fixed sample locations", -1); |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1072 | return; |
| 1073 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1074 | } |
| 1075 | else { |
| 1076 | assert(att->Type == GL_NONE); |
| 1077 | continue; |
| 1078 | } |
| 1079 | |
Brian Paul | c7d1837 | 2010-10-23 09:38:45 -0600 | [diff] [blame] | 1080 | /* check if integer color */ |
Brian Paul | ca1b551 | 2011-02-28 18:23:23 -0700 | [diff] [blame] | 1081 | fb->_IntegerColor = _mesa_is_format_integer_color(attFormat); |
Brian Paul | c7d1837 | 2010-10-23 09:38:45 -0600 | [diff] [blame] | 1082 | |
Marek Olšák | 755648c | 2013-03-28 01:56:01 +0100 | [diff] [blame] | 1083 | /* Update _AllColorBuffersFixedPoint and _HasSNormOrFloatColorBuffer. */ |
Marek Olšák | 21d407c | 2013-03-28 01:50:21 +0100 | [diff] [blame] | 1084 | if (i >= 0) { |
| 1085 | GLenum type = _mesa_get_format_datatype(attFormat); |
| 1086 | |
| 1087 | fb->_AllColorBuffersFixedPoint = |
| 1088 | fb->_AllColorBuffersFixedPoint && |
| 1089 | (type == GL_UNSIGNED_NORMALIZED || type == GL_SIGNED_NORMALIZED); |
Marek Olšák | 755648c | 2013-03-28 01:56:01 +0100 | [diff] [blame] | 1090 | |
| 1091 | fb->_HasSNormOrFloatColorBuffer = |
| 1092 | fb->_HasSNormOrFloatColorBuffer || |
| 1093 | type == GL_SIGNED_NORMALIZED || type == GL_FLOAT; |
Marek Olšák | 21d407c | 2013-03-28 01:50:21 +0100 | [diff] [blame] | 1094 | } |
| 1095 | |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1096 | /* Error-check width, height, format */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1097 | if (numImages == 1) { |
Chris Forbes | 61d42ff | 2012-12-16 20:58:00 +1300 | [diff] [blame] | 1098 | /* save format */ |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1099 | if (i >= 0) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1100 | intFormat = f; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1101 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1102 | } |
| 1103 | else { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1104 | if (!ctx->Extensions.ARB_framebuffer_object) { |
| 1105 | /* check that width, height, format are same */ |
| 1106 | if (minWidth != maxWidth || minHeight != maxHeight) { |
| 1107 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1108 | fbo_incomplete(ctx, "width or height mismatch", -1); |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1109 | return; |
| 1110 | } |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 1111 | /* check that all color buffers are the same format */ |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1112 | if (intFormat != GL_NONE && f != intFormat) { |
| 1113 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1114 | fbo_incomplete(ctx, "format mismatch", -1); |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 1115 | return; |
| 1116 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1117 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1118 | } |
Marek Olšák | a82227c | 2012-06-15 17:21:05 +0200 | [diff] [blame] | 1119 | |
| 1120 | /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported) |
| 1121 | */ |
| 1122 | if (att->Type == GL_RENDERBUFFER && |
| 1123 | att->Renderbuffer->Format == MESA_FORMAT_NONE) { |
| 1124 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1125 | fbo_incomplete(ctx, "unsupported renderbuffer format", i); |
Marek Olšák | a82227c | 2012-06-15 17:21:05 +0200 | [diff] [blame] | 1126 | return; |
| 1127 | } |
Jordan Justen | 5da8288 | 2013-04-18 10:20:05 -0700 | [diff] [blame] | 1128 | |
| 1129 | /* Check that layered rendering is consistent. */ |
Paul Berry | 9514074 | 2013-11-19 15:55:51 -0800 | [diff] [blame] | 1130 | if (att->Layered) { |
| 1131 | if (att_tex_target == GL_TEXTURE_CUBE_MAP) |
| 1132 | att_layer_count = 6; |
Kenneth Graunke | 5c399ca | 2014-05-07 14:35:42 -0700 | [diff] [blame] | 1133 | else if (att_tex_target == GL_TEXTURE_1D_ARRAY) |
| 1134 | att_layer_count = att->Renderbuffer->Height; |
Paul Berry | 9514074 | 2013-11-19 15:55:51 -0800 | [diff] [blame] | 1135 | else |
| 1136 | att_layer_count = att->Renderbuffer->Depth; |
| 1137 | } else { |
| 1138 | att_layer_count = 0; |
| 1139 | } |
Paul Berry | 28af1dc | 2013-11-19 19:01:37 -0800 | [diff] [blame] | 1140 | if (!layer_info_valid) { |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1141 | is_layered = att->Layered; |
| 1142 | max_layer_count = att_layer_count; |
Paul Berry | 28af1dc | 2013-11-19 19:01:37 -0800 | [diff] [blame] | 1143 | layer_tex_target = att_tex_target; |
| 1144 | layer_info_valid = true; |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1145 | } else if (max_layer_count > 0 && layer_tex_target != att_tex_target) { |
Paul Berry | 28af1dc | 2013-11-19 19:01:37 -0800 | [diff] [blame] | 1146 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS; |
| 1147 | fbo_incomplete(ctx, "layered framebuffer has mismatched targets", i); |
| 1148 | return; |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1149 | } else if (is_layered != att->Layered) { |
| 1150 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS; |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1151 | fbo_incomplete(ctx, |
| 1152 | "framebuffer attachment layer mode is inconsistent", |
| 1153 | i); |
Jordan Justen | 5da8288 | 2013-04-18 10:20:05 -0700 | [diff] [blame] | 1154 | return; |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1155 | } else if (att_layer_count > max_layer_count) { |
| 1156 | max_layer_count = att_layer_count; |
Jordan Justen | 5da8288 | 2013-04-18 10:20:05 -0700 | [diff] [blame] | 1157 | } |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1158 | |
| 1159 | /* |
| 1160 | * The extension GL_ARB_framebuffer_no_attachments places additional |
| 1161 | * requirement on each attachment. Those additional requirements are |
| 1162 | * tighter that those of previous versions of GL. In interest of better |
| 1163 | * compatibility, we will not enforce these restrictions. For the record |
| 1164 | * those additional restrictions are quoted below: |
| 1165 | * |
| 1166 | * "The width and height of image are greater than zero and less than or |
| 1167 | * equal to the values of the implementation-dependent limits |
| 1168 | * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively." |
| 1169 | * |
| 1170 | * "If <image> is a three-dimensional texture or a one- or two-dimensional |
| 1171 | * array texture and the attachment is layered, the depth or layer count |
| 1172 | * of the texture is less than or equal to the implementation-dependent |
| 1173 | * limit MAX_FRAMEBUFFER_LAYERS." |
| 1174 | * |
| 1175 | * "If image has multiple samples, its sample count is less than or equal |
| 1176 | * to the value of the implementation-dependent limit |
| 1177 | * MAX_FRAMEBUFFER_SAMPLES." |
| 1178 | * |
| 1179 | * The same requirements are also in place for GL 4.5, |
| 1180 | * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311 |
| 1181 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
Paul Berry | 532b1fe | 2014-01-07 06:29:47 -0800 | [diff] [blame] | 1184 | fb->MaxNumLayers = max_layer_count; |
Jordan Justen | 5da8288 | 2013-04-18 10:20:05 -0700 | [diff] [blame] | 1185 | |
Chris Forbes | a419a1c | 2014-03-23 22:41:28 +1300 | [diff] [blame] | 1186 | if (numImages == 0) { |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1187 | fb->_HasAttachments = false; |
| 1188 | |
| 1189 | if (!ctx->Extensions.ARB_framebuffer_no_attachments) { |
| 1190 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT; |
| 1191 | fbo_incomplete(ctx, "no attachments", -1); |
| 1192 | return; |
| 1193 | } |
| 1194 | |
| 1195 | if (fb->DefaultGeometry.Width == 0 || fb->DefaultGeometry.Height == 0) { |
| 1196 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT; |
| 1197 | fbo_incomplete(ctx, "no attachments and default width or height is 0", -1); |
| 1198 | return; |
| 1199 | } |
Chris Forbes | a419a1c | 2014-03-23 22:41:28 +1300 | [diff] [blame] | 1200 | } |
| 1201 | |
Jordan Justen | 09714c0 | 2012-07-19 11:27:16 -0700 | [diff] [blame] | 1202 | if (_mesa_is_desktop_gl(ctx) && !ctx->Extensions.ARB_ES2_compatibility) { |
Kristian Høgsberg | e88cef3 | 2010-05-24 16:56:12 -0400 | [diff] [blame] | 1203 | /* Check that all DrawBuffers are present */ |
| 1204 | for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1205 | if (fb->ColorDrawBuffer[j] != GL_NONE) { |
| 1206 | const struct gl_renderbuffer_attachment *att |
| 1207 | = get_attachment(ctx, fb, fb->ColorDrawBuffer[j]); |
| 1208 | assert(att); |
| 1209 | if (att->Type == GL_NONE) { |
| 1210 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT; |
| 1211 | fbo_incomplete(ctx, "missing drawbuffer", j); |
| 1212 | return; |
| 1213 | } |
| 1214 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1215 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1216 | |
Kristian Høgsberg | e88cef3 | 2010-05-24 16:56:12 -0400 | [diff] [blame] | 1217 | /* Check that the ReadBuffer is present */ |
| 1218 | if (fb->ColorReadBuffer != GL_NONE) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1219 | const struct gl_renderbuffer_attachment *att |
| 1220 | = get_attachment(ctx, fb, fb->ColorReadBuffer); |
| 1221 | assert(att); |
| 1222 | if (att->Type == GL_NONE) { |
| 1223 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT; |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1224 | fbo_incomplete(ctx, "missing readbuffer", -1); |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1225 | return; |
| 1226 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | |
Iago Toral Quiroga | d42e090 | 2014-12-12 15:14:32 +0100 | [diff] [blame] | 1230 | /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says: |
| 1231 | * |
| 1232 | * "Depth and stencil attachments, if present, are the same image." |
| 1233 | * |
| 1234 | * This restriction is not present in the OpenGL ES2 spec. |
| 1235 | */ |
| 1236 | if (_mesa_is_gles3(ctx) && |
| 1237 | has_stencil_attachment && has_depth_attachment && |
| 1238 | !_mesa_has_depthstencil_combined(fb)) { |
| 1239 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
| 1240 | fbo_incomplete(ctx, "Depth and stencil attachments must be the same image", -1); |
| 1241 | return; |
| 1242 | } |
| 1243 | |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1244 | /* Provisionally set status = COMPLETE ... */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1245 | fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT; |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1246 | |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1247 | /* ... but the driver may say the FB is incomplete. |
| 1248 | * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED |
| 1249 | * if anything. |
| 1250 | */ |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1251 | if (ctx->Driver.ValidateFramebuffer) { |
| 1252 | ctx->Driver.ValidateFramebuffer(ctx, fb); |
Brian Paul | 1f32c41 | 2009-01-19 17:34:19 -0700 | [diff] [blame] | 1253 | if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { |
Eric Anholt | 3c21a7d | 2013-06-06 11:13:02 -0700 | [diff] [blame] | 1254 | fbo_incomplete(ctx, "driver marked FBO as incomplete", -1); |
Erik Faye-Lund | 395b53d | 2015-12-16 17:09:50 +0100 | [diff] [blame] | 1255 | return; |
Brian Paul | 1f32c41 | 2009-01-19 17:34:19 -0700 | [diff] [blame] | 1256 | } |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
Erik Faye-Lund | 395b53d | 2015-12-16 17:09:50 +0100 | [diff] [blame] | 1259 | /* |
| 1260 | * Note that if ARB_framebuffer_object is supported and the attached |
| 1261 | * renderbuffers/textures are different sizes, the framebuffer |
| 1262 | * width/height will be set to the smallest width/height. |
| 1263 | */ |
| 1264 | if (numImages != 0) { |
| 1265 | fb->Width = minWidth; |
| 1266 | fb->Height = minHeight; |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 1267 | } |
Erik Faye-Lund | 395b53d | 2015-12-16 17:09:50 +0100 | [diff] [blame] | 1268 | |
| 1269 | /* finally, update the visual info for the framebuffer */ |
| 1270 | _mesa_update_framebuffer_visual(ctx, fb); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1271 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1272 | |
| 1273 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1274 | GLboolean GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1275 | _mesa_IsRenderbuffer(GLuint renderbuffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1276 | { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1277 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1278 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 1279 | if (renderbuffer) { |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1280 | struct gl_renderbuffer *rb = |
| 1281 | _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 1282 | if (rb != NULL && rb != &DummyRenderbuffer) |
| 1283 | return GL_TRUE; |
| 1284 | } |
| 1285 | return GL_FALSE; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1289 | static struct gl_renderbuffer * |
| 1290 | allocate_renderbuffer(struct gl_context *ctx, GLuint renderbuffer, |
| 1291 | const char *func) |
| 1292 | { |
| 1293 | struct gl_renderbuffer *newRb; |
| 1294 | |
| 1295 | /* create new renderbuffer object */ |
| 1296 | newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer); |
| 1297 | if (!newRb) { |
| 1298 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); |
| 1299 | return NULL; |
| 1300 | } |
| 1301 | assert(newRb->AllocStorage); |
Martin Peres | 59af7ed | 2015-03-30 10:34:20 +0300 | [diff] [blame] | 1302 | mtx_lock(&ctx->Shared->Mutex); |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1303 | _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb); |
| 1304 | newRb->RefCount = 1; /* referenced by hash table */ |
Martin Peres | 59af7ed | 2015-03-30 10:34:20 +0300 | [diff] [blame] | 1305 | mtx_unlock(&ctx->Shared->Mutex); |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1306 | |
| 1307 | return newRb; |
| 1308 | } |
| 1309 | |
| 1310 | |
Ian Romanick | 97965e8 | 2013-07-18 17:38:16 -0700 | [diff] [blame] | 1311 | static void |
| 1312 | bind_renderbuffer(GLenum target, GLuint renderbuffer, bool allow_user_names) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1313 | { |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 1314 | struct gl_renderbuffer *newRb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1315 | GET_CURRENT_CONTEXT(ctx); |
| 1316 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1317 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | 4de18fb | 2009-11-02 15:30:51 -0700 | [diff] [blame] | 1318 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1319 | return; |
| 1320 | } |
| 1321 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1322 | /* No need to flush here since the render buffer binding has no |
| 1323 | * effect on rendering state. |
| 1324 | */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1325 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1326 | if (renderbuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1327 | newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1328 | if (newRb == &DummyRenderbuffer) { |
| 1329 | /* ID was reserved, but no real renderbuffer object made yet */ |
| 1330 | newRb = NULL; |
| 1331 | } |
Ian Romanick | 97965e8 | 2013-07-18 17:38:16 -0700 | [diff] [blame] | 1332 | else if (!newRb && !allow_user_names) { |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 1333 | /* All RB IDs must be Gen'd */ |
| 1334 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)"); |
| 1335 | return; |
| 1336 | } |
| 1337 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1338 | if (!newRb) { |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1339 | newRb = allocate_renderbuffer(ctx, renderbuffer, "glBindRenderbufferEXT"); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1340 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1341 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1342 | else { |
| 1343 | newRb = NULL; |
| 1344 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1345 | |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 1346 | assert(newRb != &DummyRenderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1347 | |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 1348 | _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
Ian Romanick | 97965e8 | 2013-07-18 17:38:16 -0700 | [diff] [blame] | 1351 | void GLAPIENTRY |
| 1352 | _mesa_BindRenderbuffer(GLenum target, GLuint renderbuffer) |
| 1353 | { |
| 1354 | GET_CURRENT_CONTEXT(ctx); |
| 1355 | |
| 1356 | /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same |
| 1357 | * entry point, but they allow the use of user-generated names. |
| 1358 | */ |
| 1359 | bind_renderbuffer(target, renderbuffer, _mesa_is_gles(ctx)); |
| 1360 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1361 | |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 1362 | void GLAPIENTRY |
| 1363 | _mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer) |
| 1364 | { |
Ian Romanick | 97965e8 | 2013-07-18 17:38:16 -0700 | [diff] [blame] | 1365 | /* This function should not be in the dispatch table for core profile / |
| 1366 | * OpenGL 3.1, so execution should never get here in those cases -- no |
| 1367 | * need for an explicit test. |
| 1368 | */ |
| 1369 | bind_renderbuffer(target, renderbuffer, true); |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 1370 | } |
| 1371 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1372 | static void |
| 1373 | framebuffer_parameteri(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 1374 | GLenum pname, GLint param, const char *func) |
| 1375 | { |
| 1376 | switch (pname) { |
| 1377 | case GL_FRAMEBUFFER_DEFAULT_WIDTH: |
| 1378 | if (param < 0 || param > ctx->Const.MaxFramebufferWidth) |
| 1379 | _mesa_error(ctx, GL_INVALID_VALUE, "%s", func); |
| 1380 | else |
| 1381 | fb->DefaultGeometry.Width = param; |
| 1382 | break; |
| 1383 | case GL_FRAMEBUFFER_DEFAULT_HEIGHT: |
| 1384 | if (param < 0 || param > ctx->Const.MaxFramebufferHeight) |
| 1385 | _mesa_error(ctx, GL_INVALID_VALUE, "%s", func); |
| 1386 | else |
| 1387 | fb->DefaultGeometry.Height = param; |
| 1388 | break; |
| 1389 | case GL_FRAMEBUFFER_DEFAULT_LAYERS: |
Marta Lofstedt | f8a9388 | 2015-08-24 13:01:53 +0200 | [diff] [blame] | 1390 | /* |
| 1391 | * According to the OpenGL ES 3.1 specification section 9.2.1, the |
| 1392 | * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported. |
| 1393 | */ |
| 1394 | if (_mesa_is_gles31(ctx)) { |
| 1395 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname); |
| 1396 | break; |
| 1397 | } |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1398 | if (param < 0 || param > ctx->Const.MaxFramebufferLayers) |
Marta Lofstedt | f8a9388 | 2015-08-24 13:01:53 +0200 | [diff] [blame] | 1399 | _mesa_error(ctx, GL_INVALID_VALUE, "%s", func); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1400 | else |
| 1401 | fb->DefaultGeometry.Layers = param; |
| 1402 | break; |
| 1403 | case GL_FRAMEBUFFER_DEFAULT_SAMPLES: |
| 1404 | if (param < 0 || param > ctx->Const.MaxFramebufferSamples) |
| 1405 | _mesa_error(ctx, GL_INVALID_VALUE, "%s", func); |
| 1406 | else |
| 1407 | fb->DefaultGeometry.NumSamples = param; |
| 1408 | break; |
| 1409 | case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 1410 | fb->DefaultGeometry.FixedSampleLocations = param; |
| 1411 | break; |
| 1412 | default: |
| 1413 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1414 | "%s(pname=0x%x)", func, pname); |
| 1415 | } |
Ilia Mirkin | 095da3b | 2016-01-23 09:27:22 -0500 | [diff] [blame] | 1416 | |
| 1417 | invalidate_framebuffer(fb); |
| 1418 | ctx->NewState |= _NEW_BUFFERS; |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1419 | } |
| 1420 | |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1421 | void GLAPIENTRY |
| 1422 | _mesa_FramebufferParameteri(GLenum target, GLenum pname, GLint param) |
| 1423 | { |
| 1424 | GET_CURRENT_CONTEXT(ctx); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1425 | struct gl_framebuffer *fb; |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1426 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1427 | if (!ctx->Extensions.ARB_framebuffer_no_attachments) { |
| 1428 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1429 | "glFramebufferParameteriv not supported " |
| 1430 | "(ARB_framebuffer_no_attachments not implemented)"); |
| 1431 | return; |
| 1432 | } |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1433 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1434 | fb = get_framebuffer_target(ctx, target); |
| 1435 | if (!fb) { |
| 1436 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1437 | "glFramebufferParameteri(target=0x%x)", target); |
| 1438 | return; |
| 1439 | } |
| 1440 | |
| 1441 | /* check framebuffer binding */ |
| 1442 | if (_mesa_is_winsys_fbo(fb)) { |
| 1443 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1444 | "glFramebufferParameteri"); |
| 1445 | return; |
| 1446 | } |
| 1447 | |
| 1448 | framebuffer_parameteri(ctx, fb, pname, param, "glFramebufferParameteri"); |
| 1449 | } |
| 1450 | |
| 1451 | static void |
| 1452 | get_framebuffer_parameteriv(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 1453 | GLenum pname, GLint *params, const char *func) |
| 1454 | { |
| 1455 | switch (pname) { |
| 1456 | case GL_FRAMEBUFFER_DEFAULT_WIDTH: |
| 1457 | *params = fb->DefaultGeometry.Width; |
| 1458 | break; |
| 1459 | case GL_FRAMEBUFFER_DEFAULT_HEIGHT: |
| 1460 | *params = fb->DefaultGeometry.Height; |
| 1461 | break; |
| 1462 | case GL_FRAMEBUFFER_DEFAULT_LAYERS: |
Marta Lofstedt | f8a9388 | 2015-08-24 13:01:53 +0200 | [diff] [blame] | 1463 | /* |
| 1464 | * According to the OpenGL ES 3.1 specification section 9.2.3, the |
| 1465 | * GL_FRAMEBUFFER_LAYERS parameter name is not supported. |
| 1466 | */ |
| 1467 | if (_mesa_is_gles31(ctx)) { |
| 1468 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname); |
| 1469 | break; |
| 1470 | } |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1471 | *params = fb->DefaultGeometry.Layers; |
| 1472 | break; |
| 1473 | case GL_FRAMEBUFFER_DEFAULT_SAMPLES: |
| 1474 | *params = fb->DefaultGeometry.NumSamples; |
| 1475 | break; |
| 1476 | case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
| 1477 | *params = fb->DefaultGeometry.FixedSampleLocations; |
| 1478 | break; |
| 1479 | default: |
| 1480 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1481 | "%s(pname=0x%x)", func, pname); |
| 1482 | } |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | void GLAPIENTRY |
| 1486 | _mesa_GetFramebufferParameteriv(GLenum target, GLenum pname, GLint *params) |
| 1487 | { |
| 1488 | GET_CURRENT_CONTEXT(ctx); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1489 | struct gl_framebuffer *fb; |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1490 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1491 | if (!ctx->Extensions.ARB_framebuffer_no_attachments) { |
| 1492 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1493 | "glGetFramebufferParameteriv not supported " |
| 1494 | "(ARB_framebuffer_no_attachments not implemented)"); |
| 1495 | return; |
| 1496 | } |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1497 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 1498 | fb = get_framebuffer_target(ctx, target); |
| 1499 | if (!fb) { |
| 1500 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1501 | "glGetFramebufferParameteriv(target=0x%x)", target); |
| 1502 | return; |
| 1503 | } |
| 1504 | |
| 1505 | /* check framebuffer binding */ |
| 1506 | if (_mesa_is_winsys_fbo(fb)) { |
| 1507 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1508 | "glGetFramebufferParameteriv"); |
| 1509 | return; |
| 1510 | } |
| 1511 | |
| 1512 | get_framebuffer_parameteriv(ctx, fb, pname, params, |
| 1513 | "glGetFramebufferParameteriv"); |
Kevin Rogovin | c9d26f2 | 2015-06-17 13:29:51 +0300 | [diff] [blame] | 1514 | } |
| 1515 | |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 1516 | |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1517 | /** |
Ian Romanick | ef83bd2 | 2013-08-08 15:41:36 -0700 | [diff] [blame] | 1518 | * Remove the specified renderbuffer or texture from any attachment point in |
| 1519 | * the framebuffer. |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1520 | * |
| 1521 | * \returns |
| 1522 | * \c true if the renderbuffer was detached from an attachment point. \c |
| 1523 | * false otherwise. |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1524 | */ |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1525 | bool |
| 1526 | _mesa_detach_renderbuffer(struct gl_context *ctx, |
| 1527 | struct gl_framebuffer *fb, |
| 1528 | const void *att) |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1529 | { |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1530 | unsigned i; |
| 1531 | bool progress = false; |
| 1532 | |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1533 | for (i = 0; i < BUFFER_COUNT; i++) { |
Ian Romanick | ef83bd2 | 2013-08-08 15:41:36 -0700 | [diff] [blame] | 1534 | if (fb->Attachment[i].Texture == att |
| 1535 | || fb->Attachment[i].Renderbuffer == att) { |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 1536 | remove_attachment(ctx, &fb->Attachment[i]); |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1537 | progress = true; |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1538 | } |
| 1539 | } |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1540 | |
| 1541 | /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer |
| 1542 | * Completeness," of the OpenGL 3.1 spec says: |
| 1543 | * |
| 1544 | * "Performing any of the following actions may change whether the |
| 1545 | * framebuffer is considered complete or incomplete: |
| 1546 | * |
| 1547 | * ... |
| 1548 | * |
| 1549 | * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object |
| 1550 | * containing an image that is attached to a framebuffer object |
| 1551 | * that is bound to the framebuffer." |
| 1552 | */ |
| 1553 | if (progress) |
| 1554 | invalidate_framebuffer(fb); |
| 1555 | |
| 1556 | return progress; |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1560 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1561 | _mesa_DeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1562 | { |
| 1563 | GLint i; |
| 1564 | GET_CURRENT_CONTEXT(ctx); |
| 1565 | |
Eduardo Lima Mitev | 2012f62 | 2014-12-11 23:34:18 +0100 | [diff] [blame] | 1566 | if (n < 0) { |
| 1567 | _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteRenderbuffers(n < 0)"); |
| 1568 | return; |
| 1569 | } |
| 1570 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1571 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1572 | |
| 1573 | for (i = 0; i < n; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1574 | if (renderbuffers[i] > 0) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1575 | struct gl_renderbuffer *rb; |
| 1576 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]); |
| 1577 | if (rb) { |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1578 | /* check if deleting currently bound renderbuffer object */ |
| 1579 | if (rb == ctx->CurrentRenderbuffer) { |
| 1580 | /* bind default */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 1581 | assert(rb->RefCount >= 2); |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1582 | _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT, 0); |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Ian Romanick | ef83bd2 | 2013-08-08 15:41:36 -0700 | [diff] [blame] | 1585 | /* Section 4.4.2 (Attaching Images to Framebuffer Objects), |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1586 | * subsection "Attaching Renderbuffer Images to a Framebuffer," |
| 1587 | * of the OpenGL 3.1 spec says: |
Ian Romanick | ef83bd2 | 2013-08-08 15:41:36 -0700 | [diff] [blame] | 1588 | * |
| 1589 | * "If a renderbuffer object is deleted while its image is |
| 1590 | * attached to one or more attachment points in the currently |
| 1591 | * bound framebuffer, then it is as if FramebufferRenderbuffer |
| 1592 | * had been called, with a renderbuffer of 0, for each |
| 1593 | * attachment point to which this image was attached in the |
| 1594 | * currently bound framebuffer. In other words, this |
| 1595 | * renderbuffer image is first detached from all attachment |
| 1596 | * points in the currently bound framebuffer. Note that the |
| 1597 | * renderbuffer image is specifically not detached from any |
| 1598 | * non-bound framebuffers. Detaching the image from any |
| 1599 | * non-bound framebuffers is the responsibility of the |
| 1600 | * application. |
| 1601 | */ |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 1602 | if (_mesa_is_user_fbo(ctx->DrawBuffer)) { |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1603 | _mesa_detach_renderbuffer(ctx, ctx->DrawBuffer, rb); |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1604 | } |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 1605 | if (_mesa_is_user_fbo(ctx->ReadBuffer) |
Brian Paul | fc8c4a3 | 2011-06-16 07:31:58 -0600 | [diff] [blame] | 1606 | && ctx->ReadBuffer != ctx->DrawBuffer) { |
Ian Romanick | 438cc6b | 2013-08-08 15:26:36 -0700 | [diff] [blame] | 1607 | _mesa_detach_renderbuffer(ctx, ctx->ReadBuffer, rb); |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1610 | /* Remove from hash table immediately, to free the ID. |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 1611 | * But the object will not be freed until it's no longer |
| 1612 | * referenced anywhere else. |
| 1613 | */ |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1614 | _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1615 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1616 | if (rb != &DummyRenderbuffer) { |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 1617 | /* no longer referenced by hash table */ |
| 1618 | _mesa_reference_renderbuffer(&rb, NULL); |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 1619 | } |
| 1620 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1621 | } |
| 1622 | } |
| 1623 | } |
| 1624 | |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1625 | static void |
| 1626 | create_render_buffers(struct gl_context *ctx, GLsizei n, GLuint *renderbuffers, |
| 1627 | bool dsa) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1628 | { |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1629 | const char *func = dsa ? "glCreateRenderbuffers" : "glGenRenderbuffers"; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1630 | GLuint first; |
| 1631 | GLint i; |
| 1632 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1633 | if (n < 0) { |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1634 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(n<0)", func); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1635 | return; |
| 1636 | } |
| 1637 | |
| 1638 | if (!renderbuffers) |
| 1639 | return; |
| 1640 | |
| 1641 | first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n); |
| 1642 | |
| 1643 | for (i = 0; i < n; i++) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1644 | GLuint name = first + i; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1645 | renderbuffers[i] = name; |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1646 | |
| 1647 | if (dsa) { |
Martin Peres | fa38321 | 2015-03-25 16:28:03 +0200 | [diff] [blame] | 1648 | allocate_renderbuffer(ctx, name, func); |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1649 | } else { |
Martin Peres | fa38321 | 2015-03-25 16:28:03 +0200 | [diff] [blame] | 1650 | /* insert a dummy renderbuffer into the hash table */ |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1651 | mtx_lock(&ctx->Shared->Mutex); |
Martin Peres | fa38321 | 2015-03-25 16:28:03 +0200 | [diff] [blame] | 1652 | _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer); |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1653 | mtx_unlock(&ctx->Shared->Mutex); |
| 1654 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | |
Martin Peres | a34669b | 2015-02-12 18:52:10 +0200 | [diff] [blame] | 1659 | void GLAPIENTRY |
| 1660 | _mesa_GenRenderbuffers(GLsizei n, GLuint *renderbuffers) |
| 1661 | { |
| 1662 | GET_CURRENT_CONTEXT(ctx); |
| 1663 | create_render_buffers(ctx, n, renderbuffers, false); |
| 1664 | } |
| 1665 | |
| 1666 | |
| 1667 | void GLAPIENTRY |
| 1668 | _mesa_CreateRenderbuffers(GLsizei n, GLuint *renderbuffers) |
| 1669 | { |
| 1670 | GET_CURRENT_CONTEXT(ctx); |
| 1671 | create_render_buffers(ctx, n, renderbuffers, true); |
| 1672 | } |
| 1673 | |
| 1674 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 1675 | /** |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1676 | * Given an internal format token for a render buffer, return the |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1677 | * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, |
| 1678 | * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE, |
| 1679 | * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc). |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1680 | * |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1681 | * This is similar to _mesa_base_tex_format() but the set of valid |
| 1682 | * internal formats is different. |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1683 | * |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1684 | * 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] | 1685 | * 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] | 1686 | * |
| 1687 | * \param internalFormat as passed to glRenderbufferStorage() |
| 1688 | * \return the base internal format, or 0 if internalFormat is illegal |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 1689 | */ |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 1690 | GLenum |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1691 | _mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat) |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1692 | { |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1693 | /* |
| 1694 | * Notes: some formats such as alpha, luminance, etc. were added |
| 1695 | * with GL_ARB_framebuffer_object. |
| 1696 | */ |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1697 | switch (internalFormat) { |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1698 | case GL_ALPHA: |
| 1699 | case GL_ALPHA4: |
| 1700 | case GL_ALPHA8: |
| 1701 | case GL_ALPHA12: |
| 1702 | case GL_ALPHA16: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1703 | return (ctx->API == API_OPENGL_COMPAT && |
| 1704 | ctx->Extensions.ARB_framebuffer_object) ? GL_ALPHA : 0; |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1705 | case GL_LUMINANCE: |
| 1706 | case GL_LUMINANCE4: |
| 1707 | case GL_LUMINANCE8: |
| 1708 | case GL_LUMINANCE12: |
| 1709 | case GL_LUMINANCE16: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1710 | return (ctx->API == API_OPENGL_COMPAT && |
| 1711 | ctx->Extensions.ARB_framebuffer_object) ? GL_LUMINANCE : 0; |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1712 | case GL_LUMINANCE_ALPHA: |
| 1713 | case GL_LUMINANCE4_ALPHA4: |
| 1714 | case GL_LUMINANCE6_ALPHA2: |
| 1715 | case GL_LUMINANCE8_ALPHA8: |
| 1716 | case GL_LUMINANCE12_ALPHA4: |
| 1717 | case GL_LUMINANCE12_ALPHA12: |
| 1718 | case GL_LUMINANCE16_ALPHA16: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1719 | return (ctx->API == API_OPENGL_COMPAT && |
| 1720 | ctx->Extensions.ARB_framebuffer_object) ? GL_LUMINANCE_ALPHA : 0; |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1721 | case GL_INTENSITY: |
| 1722 | case GL_INTENSITY4: |
| 1723 | case GL_INTENSITY8: |
| 1724 | case GL_INTENSITY12: |
| 1725 | case GL_INTENSITY16: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1726 | return (ctx->API == API_OPENGL_COMPAT && |
| 1727 | ctx->Extensions.ARB_framebuffer_object) ? GL_INTENSITY : 0; |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1728 | case GL_RGB8: |
| 1729 | return GL_RGB; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1730 | case GL_RGB: |
| 1731 | case GL_R3_G3_B2: |
| 1732 | case GL_RGB4: |
| 1733 | case GL_RGB5: |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1734 | case GL_RGB10: |
| 1735 | case GL_RGB12: |
| 1736 | case GL_RGB16: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1737 | return _mesa_is_desktop_gl(ctx) ? GL_RGB : 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1738 | case GL_SRGB8_EXT: |
Matt Turner | cbef537 | 2012-11-20 13:45:03 -0800 | [diff] [blame] | 1739 | return _mesa_is_desktop_gl(ctx) ? GL_RGB : 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1740 | case GL_RGBA4: |
| 1741 | case GL_RGB5_A1: |
| 1742 | case GL_RGBA8: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1743 | return GL_RGBA; |
| 1744 | case GL_RGBA: |
| 1745 | case GL_RGBA2: |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1746 | case GL_RGBA12: |
| 1747 | case GL_RGBA16: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1748 | return _mesa_is_desktop_gl(ctx) ? GL_RGBA : 0; |
| 1749 | case GL_RGB10_A2: |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1750 | case GL_SRGB8_ALPHA8_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1751 | 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] | 1752 | case GL_STENCIL_INDEX: |
| 1753 | case GL_STENCIL_INDEX1_EXT: |
| 1754 | case GL_STENCIL_INDEX4_EXT: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1755 | case GL_STENCIL_INDEX16_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1756 | /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in |
| 1757 | * OpenGL ES, but Mesa does not currently support them. |
| 1758 | */ |
| 1759 | return _mesa_is_desktop_gl(ctx) ? GL_STENCIL_INDEX : 0; |
| 1760 | case GL_STENCIL_INDEX8_EXT: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1761 | return GL_STENCIL_INDEX; |
| 1762 | case GL_DEPTH_COMPONENT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1763 | case GL_DEPTH_COMPONENT32: |
| 1764 | return _mesa_is_desktop_gl(ctx) ? GL_DEPTH_COMPONENT : 0; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1765 | case GL_DEPTH_COMPONENT16: |
| 1766 | case GL_DEPTH_COMPONENT24: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1767 | return GL_DEPTH_COMPONENT; |
Ian Romanick | 4949322 | 2013-11-13 14:15:11 -0800 | [diff] [blame] | 1768 | case GL_DEPTH_STENCIL: |
| 1769 | return _mesa_is_desktop_gl(ctx) ? GL_DEPTH_STENCIL : 0; |
| 1770 | case GL_DEPTH24_STENCIL8: |
| 1771 | return GL_DEPTH_STENCIL; |
Marek Olšák | 1165280 | 2011-06-01 15:48:51 +0200 | [diff] [blame] | 1772 | case GL_DEPTH_COMPONENT32F: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1773 | return ctx->Version >= 30 |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1774 | || (ctx->API == API_OPENGL_COMPAT && |
| 1775 | ctx->Extensions.ARB_depth_buffer_float) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1776 | ? GL_DEPTH_COMPONENT : 0; |
Marek Olšák | 1165280 | 2011-06-01 15:48:51 +0200 | [diff] [blame] | 1777 | case GL_DEPTH32F_STENCIL8: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1778 | return ctx->Version >= 30 |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 1779 | || (ctx->API == API_OPENGL_COMPAT && |
| 1780 | ctx->Extensions.ARB_depth_buffer_float) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1781 | ? GL_DEPTH_STENCIL : 0; |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1782 | case GL_RED: |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1783 | case GL_R16: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1784 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_rg |
| 1785 | ? GL_RED : 0; |
| 1786 | case GL_R8: |
| 1787 | return ctx->API != API_OPENGLES && ctx->Extensions.ARB_texture_rg |
| 1788 | ? GL_RED : 0; |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1789 | case GL_RG: |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1790 | case GL_RG16: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1791 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_rg |
| 1792 | ? GL_RG : 0; |
| 1793 | case GL_RG8: |
| 1794 | return ctx->API != API_OPENGLES && ctx->Extensions.ARB_texture_rg |
| 1795 | ? GL_RG : 0; |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1796 | /* signed normalized texture formats */ |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1797 | case GL_RED_SNORM: |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 1798 | case GL_R8_SNORM: |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1799 | case GL_R16_SNORM: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1800 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1801 | ? GL_RED : 0; |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1802 | case GL_RG_SNORM: |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 1803 | case GL_RG8_SNORM: |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1804 | case GL_RG16_SNORM: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1805 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1806 | ? GL_RG : 0; |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1807 | case GL_RGB_SNORM: |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 1808 | case GL_RGB8_SNORM: |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1809 | case GL_RGB16_SNORM: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1810 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1811 | ? GL_RGB : 0; |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1812 | case GL_RGBA_SNORM: |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 1813 | case GL_RGBA8_SNORM: |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1814 | case GL_RGBA16_SNORM: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1815 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1816 | ? GL_RGBA : 0; |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1817 | case GL_ALPHA_SNORM: |
| 1818 | case GL_ALPHA8_SNORM: |
| 1819 | case GL_ALPHA16_SNORM: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1820 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1821 | ctx->Extensions.EXT_texture_snorm && |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1822 | ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0; |
Brian Paul | 513a324 | 2014-01-08 09:05:29 -0700 | [diff] [blame] | 1823 | case GL_LUMINANCE_SNORM: |
| 1824 | case GL_LUMINANCE8_SNORM: |
| 1825 | case GL_LUMINANCE16_SNORM: |
| 1826 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1827 | ? GL_LUMINANCE : 0; |
| 1828 | case GL_LUMINANCE_ALPHA_SNORM: |
| 1829 | case GL_LUMINANCE8_ALPHA8_SNORM: |
| 1830 | case GL_LUMINANCE16_ALPHA16_SNORM: |
| 1831 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1832 | ? GL_LUMINANCE_ALPHA : 0; |
| 1833 | case GL_INTENSITY_SNORM: |
| 1834 | case GL_INTENSITY8_SNORM: |
| 1835 | case GL_INTENSITY16_SNORM: |
| 1836 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1837 | ? GL_INTENSITY : 0; |
| 1838 | |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1839 | case GL_R16F: |
| 1840 | case GL_R32F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 1841 | return ((_mesa_is_desktop_gl(ctx) && |
| 1842 | ctx->Extensions.ARB_texture_rg && |
| 1843 | ctx->Extensions.ARB_texture_float) || |
| 1844 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
| 1845 | ? GL_RED : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1846 | case GL_RG16F: |
| 1847 | case GL_RG32F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 1848 | return ((_mesa_is_desktop_gl(ctx) && |
| 1849 | ctx->Extensions.ARB_texture_rg && |
| 1850 | ctx->Extensions.ARB_texture_float) || |
| 1851 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
| 1852 | ? GL_RG : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1853 | case GL_RGB16F: |
| 1854 | case GL_RGB32F: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1855 | return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_float) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1856 | ? GL_RGB : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1857 | case GL_RGBA16F: |
| 1858 | case GL_RGBA32F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 1859 | return ((_mesa_is_desktop_gl(ctx) && |
| 1860 | ctx->Extensions.ARB_texture_float) || |
| 1861 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1862 | ? GL_RGBA : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1863 | case GL_ALPHA16F_ARB: |
| 1864 | case GL_ALPHA32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1865 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1866 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1867 | ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0; |
| 1868 | case GL_LUMINANCE16F_ARB: |
| 1869 | case GL_LUMINANCE32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1870 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1871 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1872 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0; |
| 1873 | case GL_LUMINANCE_ALPHA16F_ARB: |
| 1874 | case GL_LUMINANCE_ALPHA32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1875 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1876 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1877 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0; |
| 1878 | case GL_INTENSITY16F_ARB: |
| 1879 | case GL_INTENSITY32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1880 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1881 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1882 | ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0; |
Marek Olšák | 631d23d | 2011-04-26 02:27:25 +0200 | [diff] [blame] | 1883 | case GL_R11F_G11F_B10F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 1884 | return ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_packed_float) || |
| 1885 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
Matt Turner | cbef537 | 2012-11-20 13:45:03 -0800 | [diff] [blame] | 1886 | ? GL_RGB : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1887 | |
| 1888 | case GL_RGBA8UI_EXT: |
| 1889 | case GL_RGBA16UI_EXT: |
| 1890 | case GL_RGBA32UI_EXT: |
| 1891 | case GL_RGBA8I_EXT: |
| 1892 | case GL_RGBA16I_EXT: |
| 1893 | case GL_RGBA32I_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1894 | return ctx->Version >= 30 |
| 1895 | || (_mesa_is_desktop_gl(ctx) && |
| 1896 | ctx->Extensions.EXT_texture_integer) ? GL_RGBA : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1897 | |
| 1898 | case GL_RGB8UI_EXT: |
| 1899 | case GL_RGB16UI_EXT: |
| 1900 | case GL_RGB32UI_EXT: |
| 1901 | case GL_RGB8I_EXT: |
| 1902 | case GL_RGB16I_EXT: |
| 1903 | case GL_RGB32I_EXT: |
Ian Romanick | a86d629 | 2012-12-03 11:55:12 -0800 | [diff] [blame] | 1904 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_integer |
| 1905 | ? GL_RGB : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1906 | case GL_R8UI: |
| 1907 | case GL_R8I: |
| 1908 | case GL_R16UI: |
| 1909 | case GL_R16I: |
| 1910 | case GL_R32UI: |
| 1911 | case GL_R32I: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1912 | return ctx->Version >= 30 |
| 1913 | || (_mesa_is_desktop_gl(ctx) && |
| 1914 | ctx->Extensions.ARB_texture_rg && |
| 1915 | ctx->Extensions.EXT_texture_integer) ? GL_RED : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1916 | |
| 1917 | case GL_RG8UI: |
| 1918 | case GL_RG8I: |
| 1919 | case GL_RG16UI: |
| 1920 | case GL_RG16I: |
| 1921 | case GL_RG32UI: |
| 1922 | case GL_RG32I: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1923 | return ctx->Version >= 30 |
| 1924 | || (_mesa_is_desktop_gl(ctx) && |
| 1925 | ctx->Extensions.ARB_texture_rg && |
| 1926 | ctx->Extensions.EXT_texture_integer) ? GL_RG : 0; |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 1927 | |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1928 | case GL_INTENSITY8I_EXT: |
| 1929 | case GL_INTENSITY8UI_EXT: |
| 1930 | case GL_INTENSITY16I_EXT: |
| 1931 | case GL_INTENSITY16UI_EXT: |
| 1932 | case GL_INTENSITY32I_EXT: |
| 1933 | case GL_INTENSITY32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1934 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1935 | ctx->Extensions.EXT_texture_integer && |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1936 | ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0; |
| 1937 | |
| 1938 | case GL_LUMINANCE8I_EXT: |
| 1939 | case GL_LUMINANCE8UI_EXT: |
| 1940 | case GL_LUMINANCE16I_EXT: |
| 1941 | case GL_LUMINANCE16UI_EXT: |
| 1942 | case GL_LUMINANCE32I_EXT: |
| 1943 | case GL_LUMINANCE32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1944 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1945 | ctx->Extensions.EXT_texture_integer && |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1946 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0; |
| 1947 | |
| 1948 | case GL_LUMINANCE_ALPHA8I_EXT: |
| 1949 | case GL_LUMINANCE_ALPHA8UI_EXT: |
| 1950 | case GL_LUMINANCE_ALPHA16I_EXT: |
| 1951 | case GL_LUMINANCE_ALPHA16UI_EXT: |
| 1952 | case GL_LUMINANCE_ALPHA32I_EXT: |
| 1953 | case GL_LUMINANCE_ALPHA32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1954 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1955 | ctx->Extensions.EXT_texture_integer && |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1956 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0; |
Dave Airlie | f449be6 | 2011-11-27 16:21:02 +0000 | [diff] [blame] | 1957 | |
Marek Olšák | 636802f | 2012-01-22 20:21:36 +0100 | [diff] [blame] | 1958 | case GL_ALPHA8I_EXT: |
| 1959 | case GL_ALPHA8UI_EXT: |
| 1960 | case GL_ALPHA16I_EXT: |
| 1961 | case GL_ALPHA16UI_EXT: |
| 1962 | case GL_ALPHA32I_EXT: |
| 1963 | case GL_ALPHA32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1964 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1965 | ctx->Extensions.EXT_texture_integer && |
Marek Olšák | 636802f | 2012-01-22 20:21:36 +0100 | [diff] [blame] | 1966 | ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0; |
| 1967 | |
Dave Airlie | f449be6 | 2011-11-27 16:21:02 +0000 | [diff] [blame] | 1968 | case GL_RGB10_A2UI: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1969 | return (_mesa_is_desktop_gl(ctx) && |
| 1970 | ctx->Extensions.ARB_texture_rgb10_a2ui) |
| 1971 | || _mesa_is_gles3(ctx) ? GL_RGBA : 0; |
Marek Olšák | 1a06e84 | 2012-07-12 14:07:41 +0200 | [diff] [blame] | 1972 | |
| 1973 | case GL_RGB565: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1974 | return _mesa_is_gles(ctx) || ctx->Extensions.ARB_ES2_compatibility |
| 1975 | ? GL_RGB : 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1976 | default: |
Eric Anholt | 65c41d5 | 2011-01-13 10:05:50 -0800 | [diff] [blame] | 1977 | return 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1978 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 1982 | /** |
| 1983 | * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk(). |
| 1984 | */ |
| 1985 | static void |
| 1986 | invalidate_rb(GLuint key, void *data, void *userData) |
| 1987 | { |
| 1988 | struct gl_framebuffer *fb = (struct gl_framebuffer *) data; |
| 1989 | struct gl_renderbuffer *rb = (struct gl_renderbuffer *) userData; |
| 1990 | |
| 1991 | /* If this is a user-created FBO */ |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 1992 | if (_mesa_is_user_fbo(fb)) { |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 1993 | GLuint i; |
| 1994 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 1995 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
| 1996 | if (att->Type == GL_RENDERBUFFER && |
| 1997 | att->Renderbuffer == rb) { |
| 1998 | /* Mark fb status as indeterminate to force re-validation */ |
| 1999 | fb->_Status = 0; |
Marek Olšák | a674ef7 | 2011-03-07 23:33:36 +0100 | [diff] [blame] | 2000 | return; |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 2001 | } |
| 2002 | } |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2007 | /** sentinal value, see below */ |
| 2008 | #define NO_SAMPLES 1000 |
| 2009 | |
Ian Romanick | eb5bc62 | 2015-11-12 09:11:20 -0800 | [diff] [blame] | 2010 | void |
| 2011 | _mesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, |
| 2012 | GLenum internalFormat, GLsizei width, |
| 2013 | GLsizei height, GLsizei samples) |
| 2014 | { |
| 2015 | const GLenum baseFormat = _mesa_base_fbo_format(ctx, internalFormat); |
| 2016 | |
| 2017 | assert(baseFormat != 0); |
| 2018 | assert(width >= 0 && width <= (GLsizei) ctx->Const.MaxRenderbufferSize); |
| 2019 | assert(height >= 0 && height <= (GLsizei) ctx->Const.MaxRenderbufferSize); |
| 2020 | assert(samples != NO_SAMPLES); |
| 2021 | if (samples != 0) { |
| 2022 | assert(samples > 0); |
| 2023 | assert(_mesa_check_sample_count(ctx, GL_RENDERBUFFER, |
| 2024 | internalFormat, samples) == GL_NO_ERROR); |
| 2025 | } |
| 2026 | |
| 2027 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 2028 | |
| 2029 | if (rb->InternalFormat == internalFormat && |
| 2030 | rb->Width == (GLuint) width && |
| 2031 | rb->Height == (GLuint) height && |
| 2032 | rb->NumSamples == samples) { |
| 2033 | /* no change in allocation needed */ |
| 2034 | return; |
| 2035 | } |
| 2036 | |
| 2037 | /* These MUST get set by the AllocStorage func */ |
| 2038 | rb->Format = MESA_FORMAT_NONE; |
| 2039 | rb->NumSamples = samples; |
| 2040 | |
| 2041 | /* Now allocate the storage */ |
| 2042 | assert(rb->AllocStorage); |
| 2043 | if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) { |
| 2044 | /* No error - check/set fields now */ |
| 2045 | /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */ |
| 2046 | assert(rb->Width == (GLuint) width); |
| 2047 | assert(rb->Height == (GLuint) height); |
| 2048 | rb->InternalFormat = internalFormat; |
| 2049 | rb->_BaseFormat = baseFormat; |
| 2050 | assert(rb->_BaseFormat != 0); |
| 2051 | } |
| 2052 | else { |
| 2053 | /* Probably ran out of memory - clear the fields */ |
| 2054 | rb->Width = 0; |
| 2055 | rb->Height = 0; |
| 2056 | rb->Format = MESA_FORMAT_NONE; |
| 2057 | rb->InternalFormat = GL_NONE; |
| 2058 | rb->_BaseFormat = GL_NONE; |
| 2059 | rb->NumSamples = 0; |
| 2060 | } |
| 2061 | |
| 2062 | /* Invalidate the framebuffers the renderbuffer is attached in. */ |
| 2063 | if (rb->AttachedAnytime) { |
| 2064 | _mesa_HashWalk(ctx->Shared->FrameBuffers, invalidate_rb, rb); |
| 2065 | } |
| 2066 | } |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2067 | |
| 2068 | /** |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2069 | * Helper function used by renderbuffer_storage_direct() and |
| 2070 | * renderbuffer_storage_target(). |
| 2071 | * samples will be NO_SAMPLES if called by a non-multisample function. |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2072 | */ |
| 2073 | static void |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2074 | renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, |
| 2075 | GLenum internalFormat, GLsizei width, |
| 2076 | GLsizei height, GLsizei samples, const char *func) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2077 | { |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2078 | GLenum baseFormat; |
Chris Forbes | 90b5a24 | 2013-02-06 20:42:53 +1300 | [diff] [blame] | 2079 | GLenum sample_count_error; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2080 | |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 2081 | baseFormat = _mesa_base_fbo_format(ctx, internalFormat); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2082 | if (baseFormat == 0) { |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 2083 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat=%s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2084 | func, _mesa_enum_to_string(internalFormat)); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2085 | return; |
| 2086 | } |
| 2087 | |
Yuanhan Liu | 49f8447 | 2011-10-25 15:36:59 +0800 | [diff] [blame] | 2088 | if (width < 0 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) { |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2089 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid width %d)", func, |
| 2090 | width); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2091 | return; |
| 2092 | } |
| 2093 | |
Yuanhan Liu | 49f8447 | 2011-10-25 15:36:59 +0800 | [diff] [blame] | 2094 | if (height < 0 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) { |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2095 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid height %d)", func, |
| 2096 | height); |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2097 | return; |
| 2098 | } |
| 2099 | |
| 2100 | if (samples == NO_SAMPLES) { |
| 2101 | /* NumSamples == 0 indicates non-multisampling */ |
| 2102 | samples = 0; |
| 2103 | } |
Chris Forbes | 21a2dfa | 2013-03-25 23:19:07 +1300 | [diff] [blame] | 2104 | else { |
| 2105 | /* check the sample count; |
| 2106 | * note: driver may choose to use more samples than what's requested |
| 2107 | */ |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2108 | sample_count_error = _mesa_check_sample_count(ctx, GL_RENDERBUFFER, |
Chris Forbes | 21a2dfa | 2013-03-25 23:19:07 +1300 | [diff] [blame] | 2109 | internalFormat, samples); |
Timothy Arceri | 46684d3 | 2015-08-13 18:44:51 +1000 | [diff] [blame] | 2110 | |
| 2111 | /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16: |
| 2112 | * |
| 2113 | * "If a negative number is provided where an argument of type sizei or |
| 2114 | * sizeiptr is specified, the error INVALID VALUE is generated." |
| 2115 | */ |
| 2116 | if (samples < 0) { |
| 2117 | sample_count_error = GL_INVALID_VALUE; |
| 2118 | } |
| 2119 | |
Chris Forbes | 21a2dfa | 2013-03-25 23:19:07 +1300 | [diff] [blame] | 2120 | if (sample_count_error != GL_NO_ERROR) { |
| 2121 | _mesa_error(ctx, sample_count_error, "%s(samples)", func); |
| 2122 | return; |
| 2123 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
Ian Romanick | eb5bc62 | 2015-11-12 09:11:20 -0800 | [diff] [blame] | 2126 | _mesa_renderbuffer_storage(ctx, rb, internalFormat, width, height, samples); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2129 | /** |
| 2130 | * Helper function used by _mesa_NamedRenderbufferStorage*(). |
| 2131 | * samples will be NO_SAMPLES if called by a non-multisample function. |
| 2132 | */ |
| 2133 | static void |
| 2134 | renderbuffer_storage_named(GLuint renderbuffer, GLenum internalFormat, |
| 2135 | GLsizei width, GLsizei height, GLsizei samples, |
| 2136 | const char *func) |
| 2137 | { |
| 2138 | GET_CURRENT_CONTEXT(ctx); |
| 2139 | |
| 2140 | if (MESA_VERBOSE & VERBOSE_API) { |
| 2141 | if (samples == NO_SAMPLES) |
| 2142 | _mesa_debug(ctx, "%s(%u, %s, %d, %d)\n", |
| 2143 | func, renderbuffer, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2144 | _mesa_enum_to_string(internalFormat), |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2145 | width, height); |
| 2146 | else |
| 2147 | _mesa_debug(ctx, "%s(%u, %s, %d, %d, %d)\n", |
| 2148 | func, renderbuffer, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2149 | _mesa_enum_to_string(internalFormat), |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2150 | width, height, samples); |
| 2151 | } |
| 2152 | |
| 2153 | struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
| 2154 | if (!rb || rb == &DummyRenderbuffer) { |
| 2155 | /* ID was reserved, but no real renderbuffer object made yet */ |
| 2156 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid renderbuffer %u)", |
| 2157 | func, renderbuffer); |
| 2158 | return; |
| 2159 | } |
| 2160 | |
| 2161 | renderbuffer_storage(ctx, rb, internalFormat, width, height, samples, func); |
| 2162 | } |
| 2163 | |
| 2164 | /** |
| 2165 | * Helper function used by _mesa_RenderbufferStorage() and |
| 2166 | * _mesa_RenderbufferStorageMultisample(). |
| 2167 | * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage(). |
| 2168 | */ |
| 2169 | static void |
| 2170 | renderbuffer_storage_target(GLenum target, GLenum internalFormat, |
| 2171 | GLsizei width, GLsizei height, GLsizei samples, |
| 2172 | const char *func) |
| 2173 | { |
| 2174 | GET_CURRENT_CONTEXT(ctx); |
| 2175 | |
| 2176 | if (MESA_VERBOSE & VERBOSE_API) { |
| 2177 | if (samples == NO_SAMPLES) |
| 2178 | _mesa_debug(ctx, "%s(%s, %s, %d, %d)\n", |
| 2179 | func, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2180 | _mesa_enum_to_string(target), |
| 2181 | _mesa_enum_to_string(internalFormat), |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2182 | width, height); |
| 2183 | else |
| 2184 | _mesa_debug(ctx, "%s(%s, %s, %d, %d, %d)\n", |
| 2185 | func, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2186 | _mesa_enum_to_string(target), |
| 2187 | _mesa_enum_to_string(internalFormat), |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2188 | width, height, samples); |
| 2189 | } |
| 2190 | |
| 2191 | if (target != GL_RENDERBUFFER_EXT) { |
| 2192 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func); |
| 2193 | return; |
| 2194 | } |
| 2195 | |
| 2196 | if (!ctx->CurrentRenderbuffer) { |
| 2197 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no renderbuffer bound)", |
| 2198 | func); |
| 2199 | return; |
| 2200 | } |
| 2201 | |
| 2202 | renderbuffer_storage(ctx, ctx->CurrentRenderbuffer, internalFormat, width, |
| 2203 | height, samples, func); |
| 2204 | } |
| 2205 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2206 | |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2207 | void GLAPIENTRY |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2208 | _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2209 | { |
Brian Paul | 51b7992 | 2010-02-24 11:57:26 -0700 | [diff] [blame] | 2210 | struct gl_renderbuffer *rb; |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2211 | GET_CURRENT_CONTEXT(ctx); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2212 | |
Chia-I Wu | 2002e4d0 | 2010-04-06 17:46:17 +0800 | [diff] [blame] | 2213 | if (!ctx->Extensions.OES_EGL_image) { |
| 2214 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2215 | "glEGLImageTargetRenderbufferStorageOES(unsupported)"); |
| 2216 | return; |
| 2217 | } |
| 2218 | |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2219 | if (target != GL_RENDERBUFFER) { |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2220 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2221 | "EGLImageTargetRenderbufferStorageOES"); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2222 | return; |
| 2223 | } |
| 2224 | |
| 2225 | rb = ctx->CurrentRenderbuffer; |
| 2226 | if (!rb) { |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2227 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2228 | "EGLImageTargetRenderbufferStorageOES"); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 2229 | return; |
| 2230 | } |
| 2231 | |
| 2232 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 2233 | |
| 2234 | ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image); |
| 2235 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2236 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2237 | |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2238 | /** |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2239 | * Helper function for _mesa_GetRenderbufferParameteriv() and |
| 2240 | * _mesa_GetFramebufferAttachmentParameteriv() |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2241 | * We have to be careful to respect the base format. For example, if a |
| 2242 | * renderbuffer/texture was created with internalFormat=GL_RGB but the |
| 2243 | * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE |
| 2244 | * we need to return zero. |
| 2245 | */ |
| 2246 | static GLint |
Mark Mueller | 71fe943 | 2014-01-04 14:11:43 -0800 | [diff] [blame] | 2247 | get_component_bits(GLenum pname, GLenum baseFormat, mesa_format format) |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2248 | { |
Brian Paul | f0b6e9a | 2011-11-23 15:33:45 -0700 | [diff] [blame] | 2249 | if (_mesa_base_format_has_channel(baseFormat, pname)) |
| 2250 | return _mesa_get_format_bits(format, pname); |
| 2251 | else |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2252 | return 0; |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | |
| 2256 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2257 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2258 | _mesa_RenderbufferStorage(GLenum target, GLenum internalFormat, |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2259 | GLsizei width, GLsizei height) |
| 2260 | { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2261 | /* GL_ARB_fbo says calling this function is equivalent to calling |
| 2262 | * glRenderbufferStorageMultisample() with samples=0. We pass in |
| 2263 | * a token value here just for error reporting purposes. |
| 2264 | */ |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2265 | renderbuffer_storage_target(target, internalFormat, width, height, |
| 2266 | NO_SAMPLES, "glRenderbufferStorage"); |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | |
| 2270 | void GLAPIENTRY |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 2271 | _mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples, |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 2272 | GLenum internalFormat, |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 2273 | GLsizei width, GLsizei height) |
| 2274 | { |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2275 | renderbuffer_storage_target(target, internalFormat, width, height, |
| 2276 | samples, "glRenderbufferStorageMultisample"); |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2279 | |
| 2280 | /** |
| 2281 | * OpenGL ES version of glRenderBufferStorage. |
| 2282 | */ |
Kristian Høgsberg | 61d94dd | 2010-04-22 21:11:56 -0400 | [diff] [blame] | 2283 | void GLAPIENTRY |
| 2284 | _es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat, |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 2285 | GLsizei width, GLsizei height) |
Kristian Høgsberg | 61d94dd | 2010-04-22 21:11:56 -0400 | [diff] [blame] | 2286 | { |
| 2287 | switch (internalFormat) { |
| 2288 | case GL_RGB565: |
| 2289 | /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */ |
| 2290 | /* choose a closest format */ |
| 2291 | internalFormat = GL_RGB5; |
| 2292 | break; |
| 2293 | default: |
| 2294 | break; |
| 2295 | } |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 2296 | |
Martin Peres | bf11c19 | 2015-02-13 15:35:48 +0200 | [diff] [blame] | 2297 | renderbuffer_storage_target(target, internalFormat, width, height, 0, |
| 2298 | "glRenderbufferStorageEXT"); |
| 2299 | } |
| 2300 | |
| 2301 | void GLAPIENTRY |
| 2302 | _mesa_NamedRenderbufferStorage(GLuint renderbuffer, GLenum internalformat, |
| 2303 | GLsizei width, GLsizei height) |
| 2304 | { |
| 2305 | /* GL_ARB_fbo says calling this function is equivalent to calling |
| 2306 | * glRenderbufferStorageMultisample() with samples=0. We pass in |
| 2307 | * a token value here just for error reporting purposes. |
| 2308 | */ |
| 2309 | renderbuffer_storage_named(renderbuffer, internalformat, width, height, |
| 2310 | NO_SAMPLES, "glNamedRenderbufferStorage"); |
| 2311 | } |
| 2312 | |
| 2313 | void GLAPIENTRY |
| 2314 | _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer, GLsizei samples, |
| 2315 | GLenum internalformat, |
| 2316 | GLsizei width, GLsizei height) |
| 2317 | { |
| 2318 | renderbuffer_storage_named(renderbuffer, internalformat, width, height, |
| 2319 | samples, |
| 2320 | "glNamedRenderbufferStorageMultisample"); |
Kristian Høgsberg | 61d94dd | 2010-04-22 21:11:56 -0400 | [diff] [blame] | 2321 | } |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 2322 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 2323 | |
Martin Peres | 245e5c4 | 2015-02-13 15:46:55 +0200 | [diff] [blame] | 2324 | static void |
| 2325 | get_render_buffer_parameteriv(struct gl_context *ctx, |
| 2326 | struct gl_renderbuffer *rb, GLenum pname, |
| 2327 | GLint *params, const char *func) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2328 | { |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 2329 | /* No need to flush here since we're just quering state which is |
| 2330 | * not effected by rendering. |
| 2331 | */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 2332 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2333 | switch (pname) { |
| 2334 | case GL_RENDERBUFFER_WIDTH_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2335 | *params = rb->Width; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2336 | return; |
| 2337 | case GL_RENDERBUFFER_HEIGHT_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2338 | *params = rb->Height; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2339 | return; |
| 2340 | case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2341 | *params = rb->InternalFormat; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2342 | return; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2343 | case GL_RENDERBUFFER_RED_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2344 | case GL_RENDERBUFFER_GREEN_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2345 | case GL_RENDERBUFFER_BLUE_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2346 | case GL_RENDERBUFFER_ALPHA_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2347 | case GL_RENDERBUFFER_DEPTH_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2348 | case GL_RENDERBUFFER_STENCIL_SIZE_EXT: |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2349 | *params = get_component_bits(pname, rb->_BaseFormat, rb->Format); |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2350 | break; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2351 | case GL_RENDERBUFFER_SAMPLES: |
Ian Romanick | ae86ebf | 2012-07-27 07:49:49 -0700 | [diff] [blame] | 2352 | if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_framebuffer_object) |
| 2353 | || _mesa_is_gles3(ctx)) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2354 | *params = rb->NumSamples; |
| 2355 | break; |
| 2356 | } |
| 2357 | /* fallthrough */ |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2358 | default: |
Martin Peres | 245e5c4 | 2015-02-13 15:46:55 +0200 | [diff] [blame] | 2359 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid pname=%s)", func, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2360 | _mesa_enum_to_string(pname)); |
Martin Peres | 245e5c4 | 2015-02-13 15:46:55 +0200 | [diff] [blame] | 2361 | return; |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | |
| 2366 | void GLAPIENTRY |
| 2367 | _mesa_GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params) |
| 2368 | { |
| 2369 | GET_CURRENT_CONTEXT(ctx); |
| 2370 | |
| 2371 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2372 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2373 | "glGetRenderbufferParameterivEXT(target)"); |
| 2374 | return; |
| 2375 | } |
Martin Peres | 245e5c4 | 2015-02-13 15:46:55 +0200 | [diff] [blame] | 2376 | |
| 2377 | if (!ctx->CurrentRenderbuffer) { |
| 2378 | _mesa_error(ctx, GL_INVALID_OPERATION, "glGetRenderbufferParameterivEXT" |
| 2379 | "(no renderbuffer bound)"); |
| 2380 | return; |
| 2381 | } |
| 2382 | |
| 2383 | get_render_buffer_parameteriv(ctx, ctx->CurrentRenderbuffer, pname, |
| 2384 | params, "glGetRenderbufferParameteriv"); |
| 2385 | } |
| 2386 | |
| 2387 | |
| 2388 | void GLAPIENTRY |
| 2389 | _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer, GLenum pname, |
| 2390 | GLint *params) |
| 2391 | { |
| 2392 | GET_CURRENT_CONTEXT(ctx); |
| 2393 | |
| 2394 | struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
| 2395 | if (!rb || rb == &DummyRenderbuffer) { |
| 2396 | /* ID was reserved, but no real renderbuffer object made yet */ |
| 2397 | _mesa_error(ctx, GL_INVALID_OPERATION, "glGetNamedRenderbufferParameteriv" |
| 2398 | "(invalid renderbuffer %i)", renderbuffer); |
| 2399 | return; |
| 2400 | } |
| 2401 | |
| 2402 | get_render_buffer_parameteriv(ctx, rb, pname, params, |
| 2403 | "glGetNamedRenderbufferParameteriv"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2407 | GLboolean GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2408 | _mesa_IsFramebuffer(GLuint framebuffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2409 | { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2410 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2411 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 2412 | if (framebuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2413 | struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 2414 | if (rb != NULL && rb != &DummyFramebuffer) |
| 2415 | return GL_TRUE; |
| 2416 | } |
| 2417 | return GL_FALSE; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | |
brian | a492ab7 | 2009-11-10 15:33:31 -0700 | [diff] [blame] | 2421 | /** |
| 2422 | * Check if any of the attachments of the given framebuffer are textures |
| 2423 | * (render to texture). Call ctx->Driver.RenderTexture() for such |
| 2424 | * attachments. |
| 2425 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2426 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 2427 | check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb) |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2428 | { |
| 2429 | GLuint i; |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 2430 | assert(ctx->Driver.RenderTexture); |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2431 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 2432 | if (_mesa_is_winsys_fbo(fb)) |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2433 | return; /* can't render to texture with winsys framebuffers */ |
| 2434 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2435 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 2436 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
Ian Romanick | fb49713 | 2013-07-27 12:04:20 -0700 | [diff] [blame] | 2437 | if (att->Texture && att->Renderbuffer->TexImage |
| 2438 | && driver_RenderTexture_is_safe(att)) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2439 | ctx->Driver.RenderTexture(ctx, fb, att); |
| 2440 | } |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 2445 | /** |
| 2446 | * Examine all the framebuffer's attachments to see if any are textures. |
| 2447 | * If so, call ctx->Driver.FinishRenderTexture() for each texture to |
| 2448 | * notify the device driver that the texture image may have changed. |
| 2449 | */ |
| 2450 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 2451 | check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb) |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 2452 | { |
Eric Anholt | 7ccb26f | 2014-03-03 09:16:48 -0800 | [diff] [blame] | 2453 | /* Skip if we know NeedsFinishRenderTexture won't be set. */ |
| 2454 | if (_mesa_is_winsys_fbo(fb) && !ctx->Driver.BindRenderbufferTexImage) |
| 2455 | return; |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2456 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 2457 | if (ctx->Driver.FinishRenderTexture) { |
| 2458 | GLuint i; |
| 2459 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 2460 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
Eric Anholt | c810e67 | 2013-05-10 12:36:43 -0700 | [diff] [blame] | 2461 | struct gl_renderbuffer *rb = att->Renderbuffer; |
| 2462 | if (rb && rb->NeedsFinishRenderTexture) { |
Eric Anholt | a5b0452 | 2013-05-10 12:17:52 -0700 | [diff] [blame] | 2463 | ctx->Driver.FinishRenderTexture(ctx, rb); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | } |
| 2467 | } |
| 2468 | |
| 2469 | |
Ian Romanick | 4a9522a | 2013-07-18 17:39:22 -0700 | [diff] [blame] | 2470 | static void |
| 2471 | bind_framebuffer(GLenum target, GLuint framebuffer, bool allow_user_names) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2472 | { |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 2473 | struct gl_framebuffer *newDrawFb, *newReadFb; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2474 | GLboolean bindReadBuf, bindDrawBuf; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2475 | GET_CURRENT_CONTEXT(ctx); |
| 2476 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2477 | switch (target) { |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2478 | case GL_DRAW_FRAMEBUFFER_EXT: |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2479 | bindDrawBuf = GL_TRUE; |
| 2480 | bindReadBuf = GL_FALSE; |
| 2481 | break; |
| 2482 | case GL_READ_FRAMEBUFFER_EXT: |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2483 | bindDrawBuf = GL_FALSE; |
| 2484 | bindReadBuf = GL_TRUE; |
| 2485 | break; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2486 | case GL_FRAMEBUFFER_EXT: |
| 2487 | bindDrawBuf = GL_TRUE; |
| 2488 | bindReadBuf = GL_TRUE; |
| 2489 | break; |
| 2490 | default: |
Brian Paul | eba4ff6 | 2005-09-06 21:22:16 +0000 | [diff] [blame] | 2491 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2492 | return; |
| 2493 | } |
| 2494 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2495 | if (framebuffer) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 2496 | /* Binding a user-created framebuffer object */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 2497 | newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer); |
| 2498 | if (newDrawFb == &DummyFramebuffer) { |
Brian Paul | 923b6fc | 2005-02-08 04:08:56 +0000 | [diff] [blame] | 2499 | /* ID was reserved, but no real framebuffer object made yet */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 2500 | newDrawFb = NULL; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2501 | } |
Ian Romanick | 4a9522a | 2013-07-18 17:39:22 -0700 | [diff] [blame] | 2502 | else if (!newDrawFb && !allow_user_names) { |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2503 | /* All FBO IDs must be Gen'd */ |
| 2504 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)"); |
| 2505 | return; |
| 2506 | } |
| 2507 | |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 2508 | if (!newDrawFb) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 2509 | /* create new framebuffer object */ |
| 2510 | newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer); |
| 2511 | if (!newDrawFb) { |
| 2512 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT"); |
| 2513 | return; |
| 2514 | } |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 2515 | _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2516 | } |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 2517 | newReadFb = newDrawFb; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2518 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2519 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 2520 | /* Binding the window system framebuffer (which was originally set |
| 2521 | * with MakeCurrent). |
| 2522 | */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 2523 | newDrawFb = ctx->WinSysDrawBuffer; |
| 2524 | newReadFb = ctx->WinSysReadBuffer; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
Ian Romanick | fed9b0e | 2015-11-13 10:46:40 -0800 | [diff] [blame] | 2527 | _mesa_bind_framebuffers(ctx, |
| 2528 | bindDrawBuf ? newDrawFb : ctx->DrawBuffer, |
| 2529 | bindReadBuf ? newReadFb : ctx->ReadBuffer); |
| 2530 | } |
| 2531 | |
| 2532 | void |
| 2533 | _mesa_bind_framebuffers(struct gl_context *ctx, |
| 2534 | struct gl_framebuffer *newDrawFb, |
| 2535 | struct gl_framebuffer *newReadFb) |
| 2536 | { |
| 2537 | struct gl_framebuffer *const oldDrawFb = ctx->DrawBuffer; |
| 2538 | struct gl_framebuffer *const oldReadFb = ctx->ReadBuffer; |
| 2539 | const bool bindDrawBuf = oldDrawFb != newDrawFb; |
| 2540 | const bool bindReadBuf = oldReadFb != newReadFb; |
| 2541 | |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 2542 | assert(newDrawFb); |
| 2543 | assert(newDrawFb != &DummyFramebuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2544 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2545 | /* |
Brian Paul | 1614463 | 2009-02-26 14:49:24 -0700 | [diff] [blame] | 2546 | * OK, now bind the new Draw/Read framebuffers, if they're changing. |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2547 | * |
| 2548 | * We also check if we're beginning and/or ending render-to-texture. |
| 2549 | * When a framebuffer with texture attachments is unbound, call |
| 2550 | * ctx->Driver.FinishRenderTexture(). |
| 2551 | * When a framebuffer with texture attachments is bound, call |
| 2552 | * ctx->Driver.RenderTexture(). |
| 2553 | * |
| 2554 | * Note that if the ReadBuffer has texture attachments we don't consider |
| 2555 | * that a render-to-texture case. |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2556 | */ |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2557 | if (bindReadBuf) { |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2558 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
brian | bc569cd | 2009-11-10 16:00:35 -0700 | [diff] [blame] | 2559 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2560 | /* check if old readbuffer was render-to-texture */ |
| 2561 | check_end_texture_render(ctx, oldReadFb); |
| 2562 | |
| 2563 | _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb); |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | if (bindDrawBuf) { |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2567 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian | 32d86eb | 2007-08-16 18:52:48 +0100 | [diff] [blame] | 2568 | |
Eric Anholt | a1fd13f | 2012-02-10 12:05:16 -0800 | [diff] [blame] | 2569 | /* check if old framebuffer had any texture attachments */ |
| 2570 | if (oldDrawFb) |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2571 | check_end_texture_render(ctx, oldDrawFb); |
brian | bc569cd | 2009-11-10 16:00:35 -0700 | [diff] [blame] | 2572 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 2573 | /* check if newly bound framebuffer has any texture attachments */ |
| 2574 | check_begin_texture_render(ctx, newDrawFb); |
| 2575 | |
| 2576 | _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb); |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2577 | } |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 2578 | |
Brian Paul | 1614463 | 2009-02-26 14:49:24 -0700 | [diff] [blame] | 2579 | if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) { |
Ian Romanick | fed9b0e | 2015-11-13 10:46:40 -0800 | [diff] [blame] | 2580 | /* The few classic drivers that actually hook this function really only |
| 2581 | * want to know if the draw framebuffer changed. |
| 2582 | */ |
| 2583 | ctx->Driver.BindFramebuffer(ctx, |
| 2584 | bindDrawBuf ? GL_FRAMEBUFFER : GL_READ_FRAMEBUFFER, |
| 2585 | newDrawFb, newReadFb); |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 2586 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 2589 | void GLAPIENTRY |
Ian Romanick | 4a9522a | 2013-07-18 17:39:22 -0700 | [diff] [blame] | 2590 | _mesa_BindFramebuffer(GLenum target, GLuint framebuffer) |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 2591 | { |
Ian Romanick | 4a9522a | 2013-07-18 17:39:22 -0700 | [diff] [blame] | 2592 | GET_CURRENT_CONTEXT(ctx); |
| 2593 | |
| 2594 | /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry |
| 2595 | * point, but they allow the use of user-generated names. |
| 2596 | */ |
| 2597 | bind_framebuffer(target, framebuffer, _mesa_is_gles(ctx)); |
Tomasz Lis | 9f07ca1 | 2013-07-16 20:57:26 +0200 | [diff] [blame] | 2598 | } |
| 2599 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 2600 | |
Ian Romanick | 4a9522a | 2013-07-18 17:39:22 -0700 | [diff] [blame] | 2601 | void GLAPIENTRY |
| 2602 | _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer) |
| 2603 | { |
| 2604 | /* This function should not be in the dispatch table for core profile / |
| 2605 | * OpenGL 3.1, so execution should never get here in those cases -- no |
| 2606 | * need for an explicit test. |
| 2607 | */ |
| 2608 | bind_framebuffer(target, framebuffer, true); |
| 2609 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2610 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 2611 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2612 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2613 | _mesa_DeleteFramebuffers(GLsizei n, const GLuint *framebuffers) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2614 | { |
| 2615 | GLint i; |
| 2616 | GET_CURRENT_CONTEXT(ctx); |
| 2617 | |
Eduardo Lima Mitev | f77a473 | 2014-12-11 23:34:17 +0100 | [diff] [blame] | 2618 | if (n < 0) { |
| 2619 | _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteFramebuffers(n < 0)"); |
| 2620 | return; |
| 2621 | } |
| 2622 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 2623 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2624 | |
| 2625 | for (i = 0; i < n; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 2626 | if (framebuffers[i] > 0) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 2627 | struct gl_framebuffer *fb; |
| 2628 | fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]); |
| 2629 | if (fb) { |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 2630 | assert(fb == &DummyFramebuffer || fb->Name == framebuffers[i]); |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 2631 | |
| 2632 | /* check if deleting currently bound framebuffer object */ |
Ian Romanick | 764be9f | 2013-11-13 14:00:06 -0800 | [diff] [blame] | 2633 | if (fb == ctx->DrawBuffer) { |
| 2634 | /* bind default */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 2635 | assert(fb->RefCount >= 2); |
Ian Romanick | 764be9f | 2013-11-13 14:00:06 -0800 | [diff] [blame] | 2636 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); |
| 2637 | } |
| 2638 | if (fb == ctx->ReadBuffer) { |
| 2639 | /* bind default */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 2640 | assert(fb->RefCount >= 2); |
Ian Romanick | 764be9f | 2013-11-13 14:00:06 -0800 | [diff] [blame] | 2641 | _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, 0); |
| 2642 | } |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 2643 | |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 2644 | /* remove from hash table immediately, to free the ID */ |
| 2645 | _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2646 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2647 | if (fb != &DummyFramebuffer) { |
| 2648 | /* But the object will not be freed until it's no longer |
| 2649 | * bound in any context. |
| 2650 | */ |
Brian Paul | d522944 | 2009-02-09 08:30:55 -0700 | [diff] [blame] | 2651 | _mesa_reference_framebuffer(&fb, NULL); |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 2652 | } |
| 2653 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2654 | } |
| 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 2659 | /** |
| 2660 | * This is the implementation for glGenFramebuffers and glCreateFramebuffers. |
| 2661 | * It is not exposed to the rest of Mesa to encourage the use of |
| 2662 | * nameless buffers in driver internals. |
| 2663 | */ |
| 2664 | static void |
| 2665 | create_framebuffers(GLsizei n, GLuint *framebuffers, bool dsa) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2666 | { |
| 2667 | GET_CURRENT_CONTEXT(ctx); |
| 2668 | GLuint first; |
| 2669 | GLint i; |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 2670 | struct gl_framebuffer *fb; |
| 2671 | |
| 2672 | const char *func = dsa ? "glCreateFramebuffers" : "glGenFramebuffers"; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2673 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2674 | if (n < 0) { |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 2675 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2676 | return; |
| 2677 | } |
| 2678 | |
| 2679 | if (!framebuffers) |
| 2680 | return; |
| 2681 | |
| 2682 | first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n); |
| 2683 | |
| 2684 | for (i = 0; i < n; i++) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2685 | GLuint name = first + i; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 2686 | framebuffers[i] = name; |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 2687 | |
| 2688 | if (dsa) { |
| 2689 | fb = ctx->Driver.NewFramebuffer(ctx, framebuffers[i]); |
| 2690 | if (!fb) { |
| 2691 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); |
| 2692 | return; |
| 2693 | } |
| 2694 | } |
| 2695 | else |
| 2696 | fb = &DummyFramebuffer; |
| 2697 | |
Brian Paul | d129ea7 | 2014-03-01 10:21:07 -0700 | [diff] [blame] | 2698 | mtx_lock(&ctx->Shared->Mutex); |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 2699 | _mesa_HashInsert(ctx->Shared->FrameBuffers, name, fb); |
Brian Paul | d129ea7 | 2014-03-01 10:21:07 -0700 | [diff] [blame] | 2700 | mtx_unlock(&ctx->Shared->Mutex); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2701 | } |
| 2702 | } |
| 2703 | |
| 2704 | |
Laura Ekstrand | f868de7 | 2015-01-23 14:54:48 -0800 | [diff] [blame] | 2705 | void GLAPIENTRY |
| 2706 | _mesa_GenFramebuffers(GLsizei n, GLuint *framebuffers) |
| 2707 | { |
| 2708 | create_framebuffers(n, framebuffers, false); |
| 2709 | } |
| 2710 | |
| 2711 | |
| 2712 | void GLAPIENTRY |
| 2713 | _mesa_CreateFramebuffers(GLsizei n, GLuint *framebuffers) |
| 2714 | { |
| 2715 | create_framebuffers(n, framebuffers, true); |
| 2716 | } |
| 2717 | |
| 2718 | |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 2719 | GLenum |
| 2720 | _mesa_check_framebuffer_status(struct gl_context *ctx, |
| 2721 | struct gl_framebuffer *buffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2722 | { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 2723 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2724 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 2725 | if (_mesa_is_winsys_fbo(buffer)) { |
Matt Turner | 8dd15e6 | 2013-07-26 16:36:19 -0700 | [diff] [blame] | 2726 | /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */ |
| 2727 | if (buffer != &IncompleteFramebuffer) { |
| 2728 | return GL_FRAMEBUFFER_COMPLETE_EXT; |
| 2729 | } else { |
| 2730 | return GL_FRAMEBUFFER_UNDEFINED; |
| 2731 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 2732 | } |
| 2733 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 2734 | /* No need to flush here */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 2735 | |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 2736 | if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) { |
| 2737 | _mesa_test_framebuffer_completeness(ctx, buffer); |
| 2738 | } |
| 2739 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2740 | return buffer->_Status; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2741 | } |
| 2742 | |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 2743 | |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 2744 | GLenum GLAPIENTRY |
| 2745 | _mesa_CheckFramebufferStatus(GLenum target) |
| 2746 | { |
| 2747 | struct gl_framebuffer *fb; |
| 2748 | GET_CURRENT_CONTEXT(ctx); |
| 2749 | |
| 2750 | if (MESA_VERBOSE & VERBOSE_API) |
| 2751 | _mesa_debug(ctx, "glCheckFramebufferStatus(%s)\n", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2752 | _mesa_enum_to_string(target)); |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 2753 | |
| 2754 | fb = get_framebuffer_target(ctx, target); |
| 2755 | if (!fb) { |
| 2756 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2757 | "glCheckFramebufferStatus(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2758 | _mesa_enum_to_string(target)); |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 2759 | return 0; |
| 2760 | } |
| 2761 | |
| 2762 | return _mesa_check_framebuffer_status(ctx, fb); |
| 2763 | } |
| 2764 | |
| 2765 | |
| 2766 | GLenum GLAPIENTRY |
| 2767 | _mesa_CheckNamedFramebufferStatus(GLuint framebuffer, GLenum target) |
| 2768 | { |
| 2769 | struct gl_framebuffer *fb; |
| 2770 | GET_CURRENT_CONTEXT(ctx); |
| 2771 | |
| 2772 | /* Validate the target (for conformance's sake) and grab a reference to the |
| 2773 | * default framebuffer in case framebuffer = 0. |
| 2774 | * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec |
| 2775 | * (30.10.2014, PDF page 336) says: |
| 2776 | * "If framebuffer is zero, then the status of the default read or |
| 2777 | * draw framebuffer (as determined by target) is returned." |
| 2778 | */ |
| 2779 | switch (target) { |
| 2780 | case GL_DRAW_FRAMEBUFFER: |
| 2781 | case GL_FRAMEBUFFER: |
| 2782 | fb = ctx->WinSysDrawBuffer; |
| 2783 | break; |
| 2784 | case GL_READ_FRAMEBUFFER: |
| 2785 | fb = ctx->WinSysReadBuffer; |
| 2786 | break; |
| 2787 | default: |
| 2788 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2789 | "glCheckNamedFramebufferStatus(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2790 | _mesa_enum_to_string(target)); |
Laura Ekstrand | f93f959 | 2015-01-29 13:15:37 -0800 | [diff] [blame] | 2791 | return 0; |
| 2792 | } |
| 2793 | |
| 2794 | if (framebuffer) { |
| 2795 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 2796 | "glCheckNamedFramebufferStatus"); |
| 2797 | if (!fb) |
| 2798 | return 0; |
| 2799 | } |
| 2800 | |
| 2801 | return _mesa_check_framebuffer_status(ctx, fb); |
| 2802 | } |
| 2803 | |
| 2804 | |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2805 | /** |
| 2806 | * Replicate the src attachment point. Used by framebuffer_texture() when |
| 2807 | * the same texture is attached at GL_DEPTH_ATTACHMENT and |
| 2808 | * GL_STENCIL_ATTACHMENT. |
| 2809 | */ |
| 2810 | static void |
| 2811 | reuse_framebuffer_texture_attachment(struct gl_framebuffer *fb, |
| 2812 | gl_buffer_index dst, |
| 2813 | gl_buffer_index src) |
| 2814 | { |
| 2815 | struct gl_renderbuffer_attachment *dst_att = &fb->Attachment[dst]; |
| 2816 | struct gl_renderbuffer_attachment *src_att = &fb->Attachment[src]; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2817 | |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2818 | assert(src_att->Texture != NULL); |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 2819 | assert(src_att->Renderbuffer != NULL); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2820 | |
| 2821 | _mesa_reference_texobj(&dst_att->Texture, src_att->Texture); |
| 2822 | _mesa_reference_renderbuffer(&dst_att->Renderbuffer, src_att->Renderbuffer); |
| 2823 | dst_att->Type = src_att->Type; |
| 2824 | dst_att->Complete = src_att->Complete; |
| 2825 | dst_att->TextureLevel = src_att->TextureLevel; |
| 2826 | dst_att->Zoffset = src_att->Zoffset; |
Dave Airlie | 35859d5 | 2016-02-29 17:16:10 +1000 | [diff] [blame] | 2827 | dst_att->Layered = src_att->Layered; |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2828 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2829 | |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 2830 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2831 | /** |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 2832 | * Common code called by gl*FramebufferTexture*() to retrieve the correct |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2833 | * texture object pointer. |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 2834 | * |
| 2835 | * \param texObj where the pointer to the texture object is returned. Note |
| 2836 | * that a successful call may return texObj = NULL. |
| 2837 | * |
| 2838 | * \return true if no errors, false if errors |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2839 | */ |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 2840 | static bool |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2841 | get_texture_for_framebuffer(struct gl_context *ctx, GLuint texture, |
| 2842 | bool layered, const char *caller, |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 2843 | struct gl_texture_object **texObj) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2844 | { |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 2845 | *texObj = NULL; /* This will get returned if texture = 0. */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2846 | |
Laura Ekstrand | a9f73f7 | 2015-03-02 13:41:13 -0800 | [diff] [blame] | 2847 | if (!texture) |
| 2848 | return true; |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2849 | |
Laura Ekstrand | a9f73f7 | 2015-03-02 13:41:13 -0800 | [diff] [blame] | 2850 | *texObj = _mesa_lookup_texture(ctx, texture); |
| 2851 | if (*texObj == NULL || (*texObj)->Target == 0) { |
| 2852 | /* Can't render to a non-existent texture object. |
| 2853 | * |
| 2854 | * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and |
| 2855 | * Managing Framebuffer Objects specifies a different error |
| 2856 | * depending upon the calling function (PDF pages 325-328). |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2857 | * *FramebufferTexture (where layered = GL_TRUE) throws invalid |
Laura Ekstrand | a9f73f7 | 2015-03-02 13:41:13 -0800 | [diff] [blame] | 2858 | * value, while the other commands throw invalid operation (where |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2859 | * layered = GL_FALSE). |
Laura Ekstrand | a9f73f7 | 2015-03-02 13:41:13 -0800 | [diff] [blame] | 2860 | */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2861 | const GLenum error = layered ? GL_INVALID_VALUE : |
Laura Ekstrand | a9f73f7 | 2015-03-02 13:41:13 -0800 | [diff] [blame] | 2862 | GL_INVALID_OPERATION; |
| 2863 | _mesa_error(ctx, error, |
| 2864 | "%s(non-existent texture %u)", caller, texture); |
| 2865 | return false; |
| 2866 | } |
| 2867 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2868 | return true; |
| 2869 | } |
| 2870 | |
| 2871 | |
| 2872 | /** |
| 2873 | * Common code called by gl*FramebufferTexture() to verify the texture target |
| 2874 | * and decide whether or not the attachment should truly be considered |
| 2875 | * layered. |
| 2876 | * |
| 2877 | * \param layered true if attachment should be considered layered, false if |
| 2878 | * not |
| 2879 | * |
| 2880 | * \return true if no errors, false if errors |
| 2881 | */ |
| 2882 | static bool |
| 2883 | check_layered_texture_target(struct gl_context *ctx, GLenum target, |
| 2884 | const char *caller, GLboolean *layered) |
| 2885 | { |
| 2886 | *layered = GL_TRUE; |
| 2887 | |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 2888 | switch (target) { |
| 2889 | case GL_TEXTURE_3D: |
| 2890 | case GL_TEXTURE_1D_ARRAY_EXT: |
| 2891 | case GL_TEXTURE_2D_ARRAY_EXT: |
| 2892 | case GL_TEXTURE_CUBE_MAP: |
| 2893 | case GL_TEXTURE_CUBE_MAP_ARRAY: |
| 2894 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: |
| 2895 | return true; |
| 2896 | case GL_TEXTURE_1D: |
| 2897 | case GL_TEXTURE_2D: |
| 2898 | case GL_TEXTURE_RECTANGLE: |
| 2899 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 2900 | /* These texture types are valid to pass to |
| 2901 | * glFramebufferTexture(), but since they aren't layered, it |
| 2902 | * is equivalent to calling glFramebufferTexture{1D,2D}(). |
| 2903 | */ |
| 2904 | *layered = GL_FALSE; |
| 2905 | return true; |
| 2906 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2907 | |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 2908 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2909 | "%s(invalid texture target %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2910 | _mesa_enum_to_string(target)); |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 2911 | return false; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | |
| 2915 | /** |
| 2916 | * Common code called by gl*FramebufferTextureLayer() to verify the texture |
| 2917 | * target. |
| 2918 | * |
| 2919 | * \return true if no errors, false if errors |
| 2920 | */ |
| 2921 | static bool |
| 2922 | check_texture_target(struct gl_context *ctx, GLenum target, |
| 2923 | const char *caller) |
| 2924 | { |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 2925 | /* We're being called by glFramebufferTextureLayer(). |
| 2926 | * The only legal texture types for that function are 3D, |
| 2927 | * cube-map, and 1D/2D/cube-map array textures. |
Ian Romanick | 832ea23 | 2015-05-20 17:19:29 -0700 | [diff] [blame] | 2928 | * |
| 2929 | * We don't need to check for GL_ARB_texture_cube_map_array because the |
| 2930 | * application wouldn't have been able to create a texture with a |
| 2931 | * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled. |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 2932 | */ |
| 2933 | switch (target) { |
| 2934 | case GL_TEXTURE_3D: |
| 2935 | case GL_TEXTURE_1D_ARRAY: |
| 2936 | case GL_TEXTURE_2D_ARRAY: |
| 2937 | case GL_TEXTURE_CUBE_MAP_ARRAY: |
| 2938 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: |
| 2939 | return true; |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 2940 | case GL_TEXTURE_CUBE_MAP: |
Ian Romanick | 832ea23 | 2015-05-20 17:19:29 -0700 | [diff] [blame] | 2941 | /* We don't need to check the extension (GL_ARB_direct_state_access) or |
| 2942 | * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always |
| 2943 | * enabled in core profile. This can be called from |
| 2944 | * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0), |
| 2945 | * so we do have to check the profile. |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 2946 | */ |
Ian Romanick | 832ea23 | 2015-05-20 17:19:29 -0700 | [diff] [blame] | 2947 | return ctx->API == API_OPENGL_CORE; |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 2948 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2949 | |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 2950 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2951 | "%s(invalid texture target %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 2952 | _mesa_enum_to_string(target)); |
Laura Ekstrand | 80e9bf2 | 2015-03-02 16:52:55 -0800 | [diff] [blame] | 2953 | return false; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | |
| 2957 | /** |
| 2958 | * Common code called by glFramebufferTexture*D() to verify the texture |
| 2959 | * target. |
| 2960 | * |
| 2961 | * \return true if no errors, false if errors |
| 2962 | */ |
| 2963 | static bool |
| 2964 | check_textarget(struct gl_context *ctx, int dims, GLenum target, |
| 2965 | GLenum textarget, const char *caller) |
| 2966 | { |
| 2967 | bool err = false; |
| 2968 | |
| 2969 | switch (dims) { |
| 2970 | case 1: |
| 2971 | switch (textarget) { |
| 2972 | case GL_TEXTURE_1D: |
| 2973 | break; |
| 2974 | case GL_TEXTURE_1D_ARRAY: |
| 2975 | err = !ctx->Extensions.EXT_texture_array; |
| 2976 | break; |
| 2977 | default: |
| 2978 | err = true; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2979 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 2980 | break; |
| 2981 | case 2: |
| 2982 | switch (textarget) { |
| 2983 | case GL_TEXTURE_2D: |
| 2984 | break; |
| 2985 | case GL_TEXTURE_RECTANGLE: |
| 2986 | err = _mesa_is_gles(ctx) |
| 2987 | || !ctx->Extensions.NV_texture_rectangle; |
| 2988 | break; |
| 2989 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 2990 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 2991 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 2992 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 2993 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 2994 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 2995 | err = !ctx->Extensions.ARB_texture_cube_map; |
| 2996 | break; |
| 2997 | case GL_TEXTURE_2D_ARRAY: |
| 2998 | err = (_mesa_is_gles(ctx) && ctx->Version < 30) |
| 2999 | || !ctx->Extensions.EXT_texture_array; |
| 3000 | break; |
| 3001 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 3002 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: |
Marta Lofstedt | 08f2dfe | 2015-08-10 13:48:11 +0300 | [diff] [blame] | 3003 | err = (_mesa_is_gles(ctx) || |
| 3004 | !ctx->Extensions.ARB_texture_multisample) && |
| 3005 | !_mesa_is_gles31(ctx); |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3006 | break; |
| 3007 | default: |
| 3008 | err = true; |
| 3009 | } |
| 3010 | break; |
| 3011 | case 3: |
| 3012 | if (textarget != GL_TEXTURE_3D) |
| 3013 | err = true; |
| 3014 | break; |
| 3015 | default: |
| 3016 | err = true; |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3017 | } |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3018 | |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3019 | if (err) { |
| 3020 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3021 | "%s(invalid textarget %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3022 | caller, _mesa_enum_to_string(textarget)); |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3023 | return false; |
| 3024 | } |
| 3025 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3026 | /* Make sure textarget is consistent with the texture's type */ |
| 3027 | err = (target == GL_TEXTURE_CUBE_MAP) ? |
| 3028 | !_mesa_is_cube_face(textarget): (target != textarget); |
| 3029 | |
| 3030 | if (err) { |
| 3031 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3032 | "%s(mismatched texture target)", caller); |
| 3033 | return false; |
| 3034 | } |
| 3035 | |
| 3036 | return true; |
| 3037 | } |
| 3038 | |
| 3039 | |
| 3040 | /** |
| 3041 | * Common code called by gl*FramebufferTextureLayer() and |
| 3042 | * glFramebufferTexture3D() to validate the layer. |
| 3043 | * |
| 3044 | * \return true if no errors, false if errors |
| 3045 | */ |
| 3046 | static bool |
| 3047 | check_layer(struct gl_context *ctx, GLenum target, GLint layer, |
| 3048 | const char *caller) |
| 3049 | { |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3050 | /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile) |
| 3051 | * spec says: |
| 3052 | * |
| 3053 | * "An INVALID_VALUE error is generated if texture is non-zero |
| 3054 | * and layer is negative." |
| 3055 | */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3056 | if (layer < 0) { |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3057 | _mesa_error(ctx, GL_INVALID_VALUE, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3058 | "%s(layer %u < 0)", caller, layer); |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3059 | return false; |
| 3060 | } |
| 3061 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3062 | if (target == GL_TEXTURE_3D) { |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3063 | const GLuint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3064 | if (layer >= maxSize) { |
Fredrik Höglund | 8ba7ad8 | 2015-05-09 15:31:45 +0200 | [diff] [blame] | 3065 | _mesa_error(ctx, GL_INVALID_VALUE, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3066 | "%s(invalid layer %u)", caller, layer); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3067 | return false; |
Fredrik Höglund | 8ba7ad8 | 2015-05-09 15:31:45 +0200 | [diff] [blame] | 3068 | } |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3069 | } |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3070 | else if ((target == GL_TEXTURE_1D_ARRAY) || |
| 3071 | (target == GL_TEXTURE_2D_ARRAY) || |
| 3072 | (target == GL_TEXTURE_CUBE_MAP_ARRAY) || |
| 3073 | (target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)) { |
| 3074 | if (layer >= ctx->Const.MaxArrayTextureLayers) { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3075 | _mesa_error(ctx, GL_INVALID_VALUE, |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3076 | "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)", |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3077 | caller, layer); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3078 | return false; |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3079 | } |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3080 | } |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3081 | else if (target == GL_TEXTURE_CUBE_MAP) { |
| 3082 | if (layer >= 6) { |
| 3083 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 3084 | "%s(layer %u >= 6)", caller, layer); |
| 3085 | return false; |
| 3086 | } |
| 3087 | } |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3088 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3089 | return true; |
| 3090 | } |
| 3091 | |
| 3092 | |
| 3093 | /** |
| 3094 | * Common code called by all gl*FramebufferTexture*() entry points to verify |
| 3095 | * the level. |
| 3096 | * |
| 3097 | * \return true if no errors, false if errors |
| 3098 | */ |
| 3099 | static bool |
| 3100 | check_level(struct gl_context *ctx, GLenum target, GLint level, |
| 3101 | const char *caller) |
| 3102 | { |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3103 | if ((level < 0) || |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3104 | (level >= _mesa_max_texture_levels(ctx, target))) { |
Laura Ekstrand | a602b21 | 2015-03-02 13:43:09 -0800 | [diff] [blame] | 3105 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 3106 | "%s(invalid level %d)", caller, level); |
| 3107 | return false; |
| 3108 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3109 | |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3110 | return true; |
| 3111 | } |
| 3112 | |
| 3113 | |
| 3114 | void |
| 3115 | _mesa_framebuffer_texture(struct gl_context *ctx, struct gl_framebuffer *fb, |
| 3116 | GLenum attachment, |
| 3117 | struct gl_texture_object *texObj, GLenum textarget, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3118 | GLint level, GLuint layer, GLboolean layered, |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3119 | const char *caller) |
| 3120 | { |
| 3121 | struct gl_renderbuffer_attachment *att; |
| 3122 | |
| 3123 | /* The window-system framebuffer object is immutable */ |
| 3124 | if (_mesa_is_winsys_fbo(fb)) { |
| 3125 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(window-system framebuffer)", |
| 3126 | caller); |
| 3127 | return; |
| 3128 | } |
| 3129 | |
| 3130 | /* Not a hash lookup, so we can afford to get the attachment here. */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 3131 | att = get_attachment(ctx, fb, attachment); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3132 | if (att == NULL) { |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3133 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid attachment %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3134 | _mesa_enum_to_string(attachment)); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3135 | return; |
| 3136 | } |
| 3137 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 3138 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 3139 | |
Brian Paul | d129ea7 | 2014-03-01 10:21:07 -0700 | [diff] [blame] | 3140 | mtx_lock(&fb->Mutex); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3141 | if (texObj) { |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3142 | if (attachment == GL_DEPTH_ATTACHMENT && |
Paul Berry | b9819a0 | 2012-04-13 21:50:08 -0700 | [diff] [blame] | 3143 | texObj == fb->Attachment[BUFFER_STENCIL].Texture && |
| 3144 | level == fb->Attachment[BUFFER_STENCIL].TextureLevel && |
| 3145 | _mesa_tex_target_to_face(textarget) == |
| 3146 | fb->Attachment[BUFFER_STENCIL].CubeMapFace && |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3147 | layer == fb->Attachment[BUFFER_STENCIL].Zoffset) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3148 | /* The texture object is already attached to the stencil attachment |
| 3149 | * point. Don't create a new renderbuffer; just reuse the stencil |
| 3150 | * attachment's. This is required to prevent a GL error in |
| 3151 | * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL). |
| 3152 | */ |
| 3153 | reuse_framebuffer_texture_attachment(fb, BUFFER_DEPTH, |
| 3154 | BUFFER_STENCIL); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3155 | } else if (attachment == GL_STENCIL_ATTACHMENT && |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3156 | texObj == fb->Attachment[BUFFER_DEPTH].Texture && |
Paul Berry | b9819a0 | 2012-04-13 21:50:08 -0700 | [diff] [blame] | 3157 | level == fb->Attachment[BUFFER_DEPTH].TextureLevel && |
| 3158 | _mesa_tex_target_to_face(textarget) == |
| 3159 | fb->Attachment[BUFFER_DEPTH].CubeMapFace && |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3160 | layer == fb->Attachment[BUFFER_DEPTH].Zoffset) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3161 | /* As above, but with depth and stencil transposed. */ |
| 3162 | reuse_framebuffer_texture_attachment(fb, BUFFER_STENCIL, |
| 3163 | BUFFER_DEPTH); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3164 | } else { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3165 | set_texture_attachment(ctx, fb, att, texObj, textarget, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3166 | level, layer, layered); |
Laura Ekstrand | 8f78c68 | 2015-01-27 14:11:13 -0800 | [diff] [blame] | 3167 | |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3168 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 3169 | /* Above we created a new renderbuffer and attached it to the |
| 3170 | * depth attachment point. Now attach it to the stencil attachment |
| 3171 | * point too. |
| 3172 | */ |
| 3173 | assert(att == &fb->Attachment[BUFFER_DEPTH]); |
| 3174 | reuse_framebuffer_texture_attachment(fb,BUFFER_STENCIL, |
| 3175 | BUFFER_DEPTH); |
| 3176 | } |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3177 | } |
| 3178 | |
Brian Paul | 2897cee | 2009-01-29 09:20:18 -0700 | [diff] [blame] | 3179 | /* Set the render-to-texture flag. We'll check this flag in |
| 3180 | * glTexImage() and friends to determine if we need to revalidate |
| 3181 | * any FBOs that might be rendering into this texture. |
| 3182 | * This flag never gets cleared since it's non-trivial to determine |
| 3183 | * when all FBOs might be done rendering to this texture. That's OK |
| 3184 | * though since it's uncommon to render to a texture then repeatedly |
| 3185 | * call glTexImage() to change images in the texture. |
| 3186 | */ |
| 3187 | texObj->_RenderToTexture = GL_TRUE; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3188 | } |
| 3189 | else { |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 3190 | remove_attachment(ctx, att); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3191 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3192 | assert(att == &fb->Attachment[BUFFER_DEPTH]); |
| 3193 | remove_attachment(ctx, &fb->Attachment[BUFFER_STENCIL]); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 3194 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3195 | } |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 3196 | |
| 3197 | invalidate_framebuffer(fb); |
| 3198 | |
Brian Paul | d129ea7 | 2014-03-01 10:21:07 -0700 | [diff] [blame] | 3199 | mtx_unlock(&fb->Mutex); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3203 | static void |
| 3204 | framebuffer_texture_with_dims(int dims, GLenum target, |
| 3205 | GLenum attachment, GLenum textarget, |
| 3206 | GLuint texture, GLint level, GLint layer, |
| 3207 | const char *caller) |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 3208 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3209 | GET_CURRENT_CONTEXT(ctx); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3210 | struct gl_framebuffer *fb; |
| 3211 | struct gl_texture_object *texObj; |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 3212 | |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3213 | /* Get the framebuffer object */ |
| 3214 | fb = get_framebuffer_target(ctx, target); |
| 3215 | if (!fb) { |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3216 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid target %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3217 | _mesa_enum_to_string(target)); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3218 | return; |
| 3219 | } |
| 3220 | |
| 3221 | /* Get the texture object */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3222 | if (!get_texture_for_framebuffer(ctx, texture, false, caller, &texObj)) |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3223 | return; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3224 | |
| 3225 | if (texObj) { |
| 3226 | if (!check_textarget(ctx, dims, texObj->Target, textarget, caller)) |
| 3227 | return; |
| 3228 | |
| 3229 | if ((dims == 3) && !check_layer(ctx, texObj->Target, layer, caller)) |
| 3230 | return; |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3231 | } |
| 3232 | |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3233 | if (!check_level(ctx, textarget, level, caller)) |
| 3234 | return; |
| 3235 | |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3236 | _mesa_framebuffer_texture(ctx, fb, attachment, texObj, textarget, level, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3237 | layer, GL_FALSE, caller); |
| 3238 | } |
| 3239 | |
| 3240 | |
| 3241 | void GLAPIENTRY |
| 3242 | _mesa_FramebufferTexture1D(GLenum target, GLenum attachment, |
| 3243 | GLenum textarget, GLuint texture, GLint level) |
| 3244 | { |
| 3245 | framebuffer_texture_with_dims(1, target, attachment, textarget, texture, |
| 3246 | level, 0, "glFramebufferTexture1D"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 3250 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 3251 | _mesa_FramebufferTexture2D(GLenum target, GLenum attachment, |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3252 | GLenum textarget, GLuint texture, GLint level) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3253 | { |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3254 | framebuffer_texture_with_dims(2, target, attachment, textarget, texture, |
| 3255 | level, 0, "glFramebufferTexture2D"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 3259 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 3260 | _mesa_FramebufferTexture3D(GLenum target, GLenum attachment, |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3261 | GLenum textarget, GLuint texture, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3262 | GLint level, GLint layer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3263 | { |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3264 | framebuffer_texture_with_dims(3, target, attachment, textarget, texture, |
| 3265 | level, layer, "glFramebufferTexture3D"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 3269 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 3270 | _mesa_FramebufferTextureLayer(GLenum target, GLenum attachment, |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3271 | GLuint texture, GLint level, GLint layer) |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 3272 | { |
| 3273 | GET_CURRENT_CONTEXT(ctx); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3274 | struct gl_framebuffer *fb; |
| 3275 | struct gl_texture_object *texObj; |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3276 | GLenum textarget = 0; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3277 | |
| 3278 | const char *func = "glFramebufferTextureLayer"; |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 3279 | |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3280 | /* Get the framebuffer object */ |
| 3281 | fb = get_framebuffer_target(ctx, target); |
| 3282 | if (!fb) { |
| 3283 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3284 | "glFramebufferTextureLayer(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3285 | _mesa_enum_to_string(target)); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3286 | return; |
| 3287 | } |
| 3288 | |
| 3289 | /* Get the texture object */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3290 | if (!get_texture_for_framebuffer(ctx, texture, false, func, &texObj)) |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3291 | return; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3292 | |
| 3293 | if (texObj) { |
| 3294 | if (!check_texture_target(ctx, texObj->Target, func)) |
| 3295 | return; |
| 3296 | |
| 3297 | if (!check_layer(ctx, texObj->Target, layer, func)) |
| 3298 | return; |
| 3299 | |
| 3300 | if (!check_level(ctx, texObj->Target, level, func)) |
| 3301 | return; |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3302 | |
| 3303 | if (texObj->Target == GL_TEXTURE_CUBE_MAP) { |
| 3304 | assert(layer >= 0 && layer < 6); |
| 3305 | textarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; |
| 3306 | layer = 0; |
| 3307 | } |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3308 | } |
| 3309 | |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3310 | _mesa_framebuffer_texture(ctx, fb, attachment, texObj, textarget, level, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3311 | layer, GL_FALSE, func); |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | |
| 3315 | void GLAPIENTRY |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3316 | _mesa_NamedFramebufferTextureLayer(GLuint framebuffer, GLenum attachment, |
| 3317 | GLuint texture, GLint level, GLint layer) |
| 3318 | { |
| 3319 | GET_CURRENT_CONTEXT(ctx); |
| 3320 | struct gl_framebuffer *fb; |
| 3321 | struct gl_texture_object *texObj; |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3322 | GLenum textarget = 0; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3323 | |
| 3324 | const char *func = "glNamedFramebufferTextureLayer"; |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3325 | |
| 3326 | /* Get the framebuffer object */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3327 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, func); |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3328 | if (!fb) |
| 3329 | return; |
| 3330 | |
| 3331 | /* Get the texture object */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3332 | if (!get_texture_for_framebuffer(ctx, texture, false, func, &texObj)) |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3333 | return; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3334 | |
| 3335 | if (texObj) { |
| 3336 | if (!check_texture_target(ctx, texObj->Target, func)) |
| 3337 | return; |
| 3338 | |
| 3339 | if (!check_layer(ctx, texObj->Target, layer, func)) |
| 3340 | return; |
| 3341 | |
| 3342 | if (!check_level(ctx, texObj->Target, level, func)) |
| 3343 | return; |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3344 | |
| 3345 | if (texObj->Target == GL_TEXTURE_CUBE_MAP) { |
| 3346 | assert(layer >= 0 && layer < 6); |
| 3347 | textarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; |
| 3348 | layer = 0; |
| 3349 | } |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3350 | } |
| 3351 | |
Fredrik Höglund | 03420ea | 2015-04-29 19:44:06 +0200 | [diff] [blame] | 3352 | _mesa_framebuffer_texture(ctx, fb, attachment, texObj, textarget, level, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3353 | layer, GL_FALSE, func); |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | |
| 3357 | void GLAPIENTRY |
Jordan Justen | 02f2bce | 2013-04-18 10:46:12 -0700 | [diff] [blame] | 3358 | _mesa_FramebufferTexture(GLenum target, GLenum attachment, |
| 3359 | GLuint texture, GLint level) |
| 3360 | { |
| 3361 | GET_CURRENT_CONTEXT(ctx); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3362 | struct gl_framebuffer *fb; |
| 3363 | struct gl_texture_object *texObj; |
Brian Paul | dbefffa | 2015-07-21 18:42:41 -0600 | [diff] [blame] | 3364 | GLboolean layered = GL_FALSE; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3365 | |
| 3366 | const char *func = "FramebufferTexture"; |
Jordan Justen | 02f2bce | 2013-04-18 10:46:12 -0700 | [diff] [blame] | 3367 | |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3368 | if (!_mesa_has_geometry_shaders(ctx)) { |
Jordan Justen | 02f2bce | 2013-04-18 10:46:12 -0700 | [diff] [blame] | 3369 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3370 | "unsupported function (glFramebufferTexture) called"); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3371 | return; |
Jordan Justen | 02f2bce | 2013-04-18 10:46:12 -0700 | [diff] [blame] | 3372 | } |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3373 | |
| 3374 | /* Get the framebuffer object */ |
| 3375 | fb = get_framebuffer_target(ctx, target); |
| 3376 | if (!fb) { |
| 3377 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3378 | "glFramebufferTexture(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3379 | _mesa_enum_to_string(target)); |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3380 | return; |
| 3381 | } |
| 3382 | |
| 3383 | /* Get the texture object */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3384 | if (!get_texture_for_framebuffer(ctx, texture, true, func, &texObj)) |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3385 | return; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3386 | |
| 3387 | if (texObj) { |
| 3388 | if (!check_layered_texture_target(ctx, texObj->Target, func, &layered)) |
| 3389 | return; |
| 3390 | |
| 3391 | if (!check_level(ctx, texObj->Target, level, func)) |
| 3392 | return; |
Laura Ekstrand | a245e3b | 2015-01-27 16:11:52 -0800 | [diff] [blame] | 3393 | } |
| 3394 | |
| 3395 | _mesa_framebuffer_texture(ctx, fb, attachment, texObj, 0, level, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3396 | 0, layered, func); |
Jordan Justen | 02f2bce | 2013-04-18 10:46:12 -0700 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3400 | void GLAPIENTRY |
| 3401 | _mesa_NamedFramebufferTexture(GLuint framebuffer, GLenum attachment, |
| 3402 | GLuint texture, GLint level) |
| 3403 | { |
| 3404 | GET_CURRENT_CONTEXT(ctx); |
| 3405 | struct gl_framebuffer *fb; |
| 3406 | struct gl_texture_object *texObj; |
Brian Paul | dbefffa | 2015-07-21 18:42:41 -0600 | [diff] [blame] | 3407 | GLboolean layered = GL_FALSE; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3408 | |
| 3409 | const char *func = "glNamedFramebufferTexture"; |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3410 | |
| 3411 | if (!_mesa_has_geometry_shaders(ctx)) { |
| 3412 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3413 | "unsupported function (glNamedFramebufferTexture) called"); |
| 3414 | return; |
| 3415 | } |
| 3416 | |
| 3417 | /* Get the framebuffer object */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3418 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, func); |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3419 | if (!fb) |
| 3420 | return; |
| 3421 | |
| 3422 | /* Get the texture object */ |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3423 | if (!get_texture_for_framebuffer(ctx, texture, true, func, &texObj)) |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3424 | return; |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3425 | |
| 3426 | if (texObj) { |
| 3427 | if (!check_layered_texture_target(ctx, texObj->Target, func, |
| 3428 | &layered)) |
| 3429 | return; |
| 3430 | |
| 3431 | if (!check_level(ctx, texObj->Target, level, func)) |
| 3432 | return; |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | _mesa_framebuffer_texture(ctx, fb, attachment, texObj, 0, level, |
Laura Ekstrand | 085c67d | 2015-03-02 16:48:59 -0800 | [diff] [blame] | 3436 | 0, layered, func); |
Laura Ekstrand | d78c831 | 2015-01-28 13:19:57 -0800 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 3440 | void |
| 3441 | _mesa_framebuffer_renderbuffer(struct gl_context *ctx, |
| 3442 | struct gl_framebuffer *fb, |
| 3443 | GLenum attachment, |
Ian Romanick | 9ae42ab | 2015-11-11 16:30:41 -0800 | [diff] [blame] | 3444 | struct gl_renderbuffer *rb) |
| 3445 | { |
| 3446 | assert(!_mesa_is_winsys_fbo(fb)); |
| 3447 | |
| 3448 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 3449 | |
| 3450 | assert(ctx->Driver.FramebufferRenderbuffer); |
| 3451 | ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb); |
| 3452 | |
| 3453 | /* Some subsequent GL commands may depend on the framebuffer's visual |
| 3454 | * after the binding is updated. Update visual info now. |
| 3455 | */ |
| 3456 | _mesa_update_framebuffer_visual(ctx, fb); |
| 3457 | } |
| 3458 | |
| 3459 | static void |
| 3460 | framebuffer_renderbuffer(struct gl_context *ctx, |
| 3461 | struct gl_framebuffer *fb, |
| 3462 | GLenum attachment, |
| 3463 | struct gl_renderbuffer *rb, |
| 3464 | const char *func) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3465 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 3466 | struct gl_renderbuffer_attachment *att; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3467 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 3468 | if (_mesa_is_winsys_fbo(fb)) { |
Brian Paul | ab8ef28 | 2005-09-07 23:21:59 +0000 | [diff] [blame] | 3469 | /* Can't attach new renderbuffers to a window system framebuffer */ |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 3470 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3471 | "%s(window-system framebuffer)", func); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3472 | return; |
| 3473 | } |
| 3474 | |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 3475 | att = get_attachment(ctx, fb, attachment); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3476 | if (att == NULL) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3477 | _mesa_error(ctx, GL_INVALID_ENUM, |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 3478 | "%s(invalid attachment %s)", func, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3479 | _mesa_enum_to_string(attachment)); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3480 | return; |
| 3481 | } |
| 3482 | |
Brian Paul | a504f23 | 2010-05-27 13:05:23 -0600 | [diff] [blame] | 3483 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT && |
| 3484 | rb && rb->Format != MESA_FORMAT_NONE) { |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 3485 | /* make sure the renderbuffer is a depth/stencil format */ |
Brian Paul | a504f23 | 2010-05-27 13:05:23 -0600 | [diff] [blame] | 3486 | const GLenum baseFormat = _mesa_get_format_base_format(rb->Format); |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 3487 | if (baseFormat != GL_DEPTH_STENCIL) { |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 3488 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 3489 | "%s(renderbuffer is not DEPTH_STENCIL format)", func); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 3490 | return; |
| 3491 | } |
| 3492 | } |
| 3493 | |
Ian Romanick | 9ae42ab | 2015-11-11 16:30:41 -0800 | [diff] [blame] | 3494 | _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3495 | } |
| 3496 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 3497 | void GLAPIENTRY |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 3498 | _mesa_FramebufferRenderbuffer(GLenum target, GLenum attachment, |
| 3499 | GLenum renderbuffertarget, |
| 3500 | GLuint renderbuffer) |
| 3501 | { |
| 3502 | struct gl_framebuffer *fb; |
| 3503 | struct gl_renderbuffer *rb; |
| 3504 | GET_CURRENT_CONTEXT(ctx); |
| 3505 | |
| 3506 | fb = get_framebuffer_target(ctx, target); |
| 3507 | if (!fb) { |
| 3508 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3509 | "glFramebufferRenderbuffer(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3510 | _mesa_enum_to_string(target)); |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 3511 | return; |
| 3512 | } |
| 3513 | |
| 3514 | if (renderbuffertarget != GL_RENDERBUFFER) { |
| 3515 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3516 | "glFramebufferRenderbuffer(renderbuffertarget is not " |
| 3517 | "GL_RENDERBUFFER)"); |
| 3518 | return; |
| 3519 | } |
| 3520 | |
| 3521 | if (renderbuffer) { |
| 3522 | rb = _mesa_lookup_renderbuffer_err(ctx, renderbuffer, |
| 3523 | "glFramebufferRenderbuffer"); |
| 3524 | if (!rb) |
| 3525 | return; |
| 3526 | } |
| 3527 | else { |
| 3528 | /* remove renderbuffer attachment */ |
| 3529 | rb = NULL; |
| 3530 | } |
| 3531 | |
Ian Romanick | 9ae42ab | 2015-11-11 16:30:41 -0800 | [diff] [blame] | 3532 | framebuffer_renderbuffer(ctx, fb, attachment, rb, |
| 3533 | "glFramebufferRenderbuffer"); |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | |
| 3537 | void GLAPIENTRY |
| 3538 | _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer, GLenum attachment, |
| 3539 | GLenum renderbuffertarget, |
| 3540 | GLuint renderbuffer) |
| 3541 | { |
| 3542 | struct gl_framebuffer *fb; |
| 3543 | struct gl_renderbuffer *rb; |
| 3544 | GET_CURRENT_CONTEXT(ctx); |
| 3545 | |
| 3546 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 3547 | "glNamedFramebufferRenderbuffer"); |
Fredrik Höglund | 5a55f68 | 2015-05-16 19:43:39 +0200 | [diff] [blame] | 3548 | if (!fb) |
| 3549 | return; |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 3550 | |
| 3551 | if (renderbuffertarget != GL_RENDERBUFFER) { |
| 3552 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3553 | "glNamedFramebufferRenderbuffer(renderbuffertarget is not " |
| 3554 | "GL_RENDERBUFFER)"); |
| 3555 | return; |
| 3556 | } |
| 3557 | |
| 3558 | if (renderbuffer) { |
| 3559 | rb = _mesa_lookup_renderbuffer_err(ctx, renderbuffer, |
| 3560 | "glNamedFramebufferRenderbuffer"); |
| 3561 | if (!rb) |
| 3562 | return; |
| 3563 | } |
| 3564 | else { |
| 3565 | /* remove renderbuffer attachment */ |
| 3566 | rb = NULL; |
| 3567 | } |
| 3568 | |
Ian Romanick | 9ae42ab | 2015-11-11 16:30:41 -0800 | [diff] [blame] | 3569 | framebuffer_renderbuffer(ctx, fb, attachment, rb, |
| 3570 | "glNamedFramebufferRenderbuffer"); |
Laura Ekstrand | a29318b | 2015-02-27 17:27:30 -0800 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3574 | void |
| 3575 | _mesa_get_framebuffer_attachment_parameter(struct gl_context *ctx, |
| 3576 | struct gl_framebuffer *buffer, |
| 3577 | GLenum attachment, GLenum pname, |
| 3578 | GLint *params, const char *caller) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3579 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 3580 | const struct gl_renderbuffer_attachment *att; |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 3581 | GLenum err; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3582 | |
Kenneth Graunke | 19f13b2 | 2016-03-07 16:43:35 -0800 | [diff] [blame^] | 3583 | /* The error code for an attachment type of GL_NONE differs between APIs. |
| 3584 | * |
| 3585 | * From the ES 2.0.25 specification, page 127: |
| 3586 | * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then |
| 3587 | * querying any other pname will generate INVALID_ENUM." |
| 3588 | * |
| 3589 | * From the OpenGL 3.0 specification, page 337, or identically, |
| 3590 | * the OpenGL ES 3.0.4 specification, page 240: |
| 3591 | * |
| 3592 | * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no |
| 3593 | * framebuffer is bound to target. In this case querying pname |
| 3594 | * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other |
| 3595 | * queries will generate an INVALID_OPERATION error." |
| 3596 | */ |
| 3597 | err = ctx->API == API_OPENGLES2 && ctx->Version < 30 ? |
| 3598 | GL_INVALID_ENUM : GL_INVALID_OPERATION; |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 3599 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 3600 | if (_mesa_is_winsys_fbo(buffer)) { |
Ian Romanick | da2e41c | 2011-10-03 12:04:09 -0700 | [diff] [blame] | 3601 | /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec |
| 3602 | * says: |
| 3603 | * |
| 3604 | * "If the framebuffer currently bound to target is zero, then |
| 3605 | * INVALID_OPERATION is generated." |
| 3606 | * |
| 3607 | * The EXT_framebuffer_object spec has the same wording, and the |
| 3608 | * OES_framebuffer_object spec refers to the EXT_framebuffer_object |
| 3609 | * spec. |
| 3610 | */ |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3611 | if ((!_mesa_is_desktop_gl(ctx) || |
| 3612 | !ctx->Extensions.ARB_framebuffer_object) |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 3613 | && !_mesa_is_gles3(ctx)) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3614 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3615 | "%s(window-system framebuffer)", caller); |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3616 | return; |
Ian Romanick | da2e41c | 2011-10-03 12:04:09 -0700 | [diff] [blame] | 3617 | } |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 3618 | |
| 3619 | if (_mesa_is_gles3(ctx) && attachment != GL_BACK && |
| 3620 | attachment != GL_DEPTH && attachment != GL_STENCIL) { |
Samuel Iglesias Gonsalvez | 284bd1e | 2015-01-16 16:00:13 +0100 | [diff] [blame] | 3621 | _mesa_error(ctx, GL_INVALID_ENUM, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3622 | "%s(invalid attachment %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3623 | _mesa_enum_to_string(attachment)); |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 3624 | return; |
| 3625 | } |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 3626 | /* the default / window-system FBO */ |
| 3627 | att = _mesa_get_fb0_attachment(ctx, buffer, attachment); |
| 3628 | } |
| 3629 | else { |
| 3630 | /* user-created framebuffer FBO */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 3631 | att = get_attachment(ctx, buffer, attachment); |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 3632 | } |
| 3633 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3634 | if (att == NULL) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3635 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid attachment %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3636 | _mesa_enum_to_string(attachment)); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3637 | return; |
| 3638 | } |
| 3639 | |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 3640 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
Brian Paul | e959274 | 2014-04-21 13:24:25 -0600 | [diff] [blame] | 3641 | const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt; |
Anuj Phogat | bd1880d | 2014-03-11 17:04:11 -0700 | [diff] [blame] | 3642 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE) { |
| 3643 | /* This behavior is first specified in OpenGL 4.4 specification. |
| 3644 | * |
| 3645 | * From the OpenGL 4.4 spec page 275: |
| 3646 | * "This query cannot be performed for a combined depth+stencil |
| 3647 | * attachment, since it does not have a single format." |
| 3648 | */ |
| 3649 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3650 | "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE" |
| 3651 | " is invalid for depth+stencil attachment)", caller); |
Anuj Phogat | bd1880d | 2014-03-11 17:04:11 -0700 | [diff] [blame] | 3652 | return; |
| 3653 | } |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 3654 | /* the depth and stencil attachments must point to the same buffer */ |
Brian Paul | 9451281 | 2014-02-01 08:58:43 -0700 | [diff] [blame] | 3655 | depthAtt = get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT); |
| 3656 | stencilAtt = get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 3657 | if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) { |
| 3658 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3659 | "%s(DEPTH/STENCIL attachments differ)", caller); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 3660 | return; |
| 3661 | } |
| 3662 | } |
| 3663 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 3664 | /* No need to flush here */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 3665 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3666 | switch (pname) { |
| 3667 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT: |
Iago Toral Quiroga | cf43995 | 2015-02-24 19:02:56 +0100 | [diff] [blame] | 3668 | /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects: |
| 3669 | * |
| 3670 | * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then |
| 3671 | * either no framebuffer is bound to target; or the default framebuffer |
| 3672 | * is bound, attachment is DEPTH or STENCIL, and the number of depth or |
| 3673 | * stencil bits, respectively, is zero." |
| 3674 | */ |
| 3675 | *params = (_mesa_is_winsys_fbo(buffer) && |
| 3676 | ((attachment != GL_DEPTH && attachment != GL_STENCIL) || |
| 3677 | (att->Type != GL_NONE))) |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 3678 | ? GL_FRAMEBUFFER_DEFAULT : att->Type; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3679 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3680 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3681 | if (att->Type == GL_RENDERBUFFER_EXT) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3682 | *params = att->Renderbuffer->Name; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3683 | } |
| 3684 | else if (att->Type == GL_TEXTURE) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3685 | *params = att->Texture->Name; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3686 | } |
| 3687 | else { |
Brian Paul | 20cf185 | 2010-12-03 08:23:31 -0700 | [diff] [blame] | 3688 | assert(att->Type == GL_NONE); |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3689 | if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) { |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 3690 | *params = 0; |
| 3691 | } else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3692 | goto invalid_pname_enum; |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 3693 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3694 | } |
| 3695 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3696 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3697 | if (att->Type == GL_TEXTURE) { |
Martin Peres | 7bd8b48 | 2015-02-12 17:54:43 +0200 | [diff] [blame] | 3698 | *params = att->TextureLevel; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3699 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 3700 | else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3701 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3702 | _mesa_enum_to_string(pname)); |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 3703 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3704 | else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3705 | goto invalid_pname_enum; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3706 | } |
| 3707 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3708 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3709 | if (att->Type == GL_TEXTURE) { |
Brian Paul | f1e4ca7 | 2008-08-06 08:39:54 -0600 | [diff] [blame] | 3710 | if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) { |
| 3711 | *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace; |
| 3712 | } |
| 3713 | else { |
| 3714 | *params = 0; |
| 3715 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3716 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 3717 | else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3718 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3719 | _mesa_enum_to_string(pname)); |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 3720 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3721 | else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3722 | goto invalid_pname_enum; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3723 | } |
| 3724 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3725 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT: |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3726 | if (ctx->API == API_OPENGLES) { |
| 3727 | goto invalid_pname_enum; |
| 3728 | } else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3729 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3730 | _mesa_enum_to_string(pname)); |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3731 | } else if (att->Type == GL_TEXTURE) { |
Samuel Iglesias Gonsalvez | 8e49a3e | 2014-12-11 23:34:13 +0100 | [diff] [blame] | 3732 | if (att->Texture && (att->Texture->Target == GL_TEXTURE_3D || |
| 3733 | att->Texture->Target == GL_TEXTURE_2D_ARRAY)) { |
Brian Paul | f1e4ca7 | 2008-08-06 08:39:54 -0600 | [diff] [blame] | 3734 | *params = att->Zoffset; |
| 3735 | } |
| 3736 | else { |
| 3737 | *params = 0; |
| 3738 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3739 | } |
| 3740 | else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3741 | goto invalid_pname_enum; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 3742 | } |
| 3743 | return; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3744 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3745 | if ((!_mesa_is_desktop_gl(ctx) || |
| 3746 | !ctx->Extensions.ARB_framebuffer_object) |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3747 | && !_mesa_is_gles3(ctx)) { |
| 3748 | goto invalid_pname_enum; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3749 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 3750 | else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3751 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3752 | _mesa_enum_to_string(pname)); |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 3753 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3754 | else { |
Marek Olšák | 69c8f46 | 2012-01-24 23:39:31 +0100 | [diff] [blame] | 3755 | if (ctx->Extensions.EXT_framebuffer_sRGB) { |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3756 | *params = |
| 3757 | _mesa_get_format_color_encoding(att->Renderbuffer->Format); |
Marek Olšák | 81ae8c6 | 2011-01-23 13:26:43 +0100 | [diff] [blame] | 3758 | } |
| 3759 | else { |
| 3760 | /* According to ARB_framebuffer_sRGB, we should return LINEAR |
| 3761 | * if the sRGB conversion is unsupported. */ |
| 3762 | *params = GL_LINEAR; |
| 3763 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3764 | } |
| 3765 | return; |
| 3766 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3767 | if ((ctx->API != API_OPENGL_COMPAT || |
| 3768 | !ctx->Extensions.ARB_framebuffer_object) |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3769 | && ctx->API != API_OPENGL_CORE |
| 3770 | && !_mesa_is_gles3(ctx)) { |
| 3771 | goto invalid_pname_enum; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3772 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 3773 | else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3774 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3775 | _mesa_enum_to_string(pname)); |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 3776 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3777 | else { |
Mark Mueller | 71fe943 | 2014-01-04 14:11:43 -0800 | [diff] [blame] | 3778 | mesa_format format = att->Renderbuffer->Format; |
Ian Romanick | d7475c7 | 2013-01-18 17:25:57 -0800 | [diff] [blame] | 3779 | |
| 3780 | /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES |
| 3781 | * 3.0.1 spec says: |
| 3782 | * |
| 3783 | * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If |
| 3784 | * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and |
| 3785 | * generate an INVALID_OPERATION error. |
| 3786 | */ |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3787 | if (_mesa_is_gles3(ctx) && |
| 3788 | attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
Ian Romanick | d7475c7 | 2013-01-18 17:25:57 -0800 | [diff] [blame] | 3789 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3790 | "%s(cannot query " |
Ian Romanick | d7475c7 | 2013-01-18 17:25:57 -0800 | [diff] [blame] | 3791 | "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of " |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3792 | "GL_DEPTH_STENCIL_ATTACHMENT)", caller); |
Ian Romanick | d7475c7 | 2013-01-18 17:25:57 -0800 | [diff] [blame] | 3793 | return; |
| 3794 | } |
| 3795 | |
Mark Mueller | 50a01d2 | 2014-01-20 19:08:54 -0800 | [diff] [blame] | 3796 | if (format == MESA_FORMAT_S_UINT8) { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 3797 | /* special cases */ |
| 3798 | *params = GL_INDEX; |
| 3799 | } |
Mark Mueller | eeed49f | 2014-01-26 15:12:56 -0800 | [diff] [blame] | 3800 | else if (format == MESA_FORMAT_Z32_FLOAT_S8X24_UINT) { |
Marek Olšák | 1165280 | 2011-06-01 15:48:51 +0200 | [diff] [blame] | 3801 | /* depends on the attachment parameter */ |
| 3802 | if (attachment == GL_STENCIL_ATTACHMENT) { |
| 3803 | *params = GL_INDEX; |
| 3804 | } |
| 3805 | else { |
| 3806 | *params = GL_FLOAT; |
| 3807 | } |
| 3808 | } |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 3809 | else { |
| 3810 | *params = _mesa_get_format_datatype(format); |
| 3811 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3812 | } |
| 3813 | return; |
| 3814 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3815 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3816 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3817 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3818 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3819 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 3820 | if ((!_mesa_is_desktop_gl(ctx) || |
| 3821 | !ctx->Extensions.ARB_framebuffer_object) |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3822 | && !_mesa_is_gles3(ctx)) { |
| 3823 | goto invalid_pname_enum; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3824 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 3825 | else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3826 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3827 | _mesa_enum_to_string(pname)); |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 3828 | } |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 3829 | else if (att->Texture) { |
| 3830 | const struct gl_texture_image *texImage = |
Brian Paul | f262ed6 | 2015-01-02 16:56:12 -0700 | [diff] [blame] | 3831 | _mesa_select_tex_image(att->Texture, att->Texture->Target, |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 3832 | att->TextureLevel); |
| 3833 | if (texImage) { |
| 3834 | *params = get_component_bits(pname, texImage->_BaseFormat, |
| 3835 | texImage->TexFormat); |
| 3836 | } |
| 3837 | else { |
| 3838 | *params = 0; |
| 3839 | } |
| 3840 | } |
| 3841 | else if (att->Renderbuffer) { |
| 3842 | *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat, |
| 3843 | att->Renderbuffer->Format); |
| 3844 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3845 | else { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3846 | _mesa_problem(ctx, "%s: invalid FBO attachment structure", caller); |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 3847 | } |
| 3848 | return; |
Paul Berry | ec79c05 | 2013-11-19 21:17:19 -0800 | [diff] [blame] | 3849 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED: |
| 3850 | if (!_mesa_has_geometry_shaders(ctx)) { |
| 3851 | goto invalid_pname_enum; |
| 3852 | } else if (att->Type == GL_TEXTURE) { |
| 3853 | *params = att->Layered; |
| 3854 | } else if (att->Type == GL_NONE) { |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3855 | _mesa_error(ctx, err, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3856 | _mesa_enum_to_string(pname)); |
Paul Berry | ec79c05 | 2013-11-19 21:17:19 -0800 | [diff] [blame] | 3857 | } else { |
| 3858 | goto invalid_pname_enum; |
| 3859 | } |
| 3860 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3861 | default: |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3862 | goto invalid_pname_enum; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3863 | } |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3864 | |
| 3865 | return; |
| 3866 | |
| 3867 | invalid_pname_enum: |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3868 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid pname %s)", caller, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3869 | _mesa_enum_to_string(pname)); |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 3870 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3874 | void GLAPIENTRY |
| 3875 | _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, |
| 3876 | GLenum pname, GLint *params) |
| 3877 | { |
| 3878 | GET_CURRENT_CONTEXT(ctx); |
| 3879 | struct gl_framebuffer *buffer; |
| 3880 | |
| 3881 | buffer = get_framebuffer_target(ctx, target); |
| 3882 | if (!buffer) { |
| 3883 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 3884 | "glGetFramebufferAttachmentParameteriv(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 3885 | _mesa_enum_to_string(target)); |
Laura Ekstrand | f22fa30 | 2015-01-29 17:11:37 -0800 | [diff] [blame] | 3886 | return; |
| 3887 | } |
| 3888 | |
| 3889 | _mesa_get_framebuffer_attachment_parameter(ctx, buffer, attachment, pname, |
| 3890 | params, |
| 3891 | "glGetFramebufferAttachmentParameteriv"); |
| 3892 | } |
| 3893 | |
| 3894 | |
| 3895 | void GLAPIENTRY |
| 3896 | _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer, |
| 3897 | GLenum attachment, |
| 3898 | GLenum pname, GLint *params) |
| 3899 | { |
| 3900 | GET_CURRENT_CONTEXT(ctx); |
| 3901 | struct gl_framebuffer *buffer; |
| 3902 | |
| 3903 | if (framebuffer) { |
| 3904 | buffer = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 3905 | "glGetNamedFramebufferAttachmentParameteriv"); |
| 3906 | if (!buffer) |
| 3907 | return; |
| 3908 | } |
| 3909 | else { |
| 3910 | /* |
| 3911 | * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL |
| 3912 | * 4.5 core spec (30.10.2014, PDF page 314): |
| 3913 | * "If framebuffer is zero, then the default draw framebuffer is |
| 3914 | * queried." |
| 3915 | */ |
| 3916 | buffer = ctx->WinSysDrawBuffer; |
| 3917 | } |
| 3918 | |
| 3919 | _mesa_get_framebuffer_attachment_parameter(ctx, buffer, attachment, pname, |
| 3920 | params, |
| 3921 | "glGetNamedFramebufferAttachmentParameteriv"); |
| 3922 | } |
| 3923 | |
| 3924 | |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 3925 | void GLAPIENTRY |
| 3926 | _mesa_NamedFramebufferParameteri(GLuint framebuffer, GLenum pname, |
| 3927 | GLint param) |
| 3928 | { |
| 3929 | GET_CURRENT_CONTEXT(ctx); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 3930 | struct gl_framebuffer *fb = NULL; |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 3931 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 3932 | if (!ctx->Extensions.ARB_framebuffer_no_attachments) { |
| 3933 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3934 | "glNamedFramebufferParameteri(" |
| 3935 | "ARB_framebuffer_no_attachments not implemented)"); |
| 3936 | return; |
| 3937 | } |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 3938 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 3939 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 3940 | "glNamedFramebufferParameteri"); |
| 3941 | |
| 3942 | if (fb) { |
| 3943 | framebuffer_parameteri(ctx, fb, pname, param, |
| 3944 | "glNamedFramebufferParameteriv"); |
| 3945 | } |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | |
| 3949 | void GLAPIENTRY |
| 3950 | _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer, GLenum pname, |
| 3951 | GLint *param) |
| 3952 | { |
| 3953 | GET_CURRENT_CONTEXT(ctx); |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 3954 | struct gl_framebuffer *fb; |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 3955 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 3956 | if (!ctx->Extensions.ARB_framebuffer_no_attachments) { |
| 3957 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3958 | "glNamedFramebufferParameteriv(" |
| 3959 | "ARB_framebuffer_no_attachments not implemented)"); |
| 3960 | return; |
| 3961 | } |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 3962 | |
Kevin Rogovin | 6aa1299 | 2015-06-17 13:29:52 +0300 | [diff] [blame] | 3963 | if (framebuffer) { |
| 3964 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 3965 | "glGetNamedFramebufferParameteriv"); |
| 3966 | } else { |
| 3967 | fb = ctx->WinSysDrawBuffer; |
| 3968 | } |
| 3969 | |
| 3970 | if (fb) { |
| 3971 | get_framebuffer_parameteriv(ctx, fb, pname, param, |
| 3972 | "glGetNamedFramebufferParameteriv"); |
| 3973 | } |
Laura Ekstrand | 9f1db78 | 2015-02-05 16:38:11 -0800 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 3977 | static void |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 3978 | invalidate_framebuffer_storage(struct gl_context *ctx, |
| 3979 | struct gl_framebuffer *fb, |
| 3980 | GLsizei numAttachments, |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 3981 | const GLenum *attachments, GLint x, GLint y, |
| 3982 | GLsizei width, GLsizei height, const char *name) |
| 3983 | { |
| 3984 | int i; |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 3985 | |
Laura Ekstrand | b4368ac | 2015-02-04 14:21:17 -0800 | [diff] [blame] | 3986 | /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core |
| 3987 | * Spec (2.2.2015, PDF page 522) says: |
| 3988 | * "An INVALID_VALUE error is generated if numAttachments, width, or |
| 3989 | * height is negative." |
| 3990 | */ |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 3991 | if (numAttachments < 0) { |
| 3992 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 3993 | "%s(numAttachments < 0)", name); |
| 3994 | return; |
| 3995 | } |
| 3996 | |
Laura Ekstrand | b4368ac | 2015-02-04 14:21:17 -0800 | [diff] [blame] | 3997 | if (width < 0) { |
| 3998 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 3999 | "%s(width < 0)", name); |
| 4000 | return; |
| 4001 | } |
| 4002 | |
| 4003 | if (height < 0) { |
| 4004 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 4005 | "%s(height < 0)", name); |
| 4006 | return; |
| 4007 | } |
| 4008 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4009 | /* The GL_ARB_invalidate_subdata spec says: |
| 4010 | * |
| 4011 | * "If an attachment is specified that does not exist in the |
| 4012 | * framebuffer bound to <target>, it is ignored." |
| 4013 | * |
| 4014 | * It also says: |
| 4015 | * |
| 4016 | * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than |
| 4017 | * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error |
| 4018 | * INVALID_OPERATION is generated." |
| 4019 | * |
| 4020 | * No mention is made of GL_AUXi being out of range. Therefore, we allow |
| 4021 | * any enum that can be allowed by the API (OpenGL ES 3.0 has a different |
| 4022 | * set of retrictions). |
| 4023 | */ |
| 4024 | for (i = 0; i < numAttachments; i++) { |
| 4025 | if (_mesa_is_winsys_fbo(fb)) { |
| 4026 | switch (attachments[i]) { |
| 4027 | case GL_ACCUM: |
| 4028 | case GL_AUX0: |
| 4029 | case GL_AUX1: |
| 4030 | case GL_AUX2: |
| 4031 | case GL_AUX3: |
| 4032 | /* Accumulation buffers and auxilary buffers were removed in |
| 4033 | * OpenGL 3.1, and they never existed in OpenGL ES. |
| 4034 | */ |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 4035 | if (ctx->API != API_OPENGL_COMPAT) |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4036 | goto invalid_enum; |
| 4037 | break; |
| 4038 | case GL_COLOR: |
| 4039 | case GL_DEPTH: |
| 4040 | case GL_STENCIL: |
| 4041 | break; |
| 4042 | case GL_BACK_LEFT: |
| 4043 | case GL_BACK_RIGHT: |
| 4044 | case GL_FRONT_LEFT: |
| 4045 | case GL_FRONT_RIGHT: |
| 4046 | if (!_mesa_is_desktop_gl(ctx)) |
| 4047 | goto invalid_enum; |
| 4048 | break; |
| 4049 | default: |
| 4050 | goto invalid_enum; |
| 4051 | } |
| 4052 | } else { |
| 4053 | switch (attachments[i]) { |
| 4054 | case GL_DEPTH_ATTACHMENT: |
| 4055 | case GL_STENCIL_ATTACHMENT: |
| 4056 | break; |
Eduardo Lima Mitev | 242ad32 | 2014-11-18 16:28:18 +0100 | [diff] [blame] | 4057 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4058 | /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only |
| 4059 | * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil |
| 4060 | * extension does not make this attachment point valid on ES 2.0. |
| 4061 | */ |
| 4062 | if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) |
| 4063 | break; |
| 4064 | /* fallthrough */ |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4065 | case GL_COLOR_ATTACHMENT0: |
| 4066 | case GL_COLOR_ATTACHMENT1: |
| 4067 | case GL_COLOR_ATTACHMENT2: |
| 4068 | case GL_COLOR_ATTACHMENT3: |
| 4069 | case GL_COLOR_ATTACHMENT4: |
| 4070 | case GL_COLOR_ATTACHMENT5: |
| 4071 | case GL_COLOR_ATTACHMENT6: |
| 4072 | case GL_COLOR_ATTACHMENT7: |
| 4073 | case GL_COLOR_ATTACHMENT8: |
| 4074 | case GL_COLOR_ATTACHMENT9: |
| 4075 | case GL_COLOR_ATTACHMENT10: |
| 4076 | case GL_COLOR_ATTACHMENT11: |
| 4077 | case GL_COLOR_ATTACHMENT12: |
| 4078 | case GL_COLOR_ATTACHMENT13: |
| 4079 | case GL_COLOR_ATTACHMENT14: |
| 4080 | case GL_COLOR_ATTACHMENT15: { |
Brian Paul | 859c387 | 2012-11-04 16:43:44 -0700 | [diff] [blame] | 4081 | unsigned k = attachments[i] - GL_COLOR_ATTACHMENT0; |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4082 | if (k >= ctx->Const.MaxColorAttachments) { |
| 4083 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 4084 | "%s(attachment >= max. color attachments)", name); |
| 4085 | return; |
| 4086 | } |
Constantin Baranov | 53904c6 | 2013-10-13 01:17:15 +0300 | [diff] [blame] | 4087 | break; |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4088 | } |
| 4089 | default: |
| 4090 | goto invalid_enum; |
| 4091 | } |
| 4092 | } |
| 4093 | } |
| 4094 | |
| 4095 | /* We don't actually do anything for this yet. Just return after |
| 4096 | * validating the parameters and generating the required errors. |
| 4097 | */ |
| 4098 | return; |
| 4099 | |
| 4100 | invalid_enum: |
Laura Ekstrand | b4368ac | 2015-02-04 14:21:17 -0800 | [diff] [blame] | 4101 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid attachment %s)", name, |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4102 | _mesa_enum_to_string(attachments[i])); |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4103 | return; |
| 4104 | } |
| 4105 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 4106 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4107 | void GLAPIENTRY |
| 4108 | _mesa_InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, |
| 4109 | const GLenum *attachments, GLint x, GLint y, |
| 4110 | GLsizei width, GLsizei height) |
| 4111 | { |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 4112 | struct gl_framebuffer *fb; |
| 4113 | GET_CURRENT_CONTEXT(ctx); |
| 4114 | |
| 4115 | fb = get_framebuffer_target(ctx, target); |
| 4116 | if (!fb) { |
| 4117 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 4118 | "glInvalidateSubFramebuffer(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4119 | _mesa_enum_to_string(target)); |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 4120 | return; |
| 4121 | } |
| 4122 | |
| 4123 | invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments, |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4124 | x, y, width, height, |
| 4125 | "glInvalidateSubFramebuffer"); |
| 4126 | } |
| 4127 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 4128 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4129 | void GLAPIENTRY |
Laura Ekstrand | d890fc7 | 2015-02-04 14:21:48 -0800 | [diff] [blame] | 4130 | _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer, |
| 4131 | GLsizei numAttachments, |
| 4132 | const GLenum *attachments, |
| 4133 | GLint x, GLint y, |
| 4134 | GLsizei width, GLsizei height) |
| 4135 | { |
| 4136 | struct gl_framebuffer *fb; |
| 4137 | GET_CURRENT_CONTEXT(ctx); |
| 4138 | |
| 4139 | /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole |
| 4140 | * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the |
| 4141 | * default draw framebuffer is affected." |
| 4142 | */ |
| 4143 | if (framebuffer) { |
| 4144 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 4145 | "glInvalidateNamedFramebufferSubData"); |
| 4146 | if (!fb) |
| 4147 | return; |
| 4148 | } |
| 4149 | else |
| 4150 | fb = ctx->WinSysDrawBuffer; |
| 4151 | |
| 4152 | invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments, |
| 4153 | x, y, width, height, |
| 4154 | "glInvalidateNamedFramebufferSubData"); |
| 4155 | } |
| 4156 | |
| 4157 | |
| 4158 | void GLAPIENTRY |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4159 | _mesa_InvalidateFramebuffer(GLenum target, GLsizei numAttachments, |
| 4160 | const GLenum *attachments) |
| 4161 | { |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 4162 | struct gl_framebuffer *fb; |
| 4163 | GET_CURRENT_CONTEXT(ctx); |
| 4164 | |
| 4165 | fb = get_framebuffer_target(ctx, target); |
| 4166 | if (!fb) { |
| 4167 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 4168 | "glInvalidateFramebuffer(invalid target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4169 | _mesa_enum_to_string(target)); |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 4170 | return; |
| 4171 | } |
| 4172 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4173 | /* The GL_ARB_invalidate_subdata spec says: |
| 4174 | * |
| 4175 | * "The command |
| 4176 | * |
| 4177 | * void InvalidateFramebuffer(enum target, |
| 4178 | * sizei numAttachments, |
| 4179 | * const enum *attachments); |
| 4180 | * |
| 4181 | * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>, |
| 4182 | * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>, |
| 4183 | * <MAX_VIEWPORT_DIMS[1]> respectively." |
| 4184 | */ |
Laura Ekstrand | 65d4a20 | 2015-02-04 09:49:58 -0800 | [diff] [blame] | 4185 | invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments, |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 4186 | 0, 0, |
Samuel Iglesias Gonsálvez | aa849d9 | 2016-03-01 12:02:27 +0100 | [diff] [blame] | 4187 | ctx->Const.MaxViewportWidth, |
| 4188 | ctx->Const.MaxViewportHeight, |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 4189 | "glInvalidateFramebuffer"); |
| 4190 | } |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 4191 | |
Brian Paul | c1377ed | 2014-03-22 10:31:58 -0600 | [diff] [blame] | 4192 | |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 4193 | void GLAPIENTRY |
Laura Ekstrand | d890fc7 | 2015-02-04 14:21:48 -0800 | [diff] [blame] | 4194 | _mesa_InvalidateNamedFramebufferData(GLuint framebuffer, |
| 4195 | GLsizei numAttachments, |
| 4196 | const GLenum *attachments) |
| 4197 | { |
| 4198 | struct gl_framebuffer *fb; |
| 4199 | GET_CURRENT_CONTEXT(ctx); |
| 4200 | |
| 4201 | /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole |
| 4202 | * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the |
| 4203 | * default draw framebuffer is affected." |
| 4204 | */ |
| 4205 | if (framebuffer) { |
| 4206 | fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, |
| 4207 | "glInvalidateNamedFramebufferData"); |
| 4208 | if (!fb) |
| 4209 | return; |
| 4210 | } |
| 4211 | else |
| 4212 | fb = ctx->WinSysDrawBuffer; |
| 4213 | |
| 4214 | /* The GL_ARB_invalidate_subdata spec says: |
| 4215 | * |
| 4216 | * "The command |
| 4217 | * |
| 4218 | * void InvalidateFramebuffer(enum target, |
| 4219 | * sizei numAttachments, |
| 4220 | * const enum *attachments); |
| 4221 | * |
| 4222 | * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>, |
| 4223 | * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>, |
| 4224 | * <MAX_VIEWPORT_DIMS[1]> respectively." |
| 4225 | */ |
| 4226 | invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments, |
| 4227 | 0, 0, |
Samuel Iglesias Gonsálvez | aa849d9 | 2016-03-01 12:02:27 +0100 | [diff] [blame] | 4228 | ctx->Const.MaxViewportWidth, |
| 4229 | ctx->Const.MaxViewportHeight, |
Laura Ekstrand | d890fc7 | 2015-02-04 14:21:48 -0800 | [diff] [blame] | 4230 | "glInvalidateNamedFramebufferData"); |
| 4231 | } |
| 4232 | |
| 4233 | |
| 4234 | void GLAPIENTRY |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 4235 | _mesa_DiscardFramebufferEXT(GLenum target, GLsizei numAttachments, |
| 4236 | const GLenum *attachments) |
| 4237 | { |
| 4238 | struct gl_framebuffer *fb; |
| 4239 | GLint i; |
| 4240 | |
| 4241 | GET_CURRENT_CONTEXT(ctx); |
| 4242 | |
| 4243 | fb = get_framebuffer_target(ctx, target); |
| 4244 | if (!fb) { |
| 4245 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 4246 | "glDiscardFramebufferEXT(target %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4247 | _mesa_enum_to_string(target)); |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 4248 | return; |
| 4249 | } |
| 4250 | |
| 4251 | if (numAttachments < 0) { |
| 4252 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 4253 | "glDiscardFramebufferEXT(numAttachments < 0)"); |
| 4254 | return; |
| 4255 | } |
| 4256 | |
| 4257 | for (i = 0; i < numAttachments; i++) { |
| 4258 | switch (attachments[i]) { |
| 4259 | case GL_COLOR: |
| 4260 | case GL_DEPTH: |
| 4261 | case GL_STENCIL: |
| 4262 | if (_mesa_is_user_fbo(fb)) |
| 4263 | goto invalid_enum; |
| 4264 | break; |
| 4265 | case GL_COLOR_ATTACHMENT0: |
| 4266 | case GL_DEPTH_ATTACHMENT: |
| 4267 | case GL_STENCIL_ATTACHMENT: |
| 4268 | if (_mesa_is_winsys_fbo(fb)) |
| 4269 | goto invalid_enum; |
| 4270 | break; |
| 4271 | default: |
| 4272 | goto invalid_enum; |
| 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | if (ctx->Driver.DiscardFramebuffer) |
| 4277 | ctx->Driver.DiscardFramebuffer(ctx, target, numAttachments, attachments); |
| 4278 | |
| 4279 | return; |
| 4280 | |
| 4281 | invalid_enum: |
| 4282 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 4283 | "glDiscardFramebufferEXT(attachment %s)", |
Kenneth Graunke | 2f11e92 | 2015-07-18 01:22:00 -0700 | [diff] [blame] | 4284 | _mesa_enum_to_string(attachments[i])); |
Tapani Pälli | 413941e | 2013-02-18 09:12:27 +0200 | [diff] [blame] | 4285 | } |