Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 3 | * Version: 7.1 |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 4 | * |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 5 | * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 6 | * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 9 | * copy of this software and associated documentation files (the "Software"), |
| 10 | * to deal in the Software without restriction, including without limitation |
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 12 | * and/or sell copies of the Software, and to permit persons to whom the |
| 13 | * Software is furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included |
| 16 | * in all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 22 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 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" |
Vinson Lee | db61b9c | 2011-01-07 00:08:24 -0800 | [diff] [blame] | 45 | #include "mfeatures.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 | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 53 | /** Set this to 1 to debug/log glBlitFramebuffer() calls */ |
| 54 | #define DEBUG_BLIT 0 |
| 55 | |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 56 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 57 | /** |
| 58 | * Notes: |
| 59 | * |
| 60 | * None of the GL_EXT_framebuffer_object functions are compiled into |
| 61 | * display lists. |
| 62 | */ |
| 63 | |
| 64 | |
| 65 | |
Brian Paul | 923b6fc | 2005-02-08 04:08:56 +0000 | [diff] [blame] | 66 | /* |
| 67 | * When glGenRender/FramebuffersEXT() is called we insert pointers to |
| 68 | * these placeholder objects into the hash table. |
| 69 | * Later, when the object ID is first bound, we replace the placeholder |
| 70 | * with the real frame/renderbuffer. |
| 71 | */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 72 | static struct gl_framebuffer DummyFramebuffer; |
| 73 | static struct gl_renderbuffer DummyRenderbuffer; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 74 | |
Kristian Høgsberg | 144356f | 2010-09-09 17:08:12 -0400 | [diff] [blame] | 75 | /* We bind this framebuffer when applications pass a NULL |
| 76 | * drawable/surface in make current. */ |
| 77 | static struct gl_framebuffer IncompleteFramebuffer; |
| 78 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 79 | |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 80 | static void |
Brian Paul | c732458 | 2012-11-30 10:04:48 -0700 | [diff] [blame] | 81 | delete_dummy_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb) |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 82 | { |
| 83 | /* no op */ |
| 84 | } |
| 85 | |
| 86 | static void |
| 87 | delete_dummy_framebuffer(struct gl_framebuffer *fb) |
| 88 | { |
| 89 | /* no op */ |
| 90 | } |
| 91 | |
| 92 | |
| 93 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 94 | _mesa_init_fbobjects(struct gl_context *ctx) |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 95 | { |
Vladimir Vukicevic | 0731701 | 2010-09-01 08:54:21 -0600 | [diff] [blame] | 96 | _glthread_INIT_MUTEX(DummyFramebuffer.Mutex); |
| 97 | _glthread_INIT_MUTEX(DummyRenderbuffer.Mutex); |
Kristian Høgsberg | 144356f | 2010-09-09 17:08:12 -0400 | [diff] [blame] | 98 | _glthread_INIT_MUTEX(IncompleteFramebuffer.Mutex); |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 99 | DummyFramebuffer.Delete = delete_dummy_framebuffer; |
| 100 | DummyRenderbuffer.Delete = delete_dummy_renderbuffer; |
Kristian Høgsberg | 144356f | 2010-09-09 17:08:12 -0400 | [diff] [blame] | 101 | IncompleteFramebuffer.Delete = delete_dummy_framebuffer; |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 102 | } |
| 103 | |
Kristian Høgsberg | 9456e22 | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 104 | struct gl_framebuffer * |
| 105 | _mesa_get_incomplete_framebuffer(void) |
| 106 | { |
Kristian Høgsberg | 144356f | 2010-09-09 17:08:12 -0400 | [diff] [blame] | 107 | return &IncompleteFramebuffer; |
Kristian Høgsberg | 9456e22 | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 108 | } |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 109 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 110 | /** |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 111 | * Helper routine for getting a gl_renderbuffer. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 112 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 113 | struct gl_renderbuffer * |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 114 | _mesa_lookup_renderbuffer(struct gl_context *ctx, GLuint id) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 115 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 116 | struct gl_renderbuffer *rb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 117 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 118 | if (id == 0) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 119 | return NULL; |
| 120 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 121 | rb = (struct gl_renderbuffer *) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 122 | _mesa_HashLookup(ctx->Shared->RenderBuffers, id); |
| 123 | return rb; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | /** |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 128 | * Helper routine for getting a gl_framebuffer. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 129 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 130 | struct gl_framebuffer * |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 131 | _mesa_lookup_framebuffer(struct gl_context *ctx, GLuint id) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 132 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 133 | struct gl_framebuffer *fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 134 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 135 | if (id == 0) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 136 | return NULL; |
| 137 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 138 | fb = (struct gl_framebuffer *) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 139 | _mesa_HashLookup(ctx->Shared->FrameBuffers, id); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 140 | return fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
| 144 | /** |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 145 | * Mark the given framebuffer as invalid. This will force the |
| 146 | * test for framebuffer completeness to be done before the framebuffer |
| 147 | * is used. |
| 148 | */ |
| 149 | static void |
| 150 | invalidate_framebuffer(struct gl_framebuffer *fb) |
| 151 | { |
| 152 | fb->_Status = 0; /* "indeterminate" */ |
| 153 | } |
| 154 | |
| 155 | |
| 156 | /** |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 157 | * Return the gl_framebuffer object which corresponds to the given |
| 158 | * framebuffer target, such as GL_DRAW_FRAMEBUFFER. |
| 159 | * Check support for GL_EXT_framebuffer_blit to determine if certain |
| 160 | * targets are legal. |
| 161 | * \return gl_framebuffer pointer or NULL if target is illegal |
| 162 | */ |
| 163 | static struct gl_framebuffer * |
| 164 | get_framebuffer_target(struct gl_context *ctx, GLenum target) |
| 165 | { |
Kenneth Graunke | c6ed42a | 2012-11-17 23:23:06 -0800 | [diff] [blame] | 166 | bool have_fb_blit = _mesa_is_gles3(ctx) || |
| 167 | (ctx->Extensions.EXT_framebuffer_blit && _mesa_is_desktop_gl(ctx)); |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 168 | switch (target) { |
| 169 | case GL_DRAW_FRAMEBUFFER: |
Kenneth Graunke | c6ed42a | 2012-11-17 23:23:06 -0800 | [diff] [blame] | 170 | return have_fb_blit ? ctx->DrawBuffer : NULL; |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 171 | case GL_READ_FRAMEBUFFER: |
Kenneth Graunke | c6ed42a | 2012-11-17 23:23:06 -0800 | [diff] [blame] | 172 | return have_fb_blit ? ctx->ReadBuffer : NULL; |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 173 | case GL_FRAMEBUFFER_EXT: |
| 174 | return ctx->DrawBuffer; |
| 175 | default: |
| 176 | return NULL; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | |
| 181 | /** |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 182 | * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 183 | * gl_renderbuffer_attachment object. |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 184 | * This function is only used for user-created FB objects, not the |
| 185 | * default / window-system FB object. |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 186 | * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to |
| 187 | * the depth buffer attachment point. |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 188 | */ |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 189 | struct gl_renderbuffer_attachment * |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 190 | _mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb, |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 191 | GLenum attachment) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 192 | { |
| 193 | GLuint i; |
| 194 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 195 | assert(_mesa_is_user_fbo(fb)); |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 196 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 197 | switch (attachment) { |
| 198 | case GL_COLOR_ATTACHMENT0_EXT: |
| 199 | case GL_COLOR_ATTACHMENT1_EXT: |
| 200 | case GL_COLOR_ATTACHMENT2_EXT: |
| 201 | case GL_COLOR_ATTACHMENT3_EXT: |
| 202 | case GL_COLOR_ATTACHMENT4_EXT: |
| 203 | case GL_COLOR_ATTACHMENT5_EXT: |
| 204 | case GL_COLOR_ATTACHMENT6_EXT: |
| 205 | case GL_COLOR_ATTACHMENT7_EXT: |
| 206 | case GL_COLOR_ATTACHMENT8_EXT: |
| 207 | case GL_COLOR_ATTACHMENT9_EXT: |
| 208 | case GL_COLOR_ATTACHMENT10_EXT: |
| 209 | case GL_COLOR_ATTACHMENT11_EXT: |
| 210 | case GL_COLOR_ATTACHMENT12_EXT: |
| 211 | case GL_COLOR_ATTACHMENT13_EXT: |
| 212 | case GL_COLOR_ATTACHMENT14_EXT: |
| 213 | case GL_COLOR_ATTACHMENT15_EXT: |
Ian Romanick | 2e3a4ab | 2011-10-02 15:03:07 -0700 | [diff] [blame] | 214 | /* Only OpenGL ES 1.x forbids color attachments other than |
| 215 | * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the |
| 216 | * hardware is used. |
| 217 | */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 218 | i = attachment - GL_COLOR_ATTACHMENT0_EXT; |
Ian Romanick | 7e4cb32 | 2011-10-02 14:50:21 -0700 | [diff] [blame] | 219 | if (i >= ctx->Const.MaxColorAttachments |
Ian Romanick | 2e3a4ab | 2011-10-02 15:03:07 -0700 | [diff] [blame] | 220 | || (i > 0 && ctx->API == API_OPENGLES)) { |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 221 | return NULL; |
| 222 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 223 | return &fb->Attachment[BUFFER_COLOR0 + i]; |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 224 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Matt Turner | ec8ee91 | 2012-11-15 22:13:48 -0800 | [diff] [blame] | 225 | if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) |
Ian Romanick | 7e4cb32 | 2011-10-02 14:50:21 -0700 | [diff] [blame] | 226 | return NULL; |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 227 | /* fall-through */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 228 | case GL_DEPTH_ATTACHMENT_EXT: |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 229 | return &fb->Attachment[BUFFER_DEPTH]; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 230 | case GL_STENCIL_ATTACHMENT_EXT: |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 231 | return &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 232 | default: |
| 233 | return NULL; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /** |
| 239 | * As above, but only used for getting attachments of the default / |
| 240 | * window-system framebuffer (not user-created framebuffer objects). |
| 241 | */ |
| 242 | static struct gl_renderbuffer_attachment * |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 243 | _mesa_get_fb0_attachment(struct gl_context *ctx, struct gl_framebuffer *fb, |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 244 | GLenum attachment) |
| 245 | { |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 246 | assert(_mesa_is_winsys_fbo(fb)); |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 247 | |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 248 | if (_mesa_is_gles3(ctx)) { |
| 249 | assert(attachment == GL_BACK || |
| 250 | attachment == GL_DEPTH || |
| 251 | attachment == GL_STENCIL); |
| 252 | switch (attachment) { |
| 253 | case GL_BACK: |
| 254 | /* Since there is no stereo rendering in ES 3.0, only return the |
| 255 | * LEFT bits. |
| 256 | */ |
| 257 | if (ctx->DrawBuffer->Visual.doubleBufferMode) |
| 258 | return &fb->Attachment[BUFFER_BACK_LEFT]; |
| 259 | return &fb->Attachment[BUFFER_FRONT_LEFT]; |
| 260 | case GL_DEPTH: |
| 261 | return &fb->Attachment[BUFFER_DEPTH]; |
| 262 | case GL_STENCIL: |
| 263 | return &fb->Attachment[BUFFER_STENCIL]; |
| 264 | } |
| 265 | } |
| 266 | |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 267 | switch (attachment) { |
Kristian Høgsberg | 80dfec3 | 2010-06-15 13:07:01 -0400 | [diff] [blame] | 268 | case GL_FRONT_LEFT: |
| 269 | return &fb->Attachment[BUFFER_FRONT_LEFT]; |
| 270 | case GL_FRONT_RIGHT: |
| 271 | return &fb->Attachment[BUFFER_FRONT_RIGHT]; |
| 272 | case GL_BACK_LEFT: |
| 273 | return &fb->Attachment[BUFFER_BACK_LEFT]; |
| 274 | case GL_BACK_RIGHT: |
| 275 | return &fb->Attachment[BUFFER_BACK_RIGHT]; |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 276 | case GL_AUX0: |
| 277 | if (fb->Visual.numAuxBuffers == 1) { |
| 278 | return &fb->Attachment[BUFFER_AUX0]; |
| 279 | } |
| 280 | return NULL; |
Ian Romanick | a8328cc | 2011-10-03 12:02:18 -0700 | [diff] [blame] | 281 | |
| 282 | /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says: |
| 283 | * |
| 284 | * "If the default framebuffer is bound to target, then attachment must |
| 285 | * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi, |
| 286 | * identifying a color buffer; DEPTH, identifying the depth buffer; or |
| 287 | * STENCIL, identifying the stencil buffer." |
| 288 | * |
| 289 | * Revision #34 of the ARB_framebuffer_object spec has essentially the same |
| 290 | * language. However, revision #33 of the ARB_framebuffer_object spec |
| 291 | * says: |
| 292 | * |
| 293 | * "If the default framebuffer is bound to <target>, then <attachment> |
| 294 | * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi, |
| 295 | * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the |
| 296 | * depth buffer, or the stencil buffer, and <pname> may be |
| 297 | * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or |
| 298 | * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME." |
| 299 | * |
| 300 | * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed |
| 301 | * from glext.h, so shipping apps should not use those values. |
| 302 | * |
| 303 | * Note that neither EXT_framebuffer_object nor OES_framebuffer_object |
| 304 | * support queries of the window system FBO. |
| 305 | */ |
| 306 | case GL_DEPTH: |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 307 | return &fb->Attachment[BUFFER_DEPTH]; |
Ian Romanick | a8328cc | 2011-10-03 12:02:18 -0700 | [diff] [blame] | 308 | case GL_STENCIL: |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 309 | return &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 310 | default: |
| 311 | return NULL; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 316 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 317 | /** |
| 318 | * Remove any texture or renderbuffer attached to the given attachment |
| 319 | * point. Update reference counts, etc. |
| 320 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 321 | void |
Brian Paul | f928854 | 2010-10-22 11:25:14 -0600 | [diff] [blame] | 322 | _mesa_remove_attachment(struct gl_context *ctx, |
| 323 | struct gl_renderbuffer_attachment *att) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 324 | { |
| 325 | if (att->Type == GL_TEXTURE) { |
| 326 | ASSERT(att->Texture); |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 327 | if (ctx->Driver.FinishRenderTexture) { |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 328 | /* tell driver that we're done rendering to this texture. */ |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 329 | ctx->Driver.FinishRenderTexture(ctx, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 330 | } |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 331 | _mesa_reference_texobj(&att->Texture, NULL); /* unbind */ |
| 332 | ASSERT(!att->Texture); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 333 | } |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 334 | if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) { |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 335 | ASSERT(!att->Texture); |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 336 | _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */ |
| 337 | ASSERT(!att->Renderbuffer); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 338 | } |
| 339 | att->Type = GL_NONE; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 340 | att->Complete = GL_TRUE; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 344 | /** |
| 345 | * Bind a texture object to an attachment point. |
| 346 | * The previous binding, if any, will be removed first. |
| 347 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 348 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 349 | _mesa_set_texture_attachment(struct gl_context *ctx, |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 350 | struct gl_framebuffer *fb, |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 351 | struct gl_renderbuffer_attachment *att, |
| 352 | struct gl_texture_object *texObj, |
| 353 | GLenum texTarget, GLuint level, GLuint zoffset) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 354 | { |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 355 | if (att->Texture == texObj) { |
| 356 | /* re-attaching same texture */ |
| 357 | ASSERT(att->Type == GL_TEXTURE); |
Eric Anholt | 6b68482 | 2009-11-04 14:31:30 -0800 | [diff] [blame] | 358 | if (ctx->Driver.FinishRenderTexture) |
| 359 | ctx->Driver.FinishRenderTexture(ctx, att); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 360 | } |
| 361 | else { |
| 362 | /* new attachment */ |
Eric Anholt | 6b68482 | 2009-11-04 14:31:30 -0800 | [diff] [blame] | 363 | if (ctx->Driver.FinishRenderTexture && att->Texture) |
| 364 | ctx->Driver.FinishRenderTexture(ctx, att); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 365 | _mesa_remove_attachment(ctx, att); |
| 366 | att->Type = GL_TEXTURE; |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 367 | assert(!att->Texture); |
| 368 | _mesa_reference_texobj(&att->Texture, texObj); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /* always update these fields */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 372 | att->TextureLevel = level; |
Brian Paul | 26f1ad6 | 2009-10-23 18:15:55 -0600 | [diff] [blame] | 373 | att->CubeMapFace = _mesa_tex_target_to_face(texTarget); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 374 | att->Zoffset = zoffset; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 375 | att->Complete = GL_FALSE; |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 376 | |
Brian Paul | db0f9e7 | 2011-04-05 07:51:01 -0600 | [diff] [blame] | 377 | if (_mesa_get_attachment_teximage(att)) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 378 | ctx->Driver.RenderTexture(ctx, fb, att); |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 379 | } |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 380 | |
| 381 | invalidate_framebuffer(fb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 385 | /** |
| 386 | * Bind a renderbuffer to an attachment point. |
| 387 | * The previous binding, if any, will be removed first. |
| 388 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 389 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 390 | _mesa_set_renderbuffer_attachment(struct gl_context *ctx, |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 391 | struct gl_renderbuffer_attachment *att, |
| 392 | struct gl_renderbuffer *rb) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 393 | { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 394 | /* XXX check if re-doing same attachment, exit early */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 395 | _mesa_remove_attachment(ctx, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 396 | att->Type = GL_RENDERBUFFER_EXT; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 397 | att->Texture = NULL; /* just to be safe */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 398 | att->Complete = GL_FALSE; |
Brian | dccd9c4 | 2007-04-02 09:56:28 -0600 | [diff] [blame] | 399 | _mesa_reference_renderbuffer(&att->Renderbuffer, rb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 402 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 403 | /** |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 404 | * Fallback for ctx->Driver.FramebufferRenderbuffer() |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 405 | * Attach a renderbuffer object to a framebuffer object. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 406 | */ |
| 407 | void |
Brian Paul | f928854 | 2010-10-22 11:25:14 -0600 | [diff] [blame] | 408 | _mesa_framebuffer_renderbuffer(struct gl_context *ctx, |
| 409 | struct gl_framebuffer *fb, |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 410 | GLenum attachment, struct gl_renderbuffer *rb) |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 411 | { |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 412 | struct gl_renderbuffer_attachment *att; |
| 413 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 414 | _glthread_LOCK_MUTEX(fb->Mutex); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 415 | |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 416 | att = _mesa_get_attachment(ctx, fb, attachment); |
| 417 | ASSERT(att); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 418 | if (rb) { |
| 419 | _mesa_set_renderbuffer_attachment(ctx, att, rb); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 420 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 421 | /* do stencil attachment here (depth already done above) */ |
| 422 | att = _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT); |
| 423 | assert(att); |
| 424 | _mesa_set_renderbuffer_attachment(ctx, att, rb); |
| 425 | } |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 426 | rb->AttachedAnytime = GL_TRUE; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 427 | } |
| 428 | else { |
| 429 | _mesa_remove_attachment(ctx, att); |
| 430 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 431 | |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 432 | invalidate_framebuffer(fb); |
| 433 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 434 | _glthread_UNLOCK_MUTEX(fb->Mutex); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | |
| 438 | /** |
Brian Paul | 62c66b3 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 439 | * Fallback for ctx->Driver.ValidateFramebuffer() |
| 440 | * Check if the renderbuffer's formats are supported by the software |
| 441 | * renderer. |
| 442 | * Drivers should probably override this. |
| 443 | */ |
| 444 | void |
| 445 | _mesa_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb) |
| 446 | { |
| 447 | gl_buffer_index buf; |
| 448 | for (buf = 0; buf < BUFFER_COUNT; buf++) { |
| 449 | const struct gl_renderbuffer *rb = fb->Attachment[buf].Renderbuffer; |
| 450 | if (rb) { |
| 451 | switch (rb->_BaseFormat) { |
| 452 | case GL_ALPHA: |
| 453 | case GL_LUMINANCE_ALPHA: |
| 454 | case GL_LUMINANCE: |
| 455 | case GL_INTENSITY: |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 456 | case GL_RED: |
| 457 | case GL_RG: |
Brian Paul | 62c66b3 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 458 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
| 459 | return; |
Marek Olšák | a3ac28a | 2011-05-14 04:42:29 +0200 | [diff] [blame] | 460 | |
| 461 | default: |
Marek Olšák | 9d7698c | 2011-04-26 02:18:24 +0200 | [diff] [blame] | 462 | switch (rb->Format) { |
Marek Olšák | a3ac28a | 2011-05-14 04:42:29 +0200 | [diff] [blame] | 463 | /* XXX This list is likely incomplete. */ |
Marek Olšák | 9d7698c | 2011-04-26 02:18:24 +0200 | [diff] [blame] | 464 | case MESA_FORMAT_RGB9_E5_FLOAT: |
| 465 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
| 466 | return; |
| 467 | default:; |
Marek Olšák | a3ac28a | 2011-05-14 04:42:29 +0200 | [diff] [blame] | 468 | /* render buffer format is supported by software rendering */ |
Marek Olšák | 9d7698c | 2011-04-26 02:18:24 +0200 | [diff] [blame] | 469 | } |
Brian Paul | 62c66b3 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | |
| 476 | /** |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 477 | * For debug only. |
| 478 | */ |
| 479 | static void |
| 480 | att_incomplete(const char *msg) |
| 481 | { |
Brian Paul | 93bcf78 | 2012-05-09 12:09:21 -0600 | [diff] [blame] | 482 | if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) { |
| 483 | _mesa_debug(NULL, "attachment incomplete: %s\n", msg); |
| 484 | } |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | |
| 488 | /** |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 489 | * For debug only. |
| 490 | */ |
| 491 | static void |
| 492 | fbo_incomplete(const char *msg, int index) |
| 493 | { |
Brian Paul | 93bcf78 | 2012-05-09 12:09:21 -0600 | [diff] [blame] | 494 | if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) { |
| 495 | _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index); |
| 496 | } |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 500 | /** |
| 501 | * Is the given base format a legal format for a color renderbuffer? |
| 502 | */ |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 503 | GLboolean |
| 504 | _mesa_is_legal_color_format(const struct gl_context *ctx, GLenum baseFormat) |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 505 | { |
| 506 | switch (baseFormat) { |
| 507 | case GL_RGB: |
| 508 | case GL_RGBA: |
| 509 | return GL_TRUE; |
Marek Olšák | 6e61853 | 2010-10-02 21:53:03 +0200 | [diff] [blame] | 510 | case GL_LUMINANCE: |
| 511 | case GL_LUMINANCE_ALPHA: |
| 512 | case GL_INTENSITY: |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 513 | case GL_ALPHA: |
Jordan Justen | cf300ea | 2012-12-27 12:41:10 -0800 | [diff] [blame] | 514 | return ctx->API == API_OPENGL_COMPAT && |
| 515 | ctx->Extensions.ARB_framebuffer_object; |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 516 | case GL_RED: |
| 517 | case GL_RG: |
| 518 | return ctx->Extensions.ARB_texture_rg; |
| 519 | default: |
| 520 | return GL_FALSE; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | |
| 525 | /** |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 526 | * Is the given base format a legal format for a color renderbuffer? |
| 527 | */ |
| 528 | static GLboolean |
| 529 | is_format_color_renderable(const struct gl_context *ctx, gl_format format, GLenum internalFormat) |
| 530 | { |
| 531 | const GLenum baseFormat = |
| 532 | _mesa_get_format_base_format(format); |
| 533 | GLboolean valid; |
| 534 | |
| 535 | valid = _mesa_is_legal_color_format(ctx, baseFormat); |
| 536 | if (!valid || _mesa_is_desktop_gl(ctx)) { |
| 537 | return valid; |
| 538 | } |
| 539 | |
| 540 | /* Reject additional cases for GLES */ |
| 541 | switch (internalFormat) { |
| 542 | case GL_RGBA8_SNORM: |
| 543 | case GL_RGB32F: |
| 544 | case GL_RGB32I: |
| 545 | case GL_RGB32UI: |
| 546 | case GL_RGB16F: |
| 547 | case GL_RGB16I: |
| 548 | case GL_RGB16UI: |
| 549 | case GL_RGB8_SNORM: |
| 550 | case GL_RGB8I: |
| 551 | case GL_RGB8UI: |
| 552 | case GL_SRGB8: |
| 553 | case GL_RGB9_E5: |
| 554 | case GL_RG8_SNORM: |
| 555 | case GL_R8_SNORM: |
| 556 | return GL_FALSE; |
| 557 | default: |
| 558 | break; |
| 559 | } |
| 560 | |
| 561 | if (format == MESA_FORMAT_ARGB2101010 && internalFormat != GL_RGB10_A2) { |
| 562 | return GL_FALSE; |
| 563 | } |
| 564 | |
| 565 | return GL_TRUE; |
| 566 | } |
| 567 | |
| 568 | |
| 569 | /** |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 570 | * Is the given base format a legal format for a depth/stencil renderbuffer? |
| 571 | */ |
| 572 | static GLboolean |
| 573 | is_legal_depth_format(const struct gl_context *ctx, GLenum baseFormat) |
| 574 | { |
| 575 | switch (baseFormat) { |
| 576 | case GL_DEPTH_COMPONENT: |
| 577 | case GL_DEPTH_STENCIL_EXT: |
| 578 | return GL_TRUE; |
| 579 | default: |
| 580 | return GL_FALSE; |
| 581 | } |
| 582 | } |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 583 | |
| 584 | |
| 585 | /** |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 586 | * Test if an attachment point is complete and update its Complete field. |
| 587 | * \param format if GL_COLOR, this is a color attachment point, |
| 588 | * if GL_DEPTH, this is a depth component attachment point, |
| 589 | * if GL_STENCIL, this is a stencil component attachment point. |
| 590 | */ |
| 591 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 592 | test_attachment_completeness(const struct gl_context *ctx, GLenum format, |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 593 | struct gl_renderbuffer_attachment *att) |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 594 | { |
| 595 | assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL); |
| 596 | |
| 597 | /* assume complete */ |
| 598 | att->Complete = GL_TRUE; |
| 599 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 600 | /* Look for reasons why the attachment might be incomplete */ |
| 601 | if (att->Type == GL_TEXTURE) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 602 | const struct gl_texture_object *texObj = att->Texture; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 603 | struct gl_texture_image *texImage; |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 604 | GLenum baseFormat; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 605 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 606 | if (!texObj) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 607 | att_incomplete("no texobj"); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 608 | att->Complete = GL_FALSE; |
| 609 | return; |
| 610 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 611 | |
| 612 | texImage = texObj->Image[att->CubeMapFace][att->TextureLevel]; |
| 613 | if (!texImage) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 614 | att_incomplete("no teximage"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 615 | att->Complete = GL_FALSE; |
| 616 | return; |
| 617 | } |
| 618 | if (texImage->Width < 1 || texImage->Height < 1) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 619 | att_incomplete("teximage width/height=0"); |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 620 | printf("texobj = %u\n", texObj->Name); |
| 621 | printf("level = %d\n", att->TextureLevel); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 622 | att->Complete = GL_FALSE; |
| 623 | return; |
| 624 | } |
| 625 | if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 626 | att_incomplete("bad z offset"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 627 | att->Complete = GL_FALSE; |
| 628 | return; |
| 629 | } |
| 630 | |
Brian Paul | 1f7c914 | 2009-09-30 20:28:45 -0600 | [diff] [blame] | 631 | baseFormat = _mesa_get_format_base_format(texImage->TexFormat); |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 632 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 633 | if (format == GL_COLOR) { |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 634 | if (!_mesa_is_legal_color_format(ctx, baseFormat)) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 635 | att_incomplete("bad format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 636 | att->Complete = GL_FALSE; |
| 637 | return; |
| 638 | } |
Brian Paul | 1f7c914 | 2009-09-30 20:28:45 -0600 | [diff] [blame] | 639 | if (_mesa_is_format_compressed(texImage->TexFormat)) { |
Eric Anholt | 957f3c8 | 2009-05-15 16:24:59 -0700 | [diff] [blame] | 640 | att_incomplete("compressed internalformat"); |
| 641 | att->Complete = GL_FALSE; |
| 642 | return; |
| 643 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 644 | } |
| 645 | else if (format == GL_DEPTH) { |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 646 | if (baseFormat == GL_DEPTH_COMPONENT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 647 | /* OK */ |
| 648 | } |
| 649 | else if (ctx->Extensions.EXT_packed_depth_stencil && |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 650 | ctx->Extensions.ARB_depth_texture && |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 651 | baseFormat == GL_DEPTH_STENCIL_EXT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 652 | /* OK */ |
| 653 | } |
| 654 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 655 | att->Complete = GL_FALSE; |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 656 | att_incomplete("bad depth format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 657 | return; |
| 658 | } |
| 659 | } |
| 660 | else { |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 661 | ASSERT(format == GL_STENCIL); |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 662 | if (ctx->Extensions.EXT_packed_depth_stencil && |
| 663 | ctx->Extensions.ARB_depth_texture && |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 664 | baseFormat == GL_DEPTH_STENCIL_EXT) { |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 665 | /* OK */ |
| 666 | } |
| 667 | else { |
| 668 | /* no such thing as stencil-only textures */ |
| 669 | att_incomplete("illegal stencil texture"); |
| 670 | att->Complete = GL_FALSE; |
| 671 | return; |
| 672 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 673 | } |
| 674 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 675 | else if (att->Type == GL_RENDERBUFFER_EXT) { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 676 | const GLenum baseFormat = |
| 677 | _mesa_get_format_base_format(att->Renderbuffer->Format); |
| 678 | |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 679 | ASSERT(att->Renderbuffer); |
| 680 | if (!att->Renderbuffer->InternalFormat || |
| 681 | att->Renderbuffer->Width < 1 || |
| 682 | att->Renderbuffer->Height < 1) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 683 | att_incomplete("0x0 renderbuffer"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 684 | att->Complete = GL_FALSE; |
| 685 | return; |
| 686 | } |
| 687 | if (format == GL_COLOR) { |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 688 | if (!_mesa_is_legal_color_format(ctx, baseFormat)) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 689 | att_incomplete("bad renderbuffer color format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 690 | att->Complete = GL_FALSE; |
| 691 | return; |
| 692 | } |
| 693 | } |
| 694 | else if (format == GL_DEPTH) { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 695 | if (baseFormat == GL_DEPTH_COMPONENT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 696 | /* OK */ |
| 697 | } |
| 698 | else if (ctx->Extensions.EXT_packed_depth_stencil && |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 699 | baseFormat == GL_DEPTH_STENCIL_EXT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 700 | /* OK */ |
| 701 | } |
| 702 | else { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 703 | att_incomplete("bad renderbuffer depth format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 704 | att->Complete = GL_FALSE; |
| 705 | return; |
| 706 | } |
| 707 | } |
| 708 | else { |
| 709 | assert(format == GL_STENCIL); |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 710 | if (baseFormat == GL_STENCIL_INDEX) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 711 | /* OK */ |
| 712 | } |
| 713 | else if (ctx->Extensions.EXT_packed_depth_stencil && |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 714 | baseFormat == GL_DEPTH_STENCIL_EXT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 715 | /* OK */ |
| 716 | } |
| 717 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 718 | att->Complete = GL_FALSE; |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 719 | att_incomplete("bad renderbuffer stencil format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 720 | return; |
| 721 | } |
| 722 | } |
| 723 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 724 | else { |
| 725 | ASSERT(att->Type == GL_NONE); |
| 726 | /* complete */ |
| 727 | return; |
| 728 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | |
| 732 | /** |
| 733 | * Test if the given framebuffer object is complete and update its |
| 734 | * Status field with the results. |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 735 | * Calls the ctx->Driver.ValidateFramebuffer() function to allow the |
| 736 | * driver to make hardware-specific validation/completeness checks. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 737 | * Also update the framebuffer's Width and Height fields if the |
| 738 | * framebuffer is complete. |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 739 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 740 | void |
Brian Paul | f928854 | 2010-10-22 11:25:14 -0600 | [diff] [blame] | 741 | _mesa_test_framebuffer_completeness(struct gl_context *ctx, |
| 742 | struct gl_framebuffer *fb) |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 743 | { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 744 | GLuint numImages; |
| 745 | GLenum intFormat = GL_NONE; /* color buffers' internal format */ |
| 746 | GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 747 | GLint numSamples = -1; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 748 | GLint i; |
Brian Paul | 28b014e | 2006-04-05 03:05:17 +0000 | [diff] [blame] | 749 | GLuint j; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 750 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 751 | assert(_mesa_is_user_fbo(fb)); |
Brian Paul | c726441 | 2005-06-01 00:50:23 +0000 | [diff] [blame] | 752 | |
Marek Olšák | e06d616 | 2012-08-04 13:37:03 +0200 | [diff] [blame] | 753 | /* we're changing framebuffer fields here */ |
| 754 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 755 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 756 | numImages = 0; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 757 | fb->Width = 0; |
| 758 | fb->Height = 0; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 759 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 760 | /* Start at -2 to more easily loop over all attachment points. |
| 761 | * -2: depth buffer |
| 762 | * -1: stencil buffer |
| 763 | * >=0: color buffer |
| 764 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 765 | for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 766 | struct gl_renderbuffer_attachment *att; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 767 | GLenum f; |
Brian Paul | ca1b551 | 2011-02-28 18:23:23 -0700 | [diff] [blame] | 768 | gl_format attFormat; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 769 | |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 770 | /* |
| 771 | * XXX for ARB_fbo, only check color buffers that are named by |
| 772 | * GL_READ_BUFFER and GL_DRAW_BUFFERi. |
| 773 | */ |
| 774 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 775 | /* check for attachment completeness |
| 776 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 777 | if (i == -2) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 778 | att = &fb->Attachment[BUFFER_DEPTH]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 779 | test_attachment_completeness(ctx, GL_DEPTH, att); |
| 780 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 781 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 782 | fbo_incomplete("depth attachment incomplete", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 783 | return; |
| 784 | } |
| 785 | } |
| 786 | else if (i == -1) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 787 | att = &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 788 | test_attachment_completeness(ctx, GL_STENCIL, att); |
| 789 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 790 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 791 | fbo_incomplete("stencil attachment incomplete", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 792 | return; |
| 793 | } |
| 794 | } |
| 795 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 796 | att = &fb->Attachment[BUFFER_COLOR0 + i]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 797 | test_attachment_completeness(ctx, GL_COLOR, att); |
| 798 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 799 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 800 | fbo_incomplete("color attachment incomplete", i); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 801 | return; |
| 802 | } |
| 803 | } |
| 804 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 805 | /* get width, height, format of the renderbuffer/texture |
| 806 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 807 | if (att->Type == GL_TEXTURE) { |
Brian Paul | db0f9e7 | 2011-04-05 07:51:01 -0600 | [diff] [blame] | 808 | const struct gl_texture_image *texImg = |
| 809 | _mesa_get_attachment_teximage(att); |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 810 | minWidth = MIN2(minWidth, texImg->Width); |
| 811 | maxWidth = MAX2(maxWidth, texImg->Width); |
| 812 | minHeight = MIN2(minHeight, texImg->Height); |
| 813 | maxHeight = MAX2(maxHeight, texImg->Height); |
Brian Paul | a9fc8ba | 2005-10-05 01:48:07 +0000 | [diff] [blame] | 814 | f = texImg->_BaseFormat; |
Brian Paul | ca1b551 | 2011-02-28 18:23:23 -0700 | [diff] [blame] | 815 | attFormat = texImg->TexFormat; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 816 | numImages++; |
Jordan Justen | 6c7fa72 | 2012-12-27 13:34:44 -0800 | [diff] [blame] | 817 | if (!is_format_color_renderable(ctx, attFormat, texImg->InternalFormat) && |
Brian Paul | e67f6ee | 2010-10-22 11:38:23 -0600 | [diff] [blame] | 818 | !is_legal_depth_format(ctx, f)) { |
Brian Paul | ed7f3ae | 2005-06-07 15:03:40 +0000 | [diff] [blame] | 819 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 820 | fbo_incomplete("texture attachment incomplete", -1); |
Brian Paul | ed7f3ae | 2005-06-07 15:03:40 +0000 | [diff] [blame] | 821 | return; |
| 822 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 823 | } |
| 824 | else if (att->Type == GL_RENDERBUFFER_EXT) { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 825 | minWidth = MIN2(minWidth, att->Renderbuffer->Width); |
| 826 | maxWidth = MAX2(minWidth, att->Renderbuffer->Width); |
| 827 | minHeight = MIN2(minHeight, att->Renderbuffer->Height); |
| 828 | maxHeight = MAX2(minHeight, att->Renderbuffer->Height); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 829 | f = att->Renderbuffer->InternalFormat; |
Brian Paul | ca1b551 | 2011-02-28 18:23:23 -0700 | [diff] [blame] | 830 | attFormat = att->Renderbuffer->Format; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 831 | numImages++; |
| 832 | } |
| 833 | else { |
| 834 | assert(att->Type == GL_NONE); |
| 835 | continue; |
| 836 | } |
| 837 | |
Fabian Bieler | c7339d4 | 2011-04-05 07:51:01 -0600 | [diff] [blame] | 838 | if (att->Renderbuffer && numSamples < 0) { |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 839 | /* first buffer */ |
| 840 | numSamples = att->Renderbuffer->NumSamples; |
| 841 | } |
| 842 | |
Brian Paul | c7d1837 | 2010-10-23 09:38:45 -0600 | [diff] [blame] | 843 | /* check if integer color */ |
Brian Paul | ca1b551 | 2011-02-28 18:23:23 -0700 | [diff] [blame] | 844 | fb->_IntegerColor = _mesa_is_format_integer_color(attFormat); |
Brian Paul | c7d1837 | 2010-10-23 09:38:45 -0600 | [diff] [blame] | 845 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 846 | /* Error-check width, height, format, samples |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 847 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 848 | if (numImages == 1) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 849 | /* save format, num samples */ |
| 850 | if (i >= 0) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 851 | intFormat = f; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 852 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 853 | } |
| 854 | else { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 855 | if (!ctx->Extensions.ARB_framebuffer_object) { |
| 856 | /* check that width, height, format are same */ |
| 857 | if (minWidth != maxWidth || minHeight != maxHeight) { |
| 858 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT; |
| 859 | fbo_incomplete("width or height mismatch", -1); |
| 860 | return; |
| 861 | } |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 862 | /* check that all color buffers are the same format */ |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 863 | if (intFormat != GL_NONE && f != intFormat) { |
| 864 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; |
| 865 | fbo_incomplete("format mismatch", -1); |
| 866 | return; |
| 867 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 868 | } |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 869 | if (att->Renderbuffer && |
| 870 | att->Renderbuffer->NumSamples != numSamples) { |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 871 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 872 | fbo_incomplete("inconsistant number of samples", i); |
| 873 | return; |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 874 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 875 | } |
Marek Olšák | a82227c | 2012-06-15 17:21:05 +0200 | [diff] [blame] | 876 | |
| 877 | /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported) |
| 878 | */ |
| 879 | if (att->Type == GL_RENDERBUFFER && |
| 880 | att->Renderbuffer->Format == MESA_FORMAT_NONE) { |
| 881 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; |
| 882 | fbo_incomplete("unsupported renderbuffer format", i); |
| 883 | return; |
| 884 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 885 | } |
| 886 | |
Jordan Justen | 09714c0 | 2012-07-19 11:27:16 -0700 | [diff] [blame] | 887 | if (_mesa_is_desktop_gl(ctx) && !ctx->Extensions.ARB_ES2_compatibility) { |
Kristian Høgsberg | e88cef3 | 2010-05-24 16:56:12 -0400 | [diff] [blame] | 888 | /* Check that all DrawBuffers are present */ |
| 889 | for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) { |
| 890 | if (fb->ColorDrawBuffer[j] != GL_NONE) { |
| 891 | const struct gl_renderbuffer_attachment *att |
| 892 | = _mesa_get_attachment(ctx, fb, fb->ColorDrawBuffer[j]); |
| 893 | assert(att); |
| 894 | if (att->Type == GL_NONE) { |
| 895 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT; |
| 896 | fbo_incomplete("missing drawbuffer", j); |
| 897 | return; |
| 898 | } |
| 899 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 900 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 901 | |
Kristian Høgsberg | e88cef3 | 2010-05-24 16:56:12 -0400 | [diff] [blame] | 902 | /* Check that the ReadBuffer is present */ |
| 903 | if (fb->ColorReadBuffer != GL_NONE) { |
| 904 | const struct gl_renderbuffer_attachment *att |
| 905 | = _mesa_get_attachment(ctx, fb, fb->ColorReadBuffer); |
| 906 | assert(att); |
| 907 | if (att->Type == GL_NONE) { |
| 908 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 909 | fbo_incomplete("missing readbuffer", -1); |
Kristian Høgsberg | e88cef3 | 2010-05-24 16:56:12 -0400 | [diff] [blame] | 910 | return; |
| 911 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | |
| 915 | if (numImages == 0) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 916 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 917 | fbo_incomplete("no attachments", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 918 | return; |
| 919 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 920 | |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 921 | /* Provisionally set status = COMPLETE ... */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 922 | fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT; |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 923 | |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 924 | /* ... but the driver may say the FB is incomplete. |
| 925 | * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED |
| 926 | * if anything. |
| 927 | */ |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 928 | if (ctx->Driver.ValidateFramebuffer) { |
| 929 | ctx->Driver.ValidateFramebuffer(ctx, fb); |
Brian Paul | 1f32c41 | 2009-01-19 17:34:19 -0700 | [diff] [blame] | 930 | if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { |
| 931 | fbo_incomplete("driver marked FBO as incomplete", -1); |
| 932 | } |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | if (fb->_Status == GL_FRAMEBUFFER_COMPLETE_EXT) { |
| 936 | /* |
| 937 | * Note that if ARB_framebuffer_object is supported and the attached |
| 938 | * renderbuffers/textures are different sizes, the framebuffer |
| 939 | * width/height will be set to the smallest width/height. |
| 940 | */ |
| 941 | fb->Width = minWidth; |
| 942 | fb->Height = minHeight; |
Brian Paul | 38768db | 2009-01-27 09:49:27 -0700 | [diff] [blame] | 943 | |
| 944 | /* finally, update the visual info for the framebuffer */ |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 945 | _mesa_update_framebuffer_visual(ctx, fb); |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 946 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 947 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 948 | |
| 949 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 950 | GLboolean GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 951 | _mesa_IsRenderbuffer(GLuint renderbuffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 952 | { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 953 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 954 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 955 | if (renderbuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 956 | struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 957 | if (rb != NULL && rb != &DummyRenderbuffer) |
| 958 | return GL_TRUE; |
| 959 | } |
| 960 | return GL_FALSE; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 964 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 965 | _mesa_BindRenderbuffer(GLenum target, GLuint renderbuffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 966 | { |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 967 | struct gl_renderbuffer *newRb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 968 | GET_CURRENT_CONTEXT(ctx); |
| 969 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 970 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | 4de18fb | 2009-11-02 15:30:51 -0700 | [diff] [blame] | 971 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 972 | return; |
| 973 | } |
| 974 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 975 | /* No need to flush here since the render buffer binding has no |
| 976 | * effect on rendering state. |
| 977 | */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 978 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 979 | if (renderbuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 980 | newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 981 | if (newRb == &DummyRenderbuffer) { |
| 982 | /* ID was reserved, but no real renderbuffer object made yet */ |
| 983 | newRb = NULL; |
| 984 | } |
Ian Romanick | a13f9df | 2012-12-01 10:50:57 -0800 | [diff] [blame] | 985 | else if (!newRb |
| 986 | && _mesa_is_desktop_gl(ctx) |
| 987 | && ctx->Extensions.ARB_framebuffer_object) { |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 988 | /* All RB IDs must be Gen'd */ |
| 989 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)"); |
| 990 | return; |
| 991 | } |
| 992 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 993 | if (!newRb) { |
| 994 | /* create new renderbuffer object */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 995 | newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 996 | if (!newRb) { |
| 997 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT"); |
| 998 | return; |
| 999 | } |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1000 | ASSERT(newRb->AllocStorage); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1001 | _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb); |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 1002 | newRb->RefCount = 1; /* referenced by hash table */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1003 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1004 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1005 | else { |
| 1006 | newRb = NULL; |
| 1007 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1008 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1009 | ASSERT(newRb != &DummyRenderbuffer); |
| 1010 | |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 1011 | _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1015 | /** |
| 1016 | * If the given renderbuffer is anywhere attached to the framebuffer, detach |
| 1017 | * the renderbuffer. |
| 1018 | * This is used when a renderbuffer object is deleted. |
| 1019 | * The spec calls for unbinding. |
| 1020 | */ |
| 1021 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1022 | detach_renderbuffer(struct gl_context *ctx, |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1023 | struct gl_framebuffer *fb, |
| 1024 | struct gl_renderbuffer *rb) |
| 1025 | { |
| 1026 | GLuint i; |
| 1027 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 1028 | if (fb->Attachment[i].Renderbuffer == rb) { |
| 1029 | _mesa_remove_attachment(ctx, &fb->Attachment[i]); |
| 1030 | } |
| 1031 | } |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 1032 | invalidate_framebuffer(fb); |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1036 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1037 | _mesa_DeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1038 | { |
| 1039 | GLint i; |
| 1040 | GET_CURRENT_CONTEXT(ctx); |
| 1041 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1042 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1043 | |
| 1044 | for (i = 0; i < n; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1045 | if (renderbuffers[i] > 0) { |
| 1046 | struct gl_renderbuffer *rb; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1047 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1048 | if (rb) { |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1049 | /* check if deleting currently bound renderbuffer object */ |
| 1050 | if (rb == ctx->CurrentRenderbuffer) { |
| 1051 | /* bind default */ |
| 1052 | ASSERT(rb->RefCount >= 2); |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1053 | _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT, 0); |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 1056 | if (_mesa_is_user_fbo(ctx->DrawBuffer)) { |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1057 | detach_renderbuffer(ctx, ctx->DrawBuffer, rb); |
| 1058 | } |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 1059 | if (_mesa_is_user_fbo(ctx->ReadBuffer) |
Brian Paul | fc8c4a3 | 2011-06-16 07:31:58 -0600 | [diff] [blame] | 1060 | && ctx->ReadBuffer != ctx->DrawBuffer) { |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1061 | detach_renderbuffer(ctx, ctx->ReadBuffer, rb); |
| 1062 | } |
| 1063 | |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 1064 | /* Remove from hash table immediately, to free the ID. |
| 1065 | * But the object will not be freed until it's no longer |
| 1066 | * referenced anywhere else. |
| 1067 | */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1068 | _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1069 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1070 | if (rb != &DummyRenderbuffer) { |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 1071 | /* no longer referenced by hash table */ |
| 1072 | _mesa_reference_renderbuffer(&rb, NULL); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1073 | } |
| 1074 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1080 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1081 | _mesa_GenRenderbuffers(GLsizei n, GLuint *renderbuffers) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1082 | { |
| 1083 | GET_CURRENT_CONTEXT(ctx); |
| 1084 | GLuint first; |
| 1085 | GLint i; |
| 1086 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1087 | if (n < 0) { |
| 1088 | _mesa_error(ctx, GL_INVALID_VALUE, "glGenRenderbuffersEXT(n)"); |
| 1089 | return; |
| 1090 | } |
| 1091 | |
| 1092 | if (!renderbuffers) |
| 1093 | return; |
| 1094 | |
| 1095 | first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n); |
| 1096 | |
| 1097 | for (i = 0; i < n; i++) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1098 | GLuint name = first + i; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1099 | renderbuffers[i] = name; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1100 | /* insert dummy placeholder into hash table */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1101 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1102 | _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1103 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 1108 | /** |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1109 | * Given an internal format token for a render buffer, return the |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1110 | * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, |
| 1111 | * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE, |
| 1112 | * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc). |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1113 | * |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1114 | * This is similar to _mesa_base_tex_format() but the set of valid |
| 1115 | * internal formats is different. |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1116 | * |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1117 | * 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] | 1118 | * 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] | 1119 | * |
| 1120 | * \param internalFormat as passed to glRenderbufferStorage() |
| 1121 | * \return the base internal format, or 0 if internalFormat is illegal |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 1122 | */ |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 1123 | GLenum |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1124 | _mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat) |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1125 | { |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1126 | /* |
| 1127 | * Notes: some formats such as alpha, luminance, etc. were added |
| 1128 | * with GL_ARB_framebuffer_object. |
| 1129 | */ |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1130 | switch (internalFormat) { |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1131 | case GL_ALPHA: |
| 1132 | case GL_ALPHA4: |
| 1133 | case GL_ALPHA8: |
| 1134 | case GL_ALPHA12: |
| 1135 | case GL_ALPHA16: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1136 | return ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_framebuffer_object |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1137 | ? GL_ALPHA : 0; |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1138 | case GL_LUMINANCE: |
| 1139 | case GL_LUMINANCE4: |
| 1140 | case GL_LUMINANCE8: |
| 1141 | case GL_LUMINANCE12: |
| 1142 | case GL_LUMINANCE16: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1143 | return ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_framebuffer_object |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1144 | ? GL_LUMINANCE : 0; |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1145 | case GL_LUMINANCE_ALPHA: |
| 1146 | case GL_LUMINANCE4_ALPHA4: |
| 1147 | case GL_LUMINANCE6_ALPHA2: |
| 1148 | case GL_LUMINANCE8_ALPHA8: |
| 1149 | case GL_LUMINANCE12_ALPHA4: |
| 1150 | case GL_LUMINANCE12_ALPHA12: |
| 1151 | case GL_LUMINANCE16_ALPHA16: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1152 | return ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_framebuffer_object |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1153 | ? GL_LUMINANCE_ALPHA : 0; |
Brian Paul | 976ea9d | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1154 | case GL_INTENSITY: |
| 1155 | case GL_INTENSITY4: |
| 1156 | case GL_INTENSITY8: |
| 1157 | case GL_INTENSITY12: |
| 1158 | case GL_INTENSITY16: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1159 | return ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_framebuffer_object |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1160 | ? GL_INTENSITY : 0; |
| 1161 | case GL_RGB8: |
| 1162 | return GL_RGB; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1163 | case GL_RGB: |
| 1164 | case GL_R3_G3_B2: |
| 1165 | case GL_RGB4: |
| 1166 | case GL_RGB5: |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1167 | case GL_RGB10: |
| 1168 | case GL_RGB12: |
| 1169 | case GL_RGB16: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1170 | return _mesa_is_desktop_gl(ctx) ? GL_RGB : 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1171 | case GL_SRGB8_EXT: |
Matt Turner | cbef537 | 2012-11-20 13:45:03 -0800 | [diff] [blame] | 1172 | return _mesa_is_desktop_gl(ctx) ? GL_RGB : 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1173 | case GL_RGBA4: |
| 1174 | case GL_RGB5_A1: |
| 1175 | case GL_RGBA8: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1176 | return GL_RGBA; |
| 1177 | case GL_RGBA: |
| 1178 | case GL_RGBA2: |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1179 | case GL_RGBA12: |
| 1180 | case GL_RGBA16: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1181 | return _mesa_is_desktop_gl(ctx) ? GL_RGBA : 0; |
| 1182 | case GL_RGB10_A2: |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1183 | case GL_SRGB8_ALPHA8_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1184 | 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] | 1185 | case GL_STENCIL_INDEX: |
| 1186 | case GL_STENCIL_INDEX1_EXT: |
| 1187 | case GL_STENCIL_INDEX4_EXT: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1188 | case GL_STENCIL_INDEX16_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1189 | /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in |
| 1190 | * OpenGL ES, but Mesa does not currently support them. |
| 1191 | */ |
| 1192 | return _mesa_is_desktop_gl(ctx) ? GL_STENCIL_INDEX : 0; |
| 1193 | case GL_STENCIL_INDEX8_EXT: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1194 | return GL_STENCIL_INDEX; |
| 1195 | case GL_DEPTH_COMPONENT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1196 | case GL_DEPTH_COMPONENT32: |
| 1197 | return _mesa_is_desktop_gl(ctx) ? GL_DEPTH_COMPONENT : 0; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1198 | case GL_DEPTH_COMPONENT16: |
| 1199 | case GL_DEPTH_COMPONENT24: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1200 | return GL_DEPTH_COMPONENT; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1201 | case GL_DEPTH_STENCIL_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1202 | return _mesa_is_desktop_gl(ctx) |
| 1203 | && ctx->Extensions.EXT_packed_depth_stencil |
| 1204 | ? GL_DEPTH_STENCIL_EXT : 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1205 | case GL_DEPTH24_STENCIL8_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1206 | return ctx->Extensions.EXT_packed_depth_stencil |
| 1207 | ? GL_DEPTH_STENCIL_EXT : 0; |
Marek Olšák | 1165280 | 2011-06-01 15:48:51 +0200 | [diff] [blame] | 1208 | case GL_DEPTH_COMPONENT32F: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1209 | return ctx->Version >= 30 |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1210 | || (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_depth_buffer_float) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1211 | ? GL_DEPTH_COMPONENT : 0; |
Marek Olšák | 1165280 | 2011-06-01 15:48:51 +0200 | [diff] [blame] | 1212 | case GL_DEPTH32F_STENCIL8: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1213 | return ctx->Version >= 30 |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1214 | || (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_depth_buffer_float) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1215 | ? GL_DEPTH_STENCIL : 0; |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1216 | case GL_RED: |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1217 | case GL_R16: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1218 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_rg |
| 1219 | ? GL_RED : 0; |
| 1220 | case GL_R8: |
| 1221 | return ctx->API != API_OPENGLES && ctx->Extensions.ARB_texture_rg |
| 1222 | ? GL_RED : 0; |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1223 | case GL_RG: |
Brian Paul | d301565 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1224 | case GL_RG16: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1225 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_rg |
| 1226 | ? GL_RG : 0; |
| 1227 | case GL_RG8: |
| 1228 | return ctx->API != API_OPENGLES && ctx->Extensions.ARB_texture_rg |
| 1229 | ? GL_RG : 0; |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1230 | /* signed normalized texture formats */ |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1231 | case GL_RED_SNORM: |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 1232 | case GL_R8_SNORM: |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1233 | case GL_R16_SNORM: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1234 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1235 | ? GL_RED : 0; |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1236 | case GL_RG_SNORM: |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 1237 | case GL_RG8_SNORM: |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1238 | case GL_RG16_SNORM: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1239 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1240 | ? GL_RG : 0; |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1241 | case GL_RGB_SNORM: |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 1242 | case GL_RGB8_SNORM: |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1243 | case GL_RGB16_SNORM: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1244 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1245 | ? GL_RGB : 0; |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1246 | case GL_RGBA_SNORM: |
Ian Romanick | 2aae3ab | 2012-12-04 10:36:10 -0800 | [diff] [blame] | 1247 | case GL_RGBA8_SNORM: |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1248 | case GL_RGBA16_SNORM: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1249 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm |
| 1250 | ? GL_RGBA : 0; |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1251 | case GL_ALPHA_SNORM: |
| 1252 | case GL_ALPHA8_SNORM: |
| 1253 | case GL_ALPHA16_SNORM: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1254 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1255 | ctx->Extensions.EXT_texture_snorm && |
Marek Olšák | 0be3699 | 2011-03-18 13:44:51 +0100 | [diff] [blame] | 1256 | ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1257 | case GL_R16F: |
| 1258 | case GL_R32F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 1259 | return ((_mesa_is_desktop_gl(ctx) && |
| 1260 | ctx->Extensions.ARB_texture_rg && |
| 1261 | ctx->Extensions.ARB_texture_float) || |
| 1262 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
| 1263 | ? GL_RED : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1264 | case GL_RG16F: |
| 1265 | case GL_RG32F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 1266 | return ((_mesa_is_desktop_gl(ctx) && |
| 1267 | ctx->Extensions.ARB_texture_rg && |
| 1268 | ctx->Extensions.ARB_texture_float) || |
| 1269 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
| 1270 | ? GL_RG : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1271 | case GL_RGB16F: |
| 1272 | case GL_RGB32F: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1273 | return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_float) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1274 | ? GL_RGB : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1275 | case GL_RGBA16F: |
| 1276 | case GL_RGBA32F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 1277 | return ((_mesa_is_desktop_gl(ctx) && |
| 1278 | ctx->Extensions.ARB_texture_float) || |
| 1279 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1280 | ? GL_RGBA : 0; |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1281 | case GL_ALPHA16F_ARB: |
| 1282 | case GL_ALPHA32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1283 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1284 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1285 | ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0; |
| 1286 | case GL_LUMINANCE16F_ARB: |
| 1287 | case GL_LUMINANCE32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1288 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1289 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1290 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0; |
| 1291 | case GL_LUMINANCE_ALPHA16F_ARB: |
| 1292 | case GL_LUMINANCE_ALPHA32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1293 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1294 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1295 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0; |
| 1296 | case GL_INTENSITY16F_ARB: |
| 1297 | case GL_INTENSITY32F_ARB: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1298 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1299 | ctx->Extensions.ARB_texture_float && |
Marek Olšák | 15f99d1 | 2011-02-16 00:35:44 +0100 | [diff] [blame] | 1300 | ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0; |
Marek Olšák | 9d7698c | 2011-04-26 02:18:24 +0200 | [diff] [blame] | 1301 | case GL_RGB9_E5: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1302 | return (_mesa_is_desktop_gl(ctx) |
| 1303 | && ctx->Extensions.EXT_texture_shared_exponent) |
Matt Turner | cbef537 | 2012-11-20 13:45:03 -0800 | [diff] [blame] | 1304 | ? GL_RGB : 0; |
Marek Olšák | 631d23d | 2011-04-26 02:27:25 +0200 | [diff] [blame] | 1305 | case GL_R11F_G11F_B10F: |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 1306 | return ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_packed_float) || |
| 1307 | _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ ) |
Matt Turner | cbef537 | 2012-11-20 13:45:03 -0800 | [diff] [blame] | 1308 | ? GL_RGB : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1309 | |
| 1310 | case GL_RGBA8UI_EXT: |
| 1311 | case GL_RGBA16UI_EXT: |
| 1312 | case GL_RGBA32UI_EXT: |
| 1313 | case GL_RGBA8I_EXT: |
| 1314 | case GL_RGBA16I_EXT: |
| 1315 | case GL_RGBA32I_EXT: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1316 | return ctx->Version >= 30 |
| 1317 | || (_mesa_is_desktop_gl(ctx) && |
| 1318 | ctx->Extensions.EXT_texture_integer) ? GL_RGBA : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1319 | |
| 1320 | case GL_RGB8UI_EXT: |
| 1321 | case GL_RGB16UI_EXT: |
| 1322 | case GL_RGB32UI_EXT: |
| 1323 | case GL_RGB8I_EXT: |
| 1324 | case GL_RGB16I_EXT: |
| 1325 | case GL_RGB32I_EXT: |
Ian Romanick | a86d629 | 2012-12-03 11:55:12 -0800 | [diff] [blame] | 1326 | return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_integer |
| 1327 | ? GL_RGB : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1328 | case GL_R8UI: |
| 1329 | case GL_R8I: |
| 1330 | case GL_R16UI: |
| 1331 | case GL_R16I: |
| 1332 | case GL_R32UI: |
| 1333 | case GL_R32I: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1334 | return ctx->Version >= 30 |
| 1335 | || (_mesa_is_desktop_gl(ctx) && |
| 1336 | ctx->Extensions.ARB_texture_rg && |
| 1337 | ctx->Extensions.EXT_texture_integer) ? GL_RED : 0; |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1338 | |
| 1339 | case GL_RG8UI: |
| 1340 | case GL_RG8I: |
| 1341 | case GL_RG16UI: |
| 1342 | case GL_RG16I: |
| 1343 | case GL_RG32UI: |
| 1344 | case GL_RG32I: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1345 | return ctx->Version >= 30 |
| 1346 | || (_mesa_is_desktop_gl(ctx) && |
| 1347 | ctx->Extensions.ARB_texture_rg && |
| 1348 | ctx->Extensions.EXT_texture_integer) ? GL_RG : 0; |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 1349 | |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1350 | case GL_INTENSITY8I_EXT: |
| 1351 | case GL_INTENSITY8UI_EXT: |
| 1352 | case GL_INTENSITY16I_EXT: |
| 1353 | case GL_INTENSITY16UI_EXT: |
| 1354 | case GL_INTENSITY32I_EXT: |
| 1355 | case GL_INTENSITY32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1356 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1357 | ctx->Extensions.EXT_texture_integer && |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1358 | ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0; |
| 1359 | |
| 1360 | case GL_LUMINANCE8I_EXT: |
| 1361 | case GL_LUMINANCE8UI_EXT: |
| 1362 | case GL_LUMINANCE16I_EXT: |
| 1363 | case GL_LUMINANCE16UI_EXT: |
| 1364 | case GL_LUMINANCE32I_EXT: |
| 1365 | case GL_LUMINANCE32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1366 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1367 | ctx->Extensions.EXT_texture_integer && |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1368 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0; |
| 1369 | |
| 1370 | case GL_LUMINANCE_ALPHA8I_EXT: |
| 1371 | case GL_LUMINANCE_ALPHA8UI_EXT: |
| 1372 | case GL_LUMINANCE_ALPHA16I_EXT: |
| 1373 | case GL_LUMINANCE_ALPHA16UI_EXT: |
| 1374 | case GL_LUMINANCE_ALPHA32I_EXT: |
| 1375 | case GL_LUMINANCE_ALPHA32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1376 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1377 | ctx->Extensions.EXT_texture_integer && |
Dave Airlie | 9c697a9 | 2011-10-04 20:59:40 +0100 | [diff] [blame] | 1378 | ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0; |
Dave Airlie | f449be6 | 2011-11-27 16:21:02 +0000 | [diff] [blame] | 1379 | |
Marek Olšák | 636802f | 2012-01-22 20:21:36 +0100 | [diff] [blame] | 1380 | case GL_ALPHA8I_EXT: |
| 1381 | case GL_ALPHA8UI_EXT: |
| 1382 | case GL_ALPHA16I_EXT: |
| 1383 | case GL_ALPHA16UI_EXT: |
| 1384 | case GL_ALPHA32I_EXT: |
| 1385 | case GL_ALPHA32UI_EXT: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 1386 | return ctx->API == API_OPENGL_COMPAT && |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1387 | ctx->Extensions.EXT_texture_integer && |
Marek Olšák | 636802f | 2012-01-22 20:21:36 +0100 | [diff] [blame] | 1388 | ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0; |
| 1389 | |
Dave Airlie | f449be6 | 2011-11-27 16:21:02 +0000 | [diff] [blame] | 1390 | case GL_RGB10_A2UI: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1391 | return (_mesa_is_desktop_gl(ctx) && |
| 1392 | ctx->Extensions.ARB_texture_rgb10_a2ui) |
| 1393 | || _mesa_is_gles3(ctx) ? GL_RGBA : 0; |
Marek Olšák | 1a06e84 | 2012-07-12 14:07:41 +0200 | [diff] [blame] | 1394 | |
| 1395 | case GL_RGB565: |
Ian Romanick | f0c99d0 | 2012-07-27 08:31:12 -0700 | [diff] [blame] | 1396 | return _mesa_is_gles(ctx) || ctx->Extensions.ARB_ES2_compatibility |
| 1397 | ? GL_RGB : 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1398 | default: |
Eric Anholt | 65c41d5 | 2011-01-13 10:05:50 -0800 | [diff] [blame] | 1399 | return 0; |
Brian Paul | f41bbc7 | 2011-01-24 19:38:52 -0700 | [diff] [blame] | 1400 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 1404 | /** |
| 1405 | * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk(). |
| 1406 | */ |
| 1407 | static void |
| 1408 | invalidate_rb(GLuint key, void *data, void *userData) |
| 1409 | { |
| 1410 | struct gl_framebuffer *fb = (struct gl_framebuffer *) data; |
| 1411 | struct gl_renderbuffer *rb = (struct gl_renderbuffer *) userData; |
| 1412 | |
| 1413 | /* If this is a user-created FBO */ |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 1414 | if (_mesa_is_user_fbo(fb)) { |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 1415 | GLuint i; |
| 1416 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 1417 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
| 1418 | if (att->Type == GL_RENDERBUFFER && |
| 1419 | att->Renderbuffer == rb) { |
| 1420 | /* Mark fb status as indeterminate to force re-validation */ |
| 1421 | fb->_Status = 0; |
Marek Olšák | a674ef7 | 2011-03-07 23:33:36 +0100 | [diff] [blame] | 1422 | return; |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 1423 | } |
| 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1429 | /** sentinal value, see below */ |
| 1430 | #define NO_SAMPLES 1000 |
| 1431 | |
| 1432 | |
| 1433 | /** |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1434 | * Helper function used by _mesa_RenderbufferStorage() and |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1435 | * _mesa_RenderbufferStorageMultisample(). |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1436 | * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage(). |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1437 | */ |
| 1438 | static void |
| 1439 | renderbuffer_storage(GLenum target, GLenum internalFormat, |
| 1440 | GLsizei width, GLsizei height, GLsizei samples) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1441 | { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1442 | const char *func = samples == NO_SAMPLES ? |
Jordan Justen | 275620c | 2013-01-12 14:19:30 -0800 | [diff] [blame] | 1443 | "glRenderbufferStorage" : "glRenderbufferStorageMultisample"; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1444 | struct gl_renderbuffer *rb; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1445 | GLenum baseFormat; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1446 | GET_CURRENT_CONTEXT(ctx); |
| 1447 | |
Jordan Justen | 275620c | 2013-01-12 14:19:30 -0800 | [diff] [blame] | 1448 | if (MESA_VERBOSE & VERBOSE_API) { |
| 1449 | if (samples == NO_SAMPLES) |
| 1450 | _mesa_debug(ctx, "%s(%s, %s, %d, %d)\n", |
| 1451 | func, |
| 1452 | _mesa_lookup_enum_by_nr(target), |
| 1453 | _mesa_lookup_enum_by_nr(internalFormat), |
| 1454 | width, height); |
| 1455 | else |
| 1456 | _mesa_debug(ctx, "%s(%s, %s, %d, %d, %d)\n", |
| 1457 | func, |
| 1458 | _mesa_lookup_enum_by_nr(target), |
| 1459 | _mesa_lookup_enum_by_nr(internalFormat), |
| 1460 | width, height, samples); |
| 1461 | } |
| 1462 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1463 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1464 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1465 | return; |
| 1466 | } |
| 1467 | |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 1468 | baseFormat = _mesa_base_fbo_format(ctx, internalFormat); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1469 | if (baseFormat == 0) { |
Jordan Justen | 119002a | 2013-01-10 17:29:27 -0800 | [diff] [blame] | 1470 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat=%s)", |
| 1471 | func, _mesa_lookup_enum_by_nr(internalFormat)); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1472 | return; |
| 1473 | } |
| 1474 | |
Yuanhan Liu | 49f8447 | 2011-10-25 15:36:59 +0800 | [diff] [blame] | 1475 | if (width < 0 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1476 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(width)", func); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1477 | return; |
| 1478 | } |
| 1479 | |
Yuanhan Liu | 49f8447 | 2011-10-25 15:36:59 +0800 | [diff] [blame] | 1480 | if (height < 0 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1481 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(height)", func); |
| 1482 | return; |
| 1483 | } |
| 1484 | |
| 1485 | if (samples == NO_SAMPLES) { |
| 1486 | /* NumSamples == 0 indicates non-multisampling */ |
| 1487 | samples = 0; |
| 1488 | } |
Brian Paul | ca0d048 | 2010-01-27 17:01:54 -0700 | [diff] [blame] | 1489 | else if (samples > (GLsizei) ctx->Const.MaxSamples) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1490 | /* note: driver may choose to use more samples than what's requested */ |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1491 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(samples)", func); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1492 | return; |
| 1493 | } |
| 1494 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1495 | rb = ctx->CurrentRenderbuffer; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1496 | if (!rb) { |
Vinson Lee | c5dde53 | 2010-09-02 16:03:32 -0700 | [diff] [blame] | 1497 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1498 | return; |
| 1499 | } |
| 1500 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1501 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 1502 | |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 1503 | if (rb->InternalFormat == internalFormat && |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 1504 | rb->Width == (GLuint) width && |
Eric Anholt | 0e8d156 | 2012-01-11 13:46:43 -0800 | [diff] [blame] | 1505 | rb->Height == (GLuint) height && |
| 1506 | rb->NumSamples == samples) { |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 1507 | /* no change in allocation needed */ |
| 1508 | return; |
| 1509 | } |
| 1510 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1511 | /* These MUST get set by the AllocStorage func */ |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1512 | rb->Format = MESA_FORMAT_NONE; |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1513 | rb->NumSamples = samples; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1514 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1515 | /* Now allocate the storage */ |
| 1516 | ASSERT(rb->AllocStorage); |
| 1517 | if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) { |
| 1518 | /* No error - check/set fields now */ |
Marek Olšák | a82227c | 2012-06-15 17:21:05 +0200 | [diff] [blame] | 1519 | /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */ |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 1520 | assert(rb->Width == (GLuint) width); |
| 1521 | assert(rb->Height == (GLuint) height); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1522 | rb->InternalFormat = internalFormat; |
Brian Paul | a8dafe7 | 2010-02-25 19:03:55 -0700 | [diff] [blame] | 1523 | rb->_BaseFormat = baseFormat; |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1524 | assert(rb->_BaseFormat != 0); |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1525 | } |
| 1526 | else { |
| 1527 | /* Probably ran out of memory - clear the fields */ |
| 1528 | rb->Width = 0; |
| 1529 | rb->Height = 0; |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1530 | rb->Format = MESA_FORMAT_NONE; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1531 | rb->InternalFormat = GL_NONE; |
| 1532 | rb->_BaseFormat = GL_NONE; |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1533 | rb->NumSamples = 0; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
Marek Olšák | df818d5 | 2011-03-06 05:26:12 +0100 | [diff] [blame] | 1536 | /* Invalidate the framebuffers the renderbuffer is attached in. */ |
| 1537 | if (rb->AttachedAnytime) { |
| 1538 | _mesa_HashWalk(ctx->Shared->FrameBuffers, invalidate_rb, rb); |
| 1539 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1542 | |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1543 | void GLAPIENTRY |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1544 | _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1545 | { |
Brian Paul | 51b7992 | 2010-02-24 11:57:26 -0700 | [diff] [blame] | 1546 | struct gl_renderbuffer *rb; |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1547 | GET_CURRENT_CONTEXT(ctx); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1548 | |
Chia-I Wu | 2002e4d0 | 2010-04-06 17:46:17 +0800 | [diff] [blame] | 1549 | if (!ctx->Extensions.OES_EGL_image) { |
| 1550 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1551 | "glEGLImageTargetRenderbufferStorageOES(unsupported)"); |
| 1552 | return; |
| 1553 | } |
| 1554 | |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1555 | if (target != GL_RENDERBUFFER) { |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1556 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1557 | "EGLImageTargetRenderbufferStorageOES"); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1558 | return; |
| 1559 | } |
| 1560 | |
| 1561 | rb = ctx->CurrentRenderbuffer; |
| 1562 | if (!rb) { |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1563 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1564 | "EGLImageTargetRenderbufferStorageOES"); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1565 | return; |
| 1566 | } |
| 1567 | |
| 1568 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 1569 | |
| 1570 | ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image); |
| 1571 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1572 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1573 | |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1574 | /** |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1575 | * Helper function for _mesa_GetRenderbufferParameteriv() and |
| 1576 | * _mesa_GetFramebufferAttachmentParameteriv() |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1577 | * We have to be careful to respect the base format. For example, if a |
| 1578 | * renderbuffer/texture was created with internalFormat=GL_RGB but the |
| 1579 | * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE |
| 1580 | * we need to return zero. |
| 1581 | */ |
| 1582 | static GLint |
| 1583 | get_component_bits(GLenum pname, GLenum baseFormat, gl_format format) |
| 1584 | { |
Brian Paul | f0b6e9a | 2011-11-23 15:33:45 -0700 | [diff] [blame] | 1585 | if (_mesa_base_format_has_channel(baseFormat, pname)) |
| 1586 | return _mesa_get_format_bits(format, pname); |
| 1587 | else |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1588 | return 0; |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | |
| 1592 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1593 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1594 | _mesa_RenderbufferStorage(GLenum target, GLenum internalFormat, |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1595 | GLsizei width, GLsizei height) |
| 1596 | { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1597 | /* GL_ARB_fbo says calling this function is equivalent to calling |
| 1598 | * glRenderbufferStorageMultisample() with samples=0. We pass in |
| 1599 | * a token value here just for error reporting purposes. |
| 1600 | */ |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1601 | renderbuffer_storage(target, internalFormat, width, height, NO_SAMPLES); |
| 1602 | } |
| 1603 | |
| 1604 | |
| 1605 | void GLAPIENTRY |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1606 | _mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples, |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1607 | GLenum internalFormat, |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1608 | GLsizei width, GLsizei height) |
| 1609 | { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1610 | renderbuffer_storage(target, internalFormat, width, height, samples); |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1613 | |
| 1614 | /** |
| 1615 | * OpenGL ES version of glRenderBufferStorage. |
| 1616 | */ |
Kristian Høgsberg | 61d94dd | 2010-04-22 21:11:56 -0400 | [diff] [blame] | 1617 | void GLAPIENTRY |
| 1618 | _es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat, |
| 1619 | GLsizei width, GLsizei height) |
| 1620 | { |
| 1621 | switch (internalFormat) { |
| 1622 | case GL_RGB565: |
| 1623 | /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */ |
| 1624 | /* choose a closest format */ |
| 1625 | internalFormat = GL_RGB5; |
| 1626 | break; |
| 1627 | default: |
| 1628 | break; |
| 1629 | } |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1630 | |
Kristian Høgsberg | 61d94dd | 2010-04-22 21:11:56 -0400 | [diff] [blame] | 1631 | renderbuffer_storage(target, internalFormat, width, height, 0); |
| 1632 | } |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1633 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1634 | |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1635 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1636 | _mesa_GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1637 | { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1638 | struct gl_renderbuffer *rb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1639 | GET_CURRENT_CONTEXT(ctx); |
| 1640 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1641 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1642 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1643 | "glGetRenderbufferParameterivEXT(target)"); |
| 1644 | return; |
| 1645 | } |
| 1646 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1647 | rb = ctx->CurrentRenderbuffer; |
| 1648 | if (!rb) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1649 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1650 | "glGetRenderbufferParameterivEXT"); |
| 1651 | return; |
| 1652 | } |
| 1653 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1654 | /* No need to flush here since we're just quering state which is |
| 1655 | * not effected by rendering. |
| 1656 | */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1657 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1658 | switch (pname) { |
| 1659 | case GL_RENDERBUFFER_WIDTH_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1660 | *params = rb->Width; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1661 | return; |
| 1662 | case GL_RENDERBUFFER_HEIGHT_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1663 | *params = rb->Height; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1664 | return; |
| 1665 | case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1666 | *params = rb->InternalFormat; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1667 | return; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1668 | case GL_RENDERBUFFER_RED_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1669 | case GL_RENDERBUFFER_GREEN_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1670 | case GL_RENDERBUFFER_BLUE_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1671 | case GL_RENDERBUFFER_ALPHA_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1672 | case GL_RENDERBUFFER_DEPTH_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1673 | case GL_RENDERBUFFER_STENCIL_SIZE_EXT: |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1674 | *params = get_component_bits(pname, rb->_BaseFormat, rb->Format); |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1675 | break; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1676 | case GL_RENDERBUFFER_SAMPLES: |
Ian Romanick | ae86ebf | 2012-07-27 07:49:49 -0700 | [diff] [blame] | 1677 | if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_framebuffer_object) |
| 1678 | || _mesa_is_gles3(ctx)) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1679 | *params = rb->NumSamples; |
| 1680 | break; |
| 1681 | } |
| 1682 | /* fallthrough */ |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1683 | default: |
| 1684 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1685 | "glGetRenderbufferParameterivEXT(target)"); |
| 1686 | return; |
| 1687 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1691 | GLboolean GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1692 | _mesa_IsFramebuffer(GLuint framebuffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1693 | { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1694 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1695 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 1696 | if (framebuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1697 | struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 1698 | if (rb != NULL && rb != &DummyFramebuffer) |
| 1699 | return GL_TRUE; |
| 1700 | } |
| 1701 | return GL_FALSE; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | |
brian | a492ab7 | 2009-11-10 15:33:31 -0700 | [diff] [blame] | 1705 | /** |
| 1706 | * Check if any of the attachments of the given framebuffer are textures |
| 1707 | * (render to texture). Call ctx->Driver.RenderTexture() for such |
| 1708 | * attachments. |
| 1709 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1710 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1711 | check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb) |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1712 | { |
| 1713 | GLuint i; |
| 1714 | ASSERT(ctx->Driver.RenderTexture); |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1715 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 1716 | if (_mesa_is_winsys_fbo(fb)) |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1717 | return; /* can't render to texture with winsys framebuffers */ |
| 1718 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1719 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 1720 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
Brian Paul | db0f9e7 | 2011-04-05 07:51:01 -0600 | [diff] [blame] | 1721 | if (att->Texture && _mesa_get_attachment_teximage(att)) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1722 | ctx->Driver.RenderTexture(ctx, fb, att); |
| 1723 | } |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 1728 | /** |
| 1729 | * Examine all the framebuffer's attachments to see if any are textures. |
| 1730 | * If so, call ctx->Driver.FinishRenderTexture() for each texture to |
| 1731 | * notify the device driver that the texture image may have changed. |
| 1732 | */ |
| 1733 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 1734 | check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb) |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 1735 | { |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 1736 | if (_mesa_is_winsys_fbo(fb)) |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1737 | return; /* can't render to texture with winsys framebuffers */ |
| 1738 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 1739 | if (ctx->Driver.FinishRenderTexture) { |
| 1740 | GLuint i; |
| 1741 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 1742 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
Brian | 8b36166 | 2007-11-09 08:55:49 -0700 | [diff] [blame] | 1743 | if (att->Texture && att->Renderbuffer) { |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 1744 | ctx->Driver.FinishRenderTexture(ctx, att); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 1745 | } |
| 1746 | } |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1751 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1752 | _mesa_BindFramebuffer(GLenum target, GLuint framebuffer) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1753 | { |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1754 | struct gl_framebuffer *newDrawFb, *newReadFb; |
brian | d96e55f | 2009-11-10 15:50:22 -0700 | [diff] [blame] | 1755 | struct gl_framebuffer *oldDrawFb, *oldReadFb; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1756 | GLboolean bindReadBuf, bindDrawBuf; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1757 | GET_CURRENT_CONTEXT(ctx); |
| 1758 | |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 1759 | #ifdef DEBUG |
| 1760 | if (ctx->Extensions.ARB_framebuffer_object) { |
| 1761 | ASSERT(ctx->Extensions.EXT_framebuffer_object); |
| 1762 | ASSERT(ctx->Extensions.EXT_framebuffer_blit); |
| 1763 | } |
| 1764 | #endif |
| 1765 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1766 | if (!ctx->Extensions.EXT_framebuffer_object) { |
| 1767 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1768 | "glBindFramebufferEXT(unsupported)"); |
| 1769 | return; |
| 1770 | } |
| 1771 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1772 | switch (target) { |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1773 | case GL_DRAW_FRAMEBUFFER_EXT: |
| 1774 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1775 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
| 1776 | return; |
| 1777 | } |
| 1778 | bindDrawBuf = GL_TRUE; |
| 1779 | bindReadBuf = GL_FALSE; |
| 1780 | break; |
| 1781 | case GL_READ_FRAMEBUFFER_EXT: |
| 1782 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1783 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
| 1784 | return; |
| 1785 | } |
| 1786 | bindDrawBuf = GL_FALSE; |
| 1787 | bindReadBuf = GL_TRUE; |
| 1788 | break; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1789 | case GL_FRAMEBUFFER_EXT: |
| 1790 | bindDrawBuf = GL_TRUE; |
| 1791 | bindReadBuf = GL_TRUE; |
| 1792 | break; |
| 1793 | default: |
Brian Paul | eba4ff6 | 2005-09-06 21:22:16 +0000 | [diff] [blame] | 1794 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1795 | return; |
| 1796 | } |
| 1797 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1798 | if (framebuffer) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1799 | /* Binding a user-created framebuffer object */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1800 | newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer); |
| 1801 | if (newDrawFb == &DummyFramebuffer) { |
Brian Paul | 923b6fc | 2005-02-08 04:08:56 +0000 | [diff] [blame] | 1802 | /* ID was reserved, but no real framebuffer object made yet */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1803 | newDrawFb = NULL; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1804 | } |
Ian Romanick | a13f9df | 2012-12-01 10:50:57 -0800 | [diff] [blame] | 1805 | else if (!newDrawFb |
| 1806 | && _mesa_is_desktop_gl(ctx) |
| 1807 | && ctx->Extensions.ARB_framebuffer_object) { |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 1808 | /* All FBO IDs must be Gen'd */ |
| 1809 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)"); |
| 1810 | return; |
| 1811 | } |
| 1812 | |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1813 | if (!newDrawFb) { |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1814 | /* create new framebuffer object */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1815 | newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer); |
| 1816 | if (!newDrawFb) { |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1817 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT"); |
| 1818 | return; |
| 1819 | } |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1820 | _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1821 | } |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1822 | newReadFb = newDrawFb; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1823 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1824 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1825 | /* Binding the window system framebuffer (which was originally set |
| 1826 | * with MakeCurrent). |
| 1827 | */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1828 | newDrawFb = ctx->WinSysDrawBuffer; |
| 1829 | newReadFb = ctx->WinSysReadBuffer; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1832 | ASSERT(newDrawFb); |
| 1833 | ASSERT(newDrawFb != &DummyFramebuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1834 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1835 | /* save pointers to current/old framebuffers */ |
brian | d96e55f | 2009-11-10 15:50:22 -0700 | [diff] [blame] | 1836 | oldDrawFb = ctx->DrawBuffer; |
| 1837 | oldReadFb = ctx->ReadBuffer; |
| 1838 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1839 | /* check if really changing bindings */ |
| 1840 | if (oldDrawFb == newDrawFb) |
| 1841 | bindDrawBuf = GL_FALSE; |
| 1842 | if (oldReadFb == newReadFb) |
| 1843 | bindReadBuf = GL_FALSE; |
| 1844 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1845 | /* |
Brian Paul | 1614463 | 2009-02-26 14:49:24 -0700 | [diff] [blame] | 1846 | * OK, now bind the new Draw/Read framebuffers, if they're changing. |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1847 | * |
| 1848 | * We also check if we're beginning and/or ending render-to-texture. |
| 1849 | * When a framebuffer with texture attachments is unbound, call |
| 1850 | * ctx->Driver.FinishRenderTexture(). |
| 1851 | * When a framebuffer with texture attachments is bound, call |
| 1852 | * ctx->Driver.RenderTexture(). |
| 1853 | * |
| 1854 | * Note that if the ReadBuffer has texture attachments we don't consider |
| 1855 | * that a render-to-texture case. |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1856 | */ |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1857 | if (bindReadBuf) { |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1858 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
brian | bc569cd | 2009-11-10 16:00:35 -0700 | [diff] [blame] | 1859 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1860 | /* check if old readbuffer was render-to-texture */ |
| 1861 | check_end_texture_render(ctx, oldReadFb); |
| 1862 | |
| 1863 | _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb); |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | if (bindDrawBuf) { |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1867 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian | 32d86eb | 2007-08-16 18:52:48 +0100 | [diff] [blame] | 1868 | |
Eric Anholt | a1fd13f | 2012-02-10 12:05:16 -0800 | [diff] [blame] | 1869 | /* check if old framebuffer had any texture attachments */ |
| 1870 | if (oldDrawFb) |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1871 | check_end_texture_render(ctx, oldDrawFb); |
brian | bc569cd | 2009-11-10 16:00:35 -0700 | [diff] [blame] | 1872 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1873 | /* check if newly bound framebuffer has any texture attachments */ |
| 1874 | check_begin_texture_render(ctx, newDrawFb); |
| 1875 | |
| 1876 | _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb); |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1877 | } |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 1878 | |
Brian Paul | 1614463 | 2009-02-26 14:49:24 -0700 | [diff] [blame] | 1879 | if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) { |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1880 | ctx->Driver.BindFramebuffer(ctx, target, newDrawFb, newReadFb); |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 1881 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1885 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1886 | _mesa_DeleteFramebuffers(GLsizei n, const GLuint *framebuffers) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1887 | { |
| 1888 | GLint i; |
| 1889 | GET_CURRENT_CONTEXT(ctx); |
| 1890 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1891 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1892 | |
| 1893 | for (i = 0; i < n; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1894 | if (framebuffers[i] > 0) { |
| 1895 | struct gl_framebuffer *fb; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1896 | fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1897 | if (fb) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1898 | ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]); |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1899 | |
| 1900 | /* check if deleting currently bound framebuffer object */ |
Erik Wien | 68ca19a | 2010-01-26 13:19:30 -0700 | [diff] [blame] | 1901 | if (ctx->Extensions.EXT_framebuffer_blit) { |
| 1902 | /* separate draw/read binding points */ |
| 1903 | if (fb == ctx->DrawBuffer) { |
| 1904 | /* bind default */ |
| 1905 | ASSERT(fb->RefCount >= 2); |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1906 | _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0); |
Erik Wien | 68ca19a | 2010-01-26 13:19:30 -0700 | [diff] [blame] | 1907 | } |
| 1908 | if (fb == ctx->ReadBuffer) { |
| 1909 | /* bind default */ |
| 1910 | ASSERT(fb->RefCount >= 2); |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1911 | _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER_EXT, 0); |
Erik Wien | 68ca19a | 2010-01-26 13:19:30 -0700 | [diff] [blame] | 1912 | } |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1913 | } |
Erik Wien | 68ca19a | 2010-01-26 13:19:30 -0700 | [diff] [blame] | 1914 | else { |
| 1915 | /* only one binding point for read/draw buffers */ |
| 1916 | if (fb == ctx->DrawBuffer || fb == ctx->ReadBuffer) { |
| 1917 | /* bind default */ |
| 1918 | ASSERT(fb->RefCount >= 2); |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1919 | _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT, 0); |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 1920 | } |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1923 | /* remove from hash table immediately, to free the ID */ |
| 1924 | _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1925 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1926 | if (fb != &DummyFramebuffer) { |
| 1927 | /* But the object will not be freed until it's no longer |
| 1928 | * bound in any context. |
| 1929 | */ |
Brian Paul | d522944 | 2009-02-09 08:30:55 -0700 | [diff] [blame] | 1930 | _mesa_reference_framebuffer(&fb, NULL); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1931 | } |
| 1932 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1933 | } |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1938 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1939 | _mesa_GenFramebuffers(GLsizei n, GLuint *framebuffers) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1940 | { |
| 1941 | GET_CURRENT_CONTEXT(ctx); |
| 1942 | GLuint first; |
| 1943 | GLint i; |
| 1944 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1945 | if (n < 0) { |
| 1946 | _mesa_error(ctx, GL_INVALID_VALUE, "glGenFramebuffersEXT(n)"); |
| 1947 | return; |
| 1948 | } |
| 1949 | |
| 1950 | if (!framebuffers) |
| 1951 | return; |
| 1952 | |
| 1953 | first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n); |
| 1954 | |
| 1955 | for (i = 0; i < n; i++) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1956 | GLuint name = first + i; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1957 | framebuffers[i] = name; |
| 1958 | /* insert dummy placeholder into hash table */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1959 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1960 | _mesa_HashInsert(ctx->Shared->FrameBuffers, name, &DummyFramebuffer); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1961 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | |
| 1966 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1967 | GLenum GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 1968 | _mesa_CheckFramebufferStatus(GLenum target) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1969 | { |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1970 | struct gl_framebuffer *buffer; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1971 | GET_CURRENT_CONTEXT(ctx); |
| 1972 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1973 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1974 | |
Jordan Justen | 7f86785 | 2013-01-12 19:21:54 -0800 | [diff] [blame] | 1975 | if (MESA_VERBOSE & VERBOSE_API) |
| 1976 | _mesa_debug(ctx, "glCheckFramebufferStatus(%s)\n", |
| 1977 | _mesa_lookup_enum_by_nr(target)); |
| 1978 | |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 1979 | buffer = get_framebuffer_target(ctx, target); |
| 1980 | if (!buffer) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1981 | _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)"); |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 1982 | return 0; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 1985 | if (_mesa_is_winsys_fbo(buffer)) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1986 | /* The window system / default framebuffer is always complete */ |
| 1987 | return GL_FRAMEBUFFER_COMPLETE_EXT; |
| 1988 | } |
| 1989 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1990 | /* No need to flush here */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1991 | |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 1992 | if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) { |
| 1993 | _mesa_test_framebuffer_completeness(ctx, buffer); |
| 1994 | } |
| 1995 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1996 | return buffer->_Status; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 1999 | |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2000 | /** |
| 2001 | * Replicate the src attachment point. Used by framebuffer_texture() when |
| 2002 | * the same texture is attached at GL_DEPTH_ATTACHMENT and |
| 2003 | * GL_STENCIL_ATTACHMENT. |
| 2004 | */ |
| 2005 | static void |
| 2006 | reuse_framebuffer_texture_attachment(struct gl_framebuffer *fb, |
| 2007 | gl_buffer_index dst, |
| 2008 | gl_buffer_index src) |
| 2009 | { |
| 2010 | struct gl_renderbuffer_attachment *dst_att = &fb->Attachment[dst]; |
| 2011 | struct gl_renderbuffer_attachment *src_att = &fb->Attachment[src]; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2012 | |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2013 | assert(src_att->Texture != NULL); |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 2014 | assert(src_att->Renderbuffer != NULL); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2015 | |
| 2016 | _mesa_reference_texobj(&dst_att->Texture, src_att->Texture); |
| 2017 | _mesa_reference_renderbuffer(&dst_att->Renderbuffer, src_att->Renderbuffer); |
| 2018 | dst_att->Type = src_att->Type; |
| 2019 | dst_att->Complete = src_att->Complete; |
| 2020 | dst_att->TextureLevel = src_att->TextureLevel; |
| 2021 | dst_att->Zoffset = src_att->Zoffset; |
| 2022 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2023 | |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 2024 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2025 | /** |
Brian Paul | 534cbbe | 2012-03-12 11:03:59 -0600 | [diff] [blame] | 2026 | * Common code called by glFramebufferTexture1D/2D/3DEXT() and |
| 2027 | * glFramebufferTextureLayerEXT(). |
| 2028 | * Note: glFramebufferTextureLayerEXT() has no textarget parameter so we'll |
| 2029 | * get textarget=0 in that case. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2030 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2031 | static void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 2032 | framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2033 | GLenum attachment, GLenum textarget, GLuint texture, |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2034 | GLint level, GLint zoffset) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2035 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 2036 | struct gl_renderbuffer_attachment *att; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2037 | struct gl_texture_object *texObj = NULL; |
| 2038 | struct gl_framebuffer *fb; |
Anuj Phogat | cc5b0ff | 2012-03-12 10:39:48 -0700 | [diff] [blame] | 2039 | GLenum maxLevelsTarget; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2040 | |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 2041 | fb = get_framebuffer_target(ctx, target); |
| 2042 | if (!fb) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2043 | _mesa_error(ctx, GL_INVALID_ENUM, |
Brian Paul | 5fec84a | 2009-01-29 15:01:09 -0700 | [diff] [blame] | 2044 | "glFramebufferTexture%sEXT(target=0x%x)", caller, target); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2045 | return; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2046 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2047 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2048 | /* check framebuffer binding */ |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 2049 | if (_mesa_is_winsys_fbo(fb)) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2050 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2051 | "glFramebufferTexture%sEXT", caller); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2052 | return; |
| 2053 | } |
| 2054 | |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2055 | /* The textarget, level, and zoffset parameters are only validated if |
| 2056 | * texture is non-zero. |
| 2057 | */ |
| 2058 | if (texture) { |
| 2059 | GLboolean err = GL_TRUE; |
| 2060 | |
| 2061 | texObj = _mesa_lookup_texture(ctx, texture); |
| 2062 | if (texObj != NULL) { |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 2063 | if (textarget == 0) { |
Brian Paul | 534cbbe | 2012-03-12 11:03:59 -0600 | [diff] [blame] | 2064 | /* If textarget == 0 it means we're being called by |
| 2065 | * glFramebufferTextureLayer() and textarget is not used. |
| 2066 | * The only legal texture types for that function are 3D and |
| 2067 | * 1D/2D arrays textures. |
| 2068 | */ |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 2069 | err = (texObj->Target != GL_TEXTURE_3D) && |
| 2070 | (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT) && |
Dave Airlie | e0e7e29 | 2012-11-03 20:41:08 +1000 | [diff] [blame] | 2071 | (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT) && |
| 2072 | (texObj->Target != GL_TEXTURE_CUBE_MAP_ARRAY); |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 2073 | } |
| 2074 | else { |
Brian Paul | 534cbbe | 2012-03-12 11:03:59 -0600 | [diff] [blame] | 2075 | /* Make sure textarget is consistent with the texture's type */ |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 2076 | err = (texObj->Target == GL_TEXTURE_CUBE_MAP) |
Brian Paul | 2efa3d4 | 2011-11-18 17:39:00 -0700 | [diff] [blame] | 2077 | ? !_mesa_is_cube_face(textarget) |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 2078 | : (texObj->Target != textarget); |
| 2079 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2080 | } |
Brian Paul | 7a2e32d | 2010-03-10 10:54:24 -0700 | [diff] [blame] | 2081 | else { |
| 2082 | /* can't render to a non-existant texture */ |
| 2083 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2084 | "glFramebufferTexture%sEXT(non existant texture)", |
| 2085 | caller); |
| 2086 | return; |
| 2087 | } |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2088 | |
| 2089 | if (err) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2090 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2091 | "glFramebufferTexture%sEXT(texture target mismatch)", |
| 2092 | caller); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2093 | return; |
| 2094 | } |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2095 | |
| 2096 | if (texObj->Target == GL_TEXTURE_3D) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2097 | const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); |
| 2098 | if (zoffset < 0 || zoffset >= maxSize) { |
| 2099 | _mesa_error(ctx, GL_INVALID_VALUE, |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 2100 | "glFramebufferTexture%sEXT(zoffset)", caller); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2101 | return; |
| 2102 | } |
| 2103 | } |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 2104 | else if ((texObj->Target == GL_TEXTURE_1D_ARRAY_EXT) || |
Dave Airlie | e0e7e29 | 2012-11-03 20:41:08 +1000 | [diff] [blame] | 2105 | (texObj->Target == GL_TEXTURE_2D_ARRAY_EXT) || |
| 2106 | (texObj->Target == GL_TEXTURE_CUBE_MAP_ARRAY)) { |
Brian Paul | 859c387 | 2012-11-04 16:43:44 -0700 | [diff] [blame] | 2107 | if (zoffset < 0 || |
| 2108 | zoffset >= (GLint) ctx->Const.MaxArrayTextureLayers) { |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 2109 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 2110 | "glFramebufferTexture%sEXT(layer)", caller); |
| 2111 | return; |
| 2112 | } |
| 2113 | } |
| 2114 | |
Anuj Phogat | cc5b0ff | 2012-03-12 10:39:48 -0700 | [diff] [blame] | 2115 | maxLevelsTarget = textarget ? textarget : texObj->Target; |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 2116 | if ((level < 0) || |
Anuj Phogat | cc5b0ff | 2012-03-12 10:39:48 -0700 | [diff] [blame] | 2117 | (level >= _mesa_max_texture_levels(ctx, maxLevelsTarget))) { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2118 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 2119 | "glFramebufferTexture%sEXT(level)", caller); |
| 2120 | return; |
| 2121 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | att = _mesa_get_attachment(ctx, fb, attachment); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2125 | if (att == NULL) { |
| 2126 | _mesa_error(ctx, GL_INVALID_ENUM, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2127 | "glFramebufferTexture%sEXT(attachment)", caller); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2128 | return; |
| 2129 | } |
| 2130 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 2131 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 2132 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2133 | _glthread_LOCK_MUTEX(fb->Mutex); |
| 2134 | if (texObj) { |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2135 | if (attachment == GL_DEPTH_ATTACHMENT && |
Paul Berry | b9819a0 | 2012-04-13 21:50:08 -0700 | [diff] [blame] | 2136 | texObj == fb->Attachment[BUFFER_STENCIL].Texture && |
| 2137 | level == fb->Attachment[BUFFER_STENCIL].TextureLevel && |
| 2138 | _mesa_tex_target_to_face(textarget) == |
| 2139 | fb->Attachment[BUFFER_STENCIL].CubeMapFace && |
| 2140 | zoffset == fb->Attachment[BUFFER_STENCIL].Zoffset) { |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2141 | /* The texture object is already attached to the stencil attachment |
| 2142 | * point. Don't create a new renderbuffer; just reuse the stencil |
| 2143 | * attachment's. This is required to prevent a GL error in |
| 2144 | * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL). |
| 2145 | */ |
| 2146 | reuse_framebuffer_texture_attachment(fb, BUFFER_DEPTH, |
| 2147 | BUFFER_STENCIL); |
| 2148 | } else if (attachment == GL_STENCIL_ATTACHMENT && |
Paul Berry | b9819a0 | 2012-04-13 21:50:08 -0700 | [diff] [blame] | 2149 | texObj == fb->Attachment[BUFFER_DEPTH].Texture && |
| 2150 | level == fb->Attachment[BUFFER_DEPTH].TextureLevel && |
| 2151 | _mesa_tex_target_to_face(textarget) == |
| 2152 | fb->Attachment[BUFFER_DEPTH].CubeMapFace && |
| 2153 | zoffset == fb->Attachment[BUFFER_DEPTH].Zoffset) { |
| 2154 | /* As above, but with depth and stencil transposed. */ |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2155 | reuse_framebuffer_texture_attachment(fb, BUFFER_STENCIL, |
| 2156 | BUFFER_DEPTH); |
| 2157 | } else { |
| 2158 | _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget, |
| 2159 | level, zoffset); |
| 2160 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 2161 | /* Above we created a new renderbuffer and attached it to the |
| 2162 | * depth attachment point. Now attach it to the stencil attachment |
| 2163 | * point too. |
| 2164 | */ |
| 2165 | assert(att == &fb->Attachment[BUFFER_DEPTH]); |
| 2166 | reuse_framebuffer_texture_attachment(fb,BUFFER_STENCIL, |
| 2167 | BUFFER_DEPTH); |
| 2168 | } |
| 2169 | } |
| 2170 | |
Brian Paul | 2897cee | 2009-01-29 09:20:18 -0700 | [diff] [blame] | 2171 | /* Set the render-to-texture flag. We'll check this flag in |
| 2172 | * glTexImage() and friends to determine if we need to revalidate |
| 2173 | * any FBOs that might be rendering into this texture. |
| 2174 | * This flag never gets cleared since it's non-trivial to determine |
| 2175 | * when all FBOs might be done rendering to this texture. That's OK |
| 2176 | * though since it's uncommon to render to a texture then repeatedly |
| 2177 | * call glTexImage() to change images in the texture. |
| 2178 | */ |
| 2179 | texObj->_RenderToTexture = GL_TRUE; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2180 | } |
| 2181 | else { |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 2182 | _mesa_remove_attachment(ctx, att); |
Chad Versace | bf8ad17 | 2011-11-10 10:19:20 -0800 | [diff] [blame] | 2183 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 2184 | assert(att == &fb->Attachment[BUFFER_DEPTH]); |
| 2185 | _mesa_remove_attachment(ctx, &fb->Attachment[BUFFER_STENCIL]); |
| 2186 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2187 | } |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 2188 | |
| 2189 | invalidate_framebuffer(fb); |
| 2190 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2191 | _glthread_UNLOCK_MUTEX(fb->Mutex); |
| 2192 | } |
| 2193 | |
| 2194 | |
| 2195 | |
| 2196 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2197 | _mesa_FramebufferTexture1D(GLenum target, GLenum attachment, |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2198 | GLenum textarget, GLuint texture, GLint level) |
| 2199 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2200 | GET_CURRENT_CONTEXT(ctx); |
| 2201 | |
Brian Paul | 352cab4 | 2011-08-18 14:35:27 -0600 | [diff] [blame] | 2202 | if (texture != 0) { |
| 2203 | GLboolean error; |
| 2204 | |
| 2205 | switch (textarget) { |
| 2206 | case GL_TEXTURE_1D: |
| 2207 | error = GL_FALSE; |
| 2208 | break; |
Brian Paul | 3e9dc51 | 2011-08-18 15:59:33 -0600 | [diff] [blame] | 2209 | case GL_TEXTURE_1D_ARRAY: |
| 2210 | error = !ctx->Extensions.EXT_texture_array; |
| 2211 | break; |
Brian Paul | 352cab4 | 2011-08-18 14:35:27 -0600 | [diff] [blame] | 2212 | default: |
| 2213 | error = GL_TRUE; |
| 2214 | } |
| 2215 | |
| 2216 | if (error) { |
| 2217 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2218 | "glFramebufferTexture1DEXT(textarget=%s)", |
| 2219 | _mesa_lookup_enum_by_nr(textarget)); |
| 2220 | return; |
| 2221 | } |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | framebuffer_texture(ctx, "1D", target, attachment, textarget, texture, |
| 2225 | level, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2229 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2230 | _mesa_FramebufferTexture2D(GLenum target, GLenum attachment, |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2231 | GLenum textarget, GLuint texture, GLint level) |
| 2232 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2233 | GET_CURRENT_CONTEXT(ctx); |
| 2234 | |
Brian Paul | 352cab4 | 2011-08-18 14:35:27 -0600 | [diff] [blame] | 2235 | if (texture != 0) { |
| 2236 | GLboolean error; |
| 2237 | |
| 2238 | switch (textarget) { |
| 2239 | case GL_TEXTURE_2D: |
| 2240 | error = GL_FALSE; |
| 2241 | break; |
| 2242 | case GL_TEXTURE_RECTANGLE: |
Ian Romanick | 7f991d2 | 2012-07-27 07:22:41 -0700 | [diff] [blame] | 2243 | error = _mesa_is_gles(ctx) |
| 2244 | || !ctx->Extensions.NV_texture_rectangle; |
Brian Paul | 352cab4 | 2011-08-18 14:35:27 -0600 | [diff] [blame] | 2245 | break; |
| 2246 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 2247 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 2248 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 2249 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 2250 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 2251 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 2252 | error = !ctx->Extensions.ARB_texture_cube_map; |
| 2253 | break; |
Brian Paul | 3e9dc51 | 2011-08-18 15:59:33 -0600 | [diff] [blame] | 2254 | case GL_TEXTURE_2D_ARRAY: |
Ian Romanick | 7f991d2 | 2012-07-27 07:22:41 -0700 | [diff] [blame] | 2255 | error = (_mesa_is_gles(ctx) && ctx->Version < 30) |
| 2256 | || !ctx->Extensions.EXT_texture_array; |
Brian Paul | 3e9dc51 | 2011-08-18 15:59:33 -0600 | [diff] [blame] | 2257 | break; |
Brian Paul | 352cab4 | 2011-08-18 14:35:27 -0600 | [diff] [blame] | 2258 | default: |
Chia-I Wu | d8ba30a | 2011-10-22 22:17:31 +0800 | [diff] [blame] | 2259 | error = GL_TRUE; |
Brian Paul | 352cab4 | 2011-08-18 14:35:27 -0600 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | if (error) { |
| 2263 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2264 | "glFramebufferTexture2DEXT(textarget=%s)", |
| 2265 | _mesa_lookup_enum_by_nr(textarget)); |
| 2266 | return; |
| 2267 | } |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | framebuffer_texture(ctx, "2D", target, attachment, textarget, texture, |
| 2271 | level, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2275 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2276 | _mesa_FramebufferTexture3D(GLenum target, GLenum attachment, |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2277 | GLenum textarget, GLuint texture, |
| 2278 | GLint level, GLint zoffset) |
| 2279 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2280 | GET_CURRENT_CONTEXT(ctx); |
| 2281 | |
| 2282 | if ((texture != 0) && (textarget != GL_TEXTURE_3D)) { |
Brian Paul | ccecc08 | 2011-08-18 11:51:48 -0600 | [diff] [blame] | 2283 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 2284 | "glFramebufferTexture3DEXT(textarget)"); |
| 2285 | return; |
| 2286 | } |
| 2287 | |
| 2288 | framebuffer_texture(ctx, "3D", target, attachment, textarget, texture, |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2289 | level, zoffset); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2293 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2294 | _mesa_FramebufferTextureLayer(GLenum target, GLenum attachment, |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 2295 | GLuint texture, GLint level, GLint layer) |
| 2296 | { |
| 2297 | GET_CURRENT_CONTEXT(ctx); |
| 2298 | |
| 2299 | framebuffer_texture(ctx, "Layer", target, attachment, 0, texture, |
| 2300 | level, layer); |
| 2301 | } |
| 2302 | |
| 2303 | |
| 2304 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2305 | _mesa_FramebufferRenderbuffer(GLenum target, GLenum attachment, |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2306 | GLenum renderbufferTarget, |
| 2307 | GLuint renderbuffer) |
| 2308 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 2309 | struct gl_renderbuffer_attachment *att; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2310 | struct gl_framebuffer *fb; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 2311 | struct gl_renderbuffer *rb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2312 | GET_CURRENT_CONTEXT(ctx); |
| 2313 | |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 2314 | fb = get_framebuffer_target(ctx, target); |
| 2315 | if (!fb) { |
| 2316 | _mesa_error(ctx, GL_INVALID_ENUM, "glFramebufferRenderbufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2317 | return; |
| 2318 | } |
| 2319 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2320 | if (renderbufferTarget != GL_RENDERBUFFER_EXT) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 2321 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2322 | "glFramebufferRenderbufferEXT(renderbufferTarget)"); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2323 | return; |
| 2324 | } |
| 2325 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 2326 | if (_mesa_is_winsys_fbo(fb)) { |
Brian Paul | ab8ef28 | 2005-09-07 23:21:59 +0000 | [diff] [blame] | 2327 | /* Can't attach new renderbuffers to a window system framebuffer */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2328 | _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT"); |
| 2329 | return; |
| 2330 | } |
| 2331 | |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 2332 | att = _mesa_get_attachment(ctx, fb, attachment); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2333 | if (att == NULL) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2334 | _mesa_error(ctx, GL_INVALID_ENUM, |
Brian Paul | 9b50cea | 2009-10-23 11:34:14 -0600 | [diff] [blame] | 2335 | "glFramebufferRenderbufferEXT(invalid attachment %s)", |
| 2336 | _mesa_lookup_enum_by_nr(attachment)); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2337 | return; |
| 2338 | } |
| 2339 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2340 | if (renderbuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 2341 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2342 | if (!rb) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 2343 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Brian Paul | 9b50cea | 2009-10-23 11:34:14 -0600 | [diff] [blame] | 2344 | "glFramebufferRenderbufferEXT(non-existant" |
| 2345 | " renderbuffer %u)", renderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2346 | return; |
| 2347 | } |
Brian Paul | dd973cd | 2011-01-12 18:14:14 -0700 | [diff] [blame] | 2348 | else if (rb == &DummyRenderbuffer) { |
| 2349 | /* This is what NVIDIA does */ |
| 2350 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 2351 | "glFramebufferRenderbufferEXT(renderbuffer %u)", |
| 2352 | renderbuffer); |
| 2353 | return; |
| 2354 | } |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2355 | } |
| 2356 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 2357 | /* remove renderbuffer attachment */ |
| 2358 | rb = NULL; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2359 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 2360 | |
Brian Paul | a504f23 | 2010-05-27 13:05:23 -0600 | [diff] [blame] | 2361 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT && |
| 2362 | rb && rb->Format != MESA_FORMAT_NONE) { |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 2363 | /* make sure the renderbuffer is a depth/stencil format */ |
Brian Paul | a504f23 | 2010-05-27 13:05:23 -0600 | [diff] [blame] | 2364 | const GLenum baseFormat = _mesa_get_format_base_format(rb->Format); |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2365 | if (baseFormat != GL_DEPTH_STENCIL) { |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 2366 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2367 | "glFramebufferRenderbufferEXT(renderbuffer" |
| 2368 | " is not DEPTH_STENCIL format)"); |
| 2369 | return; |
| 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 2374 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 2375 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 2376 | assert(ctx->Driver.FramebufferRenderbuffer); |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 2377 | ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb); |
Brian Paul | 2e01918 | 2006-03-07 01:43:52 +0000 | [diff] [blame] | 2378 | |
| 2379 | /* Some subsequent GL commands may depend on the framebuffer's visual |
| 2380 | * after the binding is updated. Update visual info now. |
| 2381 | */ |
Eric Anholt | 059cca9 | 2011-01-02 17:58:07 -0800 | [diff] [blame] | 2382 | _mesa_update_framebuffer_visual(ctx, fb); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2386 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2387 | _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2388 | GLenum pname, GLint *params) |
| 2389 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 2390 | const struct gl_renderbuffer_attachment *att; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2391 | struct gl_framebuffer *buffer; |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 2392 | GLenum err; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2393 | GET_CURRENT_CONTEXT(ctx); |
| 2394 | |
Brian Paul | dbe8851 | 2012-02-10 16:22:33 -0700 | [diff] [blame] | 2395 | /* The error differs in GL and GLES. */ |
Jordan Justen | 09714c0 | 2012-07-19 11:27:16 -0700 | [diff] [blame] | 2396 | err = _mesa_is_desktop_gl(ctx) ? GL_INVALID_OPERATION : GL_INVALID_ENUM; |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 2397 | |
Brian Paul | c699143 | 2011-02-28 18:24:25 -0700 | [diff] [blame] | 2398 | buffer = get_framebuffer_target(ctx, target); |
| 2399 | if (!buffer) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2400 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2401 | "glGetFramebufferAttachmentParameterivEXT(target)"); |
| 2402 | return; |
| 2403 | } |
| 2404 | |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 2405 | if (_mesa_is_winsys_fbo(buffer)) { |
Ian Romanick | da2e41c | 2011-10-03 12:04:09 -0700 | [diff] [blame] | 2406 | /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec |
| 2407 | * says: |
| 2408 | * |
| 2409 | * "If the framebuffer currently bound to target is zero, then |
| 2410 | * INVALID_OPERATION is generated." |
| 2411 | * |
| 2412 | * The EXT_framebuffer_object spec has the same wording, and the |
| 2413 | * OES_framebuffer_object spec refers to the EXT_framebuffer_object |
| 2414 | * spec. |
| 2415 | */ |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 2416 | if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_framebuffer_object) |
| 2417 | && !_mesa_is_gles3(ctx)) { |
Ian Romanick | da2e41c | 2011-10-03 12:04:09 -0700 | [diff] [blame] | 2418 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2419 | "glGetFramebufferAttachmentParameteriv(bound FBO = 0)"); |
| 2420 | return; |
| 2421 | } |
Anuj Phogat | 2f2801f | 2012-12-11 20:08:13 -0800 | [diff] [blame] | 2422 | |
| 2423 | if (_mesa_is_gles3(ctx) && attachment != GL_BACK && |
| 2424 | attachment != GL_DEPTH && attachment != GL_STENCIL) { |
| 2425 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2426 | "glGetFramebufferAttachmentParameteriv(attachment)"); |
| 2427 | return; |
| 2428 | } |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 2429 | /* the default / window-system FBO */ |
| 2430 | att = _mesa_get_fb0_attachment(ctx, buffer, attachment); |
| 2431 | } |
| 2432 | else { |
| 2433 | /* user-created framebuffer FBO */ |
| 2434 | att = _mesa_get_attachment(ctx, buffer, attachment); |
| 2435 | } |
| 2436 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2437 | if (att == NULL) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2438 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2439 | "glGetFramebufferAttachmentParameterivEXT(attachment)"); |
| 2440 | return; |
| 2441 | } |
| 2442 | |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 2443 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 2444 | /* the depth and stencil attachments must point to the same buffer */ |
| 2445 | const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt; |
| 2446 | depthAtt = _mesa_get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT); |
| 2447 | stencilAtt = _mesa_get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT); |
| 2448 | if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) { |
| 2449 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2450 | "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL" |
| 2451 | " attachments differ)"); |
| 2452 | return; |
| 2453 | } |
| 2454 | } |
| 2455 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 2456 | /* No need to flush here */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 2457 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2458 | switch (pname) { |
| 2459 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT: |
Brian Paul | 36ede89 | 2012-01-12 09:17:23 -0700 | [diff] [blame] | 2460 | *params = _mesa_is_winsys_fbo(buffer) |
| 2461 | ? GL_FRAMEBUFFER_DEFAULT : att->Type; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2462 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2463 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2464 | if (att->Type == GL_RENDERBUFFER_EXT) { |
| 2465 | *params = att->Renderbuffer->Name; |
| 2466 | } |
| 2467 | else if (att->Type == GL_TEXTURE) { |
| 2468 | *params = att->Texture->Name; |
| 2469 | } |
| 2470 | else { |
Brian Paul | 20cf185 | 2010-12-03 08:23:31 -0700 | [diff] [blame] | 2471 | assert(att->Type == GL_NONE); |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2472 | if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) { |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 2473 | *params = 0; |
| 2474 | } else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2475 | goto invalid_pname_enum; |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 2476 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2477 | } |
| 2478 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2479 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2480 | if (att->Type == GL_TEXTURE) { |
| 2481 | *params = att->TextureLevel; |
| 2482 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2483 | else if (att->Type == GL_NONE) { |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 2484 | _mesa_error(ctx, err, |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2485 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2486 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2487 | else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2488 | goto invalid_pname_enum; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2489 | } |
| 2490 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2491 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2492 | if (att->Type == GL_TEXTURE) { |
Brian Paul | f1e4ca7 | 2008-08-06 08:39:54 -0600 | [diff] [blame] | 2493 | if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) { |
| 2494 | *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace; |
| 2495 | } |
| 2496 | else { |
| 2497 | *params = 0; |
| 2498 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2499 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2500 | else if (att->Type == GL_NONE) { |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 2501 | _mesa_error(ctx, err, |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2502 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2503 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2504 | else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2505 | goto invalid_pname_enum; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2506 | } |
| 2507 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2508 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT: |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2509 | if (ctx->API == API_OPENGLES) { |
| 2510 | goto invalid_pname_enum; |
| 2511 | } else if (att->Type == GL_NONE) { |
| 2512 | _mesa_error(ctx, err, |
| 2513 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2514 | } else if (att->Type == GL_TEXTURE) { |
Brian Paul | f1e4ca7 | 2008-08-06 08:39:54 -0600 | [diff] [blame] | 2515 | if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) { |
| 2516 | *params = att->Zoffset; |
| 2517 | } |
| 2518 | else { |
| 2519 | *params = 0; |
| 2520 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2521 | } |
| 2522 | else { |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2523 | goto invalid_pname_enum; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2524 | } |
| 2525 | return; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2526 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2527 | if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_framebuffer_object) |
| 2528 | && !_mesa_is_gles3(ctx)) { |
| 2529 | goto invalid_pname_enum; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2530 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2531 | else if (att->Type == GL_NONE) { |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 2532 | _mesa_error(ctx, err, |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2533 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2534 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2535 | else { |
Marek Olšák | 69c8f46 | 2012-01-24 23:39:31 +0100 | [diff] [blame] | 2536 | if (ctx->Extensions.EXT_framebuffer_sRGB) { |
Marek Olšák | 81ae8c6 | 2011-01-23 13:26:43 +0100 | [diff] [blame] | 2537 | *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format); |
| 2538 | } |
| 2539 | else { |
| 2540 | /* According to ARB_framebuffer_sRGB, we should return LINEAR |
| 2541 | * if the sRGB conversion is unsupported. */ |
| 2542 | *params = GL_LINEAR; |
| 2543 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2544 | } |
| 2545 | return; |
| 2546 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 2547 | if ((ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_framebuffer_object) |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2548 | && ctx->API != API_OPENGL_CORE |
| 2549 | && !_mesa_is_gles3(ctx)) { |
| 2550 | goto invalid_pname_enum; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2551 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2552 | else if (att->Type == GL_NONE) { |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 2553 | _mesa_error(ctx, err, |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2554 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2555 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2556 | else { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2557 | gl_format format = att->Renderbuffer->Format; |
Ian Romanick | d7475c7 | 2013-01-18 17:25:57 -0800 | [diff] [blame^] | 2558 | |
| 2559 | /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES |
| 2560 | * 3.0.1 spec says: |
| 2561 | * |
| 2562 | * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If |
| 2563 | * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and |
| 2564 | * generate an INVALID_OPERATION error. |
| 2565 | */ |
| 2566 | if (_mesa_is_gles3(ctx) && attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 2567 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2568 | "glGetFramebufferAttachmentParameteriv(cannot query " |
| 2569 | "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of " |
| 2570 | "GL_DEPTH_STENCIL_ATTACHMENT"); |
| 2571 | return; |
| 2572 | } |
| 2573 | |
Ian Romanick | 55d232a | 2011-08-26 12:20:00 -0700 | [diff] [blame] | 2574 | if (format == MESA_FORMAT_S8) { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2575 | /* special cases */ |
| 2576 | *params = GL_INDEX; |
| 2577 | } |
Marek Olšák | 1165280 | 2011-06-01 15:48:51 +0200 | [diff] [blame] | 2578 | else if (format == MESA_FORMAT_Z32_FLOAT_X24S8) { |
| 2579 | /* depends on the attachment parameter */ |
| 2580 | if (attachment == GL_STENCIL_ATTACHMENT) { |
| 2581 | *params = GL_INDEX; |
| 2582 | } |
| 2583 | else { |
| 2584 | *params = GL_FLOAT; |
| 2585 | } |
| 2586 | } |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2587 | else { |
| 2588 | *params = _mesa_get_format_datatype(format); |
| 2589 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2590 | } |
| 2591 | return; |
| 2592 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2593 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2594 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2595 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2596 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2597 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2598 | if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_framebuffer_object) |
| 2599 | && !_mesa_is_gles3(ctx)) { |
| 2600 | goto invalid_pname_enum; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2601 | } |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2602 | else if (att->Type == GL_NONE) { |
Marek Olšák | 000896c | 2011-07-19 03:05:07 +0200 | [diff] [blame] | 2603 | _mesa_error(ctx, err, |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2604 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2605 | } |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2606 | else if (att->Texture) { |
| 2607 | const struct gl_texture_image *texImage = |
| 2608 | _mesa_select_tex_image(ctx, att->Texture, att->Texture->Target, |
| 2609 | att->TextureLevel); |
| 2610 | if (texImage) { |
| 2611 | *params = get_component_bits(pname, texImage->_BaseFormat, |
| 2612 | texImage->TexFormat); |
| 2613 | } |
| 2614 | else { |
| 2615 | *params = 0; |
| 2616 | } |
| 2617 | } |
| 2618 | else if (att->Renderbuffer) { |
| 2619 | *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat, |
| 2620 | att->Renderbuffer->Format); |
| 2621 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2622 | else { |
Marek Olšák | b9e9df7 | 2011-05-31 20:36:07 +0200 | [diff] [blame] | 2623 | _mesa_problem(ctx, "glGetFramebufferAttachmentParameterivEXT:" |
| 2624 | " invalid FBO attachment structure"); |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2625 | } |
| 2626 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2627 | default: |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2628 | goto invalid_pname_enum; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2629 | } |
Ian Romanick | 0cdaa47 | 2012-07-27 07:47:28 -0700 | [diff] [blame] | 2630 | |
| 2631 | return; |
| 2632 | |
| 2633 | invalid_pname_enum: |
| 2634 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2635 | "glGetFramebufferAttachmentParameteriv(pname)"); |
| 2636 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2640 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2641 | _mesa_GenerateMipmap(GLenum target) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2642 | { |
Eric Anholt | f80e1e7 | 2011-10-18 11:52:39 -0700 | [diff] [blame] | 2643 | struct gl_texture_image *srcImage; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2644 | struct gl_texture_object *texObj; |
Brian Paul | 3e9dc51 | 2011-08-18 15:59:33 -0600 | [diff] [blame] | 2645 | GLboolean error; |
| 2646 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2647 | GET_CURRENT_CONTEXT(ctx); |
| 2648 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 2649 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2650 | |
| 2651 | switch (target) { |
| 2652 | case GL_TEXTURE_1D: |
Ian Romanick | 5b44a77 | 2012-07-27 07:24:37 -0700 | [diff] [blame] | 2653 | error = _mesa_is_gles(ctx); |
| 2654 | break; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2655 | case GL_TEXTURE_2D: |
Brian Paul | 3e9dc51 | 2011-08-18 15:59:33 -0600 | [diff] [blame] | 2656 | error = GL_FALSE; |
| 2657 | break; |
Ian Romanick | 5b44a77 | 2012-07-27 07:24:37 -0700 | [diff] [blame] | 2658 | case GL_TEXTURE_3D: |
| 2659 | error = ctx->API == API_OPENGLES; |
| 2660 | break; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2661 | case GL_TEXTURE_CUBE_MAP: |
Brian Paul | 3e9dc51 | 2011-08-18 15:59:33 -0600 | [diff] [blame] | 2662 | error = !ctx->Extensions.ARB_texture_cube_map; |
| 2663 | break; |
| 2664 | case GL_TEXTURE_1D_ARRAY: |
Ian Romanick | 5b44a77 | 2012-07-27 07:24:37 -0700 | [diff] [blame] | 2665 | error = _mesa_is_gles(ctx) || !ctx->Extensions.EXT_texture_array; |
| 2666 | break; |
Brian Paul | 3e9dc51 | 2011-08-18 15:59:33 -0600 | [diff] [blame] | 2667 | case GL_TEXTURE_2D_ARRAY: |
Ian Romanick | 5b44a77 | 2012-07-27 07:24:37 -0700 | [diff] [blame] | 2668 | error = (_mesa_is_gles(ctx) && ctx->Version < 30) |
| 2669 | || !ctx->Extensions.EXT_texture_array; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2670 | break; |
| 2671 | default: |
Brian Paul | 3e9dc51 | 2011-08-18 15:59:33 -0600 | [diff] [blame] | 2672 | error = GL_TRUE; |
| 2673 | } |
| 2674 | |
| 2675 | if (error) { |
| 2676 | _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target=%s)", |
| 2677 | _mesa_lookup_enum_by_nr(target)); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2678 | return; |
| 2679 | } |
| 2680 | |
Brian Paul | a719395 | 2009-11-16 08:21:28 -0700 | [diff] [blame] | 2681 | texObj = _mesa_get_current_tex_object(ctx, target); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2682 | |
Brian Paul | 652828e | 2009-11-16 08:25:17 -0700 | [diff] [blame] | 2683 | if (texObj->BaseLevel >= texObj->MaxLevel) { |
| 2684 | /* nothing to do */ |
| 2685 | return; |
| 2686 | } |
| 2687 | |
Brian Paul | ecb7cc3 | 2010-12-06 15:11:41 -0700 | [diff] [blame] | 2688 | if (texObj->Target == GL_TEXTURE_CUBE_MAP && |
| 2689 | !_mesa_cube_complete(texObj)) { |
| 2690 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2691 | "glGenerateMipmap(incomplete cube map)"); |
| 2692 | return; |
| 2693 | } |
| 2694 | |
Keith Whitwell | 5ac93f8 | 2006-11-01 14:21:57 +0000 | [diff] [blame] | 2695 | _mesa_lock_texture(ctx, texObj); |
Eric Anholt | f80e1e7 | 2011-10-18 11:52:39 -0700 | [diff] [blame] | 2696 | |
| 2697 | srcImage = _mesa_select_tex_image(ctx, texObj, target, texObj->BaseLevel); |
| 2698 | if (!srcImage) { |
| 2699 | _mesa_unlock_texture(ctx, texObj); |
Brian Paul | f6b7157 | 2012-08-10 10:36:17 -0600 | [diff] [blame] | 2700 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2701 | "glGenerateMipmap(zero size base image)"); |
Eric Anholt | f80e1e7 | 2011-10-18 11:52:39 -0700 | [diff] [blame] | 2702 | return; |
| 2703 | } |
| 2704 | |
Anuj Phogat | c0a78d7 | 2012-11-02 10:47:33 -0700 | [diff] [blame] | 2705 | if (_mesa_is_enum_format_integer(srcImage->InternalFormat) || |
| 2706 | _mesa_is_depthstencil_format(srcImage->InternalFormat) || |
| 2707 | _mesa_is_stencil_format(srcImage->InternalFormat)) { |
| 2708 | _mesa_unlock_texture(ctx, texObj); |
| 2709 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2710 | "glGenerateMipmap(invalid internal format)"); |
| 2711 | return; |
| 2712 | } |
| 2713 | |
Eric Anholt | f849d36 | 2008-12-06 21:14:56 -0800 | [diff] [blame] | 2714 | if (target == GL_TEXTURE_CUBE_MAP) { |
Brian Paul | ef6ee07 | 2009-09-15 18:09:03 -0600 | [diff] [blame] | 2715 | GLuint face; |
Eric Anholt | f849d36 | 2008-12-06 21:14:56 -0800 | [diff] [blame] | 2716 | for (face = 0; face < 6; face++) |
| 2717 | ctx->Driver.GenerateMipmap(ctx, |
| 2718 | GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face, |
| 2719 | texObj); |
Brian Paul | ef6ee07 | 2009-09-15 18:09:03 -0600 | [diff] [blame] | 2720 | } |
| 2721 | else { |
Eric Anholt | f849d36 | 2008-12-06 21:14:56 -0800 | [diff] [blame] | 2722 | ctx->Driver.GenerateMipmap(ctx, target, texObj); |
| 2723 | } |
Keith Whitwell | 5ac93f8 | 2006-11-01 14:21:57 +0000 | [diff] [blame] | 2724 | _mesa_unlock_texture(ctx, texObj); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2725 | } |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2726 | |
| 2727 | |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2728 | static const struct gl_renderbuffer_attachment * |
Brian Paul | b3cfcdf | 2011-01-28 20:25:26 -0700 | [diff] [blame] | 2729 | find_attachment(const struct gl_framebuffer *fb, |
| 2730 | const struct gl_renderbuffer *rb) |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2731 | { |
| 2732 | GLuint i; |
| 2733 | for (i = 0; i < Elements(fb->Attachment); i++) { |
| 2734 | if (fb->Attachment[i].Renderbuffer == rb) |
| 2735 | return &fb->Attachment[i]; |
| 2736 | } |
| 2737 | return NULL; |
| 2738 | } |
| 2739 | |
| 2740 | |
Brian Paul | 9b11170 | 2012-01-09 12:38:49 -0700 | [diff] [blame] | 2741 | /** |
| 2742 | * Helper function for checking if the datatypes of color buffers are |
| 2743 | * compatible for glBlitFramebuffer. From the 3.1 spec, page 198: |
| 2744 | * |
| 2745 | * "GL_INVALID_OPERATION is generated if mask contains GL_COLOR_BUFFER_BIT |
| 2746 | * and any of the following conditions hold: |
| 2747 | * - The read buffer contains fixed-point or floating-point values and any |
| 2748 | * draw buffer contains neither fixed-point nor floating-point values. |
| 2749 | * - The read buffer contains unsigned integer values and any draw buffer |
| 2750 | * does not contain unsigned integer values. |
| 2751 | * - The read buffer contains signed integer values and any draw buffer |
| 2752 | * does not contain signed integer values." |
| 2753 | */ |
| 2754 | static GLboolean |
| 2755 | compatible_color_datatypes(gl_format srcFormat, gl_format dstFormat) |
| 2756 | { |
| 2757 | GLenum srcType = _mesa_get_format_datatype(srcFormat); |
| 2758 | GLenum dstType = _mesa_get_format_datatype(dstFormat); |
| 2759 | |
| 2760 | if (srcType != GL_INT && srcType != GL_UNSIGNED_INT) { |
| 2761 | assert(srcType == GL_UNSIGNED_NORMALIZED || |
| 2762 | srcType == GL_SIGNED_NORMALIZED || |
| 2763 | srcType == GL_FLOAT); |
| 2764 | /* Boil any of those types down to GL_FLOAT */ |
| 2765 | srcType = GL_FLOAT; |
| 2766 | } |
| 2767 | |
| 2768 | if (dstType != GL_INT && dstType != GL_UNSIGNED_INT) { |
| 2769 | assert(dstType == GL_UNSIGNED_NORMALIZED || |
| 2770 | dstType == GL_SIGNED_NORMALIZED || |
| 2771 | dstType == GL_FLOAT); |
| 2772 | /* Boil any of those types down to GL_FLOAT */ |
| 2773 | dstType = GL_FLOAT; |
| 2774 | } |
| 2775 | |
| 2776 | return srcType == dstType; |
| 2777 | } |
| 2778 | |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2779 | |
Marek Olšák | 5927227 | 2012-07-21 15:16:15 +0200 | [diff] [blame] | 2780 | static GLboolean |
Marek Olšák | 135fe90 | 2012-11-28 19:07:18 +0100 | [diff] [blame] | 2781 | compatible_resolve_formats(const struct gl_renderbuffer *readRb, |
| 2782 | const struct gl_renderbuffer *drawRb) |
Marek Olšák | 5927227 | 2012-07-21 15:16:15 +0200 | [diff] [blame] | 2783 | { |
Marek Olšák | 91ca053 | 2012-11-23 03:02:44 +0100 | [diff] [blame] | 2784 | GLenum readFormat, drawFormat; |
| 2785 | |
| 2786 | /* The simple case where we know the backing Mesa formats are the same. |
Marek Olšák | 5927227 | 2012-07-21 15:16:15 +0200 | [diff] [blame] | 2787 | */ |
Marek Olšák | 135fe90 | 2012-11-28 19:07:18 +0100 | [diff] [blame] | 2788 | if (_mesa_get_srgb_format_linear(readRb->Format) == |
| 2789 | _mesa_get_srgb_format_linear(drawRb->Format)) { |
Marek Olšák | 5927227 | 2012-07-21 15:16:15 +0200 | [diff] [blame] | 2790 | return GL_TRUE; |
| 2791 | } |
| 2792 | |
| 2793 | /* The Mesa formats are different, so we must check whether the internal |
| 2794 | * formats are compatible. |
| 2795 | * |
| 2796 | * Under some circumstances, the user may request e.g. two GL_RGBA8 |
| 2797 | * textures and get two entirely different Mesa formats like RGBA8888 and |
| 2798 | * ARGB8888. Drivers behaving like that should be able to cope with |
| 2799 | * non-matching formats by themselves, because it's not the user's fault. |
Marek Olšák | 91ca053 | 2012-11-23 03:02:44 +0100 | [diff] [blame] | 2800 | * |
| 2801 | * Blits between linear and sRGB formats are also allowed. |
Marek Olšák | 5927227 | 2012-07-21 15:16:15 +0200 | [diff] [blame] | 2802 | */ |
Marek Olšák | 135fe90 | 2012-11-28 19:07:18 +0100 | [diff] [blame] | 2803 | readFormat = _mesa_get_nongeneric_internalformat(readRb->InternalFormat); |
| 2804 | drawFormat = _mesa_get_nongeneric_internalformat(drawRb->InternalFormat); |
| 2805 | readFormat = _mesa_get_linear_internalformat(readFormat); |
| 2806 | drawFormat = _mesa_get_linear_internalformat(drawFormat); |
Marek Olšák | 91ca053 | 2012-11-23 03:02:44 +0100 | [diff] [blame] | 2807 | |
| 2808 | if (readFormat == drawFormat) { |
Marek Olšák | 5927227 | 2012-07-21 15:16:15 +0200 | [diff] [blame] | 2809 | return GL_TRUE; |
| 2810 | } |
| 2811 | |
| 2812 | return GL_FALSE; |
| 2813 | } |
| 2814 | |
| 2815 | |
| 2816 | /** |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2817 | * Blit rectangular region, optionally from one framebuffer to another. |
| 2818 | * |
| 2819 | * Note, if the src buffer is multisampled and the dest is not, this is |
| 2820 | * when the samples must be resolved to a single color. |
| 2821 | */ |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2822 | void GLAPIENTRY |
Paul Berry | 1a1db17 | 2012-11-06 08:57:59 -0800 | [diff] [blame] | 2823 | _mesa_BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2824 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 2825 | GLbitfield mask, GLenum filter) |
| 2826 | { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2827 | const GLbitfield legalMaskBits = (GL_COLOR_BUFFER_BIT | |
| 2828 | GL_DEPTH_BUFFER_BIT | |
| 2829 | GL_STENCIL_BUFFER_BIT); |
| 2830 | const struct gl_framebuffer *readFb, *drawFb; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2831 | GET_CURRENT_CONTEXT(ctx); |
| 2832 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2833 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 2834 | |
Brian Paul | 6364d75 | 2011-02-18 09:53:29 -0700 | [diff] [blame] | 2835 | if (MESA_VERBOSE & VERBOSE_API) |
| 2836 | _mesa_debug(ctx, |
| 2837 | "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n", |
| 2838 | srcX0, srcY0, srcX1, srcY1, |
| 2839 | dstX0, dstY0, dstX1, dstY1, |
| 2840 | mask, _mesa_lookup_enum_by_nr(filter)); |
| 2841 | |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2842 | if (ctx->NewState) { |
| 2843 | _mesa_update_state(ctx); |
| 2844 | } |
| 2845 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2846 | readFb = ctx->ReadBuffer; |
| 2847 | drawFb = ctx->DrawBuffer; |
| 2848 | |
| 2849 | if (!readFb || !drawFb) { |
| 2850 | /* This will normally never happen but someday we may want to |
| 2851 | * support MakeCurrent() with no drawables. |
| 2852 | */ |
| 2853 | return; |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2854 | } |
| 2855 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2856 | /* check for complete framebuffers */ |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2857 | if (drawFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT || |
| 2858 | readFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2859 | _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, |
| 2860 | "glBlitFramebufferEXT(incomplete draw/read buffers)"); |
| 2861 | return; |
| 2862 | } |
| 2863 | |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2864 | if (filter != GL_NEAREST && filter != GL_LINEAR) { |
| 2865 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(filter)"); |
| 2866 | return; |
| 2867 | } |
| 2868 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2869 | if (mask & ~legalMaskBits) { |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2870 | _mesa_error( ctx, GL_INVALID_VALUE, "glBlitFramebufferEXT(mask)"); |
| 2871 | return; |
| 2872 | } |
| 2873 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2874 | /* depth/stencil must be blitted with nearest filtering */ |
| 2875 | if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) |
| 2876 | && filter != GL_NEAREST) { |
| 2877 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Vinson Lee | 4f94e0b | 2011-03-28 20:32:01 -0700 | [diff] [blame] | 2878 | "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)"); |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2879 | return; |
| 2880 | } |
| 2881 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2882 | /* get color read/draw renderbuffers */ |
| 2883 | if (mask & GL_COLOR_BUFFER_BIT) { |
Anuj Phogat | ab36ca0 | 2012-12-11 20:17:47 -0800 | [diff] [blame] | 2884 | const GLuint numColorDrawBuffers = ctx->DrawBuffer->_NumColorDrawBuffers; |
| 2885 | const struct gl_renderbuffer *colorReadRb = readFb->_ColorReadBuffer; |
| 2886 | const struct gl_renderbuffer *colorDrawRb = NULL; |
| 2887 | GLuint i; |
Ian Romanick | bb47586 | 2011-06-07 12:38:39 -0700 | [diff] [blame] | 2888 | |
| 2889 | /* From the EXT_framebuffer_object spec: |
| 2890 | * |
| 2891 | * "If a buffer is specified in <mask> and does not exist in both |
| 2892 | * the read and draw framebuffers, the corresponding bit is silently |
| 2893 | * ignored." |
| 2894 | */ |
Anuj Phogat | ab36ca0 | 2012-12-11 20:17:47 -0800 | [diff] [blame] | 2895 | if (!colorReadRb || numColorDrawBuffers == 0) { |
| 2896 | mask &= ~GL_COLOR_BUFFER_BIT; |
Ian Romanick | bb47586 | 2011-06-07 12:38:39 -0700 | [diff] [blame] | 2897 | } |
Anuj Phogat | ab36ca0 | 2012-12-11 20:17:47 -0800 | [diff] [blame] | 2898 | else { |
| 2899 | for (i = 0; i < numColorDrawBuffers; i++) { |
| 2900 | colorDrawRb = ctx->DrawBuffer->_ColorDrawBuffers[i]; |
| 2901 | if (!colorDrawRb) |
| 2902 | continue; |
| 2903 | |
Ian Romanick | 9cb64a4 | 2013-01-17 13:37:53 -0800 | [diff] [blame] | 2904 | /* Page 193 (page 205 of the PDF) in section 4.3.2 of the OpenGL |
| 2905 | * ES 3.0.1 spec says: |
| 2906 | * |
| 2907 | * "If the source and destination buffers are identical, an |
| 2908 | * INVALID_OPERATION error is generated. Different mipmap |
| 2909 | * levels of a texture, different layers of a three- |
| 2910 | * dimensional texture or two-dimensional array texture, and |
| 2911 | * different faces of a cube map texture do not constitute |
| 2912 | * identical buffers." |
| 2913 | */ |
| 2914 | if (_mesa_is_gles3(ctx) && (colorDrawRb == colorReadRb)) { |
| 2915 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2916 | "glBlitFramebuffer(source and destination color " |
| 2917 | "buffer cannot be the same)"); |
| 2918 | return; |
| 2919 | } |
| 2920 | |
Anuj Phogat | ab36ca0 | 2012-12-11 20:17:47 -0800 | [diff] [blame] | 2921 | if (!compatible_color_datatypes(colorReadRb->Format, |
| 2922 | colorDrawRb->Format)) { |
| 2923 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2924 | "glBlitFramebufferEXT(color buffer datatypes mismatch)"); |
| 2925 | return; |
| 2926 | } |
| 2927 | /* extra checks for multisample copies... */ |
| 2928 | if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) { |
| 2929 | /* color formats must match */ |
| 2930 | if (!compatible_resolve_formats(colorReadRb, colorDrawRb)) { |
| 2931 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2932 | "glBlitFramebufferEXT(bad src/dst multisample pixel formats)"); |
| 2933 | return; |
| 2934 | } |
| 2935 | } |
| 2936 | } |
| 2937 | if (filter == GL_LINEAR) { |
| 2938 | /* 3.1 spec, page 199: |
| 2939 | * "Calling BlitFramebuffer will result in an INVALID_OPERATION error |
| 2940 | * if filter is LINEAR and read buffer contains integer data." |
| 2941 | */ |
| 2942 | GLenum type = _mesa_get_format_datatype(colorReadRb->Format); |
| 2943 | if (type == GL_INT || type == GL_UNSIGNED_INT) { |
| 2944 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2945 | "glBlitFramebufferEXT(integer color type)"); |
| 2946 | return; |
| 2947 | } |
| 2948 | } |
Brian Paul | 9b11170 | 2012-01-09 12:38:49 -0700 | [diff] [blame] | 2949 | } |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2950 | } |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2951 | |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2952 | if (mask & GL_STENCIL_BUFFER_BIT) { |
Brian Paul | d124092 | 2011-12-10 11:44:43 -0700 | [diff] [blame] | 2953 | struct gl_renderbuffer *readRb = |
| 2954 | readFb->Attachment[BUFFER_STENCIL].Renderbuffer; |
| 2955 | struct gl_renderbuffer *drawRb = |
| 2956 | drawFb->Attachment[BUFFER_STENCIL].Renderbuffer; |
Ian Romanick | bb47586 | 2011-06-07 12:38:39 -0700 | [diff] [blame] | 2957 | |
| 2958 | /* From the EXT_framebuffer_object spec: |
| 2959 | * |
| 2960 | * "If a buffer is specified in <mask> and does not exist in both |
| 2961 | * the read and draw framebuffers, the corresponding bit is silently |
| 2962 | * ignored." |
| 2963 | */ |
| 2964 | if ((readRb == NULL) || (drawRb == NULL)) { |
Ian Romanick | bb47586 | 2011-06-07 12:38:39 -0700 | [diff] [blame] | 2965 | mask &= ~GL_STENCIL_BUFFER_BIT; |
| 2966 | } |
Anuj Phogat | 252573a | 2013-01-07 15:55:31 -0800 | [diff] [blame] | 2967 | else { |
Brian Paul | 7ecbbc3 | 2013-01-15 17:02:30 -0700 | [diff] [blame] | 2968 | int read_z_bits, draw_z_bits; |
| 2969 | |
Ian Romanick | 9cb64a4 | 2013-01-17 13:37:53 -0800 | [diff] [blame] | 2970 | if (_mesa_is_gles3(ctx) && (drawRb == readRb)) { |
| 2971 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2972 | "glBlitFramebuffer(source and destination stencil " |
| 2973 | "buffer cannot be the same)"); |
| 2974 | return; |
| 2975 | } |
| 2976 | |
Anuj Phogat | 252573a | 2013-01-07 15:55:31 -0800 | [diff] [blame] | 2977 | if (_mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) != |
| 2978 | _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) { |
| 2979 | /* There is no need to check the stencil datatype here, because |
| 2980 | * there is only one: GL_UNSIGNED_INT. |
| 2981 | */ |
| 2982 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2983 | "glBlitFramebuffer(stencil attachment format mismatch)"); |
| 2984 | return; |
| 2985 | } |
| 2986 | |
Brian Paul | 7ecbbc3 | 2013-01-15 17:02:30 -0700 | [diff] [blame] | 2987 | read_z_bits = _mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS); |
| 2988 | draw_z_bits = _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS); |
Anuj Phogat | 252573a | 2013-01-07 15:55:31 -0800 | [diff] [blame] | 2989 | |
| 2990 | /* If both buffers also have depth data, the depth formats must match |
| 2991 | * as well. If one doesn't have depth, it's not blitted, so we should |
| 2992 | * ignore the depth format check. |
| 2993 | */ |
| 2994 | if (read_z_bits > 0 && draw_z_bits > 0 && |
| 2995 | (read_z_bits != draw_z_bits || |
| 2996 | _mesa_get_format_datatype(readRb->Format) != |
| 2997 | _mesa_get_format_datatype(drawRb->Format))) { |
| 2998 | |
| 2999 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebuffer" |
| 3000 | "(stencil attachment depth format mismatch)"); |
| 3001 | return; |
| 3002 | } |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | if (mask & GL_DEPTH_BUFFER_BIT) { |
Brian Paul | d124092 | 2011-12-10 11:44:43 -0700 | [diff] [blame] | 3007 | struct gl_renderbuffer *readRb = |
| 3008 | readFb->Attachment[BUFFER_DEPTH].Renderbuffer; |
| 3009 | struct gl_renderbuffer *drawRb = |
| 3010 | drawFb->Attachment[BUFFER_DEPTH].Renderbuffer; |
Ian Romanick | bb47586 | 2011-06-07 12:38:39 -0700 | [diff] [blame] | 3011 | |
| 3012 | /* From the EXT_framebuffer_object spec: |
| 3013 | * |
| 3014 | * "If a buffer is specified in <mask> and does not exist in both |
| 3015 | * the read and draw framebuffers, the corresponding bit is silently |
| 3016 | * ignored." |
| 3017 | */ |
| 3018 | if ((readRb == NULL) || (drawRb == NULL)) { |
Ian Romanick | bb47586 | 2011-06-07 12:38:39 -0700 | [diff] [blame] | 3019 | mask &= ~GL_DEPTH_BUFFER_BIT; |
| 3020 | } |
Anuj Phogat | 252573a | 2013-01-07 15:55:31 -0800 | [diff] [blame] | 3021 | else { |
Brian Paul | 7ecbbc3 | 2013-01-15 17:02:30 -0700 | [diff] [blame] | 3022 | int read_s_bit, draw_s_bit; |
| 3023 | |
Ian Romanick | 9cb64a4 | 2013-01-17 13:37:53 -0800 | [diff] [blame] | 3024 | if (_mesa_is_gles3(ctx) && (drawRb == readRb)) { |
| 3025 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3026 | "glBlitFramebuffer(source and destination depth " |
| 3027 | "buffer cannot be the same)"); |
| 3028 | return; |
| 3029 | } |
| 3030 | |
Anuj Phogat | 252573a | 2013-01-07 15:55:31 -0800 | [diff] [blame] | 3031 | if ((_mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) != |
| 3032 | _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) || |
| 3033 | (_mesa_get_format_datatype(readRb->Format) != |
| 3034 | _mesa_get_format_datatype(drawRb->Format))) { |
| 3035 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3036 | "glBlitFramebuffer(depth attachment format mismatch)"); |
| 3037 | return; |
| 3038 | } |
| 3039 | |
Brian Paul | 7ecbbc3 | 2013-01-15 17:02:30 -0700 | [diff] [blame] | 3040 | read_s_bit = _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS); |
| 3041 | draw_s_bit = _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS); |
Anuj Phogat | 252573a | 2013-01-07 15:55:31 -0800 | [diff] [blame] | 3042 | |
| 3043 | /* If both buffers also have stencil data, the stencil formats must |
| 3044 | * match as well. If one doesn't have stencil, it's not blitted, so |
| 3045 | * we should ignore the stencil format check. |
| 3046 | */ |
| 3047 | if (read_s_bit > 0 && draw_s_bit > 0 && read_s_bit != draw_s_bit) { |
| 3048 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebuffer" |
| 3049 | "(depth attachment stencil bits mismatch)"); |
| 3050 | return; |
| 3051 | } |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 3052 | } |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3053 | } |
| 3054 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 3055 | if (readFb->Visual.samples > 0 && |
| 3056 | drawFb->Visual.samples > 0 && |
| 3057 | readFb->Visual.samples != drawFb->Visual.samples) { |
| 3058 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Brian Paul | b87b857 | 2012-01-09 08:11:33 -0700 | [diff] [blame] | 3059 | "glBlitFramebufferEXT(mismatched samples)"); |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 3060 | return; |
| 3061 | } |
| 3062 | |
| 3063 | /* extra checks for multisample copies... */ |
| 3064 | if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) { |
| 3065 | /* src and dest region sizes must be the same */ |
Paul Berry | 5d5f0f3 | 2012-09-05 16:07:16 -0700 | [diff] [blame] | 3066 | if (abs(srcX1 - srcX0) != abs(dstX1 - dstX0) || |
| 3067 | abs(srcY1 - srcY0) != abs(dstY1 - dstY0)) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 3068 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Vinson Lee | 4f94e0b | 2011-03-28 20:32:01 -0700 | [diff] [blame] | 3069 | "glBlitFramebufferEXT(bad src/dst multisample region sizes)"); |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 3070 | return; |
| 3071 | } |
Brian Paul | 84c38c7 | 2012-01-09 08:11:33 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3074 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 3075 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT"); |
| 3076 | return; |
| 3077 | } |
| 3078 | |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 3079 | /* Debug code */ |
| 3080 | if (DEBUG_BLIT) { |
Anuj Phogat | ab36ca0 | 2012-12-11 20:17:47 -0800 | [diff] [blame] | 3081 | const struct gl_renderbuffer *colorReadRb = readFb->_ColorReadBuffer; |
| 3082 | const struct gl_renderbuffer *colorDrawRb = NULL; |
| 3083 | GLuint i = 0; |
| 3084 | |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 3085 | printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d," |
| 3086 | " 0x%x, 0x%x)\n", |
| 3087 | srcX0, srcY0, srcX1, srcY1, |
| 3088 | dstX0, dstY0, dstX1, dstY1, |
| 3089 | mask, filter); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 3090 | if (colorReadRb) { |
| 3091 | const struct gl_renderbuffer_attachment *att; |
| 3092 | |
| 3093 | att = find_attachment(readFb, colorReadRb); |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 3094 | printf(" Src FBO %u RB %u (%dx%d) ", |
| 3095 | readFb->Name, colorReadRb->Name, |
| 3096 | colorReadRb->Width, colorReadRb->Height); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 3097 | if (att && att->Texture) { |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 3098 | printf("Tex %u tgt 0x%x level %u face %u", |
| 3099 | att->Texture->Name, |
| 3100 | att->Texture->Target, |
| 3101 | att->TextureLevel, |
| 3102 | att->CubeMapFace); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 3103 | } |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 3104 | printf("\n"); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 3105 | |
Anuj Phogat | ab36ca0 | 2012-12-11 20:17:47 -0800 | [diff] [blame] | 3106 | /* Print all active color render buffers */ |
| 3107 | for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) { |
| 3108 | colorDrawRb = ctx->DrawBuffer->_ColorDrawBuffers[i]; |
| 3109 | if (!colorDrawRb) |
| 3110 | continue; |
| 3111 | |
| 3112 | att = find_attachment(drawFb, colorDrawRb); |
| 3113 | printf(" Dst FBO %u RB %u (%dx%d) ", |
| 3114 | drawFb->Name, colorDrawRb->Name, |
| 3115 | colorDrawRb->Width, colorDrawRb->Height); |
| 3116 | if (att && att->Texture) { |
| 3117 | printf("Tex %u tgt 0x%x level %u face %u", |
| 3118 | att->Texture->Name, |
| 3119 | att->Texture->Target, |
| 3120 | att->TextureLevel, |
| 3121 | att->CubeMapFace); |
| 3122 | } |
| 3123 | printf("\n"); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 3124 | } |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 3125 | } |
| 3126 | } |
| 3127 | |
Marek Olšák | 83478e5 | 2011-07-10 20:01:33 +0200 | [diff] [blame] | 3128 | if (!mask) { |
| 3129 | return; |
| 3130 | } |
| 3131 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 3132 | ASSERT(ctx->Driver.BlitFramebuffer); |
| 3133 | ctx->Driver.BlitFramebuffer(ctx, |
| 3134 | srcX0, srcY0, srcX1, srcY1, |
| 3135 | dstX0, dstY0, dstX1, dstY1, |
| 3136 | mask, filter); |
| 3137 | } |
Zack Rusin | da7bd6a | 2010-06-28 17:31:21 -0400 | [diff] [blame] | 3138 | |
Brian Paul | 45bd5c4 | 2011-12-16 08:44:43 -0700 | [diff] [blame] | 3139 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 3140 | static void |
| 3141 | invalidate_framebuffer_storage(GLenum target, GLsizei numAttachments, |
| 3142 | const GLenum *attachments, GLint x, GLint y, |
| 3143 | GLsizei width, GLsizei height, const char *name) |
| 3144 | { |
| 3145 | int i; |
| 3146 | struct gl_framebuffer *fb; |
| 3147 | GET_CURRENT_CONTEXT(ctx); |
| 3148 | |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 3149 | fb = get_framebuffer_target(ctx, target); |
| 3150 | if (!fb) { |
| 3151 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", name); |
| 3152 | return; |
| 3153 | } |
| 3154 | |
| 3155 | if (numAttachments < 0) { |
| 3156 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 3157 | "%s(numAttachments < 0)", name); |
| 3158 | return; |
| 3159 | } |
| 3160 | |
| 3161 | /* The GL_ARB_invalidate_subdata spec says: |
| 3162 | * |
| 3163 | * "If an attachment is specified that does not exist in the |
| 3164 | * framebuffer bound to <target>, it is ignored." |
| 3165 | * |
| 3166 | * It also says: |
| 3167 | * |
| 3168 | * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than |
| 3169 | * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error |
| 3170 | * INVALID_OPERATION is generated." |
| 3171 | * |
| 3172 | * No mention is made of GL_AUXi being out of range. Therefore, we allow |
| 3173 | * any enum that can be allowed by the API (OpenGL ES 3.0 has a different |
| 3174 | * set of retrictions). |
| 3175 | */ |
| 3176 | for (i = 0; i < numAttachments; i++) { |
| 3177 | if (_mesa_is_winsys_fbo(fb)) { |
| 3178 | switch (attachments[i]) { |
| 3179 | case GL_ACCUM: |
| 3180 | case GL_AUX0: |
| 3181 | case GL_AUX1: |
| 3182 | case GL_AUX2: |
| 3183 | case GL_AUX3: |
| 3184 | /* Accumulation buffers and auxilary buffers were removed in |
| 3185 | * OpenGL 3.1, and they never existed in OpenGL ES. |
| 3186 | */ |
Paul Berry | dbd6135 | 2012-11-27 12:26:51 -0800 | [diff] [blame] | 3187 | if (ctx->API != API_OPENGL_COMPAT) |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 3188 | goto invalid_enum; |
| 3189 | break; |
| 3190 | case GL_COLOR: |
| 3191 | case GL_DEPTH: |
| 3192 | case GL_STENCIL: |
| 3193 | break; |
| 3194 | case GL_BACK_LEFT: |
| 3195 | case GL_BACK_RIGHT: |
| 3196 | case GL_FRONT_LEFT: |
| 3197 | case GL_FRONT_RIGHT: |
| 3198 | if (!_mesa_is_desktop_gl(ctx)) |
| 3199 | goto invalid_enum; |
| 3200 | break; |
| 3201 | default: |
| 3202 | goto invalid_enum; |
| 3203 | } |
| 3204 | } else { |
| 3205 | switch (attachments[i]) { |
| 3206 | case GL_DEPTH_ATTACHMENT: |
| 3207 | case GL_STENCIL_ATTACHMENT: |
| 3208 | break; |
| 3209 | case GL_COLOR_ATTACHMENT0: |
| 3210 | case GL_COLOR_ATTACHMENT1: |
| 3211 | case GL_COLOR_ATTACHMENT2: |
| 3212 | case GL_COLOR_ATTACHMENT3: |
| 3213 | case GL_COLOR_ATTACHMENT4: |
| 3214 | case GL_COLOR_ATTACHMENT5: |
| 3215 | case GL_COLOR_ATTACHMENT6: |
| 3216 | case GL_COLOR_ATTACHMENT7: |
| 3217 | case GL_COLOR_ATTACHMENT8: |
| 3218 | case GL_COLOR_ATTACHMENT9: |
| 3219 | case GL_COLOR_ATTACHMENT10: |
| 3220 | case GL_COLOR_ATTACHMENT11: |
| 3221 | case GL_COLOR_ATTACHMENT12: |
| 3222 | case GL_COLOR_ATTACHMENT13: |
| 3223 | case GL_COLOR_ATTACHMENT14: |
| 3224 | case GL_COLOR_ATTACHMENT15: { |
Brian Paul | 859c387 | 2012-11-04 16:43:44 -0700 | [diff] [blame] | 3225 | unsigned k = attachments[i] - GL_COLOR_ATTACHMENT0; |
Ian Romanick | 342be8a | 2012-08-13 09:27:00 -0700 | [diff] [blame] | 3226 | if (k >= ctx->Const.MaxColorAttachments) { |
| 3227 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 3228 | "%s(attachment >= max. color attachments)", name); |
| 3229 | return; |
| 3230 | } |
| 3231 | } |
| 3232 | default: |
| 3233 | goto invalid_enum; |
| 3234 | } |
| 3235 | } |
| 3236 | } |
| 3237 | |
| 3238 | /* We don't actually do anything for this yet. Just return after |
| 3239 | * validating the parameters and generating the required errors. |
| 3240 | */ |
| 3241 | return; |
| 3242 | |
| 3243 | invalid_enum: |
| 3244 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(attachment)", name); |
| 3245 | return; |
| 3246 | } |
| 3247 | |
| 3248 | void GLAPIENTRY |
| 3249 | _mesa_InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, |
| 3250 | const GLenum *attachments, GLint x, GLint y, |
| 3251 | GLsizei width, GLsizei height) |
| 3252 | { |
| 3253 | invalidate_framebuffer_storage(target, numAttachments, attachments, |
| 3254 | x, y, width, height, |
| 3255 | "glInvalidateSubFramebuffer"); |
| 3256 | } |
| 3257 | |
| 3258 | void GLAPIENTRY |
| 3259 | _mesa_InvalidateFramebuffer(GLenum target, GLsizei numAttachments, |
| 3260 | const GLenum *attachments) |
| 3261 | { |
| 3262 | /* The GL_ARB_invalidate_subdata spec says: |
| 3263 | * |
| 3264 | * "The command |
| 3265 | * |
| 3266 | * void InvalidateFramebuffer(enum target, |
| 3267 | * sizei numAttachments, |
| 3268 | * const enum *attachments); |
| 3269 | * |
| 3270 | * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>, |
| 3271 | * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>, |
| 3272 | * <MAX_VIEWPORT_DIMS[1]> respectively." |
| 3273 | */ |
| 3274 | invalidate_framebuffer_storage(target, numAttachments, attachments, |
| 3275 | 0, 0, MAX_VIEWPORT_WIDTH, MAX_VIEWPORT_HEIGHT, |
| 3276 | "glInvalidateFramebuffer"); |
| 3277 | } |