2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 * GL_EXT/ARB_framebuffer_object extensions
38 #include "debug_output.h"
42 #include "framebuffer.h"
43 #include "glformats.h"
46 #include "multisample.h"
48 #include "renderbuffer.h"
57 * None of the GL_EXT_framebuffer_object functions are compiled into
64 * When glGenRender/FramebuffersEXT() is called we insert pointers to
65 * these placeholder objects into the hash table.
66 * Later, when the object ID is first bound, we replace the placeholder
67 * with the real frame/renderbuffer.
69 static struct gl_framebuffer DummyFramebuffer
;
70 static struct gl_renderbuffer DummyRenderbuffer
;
72 /* We bind this framebuffer when applications pass a NULL
73 * drawable/surface in make current. */
74 static struct gl_framebuffer IncompleteFramebuffer
;
78 delete_dummy_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
84 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
91 _mesa_init_fbobjects(struct gl_context
*ctx
)
93 simple_mtx_init(&DummyFramebuffer
.Mutex
, mtx_plain
);
94 simple_mtx_init(&DummyRenderbuffer
.Mutex
, mtx_plain
);
95 simple_mtx_init(&IncompleteFramebuffer
.Mutex
, mtx_plain
);
96 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
97 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
98 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
101 struct gl_framebuffer
*
102 _mesa_get_incomplete_framebuffer(void)
104 return &IncompleteFramebuffer
;
108 * Helper routine for getting a gl_renderbuffer.
110 struct gl_renderbuffer
*
111 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
113 struct gl_renderbuffer
*rb
;
118 rb
= (struct gl_renderbuffer
*)
119 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
125 * A convenience function for direct state access that throws
126 * GL_INVALID_OPERATION if the renderbuffer doesn't exist.
128 struct gl_renderbuffer
*
129 _mesa_lookup_renderbuffer_err(struct gl_context
*ctx
, GLuint id
,
132 struct gl_renderbuffer
*rb
;
134 rb
= _mesa_lookup_renderbuffer(ctx
, id
);
135 if (!rb
|| rb
== &DummyRenderbuffer
) {
136 _mesa_error(ctx
, GL_INVALID_OPERATION
,
137 "%s(non-existent renderbuffer %u)", func
, id
);
146 * Helper routine for getting a gl_framebuffer.
148 struct gl_framebuffer
*
149 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
151 struct gl_framebuffer
*fb
;
156 fb
= (struct gl_framebuffer
*)
157 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
163 * A convenience function for direct state access that throws
164 * GL_INVALID_OPERATION if the framebuffer doesn't exist.
166 struct gl_framebuffer
*
167 _mesa_lookup_framebuffer_err(struct gl_context
*ctx
, GLuint id
,
170 struct gl_framebuffer
*fb
;
172 fb
= _mesa_lookup_framebuffer(ctx
, id
);
173 if (!fb
|| fb
== &DummyFramebuffer
) {
174 _mesa_error(ctx
, GL_INVALID_OPERATION
,
175 "%s(non-existent framebuffer %u)", func
, id
);
184 * Mark the given framebuffer as invalid. This will force the
185 * test for framebuffer completeness to be done before the framebuffer
189 invalidate_framebuffer(struct gl_framebuffer
*fb
)
191 fb
->_Status
= 0; /* "indeterminate" */
196 * Return the gl_framebuffer object which corresponds to the given
197 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
198 * Check support for GL_EXT_framebuffer_blit to determine if certain
200 * \return gl_framebuffer pointer or NULL if target is illegal
202 static struct gl_framebuffer
*
203 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
205 bool have_fb_blit
= _mesa_is_gles3(ctx
) || _mesa_is_desktop_gl(ctx
);
207 case GL_DRAW_FRAMEBUFFER
:
208 return have_fb_blit
? ctx
->DrawBuffer
: NULL
;
209 case GL_READ_FRAMEBUFFER
:
210 return have_fb_blit
? ctx
->ReadBuffer
: NULL
;
211 case GL_FRAMEBUFFER_EXT
:
212 return ctx
->DrawBuffer
;
220 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
221 * gl_renderbuffer_attachment object.
222 * This function is only used for user-created FB objects, not the
223 * default / window-system FB object.
224 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
225 * the depth buffer attachment point.
226 * Returns if the attachment is a GL_COLOR_ATTACHMENTm_EXT on
227 * is_color_attachment, because several callers would return different errors
228 * if they don't find the attachment.
230 static struct gl_renderbuffer_attachment
*
231 get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
232 GLenum attachment
, bool *is_color_attachment
)
236 assert(_mesa_is_user_fbo(fb
));
238 if (is_color_attachment
)
239 *is_color_attachment
= false;
241 switch (attachment
) {
242 case GL_COLOR_ATTACHMENT0_EXT
:
243 case GL_COLOR_ATTACHMENT1_EXT
:
244 case GL_COLOR_ATTACHMENT2_EXT
:
245 case GL_COLOR_ATTACHMENT3_EXT
:
246 case GL_COLOR_ATTACHMENT4_EXT
:
247 case GL_COLOR_ATTACHMENT5_EXT
:
248 case GL_COLOR_ATTACHMENT6_EXT
:
249 case GL_COLOR_ATTACHMENT7_EXT
:
250 case GL_COLOR_ATTACHMENT8_EXT
:
251 case GL_COLOR_ATTACHMENT9_EXT
:
252 case GL_COLOR_ATTACHMENT10_EXT
:
253 case GL_COLOR_ATTACHMENT11_EXT
:
254 case GL_COLOR_ATTACHMENT12_EXT
:
255 case GL_COLOR_ATTACHMENT13_EXT
:
256 case GL_COLOR_ATTACHMENT14_EXT
:
257 case GL_COLOR_ATTACHMENT15_EXT
:
258 if (is_color_attachment
)
259 *is_color_attachment
= true;
260 /* Only OpenGL ES 1.x forbids color attachments other than
261 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
264 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
265 if (i
>= ctx
->Const
.MaxColorAttachments
266 || (i
> 0 && ctx
->API
== API_OPENGLES
)) {
269 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
270 case GL_DEPTH_STENCIL_ATTACHMENT
:
271 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
274 case GL_DEPTH_ATTACHMENT_EXT
:
275 return &fb
->Attachment
[BUFFER_DEPTH
];
276 case GL_STENCIL_ATTACHMENT_EXT
:
277 return &fb
->Attachment
[BUFFER_STENCIL
];
285 * As above, but only used for getting attachments of the default /
286 * window-system framebuffer (not user-created framebuffer objects).
288 static struct gl_renderbuffer_attachment
*
289 get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
292 assert(_mesa_is_winsys_fbo(fb
));
294 if (_mesa_is_gles3(ctx
)) {
295 assert(attachment
== GL_BACK
||
296 attachment
== GL_DEPTH
||
297 attachment
== GL_STENCIL
);
298 switch (attachment
) {
300 /* Since there is no stereo rendering in ES 3.0, only return the
303 if (ctx
->DrawBuffer
->Visual
.doubleBufferMode
)
304 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
305 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
307 return &fb
->Attachment
[BUFFER_DEPTH
];
309 return &fb
->Attachment
[BUFFER_STENCIL
];
313 switch (attachment
) {
315 /* Front buffers can be allocated on the first use, but
316 * glGetFramebufferAttachmentParameteriv must work even if that
317 * allocation hasn't happened yet. In such case, use the back buffer,
318 * which should be the same.
320 if (fb
->Attachment
[BUFFER_FRONT_LEFT
].Type
== GL_NONE
)
321 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
323 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
326 if (fb
->Attachment
[BUFFER_FRONT_RIGHT
].Type
== GL_NONE
)
327 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
329 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
331 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
333 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
335 /* The ARB_ES3_1_compatibility spec says:
337 * "Since this command can only query a single framebuffer
338 * attachment, BACK is equivalent to BACK_LEFT."
340 if (ctx
->Extensions
.ARB_ES3_1_compatibility
)
341 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
344 if (fb
->Visual
.numAuxBuffers
== 1) {
345 return &fb
->Attachment
[BUFFER_AUX0
];
349 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
351 * "If the default framebuffer is bound to target, then attachment must
352 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
353 * identifying a color buffer; DEPTH, identifying the depth buffer; or
354 * STENCIL, identifying the stencil buffer."
356 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
357 * language. However, revision #33 of the ARB_framebuffer_object spec
360 * "If the default framebuffer is bound to <target>, then <attachment>
361 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
362 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
363 * depth buffer, or the stencil buffer, and <pname> may be
364 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
365 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
367 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
368 * from glext.h, so shipping apps should not use those values.
370 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
371 * support queries of the window system FBO.
374 return &fb
->Attachment
[BUFFER_DEPTH
];
376 return &fb
->Attachment
[BUFFER_STENCIL
];
385 * Remove any texture or renderbuffer attached to the given attachment
386 * point. Update reference counts, etc.
389 remove_attachment(struct gl_context
*ctx
,
390 struct gl_renderbuffer_attachment
*att
)
392 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
394 /* tell driver that we're done rendering to this texture. */
395 if (rb
&& rb
->NeedsFinishRenderTexture
)
396 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
398 if (att
->Type
== GL_TEXTURE
) {
399 assert(att
->Texture
);
400 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
401 assert(!att
->Texture
);
403 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
404 assert(!att
->Texture
);
405 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
406 assert(!att
->Renderbuffer
);
409 att
->Complete
= GL_TRUE
;
413 * Verify a couple error conditions that will lead to an incomplete FBO and
414 * may cause problems for the driver's RenderTexture path.
417 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment
*att
)
419 const struct gl_texture_image
*const texImage
=
420 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
423 texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
426 if ((texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
427 && att
->Zoffset
>= texImage
->Height
)
428 || (texImage
->TexObject
->Target
!= GL_TEXTURE_1D_ARRAY
429 && att
->Zoffset
>= texImage
->Depth
))
436 * Create a renderbuffer which will be set up by the driver to wrap the
437 * texture image slice.
439 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
440 * to share most of their framebuffer rendering code between winsys,
441 * renderbuffer, and texture attachments.
443 * The allocated renderbuffer uses a non-zero Name so that drivers can check
444 * it for determining vertical orientation, but we use ~0 to make it fairly
445 * unambiguous with actual user (non-texture) renderbuffers.
448 _mesa_update_texture_renderbuffer(struct gl_context
*ctx
,
449 struct gl_framebuffer
*fb
,
450 struct gl_renderbuffer_attachment
*att
)
452 struct gl_texture_image
*texImage
;
453 struct gl_renderbuffer
*rb
;
455 texImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
457 rb
= att
->Renderbuffer
;
459 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
461 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
464 att
->Renderbuffer
= rb
;
466 /* This can't get called on a texture renderbuffer, so set it to NULL
467 * for clarity compared to user renderbuffers.
469 rb
->AllocStorage
= NULL
;
471 rb
->NeedsFinishRenderTexture
= ctx
->Driver
.FinishRenderTexture
!= NULL
;
477 rb
->_BaseFormat
= texImage
->_BaseFormat
;
478 rb
->Format
= texImage
->TexFormat
;
479 rb
->InternalFormat
= texImage
->InternalFormat
;
480 rb
->Width
= texImage
->Width2
;
481 rb
->Height
= texImage
->Height2
;
482 rb
->Depth
= texImage
->Depth2
;
483 rb
->NumSamples
= texImage
->NumSamples
;
484 rb
->NumStorageSamples
= texImage
->NumSamples
;
485 rb
->TexImage
= texImage
;
487 if (driver_RenderTexture_is_safe(att
))
488 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
492 * Bind a texture object to an attachment point.
493 * The previous binding, if any, will be removed first.
496 set_texture_attachment(struct gl_context
*ctx
,
497 struct gl_framebuffer
*fb
,
498 struct gl_renderbuffer_attachment
*att
,
499 struct gl_texture_object
*texObj
,
500 GLenum texTarget
, GLuint level
, GLuint layer
,
503 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
505 if (rb
&& rb
->NeedsFinishRenderTexture
)
506 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
508 if (att
->Texture
== texObj
) {
509 /* re-attaching same texture */
510 assert(att
->Type
== GL_TEXTURE
);
514 remove_attachment(ctx
, att
);
515 att
->Type
= GL_TEXTURE
;
516 assert(!att
->Texture
);
517 _mesa_reference_texobj(&att
->Texture
, texObj
);
519 invalidate_framebuffer(fb
);
521 /* always update these fields */
522 att
->TextureLevel
= level
;
523 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
524 att
->Zoffset
= layer
;
525 att
->Layered
= layered
;
526 att
->Complete
= GL_FALSE
;
528 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
533 * Bind a renderbuffer to an attachment point.
534 * The previous binding, if any, will be removed first.
537 set_renderbuffer_attachment(struct gl_context
*ctx
,
538 struct gl_renderbuffer_attachment
*att
,
539 struct gl_renderbuffer
*rb
)
541 /* XXX check if re-doing same attachment, exit early */
542 remove_attachment(ctx
, att
);
543 att
->Type
= GL_RENDERBUFFER_EXT
;
544 att
->Texture
= NULL
; /* just to be safe */
545 att
->Layered
= GL_FALSE
;
546 att
->Complete
= GL_FALSE
;
547 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
552 * Fallback for ctx->Driver.FramebufferRenderbuffer()
553 * Attach a renderbuffer object to a framebuffer object.
556 _mesa_FramebufferRenderbuffer_sw(struct gl_context
*ctx
,
557 struct gl_framebuffer
*fb
,
559 struct gl_renderbuffer
*rb
)
561 struct gl_renderbuffer_attachment
*att
;
563 simple_mtx_lock(&fb
->Mutex
);
565 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
568 set_renderbuffer_attachment(ctx
, att
, rb
);
569 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
570 /* do stencil attachment here (depth already done above) */
571 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
573 set_renderbuffer_attachment(ctx
, att
, rb
);
575 rb
->AttachedAnytime
= GL_TRUE
;
578 remove_attachment(ctx
, att
);
579 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
580 /* detach stencil (depth was detached above) */
581 att
= get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
, NULL
);
583 remove_attachment(ctx
, att
);
587 invalidate_framebuffer(fb
);
589 simple_mtx_unlock(&fb
->Mutex
);
594 * Fallback for ctx->Driver.ValidateFramebuffer()
595 * Check if the renderbuffer's formats are supported by the software
597 * Drivers should probably override this.
600 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
603 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
604 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
606 switch (rb
->_BaseFormat
) {
608 case GL_LUMINANCE_ALPHA
:
613 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
617 switch (rb
->Format
) {
618 /* XXX This list is likely incomplete. */
619 case MESA_FORMAT_R9G9B9E5_FLOAT
:
620 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
623 /* render buffer format is supported by software rendering */
632 * Return true if the framebuffer has a combined depth/stencil
633 * renderbuffer attached.
636 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
638 const struct gl_renderbuffer_attachment
*depth
=
639 &fb
->Attachment
[BUFFER_DEPTH
];
640 const struct gl_renderbuffer_attachment
*stencil
=
641 &fb
->Attachment
[BUFFER_STENCIL
];
643 if (depth
->Type
== stencil
->Type
) {
644 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
645 depth
->Renderbuffer
== stencil
->Renderbuffer
)
648 if (depth
->Type
== GL_TEXTURE
&&
649 depth
->Texture
== stencil
->Texture
)
661 att_incomplete(const char *msg
)
663 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
664 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
673 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
675 static GLuint msg_id
;
677 _mesa_gl_debug(ctx
, &msg_id
,
678 MESA_DEBUG_SOURCE_API
,
679 MESA_DEBUG_TYPE_OTHER
,
680 MESA_DEBUG_SEVERITY_MEDIUM
,
681 "FBO incomplete: %s [%d]\n", msg
, index
);
683 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
684 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
690 * Is the given base format a legal format for a color renderbuffer?
693 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
695 switch (baseFormat
) {
700 case GL_LUMINANCE_ALPHA
:
703 return ctx
->API
== API_OPENGL_COMPAT
&&
704 ctx
->Extensions
.ARB_framebuffer_object
;
707 return ctx
->Extensions
.ARB_texture_rg
;
715 * Is the given base format a legal format for a color renderbuffer?
718 is_format_color_renderable(const struct gl_context
*ctx
, mesa_format format
,
719 GLenum internalFormat
)
721 const GLenum baseFormat
=
722 _mesa_get_format_base_format(format
);
725 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
726 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
730 /* Reject additional cases for GLES */
731 switch (internalFormat
) {
752 if (internalFormat
!= GL_RGB10_A2
&&
753 (format
== MESA_FORMAT_B10G10R10A2_UNORM
||
754 format
== MESA_FORMAT_B10G10R10X2_UNORM
||
755 format
== MESA_FORMAT_R10G10B10A2_UNORM
||
756 format
== MESA_FORMAT_R10G10B10X2_UNORM
)) {
765 * Is the given base format a legal format for a depth/stencil renderbuffer?
768 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
770 switch (baseFormat
) {
771 case GL_DEPTH_COMPONENT
:
772 case GL_DEPTH_STENCIL_EXT
:
781 * Test if an attachment point is complete and update its Complete field.
782 * \param format if GL_COLOR, this is a color attachment point,
783 * if GL_DEPTH, this is a depth component attachment point,
784 * if GL_STENCIL, this is a stencil component attachment point.
787 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
788 struct gl_renderbuffer_attachment
*att
)
790 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
792 /* assume complete */
793 att
->Complete
= GL_TRUE
;
795 /* Look for reasons why the attachment might be incomplete */
796 if (att
->Type
== GL_TEXTURE
) {
797 const struct gl_texture_object
*texObj
= att
->Texture
;
798 const struct gl_texture_image
*texImage
;
802 att_incomplete("no texobj");
803 att
->Complete
= GL_FALSE
;
807 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
809 att_incomplete("no teximage");
810 att
->Complete
= GL_FALSE
;
813 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
814 att_incomplete("teximage width/height=0");
815 att
->Complete
= GL_FALSE
;
819 switch (texObj
->Target
) {
821 if (att
->Zoffset
>= texImage
->Depth
) {
822 att_incomplete("bad z offset");
823 att
->Complete
= GL_FALSE
;
827 case GL_TEXTURE_1D_ARRAY
:
828 if (att
->Zoffset
>= texImage
->Height
) {
829 att_incomplete("bad 1D-array layer");
830 att
->Complete
= GL_FALSE
;
834 case GL_TEXTURE_2D_ARRAY
:
835 if (att
->Zoffset
>= texImage
->Depth
) {
836 att_incomplete("bad 2D-array layer");
837 att
->Complete
= GL_FALSE
;
841 case GL_TEXTURE_CUBE_MAP_ARRAY
:
842 if (att
->Zoffset
>= texImage
->Depth
) {
843 att_incomplete("bad cube-array layer");
844 att
->Complete
= GL_FALSE
;
850 baseFormat
= texImage
->_BaseFormat
;
852 if (format
== GL_COLOR
) {
853 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
854 att_incomplete("bad format");
855 att
->Complete
= GL_FALSE
;
858 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
859 att_incomplete("compressed internalformat");
860 att
->Complete
= GL_FALSE
;
864 /* OES_texture_float allows creation and use of floating point
865 * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow
866 * these textures to be used as a render target, this is done via
867 * GL_EXT_color_buffer(_half)_float with set of new sized types.
869 if (_mesa_is_gles(ctx
) && (texObj
->_IsFloat
|| texObj
->_IsHalfFloat
)) {
870 att_incomplete("bad internal format");
871 att
->Complete
= GL_FALSE
;
875 else if (format
== GL_DEPTH
) {
876 if (baseFormat
== GL_DEPTH_COMPONENT
) {
879 else if (ctx
->Extensions
.ARB_depth_texture
&&
880 baseFormat
== GL_DEPTH_STENCIL
) {
884 att
->Complete
= GL_FALSE
;
885 att_incomplete("bad depth format");
890 assert(format
== GL_STENCIL
);
891 if (ctx
->Extensions
.ARB_depth_texture
&&
892 baseFormat
== GL_DEPTH_STENCIL
) {
894 } else if (ctx
->Extensions
.ARB_texture_stencil8
&&
895 baseFormat
== GL_STENCIL_INDEX
) {
898 /* no such thing as stencil-only textures */
899 att_incomplete("illegal stencil texture");
900 att
->Complete
= GL_FALSE
;
905 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
906 const GLenum baseFormat
= att
->Renderbuffer
->_BaseFormat
;
908 assert(att
->Renderbuffer
);
909 if (!att
->Renderbuffer
->InternalFormat
||
910 att
->Renderbuffer
->Width
< 1 ||
911 att
->Renderbuffer
->Height
< 1) {
912 att_incomplete("0x0 renderbuffer");
913 att
->Complete
= GL_FALSE
;
916 if (format
== GL_COLOR
) {
917 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
918 att_incomplete("bad renderbuffer color format");
919 att
->Complete
= GL_FALSE
;
923 else if (format
== GL_DEPTH
) {
924 if (baseFormat
== GL_DEPTH_COMPONENT
) {
927 else if (baseFormat
== GL_DEPTH_STENCIL
) {
931 att_incomplete("bad renderbuffer depth format");
932 att
->Complete
= GL_FALSE
;
937 assert(format
== GL_STENCIL
);
938 if (baseFormat
== GL_STENCIL_INDEX
||
939 baseFormat
== GL_DEPTH_STENCIL
) {
943 att
->Complete
= GL_FALSE
;
944 att_incomplete("bad renderbuffer stencil format");
950 assert(att
->Type
== GL_NONE
);
958 * Test if the given framebuffer object is complete and update its
959 * Status field with the results.
960 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
961 * driver to make hardware-specific validation/completeness checks.
962 * Also update the framebuffer's Width and Height fields if the
963 * framebuffer is complete.
966 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
967 struct gl_framebuffer
*fb
)
970 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
971 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
972 GLint numColorSamples
= -1;
973 GLint numColorStorageSamples
= -1;
974 GLint numDepthSamples
= -1;
975 GLint fixedSampleLocations
= -1;
978 /* Covers max_layer_count, is_layered, and layer_tex_target */
979 bool layer_info_valid
= false;
980 GLuint max_layer_count
= 0, att_layer_count
;
981 bool is_layered
= false;
982 GLenum layer_tex_target
= 0;
983 bool has_depth_attachment
= false;
984 bool has_stencil_attachment
= false;
986 assert(_mesa_is_user_fbo(fb
));
988 /* we're changing framebuffer fields here */
989 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
994 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
995 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
996 fb
->_HasAttachments
= true;
997 fb
->_IntegerBuffers
= 0;
999 /* Start at -2 to more easily loop over all attachment points.
1001 * -1: stencil buffer
1004 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
1005 struct gl_renderbuffer_attachment
*att
;
1007 mesa_format attFormat
;
1008 GLenum att_tex_target
= GL_NONE
;
1011 * XXX for ARB_fbo, only check color buffers that are named by
1012 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
1015 /* check for attachment completeness
1018 att
= &fb
->Attachment
[BUFFER_DEPTH
];
1019 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
1020 if (!att
->Complete
) {
1021 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1022 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
1024 } else if (att
->Type
!= GL_NONE
) {
1025 has_depth_attachment
= true;
1029 att
= &fb
->Attachment
[BUFFER_STENCIL
];
1030 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
1031 if (!att
->Complete
) {
1032 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1033 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
1035 } else if (att
->Type
!= GL_NONE
) {
1036 has_stencil_attachment
= true;
1040 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
1041 test_attachment_completeness(ctx
, GL_COLOR
, att
);
1042 if (!att
->Complete
) {
1043 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1044 fbo_incomplete(ctx
, "color attachment incomplete", i
);
1049 /* get width, height, format of the renderbuffer/texture
1051 unsigned attNumSamples
, attNumStorageSamples
;
1053 if (att
->Type
== GL_TEXTURE
) {
1054 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
1055 att_tex_target
= att
->Texture
->Target
;
1056 minWidth
= MIN2(minWidth
, texImg
->Width
);
1057 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
1058 minHeight
= MIN2(minHeight
, texImg
->Height
);
1059 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
1060 f
= texImg
->_BaseFormat
;
1061 attFormat
= texImg
->TexFormat
;
1064 if (!is_format_color_renderable(ctx
, attFormat
,
1065 texImg
->InternalFormat
) &&
1066 !is_legal_depth_format(ctx
, f
) &&
1067 f
!= GL_STENCIL_INDEX
) {
1068 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
;
1069 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
1073 if (fixedSampleLocations
< 0)
1074 fixedSampleLocations
= texImg
->FixedSampleLocations
;
1075 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
1076 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1077 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1081 attNumSamples
= texImg
->NumSamples
;
1082 attNumStorageSamples
= texImg
->NumSamples
;
1084 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1085 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
1086 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
1087 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
1088 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
1089 f
= att
->Renderbuffer
->InternalFormat
;
1090 attFormat
= att
->Renderbuffer
->Format
;
1093 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1094 if (fixedSampleLocations
< 0)
1095 fixedSampleLocations
= GL_TRUE
;
1096 else if (fixedSampleLocations
!= GL_TRUE
) {
1097 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1098 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1102 attNumSamples
= att
->Renderbuffer
->NumSamples
;
1103 attNumStorageSamples
= att
->Renderbuffer
->NumStorageSamples
;
1106 assert(att
->Type
== GL_NONE
);
1111 /* Color buffers. */
1112 if (numColorSamples
< 0) {
1113 assert(numColorStorageSamples
< 0);
1114 numColorSamples
= attNumSamples
;
1115 numColorStorageSamples
= attNumStorageSamples
;
1116 } else if (numColorSamples
!= attNumSamples
||
1117 numColorStorageSamples
!= attNumStorageSamples
) {
1118 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1119 fbo_incomplete(ctx
, "inconsistent sample counts", -1);
1123 /* Depth/stencil buffers. */
1124 if (numDepthSamples
< 0) {
1125 numDepthSamples
= attNumSamples
;
1126 } else if (numDepthSamples
!= attNumSamples
) {
1127 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1128 fbo_incomplete(ctx
, "inconsistent sample counts", -1);
1133 /* Update flags describing color buffer datatypes */
1135 GLenum type
= _mesa_get_format_datatype(attFormat
);
1137 /* check if integer color */
1138 if (_mesa_is_format_integer_color(attFormat
))
1139 fb
->_IntegerBuffers
|= (1 << i
);
1141 fb
->_AllColorBuffersFixedPoint
=
1142 fb
->_AllColorBuffersFixedPoint
&&
1143 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1145 fb
->_HasSNormOrFloatColorBuffer
=
1146 fb
->_HasSNormOrFloatColorBuffer
||
1147 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1150 /* Error-check width, height, format */
1151 if (numImages
== 1) {
1158 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1159 /* check that width, height, format are same */
1160 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1161 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1162 fbo_incomplete(ctx
, "width or height mismatch", -1);
1165 /* check that all color buffers are the same format */
1166 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1167 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1168 fbo_incomplete(ctx
, "format mismatch", -1);
1174 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1176 if (att
->Type
== GL_RENDERBUFFER
&&
1177 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1178 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1179 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1183 /* Check that layered rendering is consistent. */
1185 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1186 att_layer_count
= 6;
1187 else if (att_tex_target
== GL_TEXTURE_1D_ARRAY
)
1188 att_layer_count
= att
->Renderbuffer
->Height
;
1190 att_layer_count
= att
->Renderbuffer
->Depth
;
1192 att_layer_count
= 0;
1194 if (!layer_info_valid
) {
1195 is_layered
= att
->Layered
;
1196 max_layer_count
= att_layer_count
;
1197 layer_tex_target
= att_tex_target
;
1198 layer_info_valid
= true;
1199 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1200 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1201 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1203 } else if (is_layered
!= att
->Layered
) {
1204 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1206 "framebuffer attachment layer mode is inconsistent",
1209 } else if (att_layer_count
> max_layer_count
) {
1210 max_layer_count
= att_layer_count
;
1214 * The extension GL_ARB_framebuffer_no_attachments places additional
1215 * requirement on each attachment. Those additional requirements are
1216 * tighter that those of previous versions of GL. In interest of better
1217 * compatibility, we will not enforce these restrictions. For the record
1218 * those additional restrictions are quoted below:
1220 * "The width and height of image are greater than zero and less than or
1221 * equal to the values of the implementation-dependent limits
1222 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1224 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1225 * array texture and the attachment is layered, the depth or layer count
1226 * of the texture is less than or equal to the implementation-dependent
1227 * limit MAX_FRAMEBUFFER_LAYERS."
1229 * "If image has multiple samples, its sample count is less than or equal
1230 * to the value of the implementation-dependent limit
1231 * MAX_FRAMEBUFFER_SAMPLES."
1233 * The same requirements are also in place for GL 4.5,
1234 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1238 if (ctx
->Extensions
.AMD_framebuffer_multisample_advanced
) {
1239 /* See if non-matching sample counts are supported. */
1240 if (numColorSamples
>= 0 && numDepthSamples
>= 0) {
1243 assert(numColorStorageSamples
!= -1);
1245 numColorSamples
= MAX2(numColorSamples
, 1);
1246 numColorStorageSamples
= MAX2(numColorStorageSamples
, 1);
1247 numDepthSamples
= MAX2(numDepthSamples
, 1);
1249 if (numColorSamples
== 1 && numColorStorageSamples
== 1 &&
1250 numDepthSamples
== 1) {
1253 for (i
= 0; i
< ctx
->Const
.NumSupportedMultisampleModes
; i
++) {
1255 &ctx
->Const
.SupportedMultisampleModes
[i
].NumColorSamples
;
1257 if (counts
[0] == numColorSamples
&&
1258 counts
[1] == numColorStorageSamples
&&
1259 counts
[2] == numDepthSamples
) {
1267 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1268 fbo_incomplete(ctx
, "unsupported sample counts", -1);
1273 /* If the extension is unsupported, all sample counts must be equal. */
1274 if (numColorSamples
>= 0 &&
1275 (numColorSamples
!= numColorStorageSamples
||
1276 (numDepthSamples
>= 0 && numColorSamples
!= numDepthSamples
))) {
1277 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1278 fbo_incomplete(ctx
, "inconsistent sample counts", -1);
1283 fb
->MaxNumLayers
= max_layer_count
;
1285 if (numImages
== 0) {
1286 fb
->_HasAttachments
= false;
1288 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1289 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1290 fbo_incomplete(ctx
, "no attachments", -1);
1294 if (fb
->DefaultGeometry
.Width
== 0 || fb
->DefaultGeometry
.Height
== 0) {
1295 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1296 fbo_incomplete(ctx
, "no attachments and default width or height is 0", -1);
1301 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1302 /* Check that all DrawBuffers are present */
1303 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1304 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1305 const struct gl_renderbuffer_attachment
*att
1306 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
], NULL
);
1308 if (att
->Type
== GL_NONE
) {
1309 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1310 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1316 /* Check that the ReadBuffer is present */
1317 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1318 const struct gl_renderbuffer_attachment
*att
1319 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
, NULL
);
1321 if (att
->Type
== GL_NONE
) {
1322 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1323 fbo_incomplete(ctx
, "missing readbuffer", -1);
1329 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1331 * "Depth and stencil attachments, if present, are the same image."
1333 * This restriction is not present in the OpenGL ES2 spec.
1335 if (_mesa_is_gles3(ctx
) &&
1336 has_stencil_attachment
&& has_depth_attachment
&&
1337 !_mesa_has_depthstencil_combined(fb
)) {
1338 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1339 fbo_incomplete(ctx
, "Depth and stencil attachments must be the same image", -1);
1343 /* Provisionally set status = COMPLETE ... */
1344 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1346 /* ... but the driver may say the FB is incomplete.
1347 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1350 if (ctx
->Driver
.ValidateFramebuffer
) {
1351 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1352 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1353 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1359 * Note that if ARB_framebuffer_object is supported and the attached
1360 * renderbuffers/textures are different sizes, the framebuffer
1361 * width/height will be set to the smallest width/height.
1363 if (numImages
!= 0) {
1364 fb
->Width
= minWidth
;
1365 fb
->Height
= minHeight
;
1368 /* finally, update the visual info for the framebuffer */
1369 _mesa_update_framebuffer_visual(ctx
, fb
);
1373 GLboolean GLAPIENTRY
1374 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1376 struct gl_renderbuffer
*rb
;
1378 GET_CURRENT_CONTEXT(ctx
);
1380 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1382 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1383 return rb
!= NULL
&& rb
!= &DummyRenderbuffer
;
1387 static struct gl_renderbuffer
*
1388 allocate_renderbuffer_locked(struct gl_context
*ctx
, GLuint renderbuffer
,
1391 struct gl_renderbuffer
*newRb
;
1393 /* create new renderbuffer object */
1394 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1396 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1399 assert(newRb
->AllocStorage
);
1400 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1407 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1409 struct gl_renderbuffer
*newRb
;
1410 GET_CURRENT_CONTEXT(ctx
);
1412 if (target
!= GL_RENDERBUFFER_EXT
) {
1413 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1417 /* No need to flush here since the render buffer binding has no
1418 * effect on rendering state.
1422 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1423 if (newRb
== &DummyRenderbuffer
) {
1424 /* ID was reserved, but no real renderbuffer object made yet */
1427 else if (!newRb
&& !allow_user_names
) {
1428 /* All RB IDs must be Gen'd */
1429 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1434 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1435 newRb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
1436 "glBindRenderbufferEXT");
1437 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1444 assert(newRb
!= &DummyRenderbuffer
);
1446 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1450 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1452 GET_CURRENT_CONTEXT(ctx
);
1454 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1455 * entry point, but they allow the use of user-generated names.
1457 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1461 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1463 /* This function should not be in the dispatch table for core profile /
1464 * OpenGL 3.1, so execution should never get here in those cases -- no
1465 * need for an explicit test.
1467 bind_renderbuffer(target
, renderbuffer
, true);
1471 * ARB_framebuffer_no_attachment and ARB_sample_locations - Application passes
1472 * requested param's here. NOTE: NumSamples requested need not be _NumSamples
1473 * which is what the hw supports.
1476 framebuffer_parameteri(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1477 GLenum pname
, GLint param
, const char *func
)
1479 bool cannot_be_winsys_fbo
= false;
1482 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1483 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1484 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1485 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1486 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1487 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
)
1488 goto invalid_pname_enum
;
1489 cannot_be_winsys_fbo
= true;
1491 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1492 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1493 if (!ctx
->Extensions
.ARB_sample_locations
)
1494 goto invalid_pname_enum
;
1496 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1497 if (!ctx
->Extensions
.MESA_framebuffer_flip_y
)
1498 goto invalid_pname_enum
;
1499 cannot_be_winsys_fbo
= true;
1501 goto invalid_pname_enum
;
1504 if (cannot_be_winsys_fbo
&& _mesa_is_winsys_fbo(fb
)) {
1505 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1506 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1511 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1512 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferWidth
)
1513 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1515 fb
->DefaultGeometry
.Width
= param
;
1517 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1518 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferHeight
)
1519 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1521 fb
->DefaultGeometry
.Height
= param
;
1523 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1525 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1526 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1528 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1529 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1532 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferLayers
)
1533 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1535 fb
->DefaultGeometry
.Layers
= param
;
1537 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1538 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferSamples
)
1539 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1541 fb
->DefaultGeometry
.NumSamples
= param
;
1543 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1544 fb
->DefaultGeometry
.FixedSampleLocations
= param
;
1546 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1547 fb
->ProgrammableSampleLocations
= !!param
;
1549 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1550 fb
->SampleLocationPixelGrid
= !!param
;
1552 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1558 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1559 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1560 if (fb
== ctx
->DrawBuffer
)
1561 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
1564 invalidate_framebuffer(fb
);
1565 ctx
->NewState
|= _NEW_BUFFERS
;
1572 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1576 _mesa_FramebufferParameteri(GLenum target
, GLenum pname
, GLint param
)
1578 GET_CURRENT_CONTEXT(ctx
);
1579 struct gl_framebuffer
*fb
;
1581 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1582 !ctx
->Extensions
.ARB_sample_locations
) {
1583 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1584 "glFramebufferParameteriv not supported "
1585 "(neither ARB_framebuffer_no_attachments nor ARB_sample_locations"
1590 fb
= get_framebuffer_target(ctx
, target
);
1592 _mesa_error(ctx
, GL_INVALID_ENUM
,
1593 "glFramebufferParameteri(target=0x%x)", target
);
1597 framebuffer_parameteri(ctx
, fb
, pname
, param
, "glFramebufferParameteri");
1601 validate_get_framebuffer_parameteriv_pname(struct gl_context
*ctx
,
1602 struct gl_framebuffer
*fb
,
1603 GLuint pname
, const char *func
)
1605 bool cannot_be_winsys_fbo
= true;
1608 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1610 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1611 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1613 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1614 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1618 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1619 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1620 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1621 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1623 case GL_DOUBLEBUFFER
:
1624 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1625 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1627 case GL_SAMPLE_BUFFERS
:
1629 /* From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries:
1631 * "An INVALID_OPERATION error is generated by GetFramebufferParameteriv
1632 * if the default framebuffer is bound to target and pname is not one
1633 * of the accepted values from table 23.73, other than
1636 * For OpenGL ES, using default framebuffer raises INVALID_OPERATION
1639 cannot_be_winsys_fbo
= !_mesa_is_desktop_gl(ctx
);
1641 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1642 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1643 if (!ctx
->Extensions
.ARB_sample_locations
)
1644 goto invalid_pname_enum
;
1645 cannot_be_winsys_fbo
= false;
1647 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1648 if (!ctx
->Extensions
.MESA_framebuffer_flip_y
) {
1649 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1654 goto invalid_pname_enum
;
1657 if (cannot_be_winsys_fbo
&& _mesa_is_winsys_fbo(fb
)) {
1658 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1659 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1666 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1671 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1672 GLenum pname
, GLint
*params
, const char *func
)
1674 if (!validate_get_framebuffer_parameteriv_pname(ctx
, fb
, pname
, func
))
1678 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1679 *params
= fb
->DefaultGeometry
.Width
;
1681 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1682 *params
= fb
->DefaultGeometry
.Height
;
1684 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1685 *params
= fb
->DefaultGeometry
.Layers
;
1687 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1688 *params
= fb
->DefaultGeometry
.NumSamples
;
1690 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1691 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1693 case GL_DOUBLEBUFFER
:
1694 *params
= fb
->Visual
.doubleBufferMode
;
1696 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1697 *params
= _mesa_get_color_read_format(ctx
, fb
, func
);
1699 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1700 *params
= _mesa_get_color_read_type(ctx
, fb
, func
);
1703 *params
= _mesa_geometric_samples(fb
);
1705 case GL_SAMPLE_BUFFERS
:
1706 *params
= _mesa_geometric_samples(fb
) > 0;
1709 *params
= fb
->Visual
.stereoMode
;
1711 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1712 *params
= fb
->ProgrammableSampleLocations
;
1714 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1715 *params
= fb
->SampleLocationPixelGrid
;
1717 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1718 *params
= fb
->FlipY
;
1724 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1726 GET_CURRENT_CONTEXT(ctx
);
1727 struct gl_framebuffer
*fb
;
1729 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1730 !ctx
->Extensions
.ARB_sample_locations
) {
1731 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1732 "glGetFramebufferParameteriv not supported "
1733 "(neither ARB_framebuffer_no_attachments nor ARB_sample_locations"
1738 fb
= get_framebuffer_target(ctx
, target
);
1740 _mesa_error(ctx
, GL_INVALID_ENUM
,
1741 "glGetFramebufferParameteriv(target=0x%x)", target
);
1745 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1746 "glGetFramebufferParameteriv");
1751 * Remove the specified renderbuffer or texture from any attachment point in
1755 * \c true if the renderbuffer was detached from an attachment point. \c
1759 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1760 struct gl_framebuffer
*fb
,
1764 bool progress
= false;
1766 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1767 if (fb
->Attachment
[i
].Texture
== att
1768 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1769 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1774 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1775 * Completeness," of the OpenGL 3.1 spec says:
1777 * "Performing any of the following actions may change whether the
1778 * framebuffer is considered complete or incomplete:
1782 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1783 * containing an image that is attached to a framebuffer object
1784 * that is bound to the framebuffer."
1787 invalidate_framebuffer(fb
);
1794 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1797 GET_CURRENT_CONTEXT(ctx
);
1800 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1804 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1806 for (i
= 0; i
< n
; i
++) {
1807 if (renderbuffers
[i
] > 0) {
1808 struct gl_renderbuffer
*rb
;
1809 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1811 /* check if deleting currently bound renderbuffer object */
1812 if (rb
== ctx
->CurrentRenderbuffer
) {
1814 assert(rb
->RefCount
>= 2);
1815 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1818 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1819 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1820 * of the OpenGL 3.1 spec says:
1822 * "If a renderbuffer object is deleted while its image is
1823 * attached to one or more attachment points in the currently
1824 * bound framebuffer, then it is as if FramebufferRenderbuffer
1825 * had been called, with a renderbuffer of 0, for each
1826 * attachment point to which this image was attached in the
1827 * currently bound framebuffer. In other words, this
1828 * renderbuffer image is first detached from all attachment
1829 * points in the currently bound framebuffer. Note that the
1830 * renderbuffer image is specifically not detached from any
1831 * non-bound framebuffers. Detaching the image from any
1832 * non-bound framebuffers is the responsibility of the
1835 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1836 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1838 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1839 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1840 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1843 /* Remove from hash table immediately, to free the ID.
1844 * But the object will not be freed until it's no longer
1845 * referenced anywhere else.
1847 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1849 if (rb
!= &DummyRenderbuffer
) {
1850 /* no longer referenced by hash table */
1851 _mesa_reference_renderbuffer(&rb
, NULL
);
1859 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1862 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1869 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1871 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1873 for (i
= 0; i
< n
; i
++) {
1874 GLuint name
= first
+ i
;
1875 renderbuffers
[i
] = name
;
1878 allocate_renderbuffer_locked(ctx
, name
, func
);
1880 /* insert a dummy renderbuffer into the hash table */
1881 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1882 &DummyRenderbuffer
);
1886 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1891 create_render_buffers_err(struct gl_context
*ctx
, GLsizei n
,
1892 GLuint
*renderbuffers
, bool dsa
)
1894 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1897 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1901 create_render_buffers(ctx
, n
, renderbuffers
, dsa
);
1906 _mesa_GenRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1908 GET_CURRENT_CONTEXT(ctx
);
1909 create_render_buffers(ctx
, n
, renderbuffers
, false);
1914 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1916 GET_CURRENT_CONTEXT(ctx
);
1917 create_render_buffers_err(ctx
, n
, renderbuffers
, false);
1922 _mesa_CreateRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1924 GET_CURRENT_CONTEXT(ctx
);
1925 create_render_buffers(ctx
, n
, renderbuffers
, true);
1930 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1932 GET_CURRENT_CONTEXT(ctx
);
1933 create_render_buffers_err(ctx
, n
, renderbuffers
, true);
1938 * Given an internal format token for a render buffer, return the
1939 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1940 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1941 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1943 * This is similar to _mesa_base_tex_format() but the set of valid
1944 * internal formats is different.
1946 * Note that even if a format is determined to be legal here, validation
1947 * of the FBO may fail if the format is not supported by the driver/GPU.
1949 * \param internalFormat as passed to glRenderbufferStorage()
1950 * \return the base internal format, or 0 if internalFormat is illegal
1953 _mesa_base_fbo_format(const struct gl_context
*ctx
, GLenum internalFormat
)
1956 * Notes: some formats such as alpha, luminance, etc. were added
1957 * with GL_ARB_framebuffer_object.
1959 switch (internalFormat
) {
1965 return (ctx
->API
== API_OPENGL_COMPAT
&&
1966 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
1970 case GL_LUMINANCE12
:
1971 case GL_LUMINANCE16
:
1972 return (ctx
->API
== API_OPENGL_COMPAT
&&
1973 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
1974 case GL_LUMINANCE_ALPHA
:
1975 case GL_LUMINANCE4_ALPHA4
:
1976 case GL_LUMINANCE6_ALPHA2
:
1977 case GL_LUMINANCE8_ALPHA8
:
1978 case GL_LUMINANCE12_ALPHA4
:
1979 case GL_LUMINANCE12_ALPHA12
:
1980 case GL_LUMINANCE16_ALPHA16
:
1981 return (ctx
->API
== API_OPENGL_COMPAT
&&
1982 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
1986 case GL_INTENSITY12
:
1987 case GL_INTENSITY16
:
1988 return (ctx
->API
== API_OPENGL_COMPAT
&&
1989 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
1999 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
2001 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
2009 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
2011 return _mesa_is_desktop_gl(ctx
) || _mesa_has_EXT_texture_norm16(ctx
)
2014 case GL_SRGB8_ALPHA8_EXT
:
2015 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2016 case GL_STENCIL_INDEX
:
2017 case GL_STENCIL_INDEX1_EXT
:
2018 case GL_STENCIL_INDEX4_EXT
:
2019 case GL_STENCIL_INDEX16_EXT
:
2020 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
2021 * OpenGL ES, but Mesa does not currently support them.
2023 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
2024 case GL_STENCIL_INDEX8_EXT
:
2025 return GL_STENCIL_INDEX
;
2026 case GL_DEPTH_COMPONENT
:
2027 case GL_DEPTH_COMPONENT32
:
2028 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
2029 case GL_DEPTH_COMPONENT16
:
2030 case GL_DEPTH_COMPONENT24
:
2031 return GL_DEPTH_COMPONENT
;
2032 case GL_DEPTH_STENCIL
:
2033 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
2034 case GL_DEPTH24_STENCIL8
:
2035 return GL_DEPTH_STENCIL
;
2036 case GL_DEPTH_COMPONENT32F
:
2037 return ctx
->Version
>= 30
2038 || (ctx
->API
== API_OPENGL_COMPAT
&&
2039 ctx
->Extensions
.ARB_depth_buffer_float
)
2040 ? GL_DEPTH_COMPONENT
: 0;
2041 case GL_DEPTH32F_STENCIL8
:
2042 return ctx
->Version
>= 30
2043 || (ctx
->API
== API_OPENGL_COMPAT
&&
2044 ctx
->Extensions
.ARB_depth_buffer_float
)
2045 ? GL_DEPTH_STENCIL
: 0;
2047 return _mesa_has_ARB_texture_rg(ctx
) ? GL_RED
: 0;
2049 return _mesa_has_ARB_texture_rg(ctx
) || _mesa_has_EXT_texture_norm16(ctx
)
2052 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
2055 return _mesa_has_ARB_texture_rg(ctx
) ? GL_RG
: 0;
2057 return _mesa_has_ARB_texture_rg(ctx
) || _mesa_has_EXT_texture_norm16(ctx
)
2060 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
2062 /* signed normalized texture formats */
2066 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2071 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2075 case GL_RGB16_SNORM
:
2076 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2079 case GL_RGBA8_SNORM
:
2080 case GL_RGBA16_SNORM
:
2081 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2083 case GL_ALPHA_SNORM
:
2084 case GL_ALPHA8_SNORM
:
2085 case GL_ALPHA16_SNORM
:
2086 return ctx
->API
== API_OPENGL_COMPAT
&&
2087 ctx
->Extensions
.EXT_texture_snorm
&&
2088 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2089 case GL_LUMINANCE_SNORM
:
2090 case GL_LUMINANCE8_SNORM
:
2091 case GL_LUMINANCE16_SNORM
:
2092 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2094 case GL_LUMINANCE_ALPHA_SNORM
:
2095 case GL_LUMINANCE8_ALPHA8_SNORM
:
2096 case GL_LUMINANCE16_ALPHA16_SNORM
:
2097 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2098 ? GL_LUMINANCE_ALPHA
: 0;
2099 case GL_INTENSITY_SNORM
:
2100 case GL_INTENSITY8_SNORM
:
2101 case GL_INTENSITY16_SNORM
:
2102 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2107 return ((_mesa_is_desktop_gl(ctx
) &&
2108 ctx
->Extensions
.ARB_texture_rg
&&
2109 ctx
->Extensions
.ARB_texture_float
) ||
2110 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2114 return ((_mesa_is_desktop_gl(ctx
) &&
2115 ctx
->Extensions
.ARB_texture_rg
&&
2116 ctx
->Extensions
.ARB_texture_float
) ||
2117 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2121 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
2125 return ((_mesa_is_desktop_gl(ctx
) &&
2126 ctx
->Extensions
.ARB_texture_float
) ||
2127 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2130 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_shared_exponent
)
2132 case GL_ALPHA16F_ARB
:
2133 case GL_ALPHA32F_ARB
:
2134 return ctx
->API
== API_OPENGL_COMPAT
&&
2135 ctx
->Extensions
.ARB_texture_float
&&
2136 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2137 case GL_LUMINANCE16F_ARB
:
2138 case GL_LUMINANCE32F_ARB
:
2139 return ctx
->API
== API_OPENGL_COMPAT
&&
2140 ctx
->Extensions
.ARB_texture_float
&&
2141 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2142 case GL_LUMINANCE_ALPHA16F_ARB
:
2143 case GL_LUMINANCE_ALPHA32F_ARB
:
2144 return ctx
->API
== API_OPENGL_COMPAT
&&
2145 ctx
->Extensions
.ARB_texture_float
&&
2146 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2147 case GL_INTENSITY16F_ARB
:
2148 case GL_INTENSITY32F_ARB
:
2149 return ctx
->API
== API_OPENGL_COMPAT
&&
2150 ctx
->Extensions
.ARB_texture_float
&&
2151 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2152 case GL_R11F_G11F_B10F
:
2153 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
2154 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2157 case GL_RGBA8UI_EXT
:
2158 case GL_RGBA16UI_EXT
:
2159 case GL_RGBA32UI_EXT
:
2161 case GL_RGBA16I_EXT
:
2162 case GL_RGBA32I_EXT
:
2163 return ctx
->Version
>= 30
2164 || (_mesa_is_desktop_gl(ctx
) &&
2165 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
2168 case GL_RGB16UI_EXT
:
2169 case GL_RGB32UI_EXT
:
2173 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
2181 return ctx
->Version
>= 30
2182 || (_mesa_is_desktop_gl(ctx
) &&
2183 ctx
->Extensions
.ARB_texture_rg
&&
2184 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
2192 return ctx
->Version
>= 30
2193 || (_mesa_is_desktop_gl(ctx
) &&
2194 ctx
->Extensions
.ARB_texture_rg
&&
2195 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
2197 case GL_INTENSITY8I_EXT
:
2198 case GL_INTENSITY8UI_EXT
:
2199 case GL_INTENSITY16I_EXT
:
2200 case GL_INTENSITY16UI_EXT
:
2201 case GL_INTENSITY32I_EXT
:
2202 case GL_INTENSITY32UI_EXT
:
2203 return ctx
->API
== API_OPENGL_COMPAT
&&
2204 ctx
->Extensions
.EXT_texture_integer
&&
2205 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2207 case GL_LUMINANCE8I_EXT
:
2208 case GL_LUMINANCE8UI_EXT
:
2209 case GL_LUMINANCE16I_EXT
:
2210 case GL_LUMINANCE16UI_EXT
:
2211 case GL_LUMINANCE32I_EXT
:
2212 case GL_LUMINANCE32UI_EXT
:
2213 return ctx
->API
== API_OPENGL_COMPAT
&&
2214 ctx
->Extensions
.EXT_texture_integer
&&
2215 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2217 case GL_LUMINANCE_ALPHA8I_EXT
:
2218 case GL_LUMINANCE_ALPHA8UI_EXT
:
2219 case GL_LUMINANCE_ALPHA16I_EXT
:
2220 case GL_LUMINANCE_ALPHA16UI_EXT
:
2221 case GL_LUMINANCE_ALPHA32I_EXT
:
2222 case GL_LUMINANCE_ALPHA32UI_EXT
:
2223 return ctx
->API
== API_OPENGL_COMPAT
&&
2224 ctx
->Extensions
.EXT_texture_integer
&&
2225 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2227 case GL_ALPHA8I_EXT
:
2228 case GL_ALPHA8UI_EXT
:
2229 case GL_ALPHA16I_EXT
:
2230 case GL_ALPHA16UI_EXT
:
2231 case GL_ALPHA32I_EXT
:
2232 case GL_ALPHA32UI_EXT
:
2233 return ctx
->API
== API_OPENGL_COMPAT
&&
2234 ctx
->Extensions
.EXT_texture_integer
&&
2235 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2238 return (_mesa_is_desktop_gl(ctx
) &&
2239 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
2240 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2243 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2252 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2255 invalidate_rb(GLuint key
, void *data
, void *userData
)
2257 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2258 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2260 /* If this is a user-created FBO */
2261 if (_mesa_is_user_fbo(fb
)) {
2263 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2264 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2265 if (att
->Type
== GL_RENDERBUFFER
&&
2266 att
->Renderbuffer
== rb
) {
2267 /* Mark fb status as indeterminate to force re-validation */
2276 /** sentinal value, see below */
2277 #define NO_SAMPLES 1000
2280 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2281 GLenum internalFormat
, GLsizei width
,
2282 GLsizei height
, GLsizei samples
,
2283 GLsizei storageSamples
)
2285 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2287 assert(baseFormat
!= 0);
2288 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2289 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2290 assert(samples
!= NO_SAMPLES
);
2292 assert(samples
> 0);
2293 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2294 internalFormat
, samples
,
2295 storageSamples
) == GL_NO_ERROR
);
2298 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2300 if (rb
->InternalFormat
== internalFormat
&&
2301 rb
->Width
== (GLuint
) width
&&
2302 rb
->Height
== (GLuint
) height
&&
2303 rb
->NumSamples
== samples
&&
2304 rb
->NumStorageSamples
== storageSamples
) {
2305 /* no change in allocation needed */
2309 /* These MUST get set by the AllocStorage func */
2310 rb
->Format
= MESA_FORMAT_NONE
;
2311 rb
->NumSamples
= samples
;
2312 rb
->NumStorageSamples
= storageSamples
;
2314 /* Now allocate the storage */
2315 assert(rb
->AllocStorage
);
2316 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2317 /* No error - check/set fields now */
2318 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2319 assert(rb
->Width
== (GLuint
) width
);
2320 assert(rb
->Height
== (GLuint
) height
);
2321 rb
->InternalFormat
= internalFormat
;
2322 rb
->_BaseFormat
= baseFormat
;
2323 assert(rb
->_BaseFormat
!= 0);
2326 /* Probably ran out of memory - clear the fields */
2329 rb
->Format
= MESA_FORMAT_NONE
;
2330 rb
->InternalFormat
= GL_NONE
;
2331 rb
->_BaseFormat
= GL_NONE
;
2333 rb
->NumStorageSamples
= 0;
2336 /* Invalidate the framebuffers the renderbuffer is attached in. */
2337 if (rb
->AttachedAnytime
) {
2338 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2343 * Helper function used by renderbuffer_storage_direct() and
2344 * renderbuffer_storage_target().
2345 * samples will be NO_SAMPLES if called by a non-multisample function.
2348 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2349 GLenum internalFormat
, GLsizei width
,
2350 GLsizei height
, GLsizei samples
, GLsizei storageSamples
,
2354 GLenum sample_count_error
;
2356 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2357 if (baseFormat
== 0) {
2358 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2359 func
, _mesa_enum_to_string(internalFormat
));
2363 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2364 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2369 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2370 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2375 if (samples
== NO_SAMPLES
) {
2376 /* NumSamples == 0 indicates non-multisampling */
2381 /* check the sample count;
2382 * note: driver may choose to use more samples than what's requested
2384 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2385 internalFormat
, samples
, storageSamples
);
2387 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2389 * "If a negative number is provided where an argument of type sizei or
2390 * sizeiptr is specified, the error INVALID VALUE is generated."
2392 if (samples
< 0 || storageSamples
< 0) {
2393 sample_count_error
= GL_INVALID_VALUE
;
2396 if (sample_count_error
!= GL_NO_ERROR
) {
2397 _mesa_error(ctx
, sample_count_error
,
2398 "%s(samples=%d, storageSamples=%d)", func
, samples
,
2404 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
,
2409 * Helper function used by _mesa_NamedRenderbufferStorage*().
2410 * samples will be NO_SAMPLES if called by a non-multisample function.
2413 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2414 GLsizei width
, GLsizei height
, GLsizei samples
,
2415 GLsizei storageSamples
, const char *func
)
2417 GET_CURRENT_CONTEXT(ctx
);
2419 if (MESA_VERBOSE
& VERBOSE_API
) {
2420 if (samples
== NO_SAMPLES
)
2421 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2423 _mesa_enum_to_string(internalFormat
),
2426 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2428 _mesa_enum_to_string(internalFormat
),
2429 width
, height
, samples
);
2432 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2433 if (!rb
|| rb
== &DummyRenderbuffer
) {
2434 /* ID was reserved, but no real renderbuffer object made yet */
2435 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2436 func
, renderbuffer
);
2440 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
,
2441 storageSamples
, func
);
2445 * Helper function used by _mesa_RenderbufferStorage() and
2446 * _mesa_RenderbufferStorageMultisample().
2447 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2450 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2451 GLsizei width
, GLsizei height
, GLsizei samples
,
2452 GLsizei storageSamples
, const char *func
)
2454 GET_CURRENT_CONTEXT(ctx
);
2456 if (MESA_VERBOSE
& VERBOSE_API
) {
2457 if (samples
== NO_SAMPLES
)
2458 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2460 _mesa_enum_to_string(target
),
2461 _mesa_enum_to_string(internalFormat
),
2464 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2466 _mesa_enum_to_string(target
),
2467 _mesa_enum_to_string(internalFormat
),
2468 width
, height
, samples
);
2471 if (target
!= GL_RENDERBUFFER_EXT
) {
2472 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2476 if (!ctx
->CurrentRenderbuffer
) {
2477 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2482 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2483 height
, samples
, storageSamples
, func
);
2488 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2490 struct gl_renderbuffer
*rb
;
2491 GET_CURRENT_CONTEXT(ctx
);
2493 if (!ctx
->Extensions
.OES_EGL_image
) {
2494 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2495 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2499 if (target
!= GL_RENDERBUFFER
) {
2500 _mesa_error(ctx
, GL_INVALID_ENUM
,
2501 "EGLImageTargetRenderbufferStorageOES");
2505 rb
= ctx
->CurrentRenderbuffer
;
2507 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2508 "EGLImageTargetRenderbufferStorageOES");
2512 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2514 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2519 * Helper function for _mesa_GetRenderbufferParameteriv() and
2520 * _mesa_GetFramebufferAttachmentParameteriv()
2521 * We have to be careful to respect the base format. For example, if a
2522 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2523 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2524 * we need to return zero.
2527 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2529 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2530 return _mesa_get_format_bits(format
, pname
);
2538 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2539 GLsizei width
, GLsizei height
)
2541 /* GL_ARB_fbo says calling this function is equivalent to calling
2542 * glRenderbufferStorageMultisample() with samples=0. We pass in
2543 * a token value here just for error reporting purposes.
2545 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2546 NO_SAMPLES
, 0, "glRenderbufferStorage");
2551 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2552 GLenum internalFormat
,
2553 GLsizei width
, GLsizei height
)
2555 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2557 "glRenderbufferStorageMultisample");
2562 _mesa_RenderbufferStorageMultisampleAdvancedAMD(
2563 GLenum target
, GLsizei samples
, GLsizei storageSamples
,
2564 GLenum internalFormat
, GLsizei width
, GLsizei height
)
2566 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2567 samples
, storageSamples
,
2568 "glRenderbufferStorageMultisampleAdvancedAMD");
2573 * OpenGL ES version of glRenderBufferStorage.
2576 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2577 GLsizei width
, GLsizei height
)
2579 switch (internalFormat
) {
2581 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2582 /* choose a closest format */
2583 internalFormat
= GL_RGB5
;
2589 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0, 0,
2590 "glRenderbufferStorageEXT");
2594 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2595 GLsizei width
, GLsizei height
)
2597 /* GL_ARB_fbo says calling this function is equivalent to calling
2598 * glRenderbufferStorageMultisample() with samples=0. We pass in
2599 * a token value here just for error reporting purposes.
2601 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2602 NO_SAMPLES
, 0, "glNamedRenderbufferStorage");
2606 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2607 GLenum internalformat
,
2608 GLsizei width
, GLsizei height
)
2610 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2612 "glNamedRenderbufferStorageMultisample");
2617 _mesa_NamedRenderbufferStorageMultisampleAdvancedAMD(
2618 GLuint renderbuffer
, GLsizei samples
, GLsizei storageSamples
,
2619 GLenum internalformat
, GLsizei width
, GLsizei height
)
2621 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2622 samples
, storageSamples
,
2623 "glNamedRenderbufferStorageMultisampleAdvancedAMD");
2628 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2629 struct gl_renderbuffer
*rb
, GLenum pname
,
2630 GLint
*params
, const char *func
)
2632 /* No need to flush here since we're just quering state which is
2633 * not effected by rendering.
2637 case GL_RENDERBUFFER_WIDTH_EXT
:
2638 *params
= rb
->Width
;
2640 case GL_RENDERBUFFER_HEIGHT_EXT
:
2641 *params
= rb
->Height
;
2643 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2644 *params
= rb
->InternalFormat
;
2646 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2647 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2648 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2649 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2650 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2651 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2652 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2654 case GL_RENDERBUFFER_SAMPLES
:
2655 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2656 || _mesa_is_gles3(ctx
)) {
2657 *params
= rb
->NumSamples
;
2661 case GL_RENDERBUFFER_STORAGE_SAMPLES_AMD
:
2662 if (ctx
->Extensions
.AMD_framebuffer_multisample_advanced
) {
2663 *params
= rb
->NumStorageSamples
;
2669 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2670 _mesa_enum_to_string(pname
));
2675 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2677 GET_CURRENT_CONTEXT(ctx
);
2679 if (target
!= GL_RENDERBUFFER_EXT
) {
2680 _mesa_error(ctx
, GL_INVALID_ENUM
,
2681 "glGetRenderbufferParameterivEXT(target)");
2685 if (!ctx
->CurrentRenderbuffer
) {
2686 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2687 "(no renderbuffer bound)");
2691 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2692 params
, "glGetRenderbufferParameteriv");
2697 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2700 GET_CURRENT_CONTEXT(ctx
);
2702 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2703 if (!rb
|| rb
== &DummyRenderbuffer
) {
2704 /* ID was reserved, but no real renderbuffer object made yet */
2705 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2706 "(invalid renderbuffer %i)", renderbuffer
);
2710 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2711 "glGetNamedRenderbufferParameteriv");
2715 GLboolean GLAPIENTRY
2716 _mesa_IsFramebuffer(GLuint framebuffer
)
2718 GET_CURRENT_CONTEXT(ctx
);
2719 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2721 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2722 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2730 * Check if any of the attachments of the given framebuffer are textures
2731 * (render to texture). Call ctx->Driver.RenderTexture() for such
2735 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2738 assert(ctx
->Driver
.RenderTexture
);
2740 if (_mesa_is_winsys_fbo(fb
))
2741 return; /* can't render to texture with winsys framebuffers */
2743 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2744 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2745 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2746 && driver_RenderTexture_is_safe(att
)) {
2747 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2754 * Examine all the framebuffer's attachments to see if any are textures.
2755 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2756 * notify the device driver that the texture image may have changed.
2759 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2761 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2762 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2765 if (ctx
->Driver
.FinishRenderTexture
) {
2767 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2768 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2769 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2770 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2771 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2779 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2781 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2782 GLboolean bindReadBuf
, bindDrawBuf
;
2783 GET_CURRENT_CONTEXT(ctx
);
2786 case GL_DRAW_FRAMEBUFFER_EXT
:
2787 bindDrawBuf
= GL_TRUE
;
2788 bindReadBuf
= GL_FALSE
;
2790 case GL_READ_FRAMEBUFFER_EXT
:
2791 bindDrawBuf
= GL_FALSE
;
2792 bindReadBuf
= GL_TRUE
;
2794 case GL_FRAMEBUFFER_EXT
:
2795 bindDrawBuf
= GL_TRUE
;
2796 bindReadBuf
= GL_TRUE
;
2799 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2804 /* Binding a user-created framebuffer object */
2805 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2806 if (newDrawFb
== &DummyFramebuffer
) {
2807 /* ID was reserved, but no real framebuffer object made yet */
2810 else if (!newDrawFb
&& !allow_user_names
) {
2811 /* All FBO IDs must be Gen'd */
2812 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2817 /* create new framebuffer object */
2818 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2820 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2823 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2825 newReadFb
= newDrawFb
;
2828 /* Binding the window system framebuffer (which was originally set
2829 * with MakeCurrent).
2831 newDrawFb
= ctx
->WinSysDrawBuffer
;
2832 newReadFb
= ctx
->WinSysReadBuffer
;
2835 _mesa_bind_framebuffers(ctx
,
2836 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2837 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2841 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2842 struct gl_framebuffer
*newDrawFb
,
2843 struct gl_framebuffer
*newReadFb
)
2845 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
2846 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
2847 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
2848 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
2851 assert(newDrawFb
!= &DummyFramebuffer
);
2854 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2856 * We also check if we're beginning and/or ending render-to-texture.
2857 * When a framebuffer with texture attachments is unbound, call
2858 * ctx->Driver.FinishRenderTexture().
2859 * When a framebuffer with texture attachments is bound, call
2860 * ctx->Driver.RenderTexture().
2862 * Note that if the ReadBuffer has texture attachments we don't consider
2863 * that a render-to-texture case.
2866 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2868 /* check if old readbuffer was render-to-texture */
2869 check_end_texture_render(ctx
, oldReadFb
);
2871 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2875 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2876 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
2878 /* check if old framebuffer had any texture attachments */
2880 check_end_texture_render(ctx
, oldDrawFb
);
2882 /* check if newly bound framebuffer has any texture attachments */
2883 check_begin_texture_render(ctx
, newDrawFb
);
2885 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2888 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2889 /* The few classic drivers that actually hook this function really only
2890 * want to know if the draw framebuffer changed.
2892 ctx
->Driver
.BindFramebuffer(ctx
,
2893 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
2894 newDrawFb
, newReadFb
);
2899 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2901 GET_CURRENT_CONTEXT(ctx
);
2903 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2904 * point, but they allow the use of user-generated names.
2906 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2911 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2913 /* This function should not be in the dispatch table for core profile /
2914 * OpenGL 3.1, so execution should never get here in those cases -- no
2915 * need for an explicit test.
2917 bind_framebuffer(target
, framebuffer
, true);
2922 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2925 GET_CURRENT_CONTEXT(ctx
);
2928 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
2932 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2934 for (i
= 0; i
< n
; i
++) {
2935 if (framebuffers
[i
] > 0) {
2936 struct gl_framebuffer
*fb
;
2937 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2939 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2941 /* check if deleting currently bound framebuffer object */
2942 if (fb
== ctx
->DrawBuffer
) {
2944 assert(fb
->RefCount
>= 2);
2945 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2947 if (fb
== ctx
->ReadBuffer
) {
2949 assert(fb
->RefCount
>= 2);
2950 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2953 /* remove from hash table immediately, to free the ID */
2954 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2956 if (fb
!= &DummyFramebuffer
) {
2957 /* But the object will not be freed until it's no longer
2958 * bound in any context.
2960 _mesa_reference_framebuffer(&fb
, NULL
);
2969 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2970 * It is not exposed to the rest of Mesa to encourage the use of
2971 * nameless buffers in driver internals.
2974 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
2976 GET_CURRENT_CONTEXT(ctx
);
2979 struct gl_framebuffer
*fb
;
2981 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
2984 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
2991 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
2993 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2995 for (i
= 0; i
< n
; i
++) {
2996 GLuint name
= first
+ i
;
2997 framebuffers
[i
] = name
;
3000 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
3002 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
3003 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
3008 fb
= &DummyFramebuffer
;
3010 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
3013 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
3018 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
3020 create_framebuffers(n
, framebuffers
, false);
3025 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
3027 create_framebuffers(n
, framebuffers
, true);
3032 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
3033 struct gl_framebuffer
*buffer
)
3035 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
3037 if (_mesa_is_winsys_fbo(buffer
)) {
3038 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
3039 if (buffer
!= &IncompleteFramebuffer
) {
3040 return GL_FRAMEBUFFER_COMPLETE_EXT
;
3042 return GL_FRAMEBUFFER_UNDEFINED
;
3046 /* No need to flush here */
3048 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
3049 _mesa_test_framebuffer_completeness(ctx
, buffer
);
3052 return buffer
->_Status
;
3057 _mesa_CheckFramebufferStatus_no_error(GLenum target
)
3059 GET_CURRENT_CONTEXT(ctx
);
3061 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3062 return _mesa_check_framebuffer_status(ctx
, fb
);
3067 _mesa_CheckFramebufferStatus(GLenum target
)
3069 struct gl_framebuffer
*fb
;
3070 GET_CURRENT_CONTEXT(ctx
);
3072 if (MESA_VERBOSE
& VERBOSE_API
)
3073 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
3074 _mesa_enum_to_string(target
));
3076 fb
= get_framebuffer_target(ctx
, target
);
3078 _mesa_error(ctx
, GL_INVALID_ENUM
,
3079 "glCheckFramebufferStatus(invalid target %s)",
3080 _mesa_enum_to_string(target
));
3084 return _mesa_check_framebuffer_status(ctx
, fb
);
3089 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
3091 struct gl_framebuffer
*fb
;
3092 GET_CURRENT_CONTEXT(ctx
);
3094 /* Validate the target (for conformance's sake) and grab a reference to the
3095 * default framebuffer in case framebuffer = 0.
3096 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
3097 * (30.10.2014, PDF page 336) says:
3098 * "If framebuffer is zero, then the status of the default read or
3099 * draw framebuffer (as determined by target) is returned."
3102 case GL_DRAW_FRAMEBUFFER
:
3103 case GL_FRAMEBUFFER
:
3104 fb
= ctx
->WinSysDrawBuffer
;
3106 case GL_READ_FRAMEBUFFER
:
3107 fb
= ctx
->WinSysReadBuffer
;
3110 _mesa_error(ctx
, GL_INVALID_ENUM
,
3111 "glCheckNamedFramebufferStatus(invalid target %s)",
3112 _mesa_enum_to_string(target
));
3117 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3118 "glCheckNamedFramebufferStatus");
3123 return _mesa_check_framebuffer_status(ctx
, fb
);
3128 * Replicate the src attachment point. Used by framebuffer_texture() when
3129 * the same texture is attached at GL_DEPTH_ATTACHMENT and
3130 * GL_STENCIL_ATTACHMENT.
3133 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
3134 gl_buffer_index dst
,
3135 gl_buffer_index src
)
3137 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
3138 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
3140 assert(src_att
->Texture
!= NULL
);
3141 assert(src_att
->Renderbuffer
!= NULL
);
3143 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
3144 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
3145 dst_att
->Type
= src_att
->Type
;
3146 dst_att
->Complete
= src_att
->Complete
;
3147 dst_att
->TextureLevel
= src_att
->TextureLevel
;
3148 dst_att
->CubeMapFace
= src_att
->CubeMapFace
;
3149 dst_att
->Zoffset
= src_att
->Zoffset
;
3150 dst_att
->Layered
= src_att
->Layered
;
3154 static struct gl_texture_object
*
3155 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
)
3160 return _mesa_lookup_texture(ctx
, texture
);
3165 * Common code called by gl*FramebufferTexture*() to retrieve the correct
3166 * texture object pointer.
3168 * \param texObj where the pointer to the texture object is returned. Note
3169 * that a successful call may return texObj = NULL.
3171 * \return true if no errors, false if errors
3174 get_texture_for_framebuffer_err(struct gl_context
*ctx
, GLuint texture
,
3175 bool layered
, const char *caller
,
3176 struct gl_texture_object
**texObj
)
3178 *texObj
= NULL
; /* This will get returned if texture = 0. */
3183 *texObj
= _mesa_lookup_texture(ctx
, texture
);
3184 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
3185 /* Can't render to a non-existent texture object.
3187 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
3188 * Managing Framebuffer Objects specifies a different error
3189 * depending upon the calling function (PDF pages 325-328).
3190 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
3191 * value, while the other commands throw invalid operation (where
3192 * layered = GL_FALSE).
3194 const GLenum error
= layered
? GL_INVALID_VALUE
:
3195 GL_INVALID_OPERATION
;
3196 _mesa_error(ctx
, error
,
3197 "%s(non-existent texture %u)", caller
, texture
);
3206 * Common code called by gl*FramebufferTexture() to verify the texture target
3207 * and decide whether or not the attachment should truly be considered
3210 * \param layered true if attachment should be considered layered, false if
3213 * \return true if no errors, false if errors
3216 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
3217 const char *caller
, GLboolean
*layered
)
3223 case GL_TEXTURE_1D_ARRAY_EXT
:
3224 case GL_TEXTURE_2D_ARRAY_EXT
:
3225 case GL_TEXTURE_CUBE_MAP
:
3226 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3227 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3231 case GL_TEXTURE_RECTANGLE
:
3232 case GL_TEXTURE_2D_MULTISAMPLE
:
3233 /* These texture types are valid to pass to
3234 * glFramebufferTexture(), but since they aren't layered, it
3235 * is equivalent to calling glFramebufferTexture{1D,2D}().
3237 *layered
= GL_FALSE
;
3241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3242 "%s(invalid texture target %s)", caller
,
3243 _mesa_enum_to_string(target
));
3249 * Common code called by gl*FramebufferTextureLayer() to verify the texture
3252 * \return true if no errors, false if errors
3255 check_texture_target(struct gl_context
*ctx
, GLenum target
,
3258 /* We're being called by glFramebufferTextureLayer().
3259 * The only legal texture types for that function are 3D,
3260 * cube-map, and 1D/2D/cube-map array textures.
3262 * We don't need to check for GL_ARB_texture_cube_map_array because the
3263 * application wouldn't have been able to create a texture with a
3264 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
3268 case GL_TEXTURE_1D_ARRAY
:
3269 case GL_TEXTURE_2D_ARRAY
:
3270 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3271 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3273 case GL_TEXTURE_CUBE_MAP
:
3274 /* We don't need to check the extension (GL_ARB_direct_state_access) or
3275 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
3276 * enabled in core profile. This can be called from
3277 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
3278 * so we do have to check the profile.
3280 return ctx
->API
== API_OPENGL_CORE
;
3283 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3284 "%s(invalid texture target %s)", caller
,
3285 _mesa_enum_to_string(target
));
3291 * Common code called by glFramebufferTexture*D() to verify the texture
3294 * \return true if no errors, false if errors
3297 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
3298 GLenum textarget
, const char *caller
)
3302 switch (textarget
) {
3306 case GL_TEXTURE_1D_ARRAY
:
3307 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3312 case GL_TEXTURE_2D_ARRAY
:
3313 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3314 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3316 case GL_TEXTURE_2D_MULTISAMPLE
:
3317 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3319 !ctx
->Extensions
.ARB_texture_multisample
||
3320 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3322 case GL_TEXTURE_RECTANGLE
:
3323 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3324 !ctx
->Extensions
.NV_texture_rectangle
;
3326 case GL_TEXTURE_CUBE_MAP
:
3327 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3330 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3331 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3332 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3333 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3334 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3335 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3336 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3342 _mesa_error(ctx
, GL_INVALID_ENUM
,
3343 "%s(unknown textarget 0x%x)", caller
, textarget
);
3348 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3349 "%s(invalid textarget %s)",
3350 caller
, _mesa_enum_to_string(textarget
));
3354 /* Make sure textarget is consistent with the texture's type */
3355 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3356 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3359 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3360 "%s(mismatched texture target)", caller
);
3369 * Common code called by gl*FramebufferTextureLayer() and
3370 * glFramebufferTexture3D() to validate the layer.
3372 * \return true if no errors, false if errors
3375 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3378 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3381 * "An INVALID_VALUE error is generated if texture is non-zero
3382 * and layer is negative."
3385 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(layer %d < 0)", caller
, layer
);
3389 if (target
== GL_TEXTURE_3D
) {
3390 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3391 if (layer
>= maxSize
) {
3392 _mesa_error(ctx
, GL_INVALID_VALUE
,
3393 "%s(invalid layer %u)", caller
, layer
);
3397 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3398 (target
== GL_TEXTURE_2D_ARRAY
) ||
3399 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3400 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3401 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3402 _mesa_error(ctx
, GL_INVALID_VALUE
,
3403 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3408 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3410 _mesa_error(ctx
, GL_INVALID_VALUE
,
3411 "%s(layer %u >= 6)", caller
, layer
);
3421 * Common code called by all gl*FramebufferTexture*() entry points to verify
3424 * \return true if no errors, false if errors
3427 check_level(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
3428 GLenum target
, GLint level
, const char *caller
)
3430 /* Section 9.2.8 of the OpenGL 4.6 specification says:
3432 * "If texture refers to an immutable-format texture, level must be
3433 * greater than or equal to zero and smaller than the value of
3434 * TEXTURE_VIEW_NUM_LEVELS for texture."
3436 const int max_levels
= texObj
->Immutable
? texObj
->ImmutableLevels
:
3437 _mesa_max_texture_levels(ctx
, target
);
3439 if (level
< 0 || level
>= max_levels
) {
3440 _mesa_error(ctx
, GL_INVALID_VALUE
,
3441 "%s(invalid level %d)", caller
, level
);
3449 struct gl_renderbuffer_attachment
*
3450 _mesa_get_and_validate_attachment(struct gl_context
*ctx
,
3451 struct gl_framebuffer
*fb
,
3452 GLenum attachment
, const char *caller
)
3454 /* The window-system framebuffer object is immutable */
3455 if (_mesa_is_winsys_fbo(fb
)) {
3456 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3461 /* Not a hash lookup, so we can afford to get the attachment here. */
3462 bool is_color_attachment
;
3463 struct gl_renderbuffer_attachment
*att
=
3464 get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3466 if (is_color_attachment
) {
3467 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3468 "%s(invalid color attachment %s)", caller
,
3469 _mesa_enum_to_string(attachment
));
3471 _mesa_error(ctx
, GL_INVALID_ENUM
,
3472 "%s(invalid attachment %s)", caller
,
3473 _mesa_enum_to_string(attachment
));
3483 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3485 struct gl_renderbuffer_attachment
*att
,
3486 struct gl_texture_object
*texObj
, GLenum textarget
,
3487 GLint level
, GLuint layer
, GLboolean layered
)
3489 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3491 simple_mtx_lock(&fb
->Mutex
);
3493 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3494 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3495 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3496 _mesa_tex_target_to_face(textarget
) ==
3497 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3498 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3499 /* The texture object is already attached to the stencil attachment
3500 * point. Don't create a new renderbuffer; just reuse the stencil
3501 * attachment's. This is required to prevent a GL error in
3502 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3504 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3506 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3507 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3508 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3509 _mesa_tex_target_to_face(textarget
) ==
3510 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3511 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3512 /* As above, but with depth and stencil transposed. */
3513 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3516 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3517 level
, layer
, layered
);
3519 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3520 /* Above we created a new renderbuffer and attached it to the
3521 * depth attachment point. Now attach it to the stencil attachment
3524 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3525 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3530 /* Set the render-to-texture flag. We'll check this flag in
3531 * glTexImage() and friends to determine if we need to revalidate
3532 * any FBOs that might be rendering into this texture.
3533 * This flag never gets cleared since it's non-trivial to determine
3534 * when all FBOs might be done rendering to this texture. That's OK
3535 * though since it's uncommon to render to a texture then repeatedly
3536 * call glTexImage() to change images in the texture.
3538 texObj
->_RenderToTexture
= GL_TRUE
;
3541 remove_attachment(ctx
, att
);
3542 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3543 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3544 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3548 invalidate_framebuffer(fb
);
3550 simple_mtx_unlock(&fb
->Mutex
);
3555 framebuffer_texture_with_dims_no_error(GLenum target
, GLenum attachment
,
3556 GLenum textarget
, GLuint texture
,
3557 GLint level
, GLint layer
)
3559 GET_CURRENT_CONTEXT(ctx
);
3561 /* Get the framebuffer object */
3562 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3564 /* Get the texture object */
3565 struct gl_texture_object
*texObj
=
3566 get_texture_for_framebuffer(ctx
, texture
);
3568 struct gl_renderbuffer_attachment
*att
=
3569 get_attachment(ctx
, fb
, attachment
, NULL
);
3571 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3572 level
, layer
, GL_FALSE
);
3577 framebuffer_texture_with_dims(int dims
, GLenum target
,
3578 GLenum attachment
, GLenum textarget
,
3579 GLuint texture
, GLint level
, GLint layer
,
3582 GET_CURRENT_CONTEXT(ctx
);
3583 struct gl_framebuffer
*fb
;
3584 struct gl_texture_object
*texObj
;
3586 /* Get the framebuffer object */
3587 fb
= get_framebuffer_target(ctx
, target
);
3589 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3590 _mesa_enum_to_string(target
));
3594 /* Get the texture object */
3595 if (!get_texture_for_framebuffer_err(ctx
, texture
, false, caller
, &texObj
))
3599 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3602 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3605 if (!check_level(ctx
, texObj
, textarget
, level
, caller
))
3609 struct gl_renderbuffer_attachment
*att
=
3610 _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, caller
);
3614 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3615 level
, layer
, GL_FALSE
);
3620 _mesa_FramebufferTexture1D_no_error(GLenum target
, GLenum attachment
,
3621 GLenum textarget
, GLuint texture
,
3624 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3630 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3631 GLenum textarget
, GLuint texture
, GLint level
)
3633 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3634 level
, 0, "glFramebufferTexture1D");
3639 _mesa_FramebufferTexture2D_no_error(GLenum target
, GLenum attachment
,
3640 GLenum textarget
, GLuint texture
,
3643 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3649 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3650 GLenum textarget
, GLuint texture
, GLint level
)
3652 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3653 level
, 0, "glFramebufferTexture2D");
3658 _mesa_FramebufferTexture3D_no_error(GLenum target
, GLenum attachment
,
3659 GLenum textarget
, GLuint texture
,
3660 GLint level
, GLint layer
)
3662 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3663 texture
, level
, layer
);
3668 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3669 GLenum textarget
, GLuint texture
,
3670 GLint level
, GLint layer
)
3672 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3673 level
, layer
, "glFramebufferTexture3D");
3677 static ALWAYS_INLINE
void
3678 frame_buffer_texture(GLuint framebuffer
, GLenum target
,
3679 GLenum attachment
, GLuint texture
,
3680 GLint level
, GLint layer
, const char *func
,
3681 bool dsa
, bool no_error
, bool check_layered
)
3683 GET_CURRENT_CONTEXT(ctx
);
3684 GLboolean layered
= GL_FALSE
;
3686 if (!no_error
&& check_layered
) {
3687 if (!_mesa_has_geometry_shaders(ctx
)) {
3688 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3689 "unsupported function (%s) called", func
);
3694 /* Get the framebuffer object */
3695 struct gl_framebuffer
*fb
;
3698 fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3700 fb
= get_framebuffer_target(ctx
, target
);
3704 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3708 fb
= get_framebuffer_target(ctx
, target
);
3710 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)",
3711 func
, _mesa_enum_to_string(target
));
3717 /* Get the texture object and framebuffer attachment*/
3718 struct gl_renderbuffer_attachment
*att
;
3719 struct gl_texture_object
*texObj
;
3721 texObj
= get_texture_for_framebuffer(ctx
, texture
);
3722 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
3724 if (!get_texture_for_framebuffer_err(ctx
, texture
, check_layered
, func
,
3728 att
= _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, func
);
3733 GLenum textarget
= 0;
3735 if (check_layered
) {
3736 /* We do this regardless of no_error because this sets layered */
3737 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3743 if (!check_layered
) {
3744 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3747 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3751 if (!check_level(ctx
, texObj
, texObj
->Target
, level
, func
))
3755 if (!check_layered
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3756 assert(layer
>= 0 && layer
< 6);
3757 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3762 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3763 level
, layer
, layered
);
3767 _mesa_FramebufferTextureLayer_no_error(GLenum target
, GLenum attachment
,
3768 GLuint texture
, GLint level
,
3771 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3772 "glFramebufferTextureLayer", false, true, false);
3777 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3778 GLuint texture
, GLint level
, GLint layer
)
3780 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3781 "glFramebufferTextureLayer", false, false, false);
3786 _mesa_NamedFramebufferTextureLayer_no_error(GLuint framebuffer
,
3788 GLuint texture
, GLint level
,
3791 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3792 "glNamedFramebufferTextureLayer", true, true, false);
3797 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3798 GLuint texture
, GLint level
, GLint layer
)
3800 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3801 "glNamedFramebufferTextureLayer", true, false, false);
3806 _mesa_FramebufferTexture_no_error(GLenum target
, GLenum attachment
,
3807 GLuint texture
, GLint level
)
3809 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3810 "glFramebufferTexture", false, true, true);
3815 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3816 GLuint texture
, GLint level
)
3818 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3819 "glFramebufferTexture", false, false, true);
3823 _mesa_NamedFramebufferTexture_no_error(GLuint framebuffer
, GLenum attachment
,
3824 GLuint texture
, GLint level
)
3826 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3827 "glNamedFramebufferTexture", true, true, true);
3832 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3833 GLuint texture
, GLint level
)
3835 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3836 "glNamedFramebufferTexture", true, false, true);
3841 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3842 struct gl_framebuffer
*fb
,
3844 struct gl_renderbuffer
*rb
)
3846 assert(!_mesa_is_winsys_fbo(fb
));
3848 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3850 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3851 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3853 /* Some subsequent GL commands may depend on the framebuffer's visual
3854 * after the binding is updated. Update visual info now.
3856 _mesa_update_framebuffer_visual(ctx
, fb
);
3859 static ALWAYS_INLINE
void
3860 framebuffer_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3861 GLenum attachment
, GLenum renderbuffertarget
,
3862 GLuint renderbuffer
, const char *func
, bool no_error
)
3864 struct gl_renderbuffer_attachment
*att
;
3865 struct gl_renderbuffer
*rb
;
3866 bool is_color_attachment
;
3868 if (!no_error
&& renderbuffertarget
!= GL_RENDERBUFFER
) {
3869 _mesa_error(ctx
, GL_INVALID_ENUM
,
3870 "%s(renderbuffertarget is not GL_RENDERBUFFER)", func
);
3876 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
, func
);
3880 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
3883 /* remove renderbuffer attachment */
3888 if (_mesa_is_winsys_fbo(fb
)) {
3889 /* Can't attach new renderbuffers to a window system framebuffer */
3890 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3891 "%s(window-system framebuffer)", func
);
3895 att
= get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3898 * From OpenGL 4.5 spec, section 9.2.7 "Attaching Renderbuffer Images
3899 * to a Framebuffer":
3901 * "An INVALID_OPERATION error is generated if attachment is
3902 * COLOR_- ATTACHMENTm where m is greater than or equal to the
3903 * value of MAX_COLOR_- ATTACHMENTS ."
3905 * If we are at this point, is because the attachment is not valid, so
3906 * if is_color_attachment is true, is because of the previous reason.
3908 if (is_color_attachment
) {
3909 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3910 "%s(invalid color attachment %s)", func
,
3911 _mesa_enum_to_string(attachment
));
3913 _mesa_error(ctx
, GL_INVALID_ENUM
,
3914 "%s(invalid attachment %s)", func
,
3915 _mesa_enum_to_string(attachment
));
3921 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3922 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3923 /* make sure the renderbuffer is a depth/stencil format */
3924 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3925 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3926 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3927 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3933 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3937 framebuffer_renderbuffer_error(struct gl_context
*ctx
,
3938 struct gl_framebuffer
*fb
, GLenum attachment
,
3939 GLenum renderbuffertarget
,
3940 GLuint renderbuffer
, const char *func
)
3942 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3943 renderbuffer
, func
, false);
3947 framebuffer_renderbuffer_no_error(struct gl_context
*ctx
,
3948 struct gl_framebuffer
*fb
, GLenum attachment
,
3949 GLenum renderbuffertarget
,
3950 GLuint renderbuffer
, const char *func
)
3952 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3953 renderbuffer
, func
, true);
3957 _mesa_FramebufferRenderbuffer_no_error(GLenum target
, GLenum attachment
,
3958 GLenum renderbuffertarget
,
3959 GLuint renderbuffer
)
3961 GET_CURRENT_CONTEXT(ctx
);
3963 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3964 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3965 renderbuffer
, "glFramebufferRenderbuffer");
3969 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3970 GLenum renderbuffertarget
,
3971 GLuint renderbuffer
)
3973 struct gl_framebuffer
*fb
;
3974 GET_CURRENT_CONTEXT(ctx
);
3976 fb
= get_framebuffer_target(ctx
, target
);
3978 _mesa_error(ctx
, GL_INVALID_ENUM
,
3979 "glFramebufferRenderbuffer(invalid target %s)",
3980 _mesa_enum_to_string(target
));
3984 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
3985 renderbuffer
, "glFramebufferRenderbuffer");
3989 _mesa_NamedFramebufferRenderbuffer_no_error(GLuint framebuffer
,
3991 GLenum renderbuffertarget
,
3992 GLuint renderbuffer
)
3994 GET_CURRENT_CONTEXT(ctx
);
3996 struct gl_framebuffer
*fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3997 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3999 "glNamedFramebufferRenderbuffer");
4003 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
4004 GLenum renderbuffertarget
,
4005 GLuint renderbuffer
)
4007 struct gl_framebuffer
*fb
;
4008 GET_CURRENT_CONTEXT(ctx
);
4010 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4011 "glNamedFramebufferRenderbuffer");
4015 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
4017 "glNamedFramebufferRenderbuffer");
4022 get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
4023 struct gl_framebuffer
*buffer
,
4024 GLenum attachment
, GLenum pname
,
4025 GLint
*params
, const char *caller
)
4027 const struct gl_renderbuffer_attachment
*att
;
4028 bool is_color_attachment
= false;
4031 /* The error code for an attachment type of GL_NONE differs between APIs.
4033 * From the ES 2.0.25 specification, page 127:
4034 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
4035 * querying any other pname will generate INVALID_ENUM."
4037 * From the OpenGL 3.0 specification, page 337, or identically,
4038 * the OpenGL ES 3.0.4 specification, page 240:
4040 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
4041 * framebuffer is bound to target. In this case querying pname
4042 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
4043 * queries will generate an INVALID_OPERATION error."
4045 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
4046 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
4048 if (_mesa_is_winsys_fbo(buffer
)) {
4049 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
4052 * "If the framebuffer currently bound to target is zero, then
4053 * INVALID_OPERATION is generated."
4055 * The EXT_framebuffer_object spec has the same wording, and the
4056 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
4059 if ((!_mesa_is_desktop_gl(ctx
) ||
4060 !ctx
->Extensions
.ARB_framebuffer_object
)
4061 && !_mesa_is_gles3(ctx
)) {
4062 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4063 "%s(window-system framebuffer)", caller
);
4067 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
4068 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
4069 _mesa_error(ctx
, GL_INVALID_ENUM
,
4070 "%s(invalid attachment %s)", caller
,
4071 _mesa_enum_to_string(attachment
));
4075 /* The specs are not clear about how to handle
4076 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
4077 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
4080 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
4081 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
4083 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
4084 _mesa_error(ctx
, GL_INVALID_ENUM
,
4085 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
4086 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
4087 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
4091 /* the default / window-system FBO */
4092 att
= get_fb0_attachment(ctx
, buffer
, attachment
);
4095 /* user-created framebuffer FBO */
4096 att
= get_attachment(ctx
, buffer
, attachment
, &is_color_attachment
);
4101 * From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries":
4103 * "An INVALID_OPERATION error is generated if a framebuffer object
4104 * is bound to target and attachment is COLOR_ATTACHMENTm where m is
4105 * greater than or equal to the value of MAX_COLOR_ATTACHMENTS."
4107 * If we are at this point, is because the attachment is not valid, so
4108 * if is_color_attachment is true, is because of the previous reason.
4110 if (is_color_attachment
) {
4111 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid color attachment %s)",
4112 caller
, _mesa_enum_to_string(attachment
));
4114 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
4115 _mesa_enum_to_string(attachment
));
4120 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
4121 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
4122 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
4123 /* This behavior is first specified in OpenGL 4.4 specification.
4125 * From the OpenGL 4.4 spec page 275:
4126 * "This query cannot be performed for a combined depth+stencil
4127 * attachment, since it does not have a single format."
4129 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4130 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
4131 " is invalid for depth+stencil attachment)", caller
);
4134 /* the depth and stencil attachments must point to the same buffer */
4135 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
, NULL
);
4136 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
, NULL
);
4137 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
4138 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4139 "%s(DEPTH/STENCIL attachments differ)", caller
);
4144 /* No need to flush here */
4147 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
4148 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
4150 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
4151 * either no framebuffer is bound to target; or the default framebuffer
4152 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
4153 * stencil bits, respectively, is zero."
4155 * Note that we don't need explicit checks on DEPTH and STENCIL, because
4156 * on the case the spec is pointing, att->Type is already NONE, so we
4157 * just need to check att->Type.
4159 *params
= (_mesa_is_winsys_fbo(buffer
) && att
->Type
!= GL_NONE
) ?
4160 GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
4162 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
4163 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
4164 *params
= att
->Renderbuffer
->Name
;
4166 else if (att
->Type
== GL_TEXTURE
) {
4167 *params
= att
->Texture
->Name
;
4170 assert(att
->Type
== GL_NONE
);
4171 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
4174 goto invalid_pname_enum
;
4178 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
4179 if (att
->Type
== GL_TEXTURE
) {
4180 *params
= att
->TextureLevel
;
4182 else if (att
->Type
== GL_NONE
) {
4183 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4184 _mesa_enum_to_string(pname
));
4187 goto invalid_pname_enum
;
4190 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
4191 if (att
->Type
== GL_TEXTURE
) {
4192 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
4193 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
4199 else if (att
->Type
== GL_NONE
) {
4200 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4201 _mesa_enum_to_string(pname
));
4204 goto invalid_pname_enum
;
4207 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
4208 if (ctx
->API
== API_OPENGLES
) {
4209 goto invalid_pname_enum
;
4210 } else if (att
->Type
== GL_NONE
) {
4211 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4212 _mesa_enum_to_string(pname
));
4213 } else if (att
->Type
== GL_TEXTURE
) {
4214 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
4215 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
4216 *params
= att
->Zoffset
;
4223 goto invalid_pname_enum
;
4226 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
4227 if ((!_mesa_is_desktop_gl(ctx
) ||
4228 !ctx
->Extensions
.ARB_framebuffer_object
)
4229 && !_mesa_is_gles3(ctx
)) {
4230 goto invalid_pname_enum
;
4232 else if (att
->Type
== GL_NONE
) {
4233 if (_mesa_is_winsys_fbo(buffer
) &&
4234 (attachment
== GL_DEPTH
|| attachment
== GL_STENCIL
)) {
4235 *params
= GL_LINEAR
;
4237 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4238 _mesa_enum_to_string(pname
));
4242 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
4244 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
4247 /* According to ARB_framebuffer_sRGB, we should return LINEAR
4248 * if the sRGB conversion is unsupported. */
4249 *params
= GL_LINEAR
;
4253 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
4254 if ((ctx
->API
!= API_OPENGL_COMPAT
||
4255 !ctx
->Extensions
.ARB_framebuffer_object
)
4256 && ctx
->API
!= API_OPENGL_CORE
4257 && !_mesa_is_gles3(ctx
)) {
4258 goto invalid_pname_enum
;
4260 else if (att
->Type
== GL_NONE
) {
4261 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4262 _mesa_enum_to_string(pname
));
4265 mesa_format format
= att
->Renderbuffer
->Format
;
4267 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
4270 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
4271 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
4272 * generate an INVALID_OPERATION error.
4274 if (_mesa_is_gles3(ctx
) &&
4275 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
4276 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4278 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
4279 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
4283 if (format
== MESA_FORMAT_S_UINT8
) {
4287 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
4288 /* depends on the attachment parameter */
4289 if (attachment
== GL_STENCIL_ATTACHMENT
) {
4297 *params
= _mesa_get_format_datatype(format
);
4301 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
4302 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
4303 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
4304 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
4305 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
4306 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
4307 if ((!_mesa_is_desktop_gl(ctx
) ||
4308 !ctx
->Extensions
.ARB_framebuffer_object
)
4309 && !_mesa_is_gles3(ctx
)) {
4310 goto invalid_pname_enum
;
4312 else if (att
->Texture
) {
4313 const struct gl_texture_image
*texImage
=
4314 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
4317 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
4318 texImage
->TexFormat
);
4324 else if (att
->Renderbuffer
) {
4325 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
4326 att
->Renderbuffer
->Format
);
4329 assert(att
->Type
== GL_NONE
);
4330 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4331 _mesa_enum_to_string(pname
));
4334 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
4335 if (!_mesa_has_geometry_shaders(ctx
)) {
4336 goto invalid_pname_enum
;
4337 } else if (att
->Type
== GL_TEXTURE
) {
4338 *params
= att
->Layered
;
4339 } else if (att
->Type
== GL_NONE
) {
4340 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4341 _mesa_enum_to_string(pname
));
4343 goto invalid_pname_enum
;
4347 goto invalid_pname_enum
;
4353 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
4354 _mesa_enum_to_string(pname
));
4360 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
4361 GLenum pname
, GLint
*params
)
4363 GET_CURRENT_CONTEXT(ctx
);
4364 struct gl_framebuffer
*buffer
;
4366 buffer
= get_framebuffer_target(ctx
, target
);
4368 _mesa_error(ctx
, GL_INVALID_ENUM
,
4369 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
4370 _mesa_enum_to_string(target
));
4374 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4376 "glGetFramebufferAttachmentParameteriv");
4381 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
4383 GLenum pname
, GLint
*params
)
4385 GET_CURRENT_CONTEXT(ctx
);
4386 struct gl_framebuffer
*buffer
;
4389 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4390 "glGetNamedFramebufferAttachmentParameteriv");
4396 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
4397 * 4.5 core spec (30.10.2014, PDF page 314):
4398 * "If framebuffer is zero, then the default draw framebuffer is
4401 buffer
= ctx
->WinSysDrawBuffer
;
4404 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4406 "glGetNamedFramebufferAttachmentParameteriv");
4411 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
4414 GET_CURRENT_CONTEXT(ctx
);
4415 struct gl_framebuffer
*fb
= NULL
;
4417 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
4418 !ctx
->Extensions
.ARB_sample_locations
) {
4419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4420 "glNamedFramebufferParameteri("
4421 "neither ARB_framebuffer_no_attachments nor "
4422 "ARB_sample_locations is available)");
4427 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4428 "glNamedFramebufferParameteri");
4430 fb
= ctx
->WinSysDrawBuffer
;
4434 framebuffer_parameteri(ctx
, fb
, pname
, param
,
4435 "glNamedFramebufferParameteriv");
4441 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
4444 GET_CURRENT_CONTEXT(ctx
);
4445 struct gl_framebuffer
*fb
;
4447 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4448 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4449 "glNamedFramebufferParameteriv("
4450 "neither ARB_framebuffer_no_attachments nor ARB_sample_locations"
4456 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4457 "glGetNamedFramebufferParameteriv");
4459 fb
= ctx
->WinSysDrawBuffer
;
4462 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4463 "glGetNamedFramebufferParameteriv");
4469 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4470 struct gl_framebuffer
*fb
,
4471 GLsizei numAttachments
,
4472 const GLenum
*attachments
, GLint x
, GLint y
,
4473 GLsizei width
, GLsizei height
, const char *name
)
4477 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4478 * Spec (2.2.2015, PDF page 522) says:
4479 * "An INVALID_VALUE error is generated if numAttachments, width, or
4480 * height is negative."
4482 if (numAttachments
< 0) {
4483 _mesa_error(ctx
, GL_INVALID_VALUE
,
4484 "%s(numAttachments < 0)", name
);
4489 _mesa_error(ctx
, GL_INVALID_VALUE
,
4490 "%s(width < 0)", name
);
4495 _mesa_error(ctx
, GL_INVALID_VALUE
,
4496 "%s(height < 0)", name
);
4500 /* The GL_ARB_invalidate_subdata spec says:
4502 * "If an attachment is specified that does not exist in the
4503 * framebuffer bound to <target>, it is ignored."
4507 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4508 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4509 * INVALID_OPERATION is generated."
4511 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4512 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4513 * set of retrictions).
4515 for (i
= 0; i
< numAttachments
; i
++) {
4516 if (_mesa_is_winsys_fbo(fb
)) {
4517 switch (attachments
[i
]) {
4523 /* Accumulation buffers and auxilary buffers were removed in
4524 * OpenGL 3.1, and they never existed in OpenGL ES.
4526 if (ctx
->API
!= API_OPENGL_COMPAT
)
4536 case GL_FRONT_RIGHT
:
4537 if (!_mesa_is_desktop_gl(ctx
))
4544 switch (attachments
[i
]) {
4545 case GL_DEPTH_ATTACHMENT
:
4546 case GL_STENCIL_ATTACHMENT
:
4548 case GL_DEPTH_STENCIL_ATTACHMENT
:
4549 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4550 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4551 * extension does not make this attachment point valid on ES 2.0.
4553 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4556 case GL_COLOR_ATTACHMENT0
:
4557 case GL_COLOR_ATTACHMENT1
:
4558 case GL_COLOR_ATTACHMENT2
:
4559 case GL_COLOR_ATTACHMENT3
:
4560 case GL_COLOR_ATTACHMENT4
:
4561 case GL_COLOR_ATTACHMENT5
:
4562 case GL_COLOR_ATTACHMENT6
:
4563 case GL_COLOR_ATTACHMENT7
:
4564 case GL_COLOR_ATTACHMENT8
:
4565 case GL_COLOR_ATTACHMENT9
:
4566 case GL_COLOR_ATTACHMENT10
:
4567 case GL_COLOR_ATTACHMENT11
:
4568 case GL_COLOR_ATTACHMENT12
:
4569 case GL_COLOR_ATTACHMENT13
:
4570 case GL_COLOR_ATTACHMENT14
:
4571 case GL_COLOR_ATTACHMENT15
: {
4572 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4573 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4574 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4575 "%s(attachment >= max. color attachments)", name
);
4586 /* We don't actually do anything for this yet. Just return after
4587 * validating the parameters and generating the required errors.
4592 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4593 _mesa_enum_to_string(attachments
[i
]));
4599 _mesa_InvalidateSubFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4600 const GLenum
*attachments
, GLint x
,
4601 GLint y
, GLsizei width
, GLsizei height
)
4608 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4609 const GLenum
*attachments
, GLint x
, GLint y
,
4610 GLsizei width
, GLsizei height
)
4612 struct gl_framebuffer
*fb
;
4613 GET_CURRENT_CONTEXT(ctx
);
4615 fb
= get_framebuffer_target(ctx
, target
);
4617 _mesa_error(ctx
, GL_INVALID_ENUM
,
4618 "glInvalidateSubFramebuffer(invalid target %s)",
4619 _mesa_enum_to_string(target
));
4623 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4624 x
, y
, width
, height
,
4625 "glInvalidateSubFramebuffer");
4630 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4631 GLsizei numAttachments
,
4632 const GLenum
*attachments
,
4634 GLsizei width
, GLsizei height
)
4636 struct gl_framebuffer
*fb
;
4637 GET_CURRENT_CONTEXT(ctx
);
4639 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4640 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4641 * default draw framebuffer is affected."
4644 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4645 "glInvalidateNamedFramebufferSubData");
4650 fb
= ctx
->WinSysDrawBuffer
;
4652 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4653 x
, y
, width
, height
,
4654 "glInvalidateNamedFramebufferSubData");
4659 _mesa_InvalidateFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4660 const GLenum
*attachments
)
4667 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4668 const GLenum
*attachments
)
4670 struct gl_framebuffer
*fb
;
4671 GET_CURRENT_CONTEXT(ctx
);
4673 fb
= get_framebuffer_target(ctx
, target
);
4675 _mesa_error(ctx
, GL_INVALID_ENUM
,
4676 "glInvalidateFramebuffer(invalid target %s)",
4677 _mesa_enum_to_string(target
));
4681 /* The GL_ARB_invalidate_subdata spec says:
4685 * void InvalidateFramebuffer(enum target,
4686 * sizei numAttachments,
4687 * const enum *attachments);
4689 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4690 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4691 * <MAX_VIEWPORT_DIMS[1]> respectively."
4693 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4695 ctx
->Const
.MaxViewportWidth
,
4696 ctx
->Const
.MaxViewportHeight
,
4697 "glInvalidateFramebuffer");
4702 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4703 GLsizei numAttachments
,
4704 const GLenum
*attachments
)
4706 struct gl_framebuffer
*fb
;
4707 GET_CURRENT_CONTEXT(ctx
);
4709 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4710 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4711 * default draw framebuffer is affected."
4714 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4715 "glInvalidateNamedFramebufferData");
4720 fb
= ctx
->WinSysDrawBuffer
;
4722 /* The GL_ARB_invalidate_subdata spec says:
4726 * void InvalidateFramebuffer(enum target,
4727 * sizei numAttachments,
4728 * const enum *attachments);
4730 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4731 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4732 * <MAX_VIEWPORT_DIMS[1]> respectively."
4734 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4736 ctx
->Const
.MaxViewportWidth
,
4737 ctx
->Const
.MaxViewportHeight
,
4738 "glInvalidateNamedFramebufferData");
4743 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4744 const GLenum
*attachments
)
4746 struct gl_framebuffer
*fb
;
4749 GET_CURRENT_CONTEXT(ctx
);
4751 fb
= get_framebuffer_target(ctx
, target
);
4753 _mesa_error(ctx
, GL_INVALID_ENUM
,
4754 "glDiscardFramebufferEXT(target %s)",
4755 _mesa_enum_to_string(target
));
4759 if (numAttachments
< 0) {
4760 _mesa_error(ctx
, GL_INVALID_VALUE
,
4761 "glDiscardFramebufferEXT(numAttachments < 0)");
4765 for (i
= 0; i
< numAttachments
; i
++) {
4766 switch (attachments
[i
]) {
4770 if (_mesa_is_user_fbo(fb
))
4773 case GL_COLOR_ATTACHMENT0
:
4774 case GL_DEPTH_ATTACHMENT
:
4775 case GL_STENCIL_ATTACHMENT
:
4776 if (_mesa_is_winsys_fbo(fb
))
4784 if (ctx
->Driver
.DiscardFramebuffer
)
4785 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4790 _mesa_error(ctx
, GL_INVALID_ENUM
,
4791 "glDiscardFramebufferEXT(attachment %s)",
4792 _mesa_enum_to_string(attachments
[i
]));
4796 sample_locations(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
4797 GLuint start
, GLsizei count
, const GLfloat
*v
, bool no_error
,
4803 if (!ctx
->Extensions
.ARB_sample_locations
) {
4804 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4806 "(ARB_sample_locations not available)", name
);
4810 if (start
+ count
> MAX_SAMPLE_LOCATION_TABLE_SIZE
) {
4811 _mesa_error(ctx
, GL_INVALID_VALUE
,
4812 "%s(start+size > sample location table size)", name
);
4817 if (!fb
->SampleLocationTable
) {
4818 size_t size
= MAX_SAMPLE_LOCATION_TABLE_SIZE
* 2 * sizeof(GLfloat
);
4819 fb
->SampleLocationTable
= malloc(size
);
4820 if (!fb
->SampleLocationTable
) {
4821 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4822 "Cannot allocate sample location table");
4825 for (i
= 0; i
< MAX_SAMPLE_LOCATION_TABLE_SIZE
* 2; i
++)
4826 fb
->SampleLocationTable
[i
] = 0.5f
;
4829 for (i
= 0; i
< count
* 2; i
++) {
4830 /* The ARB_sample_locations spec says:
4832 * Sample locations outside of [0,1] result in undefined
4835 * To simplify driver implementations, we choose to clamp to
4836 * [0,1] and change NaN into 0.5.
4838 if (isnan(v
[i
]) || v
[i
] < 0.0f
|| v
[i
] > 1.0f
) {
4839 static GLuint msg_id
= 0;
4840 static const char* msg
= "Invalid sample location specified";
4841 _mesa_debug_get_id(&msg_id
);
4843 _mesa_log_msg(ctx
, MESA_DEBUG_SOURCE_API
, MESA_DEBUG_TYPE_UNDEFINED
,
4844 msg_id
, MESA_DEBUG_SEVERITY_HIGH
, strlen(msg
), msg
);
4848 fb
->SampleLocationTable
[start
* 2 + i
] = 0.5f
;
4850 fb
->SampleLocationTable
[start
* 2 + i
] = CLAMP(v
[i
], 0.0f
, 1.0f
);
4853 if (fb
== ctx
->DrawBuffer
)
4854 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
4858 _mesa_FramebufferSampleLocationsfvARB(GLenum target
, GLuint start
,
4859 GLsizei count
, const GLfloat
*v
)
4861 struct gl_framebuffer
*fb
;
4863 GET_CURRENT_CONTEXT(ctx
);
4865 fb
= get_framebuffer_target(ctx
, target
);
4867 _mesa_error(ctx
, GL_INVALID_ENUM
,
4868 "glFramebufferSampleLocationsfvARB(target %s)",
4869 _mesa_enum_to_string(target
));
4873 sample_locations(ctx
, fb
, start
, count
, v
, false,
4874 "glFramebufferSampleLocationsfvARB");
4878 _mesa_NamedFramebufferSampleLocationsfvARB(GLuint framebuffer
, GLuint start
,
4879 GLsizei count
, const GLfloat
*v
)
4881 struct gl_framebuffer
*fb
;
4883 GET_CURRENT_CONTEXT(ctx
);
4886 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4887 "glNamedFramebufferSampleLocationsfvARB");
4892 fb
= ctx
->WinSysDrawBuffer
;
4894 sample_locations(ctx
, fb
, start
, count
, v
, false,
4895 "glNamedFramebufferSampleLocationsfvARB");
4899 _mesa_FramebufferSampleLocationsfvARB_no_error(GLenum target
, GLuint start
,
4900 GLsizei count
, const GLfloat
*v
)
4902 GET_CURRENT_CONTEXT(ctx
);
4903 sample_locations(ctx
, get_framebuffer_target(ctx
, target
), start
,
4904 count
, v
, true, "glFramebufferSampleLocationsfvARB");
4908 _mesa_NamedFramebufferSampleLocationsfvARB_no_error(GLuint framebuffer
,
4909 GLuint start
, GLsizei count
,
4912 GET_CURRENT_CONTEXT(ctx
);
4913 sample_locations(ctx
, _mesa_lookup_framebuffer(ctx
, framebuffer
), start
,
4914 count
, v
, true, "glNamedFramebufferSampleLocationsfvARB");
4918 _mesa_EvaluateDepthValuesARB(void)
4920 GET_CURRENT_CONTEXT(ctx
);
4922 if (!ctx
->Extensions
.ARB_sample_locations
) {
4923 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4924 "EvaluateDepthValuesARB not supported (neither "
4925 "ARB_sample_locations nor NV_sample_locations is available)");
4929 if (ctx
->Driver
.EvaluateDepthValues
)
4930 ctx
->Driver
.EvaluateDepthValues(ctx
);