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
) {
735 return _mesa_has_EXT_render_snorm(ctx
);
738 case GL_RGBA16_SNORM
:
739 return _mesa_has_EXT_texture_norm16(ctx
) &&
740 _mesa_has_EXT_render_snorm(ctx
);
758 if (internalFormat
!= GL_RGB10_A2
&&
759 (format
== MESA_FORMAT_B10G10R10A2_UNORM
||
760 format
== MESA_FORMAT_B10G10R10X2_UNORM
||
761 format
== MESA_FORMAT_R10G10B10A2_UNORM
||
762 format
== MESA_FORMAT_R10G10B10X2_UNORM
)) {
771 * Is the given base format a legal format for a depth/stencil renderbuffer?
774 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
776 switch (baseFormat
) {
777 case GL_DEPTH_COMPONENT
:
778 case GL_DEPTH_STENCIL_EXT
:
787 * Test if an attachment point is complete and update its Complete field.
788 * \param format if GL_COLOR, this is a color attachment point,
789 * if GL_DEPTH, this is a depth component attachment point,
790 * if GL_STENCIL, this is a stencil component attachment point.
793 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
794 struct gl_renderbuffer_attachment
*att
)
796 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
798 /* assume complete */
799 att
->Complete
= GL_TRUE
;
801 /* Look for reasons why the attachment might be incomplete */
802 if (att
->Type
== GL_TEXTURE
) {
803 const struct gl_texture_object
*texObj
= att
->Texture
;
804 const struct gl_texture_image
*texImage
;
808 att_incomplete("no texobj");
809 att
->Complete
= GL_FALSE
;
813 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
815 att_incomplete("no teximage");
816 att
->Complete
= GL_FALSE
;
819 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
820 att_incomplete("teximage width/height=0");
821 att
->Complete
= GL_FALSE
;
825 switch (texObj
->Target
) {
827 if (att
->Zoffset
>= texImage
->Depth
) {
828 att_incomplete("bad z offset");
829 att
->Complete
= GL_FALSE
;
833 case GL_TEXTURE_1D_ARRAY
:
834 if (att
->Zoffset
>= texImage
->Height
) {
835 att_incomplete("bad 1D-array layer");
836 att
->Complete
= GL_FALSE
;
840 case GL_TEXTURE_2D_ARRAY
:
841 if (att
->Zoffset
>= texImage
->Depth
) {
842 att_incomplete("bad 2D-array layer");
843 att
->Complete
= GL_FALSE
;
847 case GL_TEXTURE_CUBE_MAP_ARRAY
:
848 if (att
->Zoffset
>= texImage
->Depth
) {
849 att_incomplete("bad cube-array layer");
850 att
->Complete
= GL_FALSE
;
856 baseFormat
= texImage
->_BaseFormat
;
858 if (format
== GL_COLOR
) {
859 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
860 att_incomplete("bad format");
861 att
->Complete
= GL_FALSE
;
864 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
865 att_incomplete("compressed internalformat");
866 att
->Complete
= GL_FALSE
;
870 /* OES_texture_float allows creation and use of floating point
871 * textures with GL_FLOAT, GL_HALF_FLOAT but it does not allow
872 * these textures to be used as a render target, this is done via
873 * GL_EXT_color_buffer(_half)_float with set of new sized types.
875 if (_mesa_is_gles(ctx
) && (texObj
->_IsFloat
|| texObj
->_IsHalfFloat
)) {
876 att_incomplete("bad internal format");
877 att
->Complete
= GL_FALSE
;
881 else if (format
== GL_DEPTH
) {
882 if (baseFormat
== GL_DEPTH_COMPONENT
) {
885 else if (ctx
->Extensions
.ARB_depth_texture
&&
886 baseFormat
== GL_DEPTH_STENCIL
) {
890 att
->Complete
= GL_FALSE
;
891 att_incomplete("bad depth format");
896 assert(format
== GL_STENCIL
);
897 if (ctx
->Extensions
.ARB_depth_texture
&&
898 baseFormat
== GL_DEPTH_STENCIL
) {
900 } else if (ctx
->Extensions
.ARB_texture_stencil8
&&
901 baseFormat
== GL_STENCIL_INDEX
) {
904 /* no such thing as stencil-only textures */
905 att_incomplete("illegal stencil texture");
906 att
->Complete
= GL_FALSE
;
911 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
912 const GLenum baseFormat
= att
->Renderbuffer
->_BaseFormat
;
914 assert(att
->Renderbuffer
);
915 if (!att
->Renderbuffer
->InternalFormat
||
916 att
->Renderbuffer
->Width
< 1 ||
917 att
->Renderbuffer
->Height
< 1) {
918 att_incomplete("0x0 renderbuffer");
919 att
->Complete
= GL_FALSE
;
922 if (format
== GL_COLOR
) {
923 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
924 att_incomplete("bad renderbuffer color format");
925 att
->Complete
= GL_FALSE
;
929 else if (format
== GL_DEPTH
) {
930 if (baseFormat
== GL_DEPTH_COMPONENT
) {
933 else if (baseFormat
== GL_DEPTH_STENCIL
) {
937 att_incomplete("bad renderbuffer depth format");
938 att
->Complete
= GL_FALSE
;
943 assert(format
== GL_STENCIL
);
944 if (baseFormat
== GL_STENCIL_INDEX
||
945 baseFormat
== GL_DEPTH_STENCIL
) {
949 att
->Complete
= GL_FALSE
;
950 att_incomplete("bad renderbuffer stencil format");
956 assert(att
->Type
== GL_NONE
);
964 * Test if the given framebuffer object is complete and update its
965 * Status field with the results.
966 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
967 * driver to make hardware-specific validation/completeness checks.
968 * Also update the framebuffer's Width and Height fields if the
969 * framebuffer is complete.
972 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
973 struct gl_framebuffer
*fb
)
976 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
977 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
978 GLint numColorSamples
= -1;
979 GLint numColorStorageSamples
= -1;
980 GLint numDepthSamples
= -1;
981 GLint fixedSampleLocations
= -1;
984 /* Covers max_layer_count, is_layered, and layer_tex_target */
985 bool layer_info_valid
= false;
986 GLuint max_layer_count
= 0, att_layer_count
;
987 bool is_layered
= false;
988 GLenum layer_tex_target
= 0;
989 bool has_depth_attachment
= false;
990 bool has_stencil_attachment
= false;
992 assert(_mesa_is_user_fbo(fb
));
994 /* we're changing framebuffer fields here */
995 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1000 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
1001 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
1002 fb
->_HasAttachments
= true;
1003 fb
->_IntegerBuffers
= 0;
1005 /* Start at -2 to more easily loop over all attachment points.
1007 * -1: stencil buffer
1010 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
1011 struct gl_renderbuffer_attachment
*att
;
1013 mesa_format attFormat
;
1014 GLenum att_tex_target
= GL_NONE
;
1017 * XXX for ARB_fbo, only check color buffers that are named by
1018 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
1021 /* check for attachment completeness
1024 att
= &fb
->Attachment
[BUFFER_DEPTH
];
1025 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
1026 if (!att
->Complete
) {
1027 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1028 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
1030 } else if (att
->Type
!= GL_NONE
) {
1031 has_depth_attachment
= true;
1035 att
= &fb
->Attachment
[BUFFER_STENCIL
];
1036 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
1037 if (!att
->Complete
) {
1038 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1039 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
1041 } else if (att
->Type
!= GL_NONE
) {
1042 has_stencil_attachment
= true;
1046 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
1047 test_attachment_completeness(ctx
, GL_COLOR
, att
);
1048 if (!att
->Complete
) {
1049 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
1050 fbo_incomplete(ctx
, "color attachment incomplete", i
);
1055 /* get width, height, format of the renderbuffer/texture
1057 unsigned attNumSamples
, attNumStorageSamples
;
1059 if (att
->Type
== GL_TEXTURE
) {
1060 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
1061 att_tex_target
= att
->Texture
->Target
;
1062 minWidth
= MIN2(minWidth
, texImg
->Width
);
1063 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
1064 minHeight
= MIN2(minHeight
, texImg
->Height
);
1065 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
1066 f
= texImg
->_BaseFormat
;
1067 attFormat
= texImg
->TexFormat
;
1070 if (!is_format_color_renderable(ctx
, attFormat
,
1071 texImg
->InternalFormat
) &&
1072 !is_legal_depth_format(ctx
, f
) &&
1073 f
!= GL_STENCIL_INDEX
) {
1074 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
;
1075 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
1079 if (fixedSampleLocations
< 0)
1080 fixedSampleLocations
= texImg
->FixedSampleLocations
;
1081 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
1082 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1083 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1087 attNumSamples
= texImg
->NumSamples
;
1088 attNumStorageSamples
= texImg
->NumSamples
;
1090 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1091 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
1092 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
1093 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
1094 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
1095 f
= att
->Renderbuffer
->InternalFormat
;
1096 attFormat
= att
->Renderbuffer
->Format
;
1099 /* RENDERBUFFER has fixedSampleLocations implicitly true */
1100 if (fixedSampleLocations
< 0)
1101 fixedSampleLocations
= GL_TRUE
;
1102 else if (fixedSampleLocations
!= GL_TRUE
) {
1103 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1104 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1108 attNumSamples
= att
->Renderbuffer
->NumSamples
;
1109 attNumStorageSamples
= att
->Renderbuffer
->NumStorageSamples
;
1112 assert(att
->Type
== GL_NONE
);
1117 /* Color buffers. */
1118 if (numColorSamples
< 0) {
1119 assert(numColorStorageSamples
< 0);
1120 numColorSamples
= attNumSamples
;
1121 numColorStorageSamples
= attNumStorageSamples
;
1122 } else if (numColorSamples
!= attNumSamples
||
1123 numColorStorageSamples
!= attNumStorageSamples
) {
1124 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1125 fbo_incomplete(ctx
, "inconsistent sample counts", -1);
1129 /* Depth/stencil buffers. */
1130 if (numDepthSamples
< 0) {
1131 numDepthSamples
= attNumSamples
;
1132 } else if (numDepthSamples
!= attNumSamples
) {
1133 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1134 fbo_incomplete(ctx
, "inconsistent sample counts", -1);
1139 /* Update flags describing color buffer datatypes */
1141 GLenum type
= _mesa_get_format_datatype(attFormat
);
1143 /* check if integer color */
1144 if (_mesa_is_format_integer_color(attFormat
))
1145 fb
->_IntegerBuffers
|= (1 << i
);
1147 fb
->_AllColorBuffersFixedPoint
=
1148 fb
->_AllColorBuffersFixedPoint
&&
1149 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1151 fb
->_HasSNormOrFloatColorBuffer
=
1152 fb
->_HasSNormOrFloatColorBuffer
||
1153 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1156 /* Error-check width, height, format */
1157 if (numImages
== 1) {
1164 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1165 /* check that width, height, format are same */
1166 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1167 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1168 fbo_incomplete(ctx
, "width or height mismatch", -1);
1171 /* check that all color buffers are the same format */
1172 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1173 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1174 fbo_incomplete(ctx
, "format mismatch", -1);
1180 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1182 if (att
->Type
== GL_RENDERBUFFER
&&
1183 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1184 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1185 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1189 /* Check that layered rendering is consistent. */
1191 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1192 att_layer_count
= 6;
1193 else if (att_tex_target
== GL_TEXTURE_1D_ARRAY
)
1194 att_layer_count
= att
->Renderbuffer
->Height
;
1196 att_layer_count
= att
->Renderbuffer
->Depth
;
1198 att_layer_count
= 0;
1200 if (!layer_info_valid
) {
1201 is_layered
= att
->Layered
;
1202 max_layer_count
= att_layer_count
;
1203 layer_tex_target
= att_tex_target
;
1204 layer_info_valid
= true;
1205 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1206 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1207 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1209 } else if (is_layered
!= att
->Layered
) {
1210 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1212 "framebuffer attachment layer mode is inconsistent",
1215 } else if (att_layer_count
> max_layer_count
) {
1216 max_layer_count
= att_layer_count
;
1220 * The extension GL_ARB_framebuffer_no_attachments places additional
1221 * requirement on each attachment. Those additional requirements are
1222 * tighter that those of previous versions of GL. In interest of better
1223 * compatibility, we will not enforce these restrictions. For the record
1224 * those additional restrictions are quoted below:
1226 * "The width and height of image are greater than zero and less than or
1227 * equal to the values of the implementation-dependent limits
1228 * MAX_FRAMEBUFFER_WIDTH and MAX_FRAMEBUFFER_HEIGHT, respectively."
1230 * "If <image> is a three-dimensional texture or a one- or two-dimensional
1231 * array texture and the attachment is layered, the depth or layer count
1232 * of the texture is less than or equal to the implementation-dependent
1233 * limit MAX_FRAMEBUFFER_LAYERS."
1235 * "If image has multiple samples, its sample count is less than or equal
1236 * to the value of the implementation-dependent limit
1237 * MAX_FRAMEBUFFER_SAMPLES."
1239 * The same requirements are also in place for GL 4.5,
1240 * Section 9.4.1 "Framebuffer Attachment Completeness", pg 310-311
1244 if (ctx
->Extensions
.AMD_framebuffer_multisample_advanced
) {
1245 /* See if non-matching sample counts are supported. */
1246 if (numColorSamples
>= 0 && numDepthSamples
>= 0) {
1249 assert(numColorStorageSamples
!= -1);
1251 numColorSamples
= MAX2(numColorSamples
, 1);
1252 numColorStorageSamples
= MAX2(numColorStorageSamples
, 1);
1253 numDepthSamples
= MAX2(numDepthSamples
, 1);
1255 if (numColorSamples
== 1 && numColorStorageSamples
== 1 &&
1256 numDepthSamples
== 1) {
1259 for (i
= 0; i
< ctx
->Const
.NumSupportedMultisampleModes
; i
++) {
1261 &ctx
->Const
.SupportedMultisampleModes
[i
].NumColorSamples
;
1263 if (counts
[0] == numColorSamples
&&
1264 counts
[1] == numColorStorageSamples
&&
1265 counts
[2] == numDepthSamples
) {
1273 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1274 fbo_incomplete(ctx
, "unsupported sample counts", -1);
1279 /* If the extension is unsupported, all sample counts must be equal. */
1280 if (numColorSamples
>= 0 &&
1281 (numColorSamples
!= numColorStorageSamples
||
1282 (numDepthSamples
>= 0 && numColorSamples
!= numDepthSamples
))) {
1283 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1284 fbo_incomplete(ctx
, "inconsistent sample counts", -1);
1289 fb
->MaxNumLayers
= max_layer_count
;
1291 if (numImages
== 0) {
1292 fb
->_HasAttachments
= false;
1294 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
1295 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1296 fbo_incomplete(ctx
, "no attachments", -1);
1300 if (fb
->DefaultGeometry
.Width
== 0 || fb
->DefaultGeometry
.Height
== 0) {
1301 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1302 fbo_incomplete(ctx
, "no attachments and default width or height is 0", -1);
1307 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1308 /* Check that all DrawBuffers are present */
1309 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1310 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1311 const struct gl_renderbuffer_attachment
*att
1312 = get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
], NULL
);
1314 if (att
->Type
== GL_NONE
) {
1315 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1316 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1322 /* Check that the ReadBuffer is present */
1323 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1324 const struct gl_renderbuffer_attachment
*att
1325 = get_attachment(ctx
, fb
, fb
->ColorReadBuffer
, NULL
);
1327 if (att
->Type
== GL_NONE
) {
1328 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1329 fbo_incomplete(ctx
, "missing readbuffer", -1);
1335 /* The OpenGL ES3 spec, in chapter 9.4. FRAMEBUFFER COMPLETENESS, says:
1337 * "Depth and stencil attachments, if present, are the same image."
1339 * This restriction is not present in the OpenGL ES2 spec.
1341 if (_mesa_is_gles3(ctx
) &&
1342 has_stencil_attachment
&& has_depth_attachment
&&
1343 !_mesa_has_depthstencil_combined(fb
)) {
1344 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1345 fbo_incomplete(ctx
, "Depth and stencil attachments must be the same image", -1);
1349 /* Provisionally set status = COMPLETE ... */
1350 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1352 /* ... but the driver may say the FB is incomplete.
1353 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1356 if (ctx
->Driver
.ValidateFramebuffer
) {
1357 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1358 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1359 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1365 * Note that if ARB_framebuffer_object is supported and the attached
1366 * renderbuffers/textures are different sizes, the framebuffer
1367 * width/height will be set to the smallest width/height.
1369 if (numImages
!= 0) {
1370 fb
->Width
= minWidth
;
1371 fb
->Height
= minHeight
;
1374 /* finally, update the visual info for the framebuffer */
1375 _mesa_update_framebuffer_visual(ctx
, fb
);
1379 GLboolean GLAPIENTRY
1380 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1382 struct gl_renderbuffer
*rb
;
1384 GET_CURRENT_CONTEXT(ctx
);
1386 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1388 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1389 return rb
!= NULL
&& rb
!= &DummyRenderbuffer
;
1393 static struct gl_renderbuffer
*
1394 allocate_renderbuffer_locked(struct gl_context
*ctx
, GLuint renderbuffer
,
1397 struct gl_renderbuffer
*newRb
;
1399 /* create new renderbuffer object */
1400 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1402 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1405 assert(newRb
->AllocStorage
);
1406 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1413 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1415 struct gl_renderbuffer
*newRb
;
1416 GET_CURRENT_CONTEXT(ctx
);
1418 if (target
!= GL_RENDERBUFFER_EXT
) {
1419 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1423 /* No need to flush here since the render buffer binding has no
1424 * effect on rendering state.
1428 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1429 if (newRb
== &DummyRenderbuffer
) {
1430 /* ID was reserved, but no real renderbuffer object made yet */
1433 else if (!newRb
&& !allow_user_names
) {
1434 /* All RB IDs must be Gen'd */
1435 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1440 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1441 newRb
= allocate_renderbuffer_locked(ctx
, renderbuffer
,
1442 "glBindRenderbufferEXT");
1443 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1450 assert(newRb
!= &DummyRenderbuffer
);
1452 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1456 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1458 GET_CURRENT_CONTEXT(ctx
);
1460 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1461 * entry point, but they allow the use of user-generated names.
1463 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1467 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1469 /* This function should not be in the dispatch table for core profile /
1470 * OpenGL 3.1, so execution should never get here in those cases -- no
1471 * need for an explicit test.
1473 bind_renderbuffer(target
, renderbuffer
, true);
1477 * ARB_framebuffer_no_attachment and ARB_sample_locations - Application passes
1478 * requested param's here. NOTE: NumSamples requested need not be _NumSamples
1479 * which is what the hw supports.
1482 framebuffer_parameteri(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1483 GLenum pname
, GLint param
, const char *func
)
1485 bool cannot_be_winsys_fbo
= false;
1488 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1489 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1490 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1491 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1492 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1493 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
)
1494 goto invalid_pname_enum
;
1495 cannot_be_winsys_fbo
= true;
1497 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1498 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1499 if (!ctx
->Extensions
.ARB_sample_locations
)
1500 goto invalid_pname_enum
;
1502 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1503 if (!ctx
->Extensions
.MESA_framebuffer_flip_y
)
1504 goto invalid_pname_enum
;
1505 cannot_be_winsys_fbo
= true;
1507 goto invalid_pname_enum
;
1510 if (cannot_be_winsys_fbo
&& _mesa_is_winsys_fbo(fb
)) {
1511 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1512 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1517 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1518 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferWidth
)
1519 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1521 fb
->DefaultGeometry
.Width
= param
;
1523 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1524 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferHeight
)
1525 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1527 fb
->DefaultGeometry
.Height
= param
;
1529 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1531 * According to the OpenGL ES 3.1 specification section 9.2.1, the
1532 * GL_FRAMEBUFFER_DEFAULT_LAYERS parameter name is not supported.
1534 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1535 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1538 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferLayers
)
1539 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1541 fb
->DefaultGeometry
.Layers
= param
;
1543 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1544 if (param
< 0 || param
> ctx
->Const
.MaxFramebufferSamples
)
1545 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", func
);
1547 fb
->DefaultGeometry
.NumSamples
= param
;
1549 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1550 fb
->DefaultGeometry
.FixedSampleLocations
= param
;
1552 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1553 fb
->ProgrammableSampleLocations
= !!param
;
1555 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1556 fb
->SampleLocationPixelGrid
= !!param
;
1558 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1564 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1565 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1566 if (fb
== ctx
->DrawBuffer
)
1567 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
1570 invalidate_framebuffer(fb
);
1571 ctx
->NewState
|= _NEW_BUFFERS
;
1578 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1582 _mesa_FramebufferParameteri(GLenum target
, GLenum pname
, GLint param
)
1584 GET_CURRENT_CONTEXT(ctx
);
1585 struct gl_framebuffer
*fb
;
1587 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1588 !ctx
->Extensions
.ARB_sample_locations
) {
1589 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1590 "glFramebufferParameteriv not supported "
1591 "(neither ARB_framebuffer_no_attachments nor ARB_sample_locations"
1596 fb
= get_framebuffer_target(ctx
, target
);
1598 _mesa_error(ctx
, GL_INVALID_ENUM
,
1599 "glFramebufferParameteri(target=0x%x)", target
);
1603 framebuffer_parameteri(ctx
, fb
, pname
, param
, "glFramebufferParameteri");
1607 validate_get_framebuffer_parameteriv_pname(struct gl_context
*ctx
,
1608 struct gl_framebuffer
*fb
,
1609 GLuint pname
, const char *func
)
1611 bool cannot_be_winsys_fbo
= true;
1614 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1616 * According to the OpenGL ES 3.1 specification section 9.2.3, the
1617 * GL_FRAMEBUFFER_LAYERS parameter name is not supported.
1619 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
) {
1620 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1624 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1625 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1626 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1627 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1629 case GL_DOUBLEBUFFER
:
1630 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1631 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1633 case GL_SAMPLE_BUFFERS
:
1635 /* From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries:
1637 * "An INVALID_OPERATION error is generated by GetFramebufferParameteriv
1638 * if the default framebuffer is bound to target and pname is not one
1639 * of the accepted values from table 23.73, other than
1642 * For OpenGL ES, using default framebuffer raises INVALID_OPERATION
1645 cannot_be_winsys_fbo
= !_mesa_is_desktop_gl(ctx
);
1647 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1648 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1649 if (!ctx
->Extensions
.ARB_sample_locations
)
1650 goto invalid_pname_enum
;
1651 cannot_be_winsys_fbo
= false;
1653 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1654 if (!ctx
->Extensions
.MESA_framebuffer_flip_y
) {
1655 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1660 goto invalid_pname_enum
;
1663 if (cannot_be_winsys_fbo
&& _mesa_is_winsys_fbo(fb
)) {
1664 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1665 "%s(invalid pname=0x%x for default framebuffer)", func
, pname
);
1672 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", func
, pname
);
1677 get_framebuffer_parameteriv(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
1678 GLenum pname
, GLint
*params
, const char *func
)
1680 if (!validate_get_framebuffer_parameteriv_pname(ctx
, fb
, pname
, func
))
1684 case GL_FRAMEBUFFER_DEFAULT_WIDTH
:
1685 *params
= fb
->DefaultGeometry
.Width
;
1687 case GL_FRAMEBUFFER_DEFAULT_HEIGHT
:
1688 *params
= fb
->DefaultGeometry
.Height
;
1690 case GL_FRAMEBUFFER_DEFAULT_LAYERS
:
1691 *params
= fb
->DefaultGeometry
.Layers
;
1693 case GL_FRAMEBUFFER_DEFAULT_SAMPLES
:
1694 *params
= fb
->DefaultGeometry
.NumSamples
;
1696 case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS
:
1697 *params
= fb
->DefaultGeometry
.FixedSampleLocations
;
1699 case GL_DOUBLEBUFFER
:
1700 *params
= fb
->Visual
.doubleBufferMode
;
1702 case GL_IMPLEMENTATION_COLOR_READ_FORMAT
:
1703 *params
= _mesa_get_color_read_format(ctx
, fb
, func
);
1705 case GL_IMPLEMENTATION_COLOR_READ_TYPE
:
1706 *params
= _mesa_get_color_read_type(ctx
, fb
, func
);
1709 *params
= _mesa_geometric_samples(fb
);
1711 case GL_SAMPLE_BUFFERS
:
1712 *params
= _mesa_geometric_samples(fb
) > 0;
1715 *params
= fb
->Visual
.stereoMode
;
1717 case GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_ARB
:
1718 *params
= fb
->ProgrammableSampleLocations
;
1720 case GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_ARB
:
1721 *params
= fb
->SampleLocationPixelGrid
;
1723 case GL_FRAMEBUFFER_FLIP_Y_MESA
:
1724 *params
= fb
->FlipY
;
1730 _mesa_GetFramebufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1732 GET_CURRENT_CONTEXT(ctx
);
1733 struct gl_framebuffer
*fb
;
1735 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1736 !ctx
->Extensions
.ARB_sample_locations
) {
1737 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1738 "glGetFramebufferParameteriv not supported "
1739 "(neither ARB_framebuffer_no_attachments nor ARB_sample_locations"
1744 fb
= get_framebuffer_target(ctx
, target
);
1746 _mesa_error(ctx
, GL_INVALID_ENUM
,
1747 "glGetFramebufferParameteriv(target=0x%x)", target
);
1751 get_framebuffer_parameteriv(ctx
, fb
, pname
, params
,
1752 "glGetFramebufferParameteriv");
1757 * Remove the specified renderbuffer or texture from any attachment point in
1761 * \c true if the renderbuffer was detached from an attachment point. \c
1765 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1766 struct gl_framebuffer
*fb
,
1770 bool progress
= false;
1772 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1773 if (fb
->Attachment
[i
].Texture
== att
1774 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1775 remove_attachment(ctx
, &fb
->Attachment
[i
]);
1780 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1781 * Completeness," of the OpenGL 3.1 spec says:
1783 * "Performing any of the following actions may change whether the
1784 * framebuffer is considered complete or incomplete:
1788 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1789 * containing an image that is attached to a framebuffer object
1790 * that is bound to the framebuffer."
1793 invalidate_framebuffer(fb
);
1800 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1803 GET_CURRENT_CONTEXT(ctx
);
1806 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteRenderbuffers(n < 0)");
1810 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1812 for (i
= 0; i
< n
; i
++) {
1813 if (renderbuffers
[i
] > 0) {
1814 struct gl_renderbuffer
*rb
;
1815 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1817 /* check if deleting currently bound renderbuffer object */
1818 if (rb
== ctx
->CurrentRenderbuffer
) {
1820 assert(rb
->RefCount
>= 2);
1821 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1824 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1825 * subsection "Attaching Renderbuffer Images to a Framebuffer,"
1826 * of the OpenGL 3.1 spec says:
1828 * "If a renderbuffer object is deleted while its image is
1829 * attached to one or more attachment points in the currently
1830 * bound framebuffer, then it is as if FramebufferRenderbuffer
1831 * had been called, with a renderbuffer of 0, for each
1832 * attachment point to which this image was attached in the
1833 * currently bound framebuffer. In other words, this
1834 * renderbuffer image is first detached from all attachment
1835 * points in the currently bound framebuffer. Note that the
1836 * renderbuffer image is specifically not detached from any
1837 * non-bound framebuffers. Detaching the image from any
1838 * non-bound framebuffers is the responsibility of the
1841 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1842 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1844 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1845 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1846 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1849 /* Remove from hash table immediately, to free the ID.
1850 * But the object will not be freed until it's no longer
1851 * referenced anywhere else.
1853 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1855 if (rb
!= &DummyRenderbuffer
) {
1856 /* no longer referenced by hash table */
1857 _mesa_reference_renderbuffer(&rb
, NULL
);
1865 create_render_buffers(struct gl_context
*ctx
, GLsizei n
, GLuint
*renderbuffers
,
1868 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1875 _mesa_HashLockMutex(ctx
->Shared
->RenderBuffers
);
1877 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1879 for (i
= 0; i
< n
; i
++) {
1880 GLuint name
= first
+ i
;
1881 renderbuffers
[i
] = name
;
1884 allocate_renderbuffer_locked(ctx
, name
, func
);
1886 /* insert a dummy renderbuffer into the hash table */
1887 _mesa_HashInsertLocked(ctx
->Shared
->RenderBuffers
, name
,
1888 &DummyRenderbuffer
);
1892 _mesa_HashUnlockMutex(ctx
->Shared
->RenderBuffers
);
1897 create_render_buffers_err(struct gl_context
*ctx
, GLsizei n
,
1898 GLuint
*renderbuffers
, bool dsa
)
1900 const char *func
= dsa
? "glCreateRenderbuffers" : "glGenRenderbuffers";
1903 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n<0)", func
);
1907 create_render_buffers(ctx
, n
, renderbuffers
, dsa
);
1912 _mesa_GenRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1914 GET_CURRENT_CONTEXT(ctx
);
1915 create_render_buffers(ctx
, n
, renderbuffers
, false);
1920 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1922 GET_CURRENT_CONTEXT(ctx
);
1923 create_render_buffers_err(ctx
, n
, renderbuffers
, false);
1928 _mesa_CreateRenderbuffers_no_error(GLsizei n
, GLuint
*renderbuffers
)
1930 GET_CURRENT_CONTEXT(ctx
);
1931 create_render_buffers(ctx
, n
, renderbuffers
, true);
1936 _mesa_CreateRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1938 GET_CURRENT_CONTEXT(ctx
);
1939 create_render_buffers_err(ctx
, n
, renderbuffers
, true);
1944 * Given an internal format token for a render buffer, return the
1945 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1946 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1947 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1949 * This is similar to _mesa_base_tex_format() but the set of valid
1950 * internal formats is different.
1952 * Note that even if a format is determined to be legal here, validation
1953 * of the FBO may fail if the format is not supported by the driver/GPU.
1955 * \param internalFormat as passed to glRenderbufferStorage()
1956 * \return the base internal format, or 0 if internalFormat is illegal
1959 _mesa_base_fbo_format(const struct gl_context
*ctx
, GLenum internalFormat
)
1962 * Notes: some formats such as alpha, luminance, etc. were added
1963 * with GL_ARB_framebuffer_object.
1965 switch (internalFormat
) {
1971 return (ctx
->API
== API_OPENGL_COMPAT
&&
1972 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_ALPHA
: 0;
1976 case GL_LUMINANCE12
:
1977 case GL_LUMINANCE16
:
1978 return (ctx
->API
== API_OPENGL_COMPAT
&&
1979 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE
: 0;
1980 case GL_LUMINANCE_ALPHA
:
1981 case GL_LUMINANCE4_ALPHA4
:
1982 case GL_LUMINANCE6_ALPHA2
:
1983 case GL_LUMINANCE8_ALPHA8
:
1984 case GL_LUMINANCE12_ALPHA4
:
1985 case GL_LUMINANCE12_ALPHA12
:
1986 case GL_LUMINANCE16_ALPHA16
:
1987 return (ctx
->API
== API_OPENGL_COMPAT
&&
1988 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_LUMINANCE_ALPHA
: 0;
1992 case GL_INTENSITY12
:
1993 case GL_INTENSITY16
:
1994 return (ctx
->API
== API_OPENGL_COMPAT
&&
1995 ctx
->Extensions
.ARB_framebuffer_object
) ? GL_INTENSITY
: 0;
2005 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
2007 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
2015 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
2017 return _mesa_is_desktop_gl(ctx
) || _mesa_has_EXT_texture_norm16(ctx
)
2020 case GL_SRGB8_ALPHA8_EXT
:
2021 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2022 case GL_STENCIL_INDEX
:
2023 case GL_STENCIL_INDEX1_EXT
:
2024 case GL_STENCIL_INDEX4_EXT
:
2025 case GL_STENCIL_INDEX16_EXT
:
2026 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
2027 * OpenGL ES, but Mesa does not currently support them.
2029 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
2030 case GL_STENCIL_INDEX8_EXT
:
2031 return GL_STENCIL_INDEX
;
2032 case GL_DEPTH_COMPONENT
:
2033 case GL_DEPTH_COMPONENT32
:
2034 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
2035 case GL_DEPTH_COMPONENT16
:
2036 case GL_DEPTH_COMPONENT24
:
2037 return GL_DEPTH_COMPONENT
;
2038 case GL_DEPTH_STENCIL
:
2039 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
2040 case GL_DEPTH24_STENCIL8
:
2041 return GL_DEPTH_STENCIL
;
2042 case GL_DEPTH_COMPONENT32F
:
2043 return ctx
->Version
>= 30
2044 || (ctx
->API
== API_OPENGL_COMPAT
&&
2045 ctx
->Extensions
.ARB_depth_buffer_float
)
2046 ? GL_DEPTH_COMPONENT
: 0;
2047 case GL_DEPTH32F_STENCIL8
:
2048 return ctx
->Version
>= 30
2049 || (ctx
->API
== API_OPENGL_COMPAT
&&
2050 ctx
->Extensions
.ARB_depth_buffer_float
)
2051 ? GL_DEPTH_STENCIL
: 0;
2053 return _mesa_has_ARB_texture_rg(ctx
) ? GL_RED
: 0;
2055 return _mesa_has_ARB_texture_rg(ctx
) || _mesa_has_EXT_texture_norm16(ctx
)
2058 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
2061 return _mesa_has_ARB_texture_rg(ctx
) ? GL_RG
: 0;
2063 return _mesa_has_ARB_texture_rg(ctx
) || _mesa_has_EXT_texture_norm16(ctx
)
2066 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
2068 /* signed normalized texture formats */
2070 return _mesa_has_EXT_texture_snorm(ctx
) || _mesa_has_EXT_render_snorm(ctx
)
2073 return _mesa_has_EXT_texture_snorm(ctx
) ? GL_RED
: 0;
2075 return _mesa_has_EXT_texture_snorm(ctx
) ||
2076 (_mesa_has_EXT_render_snorm(ctx
) &&
2077 _mesa_has_EXT_texture_norm16(ctx
))
2080 return _mesa_has_EXT_texture_snorm(ctx
) || _mesa_has_EXT_render_snorm(ctx
)
2083 _mesa_has_EXT_texture_snorm(ctx
) ? GL_RG
: 0;
2085 return _mesa_has_EXT_texture_snorm(ctx
) ||
2086 (_mesa_has_EXT_render_snorm(ctx
) &&
2087 _mesa_has_EXT_texture_norm16(ctx
))
2091 case GL_RGB16_SNORM
:
2092 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2094 case GL_RGBA8_SNORM
:
2095 return _mesa_has_EXT_texture_snorm(ctx
) || _mesa_has_EXT_render_snorm(ctx
)
2098 return _mesa_has_EXT_texture_snorm(ctx
) ? GL_RGBA
: 0;
2099 case GL_RGBA16_SNORM
:
2100 return _mesa_has_EXT_texture_snorm(ctx
) ||
2101 (_mesa_has_EXT_render_snorm(ctx
) &&
2102 _mesa_has_EXT_texture_norm16(ctx
))
2104 case GL_ALPHA_SNORM
:
2105 case GL_ALPHA8_SNORM
:
2106 case GL_ALPHA16_SNORM
:
2107 return ctx
->API
== API_OPENGL_COMPAT
&&
2108 ctx
->Extensions
.EXT_texture_snorm
&&
2109 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2110 case GL_LUMINANCE_SNORM
:
2111 case GL_LUMINANCE8_SNORM
:
2112 case GL_LUMINANCE16_SNORM
:
2113 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2115 case GL_LUMINANCE_ALPHA_SNORM
:
2116 case GL_LUMINANCE8_ALPHA8_SNORM
:
2117 case GL_LUMINANCE16_ALPHA16_SNORM
:
2118 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2119 ? GL_LUMINANCE_ALPHA
: 0;
2120 case GL_INTENSITY_SNORM
:
2121 case GL_INTENSITY8_SNORM
:
2122 case GL_INTENSITY16_SNORM
:
2123 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
2128 return ((_mesa_is_desktop_gl(ctx
) &&
2129 ctx
->Extensions
.ARB_texture_rg
&&
2130 ctx
->Extensions
.ARB_texture_float
) ||
2131 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2135 return ((_mesa_is_desktop_gl(ctx
) &&
2136 ctx
->Extensions
.ARB_texture_rg
&&
2137 ctx
->Extensions
.ARB_texture_float
) ||
2138 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2142 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
2146 return ((_mesa_is_desktop_gl(ctx
) &&
2147 ctx
->Extensions
.ARB_texture_float
) ||
2148 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2151 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_shared_exponent
)
2153 case GL_ALPHA16F_ARB
:
2154 case GL_ALPHA32F_ARB
:
2155 return ctx
->API
== API_OPENGL_COMPAT
&&
2156 ctx
->Extensions
.ARB_texture_float
&&
2157 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2158 case GL_LUMINANCE16F_ARB
:
2159 case GL_LUMINANCE32F_ARB
:
2160 return ctx
->API
== API_OPENGL_COMPAT
&&
2161 ctx
->Extensions
.ARB_texture_float
&&
2162 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2163 case GL_LUMINANCE_ALPHA16F_ARB
:
2164 case GL_LUMINANCE_ALPHA32F_ARB
:
2165 return ctx
->API
== API_OPENGL_COMPAT
&&
2166 ctx
->Extensions
.ARB_texture_float
&&
2167 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2168 case GL_INTENSITY16F_ARB
:
2169 case GL_INTENSITY32F_ARB
:
2170 return ctx
->API
== API_OPENGL_COMPAT
&&
2171 ctx
->Extensions
.ARB_texture_float
&&
2172 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2173 case GL_R11F_G11F_B10F
:
2174 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
2175 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
2178 case GL_RGBA8UI_EXT
:
2179 case GL_RGBA16UI_EXT
:
2180 case GL_RGBA32UI_EXT
:
2182 case GL_RGBA16I_EXT
:
2183 case GL_RGBA32I_EXT
:
2184 return ctx
->Version
>= 30
2185 || (_mesa_is_desktop_gl(ctx
) &&
2186 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
2189 case GL_RGB16UI_EXT
:
2190 case GL_RGB32UI_EXT
:
2194 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
2202 return ctx
->Version
>= 30
2203 || (_mesa_is_desktop_gl(ctx
) &&
2204 ctx
->Extensions
.ARB_texture_rg
&&
2205 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
2213 return ctx
->Version
>= 30
2214 || (_mesa_is_desktop_gl(ctx
) &&
2215 ctx
->Extensions
.ARB_texture_rg
&&
2216 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
2218 case GL_INTENSITY8I_EXT
:
2219 case GL_INTENSITY8UI_EXT
:
2220 case GL_INTENSITY16I_EXT
:
2221 case GL_INTENSITY16UI_EXT
:
2222 case GL_INTENSITY32I_EXT
:
2223 case GL_INTENSITY32UI_EXT
:
2224 return ctx
->API
== API_OPENGL_COMPAT
&&
2225 ctx
->Extensions
.EXT_texture_integer
&&
2226 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
2228 case GL_LUMINANCE8I_EXT
:
2229 case GL_LUMINANCE8UI_EXT
:
2230 case GL_LUMINANCE16I_EXT
:
2231 case GL_LUMINANCE16UI_EXT
:
2232 case GL_LUMINANCE32I_EXT
:
2233 case GL_LUMINANCE32UI_EXT
:
2234 return ctx
->API
== API_OPENGL_COMPAT
&&
2235 ctx
->Extensions
.EXT_texture_integer
&&
2236 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
2238 case GL_LUMINANCE_ALPHA8I_EXT
:
2239 case GL_LUMINANCE_ALPHA8UI_EXT
:
2240 case GL_LUMINANCE_ALPHA16I_EXT
:
2241 case GL_LUMINANCE_ALPHA16UI_EXT
:
2242 case GL_LUMINANCE_ALPHA32I_EXT
:
2243 case GL_LUMINANCE_ALPHA32UI_EXT
:
2244 return ctx
->API
== API_OPENGL_COMPAT
&&
2245 ctx
->Extensions
.EXT_texture_integer
&&
2246 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
2248 case GL_ALPHA8I_EXT
:
2249 case GL_ALPHA8UI_EXT
:
2250 case GL_ALPHA16I_EXT
:
2251 case GL_ALPHA16UI_EXT
:
2252 case GL_ALPHA32I_EXT
:
2253 case GL_ALPHA32UI_EXT
:
2254 return ctx
->API
== API_OPENGL_COMPAT
&&
2255 ctx
->Extensions
.EXT_texture_integer
&&
2256 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
2259 return (_mesa_is_desktop_gl(ctx
) &&
2260 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
2261 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
2264 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
2273 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
2276 invalidate_rb(GLuint key
, void *data
, void *userData
)
2278 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2279 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
2281 /* If this is a user-created FBO */
2282 if (_mesa_is_user_fbo(fb
)) {
2284 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2285 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2286 if (att
->Type
== GL_RENDERBUFFER
&&
2287 att
->Renderbuffer
== rb
) {
2288 /* Mark fb status as indeterminate to force re-validation */
2297 /** sentinal value, see below */
2298 #define NO_SAMPLES 1000
2301 _mesa_renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2302 GLenum internalFormat
, GLsizei width
,
2303 GLsizei height
, GLsizei samples
,
2304 GLsizei storageSamples
)
2306 const GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2308 assert(baseFormat
!= 0);
2309 assert(width
>= 0 && width
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2310 assert(height
>= 0 && height
<= (GLsizei
) ctx
->Const
.MaxRenderbufferSize
);
2311 assert(samples
!= NO_SAMPLES
);
2313 assert(samples
> 0);
2314 assert(_mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2315 internalFormat
, samples
,
2316 storageSamples
) == GL_NO_ERROR
);
2319 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2321 if (rb
->InternalFormat
== internalFormat
&&
2322 rb
->Width
== (GLuint
) width
&&
2323 rb
->Height
== (GLuint
) height
&&
2324 rb
->NumSamples
== samples
&&
2325 rb
->NumStorageSamples
== storageSamples
) {
2326 /* no change in allocation needed */
2330 /* These MUST get set by the AllocStorage func */
2331 rb
->Format
= MESA_FORMAT_NONE
;
2332 rb
->NumSamples
= samples
;
2333 rb
->NumStorageSamples
= storageSamples
;
2335 /* Now allocate the storage */
2336 assert(rb
->AllocStorage
);
2337 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
2338 /* No error - check/set fields now */
2339 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
2340 assert(rb
->Width
== (GLuint
) width
);
2341 assert(rb
->Height
== (GLuint
) height
);
2342 rb
->InternalFormat
= internalFormat
;
2343 rb
->_BaseFormat
= baseFormat
;
2344 assert(rb
->_BaseFormat
!= 0);
2347 /* Probably ran out of memory - clear the fields */
2350 rb
->Format
= MESA_FORMAT_NONE
;
2351 rb
->InternalFormat
= GL_NONE
;
2352 rb
->_BaseFormat
= GL_NONE
;
2354 rb
->NumStorageSamples
= 0;
2357 /* Invalidate the framebuffers the renderbuffer is attached in. */
2358 if (rb
->AttachedAnytime
) {
2359 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
2364 * Helper function used by renderbuffer_storage_direct() and
2365 * renderbuffer_storage_target().
2366 * samples will be NO_SAMPLES if called by a non-multisample function.
2369 renderbuffer_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
2370 GLenum internalFormat
, GLsizei width
,
2371 GLsizei height
, GLsizei samples
, GLsizei storageSamples
,
2375 GLenum sample_count_error
;
2377 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
2378 if (baseFormat
== 0) {
2379 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
2380 func
, _mesa_enum_to_string(internalFormat
));
2384 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2385 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid width %d)", func
,
2390 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
2391 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid height %d)", func
,
2396 if (samples
== NO_SAMPLES
) {
2397 /* NumSamples == 0 indicates non-multisampling */
2402 /* check the sample count;
2403 * note: driver may choose to use more samples than what's requested
2405 sample_count_error
= _mesa_check_sample_count(ctx
, GL_RENDERBUFFER
,
2406 internalFormat
, samples
, storageSamples
);
2408 /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
2410 * "If a negative number is provided where an argument of type sizei or
2411 * sizeiptr is specified, the error INVALID VALUE is generated."
2413 if (samples
< 0 || storageSamples
< 0) {
2414 sample_count_error
= GL_INVALID_VALUE
;
2417 if (sample_count_error
!= GL_NO_ERROR
) {
2418 _mesa_error(ctx
, sample_count_error
,
2419 "%s(samples=%d, storageSamples=%d)", func
, samples
,
2425 _mesa_renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
,
2430 * Helper function used by _mesa_NamedRenderbufferStorage*().
2431 * samples will be NO_SAMPLES if called by a non-multisample function.
2434 renderbuffer_storage_named(GLuint renderbuffer
, GLenum internalFormat
,
2435 GLsizei width
, GLsizei height
, GLsizei samples
,
2436 GLsizei storageSamples
, const char *func
)
2438 GET_CURRENT_CONTEXT(ctx
);
2440 if (MESA_VERBOSE
& VERBOSE_API
) {
2441 if (samples
== NO_SAMPLES
)
2442 _mesa_debug(ctx
, "%s(%u, %s, %d, %d)\n",
2444 _mesa_enum_to_string(internalFormat
),
2447 _mesa_debug(ctx
, "%s(%u, %s, %d, %d, %d)\n",
2449 _mesa_enum_to_string(internalFormat
),
2450 width
, height
, samples
);
2453 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2454 if (!rb
|| rb
== &DummyRenderbuffer
) {
2455 /* ID was reserved, but no real renderbuffer object made yet */
2456 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid renderbuffer %u)",
2457 func
, renderbuffer
);
2461 renderbuffer_storage(ctx
, rb
, internalFormat
, width
, height
, samples
,
2462 storageSamples
, func
);
2466 * Helper function used by _mesa_RenderbufferStorage() and
2467 * _mesa_RenderbufferStorageMultisample().
2468 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
2471 renderbuffer_storage_target(GLenum target
, GLenum internalFormat
,
2472 GLsizei width
, GLsizei height
, GLsizei samples
,
2473 GLsizei storageSamples
, const char *func
)
2475 GET_CURRENT_CONTEXT(ctx
);
2477 if (MESA_VERBOSE
& VERBOSE_API
) {
2478 if (samples
== NO_SAMPLES
)
2479 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
2481 _mesa_enum_to_string(target
),
2482 _mesa_enum_to_string(internalFormat
),
2485 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
2487 _mesa_enum_to_string(target
),
2488 _mesa_enum_to_string(internalFormat
),
2489 width
, height
, samples
);
2492 if (target
!= GL_RENDERBUFFER_EXT
) {
2493 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
2497 if (!ctx
->CurrentRenderbuffer
) {
2498 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no renderbuffer bound)",
2503 renderbuffer_storage(ctx
, ctx
->CurrentRenderbuffer
, internalFormat
, width
,
2504 height
, samples
, storageSamples
, func
);
2509 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
2511 struct gl_renderbuffer
*rb
;
2512 GET_CURRENT_CONTEXT(ctx
);
2514 if (!ctx
->Extensions
.OES_EGL_image
) {
2515 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2516 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
2520 if (target
!= GL_RENDERBUFFER
) {
2521 _mesa_error(ctx
, GL_INVALID_ENUM
,
2522 "EGLImageTargetRenderbufferStorageOES");
2526 rb
= ctx
->CurrentRenderbuffer
;
2528 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2529 "EGLImageTargetRenderbufferStorageOES");
2533 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2535 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
2540 * Helper function for _mesa_GetRenderbufferParameteriv() and
2541 * _mesa_GetFramebufferAttachmentParameteriv()
2542 * We have to be careful to respect the base format. For example, if a
2543 * renderbuffer/texture was created with internalFormat=GL_RGB but the
2544 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
2545 * we need to return zero.
2548 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
2550 if (_mesa_base_format_has_channel(baseFormat
, pname
))
2551 return _mesa_get_format_bits(format
, pname
);
2559 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
2560 GLsizei width
, GLsizei height
)
2562 /* GL_ARB_fbo says calling this function is equivalent to calling
2563 * glRenderbufferStorageMultisample() with samples=0. We pass in
2564 * a token value here just for error reporting purposes.
2566 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2567 NO_SAMPLES
, 0, "glRenderbufferStorage");
2572 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
2573 GLenum internalFormat
,
2574 GLsizei width
, GLsizei height
)
2576 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2578 "glRenderbufferStorageMultisample");
2583 _mesa_RenderbufferStorageMultisampleAdvancedAMD(
2584 GLenum target
, GLsizei samples
, GLsizei storageSamples
,
2585 GLenum internalFormat
, GLsizei width
, GLsizei height
)
2587 renderbuffer_storage_target(target
, internalFormat
, width
, height
,
2588 samples
, storageSamples
,
2589 "glRenderbufferStorageMultisampleAdvancedAMD");
2594 * OpenGL ES version of glRenderBufferStorage.
2597 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
2598 GLsizei width
, GLsizei height
)
2600 switch (internalFormat
) {
2602 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
2603 /* choose a closest format */
2604 internalFormat
= GL_RGB5
;
2610 renderbuffer_storage_target(target
, internalFormat
, width
, height
, 0, 0,
2611 "glRenderbufferStorageEXT");
2615 _mesa_NamedRenderbufferStorage(GLuint renderbuffer
, GLenum internalformat
,
2616 GLsizei width
, GLsizei height
)
2618 /* GL_ARB_fbo says calling this function is equivalent to calling
2619 * glRenderbufferStorageMultisample() with samples=0. We pass in
2620 * a token value here just for error reporting purposes.
2622 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2623 NO_SAMPLES
, 0, "glNamedRenderbufferStorage");
2627 _mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer
, GLsizei samples
,
2628 GLenum internalformat
,
2629 GLsizei width
, GLsizei height
)
2631 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2633 "glNamedRenderbufferStorageMultisample");
2638 _mesa_NamedRenderbufferStorageMultisampleAdvancedAMD(
2639 GLuint renderbuffer
, GLsizei samples
, GLsizei storageSamples
,
2640 GLenum internalformat
, GLsizei width
, GLsizei height
)
2642 renderbuffer_storage_named(renderbuffer
, internalformat
, width
, height
,
2643 samples
, storageSamples
,
2644 "glNamedRenderbufferStorageMultisampleAdvancedAMD");
2649 get_render_buffer_parameteriv(struct gl_context
*ctx
,
2650 struct gl_renderbuffer
*rb
, GLenum pname
,
2651 GLint
*params
, const char *func
)
2653 /* No need to flush here since we're just quering state which is
2654 * not effected by rendering.
2658 case GL_RENDERBUFFER_WIDTH_EXT
:
2659 *params
= rb
->Width
;
2661 case GL_RENDERBUFFER_HEIGHT_EXT
:
2662 *params
= rb
->Height
;
2664 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
2665 *params
= rb
->InternalFormat
;
2667 case GL_RENDERBUFFER_RED_SIZE_EXT
:
2668 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
2669 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
2670 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
2671 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
2672 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
2673 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
2675 case GL_RENDERBUFFER_SAMPLES
:
2676 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
2677 || _mesa_is_gles3(ctx
)) {
2678 *params
= rb
->NumSamples
;
2682 case GL_RENDERBUFFER_STORAGE_SAMPLES_AMD
:
2683 if (ctx
->Extensions
.AMD_framebuffer_multisample_advanced
) {
2684 *params
= rb
->NumStorageSamples
;
2690 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname=%s)", func
,
2691 _mesa_enum_to_string(pname
));
2696 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2698 GET_CURRENT_CONTEXT(ctx
);
2700 if (target
!= GL_RENDERBUFFER_EXT
) {
2701 _mesa_error(ctx
, GL_INVALID_ENUM
,
2702 "glGetRenderbufferParameterivEXT(target)");
2706 if (!ctx
->CurrentRenderbuffer
) {
2707 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetRenderbufferParameterivEXT"
2708 "(no renderbuffer bound)");
2712 get_render_buffer_parameteriv(ctx
, ctx
->CurrentRenderbuffer
, pname
,
2713 params
, "glGetRenderbufferParameteriv");
2718 _mesa_GetNamedRenderbufferParameteriv(GLuint renderbuffer
, GLenum pname
,
2721 GET_CURRENT_CONTEXT(ctx
);
2723 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2724 if (!rb
|| rb
== &DummyRenderbuffer
) {
2725 /* ID was reserved, but no real renderbuffer object made yet */
2726 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetNamedRenderbufferParameteriv"
2727 "(invalid renderbuffer %i)", renderbuffer
);
2731 get_render_buffer_parameteriv(ctx
, rb
, pname
, params
,
2732 "glGetNamedRenderbufferParameteriv");
2736 GLboolean GLAPIENTRY
2737 _mesa_IsFramebuffer(GLuint framebuffer
)
2739 GET_CURRENT_CONTEXT(ctx
);
2740 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2742 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2743 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
2751 * Check if any of the attachments of the given framebuffer are textures
2752 * (render to texture). Call ctx->Driver.RenderTexture() for such
2756 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2759 assert(ctx
->Driver
.RenderTexture
);
2761 if (_mesa_is_winsys_fbo(fb
))
2762 return; /* can't render to texture with winsys framebuffers */
2764 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2765 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2766 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2767 && driver_RenderTexture_is_safe(att
)) {
2768 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2775 * Examine all the framebuffer's attachments to see if any are textures.
2776 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2777 * notify the device driver that the texture image may have changed.
2780 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2782 /* Skip if we know NeedsFinishRenderTexture won't be set. */
2783 if (_mesa_is_winsys_fbo(fb
) && !ctx
->Driver
.BindRenderbufferTexImage
)
2786 if (ctx
->Driver
.FinishRenderTexture
) {
2788 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2789 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2790 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2791 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2792 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2800 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2802 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2803 GLboolean bindReadBuf
, bindDrawBuf
;
2804 GET_CURRENT_CONTEXT(ctx
);
2807 case GL_DRAW_FRAMEBUFFER_EXT
:
2808 bindDrawBuf
= GL_TRUE
;
2809 bindReadBuf
= GL_FALSE
;
2811 case GL_READ_FRAMEBUFFER_EXT
:
2812 bindDrawBuf
= GL_FALSE
;
2813 bindReadBuf
= GL_TRUE
;
2815 case GL_FRAMEBUFFER_EXT
:
2816 bindDrawBuf
= GL_TRUE
;
2817 bindReadBuf
= GL_TRUE
;
2820 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2825 /* Binding a user-created framebuffer object */
2826 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2827 if (newDrawFb
== &DummyFramebuffer
) {
2828 /* ID was reserved, but no real framebuffer object made yet */
2831 else if (!newDrawFb
&& !allow_user_names
) {
2832 /* All FBO IDs must be Gen'd */
2833 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2838 /* create new framebuffer object */
2839 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2841 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2844 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2846 newReadFb
= newDrawFb
;
2849 /* Binding the window system framebuffer (which was originally set
2850 * with MakeCurrent).
2852 newDrawFb
= ctx
->WinSysDrawBuffer
;
2853 newReadFb
= ctx
->WinSysReadBuffer
;
2856 _mesa_bind_framebuffers(ctx
,
2857 bindDrawBuf
? newDrawFb
: ctx
->DrawBuffer
,
2858 bindReadBuf
? newReadFb
: ctx
->ReadBuffer
);
2862 _mesa_bind_framebuffers(struct gl_context
*ctx
,
2863 struct gl_framebuffer
*newDrawFb
,
2864 struct gl_framebuffer
*newReadFb
)
2866 struct gl_framebuffer
*const oldDrawFb
= ctx
->DrawBuffer
;
2867 struct gl_framebuffer
*const oldReadFb
= ctx
->ReadBuffer
;
2868 const bool bindDrawBuf
= oldDrawFb
!= newDrawFb
;
2869 const bool bindReadBuf
= oldReadFb
!= newReadFb
;
2872 assert(newDrawFb
!= &DummyFramebuffer
);
2875 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2877 * We also check if we're beginning and/or ending render-to-texture.
2878 * When a framebuffer with texture attachments is unbound, call
2879 * ctx->Driver.FinishRenderTexture().
2880 * When a framebuffer with texture attachments is bound, call
2881 * ctx->Driver.RenderTexture().
2883 * Note that if the ReadBuffer has texture attachments we don't consider
2884 * that a render-to-texture case.
2887 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2889 /* check if old readbuffer was render-to-texture */
2890 check_end_texture_render(ctx
, oldReadFb
);
2892 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2896 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2897 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
2899 /* check if old framebuffer had any texture attachments */
2901 check_end_texture_render(ctx
, oldDrawFb
);
2903 /* check if newly bound framebuffer has any texture attachments */
2904 check_begin_texture_render(ctx
, newDrawFb
);
2906 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2909 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2910 /* The few classic drivers that actually hook this function really only
2911 * want to know if the draw framebuffer changed.
2913 ctx
->Driver
.BindFramebuffer(ctx
,
2914 bindDrawBuf
? GL_FRAMEBUFFER
: GL_READ_FRAMEBUFFER
,
2915 newDrawFb
, newReadFb
);
2920 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2922 GET_CURRENT_CONTEXT(ctx
);
2924 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2925 * point, but they allow the use of user-generated names.
2927 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2932 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2934 /* This function should not be in the dispatch table for core profile /
2935 * OpenGL 3.1, so execution should never get here in those cases -- no
2936 * need for an explicit test.
2938 bind_framebuffer(target
, framebuffer
, true);
2943 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2946 GET_CURRENT_CONTEXT(ctx
);
2949 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteFramebuffers(n < 0)");
2953 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2955 for (i
= 0; i
< n
; i
++) {
2956 if (framebuffers
[i
] > 0) {
2957 struct gl_framebuffer
*fb
;
2958 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2960 assert(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2962 /* check if deleting currently bound framebuffer object */
2963 if (fb
== ctx
->DrawBuffer
) {
2965 assert(fb
->RefCount
>= 2);
2966 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2968 if (fb
== ctx
->ReadBuffer
) {
2970 assert(fb
->RefCount
>= 2);
2971 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2974 /* remove from hash table immediately, to free the ID */
2975 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2977 if (fb
!= &DummyFramebuffer
) {
2978 /* But the object will not be freed until it's no longer
2979 * bound in any context.
2981 _mesa_reference_framebuffer(&fb
, NULL
);
2990 * This is the implementation for glGenFramebuffers and glCreateFramebuffers.
2991 * It is not exposed to the rest of Mesa to encourage the use of
2992 * nameless buffers in driver internals.
2995 create_framebuffers(GLsizei n
, GLuint
*framebuffers
, bool dsa
)
2997 GET_CURRENT_CONTEXT(ctx
);
3000 struct gl_framebuffer
*fb
;
3002 const char *func
= dsa
? "glCreateFramebuffers" : "glGenFramebuffers";
3005 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
3012 _mesa_HashLockMutex(ctx
->Shared
->FrameBuffers
);
3014 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
3016 for (i
= 0; i
< n
; i
++) {
3017 GLuint name
= first
+ i
;
3018 framebuffers
[i
] = name
;
3021 fb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffers
[i
]);
3023 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
3024 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
3029 fb
= &DummyFramebuffer
;
3031 _mesa_HashInsertLocked(ctx
->Shared
->FrameBuffers
, name
, fb
);
3034 _mesa_HashUnlockMutex(ctx
->Shared
->FrameBuffers
);
3039 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
3041 create_framebuffers(n
, framebuffers
, false);
3046 _mesa_CreateFramebuffers(GLsizei n
, GLuint
*framebuffers
)
3048 create_framebuffers(n
, framebuffers
, true);
3053 _mesa_check_framebuffer_status(struct gl_context
*ctx
,
3054 struct gl_framebuffer
*buffer
)
3056 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
3058 if (_mesa_is_winsys_fbo(buffer
)) {
3059 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
3060 if (buffer
!= &IncompleteFramebuffer
) {
3061 return GL_FRAMEBUFFER_COMPLETE_EXT
;
3063 return GL_FRAMEBUFFER_UNDEFINED
;
3067 /* No need to flush here */
3069 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
3070 _mesa_test_framebuffer_completeness(ctx
, buffer
);
3073 return buffer
->_Status
;
3078 _mesa_CheckFramebufferStatus_no_error(GLenum target
)
3080 GET_CURRENT_CONTEXT(ctx
);
3082 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3083 return _mesa_check_framebuffer_status(ctx
, fb
);
3088 _mesa_CheckFramebufferStatus(GLenum target
)
3090 struct gl_framebuffer
*fb
;
3091 GET_CURRENT_CONTEXT(ctx
);
3093 if (MESA_VERBOSE
& VERBOSE_API
)
3094 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
3095 _mesa_enum_to_string(target
));
3097 fb
= get_framebuffer_target(ctx
, target
);
3099 _mesa_error(ctx
, GL_INVALID_ENUM
,
3100 "glCheckFramebufferStatus(invalid target %s)",
3101 _mesa_enum_to_string(target
));
3105 return _mesa_check_framebuffer_status(ctx
, fb
);
3110 _mesa_CheckNamedFramebufferStatus(GLuint framebuffer
, GLenum target
)
3112 struct gl_framebuffer
*fb
;
3113 GET_CURRENT_CONTEXT(ctx
);
3115 /* Validate the target (for conformance's sake) and grab a reference to the
3116 * default framebuffer in case framebuffer = 0.
3117 * Section 9.4 Framebuffer Completeness of the OpenGL 4.5 core spec
3118 * (30.10.2014, PDF page 336) says:
3119 * "If framebuffer is zero, then the status of the default read or
3120 * draw framebuffer (as determined by target) is returned."
3123 case GL_DRAW_FRAMEBUFFER
:
3124 case GL_FRAMEBUFFER
:
3125 fb
= ctx
->WinSysDrawBuffer
;
3127 case GL_READ_FRAMEBUFFER
:
3128 fb
= ctx
->WinSysReadBuffer
;
3131 _mesa_error(ctx
, GL_INVALID_ENUM
,
3132 "glCheckNamedFramebufferStatus(invalid target %s)",
3133 _mesa_enum_to_string(target
));
3138 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
3139 "glCheckNamedFramebufferStatus");
3144 return _mesa_check_framebuffer_status(ctx
, fb
);
3149 * Replicate the src attachment point. Used by framebuffer_texture() when
3150 * the same texture is attached at GL_DEPTH_ATTACHMENT and
3151 * GL_STENCIL_ATTACHMENT.
3154 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
3155 gl_buffer_index dst
,
3156 gl_buffer_index src
)
3158 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
3159 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
3161 assert(src_att
->Texture
!= NULL
);
3162 assert(src_att
->Renderbuffer
!= NULL
);
3164 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
3165 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
3166 dst_att
->Type
= src_att
->Type
;
3167 dst_att
->Complete
= src_att
->Complete
;
3168 dst_att
->TextureLevel
= src_att
->TextureLevel
;
3169 dst_att
->CubeMapFace
= src_att
->CubeMapFace
;
3170 dst_att
->Zoffset
= src_att
->Zoffset
;
3171 dst_att
->Layered
= src_att
->Layered
;
3175 static struct gl_texture_object
*
3176 get_texture_for_framebuffer(struct gl_context
*ctx
, GLuint texture
)
3181 return _mesa_lookup_texture(ctx
, texture
);
3186 * Common code called by gl*FramebufferTexture*() to retrieve the correct
3187 * texture object pointer.
3189 * \param texObj where the pointer to the texture object is returned. Note
3190 * that a successful call may return texObj = NULL.
3192 * \return true if no errors, false if errors
3195 get_texture_for_framebuffer_err(struct gl_context
*ctx
, GLuint texture
,
3196 bool layered
, const char *caller
,
3197 struct gl_texture_object
**texObj
)
3199 *texObj
= NULL
; /* This will get returned if texture = 0. */
3204 *texObj
= _mesa_lookup_texture(ctx
, texture
);
3205 if (*texObj
== NULL
|| (*texObj
)->Target
== 0) {
3206 /* Can't render to a non-existent texture object.
3208 * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and
3209 * Managing Framebuffer Objects specifies a different error
3210 * depending upon the calling function (PDF pages 325-328).
3211 * *FramebufferTexture (where layered = GL_TRUE) throws invalid
3212 * value, while the other commands throw invalid operation (where
3213 * layered = GL_FALSE).
3215 const GLenum error
= layered
? GL_INVALID_VALUE
:
3216 GL_INVALID_OPERATION
;
3217 _mesa_error(ctx
, error
,
3218 "%s(non-existent texture %u)", caller
, texture
);
3227 * Common code called by gl*FramebufferTexture() to verify the texture target
3228 * and decide whether or not the attachment should truly be considered
3231 * \param layered true if attachment should be considered layered, false if
3234 * \return true if no errors, false if errors
3237 check_layered_texture_target(struct gl_context
*ctx
, GLenum target
,
3238 const char *caller
, GLboolean
*layered
)
3244 case GL_TEXTURE_1D_ARRAY_EXT
:
3245 case GL_TEXTURE_2D_ARRAY_EXT
:
3246 case GL_TEXTURE_CUBE_MAP
:
3247 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3248 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3252 case GL_TEXTURE_RECTANGLE
:
3253 case GL_TEXTURE_2D_MULTISAMPLE
:
3254 /* These texture types are valid to pass to
3255 * glFramebufferTexture(), but since they aren't layered, it
3256 * is equivalent to calling glFramebufferTexture{1D,2D}().
3258 *layered
= GL_FALSE
;
3262 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3263 "%s(invalid texture target %s)", caller
,
3264 _mesa_enum_to_string(target
));
3270 * Common code called by gl*FramebufferTextureLayer() to verify the texture
3273 * \return true if no errors, false if errors
3276 check_texture_target(struct gl_context
*ctx
, GLenum target
,
3279 /* We're being called by glFramebufferTextureLayer().
3280 * The only legal texture types for that function are 3D,
3281 * cube-map, and 1D/2D/cube-map array textures.
3283 * We don't need to check for GL_ARB_texture_cube_map_array because the
3284 * application wouldn't have been able to create a texture with a
3285 * GL_TEXTURE_CUBE_MAP_ARRAY target if the extension were not enabled.
3289 case GL_TEXTURE_1D_ARRAY
:
3290 case GL_TEXTURE_2D_ARRAY
:
3291 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3292 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3294 case GL_TEXTURE_CUBE_MAP
:
3295 /* We don't need to check the extension (GL_ARB_direct_state_access) or
3296 * GL version (4.5) for GL_TEXTURE_CUBE_MAP because DSA is always
3297 * enabled in core profile. This can be called from
3298 * _mesa_FramebufferTextureLayer in compatibility profile (OpenGL 3.0),
3299 * so we do have to check the profile.
3301 return ctx
->API
== API_OPENGL_CORE
;
3304 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3305 "%s(invalid texture target %s)", caller
,
3306 _mesa_enum_to_string(target
));
3312 * Common code called by glFramebufferTexture*D() to verify the texture
3315 * \return true if no errors, false if errors
3318 check_textarget(struct gl_context
*ctx
, int dims
, GLenum target
,
3319 GLenum textarget
, const char *caller
)
3323 switch (textarget
) {
3327 case GL_TEXTURE_1D_ARRAY
:
3328 err
= dims
!= 1 || !ctx
->Extensions
.EXT_texture_array
;
3333 case GL_TEXTURE_2D_ARRAY
:
3334 err
= dims
!= 2 || !ctx
->Extensions
.EXT_texture_array
||
3335 (_mesa_is_gles(ctx
) && ctx
->Version
< 30);
3337 case GL_TEXTURE_2D_MULTISAMPLE
:
3338 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
3340 !ctx
->Extensions
.ARB_texture_multisample
||
3341 (_mesa_is_gles(ctx
) && ctx
->Version
< 31);
3343 case GL_TEXTURE_RECTANGLE
:
3344 err
= dims
!= 2 || _mesa_is_gles(ctx
) ||
3345 !ctx
->Extensions
.NV_texture_rectangle
;
3347 case GL_TEXTURE_CUBE_MAP
:
3348 case GL_TEXTURE_CUBE_MAP_ARRAY
:
3351 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3352 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3353 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3354 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3355 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3356 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3357 err
= dims
!= 2 || !ctx
->Extensions
.ARB_texture_cube_map
;
3363 _mesa_error(ctx
, GL_INVALID_ENUM
,
3364 "%s(unknown textarget 0x%x)", caller
, textarget
);
3369 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3370 "%s(invalid textarget %s)",
3371 caller
, _mesa_enum_to_string(textarget
));
3375 /* Make sure textarget is consistent with the texture's type */
3376 err
= (target
== GL_TEXTURE_CUBE_MAP
) ?
3377 !_mesa_is_cube_face(textarget
): (target
!= textarget
);
3380 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3381 "%s(mismatched texture target)", caller
);
3390 * Common code called by gl*FramebufferTextureLayer() and
3391 * glFramebufferTexture3D() to validate the layer.
3393 * \return true if no errors, false if errors
3396 check_layer(struct gl_context
*ctx
, GLenum target
, GLint layer
,
3399 /* Page 306 (page 328 of the PDF) of the OpenGL 4.5 (Core Profile)
3402 * "An INVALID_VALUE error is generated if texture is non-zero
3403 * and layer is negative."
3406 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(layer %d < 0)", caller
, layer
);
3410 if (target
== GL_TEXTURE_3D
) {
3411 const GLuint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
3412 if (layer
>= maxSize
) {
3413 _mesa_error(ctx
, GL_INVALID_VALUE
,
3414 "%s(invalid layer %u)", caller
, layer
);
3418 else if ((target
== GL_TEXTURE_1D_ARRAY
) ||
3419 (target
== GL_TEXTURE_2D_ARRAY
) ||
3420 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
3421 (target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
3422 if (layer
>= ctx
->Const
.MaxArrayTextureLayers
) {
3423 _mesa_error(ctx
, GL_INVALID_VALUE
,
3424 "%s(layer %u >= GL_MAX_ARRAY_TEXTURE_LAYERS)",
3429 else if (target
== GL_TEXTURE_CUBE_MAP
) {
3431 _mesa_error(ctx
, GL_INVALID_VALUE
,
3432 "%s(layer %u >= 6)", caller
, layer
);
3442 * Common code called by all gl*FramebufferTexture*() entry points to verify
3445 * \return true if no errors, false if errors
3448 check_level(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
3449 GLenum target
, GLint level
, const char *caller
)
3451 /* Section 9.2.8 of the OpenGL 4.6 specification says:
3453 * "If texture refers to an immutable-format texture, level must be
3454 * greater than or equal to zero and smaller than the value of
3455 * TEXTURE_VIEW_NUM_LEVELS for texture."
3457 const int max_levels
= texObj
->Immutable
? texObj
->ImmutableLevels
:
3458 _mesa_max_texture_levels(ctx
, target
);
3460 if (level
< 0 || level
>= max_levels
) {
3461 _mesa_error(ctx
, GL_INVALID_VALUE
,
3462 "%s(invalid level %d)", caller
, level
);
3470 struct gl_renderbuffer_attachment
*
3471 _mesa_get_and_validate_attachment(struct gl_context
*ctx
,
3472 struct gl_framebuffer
*fb
,
3473 GLenum attachment
, const char *caller
)
3475 /* The window-system framebuffer object is immutable */
3476 if (_mesa_is_winsys_fbo(fb
)) {
3477 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(window-system framebuffer)",
3482 /* Not a hash lookup, so we can afford to get the attachment here. */
3483 bool is_color_attachment
;
3484 struct gl_renderbuffer_attachment
*att
=
3485 get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3487 if (is_color_attachment
) {
3488 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3489 "%s(invalid color attachment %s)", caller
,
3490 _mesa_enum_to_string(attachment
));
3492 _mesa_error(ctx
, GL_INVALID_ENUM
,
3493 "%s(invalid attachment %s)", caller
,
3494 _mesa_enum_to_string(attachment
));
3504 _mesa_framebuffer_texture(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3506 struct gl_renderbuffer_attachment
*att
,
3507 struct gl_texture_object
*texObj
, GLenum textarget
,
3508 GLint level
, GLuint layer
, GLboolean layered
)
3510 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3512 simple_mtx_lock(&fb
->Mutex
);
3514 if (attachment
== GL_DEPTH_ATTACHMENT
&&
3515 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
3516 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
3517 _mesa_tex_target_to_face(textarget
) ==
3518 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
3519 layer
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
3520 /* The texture object is already attached to the stencil attachment
3521 * point. Don't create a new renderbuffer; just reuse the stencil
3522 * attachment's. This is required to prevent a GL error in
3523 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
3525 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
3527 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
3528 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
3529 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
3530 _mesa_tex_target_to_face(textarget
) ==
3531 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
3532 layer
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
3533 /* As above, but with depth and stencil transposed. */
3534 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
3537 set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
3538 level
, layer
, layered
);
3540 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3541 /* Above we created a new renderbuffer and attached it to the
3542 * depth attachment point. Now attach it to the stencil attachment
3545 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3546 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
3551 /* Set the render-to-texture flag. We'll check this flag in
3552 * glTexImage() and friends to determine if we need to revalidate
3553 * any FBOs that might be rendering into this texture.
3554 * This flag never gets cleared since it's non-trivial to determine
3555 * when all FBOs might be done rendering to this texture. That's OK
3556 * though since it's uncommon to render to a texture then repeatedly
3557 * call glTexImage() to change images in the texture.
3559 texObj
->_RenderToTexture
= GL_TRUE
;
3562 remove_attachment(ctx
, att
);
3563 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
3564 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
3565 remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
3569 invalidate_framebuffer(fb
);
3571 simple_mtx_unlock(&fb
->Mutex
);
3576 framebuffer_texture_with_dims_no_error(GLenum target
, GLenum attachment
,
3577 GLenum textarget
, GLuint texture
,
3578 GLint level
, GLint layer
)
3580 GET_CURRENT_CONTEXT(ctx
);
3582 /* Get the framebuffer object */
3583 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3585 /* Get the texture object */
3586 struct gl_texture_object
*texObj
=
3587 get_texture_for_framebuffer(ctx
, texture
);
3589 struct gl_renderbuffer_attachment
*att
=
3590 get_attachment(ctx
, fb
, attachment
, NULL
);
3592 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3593 level
, layer
, GL_FALSE
);
3598 framebuffer_texture_with_dims(int dims
, GLenum target
,
3599 GLenum attachment
, GLenum textarget
,
3600 GLuint texture
, GLint level
, GLint layer
,
3603 GET_CURRENT_CONTEXT(ctx
);
3604 struct gl_framebuffer
*fb
;
3605 struct gl_texture_object
*texObj
;
3607 /* Get the framebuffer object */
3608 fb
= get_framebuffer_target(ctx
, target
);
3610 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
3611 _mesa_enum_to_string(target
));
3615 /* Get the texture object */
3616 if (!get_texture_for_framebuffer_err(ctx
, texture
, false, caller
, &texObj
))
3620 if (!check_textarget(ctx
, dims
, texObj
->Target
, textarget
, caller
))
3623 if ((dims
== 3) && !check_layer(ctx
, texObj
->Target
, layer
, caller
))
3626 if (!check_level(ctx
, texObj
, textarget
, level
, caller
))
3630 struct gl_renderbuffer_attachment
*att
=
3631 _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, caller
);
3635 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3636 level
, layer
, GL_FALSE
);
3641 _mesa_FramebufferTexture1D_no_error(GLenum target
, GLenum attachment
,
3642 GLenum textarget
, GLuint texture
,
3645 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3651 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
3652 GLenum textarget
, GLuint texture
, GLint level
)
3654 framebuffer_texture_with_dims(1, target
, attachment
, textarget
, texture
,
3655 level
, 0, "glFramebufferTexture1D");
3660 _mesa_FramebufferTexture2D_no_error(GLenum target
, GLenum attachment
,
3661 GLenum textarget
, GLuint texture
,
3664 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3670 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
3671 GLenum textarget
, GLuint texture
, GLint level
)
3673 framebuffer_texture_with_dims(2, target
, attachment
, textarget
, texture
,
3674 level
, 0, "glFramebufferTexture2D");
3679 _mesa_FramebufferTexture3D_no_error(GLenum target
, GLenum attachment
,
3680 GLenum textarget
, GLuint texture
,
3681 GLint level
, GLint layer
)
3683 framebuffer_texture_with_dims_no_error(target
, attachment
, textarget
,
3684 texture
, level
, layer
);
3689 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
3690 GLenum textarget
, GLuint texture
,
3691 GLint level
, GLint layer
)
3693 framebuffer_texture_with_dims(3, target
, attachment
, textarget
, texture
,
3694 level
, layer
, "glFramebufferTexture3D");
3698 static ALWAYS_INLINE
void
3699 frame_buffer_texture(GLuint framebuffer
, GLenum target
,
3700 GLenum attachment
, GLuint texture
,
3701 GLint level
, GLint layer
, const char *func
,
3702 bool dsa
, bool no_error
, bool check_layered
)
3704 GET_CURRENT_CONTEXT(ctx
);
3705 GLboolean layered
= GL_FALSE
;
3707 if (!no_error
&& check_layered
) {
3708 if (!_mesa_has_geometry_shaders(ctx
)) {
3709 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3710 "unsupported function (%s) called", func
);
3715 /* Get the framebuffer object */
3716 struct gl_framebuffer
*fb
;
3719 fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
3721 fb
= get_framebuffer_target(ctx
, target
);
3725 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
, func
);
3729 fb
= get_framebuffer_target(ctx
, target
);
3731 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)",
3732 func
, _mesa_enum_to_string(target
));
3738 /* Get the texture object and framebuffer attachment*/
3739 struct gl_renderbuffer_attachment
*att
;
3740 struct gl_texture_object
*texObj
;
3742 texObj
= get_texture_for_framebuffer(ctx
, texture
);
3743 att
= get_attachment(ctx
, fb
, attachment
, NULL
);
3745 if (!get_texture_for_framebuffer_err(ctx
, texture
, check_layered
, func
,
3749 att
= _mesa_get_and_validate_attachment(ctx
, fb
, attachment
, func
);
3754 GLenum textarget
= 0;
3756 if (check_layered
) {
3757 /* We do this regardless of no_error because this sets layered */
3758 if (!check_layered_texture_target(ctx
, texObj
->Target
, func
,
3764 if (!check_layered
) {
3765 if (!check_texture_target(ctx
, texObj
->Target
, func
))
3768 if (!check_layer(ctx
, texObj
->Target
, layer
, func
))
3772 if (!check_level(ctx
, texObj
, texObj
->Target
, level
, func
))
3776 if (!check_layered
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3777 assert(layer
>= 0 && layer
< 6);
3778 textarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ layer
;
3783 _mesa_framebuffer_texture(ctx
, fb
, attachment
, att
, texObj
, textarget
,
3784 level
, layer
, layered
);
3788 _mesa_FramebufferTextureLayer_no_error(GLenum target
, GLenum attachment
,
3789 GLuint texture
, GLint level
,
3792 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3793 "glFramebufferTextureLayer", false, true, false);
3798 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
3799 GLuint texture
, GLint level
, GLint layer
)
3801 frame_buffer_texture(0, target
, attachment
, texture
, level
, layer
,
3802 "glFramebufferTextureLayer", false, false, false);
3807 _mesa_NamedFramebufferTextureLayer_no_error(GLuint framebuffer
,
3809 GLuint texture
, GLint level
,
3812 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3813 "glNamedFramebufferTextureLayer", true, true, false);
3818 _mesa_NamedFramebufferTextureLayer(GLuint framebuffer
, GLenum attachment
,
3819 GLuint texture
, GLint level
, GLint layer
)
3821 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, layer
,
3822 "glNamedFramebufferTextureLayer", true, false, false);
3827 _mesa_FramebufferTexture_no_error(GLenum target
, GLenum attachment
,
3828 GLuint texture
, GLint level
)
3830 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3831 "glFramebufferTexture", false, true, true);
3836 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
3837 GLuint texture
, GLint level
)
3839 frame_buffer_texture(0, target
, attachment
, texture
, level
, 0,
3840 "glFramebufferTexture", false, false, true);
3844 _mesa_NamedFramebufferTexture_no_error(GLuint framebuffer
, GLenum attachment
,
3845 GLuint texture
, GLint level
)
3847 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3848 "glNamedFramebufferTexture", true, true, true);
3853 _mesa_NamedFramebufferTexture(GLuint framebuffer
, GLenum attachment
,
3854 GLuint texture
, GLint level
)
3856 frame_buffer_texture(framebuffer
, 0, attachment
, texture
, level
, 0,
3857 "glNamedFramebufferTexture", true, false, true);
3862 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
3863 struct gl_framebuffer
*fb
,
3865 struct gl_renderbuffer
*rb
)
3867 assert(!_mesa_is_winsys_fbo(fb
));
3869 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
3871 assert(ctx
->Driver
.FramebufferRenderbuffer
);
3872 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
3874 /* Some subsequent GL commands may depend on the framebuffer's visual
3875 * after the binding is updated. Update visual info now.
3877 _mesa_update_framebuffer_visual(ctx
, fb
);
3880 static ALWAYS_INLINE
void
3881 framebuffer_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
3882 GLenum attachment
, GLenum renderbuffertarget
,
3883 GLuint renderbuffer
, const char *func
, bool no_error
)
3885 struct gl_renderbuffer_attachment
*att
;
3886 struct gl_renderbuffer
*rb
;
3887 bool is_color_attachment
;
3889 if (!no_error
&& renderbuffertarget
!= GL_RENDERBUFFER
) {
3890 _mesa_error(ctx
, GL_INVALID_ENUM
,
3891 "%s(renderbuffertarget is not GL_RENDERBUFFER)", func
);
3897 rb
= _mesa_lookup_renderbuffer_err(ctx
, renderbuffer
, func
);
3901 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
3904 /* remove renderbuffer attachment */
3909 if (_mesa_is_winsys_fbo(fb
)) {
3910 /* Can't attach new renderbuffers to a window system framebuffer */
3911 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3912 "%s(window-system framebuffer)", func
);
3916 att
= get_attachment(ctx
, fb
, attachment
, &is_color_attachment
);
3919 * From OpenGL 4.5 spec, section 9.2.7 "Attaching Renderbuffer Images
3920 * to a Framebuffer":
3922 * "An INVALID_OPERATION error is generated if attachment is
3923 * COLOR_- ATTACHMENTm where m is greater than or equal to the
3924 * value of MAX_COLOR_- ATTACHMENTS ."
3926 * If we are at this point, is because the attachment is not valid, so
3927 * if is_color_attachment is true, is because of the previous reason.
3929 if (is_color_attachment
) {
3930 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3931 "%s(invalid color attachment %s)", func
,
3932 _mesa_enum_to_string(attachment
));
3934 _mesa_error(ctx
, GL_INVALID_ENUM
,
3935 "%s(invalid attachment %s)", func
,
3936 _mesa_enum_to_string(attachment
));
3942 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
3943 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
3944 /* make sure the renderbuffer is a depth/stencil format */
3945 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
3946 if (baseFormat
!= GL_DEPTH_STENCIL
) {
3947 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3948 "%s(renderbuffer is not DEPTH_STENCIL format)", func
);
3954 _mesa_framebuffer_renderbuffer(ctx
, fb
, attachment
, rb
);
3958 framebuffer_renderbuffer_error(struct gl_context
*ctx
,
3959 struct gl_framebuffer
*fb
, GLenum attachment
,
3960 GLenum renderbuffertarget
,
3961 GLuint renderbuffer
, const char *func
)
3963 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3964 renderbuffer
, func
, false);
3968 framebuffer_renderbuffer_no_error(struct gl_context
*ctx
,
3969 struct gl_framebuffer
*fb
, GLenum attachment
,
3970 GLenum renderbuffertarget
,
3971 GLuint renderbuffer
, const char *func
)
3973 framebuffer_renderbuffer(ctx
, fb
, attachment
, renderbuffertarget
,
3974 renderbuffer
, func
, true);
3978 _mesa_FramebufferRenderbuffer_no_error(GLenum target
, GLenum attachment
,
3979 GLenum renderbuffertarget
,
3980 GLuint renderbuffer
)
3982 GET_CURRENT_CONTEXT(ctx
);
3984 struct gl_framebuffer
*fb
= get_framebuffer_target(ctx
, target
);
3985 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
3986 renderbuffer
, "glFramebufferRenderbuffer");
3990 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
3991 GLenum renderbuffertarget
,
3992 GLuint renderbuffer
)
3994 struct gl_framebuffer
*fb
;
3995 GET_CURRENT_CONTEXT(ctx
);
3997 fb
= get_framebuffer_target(ctx
, target
);
3999 _mesa_error(ctx
, GL_INVALID_ENUM
,
4000 "glFramebufferRenderbuffer(invalid target %s)",
4001 _mesa_enum_to_string(target
));
4005 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
4006 renderbuffer
, "glFramebufferRenderbuffer");
4010 _mesa_NamedFramebufferRenderbuffer_no_error(GLuint framebuffer
,
4012 GLenum renderbuffertarget
,
4013 GLuint renderbuffer
)
4015 GET_CURRENT_CONTEXT(ctx
);
4017 struct gl_framebuffer
*fb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
4018 framebuffer_renderbuffer_no_error(ctx
, fb
, attachment
, renderbuffertarget
,
4020 "glNamedFramebufferRenderbuffer");
4024 _mesa_NamedFramebufferRenderbuffer(GLuint framebuffer
, GLenum attachment
,
4025 GLenum renderbuffertarget
,
4026 GLuint renderbuffer
)
4028 struct gl_framebuffer
*fb
;
4029 GET_CURRENT_CONTEXT(ctx
);
4031 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4032 "glNamedFramebufferRenderbuffer");
4036 framebuffer_renderbuffer_error(ctx
, fb
, attachment
, renderbuffertarget
,
4038 "glNamedFramebufferRenderbuffer");
4043 get_framebuffer_attachment_parameter(struct gl_context
*ctx
,
4044 struct gl_framebuffer
*buffer
,
4045 GLenum attachment
, GLenum pname
,
4046 GLint
*params
, const char *caller
)
4048 const struct gl_renderbuffer_attachment
*att
;
4049 bool is_color_attachment
= false;
4052 /* The error code for an attachment type of GL_NONE differs between APIs.
4054 * From the ES 2.0.25 specification, page 127:
4055 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
4056 * querying any other pname will generate INVALID_ENUM."
4058 * From the OpenGL 3.0 specification, page 337, or identically,
4059 * the OpenGL ES 3.0.4 specification, page 240:
4061 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
4062 * framebuffer is bound to target. In this case querying pname
4063 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
4064 * queries will generate an INVALID_OPERATION error."
4066 err
= ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 30 ?
4067 GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
4069 if (_mesa_is_winsys_fbo(buffer
)) {
4070 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
4073 * "If the framebuffer currently bound to target is zero, then
4074 * INVALID_OPERATION is generated."
4076 * The EXT_framebuffer_object spec has the same wording, and the
4077 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
4080 if ((!_mesa_is_desktop_gl(ctx
) ||
4081 !ctx
->Extensions
.ARB_framebuffer_object
)
4082 && !_mesa_is_gles3(ctx
)) {
4083 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4084 "%s(window-system framebuffer)", caller
);
4088 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
4089 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
4090 _mesa_error(ctx
, GL_INVALID_ENUM
,
4091 "%s(invalid attachment %s)", caller
,
4092 _mesa_enum_to_string(attachment
));
4096 /* The specs are not clear about how to handle
4097 * GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME with the default framebuffer,
4098 * but dEQP-GLES3 expects an INVALID_ENUM error. This has also been
4101 * https://cvs.khronos.org/bugzilla/show_bug.cgi?id=12928#c1
4102 * and https://bugs.freedesktop.org/show_bug.cgi?id=31947
4104 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
) {
4105 _mesa_error(ctx
, GL_INVALID_ENUM
,
4106 "%s(requesting GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME "
4107 "when GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
4108 "GL_FRAMEBUFFER_DEFAULT is not allowed)", caller
);
4112 /* the default / window-system FBO */
4113 att
= get_fb0_attachment(ctx
, buffer
, attachment
);
4116 /* user-created framebuffer FBO */
4117 att
= get_attachment(ctx
, buffer
, attachment
, &is_color_attachment
);
4122 * From OpenGL 4.5 spec, section 9.2.3 "Framebuffer Object Queries":
4124 * "An INVALID_OPERATION error is generated if a framebuffer object
4125 * is bound to target and attachment is COLOR_ATTACHMENTm where m is
4126 * greater than or equal to the value of MAX_COLOR_ATTACHMENTS."
4128 * If we are at this point, is because the attachment is not valid, so
4129 * if is_color_attachment is true, is because of the previous reason.
4131 if (is_color_attachment
) {
4132 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid color attachment %s)",
4133 caller
, _mesa_enum_to_string(attachment
));
4135 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", caller
,
4136 _mesa_enum_to_string(attachment
));
4141 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
4142 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
4143 if (pname
== GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
) {
4144 /* This behavior is first specified in OpenGL 4.4 specification.
4146 * From the OpenGL 4.4 spec page 275:
4147 * "This query cannot be performed for a combined depth+stencil
4148 * attachment, since it does not have a single format."
4150 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4151 "%s(GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
4152 " is invalid for depth+stencil attachment)", caller
);
4155 /* the depth and stencil attachments must point to the same buffer */
4156 depthAtt
= get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
, NULL
);
4157 stencilAtt
= get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
, NULL
);
4158 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
4159 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4160 "%s(DEPTH/STENCIL attachments differ)", caller
);
4165 /* No need to flush here */
4168 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
4169 /* From the OpenGL spec, 9.2. Binding and Managing Framebuffer Objects:
4171 * "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
4172 * either no framebuffer is bound to target; or the default framebuffer
4173 * is bound, attachment is DEPTH or STENCIL, and the number of depth or
4174 * stencil bits, respectively, is zero."
4176 * Note that we don't need explicit checks on DEPTH and STENCIL, because
4177 * on the case the spec is pointing, att->Type is already NONE, so we
4178 * just need to check att->Type.
4180 *params
= (_mesa_is_winsys_fbo(buffer
) && att
->Type
!= GL_NONE
) ?
4181 GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
4183 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
4184 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
4185 *params
= att
->Renderbuffer
->Name
;
4187 else if (att
->Type
== GL_TEXTURE
) {
4188 *params
= att
->Texture
->Name
;
4191 assert(att
->Type
== GL_NONE
);
4192 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
4195 goto invalid_pname_enum
;
4199 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
4200 if (att
->Type
== GL_TEXTURE
) {
4201 *params
= att
->TextureLevel
;
4203 else if (att
->Type
== GL_NONE
) {
4204 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4205 _mesa_enum_to_string(pname
));
4208 goto invalid_pname_enum
;
4211 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
4212 if (att
->Type
== GL_TEXTURE
) {
4213 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
4214 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
4220 else if (att
->Type
== GL_NONE
) {
4221 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4222 _mesa_enum_to_string(pname
));
4225 goto invalid_pname_enum
;
4228 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
4229 if (ctx
->API
== API_OPENGLES
) {
4230 goto invalid_pname_enum
;
4231 } else if (att
->Type
== GL_NONE
) {
4232 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4233 _mesa_enum_to_string(pname
));
4234 } else if (att
->Type
== GL_TEXTURE
) {
4235 if (att
->Texture
&& (att
->Texture
->Target
== GL_TEXTURE_3D
||
4236 att
->Texture
->Target
== GL_TEXTURE_2D_ARRAY
)) {
4237 *params
= att
->Zoffset
;
4244 goto invalid_pname_enum
;
4247 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
4248 if ((!_mesa_is_desktop_gl(ctx
) ||
4249 !ctx
->Extensions
.ARB_framebuffer_object
)
4250 && !_mesa_is_gles3(ctx
)) {
4251 goto invalid_pname_enum
;
4253 else if (att
->Type
== GL_NONE
) {
4254 if (_mesa_is_winsys_fbo(buffer
) &&
4255 (attachment
== GL_DEPTH
|| attachment
== GL_STENCIL
)) {
4256 *params
= GL_LINEAR
;
4258 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4259 _mesa_enum_to_string(pname
));
4263 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
4265 _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
4268 /* According to ARB_framebuffer_sRGB, we should return LINEAR
4269 * if the sRGB conversion is unsupported. */
4270 *params
= GL_LINEAR
;
4274 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
4275 if ((ctx
->API
!= API_OPENGL_COMPAT
||
4276 !ctx
->Extensions
.ARB_framebuffer_object
)
4277 && ctx
->API
!= API_OPENGL_CORE
4278 && !_mesa_is_gles3(ctx
)) {
4279 goto invalid_pname_enum
;
4281 else if (att
->Type
== GL_NONE
) {
4282 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4283 _mesa_enum_to_string(pname
));
4286 mesa_format format
= att
->Renderbuffer
->Format
;
4288 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
4291 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
4292 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
4293 * generate an INVALID_OPERATION error.
4295 if (_mesa_is_gles3(ctx
) &&
4296 attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
4297 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4299 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
4300 "GL_DEPTH_STENCIL_ATTACHMENT)", caller
);
4304 if (format
== MESA_FORMAT_S_UINT8
) {
4308 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
4309 /* depends on the attachment parameter */
4310 if (attachment
== GL_STENCIL_ATTACHMENT
) {
4318 *params
= _mesa_get_format_datatype(format
);
4322 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
4323 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
4324 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
4325 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
4326 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
4327 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
4328 if ((!_mesa_is_desktop_gl(ctx
) ||
4329 !ctx
->Extensions
.ARB_framebuffer_object
)
4330 && !_mesa_is_gles3(ctx
)) {
4331 goto invalid_pname_enum
;
4333 else if (att
->Texture
) {
4334 const struct gl_texture_image
*texImage
=
4335 _mesa_select_tex_image(att
->Texture
, att
->Texture
->Target
,
4338 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
4339 texImage
->TexFormat
);
4345 else if (att
->Renderbuffer
) {
4346 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
4347 att
->Renderbuffer
->Format
);
4350 assert(att
->Type
== GL_NONE
);
4351 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4352 _mesa_enum_to_string(pname
));
4355 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
4356 if (!_mesa_has_geometry_shaders(ctx
)) {
4357 goto invalid_pname_enum
;
4358 } else if (att
->Type
== GL_TEXTURE
) {
4359 *params
= att
->Layered
;
4360 } else if (att
->Type
== GL_NONE
) {
4361 _mesa_error(ctx
, err
, "%s(invalid pname %s)", caller
,
4362 _mesa_enum_to_string(pname
));
4364 goto invalid_pname_enum
;
4368 goto invalid_pname_enum
;
4374 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname %s)", caller
,
4375 _mesa_enum_to_string(pname
));
4381 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
4382 GLenum pname
, GLint
*params
)
4384 GET_CURRENT_CONTEXT(ctx
);
4385 struct gl_framebuffer
*buffer
;
4387 buffer
= get_framebuffer_target(ctx
, target
);
4389 _mesa_error(ctx
, GL_INVALID_ENUM
,
4390 "glGetFramebufferAttachmentParameteriv(invalid target %s)",
4391 _mesa_enum_to_string(target
));
4395 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4397 "glGetFramebufferAttachmentParameteriv");
4402 _mesa_GetNamedFramebufferAttachmentParameteriv(GLuint framebuffer
,
4404 GLenum pname
, GLint
*params
)
4406 GET_CURRENT_CONTEXT(ctx
);
4407 struct gl_framebuffer
*buffer
;
4410 buffer
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4411 "glGetNamedFramebufferAttachmentParameteriv");
4417 * Section 9.2 Binding and Managing Framebuffer Objects of the OpenGL
4418 * 4.5 core spec (30.10.2014, PDF page 314):
4419 * "If framebuffer is zero, then the default draw framebuffer is
4422 buffer
= ctx
->WinSysDrawBuffer
;
4425 get_framebuffer_attachment_parameter(ctx
, buffer
, attachment
, pname
,
4427 "glGetNamedFramebufferAttachmentParameteriv");
4432 _mesa_NamedFramebufferParameteri(GLuint framebuffer
, GLenum pname
,
4435 GET_CURRENT_CONTEXT(ctx
);
4436 struct gl_framebuffer
*fb
= NULL
;
4438 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
4439 !ctx
->Extensions
.ARB_sample_locations
) {
4440 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4441 "glNamedFramebufferParameteri("
4442 "neither ARB_framebuffer_no_attachments nor "
4443 "ARB_sample_locations is available)");
4448 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4449 "glNamedFramebufferParameteri");
4451 fb
= ctx
->WinSysDrawBuffer
;
4455 framebuffer_parameteri(ctx
, fb
, pname
, param
,
4456 "glNamedFramebufferParameteriv");
4462 _mesa_GetNamedFramebufferParameteriv(GLuint framebuffer
, GLenum pname
,
4465 GET_CURRENT_CONTEXT(ctx
);
4466 struct gl_framebuffer
*fb
;
4468 if (!ctx
->Extensions
.ARB_framebuffer_no_attachments
) {
4469 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4470 "glNamedFramebufferParameteriv("
4471 "neither ARB_framebuffer_no_attachments nor ARB_sample_locations"
4477 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4478 "glGetNamedFramebufferParameteriv");
4480 fb
= ctx
->WinSysDrawBuffer
;
4483 get_framebuffer_parameteriv(ctx
, fb
, pname
, param
,
4484 "glGetNamedFramebufferParameteriv");
4490 invalidate_framebuffer_storage(struct gl_context
*ctx
,
4491 struct gl_framebuffer
*fb
,
4492 GLsizei numAttachments
,
4493 const GLenum
*attachments
, GLint x
, GLint y
,
4494 GLsizei width
, GLsizei height
, const char *name
)
4498 /* Section 17.4 Whole Framebuffer Operations of the OpenGL 4.5 Core
4499 * Spec (2.2.2015, PDF page 522) says:
4500 * "An INVALID_VALUE error is generated if numAttachments, width, or
4501 * height is negative."
4503 if (numAttachments
< 0) {
4504 _mesa_error(ctx
, GL_INVALID_VALUE
,
4505 "%s(numAttachments < 0)", name
);
4510 _mesa_error(ctx
, GL_INVALID_VALUE
,
4511 "%s(width < 0)", name
);
4516 _mesa_error(ctx
, GL_INVALID_VALUE
,
4517 "%s(height < 0)", name
);
4521 /* The GL_ARB_invalidate_subdata spec says:
4523 * "If an attachment is specified that does not exist in the
4524 * framebuffer bound to <target>, it is ignored."
4528 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
4529 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
4530 * INVALID_OPERATION is generated."
4532 * No mention is made of GL_AUXi being out of range. Therefore, we allow
4533 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
4534 * set of retrictions).
4536 for (i
= 0; i
< numAttachments
; i
++) {
4537 if (_mesa_is_winsys_fbo(fb
)) {
4538 switch (attachments
[i
]) {
4544 /* Accumulation buffers and auxilary buffers were removed in
4545 * OpenGL 3.1, and they never existed in OpenGL ES.
4547 if (ctx
->API
!= API_OPENGL_COMPAT
)
4557 case GL_FRONT_RIGHT
:
4558 if (!_mesa_is_desktop_gl(ctx
))
4565 switch (attachments
[i
]) {
4566 case GL_DEPTH_ATTACHMENT
:
4567 case GL_STENCIL_ATTACHMENT
:
4569 case GL_DEPTH_STENCIL_ATTACHMENT
:
4570 /* GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point only
4571 * in desktop and ES 3.0 profiles. Note that OES_packed_depth_stencil
4572 * extension does not make this attachment point valid on ES 2.0.
4574 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
))
4577 case GL_COLOR_ATTACHMENT0
:
4578 case GL_COLOR_ATTACHMENT1
:
4579 case GL_COLOR_ATTACHMENT2
:
4580 case GL_COLOR_ATTACHMENT3
:
4581 case GL_COLOR_ATTACHMENT4
:
4582 case GL_COLOR_ATTACHMENT5
:
4583 case GL_COLOR_ATTACHMENT6
:
4584 case GL_COLOR_ATTACHMENT7
:
4585 case GL_COLOR_ATTACHMENT8
:
4586 case GL_COLOR_ATTACHMENT9
:
4587 case GL_COLOR_ATTACHMENT10
:
4588 case GL_COLOR_ATTACHMENT11
:
4589 case GL_COLOR_ATTACHMENT12
:
4590 case GL_COLOR_ATTACHMENT13
:
4591 case GL_COLOR_ATTACHMENT14
:
4592 case GL_COLOR_ATTACHMENT15
: {
4593 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
4594 if (k
>= ctx
->Const
.MaxColorAttachments
) {
4595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4596 "%s(attachment >= max. color attachments)", name
);
4607 /* We don't actually do anything for this yet. Just return after
4608 * validating the parameters and generating the required errors.
4613 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid attachment %s)", name
,
4614 _mesa_enum_to_string(attachments
[i
]));
4620 _mesa_InvalidateSubFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4621 const GLenum
*attachments
, GLint x
,
4622 GLint y
, GLsizei width
, GLsizei height
)
4629 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
4630 const GLenum
*attachments
, GLint x
, GLint y
,
4631 GLsizei width
, GLsizei height
)
4633 struct gl_framebuffer
*fb
;
4634 GET_CURRENT_CONTEXT(ctx
);
4636 fb
= get_framebuffer_target(ctx
, target
);
4638 _mesa_error(ctx
, GL_INVALID_ENUM
,
4639 "glInvalidateSubFramebuffer(invalid target %s)",
4640 _mesa_enum_to_string(target
));
4644 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4645 x
, y
, width
, height
,
4646 "glInvalidateSubFramebuffer");
4651 _mesa_InvalidateNamedFramebufferSubData(GLuint framebuffer
,
4652 GLsizei numAttachments
,
4653 const GLenum
*attachments
,
4655 GLsizei width
, GLsizei height
)
4657 struct gl_framebuffer
*fb
;
4658 GET_CURRENT_CONTEXT(ctx
);
4660 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4661 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4662 * default draw framebuffer is affected."
4665 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4666 "glInvalidateNamedFramebufferSubData");
4671 fb
= ctx
->WinSysDrawBuffer
;
4673 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4674 x
, y
, width
, height
,
4675 "glInvalidateNamedFramebufferSubData");
4680 _mesa_InvalidateFramebuffer_no_error(GLenum target
, GLsizei numAttachments
,
4681 const GLenum
*attachments
)
4688 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
4689 const GLenum
*attachments
)
4691 struct gl_framebuffer
*fb
;
4692 GET_CURRENT_CONTEXT(ctx
);
4694 fb
= get_framebuffer_target(ctx
, target
);
4696 _mesa_error(ctx
, GL_INVALID_ENUM
,
4697 "glInvalidateFramebuffer(invalid target %s)",
4698 _mesa_enum_to_string(target
));
4702 /* The GL_ARB_invalidate_subdata spec says:
4706 * void InvalidateFramebuffer(enum target,
4707 * sizei numAttachments,
4708 * const enum *attachments);
4710 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4711 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4712 * <MAX_VIEWPORT_DIMS[1]> respectively."
4714 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4716 ctx
->Const
.MaxViewportWidth
,
4717 ctx
->Const
.MaxViewportHeight
,
4718 "glInvalidateFramebuffer");
4723 _mesa_InvalidateNamedFramebufferData(GLuint framebuffer
,
4724 GLsizei numAttachments
,
4725 const GLenum
*attachments
)
4727 struct gl_framebuffer
*fb
;
4728 GET_CURRENT_CONTEXT(ctx
);
4730 /* The OpenGL 4.5 core spec (02.02.2015) says (in Section 17.4 Whole
4731 * Framebuffer Operations, PDF page 522): "If framebuffer is zero, the
4732 * default draw framebuffer is affected."
4735 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4736 "glInvalidateNamedFramebufferData");
4741 fb
= ctx
->WinSysDrawBuffer
;
4743 /* The GL_ARB_invalidate_subdata spec says:
4747 * void InvalidateFramebuffer(enum target,
4748 * sizei numAttachments,
4749 * const enum *attachments);
4751 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
4752 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
4753 * <MAX_VIEWPORT_DIMS[1]> respectively."
4755 invalidate_framebuffer_storage(ctx
, fb
, numAttachments
, attachments
,
4757 ctx
->Const
.MaxViewportWidth
,
4758 ctx
->Const
.MaxViewportHeight
,
4759 "glInvalidateNamedFramebufferData");
4764 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
4765 const GLenum
*attachments
)
4767 struct gl_framebuffer
*fb
;
4770 GET_CURRENT_CONTEXT(ctx
);
4772 fb
= get_framebuffer_target(ctx
, target
);
4774 _mesa_error(ctx
, GL_INVALID_ENUM
,
4775 "glDiscardFramebufferEXT(target %s)",
4776 _mesa_enum_to_string(target
));
4780 if (numAttachments
< 0) {
4781 _mesa_error(ctx
, GL_INVALID_VALUE
,
4782 "glDiscardFramebufferEXT(numAttachments < 0)");
4786 for (i
= 0; i
< numAttachments
; i
++) {
4787 switch (attachments
[i
]) {
4791 if (_mesa_is_user_fbo(fb
))
4794 case GL_COLOR_ATTACHMENT0
:
4795 case GL_DEPTH_ATTACHMENT
:
4796 case GL_STENCIL_ATTACHMENT
:
4797 if (_mesa_is_winsys_fbo(fb
))
4805 if (ctx
->Driver
.DiscardFramebuffer
)
4806 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
4811 _mesa_error(ctx
, GL_INVALID_ENUM
,
4812 "glDiscardFramebufferEXT(attachment %s)",
4813 _mesa_enum_to_string(attachments
[i
]));
4817 sample_locations(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
4818 GLuint start
, GLsizei count
, const GLfloat
*v
, bool no_error
,
4824 if (!ctx
->Extensions
.ARB_sample_locations
) {
4825 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4827 "(ARB_sample_locations not available)", name
);
4831 if (start
+ count
> MAX_SAMPLE_LOCATION_TABLE_SIZE
) {
4832 _mesa_error(ctx
, GL_INVALID_VALUE
,
4833 "%s(start+size > sample location table size)", name
);
4838 if (!fb
->SampleLocationTable
) {
4839 size_t size
= MAX_SAMPLE_LOCATION_TABLE_SIZE
* 2 * sizeof(GLfloat
);
4840 fb
->SampleLocationTable
= malloc(size
);
4841 if (!fb
->SampleLocationTable
) {
4842 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4843 "Cannot allocate sample location table");
4846 for (i
= 0; i
< MAX_SAMPLE_LOCATION_TABLE_SIZE
* 2; i
++)
4847 fb
->SampleLocationTable
[i
] = 0.5f
;
4850 for (i
= 0; i
< count
* 2; i
++) {
4851 /* The ARB_sample_locations spec says:
4853 * Sample locations outside of [0,1] result in undefined
4856 * To simplify driver implementations, we choose to clamp to
4857 * [0,1] and change NaN into 0.5.
4859 if (isnan(v
[i
]) || v
[i
] < 0.0f
|| v
[i
] > 1.0f
) {
4860 static GLuint msg_id
= 0;
4861 static const char* msg
= "Invalid sample location specified";
4862 _mesa_debug_get_id(&msg_id
);
4864 _mesa_log_msg(ctx
, MESA_DEBUG_SOURCE_API
, MESA_DEBUG_TYPE_UNDEFINED
,
4865 msg_id
, MESA_DEBUG_SEVERITY_HIGH
, strlen(msg
), msg
);
4869 fb
->SampleLocationTable
[start
* 2 + i
] = 0.5f
;
4871 fb
->SampleLocationTable
[start
* 2 + i
] = CLAMP(v
[i
], 0.0f
, 1.0f
);
4874 if (fb
== ctx
->DrawBuffer
)
4875 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleLocations
;
4879 _mesa_FramebufferSampleLocationsfvARB(GLenum target
, GLuint start
,
4880 GLsizei count
, const GLfloat
*v
)
4882 struct gl_framebuffer
*fb
;
4884 GET_CURRENT_CONTEXT(ctx
);
4886 fb
= get_framebuffer_target(ctx
, target
);
4888 _mesa_error(ctx
, GL_INVALID_ENUM
,
4889 "glFramebufferSampleLocationsfvARB(target %s)",
4890 _mesa_enum_to_string(target
));
4894 sample_locations(ctx
, fb
, start
, count
, v
, false,
4895 "glFramebufferSampleLocationsfvARB");
4899 _mesa_NamedFramebufferSampleLocationsfvARB(GLuint framebuffer
, GLuint start
,
4900 GLsizei count
, const GLfloat
*v
)
4902 struct gl_framebuffer
*fb
;
4904 GET_CURRENT_CONTEXT(ctx
);
4907 fb
= _mesa_lookup_framebuffer_err(ctx
, framebuffer
,
4908 "glNamedFramebufferSampleLocationsfvARB");
4913 fb
= ctx
->WinSysDrawBuffer
;
4915 sample_locations(ctx
, fb
, start
, count
, v
, false,
4916 "glNamedFramebufferSampleLocationsfvARB");
4920 _mesa_FramebufferSampleLocationsfvARB_no_error(GLenum target
, GLuint start
,
4921 GLsizei count
, const GLfloat
*v
)
4923 GET_CURRENT_CONTEXT(ctx
);
4924 sample_locations(ctx
, get_framebuffer_target(ctx
, target
), start
,
4925 count
, v
, true, "glFramebufferSampleLocationsfvARB");
4929 _mesa_NamedFramebufferSampleLocationsfvARB_no_error(GLuint framebuffer
,
4930 GLuint start
, GLsizei count
,
4933 GET_CURRENT_CONTEXT(ctx
);
4934 sample_locations(ctx
, _mesa_lookup_framebuffer(ctx
, framebuffer
), start
,
4935 count
, v
, true, "glNamedFramebufferSampleLocationsfvARB");
4939 _mesa_EvaluateDepthValuesARB(void)
4941 GET_CURRENT_CONTEXT(ctx
);
4943 if (!ctx
->Extensions
.ARB_sample_locations
) {
4944 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4945 "EvaluateDepthValuesARB not supported (neither "
4946 "ARB_sample_locations nor NV_sample_locations is available)");
4950 if (ctx
->Driver
.EvaluateDepthValues
)
4951 ctx
->Driver
.EvaluateDepthValues(ctx
);