2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 * GL_EXT/ARB_framebuffer_object extensions
41 #include "framebuffer.h"
42 #include "glformats.h"
45 #include "multisample.h"
47 #include "renderbuffer.h"
53 /** Set this to 1 to debug/log glBlitFramebuffer() calls */
60 * None of the GL_EXT_framebuffer_object functions are compiled into
67 * When glGenRender/FramebuffersEXT() is called we insert pointers to
68 * these placeholder objects into the hash table.
69 * Later, when the object ID is first bound, we replace the placeholder
70 * with the real frame/renderbuffer.
72 static struct gl_framebuffer DummyFramebuffer
;
73 static struct gl_renderbuffer DummyRenderbuffer
;
75 /* We bind this framebuffer when applications pass a NULL
76 * drawable/surface in make current. */
77 static struct gl_framebuffer IncompleteFramebuffer
;
81 delete_dummy_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
87 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
94 _mesa_init_fbobjects(struct gl_context
*ctx
)
96 _glthread_INIT_MUTEX(DummyFramebuffer
.Mutex
);
97 _glthread_INIT_MUTEX(DummyRenderbuffer
.Mutex
);
98 _glthread_INIT_MUTEX(IncompleteFramebuffer
.Mutex
);
99 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
100 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
101 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
104 struct gl_framebuffer
*
105 _mesa_get_incomplete_framebuffer(void)
107 return &IncompleteFramebuffer
;
111 * Helper routine for getting a gl_renderbuffer.
113 struct gl_renderbuffer
*
114 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
116 struct gl_renderbuffer
*rb
;
121 rb
= (struct gl_renderbuffer
*)
122 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
128 * Helper routine for getting a gl_framebuffer.
130 struct gl_framebuffer
*
131 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
133 struct gl_framebuffer
*fb
;
138 fb
= (struct gl_framebuffer
*)
139 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
145 * Mark the given framebuffer as invalid. This will force the
146 * test for framebuffer completeness to be done before the framebuffer
150 invalidate_framebuffer(struct gl_framebuffer
*fb
)
152 fb
->_Status
= 0; /* "indeterminate" */
157 * Return the gl_framebuffer object which corresponds to the given
158 * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
159 * Check support for GL_EXT_framebuffer_blit to determine if certain
161 * \return gl_framebuffer pointer or NULL if target is illegal
163 static struct gl_framebuffer
*
164 get_framebuffer_target(struct gl_context
*ctx
, GLenum target
)
166 bool have_fb_blit
= _mesa_is_gles3(ctx
) ||
167 (ctx
->Extensions
.EXT_framebuffer_blit
&& _mesa_is_desktop_gl(ctx
));
169 case GL_DRAW_FRAMEBUFFER
:
170 return have_fb_blit
? ctx
->DrawBuffer
: NULL
;
171 case GL_READ_FRAMEBUFFER
:
172 return have_fb_blit
? ctx
->ReadBuffer
: NULL
;
173 case GL_FRAMEBUFFER_EXT
:
174 return ctx
->DrawBuffer
;
182 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
183 * gl_renderbuffer_attachment object.
184 * This function is only used for user-created FB objects, not the
185 * default / window-system FB object.
186 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
187 * the depth buffer attachment point.
189 struct gl_renderbuffer_attachment
*
190 _mesa_get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
195 assert(_mesa_is_user_fbo(fb
));
197 switch (attachment
) {
198 case GL_COLOR_ATTACHMENT0_EXT
:
199 case GL_COLOR_ATTACHMENT1_EXT
:
200 case GL_COLOR_ATTACHMENT2_EXT
:
201 case GL_COLOR_ATTACHMENT3_EXT
:
202 case GL_COLOR_ATTACHMENT4_EXT
:
203 case GL_COLOR_ATTACHMENT5_EXT
:
204 case GL_COLOR_ATTACHMENT6_EXT
:
205 case GL_COLOR_ATTACHMENT7_EXT
:
206 case GL_COLOR_ATTACHMENT8_EXT
:
207 case GL_COLOR_ATTACHMENT9_EXT
:
208 case GL_COLOR_ATTACHMENT10_EXT
:
209 case GL_COLOR_ATTACHMENT11_EXT
:
210 case GL_COLOR_ATTACHMENT12_EXT
:
211 case GL_COLOR_ATTACHMENT13_EXT
:
212 case GL_COLOR_ATTACHMENT14_EXT
:
213 case GL_COLOR_ATTACHMENT15_EXT
:
214 /* Only OpenGL ES 1.x forbids color attachments other than
215 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
218 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
219 if (i
>= ctx
->Const
.MaxColorAttachments
220 || (i
> 0 && ctx
->API
== API_OPENGLES
)) {
223 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
224 case GL_DEPTH_STENCIL_ATTACHMENT
:
225 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
228 case GL_DEPTH_ATTACHMENT_EXT
:
229 return &fb
->Attachment
[BUFFER_DEPTH
];
230 case GL_STENCIL_ATTACHMENT_EXT
:
231 return &fb
->Attachment
[BUFFER_STENCIL
];
239 * As above, but only used for getting attachments of the default /
240 * window-system framebuffer (not user-created framebuffer objects).
242 static struct gl_renderbuffer_attachment
*
243 _mesa_get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
246 assert(_mesa_is_winsys_fbo(fb
));
248 if (_mesa_is_gles3(ctx
)) {
249 assert(attachment
== GL_BACK
||
250 attachment
== GL_DEPTH
||
251 attachment
== GL_STENCIL
);
252 switch (attachment
) {
254 /* Since there is no stereo rendering in ES 3.0, only return the
257 if (ctx
->DrawBuffer
->Visual
.doubleBufferMode
)
258 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
259 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
261 return &fb
->Attachment
[BUFFER_DEPTH
];
263 return &fb
->Attachment
[BUFFER_STENCIL
];
267 switch (attachment
) {
269 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
271 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
273 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
275 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
277 if (fb
->Visual
.numAuxBuffers
== 1) {
278 return &fb
->Attachment
[BUFFER_AUX0
];
282 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
284 * "If the default framebuffer is bound to target, then attachment must
285 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
286 * identifying a color buffer; DEPTH, identifying the depth buffer; or
287 * STENCIL, identifying the stencil buffer."
289 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
290 * language. However, revision #33 of the ARB_framebuffer_object spec
293 * "If the default framebuffer is bound to <target>, then <attachment>
294 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
295 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
296 * depth buffer, or the stencil buffer, and <pname> may be
297 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
298 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
300 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
301 * from glext.h, so shipping apps should not use those values.
303 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
304 * support queries of the window system FBO.
307 return &fb
->Attachment
[BUFFER_DEPTH
];
309 return &fb
->Attachment
[BUFFER_STENCIL
];
318 * Remove any texture or renderbuffer attached to the given attachment
319 * point. Update reference counts, etc.
322 _mesa_remove_attachment(struct gl_context
*ctx
,
323 struct gl_renderbuffer_attachment
*att
)
325 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
327 /* tell driver that we're done rendering to this texture. */
328 if (rb
&& rb
->NeedsFinishRenderTexture
)
329 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
331 if (att
->Type
== GL_TEXTURE
) {
332 ASSERT(att
->Texture
);
333 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
334 ASSERT(!att
->Texture
);
336 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
337 ASSERT(!att
->Texture
);
338 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
339 ASSERT(!att
->Renderbuffer
);
342 att
->Complete
= GL_TRUE
;
346 * Verify a couple error conditions that will lead to an incomplete FBO and
347 * may cause problems for the driver's RenderTexture path.
350 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment
*att
)
352 const struct gl_texture_image
*const texImage
=
353 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
355 if (texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
358 if ((texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
359 && att
->Zoffset
>= texImage
->Height
)
360 || (texImage
->TexObject
->Target
!= GL_TEXTURE_1D_ARRAY
361 && att
->Zoffset
>= texImage
->Depth
))
368 * Create a renderbuffer which will be set up by the driver to wrap the
369 * texture image slice.
371 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
372 * to share most of their framebuffer rendering code between winsys,
373 * renderbuffer, and texture attachments.
375 * The allocated renderbuffer uses a non-zero Name so that drivers can check
376 * it for determining vertical orientation, but we use ~0 to make it fairly
377 * unambiguous with actual user (non-texture) renderbuffers.
380 _mesa_update_texture_renderbuffer(struct gl_context
*ctx
,
381 struct gl_framebuffer
*fb
,
382 struct gl_renderbuffer_attachment
*att
)
384 struct gl_texture_image
*texImage
;
385 struct gl_renderbuffer
*rb
;
387 texImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
389 rb
= att
->Renderbuffer
;
391 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
393 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
396 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
398 /* This can't get called on a texture renderbuffer, so set it to NULL
399 * for clarity compared to user renderbuffers.
401 rb
->AllocStorage
= NULL
;
403 rb
->NeedsFinishRenderTexture
= ctx
->Driver
.FinishRenderTexture
!= NULL
;
409 rb
->_BaseFormat
= texImage
->_BaseFormat
;
410 rb
->Format
= texImage
->TexFormat
;
411 rb
->InternalFormat
= texImage
->InternalFormat
;
412 rb
->Width
= texImage
->Width2
;
413 rb
->Height
= texImage
->Height2
;
414 rb
->Depth
= texImage
->Depth2
;
415 rb
->NumSamples
= texImage
->NumSamples
;
416 rb
->TexImage
= texImage
;
418 if (driver_RenderTexture_is_safe(att
))
419 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
423 * Bind a texture object to an attachment point.
424 * The previous binding, if any, will be removed first.
427 _mesa_set_texture_attachment(struct gl_context
*ctx
,
428 struct gl_framebuffer
*fb
,
429 struct gl_renderbuffer_attachment
*att
,
430 struct gl_texture_object
*texObj
,
431 GLenum texTarget
, GLuint level
, GLuint zoffset
,
434 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
436 if (rb
&& rb
->NeedsFinishRenderTexture
)
437 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
439 if (att
->Texture
== texObj
) {
440 /* re-attaching same texture */
441 ASSERT(att
->Type
== GL_TEXTURE
);
445 _mesa_remove_attachment(ctx
, att
);
446 att
->Type
= GL_TEXTURE
;
447 assert(!att
->Texture
);
448 _mesa_reference_texobj(&att
->Texture
, texObj
);
450 invalidate_framebuffer(fb
);
452 /* always update these fields */
453 att
->TextureLevel
= level
;
454 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
455 att
->Zoffset
= zoffset
;
456 att
->Layered
= layered
;
457 att
->Complete
= GL_FALSE
;
459 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
464 * Bind a renderbuffer to an attachment point.
465 * The previous binding, if any, will be removed first.
468 _mesa_set_renderbuffer_attachment(struct gl_context
*ctx
,
469 struct gl_renderbuffer_attachment
*att
,
470 struct gl_renderbuffer
*rb
)
472 /* XXX check if re-doing same attachment, exit early */
473 _mesa_remove_attachment(ctx
, att
);
474 att
->Type
= GL_RENDERBUFFER_EXT
;
475 att
->Texture
= NULL
; /* just to be safe */
476 att
->Complete
= GL_FALSE
;
477 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
482 * Fallback for ctx->Driver.FramebufferRenderbuffer()
483 * Attach a renderbuffer object to a framebuffer object.
486 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
487 struct gl_framebuffer
*fb
,
488 GLenum attachment
, struct gl_renderbuffer
*rb
)
490 struct gl_renderbuffer_attachment
*att
;
492 _glthread_LOCK_MUTEX(fb
->Mutex
);
494 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
497 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
498 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
499 /* do stencil attachment here (depth already done above) */
500 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
502 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
504 rb
->AttachedAnytime
= GL_TRUE
;
507 _mesa_remove_attachment(ctx
, att
);
510 invalidate_framebuffer(fb
);
512 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
517 * Fallback for ctx->Driver.ValidateFramebuffer()
518 * Check if the renderbuffer's formats are supported by the software
520 * Drivers should probably override this.
523 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
526 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
527 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
529 switch (rb
->_BaseFormat
) {
531 case GL_LUMINANCE_ALPHA
:
536 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
540 switch (rb
->Format
) {
541 /* XXX This list is likely incomplete. */
542 case MESA_FORMAT_RGB9_E5_FLOAT
:
543 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
546 /* render buffer format is supported by software rendering */
555 * Return true if the framebuffer has a combined depth/stencil
556 * renderbuffer attached.
559 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
561 const struct gl_renderbuffer_attachment
*depth
=
562 &fb
->Attachment
[BUFFER_DEPTH
];
563 const struct gl_renderbuffer_attachment
*stencil
=
564 &fb
->Attachment
[BUFFER_STENCIL
];
566 if (depth
->Type
== stencil
->Type
) {
567 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
568 depth
->Renderbuffer
== stencil
->Renderbuffer
)
571 if (depth
->Type
== GL_TEXTURE
&&
572 depth
->Texture
== stencil
->Texture
)
584 att_incomplete(const char *msg
)
586 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
587 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
596 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
598 static GLuint msg_id
;
600 _mesa_gl_debug(ctx
, &msg_id
,
601 MESA_DEBUG_TYPE_OTHER
,
602 MESA_DEBUG_SEVERITY_MEDIUM
,
603 "FBO incomplete: %s [%d]\n", msg
, index
);
605 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
606 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
612 * Is the given base format a legal format for a color renderbuffer?
615 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
617 switch (baseFormat
) {
622 case GL_LUMINANCE_ALPHA
:
625 return ctx
->API
== API_OPENGL_COMPAT
&&
626 ctx
->Extensions
.ARB_framebuffer_object
;
629 return ctx
->Extensions
.ARB_texture_rg
;
637 * Is the given base format a legal format for a color renderbuffer?
640 is_format_color_renderable(const struct gl_context
*ctx
, gl_format format
, GLenum internalFormat
)
642 const GLenum baseFormat
=
643 _mesa_get_format_base_format(format
);
646 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
647 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
651 /* Reject additional cases for GLES */
652 switch (internalFormat
) {
672 if (format
== MESA_FORMAT_ARGB2101010
&& internalFormat
!= GL_RGB10_A2
) {
681 * Is the given base format a legal format for a depth/stencil renderbuffer?
684 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
686 switch (baseFormat
) {
687 case GL_DEPTH_COMPONENT
:
688 case GL_DEPTH_STENCIL_EXT
:
697 * Test if an attachment point is complete and update its Complete field.
698 * \param format if GL_COLOR, this is a color attachment point,
699 * if GL_DEPTH, this is a depth component attachment point,
700 * if GL_STENCIL, this is a stencil component attachment point.
703 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
704 struct gl_renderbuffer_attachment
*att
)
706 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
708 /* assume complete */
709 att
->Complete
= GL_TRUE
;
711 /* Look for reasons why the attachment might be incomplete */
712 if (att
->Type
== GL_TEXTURE
) {
713 const struct gl_texture_object
*texObj
= att
->Texture
;
714 struct gl_texture_image
*texImage
;
718 att_incomplete("no texobj");
719 att
->Complete
= GL_FALSE
;
723 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
725 att_incomplete("no teximage");
726 att
->Complete
= GL_FALSE
;
729 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
730 att_incomplete("teximage width/height=0");
731 att
->Complete
= GL_FALSE
;
735 switch (texObj
->Target
) {
737 if (att
->Zoffset
>= texImage
->Depth
) {
738 att_incomplete("bad z offset");
739 att
->Complete
= GL_FALSE
;
743 case GL_TEXTURE_1D_ARRAY
:
744 if (att
->Zoffset
>= texImage
->Height
) {
745 att_incomplete("bad 1D-array layer");
746 att
->Complete
= GL_FALSE
;
750 case GL_TEXTURE_2D_ARRAY
:
751 if (att
->Zoffset
>= texImage
->Depth
) {
752 att_incomplete("bad 2D-array layer");
753 att
->Complete
= GL_FALSE
;
757 case GL_TEXTURE_CUBE_MAP_ARRAY
:
758 if (att
->Zoffset
>= texImage
->Depth
) {
759 att_incomplete("bad cube-array layer");
760 att
->Complete
= GL_FALSE
;
766 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
768 if (format
== GL_COLOR
) {
769 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
770 att_incomplete("bad format");
771 att
->Complete
= GL_FALSE
;
774 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
775 att_incomplete("compressed internalformat");
776 att
->Complete
= GL_FALSE
;
780 else if (format
== GL_DEPTH
) {
781 if (baseFormat
== GL_DEPTH_COMPONENT
) {
784 else if (ctx
->Extensions
.ARB_depth_texture
&&
785 baseFormat
== GL_DEPTH_STENCIL
) {
789 att
->Complete
= GL_FALSE
;
790 att_incomplete("bad depth format");
795 ASSERT(format
== GL_STENCIL
);
796 if (ctx
->Extensions
.ARB_depth_texture
&&
797 baseFormat
== GL_DEPTH_STENCIL
) {
801 /* no such thing as stencil-only textures */
802 att_incomplete("illegal stencil texture");
803 att
->Complete
= GL_FALSE
;
808 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
809 const GLenum baseFormat
=
810 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
812 ASSERT(att
->Renderbuffer
);
813 if (!att
->Renderbuffer
->InternalFormat
||
814 att
->Renderbuffer
->Width
< 1 ||
815 att
->Renderbuffer
->Height
< 1) {
816 att_incomplete("0x0 renderbuffer");
817 att
->Complete
= GL_FALSE
;
820 if (format
== GL_COLOR
) {
821 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
822 att_incomplete("bad renderbuffer color format");
823 att
->Complete
= GL_FALSE
;
827 else if (format
== GL_DEPTH
) {
828 if (baseFormat
== GL_DEPTH_COMPONENT
) {
831 else if (baseFormat
== GL_DEPTH_STENCIL
) {
835 att_incomplete("bad renderbuffer depth format");
836 att
->Complete
= GL_FALSE
;
841 assert(format
== GL_STENCIL
);
842 if (baseFormat
== GL_STENCIL_INDEX
||
843 baseFormat
== GL_DEPTH_STENCIL
) {
847 att
->Complete
= GL_FALSE
;
848 att_incomplete("bad renderbuffer stencil format");
854 ASSERT(att
->Type
== GL_NONE
);
862 * Test if the given framebuffer object is complete and update its
863 * Status field with the results.
864 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
865 * driver to make hardware-specific validation/completeness checks.
866 * Also update the framebuffer's Width and Height fields if the
867 * framebuffer is complete.
870 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
871 struct gl_framebuffer
*fb
)
874 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
875 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
876 GLint numSamples
= -1;
877 GLint fixedSampleLocations
= -1;
880 bool layer_info_valid
= false; /* Covers layer_count and layer_tex_target */
881 GLuint layer_count
= 0, att_layer_count
;
882 GLenum layer_tex_target
= 0;
884 assert(_mesa_is_user_fbo(fb
));
886 /* we're changing framebuffer fields here */
887 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
892 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
893 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
895 /* Start at -2 to more easily loop over all attachment points.
900 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
901 struct gl_renderbuffer_attachment
*att
;
904 GLenum att_tex_target
= GL_NONE
;
907 * XXX for ARB_fbo, only check color buffers that are named by
908 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
911 /* check for attachment completeness
914 att
= &fb
->Attachment
[BUFFER_DEPTH
];
915 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
916 if (!att
->Complete
) {
917 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
918 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
923 att
= &fb
->Attachment
[BUFFER_STENCIL
];
924 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
925 if (!att
->Complete
) {
926 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
927 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
932 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
933 test_attachment_completeness(ctx
, GL_COLOR
, att
);
934 if (!att
->Complete
) {
935 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
936 fbo_incomplete(ctx
, "color attachment incomplete", i
);
941 /* get width, height, format of the renderbuffer/texture
943 if (att
->Type
== GL_TEXTURE
) {
944 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
945 att_tex_target
= att
->Texture
->Target
;
946 minWidth
= MIN2(minWidth
, texImg
->Width
);
947 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
948 minHeight
= MIN2(minHeight
, texImg
->Height
);
949 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
950 f
= texImg
->_BaseFormat
;
951 attFormat
= texImg
->TexFormat
;
954 if (!is_format_color_renderable(ctx
, attFormat
, texImg
->InternalFormat
) &&
955 !is_legal_depth_format(ctx
, f
)) {
956 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
957 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
962 numSamples
= texImg
->NumSamples
;
963 else if (numSamples
!= texImg
->NumSamples
) {
964 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
965 fbo_incomplete(ctx
, "inconsistent sample count", -1);
969 if (fixedSampleLocations
< 0)
970 fixedSampleLocations
= texImg
->FixedSampleLocations
;
971 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
972 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
973 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
977 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
978 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
979 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
980 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
981 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
982 f
= att
->Renderbuffer
->InternalFormat
;
983 attFormat
= att
->Renderbuffer
->Format
;
987 numSamples
= att
->Renderbuffer
->NumSamples
;
988 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
989 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
990 fbo_incomplete(ctx
, "inconsistent sample count", -1);
994 /* RENDERBUFFER has fixedSampleLocations implicitly true */
995 if (fixedSampleLocations
< 0)
996 fixedSampleLocations
= GL_TRUE
;
997 else if (fixedSampleLocations
!= GL_TRUE
) {
998 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
999 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1004 assert(att
->Type
== GL_NONE
);
1008 /* check if integer color */
1009 fb
->_IntegerColor
= _mesa_is_format_integer_color(attFormat
);
1011 /* Update _AllColorBuffersFixedPoint and _HasSNormOrFloatColorBuffer. */
1013 GLenum type
= _mesa_get_format_datatype(attFormat
);
1015 fb
->_AllColorBuffersFixedPoint
=
1016 fb
->_AllColorBuffersFixedPoint
&&
1017 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1019 fb
->_HasSNormOrFloatColorBuffer
=
1020 fb
->_HasSNormOrFloatColorBuffer
||
1021 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1024 /* Error-check width, height, format */
1025 if (numImages
== 1) {
1032 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1033 /* check that width, height, format are same */
1034 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1035 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1036 fbo_incomplete(ctx
, "width or height mismatch", -1);
1039 /* check that all color buffers are the same format */
1040 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1041 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1042 fbo_incomplete(ctx
, "format mismatch", -1);
1048 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1050 if (att
->Type
== GL_RENDERBUFFER
&&
1051 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1052 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1053 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1057 /* Check that layered rendering is consistent. */
1059 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1060 att_layer_count
= 6;
1062 att_layer_count
= att
->Renderbuffer
->Depth
;
1064 att_layer_count
= 0;
1066 if (!layer_info_valid
) {
1067 layer_count
= att_layer_count
;
1068 layer_tex_target
= att_tex_target
;
1069 layer_info_valid
= true;
1070 } else if (layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1071 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1072 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1074 } else if (layer_count
!= att_layer_count
) {
1075 if (layer_count
== 0 || att_layer_count
== 0) {
1076 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1077 fbo_incomplete(ctx
, "framebuffer attachment layer mode is inconsistent", i
);
1079 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
;
1080 fbo_incomplete(ctx
, "framebuffer attachment layer count is inconsistent", i
);
1086 fb
->NumLayers
= layer_count
;
1088 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1089 /* Check that all DrawBuffers are present */
1090 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1091 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1092 const struct gl_renderbuffer_attachment
*att
1093 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
1095 if (att
->Type
== GL_NONE
) {
1096 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1097 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1103 /* Check that the ReadBuffer is present */
1104 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1105 const struct gl_renderbuffer_attachment
*att
1106 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
1108 if (att
->Type
== GL_NONE
) {
1109 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1110 fbo_incomplete(ctx
, "missing readbuffer", -1);
1116 if (numImages
== 0) {
1117 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1118 fbo_incomplete(ctx
, "no attachments", -1);
1122 /* Provisionally set status = COMPLETE ... */
1123 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1125 /* ... but the driver may say the FB is incomplete.
1126 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1129 if (ctx
->Driver
.ValidateFramebuffer
) {
1130 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1131 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1132 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1136 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
1138 * Note that if ARB_framebuffer_object is supported and the attached
1139 * renderbuffers/textures are different sizes, the framebuffer
1140 * width/height will be set to the smallest width/height.
1142 fb
->Width
= minWidth
;
1143 fb
->Height
= minHeight
;
1145 /* finally, update the visual info for the framebuffer */
1146 _mesa_update_framebuffer_visual(ctx
, fb
);
1151 GLboolean GLAPIENTRY
1152 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1154 GET_CURRENT_CONTEXT(ctx
);
1155 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1157 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1158 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
1166 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1168 struct gl_renderbuffer
*newRb
;
1169 GET_CURRENT_CONTEXT(ctx
);
1171 if (target
!= GL_RENDERBUFFER_EXT
) {
1172 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1176 /* No need to flush here since the render buffer binding has no
1177 * effect on rendering state.
1181 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1182 if (newRb
== &DummyRenderbuffer
) {
1183 /* ID was reserved, but no real renderbuffer object made yet */
1186 else if (!newRb
&& !allow_user_names
) {
1187 /* All RB IDs must be Gen'd */
1188 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1193 /* create new renderbuffer object */
1194 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1196 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
1199 ASSERT(newRb
->AllocStorage
);
1200 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1201 newRb
->RefCount
= 1; /* referenced by hash table */
1208 ASSERT(newRb
!= &DummyRenderbuffer
);
1210 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1214 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1216 GET_CURRENT_CONTEXT(ctx
);
1218 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1219 * entry point, but they allow the use of user-generated names.
1221 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1225 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1227 /* This function should not be in the dispatch table for core profile /
1228 * OpenGL 3.1, so execution should never get here in those cases -- no
1229 * need for an explicit test.
1231 bind_renderbuffer(target
, renderbuffer
, true);
1236 * Remove the specified renderbuffer or texture from any attachment point in
1240 * \c true if the renderbuffer was detached from an attachment point. \c
1244 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1245 struct gl_framebuffer
*fb
,
1249 bool progress
= false;
1251 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1252 if (fb
->Attachment
[i
].Texture
== att
1253 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1254 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
1259 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1260 * Completeness," of the OpenGL 3.1 spec says:
1262 * "Performing any of the following actions may change whether the
1263 * framebuffer is considered complete or incomplete:
1267 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1268 * containing an image that is attached to a framebuffer object
1269 * that is bound to the framebuffer."
1272 invalidate_framebuffer(fb
);
1279 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1282 GET_CURRENT_CONTEXT(ctx
);
1284 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1286 for (i
= 0; i
< n
; i
++) {
1287 if (renderbuffers
[i
] > 0) {
1288 struct gl_renderbuffer
*rb
;
1289 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1291 /* check if deleting currently bound renderbuffer object */
1292 if (rb
== ctx
->CurrentRenderbuffer
) {
1294 ASSERT(rb
->RefCount
>= 2);
1295 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1298 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1299 * subsection "Attaching Renderbuffer Images to a Framebuffer," of
1300 * the OpenGL 3.1 spec says:
1302 * "If a renderbuffer object is deleted while its image is
1303 * attached to one or more attachment points in the currently
1304 * bound framebuffer, then it is as if FramebufferRenderbuffer
1305 * had been called, with a renderbuffer of 0, for each
1306 * attachment point to which this image was attached in the
1307 * currently bound framebuffer. In other words, this
1308 * renderbuffer image is first detached from all attachment
1309 * points in the currently bound framebuffer. Note that the
1310 * renderbuffer image is specifically not detached from any
1311 * non-bound framebuffers. Detaching the image from any
1312 * non-bound framebuffers is the responsibility of the
1315 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1316 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1318 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1319 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1320 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1323 /* Remove from hash table immediately, to free the ID.
1324 * But the object will not be freed until it's no longer
1325 * referenced anywhere else.
1327 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1329 if (rb
!= &DummyRenderbuffer
) {
1330 /* no longer referenced by hash table */
1331 _mesa_reference_renderbuffer(&rb
, NULL
);
1340 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1342 GET_CURRENT_CONTEXT(ctx
);
1347 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
1354 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1356 for (i
= 0; i
< n
; i
++) {
1357 GLuint name
= first
+ i
;
1358 renderbuffers
[i
] = name
;
1359 /* insert dummy placeholder into hash table */
1360 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1361 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
1362 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1368 * Given an internal format token for a render buffer, return the
1369 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1370 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1371 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1373 * This is similar to _mesa_base_tex_format() but the set of valid
1374 * internal formats is different.
1376 * Note that even if a format is determined to be legal here, validation
1377 * of the FBO may fail if the format is not supported by the driver/GPU.
1379 * \param internalFormat as passed to glRenderbufferStorage()
1380 * \return the base internal format, or 0 if internalFormat is illegal
1383 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1386 * Notes: some formats such as alpha, luminance, etc. were added
1387 * with GL_ARB_framebuffer_object.
1389 switch (internalFormat
) {
1395 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1400 case GL_LUMINANCE12
:
1401 case GL_LUMINANCE16
:
1402 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1404 case GL_LUMINANCE_ALPHA
:
1405 case GL_LUMINANCE4_ALPHA4
:
1406 case GL_LUMINANCE6_ALPHA2
:
1407 case GL_LUMINANCE8_ALPHA8
:
1408 case GL_LUMINANCE12_ALPHA4
:
1409 case GL_LUMINANCE12_ALPHA12
:
1410 case GL_LUMINANCE16_ALPHA16
:
1411 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1412 ? GL_LUMINANCE_ALPHA
: 0;
1416 case GL_INTENSITY12
:
1417 case GL_INTENSITY16
:
1418 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1429 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1431 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1440 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1442 case GL_SRGB8_ALPHA8_EXT
:
1443 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1444 case GL_STENCIL_INDEX
:
1445 case GL_STENCIL_INDEX1_EXT
:
1446 case GL_STENCIL_INDEX4_EXT
:
1447 case GL_STENCIL_INDEX16_EXT
:
1448 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1449 * OpenGL ES, but Mesa does not currently support them.
1451 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1452 case GL_STENCIL_INDEX8_EXT
:
1453 return GL_STENCIL_INDEX
;
1454 case GL_DEPTH_COMPONENT
:
1455 case GL_DEPTH_COMPONENT32
:
1456 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1457 case GL_DEPTH_COMPONENT16
:
1458 case GL_DEPTH_COMPONENT24
:
1459 return GL_DEPTH_COMPONENT
;
1460 case GL_DEPTH_STENCIL
:
1461 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
1462 case GL_DEPTH24_STENCIL8
:
1463 return GL_DEPTH_STENCIL
;
1464 case GL_DEPTH_COMPONENT32F
:
1465 return ctx
->Version
>= 30
1466 || (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_buffer_float
)
1467 ? GL_DEPTH_COMPONENT
: 0;
1468 case GL_DEPTH32F_STENCIL8
:
1469 return ctx
->Version
>= 30
1470 || (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_buffer_float
)
1471 ? GL_DEPTH_STENCIL
: 0;
1474 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1477 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1481 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1484 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1486 /* signed normalized texture formats */
1490 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1495 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1499 case GL_RGB16_SNORM
:
1500 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1503 case GL_RGBA8_SNORM
:
1504 case GL_RGBA16_SNORM
:
1505 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1507 case GL_ALPHA_SNORM
:
1508 case GL_ALPHA8_SNORM
:
1509 case GL_ALPHA16_SNORM
:
1510 return ctx
->API
== API_OPENGL_COMPAT
&&
1511 ctx
->Extensions
.EXT_texture_snorm
&&
1512 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1513 case GL_LUMINANCE_SNORM
:
1514 case GL_LUMINANCE8_SNORM
:
1515 case GL_LUMINANCE16_SNORM
:
1516 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1518 case GL_LUMINANCE_ALPHA_SNORM
:
1519 case GL_LUMINANCE8_ALPHA8_SNORM
:
1520 case GL_LUMINANCE16_ALPHA16_SNORM
:
1521 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1522 ? GL_LUMINANCE_ALPHA
: 0;
1523 case GL_INTENSITY_SNORM
:
1524 case GL_INTENSITY8_SNORM
:
1525 case GL_INTENSITY16_SNORM
:
1526 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1531 return ((_mesa_is_desktop_gl(ctx
) &&
1532 ctx
->Extensions
.ARB_texture_rg
&&
1533 ctx
->Extensions
.ARB_texture_float
) ||
1534 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1538 return ((_mesa_is_desktop_gl(ctx
) &&
1539 ctx
->Extensions
.ARB_texture_rg
&&
1540 ctx
->Extensions
.ARB_texture_float
) ||
1541 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1545 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1549 return ((_mesa_is_desktop_gl(ctx
) &&
1550 ctx
->Extensions
.ARB_texture_float
) ||
1551 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1553 case GL_ALPHA16F_ARB
:
1554 case GL_ALPHA32F_ARB
:
1555 return ctx
->API
== API_OPENGL_COMPAT
&&
1556 ctx
->Extensions
.ARB_texture_float
&&
1557 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1558 case GL_LUMINANCE16F_ARB
:
1559 case GL_LUMINANCE32F_ARB
:
1560 return ctx
->API
== API_OPENGL_COMPAT
&&
1561 ctx
->Extensions
.ARB_texture_float
&&
1562 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1563 case GL_LUMINANCE_ALPHA16F_ARB
:
1564 case GL_LUMINANCE_ALPHA32F_ARB
:
1565 return ctx
->API
== API_OPENGL_COMPAT
&&
1566 ctx
->Extensions
.ARB_texture_float
&&
1567 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1568 case GL_INTENSITY16F_ARB
:
1569 case GL_INTENSITY32F_ARB
:
1570 return ctx
->API
== API_OPENGL_COMPAT
&&
1571 ctx
->Extensions
.ARB_texture_float
&&
1572 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1574 return (_mesa_is_desktop_gl(ctx
)
1575 && ctx
->Extensions
.EXT_texture_shared_exponent
)
1577 case GL_R11F_G11F_B10F
:
1578 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1579 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1582 case GL_RGBA8UI_EXT
:
1583 case GL_RGBA16UI_EXT
:
1584 case GL_RGBA32UI_EXT
:
1586 case GL_RGBA16I_EXT
:
1587 case GL_RGBA32I_EXT
:
1588 return ctx
->Version
>= 30
1589 || (_mesa_is_desktop_gl(ctx
) &&
1590 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
1593 case GL_RGB16UI_EXT
:
1594 case GL_RGB32UI_EXT
:
1598 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
1606 return ctx
->Version
>= 30
1607 || (_mesa_is_desktop_gl(ctx
) &&
1608 ctx
->Extensions
.ARB_texture_rg
&&
1609 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
1617 return ctx
->Version
>= 30
1618 || (_mesa_is_desktop_gl(ctx
) &&
1619 ctx
->Extensions
.ARB_texture_rg
&&
1620 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
1622 case GL_INTENSITY8I_EXT
:
1623 case GL_INTENSITY8UI_EXT
:
1624 case GL_INTENSITY16I_EXT
:
1625 case GL_INTENSITY16UI_EXT
:
1626 case GL_INTENSITY32I_EXT
:
1627 case GL_INTENSITY32UI_EXT
:
1628 return ctx
->API
== API_OPENGL_COMPAT
&&
1629 ctx
->Extensions
.EXT_texture_integer
&&
1630 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1632 case GL_LUMINANCE8I_EXT
:
1633 case GL_LUMINANCE8UI_EXT
:
1634 case GL_LUMINANCE16I_EXT
:
1635 case GL_LUMINANCE16UI_EXT
:
1636 case GL_LUMINANCE32I_EXT
:
1637 case GL_LUMINANCE32UI_EXT
:
1638 return ctx
->API
== API_OPENGL_COMPAT
&&
1639 ctx
->Extensions
.EXT_texture_integer
&&
1640 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1642 case GL_LUMINANCE_ALPHA8I_EXT
:
1643 case GL_LUMINANCE_ALPHA8UI_EXT
:
1644 case GL_LUMINANCE_ALPHA16I_EXT
:
1645 case GL_LUMINANCE_ALPHA16UI_EXT
:
1646 case GL_LUMINANCE_ALPHA32I_EXT
:
1647 case GL_LUMINANCE_ALPHA32UI_EXT
:
1648 return ctx
->API
== API_OPENGL_COMPAT
&&
1649 ctx
->Extensions
.EXT_texture_integer
&&
1650 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1652 case GL_ALPHA8I_EXT
:
1653 case GL_ALPHA8UI_EXT
:
1654 case GL_ALPHA16I_EXT
:
1655 case GL_ALPHA16UI_EXT
:
1656 case GL_ALPHA32I_EXT
:
1657 case GL_ALPHA32UI_EXT
:
1658 return ctx
->API
== API_OPENGL_COMPAT
&&
1659 ctx
->Extensions
.EXT_texture_integer
&&
1660 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1663 return (_mesa_is_desktop_gl(ctx
) &&
1664 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
1665 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1668 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
1677 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1680 invalidate_rb(GLuint key
, void *data
, void *userData
)
1682 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1683 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
1685 /* If this is a user-created FBO */
1686 if (_mesa_is_user_fbo(fb
)) {
1688 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1689 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1690 if (att
->Type
== GL_RENDERBUFFER
&&
1691 att
->Renderbuffer
== rb
) {
1692 /* Mark fb status as indeterminate to force re-validation */
1701 /** sentinal value, see below */
1702 #define NO_SAMPLES 1000
1706 * Helper function used by _mesa_RenderbufferStorage() and
1707 * _mesa_RenderbufferStorageMultisample().
1708 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
1711 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1712 GLsizei width
, GLsizei height
, GLsizei samples
)
1714 const char *func
= samples
== NO_SAMPLES
?
1715 "glRenderbufferStorage" : "glRenderbufferStorageMultisample";
1716 struct gl_renderbuffer
*rb
;
1718 GLenum sample_count_error
;
1719 GET_CURRENT_CONTEXT(ctx
);
1721 if (MESA_VERBOSE
& VERBOSE_API
) {
1722 if (samples
== NO_SAMPLES
)
1723 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
1725 _mesa_lookup_enum_by_nr(target
),
1726 _mesa_lookup_enum_by_nr(internalFormat
),
1729 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
1731 _mesa_lookup_enum_by_nr(target
),
1732 _mesa_lookup_enum_by_nr(internalFormat
),
1733 width
, height
, samples
);
1736 if (target
!= GL_RENDERBUFFER_EXT
) {
1737 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1741 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1742 if (baseFormat
== 0) {
1743 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
1744 func
, _mesa_lookup_enum_by_nr(internalFormat
));
1748 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1749 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1753 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1754 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1758 if (samples
== NO_SAMPLES
) {
1759 /* NumSamples == 0 indicates non-multisampling */
1763 /* check the sample count;
1764 * note: driver may choose to use more samples than what's requested
1766 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
1767 internalFormat
, samples
);
1768 if (sample_count_error
!= GL_NO_ERROR
) {
1769 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
1774 rb
= ctx
->CurrentRenderbuffer
;
1776 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1780 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1782 if (rb
->InternalFormat
== internalFormat
&&
1783 rb
->Width
== (GLuint
) width
&&
1784 rb
->Height
== (GLuint
) height
&&
1785 rb
->NumSamples
== samples
) {
1786 /* no change in allocation needed */
1790 /* These MUST get set by the AllocStorage func */
1791 rb
->Format
= MESA_FORMAT_NONE
;
1792 rb
->NumSamples
= samples
;
1794 /* Now allocate the storage */
1795 ASSERT(rb
->AllocStorage
);
1796 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1797 /* No error - check/set fields now */
1798 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
1799 assert(rb
->Width
== (GLuint
) width
);
1800 assert(rb
->Height
== (GLuint
) height
);
1801 rb
->InternalFormat
= internalFormat
;
1802 rb
->_BaseFormat
= baseFormat
;
1803 assert(rb
->_BaseFormat
!= 0);
1806 /* Probably ran out of memory - clear the fields */
1809 rb
->Format
= MESA_FORMAT_NONE
;
1810 rb
->InternalFormat
= GL_NONE
;
1811 rb
->_BaseFormat
= GL_NONE
;
1815 /* Invalidate the framebuffers the renderbuffer is attached in. */
1816 if (rb
->AttachedAnytime
) {
1817 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
1823 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1825 struct gl_renderbuffer
*rb
;
1826 GET_CURRENT_CONTEXT(ctx
);
1828 if (!ctx
->Extensions
.OES_EGL_image
) {
1829 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1830 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1834 if (target
!= GL_RENDERBUFFER
) {
1835 _mesa_error(ctx
, GL_INVALID_ENUM
,
1836 "EGLImageTargetRenderbufferStorageOES");
1840 rb
= ctx
->CurrentRenderbuffer
;
1842 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1843 "EGLImageTargetRenderbufferStorageOES");
1847 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1849 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1854 * Helper function for _mesa_GetRenderbufferParameteriv() and
1855 * _mesa_GetFramebufferAttachmentParameteriv()
1856 * We have to be careful to respect the base format. For example, if a
1857 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1858 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1859 * we need to return zero.
1862 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1864 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1865 return _mesa_get_format_bits(format
, pname
);
1873 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
1874 GLsizei width
, GLsizei height
)
1876 /* GL_ARB_fbo says calling this function is equivalent to calling
1877 * glRenderbufferStorageMultisample() with samples=0. We pass in
1878 * a token value here just for error reporting purposes.
1880 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1885 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1886 GLenum internalFormat
,
1887 GLsizei width
, GLsizei height
)
1889 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1894 * OpenGL ES version of glRenderBufferStorage.
1897 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1898 GLsizei width
, GLsizei height
)
1900 switch (internalFormat
) {
1902 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1903 /* choose a closest format */
1904 internalFormat
= GL_RGB5
;
1910 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1915 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1917 struct gl_renderbuffer
*rb
;
1918 GET_CURRENT_CONTEXT(ctx
);
1920 if (target
!= GL_RENDERBUFFER_EXT
) {
1921 _mesa_error(ctx
, GL_INVALID_ENUM
,
1922 "glGetRenderbufferParameterivEXT(target)");
1926 rb
= ctx
->CurrentRenderbuffer
;
1928 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1929 "glGetRenderbufferParameterivEXT");
1933 /* No need to flush here since we're just quering state which is
1934 * not effected by rendering.
1938 case GL_RENDERBUFFER_WIDTH_EXT
:
1939 *params
= rb
->Width
;
1941 case GL_RENDERBUFFER_HEIGHT_EXT
:
1942 *params
= rb
->Height
;
1944 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1945 *params
= rb
->InternalFormat
;
1947 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1948 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1949 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1950 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1951 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1952 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1953 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1955 case GL_RENDERBUFFER_SAMPLES
:
1956 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
1957 || _mesa_is_gles3(ctx
)) {
1958 *params
= rb
->NumSamples
;
1963 _mesa_error(ctx
, GL_INVALID_ENUM
,
1964 "glGetRenderbufferParameterivEXT(target)");
1970 GLboolean GLAPIENTRY
1971 _mesa_IsFramebuffer(GLuint framebuffer
)
1973 GET_CURRENT_CONTEXT(ctx
);
1974 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1976 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1977 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1985 * Check if any of the attachments of the given framebuffer are textures
1986 * (render to texture). Call ctx->Driver.RenderTexture() for such
1990 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1993 ASSERT(ctx
->Driver
.RenderTexture
);
1995 if (_mesa_is_winsys_fbo(fb
))
1996 return; /* can't render to texture with winsys framebuffers */
1998 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1999 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2000 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2001 && driver_RenderTexture_is_safe(att
)) {
2002 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2009 * Examine all the framebuffer's attachments to see if any are textures.
2010 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2011 * notify the device driver that the texture image may have changed.
2014 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2016 if (_mesa_is_winsys_fbo(fb
))
2017 return; /* can't render to texture with winsys framebuffers */
2019 if (ctx
->Driver
.FinishRenderTexture
) {
2021 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2022 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2023 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2024 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2025 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2033 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2035 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2036 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
2037 GLboolean bindReadBuf
, bindDrawBuf
;
2038 GET_CURRENT_CONTEXT(ctx
);
2041 if (ctx
->Extensions
.ARB_framebuffer_object
) {
2042 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
2047 case GL_DRAW_FRAMEBUFFER_EXT
:
2048 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2049 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2052 bindDrawBuf
= GL_TRUE
;
2053 bindReadBuf
= GL_FALSE
;
2055 case GL_READ_FRAMEBUFFER_EXT
:
2056 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2057 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2060 bindDrawBuf
= GL_FALSE
;
2061 bindReadBuf
= GL_TRUE
;
2063 case GL_FRAMEBUFFER_EXT
:
2064 bindDrawBuf
= GL_TRUE
;
2065 bindReadBuf
= GL_TRUE
;
2068 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2073 /* Binding a user-created framebuffer object */
2074 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2075 if (newDrawFb
== &DummyFramebuffer
) {
2076 /* ID was reserved, but no real framebuffer object made yet */
2079 else if (!newDrawFb
&& !allow_user_names
) {
2080 /* All FBO IDs must be Gen'd */
2081 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2086 /* create new framebuffer object */
2087 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2089 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2092 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2094 newReadFb
= newDrawFb
;
2097 /* Binding the window system framebuffer (which was originally set
2098 * with MakeCurrent).
2100 newDrawFb
= ctx
->WinSysDrawBuffer
;
2101 newReadFb
= ctx
->WinSysReadBuffer
;
2105 ASSERT(newDrawFb
!= &DummyFramebuffer
);
2107 /* save pointers to current/old framebuffers */
2108 oldDrawFb
= ctx
->DrawBuffer
;
2109 oldReadFb
= ctx
->ReadBuffer
;
2111 /* check if really changing bindings */
2112 if (oldDrawFb
== newDrawFb
)
2113 bindDrawBuf
= GL_FALSE
;
2114 if (oldReadFb
== newReadFb
)
2115 bindReadBuf
= GL_FALSE
;
2118 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2120 * We also check if we're beginning and/or ending render-to-texture.
2121 * When a framebuffer with texture attachments is unbound, call
2122 * ctx->Driver.FinishRenderTexture().
2123 * When a framebuffer with texture attachments is bound, call
2124 * ctx->Driver.RenderTexture().
2126 * Note that if the ReadBuffer has texture attachments we don't consider
2127 * that a render-to-texture case.
2130 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2132 /* check if old readbuffer was render-to-texture */
2133 check_end_texture_render(ctx
, oldReadFb
);
2135 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2139 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2141 /* check if old framebuffer had any texture attachments */
2143 check_end_texture_render(ctx
, oldDrawFb
);
2145 /* check if newly bound framebuffer has any texture attachments */
2146 check_begin_texture_render(ctx
, newDrawFb
);
2148 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2151 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2152 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
2157 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2159 GET_CURRENT_CONTEXT(ctx
);
2161 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2162 * point, but they allow the use of user-generated names.
2164 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2168 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2170 /* This function should not be in the dispatch table for core profile /
2171 * OpenGL 3.1, so execution should never get here in those cases -- no
2172 * need for an explicit test.
2174 bind_framebuffer(target
, framebuffer
, true);
2178 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2181 GET_CURRENT_CONTEXT(ctx
);
2183 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2185 for (i
= 0; i
< n
; i
++) {
2186 if (framebuffers
[i
] > 0) {
2187 struct gl_framebuffer
*fb
;
2188 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2190 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2192 /* check if deleting currently bound framebuffer object */
2193 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
2194 /* separate draw/read binding points */
2195 if (fb
== ctx
->DrawBuffer
) {
2197 ASSERT(fb
->RefCount
>= 2);
2198 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT
, 0);
2200 if (fb
== ctx
->ReadBuffer
) {
2202 ASSERT(fb
->RefCount
>= 2);
2203 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER_EXT
, 0);
2207 /* only one binding point for read/draw buffers */
2208 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
2210 ASSERT(fb
->RefCount
>= 2);
2211 _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT
, 0);
2215 /* remove from hash table immediately, to free the ID */
2216 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2218 if (fb
!= &DummyFramebuffer
) {
2219 /* But the object will not be freed until it's no longer
2220 * bound in any context.
2222 _mesa_reference_framebuffer(&fb
, NULL
);
2231 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2233 GET_CURRENT_CONTEXT(ctx
);
2238 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
2245 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2247 for (i
= 0; i
< n
; i
++) {
2248 GLuint name
= first
+ i
;
2249 framebuffers
[i
] = name
;
2250 /* insert dummy placeholder into hash table */
2251 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
2252 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
2253 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
2260 _mesa_CheckFramebufferStatus(GLenum target
)
2262 struct gl_framebuffer
*buffer
;
2263 GET_CURRENT_CONTEXT(ctx
);
2265 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2267 if (MESA_VERBOSE
& VERBOSE_API
)
2268 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2269 _mesa_lookup_enum_by_nr(target
));
2271 buffer
= get_framebuffer_target(ctx
, target
);
2273 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
2277 if (_mesa_is_winsys_fbo(buffer
)) {
2278 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2279 if (buffer
!= &IncompleteFramebuffer
) {
2280 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2282 return GL_FRAMEBUFFER_UNDEFINED
;
2286 /* No need to flush here */
2288 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2289 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2292 return buffer
->_Status
;
2297 * Replicate the src attachment point. Used by framebuffer_texture() when
2298 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2299 * GL_STENCIL_ATTACHMENT.
2302 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2303 gl_buffer_index dst
,
2304 gl_buffer_index src
)
2306 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2307 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2309 assert(src_att
->Texture
!= NULL
);
2310 assert(src_att
->Renderbuffer
!= NULL
);
2312 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2313 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2314 dst_att
->Type
= src_att
->Type
;
2315 dst_att
->Complete
= src_att
->Complete
;
2316 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2317 dst_att
->Zoffset
= src_att
->Zoffset
;
2322 * Common code called by glFramebufferTexture1D/2D/3DEXT() and
2323 * glFramebufferTextureLayerEXT().
2325 * \param textarget is the textarget that was passed to the
2326 * glFramebufferTexture...() function, or 0 if the corresponding function
2327 * doesn't have a textarget parameter.
2329 * \param layered is true if this function was called from
2330 * glFramebufferTexture(), false otherwise.
2333 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
2334 GLenum attachment
, GLenum textarget
, GLuint texture
,
2335 GLint level
, GLint zoffset
, GLboolean layered
)
2337 struct gl_renderbuffer_attachment
*att
;
2338 struct gl_texture_object
*texObj
= NULL
;
2339 struct gl_framebuffer
*fb
;
2340 GLenum maxLevelsTarget
;
2342 fb
= get_framebuffer_target(ctx
, target
);
2344 _mesa_error(ctx
, GL_INVALID_ENUM
,
2345 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
2349 /* check framebuffer binding */
2350 if (_mesa_is_winsys_fbo(fb
)) {
2351 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2352 "glFramebufferTexture%sEXT", caller
);
2356 /* The textarget, level, and zoffset parameters are only validated if
2357 * texture is non-zero.
2360 GLboolean err
= GL_TRUE
;
2362 texObj
= _mesa_lookup_texture(ctx
, texture
);
2363 if (texObj
!= NULL
) {
2364 if (textarget
== 0) {
2366 /* We're being called by glFramebufferTexture() and textarget
2369 switch (texObj
->Target
) {
2371 case GL_TEXTURE_1D_ARRAY_EXT
:
2372 case GL_TEXTURE_2D_ARRAY_EXT
:
2373 case GL_TEXTURE_CUBE_MAP
:
2374 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2375 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2380 case GL_TEXTURE_RECTANGLE
:
2381 case GL_TEXTURE_2D_MULTISAMPLE
:
2382 /* These texture types are valid to pass to
2383 * glFramebufferTexture(), but since they aren't layered, it
2384 * is equivalent to calling glFramebufferTexture{1D,2D}().
2388 textarget
= texObj
->Target
;
2395 /* We're being called by glFramebufferTextureLayer() and
2396 * textarget is not used. The only legal texture types for
2397 * that function are 3D and 1D/2D arrays textures.
2399 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
2400 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
2401 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
) &&
2402 (texObj
->Target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) &&
2403 (texObj
->Target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
);
2407 /* Make sure textarget is consistent with the texture's type */
2408 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
2409 ? !_mesa_is_cube_face(textarget
)
2410 : (texObj
->Target
!= textarget
);
2414 /* can't render to a non-existant texture */
2415 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2416 "glFramebufferTexture%sEXT(non existant texture)",
2422 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2423 "glFramebufferTexture%sEXT(texture target mismatch)",
2428 if (texObj
->Target
== GL_TEXTURE_3D
) {
2429 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
2430 if (zoffset
< 0 || zoffset
>= maxSize
) {
2431 _mesa_error(ctx
, GL_INVALID_VALUE
,
2432 "glFramebufferTexture%sEXT(zoffset)", caller
);
2436 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
2437 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) ||
2438 (texObj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
2439 (texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
2441 zoffset
>= (GLint
) ctx
->Const
.MaxArrayTextureLayers
) {
2442 _mesa_error(ctx
, GL_INVALID_VALUE
,
2443 "glFramebufferTexture%sEXT(layer)", caller
);
2448 maxLevelsTarget
= textarget
? textarget
: texObj
->Target
;
2450 (level
>= _mesa_max_texture_levels(ctx
, maxLevelsTarget
))) {
2451 _mesa_error(ctx
, GL_INVALID_VALUE
,
2452 "glFramebufferTexture%sEXT(level)", caller
);
2457 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2459 _mesa_error(ctx
, GL_INVALID_ENUM
,
2460 "glFramebufferTexture%sEXT(attachment)", caller
);
2464 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2466 _glthread_LOCK_MUTEX(fb
->Mutex
);
2468 if (attachment
== GL_DEPTH_ATTACHMENT
&&
2469 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
2470 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
2471 _mesa_tex_target_to_face(textarget
) ==
2472 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
2473 zoffset
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
2474 /* The texture object is already attached to the stencil attachment
2475 * point. Don't create a new renderbuffer; just reuse the stencil
2476 * attachment's. This is required to prevent a GL error in
2477 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
2479 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
2481 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
2482 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
2483 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
2484 _mesa_tex_target_to_face(textarget
) ==
2485 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
2486 zoffset
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
2487 /* As above, but with depth and stencil transposed. */
2488 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
2491 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
2492 level
, zoffset
, layered
);
2493 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2494 /* Above we created a new renderbuffer and attached it to the
2495 * depth attachment point. Now attach it to the stencil attachment
2498 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
2499 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
2504 /* Set the render-to-texture flag. We'll check this flag in
2505 * glTexImage() and friends to determine if we need to revalidate
2506 * any FBOs that might be rendering into this texture.
2507 * This flag never gets cleared since it's non-trivial to determine
2508 * when all FBOs might be done rendering to this texture. That's OK
2509 * though since it's uncommon to render to a texture then repeatedly
2510 * call glTexImage() to change images in the texture.
2512 texObj
->_RenderToTexture
= GL_TRUE
;
2515 _mesa_remove_attachment(ctx
, att
);
2516 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2517 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
2518 _mesa_remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
2522 invalidate_framebuffer(fb
);
2524 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
2530 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
2531 GLenum textarget
, GLuint texture
, GLint level
)
2533 GET_CURRENT_CONTEXT(ctx
);
2538 switch (textarget
) {
2542 case GL_TEXTURE_1D_ARRAY
:
2543 error
= !ctx
->Extensions
.EXT_texture_array
;
2550 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2551 "glFramebufferTexture1DEXT(textarget=%s)",
2552 _mesa_lookup_enum_by_nr(textarget
));
2557 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
2558 level
, 0, GL_FALSE
);
2563 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
2564 GLenum textarget
, GLuint texture
, GLint level
)
2566 GET_CURRENT_CONTEXT(ctx
);
2571 switch (textarget
) {
2575 case GL_TEXTURE_RECTANGLE
:
2576 error
= _mesa_is_gles(ctx
)
2577 || !ctx
->Extensions
.NV_texture_rectangle
;
2579 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2580 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2581 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2582 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2583 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2584 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2585 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
2587 case GL_TEXTURE_2D_ARRAY
:
2588 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
2589 || !ctx
->Extensions
.EXT_texture_array
;
2591 case GL_TEXTURE_2D_MULTISAMPLE
:
2592 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2593 error
= _mesa_is_gles(ctx
)
2594 || !ctx
->Extensions
.ARB_texture_multisample
;
2601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2602 "glFramebufferTexture2DEXT(textarget=%s)",
2603 _mesa_lookup_enum_by_nr(textarget
));
2608 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
2609 level
, 0, GL_FALSE
);
2614 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
2615 GLenum textarget
, GLuint texture
,
2616 GLint level
, GLint zoffset
)
2618 GET_CURRENT_CONTEXT(ctx
);
2620 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
2621 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2622 "glFramebufferTexture3DEXT(textarget)");
2626 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
2627 level
, zoffset
, GL_FALSE
);
2632 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
2633 GLuint texture
, GLint level
, GLint layer
)
2635 GET_CURRENT_CONTEXT(ctx
);
2637 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2638 level
, layer
, GL_FALSE
);
2643 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
2644 GLuint texture
, GLint level
)
2646 GET_CURRENT_CONTEXT(ctx
);
2648 if (_mesa_has_geometry_shaders(ctx
)) {
2649 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2652 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2653 "unsupported function (glFramebufferTexture) called");
2659 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
2660 GLenum renderbufferTarget
,
2661 GLuint renderbuffer
)
2663 struct gl_renderbuffer_attachment
*att
;
2664 struct gl_framebuffer
*fb
;
2665 struct gl_renderbuffer
*rb
;
2666 GET_CURRENT_CONTEXT(ctx
);
2668 fb
= get_framebuffer_target(ctx
, target
);
2670 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFramebufferRenderbufferEXT(target)");
2674 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
2675 _mesa_error(ctx
, GL_INVALID_ENUM
,
2676 "glFramebufferRenderbufferEXT(renderbufferTarget)");
2680 if (_mesa_is_winsys_fbo(fb
)) {
2681 /* Can't attach new renderbuffers to a window system framebuffer */
2682 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
2686 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2688 _mesa_error(ctx
, GL_INVALID_ENUM
,
2689 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2690 _mesa_lookup_enum_by_nr(attachment
));
2695 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2697 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2698 "glFramebufferRenderbufferEXT(non-existant"
2699 " renderbuffer %u)", renderbuffer
);
2702 else if (rb
== &DummyRenderbuffer
) {
2703 /* This is what NVIDIA does */
2704 _mesa_error(ctx
, GL_INVALID_VALUE
,
2705 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2711 /* remove renderbuffer attachment */
2715 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
2716 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
2717 /* make sure the renderbuffer is a depth/stencil format */
2718 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2719 if (baseFormat
!= GL_DEPTH_STENCIL
) {
2720 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2721 "glFramebufferRenderbufferEXT(renderbuffer"
2722 " is not DEPTH_STENCIL format)");
2728 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2730 assert(ctx
->Driver
.FramebufferRenderbuffer
);
2731 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
2733 /* Some subsequent GL commands may depend on the framebuffer's visual
2734 * after the binding is updated. Update visual info now.
2736 _mesa_update_framebuffer_visual(ctx
, fb
);
2741 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
2742 GLenum pname
, GLint
*params
)
2744 const struct gl_renderbuffer_attachment
*att
;
2745 struct gl_framebuffer
*buffer
;
2747 GET_CURRENT_CONTEXT(ctx
);
2749 /* The error differs in GL and GLES. */
2750 err
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
2752 buffer
= get_framebuffer_target(ctx
, target
);
2754 _mesa_error(ctx
, GL_INVALID_ENUM
,
2755 "glGetFramebufferAttachmentParameterivEXT(target)");
2759 if (_mesa_is_winsys_fbo(buffer
)) {
2760 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
2763 * "If the framebuffer currently bound to target is zero, then
2764 * INVALID_OPERATION is generated."
2766 * The EXT_framebuffer_object spec has the same wording, and the
2767 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
2770 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2771 && !_mesa_is_gles3(ctx
)) {
2772 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2773 "glGetFramebufferAttachmentParameteriv(bound FBO = 0)");
2777 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
2778 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
2779 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2780 "glGetFramebufferAttachmentParameteriv(attachment)");
2783 /* the default / window-system FBO */
2784 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2787 /* user-created framebuffer FBO */
2788 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2792 _mesa_error(ctx
, GL_INVALID_ENUM
,
2793 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2797 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2798 /* the depth and stencil attachments must point to the same buffer */
2799 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2800 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2801 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2802 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2803 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2804 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2805 " attachments differ)");
2810 /* No need to flush here */
2813 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2814 *params
= _mesa_is_winsys_fbo(buffer
)
2815 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2817 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2818 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2819 *params
= att
->Renderbuffer
->Name
;
2821 else if (att
->Type
== GL_TEXTURE
) {
2822 *params
= att
->Texture
->Name
;
2825 assert(att
->Type
== GL_NONE
);
2826 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
2829 goto invalid_pname_enum
;
2833 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2834 if (att
->Type
== GL_TEXTURE
) {
2835 *params
= att
->TextureLevel
;
2837 else if (att
->Type
== GL_NONE
) {
2838 _mesa_error(ctx
, err
,
2839 "glGetFramebufferAttachmentParameterivEXT(pname)");
2842 goto invalid_pname_enum
;
2845 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2846 if (att
->Type
== GL_TEXTURE
) {
2847 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2848 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2854 else if (att
->Type
== GL_NONE
) {
2855 _mesa_error(ctx
, err
,
2856 "glGetFramebufferAttachmentParameterivEXT(pname)");
2859 goto invalid_pname_enum
;
2862 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2863 if (ctx
->API
== API_OPENGLES
) {
2864 goto invalid_pname_enum
;
2865 } else if (att
->Type
== GL_NONE
) {
2866 _mesa_error(ctx
, err
,
2867 "glGetFramebufferAttachmentParameterivEXT(pname)");
2868 } else if (att
->Type
== GL_TEXTURE
) {
2869 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2870 *params
= att
->Zoffset
;
2877 goto invalid_pname_enum
;
2880 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2881 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2882 && !_mesa_is_gles3(ctx
)) {
2883 goto invalid_pname_enum
;
2885 else if (att
->Type
== GL_NONE
) {
2886 _mesa_error(ctx
, err
,
2887 "glGetFramebufferAttachmentParameterivEXT(pname)");
2890 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
2891 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2894 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2895 * if the sRGB conversion is unsupported. */
2896 *params
= GL_LINEAR
;
2900 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2901 if ((ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_framebuffer_object
)
2902 && ctx
->API
!= API_OPENGL_CORE
2903 && !_mesa_is_gles3(ctx
)) {
2904 goto invalid_pname_enum
;
2906 else if (att
->Type
== GL_NONE
) {
2907 _mesa_error(ctx
, err
,
2908 "glGetFramebufferAttachmentParameterivEXT(pname)");
2911 gl_format format
= att
->Renderbuffer
->Format
;
2913 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
2916 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
2917 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
2918 * generate an INVALID_OPERATION error.
2920 if (_mesa_is_gles3(ctx
) && attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2921 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2922 "glGetFramebufferAttachmentParameteriv(cannot query "
2923 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
2924 "GL_DEPTH_STENCIL_ATTACHMENT");
2928 if (format
== MESA_FORMAT_S8
) {
2932 else if (format
== MESA_FORMAT_Z32_FLOAT_X24S8
) {
2933 /* depends on the attachment parameter */
2934 if (attachment
== GL_STENCIL_ATTACHMENT
) {
2942 *params
= _mesa_get_format_datatype(format
);
2946 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2947 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2948 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2949 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2950 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2951 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2952 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2953 && !_mesa_is_gles3(ctx
)) {
2954 goto invalid_pname_enum
;
2956 else if (att
->Type
== GL_NONE
) {
2957 _mesa_error(ctx
, err
,
2958 "glGetFramebufferAttachmentParameterivEXT(pname)");
2960 else if (att
->Texture
) {
2961 const struct gl_texture_image
*texImage
=
2962 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2965 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2966 texImage
->TexFormat
);
2972 else if (att
->Renderbuffer
) {
2973 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2974 att
->Renderbuffer
->Format
);
2977 _mesa_problem(ctx
, "glGetFramebufferAttachmentParameterivEXT:"
2978 " invalid FBO attachment structure");
2981 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
2982 if (!_mesa_has_geometry_shaders(ctx
)) {
2983 goto invalid_pname_enum
;
2984 } else if (att
->Type
== GL_TEXTURE
) {
2985 *params
= att
->Layered
;
2986 } else if (att
->Type
== GL_NONE
) {
2987 _mesa_error(ctx
, err
,
2988 "glGetFramebufferAttachmentParameteriv(pname)");
2990 goto invalid_pname_enum
;
2994 goto invalid_pname_enum
;
3000 _mesa_error(ctx
, GL_INVALID_ENUM
,
3001 "glGetFramebufferAttachmentParameteriv(pname)");
3007 _mesa_GenerateMipmap(GLenum target
)
3009 struct gl_texture_image
*srcImage
;
3010 struct gl_texture_object
*texObj
;
3013 GET_CURRENT_CONTEXT(ctx
);
3015 FLUSH_VERTICES(ctx
, 0);
3019 error
= _mesa_is_gles(ctx
);
3025 error
= ctx
->API
== API_OPENGLES
;
3027 case GL_TEXTURE_CUBE_MAP
:
3028 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
3030 case GL_TEXTURE_1D_ARRAY
:
3031 error
= _mesa_is_gles(ctx
) || !ctx
->Extensions
.EXT_texture_array
;
3033 case GL_TEXTURE_2D_ARRAY
:
3034 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
3035 || !ctx
->Extensions
.EXT_texture_array
;
3042 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target=%s)",
3043 _mesa_lookup_enum_by_nr(target
));
3047 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3049 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
3054 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
3055 !_mesa_cube_complete(texObj
)) {
3056 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3057 "glGenerateMipmap(incomplete cube map)");
3061 _mesa_lock_texture(ctx
, texObj
);
3063 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, texObj
->BaseLevel
);
3065 _mesa_unlock_texture(ctx
, texObj
);
3066 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3067 "glGenerateMipmap(zero size base image)");
3071 if (_mesa_is_enum_format_integer(srcImage
->InternalFormat
) ||
3072 _mesa_is_depthstencil_format(srcImage
->InternalFormat
) ||
3073 _mesa_is_stencil_format(srcImage
->InternalFormat
)) {
3074 _mesa_unlock_texture(ctx
, texObj
);
3075 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3076 "glGenerateMipmap(invalid internal format)");
3080 if (target
== GL_TEXTURE_CUBE_MAP
) {
3082 for (face
= 0; face
< 6; face
++)
3083 ctx
->Driver
.GenerateMipmap(ctx
,
3084 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
3088 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3090 _mesa_unlock_texture(ctx
, texObj
);
3094 static const struct gl_renderbuffer_attachment
*
3095 find_attachment(const struct gl_framebuffer
*fb
,
3096 const struct gl_renderbuffer
*rb
)
3099 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
3100 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
3101 return &fb
->Attachment
[i
];
3108 * Helper function for checking if the datatypes of color buffers are
3109 * compatible for glBlitFramebuffer. From the 3.1 spec, page 198:
3111 * "GL_INVALID_OPERATION is generated if mask contains GL_COLOR_BUFFER_BIT
3112 * and any of the following conditions hold:
3113 * - The read buffer contains fixed-point or floating-point values and any
3114 * draw buffer contains neither fixed-point nor floating-point values.
3115 * - The read buffer contains unsigned integer values and any draw buffer
3116 * does not contain unsigned integer values.
3117 * - The read buffer contains signed integer values and any draw buffer
3118 * does not contain signed integer values."
3121 compatible_color_datatypes(gl_format srcFormat
, gl_format dstFormat
)
3123 GLenum srcType
= _mesa_get_format_datatype(srcFormat
);
3124 GLenum dstType
= _mesa_get_format_datatype(dstFormat
);
3126 if (srcType
!= GL_INT
&& srcType
!= GL_UNSIGNED_INT
) {
3127 assert(srcType
== GL_UNSIGNED_NORMALIZED
||
3128 srcType
== GL_SIGNED_NORMALIZED
||
3129 srcType
== GL_FLOAT
);
3130 /* Boil any of those types down to GL_FLOAT */
3134 if (dstType
!= GL_INT
&& dstType
!= GL_UNSIGNED_INT
) {
3135 assert(dstType
== GL_UNSIGNED_NORMALIZED
||
3136 dstType
== GL_SIGNED_NORMALIZED
||
3137 dstType
== GL_FLOAT
);
3138 /* Boil any of those types down to GL_FLOAT */
3142 return srcType
== dstType
;
3147 compatible_resolve_formats(const struct gl_renderbuffer
*readRb
,
3148 const struct gl_renderbuffer
*drawRb
)
3150 GLenum readFormat
, drawFormat
;
3152 /* The simple case where we know the backing Mesa formats are the same.
3154 if (_mesa_get_srgb_format_linear(readRb
->Format
) ==
3155 _mesa_get_srgb_format_linear(drawRb
->Format
)) {
3159 /* The Mesa formats are different, so we must check whether the internal
3160 * formats are compatible.
3162 * Under some circumstances, the user may request e.g. two GL_RGBA8
3163 * textures and get two entirely different Mesa formats like RGBA8888 and
3164 * ARGB8888. Drivers behaving like that should be able to cope with
3165 * non-matching formats by themselves, because it's not the user's fault.
3167 * Blits between linear and sRGB formats are also allowed.
3169 readFormat
= _mesa_get_nongeneric_internalformat(readRb
->InternalFormat
);
3170 drawFormat
= _mesa_get_nongeneric_internalformat(drawRb
->InternalFormat
);
3171 readFormat
= _mesa_get_linear_internalformat(readFormat
);
3172 drawFormat
= _mesa_get_linear_internalformat(drawFormat
);
3174 if (readFormat
== drawFormat
) {
3182 is_valid_blit_filter(const struct gl_context
*ctx
, GLenum filter
)
3188 case GL_SCALED_RESOLVE_FASTEST_EXT
:
3189 case GL_SCALED_RESOLVE_NICEST_EXT
:
3190 return ctx
->Extensions
.EXT_framebuffer_multisample_blit_scaled
;
3197 * Blit rectangular region, optionally from one framebuffer to another.
3199 * Note, if the src buffer is multisampled and the dest is not, this is
3200 * when the samples must be resolved to a single color.
3203 _mesa_BlitFramebuffer(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
3204 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
3205 GLbitfield mask
, GLenum filter
)
3207 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
3208 GL_DEPTH_BUFFER_BIT
|
3209 GL_STENCIL_BUFFER_BIT
);
3210 const struct gl_framebuffer
*readFb
, *drawFb
;
3211 GET_CURRENT_CONTEXT(ctx
);
3213 FLUSH_VERTICES(ctx
, 0);
3215 if (MESA_VERBOSE
& VERBOSE_API
)
3217 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
3218 srcX0
, srcY0
, srcX1
, srcY1
,
3219 dstX0
, dstY0
, dstX1
, dstY1
,
3220 mask
, _mesa_lookup_enum_by_nr(filter
));
3222 if (ctx
->NewState
) {
3223 _mesa_update_state(ctx
);
3226 readFb
= ctx
->ReadBuffer
;
3227 drawFb
= ctx
->DrawBuffer
;
3229 if (!readFb
|| !drawFb
) {
3230 /* This will normally never happen but someday we may want to
3231 * support MakeCurrent() with no drawables.
3236 /* check for complete framebuffers */
3237 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
3238 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
3239 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
3240 "glBlitFramebufferEXT(incomplete draw/read buffers)");
3244 if (!is_valid_blit_filter(ctx
, filter
)) {
3245 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(%s)",
3246 _mesa_lookup_enum_by_nr(filter
));
3250 if ((filter
== GL_SCALED_RESOLVE_FASTEST_EXT
||
3251 filter
== GL_SCALED_RESOLVE_NICEST_EXT
) &&
3252 (readFb
->Visual
.samples
== 0 || drawFb
->Visual
.samples
> 0)) {
3253 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT(%s)",
3254 _mesa_lookup_enum_by_nr(filter
));
3258 if (mask
& ~legalMaskBits
) {
3259 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
3263 /* depth/stencil must be blitted with nearest filtering */
3264 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
3265 && filter
!= GL_NEAREST
) {
3266 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3267 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
3271 /* get color read/draw renderbuffers */
3272 if (mask
& GL_COLOR_BUFFER_BIT
) {
3273 const GLuint numColorDrawBuffers
= ctx
->DrawBuffer
->_NumColorDrawBuffers
;
3274 const struct gl_renderbuffer
*colorReadRb
= readFb
->_ColorReadBuffer
;
3275 const struct gl_renderbuffer
*colorDrawRb
= NULL
;
3278 /* From the EXT_framebuffer_object spec:
3280 * "If a buffer is specified in <mask> and does not exist in both
3281 * the read and draw framebuffers, the corresponding bit is silently
3284 if (!colorReadRb
|| numColorDrawBuffers
== 0) {
3285 mask
&= ~GL_COLOR_BUFFER_BIT
;
3288 for (i
= 0; i
< numColorDrawBuffers
; i
++) {
3289 colorDrawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
3293 /* Page 193 (page 205 of the PDF) in section 4.3.2 of the OpenGL
3294 * ES 3.0.1 spec says:
3296 * "If the source and destination buffers are identical, an
3297 * INVALID_OPERATION error is generated. Different mipmap
3298 * levels of a texture, different layers of a three-
3299 * dimensional texture or two-dimensional array texture, and
3300 * different faces of a cube map texture do not constitute
3301 * identical buffers."
3303 if (_mesa_is_gles3(ctx
) && (colorDrawRb
== colorReadRb
)) {
3304 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3305 "glBlitFramebuffer(source and destination color "
3306 "buffer cannot be the same)");
3310 if (!compatible_color_datatypes(colorReadRb
->Format
,
3311 colorDrawRb
->Format
)) {
3312 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3313 "glBlitFramebufferEXT(color buffer datatypes mismatch)");
3316 /* extra checks for multisample copies... */
3317 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
3318 /* color formats must match */
3319 if (!compatible_resolve_formats(colorReadRb
, colorDrawRb
)) {
3320 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3321 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
3326 if (filter
!= GL_NEAREST
) {
3327 /* From EXT_framebuffer_multisample_blit_scaled specification:
3328 * "Calling BlitFramebuffer will result in an INVALID_OPERATION error
3329 * if filter is not NEAREST and read buffer contains integer data."
3331 GLenum type
= _mesa_get_format_datatype(colorReadRb
->Format
);
3332 if (type
== GL_INT
|| type
== GL_UNSIGNED_INT
) {
3333 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3334 "glBlitFramebufferEXT(integer color type)");
3341 if (mask
& GL_STENCIL_BUFFER_BIT
) {
3342 struct gl_renderbuffer
*readRb
=
3343 readFb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3344 struct gl_renderbuffer
*drawRb
=
3345 drawFb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3347 /* From the EXT_framebuffer_object spec:
3349 * "If a buffer is specified in <mask> and does not exist in both
3350 * the read and draw framebuffers, the corresponding bit is silently
3353 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
3354 mask
&= ~GL_STENCIL_BUFFER_BIT
;
3357 int read_z_bits
, draw_z_bits
;
3359 if (_mesa_is_gles3(ctx
) && (drawRb
== readRb
)) {
3360 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3361 "glBlitFramebuffer(source and destination stencil "
3362 "buffer cannot be the same)");
3366 if (_mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
3367 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
3368 /* There is no need to check the stencil datatype here, because
3369 * there is only one: GL_UNSIGNED_INT.
3371 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3372 "glBlitFramebuffer(stencil attachment format mismatch)");
3376 read_z_bits
= _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
);
3377 draw_z_bits
= _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
);
3379 /* If both buffers also have depth data, the depth formats must match
3380 * as well. If one doesn't have depth, it's not blitted, so we should
3381 * ignore the depth format check.
3383 if (read_z_bits
> 0 && draw_z_bits
> 0 &&
3384 (read_z_bits
!= draw_z_bits
||
3385 _mesa_get_format_datatype(readRb
->Format
) !=
3386 _mesa_get_format_datatype(drawRb
->Format
))) {
3388 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebuffer"
3389 "(stencil attachment depth format mismatch)");
3395 if (mask
& GL_DEPTH_BUFFER_BIT
) {
3396 struct gl_renderbuffer
*readRb
=
3397 readFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3398 struct gl_renderbuffer
*drawRb
=
3399 drawFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3401 /* From the EXT_framebuffer_object spec:
3403 * "If a buffer is specified in <mask> and does not exist in both
3404 * the read and draw framebuffers, the corresponding bit is silently
3407 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
3408 mask
&= ~GL_DEPTH_BUFFER_BIT
;
3411 int read_s_bit
, draw_s_bit
;
3413 if (_mesa_is_gles3(ctx
) && (drawRb
== readRb
)) {
3414 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3415 "glBlitFramebuffer(source and destination depth "
3416 "buffer cannot be the same)");
3420 if ((_mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
3421 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) ||
3422 (_mesa_get_format_datatype(readRb
->Format
) !=
3423 _mesa_get_format_datatype(drawRb
->Format
))) {
3424 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3425 "glBlitFramebuffer(depth attachment format mismatch)");
3429 read_s_bit
= _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
);
3430 draw_s_bit
= _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
);
3432 /* If both buffers also have stencil data, the stencil formats must
3433 * match as well. If one doesn't have stencil, it's not blitted, so
3434 * we should ignore the stencil format check.
3436 if (read_s_bit
> 0 && draw_s_bit
> 0 && read_s_bit
!= draw_s_bit
) {
3437 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebuffer"
3438 "(depth attachment stencil bits mismatch)");
3445 if (_mesa_is_gles3(ctx
)) {
3446 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3449 * "If SAMPLE_BUFFERS for the draw framebuffer is greater than zero,
3450 * an INVALID_OPERATION error is generated."
3452 if (drawFb
->Visual
.samples
> 0) {
3453 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3454 "glBlitFramebuffer(destination samples must be 0)");
3458 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3461 * "If SAMPLE_BUFFERS for the read framebuffer is greater than zero,
3462 * no copy is performed and an INVALID_OPERATION error is generated
3463 * if the formats of the read and draw framebuffers are not
3464 * identical or if the source and destination rectangles are not
3465 * defined with the same (X0, Y0) and (X1, Y1) bounds."
3467 * The format check was made above because desktop OpenGL has the same
3470 if (readFb
->Visual
.samples
> 0
3471 && (srcX0
!= dstX0
|| srcY0
!= dstY0
3472 || srcX1
!= dstX1
|| srcY1
!= dstY1
)) {
3473 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3474 "glBlitFramebuffer(bad src/dst multisample region)");
3478 if (readFb
->Visual
.samples
> 0 &&
3479 drawFb
->Visual
.samples
> 0 &&
3480 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
3481 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3482 "glBlitFramebufferEXT(mismatched samples)");
3486 /* extra checks for multisample copies... */
3487 if ((readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) &&
3488 (filter
== GL_NEAREST
|| filter
== GL_LINEAR
)) {
3489 /* src and dest region sizes must be the same */
3490 if (abs(srcX1
- srcX0
) != abs(dstX1
- dstX0
) ||
3491 abs(srcY1
- srcY0
) != abs(dstY1
- dstY0
)) {
3492 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3493 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
3499 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
3500 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
3506 const struct gl_renderbuffer
*colorReadRb
= readFb
->_ColorReadBuffer
;
3507 const struct gl_renderbuffer
*colorDrawRb
= NULL
;
3510 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
3512 srcX0
, srcY0
, srcX1
, srcY1
,
3513 dstX0
, dstY0
, dstX1
, dstY1
,
3516 const struct gl_renderbuffer_attachment
*att
;
3518 att
= find_attachment(readFb
, colorReadRb
);
3519 printf(" Src FBO %u RB %u (%dx%d) ",
3520 readFb
->Name
, colorReadRb
->Name
,
3521 colorReadRb
->Width
, colorReadRb
->Height
);
3522 if (att
&& att
->Texture
) {
3523 printf("Tex %u tgt 0x%x level %u face %u",
3525 att
->Texture
->Target
,
3531 /* Print all active color render buffers */
3532 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
3533 colorDrawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
3537 att
= find_attachment(drawFb
, colorDrawRb
);
3538 printf(" Dst FBO %u RB %u (%dx%d) ",
3539 drawFb
->Name
, colorDrawRb
->Name
,
3540 colorDrawRb
->Width
, colorDrawRb
->Height
);
3541 if (att
&& att
->Texture
) {
3542 printf("Tex %u tgt 0x%x level %u face %u",
3544 att
->Texture
->Target
,
3554 (srcX1
- srcX0
) == 0 || (srcY1
- srcY0
) == 0 ||
3555 (dstX1
- dstX0
) == 0 || (dstY1
- dstY0
) == 0) {
3559 ASSERT(ctx
->Driver
.BlitFramebuffer
);
3560 ctx
->Driver
.BlitFramebuffer(ctx
,
3561 srcX0
, srcY0
, srcX1
, srcY1
,
3562 dstX0
, dstY0
, dstX1
, dstY1
,
3568 invalidate_framebuffer_storage(GLenum target
, GLsizei numAttachments
,
3569 const GLenum
*attachments
, GLint x
, GLint y
,
3570 GLsizei width
, GLsizei height
, const char *name
)
3573 struct gl_framebuffer
*fb
;
3574 GET_CURRENT_CONTEXT(ctx
);
3576 fb
= get_framebuffer_target(ctx
, target
);
3578 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", name
);
3582 if (numAttachments
< 0) {
3583 _mesa_error(ctx
, GL_INVALID_VALUE
,
3584 "%s(numAttachments < 0)", name
);
3588 /* The GL_ARB_invalidate_subdata spec says:
3590 * "If an attachment is specified that does not exist in the
3591 * framebuffer bound to <target>, it is ignored."
3595 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
3596 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
3597 * INVALID_OPERATION is generated."
3599 * No mention is made of GL_AUXi being out of range. Therefore, we allow
3600 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
3601 * set of retrictions).
3603 for (i
= 0; i
< numAttachments
; i
++) {
3604 if (_mesa_is_winsys_fbo(fb
)) {
3605 switch (attachments
[i
]) {
3611 /* Accumulation buffers and auxilary buffers were removed in
3612 * OpenGL 3.1, and they never existed in OpenGL ES.
3614 if (ctx
->API
!= API_OPENGL_COMPAT
)
3624 case GL_FRONT_RIGHT
:
3625 if (!_mesa_is_desktop_gl(ctx
))
3632 switch (attachments
[i
]) {
3633 case GL_DEPTH_ATTACHMENT
:
3634 case GL_STENCIL_ATTACHMENT
:
3636 case GL_COLOR_ATTACHMENT0
:
3637 case GL_COLOR_ATTACHMENT1
:
3638 case GL_COLOR_ATTACHMENT2
:
3639 case GL_COLOR_ATTACHMENT3
:
3640 case GL_COLOR_ATTACHMENT4
:
3641 case GL_COLOR_ATTACHMENT5
:
3642 case GL_COLOR_ATTACHMENT6
:
3643 case GL_COLOR_ATTACHMENT7
:
3644 case GL_COLOR_ATTACHMENT8
:
3645 case GL_COLOR_ATTACHMENT9
:
3646 case GL_COLOR_ATTACHMENT10
:
3647 case GL_COLOR_ATTACHMENT11
:
3648 case GL_COLOR_ATTACHMENT12
:
3649 case GL_COLOR_ATTACHMENT13
:
3650 case GL_COLOR_ATTACHMENT14
:
3651 case GL_COLOR_ATTACHMENT15
: {
3652 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
3653 if (k
>= ctx
->Const
.MaxColorAttachments
) {
3654 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3655 "%s(attachment >= max. color attachments)", name
);
3666 /* We don't actually do anything for this yet. Just return after
3667 * validating the parameters and generating the required errors.
3672 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(attachment)", name
);
3677 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
3678 const GLenum
*attachments
, GLint x
, GLint y
,
3679 GLsizei width
, GLsizei height
)
3681 invalidate_framebuffer_storage(target
, numAttachments
, attachments
,
3682 x
, y
, width
, height
,
3683 "glInvalidateSubFramebuffer");
3687 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
3688 const GLenum
*attachments
)
3690 /* The GL_ARB_invalidate_subdata spec says:
3694 * void InvalidateFramebuffer(enum target,
3695 * sizei numAttachments,
3696 * const enum *attachments);
3698 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
3699 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
3700 * <MAX_VIEWPORT_DIMS[1]> respectively."
3702 invalidate_framebuffer_storage(target
, numAttachments
, attachments
,
3703 0, 0, MAX_VIEWPORT_WIDTH
, MAX_VIEWPORT_HEIGHT
,
3704 "glInvalidateFramebuffer");
3708 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
3709 const GLenum
*attachments
)
3711 struct gl_framebuffer
*fb
;
3714 GET_CURRENT_CONTEXT(ctx
);
3716 fb
= get_framebuffer_target(ctx
, target
);
3718 _mesa_error(ctx
, GL_INVALID_ENUM
,
3719 "glDiscardFramebufferEXT(target %s)",
3720 _mesa_lookup_enum_by_nr(target
));
3724 if (numAttachments
< 0) {
3725 _mesa_error(ctx
, GL_INVALID_VALUE
,
3726 "glDiscardFramebufferEXT(numAttachments < 0)");
3730 for (i
= 0; i
< numAttachments
; i
++) {
3731 switch (attachments
[i
]) {
3735 if (_mesa_is_user_fbo(fb
))
3738 case GL_COLOR_ATTACHMENT0
:
3739 case GL_DEPTH_ATTACHMENT
:
3740 case GL_STENCIL_ATTACHMENT
:
3741 if (_mesa_is_winsys_fbo(fb
))
3749 if (ctx
->Driver
.DiscardFramebuffer
)
3750 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
3755 _mesa_error(ctx
, GL_INVALID_ENUM
,
3756 "glDiscardFramebufferEXT(attachment %s)",
3757 _mesa_lookup_enum_by_nr(attachments
[i
]));