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