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_EXT
) {
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_EXT
) {
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_EXT
) {
835 att_incomplete("bad renderbuffer depth format");
836 att
->Complete
= GL_FALSE
;
841 assert(format
== GL_STENCIL
);
842 if (baseFormat
== GL_STENCIL_INDEX
) {
845 else if (baseFormat
== GL_DEPTH_STENCIL_EXT
) {
849 att
->Complete
= GL_FALSE
;
850 att_incomplete("bad renderbuffer stencil format");
856 ASSERT(att
->Type
== GL_NONE
);
864 * Test if the given framebuffer object is complete and update its
865 * Status field with the results.
866 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
867 * driver to make hardware-specific validation/completeness checks.
868 * Also update the framebuffer's Width and Height fields if the
869 * framebuffer is complete.
872 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
873 struct gl_framebuffer
*fb
)
876 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
877 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
878 GLint numSamples
= -1;
879 GLint fixedSampleLocations
= -1;
882 bool layer_count_valid
= false;
883 GLuint layer_count
= 0, att_layer_count
;
885 assert(_mesa_is_user_fbo(fb
));
887 /* we're changing framebuffer fields here */
888 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
893 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
894 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
896 /* Start at -2 to more easily loop over all attachment points.
901 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
902 struct gl_renderbuffer_attachment
*att
;
905 GLenum att_tex_target
= GL_NONE
;
908 * XXX for ARB_fbo, only check color buffers that are named by
909 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
912 /* check for attachment completeness
915 att
= &fb
->Attachment
[BUFFER_DEPTH
];
916 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
917 if (!att
->Complete
) {
918 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
919 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
924 att
= &fb
->Attachment
[BUFFER_STENCIL
];
925 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
926 if (!att
->Complete
) {
927 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
928 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
933 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
934 test_attachment_completeness(ctx
, GL_COLOR
, att
);
935 if (!att
->Complete
) {
936 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
937 fbo_incomplete(ctx
, "color attachment incomplete", i
);
942 /* get width, height, format of the renderbuffer/texture
944 if (att
->Type
== GL_TEXTURE
) {
945 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
946 att_tex_target
= att
->Texture
->Target
;
947 minWidth
= MIN2(minWidth
, texImg
->Width
);
948 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
949 minHeight
= MIN2(minHeight
, texImg
->Height
);
950 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
951 f
= texImg
->_BaseFormat
;
952 attFormat
= texImg
->TexFormat
;
955 if (!is_format_color_renderable(ctx
, attFormat
, texImg
->InternalFormat
) &&
956 !is_legal_depth_format(ctx
, f
)) {
957 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
958 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
963 numSamples
= texImg
->NumSamples
;
964 else if (numSamples
!= texImg
->NumSamples
) {
965 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
966 fbo_incomplete(ctx
, "inconsistent sample count", -1);
970 if (fixedSampleLocations
< 0)
971 fixedSampleLocations
= texImg
->FixedSampleLocations
;
972 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
973 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
974 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
978 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
979 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
980 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
981 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
982 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
983 f
= att
->Renderbuffer
->InternalFormat
;
984 attFormat
= att
->Renderbuffer
->Format
;
988 numSamples
= att
->Renderbuffer
->NumSamples
;
989 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
990 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
991 fbo_incomplete(ctx
, "inconsistent sample count", -1);
995 /* RENDERBUFFER has fixedSampleLocations implicitly true */
996 if (fixedSampleLocations
< 0)
997 fixedSampleLocations
= GL_TRUE
;
998 else if (fixedSampleLocations
!= GL_TRUE
) {
999 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1000 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1005 assert(att
->Type
== GL_NONE
);
1009 /* check if integer color */
1010 fb
->_IntegerColor
= _mesa_is_format_integer_color(attFormat
);
1012 /* Update _AllColorBuffersFixedPoint and _HasSNormOrFloatColorBuffer. */
1014 GLenum type
= _mesa_get_format_datatype(attFormat
);
1016 fb
->_AllColorBuffersFixedPoint
=
1017 fb
->_AllColorBuffersFixedPoint
&&
1018 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1020 fb
->_HasSNormOrFloatColorBuffer
=
1021 fb
->_HasSNormOrFloatColorBuffer
||
1022 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1025 /* Error-check width, height, format */
1026 if (numImages
== 1) {
1033 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1034 /* check that width, height, format are same */
1035 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1036 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1037 fbo_incomplete(ctx
, "width or height mismatch", -1);
1040 /* check that all color buffers are the same format */
1041 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1042 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1043 fbo_incomplete(ctx
, "format mismatch", -1);
1049 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1051 if (att
->Type
== GL_RENDERBUFFER
&&
1052 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1053 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1054 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1058 /* Check that layered rendering is consistent. */
1060 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1061 att_layer_count
= 6;
1063 att_layer_count
= att
->Renderbuffer
->Depth
;
1065 att_layer_count
= 0;
1067 if (!layer_count_valid
) {
1068 layer_count
= att_layer_count
;
1069 layer_count_valid
= true;
1070 } else if (layer_count
!= att_layer_count
) {
1071 if (layer_count
== 0 || att_layer_count
== 0) {
1072 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1073 fbo_incomplete(ctx
, "framebuffer attachment layer mode is inconsistent", i
);
1075 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
;
1076 fbo_incomplete(ctx
, "framebuffer attachment layer count is inconsistent", i
);
1082 fb
->NumLayers
= layer_count
;
1084 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1085 /* Check that all DrawBuffers are present */
1086 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1087 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1088 const struct gl_renderbuffer_attachment
*att
1089 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
1091 if (att
->Type
== GL_NONE
) {
1092 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1093 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1099 /* Check that the ReadBuffer is present */
1100 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1101 const struct gl_renderbuffer_attachment
*att
1102 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
1104 if (att
->Type
== GL_NONE
) {
1105 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1106 fbo_incomplete(ctx
, "missing readbuffer", -1);
1112 if (numImages
== 0) {
1113 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1114 fbo_incomplete(ctx
, "no attachments", -1);
1118 /* Provisionally set status = COMPLETE ... */
1119 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1121 /* ... but the driver may say the FB is incomplete.
1122 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1125 if (ctx
->Driver
.ValidateFramebuffer
) {
1126 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1127 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1128 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1132 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
1134 * Note that if ARB_framebuffer_object is supported and the attached
1135 * renderbuffers/textures are different sizes, the framebuffer
1136 * width/height will be set to the smallest width/height.
1138 fb
->Width
= minWidth
;
1139 fb
->Height
= minHeight
;
1141 /* finally, update the visual info for the framebuffer */
1142 _mesa_update_framebuffer_visual(ctx
, fb
);
1147 GLboolean GLAPIENTRY
1148 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1150 GET_CURRENT_CONTEXT(ctx
);
1151 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1153 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1154 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
1162 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1164 struct gl_renderbuffer
*newRb
;
1165 GET_CURRENT_CONTEXT(ctx
);
1167 if (target
!= GL_RENDERBUFFER_EXT
) {
1168 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1172 /* No need to flush here since the render buffer binding has no
1173 * effect on rendering state.
1177 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1178 if (newRb
== &DummyRenderbuffer
) {
1179 /* ID was reserved, but no real renderbuffer object made yet */
1182 else if (!newRb
&& !allow_user_names
) {
1183 /* All RB IDs must be Gen'd */
1184 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1189 /* create new renderbuffer object */
1190 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1192 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
1195 ASSERT(newRb
->AllocStorage
);
1196 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1197 newRb
->RefCount
= 1; /* referenced by hash table */
1204 ASSERT(newRb
!= &DummyRenderbuffer
);
1206 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1210 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1212 GET_CURRENT_CONTEXT(ctx
);
1214 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1215 * entry point, but they allow the use of user-generated names.
1217 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1221 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1223 /* This function should not be in the dispatch table for core profile /
1224 * OpenGL 3.1, so execution should never get here in those cases -- no
1225 * need for an explicit test.
1227 bind_renderbuffer(target
, renderbuffer
, true);
1232 * Remove the specified renderbuffer or texture from any attachment point in
1236 * \c true if the renderbuffer was detached from an attachment point. \c
1240 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1241 struct gl_framebuffer
*fb
,
1245 bool progress
= false;
1247 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1248 if (fb
->Attachment
[i
].Texture
== att
1249 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1250 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
1255 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1256 * Completeness," of the OpenGL 3.1 spec says:
1258 * "Performing any of the following actions may change whether the
1259 * framebuffer is considered complete or incomplete:
1263 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1264 * containing an image that is attached to a framebuffer object
1265 * that is bound to the framebuffer."
1268 invalidate_framebuffer(fb
);
1275 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1278 GET_CURRENT_CONTEXT(ctx
);
1280 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1282 for (i
= 0; i
< n
; i
++) {
1283 if (renderbuffers
[i
] > 0) {
1284 struct gl_renderbuffer
*rb
;
1285 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1287 /* check if deleting currently bound renderbuffer object */
1288 if (rb
== ctx
->CurrentRenderbuffer
) {
1290 ASSERT(rb
->RefCount
>= 2);
1291 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1294 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1295 * subsection "Attaching Renderbuffer Images to a Framebuffer," of
1296 * the OpenGL 3.1 spec says:
1298 * "If a renderbuffer object is deleted while its image is
1299 * attached to one or more attachment points in the currently
1300 * bound framebuffer, then it is as if FramebufferRenderbuffer
1301 * had been called, with a renderbuffer of 0, for each
1302 * attachment point to which this image was attached in the
1303 * currently bound framebuffer. In other words, this
1304 * renderbuffer image is first detached from all attachment
1305 * points in the currently bound framebuffer. Note that the
1306 * renderbuffer image is specifically not detached from any
1307 * non-bound framebuffers. Detaching the image from any
1308 * non-bound framebuffers is the responsibility of the
1311 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1312 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1314 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1315 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1316 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1319 /* Remove from hash table immediately, to free the ID.
1320 * But the object will not be freed until it's no longer
1321 * referenced anywhere else.
1323 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1325 if (rb
!= &DummyRenderbuffer
) {
1326 /* no longer referenced by hash table */
1327 _mesa_reference_renderbuffer(&rb
, NULL
);
1336 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1338 GET_CURRENT_CONTEXT(ctx
);
1343 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
1350 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1352 for (i
= 0; i
< n
; i
++) {
1353 GLuint name
= first
+ i
;
1354 renderbuffers
[i
] = name
;
1355 /* insert dummy placeholder into hash table */
1356 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1357 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
1358 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1364 * Given an internal format token for a render buffer, return the
1365 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1366 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1367 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1369 * This is similar to _mesa_base_tex_format() but the set of valid
1370 * internal formats is different.
1372 * Note that even if a format is determined to be legal here, validation
1373 * of the FBO may fail if the format is not supported by the driver/GPU.
1375 * \param internalFormat as passed to glRenderbufferStorage()
1376 * \return the base internal format, or 0 if internalFormat is illegal
1379 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1382 * Notes: some formats such as alpha, luminance, etc. were added
1383 * with GL_ARB_framebuffer_object.
1385 switch (internalFormat
) {
1391 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1396 case GL_LUMINANCE12
:
1397 case GL_LUMINANCE16
:
1398 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1400 case GL_LUMINANCE_ALPHA
:
1401 case GL_LUMINANCE4_ALPHA4
:
1402 case GL_LUMINANCE6_ALPHA2
:
1403 case GL_LUMINANCE8_ALPHA8
:
1404 case GL_LUMINANCE12_ALPHA4
:
1405 case GL_LUMINANCE12_ALPHA12
:
1406 case GL_LUMINANCE16_ALPHA16
:
1407 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1408 ? GL_LUMINANCE_ALPHA
: 0;
1412 case GL_INTENSITY12
:
1413 case GL_INTENSITY16
:
1414 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1425 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1427 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1436 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1438 case GL_SRGB8_ALPHA8_EXT
:
1439 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1440 case GL_STENCIL_INDEX
:
1441 case GL_STENCIL_INDEX1_EXT
:
1442 case GL_STENCIL_INDEX4_EXT
:
1443 case GL_STENCIL_INDEX16_EXT
:
1444 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1445 * OpenGL ES, but Mesa does not currently support them.
1447 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1448 case GL_STENCIL_INDEX8_EXT
:
1449 return GL_STENCIL_INDEX
;
1450 case GL_DEPTH_COMPONENT
:
1451 case GL_DEPTH_COMPONENT32
:
1452 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1453 case GL_DEPTH_COMPONENT16
:
1454 case GL_DEPTH_COMPONENT24
:
1455 return GL_DEPTH_COMPONENT
;
1456 case GL_DEPTH_STENCIL_EXT
:
1457 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL_EXT
: 0;
1458 case GL_DEPTH24_STENCIL8_EXT
:
1459 return GL_DEPTH_STENCIL_EXT
;
1460 case GL_DEPTH_COMPONENT32F
:
1461 return ctx
->Version
>= 30
1462 || (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_buffer_float
)
1463 ? GL_DEPTH_COMPONENT
: 0;
1464 case GL_DEPTH32F_STENCIL8
:
1465 return ctx
->Version
>= 30
1466 || (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_buffer_float
)
1467 ? GL_DEPTH_STENCIL
: 0;
1470 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1473 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1477 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1480 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1482 /* signed normalized texture formats */
1486 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1491 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1495 case GL_RGB16_SNORM
:
1496 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1499 case GL_RGBA8_SNORM
:
1500 case GL_RGBA16_SNORM
:
1501 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1503 case GL_ALPHA_SNORM
:
1504 case GL_ALPHA8_SNORM
:
1505 case GL_ALPHA16_SNORM
:
1506 return ctx
->API
== API_OPENGL_COMPAT
&&
1507 ctx
->Extensions
.EXT_texture_snorm
&&
1508 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1511 return ((_mesa_is_desktop_gl(ctx
) &&
1512 ctx
->Extensions
.ARB_texture_rg
&&
1513 ctx
->Extensions
.ARB_texture_float
) ||
1514 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1518 return ((_mesa_is_desktop_gl(ctx
) &&
1519 ctx
->Extensions
.ARB_texture_rg
&&
1520 ctx
->Extensions
.ARB_texture_float
) ||
1521 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1525 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1529 return ((_mesa_is_desktop_gl(ctx
) &&
1530 ctx
->Extensions
.ARB_texture_float
) ||
1531 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1533 case GL_ALPHA16F_ARB
:
1534 case GL_ALPHA32F_ARB
:
1535 return ctx
->API
== API_OPENGL_COMPAT
&&
1536 ctx
->Extensions
.ARB_texture_float
&&
1537 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1538 case GL_LUMINANCE16F_ARB
:
1539 case GL_LUMINANCE32F_ARB
:
1540 return ctx
->API
== API_OPENGL_COMPAT
&&
1541 ctx
->Extensions
.ARB_texture_float
&&
1542 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1543 case GL_LUMINANCE_ALPHA16F_ARB
:
1544 case GL_LUMINANCE_ALPHA32F_ARB
:
1545 return ctx
->API
== API_OPENGL_COMPAT
&&
1546 ctx
->Extensions
.ARB_texture_float
&&
1547 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1548 case GL_INTENSITY16F_ARB
:
1549 case GL_INTENSITY32F_ARB
:
1550 return ctx
->API
== API_OPENGL_COMPAT
&&
1551 ctx
->Extensions
.ARB_texture_float
&&
1552 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1554 return (_mesa_is_desktop_gl(ctx
)
1555 && ctx
->Extensions
.EXT_texture_shared_exponent
)
1557 case GL_R11F_G11F_B10F
:
1558 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1559 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1562 case GL_RGBA8UI_EXT
:
1563 case GL_RGBA16UI_EXT
:
1564 case GL_RGBA32UI_EXT
:
1566 case GL_RGBA16I_EXT
:
1567 case GL_RGBA32I_EXT
:
1568 return ctx
->Version
>= 30
1569 || (_mesa_is_desktop_gl(ctx
) &&
1570 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
1573 case GL_RGB16UI_EXT
:
1574 case GL_RGB32UI_EXT
:
1578 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
1586 return ctx
->Version
>= 30
1587 || (_mesa_is_desktop_gl(ctx
) &&
1588 ctx
->Extensions
.ARB_texture_rg
&&
1589 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
1597 return ctx
->Version
>= 30
1598 || (_mesa_is_desktop_gl(ctx
) &&
1599 ctx
->Extensions
.ARB_texture_rg
&&
1600 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
1602 case GL_INTENSITY8I_EXT
:
1603 case GL_INTENSITY8UI_EXT
:
1604 case GL_INTENSITY16I_EXT
:
1605 case GL_INTENSITY16UI_EXT
:
1606 case GL_INTENSITY32I_EXT
:
1607 case GL_INTENSITY32UI_EXT
:
1608 return ctx
->API
== API_OPENGL_COMPAT
&&
1609 ctx
->Extensions
.EXT_texture_integer
&&
1610 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1612 case GL_LUMINANCE8I_EXT
:
1613 case GL_LUMINANCE8UI_EXT
:
1614 case GL_LUMINANCE16I_EXT
:
1615 case GL_LUMINANCE16UI_EXT
:
1616 case GL_LUMINANCE32I_EXT
:
1617 case GL_LUMINANCE32UI_EXT
:
1618 return ctx
->API
== API_OPENGL_COMPAT
&&
1619 ctx
->Extensions
.EXT_texture_integer
&&
1620 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1622 case GL_LUMINANCE_ALPHA8I_EXT
:
1623 case GL_LUMINANCE_ALPHA8UI_EXT
:
1624 case GL_LUMINANCE_ALPHA16I_EXT
:
1625 case GL_LUMINANCE_ALPHA16UI_EXT
:
1626 case GL_LUMINANCE_ALPHA32I_EXT
:
1627 case GL_LUMINANCE_ALPHA32UI_EXT
:
1628 return ctx
->API
== API_OPENGL_COMPAT
&&
1629 ctx
->Extensions
.EXT_texture_integer
&&
1630 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1632 case GL_ALPHA8I_EXT
:
1633 case GL_ALPHA8UI_EXT
:
1634 case GL_ALPHA16I_EXT
:
1635 case GL_ALPHA16UI_EXT
:
1636 case GL_ALPHA32I_EXT
:
1637 case GL_ALPHA32UI_EXT
:
1638 return ctx
->API
== API_OPENGL_COMPAT
&&
1639 ctx
->Extensions
.EXT_texture_integer
&&
1640 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1643 return (_mesa_is_desktop_gl(ctx
) &&
1644 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
1645 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1648 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
1657 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1660 invalidate_rb(GLuint key
, void *data
, void *userData
)
1662 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1663 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
1665 /* If this is a user-created FBO */
1666 if (_mesa_is_user_fbo(fb
)) {
1668 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1669 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1670 if (att
->Type
== GL_RENDERBUFFER
&&
1671 att
->Renderbuffer
== rb
) {
1672 /* Mark fb status as indeterminate to force re-validation */
1681 /** sentinal value, see below */
1682 #define NO_SAMPLES 1000
1686 * Helper function used by _mesa_RenderbufferStorage() and
1687 * _mesa_RenderbufferStorageMultisample().
1688 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
1691 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1692 GLsizei width
, GLsizei height
, GLsizei samples
)
1694 const char *func
= samples
== NO_SAMPLES
?
1695 "glRenderbufferStorage" : "glRenderbufferStorageMultisample";
1696 struct gl_renderbuffer
*rb
;
1698 GLenum sample_count_error
;
1699 GET_CURRENT_CONTEXT(ctx
);
1701 if (MESA_VERBOSE
& VERBOSE_API
) {
1702 if (samples
== NO_SAMPLES
)
1703 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
1705 _mesa_lookup_enum_by_nr(target
),
1706 _mesa_lookup_enum_by_nr(internalFormat
),
1709 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
1711 _mesa_lookup_enum_by_nr(target
),
1712 _mesa_lookup_enum_by_nr(internalFormat
),
1713 width
, height
, samples
);
1716 if (target
!= GL_RENDERBUFFER_EXT
) {
1717 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1721 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1722 if (baseFormat
== 0) {
1723 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
1724 func
, _mesa_lookup_enum_by_nr(internalFormat
));
1728 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1729 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1733 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1734 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1738 if (samples
== NO_SAMPLES
) {
1739 /* NumSamples == 0 indicates non-multisampling */
1743 /* check the sample count;
1744 * note: driver may choose to use more samples than what's requested
1746 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
1747 internalFormat
, samples
);
1748 if (sample_count_error
!= GL_NO_ERROR
) {
1749 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
1754 rb
= ctx
->CurrentRenderbuffer
;
1756 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1760 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1762 if (rb
->InternalFormat
== internalFormat
&&
1763 rb
->Width
== (GLuint
) width
&&
1764 rb
->Height
== (GLuint
) height
&&
1765 rb
->NumSamples
== samples
) {
1766 /* no change in allocation needed */
1770 /* These MUST get set by the AllocStorage func */
1771 rb
->Format
= MESA_FORMAT_NONE
;
1772 rb
->NumSamples
= samples
;
1774 /* Now allocate the storage */
1775 ASSERT(rb
->AllocStorage
);
1776 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1777 /* No error - check/set fields now */
1778 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
1779 assert(rb
->Width
== (GLuint
) width
);
1780 assert(rb
->Height
== (GLuint
) height
);
1781 rb
->InternalFormat
= internalFormat
;
1782 rb
->_BaseFormat
= baseFormat
;
1783 assert(rb
->_BaseFormat
!= 0);
1786 /* Probably ran out of memory - clear the fields */
1789 rb
->Format
= MESA_FORMAT_NONE
;
1790 rb
->InternalFormat
= GL_NONE
;
1791 rb
->_BaseFormat
= GL_NONE
;
1795 /* Invalidate the framebuffers the renderbuffer is attached in. */
1796 if (rb
->AttachedAnytime
) {
1797 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
1803 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1805 struct gl_renderbuffer
*rb
;
1806 GET_CURRENT_CONTEXT(ctx
);
1808 if (!ctx
->Extensions
.OES_EGL_image
) {
1809 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1810 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1814 if (target
!= GL_RENDERBUFFER
) {
1815 _mesa_error(ctx
, GL_INVALID_ENUM
,
1816 "EGLImageTargetRenderbufferStorageOES");
1820 rb
= ctx
->CurrentRenderbuffer
;
1822 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1823 "EGLImageTargetRenderbufferStorageOES");
1827 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1829 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1834 * Helper function for _mesa_GetRenderbufferParameteriv() and
1835 * _mesa_GetFramebufferAttachmentParameteriv()
1836 * We have to be careful to respect the base format. For example, if a
1837 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1838 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1839 * we need to return zero.
1842 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1844 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1845 return _mesa_get_format_bits(format
, pname
);
1853 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
1854 GLsizei width
, GLsizei height
)
1856 /* GL_ARB_fbo says calling this function is equivalent to calling
1857 * glRenderbufferStorageMultisample() with samples=0. We pass in
1858 * a token value here just for error reporting purposes.
1860 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1865 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1866 GLenum internalFormat
,
1867 GLsizei width
, GLsizei height
)
1869 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1874 * OpenGL ES version of glRenderBufferStorage.
1877 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1878 GLsizei width
, GLsizei height
)
1880 switch (internalFormat
) {
1882 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1883 /* choose a closest format */
1884 internalFormat
= GL_RGB5
;
1890 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1895 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1897 struct gl_renderbuffer
*rb
;
1898 GET_CURRENT_CONTEXT(ctx
);
1900 if (target
!= GL_RENDERBUFFER_EXT
) {
1901 _mesa_error(ctx
, GL_INVALID_ENUM
,
1902 "glGetRenderbufferParameterivEXT(target)");
1906 rb
= ctx
->CurrentRenderbuffer
;
1908 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1909 "glGetRenderbufferParameterivEXT");
1913 /* No need to flush here since we're just quering state which is
1914 * not effected by rendering.
1918 case GL_RENDERBUFFER_WIDTH_EXT
:
1919 *params
= rb
->Width
;
1921 case GL_RENDERBUFFER_HEIGHT_EXT
:
1922 *params
= rb
->Height
;
1924 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1925 *params
= rb
->InternalFormat
;
1927 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1928 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1929 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1930 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1931 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1932 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1933 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1935 case GL_RENDERBUFFER_SAMPLES
:
1936 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
1937 || _mesa_is_gles3(ctx
)) {
1938 *params
= rb
->NumSamples
;
1943 _mesa_error(ctx
, GL_INVALID_ENUM
,
1944 "glGetRenderbufferParameterivEXT(target)");
1950 GLboolean GLAPIENTRY
1951 _mesa_IsFramebuffer(GLuint framebuffer
)
1953 GET_CURRENT_CONTEXT(ctx
);
1954 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1956 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1957 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1965 * Check if any of the attachments of the given framebuffer are textures
1966 * (render to texture). Call ctx->Driver.RenderTexture() for such
1970 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1973 ASSERT(ctx
->Driver
.RenderTexture
);
1975 if (_mesa_is_winsys_fbo(fb
))
1976 return; /* can't render to texture with winsys framebuffers */
1978 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1979 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1980 if (att
->Texture
&& att
->Renderbuffer
->TexImage
1981 && driver_RenderTexture_is_safe(att
)) {
1982 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1989 * Examine all the framebuffer's attachments to see if any are textures.
1990 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1991 * notify the device driver that the texture image may have changed.
1994 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1996 if (_mesa_is_winsys_fbo(fb
))
1997 return; /* can't render to texture with winsys framebuffers */
1999 if (ctx
->Driver
.FinishRenderTexture
) {
2001 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2002 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2003 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2004 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2005 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2013 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2015 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2016 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
2017 GLboolean bindReadBuf
, bindDrawBuf
;
2018 GET_CURRENT_CONTEXT(ctx
);
2021 if (ctx
->Extensions
.ARB_framebuffer_object
) {
2022 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
2027 case GL_DRAW_FRAMEBUFFER_EXT
:
2028 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2029 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2032 bindDrawBuf
= GL_TRUE
;
2033 bindReadBuf
= GL_FALSE
;
2035 case GL_READ_FRAMEBUFFER_EXT
:
2036 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2037 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2040 bindDrawBuf
= GL_FALSE
;
2041 bindReadBuf
= GL_TRUE
;
2043 case GL_FRAMEBUFFER_EXT
:
2044 bindDrawBuf
= GL_TRUE
;
2045 bindReadBuf
= GL_TRUE
;
2048 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2053 /* Binding a user-created framebuffer object */
2054 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2055 if (newDrawFb
== &DummyFramebuffer
) {
2056 /* ID was reserved, but no real framebuffer object made yet */
2059 else if (!newDrawFb
&& !allow_user_names
) {
2060 /* All FBO IDs must be Gen'd */
2061 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2066 /* create new framebuffer object */
2067 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2069 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2072 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2074 newReadFb
= newDrawFb
;
2077 /* Binding the window system framebuffer (which was originally set
2078 * with MakeCurrent).
2080 newDrawFb
= ctx
->WinSysDrawBuffer
;
2081 newReadFb
= ctx
->WinSysReadBuffer
;
2085 ASSERT(newDrawFb
!= &DummyFramebuffer
);
2087 /* save pointers to current/old framebuffers */
2088 oldDrawFb
= ctx
->DrawBuffer
;
2089 oldReadFb
= ctx
->ReadBuffer
;
2091 /* check if really changing bindings */
2092 if (oldDrawFb
== newDrawFb
)
2093 bindDrawBuf
= GL_FALSE
;
2094 if (oldReadFb
== newReadFb
)
2095 bindReadBuf
= GL_FALSE
;
2098 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2100 * We also check if we're beginning and/or ending render-to-texture.
2101 * When a framebuffer with texture attachments is unbound, call
2102 * ctx->Driver.FinishRenderTexture().
2103 * When a framebuffer with texture attachments is bound, call
2104 * ctx->Driver.RenderTexture().
2106 * Note that if the ReadBuffer has texture attachments we don't consider
2107 * that a render-to-texture case.
2110 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2112 /* check if old readbuffer was render-to-texture */
2113 check_end_texture_render(ctx
, oldReadFb
);
2115 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2119 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2121 /* check if old framebuffer had any texture attachments */
2123 check_end_texture_render(ctx
, oldDrawFb
);
2125 /* check if newly bound framebuffer has any texture attachments */
2126 check_begin_texture_render(ctx
, newDrawFb
);
2128 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2131 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2132 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
2137 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2139 GET_CURRENT_CONTEXT(ctx
);
2141 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2142 * point, but they allow the use of user-generated names.
2144 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2148 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2150 /* This function should not be in the dispatch table for core profile /
2151 * OpenGL 3.1, so execution should never get here in those cases -- no
2152 * need for an explicit test.
2154 bind_framebuffer(target
, framebuffer
, true);
2158 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2161 GET_CURRENT_CONTEXT(ctx
);
2163 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2165 for (i
= 0; i
< n
; i
++) {
2166 if (framebuffers
[i
] > 0) {
2167 struct gl_framebuffer
*fb
;
2168 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2170 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2172 /* check if deleting currently bound framebuffer object */
2173 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
2174 /* separate draw/read binding points */
2175 if (fb
== ctx
->DrawBuffer
) {
2177 ASSERT(fb
->RefCount
>= 2);
2178 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT
, 0);
2180 if (fb
== ctx
->ReadBuffer
) {
2182 ASSERT(fb
->RefCount
>= 2);
2183 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER_EXT
, 0);
2187 /* only one binding point for read/draw buffers */
2188 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
2190 ASSERT(fb
->RefCount
>= 2);
2191 _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT
, 0);
2195 /* remove from hash table immediately, to free the ID */
2196 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2198 if (fb
!= &DummyFramebuffer
) {
2199 /* But the object will not be freed until it's no longer
2200 * bound in any context.
2202 _mesa_reference_framebuffer(&fb
, NULL
);
2211 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2213 GET_CURRENT_CONTEXT(ctx
);
2218 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
2225 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2227 for (i
= 0; i
< n
; i
++) {
2228 GLuint name
= first
+ i
;
2229 framebuffers
[i
] = name
;
2230 /* insert dummy placeholder into hash table */
2231 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
2232 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
2233 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
2240 _mesa_CheckFramebufferStatus(GLenum target
)
2242 struct gl_framebuffer
*buffer
;
2243 GET_CURRENT_CONTEXT(ctx
);
2245 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2247 if (MESA_VERBOSE
& VERBOSE_API
)
2248 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2249 _mesa_lookup_enum_by_nr(target
));
2251 buffer
= get_framebuffer_target(ctx
, target
);
2253 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
2257 if (_mesa_is_winsys_fbo(buffer
)) {
2258 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2259 if (buffer
!= &IncompleteFramebuffer
) {
2260 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2262 return GL_FRAMEBUFFER_UNDEFINED
;
2266 /* No need to flush here */
2268 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2269 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2272 return buffer
->_Status
;
2277 * Replicate the src attachment point. Used by framebuffer_texture() when
2278 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2279 * GL_STENCIL_ATTACHMENT.
2282 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2283 gl_buffer_index dst
,
2284 gl_buffer_index src
)
2286 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2287 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2289 assert(src_att
->Texture
!= NULL
);
2290 assert(src_att
->Renderbuffer
!= NULL
);
2292 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2293 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2294 dst_att
->Type
= src_att
->Type
;
2295 dst_att
->Complete
= src_att
->Complete
;
2296 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2297 dst_att
->Zoffset
= src_att
->Zoffset
;
2302 * Common code called by glFramebufferTexture1D/2D/3DEXT() and
2303 * glFramebufferTextureLayerEXT().
2305 * \param textarget is the textarget that was passed to the
2306 * glFramebufferTexture...() function, or 0 if the corresponding function
2307 * doesn't have a textarget parameter.
2309 * \param layered is true if this function was called from
2310 * glFramebufferTexture(), false otherwise.
2313 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
2314 GLenum attachment
, GLenum textarget
, GLuint texture
,
2315 GLint level
, GLint zoffset
, GLboolean layered
)
2317 struct gl_renderbuffer_attachment
*att
;
2318 struct gl_texture_object
*texObj
= NULL
;
2319 struct gl_framebuffer
*fb
;
2320 GLenum maxLevelsTarget
;
2322 fb
= get_framebuffer_target(ctx
, target
);
2324 _mesa_error(ctx
, GL_INVALID_ENUM
,
2325 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
2329 /* check framebuffer binding */
2330 if (_mesa_is_winsys_fbo(fb
)) {
2331 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2332 "glFramebufferTexture%sEXT", caller
);
2336 /* The textarget, level, and zoffset parameters are only validated if
2337 * texture is non-zero.
2340 GLboolean err
= GL_TRUE
;
2342 texObj
= _mesa_lookup_texture(ctx
, texture
);
2343 if (texObj
!= NULL
) {
2344 if (textarget
== 0) {
2346 /* We're being called by glFramebufferTexture() and textarget
2349 switch (texObj
->Target
) {
2351 case GL_TEXTURE_1D_ARRAY_EXT
:
2352 case GL_TEXTURE_2D_ARRAY_EXT
:
2353 case GL_TEXTURE_CUBE_MAP
:
2354 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2355 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2360 case GL_TEXTURE_RECTANGLE
:
2361 case GL_TEXTURE_2D_MULTISAMPLE
:
2362 /* These texture types are valid to pass to
2363 * glFramebufferTexture(), but since they aren't layered, it
2364 * is equivalent to calling glFramebufferTexture{1D,2D}().
2368 textarget
= texObj
->Target
;
2375 /* We're being called by glFramebufferTextureLayer() and
2376 * textarget is not used. The only legal texture types for
2377 * that function are 3D and 1D/2D arrays textures.
2379 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
2380 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
2381 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
) &&
2382 (texObj
->Target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) &&
2383 (texObj
->Target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
);
2387 /* Make sure textarget is consistent with the texture's type */
2388 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
2389 ? !_mesa_is_cube_face(textarget
)
2390 : (texObj
->Target
!= textarget
);
2394 /* can't render to a non-existant texture */
2395 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2396 "glFramebufferTexture%sEXT(non existant texture)",
2402 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2403 "glFramebufferTexture%sEXT(texture target mismatch)",
2408 if (texObj
->Target
== GL_TEXTURE_3D
) {
2409 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
2410 if (zoffset
< 0 || zoffset
>= maxSize
) {
2411 _mesa_error(ctx
, GL_INVALID_VALUE
,
2412 "glFramebufferTexture%sEXT(zoffset)", caller
);
2416 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
2417 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) ||
2418 (texObj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
2419 (texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
2421 zoffset
>= (GLint
) ctx
->Const
.MaxArrayTextureLayers
) {
2422 _mesa_error(ctx
, GL_INVALID_VALUE
,
2423 "glFramebufferTexture%sEXT(layer)", caller
);
2428 maxLevelsTarget
= textarget
? textarget
: texObj
->Target
;
2430 (level
>= _mesa_max_texture_levels(ctx
, maxLevelsTarget
))) {
2431 _mesa_error(ctx
, GL_INVALID_VALUE
,
2432 "glFramebufferTexture%sEXT(level)", caller
);
2437 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2439 _mesa_error(ctx
, GL_INVALID_ENUM
,
2440 "glFramebufferTexture%sEXT(attachment)", caller
);
2444 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2446 _glthread_LOCK_MUTEX(fb
->Mutex
);
2448 if (attachment
== GL_DEPTH_ATTACHMENT
&&
2449 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
2450 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
2451 _mesa_tex_target_to_face(textarget
) ==
2452 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
2453 zoffset
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
2454 /* The texture object is already attached to the stencil attachment
2455 * point. Don't create a new renderbuffer; just reuse the stencil
2456 * attachment's. This is required to prevent a GL error in
2457 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
2459 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
2461 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
2462 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
2463 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
2464 _mesa_tex_target_to_face(textarget
) ==
2465 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
2466 zoffset
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
2467 /* As above, but with depth and stencil transposed. */
2468 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
2471 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
2472 level
, zoffset
, layered
);
2473 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2474 /* Above we created a new renderbuffer and attached it to the
2475 * depth attachment point. Now attach it to the stencil attachment
2478 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
2479 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
2484 /* Set the render-to-texture flag. We'll check this flag in
2485 * glTexImage() and friends to determine if we need to revalidate
2486 * any FBOs that might be rendering into this texture.
2487 * This flag never gets cleared since it's non-trivial to determine
2488 * when all FBOs might be done rendering to this texture. That's OK
2489 * though since it's uncommon to render to a texture then repeatedly
2490 * call glTexImage() to change images in the texture.
2492 texObj
->_RenderToTexture
= GL_TRUE
;
2495 _mesa_remove_attachment(ctx
, att
);
2496 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2497 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
2498 _mesa_remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
2502 invalidate_framebuffer(fb
);
2504 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
2510 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
2511 GLenum textarget
, GLuint texture
, GLint level
)
2513 GET_CURRENT_CONTEXT(ctx
);
2518 switch (textarget
) {
2522 case GL_TEXTURE_1D_ARRAY
:
2523 error
= !ctx
->Extensions
.EXT_texture_array
;
2530 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2531 "glFramebufferTexture1DEXT(textarget=%s)",
2532 _mesa_lookup_enum_by_nr(textarget
));
2537 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
2538 level
, 0, GL_FALSE
);
2543 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
2544 GLenum textarget
, GLuint texture
, GLint level
)
2546 GET_CURRENT_CONTEXT(ctx
);
2551 switch (textarget
) {
2555 case GL_TEXTURE_RECTANGLE
:
2556 error
= _mesa_is_gles(ctx
)
2557 || !ctx
->Extensions
.NV_texture_rectangle
;
2559 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2560 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2561 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2562 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2563 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2564 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2565 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
2567 case GL_TEXTURE_2D_ARRAY
:
2568 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
2569 || !ctx
->Extensions
.EXT_texture_array
;
2571 case GL_TEXTURE_2D_MULTISAMPLE
:
2572 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2573 error
= _mesa_is_gles(ctx
)
2574 || !ctx
->Extensions
.ARB_texture_multisample
;
2581 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2582 "glFramebufferTexture2DEXT(textarget=%s)",
2583 _mesa_lookup_enum_by_nr(textarget
));
2588 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
2589 level
, 0, GL_FALSE
);
2594 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
2595 GLenum textarget
, GLuint texture
,
2596 GLint level
, GLint zoffset
)
2598 GET_CURRENT_CONTEXT(ctx
);
2600 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
2601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2602 "glFramebufferTexture3DEXT(textarget)");
2606 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
2607 level
, zoffset
, GL_FALSE
);
2612 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
2613 GLuint texture
, GLint level
, GLint layer
)
2615 GET_CURRENT_CONTEXT(ctx
);
2617 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2618 level
, layer
, GL_FALSE
);
2623 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
2624 GLuint texture
, GLint level
)
2626 GET_CURRENT_CONTEXT(ctx
);
2628 if (_mesa_has_geometry_shaders(ctx
)) {
2629 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2632 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2633 "unsupported function (glFramebufferTexture) called");
2639 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
2640 GLenum renderbufferTarget
,
2641 GLuint renderbuffer
)
2643 struct gl_renderbuffer_attachment
*att
;
2644 struct gl_framebuffer
*fb
;
2645 struct gl_renderbuffer
*rb
;
2646 GET_CURRENT_CONTEXT(ctx
);
2648 fb
= get_framebuffer_target(ctx
, target
);
2650 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFramebufferRenderbufferEXT(target)");
2654 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
2655 _mesa_error(ctx
, GL_INVALID_ENUM
,
2656 "glFramebufferRenderbufferEXT(renderbufferTarget)");
2660 if (_mesa_is_winsys_fbo(fb
)) {
2661 /* Can't attach new renderbuffers to a window system framebuffer */
2662 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
2666 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2668 _mesa_error(ctx
, GL_INVALID_ENUM
,
2669 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2670 _mesa_lookup_enum_by_nr(attachment
));
2675 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2677 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2678 "glFramebufferRenderbufferEXT(non-existant"
2679 " renderbuffer %u)", renderbuffer
);
2682 else if (rb
== &DummyRenderbuffer
) {
2683 /* This is what NVIDIA does */
2684 _mesa_error(ctx
, GL_INVALID_VALUE
,
2685 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2691 /* remove renderbuffer attachment */
2695 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
2696 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
2697 /* make sure the renderbuffer is a depth/stencil format */
2698 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2699 if (baseFormat
!= GL_DEPTH_STENCIL
) {
2700 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2701 "glFramebufferRenderbufferEXT(renderbuffer"
2702 " is not DEPTH_STENCIL format)");
2708 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2710 assert(ctx
->Driver
.FramebufferRenderbuffer
);
2711 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
2713 /* Some subsequent GL commands may depend on the framebuffer's visual
2714 * after the binding is updated. Update visual info now.
2716 _mesa_update_framebuffer_visual(ctx
, fb
);
2721 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
2722 GLenum pname
, GLint
*params
)
2724 const struct gl_renderbuffer_attachment
*att
;
2725 struct gl_framebuffer
*buffer
;
2727 GET_CURRENT_CONTEXT(ctx
);
2729 /* The error differs in GL and GLES. */
2730 err
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
2732 buffer
= get_framebuffer_target(ctx
, target
);
2734 _mesa_error(ctx
, GL_INVALID_ENUM
,
2735 "glGetFramebufferAttachmentParameterivEXT(target)");
2739 if (_mesa_is_winsys_fbo(buffer
)) {
2740 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
2743 * "If the framebuffer currently bound to target is zero, then
2744 * INVALID_OPERATION is generated."
2746 * The EXT_framebuffer_object spec has the same wording, and the
2747 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
2750 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2751 && !_mesa_is_gles3(ctx
)) {
2752 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2753 "glGetFramebufferAttachmentParameteriv(bound FBO = 0)");
2757 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
2758 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
2759 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2760 "glGetFramebufferAttachmentParameteriv(attachment)");
2763 /* the default / window-system FBO */
2764 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2767 /* user-created framebuffer FBO */
2768 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2772 _mesa_error(ctx
, GL_INVALID_ENUM
,
2773 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2777 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2778 /* the depth and stencil attachments must point to the same buffer */
2779 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2780 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2781 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2782 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2783 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2784 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2785 " attachments differ)");
2790 /* No need to flush here */
2793 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2794 *params
= _mesa_is_winsys_fbo(buffer
)
2795 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2797 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2798 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2799 *params
= att
->Renderbuffer
->Name
;
2801 else if (att
->Type
== GL_TEXTURE
) {
2802 *params
= att
->Texture
->Name
;
2805 assert(att
->Type
== GL_NONE
);
2806 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
2809 goto invalid_pname_enum
;
2813 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2814 if (att
->Type
== GL_TEXTURE
) {
2815 *params
= att
->TextureLevel
;
2817 else if (att
->Type
== GL_NONE
) {
2818 _mesa_error(ctx
, err
,
2819 "glGetFramebufferAttachmentParameterivEXT(pname)");
2822 goto invalid_pname_enum
;
2825 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2826 if (att
->Type
== GL_TEXTURE
) {
2827 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2828 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2834 else if (att
->Type
== GL_NONE
) {
2835 _mesa_error(ctx
, err
,
2836 "glGetFramebufferAttachmentParameterivEXT(pname)");
2839 goto invalid_pname_enum
;
2842 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2843 if (ctx
->API
== API_OPENGLES
) {
2844 goto invalid_pname_enum
;
2845 } else if (att
->Type
== GL_NONE
) {
2846 _mesa_error(ctx
, err
,
2847 "glGetFramebufferAttachmentParameterivEXT(pname)");
2848 } else if (att
->Type
== GL_TEXTURE
) {
2849 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2850 *params
= att
->Zoffset
;
2857 goto invalid_pname_enum
;
2860 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2861 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2862 && !_mesa_is_gles3(ctx
)) {
2863 goto invalid_pname_enum
;
2865 else if (att
->Type
== GL_NONE
) {
2866 _mesa_error(ctx
, err
,
2867 "glGetFramebufferAttachmentParameterivEXT(pname)");
2870 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
2871 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2874 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2875 * if the sRGB conversion is unsupported. */
2876 *params
= GL_LINEAR
;
2880 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2881 if ((ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_framebuffer_object
)
2882 && ctx
->API
!= API_OPENGL_CORE
2883 && !_mesa_is_gles3(ctx
)) {
2884 goto invalid_pname_enum
;
2886 else if (att
->Type
== GL_NONE
) {
2887 _mesa_error(ctx
, err
,
2888 "glGetFramebufferAttachmentParameterivEXT(pname)");
2891 gl_format format
= att
->Renderbuffer
->Format
;
2893 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
2896 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
2897 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
2898 * generate an INVALID_OPERATION error.
2900 if (_mesa_is_gles3(ctx
) && attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2901 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2902 "glGetFramebufferAttachmentParameteriv(cannot query "
2903 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
2904 "GL_DEPTH_STENCIL_ATTACHMENT");
2908 if (format
== MESA_FORMAT_S8
) {
2912 else if (format
== MESA_FORMAT_Z32_FLOAT_X24S8
) {
2913 /* depends on the attachment parameter */
2914 if (attachment
== GL_STENCIL_ATTACHMENT
) {
2922 *params
= _mesa_get_format_datatype(format
);
2926 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2927 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2928 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2929 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2930 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2931 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2932 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2933 && !_mesa_is_gles3(ctx
)) {
2934 goto invalid_pname_enum
;
2936 else if (att
->Type
== GL_NONE
) {
2937 _mesa_error(ctx
, err
,
2938 "glGetFramebufferAttachmentParameterivEXT(pname)");
2940 else if (att
->Texture
) {
2941 const struct gl_texture_image
*texImage
=
2942 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2945 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2946 texImage
->TexFormat
);
2952 else if (att
->Renderbuffer
) {
2953 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2954 att
->Renderbuffer
->Format
);
2957 _mesa_problem(ctx
, "glGetFramebufferAttachmentParameterivEXT:"
2958 " invalid FBO attachment structure");
2961 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
2962 if (!_mesa_has_geometry_shaders(ctx
)) {
2963 goto invalid_pname_enum
;
2964 } else if (att
->Type
== GL_TEXTURE
) {
2965 *params
= att
->Layered
;
2966 } else if (att
->Type
== GL_NONE
) {
2967 _mesa_error(ctx
, err
,
2968 "glGetFramebufferAttachmentParameteriv(pname)");
2970 goto invalid_pname_enum
;
2974 goto invalid_pname_enum
;
2980 _mesa_error(ctx
, GL_INVALID_ENUM
,
2981 "glGetFramebufferAttachmentParameteriv(pname)");
2987 _mesa_GenerateMipmap(GLenum target
)
2989 struct gl_texture_image
*srcImage
;
2990 struct gl_texture_object
*texObj
;
2993 GET_CURRENT_CONTEXT(ctx
);
2995 FLUSH_VERTICES(ctx
, 0);
2999 error
= _mesa_is_gles(ctx
);
3005 error
= ctx
->API
== API_OPENGLES
;
3007 case GL_TEXTURE_CUBE_MAP
:
3008 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
3010 case GL_TEXTURE_1D_ARRAY
:
3011 error
= _mesa_is_gles(ctx
) || !ctx
->Extensions
.EXT_texture_array
;
3013 case GL_TEXTURE_2D_ARRAY
:
3014 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
3015 || !ctx
->Extensions
.EXT_texture_array
;
3022 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target=%s)",
3023 _mesa_lookup_enum_by_nr(target
));
3027 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3029 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
3034 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
3035 !_mesa_cube_complete(texObj
)) {
3036 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3037 "glGenerateMipmap(incomplete cube map)");
3041 _mesa_lock_texture(ctx
, texObj
);
3043 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, texObj
->BaseLevel
);
3045 _mesa_unlock_texture(ctx
, texObj
);
3046 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3047 "glGenerateMipmap(zero size base image)");
3051 if (_mesa_is_enum_format_integer(srcImage
->InternalFormat
) ||
3052 _mesa_is_depthstencil_format(srcImage
->InternalFormat
) ||
3053 _mesa_is_stencil_format(srcImage
->InternalFormat
)) {
3054 _mesa_unlock_texture(ctx
, texObj
);
3055 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3056 "glGenerateMipmap(invalid internal format)");
3060 if (target
== GL_TEXTURE_CUBE_MAP
) {
3062 for (face
= 0; face
< 6; face
++)
3063 ctx
->Driver
.GenerateMipmap(ctx
,
3064 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
3068 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3070 _mesa_unlock_texture(ctx
, texObj
);
3074 static const struct gl_renderbuffer_attachment
*
3075 find_attachment(const struct gl_framebuffer
*fb
,
3076 const struct gl_renderbuffer
*rb
)
3079 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
3080 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
3081 return &fb
->Attachment
[i
];
3088 * Helper function for checking if the datatypes of color buffers are
3089 * compatible for glBlitFramebuffer. From the 3.1 spec, page 198:
3091 * "GL_INVALID_OPERATION is generated if mask contains GL_COLOR_BUFFER_BIT
3092 * and any of the following conditions hold:
3093 * - The read buffer contains fixed-point or floating-point values and any
3094 * draw buffer contains neither fixed-point nor floating-point values.
3095 * - The read buffer contains unsigned integer values and any draw buffer
3096 * does not contain unsigned integer values.
3097 * - The read buffer contains signed integer values and any draw buffer
3098 * does not contain signed integer values."
3101 compatible_color_datatypes(gl_format srcFormat
, gl_format dstFormat
)
3103 GLenum srcType
= _mesa_get_format_datatype(srcFormat
);
3104 GLenum dstType
= _mesa_get_format_datatype(dstFormat
);
3106 if (srcType
!= GL_INT
&& srcType
!= GL_UNSIGNED_INT
) {
3107 assert(srcType
== GL_UNSIGNED_NORMALIZED
||
3108 srcType
== GL_SIGNED_NORMALIZED
||
3109 srcType
== GL_FLOAT
);
3110 /* Boil any of those types down to GL_FLOAT */
3114 if (dstType
!= GL_INT
&& dstType
!= GL_UNSIGNED_INT
) {
3115 assert(dstType
== GL_UNSIGNED_NORMALIZED
||
3116 dstType
== GL_SIGNED_NORMALIZED
||
3117 dstType
== GL_FLOAT
);
3118 /* Boil any of those types down to GL_FLOAT */
3122 return srcType
== dstType
;
3127 compatible_resolve_formats(const struct gl_renderbuffer
*readRb
,
3128 const struct gl_renderbuffer
*drawRb
)
3130 GLenum readFormat
, drawFormat
;
3132 /* The simple case where we know the backing Mesa formats are the same.
3134 if (_mesa_get_srgb_format_linear(readRb
->Format
) ==
3135 _mesa_get_srgb_format_linear(drawRb
->Format
)) {
3139 /* The Mesa formats are different, so we must check whether the internal
3140 * formats are compatible.
3142 * Under some circumstances, the user may request e.g. two GL_RGBA8
3143 * textures and get two entirely different Mesa formats like RGBA8888 and
3144 * ARGB8888. Drivers behaving like that should be able to cope with
3145 * non-matching formats by themselves, because it's not the user's fault.
3147 * Blits between linear and sRGB formats are also allowed.
3149 readFormat
= _mesa_get_nongeneric_internalformat(readRb
->InternalFormat
);
3150 drawFormat
= _mesa_get_nongeneric_internalformat(drawRb
->InternalFormat
);
3151 readFormat
= _mesa_get_linear_internalformat(readFormat
);
3152 drawFormat
= _mesa_get_linear_internalformat(drawFormat
);
3154 if (readFormat
== drawFormat
) {
3162 is_valid_blit_filter(const struct gl_context
*ctx
, GLenum filter
)
3168 case GL_SCALED_RESOLVE_FASTEST_EXT
:
3169 case GL_SCALED_RESOLVE_NICEST_EXT
:
3170 return ctx
->Extensions
.EXT_framebuffer_multisample_blit_scaled
;
3177 * Blit rectangular region, optionally from one framebuffer to another.
3179 * Note, if the src buffer is multisampled and the dest is not, this is
3180 * when the samples must be resolved to a single color.
3183 _mesa_BlitFramebuffer(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
3184 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
3185 GLbitfield mask
, GLenum filter
)
3187 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
3188 GL_DEPTH_BUFFER_BIT
|
3189 GL_STENCIL_BUFFER_BIT
);
3190 const struct gl_framebuffer
*readFb
, *drawFb
;
3191 GET_CURRENT_CONTEXT(ctx
);
3193 FLUSH_VERTICES(ctx
, 0);
3195 if (MESA_VERBOSE
& VERBOSE_API
)
3197 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
3198 srcX0
, srcY0
, srcX1
, srcY1
,
3199 dstX0
, dstY0
, dstX1
, dstY1
,
3200 mask
, _mesa_lookup_enum_by_nr(filter
));
3202 if (ctx
->NewState
) {
3203 _mesa_update_state(ctx
);
3206 readFb
= ctx
->ReadBuffer
;
3207 drawFb
= ctx
->DrawBuffer
;
3209 if (!readFb
|| !drawFb
) {
3210 /* This will normally never happen but someday we may want to
3211 * support MakeCurrent() with no drawables.
3216 /* check for complete framebuffers */
3217 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
3218 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
3219 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
3220 "glBlitFramebufferEXT(incomplete draw/read buffers)");
3224 if (!is_valid_blit_filter(ctx
, filter
)) {
3225 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(%s)",
3226 _mesa_lookup_enum_by_nr(filter
));
3230 if ((filter
== GL_SCALED_RESOLVE_FASTEST_EXT
||
3231 filter
== GL_SCALED_RESOLVE_NICEST_EXT
) &&
3232 (readFb
->Visual
.samples
== 0 || drawFb
->Visual
.samples
> 0)) {
3233 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT(%s)",
3234 _mesa_lookup_enum_by_nr(filter
));
3238 if (mask
& ~legalMaskBits
) {
3239 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
3243 /* depth/stencil must be blitted with nearest filtering */
3244 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
3245 && filter
!= GL_NEAREST
) {
3246 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3247 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
3251 /* get color read/draw renderbuffers */
3252 if (mask
& GL_COLOR_BUFFER_BIT
) {
3253 const GLuint numColorDrawBuffers
= ctx
->DrawBuffer
->_NumColorDrawBuffers
;
3254 const struct gl_renderbuffer
*colorReadRb
= readFb
->_ColorReadBuffer
;
3255 const struct gl_renderbuffer
*colorDrawRb
= NULL
;
3258 /* From the EXT_framebuffer_object spec:
3260 * "If a buffer is specified in <mask> and does not exist in both
3261 * the read and draw framebuffers, the corresponding bit is silently
3264 if (!colorReadRb
|| numColorDrawBuffers
== 0) {
3265 mask
&= ~GL_COLOR_BUFFER_BIT
;
3268 for (i
= 0; i
< numColorDrawBuffers
; i
++) {
3269 colorDrawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
3273 /* Page 193 (page 205 of the PDF) in section 4.3.2 of the OpenGL
3274 * ES 3.0.1 spec says:
3276 * "If the source and destination buffers are identical, an
3277 * INVALID_OPERATION error is generated. Different mipmap
3278 * levels of a texture, different layers of a three-
3279 * dimensional texture or two-dimensional array texture, and
3280 * different faces of a cube map texture do not constitute
3281 * identical buffers."
3283 if (_mesa_is_gles3(ctx
) && (colorDrawRb
== colorReadRb
)) {
3284 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3285 "glBlitFramebuffer(source and destination color "
3286 "buffer cannot be the same)");
3290 if (!compatible_color_datatypes(colorReadRb
->Format
,
3291 colorDrawRb
->Format
)) {
3292 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3293 "glBlitFramebufferEXT(color buffer datatypes mismatch)");
3296 /* extra checks for multisample copies... */
3297 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
3298 /* color formats must match */
3299 if (!compatible_resolve_formats(colorReadRb
, colorDrawRb
)) {
3300 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3301 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
3306 if (filter
!= GL_NEAREST
) {
3307 /* From EXT_framebuffer_multisample_blit_scaled specification:
3308 * "Calling BlitFramebuffer will result in an INVALID_OPERATION error
3309 * if filter is not NEAREST and read buffer contains integer data."
3311 GLenum type
= _mesa_get_format_datatype(colorReadRb
->Format
);
3312 if (type
== GL_INT
|| type
== GL_UNSIGNED_INT
) {
3313 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3314 "glBlitFramebufferEXT(integer color type)");
3321 if (mask
& GL_STENCIL_BUFFER_BIT
) {
3322 struct gl_renderbuffer
*readRb
=
3323 readFb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3324 struct gl_renderbuffer
*drawRb
=
3325 drawFb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3327 /* From the EXT_framebuffer_object spec:
3329 * "If a buffer is specified in <mask> and does not exist in both
3330 * the read and draw framebuffers, the corresponding bit is silently
3333 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
3334 mask
&= ~GL_STENCIL_BUFFER_BIT
;
3337 int read_z_bits
, draw_z_bits
;
3339 if (_mesa_is_gles3(ctx
) && (drawRb
== readRb
)) {
3340 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3341 "glBlitFramebuffer(source and destination stencil "
3342 "buffer cannot be the same)");
3346 if (_mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
3347 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
3348 /* There is no need to check the stencil datatype here, because
3349 * there is only one: GL_UNSIGNED_INT.
3351 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3352 "glBlitFramebuffer(stencil attachment format mismatch)");
3356 read_z_bits
= _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
);
3357 draw_z_bits
= _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
);
3359 /* If both buffers also have depth data, the depth formats must match
3360 * as well. If one doesn't have depth, it's not blitted, so we should
3361 * ignore the depth format check.
3363 if (read_z_bits
> 0 && draw_z_bits
> 0 &&
3364 (read_z_bits
!= draw_z_bits
||
3365 _mesa_get_format_datatype(readRb
->Format
) !=
3366 _mesa_get_format_datatype(drawRb
->Format
))) {
3368 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebuffer"
3369 "(stencil attachment depth format mismatch)");
3375 if (mask
& GL_DEPTH_BUFFER_BIT
) {
3376 struct gl_renderbuffer
*readRb
=
3377 readFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3378 struct gl_renderbuffer
*drawRb
=
3379 drawFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3381 /* From the EXT_framebuffer_object spec:
3383 * "If a buffer is specified in <mask> and does not exist in both
3384 * the read and draw framebuffers, the corresponding bit is silently
3387 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
3388 mask
&= ~GL_DEPTH_BUFFER_BIT
;
3391 int read_s_bit
, draw_s_bit
;
3393 if (_mesa_is_gles3(ctx
) && (drawRb
== readRb
)) {
3394 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3395 "glBlitFramebuffer(source and destination depth "
3396 "buffer cannot be the same)");
3400 if ((_mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
3401 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) ||
3402 (_mesa_get_format_datatype(readRb
->Format
) !=
3403 _mesa_get_format_datatype(drawRb
->Format
))) {
3404 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3405 "glBlitFramebuffer(depth attachment format mismatch)");
3409 read_s_bit
= _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
);
3410 draw_s_bit
= _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
);
3412 /* If both buffers also have stencil data, the stencil formats must
3413 * match as well. If one doesn't have stencil, it's not blitted, so
3414 * we should ignore the stencil format check.
3416 if (read_s_bit
> 0 && draw_s_bit
> 0 && read_s_bit
!= draw_s_bit
) {
3417 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebuffer"
3418 "(depth attachment stencil bits mismatch)");
3425 if (_mesa_is_gles3(ctx
)) {
3426 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3429 * "If SAMPLE_BUFFERS for the draw framebuffer is greater than zero,
3430 * an INVALID_OPERATION error is generated."
3432 if (drawFb
->Visual
.samples
> 0) {
3433 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3434 "glBlitFramebuffer(destination samples must be 0)");
3438 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3441 * "If SAMPLE_BUFFERS for the read framebuffer is greater than zero,
3442 * no copy is performed and an INVALID_OPERATION error is generated
3443 * if the formats of the read and draw framebuffers are not
3444 * identical or if the source and destination rectangles are not
3445 * defined with the same (X0, Y0) and (X1, Y1) bounds."
3447 * The format check was made above because desktop OpenGL has the same
3450 if (readFb
->Visual
.samples
> 0
3451 && (srcX0
!= dstX0
|| srcY0
!= dstY0
3452 || srcX1
!= dstX1
|| srcY1
!= dstY1
)) {
3453 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3454 "glBlitFramebuffer(bad src/dst multisample region)");
3458 if (readFb
->Visual
.samples
> 0 &&
3459 drawFb
->Visual
.samples
> 0 &&
3460 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
3461 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3462 "glBlitFramebufferEXT(mismatched samples)");
3466 /* extra checks for multisample copies... */
3467 if ((readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) &&
3468 (filter
== GL_NEAREST
|| filter
== GL_LINEAR
)) {
3469 /* src and dest region sizes must be the same */
3470 if (abs(srcX1
- srcX0
) != abs(dstX1
- dstX0
) ||
3471 abs(srcY1
- srcY0
) != abs(dstY1
- dstY0
)) {
3472 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3473 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
3479 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
3480 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
3486 const struct gl_renderbuffer
*colorReadRb
= readFb
->_ColorReadBuffer
;
3487 const struct gl_renderbuffer
*colorDrawRb
= NULL
;
3490 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
3492 srcX0
, srcY0
, srcX1
, srcY1
,
3493 dstX0
, dstY0
, dstX1
, dstY1
,
3496 const struct gl_renderbuffer_attachment
*att
;
3498 att
= find_attachment(readFb
, colorReadRb
);
3499 printf(" Src FBO %u RB %u (%dx%d) ",
3500 readFb
->Name
, colorReadRb
->Name
,
3501 colorReadRb
->Width
, colorReadRb
->Height
);
3502 if (att
&& att
->Texture
) {
3503 printf("Tex %u tgt 0x%x level %u face %u",
3505 att
->Texture
->Target
,
3511 /* Print all active color render buffers */
3512 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
3513 colorDrawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
3517 att
= find_attachment(drawFb
, colorDrawRb
);
3518 printf(" Dst FBO %u RB %u (%dx%d) ",
3519 drawFb
->Name
, colorDrawRb
->Name
,
3520 colorDrawRb
->Width
, colorDrawRb
->Height
);
3521 if (att
&& att
->Texture
) {
3522 printf("Tex %u tgt 0x%x level %u face %u",
3524 att
->Texture
->Target
,
3534 (srcX1
- srcX0
) == 0 || (srcY1
- srcY0
) == 0 ||
3535 (dstX1
- dstX0
) == 0 || (dstY1
- dstY0
) == 0) {
3539 ASSERT(ctx
->Driver
.BlitFramebuffer
);
3540 ctx
->Driver
.BlitFramebuffer(ctx
,
3541 srcX0
, srcY0
, srcX1
, srcY1
,
3542 dstX0
, dstY0
, dstX1
, dstY1
,
3548 invalidate_framebuffer_storage(GLenum target
, GLsizei numAttachments
,
3549 const GLenum
*attachments
, GLint x
, GLint y
,
3550 GLsizei width
, GLsizei height
, const char *name
)
3553 struct gl_framebuffer
*fb
;
3554 GET_CURRENT_CONTEXT(ctx
);
3556 fb
= get_framebuffer_target(ctx
, target
);
3558 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", name
);
3562 if (numAttachments
< 0) {
3563 _mesa_error(ctx
, GL_INVALID_VALUE
,
3564 "%s(numAttachments < 0)", name
);
3568 /* The GL_ARB_invalidate_subdata spec says:
3570 * "If an attachment is specified that does not exist in the
3571 * framebuffer bound to <target>, it is ignored."
3575 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
3576 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
3577 * INVALID_OPERATION is generated."
3579 * No mention is made of GL_AUXi being out of range. Therefore, we allow
3580 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
3581 * set of retrictions).
3583 for (i
= 0; i
< numAttachments
; i
++) {
3584 if (_mesa_is_winsys_fbo(fb
)) {
3585 switch (attachments
[i
]) {
3591 /* Accumulation buffers and auxilary buffers were removed in
3592 * OpenGL 3.1, and they never existed in OpenGL ES.
3594 if (ctx
->API
!= API_OPENGL_COMPAT
)
3604 case GL_FRONT_RIGHT
:
3605 if (!_mesa_is_desktop_gl(ctx
))
3612 switch (attachments
[i
]) {
3613 case GL_DEPTH_ATTACHMENT
:
3614 case GL_STENCIL_ATTACHMENT
:
3616 case GL_COLOR_ATTACHMENT0
:
3617 case GL_COLOR_ATTACHMENT1
:
3618 case GL_COLOR_ATTACHMENT2
:
3619 case GL_COLOR_ATTACHMENT3
:
3620 case GL_COLOR_ATTACHMENT4
:
3621 case GL_COLOR_ATTACHMENT5
:
3622 case GL_COLOR_ATTACHMENT6
:
3623 case GL_COLOR_ATTACHMENT7
:
3624 case GL_COLOR_ATTACHMENT8
:
3625 case GL_COLOR_ATTACHMENT9
:
3626 case GL_COLOR_ATTACHMENT10
:
3627 case GL_COLOR_ATTACHMENT11
:
3628 case GL_COLOR_ATTACHMENT12
:
3629 case GL_COLOR_ATTACHMENT13
:
3630 case GL_COLOR_ATTACHMENT14
:
3631 case GL_COLOR_ATTACHMENT15
: {
3632 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
3633 if (k
>= ctx
->Const
.MaxColorAttachments
) {
3634 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3635 "%s(attachment >= max. color attachments)", name
);
3646 /* We don't actually do anything for this yet. Just return after
3647 * validating the parameters and generating the required errors.
3652 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(attachment)", name
);
3657 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
3658 const GLenum
*attachments
, GLint x
, GLint y
,
3659 GLsizei width
, GLsizei height
)
3661 invalidate_framebuffer_storage(target
, numAttachments
, attachments
,
3662 x
, y
, width
, height
,
3663 "glInvalidateSubFramebuffer");
3667 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
3668 const GLenum
*attachments
)
3670 /* The GL_ARB_invalidate_subdata spec says:
3674 * void InvalidateFramebuffer(enum target,
3675 * sizei numAttachments,
3676 * const enum *attachments);
3678 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
3679 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
3680 * <MAX_VIEWPORT_DIMS[1]> respectively."
3682 invalidate_framebuffer_storage(target
, numAttachments
, attachments
,
3683 0, 0, MAX_VIEWPORT_WIDTH
, MAX_VIEWPORT_HEIGHT
,
3684 "glInvalidateFramebuffer");
3688 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
3689 const GLenum
*attachments
)
3691 struct gl_framebuffer
*fb
;
3694 GET_CURRENT_CONTEXT(ctx
);
3696 fb
= get_framebuffer_target(ctx
, target
);
3698 _mesa_error(ctx
, GL_INVALID_ENUM
,
3699 "glDiscardFramebufferEXT(target %s)",
3700 _mesa_lookup_enum_by_nr(target
));
3704 if (numAttachments
< 0) {
3705 _mesa_error(ctx
, GL_INVALID_VALUE
,
3706 "glDiscardFramebufferEXT(numAttachments < 0)");
3710 for (i
= 0; i
< numAttachments
; i
++) {
3711 switch (attachments
[i
]) {
3715 if (_mesa_is_user_fbo(fb
))
3718 case GL_COLOR_ATTACHMENT0
:
3719 case GL_DEPTH_ATTACHMENT
:
3720 case GL_STENCIL_ATTACHMENT
:
3721 if (_mesa_is_winsys_fbo(fb
))
3729 if (ctx
->Driver
.DiscardFramebuffer
)
3730 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
3735 _mesa_error(ctx
, GL_INVALID_ENUM
,
3736 "glDiscardFramebufferEXT(attachment %s)",
3737 _mesa_lookup_enum_by_nr(attachments
[i
]));