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 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1482 GLenum pname
, GLint
*params
, const char *func
)
1485 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1486 *params
= fb
->DefaultGeometry
.Width
;
1488 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1489 *params
= fb
->DefaultGeometry
.Height
;
1491 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1493 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1494 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1496 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1497 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1500 *params
= fb
->DefaultGeometry
.Layers
;
1502 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1503 *params
= fb
->DefaultGeometry
.NumSamples
;
1505 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1506 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1509 _mesa_error(ctx
, GL_INVALID_ENUM
,
1510 "%s(pname=0x%x)", func
, pname
);
1515 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1517 GET_CURRENT_CONTEXT(ctx
);
1518 struct gl_framebuffer
*fb
;
1520 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1521 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1522 "glGetFramebufferParameteriv not supported "
1523 "(ARB_framebuffer_no_attachments not implemented)");
1527 fb
= get_framebuffer_target(ctx
, target
);
1529 _mesa_error(ctx
, GL_INVALID_ENUM
,
1530 "glGetFramebufferParameteriv(target=0x%x)", target
);
1534 /* check framebuffer binding */
1535 if (_mesa_is_winsys_fbo(fb
)) {
1536 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1537 "glGetFramebufferParameteriv");
1541 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1542 "glGetFramebufferParameteriv");
1547 * Remove the specified renderbuffer or texture from any attachment point in
1551 * \c true if the renderbuffer was detached from an attachment point. \c
1555 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1556 struct gl_framebuffer
*fb
,
1560 bool progress
= false;
1562 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1563 if (fb
->Attachment
[i
].Texture
== att
1564 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1565 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1570 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1571 * Completeness," of the OpenGL 3.1 spec says:
1573 * "Performing any of the following actions may change whether the
1574 * framebuffer is considered complete or incomplete:
1578 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1579 * containing an image that is attached to a framebuffer object
1580 * that is bound to the framebuffer."
1583 invalidate_framebuffer(fb
);
1590 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1593 GET_CURRENT_CONTEXT(ctx
);
1596 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1600 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1602 for (i
= 0; i
< n
; i
++) {
1603 if (renderbuffers
[i
] > 0) {
1604 struct gl_renderbuffer
*rb
;
1605 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1607 /* check if deleting currently bound renderbuffer object */
1608 if (rb
== ctx
->CurrentRenderbuffer
) {
1610 assert(rb
->RefCount
>= 2);
1611 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1614 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1615 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1616 * of the OpenGL 3.1 spec says:
1618 * "If a renderbuffer object is deleted while its image is
1619 * attached to one or more attachment points in the currently
1620 * bound framebuffer, then it is as if FramebufferRenderbuffer
1621 * had been called, with a renderbuffer of 0, for each
1622 * attachment point to which this image was attached in the
1623 * currently bound framebuffer. In other words, this
1624 * renderbuffer image is first detached from all attachment
1625 * points in the currently bound framebuffer. Note that the
1626 * renderbuffer image is specifically not detached from any
1627 * non-bound framebuffers. Detaching the image from any
1628 * non-bound framebuffers is the responsibility of the
1631 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1632 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1634 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1635 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1636 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1639 /* Remove from hash table immediately, to free the ID.
1640 * But the object will not be freed until it's no longer
1641 * referenced anywhere else.
1643 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1645 if (rb
!= &DummyRenderbuffer
) {
1646 /* no longer referenced by hash table */
1647 _mesa_reference_renderbuffer(&rb
, NULL
);
1655 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1658 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1663 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1670 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1672 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1674 for (i
= 0; i
< n
; i
++) {
1675 GLuint name
= first
+ i
;
1676 renderbuffers
[i
] = name
;
1679 allocate_renderbuffer_locked(ctx
, name
, func
);
1681 /* insert a dummy renderbuffer into the hash table */
1682 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1683 &DummyRenderbuffer
);
1687 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1692 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1694 GET_CURRENT_CONTEXT(ctx
);
1695 create_render_buffers(ctx
, n
, renderbuffers
, false);
1700 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1702 GET_CURRENT_CONTEXT(ctx
);
1703 create_render_buffers(ctx
, n
, renderbuffers
, true);
1708 * Given an internal format token for a render buffer, return the
1709 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1710 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1711 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1713 * This is similar to _mesa_base_tex_format() but the set of valid
1714 * internal formats is different.
1716 * Note that even if a format is determined to be legal here, validation
1717 * of the FBO may fail if the format is not supported by the driver/GPU.
1719 * \param internalFormat as passed to glRenderbufferStorage()
1720 * \return the base internal format, or 0 if internalFormat is illegal
1723 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1726 * Notes: some formats such as alpha, luminance, etc. were added
1727 * with GL_ARB_framebuffer_object.
1729 switch (internalFormat
) {
1735 return (ctx
->API
== API_OPENGL_COMPAT
&&
1736 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
1740 case GL_LUMINANCE12
:
1741 case GL_LUMINANCE16
:
1742 return (ctx
->API
== API_OPENGL_COMPAT
&&
1743 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
1744 case GL_LUMINANCE_ALPHA
:
1745 case GL_LUMINANCE4_ALPHA4
:
1746 case GL_LUMINANCE6_ALPHA2
:
1747 case GL_LUMINANCE8_ALPHA8
:
1748 case GL_LUMINANCE12_ALPHA4
:
1749 case GL_LUMINANCE12_ALPHA12
:
1750 case GL_LUMINANCE16_ALPHA16
:
1751 return (ctx
->API
== API_OPENGL_COMPAT
&&
1752 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
1756 case GL_INTENSITY12
:
1757 case GL_INTENSITY16
:
1758 return (ctx
->API
== API_OPENGL_COMPAT
&&
1759 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
1769 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1771 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1780 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1782 case GL_SRGB8_ALPHA8_EXT
:
1783 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1784 case GL_STENCIL_INDEX
:
1785 case GL_STENCIL_INDEX1_EXT
:
1786 case GL_STENCIL_INDEX4_EXT
:
1787 case GL_STENCIL_INDEX16_EXT
:
1788 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1789 * OpenGL ES, but Mesa does not currently support them.
1791 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1792 case GL_STENCIL_INDEX8_EXT
:
1793 return GL_STENCIL_INDEX
;
1794 case GL_DEPTH_COMPONENT
:
1795 case GL_DEPTH_COMPONENT32
:
1796 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1797 case GL_DEPTH_COMPONENT16
:
1798 case GL_DEPTH_COMPONENT24
:
1799 return GL_DEPTH_COMPONENT
;
1800 case GL_DEPTH_STENCIL
:
1801 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
1802 case GL_DEPTH24_STENCIL8
:
1803 return GL_DEPTH_STENCIL
;
1804 case GL_DEPTH_COMPONENT32F
:
1805 return ctx
->Version
>= 30
1806 || (ctx
->API
== API_OPENGL_COMPAT
&&
1807 ctx
->Extensions
.ARB_depth_buffer_float
)
1808 ? GL_DEPTH_COMPONENT
: 0;
1809 case GL_DEPTH32F_STENCIL8
:
1810 return ctx
->Version
>= 30
1811 || (ctx
->API
== API_OPENGL_COMPAT
&&
1812 ctx
->Extensions
.ARB_depth_buffer_float
)
1813 ? GL_DEPTH_STENCIL
: 0;
1816 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1819 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1823 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1826 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1828 /* signed normalized texture formats */
1832 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1837 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1841 case GL_RGB16_SNORM
:
1842 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1845 case GL_RGBA8_SNORM
:
1846 case GL_RGBA16_SNORM
:
1847 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1849 case GL_ALPHA_SNORM
:
1850 case GL_ALPHA8_SNORM
:
1851 case GL_ALPHA16_SNORM
:
1852 return ctx
->API
== API_OPENGL_COMPAT
&&
1853 ctx
->Extensions
.EXT_texture_snorm
&&
1854 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1855 case GL_LUMINANCE_SNORM
:
1856 case GL_LUMINANCE8_SNORM
:
1857 case GL_LUMINANCE16_SNORM
:
1858 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1860 case GL_LUMINANCE_ALPHA_SNORM
:
1861 case GL_LUMINANCE8_ALPHA8_SNORM
:
1862 case GL_LUMINANCE16_ALPHA16_SNORM
:
1863 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1864 ? GL_LUMINANCE_ALPHA
: 0;
1865 case GL_INTENSITY_SNORM
:
1866 case GL_INTENSITY8_SNORM
:
1867 case GL_INTENSITY16_SNORM
:
1868 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1873 return ((_mesa_is_desktop_gl(ctx
) &&
1874 ctx
->Extensions
.ARB_texture_rg
&&
1875 ctx
->Extensions
.ARB_texture_float
) ||
1876 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1880 return ((_mesa_is_desktop_gl(ctx
) &&
1881 ctx
->Extensions
.ARB_texture_rg
&&
1882 ctx
->Extensions
.ARB_texture_float
) ||
1883 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1887 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1891 return ((_mesa_is_desktop_gl(ctx
) &&
1892 ctx
->Extensions
.ARB_texture_float
) ||
1893 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1895 case GL_ALPHA16F_ARB
:
1896 case GL_ALPHA32F_ARB
:
1897 return ctx
->API
== API_OPENGL_COMPAT
&&
1898 ctx
->Extensions
.ARB_texture_float
&&
1899 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1900 case GL_LUMINANCE16F_ARB
:
1901 case GL_LUMINANCE32F_ARB
:
1902 return ctx
->API
== API_OPENGL_COMPAT
&&
1903 ctx
->Extensions
.ARB_texture_float
&&
1904 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1905 case GL_LUMINANCE_ALPHA16F_ARB
:
1906 case GL_LUMINANCE_ALPHA32F_ARB
:
1907 return ctx
->API
== API_OPENGL_COMPAT
&&
1908 ctx
->Extensions
.ARB_texture_float
&&
1909 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1910 case GL_INTENSITY16F_ARB
:
1911 case GL_INTENSITY32F_ARB
:
1912 return ctx
->API
== API_OPENGL_COMPAT
&&
1913 ctx
->Extensions
.ARB_texture_float
&&
1914 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1915 case GL_R11F_G11F_B10F
:
1916 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1917 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1920 case GL_RGBA8UI_EXT
:
1921 case GL_RGBA16UI_EXT
:
1922 case GL_RGBA32UI_EXT
:
1924 case GL_RGBA16I_EXT
:
1925 case GL_RGBA32I_EXT
:
1926 return ctx
->Version
>= 30
1927 || (_mesa_is_desktop_gl(ctx
) &&
1928 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
1931 case GL_RGB16UI_EXT
:
1932 case GL_RGB32UI_EXT
:
1936 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
1944 return ctx
->Version
>= 30
1945 || (_mesa_is_desktop_gl(ctx
) &&
1946 ctx
->Extensions
.ARB_texture_rg
&&
1947 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
1955 return ctx
->Version
>= 30
1956 || (_mesa_is_desktop_gl(ctx
) &&
1957 ctx
->Extensions
.ARB_texture_rg
&&
1958 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
1960 case GL_INTENSITY8I_EXT
:
1961 case GL_INTENSITY8UI_EXT
:
1962 case GL_INTENSITY16I_EXT
:
1963 case GL_INTENSITY16UI_EXT
:
1964 case GL_INTENSITY32I_EXT
:
1965 case GL_INTENSITY32UI_EXT
:
1966 return ctx
->API
== API_OPENGL_COMPAT
&&
1967 ctx
->Extensions
.EXT_texture_integer
&&
1968 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1970 case GL_LUMINANCE8I_EXT
:
1971 case GL_LUMINANCE8UI_EXT
:
1972 case GL_LUMINANCE16I_EXT
:
1973 case GL_LUMINANCE16UI_EXT
:
1974 case GL_LUMINANCE32I_EXT
:
1975 case GL_LUMINANCE32UI_EXT
:
1976 return ctx
->API
== API_OPENGL_COMPAT
&&
1977 ctx
->Extensions
.EXT_texture_integer
&&
1978 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1980 case GL_LUMINANCE_ALPHA8I_EXT
:
1981 case GL_LUMINANCE_ALPHA8UI_EXT
:
1982 case GL_LUMINANCE_ALPHA16I_EXT
:
1983 case GL_LUMINANCE_ALPHA16UI_EXT
:
1984 case GL_LUMINANCE_ALPHA32I_EXT
:
1985 case GL_LUMINANCE_ALPHA32UI_EXT
:
1986 return ctx
->API
== API_OPENGL_COMPAT
&&
1987 ctx
->Extensions
.EXT_texture_integer
&&
1988 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1990 case GL_ALPHA8I_EXT
:
1991 case GL_ALPHA8UI_EXT
:
1992 case GL_ALPHA16I_EXT
:
1993 case GL_ALPHA16UI_EXT
:
1994 case GL_ALPHA32I_EXT
:
1995 case GL_ALPHA32UI_EXT
:
1996 return ctx
->API
== API_OPENGL_COMPAT
&&
1997 ctx
->Extensions
.EXT_texture_integer
&&
1998 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2001 return (_mesa_is_desktop_gl(ctx
) &&
2002 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
2003 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2006 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2015 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2018 invalidate_rb(GLuint key
, void *data
, void *userData
)
2020 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2021 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2023 /* If this is a user-created FBO */
2024 if (_mesa_is_user_fbo(fb
)) {
2026 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2027 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2028 if (att
->Type
== GL_RENDERBUFFER
&&
2029 att
->Renderbuffer
== rb
) {
2030 /* Mark fb status as indeterminate to force re-validation */
2039 /** sentinal value, see below */
2040 #define NO_SAMPLES 1000
2043 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2044 GLenum internalFormat
, GLsizei width
,
2045 GLsizei height
, GLsizei samples
)
2047 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2049 assert(baseFormat
!= 0);
2050 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2051 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2052 assert(samples
!= NO_SAMPLES
);
2054 assert(samples
> 0);
2055 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2056 internalFormat
, samples
) == GL_NO_ERROR
);
2059 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2061 if (rb
->InternalFormat
== internalFormat
&&
2062 rb
->Width
== (GLuint
) width
&&
2063 rb
->Height
== (GLuint
) height
&&
2064 rb
->NumSamples
== samples
) {
2065 /* no change in allocation needed */
2069 /* These MUST get set by the AllocStorage func */
2070 rb
->Format
= MESA_FORMAT_NONE
;
2071 rb
->NumSamples
= samples
;
2073 /* Now allocate the storage */
2074 assert(rb
->AllocStorage
);
2075 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2076 /* No error - check/set fields now */
2077 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2078 assert(rb
->Width
== (GLuint
) width
);
2079 assert(rb
->Height
== (GLuint
) height
);
2080 rb
->InternalFormat
= internalFormat
;
2081 rb
->_BaseFormat
= baseFormat
;
2082 assert(rb
->_BaseFormat
!= 0);
2085 /* Probably ran out of memory - clear the fields */
2088 rb
->Format
= MESA_FORMAT_NONE
;
2089 rb
->InternalFormat
= GL_NONE
;
2090 rb
->_BaseFormat
= GL_NONE
;
2094 /* Invalidate the framebuffers the renderbuffer is attached in. */
2095 if (rb
->AttachedAnytime
) {
2096 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2101 * Helper function used by renderbuffer_storage_direct() and
2102 * renderbuffer_storage_target().
2103 * samples will be NO_SAMPLES if called by a non-multisample function.
2106 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2107 GLenum internalFormat
, GLsizei width
,
2108 GLsizei height
, GLsizei samples
, const char *func
)
2111 GLenum sample_count_error
;
2113 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2114 if (baseFormat
== 0) {
2115 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2116 func
, _mesa_enum_to_string(internalFormat
));
2120 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2121 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2126 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2127 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2132 if (samples
== NO_SAMPLES
) {
2133 /* NumSamples == 0 indicates non-multisampling */
2137 /* check the sample count;
2138 * note: driver may choose to use more samples than what's requested
2140 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2141 internalFormat
, samples
);
2143 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2145 * "If a negative number is provided where an argument of type sizei or
2146 * sizeiptr is specified, the error INVALID VALUE is generated."
2149 sample_count_error
= GL_INVALID_VALUE
;
2152 if (sample_count_error
!= GL_NO_ERROR
) {
2153 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
2158 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
);
2162 * Helper function used by _mesa_NamedRenderbufferStorage*().
2163 * samples will be NO_SAMPLES if called by a non-multisample function.
2166 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2167 GLsizei width
, GLsizei height
, GLsizei samples
,
2170 GET_CURRENT_CONTEXT(ctx
);
2172 if (MESA_VERBOSE
& VERBOSE_API
) {
2173 if (samples
== NO_SAMPLES
)
2174 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2176 _mesa_enum_to_string(internalFormat
),
2179 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2181 _mesa_enum_to_string(internalFormat
),
2182 width
, height
, samples
);
2185 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2186 if (!rb
|| rb
== &DummyRenderbuffer
) {
2187 /* ID was reserved, but no real renderbuffer object made yet */
2188 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2189 func
, renderbuffer
);
2193 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
, func
);
2197 * Helper function used by _mesa_RenderbufferStorage() and
2198 * _mesa_RenderbufferStorageMultisample().
2199 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2202 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2203 GLsizei width
, GLsizei height
, GLsizei samples
,
2206 GET_CURRENT_CONTEXT(ctx
);
2208 if (MESA_VERBOSE
& VERBOSE_API
) {
2209 if (samples
== NO_SAMPLES
)
2210 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2212 _mesa_enum_to_string(target
),
2213 _mesa_enum_to_string(internalFormat
),
2216 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2218 _mesa_enum_to_string(target
),
2219 _mesa_enum_to_string(internalFormat
),
2220 width
, height
, samples
);
2223 if (target
!= GL_RENDERBUFFER_EXT
) {
2224 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2228 if (!ctx
->CurrentRenderbuffer
) {
2229 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2234 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2235 height
, samples
, func
);
2240 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2242 struct gl_renderbuffer
*rb
;
2243 GET_CURRENT_CONTEXT(ctx
);
2245 if (!ctx
->Extensions
.OES_EGL_image
) {
2246 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2247 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2251 if (target
!= GL_RENDERBUFFER
) {
2252 _mesa_error(ctx
, GL_INVALID_ENUM
,
2253 "EGLImageTargetRenderbufferStorageOES");
2257 rb
= ctx
->CurrentRenderbuffer
;
2259 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2260 "EGLImageTargetRenderbufferStorageOES");
2264 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2266 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2271 * Helper function for _mesa_GetRenderbufferParameteriv() and
2272 * _mesa_GetFramebufferAttachmentParameteriv()
2273 * We have to be careful to respect the base format. For example, if a
2274 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2275 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2276 * we need to return zero.
2279 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2281 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2282 return _mesa_get_format_bits(format
, pname
);
2290 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2291 GLsizei width
, GLsizei height
)
2293 /* GL_ARB_fbo says calling this function is equivalent to calling
2294 * glRenderbufferStorageMultisample() with samples=0. We pass in
2295 * a token value here just for error reporting purposes.
2297 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2298 NO_SAMPLES
, "glRenderbufferStorage");
2303 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2304 GLenum internalFormat
,
2305 GLsizei width
, GLsizei height
)
2307 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2308 samples
, "glRenderbufferStorageMultisample");
2313 * OpenGL ES version of glRenderBufferStorage.
2316 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2317 GLsizei width
, GLsizei height
)
2319 switch (internalFormat
) {
2321 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2322 /* choose a closest format */
2323 internalFormat
= GL_RGB5
;
2329 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0,
2330 "glRenderbufferStorageEXT");
2334 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2335 GLsizei width
, GLsizei height
)
2337 /* GL_ARB_fbo says calling this function is equivalent to calling
2338 * glRenderbufferStorageMultisample() with samples=0. We pass in
2339 * a token value here just for error reporting purposes.
2341 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2342 NO_SAMPLES
, "glNamedRenderbufferStorage");
2346 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2347 GLenum internalformat
,
2348 GLsizei width
, GLsizei height
)
2350 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2352 "glNamedRenderbufferStorageMultisample");
2357 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2358 struct gl_renderbuffer
*rb
, GLenum pname
,
2359 GLint
*params
, const char *func
)
2361 /* No need to flush here since we're just quering state which is
2362 * not effected by rendering.
2366 case GL_RENDERBUFFER_WIDTH_EXT
:
2367 *params
= rb
->Width
;
2369 case GL_RENDERBUFFER_HEIGHT_EXT
:
2370 *params
= rb
->Height
;
2372 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2373 *params
= rb
->InternalFormat
;
2375 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2376 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2377 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2378 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2379 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2380 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2381 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2383 case GL_RENDERBUFFER_SAMPLES
:
2384 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2385 || _mesa_is_gles3(ctx
)) {
2386 *params
= rb
->NumSamples
;
2391 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2392 _mesa_enum_to_string(pname
));
2399 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2401 GET_CURRENT_CONTEXT(ctx
);
2403 if (target
!= GL_RENDERBUFFER_EXT
) {
2404 _mesa_error(ctx
, GL_INVALID_ENUM
,
2405 "glGetRenderbufferParameterivEXT(target)");
2409 if (!ctx
->CurrentRenderbuffer
) {
2410 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2411 "(no renderbuffer bound)");
2415 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2416 params
, "glGetRenderbufferParameteriv");
2421 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2424 GET_CURRENT_CONTEXT(ctx
);
2426 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2427 if (!rb
|| rb
== &DummyRenderbuffer
) {
2428 /* ID was reserved, but no real renderbuffer object made yet */
2429 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2430 "(invalid renderbuffer %i)", renderbuffer
);
2434 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2435 "glGetNamedRenderbufferParameteriv");
2439 GLboolean GLAPIENTRY
2440 _mesa_IsFramebuffer(GLuint framebuffer
)
2442 GET_CURRENT_CONTEXT(ctx
);
2443 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2445 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2446 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2454 * Check if any of the attachments of the given framebuffer are textures
2455 * (render to texture). Call ctx->Driver.RenderTexture() for such
2459 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2462 assert(ctx
->Driver
.RenderTexture
);
2464 if (_mesa_is_winsys_fbo(fb
))
2465 return; /* can't render to texture with winsys framebuffers */
2467 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2468 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2469 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2470 && driver_RenderTexture_is_safe(att
)) {
2471 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2478 * Examine all the framebuffer's attachments to see if any are textures.
2479 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2480 * notify the device driver that the texture image may have changed.
2483 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2485 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2486 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2489 if (ctx
->Driver
.FinishRenderTexture
) {
2491 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2492 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2493 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2494 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2495 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2503 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2505 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2506 GLboolean bindReadBuf
, bindDrawBuf
;
2507 GET_CURRENT_CONTEXT(ctx
);
2510 case GL_DRAW_FRAMEBUFFER_EXT
:
2511 bindDrawBuf
= GL_TRUE
;
2512 bindReadBuf
= GL_FALSE
;
2514 case GL_READ_FRAMEBUFFER_EXT
:
2515 bindDrawBuf
= GL_FALSE
;
2516 bindReadBuf
= GL_TRUE
;
2518 case GL_FRAMEBUFFER_EXT
:
2519 bindDrawBuf
= GL_TRUE
;
2520 bindReadBuf
= GL_TRUE
;
2523 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2528 /* Binding a user-created framebuffer object */
2529 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2530 if (newDrawFb
== &DummyFramebuffer
) {
2531 /* ID was reserved, but no real framebuffer object made yet */
2534 else if (!newDrawFb
&& !allow_user_names
) {
2535 /* All FBO IDs must be Gen'd */
2536 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2541 /* create new framebuffer object */
2542 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2544 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2547 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2549 newReadFb
= newDrawFb
;
2552 /* Binding the window system framebuffer (which was originally set
2553 * with MakeCurrent).
2555 newDrawFb
= ctx
->WinSysDrawBuffer
;
2556 newReadFb
= ctx
->WinSysReadBuffer
;
2559 _mesa_bind_framebuffers(ctx
,
2560 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2561 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2565 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2566 struct gl_framebuffer
*newDrawFb
,
2567 struct gl_framebuffer
*newReadFb
)
2569 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
2570 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
2571 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
2572 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
2575 assert(newDrawFb
!= &DummyFramebuffer
);
2578 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2580 * We also check if we're beginning and/or ending render-to-texture.
2581 * When a framebuffer with texture attachments is unbound, call
2582 * ctx->Driver.FinishRenderTexture().
2583 * When a framebuffer with texture attachments is bound, call
2584 * ctx->Driver.RenderTexture().
2586 * Note that if the ReadBuffer has texture attachments we don't consider
2587 * that a render-to-texture case.
2590 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2592 /* check if old readbuffer was render-to-texture */
2593 check_end_texture_render(ctx
, oldReadFb
);
2595 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2599 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2601 /* check if old framebuffer had any texture attachments */
2603 check_end_texture_render(ctx
, oldDrawFb
);
2605 /* check if newly bound framebuffer has any texture attachments */
2606 check_begin_texture_render(ctx
, newDrawFb
);
2608 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2611 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2612 /* The few classic drivers that actually hook this function really only
2613 * want to know if the draw framebuffer changed.
2615 ctx
->Driver
.BindFramebuffer(ctx
,
2616 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
2617 newDrawFb
, newReadFb
);
2622 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2624 GET_CURRENT_CONTEXT(ctx
);
2626 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2627 * point, but they allow the use of user-generated names.
2629 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2634 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2636 /* This function should not be in the dispatch table for core profile /
2637 * OpenGL 3.1, so execution should never get here in those cases -- no
2638 * need for an explicit test.
2640 bind_framebuffer(target
, framebuffer
, true);
2645 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2648 GET_CURRENT_CONTEXT(ctx
);
2651 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
2655 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2657 for (i
= 0; i
< n
; i
++) {
2658 if (framebuffers
[i
] > 0) {
2659 struct gl_framebuffer
*fb
;
2660 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2662 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2664 /* check if deleting currently bound framebuffer object */
2665 if (fb
== ctx
->DrawBuffer
) {
2667 assert(fb
->RefCount
>= 2);
2668 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2670 if (fb
== ctx
->ReadBuffer
) {
2672 assert(fb
->RefCount
>= 2);
2673 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2676 /* remove from hash table immediately, to free the ID */
2677 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2679 if (fb
!= &DummyFramebuffer
) {
2680 /* But the object will not be freed until it's no longer
2681 * bound in any context.
2683 _mesa_reference_framebuffer(&fb
, NULL
);
2692 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2693 * It is not exposed to the rest of Mesa to encourage the use of
2694 * nameless buffers in driver internals.
2697 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
2699 GET_CURRENT_CONTEXT(ctx
);
2702 struct gl_framebuffer
*fb
;
2704 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
2707 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
2714 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
2716 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2718 for (i
= 0; i
< n
; i
++) {
2719 GLuint name
= first
+ i
;
2720 framebuffers
[i
] = name
;
2723 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
2725 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2726 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
2731 fb
= &DummyFramebuffer
;
2733 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
2736 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2741 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2743 create_framebuffers(n
, framebuffers
, false);
2748 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2750 create_framebuffers(n
, framebuffers
, true);
2755 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
2756 struct gl_framebuffer
*buffer
)
2758 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2760 if (_mesa_is_winsys_fbo(buffer
)) {
2761 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2762 if (buffer
!= &IncompleteFramebuffer
) {
2763 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2765 return GL_FRAMEBUFFER_UNDEFINED
;
2769 /* No need to flush here */
2771 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2772 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2775 return buffer
->_Status
;
2780 _mesa_CheckFramebufferStatus(GLenum target
)
2782 struct gl_framebuffer
*fb
;
2783 GET_CURRENT_CONTEXT(ctx
);
2785 if (MESA_VERBOSE
& VERBOSE_API
)
2786 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2787 _mesa_enum_to_string(target
));
2789 fb
= get_framebuffer_target(ctx
, target
);
2791 _mesa_error(ctx
, GL_INVALID_ENUM
,
2792 "glCheckFramebufferStatus(invalid target %s)",
2793 _mesa_enum_to_string(target
));
2797 return _mesa_check_framebuffer_status(ctx
, fb
);
2802 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
2804 struct gl_framebuffer
*fb
;
2805 GET_CURRENT_CONTEXT(ctx
);
2807 /* Validate the target (for conformance's sake) and grab a reference to the
2808 * default framebuffer in case framebuffer = 0.
2809 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
2810 * (30.10.2014, PDF page 336) says:
2811 * "If framebuffer is zero, then the status of the default read or
2812 * draw framebuffer (as determined by target) is returned."
2815 case GL_DRAW_FRAMEBUFFER
:
2816 case GL_FRAMEBUFFER
:
2817 fb
= ctx
->WinSysDrawBuffer
;
2819 case GL_READ_FRAMEBUFFER
:
2820 fb
= ctx
->WinSysReadBuffer
;
2823 _mesa_error(ctx
, GL_INVALID_ENUM
,
2824 "glCheckNamedFramebufferStatus(invalid target %s)",
2825 _mesa_enum_to_string(target
));
2830 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
2831 "glCheckNamedFramebufferStatus");
2836 return _mesa_check_framebuffer_status(ctx
, fb
);
2841 * Replicate the src attachment point. Used by framebuffer_texture() when
2842 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2843 * GL_STENCIL_ATTACHMENT.
2846 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2847 gl_buffer_index dst
,
2848 gl_buffer_index src
)
2850 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2851 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2853 assert(src_att
->Texture
!= NULL
);
2854 assert(src_att
->Renderbuffer
!= NULL
);
2856 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2857 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2858 dst_att
->Type
= src_att
->Type
;
2859 dst_att
->Complete
= src_att
->Complete
;
2860 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2861 dst_att
->CubeMapFace
= src_att
->CubeMapFace
;
2862 dst_att
->Zoffset
= src_att
->Zoffset
;
2863 dst_att
->Layered
= src_att
->Layered
;
2868 * Common code called by gl*FramebufferTexture*() to retrieve the correct
2869 * texture object pointer.
2871 * \param texObj where the pointer to the texture object is returned. Note
2872 * that a successful call may return texObj = NULL.
2874 * \return true if no errors, false if errors
2877 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
,
2878 bool layered
, const char *caller
,
2879 struct gl_texture_object
**texObj
)
2881 *texObj
= NULL
; /* This will get returned if texture = 0. */
2886 *texObj
= _mesa_lookup_texture(ctx
, texture
);
2887 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
2888 /* Can't render to a non-existent texture object.
2890 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
2891 * Managing Framebuffer Objects specifies a different error
2892 * depending upon the calling function (PDF pages 325-328).
2893 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
2894 * value, while the other commands throw invalid operation (where
2895 * layered = GL_FALSE).
2897 const GLenum error
= layered
? GL_INVALID_VALUE
:
2898 GL_INVALID_OPERATION
;
2899 _mesa_error(ctx
, error
,
2900 "%s(non-existent texture %u)", caller
, texture
);
2909 * Common code called by gl*FramebufferTexture() to verify the texture target
2910 * and decide whether or not the attachment should truly be considered
2913 * \param layered true if attachment should be considered layered, false if
2916 * \return true if no errors, false if errors
2919 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
2920 const char *caller
, GLboolean
*layered
)
2926 case GL_TEXTURE_1D_ARRAY_EXT
:
2927 case GL_TEXTURE_2D_ARRAY_EXT
:
2928 case GL_TEXTURE_CUBE_MAP
:
2929 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2930 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2934 case GL_TEXTURE_RECTANGLE
:
2935 case GL_TEXTURE_2D_MULTISAMPLE
:
2936 /* These texture types are valid to pass to
2937 * glFramebufferTexture(), but since they aren't layered, it
2938 * is equivalent to calling glFramebufferTexture{1D,2D}().
2940 *layered
= GL_FALSE
;
2944 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2945 "%s(invalid texture target %s)", caller
,
2946 _mesa_enum_to_string(target
));
2952 * Common code called by gl*FramebufferTextureLayer() to verify the texture
2955 * \return true if no errors, false if errors
2958 check_texture_target(struct gl_context
*ctx
, GLenum target
,
2961 /* We're being called by glFramebufferTextureLayer().
2962 * The only legal texture types for that function are 3D,
2963 * cube-map, and 1D/2D/cube-map array textures.
2965 * We don't need to check for GL_ARB_texture_cube_map_array because the
2966 * application wouldn't have been able to create a texture with a
2967 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
2971 case GL_TEXTURE_1D_ARRAY
:
2972 case GL_TEXTURE_2D_ARRAY
:
2973 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2974 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2976 case GL_TEXTURE_CUBE_MAP
:
2977 /* We don't need to check the extension (GL_ARB_direct_state_access) or
2978 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
2979 * enabled in core profile. This can be called from
2980 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
2981 * so we do have to check the profile.
2983 return ctx
->API
== API_OPENGL_CORE
;
2986 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2987 "%s(invalid texture target %s)", caller
,
2988 _mesa_enum_to_string(target
));
2994 * Common code called by glFramebufferTexture*D() to verify the texture
2997 * \return true if no errors, false if errors
3000 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
3001 GLenum textarget
, const char *caller
)
3005 switch (textarget
) {
3009 case GL_TEXTURE_1D_ARRAY
:
3010 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3015 case GL_TEXTURE_2D_ARRAY
:
3016 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3017 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3019 case GL_TEXTURE_2D_MULTISAMPLE
:
3020 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3022 !ctx
->Extensions
.ARB_texture_multisample
||
3023 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3025 case GL_TEXTURE_RECTANGLE
:
3026 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3027 !ctx
->Extensions
.NV_texture_rectangle
;
3029 case GL_TEXTURE_CUBE_MAP
:
3030 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3033 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3034 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3035 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3036 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3037 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3038 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3039 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3045 _mesa_error(ctx
, GL_INVALID_ENUM
,
3046 "%s(unknown textarget 0x%x)", caller
, textarget
);
3051 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3052 "%s(invalid textarget %s)",
3053 caller
, _mesa_enum_to_string(textarget
));
3057 /* Make sure textarget is consistent with the texture's type */
3058 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3059 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3062 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3063 "%s(mismatched texture target)", caller
);
3072 * Common code called by gl*FramebufferTextureLayer() and
3073 * glFramebufferTexture3D() to validate the layer.
3075 * \return true if no errors, false if errors
3078 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3081 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3084 * "An INVALID_VALUE error is generated if texture is non-zero
3085 * and layer is negative."
3088 _mesa_error(ctx
, GL_INVALID_VALUE
,
3089 "%s(layer %u < 0)", caller
, layer
);
3093 if (target
== GL_TEXTURE_3D
) {
3094 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3095 if (layer
>= maxSize
) {
3096 _mesa_error(ctx
, GL_INVALID_VALUE
,
3097 "%s(invalid layer %u)", caller
, layer
);
3101 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3102 (target
== GL_TEXTURE_2D_ARRAY
) ||
3103 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3104 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3105 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3106 _mesa_error(ctx
, GL_INVALID_VALUE
,
3107 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3112 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3114 _mesa_error(ctx
, GL_INVALID_VALUE
,
3115 "%s(layer %u >= 6)", caller
, layer
);
3125 * Common code called by all gl*FramebufferTexture*() entry points to verify
3128 * \return true if no errors, false if errors
3131 check_level(struct gl_context
*ctx
, GLenum target
, GLint level
,
3135 (level
>= _mesa_max_texture_levels(ctx
, target
))) {
3136 _mesa_error(ctx
, GL_INVALID_VALUE
,
3137 "%s(invalid level %d)", caller
, level
);
3146 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3148 struct gl_texture_object
*texObj
, GLenum textarget
,
3149 GLint level
, GLuint layer
, GLboolean layered
,
3152 struct gl_renderbuffer_attachment
*att
;
3154 /* The window-system framebuffer object is immutable */
3155 if (_mesa_is_winsys_fbo(fb
)) {
3156 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3161 /* Not a hash lookup, so we can afford to get the attachment here. */
3162 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
3164 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3165 _mesa_enum_to_string(attachment
));
3169 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3171 mtx_lock(&fb
->Mutex
);
3173 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3174 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3175 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3176 _mesa_tex_target_to_face(textarget
) ==
3177 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3178 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3179 /* The texture object is already attached to the stencil attachment
3180 * point. Don't create a new renderbuffer; just reuse the stencil
3181 * attachment's. This is required to prevent a GL error in
3182 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3184 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3186 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3187 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3188 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3189 _mesa_tex_target_to_face(textarget
) ==
3190 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3191 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3192 /* As above, but with depth and stencil transposed. */
3193 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3196 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3197 level
, layer
, layered
);
3199 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3200 /* Above we created a new renderbuffer and attached it to the
3201 * depth attachment point. Now attach it to the stencil attachment
3204 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3205 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3210 /* Set the render-to-texture flag. We'll check this flag in
3211 * glTexImage() and friends to determine if we need to revalidate
3212 * any FBOs that might be rendering into this texture.
3213 * This flag never gets cleared since it's non-trivial to determine
3214 * when all FBOs might be done rendering to this texture. That's OK
3215 * though since it's uncommon to render to a texture then repeatedly
3216 * call glTexImage() to change images in the texture.
3218 texObj
->_RenderToTexture
= GL_TRUE
;
3221 remove_attachment(ctx
, att
);
3222 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3223 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3224 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3228 invalidate_framebuffer(fb
);
3230 mtx_unlock(&fb
->Mutex
);
3235 framebuffer_texture_with_dims(int dims
, GLenum target
,
3236 GLenum attachment
, GLenum textarget
,
3237 GLuint texture
, GLint level
, GLint layer
,
3240 GET_CURRENT_CONTEXT(ctx
);
3241 struct gl_framebuffer
*fb
;
3242 struct gl_texture_object
*texObj
;
3244 /* Get the framebuffer object */
3245 fb
= get_framebuffer_target(ctx
, target
);
3247 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3248 _mesa_enum_to_string(target
));
3252 /* Get the texture object */
3253 if (!get_texture_for_framebuffer(ctx
, texture
, false, caller
, &texObj
))
3257 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3260 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3263 if (!check_level(ctx
, textarget
, level
, caller
))
3267 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3268 layer
, GL_FALSE
, caller
);
3273 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3274 GLenum textarget
, GLuint texture
, GLint level
)
3276 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3277 level
, 0, "glFramebufferTexture1D");
3282 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3283 GLenum textarget
, GLuint texture
, GLint level
)
3285 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3286 level
, 0, "glFramebufferTexture2D");
3291 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3292 GLenum textarget
, GLuint texture
,
3293 GLint level
, GLint layer
)
3295 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3296 level
, layer
, "glFramebufferTexture3D");
3301 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3302 GLuint texture
, GLint level
, GLint layer
)
3304 GET_CURRENT_CONTEXT(ctx
);
3305 struct gl_framebuffer
*fb
;
3306 struct gl_texture_object
*texObj
;
3307 GLenum textarget
= 0;
3309 const char *func
= "glFramebufferTextureLayer";
3311 /* Get the framebuffer object */
3312 fb
= get_framebuffer_target(ctx
, target
);
3314 _mesa_error(ctx
, GL_INVALID_ENUM
,
3315 "glFramebufferTextureLayer(invalid target %s)",
3316 _mesa_enum_to_string(target
));
3320 /* Get the texture object */
3321 if (!get_texture_for_framebuffer(ctx
, texture
, false, func
, &texObj
))
3325 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3328 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3331 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3334 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3335 assert(layer
>= 0 && layer
< 6);
3336 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3341 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3342 layer
, GL_FALSE
, func
);
3347 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3348 GLuint texture
, GLint level
, GLint layer
)
3350 GET_CURRENT_CONTEXT(ctx
);
3351 struct gl_framebuffer
*fb
;
3352 struct gl_texture_object
*texObj
;
3353 GLenum textarget
= 0;
3355 const char *func
= "glNamedFramebufferTextureLayer";
3357 /* Get the framebuffer object */
3358 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3362 /* Get the texture object */
3363 if (!get_texture_for_framebuffer(ctx
, texture
, false, func
, &texObj
))
3367 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3370 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3373 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3376 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3377 assert(layer
>= 0 && layer
< 6);
3378 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3383 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, textarget
, level
,
3384 layer
, GL_FALSE
, func
);
3389 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3390 GLuint texture
, GLint level
)
3392 GET_CURRENT_CONTEXT(ctx
);
3393 struct gl_framebuffer
*fb
;
3394 struct gl_texture_object
*texObj
;
3395 GLboolean layered
= GL_FALSE
;
3397 const char *func
= "FramebufferTexture";
3399 if (!_mesa_has_geometry_shaders(ctx
)) {
3400 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3401 "unsupported function (glFramebufferTexture) called");
3405 /* Get the framebuffer object */
3406 fb
= get_framebuffer_target(ctx
, target
);
3408 _mesa_error(ctx
, GL_INVALID_ENUM
,
3409 "glFramebufferTexture(invalid target %s)",
3410 _mesa_enum_to_string(target
));
3414 /* Get the texture object */
3415 if (!get_texture_for_framebuffer(ctx
, texture
, true, func
, &texObj
))
3419 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
, &layered
))
3422 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3426 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, 0, level
,
3432 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3433 GLuint texture
, GLint level
)
3435 GET_CURRENT_CONTEXT(ctx
);
3436 struct gl_framebuffer
*fb
;
3437 struct gl_texture_object
*texObj
;
3438 GLboolean layered
= GL_FALSE
;
3440 const char *func
= "glNamedFramebufferTexture";
3442 if (!_mesa_has_geometry_shaders(ctx
)) {
3443 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3444 "unsupported function (glNamedFramebufferTexture) called");
3448 /* Get the framebuffer object */
3449 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3453 /* Get the texture object */
3454 if (!get_texture_for_framebuffer(ctx
, texture
, true, func
, &texObj
))
3458 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3462 if (!check_level(ctx
, texObj
->Target
, level
, func
))
3466 _mesa_framebuffer_texture(ctx
, fb
, attachment
, texObj
, 0, level
,
3472 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3473 struct gl_framebuffer
*fb
,
3475 struct gl_renderbuffer
*rb
)
3477 assert(!_mesa_is_winsys_fbo(fb
));
3479 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3481 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3482 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3484 /* Some subsequent GL commands may depend on the framebuffer's visual
3485 * after the binding is updated. Update visual info now.
3487 _mesa_update_framebuffer_visual(ctx
, fb
);
3491 framebuffer_renderbuffer(struct gl_context
*ctx
,
3492 struct gl_framebuffer
*fb
,
3494 struct gl_renderbuffer
*rb
,
3497 struct gl_renderbuffer_attachment
*att
;
3498 bool is_color_attachment
;
3500 if (_mesa_is_winsys_fbo(fb
)) {
3501 /* Can't attach new renderbuffers to a window system framebuffer */
3502 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3503 "%s(window-system framebuffer)", func
);
3507 att
= get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3510 * From OpenGL 4.5 spec, section 9.2.7 "Attaching Renderbuffer Images to
3513 * "An INVALID_OPERATION error is generated if attachment is COLOR_-
3514 * ATTACHMENTm where m is greater than or equal to the value of
3515 * MAX_COLOR_- ATTACHMENTS ."
3517 * If we are at this point, is because the attachment is not valid, so
3518 * if is_color_attachment is true, is because of the previous reason.
3520 if (is_color_attachment
) {
3521 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3522 "%s(invalid color attachment %s)", func
,
3523 _mesa_enum_to_string(attachment
));
3525 _mesa_error(ctx
, GL_INVALID_ENUM
,
3526 "%s(invalid attachment %s)", func
,
3527 _mesa_enum_to_string(attachment
));
3533 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3534 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3535 /* make sure the renderbuffer is a depth/stencil format */
3536 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3537 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3538 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3539 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3544 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3548 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3549 GLenum renderbuffertarget
,
3550 GLuint renderbuffer
)
3552 struct gl_framebuffer
*fb
;
3553 struct gl_renderbuffer
*rb
;
3554 GET_CURRENT_CONTEXT(ctx
);
3556 fb
= get_framebuffer_target(ctx
, target
);
3558 _mesa_error(ctx
, GL_INVALID_ENUM
,
3559 "glFramebufferRenderbuffer(invalid target %s)",
3560 _mesa_enum_to_string(target
));
3564 if (renderbuffertarget
!= GL_RENDERBUFFER
) {
3565 _mesa_error(ctx
, GL_INVALID_ENUM
,
3566 "glFramebufferRenderbuffer(renderbuffertarget is not "
3567 "GL_RENDERBUFFER)");
3572 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
,
3573 "glFramebufferRenderbuffer");
3578 /* remove renderbuffer attachment */
3582 framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
,
3583 "glFramebufferRenderbuffer");
3588 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
3589 GLenum renderbuffertarget
,
3590 GLuint renderbuffer
)
3592 struct gl_framebuffer
*fb
;
3593 struct gl_renderbuffer
*rb
;
3594 GET_CURRENT_CONTEXT(ctx
);
3596 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3597 "glNamedFramebufferRenderbuffer");
3601 if (renderbuffertarget
!= GL_RENDERBUFFER
) {
3602 _mesa_error(ctx
, GL_INVALID_ENUM
,
3603 "glNamedFramebufferRenderbuffer(renderbuffertarget is not "
3604 "GL_RENDERBUFFER)");
3609 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
,
3610 "glNamedFramebufferRenderbuffer");
3615 /* remove renderbuffer attachment */
3619 framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
,
3620 "glNamedFramebufferRenderbuffer");
3625 _mesa_get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
3626 struct gl_framebuffer
*buffer
,
3627 GLenum attachment
, GLenum pname
,
3628 GLint
*params
, const char *caller
)
3630 const struct gl_renderbuffer_attachment
*att
;
3631 bool is_color_attachment
;
3634 /* The error code for an attachment type of GL_NONE differs between APIs.
3636 * From the ES 2.0.25 specification, page 127:
3637 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3638 * querying any other pname will generate INVALID_ENUM."
3640 * From the OpenGL 3.0 specification, page 337, or identically,
3641 * the OpenGL ES 3.0.4 specification, page 240:
3643 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
3644 * framebuffer is bound to target. In this case querying pname
3645 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
3646 * queries will generate an INVALID_OPERATION error."
3648 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
3649 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
3651 if (_mesa_is_winsys_fbo(buffer
)) {
3652 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
3655 * "If the framebuffer currently bound to target is zero, then
3656 * INVALID_OPERATION is generated."
3658 * The EXT_framebuffer_object spec has the same wording, and the
3659 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
3662 if ((!_mesa_is_desktop_gl(ctx
) ||
3663 !ctx
->Extensions
.ARB_framebuffer_object
)
3664 && !_mesa_is_gles3(ctx
)) {
3665 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3666 "%s(window-system framebuffer)", caller
);
3670 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
3671 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
3672 _mesa_error(ctx
, GL_INVALID_ENUM
,
3673 "%s(invalid attachment %s)", caller
,
3674 _mesa_enum_to_string(attachment
));
3678 /* The specs are not clear about how to handle
3679 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
3680 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
3683 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
3684 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
3686 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
3687 _mesa_error(ctx
, GL_INVALID_ENUM
,
3688 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
3689 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
3690 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
3694 /* the default / window-system FBO */
3695 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
3698 /* user-created framebuffer FBO */
3699 att
= get_attachment(ctx
, buffer
, attachment
, &is_color_attachment
);
3704 * From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries":
3706 * "An INVALID_OPERATION error is generated if a framebuffer object
3707 * is bound to target and attachment is COLOR_ATTACHMENTm where m is
3708 * greater than or equal to the value of MAX_COLOR_ATTACHMENTS."
3710 * If we are at this point, is because the attachment is not valid, so
3711 * if is_color_attachment is true, is because of the previous reason.
3713 if (is_color_attachment
) {
3714 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid color attachment %s)",
3715 caller
, _mesa_enum_to_string(attachment
));
3717 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3718 _mesa_enum_to_string(attachment
));
3723 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3724 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
3725 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
3726 /* This behavior is first specified in OpenGL 4.4 specification.
3728 * From the OpenGL 4.4 spec page 275:
3729 * "This query cannot be performed for a combined depth+stencil
3730 * attachment, since it does not have a single format."
3732 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3733 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
3734 " is invalid for depth+stencil attachment)", caller
);
3737 /* the depth and stencil attachments must point to the same buffer */
3738 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
, NULL
);
3739 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
, NULL
);
3740 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
3741 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3742 "%s(DEPTH/STENCIL attachments differ)", caller
);
3747 /* No need to flush here */
3750 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
3751 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
3753 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3754 * either no framebuffer is bound to target; or the default framebuffer
3755 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
3756 * stencil bits, respectively, is zero."
3758 *params
= (_mesa_is_winsys_fbo(buffer
) &&
3759 ((attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) ||
3760 (att
->Type
!= GL_NONE
)))
3761 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
3763 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
3764 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
3765 *params
= att
->Renderbuffer
->Name
;
3767 else if (att
->Type
== GL_TEXTURE
) {
3768 *params
= att
->Texture
->Name
;
3771 assert(att
->Type
== GL_NONE
);
3772 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
3775 goto invalid_pname_enum
;
3779 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
3780 if (att
->Type
== GL_TEXTURE
) {
3781 *params
= att
->TextureLevel
;
3783 else if (att
->Type
== GL_NONE
) {
3784 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3785 _mesa_enum_to_string(pname
));
3788 goto invalid_pname_enum
;
3791 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
3792 if (att
->Type
== GL_TEXTURE
) {
3793 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
3794 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
3800 else if (att
->Type
== GL_NONE
) {
3801 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3802 _mesa_enum_to_string(pname
));
3805 goto invalid_pname_enum
;
3808 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
3809 if (ctx
->API
== API_OPENGLES
) {
3810 goto invalid_pname_enum
;
3811 } else if (att
->Type
== GL_NONE
) {
3812 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3813 _mesa_enum_to_string(pname
));
3814 } else if (att
->Type
== GL_TEXTURE
) {
3815 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
3816 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
3817 *params
= att
->Zoffset
;
3824 goto invalid_pname_enum
;
3827 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
3828 if ((!_mesa_is_desktop_gl(ctx
) ||
3829 !ctx
->Extensions
.ARB_framebuffer_object
)
3830 && !_mesa_is_gles3(ctx
)) {
3831 goto invalid_pname_enum
;
3833 else if (att
->Type
== GL_NONE
) {
3834 if (_mesa_is_winsys_fbo(buffer
) &&
3835 (attachment
== GL_DEPTH
|| attachment
== GL_STENCIL
)) {
3836 *params
= GL_LINEAR
;
3838 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3839 _mesa_enum_to_string(pname
));
3843 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
3845 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
3848 /* According to ARB_framebuffer_sRGB, we should return LINEAR
3849 * if the sRGB conversion is unsupported. */
3850 *params
= GL_LINEAR
;
3854 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
3855 if ((ctx
->API
!= API_OPENGL_COMPAT
||
3856 !ctx
->Extensions
.ARB_framebuffer_object
)
3857 && ctx
->API
!= API_OPENGL_CORE
3858 && !_mesa_is_gles3(ctx
)) {
3859 goto invalid_pname_enum
;
3861 else if (att
->Type
== GL_NONE
) {
3862 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3863 _mesa_enum_to_string(pname
));
3866 mesa_format format
= att
->Renderbuffer
->Format
;
3868 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
3871 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
3872 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
3873 * generate an INVALID_OPERATION error.
3875 if (_mesa_is_gles3(ctx
) &&
3876 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3877 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3879 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
3880 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
3884 if (format
== MESA_FORMAT_S_UINT8
) {
3888 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
3889 /* depends on the attachment parameter */
3890 if (attachment
== GL_STENCIL_ATTACHMENT
) {
3898 *params
= _mesa_get_format_datatype(format
);
3902 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
3903 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
3904 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
3905 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
3906 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
3907 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
3908 if ((!_mesa_is_desktop_gl(ctx
) ||
3909 !ctx
->Extensions
.ARB_framebuffer_object
)
3910 && !_mesa_is_gles3(ctx
)) {
3911 goto invalid_pname_enum
;
3913 else if (att
->Type
== GL_NONE
) {
3914 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3915 _mesa_enum_to_string(pname
));
3917 else if (att
->Texture
) {
3918 const struct gl_texture_image
*texImage
=
3919 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
3922 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
3923 texImage
->TexFormat
);
3929 else if (att
->Renderbuffer
) {
3930 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
3931 att
->Renderbuffer
->Format
);
3934 _mesa_problem(ctx
, "%s: invalid FBO attachment structure", caller
);
3937 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
3938 if (!_mesa_has_geometry_shaders(ctx
)) {
3939 goto invalid_pname_enum
;
3940 } else if (att
->Type
== GL_TEXTURE
) {
3941 *params
= att
->Layered
;
3942 } else if (att
->Type
== GL_NONE
) {
3943 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3944 _mesa_enum_to_string(pname
));
3946 goto invalid_pname_enum
;
3950 goto invalid_pname_enum
;
3956 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
3957 _mesa_enum_to_string(pname
));
3963 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
3964 GLenum pname
, GLint
*params
)
3966 GET_CURRENT_CONTEXT(ctx
);
3967 struct gl_framebuffer
*buffer
;
3969 buffer
= get_framebuffer_target(ctx
, target
);
3971 _mesa_error(ctx
, GL_INVALID_ENUM
,
3972 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
3973 _mesa_enum_to_string(target
));
3977 _mesa_get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
3979 "glGetFramebufferAttachmentParameteriv");
3984 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
3986 GLenum pname
, GLint
*params
)
3988 GET_CURRENT_CONTEXT(ctx
);
3989 struct gl_framebuffer
*buffer
;
3992 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3993 "glGetNamedFramebufferAttachmentParameteriv");
3999 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
4000 * 4.5 core spec (30.10.2014, PDF page 314):
4001 * "If framebuffer is zero, then the default draw framebuffer is
4004 buffer
= ctx
->WinSysDrawBuffer
;
4007 _mesa_get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4009 "glGetNamedFramebufferAttachmentParameteriv");
4014 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
4017 GET_CURRENT_CONTEXT(ctx
);
4018 struct gl_framebuffer
*fb
= NULL
;
4020 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4021 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4022 "glNamedFramebufferParameteri("
4023 "ARB_framebuffer_no_attachments not implemented)");
4027 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4028 "glNamedFramebufferParameteri");
4031 framebuffer_parameteri(ctx
, fb
, pname
, param
,
4032 "glNamedFramebufferParameteriv");
4038 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
4041 GET_CURRENT_CONTEXT(ctx
);
4042 struct gl_framebuffer
*fb
;
4044 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4045 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4046 "glNamedFramebufferParameteriv("
4047 "ARB_framebuffer_no_attachments not implemented)");
4052 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4053 "glGetNamedFramebufferParameteriv");
4055 fb
= ctx
->WinSysDrawBuffer
;
4059 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4060 "glGetNamedFramebufferParameteriv");
4066 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4067 struct gl_framebuffer
*fb
,
4068 GLsizei numAttachments
,
4069 const GLenum
*attachments
, GLint x
, GLint y
,
4070 GLsizei width
, GLsizei height
, const char *name
)
4074 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4075 * Spec (2.2.2015, PDF page 522) says:
4076 * "An INVALID_VALUE error is generated if numAttachments, width, or
4077 * height is negative."
4079 if (numAttachments
< 0) {
4080 _mesa_error(ctx
, GL_INVALID_VALUE
,
4081 "%s(numAttachments < 0)", name
);
4086 _mesa_error(ctx
, GL_INVALID_VALUE
,
4087 "%s(width < 0)", name
);
4092 _mesa_error(ctx
, GL_INVALID_VALUE
,
4093 "%s(height < 0)", name
);
4097 /* The GL_ARB_invalidate_subdata spec says:
4099 * "If an attachment is specified that does not exist in the
4100 * framebuffer bound to <target>, it is ignored."
4104 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4105 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4106 * INVALID_OPERATION is generated."
4108 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4109 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4110 * set of retrictions).
4112 for (i
= 0; i
< numAttachments
; i
++) {
4113 if (_mesa_is_winsys_fbo(fb
)) {
4114 switch (attachments
[i
]) {
4120 /* Accumulation buffers and auxilary buffers were removed in
4121 * OpenGL 3.1, and they never existed in OpenGL ES.
4123 if (ctx
->API
!= API_OPENGL_COMPAT
)
4133 case GL_FRONT_RIGHT
:
4134 if (!_mesa_is_desktop_gl(ctx
))
4141 switch (attachments
[i
]) {
4142 case GL_DEPTH_ATTACHMENT
:
4143 case GL_STENCIL_ATTACHMENT
:
4145 case GL_DEPTH_STENCIL_ATTACHMENT
:
4146 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4147 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4148 * extension does not make this attachment point valid on ES 2.0.
4150 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4153 case GL_COLOR_ATTACHMENT0
:
4154 case GL_COLOR_ATTACHMENT1
:
4155 case GL_COLOR_ATTACHMENT2
:
4156 case GL_COLOR_ATTACHMENT3
:
4157 case GL_COLOR_ATTACHMENT4
:
4158 case GL_COLOR_ATTACHMENT5
:
4159 case GL_COLOR_ATTACHMENT6
:
4160 case GL_COLOR_ATTACHMENT7
:
4161 case GL_COLOR_ATTACHMENT8
:
4162 case GL_COLOR_ATTACHMENT9
:
4163 case GL_COLOR_ATTACHMENT10
:
4164 case GL_COLOR_ATTACHMENT11
:
4165 case GL_COLOR_ATTACHMENT12
:
4166 case GL_COLOR_ATTACHMENT13
:
4167 case GL_COLOR_ATTACHMENT14
:
4168 case GL_COLOR_ATTACHMENT15
: {
4169 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4170 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4171 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4172 "%s(attachment >= max. color attachments)", name
);
4183 /* We don't actually do anything for this yet. Just return after
4184 * validating the parameters and generating the required errors.
4189 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4190 _mesa_enum_to_string(attachments
[i
]));
4196 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4197 const GLenum
*attachments
, GLint x
, GLint y
,
4198 GLsizei width
, GLsizei height
)
4200 struct gl_framebuffer
*fb
;
4201 GET_CURRENT_CONTEXT(ctx
);
4203 fb
= get_framebuffer_target(ctx
, target
);
4205 _mesa_error(ctx
, GL_INVALID_ENUM
,
4206 "glInvalidateSubFramebuffer(invalid target %s)",
4207 _mesa_enum_to_string(target
));
4211 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4212 x
, y
, width
, height
,
4213 "glInvalidateSubFramebuffer");
4218 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4219 GLsizei numAttachments
,
4220 const GLenum
*attachments
,
4222 GLsizei width
, GLsizei height
)
4224 struct gl_framebuffer
*fb
;
4225 GET_CURRENT_CONTEXT(ctx
);
4227 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4228 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4229 * default draw framebuffer is affected."
4232 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4233 "glInvalidateNamedFramebufferSubData");
4238 fb
= ctx
->WinSysDrawBuffer
;
4240 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4241 x
, y
, width
, height
,
4242 "glInvalidateNamedFramebufferSubData");
4247 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4248 const GLenum
*attachments
)
4250 struct gl_framebuffer
*fb
;
4251 GET_CURRENT_CONTEXT(ctx
);
4253 fb
= get_framebuffer_target(ctx
, target
);
4255 _mesa_error(ctx
, GL_INVALID_ENUM
,
4256 "glInvalidateFramebuffer(invalid target %s)",
4257 _mesa_enum_to_string(target
));
4261 /* The GL_ARB_invalidate_subdata spec says:
4265 * void InvalidateFramebuffer(enum target,
4266 * sizei numAttachments,
4267 * const enum *attachments);
4269 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4270 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4271 * <MAX_VIEWPORT_DIMS[1]> respectively."
4273 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4275 ctx
->Const
.MaxViewportWidth
,
4276 ctx
->Const
.MaxViewportHeight
,
4277 "glInvalidateFramebuffer");
4282 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4283 GLsizei numAttachments
,
4284 const GLenum
*attachments
)
4286 struct gl_framebuffer
*fb
;
4287 GET_CURRENT_CONTEXT(ctx
);
4289 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4290 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4291 * default draw framebuffer is affected."
4294 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4295 "glInvalidateNamedFramebufferData");
4300 fb
= ctx
->WinSysDrawBuffer
;
4302 /* The GL_ARB_invalidate_subdata spec says:
4306 * void InvalidateFramebuffer(enum target,
4307 * sizei numAttachments,
4308 * const enum *attachments);
4310 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4311 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4312 * <MAX_VIEWPORT_DIMS[1]> respectively."
4314 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4316 ctx
->Const
.MaxViewportWidth
,
4317 ctx
->Const
.MaxViewportHeight
,
4318 "glInvalidateNamedFramebufferData");
4323 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4324 const GLenum
*attachments
)
4326 struct gl_framebuffer
*fb
;
4329 GET_CURRENT_CONTEXT(ctx
);
4331 fb
= get_framebuffer_target(ctx
, target
);
4333 _mesa_error(ctx
, GL_INVALID_ENUM
,
4334 "glDiscardFramebufferEXT(target %s)",
4335 _mesa_enum_to_string(target
));
4339 if (numAttachments
< 0) {
4340 _mesa_error(ctx
, GL_INVALID_VALUE
,
4341 "glDiscardFramebufferEXT(numAttachments < 0)");
4345 for (i
= 0; i
< numAttachments
; i
++) {
4346 switch (attachments
[i
]) {
4350 if (_mesa_is_user_fbo(fb
))
4353 case GL_COLOR_ATTACHMENT0
:
4354 case GL_DEPTH_ATTACHMENT
:
4355 case GL_STENCIL_ATTACHMENT
:
4356 if (_mesa_is_winsys_fbo(fb
))
4364 if (ctx
->Driver
.DiscardFramebuffer
)
4365 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4370 _mesa_error(ctx
, GL_INVALID_ENUM
,
4371 "glDiscardFramebufferEXT(attachment %s)",
4372 _mesa_enum_to_string(attachments
[i
]));