r200/i915/st/mesa/compiler: use common inputs read field
[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 /**
54 * Notes:
55 *
56 * None of the GL_EXT_framebuffer_object functions are compiled into
57 * display lists.
58 */
59
60
61
62 /*
63 * When glGenRender/FramebuffersEXT() is called we insert pointers to
64 * these placeholder objects into the hash table.
65 * Later, when the object ID is first bound, we replace the placeholder
66 * with the real frame/renderbuffer.
67 */
68 static struct gl_framebuffer DummyFramebuffer;
69 static struct gl_renderbuffer DummyRenderbuffer;
70
71 /* We bind this framebuffer when applications pass a NULL
72 * drawable/surface in make current. */
73 static struct gl_framebuffer IncompleteFramebuffer;
74
75
76 static void
77 delete_dummy_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
78 {
79 /* no op */
80 }
81
82 static void
83 delete_dummy_framebuffer(struct gl_framebuffer *fb)
84 {
85 /* no op */
86 }
87
88
89 void
90 _mesa_init_fbobjects(struct gl_context *ctx)
91 {
92 mtx_init(&DummyFramebuffer.Mutex, mtx_plain);
93 mtx_init(&DummyRenderbuffer.Mutex, mtx_plain);
94 mtx_init(&IncompleteFramebuffer.Mutex, mtx_plain);
95 DummyFramebuffer.Delete = delete_dummy_framebuffer;
96 DummyRenderbuffer.Delete = delete_dummy_renderbuffer;
97 IncompleteFramebuffer.Delete = delete_dummy_framebuffer;
98 }
99
100 struct gl_framebuffer *
101 _mesa_get_incomplete_framebuffer(void)
102 {
103 return &IncompleteFramebuffer;
104 }
105
106 /**
107 * Helper routine for getting a gl_renderbuffer.
108 */
109 struct gl_renderbuffer *
110 _mesa_lookup_renderbuffer(struct gl_context *ctx, GLuint id)
111 {
112 struct gl_renderbuffer *rb;
113
114 if (id == 0)
115 return NULL;
116
117 rb = (struct gl_renderbuffer *)
118 _mesa_HashLookup(ctx->Shared->RenderBuffers, id);
119 return rb;
120 }
121
122
123 /**
124 * A convenience function for direct state access that throws
125 * GL_INVALID_OPERATION if the renderbuffer doesn't exist.
126 */
127 struct gl_renderbuffer *
128 _mesa_lookup_renderbuffer_err(struct gl_context *ctx, GLuint id,
129 const char *func)
130 {
131 struct gl_renderbuffer *rb;
132
133 rb = _mesa_lookup_renderbuffer(ctx, id);
134 if (!rb || rb == &DummyRenderbuffer) {
135 _mesa_error(ctx, GL_INVALID_OPERATION,
136 "%s(non-existent renderbuffer %u)", func, id);
137 return NULL;
138 }
139
140 return rb;
141 }
142
143
144 /**
145 * Helper routine for getting a gl_framebuffer.
146 */
147 struct gl_framebuffer *
148 _mesa_lookup_framebuffer(struct gl_context *ctx, GLuint id)
149 {
150 struct gl_framebuffer *fb;
151
152 if (id == 0)
153 return NULL;
154
155 fb = (struct gl_framebuffer *)
156 _mesa_HashLookup(ctx->Shared->FrameBuffers, id);
157 return fb;
158 }
159
160
161 /**
162 * A convenience function for direct state access that throws
163 * GL_INVALID_OPERATION if the framebuffer doesn't exist.
164 */
165 struct gl_framebuffer *
166 _mesa_lookup_framebuffer_err(struct gl_context *ctx, GLuint id,
167 const char *func)
168 {
169 struct gl_framebuffer *fb;
170
171 fb = _mesa_lookup_framebuffer(ctx, id);
172 if (!fb || fb == &DummyFramebuffer) {
173 _mesa_error(ctx, GL_INVALID_OPERATION,
174 "%s(non-existent framebuffer %u)", func, id);
175 return NULL;
176 }
177
178 return fb;
179 }
180
181
182 /**
183 * Mark the given framebuffer as invalid. This will force the
184 * test for framebuffer completeness to be done before the framebuffer
185 * is used.
186 */
187 static void
188 invalidate_framebuffer(struct gl_framebuffer *fb)
189 {
190 fb->_Status = 0; /* "indeterminate" */
191 }
192
193
194 /**
195 * Return the gl_framebuffer object which corresponds to the given
196 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
197 * Check support for GL_EXT_framebuffer_blit to determine if certain
198 * targets are legal.
199 * \return gl_framebuffer pointer or NULL if target is illegal
200 */
201 static struct gl_framebuffer *
202 get_framebuffer_target(struct gl_context *ctx, GLenum target)
203 {
204 bool have_fb_blit = _mesa_is_gles3(ctx) || _mesa_is_desktop_gl(ctx);
205 switch (target) {
206 case GL_DRAW_FRAMEBUFFER:
207 return have_fb_blit ? ctx->DrawBuffer : NULL;
208 case GL_READ_FRAMEBUFFER:
209 return have_fb_blit ? ctx->ReadBuffer : NULL;
210 case GL_FRAMEBUFFER_EXT:
211 return ctx->DrawBuffer;
212 default:
213 return NULL;
214 }
215 }
216
217
218 /**
219 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
220 * gl_renderbuffer_attachment object.
221 * This function is only used for user-created FB objects, not the
222 * default / window-system FB object.
223 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
224 * the depth buffer attachment point.
225 */
226 static struct gl_renderbuffer_attachment *
227 get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
228 GLenum attachment)
229 {
230 GLuint i;
231
232 assert(_mesa_is_user_fbo(fb));
233
234 switch (attachment) {
235 case GL_COLOR_ATTACHMENT0_EXT:
236 case GL_COLOR_ATTACHMENT1_EXT:
237 case GL_COLOR_ATTACHMENT2_EXT:
238 case GL_COLOR_ATTACHMENT3_EXT:
239 case GL_COLOR_ATTACHMENT4_EXT:
240 case GL_COLOR_ATTACHMENT5_EXT:
241 case GL_COLOR_ATTACHMENT6_EXT:
242 case GL_COLOR_ATTACHMENT7_EXT:
243 case GL_COLOR_ATTACHMENT8_EXT:
244 case GL_COLOR_ATTACHMENT9_EXT:
245 case GL_COLOR_ATTACHMENT10_EXT:
246 case GL_COLOR_ATTACHMENT11_EXT:
247 case GL_COLOR_ATTACHMENT12_EXT:
248 case GL_COLOR_ATTACHMENT13_EXT:
249 case GL_COLOR_ATTACHMENT14_EXT:
250 case GL_COLOR_ATTACHMENT15_EXT:
251 /* Only OpenGL ES 1.x forbids color attachments other than
252 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
253 * hardware is used.
254 */
255 i = attachment - GL_COLOR_ATTACHMENT0_EXT;
256 if (i >= ctx->Const.MaxColorAttachments
257 || (i > 0 && ctx->API == API_OPENGLES)) {
258 return NULL;
259 }
260 return &fb->Attachment[BUFFER_COLOR0 + i];
261 case GL_DEPTH_STENCIL_ATTACHMENT:
262 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
263 return NULL;
264 /* fall-through */
265 case GL_DEPTH_ATTACHMENT_EXT:
266 return &fb->Attachment[BUFFER_DEPTH];
267 case GL_STENCIL_ATTACHMENT_EXT:
268 return &fb->Attachment[BUFFER_STENCIL];
269 default:
270 return NULL;
271 }
272 }
273
274
275 /**
276 * As above, but only used for getting attachments of the default /
277 * window-system framebuffer (not user-created framebuffer objects).
278 */
279 static struct gl_renderbuffer_attachment *
280 _mesa_get_fb0_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
281 GLenum attachment)
282 {
283 assert(_mesa_is_winsys_fbo(fb));
284
285 if (_mesa_is_gles3(ctx)) {
286 assert(attachment == GL_BACK ||
287 attachment == GL_DEPTH ||
288 attachment == GL_STENCIL);
289 switch (attachment) {
290 case GL_BACK:
291 /* Since there is no stereo rendering in ES 3.0, only return the
292 * LEFT bits.
293 */
294 if (ctx->DrawBuffer->Visual.doubleBufferMode)
295 return &fb->Attachment[BUFFER_BACK_LEFT];
296 return &fb->Attachment[BUFFER_FRONT_LEFT];
297 case GL_DEPTH:
298 return &fb->Attachment[BUFFER_DEPTH];
299 case GL_STENCIL:
300 return &fb->Attachment[BUFFER_STENCIL];
301 }
302 }
303
304 switch (attachment) {
305 case GL_FRONT_LEFT:
306 /* Front buffers can be allocated on the first use, but
307 * glGetFramebufferAttachmentParameteriv must work even if that
308 * allocation hasn't happened yet. In such case, use the back buffer,
309 * which should be the same.
310 */
311 if (fb->Attachment[BUFFER_FRONT_LEFT].Type == GL_NONE)
312 return &fb->Attachment[BUFFER_BACK_LEFT];
313 else
314 return &fb->Attachment[BUFFER_FRONT_LEFT];
315 case GL_FRONT_RIGHT:
316 /* Same as above. */
317 if (fb->Attachment[BUFFER_FRONT_RIGHT].Type == GL_NONE)
318 return &fb->Attachment[BUFFER_BACK_RIGHT];
319 else
320 return &fb->Attachment[BUFFER_FRONT_RIGHT];
321 case GL_BACK_LEFT:
322 return &fb->Attachment[BUFFER_BACK_LEFT];
323 case GL_BACK_RIGHT:
324 return &fb->Attachment[BUFFER_BACK_RIGHT];
325 case GL_AUX0:
326 if (fb->Visual.numAuxBuffers == 1) {
327 return &fb->Attachment[BUFFER_AUX0];
328 }
329 return NULL;
330
331 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
332 *
333 * "If the default framebuffer is bound to target, then attachment must
334 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
335 * identifying a color buffer; DEPTH, identifying the depth buffer; or
336 * STENCIL, identifying the stencil buffer."
337 *
338 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
339 * language. However, revision #33 of the ARB_framebuffer_object spec
340 * says:
341 *
342 * "If the default framebuffer is bound to <target>, then <attachment>
343 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
344 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
345 * depth buffer, or the stencil buffer, and <pname> may be
346 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
347 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
348 *
349 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
350 * from glext.h, so shipping apps should not use those values.
351 *
352 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
353 * support queries of the window system FBO.
354 */
355 case GL_DEPTH:
356 return &fb->Attachment[BUFFER_DEPTH];
357 case GL_STENCIL:
358 return &fb->Attachment[BUFFER_STENCIL];
359 default:
360 return NULL;
361 }
362 }
363
364
365
366 /**
367 * Remove any texture or renderbuffer attached to the given attachment
368 * point. Update reference counts, etc.
369 */
370 static void
371 remove_attachment(struct gl_context *ctx,
372 struct gl_renderbuffer_attachment *att)
373 {
374 struct gl_renderbuffer *rb = att->Renderbuffer;
375
376 /* tell driver that we're done rendering to this texture. */
377 if (rb && rb->NeedsFinishRenderTexture)
378 ctx->Driver.FinishRenderTexture(ctx, rb);
379
380 if (att->Type == GL_TEXTURE) {
381 assert(att->Texture);
382 _mesa_reference_texobj(&att->Texture, NULL); /* unbind */
383 assert(!att->Texture);
384 }
385 if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) {
386 assert(!att->Texture);
387 _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */
388 assert(!att->Renderbuffer);
389 }
390 att->Type = GL_NONE;
391 att->Complete = GL_TRUE;
392 }
393
394 /**
395 * Verify a couple error conditions that will lead to an incomplete FBO and
396 * may cause problems for the driver's RenderTexture path.
397 */
398 static bool
399 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment *att)
400 {
401 const struct gl_texture_image *const texImage =
402 att->Texture->Image[att->CubeMapFace][att->TextureLevel];
403
404 if (!texImage ||
405 texImage->Width == 0 || texImage->Height == 0 || texImage->Depth == 0)
406 return false;
407
408 if ((texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY
409 && att->Zoffset >= texImage->Height)
410 || (texImage->TexObject->Target != GL_TEXTURE_1D_ARRAY
411 && att->Zoffset >= texImage->Depth))
412 return false;
413
414 return true;
415 }
416
417 /**
418 * Create a renderbuffer which will be set up by the driver to wrap the
419 * texture image slice.
420 *
421 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
422 * to share most of their framebuffer rendering code between winsys,
423 * renderbuffer, and texture attachments.
424 *
425 * The allocated renderbuffer uses a non-zero Name so that drivers can check
426 * it for determining vertical orientation, but we use ~0 to make it fairly
427 * unambiguous with actual user (non-texture) renderbuffers.
428 */
429 void
430 _mesa_update_texture_renderbuffer(struct gl_context *ctx,
431 struct gl_framebuffer *fb,
432 struct gl_renderbuffer_attachment *att)
433 {
434 struct gl_texture_image *texImage;
435 struct gl_renderbuffer *rb;
436
437 texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
438
439 rb = att->Renderbuffer;
440 if (!rb) {
441 rb = ctx->Driver.NewRenderbuffer(ctx, ~0);
442 if (!rb) {
443 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()");
444 return;
445 }
446 _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
447
448 /* This can't get called on a texture renderbuffer, so set it to NULL
449 * for clarity compared to user renderbuffers.
450 */
451 rb->AllocStorage = NULL;
452
453 rb->NeedsFinishRenderTexture = ctx->Driver.FinishRenderTexture != NULL;
454 }
455
456 if (!texImage)
457 return;
458
459 rb->_BaseFormat = texImage->_BaseFormat;
460 rb->Format = texImage->TexFormat;
461 rb->InternalFormat = texImage->InternalFormat;
462 rb->Width = texImage->Width2;
463 rb->Height = texImage->Height2;
464 rb->Depth = texImage->Depth2;
465 rb->NumSamples = texImage->NumSamples;
466 rb->TexImage = texImage;
467
468 if (driver_RenderTexture_is_safe(att))
469 ctx->Driver.RenderTexture(ctx, fb, att);
470 }
471
472 /**
473 * Bind a texture object to an attachment point.
474 * The previous binding, if any, will be removed first.
475 */
476 static void
477 set_texture_attachment(struct gl_context *ctx,
478 struct gl_framebuffer *fb,
479 struct gl_renderbuffer_attachment *att,
480 struct gl_texture_object *texObj,
481 GLenum texTarget, GLuint level, GLuint layer,
482 GLboolean layered)
483 {
484 struct gl_renderbuffer *rb = att->Renderbuffer;
485
486 if (rb && rb->NeedsFinishRenderTexture)
487 ctx->Driver.FinishRenderTexture(ctx, rb);
488
489 if (att->Texture == texObj) {
490 /* re-attaching same texture */
491 assert(att->Type == GL_TEXTURE);
492 }
493 else {
494 /* new attachment */
495 remove_attachment(ctx, att);
496 att->Type = GL_TEXTURE;
497 assert(!att->Texture);
498 _mesa_reference_texobj(&att->Texture, texObj);
499 }
500 invalidate_framebuffer(fb);
501
502 /* always update these fields */
503 att->TextureLevel = level;
504 att->CubeMapFace = _mesa_tex_target_to_face(texTarget);
505 att->Zoffset = layer;
506 att->Layered = layered;
507 att->Complete = GL_FALSE;
508
509 _mesa_update_texture_renderbuffer(ctx, fb, att);
510 }
511
512
513 /**
514 * Bind a renderbuffer to an attachment point.
515 * The previous binding, if any, will be removed first.
516 */
517 static void
518 set_renderbuffer_attachment(struct gl_context *ctx,
519 struct gl_renderbuffer_attachment *att,
520 struct gl_renderbuffer *rb)
521 {
522 /* XXX check if re-doing same attachment, exit early */
523 remove_attachment(ctx, att);
524 att->Type = GL_RENDERBUFFER_EXT;
525 att->Texture = NULL; /* just to be safe */
526 att->Layered = GL_FALSE;
527 att->Complete = GL_FALSE;
528 _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
529 }
530
531
532 /**
533 * Fallback for ctx->Driver.FramebufferRenderbuffer()
534 * Attach a renderbuffer object to a framebuffer object.
535 */
536 void
537 _mesa_FramebufferRenderbuffer_sw(struct gl_context *ctx,
538 struct gl_framebuffer *fb,
539 GLenum attachment,
540 struct gl_renderbuffer *rb)
541 {
542 struct gl_renderbuffer_attachment *att;
543
544 mtx_lock(&fb->Mutex);
545
546 att = get_attachment(ctx, fb, attachment);
547 assert(att);
548 if (rb) {
549 set_renderbuffer_attachment(ctx, att, rb);
550 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
551 /* do stencil attachment here (depth already done above) */
552 att = get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
553 assert(att);
554 set_renderbuffer_attachment(ctx, att, rb);
555 }
556 rb->AttachedAnytime = GL_TRUE;
557 }
558 else {
559 remove_attachment(ctx, att);
560 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
561 /* detach stencil (depth was detached above) */
562 att = get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
563 assert(att);
564 remove_attachment(ctx, att);
565 }
566 }
567
568 invalidate_framebuffer(fb);
569
570 mtx_unlock(&fb->Mutex);
571 }
572
573
574 /**
575 * Fallback for ctx->Driver.ValidateFramebuffer()
576 * Check if the renderbuffer's formats are supported by the software
577 * renderer.
578 * Drivers should probably override this.
579 */
580 void
581 _mesa_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
582 {
583 gl_buffer_index buf;
584 for (buf = 0; buf < BUFFER_COUNT; buf++) {
585 const struct gl_renderbuffer *rb = fb->Attachment[buf].Renderbuffer;
586 if (rb) {
587 switch (rb->_BaseFormat) {
588 case GL_ALPHA:
589 case GL_LUMINANCE_ALPHA:
590 case GL_LUMINANCE:
591 case GL_INTENSITY:
592 case GL_RED:
593 case GL_RG:
594 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
595 return;
596
597 default:
598 switch (rb->Format) {
599 /* XXX This list is likely incomplete. */
600 case MESA_FORMAT_R9G9B9E5_FLOAT:
601 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
602 return;
603 default:;
604 /* render buffer format is supported by software rendering */
605 }
606 }
607 }
608 }
609 }
610
611
612 /**
613 * Return true if the framebuffer has a combined depth/stencil
614 * renderbuffer attached.
615 */
616 GLboolean
617 _mesa_has_depthstencil_combined(const struct gl_framebuffer *fb)
618 {
619 const struct gl_renderbuffer_attachment *depth =
620 &fb->Attachment[BUFFER_DEPTH];
621 const struct gl_renderbuffer_attachment *stencil =
622 &fb->Attachment[BUFFER_STENCIL];
623
624 if (depth->Type == stencil->Type) {
625 if (depth->Type == GL_RENDERBUFFER_EXT &&
626 depth->Renderbuffer == stencil->Renderbuffer)
627 return GL_TRUE;
628
629 if (depth->Type == GL_TEXTURE &&
630 depth->Texture == stencil->Texture)
631 return GL_TRUE;
632 }
633
634 return GL_FALSE;
635 }
636
637
638 /**
639 * For debug only.
640 */
641 static void
642 att_incomplete(const char *msg)
643 {
644 if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) {
645 _mesa_debug(NULL, "attachment incomplete: %s\n", msg);
646 }
647 }
648
649
650 /**
651 * For debug only.
652 */
653 static void
654 fbo_incomplete(struct gl_context *ctx, const char *msg, int index)
655 {
656 static GLuint msg_id;
657
658 _mesa_gl_debug(ctx, &msg_id,
659 MESA_DEBUG_SOURCE_API,
660 MESA_DEBUG_TYPE_OTHER,
661 MESA_DEBUG_SEVERITY_MEDIUM,
662 "FBO incomplete: %s [%d]\n", msg, index);
663
664 if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) {
665 _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
666 }
667 }
668
669
670 /**
671 * Is the given base format a legal format for a color renderbuffer?
672 */
673 GLboolean
674 _mesa_is_legal_color_format(const struct gl_context *ctx, GLenum baseFormat)
675 {
676 switch (baseFormat) {
677 case GL_RGB:
678 case GL_RGBA:
679 return GL_TRUE;
680 case GL_LUMINANCE:
681 case GL_LUMINANCE_ALPHA:
682 case GL_INTENSITY:
683 case GL_ALPHA:
684 return ctx->API == API_OPENGL_COMPAT &&
685 ctx->Extensions.ARB_framebuffer_object;
686 case GL_RED:
687 case GL_RG:
688 return ctx->Extensions.ARB_texture_rg;
689 default:
690 return GL_FALSE;
691 }
692 }
693
694
695 /**
696 * Is the given base format a legal format for a color renderbuffer?
697 */
698 static GLboolean
699 is_format_color_renderable(const struct gl_context *ctx, mesa_format format,
700 GLenum internalFormat)
701 {
702 const GLenum baseFormat =
703 _mesa_get_format_base_format(format);
704 GLboolean valid;
705
706 valid = _mesa_is_legal_color_format(ctx, baseFormat);
707 if (!valid || _mesa_is_desktop_gl(ctx)) {
708 return valid;
709 }
710
711 /* Reject additional cases for GLES */
712 switch (internalFormat) {
713 case GL_RGBA8_SNORM:
714 case GL_RGB32F:
715 case GL_RGB32I:
716 case GL_RGB32UI:
717 case GL_RGB16F:
718 case GL_RGB16I:
719 case GL_RGB16UI:
720 case GL_RGB8_SNORM:
721 case GL_RGB8I:
722 case GL_RGB8UI:
723 case GL_SRGB8:
724 case GL_RGB9_E5:
725 case GL_RG8_SNORM:
726 case GL_R8_SNORM:
727 return GL_FALSE;
728 default:
729 break;
730 }
731
732 if (format == MESA_FORMAT_B10G10R10A2_UNORM &&
733 internalFormat != GL_RGB10_A2) {
734 return GL_FALSE;
735 }
736
737 return GL_TRUE;
738 }
739
740
741 /**
742 * Is the given base format a legal format for a depth/stencil renderbuffer?
743 */
744 static GLboolean
745 is_legal_depth_format(const struct gl_context *ctx, GLenum baseFormat)
746 {
747 switch (baseFormat) {
748 case GL_DEPTH_COMPONENT:
749 case GL_DEPTH_STENCIL_EXT:
750 return GL_TRUE;
751 default:
752 return GL_FALSE;
753 }
754 }
755
756
757 /**
758 * Test if an attachment point is complete and update its Complete field.
759 * \param format if GL_COLOR, this is a color attachment point,
760 * if GL_DEPTH, this is a depth component attachment point,
761 * if GL_STENCIL, this is a stencil component attachment point.
762 */
763 static void
764 test_attachment_completeness(const struct gl_context *ctx, GLenum format,
765 struct gl_renderbuffer_attachment *att)
766 {
767 assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL);
768
769 /* assume complete */
770 att->Complete = GL_TRUE;
771
772 /* Look for reasons why the attachment might be incomplete */
773 if (att->Type == GL_TEXTURE) {
774 const struct gl_texture_object *texObj = att->Texture;
775 struct gl_texture_image *texImage;
776 GLenum baseFormat;
777
778 if (!texObj) {
779 att_incomplete("no texobj");
780 att->Complete = GL_FALSE;
781 return;
782 }
783
784 texImage = texObj->Image[att->CubeMapFace][att->TextureLevel];
785 if (!texImage) {
786 att_incomplete("no teximage");
787 att->Complete = GL_FALSE;
788 return;
789 }
790 if (texImage->Width < 1 || texImage->Height < 1) {
791 att_incomplete("teximage width/height=0");
792 att->Complete = GL_FALSE;
793 return;
794 }
795
796 switch (texObj->Target) {
797 case GL_TEXTURE_3D:
798 if (att->Zoffset >= texImage->Depth) {
799 att_incomplete("bad z offset");
800 att->Complete = GL_FALSE;
801 return;
802 }
803 break;
804 case GL_TEXTURE_1D_ARRAY:
805 if (att->Zoffset >= texImage->Height) {
806 att_incomplete("bad 1D-array layer");
807 att->Complete = GL_FALSE;
808 return;
809 }
810 break;
811 case GL_TEXTURE_2D_ARRAY:
812 if (att->Zoffset >= texImage->Depth) {
813 att_incomplete("bad 2D-array layer");
814 att->Complete = GL_FALSE;
815 return;
816 }
817 break;
818 case GL_TEXTURE_CUBE_MAP_ARRAY:
819 if (att->Zoffset >= texImage->Depth) {
820 att_incomplete("bad cube-array layer");
821 att->Complete = GL_FALSE;
822 return;
823 }
824 break;
825 }
826
827 baseFormat = texImage->_BaseFormat;
828
829 if (format == GL_COLOR) {
830 if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
831 att_incomplete("bad format");
832 att->Complete = GL_FALSE;
833 return;
834 }
835 if (_mesa_is_format_compressed(texImage->TexFormat)) {
836 att_incomplete("compressed internalformat");
837 att->Complete = GL_FALSE;
838 return;
839 }
840
841 /* OES_texture_float allows creation and use of floating point
842 * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow
843 * these textures to be used as a render target, this is done via
844 * GL_EXT_color_buffer(_half)_float with set of new sized types.
845 */
846 if (_mesa_is_gles(ctx) && (texImage->TexObject->_IsFloat ||
847 texImage->TexObject->_IsHalfFloat)) {
848 att_incomplete("bad internal format");
849 att->Complete = GL_FALSE;
850 return;
851 }
852 }
853 else if (format == GL_DEPTH) {
854 if (baseFormat == GL_DEPTH_COMPONENT) {
855 /* OK */
856 }
857 else if (ctx->Extensions.ARB_depth_texture &&
858 baseFormat == GL_DEPTH_STENCIL) {
859 /* OK */
860 }
861 else {
862 att->Complete = GL_FALSE;
863 att_incomplete("bad depth format");
864 return;
865 }
866 }
867 else {
868 assert(format == GL_STENCIL);
869 if (ctx->Extensions.ARB_depth_texture &&
870 baseFormat == GL_DEPTH_STENCIL) {
871 /* OK */
872 } else if (ctx->Extensions.ARB_texture_stencil8 &&
873 baseFormat == GL_STENCIL_INDEX) {
874 /* OK */
875 } else {
876 /* no such thing as stencil-only textures */
877 att_incomplete("illegal stencil texture");
878 att->Complete = GL_FALSE;
879 return;
880 }
881 }
882 }
883 else if (att->Type == GL_RENDERBUFFER_EXT) {
884 const GLenum baseFormat = att->Renderbuffer->_BaseFormat;
885
886 assert(att->Renderbuffer);
887 if (!att->Renderbuffer->InternalFormat ||
888 att->Renderbuffer->Width < 1 ||
889 att->Renderbuffer->Height < 1) {
890 att_incomplete("0x0 renderbuffer");
891 att->Complete = GL_FALSE;
892 return;
893 }
894 if (format == GL_COLOR) {
895 if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
896 att_incomplete("bad renderbuffer color format");
897 att->Complete = GL_FALSE;
898 return;
899 }
900 }
901 else if (format == GL_DEPTH) {
902 if (baseFormat == GL_DEPTH_COMPONENT) {
903 /* OK */
904 }
905 else if (baseFormat == GL_DEPTH_STENCIL) {
906 /* OK */
907 }
908 else {
909 att_incomplete("bad renderbuffer depth format");
910 att->Complete = GL_FALSE;
911 return;
912 }
913 }
914 else {
915 assert(format == GL_STENCIL);
916 if (baseFormat == GL_STENCIL_INDEX ||
917 baseFormat == GL_DEPTH_STENCIL) {
918 /* OK */
919 }
920 else {
921 att->Complete = GL_FALSE;
922 att_incomplete("bad renderbuffer stencil format");
923 return;
924 }
925 }
926 }
927 else {
928 assert(att->Type == GL_NONE);
929 /* complete */
930 return;
931 }
932 }
933
934
935 /**
936 * Test if the given framebuffer object is complete and update its
937 * Status field with the results.
938 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
939 * driver to make hardware-specific validation/completeness checks.
940 * Also update the framebuffer's Width and Height fields if the
941 * framebuffer is complete.
942 */
943 void
944 _mesa_test_framebuffer_completeness(struct gl_context *ctx,
945 struct gl_framebuffer *fb)
946 {
947 GLuint numImages;
948 GLenum intFormat = GL_NONE; /* color buffers' internal format */
949 GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0;
950 GLint numSamples = -1;
951 GLint fixedSampleLocations = -1;
952 GLint i;
953 GLuint j;
954 /* Covers max_layer_count, is_layered, and layer_tex_target */
955 bool layer_info_valid = false;
956 GLuint max_layer_count = 0, att_layer_count;
957 bool is_layered = false;
958 GLenum layer_tex_target = 0;
959 bool has_depth_attachment = false;
960 bool has_stencil_attachment = false;
961
962 assert(_mesa_is_user_fbo(fb));
963
964 /* we're changing framebuffer fields here */
965 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
966
967 numImages = 0;
968 fb->Width = 0;
969 fb->Height = 0;
970 fb->_AllColorBuffersFixedPoint = GL_TRUE;
971 fb->_HasSNormOrFloatColorBuffer = GL_FALSE;
972 fb->_HasAttachments = true;
973 fb->_IntegerBuffers = 0;
974
975 /* Start at -2 to more easily loop over all attachment points.
976 * -2: depth buffer
977 * -1: stencil buffer
978 * >=0: color buffer
979 */
980 for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) {
981 struct gl_renderbuffer_attachment *att;
982 GLenum f;
983 mesa_format attFormat;
984 GLenum att_tex_target = GL_NONE;
985
986 /*
987 * XXX for ARB_fbo, only check color buffers that are named by
988 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
989 */
990
991 /* check for attachment completeness
992 */
993 if (i == -2) {
994 att = &fb->Attachment[BUFFER_DEPTH];
995 test_attachment_completeness(ctx, GL_DEPTH, att);
996 if (!att->Complete) {
997 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
998 fbo_incomplete(ctx, "depth attachment incomplete", -1);
999 return;
1000 } else if (att->Type != GL_NONE) {
1001 has_depth_attachment = true;
1002 }
1003 }
1004 else if (i == -1) {
1005 att = &fb->Attachment[BUFFER_STENCIL];
1006 test_attachment_completeness(ctx, GL_STENCIL, att);
1007 if (!att->Complete) {
1008 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
1009 fbo_incomplete(ctx, "stencil attachment incomplete", -1);
1010 return;
1011 } else if (att->Type != GL_NONE) {
1012 has_stencil_attachment = true;
1013 }
1014 }
1015 else {
1016 att = &fb->Attachment[BUFFER_COLOR0 + i];
1017 test_attachment_completeness(ctx, GL_COLOR, att);
1018 if (!att->Complete) {
1019 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
1020 fbo_incomplete(ctx, "color attachment incomplete", i);
1021 return;
1022 }
1023 }
1024
1025 /* get width, height, format of the renderbuffer/texture
1026 */
1027 if (att->Type == GL_TEXTURE) {
1028 const struct gl_texture_image *texImg = att->Renderbuffer->TexImage;
1029 att_tex_target = att->Texture->Target;
1030 minWidth = MIN2(minWidth, texImg->Width);
1031 maxWidth = MAX2(maxWidth, texImg->Width);
1032 minHeight = MIN2(minHeight, texImg->Height);
1033 maxHeight = MAX2(maxHeight, texImg->Height);
1034 f = texImg->_BaseFormat;
1035 attFormat = texImg->TexFormat;
1036 numImages++;
1037
1038 if (!is_format_color_renderable(ctx, attFormat,
1039 texImg->InternalFormat) &&
1040 !is_legal_depth_format(ctx, f) &&
1041 f != GL_STENCIL_INDEX) {
1042 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
1043 fbo_incomplete(ctx, "texture attachment incomplete", -1);
1044 return;
1045 }
1046
1047 if (numSamples < 0)
1048 numSamples = texImg->NumSamples;
1049 else if (numSamples != texImg->NumSamples) {
1050 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
1051 fbo_incomplete(ctx, "inconsistent sample count", -1);
1052 return;
1053 }
1054
1055 if (fixedSampleLocations < 0)
1056 fixedSampleLocations = texImg->FixedSampleLocations;
1057 else if (fixedSampleLocations != texImg->FixedSampleLocations) {
1058 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
1059 fbo_incomplete(ctx, "inconsistent fixed sample locations", -1);
1060 return;
1061 }
1062 }
1063 else if (att->Type == GL_RENDERBUFFER_EXT) {
1064 minWidth = MIN2(minWidth, att->Renderbuffer->Width);
1065 maxWidth = MAX2(minWidth, att->Renderbuffer->Width);
1066 minHeight = MIN2(minHeight, att->Renderbuffer->Height);
1067 maxHeight = MAX2(minHeight, att->Renderbuffer->Height);
1068 f = att->Renderbuffer->InternalFormat;
1069 attFormat = att->Renderbuffer->Format;
1070 numImages++;
1071
1072 if (numSamples < 0)
1073 numSamples = att->Renderbuffer->NumSamples;
1074 else if (numSamples != att->Renderbuffer->NumSamples) {
1075 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
1076 fbo_incomplete(ctx, "inconsistent sample count", -1);
1077 return;
1078 }
1079
1080 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1081 if (fixedSampleLocations < 0)
1082 fixedSampleLocations = GL_TRUE;
1083 else if (fixedSampleLocations != GL_TRUE) {
1084 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
1085 fbo_incomplete(ctx, "inconsistent fixed sample locations", -1);
1086 return;
1087 }
1088 }
1089 else {
1090 assert(att->Type == GL_NONE);
1091 continue;
1092 }
1093
1094 /* Update flags describing color buffer datatypes */
1095 if (i >= 0) {
1096 GLenum type = _mesa_get_format_datatype(attFormat);
1097
1098 /* check if integer color */
1099 if (_mesa_is_format_integer_color(attFormat))
1100 fb->_IntegerBuffers |= (1 << i);
1101
1102 fb->_AllColorBuffersFixedPoint =
1103 fb->_AllColorBuffersFixedPoint &&
1104 (type == GL_UNSIGNED_NORMALIZED || type == GL_SIGNED_NORMALIZED);
1105
1106 fb->_HasSNormOrFloatColorBuffer =
1107 fb->_HasSNormOrFloatColorBuffer ||
1108 type == GL_SIGNED_NORMALIZED || type == GL_FLOAT;
1109 }
1110
1111 /* Error-check width, height, format */
1112 if (numImages == 1) {
1113 /* save format */
1114 if (i >= 0) {
1115 intFormat = f;
1116 }
1117 }
1118 else {
1119 if (!ctx->Extensions.ARB_framebuffer_object) {
1120 /* check that width, height, format are same */
1121 if (minWidth != maxWidth || minHeight != maxHeight) {
1122 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
1123 fbo_incomplete(ctx, "width or height mismatch", -1);
1124 return;
1125 }
1126 /* check that all color buffers are the same format */
1127 if (intFormat != GL_NONE && f != intFormat) {
1128 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
1129 fbo_incomplete(ctx, "format mismatch", -1);
1130 return;
1131 }
1132 }
1133 }
1134
1135 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1136 */
1137 if (att->Type == GL_RENDERBUFFER &&
1138 att->Renderbuffer->Format == MESA_FORMAT_NONE) {
1139 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
1140 fbo_incomplete(ctx, "unsupported renderbuffer format", i);
1141 return;
1142 }
1143
1144 /* Check that layered rendering is consistent. */
1145 if (att->Layered) {
1146 if (att_tex_target == GL_TEXTURE_CUBE_MAP)
1147 att_layer_count = 6;
1148 else if (att_tex_target == GL_TEXTURE_1D_ARRAY)
1149 att_layer_count = att->Renderbuffer->Height;
1150 else
1151 att_layer_count = att->Renderbuffer->Depth;
1152 } else {
1153 att_layer_count = 0;
1154 }
1155 if (!layer_info_valid) {
1156 is_layered = att->Layered;
1157 max_layer_count = att_layer_count;
1158 layer_tex_target = att_tex_target;
1159 layer_info_valid = true;
1160 } else if (max_layer_count > 0 && layer_tex_target != att_tex_target) {
1161 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS;
1162 fbo_incomplete(ctx, "layered framebuffer has mismatched targets", i);
1163 return;
1164 } else if (is_layered != att->Layered) {
1165 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS;
1166 fbo_incomplete(ctx,
1167 "framebuffer attachment layer mode is inconsistent",
1168 i);
1169 return;
1170 } else if (att_layer_count > max_layer_count) {
1171 max_layer_count = att_layer_count;
1172 }
1173
1174 /*
1175 * The extension GL_ARB_framebuffer_no_attachments places additional
1176 * requirement on each attachment. Those additional requirements are
1177 * tighter that those of previous versions of GL. In interest of better
1178 * compatibility, we will not enforce these restrictions. For the record
1179 * those additional restrictions are quoted below:
1180 *
1181 * "The width and height of image are greater than zero and less than or
1182 * equal to the values of the implementation-dependent limits
1183 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1184 *
1185 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1186 * array texture and the attachment is layered, the depth or layer count
1187 * of the texture is less than or equal to the implementation-dependent
1188 * limit MAX_FRAMEBUFFER_LAYERS."
1189 *
1190 * "If image has multiple samples, its sample count is less than or equal
1191 * to the value of the implementation-dependent limit
1192 * MAX_FRAMEBUFFER_SAMPLES."
1193 *
1194 * The same requirements are also in place for GL 4.5,
1195 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1196 */
1197 }
1198
1199 fb->MaxNumLayers = max_layer_count;
1200
1201 if (numImages == 0) {
1202 fb->_HasAttachments = false;
1203
1204 if (!ctx->Extensions.ARB_framebuffer_no_attachments) {
1205 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT;
1206 fbo_incomplete(ctx, "no attachments", -1);
1207 return;
1208 }
1209
1210 if (fb->DefaultGeometry.Width == 0 || fb->DefaultGeometry.Height == 0) {
1211 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT;
1212 fbo_incomplete(ctx, "no attachments and default width or height is 0", -1);
1213 return;
1214 }
1215 }
1216
1217 if (_mesa_is_desktop_gl(ctx) && !ctx->Extensions.ARB_ES2_compatibility) {
1218 /* Check that all DrawBuffers are present */
1219 for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) {
1220 if (fb->ColorDrawBuffer[j] != GL_NONE) {
1221 const struct gl_renderbuffer_attachment *att
1222 = get_attachment(ctx, fb, fb->ColorDrawBuffer[j]);
1223 assert(att);
1224 if (att->Type == GL_NONE) {
1225 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT;
1226 fbo_incomplete(ctx, "missing drawbuffer", j);
1227 return;
1228 }
1229 }
1230 }
1231
1232 /* Check that the ReadBuffer is present */
1233 if (fb->ColorReadBuffer != GL_NONE) {
1234 const struct gl_renderbuffer_attachment *att
1235 = get_attachment(ctx, fb, fb->ColorReadBuffer);
1236 assert(att);
1237 if (att->Type == GL_NONE) {
1238 fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT;
1239 fbo_incomplete(ctx, "missing readbuffer", -1);
1240 return;
1241 }
1242 }
1243 }
1244
1245 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1246 *
1247 * "Depth and stencil attachments, if present, are the same image."
1248 *
1249 * This restriction is not present in the OpenGL ES2 spec.
1250 */
1251 if (_mesa_is_gles3(ctx) &&
1252 has_stencil_attachment && has_depth_attachment &&
1253 !_mesa_has_depthstencil_combined(fb)) {
1254 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
1255 fbo_incomplete(ctx, "Depth and stencil attachments must be the same image", -1);
1256 return;
1257 }
1258
1259 /* Provisionally set status = COMPLETE ... */
1260 fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
1261
1262 /* ... but the driver may say the FB is incomplete.
1263 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1264 * if anything.
1265 */
1266 if (ctx->Driver.ValidateFramebuffer) {
1267 ctx->Driver.ValidateFramebuffer(ctx, fb);
1268 if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
1269 fbo_incomplete(ctx, "driver marked FBO as incomplete", -1);
1270 return;
1271 }
1272 }
1273
1274 /*
1275 * Note that if ARB_framebuffer_object is supported and the attached
1276 * renderbuffers/textures are different sizes, the framebuffer
1277 * width/height will be set to the smallest width/height.
1278 */
1279 if (numImages != 0) {
1280 fb->Width = minWidth;
1281 fb->Height = minHeight;
1282 }
1283
1284 /* finally, update the visual info for the framebuffer */
1285 _mesa_update_framebuffer_visual(ctx, fb);
1286 }
1287
1288
1289 GLboolean GLAPIENTRY
1290 _mesa_IsRenderbuffer(GLuint renderbuffer)
1291 {
1292 GET_CURRENT_CONTEXT(ctx);
1293 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
1294 if (renderbuffer) {
1295 struct gl_renderbuffer *rb =
1296 _mesa_lookup_renderbuffer(ctx, renderbuffer);
1297 if (rb != NULL && rb != &DummyRenderbuffer)
1298 return GL_TRUE;
1299 }
1300 return GL_FALSE;
1301 }
1302
1303
1304 static struct gl_renderbuffer *
1305 allocate_renderbuffer_locked(struct gl_context *ctx, GLuint renderbuffer,
1306 const char *func)
1307 {
1308 struct gl_renderbuffer *newRb;
1309
1310 /* create new renderbuffer object */
1311 newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer);
1312 if (!newRb) {
1313 _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
1314 return NULL;
1315 }
1316 assert(newRb->AllocStorage);
1317 _mesa_HashInsertLocked(ctx->Shared->RenderBuffers, renderbuffer, newRb);
1318 newRb->RefCount = 1; /* referenced by hash table */
1319
1320 return newRb;
1321 }
1322
1323
1324 static void
1325 bind_renderbuffer(GLenum target, GLuint renderbuffer, bool allow_user_names)
1326 {
1327 struct gl_renderbuffer *newRb;
1328 GET_CURRENT_CONTEXT(ctx);
1329
1330 if (target != GL_RENDERBUFFER_EXT) {
1331 _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)");
1332 return;
1333 }
1334
1335 /* No need to flush here since the render buffer binding has no
1336 * effect on rendering state.
1337 */
1338
1339 if (renderbuffer) {
1340 newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
1341 if (newRb == &DummyRenderbuffer) {
1342 /* ID was reserved, but no real renderbuffer object made yet */
1343 newRb = NULL;
1344 }
1345 else if (!newRb && !allow_user_names) {
1346 /* All RB IDs must be Gen'd */
1347 _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)");
1348 return;
1349 }
1350
1351 if (!newRb) {
1352 _mesa_HashLockMutex(ctx->Shared->RenderBuffers);
1353 newRb = allocate_renderbuffer_locked(ctx, renderbuffer,
1354 "glBindRenderbufferEXT");
1355 _mesa_HashUnlockMutex(ctx->Shared->RenderBuffers);
1356 }
1357 }
1358 else {
1359 newRb = NULL;
1360 }
1361
1362 assert(newRb != &DummyRenderbuffer);
1363
1364 _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb);
1365 }
1366
1367 void GLAPIENTRY
1368 _mesa_BindRenderbuffer(GLenum target, GLuint renderbuffer)
1369 {
1370 GET_CURRENT_CONTEXT(ctx);
1371
1372 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1373 * entry point, but they allow the use of user-generated names.
1374 */
1375 bind_renderbuffer(target, renderbuffer, _mesa_is_gles(ctx));
1376 }
1377
1378 void GLAPIENTRY
1379 _mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
1380 {
1381 /* This function should not be in the dispatch table for core profile /
1382 * OpenGL 3.1, so execution should never get here in those cases -- no
1383 * need for an explicit test.
1384 */
1385 bind_renderbuffer(target, renderbuffer, true);
1386 }
1387
1388 /**
1389 * ARB_framebuffer_no_attachment - Application passes requested param's
1390 * here. NOTE: NumSamples requested need not be _NumSamples which is
1391 * what the hw supports.
1392 */
1393 static void
1394 framebuffer_parameteri(struct gl_context *ctx, struct gl_framebuffer *fb,
1395 GLenum pname, GLint param, const char *func)
1396 {
1397 switch (pname) {
1398 case GL_FRAMEBUFFER_DEFAULT_WIDTH:
1399 if (param < 0 || param > ctx->Const.MaxFramebufferWidth)
1400 _mesa_error(ctx, GL_INVALID_VALUE, "%s", func);
1401 else
1402 fb->DefaultGeometry.Width = param;
1403 break;
1404 case GL_FRAMEBUFFER_DEFAULT_HEIGHT:
1405 if (param < 0 || param > ctx->Const.MaxFramebufferHeight)
1406 _mesa_error(ctx, GL_INVALID_VALUE, "%s", func);
1407 else
1408 fb->DefaultGeometry.Height = param;
1409 break;
1410 case GL_FRAMEBUFFER_DEFAULT_LAYERS:
1411 /*
1412 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1413 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1414 */
1415 if (_mesa_is_gles31(ctx) && !ctx->Extensions.OES_geometry_shader) {
1416 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname);
1417 break;
1418 }
1419 if (param < 0 || param > ctx->Const.MaxFramebufferLayers)
1420 _mesa_error(ctx, GL_INVALID_VALUE, "%s", func);
1421 else
1422 fb->DefaultGeometry.Layers = param;
1423 break;
1424 case GL_FRAMEBUFFER_DEFAULT_SAMPLES:
1425 if (param < 0 || param > ctx->Const.MaxFramebufferSamples)
1426 _mesa_error(ctx, GL_INVALID_VALUE, "%s", func);
1427 else
1428 fb->DefaultGeometry.NumSamples = param;
1429 break;
1430 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS:
1431 fb->DefaultGeometry.FixedSampleLocations = param;
1432 break;
1433 default:
1434 _mesa_error(ctx, GL_INVALID_ENUM,
1435 "%s(pname=0x%x)", func, pname);
1436 }
1437
1438 invalidate_framebuffer(fb);
1439 ctx->NewState |= _NEW_BUFFERS;
1440 }
1441
1442 void GLAPIENTRY
1443 _mesa_FramebufferParameteri(GLenum target, GLenum pname, GLint param)
1444 {
1445 GET_CURRENT_CONTEXT(ctx);
1446 struct gl_framebuffer *fb;
1447
1448 if (!ctx->Extensions.ARB_framebuffer_no_attachments) {
1449 _mesa_error(ctx, GL_INVALID_OPERATION,
1450 "glFramebufferParameteriv not supported "
1451 "(ARB_framebuffer_no_attachments not implemented)");
1452 return;
1453 }
1454
1455 fb = get_framebuffer_target(ctx, target);
1456 if (!fb) {
1457 _mesa_error(ctx, GL_INVALID_ENUM,
1458 "glFramebufferParameteri(target=0x%x)", target);
1459 return;
1460 }
1461
1462 /* check framebuffer binding */
1463 if (_mesa_is_winsys_fbo(fb)) {
1464 _mesa_error(ctx, GL_INVALID_OPERATION,
1465 "glFramebufferParameteri");
1466 return;
1467 }
1468
1469 framebuffer_parameteri(ctx, fb, pname, param, "glFramebufferParameteri");
1470 }
1471
1472 static void
1473 get_framebuffer_parameteriv(struct gl_context *ctx, struct gl_framebuffer *fb,
1474 GLenum pname, GLint *params, const char *func)
1475 {
1476 switch (pname) {
1477 case GL_FRAMEBUFFER_DEFAULT_WIDTH:
1478 *params = fb->DefaultGeometry.Width;
1479 break;
1480 case GL_FRAMEBUFFER_DEFAULT_HEIGHT:
1481 *params = fb->DefaultGeometry.Height;
1482 break;
1483 case GL_FRAMEBUFFER_DEFAULT_LAYERS:
1484 /*
1485 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1486 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1487 */
1488 if (_mesa_is_gles31(ctx) && !ctx->Extensions.OES_geometry_shader) {
1489 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", func, pname);
1490 break;
1491 }
1492 *params = fb->DefaultGeometry.Layers;
1493 break;
1494 case GL_FRAMEBUFFER_DEFAULT_SAMPLES:
1495 *params = fb->DefaultGeometry.NumSamples;
1496 break;
1497 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS:
1498 *params = fb->DefaultGeometry.FixedSampleLocations;
1499 break;
1500 default:
1501 _mesa_error(ctx, GL_INVALID_ENUM,
1502 "%s(pname=0x%x)", func, pname);
1503 }
1504 }
1505
1506 void GLAPIENTRY
1507 _mesa_GetFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
1508 {
1509 GET_CURRENT_CONTEXT(ctx);
1510 struct gl_framebuffer *fb;
1511
1512 if (!ctx->Extensions.ARB_framebuffer_no_attachments) {
1513 _mesa_error(ctx, GL_INVALID_OPERATION,
1514 "glGetFramebufferParameteriv not supported "
1515 "(ARB_framebuffer_no_attachments not implemented)");
1516 return;
1517 }
1518
1519 fb = get_framebuffer_target(ctx, target);
1520 if (!fb) {
1521 _mesa_error(ctx, GL_INVALID_ENUM,
1522 "glGetFramebufferParameteriv(target=0x%x)", target);
1523 return;
1524 }
1525
1526 /* check framebuffer binding */
1527 if (_mesa_is_winsys_fbo(fb)) {
1528 _mesa_error(ctx, GL_INVALID_OPERATION,
1529 "glGetFramebufferParameteriv");
1530 return;
1531 }
1532
1533 get_framebuffer_parameteriv(ctx, fb, pname, params,
1534 "glGetFramebufferParameteriv");
1535 }
1536
1537
1538 /**
1539 * Remove the specified renderbuffer or texture from any attachment point in
1540 * the framebuffer.
1541 *
1542 * \returns
1543 * \c true if the renderbuffer was detached from an attachment point. \c
1544 * false otherwise.
1545 */
1546 bool
1547 _mesa_detach_renderbuffer(struct gl_context *ctx,
1548 struct gl_framebuffer *fb,
1549 const void *att)
1550 {
1551 unsigned i;
1552 bool progress = false;
1553
1554 for (i = 0; i < BUFFER_COUNT; i++) {
1555 if (fb->Attachment[i].Texture == att
1556 || fb->Attachment[i].Renderbuffer == att) {
1557 remove_attachment(ctx, &fb->Attachment[i]);
1558 progress = true;
1559 }
1560 }
1561
1562 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1563 * Completeness," of the OpenGL 3.1 spec says:
1564 *
1565 * "Performing any of the following actions may change whether the
1566 * framebuffer is considered complete or incomplete:
1567 *
1568 * ...
1569 *
1570 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1571 * containing an image that is attached to a framebuffer object
1572 * that is bound to the framebuffer."
1573 */
1574 if (progress)
1575 invalidate_framebuffer(fb);
1576
1577 return progress;
1578 }
1579
1580
1581 void GLAPIENTRY
1582 _mesa_DeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
1583 {
1584 GLint i;
1585 GET_CURRENT_CONTEXT(ctx);
1586
1587 if (n < 0) {
1588 _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteRenderbuffers(n < 0)");
1589 return;
1590 }
1591
1592 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1593
1594 for (i = 0; i < n; i++) {
1595 if (renderbuffers[i] > 0) {
1596 struct gl_renderbuffer *rb;
1597 rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]);
1598 if (rb) {
1599 /* check if deleting currently bound renderbuffer object */
1600 if (rb == ctx->CurrentRenderbuffer) {
1601 /* bind default */
1602 assert(rb->RefCount >= 2);
1603 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
1604 }
1605
1606 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1607 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1608 * of the OpenGL 3.1 spec says:
1609 *
1610 * "If a renderbuffer object is deleted while its image is
1611 * attached to one or more attachment points in the currently
1612 * bound framebuffer, then it is as if FramebufferRenderbuffer
1613 * had been called, with a renderbuffer of 0, for each
1614 * attachment point to which this image was attached in the
1615 * currently bound framebuffer. In other words, this
1616 * renderbuffer image is first detached from all attachment
1617 * points in the currently bound framebuffer. Note that the
1618 * renderbuffer image is specifically not detached from any
1619 * non-bound framebuffers. Detaching the image from any
1620 * non-bound framebuffers is the responsibility of the
1621 * application.
1622 */
1623 if (_mesa_is_user_fbo(ctx->DrawBuffer)) {
1624 _mesa_detach_renderbuffer(ctx, ctx->DrawBuffer, rb);
1625 }
1626 if (_mesa_is_user_fbo(ctx->ReadBuffer)
1627 && ctx->ReadBuffer != ctx->DrawBuffer) {
1628 _mesa_detach_renderbuffer(ctx, ctx->ReadBuffer, rb);
1629 }
1630
1631 /* Remove from hash table immediately, to free the ID.
1632 * But the object will not be freed until it's no longer
1633 * referenced anywhere else.
1634 */
1635 _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]);
1636
1637 if (rb != &DummyRenderbuffer) {
1638 /* no longer referenced by hash table */
1639 _mesa_reference_renderbuffer(&rb, NULL);
1640 }
1641 }
1642 }
1643 }
1644 }
1645
1646 static void
1647 create_render_buffers(struct gl_context *ctx, GLsizei n, GLuint *renderbuffers,
1648 bool dsa)
1649 {
1650 const char *func = dsa ? "glCreateRenderbuffers" : "glGenRenderbuffers";
1651 GLuint first;
1652 GLint i;
1653
1654 if (n < 0) {
1655 _mesa_error(ctx, GL_INVALID_VALUE, "%s(n<0)", func);
1656 return;
1657 }
1658
1659 if (!renderbuffers)
1660 return;
1661
1662 _mesa_HashLockMutex(ctx->Shared->RenderBuffers);
1663
1664 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n);
1665
1666 for (i = 0; i < n; i++) {
1667 GLuint name = first + i;
1668 renderbuffers[i] = name;
1669
1670 if (dsa) {
1671 allocate_renderbuffer_locked(ctx, name, func);
1672 } else {
1673 /* insert a dummy renderbuffer into the hash table */
1674 _mesa_HashInsertLocked(ctx->Shared->RenderBuffers, name,
1675 &DummyRenderbuffer);
1676 }
1677 }
1678
1679 _mesa_HashUnlockMutex(ctx->Shared->RenderBuffers);
1680 }
1681
1682
1683 void GLAPIENTRY
1684 _mesa_GenRenderbuffers(GLsizei n, GLuint *renderbuffers)
1685 {
1686 GET_CURRENT_CONTEXT(ctx);
1687 create_render_buffers(ctx, n, renderbuffers, false);
1688 }
1689
1690
1691 void GLAPIENTRY
1692 _mesa_CreateRenderbuffers(GLsizei n, GLuint *renderbuffers)
1693 {
1694 GET_CURRENT_CONTEXT(ctx);
1695 create_render_buffers(ctx, n, renderbuffers, true);
1696 }
1697
1698
1699 /**
1700 * Given an internal format token for a render buffer, return the
1701 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1702 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1703 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1704 *
1705 * This is similar to _mesa_base_tex_format() but the set of valid
1706 * internal formats is different.
1707 *
1708 * Note that even if a format is determined to be legal here, validation
1709 * of the FBO may fail if the format is not supported by the driver/GPU.
1710 *
1711 * \param internalFormat as passed to glRenderbufferStorage()
1712 * \return the base internal format, or 0 if internalFormat is illegal
1713 */
1714 GLenum
1715 _mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat)
1716 {
1717 /*
1718 * Notes: some formats such as alpha, luminance, etc. were added
1719 * with GL_ARB_framebuffer_object.
1720 */
1721 switch (internalFormat) {
1722 case GL_ALPHA:
1723 case GL_ALPHA4:
1724 case GL_ALPHA8:
1725 case GL_ALPHA12:
1726 case GL_ALPHA16:
1727 return (ctx->API == API_OPENGL_COMPAT &&
1728 ctx->Extensions.ARB_framebuffer_object) ? GL_ALPHA : 0;
1729 case GL_LUMINANCE:
1730 case GL_LUMINANCE4:
1731 case GL_LUMINANCE8:
1732 case GL_LUMINANCE12:
1733 case GL_LUMINANCE16:
1734 return (ctx->API == API_OPENGL_COMPAT &&
1735 ctx->Extensions.ARB_framebuffer_object) ? GL_LUMINANCE : 0;
1736 case GL_LUMINANCE_ALPHA:
1737 case GL_LUMINANCE4_ALPHA4:
1738 case GL_LUMINANCE6_ALPHA2:
1739 case GL_LUMINANCE8_ALPHA8:
1740 case GL_LUMINANCE12_ALPHA4:
1741 case GL_LUMINANCE12_ALPHA12:
1742 case GL_LUMINANCE16_ALPHA16:
1743 return (ctx->API == API_OPENGL_COMPAT &&
1744 ctx->Extensions.ARB_framebuffer_object) ? GL_LUMINANCE_ALPHA : 0;
1745 case GL_INTENSITY:
1746 case GL_INTENSITY4:
1747 case GL_INTENSITY8:
1748 case GL_INTENSITY12:
1749 case GL_INTENSITY16:
1750 return (ctx->API == API_OPENGL_COMPAT &&
1751 ctx->Extensions.ARB_framebuffer_object) ? GL_INTENSITY : 0;
1752 case GL_RGB8:
1753 return GL_RGB;
1754 case GL_RGB:
1755 case GL_R3_G3_B2:
1756 case GL_RGB4:
1757 case GL_RGB5:
1758 case GL_RGB10:
1759 case GL_RGB12:
1760 case GL_RGB16:
1761 return _mesa_is_desktop_gl(ctx) ? GL_RGB : 0;
1762 case GL_SRGB8_EXT:
1763 return _mesa_is_desktop_gl(ctx) ? GL_RGB : 0;
1764 case GL_RGBA4:
1765 case GL_RGB5_A1:
1766 case GL_RGBA8:
1767 return GL_RGBA;
1768 case GL_RGBA:
1769 case GL_RGBA2:
1770 case GL_RGBA12:
1771 case GL_RGBA16:
1772 return _mesa_is_desktop_gl(ctx) ? GL_RGBA : 0;
1773 case GL_RGB10_A2:
1774 case GL_SRGB8_ALPHA8_EXT:
1775 return _mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx) ? GL_RGBA : 0;
1776 case GL_STENCIL_INDEX:
1777 case GL_STENCIL_INDEX1_EXT:
1778 case GL_STENCIL_INDEX4_EXT:
1779 case GL_STENCIL_INDEX16_EXT:
1780 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1781 * OpenGL ES, but Mesa does not currently support them.
1782 */
1783 return _mesa_is_desktop_gl(ctx) ? GL_STENCIL_INDEX : 0;
1784 case GL_STENCIL_INDEX8_EXT:
1785 return GL_STENCIL_INDEX;
1786 case GL_DEPTH_COMPONENT:
1787 case GL_DEPTH_COMPONENT32:
1788 return _mesa_is_desktop_gl(ctx) ? GL_DEPTH_COMPONENT : 0;
1789 case GL_DEPTH_COMPONENT16:
1790 case GL_DEPTH_COMPONENT24:
1791 return GL_DEPTH_COMPONENT;
1792 case GL_DEPTH_STENCIL:
1793 return _mesa_is_desktop_gl(ctx) ? GL_DEPTH_STENCIL : 0;
1794 case GL_DEPTH24_STENCIL8:
1795 return GL_DEPTH_STENCIL;
1796 case GL_DEPTH_COMPONENT32F:
1797 return ctx->Version >= 30
1798 || (ctx->API == API_OPENGL_COMPAT &&
1799 ctx->Extensions.ARB_depth_buffer_float)
1800 ? GL_DEPTH_COMPONENT : 0;
1801 case GL_DEPTH32F_STENCIL8:
1802 return ctx->Version >= 30
1803 || (ctx->API == API_OPENGL_COMPAT &&
1804 ctx->Extensions.ARB_depth_buffer_float)
1805 ? GL_DEPTH_STENCIL : 0;
1806 case GL_RED:
1807 case GL_R16:
1808 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_rg
1809 ? GL_RED : 0;
1810 case GL_R8:
1811 return ctx->API != API_OPENGLES && ctx->Extensions.ARB_texture_rg
1812 ? GL_RED : 0;
1813 case GL_RG:
1814 case GL_RG16:
1815 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_rg
1816 ? GL_RG : 0;
1817 case GL_RG8:
1818 return ctx->API != API_OPENGLES && ctx->Extensions.ARB_texture_rg
1819 ? GL_RG : 0;
1820 /* signed normalized texture formats */
1821 case GL_RED_SNORM:
1822 case GL_R8_SNORM:
1823 case GL_R16_SNORM:
1824 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1825 ? GL_RED : 0;
1826 case GL_RG_SNORM:
1827 case GL_RG8_SNORM:
1828 case GL_RG16_SNORM:
1829 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1830 ? GL_RG : 0;
1831 case GL_RGB_SNORM:
1832 case GL_RGB8_SNORM:
1833 case GL_RGB16_SNORM:
1834 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1835 ? GL_RGB : 0;
1836 case GL_RGBA_SNORM:
1837 case GL_RGBA8_SNORM:
1838 case GL_RGBA16_SNORM:
1839 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1840 ? GL_RGBA : 0;
1841 case GL_ALPHA_SNORM:
1842 case GL_ALPHA8_SNORM:
1843 case GL_ALPHA16_SNORM:
1844 return ctx->API == API_OPENGL_COMPAT &&
1845 ctx->Extensions.EXT_texture_snorm &&
1846 ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
1847 case GL_LUMINANCE_SNORM:
1848 case GL_LUMINANCE8_SNORM:
1849 case GL_LUMINANCE16_SNORM:
1850 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1851 ? GL_LUMINANCE : 0;
1852 case GL_LUMINANCE_ALPHA_SNORM:
1853 case GL_LUMINANCE8_ALPHA8_SNORM:
1854 case GL_LUMINANCE16_ALPHA16_SNORM:
1855 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1856 ? GL_LUMINANCE_ALPHA : 0;
1857 case GL_INTENSITY_SNORM:
1858 case GL_INTENSITY8_SNORM:
1859 case GL_INTENSITY16_SNORM:
1860 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_snorm
1861 ? GL_INTENSITY : 0;
1862
1863 case GL_R16F:
1864 case GL_R32F:
1865 return ((_mesa_is_desktop_gl(ctx) &&
1866 ctx->Extensions.ARB_texture_rg &&
1867 ctx->Extensions.ARB_texture_float) ||
1868 _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ )
1869 ? GL_RED : 0;
1870 case GL_RG16F:
1871 case GL_RG32F:
1872 return ((_mesa_is_desktop_gl(ctx) &&
1873 ctx->Extensions.ARB_texture_rg &&
1874 ctx->Extensions.ARB_texture_float) ||
1875 _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ )
1876 ? GL_RG : 0;
1877 case GL_RGB16F:
1878 case GL_RGB32F:
1879 return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_float)
1880 ? GL_RGB : 0;
1881 case GL_RGBA16F:
1882 case GL_RGBA32F:
1883 return ((_mesa_is_desktop_gl(ctx) &&
1884 ctx->Extensions.ARB_texture_float) ||
1885 _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ )
1886 ? GL_RGBA : 0;
1887 case GL_ALPHA16F_ARB:
1888 case GL_ALPHA32F_ARB:
1889 return ctx->API == API_OPENGL_COMPAT &&
1890 ctx->Extensions.ARB_texture_float &&
1891 ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
1892 case GL_LUMINANCE16F_ARB:
1893 case GL_LUMINANCE32F_ARB:
1894 return ctx->API == API_OPENGL_COMPAT &&
1895 ctx->Extensions.ARB_texture_float &&
1896 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
1897 case GL_LUMINANCE_ALPHA16F_ARB:
1898 case GL_LUMINANCE_ALPHA32F_ARB:
1899 return ctx->API == API_OPENGL_COMPAT &&
1900 ctx->Extensions.ARB_texture_float &&
1901 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
1902 case GL_INTENSITY16F_ARB:
1903 case GL_INTENSITY32F_ARB:
1904 return ctx->API == API_OPENGL_COMPAT &&
1905 ctx->Extensions.ARB_texture_float &&
1906 ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
1907 case GL_R11F_G11F_B10F:
1908 return ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_packed_float) ||
1909 _mesa_is_gles3(ctx) /* EXT_color_buffer_float */ )
1910 ? GL_RGB : 0;
1911
1912 case GL_RGBA8UI_EXT:
1913 case GL_RGBA16UI_EXT:
1914 case GL_RGBA32UI_EXT:
1915 case GL_RGBA8I_EXT:
1916 case GL_RGBA16I_EXT:
1917 case GL_RGBA32I_EXT:
1918 return ctx->Version >= 30
1919 || (_mesa_is_desktop_gl(ctx) &&
1920 ctx->Extensions.EXT_texture_integer) ? GL_RGBA : 0;
1921
1922 case GL_RGB8UI_EXT:
1923 case GL_RGB16UI_EXT:
1924 case GL_RGB32UI_EXT:
1925 case GL_RGB8I_EXT:
1926 case GL_RGB16I_EXT:
1927 case GL_RGB32I_EXT:
1928 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_integer
1929 ? GL_RGB : 0;
1930 case GL_R8UI:
1931 case GL_R8I:
1932 case GL_R16UI:
1933 case GL_R16I:
1934 case GL_R32UI:
1935 case GL_R32I:
1936 return ctx->Version >= 30
1937 || (_mesa_is_desktop_gl(ctx) &&
1938 ctx->Extensions.ARB_texture_rg &&
1939 ctx->Extensions.EXT_texture_integer) ? GL_RED : 0;
1940
1941 case GL_RG8UI:
1942 case GL_RG8I:
1943 case GL_RG16UI:
1944 case GL_RG16I:
1945 case GL_RG32UI:
1946 case GL_RG32I:
1947 return ctx->Version >= 30
1948 || (_mesa_is_desktop_gl(ctx) &&
1949 ctx->Extensions.ARB_texture_rg &&
1950 ctx->Extensions.EXT_texture_integer) ? GL_RG : 0;
1951
1952 case GL_INTENSITY8I_EXT:
1953 case GL_INTENSITY8UI_EXT:
1954 case GL_INTENSITY16I_EXT:
1955 case GL_INTENSITY16UI_EXT:
1956 case GL_INTENSITY32I_EXT:
1957 case GL_INTENSITY32UI_EXT:
1958 return ctx->API == API_OPENGL_COMPAT &&
1959 ctx->Extensions.EXT_texture_integer &&
1960 ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
1961
1962 case GL_LUMINANCE8I_EXT:
1963 case GL_LUMINANCE8UI_EXT:
1964 case GL_LUMINANCE16I_EXT:
1965 case GL_LUMINANCE16UI_EXT:
1966 case GL_LUMINANCE32I_EXT:
1967 case GL_LUMINANCE32UI_EXT:
1968 return ctx->API == API_OPENGL_COMPAT &&
1969 ctx->Extensions.EXT_texture_integer &&
1970 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
1971
1972 case GL_LUMINANCE_ALPHA8I_EXT:
1973 case GL_LUMINANCE_ALPHA8UI_EXT:
1974 case GL_LUMINANCE_ALPHA16I_EXT:
1975 case GL_LUMINANCE_ALPHA16UI_EXT:
1976 case GL_LUMINANCE_ALPHA32I_EXT:
1977 case GL_LUMINANCE_ALPHA32UI_EXT:
1978 return ctx->API == API_OPENGL_COMPAT &&
1979 ctx->Extensions.EXT_texture_integer &&
1980 ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
1981
1982 case GL_ALPHA8I_EXT:
1983 case GL_ALPHA8UI_EXT:
1984 case GL_ALPHA16I_EXT:
1985 case GL_ALPHA16UI_EXT:
1986 case GL_ALPHA32I_EXT:
1987 case GL_ALPHA32UI_EXT:
1988 return ctx->API == API_OPENGL_COMPAT &&
1989 ctx->Extensions.EXT_texture_integer &&
1990 ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
1991
1992 case GL_RGB10_A2UI:
1993 return (_mesa_is_desktop_gl(ctx) &&
1994 ctx->Extensions.ARB_texture_rgb10_a2ui)
1995 || _mesa_is_gles3(ctx) ? GL_RGBA : 0;
1996
1997 case GL_RGB565:
1998 return _mesa_is_gles(ctx) || ctx->Extensions.ARB_ES2_compatibility
1999 ? GL_RGB : 0;
2000 default:
2001 return 0;
2002 }
2003 }
2004
2005
2006 /**
2007 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2008 */
2009 static void
2010 invalidate_rb(GLuint key, void *data, void *userData)
2011 {
2012 struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
2013 struct gl_renderbuffer *rb = (struct gl_renderbuffer *) userData;
2014
2015 /* If this is a user-created FBO */
2016 if (_mesa_is_user_fbo(fb)) {
2017 GLuint i;
2018 for (i = 0; i < BUFFER_COUNT; i++) {
2019 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
2020 if (att->Type == GL_RENDERBUFFER &&
2021 att->Renderbuffer == rb) {
2022 /* Mark fb status as indeterminate to force re-validation */
2023 fb->_Status = 0;
2024 return;
2025 }
2026 }
2027 }
2028 }
2029
2030
2031 /** sentinal value, see below */
2032 #define NO_SAMPLES 1000
2033
2034 void
2035 _mesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
2036 GLenum internalFormat, GLsizei width,
2037 GLsizei height, GLsizei samples)
2038 {
2039 const GLenum baseFormat = _mesa_base_fbo_format(ctx, internalFormat);
2040
2041 assert(baseFormat != 0);
2042 assert(width >= 0 && width <= (GLsizei) ctx->Const.MaxRenderbufferSize);
2043 assert(height >= 0 && height <= (GLsizei) ctx->Const.MaxRenderbufferSize);
2044 assert(samples != NO_SAMPLES);
2045 if (samples != 0) {
2046 assert(samples > 0);
2047 assert(_mesa_check_sample_count(ctx, GL_RENDERBUFFER,
2048 internalFormat, samples) == GL_NO_ERROR);
2049 }
2050
2051 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2052
2053 if (rb->InternalFormat == internalFormat &&
2054 rb->Width == (GLuint) width &&
2055 rb->Height == (GLuint) height &&
2056 rb->NumSamples == samples) {
2057 /* no change in allocation needed */
2058 return;
2059 }
2060
2061 /* These MUST get set by the AllocStorage func */
2062 rb->Format = MESA_FORMAT_NONE;
2063 rb->NumSamples = samples;
2064
2065 /* Now allocate the storage */
2066 assert(rb->AllocStorage);
2067 if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) {
2068 /* No error - check/set fields now */
2069 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2070 assert(rb->Width == (GLuint) width);
2071 assert(rb->Height == (GLuint) height);
2072 rb->InternalFormat = internalFormat;
2073 rb->_BaseFormat = baseFormat;
2074 assert(rb->_BaseFormat != 0);
2075 }
2076 else {
2077 /* Probably ran out of memory - clear the fields */
2078 rb->Width = 0;
2079 rb->Height = 0;
2080 rb->Format = MESA_FORMAT_NONE;
2081 rb->InternalFormat = GL_NONE;
2082 rb->_BaseFormat = GL_NONE;
2083 rb->NumSamples = 0;
2084 }
2085
2086 /* Invalidate the framebuffers the renderbuffer is attached in. */
2087 if (rb->AttachedAnytime) {
2088 _mesa_HashWalk(ctx->Shared->FrameBuffers, invalidate_rb, rb);
2089 }
2090 }
2091
2092 /**
2093 * Helper function used by renderbuffer_storage_direct() and
2094 * renderbuffer_storage_target().
2095 * samples will be NO_SAMPLES if called by a non-multisample function.
2096 */
2097 static void
2098 renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
2099 GLenum internalFormat, GLsizei width,
2100 GLsizei height, GLsizei samples, const char *func)
2101 {
2102 GLenum baseFormat;
2103 GLenum sample_count_error;
2104
2105 baseFormat = _mesa_base_fbo_format(ctx, internalFormat);
2106 if (baseFormat == 0) {
2107 _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat=%s)",
2108 func, _mesa_enum_to_string(internalFormat));
2109 return;
2110 }
2111
2112 if (width < 0 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) {
2113 _mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid width %d)", func,
2114 width);
2115 return;
2116 }
2117
2118 if (height < 0 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) {
2119 _mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid height %d)", func,
2120 height);
2121 return;
2122 }
2123
2124 if (samples == NO_SAMPLES) {
2125 /* NumSamples == 0 indicates non-multisampling */
2126 samples = 0;
2127 }
2128 else {
2129 /* check the sample count;
2130 * note: driver may choose to use more samples than what's requested
2131 */
2132 sample_count_error = _mesa_check_sample_count(ctx, GL_RENDERBUFFER,
2133 internalFormat, samples);
2134
2135 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2136 *
2137 * "If a negative number is provided where an argument of type sizei or
2138 * sizeiptr is specified, the error INVALID VALUE is generated."
2139 */
2140 if (samples < 0) {
2141 sample_count_error = GL_INVALID_VALUE;
2142 }
2143
2144 if (sample_count_error != GL_NO_ERROR) {
2145 _mesa_error(ctx, sample_count_error, "%s(samples=%d)", func, samples);
2146 return;
2147 }
2148 }
2149
2150 _mesa_renderbuffer_storage(ctx, rb, internalFormat, width, height, samples);
2151 }
2152
2153 /**
2154 * Helper function used by _mesa_NamedRenderbufferStorage*().
2155 * samples will be NO_SAMPLES if called by a non-multisample function.
2156 */
2157 static void
2158 renderbuffer_storage_named(GLuint renderbuffer, GLenum internalFormat,
2159 GLsizei width, GLsizei height, GLsizei samples,
2160 const char *func)
2161 {
2162 GET_CURRENT_CONTEXT(ctx);
2163
2164 if (MESA_VERBOSE & VERBOSE_API) {
2165 if (samples == NO_SAMPLES)
2166 _mesa_debug(ctx, "%s(%u, %s, %d, %d)\n",
2167 func, renderbuffer,
2168 _mesa_enum_to_string(internalFormat),
2169 width, height);
2170 else
2171 _mesa_debug(ctx, "%s(%u, %s, %d, %d, %d)\n",
2172 func, renderbuffer,
2173 _mesa_enum_to_string(internalFormat),
2174 width, height, samples);
2175 }
2176
2177 struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
2178 if (!rb || rb == &DummyRenderbuffer) {
2179 /* ID was reserved, but no real renderbuffer object made yet */
2180 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid renderbuffer %u)",
2181 func, renderbuffer);
2182 return;
2183 }
2184
2185 renderbuffer_storage(ctx, rb, internalFormat, width, height, samples, func);
2186 }
2187
2188 /**
2189 * Helper function used by _mesa_RenderbufferStorage() and
2190 * _mesa_RenderbufferStorageMultisample().
2191 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2192 */
2193 static void
2194 renderbuffer_storage_target(GLenum target, GLenum internalFormat,
2195 GLsizei width, GLsizei height, GLsizei samples,
2196 const char *func)
2197 {
2198 GET_CURRENT_CONTEXT(ctx);
2199
2200 if (MESA_VERBOSE & VERBOSE_API) {
2201 if (samples == NO_SAMPLES)
2202 _mesa_debug(ctx, "%s(%s, %s, %d, %d)\n",
2203 func,
2204 _mesa_enum_to_string(target),
2205 _mesa_enum_to_string(internalFormat),
2206 width, height);
2207 else
2208 _mesa_debug(ctx, "%s(%s, %s, %d, %d, %d)\n",
2209 func,
2210 _mesa_enum_to_string(target),
2211 _mesa_enum_to_string(internalFormat),
2212 width, height, samples);
2213 }
2214
2215 if (target != GL_RENDERBUFFER_EXT) {
2216 _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
2217 return;
2218 }
2219
2220 if (!ctx->CurrentRenderbuffer) {
2221 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no renderbuffer bound)",
2222 func);
2223 return;
2224 }
2225
2226 renderbuffer_storage(ctx, ctx->CurrentRenderbuffer, internalFormat, width,
2227 height, samples, func);
2228 }
2229
2230
2231 void GLAPIENTRY
2232 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
2233 {
2234 struct gl_renderbuffer *rb;
2235 GET_CURRENT_CONTEXT(ctx);
2236
2237 if (!ctx->Extensions.OES_EGL_image) {
2238 _mesa_error(ctx, GL_INVALID_OPERATION,
2239 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2240 return;
2241 }
2242
2243 if (target != GL_RENDERBUFFER) {
2244 _mesa_error(ctx, GL_INVALID_ENUM,
2245 "EGLImageTargetRenderbufferStorageOES");
2246 return;
2247 }
2248
2249 rb = ctx->CurrentRenderbuffer;
2250 if (!rb) {
2251 _mesa_error(ctx, GL_INVALID_OPERATION,
2252 "EGLImageTargetRenderbufferStorageOES");
2253 return;
2254 }
2255
2256 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2257
2258 ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image);
2259 }
2260
2261
2262 /**
2263 * Helper function for _mesa_GetRenderbufferParameteriv() and
2264 * _mesa_GetFramebufferAttachmentParameteriv()
2265 * We have to be careful to respect the base format. For example, if a
2266 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2267 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2268 * we need to return zero.
2269 */
2270 static GLint
2271 get_component_bits(GLenum pname, GLenum baseFormat, mesa_format format)
2272 {
2273 if (_mesa_base_format_has_channel(baseFormat, pname))
2274 return _mesa_get_format_bits(format, pname);
2275 else
2276 return 0;
2277 }
2278
2279
2280
2281 void GLAPIENTRY
2282 _mesa_RenderbufferStorage(GLenum target, GLenum internalFormat,
2283 GLsizei width, GLsizei height)
2284 {
2285 /* GL_ARB_fbo says calling this function is equivalent to calling
2286 * glRenderbufferStorageMultisample() with samples=0. We pass in
2287 * a token value here just for error reporting purposes.
2288 */
2289 renderbuffer_storage_target(target, internalFormat, width, height,
2290 NO_SAMPLES, "glRenderbufferStorage");
2291 }
2292
2293
2294 void GLAPIENTRY
2295 _mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples,
2296 GLenum internalFormat,
2297 GLsizei width, GLsizei height)
2298 {
2299 renderbuffer_storage_target(target, internalFormat, width, height,
2300 samples, "glRenderbufferStorageMultisample");
2301 }
2302
2303
2304 /**
2305 * OpenGL ES version of glRenderBufferStorage.
2306 */
2307 void GLAPIENTRY
2308 _es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
2309 GLsizei width, GLsizei height)
2310 {
2311 switch (internalFormat) {
2312 case GL_RGB565:
2313 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2314 /* choose a closest format */
2315 internalFormat = GL_RGB5;
2316 break;
2317 default:
2318 break;
2319 }
2320
2321 renderbuffer_storage_target(target, internalFormat, width, height, 0,
2322 "glRenderbufferStorageEXT");
2323 }
2324
2325 void GLAPIENTRY
2326 _mesa_NamedRenderbufferStorage(GLuint renderbuffer, GLenum internalformat,
2327 GLsizei width, GLsizei height)
2328 {
2329 /* GL_ARB_fbo says calling this function is equivalent to calling
2330 * glRenderbufferStorageMultisample() with samples=0. We pass in
2331 * a token value here just for error reporting purposes.
2332 */
2333 renderbuffer_storage_named(renderbuffer, internalformat, width, height,
2334 NO_SAMPLES, "glNamedRenderbufferStorage");
2335 }
2336
2337 void GLAPIENTRY
2338 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer, GLsizei samples,
2339 GLenum internalformat,
2340 GLsizei width, GLsizei height)
2341 {
2342 renderbuffer_storage_named(renderbuffer, internalformat, width, height,
2343 samples,
2344 "glNamedRenderbufferStorageMultisample");
2345 }
2346
2347
2348 static void
2349 get_render_buffer_parameteriv(struct gl_context *ctx,
2350 struct gl_renderbuffer *rb, GLenum pname,
2351 GLint *params, const char *func)
2352 {
2353 /* No need to flush here since we're just quering state which is
2354 * not effected by rendering.
2355 */
2356
2357 switch (pname) {
2358 case GL_RENDERBUFFER_WIDTH_EXT:
2359 *params = rb->Width;
2360 return;
2361 case GL_RENDERBUFFER_HEIGHT_EXT:
2362 *params = rb->Height;
2363 return;
2364 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT:
2365 *params = rb->InternalFormat;
2366 return;
2367 case GL_RENDERBUFFER_RED_SIZE_EXT:
2368 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
2369 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
2370 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
2371 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
2372 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
2373 *params = get_component_bits(pname, rb->_BaseFormat, rb->Format);
2374 break;
2375 case GL_RENDERBUFFER_SAMPLES:
2376 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_framebuffer_object)
2377 || _mesa_is_gles3(ctx)) {
2378 *params = rb->NumSamples;
2379 break;
2380 }
2381 /* fallthrough */
2382 default:
2383 _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid pname=%s)", func,
2384 _mesa_enum_to_string(pname));
2385 return;
2386 }
2387 }
2388
2389
2390 void GLAPIENTRY
2391 _mesa_GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2392 {
2393 GET_CURRENT_CONTEXT(ctx);
2394
2395 if (target != GL_RENDERBUFFER_EXT) {
2396 _mesa_error(ctx, GL_INVALID_ENUM,
2397 "glGetRenderbufferParameterivEXT(target)");
2398 return;
2399 }
2400
2401 if (!ctx->CurrentRenderbuffer) {
2402 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetRenderbufferParameterivEXT"
2403 "(no renderbuffer bound)");
2404 return;
2405 }
2406
2407 get_render_buffer_parameteriv(ctx, ctx->CurrentRenderbuffer, pname,
2408 params, "glGetRenderbufferParameteriv");
2409 }
2410
2411
2412 void GLAPIENTRY
2413 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer, GLenum pname,
2414 GLint *params)
2415 {
2416 GET_CURRENT_CONTEXT(ctx);
2417
2418 struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
2419 if (!rb || rb == &DummyRenderbuffer) {
2420 /* ID was reserved, but no real renderbuffer object made yet */
2421 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetNamedRenderbufferParameteriv"
2422 "(invalid renderbuffer %i)", renderbuffer);
2423 return;
2424 }
2425
2426 get_render_buffer_parameteriv(ctx, rb, pname, params,
2427 "glGetNamedRenderbufferParameteriv");
2428 }
2429
2430
2431 GLboolean GLAPIENTRY
2432 _mesa_IsFramebuffer(GLuint framebuffer)
2433 {
2434 GET_CURRENT_CONTEXT(ctx);
2435 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
2436 if (framebuffer) {
2437 struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer);
2438 if (rb != NULL && rb != &DummyFramebuffer)
2439 return GL_TRUE;
2440 }
2441 return GL_FALSE;
2442 }
2443
2444
2445 /**
2446 * Check if any of the attachments of the given framebuffer are textures
2447 * (render to texture). Call ctx->Driver.RenderTexture() for such
2448 * attachments.
2449 */
2450 static void
2451 check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
2452 {
2453 GLuint i;
2454 assert(ctx->Driver.RenderTexture);
2455
2456 if (_mesa_is_winsys_fbo(fb))
2457 return; /* can't render to texture with winsys framebuffers */
2458
2459 for (i = 0; i < BUFFER_COUNT; i++) {
2460 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
2461 if (att->Texture && att->Renderbuffer->TexImage
2462 && driver_RenderTexture_is_safe(att)) {
2463 ctx->Driver.RenderTexture(ctx, fb, att);
2464 }
2465 }
2466 }
2467
2468
2469 /**
2470 * Examine all the framebuffer's attachments to see if any are textures.
2471 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2472 * notify the device driver that the texture image may have changed.
2473 */
2474 static void
2475 check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
2476 {
2477 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2478 if (_mesa_is_winsys_fbo(fb) && !ctx->Driver.BindRenderbufferTexImage)
2479 return;
2480
2481 if (ctx->Driver.FinishRenderTexture) {
2482 GLuint i;
2483 for (i = 0; i < BUFFER_COUNT; i++) {
2484 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
2485 struct gl_renderbuffer *rb = att->Renderbuffer;
2486 if (rb && rb->NeedsFinishRenderTexture) {
2487 ctx->Driver.FinishRenderTexture(ctx, rb);
2488 }
2489 }
2490 }
2491 }
2492
2493
2494 static void
2495 bind_framebuffer(GLenum target, GLuint framebuffer, bool allow_user_names)
2496 {
2497 struct gl_framebuffer *newDrawFb, *newReadFb;
2498 GLboolean bindReadBuf, bindDrawBuf;
2499 GET_CURRENT_CONTEXT(ctx);
2500
2501 switch (target) {
2502 case GL_DRAW_FRAMEBUFFER_EXT:
2503 bindDrawBuf = GL_TRUE;
2504 bindReadBuf = GL_FALSE;
2505 break;
2506 case GL_READ_FRAMEBUFFER_EXT:
2507 bindDrawBuf = GL_FALSE;
2508 bindReadBuf = GL_TRUE;
2509 break;
2510 case GL_FRAMEBUFFER_EXT:
2511 bindDrawBuf = GL_TRUE;
2512 bindReadBuf = GL_TRUE;
2513 break;
2514 default:
2515 _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
2516 return;
2517 }
2518
2519 if (framebuffer) {
2520 /* Binding a user-created framebuffer object */
2521 newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer);
2522 if (newDrawFb == &DummyFramebuffer) {
2523 /* ID was reserved, but no real framebuffer object made yet */
2524 newDrawFb = NULL;
2525 }
2526 else if (!newDrawFb && !allow_user_names) {
2527 /* All FBO IDs must be Gen'd */
2528 _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)");
2529 return;
2530 }
2531
2532 if (!newDrawFb) {
2533 /* create new framebuffer object */
2534 newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer);
2535 if (!newDrawFb) {
2536 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT");
2537 return;
2538 }
2539 _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb);
2540 }
2541 newReadFb = newDrawFb;
2542 }
2543 else {
2544 /* Binding the window system framebuffer (which was originally set
2545 * with MakeCurrent).
2546 */
2547 newDrawFb = ctx->WinSysDrawBuffer;
2548 newReadFb = ctx->WinSysReadBuffer;
2549 }
2550
2551 _mesa_bind_framebuffers(ctx,
2552 bindDrawBuf ? newDrawFb : ctx->DrawBuffer,
2553 bindReadBuf ? newReadFb : ctx->ReadBuffer);
2554 }
2555
2556 void
2557 _mesa_bind_framebuffers(struct gl_context *ctx,
2558 struct gl_framebuffer *newDrawFb,
2559 struct gl_framebuffer *newReadFb)
2560 {
2561 struct gl_framebuffer *const oldDrawFb = ctx->DrawBuffer;
2562 struct gl_framebuffer *const oldReadFb = ctx->ReadBuffer;
2563 const bool bindDrawBuf = oldDrawFb != newDrawFb;
2564 const bool bindReadBuf = oldReadFb != newReadFb;
2565
2566 assert(newDrawFb);
2567 assert(newDrawFb != &DummyFramebuffer);
2568
2569 /*
2570 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2571 *
2572 * We also check if we're beginning and/or ending render-to-texture.
2573 * When a framebuffer with texture attachments is unbound, call
2574 * ctx->Driver.FinishRenderTexture().
2575 * When a framebuffer with texture attachments is bound, call
2576 * ctx->Driver.RenderTexture().
2577 *
2578 * Note that if the ReadBuffer has texture attachments we don't consider
2579 * that a render-to-texture case.
2580 */
2581 if (bindReadBuf) {
2582 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2583
2584 /* check if old readbuffer was render-to-texture */
2585 check_end_texture_render(ctx, oldReadFb);
2586
2587 _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb);
2588 }
2589
2590 if (bindDrawBuf) {
2591 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2592
2593 /* check if old framebuffer had any texture attachments */
2594 if (oldDrawFb)
2595 check_end_texture_render(ctx, oldDrawFb);
2596
2597 /* check if newly bound framebuffer has any texture attachments */
2598 check_begin_texture_render(ctx, newDrawFb);
2599
2600 _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb);
2601 }
2602
2603 if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) {
2604 /* The few classic drivers that actually hook this function really only
2605 * want to know if the draw framebuffer changed.
2606 */
2607 ctx->Driver.BindFramebuffer(ctx,
2608 bindDrawBuf ? GL_FRAMEBUFFER : GL_READ_FRAMEBUFFER,
2609 newDrawFb, newReadFb);
2610 }
2611 }
2612
2613 void GLAPIENTRY
2614 _mesa_BindFramebuffer(GLenum target, GLuint framebuffer)
2615 {
2616 GET_CURRENT_CONTEXT(ctx);
2617
2618 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2619 * point, but they allow the use of user-generated names.
2620 */
2621 bind_framebuffer(target, framebuffer, _mesa_is_gles(ctx));
2622 }
2623
2624
2625 void GLAPIENTRY
2626 _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
2627 {
2628 /* This function should not be in the dispatch table for core profile /
2629 * OpenGL 3.1, so execution should never get here in those cases -- no
2630 * need for an explicit test.
2631 */
2632 bind_framebuffer(target, framebuffer, true);
2633 }
2634
2635
2636 void GLAPIENTRY
2637 _mesa_DeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
2638 {
2639 GLint i;
2640 GET_CURRENT_CONTEXT(ctx);
2641
2642 if (n < 0) {
2643 _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteFramebuffers(n < 0)");
2644 return;
2645 }
2646
2647 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
2648
2649 for (i = 0; i < n; i++) {
2650 if (framebuffers[i] > 0) {
2651 struct gl_framebuffer *fb;
2652 fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]);
2653 if (fb) {
2654 assert(fb == &DummyFramebuffer || fb->Name == framebuffers[i]);
2655
2656 /* check if deleting currently bound framebuffer object */
2657 if (fb == ctx->DrawBuffer) {
2658 /* bind default */
2659 assert(fb->RefCount >= 2);
2660 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
2661 }
2662 if (fb == ctx->ReadBuffer) {
2663 /* bind default */
2664 assert(fb->RefCount >= 2);
2665 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, 0);
2666 }
2667
2668 /* remove from hash table immediately, to free the ID */
2669 _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]);
2670
2671 if (fb != &DummyFramebuffer) {
2672 /* But the object will not be freed until it's no longer
2673 * bound in any context.
2674 */
2675 _mesa_reference_framebuffer(&fb, NULL);
2676 }
2677 }
2678 }
2679 }
2680 }
2681
2682
2683 /**
2684 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2685 * It is not exposed to the rest of Mesa to encourage the use of
2686 * nameless buffers in driver internals.
2687 */
2688 static void
2689 create_framebuffers(GLsizei n, GLuint *framebuffers, bool dsa)
2690 {
2691 GET_CURRENT_CONTEXT(ctx);
2692 GLuint first;
2693 GLint i;
2694 struct gl_framebuffer *fb;
2695
2696 const char *func = dsa ? "glCreateFramebuffers" : "glGenFramebuffers";
2697
2698 if (n < 0) {
2699 _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func);
2700 return;
2701 }
2702
2703 if (!framebuffers)
2704 return;
2705
2706 _mesa_HashLockMutex(ctx->Shared->FrameBuffers);
2707
2708 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n);
2709
2710 for (i = 0; i < n; i++) {
2711 GLuint name = first + i;
2712 framebuffers[i] = name;
2713
2714 if (dsa) {
2715 fb = ctx->Driver.NewFramebuffer(ctx, framebuffers[i]);
2716 if (!fb) {
2717 _mesa_HashUnlockMutex(ctx->Shared->FrameBuffers);
2718 _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
2719 return;
2720 }
2721 }
2722 else
2723 fb = &DummyFramebuffer;
2724
2725 _mesa_HashInsertLocked(ctx->Shared->FrameBuffers, name, fb);
2726 }
2727
2728 _mesa_HashUnlockMutex(ctx->Shared->FrameBuffers);
2729 }
2730
2731
2732 void GLAPIENTRY
2733 _mesa_GenFramebuffers(GLsizei n, GLuint *framebuffers)
2734 {
2735 create_framebuffers(n, framebuffers, false);
2736 }
2737
2738
2739 void GLAPIENTRY
2740 _mesa_CreateFramebuffers(GLsizei n, GLuint *framebuffers)
2741 {
2742 create_framebuffers(n, framebuffers, true);
2743 }
2744
2745
2746 GLenum
2747 _mesa_check_framebuffer_status(struct gl_context *ctx,
2748 struct gl_framebuffer *buffer)
2749 {
2750 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
2751
2752 if (_mesa_is_winsys_fbo(buffer)) {
2753 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2754 if (buffer != &IncompleteFramebuffer) {
2755 return GL_FRAMEBUFFER_COMPLETE_EXT;
2756 } else {
2757 return GL_FRAMEBUFFER_UNDEFINED;
2758 }
2759 }
2760
2761 /* No need to flush here */
2762
2763 if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
2764 _mesa_test_framebuffer_completeness(ctx, buffer);
2765 }
2766
2767 return buffer->_Status;
2768 }
2769
2770
2771 GLenum GLAPIENTRY
2772 _mesa_CheckFramebufferStatus(GLenum target)
2773 {
2774 struct gl_framebuffer *fb;
2775 GET_CURRENT_CONTEXT(ctx);
2776
2777 if (MESA_VERBOSE & VERBOSE_API)
2778 _mesa_debug(ctx, "glCheckFramebufferStatus(%s)\n",
2779 _mesa_enum_to_string(target));
2780
2781 fb = get_framebuffer_target(ctx, target);
2782 if (!fb) {
2783 _mesa_error(ctx, GL_INVALID_ENUM,
2784 "glCheckFramebufferStatus(invalid target %s)",
2785 _mesa_enum_to_string(target));
2786 return 0;
2787 }
2788
2789 return _mesa_check_framebuffer_status(ctx, fb);
2790 }
2791
2792
2793 GLenum GLAPIENTRY
2794 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer, GLenum target)
2795 {
2796 struct gl_framebuffer *fb;
2797 GET_CURRENT_CONTEXT(ctx);
2798
2799 /* Validate the target (for conformance's sake) and grab a reference to the
2800 * default framebuffer in case framebuffer = 0.
2801 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
2802 * (30.10.2014, PDF page 336) says:
2803 * "If framebuffer is zero, then the status of the default read or
2804 * draw framebuffer (as determined by target) is returned."
2805 */
2806 switch (target) {
2807 case GL_DRAW_FRAMEBUFFER:
2808 case GL_FRAMEBUFFER:
2809 fb = ctx->WinSysDrawBuffer;
2810 break;
2811 case GL_READ_FRAMEBUFFER:
2812 fb = ctx->WinSysReadBuffer;
2813 break;
2814 default:
2815 _mesa_error(ctx, GL_INVALID_ENUM,
2816 "glCheckNamedFramebufferStatus(invalid target %s)",
2817 _mesa_enum_to_string(target));
2818 return 0;
2819 }
2820
2821 if (framebuffer) {
2822 fb = _mesa_lookup_framebuffer_err(ctx, framebuffer,
2823 "glCheckNamedFramebufferStatus");
2824 if (!fb)
2825 return 0;
2826 }
2827
2828 return _mesa_check_framebuffer_status(ctx, fb);
2829 }
2830
2831
2832 /**
2833 * Replicate the src attachment point. Used by framebuffer_texture() when
2834 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2835 * GL_STENCIL_ATTACHMENT.
2836 */
2837 static void
2838 reuse_framebuffer_texture_attachment(struct gl_framebuffer *fb,
2839 gl_buffer_index dst,
2840 gl_buffer_index src)
2841 {
2842 struct gl_renderbuffer_attachment *dst_att = &fb->Attachment[dst];
2843 struct gl_renderbuffer_attachment *src_att = &fb->Attachment[src];
2844
2845 assert(src_att->Texture != NULL);
2846 assert(src_att->Renderbuffer != NULL);
2847
2848 _mesa_reference_texobj(&dst_att->Texture, src_att->Texture);
2849 _mesa_reference_renderbuffer(&dst_att->Renderbuffer, src_att->Renderbuffer);
2850 dst_att->Type = src_att->Type;
2851 dst_att->Complete = src_att->Complete;
2852 dst_att->TextureLevel = src_att->TextureLevel;
2853 dst_att->Zoffset = src_att->Zoffset;
2854 dst_att->Layered = src_att->Layered;
2855 }
2856
2857
2858 /**
2859 * Common code called by gl*FramebufferTexture*() to retrieve the correct
2860 * texture object pointer.
2861 *
2862 * \param texObj where the pointer to the texture object is returned. Note
2863 * that a successful call may return texObj = NULL.
2864 *
2865 * \return true if no errors, false if errors
2866 */
2867 static bool
2868 get_texture_for_framebuffer(struct gl_context *ctx, GLuint texture,
2869 bool layered, const char *caller,
2870 struct gl_texture_object **texObj)
2871 {
2872 *texObj = NULL; /* This will get returned if texture = 0. */
2873
2874 if (!texture)
2875 return true;
2876
2877 *texObj = _mesa_lookup_texture(ctx, texture);
2878 if (*texObj == NULL || (*texObj)->Target == 0) {
2879 /* Can't render to a non-existent texture object.
2880 *
2881 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
2882 * Managing Framebuffer Objects specifies a different error
2883 * depending upon the calling function (PDF pages 325-328).
2884 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
2885 * value, while the other commands throw invalid operation (where
2886 * layered = GL_FALSE).
2887 */
2888 const GLenum error = layered ? GL_INVALID_VALUE :
2889 GL_INVALID_OPERATION;
2890 _mesa_error(ctx, error,
2891 "%s(non-existent texture %u)", caller, texture);
2892 return false;
2893 }
2894
2895 return true;
2896 }
2897
2898
2899 /**
2900 * Common code called by gl*FramebufferTexture() to verify the texture target
2901 * and decide whether or not the attachment should truly be considered
2902 * layered.
2903 *
2904 * \param layered true if attachment should be considered layered, false if
2905 * not
2906 *
2907 * \return true if no errors, false if errors
2908 */
2909 static bool
2910 check_layered_texture_target(struct gl_context *ctx, GLenum target,
2911 const char *caller, GLboolean *layered)
2912 {
2913 *layered = GL_TRUE;
2914
2915 switch (target) {
2916 case GL_TEXTURE_3D:
2917 case GL_TEXTURE_1D_ARRAY_EXT:
2918 case GL_TEXTURE_2D_ARRAY_EXT:
2919 case GL_TEXTURE_CUBE_MAP:
2920 case GL_TEXTURE_CUBE_MAP_ARRAY:
2921 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
2922 return true;
2923 case GL_TEXTURE_1D:
2924 case GL_TEXTURE_2D:
2925 case GL_TEXTURE_RECTANGLE:
2926 case GL_TEXTURE_2D_MULTISAMPLE:
2927 /* These texture types are valid to pass to
2928 * glFramebufferTexture(), but since they aren't layered, it
2929 * is equivalent to calling glFramebufferTexture{1D,2D}().
2930 */
2931 *layered = GL_FALSE;
2932 return true;
2933 }
2934
2935 _mesa_error(ctx, GL_INVALID_OPERATION,
2936 "%s(invalid texture target %s)", caller,
2937 _mesa_enum_to_string(target));
2938 return false;
2939 }
2940
2941
2942 /**
2943 * Common code called by gl*FramebufferTextureLayer() to verify the texture
2944 * target.
2945 *
2946 * \return true if no errors, false if errors
2947 */
2948 static bool
2949 check_texture_target(struct gl_context *ctx, GLenum target,
2950 const char *caller)
2951 {
2952 /* We're being called by glFramebufferTextureLayer().
2953 * The only legal texture types for that function are 3D,
2954 * cube-map, and 1D/2D/cube-map array textures.
2955 *
2956 * We don't need to check for GL_ARB_texture_cube_map_array because the
2957 * application wouldn't have been able to create a texture with a
2958 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
2959 */
2960 switch (target) {
2961 case GL_TEXTURE_3D:
2962 case GL_TEXTURE_1D_ARRAY:
2963 case GL_TEXTURE_2D_ARRAY:
2964 case GL_TEXTURE_CUBE_MAP_ARRAY:
2965 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
2966 return true;
2967 case GL_TEXTURE_CUBE_MAP:
2968 /* We don't need to check the extension (GL_ARB_direct_state_access) or
2969 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
2970 * enabled in core profile. This can be called from
2971 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
2972 * so we do have to check the profile.
2973 */
2974 return ctx->API == API_OPENGL_CORE;
2975 }
2976
2977 _mesa_error(ctx, GL_INVALID_OPERATION,
2978 "%s(invalid texture target %s)", caller,
2979 _mesa_enum_to_string(target));
2980 return false;
2981 }
2982
2983
2984 /**
2985 * Common code called by glFramebufferTexture*D() to verify the texture
2986 * target.
2987 *
2988 * \return true if no errors, false if errors
2989 */
2990 static bool
2991 check_textarget(struct gl_context *ctx, int dims, GLenum target,
2992 GLenum textarget, const char *caller)
2993 {
2994 bool err = false;
2995
2996 switch (textarget) {
2997 case GL_TEXTURE_1D:
2998 err = dims != 1;
2999 break;
3000 case GL_TEXTURE_1D_ARRAY:
3001 err = dims != 1 || !ctx->Extensions.EXT_texture_array;
3002 break;
3003 case GL_TEXTURE_2D:
3004 err = dims != 2;
3005 break;
3006 case GL_TEXTURE_2D_ARRAY:
3007 err = dims != 2 || !ctx->Extensions.EXT_texture_array ||
3008 (_mesa_is_gles(ctx) && ctx->Version < 30);
3009 break;
3010 case GL_TEXTURE_2D_MULTISAMPLE:
3011 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
3012 err = dims != 2 ||
3013 !ctx->Extensions.ARB_texture_multisample ||
3014 (_mesa_is_gles(ctx) && ctx->Version < 31);
3015 break;
3016 case GL_TEXTURE_RECTANGLE:
3017 err = dims != 2 || _mesa_is_gles(ctx) ||
3018 !ctx->Extensions.NV_texture_rectangle;
3019 break;
3020 case GL_TEXTURE_CUBE_MAP:
3021 case GL_TEXTURE_CUBE_MAP_ARRAY:
3022 err = true;
3023 break;
3024 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
3025 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
3026 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
3027 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
3028 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
3029 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
3030 err = dims != 2 || !ctx->Extensions.ARB_texture_cube_map;
3031 break;
3032 case GL_TEXTURE_3D:
3033 err = dims != 3;
3034 break;
3035 default:
3036 _mesa_error(ctx, GL_INVALID_ENUM,
3037 "%s(unknown textarget 0x%x)", caller, textarget);
3038 return false;
3039 }
3040
3041 if (err) {
3042 _mesa_error(ctx, GL_INVALID_OPERATION,
3043 "%s(invalid textarget %s)",
3044 caller, _mesa_enum_to_string(textarget));
3045 return false;
3046 }
3047
3048 /* Make sure textarget is consistent with the texture's type */
3049 err = (target == GL_TEXTURE_CUBE_MAP) ?
3050 !_mesa_is_cube_face(textarget): (target != textarget);
3051
3052 if (err) {
3053 _mesa_error(ctx, GL_INVALID_OPERATION,
3054 "%s(mismatched texture target)", caller);
3055 return false;
3056 }
3057
3058 return true;
3059 }
3060
3061
3062 /**
3063 * Common code called by gl*FramebufferTextureLayer() and
3064 * glFramebufferTexture3D() to validate the layer.
3065 *
3066 * \return true if no errors, false if errors
3067 */
3068 static bool
3069 check_layer(struct gl_context *ctx, GLenum target, GLint layer,
3070 const char *caller)
3071 {
3072 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3073 * spec says:
3074 *
3075 * "An INVALID_VALUE error is generated if texture is non-zero
3076 * and layer is negative."
3077 */
3078 if (layer < 0) {
3079 _mesa_error(ctx, GL_INVALID_VALUE,
3080 "%s(layer %u < 0)", caller, layer);
3081 return false;
3082 }
3083
3084 if (target == GL_TEXTURE_3D) {
3085 const GLuint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
3086 if (layer >= maxSize) {
3087 _mesa_error(ctx, GL_INVALID_VALUE,
3088 "%s(invalid layer %u)", caller, layer);
3089 return false;
3090 }
3091 }
3092 else if ((target == GL_TEXTURE_1D_ARRAY) ||
3093 (target == GL_TEXTURE_2D_ARRAY) ||
3094 (target == GL_TEXTURE_CUBE_MAP_ARRAY) ||
3095 (target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)) {
3096 if (layer >= ctx->Const.MaxArrayTextureLayers) {
3097 _mesa_error(ctx, GL_INVALID_VALUE,
3098 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3099 caller, layer);
3100 return false;
3101 }
3102 }
3103 else if (target == GL_TEXTURE_CUBE_MAP) {
3104 if (layer >= 6) {
3105 _mesa_error(ctx, GL_INVALID_VALUE,
3106 "%s(layer %u >= 6)", caller, layer);
3107 return false;
3108 }
3109 }
3110
3111 return true;
3112 }
3113
3114
3115 /**
3116 * Common code called by all gl*FramebufferTexture*() entry points to verify
3117 * the level.
3118 *
3119 * \return true if no errors, false if errors
3120 */
3121 static bool
3122 check_level(struct gl_context *ctx, GLenum target, GLint level,
3123 const char *caller)
3124 {
3125 if ((level < 0) ||
3126 (level >= _mesa_max_texture_levels(ctx, target))) {
3127 _mesa_error(ctx, GL_INVALID_VALUE,
3128 "%s(invalid level %d)", caller, level);
3129 return false;
3130 }
3131
3132 return true;
3133 }
3134
3135
3136 void
3137 _mesa_framebuffer_texture(struct gl_context *ctx, struct gl_framebuffer *fb,
3138 GLenum attachment,
3139 struct gl_texture_object *texObj, GLenum textarget,
3140 GLint level, GLuint layer, GLboolean layered,
3141 const char *caller)
3142 {
3143 struct gl_renderbuffer_attachment *att;
3144
3145 /* The window-system framebuffer object is immutable */
3146 if (_mesa_is_winsys_fbo(fb)) {
3147 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(window-system framebuffer)",
3148 caller);
3149 return;
3150 }
3151
3152 /* Not a hash lookup, so we can afford to get the attachment here. */
3153 att = get_attachment(ctx, fb, attachment);
3154 if (att == NULL) {
3155 _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid attachment %s)", caller,
3156 _mesa_enum_to_string(attachment));
3157 return;
3158 }
3159
3160 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
3161
3162 mtx_lock(&fb->Mutex);
3163 if (texObj) {
3164 if (attachment == GL_DEPTH_ATTACHMENT &&
3165 texObj == fb->Attachment[BUFFER_STENCIL].Texture &&
3166 level == fb->Attachment[BUFFER_STENCIL].TextureLevel &&
3167 _mesa_tex_target_to_face(textarget) ==
3168 fb->Attachment[BUFFER_STENCIL].CubeMapFace &&
3169 layer == fb->Attachment[BUFFER_STENCIL].Zoffset) {
3170 /* The texture object is already attached to the stencil attachment
3171 * point. Don't create a new renderbuffer; just reuse the stencil
3172 * attachment's. This is required to prevent a GL error in
3173 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3174 */
3175 reuse_framebuffer_texture_attachment(fb, BUFFER_DEPTH,
3176 BUFFER_STENCIL);
3177 } else if (attachment == GL_STENCIL_ATTACHMENT &&
3178 texObj == fb->Attachment[BUFFER_DEPTH].Texture &&
3179 level == fb->Attachment[BUFFER_DEPTH].TextureLevel &&
3180 _mesa_tex_target_to_face(textarget) ==
3181 fb->Attachment[BUFFER_DEPTH].CubeMapFace &&
3182 layer == fb->Attachment[BUFFER_DEPTH].Zoffset) {
3183 /* As above, but with depth and stencil transposed. */
3184 reuse_framebuffer_texture_attachment(fb, BUFFER_STENCIL,
3185 BUFFER_DEPTH);
3186 } else {
3187 set_texture_attachment(ctx, fb, att, texObj, textarget,
3188 level, layer, layered);
3189
3190 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
3191 /* Above we created a new renderbuffer and attached it to the
3192 * depth attachment point. Now attach it to the stencil attachment
3193 * point too.
3194 */
3195 assert(att == &fb->Attachment[BUFFER_DEPTH]);
3196 reuse_framebuffer_texture_attachment(fb,BUFFER_STENCIL,
3197 BUFFER_DEPTH);
3198 }
3199 }
3200
3201 /* Set the render-to-texture flag. We'll check this flag in
3202 * glTexImage() and friends to determine if we need to revalidate
3203 * any FBOs that might be rendering into this texture.
3204 * This flag never gets cleared since it's non-trivial to determine
3205 * when all FBOs might be done rendering to this texture. That's OK
3206 * though since it's uncommon to render to a texture then repeatedly
3207 * call glTexImage() to change images in the texture.
3208 */
3209 texObj->_RenderToTexture = GL_TRUE;
3210 }
3211 else {
3212 remove_attachment(ctx, att);
3213 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
3214 assert(att == &fb->Attachment[BUFFER_DEPTH]);
3215 remove_attachment(ctx, &fb->Attachment[BUFFER_STENCIL]);
3216 }
3217 }
3218
3219 invalidate_framebuffer(fb);
3220
3221 mtx_unlock(&fb->Mutex);
3222 }
3223
3224
3225 static void
3226 framebuffer_texture_with_dims(int dims, GLenum target,
3227 GLenum attachment, GLenum textarget,
3228 GLuint texture, GLint level, GLint layer,
3229 const char *caller)
3230 {
3231 GET_CURRENT_CONTEXT(ctx);
3232 struct gl_framebuffer *fb;
3233 struct gl_texture_object *texObj;
3234
3235 /* Get the framebuffer object */
3236 fb = get_framebuffer_target(ctx, target);
3237 if (!fb) {
3238 _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid target %s)", caller,
3239 _mesa_enum_to_string(target));
3240 return;
3241 }
3242
3243 /* Get the texture object */
3244 if (!get_texture_for_framebuffer(ctx, texture, false, caller, &texObj))
3245 return;
3246
3247 if (texObj) {
3248 if (!check_textarget(ctx, dims, texObj->Target, textarget, caller))
3249 return;
3250
3251 if ((dims == 3) && !check_layer(ctx, texObj->Target, layer, caller))
3252 return;
3253
3254 if (!check_level(ctx, textarget, level, caller))
3255 return;
3256 }
3257
3258 _mesa_framebuffer_texture(ctx, fb, attachment, texObj, textarget, level,
3259 layer, GL_FALSE, caller);
3260 }
3261
3262
3263 void GLAPIENTRY
3264 _mesa_FramebufferTexture1D(GLenum target, GLenum attachment,
3265 GLenum textarget, GLuint texture, GLint level)
3266 {
3267 framebuffer_texture_with_dims(1, target, attachment, textarget, texture,
3268 level, 0, "glFramebufferTexture1D");
3269 }
3270
3271
3272 void GLAPIENTRY
3273 _mesa_FramebufferTexture2D(GLenum target, GLenum attachment,
3274 GLenum textarget, GLuint texture, GLint level)
3275 {
3276 framebuffer_texture_with_dims(2, target, attachment, textarget, texture,
3277 level, 0, "glFramebufferTexture2D");
3278 }
3279
3280
3281 void GLAPIENTRY
3282 _mesa_FramebufferTexture3D(GLenum target, GLenum attachment,
3283 GLenum textarget, GLuint texture,
3284 GLint level, GLint layer)
3285 {
3286 framebuffer_texture_with_dims(3, target, attachment, textarget, texture,
3287 level, layer, "glFramebufferTexture3D");
3288 }
3289
3290
3291 void GLAPIENTRY
3292 _mesa_FramebufferTextureLayer(GLenum target, GLenum attachment,
3293 GLuint texture, GLint level, GLint layer)
3294 {
3295 GET_CURRENT_CONTEXT(ctx);
3296 struct gl_framebuffer *fb;
3297 struct gl_texture_object *texObj;
3298 GLenum textarget = 0;
3299
3300 const char *func = "glFramebufferTextureLayer";
3301
3302 /* Get the framebuffer object */
3303 fb = get_framebuffer_target(ctx, target);
3304 if (!fb) {
3305 _mesa_error(ctx, GL_INVALID_ENUM,
3306 "glFramebufferTextureLayer(invalid target %s)",
3307 _mesa_enum_to_string(target));
3308 return;
3309 }
3310
3311 /* Get the texture object */
3312 if (!get_texture_for_framebuffer(ctx, texture, false, func, &texObj))
3313 return;
3314
3315 if (texObj) {
3316 if (!check_texture_target(ctx, texObj->Target, func))
3317 return;
3318
3319 if (!check_layer(ctx, texObj->Target, layer, func))
3320 return;
3321
3322 if (!check_level(ctx, texObj->Target, level, func))
3323 return;
3324
3325 if (texObj->Target == GL_TEXTURE_CUBE_MAP) {
3326 assert(layer >= 0 && layer < 6);
3327 textarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
3328 layer = 0;
3329 }
3330 }
3331
3332 _mesa_framebuffer_texture(ctx, fb, attachment, texObj, textarget, level,
3333 layer, GL_FALSE, func);
3334 }
3335
3336
3337 void GLAPIENTRY
3338 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer, GLenum attachment,
3339 GLuint texture, GLint level, GLint layer)
3340 {
3341 GET_CURRENT_CONTEXT(ctx);
3342 struct gl_framebuffer *fb;
3343 struct gl_texture_object *texObj;
3344 GLenum textarget = 0;
3345
3346 const char *func = "glNamedFramebufferTextureLayer";
3347
3348 /* Get the framebuffer object */
3349 fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, func);
3350 if (!fb)
3351 return;
3352
3353 /* Get the texture object */
3354 if (!get_texture_for_framebuffer(ctx, texture, false, func, &texObj))
3355 return;
3356
3357 if (texObj) {
3358 if (!check_texture_target(ctx, texObj->Target, func))
3359 return;
3360
3361 if (!check_layer(ctx, texObj->Target, layer, func))
3362 return;
3363
3364 if (!check_level(ctx, texObj->Target, level, func))
3365 return;
3366
3367 if (texObj->Target == GL_TEXTURE_CUBE_MAP) {
3368 assert(layer >= 0 && layer < 6);
3369 textarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
3370 layer = 0;
3371 }
3372 }
3373
3374 _mesa_framebuffer_texture(ctx, fb, attachment, texObj, textarget, level,
3375 layer, GL_FALSE, func);
3376 }
3377
3378
3379 void GLAPIENTRY
3380 _mesa_FramebufferTexture(GLenum target, GLenum attachment,
3381 GLuint texture, GLint level)
3382 {
3383 GET_CURRENT_CONTEXT(ctx);
3384 struct gl_framebuffer *fb;
3385 struct gl_texture_object *texObj;
3386 GLboolean layered = GL_FALSE;
3387
3388 const char *func = "FramebufferTexture";
3389
3390 if (!_mesa_has_geometry_shaders(ctx)) {
3391 _mesa_error(ctx, GL_INVALID_OPERATION,
3392 "unsupported function (glFramebufferTexture) called");
3393 return;
3394 }
3395
3396 /* Get the framebuffer object */
3397 fb = get_framebuffer_target(ctx, target);
3398 if (!fb) {
3399 _mesa_error(ctx, GL_INVALID_ENUM,
3400 "glFramebufferTexture(invalid target %s)",
3401 _mesa_enum_to_string(target));
3402 return;
3403 }
3404
3405 /* Get the texture object */
3406 if (!get_texture_for_framebuffer(ctx, texture, true, func, &texObj))
3407 return;
3408
3409 if (texObj) {
3410 if (!check_layered_texture_target(ctx, texObj->Target, func, &layered))
3411 return;
3412
3413 if (!check_level(ctx, texObj->Target, level, func))
3414 return;
3415 }
3416
3417 _mesa_framebuffer_texture(ctx, fb, attachment, texObj, 0, level,
3418 0, layered, func);
3419 }
3420
3421
3422 void GLAPIENTRY
3423 _mesa_NamedFramebufferTexture(GLuint framebuffer, GLenum attachment,
3424 GLuint texture, GLint level)
3425 {
3426 GET_CURRENT_CONTEXT(ctx);
3427 struct gl_framebuffer *fb;
3428 struct gl_texture_object *texObj;
3429 GLboolean layered = GL_FALSE;
3430
3431 const char *func = "glNamedFramebufferTexture";
3432
3433 if (!_mesa_has_geometry_shaders(ctx)) {
3434 _mesa_error(ctx, GL_INVALID_OPERATION,
3435 "unsupported function (glNamedFramebufferTexture) called");
3436 return;
3437 }
3438
3439 /* Get the framebuffer object */
3440 fb = _mesa_lookup_framebuffer_err(ctx, framebuffer, func);
3441 if (!fb)
3442 return;
3443
3444 /* Get the texture object */
3445 if (!get_texture_for_framebuffer(ctx, texture, true, func, &texObj))
3446 return;
3447
3448 if (texObj) {
3449 if (!check_layered_texture_target(ctx, texObj->Target, func,
3450 &layered))
3451 return;
3452
3453 if (!check_level(ctx, texObj->Target, level, func))
3454 return;
3455 }
3456
3457 _mesa_framebuffer_texture(ctx, fb, attachment, texObj, 0, level,
3458 0, layered, func);
3459 }
3460
3461
3462 void
3463 _mesa_framebuffer_renderbuffer(struct gl_context *ctx,
3464 struct gl_framebuffer *fb,
3465 GLenum attachment,
3466 struct gl_renderbuffer *rb)
3467 {
3468 assert(!_mesa_is_winsys_fbo(fb));
3469
3470 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
3471
3472 assert(ctx->Driver.FramebufferRenderbuffer);
3473 ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb);
3474
3475 /* Some subsequent GL commands may depend on the framebuffer's visual
3476 * after the binding is updated. Update visual info now.
3477 */
3478 _mesa_update_framebuffer_visual(ctx, fb);
3479 }
3480
3481 static void
3482 framebuffer_renderbuffer(struct gl_context *ctx,
3483 struct gl_framebuffer *fb,
3484 GLenum attachment,
3485 struct gl_renderbuffer *rb,
3486 const char *func)
3487 {
3488 struct gl_renderbuffer_attachment *att;
3489
3490 if (_mesa_is_winsys_fbo(fb)) {
3491 /* Can't attach new renderbuffers to a window system framebuffer */
3492 _mesa_error(ctx, GL_INVALID_OPERATION,
3493 "%s(window-system framebuffer)", func);
3494 return;
3495 }
3496
3497 att = get_attachment(ctx, fb, attachment);
3498 if (att == NULL) {
3499 _mesa_error(ctx, GL_INVALID_ENUM,
3500 "%s(invalid attachment %s)", func,
3501 _mesa_enum_to_string(attachment));
3502 return;
3503 }
3504
3505 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT &&
3506 rb && rb->Format != MESA_FORMAT_NONE) {
3507 /* make sure the renderbuffer is a depth/stencil format */
3508 const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
3509 if (baseFormat != GL_DEPTH_STENCIL) {
3510 _mesa_error(ctx, GL_INVALID_OPERATION,
3511 "%s(renderbuffer is not DEPTH_STENCIL format)", func);
3512 return;
3513 }
3514 }
3515
3516 _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
3517 }
3518
3519 void GLAPIENTRY
3520 _mesa_FramebufferRenderbuffer(GLenum target, GLenum attachment,
3521 GLenum renderbuffertarget,
3522 GLuint renderbuffer)
3523 {
3524 struct gl_framebuffer *fb;
3525 struct gl_renderbuffer *rb;
3526 GET_CURRENT_CONTEXT(ctx);
3527
3528 fb = get_framebuffer_target(ctx, target);
3529 if (!fb) {
3530 _mesa_error(ctx, GL_INVALID_ENUM,
3531 "glFramebufferRenderbuffer(invalid target %s)",
3532 _mesa_enum_to_string(target));
3533 return;
3534 }
3535
3536 if (renderbuffertarget != GL_RENDERBUFFER) {
3537 _mesa_error(ctx, GL_INVALID_ENUM,
3538 "glFramebufferRenderbuffer(renderbuffertarget is not "
3539 "GL_RENDERBUFFER)");
3540 return;
3541 }
3542
3543 if (renderbuffer) {
3544 rb = _mesa_lookup_renderbuffer_err(ctx, renderbuffer,
3545 "glFramebufferRenderbuffer");
3546 if (!rb)
3547 return;
3548 }
3549 else {
3550 /* remove renderbuffer attachment */
3551 rb = NULL;
3552 }
3553
3554 framebuffer_renderbuffer(ctx, fb, attachment, rb,
3555 "glFramebufferRenderbuffer");
3556 }
3557
3558
3559 void GLAPIENTRY
3560 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer, GLenum attachment,
3561 GLenum renderbuffertarget,
3562 GLuint renderbuffer)
3563 {
3564 struct gl_framebuffer *fb;
3565 struct gl_renderbuffer *rb;
3566 GET_CURRENT_CONTEXT(ctx);
3567
3568 fb = _mesa_lookup_framebuffer_err(ctx, framebuffer,
3569 "glNamedFramebufferRenderbuffer");
3570 if (!fb)
3571 return;
3572
3573 if (renderbuffertarget != GL_RENDERBUFFER) {
3574 _mesa_error(ctx, GL_INVALID_ENUM,
3575 "glNamedFramebufferRenderbuffer(renderbuffertarget is not "
3576 "GL_RENDERBUFFER)");
3577 return;
3578 }
3579
3580 if (renderbuffer) {
3581 rb = _mesa_lookup_renderbuffer_err(ctx, renderbuffer,
3582 "glNamedFramebufferRenderbuffer");
3583 if (!rb)
3584 return;
3585 }
3586 else {
3587 /* remove renderbuffer attachment */
3588 rb = NULL;
3589 }
3590
3591 framebuffer_renderbuffer(ctx, fb, attachment, rb,
3592 "glNamedFramebufferRenderbuffer");
3593 }
3594
3595
3596 void
3597 _mesa_get_framebuffer_attachment_parameter(struct gl_context *ctx,
3598 struct gl_framebuffer *buffer,
3599 GLenum attachment, GLenum pname,
3600 GLint *params, const char *caller)
3601 {
3602 const struct gl_renderbuffer_attachment *att;
3603 GLenum err;
3604
3605 /* The error code for an attachment type of GL_NONE differs between APIs.
3606 *
3607 * From the ES 2.0.25 specification, page 127:
3608 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3609 * querying any other pname will generate INVALID_ENUM."
3610 *
3611 * From the OpenGL 3.0 specification, page 337, or identically,
3612 * the OpenGL ES 3.0.4 specification, page 240:
3613 *
3614 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
3615 * framebuffer is bound to target. In this case querying pname
3616 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
3617 * queries will generate an INVALID_OPERATION error."
3618 */
3619 err = ctx->API == API_OPENGLES2 && ctx->Version < 30 ?
3620 GL_INVALID_ENUM : GL_INVALID_OPERATION;
3621
3622 if (_mesa_is_winsys_fbo(buffer)) {
3623 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
3624 * says:
3625 *
3626 * "If the framebuffer currently bound to target is zero, then
3627 * INVALID_OPERATION is generated."
3628 *
3629 * The EXT_framebuffer_object spec has the same wording, and the
3630 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
3631 * spec.
3632 */
3633 if ((!_mesa_is_desktop_gl(ctx) ||
3634 !ctx->Extensions.ARB_framebuffer_object)
3635 && !_mesa_is_gles3(ctx)) {
3636 _mesa_error(ctx, GL_INVALID_OPERATION,
3637 "%s(window-system framebuffer)", caller);
3638 return;
3639 }
3640
3641 if (_mesa_is_gles3(ctx) && attachment != GL_BACK &&
3642 attachment != GL_DEPTH && attachment != GL_STENCIL) {
3643 _mesa_error(ctx, GL_INVALID_ENUM,
3644 "%s(invalid attachment %s)", caller,
3645 _mesa_enum_to_string(attachment));
3646 return;
3647 }
3648
3649 /* The specs are not clear about how to handle
3650 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
3651 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
3652 * discussed in:
3653 *
3654 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
3655 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
3656 */
3657 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) {
3658 _mesa_error(ctx, GL_INVALID_ENUM,
3659 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
3660 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
3661 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller);
3662 return;
3663 }
3664
3665 /* the default / window-system FBO */
3666 att = _mesa_get_fb0_attachment(ctx, buffer, attachment);
3667 }
3668 else {
3669 /* user-created framebuffer FBO */
3670 att = get_attachment(ctx, buffer, attachment);
3671 }
3672
3673 if (att == NULL) {
3674 _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid attachment %s)", caller,
3675 _mesa_enum_to_string(attachment));
3676 return;
3677 }
3678
3679 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
3680 const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt;
3681 if (pname == GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE) {
3682 /* This behavior is first specified in OpenGL 4.4 specification.
3683 *
3684 * From the OpenGL 4.4 spec page 275:
3685 * "This query cannot be performed for a combined depth+stencil
3686 * attachment, since it does not have a single format."
3687 */
3688 _mesa_error(ctx, GL_INVALID_OPERATION,
3689 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
3690 " is invalid for depth+stencil attachment)", caller);
3691 return;
3692 }
3693 /* the depth and stencil attachments must point to the same buffer */
3694 depthAtt = get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT);
3695 stencilAtt = get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT);
3696 if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) {
3697 _mesa_error(ctx, GL_INVALID_OPERATION,
3698 "%s(DEPTH/STENCIL attachments differ)", caller);
3699 return;
3700 }
3701 }
3702
3703 /* No need to flush here */
3704
3705 switch (pname) {
3706 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT:
3707 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
3708 *
3709 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3710 * either no framebuffer is bound to target; or the default framebuffer
3711 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
3712 * stencil bits, respectively, is zero."
3713 */
3714 *params = (_mesa_is_winsys_fbo(buffer) &&
3715 ((attachment != GL_DEPTH && attachment != GL_STENCIL) ||
3716 (att->Type != GL_NONE)))
3717 ? GL_FRAMEBUFFER_DEFAULT : att->Type;
3718 return;
3719 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT:
3720 if (att->Type == GL_RENDERBUFFER_EXT) {
3721 *params = att->Renderbuffer->Name;
3722 }
3723 else if (att->Type == GL_TEXTURE) {
3724 *params = att->Texture->Name;
3725 }
3726 else {
3727 assert(att->Type == GL_NONE);
3728 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) {
3729 *params = 0;
3730 } else {
3731 goto invalid_pname_enum;
3732 }
3733 }
3734 return;
3735 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT:
3736 if (att->Type == GL_TEXTURE) {
3737 *params = att->TextureLevel;
3738 }
3739 else if (att->Type == GL_NONE) {
3740 _mesa_error(ctx, err, "%s(invalid pname %s)", caller,
3741 _mesa_enum_to_string(pname));
3742 }
3743 else {
3744 goto invalid_pname_enum;
3745 }
3746 return;
3747 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT:
3748 if (att->Type == GL_TEXTURE) {
3749 if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) {
3750 *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace;
3751 }
3752 else {
3753 *params = 0;
3754 }
3755 }
3756 else if (att->Type == GL_NONE) {
3757 _mesa_error(ctx, err, "%s(invalid pname %s)", caller,
3758 _mesa_enum_to_string(pname));
3759 }
3760 else {
3761 goto invalid_pname_enum;
3762 }
3763 return;
3764 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT:
3765 if (ctx->API == API_OPENGLES) {
3766 goto invalid_pname_enum;
3767 } else if (att->Type == GL_NONE) {
3768 _mesa_error(ctx, err, "%s(invalid pname %s)", caller,
3769 _mesa_enum_to_string(pname));
3770 } else if (att->Type == GL_TEXTURE) {
3771 if (att->Texture && (att->Texture->Target == GL_TEXTURE_3D ||
3772 att->Texture->Target == GL_TEXTURE_2D_ARRAY)) {
3773 *params = att->Zoffset;
3774 }
3775 else {
3776 *params = 0;
3777 }
3778 }
3779 else {
3780 goto invalid_pname_enum;
3781 }
3782 return;
3783 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
3784 if ((!_mesa_is_desktop_gl(ctx) ||
3785 !ctx->Extensions.ARB_framebuffer_object)
3786 && !_mesa_is_gles3(ctx)) {
3787 goto invalid_pname_enum;
3788 }
3789 else if (att->Type == GL_NONE) {
3790 _mesa_error(ctx, err, "%s(invalid pname %s)", caller,
3791 _mesa_enum_to_string(pname));
3792 }
3793 else {
3794 if (ctx->Extensions.EXT_framebuffer_sRGB) {
3795 *params =
3796 _mesa_get_format_color_encoding(att->Renderbuffer->Format);
3797 }
3798 else {
3799 /* According to ARB_framebuffer_sRGB, we should return LINEAR
3800 * if the sRGB conversion is unsupported. */
3801 *params = GL_LINEAR;
3802 }
3803 }
3804 return;
3805 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
3806 if ((ctx->API != API_OPENGL_COMPAT ||
3807 !ctx->Extensions.ARB_framebuffer_object)
3808 && ctx->API != API_OPENGL_CORE
3809 && !_mesa_is_gles3(ctx)) {
3810 goto invalid_pname_enum;
3811 }
3812 else if (att->Type == GL_NONE) {
3813 _mesa_error(ctx, err, "%s(invalid pname %s)", caller,
3814 _mesa_enum_to_string(pname));
3815 }
3816 else {
3817 mesa_format format = att->Renderbuffer->Format;
3818
3819 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
3820 * 3.0.1 spec says:
3821 *
3822 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
3823 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
3824 * generate an INVALID_OPERATION error.
3825 */
3826 if (_mesa_is_gles3(ctx) &&
3827 attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
3828 _mesa_error(ctx, GL_INVALID_OPERATION,
3829 "%s(cannot query "
3830 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
3831 "GL_DEPTH_STENCIL_ATTACHMENT)", caller);
3832 return;
3833 }
3834
3835 if (format == MESA_FORMAT_S_UINT8) {
3836 /* special cases */
3837 *params = GL_INDEX;
3838 }
3839 else if (format == MESA_FORMAT_Z32_FLOAT_S8X24_UINT) {
3840 /* depends on the attachment parameter */
3841 if (attachment == GL_STENCIL_ATTACHMENT) {
3842 *params = GL_INDEX;
3843 }
3844 else {
3845 *params = GL_FLOAT;
3846 }
3847 }
3848 else {
3849 *params = _mesa_get_format_datatype(format);
3850 }
3851 }
3852 return;
3853 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
3854 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
3855 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
3856 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
3857 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
3858 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
3859 if ((!_mesa_is_desktop_gl(ctx) ||
3860 !ctx->Extensions.ARB_framebuffer_object)
3861 && !_mesa_is_gles3(ctx)) {
3862 goto invalid_pname_enum;
3863 }
3864 else if (att->Type == GL_NONE) {
3865 _mesa_error(ctx, err, "%s(invalid pname %s)", caller,
3866 _mesa_enum_to_string(pname));
3867 }
3868 else if (att->Texture) {
3869 const struct gl_texture_image *texImage =
3870 _mesa_select_tex_image(att->Texture, att->Texture->Target,
3871 att->TextureLevel);
3872 if (texImage) {
3873 *params = get_component_bits(pname, texImage->_BaseFormat,
3874 texImage->TexFormat);
3875 }
3876 else {
3877 *params = 0;
3878 }
3879 }
3880 else if (att->Renderbuffer) {
3881 *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat,
3882 att->Renderbuffer->Format);
3883 }
3884 else {
3885 _mesa_problem(ctx, "%s: invalid FBO attachment structure", caller);
3886 }
3887 return;
3888 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED:
3889 if (!_mesa_has_geometry_shaders(ctx)) {
3890 goto invalid_pname_enum;
3891 } else if (att->Type == GL_TEXTURE) {
3892 *params = att->Layered;
3893 } else if (att->Type == GL_NONE) {
3894 _mesa_error(ctx, err, "%s(invalid pname %s)", caller,
3895 _mesa_enum_to_string(pname));
3896 } else {
3897 goto invalid_pname_enum;
3898 }
3899 return;
3900 default:
3901 goto invalid_pname_enum;
3902 }
3903
3904 return;
3905
3906 invalid_pname_enum:
3907 _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid pname %s)", caller,
3908 _mesa_enum_to_string(pname));
3909 return;
3910 }
3911
3912
3913 void GLAPIENTRY
3914 _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
3915 GLenum pname, GLint *params)
3916 {
3917 GET_CURRENT_CONTEXT(ctx);
3918 struct gl_framebuffer *buffer;
3919
3920 buffer = get_framebuffer_target(ctx, target);
3921 if (!buffer) {
3922 _mesa_error(ctx, GL_INVALID_ENUM,
3923 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
3924 _mesa_enum_to_string(target));
3925 return;
3926 }
3927
3928 _mesa_get_framebuffer_attachment_parameter(ctx, buffer, attachment, pname,
3929 params,
3930 "glGetFramebufferAttachmentParameteriv");
3931 }
3932
3933
3934 void GLAPIENTRY
3935 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer,
3936 GLenum attachment,
3937 GLenum pname, GLint *params)
3938 {
3939 GET_CURRENT_CONTEXT(ctx);
3940 struct gl_framebuffer *buffer;
3941
3942 if (framebuffer) {
3943 buffer = _mesa_lookup_framebuffer_err(ctx, framebuffer,
3944 "glGetNamedFramebufferAttachmentParameteriv");
3945 if (!buffer)
3946 return;
3947 }
3948 else {
3949 /*
3950 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
3951 * 4.5 core spec (30.10.2014, PDF page 314):
3952 * "If framebuffer is zero, then the default draw framebuffer is
3953 * queried."
3954 */
3955 buffer = ctx->WinSysDrawBuffer;
3956 }
3957
3958 _mesa_get_framebuffer_attachment_parameter(ctx, buffer, attachment, pname,
3959 params,
3960 "glGetNamedFramebufferAttachmentParameteriv");
3961 }
3962
3963
3964 void GLAPIENTRY
3965 _mesa_NamedFramebufferParameteri(GLuint framebuffer, GLenum pname,
3966 GLint param)
3967 {
3968 GET_CURRENT_CONTEXT(ctx);
3969 struct gl_framebuffer *fb = NULL;
3970
3971 if (!ctx->Extensions.ARB_framebuffer_no_attachments) {
3972 _mesa_error(ctx, GL_INVALID_OPERATION,
3973 "glNamedFramebufferParameteri("
3974 "ARB_framebuffer_no_attachments not implemented)");
3975 return;
3976 }
3977
3978 fb = _mesa_lookup_framebuffer_err(ctx, framebuffer,
3979 "glNamedFramebufferParameteri");
3980
3981 if (fb) {
3982 framebuffer_parameteri(ctx, fb, pname, param,
3983 "glNamedFramebufferParameteriv");
3984 }
3985 }
3986
3987
3988 void GLAPIENTRY
3989 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer, GLenum pname,
3990 GLint *param)
3991 {
3992 GET_CURRENT_CONTEXT(ctx);
3993 struct gl_framebuffer *fb;
3994
3995 if (!ctx->Extensions.ARB_framebuffer_no_attachments) {
3996 _mesa_error(ctx, GL_INVALID_OPERATION,
3997 "glNamedFramebufferParameteriv("
3998 "ARB_framebuffer_no_attachments not implemented)");
3999 return;
4000 }
4001
4002 if (framebuffer) {
4003 fb = _mesa_lookup_framebuffer_err(ctx, framebuffer,
4004 "glGetNamedFramebufferParameteriv");
4005 } else {
4006 fb = ctx->WinSysDrawBuffer;
4007 }
4008
4009 if (fb) {
4010 get_framebuffer_parameteriv(ctx, fb, pname, param,
4011 "glGetNamedFramebufferParameteriv");
4012 }
4013 }
4014
4015
4016 static void
4017 invalidate_framebuffer_storage(struct gl_context *ctx,
4018 struct gl_framebuffer *fb,
4019 GLsizei numAttachments,
4020 const GLenum *attachments, GLint x, GLint y,
4021 GLsizei width, GLsizei height, const char *name)
4022 {
4023 int i;
4024
4025 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4026 * Spec (2.2.2015, PDF page 522) says:
4027 * "An INVALID_VALUE error is generated if numAttachments, width, or
4028 * height is negative."
4029 */
4030 if (numAttachments < 0) {
4031 _mesa_error(ctx, GL_INVALID_VALUE,
4032 "%s(numAttachments < 0)", name);
4033 return;
4034 }
4035
4036 if (width < 0) {
4037 _mesa_error(ctx, GL_INVALID_VALUE,
4038 "%s(width < 0)", name);
4039 return;
4040 }
4041
4042 if (height < 0) {
4043 _mesa_error(ctx, GL_INVALID_VALUE,
4044 "%s(height < 0)", name);
4045 return;
4046 }
4047
4048 /* The GL_ARB_invalidate_subdata spec says:
4049 *
4050 * "If an attachment is specified that does not exist in the
4051 * framebuffer bound to <target>, it is ignored."
4052 *
4053 * It also says:
4054 *
4055 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4056 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4057 * INVALID_OPERATION is generated."
4058 *
4059 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4060 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4061 * set of retrictions).
4062 */
4063 for (i = 0; i < numAttachments; i++) {
4064 if (_mesa_is_winsys_fbo(fb)) {
4065 switch (attachments[i]) {
4066 case GL_ACCUM:
4067 case GL_AUX0:
4068 case GL_AUX1:
4069 case GL_AUX2:
4070 case GL_AUX3:
4071 /* Accumulation buffers and auxilary buffers were removed in
4072 * OpenGL 3.1, and they never existed in OpenGL ES.
4073 */
4074 if (ctx->API != API_OPENGL_COMPAT)
4075 goto invalid_enum;
4076 break;
4077 case GL_COLOR:
4078 case GL_DEPTH:
4079 case GL_STENCIL:
4080 break;
4081 case GL_BACK_LEFT:
4082 case GL_BACK_RIGHT:
4083 case GL_FRONT_LEFT:
4084 case GL_FRONT_RIGHT:
4085 if (!_mesa_is_desktop_gl(ctx))
4086 goto invalid_enum;
4087 break;
4088 default:
4089 goto invalid_enum;
4090 }
4091 } else {
4092 switch (attachments[i]) {
4093 case GL_DEPTH_ATTACHMENT:
4094 case GL_STENCIL_ATTACHMENT:
4095 break;
4096 case GL_DEPTH_STENCIL_ATTACHMENT:
4097 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4098 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4099 * extension does not make this attachment point valid on ES 2.0.
4100 */
4101 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx))
4102 break;
4103 /* fallthrough */
4104 case GL_COLOR_ATTACHMENT0:
4105 case GL_COLOR_ATTACHMENT1:
4106 case GL_COLOR_ATTACHMENT2:
4107 case GL_COLOR_ATTACHMENT3:
4108 case GL_COLOR_ATTACHMENT4:
4109 case GL_COLOR_ATTACHMENT5:
4110 case GL_COLOR_ATTACHMENT6:
4111 case GL_COLOR_ATTACHMENT7:
4112 case GL_COLOR_ATTACHMENT8:
4113 case GL_COLOR_ATTACHMENT9:
4114 case GL_COLOR_ATTACHMENT10:
4115 case GL_COLOR_ATTACHMENT11:
4116 case GL_COLOR_ATTACHMENT12:
4117 case GL_COLOR_ATTACHMENT13:
4118 case GL_COLOR_ATTACHMENT14:
4119 case GL_COLOR_ATTACHMENT15: {
4120 unsigned k = attachments[i] - GL_COLOR_ATTACHMENT0;
4121 if (k >= ctx->Const.MaxColorAttachments) {
4122 _mesa_error(ctx, GL_INVALID_OPERATION,
4123 "%s(attachment >= max. color attachments)", name);
4124 return;
4125 }
4126 break;
4127 }
4128 default:
4129 goto invalid_enum;
4130 }
4131 }
4132 }
4133
4134 /* We don't actually do anything for this yet. Just return after
4135 * validating the parameters and generating the required errors.
4136 */
4137 return;
4138
4139 invalid_enum:
4140 _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid attachment %s)", name,
4141 _mesa_enum_to_string(attachments[i]));
4142 return;
4143 }
4144
4145
4146 void GLAPIENTRY
4147 _mesa_InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments,
4148 const GLenum *attachments, GLint x, GLint y,
4149 GLsizei width, GLsizei height)
4150 {
4151 struct gl_framebuffer *fb;
4152 GET_CURRENT_CONTEXT(ctx);
4153
4154 fb = get_framebuffer_target(ctx, target);
4155 if (!fb) {
4156 _mesa_error(ctx, GL_INVALID_ENUM,
4157 "glInvalidateSubFramebuffer(invalid target %s)",
4158 _mesa_enum_to_string(target));
4159 return;
4160 }
4161
4162 invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments,
4163 x, y, width, height,
4164 "glInvalidateSubFramebuffer");
4165 }
4166
4167
4168 void GLAPIENTRY
4169 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer,
4170 GLsizei numAttachments,
4171 const GLenum *attachments,
4172 GLint x, GLint y,
4173 GLsizei width, GLsizei height)
4174 {
4175 struct gl_framebuffer *fb;
4176 GET_CURRENT_CONTEXT(ctx);
4177
4178 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4179 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4180 * default draw framebuffer is affected."
4181 */
4182 if (framebuffer) {
4183 fb = _mesa_lookup_framebuffer_err(ctx, framebuffer,
4184 "glInvalidateNamedFramebufferSubData");
4185 if (!fb)
4186 return;
4187 }
4188 else
4189 fb = ctx->WinSysDrawBuffer;
4190
4191 invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments,
4192 x, y, width, height,
4193 "glInvalidateNamedFramebufferSubData");
4194 }
4195
4196
4197 void GLAPIENTRY
4198 _mesa_InvalidateFramebuffer(GLenum target, GLsizei numAttachments,
4199 const GLenum *attachments)
4200 {
4201 struct gl_framebuffer *fb;
4202 GET_CURRENT_CONTEXT(ctx);
4203
4204 fb = get_framebuffer_target(ctx, target);
4205 if (!fb) {
4206 _mesa_error(ctx, GL_INVALID_ENUM,
4207 "glInvalidateFramebuffer(invalid target %s)",
4208 _mesa_enum_to_string(target));
4209 return;
4210 }
4211
4212 /* The GL_ARB_invalidate_subdata spec says:
4213 *
4214 * "The command
4215 *
4216 * void InvalidateFramebuffer(enum target,
4217 * sizei numAttachments,
4218 * const enum *attachments);
4219 *
4220 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4221 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4222 * <MAX_VIEWPORT_DIMS[1]> respectively."
4223 */
4224 invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments,
4225 0, 0,
4226 ctx->Const.MaxViewportWidth,
4227 ctx->Const.MaxViewportHeight,
4228 "glInvalidateFramebuffer");
4229 }
4230
4231
4232 void GLAPIENTRY
4233 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer,
4234 GLsizei numAttachments,
4235 const GLenum *attachments)
4236 {
4237 struct gl_framebuffer *fb;
4238 GET_CURRENT_CONTEXT(ctx);
4239
4240 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4241 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4242 * default draw framebuffer is affected."
4243 */
4244 if (framebuffer) {
4245 fb = _mesa_lookup_framebuffer_err(ctx, framebuffer,
4246 "glInvalidateNamedFramebufferData");
4247 if (!fb)
4248 return;
4249 }
4250 else
4251 fb = ctx->WinSysDrawBuffer;
4252
4253 /* The GL_ARB_invalidate_subdata spec says:
4254 *
4255 * "The command
4256 *
4257 * void InvalidateFramebuffer(enum target,
4258 * sizei numAttachments,
4259 * const enum *attachments);
4260 *
4261 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4262 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4263 * <MAX_VIEWPORT_DIMS[1]> respectively."
4264 */
4265 invalidate_framebuffer_storage(ctx, fb, numAttachments, attachments,
4266 0, 0,
4267 ctx->Const.MaxViewportWidth,
4268 ctx->Const.MaxViewportHeight,
4269 "glInvalidateNamedFramebufferData");
4270 }
4271
4272
4273 void GLAPIENTRY
4274 _mesa_DiscardFramebufferEXT(GLenum target, GLsizei numAttachments,
4275 const GLenum *attachments)
4276 {
4277 struct gl_framebuffer *fb;
4278 GLint i;
4279
4280 GET_CURRENT_CONTEXT(ctx);
4281
4282 fb = get_framebuffer_target(ctx, target);
4283 if (!fb) {
4284 _mesa_error(ctx, GL_INVALID_ENUM,
4285 "glDiscardFramebufferEXT(target %s)",
4286 _mesa_enum_to_string(target));
4287 return;
4288 }
4289
4290 if (numAttachments < 0) {
4291 _mesa_error(ctx, GL_INVALID_VALUE,
4292 "glDiscardFramebufferEXT(numAttachments < 0)");
4293 return;
4294 }
4295
4296 for (i = 0; i < numAttachments; i++) {
4297 switch (attachments[i]) {
4298 case GL_COLOR:
4299 case GL_DEPTH:
4300 case GL_STENCIL:
4301 if (_mesa_is_user_fbo(fb))
4302 goto invalid_enum;
4303 break;
4304 case GL_COLOR_ATTACHMENT0:
4305 case GL_DEPTH_ATTACHMENT:
4306 case GL_STENCIL_ATTACHMENT:
4307 if (_mesa_is_winsys_fbo(fb))
4308 goto invalid_enum;
4309 break;
4310 default:
4311 goto invalid_enum;
4312 }
4313 }
4314
4315 if (ctx->Driver.DiscardFramebuffer)
4316 ctx->Driver.DiscardFramebuffer(ctx, target, numAttachments, attachments);
4317
4318 return;
4319
4320 invalid_enum:
4321 _mesa_error(ctx, GL_INVALID_ENUM,
4322 "glDiscardFramebufferEXT(attachment %s)",
4323 _mesa_enum_to_string(attachments[i]));
4324 }