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 simple_mtx_init(&DummyFramebuffer
.Mutex
, mtx_plain
);
93 simple_mtx_init(&DummyRenderbuffer
.Mutex
, mtx_plain
);
94 simple_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.
225 * Returns if the attachment is a GL_COLOR_ATTACHMENTm_EXT on
226 * is_color_attachment, because several callers would return different errors
227 * if they don't find the attachment.
229 static struct gl_renderbuffer_attachment
*
230 get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
231 GLenum attachment
, bool *is_color_attachment
)
235 assert(_mesa_is_user_fbo(fb
));
237 if (is_color_attachment
)
238 *is_color_attachment
= false;
240 switch (attachment
) {
241 case GL_COLOR_ATTACHMENT0_EXT
:
242 case GL_COLOR_ATTACHMENT1_EXT
:
243 case GL_COLOR_ATTACHMENT2_EXT
:
244 case GL_COLOR_ATTACHMENT3_EXT
:
245 case GL_COLOR_ATTACHMENT4_EXT
:
246 case GL_COLOR_ATTACHMENT5_EXT
:
247 case GL_COLOR_ATTACHMENT6_EXT
:
248 case GL_COLOR_ATTACHMENT7_EXT
:
249 case GL_COLOR_ATTACHMENT8_EXT
:
250 case GL_COLOR_ATTACHMENT9_EXT
:
251 case GL_COLOR_ATTACHMENT10_EXT
:
252 case GL_COLOR_ATTACHMENT11_EXT
:
253 case GL_COLOR_ATTACHMENT12_EXT
:
254 case GL_COLOR_ATTACHMENT13_EXT
:
255 case GL_COLOR_ATTACHMENT14_EXT
:
256 case GL_COLOR_ATTACHMENT15_EXT
:
257 if (is_color_attachment
)
258 *is_color_attachment
= true;
259 /* Only OpenGL ES 1.x forbids color attachments other than
260 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
263 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
264 if (i
>= ctx
->Const
.MaxColorAttachments
265 || (i
> 0 && ctx
->API
== API_OPENGLES
)) {
268 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
269 case GL_DEPTH_STENCIL_ATTACHMENT
:
270 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
273 case GL_DEPTH_ATTACHMENT_EXT
:
274 return &fb
->Attachment
[BUFFER_DEPTH
];
275 case GL_STENCIL_ATTACHMENT_EXT
:
276 return &fb
->Attachment
[BUFFER_STENCIL
];
284 * As above, but only used for getting attachments of the default /
285 * window-system framebuffer (not user-created framebuffer objects).
287 static struct gl_renderbuffer_attachment
*
288 get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
291 assert(_mesa_is_winsys_fbo(fb
));
293 if (_mesa_is_gles3(ctx
)) {
294 assert(attachment
== GL_BACK
||
295 attachment
== GL_DEPTH
||
296 attachment
== GL_STENCIL
);
297 switch (attachment
) {
299 /* Since there is no stereo rendering in ES 3.0, only return the
302 if (ctx
->DrawBuffer
->Visual
.doubleBufferMode
)
303 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
304 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
306 return &fb
->Attachment
[BUFFER_DEPTH
];
308 return &fb
->Attachment
[BUFFER_STENCIL
];
312 switch (attachment
) {
314 /* Front buffers can be allocated on the first use, but
315 * glGetFramebufferAttachmentParameteriv must work even if that
316 * allocation hasn't happened yet. In such case, use the back buffer,
317 * which should be the same.
319 if (fb
->Attachment
[BUFFER_FRONT_LEFT
].Type
== GL_NONE
)
320 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
322 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
325 if (fb
->Attachment
[BUFFER_FRONT_RIGHT
].Type
== GL_NONE
)
326 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
328 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
330 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
332 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
334 /* The ARB_ES3_1_compatibility spec says:
336 * "Since this command can only query a single framebuffer
337 * attachment, BACK is equivalent to BACK_LEFT."
339 if (ctx
->Extensions
.ARB_ES3_1_compatibility
)
340 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
343 if (fb
->Visual
.numAuxBuffers
== 1) {
344 return &fb
->Attachment
[BUFFER_AUX0
];
348 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
350 * "If the default framebuffer is bound to target, then attachment must
351 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
352 * identifying a color buffer; DEPTH, identifying the depth buffer; or
353 * STENCIL, identifying the stencil buffer."
355 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
356 * language. However, revision #33 of the ARB_framebuffer_object spec
359 * "If the default framebuffer is bound to <target>, then <attachment>
360 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
361 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
362 * depth buffer, or the stencil buffer, and <pname> may be
363 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
364 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
366 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
367 * from glext.h, so shipping apps should not use those values.
369 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
370 * support queries of the window system FBO.
373 return &fb
->Attachment
[BUFFER_DEPTH
];
375 return &fb
->Attachment
[BUFFER_STENCIL
];
384 * Remove any texture or renderbuffer attached to the given attachment
385 * point. Update reference counts, etc.
388 remove_attachment(struct gl_context
*ctx
,
389 struct gl_renderbuffer_attachment
*att
)
391 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
393 /* tell driver that we're done rendering to this texture. */
394 if (rb
&& rb
->NeedsFinishRenderTexture
)
395 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
397 if (att
->Type
== GL_TEXTURE
) {
398 assert(att
->Texture
);
399 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
400 assert(!att
->Texture
);
402 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
403 assert(!att
->Texture
);
404 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
405 assert(!att
->Renderbuffer
);
408 att
->Complete
= GL_TRUE
;
412 * Verify a couple error conditions that will lead to an incomplete FBO and
413 * may cause problems for the driver's RenderTexture path.
416 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment
*att
)
418 const struct gl_texture_image
*const texImage
=
419 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
422 texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
425 if ((texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
426 && att
->Zoffset
>= texImage
->Height
)
427 || (texImage
->TexObject
->Target
!= GL_TEXTURE_1D_ARRAY
428 && att
->Zoffset
>= texImage
->Depth
))
435 * Create a renderbuffer which will be set up by the driver to wrap the
436 * texture image slice.
438 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
439 * to share most of their framebuffer rendering code between winsys,
440 * renderbuffer, and texture attachments.
442 * The allocated renderbuffer uses a non-zero Name so that drivers can check
443 * it for determining vertical orientation, but we use ~0 to make it fairly
444 * unambiguous with actual user (non-texture) renderbuffers.
447 _mesa_update_texture_renderbuffer(struct gl_context
*ctx
,
448 struct gl_framebuffer
*fb
,
449 struct gl_renderbuffer_attachment
*att
)
451 struct gl_texture_image
*texImage
;
452 struct gl_renderbuffer
*rb
;
454 texImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
456 rb
= att
->Renderbuffer
;
458 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
460 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
463 att
->Renderbuffer
= rb
;
465 /* This can't get called on a texture renderbuffer, so set it to NULL
466 * for clarity compared to user renderbuffers.
468 rb
->AllocStorage
= NULL
;
470 rb
->NeedsFinishRenderTexture
= ctx
->Driver
.FinishRenderTexture
!= NULL
;
476 rb
->_BaseFormat
= texImage
->_BaseFormat
;
477 rb
->Format
= texImage
->TexFormat
;
478 rb
->InternalFormat
= texImage
->InternalFormat
;
479 rb
->Width
= texImage
->Width2
;
480 rb
->Height
= texImage
->Height2
;
481 rb
->Depth
= texImage
->Depth2
;
482 rb
->NumSamples
= texImage
->NumSamples
;
483 rb
->TexImage
= texImage
;
485 if (driver_RenderTexture_is_safe(att
))
486 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
490 * Bind a texture object to an attachment point.
491 * The previous binding, if any, will be removed first.
494 set_texture_attachment(struct gl_context
*ctx
,
495 struct gl_framebuffer
*fb
,
496 struct gl_renderbuffer_attachment
*att
,
497 struct gl_texture_object
*texObj
,
498 GLenum texTarget
, GLuint level
, GLuint layer
,
501 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
503 if (rb
&& rb
->NeedsFinishRenderTexture
)
504 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
506 if (att
->Texture
== texObj
) {
507 /* re-attaching same texture */
508 assert(att
->Type
== GL_TEXTURE
);
512 remove_attachment(ctx
, att
);
513 att
->Type
= GL_TEXTURE
;
514 assert(!att
->Texture
);
515 _mesa_reference_texobj(&att
->Texture
, texObj
);
517 invalidate_framebuffer(fb
);
519 /* always update these fields */
520 att
->TextureLevel
= level
;
521 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
522 att
->Zoffset
= layer
;
523 att
->Layered
= layered
;
524 att
->Complete
= GL_FALSE
;
526 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
531 * Bind a renderbuffer to an attachment point.
532 * The previous binding, if any, will be removed first.
535 set_renderbuffer_attachment(struct gl_context
*ctx
,
536 struct gl_renderbuffer_attachment
*att
,
537 struct gl_renderbuffer
*rb
)
539 /* XXX check if re-doing same attachment, exit early */
540 remove_attachment(ctx
, att
);
541 att
->Type
= GL_RENDERBUFFER_EXT
;
542 att
->Texture
= NULL
; /* just to be safe */
543 att
->Layered
= GL_FALSE
;
544 att
->Complete
= GL_FALSE
;
545 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
550 * Fallback for ctx->Driver.FramebufferRenderbuffer()
551 * Attach a renderbuffer object to a framebuffer object.
554 _mesa_FramebufferRenderbuffer_sw(struct gl_context
*ctx
,
555 struct gl_framebuffer
*fb
,
557 struct gl_renderbuffer
*rb
)
559 struct gl_renderbuffer_attachment
*att
;
561 simple_mtx_lock(&fb
->Mutex
);
563 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
566 set_renderbuffer_attachment(ctx
, att
, rb
);
567 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
568 /* do stencil attachment here (depth already done above) */
569 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
571 set_renderbuffer_attachment(ctx
, att
, rb
);
573 rb
->AttachedAnytime
= GL_TRUE
;
576 remove_attachment(ctx
, att
);
577 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
578 /* detach stencil (depth was detached above) */
579 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
581 remove_attachment(ctx
, att
);
585 invalidate_framebuffer(fb
);
587 simple_mtx_unlock(&fb
->Mutex
);
592 * Fallback for ctx->Driver.ValidateFramebuffer()
593 * Check if the renderbuffer's formats are supported by the software
595 * Drivers should probably override this.
598 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
601 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
602 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
604 switch (rb
->_BaseFormat
) {
606 case GL_LUMINANCE_ALPHA
:
611 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
615 switch (rb
->Format
) {
616 /* XXX This list is likely incomplete. */
617 case MESA_FORMAT_R9G9B9E5_FLOAT
:
618 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
621 /* render buffer format is supported by software rendering */
630 * Return true if the framebuffer has a combined depth/stencil
631 * renderbuffer attached.
634 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
636 const struct gl_renderbuffer_attachment
*depth
=
637 &fb
->Attachment
[BUFFER_DEPTH
];
638 const struct gl_renderbuffer_attachment
*stencil
=
639 &fb
->Attachment
[BUFFER_STENCIL
];
641 if (depth
->Type
== stencil
->Type
) {
642 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
643 depth
->Renderbuffer
== stencil
->Renderbuffer
)
646 if (depth
->Type
== GL_TEXTURE
&&
647 depth
->Texture
== stencil
->Texture
)
659 att_incomplete(const char *msg
)
661 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
662 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
671 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
673 static GLuint msg_id
;
675 _mesa_gl_debug(ctx
, &msg_id
,
676 MESA_DEBUG_SOURCE_API
,
677 MESA_DEBUG_TYPE_OTHER
,
678 MESA_DEBUG_SEVERITY_MEDIUM
,
679 "FBO incomplete: %s [%d]\n", msg
, index
);
681 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
682 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
688 * Is the given base format a legal format for a color renderbuffer?
691 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
693 switch (baseFormat
) {
698 case GL_LUMINANCE_ALPHA
:
701 return ctx
->API
== API_OPENGL_COMPAT
&&
702 ctx
->Extensions
.ARB_framebuffer_object
;
705 return ctx
->Extensions
.ARB_texture_rg
;
713 * Is the given base format a legal format for a color renderbuffer?
716 is_format_color_renderable(const struct gl_context
*ctx
, mesa_format format
,
717 GLenum internalFormat
)
719 const GLenum baseFormat
=
720 _mesa_get_format_base_format(format
);
723 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
724 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
728 /* Reject additional cases for GLES */
729 switch (internalFormat
) {
750 if (internalFormat
!= GL_RGB10_A2
&&
751 (format
== MESA_FORMAT_B10G10R10A2_UNORM
||
752 format
== MESA_FORMAT_B10G10R10X2_UNORM
||
753 format
== MESA_FORMAT_R10G10B10A2_UNORM
||
754 format
== MESA_FORMAT_R10G10B10X2_UNORM
)) {
763 * Is the given base format a legal format for a depth/stencil renderbuffer?
766 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
768 switch (baseFormat
) {
769 case GL_DEPTH_COMPONENT
:
770 case GL_DEPTH_STENCIL_EXT
:
779 * Test if an attachment point is complete and update its Complete field.
780 * \param format if GL_COLOR, this is a color attachment point,
781 * if GL_DEPTH, this is a depth component attachment point,
782 * if GL_STENCIL, this is a stencil component attachment point.
785 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
786 struct gl_renderbuffer_attachment
*att
)
788 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
790 /* assume complete */
791 att
->Complete
= GL_TRUE
;
793 /* Look for reasons why the attachment might be incomplete */
794 if (att
->Type
== GL_TEXTURE
) {
795 const struct gl_texture_object
*texObj
= att
->Texture
;
796 const struct gl_texture_image
*texImage
;
800 att_incomplete("no texobj");
801 att
->Complete
= GL_FALSE
;
805 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
807 att_incomplete("no teximage");
808 att
->Complete
= GL_FALSE
;
811 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
812 att_incomplete("teximage width/height=0");
813 att
->Complete
= GL_FALSE
;
817 switch (texObj
->Target
) {
819 if (att
->Zoffset
>= texImage
->Depth
) {
820 att_incomplete("bad z offset");
821 att
->Complete
= GL_FALSE
;
825 case GL_TEXTURE_1D_ARRAY
:
826 if (att
->Zoffset
>= texImage
->Height
) {
827 att_incomplete("bad 1D-array layer");
828 att
->Complete
= GL_FALSE
;
832 case GL_TEXTURE_2D_ARRAY
:
833 if (att
->Zoffset
>= texImage
->Depth
) {
834 att_incomplete("bad 2D-array layer");
835 att
->Complete
= GL_FALSE
;
839 case GL_TEXTURE_CUBE_MAP_ARRAY
:
840 if (att
->Zoffset
>= texImage
->Depth
) {
841 att_incomplete("bad cube-array layer");
842 att
->Complete
= GL_FALSE
;
848 baseFormat
= texImage
->_BaseFormat
;
850 if (format
== GL_COLOR
) {
851 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
852 att_incomplete("bad format");
853 att
->Complete
= GL_FALSE
;
856 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
857 att_incomplete("compressed internalformat");
858 att
->Complete
= GL_FALSE
;
862 /* OES_texture_float allows creation and use of floating point
863 * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow
864 * these textures to be used as a render target, this is done via
865 * GL_EXT_color_buffer(_half)_float with set of new sized types.
867 if (_mesa_is_gles(ctx
) && (texObj
->_IsFloat
|| texObj
->_IsHalfFloat
)) {
868 att_incomplete("bad internal format");
869 att
->Complete
= GL_FALSE
;
873 else if (format
== GL_DEPTH
) {
874 if (baseFormat
== GL_DEPTH_COMPONENT
) {
877 else if (ctx
->Extensions
.ARB_depth_texture
&&
878 baseFormat
== GL_DEPTH_STENCIL
) {
882 att
->Complete
= GL_FALSE
;
883 att_incomplete("bad depth format");
888 assert(format
== GL_STENCIL
);
889 if (ctx
->Extensions
.ARB_depth_texture
&&
890 baseFormat
== GL_DEPTH_STENCIL
) {
892 } else if (ctx
->Extensions
.ARB_texture_stencil8
&&
893 baseFormat
== GL_STENCIL_INDEX
) {
896 /* no such thing as stencil-only textures */
897 att_incomplete("illegal stencil texture");
898 att
->Complete
= GL_FALSE
;
903 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
904 const GLenum baseFormat
= att
->Renderbuffer
->_BaseFormat
;
906 assert(att
->Renderbuffer
);
907 if (!att
->Renderbuffer
->InternalFormat
||
908 att
->Renderbuffer
->Width
< 1 ||
909 att
->Renderbuffer
->Height
< 1) {
910 att_incomplete("0x0 renderbuffer");
911 att
->Complete
= GL_FALSE
;
914 if (format
== GL_COLOR
) {
915 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
916 att_incomplete("bad renderbuffer color format");
917 att
->Complete
= GL_FALSE
;
921 else if (format
== GL_DEPTH
) {
922 if (baseFormat
== GL_DEPTH_COMPONENT
) {
925 else if (baseFormat
== GL_DEPTH_STENCIL
) {
929 att_incomplete("bad renderbuffer depth format");
930 att
->Complete
= GL_FALSE
;
935 assert(format
== GL_STENCIL
);
936 if (baseFormat
== GL_STENCIL_INDEX
||
937 baseFormat
== GL_DEPTH_STENCIL
) {
941 att
->Complete
= GL_FALSE
;
942 att_incomplete("bad renderbuffer stencil format");
948 assert(att
->Type
== GL_NONE
);
956 * Test if the given framebuffer object is complete and update its
957 * Status field with the results.
958 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
959 * driver to make hardware-specific validation/completeness checks.
960 * Also update the framebuffer's Width and Height fields if the
961 * framebuffer is complete.
964 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
965 struct gl_framebuffer
*fb
)
968 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
969 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
970 GLint numSamples
= -1;
971 GLint fixedSampleLocations
= -1;
974 /* Covers max_layer_count, is_layered, and layer_tex_target */
975 bool layer_info_valid
= false;
976 GLuint max_layer_count
= 0, att_layer_count
;
977 bool is_layered
= false;
978 GLenum layer_tex_target
= 0;
979 bool has_depth_attachment
= false;
980 bool has_stencil_attachment
= false;
982 assert(_mesa_is_user_fbo(fb
));
984 /* we're changing framebuffer fields here */
985 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
990 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
991 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
992 fb
->_HasAttachments
= true;
993 fb
->_IntegerBuffers
= 0;
995 /* Start at -2 to more easily loop over all attachment points.
1000 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
1001 struct gl_renderbuffer_attachment
*att
;
1003 mesa_format attFormat
;
1004 GLenum att_tex_target
= GL_NONE
;
1007 * XXX for ARB_fbo, only check color buffers that are named by
1008 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
1011 /* check for attachment completeness
1014 att
= &fb
->Attachment
[BUFFER_DEPTH
];
1015 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
1016 if (!att
->Complete
) {
1017 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1018 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
1020 } else if (att
->Type
!= GL_NONE
) {
1021 has_depth_attachment
= true;
1025 att
= &fb
->Attachment
[BUFFER_STENCIL
];
1026 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
1027 if (!att
->Complete
) {
1028 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1029 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
1031 } else if (att
->Type
!= GL_NONE
) {
1032 has_stencil_attachment
= true;
1036 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
1037 test_attachment_completeness(ctx
, GL_COLOR
, att
);
1038 if (!att
->Complete
) {
1039 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1040 fbo_incomplete(ctx
, "color attachment incomplete", i
);
1045 /* get width, height, format of the renderbuffer/texture
1047 if (att
->Type
== GL_TEXTURE
) {
1048 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
1049 att_tex_target
= att
->Texture
->Target
;
1050 minWidth
= MIN2(minWidth
, texImg
->Width
);
1051 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
1052 minHeight
= MIN2(minHeight
, texImg
->Height
);
1053 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
1054 f
= texImg
->_BaseFormat
;
1055 attFormat
= texImg
->TexFormat
;
1058 if (!is_format_color_renderable(ctx
, attFormat
,
1059 texImg
->InternalFormat
) &&
1060 !is_legal_depth_format(ctx
, f
) &&
1061 f
!= GL_STENCIL_INDEX
) {
1062 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
;
1063 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
1068 numSamples
= texImg
->NumSamples
;
1069 else if (numSamples
!= texImg
->NumSamples
) {
1070 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1071 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1075 if (fixedSampleLocations
< 0)
1076 fixedSampleLocations
= texImg
->FixedSampleLocations
;
1077 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
1078 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1079 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1083 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1084 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
1085 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
1086 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
1087 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
1088 f
= att
->Renderbuffer
->InternalFormat
;
1089 attFormat
= att
->Renderbuffer
->Format
;
1093 numSamples
= att
->Renderbuffer
->NumSamples
;
1094 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
1095 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1096 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1100 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1101 if (fixedSampleLocations
< 0)
1102 fixedSampleLocations
= GL_TRUE
;
1103 else if (fixedSampleLocations
!= GL_TRUE
) {
1104 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1105 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1110 assert(att
->Type
== GL_NONE
);
1114 /* Update flags describing color buffer datatypes */
1116 GLenum type
= _mesa_get_format_datatype(attFormat
);
1118 /* check if integer color */
1119 if (_mesa_is_format_integer_color(attFormat
))
1120 fb
->_IntegerBuffers
|= (1 << i
);
1122 fb
->_AllColorBuffersFixedPoint
=
1123 fb
->_AllColorBuffersFixedPoint
&&
1124 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1126 fb
->_HasSNormOrFloatColorBuffer
=
1127 fb
->_HasSNormOrFloatColorBuffer
||
1128 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1131 /* Error-check width, height, format */
1132 if (numImages
== 1) {
1139 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1140 /* check that width, height, format are same */
1141 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1142 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1143 fbo_incomplete(ctx
, "width or height mismatch", -1);
1146 /* check that all color buffers are the same format */
1147 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1148 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1149 fbo_incomplete(ctx
, "format mismatch", -1);
1155 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1157 if (att
->Type
== GL_RENDERBUFFER
&&
1158 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1159 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1160 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1164 /* Check that layered rendering is consistent. */
1166 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1167 att_layer_count
= 6;
1168 else if (att_tex_target
== GL_TEXTURE_1D_ARRAY
)
1169 att_layer_count
= att
->Renderbuffer
->Height
;
1171 att_layer_count
= att
->Renderbuffer
->Depth
;
1173 att_layer_count
= 0;
1175 if (!layer_info_valid
) {
1176 is_layered
= att
->Layered
;
1177 max_layer_count
= att_layer_count
;
1178 layer_tex_target
= att_tex_target
;
1179 layer_info_valid
= true;
1180 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1181 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1182 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1184 } else if (is_layered
!= att
->Layered
) {
1185 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1187 "framebuffer attachment layer mode is inconsistent",
1190 } else if (att_layer_count
> max_layer_count
) {
1191 max_layer_count
= att_layer_count
;
1195 * The extension GL_ARB_framebuffer_no_attachments places additional
1196 * requirement on each attachment. Those additional requirements are
1197 * tighter that those of previous versions of GL. In interest of better
1198 * compatibility, we will not enforce these restrictions. For the record
1199 * those additional restrictions are quoted below:
1201 * "The width and height of image are greater than zero and less than or
1202 * equal to the values of the implementation-dependent limits
1203 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1205 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1206 * array texture and the attachment is layered, the depth or layer count
1207 * of the texture is less than or equal to the implementation-dependent
1208 * limit MAX_FRAMEBUFFER_LAYERS."
1210 * "If image has multiple samples, its sample count is less than or equal
1211 * to the value of the implementation-dependent limit
1212 * MAX_FRAMEBUFFER_SAMPLES."
1214 * The same requirements are also in place for GL 4.5,
1215 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1219 fb
->MaxNumLayers
= max_layer_count
;
1221 if (numImages
== 0) {
1222 fb
->_HasAttachments
= false;
1224 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1225 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1226 fbo_incomplete(ctx
, "no attachments", -1);
1230 if (fb
->DefaultGeometry
.Width
== 0 || fb
->DefaultGeometry
.Height
== 0) {
1231 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1232 fbo_incomplete(ctx
, "no attachments and default width or height is 0", -1);
1237 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1238 /* Check that all DrawBuffers are present */
1239 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1240 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1241 const struct gl_renderbuffer_attachment
*att
1242 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
], NULL
);
1244 if (att
->Type
== GL_NONE
) {
1245 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1246 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1252 /* Check that the ReadBuffer is present */
1253 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1254 const struct gl_renderbuffer_attachment
*att
1255 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
, NULL
);
1257 if (att
->Type
== GL_NONE
) {
1258 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1259 fbo_incomplete(ctx
, "missing readbuffer", -1);
1265 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1267 * "Depth and stencil attachments, if present, are the same image."
1269 * This restriction is not present in the OpenGL ES2 spec.
1271 if (_mesa_is_gles3(ctx
) &&
1272 has_stencil_attachment
&& has_depth_attachment
&&
1273 !_mesa_has_depthstencil_combined(fb
)) {
1274 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1275 fbo_incomplete(ctx
, "Depth and stencil attachments must be the same image", -1);
1279 /* Provisionally set status = COMPLETE ... */
1280 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1282 /* ... but the driver may say the FB is incomplete.
1283 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1286 if (ctx
->Driver
.ValidateFramebuffer
) {
1287 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1288 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1289 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1295 * Note that if ARB_framebuffer_object is supported and the attached
1296 * renderbuffers/textures are different sizes, the framebuffer
1297 * width/height will be set to the smallest width/height.
1299 if (numImages
!= 0) {
1300 fb
->Width
= minWidth
;
1301 fb
->Height
= minHeight
;
1304 /* finally, update the visual info for the framebuffer */
1305 _mesa_update_framebuffer_visual(ctx
, fb
);
1309 GLboolean GLAPIENTRY
1310 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1312 struct gl_renderbuffer
*rb
;
1314 GET_CURRENT_CONTEXT(ctx
);
1316 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1318 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1319 return rb
!= NULL
&& rb
!= &DummyRenderbuffer
;
1323 static struct gl_renderbuffer
*
1324 allocate_renderbuffer_locked(struct gl_context
*ctx
, GLuint renderbuffer
,
1327 struct gl_renderbuffer
*newRb
;
1329 /* create new renderbuffer object */
1330 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1332 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1335 assert(newRb
->AllocStorage
);
1336 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1343 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1345 struct gl_renderbuffer
*newRb
;
1346 GET_CURRENT_CONTEXT(ctx
);
1348 if (target
!= GL_RENDERBUFFER_EXT
) {
1349 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1353 /* No need to flush here since the render buffer binding has no
1354 * effect on rendering state.
1358 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1359 if (newRb
== &DummyRenderbuffer
) {
1360 /* ID was reserved, but no real renderbuffer object made yet */
1363 else if (!newRb
&& !allow_user_names
) {
1364 /* All RB IDs must be Gen'd */
1365 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1370 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1371 newRb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
1372 "glBindRenderbufferEXT");
1373 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1380 assert(newRb
!= &DummyRenderbuffer
);
1382 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1386 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1388 GET_CURRENT_CONTEXT(ctx
);
1390 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1391 * entry point, but they allow the use of user-generated names.
1393 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1397 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1399 /* This function should not be in the dispatch table for core profile /
1400 * OpenGL 3.1, so execution should never get here in those cases -- no
1401 * need for an explicit test.
1403 bind_renderbuffer(target
, renderbuffer
, true);
1407 * ARB_framebuffer_no_attachment - Application passes requested param's
1408 * here. NOTE: NumSamples requested need not be _NumSamples which is
1409 * what the hw supports.
1412 framebuffer_parameteri(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1413 GLenum pname
, GLint param
, const char *func
)
1416 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1417 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferWidth
)
1418 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1420 fb
->DefaultGeometry
.Width
= param
;
1422 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1423 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferHeight
)
1424 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1426 fb
->DefaultGeometry
.Height
= param
;
1428 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1430 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1431 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1433 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1434 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1437 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferLayers
)
1438 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1440 fb
->DefaultGeometry
.Layers
= param
;
1442 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1443 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferSamples
)
1444 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1446 fb
->DefaultGeometry
.NumSamples
= param
;
1448 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1449 fb
->DefaultGeometry
.FixedSampleLocations
= param
;
1452 _mesa_error(ctx
, GL_INVALID_ENUM
,
1453 "%s(pname=0x%x)", func
, pname
);
1456 invalidate_framebuffer(fb
);
1457 ctx
->NewState
|= _NEW_BUFFERS
;
1461 _mesa_FramebufferParameteri(GLenum target
, GLenum pname
, GLint param
)
1463 GET_CURRENT_CONTEXT(ctx
);
1464 struct gl_framebuffer
*fb
;
1466 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1467 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1468 "glFramebufferParameteriv not supported "
1469 "(ARB_framebuffer_no_attachments not implemented)");
1473 fb
= get_framebuffer_target(ctx
, target
);
1475 _mesa_error(ctx
, GL_INVALID_ENUM
,
1476 "glFramebufferParameteri(target=0x%x)", target
);
1480 /* check framebuffer binding */
1481 if (_mesa_is_winsys_fbo(fb
)) {
1482 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1483 "glFramebufferParameteri");
1487 framebuffer_parameteri(ctx
, fb
, pname
, param
, "glFramebufferParameteri");
1491 _pname_valid_for_default_framebuffer(struct gl_context
*ctx
,
1494 if (!_mesa_is_desktop_gl(ctx
))
1498 case GL_DOUBLEBUFFER
:
1499 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1500 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1502 case GL_SAMPLE_BUFFERS
:
1511 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1512 GLenum pname
, GLint
*params
, const char *func
)
1514 /* From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries:
1516 * "An INVALID_OPERATION error is generated by GetFramebufferParameteriv
1517 * if the default framebuffer is bound to target and pname is not one
1518 * of the accepted values from table 23.73, other than
1521 * For OpenGL ES, using default framebuffer still raises INVALID_OPERATION
1524 if (_mesa_is_winsys_fbo(fb
) &&
1525 !_pname_valid_for_default_framebuffer(ctx
, pname
)) {
1526 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1527 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1532 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1533 *params
= fb
->DefaultGeometry
.Width
;
1535 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1536 *params
= fb
->DefaultGeometry
.Height
;
1538 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1540 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1541 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1543 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1544 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1547 *params
= fb
->DefaultGeometry
.Layers
;
1549 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1550 *params
= fb
->DefaultGeometry
.NumSamples
;
1552 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1553 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1555 case GL_DOUBLEBUFFER
:
1556 *params
= fb
->Visual
.doubleBufferMode
;
1558 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1559 *params
= _mesa_get_color_read_format(ctx
, fb
, func
);
1561 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1562 *params
= _mesa_get_color_read_type(ctx
, fb
, func
);
1565 *params
= _mesa_geometric_samples(fb
);
1567 case GL_SAMPLE_BUFFERS
:
1568 *params
= _mesa_geometric_samples(fb
) > 0;
1571 *params
= fb
->Visual
.stereoMode
;
1574 _mesa_error(ctx
, GL_INVALID_ENUM
,
1575 "%s(pname=0x%x)", func
, pname
);
1580 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1582 GET_CURRENT_CONTEXT(ctx
);
1583 struct gl_framebuffer
*fb
;
1585 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1586 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1587 "glGetFramebufferParameteriv not supported "
1588 "(ARB_framebuffer_no_attachments not implemented)");
1592 fb
= get_framebuffer_target(ctx
, target
);
1594 _mesa_error(ctx
, GL_INVALID_ENUM
,
1595 "glGetFramebufferParameteriv(target=0x%x)", target
);
1599 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1600 "glGetFramebufferParameteriv");
1605 * Remove the specified renderbuffer or texture from any attachment point in
1609 * \c true if the renderbuffer was detached from an attachment point. \c
1613 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1614 struct gl_framebuffer
*fb
,
1618 bool progress
= false;
1620 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1621 if (fb
->Attachment
[i
].Texture
== att
1622 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1623 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1628 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1629 * Completeness," of the OpenGL 3.1 spec says:
1631 * "Performing any of the following actions may change whether the
1632 * framebuffer is considered complete or incomplete:
1636 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1637 * containing an image that is attached to a framebuffer object
1638 * that is bound to the framebuffer."
1641 invalidate_framebuffer(fb
);
1648 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1651 GET_CURRENT_CONTEXT(ctx
);
1654 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1658 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1660 for (i
= 0; i
< n
; i
++) {
1661 if (renderbuffers
[i
] > 0) {
1662 struct gl_renderbuffer
*rb
;
1663 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1665 /* check if deleting currently bound renderbuffer object */
1666 if (rb
== ctx
->CurrentRenderbuffer
) {
1668 assert(rb
->RefCount
>= 2);
1669 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1672 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1673 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1674 * of the OpenGL 3.1 spec says:
1676 * "If a renderbuffer object is deleted while its image is
1677 * attached to one or more attachment points in the currently
1678 * bound framebuffer, then it is as if FramebufferRenderbuffer
1679 * had been called, with a renderbuffer of 0, for each
1680 * attachment point to which this image was attached in the
1681 * currently bound framebuffer. In other words, this
1682 * renderbuffer image is first detached from all attachment
1683 * points in the currently bound framebuffer. Note that the
1684 * renderbuffer image is specifically not detached from any
1685 * non-bound framebuffers. Detaching the image from any
1686 * non-bound framebuffers is the responsibility of the
1689 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1690 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1692 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1693 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1694 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1697 /* Remove from hash table immediately, to free the ID.
1698 * But the object will not be freed until it's no longer
1699 * referenced anywhere else.
1701 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1703 if (rb
!= &DummyRenderbuffer
) {
1704 /* no longer referenced by hash table */
1705 _mesa_reference_renderbuffer(&rb
, NULL
);
1713 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1716 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1723 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1725 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1727 for (i
= 0; i
< n
; i
++) {
1728 GLuint name
= first
+ i
;
1729 renderbuffers
[i
] = name
;
1732 allocate_renderbuffer_locked(ctx
, name
, func
);
1734 /* insert a dummy renderbuffer into the hash table */
1735 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1736 &DummyRenderbuffer
);
1740 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1745 create_render_buffers_err(struct gl_context
*ctx
, GLsizei n
,
1746 GLuint
*renderbuffers
, bool dsa
)
1748 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1751 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1755 create_render_buffers(ctx
, n
, renderbuffers
, dsa
);
1760 _mesa_GenRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1762 GET_CURRENT_CONTEXT(ctx
);
1763 create_render_buffers(ctx
, n
, renderbuffers
, false);
1768 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1770 GET_CURRENT_CONTEXT(ctx
);
1771 create_render_buffers_err(ctx
, n
, renderbuffers
, false);
1776 _mesa_CreateRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1778 GET_CURRENT_CONTEXT(ctx
);
1779 create_render_buffers(ctx
, n
, renderbuffers
, true);
1784 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1786 GET_CURRENT_CONTEXT(ctx
);
1787 create_render_buffers_err(ctx
, n
, renderbuffers
, true);
1792 * Given an internal format token for a render buffer, return the
1793 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1794 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1795 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1797 * This is similar to _mesa_base_tex_format() but the set of valid
1798 * internal formats is different.
1800 * Note that even if a format is determined to be legal here, validation
1801 * of the FBO may fail if the format is not supported by the driver/GPU.
1803 * \param internalFormat as passed to glRenderbufferStorage()
1804 * \return the base internal format, or 0 if internalFormat is illegal
1807 _mesa_base_fbo_format(const struct gl_context
*ctx
, GLenum internalFormat
)
1810 * Notes: some formats such as alpha, luminance, etc. were added
1811 * with GL_ARB_framebuffer_object.
1813 switch (internalFormat
) {
1819 return (ctx
->API
== API_OPENGL_COMPAT
&&
1820 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
1824 case GL_LUMINANCE12
:
1825 case GL_LUMINANCE16
:
1826 return (ctx
->API
== API_OPENGL_COMPAT
&&
1827 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
1828 case GL_LUMINANCE_ALPHA
:
1829 case GL_LUMINANCE4_ALPHA4
:
1830 case GL_LUMINANCE6_ALPHA2
:
1831 case GL_LUMINANCE8_ALPHA8
:
1832 case GL_LUMINANCE12_ALPHA4
:
1833 case GL_LUMINANCE12_ALPHA12
:
1834 case GL_LUMINANCE16_ALPHA16
:
1835 return (ctx
->API
== API_OPENGL_COMPAT
&&
1836 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
1840 case GL_INTENSITY12
:
1841 case GL_INTENSITY16
:
1842 return (ctx
->API
== API_OPENGL_COMPAT
&&
1843 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
1853 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1855 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1864 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1866 case GL_SRGB8_ALPHA8_EXT
:
1867 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1868 case GL_STENCIL_INDEX
:
1869 case GL_STENCIL_INDEX1_EXT
:
1870 case GL_STENCIL_INDEX4_EXT
:
1871 case GL_STENCIL_INDEX16_EXT
:
1872 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1873 * OpenGL ES, but Mesa does not currently support them.
1875 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1876 case GL_STENCIL_INDEX8_EXT
:
1877 return GL_STENCIL_INDEX
;
1878 case GL_DEPTH_COMPONENT
:
1879 case GL_DEPTH_COMPONENT32
:
1880 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1881 case GL_DEPTH_COMPONENT16
:
1882 case GL_DEPTH_COMPONENT24
:
1883 return GL_DEPTH_COMPONENT
;
1884 case GL_DEPTH_STENCIL
:
1885 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
1886 case GL_DEPTH24_STENCIL8
:
1887 return GL_DEPTH_STENCIL
;
1888 case GL_DEPTH_COMPONENT32F
:
1889 return ctx
->Version
>= 30
1890 || (ctx
->API
== API_OPENGL_COMPAT
&&
1891 ctx
->Extensions
.ARB_depth_buffer_float
)
1892 ? GL_DEPTH_COMPONENT
: 0;
1893 case GL_DEPTH32F_STENCIL8
:
1894 return ctx
->Version
>= 30
1895 || (ctx
->API
== API_OPENGL_COMPAT
&&
1896 ctx
->Extensions
.ARB_depth_buffer_float
)
1897 ? GL_DEPTH_STENCIL
: 0;
1900 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1903 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1907 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1910 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1912 /* signed normalized texture formats */
1916 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1921 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1925 case GL_RGB16_SNORM
:
1926 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1929 case GL_RGBA8_SNORM
:
1930 case GL_RGBA16_SNORM
:
1931 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1933 case GL_ALPHA_SNORM
:
1934 case GL_ALPHA8_SNORM
:
1935 case GL_ALPHA16_SNORM
:
1936 return ctx
->API
== API_OPENGL_COMPAT
&&
1937 ctx
->Extensions
.EXT_texture_snorm
&&
1938 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1939 case GL_LUMINANCE_SNORM
:
1940 case GL_LUMINANCE8_SNORM
:
1941 case GL_LUMINANCE16_SNORM
:
1942 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1944 case GL_LUMINANCE_ALPHA_SNORM
:
1945 case GL_LUMINANCE8_ALPHA8_SNORM
:
1946 case GL_LUMINANCE16_ALPHA16_SNORM
:
1947 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1948 ? GL_LUMINANCE_ALPHA
: 0;
1949 case GL_INTENSITY_SNORM
:
1950 case GL_INTENSITY8_SNORM
:
1951 case GL_INTENSITY16_SNORM
:
1952 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1957 return ((_mesa_is_desktop_gl(ctx
) &&
1958 ctx
->Extensions
.ARB_texture_rg
&&
1959 ctx
->Extensions
.ARB_texture_float
) ||
1960 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1964 return ((_mesa_is_desktop_gl(ctx
) &&
1965 ctx
->Extensions
.ARB_texture_rg
&&
1966 ctx
->Extensions
.ARB_texture_float
) ||
1967 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1971 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1975 return ((_mesa_is_desktop_gl(ctx
) &&
1976 ctx
->Extensions
.ARB_texture_float
) ||
1977 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1980 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_shared_exponent
)
1982 case GL_ALPHA16F_ARB
:
1983 case GL_ALPHA32F_ARB
:
1984 return ctx
->API
== API_OPENGL_COMPAT
&&
1985 ctx
->Extensions
.ARB_texture_float
&&
1986 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1987 case GL_LUMINANCE16F_ARB
:
1988 case GL_LUMINANCE32F_ARB
:
1989 return ctx
->API
== API_OPENGL_COMPAT
&&
1990 ctx
->Extensions
.ARB_texture_float
&&
1991 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1992 case GL_LUMINANCE_ALPHA16F_ARB
:
1993 case GL_LUMINANCE_ALPHA32F_ARB
:
1994 return ctx
->API
== API_OPENGL_COMPAT
&&
1995 ctx
->Extensions
.ARB_texture_float
&&
1996 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1997 case GL_INTENSITY16F_ARB
:
1998 case GL_INTENSITY32F_ARB
:
1999 return ctx
->API
== API_OPENGL_COMPAT
&&
2000 ctx
->Extensions
.ARB_texture_float
&&
2001 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2002 case GL_R11F_G11F_B10F
:
2003 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
2004 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2007 case GL_RGBA8UI_EXT
:
2008 case GL_RGBA16UI_EXT
:
2009 case GL_RGBA32UI_EXT
:
2011 case GL_RGBA16I_EXT
:
2012 case GL_RGBA32I_EXT
:
2013 return ctx
->Version
>= 30
2014 || (_mesa_is_desktop_gl(ctx
) &&
2015 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
2018 case GL_RGB16UI_EXT
:
2019 case GL_RGB32UI_EXT
:
2023 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
2031 return ctx
->Version
>= 30
2032 || (_mesa_is_desktop_gl(ctx
) &&
2033 ctx
->Extensions
.ARB_texture_rg
&&
2034 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
2042 return ctx
->Version
>= 30
2043 || (_mesa_is_desktop_gl(ctx
) &&
2044 ctx
->Extensions
.ARB_texture_rg
&&
2045 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
2047 case GL_INTENSITY8I_EXT
:
2048 case GL_INTENSITY8UI_EXT
:
2049 case GL_INTENSITY16I_EXT
:
2050 case GL_INTENSITY16UI_EXT
:
2051 case GL_INTENSITY32I_EXT
:
2052 case GL_INTENSITY32UI_EXT
:
2053 return ctx
->API
== API_OPENGL_COMPAT
&&
2054 ctx
->Extensions
.EXT_texture_integer
&&
2055 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2057 case GL_LUMINANCE8I_EXT
:
2058 case GL_LUMINANCE8UI_EXT
:
2059 case GL_LUMINANCE16I_EXT
:
2060 case GL_LUMINANCE16UI_EXT
:
2061 case GL_LUMINANCE32I_EXT
:
2062 case GL_LUMINANCE32UI_EXT
:
2063 return ctx
->API
== API_OPENGL_COMPAT
&&
2064 ctx
->Extensions
.EXT_texture_integer
&&
2065 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2067 case GL_LUMINANCE_ALPHA8I_EXT
:
2068 case GL_LUMINANCE_ALPHA8UI_EXT
:
2069 case GL_LUMINANCE_ALPHA16I_EXT
:
2070 case GL_LUMINANCE_ALPHA16UI_EXT
:
2071 case GL_LUMINANCE_ALPHA32I_EXT
:
2072 case GL_LUMINANCE_ALPHA32UI_EXT
:
2073 return ctx
->API
== API_OPENGL_COMPAT
&&
2074 ctx
->Extensions
.EXT_texture_integer
&&
2075 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2077 case GL_ALPHA8I_EXT
:
2078 case GL_ALPHA8UI_EXT
:
2079 case GL_ALPHA16I_EXT
:
2080 case GL_ALPHA16UI_EXT
:
2081 case GL_ALPHA32I_EXT
:
2082 case GL_ALPHA32UI_EXT
:
2083 return ctx
->API
== API_OPENGL_COMPAT
&&
2084 ctx
->Extensions
.EXT_texture_integer
&&
2085 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2088 return (_mesa_is_desktop_gl(ctx
) &&
2089 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
2090 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2093 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2102 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2105 invalidate_rb(GLuint key
, void *data
, void *userData
)
2107 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2108 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2110 /* If this is a user-created FBO */
2111 if (_mesa_is_user_fbo(fb
)) {
2113 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2114 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2115 if (att
->Type
== GL_RENDERBUFFER
&&
2116 att
->Renderbuffer
== rb
) {
2117 /* Mark fb status as indeterminate to force re-validation */
2126 /** sentinal value, see below */
2127 #define NO_SAMPLES 1000
2130 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2131 GLenum internalFormat
, GLsizei width
,
2132 GLsizei height
, GLsizei samples
)
2134 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2136 assert(baseFormat
!= 0);
2137 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2138 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2139 assert(samples
!= NO_SAMPLES
);
2141 assert(samples
> 0);
2142 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2143 internalFormat
, samples
) == GL_NO_ERROR
);
2146 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2148 if (rb
->InternalFormat
== internalFormat
&&
2149 rb
->Width
== (GLuint
) width
&&
2150 rb
->Height
== (GLuint
) height
&&
2151 rb
->NumSamples
== samples
) {
2152 /* no change in allocation needed */
2156 /* These MUST get set by the AllocStorage func */
2157 rb
->Format
= MESA_FORMAT_NONE
;
2158 rb
->NumSamples
= samples
;
2160 /* Now allocate the storage */
2161 assert(rb
->AllocStorage
);
2162 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2163 /* No error - check/set fields now */
2164 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2165 assert(rb
->Width
== (GLuint
) width
);
2166 assert(rb
->Height
== (GLuint
) height
);
2167 rb
->InternalFormat
= internalFormat
;
2168 rb
->_BaseFormat
= baseFormat
;
2169 assert(rb
->_BaseFormat
!= 0);
2172 /* Probably ran out of memory - clear the fields */
2175 rb
->Format
= MESA_FORMAT_NONE
;
2176 rb
->InternalFormat
= GL_NONE
;
2177 rb
->_BaseFormat
= GL_NONE
;
2181 /* Invalidate the framebuffers the renderbuffer is attached in. */
2182 if (rb
->AttachedAnytime
) {
2183 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2188 * Helper function used by renderbuffer_storage_direct() and
2189 * renderbuffer_storage_target().
2190 * samples will be NO_SAMPLES if called by a non-multisample function.
2193 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2194 GLenum internalFormat
, GLsizei width
,
2195 GLsizei height
, GLsizei samples
, const char *func
)
2198 GLenum sample_count_error
;
2200 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2201 if (baseFormat
== 0) {
2202 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2203 func
, _mesa_enum_to_string(internalFormat
));
2207 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2208 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2213 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2214 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2219 if (samples
== NO_SAMPLES
) {
2220 /* NumSamples == 0 indicates non-multisampling */
2224 /* check the sample count;
2225 * note: driver may choose to use more samples than what's requested
2227 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2228 internalFormat
, samples
);
2230 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2232 * "If a negative number is provided where an argument of type sizei or
2233 * sizeiptr is specified, the error INVALID VALUE is generated."
2236 sample_count_error
= GL_INVALID_VALUE
;
2239 if (sample_count_error
!= GL_NO_ERROR
) {
2240 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
2245 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
);
2249 * Helper function used by _mesa_NamedRenderbufferStorage*().
2250 * samples will be NO_SAMPLES if called by a non-multisample function.
2253 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2254 GLsizei width
, GLsizei height
, GLsizei samples
,
2257 GET_CURRENT_CONTEXT(ctx
);
2259 if (MESA_VERBOSE
& VERBOSE_API
) {
2260 if (samples
== NO_SAMPLES
)
2261 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2263 _mesa_enum_to_string(internalFormat
),
2266 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2268 _mesa_enum_to_string(internalFormat
),
2269 width
, height
, samples
);
2272 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2273 if (!rb
|| rb
== &DummyRenderbuffer
) {
2274 /* ID was reserved, but no real renderbuffer object made yet */
2275 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2276 func
, renderbuffer
);
2280 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
, func
);
2284 * Helper function used by _mesa_RenderbufferStorage() and
2285 * _mesa_RenderbufferStorageMultisample().
2286 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2289 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2290 GLsizei width
, GLsizei height
, GLsizei samples
,
2293 GET_CURRENT_CONTEXT(ctx
);
2295 if (MESA_VERBOSE
& VERBOSE_API
) {
2296 if (samples
== NO_SAMPLES
)
2297 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2299 _mesa_enum_to_string(target
),
2300 _mesa_enum_to_string(internalFormat
),
2303 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2305 _mesa_enum_to_string(target
),
2306 _mesa_enum_to_string(internalFormat
),
2307 width
, height
, samples
);
2310 if (target
!= GL_RENDERBUFFER_EXT
) {
2311 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2315 if (!ctx
->CurrentRenderbuffer
) {
2316 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2321 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2322 height
, samples
, func
);
2327 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2329 struct gl_renderbuffer
*rb
;
2330 GET_CURRENT_CONTEXT(ctx
);
2332 if (!ctx
->Extensions
.OES_EGL_image
) {
2333 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2334 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2338 if (target
!= GL_RENDERBUFFER
) {
2339 _mesa_error(ctx
, GL_INVALID_ENUM
,
2340 "EGLImageTargetRenderbufferStorageOES");
2344 rb
= ctx
->CurrentRenderbuffer
;
2346 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2347 "EGLImageTargetRenderbufferStorageOES");
2351 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2353 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2358 * Helper function for _mesa_GetRenderbufferParameteriv() and
2359 * _mesa_GetFramebufferAttachmentParameteriv()
2360 * We have to be careful to respect the base format. For example, if a
2361 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2362 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2363 * we need to return zero.
2366 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2368 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2369 return _mesa_get_format_bits(format
, pname
);
2377 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2378 GLsizei width
, GLsizei height
)
2380 /* GL_ARB_fbo says calling this function is equivalent to calling
2381 * glRenderbufferStorageMultisample() with samples=0. We pass in
2382 * a token value here just for error reporting purposes.
2384 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2385 NO_SAMPLES
, "glRenderbufferStorage");
2390 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2391 GLenum internalFormat
,
2392 GLsizei width
, GLsizei height
)
2394 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2395 samples
, "glRenderbufferStorageMultisample");
2400 * OpenGL ES version of glRenderBufferStorage.
2403 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2404 GLsizei width
, GLsizei height
)
2406 switch (internalFormat
) {
2408 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2409 /* choose a closest format */
2410 internalFormat
= GL_RGB5
;
2416 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0,
2417 "glRenderbufferStorageEXT");
2421 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2422 GLsizei width
, GLsizei height
)
2424 /* GL_ARB_fbo says calling this function is equivalent to calling
2425 * glRenderbufferStorageMultisample() with samples=0. We pass in
2426 * a token value here just for error reporting purposes.
2428 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2429 NO_SAMPLES
, "glNamedRenderbufferStorage");
2433 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2434 GLenum internalformat
,
2435 GLsizei width
, GLsizei height
)
2437 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2439 "glNamedRenderbufferStorageMultisample");
2444 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2445 struct gl_renderbuffer
*rb
, GLenum pname
,
2446 GLint
*params
, const char *func
)
2448 /* No need to flush here since we're just quering state which is
2449 * not effected by rendering.
2453 case GL_RENDERBUFFER_WIDTH_EXT
:
2454 *params
= rb
->Width
;
2456 case GL_RENDERBUFFER_HEIGHT_EXT
:
2457 *params
= rb
->Height
;
2459 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2460 *params
= rb
->InternalFormat
;
2462 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2463 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2464 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2465 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2466 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2467 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2468 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2470 case GL_RENDERBUFFER_SAMPLES
:
2471 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2472 || _mesa_is_gles3(ctx
)) {
2473 *params
= rb
->NumSamples
;
2478 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2479 _mesa_enum_to_string(pname
));
2486 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2488 GET_CURRENT_CONTEXT(ctx
);
2490 if (target
!= GL_RENDERBUFFER_EXT
) {
2491 _mesa_error(ctx
, GL_INVALID_ENUM
,
2492 "glGetRenderbufferParameterivEXT(target)");
2496 if (!ctx
->CurrentRenderbuffer
) {
2497 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2498 "(no renderbuffer bound)");
2502 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2503 params
, "glGetRenderbufferParameteriv");
2508 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2511 GET_CURRENT_CONTEXT(ctx
);
2513 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2514 if (!rb
|| rb
== &DummyRenderbuffer
) {
2515 /* ID was reserved, but no real renderbuffer object made yet */
2516 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2517 "(invalid renderbuffer %i)", renderbuffer
);
2521 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2522 "glGetNamedRenderbufferParameteriv");
2526 GLboolean GLAPIENTRY
2527 _mesa_IsFramebuffer(GLuint framebuffer
)
2529 GET_CURRENT_CONTEXT(ctx
);
2530 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2532 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2533 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2541 * Check if any of the attachments of the given framebuffer are textures
2542 * (render to texture). Call ctx->Driver.RenderTexture() for such
2546 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2549 assert(ctx
->Driver
.RenderTexture
);
2551 if (_mesa_is_winsys_fbo(fb
))
2552 return; /* can't render to texture with winsys framebuffers */
2554 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2555 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2556 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2557 && driver_RenderTexture_is_safe(att
)) {
2558 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2565 * Examine all the framebuffer's attachments to see if any are textures.
2566 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2567 * notify the device driver that the texture image may have changed.
2570 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2572 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2573 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2576 if (ctx
->Driver
.FinishRenderTexture
) {
2578 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2579 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2580 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2581 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2582 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2590 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2592 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2593 GLboolean bindReadBuf
, bindDrawBuf
;
2594 GET_CURRENT_CONTEXT(ctx
);
2597 case GL_DRAW_FRAMEBUFFER_EXT
:
2598 bindDrawBuf
= GL_TRUE
;
2599 bindReadBuf
= GL_FALSE
;
2601 case GL_READ_FRAMEBUFFER_EXT
:
2602 bindDrawBuf
= GL_FALSE
;
2603 bindReadBuf
= GL_TRUE
;
2605 case GL_FRAMEBUFFER_EXT
:
2606 bindDrawBuf
= GL_TRUE
;
2607 bindReadBuf
= GL_TRUE
;
2610 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2615 /* Binding a user-created framebuffer object */
2616 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2617 if (newDrawFb
== &DummyFramebuffer
) {
2618 /* ID was reserved, but no real framebuffer object made yet */
2621 else if (!newDrawFb
&& !allow_user_names
) {
2622 /* All FBO IDs must be Gen'd */
2623 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2628 /* create new framebuffer object */
2629 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2631 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2634 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2636 newReadFb
= newDrawFb
;
2639 /* Binding the window system framebuffer (which was originally set
2640 * with MakeCurrent).
2642 newDrawFb
= ctx
->WinSysDrawBuffer
;
2643 newReadFb
= ctx
->WinSysReadBuffer
;
2646 _mesa_bind_framebuffers(ctx
,
2647 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2648 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2652 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2653 struct gl_framebuffer
*newDrawFb
,
2654 struct gl_framebuffer
*newReadFb
)
2656 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
2657 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
2658 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
2659 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
2662 assert(newDrawFb
!= &DummyFramebuffer
);
2665 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2667 * We also check if we're beginning and/or ending render-to-texture.
2668 * When a framebuffer with texture attachments is unbound, call
2669 * ctx->Driver.FinishRenderTexture().
2670 * When a framebuffer with texture attachments is bound, call
2671 * ctx->Driver.RenderTexture().
2673 * Note that if the ReadBuffer has texture attachments we don't consider
2674 * that a render-to-texture case.
2677 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2679 /* check if old readbuffer was render-to-texture */
2680 check_end_texture_render(ctx
, oldReadFb
);
2682 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2686 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2688 /* check if old framebuffer had any texture attachments */
2690 check_end_texture_render(ctx
, oldDrawFb
);
2692 /* check if newly bound framebuffer has any texture attachments */
2693 check_begin_texture_render(ctx
, newDrawFb
);
2695 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2698 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2699 /* The few classic drivers that actually hook this function really only
2700 * want to know if the draw framebuffer changed.
2702 ctx
->Driver
.BindFramebuffer(ctx
,
2703 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
2704 newDrawFb
, newReadFb
);
2709 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2711 GET_CURRENT_CONTEXT(ctx
);
2713 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2714 * point, but they allow the use of user-generated names.
2716 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2721 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2723 /* This function should not be in the dispatch table for core profile /
2724 * OpenGL 3.1, so execution should never get here in those cases -- no
2725 * need for an explicit test.
2727 bind_framebuffer(target
, framebuffer
, true);
2732 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2735 GET_CURRENT_CONTEXT(ctx
);
2738 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
2742 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2744 for (i
= 0; i
< n
; i
++) {
2745 if (framebuffers
[i
] > 0) {
2746 struct gl_framebuffer
*fb
;
2747 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2749 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2751 /* check if deleting currently bound framebuffer object */
2752 if (fb
== ctx
->DrawBuffer
) {
2754 assert(fb
->RefCount
>= 2);
2755 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2757 if (fb
== ctx
->ReadBuffer
) {
2759 assert(fb
->RefCount
>= 2);
2760 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2763 /* remove from hash table immediately, to free the ID */
2764 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2766 if (fb
!= &DummyFramebuffer
) {
2767 /* But the object will not be freed until it's no longer
2768 * bound in any context.
2770 _mesa_reference_framebuffer(&fb
, NULL
);
2779 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2780 * It is not exposed to the rest of Mesa to encourage the use of
2781 * nameless buffers in driver internals.
2784 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
2786 GET_CURRENT_CONTEXT(ctx
);
2789 struct gl_framebuffer
*fb
;
2791 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
2794 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
2801 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
2803 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2805 for (i
= 0; i
< n
; i
++) {
2806 GLuint name
= first
+ i
;
2807 framebuffers
[i
] = name
;
2810 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
2812 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2813 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
2818 fb
= &DummyFramebuffer
;
2820 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
2823 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2828 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2830 create_framebuffers(n
, framebuffers
, false);
2835 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2837 create_framebuffers(n
, framebuffers
, true);
2842 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
2843 struct gl_framebuffer
*buffer
)
2845 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2847 if (_mesa_is_winsys_fbo(buffer
)) {
2848 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2849 if (buffer
!= &IncompleteFramebuffer
) {
2850 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2852 return GL_FRAMEBUFFER_UNDEFINED
;
2856 /* No need to flush here */
2858 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2859 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2862 return buffer
->_Status
;
2867 _mesa_CheckFramebufferStatus_no_error(GLenum target
)
2869 GET_CURRENT_CONTEXT(ctx
);
2871 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
2872 return _mesa_check_framebuffer_status(ctx
, fb
);
2877 _mesa_CheckFramebufferStatus(GLenum target
)
2879 struct gl_framebuffer
*fb
;
2880 GET_CURRENT_CONTEXT(ctx
);
2882 if (MESA_VERBOSE
& VERBOSE_API
)
2883 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2884 _mesa_enum_to_string(target
));
2886 fb
= get_framebuffer_target(ctx
, target
);
2888 _mesa_error(ctx
, GL_INVALID_ENUM
,
2889 "glCheckFramebufferStatus(invalid target %s)",
2890 _mesa_enum_to_string(target
));
2894 return _mesa_check_framebuffer_status(ctx
, fb
);
2899 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
2901 struct gl_framebuffer
*fb
;
2902 GET_CURRENT_CONTEXT(ctx
);
2904 /* Validate the target (for conformance's sake) and grab a reference to the
2905 * default framebuffer in case framebuffer = 0.
2906 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
2907 * (30.10.2014, PDF page 336) says:
2908 * "If framebuffer is zero, then the status of the default read or
2909 * draw framebuffer (as determined by target) is returned."
2912 case GL_DRAW_FRAMEBUFFER
:
2913 case GL_FRAMEBUFFER
:
2914 fb
= ctx
->WinSysDrawBuffer
;
2916 case GL_READ_FRAMEBUFFER
:
2917 fb
= ctx
->WinSysReadBuffer
;
2920 _mesa_error(ctx
, GL_INVALID_ENUM
,
2921 "glCheckNamedFramebufferStatus(invalid target %s)",
2922 _mesa_enum_to_string(target
));
2927 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
2928 "glCheckNamedFramebufferStatus");
2933 return _mesa_check_framebuffer_status(ctx
, fb
);
2938 * Replicate the src attachment point. Used by framebuffer_texture() when
2939 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2940 * GL_STENCIL_ATTACHMENT.
2943 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2944 gl_buffer_index dst
,
2945 gl_buffer_index src
)
2947 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2948 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2950 assert(src_att
->Texture
!= NULL
);
2951 assert(src_att
->Renderbuffer
!= NULL
);
2953 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2954 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2955 dst_att
->Type
= src_att
->Type
;
2956 dst_att
->Complete
= src_att
->Complete
;
2957 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2958 dst_att
->CubeMapFace
= src_att
->CubeMapFace
;
2959 dst_att
->Zoffset
= src_att
->Zoffset
;
2960 dst_att
->Layered
= src_att
->Layered
;
2964 static struct gl_texture_object
*
2965 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
)
2970 return _mesa_lookup_texture(ctx
, texture
);
2975 * Common code called by gl*FramebufferTexture*() to retrieve the correct
2976 * texture object pointer.
2978 * \param texObj where the pointer to the texture object is returned. Note
2979 * that a successful call may return texObj = NULL.
2981 * \return true if no errors, false if errors
2984 get_texture_for_framebuffer_err(struct gl_context
*ctx
, GLuint texture
,
2985 bool layered
, const char *caller
,
2986 struct gl_texture_object
**texObj
)
2988 *texObj
= NULL
; /* This will get returned if texture = 0. */
2993 *texObj
= _mesa_lookup_texture(ctx
, texture
);
2994 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
2995 /* Can't render to a non-existent texture object.
2997 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
2998 * Managing Framebuffer Objects specifies a different error
2999 * depending upon the calling function (PDF pages 325-328).
3000 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
3001 * value, while the other commands throw invalid operation (where
3002 * layered = GL_FALSE).
3004 const GLenum error
= layered
? GL_INVALID_VALUE
:
3005 GL_INVALID_OPERATION
;
3006 _mesa_error(ctx
, error
,
3007 "%s(non-existent texture %u)", caller
, texture
);
3016 * Common code called by gl*FramebufferTexture() to verify the texture target
3017 * and decide whether or not the attachment should truly be considered
3020 * \param layered true if attachment should be considered layered, false if
3023 * \return true if no errors, false if errors
3026 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
3027 const char *caller
, GLboolean
*layered
)
3033 case GL_TEXTURE_1D_ARRAY_EXT
:
3034 case GL_TEXTURE_2D_ARRAY_EXT
:
3035 case GL_TEXTURE_CUBE_MAP
:
3036 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3037 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3041 case GL_TEXTURE_RECTANGLE
:
3042 case GL_TEXTURE_2D_MULTISAMPLE
:
3043 /* These texture types are valid to pass to
3044 * glFramebufferTexture(), but since they aren't layered, it
3045 * is equivalent to calling glFramebufferTexture{1D,2D}().
3047 *layered
= GL_FALSE
;
3051 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3052 "%s(invalid texture target %s)", caller
,
3053 _mesa_enum_to_string(target
));
3059 * Common code called by gl*FramebufferTextureLayer() to verify the texture
3062 * \return true if no errors, false if errors
3065 check_texture_target(struct gl_context
*ctx
, GLenum target
,
3068 /* We're being called by glFramebufferTextureLayer().
3069 * The only legal texture types for that function are 3D,
3070 * cube-map, and 1D/2D/cube-map array textures.
3072 * We don't need to check for GL_ARB_texture_cube_map_array because the
3073 * application wouldn't have been able to create a texture with a
3074 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
3078 case GL_TEXTURE_1D_ARRAY
:
3079 case GL_TEXTURE_2D_ARRAY
:
3080 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3081 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3083 case GL_TEXTURE_CUBE_MAP
:
3084 /* We don't need to check the extension (GL_ARB_direct_state_access) or
3085 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
3086 * enabled in core profile. This can be called from
3087 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
3088 * so we do have to check the profile.
3090 return ctx
->API
== API_OPENGL_CORE
;
3093 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3094 "%s(invalid texture target %s)", caller
,
3095 _mesa_enum_to_string(target
));
3101 * Common code called by glFramebufferTexture*D() to verify the texture
3104 * \return true if no errors, false if errors
3107 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
3108 GLenum textarget
, const char *caller
)
3112 switch (textarget
) {
3116 case GL_TEXTURE_1D_ARRAY
:
3117 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3122 case GL_TEXTURE_2D_ARRAY
:
3123 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3124 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3126 case GL_TEXTURE_2D_MULTISAMPLE
:
3127 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3129 !ctx
->Extensions
.ARB_texture_multisample
||
3130 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3132 case GL_TEXTURE_RECTANGLE
:
3133 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3134 !ctx
->Extensions
.NV_texture_rectangle
;
3136 case GL_TEXTURE_CUBE_MAP
:
3137 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3140 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3141 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3142 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3143 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3144 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3145 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3146 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3152 _mesa_error(ctx
, GL_INVALID_ENUM
,
3153 "%s(unknown textarget 0x%x)", caller
, textarget
);
3158 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3159 "%s(invalid textarget %s)",
3160 caller
, _mesa_enum_to_string(textarget
));
3164 /* Make sure textarget is consistent with the texture's type */
3165 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3166 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3169 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3170 "%s(mismatched texture target)", caller
);
3179 * Common code called by gl*FramebufferTextureLayer() and
3180 * glFramebufferTexture3D() to validate the layer.
3182 * \return true if no errors, false if errors
3185 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3188 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3191 * "An INVALID_VALUE error is generated if texture is non-zero
3192 * and layer is negative."
3195 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(layer %d < 0)", caller
, layer
);
3199 if (target
== GL_TEXTURE_3D
) {
3200 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3201 if (layer
>= maxSize
) {
3202 _mesa_error(ctx
, GL_INVALID_VALUE
,
3203 "%s(invalid layer %u)", caller
, layer
);
3207 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3208 (target
== GL_TEXTURE_2D_ARRAY
) ||
3209 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3210 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3211 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3212 _mesa_error(ctx
, GL_INVALID_VALUE
,
3213 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3218 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3220 _mesa_error(ctx
, GL_INVALID_VALUE
,
3221 "%s(layer %u >= 6)", caller
, layer
);
3231 * Common code called by all gl*FramebufferTexture*() entry points to verify
3234 * \return true if no errors, false if errors
3237 check_level(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
3238 GLenum target
, GLint level
, const char *caller
)
3240 /* Section 9.2.8 of the OpenGL 4.6 specification says:
3242 * "If texture refers to an immutable-format texture, level must be
3243 * greater than or equal to zero and smaller than the value of
3244 * TEXTURE_VIEW_NUM_LEVELS for texture."
3246 const int max_levels
= texObj
->Immutable
? texObj
->ImmutableLevels
:
3247 _mesa_max_texture_levels(ctx
, target
);
3249 if (level
< 0 || level
>= max_levels
) {
3250 _mesa_error(ctx
, GL_INVALID_VALUE
,
3251 "%s(invalid level %d)", caller
, level
);
3259 struct gl_renderbuffer_attachment
*
3260 _mesa_get_and_validate_attachment(struct gl_context
*ctx
,
3261 struct gl_framebuffer
*fb
,
3262 GLenum attachment
, const char *caller
)
3264 /* The window-system framebuffer object is immutable */
3265 if (_mesa_is_winsys_fbo(fb
)) {
3266 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3271 /* Not a hash lookup, so we can afford to get the attachment here. */
3272 bool is_color_attachment
;
3273 struct gl_renderbuffer_attachment
*att
=
3274 get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3276 if (is_color_attachment
) {
3277 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3278 "%s(invalid color attachment %s)", caller
,
3279 _mesa_enum_to_string(attachment
));
3281 _mesa_error(ctx
, GL_INVALID_ENUM
,
3282 "%s(invalid attachment %s)", caller
,
3283 _mesa_enum_to_string(attachment
));
3293 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3295 struct gl_renderbuffer_attachment
*att
,
3296 struct gl_texture_object
*texObj
, GLenum textarget
,
3297 GLint level
, GLuint layer
, GLboolean layered
)
3299 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3301 simple_mtx_lock(&fb
->Mutex
);
3303 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3304 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3305 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3306 _mesa_tex_target_to_face(textarget
) ==
3307 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3308 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3309 /* The texture object is already attached to the stencil attachment
3310 * point. Don't create a new renderbuffer; just reuse the stencil
3311 * attachment's. This is required to prevent a GL error in
3312 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3314 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3316 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3317 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3318 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3319 _mesa_tex_target_to_face(textarget
) ==
3320 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3321 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3322 /* As above, but with depth and stencil transposed. */
3323 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3326 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3327 level
, layer
, layered
);
3329 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3330 /* Above we created a new renderbuffer and attached it to the
3331 * depth attachment point. Now attach it to the stencil attachment
3334 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3335 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3340 /* Set the render-to-texture flag. We'll check this flag in
3341 * glTexImage() and friends to determine if we need to revalidate
3342 * any FBOs that might be rendering into this texture.
3343 * This flag never gets cleared since it's non-trivial to determine
3344 * when all FBOs might be done rendering to this texture. That's OK
3345 * though since it's uncommon to render to a texture then repeatedly
3346 * call glTexImage() to change images in the texture.
3348 texObj
->_RenderToTexture
= GL_TRUE
;
3351 remove_attachment(ctx
, att
);
3352 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3353 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3354 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3358 invalidate_framebuffer(fb
);
3360 simple_mtx_unlock(&fb
->Mutex
);
3365 framebuffer_texture_with_dims_no_error(GLenum target
, GLenum attachment
,
3366 GLenum textarget
, GLuint texture
,
3367 GLint level
, GLint layer
)
3369 GET_CURRENT_CONTEXT(ctx
);
3371 /* Get the framebuffer object */
3372 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3374 /* Get the texture object */
3375 struct gl_texture_object
*texObj
=
3376 get_texture_for_framebuffer(ctx
, texture
);
3378 struct gl_renderbuffer_attachment
*att
=
3379 get_attachment(ctx
, fb
, attachment
, NULL
);
3381 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3382 level
, layer
, GL_FALSE
);
3387 framebuffer_texture_with_dims(int dims
, GLenum target
,
3388 GLenum attachment
, GLenum textarget
,
3389 GLuint texture
, GLint level
, GLint layer
,
3392 GET_CURRENT_CONTEXT(ctx
);
3393 struct gl_framebuffer
*fb
;
3394 struct gl_texture_object
*texObj
;
3396 /* Get the framebuffer object */
3397 fb
= get_framebuffer_target(ctx
, target
);
3399 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3400 _mesa_enum_to_string(target
));
3404 /* Get the texture object */
3405 if (!get_texture_for_framebuffer_err(ctx
, texture
, false, caller
, &texObj
))
3409 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3412 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3415 if (!check_level(ctx
, texObj
, textarget
, level
, caller
))
3419 struct gl_renderbuffer_attachment
*att
=
3420 _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, caller
);
3424 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3425 level
, layer
, GL_FALSE
);
3430 _mesa_FramebufferTexture1D_no_error(GLenum target
, GLenum attachment
,
3431 GLenum textarget
, GLuint texture
,
3434 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3440 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3441 GLenum textarget
, GLuint texture
, GLint level
)
3443 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3444 level
, 0, "glFramebufferTexture1D");
3449 _mesa_FramebufferTexture2D_no_error(GLenum target
, GLenum attachment
,
3450 GLenum textarget
, GLuint texture
,
3453 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3459 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3460 GLenum textarget
, GLuint texture
, GLint level
)
3462 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3463 level
, 0, "glFramebufferTexture2D");
3468 _mesa_FramebufferTexture3D_no_error(GLenum target
, GLenum attachment
,
3469 GLenum textarget
, GLuint texture
,
3470 GLint level
, GLint layer
)
3472 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3473 texture
, level
, layer
);
3478 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3479 GLenum textarget
, GLuint texture
,
3480 GLint level
, GLint layer
)
3482 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3483 level
, layer
, "glFramebufferTexture3D");
3487 static ALWAYS_INLINE
void
3488 frame_buffer_texture(GLuint framebuffer
, GLenum target
,
3489 GLenum attachment
, GLuint texture
,
3490 GLint level
, GLint layer
, const char *func
,
3491 bool dsa
, bool no_error
, bool check_layered
)
3493 GET_CURRENT_CONTEXT(ctx
);
3494 GLboolean layered
= GL_FALSE
;
3496 if (!no_error
&& check_layered
) {
3497 if (!_mesa_has_geometry_shaders(ctx
)) {
3498 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3499 "unsupported function (%s) called", func
);
3504 /* Get the framebuffer object */
3505 struct gl_framebuffer
*fb
;
3508 fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3510 fb
= get_framebuffer_target(ctx
, target
);
3514 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3518 fb
= get_framebuffer_target(ctx
, target
);
3520 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)",
3521 func
, _mesa_enum_to_string(target
));
3527 /* Get the texture object and framebuffer attachment*/
3528 struct gl_renderbuffer_attachment
*att
;
3529 struct gl_texture_object
*texObj
;
3531 texObj
= get_texture_for_framebuffer(ctx
, texture
);
3532 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
3534 if (!get_texture_for_framebuffer_err(ctx
, texture
, check_layered
, func
,
3538 att
= _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, func
);
3543 GLenum textarget
= 0;
3545 if (check_layered
) {
3546 /* We do this regardless of no_error because this sets layered */
3547 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3553 if (!check_layered
) {
3554 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3557 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3561 if (!check_level(ctx
, texObj
, texObj
->Target
, level
, func
))
3565 if (!check_layered
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3566 assert(layer
>= 0 && layer
< 6);
3567 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3572 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3573 level
, layer
, layered
);
3577 _mesa_FramebufferTextureLayer_no_error(GLenum target
, GLenum attachment
,
3578 GLuint texture
, GLint level
,
3581 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3582 "glFramebufferTextureLayer", false, true, false);
3587 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3588 GLuint texture
, GLint level
, GLint layer
)
3590 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3591 "glFramebufferTextureLayer", false, false, false);
3596 _mesa_NamedFramebufferTextureLayer_no_error(GLuint framebuffer
,
3598 GLuint texture
, GLint level
,
3601 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3602 "glNamedFramebufferTextureLayer", true, true, false);
3607 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3608 GLuint texture
, GLint level
, GLint layer
)
3610 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3611 "glNamedFramebufferTextureLayer", true, false, false);
3616 _mesa_FramebufferTexture_no_error(GLenum target
, GLenum attachment
,
3617 GLuint texture
, GLint level
)
3619 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3620 "glFramebufferTexture", false, true, true);
3625 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3626 GLuint texture
, GLint level
)
3628 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3629 "glFramebufferTexture", false, false, true);
3633 _mesa_NamedFramebufferTexture_no_error(GLuint framebuffer
, GLenum attachment
,
3634 GLuint texture
, GLint level
)
3636 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3637 "glNamedFramebufferTexture", true, true, true);
3642 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3643 GLuint texture
, GLint level
)
3645 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3646 "glNamedFramebufferTexture", true, false, true);
3651 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3652 struct gl_framebuffer
*fb
,
3654 struct gl_renderbuffer
*rb
)
3656 assert(!_mesa_is_winsys_fbo(fb
));
3658 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3660 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3661 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3663 /* Some subsequent GL commands may depend on the framebuffer's visual
3664 * after the binding is updated. Update visual info now.
3666 _mesa_update_framebuffer_visual(ctx
, fb
);
3669 static ALWAYS_INLINE
void
3670 framebuffer_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3671 GLenum attachment
, GLenum renderbuffertarget
,
3672 GLuint renderbuffer
, const char *func
, bool no_error
)
3674 struct gl_renderbuffer_attachment
*att
;
3675 struct gl_renderbuffer
*rb
;
3676 bool is_color_attachment
;
3678 if (!no_error
&& renderbuffertarget
!= GL_RENDERBUFFER
) {
3679 _mesa_error(ctx
, GL_INVALID_ENUM
,
3680 "%s(renderbuffertarget is not GL_RENDERBUFFER)", func
);
3686 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
, func
);
3690 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
3693 /* remove renderbuffer attachment */
3698 if (_mesa_is_winsys_fbo(fb
)) {
3699 /* Can't attach new renderbuffers to a window system framebuffer */
3700 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3701 "%s(window-system framebuffer)", func
);
3705 att
= get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3708 * From OpenGL 4.5 spec, section 9.2.7 "Attaching Renderbuffer Images
3709 * to a Framebuffer":
3711 * "An INVALID_OPERATION error is generated if attachment is
3712 * COLOR_- ATTACHMENTm where m is greater than or equal to the
3713 * value of MAX_COLOR_- ATTACHMENTS ."
3715 * If we are at this point, is because the attachment is not valid, so
3716 * if is_color_attachment is true, is because of the previous reason.
3718 if (is_color_attachment
) {
3719 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3720 "%s(invalid color attachment %s)", func
,
3721 _mesa_enum_to_string(attachment
));
3723 _mesa_error(ctx
, GL_INVALID_ENUM
,
3724 "%s(invalid attachment %s)", func
,
3725 _mesa_enum_to_string(attachment
));
3731 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3732 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3733 /* make sure the renderbuffer is a depth/stencil format */
3734 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3735 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3736 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3737 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3743 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3747 framebuffer_renderbuffer_error(struct gl_context
*ctx
,
3748 struct gl_framebuffer
*fb
, GLenum attachment
,
3749 GLenum renderbuffertarget
,
3750 GLuint renderbuffer
, const char *func
)
3752 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3753 renderbuffer
, func
, false);
3757 framebuffer_renderbuffer_no_error(struct gl_context
*ctx
,
3758 struct gl_framebuffer
*fb
, GLenum attachment
,
3759 GLenum renderbuffertarget
,
3760 GLuint renderbuffer
, const char *func
)
3762 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3763 renderbuffer
, func
, true);
3767 _mesa_FramebufferRenderbuffer_no_error(GLenum target
, GLenum attachment
,
3768 GLenum renderbuffertarget
,
3769 GLuint renderbuffer
)
3771 GET_CURRENT_CONTEXT(ctx
);
3773 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3774 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3775 renderbuffer
, "glFramebufferRenderbuffer");
3779 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3780 GLenum renderbuffertarget
,
3781 GLuint renderbuffer
)
3783 struct gl_framebuffer
*fb
;
3784 GET_CURRENT_CONTEXT(ctx
);
3786 fb
= get_framebuffer_target(ctx
, target
);
3788 _mesa_error(ctx
, GL_INVALID_ENUM
,
3789 "glFramebufferRenderbuffer(invalid target %s)",
3790 _mesa_enum_to_string(target
));
3794 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
3795 renderbuffer
, "glFramebufferRenderbuffer");
3799 _mesa_NamedFramebufferRenderbuffer_no_error(GLuint framebuffer
,
3801 GLenum renderbuffertarget
,
3802 GLuint renderbuffer
)
3804 GET_CURRENT_CONTEXT(ctx
);
3806 struct gl_framebuffer
*fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3807 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3809 "glNamedFramebufferRenderbuffer");
3813 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
3814 GLenum renderbuffertarget
,
3815 GLuint renderbuffer
)
3817 struct gl_framebuffer
*fb
;
3818 GET_CURRENT_CONTEXT(ctx
);
3820 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3821 "glNamedFramebufferRenderbuffer");
3825 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
3827 "glNamedFramebufferRenderbuffer");
3832 get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
3833 struct gl_framebuffer
*buffer
,
3834 GLenum attachment
, GLenum pname
,
3835 GLint
*params
, const char *caller
)
3837 const struct gl_renderbuffer_attachment
*att
;
3838 bool is_color_attachment
= false;
3841 /* The error code for an attachment type of GL_NONE differs between APIs.
3843 * From the ES 2.0.25 specification, page 127:
3844 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3845 * querying any other pname will generate INVALID_ENUM."
3847 * From the OpenGL 3.0 specification, page 337, or identically,
3848 * the OpenGL ES 3.0.4 specification, page 240:
3850 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
3851 * framebuffer is bound to target. In this case querying pname
3852 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
3853 * queries will generate an INVALID_OPERATION error."
3855 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
3856 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
3858 if (_mesa_is_winsys_fbo(buffer
)) {
3859 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
3862 * "If the framebuffer currently bound to target is zero, then
3863 * INVALID_OPERATION is generated."
3865 * The EXT_framebuffer_object spec has the same wording, and the
3866 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
3869 if ((!_mesa_is_desktop_gl(ctx
) ||
3870 !ctx
->Extensions
.ARB_framebuffer_object
)
3871 && !_mesa_is_gles3(ctx
)) {
3872 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3873 "%s(window-system framebuffer)", caller
);
3877 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
3878 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
3879 _mesa_error(ctx
, GL_INVALID_ENUM
,
3880 "%s(invalid attachment %s)", caller
,
3881 _mesa_enum_to_string(attachment
));
3885 /* The specs are not clear about how to handle
3886 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
3887 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
3890 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
3891 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
3893 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
3894 _mesa_error(ctx
, GL_INVALID_ENUM
,
3895 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
3896 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
3897 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
3901 /* the default / window-system FBO */
3902 att
= get_fb0_attachment(ctx
, buffer
, attachment
);
3905 /* user-created framebuffer FBO */
3906 att
= get_attachment(ctx
, buffer
, attachment
, &is_color_attachment
);
3911 * From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries":
3913 * "An INVALID_OPERATION error is generated if a framebuffer object
3914 * is bound to target and attachment is COLOR_ATTACHMENTm where m is
3915 * greater than or equal to the value of MAX_COLOR_ATTACHMENTS."
3917 * If we are at this point, is because the attachment is not valid, so
3918 * if is_color_attachment is true, is because of the previous reason.
3920 if (is_color_attachment
) {
3921 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid color attachment %s)",
3922 caller
, _mesa_enum_to_string(attachment
));
3924 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3925 _mesa_enum_to_string(attachment
));
3930 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3931 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
3932 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
3933 /* This behavior is first specified in OpenGL 4.4 specification.
3935 * From the OpenGL 4.4 spec page 275:
3936 * "This query cannot be performed for a combined depth+stencil
3937 * attachment, since it does not have a single format."
3939 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3940 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
3941 " is invalid for depth+stencil attachment)", caller
);
3944 /* the depth and stencil attachments must point to the same buffer */
3945 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
, NULL
);
3946 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
, NULL
);
3947 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
3948 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3949 "%s(DEPTH/STENCIL attachments differ)", caller
);
3954 /* No need to flush here */
3957 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
3958 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
3960 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3961 * either no framebuffer is bound to target; or the default framebuffer
3962 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
3963 * stencil bits, respectively, is zero."
3965 * Note that we don't need explicit checks on DEPTH and STENCIL, because
3966 * on the case the spec is pointing, att->Type is already NONE, so we
3967 * just need to check att->Type.
3969 *params
= (_mesa_is_winsys_fbo(buffer
) && att
->Type
!= GL_NONE
) ?
3970 GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
3972 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
3973 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
3974 *params
= att
->Renderbuffer
->Name
;
3976 else if (att
->Type
== GL_TEXTURE
) {
3977 *params
= att
->Texture
->Name
;
3980 assert(att
->Type
== GL_NONE
);
3981 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
3984 goto invalid_pname_enum
;
3988 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
3989 if (att
->Type
== GL_TEXTURE
) {
3990 *params
= att
->TextureLevel
;
3992 else if (att
->Type
== GL_NONE
) {
3993 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3994 _mesa_enum_to_string(pname
));
3997 goto invalid_pname_enum
;
4000 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
4001 if (att
->Type
== GL_TEXTURE
) {
4002 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
4003 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
4009 else if (att
->Type
== GL_NONE
) {
4010 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4011 _mesa_enum_to_string(pname
));
4014 goto invalid_pname_enum
;
4017 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
4018 if (ctx
->API
== API_OPENGLES
) {
4019 goto invalid_pname_enum
;
4020 } else if (att
->Type
== GL_NONE
) {
4021 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4022 _mesa_enum_to_string(pname
));
4023 } else if (att
->Type
== GL_TEXTURE
) {
4024 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
4025 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
4026 *params
= att
->Zoffset
;
4033 goto invalid_pname_enum
;
4036 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
4037 if ((!_mesa_is_desktop_gl(ctx
) ||
4038 !ctx
->Extensions
.ARB_framebuffer_object
)
4039 && !_mesa_is_gles3(ctx
)) {
4040 goto invalid_pname_enum
;
4042 else if (att
->Type
== GL_NONE
) {
4043 if (_mesa_is_winsys_fbo(buffer
) &&
4044 (attachment
== GL_DEPTH
|| attachment
== GL_STENCIL
)) {
4045 *params
= GL_LINEAR
;
4047 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4048 _mesa_enum_to_string(pname
));
4052 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
4054 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
4057 /* According to ARB_framebuffer_sRGB, we should return LINEAR
4058 * if the sRGB conversion is unsupported. */
4059 *params
= GL_LINEAR
;
4063 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
4064 if ((ctx
->API
!= API_OPENGL_COMPAT
||
4065 !ctx
->Extensions
.ARB_framebuffer_object
)
4066 && ctx
->API
!= API_OPENGL_CORE
4067 && !_mesa_is_gles3(ctx
)) {
4068 goto invalid_pname_enum
;
4070 else if (att
->Type
== GL_NONE
) {
4071 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4072 _mesa_enum_to_string(pname
));
4075 mesa_format format
= att
->Renderbuffer
->Format
;
4077 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
4080 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
4081 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
4082 * generate an INVALID_OPERATION error.
4084 if (_mesa_is_gles3(ctx
) &&
4085 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
4086 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4088 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
4089 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
4093 if (format
== MESA_FORMAT_S_UINT8
) {
4097 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
4098 /* depends on the attachment parameter */
4099 if (attachment
== GL_STENCIL_ATTACHMENT
) {
4107 *params
= _mesa_get_format_datatype(format
);
4111 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
4112 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
4113 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
4114 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
4115 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
4116 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
4117 if ((!_mesa_is_desktop_gl(ctx
) ||
4118 !ctx
->Extensions
.ARB_framebuffer_object
)
4119 && !_mesa_is_gles3(ctx
)) {
4120 goto invalid_pname_enum
;
4122 else if (att
->Texture
) {
4123 const struct gl_texture_image
*texImage
=
4124 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
4127 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
4128 texImage
->TexFormat
);
4134 else if (att
->Renderbuffer
) {
4135 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
4136 att
->Renderbuffer
->Format
);
4139 assert(att
->Type
== GL_NONE
);
4140 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4141 _mesa_enum_to_string(pname
));
4144 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
4145 if (!_mesa_has_geometry_shaders(ctx
)) {
4146 goto invalid_pname_enum
;
4147 } else if (att
->Type
== GL_TEXTURE
) {
4148 *params
= att
->Layered
;
4149 } else if (att
->Type
== GL_NONE
) {
4150 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4151 _mesa_enum_to_string(pname
));
4153 goto invalid_pname_enum
;
4157 goto invalid_pname_enum
;
4163 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
4164 _mesa_enum_to_string(pname
));
4170 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
4171 GLenum pname
, GLint
*params
)
4173 GET_CURRENT_CONTEXT(ctx
);
4174 struct gl_framebuffer
*buffer
;
4176 buffer
= get_framebuffer_target(ctx
, target
);
4178 _mesa_error(ctx
, GL_INVALID_ENUM
,
4179 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
4180 _mesa_enum_to_string(target
));
4184 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4186 "glGetFramebufferAttachmentParameteriv");
4191 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
4193 GLenum pname
, GLint
*params
)
4195 GET_CURRENT_CONTEXT(ctx
);
4196 struct gl_framebuffer
*buffer
;
4199 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4200 "glGetNamedFramebufferAttachmentParameteriv");
4206 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
4207 * 4.5 core spec (30.10.2014, PDF page 314):
4208 * "If framebuffer is zero, then the default draw framebuffer is
4211 buffer
= ctx
->WinSysDrawBuffer
;
4214 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4216 "glGetNamedFramebufferAttachmentParameteriv");
4221 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
4224 GET_CURRENT_CONTEXT(ctx
);
4225 struct gl_framebuffer
*fb
= NULL
;
4227 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4228 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4229 "glNamedFramebufferParameteri("
4230 "ARB_framebuffer_no_attachments not implemented)");
4234 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4235 "glNamedFramebufferParameteri");
4238 framebuffer_parameteri(ctx
, fb
, pname
, param
,
4239 "glNamedFramebufferParameteriv");
4245 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
4248 GET_CURRENT_CONTEXT(ctx
);
4249 struct gl_framebuffer
*fb
;
4251 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4252 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4253 "glNamedFramebufferParameteriv("
4254 "ARB_framebuffer_no_attachments not implemented)");
4259 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4260 "glGetNamedFramebufferParameteriv");
4262 fb
= ctx
->WinSysDrawBuffer
;
4266 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4267 "glGetNamedFramebufferParameteriv");
4273 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4274 struct gl_framebuffer
*fb
,
4275 GLsizei numAttachments
,
4276 const GLenum
*attachments
, GLint x
, GLint y
,
4277 GLsizei width
, GLsizei height
, const char *name
)
4281 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4282 * Spec (2.2.2015, PDF page 522) says:
4283 * "An INVALID_VALUE error is generated if numAttachments, width, or
4284 * height is negative."
4286 if (numAttachments
< 0) {
4287 _mesa_error(ctx
, GL_INVALID_VALUE
,
4288 "%s(numAttachments < 0)", name
);
4293 _mesa_error(ctx
, GL_INVALID_VALUE
,
4294 "%s(width < 0)", name
);
4299 _mesa_error(ctx
, GL_INVALID_VALUE
,
4300 "%s(height < 0)", name
);
4304 /* The GL_ARB_invalidate_subdata spec says:
4306 * "If an attachment is specified that does not exist in the
4307 * framebuffer bound to <target>, it is ignored."
4311 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4312 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4313 * INVALID_OPERATION is generated."
4315 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4316 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4317 * set of retrictions).
4319 for (i
= 0; i
< numAttachments
; i
++) {
4320 if (_mesa_is_winsys_fbo(fb
)) {
4321 switch (attachments
[i
]) {
4327 /* Accumulation buffers and auxilary buffers were removed in
4328 * OpenGL 3.1, and they never existed in OpenGL ES.
4330 if (ctx
->API
!= API_OPENGL_COMPAT
)
4340 case GL_FRONT_RIGHT
:
4341 if (!_mesa_is_desktop_gl(ctx
))
4348 switch (attachments
[i
]) {
4349 case GL_DEPTH_ATTACHMENT
:
4350 case GL_STENCIL_ATTACHMENT
:
4352 case GL_DEPTH_STENCIL_ATTACHMENT
:
4353 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4354 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4355 * extension does not make this attachment point valid on ES 2.0.
4357 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4360 case GL_COLOR_ATTACHMENT0
:
4361 case GL_COLOR_ATTACHMENT1
:
4362 case GL_COLOR_ATTACHMENT2
:
4363 case GL_COLOR_ATTACHMENT3
:
4364 case GL_COLOR_ATTACHMENT4
:
4365 case GL_COLOR_ATTACHMENT5
:
4366 case GL_COLOR_ATTACHMENT6
:
4367 case GL_COLOR_ATTACHMENT7
:
4368 case GL_COLOR_ATTACHMENT8
:
4369 case GL_COLOR_ATTACHMENT9
:
4370 case GL_COLOR_ATTACHMENT10
:
4371 case GL_COLOR_ATTACHMENT11
:
4372 case GL_COLOR_ATTACHMENT12
:
4373 case GL_COLOR_ATTACHMENT13
:
4374 case GL_COLOR_ATTACHMENT14
:
4375 case GL_COLOR_ATTACHMENT15
: {
4376 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4377 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4378 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4379 "%s(attachment >= max. color attachments)", name
);
4390 /* We don't actually do anything for this yet. Just return after
4391 * validating the parameters and generating the required errors.
4396 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4397 _mesa_enum_to_string(attachments
[i
]));
4403 _mesa_InvalidateSubFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4404 const GLenum
*attachments
, GLint x
,
4405 GLint y
, GLsizei width
, GLsizei height
)
4412 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4413 const GLenum
*attachments
, GLint x
, GLint y
,
4414 GLsizei width
, GLsizei height
)
4416 struct gl_framebuffer
*fb
;
4417 GET_CURRENT_CONTEXT(ctx
);
4419 fb
= get_framebuffer_target(ctx
, target
);
4421 _mesa_error(ctx
, GL_INVALID_ENUM
,
4422 "glInvalidateSubFramebuffer(invalid target %s)",
4423 _mesa_enum_to_string(target
));
4427 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4428 x
, y
, width
, height
,
4429 "glInvalidateSubFramebuffer");
4434 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4435 GLsizei numAttachments
,
4436 const GLenum
*attachments
,
4438 GLsizei width
, GLsizei height
)
4440 struct gl_framebuffer
*fb
;
4441 GET_CURRENT_CONTEXT(ctx
);
4443 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4444 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4445 * default draw framebuffer is affected."
4448 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4449 "glInvalidateNamedFramebufferSubData");
4454 fb
= ctx
->WinSysDrawBuffer
;
4456 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4457 x
, y
, width
, height
,
4458 "glInvalidateNamedFramebufferSubData");
4463 _mesa_InvalidateFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4464 const GLenum
*attachments
)
4471 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4472 const GLenum
*attachments
)
4474 struct gl_framebuffer
*fb
;
4475 GET_CURRENT_CONTEXT(ctx
);
4477 fb
= get_framebuffer_target(ctx
, target
);
4479 _mesa_error(ctx
, GL_INVALID_ENUM
,
4480 "glInvalidateFramebuffer(invalid target %s)",
4481 _mesa_enum_to_string(target
));
4485 /* The GL_ARB_invalidate_subdata spec says:
4489 * void InvalidateFramebuffer(enum target,
4490 * sizei numAttachments,
4491 * const enum *attachments);
4493 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4494 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4495 * <MAX_VIEWPORT_DIMS[1]> respectively."
4497 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4499 ctx
->Const
.MaxViewportWidth
,
4500 ctx
->Const
.MaxViewportHeight
,
4501 "glInvalidateFramebuffer");
4506 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4507 GLsizei numAttachments
,
4508 const GLenum
*attachments
)
4510 struct gl_framebuffer
*fb
;
4511 GET_CURRENT_CONTEXT(ctx
);
4513 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4514 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4515 * default draw framebuffer is affected."
4518 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4519 "glInvalidateNamedFramebufferData");
4524 fb
= ctx
->WinSysDrawBuffer
;
4526 /* The GL_ARB_invalidate_subdata spec says:
4530 * void InvalidateFramebuffer(enum target,
4531 * sizei numAttachments,
4532 * const enum *attachments);
4534 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4535 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4536 * <MAX_VIEWPORT_DIMS[1]> respectively."
4538 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4540 ctx
->Const
.MaxViewportWidth
,
4541 ctx
->Const
.MaxViewportHeight
,
4542 "glInvalidateNamedFramebufferData");
4547 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4548 const GLenum
*attachments
)
4550 struct gl_framebuffer
*fb
;
4553 GET_CURRENT_CONTEXT(ctx
);
4555 fb
= get_framebuffer_target(ctx
, target
);
4557 _mesa_error(ctx
, GL_INVALID_ENUM
,
4558 "glDiscardFramebufferEXT(target %s)",
4559 _mesa_enum_to_string(target
));
4563 if (numAttachments
< 0) {
4564 _mesa_error(ctx
, GL_INVALID_VALUE
,
4565 "glDiscardFramebufferEXT(numAttachments < 0)");
4569 for (i
= 0; i
< numAttachments
; i
++) {
4570 switch (attachments
[i
]) {
4574 if (_mesa_is_user_fbo(fb
))
4577 case GL_COLOR_ATTACHMENT0
:
4578 case GL_DEPTH_ATTACHMENT
:
4579 case GL_STENCIL_ATTACHMENT
:
4580 if (_mesa_is_winsys_fbo(fb
))
4588 if (ctx
->Driver
.DiscardFramebuffer
)
4589 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4594 _mesa_error(ctx
, GL_INVALID_ENUM
,
4595 "glDiscardFramebufferEXT(attachment %s)",
4596 _mesa_enum_to_string(attachments
[i
]));