06cc586c431451391b7b3af67f787e5d813e80b0
[mesa.git] / src / mesa / main / fbobject.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /*
28 * GL_EXT/ARB_framebuffer_object extensions
29 *
30 * Authors:
31 * Brian Paul
32 */
33
34 #include <stdbool.h>
35
36 #include "buffers.h"
37 #include "context.h"
38 #include "enums.h"
39 #include "fbobject.h"
40 #include "formats.h"
41 #include "framebuffer.h"
42 #include "glformats.h"
43 #include "hash.h"
44 #include "macros.h"
45 #include "multisample.h"
46 #include "mtypes.h"
47 #include "renderbuffer.h"
48 #include "state.h"
49 #include "teximage.h"
50 #include "texobj.h"
51
52
53 /** Set this to 1 to debug/log glBlitFramebuffer() calls */
54 #define DEBUG_BLIT 0
55
56
57 /**
58 * Notes:
59 *
60 * None of the GL_EXT_framebuffer_object functions are compiled into
61 * display lists.
62 */
63
64
65
66 /*
67 * When glGenRender/FramebuffersEXT() is called we insert pointers to
68 * these placeholder objects into the hash table.
69 * Later, when the object ID is first bound, we replace the placeholder
70 * with the real frame/renderbuffer.
71 */
72 static struct gl_framebuffer DummyFramebuffer;
73 static struct gl_renderbuffer DummyRenderbuffer;
74
75 /* We bind this framebuffer when applications pass a NULL
76 * drawable/surface in make current. */
77 static struct gl_framebuffer IncompleteFramebuffer;
78
79
80 static void
81 delete_dummy_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
82 {
83 /* no op */
84 }
85
86 static void
87 delete_dummy_framebuffer(struct gl_framebuffer *fb)
88 {
89 /* no op */
90 }
91
92
93 void
94 _mesa_init_fbobjects(struct gl_context *ctx)
95 {
96 _glthread_INIT_MUTEX(DummyFramebuffer.Mutex);
97 _glthread_INIT_MUTEX(DummyRenderbuffer.Mutex);
98 _glthread_INIT_MUTEX(IncompleteFramebuffer.Mutex);
99 DummyFramebuffer.Delete = delete_dummy_framebuffer;
100 DummyRenderbuffer.Delete = delete_dummy_renderbuffer;
101 IncompleteFramebuffer.Delete = delete_dummy_framebuffer;
102 }
103
104 struct gl_framebuffer *
105 _mesa_get_incomplete_framebuffer(void)
106 {
107 return &IncompleteFramebuffer;
108 }
109
110 /**
111 * Helper routine for getting a gl_renderbuffer.
112 */
113 struct gl_renderbuffer *
114 _mesa_lookup_renderbuffer(struct gl_context *ctx, GLuint id)
115 {
116 struct gl_renderbuffer *rb;
117
118 if (id == 0)
119 return NULL;
120
121 rb = (struct gl_renderbuffer *)
122 _mesa_HashLookup(ctx->Shared->RenderBuffers, id);
123 return rb;
124 }
125
126
127 /**
128 * Helper routine for getting a gl_framebuffer.
129 */
130 struct gl_framebuffer *
131 _mesa_lookup_framebuffer(struct gl_context *ctx, GLuint id)
132 {
133 struct gl_framebuffer *fb;
134
135 if (id == 0)
136 return NULL;
137
138 fb = (struct gl_framebuffer *)
139 _mesa_HashLookup(ctx->Shared->FrameBuffers, id);
140 return fb;
141 }
142
143
144 /**
145 * Mark the given framebuffer as invalid. This will force the
146 * test for framebuffer completeness to be done before the framebuffer
147 * is used.
148 */
149 static void
150 invalidate_framebuffer(struct gl_framebuffer *fb)
151 {
152 fb->_Status = 0; /* "indeterminate" */
153 }
154
155
156 /**
157 * Return the gl_framebuffer object which corresponds to the given
158 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
159 * Check support for GL_EXT_framebuffer_blit to determine if certain
160 * targets are legal.
161 * \return gl_framebuffer pointer or NULL if target is illegal
162 */
163 static struct gl_framebuffer *
164 get_framebuffer_target(struct gl_context *ctx, GLenum target)
165 {
166 bool have_fb_blit = _mesa_is_gles3(ctx) ||
167 (ctx->Extensions.EXT_framebuffer_blit && _mesa_is_desktop_gl(ctx));
168 switch (target) {
169 case GL_DRAW_FRAMEBUFFER:
170 return have_fb_blit ? ctx->DrawBuffer : NULL;
171 case GL_READ_FRAMEBUFFER:
172 return have_fb_blit ? ctx->ReadBuffer : NULL;
173 case GL_FRAMEBUFFER_EXT:
174 return ctx->DrawBuffer;
175 default:
176 return NULL;
177 }
178 }
179
180
181 /**
182 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
183 * gl_renderbuffer_attachment object.
184 * This function is only used for user-created FB objects, not the
185 * default / window-system FB object.
186 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
187 * the depth buffer attachment point.
188 */
189 struct gl_renderbuffer_attachment *
190 _mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
191 GLenum attachment)
192 {
193 GLuint i;
194
195 assert(_mesa_is_user_fbo(fb));
196
197 switch (attachment) {
198 case GL_COLOR_ATTACHMENT0_EXT:
199 case GL_COLOR_ATTACHMENT1_EXT:
200 case GL_COLOR_ATTACHMENT2_EXT:
201 case GL_COLOR_ATTACHMENT3_EXT:
202 case GL_COLOR_ATTACHMENT4_EXT:
203 case GL_COLOR_ATTACHMENT5_EXT:
204 case GL_COLOR_ATTACHMENT6_EXT:
205 case GL_COLOR_ATTACHMENT7_EXT:
206 case GL_COLOR_ATTACHMENT8_EXT:
207 case GL_COLOR_ATTACHMENT9_EXT:
208 case GL_COLOR_ATTACHMENT10_EXT:
209 case GL_COLOR_ATTACHMENT11_EXT:
210 case GL_COLOR_ATTACHMENT12_EXT:
211 case GL_COLOR_ATTACHMENT13_EXT:
212 case GL_COLOR_ATTACHMENT14_EXT:
213 case GL_COLOR_ATTACHMENT15_EXT:
214 /* Only OpenGL ES 1.x forbids color attachments other than
215 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
216 * hardware is used.
217 */
218 i = attachment - GL_COLOR_ATTACHMENT0_EXT;
219 if (i >= ctx->Const.MaxColorAttachments
220 || (i > 0 && ctx->API == API_OPENGLES)) {
221 return NULL;
222 }
223 return &fb->Attachment[BUFFER_COLOR0 + i];
224 case GL_DEPTH_STENCIL_ATTACHMENT:
225 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
226 return NULL;
227 /* fall-through */
228 case GL_DEPTH_ATTACHMENT_EXT:
229 return &fb->Attachment[BUFFER_DEPTH];
230 case GL_STENCIL_ATTACHMENT_EXT:
231 return &fb->Attachment[BUFFER_STENCIL];
232 default:
233 return NULL;
234 }
235 }
236
237
238 /**
239 * As above, but only used for getting attachments of the default /
240 * window-system framebuffer (not user-created framebuffer objects).
241 */
242 static struct gl_renderbuffer_attachment *
243 _mesa_get_fb0_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
244 GLenum attachment)
245 {
246 assert(_mesa_is_winsys_fbo(fb));
247
248 if (_mesa_is_gles3(ctx)) {
249 assert(attachment == GL_BACK ||
250 attachment == GL_DEPTH ||
251 attachment == GL_STENCIL);
252 switch (attachment) {
253 case GL_BACK:
254 /* Since there is no stereo rendering in ES 3.0, only return the
255 * LEFT bits.
256 */
257 if (ctx->DrawBuffer->Visual.doubleBufferMode)
258 return &fb->Attachment[BUFFER_BACK_LEFT];
259 return &fb->Attachment[BUFFER_FRONT_LEFT];
260 case GL_DEPTH:
261 return &fb->Attachment[BUFFER_DEPTH];
262 case GL_STENCIL:
263 return &fb->Attachment[BUFFER_STENCIL];
264 }
265 }
266
267 switch (attachment) {
268 case GL_FRONT_LEFT:
269 return &fb->Attachment[BUFFER_FRONT_LEFT];
270 case GL_FRONT_RIGHT:
271 return &fb->Attachment[BUFFER_FRONT_RIGHT];
272 case GL_BACK_LEFT:
273 return &fb->Attachment[BUFFER_BACK_LEFT];
274 case GL_BACK_RIGHT:
275 return &fb->Attachment[BUFFER_BACK_RIGHT];
276 case GL_AUX0:
277 if (fb->Visual.numAuxBuffers == 1) {
278 return &fb->Attachment[BUFFER_AUX0];
279 }
280 return NULL;
281
282 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
283 *
284 * "If the default framebuffer is bound to target, then attachment must
285 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
286 * identifying a color buffer; DEPTH, identifying the depth buffer; or
287 * STENCIL, identifying the stencil buffer."
288 *
289 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
290 * language. However, revision #33 of the ARB_framebuffer_object spec
291 * says:
292 *
293 * "If the default framebuffer is bound to <target>, then <attachment>
294 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
295 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
296 * depth buffer, or the stencil buffer, and <pname> may be
297 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
298 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
299 *
300 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
301 * from glext.h, so shipping apps should not use those values.
302 *
303 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
304 * support queries of the window system FBO.
305 */
306 case GL_DEPTH:
307 return &fb->Attachment[BUFFER_DEPTH];
308 case GL_STENCIL:
309 return &fb->Attachment[BUFFER_STENCIL];
310 default:
311 return NULL;
312 }
313 }
314
315
316
317 /**
318 * Remove any texture or renderbuffer attached to the given attachment
319 * point. Update reference counts, etc.
320 */
321 void
322 _mesa_remove_attachment(struct gl_context *ctx,
323 struct gl_renderbuffer_attachment *att)
324 {
325 struct gl_renderbuffer *rb = att->Renderbuffer;
326
327 /* tell driver that we're done rendering to this texture. */
328 if (rb && rb->NeedsFinishRenderTexture)
329 ctx->Driver.FinishRenderTexture(ctx, rb);
330
331 if (att->Type == GL_TEXTURE) {
332 ASSERT(att->Texture);
333 _mesa_reference_texobj(&att->Texture, NULL); /* unbind */
334 ASSERT(!att->Texture);
335 }
336 if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) {
337 ASSERT(!att->Texture);
338 _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */
339 ASSERT(!att->Renderbuffer);
340 }
341 att->Type = GL_NONE;
342 att->Complete = GL_TRUE;
343 }
344
345 /**
346 * Verify a couple error conditions that will lead to an incomplete FBO and
347 * may cause problems for the driver's RenderTexture path.
348 */
349 static bool
350 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment *att)
351 {
352 const struct gl_texture_image *const texImage =
353 att->Texture->Image[att->CubeMapFace][att->TextureLevel];
354
355 if (texImage->Width == 0 || texImage->Height == 0 || texImage->Depth == 0)
356 return false;
357
358 if ((texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY
359 && att->Zoffset >= texImage->Height)
360 || (texImage->TexObject->Target != GL_TEXTURE_1D_ARRAY
361 && att->Zoffset >= texImage->Depth))
362 return false;
363
364 return true;
365 }
366
367 /**
368 * Create a renderbuffer which will be set up by the driver to wrap the
369 * texture image slice.
370 *
371 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
372 * to share most of their framebuffer rendering code between winsys,
373 * renderbuffer, and texture attachments.
374 *
375 * The allocated renderbuffer uses a non-zero Name so that drivers can check
376 * it for determining vertical orientation, but we use ~0 to make it fairly
377 * unambiguous with actual user (non-texture) renderbuffers.
378 */
379 void
380 _mesa_update_texture_renderbuffer(struct gl_context *ctx,
381 struct gl_framebuffer *fb,
382 struct gl_renderbuffer_attachment *att)
383 {
384 struct gl_texture_image *texImage;
385 struct gl_renderbuffer *rb;
386
387 texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
388 if (!texImage)
389 return;
390
391 rb = att->Renderbuffer;
392 if (!rb) {
393 rb = ctx->Driver.NewRenderbuffer(ctx, ~0);
394 if (!rb) {
395 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()");
396 return;
397 }
398 _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
399
400 /* This can't get called on a texture renderbuffer, so set it to NULL
401 * for clarity compared to user renderbuffers.
402 */
403 rb->AllocStorage = NULL;
404
405 rb->NeedsFinishRenderTexture = ctx->Driver.FinishRenderTexture != NULL;
406 }
407
408 rb->_BaseFormat = texImage->_BaseFormat;
409 rb->Format = texImage->TexFormat;
410 rb->InternalFormat = texImage->InternalFormat;
411 rb->Width = texImage->Width2;
412 rb->Height = texImage->Height2;
413 rb->NumSamples = texImage->NumSamples;
414 rb->TexImage = texImage;
415
416 if (driver_RenderTexture_is_safe(att))
417 ctx->Driver.RenderTexture(ctx, fb, att);
418 }
419
420 /**
421 * Bind a texture object to an attachment point.
422 * The previous binding, if any, will be removed first.
423 */
424 void
425 _mesa_set_texture_attachment(struct gl_context *ctx,
426 struct gl_framebuffer *fb,
427 struct gl_renderbuffer_attachment *att,
428 struct gl_texture_object *texObj,
429 GLenum texTarget, GLuint level, GLuint zoffset,
430 GLboolean layered)
431 {
432 struct gl_renderbuffer *rb = att->Renderbuffer;
433
434 if (rb && rb->NeedsFinishRenderTexture)
435 ctx->Driver.FinishRenderTexture(ctx, rb);
436
437 if (att->Texture == texObj) {
438 /* re-attaching same texture */
439 ASSERT(att->Type == GL_TEXTURE);
440 }
441 else {
442 /* new attachment */
443 _mesa_remove_attachment(ctx, att);
444 att->Type = GL_TEXTURE;
445 assert(!att->Texture);
446 _mesa_reference_texobj(&att->Texture, texObj);
447 }
448 invalidate_framebuffer(fb);
449
450 /* always update these fields */
451 att->TextureLevel = level;
452 att->CubeMapFace = _mesa_tex_target_to_face(texTarget);
453 att->Zoffset = zoffset;
454 att->Layered = layered;
455 att->Complete = GL_FALSE;
456
457 _mesa_update_texture_renderbuffer(ctx, fb, att);
458 }
459
460
461 /**
462 * Bind a renderbuffer to an attachment point.
463 * The previous binding, if any, will be removed first.
464 */
465 void
466 _mesa_set_renderbuffer_attachment(struct gl_context *ctx,
467 struct gl_renderbuffer_attachment *att,
468 struct gl_renderbuffer *rb)
469 {
470 /* XXX check if re-doing same attachment, exit early */
471 _mesa_remove_attachment(ctx, att);
472 att->Type = GL_RENDERBUFFER_EXT;
473 att->Texture = NULL; /* just to be safe */
474 att->Complete = GL_FALSE;
475 _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
476 }
477
478
479 /**
480 * Fallback for ctx->Driver.FramebufferRenderbuffer()
481 * Attach a renderbuffer object to a framebuffer object.
482 */
483 void
484 _mesa_framebuffer_renderbuffer(struct gl_context *ctx,
485 struct gl_framebuffer *fb,
486 GLenum attachment, struct gl_renderbuffer *rb)
487 {
488 struct gl_renderbuffer_attachment *att;
489
490 _glthread_LOCK_MUTEX(fb->Mutex);
491
492 att = _mesa_get_attachment(ctx, fb, attachment);
493 ASSERT(att);
494 if (rb) {
495 _mesa_set_renderbuffer_attachment(ctx, att, rb);
496 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
497 /* do stencil attachment here (depth already done above) */
498 att = _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
499 assert(att);
500 _mesa_set_renderbuffer_attachment(ctx, att, rb);
501 }
502 rb->AttachedAnytime = GL_TRUE;
503 }
504 else {
505 _mesa_remove_attachment(ctx, att);
506 }
507
508 invalidate_framebuffer(fb);
509
510 _glthread_UNLOCK_MUTEX(fb->Mutex);
511 }
512
513
514 /**
515 * Fallback for ctx->Driver.ValidateFramebuffer()
516 * Check if the renderbuffer's formats are supported by the software
517 * renderer.
518 * Drivers should probably override this.
519 */
520 void
521 _mesa_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
522 {
523 gl_buffer_index buf;
524 for (buf = 0; buf < BUFFER_COUNT; buf++) {
525 const struct gl_renderbuffer *rb = fb->Attachment[buf].Renderbuffer;
526 if (rb) {
527 switch (rb->_BaseFormat) {
528 case GL_ALPHA:
529 case GL_LUMINANCE_ALPHA:
530 case GL_LUMINANCE:
531 case GL_INTENSITY:
532 case GL_RED:
533 case GL_RG:
534 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
535 return;
536
537 default:
538 switch (rb->Format) {
539 /* XXX This list is likely incomplete. */
540 case MESA_FORMAT_RGB9_E5_FLOAT:
541 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
542 return;
543 default:;
544 /* render buffer format is supported by software rendering */
545 }
546 }
547 }
548 }
549 }
550
551
552 /**
553 * Return true if the framebuffer has a combined depth/stencil
554 * renderbuffer attached.
555 */
556 GLboolean
557 _mesa_has_depthstencil_combined(const struct gl_framebuffer *fb)
558 {
559 const struct gl_renderbuffer_attachment *depth =
560 &fb->Attachment[BUFFER_DEPTH];
561 const struct gl_renderbuffer_attachment *stencil =
562 &fb->Attachment[BUFFER_STENCIL];
563
564 if (depth->Type == stencil->Type) {
565 if (depth->Type == GL_RENDERBUFFER_EXT &&
566 depth->Renderbuffer == stencil->Renderbuffer)
567 return GL_TRUE;
568
569 if (depth->Type == GL_TEXTURE &&
570 depth->Texture == stencil->Texture)
571 return GL_TRUE;
572 }
573
574 return GL_FALSE;
575 }
576
577
578 /**
579 * For debug only.
580 */
581 static void
582 att_incomplete(const char *msg)
583 {
584 if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) {
585 _mesa_debug(NULL, "attachment incomplete: %s\n", msg);
586 }
587 }
588
589
590 /**
591 * For debug only.
592 */
593 static void
594 fbo_incomplete(struct gl_context *ctx, const char *msg, int index)
595 {
596 static GLuint msg_id;
597
598 _mesa_gl_debug(ctx, &msg_id,
599 MESA_DEBUG_TYPE_OTHER,
600 MESA_DEBUG_SEVERITY_MEDIUM,
601 "FBO incomplete: %s [%d]\n", msg, index);
602
603 if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) {
604 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
605 }
606 }
607
608
609 /**
610 * Is the given base format a legal format for a color renderbuffer?
611 */
612 GLboolean
613 _mesa_is_legal_color_format(const struct gl_context *ctx, GLenum baseFormat)
614 {
615 switch (baseFormat) {
616 case GL_RGB:
617 case GL_RGBA:
618 return GL_TRUE;
619 case GL_LUMINANCE:
620 case GL_LUMINANCE_ALPHA:
621 case GL_INTENSITY:
622 case GL_ALPHA:
623 return ctx->API == API_OPENGL_COMPAT &&
624 ctx->Extensions.ARB_framebuffer_object;
625 case GL_RED:
626 case GL_RG:
627 return ctx->Extensions.ARB_texture_rg;
628 default:
629 return GL_FALSE;
630 }
631 }
632
633
634 /**
635 * Is the given base format a legal format for a color renderbuffer?
636 */
637 static GLboolean
638 is_format_color_renderable(const struct gl_context *ctx, gl_format format, GLenum internalFormat)
639 {
640 const GLenum baseFormat =
641 _mesa_get_format_base_format(format);
642 GLboolean valid;
643
644 valid = _mesa_is_legal_color_format(ctx, baseFormat);
645 if (!valid || _mesa_is_desktop_gl(ctx)) {
646 return valid;
647 }
648
649 /* Reject additional cases for GLES */
650 switch (internalFormat) {
651 case GL_RGBA8_SNORM:
652 case GL_RGB32F:
653 case GL_RGB32I:
654 case GL_RGB32UI:
655 case GL_RGB16F:
656 case GL_RGB16I:
657 case GL_RGB16UI:
658 case GL_RGB8_SNORM:
659 case GL_RGB8I:
660 case GL_RGB8UI:
661 case GL_SRGB8:
662 case GL_RGB9_E5:
663 case GL_RG8_SNORM:
664 case GL_R8_SNORM:
665 return GL_FALSE;
666 default:
667 break;
668 }
669
670 if (format == MESA_FORMAT_ARGB2101010 && internalFormat != GL_RGB10_A2) {
671 return GL_FALSE;
672 }
673
674 return GL_TRUE;
675 }
676
677
678 /**
679 * Is the given base format a legal format for a depth/stencil renderbuffer?
680 */
681 static GLboolean
682 is_legal_depth_format(const struct gl_context *ctx, GLenum baseFormat)
683 {
684 switch (baseFormat) {
685 case GL_DEPTH_COMPONENT:
686 case GL_DEPTH_STENCIL_EXT:
687 return GL_TRUE;
688 default:
689 return GL_FALSE;
690 }
691 }
692
693
694 /**
695 * Test if an attachment point is complete and update its Complete field.
696 * \param format if GL_COLOR, this is a color attachment point,
697 * if GL_DEPTH, this is a depth component attachment point,
698 * if GL_STENCIL, this is a stencil component attachment point.
699 */
700 static void
701 test_attachment_completeness(const struct gl_context *ctx, GLenum format,
702 struct gl_renderbuffer_attachment *att)
703 {
704 assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL);
705
706 /* assume complete */
707 att->Complete = GL_TRUE;
708
709 /* Look for reasons why the attachment might be incomplete */
710 if (att->Type == GL_TEXTURE) {
711 const struct gl_texture_object *texObj = att->Texture;
712 struct gl_texture_image *texImage;
713 GLenum baseFormat;
714
715 if (!texObj) {
716 att_incomplete("no texobj");
717 att->Complete = GL_FALSE;
718 return;
719 }
720
721 texImage = texObj->Image[att->CubeMapFace][att->TextureLevel];
722 if (!texImage) {
723 att_incomplete("no teximage");
724 att->Complete = GL_FALSE;
725 return;
726 }
727 if (texImage->Width < 1 || texImage->Height < 1) {
728 att_incomplete("teximage width/height=0");
729 att->Complete = GL_FALSE;
730 return;
731 }
732 if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) {
733 att_incomplete("bad z offset");
734 att->Complete = GL_FALSE;
735 return;
736 }
737
738 baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
739
740 if (format == GL_COLOR) {
741 if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
742 att_incomplete("bad format");
743 att->Complete = GL_FALSE;
744 return;
745 }
746 if (_mesa_is_format_compressed(texImage->TexFormat)) {
747 att_incomplete("compressed internalformat");
748 att->Complete = GL_FALSE;
749 return;
750 }
751 }
752 else if (format == GL_DEPTH) {
753 if (baseFormat == GL_DEPTH_COMPONENT) {
754 /* OK */
755 }
756 else if (ctx->Extensions.EXT_packed_depth_stencil &&
757 ctx->Extensions.ARB_depth_texture &&
758 baseFormat == GL_DEPTH_STENCIL_EXT) {
759 /* OK */
760 }
761 else {
762 att->Complete = GL_FALSE;
763 att_incomplete("bad depth format");
764 return;
765 }
766 }
767 else {
768 ASSERT(format == GL_STENCIL);
769 if (ctx->Extensions.EXT_packed_depth_stencil &&
770 ctx->Extensions.ARB_depth_texture &&
771 baseFormat == GL_DEPTH_STENCIL_EXT) {
772 /* OK */
773 }
774 else {
775 /* no such thing as stencil-only textures */
776 att_incomplete("illegal stencil texture");
777 att->Complete = GL_FALSE;
778 return;
779 }
780 }
781 }
782 else if (att->Type == GL_RENDERBUFFER_EXT) {
783 const GLenum baseFormat =
784 _mesa_get_format_base_format(att->Renderbuffer->Format);
785
786 ASSERT(att->Renderbuffer);
787 if (!att->Renderbuffer->InternalFormat ||
788 att->Renderbuffer->Width < 1 ||
789 att->Renderbuffer->Height < 1) {
790 att_incomplete("0x0 renderbuffer");
791 att->Complete = GL_FALSE;
792 return;
793 }
794 if (format == GL_COLOR) {
795 if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
796 att_incomplete("bad renderbuffer color format");
797 att->Complete = GL_FALSE;
798 return;
799 }
800 }
801 else if (format == GL_DEPTH) {
802 if (baseFormat == GL_DEPTH_COMPONENT) {
803 /* OK */
804 }
805 else if (ctx->Extensions.EXT_packed_depth_stencil &&
806 baseFormat == GL_DEPTH_STENCIL_EXT) {
807 /* OK */
808 }
809 else {
810 att_incomplete("bad renderbuffer depth format");
811 att->Complete = GL_FALSE;
812 return;
813 }
814 }
815 else {
816 assert(format == GL_STENCIL);
817 if (baseFormat == GL_STENCIL_INDEX) {
818 /* OK */
819 }
820 else if (ctx->Extensions.EXT_packed_depth_stencil &&
821 baseFormat == GL_DEPTH_STENCIL_EXT) {
822 /* OK */
823 }
824 else {
825 att->Complete = GL_FALSE;
826 att_incomplete("bad renderbuffer stencil format");
827 return;
828 }
829 }
830 }
831 else {
832 ASSERT(att->Type == GL_NONE);
833 /* complete */
834 return;
835 }
836 }
837
838
839 /**
840 * Test if the given framebuffer object is complete and update its
841 * Status field with the results.
842 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
843 * driver to make hardware-specific validation/completeness checks.
844 * Also update the framebuffer's Width and Height fields if the
845 * framebuffer is complete.
846 */
847 void
848 _mesa_test_framebuffer_completeness(struct gl_context *ctx,
849 struct gl_framebuffer *fb)
850 {
851 GLuint numImages;
852 GLenum intFormat = GL_NONE; /* color buffers' internal format */
853 GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0;
854 GLint numSamples = -1;
855 GLint fixedSampleLocations = -1;
856 GLint i;
857 GLuint j;
858 bool layer_count_valid = false;
859 GLuint layer_count = 0, att_layer_count;
860
861 assert(_mesa_is_user_fbo(fb));
862
863 /* we're changing framebuffer fields here */
864 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
865
866 numImages = 0;
867 fb->Width = 0;
868 fb->Height = 0;
869 fb->_AllColorBuffersFixedPoint = GL_TRUE;
870 fb->_HasSNormOrFloatColorBuffer = GL_FALSE;
871
872 /* Start at -2 to more easily loop over all attachment points.
873 * -2: depth buffer
874 * -1: stencil buffer
875 * >=0: color buffer
876 */
877 for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) {
878 struct gl_renderbuffer_attachment *att;
879 GLenum f;
880 gl_format attFormat;
881
882 /*
883 * XXX for ARB_fbo, only check color buffers that are named by
884 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
885 */
886
887 /* check for attachment completeness
888 */
889 if (i == -2) {
890 att = &fb->Attachment[BUFFER_DEPTH];
891 test_attachment_completeness(ctx, GL_DEPTH, att);
892 if (!att->Complete) {
893 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
894 fbo_incomplete(ctx, "depth attachment incomplete", -1);
895 return;
896 }
897 }
898 else if (i == -1) {
899 att = &fb->Attachment[BUFFER_STENCIL];
900 test_attachment_completeness(ctx, GL_STENCIL, att);
901 if (!att->Complete) {
902 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
903 fbo_incomplete(ctx, "stencil attachment incomplete", -1);
904 return;
905 }
906 }
907 else {
908 att = &fb->Attachment[BUFFER_COLOR0 + i];
909 test_attachment_completeness(ctx, GL_COLOR, att);
910 if (!att->Complete) {
911 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
912 fbo_incomplete(ctx, "color attachment incomplete", i);
913 return;
914 }
915 }
916
917 /* get width, height, format of the renderbuffer/texture
918 */
919 if (att->Type == GL_TEXTURE) {
920 const struct gl_texture_image *texImg = att->Renderbuffer->TexImage;
921 minWidth = MIN2(minWidth, texImg->Width);
922 maxWidth = MAX2(maxWidth, texImg->Width);
923 minHeight = MIN2(minHeight, texImg->Height);
924 maxHeight = MAX2(maxHeight, texImg->Height);
925 f = texImg->_BaseFormat;
926 attFormat = texImg->TexFormat;
927 numImages++;
928
929 if (!is_format_color_renderable(ctx, attFormat, texImg->InternalFormat) &&
930 !is_legal_depth_format(ctx, f)) {
931 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
932 fbo_incomplete(ctx, "texture attachment incomplete", -1);
933 return;
934 }
935
936 if (numSamples < 0)
937 numSamples = texImg->NumSamples;
938 else if (numSamples != texImg->NumSamples) {
939 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
940 fbo_incomplete(ctx, "inconsistent sample count", -1);
941 return;
942 }
943
944 if (fixedSampleLocations < 0)
945 fixedSampleLocations = texImg->FixedSampleLocations;
946 else if (fixedSampleLocations != texImg->FixedSampleLocations) {
947 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
948 fbo_incomplete(ctx, "inconsistent fixed sample locations", -1);
949 return;
950 }
951 }
952 else if (att->Type == GL_RENDERBUFFER_EXT) {
953 minWidth = MIN2(minWidth, att->Renderbuffer->Width);
954 maxWidth = MAX2(minWidth, att->Renderbuffer->Width);
955 minHeight = MIN2(minHeight, att->Renderbuffer->Height);
956 maxHeight = MAX2(minHeight, att->Renderbuffer->Height);
957 f = att->Renderbuffer->InternalFormat;
958 attFormat = att->Renderbuffer->Format;
959 numImages++;
960
961 if (numSamples < 0)
962 numSamples = att->Renderbuffer->NumSamples;
963 else if (numSamples != att->Renderbuffer->NumSamples) {
964 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
965 fbo_incomplete(ctx, "inconsistent sample count", -1);
966 return;
967 }
968
969 /* RENDERBUFFER has fixedSampleLocations implicitly true */
970 if (fixedSampleLocations < 0)
971 fixedSampleLocations = GL_TRUE;
972 else if (fixedSampleLocations != GL_TRUE) {
973 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
974 fbo_incomplete(ctx, "inconsistent fixed sample locations", -1);
975 return;
976 }
977 }
978 else {
979 assert(att->Type == GL_NONE);
980 continue;
981 }
982
983 /* check if integer color */
984 fb->_IntegerColor = _mesa_is_format_integer_color(attFormat);
985
986 /* Update _AllColorBuffersFixedPoint and _HasSNormOrFloatColorBuffer. */
987 if (i >= 0) {
988 GLenum type = _mesa_get_format_datatype(attFormat);
989
990 fb->_AllColorBuffersFixedPoint =
991 fb->_AllColorBuffersFixedPoint &&
992 (type == GL_UNSIGNED_NORMALIZED || type == GL_SIGNED_NORMALIZED);
993
994 fb->_HasSNormOrFloatColorBuffer =
995 fb->_HasSNormOrFloatColorBuffer ||
996 type == GL_SIGNED_NORMALIZED || type == GL_FLOAT;
997 }
998
999 /* Error-check width, height, format */
1000 if (numImages == 1) {
1001 /* save format */
1002 if (i >= 0) {
1003 intFormat = f;
1004 }
1005 }
1006 else {
1007 if (!ctx->Extensions.ARB_framebuffer_object) {
1008 /* check that width, height, format are same */
1009 if (minWidth != maxWidth || minHeight != maxHeight) {
1010 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
1011 fbo_incomplete(ctx, "width or height mismatch", -1);
1012 return;
1013 }
1014 /* check that all color buffers are the same format */
1015 if (intFormat != GL_NONE && f != intFormat) {
1016 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
1017 fbo_incomplete(ctx, "format mismatch", -1);
1018 return;
1019 }
1020 }
1021 }
1022
1023 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1024 */
1025 if (att->Type == GL_RENDERBUFFER &&
1026 att->Renderbuffer->Format == MESA_FORMAT_NONE) {
1027 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
1028 fbo_incomplete(ctx, "unsupported renderbuffer format", i);
1029 return;
1030 }
1031
1032 /* Check that layered rendering is consistent. */
1033 att_layer_count = att->Layered ? att->Renderbuffer->Depth : 0;
1034 if (!layer_count_valid) {
1035 layer_count = att_layer_count;
1036 layer_count_valid = true;
1037 } else if (layer_count != att_layer_count) {
1038 if (layer_count == 0 || att_layer_count == 0) {
1039 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS;
1040 fbo_incomplete(ctx, "framebuffer attachment layer mode is inconsistent", i);
1041 } else {
1042 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB;
1043 fbo_incomplete(ctx, "framebuffer attachment layer count is inconsistent", i);
1044 }
1045 return;
1046 }
1047 }
1048
1049 fb->Layered = layer_count > 0;
1050
1051 if (_mesa_is_desktop_gl(ctx) && !ctx->Extensions.ARB_ES2_compatibility) {
1052 /* Check that all DrawBuffers are present */
1053 for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) {
1054 if (fb->ColorDrawBuffer[j] != GL_NONE) {
1055 const struct gl_renderbuffer_attachment *att
1056 = _mesa_get_attachment(ctx, fb, fb->ColorDrawBuffer[j]);
1057 assert(att);
1058 if (att->Type == GL_NONE) {
1059 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT;
1060 fbo_incomplete(ctx, "missing drawbuffer", j);
1061 return;
1062 }
1063 }
1064 }
1065
1066 /* Check that the ReadBuffer is present */
1067 if (fb->ColorReadBuffer != GL_NONE) {
1068 const struct gl_renderbuffer_attachment *att
1069 = _mesa_get_attachment(ctx, fb, fb->ColorReadBuffer);
1070 assert(att);
1071 if (att->Type == GL_NONE) {
1072 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT;
1073 fbo_incomplete(ctx, "missing readbuffer", -1);
1074 return;
1075 }
1076 }
1077 }
1078
1079 if (numImages == 0) {
1080 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT;
1081 fbo_incomplete(ctx, "no attachments", -1);
1082 return;
1083 }
1084
1085 /* Provisionally set status = COMPLETE ... */
1086 fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
1087
1088 /* ... but the driver may say the FB is incomplete.
1089 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1090 * if anything.
1091 */
1092 if (ctx->Driver.ValidateFramebuffer) {
1093 ctx->Driver.ValidateFramebuffer(ctx, fb);
1094 if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
1095 fbo_incomplete(ctx, "driver marked FBO as incomplete", -1);
1096 }
1097 }
1098
1099 if (fb->_Status == GL_FRAMEBUFFER_COMPLETE_EXT) {
1100 /*
1101 * Note that if ARB_framebuffer_object is supported and the attached
1102 * renderbuffers/textures are different sizes, the framebuffer
1103 * width/height will be set to the smallest width/height.
1104 */
1105 fb->Width = minWidth;
1106 fb->Height = minHeight;
1107
1108 /* finally, update the visual info for the framebuffer */
1109 _mesa_update_framebuffer_visual(ctx, fb);
1110 }
1111 }
1112
1113
1114 GLboolean GLAPIENTRY
1115 _mesa_IsRenderbuffer(GLuint renderbuffer)
1116 {
1117 GET_CURRENT_CONTEXT(ctx);
1118 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
1119 if (renderbuffer) {
1120 struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
1121 if (rb != NULL && rb != &DummyRenderbuffer)
1122 return GL_TRUE;
1123 }
1124 return GL_FALSE;
1125 }
1126
1127
1128 static void
1129 bind_renderbuffer(GLenum target, GLuint renderbuffer, bool allow_user_names)
1130 {
1131 struct gl_renderbuffer *newRb;
1132 GET_CURRENT_CONTEXT(ctx);
1133
1134 if (target != GL_RENDERBUFFER_EXT) {
1135 _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)");
1136 return;
1137 }
1138
1139 /* No need to flush here since the render buffer binding has no
1140 * effect on rendering state.
1141 */
1142
1143 if (renderbuffer) {
1144 newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
1145 if (newRb == &DummyRenderbuffer) {
1146 /* ID was reserved, but no real renderbuffer object made yet */
1147 newRb = NULL;
1148 }
1149 else if (!newRb && !allow_user_names) {
1150 /* All RB IDs must be Gen'd */
1151 _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)");
1152 return;
1153 }
1154
1155 if (!newRb) {
1156 /* create new renderbuffer object */
1157 newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer);
1158 if (!newRb) {
1159 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT");
1160 return;
1161 }
1162 ASSERT(newRb->AllocStorage);
1163 _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb);
1164 newRb->RefCount = 1; /* referenced by hash table */
1165 }
1166 }
1167 else {
1168 newRb = NULL;
1169 }
1170
1171 ASSERT(newRb != &DummyRenderbuffer);
1172
1173 _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb);
1174 }
1175
1176 void GLAPIENTRY
1177 _mesa_BindRenderbuffer(GLenum target, GLuint renderbuffer)
1178 {
1179 GET_CURRENT_CONTEXT(ctx);
1180
1181 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1182 * entry point, but they allow the use of user-generated names.
1183 */
1184 bind_renderbuffer(target, renderbuffer, _mesa_is_gles(ctx));
1185 }
1186
1187 void GLAPIENTRY
1188 _mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
1189 {
1190 /* This function should not be in the dispatch table for core profile /
1191 * OpenGL 3.1, so execution should never get here in those cases -- no
1192 * need for an explicit test.
1193 */
1194 bind_renderbuffer(target, renderbuffer, true);
1195 }
1196
1197
1198 /**
1199 * If the given renderbuffer is anywhere attached to the framebuffer, detach
1200 * the renderbuffer.
1201 * This is used when a renderbuffer object is deleted.
1202 * The spec calls for unbinding.
1203 */
1204 static void
1205 detach_renderbuffer(struct gl_context *ctx,
1206 struct gl_framebuffer *fb,
1207 struct gl_renderbuffer *rb)
1208 {
1209 GLuint i;
1210 for (i = 0; i < BUFFER_COUNT; i++) {
1211 if (fb->Attachment[i].Renderbuffer == rb) {
1212 _mesa_remove_attachment(ctx, &fb->Attachment[i]);
1213 }
1214 }
1215 invalidate_framebuffer(fb);
1216 }
1217
1218
1219 void GLAPIENTRY
1220 _mesa_DeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
1221 {
1222 GLint i;
1223 GET_CURRENT_CONTEXT(ctx);
1224
1225 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1226
1227 for (i = 0; i < n; i++) {
1228 if (renderbuffers[i] > 0) {
1229 struct gl_renderbuffer *rb;
1230 rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]);
1231 if (rb) {
1232 /* check if deleting currently bound renderbuffer object */
1233 if (rb == ctx->CurrentRenderbuffer) {
1234 /* bind default */
1235 ASSERT(rb->RefCount >= 2);
1236 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
1237 }
1238
1239 if (_mesa_is_user_fbo(ctx->DrawBuffer)) {
1240 detach_renderbuffer(ctx, ctx->DrawBuffer, rb);
1241 }
1242 if (_mesa_is_user_fbo(ctx->ReadBuffer)
1243 && ctx->ReadBuffer != ctx->DrawBuffer) {
1244 detach_renderbuffer(ctx, ctx->ReadBuffer, rb);
1245 }
1246
1247 /* Remove from hash table immediately, to free the ID.
1248 * But the object will not be freed until it's no longer
1249 * referenced anywhere else.
1250 */
1251 _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]);
1252
1253 if (rb != &DummyRenderbuffer) {
1254 /* no longer referenced by hash table */
1255 _mesa_reference_renderbuffer(&rb, NULL);
1256 }
1257 }
1258 }
1259 }
1260 }
1261
1262
1263 void GLAPIENTRY
1264 _mesa_GenRenderbuffers(GLsizei n, GLuint *renderbuffers)
1265 {
1266 GET_CURRENT_CONTEXT(ctx);
1267 GLuint first;
1268 GLint i;
1269
1270 if (n < 0) {
1271 _mesa_error(ctx, GL_INVALID_VALUE, "glGenRenderbuffersEXT(n)");
1272 return;
1273 }
1274
1275 if (!renderbuffers)
1276 return;
1277
1278 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n);
1279
1280 for (i = 0; i < n; i++) {
1281 GLuint name = first + i;
1282 renderbuffers[i] = name;
1283 /* insert dummy placeholder into hash table */
1284 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1285 _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer);
1286 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1287 }
1288 }
1289
1290
1291 /**
1292 * Given an internal format token for a render buffer, return the
1293 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1294 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1295 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1296 *
1297 * This is similar to _mesa_base_tex_format() but the set of valid
1298 * internal formats is different.
1299 *
1300 * Note that even if a format is determined to be legal here, validation
1301 * of the FBO may fail if the format is not supported by the driver/GPU.
1302 *
1303 * \param internalFormat as passed to glRenderbufferStorage()
1304 * \return the base internal format, or 0 if internalFormat is illegal
1305 */
1306 GLenum
1307 _mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat)
1308 {
1309 /*
1310 * Notes: some formats such as alpha, luminance, etc. were added
1311 * with GL_ARB_framebuffer_object.
1312 */
1313 switch (internalFormat) {
1314 case GL_ALPHA:
1315 case GL_ALPHA4:
1316 case GL_ALPHA8:
1317 case GL_ALPHA12:
1318 case GL_ALPHA16:
1319 return ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_framebuffer_object
1320 ? GL_ALPHA : 0;
1321 case GL_LUMINANCE:
1322 case GL_LUMINANCE4:
1323 case GL_LUMINANCE8:
1324 case GL_LUMINANCE12:
1325 case GL_LUMINANCE16:
1326 return ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_framebuffer_object
1327 ? GL_LUMINANCE : 0;
1328 case GL_LUMINANCE_ALPHA:
1329 case GL_LUMINANCE4_ALPHA4:
1330 case GL_LUMINANCE6_ALPHA2:
1331 case GL_LUMINANCE8_ALPHA8:
1332 case GL_LUMINANCE12_ALPHA4:
1333 case GL_LUMINANCE12_ALPHA12:
1334 case GL_LUMINANCE16_ALPHA16:
1335 return ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_framebuffer_object
1336 ? GL_LUMINANCE_ALPHA : 0;
1337 case GL_INTENSITY:
1338 case GL_INTENSITY4:
1339 case GL_INTENSITY8:
1340 case GL_INTENSITY12:
1341 case GL_INTENSITY16:
1342 return ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_framebuffer_object
1343 ? GL_INTENSITY : 0;
1344 case GL_RGB8:
1345 return GL_RGB;
1346 case GL_RGB:
1347 case GL_R3_G3_B2:
1348 case GL_RGB4:
1349 case GL_RGB5:
1350 case GL_RGB10:
1351 case GL_RGB12:
1352 case GL_RGB16:
1353 return _mesa_is_desktop_gl(ctx) ? GL_RGB : 0;
1354 case GL_SRGB8_EXT:
1355 return _mesa_is_desktop_gl(ctx) ? GL_RGB : 0;
1356 case GL_RGBA4:
1357 case GL_RGB5_A1:
1358 case GL_RGBA8:
1359 return GL_RGBA;
1360 case GL_RGBA:
1361 case GL_RGBA2:
1362 case GL_RGBA12:
1363 case GL_RGBA16:
1364 return _mesa_is_desktop_gl(ctx) ? GL_RGBA : 0;
1365 case GL_RGB10_A2:
1366 case GL_SRGB8_ALPHA8_EXT:
1367 return _mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx) ? GL_RGBA : 0;
1368 case GL_STENCIL_INDEX:
1369 case GL_STENCIL_INDEX1_EXT:
1370 case GL_STENCIL_INDEX4_EXT:
1371 case GL_STENCIL_INDEX16_EXT:
1372 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1373 * OpenGL ES, but Mesa does not currently support them.
1374 */
1375 return _mesa_is_desktop_gl(ctx) ? GL_STENCIL_INDEX : 0;
1376 case GL_STENCIL_INDEX8_EXT:
1377 return GL_STENCIL_INDEX;
1378 case GL_DEPTH_COMPONENT:
1379 case GL_DEPTH_COMPONENT32:
1380 return _mesa_is_desktop_gl(ctx) ? GL_DEPTH_COMPONENT : 0;
1381 case GL_DEPTH_COMPONENT16:
1382 case GL_DEPTH_COMPONENT24:
1383 return GL_DEPTH_COMPONENT;
1384 case GL_DEPTH_STENCIL_EXT:
1385 return _mesa_is_desktop_gl(ctx)
1386 && ctx->Extensions.EXT_packed_depth_stencil
1387 ? GL_DEPTH_STENCIL_EXT : 0;
1388 case GL_DEPTH24_STENCIL8_EXT:
1389 return ctx->Extensions.EXT_packed_depth_stencil
1390 ? GL_DEPTH_STENCIL_EXT : 0;
1391 case GL_DEPTH_COMPONENT32F:
1392 return ctx->Version >= 30
1393 || (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_depth_buffer_float)
1394 ? GL_DEPTH_COMPONENT : 0;
1395 case GL_DEPTH32F_STENCIL8:
1396 return ctx->Version >= 30
1397 || (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_depth_buffer_float)
1398 ? GL_DEPTH_STENCIL : 0;
1399 case GL_RED:
1400 case GL_R16:
1401 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_rg
1402 ? GL_RED : 0;
1403 case GL_R8:
1404 return ctx->API != API_OPENGLES && ctx->Extensions.ARB_texture_rg
1405 ? GL_RED : 0;
1406 case GL_RG:
1407 case GL_RG16:
1408 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_rg
1409 ? GL_RG : 0;
1410 case GL_RG8:
1411 return ctx->API != API_OPENGLES && ctx->Extensions.ARB_texture_rg
1412 ? GL_RG : 0;
1413 /* signed normalized texture formats */
1414 case GL_RED_SNORM:
1415 case GL_R8_SNORM:
1416 case GL_R16_SNORM:
1417 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1418 ? GL_RED : 0;
1419 case GL_RG_SNORM:
1420 case GL_RG8_SNORM:
1421 case GL_RG16_SNORM:
1422 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1423 ? GL_RG : 0;
1424 case GL_RGB_SNORM:
1425 case GL_RGB8_SNORM:
1426 case GL_RGB16_SNORM:
1427 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1428 ? GL_RGB : 0;
1429 case GL_RGBA_SNORM:
1430 case GL_RGBA8_SNORM:
1431 case GL_RGBA16_SNORM:
1432 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1433 ? GL_RGBA : 0;
1434 case GL_ALPHA_SNORM:
1435 case GL_ALPHA8_SNORM:
1436 case GL_ALPHA16_SNORM:
1437 return ctx->API == API_OPENGL_COMPAT &&
1438 ctx->Extensions.EXT_texture_snorm &&
1439 ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
1440 case GL_R16F:
1441 case GL_R32F:
1442 return ((_mesa_is_desktop_gl(ctx) &&
1443 ctx->Extensions.ARB_texture_rg &&
1444 ctx->Extensions.ARB_texture_float) ||
1445 _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ )
1446 ? GL_RED : 0;
1447 case GL_RG16F:
1448 case GL_RG32F:
1449 return ((_mesa_is_desktop_gl(ctx) &&
1450 ctx->Extensions.ARB_texture_rg &&
1451 ctx->Extensions.ARB_texture_float) ||
1452 _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ )
1453 ? GL_RG : 0;
1454 case GL_RGB16F:
1455 case GL_RGB32F:
1456 return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_float)
1457 ? GL_RGB : 0;
1458 case GL_RGBA16F:
1459 case GL_RGBA32F:
1460 return ((_mesa_is_desktop_gl(ctx) &&
1461 ctx->Extensions.ARB_texture_float) ||
1462 _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ )
1463 ? GL_RGBA : 0;
1464 case GL_ALPHA16F_ARB:
1465 case GL_ALPHA32F_ARB:
1466 return ctx->API == API_OPENGL_COMPAT &&
1467 ctx->Extensions.ARB_texture_float &&
1468 ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
1469 case GL_LUMINANCE16F_ARB:
1470 case GL_LUMINANCE32F_ARB:
1471 return ctx->API == API_OPENGL_COMPAT &&
1472 ctx->Extensions.ARB_texture_float &&
1473 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
1474 case GL_LUMINANCE_ALPHA16F_ARB:
1475 case GL_LUMINANCE_ALPHA32F_ARB:
1476 return ctx->API == API_OPENGL_COMPAT &&
1477 ctx->Extensions.ARB_texture_float &&
1478 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
1479 case GL_INTENSITY16F_ARB:
1480 case GL_INTENSITY32F_ARB:
1481 return ctx->API == API_OPENGL_COMPAT &&
1482 ctx->Extensions.ARB_texture_float &&
1483 ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
1484 case GL_RGB9_E5:
1485 return (_mesa_is_desktop_gl(ctx)
1486 && ctx->Extensions.EXT_texture_shared_exponent)
1487 ? GL_RGB : 0;
1488 case GL_R11F_G11F_B10F:
1489 return ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_packed_float) ||
1490 _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ )
1491 ? GL_RGB : 0;
1492
1493 case GL_RGBA8UI_EXT:
1494 case GL_RGBA16UI_EXT:
1495 case GL_RGBA32UI_EXT:
1496 case GL_RGBA8I_EXT:
1497 case GL_RGBA16I_EXT:
1498 case GL_RGBA32I_EXT:
1499 return ctx->Version >= 30
1500 || (_mesa_is_desktop_gl(ctx) &&
1501 ctx->Extensions.EXT_texture_integer) ? GL_RGBA : 0;
1502
1503 case GL_RGB8UI_EXT:
1504 case GL_RGB16UI_EXT:
1505 case GL_RGB32UI_EXT:
1506 case GL_RGB8I_EXT:
1507 case GL_RGB16I_EXT:
1508 case GL_RGB32I_EXT:
1509 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_integer
1510 ? GL_RGB : 0;
1511 case GL_R8UI:
1512 case GL_R8I:
1513 case GL_R16UI:
1514 case GL_R16I:
1515 case GL_R32UI:
1516 case GL_R32I:
1517 return ctx->Version >= 30
1518 || (_mesa_is_desktop_gl(ctx) &&
1519 ctx->Extensions.ARB_texture_rg &&
1520 ctx->Extensions.EXT_texture_integer) ? GL_RED : 0;
1521
1522 case GL_RG8UI:
1523 case GL_RG8I:
1524 case GL_RG16UI:
1525 case GL_RG16I:
1526 case GL_RG32UI:
1527 case GL_RG32I:
1528 return ctx->Version >= 30
1529 || (_mesa_is_desktop_gl(ctx) &&
1530 ctx->Extensions.ARB_texture_rg &&
1531 ctx->Extensions.EXT_texture_integer) ? GL_RG : 0;
1532
1533 case GL_INTENSITY8I_EXT:
1534 case GL_INTENSITY8UI_EXT:
1535 case GL_INTENSITY16I_EXT:
1536 case GL_INTENSITY16UI_EXT:
1537 case GL_INTENSITY32I_EXT:
1538 case GL_INTENSITY32UI_EXT:
1539 return ctx->API == API_OPENGL_COMPAT &&
1540 ctx->Extensions.EXT_texture_integer &&
1541 ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
1542
1543 case GL_LUMINANCE8I_EXT:
1544 case GL_LUMINANCE8UI_EXT:
1545 case GL_LUMINANCE16I_EXT:
1546 case GL_LUMINANCE16UI_EXT:
1547 case GL_LUMINANCE32I_EXT:
1548 case GL_LUMINANCE32UI_EXT:
1549 return ctx->API == API_OPENGL_COMPAT &&
1550 ctx->Extensions.EXT_texture_integer &&
1551 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
1552
1553 case GL_LUMINANCE_ALPHA8I_EXT:
1554 case GL_LUMINANCE_ALPHA8UI_EXT:
1555 case GL_LUMINANCE_ALPHA16I_EXT:
1556 case GL_LUMINANCE_ALPHA16UI_EXT:
1557 case GL_LUMINANCE_ALPHA32I_EXT:
1558 case GL_LUMINANCE_ALPHA32UI_EXT:
1559 return ctx->API == API_OPENGL_COMPAT &&
1560 ctx->Extensions.EXT_texture_integer &&
1561 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
1562
1563 case GL_ALPHA8I_EXT:
1564 case GL_ALPHA8UI_EXT:
1565 case GL_ALPHA16I_EXT:
1566 case GL_ALPHA16UI_EXT:
1567 case GL_ALPHA32I_EXT:
1568 case GL_ALPHA32UI_EXT:
1569 return ctx->API == API_OPENGL_COMPAT &&
1570 ctx->Extensions.EXT_texture_integer &&
1571 ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
1572
1573 case GL_RGB10_A2UI:
1574 return (_mesa_is_desktop_gl(ctx) &&
1575 ctx->Extensions.ARB_texture_rgb10_a2ui)
1576 || _mesa_is_gles3(ctx) ? GL_RGBA : 0;
1577
1578 case GL_RGB565:
1579 return _mesa_is_gles(ctx) || ctx->Extensions.ARB_ES2_compatibility
1580 ? GL_RGB : 0;
1581 default:
1582 return 0;
1583 }
1584 }
1585
1586
1587 /**
1588 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1589 */
1590 static void
1591 invalidate_rb(GLuint key, void *data, void *userData)
1592 {
1593 struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
1594 struct gl_renderbuffer *rb = (struct gl_renderbuffer *) userData;
1595
1596 /* If this is a user-created FBO */
1597 if (_mesa_is_user_fbo(fb)) {
1598 GLuint i;
1599 for (i = 0; i < BUFFER_COUNT; i++) {
1600 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
1601 if (att->Type == GL_RENDERBUFFER &&
1602 att->Renderbuffer == rb) {
1603 /* Mark fb status as indeterminate to force re-validation */
1604 fb->_Status = 0;
1605 return;
1606 }
1607 }
1608 }
1609 }
1610
1611
1612 /** sentinal value, see below */
1613 #define NO_SAMPLES 1000
1614
1615
1616 /**
1617 * Helper function used by _mesa_RenderbufferStorage() and
1618 * _mesa_RenderbufferStorageMultisample().
1619 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
1620 */
1621 static void
1622 renderbuffer_storage(GLenum target, GLenum internalFormat,
1623 GLsizei width, GLsizei height, GLsizei samples)
1624 {
1625 const char *func = samples == NO_SAMPLES ?
1626 "glRenderbufferStorage" : "glRenderbufferStorageMultisample";
1627 struct gl_renderbuffer *rb;
1628 GLenum baseFormat;
1629 GLenum sample_count_error;
1630 GET_CURRENT_CONTEXT(ctx);
1631
1632 if (MESA_VERBOSE & VERBOSE_API) {
1633 if (samples == NO_SAMPLES)
1634 _mesa_debug(ctx, "%s(%s, %s, %d, %d)\n",
1635 func,
1636 _mesa_lookup_enum_by_nr(target),
1637 _mesa_lookup_enum_by_nr(internalFormat),
1638 width, height);
1639 else
1640 _mesa_debug(ctx, "%s(%s, %s, %d, %d, %d)\n",
1641 func,
1642 _mesa_lookup_enum_by_nr(target),
1643 _mesa_lookup_enum_by_nr(internalFormat),
1644 width, height, samples);
1645 }
1646
1647 if (target != GL_RENDERBUFFER_EXT) {
1648 _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
1649 return;
1650 }
1651
1652 baseFormat = _mesa_base_fbo_format(ctx, internalFormat);
1653 if (baseFormat == 0) {
1654 _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat=%s)",
1655 func, _mesa_lookup_enum_by_nr(internalFormat));
1656 return;
1657 }
1658
1659 if (width < 0 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) {
1660 _mesa_error(ctx, GL_INVALID_VALUE, "%s(width)", func);
1661 return;
1662 }
1663
1664 if (height < 0 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) {
1665 _mesa_error(ctx, GL_INVALID_VALUE, "%s(height)", func);
1666 return;
1667 }
1668
1669 if (samples == NO_SAMPLES) {
1670 /* NumSamples == 0 indicates non-multisampling */
1671 samples = 0;
1672 }
1673 else {
1674 /* check the sample count;
1675 * note: driver may choose to use more samples than what's requested
1676 */
1677 sample_count_error = _mesa_check_sample_count(ctx, target,
1678 internalFormat, samples);
1679 if (sample_count_error != GL_NO_ERROR) {
1680 _mesa_error(ctx, sample_count_error, "%s(samples)", func);
1681 return;
1682 }
1683 }
1684
1685 rb = ctx->CurrentRenderbuffer;
1686 if (!rb) {
1687 _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
1688 return;
1689 }
1690
1691 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1692
1693 if (rb->InternalFormat == internalFormat &&
1694 rb->Width == (GLuint) width &&
1695 rb->Height == (GLuint) height &&
1696 rb->NumSamples == samples) {
1697 /* no change in allocation needed */
1698 return;
1699 }
1700
1701 /* These MUST get set by the AllocStorage func */
1702 rb->Format = MESA_FORMAT_NONE;
1703 rb->NumSamples = samples;
1704
1705 /* Now allocate the storage */
1706 ASSERT(rb->AllocStorage);
1707 if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) {
1708 /* No error - check/set fields now */
1709 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
1710 assert(rb->Width == (GLuint) width);
1711 assert(rb->Height == (GLuint) height);
1712 rb->InternalFormat = internalFormat;
1713 rb->_BaseFormat = baseFormat;
1714 assert(rb->_BaseFormat != 0);
1715 }
1716 else {
1717 /* Probably ran out of memory - clear the fields */
1718 rb->Width = 0;
1719 rb->Height = 0;
1720 rb->Format = MESA_FORMAT_NONE;
1721 rb->InternalFormat = GL_NONE;
1722 rb->_BaseFormat = GL_NONE;
1723 rb->NumSamples = 0;
1724 }
1725
1726 /* Invalidate the framebuffers the renderbuffer is attached in. */
1727 if (rb->AttachedAnytime) {
1728 _mesa_HashWalk(ctx->Shared->FrameBuffers, invalidate_rb, rb);
1729 }
1730 }
1731
1732
1733 void GLAPIENTRY
1734 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
1735 {
1736 struct gl_renderbuffer *rb;
1737 GET_CURRENT_CONTEXT(ctx);
1738
1739 if (!ctx->Extensions.OES_EGL_image) {
1740 _mesa_error(ctx, GL_INVALID_OPERATION,
1741 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1742 return;
1743 }
1744
1745 if (target != GL_RENDERBUFFER) {
1746 _mesa_error(ctx, GL_INVALID_ENUM,
1747 "EGLImageTargetRenderbufferStorageOES");
1748 return;
1749 }
1750
1751 rb = ctx->CurrentRenderbuffer;
1752 if (!rb) {
1753 _mesa_error(ctx, GL_INVALID_OPERATION,
1754 "EGLImageTargetRenderbufferStorageOES");
1755 return;
1756 }
1757
1758 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1759
1760 ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image);
1761 }
1762
1763
1764 /**
1765 * Helper function for _mesa_GetRenderbufferParameteriv() and
1766 * _mesa_GetFramebufferAttachmentParameteriv()
1767 * We have to be careful to respect the base format. For example, if a
1768 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1769 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1770 * we need to return zero.
1771 */
1772 static GLint
1773 get_component_bits(GLenum pname, GLenum baseFormat, gl_format format)
1774 {
1775 if (_mesa_base_format_has_channel(baseFormat, pname))
1776 return _mesa_get_format_bits(format, pname);
1777 else
1778 return 0;
1779 }
1780
1781
1782
1783 void GLAPIENTRY
1784 _mesa_RenderbufferStorage(GLenum target, GLenum internalFormat,
1785 GLsizei width, GLsizei height)
1786 {
1787 /* GL_ARB_fbo says calling this function is equivalent to calling
1788 * glRenderbufferStorageMultisample() with samples=0. We pass in
1789 * a token value here just for error reporting purposes.
1790 */
1791 renderbuffer_storage(target, internalFormat, width, height, NO_SAMPLES);
1792 }
1793
1794
1795 void GLAPIENTRY
1796 _mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples,
1797 GLenum internalFormat,
1798 GLsizei width, GLsizei height)
1799 {
1800 renderbuffer_storage(target, internalFormat, width, height, samples);
1801 }
1802
1803
1804 /**
1805 * OpenGL ES version of glRenderBufferStorage.
1806 */
1807 void GLAPIENTRY
1808 _es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
1809 GLsizei width, GLsizei height)
1810 {
1811 switch (internalFormat) {
1812 case GL_RGB565:
1813 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1814 /* choose a closest format */
1815 internalFormat = GL_RGB5;
1816 break;
1817 default:
1818 break;
1819 }
1820
1821 renderbuffer_storage(target, internalFormat, width, height, 0);
1822 }
1823
1824
1825 void GLAPIENTRY
1826 _mesa_GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1827 {
1828 struct gl_renderbuffer *rb;
1829 GET_CURRENT_CONTEXT(ctx);
1830
1831 if (target != GL_RENDERBUFFER_EXT) {
1832 _mesa_error(ctx, GL_INVALID_ENUM,
1833 "glGetRenderbufferParameterivEXT(target)");
1834 return;
1835 }
1836
1837 rb = ctx->CurrentRenderbuffer;
1838 if (!rb) {
1839 _mesa_error(ctx, GL_INVALID_OPERATION,
1840 "glGetRenderbufferParameterivEXT");
1841 return;
1842 }
1843
1844 /* No need to flush here since we're just quering state which is
1845 * not effected by rendering.
1846 */
1847
1848 switch (pname) {
1849 case GL_RENDERBUFFER_WIDTH_EXT:
1850 *params = rb->Width;
1851 return;
1852 case GL_RENDERBUFFER_HEIGHT_EXT:
1853 *params = rb->Height;
1854 return;
1855 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT:
1856 *params = rb->InternalFormat;
1857 return;
1858 case GL_RENDERBUFFER_RED_SIZE_EXT:
1859 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
1860 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
1861 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
1862 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
1863 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
1864 *params = get_component_bits(pname, rb->_BaseFormat, rb->Format);
1865 break;
1866 case GL_RENDERBUFFER_SAMPLES:
1867 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_framebuffer_object)
1868 || _mesa_is_gles3(ctx)) {
1869 *params = rb->NumSamples;
1870 break;
1871 }
1872 /* fallthrough */
1873 default:
1874 _mesa_error(ctx, GL_INVALID_ENUM,
1875 "glGetRenderbufferParameterivEXT(target)");
1876 return;
1877 }
1878 }
1879
1880
1881 GLboolean GLAPIENTRY
1882 _mesa_IsFramebuffer(GLuint framebuffer)
1883 {
1884 GET_CURRENT_CONTEXT(ctx);
1885 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
1886 if (framebuffer) {
1887 struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer);
1888 if (rb != NULL && rb != &DummyFramebuffer)
1889 return GL_TRUE;
1890 }
1891 return GL_FALSE;
1892 }
1893
1894
1895 /**
1896 * Check if any of the attachments of the given framebuffer are textures
1897 * (render to texture). Call ctx->Driver.RenderTexture() for such
1898 * attachments.
1899 */
1900 static void
1901 check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
1902 {
1903 GLuint i;
1904 ASSERT(ctx->Driver.RenderTexture);
1905
1906 if (_mesa_is_winsys_fbo(fb))
1907 return; /* can't render to texture with winsys framebuffers */
1908
1909 for (i = 0; i < BUFFER_COUNT; i++) {
1910 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
1911 if (att->Texture && att->Renderbuffer->TexImage
1912 && driver_RenderTexture_is_safe(att)) {
1913 ctx->Driver.RenderTexture(ctx, fb, att);
1914 }
1915 }
1916 }
1917
1918
1919 /**
1920 * Examine all the framebuffer's attachments to see if any are textures.
1921 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1922 * notify the device driver that the texture image may have changed.
1923 */
1924 static void
1925 check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
1926 {
1927 if (_mesa_is_winsys_fbo(fb))
1928 return; /* can't render to texture with winsys framebuffers */
1929
1930 if (ctx->Driver.FinishRenderTexture) {
1931 GLuint i;
1932 for (i = 0; i < BUFFER_COUNT; i++) {
1933 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
1934 struct gl_renderbuffer *rb = att->Renderbuffer;
1935 if (rb && rb->NeedsFinishRenderTexture) {
1936 ctx->Driver.FinishRenderTexture(ctx, rb);
1937 }
1938 }
1939 }
1940 }
1941
1942
1943 static void
1944 bind_framebuffer(GLenum target, GLuint framebuffer, bool allow_user_names)
1945 {
1946 struct gl_framebuffer *newDrawFb, *newReadFb;
1947 struct gl_framebuffer *oldDrawFb, *oldReadFb;
1948 GLboolean bindReadBuf, bindDrawBuf;
1949 GET_CURRENT_CONTEXT(ctx);
1950
1951 #ifdef DEBUG
1952 if (ctx->Extensions.ARB_framebuffer_object) {
1953 ASSERT(ctx->Extensions.EXT_framebuffer_blit);
1954 }
1955 #endif
1956
1957 switch (target) {
1958 case GL_DRAW_FRAMEBUFFER_EXT:
1959 if (!ctx->Extensions.EXT_framebuffer_blit) {
1960 _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
1961 return;
1962 }
1963 bindDrawBuf = GL_TRUE;
1964 bindReadBuf = GL_FALSE;
1965 break;
1966 case GL_READ_FRAMEBUFFER_EXT:
1967 if (!ctx->Extensions.EXT_framebuffer_blit) {
1968 _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
1969 return;
1970 }
1971 bindDrawBuf = GL_FALSE;
1972 bindReadBuf = GL_TRUE;
1973 break;
1974 case GL_FRAMEBUFFER_EXT:
1975 bindDrawBuf = GL_TRUE;
1976 bindReadBuf = GL_TRUE;
1977 break;
1978 default:
1979 _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
1980 return;
1981 }
1982
1983 if (framebuffer) {
1984 /* Binding a user-created framebuffer object */
1985 newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer);
1986 if (newDrawFb == &DummyFramebuffer) {
1987 /* ID was reserved, but no real framebuffer object made yet */
1988 newDrawFb = NULL;
1989 }
1990 else if (!newDrawFb && !allow_user_names) {
1991 /* All FBO IDs must be Gen'd */
1992 _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)");
1993 return;
1994 }
1995
1996 if (!newDrawFb) {
1997 /* create new framebuffer object */
1998 newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer);
1999 if (!newDrawFb) {
2000 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT");
2001 return;
2002 }
2003 _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb);
2004 }
2005 newReadFb = newDrawFb;
2006 }
2007 else {
2008 /* Binding the window system framebuffer (which was originally set
2009 * with MakeCurrent).
2010 */
2011 newDrawFb = ctx->WinSysDrawBuffer;
2012 newReadFb = ctx->WinSysReadBuffer;
2013 }
2014
2015 ASSERT(newDrawFb);
2016 ASSERT(newDrawFb != &DummyFramebuffer);
2017
2018 /* save pointers to current/old framebuffers */
2019 oldDrawFb = ctx->DrawBuffer;
2020 oldReadFb = ctx->ReadBuffer;
2021
2022 /* check if really changing bindings */
2023 if (oldDrawFb == newDrawFb)
2024 bindDrawBuf = GL_FALSE;
2025 if (oldReadFb == newReadFb)
2026 bindReadBuf = GL_FALSE;
2027
2028 /*
2029 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2030 *
2031 * We also check if we're beginning and/or ending render-to-texture.
2032 * When a framebuffer with texture attachments is unbound, call
2033 * ctx->Driver.FinishRenderTexture().
2034 * When a framebuffer with texture attachments is bound, call
2035 * ctx->Driver.RenderTexture().
2036 *
2037 * Note that if the ReadBuffer has texture attachments we don't consider
2038 * that a render-to-texture case.
2039 */
2040 if (bindReadBuf) {
2041 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2042
2043 /* check if old readbuffer was render-to-texture */
2044 check_end_texture_render(ctx, oldReadFb);
2045
2046 _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb);
2047 }
2048
2049 if (bindDrawBuf) {
2050 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2051
2052 /* check if old framebuffer had any texture attachments */
2053 if (oldDrawFb)
2054 check_end_texture_render(ctx, oldDrawFb);
2055
2056 /* check if newly bound framebuffer has any texture attachments */
2057 check_begin_texture_render(ctx, newDrawFb);
2058
2059 _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb);
2060 }
2061
2062 if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) {
2063 ctx->Driver.BindFramebuffer(ctx, target, newDrawFb, newReadFb);
2064 }
2065 }
2066
2067 void GLAPIENTRY
2068 _mesa_BindFramebuffer(GLenum target, GLuint framebuffer)
2069 {
2070 GET_CURRENT_CONTEXT(ctx);
2071
2072 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2073 * point, but they allow the use of user-generated names.
2074 */
2075 bind_framebuffer(target, framebuffer, _mesa_is_gles(ctx));
2076 }
2077
2078 void GLAPIENTRY
2079 _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
2080 {
2081 /* This function should not be in the dispatch table for core profile /
2082 * OpenGL 3.1, so execution should never get here in those cases -- no
2083 * need for an explicit test.
2084 */
2085 bind_framebuffer(target, framebuffer, true);
2086 }
2087
2088 void GLAPIENTRY
2089 _mesa_DeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
2090 {
2091 GLint i;
2092 GET_CURRENT_CONTEXT(ctx);
2093
2094 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2095
2096 for (i = 0; i < n; i++) {
2097 if (framebuffers[i] > 0) {
2098 struct gl_framebuffer *fb;
2099 fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]);
2100 if (fb) {
2101 ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]);
2102
2103 /* check if deleting currently bound framebuffer object */
2104 if (ctx->Extensions.EXT_framebuffer_blit) {
2105 /* separate draw/read binding points */
2106 if (fb == ctx->DrawBuffer) {
2107 /* bind default */
2108 ASSERT(fb->RefCount >= 2);
2109 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0);
2110 }
2111 if (fb == ctx->ReadBuffer) {
2112 /* bind default */
2113 ASSERT(fb->RefCount >= 2);
2114 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER_EXT, 0);
2115 }
2116 }
2117 else {
2118 /* only one binding point for read/draw buffers */
2119 if (fb == ctx->DrawBuffer || fb == ctx->ReadBuffer) {
2120 /* bind default */
2121 ASSERT(fb->RefCount >= 2);
2122 _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
2123 }
2124 }
2125
2126 /* remove from hash table immediately, to free the ID */
2127 _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]);
2128
2129 if (fb != &DummyFramebuffer) {
2130 /* But the object will not be freed until it's no longer
2131 * bound in any context.
2132 */
2133 _mesa_reference_framebuffer(&fb, NULL);
2134 }
2135 }
2136 }
2137 }
2138 }
2139
2140
2141 void GLAPIENTRY
2142 _mesa_GenFramebuffers(GLsizei n, GLuint *framebuffers)
2143 {
2144 GET_CURRENT_CONTEXT(ctx);
2145 GLuint first;
2146 GLint i;
2147
2148 if (n < 0) {
2149 _mesa_error(ctx, GL_INVALID_VALUE, "glGenFramebuffersEXT(n)");
2150 return;
2151 }
2152
2153 if (!framebuffers)
2154 return;
2155
2156 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n);
2157
2158 for (i = 0; i < n; i++) {
2159 GLuint name = first + i;
2160 framebuffers[i] = name;
2161 /* insert dummy placeholder into hash table */
2162 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
2163 _mesa_HashInsert(ctx->Shared->FrameBuffers, name, &DummyFramebuffer);
2164 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
2165 }
2166 }
2167
2168
2169
2170 GLenum GLAPIENTRY
2171 _mesa_CheckFramebufferStatus(GLenum target)
2172 {
2173 struct gl_framebuffer *buffer;
2174 GET_CURRENT_CONTEXT(ctx);
2175
2176 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
2177
2178 if (MESA_VERBOSE & VERBOSE_API)
2179 _mesa_debug(ctx, "glCheckFramebufferStatus(%s)\n",
2180 _mesa_lookup_enum_by_nr(target));
2181
2182 buffer = get_framebuffer_target(ctx, target);
2183 if (!buffer) {
2184 _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
2185 return 0;
2186 }
2187
2188 if (_mesa_is_winsys_fbo(buffer)) {
2189 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2190 if (buffer != &IncompleteFramebuffer) {
2191 return GL_FRAMEBUFFER_COMPLETE_EXT;
2192 } else {
2193 return GL_FRAMEBUFFER_UNDEFINED;
2194 }
2195 }
2196
2197 /* No need to flush here */
2198
2199 if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
2200 _mesa_test_framebuffer_completeness(ctx, buffer);
2201 }
2202
2203 return buffer->_Status;
2204 }
2205
2206
2207 /**
2208 * Replicate the src attachment point. Used by framebuffer_texture() when
2209 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2210 * GL_STENCIL_ATTACHMENT.
2211 */
2212 static void
2213 reuse_framebuffer_texture_attachment(struct gl_framebuffer *fb,
2214 gl_buffer_index dst,
2215 gl_buffer_index src)
2216 {
2217 struct gl_renderbuffer_attachment *dst_att = &fb->Attachment[dst];
2218 struct gl_renderbuffer_attachment *src_att = &fb->Attachment[src];
2219
2220 assert(src_att->Texture != NULL);
2221 assert(src_att->Renderbuffer != NULL);
2222
2223 _mesa_reference_texobj(&dst_att->Texture, src_att->Texture);
2224 _mesa_reference_renderbuffer(&dst_att->Renderbuffer, src_att->Renderbuffer);
2225 dst_att->Type = src_att->Type;
2226 dst_att->Complete = src_att->Complete;
2227 dst_att->TextureLevel = src_att->TextureLevel;
2228 dst_att->Zoffset = src_att->Zoffset;
2229 }
2230
2231
2232 /**
2233 * Common code called by glFramebufferTexture1D/2D/3DEXT() and
2234 * glFramebufferTextureLayerEXT().
2235 * Note: glFramebufferTextureLayerEXT() has no textarget parameter so we'll
2236 * get textarget=0 in that case.
2237 */
2238 static void
2239 framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
2240 GLenum attachment, GLenum textarget, GLuint texture,
2241 GLint level, GLint zoffset, GLboolean layered)
2242 {
2243 struct gl_renderbuffer_attachment *att;
2244 struct gl_texture_object *texObj = NULL;
2245 struct gl_framebuffer *fb;
2246 GLenum maxLevelsTarget;
2247
2248 fb = get_framebuffer_target(ctx, target);
2249 if (!fb) {
2250 _mesa_error(ctx, GL_INVALID_ENUM,
2251 "glFramebufferTexture%sEXT(target=0x%x)", caller, target);
2252 return;
2253 }
2254
2255 /* check framebuffer binding */
2256 if (_mesa_is_winsys_fbo(fb)) {
2257 _mesa_error(ctx, GL_INVALID_OPERATION,
2258 "glFramebufferTexture%sEXT", caller);
2259 return;
2260 }
2261
2262 /* The textarget, level, and zoffset parameters are only validated if
2263 * texture is non-zero.
2264 */
2265 if (texture) {
2266 GLboolean err = GL_TRUE;
2267
2268 texObj = _mesa_lookup_texture(ctx, texture);
2269 if (texObj != NULL) {
2270 if (textarget == 0) {
2271 /* If textarget == 0 it means we're being called by
2272 * glFramebufferTextureLayer() and textarget is not used.
2273 * The only legal texture types for that function are 3D and
2274 * 1D/2D arrays textures.
2275 */
2276 err = (texObj->Target != GL_TEXTURE_3D) &&
2277 (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT) &&
2278 (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT) &&
2279 (texObj->Target != GL_TEXTURE_CUBE_MAP_ARRAY) &&
2280 (texObj->Target != GL_TEXTURE_2D_MULTISAMPLE_ARRAY);
2281 }
2282 else {
2283 /* Make sure textarget is consistent with the texture's type */
2284 err = (texObj->Target == GL_TEXTURE_CUBE_MAP)
2285 ? !_mesa_is_cube_face(textarget)
2286 : (texObj->Target != textarget);
2287 }
2288 }
2289 else {
2290 /* can't render to a non-existant texture */
2291 _mesa_error(ctx, GL_INVALID_OPERATION,
2292 "glFramebufferTexture%sEXT(non existant texture)",
2293 caller);
2294 return;
2295 }
2296
2297 if (err) {
2298 _mesa_error(ctx, GL_INVALID_OPERATION,
2299 "glFramebufferTexture%sEXT(texture target mismatch)",
2300 caller);
2301 return;
2302 }
2303
2304 if (texObj->Target == GL_TEXTURE_3D) {
2305 const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
2306 if (zoffset < 0 || zoffset >= maxSize) {
2307 _mesa_error(ctx, GL_INVALID_VALUE,
2308 "glFramebufferTexture%sEXT(zoffset)", caller);
2309 return;
2310 }
2311 }
2312 else if ((texObj->Target == GL_TEXTURE_1D_ARRAY_EXT) ||
2313 (texObj->Target == GL_TEXTURE_2D_ARRAY_EXT) ||
2314 (texObj->Target == GL_TEXTURE_CUBE_MAP_ARRAY) ||
2315 (texObj->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)) {
2316 if (zoffset < 0 ||
2317 zoffset >= (GLint) ctx->Const.MaxArrayTextureLayers) {
2318 _mesa_error(ctx, GL_INVALID_VALUE,
2319 "glFramebufferTexture%sEXT(layer)", caller);
2320 return;
2321 }
2322 }
2323
2324 maxLevelsTarget = textarget ? textarget : texObj->Target;
2325 if ((level < 0) ||
2326 (level >= _mesa_max_texture_levels(ctx, maxLevelsTarget))) {
2327 _mesa_error(ctx, GL_INVALID_VALUE,
2328 "glFramebufferTexture%sEXT(level)", caller);
2329 return;
2330 }
2331 }
2332
2333 att = _mesa_get_attachment(ctx, fb, attachment);
2334 if (att == NULL) {
2335 _mesa_error(ctx, GL_INVALID_ENUM,
2336 "glFramebufferTexture%sEXT(attachment)", caller);
2337 return;
2338 }
2339
2340 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2341
2342 _glthread_LOCK_MUTEX(fb->Mutex);
2343 if (texObj) {
2344 if (attachment == GL_DEPTH_ATTACHMENT &&
2345 texObj == fb->Attachment[BUFFER_STENCIL].Texture &&
2346 level == fb->Attachment[BUFFER_STENCIL].TextureLevel &&
2347 _mesa_tex_target_to_face(textarget) ==
2348 fb->Attachment[BUFFER_STENCIL].CubeMapFace &&
2349 zoffset == fb->Attachment[BUFFER_STENCIL].Zoffset) {
2350 /* The texture object is already attached to the stencil attachment
2351 * point. Don't create a new renderbuffer; just reuse the stencil
2352 * attachment's. This is required to prevent a GL error in
2353 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
2354 */
2355 reuse_framebuffer_texture_attachment(fb, BUFFER_DEPTH,
2356 BUFFER_STENCIL);
2357 } else if (attachment == GL_STENCIL_ATTACHMENT &&
2358 texObj == fb->Attachment[BUFFER_DEPTH].Texture &&
2359 level == fb->Attachment[BUFFER_DEPTH].TextureLevel &&
2360 _mesa_tex_target_to_face(textarget) ==
2361 fb->Attachment[BUFFER_DEPTH].CubeMapFace &&
2362 zoffset == fb->Attachment[BUFFER_DEPTH].Zoffset) {
2363 /* As above, but with depth and stencil transposed. */
2364 reuse_framebuffer_texture_attachment(fb, BUFFER_STENCIL,
2365 BUFFER_DEPTH);
2366 } else {
2367 _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget,
2368 level, zoffset, layered);
2369 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
2370 /* Above we created a new renderbuffer and attached it to the
2371 * depth attachment point. Now attach it to the stencil attachment
2372 * point too.
2373 */
2374 assert(att == &fb->Attachment[BUFFER_DEPTH]);
2375 reuse_framebuffer_texture_attachment(fb,BUFFER_STENCIL,
2376 BUFFER_DEPTH);
2377 }
2378 }
2379
2380 /* Set the render-to-texture flag. We'll check this flag in
2381 * glTexImage() and friends to determine if we need to revalidate
2382 * any FBOs that might be rendering into this texture.
2383 * This flag never gets cleared since it's non-trivial to determine
2384 * when all FBOs might be done rendering to this texture. That's OK
2385 * though since it's uncommon to render to a texture then repeatedly
2386 * call glTexImage() to change images in the texture.
2387 */
2388 texObj->_RenderToTexture = GL_TRUE;
2389 }
2390 else {
2391 _mesa_remove_attachment(ctx, att);
2392 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
2393 assert(att == &fb->Attachment[BUFFER_DEPTH]);
2394 _mesa_remove_attachment(ctx, &fb->Attachment[BUFFER_STENCIL]);
2395 }
2396 }
2397
2398 invalidate_framebuffer(fb);
2399
2400 _glthread_UNLOCK_MUTEX(fb->Mutex);
2401 }
2402
2403
2404
2405 void GLAPIENTRY
2406 _mesa_FramebufferTexture1D(GLenum target, GLenum attachment,
2407 GLenum textarget, GLuint texture, GLint level)
2408 {
2409 GET_CURRENT_CONTEXT(ctx);
2410
2411 if (texture != 0) {
2412 GLboolean error;
2413
2414 switch (textarget) {
2415 case GL_TEXTURE_1D:
2416 error = GL_FALSE;
2417 break;
2418 case GL_TEXTURE_1D_ARRAY:
2419 error = !ctx->Extensions.EXT_texture_array;
2420 break;
2421 default:
2422 error = GL_TRUE;
2423 }
2424
2425 if (error) {
2426 _mesa_error(ctx, GL_INVALID_OPERATION,
2427 "glFramebufferTexture1DEXT(textarget=%s)",
2428 _mesa_lookup_enum_by_nr(textarget));
2429 return;
2430 }
2431 }
2432
2433 framebuffer_texture(ctx, "1D", target, attachment, textarget, texture,
2434 level, 0, GL_FALSE);
2435 }
2436
2437
2438 void GLAPIENTRY
2439 _mesa_FramebufferTexture2D(GLenum target, GLenum attachment,
2440 GLenum textarget, GLuint texture, GLint level)
2441 {
2442 GET_CURRENT_CONTEXT(ctx);
2443
2444 if (texture != 0) {
2445 GLboolean error;
2446
2447 switch (textarget) {
2448 case GL_TEXTURE_2D:
2449 error = GL_FALSE;
2450 break;
2451 case GL_TEXTURE_RECTANGLE:
2452 error = _mesa_is_gles(ctx)
2453 || !ctx->Extensions.NV_texture_rectangle;
2454 break;
2455 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
2456 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
2457 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
2458 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
2459 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
2460 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
2461 error = !ctx->Extensions.ARB_texture_cube_map;
2462 break;
2463 case GL_TEXTURE_2D_ARRAY:
2464 error = (_mesa_is_gles(ctx) && ctx->Version < 30)
2465 || !ctx->Extensions.EXT_texture_array;
2466 break;
2467 case GL_TEXTURE_2D_MULTISAMPLE:
2468 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
2469 error = _mesa_is_gles(ctx)
2470 || !ctx->Extensions.ARB_texture_multisample;
2471 break;
2472 default:
2473 error = GL_TRUE;
2474 }
2475
2476 if (error) {
2477 _mesa_error(ctx, GL_INVALID_OPERATION,
2478 "glFramebufferTexture2DEXT(textarget=%s)",
2479 _mesa_lookup_enum_by_nr(textarget));
2480 return;
2481 }
2482 }
2483
2484 framebuffer_texture(ctx, "2D", target, attachment, textarget, texture,
2485 level, 0, GL_FALSE);
2486 }
2487
2488
2489 void GLAPIENTRY
2490 _mesa_FramebufferTexture3D(GLenum target, GLenum attachment,
2491 GLenum textarget, GLuint texture,
2492 GLint level, GLint zoffset)
2493 {
2494 GET_CURRENT_CONTEXT(ctx);
2495
2496 if ((texture != 0) && (textarget != GL_TEXTURE_3D)) {
2497 _mesa_error(ctx, GL_INVALID_OPERATION,
2498 "glFramebufferTexture3DEXT(textarget)");
2499 return;
2500 }
2501
2502 framebuffer_texture(ctx, "3D", target, attachment, textarget, texture,
2503 level, zoffset, GL_FALSE);
2504 }
2505
2506
2507 void GLAPIENTRY
2508 _mesa_FramebufferTextureLayer(GLenum target, GLenum attachment,
2509 GLuint texture, GLint level, GLint layer)
2510 {
2511 GET_CURRENT_CONTEXT(ctx);
2512
2513 framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
2514 level, layer, GL_FALSE);
2515 }
2516
2517
2518 void GLAPIENTRY
2519 _mesa_FramebufferTexture(GLenum target, GLenum attachment,
2520 GLuint texture, GLint level)
2521 {
2522 GET_CURRENT_CONTEXT(ctx);
2523
2524 if (_mesa_has_geometry_shaders(ctx)) {
2525 framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
2526 level, 0, GL_TRUE);
2527 } else {
2528 _mesa_error(ctx, GL_INVALID_OPERATION,
2529 "unsupported function (glFramebufferTexture) called");
2530 }
2531 }
2532
2533
2534 void GLAPIENTRY
2535 _mesa_FramebufferRenderbuffer(GLenum target, GLenum attachment,
2536 GLenum renderbufferTarget,
2537 GLuint renderbuffer)
2538 {
2539 struct gl_renderbuffer_attachment *att;
2540 struct gl_framebuffer *fb;
2541 struct gl_renderbuffer *rb;
2542 GET_CURRENT_CONTEXT(ctx);
2543
2544 fb = get_framebuffer_target(ctx, target);
2545 if (!fb) {
2546 _mesa_error(ctx, GL_INVALID_ENUM, "glFramebufferRenderbufferEXT(target)");
2547 return;
2548 }
2549
2550 if (renderbufferTarget != GL_RENDERBUFFER_EXT) {
2551 _mesa_error(ctx, GL_INVALID_ENUM,
2552 "glFramebufferRenderbufferEXT(renderbufferTarget)");
2553 return;
2554 }
2555
2556 if (_mesa_is_winsys_fbo(fb)) {
2557 /* Can't attach new renderbuffers to a window system framebuffer */
2558 _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT");
2559 return;
2560 }
2561
2562 att = _mesa_get_attachment(ctx, fb, attachment);
2563 if (att == NULL) {
2564 _mesa_error(ctx, GL_INVALID_ENUM,
2565 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2566 _mesa_lookup_enum_by_nr(attachment));
2567 return;
2568 }
2569
2570 if (renderbuffer) {
2571 rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
2572 if (!rb) {
2573 _mesa_error(ctx, GL_INVALID_OPERATION,
2574 "glFramebufferRenderbufferEXT(non-existant"
2575 " renderbuffer %u)", renderbuffer);
2576 return;
2577 }
2578 else if (rb == &DummyRenderbuffer) {
2579 /* This is what NVIDIA does */
2580 _mesa_error(ctx, GL_INVALID_VALUE,
2581 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2582 renderbuffer);
2583 return;
2584 }
2585 }
2586 else {
2587 /* remove renderbuffer attachment */
2588 rb = NULL;
2589 }
2590
2591 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT &&
2592 rb && rb->Format != MESA_FORMAT_NONE) {
2593 /* make sure the renderbuffer is a depth/stencil format */
2594 const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
2595 if (baseFormat != GL_DEPTH_STENCIL) {
2596 _mesa_error(ctx, GL_INVALID_OPERATION,
2597 "glFramebufferRenderbufferEXT(renderbuffer"
2598 " is not DEPTH_STENCIL format)");
2599 return;
2600 }
2601 }
2602
2603
2604 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2605
2606 assert(ctx->Driver.FramebufferRenderbuffer);
2607 ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb);
2608
2609 /* Some subsequent GL commands may depend on the framebuffer's visual
2610 * after the binding is updated. Update visual info now.
2611 */
2612 _mesa_update_framebuffer_visual(ctx, fb);
2613 }
2614
2615
2616 void GLAPIENTRY
2617 _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
2618 GLenum pname, GLint *params)
2619 {
2620 const struct gl_renderbuffer_attachment *att;
2621 struct gl_framebuffer *buffer;
2622 GLenum err;
2623 GET_CURRENT_CONTEXT(ctx);
2624
2625 /* The error differs in GL and GLES. */
2626 err = _mesa_is_desktop_gl(ctx) ? GL_INVALID_OPERATION : GL_INVALID_ENUM;
2627
2628 buffer = get_framebuffer_target(ctx, target);
2629 if (!buffer) {
2630 _mesa_error(ctx, GL_INVALID_ENUM,
2631 "glGetFramebufferAttachmentParameterivEXT(target)");
2632 return;
2633 }
2634
2635 if (_mesa_is_winsys_fbo(buffer)) {
2636 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
2637 * says:
2638 *
2639 * "If the framebuffer currently bound to target is zero, then
2640 * INVALID_OPERATION is generated."
2641 *
2642 * The EXT_framebuffer_object spec has the same wording, and the
2643 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
2644 * spec.
2645 */
2646 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_framebuffer_object)
2647 && !_mesa_is_gles3(ctx)) {
2648 _mesa_error(ctx, GL_INVALID_OPERATION,
2649 "glGetFramebufferAttachmentParameteriv(bound FBO = 0)");
2650 return;
2651 }
2652
2653 if (_mesa_is_gles3(ctx) && attachment != GL_BACK &&
2654 attachment != GL_DEPTH && attachment != GL_STENCIL) {
2655 _mesa_error(ctx, GL_INVALID_OPERATION,
2656 "glGetFramebufferAttachmentParameteriv(attachment)");
2657 return;
2658 }
2659 /* the default / window-system FBO */
2660 att = _mesa_get_fb0_attachment(ctx, buffer, attachment);
2661 }
2662 else {
2663 /* user-created framebuffer FBO */
2664 att = _mesa_get_attachment(ctx, buffer, attachment);
2665 }
2666
2667 if (att == NULL) {
2668 _mesa_error(ctx, GL_INVALID_ENUM,
2669 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2670 return;
2671 }
2672
2673 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
2674 /* the depth and stencil attachments must point to the same buffer */
2675 const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt;
2676 depthAtt = _mesa_get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT);
2677 stencilAtt = _mesa_get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT);
2678 if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) {
2679 _mesa_error(ctx, GL_INVALID_OPERATION,
2680 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2681 " attachments differ)");
2682 return;
2683 }
2684 }
2685
2686 /* No need to flush here */
2687
2688 switch (pname) {
2689 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT:
2690 *params = _mesa_is_winsys_fbo(buffer)
2691 ? GL_FRAMEBUFFER_DEFAULT : att->Type;
2692 return;
2693 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT:
2694 if (att->Type == GL_RENDERBUFFER_EXT) {
2695 *params = att->Renderbuffer->Name;
2696 }
2697 else if (att->Type == GL_TEXTURE) {
2698 *params = att->Texture->Name;
2699 }
2700 else {
2701 assert(att->Type == GL_NONE);
2702 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) {
2703 *params = 0;
2704 } else {
2705 goto invalid_pname_enum;
2706 }
2707 }
2708 return;
2709 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT:
2710 if (att->Type == GL_TEXTURE) {
2711 *params = att->TextureLevel;
2712 }
2713 else if (att->Type == GL_NONE) {
2714 _mesa_error(ctx, err,
2715 "glGetFramebufferAttachmentParameterivEXT(pname)");
2716 }
2717 else {
2718 goto invalid_pname_enum;
2719 }
2720 return;
2721 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT:
2722 if (att->Type == GL_TEXTURE) {
2723 if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) {
2724 *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace;
2725 }
2726 else {
2727 *params = 0;
2728 }
2729 }
2730 else if (att->Type == GL_NONE) {
2731 _mesa_error(ctx, err,
2732 "glGetFramebufferAttachmentParameterivEXT(pname)");
2733 }
2734 else {
2735 goto invalid_pname_enum;
2736 }
2737 return;
2738 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT:
2739 if (ctx->API == API_OPENGLES) {
2740 goto invalid_pname_enum;
2741 } else if (att->Type == GL_NONE) {
2742 _mesa_error(ctx, err,
2743 "glGetFramebufferAttachmentParameterivEXT(pname)");
2744 } else if (att->Type == GL_TEXTURE) {
2745 if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) {
2746 *params = att->Zoffset;
2747 }
2748 else {
2749 *params = 0;
2750 }
2751 }
2752 else {
2753 goto invalid_pname_enum;
2754 }
2755 return;
2756 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2757 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_framebuffer_object)
2758 && !_mesa_is_gles3(ctx)) {
2759 goto invalid_pname_enum;
2760 }
2761 else if (att->Type == GL_NONE) {
2762 _mesa_error(ctx, err,
2763 "glGetFramebufferAttachmentParameterivEXT(pname)");
2764 }
2765 else {
2766 if (ctx->Extensions.EXT_framebuffer_sRGB) {
2767 *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format);
2768 }
2769 else {
2770 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2771 * if the sRGB conversion is unsupported. */
2772 *params = GL_LINEAR;
2773 }
2774 }
2775 return;
2776 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2777 if ((ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_framebuffer_object)
2778 && ctx->API != API_OPENGL_CORE
2779 && !_mesa_is_gles3(ctx)) {
2780 goto invalid_pname_enum;
2781 }
2782 else if (att->Type == GL_NONE) {
2783 _mesa_error(ctx, err,
2784 "glGetFramebufferAttachmentParameterivEXT(pname)");
2785 }
2786 else {
2787 gl_format format = att->Renderbuffer->Format;
2788
2789 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
2790 * 3.0.1 spec says:
2791 *
2792 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
2793 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
2794 * generate an INVALID_OPERATION error.
2795 */
2796 if (_mesa_is_gles3(ctx) && attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
2797 _mesa_error(ctx, GL_INVALID_OPERATION,
2798 "glGetFramebufferAttachmentParameteriv(cannot query "
2799 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
2800 "GL_DEPTH_STENCIL_ATTACHMENT");
2801 return;
2802 }
2803
2804 if (format == MESA_FORMAT_S8) {
2805 /* special cases */
2806 *params = GL_INDEX;
2807 }
2808 else if (format == MESA_FORMAT_Z32_FLOAT_X24S8) {
2809 /* depends on the attachment parameter */
2810 if (attachment == GL_STENCIL_ATTACHMENT) {
2811 *params = GL_INDEX;
2812 }
2813 else {
2814 *params = GL_FLOAT;
2815 }
2816 }
2817 else {
2818 *params = _mesa_get_format_datatype(format);
2819 }
2820 }
2821 return;
2822 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2823 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2824 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2825 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2826 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2827 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2828 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_framebuffer_object)
2829 && !_mesa_is_gles3(ctx)) {
2830 goto invalid_pname_enum;
2831 }
2832 else if (att->Type == GL_NONE) {
2833 _mesa_error(ctx, err,
2834 "glGetFramebufferAttachmentParameterivEXT(pname)");
2835 }
2836 else if (att->Texture) {
2837 const struct gl_texture_image *texImage =
2838 _mesa_select_tex_image(ctx, att->Texture, att->Texture->Target,
2839 att->TextureLevel);
2840 if (texImage) {
2841 *params = get_component_bits(pname, texImage->_BaseFormat,
2842 texImage->TexFormat);
2843 }
2844 else {
2845 *params = 0;
2846 }
2847 }
2848 else if (att->Renderbuffer) {
2849 *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat,
2850 att->Renderbuffer->Format);
2851 }
2852 else {
2853 _mesa_problem(ctx, "glGetFramebufferAttachmentParameterivEXT:"
2854 " invalid FBO attachment structure");
2855 }
2856 return;
2857 default:
2858 goto invalid_pname_enum;
2859 }
2860
2861 return;
2862
2863 invalid_pname_enum:
2864 _mesa_error(ctx, GL_INVALID_ENUM,
2865 "glGetFramebufferAttachmentParameteriv(pname)");
2866 return;
2867 }
2868
2869
2870 void GLAPIENTRY
2871 _mesa_GenerateMipmap(GLenum target)
2872 {
2873 struct gl_texture_image *srcImage;
2874 struct gl_texture_object *texObj;
2875 GLboolean error;
2876
2877 GET_CURRENT_CONTEXT(ctx);
2878
2879 FLUSH_VERTICES(ctx, 0);
2880
2881 switch (target) {
2882 case GL_TEXTURE_1D:
2883 error = _mesa_is_gles(ctx);
2884 break;
2885 case GL_TEXTURE_2D:
2886 error = GL_FALSE;
2887 break;
2888 case GL_TEXTURE_3D:
2889 error = ctx->API == API_OPENGLES;
2890 break;
2891 case GL_TEXTURE_CUBE_MAP:
2892 error = !ctx->Extensions.ARB_texture_cube_map;
2893 break;
2894 case GL_TEXTURE_1D_ARRAY:
2895 error = _mesa_is_gles(ctx) || !ctx->Extensions.EXT_texture_array;
2896 break;
2897 case GL_TEXTURE_2D_ARRAY:
2898 error = (_mesa_is_gles(ctx) && ctx->Version < 30)
2899 || !ctx->Extensions.EXT_texture_array;
2900 break;
2901 default:
2902 error = GL_TRUE;
2903 }
2904
2905 if (error) {
2906 _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target=%s)",
2907 _mesa_lookup_enum_by_nr(target));
2908 return;
2909 }
2910
2911 texObj = _mesa_get_current_tex_object(ctx, target);
2912
2913 if (texObj->BaseLevel >= texObj->MaxLevel) {
2914 /* nothing to do */
2915 return;
2916 }
2917
2918 if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
2919 !_mesa_cube_complete(texObj)) {
2920 _mesa_error(ctx, GL_INVALID_OPERATION,
2921 "glGenerateMipmap(incomplete cube map)");
2922 return;
2923 }
2924
2925 _mesa_lock_texture(ctx, texObj);
2926
2927 srcImage = _mesa_select_tex_image(ctx, texObj, target, texObj->BaseLevel);
2928 if (!srcImage) {
2929 _mesa_unlock_texture(ctx, texObj);
2930 _mesa_error(ctx, GL_INVALID_OPERATION,
2931 "glGenerateMipmap(zero size base image)");
2932 return;
2933 }
2934
2935 if (_mesa_is_enum_format_integer(srcImage->InternalFormat) ||
2936 _mesa_is_depthstencil_format(srcImage->InternalFormat) ||
2937 _mesa_is_stencil_format(srcImage->InternalFormat)) {
2938 _mesa_unlock_texture(ctx, texObj);
2939 _mesa_error(ctx, GL_INVALID_OPERATION,
2940 "glGenerateMipmap(invalid internal format)");
2941 return;
2942 }
2943
2944 if (target == GL_TEXTURE_CUBE_MAP) {
2945 GLuint face;
2946 for (face = 0; face < 6; face++)
2947 ctx->Driver.GenerateMipmap(ctx,
2948 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face,
2949 texObj);
2950 }
2951 else {
2952 ctx->Driver.GenerateMipmap(ctx, target, texObj);
2953 }
2954 _mesa_unlock_texture(ctx, texObj);
2955 }
2956
2957
2958 static const struct gl_renderbuffer_attachment *
2959 find_attachment(const struct gl_framebuffer *fb,
2960 const struct gl_renderbuffer *rb)
2961 {
2962 GLuint i;
2963 for (i = 0; i < Elements(fb->Attachment); i++) {
2964 if (fb->Attachment[i].Renderbuffer == rb)
2965 return &fb->Attachment[i];
2966 }
2967 return NULL;
2968 }
2969
2970
2971 /**
2972 * Helper function for checking if the datatypes of color buffers are
2973 * compatible for glBlitFramebuffer. From the 3.1 spec, page 198:
2974 *
2975 * "GL_INVALID_OPERATION is generated if mask contains GL_COLOR_BUFFER_BIT
2976 * and any of the following conditions hold:
2977 * - The read buffer contains fixed-point or floating-point values and any
2978 * draw buffer contains neither fixed-point nor floating-point values.
2979 * - The read buffer contains unsigned integer values and any draw buffer
2980 * does not contain unsigned integer values.
2981 * - The read buffer contains signed integer values and any draw buffer
2982 * does not contain signed integer values."
2983 */
2984 static GLboolean
2985 compatible_color_datatypes(gl_format srcFormat, gl_format dstFormat)
2986 {
2987 GLenum srcType = _mesa_get_format_datatype(srcFormat);
2988 GLenum dstType = _mesa_get_format_datatype(dstFormat);
2989
2990 if (srcType != GL_INT && srcType != GL_UNSIGNED_INT) {
2991 assert(srcType == GL_UNSIGNED_NORMALIZED ||
2992 srcType == GL_SIGNED_NORMALIZED ||
2993 srcType == GL_FLOAT);
2994 /* Boil any of those types down to GL_FLOAT */
2995 srcType = GL_FLOAT;
2996 }
2997
2998 if (dstType != GL_INT && dstType != GL_UNSIGNED_INT) {
2999 assert(dstType == GL_UNSIGNED_NORMALIZED ||
3000 dstType == GL_SIGNED_NORMALIZED ||
3001 dstType == GL_FLOAT);
3002 /* Boil any of those types down to GL_FLOAT */
3003 dstType = GL_FLOAT;
3004 }
3005
3006 return srcType == dstType;
3007 }
3008
3009
3010 static GLboolean
3011 compatible_resolve_formats(const struct gl_renderbuffer *readRb,
3012 const struct gl_renderbuffer *drawRb)
3013 {
3014 GLenum readFormat, drawFormat;
3015
3016 /* The simple case where we know the backing Mesa formats are the same.
3017 */
3018 if (_mesa_get_srgb_format_linear(readRb->Format) ==
3019 _mesa_get_srgb_format_linear(drawRb->Format)) {
3020 return GL_TRUE;
3021 }
3022
3023 /* The Mesa formats are different, so we must check whether the internal
3024 * formats are compatible.
3025 *
3026 * Under some circumstances, the user may request e.g. two GL_RGBA8
3027 * textures and get two entirely different Mesa formats like RGBA8888 and
3028 * ARGB8888. Drivers behaving like that should be able to cope with
3029 * non-matching formats by themselves, because it's not the user's fault.
3030 *
3031 * Blits between linear and sRGB formats are also allowed.
3032 */
3033 readFormat = _mesa_get_nongeneric_internalformat(readRb->InternalFormat);
3034 drawFormat = _mesa_get_nongeneric_internalformat(drawRb->InternalFormat);
3035 readFormat = _mesa_get_linear_internalformat(readFormat);
3036 drawFormat = _mesa_get_linear_internalformat(drawFormat);
3037
3038 if (readFormat == drawFormat) {
3039 return GL_TRUE;
3040 }
3041
3042 return GL_FALSE;
3043 }
3044
3045 static GLboolean
3046 is_valid_blit_filter(const struct gl_context *ctx, GLenum filter)
3047 {
3048 switch (filter) {
3049 case GL_NEAREST:
3050 case GL_LINEAR:
3051 return true;
3052 case GL_SCALED_RESOLVE_FASTEST_EXT:
3053 case GL_SCALED_RESOLVE_NICEST_EXT:
3054 return ctx->Extensions.EXT_framebuffer_multisample_blit_scaled;
3055 default:
3056 return false;
3057 }
3058 }
3059
3060 /**
3061 * Blit rectangular region, optionally from one framebuffer to another.
3062 *
3063 * Note, if the src buffer is multisampled and the dest is not, this is
3064 * when the samples must be resolved to a single color.
3065 */
3066 void GLAPIENTRY
3067 _mesa_BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
3068 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
3069 GLbitfield mask, GLenum filter)
3070 {
3071 const GLbitfield legalMaskBits = (GL_COLOR_BUFFER_BIT |
3072 GL_DEPTH_BUFFER_BIT |
3073 GL_STENCIL_BUFFER_BIT);
3074 const struct gl_framebuffer *readFb, *drawFb;
3075 GET_CURRENT_CONTEXT(ctx);
3076
3077 FLUSH_VERTICES(ctx, 0);
3078
3079 if (MESA_VERBOSE & VERBOSE_API)
3080 _mesa_debug(ctx,
3081 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
3082 srcX0, srcY0, srcX1, srcY1,
3083 dstX0, dstY0, dstX1, dstY1,
3084 mask, _mesa_lookup_enum_by_nr(filter));
3085
3086 if (ctx->NewState) {
3087 _mesa_update_state(ctx);
3088 }
3089
3090 readFb = ctx->ReadBuffer;
3091 drawFb = ctx->DrawBuffer;
3092
3093 if (!readFb || !drawFb) {
3094 /* This will normally never happen but someday we may want to
3095 * support MakeCurrent() with no drawables.
3096 */
3097 return;
3098 }
3099
3100 /* check for complete framebuffers */
3101 if (drawFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
3102 readFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
3103 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
3104 "glBlitFramebufferEXT(incomplete draw/read buffers)");
3105 return;
3106 }
3107
3108 if (!is_valid_blit_filter(ctx, filter)) {
3109 _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(%s)",
3110 _mesa_lookup_enum_by_nr(filter));
3111 return;
3112 }
3113
3114 if ((filter == GL_SCALED_RESOLVE_FASTEST_EXT ||
3115 filter == GL_SCALED_RESOLVE_NICEST_EXT) &&
3116 (readFb->Visual.samples == 0 || drawFb->Visual.samples > 0)) {
3117 _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT(%s)",
3118 _mesa_lookup_enum_by_nr(filter));
3119 return;
3120 }
3121
3122 if (mask & ~legalMaskBits) {
3123 _mesa_error( ctx, GL_INVALID_VALUE, "glBlitFramebufferEXT(mask)");
3124 return;
3125 }
3126
3127 /* depth/stencil must be blitted with nearest filtering */
3128 if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
3129 && filter != GL_NEAREST) {
3130 _mesa_error(ctx, GL_INVALID_OPERATION,
3131 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
3132 return;
3133 }
3134
3135 /* get color read/draw renderbuffers */
3136 if (mask & GL_COLOR_BUFFER_BIT) {
3137 const GLuint numColorDrawBuffers = ctx->DrawBuffer->_NumColorDrawBuffers;
3138 const struct gl_renderbuffer *colorReadRb = readFb->_ColorReadBuffer;
3139 const struct gl_renderbuffer *colorDrawRb = NULL;
3140 GLuint i;
3141
3142 /* From the EXT_framebuffer_object spec:
3143 *
3144 * "If a buffer is specified in <mask> and does not exist in both
3145 * the read and draw framebuffers, the corresponding bit is silently
3146 * ignored."
3147 */
3148 if (!colorReadRb || numColorDrawBuffers == 0) {
3149 mask &= ~GL_COLOR_BUFFER_BIT;
3150 }
3151 else {
3152 for (i = 0; i < numColorDrawBuffers; i++) {
3153 colorDrawRb = ctx->DrawBuffer->_ColorDrawBuffers[i];
3154 if (!colorDrawRb)
3155 continue;
3156
3157 /* Page 193 (page 205 of the PDF) in section 4.3.2 of the OpenGL
3158 * ES 3.0.1 spec says:
3159 *
3160 * "If the source and destination buffers are identical, an
3161 * INVALID_OPERATION error is generated. Different mipmap
3162 * levels of a texture, different layers of a three-
3163 * dimensional texture or two-dimensional array texture, and
3164 * different faces of a cube map texture do not constitute
3165 * identical buffers."
3166 */
3167 if (_mesa_is_gles3(ctx) && (colorDrawRb == colorReadRb)) {
3168 _mesa_error(ctx, GL_INVALID_OPERATION,
3169 "glBlitFramebuffer(source and destination color "
3170 "buffer cannot be the same)");
3171 return;
3172 }
3173
3174 if (!compatible_color_datatypes(colorReadRb->Format,
3175 colorDrawRb->Format)) {
3176 _mesa_error(ctx, GL_INVALID_OPERATION,
3177 "glBlitFramebufferEXT(color buffer datatypes mismatch)");
3178 return;
3179 }
3180 /* extra checks for multisample copies... */
3181 if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) {
3182 /* color formats must match */
3183 if (!compatible_resolve_formats(colorReadRb, colorDrawRb)) {
3184 _mesa_error(ctx, GL_INVALID_OPERATION,
3185 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
3186 return;
3187 }
3188 }
3189 }
3190 if (filter != GL_NEAREST) {
3191 /* From EXT_framebuffer_multisample_blit_scaled specification:
3192 * "Calling BlitFramebuffer will result in an INVALID_OPERATION error
3193 * if filter is not NEAREST and read buffer contains integer data."
3194 */
3195 GLenum type = _mesa_get_format_datatype(colorReadRb->Format);
3196 if (type == GL_INT || type == GL_UNSIGNED_INT) {
3197 _mesa_error(ctx, GL_INVALID_OPERATION,
3198 "glBlitFramebufferEXT(integer color type)");
3199 return;
3200 }
3201 }
3202 }
3203 }
3204
3205 if (mask & GL_STENCIL_BUFFER_BIT) {
3206 struct gl_renderbuffer *readRb =
3207 readFb->Attachment[BUFFER_STENCIL].Renderbuffer;
3208 struct gl_renderbuffer *drawRb =
3209 drawFb->Attachment[BUFFER_STENCIL].Renderbuffer;
3210
3211 /* From the EXT_framebuffer_object spec:
3212 *
3213 * "If a buffer is specified in <mask> and does not exist in both
3214 * the read and draw framebuffers, the corresponding bit is silently
3215 * ignored."
3216 */
3217 if ((readRb == NULL) || (drawRb == NULL)) {
3218 mask &= ~GL_STENCIL_BUFFER_BIT;
3219 }
3220 else {
3221 int read_z_bits, draw_z_bits;
3222
3223 if (_mesa_is_gles3(ctx) && (drawRb == readRb)) {
3224 _mesa_error(ctx, GL_INVALID_OPERATION,
3225 "glBlitFramebuffer(source and destination stencil "
3226 "buffer cannot be the same)");
3227 return;
3228 }
3229
3230 if (_mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) !=
3231 _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) {
3232 /* There is no need to check the stencil datatype here, because
3233 * there is only one: GL_UNSIGNED_INT.
3234 */
3235 _mesa_error(ctx, GL_INVALID_OPERATION,
3236 "glBlitFramebuffer(stencil attachment format mismatch)");
3237 return;
3238 }
3239
3240 read_z_bits = _mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS);
3241 draw_z_bits = _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS);
3242
3243 /* If both buffers also have depth data, the depth formats must match
3244 * as well. If one doesn't have depth, it's not blitted, so we should
3245 * ignore the depth format check.
3246 */
3247 if (read_z_bits > 0 && draw_z_bits > 0 &&
3248 (read_z_bits != draw_z_bits ||
3249 _mesa_get_format_datatype(readRb->Format) !=
3250 _mesa_get_format_datatype(drawRb->Format))) {
3251
3252 _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebuffer"
3253 "(stencil attachment depth format mismatch)");
3254 return;
3255 }
3256 }
3257 }
3258
3259 if (mask & GL_DEPTH_BUFFER_BIT) {
3260 struct gl_renderbuffer *readRb =
3261 readFb->Attachment[BUFFER_DEPTH].Renderbuffer;
3262 struct gl_renderbuffer *drawRb =
3263 drawFb->Attachment[BUFFER_DEPTH].Renderbuffer;
3264
3265 /* From the EXT_framebuffer_object spec:
3266 *
3267 * "If a buffer is specified in <mask> and does not exist in both
3268 * the read and draw framebuffers, the corresponding bit is silently
3269 * ignored."
3270 */
3271 if ((readRb == NULL) || (drawRb == NULL)) {
3272 mask &= ~GL_DEPTH_BUFFER_BIT;
3273 }
3274 else {
3275 int read_s_bit, draw_s_bit;
3276
3277 if (_mesa_is_gles3(ctx) && (drawRb == readRb)) {
3278 _mesa_error(ctx, GL_INVALID_OPERATION,
3279 "glBlitFramebuffer(source and destination depth "
3280 "buffer cannot be the same)");
3281 return;
3282 }
3283
3284 if ((_mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) !=
3285 _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) ||
3286 (_mesa_get_format_datatype(readRb->Format) !=
3287 _mesa_get_format_datatype(drawRb->Format))) {
3288 _mesa_error(ctx, GL_INVALID_OPERATION,
3289 "glBlitFramebuffer(depth attachment format mismatch)");
3290 return;
3291 }
3292
3293 read_s_bit = _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS);
3294 draw_s_bit = _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS);
3295
3296 /* If both buffers also have stencil data, the stencil formats must
3297 * match as well. If one doesn't have stencil, it's not blitted, so
3298 * we should ignore the stencil format check.
3299 */
3300 if (read_s_bit > 0 && draw_s_bit > 0 && read_s_bit != draw_s_bit) {
3301 _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebuffer"
3302 "(depth attachment stencil bits mismatch)");
3303 return;
3304 }
3305 }
3306 }
3307
3308
3309 if (_mesa_is_gles3(ctx)) {
3310 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3311 * 3.0.1 spec says:
3312 *
3313 * "If SAMPLE_BUFFERS for the draw framebuffer is greater than zero,
3314 * an INVALID_OPERATION error is generated."
3315 */
3316 if (drawFb->Visual.samples > 0) {
3317 _mesa_error(ctx, GL_INVALID_OPERATION,
3318 "glBlitFramebuffer(destination samples must be 0)");
3319 return;
3320 }
3321
3322 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3323 * 3.0.1 spec says:
3324 *
3325 * "If SAMPLE_BUFFERS for the read framebuffer is greater than zero,
3326 * no copy is performed and an INVALID_OPERATION error is generated
3327 * if the formats of the read and draw framebuffers are not
3328 * identical or if the source and destination rectangles are not
3329 * defined with the same (X0, Y0) and (X1, Y1) bounds."
3330 *
3331 * The format check was made above because desktop OpenGL has the same
3332 * requirement.
3333 */
3334 if (readFb->Visual.samples > 0
3335 && (srcX0 != dstX0 || srcY0 != dstY0
3336 || srcX1 != dstX1 || srcY1 != dstY1)) {
3337 _mesa_error(ctx, GL_INVALID_OPERATION,
3338 "glBlitFramebuffer(bad src/dst multisample region)");
3339 return;
3340 }
3341 } else {
3342 if (readFb->Visual.samples > 0 &&
3343 drawFb->Visual.samples > 0 &&
3344 readFb->Visual.samples != drawFb->Visual.samples) {
3345 _mesa_error(ctx, GL_INVALID_OPERATION,
3346 "glBlitFramebufferEXT(mismatched samples)");
3347 return;
3348 }
3349
3350 /* extra checks for multisample copies... */
3351 if ((readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) &&
3352 (filter == GL_NEAREST || filter == GL_LINEAR)) {
3353 /* src and dest region sizes must be the same */
3354 if (abs(srcX1 - srcX0) != abs(dstX1 - dstX0) ||
3355 abs(srcY1 - srcY0) != abs(dstY1 - dstY0)) {
3356 _mesa_error(ctx, GL_INVALID_OPERATION,
3357 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
3358 return;
3359 }
3360 }
3361 }
3362
3363 if (!ctx->Extensions.EXT_framebuffer_blit) {
3364 _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT");
3365 return;
3366 }
3367
3368 /* Debug code */
3369 if (DEBUG_BLIT) {
3370 const struct gl_renderbuffer *colorReadRb = readFb->_ColorReadBuffer;
3371 const struct gl_renderbuffer *colorDrawRb = NULL;
3372 GLuint i = 0;
3373
3374 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
3375 " 0x%x, 0x%x)\n",
3376 srcX0, srcY0, srcX1, srcY1,
3377 dstX0, dstY0, dstX1, dstY1,
3378 mask, filter);
3379 if (colorReadRb) {
3380 const struct gl_renderbuffer_attachment *att;
3381
3382 att = find_attachment(readFb, colorReadRb);
3383 printf(" Src FBO %u RB %u (%dx%d) ",
3384 readFb->Name, colorReadRb->Name,
3385 colorReadRb->Width, colorReadRb->Height);
3386 if (att && att->Texture) {
3387 printf("Tex %u tgt 0x%x level %u face %u",
3388 att->Texture->Name,
3389 att->Texture->Target,
3390 att->TextureLevel,
3391 att->CubeMapFace);
3392 }
3393 printf("\n");
3394
3395 /* Print all active color render buffers */
3396 for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
3397 colorDrawRb = ctx->DrawBuffer->_ColorDrawBuffers[i];
3398 if (!colorDrawRb)
3399 continue;
3400
3401 att = find_attachment(drawFb, colorDrawRb);
3402 printf(" Dst FBO %u RB %u (%dx%d) ",
3403 drawFb->Name, colorDrawRb->Name,
3404 colorDrawRb->Width, colorDrawRb->Height);
3405 if (att && att->Texture) {
3406 printf("Tex %u tgt 0x%x level %u face %u",
3407 att->Texture->Name,
3408 att->Texture->Target,
3409 att->TextureLevel,
3410 att->CubeMapFace);
3411 }
3412 printf("\n");
3413 }
3414 }
3415 }
3416
3417 if (!mask ||
3418 (srcX1 - srcX0) == 0 || (srcY1 - srcY0) == 0 ||
3419 (dstX1 - dstX0) == 0 || (dstY1 - dstY0) == 0) {
3420 return;
3421 }
3422
3423 ASSERT(ctx->Driver.BlitFramebuffer);
3424 ctx->Driver.BlitFramebuffer(ctx,
3425 srcX0, srcY0, srcX1, srcY1,
3426 dstX0, dstY0, dstX1, dstY1,
3427 mask, filter);
3428 }
3429
3430
3431 static void
3432 invalidate_framebuffer_storage(GLenum target, GLsizei numAttachments,
3433 const GLenum *attachments, GLint x, GLint y,
3434 GLsizei width, GLsizei height, const char *name)
3435 {
3436 int i;
3437 struct gl_framebuffer *fb;
3438 GET_CURRENT_CONTEXT(ctx);
3439
3440 fb = get_framebuffer_target(ctx, target);
3441 if (!fb) {
3442 _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", name);
3443 return;
3444 }
3445
3446 if (numAttachments < 0) {
3447 _mesa_error(ctx, GL_INVALID_VALUE,
3448 "%s(numAttachments < 0)", name);
3449 return;
3450 }
3451
3452 /* The GL_ARB_invalidate_subdata spec says:
3453 *
3454 * "If an attachment is specified that does not exist in the
3455 * framebuffer bound to <target>, it is ignored."
3456 *
3457 * It also says:
3458 *
3459 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
3460 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
3461 * INVALID_OPERATION is generated."
3462 *
3463 * No mention is made of GL_AUXi being out of range. Therefore, we allow
3464 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
3465 * set of retrictions).
3466 */
3467 for (i = 0; i < numAttachments; i++) {
3468 if (_mesa_is_winsys_fbo(fb)) {
3469 switch (attachments[i]) {
3470 case GL_ACCUM:
3471 case GL_AUX0:
3472 case GL_AUX1:
3473 case GL_AUX2:
3474 case GL_AUX3:
3475 /* Accumulation buffers and auxilary buffers were removed in
3476 * OpenGL 3.1, and they never existed in OpenGL ES.
3477 */
3478 if (ctx->API != API_OPENGL_COMPAT)
3479 goto invalid_enum;
3480 break;
3481 case GL_COLOR:
3482 case GL_DEPTH:
3483 case GL_STENCIL:
3484 break;
3485 case GL_BACK_LEFT:
3486 case GL_BACK_RIGHT:
3487 case GL_FRONT_LEFT:
3488 case GL_FRONT_RIGHT:
3489 if (!_mesa_is_desktop_gl(ctx))
3490 goto invalid_enum;
3491 break;
3492 default:
3493 goto invalid_enum;
3494 }
3495 } else {
3496 switch (attachments[i]) {
3497 case GL_DEPTH_ATTACHMENT:
3498 case GL_STENCIL_ATTACHMENT:
3499 break;
3500 case GL_COLOR_ATTACHMENT0:
3501 case GL_COLOR_ATTACHMENT1:
3502 case GL_COLOR_ATTACHMENT2:
3503 case GL_COLOR_ATTACHMENT3:
3504 case GL_COLOR_ATTACHMENT4:
3505 case GL_COLOR_ATTACHMENT5:
3506 case GL_COLOR_ATTACHMENT6:
3507 case GL_COLOR_ATTACHMENT7:
3508 case GL_COLOR_ATTACHMENT8:
3509 case GL_COLOR_ATTACHMENT9:
3510 case GL_COLOR_ATTACHMENT10:
3511 case GL_COLOR_ATTACHMENT11:
3512 case GL_COLOR_ATTACHMENT12:
3513 case GL_COLOR_ATTACHMENT13:
3514 case GL_COLOR_ATTACHMENT14:
3515 case GL_COLOR_ATTACHMENT15: {
3516 unsigned k = attachments[i] - GL_COLOR_ATTACHMENT0;
3517 if (k >= ctx->Const.MaxColorAttachments) {
3518 _mesa_error(ctx, GL_INVALID_OPERATION,
3519 "%s(attachment >= max. color attachments)", name);
3520 return;
3521 }
3522 }
3523 default:
3524 goto invalid_enum;
3525 }
3526 }
3527 }
3528
3529 /* We don't actually do anything for this yet. Just return after
3530 * validating the parameters and generating the required errors.
3531 */
3532 return;
3533
3534 invalid_enum:
3535 _mesa_error(ctx, GL_INVALID_ENUM, "%s(attachment)", name);
3536 return;
3537 }
3538
3539 void GLAPIENTRY
3540 _mesa_InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments,
3541 const GLenum *attachments, GLint x, GLint y,
3542 GLsizei width, GLsizei height)
3543 {
3544 invalidate_framebuffer_storage(target, numAttachments, attachments,
3545 x, y, width, height,
3546 "glInvalidateSubFramebuffer");
3547 }
3548
3549 void GLAPIENTRY
3550 _mesa_InvalidateFramebuffer(GLenum target, GLsizei numAttachments,
3551 const GLenum *attachments)
3552 {
3553 /* The GL_ARB_invalidate_subdata spec says:
3554 *
3555 * "The command
3556 *
3557 * void InvalidateFramebuffer(enum target,
3558 * sizei numAttachments,
3559 * const enum *attachments);
3560 *
3561 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
3562 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
3563 * <MAX_VIEWPORT_DIMS[1]> respectively."
3564 */
3565 invalidate_framebuffer_storage(target, numAttachments, attachments,
3566 0, 0, MAX_VIEWPORT_WIDTH, MAX_VIEWPORT_HEIGHT,
3567 "glInvalidateFramebuffer");
3568 }
3569
3570 void GLAPIENTRY
3571 _mesa_DiscardFramebufferEXT(GLenum target, GLsizei numAttachments,
3572 const GLenum *attachments)
3573 {
3574 struct gl_framebuffer *fb;
3575 GLint i;
3576
3577 GET_CURRENT_CONTEXT(ctx);
3578
3579 fb = get_framebuffer_target(ctx, target);
3580 if (!fb) {
3581 _mesa_error(ctx, GL_INVALID_ENUM,
3582 "glDiscardFramebufferEXT(target %s)",
3583 _mesa_lookup_enum_by_nr(target));
3584 return;
3585 }
3586
3587 if (numAttachments < 0) {
3588 _mesa_error(ctx, GL_INVALID_VALUE,
3589 "glDiscardFramebufferEXT(numAttachments < 0)");
3590 return;
3591 }
3592
3593 for (i = 0; i < numAttachments; i++) {
3594 switch (attachments[i]) {
3595 case GL_COLOR:
3596 case GL_DEPTH:
3597 case GL_STENCIL:
3598 if (_mesa_is_user_fbo(fb))
3599 goto invalid_enum;
3600 break;
3601 case GL_COLOR_ATTACHMENT0:
3602 case GL_DEPTH_ATTACHMENT:
3603 case GL_STENCIL_ATTACHMENT:
3604 if (_mesa_is_winsys_fbo(fb))
3605 goto invalid_enum;
3606 break;
3607 default:
3608 goto invalid_enum;
3609 }
3610 }
3611
3612 if (ctx->Driver.DiscardFramebuffer)
3613 ctx->Driver.DiscardFramebuffer(ctx, target, numAttachments, attachments);
3614
3615 return;
3616
3617 invalid_enum:
3618 _mesa_error(ctx, GL_INVALID_ENUM,
3619 "glDiscardFramebufferEXT(attachment %s)",
3620 _mesa_lookup_enum_by_nr(attachments[i]));
3621 }