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
];
391 rb
= att
->Renderbuffer
;
393 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
395 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
398 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
400 /* This can't get called on a texture renderbuffer, so set it to NULL
401 * for clarity compared to user renderbuffers.
403 rb
->AllocStorage
= NULL
;
405 rb
->NeedsFinishRenderTexture
= ctx
->Driver
.FinishRenderTexture
!= NULL
;
408 rb
->_BaseFormat
= texImage
->_BaseFormat
;
409 rb
->Format
= texImage
->TexFormat
;
410 rb
->InternalFormat
= texImage
->InternalFormat
;
411 rb
->Width
= texImage
->Width2
;
412 rb
->Height
= texImage
->Height2
;
413 rb
->NumSamples
= texImage
->NumSamples
;
414 rb
->TexImage
= texImage
;
416 if (driver_RenderTexture_is_safe(att
))
417 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
421 * Bind a texture object to an attachment point.
422 * The previous binding, if any, will be removed first.
425 _mesa_set_texture_attachment(struct gl_context
*ctx
,
426 struct gl_framebuffer
*fb
,
427 struct gl_renderbuffer_attachment
*att
,
428 struct gl_texture_object
*texObj
,
429 GLenum texTarget
, GLuint level
, GLuint zoffset
,
432 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
434 if (rb
&& rb
->NeedsFinishRenderTexture
)
435 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
437 if (att
->Texture
== texObj
) {
438 /* re-attaching same texture */
439 ASSERT(att
->Type
== GL_TEXTURE
);
443 _mesa_remove_attachment(ctx
, att
);
444 att
->Type
= GL_TEXTURE
;
445 assert(!att
->Texture
);
446 _mesa_reference_texobj(&att
->Texture
, texObj
);
448 invalidate_framebuffer(fb
);
450 /* always update these fields */
451 att
->TextureLevel
= level
;
452 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
453 att
->Zoffset
= zoffset
;
454 att
->Layered
= layered
;
455 att
->Complete
= GL_FALSE
;
457 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
462 * Bind a renderbuffer to an attachment point.
463 * The previous binding, if any, will be removed first.
466 _mesa_set_renderbuffer_attachment(struct gl_context
*ctx
,
467 struct gl_renderbuffer_attachment
*att
,
468 struct gl_renderbuffer
*rb
)
470 /* XXX check if re-doing same attachment, exit early */
471 _mesa_remove_attachment(ctx
, att
);
472 att
->Type
= GL_RENDERBUFFER_EXT
;
473 att
->Texture
= NULL
; /* just to be safe */
474 att
->Complete
= GL_FALSE
;
475 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
480 * Fallback for ctx->Driver.FramebufferRenderbuffer()
481 * Attach a renderbuffer object to a framebuffer object.
484 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
485 struct gl_framebuffer
*fb
,
486 GLenum attachment
, struct gl_renderbuffer
*rb
)
488 struct gl_renderbuffer_attachment
*att
;
490 _glthread_LOCK_MUTEX(fb
->Mutex
);
492 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
495 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
496 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
497 /* do stencil attachment here (depth already done above) */
498 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
500 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
502 rb
->AttachedAnytime
= GL_TRUE
;
505 _mesa_remove_attachment(ctx
, att
);
508 invalidate_framebuffer(fb
);
510 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
515 * Fallback for ctx->Driver.ValidateFramebuffer()
516 * Check if the renderbuffer's formats are supported by the software
518 * Drivers should probably override this.
521 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
524 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
525 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
527 switch (rb
->_BaseFormat
) {
529 case GL_LUMINANCE_ALPHA
:
534 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
538 switch (rb
->Format
) {
539 /* XXX This list is likely incomplete. */
540 case MESA_FORMAT_RGB9_E5_FLOAT
:
541 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
544 /* render buffer format is supported by software rendering */
553 * Return true if the framebuffer has a combined depth/stencil
554 * renderbuffer attached.
557 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
559 const struct gl_renderbuffer_attachment
*depth
=
560 &fb
->Attachment
[BUFFER_DEPTH
];
561 const struct gl_renderbuffer_attachment
*stencil
=
562 &fb
->Attachment
[BUFFER_STENCIL
];
564 if (depth
->Type
== stencil
->Type
) {
565 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
566 depth
->Renderbuffer
== stencil
->Renderbuffer
)
569 if (depth
->Type
== GL_TEXTURE
&&
570 depth
->Texture
== stencil
->Texture
)
582 att_incomplete(const char *msg
)
584 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
585 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
594 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
596 static GLuint msg_id
;
598 _mesa_gl_debug(ctx
, &msg_id
,
599 MESA_DEBUG_TYPE_OTHER
,
600 MESA_DEBUG_SEVERITY_MEDIUM
,
601 "FBO incomplete: %s [%d]\n", msg
, index
);
603 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
604 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
610 * Is the given base format a legal format for a color renderbuffer?
613 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
615 switch (baseFormat
) {
620 case GL_LUMINANCE_ALPHA
:
623 return ctx
->API
== API_OPENGL_COMPAT
&&
624 ctx
->Extensions
.ARB_framebuffer_object
;
627 return ctx
->Extensions
.ARB_texture_rg
;
635 * Is the given base format a legal format for a color renderbuffer?
638 is_format_color_renderable(const struct gl_context
*ctx
, gl_format format
, GLenum internalFormat
)
640 const GLenum baseFormat
=
641 _mesa_get_format_base_format(format
);
644 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
645 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
649 /* Reject additional cases for GLES */
650 switch (internalFormat
) {
670 if (format
== MESA_FORMAT_ARGB2101010
&& internalFormat
!= GL_RGB10_A2
) {
679 * Is the given base format a legal format for a depth/stencil renderbuffer?
682 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
684 switch (baseFormat
) {
685 case GL_DEPTH_COMPONENT
:
686 case GL_DEPTH_STENCIL_EXT
:
695 * Test if an attachment point is complete and update its Complete field.
696 * \param format if GL_COLOR, this is a color attachment point,
697 * if GL_DEPTH, this is a depth component attachment point,
698 * if GL_STENCIL, this is a stencil component attachment point.
701 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
702 struct gl_renderbuffer_attachment
*att
)
704 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
706 /* assume complete */
707 att
->Complete
= GL_TRUE
;
709 /* Look for reasons why the attachment might be incomplete */
710 if (att
->Type
== GL_TEXTURE
) {
711 const struct gl_texture_object
*texObj
= att
->Texture
;
712 struct gl_texture_image
*texImage
;
716 att_incomplete("no texobj");
717 att
->Complete
= GL_FALSE
;
721 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
723 att_incomplete("no teximage");
724 att
->Complete
= GL_FALSE
;
727 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
728 att_incomplete("teximage width/height=0");
729 att
->Complete
= GL_FALSE
;
732 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
733 att_incomplete("bad z offset");
734 att
->Complete
= GL_FALSE
;
738 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
740 if (format
== GL_COLOR
) {
741 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
742 att_incomplete("bad format");
743 att
->Complete
= GL_FALSE
;
746 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
747 att_incomplete("compressed internalformat");
748 att
->Complete
= GL_FALSE
;
752 else if (format
== GL_DEPTH
) {
753 if (baseFormat
== GL_DEPTH_COMPONENT
) {
756 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
757 ctx
->Extensions
.ARB_depth_texture
&&
758 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
762 att
->Complete
= GL_FALSE
;
763 att_incomplete("bad depth format");
768 ASSERT(format
== GL_STENCIL
);
769 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
770 ctx
->Extensions
.ARB_depth_texture
&&
771 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
775 /* no such thing as stencil-only textures */
776 att_incomplete("illegal stencil texture");
777 att
->Complete
= GL_FALSE
;
782 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
783 const GLenum baseFormat
=
784 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
786 ASSERT(att
->Renderbuffer
);
787 if (!att
->Renderbuffer
->InternalFormat
||
788 att
->Renderbuffer
->Width
< 1 ||
789 att
->Renderbuffer
->Height
< 1) {
790 att_incomplete("0x0 renderbuffer");
791 att
->Complete
= GL_FALSE
;
794 if (format
== GL_COLOR
) {
795 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
796 att_incomplete("bad renderbuffer color format");
797 att
->Complete
= GL_FALSE
;
801 else if (format
== GL_DEPTH
) {
802 if (baseFormat
== GL_DEPTH_COMPONENT
) {
805 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
806 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
810 att_incomplete("bad renderbuffer depth format");
811 att
->Complete
= GL_FALSE
;
816 assert(format
== GL_STENCIL
);
817 if (baseFormat
== GL_STENCIL_INDEX
) {
820 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
821 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
825 att
->Complete
= GL_FALSE
;
826 att_incomplete("bad renderbuffer stencil format");
832 ASSERT(att
->Type
== GL_NONE
);
840 * Test if the given framebuffer object is complete and update its
841 * Status field with the results.
842 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
843 * driver to make hardware-specific validation/completeness checks.
844 * Also update the framebuffer's Width and Height fields if the
845 * framebuffer is complete.
848 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
849 struct gl_framebuffer
*fb
)
852 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
853 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
854 GLint numSamples
= -1;
855 GLint fixedSampleLocations
= -1;
858 bool layer_count_valid
= false;
859 GLuint layer_count
= 0, att_layer_count
;
861 assert(_mesa_is_user_fbo(fb
));
863 /* we're changing framebuffer fields here */
864 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
869 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
870 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
872 /* Start at -2 to more easily loop over all attachment points.
877 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
878 struct gl_renderbuffer_attachment
*att
;
883 * XXX for ARB_fbo, only check color buffers that are named by
884 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
887 /* check for attachment completeness
890 att
= &fb
->Attachment
[BUFFER_DEPTH
];
891 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
892 if (!att
->Complete
) {
893 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
894 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
899 att
= &fb
->Attachment
[BUFFER_STENCIL
];
900 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
901 if (!att
->Complete
) {
902 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
903 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
908 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
909 test_attachment_completeness(ctx
, GL_COLOR
, att
);
910 if (!att
->Complete
) {
911 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
912 fbo_incomplete(ctx
, "color attachment incomplete", i
);
917 /* get width, height, format of the renderbuffer/texture
919 if (att
->Type
== GL_TEXTURE
) {
920 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
921 minWidth
= MIN2(minWidth
, texImg
->Width
);
922 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
923 minHeight
= MIN2(minHeight
, texImg
->Height
);
924 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
925 f
= texImg
->_BaseFormat
;
926 attFormat
= texImg
->TexFormat
;
929 if (!is_format_color_renderable(ctx
, attFormat
, texImg
->InternalFormat
) &&
930 !is_legal_depth_format(ctx
, f
)) {
931 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
932 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
937 numSamples
= texImg
->NumSamples
;
938 else if (numSamples
!= texImg
->NumSamples
) {
939 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
940 fbo_incomplete(ctx
, "inconsistent sample count", -1);
944 if (fixedSampleLocations
< 0)
945 fixedSampleLocations
= texImg
->FixedSampleLocations
;
946 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
947 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
948 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
952 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
953 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
954 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
955 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
956 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
957 f
= att
->Renderbuffer
->InternalFormat
;
958 attFormat
= att
->Renderbuffer
->Format
;
962 numSamples
= att
->Renderbuffer
->NumSamples
;
963 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
964 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
965 fbo_incomplete(ctx
, "inconsistent sample count", -1);
969 /* RENDERBUFFER has fixedSampleLocations implicitly true */
970 if (fixedSampleLocations
< 0)
971 fixedSampleLocations
= GL_TRUE
;
972 else if (fixedSampleLocations
!= GL_TRUE
) {
973 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
974 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
979 assert(att
->Type
== GL_NONE
);
983 /* check if integer color */
984 fb
->_IntegerColor
= _mesa_is_format_integer_color(attFormat
);
986 /* Update _AllColorBuffersFixedPoint and _HasSNormOrFloatColorBuffer. */
988 GLenum type
= _mesa_get_format_datatype(attFormat
);
990 fb
->_AllColorBuffersFixedPoint
=
991 fb
->_AllColorBuffersFixedPoint
&&
992 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
994 fb
->_HasSNormOrFloatColorBuffer
=
995 fb
->_HasSNormOrFloatColorBuffer
||
996 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
999 /* Error-check width, height, format */
1000 if (numImages
== 1) {
1007 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1008 /* check that width, height, format are same */
1009 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1010 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1011 fbo_incomplete(ctx
, "width or height mismatch", -1);
1014 /* check that all color buffers are the same format */
1015 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1016 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1017 fbo_incomplete(ctx
, "format mismatch", -1);
1023 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1025 if (att
->Type
== GL_RENDERBUFFER
&&
1026 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1027 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1028 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1032 /* Check that layered rendering is consistent. */
1033 att_layer_count
= att
->Layered
? att
->Renderbuffer
->Depth
: 0;
1034 if (!layer_count_valid
) {
1035 layer_count
= att_layer_count
;
1036 layer_count_valid
= true;
1037 } else if (layer_count
!= att_layer_count
) {
1038 if (layer_count
== 0 || att_layer_count
== 0) {
1039 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1040 fbo_incomplete(ctx
, "framebuffer attachment layer mode is inconsistent", i
);
1042 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
;
1043 fbo_incomplete(ctx
, "framebuffer attachment layer count is inconsistent", i
);
1049 fb
->Layered
= layer_count
> 0;
1051 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1052 /* Check that all DrawBuffers are present */
1053 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1054 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1055 const struct gl_renderbuffer_attachment
*att
1056 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
1058 if (att
->Type
== GL_NONE
) {
1059 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1060 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1066 /* Check that the ReadBuffer is present */
1067 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1068 const struct gl_renderbuffer_attachment
*att
1069 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
1071 if (att
->Type
== GL_NONE
) {
1072 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1073 fbo_incomplete(ctx
, "missing readbuffer", -1);
1079 if (numImages
== 0) {
1080 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1081 fbo_incomplete(ctx
, "no attachments", -1);
1085 /* Provisionally set status = COMPLETE ... */
1086 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1088 /* ... but the driver may say the FB is incomplete.
1089 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1092 if (ctx
->Driver
.ValidateFramebuffer
) {
1093 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1094 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1095 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1099 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
1101 * Note that if ARB_framebuffer_object is supported and the attached
1102 * renderbuffers/textures are different sizes, the framebuffer
1103 * width/height will be set to the smallest width/height.
1105 fb
->Width
= minWidth
;
1106 fb
->Height
= minHeight
;
1108 /* finally, update the visual info for the framebuffer */
1109 _mesa_update_framebuffer_visual(ctx
, fb
);
1114 GLboolean GLAPIENTRY
1115 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1117 GET_CURRENT_CONTEXT(ctx
);
1118 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1120 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1121 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
1129 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1131 struct gl_renderbuffer
*newRb
;
1132 GET_CURRENT_CONTEXT(ctx
);
1134 if (target
!= GL_RENDERBUFFER_EXT
) {
1135 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1139 /* No need to flush here since the render buffer binding has no
1140 * effect on rendering state.
1144 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1145 if (newRb
== &DummyRenderbuffer
) {
1146 /* ID was reserved, but no real renderbuffer object made yet */
1149 else if (!newRb
&& !allow_user_names
) {
1150 /* All RB IDs must be Gen'd */
1151 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1156 /* create new renderbuffer object */
1157 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1159 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
1162 ASSERT(newRb
->AllocStorage
);
1163 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1164 newRb
->RefCount
= 1; /* referenced by hash table */
1171 ASSERT(newRb
!= &DummyRenderbuffer
);
1173 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1177 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1179 GET_CURRENT_CONTEXT(ctx
);
1181 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1182 * entry point, but they allow the use of user-generated names.
1184 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1188 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1190 /* This function should not be in the dispatch table for core profile /
1191 * OpenGL 3.1, so execution should never get here in those cases -- no
1192 * need for an explicit test.
1194 bind_renderbuffer(target
, renderbuffer
, true);
1199 * If the given renderbuffer is anywhere attached to the framebuffer, detach
1201 * This is used when a renderbuffer object is deleted.
1202 * The spec calls for unbinding.
1205 detach_renderbuffer(struct gl_context
*ctx
,
1206 struct gl_framebuffer
*fb
,
1207 struct gl_renderbuffer
*rb
)
1210 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1211 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
1212 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
1215 invalidate_framebuffer(fb
);
1220 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1223 GET_CURRENT_CONTEXT(ctx
);
1225 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1227 for (i
= 0; i
< n
; i
++) {
1228 if (renderbuffers
[i
] > 0) {
1229 struct gl_renderbuffer
*rb
;
1230 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1232 /* check if deleting currently bound renderbuffer object */
1233 if (rb
== ctx
->CurrentRenderbuffer
) {
1235 ASSERT(rb
->RefCount
>= 2);
1236 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1239 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1240 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1242 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1243 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1244 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1247 /* Remove from hash table immediately, to free the ID.
1248 * But the object will not be freed until it's no longer
1249 * referenced anywhere else.
1251 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1253 if (rb
!= &DummyRenderbuffer
) {
1254 /* no longer referenced by hash table */
1255 _mesa_reference_renderbuffer(&rb
, NULL
);
1264 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1266 GET_CURRENT_CONTEXT(ctx
);
1271 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
1278 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1280 for (i
= 0; i
< n
; i
++) {
1281 GLuint name
= first
+ i
;
1282 renderbuffers
[i
] = name
;
1283 /* insert dummy placeholder into hash table */
1284 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1285 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
1286 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1292 * Given an internal format token for a render buffer, return the
1293 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1294 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1295 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1297 * This is similar to _mesa_base_tex_format() but the set of valid
1298 * internal formats is different.
1300 * Note that even if a format is determined to be legal here, validation
1301 * of the FBO may fail if the format is not supported by the driver/GPU.
1303 * \param internalFormat as passed to glRenderbufferStorage()
1304 * \return the base internal format, or 0 if internalFormat is illegal
1307 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1310 * Notes: some formats such as alpha, luminance, etc. were added
1311 * with GL_ARB_framebuffer_object.
1313 switch (internalFormat
) {
1319 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1324 case GL_LUMINANCE12
:
1325 case GL_LUMINANCE16
:
1326 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1328 case GL_LUMINANCE_ALPHA
:
1329 case GL_LUMINANCE4_ALPHA4
:
1330 case GL_LUMINANCE6_ALPHA2
:
1331 case GL_LUMINANCE8_ALPHA8
:
1332 case GL_LUMINANCE12_ALPHA4
:
1333 case GL_LUMINANCE12_ALPHA12
:
1334 case GL_LUMINANCE16_ALPHA16
:
1335 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1336 ? GL_LUMINANCE_ALPHA
: 0;
1340 case GL_INTENSITY12
:
1341 case GL_INTENSITY16
:
1342 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1353 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1355 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1364 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1366 case GL_SRGB8_ALPHA8_EXT
:
1367 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1368 case GL_STENCIL_INDEX
:
1369 case GL_STENCIL_INDEX1_EXT
:
1370 case GL_STENCIL_INDEX4_EXT
:
1371 case GL_STENCIL_INDEX16_EXT
:
1372 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1373 * OpenGL ES, but Mesa does not currently support them.
1375 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1376 case GL_STENCIL_INDEX8_EXT
:
1377 return GL_STENCIL_INDEX
;
1378 case GL_DEPTH_COMPONENT
:
1379 case GL_DEPTH_COMPONENT32
:
1380 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1381 case GL_DEPTH_COMPONENT16
:
1382 case GL_DEPTH_COMPONENT24
:
1383 return GL_DEPTH_COMPONENT
;
1384 case GL_DEPTH_STENCIL_EXT
:
1385 return _mesa_is_desktop_gl(ctx
)
1386 && ctx
->Extensions
.EXT_packed_depth_stencil
1387 ? GL_DEPTH_STENCIL_EXT
: 0;
1388 case GL_DEPTH24_STENCIL8_EXT
:
1389 return ctx
->Extensions
.EXT_packed_depth_stencil
1390 ? GL_DEPTH_STENCIL_EXT
: 0;
1391 case GL_DEPTH_COMPONENT32F
:
1392 return ctx
->Version
>= 30
1393 || (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_buffer_float
)
1394 ? GL_DEPTH_COMPONENT
: 0;
1395 case GL_DEPTH32F_STENCIL8
:
1396 return ctx
->Version
>= 30
1397 || (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_buffer_float
)
1398 ? GL_DEPTH_STENCIL
: 0;
1401 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1404 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1408 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1411 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1413 /* signed normalized texture formats */
1417 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1422 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1426 case GL_RGB16_SNORM
:
1427 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1430 case GL_RGBA8_SNORM
:
1431 case GL_RGBA16_SNORM
:
1432 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1434 case GL_ALPHA_SNORM
:
1435 case GL_ALPHA8_SNORM
:
1436 case GL_ALPHA16_SNORM
:
1437 return ctx
->API
== API_OPENGL_COMPAT
&&
1438 ctx
->Extensions
.EXT_texture_snorm
&&
1439 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1442 return ((_mesa_is_desktop_gl(ctx
) &&
1443 ctx
->Extensions
.ARB_texture_rg
&&
1444 ctx
->Extensions
.ARB_texture_float
) ||
1445 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1449 return ((_mesa_is_desktop_gl(ctx
) &&
1450 ctx
->Extensions
.ARB_texture_rg
&&
1451 ctx
->Extensions
.ARB_texture_float
) ||
1452 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1456 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1460 return ((_mesa_is_desktop_gl(ctx
) &&
1461 ctx
->Extensions
.ARB_texture_float
) ||
1462 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1464 case GL_ALPHA16F_ARB
:
1465 case GL_ALPHA32F_ARB
:
1466 return ctx
->API
== API_OPENGL_COMPAT
&&
1467 ctx
->Extensions
.ARB_texture_float
&&
1468 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1469 case GL_LUMINANCE16F_ARB
:
1470 case GL_LUMINANCE32F_ARB
:
1471 return ctx
->API
== API_OPENGL_COMPAT
&&
1472 ctx
->Extensions
.ARB_texture_float
&&
1473 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1474 case GL_LUMINANCE_ALPHA16F_ARB
:
1475 case GL_LUMINANCE_ALPHA32F_ARB
:
1476 return ctx
->API
== API_OPENGL_COMPAT
&&
1477 ctx
->Extensions
.ARB_texture_float
&&
1478 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1479 case GL_INTENSITY16F_ARB
:
1480 case GL_INTENSITY32F_ARB
:
1481 return ctx
->API
== API_OPENGL_COMPAT
&&
1482 ctx
->Extensions
.ARB_texture_float
&&
1483 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1485 return (_mesa_is_desktop_gl(ctx
)
1486 && ctx
->Extensions
.EXT_texture_shared_exponent
)
1488 case GL_R11F_G11F_B10F
:
1489 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1490 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1493 case GL_RGBA8UI_EXT
:
1494 case GL_RGBA16UI_EXT
:
1495 case GL_RGBA32UI_EXT
:
1497 case GL_RGBA16I_EXT
:
1498 case GL_RGBA32I_EXT
:
1499 return ctx
->Version
>= 30
1500 || (_mesa_is_desktop_gl(ctx
) &&
1501 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
1504 case GL_RGB16UI_EXT
:
1505 case GL_RGB32UI_EXT
:
1509 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
1517 return ctx
->Version
>= 30
1518 || (_mesa_is_desktop_gl(ctx
) &&
1519 ctx
->Extensions
.ARB_texture_rg
&&
1520 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
1528 return ctx
->Version
>= 30
1529 || (_mesa_is_desktop_gl(ctx
) &&
1530 ctx
->Extensions
.ARB_texture_rg
&&
1531 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
1533 case GL_INTENSITY8I_EXT
:
1534 case GL_INTENSITY8UI_EXT
:
1535 case GL_INTENSITY16I_EXT
:
1536 case GL_INTENSITY16UI_EXT
:
1537 case GL_INTENSITY32I_EXT
:
1538 case GL_INTENSITY32UI_EXT
:
1539 return ctx
->API
== API_OPENGL_COMPAT
&&
1540 ctx
->Extensions
.EXT_texture_integer
&&
1541 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1543 case GL_LUMINANCE8I_EXT
:
1544 case GL_LUMINANCE8UI_EXT
:
1545 case GL_LUMINANCE16I_EXT
:
1546 case GL_LUMINANCE16UI_EXT
:
1547 case GL_LUMINANCE32I_EXT
:
1548 case GL_LUMINANCE32UI_EXT
:
1549 return ctx
->API
== API_OPENGL_COMPAT
&&
1550 ctx
->Extensions
.EXT_texture_integer
&&
1551 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1553 case GL_LUMINANCE_ALPHA8I_EXT
:
1554 case GL_LUMINANCE_ALPHA8UI_EXT
:
1555 case GL_LUMINANCE_ALPHA16I_EXT
:
1556 case GL_LUMINANCE_ALPHA16UI_EXT
:
1557 case GL_LUMINANCE_ALPHA32I_EXT
:
1558 case GL_LUMINANCE_ALPHA32UI_EXT
:
1559 return ctx
->API
== API_OPENGL_COMPAT
&&
1560 ctx
->Extensions
.EXT_texture_integer
&&
1561 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1563 case GL_ALPHA8I_EXT
:
1564 case GL_ALPHA8UI_EXT
:
1565 case GL_ALPHA16I_EXT
:
1566 case GL_ALPHA16UI_EXT
:
1567 case GL_ALPHA32I_EXT
:
1568 case GL_ALPHA32UI_EXT
:
1569 return ctx
->API
== API_OPENGL_COMPAT
&&
1570 ctx
->Extensions
.EXT_texture_integer
&&
1571 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1574 return (_mesa_is_desktop_gl(ctx
) &&
1575 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
1576 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1579 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
1588 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1591 invalidate_rb(GLuint key
, void *data
, void *userData
)
1593 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1594 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
1596 /* If this is a user-created FBO */
1597 if (_mesa_is_user_fbo(fb
)) {
1599 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1600 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1601 if (att
->Type
== GL_RENDERBUFFER
&&
1602 att
->Renderbuffer
== rb
) {
1603 /* Mark fb status as indeterminate to force re-validation */
1612 /** sentinal value, see below */
1613 #define NO_SAMPLES 1000
1617 * Helper function used by _mesa_RenderbufferStorage() and
1618 * _mesa_RenderbufferStorageMultisample().
1619 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
1622 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1623 GLsizei width
, GLsizei height
, GLsizei samples
)
1625 const char *func
= samples
== NO_SAMPLES
?
1626 "glRenderbufferStorage" : "glRenderbufferStorageMultisample";
1627 struct gl_renderbuffer
*rb
;
1629 GLenum sample_count_error
;
1630 GET_CURRENT_CONTEXT(ctx
);
1632 if (MESA_VERBOSE
& VERBOSE_API
) {
1633 if (samples
== NO_SAMPLES
)
1634 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
1636 _mesa_lookup_enum_by_nr(target
),
1637 _mesa_lookup_enum_by_nr(internalFormat
),
1640 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
1642 _mesa_lookup_enum_by_nr(target
),
1643 _mesa_lookup_enum_by_nr(internalFormat
),
1644 width
, height
, samples
);
1647 if (target
!= GL_RENDERBUFFER_EXT
) {
1648 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1652 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1653 if (baseFormat
== 0) {
1654 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
1655 func
, _mesa_lookup_enum_by_nr(internalFormat
));
1659 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1660 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1664 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1665 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1669 if (samples
== NO_SAMPLES
) {
1670 /* NumSamples == 0 indicates non-multisampling */
1674 /* check the sample count;
1675 * note: driver may choose to use more samples than what's requested
1677 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
1678 internalFormat
, samples
);
1679 if (sample_count_error
!= GL_NO_ERROR
) {
1680 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
1685 rb
= ctx
->CurrentRenderbuffer
;
1687 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1691 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1693 if (rb
->InternalFormat
== internalFormat
&&
1694 rb
->Width
== (GLuint
) width
&&
1695 rb
->Height
== (GLuint
) height
&&
1696 rb
->NumSamples
== samples
) {
1697 /* no change in allocation needed */
1701 /* These MUST get set by the AllocStorage func */
1702 rb
->Format
= MESA_FORMAT_NONE
;
1703 rb
->NumSamples
= samples
;
1705 /* Now allocate the storage */
1706 ASSERT(rb
->AllocStorage
);
1707 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1708 /* No error - check/set fields now */
1709 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
1710 assert(rb
->Width
== (GLuint
) width
);
1711 assert(rb
->Height
== (GLuint
) height
);
1712 rb
->InternalFormat
= internalFormat
;
1713 rb
->_BaseFormat
= baseFormat
;
1714 assert(rb
->_BaseFormat
!= 0);
1717 /* Probably ran out of memory - clear the fields */
1720 rb
->Format
= MESA_FORMAT_NONE
;
1721 rb
->InternalFormat
= GL_NONE
;
1722 rb
->_BaseFormat
= GL_NONE
;
1726 /* Invalidate the framebuffers the renderbuffer is attached in. */
1727 if (rb
->AttachedAnytime
) {
1728 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
1734 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1736 struct gl_renderbuffer
*rb
;
1737 GET_CURRENT_CONTEXT(ctx
);
1739 if (!ctx
->Extensions
.OES_EGL_image
) {
1740 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1741 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1745 if (target
!= GL_RENDERBUFFER
) {
1746 _mesa_error(ctx
, GL_INVALID_ENUM
,
1747 "EGLImageTargetRenderbufferStorageOES");
1751 rb
= ctx
->CurrentRenderbuffer
;
1753 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1754 "EGLImageTargetRenderbufferStorageOES");
1758 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1760 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1765 * Helper function for _mesa_GetRenderbufferParameteriv() and
1766 * _mesa_GetFramebufferAttachmentParameteriv()
1767 * We have to be careful to respect the base format. For example, if a
1768 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1769 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1770 * we need to return zero.
1773 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1775 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1776 return _mesa_get_format_bits(format
, pname
);
1784 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
1785 GLsizei width
, GLsizei height
)
1787 /* GL_ARB_fbo says calling this function is equivalent to calling
1788 * glRenderbufferStorageMultisample() with samples=0. We pass in
1789 * a token value here just for error reporting purposes.
1791 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1796 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1797 GLenum internalFormat
,
1798 GLsizei width
, GLsizei height
)
1800 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1805 * OpenGL ES version of glRenderBufferStorage.
1808 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1809 GLsizei width
, GLsizei height
)
1811 switch (internalFormat
) {
1813 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1814 /* choose a closest format */
1815 internalFormat
= GL_RGB5
;
1821 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1826 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1828 struct gl_renderbuffer
*rb
;
1829 GET_CURRENT_CONTEXT(ctx
);
1831 if (target
!= GL_RENDERBUFFER_EXT
) {
1832 _mesa_error(ctx
, GL_INVALID_ENUM
,
1833 "glGetRenderbufferParameterivEXT(target)");
1837 rb
= ctx
->CurrentRenderbuffer
;
1839 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1840 "glGetRenderbufferParameterivEXT");
1844 /* No need to flush here since we're just quering state which is
1845 * not effected by rendering.
1849 case GL_RENDERBUFFER_WIDTH_EXT
:
1850 *params
= rb
->Width
;
1852 case GL_RENDERBUFFER_HEIGHT_EXT
:
1853 *params
= rb
->Height
;
1855 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1856 *params
= rb
->InternalFormat
;
1858 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1859 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1860 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1861 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1862 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1863 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1864 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1866 case GL_RENDERBUFFER_SAMPLES
:
1867 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
1868 || _mesa_is_gles3(ctx
)) {
1869 *params
= rb
->NumSamples
;
1874 _mesa_error(ctx
, GL_INVALID_ENUM
,
1875 "glGetRenderbufferParameterivEXT(target)");
1881 GLboolean GLAPIENTRY
1882 _mesa_IsFramebuffer(GLuint framebuffer
)
1884 GET_CURRENT_CONTEXT(ctx
);
1885 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1887 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1888 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1896 * Check if any of the attachments of the given framebuffer are textures
1897 * (render to texture). Call ctx->Driver.RenderTexture() for such
1901 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1904 ASSERT(ctx
->Driver
.RenderTexture
);
1906 if (_mesa_is_winsys_fbo(fb
))
1907 return; /* can't render to texture with winsys framebuffers */
1909 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1910 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1911 if (att
->Texture
&& att
->Renderbuffer
->TexImage
1912 && driver_RenderTexture_is_safe(att
)) {
1913 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1920 * Examine all the framebuffer's attachments to see if any are textures.
1921 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1922 * notify the device driver that the texture image may have changed.
1925 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1927 if (_mesa_is_winsys_fbo(fb
))
1928 return; /* can't render to texture with winsys framebuffers */
1930 if (ctx
->Driver
.FinishRenderTexture
) {
1932 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1933 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1934 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
1935 if (rb
&& rb
->NeedsFinishRenderTexture
) {
1936 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
1944 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
1946 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1947 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1948 GLboolean bindReadBuf
, bindDrawBuf
;
1949 GET_CURRENT_CONTEXT(ctx
);
1952 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1953 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1958 case GL_DRAW_FRAMEBUFFER_EXT
:
1959 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1960 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1963 bindDrawBuf
= GL_TRUE
;
1964 bindReadBuf
= GL_FALSE
;
1966 case GL_READ_FRAMEBUFFER_EXT
:
1967 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1968 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1971 bindDrawBuf
= GL_FALSE
;
1972 bindReadBuf
= GL_TRUE
;
1974 case GL_FRAMEBUFFER_EXT
:
1975 bindDrawBuf
= GL_TRUE
;
1976 bindReadBuf
= GL_TRUE
;
1979 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1984 /* Binding a user-created framebuffer object */
1985 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1986 if (newDrawFb
== &DummyFramebuffer
) {
1987 /* ID was reserved, but no real framebuffer object made yet */
1990 else if (!newDrawFb
&& !allow_user_names
) {
1991 /* All FBO IDs must be Gen'd */
1992 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1997 /* create new framebuffer object */
1998 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2000 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2003 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2005 newReadFb
= newDrawFb
;
2008 /* Binding the window system framebuffer (which was originally set
2009 * with MakeCurrent).
2011 newDrawFb
= ctx
->WinSysDrawBuffer
;
2012 newReadFb
= ctx
->WinSysReadBuffer
;
2016 ASSERT(newDrawFb
!= &DummyFramebuffer
);
2018 /* save pointers to current/old framebuffers */
2019 oldDrawFb
= ctx
->DrawBuffer
;
2020 oldReadFb
= ctx
->ReadBuffer
;
2022 /* check if really changing bindings */
2023 if (oldDrawFb
== newDrawFb
)
2024 bindDrawBuf
= GL_FALSE
;
2025 if (oldReadFb
== newReadFb
)
2026 bindReadBuf
= GL_FALSE
;
2029 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2031 * We also check if we're beginning and/or ending render-to-texture.
2032 * When a framebuffer with texture attachments is unbound, call
2033 * ctx->Driver.FinishRenderTexture().
2034 * When a framebuffer with texture attachments is bound, call
2035 * ctx->Driver.RenderTexture().
2037 * Note that if the ReadBuffer has texture attachments we don't consider
2038 * that a render-to-texture case.
2041 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2043 /* check if old readbuffer was render-to-texture */
2044 check_end_texture_render(ctx
, oldReadFb
);
2046 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2050 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2052 /* check if old framebuffer had any texture attachments */
2054 check_end_texture_render(ctx
, oldDrawFb
);
2056 /* check if newly bound framebuffer has any texture attachments */
2057 check_begin_texture_render(ctx
, newDrawFb
);
2059 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2062 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2063 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
2068 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2070 GET_CURRENT_CONTEXT(ctx
);
2072 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2073 * point, but they allow the use of user-generated names.
2075 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2079 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2081 /* This function should not be in the dispatch table for core profile /
2082 * OpenGL 3.1, so execution should never get here in those cases -- no
2083 * need for an explicit test.
2085 bind_framebuffer(target
, framebuffer
, true);
2089 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2092 GET_CURRENT_CONTEXT(ctx
);
2094 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2096 for (i
= 0; i
< n
; i
++) {
2097 if (framebuffers
[i
] > 0) {
2098 struct gl_framebuffer
*fb
;
2099 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2101 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2103 /* check if deleting currently bound framebuffer object */
2104 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
2105 /* separate draw/read binding points */
2106 if (fb
== ctx
->DrawBuffer
) {
2108 ASSERT(fb
->RefCount
>= 2);
2109 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT
, 0);
2111 if (fb
== ctx
->ReadBuffer
) {
2113 ASSERT(fb
->RefCount
>= 2);
2114 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER_EXT
, 0);
2118 /* only one binding point for read/draw buffers */
2119 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
2121 ASSERT(fb
->RefCount
>= 2);
2122 _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT
, 0);
2126 /* remove from hash table immediately, to free the ID */
2127 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2129 if (fb
!= &DummyFramebuffer
) {
2130 /* But the object will not be freed until it's no longer
2131 * bound in any context.
2133 _mesa_reference_framebuffer(&fb
, NULL
);
2142 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2144 GET_CURRENT_CONTEXT(ctx
);
2149 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
2156 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2158 for (i
= 0; i
< n
; i
++) {
2159 GLuint name
= first
+ i
;
2160 framebuffers
[i
] = name
;
2161 /* insert dummy placeholder into hash table */
2162 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
2163 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
2164 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
2171 _mesa_CheckFramebufferStatus(GLenum target
)
2173 struct gl_framebuffer
*buffer
;
2174 GET_CURRENT_CONTEXT(ctx
);
2176 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2178 if (MESA_VERBOSE
& VERBOSE_API
)
2179 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2180 _mesa_lookup_enum_by_nr(target
));
2182 buffer
= get_framebuffer_target(ctx
, target
);
2184 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
2188 if (_mesa_is_winsys_fbo(buffer
)) {
2189 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2190 if (buffer
!= &IncompleteFramebuffer
) {
2191 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2193 return GL_FRAMEBUFFER_UNDEFINED
;
2197 /* No need to flush here */
2199 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2200 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2203 return buffer
->_Status
;
2208 * Replicate the src attachment point. Used by framebuffer_texture() when
2209 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2210 * GL_STENCIL_ATTACHMENT.
2213 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2214 gl_buffer_index dst
,
2215 gl_buffer_index src
)
2217 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2218 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2220 assert(src_att
->Texture
!= NULL
);
2221 assert(src_att
->Renderbuffer
!= NULL
);
2223 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2224 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2225 dst_att
->Type
= src_att
->Type
;
2226 dst_att
->Complete
= src_att
->Complete
;
2227 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2228 dst_att
->Zoffset
= src_att
->Zoffset
;
2233 * Common code called by glFramebufferTexture1D/2D/3DEXT() and
2234 * glFramebufferTextureLayerEXT().
2235 * Note: glFramebufferTextureLayerEXT() has no textarget parameter so we'll
2236 * get textarget=0 in that case.
2239 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
2240 GLenum attachment
, GLenum textarget
, GLuint texture
,
2241 GLint level
, GLint zoffset
, GLboolean layered
)
2243 struct gl_renderbuffer_attachment
*att
;
2244 struct gl_texture_object
*texObj
= NULL
;
2245 struct gl_framebuffer
*fb
;
2246 GLenum maxLevelsTarget
;
2248 fb
= get_framebuffer_target(ctx
, target
);
2250 _mesa_error(ctx
, GL_INVALID_ENUM
,
2251 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
2255 /* check framebuffer binding */
2256 if (_mesa_is_winsys_fbo(fb
)) {
2257 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2258 "glFramebufferTexture%sEXT", caller
);
2262 /* The textarget, level, and zoffset parameters are only validated if
2263 * texture is non-zero.
2266 GLboolean err
= GL_TRUE
;
2268 texObj
= _mesa_lookup_texture(ctx
, texture
);
2269 if (texObj
!= NULL
) {
2270 if (textarget
== 0) {
2271 /* If textarget == 0 it means we're being called by
2272 * glFramebufferTextureLayer() and textarget is not used.
2273 * The only legal texture types for that function are 3D and
2274 * 1D/2D arrays textures.
2276 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
2277 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
2278 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
) &&
2279 (texObj
->Target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) &&
2280 (texObj
->Target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
);
2283 /* Make sure textarget is consistent with the texture's type */
2284 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
2285 ? !_mesa_is_cube_face(textarget
)
2286 : (texObj
->Target
!= textarget
);
2290 /* can't render to a non-existant texture */
2291 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2292 "glFramebufferTexture%sEXT(non existant texture)",
2298 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2299 "glFramebufferTexture%sEXT(texture target mismatch)",
2304 if (texObj
->Target
== GL_TEXTURE_3D
) {
2305 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
2306 if (zoffset
< 0 || zoffset
>= maxSize
) {
2307 _mesa_error(ctx
, GL_INVALID_VALUE
,
2308 "glFramebufferTexture%sEXT(zoffset)", caller
);
2312 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
2313 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) ||
2314 (texObj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
2315 (texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
2317 zoffset
>= (GLint
) ctx
->Const
.MaxArrayTextureLayers
) {
2318 _mesa_error(ctx
, GL_INVALID_VALUE
,
2319 "glFramebufferTexture%sEXT(layer)", caller
);
2324 maxLevelsTarget
= textarget
? textarget
: texObj
->Target
;
2326 (level
>= _mesa_max_texture_levels(ctx
, maxLevelsTarget
))) {
2327 _mesa_error(ctx
, GL_INVALID_VALUE
,
2328 "glFramebufferTexture%sEXT(level)", caller
);
2333 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2335 _mesa_error(ctx
, GL_INVALID_ENUM
,
2336 "glFramebufferTexture%sEXT(attachment)", caller
);
2340 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2342 _glthread_LOCK_MUTEX(fb
->Mutex
);
2344 if (attachment
== GL_DEPTH_ATTACHMENT
&&
2345 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
2346 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
2347 _mesa_tex_target_to_face(textarget
) ==
2348 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
2349 zoffset
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
2350 /* The texture object is already attached to the stencil attachment
2351 * point. Don't create a new renderbuffer; just reuse the stencil
2352 * attachment's. This is required to prevent a GL error in
2353 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
2355 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
2357 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
2358 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
2359 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
2360 _mesa_tex_target_to_face(textarget
) ==
2361 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
2362 zoffset
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
2363 /* As above, but with depth and stencil transposed. */
2364 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
2367 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
2368 level
, zoffset
, layered
);
2369 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2370 /* Above we created a new renderbuffer and attached it to the
2371 * depth attachment point. Now attach it to the stencil attachment
2374 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
2375 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
2380 /* Set the render-to-texture flag. We'll check this flag in
2381 * glTexImage() and friends to determine if we need to revalidate
2382 * any FBOs that might be rendering into this texture.
2383 * This flag never gets cleared since it's non-trivial to determine
2384 * when all FBOs might be done rendering to this texture. That's OK
2385 * though since it's uncommon to render to a texture then repeatedly
2386 * call glTexImage() to change images in the texture.
2388 texObj
->_RenderToTexture
= GL_TRUE
;
2391 _mesa_remove_attachment(ctx
, att
);
2392 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2393 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
2394 _mesa_remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
2398 invalidate_framebuffer(fb
);
2400 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
2406 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
2407 GLenum textarget
, GLuint texture
, GLint level
)
2409 GET_CURRENT_CONTEXT(ctx
);
2414 switch (textarget
) {
2418 case GL_TEXTURE_1D_ARRAY
:
2419 error
= !ctx
->Extensions
.EXT_texture_array
;
2426 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2427 "glFramebufferTexture1DEXT(textarget=%s)",
2428 _mesa_lookup_enum_by_nr(textarget
));
2433 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
2434 level
, 0, GL_FALSE
);
2439 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
2440 GLenum textarget
, GLuint texture
, GLint level
)
2442 GET_CURRENT_CONTEXT(ctx
);
2447 switch (textarget
) {
2451 case GL_TEXTURE_RECTANGLE
:
2452 error
= _mesa_is_gles(ctx
)
2453 || !ctx
->Extensions
.NV_texture_rectangle
;
2455 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2456 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2457 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2458 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2459 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2460 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2461 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
2463 case GL_TEXTURE_2D_ARRAY
:
2464 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
2465 || !ctx
->Extensions
.EXT_texture_array
;
2467 case GL_TEXTURE_2D_MULTISAMPLE
:
2468 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2469 error
= _mesa_is_gles(ctx
)
2470 || !ctx
->Extensions
.ARB_texture_multisample
;
2477 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2478 "glFramebufferTexture2DEXT(textarget=%s)",
2479 _mesa_lookup_enum_by_nr(textarget
));
2484 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
2485 level
, 0, GL_FALSE
);
2490 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
2491 GLenum textarget
, GLuint texture
,
2492 GLint level
, GLint zoffset
)
2494 GET_CURRENT_CONTEXT(ctx
);
2496 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
2497 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2498 "glFramebufferTexture3DEXT(textarget)");
2502 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
2503 level
, zoffset
, GL_FALSE
);
2508 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
2509 GLuint texture
, GLint level
, GLint layer
)
2511 GET_CURRENT_CONTEXT(ctx
);
2513 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2514 level
, layer
, GL_FALSE
);
2519 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
2520 GLuint texture
, GLint level
)
2522 GET_CURRENT_CONTEXT(ctx
);
2524 if (_mesa_has_geometry_shaders(ctx
)) {
2525 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2528 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2529 "unsupported function (glFramebufferTexture) called");
2535 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
2536 GLenum renderbufferTarget
,
2537 GLuint renderbuffer
)
2539 struct gl_renderbuffer_attachment
*att
;
2540 struct gl_framebuffer
*fb
;
2541 struct gl_renderbuffer
*rb
;
2542 GET_CURRENT_CONTEXT(ctx
);
2544 fb
= get_framebuffer_target(ctx
, target
);
2546 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFramebufferRenderbufferEXT(target)");
2550 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
2551 _mesa_error(ctx
, GL_INVALID_ENUM
,
2552 "glFramebufferRenderbufferEXT(renderbufferTarget)");
2556 if (_mesa_is_winsys_fbo(fb
)) {
2557 /* Can't attach new renderbuffers to a window system framebuffer */
2558 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
2562 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2564 _mesa_error(ctx
, GL_INVALID_ENUM
,
2565 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2566 _mesa_lookup_enum_by_nr(attachment
));
2571 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2573 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2574 "glFramebufferRenderbufferEXT(non-existant"
2575 " renderbuffer %u)", renderbuffer
);
2578 else if (rb
== &DummyRenderbuffer
) {
2579 /* This is what NVIDIA does */
2580 _mesa_error(ctx
, GL_INVALID_VALUE
,
2581 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2587 /* remove renderbuffer attachment */
2591 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
2592 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
2593 /* make sure the renderbuffer is a depth/stencil format */
2594 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2595 if (baseFormat
!= GL_DEPTH_STENCIL
) {
2596 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2597 "glFramebufferRenderbufferEXT(renderbuffer"
2598 " is not DEPTH_STENCIL format)");
2604 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2606 assert(ctx
->Driver
.FramebufferRenderbuffer
);
2607 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
2609 /* Some subsequent GL commands may depend on the framebuffer's visual
2610 * after the binding is updated. Update visual info now.
2612 _mesa_update_framebuffer_visual(ctx
, fb
);
2617 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
2618 GLenum pname
, GLint
*params
)
2620 const struct gl_renderbuffer_attachment
*att
;
2621 struct gl_framebuffer
*buffer
;
2623 GET_CURRENT_CONTEXT(ctx
);
2625 /* The error differs in GL and GLES. */
2626 err
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
2628 buffer
= get_framebuffer_target(ctx
, target
);
2630 _mesa_error(ctx
, GL_INVALID_ENUM
,
2631 "glGetFramebufferAttachmentParameterivEXT(target)");
2635 if (_mesa_is_winsys_fbo(buffer
)) {
2636 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
2639 * "If the framebuffer currently bound to target is zero, then
2640 * INVALID_OPERATION is generated."
2642 * The EXT_framebuffer_object spec has the same wording, and the
2643 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
2646 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2647 && !_mesa_is_gles3(ctx
)) {
2648 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2649 "glGetFramebufferAttachmentParameteriv(bound FBO = 0)");
2653 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
2654 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
2655 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2656 "glGetFramebufferAttachmentParameteriv(attachment)");
2659 /* the default / window-system FBO */
2660 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2663 /* user-created framebuffer FBO */
2664 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2668 _mesa_error(ctx
, GL_INVALID_ENUM
,
2669 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2673 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2674 /* the depth and stencil attachments must point to the same buffer */
2675 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2676 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2677 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2678 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2679 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2680 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2681 " attachments differ)");
2686 /* No need to flush here */
2689 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2690 *params
= _mesa_is_winsys_fbo(buffer
)
2691 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2693 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2694 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2695 *params
= att
->Renderbuffer
->Name
;
2697 else if (att
->Type
== GL_TEXTURE
) {
2698 *params
= att
->Texture
->Name
;
2701 assert(att
->Type
== GL_NONE
);
2702 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
2705 goto invalid_pname_enum
;
2709 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2710 if (att
->Type
== GL_TEXTURE
) {
2711 *params
= att
->TextureLevel
;
2713 else if (att
->Type
== GL_NONE
) {
2714 _mesa_error(ctx
, err
,
2715 "glGetFramebufferAttachmentParameterivEXT(pname)");
2718 goto invalid_pname_enum
;
2721 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2722 if (att
->Type
== GL_TEXTURE
) {
2723 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2724 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2730 else if (att
->Type
== GL_NONE
) {
2731 _mesa_error(ctx
, err
,
2732 "glGetFramebufferAttachmentParameterivEXT(pname)");
2735 goto invalid_pname_enum
;
2738 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2739 if (ctx
->API
== API_OPENGLES
) {
2740 goto invalid_pname_enum
;
2741 } else if (att
->Type
== GL_NONE
) {
2742 _mesa_error(ctx
, err
,
2743 "glGetFramebufferAttachmentParameterivEXT(pname)");
2744 } else if (att
->Type
== GL_TEXTURE
) {
2745 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2746 *params
= att
->Zoffset
;
2753 goto invalid_pname_enum
;
2756 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2757 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2758 && !_mesa_is_gles3(ctx
)) {
2759 goto invalid_pname_enum
;
2761 else if (att
->Type
== GL_NONE
) {
2762 _mesa_error(ctx
, err
,
2763 "glGetFramebufferAttachmentParameterivEXT(pname)");
2766 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
2767 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2770 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2771 * if the sRGB conversion is unsupported. */
2772 *params
= GL_LINEAR
;
2776 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2777 if ((ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_framebuffer_object
)
2778 && ctx
->API
!= API_OPENGL_CORE
2779 && !_mesa_is_gles3(ctx
)) {
2780 goto invalid_pname_enum
;
2782 else if (att
->Type
== GL_NONE
) {
2783 _mesa_error(ctx
, err
,
2784 "glGetFramebufferAttachmentParameterivEXT(pname)");
2787 gl_format format
= att
->Renderbuffer
->Format
;
2789 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
2792 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
2793 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
2794 * generate an INVALID_OPERATION error.
2796 if (_mesa_is_gles3(ctx
) && attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2797 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2798 "glGetFramebufferAttachmentParameteriv(cannot query "
2799 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
2800 "GL_DEPTH_STENCIL_ATTACHMENT");
2804 if (format
== MESA_FORMAT_S8
) {
2808 else if (format
== MESA_FORMAT_Z32_FLOAT_X24S8
) {
2809 /* depends on the attachment parameter */
2810 if (attachment
== GL_STENCIL_ATTACHMENT
) {
2818 *params
= _mesa_get_format_datatype(format
);
2822 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2823 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2824 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2825 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2826 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2827 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2828 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2829 && !_mesa_is_gles3(ctx
)) {
2830 goto invalid_pname_enum
;
2832 else if (att
->Type
== GL_NONE
) {
2833 _mesa_error(ctx
, err
,
2834 "glGetFramebufferAttachmentParameterivEXT(pname)");
2836 else if (att
->Texture
) {
2837 const struct gl_texture_image
*texImage
=
2838 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2841 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2842 texImage
->TexFormat
);
2848 else if (att
->Renderbuffer
) {
2849 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2850 att
->Renderbuffer
->Format
);
2853 _mesa_problem(ctx
, "glGetFramebufferAttachmentParameterivEXT:"
2854 " invalid FBO attachment structure");
2858 goto invalid_pname_enum
;
2864 _mesa_error(ctx
, GL_INVALID_ENUM
,
2865 "glGetFramebufferAttachmentParameteriv(pname)");
2871 _mesa_GenerateMipmap(GLenum target
)
2873 struct gl_texture_image
*srcImage
;
2874 struct gl_texture_object
*texObj
;
2877 GET_CURRENT_CONTEXT(ctx
);
2879 FLUSH_VERTICES(ctx
, 0);
2883 error
= _mesa_is_gles(ctx
);
2889 error
= ctx
->API
== API_OPENGLES
;
2891 case GL_TEXTURE_CUBE_MAP
:
2892 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
2894 case GL_TEXTURE_1D_ARRAY
:
2895 error
= _mesa_is_gles(ctx
) || !ctx
->Extensions
.EXT_texture_array
;
2897 case GL_TEXTURE_2D_ARRAY
:
2898 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
2899 || !ctx
->Extensions
.EXT_texture_array
;
2906 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target=%s)",
2907 _mesa_lookup_enum_by_nr(target
));
2911 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2913 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2918 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
2919 !_mesa_cube_complete(texObj
)) {
2920 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2921 "glGenerateMipmap(incomplete cube map)");
2925 _mesa_lock_texture(ctx
, texObj
);
2927 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, texObj
->BaseLevel
);
2929 _mesa_unlock_texture(ctx
, texObj
);
2930 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2931 "glGenerateMipmap(zero size base image)");
2935 if (_mesa_is_enum_format_integer(srcImage
->InternalFormat
) ||
2936 _mesa_is_depthstencil_format(srcImage
->InternalFormat
) ||
2937 _mesa_is_stencil_format(srcImage
->InternalFormat
)) {
2938 _mesa_unlock_texture(ctx
, texObj
);
2939 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2940 "glGenerateMipmap(invalid internal format)");
2944 if (target
== GL_TEXTURE_CUBE_MAP
) {
2946 for (face
= 0; face
< 6; face
++)
2947 ctx
->Driver
.GenerateMipmap(ctx
,
2948 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2952 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2954 _mesa_unlock_texture(ctx
, texObj
);
2958 static const struct gl_renderbuffer_attachment
*
2959 find_attachment(const struct gl_framebuffer
*fb
,
2960 const struct gl_renderbuffer
*rb
)
2963 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2964 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2965 return &fb
->Attachment
[i
];
2972 * Helper function for checking if the datatypes of color buffers are
2973 * compatible for glBlitFramebuffer. From the 3.1 spec, page 198:
2975 * "GL_INVALID_OPERATION is generated if mask contains GL_COLOR_BUFFER_BIT
2976 * and any of the following conditions hold:
2977 * - The read buffer contains fixed-point or floating-point values and any
2978 * draw buffer contains neither fixed-point nor floating-point values.
2979 * - The read buffer contains unsigned integer values and any draw buffer
2980 * does not contain unsigned integer values.
2981 * - The read buffer contains signed integer values and any draw buffer
2982 * does not contain signed integer values."
2985 compatible_color_datatypes(gl_format srcFormat
, gl_format dstFormat
)
2987 GLenum srcType
= _mesa_get_format_datatype(srcFormat
);
2988 GLenum dstType
= _mesa_get_format_datatype(dstFormat
);
2990 if (srcType
!= GL_INT
&& srcType
!= GL_UNSIGNED_INT
) {
2991 assert(srcType
== GL_UNSIGNED_NORMALIZED
||
2992 srcType
== GL_SIGNED_NORMALIZED
||
2993 srcType
== GL_FLOAT
);
2994 /* Boil any of those types down to GL_FLOAT */
2998 if (dstType
!= GL_INT
&& dstType
!= GL_UNSIGNED_INT
) {
2999 assert(dstType
== GL_UNSIGNED_NORMALIZED
||
3000 dstType
== GL_SIGNED_NORMALIZED
||
3001 dstType
== GL_FLOAT
);
3002 /* Boil any of those types down to GL_FLOAT */
3006 return srcType
== dstType
;
3011 compatible_resolve_formats(const struct gl_renderbuffer
*readRb
,
3012 const struct gl_renderbuffer
*drawRb
)
3014 GLenum readFormat
, drawFormat
;
3016 /* The simple case where we know the backing Mesa formats are the same.
3018 if (_mesa_get_srgb_format_linear(readRb
->Format
) ==
3019 _mesa_get_srgb_format_linear(drawRb
->Format
)) {
3023 /* The Mesa formats are different, so we must check whether the internal
3024 * formats are compatible.
3026 * Under some circumstances, the user may request e.g. two GL_RGBA8
3027 * textures and get two entirely different Mesa formats like RGBA8888 and
3028 * ARGB8888. Drivers behaving like that should be able to cope with
3029 * non-matching formats by themselves, because it's not the user's fault.
3031 * Blits between linear and sRGB formats are also allowed.
3033 readFormat
= _mesa_get_nongeneric_internalformat(readRb
->InternalFormat
);
3034 drawFormat
= _mesa_get_nongeneric_internalformat(drawRb
->InternalFormat
);
3035 readFormat
= _mesa_get_linear_internalformat(readFormat
);
3036 drawFormat
= _mesa_get_linear_internalformat(drawFormat
);
3038 if (readFormat
== drawFormat
) {
3046 is_valid_blit_filter(const struct gl_context
*ctx
, GLenum filter
)
3052 case GL_SCALED_RESOLVE_FASTEST_EXT
:
3053 case GL_SCALED_RESOLVE_NICEST_EXT
:
3054 return ctx
->Extensions
.EXT_framebuffer_multisample_blit_scaled
;
3061 * Blit rectangular region, optionally from one framebuffer to another.
3063 * Note, if the src buffer is multisampled and the dest is not, this is
3064 * when the samples must be resolved to a single color.
3067 _mesa_BlitFramebuffer(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
3068 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
3069 GLbitfield mask
, GLenum filter
)
3071 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
3072 GL_DEPTH_BUFFER_BIT
|
3073 GL_STENCIL_BUFFER_BIT
);
3074 const struct gl_framebuffer
*readFb
, *drawFb
;
3075 GET_CURRENT_CONTEXT(ctx
);
3077 FLUSH_VERTICES(ctx
, 0);
3079 if (MESA_VERBOSE
& VERBOSE_API
)
3081 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
3082 srcX0
, srcY0
, srcX1
, srcY1
,
3083 dstX0
, dstY0
, dstX1
, dstY1
,
3084 mask
, _mesa_lookup_enum_by_nr(filter
));
3086 if (ctx
->NewState
) {
3087 _mesa_update_state(ctx
);
3090 readFb
= ctx
->ReadBuffer
;
3091 drawFb
= ctx
->DrawBuffer
;
3093 if (!readFb
|| !drawFb
) {
3094 /* This will normally never happen but someday we may want to
3095 * support MakeCurrent() with no drawables.
3100 /* check for complete framebuffers */
3101 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
3102 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
3103 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
3104 "glBlitFramebufferEXT(incomplete draw/read buffers)");
3108 if (!is_valid_blit_filter(ctx
, filter
)) {
3109 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(%s)",
3110 _mesa_lookup_enum_by_nr(filter
));
3114 if ((filter
== GL_SCALED_RESOLVE_FASTEST_EXT
||
3115 filter
== GL_SCALED_RESOLVE_NICEST_EXT
) &&
3116 (readFb
->Visual
.samples
== 0 || drawFb
->Visual
.samples
> 0)) {
3117 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT(%s)",
3118 _mesa_lookup_enum_by_nr(filter
));
3122 if (mask
& ~legalMaskBits
) {
3123 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
3127 /* depth/stencil must be blitted with nearest filtering */
3128 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
3129 && filter
!= GL_NEAREST
) {
3130 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3131 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
3135 /* get color read/draw renderbuffers */
3136 if (mask
& GL_COLOR_BUFFER_BIT
) {
3137 const GLuint numColorDrawBuffers
= ctx
->DrawBuffer
->_NumColorDrawBuffers
;
3138 const struct gl_renderbuffer
*colorReadRb
= readFb
->_ColorReadBuffer
;
3139 const struct gl_renderbuffer
*colorDrawRb
= NULL
;
3142 /* From the EXT_framebuffer_object spec:
3144 * "If a buffer is specified in <mask> and does not exist in both
3145 * the read and draw framebuffers, the corresponding bit is silently
3148 if (!colorReadRb
|| numColorDrawBuffers
== 0) {
3149 mask
&= ~GL_COLOR_BUFFER_BIT
;
3152 for (i
= 0; i
< numColorDrawBuffers
; i
++) {
3153 colorDrawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
3157 /* Page 193 (page 205 of the PDF) in section 4.3.2 of the OpenGL
3158 * ES 3.0.1 spec says:
3160 * "If the source and destination buffers are identical, an
3161 * INVALID_OPERATION error is generated. Different mipmap
3162 * levels of a texture, different layers of a three-
3163 * dimensional texture or two-dimensional array texture, and
3164 * different faces of a cube map texture do not constitute
3165 * identical buffers."
3167 if (_mesa_is_gles3(ctx
) && (colorDrawRb
== colorReadRb
)) {
3168 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3169 "glBlitFramebuffer(source and destination color "
3170 "buffer cannot be the same)");
3174 if (!compatible_color_datatypes(colorReadRb
->Format
,
3175 colorDrawRb
->Format
)) {
3176 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3177 "glBlitFramebufferEXT(color buffer datatypes mismatch)");
3180 /* extra checks for multisample copies... */
3181 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
3182 /* color formats must match */
3183 if (!compatible_resolve_formats(colorReadRb
, colorDrawRb
)) {
3184 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3185 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
3190 if (filter
!= GL_NEAREST
) {
3191 /* From EXT_framebuffer_multisample_blit_scaled specification:
3192 * "Calling BlitFramebuffer will result in an INVALID_OPERATION error
3193 * if filter is not NEAREST and read buffer contains integer data."
3195 GLenum type
= _mesa_get_format_datatype(colorReadRb
->Format
);
3196 if (type
== GL_INT
|| type
== GL_UNSIGNED_INT
) {
3197 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3198 "glBlitFramebufferEXT(integer color type)");
3205 if (mask
& GL_STENCIL_BUFFER_BIT
) {
3206 struct gl_renderbuffer
*readRb
=
3207 readFb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3208 struct gl_renderbuffer
*drawRb
=
3209 drawFb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3211 /* From the EXT_framebuffer_object spec:
3213 * "If a buffer is specified in <mask> and does not exist in both
3214 * the read and draw framebuffers, the corresponding bit is silently
3217 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
3218 mask
&= ~GL_STENCIL_BUFFER_BIT
;
3221 int read_z_bits
, draw_z_bits
;
3223 if (_mesa_is_gles3(ctx
) && (drawRb
== readRb
)) {
3224 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3225 "glBlitFramebuffer(source and destination stencil "
3226 "buffer cannot be the same)");
3230 if (_mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
3231 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
3232 /* There is no need to check the stencil datatype here, because
3233 * there is only one: GL_UNSIGNED_INT.
3235 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3236 "glBlitFramebuffer(stencil attachment format mismatch)");
3240 read_z_bits
= _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
);
3241 draw_z_bits
= _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
);
3243 /* If both buffers also have depth data, the depth formats must match
3244 * as well. If one doesn't have depth, it's not blitted, so we should
3245 * ignore the depth format check.
3247 if (read_z_bits
> 0 && draw_z_bits
> 0 &&
3248 (read_z_bits
!= draw_z_bits
||
3249 _mesa_get_format_datatype(readRb
->Format
) !=
3250 _mesa_get_format_datatype(drawRb
->Format
))) {
3252 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebuffer"
3253 "(stencil attachment depth format mismatch)");
3259 if (mask
& GL_DEPTH_BUFFER_BIT
) {
3260 struct gl_renderbuffer
*readRb
=
3261 readFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3262 struct gl_renderbuffer
*drawRb
=
3263 drawFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3265 /* From the EXT_framebuffer_object spec:
3267 * "If a buffer is specified in <mask> and does not exist in both
3268 * the read and draw framebuffers, the corresponding bit is silently
3271 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
3272 mask
&= ~GL_DEPTH_BUFFER_BIT
;
3275 int read_s_bit
, draw_s_bit
;
3277 if (_mesa_is_gles3(ctx
) && (drawRb
== readRb
)) {
3278 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3279 "glBlitFramebuffer(source and destination depth "
3280 "buffer cannot be the same)");
3284 if ((_mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
3285 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) ||
3286 (_mesa_get_format_datatype(readRb
->Format
) !=
3287 _mesa_get_format_datatype(drawRb
->Format
))) {
3288 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3289 "glBlitFramebuffer(depth attachment format mismatch)");
3293 read_s_bit
= _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
);
3294 draw_s_bit
= _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
);
3296 /* If both buffers also have stencil data, the stencil formats must
3297 * match as well. If one doesn't have stencil, it's not blitted, so
3298 * we should ignore the stencil format check.
3300 if (read_s_bit
> 0 && draw_s_bit
> 0 && read_s_bit
!= draw_s_bit
) {
3301 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebuffer"
3302 "(depth attachment stencil bits mismatch)");
3309 if (_mesa_is_gles3(ctx
)) {
3310 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3313 * "If SAMPLE_BUFFERS for the draw framebuffer is greater than zero,
3314 * an INVALID_OPERATION error is generated."
3316 if (drawFb
->Visual
.samples
> 0) {
3317 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3318 "glBlitFramebuffer(destination samples must be 0)");
3322 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3325 * "If SAMPLE_BUFFERS for the read framebuffer is greater than zero,
3326 * no copy is performed and an INVALID_OPERATION error is generated
3327 * if the formats of the read and draw framebuffers are not
3328 * identical or if the source and destination rectangles are not
3329 * defined with the same (X0, Y0) and (X1, Y1) bounds."
3331 * The format check was made above because desktop OpenGL has the same
3334 if (readFb
->Visual
.samples
> 0
3335 && (srcX0
!= dstX0
|| srcY0
!= dstY0
3336 || srcX1
!= dstX1
|| srcY1
!= dstY1
)) {
3337 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3338 "glBlitFramebuffer(bad src/dst multisample region)");
3342 if (readFb
->Visual
.samples
> 0 &&
3343 drawFb
->Visual
.samples
> 0 &&
3344 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
3345 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3346 "glBlitFramebufferEXT(mismatched samples)");
3350 /* extra checks for multisample copies... */
3351 if ((readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) &&
3352 (filter
== GL_NEAREST
|| filter
== GL_LINEAR
)) {
3353 /* src and dest region sizes must be the same */
3354 if (abs(srcX1
- srcX0
) != abs(dstX1
- dstX0
) ||
3355 abs(srcY1
- srcY0
) != abs(dstY1
- dstY0
)) {
3356 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3357 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
3363 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
3364 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
3370 const struct gl_renderbuffer
*colorReadRb
= readFb
->_ColorReadBuffer
;
3371 const struct gl_renderbuffer
*colorDrawRb
= NULL
;
3374 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
3376 srcX0
, srcY0
, srcX1
, srcY1
,
3377 dstX0
, dstY0
, dstX1
, dstY1
,
3380 const struct gl_renderbuffer_attachment
*att
;
3382 att
= find_attachment(readFb
, colorReadRb
);
3383 printf(" Src FBO %u RB %u (%dx%d) ",
3384 readFb
->Name
, colorReadRb
->Name
,
3385 colorReadRb
->Width
, colorReadRb
->Height
);
3386 if (att
&& att
->Texture
) {
3387 printf("Tex %u tgt 0x%x level %u face %u",
3389 att
->Texture
->Target
,
3395 /* Print all active color render buffers */
3396 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
3397 colorDrawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
3401 att
= find_attachment(drawFb
, colorDrawRb
);
3402 printf(" Dst FBO %u RB %u (%dx%d) ",
3403 drawFb
->Name
, colorDrawRb
->Name
,
3404 colorDrawRb
->Width
, colorDrawRb
->Height
);
3405 if (att
&& att
->Texture
) {
3406 printf("Tex %u tgt 0x%x level %u face %u",
3408 att
->Texture
->Target
,
3418 (srcX1
- srcX0
) == 0 || (srcY1
- srcY0
) == 0 ||
3419 (dstX1
- dstX0
) == 0 || (dstY1
- dstY0
) == 0) {
3423 ASSERT(ctx
->Driver
.BlitFramebuffer
);
3424 ctx
->Driver
.BlitFramebuffer(ctx
,
3425 srcX0
, srcY0
, srcX1
, srcY1
,
3426 dstX0
, dstY0
, dstX1
, dstY1
,
3432 invalidate_framebuffer_storage(GLenum target
, GLsizei numAttachments
,
3433 const GLenum
*attachments
, GLint x
, GLint y
,
3434 GLsizei width
, GLsizei height
, const char *name
)
3437 struct gl_framebuffer
*fb
;
3438 GET_CURRENT_CONTEXT(ctx
);
3440 fb
= get_framebuffer_target(ctx
, target
);
3442 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", name
);
3446 if (numAttachments
< 0) {
3447 _mesa_error(ctx
, GL_INVALID_VALUE
,
3448 "%s(numAttachments < 0)", name
);
3452 /* The GL_ARB_invalidate_subdata spec says:
3454 * "If an attachment is specified that does not exist in the
3455 * framebuffer bound to <target>, it is ignored."
3459 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
3460 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
3461 * INVALID_OPERATION is generated."
3463 * No mention is made of GL_AUXi being out of range. Therefore, we allow
3464 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
3465 * set of retrictions).
3467 for (i
= 0; i
< numAttachments
; i
++) {
3468 if (_mesa_is_winsys_fbo(fb
)) {
3469 switch (attachments
[i
]) {
3475 /* Accumulation buffers and auxilary buffers were removed in
3476 * OpenGL 3.1, and they never existed in OpenGL ES.
3478 if (ctx
->API
!= API_OPENGL_COMPAT
)
3488 case GL_FRONT_RIGHT
:
3489 if (!_mesa_is_desktop_gl(ctx
))
3496 switch (attachments
[i
]) {
3497 case GL_DEPTH_ATTACHMENT
:
3498 case GL_STENCIL_ATTACHMENT
:
3500 case GL_COLOR_ATTACHMENT0
:
3501 case GL_COLOR_ATTACHMENT1
:
3502 case GL_COLOR_ATTACHMENT2
:
3503 case GL_COLOR_ATTACHMENT3
:
3504 case GL_COLOR_ATTACHMENT4
:
3505 case GL_COLOR_ATTACHMENT5
:
3506 case GL_COLOR_ATTACHMENT6
:
3507 case GL_COLOR_ATTACHMENT7
:
3508 case GL_COLOR_ATTACHMENT8
:
3509 case GL_COLOR_ATTACHMENT9
:
3510 case GL_COLOR_ATTACHMENT10
:
3511 case GL_COLOR_ATTACHMENT11
:
3512 case GL_COLOR_ATTACHMENT12
:
3513 case GL_COLOR_ATTACHMENT13
:
3514 case GL_COLOR_ATTACHMENT14
:
3515 case GL_COLOR_ATTACHMENT15
: {
3516 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
3517 if (k
>= ctx
->Const
.MaxColorAttachments
) {
3518 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3519 "%s(attachment >= max. color attachments)", name
);
3529 /* We don't actually do anything for this yet. Just return after
3530 * validating the parameters and generating the required errors.
3535 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(attachment)", name
);
3540 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
3541 const GLenum
*attachments
, GLint x
, GLint y
,
3542 GLsizei width
, GLsizei height
)
3544 invalidate_framebuffer_storage(target
, numAttachments
, attachments
,
3545 x
, y
, width
, height
,
3546 "glInvalidateSubFramebuffer");
3550 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
3551 const GLenum
*attachments
)
3553 /* The GL_ARB_invalidate_subdata spec says:
3557 * void InvalidateFramebuffer(enum target,
3558 * sizei numAttachments,
3559 * const enum *attachments);
3561 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
3562 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
3563 * <MAX_VIEWPORT_DIMS[1]> respectively."
3565 invalidate_framebuffer_storage(target
, numAttachments
, attachments
,
3566 0, 0, MAX_VIEWPORT_WIDTH
, MAX_VIEWPORT_HEIGHT
,
3567 "glInvalidateFramebuffer");
3571 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
3572 const GLenum
*attachments
)
3574 struct gl_framebuffer
*fb
;
3577 GET_CURRENT_CONTEXT(ctx
);
3579 fb
= get_framebuffer_target(ctx
, target
);
3581 _mesa_error(ctx
, GL_INVALID_ENUM
,
3582 "glDiscardFramebufferEXT(target %s)",
3583 _mesa_lookup_enum_by_nr(target
));
3587 if (numAttachments
< 0) {
3588 _mesa_error(ctx
, GL_INVALID_VALUE
,
3589 "glDiscardFramebufferEXT(numAttachments < 0)");
3593 for (i
= 0; i
< numAttachments
; i
++) {
3594 switch (attachments
[i
]) {
3598 if (_mesa_is_user_fbo(fb
))
3601 case GL_COLOR_ATTACHMENT0
:
3602 case GL_DEPTH_ATTACHMENT
:
3603 case GL_STENCIL_ATTACHMENT
:
3604 if (_mesa_is_winsys_fbo(fb
))
3612 if (ctx
->Driver
.DiscardFramebuffer
)
3613 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
3618 _mesa_error(ctx
, GL_INVALID_ENUM
,
3619 "glDiscardFramebufferEXT(attachment %s)",
3620 _mesa_lookup_enum_by_nr(attachments
[i
]));