blob: ab91fbc4de901d0c4d3a96b80b8711ec405dca85 [file] [log] [blame]
Brian Paulddc82ee2005-02-05 19:56:45 +00001/*
2 * Mesa 3-D graphics library
Brian Paul3dc65912008-07-03 15:40:38 -06003 * Version: 7.1
Brian Paulddc82ee2005-02-05 19:56:45 +00004 *
Brian Paul3dc65912008-07-03 15:40:38 -06005 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
Brian Paul989edea2009-01-22 15:05:13 -07006 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
Brian Paulddc82ee2005-02-05 19:56:45 +00007 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
Brian Paul463642c2005-02-08 02:06:00 +000027/*
Brian Paul989edea2009-01-22 15:05:13 -070028 * GL_EXT/ARB_framebuffer_object extensions
29 *
Brian Paul463642c2005-02-08 02:06:00 +000030 * Authors:
31 * Brian Paul
32 */
33
34
Roland Scheideggera1bc0d02007-07-18 20:17:14 +020035#include "buffers.h"
Brian Paulddc82ee2005-02-05 19:56:45 +000036#include "context.h"
37#include "fbobject.h"
Brian Paule4b23562005-05-04 20:11:35 +000038#include "framebuffer.h"
Brian Paulddc82ee2005-02-05 19:56:45 +000039#include "hash.h"
Brian Paul989edea2009-01-22 15:05:13 -070040#include "macros.h"
Brian Paul24edd902006-09-29 01:24:26 +000041#include "mipmap.h"
Brian Paule4b23562005-05-04 20:11:35 +000042#include "renderbuffer.h"
Brian Paul99745402006-03-01 02:02:43 +000043#include "state.h"
Brian Paul463642c2005-02-08 02:06:00 +000044#include "teximage.h"
Brian Paulea4fe662006-03-26 05:22:17 +000045#include "texobj.h"
Brian Paul463642c2005-02-08 02:06:00 +000046#include "texstore.h"
Brian Paulddc82ee2005-02-05 19:56:45 +000047
48
Brian Pauld9468c92005-02-10 16:08:07 +000049/**
50 * Notes:
51 *
52 * None of the GL_EXT_framebuffer_object functions are compiled into
53 * display lists.
54 */
55
56
57
Brian Paul923b6fc2005-02-08 04:08:56 +000058/*
59 * When glGenRender/FramebuffersEXT() is called we insert pointers to
60 * these placeholder objects into the hash table.
61 * Later, when the object ID is first bound, we replace the placeholder
62 * with the real frame/renderbuffer.
63 */
Brian Paul2c6f9112005-02-24 05:47:06 +000064static struct gl_framebuffer DummyFramebuffer;
65static struct gl_renderbuffer DummyRenderbuffer;
Brian Paul1864c7d2005-02-08 03:46:37 +000066
67
Brian Paul3deaa012005-02-07 05:08:24 +000068#define IS_CUBE_FACE(TARGET) \
69 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
70 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
Brian Paulddc82ee2005-02-05 19:56:45 +000071
72
Brian Paul3dc65912008-07-03 15:40:38 -060073static void
74delete_dummy_renderbuffer(struct gl_renderbuffer *rb)
75{
76 /* no op */
77}
78
79static void
80delete_dummy_framebuffer(struct gl_framebuffer *fb)
81{
82 /* no op */
83}
84
85
86void
87_mesa_init_fbobjects(GLcontext *ctx)
88{
89 DummyFramebuffer.Delete = delete_dummy_framebuffer;
90 DummyRenderbuffer.Delete = delete_dummy_renderbuffer;
91}
92
93
Brian Paulddc82ee2005-02-05 19:56:45 +000094/**
Brian Paul2c6f9112005-02-24 05:47:06 +000095 * Helper routine for getting a gl_renderbuffer.
Brian Paulddc82ee2005-02-05 19:56:45 +000096 */
Brian Paulea4fe662006-03-26 05:22:17 +000097struct gl_renderbuffer *
98_mesa_lookup_renderbuffer(GLcontext *ctx, GLuint id)
Brian Paulddc82ee2005-02-05 19:56:45 +000099{
Brian Paul2c6f9112005-02-24 05:47:06 +0000100 struct gl_renderbuffer *rb;
Brian Paulddc82ee2005-02-05 19:56:45 +0000101
Brian Paul1864c7d2005-02-08 03:46:37 +0000102 if (id == 0)
Brian Paulddc82ee2005-02-05 19:56:45 +0000103 return NULL;
104
Brian Paul2c6f9112005-02-24 05:47:06 +0000105 rb = (struct gl_renderbuffer *)
Brian Paulddc82ee2005-02-05 19:56:45 +0000106 _mesa_HashLookup(ctx->Shared->RenderBuffers, id);
107 return rb;
108}
109
110
111/**
Brian Paul2c6f9112005-02-24 05:47:06 +0000112 * Helper routine for getting a gl_framebuffer.
Brian Paulddc82ee2005-02-05 19:56:45 +0000113 */
Brian Paulea4fe662006-03-26 05:22:17 +0000114struct gl_framebuffer *
115_mesa_lookup_framebuffer(GLcontext *ctx, GLuint id)
Brian Paulddc82ee2005-02-05 19:56:45 +0000116{
Brian Paul2c6f9112005-02-24 05:47:06 +0000117 struct gl_framebuffer *fb;
Brian Paulddc82ee2005-02-05 19:56:45 +0000118
Brian Paul1864c7d2005-02-08 03:46:37 +0000119 if (id == 0)
Brian Paulddc82ee2005-02-05 19:56:45 +0000120 return NULL;
121
Brian Paul2c6f9112005-02-24 05:47:06 +0000122 fb = (struct gl_framebuffer *)
Brian Paulddc82ee2005-02-05 19:56:45 +0000123 _mesa_HashLookup(ctx->Shared->FrameBuffers, id);
Brian Paul463642c2005-02-08 02:06:00 +0000124 return fb;
Brian Paulddc82ee2005-02-05 19:56:45 +0000125}
126
127
128/**
Brian Paul72966362009-01-21 16:28:38 -0700129 * Mark the given framebuffer as invalid. This will force the
130 * test for framebuffer completeness to be done before the framebuffer
131 * is used.
132 */
133static void
134invalidate_framebuffer(struct gl_framebuffer *fb)
135{
136 fb->_Status = 0; /* "indeterminate" */
137}
138
139
140/**
Brian Pauld9468c92005-02-10 16:08:07 +0000141 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
Brian Paul2c6f9112005-02-24 05:47:06 +0000142 * gl_renderbuffer_attachment object.
Brian Paul30590072009-01-21 11:06:11 -0700143 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
144 * the depth buffer attachment point.
Brian Pauld9468c92005-02-10 16:08:07 +0000145 */
Brian Paul84716042005-11-16 04:05:54 +0000146struct gl_renderbuffer_attachment *
147_mesa_get_attachment(GLcontext *ctx, struct gl_framebuffer *fb,
148 GLenum attachment)
Brian Paul3deaa012005-02-07 05:08:24 +0000149{
150 GLuint i;
151
152 switch (attachment) {
153 case GL_COLOR_ATTACHMENT0_EXT:
154 case GL_COLOR_ATTACHMENT1_EXT:
155 case GL_COLOR_ATTACHMENT2_EXT:
156 case GL_COLOR_ATTACHMENT3_EXT:
157 case GL_COLOR_ATTACHMENT4_EXT:
158 case GL_COLOR_ATTACHMENT5_EXT:
159 case GL_COLOR_ATTACHMENT6_EXT:
160 case GL_COLOR_ATTACHMENT7_EXT:
161 case GL_COLOR_ATTACHMENT8_EXT:
162 case GL_COLOR_ATTACHMENT9_EXT:
163 case GL_COLOR_ATTACHMENT10_EXT:
164 case GL_COLOR_ATTACHMENT11_EXT:
165 case GL_COLOR_ATTACHMENT12_EXT:
166 case GL_COLOR_ATTACHMENT13_EXT:
167 case GL_COLOR_ATTACHMENT14_EXT:
168 case GL_COLOR_ATTACHMENT15_EXT:
169 i = attachment - GL_COLOR_ATTACHMENT0_EXT;
170 if (i >= ctx->Const.MaxColorAttachments) {
171 return NULL;
172 }
Brian Paule4b23562005-05-04 20:11:35 +0000173 return &fb->Attachment[BUFFER_COLOR0 + i];
Brian Paul30590072009-01-21 11:06:11 -0700174 case GL_DEPTH_STENCIL_ATTACHMENT:
175 /* fall-through */
Brian Paul3deaa012005-02-07 05:08:24 +0000176 case GL_DEPTH_ATTACHMENT_EXT:
Brian Paule4b23562005-05-04 20:11:35 +0000177 return &fb->Attachment[BUFFER_DEPTH];
Brian Paul3deaa012005-02-07 05:08:24 +0000178 case GL_STENCIL_ATTACHMENT_EXT:
Brian Paule4b23562005-05-04 20:11:35 +0000179 return &fb->Attachment[BUFFER_STENCIL];
Brian Paul3deaa012005-02-07 05:08:24 +0000180 default:
181 return NULL;
182 }
183}
184
185
Brian Pauld9468c92005-02-10 16:08:07 +0000186/**
187 * Remove any texture or renderbuffer attached to the given attachment
188 * point. Update reference counts, etc.
189 */
Brian Paule4b23562005-05-04 20:11:35 +0000190void
191_mesa_remove_attachment(GLcontext *ctx, struct gl_renderbuffer_attachment *att)
Brian Paul3deaa012005-02-07 05:08:24 +0000192{
193 if (att->Type == GL_TEXTURE) {
194 ASSERT(att->Texture);
Brian9e01b912007-08-13 11:29:46 +0100195 if (ctx->Driver.FinishRenderTexture) {
Brian Paul0e31e022005-12-01 00:25:00 +0000196 /* tell driver that we're done rendering to this texture. */
Brian9e01b912007-08-13 11:29:46 +0100197 ctx->Driver.FinishRenderTexture(ctx, att);
Brian Paul3deaa012005-02-07 05:08:24 +0000198 }
Brian9e01b912007-08-13 11:29:46 +0100199 _mesa_reference_texobj(&att->Texture, NULL); /* unbind */
200 ASSERT(!att->Texture);
Brian Paul3deaa012005-02-07 05:08:24 +0000201 }
Brian Paul0e31e022005-12-01 00:25:00 +0000202 if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) {
Brian Paul3deaa012005-02-07 05:08:24 +0000203 ASSERT(!att->Texture);
Brian9e01b912007-08-13 11:29:46 +0100204 _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */
205 ASSERT(!att->Renderbuffer);
Brian Paul3deaa012005-02-07 05:08:24 +0000206 }
207 att->Type = GL_NONE;
Brian Paulf0bbbf62005-02-09 03:50:30 +0000208 att->Complete = GL_TRUE;
Brian Paul3deaa012005-02-07 05:08:24 +0000209}
210
211
Brian Pauld9468c92005-02-10 16:08:07 +0000212/**
213 * Bind a texture object to an attachment point.
214 * The previous binding, if any, will be removed first.
215 */
Brian Paule4b23562005-05-04 20:11:35 +0000216void
217_mesa_set_texture_attachment(GLcontext *ctx,
Brian Paul519b23b2006-03-20 18:51:57 +0000218 struct gl_framebuffer *fb,
Brian Paule4b23562005-05-04 20:11:35 +0000219 struct gl_renderbuffer_attachment *att,
220 struct gl_texture_object *texObj,
221 GLenum texTarget, GLuint level, GLuint zoffset)
Brian Paul3deaa012005-02-07 05:08:24 +0000222{
Brian Paul0e31e022005-12-01 00:25:00 +0000223 if (att->Texture == texObj) {
224 /* re-attaching same texture */
225 ASSERT(att->Type == GL_TEXTURE);
226 }
227 else {
228 /* new attachment */
229 _mesa_remove_attachment(ctx, att);
230 att->Type = GL_TEXTURE;
Brian9e01b912007-08-13 11:29:46 +0100231 assert(!att->Texture);
232 _mesa_reference_texobj(&att->Texture, texObj);
Brian Paul0e31e022005-12-01 00:25:00 +0000233 }
234
235 /* always update these fields */
Brian Paul3deaa012005-02-07 05:08:24 +0000236 att->TextureLevel = level;
237 if (IS_CUBE_FACE(texTarget)) {
238 att->CubeMapFace = texTarget - GL_TEXTURE_CUBE_MAP_POSITIVE_X;
239 }
240 else {
241 att->CubeMapFace = 0;
242 }
243 att->Zoffset = zoffset;
Brian Paulf0bbbf62005-02-09 03:50:30 +0000244 att->Complete = GL_FALSE;
Brian Paul519b23b2006-03-20 18:51:57 +0000245
246 if (att->Texture->Image[att->CubeMapFace][att->TextureLevel]) {
Brian Paulea4fe662006-03-26 05:22:17 +0000247 ctx->Driver.RenderTexture(ctx, fb, att);
Brian Paul519b23b2006-03-20 18:51:57 +0000248 }
Brian Paul72966362009-01-21 16:28:38 -0700249
250 invalidate_framebuffer(fb);
Brian Paul3deaa012005-02-07 05:08:24 +0000251}
252
253
Brian Pauld9468c92005-02-10 16:08:07 +0000254/**
255 * Bind a renderbuffer to an attachment point.
256 * The previous binding, if any, will be removed first.
257 */
Brian Paule4b23562005-05-04 20:11:35 +0000258void
259_mesa_set_renderbuffer_attachment(GLcontext *ctx,
260 struct gl_renderbuffer_attachment *att,
261 struct gl_renderbuffer *rb)
Brian Paul3deaa012005-02-07 05:08:24 +0000262{
Brian Paulea4fe662006-03-26 05:22:17 +0000263 /* XXX check if re-doing same attachment, exit early */
Brian Paule4b23562005-05-04 20:11:35 +0000264 _mesa_remove_attachment(ctx, att);
Brian Paul3deaa012005-02-07 05:08:24 +0000265 att->Type = GL_RENDERBUFFER_EXT;
Brian Paul2c6f9112005-02-24 05:47:06 +0000266 att->Texture = NULL; /* just to be safe */
Brian Paulf0bbbf62005-02-09 03:50:30 +0000267 att->Complete = GL_FALSE;
Briandccd9c42007-04-02 09:56:28 -0600268 _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
Brian Paul3deaa012005-02-07 05:08:24 +0000269}
270
Brian Paulddc82ee2005-02-05 19:56:45 +0000271
Brian Paulf0bbbf62005-02-09 03:50:30 +0000272/**
Brian Paule4b23562005-05-04 20:11:35 +0000273 * Fallback for ctx->Driver.FramebufferRenderbuffer()
Brian Paul84716042005-11-16 04:05:54 +0000274 * Attach a renderbuffer object to a framebuffer object.
Brian Paule4b23562005-05-04 20:11:35 +0000275 */
276void
Brian Paul84716042005-11-16 04:05:54 +0000277_mesa_framebuffer_renderbuffer(GLcontext *ctx, struct gl_framebuffer *fb,
278 GLenum attachment, struct gl_renderbuffer *rb)
Brian Paule4b23562005-05-04 20:11:35 +0000279{
Brian Paul84716042005-11-16 04:05:54 +0000280 struct gl_renderbuffer_attachment *att;
281
Brian Paulea4fe662006-03-26 05:22:17 +0000282 _glthread_LOCK_MUTEX(fb->Mutex);
Brian Paulea4fe662006-03-26 05:22:17 +0000283
Brian Paul84716042005-11-16 04:05:54 +0000284 att = _mesa_get_attachment(ctx, fb, attachment);
285 ASSERT(att);
Brian Paule4b23562005-05-04 20:11:35 +0000286 if (rb) {
287 _mesa_set_renderbuffer_attachment(ctx, att, rb);
Brian Paul30590072009-01-21 11:06:11 -0700288 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
289 /* do stencil attachment here (depth already done above) */
290 att = _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
291 assert(att);
292 _mesa_set_renderbuffer_attachment(ctx, att, rb);
293 }
Brian Paule4b23562005-05-04 20:11:35 +0000294 }
295 else {
296 _mesa_remove_attachment(ctx, att);
297 }
Brian Paulea4fe662006-03-26 05:22:17 +0000298
Brian Paul72966362009-01-21 16:28:38 -0700299 invalidate_framebuffer(fb);
300
Brian Paulea4fe662006-03-26 05:22:17 +0000301 _glthread_UNLOCK_MUTEX(fb->Mutex);
Brian Paule4b23562005-05-04 20:11:35 +0000302}
303
304
305/**
Brian Paul9f731c82009-02-17 16:47:54 -0700306 * For debug only.
307 */
308static void
309att_incomplete(const char *msg)
310{
311#if 0
312 _mesa_printf("attachment incomplete: %s\n", msg);
313#else
314 (void) msg;
315#endif
316}
317
318
319/**
Brian Paulf0bbbf62005-02-09 03:50:30 +0000320 * Test if an attachment point is complete and update its Complete field.
321 * \param format if GL_COLOR, this is a color attachment point,
322 * if GL_DEPTH, this is a depth component attachment point,
323 * if GL_STENCIL, this is a stencil component attachment point.
324 */
325static void
326test_attachment_completeness(const GLcontext *ctx, GLenum format,
Brian Paul2c6f9112005-02-24 05:47:06 +0000327 struct gl_renderbuffer_attachment *att)
Brian Paulf0bbbf62005-02-09 03:50:30 +0000328{
329 assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL);
330
331 /* assume complete */
332 att->Complete = GL_TRUE;
333
Brian Paulf0bbbf62005-02-09 03:50:30 +0000334 /* Look for reasons why the attachment might be incomplete */
335 if (att->Type == GL_TEXTURE) {
Brian Paule4b23562005-05-04 20:11:35 +0000336 const struct gl_texture_object *texObj = att->Texture;
Brian Paulf0bbbf62005-02-09 03:50:30 +0000337 struct gl_texture_image *texImage;
338
Brian Paule4b23562005-05-04 20:11:35 +0000339 if (!texObj) {
Brian Paul9f731c82009-02-17 16:47:54 -0700340 att_incomplete("no texobj");
Brian Paule4b23562005-05-04 20:11:35 +0000341 att->Complete = GL_FALSE;
342 return;
343 }
Brian Paulf0bbbf62005-02-09 03:50:30 +0000344
345 texImage = texObj->Image[att->CubeMapFace][att->TextureLevel];
346 if (!texImage) {
Brian Paul9f731c82009-02-17 16:47:54 -0700347 att_incomplete("no teximage");
Brian Paulf0bbbf62005-02-09 03:50:30 +0000348 att->Complete = GL_FALSE;
349 return;
350 }
351 if (texImage->Width < 1 || texImage->Height < 1) {
Brian Paul9f731c82009-02-17 16:47:54 -0700352 att_incomplete("teximage width/height=0");
353 _mesa_printf("texobj = %u\n", texObj->Name);
354 _mesa_printf("level = %d\n", att->TextureLevel);
Brian Paulf0bbbf62005-02-09 03:50:30 +0000355 att->Complete = GL_FALSE;
356 return;
357 }
358 if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) {
Brian Paul9f731c82009-02-17 16:47:54 -0700359 att_incomplete("bad z offset");
Brian Paulf0bbbf62005-02-09 03:50:30 +0000360 att->Complete = GL_FALSE;
361 return;
362 }
363
364 if (format == GL_COLOR) {
Brian Paule4b23562005-05-04 20:11:35 +0000365 if (texImage->TexFormat->BaseFormat != GL_RGB &&
366 texImage->TexFormat->BaseFormat != GL_RGBA) {
Brian Paul9f731c82009-02-17 16:47:54 -0700367 att_incomplete("bad format");
Brian Paulf0bbbf62005-02-09 03:50:30 +0000368 att->Complete = GL_FALSE;
369 return;
370 }
Eric Anholt957f3c82009-05-15 16:24:59 -0700371 if (texImage->TexFormat->TexelBytes == 0) {
372 att_incomplete("compressed internalformat");
373 att->Complete = GL_FALSE;
374 return;
375 }
Brian Paulf0bbbf62005-02-09 03:50:30 +0000376 }
377 else if (format == GL_DEPTH) {
Brian Paul1ad7b992005-09-28 02:29:50 +0000378 if (texImage->TexFormat->BaseFormat == GL_DEPTH_COMPONENT) {
379 /* OK */
380 }
381 else if (ctx->Extensions.EXT_packed_depth_stencil &&
Mathias Fröhlich042d9a52009-05-19 09:59:01 -0600382 ctx->Extensions.ARB_depth_texture &&
Brian635e9642008-03-28 13:24:12 -0600383 texImage->TexFormat->BaseFormat == GL_DEPTH_STENCIL_EXT) {
Brian Paul1ad7b992005-09-28 02:29:50 +0000384 /* OK */
385 }
386 else {
Brian Paulf0bbbf62005-02-09 03:50:30 +0000387 att->Complete = GL_FALSE;
Brian Paul9f731c82009-02-17 16:47:54 -0700388 att_incomplete("bad depth format");
Brian Paulf0bbbf62005-02-09 03:50:30 +0000389 return;
390 }
391 }
392 else {
Mathias Fröhlich042d9a52009-05-19 09:59:01 -0600393 ASSERT(format == GL_STENCIL);
394 ASSERT(att->Renderbuffer->StencilBits);
395 if (ctx->Extensions.EXT_packed_depth_stencil &&
396 ctx->Extensions.ARB_depth_texture &&
397 att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) {
398 /* OK */
399 }
400 else {
401 /* no such thing as stencil-only textures */
402 att_incomplete("illegal stencil texture");
403 att->Complete = GL_FALSE;
404 return;
405 }
Brian Paulf0bbbf62005-02-09 03:50:30 +0000406 }
407 }
Brian Paule4b23562005-05-04 20:11:35 +0000408 else if (att->Type == GL_RENDERBUFFER_EXT) {
Brian Paul49918882006-03-20 15:27:55 +0000409 ASSERT(att->Renderbuffer);
410 if (!att->Renderbuffer->InternalFormat ||
411 att->Renderbuffer->Width < 1 ||
412 att->Renderbuffer->Height < 1) {
Brian Paul9f731c82009-02-17 16:47:54 -0700413 att_incomplete("0x0 renderbuffer");
Brian Paulf0bbbf62005-02-09 03:50:30 +0000414 att->Complete = GL_FALSE;
415 return;
416 }
417 if (format == GL_COLOR) {
418 if (att->Renderbuffer->_BaseFormat != GL_RGB &&
419 att->Renderbuffer->_BaseFormat != GL_RGBA) {
Brian Paul49918882006-03-20 15:27:55 +0000420 ASSERT(att->Renderbuffer->RedBits);
421 ASSERT(att->Renderbuffer->GreenBits);
422 ASSERT(att->Renderbuffer->BlueBits);
Brian Paul9f731c82009-02-17 16:47:54 -0700423 att_incomplete("bad renderbuffer color format");
Brian Paulf0bbbf62005-02-09 03:50:30 +0000424 att->Complete = GL_FALSE;
425 return;
426 }
427 }
428 else if (format == GL_DEPTH) {
Brian Paul49918882006-03-20 15:27:55 +0000429 ASSERT(att->Renderbuffer->DepthBits);
Brian Paul1ad7b992005-09-28 02:29:50 +0000430 if (att->Renderbuffer->_BaseFormat == GL_DEPTH_COMPONENT) {
431 /* OK */
432 }
433 else if (ctx->Extensions.EXT_packed_depth_stencil &&
434 att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) {
435 /* OK */
436 }
437 else {
Brian Paul9f731c82009-02-17 16:47:54 -0700438 att_incomplete("bad renderbuffer depth format");
Brian Paulf0bbbf62005-02-09 03:50:30 +0000439 att->Complete = GL_FALSE;
440 return;
441 }
442 }
443 else {
444 assert(format == GL_STENCIL);
Brian Paul49918882006-03-20 15:27:55 +0000445 ASSERT(att->Renderbuffer->StencilBits);
Brian Paul1ad7b992005-09-28 02:29:50 +0000446 if (att->Renderbuffer->_BaseFormat == GL_STENCIL_INDEX) {
447 /* OK */
448 }
449 else if (ctx->Extensions.EXT_packed_depth_stencil &&
450 att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) {
451 /* OK */
452 }
453 else {
Brian Paulf0bbbf62005-02-09 03:50:30 +0000454 att->Complete = GL_FALSE;
Brian Paul9f731c82009-02-17 16:47:54 -0700455 att_incomplete("bad renderbuffer stencil format");
Brian Paulf0bbbf62005-02-09 03:50:30 +0000456 return;
457 }
458 }
459 }
Brian Paule4b23562005-05-04 20:11:35 +0000460 else {
461 ASSERT(att->Type == GL_NONE);
462 /* complete */
463 return;
464 }
Brian Paulf0bbbf62005-02-09 03:50:30 +0000465}
466
467
468/**
Brian Paul49918882006-03-20 15:27:55 +0000469 * Helpful for debugging
470 */
471static void
472fbo_incomplete(const char *msg, int index)
473{
Brian Paul13abf912006-04-13 19:17:13 +0000474 (void) msg;
475 (void) index;
Brian Paul49918882006-03-20 15:27:55 +0000476 /*
477 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
478 */
479}
480
481
482/**
Brian Paulf0bbbf62005-02-09 03:50:30 +0000483 * Test if the given framebuffer object is complete and update its
484 * Status field with the results.
Brian Paul3528f692009-01-22 15:13:18 -0700485 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
486 * driver to make hardware-specific validation/completeness checks.
Brian Paule4b23562005-05-04 20:11:35 +0000487 * Also update the framebuffer's Width and Height fields if the
488 * framebuffer is complete.
Brian Paulf0bbbf62005-02-09 03:50:30 +0000489 */
Brian Paule4b23562005-05-04 20:11:35 +0000490void
491_mesa_test_framebuffer_completeness(GLcontext *ctx, struct gl_framebuffer *fb)
Brian Paulf0bbbf62005-02-09 03:50:30 +0000492{
Brian Paul989edea2009-01-22 15:05:13 -0700493 GLuint numImages;
494 GLenum intFormat = GL_NONE; /* color buffers' internal format */
495 GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0;
Brian Paul722d9762009-01-20 16:58:49 -0700496 GLint numSamples = -1;
Brian Paule4b23562005-05-04 20:11:35 +0000497 GLint i;
Brian Paul28b014e2006-04-05 03:05:17 +0000498 GLuint j;
Brian Paulf0bbbf62005-02-09 03:50:30 +0000499
Brian Paulc7264412005-06-01 00:50:23 +0000500 assert(fb->Name != 0);
501
Brian Paulf0bbbf62005-02-09 03:50:30 +0000502 numImages = 0;
Brian Paule4b23562005-05-04 20:11:35 +0000503 fb->Width = 0;
504 fb->Height = 0;
Brian Paulf0bbbf62005-02-09 03:50:30 +0000505
Brian Paul989edea2009-01-22 15:05:13 -0700506 /* Start at -2 to more easily loop over all attachment points.
507 * -2: depth buffer
508 * -1: stencil buffer
509 * >=0: color buffer
510 */
Brian Paule4b23562005-05-04 20:11:35 +0000511 for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) {
Brian Paul2c6f9112005-02-24 05:47:06 +0000512 struct gl_renderbuffer_attachment *att;
Brian Paulf0bbbf62005-02-09 03:50:30 +0000513 GLenum f;
514
Brian Paul1bc59bf2009-01-22 15:07:34 -0700515 /*
516 * XXX for ARB_fbo, only check color buffers that are named by
517 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
518 */
519
Brian Paul989edea2009-01-22 15:05:13 -0700520 /* check for attachment completeness
521 */
Brian Paulf0bbbf62005-02-09 03:50:30 +0000522 if (i == -2) {
Brian Paule4b23562005-05-04 20:11:35 +0000523 att = &fb->Attachment[BUFFER_DEPTH];
Brian Paulf0bbbf62005-02-09 03:50:30 +0000524 test_attachment_completeness(ctx, GL_DEPTH, att);
525 if (!att->Complete) {
Brian Paule4b23562005-05-04 20:11:35 +0000526 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
Brian Paul49918882006-03-20 15:27:55 +0000527 fbo_incomplete("depth attachment incomplete", -1);
Brian Paulf0bbbf62005-02-09 03:50:30 +0000528 return;
529 }
530 }
531 else if (i == -1) {
Brian Paule4b23562005-05-04 20:11:35 +0000532 att = &fb->Attachment[BUFFER_STENCIL];
Brian Paulf0bbbf62005-02-09 03:50:30 +0000533 test_attachment_completeness(ctx, GL_STENCIL, att);
534 if (!att->Complete) {
Brian Paule4b23562005-05-04 20:11:35 +0000535 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
Brian Paul49918882006-03-20 15:27:55 +0000536 fbo_incomplete("stencil attachment incomplete", -1);
Brian Paulf0bbbf62005-02-09 03:50:30 +0000537 return;
538 }
539 }
540 else {
Brian Paule4b23562005-05-04 20:11:35 +0000541 att = &fb->Attachment[BUFFER_COLOR0 + i];
Brian Paulf0bbbf62005-02-09 03:50:30 +0000542 test_attachment_completeness(ctx, GL_COLOR, att);
543 if (!att->Complete) {
Brian Paule4b23562005-05-04 20:11:35 +0000544 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
Brian Paul49918882006-03-20 15:27:55 +0000545 fbo_incomplete("color attachment incomplete", i);
Brian Paulf0bbbf62005-02-09 03:50:30 +0000546 return;
547 }
548 }
549
Brian Paul989edea2009-01-22 15:05:13 -0700550 /* get width, height, format of the renderbuffer/texture
551 */
Brian Paulf0bbbf62005-02-09 03:50:30 +0000552 if (att->Type == GL_TEXTURE) {
Brian Paula9fc8ba2005-10-05 01:48:07 +0000553 const struct gl_texture_image *texImg
554 = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
Brian Paul989edea2009-01-22 15:05:13 -0700555 minWidth = MIN2(minWidth, texImg->Width);
556 maxWidth = MAX2(maxWidth, texImg->Width);
557 minHeight = MIN2(minHeight, texImg->Height);
558 maxHeight = MAX2(maxHeight, texImg->Height);
Brian Paula9fc8ba2005-10-05 01:48:07 +0000559 f = texImg->_BaseFormat;
Brian Paulf0bbbf62005-02-09 03:50:30 +0000560 numImages++;
Brian Paul9f6ff492006-03-28 15:24:50 +0000561 if (f != GL_RGB && f != GL_RGBA && f != GL_DEPTH_COMPONENT
562 && f != GL_DEPTH_STENCIL_EXT) {
Brian Pauled7f3ae2005-06-07 15:03:40 +0000563 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
Brian Paul49918882006-03-20 15:27:55 +0000564 fbo_incomplete("texture attachment incomplete", -1);
Brian Pauled7f3ae2005-06-07 15:03:40 +0000565 return;
566 }
Brian Paulf0bbbf62005-02-09 03:50:30 +0000567 }
568 else if (att->Type == GL_RENDERBUFFER_EXT) {
Brian Paul989edea2009-01-22 15:05:13 -0700569 minWidth = MIN2(minWidth, att->Renderbuffer->Width);
570 maxWidth = MAX2(minWidth, att->Renderbuffer->Width);
571 minHeight = MIN2(minHeight, att->Renderbuffer->Height);
572 maxHeight = MAX2(minHeight, att->Renderbuffer->Height);
Brian Paulf0bbbf62005-02-09 03:50:30 +0000573 f = att->Renderbuffer->InternalFormat;
574 numImages++;
575 }
576 else {
577 assert(att->Type == GL_NONE);
578 continue;
579 }
580
Brian Paul72966362009-01-21 16:28:38 -0700581 if (numSamples < 0) {
582 /* first buffer */
583 numSamples = att->Renderbuffer->NumSamples;
584 }
585
Brian Paul722d9762009-01-20 16:58:49 -0700586 /* Error-check width, height, format, samples
Brian Paul989edea2009-01-22 15:05:13 -0700587 */
Brian Paulf0bbbf62005-02-09 03:50:30 +0000588 if (numImages == 1) {
Brian Paul722d9762009-01-20 16:58:49 -0700589 /* save format, num samples */
590 if (i >= 0) {
Brian Paulf0bbbf62005-02-09 03:50:30 +0000591 intFormat = f;
Brian Paul722d9762009-01-20 16:58:49 -0700592 }
Brian Paulf0bbbf62005-02-09 03:50:30 +0000593 }
594 else {
Brian Paul989edea2009-01-22 15:05:13 -0700595 if (!ctx->Extensions.ARB_framebuffer_object) {
596 /* check that width, height, format are same */
597 if (minWidth != maxWidth || minHeight != maxHeight) {
598 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
599 fbo_incomplete("width or height mismatch", -1);
600 return;
601 }
602 /* check that all color buffer have same format */
603 if (intFormat != GL_NONE && f != intFormat) {
604 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
605 fbo_incomplete("format mismatch", -1);
606 return;
607 }
Brian Paulf0bbbf62005-02-09 03:50:30 +0000608 }
Brian Paul722d9762009-01-20 16:58:49 -0700609 if (att->Renderbuffer &&
610 att->Renderbuffer->NumSamples != numSamples) {
Brian Paul72966362009-01-21 16:28:38 -0700611 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
Brian Paul722d9762009-01-20 16:58:49 -0700612 fbo_incomplete("inconsistant number of samples", i);
613 return;
614 }
615
Brian Paulf0bbbf62005-02-09 03:50:30 +0000616 }
617 }
618
Brian Paul868c09a2008-08-08 13:06:54 -0600619#ifndef FEATURE_OES_framebuffer_object
Brian Paulf0bbbf62005-02-09 03:50:30 +0000620 /* Check that all DrawBuffers are present */
Brian Paul28b014e2006-04-05 03:05:17 +0000621 for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) {
622 if (fb->ColorDrawBuffer[j] != GL_NONE) {
Brian Paule4b23562005-05-04 20:11:35 +0000623 const struct gl_renderbuffer_attachment *att
Brian Paul28b014e2006-04-05 03:05:17 +0000624 = _mesa_get_attachment(ctx, fb, fb->ColorDrawBuffer[j]);
Brian Paule4b23562005-05-04 20:11:35 +0000625 assert(att);
Brian Paulf0bbbf62005-02-09 03:50:30 +0000626 if (att->Type == GL_NONE) {
Brian Paule4b23562005-05-04 20:11:35 +0000627 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT;
Brian Paul28b014e2006-04-05 03:05:17 +0000628 fbo_incomplete("missing drawbuffer", j);
Brian Paulf0bbbf62005-02-09 03:50:30 +0000629 return;
630 }
631 }
632 }
633
634 /* Check that the ReadBuffer is present */
Brian Paule4b23562005-05-04 20:11:35 +0000635 if (fb->ColorReadBuffer != GL_NONE) {
636 const struct gl_renderbuffer_attachment *att
Brian Paul84716042005-11-16 04:05:54 +0000637 = _mesa_get_attachment(ctx, fb, fb->ColorReadBuffer);
Brian Paule4b23562005-05-04 20:11:35 +0000638 assert(att);
Brian Paulf0bbbf62005-02-09 03:50:30 +0000639 if (att->Type == GL_NONE) {
Brian Paule4b23562005-05-04 20:11:35 +0000640 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT;
Brian Paul49918882006-03-20 15:27:55 +0000641 fbo_incomplete("missing readbuffer", -1);
Brian Paulf0bbbf62005-02-09 03:50:30 +0000642 return;
643 }
644 }
Brian Paul868c09a2008-08-08 13:06:54 -0600645#endif
Brian Paulf0bbbf62005-02-09 03:50:30 +0000646
647 if (numImages == 0) {
Brian Paule4b23562005-05-04 20:11:35 +0000648 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT;
Brian Paul49918882006-03-20 15:27:55 +0000649 fbo_incomplete("no attachments", -1);
Brian Paulf0bbbf62005-02-09 03:50:30 +0000650 return;
651 }
Brian Paulf0bbbf62005-02-09 03:50:30 +0000652
Brian Paul3528f692009-01-22 15:13:18 -0700653 /* Provisionally set status = COMPLETE ... */
Brian Paule4b23562005-05-04 20:11:35 +0000654 fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
Brian Paul3528f692009-01-22 15:13:18 -0700655
Brian Paul777a2ef2009-01-22 15:17:42 -0700656 /* ... but the driver may say the FB is incomplete.
657 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
658 * if anything.
659 */
Brian Paul3528f692009-01-22 15:13:18 -0700660 if (ctx->Driver.ValidateFramebuffer) {
661 ctx->Driver.ValidateFramebuffer(ctx, fb);
Brian Paul1f32c412009-01-19 17:34:19 -0700662 if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
663 fbo_incomplete("driver marked FBO as incomplete", -1);
664 }
Brian Paul3528f692009-01-22 15:13:18 -0700665 }
666
667 if (fb->_Status == GL_FRAMEBUFFER_COMPLETE_EXT) {
668 /*
669 * Note that if ARB_framebuffer_object is supported and the attached
670 * renderbuffers/textures are different sizes, the framebuffer
671 * width/height will be set to the smallest width/height.
672 */
673 fb->Width = minWidth;
674 fb->Height = minHeight;
Brian Paul38768db2009-01-27 09:49:27 -0700675
676 /* finally, update the visual info for the framebuffer */
677 _mesa_update_framebuffer_visual(fb);
Brian Paul3528f692009-01-22 15:13:18 -0700678 }
Brian Paule4b23562005-05-04 20:11:35 +0000679}
Brian Paulf0bbbf62005-02-09 03:50:30 +0000680
681
Brian Paul1864c7d2005-02-08 03:46:37 +0000682GLboolean GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +0000683_mesa_IsRenderbufferEXT(GLuint renderbuffer)
684{
Brian Paulddc82ee2005-02-05 19:56:45 +0000685 GET_CURRENT_CONTEXT(ctx);
Brian Paulddc82ee2005-02-05 19:56:45 +0000686 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
Brian Paulbc6cced2005-10-04 15:01:27 +0000687 if (renderbuffer) {
Brian Paulea4fe662006-03-26 05:22:17 +0000688 struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
Brian Paulbc6cced2005-10-04 15:01:27 +0000689 if (rb != NULL && rb != &DummyRenderbuffer)
690 return GL_TRUE;
691 }
692 return GL_FALSE;
Brian Paulddc82ee2005-02-05 19:56:45 +0000693}
694
695
Brian Paul1864c7d2005-02-08 03:46:37 +0000696void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +0000697_mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
698{
Brian42aaa542007-03-25 10:39:36 -0600699 struct gl_renderbuffer *newRb;
Brian Paulddc82ee2005-02-05 19:56:45 +0000700 GET_CURRENT_CONTEXT(ctx);
701
702 ASSERT_OUTSIDE_BEGIN_END(ctx);
703
Brian Paul3deaa012005-02-07 05:08:24 +0000704 if (target != GL_RENDERBUFFER_EXT) {
705 _mesa_error(ctx, GL_INVALID_ENUM,
706 "glBindRenderbufferEXT(target)");
Brian Paulddc82ee2005-02-05 19:56:45 +0000707 return;
708 }
709
Keith Whitwell009749b2009-04-21 16:55:57 +0100710 FLUSH_CURRENT(ctx, _NEW_BUFFERS);
Keith Whitwelldf058292006-09-22 11:40:35 +0000711 /* The above doesn't fully flush the drivers in the way that a
712 * glFlush does, but that is required here:
713 */
714 if (ctx->Driver.Flush)
715 ctx->Driver.Flush(ctx);
716
Brian Paul474f28e2005-10-08 14:41:17 +0000717
Brian Paul3deaa012005-02-07 05:08:24 +0000718 if (renderbuffer) {
Brian Paulea4fe662006-03-26 05:22:17 +0000719 newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
Brian Paul1864c7d2005-02-08 03:46:37 +0000720 if (newRb == &DummyRenderbuffer) {
721 /* ID was reserved, but no real renderbuffer object made yet */
722 newRb = NULL;
723 }
Brian Paul1bc59bf2009-01-22 15:07:34 -0700724 else if (!newRb && ctx->Extensions.ARB_framebuffer_object) {
725 /* All RB IDs must be Gen'd */
726 _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)");
727 return;
728 }
729
Brian Paul3deaa012005-02-07 05:08:24 +0000730 if (!newRb) {
731 /* create new renderbuffer object */
Brian Paul2c6f9112005-02-24 05:47:06 +0000732 newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer);
Brian Paul3deaa012005-02-07 05:08:24 +0000733 if (!newRb) {
734 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT");
735 return;
736 }
Brian Paul2c6f9112005-02-24 05:47:06 +0000737 ASSERT(newRb->AllocStorage);
Brian Paul1864c7d2005-02-08 03:46:37 +0000738 _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb);
Brian42aaa542007-03-25 10:39:36 -0600739 newRb->RefCount = 1; /* referenced by hash table */
Brian Paul3deaa012005-02-07 05:08:24 +0000740 }
Brian Paulddc82ee2005-02-05 19:56:45 +0000741 }
Brian Paul463642c2005-02-08 02:06:00 +0000742 else {
743 newRb = NULL;
744 }
Brian Paulddc82ee2005-02-05 19:56:45 +0000745
Brian Paul1864c7d2005-02-08 03:46:37 +0000746 ASSERT(newRb != &DummyRenderbuffer);
747
Brian42aaa542007-03-25 10:39:36 -0600748 _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb);
Brian Paulddc82ee2005-02-05 19:56:45 +0000749}
750
751
Brian Pauld0f13fa2009-01-21 11:17:45 -0700752/**
753 * If the given renderbuffer is anywhere attached to the framebuffer, detach
754 * the renderbuffer.
755 * This is used when a renderbuffer object is deleted.
756 * The spec calls for unbinding.
757 */
758static void
759detach_renderbuffer(GLcontext *ctx,
760 struct gl_framebuffer *fb,
761 struct gl_renderbuffer *rb)
762{
763 GLuint i;
764 for (i = 0; i < BUFFER_COUNT; i++) {
765 if (fb->Attachment[i].Renderbuffer == rb) {
766 _mesa_remove_attachment(ctx, &fb->Attachment[i]);
767 }
768 }
Brian Paul72966362009-01-21 16:28:38 -0700769 invalidate_framebuffer(fb);
Brian Pauld0f13fa2009-01-21 11:17:45 -0700770}
771
772
Brian Paul1864c7d2005-02-08 03:46:37 +0000773void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +0000774_mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers)
775{
776 GLint i;
777 GET_CURRENT_CONTEXT(ctx);
778
779 ASSERT_OUTSIDE_BEGIN_END(ctx);
Brian Paul474f28e2005-10-08 14:41:17 +0000780 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
Brian Paulddc82ee2005-02-05 19:56:45 +0000781
782 for (i = 0; i < n; i++) {
Brian Paul2c6f9112005-02-24 05:47:06 +0000783 if (renderbuffers[i] > 0) {
784 struct gl_renderbuffer *rb;
Brian Paulea4fe662006-03-26 05:22:17 +0000785 rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]);
Brian Paul3deaa012005-02-07 05:08:24 +0000786 if (rb) {
Brian Paul91802fd2005-10-04 16:01:02 +0000787 /* check if deleting currently bound renderbuffer object */
788 if (rb == ctx->CurrentRenderbuffer) {
789 /* bind default */
790 ASSERT(rb->RefCount >= 2);
791 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
792 }
793
Brian Pauld0f13fa2009-01-21 11:17:45 -0700794 if (ctx->DrawBuffer->Name) {
795 detach_renderbuffer(ctx, ctx->DrawBuffer, rb);
796 }
797 if (ctx->ReadBuffer->Name && ctx->ReadBuffer != ctx->DrawBuffer) {
798 detach_renderbuffer(ctx, ctx->ReadBuffer, rb);
799 }
800
Brian42aaa542007-03-25 10:39:36 -0600801 /* Remove from hash table immediately, to free the ID.
802 * But the object will not be freed until it's no longer
803 * referenced anywhere else.
804 */
Brian Paul3deaa012005-02-07 05:08:24 +0000805 _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]);
Brian Paulddc82ee2005-02-05 19:56:45 +0000806
Brian Paul1864c7d2005-02-08 03:46:37 +0000807 if (rb != &DummyRenderbuffer) {
Brian42aaa542007-03-25 10:39:36 -0600808 /* no longer referenced by hash table */
809 _mesa_reference_renderbuffer(&rb, NULL);
Brian Paul3deaa012005-02-07 05:08:24 +0000810 }
811 }
Brian Paulddc82ee2005-02-05 19:56:45 +0000812 }
813 }
814}
815
816
Brian Paul1864c7d2005-02-08 03:46:37 +0000817void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +0000818_mesa_GenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers)
819{
820 GET_CURRENT_CONTEXT(ctx);
821 GLuint first;
822 GLint i;
823
824 ASSERT_OUTSIDE_BEGIN_END(ctx);
825
826 if (n < 0) {
827 _mesa_error(ctx, GL_INVALID_VALUE, "glGenRenderbuffersEXT(n)");
828 return;
829 }
830
831 if (!renderbuffers)
832 return;
833
834 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n);
835
836 for (i = 0; i < n; i++) {
Brian Paulddc82ee2005-02-05 19:56:45 +0000837 GLuint name = first + i;
Brian Paulf0bbbf62005-02-09 03:50:30 +0000838 renderbuffers[i] = name;
Brian Paul1864c7d2005-02-08 03:46:37 +0000839 /* insert dummy placeholder into hash table */
Brian Paulddc82ee2005-02-05 19:56:45 +0000840 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul1864c7d2005-02-08 03:46:37 +0000841 _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer);
Brian Paulddc82ee2005-02-05 19:56:45 +0000842 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
Brian Paulddc82ee2005-02-05 19:56:45 +0000843 }
844}
845
846
Brian Pauld9468c92005-02-10 16:08:07 +0000847/**
848 * Given an internal format token for a render buffer, return the
849 * corresponding base format.
Brian Paul59e0faa2006-03-15 17:48:00 +0000850 * This is very similar to _mesa_base_tex_format() but the set of valid
851 * internal formats is somewhat different.
852 *
Brian Pauld9468c92005-02-10 16:08:07 +0000853 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
Brian Paul1ad7b992005-09-28 02:29:50 +0000854 * GL_DEPTH_STENCIL_EXT or zero if error.
Brian Pauld9468c92005-02-10 16:08:07 +0000855 */
Brian Paul59e0faa2006-03-15 17:48:00 +0000856GLenum
857_mesa_base_fbo_format(GLcontext *ctx, GLenum internalFormat)
Brian Paul463642c2005-02-08 02:06:00 +0000858{
859 switch (internalFormat) {
Brian Paulf0bbbf62005-02-09 03:50:30 +0000860 case GL_RGB:
861 case GL_R3_G3_B2:
862 case GL_RGB4:
863 case GL_RGB5:
864 case GL_RGB8:
865 case GL_RGB10:
866 case GL_RGB12:
867 case GL_RGB16:
868 return GL_RGB;
869 case GL_RGBA:
870 case GL_RGBA2:
871 case GL_RGBA4:
872 case GL_RGB5_A1:
873 case GL_RGBA8:
874 case GL_RGB10_A2:
875 case GL_RGBA12:
876 case GL_RGBA16:
877 return GL_RGBA;
878 case GL_STENCIL_INDEX:
879 case GL_STENCIL_INDEX1_EXT:
880 case GL_STENCIL_INDEX4_EXT:
881 case GL_STENCIL_INDEX8_EXT:
882 case GL_STENCIL_INDEX16_EXT:
883 return GL_STENCIL_INDEX;
884 case GL_DEPTH_COMPONENT:
Brian Paul2c6f9112005-02-24 05:47:06 +0000885 case GL_DEPTH_COMPONENT16:
886 case GL_DEPTH_COMPONENT24:
887 case GL_DEPTH_COMPONENT32:
Brian Paulf0bbbf62005-02-09 03:50:30 +0000888 return GL_DEPTH_COMPONENT;
Brian Paul1ad7b992005-09-28 02:29:50 +0000889 case GL_DEPTH_STENCIL_EXT:
890 case GL_DEPTH24_STENCIL8_EXT:
891 if (ctx->Extensions.EXT_packed_depth_stencil)
892 return GL_DEPTH_STENCIL_EXT;
893 else
894 return 0;
Brian Pauld9468c92005-02-10 16:08:07 +0000895 /* XXX add floating point formats eventually */
Brian Paulf0bbbf62005-02-09 03:50:30 +0000896 default:
897 return 0;
Brian Paul463642c2005-02-08 02:06:00 +0000898 }
Brian Paul463642c2005-02-08 02:06:00 +0000899}
900
901
Brian Paul4f3514e2009-01-22 15:19:56 -0700902/** sentinal value, see below */
903#define NO_SAMPLES 1000
904
905
906/**
907 * Helper function used by _mesa_RenderbufferStorageEXT() and
908 * _mesa_RenderbufferStorageMultisample().
909 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
910 */
911static void
912renderbuffer_storage(GLenum target, GLenum internalFormat,
913 GLsizei width, GLsizei height, GLsizei samples)
Brian Paulddc82ee2005-02-05 19:56:45 +0000914{
Brian Paul4f3514e2009-01-22 15:19:56 -0700915 const char *func = samples == NO_SAMPLES ?
916 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
Brian Paul2c6f9112005-02-24 05:47:06 +0000917 struct gl_renderbuffer *rb;
Brian Paul463642c2005-02-08 02:06:00 +0000918 GLenum baseFormat;
Brian Paulddc82ee2005-02-05 19:56:45 +0000919 GET_CURRENT_CONTEXT(ctx);
920
921 ASSERT_OUTSIDE_BEGIN_END(ctx);
922
Brian Paul463642c2005-02-08 02:06:00 +0000923 if (target != GL_RENDERBUFFER_EXT) {
Brian Paul4f3514e2009-01-22 15:19:56 -0700924 _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
Brian Paulddc82ee2005-02-05 19:56:45 +0000925 return;
926 }
927
Brian Paul59e0faa2006-03-15 17:48:00 +0000928 baseFormat = _mesa_base_fbo_format(ctx, internalFormat);
Brian Paul463642c2005-02-08 02:06:00 +0000929 if (baseFormat == 0) {
Brian Paul4f3514e2009-01-22 15:19:56 -0700930 _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat)", func);
Brian Paulddc82ee2005-02-05 19:56:45 +0000931 return;
932 }
933
Brian Paul13abf912006-04-13 19:17:13 +0000934 if (width < 1 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) {
Brian Paul4f3514e2009-01-22 15:19:56 -0700935 _mesa_error(ctx, GL_INVALID_VALUE, "%s(width)", func);
Brian Paulddc82ee2005-02-05 19:56:45 +0000936 return;
937 }
938
Brian Paul13abf912006-04-13 19:17:13 +0000939 if (height < 1 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) {
Brian Paul4f3514e2009-01-22 15:19:56 -0700940 _mesa_error(ctx, GL_INVALID_VALUE, "%s(height)", func);
941 return;
942 }
943
944 if (samples == NO_SAMPLES) {
945 /* NumSamples == 0 indicates non-multisampling */
946 samples = 0;
947 }
948 else if (samples > ctx->Const.MaxSamples) {
Brian Paul722d9762009-01-20 16:58:49 -0700949 /* note: driver may choose to use more samples than what's requested */
Brian Paul4f3514e2009-01-22 15:19:56 -0700950 _mesa_error(ctx, GL_INVALID_VALUE, "%s(samples)", func);
Brian Paulddc82ee2005-02-05 19:56:45 +0000951 return;
952 }
953
Brian Paul2c6f9112005-02-24 05:47:06 +0000954 rb = ctx->CurrentRenderbuffer;
Brian Paul2c6f9112005-02-24 05:47:06 +0000955 if (!rb) {
Brian Paul4f3514e2009-01-22 15:19:56 -0700956 _mesa_error(ctx, GL_INVALID_OPERATION, func);
Brian Paul463642c2005-02-08 02:06:00 +0000957 return;
958 }
959
Brian Paul474f28e2005-10-08 14:41:17 +0000960 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
961
Brian Paul311bcf52005-11-18 02:24:14 +0000962 if (rb->InternalFormat == internalFormat &&
Brian Paul13abf912006-04-13 19:17:13 +0000963 rb->Width == (GLuint) width &&
964 rb->Height == (GLuint) height) {
Brian Paul311bcf52005-11-18 02:24:14 +0000965 /* no change in allocation needed */
966 return;
967 }
968
Brian Paulea4fe662006-03-26 05:22:17 +0000969 /* These MUST get set by the AllocStorage func */
970 rb->_ActualFormat = 0;
971 rb->RedBits =
972 rb->GreenBits =
973 rb->BlueBits =
974 rb->AlphaBits =
975 rb->IndexBits =
976 rb->DepthBits =
977 rb->StencilBits = 0;
Brian Paul4f3514e2009-01-22 15:19:56 -0700978 rb->NumSamples = samples;
Brian Paulea4fe662006-03-26 05:22:17 +0000979
Brian Paul2c6f9112005-02-24 05:47:06 +0000980 /* Now allocate the storage */
981 ASSERT(rb->AllocStorage);
982 if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) {
983 /* No error - check/set fields now */
Brian Paulea4fe662006-03-26 05:22:17 +0000984 assert(rb->_ActualFormat);
Brian Paul13abf912006-04-13 19:17:13 +0000985 assert(rb->Width == (GLuint) width);
986 assert(rb->Height == (GLuint) height);
Brian Paul0e31e022005-12-01 00:25:00 +0000987 assert(rb->RedBits || rb->GreenBits || rb->BlueBits || rb->AlphaBits ||
988 rb->DepthBits || rb->StencilBits || rb->IndexBits);
Brian Paulea4fe662006-03-26 05:22:17 +0000989 rb->InternalFormat = internalFormat;
Brian Paul2c6f9112005-02-24 05:47:06 +0000990 rb->_BaseFormat = baseFormat;
991 }
992 else {
993 /* Probably ran out of memory - clear the fields */
994 rb->Width = 0;
995 rb->Height = 0;
996 rb->InternalFormat = GL_NONE;
Brian Paulea4fe662006-03-26 05:22:17 +0000997 rb->_ActualFormat = GL_NONE;
Brian Paul2c6f9112005-02-24 05:47:06 +0000998 rb->_BaseFormat = GL_NONE;
Brian Paul0e31e022005-12-01 00:25:00 +0000999 rb->RedBits =
1000 rb->GreenBits =
1001 rb->BlueBits =
1002 rb->AlphaBits =
1003 rb->IndexBits =
1004 rb->DepthBits =
Brian Paul4f3514e2009-01-22 15:19:56 -07001005 rb->StencilBits =
1006 rb->NumSamples = 0;
Brian Paul463642c2005-02-08 02:06:00 +00001007 }
1008
Brian Paule4b23562005-05-04 20:11:35 +00001009 /*
1010 test_framebuffer_completeness(ctx, fb);
1011 */
Brian Paul2c6f9112005-02-24 05:47:06 +00001012 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
1013 * points???
1014 */
Brian Paulddc82ee2005-02-05 19:56:45 +00001015}
1016
1017
Brian Paul1864c7d2005-02-08 03:46:37 +00001018void GLAPIENTRY
Brian Paul4f3514e2009-01-22 15:19:56 -07001019_mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
1020 GLsizei width, GLsizei height)
1021{
Brian Paul722d9762009-01-20 16:58:49 -07001022 /* GL_ARB_fbo says calling this function is equivalent to calling
1023 * glRenderbufferStorageMultisample() with samples=0. We pass in
1024 * a token value here just for error reporting purposes.
1025 */
Brian Paul4f3514e2009-01-22 15:19:56 -07001026 renderbuffer_storage(target, internalFormat, width, height, NO_SAMPLES);
1027}
1028
1029
1030void GLAPIENTRY
Brian Paul777a2ef2009-01-22 15:17:42 -07001031_mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples,
Brian Paul4f3514e2009-01-22 15:19:56 -07001032 GLenum internalFormat,
Brian Paul777a2ef2009-01-22 15:17:42 -07001033 GLsizei width, GLsizei height)
1034{
Brian Paul4f3514e2009-01-22 15:19:56 -07001035 renderbuffer_storage(target, internalFormat, width, height, samples);
Brian Paul777a2ef2009-01-22 15:17:42 -07001036}
1037
1038
1039
1040void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001041_mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params)
1042{
Brian Paul722d9762009-01-20 16:58:49 -07001043 struct gl_renderbuffer *rb;
Brian Paulddc82ee2005-02-05 19:56:45 +00001044 GET_CURRENT_CONTEXT(ctx);
1045
1046 ASSERT_OUTSIDE_BEGIN_END(ctx);
1047
Brian Paul463642c2005-02-08 02:06:00 +00001048 if (target != GL_RENDERBUFFER_EXT) {
Brian Paulddc82ee2005-02-05 19:56:45 +00001049 _mesa_error(ctx, GL_INVALID_ENUM,
1050 "glGetRenderbufferParameterivEXT(target)");
1051 return;
1052 }
1053
Brian Paul722d9762009-01-20 16:58:49 -07001054 rb = ctx->CurrentRenderbuffer;
1055 if (!rb) {
Brian Paulddc82ee2005-02-05 19:56:45 +00001056 _mesa_error(ctx, GL_INVALID_OPERATION,
1057 "glGetRenderbufferParameterivEXT");
1058 return;
1059 }
1060
Brian Paul474f28e2005-10-08 14:41:17 +00001061 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1062
Brian Paul463642c2005-02-08 02:06:00 +00001063 switch (pname) {
1064 case GL_RENDERBUFFER_WIDTH_EXT:
Brian Paul722d9762009-01-20 16:58:49 -07001065 *params = rb->Width;
Brian Paul463642c2005-02-08 02:06:00 +00001066 return;
1067 case GL_RENDERBUFFER_HEIGHT_EXT:
Brian Paul722d9762009-01-20 16:58:49 -07001068 *params = rb->Height;
Brian Paul463642c2005-02-08 02:06:00 +00001069 return;
1070 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT:
Brian Paul722d9762009-01-20 16:58:49 -07001071 *params = rb->InternalFormat;
Brian Paul463642c2005-02-08 02:06:00 +00001072 return;
Brian Paul1b939532005-05-31 23:55:21 +00001073 case GL_RENDERBUFFER_RED_SIZE_EXT:
Brian Paul722d9762009-01-20 16:58:49 -07001074 *params = rb->RedBits;
Brian Paul1b939532005-05-31 23:55:21 +00001075 break;
1076 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
Brian Paul722d9762009-01-20 16:58:49 -07001077 *params = rb->GreenBits;
Brian Paul1b939532005-05-31 23:55:21 +00001078 break;
1079 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
Brian Paul722d9762009-01-20 16:58:49 -07001080 *params = rb->BlueBits;
Brian Paul1b939532005-05-31 23:55:21 +00001081 break;
1082 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
Brian Paul722d9762009-01-20 16:58:49 -07001083 *params = rb->AlphaBits;
Brian Paul1b939532005-05-31 23:55:21 +00001084 break;
1085 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
Brian Paul722d9762009-01-20 16:58:49 -07001086 *params = rb->DepthBits;
Brian Paul1b939532005-05-31 23:55:21 +00001087 break;
1088 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
Brian Paul722d9762009-01-20 16:58:49 -07001089 *params = rb->StencilBits;
Brian Paul1b939532005-05-31 23:55:21 +00001090 break;
Brian Paul722d9762009-01-20 16:58:49 -07001091 case GL_RENDERBUFFER_SAMPLES:
1092 if (ctx->Extensions.ARB_framebuffer_object) {
1093 *params = rb->NumSamples;
1094 break;
1095 }
1096 /* fallthrough */
Brian Paul463642c2005-02-08 02:06:00 +00001097 default:
1098 _mesa_error(ctx, GL_INVALID_ENUM,
1099 "glGetRenderbufferParameterivEXT(target)");
1100 return;
1101 }
Brian Paulddc82ee2005-02-05 19:56:45 +00001102}
1103
1104
Brian Paul1864c7d2005-02-08 03:46:37 +00001105GLboolean GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001106_mesa_IsFramebufferEXT(GLuint framebuffer)
1107{
Brian Paulddc82ee2005-02-05 19:56:45 +00001108 GET_CURRENT_CONTEXT(ctx);
Brian Paulddc82ee2005-02-05 19:56:45 +00001109 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
Brian Paulbc6cced2005-10-04 15:01:27 +00001110 if (framebuffer) {
Brian Paulea4fe662006-03-26 05:22:17 +00001111 struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer);
Brian Paulbc6cced2005-10-04 15:01:27 +00001112 if (rb != NULL && rb != &DummyFramebuffer)
1113 return GL_TRUE;
1114 }
1115 return GL_FALSE;
Brian Paulddc82ee2005-02-05 19:56:45 +00001116}
1117
1118
Brian Paulea4fe662006-03-26 05:22:17 +00001119static void
1120check_begin_texture_render(GLcontext *ctx, struct gl_framebuffer *fb)
1121{
1122 GLuint i;
1123 ASSERT(ctx->Driver.RenderTexture);
1124 for (i = 0; i < BUFFER_COUNT; i++) {
1125 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
1126 struct gl_texture_object *texObj = att->Texture;
Brian Paul9f6ff492006-03-28 15:24:50 +00001127 if (texObj
1128 && att->Texture->Image[att->CubeMapFace][att->TextureLevel]) {
Brian Paulea4fe662006-03-26 05:22:17 +00001129 ctx->Driver.RenderTexture(ctx, fb, att);
1130 }
1131 }
1132}
1133
1134
Brian Paul0e31e022005-12-01 00:25:00 +00001135/**
1136 * Examine all the framebuffer's attachments to see if any are textures.
1137 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1138 * notify the device driver that the texture image may have changed.
1139 */
1140static void
Brian Paulea4fe662006-03-26 05:22:17 +00001141check_end_texture_render(GLcontext *ctx, struct gl_framebuffer *fb)
Brian Paul0e31e022005-12-01 00:25:00 +00001142{
1143 if (ctx->Driver.FinishRenderTexture) {
1144 GLuint i;
1145 for (i = 0; i < BUFFER_COUNT; i++) {
1146 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
Brian8b361662007-11-09 08:55:49 -07001147 if (att->Texture && att->Renderbuffer) {
Brian Paul519b23b2006-03-20 18:51:57 +00001148 ctx->Driver.FinishRenderTexture(ctx, att);
Brian Paul0e31e022005-12-01 00:25:00 +00001149 }
1150 }
1151 }
1152}
1153
1154
Brian Paul1864c7d2005-02-08 03:46:37 +00001155void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001156_mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
1157{
Roland Scheideggerdbfb3752007-07-17 17:29:55 +02001158 struct gl_framebuffer *newFb, *newFbread;
Brian Paul0bffb112005-11-08 14:45:48 +00001159 GLboolean bindReadBuf, bindDrawBuf;
Brian Paulddc82ee2005-02-05 19:56:45 +00001160 GET_CURRENT_CONTEXT(ctx);
1161
Brian Paul1bc59bf2009-01-22 15:07:34 -07001162#ifdef DEBUG
1163 if (ctx->Extensions.ARB_framebuffer_object) {
1164 ASSERT(ctx->Extensions.EXT_framebuffer_object);
1165 ASSERT(ctx->Extensions.EXT_framebuffer_blit);
1166 }
1167#endif
1168
Brian Paulddc82ee2005-02-05 19:56:45 +00001169 ASSERT_OUTSIDE_BEGIN_END(ctx);
1170
Brian Paulea4fe662006-03-26 05:22:17 +00001171 if (!ctx->Extensions.EXT_framebuffer_object) {
1172 _mesa_error(ctx, GL_INVALID_OPERATION,
1173 "glBindFramebufferEXT(unsupported)");
1174 return;
1175 }
1176
Brian Paul0bffb112005-11-08 14:45:48 +00001177 switch (target) {
1178#if FEATURE_EXT_framebuffer_blit
1179 case GL_DRAW_FRAMEBUFFER_EXT:
1180 if (!ctx->Extensions.EXT_framebuffer_blit) {
1181 _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
1182 return;
1183 }
1184 bindDrawBuf = GL_TRUE;
1185 bindReadBuf = GL_FALSE;
1186 break;
1187 case GL_READ_FRAMEBUFFER_EXT:
1188 if (!ctx->Extensions.EXT_framebuffer_blit) {
1189 _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
1190 return;
1191 }
1192 bindDrawBuf = GL_FALSE;
1193 bindReadBuf = GL_TRUE;
1194 break;
1195#endif
1196 case GL_FRAMEBUFFER_EXT:
1197 bindDrawBuf = GL_TRUE;
1198 bindReadBuf = GL_TRUE;
1199 break;
1200 default:
Brian Pauleba4ff62005-09-06 21:22:16 +00001201 _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
Brian Paulddc82ee2005-02-05 19:56:45 +00001202 return;
1203 }
1204
Keith Whitwell009749b2009-04-21 16:55:57 +01001205 FLUSH_CURRENT(ctx, _NEW_BUFFERS);
Keith Whitwell5ac93f82006-11-01 14:21:57 +00001206 if (ctx->Driver.Flush) {
1207 ctx->Driver.Flush(ctx);
1208 }
Brian32d86eb2007-08-16 18:52:48 +01001209
Brian Paul3deaa012005-02-07 05:08:24 +00001210 if (framebuffer) {
Brian Paule4b23562005-05-04 20:11:35 +00001211 /* Binding a user-created framebuffer object */
Brian Paulea4fe662006-03-26 05:22:17 +00001212 newFb = _mesa_lookup_framebuffer(ctx, framebuffer);
Brian Paul1864c7d2005-02-08 03:46:37 +00001213 if (newFb == &DummyFramebuffer) {
Brian Paul923b6fc2005-02-08 04:08:56 +00001214 /* ID was reserved, but no real framebuffer object made yet */
Brian Paul1864c7d2005-02-08 03:46:37 +00001215 newFb = NULL;
1216 }
Brian Paul1bc59bf2009-01-22 15:07:34 -07001217 else if (!newFb && ctx->Extensions.ARB_framebuffer_object) {
1218 /* All FBO IDs must be Gen'd */
1219 _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)");
1220 return;
1221 }
1222
Brian Paul3deaa012005-02-07 05:08:24 +00001223 if (!newFb) {
1224 /* create new framebuffer object */
Brian Paul2c6f9112005-02-24 05:47:06 +00001225 newFb = ctx->Driver.NewFramebuffer(ctx, framebuffer);
Brian Paul3deaa012005-02-07 05:08:24 +00001226 if (!newFb) {
1227 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT");
1228 return;
1229 }
Brian Paul1864c7d2005-02-08 03:46:37 +00001230 _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newFb);
Brian Paul3deaa012005-02-07 05:08:24 +00001231 }
Roland Scheideggerdbfb3752007-07-17 17:29:55 +02001232 newFbread = newFb;
Brian Paul3deaa012005-02-07 05:08:24 +00001233 }
Brian Paul463642c2005-02-08 02:06:00 +00001234 else {
Brian Paule4b23562005-05-04 20:11:35 +00001235 /* Binding the window system framebuffer (which was originally set
1236 * with MakeCurrent).
1237 */
1238 newFb = ctx->WinSysDrawBuffer;
Roland Scheideggerdbfb3752007-07-17 17:29:55 +02001239 newFbread = ctx->WinSysReadBuffer;
Brian Paul3deaa012005-02-07 05:08:24 +00001240 }
1241
Brian Paulea4fe662006-03-26 05:22:17 +00001242 ASSERT(newFb);
Brian Paul1864c7d2005-02-08 03:46:37 +00001243 ASSERT(newFb != &DummyFramebuffer);
1244
Brian Paulea4fe662006-03-26 05:22:17 +00001245 /*
Brian Paul16144632009-02-26 14:49:24 -07001246 * OK, now bind the new Draw/Read framebuffers, if they're changing.
Brian Paulea4fe662006-03-26 05:22:17 +00001247 */
1248
Brian Paul0bffb112005-11-08 14:45:48 +00001249 if (bindReadBuf) {
Brian Paul16144632009-02-26 14:49:24 -07001250 if (ctx->ReadBuffer == newFbread)
1251 bindReadBuf = GL_FALSE; /* no change */
1252 else
1253 _mesa_reference_framebuffer(&ctx->ReadBuffer, newFbread);
Brian Paul0bffb112005-11-08 14:45:48 +00001254 }
1255
1256 if (bindDrawBuf) {
Briana510bc32007-03-06 10:07:59 -07001257 /* check if old FB had any texture attachments */
Brian Paul16144632009-02-26 14:49:24 -07001258 if (ctx->DrawBuffer->Name != 0) {
1259 check_end_texture_render(ctx, ctx->DrawBuffer);
1260 }
Brian32d86eb2007-08-16 18:52:48 +01001261
Brian Paul16144632009-02-26 14:49:24 -07001262 if (ctx->DrawBuffer == newFb)
1263 bindDrawBuf = GL_FALSE; /* no change */
1264 else
1265 _mesa_reference_framebuffer(&ctx->DrawBuffer, newFb);
Brian32d86eb2007-08-16 18:52:48 +01001266
1267 if (newFb->Name != 0) {
1268 /* check if newly bound framebuffer has any texture attachments */
1269 check_begin_texture_render(ctx, newFb);
1270 }
Brian Paul0bffb112005-11-08 14:45:48 +00001271 }
Brian Paul59e0faa2006-03-15 17:48:00 +00001272
Brian Paul16144632009-02-26 14:49:24 -07001273 if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) {
Roland Scheideggerdbfb3752007-07-17 17:29:55 +02001274 ctx->Driver.BindFramebuffer(ctx, target, newFb, newFbread);
Brian Paul59e0faa2006-03-15 17:48:00 +00001275 }
Brian Paulddc82ee2005-02-05 19:56:45 +00001276}
1277
1278
Brian Paul1864c7d2005-02-08 03:46:37 +00001279void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001280_mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers)
1281{
1282 GLint i;
1283 GET_CURRENT_CONTEXT(ctx);
1284
1285 ASSERT_OUTSIDE_BEGIN_END(ctx);
Keith Whitwell009749b2009-04-21 16:55:57 +01001286 FLUSH_CURRENT(ctx, _NEW_BUFFERS);
Keith Whitwelldf058292006-09-22 11:40:35 +00001287 /* The above doesn't fully flush the drivers in the way that a
1288 * glFlush does, but that is required here:
1289 */
1290 if (ctx->Driver.Flush)
1291 ctx->Driver.Flush(ctx);
Brian Paulddc82ee2005-02-05 19:56:45 +00001292
1293 for (i = 0; i < n; i++) {
Brian Paul2c6f9112005-02-24 05:47:06 +00001294 if (framebuffers[i] > 0) {
1295 struct gl_framebuffer *fb;
Brian Paulea4fe662006-03-26 05:22:17 +00001296 fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]);
Brian Paul3deaa012005-02-07 05:08:24 +00001297 if (fb) {
Brian Paule4b23562005-05-04 20:11:35 +00001298 ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]);
Brian Paul91802fd2005-10-04 16:01:02 +00001299
1300 /* check if deleting currently bound framebuffer object */
1301 if (fb == ctx->DrawBuffer) {
1302 /* bind default */
1303 ASSERT(fb->RefCount >= 2);
Brian Pauld0f13fa2009-01-21 11:17:45 -07001304 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
1305 }
1306 if (fb == ctx->ReadBuffer) {
1307 /* bind default */
1308 ASSERT(fb->RefCount >= 2);
1309 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
Brian Paul91802fd2005-10-04 16:01:02 +00001310 }
1311
Brian Paul3deaa012005-02-07 05:08:24 +00001312 /* remove from hash table immediately, to free the ID */
1313 _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]);
Brian Paulddc82ee2005-02-05 19:56:45 +00001314
Brian Paul1864c7d2005-02-08 03:46:37 +00001315 if (fb != &DummyFramebuffer) {
1316 /* But the object will not be freed until it's no longer
1317 * bound in any context.
1318 */
Brian Pauld5229442009-02-09 08:30:55 -07001319 _mesa_reference_framebuffer(&fb, NULL);
Brian Paul3deaa012005-02-07 05:08:24 +00001320 }
1321 }
Brian Paulddc82ee2005-02-05 19:56:45 +00001322 }
1323 }
1324}
1325
1326
Brian Paul1864c7d2005-02-08 03:46:37 +00001327void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001328_mesa_GenFramebuffersEXT(GLsizei n, GLuint *framebuffers)
1329{
1330 GET_CURRENT_CONTEXT(ctx);
1331 GLuint first;
1332 GLint i;
1333
1334 ASSERT_OUTSIDE_BEGIN_END(ctx);
1335
1336 if (n < 0) {
1337 _mesa_error(ctx, GL_INVALID_VALUE, "glGenFramebuffersEXT(n)");
1338 return;
1339 }
1340
1341 if (!framebuffers)
1342 return;
1343
1344 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n);
1345
1346 for (i = 0; i < n; i++) {
Brian Paulddc82ee2005-02-05 19:56:45 +00001347 GLuint name = first + i;
Brian Paulf0bbbf62005-02-09 03:50:30 +00001348 framebuffers[i] = name;
1349 /* insert dummy placeholder into hash table */
Brian Paulddc82ee2005-02-05 19:56:45 +00001350 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
Brian Paul1864c7d2005-02-08 03:46:37 +00001351 _mesa_HashInsert(ctx->Shared->FrameBuffers, name, &DummyFramebuffer);
Brian Paulddc82ee2005-02-05 19:56:45 +00001352 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
Brian Paulddc82ee2005-02-05 19:56:45 +00001353 }
1354}
1355
1356
1357
Brian Paul1864c7d2005-02-08 03:46:37 +00001358GLenum GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001359_mesa_CheckFramebufferStatusEXT(GLenum target)
1360{
Brian Paul0bffb112005-11-08 14:45:48 +00001361 struct gl_framebuffer *buffer;
Brian Paulddc82ee2005-02-05 19:56:45 +00001362 GET_CURRENT_CONTEXT(ctx);
1363
Brian Paule4b23562005-05-04 20:11:35 +00001364 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
Brian Paulddc82ee2005-02-05 19:56:45 +00001365
Brian Paul0bffb112005-11-08 14:45:48 +00001366 switch (target) {
1367#if FEATURE_EXT_framebuffer_blit
1368 case GL_DRAW_FRAMEBUFFER_EXT:
1369 if (!ctx->Extensions.EXT_framebuffer_blit) {
1370 _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
1371 return 0;
1372 }
1373 buffer = ctx->DrawBuffer;
1374 break;
1375 case GL_READ_FRAMEBUFFER_EXT:
1376 if (!ctx->Extensions.EXT_framebuffer_blit) {
1377 _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
1378 return 0;
1379 }
1380 buffer = ctx->ReadBuffer;
1381 break;
1382#endif
1383 case GL_FRAMEBUFFER_EXT:
1384 buffer = ctx->DrawBuffer;
1385 break;
1386 default:
Brian Paulf0bbbf62005-02-09 03:50:30 +00001387 _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
Brian Paule4b23562005-05-04 20:11:35 +00001388 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
Brian Paulddc82ee2005-02-05 19:56:45 +00001389 }
1390
Brian Paul0bffb112005-11-08 14:45:48 +00001391 if (buffer->Name == 0) {
Brian Paulf0bbbf62005-02-09 03:50:30 +00001392 /* The window system / default framebuffer is always complete */
1393 return GL_FRAMEBUFFER_COMPLETE_EXT;
1394 }
1395
Brian Paul474f28e2005-10-08 14:41:17 +00001396 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1397
Brian Paul72966362009-01-21 16:28:38 -07001398 if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
1399 _mesa_test_framebuffer_completeness(ctx, buffer);
1400 }
1401
Brian Paul0bffb112005-11-08 14:45:48 +00001402 return buffer->_Status;
Brian Paulddc82ee2005-02-05 19:56:45 +00001403}
1404
1405
1406
1407/**
Brian Paulea4fe662006-03-26 05:22:17 +00001408 * Common code called by glFramebufferTexture1D/2D/3DEXT().
Brian Paulddc82ee2005-02-05 19:56:45 +00001409 */
Brian Paulea4fe662006-03-26 05:22:17 +00001410static void
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001411framebuffer_texture(GLcontext *ctx, const char *caller, GLenum target,
1412 GLenum attachment, GLenum textarget, GLuint texture,
Brian Paulea4fe662006-03-26 05:22:17 +00001413 GLint level, GLint zoffset)
Brian Paulddc82ee2005-02-05 19:56:45 +00001414{
Brian Paul2c6f9112005-02-24 05:47:06 +00001415 struct gl_renderbuffer_attachment *att;
Brian Paulea4fe662006-03-26 05:22:17 +00001416 struct gl_texture_object *texObj = NULL;
1417 struct gl_framebuffer *fb;
Brian Paul5fec84a2009-01-29 15:01:09 -07001418 GLboolean error = GL_FALSE;
Brian Paulddc82ee2005-02-05 19:56:45 +00001419
1420 ASSERT_OUTSIDE_BEGIN_END(ctx);
1421
Brian Paul5fec84a2009-01-29 15:01:09 -07001422 switch (target) {
1423 case GL_READ_FRAMEBUFFER_EXT:
1424 error = !ctx->Extensions.EXT_framebuffer_blit;
1425 fb = ctx->ReadBuffer;
1426 break;
1427 case GL_DRAW_FRAMEBUFFER_EXT:
1428 error = !ctx->Extensions.EXT_framebuffer_blit;
1429 /* fall-through */
1430 case GL_FRAMEBUFFER_EXT:
1431 fb = ctx->DrawBuffer;
1432 break;
1433 default:
1434 error = GL_TRUE;
1435 }
1436
1437 if (error) {
Brian Paulea4fe662006-03-26 05:22:17 +00001438 _mesa_error(ctx, GL_INVALID_ENUM,
Brian Paul5fec84a2009-01-29 15:01:09 -07001439 "glFramebufferTexture%sEXT(target=0x%x)", caller, target);
Brian Paulddc82ee2005-02-05 19:56:45 +00001440 return;
Brian Paulea4fe662006-03-26 05:22:17 +00001441 }
Brian Paulddc82ee2005-02-05 19:56:45 +00001442
Brian Paulea4fe662006-03-26 05:22:17 +00001443 ASSERT(fb);
Brian Paul3deaa012005-02-07 05:08:24 +00001444
Brian Paulea4fe662006-03-26 05:22:17 +00001445 /* check framebuffer binding */
1446 if (fb->Name == 0) {
1447 _mesa_error(ctx, GL_INVALID_OPERATION,
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001448 "glFramebufferTexture%sEXT", caller);
Brian Paulea4fe662006-03-26 05:22:17 +00001449 return;
1450 }
1451
Brian Paulea4fe662006-03-26 05:22:17 +00001452
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001453 /* The textarget, level, and zoffset parameters are only validated if
1454 * texture is non-zero.
1455 */
1456 if (texture) {
1457 GLboolean err = GL_TRUE;
1458
1459 texObj = _mesa_lookup_texture(ctx, texture);
1460 if (texObj != NULL) {
Ian Romanickbb372f12007-05-16 15:34:22 -07001461 if (textarget == 0) {
1462 err = (texObj->Target != GL_TEXTURE_3D) &&
1463 (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT) &&
1464 (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT);
1465 }
1466 else {
1467 err = (texObj->Target == GL_TEXTURE_CUBE_MAP)
1468 ? !IS_CUBE_FACE(textarget)
1469 : (texObj->Target != textarget);
1470 }
Brian Paulea4fe662006-03-26 05:22:17 +00001471 }
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001472
1473 if (err) {
Brian Paulea4fe662006-03-26 05:22:17 +00001474 _mesa_error(ctx, GL_INVALID_OPERATION,
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001475 "glFramebufferTexture%sEXT(texture target mismatch)",
1476 caller);
Brian Paulea4fe662006-03-26 05:22:17 +00001477 return;
1478 }
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001479
1480 if (texObj->Target == GL_TEXTURE_3D) {
Brian Paulea4fe662006-03-26 05:22:17 +00001481 const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
1482 if (zoffset < 0 || zoffset >= maxSize) {
1483 _mesa_error(ctx, GL_INVALID_VALUE,
Ian Romanickbb372f12007-05-16 15:34:22 -07001484 "glFramebufferTexture%sEXT(zoffset)", caller);
Brian Paulea4fe662006-03-26 05:22:17 +00001485 return;
1486 }
1487 }
Ian Romanickbb372f12007-05-16 15:34:22 -07001488 else if ((texObj->Target == GL_TEXTURE_1D_ARRAY_EXT) ||
1489 (texObj->Target == GL_TEXTURE_2D_ARRAY_EXT)) {
1490 if (zoffset < 0 || zoffset >= ctx->Const.MaxArrayTextureLayers) {
1491 _mesa_error(ctx, GL_INVALID_VALUE,
1492 "glFramebufferTexture%sEXT(layer)", caller);
1493 return;
1494 }
1495 }
1496
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001497 if ((level < 0) ||
1498 (level >= _mesa_max_texture_levels(ctx, texObj->Target))) {
1499 _mesa_error(ctx, GL_INVALID_VALUE,
1500 "glFramebufferTexture%sEXT(level)", caller);
1501 return;
1502 }
Brian Paulea4fe662006-03-26 05:22:17 +00001503 }
1504
1505 att = _mesa_get_attachment(ctx, fb, attachment);
Brian Paul3deaa012005-02-07 05:08:24 +00001506 if (att == NULL) {
1507 _mesa_error(ctx, GL_INVALID_ENUM,
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001508 "glFramebufferTexture%sEXT(attachment)", caller);
Brian Paul3deaa012005-02-07 05:08:24 +00001509 return;
1510 }
1511
Brian Paul30590072009-01-21 11:06:11 -07001512 if (texObj && attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
1513 /* the texture format must be depth+stencil */
1514 const struct gl_texture_image *texImg;
1515 texImg = texObj->Image[0][texObj->BaseLevel];
1516 if (!texImg || texImg->_BaseFormat != GL_DEPTH_STENCIL) {
1517 _mesa_error(ctx, GL_INVALID_OPERATION,
1518 "glFramebufferTexture%sEXT(texture is not"
1519 " DEPTH_STENCIL format)", caller);
1520 return;
1521 }
1522 }
1523
Keith Whitwell009749b2009-04-21 16:55:57 +01001524 FLUSH_CURRENT(ctx, _NEW_BUFFERS);
Keith Whitwelldf058292006-09-22 11:40:35 +00001525 /* The above doesn't fully flush the drivers in the way that a
1526 * glFlush does, but that is required here:
1527 */
1528 if (ctx->Driver.Flush)
1529 ctx->Driver.Flush(ctx);
Brian Paul474f28e2005-10-08 14:41:17 +00001530
Brian Paulea4fe662006-03-26 05:22:17 +00001531 _glthread_LOCK_MUTEX(fb->Mutex);
1532 if (texObj) {
1533 _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget,
1534 level, zoffset);
Brian Paul2897cee2009-01-29 09:20:18 -07001535 /* Set the render-to-texture flag. We'll check this flag in
1536 * glTexImage() and friends to determine if we need to revalidate
1537 * any FBOs that might be rendering into this texture.
1538 * This flag never gets cleared since it's non-trivial to determine
1539 * when all FBOs might be done rendering to this texture. That's OK
1540 * though since it's uncommon to render to a texture then repeatedly
1541 * call glTexImage() to change images in the texture.
1542 */
1543 texObj->_RenderToTexture = GL_TRUE;
Brian Paul3deaa012005-02-07 05:08:24 +00001544 }
1545 else {
Brian Paul519b23b2006-03-20 18:51:57 +00001546 _mesa_remove_attachment(ctx, att);
Brian Paul3deaa012005-02-07 05:08:24 +00001547 }
Brian Paul72966362009-01-21 16:28:38 -07001548
1549 invalidate_framebuffer(fb);
1550
Brian Paulea4fe662006-03-26 05:22:17 +00001551 _glthread_UNLOCK_MUTEX(fb->Mutex);
1552}
1553
1554
1555
1556void GLAPIENTRY
1557_mesa_FramebufferTexture1DEXT(GLenum target, GLenum attachment,
1558 GLenum textarget, GLuint texture, GLint level)
1559{
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001560 GET_CURRENT_CONTEXT(ctx);
1561
1562 if ((texture != 0) && (textarget != GL_TEXTURE_1D)) {
1563 _mesa_error(ctx, GL_INVALID_ENUM,
1564 "glFramebufferTexture1DEXT(textarget)");
1565 return;
1566 }
1567
1568 framebuffer_texture(ctx, "1D", target, attachment, textarget, texture,
1569 level, 0);
Brian Paulddc82ee2005-02-05 19:56:45 +00001570}
1571
1572
Brian Paul1864c7d2005-02-08 03:46:37 +00001573void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001574_mesa_FramebufferTexture2DEXT(GLenum target, GLenum attachment,
1575 GLenum textarget, GLuint texture, GLint level)
1576{
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001577 GET_CURRENT_CONTEXT(ctx);
1578
1579 if ((texture != 0) &&
1580 (textarget != GL_TEXTURE_2D) &&
1581 (textarget != GL_TEXTURE_RECTANGLE_ARB) &&
1582 (!IS_CUBE_FACE(textarget))) {
1583 _mesa_error(ctx, GL_INVALID_OPERATION,
Brian Paul5fec84a2009-01-29 15:01:09 -07001584 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget);
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001585 return;
1586 }
1587
1588 framebuffer_texture(ctx, "2D", target, attachment, textarget, texture,
1589 level, 0);
Brian Paulddc82ee2005-02-05 19:56:45 +00001590}
1591
1592
Brian Paul1864c7d2005-02-08 03:46:37 +00001593void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001594_mesa_FramebufferTexture3DEXT(GLenum target, GLenum attachment,
1595 GLenum textarget, GLuint texture,
1596 GLint level, GLint zoffset)
1597{
Ian Romanickb0fe0d82007-05-15 13:42:25 -07001598 GET_CURRENT_CONTEXT(ctx);
1599
1600 if ((texture != 0) && (textarget != GL_TEXTURE_3D)) {
1601 _mesa_error(ctx, GL_INVALID_ENUM,
1602 "glFramebufferTexture3DEXT(textarget)");
1603 return;
1604 }
1605
1606 framebuffer_texture(ctx, "3D", target, attachment, textarget, texture,
Brian Paulea4fe662006-03-26 05:22:17 +00001607 level, zoffset);
Brian Paulddc82ee2005-02-05 19:56:45 +00001608}
1609
1610
Brian Paul1864c7d2005-02-08 03:46:37 +00001611void GLAPIENTRY
Ian Romanickbb372f12007-05-16 15:34:22 -07001612_mesa_FramebufferTextureLayerEXT(GLenum target, GLenum attachment,
1613 GLuint texture, GLint level, GLint layer)
1614{
1615 GET_CURRENT_CONTEXT(ctx);
1616
1617 framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
1618 level, layer);
1619}
1620
1621
1622void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001623_mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment,
1624 GLenum renderbufferTarget,
1625 GLuint renderbuffer)
1626{
Brian Paul2c6f9112005-02-24 05:47:06 +00001627 struct gl_renderbuffer_attachment *att;
Brian Paul0bffb112005-11-08 14:45:48 +00001628 struct gl_framebuffer *fb;
Brian Paule4b23562005-05-04 20:11:35 +00001629 struct gl_renderbuffer *rb;
Brian Paulddc82ee2005-02-05 19:56:45 +00001630 GET_CURRENT_CONTEXT(ctx);
1631
1632 ASSERT_OUTSIDE_BEGIN_END(ctx);
1633
Brian Paul0bffb112005-11-08 14:45:48 +00001634 switch (target) {
1635#if FEATURE_EXT_framebuffer_blit
1636 case GL_DRAW_FRAMEBUFFER_EXT:
1637 if (!ctx->Extensions.EXT_framebuffer_blit) {
1638 _mesa_error(ctx, GL_INVALID_ENUM,
1639 "glFramebufferRenderbufferEXT(target)");
1640 return;
1641 }
1642 fb = ctx->DrawBuffer;
1643 break;
1644 case GL_READ_FRAMEBUFFER_EXT:
1645 if (!ctx->Extensions.EXT_framebuffer_blit) {
1646 _mesa_error(ctx, GL_INVALID_ENUM,
1647 "glFramebufferRenderbufferEXT(target)");
1648 return;
1649 }
1650 fb = ctx->ReadBuffer;
1651 break;
1652#endif
1653 case GL_FRAMEBUFFER_EXT:
1654 fb = ctx->DrawBuffer;
1655 break;
1656 default:
Brian Paulddc82ee2005-02-05 19:56:45 +00001657 _mesa_error(ctx, GL_INVALID_ENUM,
1658 "glFramebufferRenderbufferEXT(target)");
1659 return;
1660 }
1661
Brian Paul3deaa012005-02-07 05:08:24 +00001662 if (renderbufferTarget != GL_RENDERBUFFER_EXT) {
Brian Paule4b23562005-05-04 20:11:35 +00001663 _mesa_error(ctx, GL_INVALID_ENUM,
1664 "glFramebufferRenderbufferEXT(renderbufferTarget)");
Brian Paul3deaa012005-02-07 05:08:24 +00001665 return;
1666 }
1667
Brian Paul0bffb112005-11-08 14:45:48 +00001668 if (fb->Name == 0) {
Brian Paulab8ef282005-09-07 23:21:59 +00001669 /* Can't attach new renderbuffers to a window system framebuffer */
Brian Paul3deaa012005-02-07 05:08:24 +00001670 _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT");
1671 return;
1672 }
1673
Brian Paul84716042005-11-16 04:05:54 +00001674 att = _mesa_get_attachment(ctx, fb, attachment);
Brian Paul3deaa012005-02-07 05:08:24 +00001675 if (att == NULL) {
Brian Paulddc82ee2005-02-05 19:56:45 +00001676 _mesa_error(ctx, GL_INVALID_ENUM,
1677 "glFramebufferRenderbufferEXT(attachment)");
1678 return;
1679 }
1680
Brian Paul1864c7d2005-02-08 03:46:37 +00001681 if (renderbuffer) {
Brian Paulea4fe662006-03-26 05:22:17 +00001682 rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
Brian Paul1864c7d2005-02-08 03:46:37 +00001683 if (!rb) {
Brian Paule4b23562005-05-04 20:11:35 +00001684 _mesa_error(ctx, GL_INVALID_OPERATION,
Brian Paul1864c7d2005-02-08 03:46:37 +00001685 "glFramebufferRenderbufferEXT(renderbuffer)");
1686 return;
1687 }
Brian Paul1864c7d2005-02-08 03:46:37 +00001688 }
1689 else {
Brian Paule4b23562005-05-04 20:11:35 +00001690 /* remove renderbuffer attachment */
1691 rb = NULL;
Brian Paul1864c7d2005-02-08 03:46:37 +00001692 }
Brian Paule4b23562005-05-04 20:11:35 +00001693
Brian Paul30590072009-01-21 11:06:11 -07001694 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
1695 /* make sure the renderbuffer is a depth/stencil format */
1696 if (rb->_BaseFormat != GL_DEPTH_STENCIL) {
1697 _mesa_error(ctx, GL_INVALID_OPERATION,
1698 "glFramebufferRenderbufferEXT(renderbuffer"
1699 " is not DEPTH_STENCIL format)");
1700 return;
1701 }
1702 }
1703
1704
Keith Whitwell009749b2009-04-21 16:55:57 +01001705 FLUSH_CURRENT(ctx, _NEW_BUFFERS);
Keith Whitwelldf058292006-09-22 11:40:35 +00001706 /* The above doesn't fully flush the drivers in the way that a
1707 * glFlush does, but that is required here:
1708 */
1709 if (ctx->Driver.Flush)
1710 ctx->Driver.Flush(ctx);
Brian Paul474f28e2005-10-08 14:41:17 +00001711
Brian Paule4b23562005-05-04 20:11:35 +00001712 assert(ctx->Driver.FramebufferRenderbuffer);
Brian Paul84716042005-11-16 04:05:54 +00001713 ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb);
Brian Paul2e019182006-03-07 01:43:52 +00001714
1715 /* Some subsequent GL commands may depend on the framebuffer's visual
1716 * after the binding is updated. Update visual info now.
1717 */
1718 _mesa_update_framebuffer_visual(fb);
Brian Paulddc82ee2005-02-05 19:56:45 +00001719}
1720
1721
Brian Paul1864c7d2005-02-08 03:46:37 +00001722void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001723_mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment,
1724 GLenum pname, GLint *params)
1725{
Brian Paul2c6f9112005-02-24 05:47:06 +00001726 const struct gl_renderbuffer_attachment *att;
Brian Paul0bffb112005-11-08 14:45:48 +00001727 struct gl_framebuffer *buffer;
Brian Paulddc82ee2005-02-05 19:56:45 +00001728 GET_CURRENT_CONTEXT(ctx);
1729
1730 ASSERT_OUTSIDE_BEGIN_END(ctx);
1731
Brian Paul0bffb112005-11-08 14:45:48 +00001732 switch (target) {
1733#if FEATURE_EXT_framebuffer_blit
1734 case GL_DRAW_FRAMEBUFFER_EXT:
1735 if (!ctx->Extensions.EXT_framebuffer_blit) {
1736 _mesa_error(ctx, GL_INVALID_ENUM,
1737 "glGetFramebufferAttachmentParameterivEXT(target)");
1738 return;
1739 }
1740 buffer = ctx->DrawBuffer;
1741 break;
1742 case GL_READ_FRAMEBUFFER_EXT:
1743 if (!ctx->Extensions.EXT_framebuffer_blit) {
1744 _mesa_error(ctx, GL_INVALID_ENUM,
1745 "glGetFramebufferAttachmentParameterivEXT(target)");
1746 return;
1747 }
1748 buffer = ctx->ReadBuffer;
1749 break;
1750#endif
1751 case GL_FRAMEBUFFER_EXT:
1752 buffer = ctx->DrawBuffer;
1753 break;
1754 default:
Brian Paulddc82ee2005-02-05 19:56:45 +00001755 _mesa_error(ctx, GL_INVALID_ENUM,
1756 "glGetFramebufferAttachmentParameterivEXT(target)");
1757 return;
1758 }
1759
Brian Paul0bffb112005-11-08 14:45:48 +00001760 if (buffer->Name == 0) {
Brian Paul3deaa012005-02-07 05:08:24 +00001761 _mesa_error(ctx, GL_INVALID_OPERATION,
1762 "glGetFramebufferAttachmentParameterivEXT");
1763 return;
1764 }
1765
Brian Paul84716042005-11-16 04:05:54 +00001766 att = _mesa_get_attachment(ctx, buffer, attachment);
Brian Paul3deaa012005-02-07 05:08:24 +00001767 if (att == NULL) {
Brian Paulddc82ee2005-02-05 19:56:45 +00001768 _mesa_error(ctx, GL_INVALID_ENUM,
1769 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1770 return;
1771 }
1772
Brian Paul30590072009-01-21 11:06:11 -07001773 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
1774 /* the depth and stencil attachments must point to the same buffer */
1775 const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt;
1776 depthAtt = _mesa_get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT);
1777 stencilAtt = _mesa_get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT);
1778 if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) {
1779 _mesa_error(ctx, GL_INVALID_OPERATION,
1780 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
1781 " attachments differ)");
1782 return;
1783 }
1784 }
1785
Keith Whitwell009749b2009-04-21 16:55:57 +01001786 FLUSH_CURRENT(ctx, _NEW_BUFFERS);
Keith Whitwelldf058292006-09-22 11:40:35 +00001787 /* The above doesn't fully flush the drivers in the way that a
1788 * glFlush does, but that is required here:
1789 */
1790 if (ctx->Driver.Flush)
1791 ctx->Driver.Flush(ctx);
Brian Paul474f28e2005-10-08 14:41:17 +00001792
Brian Paulddc82ee2005-02-05 19:56:45 +00001793 switch (pname) {
1794 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT:
Brian Paul3deaa012005-02-07 05:08:24 +00001795 *params = att->Type;
1796 return;
Brian Paulddc82ee2005-02-05 19:56:45 +00001797 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT:
Brian Paul3deaa012005-02-07 05:08:24 +00001798 if (att->Type == GL_RENDERBUFFER_EXT) {
1799 *params = att->Renderbuffer->Name;
1800 }
1801 else if (att->Type == GL_TEXTURE) {
1802 *params = att->Texture->Name;
1803 }
1804 else {
1805 _mesa_error(ctx, GL_INVALID_ENUM,
1806 "glGetFramebufferAttachmentParameterivEXT(pname)");
1807 }
1808 return;
Brian Paulddc82ee2005-02-05 19:56:45 +00001809 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT:
Brian Paul3deaa012005-02-07 05:08:24 +00001810 if (att->Type == GL_TEXTURE) {
1811 *params = att->TextureLevel;
1812 }
1813 else {
1814 _mesa_error(ctx, GL_INVALID_ENUM,
1815 "glGetFramebufferAttachmentParameterivEXT(pname)");
1816 }
1817 return;
Brian Paulddc82ee2005-02-05 19:56:45 +00001818 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT:
Brian Paul3deaa012005-02-07 05:08:24 +00001819 if (att->Type == GL_TEXTURE) {
Brian Paulf1e4ca72008-08-06 08:39:54 -06001820 if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) {
1821 *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace;
1822 }
1823 else {
1824 *params = 0;
1825 }
Brian Paul3deaa012005-02-07 05:08:24 +00001826 }
1827 else {
1828 _mesa_error(ctx, GL_INVALID_ENUM,
1829 "glGetFramebufferAttachmentParameterivEXT(pname)");
1830 }
1831 return;
Brian Paulddc82ee2005-02-05 19:56:45 +00001832 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT:
Brian Paul3deaa012005-02-07 05:08:24 +00001833 if (att->Type == GL_TEXTURE) {
Brian Paulf1e4ca72008-08-06 08:39:54 -06001834 if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) {
1835 *params = att->Zoffset;
1836 }
1837 else {
1838 *params = 0;
1839 }
Brian Paul3deaa012005-02-07 05:08:24 +00001840 }
1841 else {
1842 _mesa_error(ctx, GL_INVALID_ENUM,
1843 "glGetFramebufferAttachmentParameterivEXT(pname)");
1844 }
1845 return;
Brian Paul1bc59bf2009-01-22 15:07:34 -07001846 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
1847 if (!ctx->Extensions.ARB_framebuffer_object) {
1848 _mesa_error(ctx, GL_INVALID_ENUM,
1849 "glGetFramebufferAttachmentParameterivEXT(pname)");
1850 }
1851 else {
1852 *params = att->Renderbuffer->ColorEncoding;
1853 }
1854 return;
1855 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
1856 if (!ctx->Extensions.ARB_framebuffer_object) {
1857 _mesa_error(ctx, GL_INVALID_ENUM,
1858 "glGetFramebufferAttachmentParameterivEXT(pname)");
1859 return;
1860 }
1861 else {
1862 *params = att->Renderbuffer->ComponentType;
1863 }
1864 return;
1865 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
1866 if (!ctx->Extensions.ARB_framebuffer_object) {
1867 _mesa_error(ctx, GL_INVALID_ENUM,
1868 "glGetFramebufferAttachmentParameterivEXT(pname)");
1869 }
1870 else {
1871 *params = att->Renderbuffer->RedBits;
1872 }
1873 return;
1874 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
1875 if (!ctx->Extensions.ARB_framebuffer_object) {
1876 _mesa_error(ctx, GL_INVALID_ENUM,
1877 "glGetFramebufferAttachmentParameterivEXT(pname)");
1878 }
1879 else {
1880 *params = att->Renderbuffer->GreenBits;
1881 }
1882 return;
1883 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
1884 if (!ctx->Extensions.ARB_framebuffer_object) {
1885 _mesa_error(ctx, GL_INVALID_ENUM,
1886 "glGetFramebufferAttachmentParameterivEXT(pname)");
1887 }
1888 else {
1889 *params = att->Renderbuffer->BlueBits;
1890 }
1891 return;
1892 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
1893 if (!ctx->Extensions.ARB_framebuffer_object) {
1894 _mesa_error(ctx, GL_INVALID_ENUM,
1895 "glGetFramebufferAttachmentParameterivEXT(pname)");
1896 }
1897 else {
1898 *params = att->Renderbuffer->AlphaBits;
1899 }
1900 return;
1901 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
1902 if (!ctx->Extensions.ARB_framebuffer_object) {
1903 _mesa_error(ctx, GL_INVALID_ENUM,
1904 "glGetFramebufferAttachmentParameterivEXT(pname)");
1905 }
1906 else {
1907 *params = att->Renderbuffer->DepthBits;
1908 }
1909 return;
1910 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
1911 if (!ctx->Extensions.ARB_framebuffer_object) {
1912 _mesa_error(ctx, GL_INVALID_ENUM,
1913 "glGetFramebufferAttachmentParameterivEXT(pname)");
1914 }
1915 else {
1916 *params = att->Renderbuffer->StencilBits;
1917 }
1918 return;
Brian Paulddc82ee2005-02-05 19:56:45 +00001919 default:
1920 _mesa_error(ctx, GL_INVALID_ENUM,
1921 "glGetFramebufferAttachmentParameterivEXT(pname)");
1922 return;
1923 }
Brian Paulddc82ee2005-02-05 19:56:45 +00001924}
1925
1926
Brian Paul1864c7d2005-02-08 03:46:37 +00001927void GLAPIENTRY
Brian Paulddc82ee2005-02-05 19:56:45 +00001928_mesa_GenerateMipmapEXT(GLenum target)
1929{
Brian Paul463642c2005-02-08 02:06:00 +00001930 struct gl_texture_unit *texUnit;
1931 struct gl_texture_object *texObj;
Brian Paulddc82ee2005-02-05 19:56:45 +00001932 GET_CURRENT_CONTEXT(ctx);
1933
1934 ASSERT_OUTSIDE_BEGIN_END(ctx);
Brian Paul474f28e2005-10-08 14:41:17 +00001935 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
Brian Paulddc82ee2005-02-05 19:56:45 +00001936
1937 switch (target) {
1938 case GL_TEXTURE_1D:
1939 case GL_TEXTURE_2D:
Brian Paulddc82ee2005-02-05 19:56:45 +00001940 case GL_TEXTURE_3D:
Brian Paul463642c2005-02-08 02:06:00 +00001941 case GL_TEXTURE_CUBE_MAP:
Brian Paul1b939532005-05-31 23:55:21 +00001942 /* OK, legal value */
Brian Paulddc82ee2005-02-05 19:56:45 +00001943 break;
1944 default:
1945 _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target)");
1946 return;
1947 }
1948
Brian Paul463642c2005-02-08 02:06:00 +00001949 texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1950 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1951
Keith Whitwell5ac93f82006-11-01 14:21:57 +00001952 _mesa_lock_texture(ctx, texObj);
Eric Anholtf849d362008-12-06 21:14:56 -08001953 if (target == GL_TEXTURE_CUBE_MAP) {
1954 int face;
1955
1956 for (face = 0; face < 6; face++)
1957 ctx->Driver.GenerateMipmap(ctx,
1958 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face,
1959 texObj);
1960 } else {
1961 ctx->Driver.GenerateMipmap(ctx, target, texObj);
1962 }
Keith Whitwell5ac93f82006-11-01 14:21:57 +00001963 _mesa_unlock_texture(ctx, texObj);
Brian Paulddc82ee2005-02-05 19:56:45 +00001964}
Brian Paul0bffb112005-11-08 14:45:48 +00001965
1966
1967#if FEATURE_EXT_framebuffer_blit
Brian Paul722d9762009-01-20 16:58:49 -07001968/**
1969 * Blit rectangular region, optionally from one framebuffer to another.
1970 *
1971 * Note, if the src buffer is multisampled and the dest is not, this is
1972 * when the samples must be resolved to a single color.
1973 */
Brian Paul0bffb112005-11-08 14:45:48 +00001974void GLAPIENTRY
1975_mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1976 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
1977 GLbitfield mask, GLenum filter)
1978{
Brian Paul722d9762009-01-20 16:58:49 -07001979 const GLbitfield legalMaskBits = (GL_COLOR_BUFFER_BIT |
1980 GL_DEPTH_BUFFER_BIT |
1981 GL_STENCIL_BUFFER_BIT);
1982 const struct gl_framebuffer *readFb, *drawFb;
1983 const struct gl_renderbuffer *colorReadRb, *colorDrawRb;
Brian Paul0bffb112005-11-08 14:45:48 +00001984 GET_CURRENT_CONTEXT(ctx);
1985
1986 ASSERT_OUTSIDE_BEGIN_END(ctx);
1987 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1988
Brian Paul99745402006-03-01 02:02:43 +00001989 if (ctx->NewState) {
1990 _mesa_update_state(ctx);
1991 }
1992
Brian Paul722d9762009-01-20 16:58:49 -07001993 readFb = ctx->ReadBuffer;
1994 drawFb = ctx->DrawBuffer;
1995
1996 if (!readFb || !drawFb) {
1997 /* This will normally never happen but someday we may want to
1998 * support MakeCurrent() with no drawables.
1999 */
2000 return;
Brian Paul99745402006-03-01 02:02:43 +00002001 }
2002
Brian Paul0bffb112005-11-08 14:45:48 +00002003 /* check for complete framebuffers */
Brian Paul722d9762009-01-20 16:58:49 -07002004 if (drawFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
2005 readFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
Brian Paul0bffb112005-11-08 14:45:48 +00002006 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
2007 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2008 return;
2009 }
2010
Brian Paul99745402006-03-01 02:02:43 +00002011 if (filter != GL_NEAREST && filter != GL_LINEAR) {
2012 _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(filter)");
2013 return;
2014 }
2015
Brian Paul722d9762009-01-20 16:58:49 -07002016 if (mask & ~legalMaskBits) {
Brian Paul99745402006-03-01 02:02:43 +00002017 _mesa_error( ctx, GL_INVALID_VALUE, "glBlitFramebufferEXT(mask)");
2018 return;
2019 }
2020
Brian Paul0bffb112005-11-08 14:45:48 +00002021 /* depth/stencil must be blitted with nearest filtering */
2022 if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
2023 && filter != GL_NEAREST) {
2024 _mesa_error(ctx, GL_INVALID_OPERATION,
2025 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
2026 return;
2027 }
2028
Brian Paul722d9762009-01-20 16:58:49 -07002029 /* get color read/draw renderbuffers */
2030 if (mask & GL_COLOR_BUFFER_BIT) {
2031 colorReadRb = readFb->_ColorReadBuffer;
2032 colorDrawRb = drawFb->_ColorDrawBuffers[0];
2033 }
2034 else {
2035 colorReadRb = colorDrawRb = NULL;
2036 }
2037
Brian Paul99745402006-03-01 02:02:43 +00002038 if (mask & GL_STENCIL_BUFFER_BIT) {
Brian Paul722d9762009-01-20 16:58:49 -07002039 struct gl_renderbuffer *readRb = readFb->_StencilBuffer;
2040 struct gl_renderbuffer *drawRb = drawFb->_StencilBuffer;
Brian Pauldcebe222009-08-05 13:44:59 -06002041 if (!readRb ||
2042 !drawRb ||
2043 readRb->StencilBits != drawRb->StencilBits) {
Brian Paul99745402006-03-01 02:02:43 +00002044 _mesa_error(ctx, GL_INVALID_OPERATION,
2045 "glBlitFramebufferEXT(stencil buffer size mismatch");
2046 return;
2047 }
2048 }
2049
2050 if (mask & GL_DEPTH_BUFFER_BIT) {
Brian Paul722d9762009-01-20 16:58:49 -07002051 struct gl_renderbuffer *readRb = readFb->_DepthBuffer;
2052 struct gl_renderbuffer *drawRb = drawFb->_DepthBuffer;
Brian Pauldcebe222009-08-05 13:44:59 -06002053 if (!readRb ||
2054 !drawRb ||
2055 readRb->DepthBits != drawRb->DepthBits) {
Brian Paul99745402006-03-01 02:02:43 +00002056 _mesa_error(ctx, GL_INVALID_OPERATION,
2057 "glBlitFramebufferEXT(depth buffer size mismatch");
2058 return;
2059 }
Brian Paul0bffb112005-11-08 14:45:48 +00002060 }
2061
Brian Paul722d9762009-01-20 16:58:49 -07002062 if (readFb->Visual.samples > 0 &&
2063 drawFb->Visual.samples > 0 &&
2064 readFb->Visual.samples != drawFb->Visual.samples) {
2065 _mesa_error(ctx, GL_INVALID_OPERATION,
2066 "glBlitFramebufferEXT(mismatched samples");
2067 return;
2068 }
2069
2070 /* extra checks for multisample copies... */
2071 if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) {
2072 /* src and dest region sizes must be the same */
2073 if (srcX1 - srcX0 != dstX1 - dstX0 ||
2074 srcY1 - srcY0 != dstY1 - dstY0) {
2075 _mesa_error(ctx, GL_INVALID_OPERATION,
2076 "glBlitFramebufferEXT(bad src/dst multisample region sizes");
2077 return;
2078 }
2079
2080 /* color formats must match */
2081 if (colorReadRb &&
2082 colorDrawRb &&
2083 colorReadRb->_ActualFormat != colorDrawRb->_ActualFormat) {
2084 _mesa_error(ctx, GL_INVALID_OPERATION,
2085 "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
2086 return;
2087 }
2088 }
2089
Brian Paul0bffb112005-11-08 14:45:48 +00002090 if (!ctx->Extensions.EXT_framebuffer_blit) {
2091 _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT");
2092 return;
2093 }
2094
2095 ASSERT(ctx->Driver.BlitFramebuffer);
2096 ctx->Driver.BlitFramebuffer(ctx,
2097 srcX0, srcY0, srcX1, srcY1,
2098 dstX0, dstY0, dstX1, dstY1,
2099 mask, filter);
2100}
2101#endif /* FEATURE_EXT_framebuffer_blit */