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
38 #include "debug_output.h"
42 #include "framebuffer.h"
43 #include "glformats.h"
46 #include "multisample.h"
48 #include "renderbuffer.h"
57 * None of the GL_EXT_framebuffer_object functions are compiled into
64 * When glGenRender/FramebuffersEXT() is called we insert pointers to
65 * these placeholder objects into the hash table.
66 * Later, when the object ID is first bound, we replace the placeholder
67 * with the real frame/renderbuffer.
69 static struct gl_framebuffer DummyFramebuffer
;
70 static struct gl_renderbuffer DummyRenderbuffer
;
72 /* We bind this framebuffer when applications pass a NULL
73 * drawable/surface in make current. */
74 static struct gl_framebuffer IncompleteFramebuffer
;
78 delete_dummy_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
84 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
91 _mesa_init_fbobjects(struct gl_context
*ctx
)
93 simple_mtx_init(&DummyFramebuffer
.Mutex
, mtx_plain
);
94 simple_mtx_init(&DummyRenderbuffer
.Mutex
, mtx_plain
);
95 simple_mtx_init(&IncompleteFramebuffer
.Mutex
, mtx_plain
);
96 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
97 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
98 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
101 struct gl_framebuffer
*
102 _mesa_get_incomplete_framebuffer(void)
104 return &IncompleteFramebuffer
;
108 * Helper routine for getting a gl_renderbuffer.
110 struct gl_renderbuffer
*
111 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
113 struct gl_renderbuffer
*rb
;
118 rb
= (struct gl_renderbuffer
*)
119 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
125 * A convenience function for direct state access that throws
126 * GL_INVALID_OPERATION if the renderbuffer doesn't exist.
128 struct gl_renderbuffer
*
129 _mesa_lookup_renderbuffer_err(struct gl_context
*ctx
, GLuint id
,
132 struct gl_renderbuffer
*rb
;
134 rb
= _mesa_lookup_renderbuffer(ctx
, id
);
135 if (!rb
|| rb
== &DummyRenderbuffer
) {
136 _mesa_error(ctx
, GL_INVALID_OPERATION
,
137 "%s(non-existent renderbuffer %u)", func
, id
);
146 * Helper routine for getting a gl_framebuffer.
148 struct gl_framebuffer
*
149 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
151 struct gl_framebuffer
*fb
;
156 fb
= (struct gl_framebuffer
*)
157 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
163 struct gl_framebuffer
*
164 _mesa_lookup_framebuffer_dsa(struct gl_context
*ctx
, GLuint id
,
167 struct gl_framebuffer
*fb
;
172 fb
= _mesa_lookup_framebuffer(ctx
, id
);
174 /* Name exists but buffer is not initialized */
175 if (fb
== &DummyFramebuffer
) {
176 fb
= ctx
->Driver
.NewFramebuffer(ctx
, id
);
177 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, id
, fb
);
179 /* Name doesn't exist */
181 fb
= ctx
->Driver
.NewFramebuffer(ctx
, id
);
183 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
186 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, id
, fb
);
193 * A convenience function for direct state access that throws
194 * GL_INVALID_OPERATION if the framebuffer doesn't exist.
196 struct gl_framebuffer
*
197 _mesa_lookup_framebuffer_err(struct gl_context
*ctx
, GLuint id
,
200 struct gl_framebuffer
*fb
;
202 fb
= _mesa_lookup_framebuffer(ctx
, id
);
203 if (!fb
|| fb
== &DummyFramebuffer
) {
204 _mesa_error(ctx
, GL_INVALID_OPERATION
,
205 "%s(non-existent framebuffer %u)", func
, id
);
214 * Mark the given framebuffer as invalid. This will force the
215 * test for framebuffer completeness to be done before the framebuffer
219 invalidate_framebuffer(struct gl_framebuffer
*fb
)
221 fb
->_Status
= 0; /* "indeterminate" */
226 * Return the gl_framebuffer object which corresponds to the given
227 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
228 * Check support for GL_EXT_framebuffer_blit to determine if certain
230 * \return gl_framebuffer pointer or NULL if target is illegal
232 static struct gl_framebuffer
*
233 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
235 bool have_fb_blit
= _mesa_is_gles3(ctx
) || _mesa_is_desktop_gl(ctx
);
237 case GL_DRAW_FRAMEBUFFER
:
238 return have_fb_blit
? ctx
->DrawBuffer
: NULL
;
239 case GL_READ_FRAMEBUFFER
:
240 return have_fb_blit
? ctx
->ReadBuffer
: NULL
;
241 case GL_FRAMEBUFFER_EXT
:
242 return ctx
->DrawBuffer
;
250 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
251 * gl_renderbuffer_attachment object.
252 * This function is only used for user-created FB objects, not the
253 * default / window-system FB object.
254 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
255 * the depth buffer attachment point.
256 * Returns if the attachment is a GL_COLOR_ATTACHMENTm_EXT on
257 * is_color_attachment, because several callers would return different errors
258 * if they don't find the attachment.
260 static struct gl_renderbuffer_attachment
*
261 get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
262 GLenum attachment
, bool *is_color_attachment
)
266 assert(_mesa_is_user_fbo(fb
));
268 if (is_color_attachment
)
269 *is_color_attachment
= false;
271 switch (attachment
) {
272 case GL_COLOR_ATTACHMENT0_EXT
:
273 case GL_COLOR_ATTACHMENT1_EXT
:
274 case GL_COLOR_ATTACHMENT2_EXT
:
275 case GL_COLOR_ATTACHMENT3_EXT
:
276 case GL_COLOR_ATTACHMENT4_EXT
:
277 case GL_COLOR_ATTACHMENT5_EXT
:
278 case GL_COLOR_ATTACHMENT6_EXT
:
279 case GL_COLOR_ATTACHMENT7_EXT
:
280 case GL_COLOR_ATTACHMENT8_EXT
:
281 case GL_COLOR_ATTACHMENT9_EXT
:
282 case GL_COLOR_ATTACHMENT10_EXT
:
283 case GL_COLOR_ATTACHMENT11_EXT
:
284 case GL_COLOR_ATTACHMENT12_EXT
:
285 case GL_COLOR_ATTACHMENT13_EXT
:
286 case GL_COLOR_ATTACHMENT14_EXT
:
287 case GL_COLOR_ATTACHMENT15_EXT
:
288 if (is_color_attachment
)
289 *is_color_attachment
= true;
290 /* Only OpenGL ES 1.x forbids color attachments other than
291 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
294 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
295 if (i
>= ctx
->Const
.MaxColorAttachments
296 || (i
> 0 && ctx
->API
== API_OPENGLES
)) {
299 assert(BUFFER_COLOR0
+ i
< ARRAY_SIZE(fb
->Attachment
));
300 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
301 case GL_DEPTH_STENCIL_ATTACHMENT
:
302 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
305 case GL_DEPTH_ATTACHMENT_EXT
:
306 return &fb
->Attachment
[BUFFER_DEPTH
];
307 case GL_STENCIL_ATTACHMENT_EXT
:
308 return &fb
->Attachment
[BUFFER_STENCIL
];
316 * As above, but only used for getting attachments of the default /
317 * window-system framebuffer (not user-created framebuffer objects).
319 static struct gl_renderbuffer_attachment
*
320 get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
323 assert(_mesa_is_winsys_fbo(fb
));
325 attachment
= _mesa_back_to_front_if_single_buffered(fb
, attachment
);
327 if (_mesa_is_gles3(ctx
)) {
328 switch (attachment
) {
330 /* Since there is no stereo rendering in ES 3.0, only return the
333 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
335 /* We might get this if back_to_front triggers above */
336 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
338 return &fb
->Attachment
[BUFFER_DEPTH
];
340 return &fb
->Attachment
[BUFFER_STENCIL
];
342 unreachable("invalid attachment");
346 switch (attachment
) {
348 /* Front buffers can be allocated on the first use, but
349 * glGetFramebufferAttachmentParameteriv must work even if that
350 * allocation hasn't happened yet. In such case, use the back buffer,
351 * which should be the same.
353 if (fb
->Attachment
[BUFFER_FRONT_LEFT
].Type
== GL_NONE
)
354 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
356 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
359 if (fb
->Attachment
[BUFFER_FRONT_RIGHT
].Type
== GL_NONE
)
360 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
362 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
364 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
366 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
368 /* The ARB_ES3_1_compatibility spec says:
370 * "Since this command can only query a single framebuffer
371 * attachment, BACK is equivalent to BACK_LEFT."
373 if (ctx
->Extensions
.ARB_ES3_1_compatibility
)
374 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
377 if (fb
->Visual
.numAuxBuffers
== 1) {
378 return &fb
->Attachment
[BUFFER_AUX0
];
382 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
384 * "If the default framebuffer is bound to target, then attachment must
385 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
386 * identifying a color buffer; DEPTH, identifying the depth buffer; or
387 * STENCIL, identifying the stencil buffer."
389 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
390 * language. However, revision #33 of the ARB_framebuffer_object spec
393 * "If the default framebuffer is bound to <target>, then <attachment>
394 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
395 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
396 * depth buffer, or the stencil buffer, and <pname> may be
397 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
398 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
400 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
401 * from glext.h, so shipping apps should not use those values.
403 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
404 * support queries of the window system FBO.
407 return &fb
->Attachment
[BUFFER_DEPTH
];
409 return &fb
->Attachment
[BUFFER_STENCIL
];
418 * Remove any texture or renderbuffer attached to the given attachment
419 * point. Update reference counts, etc.
422 remove_attachment(struct gl_context
*ctx
,
423 struct gl_renderbuffer_attachment
*att
)
425 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
427 /* tell driver that we're done rendering to this texture. */
428 if (rb
&& rb
->NeedsFinishRenderTexture
)
429 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
431 if (att
->Type
== GL_TEXTURE
) {
432 assert(att
->Texture
);
433 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
434 assert(!att
->Texture
);
436 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
437 assert(!att
->Texture
);
438 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
439 assert(!att
->Renderbuffer
);
442 att
->Complete
= GL_TRUE
;
446 * Verify a couple error conditions that will lead to an incomplete FBO and
447 * may cause problems for the driver's RenderTexture path.
450 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment
*att
)
452 const struct gl_texture_image
*const texImage
=
453 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
456 texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
459 if ((texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
460 && att
->Zoffset
>= texImage
->Height
)
461 || (texImage
->TexObject
->Target
!= GL_TEXTURE_1D_ARRAY
462 && att
->Zoffset
>= texImage
->Depth
))
469 * Create a renderbuffer which will be set up by the driver to wrap the
470 * texture image slice.
472 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
473 * to share most of their framebuffer rendering code between winsys,
474 * renderbuffer, and texture attachments.
476 * The allocated renderbuffer uses a non-zero Name so that drivers can check
477 * it for determining vertical orientation, but we use ~0 to make it fairly
478 * unambiguous with actual user (non-texture) renderbuffers.
481 _mesa_update_texture_renderbuffer(struct gl_context
*ctx
,
482 struct gl_framebuffer
*fb
,
483 struct gl_renderbuffer_attachment
*att
)
485 struct gl_texture_image
*texImage
;
486 struct gl_renderbuffer
*rb
;
488 texImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
490 rb
= att
->Renderbuffer
;
492 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
494 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
497 att
->Renderbuffer
= rb
;
499 /* This can't get called on a texture renderbuffer, so set it to NULL
500 * for clarity compared to user renderbuffers.
502 rb
->AllocStorage
= NULL
;
504 rb
->NeedsFinishRenderTexture
= ctx
->Driver
.FinishRenderTexture
!= NULL
;
510 rb
->_BaseFormat
= texImage
->_BaseFormat
;
511 rb
->Format
= texImage
->TexFormat
;
512 rb
->InternalFormat
= texImage
->InternalFormat
;
513 rb
->Width
= texImage
->Width2
;
514 rb
->Height
= texImage
->Height2
;
515 rb
->Depth
= texImage
->Depth2
;
516 rb
->NumSamples
= texImage
->NumSamples
;
517 rb
->NumStorageSamples
= texImage
->NumSamples
;
518 rb
->TexImage
= texImage
;
520 if (driver_RenderTexture_is_safe(att
))
521 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
525 * Bind a texture object to an attachment point.
526 * The previous binding, if any, will be removed first.
529 set_texture_attachment(struct gl_context
*ctx
,
530 struct gl_framebuffer
*fb
,
531 struct gl_renderbuffer_attachment
*att
,
532 struct gl_texture_object
*texObj
,
533 GLenum texTarget
, GLuint level
, GLsizei samples
,
534 GLuint layer
, GLboolean layered
)
536 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
538 if (rb
&& rb
->NeedsFinishRenderTexture
)
539 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
541 if (att
->Texture
== texObj
) {
542 /* re-attaching same texture */
543 assert(att
->Type
== GL_TEXTURE
);
547 remove_attachment(ctx
, att
);
548 att
->Type
= GL_TEXTURE
;
549 assert(!att
->Texture
);
550 _mesa_reference_texobj(&att
->Texture
, texObj
);
552 invalidate_framebuffer(fb
);
554 /* always update these fields */
555 att
->TextureLevel
= level
;
556 att
->NumSamples
= samples
;
557 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
558 att
->Zoffset
= layer
;
559 att
->Layered
= layered
;
560 att
->Complete
= GL_FALSE
;
562 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
567 * Bind a renderbuffer to an attachment point.
568 * The previous binding, if any, will be removed first.
571 set_renderbuffer_attachment(struct gl_context
*ctx
,
572 struct gl_renderbuffer_attachment
*att
,
573 struct gl_renderbuffer
*rb
)
575 /* XXX check if re-doing same attachment, exit early */
576 remove_attachment(ctx
, att
);
577 att
->Type
= GL_RENDERBUFFER_EXT
;
578 att
->Texture
= NULL
; /* just to be safe */
579 att
->Layered
= GL_FALSE
;
580 att
->Complete
= GL_FALSE
;
581 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
586 * Fallback for ctx->Driver.FramebufferRenderbuffer()
587 * Attach a renderbuffer object to a framebuffer object.
590 _mesa_FramebufferRenderbuffer_sw(struct gl_context
*ctx
,
591 struct gl_framebuffer
*fb
,
593 struct gl_renderbuffer
*rb
)
595 struct gl_renderbuffer_attachment
*att
;
597 simple_mtx_lock(&fb
->Mutex
);
599 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
602 set_renderbuffer_attachment(ctx
, att
, rb
);
603 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
604 /* do stencil attachment here (depth already done above) */
605 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
607 set_renderbuffer_attachment(ctx
, att
, rb
);
609 rb
->AttachedAnytime
= GL_TRUE
;
612 remove_attachment(ctx
, att
);
613 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
614 /* detach stencil (depth was detached above) */
615 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
617 remove_attachment(ctx
, att
);
621 invalidate_framebuffer(fb
);
623 simple_mtx_unlock(&fb
->Mutex
);
628 * Fallback for ctx->Driver.ValidateFramebuffer()
629 * Check if the renderbuffer's formats are supported by the software
631 * Drivers should probably override this.
634 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
637 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
638 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
640 switch (rb
->_BaseFormat
) {
642 case GL_LUMINANCE_ALPHA
:
647 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
651 switch (rb
->Format
) {
652 /* XXX This list is likely incomplete. */
653 case MESA_FORMAT_R9G9B9E5_FLOAT
:
654 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
657 /* render buffer format is supported by software rendering */
666 * Return true if the framebuffer has a combined depth/stencil
667 * renderbuffer attached.
670 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
672 const struct gl_renderbuffer_attachment
*depth
=
673 &fb
->Attachment
[BUFFER_DEPTH
];
674 const struct gl_renderbuffer_attachment
*stencil
=
675 &fb
->Attachment
[BUFFER_STENCIL
];
677 if (depth
->Type
== stencil
->Type
) {
678 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
679 depth
->Renderbuffer
== stencil
->Renderbuffer
)
682 if (depth
->Type
== GL_TEXTURE
&&
683 depth
->Texture
== stencil
->Texture
)
695 att_incomplete(const char *msg
)
697 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
698 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
707 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
709 static GLuint msg_id
;
711 _mesa_gl_debugf(ctx
, &msg_id
,
712 MESA_DEBUG_SOURCE_API
,
713 MESA_DEBUG_TYPE_OTHER
,
714 MESA_DEBUG_SEVERITY_MEDIUM
,
715 "FBO incomplete: %s [%d]\n", msg
, index
);
717 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
718 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
724 * Is the given base format a legal format for a color renderbuffer?
727 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
729 switch (baseFormat
) {
734 case GL_LUMINANCE_ALPHA
:
737 return ctx
->API
== API_OPENGL_COMPAT
&&
738 ctx
->Extensions
.ARB_framebuffer_object
;
741 return ctx
->Extensions
.ARB_texture_rg
;
749 * Is the given base format a legal format for a color renderbuffer?
752 is_format_color_renderable(const struct gl_context
*ctx
, mesa_format format
,
753 GLenum internalFormat
)
755 const GLenum baseFormat
=
756 _mesa_get_format_base_format(format
);
759 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
760 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
764 /* Reject additional cases for GLES */
765 switch (internalFormat
) {
769 return _mesa_has_EXT_render_snorm(ctx
);
772 case GL_RGBA16_SNORM
:
773 return _mesa_has_EXT_texture_norm16(ctx
) &&
774 _mesa_has_EXT_render_snorm(ctx
);
793 if (internalFormat
!= GL_RGB10_A2
&&
794 (format
== MESA_FORMAT_B10G10R10A2_UNORM
||
795 format
== MESA_FORMAT_B10G10R10X2_UNORM
||
796 format
== MESA_FORMAT_R10G10B10A2_UNORM
||
797 format
== MESA_FORMAT_R10G10B10X2_UNORM
)) {
806 * Is the given base format a legal format for a depth/stencil renderbuffer?
809 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
811 switch (baseFormat
) {
812 case GL_DEPTH_COMPONENT
:
813 case GL_DEPTH_STENCIL_EXT
:
822 * Test if an attachment point is complete and update its Complete field.
823 * \param format if GL_COLOR, this is a color attachment point,
824 * if GL_DEPTH, this is a depth component attachment point,
825 * if GL_STENCIL, this is a stencil component attachment point.
828 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
829 struct gl_renderbuffer_attachment
*att
)
831 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
833 /* assume complete */
834 att
->Complete
= GL_TRUE
;
836 /* Look for reasons why the attachment might be incomplete */
837 if (att
->Type
== GL_TEXTURE
) {
838 const struct gl_texture_object
*texObj
= att
->Texture
;
839 const struct gl_texture_image
*texImage
;
843 att_incomplete("no texobj");
844 att
->Complete
= GL_FALSE
;
848 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
850 att_incomplete("no teximage");
851 att
->Complete
= GL_FALSE
;
854 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
855 att_incomplete("teximage width/height=0");
856 att
->Complete
= GL_FALSE
;
860 switch (texObj
->Target
) {
862 if (att
->Zoffset
>= texImage
->Depth
) {
863 att_incomplete("bad z offset");
864 att
->Complete
= GL_FALSE
;
868 case GL_TEXTURE_1D_ARRAY
:
869 if (att
->Zoffset
>= texImage
->Height
) {
870 att_incomplete("bad 1D-array layer");
871 att
->Complete
= GL_FALSE
;
875 case GL_TEXTURE_2D_ARRAY
:
876 if (att
->Zoffset
>= texImage
->Depth
) {
877 att_incomplete("bad 2D-array layer");
878 att
->Complete
= GL_FALSE
;
882 case GL_TEXTURE_CUBE_MAP_ARRAY
:
883 if (att
->Zoffset
>= texImage
->Depth
) {
884 att_incomplete("bad cube-array layer");
885 att
->Complete
= GL_FALSE
;
891 baseFormat
= texImage
->_BaseFormat
;
893 if (format
== GL_COLOR
) {
894 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
895 att_incomplete("bad format");
896 att
->Complete
= GL_FALSE
;
899 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
900 att_incomplete("compressed internalformat");
901 att
->Complete
= GL_FALSE
;
905 /* OES_texture_float allows creation and use of floating point
906 * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow
907 * these textures to be used as a render target, this is done via
908 * GL_EXT_color_buffer(_half)_float with set of new sized types.
910 if (_mesa_is_gles(ctx
) && (texObj
->_IsFloat
|| texObj
->_IsHalfFloat
)) {
911 att_incomplete("bad internal format");
912 att
->Complete
= GL_FALSE
;
916 else if (format
== GL_DEPTH
) {
917 if (baseFormat
== GL_DEPTH_COMPONENT
) {
920 else if (ctx
->Extensions
.ARB_depth_texture
&&
921 baseFormat
== GL_DEPTH_STENCIL
) {
925 att
->Complete
= GL_FALSE
;
926 att_incomplete("bad depth format");
931 assert(format
== GL_STENCIL
);
932 if (ctx
->Extensions
.ARB_depth_texture
&&
933 baseFormat
== GL_DEPTH_STENCIL
) {
935 } else if (ctx
->Extensions
.ARB_texture_stencil8
&&
936 baseFormat
== GL_STENCIL_INDEX
) {
939 /* no such thing as stencil-only textures */
940 att_incomplete("illegal stencil texture");
941 att
->Complete
= GL_FALSE
;
946 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
947 const GLenum baseFormat
= att
->Renderbuffer
->_BaseFormat
;
949 assert(att
->Renderbuffer
);
950 if (!att
->Renderbuffer
->InternalFormat
||
951 att
->Renderbuffer
->Width
< 1 ||
952 att
->Renderbuffer
->Height
< 1) {
953 att_incomplete("0x0 renderbuffer");
954 att
->Complete
= GL_FALSE
;
957 if (format
== GL_COLOR
) {
958 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
959 att_incomplete("bad renderbuffer color format");
960 att
->Complete
= GL_FALSE
;
964 else if (format
== GL_DEPTH
) {
965 if (baseFormat
== GL_DEPTH_COMPONENT
) {
968 else if (baseFormat
== GL_DEPTH_STENCIL
) {
972 att_incomplete("bad renderbuffer depth format");
973 att
->Complete
= GL_FALSE
;
978 assert(format
== GL_STENCIL
);
979 if (baseFormat
== GL_STENCIL_INDEX
||
980 baseFormat
== GL_DEPTH_STENCIL
) {
984 att
->Complete
= GL_FALSE
;
985 att_incomplete("bad renderbuffer stencil format");
991 assert(att
->Type
== GL_NONE
);
999 * Test if the given framebuffer object is complete and update its
1000 * Status field with the results.
1001 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
1002 * driver to make hardware-specific validation/completeness checks.
1003 * Also update the framebuffer's Width and Height fields if the
1004 * framebuffer is complete.
1007 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
1008 struct gl_framebuffer
*fb
)
1011 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
1012 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
1013 GLint numColorSamples
= -1;
1014 GLint numColorStorageSamples
= -1;
1015 GLint numDepthSamples
= -1;
1016 GLint fixedSampleLocations
= -1;
1019 /* Covers max_layer_count, is_layered, and layer_tex_target */
1020 bool layer_info_valid
= false;
1021 GLuint max_layer_count
= 0, att_layer_count
;
1022 bool is_layered
= false;
1023 GLenum layer_tex_target
= 0;
1024 bool has_depth_attachment
= false;
1025 bool has_stencil_attachment
= false;
1027 assert(_mesa_is_user_fbo(fb
));
1029 /* we're changing framebuffer fields here */
1030 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1035 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
1036 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
1037 fb
->_HasAttachments
= true;
1038 fb
->_IntegerBuffers
= 0;
1039 fb
->_RGBBuffers
= 0;
1040 fb
->_FP32Buffers
= 0;
1042 /* Start at -2 to more easily loop over all attachment points.
1044 * -1: stencil buffer
1047 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
1048 struct gl_renderbuffer_attachment
*att
;
1051 mesa_format attFormat
;
1052 GLenum att_tex_target
= GL_NONE
;
1055 * XXX for ARB_fbo, only check color buffers that are named by
1056 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
1059 /* check for attachment completeness
1062 att
= &fb
->Attachment
[BUFFER_DEPTH
];
1063 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
1064 if (!att
->Complete
) {
1065 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1066 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
1068 } else if (att
->Type
!= GL_NONE
) {
1069 has_depth_attachment
= true;
1073 att
= &fb
->Attachment
[BUFFER_STENCIL
];
1074 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
1075 if (!att
->Complete
) {
1076 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1077 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
1079 } else if (att
->Type
!= GL_NONE
) {
1080 has_stencil_attachment
= true;
1084 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
1085 test_attachment_completeness(ctx
, GL_COLOR
, att
);
1086 if (!att
->Complete
) {
1087 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1088 fbo_incomplete(ctx
, "color attachment incomplete", i
);
1093 /* get width, height, format of the renderbuffer/texture
1095 unsigned attNumSamples
, attNumStorageSamples
;
1097 if (att
->Type
== GL_TEXTURE
) {
1098 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
1099 att_tex_target
= att
->Texture
->Target
;
1100 minWidth
= MIN2(minWidth
, texImg
->Width
);
1101 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
1102 minHeight
= MIN2(minHeight
, texImg
->Height
);
1103 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
1104 f
= texImg
->_BaseFormat
;
1106 attFormat
= texImg
->TexFormat
;
1109 if (!is_format_color_renderable(ctx
, attFormat
,
1110 texImg
->InternalFormat
) &&
1111 !is_legal_depth_format(ctx
, f
) &&
1112 f
!= GL_STENCIL_INDEX
) {
1113 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
;
1114 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
1118 if (fixedSampleLocations
< 0)
1119 fixedSampleLocations
= texImg
->FixedSampleLocations
;
1120 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
1121 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1122 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1126 if (att
->NumSamples
> 0)
1127 attNumSamples
= att
->NumSamples
;
1129 attNumSamples
= texImg
->NumSamples
;
1130 attNumStorageSamples
= attNumSamples
;
1132 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1133 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
1134 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
1135 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
1136 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
1137 f
= att
->Renderbuffer
->InternalFormat
;
1138 baseFormat
= att
->Renderbuffer
->_BaseFormat
;
1139 attFormat
= att
->Renderbuffer
->Format
;
1142 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1143 if (fixedSampleLocations
< 0)
1144 fixedSampleLocations
= GL_TRUE
;
1145 else if (fixedSampleLocations
!= GL_TRUE
) {
1146 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1147 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1151 attNumSamples
= att
->Renderbuffer
->NumSamples
;
1152 attNumStorageSamples
= att
->Renderbuffer
->NumStorageSamples
;
1155 assert(att
->Type
== GL_NONE
);
1160 /* Color buffers. */
1161 if (numColorSamples
< 0) {
1162 assert(numColorStorageSamples
< 0);
1163 numColorSamples
= attNumSamples
;
1164 numColorStorageSamples
= attNumStorageSamples
;
1165 } else if (numColorSamples
!= attNumSamples
||
1166 numColorStorageSamples
!= attNumStorageSamples
) {
1167 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1168 fbo_incomplete(ctx
, "inconsistent sample counts", -1);
1172 /* Depth/stencil buffers. */
1173 if (numDepthSamples
< 0) {
1174 numDepthSamples
= attNumSamples
;
1175 } else if (numDepthSamples
!= attNumSamples
) {
1176 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1177 fbo_incomplete(ctx
, "inconsistent sample counts", -1);
1182 /* Update flags describing color buffer datatypes */
1184 GLenum type
= _mesa_get_format_datatype(attFormat
);
1186 /* check if integer color */
1187 if (_mesa_is_format_integer_color(attFormat
))
1188 fb
->_IntegerBuffers
|= (1 << i
);
1190 if (baseFormat
== GL_RGB
)
1191 fb
->_RGBBuffers
|= (1 << i
);
1193 if (type
== GL_FLOAT
&& _mesa_get_format_max_bits(attFormat
) > 16)
1194 fb
->_FP32Buffers
|= (1 << i
);
1196 fb
->_AllColorBuffersFixedPoint
=
1197 fb
->_AllColorBuffersFixedPoint
&&
1198 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1200 fb
->_HasSNormOrFloatColorBuffer
=
1201 fb
->_HasSNormOrFloatColorBuffer
||
1202 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1205 /* Error-check width, height, format */
1206 if (numImages
== 1) {
1213 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1214 /* check that width, height, format are same */
1215 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1216 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1217 fbo_incomplete(ctx
, "width or height mismatch", -1);
1220 /* check that all color buffers are the same format */
1221 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1222 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1223 fbo_incomplete(ctx
, "format mismatch", -1);
1229 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1231 if (att
->Type
== GL_RENDERBUFFER
&&
1232 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1233 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1234 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1238 /* Check that layered rendering is consistent. */
1240 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1241 att_layer_count
= 6;
1242 else if (att_tex_target
== GL_TEXTURE_1D_ARRAY
)
1243 att_layer_count
= att
->Renderbuffer
->Height
;
1245 att_layer_count
= att
->Renderbuffer
->Depth
;
1247 att_layer_count
= 0;
1249 if (!layer_info_valid
) {
1250 is_layered
= att
->Layered
;
1251 max_layer_count
= att_layer_count
;
1252 layer_tex_target
= att_tex_target
;
1253 layer_info_valid
= true;
1254 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1255 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1256 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1258 } else if (is_layered
!= att
->Layered
) {
1259 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1261 "framebuffer attachment layer mode is inconsistent",
1264 } else if (att_layer_count
> max_layer_count
) {
1265 max_layer_count
= att_layer_count
;
1269 * The extension GL_ARB_framebuffer_no_attachments places additional
1270 * requirement on each attachment. Those additional requirements are
1271 * tighter that those of previous versions of GL. In interest of better
1272 * compatibility, we will not enforce these restrictions. For the record
1273 * those additional restrictions are quoted below:
1275 * "The width and height of image are greater than zero and less than or
1276 * equal to the values of the implementation-dependent limits
1277 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1279 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1280 * array texture and the attachment is layered, the depth or layer count
1281 * of the texture is less than or equal to the implementation-dependent
1282 * limit MAX_FRAMEBUFFER_LAYERS."
1284 * "If image has multiple samples, its sample count is less than or equal
1285 * to the value of the implementation-dependent limit
1286 * MAX_FRAMEBUFFER_SAMPLES."
1288 * The same requirements are also in place for GL 4.5,
1289 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1293 if (ctx
->Extensions
.AMD_framebuffer_multisample_advanced
) {
1294 /* See if non-matching sample counts are supported. */
1295 if (numColorSamples
>= 0 && numDepthSamples
>= 0) {
1298 assert(numColorStorageSamples
!= -1);
1300 numColorSamples
= MAX2(numColorSamples
, 1);
1301 numColorStorageSamples
= MAX2(numColorStorageSamples
, 1);
1302 numDepthSamples
= MAX2(numDepthSamples
, 1);
1304 if (numColorSamples
== 1 && numColorStorageSamples
== 1 &&
1305 numDepthSamples
== 1) {
1308 for (i
= 0; i
< ctx
->Const
.NumSupportedMultisampleModes
; i
++) {
1310 &ctx
->Const
.SupportedMultisampleModes
[i
].NumColorSamples
;
1312 if (counts
[0] == numColorSamples
&&
1313 counts
[1] == numColorStorageSamples
&&
1314 counts
[2] == numDepthSamples
) {
1322 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1323 fbo_incomplete(ctx
, "unsupported sample counts", -1);
1328 /* If the extension is unsupported, all sample counts must be equal. */
1329 if (numColorSamples
>= 0 &&
1330 (numColorSamples
!= numColorStorageSamples
||
1331 (numDepthSamples
>= 0 && numColorSamples
!= numDepthSamples
))) {
1332 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1333 fbo_incomplete(ctx
, "inconsistent sample counts", -1);
1338 fb
->MaxNumLayers
= max_layer_count
;
1340 if (numImages
== 0) {
1341 fb
->_HasAttachments
= false;
1343 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1344 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1345 fbo_incomplete(ctx
, "no attachments", -1);
1349 if (fb
->DefaultGeometry
.Width
== 0 || fb
->DefaultGeometry
.Height
== 0) {
1350 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1351 fbo_incomplete(ctx
, "no attachments and default width or height is 0", -1);
1356 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1357 /* Check that all DrawBuffers are present */
1358 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1359 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1360 const struct gl_renderbuffer_attachment
*att
1361 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
], NULL
);
1363 if (att
->Type
== GL_NONE
) {
1364 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1365 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1371 /* Check that the ReadBuffer is present */
1372 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1373 const struct gl_renderbuffer_attachment
*att
1374 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
, NULL
);
1376 if (att
->Type
== GL_NONE
) {
1377 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1378 fbo_incomplete(ctx
, "missing readbuffer", -1);
1384 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1386 * "Depth and stencil attachments, if present, are the same image."
1388 * This restriction is not present in the OpenGL ES2 spec.
1390 if (_mesa_is_gles3(ctx
) &&
1391 has_stencil_attachment
&& has_depth_attachment
&&
1392 !_mesa_has_depthstencil_combined(fb
)) {
1393 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1394 fbo_incomplete(ctx
, "Depth and stencil attachments must be the same image", -1);
1398 /* Provisionally set status = COMPLETE ... */
1399 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1401 /* ... but the driver may say the FB is incomplete.
1402 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1405 if (ctx
->Driver
.ValidateFramebuffer
) {
1406 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1407 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1408 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1414 * Note that if ARB_framebuffer_object is supported and the attached
1415 * renderbuffers/textures are different sizes, the framebuffer
1416 * width/height will be set to the smallest width/height.
1418 if (numImages
!= 0) {
1419 fb
->Width
= minWidth
;
1420 fb
->Height
= minHeight
;
1423 /* finally, update the visual info for the framebuffer */
1424 _mesa_update_framebuffer_visual(ctx
, fb
);
1428 GLboolean GLAPIENTRY
1429 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1431 struct gl_renderbuffer
*rb
;
1433 GET_CURRENT_CONTEXT(ctx
);
1435 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1437 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1438 return rb
!= NULL
&& rb
!= &DummyRenderbuffer
;
1442 static struct gl_renderbuffer
*
1443 allocate_renderbuffer_locked(struct gl_context
*ctx
, GLuint renderbuffer
,
1446 struct gl_renderbuffer
*newRb
;
1448 /* create new renderbuffer object */
1449 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1451 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1454 assert(newRb
->AllocStorage
);
1455 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1462 bind_renderbuffer(GLenum target
, GLuint renderbuffer
)
1464 struct gl_renderbuffer
*newRb
;
1465 GET_CURRENT_CONTEXT(ctx
);
1467 if (target
!= GL_RENDERBUFFER_EXT
) {
1468 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1472 /* No need to flush here since the render buffer binding has no
1473 * effect on rendering state.
1477 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1478 if (newRb
== &DummyRenderbuffer
) {
1479 /* ID was reserved, but no real renderbuffer object made yet */
1482 else if (!newRb
&& ctx
->API
== API_OPENGL_CORE
) {
1483 /* All RB IDs must be Gen'd */
1484 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1485 "glBindRenderbuffer(non-gen name)");
1490 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1491 newRb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
1492 "glBindRenderbufferEXT");
1493 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1500 assert(newRb
!= &DummyRenderbuffer
);
1502 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1506 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1508 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1509 * entry point, but they allow the use of user-generated names.
1511 bind_renderbuffer(target
, renderbuffer
);
1515 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1517 bind_renderbuffer(target
, renderbuffer
);
1521 * ARB_framebuffer_no_attachment and ARB_sample_locations - Application passes
1522 * requested param's here. NOTE: NumSamples requested need not be _NumSamples
1523 * which is what the hw supports.
1526 framebuffer_parameteri(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1527 GLenum pname
, GLint param
, const char *func
)
1529 bool cannot_be_winsys_fbo
= false;
1532 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1533 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1534 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1535 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1536 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1537 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
)
1538 goto invalid_pname_enum
;
1539 cannot_be_winsys_fbo
= true;
1541 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1542 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1543 if (!ctx
->Extensions
.ARB_sample_locations
)
1544 goto invalid_pname_enum
;
1546 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1547 if (!ctx
->Extensions
.MESA_framebuffer_flip_y
)
1548 goto invalid_pname_enum
;
1549 cannot_be_winsys_fbo
= true;
1552 goto invalid_pname_enum
;
1555 if (cannot_be_winsys_fbo
&& _mesa_is_winsys_fbo(fb
)) {
1556 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1557 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1562 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1563 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferWidth
)
1564 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1566 fb
->DefaultGeometry
.Width
= param
;
1568 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1569 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferHeight
)
1570 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1572 fb
->DefaultGeometry
.Height
= param
;
1574 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1576 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1577 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1579 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1580 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1583 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferLayers
)
1584 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1586 fb
->DefaultGeometry
.Layers
= param
;
1588 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1589 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferSamples
)
1590 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1592 fb
->DefaultGeometry
.NumSamples
= param
;
1594 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1595 fb
->DefaultGeometry
.FixedSampleLocations
= param
;
1597 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1598 fb
->ProgrammableSampleLocations
= !!param
;
1600 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1601 fb
->SampleLocationPixelGrid
= !!param
;
1603 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1609 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1610 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1611 if (fb
== ctx
->DrawBuffer
)
1612 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
1615 invalidate_framebuffer(fb
);
1616 ctx
->NewState
|= _NEW_BUFFERS
;
1623 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1627 validate_framebuffer_parameter_extensions(GLenum pname
, const char *func
)
1629 GET_CURRENT_CONTEXT(ctx
);
1631 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1632 !ctx
->Extensions
.ARB_sample_locations
&&
1633 !ctx
->Extensions
.MESA_framebuffer_flip_y
) {
1634 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1636 "(none of ARB_framebuffer_no_attachments,"
1637 " ARB_sample_locations, or"
1638 " MESA_framebuffer_flip_y extensions are available)",
1644 * If only the MESA_framebuffer_flip_y extension is enabled
1645 * pname can only be GL_FRAMEBUFFER_FLIP_Y_MESA
1647 if (ctx
->Extensions
.MESA_framebuffer_flip_y
&&
1648 pname
!= GL_FRAMEBUFFER_FLIP_Y_MESA
&&
1649 !(ctx
->Extensions
.ARB_framebuffer_no_attachments
||
1650 ctx
->Extensions
.ARB_sample_locations
)) {
1651 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1659 _mesa_FramebufferParameteri(GLenum target
, GLenum pname
, GLint param
)
1661 GET_CURRENT_CONTEXT(ctx
);
1662 struct gl_framebuffer
*fb
;
1664 if (!validate_framebuffer_parameter_extensions(pname
,
1665 "glFramebufferParameteri")) {
1669 fb
= get_framebuffer_target(ctx
, target
);
1671 _mesa_error(ctx
, GL_INVALID_ENUM
,
1672 "glFramebufferParameteri(target=0x%x)", target
);
1676 framebuffer_parameteri(ctx
, fb
, pname
, param
, "glFramebufferParameteri");
1680 _mesa_FramebufferParameteriMESA(GLenum target
, GLenum pname
, GLint param
)
1682 _mesa_FramebufferParameteri(target
, pname
, param
);
1686 validate_get_framebuffer_parameteriv_pname(struct gl_context
*ctx
,
1687 struct gl_framebuffer
*fb
,
1688 GLuint pname
, const char *func
)
1690 bool cannot_be_winsys_fbo
= true;
1693 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1695 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1696 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1698 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1699 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1703 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1704 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1705 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1706 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1708 case GL_DOUBLEBUFFER
:
1709 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1710 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1712 case GL_SAMPLE_BUFFERS
:
1714 /* From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries:
1716 * "An INVALID_OPERATION error is generated by GetFramebufferParameteriv
1717 * if the default framebuffer is bound to target and pname is not one
1718 * of the accepted values from table 23.73, other than
1721 * For OpenGL ES, using default framebuffer raises INVALID_OPERATION
1724 cannot_be_winsys_fbo
= !_mesa_is_desktop_gl(ctx
);
1726 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1727 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1728 if (!ctx
->Extensions
.ARB_sample_locations
)
1729 goto invalid_pname_enum
;
1730 cannot_be_winsys_fbo
= false;
1732 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1733 if (!ctx
->Extensions
.MESA_framebuffer_flip_y
) {
1734 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1739 goto invalid_pname_enum
;
1742 if (cannot_be_winsys_fbo
&& _mesa_is_winsys_fbo(fb
)) {
1743 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1744 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1751 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1756 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1757 GLenum pname
, GLint
*params
, const char *func
)
1759 if (!validate_get_framebuffer_parameteriv_pname(ctx
, fb
, pname
, func
))
1763 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1764 *params
= fb
->DefaultGeometry
.Width
;
1766 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1767 *params
= fb
->DefaultGeometry
.Height
;
1769 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1770 *params
= fb
->DefaultGeometry
.Layers
;
1772 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1773 *params
= fb
->DefaultGeometry
.NumSamples
;
1775 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1776 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1778 case GL_DOUBLEBUFFER
:
1779 *params
= fb
->Visual
.doubleBufferMode
;
1781 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1782 *params
= _mesa_get_color_read_format(ctx
, fb
, func
);
1784 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1785 *params
= _mesa_get_color_read_type(ctx
, fb
, func
);
1788 *params
= _mesa_geometric_samples(fb
);
1790 case GL_SAMPLE_BUFFERS
:
1791 *params
= _mesa_geometric_samples(fb
) > 0;
1794 *params
= fb
->Visual
.stereoMode
;
1796 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1797 *params
= fb
->ProgrammableSampleLocations
;
1799 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1800 *params
= fb
->SampleLocationPixelGrid
;
1802 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1803 *params
= fb
->FlipY
;
1809 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1811 GET_CURRENT_CONTEXT(ctx
);
1812 struct gl_framebuffer
*fb
;
1814 if (!validate_framebuffer_parameter_extensions(pname
,
1815 "glGetFramebufferParameteriv")) {
1819 fb
= get_framebuffer_target(ctx
, target
);
1821 _mesa_error(ctx
, GL_INVALID_ENUM
,
1822 "glGetFramebufferParameteriv(target=0x%x)", target
);
1826 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1827 "glGetFramebufferParameteriv");
1831 _mesa_GetFramebufferParameterivMESA(GLenum target
, GLenum pname
, GLint
*params
)
1833 _mesa_GetFramebufferParameteriv(target
, pname
, params
);
1837 * Remove the specified renderbuffer or texture from any attachment point in
1841 * \c true if the renderbuffer was detached from an attachment point. \c
1845 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1846 struct gl_framebuffer
*fb
,
1850 bool progress
= false;
1852 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1853 if (fb
->Attachment
[i
].Texture
== att
1854 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1855 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1860 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1861 * Completeness," of the OpenGL 3.1 spec says:
1863 * "Performing any of the following actions may change whether the
1864 * framebuffer is considered complete or incomplete:
1868 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1869 * containing an image that is attached to a framebuffer object
1870 * that is bound to the framebuffer."
1873 invalidate_framebuffer(fb
);
1880 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1883 GET_CURRENT_CONTEXT(ctx
);
1886 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1890 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1892 for (i
= 0; i
< n
; i
++) {
1893 if (renderbuffers
[i
] > 0) {
1894 struct gl_renderbuffer
*rb
;
1895 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1897 /* check if deleting currently bound renderbuffer object */
1898 if (rb
== ctx
->CurrentRenderbuffer
) {
1900 assert(rb
->RefCount
>= 2);
1901 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1904 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1905 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1906 * of the OpenGL 3.1 spec says:
1908 * "If a renderbuffer object is deleted while its image is
1909 * attached to one or more attachment points in the currently
1910 * bound framebuffer, then it is as if FramebufferRenderbuffer
1911 * had been called, with a renderbuffer of 0, for each
1912 * attachment point to which this image was attached in the
1913 * currently bound framebuffer. In other words, this
1914 * renderbuffer image is first detached from all attachment
1915 * points in the currently bound framebuffer. Note that the
1916 * renderbuffer image is specifically not detached from any
1917 * non-bound framebuffers. Detaching the image from any
1918 * non-bound framebuffers is the responsibility of the
1921 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1922 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1924 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1925 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1926 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1929 /* Remove from hash table immediately, to free the ID.
1930 * But the object will not be freed until it's no longer
1931 * referenced anywhere else.
1933 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1935 if (rb
!= &DummyRenderbuffer
) {
1936 /* no longer referenced by hash table */
1937 _mesa_reference_renderbuffer(&rb
, NULL
);
1945 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1948 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1955 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1957 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1959 for (i
= 0; i
< n
; i
++) {
1960 GLuint name
= first
+ i
;
1961 renderbuffers
[i
] = name
;
1964 allocate_renderbuffer_locked(ctx
, name
, func
);
1966 /* insert a dummy renderbuffer into the hash table */
1967 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1968 &DummyRenderbuffer
);
1972 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1977 create_render_buffers_err(struct gl_context
*ctx
, GLsizei n
,
1978 GLuint
*renderbuffers
, bool dsa
)
1980 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1983 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1987 create_render_buffers(ctx
, n
, renderbuffers
, dsa
);
1992 _mesa_GenRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1994 GET_CURRENT_CONTEXT(ctx
);
1995 create_render_buffers(ctx
, n
, renderbuffers
, false);
2000 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
2002 GET_CURRENT_CONTEXT(ctx
);
2003 create_render_buffers_err(ctx
, n
, renderbuffers
, false);
2008 _mesa_CreateRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
2010 GET_CURRENT_CONTEXT(ctx
);
2011 create_render_buffers(ctx
, n
, renderbuffers
, true);
2016 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
2018 GET_CURRENT_CONTEXT(ctx
);
2019 create_render_buffers_err(ctx
, n
, renderbuffers
, true);
2024 * Given an internal format token for a render buffer, return the
2025 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
2026 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
2027 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
2029 * This is similar to _mesa_base_tex_format() but the set of valid
2030 * internal formats is different.
2032 * Note that even if a format is determined to be legal here, validation
2033 * of the FBO may fail if the format is not supported by the driver/GPU.
2035 * \param internalFormat as passed to glRenderbufferStorage()
2036 * \return the base internal format, or 0 if internalFormat is illegal
2039 _mesa_base_fbo_format(const struct gl_context
*ctx
, GLenum internalFormat
)
2042 * Notes: some formats such as alpha, luminance, etc. were added
2043 * with GL_ARB_framebuffer_object.
2045 switch (internalFormat
) {
2051 return (ctx
->API
== API_OPENGL_COMPAT
&&
2052 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
2056 case GL_LUMINANCE12
:
2057 case GL_LUMINANCE16
:
2058 return (ctx
->API
== API_OPENGL_COMPAT
&&
2059 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
2060 case GL_LUMINANCE_ALPHA
:
2061 case GL_LUMINANCE4_ALPHA4
:
2062 case GL_LUMINANCE6_ALPHA2
:
2063 case GL_LUMINANCE8_ALPHA8
:
2064 case GL_LUMINANCE12_ALPHA4
:
2065 case GL_LUMINANCE12_ALPHA12
:
2066 case GL_LUMINANCE16_ALPHA16
:
2067 return (ctx
->API
== API_OPENGL_COMPAT
&&
2068 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
2072 case GL_INTENSITY12
:
2073 case GL_INTENSITY16
:
2074 return (ctx
->API
== API_OPENGL_COMPAT
&&
2075 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
2085 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
2087 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
2095 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
2097 return _mesa_is_desktop_gl(ctx
) || _mesa_has_EXT_texture_norm16(ctx
)
2100 case GL_SRGB8_ALPHA8_EXT
:
2101 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2102 case GL_STENCIL_INDEX
:
2103 case GL_STENCIL_INDEX1_EXT
:
2104 case GL_STENCIL_INDEX4_EXT
:
2105 case GL_STENCIL_INDEX16_EXT
:
2106 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
2107 * OpenGL ES, but Mesa does not currently support them.
2109 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
2110 case GL_STENCIL_INDEX8_EXT
:
2111 return GL_STENCIL_INDEX
;
2112 case GL_DEPTH_COMPONENT
:
2113 case GL_DEPTH_COMPONENT32
:
2114 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
2115 case GL_DEPTH_COMPONENT16
:
2116 case GL_DEPTH_COMPONENT24
:
2117 return GL_DEPTH_COMPONENT
;
2118 case GL_DEPTH_STENCIL
:
2119 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
2120 case GL_DEPTH24_STENCIL8
:
2121 return GL_DEPTH_STENCIL
;
2122 case GL_DEPTH_COMPONENT32F
:
2123 return ctx
->Version
>= 30
2124 || (ctx
->API
== API_OPENGL_COMPAT
&&
2125 ctx
->Extensions
.ARB_depth_buffer_float
)
2126 ? GL_DEPTH_COMPONENT
: 0;
2127 case GL_DEPTH32F_STENCIL8
:
2128 return ctx
->Version
>= 30
2129 || (ctx
->API
== API_OPENGL_COMPAT
&&
2130 ctx
->Extensions
.ARB_depth_buffer_float
)
2131 ? GL_DEPTH_STENCIL
: 0;
2133 return _mesa_has_ARB_texture_rg(ctx
) ? GL_RED
: 0;
2135 return _mesa_has_ARB_texture_rg(ctx
) || _mesa_has_EXT_texture_norm16(ctx
)
2138 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
2141 return _mesa_has_ARB_texture_rg(ctx
) ? GL_RG
: 0;
2143 return _mesa_has_ARB_texture_rg(ctx
) || _mesa_has_EXT_texture_norm16(ctx
)
2146 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
2148 /* signed normalized texture formats */
2150 return _mesa_has_EXT_texture_snorm(ctx
) || _mesa_has_EXT_render_snorm(ctx
)
2153 return _mesa_has_EXT_texture_snorm(ctx
) ? GL_RED
: 0;
2155 return _mesa_has_EXT_texture_snorm(ctx
) ||
2156 (_mesa_has_EXT_render_snorm(ctx
) &&
2157 _mesa_has_EXT_texture_norm16(ctx
))
2160 return _mesa_has_EXT_texture_snorm(ctx
) || _mesa_has_EXT_render_snorm(ctx
)
2163 return _mesa_has_EXT_texture_snorm(ctx
) ? GL_RG
: 0;
2165 return _mesa_has_EXT_texture_snorm(ctx
) ||
2166 (_mesa_has_EXT_render_snorm(ctx
) &&
2167 _mesa_has_EXT_texture_norm16(ctx
))
2171 case GL_RGB16_SNORM
:
2172 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2174 case GL_RGBA8_SNORM
:
2175 return _mesa_has_EXT_texture_snorm(ctx
) || _mesa_has_EXT_render_snorm(ctx
)
2178 return _mesa_has_EXT_texture_snorm(ctx
) ? GL_RGBA
: 0;
2179 case GL_RGBA16_SNORM
:
2180 return _mesa_has_EXT_texture_snorm(ctx
) ||
2181 (_mesa_has_EXT_render_snorm(ctx
) &&
2182 _mesa_has_EXT_texture_norm16(ctx
))
2184 case GL_ALPHA_SNORM
:
2185 case GL_ALPHA8_SNORM
:
2186 case GL_ALPHA16_SNORM
:
2187 return ctx
->API
== API_OPENGL_COMPAT
&&
2188 ctx
->Extensions
.EXT_texture_snorm
&&
2189 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2190 case GL_LUMINANCE_SNORM
:
2191 case GL_LUMINANCE8_SNORM
:
2192 case GL_LUMINANCE16_SNORM
:
2193 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2195 case GL_LUMINANCE_ALPHA_SNORM
:
2196 case GL_LUMINANCE8_ALPHA8_SNORM
:
2197 case GL_LUMINANCE16_ALPHA16_SNORM
:
2198 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2199 ? GL_LUMINANCE_ALPHA
: 0;
2200 case GL_INTENSITY_SNORM
:
2201 case GL_INTENSITY8_SNORM
:
2202 case GL_INTENSITY16_SNORM
:
2203 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2208 return ((_mesa_is_desktop_gl(ctx
) &&
2209 ctx
->Extensions
.ARB_texture_rg
&&
2210 ctx
->Extensions
.ARB_texture_float
) ||
2211 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2215 return ((_mesa_is_desktop_gl(ctx
) &&
2216 ctx
->Extensions
.ARB_texture_rg
&&
2217 ctx
->Extensions
.ARB_texture_float
) ||
2218 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2222 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
2226 return ((_mesa_is_desktop_gl(ctx
) &&
2227 ctx
->Extensions
.ARB_texture_float
) ||
2228 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2231 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_shared_exponent
)
2233 case GL_ALPHA16F_ARB
:
2234 case GL_ALPHA32F_ARB
:
2235 return ctx
->API
== API_OPENGL_COMPAT
&&
2236 ctx
->Extensions
.ARB_texture_float
&&
2237 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2238 case GL_LUMINANCE16F_ARB
:
2239 case GL_LUMINANCE32F_ARB
:
2240 return ctx
->API
== API_OPENGL_COMPAT
&&
2241 ctx
->Extensions
.ARB_texture_float
&&
2242 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2243 case GL_LUMINANCE_ALPHA16F_ARB
:
2244 case GL_LUMINANCE_ALPHA32F_ARB
:
2245 return ctx
->API
== API_OPENGL_COMPAT
&&
2246 ctx
->Extensions
.ARB_texture_float
&&
2247 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2248 case GL_INTENSITY16F_ARB
:
2249 case GL_INTENSITY32F_ARB
:
2250 return ctx
->API
== API_OPENGL_COMPAT
&&
2251 ctx
->Extensions
.ARB_texture_float
&&
2252 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2253 case GL_R11F_G11F_B10F
:
2254 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
2255 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2258 case GL_RGBA8UI_EXT
:
2259 case GL_RGBA16UI_EXT
:
2260 case GL_RGBA32UI_EXT
:
2262 case GL_RGBA16I_EXT
:
2263 case GL_RGBA32I_EXT
:
2264 return ctx
->Version
>= 30
2265 || (_mesa_is_desktop_gl(ctx
) &&
2266 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
2269 case GL_RGB16UI_EXT
:
2270 case GL_RGB32UI_EXT
:
2274 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
2282 return ctx
->Version
>= 30
2283 || (_mesa_is_desktop_gl(ctx
) &&
2284 ctx
->Extensions
.ARB_texture_rg
&&
2285 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
2293 return ctx
->Version
>= 30
2294 || (_mesa_is_desktop_gl(ctx
) &&
2295 ctx
->Extensions
.ARB_texture_rg
&&
2296 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
2298 case GL_INTENSITY8I_EXT
:
2299 case GL_INTENSITY8UI_EXT
:
2300 case GL_INTENSITY16I_EXT
:
2301 case GL_INTENSITY16UI_EXT
:
2302 case GL_INTENSITY32I_EXT
:
2303 case GL_INTENSITY32UI_EXT
:
2304 return ctx
->API
== API_OPENGL_COMPAT
&&
2305 ctx
->Extensions
.EXT_texture_integer
&&
2306 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2308 case GL_LUMINANCE8I_EXT
:
2309 case GL_LUMINANCE8UI_EXT
:
2310 case GL_LUMINANCE16I_EXT
:
2311 case GL_LUMINANCE16UI_EXT
:
2312 case GL_LUMINANCE32I_EXT
:
2313 case GL_LUMINANCE32UI_EXT
:
2314 return ctx
->API
== API_OPENGL_COMPAT
&&
2315 ctx
->Extensions
.EXT_texture_integer
&&
2316 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2318 case GL_LUMINANCE_ALPHA8I_EXT
:
2319 case GL_LUMINANCE_ALPHA8UI_EXT
:
2320 case GL_LUMINANCE_ALPHA16I_EXT
:
2321 case GL_LUMINANCE_ALPHA16UI_EXT
:
2322 case GL_LUMINANCE_ALPHA32I_EXT
:
2323 case GL_LUMINANCE_ALPHA32UI_EXT
:
2324 return ctx
->API
== API_OPENGL_COMPAT
&&
2325 ctx
->Extensions
.EXT_texture_integer
&&
2326 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2328 case GL_ALPHA8I_EXT
:
2329 case GL_ALPHA8UI_EXT
:
2330 case GL_ALPHA16I_EXT
:
2331 case GL_ALPHA16UI_EXT
:
2332 case GL_ALPHA32I_EXT
:
2333 case GL_ALPHA32UI_EXT
:
2334 return ctx
->API
== API_OPENGL_COMPAT
&&
2335 ctx
->Extensions
.EXT_texture_integer
&&
2336 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2339 return (_mesa_is_desktop_gl(ctx
) &&
2340 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
2341 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2344 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2353 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2356 invalidate_rb(GLuint key
, void *data
, void *userData
)
2358 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2359 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2361 /* If this is a user-created FBO */
2362 if (_mesa_is_user_fbo(fb
)) {
2364 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2365 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2366 if (att
->Type
== GL_RENDERBUFFER
&&
2367 att
->Renderbuffer
== rb
) {
2368 /* Mark fb status as indeterminate to force re-validation */
2377 /** sentinal value, see below */
2378 #define NO_SAMPLES 1000
2381 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2382 GLenum internalFormat
, GLsizei width
,
2383 GLsizei height
, GLsizei samples
,
2384 GLsizei storageSamples
)
2386 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2388 assert(baseFormat
!= 0);
2389 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2390 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2391 assert(samples
!= NO_SAMPLES
);
2393 assert(samples
> 0);
2394 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2395 internalFormat
, samples
,
2396 storageSamples
) == GL_NO_ERROR
);
2399 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2401 if (rb
->InternalFormat
== internalFormat
&&
2402 rb
->Width
== (GLuint
) width
&&
2403 rb
->Height
== (GLuint
) height
&&
2404 rb
->NumSamples
== samples
&&
2405 rb
->NumStorageSamples
== storageSamples
) {
2406 /* no change in allocation needed */
2410 /* These MUST get set by the AllocStorage func */
2411 rb
->Format
= MESA_FORMAT_NONE
;
2412 rb
->NumSamples
= samples
;
2413 rb
->NumStorageSamples
= storageSamples
;
2415 /* Now allocate the storage */
2416 assert(rb
->AllocStorage
);
2417 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2418 /* No error - check/set fields now */
2419 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2420 assert(rb
->Width
== (GLuint
) width
);
2421 assert(rb
->Height
== (GLuint
) height
);
2422 rb
->InternalFormat
= internalFormat
;
2423 rb
->_BaseFormat
= baseFormat
;
2424 assert(rb
->_BaseFormat
!= 0);
2427 /* Probably ran out of memory - clear the fields */
2430 rb
->Format
= MESA_FORMAT_NONE
;
2431 rb
->InternalFormat
= GL_NONE
;
2432 rb
->_BaseFormat
= GL_NONE
;
2434 rb
->NumStorageSamples
= 0;
2437 /* Invalidate the framebuffers the renderbuffer is attached in. */
2438 if (rb
->AttachedAnytime
) {
2439 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2444 * Helper function used by renderbuffer_storage_direct() and
2445 * renderbuffer_storage_target().
2446 * samples will be NO_SAMPLES if called by a non-multisample function.
2449 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2450 GLenum internalFormat
, GLsizei width
,
2451 GLsizei height
, GLsizei samples
, GLsizei storageSamples
,
2455 GLenum sample_count_error
;
2457 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2458 if (baseFormat
== 0) {
2459 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2460 func
, _mesa_enum_to_string(internalFormat
));
2464 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2465 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2470 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2471 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2476 if (samples
== NO_SAMPLES
) {
2477 /* NumSamples == 0 indicates non-multisampling */
2482 /* check the sample count;
2483 * note: driver may choose to use more samples than what's requested
2485 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2486 internalFormat
, samples
, storageSamples
);
2488 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2490 * "If a negative number is provided where an argument of type sizei or
2491 * sizeiptr is specified, the error INVALID VALUE is generated."
2493 if (samples
< 0 || storageSamples
< 0) {
2494 sample_count_error
= GL_INVALID_VALUE
;
2497 if (sample_count_error
!= GL_NO_ERROR
) {
2498 _mesa_error(ctx
, sample_count_error
,
2499 "%s(samples=%d, storageSamples=%d)", func
, samples
,
2505 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
,
2510 * Helper function used by _mesa_NamedRenderbufferStorage*().
2511 * samples will be NO_SAMPLES if called by a non-multisample function.
2514 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2515 GLsizei width
, GLsizei height
, GLsizei samples
,
2516 GLsizei storageSamples
, const char *func
)
2518 GET_CURRENT_CONTEXT(ctx
);
2520 if (MESA_VERBOSE
& VERBOSE_API
) {
2521 if (samples
== NO_SAMPLES
)
2522 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2524 _mesa_enum_to_string(internalFormat
),
2527 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2529 _mesa_enum_to_string(internalFormat
),
2530 width
, height
, samples
);
2533 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2534 if (!rb
|| rb
== &DummyRenderbuffer
) {
2535 /* ID was reserved, but no real renderbuffer object made yet */
2536 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2537 func
, renderbuffer
);
2541 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
,
2542 storageSamples
, func
);
2546 * Helper function used by _mesa_RenderbufferStorage() and
2547 * _mesa_RenderbufferStorageMultisample().
2548 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2551 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2552 GLsizei width
, GLsizei height
, GLsizei samples
,
2553 GLsizei storageSamples
, const char *func
)
2555 GET_CURRENT_CONTEXT(ctx
);
2557 if (MESA_VERBOSE
& VERBOSE_API
) {
2558 if (samples
== NO_SAMPLES
)
2559 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2561 _mesa_enum_to_string(target
),
2562 _mesa_enum_to_string(internalFormat
),
2565 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2567 _mesa_enum_to_string(target
),
2568 _mesa_enum_to_string(internalFormat
),
2569 width
, height
, samples
);
2572 if (target
!= GL_RENDERBUFFER_EXT
) {
2573 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2577 if (!ctx
->CurrentRenderbuffer
) {
2578 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2583 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2584 height
, samples
, storageSamples
, func
);
2589 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2591 struct gl_renderbuffer
*rb
;
2592 GET_CURRENT_CONTEXT(ctx
);
2594 if (!ctx
->Extensions
.OES_EGL_image
) {
2595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2596 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2600 if (target
!= GL_RENDERBUFFER
) {
2601 _mesa_error(ctx
, GL_INVALID_ENUM
,
2602 "EGLImageTargetRenderbufferStorageOES");
2606 rb
= ctx
->CurrentRenderbuffer
;
2608 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2609 "EGLImageTargetRenderbufferStorageOES");
2613 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2615 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2620 * Helper function for _mesa_GetRenderbufferParameteriv() and
2621 * _mesa_GetFramebufferAttachmentParameteriv()
2622 * We have to be careful to respect the base format. For example, if a
2623 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2624 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2625 * we need to return zero.
2628 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2630 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2631 return _mesa_get_format_bits(format
, pname
);
2639 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2640 GLsizei width
, GLsizei height
)
2642 /* GL_ARB_fbo says calling this function is equivalent to calling
2643 * glRenderbufferStorageMultisample() with samples=0. We pass in
2644 * a token value here just for error reporting purposes.
2646 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2647 NO_SAMPLES
, 0, "glRenderbufferStorage");
2652 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2653 GLenum internalFormat
,
2654 GLsizei width
, GLsizei height
)
2656 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2658 "glRenderbufferStorageMultisample");
2663 _mesa_RenderbufferStorageMultisampleAdvancedAMD(
2664 GLenum target
, GLsizei samples
, GLsizei storageSamples
,
2665 GLenum internalFormat
, GLsizei width
, GLsizei height
)
2667 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2668 samples
, storageSamples
,
2669 "glRenderbufferStorageMultisampleAdvancedAMD");
2674 * OpenGL ES version of glRenderBufferStorage.
2677 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2678 GLsizei width
, GLsizei height
)
2680 switch (internalFormat
) {
2682 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2683 /* choose a closest format */
2684 internalFormat
= GL_RGB5
;
2690 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0, 0,
2691 "glRenderbufferStorageEXT");
2695 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2696 GLsizei width
, GLsizei height
)
2698 /* GL_ARB_fbo says calling this function is equivalent to calling
2699 * glRenderbufferStorageMultisample() with samples=0. We pass in
2700 * a token value here just for error reporting purposes.
2702 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2703 NO_SAMPLES
, 0, "glNamedRenderbufferStorage");
2707 _mesa_NamedRenderbufferStorageEXT(GLuint renderbuffer
, GLenum internalformat
,
2708 GLsizei width
, GLsizei height
)
2710 GET_CURRENT_CONTEXT(ctx
);
2711 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2712 if (!rb
|| rb
== &DummyRenderbuffer
) {
2713 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
2714 rb
= allocate_renderbuffer_locked(ctx
, renderbuffer
, "glNamedRenderbufferStorageEXT");
2715 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
2717 renderbuffer_storage(ctx
, rb
, internalformat
, width
, height
, NO_SAMPLES
,
2718 0, "glNamedRenderbufferStorageEXT");
2723 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2724 GLenum internalformat
,
2725 GLsizei width
, GLsizei height
)
2727 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2729 "glNamedRenderbufferStorageMultisample");
2734 _mesa_NamedRenderbufferStorageMultisampleEXT(GLuint renderbuffer
, GLsizei samples
,
2735 GLenum internalformat
,
2736 GLsizei width
, GLsizei height
)
2738 GET_CURRENT_CONTEXT(ctx
);
2739 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2740 if (!rb
|| rb
== &DummyRenderbuffer
) {
2741 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
2742 rb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
2743 "glNamedRenderbufferStorageMultisampleEXT");
2744 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
2746 renderbuffer_storage(ctx
, rb
, internalformat
, width
, height
,
2748 "glNamedRenderbufferStorageMultisample");
2753 _mesa_NamedRenderbufferStorageMultisampleAdvancedAMD(
2754 GLuint renderbuffer
, GLsizei samples
, GLsizei storageSamples
,
2755 GLenum internalformat
, GLsizei width
, GLsizei height
)
2757 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2758 samples
, storageSamples
,
2759 "glNamedRenderbufferStorageMultisampleAdvancedAMD");
2764 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2765 struct gl_renderbuffer
*rb
, GLenum pname
,
2766 GLint
*params
, const char *func
)
2768 /* No need to flush here since we're just quering state which is
2769 * not effected by rendering.
2773 case GL_RENDERBUFFER_WIDTH_EXT
:
2774 *params
= rb
->Width
;
2776 case GL_RENDERBUFFER_HEIGHT_EXT
:
2777 *params
= rb
->Height
;
2779 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2780 *params
= rb
->InternalFormat
;
2782 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2783 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2784 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2785 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2786 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2787 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2788 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2790 case GL_RENDERBUFFER_SAMPLES
:
2791 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2792 || _mesa_is_gles3(ctx
)) {
2793 *params
= rb
->NumSamples
;
2797 case GL_RENDERBUFFER_STORAGE_SAMPLES_AMD
:
2798 if (ctx
->Extensions
.AMD_framebuffer_multisample_advanced
) {
2799 *params
= rb
->NumStorageSamples
;
2805 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2806 _mesa_enum_to_string(pname
));
2811 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2813 GET_CURRENT_CONTEXT(ctx
);
2815 if (target
!= GL_RENDERBUFFER_EXT
) {
2816 _mesa_error(ctx
, GL_INVALID_ENUM
,
2817 "glGetRenderbufferParameterivEXT(target)");
2821 if (!ctx
->CurrentRenderbuffer
) {
2822 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2823 "(no renderbuffer bound)");
2827 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2828 params
, "glGetRenderbufferParameteriv");
2833 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2836 GET_CURRENT_CONTEXT(ctx
);
2838 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2839 if (!rb
|| rb
== &DummyRenderbuffer
) {
2840 /* ID was reserved, but no real renderbuffer object made yet */
2841 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2842 "(invalid renderbuffer %i)", renderbuffer
);
2846 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2847 "glGetNamedRenderbufferParameteriv");
2852 _mesa_GetNamedRenderbufferParameterivEXT(GLuint renderbuffer
, GLenum pname
,
2855 GET_CURRENT_CONTEXT(ctx
);
2857 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2858 if (!rb
|| rb
== &DummyRenderbuffer
) {
2859 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
2860 rb
= allocate_renderbuffer_locked(ctx
, renderbuffer
, "glGetNamedRenderbufferParameterivEXT");
2861 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
2864 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2865 "glGetNamedRenderbufferParameterivEXT");
2869 GLboolean GLAPIENTRY
2870 _mesa_IsFramebuffer(GLuint framebuffer
)
2872 GET_CURRENT_CONTEXT(ctx
);
2873 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2875 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2876 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2884 * Check if any of the attachments of the given framebuffer are textures
2885 * (render to texture). Call ctx->Driver.RenderTexture() for such
2889 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2892 assert(ctx
->Driver
.RenderTexture
);
2894 if (_mesa_is_winsys_fbo(fb
))
2895 return; /* can't render to texture with winsys framebuffers */
2897 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2898 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2899 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2900 && driver_RenderTexture_is_safe(att
)) {
2901 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2908 * Examine all the framebuffer's attachments to see if any are textures.
2909 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2910 * notify the device driver that the texture image may have changed.
2913 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2915 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2916 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2919 if (ctx
->Driver
.FinishRenderTexture
) {
2921 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2922 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2923 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2924 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2925 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2933 bind_framebuffer(GLenum target
, GLuint framebuffer
)
2935 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2936 GLboolean bindReadBuf
, bindDrawBuf
;
2937 GET_CURRENT_CONTEXT(ctx
);
2940 case GL_DRAW_FRAMEBUFFER_EXT
:
2941 bindDrawBuf
= GL_TRUE
;
2942 bindReadBuf
= GL_FALSE
;
2944 case GL_READ_FRAMEBUFFER_EXT
:
2945 bindDrawBuf
= GL_FALSE
;
2946 bindReadBuf
= GL_TRUE
;
2948 case GL_FRAMEBUFFER_EXT
:
2949 bindDrawBuf
= GL_TRUE
;
2950 bindReadBuf
= GL_TRUE
;
2953 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2958 /* Binding a user-created framebuffer object */
2959 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2960 if (newDrawFb
== &DummyFramebuffer
) {
2961 /* ID was reserved, but no real framebuffer object made yet */
2964 else if (!newDrawFb
&& ctx
->API
== API_OPENGL_CORE
) {
2965 /* All FBO IDs must be Gen'd */
2966 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2967 "glBindFramebuffer(non-gen name)");
2972 /* create new framebuffer object */
2973 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2975 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2978 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2980 newReadFb
= newDrawFb
;
2983 /* Binding the window system framebuffer (which was originally set
2984 * with MakeCurrent).
2986 newDrawFb
= ctx
->WinSysDrawBuffer
;
2987 newReadFb
= ctx
->WinSysReadBuffer
;
2990 _mesa_bind_framebuffers(ctx
,
2991 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2992 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2996 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2997 struct gl_framebuffer
*newDrawFb
,
2998 struct gl_framebuffer
*newReadFb
)
3000 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
3001 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
3002 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
3003 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
3006 assert(newDrawFb
!= &DummyFramebuffer
);
3009 * OK, now bind the new Draw/Read framebuffers, if they're changing.
3011 * We also check if we're beginning and/or ending render-to-texture.
3012 * When a framebuffer with texture attachments is unbound, call
3013 * ctx->Driver.FinishRenderTexture().
3014 * When a framebuffer with texture attachments is bound, call
3015 * ctx->Driver.RenderTexture().
3017 * Note that if the ReadBuffer has texture attachments we don't consider
3018 * that a render-to-texture case.
3021 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3023 /* check if old readbuffer was render-to-texture */
3024 check_end_texture_render(ctx
, oldReadFb
);
3026 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
3030 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3031 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
3033 /* check if old framebuffer had any texture attachments */
3035 check_end_texture_render(ctx
, oldDrawFb
);
3037 /* check if newly bound framebuffer has any texture attachments */
3038 check_begin_texture_render(ctx
, newDrawFb
);
3040 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
3041 _mesa_update_allow_draw_out_of_order(ctx
);
3044 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
3045 /* The few classic drivers that actually hook this function really only
3046 * want to know if the draw framebuffer changed.
3048 ctx
->Driver
.BindFramebuffer(ctx
,
3049 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
3050 newDrawFb
, newReadFb
);
3055 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
3057 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
3058 * point, but they allow the use of user-generated names.
3060 bind_framebuffer(target
, framebuffer
);
3065 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
3067 bind_framebuffer(target
, framebuffer
);
3072 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
3075 GET_CURRENT_CONTEXT(ctx
);
3078 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
3082 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3084 for (i
= 0; i
< n
; i
++) {
3085 if (framebuffers
[i
] > 0) {
3086 struct gl_framebuffer
*fb
;
3087 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
3089 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
3091 /* check if deleting currently bound framebuffer object */
3092 if (fb
== ctx
->DrawBuffer
) {
3094 assert(fb
->RefCount
>= 2);
3095 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
3097 if (fb
== ctx
->ReadBuffer
) {
3099 assert(fb
->RefCount
>= 2);
3100 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
3103 /* remove from hash table immediately, to free the ID */
3104 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
3106 if (fb
!= &DummyFramebuffer
) {
3107 /* But the object will not be freed until it's no longer
3108 * bound in any context.
3110 _mesa_reference_framebuffer(&fb
, NULL
);
3119 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
3120 * It is not exposed to the rest of Mesa to encourage the use of
3121 * nameless buffers in driver internals.
3124 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
3126 GET_CURRENT_CONTEXT(ctx
);
3129 struct gl_framebuffer
*fb
;
3131 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
3134 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
3141 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
3143 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
3145 for (i
= 0; i
< n
; i
++) {
3146 GLuint name
= first
+ i
;
3147 framebuffers
[i
] = name
;
3150 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
3152 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
3153 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
3158 fb
= &DummyFramebuffer
;
3160 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
3163 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
3168 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
3170 create_framebuffers(n
, framebuffers
, false);
3175 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
3177 create_framebuffers(n
, framebuffers
, true);
3182 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
3183 struct gl_framebuffer
*buffer
)
3185 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
3187 if (_mesa_is_winsys_fbo(buffer
)) {
3188 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
3189 if (buffer
!= &IncompleteFramebuffer
) {
3190 return GL_FRAMEBUFFER_COMPLETE_EXT
;
3192 return GL_FRAMEBUFFER_UNDEFINED
;
3196 /* No need to flush here */
3198 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
3199 _mesa_test_framebuffer_completeness(ctx
, buffer
);
3202 return buffer
->_Status
;
3207 _mesa_CheckFramebufferStatus_no_error(GLenum target
)
3209 GET_CURRENT_CONTEXT(ctx
);
3211 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3212 return _mesa_check_framebuffer_status(ctx
, fb
);
3217 _mesa_CheckFramebufferStatus(GLenum target
)
3219 struct gl_framebuffer
*fb
;
3220 GET_CURRENT_CONTEXT(ctx
);
3222 if (MESA_VERBOSE
& VERBOSE_API
)
3223 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
3224 _mesa_enum_to_string(target
));
3226 fb
= get_framebuffer_target(ctx
, target
);
3228 _mesa_error(ctx
, GL_INVALID_ENUM
,
3229 "glCheckFramebufferStatus(invalid target %s)",
3230 _mesa_enum_to_string(target
));
3234 return _mesa_check_framebuffer_status(ctx
, fb
);
3239 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
3241 struct gl_framebuffer
*fb
;
3242 GET_CURRENT_CONTEXT(ctx
);
3244 /* Validate the target (for conformance's sake) and grab a reference to the
3245 * default framebuffer in case framebuffer = 0.
3246 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
3247 * (30.10.2014, PDF page 336) says:
3248 * "If framebuffer is zero, then the status of the default read or
3249 * draw framebuffer (as determined by target) is returned."
3252 case GL_DRAW_FRAMEBUFFER
:
3253 case GL_FRAMEBUFFER
:
3254 fb
= ctx
->WinSysDrawBuffer
;
3256 case GL_READ_FRAMEBUFFER
:
3257 fb
= ctx
->WinSysReadBuffer
;
3260 _mesa_error(ctx
, GL_INVALID_ENUM
,
3261 "glCheckNamedFramebufferStatus(invalid target %s)",
3262 _mesa_enum_to_string(target
));
3267 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3268 "glCheckNamedFramebufferStatus");
3273 return _mesa_check_framebuffer_status(ctx
, fb
);
3278 _mesa_CheckNamedFramebufferStatusEXT(GLuint framebuffer
, GLenum target
)
3280 struct gl_framebuffer
*fb
;
3281 GET_CURRENT_CONTEXT(ctx
);
3284 case GL_DRAW_FRAMEBUFFER
:
3285 case GL_FRAMEBUFFER
:
3286 case GL_READ_FRAMEBUFFER
:
3289 _mesa_error(ctx
, GL_INVALID_ENUM
,
3290 "glCheckNamedFramebufferStatusEXT(invalid target %s)",
3291 _mesa_enum_to_string(target
));
3295 if (framebuffer
== 0) {
3296 return _mesa_CheckNamedFramebufferStatus(0, target
);
3299 fb
= _mesa_lookup_framebuffer_dsa(ctx
, framebuffer
,
3300 "glCheckNamedFramebufferStatusEXT");
3304 return _mesa_check_framebuffer_status(ctx
, fb
);
3309 * Replicate the src attachment point. Used by framebuffer_texture() when
3310 * the same texture is attached at GL_DEPTH_ATTACHMENT and
3311 * GL_STENCIL_ATTACHMENT.
3314 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
3315 gl_buffer_index dst
,
3316 gl_buffer_index src
)
3318 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
3319 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
3321 assert(src_att
->Texture
!= NULL
);
3322 assert(src_att
->Renderbuffer
!= NULL
);
3324 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
3325 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
3326 dst_att
->Type
= src_att
->Type
;
3327 dst_att
->Complete
= src_att
->Complete
;
3328 dst_att
->TextureLevel
= src_att
->TextureLevel
;
3329 dst_att
->CubeMapFace
= src_att
->CubeMapFace
;
3330 dst_att
->Zoffset
= src_att
->Zoffset
;
3331 dst_att
->Layered
= src_att
->Layered
;
3335 static struct gl_texture_object
*
3336 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
)
3341 return _mesa_lookup_texture(ctx
, texture
);
3346 * Common code called by gl*FramebufferTexture*() to retrieve the correct
3347 * texture object pointer.
3349 * \param texObj where the pointer to the texture object is returned. Note
3350 * that a successful call may return texObj = NULL.
3352 * \return true if no errors, false if errors
3355 get_texture_for_framebuffer_err(struct gl_context
*ctx
, GLuint texture
,
3356 bool layered
, const char *caller
,
3357 struct gl_texture_object
**texObj
)
3359 *texObj
= NULL
; /* This will get returned if texture = 0. */
3364 *texObj
= _mesa_lookup_texture(ctx
, texture
);
3365 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
3366 /* Can't render to a non-existent texture object.
3368 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
3369 * Managing Framebuffer Objects specifies a different error
3370 * depending upon the calling function (PDF pages 325-328).
3371 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
3372 * value, while the other commands throw invalid operation (where
3373 * layered = GL_FALSE).
3375 const GLenum error
= layered
? GL_INVALID_VALUE
:
3376 GL_INVALID_OPERATION
;
3377 _mesa_error(ctx
, error
,
3378 "%s(non-existent texture %u)", caller
, texture
);
3387 * Common code called by gl*FramebufferTexture() to verify the texture target
3388 * and decide whether or not the attachment should truly be considered
3391 * \param layered true if attachment should be considered layered, false if
3394 * \return true if no errors, false if errors
3397 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
3398 const char *caller
, GLboolean
*layered
)
3404 case GL_TEXTURE_1D_ARRAY_EXT
:
3405 case GL_TEXTURE_2D_ARRAY_EXT
:
3406 case GL_TEXTURE_CUBE_MAP
:
3407 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3408 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3412 case GL_TEXTURE_RECTANGLE
:
3413 case GL_TEXTURE_2D_MULTISAMPLE
:
3414 /* These texture types are valid to pass to
3415 * glFramebufferTexture(), but since they aren't layered, it
3416 * is equivalent to calling glFramebufferTexture{1D,2D}().
3418 *layered
= GL_FALSE
;
3422 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3423 "%s(invalid texture target %s)", caller
,
3424 _mesa_enum_to_string(target
));
3430 * Common code called by gl*FramebufferTextureLayer() to verify the texture
3433 * \return true if no errors, false if errors
3436 check_texture_target(struct gl_context
*ctx
, GLenum target
,
3439 /* We're being called by glFramebufferTextureLayer().
3440 * The only legal texture types for that function are 3D,
3441 * cube-map, and 1D/2D/cube-map array textures.
3443 * We don't need to check for GL_ARB_texture_cube_map_array because the
3444 * application wouldn't have been able to create a texture with a
3445 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
3449 case GL_TEXTURE_1D_ARRAY
:
3450 case GL_TEXTURE_2D_ARRAY
:
3451 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3452 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3454 case GL_TEXTURE_CUBE_MAP
:
3455 /* GL_TEXTURE_CUBE_MAP is only allowed by OpenGL 4.5 here, which
3456 * includes the DSA API.
3458 * Because DSA is only enabled for GL 3.1+ and this can be called
3459 * from _mesa_FramebufferTextureLayer in compatibility profile,
3460 * we need to check the version.
3462 return _mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 31;
3465 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3466 "%s(invalid texture target %s)", caller
,
3467 _mesa_enum_to_string(target
));
3473 * Common code called by glFramebufferTexture*D() to verify the texture
3476 * \return true if no errors, false if errors
3479 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
3480 GLenum textarget
, const char *caller
)
3484 switch (textarget
) {
3488 case GL_TEXTURE_1D_ARRAY
:
3489 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3494 case GL_TEXTURE_2D_ARRAY
:
3495 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3496 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3498 case GL_TEXTURE_2D_MULTISAMPLE
:
3499 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3501 !ctx
->Extensions
.ARB_texture_multisample
||
3502 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3504 case GL_TEXTURE_RECTANGLE
:
3505 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3506 !ctx
->Extensions
.NV_texture_rectangle
;
3508 case GL_TEXTURE_CUBE_MAP
:
3509 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3512 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3513 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3514 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3515 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3516 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3517 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3518 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3524 _mesa_error(ctx
, GL_INVALID_ENUM
,
3525 "%s(unknown textarget 0x%x)", caller
, textarget
);
3530 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3531 "%s(invalid textarget %s)",
3532 caller
, _mesa_enum_to_string(textarget
));
3536 /* Make sure textarget is consistent with the texture's type */
3537 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3538 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3541 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3542 "%s(mismatched texture target)", caller
);
3551 * Common code called by gl*FramebufferTextureLayer() and
3552 * glFramebufferTexture3D() to validate the layer.
3554 * \return true if no errors, false if errors
3557 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3560 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3563 * "An INVALID_VALUE error is generated if texture is non-zero
3564 * and layer is negative."
3567 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(layer %d < 0)", caller
, layer
);
3571 if (target
== GL_TEXTURE_3D
) {
3572 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3573 if (layer
>= maxSize
) {
3574 _mesa_error(ctx
, GL_INVALID_VALUE
,
3575 "%s(invalid layer %u)", caller
, layer
);
3579 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3580 (target
== GL_TEXTURE_2D_ARRAY
) ||
3581 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3582 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3583 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3584 _mesa_error(ctx
, GL_INVALID_VALUE
,
3585 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3590 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3592 _mesa_error(ctx
, GL_INVALID_VALUE
,
3593 "%s(layer %u >= 6)", caller
, layer
);
3603 * Common code called by all gl*FramebufferTexture*() entry points to verify
3606 * \return true if no errors, false if errors
3609 check_level(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
3610 GLenum target
, GLint level
, const char *caller
)
3612 /* Section 9.2.8 of the OpenGL 4.6 specification says:
3614 * "If texture refers to an immutable-format texture, level must be
3615 * greater than or equal to zero and smaller than the value of
3616 * TEXTURE_VIEW_NUM_LEVELS for texture."
3618 const int max_levels
= texObj
->Immutable
? texObj
->ImmutableLevels
:
3619 _mesa_max_texture_levels(ctx
, target
);
3621 if (level
< 0 || level
>= max_levels
) {
3622 _mesa_error(ctx
, GL_INVALID_VALUE
,
3623 "%s(invalid level %d)", caller
, level
);
3631 struct gl_renderbuffer_attachment
*
3632 _mesa_get_and_validate_attachment(struct gl_context
*ctx
,
3633 struct gl_framebuffer
*fb
,
3634 GLenum attachment
, const char *caller
)
3636 /* The window-system framebuffer object is immutable */
3637 if (_mesa_is_winsys_fbo(fb
)) {
3638 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3643 /* Not a hash lookup, so we can afford to get the attachment here. */
3644 bool is_color_attachment
;
3645 struct gl_renderbuffer_attachment
*att
=
3646 get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3648 if (is_color_attachment
) {
3649 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3650 "%s(invalid color attachment %s)", caller
,
3651 _mesa_enum_to_string(attachment
));
3653 _mesa_error(ctx
, GL_INVALID_ENUM
,
3654 "%s(invalid attachment %s)", caller
,
3655 _mesa_enum_to_string(attachment
));
3665 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3667 struct gl_renderbuffer_attachment
*att
,
3668 struct gl_texture_object
*texObj
, GLenum textarget
,
3669 GLint level
, GLsizei samples
,
3670 GLuint layer
, GLboolean layered
)
3672 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3674 simple_mtx_lock(&fb
->Mutex
);
3676 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3677 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3678 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3679 _mesa_tex_target_to_face(textarget
) ==
3680 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3681 samples
== fb
->Attachment
[BUFFER_STENCIL
].NumSamples
&&
3682 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3683 /* The texture object is already attached to the stencil attachment
3684 * point. Don't create a new renderbuffer; just reuse the stencil
3685 * attachment's. This is required to prevent a GL error in
3686 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3688 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3690 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3691 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3692 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3693 _mesa_tex_target_to_face(textarget
) ==
3694 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3695 samples
== fb
->Attachment
[BUFFER_DEPTH
].NumSamples
&&
3696 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3697 /* As above, but with depth and stencil transposed. */
3698 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3701 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3702 level
, samples
, layer
, layered
);
3704 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3705 /* Above we created a new renderbuffer and attached it to the
3706 * depth attachment point. Now attach it to the stencil attachment
3709 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3710 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3715 /* Set the render-to-texture flag. We'll check this flag in
3716 * glTexImage() and friends to determine if we need to revalidate
3717 * any FBOs that might be rendering into this texture.
3718 * This flag never gets cleared since it's non-trivial to determine
3719 * when all FBOs might be done rendering to this texture. That's OK
3720 * though since it's uncommon to render to a texture then repeatedly
3721 * call glTexImage() to change images in the texture.
3723 texObj
->_RenderToTexture
= GL_TRUE
;
3726 remove_attachment(ctx
, att
);
3727 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3728 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3729 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3733 invalidate_framebuffer(fb
);
3735 simple_mtx_unlock(&fb
->Mutex
);
3740 framebuffer_texture_with_dims_no_error(GLenum target
, GLenum attachment
,
3741 GLenum textarget
, GLuint texture
,
3742 GLint level
, GLint layer
)
3744 GET_CURRENT_CONTEXT(ctx
);
3746 /* Get the framebuffer object */
3747 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3749 /* Get the texture object */
3750 struct gl_texture_object
*texObj
=
3751 get_texture_for_framebuffer(ctx
, texture
);
3753 struct gl_renderbuffer_attachment
*att
=
3754 get_attachment(ctx
, fb
, attachment
, NULL
);
3756 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3757 level
, 0, layer
, GL_FALSE
);
3762 framebuffer_texture_with_dims(int dims
, GLenum target
, GLuint framebuffer
,
3763 GLenum attachment
, GLenum textarget
,
3764 GLuint texture
, GLint level
, GLsizei samples
,
3765 GLint layer
, const char *caller
, bool dsa
)
3767 GET_CURRENT_CONTEXT(ctx
);
3768 struct gl_framebuffer
*fb
;
3769 struct gl_texture_object
*texObj
;
3771 /* Get the framebuffer object */
3773 fb
= _mesa_lookup_framebuffer_dsa(ctx
, framebuffer
, caller
);
3775 fb
= get_framebuffer_target(ctx
, target
);
3778 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3779 _mesa_enum_to_string(target
));
3783 /* Get the texture object */
3784 if (!get_texture_for_framebuffer_err(ctx
, texture
, false, caller
, &texObj
))
3788 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3791 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3794 if (!check_level(ctx
, texObj
, textarget
, level
, caller
))
3798 struct gl_renderbuffer_attachment
*att
=
3799 _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, caller
);
3803 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3804 level
, samples
, layer
, GL_FALSE
);
3809 _mesa_FramebufferTexture1D_no_error(GLenum target
, GLenum attachment
,
3810 GLenum textarget
, GLuint texture
,
3813 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3819 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3820 GLenum textarget
, GLuint texture
, GLint level
)
3822 framebuffer_texture_with_dims(1, target
, 0, attachment
, textarget
, texture
,
3823 level
, 0, 0, "glFramebufferTexture1D", false);
3828 _mesa_FramebufferTexture2D_no_error(GLenum target
, GLenum attachment
,
3829 GLenum textarget
, GLuint texture
,
3832 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3838 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3839 GLenum textarget
, GLuint texture
, GLint level
)
3841 framebuffer_texture_with_dims(2, target
, 0, attachment
, textarget
, texture
,
3842 level
, 0, 0, "glFramebufferTexture2D", false);
3847 _mesa_FramebufferTexture2DMultisampleEXT(GLenum target
, GLenum attachment
,
3848 GLenum textarget
, GLuint texture
,
3849 GLint level
, GLsizei samples
)
3851 framebuffer_texture_with_dims(2, target
, 0, attachment
, textarget
, texture
,
3853 "glFramebufferTexture2DMultisampleEXT",
3859 _mesa_FramebufferTexture3D_no_error(GLenum target
, GLenum attachment
,
3860 GLenum textarget
, GLuint texture
,
3861 GLint level
, GLint layer
)
3863 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3864 texture
, level
, layer
);
3869 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3870 GLenum textarget
, GLuint texture
,
3871 GLint level
, GLint layer
)
3873 framebuffer_texture_with_dims(3, target
, 0, attachment
, textarget
, texture
,
3874 level
, 0, layer
, "glFramebufferTexture3D", false);
3878 static ALWAYS_INLINE
void
3879 frame_buffer_texture(GLuint framebuffer
, GLenum target
,
3880 GLenum attachment
, GLuint texture
,
3881 GLint level
, GLint layer
, const char *func
,
3882 bool dsa
, bool no_error
, bool check_layered
)
3884 GET_CURRENT_CONTEXT(ctx
);
3885 GLboolean layered
= GL_FALSE
;
3887 if (!no_error
&& check_layered
) {
3888 if (!_mesa_has_geometry_shaders(ctx
)) {
3889 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3890 "unsupported function (%s) called", func
);
3895 /* Get the framebuffer object */
3896 struct gl_framebuffer
*fb
;
3899 fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3901 fb
= get_framebuffer_target(ctx
, target
);
3905 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3909 fb
= get_framebuffer_target(ctx
, target
);
3911 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)",
3912 func
, _mesa_enum_to_string(target
));
3918 /* Get the texture object and framebuffer attachment*/
3919 struct gl_renderbuffer_attachment
*att
;
3920 struct gl_texture_object
*texObj
;
3922 texObj
= get_texture_for_framebuffer(ctx
, texture
);
3923 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
3925 if (!get_texture_for_framebuffer_err(ctx
, texture
, check_layered
, func
,
3929 att
= _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, func
);
3934 GLenum textarget
= 0;
3936 if (check_layered
) {
3937 /* We do this regardless of no_error because this sets layered */
3938 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3944 if (!check_layered
) {
3945 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3948 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3952 if (!check_level(ctx
, texObj
, texObj
->Target
, level
, func
))
3956 if (!check_layered
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3957 assert(layer
>= 0 && layer
< 6);
3958 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3963 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3964 level
, 0, layer
, layered
);
3968 _mesa_FramebufferTextureLayer_no_error(GLenum target
, GLenum attachment
,
3969 GLuint texture
, GLint level
,
3972 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3973 "glFramebufferTextureLayer", false, true, false);
3978 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3979 GLuint texture
, GLint level
, GLint layer
)
3981 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3982 "glFramebufferTextureLayer", false, false, false);
3987 _mesa_NamedFramebufferTextureLayer_no_error(GLuint framebuffer
,
3989 GLuint texture
, GLint level
,
3992 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3993 "glNamedFramebufferTextureLayer", true, true, false);
3998 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3999 GLuint texture
, GLint level
, GLint layer
)
4001 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
4002 "glNamedFramebufferTextureLayer", true, false, false);
4007 _mesa_FramebufferTexture_no_error(GLenum target
, GLenum attachment
,
4008 GLuint texture
, GLint level
)
4010 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
4011 "glFramebufferTexture", false, true, true);
4016 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
4017 GLuint texture
, GLint level
)
4019 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
4020 "glFramebufferTexture", false, false, true);
4024 _mesa_NamedFramebufferTexture_no_error(GLuint framebuffer
, GLenum attachment
,
4025 GLuint texture
, GLint level
)
4027 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
4028 "glNamedFramebufferTexture", true, true, true);
4033 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
4034 GLuint texture
, GLint level
)
4036 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
4037 "glNamedFramebufferTexture", true, false, true);
4042 _mesa_NamedFramebufferTexture1DEXT(GLuint framebuffer
, GLenum attachment
,
4043 GLenum textarget
, GLuint texture
, GLint level
)
4045 framebuffer_texture_with_dims(1, GL_FRAMEBUFFER
, framebuffer
, attachment
,
4046 textarget
, texture
, level
, 0, 0,
4047 "glNamedFramebufferTexture1DEXT", true);
4052 _mesa_NamedFramebufferTexture2DEXT(GLuint framebuffer
, GLenum attachment
,
4053 GLenum textarget
, GLuint texture
, GLint level
)
4055 framebuffer_texture_with_dims(2, GL_FRAMEBUFFER
, framebuffer
, attachment
,
4056 textarget
, texture
, level
, 0, 0,
4057 "glNamedFramebufferTexture2DEXT", true);
4062 _mesa_NamedFramebufferTexture3DEXT(GLuint framebuffer
, GLenum attachment
,
4063 GLenum textarget
, GLuint texture
,
4064 GLint level
, GLint zoffset
)
4066 framebuffer_texture_with_dims(3, GL_FRAMEBUFFER
, framebuffer
, attachment
,
4067 textarget
, texture
, level
, 0, zoffset
,
4068 "glNamedFramebufferTexture3DEXT", true);
4073 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
4074 struct gl_framebuffer
*fb
,
4076 struct gl_renderbuffer
*rb
)
4078 assert(!_mesa_is_winsys_fbo(fb
));
4080 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
4082 assert(ctx
->Driver
.FramebufferRenderbuffer
);
4083 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
4085 /* Some subsequent GL commands may depend on the framebuffer's visual
4086 * after the binding is updated. Update visual info now.
4088 _mesa_update_framebuffer_visual(ctx
, fb
);
4091 static ALWAYS_INLINE
void
4092 framebuffer_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
4093 GLenum attachment
, GLenum renderbuffertarget
,
4094 GLuint renderbuffer
, const char *func
, bool no_error
)
4096 struct gl_renderbuffer_attachment
*att
;
4097 struct gl_renderbuffer
*rb
;
4098 bool is_color_attachment
;
4100 if (!no_error
&& renderbuffertarget
!= GL_RENDERBUFFER
) {
4101 _mesa_error(ctx
, GL_INVALID_ENUM
,
4102 "%s(renderbuffertarget is not GL_RENDERBUFFER)", func
);
4108 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
, func
);
4112 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
4115 /* remove renderbuffer attachment */
4120 if (_mesa_is_winsys_fbo(fb
)) {
4121 /* Can't attach new renderbuffers to a window system framebuffer */
4122 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4123 "%s(window-system framebuffer)", func
);
4127 att
= get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
4130 * From OpenGL 4.5 spec, section 9.2.7 "Attaching Renderbuffer Images
4131 * to a Framebuffer":
4133 * "An INVALID_OPERATION error is generated if attachment is
4134 * COLOR_- ATTACHMENTm where m is greater than or equal to the
4135 * value of MAX_COLOR_- ATTACHMENTS ."
4137 * If we are at this point, is because the attachment is not valid, so
4138 * if is_color_attachment is true, is because of the previous reason.
4140 if (is_color_attachment
) {
4141 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4142 "%s(invalid color attachment %s)", func
,
4143 _mesa_enum_to_string(attachment
));
4145 _mesa_error(ctx
, GL_INVALID_ENUM
,
4146 "%s(invalid attachment %s)", func
,
4147 _mesa_enum_to_string(attachment
));
4153 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
4154 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
4155 /* make sure the renderbuffer is a depth/stencil format */
4156 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
4157 if (baseFormat
!= GL_DEPTH_STENCIL
) {
4158 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4159 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
4165 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
4169 framebuffer_renderbuffer_error(struct gl_context
*ctx
,
4170 struct gl_framebuffer
*fb
, GLenum attachment
,
4171 GLenum renderbuffertarget
,
4172 GLuint renderbuffer
, const char *func
)
4174 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
4175 renderbuffer
, func
, false);
4179 framebuffer_renderbuffer_no_error(struct gl_context
*ctx
,
4180 struct gl_framebuffer
*fb
, GLenum attachment
,
4181 GLenum renderbuffertarget
,
4182 GLuint renderbuffer
, const char *func
)
4184 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
4185 renderbuffer
, func
, true);
4189 _mesa_FramebufferRenderbuffer_no_error(GLenum target
, GLenum attachment
,
4190 GLenum renderbuffertarget
,
4191 GLuint renderbuffer
)
4193 GET_CURRENT_CONTEXT(ctx
);
4195 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
4196 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
4197 renderbuffer
, "glFramebufferRenderbuffer");
4201 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
4202 GLenum renderbuffertarget
,
4203 GLuint renderbuffer
)
4205 struct gl_framebuffer
*fb
;
4206 GET_CURRENT_CONTEXT(ctx
);
4208 fb
= get_framebuffer_target(ctx
, target
);
4210 _mesa_error(ctx
, GL_INVALID_ENUM
,
4211 "glFramebufferRenderbuffer(invalid target %s)",
4212 _mesa_enum_to_string(target
));
4216 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
4217 renderbuffer
, "glFramebufferRenderbuffer");
4221 _mesa_NamedFramebufferRenderbuffer_no_error(GLuint framebuffer
,
4223 GLenum renderbuffertarget
,
4224 GLuint renderbuffer
)
4226 GET_CURRENT_CONTEXT(ctx
);
4228 struct gl_framebuffer
*fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
4229 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
4231 "glNamedFramebufferRenderbuffer");
4235 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
4236 GLenum renderbuffertarget
,
4237 GLuint renderbuffer
)
4239 struct gl_framebuffer
*fb
;
4240 GET_CURRENT_CONTEXT(ctx
);
4242 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4243 "glNamedFramebufferRenderbuffer");
4247 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
4249 "glNamedFramebufferRenderbuffer");
4254 _mesa_NamedFramebufferRenderbufferEXT(GLuint framebuffer
, GLenum attachment
,
4255 GLenum renderbuffertarget
,
4256 GLuint renderbuffer
)
4258 struct gl_framebuffer
*fb
;
4259 GET_CURRENT_CONTEXT(ctx
);
4261 fb
= _mesa_lookup_framebuffer_dsa(ctx
, framebuffer
,
4262 "glNamedFramebufferRenderbufferEXT");
4266 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
4268 "glNamedFramebufferRenderbuffer");
4273 get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
4274 struct gl_framebuffer
*buffer
,
4275 GLenum attachment
, GLenum pname
,
4276 GLint
*params
, const char *caller
)
4278 const struct gl_renderbuffer_attachment
*att
;
4279 bool is_color_attachment
= false;
4282 /* The error code for an attachment type of GL_NONE differs between APIs.
4284 * From the ES 2.0.25 specification, page 127:
4285 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
4286 * querying any other pname will generate INVALID_ENUM."
4288 * From the OpenGL 3.0 specification, page 337, or identically,
4289 * the OpenGL ES 3.0.4 specification, page 240:
4291 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
4292 * framebuffer is bound to target. In this case querying pname
4293 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
4294 * queries will generate an INVALID_OPERATION error."
4296 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
4297 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
4299 if (_mesa_is_winsys_fbo(buffer
)) {
4300 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
4303 * "If the framebuffer currently bound to target is zero, then
4304 * INVALID_OPERATION is generated."
4306 * The EXT_framebuffer_object spec has the same wording, and the
4307 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
4310 if ((!_mesa_is_desktop_gl(ctx
) ||
4311 !ctx
->Extensions
.ARB_framebuffer_object
)
4312 && !_mesa_is_gles3(ctx
)) {
4313 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4314 "%s(window-system framebuffer)", caller
);
4318 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
4319 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
4320 _mesa_error(ctx
, GL_INVALID_ENUM
,
4321 "%s(invalid attachment %s)", caller
,
4322 _mesa_enum_to_string(attachment
));
4326 /* The specs are not clear about how to handle
4327 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
4328 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
4331 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
4332 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
4334 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
4335 _mesa_error(ctx
, GL_INVALID_ENUM
,
4336 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
4337 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
4338 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
4342 /* the default / window-system FBO */
4343 att
= get_fb0_attachment(ctx
, buffer
, attachment
);
4346 /* user-created framebuffer FBO */
4347 att
= get_attachment(ctx
, buffer
, attachment
, &is_color_attachment
);
4352 * From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries":
4354 * "An INVALID_OPERATION error is generated if a framebuffer object
4355 * is bound to target and attachment is COLOR_ATTACHMENTm where m is
4356 * greater than or equal to the value of MAX_COLOR_ATTACHMENTS."
4358 * If we are at this point, is because the attachment is not valid, so
4359 * if is_color_attachment is true, is because of the previous reason.
4361 if (is_color_attachment
) {
4362 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid color attachment %s)",
4363 caller
, _mesa_enum_to_string(attachment
));
4365 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
4366 _mesa_enum_to_string(attachment
));
4371 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
4372 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
4373 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
4374 /* This behavior is first specified in OpenGL 4.4 specification.
4376 * From the OpenGL 4.4 spec page 275:
4377 * "This query cannot be performed for a combined depth+stencil
4378 * attachment, since it does not have a single format."
4380 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4381 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
4382 " is invalid for depth+stencil attachment)", caller
);
4385 /* the depth and stencil attachments must point to the same buffer */
4386 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
, NULL
);
4387 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
, NULL
);
4388 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
4389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4390 "%s(DEPTH/STENCIL attachments differ)", caller
);
4395 /* No need to flush here */
4398 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
4399 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
4401 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
4402 * either no framebuffer is bound to target; or the default framebuffer
4403 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
4404 * stencil bits, respectively, is zero."
4406 * Note that we don't need explicit checks on DEPTH and STENCIL, because
4407 * on the case the spec is pointing, att->Type is already NONE, so we
4408 * just need to check att->Type.
4410 *params
= (_mesa_is_winsys_fbo(buffer
) && att
->Type
!= GL_NONE
) ?
4411 GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
4413 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
4414 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
4415 *params
= att
->Renderbuffer
->Name
;
4417 else if (att
->Type
== GL_TEXTURE
) {
4418 *params
= att
->Texture
->Name
;
4421 assert(att
->Type
== GL_NONE
);
4422 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
4425 goto invalid_pname_enum
;
4429 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
4430 if (att
->Type
== GL_TEXTURE
) {
4431 *params
= att
->TextureLevel
;
4433 else if (att
->Type
== GL_NONE
) {
4434 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4435 _mesa_enum_to_string(pname
));
4438 goto invalid_pname_enum
;
4441 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
4442 if (att
->Type
== GL_TEXTURE
) {
4443 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
4444 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
4450 else if (att
->Type
== GL_NONE
) {
4451 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4452 _mesa_enum_to_string(pname
));
4455 goto invalid_pname_enum
;
4458 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
4459 if (ctx
->API
== API_OPENGLES
) {
4460 goto invalid_pname_enum
;
4461 } else if (att
->Type
== GL_NONE
) {
4462 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4463 _mesa_enum_to_string(pname
));
4464 } else if (att
->Type
== GL_TEXTURE
) {
4465 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
4466 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
4467 *params
= att
->Zoffset
;
4474 goto invalid_pname_enum
;
4477 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
4478 if ((!_mesa_is_desktop_gl(ctx
) ||
4479 !ctx
->Extensions
.ARB_framebuffer_object
)
4480 && !_mesa_is_gles3(ctx
)) {
4481 goto invalid_pname_enum
;
4483 else if (att
->Type
== GL_NONE
) {
4484 if (_mesa_is_winsys_fbo(buffer
) &&
4485 (attachment
== GL_DEPTH
|| attachment
== GL_STENCIL
)) {
4486 *params
= GL_LINEAR
;
4488 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4489 _mesa_enum_to_string(pname
));
4493 if (ctx
->Extensions
.EXT_sRGB
) {
4494 *params
= (_mesa_is_format_srgb(att
->Renderbuffer
->Format
) ?
4495 GL_SRGB
: GL_LINEAR
);
4498 /* According to ARB_framebuffer_sRGB, we should return LINEAR
4499 * if the sRGB conversion is unsupported. */
4500 *params
= GL_LINEAR
;
4504 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
4505 if ((ctx
->API
!= API_OPENGL_COMPAT
||
4506 !ctx
->Extensions
.ARB_framebuffer_object
)
4507 && ctx
->API
!= API_OPENGL_CORE
4508 && !_mesa_is_gles3(ctx
)) {
4509 goto invalid_pname_enum
;
4511 else if (att
->Type
== GL_NONE
) {
4512 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4513 _mesa_enum_to_string(pname
));
4516 mesa_format format
= att
->Renderbuffer
->Format
;
4518 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
4521 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
4522 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
4523 * generate an INVALID_OPERATION error.
4525 if (_mesa_is_gles3(ctx
) &&
4526 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
4527 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4529 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
4530 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
4534 if (format
== MESA_FORMAT_S_UINT8
) {
4538 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
4539 /* depends on the attachment parameter */
4540 if (attachment
== GL_STENCIL_ATTACHMENT
) {
4548 *params
= _mesa_get_format_datatype(format
);
4552 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
4553 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
4554 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
4555 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
4556 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
4557 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
4558 if ((!_mesa_is_desktop_gl(ctx
) ||
4559 !ctx
->Extensions
.ARB_framebuffer_object
)
4560 && !_mesa_is_gles3(ctx
)) {
4561 goto invalid_pname_enum
;
4563 else if (att
->Texture
) {
4564 const struct gl_texture_image
*texImage
=
4565 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
4568 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
4569 texImage
->TexFormat
);
4575 else if (att
->Renderbuffer
) {
4576 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
4577 att
->Renderbuffer
->Format
);
4580 assert(att
->Type
== GL_NONE
);
4581 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4582 _mesa_enum_to_string(pname
));
4585 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
4586 if (!_mesa_has_geometry_shaders(ctx
)) {
4587 goto invalid_pname_enum
;
4588 } else if (att
->Type
== GL_TEXTURE
) {
4589 *params
= att
->Layered
;
4590 } else if (att
->Type
== GL_NONE
) {
4591 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4592 _mesa_enum_to_string(pname
));
4594 goto invalid_pname_enum
;
4597 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT
:
4598 if (!ctx
->Extensions
.EXT_multisampled_render_to_texture
) {
4599 goto invalid_pname_enum
;
4600 } else if (att
->Type
== GL_TEXTURE
) {
4601 *params
= att
->NumSamples
;
4602 } else if (att
->Type
== GL_NONE
) {
4603 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4604 _mesa_enum_to_string(pname
));
4606 goto invalid_pname_enum
;
4610 goto invalid_pname_enum
;
4616 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
4617 _mesa_enum_to_string(pname
));
4623 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
4624 GLenum pname
, GLint
*params
)
4626 GET_CURRENT_CONTEXT(ctx
);
4627 struct gl_framebuffer
*buffer
;
4629 buffer
= get_framebuffer_target(ctx
, target
);
4631 _mesa_error(ctx
, GL_INVALID_ENUM
,
4632 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
4633 _mesa_enum_to_string(target
));
4637 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4639 "glGetFramebufferAttachmentParameteriv");
4644 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
4646 GLenum pname
, GLint
*params
)
4648 GET_CURRENT_CONTEXT(ctx
);
4649 struct gl_framebuffer
*buffer
;
4652 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4653 "glGetNamedFramebufferAttachmentParameteriv");
4659 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
4660 * 4.5 core spec (30.10.2014, PDF page 314):
4661 * "If framebuffer is zero, then the default draw framebuffer is
4664 buffer
= ctx
->WinSysDrawBuffer
;
4667 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4669 "glGetNamedFramebufferAttachmentParameteriv");
4674 _mesa_GetNamedFramebufferAttachmentParameterivEXT(GLuint framebuffer
,
4676 GLenum pname
, GLint
*params
)
4678 GET_CURRENT_CONTEXT(ctx
);
4679 struct gl_framebuffer
*buffer
;
4682 buffer
= _mesa_lookup_framebuffer_dsa(ctx
, framebuffer
,
4683 "glGetNamedFramebufferAttachmentParameterivEXT");
4689 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
4690 * 4.5 core spec (30.10.2014, PDF page 314):
4691 * "If framebuffer is zero, then the default draw framebuffer is
4694 buffer
= ctx
->WinSysDrawBuffer
;
4697 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4699 "glGetNamedFramebufferAttachmentParameterivEXT");
4704 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
4707 GET_CURRENT_CONTEXT(ctx
);
4708 struct gl_framebuffer
*fb
= NULL
;
4710 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
4711 !ctx
->Extensions
.ARB_sample_locations
) {
4712 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4713 "glNamedFramebufferParameteri("
4714 "neither ARB_framebuffer_no_attachments nor "
4715 "ARB_sample_locations is available)");
4720 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4721 "glNamedFramebufferParameteri");
4723 fb
= ctx
->WinSysDrawBuffer
;
4727 framebuffer_parameteri(ctx
, fb
, pname
, param
,
4728 "glNamedFramebufferParameteriv");
4733 /* Helper function for ARB_framebuffer_no_attachments functions interacting with EXT_direct_state_access */
4734 static struct gl_framebuffer
*
4735 lookup_named_framebuffer_ext_dsa(struct gl_context
*ctx
, GLuint framebuffer
, const char* caller
)
4737 struct gl_framebuffer
*fb
= NULL
;
4740 /* The ARB_framebuffer_no_attachments spec says:
4742 * "The error INVALID_VALUE is generated if <framebuffer> is not
4743 * a name returned by GenFramebuffers. If a framebuffer object
4744 * named <framebuffer> does not yet exist, it will be created."
4746 * This is different from the EXT_direct_state_access spec which says:
4748 * "If the framebuffer object named by the framebuffer parameter has not
4749 * been previously bound or has been deleted since the last binding,
4750 * the GL first creates a new state vector in the same manner as when
4751 * BindFramebuffer creates a new framebuffer object"
4753 * So first we verify that the name exists.
4755 fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
4757 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(frameBuffer)", caller
);
4760 /* Then, make sure it's initialized */
4761 if (fb
== &DummyFramebuffer
) {
4762 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
4763 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, fb
);
4767 fb
= ctx
->WinSysDrawBuffer
;
4774 _mesa_NamedFramebufferParameteriEXT(GLuint framebuffer
, GLenum pname
,
4777 GET_CURRENT_CONTEXT(ctx
);
4778 struct gl_framebuffer
*fb
=
4779 lookup_named_framebuffer_ext_dsa(ctx
, framebuffer
,
4780 "glNamedFramebufferParameteriEXT");
4785 framebuffer_parameteri(ctx
, fb
, pname
, param
,
4786 "glNamedFramebufferParameteriEXT");
4791 _mesa_GetFramebufferParameterivEXT(GLuint framebuffer
, GLenum pname
,
4794 GET_CURRENT_CONTEXT(ctx
);
4795 struct gl_framebuffer
*fb
;
4798 fb
= _mesa_lookup_framebuffer_dsa(ctx
, framebuffer
,
4799 "glGetFramebufferParameterivEXT");
4801 fb
= ctx
->WinSysDrawBuffer
;
4804 /* The GL_EXT_direct_state_access says:
4806 * The pname parameter must be one of framebuffer dependent values
4807 * listed in either table 4.nnn (namely DRAW_BUFFER, READ_BUFFER,
4808 * or DRAW_BUFFER0 through DRAW_BUFFER15).
4810 if (pname
== GL_DRAW_BUFFER
) {
4811 *param
= fb
->ColorDrawBuffer
[0];
4814 else if (pname
== GL_READ_BUFFER
) {
4815 *param
= fb
->ColorReadBuffer
;
4817 else if (GL_DRAW_BUFFER0
<= pname
&& pname
<= GL_DRAW_BUFFER15
) {
4818 unsigned buffer
= pname
- GL_DRAW_BUFFER0
;
4819 if (buffer
< ARRAY_SIZE(fb
->ColorDrawBuffer
))
4820 *param
= fb
->ColorDrawBuffer
[buffer
];
4822 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetFramebufferParameterivEXT(pname)");
4825 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetFramebufferParameterivEXT(pname)");
4832 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
4835 GET_CURRENT_CONTEXT(ctx
);
4836 struct gl_framebuffer
*fb
;
4838 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4839 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4840 "glNamedFramebufferParameteriv("
4841 "neither ARB_framebuffer_no_attachments nor ARB_sample_locations"
4847 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4848 "glGetNamedFramebufferParameteriv");
4850 fb
= ctx
->WinSysDrawBuffer
;
4853 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4854 "glGetNamedFramebufferParameteriv");
4860 _mesa_GetNamedFramebufferParameterivEXT(GLuint framebuffer
, GLenum pname
,
4863 GET_CURRENT_CONTEXT(ctx
);
4864 struct gl_framebuffer
*fb
=
4865 lookup_named_framebuffer_ext_dsa(ctx
, framebuffer
,
4866 "glGetNamedFramebufferParameterivEXT");
4871 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4872 "glGetNamedFramebufferParameterivEXT");
4877 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4878 struct gl_framebuffer
*fb
,
4879 GLsizei numAttachments
,
4880 const GLenum
*attachments
, GLint x
, GLint y
,
4881 GLsizei width
, GLsizei height
, const char *name
)
4885 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4886 * Spec (2.2.2015, PDF page 522) says:
4887 * "An INVALID_VALUE error is generated if numAttachments, width, or
4888 * height is negative."
4890 if (numAttachments
< 0) {
4891 _mesa_error(ctx
, GL_INVALID_VALUE
,
4892 "%s(numAttachments < 0)", name
);
4897 _mesa_error(ctx
, GL_INVALID_VALUE
,
4898 "%s(width < 0)", name
);
4903 _mesa_error(ctx
, GL_INVALID_VALUE
,
4904 "%s(height < 0)", name
);
4908 /* The GL_ARB_invalidate_subdata spec says:
4910 * "If an attachment is specified that does not exist in the
4911 * framebuffer bound to <target>, it is ignored."
4915 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4916 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4917 * INVALID_OPERATION is generated."
4919 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4920 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4921 * set of retrictions).
4923 for (i
= 0; i
< numAttachments
; i
++) {
4924 if (_mesa_is_winsys_fbo(fb
)) {
4925 switch (attachments
[i
]) {
4931 /* Accumulation buffers and auxilary buffers were removed in
4932 * OpenGL 3.1, and they never existed in OpenGL ES.
4934 if (ctx
->API
!= API_OPENGL_COMPAT
)
4944 case GL_FRONT_RIGHT
:
4945 if (!_mesa_is_desktop_gl(ctx
))
4952 switch (attachments
[i
]) {
4953 case GL_DEPTH_ATTACHMENT
:
4954 case GL_STENCIL_ATTACHMENT
:
4956 case GL_DEPTH_STENCIL_ATTACHMENT
:
4957 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4958 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4959 * extension does not make this attachment point valid on ES 2.0.
4961 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4964 case GL_COLOR_ATTACHMENT0
:
4965 case GL_COLOR_ATTACHMENT1
:
4966 case GL_COLOR_ATTACHMENT2
:
4967 case GL_COLOR_ATTACHMENT3
:
4968 case GL_COLOR_ATTACHMENT4
:
4969 case GL_COLOR_ATTACHMENT5
:
4970 case GL_COLOR_ATTACHMENT6
:
4971 case GL_COLOR_ATTACHMENT7
:
4972 case GL_COLOR_ATTACHMENT8
:
4973 case GL_COLOR_ATTACHMENT9
:
4974 case GL_COLOR_ATTACHMENT10
:
4975 case GL_COLOR_ATTACHMENT11
:
4976 case GL_COLOR_ATTACHMENT12
:
4977 case GL_COLOR_ATTACHMENT13
:
4978 case GL_COLOR_ATTACHMENT14
:
4979 case GL_COLOR_ATTACHMENT15
: {
4980 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4981 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4982 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4983 "%s(attachment >= max. color attachments)", name
);
4994 /* We don't actually do anything for this yet. Just return after
4995 * validating the parameters and generating the required errors.
5000 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
5001 _mesa_enum_to_string(attachments
[i
]));
5005 static struct gl_renderbuffer_attachment
*
5006 get_fb_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
5007 const GLenum attachment
)
5009 switch (attachment
) {
5011 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
5012 case GL_COLOR_ATTACHMENT0
:
5013 case GL_COLOR_ATTACHMENT1
:
5014 case GL_COLOR_ATTACHMENT2
:
5015 case GL_COLOR_ATTACHMENT3
:
5016 case GL_COLOR_ATTACHMENT4
:
5017 case GL_COLOR_ATTACHMENT5
:
5018 case GL_COLOR_ATTACHMENT6
:
5019 case GL_COLOR_ATTACHMENT7
:
5020 case GL_COLOR_ATTACHMENT8
:
5021 case GL_COLOR_ATTACHMENT9
:
5022 case GL_COLOR_ATTACHMENT10
:
5023 case GL_COLOR_ATTACHMENT11
:
5024 case GL_COLOR_ATTACHMENT12
:
5025 case GL_COLOR_ATTACHMENT13
:
5026 case GL_COLOR_ATTACHMENT14
:
5027 case GL_COLOR_ATTACHMENT15
: {
5028 const unsigned i
= attachment
- GL_COLOR_ATTACHMENT0
;
5029 if (i
>= ctx
->Const
.MaxColorAttachments
)
5031 assert(BUFFER_COLOR0
+ i
< ARRAY_SIZE(fb
->Attachment
));
5032 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
5035 case GL_DEPTH_ATTACHMENT
:
5036 case GL_DEPTH_STENCIL_ATTACHMENT
:
5037 return &fb
->Attachment
[BUFFER_DEPTH
];
5039 case GL_STENCIL_ATTACHMENT
:
5040 return &fb
->Attachment
[BUFFER_STENCIL
];
5047 discard_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
5048 GLsizei numAttachments
, const GLenum
*attachments
)
5050 if (!ctx
->Driver
.DiscardFramebuffer
)
5053 for (int i
= 0; i
< numAttachments
; i
++) {
5054 struct gl_renderbuffer_attachment
*att
=
5055 get_fb_attachment(ctx
, fb
, attachments
[i
]);
5060 /* If we're asked to invalidate just depth or just stencil, but the
5061 * attachment is packed depth/stencil, then we can only use
5062 * Driver.DiscardFramebuffer if the attachments list includes both depth
5063 * and stencil and they both point at the same renderbuffer.
5065 if ((attachments
[i
] == GL_DEPTH_ATTACHMENT
||
5066 attachments
[i
] == GL_STENCIL_ATTACHMENT
) &&
5067 (!att
->Renderbuffer
||
5068 att
->Renderbuffer
->_BaseFormat
== GL_DEPTH_STENCIL
)) {
5069 GLenum other_format
= (attachments
[i
] == GL_DEPTH_ATTACHMENT
?
5070 GL_STENCIL_ATTACHMENT
: GL_DEPTH_ATTACHMENT
);
5071 bool has_both
= false;
5072 for (int j
= 0; j
< numAttachments
; j
++) {
5073 if (attachments
[j
] == other_format
) {
5079 if (fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
!=
5080 fb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
|| !has_both
)
5084 ctx
->Driver
.DiscardFramebuffer(ctx
, fb
, att
);
5089 _mesa_InvalidateSubFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
5090 const GLenum
*attachments
, GLint x
,
5091 GLint y
, GLsizei width
, GLsizei height
)
5098 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
5099 const GLenum
*attachments
, GLint x
, GLint y
,
5100 GLsizei width
, GLsizei height
)
5102 struct gl_framebuffer
*fb
;
5103 GET_CURRENT_CONTEXT(ctx
);
5105 fb
= get_framebuffer_target(ctx
, target
);
5107 _mesa_error(ctx
, GL_INVALID_ENUM
,
5108 "glInvalidateSubFramebuffer(invalid target %s)",
5109 _mesa_enum_to_string(target
));
5113 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
5114 x
, y
, width
, height
,
5115 "glInvalidateSubFramebuffer");
5120 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
5121 GLsizei numAttachments
,
5122 const GLenum
*attachments
,
5124 GLsizei width
, GLsizei height
)
5126 struct gl_framebuffer
*fb
;
5127 GET_CURRENT_CONTEXT(ctx
);
5129 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
5130 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
5131 * default draw framebuffer is affected."
5134 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
5135 "glInvalidateNamedFramebufferSubData");
5140 fb
= ctx
->WinSysDrawBuffer
;
5142 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
5143 x
, y
, width
, height
,
5144 "glInvalidateNamedFramebufferSubData");
5148 _mesa_InvalidateFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
5149 const GLenum
*attachments
)
5151 struct gl_framebuffer
*fb
;
5152 GET_CURRENT_CONTEXT(ctx
);
5154 fb
= get_framebuffer_target(ctx
, target
);
5158 discard_framebuffer(ctx
, fb
, numAttachments
, attachments
);
5163 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
5164 const GLenum
*attachments
)
5166 struct gl_framebuffer
*fb
;
5167 GET_CURRENT_CONTEXT(ctx
);
5169 fb
= get_framebuffer_target(ctx
, target
);
5171 _mesa_error(ctx
, GL_INVALID_ENUM
,
5172 "glInvalidateFramebuffer(invalid target %s)",
5173 _mesa_enum_to_string(target
));
5177 /* The GL_ARB_invalidate_subdata spec says:
5181 * void InvalidateFramebuffer(enum target,
5182 * sizei numAttachments,
5183 * const enum *attachments);
5185 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
5186 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
5187 * <MAX_VIEWPORT_DIMS[1]> respectively."
5189 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
5191 ctx
->Const
.MaxViewportWidth
,
5192 ctx
->Const
.MaxViewportHeight
,
5193 "glInvalidateFramebuffer");
5195 discard_framebuffer(ctx
, fb
, numAttachments
, attachments
);
5200 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
5201 GLsizei numAttachments
,
5202 const GLenum
*attachments
)
5204 struct gl_framebuffer
*fb
;
5205 GET_CURRENT_CONTEXT(ctx
);
5207 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
5208 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
5209 * default draw framebuffer is affected."
5212 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
5213 "glInvalidateNamedFramebufferData");
5218 fb
= ctx
->WinSysDrawBuffer
;
5220 /* The GL_ARB_invalidate_subdata spec says:
5224 * void InvalidateFramebuffer(enum target,
5225 * sizei numAttachments,
5226 * const enum *attachments);
5228 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
5229 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
5230 * <MAX_VIEWPORT_DIMS[1]> respectively."
5232 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
5234 ctx
->Const
.MaxViewportWidth
,
5235 ctx
->Const
.MaxViewportHeight
,
5236 "glInvalidateNamedFramebufferData");
5241 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
5242 const GLenum
*attachments
)
5244 struct gl_framebuffer
*fb
;
5247 GET_CURRENT_CONTEXT(ctx
);
5249 fb
= get_framebuffer_target(ctx
, target
);
5251 _mesa_error(ctx
, GL_INVALID_ENUM
,
5252 "glDiscardFramebufferEXT(target %s)",
5253 _mesa_enum_to_string(target
));
5257 if (numAttachments
< 0) {
5258 _mesa_error(ctx
, GL_INVALID_VALUE
,
5259 "glDiscardFramebufferEXT(numAttachments < 0)");
5263 for (i
= 0; i
< numAttachments
; i
++) {
5264 switch (attachments
[i
]) {
5268 if (_mesa_is_user_fbo(fb
))
5271 case GL_COLOR_ATTACHMENT0
:
5272 case GL_DEPTH_ATTACHMENT
:
5273 case GL_STENCIL_ATTACHMENT
:
5274 if (_mesa_is_winsys_fbo(fb
))
5282 discard_framebuffer(ctx
, fb
, numAttachments
, attachments
);
5287 _mesa_error(ctx
, GL_INVALID_ENUM
,
5288 "glDiscardFramebufferEXT(attachment %s)",
5289 _mesa_enum_to_string(attachments
[i
]));
5293 sample_locations(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
5294 GLuint start
, GLsizei count
, const GLfloat
*v
, bool no_error
,
5300 if (!ctx
->Extensions
.ARB_sample_locations
) {
5301 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5303 "(ARB_sample_locations not available)", name
);
5307 if (start
+ count
> MAX_SAMPLE_LOCATION_TABLE_SIZE
) {
5308 _mesa_error(ctx
, GL_INVALID_VALUE
,
5309 "%s(start+size > sample location table size)", name
);
5314 if (!fb
->SampleLocationTable
) {
5315 size_t size
= MAX_SAMPLE_LOCATION_TABLE_SIZE
* 2 * sizeof(GLfloat
);
5316 fb
->SampleLocationTable
= malloc(size
);
5317 if (!fb
->SampleLocationTable
) {
5318 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
5319 "Cannot allocate sample location table");
5322 for (i
= 0; i
< MAX_SAMPLE_LOCATION_TABLE_SIZE
* 2; i
++)
5323 fb
->SampleLocationTable
[i
] = 0.5f
;
5326 for (i
= 0; i
< count
* 2; i
++) {
5327 /* The ARB_sample_locations spec says:
5329 * Sample locations outside of [0,1] result in undefined
5332 * To simplify driver implementations, we choose to clamp to
5333 * [0,1] and change NaN into 0.5.
5335 if (isnan(v
[i
]) || v
[i
] < 0.0f
|| v
[i
] > 1.0f
) {
5336 static GLuint msg_id
= 0;
5337 static const char* msg
= "Invalid sample location specified";
5338 _mesa_debug_get_id(&msg_id
);
5340 _mesa_log_msg(ctx
, MESA_DEBUG_SOURCE_API
, MESA_DEBUG_TYPE_UNDEFINED
,
5341 msg_id
, MESA_DEBUG_SEVERITY_HIGH
, strlen(msg
), msg
);
5345 fb
->SampleLocationTable
[start
* 2 + i
] = 0.5f
;
5347 fb
->SampleLocationTable
[start
* 2 + i
] = SATURATE(v
[i
]);
5350 if (fb
== ctx
->DrawBuffer
)
5351 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
5355 _mesa_FramebufferSampleLocationsfvARB(GLenum target
, GLuint start
,
5356 GLsizei count
, const GLfloat
*v
)
5358 struct gl_framebuffer
*fb
;
5360 GET_CURRENT_CONTEXT(ctx
);
5362 fb
= get_framebuffer_target(ctx
, target
);
5364 _mesa_error(ctx
, GL_INVALID_ENUM
,
5365 "glFramebufferSampleLocationsfvARB(target %s)",
5366 _mesa_enum_to_string(target
));
5370 sample_locations(ctx
, fb
, start
, count
, v
, false,
5371 "glFramebufferSampleLocationsfvARB");
5375 _mesa_NamedFramebufferSampleLocationsfvARB(GLuint framebuffer
, GLuint start
,
5376 GLsizei count
, const GLfloat
*v
)
5378 struct gl_framebuffer
*fb
;
5380 GET_CURRENT_CONTEXT(ctx
);
5383 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
5384 "glNamedFramebufferSampleLocationsfvARB");
5389 fb
= ctx
->WinSysDrawBuffer
;
5391 sample_locations(ctx
, fb
, start
, count
, v
, false,
5392 "glNamedFramebufferSampleLocationsfvARB");
5396 _mesa_FramebufferSampleLocationsfvARB_no_error(GLenum target
, GLuint start
,
5397 GLsizei count
, const GLfloat
*v
)
5399 GET_CURRENT_CONTEXT(ctx
);
5400 sample_locations(ctx
, get_framebuffer_target(ctx
, target
), start
,
5401 count
, v
, true, "glFramebufferSampleLocationsfvARB");
5405 _mesa_NamedFramebufferSampleLocationsfvARB_no_error(GLuint framebuffer
,
5406 GLuint start
, GLsizei count
,
5409 GET_CURRENT_CONTEXT(ctx
);
5410 sample_locations(ctx
, _mesa_lookup_framebuffer(ctx
, framebuffer
), start
,
5411 count
, v
, true, "glNamedFramebufferSampleLocationsfvARB");
5415 _mesa_EvaluateDepthValuesARB(void)
5417 GET_CURRENT_CONTEXT(ctx
);
5419 if (!ctx
->Extensions
.ARB_sample_locations
) {
5420 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5421 "EvaluateDepthValuesARB not supported (neither "
5422 "ARB_sample_locations nor NV_sample_locations is available)");
5426 if (ctx
->Driver
.EvaluateDepthValues
)
5427 ctx
->Driver
.EvaluateDepthValues(ctx
);