2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 * GL_EXT/ARB_framebuffer_object extensions
41 #include "framebuffer.h"
42 #include "glformats.h"
45 #include "multisample.h"
47 #include "renderbuffer.h"
56 * None of the GL_EXT_framebuffer_object functions are compiled into
63 * When glGenRender/FramebuffersEXT() is called we insert pointers to
64 * these placeholder objects into the hash table.
65 * Later, when the object ID is first bound, we replace the placeholder
66 * with the real frame/renderbuffer.
68 static struct gl_framebuffer DummyFramebuffer
;
69 static struct gl_renderbuffer DummyRenderbuffer
;
71 /* We bind this framebuffer when applications pass a NULL
72 * drawable/surface in make current. */
73 static struct gl_framebuffer IncompleteFramebuffer
;
77 delete_dummy_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
83 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
90 _mesa_init_fbobjects(struct gl_context
*ctx
)
92 mtx_init(&DummyFramebuffer
.Mutex
, mtx_plain
);
93 mtx_init(&DummyRenderbuffer
.Mutex
, mtx_plain
);
94 mtx_init(&IncompleteFramebuffer
.Mutex
, mtx_plain
);
95 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
96 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
97 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
100 struct gl_framebuffer
*
101 _mesa_get_incomplete_framebuffer(void)
103 return &IncompleteFramebuffer
;
107 * Helper routine for getting a gl_renderbuffer.
109 struct gl_renderbuffer
*
110 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
112 struct gl_renderbuffer
*rb
;
117 rb
= (struct gl_renderbuffer
*)
118 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
124 * A convenience function for direct state access that throws
125 * GL_INVALID_OPERATION if the renderbuffer doesn't exist.
127 struct gl_renderbuffer
*
128 _mesa_lookup_renderbuffer_err(struct gl_context
*ctx
, GLuint id
,
131 struct gl_renderbuffer
*rb
;
133 rb
= _mesa_lookup_renderbuffer(ctx
, id
);
134 if (!rb
|| rb
== &DummyRenderbuffer
) {
135 _mesa_error(ctx
, GL_INVALID_OPERATION
,
136 "%s(non-existent renderbuffer %u)", func
, id
);
145 * Helper routine for getting a gl_framebuffer.
147 struct gl_framebuffer
*
148 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
150 struct gl_framebuffer
*fb
;
155 fb
= (struct gl_framebuffer
*)
156 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
162 * A convenience function for direct state access that throws
163 * GL_INVALID_OPERATION if the framebuffer doesn't exist.
165 struct gl_framebuffer
*
166 _mesa_lookup_framebuffer_err(struct gl_context
*ctx
, GLuint id
,
169 struct gl_framebuffer
*fb
;
171 fb
= _mesa_lookup_framebuffer(ctx
, id
);
172 if (!fb
|| fb
== &DummyFramebuffer
) {
173 _mesa_error(ctx
, GL_INVALID_OPERATION
,
174 "%s(non-existent framebuffer %u)", func
, id
);
183 * Mark the given framebuffer as invalid. This will force the
184 * test for framebuffer completeness to be done before the framebuffer
188 invalidate_framebuffer(struct gl_framebuffer
*fb
)
190 fb
->_Status
= 0; /* "indeterminate" */
195 * Return the gl_framebuffer object which corresponds to the given
196 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
197 * Check support for GL_EXT_framebuffer_blit to determine if certain
199 * \return gl_framebuffer pointer or NULL if target is illegal
201 static struct gl_framebuffer
*
202 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
204 bool have_fb_blit
= _mesa_is_gles3(ctx
) || _mesa_is_desktop_gl(ctx
);
206 case GL_DRAW_FRAMEBUFFER
:
207 return have_fb_blit
? ctx
->DrawBuffer
: NULL
;
208 case GL_READ_FRAMEBUFFER
:
209 return have_fb_blit
? ctx
->ReadBuffer
: NULL
;
210 case GL_FRAMEBUFFER_EXT
:
211 return ctx
->DrawBuffer
;
219 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
220 * gl_renderbuffer_attachment object.
221 * This function is only used for user-created FB objects, not the
222 * default / window-system FB object.
223 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
224 * the depth buffer attachment point.
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 if (fb
->Visual
.numAuxBuffers
== 1) {
335 return &fb
->Attachment
[BUFFER_AUX0
];
339 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
341 * "If the default framebuffer is bound to target, then attachment must
342 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
343 * identifying a color buffer; DEPTH, identifying the depth buffer; or
344 * STENCIL, identifying the stencil buffer."
346 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
347 * language. However, revision #33 of the ARB_framebuffer_object spec
350 * "If the default framebuffer is bound to <target>, then <attachment>
351 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
352 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
353 * depth buffer, or the stencil buffer, and <pname> may be
354 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
355 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
357 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
358 * from glext.h, so shipping apps should not use those values.
360 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
361 * support queries of the window system FBO.
364 return &fb
->Attachment
[BUFFER_DEPTH
];
366 return &fb
->Attachment
[BUFFER_STENCIL
];
375 * Remove any texture or renderbuffer attached to the given attachment
376 * point. Update reference counts, etc.
379 remove_attachment(struct gl_context
*ctx
,
380 struct gl_renderbuffer_attachment
*att
)
382 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
384 /* tell driver that we're done rendering to this texture. */
385 if (rb
&& rb
->NeedsFinishRenderTexture
)
386 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
388 if (att
->Type
== GL_TEXTURE
) {
389 assert(att
->Texture
);
390 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
391 assert(!att
->Texture
);
393 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
394 assert(!att
->Texture
);
395 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
396 assert(!att
->Renderbuffer
);
399 att
->Complete
= GL_TRUE
;
403 * Verify a couple error conditions that will lead to an incomplete FBO and
404 * may cause problems for the driver's RenderTexture path.
407 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment
*att
)
409 const struct gl_texture_image
*const texImage
=
410 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
413 texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
416 if ((texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
417 && att
->Zoffset
>= texImage
->Height
)
418 || (texImage
->TexObject
->Target
!= GL_TEXTURE_1D_ARRAY
419 && att
->Zoffset
>= texImage
->Depth
))
426 * Create a renderbuffer which will be set up by the driver to wrap the
427 * texture image slice.
429 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
430 * to share most of their framebuffer rendering code between winsys,
431 * renderbuffer, and texture attachments.
433 * The allocated renderbuffer uses a non-zero Name so that drivers can check
434 * it for determining vertical orientation, but we use ~0 to make it fairly
435 * unambiguous with actual user (non-texture) renderbuffers.
438 _mesa_update_texture_renderbuffer(struct gl_context
*ctx
,
439 struct gl_framebuffer
*fb
,
440 struct gl_renderbuffer_attachment
*att
)
442 struct gl_texture_image
*texImage
;
443 struct gl_renderbuffer
*rb
;
445 texImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
447 rb
= att
->Renderbuffer
;
449 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
451 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
454 att
->Renderbuffer
= rb
;
456 /* This can't get called on a texture renderbuffer, so set it to NULL
457 * for clarity compared to user renderbuffers.
459 rb
->AllocStorage
= NULL
;
461 rb
->NeedsFinishRenderTexture
= ctx
->Driver
.FinishRenderTexture
!= NULL
;
467 rb
->_BaseFormat
= texImage
->_BaseFormat
;
468 rb
->Format
= texImage
->TexFormat
;
469 rb
->InternalFormat
= texImage
->InternalFormat
;
470 rb
->Width
= texImage
->Width2
;
471 rb
->Height
= texImage
->Height2
;
472 rb
->Depth
= texImage
->Depth2
;
473 rb
->NumSamples
= texImage
->NumSamples
;
474 rb
->TexImage
= texImage
;
476 if (driver_RenderTexture_is_safe(att
))
477 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
481 * Bind a texture object to an attachment point.
482 * The previous binding, if any, will be removed first.
485 set_texture_attachment(struct gl_context
*ctx
,
486 struct gl_framebuffer
*fb
,
487 struct gl_renderbuffer_attachment
*att
,
488 struct gl_texture_object
*texObj
,
489 GLenum texTarget
, GLuint level
, GLuint layer
,
492 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
494 if (rb
&& rb
->NeedsFinishRenderTexture
)
495 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
497 if (att
->Texture
== texObj
) {
498 /* re-attaching same texture */
499 assert(att
->Type
== GL_TEXTURE
);
503 remove_attachment(ctx
, att
);
504 att
->Type
= GL_TEXTURE
;
505 assert(!att
->Texture
);
506 _mesa_reference_texobj(&att
->Texture
, texObj
);
508 invalidate_framebuffer(fb
);
510 /* always update these fields */
511 att
->TextureLevel
= level
;
512 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
513 att
->Zoffset
= layer
;
514 att
->Layered
= layered
;
515 att
->Complete
= GL_FALSE
;
517 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
522 * Bind a renderbuffer to an attachment point.
523 * The previous binding, if any, will be removed first.
526 set_renderbuffer_attachment(struct gl_context
*ctx
,
527 struct gl_renderbuffer_attachment
*att
,
528 struct gl_renderbuffer
*rb
)
530 /* XXX check if re-doing same attachment, exit early */
531 remove_attachment(ctx
, att
);
532 att
->Type
= GL_RENDERBUFFER_EXT
;
533 att
->Texture
= NULL
; /* just to be safe */
534 att
->Layered
= GL_FALSE
;
535 att
->Complete
= GL_FALSE
;
536 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
541 * Fallback for ctx->Driver.FramebufferRenderbuffer()
542 * Attach a renderbuffer object to a framebuffer object.
545 _mesa_FramebufferRenderbuffer_sw(struct gl_context
*ctx
,
546 struct gl_framebuffer
*fb
,
548 struct gl_renderbuffer
*rb
)
550 struct gl_renderbuffer_attachment
*att
;
552 mtx_lock(&fb
->Mutex
);
554 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
557 set_renderbuffer_attachment(ctx
, att
, rb
);
558 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
559 /* do stencil attachment here (depth already done above) */
560 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
562 set_renderbuffer_attachment(ctx
, att
, rb
);
564 rb
->AttachedAnytime
= GL_TRUE
;
567 remove_attachment(ctx
, att
);
568 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
569 /* detach stencil (depth was detached above) */
570 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
572 remove_attachment(ctx
, att
);
576 invalidate_framebuffer(fb
);
578 mtx_unlock(&fb
->Mutex
);
583 * Fallback for ctx->Driver.ValidateFramebuffer()
584 * Check if the renderbuffer's formats are supported by the software
586 * Drivers should probably override this.
589 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
592 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
593 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
595 switch (rb
->_BaseFormat
) {
597 case GL_LUMINANCE_ALPHA
:
602 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
606 switch (rb
->Format
) {
607 /* XXX This list is likely incomplete. */
608 case MESA_FORMAT_R9G9B9E5_FLOAT
:
609 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
612 /* render buffer format is supported by software rendering */
621 * Return true if the framebuffer has a combined depth/stencil
622 * renderbuffer attached.
625 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
627 const struct gl_renderbuffer_attachment
*depth
=
628 &fb
->Attachment
[BUFFER_DEPTH
];
629 const struct gl_renderbuffer_attachment
*stencil
=
630 &fb
->Attachment
[BUFFER_STENCIL
];
632 if (depth
->Type
== stencil
->Type
) {
633 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
634 depth
->Renderbuffer
== stencil
->Renderbuffer
)
637 if (depth
->Type
== GL_TEXTURE
&&
638 depth
->Texture
== stencil
->Texture
)
650 att_incomplete(const char *msg
)
652 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
653 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
662 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
664 static GLuint msg_id
;
666 _mesa_gl_debug(ctx
, &msg_id
,
667 MESA_DEBUG_SOURCE_API
,
668 MESA_DEBUG_TYPE_OTHER
,
669 MESA_DEBUG_SEVERITY_MEDIUM
,
670 "FBO incomplete: %s [%d]\n", msg
, index
);
672 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
673 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
679 * Is the given base format a legal format for a color renderbuffer?
682 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
684 switch (baseFormat
) {
689 case GL_LUMINANCE_ALPHA
:
692 return ctx
->API
== API_OPENGL_COMPAT
&&
693 ctx
->Extensions
.ARB_framebuffer_object
;
696 return ctx
->Extensions
.ARB_texture_rg
;
704 * Is the given base format a legal format for a color renderbuffer?
707 is_format_color_renderable(const struct gl_context
*ctx
, mesa_format format
,
708 GLenum internalFormat
)
710 const GLenum baseFormat
=
711 _mesa_get_format_base_format(format
);
714 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
715 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
719 /* Reject additional cases for GLES */
720 switch (internalFormat
) {
741 if (internalFormat
!= GL_RGB10_A2
&&
742 (format
== MESA_FORMAT_B10G10R10A2_UNORM
||
743 format
== MESA_FORMAT_B10G10R10X2_UNORM
||
744 format
== MESA_FORMAT_R10G10B10A2_UNORM
||
745 format
== MESA_FORMAT_R10G10B10X2_UNORM
)) {
754 * Is the given base format a legal format for a depth/stencil renderbuffer?
757 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
759 switch (baseFormat
) {
760 case GL_DEPTH_COMPONENT
:
761 case GL_DEPTH_STENCIL_EXT
:
770 * Test if an attachment point is complete and update its Complete field.
771 * \param format if GL_COLOR, this is a color attachment point,
772 * if GL_DEPTH, this is a depth component attachment point,
773 * if GL_STENCIL, this is a stencil component attachment point.
776 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
777 struct gl_renderbuffer_attachment
*att
)
779 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
781 /* assume complete */
782 att
->Complete
= GL_TRUE
;
784 /* Look for reasons why the attachment might be incomplete */
785 if (att
->Type
== GL_TEXTURE
) {
786 const struct gl_texture_object
*texObj
= att
->Texture
;
787 struct gl_texture_image
*texImage
;
791 att_incomplete("no texobj");
792 att
->Complete
= GL_FALSE
;
796 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
798 att_incomplete("no teximage");
799 att
->Complete
= GL_FALSE
;
802 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
803 att_incomplete("teximage width/height=0");
804 att
->Complete
= GL_FALSE
;
808 switch (texObj
->Target
) {
810 if (att
->Zoffset
>= texImage
->Depth
) {
811 att_incomplete("bad z offset");
812 att
->Complete
= GL_FALSE
;
816 case GL_TEXTURE_1D_ARRAY
:
817 if (att
->Zoffset
>= texImage
->Height
) {
818 att_incomplete("bad 1D-array layer");
819 att
->Complete
= GL_FALSE
;
823 case GL_TEXTURE_2D_ARRAY
:
824 if (att
->Zoffset
>= texImage
->Depth
) {
825 att_incomplete("bad 2D-array layer");
826 att
->Complete
= GL_FALSE
;
830 case GL_TEXTURE_CUBE_MAP_ARRAY
:
831 if (att
->Zoffset
>= texImage
->Depth
) {
832 att_incomplete("bad cube-array layer");
833 att
->Complete
= GL_FALSE
;
839 baseFormat
= texImage
->_BaseFormat
;
841 if (format
== GL_COLOR
) {
842 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
843 att_incomplete("bad format");
844 att
->Complete
= GL_FALSE
;
847 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
848 att_incomplete("compressed internalformat");
849 att
->Complete
= GL_FALSE
;
853 /* OES_texture_float allows creation and use of floating point
854 * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow
855 * these textures to be used as a render target, this is done via
856 * GL_EXT_color_buffer(_half)_float with set of new sized types.
858 if (_mesa_is_gles(ctx
) && (texImage
->TexObject
->_IsFloat
||
859 texImage
->TexObject
->_IsHalfFloat
)) {
860 att_incomplete("bad internal format");
861 att
->Complete
= GL_FALSE
;
865 else if (format
== GL_DEPTH
) {
866 if (baseFormat
== GL_DEPTH_COMPONENT
) {
869 else if (ctx
->Extensions
.ARB_depth_texture
&&
870 baseFormat
== GL_DEPTH_STENCIL
) {
874 att
->Complete
= GL_FALSE
;
875 att_incomplete("bad depth format");
880 assert(format
== GL_STENCIL
);
881 if (ctx
->Extensions
.ARB_depth_texture
&&
882 baseFormat
== GL_DEPTH_STENCIL
) {
884 } else if (ctx
->Extensions
.ARB_texture_stencil8
&&
885 baseFormat
== GL_STENCIL_INDEX
) {
888 /* no such thing as stencil-only textures */
889 att_incomplete("illegal stencil texture");
890 att
->Complete
= GL_FALSE
;
895 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
896 const GLenum baseFormat
= att
->Renderbuffer
->_BaseFormat
;
898 assert(att
->Renderbuffer
);
899 if (!att
->Renderbuffer
->InternalFormat
||
900 att
->Renderbuffer
->Width
< 1 ||
901 att
->Renderbuffer
->Height
< 1) {
902 att_incomplete("0x0 renderbuffer");
903 att
->Complete
= GL_FALSE
;
906 if (format
== GL_COLOR
) {
907 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
908 att_incomplete("bad renderbuffer color format");
909 att
->Complete
= GL_FALSE
;
913 else if (format
== GL_DEPTH
) {
914 if (baseFormat
== GL_DEPTH_COMPONENT
) {
917 else if (baseFormat
== GL_DEPTH_STENCIL
) {
921 att_incomplete("bad renderbuffer depth format");
922 att
->Complete
= GL_FALSE
;
927 assert(format
== GL_STENCIL
);
928 if (baseFormat
== GL_STENCIL_INDEX
||
929 baseFormat
== GL_DEPTH_STENCIL
) {
933 att
->Complete
= GL_FALSE
;
934 att_incomplete("bad renderbuffer stencil format");
940 assert(att
->Type
== GL_NONE
);
948 * Test if the given framebuffer object is complete and update its
949 * Status field with the results.
950 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
951 * driver to make hardware-specific validation/completeness checks.
952 * Also update the framebuffer's Width and Height fields if the
953 * framebuffer is complete.
956 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
957 struct gl_framebuffer
*fb
)
960 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
961 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
962 GLint numSamples
= -1;
963 GLint fixedSampleLocations
= -1;
966 /* Covers max_layer_count, is_layered, and layer_tex_target */
967 bool layer_info_valid
= false;
968 GLuint max_layer_count
= 0, att_layer_count
;
969 bool is_layered
= false;
970 GLenum layer_tex_target
= 0;
971 bool has_depth_attachment
= false;
972 bool has_stencil_attachment
= false;
974 assert(_mesa_is_user_fbo(fb
));
976 /* we're changing framebuffer fields here */
977 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
982 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
983 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
984 fb
->_HasAttachments
= true;
985 fb
->_IntegerBuffers
= 0;
987 /* Start at -2 to more easily loop over all attachment points.
992 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
993 struct gl_renderbuffer_attachment
*att
;
995 mesa_format attFormat
;
996 GLenum att_tex_target
= GL_NONE
;
999 * XXX for ARB_fbo, only check color buffers that are named by
1000 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
1003 /* check for attachment completeness
1006 att
= &fb
->Attachment
[BUFFER_DEPTH
];
1007 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
1008 if (!att
->Complete
) {
1009 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1010 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
1012 } else if (att
->Type
!= GL_NONE
) {
1013 has_depth_attachment
= true;
1017 att
= &fb
->Attachment
[BUFFER_STENCIL
];
1018 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
1019 if (!att
->Complete
) {
1020 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1021 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
1023 } else if (att
->Type
!= GL_NONE
) {
1024 has_stencil_attachment
= true;
1028 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
1029 test_attachment_completeness(ctx
, GL_COLOR
, att
);
1030 if (!att
->Complete
) {
1031 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1032 fbo_incomplete(ctx
, "color attachment incomplete", i
);
1037 /* get width, height, format of the renderbuffer/texture
1039 if (att
->Type
== GL_TEXTURE
) {
1040 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
1041 att_tex_target
= att
->Texture
->Target
;
1042 minWidth
= MIN2(minWidth
, texImg
->Width
);
1043 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
1044 minHeight
= MIN2(minHeight
, texImg
->Height
);
1045 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
1046 f
= texImg
->_BaseFormat
;
1047 attFormat
= texImg
->TexFormat
;
1050 if (!is_format_color_renderable(ctx
, attFormat
,
1051 texImg
->InternalFormat
) &&
1052 !is_legal_depth_format(ctx
, f
) &&
1053 f
!= GL_STENCIL_INDEX
) {
1054 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
;
1055 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
1060 numSamples
= texImg
->NumSamples
;
1061 else if (numSamples
!= texImg
->NumSamples
) {
1062 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1063 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1067 if (fixedSampleLocations
< 0)
1068 fixedSampleLocations
= texImg
->FixedSampleLocations
;
1069 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
1070 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1071 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1075 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1076 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
1077 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
1078 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
1079 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
1080 f
= att
->Renderbuffer
->InternalFormat
;
1081 attFormat
= att
->Renderbuffer
->Format
;
1085 numSamples
= att
->Renderbuffer
->NumSamples
;
1086 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
1087 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1088 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1092 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1093 if (fixedSampleLocations
< 0)
1094 fixedSampleLocations
= GL_TRUE
;
1095 else if (fixedSampleLocations
!= GL_TRUE
) {
1096 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1097 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1102 assert(att
->Type
== GL_NONE
);
1106 /* Update flags describing color buffer datatypes */
1108 GLenum type
= _mesa_get_format_datatype(attFormat
);
1110 /* check if integer color */
1111 if (_mesa_is_format_integer_color(attFormat
))
1112 fb
->_IntegerBuffers
|= (1 << i
);
1114 fb
->_AllColorBuffersFixedPoint
=
1115 fb
->_AllColorBuffersFixedPoint
&&
1116 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1118 fb
->_HasSNormOrFloatColorBuffer
=
1119 fb
->_HasSNormOrFloatColorBuffer
||
1120 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1123 /* Error-check width, height, format */
1124 if (numImages
== 1) {
1131 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1132 /* check that width, height, format are same */
1133 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1134 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1135 fbo_incomplete(ctx
, "width or height mismatch", -1);
1138 /* check that all color buffers are the same format */
1139 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1140 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1141 fbo_incomplete(ctx
, "format mismatch", -1);
1147 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1149 if (att
->Type
== GL_RENDERBUFFER
&&
1150 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1151 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1152 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1156 /* Check that layered rendering is consistent. */
1158 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1159 att_layer_count
= 6;
1160 else if (att_tex_target
== GL_TEXTURE_1D_ARRAY
)
1161 att_layer_count
= att
->Renderbuffer
->Height
;
1163 att_layer_count
= att
->Renderbuffer
->Depth
;
1165 att_layer_count
= 0;
1167 if (!layer_info_valid
) {
1168 is_layered
= att
->Layered
;
1169 max_layer_count
= att_layer_count
;
1170 layer_tex_target
= att_tex_target
;
1171 layer_info_valid
= true;
1172 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1173 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1174 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1176 } else if (is_layered
!= att
->Layered
) {
1177 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1179 "framebuffer attachment layer mode is inconsistent",
1182 } else if (att_layer_count
> max_layer_count
) {
1183 max_layer_count
= att_layer_count
;
1187 * The extension GL_ARB_framebuffer_no_attachments places additional
1188 * requirement on each attachment. Those additional requirements are
1189 * tighter that those of previous versions of GL. In interest of better
1190 * compatibility, we will not enforce these restrictions. For the record
1191 * those additional restrictions are quoted below:
1193 * "The width and height of image are greater than zero and less than or
1194 * equal to the values of the implementation-dependent limits
1195 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1197 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1198 * array texture and the attachment is layered, the depth or layer count
1199 * of the texture is less than or equal to the implementation-dependent
1200 * limit MAX_FRAMEBUFFER_LAYERS."
1202 * "If image has multiple samples, its sample count is less than or equal
1203 * to the value of the implementation-dependent limit
1204 * MAX_FRAMEBUFFER_SAMPLES."
1206 * The same requirements are also in place for GL 4.5,
1207 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1211 fb
->MaxNumLayers
= max_layer_count
;
1213 if (numImages
== 0) {
1214 fb
->_HasAttachments
= false;
1216 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1217 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1218 fbo_incomplete(ctx
, "no attachments", -1);
1222 if (fb
->DefaultGeometry
.Width
== 0 || fb
->DefaultGeometry
.Height
== 0) {
1223 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1224 fbo_incomplete(ctx
, "no attachments and default width or height is 0", -1);
1229 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1230 /* Check that all DrawBuffers are present */
1231 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1232 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1233 const struct gl_renderbuffer_attachment
*att
1234 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
], NULL
);
1236 if (att
->Type
== GL_NONE
) {
1237 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1238 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1244 /* Check that the ReadBuffer is present */
1245 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1246 const struct gl_renderbuffer_attachment
*att
1247 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
, NULL
);
1249 if (att
->Type
== GL_NONE
) {
1250 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1251 fbo_incomplete(ctx
, "missing readbuffer", -1);
1257 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1259 * "Depth and stencil attachments, if present, are the same image."
1261 * This restriction is not present in the OpenGL ES2 spec.
1263 if (_mesa_is_gles3(ctx
) &&
1264 has_stencil_attachment
&& has_depth_attachment
&&
1265 !_mesa_has_depthstencil_combined(fb
)) {
1266 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1267 fbo_incomplete(ctx
, "Depth and stencil attachments must be the same image", -1);
1271 /* Provisionally set status = COMPLETE ... */
1272 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1274 /* ... but the driver may say the FB is incomplete.
1275 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1278 if (ctx
->Driver
.ValidateFramebuffer
) {
1279 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1280 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1281 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1287 * Note that if ARB_framebuffer_object is supported and the attached
1288 * renderbuffers/textures are different sizes, the framebuffer
1289 * width/height will be set to the smallest width/height.
1291 if (numImages
!= 0) {
1292 fb
->Width
= minWidth
;
1293 fb
->Height
= minHeight
;
1296 /* finally, update the visual info for the framebuffer */
1297 _mesa_update_framebuffer_visual(ctx
, fb
);
1301 GLboolean GLAPIENTRY
1302 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1304 struct gl_renderbuffer
*rb
;
1306 GET_CURRENT_CONTEXT(ctx
);
1308 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1310 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1311 return rb
!= NULL
&& rb
!= &DummyRenderbuffer
;
1315 static struct gl_renderbuffer
*
1316 allocate_renderbuffer_locked(struct gl_context
*ctx
, GLuint renderbuffer
,
1319 struct gl_renderbuffer
*newRb
;
1321 /* create new renderbuffer object */
1322 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1324 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1327 assert(newRb
->AllocStorage
);
1328 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1335 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1337 struct gl_renderbuffer
*newRb
;
1338 GET_CURRENT_CONTEXT(ctx
);
1340 if (target
!= GL_RENDERBUFFER_EXT
) {
1341 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1345 /* No need to flush here since the render buffer binding has no
1346 * effect on rendering state.
1350 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1351 if (newRb
== &DummyRenderbuffer
) {
1352 /* ID was reserved, but no real renderbuffer object made yet */
1355 else if (!newRb
&& !allow_user_names
) {
1356 /* All RB IDs must be Gen'd */
1357 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1362 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1363 newRb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
1364 "glBindRenderbufferEXT");
1365 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1372 assert(newRb
!= &DummyRenderbuffer
);
1374 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1378 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1380 GET_CURRENT_CONTEXT(ctx
);
1382 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1383 * entry point, but they allow the use of user-generated names.
1385 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1389 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1391 /* This function should not be in the dispatch table for core profile /
1392 * OpenGL 3.1, so execution should never get here in those cases -- no
1393 * need for an explicit test.
1395 bind_renderbuffer(target
, renderbuffer
, true);
1399 * ARB_framebuffer_no_attachment - Application passes requested param's
1400 * here. NOTE: NumSamples requested need not be _NumSamples which is
1401 * what the hw supports.
1404 framebuffer_parameteri(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1405 GLenum pname
, GLint param
, const char *func
)
1408 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1409 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferWidth
)
1410 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1412 fb
->DefaultGeometry
.Width
= param
;
1414 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1415 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferHeight
)
1416 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1418 fb
->DefaultGeometry
.Height
= param
;
1420 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1422 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1423 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1425 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1426 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1429 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferLayers
)
1430 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1432 fb
->DefaultGeometry
.Layers
= param
;
1434 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1435 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferSamples
)
1436 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1438 fb
->DefaultGeometry
.NumSamples
= param
;
1440 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1441 fb
->DefaultGeometry
.FixedSampleLocations
= param
;
1444 _mesa_error(ctx
, GL_INVALID_ENUM
,
1445 "%s(pname=0x%x)", func
, pname
);
1448 invalidate_framebuffer(fb
);
1449 ctx
->NewState
|= _NEW_BUFFERS
;
1453 _mesa_FramebufferParameteri(GLenum target
, GLenum pname
, GLint param
)
1455 GET_CURRENT_CONTEXT(ctx
);
1456 struct gl_framebuffer
*fb
;
1458 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1459 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1460 "glFramebufferParameteriv not supported "
1461 "(ARB_framebuffer_no_attachments not implemented)");
1465 fb
= get_framebuffer_target(ctx
, target
);
1467 _mesa_error(ctx
, GL_INVALID_ENUM
,
1468 "glFramebufferParameteri(target=0x%x)", target
);
1472 /* check framebuffer binding */
1473 if (_mesa_is_winsys_fbo(fb
)) {
1474 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1475 "glFramebufferParameteri");
1479 framebuffer_parameteri(ctx
, fb
, pname
, param
, "glFramebufferParameteri");
1483 _pname_valid_for_default_framebuffer(struct gl_context
*ctx
,
1486 if (!_mesa_is_desktop_gl(ctx
))
1490 case GL_DOUBLEBUFFER
:
1491 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1492 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1494 case GL_SAMPLE_BUFFERS
:
1503 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1504 GLenum pname
, GLint
*params
, const char *func
)
1506 /* From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries:
1508 * "An INVALID_OPERATION error is generated by GetFramebufferParameteriv
1509 * if the default framebuffer is bound to target and pname is not one
1510 * of the accepted values from table 23.73, other than
1513 * For OpenGL ES, using default framebuffer still raises INVALID_OPERATION
1516 if (_mesa_is_winsys_fbo(fb
) &&
1517 !_pname_valid_for_default_framebuffer(ctx
, pname
)) {
1518 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1519 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1524 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1525 *params
= fb
->DefaultGeometry
.Width
;
1527 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1528 *params
= fb
->DefaultGeometry
.Height
;
1530 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1532 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1533 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1535 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1536 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1539 *params
= fb
->DefaultGeometry
.Layers
;
1541 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1542 *params
= fb
->DefaultGeometry
.NumSamples
;
1544 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1545 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1547 case GL_DOUBLEBUFFER
:
1548 *params
= fb
->Visual
.doubleBufferMode
;
1550 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1551 *params
= _mesa_get_color_read_format(ctx
, fb
, func
);
1553 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1554 *params
= _mesa_get_color_read_type(ctx
, fb
, func
);
1557 *params
= _mesa_geometric_samples(fb
);
1559 case GL_SAMPLE_BUFFERS
:
1560 *params
= _mesa_geometric_samples(fb
) > 0;
1563 *params
= fb
->Visual
.stereoMode
;
1566 _mesa_error(ctx
, GL_INVALID_ENUM
,
1567 "%s(pname=0x%x)", func
, pname
);
1572 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1574 GET_CURRENT_CONTEXT(ctx
);
1575 struct gl_framebuffer
*fb
;
1577 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1578 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1579 "glGetFramebufferParameteriv not supported "
1580 "(ARB_framebuffer_no_attachments not implemented)");
1584 fb
= get_framebuffer_target(ctx
, target
);
1586 _mesa_error(ctx
, GL_INVALID_ENUM
,
1587 "glGetFramebufferParameteriv(target=0x%x)", target
);
1591 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1592 "glGetFramebufferParameteriv");
1597 * Remove the specified renderbuffer or texture from any attachment point in
1601 * \c true if the renderbuffer was detached from an attachment point. \c
1605 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1606 struct gl_framebuffer
*fb
,
1610 bool progress
= false;
1612 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1613 if (fb
->Attachment
[i
].Texture
== att
1614 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1615 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1620 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1621 * Completeness," of the OpenGL 3.1 spec says:
1623 * "Performing any of the following actions may change whether the
1624 * framebuffer is considered complete or incomplete:
1628 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1629 * containing an image that is attached to a framebuffer object
1630 * that is bound to the framebuffer."
1633 invalidate_framebuffer(fb
);
1640 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1643 GET_CURRENT_CONTEXT(ctx
);
1646 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1650 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1652 for (i
= 0; i
< n
; i
++) {
1653 if (renderbuffers
[i
] > 0) {
1654 struct gl_renderbuffer
*rb
;
1655 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1657 /* check if deleting currently bound renderbuffer object */
1658 if (rb
== ctx
->CurrentRenderbuffer
) {
1660 assert(rb
->RefCount
>= 2);
1661 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1664 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1665 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1666 * of the OpenGL 3.1 spec says:
1668 * "If a renderbuffer object is deleted while its image is
1669 * attached to one or more attachment points in the currently
1670 * bound framebuffer, then it is as if FramebufferRenderbuffer
1671 * had been called, with a renderbuffer of 0, for each
1672 * attachment point to which this image was attached in the
1673 * currently bound framebuffer. In other words, this
1674 * renderbuffer image is first detached from all attachment
1675 * points in the currently bound framebuffer. Note that the
1676 * renderbuffer image is specifically not detached from any
1677 * non-bound framebuffers. Detaching the image from any
1678 * non-bound framebuffers is the responsibility of the
1681 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1682 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1684 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1685 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1686 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1689 /* Remove from hash table immediately, to free the ID.
1690 * But the object will not be freed until it's no longer
1691 * referenced anywhere else.
1693 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1695 if (rb
!= &DummyRenderbuffer
) {
1696 /* no longer referenced by hash table */
1697 _mesa_reference_renderbuffer(&rb
, NULL
);
1705 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1708 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1715 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1717 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1719 for (i
= 0; i
< n
; i
++) {
1720 GLuint name
= first
+ i
;
1721 renderbuffers
[i
] = name
;
1724 allocate_renderbuffer_locked(ctx
, name
, func
);
1726 /* insert a dummy renderbuffer into the hash table */
1727 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1728 &DummyRenderbuffer
);
1732 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1737 create_render_buffers_err(struct gl_context
*ctx
, GLsizei n
,
1738 GLuint
*renderbuffers
, bool dsa
)
1740 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1743 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1747 create_render_buffers(ctx
, n
, renderbuffers
, dsa
);
1752 _mesa_GenRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1754 GET_CURRENT_CONTEXT(ctx
);
1755 create_render_buffers(ctx
, n
, renderbuffers
, false);
1760 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1762 GET_CURRENT_CONTEXT(ctx
);
1763 create_render_buffers_err(ctx
, n
, renderbuffers
, false);
1768 _mesa_CreateRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1770 GET_CURRENT_CONTEXT(ctx
);
1771 create_render_buffers(ctx
, n
, renderbuffers
, true);
1776 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1778 GET_CURRENT_CONTEXT(ctx
);
1779 create_render_buffers_err(ctx
, n
, renderbuffers
, true);
1784 * Given an internal format token for a render buffer, return the
1785 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1786 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1787 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1789 * This is similar to _mesa_base_tex_format() but the set of valid
1790 * internal formats is different.
1792 * Note that even if a format is determined to be legal here, validation
1793 * of the FBO may fail if the format is not supported by the driver/GPU.
1795 * \param internalFormat as passed to glRenderbufferStorage()
1796 * \return the base internal format, or 0 if internalFormat is illegal
1799 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1802 * Notes: some formats such as alpha, luminance, etc. were added
1803 * with GL_ARB_framebuffer_object.
1805 switch (internalFormat
) {
1811 return (ctx
->API
== API_OPENGL_COMPAT
&&
1812 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
1816 case GL_LUMINANCE12
:
1817 case GL_LUMINANCE16
:
1818 return (ctx
->API
== API_OPENGL_COMPAT
&&
1819 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
1820 case GL_LUMINANCE_ALPHA
:
1821 case GL_LUMINANCE4_ALPHA4
:
1822 case GL_LUMINANCE6_ALPHA2
:
1823 case GL_LUMINANCE8_ALPHA8
:
1824 case GL_LUMINANCE12_ALPHA4
:
1825 case GL_LUMINANCE12_ALPHA12
:
1826 case GL_LUMINANCE16_ALPHA16
:
1827 return (ctx
->API
== API_OPENGL_COMPAT
&&
1828 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
1832 case GL_INTENSITY12
:
1833 case GL_INTENSITY16
:
1834 return (ctx
->API
== API_OPENGL_COMPAT
&&
1835 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
1845 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1847 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1856 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1858 case GL_SRGB8_ALPHA8_EXT
:
1859 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1860 case GL_STENCIL_INDEX
:
1861 case GL_STENCIL_INDEX1_EXT
:
1862 case GL_STENCIL_INDEX4_EXT
:
1863 case GL_STENCIL_INDEX16_EXT
:
1864 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1865 * OpenGL ES, but Mesa does not currently support them.
1867 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1868 case GL_STENCIL_INDEX8_EXT
:
1869 return GL_STENCIL_INDEX
;
1870 case GL_DEPTH_COMPONENT
:
1871 case GL_DEPTH_COMPONENT32
:
1872 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1873 case GL_DEPTH_COMPONENT16
:
1874 case GL_DEPTH_COMPONENT24
:
1875 return GL_DEPTH_COMPONENT
;
1876 case GL_DEPTH_STENCIL
:
1877 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
1878 case GL_DEPTH24_STENCIL8
:
1879 return GL_DEPTH_STENCIL
;
1880 case GL_DEPTH_COMPONENT32F
:
1881 return ctx
->Version
>= 30
1882 || (ctx
->API
== API_OPENGL_COMPAT
&&
1883 ctx
->Extensions
.ARB_depth_buffer_float
)
1884 ? GL_DEPTH_COMPONENT
: 0;
1885 case GL_DEPTH32F_STENCIL8
:
1886 return ctx
->Version
>= 30
1887 || (ctx
->API
== API_OPENGL_COMPAT
&&
1888 ctx
->Extensions
.ARB_depth_buffer_float
)
1889 ? GL_DEPTH_STENCIL
: 0;
1892 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1895 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1899 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1902 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1904 /* signed normalized texture formats */
1908 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1913 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1917 case GL_RGB16_SNORM
:
1918 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1921 case GL_RGBA8_SNORM
:
1922 case GL_RGBA16_SNORM
:
1923 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1925 case GL_ALPHA_SNORM
:
1926 case GL_ALPHA8_SNORM
:
1927 case GL_ALPHA16_SNORM
:
1928 return ctx
->API
== API_OPENGL_COMPAT
&&
1929 ctx
->Extensions
.EXT_texture_snorm
&&
1930 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1931 case GL_LUMINANCE_SNORM
:
1932 case GL_LUMINANCE8_SNORM
:
1933 case GL_LUMINANCE16_SNORM
:
1934 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1936 case GL_LUMINANCE_ALPHA_SNORM
:
1937 case GL_LUMINANCE8_ALPHA8_SNORM
:
1938 case GL_LUMINANCE16_ALPHA16_SNORM
:
1939 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1940 ? GL_LUMINANCE_ALPHA
: 0;
1941 case GL_INTENSITY_SNORM
:
1942 case GL_INTENSITY8_SNORM
:
1943 case GL_INTENSITY16_SNORM
:
1944 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1949 return ((_mesa_is_desktop_gl(ctx
) &&
1950 ctx
->Extensions
.ARB_texture_rg
&&
1951 ctx
->Extensions
.ARB_texture_float
) ||
1952 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1956 return ((_mesa_is_desktop_gl(ctx
) &&
1957 ctx
->Extensions
.ARB_texture_rg
&&
1958 ctx
->Extensions
.ARB_texture_float
) ||
1959 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1963 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1967 return ((_mesa_is_desktop_gl(ctx
) &&
1968 ctx
->Extensions
.ARB_texture_float
) ||
1969 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1971 case GL_ALPHA16F_ARB
:
1972 case GL_ALPHA32F_ARB
:
1973 return ctx
->API
== API_OPENGL_COMPAT
&&
1974 ctx
->Extensions
.ARB_texture_float
&&
1975 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1976 case GL_LUMINANCE16F_ARB
:
1977 case GL_LUMINANCE32F_ARB
:
1978 return ctx
->API
== API_OPENGL_COMPAT
&&
1979 ctx
->Extensions
.ARB_texture_float
&&
1980 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1981 case GL_LUMINANCE_ALPHA16F_ARB
:
1982 case GL_LUMINANCE_ALPHA32F_ARB
:
1983 return ctx
->API
== API_OPENGL_COMPAT
&&
1984 ctx
->Extensions
.ARB_texture_float
&&
1985 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1986 case GL_INTENSITY16F_ARB
:
1987 case GL_INTENSITY32F_ARB
:
1988 return ctx
->API
== API_OPENGL_COMPAT
&&
1989 ctx
->Extensions
.ARB_texture_float
&&
1990 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1991 case GL_R11F_G11F_B10F
:
1992 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1993 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1996 case GL_RGBA8UI_EXT
:
1997 case GL_RGBA16UI_EXT
:
1998 case GL_RGBA32UI_EXT
:
2000 case GL_RGBA16I_EXT
:
2001 case GL_RGBA32I_EXT
:
2002 return ctx
->Version
>= 30
2003 || (_mesa_is_desktop_gl(ctx
) &&
2004 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
2007 case GL_RGB16UI_EXT
:
2008 case GL_RGB32UI_EXT
:
2012 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
2020 return ctx
->Version
>= 30
2021 || (_mesa_is_desktop_gl(ctx
) &&
2022 ctx
->Extensions
.ARB_texture_rg
&&
2023 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
2031 return ctx
->Version
>= 30
2032 || (_mesa_is_desktop_gl(ctx
) &&
2033 ctx
->Extensions
.ARB_texture_rg
&&
2034 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
2036 case GL_INTENSITY8I_EXT
:
2037 case GL_INTENSITY8UI_EXT
:
2038 case GL_INTENSITY16I_EXT
:
2039 case GL_INTENSITY16UI_EXT
:
2040 case GL_INTENSITY32I_EXT
:
2041 case GL_INTENSITY32UI_EXT
:
2042 return ctx
->API
== API_OPENGL_COMPAT
&&
2043 ctx
->Extensions
.EXT_texture_integer
&&
2044 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2046 case GL_LUMINANCE8I_EXT
:
2047 case GL_LUMINANCE8UI_EXT
:
2048 case GL_LUMINANCE16I_EXT
:
2049 case GL_LUMINANCE16UI_EXT
:
2050 case GL_LUMINANCE32I_EXT
:
2051 case GL_LUMINANCE32UI_EXT
:
2052 return ctx
->API
== API_OPENGL_COMPAT
&&
2053 ctx
->Extensions
.EXT_texture_integer
&&
2054 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2056 case GL_LUMINANCE_ALPHA8I_EXT
:
2057 case GL_LUMINANCE_ALPHA8UI_EXT
:
2058 case GL_LUMINANCE_ALPHA16I_EXT
:
2059 case GL_LUMINANCE_ALPHA16UI_EXT
:
2060 case GL_LUMINANCE_ALPHA32I_EXT
:
2061 case GL_LUMINANCE_ALPHA32UI_EXT
:
2062 return ctx
->API
== API_OPENGL_COMPAT
&&
2063 ctx
->Extensions
.EXT_texture_integer
&&
2064 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2066 case GL_ALPHA8I_EXT
:
2067 case GL_ALPHA8UI_EXT
:
2068 case GL_ALPHA16I_EXT
:
2069 case GL_ALPHA16UI_EXT
:
2070 case GL_ALPHA32I_EXT
:
2071 case GL_ALPHA32UI_EXT
:
2072 return ctx
->API
== API_OPENGL_COMPAT
&&
2073 ctx
->Extensions
.EXT_texture_integer
&&
2074 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2077 return (_mesa_is_desktop_gl(ctx
) &&
2078 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
2079 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2082 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2091 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2094 invalidate_rb(GLuint key
, void *data
, void *userData
)
2096 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2097 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2099 /* If this is a user-created FBO */
2100 if (_mesa_is_user_fbo(fb
)) {
2102 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2103 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2104 if (att
->Type
== GL_RENDERBUFFER
&&
2105 att
->Renderbuffer
== rb
) {
2106 /* Mark fb status as indeterminate to force re-validation */
2115 /** sentinal value, see below */
2116 #define NO_SAMPLES 1000
2119 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2120 GLenum internalFormat
, GLsizei width
,
2121 GLsizei height
, GLsizei samples
)
2123 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2125 assert(baseFormat
!= 0);
2126 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2127 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2128 assert(samples
!= NO_SAMPLES
);
2130 assert(samples
> 0);
2131 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2132 internalFormat
, samples
) == GL_NO_ERROR
);
2135 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2137 if (rb
->InternalFormat
== internalFormat
&&
2138 rb
->Width
== (GLuint
) width
&&
2139 rb
->Height
== (GLuint
) height
&&
2140 rb
->NumSamples
== samples
) {
2141 /* no change in allocation needed */
2145 /* These MUST get set by the AllocStorage func */
2146 rb
->Format
= MESA_FORMAT_NONE
;
2147 rb
->NumSamples
= samples
;
2149 /* Now allocate the storage */
2150 assert(rb
->AllocStorage
);
2151 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2152 /* No error - check/set fields now */
2153 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2154 assert(rb
->Width
== (GLuint
) width
);
2155 assert(rb
->Height
== (GLuint
) height
);
2156 rb
->InternalFormat
= internalFormat
;
2157 rb
->_BaseFormat
= baseFormat
;
2158 assert(rb
->_BaseFormat
!= 0);
2161 /* Probably ran out of memory - clear the fields */
2164 rb
->Format
= MESA_FORMAT_NONE
;
2165 rb
->InternalFormat
= GL_NONE
;
2166 rb
->_BaseFormat
= GL_NONE
;
2170 /* Invalidate the framebuffers the renderbuffer is attached in. */
2171 if (rb
->AttachedAnytime
) {
2172 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2177 * Helper function used by renderbuffer_storage_direct() and
2178 * renderbuffer_storage_target().
2179 * samples will be NO_SAMPLES if called by a non-multisample function.
2182 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2183 GLenum internalFormat
, GLsizei width
,
2184 GLsizei height
, GLsizei samples
, const char *func
)
2187 GLenum sample_count_error
;
2189 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2190 if (baseFormat
== 0) {
2191 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2192 func
, _mesa_enum_to_string(internalFormat
));
2196 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2197 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2202 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2203 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2208 if (samples
== NO_SAMPLES
) {
2209 /* NumSamples == 0 indicates non-multisampling */
2213 /* check the sample count;
2214 * note: driver may choose to use more samples than what's requested
2216 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2217 internalFormat
, samples
);
2219 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2221 * "If a negative number is provided where an argument of type sizei or
2222 * sizeiptr is specified, the error INVALID VALUE is generated."
2225 sample_count_error
= GL_INVALID_VALUE
;
2228 if (sample_count_error
!= GL_NO_ERROR
) {
2229 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
2234 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
);
2238 * Helper function used by _mesa_NamedRenderbufferStorage*().
2239 * samples will be NO_SAMPLES if called by a non-multisample function.
2242 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2243 GLsizei width
, GLsizei height
, GLsizei samples
,
2246 GET_CURRENT_CONTEXT(ctx
);
2248 if (MESA_VERBOSE
& VERBOSE_API
) {
2249 if (samples
== NO_SAMPLES
)
2250 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2252 _mesa_enum_to_string(internalFormat
),
2255 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2257 _mesa_enum_to_string(internalFormat
),
2258 width
, height
, samples
);
2261 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2262 if (!rb
|| rb
== &DummyRenderbuffer
) {
2263 /* ID was reserved, but no real renderbuffer object made yet */
2264 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2265 func
, renderbuffer
);
2269 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
, func
);
2273 * Helper function used by _mesa_RenderbufferStorage() and
2274 * _mesa_RenderbufferStorageMultisample().
2275 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2278 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2279 GLsizei width
, GLsizei height
, GLsizei samples
,
2282 GET_CURRENT_CONTEXT(ctx
);
2284 if (MESA_VERBOSE
& VERBOSE_API
) {
2285 if (samples
== NO_SAMPLES
)
2286 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2288 _mesa_enum_to_string(target
),
2289 _mesa_enum_to_string(internalFormat
),
2292 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2294 _mesa_enum_to_string(target
),
2295 _mesa_enum_to_string(internalFormat
),
2296 width
, height
, samples
);
2299 if (target
!= GL_RENDERBUFFER_EXT
) {
2300 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2304 if (!ctx
->CurrentRenderbuffer
) {
2305 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2310 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2311 height
, samples
, func
);
2316 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2318 struct gl_renderbuffer
*rb
;
2319 GET_CURRENT_CONTEXT(ctx
);
2321 if (!ctx
->Extensions
.OES_EGL_image
) {
2322 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2323 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2327 if (target
!= GL_RENDERBUFFER
) {
2328 _mesa_error(ctx
, GL_INVALID_ENUM
,
2329 "EGLImageTargetRenderbufferStorageOES");
2333 rb
= ctx
->CurrentRenderbuffer
;
2335 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2336 "EGLImageTargetRenderbufferStorageOES");
2340 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2342 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2347 * Helper function for _mesa_GetRenderbufferParameteriv() and
2348 * _mesa_GetFramebufferAttachmentParameteriv()
2349 * We have to be careful to respect the base format. For example, if a
2350 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2351 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2352 * we need to return zero.
2355 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2357 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2358 return _mesa_get_format_bits(format
, pname
);
2366 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2367 GLsizei width
, GLsizei height
)
2369 /* GL_ARB_fbo says calling this function is equivalent to calling
2370 * glRenderbufferStorageMultisample() with samples=0. We pass in
2371 * a token value here just for error reporting purposes.
2373 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2374 NO_SAMPLES
, "glRenderbufferStorage");
2379 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2380 GLenum internalFormat
,
2381 GLsizei width
, GLsizei height
)
2383 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2384 samples
, "glRenderbufferStorageMultisample");
2389 * OpenGL ES version of glRenderBufferStorage.
2392 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2393 GLsizei width
, GLsizei height
)
2395 switch (internalFormat
) {
2397 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2398 /* choose a closest format */
2399 internalFormat
= GL_RGB5
;
2405 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0,
2406 "glRenderbufferStorageEXT");
2410 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2411 GLsizei width
, GLsizei height
)
2413 /* GL_ARB_fbo says calling this function is equivalent to calling
2414 * glRenderbufferStorageMultisample() with samples=0. We pass in
2415 * a token value here just for error reporting purposes.
2417 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2418 NO_SAMPLES
, "glNamedRenderbufferStorage");
2422 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2423 GLenum internalformat
,
2424 GLsizei width
, GLsizei height
)
2426 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2428 "glNamedRenderbufferStorageMultisample");
2433 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2434 struct gl_renderbuffer
*rb
, GLenum pname
,
2435 GLint
*params
, const char *func
)
2437 /* No need to flush here since we're just quering state which is
2438 * not effected by rendering.
2442 case GL_RENDERBUFFER_WIDTH_EXT
:
2443 *params
= rb
->Width
;
2445 case GL_RENDERBUFFER_HEIGHT_EXT
:
2446 *params
= rb
->Height
;
2448 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2449 *params
= rb
->InternalFormat
;
2451 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2452 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2453 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2454 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2455 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2456 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2457 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2459 case GL_RENDERBUFFER_SAMPLES
:
2460 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2461 || _mesa_is_gles3(ctx
)) {
2462 *params
= rb
->NumSamples
;
2467 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2468 _mesa_enum_to_string(pname
));
2475 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2477 GET_CURRENT_CONTEXT(ctx
);
2479 if (target
!= GL_RENDERBUFFER_EXT
) {
2480 _mesa_error(ctx
, GL_INVALID_ENUM
,
2481 "glGetRenderbufferParameterivEXT(target)");
2485 if (!ctx
->CurrentRenderbuffer
) {
2486 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2487 "(no renderbuffer bound)");
2491 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2492 params
, "glGetRenderbufferParameteriv");
2497 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2500 GET_CURRENT_CONTEXT(ctx
);
2502 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2503 if (!rb
|| rb
== &DummyRenderbuffer
) {
2504 /* ID was reserved, but no real renderbuffer object made yet */
2505 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2506 "(invalid renderbuffer %i)", renderbuffer
);
2510 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2511 "glGetNamedRenderbufferParameteriv");
2515 GLboolean GLAPIENTRY
2516 _mesa_IsFramebuffer(GLuint framebuffer
)
2518 GET_CURRENT_CONTEXT(ctx
);
2519 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2521 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2522 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2530 * Check if any of the attachments of the given framebuffer are textures
2531 * (render to texture). Call ctx->Driver.RenderTexture() for such
2535 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2538 assert(ctx
->Driver
.RenderTexture
);
2540 if (_mesa_is_winsys_fbo(fb
))
2541 return; /* can't render to texture with winsys framebuffers */
2543 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2544 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2545 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2546 && driver_RenderTexture_is_safe(att
)) {
2547 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2554 * Examine all the framebuffer's attachments to see if any are textures.
2555 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2556 * notify the device driver that the texture image may have changed.
2559 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2561 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2562 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2565 if (ctx
->Driver
.FinishRenderTexture
) {
2567 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2568 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2569 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2570 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2571 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2579 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2581 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2582 GLboolean bindReadBuf
, bindDrawBuf
;
2583 GET_CURRENT_CONTEXT(ctx
);
2586 case GL_DRAW_FRAMEBUFFER_EXT
:
2587 bindDrawBuf
= GL_TRUE
;
2588 bindReadBuf
= GL_FALSE
;
2590 case GL_READ_FRAMEBUFFER_EXT
:
2591 bindDrawBuf
= GL_FALSE
;
2592 bindReadBuf
= GL_TRUE
;
2594 case GL_FRAMEBUFFER_EXT
:
2595 bindDrawBuf
= GL_TRUE
;
2596 bindReadBuf
= GL_TRUE
;
2599 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2604 /* Binding a user-created framebuffer object */
2605 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2606 if (newDrawFb
== &DummyFramebuffer
) {
2607 /* ID was reserved, but no real framebuffer object made yet */
2610 else if (!newDrawFb
&& !allow_user_names
) {
2611 /* All FBO IDs must be Gen'd */
2612 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2617 /* create new framebuffer object */
2618 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2620 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2623 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2625 newReadFb
= newDrawFb
;
2628 /* Binding the window system framebuffer (which was originally set
2629 * with MakeCurrent).
2631 newDrawFb
= ctx
->WinSysDrawBuffer
;
2632 newReadFb
= ctx
->WinSysReadBuffer
;
2635 _mesa_bind_framebuffers(ctx
,
2636 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2637 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2641 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2642 struct gl_framebuffer
*newDrawFb
,
2643 struct gl_framebuffer
*newReadFb
)
2645 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
2646 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
2647 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
2648 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
2651 assert(newDrawFb
!= &DummyFramebuffer
);
2654 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2656 * We also check if we're beginning and/or ending render-to-texture.
2657 * When a framebuffer with texture attachments is unbound, call
2658 * ctx->Driver.FinishRenderTexture().
2659 * When a framebuffer with texture attachments is bound, call
2660 * ctx->Driver.RenderTexture().
2662 * Note that if the ReadBuffer has texture attachments we don't consider
2663 * that a render-to-texture case.
2666 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2668 /* check if old readbuffer was render-to-texture */
2669 check_end_texture_render(ctx
, oldReadFb
);
2671 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2675 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2677 /* check if old framebuffer had any texture attachments */
2679 check_end_texture_render(ctx
, oldDrawFb
);
2681 /* check if newly bound framebuffer has any texture attachments */
2682 check_begin_texture_render(ctx
, newDrawFb
);
2684 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2687 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2688 /* The few classic drivers that actually hook this function really only
2689 * want to know if the draw framebuffer changed.
2691 ctx
->Driver
.BindFramebuffer(ctx
,
2692 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
2693 newDrawFb
, newReadFb
);
2698 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2700 GET_CURRENT_CONTEXT(ctx
);
2702 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2703 * point, but they allow the use of user-generated names.
2705 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2710 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2712 /* This function should not be in the dispatch table for core profile /
2713 * OpenGL 3.1, so execution should never get here in those cases -- no
2714 * need for an explicit test.
2716 bind_framebuffer(target
, framebuffer
, true);
2721 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2724 GET_CURRENT_CONTEXT(ctx
);
2727 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
2731 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2733 for (i
= 0; i
< n
; i
++) {
2734 if (framebuffers
[i
] > 0) {
2735 struct gl_framebuffer
*fb
;
2736 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2738 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2740 /* check if deleting currently bound framebuffer object */
2741 if (fb
== ctx
->DrawBuffer
) {
2743 assert(fb
->RefCount
>= 2);
2744 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2746 if (fb
== ctx
->ReadBuffer
) {
2748 assert(fb
->RefCount
>= 2);
2749 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2752 /* remove from hash table immediately, to free the ID */
2753 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2755 if (fb
!= &DummyFramebuffer
) {
2756 /* But the object will not be freed until it's no longer
2757 * bound in any context.
2759 _mesa_reference_framebuffer(&fb
, NULL
);
2768 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2769 * It is not exposed to the rest of Mesa to encourage the use of
2770 * nameless buffers in driver internals.
2773 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
2775 GET_CURRENT_CONTEXT(ctx
);
2778 struct gl_framebuffer
*fb
;
2780 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
2783 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
2790 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
2792 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2794 for (i
= 0; i
< n
; i
++) {
2795 GLuint name
= first
+ i
;
2796 framebuffers
[i
] = name
;
2799 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
2801 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2802 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
2807 fb
= &DummyFramebuffer
;
2809 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
2812 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2817 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2819 create_framebuffers(n
, framebuffers
, false);
2824 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2826 create_framebuffers(n
, framebuffers
, true);
2831 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
2832 struct gl_framebuffer
*buffer
)
2834 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2836 if (_mesa_is_winsys_fbo(buffer
)) {
2837 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2838 if (buffer
!= &IncompleteFramebuffer
) {
2839 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2841 return GL_FRAMEBUFFER_UNDEFINED
;
2845 /* No need to flush here */
2847 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2848 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2851 return buffer
->_Status
;
2856 _mesa_CheckFramebufferStatus_no_error(GLenum target
)
2858 GET_CURRENT_CONTEXT(ctx
);
2860 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
2861 return _mesa_check_framebuffer_status(ctx
, fb
);
2866 _mesa_CheckFramebufferStatus(GLenum target
)
2868 struct gl_framebuffer
*fb
;
2869 GET_CURRENT_CONTEXT(ctx
);
2871 if (MESA_VERBOSE
& VERBOSE_API
)
2872 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2873 _mesa_enum_to_string(target
));
2875 fb
= get_framebuffer_target(ctx
, target
);
2877 _mesa_error(ctx
, GL_INVALID_ENUM
,
2878 "glCheckFramebufferStatus(invalid target %s)",
2879 _mesa_enum_to_string(target
));
2883 return _mesa_check_framebuffer_status(ctx
, fb
);
2888 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
2890 struct gl_framebuffer
*fb
;
2891 GET_CURRENT_CONTEXT(ctx
);
2893 /* Validate the target (for conformance's sake) and grab a reference to the
2894 * default framebuffer in case framebuffer = 0.
2895 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
2896 * (30.10.2014, PDF page 336) says:
2897 * "If framebuffer is zero, then the status of the default read or
2898 * draw framebuffer (as determined by target) is returned."
2901 case GL_DRAW_FRAMEBUFFER
:
2902 case GL_FRAMEBUFFER
:
2903 fb
= ctx
->WinSysDrawBuffer
;
2905 case GL_READ_FRAMEBUFFER
:
2906 fb
= ctx
->WinSysReadBuffer
;
2909 _mesa_error(ctx
, GL_INVALID_ENUM
,
2910 "glCheckNamedFramebufferStatus(invalid target %s)",
2911 _mesa_enum_to_string(target
));
2916 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
2917 "glCheckNamedFramebufferStatus");
2922 return _mesa_check_framebuffer_status(ctx
, fb
);
2927 * Replicate the src attachment point. Used by framebuffer_texture() when
2928 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2929 * GL_STENCIL_ATTACHMENT.
2932 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2933 gl_buffer_index dst
,
2934 gl_buffer_index src
)
2936 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2937 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2939 assert(src_att
->Texture
!= NULL
);
2940 assert(src_att
->Renderbuffer
!= NULL
);
2942 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2943 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2944 dst_att
->Type
= src_att
->Type
;
2945 dst_att
->Complete
= src_att
->Complete
;
2946 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2947 dst_att
->CubeMapFace
= src_att
->CubeMapFace
;
2948 dst_att
->Zoffset
= src_att
->Zoffset
;
2949 dst_att
->Layered
= src_att
->Layered
;
2953 static struct gl_texture_object
*
2954 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
)
2959 return _mesa_lookup_texture(ctx
, texture
);
2964 * Common code called by gl*FramebufferTexture*() to retrieve the correct
2965 * texture object pointer.
2967 * \param texObj where the pointer to the texture object is returned. Note
2968 * that a successful call may return texObj = NULL.
2970 * \return true if no errors, false if errors
2973 get_texture_for_framebuffer_err(struct gl_context
*ctx
, GLuint texture
,
2974 bool layered
, const char *caller
,
2975 struct gl_texture_object
**texObj
)
2977 *texObj
= NULL
; /* This will get returned if texture = 0. */
2982 *texObj
= _mesa_lookup_texture(ctx
, texture
);
2983 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
2984 /* Can't render to a non-existent texture object.
2986 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
2987 * Managing Framebuffer Objects specifies a different error
2988 * depending upon the calling function (PDF pages 325-328).
2989 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
2990 * value, while the other commands throw invalid operation (where
2991 * layered = GL_FALSE).
2993 const GLenum error
= layered
? GL_INVALID_VALUE
:
2994 GL_INVALID_OPERATION
;
2995 _mesa_error(ctx
, error
,
2996 "%s(non-existent texture %u)", caller
, texture
);
3005 * Common code called by gl*FramebufferTexture() to verify the texture target
3006 * and decide whether or not the attachment should truly be considered
3009 * \param layered true if attachment should be considered layered, false if
3012 * \return true if no errors, false if errors
3015 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
3016 const char *caller
, GLboolean
*layered
)
3022 case GL_TEXTURE_1D_ARRAY_EXT
:
3023 case GL_TEXTURE_2D_ARRAY_EXT
:
3024 case GL_TEXTURE_CUBE_MAP
:
3025 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3026 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3030 case GL_TEXTURE_RECTANGLE
:
3031 case GL_TEXTURE_2D_MULTISAMPLE
:
3032 /* These texture types are valid to pass to
3033 * glFramebufferTexture(), but since they aren't layered, it
3034 * is equivalent to calling glFramebufferTexture{1D,2D}().
3036 *layered
= GL_FALSE
;
3040 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3041 "%s(invalid texture target %s)", caller
,
3042 _mesa_enum_to_string(target
));
3048 * Common code called by gl*FramebufferTextureLayer() to verify the texture
3051 * \return true if no errors, false if errors
3054 check_texture_target(struct gl_context
*ctx
, GLenum target
,
3057 /* We're being called by glFramebufferTextureLayer().
3058 * The only legal texture types for that function are 3D,
3059 * cube-map, and 1D/2D/cube-map array textures.
3061 * We don't need to check for GL_ARB_texture_cube_map_array because the
3062 * application wouldn't have been able to create a texture with a
3063 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
3067 case GL_TEXTURE_1D_ARRAY
:
3068 case GL_TEXTURE_2D_ARRAY
:
3069 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3070 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3072 case GL_TEXTURE_CUBE_MAP
:
3073 /* We don't need to check the extension (GL_ARB_direct_state_access) or
3074 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
3075 * enabled in core profile. This can be called from
3076 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
3077 * so we do have to check the profile.
3079 return ctx
->API
== API_OPENGL_CORE
;
3082 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3083 "%s(invalid texture target %s)", caller
,
3084 _mesa_enum_to_string(target
));
3090 * Common code called by glFramebufferTexture*D() to verify the texture
3093 * \return true if no errors, false if errors
3096 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
3097 GLenum textarget
, const char *caller
)
3101 switch (textarget
) {
3105 case GL_TEXTURE_1D_ARRAY
:
3106 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3111 case GL_TEXTURE_2D_ARRAY
:
3112 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3113 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3115 case GL_TEXTURE_2D_MULTISAMPLE
:
3116 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3118 !ctx
->Extensions
.ARB_texture_multisample
||
3119 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3121 case GL_TEXTURE_RECTANGLE
:
3122 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3123 !ctx
->Extensions
.NV_texture_rectangle
;
3125 case GL_TEXTURE_CUBE_MAP
:
3126 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3129 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3130 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3131 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3132 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3133 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3134 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3135 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3141 _mesa_error(ctx
, GL_INVALID_ENUM
,
3142 "%s(unknown textarget 0x%x)", caller
, textarget
);
3147 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3148 "%s(invalid textarget %s)",
3149 caller
, _mesa_enum_to_string(textarget
));
3153 /* Make sure textarget is consistent with the texture's type */
3154 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3155 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3158 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3159 "%s(mismatched texture target)", caller
);
3168 * Common code called by gl*FramebufferTextureLayer() and
3169 * glFramebufferTexture3D() to validate the layer.
3171 * \return true if no errors, false if errors
3174 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3177 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3180 * "An INVALID_VALUE error is generated if texture is non-zero
3181 * and layer is negative."
3184 _mesa_error(ctx
, GL_INVALID_VALUE
,
3185 "%s(layer %u < 0)", caller
, layer
);
3189 if (target
== GL_TEXTURE_3D
) {
3190 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3191 if (layer
>= maxSize
) {
3192 _mesa_error(ctx
, GL_INVALID_VALUE
,
3193 "%s(invalid layer %u)", caller
, layer
);
3197 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3198 (target
== GL_TEXTURE_2D_ARRAY
) ||
3199 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3200 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3201 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3202 _mesa_error(ctx
, GL_INVALID_VALUE
,
3203 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3208 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3210 _mesa_error(ctx
, GL_INVALID_VALUE
,
3211 "%s(layer %u >= 6)", caller
, layer
);
3221 * Common code called by all gl*FramebufferTexture*() entry points to verify
3224 * \return true if no errors, false if errors
3227 check_level(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
3228 GLenum target
, GLint level
, const char *caller
)
3230 /* Section 9.2.8 of the OpenGL 4.6 specification says:
3232 * "If texture refers to an immutable-format texture, level must be
3233 * greater than or equal to zero and smaller than the value of
3234 * TEXTURE_VIEW_NUM_LEVELS for texture."
3236 const int max_levels
= texObj
->Immutable
? texObj
->ImmutableLevels
:
3237 _mesa_max_texture_levels(ctx
, target
);
3239 if (level
< 0 || level
>= max_levels
) {
3240 _mesa_error(ctx
, GL_INVALID_VALUE
,
3241 "%s(invalid level %d)", caller
, level
);
3249 struct gl_renderbuffer_attachment
*
3250 _mesa_get_and_validate_attachment(struct gl_context
*ctx
,
3251 struct gl_framebuffer
*fb
,
3252 GLenum attachment
, const char *caller
)
3254 /* The window-system framebuffer object is immutable */
3255 if (_mesa_is_winsys_fbo(fb
)) {
3256 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3261 /* Not a hash lookup, so we can afford to get the attachment here. */
3262 bool is_color_attachment
;
3263 struct gl_renderbuffer_attachment
*att
=
3264 get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3266 if (is_color_attachment
) {
3267 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3268 "%s(invalid color attachment %s)", caller
,
3269 _mesa_enum_to_string(attachment
));
3271 _mesa_error(ctx
, GL_INVALID_ENUM
,
3272 "%s(invalid attachment %s)", caller
,
3273 _mesa_enum_to_string(attachment
));
3283 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3285 struct gl_renderbuffer_attachment
*att
,
3286 struct gl_texture_object
*texObj
, GLenum textarget
,
3287 GLint level
, GLuint layer
, GLboolean layered
)
3289 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3291 mtx_lock(&fb
->Mutex
);
3293 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3294 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3295 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3296 _mesa_tex_target_to_face(textarget
) ==
3297 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3298 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3299 /* The texture object is already attached to the stencil attachment
3300 * point. Don't create a new renderbuffer; just reuse the stencil
3301 * attachment's. This is required to prevent a GL error in
3302 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3304 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3306 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3307 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3308 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3309 _mesa_tex_target_to_face(textarget
) ==
3310 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3311 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3312 /* As above, but with depth and stencil transposed. */
3313 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3316 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3317 level
, layer
, layered
);
3319 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3320 /* Above we created a new renderbuffer and attached it to the
3321 * depth attachment point. Now attach it to the stencil attachment
3324 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3325 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3330 /* Set the render-to-texture flag. We'll check this flag in
3331 * glTexImage() and friends to determine if we need to revalidate
3332 * any FBOs that might be rendering into this texture.
3333 * This flag never gets cleared since it's non-trivial to determine
3334 * when all FBOs might be done rendering to this texture. That's OK
3335 * though since it's uncommon to render to a texture then repeatedly
3336 * call glTexImage() to change images in the texture.
3338 texObj
->_RenderToTexture
= GL_TRUE
;
3341 remove_attachment(ctx
, att
);
3342 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3343 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3344 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3348 invalidate_framebuffer(fb
);
3350 mtx_unlock(&fb
->Mutex
);
3355 framebuffer_texture_with_dims_no_error(GLenum target
, GLenum attachment
,
3356 GLenum textarget
, GLuint texture
,
3357 GLint level
, GLint layer
)
3359 GET_CURRENT_CONTEXT(ctx
);
3361 /* Get the framebuffer object */
3362 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3364 /* Get the texture object */
3365 struct gl_texture_object
*texObj
=
3366 get_texture_for_framebuffer(ctx
, texture
);
3368 struct gl_renderbuffer_attachment
*att
=
3369 get_attachment(ctx
, fb
, attachment
, NULL
);
3371 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3372 level
, layer
, GL_FALSE
);
3377 framebuffer_texture_with_dims(int dims
, GLenum target
,
3378 GLenum attachment
, GLenum textarget
,
3379 GLuint texture
, GLint level
, GLint layer
,
3382 GET_CURRENT_CONTEXT(ctx
);
3383 struct gl_framebuffer
*fb
;
3384 struct gl_texture_object
*texObj
;
3386 /* Get the framebuffer object */
3387 fb
= get_framebuffer_target(ctx
, target
);
3389 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3390 _mesa_enum_to_string(target
));
3394 /* Get the texture object */
3395 if (!get_texture_for_framebuffer_err(ctx
, texture
, false, caller
, &texObj
))
3399 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3402 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3405 if (!check_level(ctx
, texObj
, textarget
, level
, caller
))
3409 struct gl_renderbuffer_attachment
*att
=
3410 _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, caller
);
3414 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3415 level
, layer
, GL_FALSE
);
3420 _mesa_FramebufferTexture1D_no_error(GLenum target
, GLenum attachment
,
3421 GLenum textarget
, GLuint texture
,
3424 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3430 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3431 GLenum textarget
, GLuint texture
, GLint level
)
3433 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3434 level
, 0, "glFramebufferTexture1D");
3439 _mesa_FramebufferTexture2D_no_error(GLenum target
, GLenum attachment
,
3440 GLenum textarget
, GLuint texture
,
3443 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3449 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3450 GLenum textarget
, GLuint texture
, GLint level
)
3452 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3453 level
, 0, "glFramebufferTexture2D");
3458 _mesa_FramebufferTexture3D_no_error(GLenum target
, GLenum attachment
,
3459 GLenum textarget
, GLuint texture
,
3460 GLint level
, GLint layer
)
3462 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3463 texture
, level
, layer
);
3468 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3469 GLenum textarget
, GLuint texture
,
3470 GLint level
, GLint layer
)
3472 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3473 level
, layer
, "glFramebufferTexture3D");
3477 static ALWAYS_INLINE
void
3478 frame_buffer_texture(GLuint framebuffer
, GLenum target
,
3479 GLenum attachment
, GLuint texture
,
3480 GLint level
, GLint layer
, const char *func
,
3481 bool dsa
, bool no_error
, bool check_layered
)
3483 GET_CURRENT_CONTEXT(ctx
);
3484 GLboolean layered
= GL_FALSE
;
3486 if (!no_error
&& check_layered
) {
3487 if (!_mesa_has_geometry_shaders(ctx
)) {
3488 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3489 "unsupported function (%s) called", func
);
3494 /* Get the framebuffer object */
3495 struct gl_framebuffer
*fb
;
3498 fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3500 fb
= get_framebuffer_target(ctx
, target
);
3504 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3508 fb
= get_framebuffer_target(ctx
, target
);
3510 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)",
3511 func
, _mesa_enum_to_string(target
));
3517 /* Get the texture object and framebuffer attachment*/
3518 struct gl_renderbuffer_attachment
*att
;
3519 struct gl_texture_object
*texObj
;
3521 texObj
= get_texture_for_framebuffer(ctx
, texture
);
3522 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
3524 if (!get_texture_for_framebuffer_err(ctx
, texture
, check_layered
, func
,
3528 att
= _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, func
);
3533 GLenum textarget
= 0;
3535 if (check_layered
) {
3536 /* We do this regardless of no_error because this sets layered */
3537 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3543 if (!check_layered
) {
3544 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3547 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3551 if (!check_level(ctx
, texObj
, texObj
->Target
, level
, func
))
3555 if (!check_layered
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3556 assert(layer
>= 0 && layer
< 6);
3557 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3562 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3563 level
, layer
, layered
);
3567 _mesa_FramebufferTextureLayer_no_error(GLenum target
, GLenum attachment
,
3568 GLuint texture
, GLint level
,
3571 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3572 "glFramebufferTextureLayer", false, true, false);
3577 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3578 GLuint texture
, GLint level
, GLint layer
)
3580 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3581 "glFramebufferTextureLayer", false, false, false);
3586 _mesa_NamedFramebufferTextureLayer_no_error(GLuint framebuffer
,
3588 GLuint texture
, GLint level
,
3591 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3592 "glNamedFramebufferTextureLayer", true, true, false);
3597 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3598 GLuint texture
, GLint level
, GLint layer
)
3600 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3601 "glNamedFramebufferTextureLayer", true, false, false);
3606 _mesa_FramebufferTexture_no_error(GLenum target
, GLenum attachment
,
3607 GLuint texture
, GLint level
)
3609 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3610 "glFramebufferTexture", false, true, true);
3615 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3616 GLuint texture
, GLint level
)
3618 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3619 "glFramebufferTexture", false, false, true);
3623 _mesa_NamedFramebufferTexture_no_error(GLuint framebuffer
, GLenum attachment
,
3624 GLuint texture
, GLint level
)
3626 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3627 "glNamedFramebufferTexture", true, true, true);
3632 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3633 GLuint texture
, GLint level
)
3635 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3636 "glNamedFramebufferTexture", true, false, true);
3641 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3642 struct gl_framebuffer
*fb
,
3644 struct gl_renderbuffer
*rb
)
3646 assert(!_mesa_is_winsys_fbo(fb
));
3648 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3650 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3651 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3653 /* Some subsequent GL commands may depend on the framebuffer's visual
3654 * after the binding is updated. Update visual info now.
3656 _mesa_update_framebuffer_visual(ctx
, fb
);
3659 static ALWAYS_INLINE
void
3660 framebuffer_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3661 GLenum attachment
, GLenum renderbuffertarget
,
3662 GLuint renderbuffer
, const char *func
, bool no_error
)
3664 struct gl_renderbuffer_attachment
*att
;
3665 struct gl_renderbuffer
*rb
;
3666 bool is_color_attachment
;
3668 if (!no_error
&& renderbuffertarget
!= GL_RENDERBUFFER
) {
3669 _mesa_error(ctx
, GL_INVALID_ENUM
,
3670 "%s(renderbuffertarget is not GL_RENDERBUFFER)", func
);
3676 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
, func
);
3680 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
3683 /* remove renderbuffer attachment */
3688 if (_mesa_is_winsys_fbo(fb
)) {
3689 /* Can't attach new renderbuffers to a window system framebuffer */
3690 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3691 "%s(window-system framebuffer)", func
);
3695 att
= get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3698 * From OpenGL 4.5 spec, section 9.2.7 "Attaching Renderbuffer Images
3699 * to a Framebuffer":
3701 * "An INVALID_OPERATION error is generated if attachment is
3702 * COLOR_- ATTACHMENTm where m is greater than or equal to the
3703 * value of MAX_COLOR_- ATTACHMENTS ."
3705 * If we are at this point, is because the attachment is not valid, so
3706 * if is_color_attachment is true, is because of the previous reason.
3708 if (is_color_attachment
) {
3709 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3710 "%s(invalid color attachment %s)", func
,
3711 _mesa_enum_to_string(attachment
));
3713 _mesa_error(ctx
, GL_INVALID_ENUM
,
3714 "%s(invalid attachment %s)", func
,
3715 _mesa_enum_to_string(attachment
));
3721 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3722 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3723 /* make sure the renderbuffer is a depth/stencil format */
3724 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3725 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3726 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3727 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3733 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3737 framebuffer_renderbuffer_error(struct gl_context
*ctx
,
3738 struct gl_framebuffer
*fb
, GLenum attachment
,
3739 GLenum renderbuffertarget
,
3740 GLuint renderbuffer
, const char *func
)
3742 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3743 renderbuffer
, func
, false);
3747 framebuffer_renderbuffer_no_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
, true);
3757 _mesa_FramebufferRenderbuffer_no_error(GLenum target
, GLenum attachment
,
3758 GLenum renderbuffertarget
,
3759 GLuint renderbuffer
)
3761 GET_CURRENT_CONTEXT(ctx
);
3763 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3764 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3765 renderbuffer
, "glFramebufferRenderbuffer");
3769 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3770 GLenum renderbuffertarget
,
3771 GLuint renderbuffer
)
3773 struct gl_framebuffer
*fb
;
3774 GET_CURRENT_CONTEXT(ctx
);
3776 fb
= get_framebuffer_target(ctx
, target
);
3778 _mesa_error(ctx
, GL_INVALID_ENUM
,
3779 "glFramebufferRenderbuffer(invalid target %s)",
3780 _mesa_enum_to_string(target
));
3784 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
3785 renderbuffer
, "glFramebufferRenderbuffer");
3789 _mesa_NamedFramebufferRenderbuffer_no_error(GLuint framebuffer
,
3791 GLenum renderbuffertarget
,
3792 GLuint renderbuffer
)
3794 GET_CURRENT_CONTEXT(ctx
);
3796 struct gl_framebuffer
*fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3797 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3799 "glNamedFramebufferRenderbuffer");
3803 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
3804 GLenum renderbuffertarget
,
3805 GLuint renderbuffer
)
3807 struct gl_framebuffer
*fb
;
3808 GET_CURRENT_CONTEXT(ctx
);
3810 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3811 "glNamedFramebufferRenderbuffer");
3815 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
3817 "glNamedFramebufferRenderbuffer");
3822 get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
3823 struct gl_framebuffer
*buffer
,
3824 GLenum attachment
, GLenum pname
,
3825 GLint
*params
, const char *caller
)
3827 const struct gl_renderbuffer_attachment
*att
;
3828 bool is_color_attachment
= false;
3831 /* The error code for an attachment type of GL_NONE differs between APIs.
3833 * From the ES 2.0.25 specification, page 127:
3834 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3835 * querying any other pname will generate INVALID_ENUM."
3837 * From the OpenGL 3.0 specification, page 337, or identically,
3838 * the OpenGL ES 3.0.4 specification, page 240:
3840 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
3841 * framebuffer is bound to target. In this case querying pname
3842 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
3843 * queries will generate an INVALID_OPERATION error."
3845 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
3846 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
3848 if (_mesa_is_winsys_fbo(buffer
)) {
3849 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
3852 * "If the framebuffer currently bound to target is zero, then
3853 * INVALID_OPERATION is generated."
3855 * The EXT_framebuffer_object spec has the same wording, and the
3856 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
3859 if ((!_mesa_is_desktop_gl(ctx
) ||
3860 !ctx
->Extensions
.ARB_framebuffer_object
)
3861 && !_mesa_is_gles3(ctx
)) {
3862 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3863 "%s(window-system framebuffer)", caller
);
3867 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
3868 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
3869 _mesa_error(ctx
, GL_INVALID_ENUM
,
3870 "%s(invalid attachment %s)", caller
,
3871 _mesa_enum_to_string(attachment
));
3875 /* The specs are not clear about how to handle
3876 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
3877 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
3880 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
3881 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
3883 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
3884 _mesa_error(ctx
, GL_INVALID_ENUM
,
3885 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
3886 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
3887 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
3891 /* the default / window-system FBO */
3892 att
= get_fb0_attachment(ctx
, buffer
, attachment
);
3895 /* user-created framebuffer FBO */
3896 att
= get_attachment(ctx
, buffer
, attachment
, &is_color_attachment
);
3901 * From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries":
3903 * "An INVALID_OPERATION error is generated if a framebuffer object
3904 * is bound to target and attachment is COLOR_ATTACHMENTm where m is
3905 * greater than or equal to the value of MAX_COLOR_ATTACHMENTS."
3907 * If we are at this point, is because the attachment is not valid, so
3908 * if is_color_attachment is true, is because of the previous reason.
3910 if (is_color_attachment
) {
3911 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid color attachment %s)",
3912 caller
, _mesa_enum_to_string(attachment
));
3914 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3915 _mesa_enum_to_string(attachment
));
3920 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3921 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
3922 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
3923 /* This behavior is first specified in OpenGL 4.4 specification.
3925 * From the OpenGL 4.4 spec page 275:
3926 * "This query cannot be performed for a combined depth+stencil
3927 * attachment, since it does not have a single format."
3929 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3930 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
3931 " is invalid for depth+stencil attachment)", caller
);
3934 /* the depth and stencil attachments must point to the same buffer */
3935 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
, NULL
);
3936 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
, NULL
);
3937 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
3938 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3939 "%s(DEPTH/STENCIL attachments differ)", caller
);
3944 /* No need to flush here */
3947 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
3948 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
3950 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3951 * either no framebuffer is bound to target; or the default framebuffer
3952 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
3953 * stencil bits, respectively, is zero."
3955 * Note that we don't need explicit checks on DEPTH and STENCIL, because
3956 * on the case the spec is pointing, att->Type is already NONE, so we
3957 * just need to check att->Type.
3959 *params
= (_mesa_is_winsys_fbo(buffer
) && att
->Type
!= GL_NONE
) ?
3960 GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
3962 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
3963 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
3964 *params
= att
->Renderbuffer
->Name
;
3966 else if (att
->Type
== GL_TEXTURE
) {
3967 *params
= att
->Texture
->Name
;
3970 assert(att
->Type
== GL_NONE
);
3971 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
3974 goto invalid_pname_enum
;
3978 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
3979 if (att
->Type
== GL_TEXTURE
) {
3980 *params
= att
->TextureLevel
;
3982 else if (att
->Type
== GL_NONE
) {
3983 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3984 _mesa_enum_to_string(pname
));
3987 goto invalid_pname_enum
;
3990 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
3991 if (att
->Type
== GL_TEXTURE
) {
3992 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
3993 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
3999 else if (att
->Type
== GL_NONE
) {
4000 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4001 _mesa_enum_to_string(pname
));
4004 goto invalid_pname_enum
;
4007 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
4008 if (ctx
->API
== API_OPENGLES
) {
4009 goto invalid_pname_enum
;
4010 } else if (att
->Type
== GL_NONE
) {
4011 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4012 _mesa_enum_to_string(pname
));
4013 } else if (att
->Type
== GL_TEXTURE
) {
4014 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
4015 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
4016 *params
= att
->Zoffset
;
4023 goto invalid_pname_enum
;
4026 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
4027 if ((!_mesa_is_desktop_gl(ctx
) ||
4028 !ctx
->Extensions
.ARB_framebuffer_object
)
4029 && !_mesa_is_gles3(ctx
)) {
4030 goto invalid_pname_enum
;
4032 else if (att
->Type
== GL_NONE
) {
4033 if (_mesa_is_winsys_fbo(buffer
) &&
4034 (attachment
== GL_DEPTH
|| attachment
== GL_STENCIL
)) {
4035 *params
= GL_LINEAR
;
4037 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4038 _mesa_enum_to_string(pname
));
4042 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
4044 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
4047 /* According to ARB_framebuffer_sRGB, we should return LINEAR
4048 * if the sRGB conversion is unsupported. */
4049 *params
= GL_LINEAR
;
4053 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
4054 if ((ctx
->API
!= API_OPENGL_COMPAT
||
4055 !ctx
->Extensions
.ARB_framebuffer_object
)
4056 && ctx
->API
!= API_OPENGL_CORE
4057 && !_mesa_is_gles3(ctx
)) {
4058 goto invalid_pname_enum
;
4060 else if (att
->Type
== GL_NONE
) {
4061 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4062 _mesa_enum_to_string(pname
));
4065 mesa_format format
= att
->Renderbuffer
->Format
;
4067 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
4070 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
4071 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
4072 * generate an INVALID_OPERATION error.
4074 if (_mesa_is_gles3(ctx
) &&
4075 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
4076 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4078 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
4079 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
4083 if (format
== MESA_FORMAT_S_UINT8
) {
4087 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
4088 /* depends on the attachment parameter */
4089 if (attachment
== GL_STENCIL_ATTACHMENT
) {
4097 *params
= _mesa_get_format_datatype(format
);
4101 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
4102 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
4103 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
4104 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
4105 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
4106 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
4107 if ((!_mesa_is_desktop_gl(ctx
) ||
4108 !ctx
->Extensions
.ARB_framebuffer_object
)
4109 && !_mesa_is_gles3(ctx
)) {
4110 goto invalid_pname_enum
;
4112 else if (att
->Texture
) {
4113 const struct gl_texture_image
*texImage
=
4114 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
4117 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
4118 texImage
->TexFormat
);
4124 else if (att
->Renderbuffer
) {
4125 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
4126 att
->Renderbuffer
->Format
);
4129 assert(att
->Type
== GL_NONE
);
4130 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4131 _mesa_enum_to_string(pname
));
4134 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
4135 if (!_mesa_has_geometry_shaders(ctx
)) {
4136 goto invalid_pname_enum
;
4137 } else if (att
->Type
== GL_TEXTURE
) {
4138 *params
= att
->Layered
;
4139 } else if (att
->Type
== GL_NONE
) {
4140 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4141 _mesa_enum_to_string(pname
));
4143 goto invalid_pname_enum
;
4147 goto invalid_pname_enum
;
4153 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
4154 _mesa_enum_to_string(pname
));
4160 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
4161 GLenum pname
, GLint
*params
)
4163 GET_CURRENT_CONTEXT(ctx
);
4164 struct gl_framebuffer
*buffer
;
4166 buffer
= get_framebuffer_target(ctx
, target
);
4168 _mesa_error(ctx
, GL_INVALID_ENUM
,
4169 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
4170 _mesa_enum_to_string(target
));
4174 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4176 "glGetFramebufferAttachmentParameteriv");
4181 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
4183 GLenum pname
, GLint
*params
)
4185 GET_CURRENT_CONTEXT(ctx
);
4186 struct gl_framebuffer
*buffer
;
4189 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4190 "glGetNamedFramebufferAttachmentParameteriv");
4196 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
4197 * 4.5 core spec (30.10.2014, PDF page 314):
4198 * "If framebuffer is zero, then the default draw framebuffer is
4201 buffer
= ctx
->WinSysDrawBuffer
;
4204 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4206 "glGetNamedFramebufferAttachmentParameteriv");
4211 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
4214 GET_CURRENT_CONTEXT(ctx
);
4215 struct gl_framebuffer
*fb
= NULL
;
4217 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4218 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4219 "glNamedFramebufferParameteri("
4220 "ARB_framebuffer_no_attachments not implemented)");
4224 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4225 "glNamedFramebufferParameteri");
4228 framebuffer_parameteri(ctx
, fb
, pname
, param
,
4229 "glNamedFramebufferParameteriv");
4235 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
4238 GET_CURRENT_CONTEXT(ctx
);
4239 struct gl_framebuffer
*fb
;
4241 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4242 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4243 "glNamedFramebufferParameteriv("
4244 "ARB_framebuffer_no_attachments not implemented)");
4249 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4250 "glGetNamedFramebufferParameteriv");
4252 fb
= ctx
->WinSysDrawBuffer
;
4256 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4257 "glGetNamedFramebufferParameteriv");
4263 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4264 struct gl_framebuffer
*fb
,
4265 GLsizei numAttachments
,
4266 const GLenum
*attachments
, GLint x
, GLint y
,
4267 GLsizei width
, GLsizei height
, const char *name
)
4271 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4272 * Spec (2.2.2015, PDF page 522) says:
4273 * "An INVALID_VALUE error is generated if numAttachments, width, or
4274 * height is negative."
4276 if (numAttachments
< 0) {
4277 _mesa_error(ctx
, GL_INVALID_VALUE
,
4278 "%s(numAttachments < 0)", name
);
4283 _mesa_error(ctx
, GL_INVALID_VALUE
,
4284 "%s(width < 0)", name
);
4289 _mesa_error(ctx
, GL_INVALID_VALUE
,
4290 "%s(height < 0)", name
);
4294 /* The GL_ARB_invalidate_subdata spec says:
4296 * "If an attachment is specified that does not exist in the
4297 * framebuffer bound to <target>, it is ignored."
4301 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4302 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4303 * INVALID_OPERATION is generated."
4305 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4306 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4307 * set of retrictions).
4309 for (i
= 0; i
< numAttachments
; i
++) {
4310 if (_mesa_is_winsys_fbo(fb
)) {
4311 switch (attachments
[i
]) {
4317 /* Accumulation buffers and auxilary buffers were removed in
4318 * OpenGL 3.1, and they never existed in OpenGL ES.
4320 if (ctx
->API
!= API_OPENGL_COMPAT
)
4330 case GL_FRONT_RIGHT
:
4331 if (!_mesa_is_desktop_gl(ctx
))
4338 switch (attachments
[i
]) {
4339 case GL_DEPTH_ATTACHMENT
:
4340 case GL_STENCIL_ATTACHMENT
:
4342 case GL_DEPTH_STENCIL_ATTACHMENT
:
4343 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4344 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4345 * extension does not make this attachment point valid on ES 2.0.
4347 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4350 case GL_COLOR_ATTACHMENT0
:
4351 case GL_COLOR_ATTACHMENT1
:
4352 case GL_COLOR_ATTACHMENT2
:
4353 case GL_COLOR_ATTACHMENT3
:
4354 case GL_COLOR_ATTACHMENT4
:
4355 case GL_COLOR_ATTACHMENT5
:
4356 case GL_COLOR_ATTACHMENT6
:
4357 case GL_COLOR_ATTACHMENT7
:
4358 case GL_COLOR_ATTACHMENT8
:
4359 case GL_COLOR_ATTACHMENT9
:
4360 case GL_COLOR_ATTACHMENT10
:
4361 case GL_COLOR_ATTACHMENT11
:
4362 case GL_COLOR_ATTACHMENT12
:
4363 case GL_COLOR_ATTACHMENT13
:
4364 case GL_COLOR_ATTACHMENT14
:
4365 case GL_COLOR_ATTACHMENT15
: {
4366 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4367 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4368 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4369 "%s(attachment >= max. color attachments)", name
);
4380 /* We don't actually do anything for this yet. Just return after
4381 * validating the parameters and generating the required errors.
4386 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4387 _mesa_enum_to_string(attachments
[i
]));
4393 _mesa_InvalidateSubFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4394 const GLenum
*attachments
, GLint x
,
4395 GLint y
, GLsizei width
, GLsizei height
)
4402 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4403 const GLenum
*attachments
, GLint x
, GLint y
,
4404 GLsizei width
, GLsizei height
)
4406 struct gl_framebuffer
*fb
;
4407 GET_CURRENT_CONTEXT(ctx
);
4409 fb
= get_framebuffer_target(ctx
, target
);
4411 _mesa_error(ctx
, GL_INVALID_ENUM
,
4412 "glInvalidateSubFramebuffer(invalid target %s)",
4413 _mesa_enum_to_string(target
));
4417 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4418 x
, y
, width
, height
,
4419 "glInvalidateSubFramebuffer");
4424 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4425 GLsizei numAttachments
,
4426 const GLenum
*attachments
,
4428 GLsizei width
, GLsizei height
)
4430 struct gl_framebuffer
*fb
;
4431 GET_CURRENT_CONTEXT(ctx
);
4433 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4434 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4435 * default draw framebuffer is affected."
4438 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4439 "glInvalidateNamedFramebufferSubData");
4444 fb
= ctx
->WinSysDrawBuffer
;
4446 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4447 x
, y
, width
, height
,
4448 "glInvalidateNamedFramebufferSubData");
4453 _mesa_InvalidateFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4454 const GLenum
*attachments
)
4461 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4462 const GLenum
*attachments
)
4464 struct gl_framebuffer
*fb
;
4465 GET_CURRENT_CONTEXT(ctx
);
4467 fb
= get_framebuffer_target(ctx
, target
);
4469 _mesa_error(ctx
, GL_INVALID_ENUM
,
4470 "glInvalidateFramebuffer(invalid target %s)",
4471 _mesa_enum_to_string(target
));
4475 /* The GL_ARB_invalidate_subdata spec says:
4479 * void InvalidateFramebuffer(enum target,
4480 * sizei numAttachments,
4481 * const enum *attachments);
4483 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4484 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4485 * <MAX_VIEWPORT_DIMS[1]> respectively."
4487 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4489 ctx
->Const
.MaxViewportWidth
,
4490 ctx
->Const
.MaxViewportHeight
,
4491 "glInvalidateFramebuffer");
4496 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4497 GLsizei numAttachments
,
4498 const GLenum
*attachments
)
4500 struct gl_framebuffer
*fb
;
4501 GET_CURRENT_CONTEXT(ctx
);
4503 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4504 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4505 * default draw framebuffer is affected."
4508 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4509 "glInvalidateNamedFramebufferData");
4514 fb
= ctx
->WinSysDrawBuffer
;
4516 /* The GL_ARB_invalidate_subdata spec says:
4520 * void InvalidateFramebuffer(enum target,
4521 * sizei numAttachments,
4522 * const enum *attachments);
4524 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4525 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4526 * <MAX_VIEWPORT_DIMS[1]> respectively."
4528 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4530 ctx
->Const
.MaxViewportWidth
,
4531 ctx
->Const
.MaxViewportHeight
,
4532 "glInvalidateNamedFramebufferData");
4537 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4538 const GLenum
*attachments
)
4540 struct gl_framebuffer
*fb
;
4543 GET_CURRENT_CONTEXT(ctx
);
4545 fb
= get_framebuffer_target(ctx
, target
);
4547 _mesa_error(ctx
, GL_INVALID_ENUM
,
4548 "glDiscardFramebufferEXT(target %s)",
4549 _mesa_enum_to_string(target
));
4553 if (numAttachments
< 0) {
4554 _mesa_error(ctx
, GL_INVALID_VALUE
,
4555 "glDiscardFramebufferEXT(numAttachments < 0)");
4559 for (i
= 0; i
< numAttachments
; i
++) {
4560 switch (attachments
[i
]) {
4564 if (_mesa_is_user_fbo(fb
))
4567 case GL_COLOR_ATTACHMENT0
:
4568 case GL_DEPTH_ATTACHMENT
:
4569 case GL_STENCIL_ATTACHMENT
:
4570 if (_mesa_is_winsys_fbo(fb
))
4578 if (ctx
->Driver
.DiscardFramebuffer
)
4579 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4584 _mesa_error(ctx
, GL_INVALID_ENUM
,
4585 "glDiscardFramebufferEXT(attachment %s)",
4586 _mesa_enum_to_string(attachments
[i
]));