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