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
->CubeMapFace
= src_att
->CubeMapFace
;
2854 dst_att
->Zoffset
= src_att
->Zoffset
;
2855 dst_att
->Layered
= src_att
->Layered
;
2860 * Common code called by gl*FramebufferTexture*() to retrieve the correct
2861 * texture object pointer.
2863 * \param texObj where the pointer to the texture object is returned. Note
2864 * that a successful call may return texObj = NULL.
2866 * \return true if no errors, false if errors
2869 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
,
2870 bool layered
, const char *caller
,
2871 struct gl_texture_object
**texObj
)
2873 *texObj
= NULL
; /* This will get returned if texture = 0. */
2878 *texObj
= _mesa_lookup_texture(ctx
, texture
);
2879 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
2880 /* Can't render to a non-existent texture object.
2882 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
2883 * Managing Framebuffer Objects specifies a different error
2884 * depending upon the calling function (PDF pages 325-328).
2885 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
2886 * value, while the other commands throw invalid operation (where
2887 * layered = GL_FALSE).
2889 const GLenum error
= layered
? GL_INVALID_VALUE
:
2890 GL_INVALID_OPERATION
;
2891 _mesa_error(ctx
, error
,
2892 "%s(non-existent texture %u)", caller
, texture
);
2901 * Common code called by gl*FramebufferTexture() to verify the texture target
2902 * and decide whether or not the attachment should truly be considered
2905 * \param layered true if attachment should be considered layered, false if
2908 * \return true if no errors, false if errors
2911 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
2912 const char *caller
, GLboolean
*layered
)
2918 case GL_TEXTURE_1D_ARRAY_EXT
:
2919 case GL_TEXTURE_2D_ARRAY_EXT
:
2920 case GL_TEXTURE_CUBE_MAP
:
2921 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2922 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2926 case GL_TEXTURE_RECTANGLE
:
2927 case GL_TEXTURE_2D_MULTISAMPLE
:
2928 /* These texture types are valid to pass to
2929 * glFramebufferTexture(), but since they aren't layered, it
2930 * is equivalent to calling glFramebufferTexture{1D,2D}().
2932 *layered
= GL_FALSE
;
2936 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2937 "%s(invalid texture target %s)", caller
,
2938 _mesa_enum_to_string(target
));
2944 * Common code called by gl*FramebufferTextureLayer() to verify the texture
2947 * \return true if no errors, false if errors
2950 check_texture_target(struct gl_context
*ctx
, GLenum target
,
2953 /* We're being called by glFramebufferTextureLayer().
2954 * The only legal texture types for that function are 3D,
2955 * cube-map, and 1D/2D/cube-map array textures.
2957 * We don't need to check for GL_ARB_texture_cube_map_array because the
2958 * application wouldn't have been able to create a texture with a
2959 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
2963 case GL_TEXTURE_1D_ARRAY
:
2964 case GL_TEXTURE_2D_ARRAY
:
2965 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2966 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2968 case GL_TEXTURE_CUBE_MAP
:
2969 /* We don't need to check the extension (GL_ARB_direct_state_access) or
2970 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
2971 * enabled in core profile. This can be called from
2972 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
2973 * so we do have to check the profile.
2975 return ctx
->API
== API_OPENGL_CORE
;
2978 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2979 "%s(invalid texture target %s)", caller
,
2980 _mesa_enum_to_string(target
));
2986 * Common code called by glFramebufferTexture*D() to verify the texture
2989 * \return true if no errors, false if errors
2992 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
2993 GLenum textarget
, const char *caller
)
2997 switch (textarget
) {
3001 case GL_TEXTURE_1D_ARRAY
:
3002 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3007 case GL_TEXTURE_2D_ARRAY
:
3008 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3009 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3011 case GL_TEXTURE_2D_MULTISAMPLE
:
3012 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3014 !ctx
->Extensions
.ARB_texture_multisample
||
3015 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3017 case GL_TEXTURE_RECTANGLE
:
3018 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3019 !ctx
->Extensions
.NV_texture_rectangle
;
3021 case GL_TEXTURE_CUBE_MAP
:
3022 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3025 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3026 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3027 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3028 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3029 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3030 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3031 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3037 _mesa_error(ctx
, GL_INVALID_ENUM
,
3038 "%s(unknown textarget 0x%x)", caller
, textarget
);
3043 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3044 "%s(invalid textarget %s)",
3045 caller
, _mesa_enum_to_string(textarget
));
3049 /* Make sure textarget is consistent with the texture's type */
3050 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3051 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3054 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3055 "%s(mismatched texture target)", caller
);
3064 * Common code called by gl*FramebufferTextureLayer() and
3065 * glFramebufferTexture3D() to validate the layer.
3067 * \return true if no errors, false if errors
3070 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3073 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3076 * "An INVALID_VALUE error is generated if texture is non-zero
3077 * and layer is negative."
3080 _mesa_error(ctx
, GL_INVALID_VALUE
,
3081 "%s(layer %u < 0)", caller
, layer
);
3085 if (target
== GL_TEXTURE_3D
) {
3086 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3087 if (layer
>= maxSize
) {
3088 _mesa_error(ctx
, GL_INVALID_VALUE
,
3089 "%s(invalid layer %u)", caller
, layer
);
3093 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3094 (target
== GL_TEXTURE_2D_ARRAY
) ||
3095 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3096 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3097 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3098 _mesa_error(ctx
, GL_INVALID_VALUE
,
3099 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3104 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3106 _mesa_error(ctx
, GL_INVALID_VALUE
,
3107 "%s(layer %u >= 6)", caller
, layer
);
3117 * Common code called by all gl*FramebufferTexture*() entry points to verify
3120 * \return true if no errors, false if errors
3123 check_level(struct gl_context
*ctx
, GLenum target
, GLint level
,
3127 (level
>= _mesa_max_texture_levels(ctx
, target
))) {
3128 _mesa_error(ctx
, GL_INVALID_VALUE
,
3129 "%s(invalid level %d)", caller
, level
);
3138 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3140 struct gl_texture_object
*texObj
, GLenum textarget
,
3141 GLint level
, GLuint layer
, GLboolean layered
,
3144 struct gl_renderbuffer_attachment
*att
;
3146 /* The window-system framebuffer object is immutable */
3147 if (_mesa_is_winsys_fbo(fb
)) {
3148 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3153 /* Not a hash lookup, so we can afford to get the attachment here. */
3154 att
= get_attachment(ctx
, fb
, attachment
);
3156 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3157 _mesa_enum_to_string(attachment
));
3161 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3163 mtx_lock(&fb
->Mutex
);
3165 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3166 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3167 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3168 _mesa_tex_target_to_face(textarget
) ==
3169 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3170 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3171 /* The texture object is already attached to the stencil attachment
3172 * point. Don't create a new renderbuffer; just reuse the stencil
3173 * attachment's. This is required to prevent a GL error in
3174 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3176 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3178 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3179 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3180 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3181 _mesa_tex_target_to_face(textarget
) ==
3182 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3183 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3184 /* As above, but with depth and stencil transposed. */
3185 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3188 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3189 level
, layer
, layered
);
3191 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3192 /* Above we created a new renderbuffer and attached it to the
3193 * depth attachment point. Now attach it to the stencil attachment
3196 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3197 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3202 /* Set the render-to-texture flag. We'll check this flag in
3203 * glTexImage() and friends to determine if we need to revalidate
3204 * any FBOs that might be rendering into this texture.
3205 * This flag never gets cleared since it's non-trivial to determine
3206 * when all FBOs might be done rendering to this texture. That's OK
3207 * though since it's uncommon to render to a texture then repeatedly
3208 * call glTexImage() to change images in the texture.
3210 texObj
->_RenderToTexture
= GL_TRUE
;
3213 remove_attachment(ctx
, att
);
3214 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3215 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3216 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3220 invalidate_framebuffer(fb
);
3222 mtx_unlock(&fb
->Mutex
);
3227 framebuffer_texture_with_dims(int dims
, GLenum target
,
3228 GLenum attachment
, GLenum textarget
,
3229 GLuint texture
, GLint level
, GLint layer
,
3232 GET_CURRENT_CONTEXT(ctx
);
3233 struct gl_framebuffer
*fb
;
3234 struct gl_texture_object
*texObj
;
3236 /* Get the framebuffer object */
3237 fb
= get_framebuffer_target(ctx
, target
);
3239 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3240 _mesa_enum_to_string(target
));
3244 /* Get the texture object */
3245 if (!get_texture_for_framebuffer(ctx
, texture
, false, caller
, &texObj
))
3249 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3252 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3255 if (!check_level(ctx
, textarget
, level
, caller
))
3259 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3260 layer
, GL_FALSE
, caller
);
3265 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3266 GLenum textarget
, GLuint texture
, GLint level
)
3268 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3269 level
, 0, "glFramebufferTexture1D");
3274 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3275 GLenum textarget
, GLuint texture
, GLint level
)
3277 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3278 level
, 0, "glFramebufferTexture2D");
3283 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3284 GLenum textarget
, GLuint texture
,
3285 GLint level
, GLint layer
)
3287 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3288 level
, layer
, "glFramebufferTexture3D");
3293 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3294 GLuint texture
, GLint level
, GLint layer
)
3296 GET_CURRENT_CONTEXT(ctx
);
3297 struct gl_framebuffer
*fb
;
3298 struct gl_texture_object
*texObj
;
3299 GLenum textarget
= 0;
3301 const char *func
= "glFramebufferTextureLayer";
3303 /* Get the framebuffer object */
3304 fb
= get_framebuffer_target(ctx
, target
);
3306 _mesa_error(ctx
, GL_INVALID_ENUM
,
3307 "glFramebufferTextureLayer(invalid target %s)",
3308 _mesa_enum_to_string(target
));
3312 /* Get the texture object */
3313 if (!get_texture_for_framebuffer(ctx
, texture
, false, func
, &texObj
))
3317 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3320 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3323 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3326 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3327 assert(layer
>= 0 && layer
< 6);
3328 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3333 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3334 layer
, GL_FALSE
, func
);
3339 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3340 GLuint texture
, GLint level
, GLint layer
)
3342 GET_CURRENT_CONTEXT(ctx
);
3343 struct gl_framebuffer
*fb
;
3344 struct gl_texture_object
*texObj
;
3345 GLenum textarget
= 0;
3347 const char *func
= "glNamedFramebufferTextureLayer";
3349 /* Get the framebuffer object */
3350 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3354 /* Get the texture object */
3355 if (!get_texture_for_framebuffer(ctx
, texture
, false, func
, &texObj
))
3359 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3362 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3365 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3368 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3369 assert(layer
>= 0 && layer
< 6);
3370 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3375 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3376 layer
, GL_FALSE
, func
);
3381 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3382 GLuint texture
, GLint level
)
3384 GET_CURRENT_CONTEXT(ctx
);
3385 struct gl_framebuffer
*fb
;
3386 struct gl_texture_object
*texObj
;
3387 GLboolean layered
= GL_FALSE
;
3389 const char *func
= "FramebufferTexture";
3391 if (!_mesa_has_geometry_shaders(ctx
)) {
3392 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3393 "unsupported function (glFramebufferTexture) called");
3397 /* Get the framebuffer object */
3398 fb
= get_framebuffer_target(ctx
, target
);
3400 _mesa_error(ctx
, GL_INVALID_ENUM
,
3401 "glFramebufferTexture(invalid target %s)",
3402 _mesa_enum_to_string(target
));
3406 /* Get the texture object */
3407 if (!get_texture_for_framebuffer(ctx
, texture
, true, func
, &texObj
))
3411 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
, &layered
))
3414 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3418 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, 0, level
,
3424 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3425 GLuint texture
, GLint level
)
3427 GET_CURRENT_CONTEXT(ctx
);
3428 struct gl_framebuffer
*fb
;
3429 struct gl_texture_object
*texObj
;
3430 GLboolean layered
= GL_FALSE
;
3432 const char *func
= "glNamedFramebufferTexture";
3434 if (!_mesa_has_geometry_shaders(ctx
)) {
3435 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3436 "unsupported function (glNamedFramebufferTexture) called");
3440 /* Get the framebuffer object */
3441 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3445 /* Get the texture object */
3446 if (!get_texture_for_framebuffer(ctx
, texture
, true, func
, &texObj
))
3450 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3454 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3458 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, 0, level
,
3464 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3465 struct gl_framebuffer
*fb
,
3467 struct gl_renderbuffer
*rb
)
3469 assert(!_mesa_is_winsys_fbo(fb
));
3471 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3473 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3474 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3476 /* Some subsequent GL commands may depend on the framebuffer's visual
3477 * after the binding is updated. Update visual info now.
3479 _mesa_update_framebuffer_visual(ctx
, fb
);
3483 framebuffer_renderbuffer(struct gl_context
*ctx
,
3484 struct gl_framebuffer
*fb
,
3486 struct gl_renderbuffer
*rb
,
3489 struct gl_renderbuffer_attachment
*att
;
3491 if (_mesa_is_winsys_fbo(fb
)) {
3492 /* Can't attach new renderbuffers to a window system framebuffer */
3493 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3494 "%s(window-system framebuffer)", func
);
3498 att
= get_attachment(ctx
, fb
, attachment
);
3500 _mesa_error(ctx
, GL_INVALID_ENUM
,
3501 "%s(invalid attachment %s)", func
,
3502 _mesa_enum_to_string(attachment
));
3506 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3507 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3508 /* make sure the renderbuffer is a depth/stencil format */
3509 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3510 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3511 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3512 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3517 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3521 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3522 GLenum renderbuffertarget
,
3523 GLuint renderbuffer
)
3525 struct gl_framebuffer
*fb
;
3526 struct gl_renderbuffer
*rb
;
3527 GET_CURRENT_CONTEXT(ctx
);
3529 fb
= get_framebuffer_target(ctx
, target
);
3531 _mesa_error(ctx
, GL_INVALID_ENUM
,
3532 "glFramebufferRenderbuffer(invalid target %s)",
3533 _mesa_enum_to_string(target
));
3537 if (renderbuffertarget
!= GL_RENDERBUFFER
) {
3538 _mesa_error(ctx
, GL_INVALID_ENUM
,
3539 "glFramebufferRenderbuffer(renderbuffertarget is not "
3540 "GL_RENDERBUFFER)");
3545 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
,
3546 "glFramebufferRenderbuffer");
3551 /* remove renderbuffer attachment */
3555 framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
,
3556 "glFramebufferRenderbuffer");
3561 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
3562 GLenum renderbuffertarget
,
3563 GLuint renderbuffer
)
3565 struct gl_framebuffer
*fb
;
3566 struct gl_renderbuffer
*rb
;
3567 GET_CURRENT_CONTEXT(ctx
);
3569 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3570 "glNamedFramebufferRenderbuffer");
3574 if (renderbuffertarget
!= GL_RENDERBUFFER
) {
3575 _mesa_error(ctx
, GL_INVALID_ENUM
,
3576 "glNamedFramebufferRenderbuffer(renderbuffertarget is not "
3577 "GL_RENDERBUFFER)");
3582 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
,
3583 "glNamedFramebufferRenderbuffer");
3588 /* remove renderbuffer attachment */
3592 framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
,
3593 "glNamedFramebufferRenderbuffer");
3598 _mesa_get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
3599 struct gl_framebuffer
*buffer
,
3600 GLenum attachment
, GLenum pname
,
3601 GLint
*params
, const char *caller
)
3603 const struct gl_renderbuffer_attachment
*att
;
3606 /* The error code for an attachment type of GL_NONE differs between APIs.
3608 * From the ES 2.0.25 specification, page 127:
3609 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3610 * querying any other pname will generate INVALID_ENUM."
3612 * From the OpenGL 3.0 specification, page 337, or identically,
3613 * the OpenGL ES 3.0.4 specification, page 240:
3615 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
3616 * framebuffer is bound to target. In this case querying pname
3617 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
3618 * queries will generate an INVALID_OPERATION error."
3620 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
3621 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
3623 if (_mesa_is_winsys_fbo(buffer
)) {
3624 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
3627 * "If the framebuffer currently bound to target is zero, then
3628 * INVALID_OPERATION is generated."
3630 * The EXT_framebuffer_object spec has the same wording, and the
3631 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
3634 if ((!_mesa_is_desktop_gl(ctx
) ||
3635 !ctx
->Extensions
.ARB_framebuffer_object
)
3636 && !_mesa_is_gles3(ctx
)) {
3637 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3638 "%s(window-system framebuffer)", caller
);
3642 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
3643 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
3644 _mesa_error(ctx
, GL_INVALID_ENUM
,
3645 "%s(invalid attachment %s)", caller
,
3646 _mesa_enum_to_string(attachment
));
3650 /* The specs are not clear about how to handle
3651 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
3652 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
3655 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
3656 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
3658 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
3659 _mesa_error(ctx
, GL_INVALID_ENUM
,
3660 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
3661 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
3662 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
3666 /* the default / window-system FBO */
3667 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
3670 /* user-created framebuffer FBO */
3671 att
= get_attachment(ctx
, buffer
, attachment
);
3675 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3676 _mesa_enum_to_string(attachment
));
3680 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3681 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
3682 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
3683 /* This behavior is first specified in OpenGL 4.4 specification.
3685 * From the OpenGL 4.4 spec page 275:
3686 * "This query cannot be performed for a combined depth+stencil
3687 * attachment, since it does not have a single format."
3689 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3690 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
3691 " is invalid for depth+stencil attachment)", caller
);
3694 /* the depth and stencil attachments must point to the same buffer */
3695 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
3696 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
3697 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
3698 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3699 "%s(DEPTH/STENCIL attachments differ)", caller
);
3704 /* No need to flush here */
3707 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
3708 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
3710 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3711 * either no framebuffer is bound to target; or the default framebuffer
3712 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
3713 * stencil bits, respectively, is zero."
3715 *params
= (_mesa_is_winsys_fbo(buffer
) &&
3716 ((attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) ||
3717 (att
->Type
!= GL_NONE
)))
3718 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
3720 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
3721 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
3722 *params
= att
->Renderbuffer
->Name
;
3724 else if (att
->Type
== GL_TEXTURE
) {
3725 *params
= att
->Texture
->Name
;
3728 assert(att
->Type
== GL_NONE
);
3729 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
3732 goto invalid_pname_enum
;
3736 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
3737 if (att
->Type
== GL_TEXTURE
) {
3738 *params
= att
->TextureLevel
;
3740 else if (att
->Type
== GL_NONE
) {
3741 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3742 _mesa_enum_to_string(pname
));
3745 goto invalid_pname_enum
;
3748 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
3749 if (att
->Type
== GL_TEXTURE
) {
3750 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
3751 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
3757 else if (att
->Type
== GL_NONE
) {
3758 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3759 _mesa_enum_to_string(pname
));
3762 goto invalid_pname_enum
;
3765 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
3766 if (ctx
->API
== API_OPENGLES
) {
3767 goto invalid_pname_enum
;
3768 } else if (att
->Type
== GL_NONE
) {
3769 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3770 _mesa_enum_to_string(pname
));
3771 } else if (att
->Type
== GL_TEXTURE
) {
3772 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
3773 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
3774 *params
= att
->Zoffset
;
3781 goto invalid_pname_enum
;
3784 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
3785 if ((!_mesa_is_desktop_gl(ctx
) ||
3786 !ctx
->Extensions
.ARB_framebuffer_object
)
3787 && !_mesa_is_gles3(ctx
)) {
3788 goto invalid_pname_enum
;
3790 else if (att
->Type
== GL_NONE
) {
3791 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3792 _mesa_enum_to_string(pname
));
3795 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
3797 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
3800 /* According to ARB_framebuffer_sRGB, we should return LINEAR
3801 * if the sRGB conversion is unsupported. */
3802 *params
= GL_LINEAR
;
3806 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
3807 if ((ctx
->API
!= API_OPENGL_COMPAT
||
3808 !ctx
->Extensions
.ARB_framebuffer_object
)
3809 && ctx
->API
!= API_OPENGL_CORE
3810 && !_mesa_is_gles3(ctx
)) {
3811 goto invalid_pname_enum
;
3813 else if (att
->Type
== GL_NONE
) {
3814 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3815 _mesa_enum_to_string(pname
));
3818 mesa_format format
= att
->Renderbuffer
->Format
;
3820 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
3823 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
3824 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
3825 * generate an INVALID_OPERATION error.
3827 if (_mesa_is_gles3(ctx
) &&
3828 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3829 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3831 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
3832 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
3836 if (format
== MESA_FORMAT_S_UINT8
) {
3840 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
3841 /* depends on the attachment parameter */
3842 if (attachment
== GL_STENCIL_ATTACHMENT
) {
3850 *params
= _mesa_get_format_datatype(format
);
3854 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
3855 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
3856 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
3857 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
3858 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
3859 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
3860 if ((!_mesa_is_desktop_gl(ctx
) ||
3861 !ctx
->Extensions
.ARB_framebuffer_object
)
3862 && !_mesa_is_gles3(ctx
)) {
3863 goto invalid_pname_enum
;
3865 else if (att
->Type
== GL_NONE
) {
3866 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3867 _mesa_enum_to_string(pname
));
3869 else if (att
->Texture
) {
3870 const struct gl_texture_image
*texImage
=
3871 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
3874 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
3875 texImage
->TexFormat
);
3881 else if (att
->Renderbuffer
) {
3882 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
3883 att
->Renderbuffer
->Format
);
3886 _mesa_problem(ctx
, "%s: invalid FBO attachment structure", caller
);
3889 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
3890 if (!_mesa_has_geometry_shaders(ctx
)) {
3891 goto invalid_pname_enum
;
3892 } else if (att
->Type
== GL_TEXTURE
) {
3893 *params
= att
->Layered
;
3894 } else if (att
->Type
== GL_NONE
) {
3895 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3896 _mesa_enum_to_string(pname
));
3898 goto invalid_pname_enum
;
3902 goto invalid_pname_enum
;
3908 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
3909 _mesa_enum_to_string(pname
));
3915 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
3916 GLenum pname
, GLint
*params
)
3918 GET_CURRENT_CONTEXT(ctx
);
3919 struct gl_framebuffer
*buffer
;
3921 buffer
= get_framebuffer_target(ctx
, target
);
3923 _mesa_error(ctx
, GL_INVALID_ENUM
,
3924 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
3925 _mesa_enum_to_string(target
));
3929 _mesa_get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
3931 "glGetFramebufferAttachmentParameteriv");
3936 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
3938 GLenum pname
, GLint
*params
)
3940 GET_CURRENT_CONTEXT(ctx
);
3941 struct gl_framebuffer
*buffer
;
3944 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3945 "glGetNamedFramebufferAttachmentParameteriv");
3951 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
3952 * 4.5 core spec (30.10.2014, PDF page 314):
3953 * "If framebuffer is zero, then the default draw framebuffer is
3956 buffer
= ctx
->WinSysDrawBuffer
;
3959 _mesa_get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
3961 "glGetNamedFramebufferAttachmentParameteriv");
3966 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
3969 GET_CURRENT_CONTEXT(ctx
);
3970 struct gl_framebuffer
*fb
= NULL
;
3972 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
3973 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3974 "glNamedFramebufferParameteri("
3975 "ARB_framebuffer_no_attachments not implemented)");
3979 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3980 "glNamedFramebufferParameteri");
3983 framebuffer_parameteri(ctx
, fb
, pname
, param
,
3984 "glNamedFramebufferParameteriv");
3990 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
3993 GET_CURRENT_CONTEXT(ctx
);
3994 struct gl_framebuffer
*fb
;
3996 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
3997 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3998 "glNamedFramebufferParameteriv("
3999 "ARB_framebuffer_no_attachments not implemented)");
4004 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4005 "glGetNamedFramebufferParameteriv");
4007 fb
= ctx
->WinSysDrawBuffer
;
4011 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4012 "glGetNamedFramebufferParameteriv");
4018 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4019 struct gl_framebuffer
*fb
,
4020 GLsizei numAttachments
,
4021 const GLenum
*attachments
, GLint x
, GLint y
,
4022 GLsizei width
, GLsizei height
, const char *name
)
4026 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4027 * Spec (2.2.2015, PDF page 522) says:
4028 * "An INVALID_VALUE error is generated if numAttachments, width, or
4029 * height is negative."
4031 if (numAttachments
< 0) {
4032 _mesa_error(ctx
, GL_INVALID_VALUE
,
4033 "%s(numAttachments < 0)", name
);
4038 _mesa_error(ctx
, GL_INVALID_VALUE
,
4039 "%s(width < 0)", name
);
4044 _mesa_error(ctx
, GL_INVALID_VALUE
,
4045 "%s(height < 0)", name
);
4049 /* The GL_ARB_invalidate_subdata spec says:
4051 * "If an attachment is specified that does not exist in the
4052 * framebuffer bound to <target>, it is ignored."
4056 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4057 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4058 * INVALID_OPERATION is generated."
4060 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4061 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4062 * set of retrictions).
4064 for (i
= 0; i
< numAttachments
; i
++) {
4065 if (_mesa_is_winsys_fbo(fb
)) {
4066 switch (attachments
[i
]) {
4072 /* Accumulation buffers and auxilary buffers were removed in
4073 * OpenGL 3.1, and they never existed in OpenGL ES.
4075 if (ctx
->API
!= API_OPENGL_COMPAT
)
4085 case GL_FRONT_RIGHT
:
4086 if (!_mesa_is_desktop_gl(ctx
))
4093 switch (attachments
[i
]) {
4094 case GL_DEPTH_ATTACHMENT
:
4095 case GL_STENCIL_ATTACHMENT
:
4097 case GL_DEPTH_STENCIL_ATTACHMENT
:
4098 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4099 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4100 * extension does not make this attachment point valid on ES 2.0.
4102 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4105 case GL_COLOR_ATTACHMENT0
:
4106 case GL_COLOR_ATTACHMENT1
:
4107 case GL_COLOR_ATTACHMENT2
:
4108 case GL_COLOR_ATTACHMENT3
:
4109 case GL_COLOR_ATTACHMENT4
:
4110 case GL_COLOR_ATTACHMENT5
:
4111 case GL_COLOR_ATTACHMENT6
:
4112 case GL_COLOR_ATTACHMENT7
:
4113 case GL_COLOR_ATTACHMENT8
:
4114 case GL_COLOR_ATTACHMENT9
:
4115 case GL_COLOR_ATTACHMENT10
:
4116 case GL_COLOR_ATTACHMENT11
:
4117 case GL_COLOR_ATTACHMENT12
:
4118 case GL_COLOR_ATTACHMENT13
:
4119 case GL_COLOR_ATTACHMENT14
:
4120 case GL_COLOR_ATTACHMENT15
: {
4121 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4122 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4123 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4124 "%s(attachment >= max. color attachments)", name
);
4135 /* We don't actually do anything for this yet. Just return after
4136 * validating the parameters and generating the required errors.
4141 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4142 _mesa_enum_to_string(attachments
[i
]));
4148 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4149 const GLenum
*attachments
, GLint x
, GLint y
,
4150 GLsizei width
, GLsizei height
)
4152 struct gl_framebuffer
*fb
;
4153 GET_CURRENT_CONTEXT(ctx
);
4155 fb
= get_framebuffer_target(ctx
, target
);
4157 _mesa_error(ctx
, GL_INVALID_ENUM
,
4158 "glInvalidateSubFramebuffer(invalid target %s)",
4159 _mesa_enum_to_string(target
));
4163 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4164 x
, y
, width
, height
,
4165 "glInvalidateSubFramebuffer");
4170 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4171 GLsizei numAttachments
,
4172 const GLenum
*attachments
,
4174 GLsizei width
, GLsizei height
)
4176 struct gl_framebuffer
*fb
;
4177 GET_CURRENT_CONTEXT(ctx
);
4179 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4180 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4181 * default draw framebuffer is affected."
4184 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4185 "glInvalidateNamedFramebufferSubData");
4190 fb
= ctx
->WinSysDrawBuffer
;
4192 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4193 x
, y
, width
, height
,
4194 "glInvalidateNamedFramebufferSubData");
4199 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4200 const GLenum
*attachments
)
4202 struct gl_framebuffer
*fb
;
4203 GET_CURRENT_CONTEXT(ctx
);
4205 fb
= get_framebuffer_target(ctx
, target
);
4207 _mesa_error(ctx
, GL_INVALID_ENUM
,
4208 "glInvalidateFramebuffer(invalid target %s)",
4209 _mesa_enum_to_string(target
));
4213 /* The GL_ARB_invalidate_subdata spec says:
4217 * void InvalidateFramebuffer(enum target,
4218 * sizei numAttachments,
4219 * const enum *attachments);
4221 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4222 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4223 * <MAX_VIEWPORT_DIMS[1]> respectively."
4225 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4227 ctx
->Const
.MaxViewportWidth
,
4228 ctx
->Const
.MaxViewportHeight
,
4229 "glInvalidateFramebuffer");
4234 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4235 GLsizei numAttachments
,
4236 const GLenum
*attachments
)
4238 struct gl_framebuffer
*fb
;
4239 GET_CURRENT_CONTEXT(ctx
);
4241 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4242 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4243 * default draw framebuffer is affected."
4246 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4247 "glInvalidateNamedFramebufferData");
4252 fb
= ctx
->WinSysDrawBuffer
;
4254 /* The GL_ARB_invalidate_subdata spec says:
4258 * void InvalidateFramebuffer(enum target,
4259 * sizei numAttachments,
4260 * const enum *attachments);
4262 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4263 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4264 * <MAX_VIEWPORT_DIMS[1]> respectively."
4266 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4268 ctx
->Const
.MaxViewportWidth
,
4269 ctx
->Const
.MaxViewportHeight
,
4270 "glInvalidateNamedFramebufferData");
4275 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4276 const GLenum
*attachments
)
4278 struct gl_framebuffer
*fb
;
4281 GET_CURRENT_CONTEXT(ctx
);
4283 fb
= get_framebuffer_target(ctx
, target
);
4285 _mesa_error(ctx
, GL_INVALID_ENUM
,
4286 "glDiscardFramebufferEXT(target %s)",
4287 _mesa_enum_to_string(target
));
4291 if (numAttachments
< 0) {
4292 _mesa_error(ctx
, GL_INVALID_VALUE
,
4293 "glDiscardFramebufferEXT(numAttachments < 0)");
4297 for (i
= 0; i
< numAttachments
; i
++) {
4298 switch (attachments
[i
]) {
4302 if (_mesa_is_user_fbo(fb
))
4305 case GL_COLOR_ATTACHMENT0
:
4306 case GL_DEPTH_ATTACHMENT
:
4307 case GL_STENCIL_ATTACHMENT
:
4308 if (_mesa_is_winsys_fbo(fb
))
4316 if (ctx
->Driver
.DiscardFramebuffer
)
4317 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4322 _mesa_error(ctx
, GL_INVALID_ENUM
,
4323 "glDiscardFramebufferEXT(attachment %s)",
4324 _mesa_enum_to_string(attachments
[i
]));