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