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 | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 26 | /* |
| 27 | * Authors: |
| 28 | * Brian Paul |
| 29 | */ |
| 30 | |
| 31 | |
Roland Scheidegger | a1bc0d0 | 2007-07-18 20:17:14 +0200 | [diff] [blame] | 32 | #include "buffers.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 33 | #include "context.h" |
| 34 | #include "fbobject.h" |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 35 | #include "framebuffer.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 36 | #include "hash.h" |
Brian Paul | 24edd90 | 2006-09-29 01:24:26 +0000 | [diff] [blame] | 37 | #include "mipmap.h" |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 38 | #include "renderbuffer.h" |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 39 | #include "state.h" |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 40 | #include "teximage.h" |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 41 | #include "texobj.h" |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 42 | #include "texstore.h" |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 43 | |
| 44 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 45 | /** |
| 46 | * Notes: |
| 47 | * |
| 48 | * None of the GL_EXT_framebuffer_object functions are compiled into |
| 49 | * display lists. |
| 50 | */ |
| 51 | |
| 52 | |
| 53 | |
Brian Paul | 923b6fc | 2005-02-08 04:08:56 +0000 | [diff] [blame] | 54 | /* |
| 55 | * When glGenRender/FramebuffersEXT() is called we insert pointers to |
| 56 | * these placeholder objects into the hash table. |
| 57 | * Later, when the object ID is first bound, we replace the placeholder |
| 58 | * with the real frame/renderbuffer. |
| 59 | */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 60 | static struct gl_framebuffer DummyFramebuffer; |
| 61 | static struct gl_renderbuffer DummyRenderbuffer; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 62 | |
| 63 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 64 | #define IS_CUBE_FACE(TARGET) \ |
| 65 | ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \ |
| 66 | (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 67 | |
| 68 | |
Brian Paul | 3dc6591 | 2008-07-03 15:40:38 -0600 | [diff] [blame] | 69 | static void |
| 70 | delete_dummy_renderbuffer(struct gl_renderbuffer *rb) |
| 71 | { |
| 72 | /* no op */ |
| 73 | } |
| 74 | |
| 75 | static void |
| 76 | delete_dummy_framebuffer(struct gl_framebuffer *fb) |
| 77 | { |
| 78 | /* no op */ |
| 79 | } |
| 80 | |
| 81 | |
| 82 | void |
| 83 | _mesa_init_fbobjects(GLcontext *ctx) |
| 84 | { |
| 85 | DummyFramebuffer.Delete = delete_dummy_framebuffer; |
| 86 | DummyRenderbuffer.Delete = delete_dummy_renderbuffer; |
| 87 | } |
| 88 | |
| 89 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 90 | /** |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 91 | * Helper routine for getting a gl_renderbuffer. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 92 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 93 | struct gl_renderbuffer * |
| 94 | _mesa_lookup_renderbuffer(GLcontext *ctx, GLuint id) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 95 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 96 | struct gl_renderbuffer *rb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 97 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 98 | if (id == 0) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 99 | return NULL; |
| 100 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 101 | rb = (struct gl_renderbuffer *) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 102 | _mesa_HashLookup(ctx->Shared->RenderBuffers, id); |
| 103 | return rb; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | /** |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 108 | * Helper routine for getting a gl_framebuffer. |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 109 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 110 | struct gl_framebuffer * |
| 111 | _mesa_lookup_framebuffer(GLcontext *ctx, GLuint id) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 112 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 113 | struct gl_framebuffer *fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 114 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 115 | if (id == 0) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 116 | return NULL; |
| 117 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 118 | fb = (struct gl_framebuffer *) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 119 | _mesa_HashLookup(ctx->Shared->FrameBuffers, id); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 120 | return fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
| 124 | /** |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 125 | * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 126 | * gl_renderbuffer_attachment object. |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 127 | */ |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 128 | struct gl_renderbuffer_attachment * |
| 129 | _mesa_get_attachment(GLcontext *ctx, struct gl_framebuffer *fb, |
| 130 | GLenum attachment) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 131 | { |
| 132 | GLuint i; |
| 133 | |
| 134 | switch (attachment) { |
| 135 | case GL_COLOR_ATTACHMENT0_EXT: |
| 136 | case GL_COLOR_ATTACHMENT1_EXT: |
| 137 | case GL_COLOR_ATTACHMENT2_EXT: |
| 138 | case GL_COLOR_ATTACHMENT3_EXT: |
| 139 | case GL_COLOR_ATTACHMENT4_EXT: |
| 140 | case GL_COLOR_ATTACHMENT5_EXT: |
| 141 | case GL_COLOR_ATTACHMENT6_EXT: |
| 142 | case GL_COLOR_ATTACHMENT7_EXT: |
| 143 | case GL_COLOR_ATTACHMENT8_EXT: |
| 144 | case GL_COLOR_ATTACHMENT9_EXT: |
| 145 | case GL_COLOR_ATTACHMENT10_EXT: |
| 146 | case GL_COLOR_ATTACHMENT11_EXT: |
| 147 | case GL_COLOR_ATTACHMENT12_EXT: |
| 148 | case GL_COLOR_ATTACHMENT13_EXT: |
| 149 | case GL_COLOR_ATTACHMENT14_EXT: |
| 150 | case GL_COLOR_ATTACHMENT15_EXT: |
| 151 | i = attachment - GL_COLOR_ATTACHMENT0_EXT; |
| 152 | if (i >= ctx->Const.MaxColorAttachments) { |
| 153 | return NULL; |
| 154 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 155 | return &fb->Attachment[BUFFER_COLOR0 + i]; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 156 | case GL_DEPTH_ATTACHMENT_EXT: |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 157 | return &fb->Attachment[BUFFER_DEPTH]; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 158 | case GL_STENCIL_ATTACHMENT_EXT: |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 159 | return &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 160 | default: |
| 161 | return NULL; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 166 | /** |
| 167 | * Remove any texture or renderbuffer attached to the given attachment |
| 168 | * point. Update reference counts, etc. |
| 169 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 170 | void |
| 171 | _mesa_remove_attachment(GLcontext *ctx, struct gl_renderbuffer_attachment *att) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 172 | { |
| 173 | if (att->Type == GL_TEXTURE) { |
| 174 | ASSERT(att->Texture); |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 175 | if (ctx->Driver.FinishRenderTexture) { |
| 176 | /* tell driver we're done rendering to this texobj */ |
| 177 | ctx->Driver.FinishRenderTexture(ctx, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 178 | } |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 179 | _mesa_reference_texobj(&att->Texture, NULL); /* unbind */ |
| 180 | ASSERT(!att->Texture); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 181 | } |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 182 | if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) { |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 183 | ASSERT(!att->Texture); |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 184 | _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */ |
| 185 | ASSERT(!att->Renderbuffer); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 186 | } |
| 187 | att->Type = GL_NONE; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 188 | att->Complete = GL_TRUE; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 192 | /** |
| 193 | * Bind a texture object to an attachment point. |
| 194 | * The previous binding, if any, will be removed first. |
| 195 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 196 | void |
| 197 | _mesa_set_texture_attachment(GLcontext *ctx, |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 198 | struct gl_framebuffer *fb, |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 199 | struct gl_renderbuffer_attachment *att, |
| 200 | struct gl_texture_object *texObj, |
| 201 | GLenum texTarget, GLuint level, GLuint zoffset) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 202 | { |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 203 | if (att->Texture == texObj) { |
| 204 | /* re-attaching same texture */ |
| 205 | ASSERT(att->Type == GL_TEXTURE); |
| 206 | } |
| 207 | else { |
| 208 | /* new attachment */ |
| 209 | _mesa_remove_attachment(ctx, att); |
| 210 | att->Type = GL_TEXTURE; |
Brian | 9e01b91 | 2007-08-13 11:29:46 +0100 | [diff] [blame] | 211 | assert(!att->Texture); |
| 212 | _mesa_reference_texobj(&att->Texture, texObj); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /* always update these fields */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 216 | att->TextureLevel = level; |
| 217 | if (IS_CUBE_FACE(texTarget)) { |
| 218 | att->CubeMapFace = texTarget - GL_TEXTURE_CUBE_MAP_POSITIVE_X; |
| 219 | } |
| 220 | else { |
| 221 | att->CubeMapFace = 0; |
| 222 | } |
| 223 | att->Zoffset = zoffset; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 224 | att->Complete = GL_FALSE; |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 225 | |
| 226 | if (att->Texture->Image[att->CubeMapFace][att->TextureLevel]) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 227 | ctx->Driver.RenderTexture(ctx, fb, att); |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 228 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 232 | /** |
| 233 | * Bind a renderbuffer to an attachment point. |
| 234 | * The previous binding, if any, will be removed first. |
| 235 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 236 | void |
| 237 | _mesa_set_renderbuffer_attachment(GLcontext *ctx, |
| 238 | struct gl_renderbuffer_attachment *att, |
| 239 | struct gl_renderbuffer *rb) |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 240 | { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 241 | /* XXX check if re-doing same attachment, exit early */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 242 | _mesa_remove_attachment(ctx, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 243 | att->Type = GL_RENDERBUFFER_EXT; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 244 | att->Texture = NULL; /* just to be safe */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 245 | att->Complete = GL_FALSE; |
Brian | dccd9c4 | 2007-04-02 09:56:28 -0600 | [diff] [blame] | 246 | _mesa_reference_renderbuffer(&att->Renderbuffer, rb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 249 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 250 | /** |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 251 | * Fallback for ctx->Driver.FramebufferRenderbuffer() |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 252 | * Attach a renderbuffer object to a framebuffer object. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 253 | */ |
| 254 | void |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 255 | _mesa_framebuffer_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb, |
| 256 | GLenum attachment, struct gl_renderbuffer *rb) |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 257 | { |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 258 | struct gl_renderbuffer_attachment *att; |
| 259 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 260 | _glthread_LOCK_MUTEX(fb->Mutex); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 261 | |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 262 | att = _mesa_get_attachment(ctx, fb, attachment); |
| 263 | ASSERT(att); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 264 | if (rb) { |
| 265 | _mesa_set_renderbuffer_attachment(ctx, att, rb); |
| 266 | } |
| 267 | else { |
| 268 | _mesa_remove_attachment(ctx, att); |
| 269 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 270 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 271 | _glthread_UNLOCK_MUTEX(fb->Mutex); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | |
| 275 | /** |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 276 | * Test if an attachment point is complete and update its Complete field. |
| 277 | * \param format if GL_COLOR, this is a color attachment point, |
| 278 | * if GL_DEPTH, this is a depth component attachment point, |
| 279 | * if GL_STENCIL, this is a stencil component attachment point. |
| 280 | */ |
| 281 | static void |
| 282 | test_attachment_completeness(const GLcontext *ctx, GLenum format, |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 283 | struct gl_renderbuffer_attachment *att) |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 284 | { |
| 285 | assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL); |
| 286 | |
| 287 | /* assume complete */ |
| 288 | att->Complete = GL_TRUE; |
| 289 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 290 | /* Look for reasons why the attachment might be incomplete */ |
| 291 | if (att->Type == GL_TEXTURE) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 292 | const struct gl_texture_object *texObj = att->Texture; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 293 | struct gl_texture_image *texImage; |
| 294 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 295 | if (!texObj) { |
| 296 | att->Complete = GL_FALSE; |
| 297 | return; |
| 298 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 299 | |
| 300 | texImage = texObj->Image[att->CubeMapFace][att->TextureLevel]; |
| 301 | if (!texImage) { |
| 302 | att->Complete = GL_FALSE; |
| 303 | return; |
| 304 | } |
| 305 | if (texImage->Width < 1 || texImage->Height < 1) { |
| 306 | att->Complete = GL_FALSE; |
| 307 | return; |
| 308 | } |
| 309 | if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) { |
| 310 | att->Complete = GL_FALSE; |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | if (format == GL_COLOR) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 315 | if (texImage->TexFormat->BaseFormat != GL_RGB && |
| 316 | texImage->TexFormat->BaseFormat != GL_RGBA) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 317 | att->Complete = GL_FALSE; |
| 318 | return; |
| 319 | } |
| 320 | } |
| 321 | else if (format == GL_DEPTH) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 322 | if (texImage->TexFormat->BaseFormat == GL_DEPTH_COMPONENT) { |
| 323 | /* OK */ |
| 324 | } |
| 325 | else if (ctx->Extensions.EXT_packed_depth_stencil && |
Brian | 635e964 | 2008-03-28 13:24:12 -0600 | [diff] [blame] | 326 | texImage->TexFormat->BaseFormat == GL_DEPTH_STENCIL_EXT) { |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 327 | /* OK */ |
| 328 | } |
| 329 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 330 | att->Complete = GL_FALSE; |
| 331 | return; |
| 332 | } |
| 333 | } |
| 334 | else { |
| 335 | /* no such thing as stencil textures */ |
| 336 | att->Complete = GL_FALSE; |
| 337 | return; |
| 338 | } |
| 339 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 340 | else if (att->Type == GL_RENDERBUFFER_EXT) { |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 341 | ASSERT(att->Renderbuffer); |
| 342 | if (!att->Renderbuffer->InternalFormat || |
| 343 | att->Renderbuffer->Width < 1 || |
| 344 | att->Renderbuffer->Height < 1) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 345 | att->Complete = GL_FALSE; |
| 346 | return; |
| 347 | } |
| 348 | if (format == GL_COLOR) { |
| 349 | if (att->Renderbuffer->_BaseFormat != GL_RGB && |
| 350 | att->Renderbuffer->_BaseFormat != GL_RGBA) { |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 351 | ASSERT(att->Renderbuffer->RedBits); |
| 352 | ASSERT(att->Renderbuffer->GreenBits); |
| 353 | ASSERT(att->Renderbuffer->BlueBits); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 354 | att->Complete = GL_FALSE; |
| 355 | return; |
| 356 | } |
| 357 | } |
| 358 | else if (format == GL_DEPTH) { |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 359 | ASSERT(att->Renderbuffer->DepthBits); |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 360 | if (att->Renderbuffer->_BaseFormat == GL_DEPTH_COMPONENT) { |
| 361 | /* OK */ |
| 362 | } |
| 363 | else if (ctx->Extensions.EXT_packed_depth_stencil && |
| 364 | att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) { |
| 365 | /* OK */ |
| 366 | } |
| 367 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 368 | att->Complete = GL_FALSE; |
| 369 | return; |
| 370 | } |
| 371 | } |
| 372 | else { |
| 373 | assert(format == GL_STENCIL); |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 374 | ASSERT(att->Renderbuffer->StencilBits); |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 375 | if (att->Renderbuffer->_BaseFormat == GL_STENCIL_INDEX) { |
| 376 | /* OK */ |
| 377 | } |
| 378 | else if (ctx->Extensions.EXT_packed_depth_stencil && |
| 379 | att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) { |
| 380 | /* OK */ |
| 381 | } |
| 382 | else { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 383 | att->Complete = GL_FALSE; |
| 384 | return; |
| 385 | } |
| 386 | } |
| 387 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 388 | else { |
| 389 | ASSERT(att->Type == GL_NONE); |
| 390 | /* complete */ |
| 391 | return; |
| 392 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | |
| 396 | /** |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 397 | * Helpful for debugging |
| 398 | */ |
| 399 | static void |
| 400 | fbo_incomplete(const char *msg, int index) |
| 401 | { |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 402 | (void) msg; |
| 403 | (void) index; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 404 | /* |
| 405 | _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index); |
| 406 | */ |
| 407 | } |
| 408 | |
| 409 | |
| 410 | /** |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 411 | * Test if the given framebuffer object is complete and update its |
| 412 | * Status field with the results. |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 413 | * Also update the framebuffer's Width and Height fields if the |
| 414 | * framebuffer is complete. |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 415 | */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 416 | void |
| 417 | _mesa_test_framebuffer_completeness(GLcontext *ctx, struct gl_framebuffer *fb) |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 418 | { |
Brian Paul | 6c0c917 | 2005-02-27 16:23:41 +0000 | [diff] [blame] | 419 | GLuint numImages, width = 0, height = 0; |
| 420 | GLenum intFormat = GL_NONE; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 421 | GLuint w = 0, h = 0; |
| 422 | GLint i; |
Brian Paul | 28b014e | 2006-04-05 03:05:17 +0000 | [diff] [blame] | 423 | GLuint j; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 424 | |
Brian Paul | c726441 | 2005-06-01 00:50:23 +0000 | [diff] [blame] | 425 | assert(fb->Name != 0); |
| 426 | |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 427 | numImages = 0; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 428 | fb->Width = 0; |
| 429 | fb->Height = 0; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 430 | |
| 431 | /* Start at -2 to more easily loop over all attachment points */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 432 | for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 433 | struct gl_renderbuffer_attachment *att; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 434 | GLenum f; |
| 435 | |
| 436 | if (i == -2) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 437 | att = &fb->Attachment[BUFFER_DEPTH]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 438 | test_attachment_completeness(ctx, GL_DEPTH, att); |
| 439 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 440 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 441 | fbo_incomplete("depth attachment incomplete", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 442 | return; |
| 443 | } |
| 444 | } |
| 445 | else if (i == -1) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 446 | att = &fb->Attachment[BUFFER_STENCIL]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 447 | test_attachment_completeness(ctx, GL_STENCIL, att); |
| 448 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 449 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 450 | fbo_incomplete("stencil attachment incomplete", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 451 | return; |
| 452 | } |
| 453 | } |
| 454 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 455 | att = &fb->Attachment[BUFFER_COLOR0 + i]; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 456 | test_attachment_completeness(ctx, GL_COLOR, att); |
| 457 | if (!att->Complete) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 458 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 459 | fbo_incomplete("color attachment incomplete", i); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 460 | return; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | if (att->Type == GL_TEXTURE) { |
Brian Paul | a9fc8ba | 2005-10-05 01:48:07 +0000 | [diff] [blame] | 465 | const struct gl_texture_image *texImg |
| 466 | = att->Texture->Image[att->CubeMapFace][att->TextureLevel]; |
| 467 | w = texImg->Width; |
| 468 | h = texImg->Height; |
| 469 | f = texImg->_BaseFormat; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 470 | numImages++; |
Brian Paul | 9f6ff49 | 2006-03-28 15:24:50 +0000 | [diff] [blame] | 471 | if (f != GL_RGB && f != GL_RGBA && f != GL_DEPTH_COMPONENT |
| 472 | && f != GL_DEPTH_STENCIL_EXT) { |
Brian Paul | ed7f3ae | 2005-06-07 15:03:40 +0000 | [diff] [blame] | 473 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 474 | fbo_incomplete("texture attachment incomplete", -1); |
Brian Paul | ed7f3ae | 2005-06-07 15:03:40 +0000 | [diff] [blame] | 475 | return; |
| 476 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 477 | } |
| 478 | else if (att->Type == GL_RENDERBUFFER_EXT) { |
| 479 | w = att->Renderbuffer->Width; |
| 480 | h = att->Renderbuffer->Height; |
| 481 | f = att->Renderbuffer->InternalFormat; |
| 482 | numImages++; |
| 483 | } |
| 484 | else { |
| 485 | assert(att->Type == GL_NONE); |
| 486 | continue; |
| 487 | } |
| 488 | |
| 489 | if (numImages == 1) { |
| 490 | /* set required width, height and format */ |
| 491 | width = w; |
| 492 | height = h; |
| 493 | if (i >= 0) |
| 494 | intFormat = f; |
| 495 | } |
| 496 | else { |
| 497 | /* check that width, height, format are same */ |
| 498 | if (w != width || h != height) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 499 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 500 | fbo_incomplete("width or height mismatch", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 501 | return; |
| 502 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 503 | if (intFormat != GL_NONE && f != intFormat) { |
| 504 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 505 | fbo_incomplete("format mismatch", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 506 | return; |
| 507 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
Brian Paul | 868c09a | 2008-08-08 13:06:54 -0600 | [diff] [blame^] | 511 | #ifndef FEATURE_OES_framebuffer_object |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 512 | /* Check that all DrawBuffers are present */ |
Brian Paul | 28b014e | 2006-04-05 03:05:17 +0000 | [diff] [blame] | 513 | for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) { |
| 514 | if (fb->ColorDrawBuffer[j] != GL_NONE) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 515 | const struct gl_renderbuffer_attachment *att |
Brian Paul | 28b014e | 2006-04-05 03:05:17 +0000 | [diff] [blame] | 516 | = _mesa_get_attachment(ctx, fb, fb->ColorDrawBuffer[j]); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 517 | assert(att); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 518 | if (att->Type == GL_NONE) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 519 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT; |
Brian Paul | 28b014e | 2006-04-05 03:05:17 +0000 | [diff] [blame] | 520 | fbo_incomplete("missing drawbuffer", j); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 521 | return; |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | /* Check that the ReadBuffer is present */ |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 527 | if (fb->ColorReadBuffer != GL_NONE) { |
| 528 | const struct gl_renderbuffer_attachment *att |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 529 | = _mesa_get_attachment(ctx, fb, fb->ColorReadBuffer); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 530 | assert(att); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 531 | if (att->Type == GL_NONE) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 532 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 533 | fbo_incomplete("missing readbuffer", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 534 | return; |
| 535 | } |
| 536 | } |
Brian Paul | 868c09a | 2008-08-08 13:06:54 -0600 | [diff] [blame^] | 537 | #endif |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 538 | |
| 539 | if (numImages == 0) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 540 | fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT; |
Brian Paul | 4991888 | 2006-03-20 15:27:55 +0000 | [diff] [blame] | 541 | fbo_incomplete("no attachments", -1); |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 542 | return; |
| 543 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 544 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 545 | /* |
| 546 | * If we get here, the framebuffer is complete! |
| 547 | */ |
| 548 | fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT; |
| 549 | fb->Width = w; |
| 550 | fb->Height = h; |
| 551 | } |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 552 | |
| 553 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 554 | GLboolean GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 555 | _mesa_IsRenderbufferEXT(GLuint renderbuffer) |
| 556 | { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 557 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 558 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 559 | if (renderbuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 560 | struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 561 | if (rb != NULL && rb != &DummyRenderbuffer) |
| 562 | return GL_TRUE; |
| 563 | } |
| 564 | return GL_FALSE; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 568 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 569 | _mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer) |
| 570 | { |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 571 | struct gl_renderbuffer *newRb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 572 | GET_CURRENT_CONTEXT(ctx); |
| 573 | |
| 574 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 575 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 576 | if (target != GL_RENDERBUFFER_EXT) { |
| 577 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 578 | "glBindRenderbufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 579 | return; |
| 580 | } |
| 581 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 582 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Keith Whitwell | df05829 | 2006-09-22 11:40:35 +0000 | [diff] [blame] | 583 | /* The above doesn't fully flush the drivers in the way that a |
| 584 | * glFlush does, but that is required here: |
| 585 | */ |
| 586 | if (ctx->Driver.Flush) |
| 587 | ctx->Driver.Flush(ctx); |
| 588 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 589 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 590 | if (renderbuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 591 | newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 592 | if (newRb == &DummyRenderbuffer) { |
| 593 | /* ID was reserved, but no real renderbuffer object made yet */ |
| 594 | newRb = NULL; |
| 595 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 596 | if (!newRb) { |
| 597 | /* create new renderbuffer object */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 598 | newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 599 | if (!newRb) { |
| 600 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT"); |
| 601 | return; |
| 602 | } |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 603 | ASSERT(newRb->AllocStorage); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 604 | _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb); |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 605 | newRb->RefCount = 1; /* referenced by hash table */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 606 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 607 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 608 | else { |
| 609 | newRb = NULL; |
| 610 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 611 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 612 | ASSERT(newRb != &DummyRenderbuffer); |
| 613 | |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 614 | _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 618 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 619 | _mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers) |
| 620 | { |
| 621 | GLint i; |
| 622 | GET_CURRENT_CONTEXT(ctx); |
| 623 | |
| 624 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 625 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 626 | |
| 627 | for (i = 0; i < n; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 628 | if (renderbuffers[i] > 0) { |
| 629 | struct gl_renderbuffer *rb; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 630 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 631 | if (rb) { |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 632 | /* check if deleting currently bound renderbuffer object */ |
| 633 | if (rb == ctx->CurrentRenderbuffer) { |
| 634 | /* bind default */ |
| 635 | ASSERT(rb->RefCount >= 2); |
| 636 | _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); |
| 637 | } |
| 638 | |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 639 | /* Remove from hash table immediately, to free the ID. |
| 640 | * But the object will not be freed until it's no longer |
| 641 | * referenced anywhere else. |
| 642 | */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 643 | _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 644 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 645 | if (rb != &DummyRenderbuffer) { |
Brian | 42aaa54 | 2007-03-25 10:39:36 -0600 | [diff] [blame] | 646 | /* no longer referenced by hash table */ |
| 647 | _mesa_reference_renderbuffer(&rb, NULL); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 648 | } |
| 649 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 655 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 656 | _mesa_GenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers) |
| 657 | { |
| 658 | GET_CURRENT_CONTEXT(ctx); |
| 659 | GLuint first; |
| 660 | GLint i; |
| 661 | |
| 662 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 663 | |
| 664 | if (n < 0) { |
| 665 | _mesa_error(ctx, GL_INVALID_VALUE, "glGenRenderbuffersEXT(n)"); |
| 666 | return; |
| 667 | } |
| 668 | |
| 669 | if (!renderbuffers) |
| 670 | return; |
| 671 | |
| 672 | first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n); |
| 673 | |
| 674 | for (i = 0; i < n; i++) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 675 | GLuint name = first + i; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 676 | renderbuffers[i] = name; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 677 | /* insert dummy placeholder into hash table */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 678 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 679 | _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 680 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
| 684 | |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 685 | /** |
| 686 | * Given an internal format token for a render buffer, return the |
| 687 | * corresponding base format. |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 688 | * This is very similar to _mesa_base_tex_format() but the set of valid |
| 689 | * internal formats is somewhat different. |
| 690 | * |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 691 | * \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] | 692 | * GL_DEPTH_STENCIL_EXT or zero if error. |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 693 | */ |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 694 | GLenum |
| 695 | _mesa_base_fbo_format(GLcontext *ctx, GLenum internalFormat) |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 696 | { |
| 697 | switch (internalFormat) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 698 | case GL_RGB: |
| 699 | case GL_R3_G3_B2: |
| 700 | case GL_RGB4: |
| 701 | case GL_RGB5: |
| 702 | case GL_RGB8: |
| 703 | case GL_RGB10: |
| 704 | case GL_RGB12: |
| 705 | case GL_RGB16: |
| 706 | return GL_RGB; |
| 707 | case GL_RGBA: |
| 708 | case GL_RGBA2: |
| 709 | case GL_RGBA4: |
| 710 | case GL_RGB5_A1: |
| 711 | case GL_RGBA8: |
| 712 | case GL_RGB10_A2: |
| 713 | case GL_RGBA12: |
| 714 | case GL_RGBA16: |
| 715 | return GL_RGBA; |
| 716 | case GL_STENCIL_INDEX: |
| 717 | case GL_STENCIL_INDEX1_EXT: |
| 718 | case GL_STENCIL_INDEX4_EXT: |
| 719 | case GL_STENCIL_INDEX8_EXT: |
| 720 | case GL_STENCIL_INDEX16_EXT: |
| 721 | return GL_STENCIL_INDEX; |
| 722 | case GL_DEPTH_COMPONENT: |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 723 | case GL_DEPTH_COMPONENT16: |
| 724 | case GL_DEPTH_COMPONENT24: |
| 725 | case GL_DEPTH_COMPONENT32: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 726 | return GL_DEPTH_COMPONENT; |
Brian Paul | 1ad7b99 | 2005-09-28 02:29:50 +0000 | [diff] [blame] | 727 | case GL_DEPTH_STENCIL_EXT: |
| 728 | case GL_DEPTH24_STENCIL8_EXT: |
| 729 | if (ctx->Extensions.EXT_packed_depth_stencil) |
| 730 | return GL_DEPTH_STENCIL_EXT; |
| 731 | else |
| 732 | return 0; |
Brian Paul | d9468c9 | 2005-02-10 16:08:07 +0000 | [diff] [blame] | 733 | /* XXX add floating point formats eventually */ |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 734 | default: |
| 735 | return 0; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 736 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 740 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 741 | _mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat, |
| 742 | GLsizei width, GLsizei height) |
| 743 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 744 | struct gl_renderbuffer *rb; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 745 | GLenum baseFormat; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 746 | GET_CURRENT_CONTEXT(ctx); |
| 747 | |
| 748 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 749 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 750 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 751 | _mesa_error(ctx, GL_INVALID_ENUM, "glRenderbufferStorageEXT(target)"); |
| 752 | return; |
| 753 | } |
| 754 | |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 755 | baseFormat = _mesa_base_fbo_format(ctx, internalFormat); |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 756 | if (baseFormat == 0) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 757 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 758 | "glRenderbufferStorageEXT(internalFormat)"); |
| 759 | return; |
| 760 | } |
| 761 | |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 762 | if (width < 1 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 763 | _mesa_error(ctx, GL_INVALID_VALUE, "glRenderbufferStorageEXT(width)"); |
| 764 | return; |
| 765 | } |
| 766 | |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 767 | if (height < 1 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 768 | _mesa_error(ctx, GL_INVALID_VALUE, "glRenderbufferStorageEXT(height)"); |
| 769 | return; |
| 770 | } |
| 771 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 772 | rb = ctx->CurrentRenderbuffer; |
| 773 | |
| 774 | if (!rb) { |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 775 | _mesa_error(ctx, GL_INVALID_OPERATION, "glRenderbufferStorageEXT"); |
| 776 | return; |
| 777 | } |
| 778 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 779 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 780 | |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 781 | if (rb->InternalFormat == internalFormat && |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 782 | rb->Width == (GLuint) width && |
| 783 | rb->Height == (GLuint) height) { |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 784 | /* no change in allocation needed */ |
| 785 | return; |
| 786 | } |
| 787 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 788 | /* These MUST get set by the AllocStorage func */ |
| 789 | rb->_ActualFormat = 0; |
| 790 | rb->RedBits = |
| 791 | rb->GreenBits = |
| 792 | rb->BlueBits = |
| 793 | rb->AlphaBits = |
| 794 | rb->IndexBits = |
| 795 | rb->DepthBits = |
| 796 | rb->StencilBits = 0; |
| 797 | |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 798 | /* Now allocate the storage */ |
| 799 | ASSERT(rb->AllocStorage); |
| 800 | if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) { |
| 801 | /* No error - check/set fields now */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 802 | assert(rb->_ActualFormat); |
Brian Paul | 13abf91 | 2006-04-13 19:17:13 +0000 | [diff] [blame] | 803 | assert(rb->Width == (GLuint) width); |
| 804 | assert(rb->Height == (GLuint) height); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 805 | assert(rb->RedBits || rb->GreenBits || rb->BlueBits || rb->AlphaBits || |
| 806 | rb->DepthBits || rb->StencilBits || rb->IndexBits); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 807 | rb->InternalFormat = internalFormat; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 808 | rb->_BaseFormat = baseFormat; |
| 809 | } |
| 810 | else { |
| 811 | /* Probably ran out of memory - clear the fields */ |
| 812 | rb->Width = 0; |
| 813 | rb->Height = 0; |
| 814 | rb->InternalFormat = GL_NONE; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 815 | rb->_ActualFormat = GL_NONE; |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 816 | rb->_BaseFormat = GL_NONE; |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 817 | rb->RedBits = |
| 818 | rb->GreenBits = |
| 819 | rb->BlueBits = |
| 820 | rb->AlphaBits = |
| 821 | rb->IndexBits = |
| 822 | rb->DepthBits = |
| 823 | rb->StencilBits = 0; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 824 | } |
| 825 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 826 | /* |
| 827 | test_framebuffer_completeness(ctx, fb); |
| 828 | */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 829 | /* XXX if this renderbuffer is attached anywhere, invalidate attachment |
| 830 | * points??? |
| 831 | */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 835 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 836 | _mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params) |
| 837 | { |
| 838 | GET_CURRENT_CONTEXT(ctx); |
| 839 | |
| 840 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 841 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 842 | if (target != GL_RENDERBUFFER_EXT) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 843 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 844 | "glGetRenderbufferParameterivEXT(target)"); |
| 845 | return; |
| 846 | } |
| 847 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 848 | if (!ctx->CurrentRenderbuffer) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 849 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 850 | "glGetRenderbufferParameterivEXT"); |
| 851 | return; |
| 852 | } |
| 853 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 854 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 855 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 856 | switch (pname) { |
| 857 | case GL_RENDERBUFFER_WIDTH_EXT: |
| 858 | *params = ctx->CurrentRenderbuffer->Width; |
| 859 | return; |
| 860 | case GL_RENDERBUFFER_HEIGHT_EXT: |
| 861 | *params = ctx->CurrentRenderbuffer->Height; |
| 862 | return; |
| 863 | case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT: |
| 864 | *params = ctx->CurrentRenderbuffer->InternalFormat; |
| 865 | return; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 866 | case GL_RENDERBUFFER_RED_SIZE_EXT: |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 867 | *params = ctx->CurrentRenderbuffer->RedBits; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 868 | break; |
| 869 | case GL_RENDERBUFFER_GREEN_SIZE_EXT: |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 870 | *params = ctx->CurrentRenderbuffer->GreenBits; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 871 | break; |
| 872 | case GL_RENDERBUFFER_BLUE_SIZE_EXT: |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 873 | *params = ctx->CurrentRenderbuffer->BlueBits; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 874 | break; |
| 875 | case GL_RENDERBUFFER_ALPHA_SIZE_EXT: |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 876 | *params = ctx->CurrentRenderbuffer->AlphaBits; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 877 | break; |
| 878 | case GL_RENDERBUFFER_DEPTH_SIZE_EXT: |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 879 | *params = ctx->CurrentRenderbuffer->DepthBits; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 880 | break; |
| 881 | case GL_RENDERBUFFER_STENCIL_SIZE_EXT: |
Brian Paul | 311bcf5 | 2005-11-18 02:24:14 +0000 | [diff] [blame] | 882 | *params = ctx->CurrentRenderbuffer->StencilBits; |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 883 | break; |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 884 | default: |
| 885 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 886 | "glGetRenderbufferParameterivEXT(target)"); |
| 887 | return; |
| 888 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 892 | GLboolean GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 893 | _mesa_IsFramebufferEXT(GLuint framebuffer) |
| 894 | { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 895 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 896 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 897 | if (framebuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 898 | struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer); |
Brian Paul | bc6cced | 2005-10-04 15:01:27 +0000 | [diff] [blame] | 899 | if (rb != NULL && rb != &DummyFramebuffer) |
| 900 | return GL_TRUE; |
| 901 | } |
| 902 | return GL_FALSE; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 906 | static void |
| 907 | check_begin_texture_render(GLcontext *ctx, struct gl_framebuffer *fb) |
| 908 | { |
| 909 | GLuint i; |
| 910 | ASSERT(ctx->Driver.RenderTexture); |
| 911 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 912 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
| 913 | struct gl_texture_object *texObj = att->Texture; |
Brian Paul | 9f6ff49 | 2006-03-28 15:24:50 +0000 | [diff] [blame] | 914 | if (texObj |
| 915 | && att->Texture->Image[att->CubeMapFace][att->TextureLevel]) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 916 | ctx->Driver.RenderTexture(ctx, fb, att); |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 922 | /** |
| 923 | * Examine all the framebuffer's attachments to see if any are textures. |
| 924 | * If so, call ctx->Driver.FinishRenderTexture() for each texture to |
| 925 | * notify the device driver that the texture image may have changed. |
| 926 | */ |
| 927 | static void |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 928 | check_end_texture_render(GLcontext *ctx, struct gl_framebuffer *fb) |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 929 | { |
| 930 | if (ctx->Driver.FinishRenderTexture) { |
| 931 | GLuint i; |
| 932 | for (i = 0; i < BUFFER_COUNT; i++) { |
| 933 | struct gl_renderbuffer_attachment *att = fb->Attachment + i; |
Brian | 8b36166 | 2007-11-09 08:55:49 -0700 | [diff] [blame] | 934 | if (att->Texture && att->Renderbuffer) { |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 935 | ctx->Driver.FinishRenderTexture(ctx, att); |
Brian Paul | 0e31e02 | 2005-12-01 00:25:00 +0000 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 942 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 943 | _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer) |
| 944 | { |
Roland Scheidegger | dbfb375 | 2007-07-17 17:29:55 +0200 | [diff] [blame] | 945 | struct gl_framebuffer *newFb, *newFbread; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 946 | GLboolean bindReadBuf, bindDrawBuf; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 947 | GET_CURRENT_CONTEXT(ctx); |
| 948 | |
| 949 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 950 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 951 | if (!ctx->Extensions.EXT_framebuffer_object) { |
| 952 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 953 | "glBindFramebufferEXT(unsupported)"); |
| 954 | return; |
| 955 | } |
| 956 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 957 | switch (target) { |
| 958 | #if FEATURE_EXT_framebuffer_blit |
| 959 | case GL_DRAW_FRAMEBUFFER_EXT: |
| 960 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 961 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
| 962 | return; |
| 963 | } |
| 964 | bindDrawBuf = GL_TRUE; |
| 965 | bindReadBuf = GL_FALSE; |
| 966 | break; |
| 967 | case GL_READ_FRAMEBUFFER_EXT: |
| 968 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 969 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
| 970 | return; |
| 971 | } |
| 972 | bindDrawBuf = GL_FALSE; |
| 973 | bindReadBuf = GL_TRUE; |
| 974 | break; |
| 975 | #endif |
| 976 | case GL_FRAMEBUFFER_EXT: |
| 977 | bindDrawBuf = GL_TRUE; |
| 978 | bindReadBuf = GL_TRUE; |
| 979 | break; |
| 980 | default: |
Brian Paul | eba4ff6 | 2005-09-06 21:22:16 +0000 | [diff] [blame] | 981 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)"); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 982 | return; |
| 983 | } |
| 984 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 985 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian | 32d86eb | 2007-08-16 18:52:48 +0100 | [diff] [blame] | 986 | |
Keith Whitwell | 5ac93f8 | 2006-11-01 14:21:57 +0000 | [diff] [blame] | 987 | if (ctx->Driver.Flush) { |
| 988 | ctx->Driver.Flush(ctx); |
| 989 | } |
Brian | 32d86eb | 2007-08-16 18:52:48 +0100 | [diff] [blame] | 990 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 991 | if (framebuffer) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 992 | /* Binding a user-created framebuffer object */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 993 | newFb = _mesa_lookup_framebuffer(ctx, framebuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 994 | if (newFb == &DummyFramebuffer) { |
Brian Paul | 923b6fc | 2005-02-08 04:08:56 +0000 | [diff] [blame] | 995 | /* ID was reserved, but no real framebuffer object made yet */ |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 996 | newFb = NULL; |
| 997 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 998 | if (!newFb) { |
| 999 | /* create new framebuffer object */ |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1000 | newFb = ctx->Driver.NewFramebuffer(ctx, framebuffer); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1001 | if (!newFb) { |
| 1002 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT"); |
| 1003 | return; |
| 1004 | } |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1005 | _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newFb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1006 | } |
Roland Scheidegger | dbfb375 | 2007-07-17 17:29:55 +0200 | [diff] [blame] | 1007 | newFbread = newFb; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1008 | } |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1009 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1010 | /* Binding the window system framebuffer (which was originally set |
| 1011 | * with MakeCurrent). |
| 1012 | */ |
| 1013 | newFb = ctx->WinSysDrawBuffer; |
Roland Scheidegger | dbfb375 | 2007-07-17 17:29:55 +0200 | [diff] [blame] | 1014 | newFbread = ctx->WinSysReadBuffer; |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1017 | ASSERT(newFb); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1018 | ASSERT(newFb != &DummyFramebuffer); |
| 1019 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1020 | /* |
| 1021 | * XXX check if re-binding same buffer and skip some of this code. |
| 1022 | */ |
| 1023 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1024 | if (bindReadBuf) { |
Roland Scheidegger | dbfb375 | 2007-07-17 17:29:55 +0200 | [diff] [blame] | 1025 | _mesa_reference_framebuffer(&ctx->ReadBuffer, newFbread); |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | if (bindDrawBuf) { |
Brian | a510bc3 | 2007-03-06 10:07:59 -0700 | [diff] [blame] | 1029 | /* check if old FB had any texture attachments */ |
| 1030 | check_end_texture_render(ctx, ctx->DrawBuffer); |
Brian | 32d86eb | 2007-08-16 18:52:48 +0100 | [diff] [blame] | 1031 | |
Brian | a510bc3 | 2007-03-06 10:07:59 -0700 | [diff] [blame] | 1032 | /* check if time to delete this framebuffer */ |
Brian | a510bc3 | 2007-03-06 10:07:59 -0700 | [diff] [blame] | 1033 | _mesa_reference_framebuffer(&ctx->DrawBuffer, newFb); |
Brian | 32d86eb | 2007-08-16 18:52:48 +0100 | [diff] [blame] | 1034 | |
| 1035 | if (newFb->Name != 0) { |
| 1036 | /* check if newly bound framebuffer has any texture attachments */ |
| 1037 | check_begin_texture_render(ctx, newFb); |
| 1038 | } |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1039 | } |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 1040 | |
| 1041 | if (ctx->Driver.BindFramebuffer) { |
Roland Scheidegger | dbfb375 | 2007-07-17 17:29:55 +0200 | [diff] [blame] | 1042 | ctx->Driver.BindFramebuffer(ctx, target, newFb, newFbread); |
Brian Paul | 59e0faa | 2006-03-15 17:48:00 +0000 | [diff] [blame] | 1043 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1047 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1048 | _mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers) |
| 1049 | { |
| 1050 | GLint i; |
| 1051 | GET_CURRENT_CONTEXT(ctx); |
| 1052 | |
| 1053 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1054 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Keith Whitwell | df05829 | 2006-09-22 11:40:35 +0000 | [diff] [blame] | 1055 | /* The above doesn't fully flush the drivers in the way that a |
| 1056 | * glFlush does, but that is required here: |
| 1057 | */ |
| 1058 | if (ctx->Driver.Flush) |
| 1059 | ctx->Driver.Flush(ctx); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1060 | |
| 1061 | for (i = 0; i < n; i++) { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1062 | if (framebuffers[i] > 0) { |
| 1063 | struct gl_framebuffer *fb; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1064 | fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1065 | if (fb) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1066 | ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]); |
Brian Paul | 91802fd | 2005-10-04 16:01:02 +0000 | [diff] [blame] | 1067 | |
| 1068 | /* check if deleting currently bound framebuffer object */ |
| 1069 | if (fb == ctx->DrawBuffer) { |
| 1070 | /* bind default */ |
| 1071 | ASSERT(fb->RefCount >= 2); |
| 1072 | _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); |
| 1073 | } |
| 1074 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1075 | /* remove from hash table immediately, to free the ID */ |
| 1076 | _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1077 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1078 | if (fb != &DummyFramebuffer) { |
| 1079 | /* But the object will not be freed until it's no longer |
| 1080 | * bound in any context. |
| 1081 | */ |
Brian | a510bc3 | 2007-03-06 10:07:59 -0700 | [diff] [blame] | 1082 | _mesa_unreference_framebuffer(&fb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1083 | } |
| 1084 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1090 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1091 | _mesa_GenFramebuffersEXT(GLsizei n, GLuint *framebuffers) |
| 1092 | { |
| 1093 | GET_CURRENT_CONTEXT(ctx); |
| 1094 | GLuint first; |
| 1095 | GLint i; |
| 1096 | |
| 1097 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1098 | |
| 1099 | if (n < 0) { |
| 1100 | _mesa_error(ctx, GL_INVALID_VALUE, "glGenFramebuffersEXT(n)"); |
| 1101 | return; |
| 1102 | } |
| 1103 | |
| 1104 | if (!framebuffers) |
| 1105 | return; |
| 1106 | |
| 1107 | first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n); |
| 1108 | |
| 1109 | for (i = 0; i < n; i++) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1110 | GLuint name = first + i; |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1111 | framebuffers[i] = name; |
| 1112 | /* insert dummy placeholder into hash table */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1113 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1114 | _mesa_HashInsert(ctx->Shared->FrameBuffers, name, &DummyFramebuffer); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1115 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | |
| 1120 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1121 | GLenum GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1122 | _mesa_CheckFramebufferStatusEXT(GLenum target) |
| 1123 | { |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1124 | struct gl_framebuffer *buffer; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1125 | GET_CURRENT_CONTEXT(ctx); |
| 1126 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1127 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1128 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1129 | switch (target) { |
| 1130 | #if FEATURE_EXT_framebuffer_blit |
| 1131 | case GL_DRAW_FRAMEBUFFER_EXT: |
| 1132 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1133 | _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)"); |
| 1134 | return 0; |
| 1135 | } |
| 1136 | buffer = ctx->DrawBuffer; |
| 1137 | break; |
| 1138 | case GL_READ_FRAMEBUFFER_EXT: |
| 1139 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1140 | _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)"); |
| 1141 | return 0; |
| 1142 | } |
| 1143 | buffer = ctx->ReadBuffer; |
| 1144 | break; |
| 1145 | #endif |
| 1146 | case GL_FRAMEBUFFER_EXT: |
| 1147 | buffer = ctx->DrawBuffer; |
| 1148 | break; |
| 1149 | default: |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1150 | _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)"); |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1151 | return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1154 | if (buffer->Name == 0) { |
Brian Paul | f0bbbf6 | 2005-02-09 03:50:30 +0000 | [diff] [blame] | 1155 | /* The window system / default framebuffer is always complete */ |
| 1156 | return GL_FRAMEBUFFER_COMPLETE_EXT; |
| 1157 | } |
| 1158 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1159 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 1160 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1161 | _mesa_test_framebuffer_completeness(ctx, buffer); |
| 1162 | return buffer->_Status; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | /** |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1168 | * Common code called by glFramebufferTexture1D/2D/3DEXT(). |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1169 | */ |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1170 | static void |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1171 | framebuffer_texture(GLcontext *ctx, const char *caller, GLenum target, |
| 1172 | GLenum attachment, GLenum textarget, GLuint texture, |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1173 | GLint level, GLint zoffset) |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1174 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1175 | struct gl_renderbuffer_attachment *att; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1176 | struct gl_texture_object *texObj = NULL; |
| 1177 | struct gl_framebuffer *fb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1178 | |
| 1179 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1180 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1181 | if (target != GL_FRAMEBUFFER_EXT) { |
| 1182 | _mesa_error(ctx, GL_INVALID_ENUM, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1183 | "glFramebufferTexture%sEXT(target)", caller); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1184 | return; |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1185 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1186 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1187 | fb = ctx->DrawBuffer; |
| 1188 | ASSERT(fb); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1189 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1190 | /* check framebuffer binding */ |
| 1191 | if (fb->Name == 0) { |
| 1192 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1193 | "glFramebufferTexture%sEXT", caller); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1194 | return; |
| 1195 | } |
| 1196 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1197 | |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1198 | /* The textarget, level, and zoffset parameters are only validated if |
| 1199 | * texture is non-zero. |
| 1200 | */ |
| 1201 | if (texture) { |
| 1202 | GLboolean err = GL_TRUE; |
| 1203 | |
| 1204 | texObj = _mesa_lookup_texture(ctx, texture); |
| 1205 | if (texObj != NULL) { |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 1206 | if (textarget == 0) { |
| 1207 | err = (texObj->Target != GL_TEXTURE_3D) && |
| 1208 | (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT) && |
| 1209 | (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT); |
| 1210 | } |
| 1211 | else { |
| 1212 | err = (texObj->Target == GL_TEXTURE_CUBE_MAP) |
| 1213 | ? !IS_CUBE_FACE(textarget) |
| 1214 | : (texObj->Target != textarget); |
| 1215 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1216 | } |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1217 | |
| 1218 | if (err) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1219 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1220 | "glFramebufferTexture%sEXT(texture target mismatch)", |
| 1221 | caller); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1222 | return; |
| 1223 | } |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1224 | |
| 1225 | if (texObj->Target == GL_TEXTURE_3D) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1226 | const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1); |
| 1227 | if (zoffset < 0 || zoffset >= maxSize) { |
| 1228 | _mesa_error(ctx, GL_INVALID_VALUE, |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 1229 | "glFramebufferTexture%sEXT(zoffset)", caller); |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1230 | return; |
| 1231 | } |
| 1232 | } |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 1233 | else if ((texObj->Target == GL_TEXTURE_1D_ARRAY_EXT) || |
| 1234 | (texObj->Target == GL_TEXTURE_2D_ARRAY_EXT)) { |
| 1235 | if (zoffset < 0 || zoffset >= ctx->Const.MaxArrayTextureLayers) { |
| 1236 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1237 | "glFramebufferTexture%sEXT(layer)", caller); |
| 1238 | return; |
| 1239 | } |
| 1240 | } |
| 1241 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1242 | |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1243 | if ((level < 0) || |
| 1244 | (level >= _mesa_max_texture_levels(ctx, texObj->Target))) { |
| 1245 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1246 | "glFramebufferTexture%sEXT(level)", caller); |
| 1247 | return; |
| 1248 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | att = _mesa_get_attachment(ctx, fb, attachment); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1252 | if (att == NULL) { |
| 1253 | _mesa_error(ctx, GL_INVALID_ENUM, |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1254 | "glFramebufferTexture%sEXT(attachment)", caller); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1255 | return; |
| 1256 | } |
| 1257 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1258 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Keith Whitwell | df05829 | 2006-09-22 11:40:35 +0000 | [diff] [blame] | 1259 | /* The above doesn't fully flush the drivers in the way that a |
| 1260 | * glFlush does, but that is required here: |
| 1261 | */ |
| 1262 | if (ctx->Driver.Flush) |
| 1263 | ctx->Driver.Flush(ctx); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1264 | |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1265 | _glthread_LOCK_MUTEX(fb->Mutex); |
| 1266 | if (texObj) { |
| 1267 | _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget, |
| 1268 | level, zoffset); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1269 | } |
| 1270 | else { |
Brian Paul | 519b23b | 2006-03-20 18:51:57 +0000 | [diff] [blame] | 1271 | _mesa_remove_attachment(ctx, att); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1272 | } |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1273 | _glthread_UNLOCK_MUTEX(fb->Mutex); |
| 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | void GLAPIENTRY |
| 1279 | _mesa_FramebufferTexture1DEXT(GLenum target, GLenum attachment, |
| 1280 | GLenum textarget, GLuint texture, GLint level) |
| 1281 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1282 | GET_CURRENT_CONTEXT(ctx); |
| 1283 | |
| 1284 | if ((texture != 0) && (textarget != GL_TEXTURE_1D)) { |
| 1285 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1286 | "glFramebufferTexture1DEXT(textarget)"); |
| 1287 | return; |
| 1288 | } |
| 1289 | |
| 1290 | framebuffer_texture(ctx, "1D", target, attachment, textarget, texture, |
| 1291 | level, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1295 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1296 | _mesa_FramebufferTexture2DEXT(GLenum target, GLenum attachment, |
| 1297 | GLenum textarget, GLuint texture, GLint level) |
| 1298 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1299 | GET_CURRENT_CONTEXT(ctx); |
| 1300 | |
| 1301 | if ((texture != 0) && |
| 1302 | (textarget != GL_TEXTURE_2D) && |
| 1303 | (textarget != GL_TEXTURE_RECTANGLE_ARB) && |
| 1304 | (!IS_CUBE_FACE(textarget))) { |
| 1305 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1306 | "glFramebufferTexture2DEXT(textarget)"); |
| 1307 | return; |
| 1308 | } |
| 1309 | |
| 1310 | framebuffer_texture(ctx, "2D", target, attachment, textarget, texture, |
| 1311 | level, 0); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1315 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1316 | _mesa_FramebufferTexture3DEXT(GLenum target, GLenum attachment, |
| 1317 | GLenum textarget, GLuint texture, |
| 1318 | GLint level, GLint zoffset) |
| 1319 | { |
Ian Romanick | b0fe0d8 | 2007-05-15 13:42:25 -0700 | [diff] [blame] | 1320 | GET_CURRENT_CONTEXT(ctx); |
| 1321 | |
| 1322 | if ((texture != 0) && (textarget != GL_TEXTURE_3D)) { |
| 1323 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1324 | "glFramebufferTexture3DEXT(textarget)"); |
| 1325 | return; |
| 1326 | } |
| 1327 | |
| 1328 | framebuffer_texture(ctx, "3D", target, attachment, textarget, texture, |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1329 | level, zoffset); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1333 | void GLAPIENTRY |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 1334 | _mesa_FramebufferTextureLayerEXT(GLenum target, GLenum attachment, |
| 1335 | GLuint texture, GLint level, GLint layer) |
| 1336 | { |
| 1337 | GET_CURRENT_CONTEXT(ctx); |
| 1338 | |
| 1339 | framebuffer_texture(ctx, "Layer", target, attachment, 0, texture, |
| 1340 | level, layer); |
| 1341 | } |
| 1342 | |
| 1343 | |
| 1344 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1345 | _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment, |
| 1346 | GLenum renderbufferTarget, |
| 1347 | GLuint renderbuffer) |
| 1348 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1349 | struct gl_renderbuffer_attachment *att; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1350 | struct gl_framebuffer *fb; |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1351 | struct gl_renderbuffer *rb; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1352 | GET_CURRENT_CONTEXT(ctx); |
| 1353 | |
| 1354 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1355 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1356 | switch (target) { |
| 1357 | #if FEATURE_EXT_framebuffer_blit |
| 1358 | case GL_DRAW_FRAMEBUFFER_EXT: |
| 1359 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1360 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1361 | "glFramebufferRenderbufferEXT(target)"); |
| 1362 | return; |
| 1363 | } |
| 1364 | fb = ctx->DrawBuffer; |
| 1365 | break; |
| 1366 | case GL_READ_FRAMEBUFFER_EXT: |
| 1367 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1368 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1369 | "glFramebufferRenderbufferEXT(target)"); |
| 1370 | return; |
| 1371 | } |
| 1372 | fb = ctx->ReadBuffer; |
| 1373 | break; |
| 1374 | #endif |
| 1375 | case GL_FRAMEBUFFER_EXT: |
| 1376 | fb = ctx->DrawBuffer; |
| 1377 | break; |
| 1378 | default: |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1379 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1380 | "glFramebufferRenderbufferEXT(target)"); |
| 1381 | return; |
| 1382 | } |
| 1383 | |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1384 | if (renderbufferTarget != GL_RENDERBUFFER_EXT) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1385 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1386 | "glFramebufferRenderbufferEXT(renderbufferTarget)"); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1387 | return; |
| 1388 | } |
| 1389 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1390 | if (fb->Name == 0) { |
Brian Paul | ab8ef28 | 2005-09-07 23:21:59 +0000 | [diff] [blame] | 1391 | /* Can't attach new renderbuffers to a window system framebuffer */ |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1392 | _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT"); |
| 1393 | return; |
| 1394 | } |
| 1395 | |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 1396 | att = _mesa_get_attachment(ctx, fb, attachment); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1397 | if (att == NULL) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1398 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1399 | "glFramebufferRenderbufferEXT(attachment)"); |
| 1400 | return; |
| 1401 | } |
| 1402 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1403 | if (renderbuffer) { |
Brian Paul | ea4fe66 | 2006-03-26 05:22:17 +0000 | [diff] [blame] | 1404 | rb = _mesa_lookup_renderbuffer(ctx, renderbuffer); |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1405 | if (!rb) { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1406 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1407 | "glFramebufferRenderbufferEXT(renderbuffer)"); |
| 1408 | return; |
| 1409 | } |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1410 | } |
| 1411 | else { |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1412 | /* remove renderbuffer attachment */ |
| 1413 | rb = NULL; |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1414 | } |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1415 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1416 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Keith Whitwell | df05829 | 2006-09-22 11:40:35 +0000 | [diff] [blame] | 1417 | /* The above doesn't fully flush the drivers in the way that a |
| 1418 | * glFlush does, but that is required here: |
| 1419 | */ |
| 1420 | if (ctx->Driver.Flush) |
| 1421 | ctx->Driver.Flush(ctx); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1422 | |
Brian Paul | e4b2356 | 2005-05-04 20:11:35 +0000 | [diff] [blame] | 1423 | assert(ctx->Driver.FramebufferRenderbuffer); |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 1424 | ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb); |
Brian Paul | 2e01918 | 2006-03-07 01:43:52 +0000 | [diff] [blame] | 1425 | |
| 1426 | /* Some subsequent GL commands may depend on the framebuffer's visual |
| 1427 | * after the binding is updated. Update visual info now. |
| 1428 | */ |
| 1429 | _mesa_update_framebuffer_visual(fb); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1433 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1434 | _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, |
| 1435 | GLenum pname, GLint *params) |
| 1436 | { |
Brian Paul | 2c6f911 | 2005-02-24 05:47:06 +0000 | [diff] [blame] | 1437 | const struct gl_renderbuffer_attachment *att; |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1438 | struct gl_framebuffer *buffer; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1439 | GET_CURRENT_CONTEXT(ctx); |
| 1440 | |
| 1441 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1442 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1443 | switch (target) { |
| 1444 | #if FEATURE_EXT_framebuffer_blit |
| 1445 | case GL_DRAW_FRAMEBUFFER_EXT: |
| 1446 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1447 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1448 | "glGetFramebufferAttachmentParameterivEXT(target)"); |
| 1449 | return; |
| 1450 | } |
| 1451 | buffer = ctx->DrawBuffer; |
| 1452 | break; |
| 1453 | case GL_READ_FRAMEBUFFER_EXT: |
| 1454 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1455 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1456 | "glGetFramebufferAttachmentParameterivEXT(target)"); |
| 1457 | return; |
| 1458 | } |
| 1459 | buffer = ctx->ReadBuffer; |
| 1460 | break; |
| 1461 | #endif |
| 1462 | case GL_FRAMEBUFFER_EXT: |
| 1463 | buffer = ctx->DrawBuffer; |
| 1464 | break; |
| 1465 | default: |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1466 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1467 | "glGetFramebufferAttachmentParameterivEXT(target)"); |
| 1468 | return; |
| 1469 | } |
| 1470 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1471 | if (buffer->Name == 0) { |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1472 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1473 | "glGetFramebufferAttachmentParameterivEXT"); |
| 1474 | return; |
| 1475 | } |
| 1476 | |
Brian Paul | 8471604 | 2005-11-16 04:05:54 +0000 | [diff] [blame] | 1477 | att = _mesa_get_attachment(ctx, buffer, attachment); |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1478 | if (att == NULL) { |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1479 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1480 | "glGetFramebufferAttachmentParameterivEXT(attachment)"); |
| 1481 | return; |
| 1482 | } |
| 1483 | |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1484 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Keith Whitwell | df05829 | 2006-09-22 11:40:35 +0000 | [diff] [blame] | 1485 | /* The above doesn't fully flush the drivers in the way that a |
| 1486 | * glFlush does, but that is required here: |
| 1487 | */ |
| 1488 | if (ctx->Driver.Flush) |
| 1489 | ctx->Driver.Flush(ctx); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1490 | |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1491 | switch (pname) { |
| 1492 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1493 | *params = att->Type; |
| 1494 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1495 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1496 | if (att->Type == GL_RENDERBUFFER_EXT) { |
| 1497 | *params = att->Renderbuffer->Name; |
| 1498 | } |
| 1499 | else if (att->Type == GL_TEXTURE) { |
| 1500 | *params = att->Texture->Name; |
| 1501 | } |
| 1502 | else { |
| 1503 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1504 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 1505 | } |
| 1506 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1507 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1508 | if (att->Type == GL_TEXTURE) { |
| 1509 | *params = att->TextureLevel; |
| 1510 | } |
| 1511 | else { |
| 1512 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1513 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 1514 | } |
| 1515 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1516 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1517 | if (att->Type == GL_TEXTURE) { |
Brian Paul | f1e4ca7 | 2008-08-06 08:39:54 -0600 | [diff] [blame] | 1518 | if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) { |
| 1519 | *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace; |
| 1520 | } |
| 1521 | else { |
| 1522 | *params = 0; |
| 1523 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1524 | } |
| 1525 | else { |
| 1526 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1527 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 1528 | } |
| 1529 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1530 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT: |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1531 | if (att->Type == GL_TEXTURE) { |
Brian Paul | f1e4ca7 | 2008-08-06 08:39:54 -0600 | [diff] [blame] | 1532 | if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) { |
| 1533 | *params = att->Zoffset; |
| 1534 | } |
| 1535 | else { |
| 1536 | *params = 0; |
| 1537 | } |
Brian Paul | 3deaa01 | 2005-02-07 05:08:24 +0000 | [diff] [blame] | 1538 | } |
| 1539 | else { |
| 1540 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1541 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 1542 | } |
| 1543 | return; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1544 | default: |
| 1545 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1546 | "glGetFramebufferAttachmentParameterivEXT(pname)"); |
| 1547 | return; |
| 1548 | } |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | |
Brian Paul | 1864c7d | 2005-02-08 03:46:37 +0000 | [diff] [blame] | 1552 | void GLAPIENTRY |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1553 | _mesa_GenerateMipmapEXT(GLenum target) |
| 1554 | { |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1555 | struct gl_texture_unit *texUnit; |
| 1556 | struct gl_texture_object *texObj; |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1557 | GET_CURRENT_CONTEXT(ctx); |
| 1558 | |
| 1559 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
Brian Paul | 474f28e | 2005-10-08 14:41:17 +0000 | [diff] [blame] | 1560 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1561 | |
| 1562 | switch (target) { |
| 1563 | case GL_TEXTURE_1D: |
| 1564 | case GL_TEXTURE_2D: |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1565 | case GL_TEXTURE_3D: |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1566 | case GL_TEXTURE_CUBE_MAP: |
Brian Paul | 1b93953 | 2005-05-31 23:55:21 +0000 | [diff] [blame] | 1567 | /* OK, legal value */ |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1568 | break; |
| 1569 | default: |
| 1570 | _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target)"); |
| 1571 | return; |
| 1572 | } |
| 1573 | |
Brian Paul | 463642c | 2005-02-08 02:06:00 +0000 | [diff] [blame] | 1574 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1575 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1576 | |
| 1577 | /* XXX this might not handle cube maps correctly */ |
Keith Whitwell | 5ac93f8 | 2006-11-01 14:21:57 +0000 | [diff] [blame] | 1578 | _mesa_lock_texture(ctx, texObj); |
Brian | d4e1d85 | 2008-02-08 14:45:58 -0700 | [diff] [blame] | 1579 | ctx->Driver.GenerateMipmap(ctx, target, texObj); |
Keith Whitwell | 5ac93f8 | 2006-11-01 14:21:57 +0000 | [diff] [blame] | 1580 | _mesa_unlock_texture(ctx, texObj); |
Brian Paul | ddc82ee | 2005-02-05 19:56:45 +0000 | [diff] [blame] | 1581 | } |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1582 | |
| 1583 | |
| 1584 | #if FEATURE_EXT_framebuffer_blit |
| 1585 | void GLAPIENTRY |
| 1586 | _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 1587 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 1588 | GLbitfield mask, GLenum filter) |
| 1589 | { |
| 1590 | GET_CURRENT_CONTEXT(ctx); |
| 1591 | |
| 1592 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 1593 | FLUSH_VERTICES(ctx, _NEW_BUFFERS); |
| 1594 | |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 1595 | if (ctx->NewState) { |
| 1596 | _mesa_update_state(ctx); |
| 1597 | } |
| 1598 | |
| 1599 | if (!ctx->ReadBuffer) { |
| 1600 | /* XXX */ |
| 1601 | } |
| 1602 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1603 | /* check for complete framebuffers */ |
| 1604 | if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT || |
| 1605 | ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { |
| 1606 | _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, |
| 1607 | "glBlitFramebufferEXT(incomplete draw/read buffers)"); |
| 1608 | return; |
| 1609 | } |
| 1610 | |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 1611 | if (filter != GL_NEAREST && filter != GL_LINEAR) { |
| 1612 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(filter)"); |
| 1613 | return; |
| 1614 | } |
| 1615 | |
| 1616 | if (mask & ~(GL_COLOR_BUFFER_BIT | |
| 1617 | GL_DEPTH_BUFFER_BIT | |
| 1618 | GL_STENCIL_BUFFER_BIT)) { |
| 1619 | _mesa_error( ctx, GL_INVALID_VALUE, "glBlitFramebufferEXT(mask)"); |
| 1620 | return; |
| 1621 | } |
| 1622 | |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1623 | /* depth/stencil must be blitted with nearest filtering */ |
| 1624 | if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) |
| 1625 | && filter != GL_NEAREST) { |
| 1626 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1627 | "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter"); |
| 1628 | return; |
| 1629 | } |
| 1630 | |
Brian Paul | 9974540 | 2006-03-01 02:02:43 +0000 | [diff] [blame] | 1631 | if (mask & GL_STENCIL_BUFFER_BIT) { |
| 1632 | struct gl_renderbuffer *readRb = ctx->ReadBuffer->_StencilBuffer; |
| 1633 | struct gl_renderbuffer *drawRb = ctx->DrawBuffer->_StencilBuffer; |
| 1634 | if (readRb->StencilBits != drawRb->StencilBits) { |
| 1635 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1636 | "glBlitFramebufferEXT(stencil buffer size mismatch"); |
| 1637 | return; |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | if (mask & GL_DEPTH_BUFFER_BIT) { |
| 1642 | struct gl_renderbuffer *readRb = ctx->ReadBuffer->_DepthBuffer; |
| 1643 | struct gl_renderbuffer *drawRb = ctx->DrawBuffer->_DepthBuffer; |
| 1644 | if (readRb->DepthBits != drawRb->DepthBits) { |
| 1645 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1646 | "glBlitFramebufferEXT(depth buffer size mismatch"); |
| 1647 | return; |
| 1648 | } |
Brian Paul | 0bffb11 | 2005-11-08 14:45:48 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | if (!ctx->Extensions.EXT_framebuffer_blit) { |
| 1652 | _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT"); |
| 1653 | return; |
| 1654 | } |
| 1655 | |
| 1656 | ASSERT(ctx->Driver.BlitFramebuffer); |
| 1657 | ctx->Driver.BlitFramebuffer(ctx, |
| 1658 | srcX0, srcY0, srcX1, srcY1, |
| 1659 | dstX0, dstY0, dstX1, dstY1, |
| 1660 | mask, filter); |
| 1661 | } |
| 1662 | #endif /* FEATURE_EXT_framebuffer_blit */ |