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 | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 42 | #include "macros.h" |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 43 | #include "renderbuffer.h" |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 44 | #include "state.h" |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 45 | #include "teximage.h" |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 46 | #include "texobj.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 47 | |
| 48 | |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 49 | /** Set this to 1 to help debug FBO incompleteness problems */ |
| 50 | #define DEBUG_FBO 0 |
| 51 | |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 52 | /** Set this to 1 to debug/log glBlitFramebuffer() calls */ |
| 53 | #define DEBUG_BLIT 0 |
| 54 | |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 55 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 56 | /** |
| 57 | * Notes: |
| 58 | * |
| 59 | * None of the GL_EXT_framebuffer_object functions are compiled into |
| 60 | * display lists. |
| 61 | */ |
| 62 | |
| 63 | |
| 64 | |
Brian Paul | 923b6fc | 2005-02-08 04:08:56 +0000 | [diff] [blame] | 65 | /* |
| 66 | * When glGenRender/FramebuffersEXT() is called we insert pointers to |
| 67 | * these placeholder objects into the hash table. |
| 68 | * Later, when the object ID is first bound, we replace the placeholder |
| 69 | * with the real frame/renderbuffer. |
| 70 | */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 71 | static struct gl_framebuffer DummyFramebuffer; |
| 72 | static struct gl_renderbuffer DummyRenderbuffer; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 73 | |
| 74 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 75 | #define IS_CUBE_FACE(TARGET) \ |
| 76 | ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \ |
| 77 | (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 78 | |
| 79 | |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 80 | static void |
| 81 | delete_dummy_renderbuffer(struct gl_renderbuffer *rb) |
| 82 | { |
| 83 | /* no op */ |
| 84 | } |
| 85 | |
| 86 | static void |
| 87 | delete_dummy_framebuffer(struct gl_framebuffer *fb) |
| 88 | { |
| 89 | /* no op */ |
| 90 | } |
| 91 | |
| 92 | |
| 93 | void |
| 94 | _mesa_init_fbobjects(GLcontext *ctx) |
| 95 | { |
Vladimir Vukicevic | 0731701 | 2010-09-01 08:54:21 -0600 | [diff] [blame^] | 96 | _glthread_INIT_MUTEX(DummyFramebuffer.Mutex); |
| 97 | _glthread_INIT_MUTEX(DummyRenderbuffer.Mutex); |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 98 | DummyFramebuffer.Delete = delete_dummy_framebuffer; |
| 99 | DummyRenderbuffer.Delete = delete_dummy_renderbuffer; |
| 100 | } |
| 101 | |
Kristian Høgsberg | 9456e22 | 2010-06-04 14:28:59 -0400 | [diff] [blame] | 102 | struct gl_framebuffer * |
| 103 | _mesa_get_incomplete_framebuffer(void) |
| 104 | { |
| 105 | return &DummyFramebuffer; |
| 106 | } |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 107 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 108 | /** |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 109 | * Helper routine for getting a gl_renderbuffer. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 110 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 111 | struct gl_renderbuffer * |
| 112 | _mesa_lookup_renderbuffer(GLcontext *ctx, GLuint id) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 113 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 114 | struct gl_renderbuffer *rb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 115 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 116 | if (id == 0) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 117 | return NULL; |
| 118 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 119 | rb = (struct gl_renderbuffer *) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 120 | _mesa_HashLookup(ctx->Shared->RenderBuffers, id); |
| 121 | return rb; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | /** |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 126 | * Helper routine for getting a gl_framebuffer. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 127 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 128 | struct gl_framebuffer * |
| 129 | _mesa_lookup_framebuffer(GLcontext *ctx, GLuint id) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 130 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 131 | struct gl_framebuffer *fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 132 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 133 | if (id == 0) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 134 | return NULL; |
| 135 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 136 | fb = (struct gl_framebuffer *) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 137 | _mesa_HashLookup(ctx->Shared->FrameBuffers, id); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 138 | return fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
| 142 | /** |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 143 | * Mark the given framebuffer as invalid. This will force the |
| 144 | * test for framebuffer completeness to be done before the framebuffer |
| 145 | * is used. |
| 146 | */ |
| 147 | static void |
| 148 | invalidate_framebuffer(struct gl_framebuffer *fb) |
| 149 | { |
| 150 | fb->_Status = 0; /* "indeterminate" */ |
| 151 | } |
| 152 | |
| 153 | |
| 154 | /** |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 155 | * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 156 | * gl_renderbuffer_attachment object. |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 157 | * This function is only used for user-created FB objects, not the |
| 158 | * default / window-system FB object. |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 159 | * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to |
| 160 | * the depth buffer attachment point. |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 161 | */ |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 162 | struct gl_renderbuffer_attachment * |
| 163 | _mesa_get_attachment(GLcontext *ctx, struct gl_framebuffer *fb, |
| 164 | GLenum attachment) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 165 | { |
| 166 | GLuint i; |
| 167 | |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 168 | assert(fb->Name > 0); |
| 169 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 170 | switch (attachment) { |
| 171 | case GL_COLOR_ATTACHMENT0_EXT: |
| 172 | case GL_COLOR_ATTACHMENT1_EXT: |
| 173 | case GL_COLOR_ATTACHMENT2_EXT: |
| 174 | case GL_COLOR_ATTACHMENT3_EXT: |
| 175 | case GL_COLOR_ATTACHMENT4_EXT: |
| 176 | case GL_COLOR_ATTACHMENT5_EXT: |
| 177 | case GL_COLOR_ATTACHMENT6_EXT: |
| 178 | case GL_COLOR_ATTACHMENT7_EXT: |
| 179 | case GL_COLOR_ATTACHMENT8_EXT: |
| 180 | case GL_COLOR_ATTACHMENT9_EXT: |
| 181 | case GL_COLOR_ATTACHMENT10_EXT: |
| 182 | case GL_COLOR_ATTACHMENT11_EXT: |
| 183 | case GL_COLOR_ATTACHMENT12_EXT: |
| 184 | case GL_COLOR_ATTACHMENT13_EXT: |
| 185 | case GL_COLOR_ATTACHMENT14_EXT: |
| 186 | case GL_COLOR_ATTACHMENT15_EXT: |
| 187 | i = attachment - GL_COLOR_ATTACHMENT0_EXT; |
| 188 | if (i >= ctx->Const.MaxColorAttachments) { |
| 189 | return NULL; |
| 190 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 191 | return &fb->Attachment[BUFFER_COLOR0 + i]; |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 192 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 193 | /* fall-through */ |
Brian Paul | 8829e06 | 2010-03-20 11:50:55 -0600 | [diff] [blame] | 194 | case GL_DEPTH_BUFFER: |
| 195 | /* fall-through / new in GL 3.0 */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 196 | case GL_DEPTH_ATTACHMENT_EXT: |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 197 | return &fb->Attachment[BUFFER_DEPTH]; |
Brian Paul | 8829e06 | 2010-03-20 11:50:55 -0600 | [diff] [blame] | 198 | case GL_STENCIL_BUFFER: |
| 199 | /* fall-through / new in GL 3.0 */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 200 | case GL_STENCIL_ATTACHMENT_EXT: |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 201 | return &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 202 | default: |
| 203 | return NULL; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | |
| 208 | /** |
| 209 | * As above, but only used for getting attachments of the default / |
| 210 | * window-system framebuffer (not user-created framebuffer objects). |
| 211 | */ |
| 212 | static struct gl_renderbuffer_attachment * |
| 213 | _mesa_get_fb0_attachment(GLcontext *ctx, struct gl_framebuffer *fb, |
| 214 | GLenum attachment) |
| 215 | { |
| 216 | assert(fb->Name == 0); |
| 217 | |
| 218 | switch (attachment) { |
Kristian Høgsberg | 80dfec3 | 2010-06-15 13:07:01 -0400 | [diff] [blame] | 219 | case GL_FRONT_LEFT: |
| 220 | return &fb->Attachment[BUFFER_FRONT_LEFT]; |
| 221 | case GL_FRONT_RIGHT: |
| 222 | return &fb->Attachment[BUFFER_FRONT_RIGHT]; |
| 223 | case GL_BACK_LEFT: |
| 224 | return &fb->Attachment[BUFFER_BACK_LEFT]; |
| 225 | case GL_BACK_RIGHT: |
| 226 | return &fb->Attachment[BUFFER_BACK_RIGHT]; |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 227 | case GL_AUX0: |
| 228 | if (fb->Visual.numAuxBuffers == 1) { |
| 229 | return &fb->Attachment[BUFFER_AUX0]; |
| 230 | } |
| 231 | return NULL; |
| 232 | case GL_DEPTH_BUFFER: |
| 233 | /* fall-through / new in GL 3.0 */ |
| 234 | case GL_DEPTH_ATTACHMENT_EXT: |
| 235 | return &fb->Attachment[BUFFER_DEPTH]; |
| 236 | case GL_STENCIL_BUFFER: |
| 237 | /* fall-through / new in GL 3.0 */ |
| 238 | case GL_STENCIL_ATTACHMENT_EXT: |
| 239 | return &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 240 | default: |
| 241 | return NULL; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 246 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 247 | /** |
| 248 | * Remove any texture or renderbuffer attached to the given attachment |
| 249 | * point. Update reference counts, etc. |
| 250 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 251 | void |
| 252 | _mesa_remove_attachment(GLcontext *ctx, struct gl_renderbuffer_attachment *att) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 253 | { |
| 254 | if (att->Type == GL_TEXTURE) { |
| 255 | ASSERT(att->Texture); |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 256 | if (ctx->Driver.FinishRenderTexture) { |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 257 | /* tell driver that we're done rendering to this texture. */ |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 258 | ctx->Driver.FinishRenderTexture(ctx, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 259 | } |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 260 | _mesa_reference_texobj(&att->Texture, NULL); /* unbind */ |
| 261 | ASSERT(!att->Texture); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 262 | } |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 263 | if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) { |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 264 | ASSERT(!att->Texture); |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 265 | _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */ |
| 266 | ASSERT(!att->Renderbuffer); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 267 | } |
| 268 | att->Type = GL_NONE; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 269 | att->Complete = GL_TRUE; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 273 | /** |
| 274 | * Bind a texture object to an attachment point. |
| 275 | * The previous binding, if any, will be removed first. |
| 276 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 277 | void |
| 278 | _mesa_set_texture_attachment(GLcontext *ctx, |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 279 | struct gl_framebuffer *fb, |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 280 | struct gl_renderbuffer_attachment *att, |
| 281 | struct gl_texture_object *texObj, |
| 282 | GLenum texTarget, GLuint level, GLuint zoffset) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 283 | { |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 284 | if (att->Texture == texObj) { |
| 285 | /* re-attaching same texture */ |
| 286 | ASSERT(att->Type == GL_TEXTURE); |
Eric Anholt | 6b68482 | 2009-11-04 14:31:30 -0800 | [diff] [blame] | 287 | if (ctx->Driver.FinishRenderTexture) |
| 288 | ctx->Driver.FinishRenderTexture(ctx, att); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 289 | } |
| 290 | else { |
| 291 | /* new attachment */ |
Eric Anholt | 6b68482 | 2009-11-04 14:31:30 -0800 | [diff] [blame] | 292 | if (ctx->Driver.FinishRenderTexture && att->Texture) |
| 293 | ctx->Driver.FinishRenderTexture(ctx, att); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 294 | _mesa_remove_attachment(ctx, att); |
| 295 | att->Type = GL_TEXTURE; |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 296 | assert(!att->Texture); |
| 297 | _mesa_reference_texobj(&att->Texture, texObj); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* always update these fields */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 301 | att->TextureLevel = level; |
Brian Paul | 26f1ad6 | 2009-10-23 18:15:55 -0600 | [diff] [blame] | 302 | att->CubeMapFace = _mesa_tex_target_to_face(texTarget); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 303 | att->Zoffset = zoffset; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 304 | att->Complete = GL_FALSE; |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 305 | |
| 306 | if (att->Texture->Image[att->CubeMapFace][att->TextureLevel]) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 307 | ctx->Driver.RenderTexture(ctx, fb, att); |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 308 | } |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 309 | |
| 310 | invalidate_framebuffer(fb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 314 | /** |
| 315 | * Bind a renderbuffer to an attachment point. |
| 316 | * The previous binding, if any, will be removed first. |
| 317 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 318 | void |
| 319 | _mesa_set_renderbuffer_attachment(GLcontext *ctx, |
| 320 | struct gl_renderbuffer_attachment *att, |
| 321 | struct gl_renderbuffer *rb) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 322 | { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 323 | /* XXX check if re-doing same attachment, exit early */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 324 | _mesa_remove_attachment(ctx, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 325 | att->Type = GL_RENDERBUFFER_EXT; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 326 | att->Texture = NULL; /* just to be safe */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 327 | att->Complete = GL_FALSE; |
Brian | dccd9c4 | 2007-04-02 09:56:28 -0600 | [diff] [blame] | 328 | _mesa_reference_renderbuffer(&att->Renderbuffer, rb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 331 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 332 | /** |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 333 | * Fallback for ctx->Driver.FramebufferRenderbuffer() |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 334 | * Attach a renderbuffer object to a framebuffer object. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 335 | */ |
| 336 | void |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 337 | _mesa_framebuffer_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb, |
| 338 | GLenum attachment, struct gl_renderbuffer *rb) |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 339 | { |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 340 | struct gl_renderbuffer_attachment *att; |
| 341 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 342 | _glthread_LOCK_MUTEX(fb->Mutex); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 343 | |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 344 | att = _mesa_get_attachment(ctx, fb, attachment); |
| 345 | ASSERT(att); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 346 | if (rb) { |
| 347 | _mesa_set_renderbuffer_attachment(ctx, att, rb); |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 348 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 349 | /* do stencil attachment here (depth already done above) */ |
| 350 | att = _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT); |
| 351 | assert(att); |
| 352 | _mesa_set_renderbuffer_attachment(ctx, att, rb); |
| 353 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 354 | } |
| 355 | else { |
| 356 | _mesa_remove_attachment(ctx, att); |
| 357 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 358 | |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 359 | invalidate_framebuffer(fb); |
| 360 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 361 | _glthread_UNLOCK_MUTEX(fb->Mutex); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | |
| 365 | /** |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 366 | * For debug only. |
| 367 | */ |
| 368 | static void |
| 369 | att_incomplete(const char *msg) |
| 370 | { |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 371 | #if DEBUG_FBO |
| 372 | _mesa_debug(NULL, "attachment incomplete: %s\n", msg); |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 373 | #else |
| 374 | (void) msg; |
| 375 | #endif |
| 376 | } |
| 377 | |
| 378 | |
| 379 | /** |
Brian Paul | c26c200 | 2009-09-15 17:20:32 -0600 | [diff] [blame] | 380 | * For debug only. |
| 381 | */ |
| 382 | static void |
| 383 | fbo_incomplete(const char *msg, int index) |
| 384 | { |
| 385 | #if DEBUG_FBO |
| 386 | _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index); |
| 387 | #else |
| 388 | (void) msg; |
| 389 | (void) index; |
| 390 | #endif |
| 391 | } |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | /** |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 397 | * Test if an attachment point is complete and update its Complete field. |
| 398 | * \param format if GL_COLOR, this is a color attachment point, |
| 399 | * if GL_DEPTH, this is a depth component attachment point, |
| 400 | * if GL_STENCIL, this is a stencil component attachment point. |
| 401 | */ |
| 402 | static void |
| 403 | test_attachment_completeness(const GLcontext *ctx, GLenum format, |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 404 | struct gl_renderbuffer_attachment *att) |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 405 | { |
| 406 | assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL); |
| 407 | |
| 408 | /* assume complete */ |
| 409 | att->Complete = GL_TRUE; |
| 410 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 411 | /* Look for reasons why the attachment might be incomplete */ |
| 412 | if (att->Type == GL_TEXTURE) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 413 | const struct gl_texture_object *texObj = att->Texture; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 414 | struct gl_texture_image *texImage; |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 415 | GLenum baseFormat; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 416 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 417 | if (!texObj) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 418 | att_incomplete("no texobj"); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 419 | att->Complete = GL_FALSE; |
| 420 | return; |
| 421 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 422 | |
| 423 | texImage = texObj->Image[att->CubeMapFace][att->TextureLevel]; |
| 424 | if (!texImage) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 425 | att_incomplete("no teximage"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 426 | att->Complete = GL_FALSE; |
| 427 | return; |
| 428 | } |
| 429 | if (texImage->Width < 1 || texImage->Height < 1) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 430 | att_incomplete("teximage width/height=0"); |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 431 | printf("texobj = %u\n", texObj->Name); |
| 432 | printf("level = %d\n", att->TextureLevel); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 433 | att->Complete = GL_FALSE; |
| 434 | return; |
| 435 | } |
| 436 | if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 437 | att_incomplete("bad z offset"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 438 | att->Complete = GL_FALSE; |
| 439 | return; |
| 440 | } |
| 441 | |
Brian Paul | 1f7c914 | 2009-09-30 20:28:45 -0600 | [diff] [blame] | 442 | baseFormat = _mesa_get_format_base_format(texImage->TexFormat); |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 443 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 444 | if (format == GL_COLOR) { |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 445 | if (baseFormat != GL_RGB && |
Eric Anholt | 262cdbd | 2010-05-25 08:00:51 -0700 | [diff] [blame] | 446 | baseFormat != GL_RGBA && |
| 447 | (!ctx->Extensions.ARB_framebuffer_object || |
| 448 | baseFormat != GL_ALPHA)) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 449 | att_incomplete("bad format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 450 | att->Complete = GL_FALSE; |
| 451 | return; |
| 452 | } |
Brian Paul | 1f7c914 | 2009-09-30 20:28:45 -0600 | [diff] [blame] | 453 | if (_mesa_is_format_compressed(texImage->TexFormat)) { |
Eric Anholt | 957f3c8 | 2009-05-15 16:24:59 -0700 | [diff] [blame] | 454 | att_incomplete("compressed internalformat"); |
| 455 | att->Complete = GL_FALSE; |
| 456 | return; |
| 457 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 458 | } |
| 459 | else if (format == GL_DEPTH) { |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 460 | if (baseFormat == GL_DEPTH_COMPONENT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 461 | /* OK */ |
| 462 | } |
| 463 | else if (ctx->Extensions.EXT_packed_depth_stencil && |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 464 | ctx->Extensions.ARB_depth_texture && |
Brian Paul | 5cf5d4b | 2009-09-27 20:51:18 -0600 | [diff] [blame] | 465 | baseFormat == GL_DEPTH_STENCIL_EXT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 466 | /* OK */ |
| 467 | } |
| 468 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 469 | att->Complete = GL_FALSE; |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 470 | att_incomplete("bad depth format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 471 | return; |
| 472 | } |
| 473 | } |
| 474 | else { |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 475 | ASSERT(format == GL_STENCIL); |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 476 | if (ctx->Extensions.EXT_packed_depth_stencil && |
| 477 | ctx->Extensions.ARB_depth_texture && |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 478 | baseFormat == GL_DEPTH_STENCIL_EXT) { |
Mathias Fröhlich | 042d9a5 | 2009-05-19 09:59:01 -0600 | [diff] [blame] | 479 | /* OK */ |
| 480 | } |
| 481 | else { |
| 482 | /* no such thing as stencil-only textures */ |
| 483 | att_incomplete("illegal stencil texture"); |
| 484 | att->Complete = GL_FALSE; |
| 485 | return; |
| 486 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 487 | } |
| 488 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 489 | else if (att->Type == GL_RENDERBUFFER_EXT) { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 490 | const GLenum baseFormat = |
| 491 | _mesa_get_format_base_format(att->Renderbuffer->Format); |
| 492 | |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 493 | ASSERT(att->Renderbuffer); |
| 494 | if (!att->Renderbuffer->InternalFormat || |
| 495 | att->Renderbuffer->Width < 1 || |
| 496 | att->Renderbuffer->Height < 1) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 497 | att_incomplete("0x0 renderbuffer"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 498 | att->Complete = GL_FALSE; |
| 499 | return; |
| 500 | } |
| 501 | if (format == GL_COLOR) { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 502 | if (baseFormat != GL_RGB && |
| 503 | baseFormat != GL_RGBA) { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 504 | att_incomplete("bad renderbuffer color format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 505 | att->Complete = GL_FALSE; |
| 506 | return; |
| 507 | } |
| 508 | } |
| 509 | else if (format == GL_DEPTH) { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 510 | if (baseFormat == GL_DEPTH_COMPONENT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 511 | /* OK */ |
| 512 | } |
| 513 | else if (ctx->Extensions.EXT_packed_depth_stencil && |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 514 | baseFormat == GL_DEPTH_STENCIL_EXT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 515 | /* OK */ |
| 516 | } |
| 517 | else { |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 518 | att_incomplete("bad renderbuffer depth format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 519 | att->Complete = GL_FALSE; |
| 520 | return; |
| 521 | } |
| 522 | } |
| 523 | else { |
| 524 | assert(format == GL_STENCIL); |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 525 | if (baseFormat == GL_STENCIL_INDEX) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 526 | /* OK */ |
| 527 | } |
| 528 | else if (ctx->Extensions.EXT_packed_depth_stencil && |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 529 | baseFormat == GL_DEPTH_STENCIL_EXT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 530 | /* OK */ |
| 531 | } |
| 532 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 533 | att->Complete = GL_FALSE; |
Brian Paul | 9f731c8 | 2009-02-17 16:47:54 -0700 | [diff] [blame] | 534 | att_incomplete("bad renderbuffer stencil format"); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 535 | return; |
| 536 | } |
| 537 | } |
| 538 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 539 | else { |
| 540 | ASSERT(att->Type == GL_NONE); |
| 541 | /* complete */ |
| 542 | return; |
| 543 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | |
| 547 | /** |
| 548 | * Test if the given framebuffer object is complete and update its |
| 549 | * Status field with the results. |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 550 | * Calls the ctx->Driver.ValidateFramebuffer() function to allow the |
| 551 | * driver to make hardware-specific validation/completeness checks. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 552 | * Also update the framebuffer's Width and Height fields if the |
| 553 | * framebuffer is complete. |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 554 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 555 | void |
| 556 | _mesa_test_framebuffer_completeness(GLcontext *ctx, struct gl_framebuffer *fb) |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 557 | { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 558 | GLuint numImages; |
| 559 | GLenum intFormat = GL_NONE; /* color buffers' internal format */ |
| 560 | GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 561 | GLint numSamples = -1; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 562 | GLint i; |
Brian Paul | 28b014e | 2006-04-05 03:05:17 +0000 | [diff] [blame] | 563 | GLuint j; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 564 | |
Brian Paul | c726441 | 2005-06-01 00:50:23 +0000 | [diff] [blame] | 565 | assert(fb->Name != 0); |
| 566 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 567 | numImages = 0; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 568 | fb->Width = 0; |
| 569 | fb->Height = 0; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 570 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 571 | /* Start at -2 to more easily loop over all attachment points. |
| 572 | * -2: depth buffer |
| 573 | * -1: stencil buffer |
| 574 | * >=0: color buffer |
| 575 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 576 | for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 577 | struct gl_renderbuffer_attachment *att; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 578 | GLenum f; |
| 579 | |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 580 | /* |
| 581 | * XXX for ARB_fbo, only check color buffers that are named by |
| 582 | * GL_READ_BUFFER and GL_DRAW_BUFFERi. |
| 583 | */ |
| 584 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 585 | /* check for attachment completeness |
| 586 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 587 | if (i == -2) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 588 | att = &fb->Attachment[BUFFER_DEPTH]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 589 | test_attachment_completeness(ctx, GL_DEPTH, att); |
| 590 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 591 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 592 | fbo_incomplete("depth attachment incomplete", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 593 | return; |
| 594 | } |
| 595 | } |
| 596 | else if (i == -1) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 597 | att = &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 598 | test_attachment_completeness(ctx, GL_STENCIL, att); |
| 599 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 600 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 601 | fbo_incomplete("stencil attachment incomplete", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 602 | return; |
| 603 | } |
| 604 | } |
| 605 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 606 | att = &fb->Attachment[BUFFER_COLOR0 + i]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 607 | test_attachment_completeness(ctx, GL_COLOR, att); |
| 608 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 609 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 610 | fbo_incomplete("color attachment incomplete", i); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 611 | return; |
| 612 | } |
| 613 | } |
| 614 | |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 615 | /* get width, height, format of the renderbuffer/texture |
| 616 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 617 | if (att->Type == GL_TEXTURE) { |
Brian Paul | a9fc8ba | 2005-10-05 01:48:07 +0000 | [diff] [blame] | 618 | const struct gl_texture_image *texImg |
| 619 | = att->Texture->Image[att->CubeMapFace][att->TextureLevel]; |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 620 | minWidth = MIN2(minWidth, texImg->Width); |
| 621 | maxWidth = MAX2(maxWidth, texImg->Width); |
| 622 | minHeight = MIN2(minHeight, texImg->Height); |
| 623 | maxHeight = MAX2(maxHeight, texImg->Height); |
Brian Paul | a9fc8ba | 2005-10-05 01:48:07 +0000 | [diff] [blame] | 624 | f = texImg->_BaseFormat; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 625 | numImages++; |
Brian Paul | 9f6ff49 | 2006-03-28 15:24:50 +0000 | [diff] [blame] | 626 | if (f != GL_RGB && f != GL_RGBA && f != GL_DEPTH_COMPONENT |
Eric Anholt | 262cdbd | 2010-05-25 08:00:51 -0700 | [diff] [blame] | 627 | && f != GL_DEPTH_STENCIL_EXT |
| 628 | && (!ctx->Extensions.ARB_framebuffer_object || f != GL_ALPHA)) { |
Brian Paul | ed7f3ae | 2005-06-07 15:03:40 +0000 | [diff] [blame] | 629 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 630 | fbo_incomplete("texture attachment incomplete", -1); |
Brian Paul | ed7f3ae | 2005-06-07 15:03:40 +0000 | [diff] [blame] | 631 | return; |
| 632 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 633 | } |
| 634 | else if (att->Type == GL_RENDERBUFFER_EXT) { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 635 | minWidth = MIN2(minWidth, att->Renderbuffer->Width); |
| 636 | maxWidth = MAX2(minWidth, att->Renderbuffer->Width); |
| 637 | minHeight = MIN2(minHeight, att->Renderbuffer->Height); |
| 638 | maxHeight = MAX2(minHeight, att->Renderbuffer->Height); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 639 | f = att->Renderbuffer->InternalFormat; |
| 640 | numImages++; |
| 641 | } |
| 642 | else { |
| 643 | assert(att->Type == GL_NONE); |
| 644 | continue; |
| 645 | } |
| 646 | |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 647 | if (numSamples < 0) { |
| 648 | /* first buffer */ |
| 649 | numSamples = att->Renderbuffer->NumSamples; |
| 650 | } |
| 651 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 652 | /* Error-check width, height, format, samples |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 653 | */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 654 | if (numImages == 1) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 655 | /* save format, num samples */ |
| 656 | if (i >= 0) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 657 | intFormat = f; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 658 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 659 | } |
| 660 | else { |
Brian Paul | 989edea | 2009-01-22 15:05:13 -0700 | [diff] [blame] | 661 | if (!ctx->Extensions.ARB_framebuffer_object) { |
| 662 | /* check that width, height, format are same */ |
| 663 | if (minWidth != maxWidth || minHeight != maxHeight) { |
| 664 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT; |
| 665 | fbo_incomplete("width or height mismatch", -1); |
| 666 | return; |
| 667 | } |
| 668 | /* check that all color buffer have same format */ |
| 669 | if (intFormat != GL_NONE && f != intFormat) { |
| 670 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; |
| 671 | fbo_incomplete("format mismatch", -1); |
| 672 | return; |
| 673 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 674 | } |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 675 | if (att->Renderbuffer && |
| 676 | att->Renderbuffer->NumSamples != numSamples) { |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 677 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 678 | fbo_incomplete("inconsistant number of samples", i); |
| 679 | return; |
| 680 | } |
| 681 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
Kristian Høgsberg | e88cef3 | 2010-05-24 16:56:12 -0400 | [diff] [blame] | 685 | #if FEATURE_GL |
| 686 | if (ctx->API == API_OPENGL) { |
| 687 | /* Check that all DrawBuffers are present */ |
| 688 | for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) { |
| 689 | if (fb->ColorDrawBuffer[j] != GL_NONE) { |
| 690 | const struct gl_renderbuffer_attachment *att |
| 691 | = _mesa_get_attachment(ctx, fb, fb->ColorDrawBuffer[j]); |
| 692 | assert(att); |
| 693 | if (att->Type == GL_NONE) { |
| 694 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT; |
| 695 | fbo_incomplete("missing drawbuffer", j); |
| 696 | return; |
| 697 | } |
| 698 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 699 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 700 | |
Kristian Høgsberg | e88cef3 | 2010-05-24 16:56:12 -0400 | [diff] [blame] | 701 | /* Check that the ReadBuffer is present */ |
| 702 | if (fb->ColorReadBuffer != GL_NONE) { |
| 703 | const struct gl_renderbuffer_attachment *att |
| 704 | = _mesa_get_attachment(ctx, fb, fb->ColorReadBuffer); |
| 705 | assert(att); |
| 706 | if (att->Type == GL_NONE) { |
| 707 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 708 | fbo_incomplete("missing readbuffer", -1); |
Kristian Høgsberg | e88cef3 | 2010-05-24 16:56:12 -0400 | [diff] [blame] | 709 | return; |
| 710 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 711 | } |
| 712 | } |
Chia-I Wu | 9927d7f | 2009-10-02 15:32:04 +0800 | [diff] [blame] | 713 | #else |
| 714 | (void) j; |
Brian Paul | 868c09a | 2008-08-08 13:06:54 -0600 | [diff] [blame] | 715 | #endif |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 716 | |
| 717 | if (numImages == 0) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 718 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 719 | fbo_incomplete("no attachments", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 720 | return; |
| 721 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 722 | |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 723 | /* Provisionally set status = COMPLETE ... */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 724 | fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT; |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 725 | |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 726 | /* ... but the driver may say the FB is incomplete. |
| 727 | * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED |
| 728 | * if anything. |
| 729 | */ |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 730 | if (ctx->Driver.ValidateFramebuffer) { |
| 731 | ctx->Driver.ValidateFramebuffer(ctx, fb); |
Brian Paul | 1f32c41 | 2009-01-19 17:34:19 -0700 | [diff] [blame] | 732 | if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { |
| 733 | fbo_incomplete("driver marked FBO as incomplete", -1); |
| 734 | } |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | if (fb->_Status == GL_FRAMEBUFFER_COMPLETE_EXT) { |
| 738 | /* |
| 739 | * Note that if ARB_framebuffer_object is supported and the attached |
| 740 | * renderbuffers/textures are different sizes, the framebuffer |
| 741 | * width/height will be set to the smallest width/height. |
| 742 | */ |
| 743 | fb->Width = minWidth; |
| 744 | fb->Height = minHeight; |
Brian Paul | 38768db | 2009-01-27 09:49:27 -0700 | [diff] [blame] | 745 | |
| 746 | /* finally, update the visual info for the framebuffer */ |
| 747 | _mesa_update_framebuffer_visual(fb); |
Brian Paul | 3528f69 | 2009-01-22 15:13:18 -0700 | [diff] [blame] | 748 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 749 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 750 | |
| 751 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 752 | GLboolean GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 753 | _mesa_IsRenderbufferEXT(GLuint renderbuffer) |
| 754 | { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 755 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 756 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 757 | if (renderbuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 758 | struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 759 | if (rb != NULL && rb != &DummyRenderbuffer) |
| 760 | return GL_TRUE; |
| 761 | } |
| 762 | return GL_FALSE; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 766 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 767 | _mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer) |
| 768 | { |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 769 | struct gl_renderbuffer *newRb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 770 | GET_CURRENT_CONTEXT(ctx); |
| 771 | |
| 772 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 773 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 774 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | 4de18fb | 2009-11-02 15:30:51 -0700 | [diff] [blame] | 775 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 776 | return; |
| 777 | } |
| 778 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 779 | /* No need to flush here since the render buffer binding has no |
| 780 | * effect on rendering state. |
| 781 | */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 782 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 783 | if (renderbuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 784 | newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 785 | if (newRb == &DummyRenderbuffer) { |
| 786 | /* ID was reserved, but no real renderbuffer object made yet */ |
| 787 | newRb = NULL; |
| 788 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 789 | else if (!newRb && ctx->Extensions.ARB_framebuffer_object) { |
| 790 | /* All RB IDs must be Gen'd */ |
| 791 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)"); |
| 792 | return; |
| 793 | } |
| 794 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 795 | if (!newRb) { |
| 796 | /* create new renderbuffer object */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 797 | newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 798 | if (!newRb) { |
| 799 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT"); |
| 800 | return; |
| 801 | } |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 802 | ASSERT(newRb->AllocStorage); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 803 | _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb); |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 804 | newRb->RefCount = 1; /* referenced by hash table */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 805 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 806 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 807 | else { |
| 808 | newRb = NULL; |
| 809 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 810 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 811 | ASSERT(newRb != &DummyRenderbuffer); |
| 812 | |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 813 | _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 817 | /** |
| 818 | * If the given renderbuffer is anywhere attached to the framebuffer, detach |
| 819 | * the renderbuffer. |
| 820 | * This is used when a renderbuffer object is deleted. |
| 821 | * The spec calls for unbinding. |
| 822 | */ |
| 823 | static void |
| 824 | detach_renderbuffer(GLcontext *ctx, |
| 825 | struct gl_framebuffer *fb, |
| 826 | struct gl_renderbuffer *rb) |
| 827 | { |
| 828 | GLuint i; |
| 829 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 830 | if (fb->Attachment[i].Renderbuffer == rb) { |
| 831 | _mesa_remove_attachment(ctx, &fb->Attachment[i]); |
| 832 | } |
| 833 | } |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 834 | invalidate_framebuffer(fb); |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 838 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 839 | _mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers) |
| 840 | { |
| 841 | GLint i; |
| 842 | GET_CURRENT_CONTEXT(ctx); |
| 843 | |
| 844 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 845 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 846 | |
| 847 | for (i = 0; i < n; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 848 | if (renderbuffers[i] > 0) { |
| 849 | struct gl_renderbuffer *rb; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 850 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 851 | if (rb) { |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 852 | /* check if deleting currently bound renderbuffer object */ |
| 853 | if (rb == ctx->CurrentRenderbuffer) { |
| 854 | /* bind default */ |
| 855 | ASSERT(rb->RefCount >= 2); |
| 856 | _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); |
| 857 | } |
| 858 | |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 859 | if (ctx->DrawBuffer->Name) { |
| 860 | detach_renderbuffer(ctx, ctx->DrawBuffer, rb); |
| 861 | } |
| 862 | if (ctx->ReadBuffer->Name && ctx->ReadBuffer != ctx->DrawBuffer) { |
| 863 | detach_renderbuffer(ctx, ctx->ReadBuffer, rb); |
| 864 | } |
| 865 | |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 866 | /* Remove from hash table immediately, to free the ID. |
| 867 | * But the object will not be freed until it's no longer |
| 868 | * referenced anywhere else. |
| 869 | */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 870 | _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 871 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 872 | if (rb != &DummyRenderbuffer) { |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 873 | /* no longer referenced by hash table */ |
| 874 | _mesa_reference_renderbuffer(&rb, NULL); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 875 | } |
| 876 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 882 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 883 | _mesa_GenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers) |
| 884 | { |
| 885 | GET_CURRENT_CONTEXT(ctx); |
| 886 | GLuint first; |
| 887 | GLint i; |
| 888 | |
| 889 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 890 | |
| 891 | if (n < 0) { |
| 892 | _mesa_error(ctx, GL_INVALID_VALUE, "glGenRenderbuffersEXT(n)"); |
| 893 | return; |
| 894 | } |
| 895 | |
| 896 | if (!renderbuffers) |
| 897 | return; |
| 898 | |
| 899 | first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n); |
| 900 | |
| 901 | for (i = 0; i < n; i++) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 902 | GLuint name = first + i; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 903 | renderbuffers[i] = name; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 904 | /* insert dummy placeholder into hash table */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 905 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 906 | _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 907 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
| 911 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 912 | /** |
| 913 | * Given an internal format token for a render buffer, return the |
| 914 | * corresponding base format. |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 915 | * This is very similar to _mesa_base_tex_format() but the set of valid |
| 916 | * internal formats is somewhat different. |
| 917 | * |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 918 | * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 919 | * GL_DEPTH_STENCIL_EXT or zero if error. |
Brian Paul | 031f23a | 2010-01-19 17:59:50 -0700 | [diff] [blame] | 920 | * |
| 921 | * XXX in the future when we support red-only and red-green formats |
| 922 | * we'll also return GL_RED and GL_RG. |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 923 | */ |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 924 | GLenum |
| 925 | _mesa_base_fbo_format(GLcontext *ctx, GLenum internalFormat) |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 926 | { |
| 927 | switch (internalFormat) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 928 | case GL_RGB: |
| 929 | case GL_R3_G3_B2: |
| 930 | case GL_RGB4: |
| 931 | case GL_RGB5: |
| 932 | case GL_RGB8: |
| 933 | case GL_RGB10: |
| 934 | case GL_RGB12: |
| 935 | case GL_RGB16: |
| 936 | return GL_RGB; |
| 937 | case GL_RGBA: |
| 938 | case GL_RGBA2: |
| 939 | case GL_RGBA4: |
| 940 | case GL_RGB5_A1: |
| 941 | case GL_RGBA8: |
| 942 | case GL_RGB10_A2: |
| 943 | case GL_RGBA12: |
| 944 | case GL_RGBA16: |
Brian Paul | 8ea6148 | 2010-05-09 18:42:14 -0600 | [diff] [blame] | 945 | case GL_RGBA16_SNORM: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 946 | return GL_RGBA; |
| 947 | case GL_STENCIL_INDEX: |
| 948 | case GL_STENCIL_INDEX1_EXT: |
| 949 | case GL_STENCIL_INDEX4_EXT: |
| 950 | case GL_STENCIL_INDEX8_EXT: |
| 951 | case GL_STENCIL_INDEX16_EXT: |
| 952 | return GL_STENCIL_INDEX; |
| 953 | case GL_DEPTH_COMPONENT: |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 954 | case GL_DEPTH_COMPONENT16: |
| 955 | case GL_DEPTH_COMPONENT24: |
| 956 | case GL_DEPTH_COMPONENT32: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 957 | return GL_DEPTH_COMPONENT; |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 958 | case GL_DEPTH_STENCIL_EXT: |
| 959 | case GL_DEPTH24_STENCIL8_EXT: |
| 960 | if (ctx->Extensions.EXT_packed_depth_stencil) |
| 961 | return GL_DEPTH_STENCIL_EXT; |
| 962 | else |
| 963 | return 0; |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 964 | /* XXX add floating point formats eventually */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 965 | default: |
| 966 | return 0; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 967 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 971 | /** sentinal value, see below */ |
| 972 | #define NO_SAMPLES 1000 |
| 973 | |
| 974 | |
| 975 | /** |
| 976 | * Helper function used by _mesa_RenderbufferStorageEXT() and |
| 977 | * _mesa_RenderbufferStorageMultisample(). |
| 978 | * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT(). |
| 979 | */ |
| 980 | static void |
| 981 | renderbuffer_storage(GLenum target, GLenum internalFormat, |
| 982 | GLsizei width, GLsizei height, GLsizei samples) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 983 | { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 984 | const char *func = samples == NO_SAMPLES ? |
| 985 | "glRenderbufferStorage" : "RenderbufferStorageMultisample"; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 986 | struct gl_renderbuffer *rb; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 987 | GLenum baseFormat; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 988 | GET_CURRENT_CONTEXT(ctx); |
| 989 | |
| 990 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 991 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 992 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 993 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 994 | return; |
| 995 | } |
| 996 | |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 997 | baseFormat = _mesa_base_fbo_format(ctx, internalFormat); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 998 | if (baseFormat == 0) { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 999 | _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat)", func); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1000 | return; |
| 1001 | } |
| 1002 | |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 1003 | if (width < 1 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1004 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(width)", func); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1005 | return; |
| 1006 | } |
| 1007 | |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 1008 | if (height < 1 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1009 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(height)", func); |
| 1010 | return; |
| 1011 | } |
| 1012 | |
| 1013 | if (samples == NO_SAMPLES) { |
| 1014 | /* NumSamples == 0 indicates non-multisampling */ |
| 1015 | samples = 0; |
| 1016 | } |
Brian Paul | ca0d048 | 2010-01-27 17:01:54 -0700 | [diff] [blame] | 1017 | else if (samples > (GLsizei) ctx->Const.MaxSamples) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1018 | /* note: driver may choose to use more samples than what's requested */ |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1019 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(samples)", func); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1020 | return; |
| 1021 | } |
| 1022 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1023 | rb = ctx->CurrentRenderbuffer; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1024 | if (!rb) { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1025 | _mesa_error(ctx, GL_INVALID_OPERATION, func); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1026 | return; |
| 1027 | } |
| 1028 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1029 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 1030 | |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 1031 | if (rb->InternalFormat == internalFormat && |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 1032 | rb->Width == (GLuint) width && |
| 1033 | rb->Height == (GLuint) height) { |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 1034 | /* no change in allocation needed */ |
| 1035 | return; |
| 1036 | } |
| 1037 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1038 | /* These MUST get set by the AllocStorage func */ |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1039 | rb->Format = MESA_FORMAT_NONE; |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1040 | rb->NumSamples = samples; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1041 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1042 | /* Now allocate the storage */ |
| 1043 | ASSERT(rb->AllocStorage); |
| 1044 | if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) { |
| 1045 | /* No error - check/set fields now */ |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1046 | assert(rb->Format != MESA_FORMAT_NONE); |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 1047 | assert(rb->Width == (GLuint) width); |
| 1048 | assert(rb->Height == (GLuint) height); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1049 | rb->InternalFormat = internalFormat; |
Brian Paul | a8dafe7 | 2010-02-25 19:03:55 -0700 | [diff] [blame] | 1050 | rb->_BaseFormat = baseFormat; |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1051 | assert(rb->_BaseFormat != 0); |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1052 | } |
| 1053 | else { |
| 1054 | /* Probably ran out of memory - clear the fields */ |
| 1055 | rb->Width = 0; |
| 1056 | rb->Height = 0; |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1057 | rb->Format = MESA_FORMAT_NONE; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1058 | rb->InternalFormat = GL_NONE; |
| 1059 | rb->_BaseFormat = GL_NONE; |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1060 | rb->NumSamples = 0; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1063 | /* |
| 1064 | test_framebuffer_completeness(ctx, fb); |
| 1065 | */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1066 | /* XXX if this renderbuffer is attached anywhere, invalidate attachment |
| 1067 | * points??? |
| 1068 | */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1071 | |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1072 | #if FEATURE_OES_EGL_image |
| 1073 | void GLAPIENTRY |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1074 | _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1075 | { |
Brian Paul | 51b7992 | 2010-02-24 11:57:26 -0700 | [diff] [blame] | 1076 | struct gl_renderbuffer *rb; |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1077 | GET_CURRENT_CONTEXT(ctx); |
| 1078 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1079 | |
Chia-I Wu | 2002e4d0 | 2010-04-06 17:46:17 +0800 | [diff] [blame] | 1080 | if (!ctx->Extensions.OES_EGL_image) { |
| 1081 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1082 | "glEGLImageTargetRenderbufferStorageOES(unsupported)"); |
| 1083 | return; |
| 1084 | } |
| 1085 | |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1086 | if (target != GL_RENDERBUFFER) { |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1087 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1088 | "EGLImageTargetRenderbufferStorageOES"); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1089 | return; |
| 1090 | } |
| 1091 | |
| 1092 | rb = ctx->CurrentRenderbuffer; |
| 1093 | if (!rb) { |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1094 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1095 | "EGLImageTargetRenderbufferStorageOES"); |
Kristian Høgsberg | d1dc5b1 | 2010-02-11 17:42:30 -0500 | [diff] [blame] | 1096 | return; |
| 1097 | } |
| 1098 | |
| 1099 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 1100 | |
| 1101 | ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image); |
| 1102 | } |
| 1103 | #endif |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1104 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1105 | |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1106 | /** |
| 1107 | * Helper function for _mesa_GetRenderbufferParameterivEXT() and |
| 1108 | * _mesa_GetFramebufferAttachmentParameterivEXT() |
| 1109 | * We have to be careful to respect the base format. For example, if a |
| 1110 | * renderbuffer/texture was created with internalFormat=GL_RGB but the |
| 1111 | * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE |
| 1112 | * we need to return zero. |
| 1113 | */ |
| 1114 | static GLint |
| 1115 | get_component_bits(GLenum pname, GLenum baseFormat, gl_format format) |
| 1116 | { |
| 1117 | switch (pname) { |
| 1118 | case GL_RENDERBUFFER_RED_SIZE_EXT: |
| 1119 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 1120 | case GL_RENDERBUFFER_GREEN_SIZE_EXT: |
| 1121 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 1122 | case GL_RENDERBUFFER_BLUE_SIZE_EXT: |
| 1123 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 1124 | if (baseFormat == GL_RGB || baseFormat == GL_RGBA) |
| 1125 | return _mesa_get_format_bits(format, pname); |
| 1126 | else |
| 1127 | return 0; |
| 1128 | case GL_RENDERBUFFER_ALPHA_SIZE_EXT: |
| 1129 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 1130 | if (baseFormat == GL_RGBA || baseFormat == GL_ALPHA) |
| 1131 | return _mesa_get_format_bits(format, pname); |
| 1132 | else |
| 1133 | return 0; |
| 1134 | case GL_RENDERBUFFER_DEPTH_SIZE_EXT: |
| 1135 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 1136 | if (baseFormat == GL_DEPTH_COMPONENT || baseFormat == GL_DEPTH_STENCIL) |
| 1137 | return _mesa_get_format_bits(format, pname); |
| 1138 | else |
| 1139 | return 0; |
| 1140 | case GL_RENDERBUFFER_STENCIL_SIZE_EXT: |
| 1141 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 1142 | if (baseFormat == GL_STENCIL_INDEX || baseFormat == GL_DEPTH_STENCIL) |
| 1143 | return _mesa_get_format_bits(format, pname); |
| 1144 | else |
| 1145 | return 0; |
| 1146 | default: |
| 1147 | return 0; |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1153 | void GLAPIENTRY |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1154 | _mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat, |
| 1155 | GLsizei width, GLsizei height) |
| 1156 | { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1157 | /* GL_ARB_fbo says calling this function is equivalent to calling |
| 1158 | * glRenderbufferStorageMultisample() with samples=0. We pass in |
| 1159 | * a token value here just for error reporting purposes. |
| 1160 | */ |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1161 | renderbuffer_storage(target, internalFormat, width, height, NO_SAMPLES); |
| 1162 | } |
| 1163 | |
| 1164 | |
| 1165 | void GLAPIENTRY |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1166 | _mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples, |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1167 | GLenum internalFormat, |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1168 | GLsizei width, GLsizei height) |
| 1169 | { |
Brian Paul | 4f3514e | 2009-01-22 15:19:56 -0700 | [diff] [blame] | 1170 | renderbuffer_storage(target, internalFormat, width, height, samples); |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1173 | |
| 1174 | /** |
| 1175 | * OpenGL ES version of glRenderBufferStorage. |
| 1176 | */ |
Kristian Høgsberg | 61d94dd | 2010-04-22 21:11:56 -0400 | [diff] [blame] | 1177 | void GLAPIENTRY |
| 1178 | _es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat, |
| 1179 | GLsizei width, GLsizei height) |
| 1180 | { |
| 1181 | switch (internalFormat) { |
| 1182 | case GL_RGB565: |
| 1183 | /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */ |
| 1184 | /* choose a closest format */ |
| 1185 | internalFormat = GL_RGB5; |
| 1186 | break; |
| 1187 | default: |
| 1188 | break; |
| 1189 | } |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1190 | |
Kristian Høgsberg | 61d94dd | 2010-04-22 21:11:56 -0400 | [diff] [blame] | 1191 | renderbuffer_storage(target, internalFormat, width, height, 0); |
| 1192 | } |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1193 | |
Brian Paul | 23c5b21 | 2010-05-28 13:33:03 -0600 | [diff] [blame] | 1194 | |
Brian Paul | 777a2ef | 2009-01-22 15:17:42 -0700 | [diff] [blame] | 1195 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1196 | _mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params) |
| 1197 | { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1198 | struct gl_renderbuffer *rb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1199 | GET_CURRENT_CONTEXT(ctx); |
| 1200 | |
| 1201 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1202 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1203 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1204 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1205 | "glGetRenderbufferParameterivEXT(target)"); |
| 1206 | return; |
| 1207 | } |
| 1208 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1209 | rb = ctx->CurrentRenderbuffer; |
| 1210 | if (!rb) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1211 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1212 | "glGetRenderbufferParameterivEXT"); |
| 1213 | return; |
| 1214 | } |
| 1215 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1216 | /* No need to flush here since we're just quering state which is |
| 1217 | * not effected by rendering. |
| 1218 | */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1219 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1220 | switch (pname) { |
| 1221 | case GL_RENDERBUFFER_WIDTH_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1222 | *params = rb->Width; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1223 | return; |
| 1224 | case GL_RENDERBUFFER_HEIGHT_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1225 | *params = rb->Height; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1226 | return; |
| 1227 | case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT: |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1228 | *params = rb->InternalFormat; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1229 | return; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1230 | case GL_RENDERBUFFER_RED_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1231 | case GL_RENDERBUFFER_GREEN_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1232 | case GL_RENDERBUFFER_BLUE_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1233 | case GL_RENDERBUFFER_ALPHA_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1234 | case GL_RENDERBUFFER_DEPTH_SIZE_EXT: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1235 | case GL_RENDERBUFFER_STENCIL_SIZE_EXT: |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1236 | *params = get_component_bits(pname, rb->_BaseFormat, rb->Format); |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1237 | break; |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 1238 | case GL_RENDERBUFFER_SAMPLES: |
| 1239 | if (ctx->Extensions.ARB_framebuffer_object) { |
| 1240 | *params = rb->NumSamples; |
| 1241 | break; |
| 1242 | } |
| 1243 | /* fallthrough */ |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1244 | default: |
| 1245 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1246 | "glGetRenderbufferParameterivEXT(target)"); |
| 1247 | return; |
| 1248 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1252 | GLboolean GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1253 | _mesa_IsFramebufferEXT(GLuint framebuffer) |
| 1254 | { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1255 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1256 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 1257 | if (framebuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1258 | struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 1259 | if (rb != NULL && rb != &DummyFramebuffer) |
| 1260 | return GL_TRUE; |
| 1261 | } |
| 1262 | return GL_FALSE; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | |
brian | a492ab7 | 2009-11-10 15:33:31 -0700 | [diff] [blame] | 1266 | /** |
| 1267 | * Check if any of the attachments of the given framebuffer are textures |
| 1268 | * (render to texture). Call ctx->Driver.RenderTexture() for such |
| 1269 | * attachments. |
| 1270 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1271 | static void |
| 1272 | check_begin_texture_render(GLcontext *ctx, struct gl_framebuffer *fb) |
| 1273 | { |
| 1274 | GLuint i; |
| 1275 | ASSERT(ctx->Driver.RenderTexture); |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1276 | |
| 1277 | if (fb->Name == 0) |
| 1278 | return; /* can't render to texture with winsys framebuffers */ |
| 1279 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1280 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 1281 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
| 1282 | struct gl_texture_object *texObj = att->Texture; |
Brian Paul | 9f6ff49 | 2006-03-28 15:24:50 +0000 | [diff] [blame] | 1283 | if (texObj |
Brian Paul | b5d6a8e | 2009-10-12 18:09:32 -0600 | [diff] [blame] | 1284 | && texObj->Image[att->CubeMapFace][att->TextureLevel]) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1285 | ctx->Driver.RenderTexture(ctx, fb, att); |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 1291 | /** |
| 1292 | * Examine all the framebuffer's attachments to see if any are textures. |
| 1293 | * If so, call ctx->Driver.FinishRenderTexture() for each texture to |
| 1294 | * notify the device driver that the texture image may have changed. |
| 1295 | */ |
| 1296 | static void |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1297 | check_end_texture_render(GLcontext *ctx, struct gl_framebuffer *fb) |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 1298 | { |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1299 | if (fb->Name == 0) |
| 1300 | return; /* can't render to texture with winsys framebuffers */ |
| 1301 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 1302 | if (ctx->Driver.FinishRenderTexture) { |
| 1303 | GLuint i; |
| 1304 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 1305 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
Brian | 8b36166 | 2007-11-09 08:55:49 -0700 | [diff] [blame] | 1306 | if (att->Texture && att->Renderbuffer) { |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 1307 | ctx->Driver.FinishRenderTexture(ctx, att); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 1308 | } |
| 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1314 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1315 | _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer) |
| 1316 | { |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1317 | struct gl_framebuffer *newDrawFb, *newReadFb; |
brian | d96e55f | 2009-11-10 15:50:22 -0700 | [diff] [blame] | 1318 | struct gl_framebuffer *oldDrawFb, *oldReadFb; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1319 | GLboolean bindReadBuf, bindDrawBuf; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1320 | GET_CURRENT_CONTEXT(ctx); |
| 1321 | |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 1322 | #ifdef DEBUG |
| 1323 | if (ctx->Extensions.ARB_framebuffer_object) { |
| 1324 | ASSERT(ctx->Extensions.EXT_framebuffer_object); |
| 1325 | ASSERT(ctx->Extensions.EXT_framebuffer_blit); |
| 1326 | } |
| 1327 | #endif |
| 1328 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1329 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1330 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1331 | if (!ctx->Extensions.EXT_framebuffer_object) { |
| 1332 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1333 | "glBindFramebufferEXT(unsupported)"); |
| 1334 | return; |
| 1335 | } |
| 1336 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1337 | switch (target) { |
| 1338 | #if FEATURE_EXT_framebuffer_blit |
| 1339 | case GL_DRAW_FRAMEBUFFER_EXT: |
| 1340 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1341 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
| 1342 | return; |
| 1343 | } |
| 1344 | bindDrawBuf = GL_TRUE; |
| 1345 | bindReadBuf = GL_FALSE; |
| 1346 | break; |
| 1347 | case GL_READ_FRAMEBUFFER_EXT: |
| 1348 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1349 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
| 1350 | return; |
| 1351 | } |
| 1352 | bindDrawBuf = GL_FALSE; |
| 1353 | bindReadBuf = GL_TRUE; |
| 1354 | break; |
| 1355 | #endif |
| 1356 | case GL_FRAMEBUFFER_EXT: |
| 1357 | bindDrawBuf = GL_TRUE; |
| 1358 | bindReadBuf = GL_TRUE; |
| 1359 | break; |
| 1360 | default: |
Brian Paul | eba4ff6 | 2005-09-06 21:22:16 +0000 | [diff] [blame] | 1361 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1362 | return; |
| 1363 | } |
| 1364 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1365 | if (framebuffer) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1366 | /* Binding a user-created framebuffer object */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1367 | newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer); |
| 1368 | if (newDrawFb == &DummyFramebuffer) { |
Brian Paul | 923b6fc | 2005-02-08 04:08:56 +0000 | [diff] [blame] | 1369 | /* ID was reserved, but no real framebuffer object made yet */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1370 | newDrawFb = NULL; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1371 | } |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1372 | else if (!newDrawFb && ctx->Extensions.ARB_framebuffer_object) { |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 1373 | /* All FBO IDs must be Gen'd */ |
| 1374 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)"); |
| 1375 | return; |
| 1376 | } |
| 1377 | |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1378 | if (!newDrawFb) { |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1379 | /* create new framebuffer object */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1380 | newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer); |
| 1381 | if (!newDrawFb) { |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1382 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT"); |
| 1383 | return; |
| 1384 | } |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1385 | _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1386 | } |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1387 | newReadFb = newDrawFb; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1388 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1389 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1390 | /* Binding the window system framebuffer (which was originally set |
| 1391 | * with MakeCurrent). |
| 1392 | */ |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1393 | newDrawFb = ctx->WinSysDrawBuffer; |
| 1394 | newReadFb = ctx->WinSysReadBuffer; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1397 | ASSERT(newDrawFb); |
| 1398 | ASSERT(newDrawFb != &DummyFramebuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1399 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1400 | /* save pointers to current/old framebuffers */ |
brian | d96e55f | 2009-11-10 15:50:22 -0700 | [diff] [blame] | 1401 | oldDrawFb = ctx->DrawBuffer; |
| 1402 | oldReadFb = ctx->ReadBuffer; |
| 1403 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1404 | /* check if really changing bindings */ |
| 1405 | if (oldDrawFb == newDrawFb) |
| 1406 | bindDrawBuf = GL_FALSE; |
| 1407 | if (oldReadFb == newReadFb) |
| 1408 | bindReadBuf = GL_FALSE; |
| 1409 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1410 | /* |
Brian Paul | 1614463 | 2009-02-26 14:49:24 -0700 | [diff] [blame] | 1411 | * OK, now bind the new Draw/Read framebuffers, if they're changing. |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1412 | * |
| 1413 | * We also check if we're beginning and/or ending render-to-texture. |
| 1414 | * When a framebuffer with texture attachments is unbound, call |
| 1415 | * ctx->Driver.FinishRenderTexture(). |
| 1416 | * When a framebuffer with texture attachments is bound, call |
| 1417 | * ctx->Driver.RenderTexture(). |
| 1418 | * |
| 1419 | * Note that if the ReadBuffer has texture attachments we don't consider |
| 1420 | * that a render-to-texture case. |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1421 | */ |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1422 | if (bindReadBuf) { |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1423 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
brian | bc569cd | 2009-11-10 16:00:35 -0700 | [diff] [blame] | 1424 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1425 | /* check if old readbuffer was render-to-texture */ |
| 1426 | check_end_texture_render(ctx, oldReadFb); |
| 1427 | |
| 1428 | _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb); |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | if (bindDrawBuf) { |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1432 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian | 32d86eb | 2007-08-16 18:52:48 +0100 | [diff] [blame] | 1433 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1434 | /* check if old read/draw buffers were render-to-texture */ |
| 1435 | if (!bindReadBuf) |
| 1436 | check_end_texture_render(ctx, oldReadFb); |
brian | bc569cd | 2009-11-10 16:00:35 -0700 | [diff] [blame] | 1437 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1438 | if (oldDrawFb != oldReadFb) |
| 1439 | check_end_texture_render(ctx, oldDrawFb); |
brian | bc569cd | 2009-11-10 16:00:35 -0700 | [diff] [blame] | 1440 | |
brian | a65b84d | 2009-11-10 18:02:03 -0700 | [diff] [blame] | 1441 | /* check if newly bound framebuffer has any texture attachments */ |
| 1442 | check_begin_texture_render(ctx, newDrawFb); |
| 1443 | |
| 1444 | _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb); |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1445 | } |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 1446 | |
Brian Paul | 1614463 | 2009-02-26 14:49:24 -0700 | [diff] [blame] | 1447 | if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) { |
brian | e6f60d3 | 2009-11-10 15:47:34 -0700 | [diff] [blame] | 1448 | ctx->Driver.BindFramebuffer(ctx, target, newDrawFb, newReadFb); |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 1449 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1453 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1454 | _mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers) |
| 1455 | { |
| 1456 | GLint i; |
| 1457 | GET_CURRENT_CONTEXT(ctx); |
| 1458 | |
| 1459 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1460 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1461 | |
| 1462 | for (i = 0; i < n; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1463 | if (framebuffers[i] > 0) { |
| 1464 | struct gl_framebuffer *fb; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1465 | fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1466 | if (fb) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1467 | ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]); |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1468 | |
| 1469 | /* check if deleting currently bound framebuffer object */ |
Erik Wien | 68ca19a | 2010-01-26 13:19:30 -0700 | [diff] [blame] | 1470 | if (ctx->Extensions.EXT_framebuffer_blit) { |
| 1471 | /* separate draw/read binding points */ |
| 1472 | if (fb == ctx->DrawBuffer) { |
| 1473 | /* bind default */ |
| 1474 | ASSERT(fb->RefCount >= 2); |
| 1475 | _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); |
| 1476 | } |
| 1477 | if (fb == ctx->ReadBuffer) { |
| 1478 | /* bind default */ |
| 1479 | ASSERT(fb->RefCount >= 2); |
| 1480 | _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); |
| 1481 | } |
Brian Paul | d0f13fa | 2009-01-21 11:17:45 -0700 | [diff] [blame] | 1482 | } |
Erik Wien | 68ca19a | 2010-01-26 13:19:30 -0700 | [diff] [blame] | 1483 | else { |
| 1484 | /* only one binding point for read/draw buffers */ |
| 1485 | if (fb == ctx->DrawBuffer || fb == ctx->ReadBuffer) { |
| 1486 | /* bind default */ |
| 1487 | ASSERT(fb->RefCount >= 2); |
| 1488 | _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
| 1489 | } |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1492 | /* remove from hash table immediately, to free the ID */ |
| 1493 | _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1494 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1495 | if (fb != &DummyFramebuffer) { |
| 1496 | /* But the object will not be freed until it's no longer |
| 1497 | * bound in any context. |
| 1498 | */ |
Brian Paul | d522944 | 2009-02-09 08:30:55 -0700 | [diff] [blame] | 1499 | _mesa_reference_framebuffer(&fb, NULL); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1500 | } |
| 1501 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1507 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1508 | _mesa_GenFramebuffersEXT(GLsizei n, GLuint *framebuffers) |
| 1509 | { |
| 1510 | GET_CURRENT_CONTEXT(ctx); |
| 1511 | GLuint first; |
| 1512 | GLint i; |
| 1513 | |
| 1514 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1515 | |
| 1516 | if (n < 0) { |
| 1517 | _mesa_error(ctx, GL_INVALID_VALUE, "glGenFramebuffersEXT(n)"); |
| 1518 | return; |
| 1519 | } |
| 1520 | |
| 1521 | if (!framebuffers) |
| 1522 | return; |
| 1523 | |
| 1524 | first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n); |
| 1525 | |
| 1526 | for (i = 0; i < n; i++) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1527 | GLuint name = first + i; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1528 | framebuffers[i] = name; |
| 1529 | /* insert dummy placeholder into hash table */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1530 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1531 | _mesa_HashInsert(ctx->Shared->FrameBuffers, name, &DummyFramebuffer); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1532 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | |
| 1537 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1538 | GLenum GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1539 | _mesa_CheckFramebufferStatusEXT(GLenum target) |
| 1540 | { |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1541 | struct gl_framebuffer *buffer; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1542 | GET_CURRENT_CONTEXT(ctx); |
| 1543 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1544 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1545 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1546 | switch (target) { |
| 1547 | #if FEATURE_EXT_framebuffer_blit |
| 1548 | case GL_DRAW_FRAMEBUFFER_EXT: |
| 1549 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1550 | _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)"); |
| 1551 | return 0; |
| 1552 | } |
| 1553 | buffer = ctx->DrawBuffer; |
| 1554 | break; |
| 1555 | case GL_READ_FRAMEBUFFER_EXT: |
| 1556 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1557 | _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)"); |
| 1558 | return 0; |
| 1559 | } |
| 1560 | buffer = ctx->ReadBuffer; |
| 1561 | break; |
| 1562 | #endif |
| 1563 | case GL_FRAMEBUFFER_EXT: |
| 1564 | buffer = ctx->DrawBuffer; |
| 1565 | break; |
| 1566 | default: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1567 | _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)"); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1568 | return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1571 | if (buffer->Name == 0) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1572 | /* The window system / default framebuffer is always complete */ |
| 1573 | return GL_FRAMEBUFFER_COMPLETE_EXT; |
| 1574 | } |
| 1575 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1576 | /* No need to flush here */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1577 | |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 1578 | if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) { |
| 1579 | _mesa_test_framebuffer_completeness(ctx, buffer); |
| 1580 | } |
| 1581 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1582 | return buffer->_Status; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | |
| 1586 | |
| 1587 | /** |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1588 | * Common code called by glFramebufferTexture1D/2D/3DEXT(). |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1589 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1590 | static void |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1591 | framebuffer_texture(GLcontext *ctx, const char *caller, GLenum target, |
| 1592 | GLenum attachment, GLenum textarget, GLuint texture, |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1593 | GLint level, GLint zoffset) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1594 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1595 | struct gl_renderbuffer_attachment *att; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1596 | struct gl_texture_object *texObj = NULL; |
| 1597 | struct gl_framebuffer *fb; |
Brian Paul | 5fec84a | 2009-01-29 15:01:09 -0700 | [diff] [blame] | 1598 | GLboolean error = GL_FALSE; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1599 | |
| 1600 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1601 | |
Brian Paul | 5fec84a | 2009-01-29 15:01:09 -0700 | [diff] [blame] | 1602 | switch (target) { |
| 1603 | case GL_READ_FRAMEBUFFER_EXT: |
| 1604 | error = !ctx->Extensions.EXT_framebuffer_blit; |
| 1605 | fb = ctx->ReadBuffer; |
| 1606 | break; |
| 1607 | case GL_DRAW_FRAMEBUFFER_EXT: |
| 1608 | error = !ctx->Extensions.EXT_framebuffer_blit; |
| 1609 | /* fall-through */ |
| 1610 | case GL_FRAMEBUFFER_EXT: |
| 1611 | fb = ctx->DrawBuffer; |
| 1612 | break; |
| 1613 | default: |
| 1614 | error = GL_TRUE; |
| 1615 | } |
| 1616 | |
| 1617 | if (error) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1618 | _mesa_error(ctx, GL_INVALID_ENUM, |
Brian Paul | 5fec84a | 2009-01-29 15:01:09 -0700 | [diff] [blame] | 1619 | "glFramebufferTexture%sEXT(target=0x%x)", caller, target); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1620 | return; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1621 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1622 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1623 | ASSERT(fb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1624 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1625 | /* check framebuffer binding */ |
| 1626 | if (fb->Name == 0) { |
| 1627 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1628 | "glFramebufferTexture%sEXT", caller); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1629 | return; |
| 1630 | } |
| 1631 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1632 | |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1633 | /* The textarget, level, and zoffset parameters are only validated if |
| 1634 | * texture is non-zero. |
| 1635 | */ |
| 1636 | if (texture) { |
| 1637 | GLboolean err = GL_TRUE; |
| 1638 | |
| 1639 | texObj = _mesa_lookup_texture(ctx, texture); |
| 1640 | if (texObj != NULL) { |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 1641 | if (textarget == 0) { |
Brian Paul | 7a2e32d | 2010-03-10 10:54:24 -0700 | [diff] [blame] | 1642 | /* XXX what's the purpose of this? */ |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 1643 | err = (texObj->Target != GL_TEXTURE_3D) && |
| 1644 | (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT) && |
| 1645 | (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT); |
| 1646 | } |
| 1647 | else { |
| 1648 | err = (texObj->Target == GL_TEXTURE_CUBE_MAP) |
| 1649 | ? !IS_CUBE_FACE(textarget) |
| 1650 | : (texObj->Target != textarget); |
| 1651 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1652 | } |
Brian Paul | 7a2e32d | 2010-03-10 10:54:24 -0700 | [diff] [blame] | 1653 | else { |
| 1654 | /* can't render to a non-existant texture */ |
| 1655 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1656 | "glFramebufferTexture%sEXT(non existant texture)", |
| 1657 | caller); |
| 1658 | return; |
| 1659 | } |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1660 | |
| 1661 | if (err) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1662 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1663 | "glFramebufferTexture%sEXT(texture target mismatch)", |
| 1664 | caller); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1665 | return; |
| 1666 | } |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1667 | |
| 1668 | if (texObj->Target == GL_TEXTURE_3D) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1669 | const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); |
| 1670 | if (zoffset < 0 || zoffset >= maxSize) { |
| 1671 | _mesa_error(ctx, GL_INVALID_VALUE, |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 1672 | "glFramebufferTexture%sEXT(zoffset)", caller); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1673 | return; |
| 1674 | } |
| 1675 | } |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 1676 | else if ((texObj->Target == GL_TEXTURE_1D_ARRAY_EXT) || |
| 1677 | (texObj->Target == GL_TEXTURE_2D_ARRAY_EXT)) { |
| 1678 | if (zoffset < 0 || zoffset >= ctx->Const.MaxArrayTextureLayers) { |
| 1679 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1680 | "glFramebufferTexture%sEXT(layer)", caller); |
| 1681 | return; |
| 1682 | } |
| 1683 | } |
| 1684 | |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1685 | if ((level < 0) || |
| 1686 | (level >= _mesa_max_texture_levels(ctx, texObj->Target))) { |
| 1687 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1688 | "glFramebufferTexture%sEXT(level)", caller); |
| 1689 | return; |
| 1690 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | att = _mesa_get_attachment(ctx, fb, attachment); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1694 | if (att == NULL) { |
| 1695 | _mesa_error(ctx, GL_INVALID_ENUM, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1696 | "glFramebufferTexture%sEXT(attachment)", caller); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1697 | return; |
| 1698 | } |
| 1699 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1700 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1701 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1702 | _glthread_LOCK_MUTEX(fb->Mutex); |
| 1703 | if (texObj) { |
| 1704 | _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget, |
| 1705 | level, zoffset); |
Brian Paul | 2897cee | 2009-01-29 09:20:18 -0700 | [diff] [blame] | 1706 | /* Set the render-to-texture flag. We'll check this flag in |
| 1707 | * glTexImage() and friends to determine if we need to revalidate |
| 1708 | * any FBOs that might be rendering into this texture. |
| 1709 | * This flag never gets cleared since it's non-trivial to determine |
| 1710 | * when all FBOs might be done rendering to this texture. That's OK |
| 1711 | * though since it's uncommon to render to a texture then repeatedly |
| 1712 | * call glTexImage() to change images in the texture. |
| 1713 | */ |
| 1714 | texObj->_RenderToTexture = GL_TRUE; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1715 | } |
| 1716 | else { |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 1717 | _mesa_remove_attachment(ctx, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1718 | } |
Brian Paul | 7296636 | 2009-01-21 16:28:38 -0700 | [diff] [blame] | 1719 | |
| 1720 | invalidate_framebuffer(fb); |
| 1721 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1722 | _glthread_UNLOCK_MUTEX(fb->Mutex); |
| 1723 | } |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | void GLAPIENTRY |
| 1728 | _mesa_FramebufferTexture1DEXT(GLenum target, GLenum attachment, |
| 1729 | GLenum textarget, GLuint texture, GLint level) |
| 1730 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1731 | GET_CURRENT_CONTEXT(ctx); |
| 1732 | |
| 1733 | if ((texture != 0) && (textarget != GL_TEXTURE_1D)) { |
| 1734 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1735 | "glFramebufferTexture1DEXT(textarget)"); |
| 1736 | return; |
| 1737 | } |
| 1738 | |
| 1739 | framebuffer_texture(ctx, "1D", target, attachment, textarget, texture, |
| 1740 | level, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1744 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1745 | _mesa_FramebufferTexture2DEXT(GLenum target, GLenum attachment, |
| 1746 | GLenum textarget, GLuint texture, GLint level) |
| 1747 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1748 | GET_CURRENT_CONTEXT(ctx); |
| 1749 | |
| 1750 | if ((texture != 0) && |
| 1751 | (textarget != GL_TEXTURE_2D) && |
| 1752 | (textarget != GL_TEXTURE_RECTANGLE_ARB) && |
| 1753 | (!IS_CUBE_FACE(textarget))) { |
| 1754 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Brian Paul | 5fec84a | 2009-01-29 15:01:09 -0700 | [diff] [blame] | 1755 | "glFramebufferTexture2DEXT(textarget=0x%x)", textarget); |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1756 | return; |
| 1757 | } |
| 1758 | |
| 1759 | framebuffer_texture(ctx, "2D", target, attachment, textarget, texture, |
| 1760 | level, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1764 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1765 | _mesa_FramebufferTexture3DEXT(GLenum target, GLenum attachment, |
| 1766 | GLenum textarget, GLuint texture, |
| 1767 | GLint level, GLint zoffset) |
| 1768 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1769 | GET_CURRENT_CONTEXT(ctx); |
| 1770 | |
| 1771 | if ((texture != 0) && (textarget != GL_TEXTURE_3D)) { |
| 1772 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1773 | "glFramebufferTexture3DEXT(textarget)"); |
| 1774 | return; |
| 1775 | } |
| 1776 | |
| 1777 | framebuffer_texture(ctx, "3D", target, attachment, textarget, texture, |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1778 | level, zoffset); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1782 | void GLAPIENTRY |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 1783 | _mesa_FramebufferTextureLayerEXT(GLenum target, GLenum attachment, |
| 1784 | GLuint texture, GLint level, GLint layer) |
| 1785 | { |
| 1786 | GET_CURRENT_CONTEXT(ctx); |
| 1787 | |
| 1788 | framebuffer_texture(ctx, "Layer", target, attachment, 0, texture, |
| 1789 | level, layer); |
| 1790 | } |
| 1791 | |
| 1792 | |
| 1793 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1794 | _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment, |
| 1795 | GLenum renderbufferTarget, |
| 1796 | GLuint renderbuffer) |
| 1797 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1798 | struct gl_renderbuffer_attachment *att; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1799 | struct gl_framebuffer *fb; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1800 | struct gl_renderbuffer *rb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1801 | GET_CURRENT_CONTEXT(ctx); |
| 1802 | |
| 1803 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1804 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1805 | switch (target) { |
| 1806 | #if FEATURE_EXT_framebuffer_blit |
| 1807 | case GL_DRAW_FRAMEBUFFER_EXT: |
| 1808 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1809 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1810 | "glFramebufferRenderbufferEXT(target)"); |
| 1811 | return; |
| 1812 | } |
| 1813 | fb = ctx->DrawBuffer; |
| 1814 | break; |
| 1815 | case GL_READ_FRAMEBUFFER_EXT: |
| 1816 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1817 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1818 | "glFramebufferRenderbufferEXT(target)"); |
| 1819 | return; |
| 1820 | } |
| 1821 | fb = ctx->ReadBuffer; |
| 1822 | break; |
| 1823 | #endif |
| 1824 | case GL_FRAMEBUFFER_EXT: |
| 1825 | fb = ctx->DrawBuffer; |
| 1826 | break; |
| 1827 | default: |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1828 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1829 | "glFramebufferRenderbufferEXT(target)"); |
| 1830 | return; |
| 1831 | } |
| 1832 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1833 | if (renderbufferTarget != GL_RENDERBUFFER_EXT) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1834 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1835 | "glFramebufferRenderbufferEXT(renderbufferTarget)"); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1836 | return; |
| 1837 | } |
| 1838 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1839 | if (fb->Name == 0) { |
Brian Paul | ab8ef28 | 2005-09-07 23:21:59 +0000 | [diff] [blame] | 1840 | /* Can't attach new renderbuffers to a window system framebuffer */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1841 | _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT"); |
| 1842 | return; |
| 1843 | } |
| 1844 | |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 1845 | att = _mesa_get_attachment(ctx, fb, attachment); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1846 | if (att == NULL) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1847 | _mesa_error(ctx, GL_INVALID_ENUM, |
Brian Paul | 9b50cea | 2009-10-23 11:34:14 -0600 | [diff] [blame] | 1848 | "glFramebufferRenderbufferEXT(invalid attachment %s)", |
| 1849 | _mesa_lookup_enum_by_nr(attachment)); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1850 | return; |
| 1851 | } |
| 1852 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1853 | if (renderbuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1854 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1855 | if (!rb) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1856 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Brian Paul | 9b50cea | 2009-10-23 11:34:14 -0600 | [diff] [blame] | 1857 | "glFramebufferRenderbufferEXT(non-existant" |
| 1858 | " renderbuffer %u)", renderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1859 | return; |
| 1860 | } |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1861 | } |
| 1862 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1863 | /* remove renderbuffer attachment */ |
| 1864 | rb = NULL; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1865 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1866 | |
Brian Paul | a504f23 | 2010-05-27 13:05:23 -0600 | [diff] [blame] | 1867 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT && |
| 1868 | rb && rb->Format != MESA_FORMAT_NONE) { |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 1869 | /* make sure the renderbuffer is a depth/stencil format */ |
Brian Paul | a504f23 | 2010-05-27 13:05:23 -0600 | [diff] [blame] | 1870 | const GLenum baseFormat = _mesa_get_format_base_format(rb->Format); |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 1871 | if (baseFormat != GL_DEPTH_STENCIL) { |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 1872 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1873 | "glFramebufferRenderbufferEXT(renderbuffer" |
| 1874 | " is not DEPTH_STENCIL format)"); |
| 1875 | return; |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1880 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1881 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1882 | assert(ctx->Driver.FramebufferRenderbuffer); |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 1883 | ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb); |
Brian Paul | 2e01918 | 2006-03-07 01:43:52 +0000 | [diff] [blame] | 1884 | |
| 1885 | /* Some subsequent GL commands may depend on the framebuffer's visual |
| 1886 | * after the binding is updated. Update visual info now. |
| 1887 | */ |
| 1888 | _mesa_update_framebuffer_visual(fb); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1892 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1893 | _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, |
| 1894 | GLenum pname, GLint *params) |
| 1895 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1896 | const struct gl_renderbuffer_attachment *att; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1897 | struct gl_framebuffer *buffer; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1898 | GET_CURRENT_CONTEXT(ctx); |
| 1899 | |
| 1900 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1901 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1902 | switch (target) { |
| 1903 | #if FEATURE_EXT_framebuffer_blit |
| 1904 | case GL_DRAW_FRAMEBUFFER_EXT: |
| 1905 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1906 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1907 | "glGetFramebufferAttachmentParameterivEXT(target)"); |
| 1908 | return; |
| 1909 | } |
| 1910 | buffer = ctx->DrawBuffer; |
| 1911 | break; |
| 1912 | case GL_READ_FRAMEBUFFER_EXT: |
| 1913 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1914 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1915 | "glGetFramebufferAttachmentParameterivEXT(target)"); |
| 1916 | return; |
| 1917 | } |
| 1918 | buffer = ctx->ReadBuffer; |
| 1919 | break; |
| 1920 | #endif |
| 1921 | case GL_FRAMEBUFFER_EXT: |
| 1922 | buffer = ctx->DrawBuffer; |
| 1923 | break; |
| 1924 | default: |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1925 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1926 | "glGetFramebufferAttachmentParameterivEXT(target)"); |
| 1927 | return; |
| 1928 | } |
| 1929 | |
Brian Paul | 61ec205 | 2010-06-22 08:37:44 -0600 | [diff] [blame] | 1930 | if (buffer->Name == 0) { |
| 1931 | /* the default / window-system FBO */ |
| 1932 | att = _mesa_get_fb0_attachment(ctx, buffer, attachment); |
| 1933 | } |
| 1934 | else { |
| 1935 | /* user-created framebuffer FBO */ |
| 1936 | att = _mesa_get_attachment(ctx, buffer, attachment); |
| 1937 | } |
| 1938 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1939 | if (att == NULL) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1940 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1941 | "glGetFramebufferAttachmentParameterivEXT(attachment)"); |
| 1942 | return; |
| 1943 | } |
| 1944 | |
Brian Paul | 3059007 | 2009-01-21 11:06:11 -0700 | [diff] [blame] | 1945 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 1946 | /* the depth and stencil attachments must point to the same buffer */ |
| 1947 | const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt; |
| 1948 | depthAtt = _mesa_get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT); |
| 1949 | stencilAtt = _mesa_get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT); |
| 1950 | if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) { |
| 1951 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1952 | "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL" |
| 1953 | " attachments differ)"); |
| 1954 | return; |
| 1955 | } |
| 1956 | } |
| 1957 | |
Brian Paul | 800e553 | 2009-11-02 15:39:39 -0700 | [diff] [blame] | 1958 | /* No need to flush here */ |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1959 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1960 | switch (pname) { |
| 1961 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1962 | *params = att->Type; |
| 1963 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1964 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1965 | if (att->Type == GL_RENDERBUFFER_EXT) { |
| 1966 | *params = att->Renderbuffer->Name; |
| 1967 | } |
| 1968 | else if (att->Type == GL_TEXTURE) { |
| 1969 | *params = att->Texture->Name; |
| 1970 | } |
| 1971 | else { |
| 1972 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1973 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 1974 | } |
| 1975 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1976 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1977 | if (att->Type == GL_TEXTURE) { |
| 1978 | *params = att->TextureLevel; |
| 1979 | } |
| 1980 | else { |
| 1981 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1982 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 1983 | } |
| 1984 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1985 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1986 | if (att->Type == GL_TEXTURE) { |
Brian Paul | f1e4ca7 | 2008-08-06 08:39:54 -0600 | [diff] [blame] | 1987 | if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) { |
| 1988 | *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace; |
| 1989 | } |
| 1990 | else { |
| 1991 | *params = 0; |
| 1992 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1993 | } |
| 1994 | else { |
| 1995 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1996 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 1997 | } |
| 1998 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1999 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2000 | if (att->Type == GL_TEXTURE) { |
Brian Paul | f1e4ca7 | 2008-08-06 08:39:54 -0600 | [diff] [blame] | 2001 | if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) { |
| 2002 | *params = att->Zoffset; |
| 2003 | } |
| 2004 | else { |
| 2005 | *params = 0; |
| 2006 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 2007 | } |
| 2008 | else { |
| 2009 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2010 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2011 | } |
| 2012 | return; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2013 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 2014 | if (!ctx->Extensions.ARB_framebuffer_object) { |
| 2015 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2016 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2017 | } |
| 2018 | else { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2019 | *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format); |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2020 | } |
| 2021 | return; |
| 2022 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 2023 | if (!ctx->Extensions.ARB_framebuffer_object) { |
| 2024 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2025 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2026 | return; |
| 2027 | } |
| 2028 | else { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2029 | gl_format format = att->Renderbuffer->Format; |
| 2030 | if (format == MESA_FORMAT_CI8 || format == MESA_FORMAT_S8) { |
| 2031 | /* special cases */ |
| 2032 | *params = GL_INDEX; |
| 2033 | } |
| 2034 | else { |
| 2035 | *params = _mesa_get_format_datatype(format); |
| 2036 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2037 | } |
| 2038 | return; |
| 2039 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2040 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2041 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2042 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2043 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2044 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 2045 | if (!ctx->Extensions.ARB_framebuffer_object) { |
| 2046 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2047 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2048 | } |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2049 | else if (att->Texture) { |
| 2050 | const struct gl_texture_image *texImage = |
| 2051 | _mesa_select_tex_image(ctx, att->Texture, att->Texture->Target, |
| 2052 | att->TextureLevel); |
| 2053 | if (texImage) { |
| 2054 | *params = get_component_bits(pname, texImage->_BaseFormat, |
| 2055 | texImage->TexFormat); |
| 2056 | } |
| 2057 | else { |
| 2058 | *params = 0; |
| 2059 | } |
| 2060 | } |
| 2061 | else if (att->Renderbuffer) { |
| 2062 | *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat, |
| 2063 | att->Renderbuffer->Format); |
| 2064 | } |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2065 | else { |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2066 | *params = 0; |
Brian Paul | 1bc59bf | 2009-01-22 15:07:34 -0700 | [diff] [blame] | 2067 | } |
| 2068 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2069 | default: |
| 2070 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 2071 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 2072 | return; |
| 2073 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 2077 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2078 | _mesa_GenerateMipmapEXT(GLenum target) |
| 2079 | { |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2080 | struct gl_texture_object *texObj; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2081 | GET_CURRENT_CONTEXT(ctx); |
| 2082 | |
| 2083 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 2084 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2085 | |
| 2086 | switch (target) { |
| 2087 | case GL_TEXTURE_1D: |
| 2088 | case GL_TEXTURE_2D: |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2089 | case GL_TEXTURE_3D: |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2090 | case GL_TEXTURE_CUBE_MAP: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 2091 | /* OK, legal value */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2092 | break; |
| 2093 | default: |
| 2094 | _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target)"); |
| 2095 | return; |
| 2096 | } |
| 2097 | |
Brian Paul | a719395 | 2009-11-16 08:21:28 -0700 | [diff] [blame] | 2098 | texObj = _mesa_get_current_tex_object(ctx, target); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 2099 | |
Brian Paul | 652828e | 2009-11-16 08:25:17 -0700 | [diff] [blame] | 2100 | if (texObj->BaseLevel >= texObj->MaxLevel) { |
| 2101 | /* nothing to do */ |
| 2102 | return; |
| 2103 | } |
| 2104 | |
Keith Whitwell | 5ac93f8 | 2006-11-01 14:21:57 +0000 | [diff] [blame] | 2105 | _mesa_lock_texture(ctx, texObj); |
Eric Anholt | f849d36 | 2008-12-06 21:14:56 -0800 | [diff] [blame] | 2106 | if (target == GL_TEXTURE_CUBE_MAP) { |
Brian Paul | ef6ee07 | 2009-09-15 18:09:03 -0600 | [diff] [blame] | 2107 | GLuint face; |
Eric Anholt | f849d36 | 2008-12-06 21:14:56 -0800 | [diff] [blame] | 2108 | for (face = 0; face < 6; face++) |
| 2109 | ctx->Driver.GenerateMipmap(ctx, |
| 2110 | GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face, |
| 2111 | texObj); |
Brian Paul | ef6ee07 | 2009-09-15 18:09:03 -0600 | [diff] [blame] | 2112 | } |
| 2113 | else { |
Eric Anholt | f849d36 | 2008-12-06 21:14:56 -0800 | [diff] [blame] | 2114 | ctx->Driver.GenerateMipmap(ctx, target, texObj); |
| 2115 | } |
Keith Whitwell | 5ac93f8 | 2006-11-01 14:21:57 +0000 | [diff] [blame] | 2116 | _mesa_unlock_texture(ctx, texObj); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 2117 | } |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2118 | |
| 2119 | |
| 2120 | #if FEATURE_EXT_framebuffer_blit |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2121 | |
| 2122 | static const struct gl_renderbuffer_attachment * |
| 2123 | find_attachment(const struct gl_framebuffer *fb, const struct gl_renderbuffer *rb) |
| 2124 | { |
| 2125 | GLuint i; |
| 2126 | for (i = 0; i < Elements(fb->Attachment); i++) { |
| 2127 | if (fb->Attachment[i].Renderbuffer == rb) |
| 2128 | return &fb->Attachment[i]; |
| 2129 | } |
| 2130 | return NULL; |
| 2131 | } |
| 2132 | |
| 2133 | |
| 2134 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2135 | /** |
| 2136 | * Blit rectangular region, optionally from one framebuffer to another. |
| 2137 | * |
| 2138 | * Note, if the src buffer is multisampled and the dest is not, this is |
| 2139 | * when the samples must be resolved to a single color. |
| 2140 | */ |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2141 | void GLAPIENTRY |
| 2142 | _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 2143 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 2144 | GLbitfield mask, GLenum filter) |
| 2145 | { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2146 | const GLbitfield legalMaskBits = (GL_COLOR_BUFFER_BIT | |
| 2147 | GL_DEPTH_BUFFER_BIT | |
| 2148 | GL_STENCIL_BUFFER_BIT); |
| 2149 | const struct gl_framebuffer *readFb, *drawFb; |
| 2150 | const struct gl_renderbuffer *colorReadRb, *colorDrawRb; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2151 | GET_CURRENT_CONTEXT(ctx); |
| 2152 | |
| 2153 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 2154 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 2155 | |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2156 | if (ctx->NewState) { |
| 2157 | _mesa_update_state(ctx); |
| 2158 | } |
| 2159 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2160 | readFb = ctx->ReadBuffer; |
| 2161 | drawFb = ctx->DrawBuffer; |
| 2162 | |
| 2163 | if (!readFb || !drawFb) { |
| 2164 | /* This will normally never happen but someday we may want to |
| 2165 | * support MakeCurrent() with no drawables. |
| 2166 | */ |
| 2167 | return; |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2170 | /* check for complete framebuffers */ |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2171 | if (drawFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT || |
| 2172 | readFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2173 | _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, |
| 2174 | "glBlitFramebufferEXT(incomplete draw/read buffers)"); |
| 2175 | return; |
| 2176 | } |
| 2177 | |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2178 | if (filter != GL_NEAREST && filter != GL_LINEAR) { |
| 2179 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(filter)"); |
| 2180 | return; |
| 2181 | } |
| 2182 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2183 | if (mask & ~legalMaskBits) { |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2184 | _mesa_error( ctx, GL_INVALID_VALUE, "glBlitFramebufferEXT(mask)"); |
| 2185 | return; |
| 2186 | } |
| 2187 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2188 | /* depth/stencil must be blitted with nearest filtering */ |
| 2189 | if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) |
| 2190 | && filter != GL_NEAREST) { |
| 2191 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2192 | "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter"); |
| 2193 | return; |
| 2194 | } |
| 2195 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2196 | /* get color read/draw renderbuffers */ |
| 2197 | if (mask & GL_COLOR_BUFFER_BIT) { |
| 2198 | colorReadRb = readFb->_ColorReadBuffer; |
| 2199 | colorDrawRb = drawFb->_ColorDrawBuffers[0]; |
| 2200 | } |
| 2201 | else { |
| 2202 | colorReadRb = colorDrawRb = NULL; |
| 2203 | } |
| 2204 | |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2205 | if (mask & GL_STENCIL_BUFFER_BIT) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2206 | struct gl_renderbuffer *readRb = readFb->_StencilBuffer; |
| 2207 | struct gl_renderbuffer *drawRb = drawFb->_StencilBuffer; |
Brian Paul | dcebe22 | 2009-08-05 13:44:59 -0600 | [diff] [blame] | 2208 | if (!readRb || |
| 2209 | !drawRb || |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2210 | _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) != |
| 2211 | _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) { |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2212 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2213 | "glBlitFramebufferEXT(stencil buffer size mismatch"); |
| 2214 | return; |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | if (mask & GL_DEPTH_BUFFER_BIT) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2219 | struct gl_renderbuffer *readRb = readFb->_DepthBuffer; |
| 2220 | struct gl_renderbuffer *drawRb = drawFb->_DepthBuffer; |
Brian Paul | dcebe22 | 2009-08-05 13:44:59 -0600 | [diff] [blame] | 2221 | if (!readRb || |
| 2222 | !drawRb || |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2223 | _mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) != |
| 2224 | _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) { |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 2225 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2226 | "glBlitFramebufferEXT(depth buffer size mismatch"); |
| 2227 | return; |
| 2228 | } |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2231 | if (readFb->Visual.samples > 0 && |
| 2232 | drawFb->Visual.samples > 0 && |
| 2233 | readFb->Visual.samples != drawFb->Visual.samples) { |
| 2234 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2235 | "glBlitFramebufferEXT(mismatched samples"); |
| 2236 | return; |
| 2237 | } |
| 2238 | |
| 2239 | /* extra checks for multisample copies... */ |
| 2240 | if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) { |
| 2241 | /* src and dest region sizes must be the same */ |
| 2242 | if (srcX1 - srcX0 != dstX1 - dstX0 || |
| 2243 | srcY1 - srcY0 != dstY1 - dstY0) { |
| 2244 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2245 | "glBlitFramebufferEXT(bad src/dst multisample region sizes"); |
| 2246 | return; |
| 2247 | } |
| 2248 | |
| 2249 | /* color formats must match */ |
| 2250 | if (colorReadRb && |
| 2251 | colorDrawRb && |
Brian Paul | 45e76d2 | 2009-10-08 20:27:27 -0600 | [diff] [blame] | 2252 | colorReadRb->Format != colorDrawRb->Format) { |
Brian Paul | 722d976 | 2009-01-20 16:58:49 -0700 | [diff] [blame] | 2253 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2254 | "glBlitFramebufferEXT(bad src/dst multisample pixel formats"); |
| 2255 | return; |
| 2256 | } |
| 2257 | } |
| 2258 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2259 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 2260 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT"); |
| 2261 | return; |
| 2262 | } |
| 2263 | |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2264 | /* Debug code */ |
| 2265 | if (DEBUG_BLIT) { |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 2266 | printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d," |
| 2267 | " 0x%x, 0x%x)\n", |
| 2268 | srcX0, srcY0, srcX1, srcY1, |
| 2269 | dstX0, dstY0, dstX1, dstY1, |
| 2270 | mask, filter); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2271 | if (colorReadRb) { |
| 2272 | const struct gl_renderbuffer_attachment *att; |
| 2273 | |
| 2274 | att = find_attachment(readFb, colorReadRb); |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 2275 | printf(" Src FBO %u RB %u (%dx%d) ", |
| 2276 | readFb->Name, colorReadRb->Name, |
| 2277 | colorReadRb->Width, colorReadRb->Height); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2278 | if (att && att->Texture) { |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 2279 | printf("Tex %u tgt 0x%x level %u face %u", |
| 2280 | att->Texture->Name, |
| 2281 | att->Texture->Target, |
| 2282 | att->TextureLevel, |
| 2283 | att->CubeMapFace); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2284 | } |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 2285 | printf("\n"); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2286 | |
| 2287 | att = find_attachment(drawFb, colorDrawRb); |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 2288 | printf(" Dst FBO %u RB %u (%dx%d) ", |
| 2289 | drawFb->Name, colorDrawRb->Name, |
| 2290 | colorDrawRb->Width, colorDrawRb->Height); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2291 | if (att && att->Texture) { |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 2292 | printf("Tex %u tgt 0x%x level %u face %u", |
| 2293 | att->Texture->Name, |
| 2294 | att->Texture->Target, |
| 2295 | att->TextureLevel, |
| 2296 | att->CubeMapFace); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2297 | } |
Kristian Høgsberg | 298be2b | 2010-02-19 12:32:24 -0500 | [diff] [blame] | 2298 | printf("\n"); |
Brian Paul | 21f8d31 | 2009-10-27 16:59:23 -0600 | [diff] [blame] | 2299 | } |
| 2300 | } |
| 2301 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 2302 | ASSERT(ctx->Driver.BlitFramebuffer); |
| 2303 | ctx->Driver.BlitFramebuffer(ctx, |
| 2304 | srcX0, srcY0, srcX1, srcY1, |
| 2305 | dstX0, dstY0, dstX1, dstY1, |
| 2306 | mask, filter); |
| 2307 | } |
| 2308 | #endif /* FEATURE_EXT_framebuffer_blit */ |
Zack Rusin | da7bd6a | 2010-06-28 17:31:21 -0400 | [diff] [blame] | 2309 | |
| 2310 | #if FEATURE_ARB_geometry_shader4 |
| 2311 | void GLAPIENTRY |
| 2312 | _mesa_FramebufferTextureARB(GLenum target, GLenum attachment, |
| 2313 | GLuint texture, GLint level) |
| 2314 | { |
| 2315 | GET_CURRENT_CONTEXT(ctx); |
| 2316 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2317 | "glFramebufferTextureARB " |
| 2318 | "not implemented!"); |
| 2319 | } |
| 2320 | |
| 2321 | void GLAPIENTRY |
| 2322 | _mesa_FramebufferTextureFaceARB(GLenum target, GLenum attachment, |
| 2323 | GLuint texture, GLint level, GLenum face) |
| 2324 | { |
| 2325 | GET_CURRENT_CONTEXT(ctx); |
| 2326 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 2327 | "glFramebufferTextureFaceARB " |
| 2328 | "not implemented!"); |
| 2329 | } |
| 2330 | #endif /* FEATURE_ARB_geometry_shader4 */ |