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 * A convenience function for direct state access that throws
164 * GL_INVALID_OPERATION if the framebuffer doesn't exist.
166 struct gl_framebuffer
*
167 _mesa_lookup_framebuffer_err(struct gl_context
*ctx
, GLuint id
,
170 struct gl_framebuffer
*fb
;
172 fb
= _mesa_lookup_framebuffer(ctx
, id
);
173 if (!fb
|| fb
== &DummyFramebuffer
) {
174 _mesa_error(ctx
, GL_INVALID_OPERATION
,
175 "%s(non-existent framebuffer %u)", func
, id
);
184 * Mark the given framebuffer as invalid. This will force the
185 * test for framebuffer completeness to be done before the framebuffer
189 invalidate_framebuffer(struct gl_framebuffer
*fb
)
191 fb
->_Status
= 0; /* "indeterminate" */
196 * Return the gl_framebuffer object which corresponds to the given
197 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
198 * Check support for GL_EXT_framebuffer_blit to determine if certain
200 * \return gl_framebuffer pointer or NULL if target is illegal
202 static struct gl_framebuffer
*
203 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
205 bool have_fb_blit
= _mesa_is_gles3(ctx
) || _mesa_is_desktop_gl(ctx
);
207 case GL_DRAW_FRAMEBUFFER
:
208 return have_fb_blit
? ctx
->DrawBuffer
: NULL
;
209 case GL_READ_FRAMEBUFFER
:
210 return have_fb_blit
? ctx
->ReadBuffer
: NULL
;
211 case GL_FRAMEBUFFER_EXT
:
212 return ctx
->DrawBuffer
;
220 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
221 * gl_renderbuffer_attachment object.
222 * This function is only used for user-created FB objects, not the
223 * default / window-system FB object.
224 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
225 * the depth buffer attachment point.
226 * Returns if the attachment is a GL_COLOR_ATTACHMENTm_EXT on
227 * is_color_attachment, because several callers would return different errors
228 * if they don't find the attachment.
230 static struct gl_renderbuffer_attachment
*
231 get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
232 GLenum attachment
, bool *is_color_attachment
)
236 assert(_mesa_is_user_fbo(fb
));
238 if (is_color_attachment
)
239 *is_color_attachment
= false;
241 switch (attachment
) {
242 case GL_COLOR_ATTACHMENT0_EXT
:
243 case GL_COLOR_ATTACHMENT1_EXT
:
244 case GL_COLOR_ATTACHMENT2_EXT
:
245 case GL_COLOR_ATTACHMENT3_EXT
:
246 case GL_COLOR_ATTACHMENT4_EXT
:
247 case GL_COLOR_ATTACHMENT5_EXT
:
248 case GL_COLOR_ATTACHMENT6_EXT
:
249 case GL_COLOR_ATTACHMENT7_EXT
:
250 case GL_COLOR_ATTACHMENT8_EXT
:
251 case GL_COLOR_ATTACHMENT9_EXT
:
252 case GL_COLOR_ATTACHMENT10_EXT
:
253 case GL_COLOR_ATTACHMENT11_EXT
:
254 case GL_COLOR_ATTACHMENT12_EXT
:
255 case GL_COLOR_ATTACHMENT13_EXT
:
256 case GL_COLOR_ATTACHMENT14_EXT
:
257 case GL_COLOR_ATTACHMENT15_EXT
:
258 if (is_color_attachment
)
259 *is_color_attachment
= true;
260 /* Only OpenGL ES 1.x forbids color attachments other than
261 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
264 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
265 if (i
>= ctx
->Const
.MaxColorAttachments
266 || (i
> 0 && ctx
->API
== API_OPENGLES
)) {
269 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
270 case GL_DEPTH_STENCIL_ATTACHMENT
:
271 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
274 case GL_DEPTH_ATTACHMENT_EXT
:
275 return &fb
->Attachment
[BUFFER_DEPTH
];
276 case GL_STENCIL_ATTACHMENT_EXT
:
277 return &fb
->Attachment
[BUFFER_STENCIL
];
285 * As above, but only used for getting attachments of the default /
286 * window-system framebuffer (not user-created framebuffer objects).
288 static struct gl_renderbuffer_attachment
*
289 get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
292 assert(_mesa_is_winsys_fbo(fb
));
294 if (_mesa_is_gles3(ctx
)) {
295 assert(attachment
== GL_BACK
||
296 attachment
== GL_DEPTH
||
297 attachment
== GL_STENCIL
);
298 switch (attachment
) {
300 /* Since there is no stereo rendering in ES 3.0, only return the
303 if (ctx
->DrawBuffer
->Visual
.doubleBufferMode
)
304 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
305 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
307 return &fb
->Attachment
[BUFFER_DEPTH
];
309 return &fb
->Attachment
[BUFFER_STENCIL
];
313 switch (attachment
) {
315 /* Front buffers can be allocated on the first use, but
316 * glGetFramebufferAttachmentParameteriv must work even if that
317 * allocation hasn't happened yet. In such case, use the back buffer,
318 * which should be the same.
320 if (fb
->Attachment
[BUFFER_FRONT_LEFT
].Type
== GL_NONE
)
321 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
323 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
326 if (fb
->Attachment
[BUFFER_FRONT_RIGHT
].Type
== GL_NONE
)
327 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
329 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
331 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
333 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
335 /* The ARB_ES3_1_compatibility spec says:
337 * "Since this command can only query a single framebuffer
338 * attachment, BACK is equivalent to BACK_LEFT."
340 if (ctx
->Extensions
.ARB_ES3_1_compatibility
)
341 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
344 if (fb
->Visual
.numAuxBuffers
== 1) {
345 return &fb
->Attachment
[BUFFER_AUX0
];
349 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
351 * "If the default framebuffer is bound to target, then attachment must
352 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
353 * identifying a color buffer; DEPTH, identifying the depth buffer; or
354 * STENCIL, identifying the stencil buffer."
356 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
357 * language. However, revision #33 of the ARB_framebuffer_object spec
360 * "If the default framebuffer is bound to <target>, then <attachment>
361 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
362 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
363 * depth buffer, or the stencil buffer, and <pname> may be
364 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
365 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
367 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
368 * from glext.h, so shipping apps should not use those values.
370 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
371 * support queries of the window system FBO.
374 return &fb
->Attachment
[BUFFER_DEPTH
];
376 return &fb
->Attachment
[BUFFER_STENCIL
];
385 * Remove any texture or renderbuffer attached to the given attachment
386 * point. Update reference counts, etc.
389 remove_attachment(struct gl_context
*ctx
,
390 struct gl_renderbuffer_attachment
*att
)
392 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
394 /* tell driver that we're done rendering to this texture. */
395 if (rb
&& rb
->NeedsFinishRenderTexture
)
396 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
398 if (att
->Type
== GL_TEXTURE
) {
399 assert(att
->Texture
);
400 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
401 assert(!att
->Texture
);
403 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
404 assert(!att
->Texture
);
405 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
406 assert(!att
->Renderbuffer
);
409 att
->Complete
= GL_TRUE
;
413 * Verify a couple error conditions that will lead to an incomplete FBO and
414 * may cause problems for the driver's RenderTexture path.
417 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment
*att
)
419 const struct gl_texture_image
*const texImage
=
420 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
423 texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
426 if ((texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
427 && att
->Zoffset
>= texImage
->Height
)
428 || (texImage
->TexObject
->Target
!= GL_TEXTURE_1D_ARRAY
429 && att
->Zoffset
>= texImage
->Depth
))
436 * Create a renderbuffer which will be set up by the driver to wrap the
437 * texture image slice.
439 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
440 * to share most of their framebuffer rendering code between winsys,
441 * renderbuffer, and texture attachments.
443 * The allocated renderbuffer uses a non-zero Name so that drivers can check
444 * it for determining vertical orientation, but we use ~0 to make it fairly
445 * unambiguous with actual user (non-texture) renderbuffers.
448 _mesa_update_texture_renderbuffer(struct gl_context
*ctx
,
449 struct gl_framebuffer
*fb
,
450 struct gl_renderbuffer_attachment
*att
)
452 struct gl_texture_image
*texImage
;
453 struct gl_renderbuffer
*rb
;
455 texImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
457 rb
= att
->Renderbuffer
;
459 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
461 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
464 att
->Renderbuffer
= rb
;
466 /* This can't get called on a texture renderbuffer, so set it to NULL
467 * for clarity compared to user renderbuffers.
469 rb
->AllocStorage
= NULL
;
471 rb
->NeedsFinishRenderTexture
= ctx
->Driver
.FinishRenderTexture
!= NULL
;
477 rb
->_BaseFormat
= texImage
->_BaseFormat
;
478 rb
->Format
= texImage
->TexFormat
;
479 rb
->InternalFormat
= texImage
->InternalFormat
;
480 rb
->Width
= texImage
->Width2
;
481 rb
->Height
= texImage
->Height2
;
482 rb
->Depth
= texImage
->Depth2
;
483 rb
->NumSamples
= texImage
->NumSamples
;
484 rb
->TexImage
= texImage
;
486 if (driver_RenderTexture_is_safe(att
))
487 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
491 * Bind a texture object to an attachment point.
492 * The previous binding, if any, will be removed first.
495 set_texture_attachment(struct gl_context
*ctx
,
496 struct gl_framebuffer
*fb
,
497 struct gl_renderbuffer_attachment
*att
,
498 struct gl_texture_object
*texObj
,
499 GLenum texTarget
, GLuint level
, GLuint layer
,
502 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
504 if (rb
&& rb
->NeedsFinishRenderTexture
)
505 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
507 if (att
->Texture
== texObj
) {
508 /* re-attaching same texture */
509 assert(att
->Type
== GL_TEXTURE
);
513 remove_attachment(ctx
, att
);
514 att
->Type
= GL_TEXTURE
;
515 assert(!att
->Texture
);
516 _mesa_reference_texobj(&att
->Texture
, texObj
);
518 invalidate_framebuffer(fb
);
520 /* always update these fields */
521 att
->TextureLevel
= level
;
522 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
523 att
->Zoffset
= layer
;
524 att
->Layered
= layered
;
525 att
->Complete
= GL_FALSE
;
527 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
532 * Bind a renderbuffer to an attachment point.
533 * The previous binding, if any, will be removed first.
536 set_renderbuffer_attachment(struct gl_context
*ctx
,
537 struct gl_renderbuffer_attachment
*att
,
538 struct gl_renderbuffer
*rb
)
540 /* XXX check if re-doing same attachment, exit early */
541 remove_attachment(ctx
, att
);
542 att
->Type
= GL_RENDERBUFFER_EXT
;
543 att
->Texture
= NULL
; /* just to be safe */
544 att
->Layered
= GL_FALSE
;
545 att
->Complete
= GL_FALSE
;
546 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
551 * Fallback for ctx->Driver.FramebufferRenderbuffer()
552 * Attach a renderbuffer object to a framebuffer object.
555 _mesa_FramebufferRenderbuffer_sw(struct gl_context
*ctx
,
556 struct gl_framebuffer
*fb
,
558 struct gl_renderbuffer
*rb
)
560 struct gl_renderbuffer_attachment
*att
;
562 simple_mtx_lock(&fb
->Mutex
);
564 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
567 set_renderbuffer_attachment(ctx
, att
, rb
);
568 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
569 /* do stencil attachment here (depth already done above) */
570 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
572 set_renderbuffer_attachment(ctx
, att
, rb
);
574 rb
->AttachedAnytime
= GL_TRUE
;
577 remove_attachment(ctx
, att
);
578 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
579 /* detach stencil (depth was detached above) */
580 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
582 remove_attachment(ctx
, att
);
586 invalidate_framebuffer(fb
);
588 simple_mtx_unlock(&fb
->Mutex
);
593 * Fallback for ctx->Driver.ValidateFramebuffer()
594 * Check if the renderbuffer's formats are supported by the software
596 * Drivers should probably override this.
599 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
602 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
603 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
605 switch (rb
->_BaseFormat
) {
607 case GL_LUMINANCE_ALPHA
:
612 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
616 switch (rb
->Format
) {
617 /* XXX This list is likely incomplete. */
618 case MESA_FORMAT_R9G9B9E5_FLOAT
:
619 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
622 /* render buffer format is supported by software rendering */
631 * Return true if the framebuffer has a combined depth/stencil
632 * renderbuffer attached.
635 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
637 const struct gl_renderbuffer_attachment
*depth
=
638 &fb
->Attachment
[BUFFER_DEPTH
];
639 const struct gl_renderbuffer_attachment
*stencil
=
640 &fb
->Attachment
[BUFFER_STENCIL
];
642 if (depth
->Type
== stencil
->Type
) {
643 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
644 depth
->Renderbuffer
== stencil
->Renderbuffer
)
647 if (depth
->Type
== GL_TEXTURE
&&
648 depth
->Texture
== stencil
->Texture
)
660 att_incomplete(const char *msg
)
662 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
663 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
672 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
674 static GLuint msg_id
;
676 _mesa_gl_debug(ctx
, &msg_id
,
677 MESA_DEBUG_SOURCE_API
,
678 MESA_DEBUG_TYPE_OTHER
,
679 MESA_DEBUG_SEVERITY_MEDIUM
,
680 "FBO incomplete: %s [%d]\n", msg
, index
);
682 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
683 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
689 * Is the given base format a legal format for a color renderbuffer?
692 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
694 switch (baseFormat
) {
699 case GL_LUMINANCE_ALPHA
:
702 return ctx
->API
== API_OPENGL_COMPAT
&&
703 ctx
->Extensions
.ARB_framebuffer_object
;
706 return ctx
->Extensions
.ARB_texture_rg
;
714 * Is the given base format a legal format for a color renderbuffer?
717 is_format_color_renderable(const struct gl_context
*ctx
, mesa_format format
,
718 GLenum internalFormat
)
720 const GLenum baseFormat
=
721 _mesa_get_format_base_format(format
);
724 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
725 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
729 /* Reject additional cases for GLES */
730 switch (internalFormat
) {
751 if (internalFormat
!= GL_RGB10_A2
&&
752 (format
== MESA_FORMAT_B10G10R10A2_UNORM
||
753 format
== MESA_FORMAT_B10G10R10X2_UNORM
||
754 format
== MESA_FORMAT_R10G10B10A2_UNORM
||
755 format
== MESA_FORMAT_R10G10B10X2_UNORM
)) {
764 * Is the given base format a legal format for a depth/stencil renderbuffer?
767 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
769 switch (baseFormat
) {
770 case GL_DEPTH_COMPONENT
:
771 case GL_DEPTH_STENCIL_EXT
:
780 * Test if an attachment point is complete and update its Complete field.
781 * \param format if GL_COLOR, this is a color attachment point,
782 * if GL_DEPTH, this is a depth component attachment point,
783 * if GL_STENCIL, this is a stencil component attachment point.
786 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
787 struct gl_renderbuffer_attachment
*att
)
789 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
791 /* assume complete */
792 att
->Complete
= GL_TRUE
;
794 /* Look for reasons why the attachment might be incomplete */
795 if (att
->Type
== GL_TEXTURE
) {
796 const struct gl_texture_object
*texObj
= att
->Texture
;
797 const struct gl_texture_image
*texImage
;
801 att_incomplete("no texobj");
802 att
->Complete
= GL_FALSE
;
806 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
808 att_incomplete("no teximage");
809 att
->Complete
= GL_FALSE
;
812 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
813 att_incomplete("teximage width/height=0");
814 att
->Complete
= GL_FALSE
;
818 switch (texObj
->Target
) {
820 if (att
->Zoffset
>= texImage
->Depth
) {
821 att_incomplete("bad z offset");
822 att
->Complete
= GL_FALSE
;
826 case GL_TEXTURE_1D_ARRAY
:
827 if (att
->Zoffset
>= texImage
->Height
) {
828 att_incomplete("bad 1D-array layer");
829 att
->Complete
= GL_FALSE
;
833 case GL_TEXTURE_2D_ARRAY
:
834 if (att
->Zoffset
>= texImage
->Depth
) {
835 att_incomplete("bad 2D-array layer");
836 att
->Complete
= GL_FALSE
;
840 case GL_TEXTURE_CUBE_MAP_ARRAY
:
841 if (att
->Zoffset
>= texImage
->Depth
) {
842 att_incomplete("bad cube-array layer");
843 att
->Complete
= GL_FALSE
;
849 baseFormat
= texImage
->_BaseFormat
;
851 if (format
== GL_COLOR
) {
852 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
853 att_incomplete("bad format");
854 att
->Complete
= GL_FALSE
;
857 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
858 att_incomplete("compressed internalformat");
859 att
->Complete
= GL_FALSE
;
863 /* OES_texture_float allows creation and use of floating point
864 * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow
865 * these textures to be used as a render target, this is done via
866 * GL_EXT_color_buffer(_half)_float with set of new sized types.
868 if (_mesa_is_gles(ctx
) && (texObj
->_IsFloat
|| texObj
->_IsHalfFloat
)) {
869 att_incomplete("bad internal format");
870 att
->Complete
= GL_FALSE
;
874 else if (format
== GL_DEPTH
) {
875 if (baseFormat
== GL_DEPTH_COMPONENT
) {
878 else if (ctx
->Extensions
.ARB_depth_texture
&&
879 baseFormat
== GL_DEPTH_STENCIL
) {
883 att
->Complete
= GL_FALSE
;
884 att_incomplete("bad depth format");
889 assert(format
== GL_STENCIL
);
890 if (ctx
->Extensions
.ARB_depth_texture
&&
891 baseFormat
== GL_DEPTH_STENCIL
) {
893 } else if (ctx
->Extensions
.ARB_texture_stencil8
&&
894 baseFormat
== GL_STENCIL_INDEX
) {
897 /* no such thing as stencil-only textures */
898 att_incomplete("illegal stencil texture");
899 att
->Complete
= GL_FALSE
;
904 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
905 const GLenum baseFormat
= att
->Renderbuffer
->_BaseFormat
;
907 assert(att
->Renderbuffer
);
908 if (!att
->Renderbuffer
->InternalFormat
||
909 att
->Renderbuffer
->Width
< 1 ||
910 att
->Renderbuffer
->Height
< 1) {
911 att_incomplete("0x0 renderbuffer");
912 att
->Complete
= GL_FALSE
;
915 if (format
== GL_COLOR
) {
916 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
917 att_incomplete("bad renderbuffer color format");
918 att
->Complete
= GL_FALSE
;
922 else if (format
== GL_DEPTH
) {
923 if (baseFormat
== GL_DEPTH_COMPONENT
) {
926 else if (baseFormat
== GL_DEPTH_STENCIL
) {
930 att_incomplete("bad renderbuffer depth format");
931 att
->Complete
= GL_FALSE
;
936 assert(format
== GL_STENCIL
);
937 if (baseFormat
== GL_STENCIL_INDEX
||
938 baseFormat
== GL_DEPTH_STENCIL
) {
942 att
->Complete
= GL_FALSE
;
943 att_incomplete("bad renderbuffer stencil format");
949 assert(att
->Type
== GL_NONE
);
957 * Test if the given framebuffer object is complete and update its
958 * Status field with the results.
959 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
960 * driver to make hardware-specific validation/completeness checks.
961 * Also update the framebuffer's Width and Height fields if the
962 * framebuffer is complete.
965 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
966 struct gl_framebuffer
*fb
)
969 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
970 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
971 GLint numSamples
= -1;
972 GLint fixedSampleLocations
= -1;
975 /* Covers max_layer_count, is_layered, and layer_tex_target */
976 bool layer_info_valid
= false;
977 GLuint max_layer_count
= 0, att_layer_count
;
978 bool is_layered
= false;
979 GLenum layer_tex_target
= 0;
980 bool has_depth_attachment
= false;
981 bool has_stencil_attachment
= false;
983 assert(_mesa_is_user_fbo(fb
));
985 /* we're changing framebuffer fields here */
986 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
991 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
992 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
993 fb
->_HasAttachments
= true;
994 fb
->_IntegerBuffers
= 0;
996 /* Start at -2 to more easily loop over all attachment points.
1001 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
1002 struct gl_renderbuffer_attachment
*att
;
1004 mesa_format attFormat
;
1005 GLenum att_tex_target
= GL_NONE
;
1008 * XXX for ARB_fbo, only check color buffers that are named by
1009 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
1012 /* check for attachment completeness
1015 att
= &fb
->Attachment
[BUFFER_DEPTH
];
1016 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
1017 if (!att
->Complete
) {
1018 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1019 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
1021 } else if (att
->Type
!= GL_NONE
) {
1022 has_depth_attachment
= true;
1026 att
= &fb
->Attachment
[BUFFER_STENCIL
];
1027 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
1028 if (!att
->Complete
) {
1029 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1030 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
1032 } else if (att
->Type
!= GL_NONE
) {
1033 has_stencil_attachment
= true;
1037 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
1038 test_attachment_completeness(ctx
, GL_COLOR
, att
);
1039 if (!att
->Complete
) {
1040 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1041 fbo_incomplete(ctx
, "color attachment incomplete", i
);
1046 /* get width, height, format of the renderbuffer/texture
1048 if (att
->Type
== GL_TEXTURE
) {
1049 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
1050 att_tex_target
= att
->Texture
->Target
;
1051 minWidth
= MIN2(minWidth
, texImg
->Width
);
1052 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
1053 minHeight
= MIN2(minHeight
, texImg
->Height
);
1054 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
1055 f
= texImg
->_BaseFormat
;
1056 attFormat
= texImg
->TexFormat
;
1059 if (!is_format_color_renderable(ctx
, attFormat
,
1060 texImg
->InternalFormat
) &&
1061 !is_legal_depth_format(ctx
, f
) &&
1062 f
!= GL_STENCIL_INDEX
) {
1063 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
;
1064 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
1069 numSamples
= texImg
->NumSamples
;
1070 else if (numSamples
!= texImg
->NumSamples
) {
1071 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1072 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1076 if (fixedSampleLocations
< 0)
1077 fixedSampleLocations
= texImg
->FixedSampleLocations
;
1078 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
1079 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1080 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1084 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1085 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
1086 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
1087 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
1088 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
1089 f
= att
->Renderbuffer
->InternalFormat
;
1090 attFormat
= att
->Renderbuffer
->Format
;
1094 numSamples
= att
->Renderbuffer
->NumSamples
;
1095 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
1096 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1097 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1101 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1102 if (fixedSampleLocations
< 0)
1103 fixedSampleLocations
= GL_TRUE
;
1104 else if (fixedSampleLocations
!= GL_TRUE
) {
1105 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1106 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1111 assert(att
->Type
== GL_NONE
);
1115 /* Update flags describing color buffer datatypes */
1117 GLenum type
= _mesa_get_format_datatype(attFormat
);
1119 /* check if integer color */
1120 if (_mesa_is_format_integer_color(attFormat
))
1121 fb
->_IntegerBuffers
|= (1 << i
);
1123 fb
->_AllColorBuffersFixedPoint
=
1124 fb
->_AllColorBuffersFixedPoint
&&
1125 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1127 fb
->_HasSNormOrFloatColorBuffer
=
1128 fb
->_HasSNormOrFloatColorBuffer
||
1129 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1132 /* Error-check width, height, format */
1133 if (numImages
== 1) {
1140 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1141 /* check that width, height, format are same */
1142 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1143 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1144 fbo_incomplete(ctx
, "width or height mismatch", -1);
1147 /* check that all color buffers are the same format */
1148 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1149 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1150 fbo_incomplete(ctx
, "format mismatch", -1);
1156 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1158 if (att
->Type
== GL_RENDERBUFFER
&&
1159 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1160 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1161 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1165 /* Check that layered rendering is consistent. */
1167 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1168 att_layer_count
= 6;
1169 else if (att_tex_target
== GL_TEXTURE_1D_ARRAY
)
1170 att_layer_count
= att
->Renderbuffer
->Height
;
1172 att_layer_count
= att
->Renderbuffer
->Depth
;
1174 att_layer_count
= 0;
1176 if (!layer_info_valid
) {
1177 is_layered
= att
->Layered
;
1178 max_layer_count
= att_layer_count
;
1179 layer_tex_target
= att_tex_target
;
1180 layer_info_valid
= true;
1181 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1182 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1183 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1185 } else if (is_layered
!= att
->Layered
) {
1186 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1188 "framebuffer attachment layer mode is inconsistent",
1191 } else if (att_layer_count
> max_layer_count
) {
1192 max_layer_count
= att_layer_count
;
1196 * The extension GL_ARB_framebuffer_no_attachments places additional
1197 * requirement on each attachment. Those additional requirements are
1198 * tighter that those of previous versions of GL. In interest of better
1199 * compatibility, we will not enforce these restrictions. For the record
1200 * those additional restrictions are quoted below:
1202 * "The width and height of image are greater than zero and less than or
1203 * equal to the values of the implementation-dependent limits
1204 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1206 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1207 * array texture and the attachment is layered, the depth or layer count
1208 * of the texture is less than or equal to the implementation-dependent
1209 * limit MAX_FRAMEBUFFER_LAYERS."
1211 * "If image has multiple samples, its sample count is less than or equal
1212 * to the value of the implementation-dependent limit
1213 * MAX_FRAMEBUFFER_SAMPLES."
1215 * The same requirements are also in place for GL 4.5,
1216 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1220 fb
->MaxNumLayers
= max_layer_count
;
1222 if (numImages
== 0) {
1223 fb
->_HasAttachments
= false;
1225 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1226 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1227 fbo_incomplete(ctx
, "no attachments", -1);
1231 if (fb
->DefaultGeometry
.Width
== 0 || fb
->DefaultGeometry
.Height
== 0) {
1232 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1233 fbo_incomplete(ctx
, "no attachments and default width or height is 0", -1);
1238 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1239 /* Check that all DrawBuffers are present */
1240 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1241 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1242 const struct gl_renderbuffer_attachment
*att
1243 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
], NULL
);
1245 if (att
->Type
== GL_NONE
) {
1246 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1247 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1253 /* Check that the ReadBuffer is present */
1254 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1255 const struct gl_renderbuffer_attachment
*att
1256 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
, NULL
);
1258 if (att
->Type
== GL_NONE
) {
1259 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1260 fbo_incomplete(ctx
, "missing readbuffer", -1);
1266 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1268 * "Depth and stencil attachments, if present, are the same image."
1270 * This restriction is not present in the OpenGL ES2 spec.
1272 if (_mesa_is_gles3(ctx
) &&
1273 has_stencil_attachment
&& has_depth_attachment
&&
1274 !_mesa_has_depthstencil_combined(fb
)) {
1275 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1276 fbo_incomplete(ctx
, "Depth and stencil attachments must be the same image", -1);
1280 /* Provisionally set status = COMPLETE ... */
1281 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1283 /* ... but the driver may say the FB is incomplete.
1284 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1287 if (ctx
->Driver
.ValidateFramebuffer
) {
1288 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1289 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1290 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1296 * Note that if ARB_framebuffer_object is supported and the attached
1297 * renderbuffers/textures are different sizes, the framebuffer
1298 * width/height will be set to the smallest width/height.
1300 if (numImages
!= 0) {
1301 fb
->Width
= minWidth
;
1302 fb
->Height
= minHeight
;
1305 /* finally, update the visual info for the framebuffer */
1306 _mesa_update_framebuffer_visual(ctx
, fb
);
1310 GLboolean GLAPIENTRY
1311 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1313 struct gl_renderbuffer
*rb
;
1315 GET_CURRENT_CONTEXT(ctx
);
1317 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1319 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1320 return rb
!= NULL
&& rb
!= &DummyRenderbuffer
;
1324 static struct gl_renderbuffer
*
1325 allocate_renderbuffer_locked(struct gl_context
*ctx
, GLuint renderbuffer
,
1328 struct gl_renderbuffer
*newRb
;
1330 /* create new renderbuffer object */
1331 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1333 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1336 assert(newRb
->AllocStorage
);
1337 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1344 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1346 struct gl_renderbuffer
*newRb
;
1347 GET_CURRENT_CONTEXT(ctx
);
1349 if (target
!= GL_RENDERBUFFER_EXT
) {
1350 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1354 /* No need to flush here since the render buffer binding has no
1355 * effect on rendering state.
1359 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1360 if (newRb
== &DummyRenderbuffer
) {
1361 /* ID was reserved, but no real renderbuffer object made yet */
1364 else if (!newRb
&& !allow_user_names
) {
1365 /* All RB IDs must be Gen'd */
1366 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1371 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1372 newRb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
1373 "glBindRenderbufferEXT");
1374 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1381 assert(newRb
!= &DummyRenderbuffer
);
1383 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1387 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1389 GET_CURRENT_CONTEXT(ctx
);
1391 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1392 * entry point, but they allow the use of user-generated names.
1394 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1398 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1400 /* This function should not be in the dispatch table for core profile /
1401 * OpenGL 3.1, so execution should never get here in those cases -- no
1402 * need for an explicit test.
1404 bind_renderbuffer(target
, renderbuffer
, true);
1408 * ARB_framebuffer_no_attachment and ARB_sample_locations - Application passes
1409 * requested param's here. NOTE: NumSamples requested need not be _NumSamples
1410 * which is what the hw supports.
1413 framebuffer_parameteri(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1414 GLenum pname
, GLint param
, const char *func
)
1416 bool cannot_be_winsys_fbo
= false;
1419 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1420 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1421 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1422 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1423 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1424 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
)
1425 goto invalid_pname_enum
;
1426 cannot_be_winsys_fbo
= true;
1428 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1429 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1430 if (!ctx
->Extensions
.ARB_sample_locations
)
1431 goto invalid_pname_enum
;
1434 goto invalid_pname_enum
;
1437 if (cannot_be_winsys_fbo
&& _mesa_is_winsys_fbo(fb
)) {
1438 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1439 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1444 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1445 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferWidth
)
1446 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1448 fb
->DefaultGeometry
.Width
= param
;
1450 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1451 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferHeight
)
1452 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1454 fb
->DefaultGeometry
.Height
= param
;
1456 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1458 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1459 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1461 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1462 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1465 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferLayers
)
1466 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1468 fb
->DefaultGeometry
.Layers
= param
;
1470 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1471 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferSamples
)
1472 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1474 fb
->DefaultGeometry
.NumSamples
= param
;
1476 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1477 fb
->DefaultGeometry
.FixedSampleLocations
= param
;
1479 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1480 fb
->ProgrammableSampleLocations
= !!param
;
1482 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1483 fb
->SampleLocationPixelGrid
= !!param
;
1488 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1489 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1490 if (fb
== ctx
->DrawBuffer
)
1491 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
1494 invalidate_framebuffer(fb
);
1495 ctx
->NewState
|= _NEW_BUFFERS
;
1502 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1506 _mesa_FramebufferParameteri(GLenum target
, GLenum pname
, GLint param
)
1508 GET_CURRENT_CONTEXT(ctx
);
1509 struct gl_framebuffer
*fb
;
1511 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1512 !ctx
->Extensions
.ARB_sample_locations
) {
1513 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1514 "glFramebufferParameteriv not supported "
1515 "(neither ARB_framebuffer_no_attachments nor ARB_sample_locations"
1520 fb
= get_framebuffer_target(ctx
, target
);
1522 _mesa_error(ctx
, GL_INVALID_ENUM
,
1523 "glFramebufferParameteri(target=0x%x)", target
);
1527 framebuffer_parameteri(ctx
, fb
, pname
, param
, "glFramebufferParameteri");
1531 validate_get_framebuffer_parameteriv_pname(struct gl_context
*ctx
,
1532 struct gl_framebuffer
*fb
,
1533 GLuint pname
, const char *func
)
1535 bool cannot_be_winsys_fbo
= true;
1538 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1540 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1541 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1543 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1544 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1548 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1549 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1550 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1551 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1553 case GL_DOUBLEBUFFER
:
1554 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1555 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1557 case GL_SAMPLE_BUFFERS
:
1559 /* From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries:
1561 * "An INVALID_OPERATION error is generated by GetFramebufferParameteriv
1562 * if the default framebuffer is bound to target and pname is not one
1563 * of the accepted values from table 23.73, other than
1566 * For OpenGL ES, using default framebuffer raises INVALID_OPERATION
1569 cannot_be_winsys_fbo
= !_mesa_is_desktop_gl(ctx
);
1571 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1572 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1573 if (!ctx
->Extensions
.ARB_sample_locations
)
1574 goto invalid_pname_enum
;
1575 cannot_be_winsys_fbo
= false;
1578 goto invalid_pname_enum
;
1581 if (cannot_be_winsys_fbo
&& _mesa_is_winsys_fbo(fb
)) {
1582 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1583 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1590 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1595 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1596 GLenum pname
, GLint
*params
, const char *func
)
1598 if (!validate_get_framebuffer_parameteriv_pname(ctx
, fb
, pname
, func
))
1602 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1603 *params
= fb
->DefaultGeometry
.Width
;
1605 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1606 *params
= fb
->DefaultGeometry
.Height
;
1608 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1609 *params
= fb
->DefaultGeometry
.Layers
;
1611 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1612 *params
= fb
->DefaultGeometry
.NumSamples
;
1614 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1615 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1617 case GL_DOUBLEBUFFER
:
1618 *params
= fb
->Visual
.doubleBufferMode
;
1620 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1621 *params
= _mesa_get_color_read_format(ctx
, fb
, func
);
1623 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1624 *params
= _mesa_get_color_read_type(ctx
, fb
, func
);
1627 *params
= _mesa_geometric_samples(fb
);
1629 case GL_SAMPLE_BUFFERS
:
1630 *params
= _mesa_geometric_samples(fb
) > 0;
1633 *params
= fb
->Visual
.stereoMode
;
1635 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1636 *params
= fb
->ProgrammableSampleLocations
;
1638 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1639 *params
= fb
->SampleLocationPixelGrid
;
1645 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1647 GET_CURRENT_CONTEXT(ctx
);
1648 struct gl_framebuffer
*fb
;
1650 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1651 !ctx
->Extensions
.ARB_sample_locations
) {
1652 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1653 "glGetFramebufferParameteriv not supported "
1654 "(neither ARB_framebuffer_no_attachments nor ARB_sample_locations"
1659 fb
= get_framebuffer_target(ctx
, target
);
1661 _mesa_error(ctx
, GL_INVALID_ENUM
,
1662 "glGetFramebufferParameteriv(target=0x%x)", target
);
1666 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1667 "glGetFramebufferParameteriv");
1672 * Remove the specified renderbuffer or texture from any attachment point in
1676 * \c true if the renderbuffer was detached from an attachment point. \c
1680 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1681 struct gl_framebuffer
*fb
,
1685 bool progress
= false;
1687 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1688 if (fb
->Attachment
[i
].Texture
== att
1689 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1690 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1695 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1696 * Completeness," of the OpenGL 3.1 spec says:
1698 * "Performing any of the following actions may change whether the
1699 * framebuffer is considered complete or incomplete:
1703 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1704 * containing an image that is attached to a framebuffer object
1705 * that is bound to the framebuffer."
1708 invalidate_framebuffer(fb
);
1715 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1718 GET_CURRENT_CONTEXT(ctx
);
1721 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1725 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1727 for (i
= 0; i
< n
; i
++) {
1728 if (renderbuffers
[i
] > 0) {
1729 struct gl_renderbuffer
*rb
;
1730 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1732 /* check if deleting currently bound renderbuffer object */
1733 if (rb
== ctx
->CurrentRenderbuffer
) {
1735 assert(rb
->RefCount
>= 2);
1736 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1739 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1740 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1741 * of the OpenGL 3.1 spec says:
1743 * "If a renderbuffer object is deleted while its image is
1744 * attached to one or more attachment points in the currently
1745 * bound framebuffer, then it is as if FramebufferRenderbuffer
1746 * had been called, with a renderbuffer of 0, for each
1747 * attachment point to which this image was attached in the
1748 * currently bound framebuffer. In other words, this
1749 * renderbuffer image is first detached from all attachment
1750 * points in the currently bound framebuffer. Note that the
1751 * renderbuffer image is specifically not detached from any
1752 * non-bound framebuffers. Detaching the image from any
1753 * non-bound framebuffers is the responsibility of the
1756 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1757 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1759 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1760 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1761 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1764 /* Remove from hash table immediately, to free the ID.
1765 * But the object will not be freed until it's no longer
1766 * referenced anywhere else.
1768 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1770 if (rb
!= &DummyRenderbuffer
) {
1771 /* no longer referenced by hash table */
1772 _mesa_reference_renderbuffer(&rb
, NULL
);
1780 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1783 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1790 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1792 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1794 for (i
= 0; i
< n
; i
++) {
1795 GLuint name
= first
+ i
;
1796 renderbuffers
[i
] = name
;
1799 allocate_renderbuffer_locked(ctx
, name
, func
);
1801 /* insert a dummy renderbuffer into the hash table */
1802 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1803 &DummyRenderbuffer
);
1807 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1812 create_render_buffers_err(struct gl_context
*ctx
, GLsizei n
,
1813 GLuint
*renderbuffers
, bool dsa
)
1815 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1818 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1822 create_render_buffers(ctx
, n
, renderbuffers
, dsa
);
1827 _mesa_GenRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1829 GET_CURRENT_CONTEXT(ctx
);
1830 create_render_buffers(ctx
, n
, renderbuffers
, false);
1835 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1837 GET_CURRENT_CONTEXT(ctx
);
1838 create_render_buffers_err(ctx
, n
, renderbuffers
, false);
1843 _mesa_CreateRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1845 GET_CURRENT_CONTEXT(ctx
);
1846 create_render_buffers(ctx
, n
, renderbuffers
, true);
1851 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1853 GET_CURRENT_CONTEXT(ctx
);
1854 create_render_buffers_err(ctx
, n
, renderbuffers
, true);
1859 * Given an internal format token for a render buffer, return the
1860 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1861 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1862 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1864 * This is similar to _mesa_base_tex_format() but the set of valid
1865 * internal formats is different.
1867 * Note that even if a format is determined to be legal here, validation
1868 * of the FBO may fail if the format is not supported by the driver/GPU.
1870 * \param internalFormat as passed to glRenderbufferStorage()
1871 * \return the base internal format, or 0 if internalFormat is illegal
1874 _mesa_base_fbo_format(const struct gl_context
*ctx
, GLenum internalFormat
)
1877 * Notes: some formats such as alpha, luminance, etc. were added
1878 * with GL_ARB_framebuffer_object.
1880 switch (internalFormat
) {
1886 return (ctx
->API
== API_OPENGL_COMPAT
&&
1887 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
1891 case GL_LUMINANCE12
:
1892 case GL_LUMINANCE16
:
1893 return (ctx
->API
== API_OPENGL_COMPAT
&&
1894 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
1895 case GL_LUMINANCE_ALPHA
:
1896 case GL_LUMINANCE4_ALPHA4
:
1897 case GL_LUMINANCE6_ALPHA2
:
1898 case GL_LUMINANCE8_ALPHA8
:
1899 case GL_LUMINANCE12_ALPHA4
:
1900 case GL_LUMINANCE12_ALPHA12
:
1901 case GL_LUMINANCE16_ALPHA16
:
1902 return (ctx
->API
== API_OPENGL_COMPAT
&&
1903 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
1907 case GL_INTENSITY12
:
1908 case GL_INTENSITY16
:
1909 return (ctx
->API
== API_OPENGL_COMPAT
&&
1910 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
1920 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1922 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1931 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1933 case GL_SRGB8_ALPHA8_EXT
:
1934 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1935 case GL_STENCIL_INDEX
:
1936 case GL_STENCIL_INDEX1_EXT
:
1937 case GL_STENCIL_INDEX4_EXT
:
1938 case GL_STENCIL_INDEX16_EXT
:
1939 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1940 * OpenGL ES, but Mesa does not currently support them.
1942 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1943 case GL_STENCIL_INDEX8_EXT
:
1944 return GL_STENCIL_INDEX
;
1945 case GL_DEPTH_COMPONENT
:
1946 case GL_DEPTH_COMPONENT32
:
1947 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1948 case GL_DEPTH_COMPONENT16
:
1949 case GL_DEPTH_COMPONENT24
:
1950 return GL_DEPTH_COMPONENT
;
1951 case GL_DEPTH_STENCIL
:
1952 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
1953 case GL_DEPTH24_STENCIL8
:
1954 return GL_DEPTH_STENCIL
;
1955 case GL_DEPTH_COMPONENT32F
:
1956 return ctx
->Version
>= 30
1957 || (ctx
->API
== API_OPENGL_COMPAT
&&
1958 ctx
->Extensions
.ARB_depth_buffer_float
)
1959 ? GL_DEPTH_COMPONENT
: 0;
1960 case GL_DEPTH32F_STENCIL8
:
1961 return ctx
->Version
>= 30
1962 || (ctx
->API
== API_OPENGL_COMPAT
&&
1963 ctx
->Extensions
.ARB_depth_buffer_float
)
1964 ? GL_DEPTH_STENCIL
: 0;
1967 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1970 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1974 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1977 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1979 /* signed normalized texture formats */
1983 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1988 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1992 case GL_RGB16_SNORM
:
1993 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1996 case GL_RGBA8_SNORM
:
1997 case GL_RGBA16_SNORM
:
1998 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2000 case GL_ALPHA_SNORM
:
2001 case GL_ALPHA8_SNORM
:
2002 case GL_ALPHA16_SNORM
:
2003 return ctx
->API
== API_OPENGL_COMPAT
&&
2004 ctx
->Extensions
.EXT_texture_snorm
&&
2005 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2006 case GL_LUMINANCE_SNORM
:
2007 case GL_LUMINANCE8_SNORM
:
2008 case GL_LUMINANCE16_SNORM
:
2009 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2011 case GL_LUMINANCE_ALPHA_SNORM
:
2012 case GL_LUMINANCE8_ALPHA8_SNORM
:
2013 case GL_LUMINANCE16_ALPHA16_SNORM
:
2014 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2015 ? GL_LUMINANCE_ALPHA
: 0;
2016 case GL_INTENSITY_SNORM
:
2017 case GL_INTENSITY8_SNORM
:
2018 case GL_INTENSITY16_SNORM
:
2019 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2024 return ((_mesa_is_desktop_gl(ctx
) &&
2025 ctx
->Extensions
.ARB_texture_rg
&&
2026 ctx
->Extensions
.ARB_texture_float
) ||
2027 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2031 return ((_mesa_is_desktop_gl(ctx
) &&
2032 ctx
->Extensions
.ARB_texture_rg
&&
2033 ctx
->Extensions
.ARB_texture_float
) ||
2034 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2038 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
2042 return ((_mesa_is_desktop_gl(ctx
) &&
2043 ctx
->Extensions
.ARB_texture_float
) ||
2044 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2047 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_shared_exponent
)
2049 case GL_ALPHA16F_ARB
:
2050 case GL_ALPHA32F_ARB
:
2051 return ctx
->API
== API_OPENGL_COMPAT
&&
2052 ctx
->Extensions
.ARB_texture_float
&&
2053 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2054 case GL_LUMINANCE16F_ARB
:
2055 case GL_LUMINANCE32F_ARB
:
2056 return ctx
->API
== API_OPENGL_COMPAT
&&
2057 ctx
->Extensions
.ARB_texture_float
&&
2058 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2059 case GL_LUMINANCE_ALPHA16F_ARB
:
2060 case GL_LUMINANCE_ALPHA32F_ARB
:
2061 return ctx
->API
== API_OPENGL_COMPAT
&&
2062 ctx
->Extensions
.ARB_texture_float
&&
2063 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2064 case GL_INTENSITY16F_ARB
:
2065 case GL_INTENSITY32F_ARB
:
2066 return ctx
->API
== API_OPENGL_COMPAT
&&
2067 ctx
->Extensions
.ARB_texture_float
&&
2068 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2069 case GL_R11F_G11F_B10F
:
2070 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
2071 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2074 case GL_RGBA8UI_EXT
:
2075 case GL_RGBA16UI_EXT
:
2076 case GL_RGBA32UI_EXT
:
2078 case GL_RGBA16I_EXT
:
2079 case GL_RGBA32I_EXT
:
2080 return ctx
->Version
>= 30
2081 || (_mesa_is_desktop_gl(ctx
) &&
2082 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
2085 case GL_RGB16UI_EXT
:
2086 case GL_RGB32UI_EXT
:
2090 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
2098 return ctx
->Version
>= 30
2099 || (_mesa_is_desktop_gl(ctx
) &&
2100 ctx
->Extensions
.ARB_texture_rg
&&
2101 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
2109 return ctx
->Version
>= 30
2110 || (_mesa_is_desktop_gl(ctx
) &&
2111 ctx
->Extensions
.ARB_texture_rg
&&
2112 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
2114 case GL_INTENSITY8I_EXT
:
2115 case GL_INTENSITY8UI_EXT
:
2116 case GL_INTENSITY16I_EXT
:
2117 case GL_INTENSITY16UI_EXT
:
2118 case GL_INTENSITY32I_EXT
:
2119 case GL_INTENSITY32UI_EXT
:
2120 return ctx
->API
== API_OPENGL_COMPAT
&&
2121 ctx
->Extensions
.EXT_texture_integer
&&
2122 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2124 case GL_LUMINANCE8I_EXT
:
2125 case GL_LUMINANCE8UI_EXT
:
2126 case GL_LUMINANCE16I_EXT
:
2127 case GL_LUMINANCE16UI_EXT
:
2128 case GL_LUMINANCE32I_EXT
:
2129 case GL_LUMINANCE32UI_EXT
:
2130 return ctx
->API
== API_OPENGL_COMPAT
&&
2131 ctx
->Extensions
.EXT_texture_integer
&&
2132 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2134 case GL_LUMINANCE_ALPHA8I_EXT
:
2135 case GL_LUMINANCE_ALPHA8UI_EXT
:
2136 case GL_LUMINANCE_ALPHA16I_EXT
:
2137 case GL_LUMINANCE_ALPHA16UI_EXT
:
2138 case GL_LUMINANCE_ALPHA32I_EXT
:
2139 case GL_LUMINANCE_ALPHA32UI_EXT
:
2140 return ctx
->API
== API_OPENGL_COMPAT
&&
2141 ctx
->Extensions
.EXT_texture_integer
&&
2142 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2144 case GL_ALPHA8I_EXT
:
2145 case GL_ALPHA8UI_EXT
:
2146 case GL_ALPHA16I_EXT
:
2147 case GL_ALPHA16UI_EXT
:
2148 case GL_ALPHA32I_EXT
:
2149 case GL_ALPHA32UI_EXT
:
2150 return ctx
->API
== API_OPENGL_COMPAT
&&
2151 ctx
->Extensions
.EXT_texture_integer
&&
2152 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2155 return (_mesa_is_desktop_gl(ctx
) &&
2156 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
2157 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2160 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2169 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2172 invalidate_rb(GLuint key
, void *data
, void *userData
)
2174 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2175 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2177 /* If this is a user-created FBO */
2178 if (_mesa_is_user_fbo(fb
)) {
2180 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2181 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2182 if (att
->Type
== GL_RENDERBUFFER
&&
2183 att
->Renderbuffer
== rb
) {
2184 /* Mark fb status as indeterminate to force re-validation */
2193 /** sentinal value, see below */
2194 #define NO_SAMPLES 1000
2197 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2198 GLenum internalFormat
, GLsizei width
,
2199 GLsizei height
, GLsizei samples
)
2201 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2203 assert(baseFormat
!= 0);
2204 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2205 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2206 assert(samples
!= NO_SAMPLES
);
2208 assert(samples
> 0);
2209 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2210 internalFormat
, samples
) == GL_NO_ERROR
);
2213 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2215 if (rb
->InternalFormat
== internalFormat
&&
2216 rb
->Width
== (GLuint
) width
&&
2217 rb
->Height
== (GLuint
) height
&&
2218 rb
->NumSamples
== samples
) {
2219 /* no change in allocation needed */
2223 /* These MUST get set by the AllocStorage func */
2224 rb
->Format
= MESA_FORMAT_NONE
;
2225 rb
->NumSamples
= samples
;
2227 /* Now allocate the storage */
2228 assert(rb
->AllocStorage
);
2229 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2230 /* No error - check/set fields now */
2231 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2232 assert(rb
->Width
== (GLuint
) width
);
2233 assert(rb
->Height
== (GLuint
) height
);
2234 rb
->InternalFormat
= internalFormat
;
2235 rb
->_BaseFormat
= baseFormat
;
2236 assert(rb
->_BaseFormat
!= 0);
2239 /* Probably ran out of memory - clear the fields */
2242 rb
->Format
= MESA_FORMAT_NONE
;
2243 rb
->InternalFormat
= GL_NONE
;
2244 rb
->_BaseFormat
= GL_NONE
;
2248 /* Invalidate the framebuffers the renderbuffer is attached in. */
2249 if (rb
->AttachedAnytime
) {
2250 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2255 * Helper function used by renderbuffer_storage_direct() and
2256 * renderbuffer_storage_target().
2257 * samples will be NO_SAMPLES if called by a non-multisample function.
2260 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2261 GLenum internalFormat
, GLsizei width
,
2262 GLsizei height
, GLsizei samples
, const char *func
)
2265 GLenum sample_count_error
;
2267 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2268 if (baseFormat
== 0) {
2269 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2270 func
, _mesa_enum_to_string(internalFormat
));
2274 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2275 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2280 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2281 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2286 if (samples
== NO_SAMPLES
) {
2287 /* NumSamples == 0 indicates non-multisampling */
2291 /* check the sample count;
2292 * note: driver may choose to use more samples than what's requested
2294 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2295 internalFormat
, samples
);
2297 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2299 * "If a negative number is provided where an argument of type sizei or
2300 * sizeiptr is specified, the error INVALID VALUE is generated."
2303 sample_count_error
= GL_INVALID_VALUE
;
2306 if (sample_count_error
!= GL_NO_ERROR
) {
2307 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
2312 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
);
2316 * Helper function used by _mesa_NamedRenderbufferStorage*().
2317 * samples will be NO_SAMPLES if called by a non-multisample function.
2320 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2321 GLsizei width
, GLsizei height
, GLsizei samples
,
2324 GET_CURRENT_CONTEXT(ctx
);
2326 if (MESA_VERBOSE
& VERBOSE_API
) {
2327 if (samples
== NO_SAMPLES
)
2328 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2330 _mesa_enum_to_string(internalFormat
),
2333 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2335 _mesa_enum_to_string(internalFormat
),
2336 width
, height
, samples
);
2339 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2340 if (!rb
|| rb
== &DummyRenderbuffer
) {
2341 /* ID was reserved, but no real renderbuffer object made yet */
2342 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2343 func
, renderbuffer
);
2347 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
, func
);
2351 * Helper function used by _mesa_RenderbufferStorage() and
2352 * _mesa_RenderbufferStorageMultisample().
2353 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2356 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2357 GLsizei width
, GLsizei height
, GLsizei samples
,
2360 GET_CURRENT_CONTEXT(ctx
);
2362 if (MESA_VERBOSE
& VERBOSE_API
) {
2363 if (samples
== NO_SAMPLES
)
2364 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2366 _mesa_enum_to_string(target
),
2367 _mesa_enum_to_string(internalFormat
),
2370 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2372 _mesa_enum_to_string(target
),
2373 _mesa_enum_to_string(internalFormat
),
2374 width
, height
, samples
);
2377 if (target
!= GL_RENDERBUFFER_EXT
) {
2378 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2382 if (!ctx
->CurrentRenderbuffer
) {
2383 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2388 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2389 height
, samples
, func
);
2394 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2396 struct gl_renderbuffer
*rb
;
2397 GET_CURRENT_CONTEXT(ctx
);
2399 if (!ctx
->Extensions
.OES_EGL_image
) {
2400 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2401 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2405 if (target
!= GL_RENDERBUFFER
) {
2406 _mesa_error(ctx
, GL_INVALID_ENUM
,
2407 "EGLImageTargetRenderbufferStorageOES");
2411 rb
= ctx
->CurrentRenderbuffer
;
2413 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2414 "EGLImageTargetRenderbufferStorageOES");
2418 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2420 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2425 * Helper function for _mesa_GetRenderbufferParameteriv() and
2426 * _mesa_GetFramebufferAttachmentParameteriv()
2427 * We have to be careful to respect the base format. For example, if a
2428 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2429 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2430 * we need to return zero.
2433 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2435 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2436 return _mesa_get_format_bits(format
, pname
);
2444 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2445 GLsizei width
, GLsizei height
)
2447 /* GL_ARB_fbo says calling this function is equivalent to calling
2448 * glRenderbufferStorageMultisample() with samples=0. We pass in
2449 * a token value here just for error reporting purposes.
2451 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2452 NO_SAMPLES
, "glRenderbufferStorage");
2457 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2458 GLenum internalFormat
,
2459 GLsizei width
, GLsizei height
)
2461 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2462 samples
, "glRenderbufferStorageMultisample");
2467 * OpenGL ES version of glRenderBufferStorage.
2470 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2471 GLsizei width
, GLsizei height
)
2473 switch (internalFormat
) {
2475 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2476 /* choose a closest format */
2477 internalFormat
= GL_RGB5
;
2483 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0,
2484 "glRenderbufferStorageEXT");
2488 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2489 GLsizei width
, GLsizei height
)
2491 /* GL_ARB_fbo says calling this function is equivalent to calling
2492 * glRenderbufferStorageMultisample() with samples=0. We pass in
2493 * a token value here just for error reporting purposes.
2495 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2496 NO_SAMPLES
, "glNamedRenderbufferStorage");
2500 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2501 GLenum internalformat
,
2502 GLsizei width
, GLsizei height
)
2504 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2506 "glNamedRenderbufferStorageMultisample");
2511 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2512 struct gl_renderbuffer
*rb
, GLenum pname
,
2513 GLint
*params
, const char *func
)
2515 /* No need to flush here since we're just quering state which is
2516 * not effected by rendering.
2520 case GL_RENDERBUFFER_WIDTH_EXT
:
2521 *params
= rb
->Width
;
2523 case GL_RENDERBUFFER_HEIGHT_EXT
:
2524 *params
= rb
->Height
;
2526 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2527 *params
= rb
->InternalFormat
;
2529 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2530 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2531 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2532 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2533 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2534 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2535 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2537 case GL_RENDERBUFFER_SAMPLES
:
2538 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2539 || _mesa_is_gles3(ctx
)) {
2540 *params
= rb
->NumSamples
;
2545 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2546 _mesa_enum_to_string(pname
));
2553 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2555 GET_CURRENT_CONTEXT(ctx
);
2557 if (target
!= GL_RENDERBUFFER_EXT
) {
2558 _mesa_error(ctx
, GL_INVALID_ENUM
,
2559 "glGetRenderbufferParameterivEXT(target)");
2563 if (!ctx
->CurrentRenderbuffer
) {
2564 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2565 "(no renderbuffer bound)");
2569 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2570 params
, "glGetRenderbufferParameteriv");
2575 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2578 GET_CURRENT_CONTEXT(ctx
);
2580 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2581 if (!rb
|| rb
== &DummyRenderbuffer
) {
2582 /* ID was reserved, but no real renderbuffer object made yet */
2583 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2584 "(invalid renderbuffer %i)", renderbuffer
);
2588 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2589 "glGetNamedRenderbufferParameteriv");
2593 GLboolean GLAPIENTRY
2594 _mesa_IsFramebuffer(GLuint framebuffer
)
2596 GET_CURRENT_CONTEXT(ctx
);
2597 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2599 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2600 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2608 * Check if any of the attachments of the given framebuffer are textures
2609 * (render to texture). Call ctx->Driver.RenderTexture() for such
2613 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2616 assert(ctx
->Driver
.RenderTexture
);
2618 if (_mesa_is_winsys_fbo(fb
))
2619 return; /* can't render to texture with winsys framebuffers */
2621 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2622 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2623 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2624 && driver_RenderTexture_is_safe(att
)) {
2625 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2632 * Examine all the framebuffer's attachments to see if any are textures.
2633 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2634 * notify the device driver that the texture image may have changed.
2637 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2639 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2640 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2643 if (ctx
->Driver
.FinishRenderTexture
) {
2645 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2646 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2647 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2648 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2649 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2657 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2659 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2660 GLboolean bindReadBuf
, bindDrawBuf
;
2661 GET_CURRENT_CONTEXT(ctx
);
2664 case GL_DRAW_FRAMEBUFFER_EXT
:
2665 bindDrawBuf
= GL_TRUE
;
2666 bindReadBuf
= GL_FALSE
;
2668 case GL_READ_FRAMEBUFFER_EXT
:
2669 bindDrawBuf
= GL_FALSE
;
2670 bindReadBuf
= GL_TRUE
;
2672 case GL_FRAMEBUFFER_EXT
:
2673 bindDrawBuf
= GL_TRUE
;
2674 bindReadBuf
= GL_TRUE
;
2677 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2682 /* Binding a user-created framebuffer object */
2683 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2684 if (newDrawFb
== &DummyFramebuffer
) {
2685 /* ID was reserved, but no real framebuffer object made yet */
2688 else if (!newDrawFb
&& !allow_user_names
) {
2689 /* All FBO IDs must be Gen'd */
2690 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2695 /* create new framebuffer object */
2696 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2698 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2701 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2703 newReadFb
= newDrawFb
;
2706 /* Binding the window system framebuffer (which was originally set
2707 * with MakeCurrent).
2709 newDrawFb
= ctx
->WinSysDrawBuffer
;
2710 newReadFb
= ctx
->WinSysReadBuffer
;
2713 _mesa_bind_framebuffers(ctx
,
2714 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2715 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2719 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2720 struct gl_framebuffer
*newDrawFb
,
2721 struct gl_framebuffer
*newReadFb
)
2723 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
2724 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
2725 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
2726 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
2729 assert(newDrawFb
!= &DummyFramebuffer
);
2732 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2734 * We also check if we're beginning and/or ending render-to-texture.
2735 * When a framebuffer with texture attachments is unbound, call
2736 * ctx->Driver.FinishRenderTexture().
2737 * When a framebuffer with texture attachments is bound, call
2738 * ctx->Driver.RenderTexture().
2740 * Note that if the ReadBuffer has texture attachments we don't consider
2741 * that a render-to-texture case.
2744 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2746 /* check if old readbuffer was render-to-texture */
2747 check_end_texture_render(ctx
, oldReadFb
);
2749 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2753 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2754 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
2756 /* check if old framebuffer had any texture attachments */
2758 check_end_texture_render(ctx
, oldDrawFb
);
2760 /* check if newly bound framebuffer has any texture attachments */
2761 check_begin_texture_render(ctx
, newDrawFb
);
2763 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2766 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2767 /* The few classic drivers that actually hook this function really only
2768 * want to know if the draw framebuffer changed.
2770 ctx
->Driver
.BindFramebuffer(ctx
,
2771 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
2772 newDrawFb
, newReadFb
);
2777 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2779 GET_CURRENT_CONTEXT(ctx
);
2781 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2782 * point, but they allow the use of user-generated names.
2784 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2789 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2791 /* This function should not be in the dispatch table for core profile /
2792 * OpenGL 3.1, so execution should never get here in those cases -- no
2793 * need for an explicit test.
2795 bind_framebuffer(target
, framebuffer
, true);
2800 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2803 GET_CURRENT_CONTEXT(ctx
);
2806 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
2810 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2812 for (i
= 0; i
< n
; i
++) {
2813 if (framebuffers
[i
] > 0) {
2814 struct gl_framebuffer
*fb
;
2815 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2817 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2819 /* check if deleting currently bound framebuffer object */
2820 if (fb
== ctx
->DrawBuffer
) {
2822 assert(fb
->RefCount
>= 2);
2823 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2825 if (fb
== ctx
->ReadBuffer
) {
2827 assert(fb
->RefCount
>= 2);
2828 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2831 /* remove from hash table immediately, to free the ID */
2832 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2834 if (fb
!= &DummyFramebuffer
) {
2835 /* But the object will not be freed until it's no longer
2836 * bound in any context.
2838 _mesa_reference_framebuffer(&fb
, NULL
);
2847 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2848 * It is not exposed to the rest of Mesa to encourage the use of
2849 * nameless buffers in driver internals.
2852 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
2854 GET_CURRENT_CONTEXT(ctx
);
2857 struct gl_framebuffer
*fb
;
2859 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
2862 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
2869 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
2871 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2873 for (i
= 0; i
< n
; i
++) {
2874 GLuint name
= first
+ i
;
2875 framebuffers
[i
] = name
;
2878 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
2880 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2881 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
2886 fb
= &DummyFramebuffer
;
2888 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
2891 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2896 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2898 create_framebuffers(n
, framebuffers
, false);
2903 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2905 create_framebuffers(n
, framebuffers
, true);
2910 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
2911 struct gl_framebuffer
*buffer
)
2913 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2915 if (_mesa_is_winsys_fbo(buffer
)) {
2916 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2917 if (buffer
!= &IncompleteFramebuffer
) {
2918 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2920 return GL_FRAMEBUFFER_UNDEFINED
;
2924 /* No need to flush here */
2926 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2927 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2930 return buffer
->_Status
;
2935 _mesa_CheckFramebufferStatus_no_error(GLenum target
)
2937 GET_CURRENT_CONTEXT(ctx
);
2939 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
2940 return _mesa_check_framebuffer_status(ctx
, fb
);
2945 _mesa_CheckFramebufferStatus(GLenum target
)
2947 struct gl_framebuffer
*fb
;
2948 GET_CURRENT_CONTEXT(ctx
);
2950 if (MESA_VERBOSE
& VERBOSE_API
)
2951 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2952 _mesa_enum_to_string(target
));
2954 fb
= get_framebuffer_target(ctx
, target
);
2956 _mesa_error(ctx
, GL_INVALID_ENUM
,
2957 "glCheckFramebufferStatus(invalid target %s)",
2958 _mesa_enum_to_string(target
));
2962 return _mesa_check_framebuffer_status(ctx
, fb
);
2967 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
2969 struct gl_framebuffer
*fb
;
2970 GET_CURRENT_CONTEXT(ctx
);
2972 /* Validate the target (for conformance's sake) and grab a reference to the
2973 * default framebuffer in case framebuffer = 0.
2974 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
2975 * (30.10.2014, PDF page 336) says:
2976 * "If framebuffer is zero, then the status of the default read or
2977 * draw framebuffer (as determined by target) is returned."
2980 case GL_DRAW_FRAMEBUFFER
:
2981 case GL_FRAMEBUFFER
:
2982 fb
= ctx
->WinSysDrawBuffer
;
2984 case GL_READ_FRAMEBUFFER
:
2985 fb
= ctx
->WinSysReadBuffer
;
2988 _mesa_error(ctx
, GL_INVALID_ENUM
,
2989 "glCheckNamedFramebufferStatus(invalid target %s)",
2990 _mesa_enum_to_string(target
));
2995 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
2996 "glCheckNamedFramebufferStatus");
3001 return _mesa_check_framebuffer_status(ctx
, fb
);
3006 * Replicate the src attachment point. Used by framebuffer_texture() when
3007 * the same texture is attached at GL_DEPTH_ATTACHMENT and
3008 * GL_STENCIL_ATTACHMENT.
3011 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
3012 gl_buffer_index dst
,
3013 gl_buffer_index src
)
3015 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
3016 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
3018 assert(src_att
->Texture
!= NULL
);
3019 assert(src_att
->Renderbuffer
!= NULL
);
3021 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
3022 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
3023 dst_att
->Type
= src_att
->Type
;
3024 dst_att
->Complete
= src_att
->Complete
;
3025 dst_att
->TextureLevel
= src_att
->TextureLevel
;
3026 dst_att
->CubeMapFace
= src_att
->CubeMapFace
;
3027 dst_att
->Zoffset
= src_att
->Zoffset
;
3028 dst_att
->Layered
= src_att
->Layered
;
3032 static struct gl_texture_object
*
3033 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
)
3038 return _mesa_lookup_texture(ctx
, texture
);
3043 * Common code called by gl*FramebufferTexture*() to retrieve the correct
3044 * texture object pointer.
3046 * \param texObj where the pointer to the texture object is returned. Note
3047 * that a successful call may return texObj = NULL.
3049 * \return true if no errors, false if errors
3052 get_texture_for_framebuffer_err(struct gl_context
*ctx
, GLuint texture
,
3053 bool layered
, const char *caller
,
3054 struct gl_texture_object
**texObj
)
3056 *texObj
= NULL
; /* This will get returned if texture = 0. */
3061 *texObj
= _mesa_lookup_texture(ctx
, texture
);
3062 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
3063 /* Can't render to a non-existent texture object.
3065 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
3066 * Managing Framebuffer Objects specifies a different error
3067 * depending upon the calling function (PDF pages 325-328).
3068 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
3069 * value, while the other commands throw invalid operation (where
3070 * layered = GL_FALSE).
3072 const GLenum error
= layered
? GL_INVALID_VALUE
:
3073 GL_INVALID_OPERATION
;
3074 _mesa_error(ctx
, error
,
3075 "%s(non-existent texture %u)", caller
, texture
);
3084 * Common code called by gl*FramebufferTexture() to verify the texture target
3085 * and decide whether or not the attachment should truly be considered
3088 * \param layered true if attachment should be considered layered, false if
3091 * \return true if no errors, false if errors
3094 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
3095 const char *caller
, GLboolean
*layered
)
3101 case GL_TEXTURE_1D_ARRAY_EXT
:
3102 case GL_TEXTURE_2D_ARRAY_EXT
:
3103 case GL_TEXTURE_CUBE_MAP
:
3104 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3105 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3109 case GL_TEXTURE_RECTANGLE
:
3110 case GL_TEXTURE_2D_MULTISAMPLE
:
3111 /* These texture types are valid to pass to
3112 * glFramebufferTexture(), but since they aren't layered, it
3113 * is equivalent to calling glFramebufferTexture{1D,2D}().
3115 *layered
= GL_FALSE
;
3119 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3120 "%s(invalid texture target %s)", caller
,
3121 _mesa_enum_to_string(target
));
3127 * Common code called by gl*FramebufferTextureLayer() to verify the texture
3130 * \return true if no errors, false if errors
3133 check_texture_target(struct gl_context
*ctx
, GLenum target
,
3136 /* We're being called by glFramebufferTextureLayer().
3137 * The only legal texture types for that function are 3D,
3138 * cube-map, and 1D/2D/cube-map array textures.
3140 * We don't need to check for GL_ARB_texture_cube_map_array because the
3141 * application wouldn't have been able to create a texture with a
3142 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
3146 case GL_TEXTURE_1D_ARRAY
:
3147 case GL_TEXTURE_2D_ARRAY
:
3148 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3149 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3151 case GL_TEXTURE_CUBE_MAP
:
3152 /* We don't need to check the extension (GL_ARB_direct_state_access) or
3153 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
3154 * enabled in core profile. This can be called from
3155 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
3156 * so we do have to check the profile.
3158 return ctx
->API
== API_OPENGL_CORE
;
3161 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3162 "%s(invalid texture target %s)", caller
,
3163 _mesa_enum_to_string(target
));
3169 * Common code called by glFramebufferTexture*D() to verify the texture
3172 * \return true if no errors, false if errors
3175 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
3176 GLenum textarget
, const char *caller
)
3180 switch (textarget
) {
3184 case GL_TEXTURE_1D_ARRAY
:
3185 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3190 case GL_TEXTURE_2D_ARRAY
:
3191 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3192 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3194 case GL_TEXTURE_2D_MULTISAMPLE
:
3195 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3197 !ctx
->Extensions
.ARB_texture_multisample
||
3198 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3200 case GL_TEXTURE_RECTANGLE
:
3201 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3202 !ctx
->Extensions
.NV_texture_rectangle
;
3204 case GL_TEXTURE_CUBE_MAP
:
3205 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3208 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3209 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3210 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3211 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3212 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3213 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3214 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3220 _mesa_error(ctx
, GL_INVALID_ENUM
,
3221 "%s(unknown textarget 0x%x)", caller
, textarget
);
3226 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3227 "%s(invalid textarget %s)",
3228 caller
, _mesa_enum_to_string(textarget
));
3232 /* Make sure textarget is consistent with the texture's type */
3233 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3234 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3237 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3238 "%s(mismatched texture target)", caller
);
3247 * Common code called by gl*FramebufferTextureLayer() and
3248 * glFramebufferTexture3D() to validate the layer.
3250 * \return true if no errors, false if errors
3253 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3256 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3259 * "An INVALID_VALUE error is generated if texture is non-zero
3260 * and layer is negative."
3263 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(layer %d < 0)", caller
, layer
);
3267 if (target
== GL_TEXTURE_3D
) {
3268 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3269 if (layer
>= maxSize
) {
3270 _mesa_error(ctx
, GL_INVALID_VALUE
,
3271 "%s(invalid layer %u)", caller
, layer
);
3275 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3276 (target
== GL_TEXTURE_2D_ARRAY
) ||
3277 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3278 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3279 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3280 _mesa_error(ctx
, GL_INVALID_VALUE
,
3281 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3286 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3288 _mesa_error(ctx
, GL_INVALID_VALUE
,
3289 "%s(layer %u >= 6)", caller
, layer
);
3299 * Common code called by all gl*FramebufferTexture*() entry points to verify
3302 * \return true if no errors, false if errors
3305 check_level(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
3306 GLenum target
, GLint level
, const char *caller
)
3308 /* Section 9.2.8 of the OpenGL 4.6 specification says:
3310 * "If texture refers to an immutable-format texture, level must be
3311 * greater than or equal to zero and smaller than the value of
3312 * TEXTURE_VIEW_NUM_LEVELS for texture."
3314 const int max_levels
= texObj
->Immutable
? texObj
->ImmutableLevels
:
3315 _mesa_max_texture_levels(ctx
, target
);
3317 if (level
< 0 || level
>= max_levels
) {
3318 _mesa_error(ctx
, GL_INVALID_VALUE
,
3319 "%s(invalid level %d)", caller
, level
);
3327 struct gl_renderbuffer_attachment
*
3328 _mesa_get_and_validate_attachment(struct gl_context
*ctx
,
3329 struct gl_framebuffer
*fb
,
3330 GLenum attachment
, const char *caller
)
3332 /* The window-system framebuffer object is immutable */
3333 if (_mesa_is_winsys_fbo(fb
)) {
3334 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3339 /* Not a hash lookup, so we can afford to get the attachment here. */
3340 bool is_color_attachment
;
3341 struct gl_renderbuffer_attachment
*att
=
3342 get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3344 if (is_color_attachment
) {
3345 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3346 "%s(invalid color attachment %s)", caller
,
3347 _mesa_enum_to_string(attachment
));
3349 _mesa_error(ctx
, GL_INVALID_ENUM
,
3350 "%s(invalid attachment %s)", caller
,
3351 _mesa_enum_to_string(attachment
));
3361 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3363 struct gl_renderbuffer_attachment
*att
,
3364 struct gl_texture_object
*texObj
, GLenum textarget
,
3365 GLint level
, GLuint layer
, GLboolean layered
)
3367 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3369 simple_mtx_lock(&fb
->Mutex
);
3371 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3372 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3373 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3374 _mesa_tex_target_to_face(textarget
) ==
3375 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3376 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3377 /* The texture object is already attached to the stencil attachment
3378 * point. Don't create a new renderbuffer; just reuse the stencil
3379 * attachment's. This is required to prevent a GL error in
3380 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3382 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3384 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3385 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3386 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3387 _mesa_tex_target_to_face(textarget
) ==
3388 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3389 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3390 /* As above, but with depth and stencil transposed. */
3391 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3394 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3395 level
, layer
, layered
);
3397 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3398 /* Above we created a new renderbuffer and attached it to the
3399 * depth attachment point. Now attach it to the stencil attachment
3402 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3403 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3408 /* Set the render-to-texture flag. We'll check this flag in
3409 * glTexImage() and friends to determine if we need to revalidate
3410 * any FBOs that might be rendering into this texture.
3411 * This flag never gets cleared since it's non-trivial to determine
3412 * when all FBOs might be done rendering to this texture. That's OK
3413 * though since it's uncommon to render to a texture then repeatedly
3414 * call glTexImage() to change images in the texture.
3416 texObj
->_RenderToTexture
= GL_TRUE
;
3419 remove_attachment(ctx
, att
);
3420 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3421 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3422 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3426 invalidate_framebuffer(fb
);
3428 simple_mtx_unlock(&fb
->Mutex
);
3433 framebuffer_texture_with_dims_no_error(GLenum target
, GLenum attachment
,
3434 GLenum textarget
, GLuint texture
,
3435 GLint level
, GLint layer
)
3437 GET_CURRENT_CONTEXT(ctx
);
3439 /* Get the framebuffer object */
3440 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3442 /* Get the texture object */
3443 struct gl_texture_object
*texObj
=
3444 get_texture_for_framebuffer(ctx
, texture
);
3446 struct gl_renderbuffer_attachment
*att
=
3447 get_attachment(ctx
, fb
, attachment
, NULL
);
3449 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3450 level
, layer
, GL_FALSE
);
3455 framebuffer_texture_with_dims(int dims
, GLenum target
,
3456 GLenum attachment
, GLenum textarget
,
3457 GLuint texture
, GLint level
, GLint layer
,
3460 GET_CURRENT_CONTEXT(ctx
);
3461 struct gl_framebuffer
*fb
;
3462 struct gl_texture_object
*texObj
;
3464 /* Get the framebuffer object */
3465 fb
= get_framebuffer_target(ctx
, target
);
3467 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3468 _mesa_enum_to_string(target
));
3472 /* Get the texture object */
3473 if (!get_texture_for_framebuffer_err(ctx
, texture
, false, caller
, &texObj
))
3477 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3480 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3483 if (!check_level(ctx
, texObj
, textarget
, level
, caller
))
3487 struct gl_renderbuffer_attachment
*att
=
3488 _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, caller
);
3492 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3493 level
, layer
, GL_FALSE
);
3498 _mesa_FramebufferTexture1D_no_error(GLenum target
, GLenum attachment
,
3499 GLenum textarget
, GLuint texture
,
3502 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3508 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3509 GLenum textarget
, GLuint texture
, GLint level
)
3511 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3512 level
, 0, "glFramebufferTexture1D");
3517 _mesa_FramebufferTexture2D_no_error(GLenum target
, GLenum attachment
,
3518 GLenum textarget
, GLuint texture
,
3521 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3527 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3528 GLenum textarget
, GLuint texture
, GLint level
)
3530 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3531 level
, 0, "glFramebufferTexture2D");
3536 _mesa_FramebufferTexture3D_no_error(GLenum target
, GLenum attachment
,
3537 GLenum textarget
, GLuint texture
,
3538 GLint level
, GLint layer
)
3540 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3541 texture
, level
, layer
);
3546 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3547 GLenum textarget
, GLuint texture
,
3548 GLint level
, GLint layer
)
3550 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3551 level
, layer
, "glFramebufferTexture3D");
3555 static ALWAYS_INLINE
void
3556 frame_buffer_texture(GLuint framebuffer
, GLenum target
,
3557 GLenum attachment
, GLuint texture
,
3558 GLint level
, GLint layer
, const char *func
,
3559 bool dsa
, bool no_error
, bool check_layered
)
3561 GET_CURRENT_CONTEXT(ctx
);
3562 GLboolean layered
= GL_FALSE
;
3564 if (!no_error
&& check_layered
) {
3565 if (!_mesa_has_geometry_shaders(ctx
)) {
3566 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3567 "unsupported function (%s) called", func
);
3572 /* Get the framebuffer object */
3573 struct gl_framebuffer
*fb
;
3576 fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3578 fb
= get_framebuffer_target(ctx
, target
);
3582 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3586 fb
= get_framebuffer_target(ctx
, target
);
3588 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)",
3589 func
, _mesa_enum_to_string(target
));
3595 /* Get the texture object and framebuffer attachment*/
3596 struct gl_renderbuffer_attachment
*att
;
3597 struct gl_texture_object
*texObj
;
3599 texObj
= get_texture_for_framebuffer(ctx
, texture
);
3600 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
3602 if (!get_texture_for_framebuffer_err(ctx
, texture
, check_layered
, func
,
3606 att
= _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, func
);
3611 GLenum textarget
= 0;
3613 if (check_layered
) {
3614 /* We do this regardless of no_error because this sets layered */
3615 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3621 if (!check_layered
) {
3622 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3625 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3629 if (!check_level(ctx
, texObj
, texObj
->Target
, level
, func
))
3633 if (!check_layered
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3634 assert(layer
>= 0 && layer
< 6);
3635 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3640 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3641 level
, layer
, layered
);
3645 _mesa_FramebufferTextureLayer_no_error(GLenum target
, GLenum attachment
,
3646 GLuint texture
, GLint level
,
3649 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3650 "glFramebufferTextureLayer", false, true, false);
3655 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3656 GLuint texture
, GLint level
, GLint layer
)
3658 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3659 "glFramebufferTextureLayer", false, false, false);
3664 _mesa_NamedFramebufferTextureLayer_no_error(GLuint framebuffer
,
3666 GLuint texture
, GLint level
,
3669 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3670 "glNamedFramebufferTextureLayer", true, true, false);
3675 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3676 GLuint texture
, GLint level
, GLint layer
)
3678 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3679 "glNamedFramebufferTextureLayer", true, false, false);
3684 _mesa_FramebufferTexture_no_error(GLenum target
, GLenum attachment
,
3685 GLuint texture
, GLint level
)
3687 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3688 "glFramebufferTexture", false, true, true);
3693 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3694 GLuint texture
, GLint level
)
3696 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3697 "glFramebufferTexture", false, false, true);
3701 _mesa_NamedFramebufferTexture_no_error(GLuint framebuffer
, GLenum attachment
,
3702 GLuint texture
, GLint level
)
3704 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3705 "glNamedFramebufferTexture", true, true, true);
3710 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3711 GLuint texture
, GLint level
)
3713 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3714 "glNamedFramebufferTexture", true, false, true);
3719 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3720 struct gl_framebuffer
*fb
,
3722 struct gl_renderbuffer
*rb
)
3724 assert(!_mesa_is_winsys_fbo(fb
));
3726 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3728 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3729 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3731 /* Some subsequent GL commands may depend on the framebuffer's visual
3732 * after the binding is updated. Update visual info now.
3734 _mesa_update_framebuffer_visual(ctx
, fb
);
3737 static ALWAYS_INLINE
void
3738 framebuffer_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3739 GLenum attachment
, GLenum renderbuffertarget
,
3740 GLuint renderbuffer
, const char *func
, bool no_error
)
3742 struct gl_renderbuffer_attachment
*att
;
3743 struct gl_renderbuffer
*rb
;
3744 bool is_color_attachment
;
3746 if (!no_error
&& renderbuffertarget
!= GL_RENDERBUFFER
) {
3747 _mesa_error(ctx
, GL_INVALID_ENUM
,
3748 "%s(renderbuffertarget is not GL_RENDERBUFFER)", func
);
3754 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
, func
);
3758 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
3761 /* remove renderbuffer attachment */
3766 if (_mesa_is_winsys_fbo(fb
)) {
3767 /* Can't attach new renderbuffers to a window system framebuffer */
3768 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3769 "%s(window-system framebuffer)", func
);
3773 att
= get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3776 * From OpenGL 4.5 spec, section 9.2.7 "Attaching Renderbuffer Images
3777 * to a Framebuffer":
3779 * "An INVALID_OPERATION error is generated if attachment is
3780 * COLOR_- ATTACHMENTm where m is greater than or equal to the
3781 * value of MAX_COLOR_- ATTACHMENTS ."
3783 * If we are at this point, is because the attachment is not valid, so
3784 * if is_color_attachment is true, is because of the previous reason.
3786 if (is_color_attachment
) {
3787 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3788 "%s(invalid color attachment %s)", func
,
3789 _mesa_enum_to_string(attachment
));
3791 _mesa_error(ctx
, GL_INVALID_ENUM
,
3792 "%s(invalid attachment %s)", func
,
3793 _mesa_enum_to_string(attachment
));
3799 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3800 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3801 /* make sure the renderbuffer is a depth/stencil format */
3802 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3803 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3804 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3805 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3811 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3815 framebuffer_renderbuffer_error(struct gl_context
*ctx
,
3816 struct gl_framebuffer
*fb
, GLenum attachment
,
3817 GLenum renderbuffertarget
,
3818 GLuint renderbuffer
, const char *func
)
3820 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3821 renderbuffer
, func
, false);
3825 framebuffer_renderbuffer_no_error(struct gl_context
*ctx
,
3826 struct gl_framebuffer
*fb
, GLenum attachment
,
3827 GLenum renderbuffertarget
,
3828 GLuint renderbuffer
, const char *func
)
3830 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3831 renderbuffer
, func
, true);
3835 _mesa_FramebufferRenderbuffer_no_error(GLenum target
, GLenum attachment
,
3836 GLenum renderbuffertarget
,
3837 GLuint renderbuffer
)
3839 GET_CURRENT_CONTEXT(ctx
);
3841 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3842 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3843 renderbuffer
, "glFramebufferRenderbuffer");
3847 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3848 GLenum renderbuffertarget
,
3849 GLuint renderbuffer
)
3851 struct gl_framebuffer
*fb
;
3852 GET_CURRENT_CONTEXT(ctx
);
3854 fb
= get_framebuffer_target(ctx
, target
);
3856 _mesa_error(ctx
, GL_INVALID_ENUM
,
3857 "glFramebufferRenderbuffer(invalid target %s)",
3858 _mesa_enum_to_string(target
));
3862 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
3863 renderbuffer
, "glFramebufferRenderbuffer");
3867 _mesa_NamedFramebufferRenderbuffer_no_error(GLuint framebuffer
,
3869 GLenum renderbuffertarget
,
3870 GLuint renderbuffer
)
3872 GET_CURRENT_CONTEXT(ctx
);
3874 struct gl_framebuffer
*fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3875 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3877 "glNamedFramebufferRenderbuffer");
3881 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
3882 GLenum renderbuffertarget
,
3883 GLuint renderbuffer
)
3885 struct gl_framebuffer
*fb
;
3886 GET_CURRENT_CONTEXT(ctx
);
3888 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3889 "glNamedFramebufferRenderbuffer");
3893 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
3895 "glNamedFramebufferRenderbuffer");
3900 get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
3901 struct gl_framebuffer
*buffer
,
3902 GLenum attachment
, GLenum pname
,
3903 GLint
*params
, const char *caller
)
3905 const struct gl_renderbuffer_attachment
*att
;
3906 bool is_color_attachment
= false;
3909 /* The error code for an attachment type of GL_NONE differs between APIs.
3911 * From the ES 2.0.25 specification, page 127:
3912 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3913 * querying any other pname will generate INVALID_ENUM."
3915 * From the OpenGL 3.0 specification, page 337, or identically,
3916 * the OpenGL ES 3.0.4 specification, page 240:
3918 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
3919 * framebuffer is bound to target. In this case querying pname
3920 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
3921 * queries will generate an INVALID_OPERATION error."
3923 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
3924 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
3926 if (_mesa_is_winsys_fbo(buffer
)) {
3927 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
3930 * "If the framebuffer currently bound to target is zero, then
3931 * INVALID_OPERATION is generated."
3933 * The EXT_framebuffer_object spec has the same wording, and the
3934 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
3937 if ((!_mesa_is_desktop_gl(ctx
) ||
3938 !ctx
->Extensions
.ARB_framebuffer_object
)
3939 && !_mesa_is_gles3(ctx
)) {
3940 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3941 "%s(window-system framebuffer)", caller
);
3945 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
3946 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
3947 _mesa_error(ctx
, GL_INVALID_ENUM
,
3948 "%s(invalid attachment %s)", caller
,
3949 _mesa_enum_to_string(attachment
));
3953 /* The specs are not clear about how to handle
3954 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
3955 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
3958 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
3959 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
3961 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
3962 _mesa_error(ctx
, GL_INVALID_ENUM
,
3963 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
3964 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
3965 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
3969 /* the default / window-system FBO */
3970 att
= get_fb0_attachment(ctx
, buffer
, attachment
);
3973 /* user-created framebuffer FBO */
3974 att
= get_attachment(ctx
, buffer
, attachment
, &is_color_attachment
);
3979 * From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries":
3981 * "An INVALID_OPERATION error is generated if a framebuffer object
3982 * is bound to target and attachment is COLOR_ATTACHMENTm where m is
3983 * greater than or equal to the value of MAX_COLOR_ATTACHMENTS."
3985 * If we are at this point, is because the attachment is not valid, so
3986 * if is_color_attachment is true, is because of the previous reason.
3988 if (is_color_attachment
) {
3989 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid color attachment %s)",
3990 caller
, _mesa_enum_to_string(attachment
));
3992 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3993 _mesa_enum_to_string(attachment
));
3998 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3999 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
4000 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
4001 /* This behavior is first specified in OpenGL 4.4 specification.
4003 * From the OpenGL 4.4 spec page 275:
4004 * "This query cannot be performed for a combined depth+stencil
4005 * attachment, since it does not have a single format."
4007 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4008 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
4009 " is invalid for depth+stencil attachment)", caller
);
4012 /* the depth and stencil attachments must point to the same buffer */
4013 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
, NULL
);
4014 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
, NULL
);
4015 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
4016 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4017 "%s(DEPTH/STENCIL attachments differ)", caller
);
4022 /* No need to flush here */
4025 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
4026 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
4028 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
4029 * either no framebuffer is bound to target; or the default framebuffer
4030 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
4031 * stencil bits, respectively, is zero."
4033 * Note that we don't need explicit checks on DEPTH and STENCIL, because
4034 * on the case the spec is pointing, att->Type is already NONE, so we
4035 * just need to check att->Type.
4037 *params
= (_mesa_is_winsys_fbo(buffer
) && att
->Type
!= GL_NONE
) ?
4038 GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
4040 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
4041 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
4042 *params
= att
->Renderbuffer
->Name
;
4044 else if (att
->Type
== GL_TEXTURE
) {
4045 *params
= att
->Texture
->Name
;
4048 assert(att
->Type
== GL_NONE
);
4049 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
4052 goto invalid_pname_enum
;
4056 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
4057 if (att
->Type
== GL_TEXTURE
) {
4058 *params
= att
->TextureLevel
;
4060 else if (att
->Type
== GL_NONE
) {
4061 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4062 _mesa_enum_to_string(pname
));
4065 goto invalid_pname_enum
;
4068 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
4069 if (att
->Type
== GL_TEXTURE
) {
4070 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
4071 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
4077 else if (att
->Type
== GL_NONE
) {
4078 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4079 _mesa_enum_to_string(pname
));
4082 goto invalid_pname_enum
;
4085 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
4086 if (ctx
->API
== API_OPENGLES
) {
4087 goto invalid_pname_enum
;
4088 } else if (att
->Type
== GL_NONE
) {
4089 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4090 _mesa_enum_to_string(pname
));
4091 } else if (att
->Type
== GL_TEXTURE
) {
4092 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
4093 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
4094 *params
= att
->Zoffset
;
4101 goto invalid_pname_enum
;
4104 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
4105 if ((!_mesa_is_desktop_gl(ctx
) ||
4106 !ctx
->Extensions
.ARB_framebuffer_object
)
4107 && !_mesa_is_gles3(ctx
)) {
4108 goto invalid_pname_enum
;
4110 else if (att
->Type
== GL_NONE
) {
4111 if (_mesa_is_winsys_fbo(buffer
) &&
4112 (attachment
== GL_DEPTH
|| attachment
== GL_STENCIL
)) {
4113 *params
= GL_LINEAR
;
4115 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4116 _mesa_enum_to_string(pname
));
4120 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
4122 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
4125 /* According to ARB_framebuffer_sRGB, we should return LINEAR
4126 * if the sRGB conversion is unsupported. */
4127 *params
= GL_LINEAR
;
4131 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
4132 if ((ctx
->API
!= API_OPENGL_COMPAT
||
4133 !ctx
->Extensions
.ARB_framebuffer_object
)
4134 && ctx
->API
!= API_OPENGL_CORE
4135 && !_mesa_is_gles3(ctx
)) {
4136 goto invalid_pname_enum
;
4138 else if (att
->Type
== GL_NONE
) {
4139 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4140 _mesa_enum_to_string(pname
));
4143 mesa_format format
= att
->Renderbuffer
->Format
;
4145 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
4148 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
4149 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
4150 * generate an INVALID_OPERATION error.
4152 if (_mesa_is_gles3(ctx
) &&
4153 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
4154 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4156 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
4157 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
4161 if (format
== MESA_FORMAT_S_UINT8
) {
4165 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
4166 /* depends on the attachment parameter */
4167 if (attachment
== GL_STENCIL_ATTACHMENT
) {
4175 *params
= _mesa_get_format_datatype(format
);
4179 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
4180 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
4181 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
4182 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
4183 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
4184 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
4185 if ((!_mesa_is_desktop_gl(ctx
) ||
4186 !ctx
->Extensions
.ARB_framebuffer_object
)
4187 && !_mesa_is_gles3(ctx
)) {
4188 goto invalid_pname_enum
;
4190 else if (att
->Texture
) {
4191 const struct gl_texture_image
*texImage
=
4192 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
4195 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
4196 texImage
->TexFormat
);
4202 else if (att
->Renderbuffer
) {
4203 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
4204 att
->Renderbuffer
->Format
);
4207 assert(att
->Type
== GL_NONE
);
4208 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4209 _mesa_enum_to_string(pname
));
4212 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
4213 if (!_mesa_has_geometry_shaders(ctx
)) {
4214 goto invalid_pname_enum
;
4215 } else if (att
->Type
== GL_TEXTURE
) {
4216 *params
= att
->Layered
;
4217 } else if (att
->Type
== GL_NONE
) {
4218 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4219 _mesa_enum_to_string(pname
));
4221 goto invalid_pname_enum
;
4225 goto invalid_pname_enum
;
4231 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
4232 _mesa_enum_to_string(pname
));
4238 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
4239 GLenum pname
, GLint
*params
)
4241 GET_CURRENT_CONTEXT(ctx
);
4242 struct gl_framebuffer
*buffer
;
4244 buffer
= get_framebuffer_target(ctx
, target
);
4246 _mesa_error(ctx
, GL_INVALID_ENUM
,
4247 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
4248 _mesa_enum_to_string(target
));
4252 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4254 "glGetFramebufferAttachmentParameteriv");
4259 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
4261 GLenum pname
, GLint
*params
)
4263 GET_CURRENT_CONTEXT(ctx
);
4264 struct gl_framebuffer
*buffer
;
4267 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4268 "glGetNamedFramebufferAttachmentParameteriv");
4274 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
4275 * 4.5 core spec (30.10.2014, PDF page 314):
4276 * "If framebuffer is zero, then the default draw framebuffer is
4279 buffer
= ctx
->WinSysDrawBuffer
;
4282 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4284 "glGetNamedFramebufferAttachmentParameteriv");
4289 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
4292 GET_CURRENT_CONTEXT(ctx
);
4293 struct gl_framebuffer
*fb
= NULL
;
4295 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
4296 !ctx
->Extensions
.ARB_sample_locations
) {
4297 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4298 "glNamedFramebufferParameteri("
4299 "neither ARB_framebuffer_no_attachments nor "
4300 "ARB_sample_locations is available)");
4305 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4306 "glNamedFramebufferParameteri");
4308 fb
= ctx
->WinSysDrawBuffer
;
4312 framebuffer_parameteri(ctx
, fb
, pname
, param
,
4313 "glNamedFramebufferParameteriv");
4319 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
4322 GET_CURRENT_CONTEXT(ctx
);
4323 struct gl_framebuffer
*fb
;
4325 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4326 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4327 "glNamedFramebufferParameteriv("
4328 "neither ARB_framebuffer_no_attachments nor ARB_sample_locations"
4334 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4335 "glGetNamedFramebufferParameteriv");
4337 fb
= ctx
->WinSysDrawBuffer
;
4340 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4341 "glGetNamedFramebufferParameteriv");
4347 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4348 struct gl_framebuffer
*fb
,
4349 GLsizei numAttachments
,
4350 const GLenum
*attachments
, GLint x
, GLint y
,
4351 GLsizei width
, GLsizei height
, const char *name
)
4355 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4356 * Spec (2.2.2015, PDF page 522) says:
4357 * "An INVALID_VALUE error is generated if numAttachments, width, or
4358 * height is negative."
4360 if (numAttachments
< 0) {
4361 _mesa_error(ctx
, GL_INVALID_VALUE
,
4362 "%s(numAttachments < 0)", name
);
4367 _mesa_error(ctx
, GL_INVALID_VALUE
,
4368 "%s(width < 0)", name
);
4373 _mesa_error(ctx
, GL_INVALID_VALUE
,
4374 "%s(height < 0)", name
);
4378 /* The GL_ARB_invalidate_subdata spec says:
4380 * "If an attachment is specified that does not exist in the
4381 * framebuffer bound to <target>, it is ignored."
4385 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4386 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4387 * INVALID_OPERATION is generated."
4389 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4390 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4391 * set of retrictions).
4393 for (i
= 0; i
< numAttachments
; i
++) {
4394 if (_mesa_is_winsys_fbo(fb
)) {
4395 switch (attachments
[i
]) {
4401 /* Accumulation buffers and auxilary buffers were removed in
4402 * OpenGL 3.1, and they never existed in OpenGL ES.
4404 if (ctx
->API
!= API_OPENGL_COMPAT
)
4414 case GL_FRONT_RIGHT
:
4415 if (!_mesa_is_desktop_gl(ctx
))
4422 switch (attachments
[i
]) {
4423 case GL_DEPTH_ATTACHMENT
:
4424 case GL_STENCIL_ATTACHMENT
:
4426 case GL_DEPTH_STENCIL_ATTACHMENT
:
4427 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4428 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4429 * extension does not make this attachment point valid on ES 2.0.
4431 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4434 case GL_COLOR_ATTACHMENT0
:
4435 case GL_COLOR_ATTACHMENT1
:
4436 case GL_COLOR_ATTACHMENT2
:
4437 case GL_COLOR_ATTACHMENT3
:
4438 case GL_COLOR_ATTACHMENT4
:
4439 case GL_COLOR_ATTACHMENT5
:
4440 case GL_COLOR_ATTACHMENT6
:
4441 case GL_COLOR_ATTACHMENT7
:
4442 case GL_COLOR_ATTACHMENT8
:
4443 case GL_COLOR_ATTACHMENT9
:
4444 case GL_COLOR_ATTACHMENT10
:
4445 case GL_COLOR_ATTACHMENT11
:
4446 case GL_COLOR_ATTACHMENT12
:
4447 case GL_COLOR_ATTACHMENT13
:
4448 case GL_COLOR_ATTACHMENT14
:
4449 case GL_COLOR_ATTACHMENT15
: {
4450 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4451 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4452 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4453 "%s(attachment >= max. color attachments)", name
);
4464 /* We don't actually do anything for this yet. Just return after
4465 * validating the parameters and generating the required errors.
4470 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4471 _mesa_enum_to_string(attachments
[i
]));
4477 _mesa_InvalidateSubFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4478 const GLenum
*attachments
, GLint x
,
4479 GLint y
, GLsizei width
, GLsizei height
)
4486 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4487 const GLenum
*attachments
, GLint x
, GLint y
,
4488 GLsizei width
, GLsizei height
)
4490 struct gl_framebuffer
*fb
;
4491 GET_CURRENT_CONTEXT(ctx
);
4493 fb
= get_framebuffer_target(ctx
, target
);
4495 _mesa_error(ctx
, GL_INVALID_ENUM
,
4496 "glInvalidateSubFramebuffer(invalid target %s)",
4497 _mesa_enum_to_string(target
));
4501 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4502 x
, y
, width
, height
,
4503 "glInvalidateSubFramebuffer");
4508 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4509 GLsizei numAttachments
,
4510 const GLenum
*attachments
,
4512 GLsizei width
, GLsizei height
)
4514 struct gl_framebuffer
*fb
;
4515 GET_CURRENT_CONTEXT(ctx
);
4517 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4518 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4519 * default draw framebuffer is affected."
4522 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4523 "glInvalidateNamedFramebufferSubData");
4528 fb
= ctx
->WinSysDrawBuffer
;
4530 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4531 x
, y
, width
, height
,
4532 "glInvalidateNamedFramebufferSubData");
4537 _mesa_InvalidateFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4538 const GLenum
*attachments
)
4545 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4546 const GLenum
*attachments
)
4548 struct gl_framebuffer
*fb
;
4549 GET_CURRENT_CONTEXT(ctx
);
4551 fb
= get_framebuffer_target(ctx
, target
);
4553 _mesa_error(ctx
, GL_INVALID_ENUM
,
4554 "glInvalidateFramebuffer(invalid target %s)",
4555 _mesa_enum_to_string(target
));
4559 /* The GL_ARB_invalidate_subdata spec says:
4563 * void InvalidateFramebuffer(enum target,
4564 * sizei numAttachments,
4565 * const enum *attachments);
4567 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4568 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4569 * <MAX_VIEWPORT_DIMS[1]> respectively."
4571 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4573 ctx
->Const
.MaxViewportWidth
,
4574 ctx
->Const
.MaxViewportHeight
,
4575 "glInvalidateFramebuffer");
4580 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4581 GLsizei numAttachments
,
4582 const GLenum
*attachments
)
4584 struct gl_framebuffer
*fb
;
4585 GET_CURRENT_CONTEXT(ctx
);
4587 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4588 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4589 * default draw framebuffer is affected."
4592 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4593 "glInvalidateNamedFramebufferData");
4598 fb
= ctx
->WinSysDrawBuffer
;
4600 /* The GL_ARB_invalidate_subdata spec says:
4604 * void InvalidateFramebuffer(enum target,
4605 * sizei numAttachments,
4606 * const enum *attachments);
4608 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4609 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4610 * <MAX_VIEWPORT_DIMS[1]> respectively."
4612 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4614 ctx
->Const
.MaxViewportWidth
,
4615 ctx
->Const
.MaxViewportHeight
,
4616 "glInvalidateNamedFramebufferData");
4621 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4622 const GLenum
*attachments
)
4624 struct gl_framebuffer
*fb
;
4627 GET_CURRENT_CONTEXT(ctx
);
4629 fb
= get_framebuffer_target(ctx
, target
);
4631 _mesa_error(ctx
, GL_INVALID_ENUM
,
4632 "glDiscardFramebufferEXT(target %s)",
4633 _mesa_enum_to_string(target
));
4637 if (numAttachments
< 0) {
4638 _mesa_error(ctx
, GL_INVALID_VALUE
,
4639 "glDiscardFramebufferEXT(numAttachments < 0)");
4643 for (i
= 0; i
< numAttachments
; i
++) {
4644 switch (attachments
[i
]) {
4648 if (_mesa_is_user_fbo(fb
))
4651 case GL_COLOR_ATTACHMENT0
:
4652 case GL_DEPTH_ATTACHMENT
:
4653 case GL_STENCIL_ATTACHMENT
:
4654 if (_mesa_is_winsys_fbo(fb
))
4662 if (ctx
->Driver
.DiscardFramebuffer
)
4663 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4668 _mesa_error(ctx
, GL_INVALID_ENUM
,
4669 "glDiscardFramebufferEXT(attachment %s)",
4670 _mesa_enum_to_string(attachments
[i
]));
4674 sample_locations(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
4675 GLuint start
, GLsizei count
, const GLfloat
*v
, bool no_error
,
4681 if (!ctx
->Extensions
.ARB_sample_locations
) {
4682 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4684 "(ARB_sample_locations not available)", name
);
4688 if (start
+ count
> MAX_SAMPLE_LOCATION_TABLE_SIZE
) {
4689 _mesa_error(ctx
, GL_INVALID_VALUE
,
4690 "%s(start+size > sample location table size)", name
);
4695 if (!fb
->SampleLocationTable
) {
4696 size_t size
= MAX_SAMPLE_LOCATION_TABLE_SIZE
* 2 * sizeof(GLfloat
);
4697 fb
->SampleLocationTable
= malloc(size
);
4698 if (!fb
->SampleLocationTable
)
4699 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4700 "Cannot allocate sample location table");
4701 for (i
= 0; i
< MAX_SAMPLE_LOCATION_TABLE_SIZE
* 2; i
++)
4702 fb
->SampleLocationTable
[i
] = 0.5f
;
4705 for (i
= 0; i
< count
* 2; i
++) {
4706 /* The ARB_sample_locations spec says:
4708 * Sample locations outside of [0,1] result in undefined
4711 * To simplify driver implementations, we choose to clamp to
4712 * [0,1] and change NaN into 0.5.
4714 if (isnan(v
[i
]) || v
[i
] < 0.0f
|| v
[i
] > 1.0f
) {
4715 static GLuint msg_id
= 0;
4716 static const char* msg
= "Invalid sample location specified";
4717 _mesa_debug_get_id(&msg_id
);
4719 _mesa_log_msg(ctx
, MESA_DEBUG_SOURCE_API
, MESA_DEBUG_TYPE_UNDEFINED
,
4720 msg_id
, MESA_DEBUG_SEVERITY_HIGH
, strlen(msg
), msg
);
4724 fb
->SampleLocationTable
[start
* 2 + i
] = 0.5f
;
4726 fb
->SampleLocationTable
[start
* 2 + i
] = CLAMP(v
[i
], 0.0f
, 1.0f
);
4729 if (fb
== ctx
->DrawBuffer
)
4730 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
4734 _mesa_FramebufferSampleLocationsfvARB(GLenum target
, GLuint start
,
4735 GLsizei count
, const GLfloat
*v
)
4737 struct gl_framebuffer
*fb
;
4739 GET_CURRENT_CONTEXT(ctx
);
4741 fb
= get_framebuffer_target(ctx
, target
);
4743 _mesa_error(ctx
, GL_INVALID_ENUM
,
4744 "glFramebufferSampleLocationsfvARB(target %s)",
4745 _mesa_enum_to_string(target
));
4749 sample_locations(ctx
, fb
, start
, count
, v
, false,
4750 "glFramebufferSampleLocationsfvARB");
4754 _mesa_NamedFramebufferSampleLocationsfvARB(GLuint framebuffer
, GLuint start
,
4755 GLsizei count
, const GLfloat
*v
)
4757 struct gl_framebuffer
*fb
;
4759 GET_CURRENT_CONTEXT(ctx
);
4762 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4763 "glNamedFramebufferSampleLocationsfvARB");
4768 fb
= ctx
->WinSysDrawBuffer
;
4770 sample_locations(ctx
, fb
, start
, count
, v
, false,
4771 "glNamedFramebufferSampleLocationsfvARB");
4775 _mesa_FramebufferSampleLocationsfvARB_no_error(GLenum target
, GLuint start
,
4776 GLsizei count
, const GLfloat
*v
)
4778 GET_CURRENT_CONTEXT(ctx
);
4779 sample_locations(ctx
, get_framebuffer_target(ctx
, target
), start
,
4780 count
, v
, true, "glFramebufferSampleLocationsfvARB");
4784 _mesa_NamedFramebufferSampleLocationsfvARB_no_error(GLuint framebuffer
,
4785 GLuint start
, GLsizei count
,
4788 GET_CURRENT_CONTEXT(ctx
);
4789 sample_locations(ctx
, _mesa_lookup_framebuffer(ctx
, framebuffer
), start
,
4790 count
, v
, true, "glNamedFramebufferSampleLocationsfvARB");
4794 _mesa_EvaluateDepthValuesARB(void)
4796 GET_CURRENT_CONTEXT(ctx
);
4798 if (!ctx
->Extensions
.ARB_sample_locations
) {
4799 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4800 "EvaluateDepthValuesARB not supported (neither "
4801 "ARB_sample_locations nor NV_sample_locations is available)");
4805 if (ctx
->Driver
.EvaluateDepthValues
)
4806 ctx
->Driver
.EvaluateDepthValues(ctx
);