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;
973 fb
->_IntegerBuffers
= 0;
975 /* Start at -2 to more easily loop over all attachment points.
980 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
981 struct gl_renderbuffer_attachment
*att
;
983 mesa_format attFormat
;
984 GLenum att_tex_target
= GL_NONE
;
987 * XXX for ARB_fbo, only check color buffers that are named by
988 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
991 /* check for attachment completeness
994 att
= &fb
->Attachment
[BUFFER_DEPTH
];
995 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
996 if (!att
->Complete
) {
997 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
998 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
1000 } else if (att
->Type
!= GL_NONE
) {
1001 has_depth_attachment
= true;
1005 att
= &fb
->Attachment
[BUFFER_STENCIL
];
1006 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
1007 if (!att
->Complete
) {
1008 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1009 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
1011 } else if (att
->Type
!= GL_NONE
) {
1012 has_stencil_attachment
= true;
1016 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
1017 test_attachment_completeness(ctx
, GL_COLOR
, att
);
1018 if (!att
->Complete
) {
1019 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1020 fbo_incomplete(ctx
, "color attachment incomplete", i
);
1025 /* get width, height, format of the renderbuffer/texture
1027 if (att
->Type
== GL_TEXTURE
) {
1028 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
1029 att_tex_target
= att
->Texture
->Target
;
1030 minWidth
= MIN2(minWidth
, texImg
->Width
);
1031 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
1032 minHeight
= MIN2(minHeight
, texImg
->Height
);
1033 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
1034 f
= texImg
->_BaseFormat
;
1035 attFormat
= texImg
->TexFormat
;
1038 if (!is_format_color_renderable(ctx
, attFormat
,
1039 texImg
->InternalFormat
) &&
1040 !is_legal_depth_format(ctx
, f
) &&
1041 f
!= GL_STENCIL_INDEX
) {
1042 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
;
1043 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
1048 numSamples
= texImg
->NumSamples
;
1049 else if (numSamples
!= texImg
->NumSamples
) {
1050 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1051 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1055 if (fixedSampleLocations
< 0)
1056 fixedSampleLocations
= texImg
->FixedSampleLocations
;
1057 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
1058 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1059 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1063 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1064 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
1065 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
1066 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
1067 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
1068 f
= att
->Renderbuffer
->InternalFormat
;
1069 attFormat
= att
->Renderbuffer
->Format
;
1073 numSamples
= att
->Renderbuffer
->NumSamples
;
1074 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
1075 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1076 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1080 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1081 if (fixedSampleLocations
< 0)
1082 fixedSampleLocations
= GL_TRUE
;
1083 else if (fixedSampleLocations
!= GL_TRUE
) {
1084 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1085 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1090 assert(att
->Type
== GL_NONE
);
1094 /* Update flags describing color buffer datatypes */
1096 GLenum type
= _mesa_get_format_datatype(attFormat
);
1098 /* check if integer color */
1099 if (_mesa_is_format_integer_color(attFormat
))
1100 fb
->_IntegerBuffers
|= (1 << i
);
1102 fb
->_AllColorBuffersFixedPoint
=
1103 fb
->_AllColorBuffersFixedPoint
&&
1104 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1106 fb
->_HasSNormOrFloatColorBuffer
=
1107 fb
->_HasSNormOrFloatColorBuffer
||
1108 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1111 /* Error-check width, height, format */
1112 if (numImages
== 1) {
1119 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1120 /* check that width, height, format are same */
1121 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1122 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1123 fbo_incomplete(ctx
, "width or height mismatch", -1);
1126 /* check that all color buffers are the same format */
1127 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1128 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1129 fbo_incomplete(ctx
, "format mismatch", -1);
1135 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1137 if (att
->Type
== GL_RENDERBUFFER
&&
1138 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1139 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1140 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1144 /* Check that layered rendering is consistent. */
1146 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1147 att_layer_count
= 6;
1148 else if (att_tex_target
== GL_TEXTURE_1D_ARRAY
)
1149 att_layer_count
= att
->Renderbuffer
->Height
;
1151 att_layer_count
= att
->Renderbuffer
->Depth
;
1153 att_layer_count
= 0;
1155 if (!layer_info_valid
) {
1156 is_layered
= att
->Layered
;
1157 max_layer_count
= att_layer_count
;
1158 layer_tex_target
= att_tex_target
;
1159 layer_info_valid
= true;
1160 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1161 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1162 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1164 } else if (is_layered
!= att
->Layered
) {
1165 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1167 "framebuffer attachment layer mode is inconsistent",
1170 } else if (att_layer_count
> max_layer_count
) {
1171 max_layer_count
= att_layer_count
;
1175 * The extension GL_ARB_framebuffer_no_attachments places additional
1176 * requirement on each attachment. Those additional requirements are
1177 * tighter that those of previous versions of GL. In interest of better
1178 * compatibility, we will not enforce these restrictions. For the record
1179 * those additional restrictions are quoted below:
1181 * "The width and height of image are greater than zero and less than or
1182 * equal to the values of the implementation-dependent limits
1183 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1185 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1186 * array texture and the attachment is layered, the depth or layer count
1187 * of the texture is less than or equal to the implementation-dependent
1188 * limit MAX_FRAMEBUFFER_LAYERS."
1190 * "If image has multiple samples, its sample count is less than or equal
1191 * to the value of the implementation-dependent limit
1192 * MAX_FRAMEBUFFER_SAMPLES."
1194 * The same requirements are also in place for GL 4.5,
1195 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1199 fb
->MaxNumLayers
= max_layer_count
;
1201 if (numImages
== 0) {
1202 fb
->_HasAttachments
= false;
1204 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1205 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1206 fbo_incomplete(ctx
, "no attachments", -1);
1210 if (fb
->DefaultGeometry
.Width
== 0 || fb
->DefaultGeometry
.Height
== 0) {
1211 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1212 fbo_incomplete(ctx
, "no attachments and default width or height is 0", -1);
1217 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1218 /* Check that all DrawBuffers are present */
1219 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1220 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1221 const struct gl_renderbuffer_attachment
*att
1222 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
1224 if (att
->Type
== GL_NONE
) {
1225 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1226 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1232 /* Check that the ReadBuffer is present */
1233 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1234 const struct gl_renderbuffer_attachment
*att
1235 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
1237 if (att
->Type
== GL_NONE
) {
1238 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1239 fbo_incomplete(ctx
, "missing readbuffer", -1);
1245 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1247 * "Depth and stencil attachments, if present, are the same image."
1249 * This restriction is not present in the OpenGL ES2 spec.
1251 if (_mesa_is_gles3(ctx
) &&
1252 has_stencil_attachment
&& has_depth_attachment
&&
1253 !_mesa_has_depthstencil_combined(fb
)) {
1254 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1255 fbo_incomplete(ctx
, "Depth and stencil attachments must be the same image", -1);
1259 /* Provisionally set status = COMPLETE ... */
1260 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1262 /* ... but the driver may say the FB is incomplete.
1263 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1266 if (ctx
->Driver
.ValidateFramebuffer
) {
1267 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1268 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1269 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1275 * Note that if ARB_framebuffer_object is supported and the attached
1276 * renderbuffers/textures are different sizes, the framebuffer
1277 * width/height will be set to the smallest width/height.
1279 if (numImages
!= 0) {
1280 fb
->Width
= minWidth
;
1281 fb
->Height
= minHeight
;
1284 /* finally, update the visual info for the framebuffer */
1285 _mesa_update_framebuffer_visual(ctx
, fb
);
1289 GLboolean GLAPIENTRY
1290 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1292 GET_CURRENT_CONTEXT(ctx
);
1293 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1295 struct gl_renderbuffer
*rb
=
1296 _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1297 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
1304 static struct gl_renderbuffer
*
1305 allocate_renderbuffer_locked(struct gl_context
*ctx
, GLuint renderbuffer
,
1308 struct gl_renderbuffer
*newRb
;
1310 /* create new renderbuffer object */
1311 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1313 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1316 assert(newRb
->AllocStorage
);
1317 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1318 newRb
->RefCount
= 1; /* referenced by hash table */
1325 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1327 struct gl_renderbuffer
*newRb
;
1328 GET_CURRENT_CONTEXT(ctx
);
1330 if (target
!= GL_RENDERBUFFER_EXT
) {
1331 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1335 /* No need to flush here since the render buffer binding has no
1336 * effect on rendering state.
1340 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1341 if (newRb
== &DummyRenderbuffer
) {
1342 /* ID was reserved, but no real renderbuffer object made yet */
1345 else if (!newRb
&& !allow_user_names
) {
1346 /* All RB IDs must be Gen'd */
1347 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1352 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1353 newRb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
1354 "glBindRenderbufferEXT");
1355 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1362 assert(newRb
!= &DummyRenderbuffer
);
1364 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1368 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1370 GET_CURRENT_CONTEXT(ctx
);
1372 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1373 * entry point, but they allow the use of user-generated names.
1375 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1379 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1381 /* This function should not be in the dispatch table for core profile /
1382 * OpenGL 3.1, so execution should never get here in those cases -- no
1383 * need for an explicit test.
1385 bind_renderbuffer(target
, renderbuffer
, true);
1389 * ARB_framebuffer_no_attachment - Application passes requested param's
1390 * here. NOTE: NumSamples requested need not be _NumSamples which is
1391 * what the hw supports.
1394 framebuffer_parameteri(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1395 GLenum pname
, GLint param
, const char *func
)
1398 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1399 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferWidth
)
1400 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1402 fb
->DefaultGeometry
.Width
= param
;
1404 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1405 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferHeight
)
1406 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1408 fb
->DefaultGeometry
.Height
= param
;
1410 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1412 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1413 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1415 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1416 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1419 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferLayers
)
1420 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1422 fb
->DefaultGeometry
.Layers
= param
;
1424 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1425 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferSamples
)
1426 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1428 fb
->DefaultGeometry
.NumSamples
= param
;
1430 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1431 fb
->DefaultGeometry
.FixedSampleLocations
= param
;
1434 _mesa_error(ctx
, GL_INVALID_ENUM
,
1435 "%s(pname=0x%x)", func
, pname
);
1438 invalidate_framebuffer(fb
);
1439 ctx
->NewState
|= _NEW_BUFFERS
;
1443 _mesa_FramebufferParameteri(GLenum target
, GLenum pname
, GLint param
)
1445 GET_CURRENT_CONTEXT(ctx
);
1446 struct gl_framebuffer
*fb
;
1448 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1449 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1450 "glFramebufferParameteriv not supported "
1451 "(ARB_framebuffer_no_attachments not implemented)");
1455 fb
= get_framebuffer_target(ctx
, target
);
1457 _mesa_error(ctx
, GL_INVALID_ENUM
,
1458 "glFramebufferParameteri(target=0x%x)", target
);
1462 /* check framebuffer binding */
1463 if (_mesa_is_winsys_fbo(fb
)) {
1464 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1465 "glFramebufferParameteri");
1469 framebuffer_parameteri(ctx
, fb
, pname
, param
, "glFramebufferParameteri");
1473 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1474 GLenum pname
, GLint
*params
, const char *func
)
1477 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1478 *params
= fb
->DefaultGeometry
.Width
;
1480 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1481 *params
= fb
->DefaultGeometry
.Height
;
1483 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1485 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1486 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1488 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1489 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1492 *params
= fb
->DefaultGeometry
.Layers
;
1494 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1495 *params
= fb
->DefaultGeometry
.NumSamples
;
1497 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1498 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1501 _mesa_error(ctx
, GL_INVALID_ENUM
,
1502 "%s(pname=0x%x)", func
, pname
);
1507 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1509 GET_CURRENT_CONTEXT(ctx
);
1510 struct gl_framebuffer
*fb
;
1512 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1513 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1514 "glGetFramebufferParameteriv not supported "
1515 "(ARB_framebuffer_no_attachments not implemented)");
1519 fb
= get_framebuffer_target(ctx
, target
);
1521 _mesa_error(ctx
, GL_INVALID_ENUM
,
1522 "glGetFramebufferParameteriv(target=0x%x)", target
);
1526 /* check framebuffer binding */
1527 if (_mesa_is_winsys_fbo(fb
)) {
1528 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1529 "glGetFramebufferParameteriv");
1533 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1534 "glGetFramebufferParameteriv");
1539 * Remove the specified renderbuffer or texture from any attachment point in
1543 * \c true if the renderbuffer was detached from an attachment point. \c
1547 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1548 struct gl_framebuffer
*fb
,
1552 bool progress
= false;
1554 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1555 if (fb
->Attachment
[i
].Texture
== att
1556 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1557 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1562 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1563 * Completeness," of the OpenGL 3.1 spec says:
1565 * "Performing any of the following actions may change whether the
1566 * framebuffer is considered complete or incomplete:
1570 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1571 * containing an image that is attached to a framebuffer object
1572 * that is bound to the framebuffer."
1575 invalidate_framebuffer(fb
);
1582 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1585 GET_CURRENT_CONTEXT(ctx
);
1588 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1592 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1594 for (i
= 0; i
< n
; i
++) {
1595 if (renderbuffers
[i
] > 0) {
1596 struct gl_renderbuffer
*rb
;
1597 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1599 /* check if deleting currently bound renderbuffer object */
1600 if (rb
== ctx
->CurrentRenderbuffer
) {
1602 assert(rb
->RefCount
>= 2);
1603 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1606 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1607 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1608 * of the OpenGL 3.1 spec says:
1610 * "If a renderbuffer object is deleted while its image is
1611 * attached to one or more attachment points in the currently
1612 * bound framebuffer, then it is as if FramebufferRenderbuffer
1613 * had been called, with a renderbuffer of 0, for each
1614 * attachment point to which this image was attached in the
1615 * currently bound framebuffer. In other words, this
1616 * renderbuffer image is first detached from all attachment
1617 * points in the currently bound framebuffer. Note that the
1618 * renderbuffer image is specifically not detached from any
1619 * non-bound framebuffers. Detaching the image from any
1620 * non-bound framebuffers is the responsibility of the
1623 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1624 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1626 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1627 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1628 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1631 /* Remove from hash table immediately, to free the ID.
1632 * But the object will not be freed until it's no longer
1633 * referenced anywhere else.
1635 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1637 if (rb
!= &DummyRenderbuffer
) {
1638 /* no longer referenced by hash table */
1639 _mesa_reference_renderbuffer(&rb
, NULL
);
1647 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1650 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1655 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1662 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1664 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1666 for (i
= 0; i
< n
; i
++) {
1667 GLuint name
= first
+ i
;
1668 renderbuffers
[i
] = name
;
1671 allocate_renderbuffer_locked(ctx
, name
, func
);
1673 /* insert a dummy renderbuffer into the hash table */
1674 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1675 &DummyRenderbuffer
);
1679 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1684 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1686 GET_CURRENT_CONTEXT(ctx
);
1687 create_render_buffers(ctx
, n
, renderbuffers
, false);
1692 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1694 GET_CURRENT_CONTEXT(ctx
);
1695 create_render_buffers(ctx
, n
, renderbuffers
, true);
1700 * Given an internal format token for a render buffer, return the
1701 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1702 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1703 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1705 * This is similar to _mesa_base_tex_format() but the set of valid
1706 * internal formats is different.
1708 * Note that even if a format is determined to be legal here, validation
1709 * of the FBO may fail if the format is not supported by the driver/GPU.
1711 * \param internalFormat as passed to glRenderbufferStorage()
1712 * \return the base internal format, or 0 if internalFormat is illegal
1715 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1718 * Notes: some formats such as alpha, luminance, etc. were added
1719 * with GL_ARB_framebuffer_object.
1721 switch (internalFormat
) {
1727 return (ctx
->API
== API_OPENGL_COMPAT
&&
1728 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
1732 case GL_LUMINANCE12
:
1733 case GL_LUMINANCE16
:
1734 return (ctx
->API
== API_OPENGL_COMPAT
&&
1735 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
1736 case GL_LUMINANCE_ALPHA
:
1737 case GL_LUMINANCE4_ALPHA4
:
1738 case GL_LUMINANCE6_ALPHA2
:
1739 case GL_LUMINANCE8_ALPHA8
:
1740 case GL_LUMINANCE12_ALPHA4
:
1741 case GL_LUMINANCE12_ALPHA12
:
1742 case GL_LUMINANCE16_ALPHA16
:
1743 return (ctx
->API
== API_OPENGL_COMPAT
&&
1744 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
1748 case GL_INTENSITY12
:
1749 case GL_INTENSITY16
:
1750 return (ctx
->API
== API_OPENGL_COMPAT
&&
1751 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
1761 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1763 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1772 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1774 case GL_SRGB8_ALPHA8_EXT
:
1775 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1776 case GL_STENCIL_INDEX
:
1777 case GL_STENCIL_INDEX1_EXT
:
1778 case GL_STENCIL_INDEX4_EXT
:
1779 case GL_STENCIL_INDEX16_EXT
:
1780 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1781 * OpenGL ES, but Mesa does not currently support them.
1783 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1784 case GL_STENCIL_INDEX8_EXT
:
1785 return GL_STENCIL_INDEX
;
1786 case GL_DEPTH_COMPONENT
:
1787 case GL_DEPTH_COMPONENT32
:
1788 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1789 case GL_DEPTH_COMPONENT16
:
1790 case GL_DEPTH_COMPONENT24
:
1791 return GL_DEPTH_COMPONENT
;
1792 case GL_DEPTH_STENCIL
:
1793 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
1794 case GL_DEPTH24_STENCIL8
:
1795 return GL_DEPTH_STENCIL
;
1796 case GL_DEPTH_COMPONENT32F
:
1797 return ctx
->Version
>= 30
1798 || (ctx
->API
== API_OPENGL_COMPAT
&&
1799 ctx
->Extensions
.ARB_depth_buffer_float
)
1800 ? GL_DEPTH_COMPONENT
: 0;
1801 case GL_DEPTH32F_STENCIL8
:
1802 return ctx
->Version
>= 30
1803 || (ctx
->API
== API_OPENGL_COMPAT
&&
1804 ctx
->Extensions
.ARB_depth_buffer_float
)
1805 ? GL_DEPTH_STENCIL
: 0;
1808 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1811 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1815 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1818 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1820 /* signed normalized texture formats */
1824 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1829 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1833 case GL_RGB16_SNORM
:
1834 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1837 case GL_RGBA8_SNORM
:
1838 case GL_RGBA16_SNORM
:
1839 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1841 case GL_ALPHA_SNORM
:
1842 case GL_ALPHA8_SNORM
:
1843 case GL_ALPHA16_SNORM
:
1844 return ctx
->API
== API_OPENGL_COMPAT
&&
1845 ctx
->Extensions
.EXT_texture_snorm
&&
1846 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1847 case GL_LUMINANCE_SNORM
:
1848 case GL_LUMINANCE8_SNORM
:
1849 case GL_LUMINANCE16_SNORM
:
1850 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1852 case GL_LUMINANCE_ALPHA_SNORM
:
1853 case GL_LUMINANCE8_ALPHA8_SNORM
:
1854 case GL_LUMINANCE16_ALPHA16_SNORM
:
1855 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1856 ? GL_LUMINANCE_ALPHA
: 0;
1857 case GL_INTENSITY_SNORM
:
1858 case GL_INTENSITY8_SNORM
:
1859 case GL_INTENSITY16_SNORM
:
1860 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1865 return ((_mesa_is_desktop_gl(ctx
) &&
1866 ctx
->Extensions
.ARB_texture_rg
&&
1867 ctx
->Extensions
.ARB_texture_float
) ||
1868 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1872 return ((_mesa_is_desktop_gl(ctx
) &&
1873 ctx
->Extensions
.ARB_texture_rg
&&
1874 ctx
->Extensions
.ARB_texture_float
) ||
1875 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1879 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1883 return ((_mesa_is_desktop_gl(ctx
) &&
1884 ctx
->Extensions
.ARB_texture_float
) ||
1885 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1887 case GL_ALPHA16F_ARB
:
1888 case GL_ALPHA32F_ARB
:
1889 return ctx
->API
== API_OPENGL_COMPAT
&&
1890 ctx
->Extensions
.ARB_texture_float
&&
1891 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1892 case GL_LUMINANCE16F_ARB
:
1893 case GL_LUMINANCE32F_ARB
:
1894 return ctx
->API
== API_OPENGL_COMPAT
&&
1895 ctx
->Extensions
.ARB_texture_float
&&
1896 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1897 case GL_LUMINANCE_ALPHA16F_ARB
:
1898 case GL_LUMINANCE_ALPHA32F_ARB
:
1899 return ctx
->API
== API_OPENGL_COMPAT
&&
1900 ctx
->Extensions
.ARB_texture_float
&&
1901 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1902 case GL_INTENSITY16F_ARB
:
1903 case GL_INTENSITY32F_ARB
:
1904 return ctx
->API
== API_OPENGL_COMPAT
&&
1905 ctx
->Extensions
.ARB_texture_float
&&
1906 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1907 case GL_R11F_G11F_B10F
:
1908 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1909 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1912 case GL_RGBA8UI_EXT
:
1913 case GL_RGBA16UI_EXT
:
1914 case GL_RGBA32UI_EXT
:
1916 case GL_RGBA16I_EXT
:
1917 case GL_RGBA32I_EXT
:
1918 return ctx
->Version
>= 30
1919 || (_mesa_is_desktop_gl(ctx
) &&
1920 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
1923 case GL_RGB16UI_EXT
:
1924 case GL_RGB32UI_EXT
:
1928 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
1936 return ctx
->Version
>= 30
1937 || (_mesa_is_desktop_gl(ctx
) &&
1938 ctx
->Extensions
.ARB_texture_rg
&&
1939 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
1947 return ctx
->Version
>= 30
1948 || (_mesa_is_desktop_gl(ctx
) &&
1949 ctx
->Extensions
.ARB_texture_rg
&&
1950 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
1952 case GL_INTENSITY8I_EXT
:
1953 case GL_INTENSITY8UI_EXT
:
1954 case GL_INTENSITY16I_EXT
:
1955 case GL_INTENSITY16UI_EXT
:
1956 case GL_INTENSITY32I_EXT
:
1957 case GL_INTENSITY32UI_EXT
:
1958 return ctx
->API
== API_OPENGL_COMPAT
&&
1959 ctx
->Extensions
.EXT_texture_integer
&&
1960 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1962 case GL_LUMINANCE8I_EXT
:
1963 case GL_LUMINANCE8UI_EXT
:
1964 case GL_LUMINANCE16I_EXT
:
1965 case GL_LUMINANCE16UI_EXT
:
1966 case GL_LUMINANCE32I_EXT
:
1967 case GL_LUMINANCE32UI_EXT
:
1968 return ctx
->API
== API_OPENGL_COMPAT
&&
1969 ctx
->Extensions
.EXT_texture_integer
&&
1970 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1972 case GL_LUMINANCE_ALPHA8I_EXT
:
1973 case GL_LUMINANCE_ALPHA8UI_EXT
:
1974 case GL_LUMINANCE_ALPHA16I_EXT
:
1975 case GL_LUMINANCE_ALPHA16UI_EXT
:
1976 case GL_LUMINANCE_ALPHA32I_EXT
:
1977 case GL_LUMINANCE_ALPHA32UI_EXT
:
1978 return ctx
->API
== API_OPENGL_COMPAT
&&
1979 ctx
->Extensions
.EXT_texture_integer
&&
1980 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1982 case GL_ALPHA8I_EXT
:
1983 case GL_ALPHA8UI_EXT
:
1984 case GL_ALPHA16I_EXT
:
1985 case GL_ALPHA16UI_EXT
:
1986 case GL_ALPHA32I_EXT
:
1987 case GL_ALPHA32UI_EXT
:
1988 return ctx
->API
== API_OPENGL_COMPAT
&&
1989 ctx
->Extensions
.EXT_texture_integer
&&
1990 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1993 return (_mesa_is_desktop_gl(ctx
) &&
1994 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
1995 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1998 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2007 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2010 invalidate_rb(GLuint key
, void *data
, void *userData
)
2012 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2013 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2015 /* If this is a user-created FBO */
2016 if (_mesa_is_user_fbo(fb
)) {
2018 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2019 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2020 if (att
->Type
== GL_RENDERBUFFER
&&
2021 att
->Renderbuffer
== rb
) {
2022 /* Mark fb status as indeterminate to force re-validation */
2031 /** sentinal value, see below */
2032 #define NO_SAMPLES 1000
2035 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2036 GLenum internalFormat
, GLsizei width
,
2037 GLsizei height
, GLsizei samples
)
2039 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2041 assert(baseFormat
!= 0);
2042 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2043 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2044 assert(samples
!= NO_SAMPLES
);
2046 assert(samples
> 0);
2047 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2048 internalFormat
, samples
) == GL_NO_ERROR
);
2051 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2053 if (rb
->InternalFormat
== internalFormat
&&
2054 rb
->Width
== (GLuint
) width
&&
2055 rb
->Height
== (GLuint
) height
&&
2056 rb
->NumSamples
== samples
) {
2057 /* no change in allocation needed */
2061 /* These MUST get set by the AllocStorage func */
2062 rb
->Format
= MESA_FORMAT_NONE
;
2063 rb
->NumSamples
= samples
;
2065 /* Now allocate the storage */
2066 assert(rb
->AllocStorage
);
2067 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2068 /* No error - check/set fields now */
2069 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2070 assert(rb
->Width
== (GLuint
) width
);
2071 assert(rb
->Height
== (GLuint
) height
);
2072 rb
->InternalFormat
= internalFormat
;
2073 rb
->_BaseFormat
= baseFormat
;
2074 assert(rb
->_BaseFormat
!= 0);
2077 /* Probably ran out of memory - clear the fields */
2080 rb
->Format
= MESA_FORMAT_NONE
;
2081 rb
->InternalFormat
= GL_NONE
;
2082 rb
->_BaseFormat
= GL_NONE
;
2086 /* Invalidate the framebuffers the renderbuffer is attached in. */
2087 if (rb
->AttachedAnytime
) {
2088 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2093 * Helper function used by renderbuffer_storage_direct() and
2094 * renderbuffer_storage_target().
2095 * samples will be NO_SAMPLES if called by a non-multisample function.
2098 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2099 GLenum internalFormat
, GLsizei width
,
2100 GLsizei height
, GLsizei samples
, const char *func
)
2103 GLenum sample_count_error
;
2105 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2106 if (baseFormat
== 0) {
2107 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2108 func
, _mesa_enum_to_string(internalFormat
));
2112 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2113 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2118 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2119 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2124 if (samples
== NO_SAMPLES
) {
2125 /* NumSamples == 0 indicates non-multisampling */
2129 /* check the sample count;
2130 * note: driver may choose to use more samples than what's requested
2132 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2133 internalFormat
, samples
);
2135 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2137 * "If a negative number is provided where an argument of type sizei or
2138 * sizeiptr is specified, the error INVALID VALUE is generated."
2141 sample_count_error
= GL_INVALID_VALUE
;
2144 if (sample_count_error
!= GL_NO_ERROR
) {
2145 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
2150 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
);
2154 * Helper function used by _mesa_NamedRenderbufferStorage*().
2155 * samples will be NO_SAMPLES if called by a non-multisample function.
2158 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2159 GLsizei width
, GLsizei height
, GLsizei samples
,
2162 GET_CURRENT_CONTEXT(ctx
);
2164 if (MESA_VERBOSE
& VERBOSE_API
) {
2165 if (samples
== NO_SAMPLES
)
2166 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2168 _mesa_enum_to_string(internalFormat
),
2171 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2173 _mesa_enum_to_string(internalFormat
),
2174 width
, height
, samples
);
2177 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2178 if (!rb
|| rb
== &DummyRenderbuffer
) {
2179 /* ID was reserved, but no real renderbuffer object made yet */
2180 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2181 func
, renderbuffer
);
2185 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
, func
);
2189 * Helper function used by _mesa_RenderbufferStorage() and
2190 * _mesa_RenderbufferStorageMultisample().
2191 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2194 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2195 GLsizei width
, GLsizei height
, GLsizei samples
,
2198 GET_CURRENT_CONTEXT(ctx
);
2200 if (MESA_VERBOSE
& VERBOSE_API
) {
2201 if (samples
== NO_SAMPLES
)
2202 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2204 _mesa_enum_to_string(target
),
2205 _mesa_enum_to_string(internalFormat
),
2208 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2210 _mesa_enum_to_string(target
),
2211 _mesa_enum_to_string(internalFormat
),
2212 width
, height
, samples
);
2215 if (target
!= GL_RENDERBUFFER_EXT
) {
2216 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2220 if (!ctx
->CurrentRenderbuffer
) {
2221 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2226 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2227 height
, samples
, func
);
2232 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2234 struct gl_renderbuffer
*rb
;
2235 GET_CURRENT_CONTEXT(ctx
);
2237 if (!ctx
->Extensions
.OES_EGL_image
) {
2238 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2239 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2243 if (target
!= GL_RENDERBUFFER
) {
2244 _mesa_error(ctx
, GL_INVALID_ENUM
,
2245 "EGLImageTargetRenderbufferStorageOES");
2249 rb
= ctx
->CurrentRenderbuffer
;
2251 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2252 "EGLImageTargetRenderbufferStorageOES");
2256 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2258 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2263 * Helper function for _mesa_GetRenderbufferParameteriv() and
2264 * _mesa_GetFramebufferAttachmentParameteriv()
2265 * We have to be careful to respect the base format. For example, if a
2266 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2267 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2268 * we need to return zero.
2271 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2273 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2274 return _mesa_get_format_bits(format
, pname
);
2282 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2283 GLsizei width
, GLsizei height
)
2285 /* GL_ARB_fbo says calling this function is equivalent to calling
2286 * glRenderbufferStorageMultisample() with samples=0. We pass in
2287 * a token value here just for error reporting purposes.
2289 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2290 NO_SAMPLES
, "glRenderbufferStorage");
2295 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2296 GLenum internalFormat
,
2297 GLsizei width
, GLsizei height
)
2299 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2300 samples
, "glRenderbufferStorageMultisample");
2305 * OpenGL ES version of glRenderBufferStorage.
2308 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2309 GLsizei width
, GLsizei height
)
2311 switch (internalFormat
) {
2313 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2314 /* choose a closest format */
2315 internalFormat
= GL_RGB5
;
2321 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0,
2322 "glRenderbufferStorageEXT");
2326 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2327 GLsizei width
, GLsizei height
)
2329 /* GL_ARB_fbo says calling this function is equivalent to calling
2330 * glRenderbufferStorageMultisample() with samples=0. We pass in
2331 * a token value here just for error reporting purposes.
2333 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2334 NO_SAMPLES
, "glNamedRenderbufferStorage");
2338 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2339 GLenum internalformat
,
2340 GLsizei width
, GLsizei height
)
2342 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2344 "glNamedRenderbufferStorageMultisample");
2349 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2350 struct gl_renderbuffer
*rb
, GLenum pname
,
2351 GLint
*params
, const char *func
)
2353 /* No need to flush here since we're just quering state which is
2354 * not effected by rendering.
2358 case GL_RENDERBUFFER_WIDTH_EXT
:
2359 *params
= rb
->Width
;
2361 case GL_RENDERBUFFER_HEIGHT_EXT
:
2362 *params
= rb
->Height
;
2364 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2365 *params
= rb
->InternalFormat
;
2367 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2368 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2369 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2370 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2371 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2372 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2373 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2375 case GL_RENDERBUFFER_SAMPLES
:
2376 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2377 || _mesa_is_gles3(ctx
)) {
2378 *params
= rb
->NumSamples
;
2383 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2384 _mesa_enum_to_string(pname
));
2391 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2393 GET_CURRENT_CONTEXT(ctx
);
2395 if (target
!= GL_RENDERBUFFER_EXT
) {
2396 _mesa_error(ctx
, GL_INVALID_ENUM
,
2397 "glGetRenderbufferParameterivEXT(target)");
2401 if (!ctx
->CurrentRenderbuffer
) {
2402 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2403 "(no renderbuffer bound)");
2407 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2408 params
, "glGetRenderbufferParameteriv");
2413 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2416 GET_CURRENT_CONTEXT(ctx
);
2418 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2419 if (!rb
|| rb
== &DummyRenderbuffer
) {
2420 /* ID was reserved, but no real renderbuffer object made yet */
2421 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2422 "(invalid renderbuffer %i)", renderbuffer
);
2426 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2427 "glGetNamedRenderbufferParameteriv");
2431 GLboolean GLAPIENTRY
2432 _mesa_IsFramebuffer(GLuint framebuffer
)
2434 GET_CURRENT_CONTEXT(ctx
);
2435 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2437 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2438 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2446 * Check if any of the attachments of the given framebuffer are textures
2447 * (render to texture). Call ctx->Driver.RenderTexture() for such
2451 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2454 assert(ctx
->Driver
.RenderTexture
);
2456 if (_mesa_is_winsys_fbo(fb
))
2457 return; /* can't render to texture with winsys framebuffers */
2459 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2460 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2461 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2462 && driver_RenderTexture_is_safe(att
)) {
2463 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2470 * Examine all the framebuffer's attachments to see if any are textures.
2471 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2472 * notify the device driver that the texture image may have changed.
2475 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2477 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2478 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2481 if (ctx
->Driver
.FinishRenderTexture
) {
2483 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2484 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2485 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2486 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2487 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2495 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2497 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2498 GLboolean bindReadBuf
, bindDrawBuf
;
2499 GET_CURRENT_CONTEXT(ctx
);
2502 case GL_DRAW_FRAMEBUFFER_EXT
:
2503 bindDrawBuf
= GL_TRUE
;
2504 bindReadBuf
= GL_FALSE
;
2506 case GL_READ_FRAMEBUFFER_EXT
:
2507 bindDrawBuf
= GL_FALSE
;
2508 bindReadBuf
= GL_TRUE
;
2510 case GL_FRAMEBUFFER_EXT
:
2511 bindDrawBuf
= GL_TRUE
;
2512 bindReadBuf
= GL_TRUE
;
2515 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2520 /* Binding a user-created framebuffer object */
2521 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2522 if (newDrawFb
== &DummyFramebuffer
) {
2523 /* ID was reserved, but no real framebuffer object made yet */
2526 else if (!newDrawFb
&& !allow_user_names
) {
2527 /* All FBO IDs must be Gen'd */
2528 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2533 /* create new framebuffer object */
2534 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2536 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2539 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2541 newReadFb
= newDrawFb
;
2544 /* Binding the window system framebuffer (which was originally set
2545 * with MakeCurrent).
2547 newDrawFb
= ctx
->WinSysDrawBuffer
;
2548 newReadFb
= ctx
->WinSysReadBuffer
;
2551 _mesa_bind_framebuffers(ctx
,
2552 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2553 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2557 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2558 struct gl_framebuffer
*newDrawFb
,
2559 struct gl_framebuffer
*newReadFb
)
2561 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
2562 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
2563 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
2564 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
2567 assert(newDrawFb
!= &DummyFramebuffer
);
2570 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2572 * We also check if we're beginning and/or ending render-to-texture.
2573 * When a framebuffer with texture attachments is unbound, call
2574 * ctx->Driver.FinishRenderTexture().
2575 * When a framebuffer with texture attachments is bound, call
2576 * ctx->Driver.RenderTexture().
2578 * Note that if the ReadBuffer has texture attachments we don't consider
2579 * that a render-to-texture case.
2582 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2584 /* check if old readbuffer was render-to-texture */
2585 check_end_texture_render(ctx
, oldReadFb
);
2587 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2591 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2593 /* check if old framebuffer had any texture attachments */
2595 check_end_texture_render(ctx
, oldDrawFb
);
2597 /* check if newly bound framebuffer has any texture attachments */
2598 check_begin_texture_render(ctx
, newDrawFb
);
2600 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2603 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2604 /* The few classic drivers that actually hook this function really only
2605 * want to know if the draw framebuffer changed.
2607 ctx
->Driver
.BindFramebuffer(ctx
,
2608 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
2609 newDrawFb
, newReadFb
);
2614 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2616 GET_CURRENT_CONTEXT(ctx
);
2618 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2619 * point, but they allow the use of user-generated names.
2621 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2626 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2628 /* This function should not be in the dispatch table for core profile /
2629 * OpenGL 3.1, so execution should never get here in those cases -- no
2630 * need for an explicit test.
2632 bind_framebuffer(target
, framebuffer
, true);
2637 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2640 GET_CURRENT_CONTEXT(ctx
);
2643 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
2647 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2649 for (i
= 0; i
< n
; i
++) {
2650 if (framebuffers
[i
] > 0) {
2651 struct gl_framebuffer
*fb
;
2652 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2654 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2656 /* check if deleting currently bound framebuffer object */
2657 if (fb
== ctx
->DrawBuffer
) {
2659 assert(fb
->RefCount
>= 2);
2660 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2662 if (fb
== ctx
->ReadBuffer
) {
2664 assert(fb
->RefCount
>= 2);
2665 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2668 /* remove from hash table immediately, to free the ID */
2669 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2671 if (fb
!= &DummyFramebuffer
) {
2672 /* But the object will not be freed until it's no longer
2673 * bound in any context.
2675 _mesa_reference_framebuffer(&fb
, NULL
);
2684 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2685 * It is not exposed to the rest of Mesa to encourage the use of
2686 * nameless buffers in driver internals.
2689 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
2691 GET_CURRENT_CONTEXT(ctx
);
2694 struct gl_framebuffer
*fb
;
2696 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
2699 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
2706 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
2708 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2710 for (i
= 0; i
< n
; i
++) {
2711 GLuint name
= first
+ i
;
2712 framebuffers
[i
] = name
;
2715 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
2717 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2718 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
2723 fb
= &DummyFramebuffer
;
2725 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
2728 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2733 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2735 create_framebuffers(n
, framebuffers
, false);
2740 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2742 create_framebuffers(n
, framebuffers
, true);
2747 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
2748 struct gl_framebuffer
*buffer
)
2750 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2752 if (_mesa_is_winsys_fbo(buffer
)) {
2753 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2754 if (buffer
!= &IncompleteFramebuffer
) {
2755 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2757 return GL_FRAMEBUFFER_UNDEFINED
;
2761 /* No need to flush here */
2763 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2764 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2767 return buffer
->_Status
;
2772 _mesa_CheckFramebufferStatus(GLenum target
)
2774 struct gl_framebuffer
*fb
;
2775 GET_CURRENT_CONTEXT(ctx
);
2777 if (MESA_VERBOSE
& VERBOSE_API
)
2778 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2779 _mesa_enum_to_string(target
));
2781 fb
= get_framebuffer_target(ctx
, target
);
2783 _mesa_error(ctx
, GL_INVALID_ENUM
,
2784 "glCheckFramebufferStatus(invalid target %s)",
2785 _mesa_enum_to_string(target
));
2789 return _mesa_check_framebuffer_status(ctx
, fb
);
2794 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
2796 struct gl_framebuffer
*fb
;
2797 GET_CURRENT_CONTEXT(ctx
);
2799 /* Validate the target (for conformance's sake) and grab a reference to the
2800 * default framebuffer in case framebuffer = 0.
2801 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
2802 * (30.10.2014, PDF page 336) says:
2803 * "If framebuffer is zero, then the status of the default read or
2804 * draw framebuffer (as determined by target) is returned."
2807 case GL_DRAW_FRAMEBUFFER
:
2808 case GL_FRAMEBUFFER
:
2809 fb
= ctx
->WinSysDrawBuffer
;
2811 case GL_READ_FRAMEBUFFER
:
2812 fb
= ctx
->WinSysReadBuffer
;
2815 _mesa_error(ctx
, GL_INVALID_ENUM
,
2816 "glCheckNamedFramebufferStatus(invalid target %s)",
2817 _mesa_enum_to_string(target
));
2822 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
2823 "glCheckNamedFramebufferStatus");
2828 return _mesa_check_framebuffer_status(ctx
, fb
);
2833 * Replicate the src attachment point. Used by framebuffer_texture() when
2834 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2835 * GL_STENCIL_ATTACHMENT.
2838 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2839 gl_buffer_index dst
,
2840 gl_buffer_index src
)
2842 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2843 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2845 assert(src_att
->Texture
!= NULL
);
2846 assert(src_att
->Renderbuffer
!= NULL
);
2848 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2849 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2850 dst_att
->Type
= src_att
->Type
;
2851 dst_att
->Complete
= src_att
->Complete
;
2852 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2853 dst_att
->Zoffset
= src_att
->Zoffset
;
2854 dst_att
->Layered
= src_att
->Layered
;
2859 * Common code called by gl*FramebufferTexture*() to retrieve the correct
2860 * texture object pointer.
2862 * \param texObj where the pointer to the texture object is returned. Note
2863 * that a successful call may return texObj = NULL.
2865 * \return true if no errors, false if errors
2868 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
,
2869 bool layered
, const char *caller
,
2870 struct gl_texture_object
**texObj
)
2872 *texObj
= NULL
; /* This will get returned if texture = 0. */
2877 *texObj
= _mesa_lookup_texture(ctx
, texture
);
2878 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
2879 /* Can't render to a non-existent texture object.
2881 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
2882 * Managing Framebuffer Objects specifies a different error
2883 * depending upon the calling function (PDF pages 325-328).
2884 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
2885 * value, while the other commands throw invalid operation (where
2886 * layered = GL_FALSE).
2888 const GLenum error
= layered
? GL_INVALID_VALUE
:
2889 GL_INVALID_OPERATION
;
2890 _mesa_error(ctx
, error
,
2891 "%s(non-existent texture %u)", caller
, texture
);
2900 * Common code called by gl*FramebufferTexture() to verify the texture target
2901 * and decide whether or not the attachment should truly be considered
2904 * \param layered true if attachment should be considered layered, false if
2907 * \return true if no errors, false if errors
2910 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
2911 const char *caller
, GLboolean
*layered
)
2917 case GL_TEXTURE_1D_ARRAY_EXT
:
2918 case GL_TEXTURE_2D_ARRAY_EXT
:
2919 case GL_TEXTURE_CUBE_MAP
:
2920 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2921 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2925 case GL_TEXTURE_RECTANGLE
:
2926 case GL_TEXTURE_2D_MULTISAMPLE
:
2927 /* These texture types are valid to pass to
2928 * glFramebufferTexture(), but since they aren't layered, it
2929 * is equivalent to calling glFramebufferTexture{1D,2D}().
2931 *layered
= GL_FALSE
;
2935 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2936 "%s(invalid texture target %s)", caller
,
2937 _mesa_enum_to_string(target
));
2943 * Common code called by gl*FramebufferTextureLayer() to verify the texture
2946 * \return true if no errors, false if errors
2949 check_texture_target(struct gl_context
*ctx
, GLenum target
,
2952 /* We're being called by glFramebufferTextureLayer().
2953 * The only legal texture types for that function are 3D,
2954 * cube-map, and 1D/2D/cube-map array textures.
2956 * We don't need to check for GL_ARB_texture_cube_map_array because the
2957 * application wouldn't have been able to create a texture with a
2958 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
2962 case GL_TEXTURE_1D_ARRAY
:
2963 case GL_TEXTURE_2D_ARRAY
:
2964 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2965 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2967 case GL_TEXTURE_CUBE_MAP
:
2968 /* We don't need to check the extension (GL_ARB_direct_state_access) or
2969 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
2970 * enabled in core profile. This can be called from
2971 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
2972 * so we do have to check the profile.
2974 return ctx
->API
== API_OPENGL_CORE
;
2977 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2978 "%s(invalid texture target %s)", caller
,
2979 _mesa_enum_to_string(target
));
2985 * Common code called by glFramebufferTexture*D() to verify the texture
2988 * \return true if no errors, false if errors
2991 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
2992 GLenum textarget
, const char *caller
)
2996 switch (textarget
) {
3000 case GL_TEXTURE_1D_ARRAY
:
3001 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3006 case GL_TEXTURE_2D_ARRAY
:
3007 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3008 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3010 case GL_TEXTURE_2D_MULTISAMPLE
:
3011 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3013 !ctx
->Extensions
.ARB_texture_multisample
||
3014 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3016 case GL_TEXTURE_RECTANGLE
:
3017 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3018 !ctx
->Extensions
.NV_texture_rectangle
;
3020 case GL_TEXTURE_CUBE_MAP
:
3021 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3024 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3025 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3026 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3027 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3028 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3029 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3030 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3036 _mesa_error(ctx
, GL_INVALID_ENUM
,
3037 "%s(unknown textarget 0x%x)", caller
, textarget
);
3042 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3043 "%s(invalid textarget %s)",
3044 caller
, _mesa_enum_to_string(textarget
));
3048 /* Make sure textarget is consistent with the texture's type */
3049 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3050 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3053 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3054 "%s(mismatched texture target)", caller
);
3063 * Common code called by gl*FramebufferTextureLayer() and
3064 * glFramebufferTexture3D() to validate the layer.
3066 * \return true if no errors, false if errors
3069 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3072 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3075 * "An INVALID_VALUE error is generated if texture is non-zero
3076 * and layer is negative."
3079 _mesa_error(ctx
, GL_INVALID_VALUE
,
3080 "%s(layer %u < 0)", caller
, layer
);
3084 if (target
== GL_TEXTURE_3D
) {
3085 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3086 if (layer
>= maxSize
) {
3087 _mesa_error(ctx
, GL_INVALID_VALUE
,
3088 "%s(invalid layer %u)", caller
, layer
);
3092 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3093 (target
== GL_TEXTURE_2D_ARRAY
) ||
3094 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3095 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3096 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3097 _mesa_error(ctx
, GL_INVALID_VALUE
,
3098 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3103 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3105 _mesa_error(ctx
, GL_INVALID_VALUE
,
3106 "%s(layer %u >= 6)", caller
, layer
);
3116 * Common code called by all gl*FramebufferTexture*() entry points to verify
3119 * \return true if no errors, false if errors
3122 check_level(struct gl_context
*ctx
, GLenum target
, GLint level
,
3126 (level
>= _mesa_max_texture_levels(ctx
, target
))) {
3127 _mesa_error(ctx
, GL_INVALID_VALUE
,
3128 "%s(invalid level %d)", caller
, level
);
3137 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3139 struct gl_texture_object
*texObj
, GLenum textarget
,
3140 GLint level
, GLuint layer
, GLboolean layered
,
3143 struct gl_renderbuffer_attachment
*att
;
3145 /* The window-system framebuffer object is immutable */
3146 if (_mesa_is_winsys_fbo(fb
)) {
3147 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3152 /* Not a hash lookup, so we can afford to get the attachment here. */
3153 att
= get_attachment(ctx
, fb
, attachment
);
3155 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3156 _mesa_enum_to_string(attachment
));
3160 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3162 mtx_lock(&fb
->Mutex
);
3164 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3165 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3166 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3167 _mesa_tex_target_to_face(textarget
) ==
3168 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3169 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3170 /* The texture object is already attached to the stencil attachment
3171 * point. Don't create a new renderbuffer; just reuse the stencil
3172 * attachment's. This is required to prevent a GL error in
3173 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3175 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3177 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3178 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3179 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3180 _mesa_tex_target_to_face(textarget
) ==
3181 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3182 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3183 /* As above, but with depth and stencil transposed. */
3184 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3187 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3188 level
, layer
, layered
);
3190 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3191 /* Above we created a new renderbuffer and attached it to the
3192 * depth attachment point. Now attach it to the stencil attachment
3195 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3196 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3201 /* Set the render-to-texture flag. We'll check this flag in
3202 * glTexImage() and friends to determine if we need to revalidate
3203 * any FBOs that might be rendering into this texture.
3204 * This flag never gets cleared since it's non-trivial to determine
3205 * when all FBOs might be done rendering to this texture. That's OK
3206 * though since it's uncommon to render to a texture then repeatedly
3207 * call glTexImage() to change images in the texture.
3209 texObj
->_RenderToTexture
= GL_TRUE
;
3212 remove_attachment(ctx
, att
);
3213 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3214 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3215 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3219 invalidate_framebuffer(fb
);
3221 mtx_unlock(&fb
->Mutex
);
3226 framebuffer_texture_with_dims(int dims
, GLenum target
,
3227 GLenum attachment
, GLenum textarget
,
3228 GLuint texture
, GLint level
, GLint layer
,
3231 GET_CURRENT_CONTEXT(ctx
);
3232 struct gl_framebuffer
*fb
;
3233 struct gl_texture_object
*texObj
;
3235 /* Get the framebuffer object */
3236 fb
= get_framebuffer_target(ctx
, target
);
3238 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3239 _mesa_enum_to_string(target
));
3243 /* Get the texture object */
3244 if (!get_texture_for_framebuffer(ctx
, texture
, false, caller
, &texObj
))
3248 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3251 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3254 if (!check_level(ctx
, textarget
, level
, caller
))
3258 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3259 layer
, GL_FALSE
, caller
);
3264 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3265 GLenum textarget
, GLuint texture
, GLint level
)
3267 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3268 level
, 0, "glFramebufferTexture1D");
3273 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3274 GLenum textarget
, GLuint texture
, GLint level
)
3276 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3277 level
, 0, "glFramebufferTexture2D");
3282 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3283 GLenum textarget
, GLuint texture
,
3284 GLint level
, GLint layer
)
3286 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3287 level
, layer
, "glFramebufferTexture3D");
3292 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3293 GLuint texture
, GLint level
, GLint layer
)
3295 GET_CURRENT_CONTEXT(ctx
);
3296 struct gl_framebuffer
*fb
;
3297 struct gl_texture_object
*texObj
;
3298 GLenum textarget
= 0;
3300 const char *func
= "glFramebufferTextureLayer";
3302 /* Get the framebuffer object */
3303 fb
= get_framebuffer_target(ctx
, target
);
3305 _mesa_error(ctx
, GL_INVALID_ENUM
,
3306 "glFramebufferTextureLayer(invalid target %s)",
3307 _mesa_enum_to_string(target
));
3311 /* Get the texture object */
3312 if (!get_texture_for_framebuffer(ctx
, texture
, false, func
, &texObj
))
3316 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3319 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3322 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3325 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3326 assert(layer
>= 0 && layer
< 6);
3327 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3332 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3333 layer
, GL_FALSE
, func
);
3338 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3339 GLuint texture
, GLint level
, GLint layer
)
3341 GET_CURRENT_CONTEXT(ctx
);
3342 struct gl_framebuffer
*fb
;
3343 struct gl_texture_object
*texObj
;
3344 GLenum textarget
= 0;
3346 const char *func
= "glNamedFramebufferTextureLayer";
3348 /* Get the framebuffer object */
3349 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3353 /* Get the texture object */
3354 if (!get_texture_for_framebuffer(ctx
, texture
, false, func
, &texObj
))
3358 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3361 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3364 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3367 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3368 assert(layer
>= 0 && layer
< 6);
3369 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3374 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3375 layer
, GL_FALSE
, func
);
3380 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3381 GLuint texture
, GLint level
)
3383 GET_CURRENT_CONTEXT(ctx
);
3384 struct gl_framebuffer
*fb
;
3385 struct gl_texture_object
*texObj
;
3386 GLboolean layered
= GL_FALSE
;
3388 const char *func
= "FramebufferTexture";
3390 if (!_mesa_has_geometry_shaders(ctx
)) {
3391 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3392 "unsupported function (glFramebufferTexture) called");
3396 /* Get the framebuffer object */
3397 fb
= get_framebuffer_target(ctx
, target
);
3399 _mesa_error(ctx
, GL_INVALID_ENUM
,
3400 "glFramebufferTexture(invalid target %s)",
3401 _mesa_enum_to_string(target
));
3405 /* Get the texture object */
3406 if (!get_texture_for_framebuffer(ctx
, texture
, true, func
, &texObj
))
3410 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
, &layered
))
3413 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3417 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, 0, level
,
3423 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3424 GLuint texture
, GLint level
)
3426 GET_CURRENT_CONTEXT(ctx
);
3427 struct gl_framebuffer
*fb
;
3428 struct gl_texture_object
*texObj
;
3429 GLboolean layered
= GL_FALSE
;
3431 const char *func
= "glNamedFramebufferTexture";
3433 if (!_mesa_has_geometry_shaders(ctx
)) {
3434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3435 "unsupported function (glNamedFramebufferTexture) called");
3439 /* Get the framebuffer object */
3440 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3444 /* Get the texture object */
3445 if (!get_texture_for_framebuffer(ctx
, texture
, true, func
, &texObj
))
3449 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3453 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3457 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, 0, level
,
3463 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3464 struct gl_framebuffer
*fb
,
3466 struct gl_renderbuffer
*rb
)
3468 assert(!_mesa_is_winsys_fbo(fb
));
3470 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3472 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3473 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3475 /* Some subsequent GL commands may depend on the framebuffer's visual
3476 * after the binding is updated. Update visual info now.
3478 _mesa_update_framebuffer_visual(ctx
, fb
);
3482 framebuffer_renderbuffer(struct gl_context
*ctx
,
3483 struct gl_framebuffer
*fb
,
3485 struct gl_renderbuffer
*rb
,
3488 struct gl_renderbuffer_attachment
*att
;
3490 if (_mesa_is_winsys_fbo(fb
)) {
3491 /* Can't attach new renderbuffers to a window system framebuffer */
3492 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3493 "%s(window-system framebuffer)", func
);
3497 att
= get_attachment(ctx
, fb
, attachment
);
3499 _mesa_error(ctx
, GL_INVALID_ENUM
,
3500 "%s(invalid attachment %s)", func
,
3501 _mesa_enum_to_string(attachment
));
3505 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3506 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3507 /* make sure the renderbuffer is a depth/stencil format */
3508 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3509 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3510 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3511 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3516 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3520 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3521 GLenum renderbuffertarget
,
3522 GLuint renderbuffer
)
3524 struct gl_framebuffer
*fb
;
3525 struct gl_renderbuffer
*rb
;
3526 GET_CURRENT_CONTEXT(ctx
);
3528 fb
= get_framebuffer_target(ctx
, target
);
3530 _mesa_error(ctx
, GL_INVALID_ENUM
,
3531 "glFramebufferRenderbuffer(invalid target %s)",
3532 _mesa_enum_to_string(target
));
3536 if (renderbuffertarget
!= GL_RENDERBUFFER
) {
3537 _mesa_error(ctx
, GL_INVALID_ENUM
,
3538 "glFramebufferRenderbuffer(renderbuffertarget is not "
3539 "GL_RENDERBUFFER)");
3544 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
,
3545 "glFramebufferRenderbuffer");
3550 /* remove renderbuffer attachment */
3554 framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
,
3555 "glFramebufferRenderbuffer");
3560 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
3561 GLenum renderbuffertarget
,
3562 GLuint renderbuffer
)
3564 struct gl_framebuffer
*fb
;
3565 struct gl_renderbuffer
*rb
;
3566 GET_CURRENT_CONTEXT(ctx
);
3568 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3569 "glNamedFramebufferRenderbuffer");
3573 if (renderbuffertarget
!= GL_RENDERBUFFER
) {
3574 _mesa_error(ctx
, GL_INVALID_ENUM
,
3575 "glNamedFramebufferRenderbuffer(renderbuffertarget is not "
3576 "GL_RENDERBUFFER)");
3581 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
,
3582 "glNamedFramebufferRenderbuffer");
3587 /* remove renderbuffer attachment */
3591 framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
,
3592 "glNamedFramebufferRenderbuffer");
3597 _mesa_get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
3598 struct gl_framebuffer
*buffer
,
3599 GLenum attachment
, GLenum pname
,
3600 GLint
*params
, const char *caller
)
3602 const struct gl_renderbuffer_attachment
*att
;
3605 /* The error code for an attachment type of GL_NONE differs between APIs.
3607 * From the ES 2.0.25 specification, page 127:
3608 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3609 * querying any other pname will generate INVALID_ENUM."
3611 * From the OpenGL 3.0 specification, page 337, or identically,
3612 * the OpenGL ES 3.0.4 specification, page 240:
3614 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
3615 * framebuffer is bound to target. In this case querying pname
3616 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
3617 * queries will generate an INVALID_OPERATION error."
3619 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
3620 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
3622 if (_mesa_is_winsys_fbo(buffer
)) {
3623 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
3626 * "If the framebuffer currently bound to target is zero, then
3627 * INVALID_OPERATION is generated."
3629 * The EXT_framebuffer_object spec has the same wording, and the
3630 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
3633 if ((!_mesa_is_desktop_gl(ctx
) ||
3634 !ctx
->Extensions
.ARB_framebuffer_object
)
3635 && !_mesa_is_gles3(ctx
)) {
3636 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3637 "%s(window-system framebuffer)", caller
);
3641 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
3642 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
3643 _mesa_error(ctx
, GL_INVALID_ENUM
,
3644 "%s(invalid attachment %s)", caller
,
3645 _mesa_enum_to_string(attachment
));
3649 /* The specs are not clear about how to handle
3650 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
3651 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
3654 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
3655 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
3657 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
3658 _mesa_error(ctx
, GL_INVALID_ENUM
,
3659 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
3660 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
3661 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
3665 /* the default / window-system FBO */
3666 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
3669 /* user-created framebuffer FBO */
3670 att
= get_attachment(ctx
, buffer
, attachment
);
3674 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3675 _mesa_enum_to_string(attachment
));
3679 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3680 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
3681 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
3682 /* This behavior is first specified in OpenGL 4.4 specification.
3684 * From the OpenGL 4.4 spec page 275:
3685 * "This query cannot be performed for a combined depth+stencil
3686 * attachment, since it does not have a single format."
3688 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3689 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
3690 " is invalid for depth+stencil attachment)", caller
);
3693 /* the depth and stencil attachments must point to the same buffer */
3694 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
3695 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
3696 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
3697 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3698 "%s(DEPTH/STENCIL attachments differ)", caller
);
3703 /* No need to flush here */
3706 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
3707 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
3709 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3710 * either no framebuffer is bound to target; or the default framebuffer
3711 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
3712 * stencil bits, respectively, is zero."
3714 *params
= (_mesa_is_winsys_fbo(buffer
) &&
3715 ((attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) ||
3716 (att
->Type
!= GL_NONE
)))
3717 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
3719 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
3720 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
3721 *params
= att
->Renderbuffer
->Name
;
3723 else if (att
->Type
== GL_TEXTURE
) {
3724 *params
= att
->Texture
->Name
;
3727 assert(att
->Type
== GL_NONE
);
3728 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
3731 goto invalid_pname_enum
;
3735 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
3736 if (att
->Type
== GL_TEXTURE
) {
3737 *params
= att
->TextureLevel
;
3739 else if (att
->Type
== GL_NONE
) {
3740 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3741 _mesa_enum_to_string(pname
));
3744 goto invalid_pname_enum
;
3747 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
3748 if (att
->Type
== GL_TEXTURE
) {
3749 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
3750 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
3756 else if (att
->Type
== GL_NONE
) {
3757 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3758 _mesa_enum_to_string(pname
));
3761 goto invalid_pname_enum
;
3764 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
3765 if (ctx
->API
== API_OPENGLES
) {
3766 goto invalid_pname_enum
;
3767 } else if (att
->Type
== GL_NONE
) {
3768 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3769 _mesa_enum_to_string(pname
));
3770 } else if (att
->Type
== GL_TEXTURE
) {
3771 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
3772 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
3773 *params
= att
->Zoffset
;
3780 goto invalid_pname_enum
;
3783 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
3784 if ((!_mesa_is_desktop_gl(ctx
) ||
3785 !ctx
->Extensions
.ARB_framebuffer_object
)
3786 && !_mesa_is_gles3(ctx
)) {
3787 goto invalid_pname_enum
;
3789 else if (att
->Type
== GL_NONE
) {
3790 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3791 _mesa_enum_to_string(pname
));
3794 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
3796 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
3799 /* According to ARB_framebuffer_sRGB, we should return LINEAR
3800 * if the sRGB conversion is unsupported. */
3801 *params
= GL_LINEAR
;
3805 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
3806 if ((ctx
->API
!= API_OPENGL_COMPAT
||
3807 !ctx
->Extensions
.ARB_framebuffer_object
)
3808 && ctx
->API
!= API_OPENGL_CORE
3809 && !_mesa_is_gles3(ctx
)) {
3810 goto invalid_pname_enum
;
3812 else if (att
->Type
== GL_NONE
) {
3813 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3814 _mesa_enum_to_string(pname
));
3817 mesa_format format
= att
->Renderbuffer
->Format
;
3819 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
3822 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
3823 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
3824 * generate an INVALID_OPERATION error.
3826 if (_mesa_is_gles3(ctx
) &&
3827 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3828 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3830 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
3831 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
3835 if (format
== MESA_FORMAT_S_UINT8
) {
3839 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
3840 /* depends on the attachment parameter */
3841 if (attachment
== GL_STENCIL_ATTACHMENT
) {
3849 *params
= _mesa_get_format_datatype(format
);
3853 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
3854 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
3855 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
3856 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
3857 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
3858 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
3859 if ((!_mesa_is_desktop_gl(ctx
) ||
3860 !ctx
->Extensions
.ARB_framebuffer_object
)
3861 && !_mesa_is_gles3(ctx
)) {
3862 goto invalid_pname_enum
;
3864 else if (att
->Type
== GL_NONE
) {
3865 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3866 _mesa_enum_to_string(pname
));
3868 else if (att
->Texture
) {
3869 const struct gl_texture_image
*texImage
=
3870 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
3873 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
3874 texImage
->TexFormat
);
3880 else if (att
->Renderbuffer
) {
3881 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
3882 att
->Renderbuffer
->Format
);
3885 _mesa_problem(ctx
, "%s: invalid FBO attachment structure", caller
);
3888 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
3889 if (!_mesa_has_geometry_shaders(ctx
)) {
3890 goto invalid_pname_enum
;
3891 } else if (att
->Type
== GL_TEXTURE
) {
3892 *params
= att
->Layered
;
3893 } else if (att
->Type
== GL_NONE
) {
3894 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3895 _mesa_enum_to_string(pname
));
3897 goto invalid_pname_enum
;
3901 goto invalid_pname_enum
;
3907 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
3908 _mesa_enum_to_string(pname
));
3914 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
3915 GLenum pname
, GLint
*params
)
3917 GET_CURRENT_CONTEXT(ctx
);
3918 struct gl_framebuffer
*buffer
;
3920 buffer
= get_framebuffer_target(ctx
, target
);
3922 _mesa_error(ctx
, GL_INVALID_ENUM
,
3923 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
3924 _mesa_enum_to_string(target
));
3928 _mesa_get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
3930 "glGetFramebufferAttachmentParameteriv");
3935 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
3937 GLenum pname
, GLint
*params
)
3939 GET_CURRENT_CONTEXT(ctx
);
3940 struct gl_framebuffer
*buffer
;
3943 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3944 "glGetNamedFramebufferAttachmentParameteriv");
3950 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
3951 * 4.5 core spec (30.10.2014, PDF page 314):
3952 * "If framebuffer is zero, then the default draw framebuffer is
3955 buffer
= ctx
->WinSysDrawBuffer
;
3958 _mesa_get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
3960 "glGetNamedFramebufferAttachmentParameteriv");
3965 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
3968 GET_CURRENT_CONTEXT(ctx
);
3969 struct gl_framebuffer
*fb
= NULL
;
3971 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
3972 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3973 "glNamedFramebufferParameteri("
3974 "ARB_framebuffer_no_attachments not implemented)");
3978 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3979 "glNamedFramebufferParameteri");
3982 framebuffer_parameteri(ctx
, fb
, pname
, param
,
3983 "glNamedFramebufferParameteriv");
3989 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
3992 GET_CURRENT_CONTEXT(ctx
);
3993 struct gl_framebuffer
*fb
;
3995 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
3996 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3997 "glNamedFramebufferParameteriv("
3998 "ARB_framebuffer_no_attachments not implemented)");
4003 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4004 "glGetNamedFramebufferParameteriv");
4006 fb
= ctx
->WinSysDrawBuffer
;
4010 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4011 "glGetNamedFramebufferParameteriv");
4017 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4018 struct gl_framebuffer
*fb
,
4019 GLsizei numAttachments
,
4020 const GLenum
*attachments
, GLint x
, GLint y
,
4021 GLsizei width
, GLsizei height
, const char *name
)
4025 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4026 * Spec (2.2.2015, PDF page 522) says:
4027 * "An INVALID_VALUE error is generated if numAttachments, width, or
4028 * height is negative."
4030 if (numAttachments
< 0) {
4031 _mesa_error(ctx
, GL_INVALID_VALUE
,
4032 "%s(numAttachments < 0)", name
);
4037 _mesa_error(ctx
, GL_INVALID_VALUE
,
4038 "%s(width < 0)", name
);
4043 _mesa_error(ctx
, GL_INVALID_VALUE
,
4044 "%s(height < 0)", name
);
4048 /* The GL_ARB_invalidate_subdata spec says:
4050 * "If an attachment is specified that does not exist in the
4051 * framebuffer bound to <target>, it is ignored."
4055 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4056 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4057 * INVALID_OPERATION is generated."
4059 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4060 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4061 * set of retrictions).
4063 for (i
= 0; i
< numAttachments
; i
++) {
4064 if (_mesa_is_winsys_fbo(fb
)) {
4065 switch (attachments
[i
]) {
4071 /* Accumulation buffers and auxilary buffers were removed in
4072 * OpenGL 3.1, and they never existed in OpenGL ES.
4074 if (ctx
->API
!= API_OPENGL_COMPAT
)
4084 case GL_FRONT_RIGHT
:
4085 if (!_mesa_is_desktop_gl(ctx
))
4092 switch (attachments
[i
]) {
4093 case GL_DEPTH_ATTACHMENT
:
4094 case GL_STENCIL_ATTACHMENT
:
4096 case GL_DEPTH_STENCIL_ATTACHMENT
:
4097 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4098 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4099 * extension does not make this attachment point valid on ES 2.0.
4101 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4104 case GL_COLOR_ATTACHMENT0
:
4105 case GL_COLOR_ATTACHMENT1
:
4106 case GL_COLOR_ATTACHMENT2
:
4107 case GL_COLOR_ATTACHMENT3
:
4108 case GL_COLOR_ATTACHMENT4
:
4109 case GL_COLOR_ATTACHMENT5
:
4110 case GL_COLOR_ATTACHMENT6
:
4111 case GL_COLOR_ATTACHMENT7
:
4112 case GL_COLOR_ATTACHMENT8
:
4113 case GL_COLOR_ATTACHMENT9
:
4114 case GL_COLOR_ATTACHMENT10
:
4115 case GL_COLOR_ATTACHMENT11
:
4116 case GL_COLOR_ATTACHMENT12
:
4117 case GL_COLOR_ATTACHMENT13
:
4118 case GL_COLOR_ATTACHMENT14
:
4119 case GL_COLOR_ATTACHMENT15
: {
4120 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4121 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4122 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4123 "%s(attachment >= max. color attachments)", name
);
4134 /* We don't actually do anything for this yet. Just return after
4135 * validating the parameters and generating the required errors.
4140 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4141 _mesa_enum_to_string(attachments
[i
]));
4147 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4148 const GLenum
*attachments
, GLint x
, GLint y
,
4149 GLsizei width
, GLsizei height
)
4151 struct gl_framebuffer
*fb
;
4152 GET_CURRENT_CONTEXT(ctx
);
4154 fb
= get_framebuffer_target(ctx
, target
);
4156 _mesa_error(ctx
, GL_INVALID_ENUM
,
4157 "glInvalidateSubFramebuffer(invalid target %s)",
4158 _mesa_enum_to_string(target
));
4162 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4163 x
, y
, width
, height
,
4164 "glInvalidateSubFramebuffer");
4169 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4170 GLsizei numAttachments
,
4171 const GLenum
*attachments
,
4173 GLsizei width
, GLsizei height
)
4175 struct gl_framebuffer
*fb
;
4176 GET_CURRENT_CONTEXT(ctx
);
4178 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4179 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4180 * default draw framebuffer is affected."
4183 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4184 "glInvalidateNamedFramebufferSubData");
4189 fb
= ctx
->WinSysDrawBuffer
;
4191 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4192 x
, y
, width
, height
,
4193 "glInvalidateNamedFramebufferSubData");
4198 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4199 const GLenum
*attachments
)
4201 struct gl_framebuffer
*fb
;
4202 GET_CURRENT_CONTEXT(ctx
);
4204 fb
= get_framebuffer_target(ctx
, target
);
4206 _mesa_error(ctx
, GL_INVALID_ENUM
,
4207 "glInvalidateFramebuffer(invalid target %s)",
4208 _mesa_enum_to_string(target
));
4212 /* The GL_ARB_invalidate_subdata spec says:
4216 * void InvalidateFramebuffer(enum target,
4217 * sizei numAttachments,
4218 * const enum *attachments);
4220 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4221 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4222 * <MAX_VIEWPORT_DIMS[1]> respectively."
4224 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4226 ctx
->Const
.MaxViewportWidth
,
4227 ctx
->Const
.MaxViewportHeight
,
4228 "glInvalidateFramebuffer");
4233 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4234 GLsizei numAttachments
,
4235 const GLenum
*attachments
)
4237 struct gl_framebuffer
*fb
;
4238 GET_CURRENT_CONTEXT(ctx
);
4240 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4241 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4242 * default draw framebuffer is affected."
4245 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4246 "glInvalidateNamedFramebufferData");
4251 fb
= ctx
->WinSysDrawBuffer
;
4253 /* The GL_ARB_invalidate_subdata spec says:
4257 * void InvalidateFramebuffer(enum target,
4258 * sizei numAttachments,
4259 * const enum *attachments);
4261 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4262 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4263 * <MAX_VIEWPORT_DIMS[1]> respectively."
4265 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4267 ctx
->Const
.MaxViewportWidth
,
4268 ctx
->Const
.MaxViewportHeight
,
4269 "glInvalidateNamedFramebufferData");
4274 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4275 const GLenum
*attachments
)
4277 struct gl_framebuffer
*fb
;
4280 GET_CURRENT_CONTEXT(ctx
);
4282 fb
= get_framebuffer_target(ctx
, target
);
4284 _mesa_error(ctx
, GL_INVALID_ENUM
,
4285 "glDiscardFramebufferEXT(target %s)",
4286 _mesa_enum_to_string(target
));
4290 if (numAttachments
< 0) {
4291 _mesa_error(ctx
, GL_INVALID_VALUE
,
4292 "glDiscardFramebufferEXT(numAttachments < 0)");
4296 for (i
= 0; i
< numAttachments
; i
++) {
4297 switch (attachments
[i
]) {
4301 if (_mesa_is_user_fbo(fb
))
4304 case GL_COLOR_ATTACHMENT0
:
4305 case GL_DEPTH_ATTACHMENT
:
4306 case GL_STENCIL_ATTACHMENT
:
4307 if (_mesa_is_winsys_fbo(fb
))
4315 if (ctx
->Driver
.DiscardFramebuffer
)
4316 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4321 _mesa_error(ctx
, GL_INVALID_ENUM
,
4322 "glDiscardFramebufferEXT(attachment %s)",
4323 _mesa_enum_to_string(attachments
[i
]));