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