2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
28 * GL_EXT/ARB_framebuffer_object extensions
41 #include "framebuffer.h"
42 #include "glformats.h"
45 #include "multisample.h"
47 #include "renderbuffer.h"
56 * None of the GL_EXT_framebuffer_object functions are compiled into
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.
68 static struct gl_framebuffer DummyFramebuffer
;
69 static struct gl_renderbuffer DummyRenderbuffer
;
71 /* We bind this framebuffer when applications pass a NULL
72 * drawable/surface in make current. */
73 static struct gl_framebuffer IncompleteFramebuffer
;
77 delete_dummy_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
83 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
90 _mesa_init_fbobjects(struct gl_context
*ctx
)
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
;
100 struct gl_framebuffer
*
101 _mesa_get_incomplete_framebuffer(void)
103 return &IncompleteFramebuffer
;
107 * Helper routine for getting a gl_renderbuffer.
109 struct gl_renderbuffer
*
110 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
112 struct gl_renderbuffer
*rb
;
117 rb
= (struct gl_renderbuffer
*)
118 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
124 * A convenience function for direct state access that throws
125 * GL_INVALID_OPERATION if the renderbuffer doesn't exist.
127 struct gl_renderbuffer
*
128 _mesa_lookup_renderbuffer_err(struct gl_context
*ctx
, GLuint id
,
131 struct gl_renderbuffer
*rb
;
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
);
145 * Helper routine for getting a gl_framebuffer.
147 struct gl_framebuffer
*
148 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
150 struct gl_framebuffer
*fb
;
155 fb
= (struct gl_framebuffer
*)
156 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
162 * A convenience function for direct state access that throws
163 * GL_INVALID_OPERATION if the framebuffer doesn't exist.
165 struct gl_framebuffer
*
166 _mesa_lookup_framebuffer_err(struct gl_context
*ctx
, GLuint id
,
169 struct gl_framebuffer
*fb
;
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
);
183 * Mark the given framebuffer as invalid. This will force the
184 * test for framebuffer completeness to be done before the framebuffer
188 invalidate_framebuffer(struct gl_framebuffer
*fb
)
190 fb
->_Status
= 0; /* "indeterminate" */
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
199 * \return gl_framebuffer pointer or NULL if target is illegal
201 static struct gl_framebuffer
*
202 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
204 bool have_fb_blit
= _mesa_is_gles3(ctx
) || _mesa_is_desktop_gl(ctx
);
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
;
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.
226 static struct gl_renderbuffer_attachment
*
227 get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
232 assert(_mesa_is_user_fbo(fb
));
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
255 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
256 if (i
>= ctx
->Const
.MaxColorAttachments
257 || (i
> 0 && ctx
->API
== API_OPENGLES
)) {
260 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
261 case GL_DEPTH_STENCIL_ATTACHMENT
:
262 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
265 case GL_DEPTH_ATTACHMENT_EXT
:
266 return &fb
->Attachment
[BUFFER_DEPTH
];
267 case GL_STENCIL_ATTACHMENT_EXT
:
268 return &fb
->Attachment
[BUFFER_STENCIL
];
276 * As above, but only used for getting attachments of the default /
277 * window-system framebuffer (not user-created framebuffer objects).
279 static struct gl_renderbuffer_attachment
*
280 _mesa_get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
283 assert(_mesa_is_winsys_fbo(fb
));
285 if (_mesa_is_gles3(ctx
)) {
286 assert(attachment
== GL_BACK
||
287 attachment
== GL_DEPTH
||
288 attachment
== GL_STENCIL
);
289 switch (attachment
) {
291 /* Since there is no stereo rendering in ES 3.0, only return the
294 if (ctx
->DrawBuffer
->Visual
.doubleBufferMode
)
295 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
296 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
298 return &fb
->Attachment
[BUFFER_DEPTH
];
300 return &fb
->Attachment
[BUFFER_STENCIL
];
304 switch (attachment
) {
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.
311 if (fb
->Attachment
[BUFFER_FRONT_LEFT
].Type
== GL_NONE
)
312 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
314 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
317 if (fb
->Attachment
[BUFFER_FRONT_RIGHT
].Type
== GL_NONE
)
318 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
320 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
322 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
324 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
326 if (fb
->Visual
.numAuxBuffers
== 1) {
327 return &fb
->Attachment
[BUFFER_AUX0
];
331 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
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."
338 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
339 * language. However, revision #33 of the ARB_framebuffer_object spec
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."
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.
352 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
353 * support queries of the window system FBO.
356 return &fb
->Attachment
[BUFFER_DEPTH
];
358 return &fb
->Attachment
[BUFFER_STENCIL
];
367 * Remove any texture or renderbuffer attached to the given attachment
368 * point. Update reference counts, etc.
371 remove_attachment(struct gl_context
*ctx
,
372 struct gl_renderbuffer_attachment
*att
)
374 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
376 /* tell driver that we're done rendering to this texture. */
377 if (rb
&& rb
->NeedsFinishRenderTexture
)
378 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
380 if (att
->Type
== GL_TEXTURE
) {
381 assert(att
->Texture
);
382 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
383 assert(!att
->Texture
);
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
);
391 att
->Complete
= GL_TRUE
;
395 * Verify a couple error conditions that will lead to an incomplete FBO and
396 * may cause problems for the driver's RenderTexture path.
399 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment
*att
)
401 const struct gl_texture_image
*const texImage
=
402 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
405 texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
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
))
418 * Create a renderbuffer which will be set up by the driver to wrap the
419 * texture image slice.
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.
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.
430 _mesa_update_texture_renderbuffer(struct gl_context
*ctx
,
431 struct gl_framebuffer
*fb
,
432 struct gl_renderbuffer_attachment
*att
)
434 struct gl_texture_image
*texImage
;
435 struct gl_renderbuffer
*rb
;
437 texImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
439 rb
= att
->Renderbuffer
;
441 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
443 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
446 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
448 /* This can't get called on a texture renderbuffer, so set it to NULL
449 * for clarity compared to user renderbuffers.
451 rb
->AllocStorage
= NULL
;
453 rb
->NeedsFinishRenderTexture
= ctx
->Driver
.FinishRenderTexture
!= NULL
;
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
;
468 if (driver_RenderTexture_is_safe(att
))
469 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
473 * Bind a texture object to an attachment point.
474 * The previous binding, if any, will be removed first.
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
,
484 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
486 if (rb
&& rb
->NeedsFinishRenderTexture
)
487 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
489 if (att
->Texture
== texObj
) {
490 /* re-attaching same texture */
491 assert(att
->Type
== GL_TEXTURE
);
495 remove_attachment(ctx
, att
);
496 att
->Type
= GL_TEXTURE
;
497 assert(!att
->Texture
);
498 _mesa_reference_texobj(&att
->Texture
, texObj
);
500 invalidate_framebuffer(fb
);
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
;
509 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
514 * Bind a renderbuffer to an attachment point.
515 * The previous binding, if any, will be removed first.
518 set_renderbuffer_attachment(struct gl_context
*ctx
,
519 struct gl_renderbuffer_attachment
*att
,
520 struct gl_renderbuffer
*rb
)
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
);
533 * Fallback for ctx->Driver.FramebufferRenderbuffer()
534 * Attach a renderbuffer object to a framebuffer object.
537 _mesa_FramebufferRenderbuffer_sw(struct gl_context
*ctx
,
538 struct gl_framebuffer
*fb
,
540 struct gl_renderbuffer
*rb
)
542 struct gl_renderbuffer_attachment
*att
;
544 mtx_lock(&fb
->Mutex
);
546 att
= get_attachment(ctx
, fb
, attachment
);
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
);
554 set_renderbuffer_attachment(ctx
, att
, rb
);
556 rb
->AttachedAnytime
= GL_TRUE
;
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
);
564 remove_attachment(ctx
, att
);
568 invalidate_framebuffer(fb
);
570 mtx_unlock(&fb
->Mutex
);
575 * Fallback for ctx->Driver.ValidateFramebuffer()
576 * Check if the renderbuffer's formats are supported by the software
578 * Drivers should probably override this.
581 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
584 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
585 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
587 switch (rb
->_BaseFormat
) {
589 case GL_LUMINANCE_ALPHA
:
594 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
598 switch (rb
->Format
) {
599 /* XXX This list is likely incomplete. */
600 case MESA_FORMAT_R9G9B9E5_FLOAT
:
601 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
604 /* render buffer format is supported by software rendering */
613 * Return true if the framebuffer has a combined depth/stencil
614 * renderbuffer attached.
617 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
619 const struct gl_renderbuffer_attachment
*depth
=
620 &fb
->Attachment
[BUFFER_DEPTH
];
621 const struct gl_renderbuffer_attachment
*stencil
=
622 &fb
->Attachment
[BUFFER_STENCIL
];
624 if (depth
->Type
== stencil
->Type
) {
625 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
626 depth
->Renderbuffer
== stencil
->Renderbuffer
)
629 if (depth
->Type
== GL_TEXTURE
&&
630 depth
->Texture
== stencil
->Texture
)
642 att_incomplete(const char *msg
)
644 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
645 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
654 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
656 static GLuint msg_id
;
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
);
664 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
665 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
671 * Is the given base format a legal format for a color renderbuffer?
674 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
676 switch (baseFormat
) {
681 case GL_LUMINANCE_ALPHA
:
684 return ctx
->API
== API_OPENGL_COMPAT
&&
685 ctx
->Extensions
.ARB_framebuffer_object
;
688 return ctx
->Extensions
.ARB_texture_rg
;
696 * Is the given base format a legal format for a color renderbuffer?
699 is_format_color_renderable(const struct gl_context
*ctx
, mesa_format format
,
700 GLenum internalFormat
)
702 const GLenum baseFormat
=
703 _mesa_get_format_base_format(format
);
706 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
707 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
711 /* Reject additional cases for GLES */
712 switch (internalFormat
) {
732 if (format
== MESA_FORMAT_B10G10R10A2_UNORM
&&
733 internalFormat
!= GL_RGB10_A2
) {
742 * Is the given base format a legal format for a depth/stencil renderbuffer?
745 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
747 switch (baseFormat
) {
748 case GL_DEPTH_COMPONENT
:
749 case GL_DEPTH_STENCIL_EXT
:
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.
764 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
765 struct gl_renderbuffer_attachment
*att
)
767 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
769 /* assume complete */
770 att
->Complete
= GL_TRUE
;
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
;
779 att_incomplete("no texobj");
780 att
->Complete
= GL_FALSE
;
784 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
786 att_incomplete("no teximage");
787 att
->Complete
= GL_FALSE
;
790 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
791 att_incomplete("teximage width/height=0");
792 att
->Complete
= GL_FALSE
;
796 switch (texObj
->Target
) {
798 if (att
->Zoffset
>= texImage
->Depth
) {
799 att_incomplete("bad z offset");
800 att
->Complete
= GL_FALSE
;
804 case GL_TEXTURE_1D_ARRAY
:
805 if (att
->Zoffset
>= texImage
->Height
) {
806 att_incomplete("bad 1D-array layer");
807 att
->Complete
= GL_FALSE
;
811 case GL_TEXTURE_2D_ARRAY
:
812 if (att
->Zoffset
>= texImage
->Depth
) {
813 att_incomplete("bad 2D-array layer");
814 att
->Complete
= GL_FALSE
;
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
;
827 baseFormat
= texImage
->_BaseFormat
;
829 if (format
== GL_COLOR
) {
830 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
831 att_incomplete("bad format");
832 att
->Complete
= GL_FALSE
;
835 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
836 att_incomplete("compressed internalformat");
837 att
->Complete
= GL_FALSE
;
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.
846 if (_mesa_is_gles(ctx
) && (texImage
->TexObject
->_IsFloat
||
847 texImage
->TexObject
->_IsHalfFloat
)) {
848 att_incomplete("bad internal format");
849 att
->Complete
= GL_FALSE
;
853 else if (format
== GL_DEPTH
) {
854 if (baseFormat
== GL_DEPTH_COMPONENT
) {
857 else if (ctx
->Extensions
.ARB_depth_texture
&&
858 baseFormat
== GL_DEPTH_STENCIL
) {
862 att
->Complete
= GL_FALSE
;
863 att_incomplete("bad depth format");
868 assert(format
== GL_STENCIL
);
869 if (ctx
->Extensions
.ARB_depth_texture
&&
870 baseFormat
== GL_DEPTH_STENCIL
) {
872 } else if (ctx
->Extensions
.ARB_texture_stencil8
&&
873 baseFormat
== GL_STENCIL_INDEX
) {
876 /* no such thing as stencil-only textures */
877 att_incomplete("illegal stencil texture");
878 att
->Complete
= GL_FALSE
;
883 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
884 const GLenum baseFormat
= att
->Renderbuffer
->_BaseFormat
;
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
;
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
;
901 else if (format
== GL_DEPTH
) {
902 if (baseFormat
== GL_DEPTH_COMPONENT
) {
905 else if (baseFormat
== GL_DEPTH_STENCIL
) {
909 att_incomplete("bad renderbuffer depth format");
910 att
->Complete
= GL_FALSE
;
915 assert(format
== GL_STENCIL
);
916 if (baseFormat
== GL_STENCIL_INDEX
||
917 baseFormat
== GL_DEPTH_STENCIL
) {
921 att
->Complete
= GL_FALSE
;
922 att_incomplete("bad renderbuffer stencil format");
928 assert(att
->Type
== GL_NONE
);
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.
944 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
945 struct gl_framebuffer
*fb
)
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;
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;
962 assert(_mesa_is_user_fbo(fb
));
964 /* we're changing framebuffer fields here */
965 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
970 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
971 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
972 fb
->_HasAttachments
= true;
974 /* Start at -2 to more easily loop over all attachment points.
979 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
980 struct gl_renderbuffer_attachment
*att
;
982 mesa_format attFormat
;
983 GLenum att_tex_target
= GL_NONE
;
986 * XXX for ARB_fbo, only check color buffers that are named by
987 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
990 /* check for attachment completeness
993 att
= &fb
->Attachment
[BUFFER_DEPTH
];
994 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
995 if (!att
->Complete
) {
996 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
997 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
999 } else if (att
->Type
!= GL_NONE
) {
1000 has_depth_attachment
= true;
1004 att
= &fb
->Attachment
[BUFFER_STENCIL
];
1005 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
1006 if (!att
->Complete
) {
1007 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1008 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
1010 } else if (att
->Type
!= GL_NONE
) {
1011 has_stencil_attachment
= true;
1015 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
1016 test_attachment_completeness(ctx
, GL_COLOR
, att
);
1017 if (!att
->Complete
) {
1018 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1019 fbo_incomplete(ctx
, "color attachment incomplete", i
);
1024 /* get width, height, format of the renderbuffer/texture
1026 if (att
->Type
== GL_TEXTURE
) {
1027 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
1028 att_tex_target
= att
->Texture
->Target
;
1029 minWidth
= MIN2(minWidth
, texImg
->Width
);
1030 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
1031 minHeight
= MIN2(minHeight
, texImg
->Height
);
1032 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
1033 f
= texImg
->_BaseFormat
;
1034 attFormat
= texImg
->TexFormat
;
1037 if (!is_format_color_renderable(ctx
, attFormat
,
1038 texImg
->InternalFormat
) &&
1039 !is_legal_depth_format(ctx
, f
) &&
1040 f
!= GL_STENCIL_INDEX
) {
1041 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
;
1042 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
1047 numSamples
= texImg
->NumSamples
;
1048 else if (numSamples
!= texImg
->NumSamples
) {
1049 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1050 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1054 if (fixedSampleLocations
< 0)
1055 fixedSampleLocations
= texImg
->FixedSampleLocations
;
1056 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
1057 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1058 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1062 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1063 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
1064 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
1065 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
1066 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
1067 f
= att
->Renderbuffer
->InternalFormat
;
1068 attFormat
= att
->Renderbuffer
->Format
;
1072 numSamples
= att
->Renderbuffer
->NumSamples
;
1073 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
1074 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1075 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1079 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1080 if (fixedSampleLocations
< 0)
1081 fixedSampleLocations
= GL_TRUE
;
1082 else if (fixedSampleLocations
!= GL_TRUE
) {
1083 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1084 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1089 assert(att
->Type
== GL_NONE
);
1093 /* check if integer color */
1094 fb
->_IntegerColor
= _mesa_is_format_integer_color(attFormat
);
1096 /* Update _AllColorBuffersFixedPoint and _HasSNormOrFloatColorBuffer. */
1098 GLenum type
= _mesa_get_format_datatype(attFormat
);
1100 fb
->_AllColorBuffersFixedPoint
=
1101 fb
->_AllColorBuffersFixedPoint
&&
1102 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1104 fb
->_HasSNormOrFloatColorBuffer
=
1105 fb
->_HasSNormOrFloatColorBuffer
||
1106 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1109 /* Error-check width, height, format */
1110 if (numImages
== 1) {
1117 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1118 /* check that width, height, format are same */
1119 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1120 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1121 fbo_incomplete(ctx
, "width or height mismatch", -1);
1124 /* check that all color buffers are the same format */
1125 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1126 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1127 fbo_incomplete(ctx
, "format mismatch", -1);
1133 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1135 if (att
->Type
== GL_RENDERBUFFER
&&
1136 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1137 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1138 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1142 /* Check that layered rendering is consistent. */
1144 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1145 att_layer_count
= 6;
1146 else if (att_tex_target
== GL_TEXTURE_1D_ARRAY
)
1147 att_layer_count
= att
->Renderbuffer
->Height
;
1149 att_layer_count
= att
->Renderbuffer
->Depth
;
1151 att_layer_count
= 0;
1153 if (!layer_info_valid
) {
1154 is_layered
= att
->Layered
;
1155 max_layer_count
= att_layer_count
;
1156 layer_tex_target
= att_tex_target
;
1157 layer_info_valid
= true;
1158 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1159 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1160 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1162 } else if (is_layered
!= att
->Layered
) {
1163 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1165 "framebuffer attachment layer mode is inconsistent",
1168 } else if (att_layer_count
> max_layer_count
) {
1169 max_layer_count
= att_layer_count
;
1173 * The extension GL_ARB_framebuffer_no_attachments places additional
1174 * requirement on each attachment. Those additional requirements are
1175 * tighter that those of previous versions of GL. In interest of better
1176 * compatibility, we will not enforce these restrictions. For the record
1177 * those additional restrictions are quoted below:
1179 * "The width and height of image are greater than zero and less than or
1180 * equal to the values of the implementation-dependent limits
1181 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1183 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1184 * array texture and the attachment is layered, the depth or layer count
1185 * of the texture is less than or equal to the implementation-dependent
1186 * limit MAX_FRAMEBUFFER_LAYERS."
1188 * "If image has multiple samples, its sample count is less than or equal
1189 * to the value of the implementation-dependent limit
1190 * MAX_FRAMEBUFFER_SAMPLES."
1192 * The same requirements are also in place for GL 4.5,
1193 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1197 fb
->MaxNumLayers
= max_layer_count
;
1199 if (numImages
== 0) {
1200 fb
->_HasAttachments
= false;
1202 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1203 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1204 fbo_incomplete(ctx
, "no attachments", -1);
1208 if (fb
->DefaultGeometry
.Width
== 0 || fb
->DefaultGeometry
.Height
== 0) {
1209 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1210 fbo_incomplete(ctx
, "no attachments and default width or height is 0", -1);
1215 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1216 /* Check that all DrawBuffers are present */
1217 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1218 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1219 const struct gl_renderbuffer_attachment
*att
1220 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
1222 if (att
->Type
== GL_NONE
) {
1223 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1224 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1230 /* Check that the ReadBuffer is present */
1231 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1232 const struct gl_renderbuffer_attachment
*att
1233 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
1235 if (att
->Type
== GL_NONE
) {
1236 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1237 fbo_incomplete(ctx
, "missing readbuffer", -1);
1243 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1245 * "Depth and stencil attachments, if present, are the same image."
1247 * This restriction is not present in the OpenGL ES2 spec.
1249 if (_mesa_is_gles3(ctx
) &&
1250 has_stencil_attachment
&& has_depth_attachment
&&
1251 !_mesa_has_depthstencil_combined(fb
)) {
1252 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1253 fbo_incomplete(ctx
, "Depth and stencil attachments must be the same image", -1);
1257 /* Provisionally set status = COMPLETE ... */
1258 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1260 /* ... but the driver may say the FB is incomplete.
1261 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1264 if (ctx
->Driver
.ValidateFramebuffer
) {
1265 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1266 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1267 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1273 * Note that if ARB_framebuffer_object is supported and the attached
1274 * renderbuffers/textures are different sizes, the framebuffer
1275 * width/height will be set to the smallest width/height.
1277 if (numImages
!= 0) {
1278 fb
->Width
= minWidth
;
1279 fb
->Height
= minHeight
;
1282 /* finally, update the visual info for the framebuffer */
1283 _mesa_update_framebuffer_visual(ctx
, fb
);
1287 GLboolean GLAPIENTRY
1288 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1290 GET_CURRENT_CONTEXT(ctx
);
1291 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1293 struct gl_renderbuffer
*rb
=
1294 _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1295 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
1302 static struct gl_renderbuffer
*
1303 allocate_renderbuffer_locked(struct gl_context
*ctx
, GLuint renderbuffer
,
1306 struct gl_renderbuffer
*newRb
;
1308 /* create new renderbuffer object */
1309 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1311 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1314 assert(newRb
->AllocStorage
);
1315 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1316 newRb
->RefCount
= 1; /* referenced by hash table */
1323 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1325 struct gl_renderbuffer
*newRb
;
1326 GET_CURRENT_CONTEXT(ctx
);
1328 if (target
!= GL_RENDERBUFFER_EXT
) {
1329 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1333 /* No need to flush here since the render buffer binding has no
1334 * effect on rendering state.
1338 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1339 if (newRb
== &DummyRenderbuffer
) {
1340 /* ID was reserved, but no real renderbuffer object made yet */
1343 else if (!newRb
&& !allow_user_names
) {
1344 /* All RB IDs must be Gen'd */
1345 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1350 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1351 newRb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
1352 "glBindRenderbufferEXT");
1353 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1360 assert(newRb
!= &DummyRenderbuffer
);
1362 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1366 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1368 GET_CURRENT_CONTEXT(ctx
);
1370 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1371 * entry point, but they allow the use of user-generated names.
1373 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1377 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1379 /* This function should not be in the dispatch table for core profile /
1380 * OpenGL 3.1, so execution should never get here in those cases -- no
1381 * need for an explicit test.
1383 bind_renderbuffer(target
, renderbuffer
, true);
1387 * ARB_framebuffer_no_attachment - Application passes requested param's
1388 * here. NOTE: NumSamples requested need not be _NumSamples which is
1389 * what the hw supports.
1392 framebuffer_parameteri(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1393 GLenum pname
, GLint param
, const char *func
)
1396 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1397 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferWidth
)
1398 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1400 fb
->DefaultGeometry
.Width
= param
;
1402 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1403 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferHeight
)
1404 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1406 fb
->DefaultGeometry
.Height
= param
;
1408 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1410 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1411 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1413 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1414 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1417 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferLayers
)
1418 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1420 fb
->DefaultGeometry
.Layers
= param
;
1422 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1423 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferSamples
)
1424 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1426 fb
->DefaultGeometry
.NumSamples
= param
;
1428 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1429 fb
->DefaultGeometry
.FixedSampleLocations
= param
;
1432 _mesa_error(ctx
, GL_INVALID_ENUM
,
1433 "%s(pname=0x%x)", func
, pname
);
1436 invalidate_framebuffer(fb
);
1437 ctx
->NewState
|= _NEW_BUFFERS
;
1441 _mesa_FramebufferParameteri(GLenum target
, GLenum pname
, GLint param
)
1443 GET_CURRENT_CONTEXT(ctx
);
1444 struct gl_framebuffer
*fb
;
1446 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1447 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1448 "glFramebufferParameteriv not supported "
1449 "(ARB_framebuffer_no_attachments not implemented)");
1453 fb
= get_framebuffer_target(ctx
, target
);
1455 _mesa_error(ctx
, GL_INVALID_ENUM
,
1456 "glFramebufferParameteri(target=0x%x)", target
);
1460 /* check framebuffer binding */
1461 if (_mesa_is_winsys_fbo(fb
)) {
1462 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1463 "glFramebufferParameteri");
1467 framebuffer_parameteri(ctx
, fb
, pname
, param
, "glFramebufferParameteri");
1471 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1472 GLenum pname
, GLint
*params
, const char *func
)
1475 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1476 *params
= fb
->DefaultGeometry
.Width
;
1478 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1479 *params
= fb
->DefaultGeometry
.Height
;
1481 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1483 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1484 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1486 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1487 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1490 *params
= fb
->DefaultGeometry
.Layers
;
1492 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1493 *params
= fb
->DefaultGeometry
.NumSamples
;
1495 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1496 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1499 _mesa_error(ctx
, GL_INVALID_ENUM
,
1500 "%s(pname=0x%x)", func
, pname
);
1505 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1507 GET_CURRENT_CONTEXT(ctx
);
1508 struct gl_framebuffer
*fb
;
1510 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1511 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1512 "glGetFramebufferParameteriv not supported "
1513 "(ARB_framebuffer_no_attachments not implemented)");
1517 fb
= get_framebuffer_target(ctx
, target
);
1519 _mesa_error(ctx
, GL_INVALID_ENUM
,
1520 "glGetFramebufferParameteriv(target=0x%x)", target
);
1524 /* check framebuffer binding */
1525 if (_mesa_is_winsys_fbo(fb
)) {
1526 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1527 "glGetFramebufferParameteriv");
1531 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1532 "glGetFramebufferParameteriv");
1537 * Remove the specified renderbuffer or texture from any attachment point in
1541 * \c true if the renderbuffer was detached from an attachment point. \c
1545 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1546 struct gl_framebuffer
*fb
,
1550 bool progress
= false;
1552 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1553 if (fb
->Attachment
[i
].Texture
== att
1554 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1555 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1560 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1561 * Completeness," of the OpenGL 3.1 spec says:
1563 * "Performing any of the following actions may change whether the
1564 * framebuffer is considered complete or incomplete:
1568 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1569 * containing an image that is attached to a framebuffer object
1570 * that is bound to the framebuffer."
1573 invalidate_framebuffer(fb
);
1580 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1583 GET_CURRENT_CONTEXT(ctx
);
1586 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1590 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1592 for (i
= 0; i
< n
; i
++) {
1593 if (renderbuffers
[i
] > 0) {
1594 struct gl_renderbuffer
*rb
;
1595 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1597 /* check if deleting currently bound renderbuffer object */
1598 if (rb
== ctx
->CurrentRenderbuffer
) {
1600 assert(rb
->RefCount
>= 2);
1601 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1604 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1605 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1606 * of the OpenGL 3.1 spec says:
1608 * "If a renderbuffer object is deleted while its image is
1609 * attached to one or more attachment points in the currently
1610 * bound framebuffer, then it is as if FramebufferRenderbuffer
1611 * had been called, with a renderbuffer of 0, for each
1612 * attachment point to which this image was attached in the
1613 * currently bound framebuffer. In other words, this
1614 * renderbuffer image is first detached from all attachment
1615 * points in the currently bound framebuffer. Note that the
1616 * renderbuffer image is specifically not detached from any
1617 * non-bound framebuffers. Detaching the image from any
1618 * non-bound framebuffers is the responsibility of the
1621 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1622 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1624 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1625 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1626 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1629 /* Remove from hash table immediately, to free the ID.
1630 * But the object will not be freed until it's no longer
1631 * referenced anywhere else.
1633 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1635 if (rb
!= &DummyRenderbuffer
) {
1636 /* no longer referenced by hash table */
1637 _mesa_reference_renderbuffer(&rb
, NULL
);
1645 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1648 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1653 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1660 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1662 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1664 for (i
= 0; i
< n
; i
++) {
1665 GLuint name
= first
+ i
;
1666 renderbuffers
[i
] = name
;
1669 allocate_renderbuffer_locked(ctx
, name
, func
);
1671 /* insert a dummy renderbuffer into the hash table */
1672 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1673 &DummyRenderbuffer
);
1677 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1682 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1684 GET_CURRENT_CONTEXT(ctx
);
1685 create_render_buffers(ctx
, n
, renderbuffers
, false);
1690 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1692 GET_CURRENT_CONTEXT(ctx
);
1693 create_render_buffers(ctx
, n
, renderbuffers
, true);
1698 * Given an internal format token for a render buffer, return the
1699 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1700 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1701 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1703 * This is similar to _mesa_base_tex_format() but the set of valid
1704 * internal formats is different.
1706 * Note that even if a format is determined to be legal here, validation
1707 * of the FBO may fail if the format is not supported by the driver/GPU.
1709 * \param internalFormat as passed to glRenderbufferStorage()
1710 * \return the base internal format, or 0 if internalFormat is illegal
1713 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1716 * Notes: some formats such as alpha, luminance, etc. were added
1717 * with GL_ARB_framebuffer_object.
1719 switch (internalFormat
) {
1725 return (ctx
->API
== API_OPENGL_COMPAT
&&
1726 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
1730 case GL_LUMINANCE12
:
1731 case GL_LUMINANCE16
:
1732 return (ctx
->API
== API_OPENGL_COMPAT
&&
1733 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
1734 case GL_LUMINANCE_ALPHA
:
1735 case GL_LUMINANCE4_ALPHA4
:
1736 case GL_LUMINANCE6_ALPHA2
:
1737 case GL_LUMINANCE8_ALPHA8
:
1738 case GL_LUMINANCE12_ALPHA4
:
1739 case GL_LUMINANCE12_ALPHA12
:
1740 case GL_LUMINANCE16_ALPHA16
:
1741 return (ctx
->API
== API_OPENGL_COMPAT
&&
1742 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
1746 case GL_INTENSITY12
:
1747 case GL_INTENSITY16
:
1748 return (ctx
->API
== API_OPENGL_COMPAT
&&
1749 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
1759 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1761 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1770 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1772 case GL_SRGB8_ALPHA8_EXT
:
1773 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1774 case GL_STENCIL_INDEX
:
1775 case GL_STENCIL_INDEX1_EXT
:
1776 case GL_STENCIL_INDEX4_EXT
:
1777 case GL_STENCIL_INDEX16_EXT
:
1778 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1779 * OpenGL ES, but Mesa does not currently support them.
1781 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1782 case GL_STENCIL_INDEX8_EXT
:
1783 return GL_STENCIL_INDEX
;
1784 case GL_DEPTH_COMPONENT
:
1785 case GL_DEPTH_COMPONENT32
:
1786 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1787 case GL_DEPTH_COMPONENT16
:
1788 case GL_DEPTH_COMPONENT24
:
1789 return GL_DEPTH_COMPONENT
;
1790 case GL_DEPTH_STENCIL
:
1791 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
1792 case GL_DEPTH24_STENCIL8
:
1793 return GL_DEPTH_STENCIL
;
1794 case GL_DEPTH_COMPONENT32F
:
1795 return ctx
->Version
>= 30
1796 || (ctx
->API
== API_OPENGL_COMPAT
&&
1797 ctx
->Extensions
.ARB_depth_buffer_float
)
1798 ? GL_DEPTH_COMPONENT
: 0;
1799 case GL_DEPTH32F_STENCIL8
:
1800 return ctx
->Version
>= 30
1801 || (ctx
->API
== API_OPENGL_COMPAT
&&
1802 ctx
->Extensions
.ARB_depth_buffer_float
)
1803 ? GL_DEPTH_STENCIL
: 0;
1806 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1809 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1813 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1816 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1818 /* signed normalized texture formats */
1822 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1827 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1831 case GL_RGB16_SNORM
:
1832 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1835 case GL_RGBA8_SNORM
:
1836 case GL_RGBA16_SNORM
:
1837 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1839 case GL_ALPHA_SNORM
:
1840 case GL_ALPHA8_SNORM
:
1841 case GL_ALPHA16_SNORM
:
1842 return ctx
->API
== API_OPENGL_COMPAT
&&
1843 ctx
->Extensions
.EXT_texture_snorm
&&
1844 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1845 case GL_LUMINANCE_SNORM
:
1846 case GL_LUMINANCE8_SNORM
:
1847 case GL_LUMINANCE16_SNORM
:
1848 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1850 case GL_LUMINANCE_ALPHA_SNORM
:
1851 case GL_LUMINANCE8_ALPHA8_SNORM
:
1852 case GL_LUMINANCE16_ALPHA16_SNORM
:
1853 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1854 ? GL_LUMINANCE_ALPHA
: 0;
1855 case GL_INTENSITY_SNORM
:
1856 case GL_INTENSITY8_SNORM
:
1857 case GL_INTENSITY16_SNORM
:
1858 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1863 return ((_mesa_is_desktop_gl(ctx
) &&
1864 ctx
->Extensions
.ARB_texture_rg
&&
1865 ctx
->Extensions
.ARB_texture_float
) ||
1866 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1870 return ((_mesa_is_desktop_gl(ctx
) &&
1871 ctx
->Extensions
.ARB_texture_rg
&&
1872 ctx
->Extensions
.ARB_texture_float
) ||
1873 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1877 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1881 return ((_mesa_is_desktop_gl(ctx
) &&
1882 ctx
->Extensions
.ARB_texture_float
) ||
1883 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1885 case GL_ALPHA16F_ARB
:
1886 case GL_ALPHA32F_ARB
:
1887 return ctx
->API
== API_OPENGL_COMPAT
&&
1888 ctx
->Extensions
.ARB_texture_float
&&
1889 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1890 case GL_LUMINANCE16F_ARB
:
1891 case GL_LUMINANCE32F_ARB
:
1892 return ctx
->API
== API_OPENGL_COMPAT
&&
1893 ctx
->Extensions
.ARB_texture_float
&&
1894 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1895 case GL_LUMINANCE_ALPHA16F_ARB
:
1896 case GL_LUMINANCE_ALPHA32F_ARB
:
1897 return ctx
->API
== API_OPENGL_COMPAT
&&
1898 ctx
->Extensions
.ARB_texture_float
&&
1899 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1900 case GL_INTENSITY16F_ARB
:
1901 case GL_INTENSITY32F_ARB
:
1902 return ctx
->API
== API_OPENGL_COMPAT
&&
1903 ctx
->Extensions
.ARB_texture_float
&&
1904 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1905 case GL_R11F_G11F_B10F
:
1906 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1907 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1910 case GL_RGBA8UI_EXT
:
1911 case GL_RGBA16UI_EXT
:
1912 case GL_RGBA32UI_EXT
:
1914 case GL_RGBA16I_EXT
:
1915 case GL_RGBA32I_EXT
:
1916 return ctx
->Version
>= 30
1917 || (_mesa_is_desktop_gl(ctx
) &&
1918 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
1921 case GL_RGB16UI_EXT
:
1922 case GL_RGB32UI_EXT
:
1926 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
1934 return ctx
->Version
>= 30
1935 || (_mesa_is_desktop_gl(ctx
) &&
1936 ctx
->Extensions
.ARB_texture_rg
&&
1937 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
1945 return ctx
->Version
>= 30
1946 || (_mesa_is_desktop_gl(ctx
) &&
1947 ctx
->Extensions
.ARB_texture_rg
&&
1948 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
1950 case GL_INTENSITY8I_EXT
:
1951 case GL_INTENSITY8UI_EXT
:
1952 case GL_INTENSITY16I_EXT
:
1953 case GL_INTENSITY16UI_EXT
:
1954 case GL_INTENSITY32I_EXT
:
1955 case GL_INTENSITY32UI_EXT
:
1956 return ctx
->API
== API_OPENGL_COMPAT
&&
1957 ctx
->Extensions
.EXT_texture_integer
&&
1958 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1960 case GL_LUMINANCE8I_EXT
:
1961 case GL_LUMINANCE8UI_EXT
:
1962 case GL_LUMINANCE16I_EXT
:
1963 case GL_LUMINANCE16UI_EXT
:
1964 case GL_LUMINANCE32I_EXT
:
1965 case GL_LUMINANCE32UI_EXT
:
1966 return ctx
->API
== API_OPENGL_COMPAT
&&
1967 ctx
->Extensions
.EXT_texture_integer
&&
1968 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1970 case GL_LUMINANCE_ALPHA8I_EXT
:
1971 case GL_LUMINANCE_ALPHA8UI_EXT
:
1972 case GL_LUMINANCE_ALPHA16I_EXT
:
1973 case GL_LUMINANCE_ALPHA16UI_EXT
:
1974 case GL_LUMINANCE_ALPHA32I_EXT
:
1975 case GL_LUMINANCE_ALPHA32UI_EXT
:
1976 return ctx
->API
== API_OPENGL_COMPAT
&&
1977 ctx
->Extensions
.EXT_texture_integer
&&
1978 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1980 case GL_ALPHA8I_EXT
:
1981 case GL_ALPHA8UI_EXT
:
1982 case GL_ALPHA16I_EXT
:
1983 case GL_ALPHA16UI_EXT
:
1984 case GL_ALPHA32I_EXT
:
1985 case GL_ALPHA32UI_EXT
:
1986 return ctx
->API
== API_OPENGL_COMPAT
&&
1987 ctx
->Extensions
.EXT_texture_integer
&&
1988 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1991 return (_mesa_is_desktop_gl(ctx
) &&
1992 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
1993 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1996 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2005 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2008 invalidate_rb(GLuint key
, void *data
, void *userData
)
2010 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2011 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2013 /* If this is a user-created FBO */
2014 if (_mesa_is_user_fbo(fb
)) {
2016 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2017 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2018 if (att
->Type
== GL_RENDERBUFFER
&&
2019 att
->Renderbuffer
== rb
) {
2020 /* Mark fb status as indeterminate to force re-validation */
2029 /** sentinal value, see below */
2030 #define NO_SAMPLES 1000
2033 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2034 GLenum internalFormat
, GLsizei width
,
2035 GLsizei height
, GLsizei samples
)
2037 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2039 assert(baseFormat
!= 0);
2040 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2041 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2042 assert(samples
!= NO_SAMPLES
);
2044 assert(samples
> 0);
2045 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2046 internalFormat
, samples
) == GL_NO_ERROR
);
2049 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2051 if (rb
->InternalFormat
== internalFormat
&&
2052 rb
->Width
== (GLuint
) width
&&
2053 rb
->Height
== (GLuint
) height
&&
2054 rb
->NumSamples
== samples
) {
2055 /* no change in allocation needed */
2059 /* These MUST get set by the AllocStorage func */
2060 rb
->Format
= MESA_FORMAT_NONE
;
2061 rb
->NumSamples
= samples
;
2063 /* Now allocate the storage */
2064 assert(rb
->AllocStorage
);
2065 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2066 /* No error - check/set fields now */
2067 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2068 assert(rb
->Width
== (GLuint
) width
);
2069 assert(rb
->Height
== (GLuint
) height
);
2070 rb
->InternalFormat
= internalFormat
;
2071 rb
->_BaseFormat
= baseFormat
;
2072 assert(rb
->_BaseFormat
!= 0);
2075 /* Probably ran out of memory - clear the fields */
2078 rb
->Format
= MESA_FORMAT_NONE
;
2079 rb
->InternalFormat
= GL_NONE
;
2080 rb
->_BaseFormat
= GL_NONE
;
2084 /* Invalidate the framebuffers the renderbuffer is attached in. */
2085 if (rb
->AttachedAnytime
) {
2086 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2091 * Helper function used by renderbuffer_storage_direct() and
2092 * renderbuffer_storage_target().
2093 * samples will be NO_SAMPLES if called by a non-multisample function.
2096 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2097 GLenum internalFormat
, GLsizei width
,
2098 GLsizei height
, GLsizei samples
, const char *func
)
2101 GLenum sample_count_error
;
2103 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2104 if (baseFormat
== 0) {
2105 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2106 func
, _mesa_enum_to_string(internalFormat
));
2110 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2111 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2116 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2117 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2122 if (samples
== NO_SAMPLES
) {
2123 /* NumSamples == 0 indicates non-multisampling */
2127 /* check the sample count;
2128 * note: driver may choose to use more samples than what's requested
2130 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2131 internalFormat
, samples
);
2133 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2135 * "If a negative number is provided where an argument of type sizei or
2136 * sizeiptr is specified, the error INVALID VALUE is generated."
2139 sample_count_error
= GL_INVALID_VALUE
;
2142 if (sample_count_error
!= GL_NO_ERROR
) {
2143 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
2148 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
);
2152 * Helper function used by _mesa_NamedRenderbufferStorage*().
2153 * samples will be NO_SAMPLES if called by a non-multisample function.
2156 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2157 GLsizei width
, GLsizei height
, GLsizei samples
,
2160 GET_CURRENT_CONTEXT(ctx
);
2162 if (MESA_VERBOSE
& VERBOSE_API
) {
2163 if (samples
== NO_SAMPLES
)
2164 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2166 _mesa_enum_to_string(internalFormat
),
2169 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2171 _mesa_enum_to_string(internalFormat
),
2172 width
, height
, samples
);
2175 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2176 if (!rb
|| rb
== &DummyRenderbuffer
) {
2177 /* ID was reserved, but no real renderbuffer object made yet */
2178 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2179 func
, renderbuffer
);
2183 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
, func
);
2187 * Helper function used by _mesa_RenderbufferStorage() and
2188 * _mesa_RenderbufferStorageMultisample().
2189 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2192 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2193 GLsizei width
, GLsizei height
, GLsizei samples
,
2196 GET_CURRENT_CONTEXT(ctx
);
2198 if (MESA_VERBOSE
& VERBOSE_API
) {
2199 if (samples
== NO_SAMPLES
)
2200 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2202 _mesa_enum_to_string(target
),
2203 _mesa_enum_to_string(internalFormat
),
2206 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2208 _mesa_enum_to_string(target
),
2209 _mesa_enum_to_string(internalFormat
),
2210 width
, height
, samples
);
2213 if (target
!= GL_RENDERBUFFER_EXT
) {
2214 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2218 if (!ctx
->CurrentRenderbuffer
) {
2219 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2224 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2225 height
, samples
, func
);
2230 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2232 struct gl_renderbuffer
*rb
;
2233 GET_CURRENT_CONTEXT(ctx
);
2235 if (!ctx
->Extensions
.OES_EGL_image
) {
2236 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2237 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2241 if (target
!= GL_RENDERBUFFER
) {
2242 _mesa_error(ctx
, GL_INVALID_ENUM
,
2243 "EGLImageTargetRenderbufferStorageOES");
2247 rb
= ctx
->CurrentRenderbuffer
;
2249 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2250 "EGLImageTargetRenderbufferStorageOES");
2254 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2256 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2261 * Helper function for _mesa_GetRenderbufferParameteriv() and
2262 * _mesa_GetFramebufferAttachmentParameteriv()
2263 * We have to be careful to respect the base format. For example, if a
2264 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2265 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2266 * we need to return zero.
2269 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2271 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2272 return _mesa_get_format_bits(format
, pname
);
2280 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2281 GLsizei width
, GLsizei height
)
2283 /* GL_ARB_fbo says calling this function is equivalent to calling
2284 * glRenderbufferStorageMultisample() with samples=0. We pass in
2285 * a token value here just for error reporting purposes.
2287 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2288 NO_SAMPLES
, "glRenderbufferStorage");
2293 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2294 GLenum internalFormat
,
2295 GLsizei width
, GLsizei height
)
2297 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2298 samples
, "glRenderbufferStorageMultisample");
2303 * OpenGL ES version of glRenderBufferStorage.
2306 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2307 GLsizei width
, GLsizei height
)
2309 switch (internalFormat
) {
2311 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2312 /* choose a closest format */
2313 internalFormat
= GL_RGB5
;
2319 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0,
2320 "glRenderbufferStorageEXT");
2324 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2325 GLsizei width
, GLsizei height
)
2327 /* GL_ARB_fbo says calling this function is equivalent to calling
2328 * glRenderbufferStorageMultisample() with samples=0. We pass in
2329 * a token value here just for error reporting purposes.
2331 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2332 NO_SAMPLES
, "glNamedRenderbufferStorage");
2336 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2337 GLenum internalformat
,
2338 GLsizei width
, GLsizei height
)
2340 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2342 "glNamedRenderbufferStorageMultisample");
2347 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2348 struct gl_renderbuffer
*rb
, GLenum pname
,
2349 GLint
*params
, const char *func
)
2351 /* No need to flush here since we're just quering state which is
2352 * not effected by rendering.
2356 case GL_RENDERBUFFER_WIDTH_EXT
:
2357 *params
= rb
->Width
;
2359 case GL_RENDERBUFFER_HEIGHT_EXT
:
2360 *params
= rb
->Height
;
2362 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2363 *params
= rb
->InternalFormat
;
2365 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2366 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2367 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2368 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2369 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2370 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2371 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2373 case GL_RENDERBUFFER_SAMPLES
:
2374 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2375 || _mesa_is_gles3(ctx
)) {
2376 *params
= rb
->NumSamples
;
2381 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2382 _mesa_enum_to_string(pname
));
2389 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2391 GET_CURRENT_CONTEXT(ctx
);
2393 if (target
!= GL_RENDERBUFFER_EXT
) {
2394 _mesa_error(ctx
, GL_INVALID_ENUM
,
2395 "glGetRenderbufferParameterivEXT(target)");
2399 if (!ctx
->CurrentRenderbuffer
) {
2400 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2401 "(no renderbuffer bound)");
2405 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2406 params
, "glGetRenderbufferParameteriv");
2411 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2414 GET_CURRENT_CONTEXT(ctx
);
2416 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2417 if (!rb
|| rb
== &DummyRenderbuffer
) {
2418 /* ID was reserved, but no real renderbuffer object made yet */
2419 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2420 "(invalid renderbuffer %i)", renderbuffer
);
2424 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2425 "glGetNamedRenderbufferParameteriv");
2429 GLboolean GLAPIENTRY
2430 _mesa_IsFramebuffer(GLuint framebuffer
)
2432 GET_CURRENT_CONTEXT(ctx
);
2433 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2435 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2436 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2444 * Check if any of the attachments of the given framebuffer are textures
2445 * (render to texture). Call ctx->Driver.RenderTexture() for such
2449 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2452 assert(ctx
->Driver
.RenderTexture
);
2454 if (_mesa_is_winsys_fbo(fb
))
2455 return; /* can't render to texture with winsys framebuffers */
2457 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2458 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2459 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2460 && driver_RenderTexture_is_safe(att
)) {
2461 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2468 * Examine all the framebuffer's attachments to see if any are textures.
2469 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2470 * notify the device driver that the texture image may have changed.
2473 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2475 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2476 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2479 if (ctx
->Driver
.FinishRenderTexture
) {
2481 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2482 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2483 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2484 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2485 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2493 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2495 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2496 GLboolean bindReadBuf
, bindDrawBuf
;
2497 GET_CURRENT_CONTEXT(ctx
);
2500 case GL_DRAW_FRAMEBUFFER_EXT
:
2501 bindDrawBuf
= GL_TRUE
;
2502 bindReadBuf
= GL_FALSE
;
2504 case GL_READ_FRAMEBUFFER_EXT
:
2505 bindDrawBuf
= GL_FALSE
;
2506 bindReadBuf
= GL_TRUE
;
2508 case GL_FRAMEBUFFER_EXT
:
2509 bindDrawBuf
= GL_TRUE
;
2510 bindReadBuf
= GL_TRUE
;
2513 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2518 /* Binding a user-created framebuffer object */
2519 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2520 if (newDrawFb
== &DummyFramebuffer
) {
2521 /* ID was reserved, but no real framebuffer object made yet */
2524 else if (!newDrawFb
&& !allow_user_names
) {
2525 /* All FBO IDs must be Gen'd */
2526 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2531 /* create new framebuffer object */
2532 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2534 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2537 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2539 newReadFb
= newDrawFb
;
2542 /* Binding the window system framebuffer (which was originally set
2543 * with MakeCurrent).
2545 newDrawFb
= ctx
->WinSysDrawBuffer
;
2546 newReadFb
= ctx
->WinSysReadBuffer
;
2549 _mesa_bind_framebuffers(ctx
,
2550 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2551 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2555 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2556 struct gl_framebuffer
*newDrawFb
,
2557 struct gl_framebuffer
*newReadFb
)
2559 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
2560 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
2561 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
2562 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
2565 assert(newDrawFb
!= &DummyFramebuffer
);
2568 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2570 * We also check if we're beginning and/or ending render-to-texture.
2571 * When a framebuffer with texture attachments is unbound, call
2572 * ctx->Driver.FinishRenderTexture().
2573 * When a framebuffer with texture attachments is bound, call
2574 * ctx->Driver.RenderTexture().
2576 * Note that if the ReadBuffer has texture attachments we don't consider
2577 * that a render-to-texture case.
2580 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2582 /* check if old readbuffer was render-to-texture */
2583 check_end_texture_render(ctx
, oldReadFb
);
2585 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2589 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2591 /* check if old framebuffer had any texture attachments */
2593 check_end_texture_render(ctx
, oldDrawFb
);
2595 /* check if newly bound framebuffer has any texture attachments */
2596 check_begin_texture_render(ctx
, newDrawFb
);
2598 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2601 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2602 /* The few classic drivers that actually hook this function really only
2603 * want to know if the draw framebuffer changed.
2605 ctx
->Driver
.BindFramebuffer(ctx
,
2606 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
2607 newDrawFb
, newReadFb
);
2612 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2614 GET_CURRENT_CONTEXT(ctx
);
2616 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2617 * point, but they allow the use of user-generated names.
2619 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2624 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2626 /* This function should not be in the dispatch table for core profile /
2627 * OpenGL 3.1, so execution should never get here in those cases -- no
2628 * need for an explicit test.
2630 bind_framebuffer(target
, framebuffer
, true);
2635 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2638 GET_CURRENT_CONTEXT(ctx
);
2641 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
2645 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2647 for (i
= 0; i
< n
; i
++) {
2648 if (framebuffers
[i
] > 0) {
2649 struct gl_framebuffer
*fb
;
2650 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2652 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2654 /* check if deleting currently bound framebuffer object */
2655 if (fb
== ctx
->DrawBuffer
) {
2657 assert(fb
->RefCount
>= 2);
2658 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2660 if (fb
== ctx
->ReadBuffer
) {
2662 assert(fb
->RefCount
>= 2);
2663 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2666 /* remove from hash table immediately, to free the ID */
2667 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2669 if (fb
!= &DummyFramebuffer
) {
2670 /* But the object will not be freed until it's no longer
2671 * bound in any context.
2673 _mesa_reference_framebuffer(&fb
, NULL
);
2682 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2683 * It is not exposed to the rest of Mesa to encourage the use of
2684 * nameless buffers in driver internals.
2687 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
2689 GET_CURRENT_CONTEXT(ctx
);
2692 struct gl_framebuffer
*fb
;
2694 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
2697 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
2704 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
2706 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2708 for (i
= 0; i
< n
; i
++) {
2709 GLuint name
= first
+ i
;
2710 framebuffers
[i
] = name
;
2713 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
2715 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2716 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
2721 fb
= &DummyFramebuffer
;
2723 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
2726 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2731 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2733 create_framebuffers(n
, framebuffers
, false);
2738 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2740 create_framebuffers(n
, framebuffers
, true);
2745 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
2746 struct gl_framebuffer
*buffer
)
2748 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2750 if (_mesa_is_winsys_fbo(buffer
)) {
2751 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2752 if (buffer
!= &IncompleteFramebuffer
) {
2753 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2755 return GL_FRAMEBUFFER_UNDEFINED
;
2759 /* No need to flush here */
2761 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2762 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2765 return buffer
->_Status
;
2770 _mesa_CheckFramebufferStatus(GLenum target
)
2772 struct gl_framebuffer
*fb
;
2773 GET_CURRENT_CONTEXT(ctx
);
2775 if (MESA_VERBOSE
& VERBOSE_API
)
2776 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2777 _mesa_enum_to_string(target
));
2779 fb
= get_framebuffer_target(ctx
, target
);
2781 _mesa_error(ctx
, GL_INVALID_ENUM
,
2782 "glCheckFramebufferStatus(invalid target %s)",
2783 _mesa_enum_to_string(target
));
2787 return _mesa_check_framebuffer_status(ctx
, fb
);
2792 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
2794 struct gl_framebuffer
*fb
;
2795 GET_CURRENT_CONTEXT(ctx
);
2797 /* Validate the target (for conformance's sake) and grab a reference to the
2798 * default framebuffer in case framebuffer = 0.
2799 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
2800 * (30.10.2014, PDF page 336) says:
2801 * "If framebuffer is zero, then the status of the default read or
2802 * draw framebuffer (as determined by target) is returned."
2805 case GL_DRAW_FRAMEBUFFER
:
2806 case GL_FRAMEBUFFER
:
2807 fb
= ctx
->WinSysDrawBuffer
;
2809 case GL_READ_FRAMEBUFFER
:
2810 fb
= ctx
->WinSysReadBuffer
;
2813 _mesa_error(ctx
, GL_INVALID_ENUM
,
2814 "glCheckNamedFramebufferStatus(invalid target %s)",
2815 _mesa_enum_to_string(target
));
2820 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
2821 "glCheckNamedFramebufferStatus");
2826 return _mesa_check_framebuffer_status(ctx
, fb
);
2831 * Replicate the src attachment point. Used by framebuffer_texture() when
2832 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2833 * GL_STENCIL_ATTACHMENT.
2836 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2837 gl_buffer_index dst
,
2838 gl_buffer_index src
)
2840 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2841 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2843 assert(src_att
->Texture
!= NULL
);
2844 assert(src_att
->Renderbuffer
!= NULL
);
2846 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2847 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2848 dst_att
->Type
= src_att
->Type
;
2849 dst_att
->Complete
= src_att
->Complete
;
2850 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2851 dst_att
->Zoffset
= src_att
->Zoffset
;
2852 dst_att
->Layered
= src_att
->Layered
;
2857 * Common code called by gl*FramebufferTexture*() to retrieve the correct
2858 * texture object pointer.
2860 * \param texObj where the pointer to the texture object is returned. Note
2861 * that a successful call may return texObj = NULL.
2863 * \return true if no errors, false if errors
2866 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
,
2867 bool layered
, const char *caller
,
2868 struct gl_texture_object
**texObj
)
2870 *texObj
= NULL
; /* This will get returned if texture = 0. */
2875 *texObj
= _mesa_lookup_texture(ctx
, texture
);
2876 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
2877 /* Can't render to a non-existent texture object.
2879 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
2880 * Managing Framebuffer Objects specifies a different error
2881 * depending upon the calling function (PDF pages 325-328).
2882 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
2883 * value, while the other commands throw invalid operation (where
2884 * layered = GL_FALSE).
2886 const GLenum error
= layered
? GL_INVALID_VALUE
:
2887 GL_INVALID_OPERATION
;
2888 _mesa_error(ctx
, error
,
2889 "%s(non-existent texture %u)", caller
, texture
);
2898 * Common code called by gl*FramebufferTexture() to verify the texture target
2899 * and decide whether or not the attachment should truly be considered
2902 * \param layered true if attachment should be considered layered, false if
2905 * \return true if no errors, false if errors
2908 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
2909 const char *caller
, GLboolean
*layered
)
2915 case GL_TEXTURE_1D_ARRAY_EXT
:
2916 case GL_TEXTURE_2D_ARRAY_EXT
:
2917 case GL_TEXTURE_CUBE_MAP
:
2918 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2919 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2923 case GL_TEXTURE_RECTANGLE
:
2924 case GL_TEXTURE_2D_MULTISAMPLE
:
2925 /* These texture types are valid to pass to
2926 * glFramebufferTexture(), but since they aren't layered, it
2927 * is equivalent to calling glFramebufferTexture{1D,2D}().
2929 *layered
= GL_FALSE
;
2933 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2934 "%s(invalid texture target %s)", caller
,
2935 _mesa_enum_to_string(target
));
2941 * Common code called by gl*FramebufferTextureLayer() to verify the texture
2944 * \return true if no errors, false if errors
2947 check_texture_target(struct gl_context
*ctx
, GLenum target
,
2950 /* We're being called by glFramebufferTextureLayer().
2951 * The only legal texture types for that function are 3D,
2952 * cube-map, and 1D/2D/cube-map array textures.
2954 * We don't need to check for GL_ARB_texture_cube_map_array because the
2955 * application wouldn't have been able to create a texture with a
2956 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
2960 case GL_TEXTURE_1D_ARRAY
:
2961 case GL_TEXTURE_2D_ARRAY
:
2962 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2963 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2965 case GL_TEXTURE_CUBE_MAP
:
2966 /* We don't need to check the extension (GL_ARB_direct_state_access) or
2967 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
2968 * enabled in core profile. This can be called from
2969 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
2970 * so we do have to check the profile.
2972 return ctx
->API
== API_OPENGL_CORE
;
2975 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2976 "%s(invalid texture target %s)", caller
,
2977 _mesa_enum_to_string(target
));
2983 * Common code called by glFramebufferTexture*D() to verify the texture
2986 * \return true if no errors, false if errors
2989 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
2990 GLenum textarget
, const char *caller
)
2996 switch (textarget
) {
2999 case GL_TEXTURE_1D_ARRAY
:
3000 err
= !ctx
->Extensions
.EXT_texture_array
;
3007 switch (textarget
) {
3010 case GL_TEXTURE_RECTANGLE
:
3011 err
= _mesa_is_gles(ctx
)
3012 || !ctx
->Extensions
.NV_texture_rectangle
;
3014 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3015 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3016 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3017 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3018 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3019 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3020 err
= !ctx
->Extensions
.ARB_texture_cube_map
;
3022 case GL_TEXTURE_2D_ARRAY
:
3023 err
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
3024 || !ctx
->Extensions
.EXT_texture_array
;
3026 case GL_TEXTURE_2D_MULTISAMPLE
:
3027 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3028 err
= (_mesa_is_gles(ctx
) ||
3029 !ctx
->Extensions
.ARB_texture_multisample
) &&
3030 !_mesa_is_gles31(ctx
);
3037 if (textarget
!= GL_TEXTURE_3D
)
3045 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3046 "%s(invalid textarget %s)",
3047 caller
, _mesa_enum_to_string(textarget
));
3051 /* Make sure textarget is consistent with the texture's type */
3052 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3053 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3056 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3057 "%s(mismatched texture target)", caller
);
3066 * Common code called by gl*FramebufferTextureLayer() and
3067 * glFramebufferTexture3D() to validate the layer.
3069 * \return true if no errors, false if errors
3072 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3075 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3078 * "An INVALID_VALUE error is generated if texture is non-zero
3079 * and layer is negative."
3082 _mesa_error(ctx
, GL_INVALID_VALUE
,
3083 "%s(layer %u < 0)", caller
, layer
);
3087 if (target
== GL_TEXTURE_3D
) {
3088 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3089 if (layer
>= maxSize
) {
3090 _mesa_error(ctx
, GL_INVALID_VALUE
,
3091 "%s(invalid layer %u)", caller
, layer
);
3095 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3096 (target
== GL_TEXTURE_2D_ARRAY
) ||
3097 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3098 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3099 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3100 _mesa_error(ctx
, GL_INVALID_VALUE
,
3101 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3106 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3108 _mesa_error(ctx
, GL_INVALID_VALUE
,
3109 "%s(layer %u >= 6)", caller
, layer
);
3119 * Common code called by all gl*FramebufferTexture*() entry points to verify
3122 * \return true if no errors, false if errors
3125 check_level(struct gl_context
*ctx
, GLenum target
, GLint level
,
3129 (level
>= _mesa_max_texture_levels(ctx
, target
))) {
3130 _mesa_error(ctx
, GL_INVALID_VALUE
,
3131 "%s(invalid level %d)", caller
, level
);
3140 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3142 struct gl_texture_object
*texObj
, GLenum textarget
,
3143 GLint level
, GLuint layer
, GLboolean layered
,
3146 struct gl_renderbuffer_attachment
*att
;
3148 /* The window-system framebuffer object is immutable */
3149 if (_mesa_is_winsys_fbo(fb
)) {
3150 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3155 /* Not a hash lookup, so we can afford to get the attachment here. */
3156 att
= get_attachment(ctx
, fb
, attachment
);
3158 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3159 _mesa_enum_to_string(attachment
));
3163 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3165 mtx_lock(&fb
->Mutex
);
3167 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3168 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3169 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3170 _mesa_tex_target_to_face(textarget
) ==
3171 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3172 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3173 /* The texture object is already attached to the stencil attachment
3174 * point. Don't create a new renderbuffer; just reuse the stencil
3175 * attachment's. This is required to prevent a GL error in
3176 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3178 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3180 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3181 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3182 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3183 _mesa_tex_target_to_face(textarget
) ==
3184 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3185 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3186 /* As above, but with depth and stencil transposed. */
3187 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3190 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3191 level
, layer
, layered
);
3193 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3194 /* Above we created a new renderbuffer and attached it to the
3195 * depth attachment point. Now attach it to the stencil attachment
3198 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3199 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3204 /* Set the render-to-texture flag. We'll check this flag in
3205 * glTexImage() and friends to determine if we need to revalidate
3206 * any FBOs that might be rendering into this texture.
3207 * This flag never gets cleared since it's non-trivial to determine
3208 * when all FBOs might be done rendering to this texture. That's OK
3209 * though since it's uncommon to render to a texture then repeatedly
3210 * call glTexImage() to change images in the texture.
3212 texObj
->_RenderToTexture
= GL_TRUE
;
3215 remove_attachment(ctx
, att
);
3216 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3217 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3218 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3222 invalidate_framebuffer(fb
);
3224 mtx_unlock(&fb
->Mutex
);
3229 framebuffer_texture_with_dims(int dims
, GLenum target
,
3230 GLenum attachment
, GLenum textarget
,
3231 GLuint texture
, GLint level
, GLint layer
,
3234 GET_CURRENT_CONTEXT(ctx
);
3235 struct gl_framebuffer
*fb
;
3236 struct gl_texture_object
*texObj
;
3238 /* Get the framebuffer object */
3239 fb
= get_framebuffer_target(ctx
, target
);
3241 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3242 _mesa_enum_to_string(target
));
3246 /* Get the texture object */
3247 if (!get_texture_for_framebuffer(ctx
, texture
, false, caller
, &texObj
))
3251 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3254 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3257 if (!check_level(ctx
, textarget
, level
, caller
))
3261 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3262 layer
, GL_FALSE
, caller
);
3267 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3268 GLenum textarget
, GLuint texture
, GLint level
)
3270 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3271 level
, 0, "glFramebufferTexture1D");
3276 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3277 GLenum textarget
, GLuint texture
, GLint level
)
3279 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3280 level
, 0, "glFramebufferTexture2D");
3285 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3286 GLenum textarget
, GLuint texture
,
3287 GLint level
, GLint layer
)
3289 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3290 level
, layer
, "glFramebufferTexture3D");
3295 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3296 GLuint texture
, GLint level
, GLint layer
)
3298 GET_CURRENT_CONTEXT(ctx
);
3299 struct gl_framebuffer
*fb
;
3300 struct gl_texture_object
*texObj
;
3301 GLenum textarget
= 0;
3303 const char *func
= "glFramebufferTextureLayer";
3305 /* Get the framebuffer object */
3306 fb
= get_framebuffer_target(ctx
, target
);
3308 _mesa_error(ctx
, GL_INVALID_ENUM
,
3309 "glFramebufferTextureLayer(invalid target %s)",
3310 _mesa_enum_to_string(target
));
3314 /* Get the texture object */
3315 if (!get_texture_for_framebuffer(ctx
, texture
, false, func
, &texObj
))
3319 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3322 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3325 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3328 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3329 assert(layer
>= 0 && layer
< 6);
3330 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3335 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3336 layer
, GL_FALSE
, func
);
3341 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3342 GLuint texture
, GLint level
, GLint layer
)
3344 GET_CURRENT_CONTEXT(ctx
);
3345 struct gl_framebuffer
*fb
;
3346 struct gl_texture_object
*texObj
;
3347 GLenum textarget
= 0;
3349 const char *func
= "glNamedFramebufferTextureLayer";
3351 /* Get the framebuffer object */
3352 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3356 /* Get the texture object */
3357 if (!get_texture_for_framebuffer(ctx
, texture
, false, func
, &texObj
))
3361 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3364 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3367 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3370 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3371 assert(layer
>= 0 && layer
< 6);
3372 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3377 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3378 layer
, GL_FALSE
, func
);
3383 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3384 GLuint texture
, GLint level
)
3386 GET_CURRENT_CONTEXT(ctx
);
3387 struct gl_framebuffer
*fb
;
3388 struct gl_texture_object
*texObj
;
3389 GLboolean layered
= GL_FALSE
;
3391 const char *func
= "FramebufferTexture";
3393 if (!_mesa_has_geometry_shaders(ctx
)) {
3394 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3395 "unsupported function (glFramebufferTexture) called");
3399 /* Get the framebuffer object */
3400 fb
= get_framebuffer_target(ctx
, target
);
3402 _mesa_error(ctx
, GL_INVALID_ENUM
,
3403 "glFramebufferTexture(invalid target %s)",
3404 _mesa_enum_to_string(target
));
3408 /* Get the texture object */
3409 if (!get_texture_for_framebuffer(ctx
, texture
, true, func
, &texObj
))
3413 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
, &layered
))
3416 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3420 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, 0, level
,
3426 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3427 GLuint texture
, GLint level
)
3429 GET_CURRENT_CONTEXT(ctx
);
3430 struct gl_framebuffer
*fb
;
3431 struct gl_texture_object
*texObj
;
3432 GLboolean layered
= GL_FALSE
;
3434 const char *func
= "glNamedFramebufferTexture";
3436 if (!_mesa_has_geometry_shaders(ctx
)) {
3437 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3438 "unsupported function (glNamedFramebufferTexture) called");
3442 /* Get the framebuffer object */
3443 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3447 /* Get the texture object */
3448 if (!get_texture_for_framebuffer(ctx
, texture
, true, func
, &texObj
))
3452 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3456 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3460 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, 0, level
,
3466 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3467 struct gl_framebuffer
*fb
,
3469 struct gl_renderbuffer
*rb
)
3471 assert(!_mesa_is_winsys_fbo(fb
));
3473 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3475 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3476 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3478 /* Some subsequent GL commands may depend on the framebuffer's visual
3479 * after the binding is updated. Update visual info now.
3481 _mesa_update_framebuffer_visual(ctx
, fb
);
3485 framebuffer_renderbuffer(struct gl_context
*ctx
,
3486 struct gl_framebuffer
*fb
,
3488 struct gl_renderbuffer
*rb
,
3491 struct gl_renderbuffer_attachment
*att
;
3493 if (_mesa_is_winsys_fbo(fb
)) {
3494 /* Can't attach new renderbuffers to a window system framebuffer */
3495 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3496 "%s(window-system framebuffer)", func
);
3500 att
= get_attachment(ctx
, fb
, attachment
);
3502 _mesa_error(ctx
, GL_INVALID_ENUM
,
3503 "%s(invalid attachment %s)", func
,
3504 _mesa_enum_to_string(attachment
));
3508 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3509 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3510 /* make sure the renderbuffer is a depth/stencil format */
3511 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3512 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3513 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3514 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3519 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3523 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3524 GLenum renderbuffertarget
,
3525 GLuint renderbuffer
)
3527 struct gl_framebuffer
*fb
;
3528 struct gl_renderbuffer
*rb
;
3529 GET_CURRENT_CONTEXT(ctx
);
3531 fb
= get_framebuffer_target(ctx
, target
);
3533 _mesa_error(ctx
, GL_INVALID_ENUM
,
3534 "glFramebufferRenderbuffer(invalid target %s)",
3535 _mesa_enum_to_string(target
));
3539 if (renderbuffertarget
!= GL_RENDERBUFFER
) {
3540 _mesa_error(ctx
, GL_INVALID_ENUM
,
3541 "glFramebufferRenderbuffer(renderbuffertarget is not "
3542 "GL_RENDERBUFFER)");
3547 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
,
3548 "glFramebufferRenderbuffer");
3553 /* remove renderbuffer attachment */
3557 framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
,
3558 "glFramebufferRenderbuffer");
3563 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
3564 GLenum renderbuffertarget
,
3565 GLuint renderbuffer
)
3567 struct gl_framebuffer
*fb
;
3568 struct gl_renderbuffer
*rb
;
3569 GET_CURRENT_CONTEXT(ctx
);
3571 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3572 "glNamedFramebufferRenderbuffer");
3576 if (renderbuffertarget
!= GL_RENDERBUFFER
) {
3577 _mesa_error(ctx
, GL_INVALID_ENUM
,
3578 "glNamedFramebufferRenderbuffer(renderbuffertarget is not "
3579 "GL_RENDERBUFFER)");
3584 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
,
3585 "glNamedFramebufferRenderbuffer");
3590 /* remove renderbuffer attachment */
3594 framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
,
3595 "glNamedFramebufferRenderbuffer");
3600 _mesa_get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
3601 struct gl_framebuffer
*buffer
,
3602 GLenum attachment
, GLenum pname
,
3603 GLint
*params
, const char *caller
)
3605 const struct gl_renderbuffer_attachment
*att
;
3608 /* The error code for an attachment type of GL_NONE differs between APIs.
3610 * From the ES 2.0.25 specification, page 127:
3611 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3612 * querying any other pname will generate INVALID_ENUM."
3614 * From the OpenGL 3.0 specification, page 337, or identically,
3615 * the OpenGL ES 3.0.4 specification, page 240:
3617 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
3618 * framebuffer is bound to target. In this case querying pname
3619 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
3620 * queries will generate an INVALID_OPERATION error."
3622 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
3623 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
3625 if (_mesa_is_winsys_fbo(buffer
)) {
3626 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
3629 * "If the framebuffer currently bound to target is zero, then
3630 * INVALID_OPERATION is generated."
3632 * The EXT_framebuffer_object spec has the same wording, and the
3633 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
3636 if ((!_mesa_is_desktop_gl(ctx
) ||
3637 !ctx
->Extensions
.ARB_framebuffer_object
)
3638 && !_mesa_is_gles3(ctx
)) {
3639 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3640 "%s(window-system framebuffer)", caller
);
3644 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
3645 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
3646 _mesa_error(ctx
, GL_INVALID_ENUM
,
3647 "%s(invalid attachment %s)", caller
,
3648 _mesa_enum_to_string(attachment
));
3652 /* The specs are not clear about how to handle
3653 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
3654 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
3657 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
3658 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
3660 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
3661 _mesa_error(ctx
, GL_INVALID_ENUM
,
3662 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
3663 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
3664 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
3668 /* the default / window-system FBO */
3669 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
3672 /* user-created framebuffer FBO */
3673 att
= get_attachment(ctx
, buffer
, attachment
);
3677 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3678 _mesa_enum_to_string(attachment
));
3682 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3683 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
3684 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
3685 /* This behavior is first specified in OpenGL 4.4 specification.
3687 * From the OpenGL 4.4 spec page 275:
3688 * "This query cannot be performed for a combined depth+stencil
3689 * attachment, since it does not have a single format."
3691 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3692 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
3693 " is invalid for depth+stencil attachment)", caller
);
3696 /* the depth and stencil attachments must point to the same buffer */
3697 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
3698 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
3699 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
3700 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3701 "%s(DEPTH/STENCIL attachments differ)", caller
);
3706 /* No need to flush here */
3709 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
3710 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
3712 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3713 * either no framebuffer is bound to target; or the default framebuffer
3714 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
3715 * stencil bits, respectively, is zero."
3717 *params
= (_mesa_is_winsys_fbo(buffer
) &&
3718 ((attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) ||
3719 (att
->Type
!= GL_NONE
)))
3720 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
3722 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
3723 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
3724 *params
= att
->Renderbuffer
->Name
;
3726 else if (att
->Type
== GL_TEXTURE
) {
3727 *params
= att
->Texture
->Name
;
3730 assert(att
->Type
== GL_NONE
);
3731 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
3734 goto invalid_pname_enum
;
3738 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
3739 if (att
->Type
== GL_TEXTURE
) {
3740 *params
= att
->TextureLevel
;
3742 else if (att
->Type
== GL_NONE
) {
3743 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3744 _mesa_enum_to_string(pname
));
3747 goto invalid_pname_enum
;
3750 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
3751 if (att
->Type
== GL_TEXTURE
) {
3752 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
3753 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
3759 else if (att
->Type
== GL_NONE
) {
3760 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3761 _mesa_enum_to_string(pname
));
3764 goto invalid_pname_enum
;
3767 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
3768 if (ctx
->API
== API_OPENGLES
) {
3769 goto invalid_pname_enum
;
3770 } else if (att
->Type
== GL_NONE
) {
3771 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3772 _mesa_enum_to_string(pname
));
3773 } else if (att
->Type
== GL_TEXTURE
) {
3774 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
3775 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
3776 *params
= att
->Zoffset
;
3783 goto invalid_pname_enum
;
3786 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
3787 if ((!_mesa_is_desktop_gl(ctx
) ||
3788 !ctx
->Extensions
.ARB_framebuffer_object
)
3789 && !_mesa_is_gles3(ctx
)) {
3790 goto invalid_pname_enum
;
3792 else if (att
->Type
== GL_NONE
) {
3793 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3794 _mesa_enum_to_string(pname
));
3797 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
3799 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
3802 /* According to ARB_framebuffer_sRGB, we should return LINEAR
3803 * if the sRGB conversion is unsupported. */
3804 *params
= GL_LINEAR
;
3808 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
3809 if ((ctx
->API
!= API_OPENGL_COMPAT
||
3810 !ctx
->Extensions
.ARB_framebuffer_object
)
3811 && ctx
->API
!= API_OPENGL_CORE
3812 && !_mesa_is_gles3(ctx
)) {
3813 goto invalid_pname_enum
;
3815 else if (att
->Type
== GL_NONE
) {
3816 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3817 _mesa_enum_to_string(pname
));
3820 mesa_format format
= att
->Renderbuffer
->Format
;
3822 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
3825 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
3826 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
3827 * generate an INVALID_OPERATION error.
3829 if (_mesa_is_gles3(ctx
) &&
3830 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3831 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3833 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
3834 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
3838 if (format
== MESA_FORMAT_S_UINT8
) {
3842 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
3843 /* depends on the attachment parameter */
3844 if (attachment
== GL_STENCIL_ATTACHMENT
) {
3852 *params
= _mesa_get_format_datatype(format
);
3856 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
3857 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
3858 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
3859 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
3860 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
3861 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
3862 if ((!_mesa_is_desktop_gl(ctx
) ||
3863 !ctx
->Extensions
.ARB_framebuffer_object
)
3864 && !_mesa_is_gles3(ctx
)) {
3865 goto invalid_pname_enum
;
3867 else if (att
->Type
== GL_NONE
) {
3868 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3869 _mesa_enum_to_string(pname
));
3871 else if (att
->Texture
) {
3872 const struct gl_texture_image
*texImage
=
3873 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
3876 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
3877 texImage
->TexFormat
);
3883 else if (att
->Renderbuffer
) {
3884 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
3885 att
->Renderbuffer
->Format
);
3888 _mesa_problem(ctx
, "%s: invalid FBO attachment structure", caller
);
3891 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
3892 if (!_mesa_has_geometry_shaders(ctx
)) {
3893 goto invalid_pname_enum
;
3894 } else if (att
->Type
== GL_TEXTURE
) {
3895 *params
= att
->Layered
;
3896 } else if (att
->Type
== GL_NONE
) {
3897 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3898 _mesa_enum_to_string(pname
));
3900 goto invalid_pname_enum
;
3904 goto invalid_pname_enum
;
3910 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
3911 _mesa_enum_to_string(pname
));
3917 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
3918 GLenum pname
, GLint
*params
)
3920 GET_CURRENT_CONTEXT(ctx
);
3921 struct gl_framebuffer
*buffer
;
3923 buffer
= get_framebuffer_target(ctx
, target
);
3925 _mesa_error(ctx
, GL_INVALID_ENUM
,
3926 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
3927 _mesa_enum_to_string(target
));
3931 _mesa_get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
3933 "glGetFramebufferAttachmentParameteriv");
3938 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
3940 GLenum pname
, GLint
*params
)
3942 GET_CURRENT_CONTEXT(ctx
);
3943 struct gl_framebuffer
*buffer
;
3946 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3947 "glGetNamedFramebufferAttachmentParameteriv");
3953 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
3954 * 4.5 core spec (30.10.2014, PDF page 314):
3955 * "If framebuffer is zero, then the default draw framebuffer is
3958 buffer
= ctx
->WinSysDrawBuffer
;
3961 _mesa_get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
3963 "glGetNamedFramebufferAttachmentParameteriv");
3968 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
3971 GET_CURRENT_CONTEXT(ctx
);
3972 struct gl_framebuffer
*fb
= NULL
;
3974 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
3975 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3976 "glNamedFramebufferParameteri("
3977 "ARB_framebuffer_no_attachments not implemented)");
3981 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3982 "glNamedFramebufferParameteri");
3985 framebuffer_parameteri(ctx
, fb
, pname
, param
,
3986 "glNamedFramebufferParameteriv");
3992 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
3995 GET_CURRENT_CONTEXT(ctx
);
3996 struct gl_framebuffer
*fb
;
3998 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
3999 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4000 "glNamedFramebufferParameteriv("
4001 "ARB_framebuffer_no_attachments not implemented)");
4006 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4007 "glGetNamedFramebufferParameteriv");
4009 fb
= ctx
->WinSysDrawBuffer
;
4013 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4014 "glGetNamedFramebufferParameteriv");
4020 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4021 struct gl_framebuffer
*fb
,
4022 GLsizei numAttachments
,
4023 const GLenum
*attachments
, GLint x
, GLint y
,
4024 GLsizei width
, GLsizei height
, const char *name
)
4028 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4029 * Spec (2.2.2015, PDF page 522) says:
4030 * "An INVALID_VALUE error is generated if numAttachments, width, or
4031 * height is negative."
4033 if (numAttachments
< 0) {
4034 _mesa_error(ctx
, GL_INVALID_VALUE
,
4035 "%s(numAttachments < 0)", name
);
4040 _mesa_error(ctx
, GL_INVALID_VALUE
,
4041 "%s(width < 0)", name
);
4046 _mesa_error(ctx
, GL_INVALID_VALUE
,
4047 "%s(height < 0)", name
);
4051 /* The GL_ARB_invalidate_subdata spec says:
4053 * "If an attachment is specified that does not exist in the
4054 * framebuffer bound to <target>, it is ignored."
4058 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4059 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4060 * INVALID_OPERATION is generated."
4062 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4063 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4064 * set of retrictions).
4066 for (i
= 0; i
< numAttachments
; i
++) {
4067 if (_mesa_is_winsys_fbo(fb
)) {
4068 switch (attachments
[i
]) {
4074 /* Accumulation buffers and auxilary buffers were removed in
4075 * OpenGL 3.1, and they never existed in OpenGL ES.
4077 if (ctx
->API
!= API_OPENGL_COMPAT
)
4087 case GL_FRONT_RIGHT
:
4088 if (!_mesa_is_desktop_gl(ctx
))
4095 switch (attachments
[i
]) {
4096 case GL_DEPTH_ATTACHMENT
:
4097 case GL_STENCIL_ATTACHMENT
:
4099 case GL_DEPTH_STENCIL_ATTACHMENT
:
4100 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4101 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4102 * extension does not make this attachment point valid on ES 2.0.
4104 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4107 case GL_COLOR_ATTACHMENT0
:
4108 case GL_COLOR_ATTACHMENT1
:
4109 case GL_COLOR_ATTACHMENT2
:
4110 case GL_COLOR_ATTACHMENT3
:
4111 case GL_COLOR_ATTACHMENT4
:
4112 case GL_COLOR_ATTACHMENT5
:
4113 case GL_COLOR_ATTACHMENT6
:
4114 case GL_COLOR_ATTACHMENT7
:
4115 case GL_COLOR_ATTACHMENT8
:
4116 case GL_COLOR_ATTACHMENT9
:
4117 case GL_COLOR_ATTACHMENT10
:
4118 case GL_COLOR_ATTACHMENT11
:
4119 case GL_COLOR_ATTACHMENT12
:
4120 case GL_COLOR_ATTACHMENT13
:
4121 case GL_COLOR_ATTACHMENT14
:
4122 case GL_COLOR_ATTACHMENT15
: {
4123 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4124 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4125 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4126 "%s(attachment >= max. color attachments)", name
);
4137 /* We don't actually do anything for this yet. Just return after
4138 * validating the parameters and generating the required errors.
4143 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4144 _mesa_enum_to_string(attachments
[i
]));
4150 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4151 const GLenum
*attachments
, GLint x
, GLint y
,
4152 GLsizei width
, GLsizei height
)
4154 struct gl_framebuffer
*fb
;
4155 GET_CURRENT_CONTEXT(ctx
);
4157 fb
= get_framebuffer_target(ctx
, target
);
4159 _mesa_error(ctx
, GL_INVALID_ENUM
,
4160 "glInvalidateSubFramebuffer(invalid target %s)",
4161 _mesa_enum_to_string(target
));
4165 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4166 x
, y
, width
, height
,
4167 "glInvalidateSubFramebuffer");
4172 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4173 GLsizei numAttachments
,
4174 const GLenum
*attachments
,
4176 GLsizei width
, GLsizei height
)
4178 struct gl_framebuffer
*fb
;
4179 GET_CURRENT_CONTEXT(ctx
);
4181 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4182 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4183 * default draw framebuffer is affected."
4186 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4187 "glInvalidateNamedFramebufferSubData");
4192 fb
= ctx
->WinSysDrawBuffer
;
4194 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4195 x
, y
, width
, height
,
4196 "glInvalidateNamedFramebufferSubData");
4201 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4202 const GLenum
*attachments
)
4204 struct gl_framebuffer
*fb
;
4205 GET_CURRENT_CONTEXT(ctx
);
4207 fb
= get_framebuffer_target(ctx
, target
);
4209 _mesa_error(ctx
, GL_INVALID_ENUM
,
4210 "glInvalidateFramebuffer(invalid target %s)",
4211 _mesa_enum_to_string(target
));
4215 /* The GL_ARB_invalidate_subdata spec says:
4219 * void InvalidateFramebuffer(enum target,
4220 * sizei numAttachments,
4221 * const enum *attachments);
4223 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4224 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4225 * <MAX_VIEWPORT_DIMS[1]> respectively."
4227 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4229 ctx
->Const
.MaxViewportWidth
,
4230 ctx
->Const
.MaxViewportHeight
,
4231 "glInvalidateFramebuffer");
4236 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4237 GLsizei numAttachments
,
4238 const GLenum
*attachments
)
4240 struct gl_framebuffer
*fb
;
4241 GET_CURRENT_CONTEXT(ctx
);
4243 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4244 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4245 * default draw framebuffer is affected."
4248 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4249 "glInvalidateNamedFramebufferData");
4254 fb
= ctx
->WinSysDrawBuffer
;
4256 /* The GL_ARB_invalidate_subdata spec says:
4260 * void InvalidateFramebuffer(enum target,
4261 * sizei numAttachments,
4262 * const enum *attachments);
4264 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4265 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4266 * <MAX_VIEWPORT_DIMS[1]> respectively."
4268 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4270 ctx
->Const
.MaxViewportWidth
,
4271 ctx
->Const
.MaxViewportHeight
,
4272 "glInvalidateNamedFramebufferData");
4277 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4278 const GLenum
*attachments
)
4280 struct gl_framebuffer
*fb
;
4283 GET_CURRENT_CONTEXT(ctx
);
4285 fb
= get_framebuffer_target(ctx
, target
);
4287 _mesa_error(ctx
, GL_INVALID_ENUM
,
4288 "glDiscardFramebufferEXT(target %s)",
4289 _mesa_enum_to_string(target
));
4293 if (numAttachments
< 0) {
4294 _mesa_error(ctx
, GL_INVALID_VALUE
,
4295 "glDiscardFramebufferEXT(numAttachments < 0)");
4299 for (i
= 0; i
< numAttachments
; i
++) {
4300 switch (attachments
[i
]) {
4304 if (_mesa_is_user_fbo(fb
))
4307 case GL_COLOR_ATTACHMENT0
:
4308 case GL_DEPTH_ATTACHMENT
:
4309 case GL_STENCIL_ATTACHMENT
:
4310 if (_mesa_is_winsys_fbo(fb
))
4318 if (ctx
->Driver
.DiscardFramebuffer
)
4319 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4324 _mesa_error(ctx
, GL_INVALID_ENUM
,
4325 "glDiscardFramebufferEXT(attachment %s)",
4326 _mesa_enum_to_string(attachments
[i
]));