2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 * GL_EXT/ARB_framebuffer_object extensions
41 #include "framebuffer.h"
42 #include "glformats.h"
45 #include "multisample.h"
47 #include "renderbuffer.h"
56 * None of the GL_EXT_framebuffer_object functions are compiled into
63 * When glGenRender/FramebuffersEXT() is called we insert pointers to
64 * these placeholder objects into the hash table.
65 * Later, when the object ID is first bound, we replace the placeholder
66 * with the real frame/renderbuffer.
68 static struct gl_framebuffer DummyFramebuffer
;
69 static struct gl_renderbuffer DummyRenderbuffer
;
71 /* We bind this framebuffer when applications pass a NULL
72 * drawable/surface in make current. */
73 static struct gl_framebuffer IncompleteFramebuffer
;
77 delete_dummy_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
83 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
90 _mesa_init_fbobjects(struct gl_context
*ctx
)
92 mtx_init(&DummyFramebuffer
.Mutex
, mtx_plain
);
93 mtx_init(&DummyRenderbuffer
.Mutex
, mtx_plain
);
94 mtx_init(&IncompleteFramebuffer
.Mutex
, mtx_plain
);
95 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
96 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
97 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
100 struct gl_framebuffer
*
101 _mesa_get_incomplete_framebuffer(void)
103 return &IncompleteFramebuffer
;
107 * Helper routine for getting a gl_renderbuffer.
109 struct gl_renderbuffer
*
110 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
112 struct gl_renderbuffer
*rb
;
117 rb
= (struct gl_renderbuffer
*)
118 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
124 * A convenience function for direct state access that throws
125 * GL_INVALID_OPERATION if the renderbuffer doesn't exist.
127 struct gl_renderbuffer
*
128 _mesa_lookup_renderbuffer_err(struct gl_context
*ctx
, GLuint id
,
131 struct gl_renderbuffer
*rb
;
133 rb
= _mesa_lookup_renderbuffer(ctx
, id
);
134 if (!rb
|| rb
== &DummyRenderbuffer
) {
135 _mesa_error(ctx
, GL_INVALID_OPERATION
,
136 "%s(non-existent renderbuffer %u)", func
, id
);
145 * Helper routine for getting a gl_framebuffer.
147 struct gl_framebuffer
*
148 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
150 struct gl_framebuffer
*fb
;
155 fb
= (struct gl_framebuffer
*)
156 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
162 * A convenience function for direct state access that throws
163 * GL_INVALID_OPERATION if the framebuffer doesn't exist.
165 struct gl_framebuffer
*
166 _mesa_lookup_framebuffer_err(struct gl_context
*ctx
, GLuint id
,
169 struct gl_framebuffer
*fb
;
171 fb
= _mesa_lookup_framebuffer(ctx
, id
);
172 if (!fb
|| fb
== &DummyFramebuffer
) {
173 _mesa_error(ctx
, GL_INVALID_OPERATION
,
174 "%s(non-existent framebuffer %u)", func
, id
);
183 * Mark the given framebuffer as invalid. This will force the
184 * test for framebuffer completeness to be done before the framebuffer
188 invalidate_framebuffer(struct gl_framebuffer
*fb
)
190 fb
->_Status
= 0; /* "indeterminate" */
195 * Return the gl_framebuffer object which corresponds to the given
196 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
197 * Check support for GL_EXT_framebuffer_blit to determine if certain
199 * \return gl_framebuffer pointer or NULL if target is illegal
201 static struct gl_framebuffer
*
202 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
204 bool have_fb_blit
= _mesa_is_gles3(ctx
) || _mesa_is_desktop_gl(ctx
);
206 case GL_DRAW_FRAMEBUFFER
:
207 return have_fb_blit
? ctx
->DrawBuffer
: NULL
;
208 case GL_READ_FRAMEBUFFER
:
209 return have_fb_blit
? ctx
->ReadBuffer
: NULL
;
210 case GL_FRAMEBUFFER_EXT
:
211 return ctx
->DrawBuffer
;
219 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
220 * gl_renderbuffer_attachment object.
221 * This function is only used for user-created FB objects, not the
222 * default / window-system FB object.
223 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
224 * the depth buffer attachment point.
225 * Returns if the attachment is a GL_COLOR_ATTACHMENTm_EXT on
226 * is_color_attachment, because several callers would return different errors
227 * if they don't find the attachment.
229 static struct gl_renderbuffer_attachment
*
230 get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
231 GLenum attachment
, bool *is_color_attachment
)
235 assert(_mesa_is_user_fbo(fb
));
237 if (is_color_attachment
)
238 *is_color_attachment
= false;
240 switch (attachment
) {
241 case GL_COLOR_ATTACHMENT0_EXT
:
242 case GL_COLOR_ATTACHMENT1_EXT
:
243 case GL_COLOR_ATTACHMENT2_EXT
:
244 case GL_COLOR_ATTACHMENT3_EXT
:
245 case GL_COLOR_ATTACHMENT4_EXT
:
246 case GL_COLOR_ATTACHMENT5_EXT
:
247 case GL_COLOR_ATTACHMENT6_EXT
:
248 case GL_COLOR_ATTACHMENT7_EXT
:
249 case GL_COLOR_ATTACHMENT8_EXT
:
250 case GL_COLOR_ATTACHMENT9_EXT
:
251 case GL_COLOR_ATTACHMENT10_EXT
:
252 case GL_COLOR_ATTACHMENT11_EXT
:
253 case GL_COLOR_ATTACHMENT12_EXT
:
254 case GL_COLOR_ATTACHMENT13_EXT
:
255 case GL_COLOR_ATTACHMENT14_EXT
:
256 case GL_COLOR_ATTACHMENT15_EXT
:
257 if (is_color_attachment
)
258 *is_color_attachment
= true;
259 /* Only OpenGL ES 1.x forbids color attachments other than
260 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
263 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
264 if (i
>= ctx
->Const
.MaxColorAttachments
265 || (i
> 0 && ctx
->API
== API_OPENGLES
)) {
268 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
269 case GL_DEPTH_STENCIL_ATTACHMENT
:
270 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
273 case GL_DEPTH_ATTACHMENT_EXT
:
274 return &fb
->Attachment
[BUFFER_DEPTH
];
275 case GL_STENCIL_ATTACHMENT_EXT
:
276 return &fb
->Attachment
[BUFFER_STENCIL
];
284 * As above, but only used for getting attachments of the default /
285 * window-system framebuffer (not user-created framebuffer objects).
287 static struct gl_renderbuffer_attachment
*
288 _mesa_get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
291 assert(_mesa_is_winsys_fbo(fb
));
293 if (_mesa_is_gles3(ctx
)) {
294 assert(attachment
== GL_BACK
||
295 attachment
== GL_DEPTH
||
296 attachment
== GL_STENCIL
);
297 switch (attachment
) {
299 /* Since there is no stereo rendering in ES 3.0, only return the
302 if (ctx
->DrawBuffer
->Visual
.doubleBufferMode
)
303 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
304 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
306 return &fb
->Attachment
[BUFFER_DEPTH
];
308 return &fb
->Attachment
[BUFFER_STENCIL
];
312 switch (attachment
) {
314 /* Front buffers can be allocated on the first use, but
315 * glGetFramebufferAttachmentParameteriv must work even if that
316 * allocation hasn't happened yet. In such case, use the back buffer,
317 * which should be the same.
319 if (fb
->Attachment
[BUFFER_FRONT_LEFT
].Type
== GL_NONE
)
320 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
322 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
325 if (fb
->Attachment
[BUFFER_FRONT_RIGHT
].Type
== GL_NONE
)
326 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
328 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
330 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
332 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
334 if (fb
->Visual
.numAuxBuffers
== 1) {
335 return &fb
->Attachment
[BUFFER_AUX0
];
339 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
341 * "If the default framebuffer is bound to target, then attachment must
342 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
343 * identifying a color buffer; DEPTH, identifying the depth buffer; or
344 * STENCIL, identifying the stencil buffer."
346 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
347 * language. However, revision #33 of the ARB_framebuffer_object spec
350 * "If the default framebuffer is bound to <target>, then <attachment>
351 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
352 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
353 * depth buffer, or the stencil buffer, and <pname> may be
354 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
355 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
357 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
358 * from glext.h, so shipping apps should not use those values.
360 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
361 * support queries of the window system FBO.
364 return &fb
->Attachment
[BUFFER_DEPTH
];
366 return &fb
->Attachment
[BUFFER_STENCIL
];
375 * Remove any texture or renderbuffer attached to the given attachment
376 * point. Update reference counts, etc.
379 remove_attachment(struct gl_context
*ctx
,
380 struct gl_renderbuffer_attachment
*att
)
382 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
384 /* tell driver that we're done rendering to this texture. */
385 if (rb
&& rb
->NeedsFinishRenderTexture
)
386 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
388 if (att
->Type
== GL_TEXTURE
) {
389 assert(att
->Texture
);
390 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
391 assert(!att
->Texture
);
393 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
394 assert(!att
->Texture
);
395 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
396 assert(!att
->Renderbuffer
);
399 att
->Complete
= GL_TRUE
;
403 * Verify a couple error conditions that will lead to an incomplete FBO and
404 * may cause problems for the driver's RenderTexture path.
407 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment
*att
)
409 const struct gl_texture_image
*const texImage
=
410 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
413 texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
416 if ((texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
417 && att
->Zoffset
>= texImage
->Height
)
418 || (texImage
->TexObject
->Target
!= GL_TEXTURE_1D_ARRAY
419 && att
->Zoffset
>= texImage
->Depth
))
426 * Create a renderbuffer which will be set up by the driver to wrap the
427 * texture image slice.
429 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
430 * to share most of their framebuffer rendering code between winsys,
431 * renderbuffer, and texture attachments.
433 * The allocated renderbuffer uses a non-zero Name so that drivers can check
434 * it for determining vertical orientation, but we use ~0 to make it fairly
435 * unambiguous with actual user (non-texture) renderbuffers.
438 _mesa_update_texture_renderbuffer(struct gl_context
*ctx
,
439 struct gl_framebuffer
*fb
,
440 struct gl_renderbuffer_attachment
*att
)
442 struct gl_texture_image
*texImage
;
443 struct gl_renderbuffer
*rb
;
445 texImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
447 rb
= att
->Renderbuffer
;
449 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
451 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
454 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
456 /* This can't get called on a texture renderbuffer, so set it to NULL
457 * for clarity compared to user renderbuffers.
459 rb
->AllocStorage
= NULL
;
461 rb
->NeedsFinishRenderTexture
= ctx
->Driver
.FinishRenderTexture
!= NULL
;
467 rb
->_BaseFormat
= texImage
->_BaseFormat
;
468 rb
->Format
= texImage
->TexFormat
;
469 rb
->InternalFormat
= texImage
->InternalFormat
;
470 rb
->Width
= texImage
->Width2
;
471 rb
->Height
= texImage
->Height2
;
472 rb
->Depth
= texImage
->Depth2
;
473 rb
->NumSamples
= texImage
->NumSamples
;
474 rb
->TexImage
= texImage
;
476 if (driver_RenderTexture_is_safe(att
))
477 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
481 * Bind a texture object to an attachment point.
482 * The previous binding, if any, will be removed first.
485 set_texture_attachment(struct gl_context
*ctx
,
486 struct gl_framebuffer
*fb
,
487 struct gl_renderbuffer_attachment
*att
,
488 struct gl_texture_object
*texObj
,
489 GLenum texTarget
, GLuint level
, GLuint layer
,
492 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
494 if (rb
&& rb
->NeedsFinishRenderTexture
)
495 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
497 if (att
->Texture
== texObj
) {
498 /* re-attaching same texture */
499 assert(att
->Type
== GL_TEXTURE
);
503 remove_attachment(ctx
, att
);
504 att
->Type
= GL_TEXTURE
;
505 assert(!att
->Texture
);
506 _mesa_reference_texobj(&att
->Texture
, texObj
);
508 invalidate_framebuffer(fb
);
510 /* always update these fields */
511 att
->TextureLevel
= level
;
512 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
513 att
->Zoffset
= layer
;
514 att
->Layered
= layered
;
515 att
->Complete
= GL_FALSE
;
517 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
522 * Bind a renderbuffer to an attachment point.
523 * The previous binding, if any, will be removed first.
526 set_renderbuffer_attachment(struct gl_context
*ctx
,
527 struct gl_renderbuffer_attachment
*att
,
528 struct gl_renderbuffer
*rb
)
530 /* XXX check if re-doing same attachment, exit early */
531 remove_attachment(ctx
, att
);
532 att
->Type
= GL_RENDERBUFFER_EXT
;
533 att
->Texture
= NULL
; /* just to be safe */
534 att
->Layered
= GL_FALSE
;
535 att
->Complete
= GL_FALSE
;
536 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
541 * Fallback for ctx->Driver.FramebufferRenderbuffer()
542 * Attach a renderbuffer object to a framebuffer object.
545 _mesa_FramebufferRenderbuffer_sw(struct gl_context
*ctx
,
546 struct gl_framebuffer
*fb
,
548 struct gl_renderbuffer
*rb
)
550 struct gl_renderbuffer_attachment
*att
;
552 mtx_lock(&fb
->Mutex
);
554 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
557 set_renderbuffer_attachment(ctx
, att
, rb
);
558 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
559 /* do stencil attachment here (depth already done above) */
560 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
562 set_renderbuffer_attachment(ctx
, att
, rb
);
564 rb
->AttachedAnytime
= GL_TRUE
;
567 remove_attachment(ctx
, att
);
568 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
569 /* detach stencil (depth was detached above) */
570 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
572 remove_attachment(ctx
, att
);
576 invalidate_framebuffer(fb
);
578 mtx_unlock(&fb
->Mutex
);
583 * Fallback for ctx->Driver.ValidateFramebuffer()
584 * Check if the renderbuffer's formats are supported by the software
586 * Drivers should probably override this.
589 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
592 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
593 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
595 switch (rb
->_BaseFormat
) {
597 case GL_LUMINANCE_ALPHA
:
602 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
606 switch (rb
->Format
) {
607 /* XXX This list is likely incomplete. */
608 case MESA_FORMAT_R9G9B9E5_FLOAT
:
609 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
612 /* render buffer format is supported by software rendering */
621 * Return true if the framebuffer has a combined depth/stencil
622 * renderbuffer attached.
625 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
627 const struct gl_renderbuffer_attachment
*depth
=
628 &fb
->Attachment
[BUFFER_DEPTH
];
629 const struct gl_renderbuffer_attachment
*stencil
=
630 &fb
->Attachment
[BUFFER_STENCIL
];
632 if (depth
->Type
== stencil
->Type
) {
633 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
634 depth
->Renderbuffer
== stencil
->Renderbuffer
)
637 if (depth
->Type
== GL_TEXTURE
&&
638 depth
->Texture
== stencil
->Texture
)
650 att_incomplete(const char *msg
)
652 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
653 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
662 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
664 static GLuint msg_id
;
666 _mesa_gl_debug(ctx
, &msg_id
,
667 MESA_DEBUG_SOURCE_API
,
668 MESA_DEBUG_TYPE_OTHER
,
669 MESA_DEBUG_SEVERITY_MEDIUM
,
670 "FBO incomplete: %s [%d]\n", msg
, index
);
672 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
673 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
679 * Is the given base format a legal format for a color renderbuffer?
682 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
684 switch (baseFormat
) {
689 case GL_LUMINANCE_ALPHA
:
692 return ctx
->API
== API_OPENGL_COMPAT
&&
693 ctx
->Extensions
.ARB_framebuffer_object
;
696 return ctx
->Extensions
.ARB_texture_rg
;
704 * Is the given base format a legal format for a color renderbuffer?
707 is_format_color_renderable(const struct gl_context
*ctx
, mesa_format format
,
708 GLenum internalFormat
)
710 const GLenum baseFormat
=
711 _mesa_get_format_base_format(format
);
714 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
715 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
719 /* Reject additional cases for GLES */
720 switch (internalFormat
) {
740 if (format
== MESA_FORMAT_B10G10R10A2_UNORM
&&
741 internalFormat
!= GL_RGB10_A2
) {
750 * Is the given base format a legal format for a depth/stencil renderbuffer?
753 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
755 switch (baseFormat
) {
756 case GL_DEPTH_COMPONENT
:
757 case GL_DEPTH_STENCIL_EXT
:
766 * Test if an attachment point is complete and update its Complete field.
767 * \param format if GL_COLOR, this is a color attachment point,
768 * if GL_DEPTH, this is a depth component attachment point,
769 * if GL_STENCIL, this is a stencil component attachment point.
772 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
773 struct gl_renderbuffer_attachment
*att
)
775 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
777 /* assume complete */
778 att
->Complete
= GL_TRUE
;
780 /* Look for reasons why the attachment might be incomplete */
781 if (att
->Type
== GL_TEXTURE
) {
782 const struct gl_texture_object
*texObj
= att
->Texture
;
783 struct gl_texture_image
*texImage
;
787 att_incomplete("no texobj");
788 att
->Complete
= GL_FALSE
;
792 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
794 att_incomplete("no teximage");
795 att
->Complete
= GL_FALSE
;
798 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
799 att_incomplete("teximage width/height=0");
800 att
->Complete
= GL_FALSE
;
804 switch (texObj
->Target
) {
806 if (att
->Zoffset
>= texImage
->Depth
) {
807 att_incomplete("bad z offset");
808 att
->Complete
= GL_FALSE
;
812 case GL_TEXTURE_1D_ARRAY
:
813 if (att
->Zoffset
>= texImage
->Height
) {
814 att_incomplete("bad 1D-array layer");
815 att
->Complete
= GL_FALSE
;
819 case GL_TEXTURE_2D_ARRAY
:
820 if (att
->Zoffset
>= texImage
->Depth
) {
821 att_incomplete("bad 2D-array layer");
822 att
->Complete
= GL_FALSE
;
826 case GL_TEXTURE_CUBE_MAP_ARRAY
:
827 if (att
->Zoffset
>= texImage
->Depth
) {
828 att_incomplete("bad cube-array layer");
829 att
->Complete
= GL_FALSE
;
835 baseFormat
= texImage
->_BaseFormat
;
837 if (format
== GL_COLOR
) {
838 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
839 att_incomplete("bad format");
840 att
->Complete
= GL_FALSE
;
843 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
844 att_incomplete("compressed internalformat");
845 att
->Complete
= GL_FALSE
;
849 /* OES_texture_float allows creation and use of floating point
850 * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow
851 * these textures to be used as a render target, this is done via
852 * GL_EXT_color_buffer(_half)_float with set of new sized types.
854 if (_mesa_is_gles(ctx
) && (texImage
->TexObject
->_IsFloat
||
855 texImage
->TexObject
->_IsHalfFloat
)) {
856 att_incomplete("bad internal format");
857 att
->Complete
= GL_FALSE
;
861 else if (format
== GL_DEPTH
) {
862 if (baseFormat
== GL_DEPTH_COMPONENT
) {
865 else if (ctx
->Extensions
.ARB_depth_texture
&&
866 baseFormat
== GL_DEPTH_STENCIL
) {
870 att
->Complete
= GL_FALSE
;
871 att_incomplete("bad depth format");
876 assert(format
== GL_STENCIL
);
877 if (ctx
->Extensions
.ARB_depth_texture
&&
878 baseFormat
== GL_DEPTH_STENCIL
) {
880 } else if (ctx
->Extensions
.ARB_texture_stencil8
&&
881 baseFormat
== GL_STENCIL_INDEX
) {
884 /* no such thing as stencil-only textures */
885 att_incomplete("illegal stencil texture");
886 att
->Complete
= GL_FALSE
;
891 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
892 const GLenum baseFormat
= att
->Renderbuffer
->_BaseFormat
;
894 assert(att
->Renderbuffer
);
895 if (!att
->Renderbuffer
->InternalFormat
||
896 att
->Renderbuffer
->Width
< 1 ||
897 att
->Renderbuffer
->Height
< 1) {
898 att_incomplete("0x0 renderbuffer");
899 att
->Complete
= GL_FALSE
;
902 if (format
== GL_COLOR
) {
903 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
904 att_incomplete("bad renderbuffer color format");
905 att
->Complete
= GL_FALSE
;
909 else if (format
== GL_DEPTH
) {
910 if (baseFormat
== GL_DEPTH_COMPONENT
) {
913 else if (baseFormat
== GL_DEPTH_STENCIL
) {
917 att_incomplete("bad renderbuffer depth format");
918 att
->Complete
= GL_FALSE
;
923 assert(format
== GL_STENCIL
);
924 if (baseFormat
== GL_STENCIL_INDEX
||
925 baseFormat
== GL_DEPTH_STENCIL
) {
929 att
->Complete
= GL_FALSE
;
930 att_incomplete("bad renderbuffer stencil format");
936 assert(att
->Type
== GL_NONE
);
944 * Test if the given framebuffer object is complete and update its
945 * Status field with the results.
946 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
947 * driver to make hardware-specific validation/completeness checks.
948 * Also update the framebuffer's Width and Height fields if the
949 * framebuffer is complete.
952 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
953 struct gl_framebuffer
*fb
)
956 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
957 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
958 GLint numSamples
= -1;
959 GLint fixedSampleLocations
= -1;
962 /* Covers max_layer_count, is_layered, and layer_tex_target */
963 bool layer_info_valid
= false;
964 GLuint max_layer_count
= 0, att_layer_count
;
965 bool is_layered
= false;
966 GLenum layer_tex_target
= 0;
967 bool has_depth_attachment
= false;
968 bool has_stencil_attachment
= false;
970 assert(_mesa_is_user_fbo(fb
));
972 /* we're changing framebuffer fields here */
973 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
978 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
979 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
980 fb
->_HasAttachments
= true;
981 fb
->_IntegerBuffers
= 0;
983 /* Start at -2 to more easily loop over all attachment points.
988 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
989 struct gl_renderbuffer_attachment
*att
;
991 mesa_format attFormat
;
992 GLenum att_tex_target
= GL_NONE
;
995 * XXX for ARB_fbo, only check color buffers that are named by
996 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
999 /* check for attachment completeness
1002 att
= &fb
->Attachment
[BUFFER_DEPTH
];
1003 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
1004 if (!att
->Complete
) {
1005 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1006 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
1008 } else if (att
->Type
!= GL_NONE
) {
1009 has_depth_attachment
= true;
1013 att
= &fb
->Attachment
[BUFFER_STENCIL
];
1014 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
1015 if (!att
->Complete
) {
1016 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1017 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
1019 } else if (att
->Type
!= GL_NONE
) {
1020 has_stencil_attachment
= true;
1024 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
1025 test_attachment_completeness(ctx
, GL_COLOR
, att
);
1026 if (!att
->Complete
) {
1027 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1028 fbo_incomplete(ctx
, "color attachment incomplete", i
);
1033 /* get width, height, format of the renderbuffer/texture
1035 if (att
->Type
== GL_TEXTURE
) {
1036 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
1037 att_tex_target
= att
->Texture
->Target
;
1038 minWidth
= MIN2(minWidth
, texImg
->Width
);
1039 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
1040 minHeight
= MIN2(minHeight
, texImg
->Height
);
1041 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
1042 f
= texImg
->_BaseFormat
;
1043 attFormat
= texImg
->TexFormat
;
1046 if (!is_format_color_renderable(ctx
, attFormat
,
1047 texImg
->InternalFormat
) &&
1048 !is_legal_depth_format(ctx
, f
) &&
1049 f
!= GL_STENCIL_INDEX
) {
1050 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
;
1051 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
1056 numSamples
= texImg
->NumSamples
;
1057 else if (numSamples
!= texImg
->NumSamples
) {
1058 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1059 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1063 if (fixedSampleLocations
< 0)
1064 fixedSampleLocations
= texImg
->FixedSampleLocations
;
1065 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
1066 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1067 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1071 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1072 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
1073 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
1074 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
1075 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
1076 f
= att
->Renderbuffer
->InternalFormat
;
1077 attFormat
= att
->Renderbuffer
->Format
;
1081 numSamples
= att
->Renderbuffer
->NumSamples
;
1082 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
1083 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1084 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1088 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1089 if (fixedSampleLocations
< 0)
1090 fixedSampleLocations
= GL_TRUE
;
1091 else if (fixedSampleLocations
!= GL_TRUE
) {
1092 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1093 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1098 assert(att
->Type
== GL_NONE
);
1102 /* Update flags describing color buffer datatypes */
1104 GLenum type
= _mesa_get_format_datatype(attFormat
);
1106 /* check if integer color */
1107 if (_mesa_is_format_integer_color(attFormat
))
1108 fb
->_IntegerBuffers
|= (1 << i
);
1110 fb
->_AllColorBuffersFixedPoint
=
1111 fb
->_AllColorBuffersFixedPoint
&&
1112 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1114 fb
->_HasSNormOrFloatColorBuffer
=
1115 fb
->_HasSNormOrFloatColorBuffer
||
1116 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1119 /* Error-check width, height, format */
1120 if (numImages
== 1) {
1127 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1128 /* check that width, height, format are same */
1129 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1130 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1131 fbo_incomplete(ctx
, "width or height mismatch", -1);
1134 /* check that all color buffers are the same format */
1135 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1136 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1137 fbo_incomplete(ctx
, "format mismatch", -1);
1143 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1145 if (att
->Type
== GL_RENDERBUFFER
&&
1146 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1147 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1148 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1152 /* Check that layered rendering is consistent. */
1154 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1155 att_layer_count
= 6;
1156 else if (att_tex_target
== GL_TEXTURE_1D_ARRAY
)
1157 att_layer_count
= att
->Renderbuffer
->Height
;
1159 att_layer_count
= att
->Renderbuffer
->Depth
;
1161 att_layer_count
= 0;
1163 if (!layer_info_valid
) {
1164 is_layered
= att
->Layered
;
1165 max_layer_count
= att_layer_count
;
1166 layer_tex_target
= att_tex_target
;
1167 layer_info_valid
= true;
1168 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1169 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1170 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1172 } else if (is_layered
!= att
->Layered
) {
1173 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1175 "framebuffer attachment layer mode is inconsistent",
1178 } else if (att_layer_count
> max_layer_count
) {
1179 max_layer_count
= att_layer_count
;
1183 * The extension GL_ARB_framebuffer_no_attachments places additional
1184 * requirement on each attachment. Those additional requirements are
1185 * tighter that those of previous versions of GL. In interest of better
1186 * compatibility, we will not enforce these restrictions. For the record
1187 * those additional restrictions are quoted below:
1189 * "The width and height of image are greater than zero and less than or
1190 * equal to the values of the implementation-dependent limits
1191 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1193 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1194 * array texture and the attachment is layered, the depth or layer count
1195 * of the texture is less than or equal to the implementation-dependent
1196 * limit MAX_FRAMEBUFFER_LAYERS."
1198 * "If image has multiple samples, its sample count is less than or equal
1199 * to the value of the implementation-dependent limit
1200 * MAX_FRAMEBUFFER_SAMPLES."
1202 * The same requirements are also in place for GL 4.5,
1203 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1207 fb
->MaxNumLayers
= max_layer_count
;
1209 if (numImages
== 0) {
1210 fb
->_HasAttachments
= false;
1212 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1213 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1214 fbo_incomplete(ctx
, "no attachments", -1);
1218 if (fb
->DefaultGeometry
.Width
== 0 || fb
->DefaultGeometry
.Height
== 0) {
1219 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1220 fbo_incomplete(ctx
, "no attachments and default width or height is 0", -1);
1225 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1226 /* Check that all DrawBuffers are present */
1227 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1228 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1229 const struct gl_renderbuffer_attachment
*att
1230 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
], NULL
);
1232 if (att
->Type
== GL_NONE
) {
1233 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1234 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1240 /* Check that the ReadBuffer is present */
1241 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1242 const struct gl_renderbuffer_attachment
*att
1243 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
, NULL
);
1245 if (att
->Type
== GL_NONE
) {
1246 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1247 fbo_incomplete(ctx
, "missing readbuffer", -1);
1253 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1255 * "Depth and stencil attachments, if present, are the same image."
1257 * This restriction is not present in the OpenGL ES2 spec.
1259 if (_mesa_is_gles3(ctx
) &&
1260 has_stencil_attachment
&& has_depth_attachment
&&
1261 !_mesa_has_depthstencil_combined(fb
)) {
1262 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1263 fbo_incomplete(ctx
, "Depth and stencil attachments must be the same image", -1);
1267 /* Provisionally set status = COMPLETE ... */
1268 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1270 /* ... but the driver may say the FB is incomplete.
1271 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1274 if (ctx
->Driver
.ValidateFramebuffer
) {
1275 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1276 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1277 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1283 * Note that if ARB_framebuffer_object is supported and the attached
1284 * renderbuffers/textures are different sizes, the framebuffer
1285 * width/height will be set to the smallest width/height.
1287 if (numImages
!= 0) {
1288 fb
->Width
= minWidth
;
1289 fb
->Height
= minHeight
;
1292 /* finally, update the visual info for the framebuffer */
1293 _mesa_update_framebuffer_visual(ctx
, fb
);
1297 GLboolean GLAPIENTRY
1298 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1300 GET_CURRENT_CONTEXT(ctx
);
1301 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1303 struct gl_renderbuffer
*rb
=
1304 _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1305 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
1312 static struct gl_renderbuffer
*
1313 allocate_renderbuffer_locked(struct gl_context
*ctx
, GLuint renderbuffer
,
1316 struct gl_renderbuffer
*newRb
;
1318 /* create new renderbuffer object */
1319 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1321 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1324 assert(newRb
->AllocStorage
);
1325 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1326 newRb
->RefCount
= 1; /* referenced by hash table */
1333 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1335 struct gl_renderbuffer
*newRb
;
1336 GET_CURRENT_CONTEXT(ctx
);
1338 if (target
!= GL_RENDERBUFFER_EXT
) {
1339 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1343 /* No need to flush here since the render buffer binding has no
1344 * effect on rendering state.
1348 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1349 if (newRb
== &DummyRenderbuffer
) {
1350 /* ID was reserved, but no real renderbuffer object made yet */
1353 else if (!newRb
&& !allow_user_names
) {
1354 /* All RB IDs must be Gen'd */
1355 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1360 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1361 newRb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
1362 "glBindRenderbufferEXT");
1363 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1370 assert(newRb
!= &DummyRenderbuffer
);
1372 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1376 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1378 GET_CURRENT_CONTEXT(ctx
);
1380 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1381 * entry point, but they allow the use of user-generated names.
1383 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1387 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1389 /* This function should not be in the dispatch table for core profile /
1390 * OpenGL 3.1, so execution should never get here in those cases -- no
1391 * need for an explicit test.
1393 bind_renderbuffer(target
, renderbuffer
, true);
1397 * ARB_framebuffer_no_attachment - Application passes requested param's
1398 * here. NOTE: NumSamples requested need not be _NumSamples which is
1399 * what the hw supports.
1402 framebuffer_parameteri(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1403 GLenum pname
, GLint param
, const char *func
)
1406 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1407 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferWidth
)
1408 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1410 fb
->DefaultGeometry
.Width
= param
;
1412 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1413 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferHeight
)
1414 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1416 fb
->DefaultGeometry
.Height
= param
;
1418 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1420 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1421 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1423 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1424 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1427 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferLayers
)
1428 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1430 fb
->DefaultGeometry
.Layers
= param
;
1432 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1433 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferSamples
)
1434 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1436 fb
->DefaultGeometry
.NumSamples
= param
;
1438 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1439 fb
->DefaultGeometry
.FixedSampleLocations
= param
;
1442 _mesa_error(ctx
, GL_INVALID_ENUM
,
1443 "%s(pname=0x%x)", func
, pname
);
1446 invalidate_framebuffer(fb
);
1447 ctx
->NewState
|= _NEW_BUFFERS
;
1451 _mesa_FramebufferParameteri(GLenum target
, GLenum pname
, GLint param
)
1453 GET_CURRENT_CONTEXT(ctx
);
1454 struct gl_framebuffer
*fb
;
1456 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1457 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1458 "glFramebufferParameteriv not supported "
1459 "(ARB_framebuffer_no_attachments not implemented)");
1463 fb
= get_framebuffer_target(ctx
, target
);
1465 _mesa_error(ctx
, GL_INVALID_ENUM
,
1466 "glFramebufferParameteri(target=0x%x)", target
);
1470 /* check framebuffer binding */
1471 if (_mesa_is_winsys_fbo(fb
)) {
1472 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1473 "glFramebufferParameteri");
1477 framebuffer_parameteri(ctx
, fb
, pname
, param
, "glFramebufferParameteri");
1481 _pname_valid_for_default_framebuffer(struct gl_context
*ctx
,
1484 if (!_mesa_is_desktop_gl(ctx
))
1488 case GL_DOUBLEBUFFER
:
1489 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1490 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1492 case GL_SAMPLE_BUFFERS
:
1501 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1502 GLenum pname
, GLint
*params
, const char *func
)
1504 /* From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries:
1506 * "An INVALID_OPERATION error is generated by GetFramebufferParameteriv
1507 * if the default framebuffer is bound to target and pname is not one
1508 * of the accepted values from table 23.73, other than
1511 * For OpenGL ES, using default framebuffer still raises INVALID_OPERATION
1514 if (_mesa_is_winsys_fbo(fb
) &&
1515 !_pname_valid_for_default_framebuffer(ctx
, pname
)) {
1516 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1517 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1522 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1523 *params
= fb
->DefaultGeometry
.Width
;
1525 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1526 *params
= fb
->DefaultGeometry
.Height
;
1528 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1530 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1531 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1533 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1534 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1537 *params
= fb
->DefaultGeometry
.Layers
;
1539 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1540 *params
= fb
->DefaultGeometry
.NumSamples
;
1542 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1543 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1545 case GL_DOUBLEBUFFER
:
1546 *params
= fb
->Visual
.doubleBufferMode
;
1548 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1549 *params
= _mesa_get_color_read_format(ctx
, fb
, func
);
1551 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1552 *params
= _mesa_get_color_read_type(ctx
, fb
, func
);
1555 *params
= _mesa_geometric_samples(fb
);
1557 case GL_SAMPLE_BUFFERS
:
1558 *params
= _mesa_geometric_samples(fb
) > 0;
1561 *params
= fb
->Visual
.stereoMode
;
1564 _mesa_error(ctx
, GL_INVALID_ENUM
,
1565 "%s(pname=0x%x)", func
, pname
);
1570 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1572 GET_CURRENT_CONTEXT(ctx
);
1573 struct gl_framebuffer
*fb
;
1575 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1576 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1577 "glGetFramebufferParameteriv not supported "
1578 "(ARB_framebuffer_no_attachments not implemented)");
1582 fb
= get_framebuffer_target(ctx
, target
);
1584 _mesa_error(ctx
, GL_INVALID_ENUM
,
1585 "glGetFramebufferParameteriv(target=0x%x)", target
);
1589 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1590 "glGetFramebufferParameteriv");
1595 * Remove the specified renderbuffer or texture from any attachment point in
1599 * \c true if the renderbuffer was detached from an attachment point. \c
1603 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1604 struct gl_framebuffer
*fb
,
1608 bool progress
= false;
1610 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1611 if (fb
->Attachment
[i
].Texture
== att
1612 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1613 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1618 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1619 * Completeness," of the OpenGL 3.1 spec says:
1621 * "Performing any of the following actions may change whether the
1622 * framebuffer is considered complete or incomplete:
1626 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1627 * containing an image that is attached to a framebuffer object
1628 * that is bound to the framebuffer."
1631 invalidate_framebuffer(fb
);
1638 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1641 GET_CURRENT_CONTEXT(ctx
);
1644 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1648 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1650 for (i
= 0; i
< n
; i
++) {
1651 if (renderbuffers
[i
] > 0) {
1652 struct gl_renderbuffer
*rb
;
1653 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1655 /* check if deleting currently bound renderbuffer object */
1656 if (rb
== ctx
->CurrentRenderbuffer
) {
1658 assert(rb
->RefCount
>= 2);
1659 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1662 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1663 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1664 * of the OpenGL 3.1 spec says:
1666 * "If a renderbuffer object is deleted while its image is
1667 * attached to one or more attachment points in the currently
1668 * bound framebuffer, then it is as if FramebufferRenderbuffer
1669 * had been called, with a renderbuffer of 0, for each
1670 * attachment point to which this image was attached in the
1671 * currently bound framebuffer. In other words, this
1672 * renderbuffer image is first detached from all attachment
1673 * points in the currently bound framebuffer. Note that the
1674 * renderbuffer image is specifically not detached from any
1675 * non-bound framebuffers. Detaching the image from any
1676 * non-bound framebuffers is the responsibility of the
1679 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1680 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1682 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1683 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1684 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1687 /* Remove from hash table immediately, to free the ID.
1688 * But the object will not be freed until it's no longer
1689 * referenced anywhere else.
1691 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1693 if (rb
!= &DummyRenderbuffer
) {
1694 /* no longer referenced by hash table */
1695 _mesa_reference_renderbuffer(&rb
, NULL
);
1703 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1706 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1711 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1718 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1720 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1722 for (i
= 0; i
< n
; i
++) {
1723 GLuint name
= first
+ i
;
1724 renderbuffers
[i
] = name
;
1727 allocate_renderbuffer_locked(ctx
, name
, func
);
1729 /* insert a dummy renderbuffer into the hash table */
1730 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1731 &DummyRenderbuffer
);
1735 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1740 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1742 GET_CURRENT_CONTEXT(ctx
);
1743 create_render_buffers(ctx
, n
, renderbuffers
, false);
1748 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1750 GET_CURRENT_CONTEXT(ctx
);
1751 create_render_buffers(ctx
, n
, renderbuffers
, true);
1756 * Given an internal format token for a render buffer, return the
1757 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1758 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1759 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1761 * This is similar to _mesa_base_tex_format() but the set of valid
1762 * internal formats is different.
1764 * Note that even if a format is determined to be legal here, validation
1765 * of the FBO may fail if the format is not supported by the driver/GPU.
1767 * \param internalFormat as passed to glRenderbufferStorage()
1768 * \return the base internal format, or 0 if internalFormat is illegal
1771 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1774 * Notes: some formats such as alpha, luminance, etc. were added
1775 * with GL_ARB_framebuffer_object.
1777 switch (internalFormat
) {
1783 return (ctx
->API
== API_OPENGL_COMPAT
&&
1784 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
1788 case GL_LUMINANCE12
:
1789 case GL_LUMINANCE16
:
1790 return (ctx
->API
== API_OPENGL_COMPAT
&&
1791 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
1792 case GL_LUMINANCE_ALPHA
:
1793 case GL_LUMINANCE4_ALPHA4
:
1794 case GL_LUMINANCE6_ALPHA2
:
1795 case GL_LUMINANCE8_ALPHA8
:
1796 case GL_LUMINANCE12_ALPHA4
:
1797 case GL_LUMINANCE12_ALPHA12
:
1798 case GL_LUMINANCE16_ALPHA16
:
1799 return (ctx
->API
== API_OPENGL_COMPAT
&&
1800 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
1804 case GL_INTENSITY12
:
1805 case GL_INTENSITY16
:
1806 return (ctx
->API
== API_OPENGL_COMPAT
&&
1807 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
1817 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1819 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1828 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1830 case GL_SRGB8_ALPHA8_EXT
:
1831 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1832 case GL_STENCIL_INDEX
:
1833 case GL_STENCIL_INDEX1_EXT
:
1834 case GL_STENCIL_INDEX4_EXT
:
1835 case GL_STENCIL_INDEX16_EXT
:
1836 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1837 * OpenGL ES, but Mesa does not currently support them.
1839 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1840 case GL_STENCIL_INDEX8_EXT
:
1841 return GL_STENCIL_INDEX
;
1842 case GL_DEPTH_COMPONENT
:
1843 case GL_DEPTH_COMPONENT32
:
1844 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1845 case GL_DEPTH_COMPONENT16
:
1846 case GL_DEPTH_COMPONENT24
:
1847 return GL_DEPTH_COMPONENT
;
1848 case GL_DEPTH_STENCIL
:
1849 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
1850 case GL_DEPTH24_STENCIL8
:
1851 return GL_DEPTH_STENCIL
;
1852 case GL_DEPTH_COMPONENT32F
:
1853 return ctx
->Version
>= 30
1854 || (ctx
->API
== API_OPENGL_COMPAT
&&
1855 ctx
->Extensions
.ARB_depth_buffer_float
)
1856 ? GL_DEPTH_COMPONENT
: 0;
1857 case GL_DEPTH32F_STENCIL8
:
1858 return ctx
->Version
>= 30
1859 || (ctx
->API
== API_OPENGL_COMPAT
&&
1860 ctx
->Extensions
.ARB_depth_buffer_float
)
1861 ? GL_DEPTH_STENCIL
: 0;
1864 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1867 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1871 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1874 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1876 /* signed normalized texture formats */
1880 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1885 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1889 case GL_RGB16_SNORM
:
1890 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1893 case GL_RGBA8_SNORM
:
1894 case GL_RGBA16_SNORM
:
1895 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1897 case GL_ALPHA_SNORM
:
1898 case GL_ALPHA8_SNORM
:
1899 case GL_ALPHA16_SNORM
:
1900 return ctx
->API
== API_OPENGL_COMPAT
&&
1901 ctx
->Extensions
.EXT_texture_snorm
&&
1902 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1903 case GL_LUMINANCE_SNORM
:
1904 case GL_LUMINANCE8_SNORM
:
1905 case GL_LUMINANCE16_SNORM
:
1906 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1908 case GL_LUMINANCE_ALPHA_SNORM
:
1909 case GL_LUMINANCE8_ALPHA8_SNORM
:
1910 case GL_LUMINANCE16_ALPHA16_SNORM
:
1911 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1912 ? GL_LUMINANCE_ALPHA
: 0;
1913 case GL_INTENSITY_SNORM
:
1914 case GL_INTENSITY8_SNORM
:
1915 case GL_INTENSITY16_SNORM
:
1916 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1921 return ((_mesa_is_desktop_gl(ctx
) &&
1922 ctx
->Extensions
.ARB_texture_rg
&&
1923 ctx
->Extensions
.ARB_texture_float
) ||
1924 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1928 return ((_mesa_is_desktop_gl(ctx
) &&
1929 ctx
->Extensions
.ARB_texture_rg
&&
1930 ctx
->Extensions
.ARB_texture_float
) ||
1931 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1935 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1939 return ((_mesa_is_desktop_gl(ctx
) &&
1940 ctx
->Extensions
.ARB_texture_float
) ||
1941 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1943 case GL_ALPHA16F_ARB
:
1944 case GL_ALPHA32F_ARB
:
1945 return ctx
->API
== API_OPENGL_COMPAT
&&
1946 ctx
->Extensions
.ARB_texture_float
&&
1947 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1948 case GL_LUMINANCE16F_ARB
:
1949 case GL_LUMINANCE32F_ARB
:
1950 return ctx
->API
== API_OPENGL_COMPAT
&&
1951 ctx
->Extensions
.ARB_texture_float
&&
1952 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1953 case GL_LUMINANCE_ALPHA16F_ARB
:
1954 case GL_LUMINANCE_ALPHA32F_ARB
:
1955 return ctx
->API
== API_OPENGL_COMPAT
&&
1956 ctx
->Extensions
.ARB_texture_float
&&
1957 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1958 case GL_INTENSITY16F_ARB
:
1959 case GL_INTENSITY32F_ARB
:
1960 return ctx
->API
== API_OPENGL_COMPAT
&&
1961 ctx
->Extensions
.ARB_texture_float
&&
1962 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1963 case GL_R11F_G11F_B10F
:
1964 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1965 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1968 case GL_RGBA8UI_EXT
:
1969 case GL_RGBA16UI_EXT
:
1970 case GL_RGBA32UI_EXT
:
1972 case GL_RGBA16I_EXT
:
1973 case GL_RGBA32I_EXT
:
1974 return ctx
->Version
>= 30
1975 || (_mesa_is_desktop_gl(ctx
) &&
1976 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
1979 case GL_RGB16UI_EXT
:
1980 case GL_RGB32UI_EXT
:
1984 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
1992 return ctx
->Version
>= 30
1993 || (_mesa_is_desktop_gl(ctx
) &&
1994 ctx
->Extensions
.ARB_texture_rg
&&
1995 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
2003 return ctx
->Version
>= 30
2004 || (_mesa_is_desktop_gl(ctx
) &&
2005 ctx
->Extensions
.ARB_texture_rg
&&
2006 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
2008 case GL_INTENSITY8I_EXT
:
2009 case GL_INTENSITY8UI_EXT
:
2010 case GL_INTENSITY16I_EXT
:
2011 case GL_INTENSITY16UI_EXT
:
2012 case GL_INTENSITY32I_EXT
:
2013 case GL_INTENSITY32UI_EXT
:
2014 return ctx
->API
== API_OPENGL_COMPAT
&&
2015 ctx
->Extensions
.EXT_texture_integer
&&
2016 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2018 case GL_LUMINANCE8I_EXT
:
2019 case GL_LUMINANCE8UI_EXT
:
2020 case GL_LUMINANCE16I_EXT
:
2021 case GL_LUMINANCE16UI_EXT
:
2022 case GL_LUMINANCE32I_EXT
:
2023 case GL_LUMINANCE32UI_EXT
:
2024 return ctx
->API
== API_OPENGL_COMPAT
&&
2025 ctx
->Extensions
.EXT_texture_integer
&&
2026 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2028 case GL_LUMINANCE_ALPHA8I_EXT
:
2029 case GL_LUMINANCE_ALPHA8UI_EXT
:
2030 case GL_LUMINANCE_ALPHA16I_EXT
:
2031 case GL_LUMINANCE_ALPHA16UI_EXT
:
2032 case GL_LUMINANCE_ALPHA32I_EXT
:
2033 case GL_LUMINANCE_ALPHA32UI_EXT
:
2034 return ctx
->API
== API_OPENGL_COMPAT
&&
2035 ctx
->Extensions
.EXT_texture_integer
&&
2036 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2038 case GL_ALPHA8I_EXT
:
2039 case GL_ALPHA8UI_EXT
:
2040 case GL_ALPHA16I_EXT
:
2041 case GL_ALPHA16UI_EXT
:
2042 case GL_ALPHA32I_EXT
:
2043 case GL_ALPHA32UI_EXT
:
2044 return ctx
->API
== API_OPENGL_COMPAT
&&
2045 ctx
->Extensions
.EXT_texture_integer
&&
2046 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2049 return (_mesa_is_desktop_gl(ctx
) &&
2050 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
2051 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2054 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2063 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2066 invalidate_rb(GLuint key
, void *data
, void *userData
)
2068 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2069 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2071 /* If this is a user-created FBO */
2072 if (_mesa_is_user_fbo(fb
)) {
2074 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2075 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2076 if (att
->Type
== GL_RENDERBUFFER
&&
2077 att
->Renderbuffer
== rb
) {
2078 /* Mark fb status as indeterminate to force re-validation */
2087 /** sentinal value, see below */
2088 #define NO_SAMPLES 1000
2091 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2092 GLenum internalFormat
, GLsizei width
,
2093 GLsizei height
, GLsizei samples
)
2095 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2097 assert(baseFormat
!= 0);
2098 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2099 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2100 assert(samples
!= NO_SAMPLES
);
2102 assert(samples
> 0);
2103 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2104 internalFormat
, samples
) == GL_NO_ERROR
);
2107 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2109 if (rb
->InternalFormat
== internalFormat
&&
2110 rb
->Width
== (GLuint
) width
&&
2111 rb
->Height
== (GLuint
) height
&&
2112 rb
->NumSamples
== samples
) {
2113 /* no change in allocation needed */
2117 /* These MUST get set by the AllocStorage func */
2118 rb
->Format
= MESA_FORMAT_NONE
;
2119 rb
->NumSamples
= samples
;
2121 /* Now allocate the storage */
2122 assert(rb
->AllocStorage
);
2123 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2124 /* No error - check/set fields now */
2125 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2126 assert(rb
->Width
== (GLuint
) width
);
2127 assert(rb
->Height
== (GLuint
) height
);
2128 rb
->InternalFormat
= internalFormat
;
2129 rb
->_BaseFormat
= baseFormat
;
2130 assert(rb
->_BaseFormat
!= 0);
2133 /* Probably ran out of memory - clear the fields */
2136 rb
->Format
= MESA_FORMAT_NONE
;
2137 rb
->InternalFormat
= GL_NONE
;
2138 rb
->_BaseFormat
= GL_NONE
;
2142 /* Invalidate the framebuffers the renderbuffer is attached in. */
2143 if (rb
->AttachedAnytime
) {
2144 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2149 * Helper function used by renderbuffer_storage_direct() and
2150 * renderbuffer_storage_target().
2151 * samples will be NO_SAMPLES if called by a non-multisample function.
2154 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2155 GLenum internalFormat
, GLsizei width
,
2156 GLsizei height
, GLsizei samples
, const char *func
)
2159 GLenum sample_count_error
;
2161 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2162 if (baseFormat
== 0) {
2163 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2164 func
, _mesa_enum_to_string(internalFormat
));
2168 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2169 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2174 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2175 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2180 if (samples
== NO_SAMPLES
) {
2181 /* NumSamples == 0 indicates non-multisampling */
2185 /* check the sample count;
2186 * note: driver may choose to use more samples than what's requested
2188 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2189 internalFormat
, samples
);
2191 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2193 * "If a negative number is provided where an argument of type sizei or
2194 * sizeiptr is specified, the error INVALID VALUE is generated."
2197 sample_count_error
= GL_INVALID_VALUE
;
2200 if (sample_count_error
!= GL_NO_ERROR
) {
2201 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
2206 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
);
2210 * Helper function used by _mesa_NamedRenderbufferStorage*().
2211 * samples will be NO_SAMPLES if called by a non-multisample function.
2214 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2215 GLsizei width
, GLsizei height
, GLsizei samples
,
2218 GET_CURRENT_CONTEXT(ctx
);
2220 if (MESA_VERBOSE
& VERBOSE_API
) {
2221 if (samples
== NO_SAMPLES
)
2222 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2224 _mesa_enum_to_string(internalFormat
),
2227 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2229 _mesa_enum_to_string(internalFormat
),
2230 width
, height
, samples
);
2233 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2234 if (!rb
|| rb
== &DummyRenderbuffer
) {
2235 /* ID was reserved, but no real renderbuffer object made yet */
2236 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2237 func
, renderbuffer
);
2241 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
, func
);
2245 * Helper function used by _mesa_RenderbufferStorage() and
2246 * _mesa_RenderbufferStorageMultisample().
2247 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2250 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2251 GLsizei width
, GLsizei height
, GLsizei samples
,
2254 GET_CURRENT_CONTEXT(ctx
);
2256 if (MESA_VERBOSE
& VERBOSE_API
) {
2257 if (samples
== NO_SAMPLES
)
2258 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2260 _mesa_enum_to_string(target
),
2261 _mesa_enum_to_string(internalFormat
),
2264 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2266 _mesa_enum_to_string(target
),
2267 _mesa_enum_to_string(internalFormat
),
2268 width
, height
, samples
);
2271 if (target
!= GL_RENDERBUFFER_EXT
) {
2272 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2276 if (!ctx
->CurrentRenderbuffer
) {
2277 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2282 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2283 height
, samples
, func
);
2288 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2290 struct gl_renderbuffer
*rb
;
2291 GET_CURRENT_CONTEXT(ctx
);
2293 if (!ctx
->Extensions
.OES_EGL_image
) {
2294 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2295 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2299 if (target
!= GL_RENDERBUFFER
) {
2300 _mesa_error(ctx
, GL_INVALID_ENUM
,
2301 "EGLImageTargetRenderbufferStorageOES");
2305 rb
= ctx
->CurrentRenderbuffer
;
2307 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2308 "EGLImageTargetRenderbufferStorageOES");
2312 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2314 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2319 * Helper function for _mesa_GetRenderbufferParameteriv() and
2320 * _mesa_GetFramebufferAttachmentParameteriv()
2321 * We have to be careful to respect the base format. For example, if a
2322 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2323 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2324 * we need to return zero.
2327 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2329 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2330 return _mesa_get_format_bits(format
, pname
);
2338 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2339 GLsizei width
, GLsizei height
)
2341 /* GL_ARB_fbo says calling this function is equivalent to calling
2342 * glRenderbufferStorageMultisample() with samples=0. We pass in
2343 * a token value here just for error reporting purposes.
2345 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2346 NO_SAMPLES
, "glRenderbufferStorage");
2351 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2352 GLenum internalFormat
,
2353 GLsizei width
, GLsizei height
)
2355 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2356 samples
, "glRenderbufferStorageMultisample");
2361 * OpenGL ES version of glRenderBufferStorage.
2364 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2365 GLsizei width
, GLsizei height
)
2367 switch (internalFormat
) {
2369 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2370 /* choose a closest format */
2371 internalFormat
= GL_RGB5
;
2377 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0,
2378 "glRenderbufferStorageEXT");
2382 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2383 GLsizei width
, GLsizei height
)
2385 /* GL_ARB_fbo says calling this function is equivalent to calling
2386 * glRenderbufferStorageMultisample() with samples=0. We pass in
2387 * a token value here just for error reporting purposes.
2389 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2390 NO_SAMPLES
, "glNamedRenderbufferStorage");
2394 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2395 GLenum internalformat
,
2396 GLsizei width
, GLsizei height
)
2398 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2400 "glNamedRenderbufferStorageMultisample");
2405 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2406 struct gl_renderbuffer
*rb
, GLenum pname
,
2407 GLint
*params
, const char *func
)
2409 /* No need to flush here since we're just quering state which is
2410 * not effected by rendering.
2414 case GL_RENDERBUFFER_WIDTH_EXT
:
2415 *params
= rb
->Width
;
2417 case GL_RENDERBUFFER_HEIGHT_EXT
:
2418 *params
= rb
->Height
;
2420 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2421 *params
= rb
->InternalFormat
;
2423 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2424 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2425 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2426 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2427 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2428 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2429 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2431 case GL_RENDERBUFFER_SAMPLES
:
2432 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2433 || _mesa_is_gles3(ctx
)) {
2434 *params
= rb
->NumSamples
;
2439 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2440 _mesa_enum_to_string(pname
));
2447 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2449 GET_CURRENT_CONTEXT(ctx
);
2451 if (target
!= GL_RENDERBUFFER_EXT
) {
2452 _mesa_error(ctx
, GL_INVALID_ENUM
,
2453 "glGetRenderbufferParameterivEXT(target)");
2457 if (!ctx
->CurrentRenderbuffer
) {
2458 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2459 "(no renderbuffer bound)");
2463 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2464 params
, "glGetRenderbufferParameteriv");
2469 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2472 GET_CURRENT_CONTEXT(ctx
);
2474 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2475 if (!rb
|| rb
== &DummyRenderbuffer
) {
2476 /* ID was reserved, but no real renderbuffer object made yet */
2477 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2478 "(invalid renderbuffer %i)", renderbuffer
);
2482 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2483 "glGetNamedRenderbufferParameteriv");
2487 GLboolean GLAPIENTRY
2488 _mesa_IsFramebuffer(GLuint framebuffer
)
2490 GET_CURRENT_CONTEXT(ctx
);
2491 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2493 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2494 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2502 * Check if any of the attachments of the given framebuffer are textures
2503 * (render to texture). Call ctx->Driver.RenderTexture() for such
2507 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2510 assert(ctx
->Driver
.RenderTexture
);
2512 if (_mesa_is_winsys_fbo(fb
))
2513 return; /* can't render to texture with winsys framebuffers */
2515 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2516 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2517 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2518 && driver_RenderTexture_is_safe(att
)) {
2519 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2526 * Examine all the framebuffer's attachments to see if any are textures.
2527 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2528 * notify the device driver that the texture image may have changed.
2531 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2533 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2534 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2537 if (ctx
->Driver
.FinishRenderTexture
) {
2539 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2540 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2541 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2542 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2543 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2551 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2553 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2554 GLboolean bindReadBuf
, bindDrawBuf
;
2555 GET_CURRENT_CONTEXT(ctx
);
2558 case GL_DRAW_FRAMEBUFFER_EXT
:
2559 bindDrawBuf
= GL_TRUE
;
2560 bindReadBuf
= GL_FALSE
;
2562 case GL_READ_FRAMEBUFFER_EXT
:
2563 bindDrawBuf
= GL_FALSE
;
2564 bindReadBuf
= GL_TRUE
;
2566 case GL_FRAMEBUFFER_EXT
:
2567 bindDrawBuf
= GL_TRUE
;
2568 bindReadBuf
= GL_TRUE
;
2571 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2576 /* Binding a user-created framebuffer object */
2577 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2578 if (newDrawFb
== &DummyFramebuffer
) {
2579 /* ID was reserved, but no real framebuffer object made yet */
2582 else if (!newDrawFb
&& !allow_user_names
) {
2583 /* All FBO IDs must be Gen'd */
2584 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2589 /* create new framebuffer object */
2590 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2592 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2595 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2597 newReadFb
= newDrawFb
;
2600 /* Binding the window system framebuffer (which was originally set
2601 * with MakeCurrent).
2603 newDrawFb
= ctx
->WinSysDrawBuffer
;
2604 newReadFb
= ctx
->WinSysReadBuffer
;
2607 _mesa_bind_framebuffers(ctx
,
2608 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2609 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2613 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2614 struct gl_framebuffer
*newDrawFb
,
2615 struct gl_framebuffer
*newReadFb
)
2617 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
2618 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
2619 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
2620 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
2623 assert(newDrawFb
!= &DummyFramebuffer
);
2626 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2628 * We also check if we're beginning and/or ending render-to-texture.
2629 * When a framebuffer with texture attachments is unbound, call
2630 * ctx->Driver.FinishRenderTexture().
2631 * When a framebuffer with texture attachments is bound, call
2632 * ctx->Driver.RenderTexture().
2634 * Note that if the ReadBuffer has texture attachments we don't consider
2635 * that a render-to-texture case.
2638 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2640 /* check if old readbuffer was render-to-texture */
2641 check_end_texture_render(ctx
, oldReadFb
);
2643 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2647 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2649 /* check if old framebuffer had any texture attachments */
2651 check_end_texture_render(ctx
, oldDrawFb
);
2653 /* check if newly bound framebuffer has any texture attachments */
2654 check_begin_texture_render(ctx
, newDrawFb
);
2656 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2659 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2660 /* The few classic drivers that actually hook this function really only
2661 * want to know if the draw framebuffer changed.
2663 ctx
->Driver
.BindFramebuffer(ctx
,
2664 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
2665 newDrawFb
, newReadFb
);
2670 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2672 GET_CURRENT_CONTEXT(ctx
);
2674 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2675 * point, but they allow the use of user-generated names.
2677 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2682 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2684 /* This function should not be in the dispatch table for core profile /
2685 * OpenGL 3.1, so execution should never get here in those cases -- no
2686 * need for an explicit test.
2688 bind_framebuffer(target
, framebuffer
, true);
2693 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2696 GET_CURRENT_CONTEXT(ctx
);
2699 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
2703 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2705 for (i
= 0; i
< n
; i
++) {
2706 if (framebuffers
[i
] > 0) {
2707 struct gl_framebuffer
*fb
;
2708 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2710 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2712 /* check if deleting currently bound framebuffer object */
2713 if (fb
== ctx
->DrawBuffer
) {
2715 assert(fb
->RefCount
>= 2);
2716 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2718 if (fb
== ctx
->ReadBuffer
) {
2720 assert(fb
->RefCount
>= 2);
2721 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2724 /* remove from hash table immediately, to free the ID */
2725 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2727 if (fb
!= &DummyFramebuffer
) {
2728 /* But the object will not be freed until it's no longer
2729 * bound in any context.
2731 _mesa_reference_framebuffer(&fb
, NULL
);
2740 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2741 * It is not exposed to the rest of Mesa to encourage the use of
2742 * nameless buffers in driver internals.
2745 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
2747 GET_CURRENT_CONTEXT(ctx
);
2750 struct gl_framebuffer
*fb
;
2752 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
2755 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
2762 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
2764 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2766 for (i
= 0; i
< n
; i
++) {
2767 GLuint name
= first
+ i
;
2768 framebuffers
[i
] = name
;
2771 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
2773 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2774 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
2779 fb
= &DummyFramebuffer
;
2781 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
2784 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2789 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2791 create_framebuffers(n
, framebuffers
, false);
2796 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2798 create_framebuffers(n
, framebuffers
, true);
2803 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
2804 struct gl_framebuffer
*buffer
)
2806 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2808 if (_mesa_is_winsys_fbo(buffer
)) {
2809 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2810 if (buffer
!= &IncompleteFramebuffer
) {
2811 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2813 return GL_FRAMEBUFFER_UNDEFINED
;
2817 /* No need to flush here */
2819 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2820 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2823 return buffer
->_Status
;
2828 _mesa_CheckFramebufferStatus(GLenum target
)
2830 struct gl_framebuffer
*fb
;
2831 GET_CURRENT_CONTEXT(ctx
);
2833 if (MESA_VERBOSE
& VERBOSE_API
)
2834 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2835 _mesa_enum_to_string(target
));
2837 fb
= get_framebuffer_target(ctx
, target
);
2839 _mesa_error(ctx
, GL_INVALID_ENUM
,
2840 "glCheckFramebufferStatus(invalid target %s)",
2841 _mesa_enum_to_string(target
));
2845 return _mesa_check_framebuffer_status(ctx
, fb
);
2850 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
2852 struct gl_framebuffer
*fb
;
2853 GET_CURRENT_CONTEXT(ctx
);
2855 /* Validate the target (for conformance's sake) and grab a reference to the
2856 * default framebuffer in case framebuffer = 0.
2857 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
2858 * (30.10.2014, PDF page 336) says:
2859 * "If framebuffer is zero, then the status of the default read or
2860 * draw framebuffer (as determined by target) is returned."
2863 case GL_DRAW_FRAMEBUFFER
:
2864 case GL_FRAMEBUFFER
:
2865 fb
= ctx
->WinSysDrawBuffer
;
2867 case GL_READ_FRAMEBUFFER
:
2868 fb
= ctx
->WinSysReadBuffer
;
2871 _mesa_error(ctx
, GL_INVALID_ENUM
,
2872 "glCheckNamedFramebufferStatus(invalid target %s)",
2873 _mesa_enum_to_string(target
));
2878 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
2879 "glCheckNamedFramebufferStatus");
2884 return _mesa_check_framebuffer_status(ctx
, fb
);
2889 * Replicate the src attachment point. Used by framebuffer_texture() when
2890 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2891 * GL_STENCIL_ATTACHMENT.
2894 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2895 gl_buffer_index dst
,
2896 gl_buffer_index src
)
2898 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2899 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2901 assert(src_att
->Texture
!= NULL
);
2902 assert(src_att
->Renderbuffer
!= NULL
);
2904 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2905 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2906 dst_att
->Type
= src_att
->Type
;
2907 dst_att
->Complete
= src_att
->Complete
;
2908 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2909 dst_att
->CubeMapFace
= src_att
->CubeMapFace
;
2910 dst_att
->Zoffset
= src_att
->Zoffset
;
2911 dst_att
->Layered
= src_att
->Layered
;
2916 * Common code called by gl*FramebufferTexture*() to retrieve the correct
2917 * texture object pointer.
2919 * \param texObj where the pointer to the texture object is returned. Note
2920 * that a successful call may return texObj = NULL.
2922 * \return true if no errors, false if errors
2925 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
,
2926 bool layered
, const char *caller
,
2927 struct gl_texture_object
**texObj
)
2929 *texObj
= NULL
; /* This will get returned if texture = 0. */
2934 *texObj
= _mesa_lookup_texture(ctx
, texture
);
2935 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
2936 /* Can't render to a non-existent texture object.
2938 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
2939 * Managing Framebuffer Objects specifies a different error
2940 * depending upon the calling function (PDF pages 325-328).
2941 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
2942 * value, while the other commands throw invalid operation (where
2943 * layered = GL_FALSE).
2945 const GLenum error
= layered
? GL_INVALID_VALUE
:
2946 GL_INVALID_OPERATION
;
2947 _mesa_error(ctx
, error
,
2948 "%s(non-existent texture %u)", caller
, texture
);
2957 * Common code called by gl*FramebufferTexture() to verify the texture target
2958 * and decide whether or not the attachment should truly be considered
2961 * \param layered true if attachment should be considered layered, false if
2964 * \return true if no errors, false if errors
2967 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
2968 const char *caller
, GLboolean
*layered
)
2974 case GL_TEXTURE_1D_ARRAY_EXT
:
2975 case GL_TEXTURE_2D_ARRAY_EXT
:
2976 case GL_TEXTURE_CUBE_MAP
:
2977 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2978 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2982 case GL_TEXTURE_RECTANGLE
:
2983 case GL_TEXTURE_2D_MULTISAMPLE
:
2984 /* These texture types are valid to pass to
2985 * glFramebufferTexture(), but since they aren't layered, it
2986 * is equivalent to calling glFramebufferTexture{1D,2D}().
2988 *layered
= GL_FALSE
;
2992 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2993 "%s(invalid texture target %s)", caller
,
2994 _mesa_enum_to_string(target
));
3000 * Common code called by gl*FramebufferTextureLayer() to verify the texture
3003 * \return true if no errors, false if errors
3006 check_texture_target(struct gl_context
*ctx
, GLenum target
,
3009 /* We're being called by glFramebufferTextureLayer().
3010 * The only legal texture types for that function are 3D,
3011 * cube-map, and 1D/2D/cube-map array textures.
3013 * We don't need to check for GL_ARB_texture_cube_map_array because the
3014 * application wouldn't have been able to create a texture with a
3015 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
3019 case GL_TEXTURE_1D_ARRAY
:
3020 case GL_TEXTURE_2D_ARRAY
:
3021 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3022 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3024 case GL_TEXTURE_CUBE_MAP
:
3025 /* We don't need to check the extension (GL_ARB_direct_state_access) or
3026 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
3027 * enabled in core profile. This can be called from
3028 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
3029 * so we do have to check the profile.
3031 return ctx
->API
== API_OPENGL_CORE
;
3034 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3035 "%s(invalid texture target %s)", caller
,
3036 _mesa_enum_to_string(target
));
3042 * Common code called by glFramebufferTexture*D() to verify the texture
3045 * \return true if no errors, false if errors
3048 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
3049 GLenum textarget
, const char *caller
)
3053 switch (textarget
) {
3057 case GL_TEXTURE_1D_ARRAY
:
3058 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3063 case GL_TEXTURE_2D_ARRAY
:
3064 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3065 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3067 case GL_TEXTURE_2D_MULTISAMPLE
:
3068 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3070 !ctx
->Extensions
.ARB_texture_multisample
||
3071 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3073 case GL_TEXTURE_RECTANGLE
:
3074 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3075 !ctx
->Extensions
.NV_texture_rectangle
;
3077 case GL_TEXTURE_CUBE_MAP
:
3078 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3081 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3082 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3083 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3084 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3085 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3086 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3087 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3093 _mesa_error(ctx
, GL_INVALID_ENUM
,
3094 "%s(unknown textarget 0x%x)", caller
, textarget
);
3099 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3100 "%s(invalid textarget %s)",
3101 caller
, _mesa_enum_to_string(textarget
));
3105 /* Make sure textarget is consistent with the texture's type */
3106 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3107 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3110 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3111 "%s(mismatched texture target)", caller
);
3120 * Common code called by gl*FramebufferTextureLayer() and
3121 * glFramebufferTexture3D() to validate the layer.
3123 * \return true if no errors, false if errors
3126 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3129 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3132 * "An INVALID_VALUE error is generated if texture is non-zero
3133 * and layer is negative."
3136 _mesa_error(ctx
, GL_INVALID_VALUE
,
3137 "%s(layer %u < 0)", caller
, layer
);
3141 if (target
== GL_TEXTURE_3D
) {
3142 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3143 if (layer
>= maxSize
) {
3144 _mesa_error(ctx
, GL_INVALID_VALUE
,
3145 "%s(invalid layer %u)", caller
, layer
);
3149 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3150 (target
== GL_TEXTURE_2D_ARRAY
) ||
3151 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3152 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3153 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3154 _mesa_error(ctx
, GL_INVALID_VALUE
,
3155 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3160 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3162 _mesa_error(ctx
, GL_INVALID_VALUE
,
3163 "%s(layer %u >= 6)", caller
, layer
);
3173 * Common code called by all gl*FramebufferTexture*() entry points to verify
3176 * \return true if no errors, false if errors
3179 check_level(struct gl_context
*ctx
, GLenum target
, GLint level
,
3183 (level
>= _mesa_max_texture_levels(ctx
, target
))) {
3184 _mesa_error(ctx
, GL_INVALID_VALUE
,
3185 "%s(invalid level %d)", caller
, level
);
3194 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3196 struct gl_texture_object
*texObj
, GLenum textarget
,
3197 GLint level
, GLuint layer
, GLboolean layered
,
3200 struct gl_renderbuffer_attachment
*att
;
3201 bool is_color_attachment
;
3203 /* The window-system framebuffer object is immutable */
3204 if (_mesa_is_winsys_fbo(fb
)) {
3205 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3210 /* Not a hash lookup, so we can afford to get the attachment here. */
3211 att
= get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3213 if (is_color_attachment
) {
3214 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3215 "%s(invalid color attachment %s)", caller
,
3216 _mesa_enum_to_string(attachment
));
3218 _mesa_error(ctx
, GL_INVALID_ENUM
,
3219 "%s(invalid attachment %s)", caller
,
3220 _mesa_enum_to_string(attachment
));
3225 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3227 mtx_lock(&fb
->Mutex
);
3229 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3230 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3231 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3232 _mesa_tex_target_to_face(textarget
) ==
3233 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3234 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3235 /* The texture object is already attached to the stencil attachment
3236 * point. Don't create a new renderbuffer; just reuse the stencil
3237 * attachment's. This is required to prevent a GL error in
3238 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3240 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3242 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3243 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3244 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3245 _mesa_tex_target_to_face(textarget
) ==
3246 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3247 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3248 /* As above, but with depth and stencil transposed. */
3249 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3252 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3253 level
, layer
, layered
);
3255 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3256 /* Above we created a new renderbuffer and attached it to the
3257 * depth attachment point. Now attach it to the stencil attachment
3260 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3261 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3266 /* Set the render-to-texture flag. We'll check this flag in
3267 * glTexImage() and friends to determine if we need to revalidate
3268 * any FBOs that might be rendering into this texture.
3269 * This flag never gets cleared since it's non-trivial to determine
3270 * when all FBOs might be done rendering to this texture. That's OK
3271 * though since it's uncommon to render to a texture then repeatedly
3272 * call glTexImage() to change images in the texture.
3274 texObj
->_RenderToTexture
= GL_TRUE
;
3277 remove_attachment(ctx
, att
);
3278 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3279 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3280 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3284 invalidate_framebuffer(fb
);
3286 mtx_unlock(&fb
->Mutex
);
3291 framebuffer_texture_with_dims(int dims
, GLenum target
,
3292 GLenum attachment
, GLenum textarget
,
3293 GLuint texture
, GLint level
, GLint layer
,
3296 GET_CURRENT_CONTEXT(ctx
);
3297 struct gl_framebuffer
*fb
;
3298 struct gl_texture_object
*texObj
;
3300 /* Get the framebuffer object */
3301 fb
= get_framebuffer_target(ctx
, target
);
3303 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3304 _mesa_enum_to_string(target
));
3308 /* Get the texture object */
3309 if (!get_texture_for_framebuffer(ctx
, texture
, false, caller
, &texObj
))
3313 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3316 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3319 if (!check_level(ctx
, textarget
, level
, caller
))
3323 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3324 layer
, GL_FALSE
, caller
);
3329 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3330 GLenum textarget
, GLuint texture
, GLint level
)
3332 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3333 level
, 0, "glFramebufferTexture1D");
3338 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3339 GLenum textarget
, GLuint texture
, GLint level
)
3341 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3342 level
, 0, "glFramebufferTexture2D");
3347 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3348 GLenum textarget
, GLuint texture
,
3349 GLint level
, GLint layer
)
3351 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3352 level
, layer
, "glFramebufferTexture3D");
3357 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3358 GLuint texture
, GLint level
, GLint layer
)
3360 GET_CURRENT_CONTEXT(ctx
);
3361 struct gl_framebuffer
*fb
;
3362 struct gl_texture_object
*texObj
;
3363 GLenum textarget
= 0;
3365 const char *func
= "glFramebufferTextureLayer";
3367 /* Get the framebuffer object */
3368 fb
= get_framebuffer_target(ctx
, target
);
3370 _mesa_error(ctx
, GL_INVALID_ENUM
,
3371 "glFramebufferTextureLayer(invalid target %s)",
3372 _mesa_enum_to_string(target
));
3376 /* Get the texture object */
3377 if (!get_texture_for_framebuffer(ctx
, texture
, false, func
, &texObj
))
3381 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3384 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3387 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3390 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3391 assert(layer
>= 0 && layer
< 6);
3392 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3397 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3398 layer
, GL_FALSE
, func
);
3403 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3404 GLuint texture
, GLint level
, GLint layer
)
3406 GET_CURRENT_CONTEXT(ctx
);
3407 struct gl_framebuffer
*fb
;
3408 struct gl_texture_object
*texObj
;
3409 GLenum textarget
= 0;
3411 const char *func
= "glNamedFramebufferTextureLayer";
3413 /* Get the framebuffer object */
3414 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3418 /* Get the texture object */
3419 if (!get_texture_for_framebuffer(ctx
, texture
, false, func
, &texObj
))
3423 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3426 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3429 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3432 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3433 assert(layer
>= 0 && layer
< 6);
3434 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3439 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3440 layer
, GL_FALSE
, func
);
3445 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3446 GLuint texture
, GLint level
)
3448 GET_CURRENT_CONTEXT(ctx
);
3449 struct gl_framebuffer
*fb
;
3450 struct gl_texture_object
*texObj
;
3451 GLboolean layered
= GL_FALSE
;
3453 const char *func
= "FramebufferTexture";
3455 if (!_mesa_has_geometry_shaders(ctx
)) {
3456 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3457 "unsupported function (glFramebufferTexture) called");
3461 /* Get the framebuffer object */
3462 fb
= get_framebuffer_target(ctx
, target
);
3464 _mesa_error(ctx
, GL_INVALID_ENUM
,
3465 "glFramebufferTexture(invalid target %s)",
3466 _mesa_enum_to_string(target
));
3470 /* Get the texture object */
3471 if (!get_texture_for_framebuffer(ctx
, texture
, true, func
, &texObj
))
3475 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
, &layered
))
3478 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3482 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, 0, level
,
3488 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3489 GLuint texture
, GLint level
)
3491 GET_CURRENT_CONTEXT(ctx
);
3492 struct gl_framebuffer
*fb
;
3493 struct gl_texture_object
*texObj
;
3494 GLboolean layered
= GL_FALSE
;
3496 const char *func
= "glNamedFramebufferTexture";
3498 if (!_mesa_has_geometry_shaders(ctx
)) {
3499 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3500 "unsupported function (glNamedFramebufferTexture) called");
3504 /* Get the framebuffer object */
3505 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3509 /* Get the texture object */
3510 if (!get_texture_for_framebuffer(ctx
, texture
, true, func
, &texObj
))
3514 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3518 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3522 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, 0, level
,
3528 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3529 struct gl_framebuffer
*fb
,
3531 struct gl_renderbuffer
*rb
)
3533 assert(!_mesa_is_winsys_fbo(fb
));
3535 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3537 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3538 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3540 /* Some subsequent GL commands may depend on the framebuffer's visual
3541 * after the binding is updated. Update visual info now.
3543 _mesa_update_framebuffer_visual(ctx
, fb
);
3547 framebuffer_renderbuffer(struct gl_context
*ctx
,
3548 struct gl_framebuffer
*fb
,
3550 struct gl_renderbuffer
*rb
,
3553 struct gl_renderbuffer_attachment
*att
;
3554 bool is_color_attachment
;
3556 if (_mesa_is_winsys_fbo(fb
)) {
3557 /* Can't attach new renderbuffers to a window system framebuffer */
3558 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3559 "%s(window-system framebuffer)", func
);
3563 att
= get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3566 * From OpenGL 4.5 spec, section 9.2.7 "Attaching Renderbuffer Images to
3569 * "An INVALID_OPERATION error is generated if attachment is COLOR_-
3570 * ATTACHMENTm where m is greater than or equal to the value of
3571 * MAX_COLOR_- ATTACHMENTS ."
3573 * If we are at this point, is because the attachment is not valid, so
3574 * if is_color_attachment is true, is because of the previous reason.
3576 if (is_color_attachment
) {
3577 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3578 "%s(invalid color attachment %s)", func
,
3579 _mesa_enum_to_string(attachment
));
3581 _mesa_error(ctx
, GL_INVALID_ENUM
,
3582 "%s(invalid attachment %s)", func
,
3583 _mesa_enum_to_string(attachment
));
3589 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3590 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3591 /* make sure the renderbuffer is a depth/stencil format */
3592 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3593 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3594 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3595 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3600 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3604 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3605 GLenum renderbuffertarget
,
3606 GLuint renderbuffer
)
3608 struct gl_framebuffer
*fb
;
3609 struct gl_renderbuffer
*rb
;
3610 GET_CURRENT_CONTEXT(ctx
);
3612 fb
= get_framebuffer_target(ctx
, target
);
3614 _mesa_error(ctx
, GL_INVALID_ENUM
,
3615 "glFramebufferRenderbuffer(invalid target %s)",
3616 _mesa_enum_to_string(target
));
3620 if (renderbuffertarget
!= GL_RENDERBUFFER
) {
3621 _mesa_error(ctx
, GL_INVALID_ENUM
,
3622 "glFramebufferRenderbuffer(renderbuffertarget is not "
3623 "GL_RENDERBUFFER)");
3628 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
,
3629 "glFramebufferRenderbuffer");
3634 /* remove renderbuffer attachment */
3638 framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
,
3639 "glFramebufferRenderbuffer");
3644 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
3645 GLenum renderbuffertarget
,
3646 GLuint renderbuffer
)
3648 struct gl_framebuffer
*fb
;
3649 struct gl_renderbuffer
*rb
;
3650 GET_CURRENT_CONTEXT(ctx
);
3652 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3653 "glNamedFramebufferRenderbuffer");
3657 if (renderbuffertarget
!= GL_RENDERBUFFER
) {
3658 _mesa_error(ctx
, GL_INVALID_ENUM
,
3659 "glNamedFramebufferRenderbuffer(renderbuffertarget is not "
3660 "GL_RENDERBUFFER)");
3665 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
,
3666 "glNamedFramebufferRenderbuffer");
3671 /* remove renderbuffer attachment */
3675 framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
,
3676 "glNamedFramebufferRenderbuffer");
3681 _mesa_get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
3682 struct gl_framebuffer
*buffer
,
3683 GLenum attachment
, GLenum pname
,
3684 GLint
*params
, const char *caller
)
3686 const struct gl_renderbuffer_attachment
*att
;
3687 bool is_color_attachment
= false;
3690 /* The error code for an attachment type of GL_NONE differs between APIs.
3692 * From the ES 2.0.25 specification, page 127:
3693 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3694 * querying any other pname will generate INVALID_ENUM."
3696 * From the OpenGL 3.0 specification, page 337, or identically,
3697 * the OpenGL ES 3.0.4 specification, page 240:
3699 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
3700 * framebuffer is bound to target. In this case querying pname
3701 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
3702 * queries will generate an INVALID_OPERATION error."
3704 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
3705 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
3707 if (_mesa_is_winsys_fbo(buffer
)) {
3708 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
3711 * "If the framebuffer currently bound to target is zero, then
3712 * INVALID_OPERATION is generated."
3714 * The EXT_framebuffer_object spec has the same wording, and the
3715 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
3718 if ((!_mesa_is_desktop_gl(ctx
) ||
3719 !ctx
->Extensions
.ARB_framebuffer_object
)
3720 && !_mesa_is_gles3(ctx
)) {
3721 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3722 "%s(window-system framebuffer)", caller
);
3726 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
3727 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
3728 _mesa_error(ctx
, GL_INVALID_ENUM
,
3729 "%s(invalid attachment %s)", caller
,
3730 _mesa_enum_to_string(attachment
));
3734 /* The specs are not clear about how to handle
3735 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
3736 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
3739 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
3740 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
3742 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
3743 _mesa_error(ctx
, GL_INVALID_ENUM
,
3744 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
3745 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
3746 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
3750 /* the default / window-system FBO */
3751 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
3754 /* user-created framebuffer FBO */
3755 att
= get_attachment(ctx
, buffer
, attachment
, &is_color_attachment
);
3760 * From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries":
3762 * "An INVALID_OPERATION error is generated if a framebuffer object
3763 * is bound to target and attachment is COLOR_ATTACHMENTm where m is
3764 * greater than or equal to the value of MAX_COLOR_ATTACHMENTS."
3766 * If we are at this point, is because the attachment is not valid, so
3767 * if is_color_attachment is true, is because of the previous reason.
3769 if (is_color_attachment
) {
3770 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid color attachment %s)",
3771 caller
, _mesa_enum_to_string(attachment
));
3773 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3774 _mesa_enum_to_string(attachment
));
3779 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3780 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
3781 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
3782 /* This behavior is first specified in OpenGL 4.4 specification.
3784 * From the OpenGL 4.4 spec page 275:
3785 * "This query cannot be performed for a combined depth+stencil
3786 * attachment, since it does not have a single format."
3788 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3789 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
3790 " is invalid for depth+stencil attachment)", caller
);
3793 /* the depth and stencil attachments must point to the same buffer */
3794 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
, NULL
);
3795 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
, NULL
);
3796 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
3797 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3798 "%s(DEPTH/STENCIL attachments differ)", caller
);
3803 /* No need to flush here */
3806 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
3807 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
3809 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3810 * either no framebuffer is bound to target; or the default framebuffer
3811 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
3812 * stencil bits, respectively, is zero."
3814 * Note that we don't need explicit checks on DEPTH and STENCIL, because
3815 * on the case the spec is pointing, att->Type is already NONE, so we
3816 * just need to check att->Type.
3818 *params
= (_mesa_is_winsys_fbo(buffer
) && att
->Type
!= GL_NONE
) ?
3819 GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
3821 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
3822 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
3823 *params
= att
->Renderbuffer
->Name
;
3825 else if (att
->Type
== GL_TEXTURE
) {
3826 *params
= att
->Texture
->Name
;
3829 assert(att
->Type
== GL_NONE
);
3830 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
3833 goto invalid_pname_enum
;
3837 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
3838 if (att
->Type
== GL_TEXTURE
) {
3839 *params
= att
->TextureLevel
;
3841 else if (att
->Type
== GL_NONE
) {
3842 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3843 _mesa_enum_to_string(pname
));
3846 goto invalid_pname_enum
;
3849 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
3850 if (att
->Type
== GL_TEXTURE
) {
3851 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
3852 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
3858 else if (att
->Type
== GL_NONE
) {
3859 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3860 _mesa_enum_to_string(pname
));
3863 goto invalid_pname_enum
;
3866 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
3867 if (ctx
->API
== API_OPENGLES
) {
3868 goto invalid_pname_enum
;
3869 } else if (att
->Type
== GL_NONE
) {
3870 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3871 _mesa_enum_to_string(pname
));
3872 } else if (att
->Type
== GL_TEXTURE
) {
3873 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
3874 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
3875 *params
= att
->Zoffset
;
3882 goto invalid_pname_enum
;
3885 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
3886 if ((!_mesa_is_desktop_gl(ctx
) ||
3887 !ctx
->Extensions
.ARB_framebuffer_object
)
3888 && !_mesa_is_gles3(ctx
)) {
3889 goto invalid_pname_enum
;
3891 else if (att
->Type
== GL_NONE
) {
3892 if (_mesa_is_winsys_fbo(buffer
) &&
3893 (attachment
== GL_DEPTH
|| attachment
== GL_STENCIL
)) {
3894 *params
= GL_LINEAR
;
3896 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3897 _mesa_enum_to_string(pname
));
3901 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
3903 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
3906 /* According to ARB_framebuffer_sRGB, we should return LINEAR
3907 * if the sRGB conversion is unsupported. */
3908 *params
= GL_LINEAR
;
3912 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
3913 if ((ctx
->API
!= API_OPENGL_COMPAT
||
3914 !ctx
->Extensions
.ARB_framebuffer_object
)
3915 && ctx
->API
!= API_OPENGL_CORE
3916 && !_mesa_is_gles3(ctx
)) {
3917 goto invalid_pname_enum
;
3919 else if (att
->Type
== GL_NONE
) {
3920 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3921 _mesa_enum_to_string(pname
));
3924 mesa_format format
= att
->Renderbuffer
->Format
;
3926 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
3929 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
3930 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
3931 * generate an INVALID_OPERATION error.
3933 if (_mesa_is_gles3(ctx
) &&
3934 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3935 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3937 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
3938 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
3942 if (format
== MESA_FORMAT_S_UINT8
) {
3946 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
3947 /* depends on the attachment parameter */
3948 if (attachment
== GL_STENCIL_ATTACHMENT
) {
3956 *params
= _mesa_get_format_datatype(format
);
3960 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
3961 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
3962 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
3963 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
3964 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
3965 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
3966 if ((!_mesa_is_desktop_gl(ctx
) ||
3967 !ctx
->Extensions
.ARB_framebuffer_object
)
3968 && !_mesa_is_gles3(ctx
)) {
3969 goto invalid_pname_enum
;
3971 else if (att
->Type
== GL_NONE
) {
3972 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3973 _mesa_enum_to_string(pname
));
3975 else if (att
->Texture
) {
3976 const struct gl_texture_image
*texImage
=
3977 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
3980 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
3981 texImage
->TexFormat
);
3987 else if (att
->Renderbuffer
) {
3988 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
3989 att
->Renderbuffer
->Format
);
3992 _mesa_problem(ctx
, "%s: invalid FBO attachment structure", caller
);
3995 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
3996 if (!_mesa_has_geometry_shaders(ctx
)) {
3997 goto invalid_pname_enum
;
3998 } else if (att
->Type
== GL_TEXTURE
) {
3999 *params
= att
->Layered
;
4000 } else if (att
->Type
== GL_NONE
) {
4001 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4002 _mesa_enum_to_string(pname
));
4004 goto invalid_pname_enum
;
4008 goto invalid_pname_enum
;
4014 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
4015 _mesa_enum_to_string(pname
));
4021 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
4022 GLenum pname
, GLint
*params
)
4024 GET_CURRENT_CONTEXT(ctx
);
4025 struct gl_framebuffer
*buffer
;
4027 buffer
= get_framebuffer_target(ctx
, target
);
4029 _mesa_error(ctx
, GL_INVALID_ENUM
,
4030 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
4031 _mesa_enum_to_string(target
));
4035 _mesa_get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4037 "glGetFramebufferAttachmentParameteriv");
4042 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
4044 GLenum pname
, GLint
*params
)
4046 GET_CURRENT_CONTEXT(ctx
);
4047 struct gl_framebuffer
*buffer
;
4050 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4051 "glGetNamedFramebufferAttachmentParameteriv");
4057 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
4058 * 4.5 core spec (30.10.2014, PDF page 314):
4059 * "If framebuffer is zero, then the default draw framebuffer is
4062 buffer
= ctx
->WinSysDrawBuffer
;
4065 _mesa_get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4067 "glGetNamedFramebufferAttachmentParameteriv");
4072 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
4075 GET_CURRENT_CONTEXT(ctx
);
4076 struct gl_framebuffer
*fb
= NULL
;
4078 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4079 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4080 "glNamedFramebufferParameteri("
4081 "ARB_framebuffer_no_attachments not implemented)");
4085 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4086 "glNamedFramebufferParameteri");
4089 framebuffer_parameteri(ctx
, fb
, pname
, param
,
4090 "glNamedFramebufferParameteriv");
4096 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
4099 GET_CURRENT_CONTEXT(ctx
);
4100 struct gl_framebuffer
*fb
;
4102 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4103 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4104 "glNamedFramebufferParameteriv("
4105 "ARB_framebuffer_no_attachments not implemented)");
4110 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4111 "glGetNamedFramebufferParameteriv");
4113 fb
= ctx
->WinSysDrawBuffer
;
4117 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4118 "glGetNamedFramebufferParameteriv");
4124 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4125 struct gl_framebuffer
*fb
,
4126 GLsizei numAttachments
,
4127 const GLenum
*attachments
, GLint x
, GLint y
,
4128 GLsizei width
, GLsizei height
, const char *name
)
4132 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4133 * Spec (2.2.2015, PDF page 522) says:
4134 * "An INVALID_VALUE error is generated if numAttachments, width, or
4135 * height is negative."
4137 if (numAttachments
< 0) {
4138 _mesa_error(ctx
, GL_INVALID_VALUE
,
4139 "%s(numAttachments < 0)", name
);
4144 _mesa_error(ctx
, GL_INVALID_VALUE
,
4145 "%s(width < 0)", name
);
4150 _mesa_error(ctx
, GL_INVALID_VALUE
,
4151 "%s(height < 0)", name
);
4155 /* The GL_ARB_invalidate_subdata spec says:
4157 * "If an attachment is specified that does not exist in the
4158 * framebuffer bound to <target>, it is ignored."
4162 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4163 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4164 * INVALID_OPERATION is generated."
4166 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4167 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4168 * set of retrictions).
4170 for (i
= 0; i
< numAttachments
; i
++) {
4171 if (_mesa_is_winsys_fbo(fb
)) {
4172 switch (attachments
[i
]) {
4178 /* Accumulation buffers and auxilary buffers were removed in
4179 * OpenGL 3.1, and they never existed in OpenGL ES.
4181 if (ctx
->API
!= API_OPENGL_COMPAT
)
4191 case GL_FRONT_RIGHT
:
4192 if (!_mesa_is_desktop_gl(ctx
))
4199 switch (attachments
[i
]) {
4200 case GL_DEPTH_ATTACHMENT
:
4201 case GL_STENCIL_ATTACHMENT
:
4203 case GL_DEPTH_STENCIL_ATTACHMENT
:
4204 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4205 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4206 * extension does not make this attachment point valid on ES 2.0.
4208 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4211 case GL_COLOR_ATTACHMENT0
:
4212 case GL_COLOR_ATTACHMENT1
:
4213 case GL_COLOR_ATTACHMENT2
:
4214 case GL_COLOR_ATTACHMENT3
:
4215 case GL_COLOR_ATTACHMENT4
:
4216 case GL_COLOR_ATTACHMENT5
:
4217 case GL_COLOR_ATTACHMENT6
:
4218 case GL_COLOR_ATTACHMENT7
:
4219 case GL_COLOR_ATTACHMENT8
:
4220 case GL_COLOR_ATTACHMENT9
:
4221 case GL_COLOR_ATTACHMENT10
:
4222 case GL_COLOR_ATTACHMENT11
:
4223 case GL_COLOR_ATTACHMENT12
:
4224 case GL_COLOR_ATTACHMENT13
:
4225 case GL_COLOR_ATTACHMENT14
:
4226 case GL_COLOR_ATTACHMENT15
: {
4227 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4228 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4229 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4230 "%s(attachment >= max. color attachments)", name
);
4241 /* We don't actually do anything for this yet. Just return after
4242 * validating the parameters and generating the required errors.
4247 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4248 _mesa_enum_to_string(attachments
[i
]));
4254 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4255 const GLenum
*attachments
, GLint x
, GLint y
,
4256 GLsizei width
, GLsizei height
)
4258 struct gl_framebuffer
*fb
;
4259 GET_CURRENT_CONTEXT(ctx
);
4261 fb
= get_framebuffer_target(ctx
, target
);
4263 _mesa_error(ctx
, GL_INVALID_ENUM
,
4264 "glInvalidateSubFramebuffer(invalid target %s)",
4265 _mesa_enum_to_string(target
));
4269 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4270 x
, y
, width
, height
,
4271 "glInvalidateSubFramebuffer");
4276 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4277 GLsizei numAttachments
,
4278 const GLenum
*attachments
,
4280 GLsizei width
, GLsizei height
)
4282 struct gl_framebuffer
*fb
;
4283 GET_CURRENT_CONTEXT(ctx
);
4285 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4286 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4287 * default draw framebuffer is affected."
4290 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4291 "glInvalidateNamedFramebufferSubData");
4296 fb
= ctx
->WinSysDrawBuffer
;
4298 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4299 x
, y
, width
, height
,
4300 "glInvalidateNamedFramebufferSubData");
4305 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4306 const GLenum
*attachments
)
4308 struct gl_framebuffer
*fb
;
4309 GET_CURRENT_CONTEXT(ctx
);
4311 fb
= get_framebuffer_target(ctx
, target
);
4313 _mesa_error(ctx
, GL_INVALID_ENUM
,
4314 "glInvalidateFramebuffer(invalid target %s)",
4315 _mesa_enum_to_string(target
));
4319 /* The GL_ARB_invalidate_subdata spec says:
4323 * void InvalidateFramebuffer(enum target,
4324 * sizei numAttachments,
4325 * const enum *attachments);
4327 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4328 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4329 * <MAX_VIEWPORT_DIMS[1]> respectively."
4331 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4333 ctx
->Const
.MaxViewportWidth
,
4334 ctx
->Const
.MaxViewportHeight
,
4335 "glInvalidateFramebuffer");
4340 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4341 GLsizei numAttachments
,
4342 const GLenum
*attachments
)
4344 struct gl_framebuffer
*fb
;
4345 GET_CURRENT_CONTEXT(ctx
);
4347 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4348 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4349 * default draw framebuffer is affected."
4352 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4353 "glInvalidateNamedFramebufferData");
4358 fb
= ctx
->WinSysDrawBuffer
;
4360 /* The GL_ARB_invalidate_subdata spec says:
4364 * void InvalidateFramebuffer(enum target,
4365 * sizei numAttachments,
4366 * const enum *attachments);
4368 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4369 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4370 * <MAX_VIEWPORT_DIMS[1]> respectively."
4372 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4374 ctx
->Const
.MaxViewportWidth
,
4375 ctx
->Const
.MaxViewportHeight
,
4376 "glInvalidateNamedFramebufferData");
4381 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4382 const GLenum
*attachments
)
4384 struct gl_framebuffer
*fb
;
4387 GET_CURRENT_CONTEXT(ctx
);
4389 fb
= get_framebuffer_target(ctx
, target
);
4391 _mesa_error(ctx
, GL_INVALID_ENUM
,
4392 "glDiscardFramebufferEXT(target %s)",
4393 _mesa_enum_to_string(target
));
4397 if (numAttachments
< 0) {
4398 _mesa_error(ctx
, GL_INVALID_VALUE
,
4399 "glDiscardFramebufferEXT(numAttachments < 0)");
4403 for (i
= 0; i
< numAttachments
; i
++) {
4404 switch (attachments
[i
]) {
4408 if (_mesa_is_user_fbo(fb
))
4411 case GL_COLOR_ATTACHMENT0
:
4412 case GL_DEPTH_ATTACHMENT
:
4413 case GL_STENCIL_ATTACHMENT
:
4414 if (_mesa_is_winsys_fbo(fb
))
4422 if (ctx
->Driver
.DiscardFramebuffer
)
4423 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4428 _mesa_error(ctx
, GL_INVALID_ENUM
,
4429 "glDiscardFramebufferEXT(attachment %s)",
4430 _mesa_enum_to_string(attachments
[i
]));