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