2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 * GL_EXT/ARB_framebuffer_object extensions
41 #include "framebuffer.h"
42 #include "glformats.h"
45 #include "multisample.h"
47 #include "renderbuffer.h"
56 * None of the GL_EXT_framebuffer_object functions are compiled into
63 * When glGenRender/FramebuffersEXT() is called we insert pointers to
64 * these placeholder objects into the hash table.
65 * Later, when the object ID is first bound, we replace the placeholder
66 * with the real frame/renderbuffer.
68 static struct gl_framebuffer DummyFramebuffer
;
69 static struct gl_renderbuffer DummyRenderbuffer
;
71 /* We bind this framebuffer when applications pass a NULL
72 * drawable/surface in make current. */
73 static struct gl_framebuffer IncompleteFramebuffer
;
77 delete_dummy_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
83 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
90 _mesa_init_fbobjects(struct gl_context
*ctx
)
92 mtx_init(&DummyFramebuffer
.Mutex
, mtx_plain
);
93 mtx_init(&DummyRenderbuffer
.Mutex
, mtx_plain
);
94 mtx_init(&IncompleteFramebuffer
.Mutex
, mtx_plain
);
95 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
96 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
97 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
100 struct gl_framebuffer
*
101 _mesa_get_incomplete_framebuffer(void)
103 return &IncompleteFramebuffer
;
107 * Helper routine for getting a gl_renderbuffer.
109 struct gl_renderbuffer
*
110 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
112 struct gl_renderbuffer
*rb
;
117 rb
= (struct gl_renderbuffer
*)
118 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
124 * A convenience function for direct state access that throws
125 * GL_INVALID_OPERATION if the renderbuffer doesn't exist.
127 struct gl_renderbuffer
*
128 _mesa_lookup_renderbuffer_err(struct gl_context
*ctx
, GLuint id
,
131 struct gl_renderbuffer
*rb
;
133 rb
= _mesa_lookup_renderbuffer(ctx
, id
);
134 if (!rb
|| rb
== &DummyRenderbuffer
) {
135 _mesa_error(ctx
, GL_INVALID_OPERATION
,
136 "%s(non-existent renderbuffer %u)", func
, id
);
145 * Helper routine for getting a gl_framebuffer.
147 struct gl_framebuffer
*
148 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
150 struct gl_framebuffer
*fb
;
155 fb
= (struct gl_framebuffer
*)
156 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
162 * A convenience function for direct state access that throws
163 * GL_INVALID_OPERATION if the framebuffer doesn't exist.
165 struct gl_framebuffer
*
166 _mesa_lookup_framebuffer_err(struct gl_context
*ctx
, GLuint id
,
169 struct gl_framebuffer
*fb
;
171 fb
= _mesa_lookup_framebuffer(ctx
, id
);
172 if (!fb
|| fb
== &DummyFramebuffer
) {
173 _mesa_error(ctx
, GL_INVALID_OPERATION
,
174 "%s(non-existent framebuffer %u)", func
, id
);
183 * Mark the given framebuffer as invalid. This will force the
184 * test for framebuffer completeness to be done before the framebuffer
188 invalidate_framebuffer(struct gl_framebuffer
*fb
)
190 fb
->_Status
= 0; /* "indeterminate" */
195 * Return the gl_framebuffer object which corresponds to the given
196 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
197 * Check support for GL_EXT_framebuffer_blit to determine if certain
199 * \return gl_framebuffer pointer or NULL if target is illegal
201 static struct gl_framebuffer
*
202 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
204 bool have_fb_blit
= _mesa_is_gles3(ctx
) || _mesa_is_desktop_gl(ctx
);
206 case GL_DRAW_FRAMEBUFFER
:
207 return have_fb_blit
? ctx
->DrawBuffer
: NULL
;
208 case GL_READ_FRAMEBUFFER
:
209 return have_fb_blit
? ctx
->ReadBuffer
: NULL
;
210 case GL_FRAMEBUFFER_EXT
:
211 return ctx
->DrawBuffer
;
219 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
220 * gl_renderbuffer_attachment object.
221 * This function is only used for user-created FB objects, not the
222 * default / window-system FB object.
223 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
224 * the depth buffer attachment point.
225 * Returns if the attachment is a GL_COLOR_ATTACHMENTm_EXT on
226 * is_color_attachment, because several callers would return different errors
227 * if they don't find the attachment.
229 static struct gl_renderbuffer_attachment
*
230 get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
231 GLenum attachment
, bool *is_color_attachment
)
235 assert(_mesa_is_user_fbo(fb
));
237 if (is_color_attachment
)
238 *is_color_attachment
= false;
240 switch (attachment
) {
241 case GL_COLOR_ATTACHMENT0_EXT
:
242 case GL_COLOR_ATTACHMENT1_EXT
:
243 case GL_COLOR_ATTACHMENT2_EXT
:
244 case GL_COLOR_ATTACHMENT3_EXT
:
245 case GL_COLOR_ATTACHMENT4_EXT
:
246 case GL_COLOR_ATTACHMENT5_EXT
:
247 case GL_COLOR_ATTACHMENT6_EXT
:
248 case GL_COLOR_ATTACHMENT7_EXT
:
249 case GL_COLOR_ATTACHMENT8_EXT
:
250 case GL_COLOR_ATTACHMENT9_EXT
:
251 case GL_COLOR_ATTACHMENT10_EXT
:
252 case GL_COLOR_ATTACHMENT11_EXT
:
253 case GL_COLOR_ATTACHMENT12_EXT
:
254 case GL_COLOR_ATTACHMENT13_EXT
:
255 case GL_COLOR_ATTACHMENT14_EXT
:
256 case GL_COLOR_ATTACHMENT15_EXT
:
257 if (is_color_attachment
)
258 *is_color_attachment
= true;
259 /* Only OpenGL ES 1.x forbids color attachments other than
260 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
263 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
264 if (i
>= ctx
->Const
.MaxColorAttachments
265 || (i
> 0 && ctx
->API
== API_OPENGLES
)) {
268 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
269 case GL_DEPTH_STENCIL_ATTACHMENT
:
270 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
273 case GL_DEPTH_ATTACHMENT_EXT
:
274 return &fb
->Attachment
[BUFFER_DEPTH
];
275 case GL_STENCIL_ATTACHMENT_EXT
:
276 return &fb
->Attachment
[BUFFER_STENCIL
];
284 * As above, but only used for getting attachments of the default /
285 * window-system framebuffer (not user-created framebuffer objects).
287 static struct gl_renderbuffer_attachment
*
288 get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
291 assert(_mesa_is_winsys_fbo(fb
));
293 if (_mesa_is_gles3(ctx
)) {
294 assert(attachment
== GL_BACK
||
295 attachment
== GL_DEPTH
||
296 attachment
== GL_STENCIL
);
297 switch (attachment
) {
299 /* Since there is no stereo rendering in ES 3.0, only return the
302 if (ctx
->DrawBuffer
->Visual
.doubleBufferMode
)
303 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
304 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
306 return &fb
->Attachment
[BUFFER_DEPTH
];
308 return &fb
->Attachment
[BUFFER_STENCIL
];
312 switch (attachment
) {
314 /* Front buffers can be allocated on the first use, but
315 * glGetFramebufferAttachmentParameteriv must work even if that
316 * allocation hasn't happened yet. In such case, use the back buffer,
317 * which should be the same.
319 if (fb
->Attachment
[BUFFER_FRONT_LEFT
].Type
== GL_NONE
)
320 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
322 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
325 if (fb
->Attachment
[BUFFER_FRONT_RIGHT
].Type
== GL_NONE
)
326 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
328 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
330 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
332 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
334 if (fb
->Visual
.numAuxBuffers
== 1) {
335 return &fb
->Attachment
[BUFFER_AUX0
];
339 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
341 * "If the default framebuffer is bound to target, then attachment must
342 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
343 * identifying a color buffer; DEPTH, identifying the depth buffer; or
344 * STENCIL, identifying the stencil buffer."
346 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
347 * language. However, revision #33 of the ARB_framebuffer_object spec
350 * "If the default framebuffer is bound to <target>, then <attachment>
351 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
352 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
353 * depth buffer, or the stencil buffer, and <pname> may be
354 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
355 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
357 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
358 * from glext.h, so shipping apps should not use those values.
360 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
361 * support queries of the window system FBO.
364 return &fb
->Attachment
[BUFFER_DEPTH
];
366 return &fb
->Attachment
[BUFFER_STENCIL
];
375 * Remove any texture or renderbuffer attached to the given attachment
376 * point. Update reference counts, etc.
379 remove_attachment(struct gl_context
*ctx
,
380 struct gl_renderbuffer_attachment
*att
)
382 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
384 /* tell driver that we're done rendering to this texture. */
385 if (rb
&& rb
->NeedsFinishRenderTexture
)
386 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
388 if (att
->Type
== GL_TEXTURE
) {
389 assert(att
->Texture
);
390 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
391 assert(!att
->Texture
);
393 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
394 assert(!att
->Texture
);
395 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
396 assert(!att
->Renderbuffer
);
399 att
->Complete
= GL_TRUE
;
403 * Verify a couple error conditions that will lead to an incomplete FBO and
404 * may cause problems for the driver's RenderTexture path.
407 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment
*att
)
409 const struct gl_texture_image
*const texImage
=
410 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
413 texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
416 if ((texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
417 && att
->Zoffset
>= texImage
->Height
)
418 || (texImage
->TexObject
->Target
!= GL_TEXTURE_1D_ARRAY
419 && att
->Zoffset
>= texImage
->Depth
))
426 * Create a renderbuffer which will be set up by the driver to wrap the
427 * texture image slice.
429 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
430 * to share most of their framebuffer rendering code between winsys,
431 * renderbuffer, and texture attachments.
433 * The allocated renderbuffer uses a non-zero Name so that drivers can check
434 * it for determining vertical orientation, but we use ~0 to make it fairly
435 * unambiguous with actual user (non-texture) renderbuffers.
438 _mesa_update_texture_renderbuffer(struct gl_context
*ctx
,
439 struct gl_framebuffer
*fb
,
440 struct gl_renderbuffer_attachment
*att
)
442 struct gl_texture_image
*texImage
;
443 struct gl_renderbuffer
*rb
;
445 texImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
447 rb
= att
->Renderbuffer
;
449 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
451 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
454 att
->Renderbuffer
= rb
;
456 /* This can't get called on a texture renderbuffer, so set it to NULL
457 * for clarity compared to user renderbuffers.
459 rb
->AllocStorage
= NULL
;
461 rb
->NeedsFinishRenderTexture
= ctx
->Driver
.FinishRenderTexture
!= NULL
;
467 rb
->_BaseFormat
= texImage
->_BaseFormat
;
468 rb
->Format
= texImage
->TexFormat
;
469 rb
->InternalFormat
= texImage
->InternalFormat
;
470 rb
->Width
= texImage
->Width2
;
471 rb
->Height
= texImage
->Height2
;
472 rb
->Depth
= texImage
->Depth2
;
473 rb
->NumSamples
= texImage
->NumSamples
;
474 rb
->TexImage
= texImage
;
476 if (driver_RenderTexture_is_safe(att
))
477 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
481 * Bind a texture object to an attachment point.
482 * The previous binding, if any, will be removed first.
485 set_texture_attachment(struct gl_context
*ctx
,
486 struct gl_framebuffer
*fb
,
487 struct gl_renderbuffer_attachment
*att
,
488 struct gl_texture_object
*texObj
,
489 GLenum texTarget
, GLuint level
, GLuint layer
,
492 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
494 if (rb
&& rb
->NeedsFinishRenderTexture
)
495 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
497 if (att
->Texture
== texObj
) {
498 /* re-attaching same texture */
499 assert(att
->Type
== GL_TEXTURE
);
503 remove_attachment(ctx
, att
);
504 att
->Type
= GL_TEXTURE
;
505 assert(!att
->Texture
);
506 _mesa_reference_texobj(&att
->Texture
, texObj
);
508 invalidate_framebuffer(fb
);
510 /* always update these fields */
511 att
->TextureLevel
= level
;
512 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
513 att
->Zoffset
= layer
;
514 att
->Layered
= layered
;
515 att
->Complete
= GL_FALSE
;
517 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
522 * Bind a renderbuffer to an attachment point.
523 * The previous binding, if any, will be removed first.
526 set_renderbuffer_attachment(struct gl_context
*ctx
,
527 struct gl_renderbuffer_attachment
*att
,
528 struct gl_renderbuffer
*rb
)
530 /* XXX check if re-doing same attachment, exit early */
531 remove_attachment(ctx
, att
);
532 att
->Type
= GL_RENDERBUFFER_EXT
;
533 att
->Texture
= NULL
; /* just to be safe */
534 att
->Layered
= GL_FALSE
;
535 att
->Complete
= GL_FALSE
;
536 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
541 * Fallback for ctx->Driver.FramebufferRenderbuffer()
542 * Attach a renderbuffer object to a framebuffer object.
545 _mesa_FramebufferRenderbuffer_sw(struct gl_context
*ctx
,
546 struct gl_framebuffer
*fb
,
548 struct gl_renderbuffer
*rb
)
550 struct gl_renderbuffer_attachment
*att
;
552 mtx_lock(&fb
->Mutex
);
554 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
557 set_renderbuffer_attachment(ctx
, att
, rb
);
558 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
559 /* do stencil attachment here (depth already done above) */
560 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
562 set_renderbuffer_attachment(ctx
, att
, rb
);
564 rb
->AttachedAnytime
= GL_TRUE
;
567 remove_attachment(ctx
, att
);
568 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
569 /* detach stencil (depth was detached above) */
570 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
572 remove_attachment(ctx
, att
);
576 invalidate_framebuffer(fb
);
578 mtx_unlock(&fb
->Mutex
);
583 * Fallback for ctx->Driver.ValidateFramebuffer()
584 * Check if the renderbuffer's formats are supported by the software
586 * Drivers should probably override this.
589 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
592 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
593 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
595 switch (rb
->_BaseFormat
) {
597 case GL_LUMINANCE_ALPHA
:
602 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
606 switch (rb
->Format
) {
607 /* XXX This list is likely incomplete. */
608 case MESA_FORMAT_R9G9B9E5_FLOAT
:
609 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
612 /* render buffer format is supported by software rendering */
621 * Return true if the framebuffer has a combined depth/stencil
622 * renderbuffer attached.
625 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
627 const struct gl_renderbuffer_attachment
*depth
=
628 &fb
->Attachment
[BUFFER_DEPTH
];
629 const struct gl_renderbuffer_attachment
*stencil
=
630 &fb
->Attachment
[BUFFER_STENCIL
];
632 if (depth
->Type
== stencil
->Type
) {
633 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
634 depth
->Renderbuffer
== stencil
->Renderbuffer
)
637 if (depth
->Type
== GL_TEXTURE
&&
638 depth
->Texture
== stencil
->Texture
)
650 att_incomplete(const char *msg
)
652 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
653 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
662 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
664 static GLuint msg_id
;
666 _mesa_gl_debug(ctx
, &msg_id
,
667 MESA_DEBUG_SOURCE_API
,
668 MESA_DEBUG_TYPE_OTHER
,
669 MESA_DEBUG_SEVERITY_MEDIUM
,
670 "FBO incomplete: %s [%d]\n", msg
, index
);
672 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
673 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
679 * Is the given base format a legal format for a color renderbuffer?
682 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
684 switch (baseFormat
) {
689 case GL_LUMINANCE_ALPHA
:
692 return ctx
->API
== API_OPENGL_COMPAT
&&
693 ctx
->Extensions
.ARB_framebuffer_object
;
696 return ctx
->Extensions
.ARB_texture_rg
;
704 * Is the given base format a legal format for a color renderbuffer?
707 is_format_color_renderable(const struct gl_context
*ctx
, mesa_format format
,
708 GLenum internalFormat
)
710 const GLenum baseFormat
=
711 _mesa_get_format_base_format(format
);
714 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
715 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
719 /* Reject additional cases for GLES */
720 switch (internalFormat
) {
741 if (internalFormat
!= GL_RGB10_A2
&&
742 (format
== MESA_FORMAT_B10G10R10A2_UNORM
||
743 format
== MESA_FORMAT_B10G10R10X2_UNORM
||
744 format
== MESA_FORMAT_R10G10B10A2_UNORM
||
745 format
== MESA_FORMAT_R10G10B10X2_UNORM
)) {
754 * Is the given base format a legal format for a depth/stencil renderbuffer?
757 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
759 switch (baseFormat
) {
760 case GL_DEPTH_COMPONENT
:
761 case GL_DEPTH_STENCIL_EXT
:
770 * Test if an attachment point is complete and update its Complete field.
771 * \param format if GL_COLOR, this is a color attachment point,
772 * if GL_DEPTH, this is a depth component attachment point,
773 * if GL_STENCIL, this is a stencil component attachment point.
776 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
777 struct gl_renderbuffer_attachment
*att
)
779 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
781 /* assume complete */
782 att
->Complete
= GL_TRUE
;
784 /* Look for reasons why the attachment might be incomplete */
785 if (att
->Type
== GL_TEXTURE
) {
786 const struct gl_texture_object
*texObj
= att
->Texture
;
787 struct gl_texture_image
*texImage
;
791 att_incomplete("no texobj");
792 att
->Complete
= GL_FALSE
;
796 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
798 att_incomplete("no teximage");
799 att
->Complete
= GL_FALSE
;
802 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
803 att_incomplete("teximage width/height=0");
804 att
->Complete
= GL_FALSE
;
808 switch (texObj
->Target
) {
810 if (att
->Zoffset
>= texImage
->Depth
) {
811 att_incomplete("bad z offset");
812 att
->Complete
= GL_FALSE
;
816 case GL_TEXTURE_1D_ARRAY
:
817 if (att
->Zoffset
>= texImage
->Height
) {
818 att_incomplete("bad 1D-array layer");
819 att
->Complete
= GL_FALSE
;
823 case GL_TEXTURE_2D_ARRAY
:
824 if (att
->Zoffset
>= texImage
->Depth
) {
825 att_incomplete("bad 2D-array layer");
826 att
->Complete
= GL_FALSE
;
830 case GL_TEXTURE_CUBE_MAP_ARRAY
:
831 if (att
->Zoffset
>= texImage
->Depth
) {
832 att_incomplete("bad cube-array layer");
833 att
->Complete
= GL_FALSE
;
839 baseFormat
= texImage
->_BaseFormat
;
841 if (format
== GL_COLOR
) {
842 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
843 att_incomplete("bad format");
844 att
->Complete
= GL_FALSE
;
847 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
848 att_incomplete("compressed internalformat");
849 att
->Complete
= GL_FALSE
;
853 /* OES_texture_float allows creation and use of floating point
854 * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow
855 * these textures to be used as a render target, this is done via
856 * GL_EXT_color_buffer(_half)_float with set of new sized types.
858 if (_mesa_is_gles(ctx
) && (texObj
->_IsFloat
|| texObj
->_IsHalfFloat
)) {
859 att_incomplete("bad internal format");
860 att
->Complete
= GL_FALSE
;
864 else if (format
== GL_DEPTH
) {
865 if (baseFormat
== GL_DEPTH_COMPONENT
) {
868 else if (ctx
->Extensions
.ARB_depth_texture
&&
869 baseFormat
== GL_DEPTH_STENCIL
) {
873 att
->Complete
= GL_FALSE
;
874 att_incomplete("bad depth format");
879 assert(format
== GL_STENCIL
);
880 if (ctx
->Extensions
.ARB_depth_texture
&&
881 baseFormat
== GL_DEPTH_STENCIL
) {
883 } else if (ctx
->Extensions
.ARB_texture_stencil8
&&
884 baseFormat
== GL_STENCIL_INDEX
) {
887 /* no such thing as stencil-only textures */
888 att_incomplete("illegal stencil texture");
889 att
->Complete
= GL_FALSE
;
894 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
895 const GLenum baseFormat
= att
->Renderbuffer
->_BaseFormat
;
897 assert(att
->Renderbuffer
);
898 if (!att
->Renderbuffer
->InternalFormat
||
899 att
->Renderbuffer
->Width
< 1 ||
900 att
->Renderbuffer
->Height
< 1) {
901 att_incomplete("0x0 renderbuffer");
902 att
->Complete
= GL_FALSE
;
905 if (format
== GL_COLOR
) {
906 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
907 att_incomplete("bad renderbuffer color format");
908 att
->Complete
= GL_FALSE
;
912 else if (format
== GL_DEPTH
) {
913 if (baseFormat
== GL_DEPTH_COMPONENT
) {
916 else if (baseFormat
== GL_DEPTH_STENCIL
) {
920 att_incomplete("bad renderbuffer depth format");
921 att
->Complete
= GL_FALSE
;
926 assert(format
== GL_STENCIL
);
927 if (baseFormat
== GL_STENCIL_INDEX
||
928 baseFormat
== GL_DEPTH_STENCIL
) {
932 att
->Complete
= GL_FALSE
;
933 att_incomplete("bad renderbuffer stencil format");
939 assert(att
->Type
== GL_NONE
);
947 * Test if the given framebuffer object is complete and update its
948 * Status field with the results.
949 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
950 * driver to make hardware-specific validation/completeness checks.
951 * Also update the framebuffer's Width and Height fields if the
952 * framebuffer is complete.
955 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
956 struct gl_framebuffer
*fb
)
959 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
960 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
961 GLint numSamples
= -1;
962 GLint fixedSampleLocations
= -1;
965 /* Covers max_layer_count, is_layered, and layer_tex_target */
966 bool layer_info_valid
= false;
967 GLuint max_layer_count
= 0, att_layer_count
;
968 bool is_layered
= false;
969 GLenum layer_tex_target
= 0;
970 bool has_depth_attachment
= false;
971 bool has_stencil_attachment
= false;
973 assert(_mesa_is_user_fbo(fb
));
975 /* we're changing framebuffer fields here */
976 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
981 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
982 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
983 fb
->_HasAttachments
= true;
984 fb
->_IntegerBuffers
= 0;
986 /* Start at -2 to more easily loop over all attachment points.
991 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
992 struct gl_renderbuffer_attachment
*att
;
994 mesa_format attFormat
;
995 GLenum att_tex_target
= GL_NONE
;
998 * XXX for ARB_fbo, only check color buffers that are named by
999 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
1002 /* check for attachment completeness
1005 att
= &fb
->Attachment
[BUFFER_DEPTH
];
1006 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
1007 if (!att
->Complete
) {
1008 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1009 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
1011 } else if (att
->Type
!= GL_NONE
) {
1012 has_depth_attachment
= true;
1016 att
= &fb
->Attachment
[BUFFER_STENCIL
];
1017 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
1018 if (!att
->Complete
) {
1019 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1020 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
1022 } else if (att
->Type
!= GL_NONE
) {
1023 has_stencil_attachment
= true;
1027 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
1028 test_attachment_completeness(ctx
, GL_COLOR
, att
);
1029 if (!att
->Complete
) {
1030 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1031 fbo_incomplete(ctx
, "color attachment incomplete", i
);
1036 /* get width, height, format of the renderbuffer/texture
1038 if (att
->Type
== GL_TEXTURE
) {
1039 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
1040 att_tex_target
= att
->Texture
->Target
;
1041 minWidth
= MIN2(minWidth
, texImg
->Width
);
1042 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
1043 minHeight
= MIN2(minHeight
, texImg
->Height
);
1044 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
1045 f
= texImg
->_BaseFormat
;
1046 attFormat
= texImg
->TexFormat
;
1049 if (!is_format_color_renderable(ctx
, attFormat
,
1050 texImg
->InternalFormat
) &&
1051 !is_legal_depth_format(ctx
, f
) &&
1052 f
!= GL_STENCIL_INDEX
) {
1053 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
;
1054 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
1059 numSamples
= texImg
->NumSamples
;
1060 else if (numSamples
!= texImg
->NumSamples
) {
1061 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1062 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1066 if (fixedSampleLocations
< 0)
1067 fixedSampleLocations
= texImg
->FixedSampleLocations
;
1068 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
1069 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1070 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1074 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1075 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
1076 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
1077 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
1078 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
1079 f
= att
->Renderbuffer
->InternalFormat
;
1080 attFormat
= att
->Renderbuffer
->Format
;
1084 numSamples
= att
->Renderbuffer
->NumSamples
;
1085 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
1086 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1087 fbo_incomplete(ctx
, "inconsistent sample count", -1);
1091 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1092 if (fixedSampleLocations
< 0)
1093 fixedSampleLocations
= GL_TRUE
;
1094 else if (fixedSampleLocations
!= GL_TRUE
) {
1095 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1096 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1101 assert(att
->Type
== GL_NONE
);
1105 /* Update flags describing color buffer datatypes */
1107 GLenum type
= _mesa_get_format_datatype(attFormat
);
1109 /* check if integer color */
1110 if (_mesa_is_format_integer_color(attFormat
))
1111 fb
->_IntegerBuffers
|= (1 << i
);
1113 fb
->_AllColorBuffersFixedPoint
=
1114 fb
->_AllColorBuffersFixedPoint
&&
1115 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1117 fb
->_HasSNormOrFloatColorBuffer
=
1118 fb
->_HasSNormOrFloatColorBuffer
||
1119 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1122 /* Error-check width, height, format */
1123 if (numImages
== 1) {
1130 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1131 /* check that width, height, format are same */
1132 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1133 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1134 fbo_incomplete(ctx
, "width or height mismatch", -1);
1137 /* check that all color buffers are the same format */
1138 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1139 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1140 fbo_incomplete(ctx
, "format mismatch", -1);
1146 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1148 if (att
->Type
== GL_RENDERBUFFER
&&
1149 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1150 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1151 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1155 /* Check that layered rendering is consistent. */
1157 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1158 att_layer_count
= 6;
1159 else if (att_tex_target
== GL_TEXTURE_1D_ARRAY
)
1160 att_layer_count
= att
->Renderbuffer
->Height
;
1162 att_layer_count
= att
->Renderbuffer
->Depth
;
1164 att_layer_count
= 0;
1166 if (!layer_info_valid
) {
1167 is_layered
= att
->Layered
;
1168 max_layer_count
= att_layer_count
;
1169 layer_tex_target
= att_tex_target
;
1170 layer_info_valid
= true;
1171 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1172 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1173 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1175 } else if (is_layered
!= att
->Layered
) {
1176 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1178 "framebuffer attachment layer mode is inconsistent",
1181 } else if (att_layer_count
> max_layer_count
) {
1182 max_layer_count
= att_layer_count
;
1186 * The extension GL_ARB_framebuffer_no_attachments places additional
1187 * requirement on each attachment. Those additional requirements are
1188 * tighter that those of previous versions of GL. In interest of better
1189 * compatibility, we will not enforce these restrictions. For the record
1190 * those additional restrictions are quoted below:
1192 * "The width and height of image are greater than zero and less than or
1193 * equal to the values of the implementation-dependent limits
1194 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1196 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1197 * array texture and the attachment is layered, the depth or layer count
1198 * of the texture is less than or equal to the implementation-dependent
1199 * limit MAX_FRAMEBUFFER_LAYERS."
1201 * "If image has multiple samples, its sample count is less than or equal
1202 * to the value of the implementation-dependent limit
1203 * MAX_FRAMEBUFFER_SAMPLES."
1205 * The same requirements are also in place for GL 4.5,
1206 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1210 fb
->MaxNumLayers
= max_layer_count
;
1212 if (numImages
== 0) {
1213 fb
->_HasAttachments
= false;
1215 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1216 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1217 fbo_incomplete(ctx
, "no attachments", -1);
1221 if (fb
->DefaultGeometry
.Width
== 0 || fb
->DefaultGeometry
.Height
== 0) {
1222 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1223 fbo_incomplete(ctx
, "no attachments and default width or height is 0", -1);
1228 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1229 /* Check that all DrawBuffers are present */
1230 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1231 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1232 const struct gl_renderbuffer_attachment
*att
1233 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
], NULL
);
1235 if (att
->Type
== GL_NONE
) {
1236 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1237 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1243 /* Check that the ReadBuffer is present */
1244 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1245 const struct gl_renderbuffer_attachment
*att
1246 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
, NULL
);
1248 if (att
->Type
== GL_NONE
) {
1249 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1250 fbo_incomplete(ctx
, "missing readbuffer", -1);
1256 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1258 * "Depth and stencil attachments, if present, are the same image."
1260 * This restriction is not present in the OpenGL ES2 spec.
1262 if (_mesa_is_gles3(ctx
) &&
1263 has_stencil_attachment
&& has_depth_attachment
&&
1264 !_mesa_has_depthstencil_combined(fb
)) {
1265 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1266 fbo_incomplete(ctx
, "Depth and stencil attachments must be the same image", -1);
1270 /* Provisionally set status = COMPLETE ... */
1271 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1273 /* ... but the driver may say the FB is incomplete.
1274 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1277 if (ctx
->Driver
.ValidateFramebuffer
) {
1278 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1279 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1280 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1286 * Note that if ARB_framebuffer_object is supported and the attached
1287 * renderbuffers/textures are different sizes, the framebuffer
1288 * width/height will be set to the smallest width/height.
1290 if (numImages
!= 0) {
1291 fb
->Width
= minWidth
;
1292 fb
->Height
= minHeight
;
1295 /* finally, update the visual info for the framebuffer */
1296 _mesa_update_framebuffer_visual(ctx
, fb
);
1300 GLboolean GLAPIENTRY
1301 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1303 struct gl_renderbuffer
*rb
;
1305 GET_CURRENT_CONTEXT(ctx
);
1307 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1309 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1310 return rb
!= NULL
&& rb
!= &DummyRenderbuffer
;
1314 static struct gl_renderbuffer
*
1315 allocate_renderbuffer_locked(struct gl_context
*ctx
, GLuint renderbuffer
,
1318 struct gl_renderbuffer
*newRb
;
1320 /* create new renderbuffer object */
1321 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1323 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1326 assert(newRb
->AllocStorage
);
1327 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1334 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1336 struct gl_renderbuffer
*newRb
;
1337 GET_CURRENT_CONTEXT(ctx
);
1339 if (target
!= GL_RENDERBUFFER_EXT
) {
1340 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1344 /* No need to flush here since the render buffer binding has no
1345 * effect on rendering state.
1349 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1350 if (newRb
== &DummyRenderbuffer
) {
1351 /* ID was reserved, but no real renderbuffer object made yet */
1354 else if (!newRb
&& !allow_user_names
) {
1355 /* All RB IDs must be Gen'd */
1356 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1361 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1362 newRb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
1363 "glBindRenderbufferEXT");
1364 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1371 assert(newRb
!= &DummyRenderbuffer
);
1373 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1377 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1379 GET_CURRENT_CONTEXT(ctx
);
1381 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1382 * entry point, but they allow the use of user-generated names.
1384 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1388 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1390 /* This function should not be in the dispatch table for core profile /
1391 * OpenGL 3.1, so execution should never get here in those cases -- no
1392 * need for an explicit test.
1394 bind_renderbuffer(target
, renderbuffer
, true);
1398 * ARB_framebuffer_no_attachment - Application passes requested param's
1399 * here. NOTE: NumSamples requested need not be _NumSamples which is
1400 * what the hw supports.
1403 framebuffer_parameteri(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1404 GLenum pname
, GLint param
, const char *func
)
1407 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1408 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferWidth
)
1409 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1411 fb
->DefaultGeometry
.Width
= param
;
1413 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1414 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferHeight
)
1415 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1417 fb
->DefaultGeometry
.Height
= param
;
1419 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1421 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1422 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1424 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1425 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1428 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferLayers
)
1429 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1431 fb
->DefaultGeometry
.Layers
= param
;
1433 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1434 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferSamples
)
1435 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1437 fb
->DefaultGeometry
.NumSamples
= param
;
1439 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1440 fb
->DefaultGeometry
.FixedSampleLocations
= param
;
1443 _mesa_error(ctx
, GL_INVALID_ENUM
,
1444 "%s(pname=0x%x)", func
, pname
);
1447 invalidate_framebuffer(fb
);
1448 ctx
->NewState
|= _NEW_BUFFERS
;
1452 _mesa_FramebufferParameteri(GLenum target
, GLenum pname
, GLint param
)
1454 GET_CURRENT_CONTEXT(ctx
);
1455 struct gl_framebuffer
*fb
;
1457 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1458 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1459 "glFramebufferParameteriv not supported "
1460 "(ARB_framebuffer_no_attachments not implemented)");
1464 fb
= get_framebuffer_target(ctx
, target
);
1466 _mesa_error(ctx
, GL_INVALID_ENUM
,
1467 "glFramebufferParameteri(target=0x%x)", target
);
1471 /* check framebuffer binding */
1472 if (_mesa_is_winsys_fbo(fb
)) {
1473 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1474 "glFramebufferParameteri");
1478 framebuffer_parameteri(ctx
, fb
, pname
, param
, "glFramebufferParameteri");
1482 _pname_valid_for_default_framebuffer(struct gl_context
*ctx
,
1485 if (!_mesa_is_desktop_gl(ctx
))
1489 case GL_DOUBLEBUFFER
:
1490 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1491 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1493 case GL_SAMPLE_BUFFERS
:
1502 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1503 GLenum pname
, GLint
*params
, const char *func
)
1505 /* From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries:
1507 * "An INVALID_OPERATION error is generated by GetFramebufferParameteriv
1508 * if the default framebuffer is bound to target and pname is not one
1509 * of the accepted values from table 23.73, other than
1512 * For OpenGL ES, using default framebuffer still raises INVALID_OPERATION
1515 if (_mesa_is_winsys_fbo(fb
) &&
1516 !_pname_valid_for_default_framebuffer(ctx
, pname
)) {
1517 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1518 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1523 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1524 *params
= fb
->DefaultGeometry
.Width
;
1526 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1527 *params
= fb
->DefaultGeometry
.Height
;
1529 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1531 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1532 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1534 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1535 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1538 *params
= fb
->DefaultGeometry
.Layers
;
1540 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1541 *params
= fb
->DefaultGeometry
.NumSamples
;
1543 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1544 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1546 case GL_DOUBLEBUFFER
:
1547 *params
= fb
->Visual
.doubleBufferMode
;
1549 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1550 *params
= _mesa_get_color_read_format(ctx
, fb
, func
);
1552 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1553 *params
= _mesa_get_color_read_type(ctx
, fb
, func
);
1556 *params
= _mesa_geometric_samples(fb
);
1558 case GL_SAMPLE_BUFFERS
:
1559 *params
= _mesa_geometric_samples(fb
) > 0;
1562 *params
= fb
->Visual
.stereoMode
;
1565 _mesa_error(ctx
, GL_INVALID_ENUM
,
1566 "%s(pname=0x%x)", func
, pname
);
1571 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1573 GET_CURRENT_CONTEXT(ctx
);
1574 struct gl_framebuffer
*fb
;
1576 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1577 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1578 "glGetFramebufferParameteriv not supported "
1579 "(ARB_framebuffer_no_attachments not implemented)");
1583 fb
= get_framebuffer_target(ctx
, target
);
1585 _mesa_error(ctx
, GL_INVALID_ENUM
,
1586 "glGetFramebufferParameteriv(target=0x%x)", target
);
1590 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1591 "glGetFramebufferParameteriv");
1596 * Remove the specified renderbuffer or texture from any attachment point in
1600 * \c true if the renderbuffer was detached from an attachment point. \c
1604 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1605 struct gl_framebuffer
*fb
,
1609 bool progress
= false;
1611 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1612 if (fb
->Attachment
[i
].Texture
== att
1613 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1614 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1619 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1620 * Completeness," of the OpenGL 3.1 spec says:
1622 * "Performing any of the following actions may change whether the
1623 * framebuffer is considered complete or incomplete:
1627 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1628 * containing an image that is attached to a framebuffer object
1629 * that is bound to the framebuffer."
1632 invalidate_framebuffer(fb
);
1639 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1642 GET_CURRENT_CONTEXT(ctx
);
1645 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1649 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1651 for (i
= 0; i
< n
; i
++) {
1652 if (renderbuffers
[i
] > 0) {
1653 struct gl_renderbuffer
*rb
;
1654 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1656 /* check if deleting currently bound renderbuffer object */
1657 if (rb
== ctx
->CurrentRenderbuffer
) {
1659 assert(rb
->RefCount
>= 2);
1660 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1663 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1664 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1665 * of the OpenGL 3.1 spec says:
1667 * "If a renderbuffer object is deleted while its image is
1668 * attached to one or more attachment points in the currently
1669 * bound framebuffer, then it is as if FramebufferRenderbuffer
1670 * had been called, with a renderbuffer of 0, for each
1671 * attachment point to which this image was attached in the
1672 * currently bound framebuffer. In other words, this
1673 * renderbuffer image is first detached from all attachment
1674 * points in the currently bound framebuffer. Note that the
1675 * renderbuffer image is specifically not detached from any
1676 * non-bound framebuffers. Detaching the image from any
1677 * non-bound framebuffers is the responsibility of the
1680 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1681 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1683 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1684 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1685 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1688 /* Remove from hash table immediately, to free the ID.
1689 * But the object will not be freed until it's no longer
1690 * referenced anywhere else.
1692 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1694 if (rb
!= &DummyRenderbuffer
) {
1695 /* no longer referenced by hash table */
1696 _mesa_reference_renderbuffer(&rb
, NULL
);
1704 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1707 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1714 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1716 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1718 for (i
= 0; i
< n
; i
++) {
1719 GLuint name
= first
+ i
;
1720 renderbuffers
[i
] = name
;
1723 allocate_renderbuffer_locked(ctx
, name
, func
);
1725 /* insert a dummy renderbuffer into the hash table */
1726 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1727 &DummyRenderbuffer
);
1731 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1736 create_render_buffers_err(struct gl_context
*ctx
, GLsizei n
,
1737 GLuint
*renderbuffers
, bool dsa
)
1739 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1742 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1746 create_render_buffers(ctx
, n
, renderbuffers
, dsa
);
1751 _mesa_GenRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1753 GET_CURRENT_CONTEXT(ctx
);
1754 create_render_buffers(ctx
, n
, renderbuffers
, false);
1759 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1761 GET_CURRENT_CONTEXT(ctx
);
1762 create_render_buffers_err(ctx
, n
, renderbuffers
, false);
1767 _mesa_CreateRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1769 GET_CURRENT_CONTEXT(ctx
);
1770 create_render_buffers(ctx
, n
, renderbuffers
, true);
1775 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1777 GET_CURRENT_CONTEXT(ctx
);
1778 create_render_buffers_err(ctx
, n
, renderbuffers
, true);
1783 * Given an internal format token for a render buffer, return the
1784 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1785 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1786 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1788 * This is similar to _mesa_base_tex_format() but the set of valid
1789 * internal formats is different.
1791 * Note that even if a format is determined to be legal here, validation
1792 * of the FBO may fail if the format is not supported by the driver/GPU.
1794 * \param internalFormat as passed to glRenderbufferStorage()
1795 * \return the base internal format, or 0 if internalFormat is illegal
1798 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1801 * Notes: some formats such as alpha, luminance, etc. were added
1802 * with GL_ARB_framebuffer_object.
1804 switch (internalFormat
) {
1810 return (ctx
->API
== API_OPENGL_COMPAT
&&
1811 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
1815 case GL_LUMINANCE12
:
1816 case GL_LUMINANCE16
:
1817 return (ctx
->API
== API_OPENGL_COMPAT
&&
1818 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
1819 case GL_LUMINANCE_ALPHA
:
1820 case GL_LUMINANCE4_ALPHA4
:
1821 case GL_LUMINANCE6_ALPHA2
:
1822 case GL_LUMINANCE8_ALPHA8
:
1823 case GL_LUMINANCE12_ALPHA4
:
1824 case GL_LUMINANCE12_ALPHA12
:
1825 case GL_LUMINANCE16_ALPHA16
:
1826 return (ctx
->API
== API_OPENGL_COMPAT
&&
1827 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
1831 case GL_INTENSITY12
:
1832 case GL_INTENSITY16
:
1833 return (ctx
->API
== API_OPENGL_COMPAT
&&
1834 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
1844 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1846 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1855 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1857 case GL_SRGB8_ALPHA8_EXT
:
1858 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1859 case GL_STENCIL_INDEX
:
1860 case GL_STENCIL_INDEX1_EXT
:
1861 case GL_STENCIL_INDEX4_EXT
:
1862 case GL_STENCIL_INDEX16_EXT
:
1863 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1864 * OpenGL ES, but Mesa does not currently support them.
1866 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1867 case GL_STENCIL_INDEX8_EXT
:
1868 return GL_STENCIL_INDEX
;
1869 case GL_DEPTH_COMPONENT
:
1870 case GL_DEPTH_COMPONENT32
:
1871 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1872 case GL_DEPTH_COMPONENT16
:
1873 case GL_DEPTH_COMPONENT24
:
1874 return GL_DEPTH_COMPONENT
;
1875 case GL_DEPTH_STENCIL
:
1876 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
1877 case GL_DEPTH24_STENCIL8
:
1878 return GL_DEPTH_STENCIL
;
1879 case GL_DEPTH_COMPONENT32F
:
1880 return ctx
->Version
>= 30
1881 || (ctx
->API
== API_OPENGL_COMPAT
&&
1882 ctx
->Extensions
.ARB_depth_buffer_float
)
1883 ? GL_DEPTH_COMPONENT
: 0;
1884 case GL_DEPTH32F_STENCIL8
:
1885 return ctx
->Version
>= 30
1886 || (ctx
->API
== API_OPENGL_COMPAT
&&
1887 ctx
->Extensions
.ARB_depth_buffer_float
)
1888 ? GL_DEPTH_STENCIL
: 0;
1891 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1894 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1898 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1901 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1903 /* signed normalized texture formats */
1907 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1912 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1916 case GL_RGB16_SNORM
:
1917 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1920 case GL_RGBA8_SNORM
:
1921 case GL_RGBA16_SNORM
:
1922 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1924 case GL_ALPHA_SNORM
:
1925 case GL_ALPHA8_SNORM
:
1926 case GL_ALPHA16_SNORM
:
1927 return ctx
->API
== API_OPENGL_COMPAT
&&
1928 ctx
->Extensions
.EXT_texture_snorm
&&
1929 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1930 case GL_LUMINANCE_SNORM
:
1931 case GL_LUMINANCE8_SNORM
:
1932 case GL_LUMINANCE16_SNORM
:
1933 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1935 case GL_LUMINANCE_ALPHA_SNORM
:
1936 case GL_LUMINANCE8_ALPHA8_SNORM
:
1937 case GL_LUMINANCE16_ALPHA16_SNORM
:
1938 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1939 ? GL_LUMINANCE_ALPHA
: 0;
1940 case GL_INTENSITY_SNORM
:
1941 case GL_INTENSITY8_SNORM
:
1942 case GL_INTENSITY16_SNORM
:
1943 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1948 return ((_mesa_is_desktop_gl(ctx
) &&
1949 ctx
->Extensions
.ARB_texture_rg
&&
1950 ctx
->Extensions
.ARB_texture_float
) ||
1951 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1955 return ((_mesa_is_desktop_gl(ctx
) &&
1956 ctx
->Extensions
.ARB_texture_rg
&&
1957 ctx
->Extensions
.ARB_texture_float
) ||
1958 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1962 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1966 return ((_mesa_is_desktop_gl(ctx
) &&
1967 ctx
->Extensions
.ARB_texture_float
) ||
1968 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1970 case GL_ALPHA16F_ARB
:
1971 case GL_ALPHA32F_ARB
:
1972 return ctx
->API
== API_OPENGL_COMPAT
&&
1973 ctx
->Extensions
.ARB_texture_float
&&
1974 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1975 case GL_LUMINANCE16F_ARB
:
1976 case GL_LUMINANCE32F_ARB
:
1977 return ctx
->API
== API_OPENGL_COMPAT
&&
1978 ctx
->Extensions
.ARB_texture_float
&&
1979 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1980 case GL_LUMINANCE_ALPHA16F_ARB
:
1981 case GL_LUMINANCE_ALPHA32F_ARB
:
1982 return ctx
->API
== API_OPENGL_COMPAT
&&
1983 ctx
->Extensions
.ARB_texture_float
&&
1984 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1985 case GL_INTENSITY16F_ARB
:
1986 case GL_INTENSITY32F_ARB
:
1987 return ctx
->API
== API_OPENGL_COMPAT
&&
1988 ctx
->Extensions
.ARB_texture_float
&&
1989 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1990 case GL_R11F_G11F_B10F
:
1991 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1992 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1995 case GL_RGBA8UI_EXT
:
1996 case GL_RGBA16UI_EXT
:
1997 case GL_RGBA32UI_EXT
:
1999 case GL_RGBA16I_EXT
:
2000 case GL_RGBA32I_EXT
:
2001 return ctx
->Version
>= 30
2002 || (_mesa_is_desktop_gl(ctx
) &&
2003 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
2006 case GL_RGB16UI_EXT
:
2007 case GL_RGB32UI_EXT
:
2011 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
2019 return ctx
->Version
>= 30
2020 || (_mesa_is_desktop_gl(ctx
) &&
2021 ctx
->Extensions
.ARB_texture_rg
&&
2022 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
2030 return ctx
->Version
>= 30
2031 || (_mesa_is_desktop_gl(ctx
) &&
2032 ctx
->Extensions
.ARB_texture_rg
&&
2033 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
2035 case GL_INTENSITY8I_EXT
:
2036 case GL_INTENSITY8UI_EXT
:
2037 case GL_INTENSITY16I_EXT
:
2038 case GL_INTENSITY16UI_EXT
:
2039 case GL_INTENSITY32I_EXT
:
2040 case GL_INTENSITY32UI_EXT
:
2041 return ctx
->API
== API_OPENGL_COMPAT
&&
2042 ctx
->Extensions
.EXT_texture_integer
&&
2043 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2045 case GL_LUMINANCE8I_EXT
:
2046 case GL_LUMINANCE8UI_EXT
:
2047 case GL_LUMINANCE16I_EXT
:
2048 case GL_LUMINANCE16UI_EXT
:
2049 case GL_LUMINANCE32I_EXT
:
2050 case GL_LUMINANCE32UI_EXT
:
2051 return ctx
->API
== API_OPENGL_COMPAT
&&
2052 ctx
->Extensions
.EXT_texture_integer
&&
2053 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2055 case GL_LUMINANCE_ALPHA8I_EXT
:
2056 case GL_LUMINANCE_ALPHA8UI_EXT
:
2057 case GL_LUMINANCE_ALPHA16I_EXT
:
2058 case GL_LUMINANCE_ALPHA16UI_EXT
:
2059 case GL_LUMINANCE_ALPHA32I_EXT
:
2060 case GL_LUMINANCE_ALPHA32UI_EXT
:
2061 return ctx
->API
== API_OPENGL_COMPAT
&&
2062 ctx
->Extensions
.EXT_texture_integer
&&
2063 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2065 case GL_ALPHA8I_EXT
:
2066 case GL_ALPHA8UI_EXT
:
2067 case GL_ALPHA16I_EXT
:
2068 case GL_ALPHA16UI_EXT
:
2069 case GL_ALPHA32I_EXT
:
2070 case GL_ALPHA32UI_EXT
:
2071 return ctx
->API
== API_OPENGL_COMPAT
&&
2072 ctx
->Extensions
.EXT_texture_integer
&&
2073 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2076 return (_mesa_is_desktop_gl(ctx
) &&
2077 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
2078 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2081 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2090 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2093 invalidate_rb(GLuint key
, void *data
, void *userData
)
2095 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2096 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2098 /* If this is a user-created FBO */
2099 if (_mesa_is_user_fbo(fb
)) {
2101 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2102 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2103 if (att
->Type
== GL_RENDERBUFFER
&&
2104 att
->Renderbuffer
== rb
) {
2105 /* Mark fb status as indeterminate to force re-validation */
2114 /** sentinal value, see below */
2115 #define NO_SAMPLES 1000
2118 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2119 GLenum internalFormat
, GLsizei width
,
2120 GLsizei height
, GLsizei samples
)
2122 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2124 assert(baseFormat
!= 0);
2125 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2126 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2127 assert(samples
!= NO_SAMPLES
);
2129 assert(samples
> 0);
2130 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2131 internalFormat
, samples
) == GL_NO_ERROR
);
2134 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2136 if (rb
->InternalFormat
== internalFormat
&&
2137 rb
->Width
== (GLuint
) width
&&
2138 rb
->Height
== (GLuint
) height
&&
2139 rb
->NumSamples
== samples
) {
2140 /* no change in allocation needed */
2144 /* These MUST get set by the AllocStorage func */
2145 rb
->Format
= MESA_FORMAT_NONE
;
2146 rb
->NumSamples
= samples
;
2148 /* Now allocate the storage */
2149 assert(rb
->AllocStorage
);
2150 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2151 /* No error - check/set fields now */
2152 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2153 assert(rb
->Width
== (GLuint
) width
);
2154 assert(rb
->Height
== (GLuint
) height
);
2155 rb
->InternalFormat
= internalFormat
;
2156 rb
->_BaseFormat
= baseFormat
;
2157 assert(rb
->_BaseFormat
!= 0);
2160 /* Probably ran out of memory - clear the fields */
2163 rb
->Format
= MESA_FORMAT_NONE
;
2164 rb
->InternalFormat
= GL_NONE
;
2165 rb
->_BaseFormat
= GL_NONE
;
2169 /* Invalidate the framebuffers the renderbuffer is attached in. */
2170 if (rb
->AttachedAnytime
) {
2171 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2176 * Helper function used by renderbuffer_storage_direct() and
2177 * renderbuffer_storage_target().
2178 * samples will be NO_SAMPLES if called by a non-multisample function.
2181 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2182 GLenum internalFormat
, GLsizei width
,
2183 GLsizei height
, GLsizei samples
, const char *func
)
2186 GLenum sample_count_error
;
2188 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2189 if (baseFormat
== 0) {
2190 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2191 func
, _mesa_enum_to_string(internalFormat
));
2195 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2196 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2201 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2202 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2207 if (samples
== NO_SAMPLES
) {
2208 /* NumSamples == 0 indicates non-multisampling */
2212 /* check the sample count;
2213 * note: driver may choose to use more samples than what's requested
2215 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2216 internalFormat
, samples
);
2218 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2220 * "If a negative number is provided where an argument of type sizei or
2221 * sizeiptr is specified, the error INVALID VALUE is generated."
2224 sample_count_error
= GL_INVALID_VALUE
;
2227 if (sample_count_error
!= GL_NO_ERROR
) {
2228 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
2233 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
);
2237 * Helper function used by _mesa_NamedRenderbufferStorage*().
2238 * samples will be NO_SAMPLES if called by a non-multisample function.
2241 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2242 GLsizei width
, GLsizei height
, GLsizei samples
,
2245 GET_CURRENT_CONTEXT(ctx
);
2247 if (MESA_VERBOSE
& VERBOSE_API
) {
2248 if (samples
== NO_SAMPLES
)
2249 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2251 _mesa_enum_to_string(internalFormat
),
2254 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2256 _mesa_enum_to_string(internalFormat
),
2257 width
, height
, samples
);
2260 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2261 if (!rb
|| rb
== &DummyRenderbuffer
) {
2262 /* ID was reserved, but no real renderbuffer object made yet */
2263 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2264 func
, renderbuffer
);
2268 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
, func
);
2272 * Helper function used by _mesa_RenderbufferStorage() and
2273 * _mesa_RenderbufferStorageMultisample().
2274 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2277 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2278 GLsizei width
, GLsizei height
, GLsizei samples
,
2281 GET_CURRENT_CONTEXT(ctx
);
2283 if (MESA_VERBOSE
& VERBOSE_API
) {
2284 if (samples
== NO_SAMPLES
)
2285 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2287 _mesa_enum_to_string(target
),
2288 _mesa_enum_to_string(internalFormat
),
2291 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2293 _mesa_enum_to_string(target
),
2294 _mesa_enum_to_string(internalFormat
),
2295 width
, height
, samples
);
2298 if (target
!= GL_RENDERBUFFER_EXT
) {
2299 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2303 if (!ctx
->CurrentRenderbuffer
) {
2304 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2309 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2310 height
, samples
, func
);
2315 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2317 struct gl_renderbuffer
*rb
;
2318 GET_CURRENT_CONTEXT(ctx
);
2320 if (!ctx
->Extensions
.OES_EGL_image
) {
2321 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2322 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2326 if (target
!= GL_RENDERBUFFER
) {
2327 _mesa_error(ctx
, GL_INVALID_ENUM
,
2328 "EGLImageTargetRenderbufferStorageOES");
2332 rb
= ctx
->CurrentRenderbuffer
;
2334 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2335 "EGLImageTargetRenderbufferStorageOES");
2339 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2341 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2346 * Helper function for _mesa_GetRenderbufferParameteriv() and
2347 * _mesa_GetFramebufferAttachmentParameteriv()
2348 * We have to be careful to respect the base format. For example, if a
2349 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2350 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2351 * we need to return zero.
2354 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2356 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2357 return _mesa_get_format_bits(format
, pname
);
2365 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2366 GLsizei width
, GLsizei height
)
2368 /* GL_ARB_fbo says calling this function is equivalent to calling
2369 * glRenderbufferStorageMultisample() with samples=0. We pass in
2370 * a token value here just for error reporting purposes.
2372 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2373 NO_SAMPLES
, "glRenderbufferStorage");
2378 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2379 GLenum internalFormat
,
2380 GLsizei width
, GLsizei height
)
2382 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2383 samples
, "glRenderbufferStorageMultisample");
2388 * OpenGL ES version of glRenderBufferStorage.
2391 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2392 GLsizei width
, GLsizei height
)
2394 switch (internalFormat
) {
2396 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2397 /* choose a closest format */
2398 internalFormat
= GL_RGB5
;
2404 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0,
2405 "glRenderbufferStorageEXT");
2409 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2410 GLsizei width
, GLsizei height
)
2412 /* GL_ARB_fbo says calling this function is equivalent to calling
2413 * glRenderbufferStorageMultisample() with samples=0. We pass in
2414 * a token value here just for error reporting purposes.
2416 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2417 NO_SAMPLES
, "glNamedRenderbufferStorage");
2421 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2422 GLenum internalformat
,
2423 GLsizei width
, GLsizei height
)
2425 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2427 "glNamedRenderbufferStorageMultisample");
2432 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2433 struct gl_renderbuffer
*rb
, GLenum pname
,
2434 GLint
*params
, const char *func
)
2436 /* No need to flush here since we're just quering state which is
2437 * not effected by rendering.
2441 case GL_RENDERBUFFER_WIDTH_EXT
:
2442 *params
= rb
->Width
;
2444 case GL_RENDERBUFFER_HEIGHT_EXT
:
2445 *params
= rb
->Height
;
2447 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2448 *params
= rb
->InternalFormat
;
2450 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2451 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2452 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2453 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2454 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2455 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2456 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2458 case GL_RENDERBUFFER_SAMPLES
:
2459 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2460 || _mesa_is_gles3(ctx
)) {
2461 *params
= rb
->NumSamples
;
2466 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2467 _mesa_enum_to_string(pname
));
2474 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2476 GET_CURRENT_CONTEXT(ctx
);
2478 if (target
!= GL_RENDERBUFFER_EXT
) {
2479 _mesa_error(ctx
, GL_INVALID_ENUM
,
2480 "glGetRenderbufferParameterivEXT(target)");
2484 if (!ctx
->CurrentRenderbuffer
) {
2485 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2486 "(no renderbuffer bound)");
2490 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2491 params
, "glGetRenderbufferParameteriv");
2496 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2499 GET_CURRENT_CONTEXT(ctx
);
2501 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2502 if (!rb
|| rb
== &DummyRenderbuffer
) {
2503 /* ID was reserved, but no real renderbuffer object made yet */
2504 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2505 "(invalid renderbuffer %i)", renderbuffer
);
2509 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2510 "glGetNamedRenderbufferParameteriv");
2514 GLboolean GLAPIENTRY
2515 _mesa_IsFramebuffer(GLuint framebuffer
)
2517 GET_CURRENT_CONTEXT(ctx
);
2518 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2520 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2521 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2529 * Check if any of the attachments of the given framebuffer are textures
2530 * (render to texture). Call ctx->Driver.RenderTexture() for such
2534 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2537 assert(ctx
->Driver
.RenderTexture
);
2539 if (_mesa_is_winsys_fbo(fb
))
2540 return; /* can't render to texture with winsys framebuffers */
2542 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2543 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2544 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2545 && driver_RenderTexture_is_safe(att
)) {
2546 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2553 * Examine all the framebuffer's attachments to see if any are textures.
2554 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2555 * notify the device driver that the texture image may have changed.
2558 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2560 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2561 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2564 if (ctx
->Driver
.FinishRenderTexture
) {
2566 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2567 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2568 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2569 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2570 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2578 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2580 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2581 GLboolean bindReadBuf
, bindDrawBuf
;
2582 GET_CURRENT_CONTEXT(ctx
);
2585 case GL_DRAW_FRAMEBUFFER_EXT
:
2586 bindDrawBuf
= GL_TRUE
;
2587 bindReadBuf
= GL_FALSE
;
2589 case GL_READ_FRAMEBUFFER_EXT
:
2590 bindDrawBuf
= GL_FALSE
;
2591 bindReadBuf
= GL_TRUE
;
2593 case GL_FRAMEBUFFER_EXT
:
2594 bindDrawBuf
= GL_TRUE
;
2595 bindReadBuf
= GL_TRUE
;
2598 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2603 /* Binding a user-created framebuffer object */
2604 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2605 if (newDrawFb
== &DummyFramebuffer
) {
2606 /* ID was reserved, but no real framebuffer object made yet */
2609 else if (!newDrawFb
&& !allow_user_names
) {
2610 /* All FBO IDs must be Gen'd */
2611 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2616 /* create new framebuffer object */
2617 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2619 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2622 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2624 newReadFb
= newDrawFb
;
2627 /* Binding the window system framebuffer (which was originally set
2628 * with MakeCurrent).
2630 newDrawFb
= ctx
->WinSysDrawBuffer
;
2631 newReadFb
= ctx
->WinSysReadBuffer
;
2634 _mesa_bind_framebuffers(ctx
,
2635 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2636 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2640 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2641 struct gl_framebuffer
*newDrawFb
,
2642 struct gl_framebuffer
*newReadFb
)
2644 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
2645 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
2646 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
2647 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
2650 assert(newDrawFb
!= &DummyFramebuffer
);
2653 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2655 * We also check if we're beginning and/or ending render-to-texture.
2656 * When a framebuffer with texture attachments is unbound, call
2657 * ctx->Driver.FinishRenderTexture().
2658 * When a framebuffer with texture attachments is bound, call
2659 * ctx->Driver.RenderTexture().
2661 * Note that if the ReadBuffer has texture attachments we don't consider
2662 * that a render-to-texture case.
2665 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2667 /* check if old readbuffer was render-to-texture */
2668 check_end_texture_render(ctx
, oldReadFb
);
2670 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2674 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2676 /* check if old framebuffer had any texture attachments */
2678 check_end_texture_render(ctx
, oldDrawFb
);
2680 /* check if newly bound framebuffer has any texture attachments */
2681 check_begin_texture_render(ctx
, newDrawFb
);
2683 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2686 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2687 /* The few classic drivers that actually hook this function really only
2688 * want to know if the draw framebuffer changed.
2690 ctx
->Driver
.BindFramebuffer(ctx
,
2691 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
2692 newDrawFb
, newReadFb
);
2697 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2699 GET_CURRENT_CONTEXT(ctx
);
2701 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2702 * point, but they allow the use of user-generated names.
2704 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2709 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2711 /* This function should not be in the dispatch table for core profile /
2712 * OpenGL 3.1, so execution should never get here in those cases -- no
2713 * need for an explicit test.
2715 bind_framebuffer(target
, framebuffer
, true);
2720 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2723 GET_CURRENT_CONTEXT(ctx
);
2726 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
2730 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2732 for (i
= 0; i
< n
; i
++) {
2733 if (framebuffers
[i
] > 0) {
2734 struct gl_framebuffer
*fb
;
2735 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2737 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2739 /* check if deleting currently bound framebuffer object */
2740 if (fb
== ctx
->DrawBuffer
) {
2742 assert(fb
->RefCount
>= 2);
2743 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2745 if (fb
== ctx
->ReadBuffer
) {
2747 assert(fb
->RefCount
>= 2);
2748 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2751 /* remove from hash table immediately, to free the ID */
2752 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2754 if (fb
!= &DummyFramebuffer
) {
2755 /* But the object will not be freed until it's no longer
2756 * bound in any context.
2758 _mesa_reference_framebuffer(&fb
, NULL
);
2767 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2768 * It is not exposed to the rest of Mesa to encourage the use of
2769 * nameless buffers in driver internals.
2772 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
2774 GET_CURRENT_CONTEXT(ctx
);
2777 struct gl_framebuffer
*fb
;
2779 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
2782 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
2789 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
2791 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2793 for (i
= 0; i
< n
; i
++) {
2794 GLuint name
= first
+ i
;
2795 framebuffers
[i
] = name
;
2798 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
2800 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2801 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
2806 fb
= &DummyFramebuffer
;
2808 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
2811 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
2816 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2818 create_framebuffers(n
, framebuffers
, false);
2823 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2825 create_framebuffers(n
, framebuffers
, true);
2830 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
2831 struct gl_framebuffer
*buffer
)
2833 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2835 if (_mesa_is_winsys_fbo(buffer
)) {
2836 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2837 if (buffer
!= &IncompleteFramebuffer
) {
2838 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2840 return GL_FRAMEBUFFER_UNDEFINED
;
2844 /* No need to flush here */
2846 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2847 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2850 return buffer
->_Status
;
2855 _mesa_CheckFramebufferStatus_no_error(GLenum target
)
2857 GET_CURRENT_CONTEXT(ctx
);
2859 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
2860 return _mesa_check_framebuffer_status(ctx
, fb
);
2865 _mesa_CheckFramebufferStatus(GLenum target
)
2867 struct gl_framebuffer
*fb
;
2868 GET_CURRENT_CONTEXT(ctx
);
2870 if (MESA_VERBOSE
& VERBOSE_API
)
2871 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2872 _mesa_enum_to_string(target
));
2874 fb
= get_framebuffer_target(ctx
, target
);
2876 _mesa_error(ctx
, GL_INVALID_ENUM
,
2877 "glCheckFramebufferStatus(invalid target %s)",
2878 _mesa_enum_to_string(target
));
2882 return _mesa_check_framebuffer_status(ctx
, fb
);
2887 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
2889 struct gl_framebuffer
*fb
;
2890 GET_CURRENT_CONTEXT(ctx
);
2892 /* Validate the target (for conformance's sake) and grab a reference to the
2893 * default framebuffer in case framebuffer = 0.
2894 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
2895 * (30.10.2014, PDF page 336) says:
2896 * "If framebuffer is zero, then the status of the default read or
2897 * draw framebuffer (as determined by target) is returned."
2900 case GL_DRAW_FRAMEBUFFER
:
2901 case GL_FRAMEBUFFER
:
2902 fb
= ctx
->WinSysDrawBuffer
;
2904 case GL_READ_FRAMEBUFFER
:
2905 fb
= ctx
->WinSysReadBuffer
;
2908 _mesa_error(ctx
, GL_INVALID_ENUM
,
2909 "glCheckNamedFramebufferStatus(invalid target %s)",
2910 _mesa_enum_to_string(target
));
2915 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
2916 "glCheckNamedFramebufferStatus");
2921 return _mesa_check_framebuffer_status(ctx
, fb
);
2926 * Replicate the src attachment point. Used by framebuffer_texture() when
2927 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2928 * GL_STENCIL_ATTACHMENT.
2931 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2932 gl_buffer_index dst
,
2933 gl_buffer_index src
)
2935 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2936 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2938 assert(src_att
->Texture
!= NULL
);
2939 assert(src_att
->Renderbuffer
!= NULL
);
2941 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2942 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2943 dst_att
->Type
= src_att
->Type
;
2944 dst_att
->Complete
= src_att
->Complete
;
2945 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2946 dst_att
->CubeMapFace
= src_att
->CubeMapFace
;
2947 dst_att
->Zoffset
= src_att
->Zoffset
;
2948 dst_att
->Layered
= src_att
->Layered
;
2952 static struct gl_texture_object
*
2953 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
)
2958 return _mesa_lookup_texture(ctx
, texture
);
2963 * Common code called by gl*FramebufferTexture*() to retrieve the correct
2964 * texture object pointer.
2966 * \param texObj where the pointer to the texture object is returned. Note
2967 * that a successful call may return texObj = NULL.
2969 * \return true if no errors, false if errors
2972 get_texture_for_framebuffer_err(struct gl_context
*ctx
, GLuint texture
,
2973 bool layered
, const char *caller
,
2974 struct gl_texture_object
**texObj
)
2976 *texObj
= NULL
; /* This will get returned if texture = 0. */
2981 *texObj
= _mesa_lookup_texture(ctx
, texture
);
2982 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
2983 /* Can't render to a non-existent texture object.
2985 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
2986 * Managing Framebuffer Objects specifies a different error
2987 * depending upon the calling function (PDF pages 325-328).
2988 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
2989 * value, while the other commands throw invalid operation (where
2990 * layered = GL_FALSE).
2992 const GLenum error
= layered
? GL_INVALID_VALUE
:
2993 GL_INVALID_OPERATION
;
2994 _mesa_error(ctx
, error
,
2995 "%s(non-existent texture %u)", caller
, texture
);
3004 * Common code called by gl*FramebufferTexture() to verify the texture target
3005 * and decide whether or not the attachment should truly be considered
3008 * \param layered true if attachment should be considered layered, false if
3011 * \return true if no errors, false if errors
3014 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
3015 const char *caller
, GLboolean
*layered
)
3021 case GL_TEXTURE_1D_ARRAY_EXT
:
3022 case GL_TEXTURE_2D_ARRAY_EXT
:
3023 case GL_TEXTURE_CUBE_MAP
:
3024 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3025 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3029 case GL_TEXTURE_RECTANGLE
:
3030 case GL_TEXTURE_2D_MULTISAMPLE
:
3031 /* These texture types are valid to pass to
3032 * glFramebufferTexture(), but since they aren't layered, it
3033 * is equivalent to calling glFramebufferTexture{1D,2D}().
3035 *layered
= GL_FALSE
;
3039 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3040 "%s(invalid texture target %s)", caller
,
3041 _mesa_enum_to_string(target
));
3047 * Common code called by gl*FramebufferTextureLayer() to verify the texture
3050 * \return true if no errors, false if errors
3053 check_texture_target(struct gl_context
*ctx
, GLenum target
,
3056 /* We're being called by glFramebufferTextureLayer().
3057 * The only legal texture types for that function are 3D,
3058 * cube-map, and 1D/2D/cube-map array textures.
3060 * We don't need to check for GL_ARB_texture_cube_map_array because the
3061 * application wouldn't have been able to create a texture with a
3062 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
3066 case GL_TEXTURE_1D_ARRAY
:
3067 case GL_TEXTURE_2D_ARRAY
:
3068 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3069 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3071 case GL_TEXTURE_CUBE_MAP
:
3072 /* We don't need to check the extension (GL_ARB_direct_state_access) or
3073 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
3074 * enabled in core profile. This can be called from
3075 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
3076 * so we do have to check the profile.
3078 return ctx
->API
== API_OPENGL_CORE
;
3081 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3082 "%s(invalid texture target %s)", caller
,
3083 _mesa_enum_to_string(target
));
3089 * Common code called by glFramebufferTexture*D() to verify the texture
3092 * \return true if no errors, false if errors
3095 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
3096 GLenum textarget
, const char *caller
)
3100 switch (textarget
) {
3104 case GL_TEXTURE_1D_ARRAY
:
3105 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3110 case GL_TEXTURE_2D_ARRAY
:
3111 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3112 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3114 case GL_TEXTURE_2D_MULTISAMPLE
:
3115 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3117 !ctx
->Extensions
.ARB_texture_multisample
||
3118 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3120 case GL_TEXTURE_RECTANGLE
:
3121 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3122 !ctx
->Extensions
.NV_texture_rectangle
;
3124 case GL_TEXTURE_CUBE_MAP
:
3125 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3128 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3129 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3130 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3131 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3132 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3133 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3134 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3140 _mesa_error(ctx
, GL_INVALID_ENUM
,
3141 "%s(unknown textarget 0x%x)", caller
, textarget
);
3146 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3147 "%s(invalid textarget %s)",
3148 caller
, _mesa_enum_to_string(textarget
));
3152 /* Make sure textarget is consistent with the texture's type */
3153 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3154 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3157 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3158 "%s(mismatched texture target)", caller
);
3167 * Common code called by gl*FramebufferTextureLayer() and
3168 * glFramebufferTexture3D() to validate the layer.
3170 * \return true if no errors, false if errors
3173 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3176 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3179 * "An INVALID_VALUE error is generated if texture is non-zero
3180 * and layer is negative."
3183 _mesa_error(ctx
, GL_INVALID_VALUE
,
3184 "%s(layer %u < 0)", caller
, layer
);
3188 if (target
== GL_TEXTURE_3D
) {
3189 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3190 if (layer
>= maxSize
) {
3191 _mesa_error(ctx
, GL_INVALID_VALUE
,
3192 "%s(invalid layer %u)", caller
, layer
);
3196 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3197 (target
== GL_TEXTURE_2D_ARRAY
) ||
3198 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3199 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3200 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3201 _mesa_error(ctx
, GL_INVALID_VALUE
,
3202 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3207 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3209 _mesa_error(ctx
, GL_INVALID_VALUE
,
3210 "%s(layer %u >= 6)", caller
, layer
);
3220 * Common code called by all gl*FramebufferTexture*() entry points to verify
3223 * \return true if no errors, false if errors
3226 check_level(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
3227 GLenum target
, GLint level
, const char *caller
)
3229 /* Section 9.2.8 of the OpenGL 4.6 specification says:
3231 * "If texture refers to an immutable-format texture, level must be
3232 * greater than or equal to zero and smaller than the value of
3233 * TEXTURE_VIEW_NUM_LEVELS for texture."
3235 const int max_levels
= texObj
->Immutable
? texObj
->ImmutableLevels
:
3236 _mesa_max_texture_levels(ctx
, target
);
3238 if (level
< 0 || level
>= max_levels
) {
3239 _mesa_error(ctx
, GL_INVALID_VALUE
,
3240 "%s(invalid level %d)", caller
, level
);
3248 struct gl_renderbuffer_attachment
*
3249 _mesa_get_and_validate_attachment(struct gl_context
*ctx
,
3250 struct gl_framebuffer
*fb
,
3251 GLenum attachment
, const char *caller
)
3253 /* The window-system framebuffer object is immutable */
3254 if (_mesa_is_winsys_fbo(fb
)) {
3255 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3260 /* Not a hash lookup, so we can afford to get the attachment here. */
3261 bool is_color_attachment
;
3262 struct gl_renderbuffer_attachment
*att
=
3263 get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3265 if (is_color_attachment
) {
3266 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3267 "%s(invalid color attachment %s)", caller
,
3268 _mesa_enum_to_string(attachment
));
3270 _mesa_error(ctx
, GL_INVALID_ENUM
,
3271 "%s(invalid attachment %s)", caller
,
3272 _mesa_enum_to_string(attachment
));
3282 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3284 struct gl_renderbuffer_attachment
*att
,
3285 struct gl_texture_object
*texObj
, GLenum textarget
,
3286 GLint level
, GLuint layer
, GLboolean layered
)
3288 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3290 mtx_lock(&fb
->Mutex
);
3292 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3293 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3294 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3295 _mesa_tex_target_to_face(textarget
) ==
3296 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3297 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3298 /* The texture object is already attached to the stencil attachment
3299 * point. Don't create a new renderbuffer; just reuse the stencil
3300 * attachment's. This is required to prevent a GL error in
3301 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3303 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3305 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3306 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3307 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3308 _mesa_tex_target_to_face(textarget
) ==
3309 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3310 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3311 /* As above, but with depth and stencil transposed. */
3312 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3315 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3316 level
, layer
, layered
);
3318 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3319 /* Above we created a new renderbuffer and attached it to the
3320 * depth attachment point. Now attach it to the stencil attachment
3323 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3324 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3329 /* Set the render-to-texture flag. We'll check this flag in
3330 * glTexImage() and friends to determine if we need to revalidate
3331 * any FBOs that might be rendering into this texture.
3332 * This flag never gets cleared since it's non-trivial to determine
3333 * when all FBOs might be done rendering to this texture. That's OK
3334 * though since it's uncommon to render to a texture then repeatedly
3335 * call glTexImage() to change images in the texture.
3337 texObj
->_RenderToTexture
= GL_TRUE
;
3340 remove_attachment(ctx
, att
);
3341 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3342 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3343 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3347 invalidate_framebuffer(fb
);
3349 mtx_unlock(&fb
->Mutex
);
3354 framebuffer_texture_with_dims_no_error(GLenum target
, GLenum attachment
,
3355 GLenum textarget
, GLuint texture
,
3356 GLint level
, GLint layer
)
3358 GET_CURRENT_CONTEXT(ctx
);
3360 /* Get the framebuffer object */
3361 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3363 /* Get the texture object */
3364 struct gl_texture_object
*texObj
=
3365 get_texture_for_framebuffer(ctx
, texture
);
3367 struct gl_renderbuffer_attachment
*att
=
3368 get_attachment(ctx
, fb
, attachment
, NULL
);
3370 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3371 level
, layer
, GL_FALSE
);
3376 framebuffer_texture_with_dims(int dims
, GLenum target
,
3377 GLenum attachment
, GLenum textarget
,
3378 GLuint texture
, GLint level
, GLint layer
,
3381 GET_CURRENT_CONTEXT(ctx
);
3382 struct gl_framebuffer
*fb
;
3383 struct gl_texture_object
*texObj
;
3385 /* Get the framebuffer object */
3386 fb
= get_framebuffer_target(ctx
, target
);
3388 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3389 _mesa_enum_to_string(target
));
3393 /* Get the texture object */
3394 if (!get_texture_for_framebuffer_err(ctx
, texture
, false, caller
, &texObj
))
3398 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3401 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3404 if (!check_level(ctx
, texObj
, textarget
, level
, caller
))
3408 struct gl_renderbuffer_attachment
*att
=
3409 _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, caller
);
3413 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3414 level
, layer
, GL_FALSE
);
3419 _mesa_FramebufferTexture1D_no_error(GLenum target
, GLenum attachment
,
3420 GLenum textarget
, GLuint texture
,
3423 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3429 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3430 GLenum textarget
, GLuint texture
, GLint level
)
3432 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3433 level
, 0, "glFramebufferTexture1D");
3438 _mesa_FramebufferTexture2D_no_error(GLenum target
, GLenum attachment
,
3439 GLenum textarget
, GLuint texture
,
3442 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3448 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3449 GLenum textarget
, GLuint texture
, GLint level
)
3451 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3452 level
, 0, "glFramebufferTexture2D");
3457 _mesa_FramebufferTexture3D_no_error(GLenum target
, GLenum attachment
,
3458 GLenum textarget
, GLuint texture
,
3459 GLint level
, GLint layer
)
3461 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3462 texture
, level
, layer
);
3467 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3468 GLenum textarget
, GLuint texture
,
3469 GLint level
, GLint layer
)
3471 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3472 level
, layer
, "glFramebufferTexture3D");
3476 static ALWAYS_INLINE
void
3477 frame_buffer_texture(GLuint framebuffer
, GLenum target
,
3478 GLenum attachment
, GLuint texture
,
3479 GLint level
, GLint layer
, const char *func
,
3480 bool dsa
, bool no_error
, bool check_layered
)
3482 GET_CURRENT_CONTEXT(ctx
);
3483 GLboolean layered
= GL_FALSE
;
3485 if (!no_error
&& check_layered
) {
3486 if (!_mesa_has_geometry_shaders(ctx
)) {
3487 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3488 "unsupported function (%s) called", func
);
3493 /* Get the framebuffer object */
3494 struct gl_framebuffer
*fb
;
3497 fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3499 fb
= get_framebuffer_target(ctx
, target
);
3503 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3507 fb
= get_framebuffer_target(ctx
, target
);
3509 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)",
3510 func
, _mesa_enum_to_string(target
));
3516 /* Get the texture object and framebuffer attachment*/
3517 struct gl_renderbuffer_attachment
*att
;
3518 struct gl_texture_object
*texObj
;
3520 texObj
= get_texture_for_framebuffer(ctx
, texture
);
3521 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
3523 if (!get_texture_for_framebuffer_err(ctx
, texture
, check_layered
, func
,
3527 att
= _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, func
);
3532 GLenum textarget
= 0;
3534 if (check_layered
) {
3535 /* We do this regardless of no_error because this sets layered */
3536 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3542 if (!check_layered
) {
3543 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3546 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3550 if (!check_level(ctx
, texObj
, texObj
->Target
, level
, func
))
3554 if (!check_layered
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3555 assert(layer
>= 0 && layer
< 6);
3556 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3561 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3562 level
, layer
, layered
);
3566 _mesa_FramebufferTextureLayer_no_error(GLenum target
, GLenum attachment
,
3567 GLuint texture
, GLint level
,
3570 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3571 "glFramebufferTextureLayer", false, true, false);
3576 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3577 GLuint texture
, GLint level
, GLint layer
)
3579 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3580 "glFramebufferTextureLayer", false, false, false);
3585 _mesa_NamedFramebufferTextureLayer_no_error(GLuint framebuffer
,
3587 GLuint texture
, GLint level
,
3590 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3591 "glNamedFramebufferTextureLayer", true, true, false);
3596 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3597 GLuint texture
, GLint level
, GLint layer
)
3599 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3600 "glNamedFramebufferTextureLayer", true, false, false);
3605 _mesa_FramebufferTexture_no_error(GLenum target
, GLenum attachment
,
3606 GLuint texture
, GLint level
)
3608 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3609 "glFramebufferTexture", false, true, true);
3614 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3615 GLuint texture
, GLint level
)
3617 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3618 "glFramebufferTexture", false, false, true);
3622 _mesa_NamedFramebufferTexture_no_error(GLuint framebuffer
, GLenum attachment
,
3623 GLuint texture
, GLint level
)
3625 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3626 "glNamedFramebufferTexture", true, true, true);
3631 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3632 GLuint texture
, GLint level
)
3634 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3635 "glNamedFramebufferTexture", true, false, true);
3640 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3641 struct gl_framebuffer
*fb
,
3643 struct gl_renderbuffer
*rb
)
3645 assert(!_mesa_is_winsys_fbo(fb
));
3647 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3649 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3650 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3652 /* Some subsequent GL commands may depend on the framebuffer's visual
3653 * after the binding is updated. Update visual info now.
3655 _mesa_update_framebuffer_visual(ctx
, fb
);
3658 static ALWAYS_INLINE
void
3659 framebuffer_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3660 GLenum attachment
, GLenum renderbuffertarget
,
3661 GLuint renderbuffer
, const char *func
, bool no_error
)
3663 struct gl_renderbuffer_attachment
*att
;
3664 struct gl_renderbuffer
*rb
;
3665 bool is_color_attachment
;
3667 if (!no_error
&& renderbuffertarget
!= GL_RENDERBUFFER
) {
3668 _mesa_error(ctx
, GL_INVALID_ENUM
,
3669 "%s(renderbuffertarget is not GL_RENDERBUFFER)", func
);
3675 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
, func
);
3679 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
3682 /* remove renderbuffer attachment */
3687 if (_mesa_is_winsys_fbo(fb
)) {
3688 /* Can't attach new renderbuffers to a window system framebuffer */
3689 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3690 "%s(window-system framebuffer)", func
);
3694 att
= get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3697 * From OpenGL 4.5 spec, section 9.2.7 "Attaching Renderbuffer Images
3698 * to a Framebuffer":
3700 * "An INVALID_OPERATION error is generated if attachment is
3701 * COLOR_- ATTACHMENTm where m is greater than or equal to the
3702 * value of MAX_COLOR_- ATTACHMENTS ."
3704 * If we are at this point, is because the attachment is not valid, so
3705 * if is_color_attachment is true, is because of the previous reason.
3707 if (is_color_attachment
) {
3708 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3709 "%s(invalid color attachment %s)", func
,
3710 _mesa_enum_to_string(attachment
));
3712 _mesa_error(ctx
, GL_INVALID_ENUM
,
3713 "%s(invalid attachment %s)", func
,
3714 _mesa_enum_to_string(attachment
));
3720 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3721 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3722 /* make sure the renderbuffer is a depth/stencil format */
3723 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3724 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3725 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3726 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3732 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3736 framebuffer_renderbuffer_error(struct gl_context
*ctx
,
3737 struct gl_framebuffer
*fb
, GLenum attachment
,
3738 GLenum renderbuffertarget
,
3739 GLuint renderbuffer
, const char *func
)
3741 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3742 renderbuffer
, func
, false);
3746 framebuffer_renderbuffer_no_error(struct gl_context
*ctx
,
3747 struct gl_framebuffer
*fb
, GLenum attachment
,
3748 GLenum renderbuffertarget
,
3749 GLuint renderbuffer
, const char *func
)
3751 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3752 renderbuffer
, func
, true);
3756 _mesa_FramebufferRenderbuffer_no_error(GLenum target
, GLenum attachment
,
3757 GLenum renderbuffertarget
,
3758 GLuint renderbuffer
)
3760 GET_CURRENT_CONTEXT(ctx
);
3762 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3763 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3764 renderbuffer
, "glFramebufferRenderbuffer");
3768 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3769 GLenum renderbuffertarget
,
3770 GLuint renderbuffer
)
3772 struct gl_framebuffer
*fb
;
3773 GET_CURRENT_CONTEXT(ctx
);
3775 fb
= get_framebuffer_target(ctx
, target
);
3777 _mesa_error(ctx
, GL_INVALID_ENUM
,
3778 "glFramebufferRenderbuffer(invalid target %s)",
3779 _mesa_enum_to_string(target
));
3783 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
3784 renderbuffer
, "glFramebufferRenderbuffer");
3788 _mesa_NamedFramebufferRenderbuffer_no_error(GLuint framebuffer
,
3790 GLenum renderbuffertarget
,
3791 GLuint renderbuffer
)
3793 GET_CURRENT_CONTEXT(ctx
);
3795 struct gl_framebuffer
*fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3796 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3798 "glNamedFramebufferRenderbuffer");
3802 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
3803 GLenum renderbuffertarget
,
3804 GLuint renderbuffer
)
3806 struct gl_framebuffer
*fb
;
3807 GET_CURRENT_CONTEXT(ctx
);
3809 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3810 "glNamedFramebufferRenderbuffer");
3814 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
3816 "glNamedFramebufferRenderbuffer");
3821 get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
3822 struct gl_framebuffer
*buffer
,
3823 GLenum attachment
, GLenum pname
,
3824 GLint
*params
, const char *caller
)
3826 const struct gl_renderbuffer_attachment
*att
;
3827 bool is_color_attachment
= false;
3830 /* The error code for an attachment type of GL_NONE differs between APIs.
3832 * From the ES 2.0.25 specification, page 127:
3833 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3834 * querying any other pname will generate INVALID_ENUM."
3836 * From the OpenGL 3.0 specification, page 337, or identically,
3837 * the OpenGL ES 3.0.4 specification, page 240:
3839 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
3840 * framebuffer is bound to target. In this case querying pname
3841 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
3842 * queries will generate an INVALID_OPERATION error."
3844 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
3845 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
3847 if (_mesa_is_winsys_fbo(buffer
)) {
3848 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
3851 * "If the framebuffer currently bound to target is zero, then
3852 * INVALID_OPERATION is generated."
3854 * The EXT_framebuffer_object spec has the same wording, and the
3855 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
3858 if ((!_mesa_is_desktop_gl(ctx
) ||
3859 !ctx
->Extensions
.ARB_framebuffer_object
)
3860 && !_mesa_is_gles3(ctx
)) {
3861 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3862 "%s(window-system framebuffer)", caller
);
3866 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
3867 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
3868 _mesa_error(ctx
, GL_INVALID_ENUM
,
3869 "%s(invalid attachment %s)", caller
,
3870 _mesa_enum_to_string(attachment
));
3874 /* The specs are not clear about how to handle
3875 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
3876 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
3879 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
3880 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
3882 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
3883 _mesa_error(ctx
, GL_INVALID_ENUM
,
3884 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
3885 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
3886 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
3890 /* the default / window-system FBO */
3891 att
= get_fb0_attachment(ctx
, buffer
, attachment
);
3894 /* user-created framebuffer FBO */
3895 att
= get_attachment(ctx
, buffer
, attachment
, &is_color_attachment
);
3900 * From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries":
3902 * "An INVALID_OPERATION error is generated if a framebuffer object
3903 * is bound to target and attachment is COLOR_ATTACHMENTm where m is
3904 * greater than or equal to the value of MAX_COLOR_ATTACHMENTS."
3906 * If we are at this point, is because the attachment is not valid, so
3907 * if is_color_attachment is true, is because of the previous reason.
3909 if (is_color_attachment
) {
3910 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid color attachment %s)",
3911 caller
, _mesa_enum_to_string(attachment
));
3913 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
3914 _mesa_enum_to_string(attachment
));
3919 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3920 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
3921 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
3922 /* This behavior is first specified in OpenGL 4.4 specification.
3924 * From the OpenGL 4.4 spec page 275:
3925 * "This query cannot be performed for a combined depth+stencil
3926 * attachment, since it does not have a single format."
3928 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3929 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
3930 " is invalid for depth+stencil attachment)", caller
);
3933 /* the depth and stencil attachments must point to the same buffer */
3934 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
, NULL
);
3935 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
, NULL
);
3936 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
3937 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3938 "%s(DEPTH/STENCIL attachments differ)", caller
);
3943 /* No need to flush here */
3946 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
3947 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
3949 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
3950 * either no framebuffer is bound to target; or the default framebuffer
3951 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
3952 * stencil bits, respectively, is zero."
3954 * Note that we don't need explicit checks on DEPTH and STENCIL, because
3955 * on the case the spec is pointing, att->Type is already NONE, so we
3956 * just need to check att->Type.
3958 *params
= (_mesa_is_winsys_fbo(buffer
) && att
->Type
!= GL_NONE
) ?
3959 GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
3961 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
3962 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
3963 *params
= att
->Renderbuffer
->Name
;
3965 else if (att
->Type
== GL_TEXTURE
) {
3966 *params
= att
->Texture
->Name
;
3969 assert(att
->Type
== GL_NONE
);
3970 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
3973 goto invalid_pname_enum
;
3977 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
3978 if (att
->Type
== GL_TEXTURE
) {
3979 *params
= att
->TextureLevel
;
3981 else if (att
->Type
== GL_NONE
) {
3982 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
3983 _mesa_enum_to_string(pname
));
3986 goto invalid_pname_enum
;
3989 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
3990 if (att
->Type
== GL_TEXTURE
) {
3991 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
3992 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
3998 else if (att
->Type
== GL_NONE
) {
3999 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4000 _mesa_enum_to_string(pname
));
4003 goto invalid_pname_enum
;
4006 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
4007 if (ctx
->API
== API_OPENGLES
) {
4008 goto invalid_pname_enum
;
4009 } else if (att
->Type
== GL_NONE
) {
4010 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4011 _mesa_enum_to_string(pname
));
4012 } else if (att
->Type
== GL_TEXTURE
) {
4013 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
4014 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
4015 *params
= att
->Zoffset
;
4022 goto invalid_pname_enum
;
4025 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
4026 if ((!_mesa_is_desktop_gl(ctx
) ||
4027 !ctx
->Extensions
.ARB_framebuffer_object
)
4028 && !_mesa_is_gles3(ctx
)) {
4029 goto invalid_pname_enum
;
4031 else if (att
->Type
== GL_NONE
) {
4032 if (_mesa_is_winsys_fbo(buffer
) &&
4033 (attachment
== GL_DEPTH
|| attachment
== GL_STENCIL
)) {
4034 *params
= GL_LINEAR
;
4036 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4037 _mesa_enum_to_string(pname
));
4041 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
4043 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
4046 /* According to ARB_framebuffer_sRGB, we should return LINEAR
4047 * if the sRGB conversion is unsupported. */
4048 *params
= GL_LINEAR
;
4052 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
4053 if ((ctx
->API
!= API_OPENGL_COMPAT
||
4054 !ctx
->Extensions
.ARB_framebuffer_object
)
4055 && ctx
->API
!= API_OPENGL_CORE
4056 && !_mesa_is_gles3(ctx
)) {
4057 goto invalid_pname_enum
;
4059 else if (att
->Type
== GL_NONE
) {
4060 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4061 _mesa_enum_to_string(pname
));
4064 mesa_format format
= att
->Renderbuffer
->Format
;
4066 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
4069 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
4070 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
4071 * generate an INVALID_OPERATION error.
4073 if (_mesa_is_gles3(ctx
) &&
4074 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
4075 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4077 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
4078 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
4082 if (format
== MESA_FORMAT_S_UINT8
) {
4086 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
4087 /* depends on the attachment parameter */
4088 if (attachment
== GL_STENCIL_ATTACHMENT
) {
4096 *params
= _mesa_get_format_datatype(format
);
4100 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
4101 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
4102 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
4103 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
4104 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
4105 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
4106 if ((!_mesa_is_desktop_gl(ctx
) ||
4107 !ctx
->Extensions
.ARB_framebuffer_object
)
4108 && !_mesa_is_gles3(ctx
)) {
4109 goto invalid_pname_enum
;
4111 else if (att
->Texture
) {
4112 const struct gl_texture_image
*texImage
=
4113 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
4116 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
4117 texImage
->TexFormat
);
4123 else if (att
->Renderbuffer
) {
4124 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
4125 att
->Renderbuffer
->Format
);
4128 assert(att
->Type
== GL_NONE
);
4129 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4130 _mesa_enum_to_string(pname
));
4133 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
4134 if (!_mesa_has_geometry_shaders(ctx
)) {
4135 goto invalid_pname_enum
;
4136 } else if (att
->Type
== GL_TEXTURE
) {
4137 *params
= att
->Layered
;
4138 } else if (att
->Type
== GL_NONE
) {
4139 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4140 _mesa_enum_to_string(pname
));
4142 goto invalid_pname_enum
;
4146 goto invalid_pname_enum
;
4152 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
4153 _mesa_enum_to_string(pname
));
4159 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
4160 GLenum pname
, GLint
*params
)
4162 GET_CURRENT_CONTEXT(ctx
);
4163 struct gl_framebuffer
*buffer
;
4165 buffer
= get_framebuffer_target(ctx
, target
);
4167 _mesa_error(ctx
, GL_INVALID_ENUM
,
4168 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
4169 _mesa_enum_to_string(target
));
4173 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4175 "glGetFramebufferAttachmentParameteriv");
4180 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
4182 GLenum pname
, GLint
*params
)
4184 GET_CURRENT_CONTEXT(ctx
);
4185 struct gl_framebuffer
*buffer
;
4188 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4189 "glGetNamedFramebufferAttachmentParameteriv");
4195 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
4196 * 4.5 core spec (30.10.2014, PDF page 314):
4197 * "If framebuffer is zero, then the default draw framebuffer is
4200 buffer
= ctx
->WinSysDrawBuffer
;
4203 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4205 "glGetNamedFramebufferAttachmentParameteriv");
4210 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
4213 GET_CURRENT_CONTEXT(ctx
);
4214 struct gl_framebuffer
*fb
= NULL
;
4216 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4217 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4218 "glNamedFramebufferParameteri("
4219 "ARB_framebuffer_no_attachments not implemented)");
4223 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4224 "glNamedFramebufferParameteri");
4227 framebuffer_parameteri(ctx
, fb
, pname
, param
,
4228 "glNamedFramebufferParameteriv");
4234 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
4237 GET_CURRENT_CONTEXT(ctx
);
4238 struct gl_framebuffer
*fb
;
4240 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4242 "glNamedFramebufferParameteriv("
4243 "ARB_framebuffer_no_attachments not implemented)");
4248 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4249 "glGetNamedFramebufferParameteriv");
4251 fb
= ctx
->WinSysDrawBuffer
;
4255 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4256 "glGetNamedFramebufferParameteriv");
4262 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4263 struct gl_framebuffer
*fb
,
4264 GLsizei numAttachments
,
4265 const GLenum
*attachments
, GLint x
, GLint y
,
4266 GLsizei width
, GLsizei height
, const char *name
)
4270 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4271 * Spec (2.2.2015, PDF page 522) says:
4272 * "An INVALID_VALUE error is generated if numAttachments, width, or
4273 * height is negative."
4275 if (numAttachments
< 0) {
4276 _mesa_error(ctx
, GL_INVALID_VALUE
,
4277 "%s(numAttachments < 0)", name
);
4282 _mesa_error(ctx
, GL_INVALID_VALUE
,
4283 "%s(width < 0)", name
);
4288 _mesa_error(ctx
, GL_INVALID_VALUE
,
4289 "%s(height < 0)", name
);
4293 /* The GL_ARB_invalidate_subdata spec says:
4295 * "If an attachment is specified that does not exist in the
4296 * framebuffer bound to <target>, it is ignored."
4300 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4301 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4302 * INVALID_OPERATION is generated."
4304 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4305 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4306 * set of retrictions).
4308 for (i
= 0; i
< numAttachments
; i
++) {
4309 if (_mesa_is_winsys_fbo(fb
)) {
4310 switch (attachments
[i
]) {
4316 /* Accumulation buffers and auxilary buffers were removed in
4317 * OpenGL 3.1, and they never existed in OpenGL ES.
4319 if (ctx
->API
!= API_OPENGL_COMPAT
)
4329 case GL_FRONT_RIGHT
:
4330 if (!_mesa_is_desktop_gl(ctx
))
4337 switch (attachments
[i
]) {
4338 case GL_DEPTH_ATTACHMENT
:
4339 case GL_STENCIL_ATTACHMENT
:
4341 case GL_DEPTH_STENCIL_ATTACHMENT
:
4342 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4343 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4344 * extension does not make this attachment point valid on ES 2.0.
4346 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4349 case GL_COLOR_ATTACHMENT0
:
4350 case GL_COLOR_ATTACHMENT1
:
4351 case GL_COLOR_ATTACHMENT2
:
4352 case GL_COLOR_ATTACHMENT3
:
4353 case GL_COLOR_ATTACHMENT4
:
4354 case GL_COLOR_ATTACHMENT5
:
4355 case GL_COLOR_ATTACHMENT6
:
4356 case GL_COLOR_ATTACHMENT7
:
4357 case GL_COLOR_ATTACHMENT8
:
4358 case GL_COLOR_ATTACHMENT9
:
4359 case GL_COLOR_ATTACHMENT10
:
4360 case GL_COLOR_ATTACHMENT11
:
4361 case GL_COLOR_ATTACHMENT12
:
4362 case GL_COLOR_ATTACHMENT13
:
4363 case GL_COLOR_ATTACHMENT14
:
4364 case GL_COLOR_ATTACHMENT15
: {
4365 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4366 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4367 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4368 "%s(attachment >= max. color attachments)", name
);
4379 /* We don't actually do anything for this yet. Just return after
4380 * validating the parameters and generating the required errors.
4385 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4386 _mesa_enum_to_string(attachments
[i
]));
4392 _mesa_InvalidateSubFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4393 const GLenum
*attachments
, GLint x
,
4394 GLint y
, GLsizei width
, GLsizei height
)
4401 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4402 const GLenum
*attachments
, GLint x
, GLint y
,
4403 GLsizei width
, GLsizei height
)
4405 struct gl_framebuffer
*fb
;
4406 GET_CURRENT_CONTEXT(ctx
);
4408 fb
= get_framebuffer_target(ctx
, target
);
4410 _mesa_error(ctx
, GL_INVALID_ENUM
,
4411 "glInvalidateSubFramebuffer(invalid target %s)",
4412 _mesa_enum_to_string(target
));
4416 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4417 x
, y
, width
, height
,
4418 "glInvalidateSubFramebuffer");
4423 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4424 GLsizei numAttachments
,
4425 const GLenum
*attachments
,
4427 GLsizei width
, GLsizei height
)
4429 struct gl_framebuffer
*fb
;
4430 GET_CURRENT_CONTEXT(ctx
);
4432 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4433 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4434 * default draw framebuffer is affected."
4437 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4438 "glInvalidateNamedFramebufferSubData");
4443 fb
= ctx
->WinSysDrawBuffer
;
4445 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4446 x
, y
, width
, height
,
4447 "glInvalidateNamedFramebufferSubData");
4452 _mesa_InvalidateFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4453 const GLenum
*attachments
)
4460 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4461 const GLenum
*attachments
)
4463 struct gl_framebuffer
*fb
;
4464 GET_CURRENT_CONTEXT(ctx
);
4466 fb
= get_framebuffer_target(ctx
, target
);
4468 _mesa_error(ctx
, GL_INVALID_ENUM
,
4469 "glInvalidateFramebuffer(invalid target %s)",
4470 _mesa_enum_to_string(target
));
4474 /* The GL_ARB_invalidate_subdata spec says:
4478 * void InvalidateFramebuffer(enum target,
4479 * sizei numAttachments,
4480 * const enum *attachments);
4482 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4483 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4484 * <MAX_VIEWPORT_DIMS[1]> respectively."
4486 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4488 ctx
->Const
.MaxViewportWidth
,
4489 ctx
->Const
.MaxViewportHeight
,
4490 "glInvalidateFramebuffer");
4495 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4496 GLsizei numAttachments
,
4497 const GLenum
*attachments
)
4499 struct gl_framebuffer
*fb
;
4500 GET_CURRENT_CONTEXT(ctx
);
4502 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4503 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4504 * default draw framebuffer is affected."
4507 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4508 "glInvalidateNamedFramebufferData");
4513 fb
= ctx
->WinSysDrawBuffer
;
4515 /* The GL_ARB_invalidate_subdata spec says:
4519 * void InvalidateFramebuffer(enum target,
4520 * sizei numAttachments,
4521 * const enum *attachments);
4523 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4524 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4525 * <MAX_VIEWPORT_DIMS[1]> respectively."
4527 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4529 ctx
->Const
.MaxViewportWidth
,
4530 ctx
->Const
.MaxViewportHeight
,
4531 "glInvalidateNamedFramebufferData");
4536 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4537 const GLenum
*attachments
)
4539 struct gl_framebuffer
*fb
;
4542 GET_CURRENT_CONTEXT(ctx
);
4544 fb
= get_framebuffer_target(ctx
, target
);
4546 _mesa_error(ctx
, GL_INVALID_ENUM
,
4547 "glDiscardFramebufferEXT(target %s)",
4548 _mesa_enum_to_string(target
));
4552 if (numAttachments
< 0) {
4553 _mesa_error(ctx
, GL_INVALID_VALUE
,
4554 "glDiscardFramebufferEXT(numAttachments < 0)");
4558 for (i
= 0; i
< numAttachments
; i
++) {
4559 switch (attachments
[i
]) {
4563 if (_mesa_is_user_fbo(fb
))
4566 case GL_COLOR_ATTACHMENT0
:
4567 case GL_DEPTH_ATTACHMENT
:
4568 case GL_STENCIL_ATTACHMENT
:
4569 if (_mesa_is_winsys_fbo(fb
))
4577 if (ctx
->Driver
.DiscardFramebuffer
)
4578 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4583 _mesa_error(ctx
, GL_INVALID_ENUM
,
4584 "glDiscardFramebufferEXT(attachment %s)",
4585 _mesa_enum_to_string(attachments
[i
]));