2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
29 * GL_EXT/ARB_framebuffer_object extensions
42 #include "framebuffer.h"
43 #include "glformats.h"
46 #include "multisample.h"
48 #include "renderbuffer.h"
54 /** Set this to 1 to debug/log glBlitFramebuffer() calls */
61 * None of the GL_EXT_framebuffer_object functions are compiled into
68 * When glGenRender/FramebuffersEXT() is called we insert pointers to
69 * these placeholder objects into the hash table.
70 * Later, when the object ID is first bound, we replace the placeholder
71 * with the real frame/renderbuffer.
73 static struct gl_framebuffer DummyFramebuffer
;
74 static struct gl_renderbuffer DummyRenderbuffer
;
76 /* We bind this framebuffer when applications pass a NULL
77 * drawable/surface in make current. */
78 static struct gl_framebuffer IncompleteFramebuffer
;
82 delete_dummy_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
88 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
95 _mesa_init_fbobjects(struct gl_context
*ctx
)
97 _glthread_INIT_MUTEX(DummyFramebuffer
.Mutex
);
98 _glthread_INIT_MUTEX(DummyRenderbuffer
.Mutex
);
99 _glthread_INIT_MUTEX(IncompleteFramebuffer
.Mutex
);
100 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
101 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
102 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
105 struct gl_framebuffer
*
106 _mesa_get_incomplete_framebuffer(void)
108 return &IncompleteFramebuffer
;
112 * Helper routine for getting a gl_renderbuffer.
114 struct gl_renderbuffer
*
115 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
117 struct gl_renderbuffer
*rb
;
122 rb
= (struct gl_renderbuffer
*)
123 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
129 * Helper routine for getting a gl_framebuffer.
131 struct gl_framebuffer
*
132 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
134 struct gl_framebuffer
*fb
;
139 fb
= (struct gl_framebuffer
*)
140 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
146 * Mark the given framebuffer as invalid. This will force the
147 * test for framebuffer completeness to be done before the framebuffer
151 invalidate_framebuffer(struct gl_framebuffer
*fb
)
153 fb
->_Status
= 0; /* "indeterminate" */
158 * Return the gl_framebuffer object which corresponds to the given
159 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
160 * Check support for GL_EXT_framebuffer_blit to determine if certain
162 * \return gl_framebuffer pointer or NULL if target is illegal
164 static struct gl_framebuffer
*
165 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
167 bool have_fb_blit
= _mesa_is_gles3(ctx
) ||
168 (ctx
->Extensions
.EXT_framebuffer_blit
&& _mesa_is_desktop_gl(ctx
));
170 case GL_DRAW_FRAMEBUFFER
:
171 return have_fb_blit
? ctx
->DrawBuffer
: NULL
;
172 case GL_READ_FRAMEBUFFER
:
173 return have_fb_blit
? ctx
->ReadBuffer
: NULL
;
174 case GL_FRAMEBUFFER_EXT
:
175 return ctx
->DrawBuffer
;
183 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
184 * gl_renderbuffer_attachment object.
185 * This function is only used for user-created FB objects, not the
186 * default / window-system FB object.
187 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
188 * the depth buffer attachment point.
190 struct gl_renderbuffer_attachment
*
191 _mesa_get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
196 assert(_mesa_is_user_fbo(fb
));
198 switch (attachment
) {
199 case GL_COLOR_ATTACHMENT0_EXT
:
200 case GL_COLOR_ATTACHMENT1_EXT
:
201 case GL_COLOR_ATTACHMENT2_EXT
:
202 case GL_COLOR_ATTACHMENT3_EXT
:
203 case GL_COLOR_ATTACHMENT4_EXT
:
204 case GL_COLOR_ATTACHMENT5_EXT
:
205 case GL_COLOR_ATTACHMENT6_EXT
:
206 case GL_COLOR_ATTACHMENT7_EXT
:
207 case GL_COLOR_ATTACHMENT8_EXT
:
208 case GL_COLOR_ATTACHMENT9_EXT
:
209 case GL_COLOR_ATTACHMENT10_EXT
:
210 case GL_COLOR_ATTACHMENT11_EXT
:
211 case GL_COLOR_ATTACHMENT12_EXT
:
212 case GL_COLOR_ATTACHMENT13_EXT
:
213 case GL_COLOR_ATTACHMENT14_EXT
:
214 case GL_COLOR_ATTACHMENT15_EXT
:
215 /* Only OpenGL ES 1.x forbids color attachments other than
216 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
219 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
220 if (i
>= ctx
->Const
.MaxColorAttachments
221 || (i
> 0 && ctx
->API
== API_OPENGLES
)) {
224 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
225 case GL_DEPTH_STENCIL_ATTACHMENT
:
226 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
229 case GL_DEPTH_ATTACHMENT_EXT
:
230 return &fb
->Attachment
[BUFFER_DEPTH
];
231 case GL_STENCIL_ATTACHMENT_EXT
:
232 return &fb
->Attachment
[BUFFER_STENCIL
];
240 * As above, but only used for getting attachments of the default /
241 * window-system framebuffer (not user-created framebuffer objects).
243 static struct gl_renderbuffer_attachment
*
244 _mesa_get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
247 assert(_mesa_is_winsys_fbo(fb
));
249 if (_mesa_is_gles3(ctx
)) {
250 assert(attachment
== GL_BACK
||
251 attachment
== GL_DEPTH
||
252 attachment
== GL_STENCIL
);
253 switch (attachment
) {
255 /* Since there is no stereo rendering in ES 3.0, only return the
258 if (ctx
->DrawBuffer
->Visual
.doubleBufferMode
)
259 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
260 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
262 return &fb
->Attachment
[BUFFER_DEPTH
];
264 return &fb
->Attachment
[BUFFER_STENCIL
];
268 switch (attachment
) {
270 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
272 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
274 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
276 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
278 if (fb
->Visual
.numAuxBuffers
== 1) {
279 return &fb
->Attachment
[BUFFER_AUX0
];
283 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
285 * "If the default framebuffer is bound to target, then attachment must
286 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
287 * identifying a color buffer; DEPTH, identifying the depth buffer; or
288 * STENCIL, identifying the stencil buffer."
290 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
291 * language. However, revision #33 of the ARB_framebuffer_object spec
294 * "If the default framebuffer is bound to <target>, then <attachment>
295 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
296 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
297 * depth buffer, or the stencil buffer, and <pname> may be
298 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
299 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
301 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
302 * from glext.h, so shipping apps should not use those values.
304 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
305 * support queries of the window system FBO.
308 return &fb
->Attachment
[BUFFER_DEPTH
];
310 return &fb
->Attachment
[BUFFER_STENCIL
];
319 * Remove any texture or renderbuffer attached to the given attachment
320 * point. Update reference counts, etc.
323 _mesa_remove_attachment(struct gl_context
*ctx
,
324 struct gl_renderbuffer_attachment
*att
)
326 if (att
->Type
== GL_TEXTURE
) {
327 ASSERT(att
->Texture
);
328 if (ctx
->Driver
.FinishRenderTexture
) {
329 /* tell driver that we're done rendering to this texture. */
330 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
332 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
333 ASSERT(!att
->Texture
);
335 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
336 ASSERT(!att
->Texture
);
337 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
338 ASSERT(!att
->Renderbuffer
);
341 att
->Complete
= GL_TRUE
;
346 * Bind a texture object to an attachment point.
347 * The previous binding, if any, will be removed first.
350 _mesa_set_texture_attachment(struct gl_context
*ctx
,
351 struct gl_framebuffer
*fb
,
352 struct gl_renderbuffer_attachment
*att
,
353 struct gl_texture_object
*texObj
,
354 GLenum texTarget
, GLuint level
, GLuint zoffset
,
357 if (att
->Texture
== texObj
) {
358 /* re-attaching same texture */
359 ASSERT(att
->Type
== GL_TEXTURE
);
360 if (ctx
->Driver
.FinishRenderTexture
)
361 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
365 if (ctx
->Driver
.FinishRenderTexture
&& att
->Texture
)
366 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
367 _mesa_remove_attachment(ctx
, att
);
368 att
->Type
= GL_TEXTURE
;
369 assert(!att
->Texture
);
370 _mesa_reference_texobj(&att
->Texture
, texObj
);
373 /* always update these fields */
374 att
->TextureLevel
= level
;
375 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
376 att
->Zoffset
= zoffset
;
377 att
->Layered
= layered
;
378 att
->Complete
= GL_FALSE
;
380 if (_mesa_get_attachment_teximage(att
)) {
381 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
384 invalidate_framebuffer(fb
);
389 * Bind a renderbuffer to an attachment point.
390 * The previous binding, if any, will be removed first.
393 _mesa_set_renderbuffer_attachment(struct gl_context
*ctx
,
394 struct gl_renderbuffer_attachment
*att
,
395 struct gl_renderbuffer
*rb
)
397 /* XXX check if re-doing same attachment, exit early */
398 _mesa_remove_attachment(ctx
, att
);
399 att
->Type
= GL_RENDERBUFFER_EXT
;
400 att
->Texture
= NULL
; /* just to be safe */
401 att
->Complete
= GL_FALSE
;
402 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
407 * Fallback for ctx->Driver.FramebufferRenderbuffer()
408 * Attach a renderbuffer object to a framebuffer object.
411 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
412 struct gl_framebuffer
*fb
,
413 GLenum attachment
, struct gl_renderbuffer
*rb
)
415 struct gl_renderbuffer_attachment
*att
;
417 _glthread_LOCK_MUTEX(fb
->Mutex
);
419 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
422 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
423 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
424 /* do stencil attachment here (depth already done above) */
425 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
427 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
429 rb
->AttachedAnytime
= GL_TRUE
;
432 _mesa_remove_attachment(ctx
, att
);
435 invalidate_framebuffer(fb
);
437 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
442 * Fallback for ctx->Driver.ValidateFramebuffer()
443 * Check if the renderbuffer's formats are supported by the software
445 * Drivers should probably override this.
448 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
451 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
452 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
454 switch (rb
->_BaseFormat
) {
456 case GL_LUMINANCE_ALPHA
:
461 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
465 switch (rb
->Format
) {
466 /* XXX This list is likely incomplete. */
467 case MESA_FORMAT_RGB9_E5_FLOAT
:
468 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
471 /* render buffer format is supported by software rendering */
480 * Return true if the framebuffer has a combined depth/stencil
481 * renderbuffer attached.
484 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
486 const struct gl_renderbuffer_attachment
*depth
=
487 &fb
->Attachment
[BUFFER_DEPTH
];
488 const struct gl_renderbuffer_attachment
*stencil
=
489 &fb
->Attachment
[BUFFER_STENCIL
];
491 if (depth
->Type
== stencil
->Type
) {
492 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
493 depth
->Renderbuffer
== stencil
->Renderbuffer
)
496 if (depth
->Type
== GL_TEXTURE
&&
497 depth
->Texture
== stencil
->Texture
)
509 att_incomplete(const char *msg
)
511 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
512 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
521 fbo_incomplete(const char *msg
, int index
)
523 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
524 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
530 * Is the given base format a legal format for a color renderbuffer?
533 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
535 switch (baseFormat
) {
540 case GL_LUMINANCE_ALPHA
:
543 return ctx
->API
== API_OPENGL_COMPAT
&&
544 ctx
->Extensions
.ARB_framebuffer_object
;
547 return ctx
->Extensions
.ARB_texture_rg
;
555 * Is the given base format a legal format for a color renderbuffer?
558 is_format_color_renderable(const struct gl_context
*ctx
, gl_format format
, GLenum internalFormat
)
560 const GLenum baseFormat
=
561 _mesa_get_format_base_format(format
);
564 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
565 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
569 /* Reject additional cases for GLES */
570 switch (internalFormat
) {
590 if (format
== MESA_FORMAT_ARGB2101010
&& internalFormat
!= GL_RGB10_A2
) {
599 * Is the given base format a legal format for a depth/stencil renderbuffer?
602 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
604 switch (baseFormat
) {
605 case GL_DEPTH_COMPONENT
:
606 case GL_DEPTH_STENCIL_EXT
:
615 * Test if an attachment point is complete and update its Complete field.
616 * \param format if GL_COLOR, this is a color attachment point,
617 * if GL_DEPTH, this is a depth component attachment point,
618 * if GL_STENCIL, this is a stencil component attachment point.
621 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
622 struct gl_renderbuffer_attachment
*att
)
624 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
626 /* assume complete */
627 att
->Complete
= GL_TRUE
;
629 /* Look for reasons why the attachment might be incomplete */
630 if (att
->Type
== GL_TEXTURE
) {
631 const struct gl_texture_object
*texObj
= att
->Texture
;
632 struct gl_texture_image
*texImage
;
636 att_incomplete("no texobj");
637 att
->Complete
= GL_FALSE
;
641 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
643 att_incomplete("no teximage");
644 att
->Complete
= GL_FALSE
;
647 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
648 att_incomplete("teximage width/height=0");
649 printf("texobj = %u\n", texObj
->Name
);
650 printf("level = %d\n", att
->TextureLevel
);
651 att
->Complete
= GL_FALSE
;
654 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
655 att_incomplete("bad z offset");
656 att
->Complete
= GL_FALSE
;
660 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
662 if (format
== GL_COLOR
) {
663 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
664 att_incomplete("bad format");
665 att
->Complete
= GL_FALSE
;
668 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
669 att_incomplete("compressed internalformat");
670 att
->Complete
= GL_FALSE
;
674 else if (format
== GL_DEPTH
) {
675 if (baseFormat
== GL_DEPTH_COMPONENT
) {
678 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
679 ctx
->Extensions
.ARB_depth_texture
&&
680 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
684 att
->Complete
= GL_FALSE
;
685 att_incomplete("bad depth format");
690 ASSERT(format
== GL_STENCIL
);
691 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
692 ctx
->Extensions
.ARB_depth_texture
&&
693 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
697 /* no such thing as stencil-only textures */
698 att_incomplete("illegal stencil texture");
699 att
->Complete
= GL_FALSE
;
704 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
705 const GLenum baseFormat
=
706 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
708 ASSERT(att
->Renderbuffer
);
709 if (!att
->Renderbuffer
->InternalFormat
||
710 att
->Renderbuffer
->Width
< 1 ||
711 att
->Renderbuffer
->Height
< 1) {
712 att_incomplete("0x0 renderbuffer");
713 att
->Complete
= GL_FALSE
;
716 if (format
== GL_COLOR
) {
717 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
718 att_incomplete("bad renderbuffer color format");
719 att
->Complete
= GL_FALSE
;
723 else if (format
== GL_DEPTH
) {
724 if (baseFormat
== GL_DEPTH_COMPONENT
) {
727 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
728 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
732 att_incomplete("bad renderbuffer depth format");
733 att
->Complete
= GL_FALSE
;
738 assert(format
== GL_STENCIL
);
739 if (baseFormat
== GL_STENCIL_INDEX
) {
742 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
743 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
747 att
->Complete
= GL_FALSE
;
748 att_incomplete("bad renderbuffer stencil format");
754 ASSERT(att
->Type
== GL_NONE
);
762 * Test if the given framebuffer object is complete and update its
763 * Status field with the results.
764 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
765 * driver to make hardware-specific validation/completeness checks.
766 * Also update the framebuffer's Width and Height fields if the
767 * framebuffer is complete.
770 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
771 struct gl_framebuffer
*fb
)
774 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
775 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
776 GLint numSamples
= -1;
777 GLint fixedSampleLocations
= -1;
780 bool layer_count_valid
= false;
781 GLuint layer_count
= 0, att_layer_count
;
783 assert(_mesa_is_user_fbo(fb
));
785 /* we're changing framebuffer fields here */
786 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
791 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
792 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
794 /* Start at -2 to more easily loop over all attachment points.
799 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
800 struct gl_renderbuffer_attachment
*att
;
805 * XXX for ARB_fbo, only check color buffers that are named by
806 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
809 /* check for attachment completeness
812 att
= &fb
->Attachment
[BUFFER_DEPTH
];
813 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
814 if (!att
->Complete
) {
815 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
816 fbo_incomplete("depth attachment incomplete", -1);
821 att
= &fb
->Attachment
[BUFFER_STENCIL
];
822 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
823 if (!att
->Complete
) {
824 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
825 fbo_incomplete("stencil attachment incomplete", -1);
830 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
831 test_attachment_completeness(ctx
, GL_COLOR
, att
);
832 if (!att
->Complete
) {
833 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
834 fbo_incomplete("color attachment incomplete", i
);
839 /* get width, height, format of the renderbuffer/texture
841 if (att
->Type
== GL_TEXTURE
) {
842 const struct gl_texture_image
*texImg
=
843 _mesa_get_attachment_teximage(att
);
844 minWidth
= MIN2(minWidth
, texImg
->Width
);
845 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
846 minHeight
= MIN2(minHeight
, texImg
->Height
);
847 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
848 f
= texImg
->_BaseFormat
;
849 attFormat
= texImg
->TexFormat
;
852 if (!is_format_color_renderable(ctx
, attFormat
, texImg
->InternalFormat
) &&
853 !is_legal_depth_format(ctx
, f
)) {
854 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
855 fbo_incomplete("texture attachment incomplete", -1);
860 numSamples
= texImg
->NumSamples
;
861 else if (numSamples
!= texImg
->NumSamples
) {
862 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
863 fbo_incomplete("inconsistent sample count", -1);
867 if (fixedSampleLocations
< 0)
868 fixedSampleLocations
= texImg
->FixedSampleLocations
;
869 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
870 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
871 fbo_incomplete("inconsistent fixed sample locations", -1);
875 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
876 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
877 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
878 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
879 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
880 f
= att
->Renderbuffer
->InternalFormat
;
881 attFormat
= att
->Renderbuffer
->Format
;
885 numSamples
= att
->Renderbuffer
->NumSamples
;
886 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
887 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
888 fbo_incomplete("inconsistent sample count", -1);
892 /* RENDERBUFFER has fixedSampleLocations implicitly true */
893 if (fixedSampleLocations
< 0)
894 fixedSampleLocations
= GL_TRUE
;
895 else if (fixedSampleLocations
!= GL_TRUE
) {
896 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
897 fbo_incomplete("inconsistent fixed sample locations", -1);
902 assert(att
->Type
== GL_NONE
);
906 /* check if integer color */
907 fb
->_IntegerColor
= _mesa_is_format_integer_color(attFormat
);
909 /* Update _AllColorBuffersFixedPoint and _HasSNormOrFloatColorBuffer. */
911 GLenum type
= _mesa_get_format_datatype(attFormat
);
913 fb
->_AllColorBuffersFixedPoint
=
914 fb
->_AllColorBuffersFixedPoint
&&
915 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
917 fb
->_HasSNormOrFloatColorBuffer
=
918 fb
->_HasSNormOrFloatColorBuffer
||
919 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
922 /* Error-check width, height, format */
923 if (numImages
== 1) {
930 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
931 /* check that width, height, format are same */
932 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
933 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
934 fbo_incomplete("width or height mismatch", -1);
937 /* check that all color buffers are the same format */
938 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
939 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
940 fbo_incomplete("format mismatch", -1);
946 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
948 if (att
->Type
== GL_RENDERBUFFER
&&
949 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
950 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
951 fbo_incomplete("unsupported renderbuffer format", i
);
955 /* Check that layered rendering is consistent. */
956 att_layer_count
= att
->Layered
? att
->Renderbuffer
->Depth
: 0;
957 if (!layer_count_valid
) {
958 layer_count
= att_layer_count
;
959 layer_count_valid
= true;
960 } else if (layer_count
!= att_layer_count
) {
961 if (layer_count
== 0 || att_layer_count
== 0) {
962 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
963 fbo_incomplete("framebuffer attachment layer mode is inconsistent", i
);
965 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
;
966 fbo_incomplete("framebuffer attachment layer count is inconsistent", i
);
972 fb
->Layered
= layer_count
> 0;
974 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
975 /* Check that all DrawBuffers are present */
976 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
977 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
978 const struct gl_renderbuffer_attachment
*att
979 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
981 if (att
->Type
== GL_NONE
) {
982 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
983 fbo_incomplete("missing drawbuffer", j
);
989 /* Check that the ReadBuffer is present */
990 if (fb
->ColorReadBuffer
!= GL_NONE
) {
991 const struct gl_renderbuffer_attachment
*att
992 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
994 if (att
->Type
== GL_NONE
) {
995 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
996 fbo_incomplete("missing readbuffer", -1);
1002 if (numImages
== 0) {
1003 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1004 fbo_incomplete("no attachments", -1);
1008 /* Provisionally set status = COMPLETE ... */
1009 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1011 /* ... but the driver may say the FB is incomplete.
1012 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1015 if (ctx
->Driver
.ValidateFramebuffer
) {
1016 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1017 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1018 fbo_incomplete("driver marked FBO as incomplete", -1);
1022 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
1024 * Note that if ARB_framebuffer_object is supported and the attached
1025 * renderbuffers/textures are different sizes, the framebuffer
1026 * width/height will be set to the smallest width/height.
1028 fb
->Width
= minWidth
;
1029 fb
->Height
= minHeight
;
1031 /* finally, update the visual info for the framebuffer */
1032 _mesa_update_framebuffer_visual(ctx
, fb
);
1037 GLboolean GLAPIENTRY
1038 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1040 GET_CURRENT_CONTEXT(ctx
);
1041 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1043 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1044 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
1052 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1054 struct gl_renderbuffer
*newRb
;
1055 GET_CURRENT_CONTEXT(ctx
);
1057 if (target
!= GL_RENDERBUFFER_EXT
) {
1058 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1062 /* No need to flush here since the render buffer binding has no
1063 * effect on rendering state.
1067 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1068 if (newRb
== &DummyRenderbuffer
) {
1069 /* ID was reserved, but no real renderbuffer object made yet */
1073 && _mesa_is_desktop_gl(ctx
)
1074 && ctx
->Extensions
.ARB_framebuffer_object
) {
1075 /* All RB IDs must be Gen'd */
1076 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1081 /* create new renderbuffer object */
1082 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1084 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
1087 ASSERT(newRb
->AllocStorage
);
1088 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1089 newRb
->RefCount
= 1; /* referenced by hash table */
1096 ASSERT(newRb
!= &DummyRenderbuffer
);
1098 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1103 * If the given renderbuffer is anywhere attached to the framebuffer, detach
1105 * This is used when a renderbuffer object is deleted.
1106 * The spec calls for unbinding.
1109 detach_renderbuffer(struct gl_context
*ctx
,
1110 struct gl_framebuffer
*fb
,
1111 struct gl_renderbuffer
*rb
)
1114 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1115 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
1116 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
1119 invalidate_framebuffer(fb
);
1124 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1127 GET_CURRENT_CONTEXT(ctx
);
1129 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1131 for (i
= 0; i
< n
; i
++) {
1132 if (renderbuffers
[i
] > 0) {
1133 struct gl_renderbuffer
*rb
;
1134 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1136 /* check if deleting currently bound renderbuffer object */
1137 if (rb
== ctx
->CurrentRenderbuffer
) {
1139 ASSERT(rb
->RefCount
>= 2);
1140 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1143 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1144 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1146 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1147 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1148 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1151 /* Remove from hash table immediately, to free the ID.
1152 * But the object will not be freed until it's no longer
1153 * referenced anywhere else.
1155 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1157 if (rb
!= &DummyRenderbuffer
) {
1158 /* no longer referenced by hash table */
1159 _mesa_reference_renderbuffer(&rb
, NULL
);
1168 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1170 GET_CURRENT_CONTEXT(ctx
);
1175 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
1182 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1184 for (i
= 0; i
< n
; i
++) {
1185 GLuint name
= first
+ i
;
1186 renderbuffers
[i
] = name
;
1187 /* insert dummy placeholder into hash table */
1188 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1189 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
1190 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1196 * Given an internal format token for a render buffer, return the
1197 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1198 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1199 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1201 * This is similar to _mesa_base_tex_format() but the set of valid
1202 * internal formats is different.
1204 * Note that even if a format is determined to be legal here, validation
1205 * of the FBO may fail if the format is not supported by the driver/GPU.
1207 * \param internalFormat as passed to glRenderbufferStorage()
1208 * \return the base internal format, or 0 if internalFormat is illegal
1211 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1214 * Notes: some formats such as alpha, luminance, etc. were added
1215 * with GL_ARB_framebuffer_object.
1217 switch (internalFormat
) {
1223 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1228 case GL_LUMINANCE12
:
1229 case GL_LUMINANCE16
:
1230 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1232 case GL_LUMINANCE_ALPHA
:
1233 case GL_LUMINANCE4_ALPHA4
:
1234 case GL_LUMINANCE6_ALPHA2
:
1235 case GL_LUMINANCE8_ALPHA8
:
1236 case GL_LUMINANCE12_ALPHA4
:
1237 case GL_LUMINANCE12_ALPHA12
:
1238 case GL_LUMINANCE16_ALPHA16
:
1239 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1240 ? GL_LUMINANCE_ALPHA
: 0;
1244 case GL_INTENSITY12
:
1245 case GL_INTENSITY16
:
1246 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1257 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1259 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1268 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1270 case GL_SRGB8_ALPHA8_EXT
:
1271 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1272 case GL_STENCIL_INDEX
:
1273 case GL_STENCIL_INDEX1_EXT
:
1274 case GL_STENCIL_INDEX4_EXT
:
1275 case GL_STENCIL_INDEX16_EXT
:
1276 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1277 * OpenGL ES, but Mesa does not currently support them.
1279 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1280 case GL_STENCIL_INDEX8_EXT
:
1281 return GL_STENCIL_INDEX
;
1282 case GL_DEPTH_COMPONENT
:
1283 case GL_DEPTH_COMPONENT32
:
1284 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1285 case GL_DEPTH_COMPONENT16
:
1286 case GL_DEPTH_COMPONENT24
:
1287 return GL_DEPTH_COMPONENT
;
1288 case GL_DEPTH_STENCIL_EXT
:
1289 return _mesa_is_desktop_gl(ctx
)
1290 && ctx
->Extensions
.EXT_packed_depth_stencil
1291 ? GL_DEPTH_STENCIL_EXT
: 0;
1292 case GL_DEPTH24_STENCIL8_EXT
:
1293 return ctx
->Extensions
.EXT_packed_depth_stencil
1294 ? GL_DEPTH_STENCIL_EXT
: 0;
1295 case GL_DEPTH_COMPONENT32F
:
1296 return ctx
->Version
>= 30
1297 || (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_buffer_float
)
1298 ? GL_DEPTH_COMPONENT
: 0;
1299 case GL_DEPTH32F_STENCIL8
:
1300 return ctx
->Version
>= 30
1301 || (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_buffer_float
)
1302 ? GL_DEPTH_STENCIL
: 0;
1305 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1308 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1312 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1315 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1317 /* signed normalized texture formats */
1321 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1326 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1330 case GL_RGB16_SNORM
:
1331 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1334 case GL_RGBA8_SNORM
:
1335 case GL_RGBA16_SNORM
:
1336 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1338 case GL_ALPHA_SNORM
:
1339 case GL_ALPHA8_SNORM
:
1340 case GL_ALPHA16_SNORM
:
1341 return ctx
->API
== API_OPENGL_COMPAT
&&
1342 ctx
->Extensions
.EXT_texture_snorm
&&
1343 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1346 return ((_mesa_is_desktop_gl(ctx
) &&
1347 ctx
->Extensions
.ARB_texture_rg
&&
1348 ctx
->Extensions
.ARB_texture_float
) ||
1349 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1353 return ((_mesa_is_desktop_gl(ctx
) &&
1354 ctx
->Extensions
.ARB_texture_rg
&&
1355 ctx
->Extensions
.ARB_texture_float
) ||
1356 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1360 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1364 return ((_mesa_is_desktop_gl(ctx
) &&
1365 ctx
->Extensions
.ARB_texture_float
) ||
1366 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1368 case GL_ALPHA16F_ARB
:
1369 case GL_ALPHA32F_ARB
:
1370 return ctx
->API
== API_OPENGL_COMPAT
&&
1371 ctx
->Extensions
.ARB_texture_float
&&
1372 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1373 case GL_LUMINANCE16F_ARB
:
1374 case GL_LUMINANCE32F_ARB
:
1375 return ctx
->API
== API_OPENGL_COMPAT
&&
1376 ctx
->Extensions
.ARB_texture_float
&&
1377 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1378 case GL_LUMINANCE_ALPHA16F_ARB
:
1379 case GL_LUMINANCE_ALPHA32F_ARB
:
1380 return ctx
->API
== API_OPENGL_COMPAT
&&
1381 ctx
->Extensions
.ARB_texture_float
&&
1382 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1383 case GL_INTENSITY16F_ARB
:
1384 case GL_INTENSITY32F_ARB
:
1385 return ctx
->API
== API_OPENGL_COMPAT
&&
1386 ctx
->Extensions
.ARB_texture_float
&&
1387 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1389 return (_mesa_is_desktop_gl(ctx
)
1390 && ctx
->Extensions
.EXT_texture_shared_exponent
)
1392 case GL_R11F_G11F_B10F
:
1393 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1394 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1397 case GL_RGBA8UI_EXT
:
1398 case GL_RGBA16UI_EXT
:
1399 case GL_RGBA32UI_EXT
:
1401 case GL_RGBA16I_EXT
:
1402 case GL_RGBA32I_EXT
:
1403 return ctx
->Version
>= 30
1404 || (_mesa_is_desktop_gl(ctx
) &&
1405 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
1408 case GL_RGB16UI_EXT
:
1409 case GL_RGB32UI_EXT
:
1413 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
1421 return ctx
->Version
>= 30
1422 || (_mesa_is_desktop_gl(ctx
) &&
1423 ctx
->Extensions
.ARB_texture_rg
&&
1424 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
1432 return ctx
->Version
>= 30
1433 || (_mesa_is_desktop_gl(ctx
) &&
1434 ctx
->Extensions
.ARB_texture_rg
&&
1435 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
1437 case GL_INTENSITY8I_EXT
:
1438 case GL_INTENSITY8UI_EXT
:
1439 case GL_INTENSITY16I_EXT
:
1440 case GL_INTENSITY16UI_EXT
:
1441 case GL_INTENSITY32I_EXT
:
1442 case GL_INTENSITY32UI_EXT
:
1443 return ctx
->API
== API_OPENGL_COMPAT
&&
1444 ctx
->Extensions
.EXT_texture_integer
&&
1445 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1447 case GL_LUMINANCE8I_EXT
:
1448 case GL_LUMINANCE8UI_EXT
:
1449 case GL_LUMINANCE16I_EXT
:
1450 case GL_LUMINANCE16UI_EXT
:
1451 case GL_LUMINANCE32I_EXT
:
1452 case GL_LUMINANCE32UI_EXT
:
1453 return ctx
->API
== API_OPENGL_COMPAT
&&
1454 ctx
->Extensions
.EXT_texture_integer
&&
1455 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1457 case GL_LUMINANCE_ALPHA8I_EXT
:
1458 case GL_LUMINANCE_ALPHA8UI_EXT
:
1459 case GL_LUMINANCE_ALPHA16I_EXT
:
1460 case GL_LUMINANCE_ALPHA16UI_EXT
:
1461 case GL_LUMINANCE_ALPHA32I_EXT
:
1462 case GL_LUMINANCE_ALPHA32UI_EXT
:
1463 return ctx
->API
== API_OPENGL_COMPAT
&&
1464 ctx
->Extensions
.EXT_texture_integer
&&
1465 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1467 case GL_ALPHA8I_EXT
:
1468 case GL_ALPHA8UI_EXT
:
1469 case GL_ALPHA16I_EXT
:
1470 case GL_ALPHA16UI_EXT
:
1471 case GL_ALPHA32I_EXT
:
1472 case GL_ALPHA32UI_EXT
:
1473 return ctx
->API
== API_OPENGL_COMPAT
&&
1474 ctx
->Extensions
.EXT_texture_integer
&&
1475 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1478 return (_mesa_is_desktop_gl(ctx
) &&
1479 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
1480 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1483 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
1492 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1495 invalidate_rb(GLuint key
, void *data
, void *userData
)
1497 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1498 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
1500 /* If this is a user-created FBO */
1501 if (_mesa_is_user_fbo(fb
)) {
1503 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1504 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1505 if (att
->Type
== GL_RENDERBUFFER
&&
1506 att
->Renderbuffer
== rb
) {
1507 /* Mark fb status as indeterminate to force re-validation */
1516 /** sentinal value, see below */
1517 #define NO_SAMPLES 1000
1521 * Helper function used by _mesa_RenderbufferStorage() and
1522 * _mesa_RenderbufferStorageMultisample().
1523 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
1526 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1527 GLsizei width
, GLsizei height
, GLsizei samples
)
1529 const char *func
= samples
== NO_SAMPLES
?
1530 "glRenderbufferStorage" : "glRenderbufferStorageMultisample";
1531 struct gl_renderbuffer
*rb
;
1533 GLenum sample_count_error
;
1534 GET_CURRENT_CONTEXT(ctx
);
1536 if (MESA_VERBOSE
& VERBOSE_API
) {
1537 if (samples
== NO_SAMPLES
)
1538 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
1540 _mesa_lookup_enum_by_nr(target
),
1541 _mesa_lookup_enum_by_nr(internalFormat
),
1544 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
1546 _mesa_lookup_enum_by_nr(target
),
1547 _mesa_lookup_enum_by_nr(internalFormat
),
1548 width
, height
, samples
);
1551 if (target
!= GL_RENDERBUFFER_EXT
) {
1552 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1556 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1557 if (baseFormat
== 0) {
1558 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
1559 func
, _mesa_lookup_enum_by_nr(internalFormat
));
1563 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1564 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1568 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1569 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1573 if (samples
== NO_SAMPLES
) {
1574 /* NumSamples == 0 indicates non-multisampling */
1578 /* check the sample count;
1579 * note: driver may choose to use more samples than what's requested
1581 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
1582 internalFormat
, samples
);
1583 if (sample_count_error
!= GL_NO_ERROR
) {
1584 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
1589 rb
= ctx
->CurrentRenderbuffer
;
1591 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1595 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1597 if (rb
->InternalFormat
== internalFormat
&&
1598 rb
->Width
== (GLuint
) width
&&
1599 rb
->Height
== (GLuint
) height
&&
1600 rb
->NumSamples
== samples
) {
1601 /* no change in allocation needed */
1605 /* These MUST get set by the AllocStorage func */
1606 rb
->Format
= MESA_FORMAT_NONE
;
1607 rb
->NumSamples
= samples
;
1609 /* Now allocate the storage */
1610 ASSERT(rb
->AllocStorage
);
1611 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1612 /* No error - check/set fields now */
1613 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
1614 assert(rb
->Width
== (GLuint
) width
);
1615 assert(rb
->Height
== (GLuint
) height
);
1616 rb
->InternalFormat
= internalFormat
;
1617 rb
->_BaseFormat
= baseFormat
;
1618 assert(rb
->_BaseFormat
!= 0);
1621 /* Probably ran out of memory - clear the fields */
1624 rb
->Format
= MESA_FORMAT_NONE
;
1625 rb
->InternalFormat
= GL_NONE
;
1626 rb
->_BaseFormat
= GL_NONE
;
1630 /* Invalidate the framebuffers the renderbuffer is attached in. */
1631 if (rb
->AttachedAnytime
) {
1632 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
1638 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1640 struct gl_renderbuffer
*rb
;
1641 GET_CURRENT_CONTEXT(ctx
);
1643 if (!ctx
->Extensions
.OES_EGL_image
) {
1644 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1645 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1649 if (target
!= GL_RENDERBUFFER
) {
1650 _mesa_error(ctx
, GL_INVALID_ENUM
,
1651 "EGLImageTargetRenderbufferStorageOES");
1655 rb
= ctx
->CurrentRenderbuffer
;
1657 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1658 "EGLImageTargetRenderbufferStorageOES");
1662 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1664 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1669 * Helper function for _mesa_GetRenderbufferParameteriv() and
1670 * _mesa_GetFramebufferAttachmentParameteriv()
1671 * We have to be careful to respect the base format. For example, if a
1672 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1673 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1674 * we need to return zero.
1677 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1679 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1680 return _mesa_get_format_bits(format
, pname
);
1688 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
1689 GLsizei width
, GLsizei height
)
1691 /* GL_ARB_fbo says calling this function is equivalent to calling
1692 * glRenderbufferStorageMultisample() with samples=0. We pass in
1693 * a token value here just for error reporting purposes.
1695 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1700 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1701 GLenum internalFormat
,
1702 GLsizei width
, GLsizei height
)
1704 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1709 * OpenGL ES version of glRenderBufferStorage.
1712 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1713 GLsizei width
, GLsizei height
)
1715 switch (internalFormat
) {
1717 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1718 /* choose a closest format */
1719 internalFormat
= GL_RGB5
;
1725 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1730 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1732 struct gl_renderbuffer
*rb
;
1733 GET_CURRENT_CONTEXT(ctx
);
1735 if (target
!= GL_RENDERBUFFER_EXT
) {
1736 _mesa_error(ctx
, GL_INVALID_ENUM
,
1737 "glGetRenderbufferParameterivEXT(target)");
1741 rb
= ctx
->CurrentRenderbuffer
;
1743 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1744 "glGetRenderbufferParameterivEXT");
1748 /* No need to flush here since we're just quering state which is
1749 * not effected by rendering.
1753 case GL_RENDERBUFFER_WIDTH_EXT
:
1754 *params
= rb
->Width
;
1756 case GL_RENDERBUFFER_HEIGHT_EXT
:
1757 *params
= rb
->Height
;
1759 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1760 *params
= rb
->InternalFormat
;
1762 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1763 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1764 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1765 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1766 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1767 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1768 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1770 case GL_RENDERBUFFER_SAMPLES
:
1771 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
1772 || _mesa_is_gles3(ctx
)) {
1773 *params
= rb
->NumSamples
;
1778 _mesa_error(ctx
, GL_INVALID_ENUM
,
1779 "glGetRenderbufferParameterivEXT(target)");
1785 GLboolean GLAPIENTRY
1786 _mesa_IsFramebuffer(GLuint framebuffer
)
1788 GET_CURRENT_CONTEXT(ctx
);
1789 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1791 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1792 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1800 * Check if any of the attachments of the given framebuffer are textures
1801 * (render to texture). Call ctx->Driver.RenderTexture() for such
1805 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1808 ASSERT(ctx
->Driver
.RenderTexture
);
1810 if (_mesa_is_winsys_fbo(fb
))
1811 return; /* can't render to texture with winsys framebuffers */
1813 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1814 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1815 if (att
->Texture
&& _mesa_get_attachment_teximage(att
)) {
1816 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1823 * Examine all the framebuffer's attachments to see if any are textures.
1824 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1825 * notify the device driver that the texture image may have changed.
1828 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1830 if (_mesa_is_winsys_fbo(fb
))
1831 return; /* can't render to texture with winsys framebuffers */
1833 if (ctx
->Driver
.FinishRenderTexture
) {
1835 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1836 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1837 if (att
->Texture
&& att
->Renderbuffer
) {
1838 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1846 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
1848 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1849 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1850 GLboolean bindReadBuf
, bindDrawBuf
;
1851 GET_CURRENT_CONTEXT(ctx
);
1854 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1855 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1856 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1860 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1861 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1862 "glBindFramebufferEXT(unsupported)");
1867 case GL_DRAW_FRAMEBUFFER_EXT
:
1868 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1869 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1872 bindDrawBuf
= GL_TRUE
;
1873 bindReadBuf
= GL_FALSE
;
1875 case GL_READ_FRAMEBUFFER_EXT
:
1876 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1877 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1880 bindDrawBuf
= GL_FALSE
;
1881 bindReadBuf
= GL_TRUE
;
1883 case GL_FRAMEBUFFER_EXT
:
1884 bindDrawBuf
= GL_TRUE
;
1885 bindReadBuf
= GL_TRUE
;
1888 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1893 /* Binding a user-created framebuffer object */
1894 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1895 if (newDrawFb
== &DummyFramebuffer
) {
1896 /* ID was reserved, but no real framebuffer object made yet */
1900 && _mesa_is_desktop_gl(ctx
)
1901 && ctx
->Extensions
.ARB_framebuffer_object
) {
1902 /* All FBO IDs must be Gen'd */
1903 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1908 /* create new framebuffer object */
1909 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1911 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1914 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1916 newReadFb
= newDrawFb
;
1919 /* Binding the window system framebuffer (which was originally set
1920 * with MakeCurrent).
1922 newDrawFb
= ctx
->WinSysDrawBuffer
;
1923 newReadFb
= ctx
->WinSysReadBuffer
;
1927 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1929 /* save pointers to current/old framebuffers */
1930 oldDrawFb
= ctx
->DrawBuffer
;
1931 oldReadFb
= ctx
->ReadBuffer
;
1933 /* check if really changing bindings */
1934 if (oldDrawFb
== newDrawFb
)
1935 bindDrawBuf
= GL_FALSE
;
1936 if (oldReadFb
== newReadFb
)
1937 bindReadBuf
= GL_FALSE
;
1940 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1942 * We also check if we're beginning and/or ending render-to-texture.
1943 * When a framebuffer with texture attachments is unbound, call
1944 * ctx->Driver.FinishRenderTexture().
1945 * When a framebuffer with texture attachments is bound, call
1946 * ctx->Driver.RenderTexture().
1948 * Note that if the ReadBuffer has texture attachments we don't consider
1949 * that a render-to-texture case.
1952 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1954 /* check if old readbuffer was render-to-texture */
1955 check_end_texture_render(ctx
, oldReadFb
);
1957 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1961 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1963 /* check if old framebuffer had any texture attachments */
1965 check_end_texture_render(ctx
, oldDrawFb
);
1967 /* check if newly bound framebuffer has any texture attachments */
1968 check_begin_texture_render(ctx
, newDrawFb
);
1970 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1973 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1974 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1980 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
1983 GET_CURRENT_CONTEXT(ctx
);
1985 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1987 for (i
= 0; i
< n
; i
++) {
1988 if (framebuffers
[i
] > 0) {
1989 struct gl_framebuffer
*fb
;
1990 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1992 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1994 /* check if deleting currently bound framebuffer object */
1995 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1996 /* separate draw/read binding points */
1997 if (fb
== ctx
->DrawBuffer
) {
1999 ASSERT(fb
->RefCount
>= 2);
2000 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT
, 0);
2002 if (fb
== ctx
->ReadBuffer
) {
2004 ASSERT(fb
->RefCount
>= 2);
2005 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER_EXT
, 0);
2009 /* only one binding point for read/draw buffers */
2010 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
2012 ASSERT(fb
->RefCount
>= 2);
2013 _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT
, 0);
2017 /* remove from hash table immediately, to free the ID */
2018 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2020 if (fb
!= &DummyFramebuffer
) {
2021 /* But the object will not be freed until it's no longer
2022 * bound in any context.
2024 _mesa_reference_framebuffer(&fb
, NULL
);
2033 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2035 GET_CURRENT_CONTEXT(ctx
);
2040 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
2047 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2049 for (i
= 0; i
< n
; i
++) {
2050 GLuint name
= first
+ i
;
2051 framebuffers
[i
] = name
;
2052 /* insert dummy placeholder into hash table */
2053 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
2054 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
2055 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
2062 _mesa_CheckFramebufferStatus(GLenum target
)
2064 struct gl_framebuffer
*buffer
;
2065 GET_CURRENT_CONTEXT(ctx
);
2067 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2069 if (MESA_VERBOSE
& VERBOSE_API
)
2070 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2071 _mesa_lookup_enum_by_nr(target
));
2073 buffer
= get_framebuffer_target(ctx
, target
);
2075 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
2079 if (_mesa_is_winsys_fbo(buffer
)) {
2080 /* The window system / default framebuffer is always complete */
2081 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2084 /* No need to flush here */
2086 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2087 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2090 return buffer
->_Status
;
2095 * Replicate the src attachment point. Used by framebuffer_texture() when
2096 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2097 * GL_STENCIL_ATTACHMENT.
2100 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2101 gl_buffer_index dst
,
2102 gl_buffer_index src
)
2104 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2105 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2107 assert(src_att
->Texture
!= NULL
);
2108 assert(src_att
->Renderbuffer
!= NULL
);
2110 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2111 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2112 dst_att
->Type
= src_att
->Type
;
2113 dst_att
->Complete
= src_att
->Complete
;
2114 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2115 dst_att
->Zoffset
= src_att
->Zoffset
;
2120 * Common code called by glFramebufferTexture1D/2D/3DEXT() and
2121 * glFramebufferTextureLayerEXT().
2122 * Note: glFramebufferTextureLayerEXT() has no textarget parameter so we'll
2123 * get textarget=0 in that case.
2126 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
2127 GLenum attachment
, GLenum textarget
, GLuint texture
,
2128 GLint level
, GLint zoffset
, GLboolean layered
)
2130 struct gl_renderbuffer_attachment
*att
;
2131 struct gl_texture_object
*texObj
= NULL
;
2132 struct gl_framebuffer
*fb
;
2133 GLenum maxLevelsTarget
;
2135 fb
= get_framebuffer_target(ctx
, target
);
2137 _mesa_error(ctx
, GL_INVALID_ENUM
,
2138 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
2142 /* check framebuffer binding */
2143 if (_mesa_is_winsys_fbo(fb
)) {
2144 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2145 "glFramebufferTexture%sEXT", caller
);
2149 /* The textarget, level, and zoffset parameters are only validated if
2150 * texture is non-zero.
2153 GLboolean err
= GL_TRUE
;
2155 texObj
= _mesa_lookup_texture(ctx
, texture
);
2156 if (texObj
!= NULL
) {
2157 if (textarget
== 0) {
2158 /* If textarget == 0 it means we're being called by
2159 * glFramebufferTextureLayer() and textarget is not used.
2160 * The only legal texture types for that function are 3D and
2161 * 1D/2D arrays textures.
2163 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
2164 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
2165 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
) &&
2166 (texObj
->Target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) &&
2167 (texObj
->Target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
);
2170 /* Make sure textarget is consistent with the texture's type */
2171 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
2172 ? !_mesa_is_cube_face(textarget
)
2173 : (texObj
->Target
!= textarget
);
2177 /* can't render to a non-existant texture */
2178 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2179 "glFramebufferTexture%sEXT(non existant texture)",
2185 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2186 "glFramebufferTexture%sEXT(texture target mismatch)",
2191 if (texObj
->Target
== GL_TEXTURE_3D
) {
2192 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
2193 if (zoffset
< 0 || zoffset
>= maxSize
) {
2194 _mesa_error(ctx
, GL_INVALID_VALUE
,
2195 "glFramebufferTexture%sEXT(zoffset)", caller
);
2199 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
2200 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) ||
2201 (texObj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
2202 (texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
2204 zoffset
>= (GLint
) ctx
->Const
.MaxArrayTextureLayers
) {
2205 _mesa_error(ctx
, GL_INVALID_VALUE
,
2206 "glFramebufferTexture%sEXT(layer)", caller
);
2211 maxLevelsTarget
= textarget
? textarget
: texObj
->Target
;
2213 (level
>= _mesa_max_texture_levels(ctx
, maxLevelsTarget
))) {
2214 _mesa_error(ctx
, GL_INVALID_VALUE
,
2215 "glFramebufferTexture%sEXT(level)", caller
);
2220 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2222 _mesa_error(ctx
, GL_INVALID_ENUM
,
2223 "glFramebufferTexture%sEXT(attachment)", caller
);
2227 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2229 _glthread_LOCK_MUTEX(fb
->Mutex
);
2231 if (attachment
== GL_DEPTH_ATTACHMENT
&&
2232 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
2233 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
2234 _mesa_tex_target_to_face(textarget
) ==
2235 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
2236 zoffset
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
2237 /* The texture object is already attached to the stencil attachment
2238 * point. Don't create a new renderbuffer; just reuse the stencil
2239 * attachment's. This is required to prevent a GL error in
2240 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
2242 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
2244 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
2245 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
2246 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
2247 _mesa_tex_target_to_face(textarget
) ==
2248 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
2249 zoffset
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
2250 /* As above, but with depth and stencil transposed. */
2251 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
2254 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
2255 level
, zoffset
, layered
);
2256 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2257 /* Above we created a new renderbuffer and attached it to the
2258 * depth attachment point. Now attach it to the stencil attachment
2261 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
2262 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
2267 /* Set the render-to-texture flag. We'll check this flag in
2268 * glTexImage() and friends to determine if we need to revalidate
2269 * any FBOs that might be rendering into this texture.
2270 * This flag never gets cleared since it's non-trivial to determine
2271 * when all FBOs might be done rendering to this texture. That's OK
2272 * though since it's uncommon to render to a texture then repeatedly
2273 * call glTexImage() to change images in the texture.
2275 texObj
->_RenderToTexture
= GL_TRUE
;
2278 _mesa_remove_attachment(ctx
, att
);
2279 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2280 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
2281 _mesa_remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
2285 invalidate_framebuffer(fb
);
2287 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
2293 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
2294 GLenum textarget
, GLuint texture
, GLint level
)
2296 GET_CURRENT_CONTEXT(ctx
);
2301 switch (textarget
) {
2305 case GL_TEXTURE_1D_ARRAY
:
2306 error
= !ctx
->Extensions
.EXT_texture_array
;
2313 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2314 "glFramebufferTexture1DEXT(textarget=%s)",
2315 _mesa_lookup_enum_by_nr(textarget
));
2320 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
2321 level
, 0, GL_FALSE
);
2326 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
2327 GLenum textarget
, GLuint texture
, GLint level
)
2329 GET_CURRENT_CONTEXT(ctx
);
2334 switch (textarget
) {
2338 case GL_TEXTURE_RECTANGLE
:
2339 error
= _mesa_is_gles(ctx
)
2340 || !ctx
->Extensions
.NV_texture_rectangle
;
2342 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2343 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2344 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2345 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2346 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2347 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2348 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
2350 case GL_TEXTURE_2D_ARRAY
:
2351 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
2352 || !ctx
->Extensions
.EXT_texture_array
;
2354 case GL_TEXTURE_2D_MULTISAMPLE
:
2355 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2356 error
= _mesa_is_gles(ctx
)
2357 || !ctx
->Extensions
.ARB_texture_multisample
;
2364 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2365 "glFramebufferTexture2DEXT(textarget=%s)",
2366 _mesa_lookup_enum_by_nr(textarget
));
2371 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
2372 level
, 0, GL_FALSE
);
2377 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
2378 GLenum textarget
, GLuint texture
,
2379 GLint level
, GLint zoffset
)
2381 GET_CURRENT_CONTEXT(ctx
);
2383 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
2384 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2385 "glFramebufferTexture3DEXT(textarget)");
2389 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
2390 level
, zoffset
, GL_FALSE
);
2395 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
2396 GLuint texture
, GLint level
, GLint layer
)
2398 GET_CURRENT_CONTEXT(ctx
);
2400 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2401 level
, layer
, GL_FALSE
);
2406 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
2407 GLuint texture
, GLint level
)
2409 GET_CURRENT_CONTEXT(ctx
);
2411 if (ctx
->Version
>= 32 || ctx
->Extensions
.ARB_geometry_shader4
) {
2412 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2415 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2416 "unsupported function (glFramebufferTexture) called");
2422 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
2423 GLenum renderbufferTarget
,
2424 GLuint renderbuffer
)
2426 struct gl_renderbuffer_attachment
*att
;
2427 struct gl_framebuffer
*fb
;
2428 struct gl_renderbuffer
*rb
;
2429 GET_CURRENT_CONTEXT(ctx
);
2431 fb
= get_framebuffer_target(ctx
, target
);
2433 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFramebufferRenderbufferEXT(target)");
2437 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
2438 _mesa_error(ctx
, GL_INVALID_ENUM
,
2439 "glFramebufferRenderbufferEXT(renderbufferTarget)");
2443 if (_mesa_is_winsys_fbo(fb
)) {
2444 /* Can't attach new renderbuffers to a window system framebuffer */
2445 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
2449 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2451 _mesa_error(ctx
, GL_INVALID_ENUM
,
2452 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2453 _mesa_lookup_enum_by_nr(attachment
));
2458 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2460 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2461 "glFramebufferRenderbufferEXT(non-existant"
2462 " renderbuffer %u)", renderbuffer
);
2465 else if (rb
== &DummyRenderbuffer
) {
2466 /* This is what NVIDIA does */
2467 _mesa_error(ctx
, GL_INVALID_VALUE
,
2468 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2474 /* remove renderbuffer attachment */
2478 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
2479 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
2480 /* make sure the renderbuffer is a depth/stencil format */
2481 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2482 if (baseFormat
!= GL_DEPTH_STENCIL
) {
2483 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2484 "glFramebufferRenderbufferEXT(renderbuffer"
2485 " is not DEPTH_STENCIL format)");
2491 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2493 assert(ctx
->Driver
.FramebufferRenderbuffer
);
2494 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
2496 /* Some subsequent GL commands may depend on the framebuffer's visual
2497 * after the binding is updated. Update visual info now.
2499 _mesa_update_framebuffer_visual(ctx
, fb
);
2504 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
2505 GLenum pname
, GLint
*params
)
2507 const struct gl_renderbuffer_attachment
*att
;
2508 struct gl_framebuffer
*buffer
;
2510 GET_CURRENT_CONTEXT(ctx
);
2512 /* The error differs in GL and GLES. */
2513 err
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
2515 buffer
= get_framebuffer_target(ctx
, target
);
2517 _mesa_error(ctx
, GL_INVALID_ENUM
,
2518 "glGetFramebufferAttachmentParameterivEXT(target)");
2522 if (_mesa_is_winsys_fbo(buffer
)) {
2523 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
2526 * "If the framebuffer currently bound to target is zero, then
2527 * INVALID_OPERATION is generated."
2529 * The EXT_framebuffer_object spec has the same wording, and the
2530 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
2533 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2534 && !_mesa_is_gles3(ctx
)) {
2535 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2536 "glGetFramebufferAttachmentParameteriv(bound FBO = 0)");
2540 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
2541 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
2542 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2543 "glGetFramebufferAttachmentParameteriv(attachment)");
2546 /* the default / window-system FBO */
2547 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2550 /* user-created framebuffer FBO */
2551 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2555 _mesa_error(ctx
, GL_INVALID_ENUM
,
2556 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2560 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2561 /* the depth and stencil attachments must point to the same buffer */
2562 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2563 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2564 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2565 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2566 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2567 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2568 " attachments differ)");
2573 /* No need to flush here */
2576 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2577 *params
= _mesa_is_winsys_fbo(buffer
)
2578 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2580 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2581 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2582 *params
= att
->Renderbuffer
->Name
;
2584 else if (att
->Type
== GL_TEXTURE
) {
2585 *params
= att
->Texture
->Name
;
2588 assert(att
->Type
== GL_NONE
);
2589 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
2592 goto invalid_pname_enum
;
2596 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2597 if (att
->Type
== GL_TEXTURE
) {
2598 *params
= att
->TextureLevel
;
2600 else if (att
->Type
== GL_NONE
) {
2601 _mesa_error(ctx
, err
,
2602 "glGetFramebufferAttachmentParameterivEXT(pname)");
2605 goto invalid_pname_enum
;
2608 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2609 if (att
->Type
== GL_TEXTURE
) {
2610 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2611 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2617 else if (att
->Type
== GL_NONE
) {
2618 _mesa_error(ctx
, err
,
2619 "glGetFramebufferAttachmentParameterivEXT(pname)");
2622 goto invalid_pname_enum
;
2625 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2626 if (ctx
->API
== API_OPENGLES
) {
2627 goto invalid_pname_enum
;
2628 } else if (att
->Type
== GL_NONE
) {
2629 _mesa_error(ctx
, err
,
2630 "glGetFramebufferAttachmentParameterivEXT(pname)");
2631 } else if (att
->Type
== GL_TEXTURE
) {
2632 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2633 *params
= att
->Zoffset
;
2640 goto invalid_pname_enum
;
2643 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2644 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2645 && !_mesa_is_gles3(ctx
)) {
2646 goto invalid_pname_enum
;
2648 else if (att
->Type
== GL_NONE
) {
2649 _mesa_error(ctx
, err
,
2650 "glGetFramebufferAttachmentParameterivEXT(pname)");
2653 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
2654 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2657 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2658 * if the sRGB conversion is unsupported. */
2659 *params
= GL_LINEAR
;
2663 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2664 if ((ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_framebuffer_object
)
2665 && ctx
->API
!= API_OPENGL_CORE
2666 && !_mesa_is_gles3(ctx
)) {
2667 goto invalid_pname_enum
;
2669 else if (att
->Type
== GL_NONE
) {
2670 _mesa_error(ctx
, err
,
2671 "glGetFramebufferAttachmentParameterivEXT(pname)");
2674 gl_format format
= att
->Renderbuffer
->Format
;
2676 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
2679 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
2680 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
2681 * generate an INVALID_OPERATION error.
2683 if (_mesa_is_gles3(ctx
) && attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2684 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2685 "glGetFramebufferAttachmentParameteriv(cannot query "
2686 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
2687 "GL_DEPTH_STENCIL_ATTACHMENT");
2691 if (format
== MESA_FORMAT_S8
) {
2695 else if (format
== MESA_FORMAT_Z32_FLOAT_X24S8
) {
2696 /* depends on the attachment parameter */
2697 if (attachment
== GL_STENCIL_ATTACHMENT
) {
2705 *params
= _mesa_get_format_datatype(format
);
2709 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2710 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2711 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2712 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2713 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2714 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2715 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2716 && !_mesa_is_gles3(ctx
)) {
2717 goto invalid_pname_enum
;
2719 else if (att
->Type
== GL_NONE
) {
2720 _mesa_error(ctx
, err
,
2721 "glGetFramebufferAttachmentParameterivEXT(pname)");
2723 else if (att
->Texture
) {
2724 const struct gl_texture_image
*texImage
=
2725 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2728 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2729 texImage
->TexFormat
);
2735 else if (att
->Renderbuffer
) {
2736 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2737 att
->Renderbuffer
->Format
);
2740 _mesa_problem(ctx
, "glGetFramebufferAttachmentParameterivEXT:"
2741 " invalid FBO attachment structure");
2745 goto invalid_pname_enum
;
2751 _mesa_error(ctx
, GL_INVALID_ENUM
,
2752 "glGetFramebufferAttachmentParameteriv(pname)");
2758 _mesa_GenerateMipmap(GLenum target
)
2760 struct gl_texture_image
*srcImage
;
2761 struct gl_texture_object
*texObj
;
2764 GET_CURRENT_CONTEXT(ctx
);
2766 FLUSH_VERTICES(ctx
, 0);
2770 error
= _mesa_is_gles(ctx
);
2776 error
= ctx
->API
== API_OPENGLES
;
2778 case GL_TEXTURE_CUBE_MAP
:
2779 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
2781 case GL_TEXTURE_1D_ARRAY
:
2782 error
= _mesa_is_gles(ctx
) || !ctx
->Extensions
.EXT_texture_array
;
2784 case GL_TEXTURE_2D_ARRAY
:
2785 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
2786 || !ctx
->Extensions
.EXT_texture_array
;
2793 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target=%s)",
2794 _mesa_lookup_enum_by_nr(target
));
2798 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2800 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2805 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
2806 !_mesa_cube_complete(texObj
)) {
2807 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2808 "glGenerateMipmap(incomplete cube map)");
2812 _mesa_lock_texture(ctx
, texObj
);
2814 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, texObj
->BaseLevel
);
2816 _mesa_unlock_texture(ctx
, texObj
);
2817 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2818 "glGenerateMipmap(zero size base image)");
2822 if (_mesa_is_enum_format_integer(srcImage
->InternalFormat
) ||
2823 _mesa_is_depthstencil_format(srcImage
->InternalFormat
) ||
2824 _mesa_is_stencil_format(srcImage
->InternalFormat
)) {
2825 _mesa_unlock_texture(ctx
, texObj
);
2826 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2827 "glGenerateMipmap(invalid internal format)");
2831 if (target
== GL_TEXTURE_CUBE_MAP
) {
2833 for (face
= 0; face
< 6; face
++)
2834 ctx
->Driver
.GenerateMipmap(ctx
,
2835 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2839 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2841 _mesa_unlock_texture(ctx
, texObj
);
2845 static const struct gl_renderbuffer_attachment
*
2846 find_attachment(const struct gl_framebuffer
*fb
,
2847 const struct gl_renderbuffer
*rb
)
2850 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2851 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2852 return &fb
->Attachment
[i
];
2859 * Helper function for checking if the datatypes of color buffers are
2860 * compatible for glBlitFramebuffer. From the 3.1 spec, page 198:
2862 * "GL_INVALID_OPERATION is generated if mask contains GL_COLOR_BUFFER_BIT
2863 * and any of the following conditions hold:
2864 * - The read buffer contains fixed-point or floating-point values and any
2865 * draw buffer contains neither fixed-point nor floating-point values.
2866 * - The read buffer contains unsigned integer values and any draw buffer
2867 * does not contain unsigned integer values.
2868 * - The read buffer contains signed integer values and any draw buffer
2869 * does not contain signed integer values."
2872 compatible_color_datatypes(gl_format srcFormat
, gl_format dstFormat
)
2874 GLenum srcType
= _mesa_get_format_datatype(srcFormat
);
2875 GLenum dstType
= _mesa_get_format_datatype(dstFormat
);
2877 if (srcType
!= GL_INT
&& srcType
!= GL_UNSIGNED_INT
) {
2878 assert(srcType
== GL_UNSIGNED_NORMALIZED
||
2879 srcType
== GL_SIGNED_NORMALIZED
||
2880 srcType
== GL_FLOAT
);
2881 /* Boil any of those types down to GL_FLOAT */
2885 if (dstType
!= GL_INT
&& dstType
!= GL_UNSIGNED_INT
) {
2886 assert(dstType
== GL_UNSIGNED_NORMALIZED
||
2887 dstType
== GL_SIGNED_NORMALIZED
||
2888 dstType
== GL_FLOAT
);
2889 /* Boil any of those types down to GL_FLOAT */
2893 return srcType
== dstType
;
2898 compatible_resolve_formats(const struct gl_renderbuffer
*readRb
,
2899 const struct gl_renderbuffer
*drawRb
)
2901 GLenum readFormat
, drawFormat
;
2903 /* The simple case where we know the backing Mesa formats are the same.
2905 if (_mesa_get_srgb_format_linear(readRb
->Format
) ==
2906 _mesa_get_srgb_format_linear(drawRb
->Format
)) {
2910 /* The Mesa formats are different, so we must check whether the internal
2911 * formats are compatible.
2913 * Under some circumstances, the user may request e.g. two GL_RGBA8
2914 * textures and get two entirely different Mesa formats like RGBA8888 and
2915 * ARGB8888. Drivers behaving like that should be able to cope with
2916 * non-matching formats by themselves, because it's not the user's fault.
2918 * Blits between linear and sRGB formats are also allowed.
2920 readFormat
= _mesa_get_nongeneric_internalformat(readRb
->InternalFormat
);
2921 drawFormat
= _mesa_get_nongeneric_internalformat(drawRb
->InternalFormat
);
2922 readFormat
= _mesa_get_linear_internalformat(readFormat
);
2923 drawFormat
= _mesa_get_linear_internalformat(drawFormat
);
2925 if (readFormat
== drawFormat
) {
2934 * Blit rectangular region, optionally from one framebuffer to another.
2936 * Note, if the src buffer is multisampled and the dest is not, this is
2937 * when the samples must be resolved to a single color.
2940 _mesa_BlitFramebuffer(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2941 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2942 GLbitfield mask
, GLenum filter
)
2944 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2945 GL_DEPTH_BUFFER_BIT
|
2946 GL_STENCIL_BUFFER_BIT
);
2947 const struct gl_framebuffer
*readFb
, *drawFb
;
2948 GET_CURRENT_CONTEXT(ctx
);
2950 FLUSH_VERTICES(ctx
, 0);
2952 if (MESA_VERBOSE
& VERBOSE_API
)
2954 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
2955 srcX0
, srcY0
, srcX1
, srcY1
,
2956 dstX0
, dstY0
, dstX1
, dstY1
,
2957 mask
, _mesa_lookup_enum_by_nr(filter
));
2959 if (ctx
->NewState
) {
2960 _mesa_update_state(ctx
);
2963 readFb
= ctx
->ReadBuffer
;
2964 drawFb
= ctx
->DrawBuffer
;
2966 if (!readFb
|| !drawFb
) {
2967 /* This will normally never happen but someday we may want to
2968 * support MakeCurrent() with no drawables.
2973 /* check for complete framebuffers */
2974 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2975 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2976 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2977 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2981 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2982 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2986 if (mask
& ~legalMaskBits
) {
2987 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2991 /* depth/stencil must be blitted with nearest filtering */
2992 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2993 && filter
!= GL_NEAREST
) {
2994 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2995 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
2999 /* get color read/draw renderbuffers */
3000 if (mask
& GL_COLOR_BUFFER_BIT
) {
3001 const GLuint numColorDrawBuffers
= ctx
->DrawBuffer
->_NumColorDrawBuffers
;
3002 const struct gl_renderbuffer
*colorReadRb
= readFb
->_ColorReadBuffer
;
3003 const struct gl_renderbuffer
*colorDrawRb
= NULL
;
3006 /* From the EXT_framebuffer_object spec:
3008 * "If a buffer is specified in <mask> and does not exist in both
3009 * the read and draw framebuffers, the corresponding bit is silently
3012 if (!colorReadRb
|| numColorDrawBuffers
== 0) {
3013 mask
&= ~GL_COLOR_BUFFER_BIT
;
3016 for (i
= 0; i
< numColorDrawBuffers
; i
++) {
3017 colorDrawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
3021 /* Page 193 (page 205 of the PDF) in section 4.3.2 of the OpenGL
3022 * ES 3.0.1 spec says:
3024 * "If the source and destination buffers are identical, an
3025 * INVALID_OPERATION error is generated. Different mipmap
3026 * levels of a texture, different layers of a three-
3027 * dimensional texture or two-dimensional array texture, and
3028 * different faces of a cube map texture do not constitute
3029 * identical buffers."
3031 if (_mesa_is_gles3(ctx
) && (colorDrawRb
== colorReadRb
)) {
3032 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3033 "glBlitFramebuffer(source and destination color "
3034 "buffer cannot be the same)");
3038 if (!compatible_color_datatypes(colorReadRb
->Format
,
3039 colorDrawRb
->Format
)) {
3040 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3041 "glBlitFramebufferEXT(color buffer datatypes mismatch)");
3044 /* extra checks for multisample copies... */
3045 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
3046 /* color formats must match */
3047 if (!compatible_resolve_formats(colorReadRb
, colorDrawRb
)) {
3048 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3049 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
3054 if (filter
== GL_LINEAR
) {
3055 /* 3.1 spec, page 199:
3056 * "Calling BlitFramebuffer will result in an INVALID_OPERATION error
3057 * if filter is LINEAR and read buffer contains integer data."
3059 GLenum type
= _mesa_get_format_datatype(colorReadRb
->Format
);
3060 if (type
== GL_INT
|| type
== GL_UNSIGNED_INT
) {
3061 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3062 "glBlitFramebufferEXT(integer color type)");
3069 if (mask
& GL_STENCIL_BUFFER_BIT
) {
3070 struct gl_renderbuffer
*readRb
=
3071 readFb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3072 struct gl_renderbuffer
*drawRb
=
3073 drawFb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3075 /* From the EXT_framebuffer_object spec:
3077 * "If a buffer is specified in <mask> and does not exist in both
3078 * the read and draw framebuffers, the corresponding bit is silently
3081 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
3082 mask
&= ~GL_STENCIL_BUFFER_BIT
;
3085 int read_z_bits
, draw_z_bits
;
3087 if (_mesa_is_gles3(ctx
) && (drawRb
== readRb
)) {
3088 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3089 "glBlitFramebuffer(source and destination stencil "
3090 "buffer cannot be the same)");
3094 if (_mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
3095 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
3096 /* There is no need to check the stencil datatype here, because
3097 * there is only one: GL_UNSIGNED_INT.
3099 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3100 "glBlitFramebuffer(stencil attachment format mismatch)");
3104 read_z_bits
= _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
);
3105 draw_z_bits
= _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
);
3107 /* If both buffers also have depth data, the depth formats must match
3108 * as well. If one doesn't have depth, it's not blitted, so we should
3109 * ignore the depth format check.
3111 if (read_z_bits
> 0 && draw_z_bits
> 0 &&
3112 (read_z_bits
!= draw_z_bits
||
3113 _mesa_get_format_datatype(readRb
->Format
) !=
3114 _mesa_get_format_datatype(drawRb
->Format
))) {
3116 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebuffer"
3117 "(stencil attachment depth format mismatch)");
3123 if (mask
& GL_DEPTH_BUFFER_BIT
) {
3124 struct gl_renderbuffer
*readRb
=
3125 readFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3126 struct gl_renderbuffer
*drawRb
=
3127 drawFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3129 /* From the EXT_framebuffer_object spec:
3131 * "If a buffer is specified in <mask> and does not exist in both
3132 * the read and draw framebuffers, the corresponding bit is silently
3135 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
3136 mask
&= ~GL_DEPTH_BUFFER_BIT
;
3139 int read_s_bit
, draw_s_bit
;
3141 if (_mesa_is_gles3(ctx
) && (drawRb
== readRb
)) {
3142 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3143 "glBlitFramebuffer(source and destination depth "
3144 "buffer cannot be the same)");
3148 if ((_mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
3149 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) ||
3150 (_mesa_get_format_datatype(readRb
->Format
) !=
3151 _mesa_get_format_datatype(drawRb
->Format
))) {
3152 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3153 "glBlitFramebuffer(depth attachment format mismatch)");
3157 read_s_bit
= _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
);
3158 draw_s_bit
= _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
);
3160 /* If both buffers also have stencil data, the stencil formats must
3161 * match as well. If one doesn't have stencil, it's not blitted, so
3162 * we should ignore the stencil format check.
3164 if (read_s_bit
> 0 && draw_s_bit
> 0 && read_s_bit
!= draw_s_bit
) {
3165 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebuffer"
3166 "(depth attachment stencil bits mismatch)");
3173 if (_mesa_is_gles3(ctx
)) {
3174 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3177 * "If SAMPLE_BUFFERS for the draw framebuffer is greater than zero,
3178 * an INVALID_OPERATION error is generated."
3180 if (drawFb
->Visual
.samples
> 0) {
3181 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3182 "glBlitFramebuffer(destination samples must be 0)");
3186 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3189 * "If SAMPLE_BUFFERS for the read framebuffer is greater than zero,
3190 * no copy is performed and an INVALID_OPERATION error is generated
3191 * if the formats of the read and draw framebuffers are not
3192 * identical or if the source and destination rectangles are not
3193 * defined with the same (X0, Y0) and (X1, Y1) bounds."
3195 * The format check was made above because desktop OpenGL has the same
3198 if (readFb
->Visual
.samples
> 0
3199 && (srcX0
!= dstX0
|| srcY0
!= dstY0
3200 || srcX1
!= dstX1
|| srcY1
!= dstY1
)) {
3201 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3202 "glBlitFramebuffer(bad src/dst multisample region)");
3206 if (readFb
->Visual
.samples
> 0 &&
3207 drawFb
->Visual
.samples
> 0 &&
3208 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
3209 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3210 "glBlitFramebufferEXT(mismatched samples)");
3214 /* extra checks for multisample copies... */
3215 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
3216 /* src and dest region sizes must be the same */
3217 if (abs(srcX1
- srcX0
) != abs(dstX1
- dstX0
) ||
3218 abs(srcY1
- srcY0
) != abs(dstY1
- dstY0
)) {
3219 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3220 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
3226 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
3227 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
3233 const struct gl_renderbuffer
*colorReadRb
= readFb
->_ColorReadBuffer
;
3234 const struct gl_renderbuffer
*colorDrawRb
= NULL
;
3237 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
3239 srcX0
, srcY0
, srcX1
, srcY1
,
3240 dstX0
, dstY0
, dstX1
, dstY1
,
3243 const struct gl_renderbuffer_attachment
*att
;
3245 att
= find_attachment(readFb
, colorReadRb
);
3246 printf(" Src FBO %u RB %u (%dx%d) ",
3247 readFb
->Name
, colorReadRb
->Name
,
3248 colorReadRb
->Width
, colorReadRb
->Height
);
3249 if (att
&& att
->Texture
) {
3250 printf("Tex %u tgt 0x%x level %u face %u",
3252 att
->Texture
->Target
,
3258 /* Print all active color render buffers */
3259 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
3260 colorDrawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
3264 att
= find_attachment(drawFb
, colorDrawRb
);
3265 printf(" Dst FBO %u RB %u (%dx%d) ",
3266 drawFb
->Name
, colorDrawRb
->Name
,
3267 colorDrawRb
->Width
, colorDrawRb
->Height
);
3268 if (att
&& att
->Texture
) {
3269 printf("Tex %u tgt 0x%x level %u face %u",
3271 att
->Texture
->Target
,
3281 (srcX1
- srcX0
) == 0 || (srcY1
- srcY0
) == 0 ||
3282 (dstX1
- dstX0
) == 0 || (dstY1
- dstY0
) == 0) {
3286 ASSERT(ctx
->Driver
.BlitFramebuffer
);
3287 ctx
->Driver
.BlitFramebuffer(ctx
,
3288 srcX0
, srcY0
, srcX1
, srcY1
,
3289 dstX0
, dstY0
, dstX1
, dstY1
,
3295 invalidate_framebuffer_storage(GLenum target
, GLsizei numAttachments
,
3296 const GLenum
*attachments
, GLint x
, GLint y
,
3297 GLsizei width
, GLsizei height
, const char *name
)
3300 struct gl_framebuffer
*fb
;
3301 GET_CURRENT_CONTEXT(ctx
);
3303 fb
= get_framebuffer_target(ctx
, target
);
3305 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", name
);
3309 if (numAttachments
< 0) {
3310 _mesa_error(ctx
, GL_INVALID_VALUE
,
3311 "%s(numAttachments < 0)", name
);
3315 /* The GL_ARB_invalidate_subdata spec says:
3317 * "If an attachment is specified that does not exist in the
3318 * framebuffer bound to <target>, it is ignored."
3322 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
3323 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
3324 * INVALID_OPERATION is generated."
3326 * No mention is made of GL_AUXi being out of range. Therefore, we allow
3327 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
3328 * set of retrictions).
3330 for (i
= 0; i
< numAttachments
; i
++) {
3331 if (_mesa_is_winsys_fbo(fb
)) {
3332 switch (attachments
[i
]) {
3338 /* Accumulation buffers and auxilary buffers were removed in
3339 * OpenGL 3.1, and they never existed in OpenGL ES.
3341 if (ctx
->API
!= API_OPENGL_COMPAT
)
3351 case GL_FRONT_RIGHT
:
3352 if (!_mesa_is_desktop_gl(ctx
))
3359 switch (attachments
[i
]) {
3360 case GL_DEPTH_ATTACHMENT
:
3361 case GL_STENCIL_ATTACHMENT
:
3363 case GL_COLOR_ATTACHMENT0
:
3364 case GL_COLOR_ATTACHMENT1
:
3365 case GL_COLOR_ATTACHMENT2
:
3366 case GL_COLOR_ATTACHMENT3
:
3367 case GL_COLOR_ATTACHMENT4
:
3368 case GL_COLOR_ATTACHMENT5
:
3369 case GL_COLOR_ATTACHMENT6
:
3370 case GL_COLOR_ATTACHMENT7
:
3371 case GL_COLOR_ATTACHMENT8
:
3372 case GL_COLOR_ATTACHMENT9
:
3373 case GL_COLOR_ATTACHMENT10
:
3374 case GL_COLOR_ATTACHMENT11
:
3375 case GL_COLOR_ATTACHMENT12
:
3376 case GL_COLOR_ATTACHMENT13
:
3377 case GL_COLOR_ATTACHMENT14
:
3378 case GL_COLOR_ATTACHMENT15
: {
3379 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
3380 if (k
>= ctx
->Const
.MaxColorAttachments
) {
3381 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3382 "%s(attachment >= max. color attachments)", name
);
3392 /* We don't actually do anything for this yet. Just return after
3393 * validating the parameters and generating the required errors.
3398 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(attachment)", name
);
3403 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
3404 const GLenum
*attachments
, GLint x
, GLint y
,
3405 GLsizei width
, GLsizei height
)
3407 invalidate_framebuffer_storage(target
, numAttachments
, attachments
,
3408 x
, y
, width
, height
,
3409 "glInvalidateSubFramebuffer");
3413 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
3414 const GLenum
*attachments
)
3416 /* The GL_ARB_invalidate_subdata spec says:
3420 * void InvalidateFramebuffer(enum target,
3421 * sizei numAttachments,
3422 * const enum *attachments);
3424 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
3425 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
3426 * <MAX_VIEWPORT_DIMS[1]> respectively."
3428 invalidate_framebuffer_storage(target
, numAttachments
, attachments
,
3429 0, 0, MAX_VIEWPORT_WIDTH
, MAX_VIEWPORT_HEIGHT
,
3430 "glInvalidateFramebuffer");
3434 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
3435 const GLenum
*attachments
)
3437 struct gl_framebuffer
*fb
;
3440 GET_CURRENT_CONTEXT(ctx
);
3442 fb
= get_framebuffer_target(ctx
, target
);
3444 _mesa_error(ctx
, GL_INVALID_ENUM
,
3445 "glDiscardFramebufferEXT(target %s)",
3446 _mesa_lookup_enum_by_nr(target
));
3450 if (numAttachments
< 0) {
3451 _mesa_error(ctx
, GL_INVALID_VALUE
,
3452 "glDiscardFramebufferEXT(numAttachments < 0)");
3456 for (i
= 0; i
< numAttachments
; i
++) {
3457 switch (attachments
[i
]) {
3461 if (_mesa_is_user_fbo(fb
))
3464 case GL_COLOR_ATTACHMENT0
:
3465 case GL_DEPTH_ATTACHMENT
:
3466 case GL_STENCIL_ATTACHMENT
:
3467 if (_mesa_is_winsys_fbo(fb
))
3475 if (ctx
->Driver
.DiscardFramebuffer
)
3476 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
3481 _mesa_error(ctx
, GL_INVALID_ENUM
,
3482 "glDiscardFramebufferEXT(attachment %s)",
3483 _mesa_lookup_enum_by_nr(attachments
[i
]));