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
) || _mesa_is_desktop_gl(ctx
);
168 case GL_DRAW_FRAMEBUFFER
:
169 return have_fb_blit
? ctx
->DrawBuffer
: NULL
;
170 case GL_READ_FRAMEBUFFER
:
171 return have_fb_blit
? ctx
->ReadBuffer
: NULL
;
172 case GL_FRAMEBUFFER_EXT
:
173 return ctx
->DrawBuffer
;
181 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
182 * gl_renderbuffer_attachment object.
183 * This function is only used for user-created FB objects, not the
184 * default / window-system FB object.
185 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
186 * the depth buffer attachment point.
188 struct gl_renderbuffer_attachment
*
189 _mesa_get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
194 assert(_mesa_is_user_fbo(fb
));
196 switch (attachment
) {
197 case GL_COLOR_ATTACHMENT0_EXT
:
198 case GL_COLOR_ATTACHMENT1_EXT
:
199 case GL_COLOR_ATTACHMENT2_EXT
:
200 case GL_COLOR_ATTACHMENT3_EXT
:
201 case GL_COLOR_ATTACHMENT4_EXT
:
202 case GL_COLOR_ATTACHMENT5_EXT
:
203 case GL_COLOR_ATTACHMENT6_EXT
:
204 case GL_COLOR_ATTACHMENT7_EXT
:
205 case GL_COLOR_ATTACHMENT8_EXT
:
206 case GL_COLOR_ATTACHMENT9_EXT
:
207 case GL_COLOR_ATTACHMENT10_EXT
:
208 case GL_COLOR_ATTACHMENT11_EXT
:
209 case GL_COLOR_ATTACHMENT12_EXT
:
210 case GL_COLOR_ATTACHMENT13_EXT
:
211 case GL_COLOR_ATTACHMENT14_EXT
:
212 case GL_COLOR_ATTACHMENT15_EXT
:
213 /* Only OpenGL ES 1.x forbids color attachments other than
214 * GL_COLOR_ATTACHMENT0. For all other APIs the limit set by the
217 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
218 if (i
>= ctx
->Const
.MaxColorAttachments
219 || (i
> 0 && ctx
->API
== API_OPENGLES
)) {
222 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
223 case GL_DEPTH_STENCIL_ATTACHMENT
:
224 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
227 case GL_DEPTH_ATTACHMENT_EXT
:
228 return &fb
->Attachment
[BUFFER_DEPTH
];
229 case GL_STENCIL_ATTACHMENT_EXT
:
230 return &fb
->Attachment
[BUFFER_STENCIL
];
238 * As above, but only used for getting attachments of the default /
239 * window-system framebuffer (not user-created framebuffer objects).
241 static struct gl_renderbuffer_attachment
*
242 _mesa_get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
245 assert(_mesa_is_winsys_fbo(fb
));
247 if (_mesa_is_gles3(ctx
)) {
248 assert(attachment
== GL_BACK
||
249 attachment
== GL_DEPTH
||
250 attachment
== GL_STENCIL
);
251 switch (attachment
) {
253 /* Since there is no stereo rendering in ES 3.0, only return the
256 if (ctx
->DrawBuffer
->Visual
.doubleBufferMode
)
257 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
258 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
260 return &fb
->Attachment
[BUFFER_DEPTH
];
262 return &fb
->Attachment
[BUFFER_STENCIL
];
266 switch (attachment
) {
268 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
270 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
272 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
274 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
276 if (fb
->Visual
.numAuxBuffers
== 1) {
277 return &fb
->Attachment
[BUFFER_AUX0
];
281 /* Page 336 (page 352 of the PDF) of the OpenGL 3.0 spec says:
283 * "If the default framebuffer is bound to target, then attachment must
284 * be one of FRONT LEFT, FRONT RIGHT, BACK LEFT, BACK RIGHT, or AUXi,
285 * identifying a color buffer; DEPTH, identifying the depth buffer; or
286 * STENCIL, identifying the stencil buffer."
288 * Revision #34 of the ARB_framebuffer_object spec has essentially the same
289 * language. However, revision #33 of the ARB_framebuffer_object spec
292 * "If the default framebuffer is bound to <target>, then <attachment>
293 * must be one of FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT, AUXi,
294 * DEPTH_BUFFER, or STENCIL_BUFFER, identifying a color buffer, the
295 * depth buffer, or the stencil buffer, and <pname> may be
296 * FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE or
297 * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME."
299 * The enum values for DEPTH_BUFFER and STENCIL_BUFFER have been removed
300 * from glext.h, so shipping apps should not use those values.
302 * Note that neither EXT_framebuffer_object nor OES_framebuffer_object
303 * support queries of the window system FBO.
306 return &fb
->Attachment
[BUFFER_DEPTH
];
308 return &fb
->Attachment
[BUFFER_STENCIL
];
317 * Remove any texture or renderbuffer attached to the given attachment
318 * point. Update reference counts, etc.
321 _mesa_remove_attachment(struct gl_context
*ctx
,
322 struct gl_renderbuffer_attachment
*att
)
324 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
326 /* tell driver that we're done rendering to this texture. */
327 if (rb
&& rb
->NeedsFinishRenderTexture
)
328 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
330 if (att
->Type
== GL_TEXTURE
) {
331 ASSERT(att
->Texture
);
332 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
333 ASSERT(!att
->Texture
);
335 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
336 ASSERT(!att
->Texture
);
337 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
338 ASSERT(!att
->Renderbuffer
);
341 att
->Complete
= GL_TRUE
;
345 * Verify a couple error conditions that will lead to an incomplete FBO and
346 * may cause problems for the driver's RenderTexture path.
349 driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment
*att
)
351 const struct gl_texture_image
*const texImage
=
352 att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
354 if (texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
357 if ((texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
358 && att
->Zoffset
>= texImage
->Height
)
359 || (texImage
->TexObject
->Target
!= GL_TEXTURE_1D_ARRAY
360 && att
->Zoffset
>= texImage
->Depth
))
367 * Create a renderbuffer which will be set up by the driver to wrap the
368 * texture image slice.
370 * By using a gl_renderbuffer (like user-allocated renderbuffers), drivers get
371 * to share most of their framebuffer rendering code between winsys,
372 * renderbuffer, and texture attachments.
374 * The allocated renderbuffer uses a non-zero Name so that drivers can check
375 * it for determining vertical orientation, but we use ~0 to make it fairly
376 * unambiguous with actual user (non-texture) renderbuffers.
379 _mesa_update_texture_renderbuffer(struct gl_context
*ctx
,
380 struct gl_framebuffer
*fb
,
381 struct gl_renderbuffer_attachment
*att
)
383 struct gl_texture_image
*texImage
;
384 struct gl_renderbuffer
*rb
;
386 texImage
= att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
388 rb
= att
->Renderbuffer
;
390 rb
= ctx
->Driver
.NewRenderbuffer(ctx
, ~0);
392 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glFramebufferTexture()");
395 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
397 /* This can't get called on a texture renderbuffer, so set it to NULL
398 * for clarity compared to user renderbuffers.
400 rb
->AllocStorage
= NULL
;
402 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
->Depth
= texImage
->Depth2
;
414 rb
->NumSamples
= texImage
->NumSamples
;
415 rb
->TexImage
= texImage
;
417 if (driver_RenderTexture_is_safe(att
))
418 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
422 * Bind a texture object to an attachment point.
423 * The previous binding, if any, will be removed first.
426 _mesa_set_texture_attachment(struct gl_context
*ctx
,
427 struct gl_framebuffer
*fb
,
428 struct gl_renderbuffer_attachment
*att
,
429 struct gl_texture_object
*texObj
,
430 GLenum texTarget
, GLuint level
, GLuint zoffset
,
433 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
435 if (rb
&& rb
->NeedsFinishRenderTexture
)
436 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
438 if (att
->Texture
== texObj
) {
439 /* re-attaching same texture */
440 ASSERT(att
->Type
== GL_TEXTURE
);
444 _mesa_remove_attachment(ctx
, att
);
445 att
->Type
= GL_TEXTURE
;
446 assert(!att
->Texture
);
447 _mesa_reference_texobj(&att
->Texture
, texObj
);
449 invalidate_framebuffer(fb
);
451 /* always update these fields */
452 att
->TextureLevel
= level
;
453 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
454 att
->Zoffset
= zoffset
;
455 att
->Layered
= layered
;
456 att
->Complete
= GL_FALSE
;
458 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
463 * Bind a renderbuffer to an attachment point.
464 * The previous binding, if any, will be removed first.
467 _mesa_set_renderbuffer_attachment(struct gl_context
*ctx
,
468 struct gl_renderbuffer_attachment
*att
,
469 struct gl_renderbuffer
*rb
)
471 /* XXX check if re-doing same attachment, exit early */
472 _mesa_remove_attachment(ctx
, att
);
473 att
->Type
= GL_RENDERBUFFER_EXT
;
474 att
->Texture
= NULL
; /* just to be safe */
475 att
->Complete
= GL_FALSE
;
476 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
481 * Fallback for ctx->Driver.FramebufferRenderbuffer()
482 * Attach a renderbuffer object to a framebuffer object.
485 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
,
486 struct gl_framebuffer
*fb
,
487 GLenum attachment
, struct gl_renderbuffer
*rb
)
489 struct gl_renderbuffer_attachment
*att
;
491 _glthread_LOCK_MUTEX(fb
->Mutex
);
493 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
496 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
497 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
498 /* do stencil attachment here (depth already done above) */
499 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
501 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
503 rb
->AttachedAnytime
= GL_TRUE
;
506 _mesa_remove_attachment(ctx
, att
);
509 invalidate_framebuffer(fb
);
511 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
516 * Fallback for ctx->Driver.ValidateFramebuffer()
517 * Check if the renderbuffer's formats are supported by the software
519 * Drivers should probably override this.
522 _mesa_validate_framebuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
525 for (buf
= 0; buf
< BUFFER_COUNT
; buf
++) {
526 const struct gl_renderbuffer
*rb
= fb
->Attachment
[buf
].Renderbuffer
;
528 switch (rb
->_BaseFormat
) {
530 case GL_LUMINANCE_ALPHA
:
535 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
539 switch (rb
->Format
) {
540 /* XXX This list is likely incomplete. */
541 case MESA_FORMAT_R9G9B9E5_FLOAT
:
542 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
545 /* render buffer format is supported by software rendering */
554 * Return true if the framebuffer has a combined depth/stencil
555 * renderbuffer attached.
558 _mesa_has_depthstencil_combined(const struct gl_framebuffer
*fb
)
560 const struct gl_renderbuffer_attachment
*depth
=
561 &fb
->Attachment
[BUFFER_DEPTH
];
562 const struct gl_renderbuffer_attachment
*stencil
=
563 &fb
->Attachment
[BUFFER_STENCIL
];
565 if (depth
->Type
== stencil
->Type
) {
566 if (depth
->Type
== GL_RENDERBUFFER_EXT
&&
567 depth
->Renderbuffer
== stencil
->Renderbuffer
)
570 if (depth
->Type
== GL_TEXTURE
&&
571 depth
->Texture
== stencil
->Texture
)
583 att_incomplete(const char *msg
)
585 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
586 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
595 fbo_incomplete(struct gl_context
*ctx
, const char *msg
, int index
)
597 static GLuint msg_id
;
599 _mesa_gl_debug(ctx
, &msg_id
,
600 MESA_DEBUG_TYPE_OTHER
,
601 MESA_DEBUG_SEVERITY_MEDIUM
,
602 "FBO incomplete: %s [%d]\n", msg
, index
);
604 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_FBO
) {
605 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
611 * Is the given base format a legal format for a color renderbuffer?
614 _mesa_is_legal_color_format(const struct gl_context
*ctx
, GLenum baseFormat
)
616 switch (baseFormat
) {
621 case GL_LUMINANCE_ALPHA
:
624 return ctx
->API
== API_OPENGL_COMPAT
&&
625 ctx
->Extensions
.ARB_framebuffer_object
;
628 return ctx
->Extensions
.ARB_texture_rg
;
636 * Is the given base format a legal format for a color renderbuffer?
639 is_format_color_renderable(const struct gl_context
*ctx
, mesa_format format
, GLenum internalFormat
)
641 const GLenum baseFormat
=
642 _mesa_get_format_base_format(format
);
645 valid
= _mesa_is_legal_color_format(ctx
, baseFormat
);
646 if (!valid
|| _mesa_is_desktop_gl(ctx
)) {
650 /* Reject additional cases for GLES */
651 switch (internalFormat
) {
671 if (format
== MESA_FORMAT_B10G10R10A2_UNORM
&& internalFormat
!= GL_RGB10_A2
) {
680 * Is the given base format a legal format for a depth/stencil renderbuffer?
683 is_legal_depth_format(const struct gl_context
*ctx
, GLenum baseFormat
)
685 switch (baseFormat
) {
686 case GL_DEPTH_COMPONENT
:
687 case GL_DEPTH_STENCIL_EXT
:
696 * Test if an attachment point is complete and update its Complete field.
697 * \param format if GL_COLOR, this is a color attachment point,
698 * if GL_DEPTH, this is a depth component attachment point,
699 * if GL_STENCIL, this is a stencil component attachment point.
702 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
703 struct gl_renderbuffer_attachment
*att
)
705 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
707 /* assume complete */
708 att
->Complete
= GL_TRUE
;
710 /* Look for reasons why the attachment might be incomplete */
711 if (att
->Type
== GL_TEXTURE
) {
712 const struct gl_texture_object
*texObj
= att
->Texture
;
713 struct gl_texture_image
*texImage
;
717 att_incomplete("no texobj");
718 att
->Complete
= GL_FALSE
;
722 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
724 att_incomplete("no teximage");
725 att
->Complete
= GL_FALSE
;
728 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
729 att_incomplete("teximage width/height=0");
730 att
->Complete
= GL_FALSE
;
734 switch (texObj
->Target
) {
736 if (att
->Zoffset
>= texImage
->Depth
) {
737 att_incomplete("bad z offset");
738 att
->Complete
= GL_FALSE
;
742 case GL_TEXTURE_1D_ARRAY
:
743 if (att
->Zoffset
>= texImage
->Height
) {
744 att_incomplete("bad 1D-array layer");
745 att
->Complete
= GL_FALSE
;
749 case GL_TEXTURE_2D_ARRAY
:
750 if (att
->Zoffset
>= texImage
->Depth
) {
751 att_incomplete("bad 2D-array layer");
752 att
->Complete
= GL_FALSE
;
756 case GL_TEXTURE_CUBE_MAP_ARRAY
:
757 if (att
->Zoffset
>= texImage
->Depth
) {
758 att_incomplete("bad cube-array layer");
759 att
->Complete
= GL_FALSE
;
765 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
767 if (format
== GL_COLOR
) {
768 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
769 att_incomplete("bad format");
770 att
->Complete
= GL_FALSE
;
773 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
774 att_incomplete("compressed internalformat");
775 att
->Complete
= GL_FALSE
;
779 else if (format
== GL_DEPTH
) {
780 if (baseFormat
== GL_DEPTH_COMPONENT
) {
783 else if (ctx
->Extensions
.ARB_depth_texture
&&
784 baseFormat
== GL_DEPTH_STENCIL
) {
788 att
->Complete
= GL_FALSE
;
789 att_incomplete("bad depth format");
794 ASSERT(format
== GL_STENCIL
);
795 if (ctx
->Extensions
.ARB_depth_texture
&&
796 baseFormat
== GL_DEPTH_STENCIL
) {
800 /* no such thing as stencil-only textures */
801 att_incomplete("illegal stencil texture");
802 att
->Complete
= GL_FALSE
;
807 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
808 const GLenum baseFormat
=
809 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
811 ASSERT(att
->Renderbuffer
);
812 if (!att
->Renderbuffer
->InternalFormat
||
813 att
->Renderbuffer
->Width
< 1 ||
814 att
->Renderbuffer
->Height
< 1) {
815 att_incomplete("0x0 renderbuffer");
816 att
->Complete
= GL_FALSE
;
819 if (format
== GL_COLOR
) {
820 if (!_mesa_is_legal_color_format(ctx
, baseFormat
)) {
821 att_incomplete("bad renderbuffer color format");
822 att
->Complete
= GL_FALSE
;
826 else if (format
== GL_DEPTH
) {
827 if (baseFormat
== GL_DEPTH_COMPONENT
) {
830 else if (baseFormat
== GL_DEPTH_STENCIL
) {
834 att_incomplete("bad renderbuffer depth format");
835 att
->Complete
= GL_FALSE
;
840 assert(format
== GL_STENCIL
);
841 if (baseFormat
== GL_STENCIL_INDEX
||
842 baseFormat
== GL_DEPTH_STENCIL
) {
846 att
->Complete
= GL_FALSE
;
847 att_incomplete("bad renderbuffer stencil format");
853 ASSERT(att
->Type
== GL_NONE
);
861 * Test if the given framebuffer object is complete and update its
862 * Status field with the results.
863 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
864 * driver to make hardware-specific validation/completeness checks.
865 * Also update the framebuffer's Width and Height fields if the
866 * framebuffer is complete.
869 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
,
870 struct gl_framebuffer
*fb
)
873 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
874 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
875 GLint numSamples
= -1;
876 GLint fixedSampleLocations
= -1;
879 /* Covers max_layer_count, is_layered, and layer_tex_target */
880 bool layer_info_valid
= false;
881 GLuint max_layer_count
= 0, att_layer_count
;
882 bool is_layered
= false;
883 GLenum layer_tex_target
= 0;
885 assert(_mesa_is_user_fbo(fb
));
887 /* we're changing framebuffer fields here */
888 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
893 fb
->_AllColorBuffersFixedPoint
= GL_TRUE
;
894 fb
->_HasSNormOrFloatColorBuffer
= GL_FALSE
;
896 /* Start at -2 to more easily loop over all attachment points.
901 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
902 struct gl_renderbuffer_attachment
*att
;
904 mesa_format attFormat
;
905 GLenum att_tex_target
= GL_NONE
;
908 * XXX for ARB_fbo, only check color buffers that are named by
909 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
912 /* check for attachment completeness
915 att
= &fb
->Attachment
[BUFFER_DEPTH
];
916 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
917 if (!att
->Complete
) {
918 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
919 fbo_incomplete(ctx
, "depth attachment incomplete", -1);
924 att
= &fb
->Attachment
[BUFFER_STENCIL
];
925 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
926 if (!att
->Complete
) {
927 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
928 fbo_incomplete(ctx
, "stencil attachment incomplete", -1);
933 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
934 test_attachment_completeness(ctx
, GL_COLOR
, att
);
935 if (!att
->Complete
) {
936 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
937 fbo_incomplete(ctx
, "color attachment incomplete", i
);
942 /* get width, height, format of the renderbuffer/texture
944 if (att
->Type
== GL_TEXTURE
) {
945 const struct gl_texture_image
*texImg
= att
->Renderbuffer
->TexImage
;
946 att_tex_target
= att
->Texture
->Target
;
947 minWidth
= MIN2(minWidth
, texImg
->Width
);
948 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
949 minHeight
= MIN2(minHeight
, texImg
->Height
);
950 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
951 f
= texImg
->_BaseFormat
;
952 attFormat
= texImg
->TexFormat
;
955 if (!is_format_color_renderable(ctx
, attFormat
, texImg
->InternalFormat
) &&
956 !is_legal_depth_format(ctx
, f
)) {
957 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
958 fbo_incomplete(ctx
, "texture attachment incomplete", -1);
963 numSamples
= texImg
->NumSamples
;
964 else if (numSamples
!= texImg
->NumSamples
) {
965 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
966 fbo_incomplete(ctx
, "inconsistent sample count", -1);
970 if (fixedSampleLocations
< 0)
971 fixedSampleLocations
= texImg
->FixedSampleLocations
;
972 else if (fixedSampleLocations
!= texImg
->FixedSampleLocations
) {
973 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
974 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
978 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
979 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
980 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
981 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
982 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
983 f
= att
->Renderbuffer
->InternalFormat
;
984 attFormat
= att
->Renderbuffer
->Format
;
988 numSamples
= att
->Renderbuffer
->NumSamples
;
989 else if (numSamples
!= att
->Renderbuffer
->NumSamples
) {
990 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
991 fbo_incomplete(ctx
, "inconsistent sample count", -1);
995 /* RENDERBUFFER has fixedSampleLocations implicitly true */
996 if (fixedSampleLocations
< 0)
997 fixedSampleLocations
= GL_TRUE
;
998 else if (fixedSampleLocations
!= GL_TRUE
) {
999 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
1000 fbo_incomplete(ctx
, "inconsistent fixed sample locations", -1);
1005 assert(att
->Type
== GL_NONE
);
1009 /* check if integer color */
1010 fb
->_IntegerColor
= _mesa_is_format_integer_color(attFormat
);
1012 /* Update _AllColorBuffersFixedPoint and _HasSNormOrFloatColorBuffer. */
1014 GLenum type
= _mesa_get_format_datatype(attFormat
);
1016 fb
->_AllColorBuffersFixedPoint
=
1017 fb
->_AllColorBuffersFixedPoint
&&
1018 (type
== GL_UNSIGNED_NORMALIZED
|| type
== GL_SIGNED_NORMALIZED
);
1020 fb
->_HasSNormOrFloatColorBuffer
=
1021 fb
->_HasSNormOrFloatColorBuffer
||
1022 type
== GL_SIGNED_NORMALIZED
|| type
== GL_FLOAT
;
1025 /* Error-check width, height, format */
1026 if (numImages
== 1) {
1033 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1034 /* check that width, height, format are same */
1035 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
1036 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
1037 fbo_incomplete(ctx
, "width or height mismatch", -1);
1040 /* check that all color buffers are the same format */
1041 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
1042 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
1043 fbo_incomplete(ctx
, "format mismatch", -1);
1049 /* Check that the format is valid. (MESA_FORMAT_NONE means unsupported)
1051 if (att
->Type
== GL_RENDERBUFFER
&&
1052 att
->Renderbuffer
->Format
== MESA_FORMAT_NONE
) {
1053 fb
->_Status
= GL_FRAMEBUFFER_UNSUPPORTED
;
1054 fbo_incomplete(ctx
, "unsupported renderbuffer format", i
);
1058 /* Check that layered rendering is consistent. */
1060 if (att_tex_target
== GL_TEXTURE_CUBE_MAP
)
1061 att_layer_count
= 6;
1063 att_layer_count
= att
->Renderbuffer
->Depth
;
1065 att_layer_count
= 0;
1067 if (!layer_info_valid
) {
1068 is_layered
= att
->Layered
;
1069 max_layer_count
= att_layer_count
;
1070 layer_tex_target
= att_tex_target
;
1071 layer_info_valid
= true;
1072 } else if (max_layer_count
> 0 && layer_tex_target
!= att_tex_target
) {
1073 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1074 fbo_incomplete(ctx
, "layered framebuffer has mismatched targets", i
);
1076 } else if (is_layered
!= att
->Layered
) {
1077 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
;
1078 fbo_incomplete(ctx
, "framebuffer attachment layer mode is inconsistent", i
);
1080 } else if (att_layer_count
> max_layer_count
) {
1081 max_layer_count
= att_layer_count
;
1085 fb
->MaxNumLayers
= max_layer_count
;
1087 if (_mesa_is_desktop_gl(ctx
) && !ctx
->Extensions
.ARB_ES2_compatibility
) {
1088 /* Check that all DrawBuffers are present */
1089 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
1090 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
1091 const struct gl_renderbuffer_attachment
*att
1092 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
1094 if (att
->Type
== GL_NONE
) {
1095 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
1096 fbo_incomplete(ctx
, "missing drawbuffer", j
);
1102 /* Check that the ReadBuffer is present */
1103 if (fb
->ColorReadBuffer
!= GL_NONE
) {
1104 const struct gl_renderbuffer_attachment
*att
1105 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
1107 if (att
->Type
== GL_NONE
) {
1108 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
1109 fbo_incomplete(ctx
, "missing readbuffer", -1);
1115 if (numImages
== 0) {
1116 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
1117 fbo_incomplete(ctx
, "no attachments", -1);
1121 /* Provisionally set status = COMPLETE ... */
1122 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
1124 /* ... but the driver may say the FB is incomplete.
1125 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
1128 if (ctx
->Driver
.ValidateFramebuffer
) {
1129 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
1130 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1131 fbo_incomplete(ctx
, "driver marked FBO as incomplete", -1);
1135 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
1137 * Note that if ARB_framebuffer_object is supported and the attached
1138 * renderbuffers/textures are different sizes, the framebuffer
1139 * width/height will be set to the smallest width/height.
1141 fb
->Width
= minWidth
;
1142 fb
->Height
= minHeight
;
1144 /* finally, update the visual info for the framebuffer */
1145 _mesa_update_framebuffer_visual(ctx
, fb
);
1150 GLboolean GLAPIENTRY
1151 _mesa_IsRenderbuffer(GLuint renderbuffer
)
1153 GET_CURRENT_CONTEXT(ctx
);
1154 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1156 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1157 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
1165 bind_renderbuffer(GLenum target
, GLuint renderbuffer
, bool allow_user_names
)
1167 struct gl_renderbuffer
*newRb
;
1168 GET_CURRENT_CONTEXT(ctx
);
1170 if (target
!= GL_RENDERBUFFER_EXT
) {
1171 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
1175 /* No need to flush here since the render buffer binding has no
1176 * effect on rendering state.
1180 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1181 if (newRb
== &DummyRenderbuffer
) {
1182 /* ID was reserved, but no real renderbuffer object made yet */
1185 else if (!newRb
&& !allow_user_names
) {
1186 /* All RB IDs must be Gen'd */
1187 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
1192 /* create new renderbuffer object */
1193 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
1195 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
1198 ASSERT(newRb
->AllocStorage
);
1199 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
1200 newRb
->RefCount
= 1; /* referenced by hash table */
1207 ASSERT(newRb
!= &DummyRenderbuffer
);
1209 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
1213 _mesa_BindRenderbuffer(GLenum target
, GLuint renderbuffer
)
1215 GET_CURRENT_CONTEXT(ctx
);
1217 /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
1218 * entry point, but they allow the use of user-generated names.
1220 bind_renderbuffer(target
, renderbuffer
, _mesa_is_gles(ctx
));
1224 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
1226 /* This function should not be in the dispatch table for core profile /
1227 * OpenGL 3.1, so execution should never get here in those cases -- no
1228 * need for an explicit test.
1230 bind_renderbuffer(target
, renderbuffer
, true);
1235 * Remove the specified renderbuffer or texture from any attachment point in
1239 * \c true if the renderbuffer was detached from an attachment point. \c
1243 _mesa_detach_renderbuffer(struct gl_context
*ctx
,
1244 struct gl_framebuffer
*fb
,
1248 bool progress
= false;
1250 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1251 if (fb
->Attachment
[i
].Texture
== att
1252 || fb
->Attachment
[i
].Renderbuffer
== att
) {
1253 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
1258 /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
1259 * Completeness," of the OpenGL 3.1 spec says:
1261 * "Performing any of the following actions may change whether the
1262 * framebuffer is considered complete or incomplete:
1266 * - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
1267 * containing an image that is attached to a framebuffer object
1268 * that is bound to the framebuffer."
1271 invalidate_framebuffer(fb
);
1278 _mesa_DeleteRenderbuffers(GLsizei n
, const GLuint
*renderbuffers
)
1281 GET_CURRENT_CONTEXT(ctx
);
1283 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1285 for (i
= 0; i
< n
; i
++) {
1286 if (renderbuffers
[i
] > 0) {
1287 struct gl_renderbuffer
*rb
;
1288 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
1290 /* check if deleting currently bound renderbuffer object */
1291 if (rb
== ctx
->CurrentRenderbuffer
) {
1293 ASSERT(rb
->RefCount
>= 2);
1294 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, 0);
1297 /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
1298 * subsection "Attaching Renderbuffer Images to a Framebuffer," of
1299 * the OpenGL 3.1 spec says:
1301 * "If a renderbuffer object is deleted while its image is
1302 * attached to one or more attachment points in the currently
1303 * bound framebuffer, then it is as if FramebufferRenderbuffer
1304 * had been called, with a renderbuffer of 0, for each
1305 * attachment point to which this image was attached in the
1306 * currently bound framebuffer. In other words, this
1307 * renderbuffer image is first detached from all attachment
1308 * points in the currently bound framebuffer. Note that the
1309 * renderbuffer image is specifically not detached from any
1310 * non-bound framebuffers. Detaching the image from any
1311 * non-bound framebuffers is the responsibility of the
1314 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1315 _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
1317 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1318 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1319 _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
1322 /* Remove from hash table immediately, to free the ID.
1323 * But the object will not be freed until it's no longer
1324 * referenced anywhere else.
1326 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
1328 if (rb
!= &DummyRenderbuffer
) {
1329 /* no longer referenced by hash table */
1330 _mesa_reference_renderbuffer(&rb
, NULL
);
1339 _mesa_GenRenderbuffers(GLsizei n
, GLuint
*renderbuffers
)
1341 GET_CURRENT_CONTEXT(ctx
);
1346 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
1353 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
1355 for (i
= 0; i
< n
; i
++) {
1356 GLuint name
= first
+ i
;
1357 renderbuffers
[i
] = name
;
1358 /* insert dummy placeholder into hash table */
1359 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1360 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
1361 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1367 * Given an internal format token for a render buffer, return the
1368 * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
1369 * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
1370 * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
1372 * This is similar to _mesa_base_tex_format() but the set of valid
1373 * internal formats is different.
1375 * Note that even if a format is determined to be legal here, validation
1376 * of the FBO may fail if the format is not supported by the driver/GPU.
1378 * \param internalFormat as passed to glRenderbufferStorage()
1379 * \return the base internal format, or 0 if internalFormat is illegal
1382 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
1385 * Notes: some formats such as alpha, luminance, etc. were added
1386 * with GL_ARB_framebuffer_object.
1388 switch (internalFormat
) {
1394 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1399 case GL_LUMINANCE12
:
1400 case GL_LUMINANCE16
:
1401 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1403 case GL_LUMINANCE_ALPHA
:
1404 case GL_LUMINANCE4_ALPHA4
:
1405 case GL_LUMINANCE6_ALPHA2
:
1406 case GL_LUMINANCE8_ALPHA8
:
1407 case GL_LUMINANCE12_ALPHA4
:
1408 case GL_LUMINANCE12_ALPHA12
:
1409 case GL_LUMINANCE16_ALPHA16
:
1410 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1411 ? GL_LUMINANCE_ALPHA
: 0;
1415 case GL_INTENSITY12
:
1416 case GL_INTENSITY16
:
1417 return ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_framebuffer_object
1428 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1430 return _mesa_is_desktop_gl(ctx
) ? GL_RGB
: 0;
1439 return _mesa_is_desktop_gl(ctx
) ? GL_RGBA
: 0;
1441 case GL_SRGB8_ALPHA8_EXT
:
1442 return _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1443 case GL_STENCIL_INDEX
:
1444 case GL_STENCIL_INDEX1_EXT
:
1445 case GL_STENCIL_INDEX4_EXT
:
1446 case GL_STENCIL_INDEX16_EXT
:
1447 /* There are extensions for GL_STENCIL_INDEX1 and GL_STENCIL_INDEX4 in
1448 * OpenGL ES, but Mesa does not currently support them.
1450 return _mesa_is_desktop_gl(ctx
) ? GL_STENCIL_INDEX
: 0;
1451 case GL_STENCIL_INDEX8_EXT
:
1452 return GL_STENCIL_INDEX
;
1453 case GL_DEPTH_COMPONENT
:
1454 case GL_DEPTH_COMPONENT32
:
1455 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_COMPONENT
: 0;
1456 case GL_DEPTH_COMPONENT16
:
1457 case GL_DEPTH_COMPONENT24
:
1458 return GL_DEPTH_COMPONENT
;
1459 case GL_DEPTH_STENCIL
:
1460 return _mesa_is_desktop_gl(ctx
) ? GL_DEPTH_STENCIL
: 0;
1461 case GL_DEPTH24_STENCIL8
:
1462 return GL_DEPTH_STENCIL
;
1463 case GL_DEPTH_COMPONENT32F
:
1464 return ctx
->Version
>= 30
1465 || (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_buffer_float
)
1466 ? GL_DEPTH_COMPONENT
: 0;
1467 case GL_DEPTH32F_STENCIL8
:
1468 return ctx
->Version
>= 30
1469 || (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_depth_buffer_float
)
1470 ? GL_DEPTH_STENCIL
: 0;
1473 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1476 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1480 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_rg
1483 return ctx
->API
!= API_OPENGLES
&& ctx
->Extensions
.ARB_texture_rg
1485 /* signed normalized texture formats */
1489 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1494 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1498 case GL_RGB16_SNORM
:
1499 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1502 case GL_RGBA8_SNORM
:
1503 case GL_RGBA16_SNORM
:
1504 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1506 case GL_ALPHA_SNORM
:
1507 case GL_ALPHA8_SNORM
:
1508 case GL_ALPHA16_SNORM
:
1509 return ctx
->API
== API_OPENGL_COMPAT
&&
1510 ctx
->Extensions
.EXT_texture_snorm
&&
1511 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1512 case GL_LUMINANCE_SNORM
:
1513 case GL_LUMINANCE8_SNORM
:
1514 case GL_LUMINANCE16_SNORM
:
1515 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1517 case GL_LUMINANCE_ALPHA_SNORM
:
1518 case GL_LUMINANCE8_ALPHA8_SNORM
:
1519 case GL_LUMINANCE16_ALPHA16_SNORM
:
1520 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1521 ? GL_LUMINANCE_ALPHA
: 0;
1522 case GL_INTENSITY_SNORM
:
1523 case GL_INTENSITY8_SNORM
:
1524 case GL_INTENSITY16_SNORM
:
1525 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_snorm
1530 return ((_mesa_is_desktop_gl(ctx
) &&
1531 ctx
->Extensions
.ARB_texture_rg
&&
1532 ctx
->Extensions
.ARB_texture_float
) ||
1533 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1537 return ((_mesa_is_desktop_gl(ctx
) &&
1538 ctx
->Extensions
.ARB_texture_rg
&&
1539 ctx
->Extensions
.ARB_texture_float
) ||
1540 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1544 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_float
)
1548 return ((_mesa_is_desktop_gl(ctx
) &&
1549 ctx
->Extensions
.ARB_texture_float
) ||
1550 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1552 case GL_ALPHA16F_ARB
:
1553 case GL_ALPHA32F_ARB
:
1554 return ctx
->API
== API_OPENGL_COMPAT
&&
1555 ctx
->Extensions
.ARB_texture_float
&&
1556 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1557 case GL_LUMINANCE16F_ARB
:
1558 case GL_LUMINANCE32F_ARB
:
1559 return ctx
->API
== API_OPENGL_COMPAT
&&
1560 ctx
->Extensions
.ARB_texture_float
&&
1561 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1562 case GL_LUMINANCE_ALPHA16F_ARB
:
1563 case GL_LUMINANCE_ALPHA32F_ARB
:
1564 return ctx
->API
== API_OPENGL_COMPAT
&&
1565 ctx
->Extensions
.ARB_texture_float
&&
1566 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1567 case GL_INTENSITY16F_ARB
:
1568 case GL_INTENSITY32F_ARB
:
1569 return ctx
->API
== API_OPENGL_COMPAT
&&
1570 ctx
->Extensions
.ARB_texture_float
&&
1571 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1573 return (_mesa_is_desktop_gl(ctx
)
1574 && ctx
->Extensions
.EXT_texture_shared_exponent
)
1576 case GL_R11F_G11F_B10F
:
1577 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_packed_float
) ||
1578 _mesa_is_gles3(ctx
) /* EXT_color_buffer_float */ )
1581 case GL_RGBA8UI_EXT
:
1582 case GL_RGBA16UI_EXT
:
1583 case GL_RGBA32UI_EXT
:
1585 case GL_RGBA16I_EXT
:
1586 case GL_RGBA32I_EXT
:
1587 return ctx
->Version
>= 30
1588 || (_mesa_is_desktop_gl(ctx
) &&
1589 ctx
->Extensions
.EXT_texture_integer
) ? GL_RGBA
: 0;
1592 case GL_RGB16UI_EXT
:
1593 case GL_RGB32UI_EXT
:
1597 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_integer
1605 return ctx
->Version
>= 30
1606 || (_mesa_is_desktop_gl(ctx
) &&
1607 ctx
->Extensions
.ARB_texture_rg
&&
1608 ctx
->Extensions
.EXT_texture_integer
) ? GL_RED
: 0;
1616 return ctx
->Version
>= 30
1617 || (_mesa_is_desktop_gl(ctx
) &&
1618 ctx
->Extensions
.ARB_texture_rg
&&
1619 ctx
->Extensions
.EXT_texture_integer
) ? GL_RG
: 0;
1621 case GL_INTENSITY8I_EXT
:
1622 case GL_INTENSITY8UI_EXT
:
1623 case GL_INTENSITY16I_EXT
:
1624 case GL_INTENSITY16UI_EXT
:
1625 case GL_INTENSITY32I_EXT
:
1626 case GL_INTENSITY32UI_EXT
:
1627 return ctx
->API
== API_OPENGL_COMPAT
&&
1628 ctx
->Extensions
.EXT_texture_integer
&&
1629 ctx
->Extensions
.ARB_framebuffer_object
? GL_INTENSITY
: 0;
1631 case GL_LUMINANCE8I_EXT
:
1632 case GL_LUMINANCE8UI_EXT
:
1633 case GL_LUMINANCE16I_EXT
:
1634 case GL_LUMINANCE16UI_EXT
:
1635 case GL_LUMINANCE32I_EXT
:
1636 case GL_LUMINANCE32UI_EXT
:
1637 return ctx
->API
== API_OPENGL_COMPAT
&&
1638 ctx
->Extensions
.EXT_texture_integer
&&
1639 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE
: 0;
1641 case GL_LUMINANCE_ALPHA8I_EXT
:
1642 case GL_LUMINANCE_ALPHA8UI_EXT
:
1643 case GL_LUMINANCE_ALPHA16I_EXT
:
1644 case GL_LUMINANCE_ALPHA16UI_EXT
:
1645 case GL_LUMINANCE_ALPHA32I_EXT
:
1646 case GL_LUMINANCE_ALPHA32UI_EXT
:
1647 return ctx
->API
== API_OPENGL_COMPAT
&&
1648 ctx
->Extensions
.EXT_texture_integer
&&
1649 ctx
->Extensions
.ARB_framebuffer_object
? GL_LUMINANCE_ALPHA
: 0;
1651 case GL_ALPHA8I_EXT
:
1652 case GL_ALPHA8UI_EXT
:
1653 case GL_ALPHA16I_EXT
:
1654 case GL_ALPHA16UI_EXT
:
1655 case GL_ALPHA32I_EXT
:
1656 case GL_ALPHA32UI_EXT
:
1657 return ctx
->API
== API_OPENGL_COMPAT
&&
1658 ctx
->Extensions
.EXT_texture_integer
&&
1659 ctx
->Extensions
.ARB_framebuffer_object
? GL_ALPHA
: 0;
1662 return (_mesa_is_desktop_gl(ctx
) &&
1663 ctx
->Extensions
.ARB_texture_rgb10_a2ui
)
1664 || _mesa_is_gles3(ctx
) ? GL_RGBA
: 0;
1667 return _mesa_is_gles(ctx
) || ctx
->Extensions
.ARB_ES2_compatibility
1676 * Invalidate a renderbuffer attachment. Called from _mesa_HashWalk().
1679 invalidate_rb(GLuint key
, void *data
, void *userData
)
1681 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1682 struct gl_renderbuffer
*rb
= (struct gl_renderbuffer
*) userData
;
1684 /* If this is a user-created FBO */
1685 if (_mesa_is_user_fbo(fb
)) {
1687 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1688 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1689 if (att
->Type
== GL_RENDERBUFFER
&&
1690 att
->Renderbuffer
== rb
) {
1691 /* Mark fb status as indeterminate to force re-validation */
1700 /** sentinal value, see below */
1701 #define NO_SAMPLES 1000
1705 * Helper function used by _mesa_RenderbufferStorage() and
1706 * _mesa_RenderbufferStorageMultisample().
1707 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
1710 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1711 GLsizei width
, GLsizei height
, GLsizei samples
)
1713 const char *func
= samples
== NO_SAMPLES
?
1714 "glRenderbufferStorage" : "glRenderbufferStorageMultisample";
1715 struct gl_renderbuffer
*rb
;
1717 GLenum sample_count_error
;
1718 GET_CURRENT_CONTEXT(ctx
);
1720 if (MESA_VERBOSE
& VERBOSE_API
) {
1721 if (samples
== NO_SAMPLES
)
1722 _mesa_debug(ctx
, "%s(%s, %s, %d, %d)\n",
1724 _mesa_lookup_enum_by_nr(target
),
1725 _mesa_lookup_enum_by_nr(internalFormat
),
1728 _mesa_debug(ctx
, "%s(%s, %s, %d, %d, %d)\n",
1730 _mesa_lookup_enum_by_nr(target
),
1731 _mesa_lookup_enum_by_nr(internalFormat
),
1732 width
, height
, samples
);
1735 if (target
!= GL_RENDERBUFFER_EXT
) {
1736 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1740 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1741 if (baseFormat
== 0) {
1742 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat=%s)",
1743 func
, _mesa_lookup_enum_by_nr(internalFormat
));
1747 if (width
< 0 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1748 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1752 if (height
< 0 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1753 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1757 if (samples
== NO_SAMPLES
) {
1758 /* NumSamples == 0 indicates non-multisampling */
1762 /* check the sample count;
1763 * note: driver may choose to use more samples than what's requested
1765 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
1766 internalFormat
, samples
);
1767 if (sample_count_error
!= GL_NO_ERROR
) {
1768 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
1773 rb
= ctx
->CurrentRenderbuffer
;
1775 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1779 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1781 if (rb
->InternalFormat
== internalFormat
&&
1782 rb
->Width
== (GLuint
) width
&&
1783 rb
->Height
== (GLuint
) height
&&
1784 rb
->NumSamples
== samples
) {
1785 /* no change in allocation needed */
1789 /* These MUST get set by the AllocStorage func */
1790 rb
->Format
= MESA_FORMAT_NONE
;
1791 rb
->NumSamples
= samples
;
1793 /* Now allocate the storage */
1794 ASSERT(rb
->AllocStorage
);
1795 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1796 /* No error - check/set fields now */
1797 /* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
1798 assert(rb
->Width
== (GLuint
) width
);
1799 assert(rb
->Height
== (GLuint
) height
);
1800 rb
->InternalFormat
= internalFormat
;
1801 rb
->_BaseFormat
= baseFormat
;
1802 assert(rb
->_BaseFormat
!= 0);
1805 /* Probably ran out of memory - clear the fields */
1808 rb
->Format
= MESA_FORMAT_NONE
;
1809 rb
->InternalFormat
= GL_NONE
;
1810 rb
->_BaseFormat
= GL_NONE
;
1814 /* Invalidate the framebuffers the renderbuffer is attached in. */
1815 if (rb
->AttachedAnytime
) {
1816 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, invalidate_rb
, rb
);
1822 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1824 struct gl_renderbuffer
*rb
;
1825 GET_CURRENT_CONTEXT(ctx
);
1827 if (!ctx
->Extensions
.OES_EGL_image
) {
1828 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1829 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1833 if (target
!= GL_RENDERBUFFER
) {
1834 _mesa_error(ctx
, GL_INVALID_ENUM
,
1835 "EGLImageTargetRenderbufferStorageOES");
1839 rb
= ctx
->CurrentRenderbuffer
;
1841 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1842 "EGLImageTargetRenderbufferStorageOES");
1846 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1848 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1853 * Helper function for _mesa_GetRenderbufferParameteriv() and
1854 * _mesa_GetFramebufferAttachmentParameteriv()
1855 * We have to be careful to respect the base format. For example, if a
1856 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1857 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1858 * we need to return zero.
1861 get_component_bits(GLenum pname
, GLenum baseFormat
, mesa_format format
)
1863 if (_mesa_base_format_has_channel(baseFormat
, pname
))
1864 return _mesa_get_format_bits(format
, pname
);
1872 _mesa_RenderbufferStorage(GLenum target
, GLenum internalFormat
,
1873 GLsizei width
, GLsizei height
)
1875 /* GL_ARB_fbo says calling this function is equivalent to calling
1876 * glRenderbufferStorageMultisample() with samples=0. We pass in
1877 * a token value here just for error reporting purposes.
1879 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1884 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1885 GLenum internalFormat
,
1886 GLsizei width
, GLsizei height
)
1888 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1893 * OpenGL ES version of glRenderBufferStorage.
1896 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1897 GLsizei width
, GLsizei height
)
1899 switch (internalFormat
) {
1901 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1902 /* choose a closest format */
1903 internalFormat
= GL_RGB5
;
1909 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1914 _mesa_GetRenderbufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1916 struct gl_renderbuffer
*rb
;
1917 GET_CURRENT_CONTEXT(ctx
);
1919 if (target
!= GL_RENDERBUFFER_EXT
) {
1920 _mesa_error(ctx
, GL_INVALID_ENUM
,
1921 "glGetRenderbufferParameterivEXT(target)");
1925 rb
= ctx
->CurrentRenderbuffer
;
1927 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1928 "glGetRenderbufferParameterivEXT");
1932 /* No need to flush here since we're just quering state which is
1933 * not effected by rendering.
1937 case GL_RENDERBUFFER_WIDTH_EXT
:
1938 *params
= rb
->Width
;
1940 case GL_RENDERBUFFER_HEIGHT_EXT
:
1941 *params
= rb
->Height
;
1943 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1944 *params
= rb
->InternalFormat
;
1946 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1947 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1948 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1949 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1950 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1951 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1952 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1954 case GL_RENDERBUFFER_SAMPLES
:
1955 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_framebuffer_object
)
1956 || _mesa_is_gles3(ctx
)) {
1957 *params
= rb
->NumSamples
;
1962 _mesa_error(ctx
, GL_INVALID_ENUM
,
1963 "glGetRenderbufferParameterivEXT(target)");
1969 GLboolean GLAPIENTRY
1970 _mesa_IsFramebuffer(GLuint framebuffer
)
1972 GET_CURRENT_CONTEXT(ctx
);
1973 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1975 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1976 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1984 * Check if any of the attachments of the given framebuffer are textures
1985 * (render to texture). Call ctx->Driver.RenderTexture() for such
1989 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1992 ASSERT(ctx
->Driver
.RenderTexture
);
1994 if (_mesa_is_winsys_fbo(fb
))
1995 return; /* can't render to texture with winsys framebuffers */
1997 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1998 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1999 if (att
->Texture
&& att
->Renderbuffer
->TexImage
2000 && driver_RenderTexture_is_safe(att
)) {
2001 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
2008 * Examine all the framebuffer's attachments to see if any are textures.
2009 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
2010 * notify the device driver that the texture image may have changed.
2013 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
2015 if (_mesa_is_winsys_fbo(fb
))
2016 return; /* can't render to texture with winsys framebuffers */
2018 if (ctx
->Driver
.FinishRenderTexture
) {
2020 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2021 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2022 struct gl_renderbuffer
*rb
= att
->Renderbuffer
;
2023 if (rb
&& rb
->NeedsFinishRenderTexture
) {
2024 ctx
->Driver
.FinishRenderTexture(ctx
, rb
);
2032 bind_framebuffer(GLenum target
, GLuint framebuffer
, bool allow_user_names
)
2034 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
2035 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
2036 GLboolean bindReadBuf
, bindDrawBuf
;
2037 GET_CURRENT_CONTEXT(ctx
);
2040 case GL_DRAW_FRAMEBUFFER_EXT
:
2041 bindDrawBuf
= GL_TRUE
;
2042 bindReadBuf
= GL_FALSE
;
2044 case GL_READ_FRAMEBUFFER_EXT
:
2045 bindDrawBuf
= GL_FALSE
;
2046 bindReadBuf
= GL_TRUE
;
2048 case GL_FRAMEBUFFER_EXT
:
2049 bindDrawBuf
= GL_TRUE
;
2050 bindReadBuf
= GL_TRUE
;
2053 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
2058 /* Binding a user-created framebuffer object */
2059 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
2060 if (newDrawFb
== &DummyFramebuffer
) {
2061 /* ID was reserved, but no real framebuffer object made yet */
2064 else if (!newDrawFb
&& !allow_user_names
) {
2065 /* All FBO IDs must be Gen'd */
2066 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
2071 /* create new framebuffer object */
2072 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
2074 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
2077 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
2079 newReadFb
= newDrawFb
;
2082 /* Binding the window system framebuffer (which was originally set
2083 * with MakeCurrent).
2085 newDrawFb
= ctx
->WinSysDrawBuffer
;
2086 newReadFb
= ctx
->WinSysReadBuffer
;
2090 ASSERT(newDrawFb
!= &DummyFramebuffer
);
2092 /* save pointers to current/old framebuffers */
2093 oldDrawFb
= ctx
->DrawBuffer
;
2094 oldReadFb
= ctx
->ReadBuffer
;
2096 /* check if really changing bindings */
2097 if (oldDrawFb
== newDrawFb
)
2098 bindDrawBuf
= GL_FALSE
;
2099 if (oldReadFb
== newReadFb
)
2100 bindReadBuf
= GL_FALSE
;
2103 * OK, now bind the new Draw/Read framebuffers, if they're changing.
2105 * We also check if we're beginning and/or ending render-to-texture.
2106 * When a framebuffer with texture attachments is unbound, call
2107 * ctx->Driver.FinishRenderTexture().
2108 * When a framebuffer with texture attachments is bound, call
2109 * ctx->Driver.RenderTexture().
2111 * Note that if the ReadBuffer has texture attachments we don't consider
2112 * that a render-to-texture case.
2115 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2117 /* check if old readbuffer was render-to-texture */
2118 check_end_texture_render(ctx
, oldReadFb
);
2120 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
2124 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2126 /* check if old framebuffer had any texture attachments */
2128 check_end_texture_render(ctx
, oldDrawFb
);
2130 /* check if newly bound framebuffer has any texture attachments */
2131 check_begin_texture_render(ctx
, newDrawFb
);
2133 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
2136 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
2137 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
2142 _mesa_BindFramebuffer(GLenum target
, GLuint framebuffer
)
2144 GET_CURRENT_CONTEXT(ctx
);
2146 /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
2147 * point, but they allow the use of user-generated names.
2149 bind_framebuffer(target
, framebuffer
, _mesa_is_gles(ctx
));
2153 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
2155 /* This function should not be in the dispatch table for core profile /
2156 * OpenGL 3.1, so execution should never get here in those cases -- no
2157 * need for an explicit test.
2159 bind_framebuffer(target
, framebuffer
, true);
2163 _mesa_DeleteFramebuffers(GLsizei n
, const GLuint
*framebuffers
)
2166 GET_CURRENT_CONTEXT(ctx
);
2168 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2170 for (i
= 0; i
< n
; i
++) {
2171 if (framebuffers
[i
] > 0) {
2172 struct gl_framebuffer
*fb
;
2173 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
2175 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
2177 /* check if deleting currently bound framebuffer object */
2178 if (fb
== ctx
->DrawBuffer
) {
2180 ASSERT(fb
->RefCount
>= 2);
2181 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
2183 if (fb
== ctx
->ReadBuffer
) {
2185 ASSERT(fb
->RefCount
>= 2);
2186 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
2189 /* remove from hash table immediately, to free the ID */
2190 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
2192 if (fb
!= &DummyFramebuffer
) {
2193 /* But the object will not be freed until it's no longer
2194 * bound in any context.
2196 _mesa_reference_framebuffer(&fb
, NULL
);
2205 _mesa_GenFramebuffers(GLsizei n
, GLuint
*framebuffers
)
2207 GET_CURRENT_CONTEXT(ctx
);
2212 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
2219 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
2221 for (i
= 0; i
< n
; i
++) {
2222 GLuint name
= first
+ i
;
2223 framebuffers
[i
] = name
;
2224 /* insert dummy placeholder into hash table */
2225 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
2226 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
2227 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
2234 _mesa_CheckFramebufferStatus(GLenum target
)
2236 struct gl_framebuffer
*buffer
;
2237 GET_CURRENT_CONTEXT(ctx
);
2239 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2241 if (MESA_VERBOSE
& VERBOSE_API
)
2242 _mesa_debug(ctx
, "glCheckFramebufferStatus(%s)\n",
2243 _mesa_lookup_enum_by_nr(target
));
2245 buffer
= get_framebuffer_target(ctx
, target
);
2247 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
2251 if (_mesa_is_winsys_fbo(buffer
)) {
2252 /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
2253 if (buffer
!= &IncompleteFramebuffer
) {
2254 return GL_FRAMEBUFFER_COMPLETE_EXT
;
2256 return GL_FRAMEBUFFER_UNDEFINED
;
2260 /* No need to flush here */
2262 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
2263 _mesa_test_framebuffer_completeness(ctx
, buffer
);
2266 return buffer
->_Status
;
2271 * Replicate the src attachment point. Used by framebuffer_texture() when
2272 * the same texture is attached at GL_DEPTH_ATTACHMENT and
2273 * GL_STENCIL_ATTACHMENT.
2276 reuse_framebuffer_texture_attachment(struct gl_framebuffer
*fb
,
2277 gl_buffer_index dst
,
2278 gl_buffer_index src
)
2280 struct gl_renderbuffer_attachment
*dst_att
= &fb
->Attachment
[dst
];
2281 struct gl_renderbuffer_attachment
*src_att
= &fb
->Attachment
[src
];
2283 assert(src_att
->Texture
!= NULL
);
2284 assert(src_att
->Renderbuffer
!= NULL
);
2286 _mesa_reference_texobj(&dst_att
->Texture
, src_att
->Texture
);
2287 _mesa_reference_renderbuffer(&dst_att
->Renderbuffer
, src_att
->Renderbuffer
);
2288 dst_att
->Type
= src_att
->Type
;
2289 dst_att
->Complete
= src_att
->Complete
;
2290 dst_att
->TextureLevel
= src_att
->TextureLevel
;
2291 dst_att
->Zoffset
= src_att
->Zoffset
;
2296 * Common code called by glFramebufferTexture1D/2D/3DEXT() and
2297 * glFramebufferTextureLayerEXT().
2299 * \param textarget is the textarget that was passed to the
2300 * glFramebufferTexture...() function, or 0 if the corresponding function
2301 * doesn't have a textarget parameter.
2303 * \param layered is true if this function was called from
2304 * glFramebufferTexture(), false otherwise.
2307 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
2308 GLenum attachment
, GLenum textarget
, GLuint texture
,
2309 GLint level
, GLint zoffset
, GLboolean layered
)
2311 struct gl_renderbuffer_attachment
*att
;
2312 struct gl_texture_object
*texObj
= NULL
;
2313 struct gl_framebuffer
*fb
;
2314 GLenum maxLevelsTarget
;
2316 fb
= get_framebuffer_target(ctx
, target
);
2318 _mesa_error(ctx
, GL_INVALID_ENUM
,
2319 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
2323 /* check framebuffer binding */
2324 if (_mesa_is_winsys_fbo(fb
)) {
2325 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2326 "glFramebufferTexture%sEXT", caller
);
2330 /* The textarget, level, and zoffset parameters are only validated if
2331 * texture is non-zero.
2334 GLboolean err
= GL_TRUE
;
2336 texObj
= _mesa_lookup_texture(ctx
, texture
);
2337 if (texObj
!= NULL
) {
2338 if (textarget
== 0) {
2340 /* We're being called by glFramebufferTexture() and textarget
2343 switch (texObj
->Target
) {
2345 case GL_TEXTURE_1D_ARRAY_EXT
:
2346 case GL_TEXTURE_2D_ARRAY_EXT
:
2347 case GL_TEXTURE_CUBE_MAP
:
2348 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2349 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2354 case GL_TEXTURE_RECTANGLE
:
2355 case GL_TEXTURE_2D_MULTISAMPLE
:
2356 /* These texture types are valid to pass to
2357 * glFramebufferTexture(), but since they aren't layered, it
2358 * is equivalent to calling glFramebufferTexture{1D,2D}().
2362 textarget
= texObj
->Target
;
2369 /* We're being called by glFramebufferTextureLayer() and
2370 * textarget is not used. The only legal texture types for
2371 * that function are 3D and 1D/2D arrays textures.
2373 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
2374 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
2375 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
) &&
2376 (texObj
->Target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) &&
2377 (texObj
->Target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
);
2381 /* Make sure textarget is consistent with the texture's type */
2382 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
2383 ? !_mesa_is_cube_face(textarget
)
2384 : (texObj
->Target
!= textarget
);
2388 /* can't render to a non-existant texture */
2389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2390 "glFramebufferTexture%sEXT(non existant texture)",
2396 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2397 "glFramebufferTexture%sEXT(texture target mismatch)",
2402 if (texObj
->Target
== GL_TEXTURE_3D
) {
2403 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
2404 if (zoffset
< 0 || zoffset
>= maxSize
) {
2405 _mesa_error(ctx
, GL_INVALID_VALUE
,
2406 "glFramebufferTexture%sEXT(zoffset)", caller
);
2410 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
2411 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
) ||
2412 (texObj
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
2413 (texObj
->Target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)) {
2415 zoffset
>= (GLint
) ctx
->Const
.MaxArrayTextureLayers
) {
2416 _mesa_error(ctx
, GL_INVALID_VALUE
,
2417 "glFramebufferTexture%sEXT(layer)", caller
);
2422 maxLevelsTarget
= textarget
? textarget
: texObj
->Target
;
2424 (level
>= _mesa_max_texture_levels(ctx
, maxLevelsTarget
))) {
2425 _mesa_error(ctx
, GL_INVALID_VALUE
,
2426 "glFramebufferTexture%sEXT(level)", caller
);
2431 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2433 _mesa_error(ctx
, GL_INVALID_ENUM
,
2434 "glFramebufferTexture%sEXT(attachment)", caller
);
2438 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2440 _glthread_LOCK_MUTEX(fb
->Mutex
);
2442 if (attachment
== GL_DEPTH_ATTACHMENT
&&
2443 texObj
== fb
->Attachment
[BUFFER_STENCIL
].Texture
&&
2444 level
== fb
->Attachment
[BUFFER_STENCIL
].TextureLevel
&&
2445 _mesa_tex_target_to_face(textarget
) ==
2446 fb
->Attachment
[BUFFER_STENCIL
].CubeMapFace
&&
2447 zoffset
== fb
->Attachment
[BUFFER_STENCIL
].Zoffset
) {
2448 /* The texture object is already attached to the stencil attachment
2449 * point. Don't create a new renderbuffer; just reuse the stencil
2450 * attachment's. This is required to prevent a GL error in
2451 * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
2453 reuse_framebuffer_texture_attachment(fb
, BUFFER_DEPTH
,
2455 } else if (attachment
== GL_STENCIL_ATTACHMENT
&&
2456 texObj
== fb
->Attachment
[BUFFER_DEPTH
].Texture
&&
2457 level
== fb
->Attachment
[BUFFER_DEPTH
].TextureLevel
&&
2458 _mesa_tex_target_to_face(textarget
) ==
2459 fb
->Attachment
[BUFFER_DEPTH
].CubeMapFace
&&
2460 zoffset
== fb
->Attachment
[BUFFER_DEPTH
].Zoffset
) {
2461 /* As above, but with depth and stencil transposed. */
2462 reuse_framebuffer_texture_attachment(fb
, BUFFER_STENCIL
,
2465 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
2466 level
, zoffset
, layered
);
2467 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2468 /* Above we created a new renderbuffer and attached it to the
2469 * depth attachment point. Now attach it to the stencil attachment
2472 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
2473 reuse_framebuffer_texture_attachment(fb
,BUFFER_STENCIL
,
2478 /* Set the render-to-texture flag. We'll check this flag in
2479 * glTexImage() and friends to determine if we need to revalidate
2480 * any FBOs that might be rendering into this texture.
2481 * This flag never gets cleared since it's non-trivial to determine
2482 * when all FBOs might be done rendering to this texture. That's OK
2483 * though since it's uncommon to render to a texture then repeatedly
2484 * call glTexImage() to change images in the texture.
2486 texObj
->_RenderToTexture
= GL_TRUE
;
2489 _mesa_remove_attachment(ctx
, att
);
2490 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2491 assert(att
== &fb
->Attachment
[BUFFER_DEPTH
]);
2492 _mesa_remove_attachment(ctx
, &fb
->Attachment
[BUFFER_STENCIL
]);
2496 invalidate_framebuffer(fb
);
2498 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
2504 _mesa_FramebufferTexture1D(GLenum target
, GLenum attachment
,
2505 GLenum textarget
, GLuint texture
, GLint level
)
2507 GET_CURRENT_CONTEXT(ctx
);
2512 switch (textarget
) {
2516 case GL_TEXTURE_1D_ARRAY
:
2517 error
= !ctx
->Extensions
.EXT_texture_array
;
2524 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2525 "glFramebufferTexture1DEXT(textarget=%s)",
2526 _mesa_lookup_enum_by_nr(textarget
));
2531 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
2532 level
, 0, GL_FALSE
);
2537 _mesa_FramebufferTexture2D(GLenum target
, GLenum attachment
,
2538 GLenum textarget
, GLuint texture
, GLint level
)
2540 GET_CURRENT_CONTEXT(ctx
);
2545 switch (textarget
) {
2549 case GL_TEXTURE_RECTANGLE
:
2550 error
= _mesa_is_gles(ctx
)
2551 || !ctx
->Extensions
.NV_texture_rectangle
;
2553 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2554 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2555 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2556 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2557 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2558 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2559 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
2561 case GL_TEXTURE_2D_ARRAY
:
2562 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
2563 || !ctx
->Extensions
.EXT_texture_array
;
2565 case GL_TEXTURE_2D_MULTISAMPLE
:
2566 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2567 error
= _mesa_is_gles(ctx
)
2568 || !ctx
->Extensions
.ARB_texture_multisample
;
2575 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2576 "glFramebufferTexture2DEXT(textarget=%s)",
2577 _mesa_lookup_enum_by_nr(textarget
));
2582 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
2583 level
, 0, GL_FALSE
);
2588 _mesa_FramebufferTexture3D(GLenum target
, GLenum attachment
,
2589 GLenum textarget
, GLuint texture
,
2590 GLint level
, GLint zoffset
)
2592 GET_CURRENT_CONTEXT(ctx
);
2594 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
2595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2596 "glFramebufferTexture3DEXT(textarget)");
2600 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
2601 level
, zoffset
, GL_FALSE
);
2606 _mesa_FramebufferTextureLayer(GLenum target
, GLenum attachment
,
2607 GLuint texture
, GLint level
, GLint layer
)
2609 GET_CURRENT_CONTEXT(ctx
);
2611 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2612 level
, layer
, GL_FALSE
);
2617 _mesa_FramebufferTexture(GLenum target
, GLenum attachment
,
2618 GLuint texture
, GLint level
)
2620 GET_CURRENT_CONTEXT(ctx
);
2622 if (_mesa_has_geometry_shaders(ctx
)) {
2623 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
2626 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2627 "unsupported function (glFramebufferTexture) called");
2633 _mesa_FramebufferRenderbuffer(GLenum target
, GLenum attachment
,
2634 GLenum renderbufferTarget
,
2635 GLuint renderbuffer
)
2637 struct gl_renderbuffer_attachment
*att
;
2638 struct gl_framebuffer
*fb
;
2639 struct gl_renderbuffer
*rb
;
2640 GET_CURRENT_CONTEXT(ctx
);
2642 fb
= get_framebuffer_target(ctx
, target
);
2644 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFramebufferRenderbufferEXT(target)");
2648 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
2649 _mesa_error(ctx
, GL_INVALID_ENUM
,
2650 "glFramebufferRenderbufferEXT(renderbufferTarget)");
2654 if (_mesa_is_winsys_fbo(fb
)) {
2655 /* Can't attach new renderbuffers to a window system framebuffer */
2656 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
2660 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
2662 _mesa_error(ctx
, GL_INVALID_ENUM
,
2663 "glFramebufferRenderbufferEXT(invalid attachment %s)",
2664 _mesa_lookup_enum_by_nr(attachment
));
2669 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
2671 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2672 "glFramebufferRenderbufferEXT(non-existant"
2673 " renderbuffer %u)", renderbuffer
);
2676 else if (rb
== &DummyRenderbuffer
) {
2677 /* This is what NVIDIA does */
2678 _mesa_error(ctx
, GL_INVALID_VALUE
,
2679 "glFramebufferRenderbufferEXT(renderbuffer %u)",
2685 /* remove renderbuffer attachment */
2689 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
2690 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
2691 /* make sure the renderbuffer is a depth/stencil format */
2692 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
2693 if (baseFormat
!= GL_DEPTH_STENCIL
) {
2694 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2695 "glFramebufferRenderbufferEXT(renderbuffer"
2696 " is not DEPTH_STENCIL format)");
2702 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2704 assert(ctx
->Driver
.FramebufferRenderbuffer
);
2705 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
2707 /* Some subsequent GL commands may depend on the framebuffer's visual
2708 * after the binding is updated. Update visual info now.
2710 _mesa_update_framebuffer_visual(ctx
, fb
);
2715 _mesa_GetFramebufferAttachmentParameteriv(GLenum target
, GLenum attachment
,
2716 GLenum pname
, GLint
*params
)
2718 const struct gl_renderbuffer_attachment
*att
;
2719 struct gl_framebuffer
*buffer
;
2721 GET_CURRENT_CONTEXT(ctx
);
2723 /* The error differs in GL and GLES. */
2724 err
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
2726 buffer
= get_framebuffer_target(ctx
, target
);
2728 _mesa_error(ctx
, GL_INVALID_ENUM
,
2729 "glGetFramebufferAttachmentParameterivEXT(target)");
2733 if (_mesa_is_winsys_fbo(buffer
)) {
2734 /* Page 126 (page 136 of the PDF) of the OpenGL ES 2.0.25 spec
2737 * "If the framebuffer currently bound to target is zero, then
2738 * INVALID_OPERATION is generated."
2740 * The EXT_framebuffer_object spec has the same wording, and the
2741 * OES_framebuffer_object spec refers to the EXT_framebuffer_object
2744 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2745 && !_mesa_is_gles3(ctx
)) {
2746 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2747 "glGetFramebufferAttachmentParameteriv(bound FBO = 0)");
2751 if (_mesa_is_gles3(ctx
) && attachment
!= GL_BACK
&&
2752 attachment
!= GL_DEPTH
&& attachment
!= GL_STENCIL
) {
2753 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2754 "glGetFramebufferAttachmentParameteriv(attachment)");
2757 /* the default / window-system FBO */
2758 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
2761 /* user-created framebuffer FBO */
2762 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
2766 _mesa_error(ctx
, GL_INVALID_ENUM
,
2767 "glGetFramebufferAttachmentParameterivEXT(attachment)");
2771 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2772 /* the depth and stencil attachments must point to the same buffer */
2773 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
2774 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
2775 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
2776 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
2777 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2778 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
2779 " attachments differ)");
2784 /* No need to flush here */
2787 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
2788 *params
= _mesa_is_winsys_fbo(buffer
)
2789 ? GL_FRAMEBUFFER_DEFAULT
: att
->Type
;
2791 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
2792 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
2793 *params
= att
->Renderbuffer
->Name
;
2795 else if (att
->Type
== GL_TEXTURE
) {
2796 *params
= att
->Texture
->Name
;
2799 assert(att
->Type
== GL_NONE
);
2800 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
2803 goto invalid_pname_enum
;
2807 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
2808 if (att
->Type
== GL_TEXTURE
) {
2809 *params
= att
->TextureLevel
;
2811 else if (att
->Type
== GL_NONE
) {
2812 _mesa_error(ctx
, err
,
2813 "glGetFramebufferAttachmentParameterivEXT(pname)");
2816 goto invalid_pname_enum
;
2819 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2820 if (att
->Type
== GL_TEXTURE
) {
2821 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2822 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2828 else if (att
->Type
== GL_NONE
) {
2829 _mesa_error(ctx
, err
,
2830 "glGetFramebufferAttachmentParameterivEXT(pname)");
2833 goto invalid_pname_enum
;
2836 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2837 if (ctx
->API
== API_OPENGLES
) {
2838 goto invalid_pname_enum
;
2839 } else if (att
->Type
== GL_NONE
) {
2840 _mesa_error(ctx
, err
,
2841 "glGetFramebufferAttachmentParameterivEXT(pname)");
2842 } else if (att
->Type
== GL_TEXTURE
) {
2843 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2844 *params
= att
->Zoffset
;
2851 goto invalid_pname_enum
;
2854 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2855 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2856 && !_mesa_is_gles3(ctx
)) {
2857 goto invalid_pname_enum
;
2859 else if (att
->Type
== GL_NONE
) {
2860 _mesa_error(ctx
, err
,
2861 "glGetFramebufferAttachmentParameterivEXT(pname)");
2864 if (ctx
->Extensions
.EXT_framebuffer_sRGB
) {
2865 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2868 /* According to ARB_framebuffer_sRGB, we should return LINEAR
2869 * if the sRGB conversion is unsupported. */
2870 *params
= GL_LINEAR
;
2874 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2875 if ((ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.ARB_framebuffer_object
)
2876 && ctx
->API
!= API_OPENGL_CORE
2877 && !_mesa_is_gles3(ctx
)) {
2878 goto invalid_pname_enum
;
2880 else if (att
->Type
== GL_NONE
) {
2881 _mesa_error(ctx
, err
,
2882 "glGetFramebufferAttachmentParameterivEXT(pname)");
2885 mesa_format format
= att
->Renderbuffer
->Format
;
2887 /* Page 235 (page 247 of the PDF) in section 6.1.13 of the OpenGL ES
2890 * "If pname is FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE.... If
2891 * attachment is DEPTH_STENCIL_ATTACHMENT the query will fail and
2892 * generate an INVALID_OPERATION error.
2894 if (_mesa_is_gles3(ctx
) && attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
2895 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2896 "glGetFramebufferAttachmentParameteriv(cannot query "
2897 "GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE of "
2898 "GL_DEPTH_STENCIL_ATTACHMENT");
2902 if (format
== MESA_FORMAT_S_UINT8
) {
2906 else if (format
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
) {
2907 /* depends on the attachment parameter */
2908 if (attachment
== GL_STENCIL_ATTACHMENT
) {
2916 *params
= _mesa_get_format_datatype(format
);
2920 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2921 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2922 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2923 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2924 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2925 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2926 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_framebuffer_object
)
2927 && !_mesa_is_gles3(ctx
)) {
2928 goto invalid_pname_enum
;
2930 else if (att
->Type
== GL_NONE
) {
2931 _mesa_error(ctx
, err
,
2932 "glGetFramebufferAttachmentParameterivEXT(pname)");
2934 else if (att
->Texture
) {
2935 const struct gl_texture_image
*texImage
=
2936 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2939 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2940 texImage
->TexFormat
);
2946 else if (att
->Renderbuffer
) {
2947 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2948 att
->Renderbuffer
->Format
);
2951 _mesa_problem(ctx
, "glGetFramebufferAttachmentParameterivEXT:"
2952 " invalid FBO attachment structure");
2955 case GL_FRAMEBUFFER_ATTACHMENT_LAYERED
:
2956 if (!_mesa_has_geometry_shaders(ctx
)) {
2957 goto invalid_pname_enum
;
2958 } else if (att
->Type
== GL_TEXTURE
) {
2959 *params
= att
->Layered
;
2960 } else if (att
->Type
== GL_NONE
) {
2961 _mesa_error(ctx
, err
,
2962 "glGetFramebufferAttachmentParameteriv(pname)");
2964 goto invalid_pname_enum
;
2968 goto invalid_pname_enum
;
2974 _mesa_error(ctx
, GL_INVALID_ENUM
,
2975 "glGetFramebufferAttachmentParameteriv(pname)");
2981 * Generate all the mipmap levels below the base level.
2982 * Note: this GL function would be more useful if one could specify a
2983 * cube face, a set of array slices, etc.
2986 _mesa_GenerateMipmap(GLenum target
)
2988 struct gl_texture_image
*srcImage
;
2989 struct gl_texture_object
*texObj
;
2992 GET_CURRENT_CONTEXT(ctx
);
2994 FLUSH_VERTICES(ctx
, 0);
2998 error
= _mesa_is_gles(ctx
);
3004 error
= ctx
->API
== API_OPENGLES
;
3006 case GL_TEXTURE_CUBE_MAP
:
3007 error
= !ctx
->Extensions
.ARB_texture_cube_map
;
3009 case GL_TEXTURE_1D_ARRAY
:
3010 error
= _mesa_is_gles(ctx
) || !ctx
->Extensions
.EXT_texture_array
;
3012 case GL_TEXTURE_2D_ARRAY
:
3013 error
= (_mesa_is_gles(ctx
) && ctx
->Version
< 30)
3014 || !ctx
->Extensions
.EXT_texture_array
;
3021 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target=%s)",
3022 _mesa_lookup_enum_by_nr(target
));
3026 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3028 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
3033 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
&&
3034 !_mesa_cube_complete(texObj
)) {
3035 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3036 "glGenerateMipmap(incomplete cube map)");
3040 _mesa_lock_texture(ctx
, texObj
);
3042 srcImage
= _mesa_select_tex_image(ctx
, texObj
, target
, texObj
->BaseLevel
);
3044 _mesa_unlock_texture(ctx
, texObj
);
3045 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3046 "glGenerateMipmap(zero size base image)");
3050 if (_mesa_is_enum_format_integer(srcImage
->InternalFormat
) ||
3051 _mesa_is_depthstencil_format(srcImage
->InternalFormat
) ||
3052 _mesa_is_stencil_format(srcImage
->InternalFormat
)) {
3053 _mesa_unlock_texture(ctx
, texObj
);
3054 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3055 "glGenerateMipmap(invalid internal format)");
3059 if (target
== GL_TEXTURE_CUBE_MAP
) {
3061 for (face
= 0; face
< 6; face
++)
3062 ctx
->Driver
.GenerateMipmap(ctx
,
3063 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
3067 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3069 _mesa_unlock_texture(ctx
, texObj
);
3073 static const struct gl_renderbuffer_attachment
*
3074 find_attachment(const struct gl_framebuffer
*fb
,
3075 const struct gl_renderbuffer
*rb
)
3078 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
3079 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
3080 return &fb
->Attachment
[i
];
3087 * Helper function for checking if the datatypes of color buffers are
3088 * compatible for glBlitFramebuffer. From the 3.1 spec, page 198:
3090 * "GL_INVALID_OPERATION is generated if mask contains GL_COLOR_BUFFER_BIT
3091 * and any of the following conditions hold:
3092 * - The read buffer contains fixed-point or floating-point values and any
3093 * draw buffer contains neither fixed-point nor floating-point values.
3094 * - The read buffer contains unsigned integer values and any draw buffer
3095 * does not contain unsigned integer values.
3096 * - The read buffer contains signed integer values and any draw buffer
3097 * does not contain signed integer values."
3100 compatible_color_datatypes(mesa_format srcFormat
, mesa_format dstFormat
)
3102 GLenum srcType
= _mesa_get_format_datatype(srcFormat
);
3103 GLenum dstType
= _mesa_get_format_datatype(dstFormat
);
3105 if (srcType
!= GL_INT
&& srcType
!= GL_UNSIGNED_INT
) {
3106 assert(srcType
== GL_UNSIGNED_NORMALIZED
||
3107 srcType
== GL_SIGNED_NORMALIZED
||
3108 srcType
== GL_FLOAT
);
3109 /* Boil any of those types down to GL_FLOAT */
3113 if (dstType
!= GL_INT
&& dstType
!= GL_UNSIGNED_INT
) {
3114 assert(dstType
== GL_UNSIGNED_NORMALIZED
||
3115 dstType
== GL_SIGNED_NORMALIZED
||
3116 dstType
== GL_FLOAT
);
3117 /* Boil any of those types down to GL_FLOAT */
3121 return srcType
== dstType
;
3126 compatible_resolve_formats(const struct gl_renderbuffer
*readRb
,
3127 const struct gl_renderbuffer
*drawRb
)
3129 GLenum readFormat
, drawFormat
;
3131 /* The simple case where we know the backing Mesa formats are the same.
3133 if (_mesa_get_srgb_format_linear(readRb
->Format
) ==
3134 _mesa_get_srgb_format_linear(drawRb
->Format
)) {
3138 /* The Mesa formats are different, so we must check whether the internal
3139 * formats are compatible.
3141 * Under some circumstances, the user may request e.g. two GL_RGBA8
3142 * textures and get two entirely different Mesa formats like RGBA8888 and
3143 * ARGB8888. Drivers behaving like that should be able to cope with
3144 * non-matching formats by themselves, because it's not the user's fault.
3146 * Blits between linear and sRGB formats are also allowed.
3148 readFormat
= _mesa_get_nongeneric_internalformat(readRb
->InternalFormat
);
3149 drawFormat
= _mesa_get_nongeneric_internalformat(drawRb
->InternalFormat
);
3150 readFormat
= _mesa_get_linear_internalformat(readFormat
);
3151 drawFormat
= _mesa_get_linear_internalformat(drawFormat
);
3153 if (readFormat
== drawFormat
) {
3161 is_valid_blit_filter(const struct gl_context
*ctx
, GLenum filter
)
3167 case GL_SCALED_RESOLVE_FASTEST_EXT
:
3168 case GL_SCALED_RESOLVE_NICEST_EXT
:
3169 return ctx
->Extensions
.EXT_framebuffer_multisample_blit_scaled
;
3176 * Blit rectangular region, optionally from one framebuffer to another.
3178 * Note, if the src buffer is multisampled and the dest is not, this is
3179 * when the samples must be resolved to a single color.
3182 _mesa_BlitFramebuffer(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
3183 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
3184 GLbitfield mask
, GLenum filter
)
3186 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
3187 GL_DEPTH_BUFFER_BIT
|
3188 GL_STENCIL_BUFFER_BIT
);
3189 const struct gl_framebuffer
*readFb
, *drawFb
;
3190 GET_CURRENT_CONTEXT(ctx
);
3192 FLUSH_VERTICES(ctx
, 0);
3194 if (MESA_VERBOSE
& VERBOSE_API
)
3196 "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, 0x%x, %s)\n",
3197 srcX0
, srcY0
, srcX1
, srcY1
,
3198 dstX0
, dstY0
, dstX1
, dstY1
,
3199 mask
, _mesa_lookup_enum_by_nr(filter
));
3201 if (ctx
->NewState
) {
3202 _mesa_update_state(ctx
);
3205 readFb
= ctx
->ReadBuffer
;
3206 drawFb
= ctx
->DrawBuffer
;
3208 if (!readFb
|| !drawFb
) {
3209 /* This will normally never happen but someday we may want to
3210 * support MakeCurrent() with no drawables.
3215 /* check for complete framebuffers */
3216 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
3217 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
3218 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
3219 "glBlitFramebufferEXT(incomplete draw/read buffers)");
3223 if (!is_valid_blit_filter(ctx
, filter
)) {
3224 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(%s)",
3225 _mesa_lookup_enum_by_nr(filter
));
3229 if ((filter
== GL_SCALED_RESOLVE_FASTEST_EXT
||
3230 filter
== GL_SCALED_RESOLVE_NICEST_EXT
) &&
3231 (readFb
->Visual
.samples
== 0 || drawFb
->Visual
.samples
> 0)) {
3232 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT(%s)",
3233 _mesa_lookup_enum_by_nr(filter
));
3237 if (mask
& ~legalMaskBits
) {
3238 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
3242 /* depth/stencil must be blitted with nearest filtering */
3243 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
3244 && filter
!= GL_NEAREST
) {
3245 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3246 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter)");
3250 /* get color read/draw renderbuffers */
3251 if (mask
& GL_COLOR_BUFFER_BIT
) {
3252 const GLuint numColorDrawBuffers
= ctx
->DrawBuffer
->_NumColorDrawBuffers
;
3253 const struct gl_renderbuffer
*colorReadRb
= readFb
->_ColorReadBuffer
;
3254 const struct gl_renderbuffer
*colorDrawRb
= NULL
;
3257 /* From the EXT_framebuffer_object spec:
3259 * "If a buffer is specified in <mask> and does not exist in both
3260 * the read and draw framebuffers, the corresponding bit is silently
3263 if (!colorReadRb
|| numColorDrawBuffers
== 0) {
3264 mask
&= ~GL_COLOR_BUFFER_BIT
;
3267 for (i
= 0; i
< numColorDrawBuffers
; i
++) {
3268 colorDrawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
3272 /* Page 193 (page 205 of the PDF) in section 4.3.2 of the OpenGL
3273 * ES 3.0.1 spec says:
3275 * "If the source and destination buffers are identical, an
3276 * INVALID_OPERATION error is generated. Different mipmap
3277 * levels of a texture, different layers of a three-
3278 * dimensional texture or two-dimensional array texture, and
3279 * different faces of a cube map texture do not constitute
3280 * identical buffers."
3282 if (_mesa_is_gles3(ctx
) && (colorDrawRb
== colorReadRb
)) {
3283 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3284 "glBlitFramebuffer(source and destination color "
3285 "buffer cannot be the same)");
3289 if (!compatible_color_datatypes(colorReadRb
->Format
,
3290 colorDrawRb
->Format
)) {
3291 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3292 "glBlitFramebufferEXT(color buffer datatypes mismatch)");
3295 /* extra checks for multisample copies... */
3296 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
3297 /* color formats must match */
3298 if (!compatible_resolve_formats(colorReadRb
, colorDrawRb
)) {
3299 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3300 "glBlitFramebufferEXT(bad src/dst multisample pixel formats)");
3305 if (filter
!= GL_NEAREST
) {
3306 /* From EXT_framebuffer_multisample_blit_scaled specification:
3307 * "Calling BlitFramebuffer will result in an INVALID_OPERATION error
3308 * if filter is not NEAREST and read buffer contains integer data."
3310 GLenum type
= _mesa_get_format_datatype(colorReadRb
->Format
);
3311 if (type
== GL_INT
|| type
== GL_UNSIGNED_INT
) {
3312 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3313 "glBlitFramebufferEXT(integer color type)");
3320 if (mask
& GL_STENCIL_BUFFER_BIT
) {
3321 struct gl_renderbuffer
*readRb
=
3322 readFb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3323 struct gl_renderbuffer
*drawRb
=
3324 drawFb
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3326 /* From the EXT_framebuffer_object spec:
3328 * "If a buffer is specified in <mask> and does not exist in both
3329 * the read and draw framebuffers, the corresponding bit is silently
3332 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
3333 mask
&= ~GL_STENCIL_BUFFER_BIT
;
3336 int read_z_bits
, draw_z_bits
;
3338 if (_mesa_is_gles3(ctx
) && (drawRb
== readRb
)) {
3339 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3340 "glBlitFramebuffer(source and destination stencil "
3341 "buffer cannot be the same)");
3345 if (_mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
3346 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
3347 /* There is no need to check the stencil datatype here, because
3348 * there is only one: GL_UNSIGNED_INT.
3350 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3351 "glBlitFramebuffer(stencil attachment format mismatch)");
3355 read_z_bits
= _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
);
3356 draw_z_bits
= _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
);
3358 /* If both buffers also have depth data, the depth formats must match
3359 * as well. If one doesn't have depth, it's not blitted, so we should
3360 * ignore the depth format check.
3362 if (read_z_bits
> 0 && draw_z_bits
> 0 &&
3363 (read_z_bits
!= draw_z_bits
||
3364 _mesa_get_format_datatype(readRb
->Format
) !=
3365 _mesa_get_format_datatype(drawRb
->Format
))) {
3367 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebuffer"
3368 "(stencil attachment depth format mismatch)");
3374 if (mask
& GL_DEPTH_BUFFER_BIT
) {
3375 struct gl_renderbuffer
*readRb
=
3376 readFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3377 struct gl_renderbuffer
*drawRb
=
3378 drawFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3380 /* From the EXT_framebuffer_object spec:
3382 * "If a buffer is specified in <mask> and does not exist in both
3383 * the read and draw framebuffers, the corresponding bit is silently
3386 if ((readRb
== NULL
) || (drawRb
== NULL
)) {
3387 mask
&= ~GL_DEPTH_BUFFER_BIT
;
3390 int read_s_bit
, draw_s_bit
;
3392 if (_mesa_is_gles3(ctx
) && (drawRb
== readRb
)) {
3393 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3394 "glBlitFramebuffer(source and destination depth "
3395 "buffer cannot be the same)");
3399 if ((_mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
3400 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) ||
3401 (_mesa_get_format_datatype(readRb
->Format
) !=
3402 _mesa_get_format_datatype(drawRb
->Format
))) {
3403 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3404 "glBlitFramebuffer(depth attachment format mismatch)");
3408 read_s_bit
= _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
);
3409 draw_s_bit
= _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
);
3411 /* If both buffers also have stencil data, the stencil formats must
3412 * match as well. If one doesn't have stencil, it's not blitted, so
3413 * we should ignore the stencil format check.
3415 if (read_s_bit
> 0 && draw_s_bit
> 0 && read_s_bit
!= draw_s_bit
) {
3416 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebuffer"
3417 "(depth attachment stencil bits mismatch)");
3424 if (_mesa_is_gles3(ctx
)) {
3425 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3428 * "If SAMPLE_BUFFERS for the draw framebuffer is greater than zero,
3429 * an INVALID_OPERATION error is generated."
3431 if (drawFb
->Visual
.samples
> 0) {
3432 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3433 "glBlitFramebuffer(destination samples must be 0)");
3437 /* Page 194 (page 206 of the PDF) in section 4.3.2 of the OpenGL ES
3440 * "If SAMPLE_BUFFERS for the read framebuffer is greater than zero,
3441 * no copy is performed and an INVALID_OPERATION error is generated
3442 * if the formats of the read and draw framebuffers are not
3443 * identical or if the source and destination rectangles are not
3444 * defined with the same (X0, Y0) and (X1, Y1) bounds."
3446 * The format check was made above because desktop OpenGL has the same
3449 if (readFb
->Visual
.samples
> 0
3450 && (srcX0
!= dstX0
|| srcY0
!= dstY0
3451 || srcX1
!= dstX1
|| srcY1
!= dstY1
)) {
3452 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3453 "glBlitFramebuffer(bad src/dst multisample region)");
3457 if (readFb
->Visual
.samples
> 0 &&
3458 drawFb
->Visual
.samples
> 0 &&
3459 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
3460 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3461 "glBlitFramebufferEXT(mismatched samples)");
3465 /* extra checks for multisample copies... */
3466 if ((readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) &&
3467 (filter
== GL_NEAREST
|| filter
== GL_LINEAR
)) {
3468 /* src and dest region sizes must be the same */
3469 if (abs(srcX1
- srcX0
) != abs(dstX1
- dstX0
) ||
3470 abs(srcY1
- srcY0
) != abs(dstY1
- dstY0
)) {
3471 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3472 "glBlitFramebufferEXT(bad src/dst multisample region sizes)");
3480 const struct gl_renderbuffer
*colorReadRb
= readFb
->_ColorReadBuffer
;
3481 const struct gl_renderbuffer
*colorDrawRb
= NULL
;
3484 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
3486 srcX0
, srcY0
, srcX1
, srcY1
,
3487 dstX0
, dstY0
, dstX1
, dstY1
,
3490 const struct gl_renderbuffer_attachment
*att
;
3492 att
= find_attachment(readFb
, colorReadRb
);
3493 printf(" Src FBO %u RB %u (%dx%d) ",
3494 readFb
->Name
, colorReadRb
->Name
,
3495 colorReadRb
->Width
, colorReadRb
->Height
);
3496 if (att
&& att
->Texture
) {
3497 printf("Tex %u tgt 0x%x level %u face %u",
3499 att
->Texture
->Target
,
3505 /* Print all active color render buffers */
3506 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
3507 colorDrawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
3511 att
= find_attachment(drawFb
, colorDrawRb
);
3512 printf(" Dst FBO %u RB %u (%dx%d) ",
3513 drawFb
->Name
, colorDrawRb
->Name
,
3514 colorDrawRb
->Width
, colorDrawRb
->Height
);
3515 if (att
&& att
->Texture
) {
3516 printf("Tex %u tgt 0x%x level %u face %u",
3518 att
->Texture
->Target
,
3528 (srcX1
- srcX0
) == 0 || (srcY1
- srcY0
) == 0 ||
3529 (dstX1
- dstX0
) == 0 || (dstY1
- dstY0
) == 0) {
3533 ASSERT(ctx
->Driver
.BlitFramebuffer
);
3534 ctx
->Driver
.BlitFramebuffer(ctx
,
3535 srcX0
, srcY0
, srcX1
, srcY1
,
3536 dstX0
, dstY0
, dstX1
, dstY1
,
3542 invalidate_framebuffer_storage(GLenum target
, GLsizei numAttachments
,
3543 const GLenum
*attachments
, GLint x
, GLint y
,
3544 GLsizei width
, GLsizei height
, const char *name
)
3547 struct gl_framebuffer
*fb
;
3548 GET_CURRENT_CONTEXT(ctx
);
3550 fb
= get_framebuffer_target(ctx
, target
);
3552 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", name
);
3556 if (numAttachments
< 0) {
3557 _mesa_error(ctx
, GL_INVALID_VALUE
,
3558 "%s(numAttachments < 0)", name
);
3562 /* The GL_ARB_invalidate_subdata spec says:
3564 * "If an attachment is specified that does not exist in the
3565 * framebuffer bound to <target>, it is ignored."
3569 * "If <attachments> contains COLOR_ATTACHMENTm and m is greater than
3570 * or equal to the value of MAX_COLOR_ATTACHMENTS, then the error
3571 * INVALID_OPERATION is generated."
3573 * No mention is made of GL_AUXi being out of range. Therefore, we allow
3574 * any enum that can be allowed by the API (OpenGL ES 3.0 has a different
3575 * set of retrictions).
3577 for (i
= 0; i
< numAttachments
; i
++) {
3578 if (_mesa_is_winsys_fbo(fb
)) {
3579 switch (attachments
[i
]) {
3585 /* Accumulation buffers and auxilary buffers were removed in
3586 * OpenGL 3.1, and they never existed in OpenGL ES.
3588 if (ctx
->API
!= API_OPENGL_COMPAT
)
3598 case GL_FRONT_RIGHT
:
3599 if (!_mesa_is_desktop_gl(ctx
))
3606 switch (attachments
[i
]) {
3607 case GL_DEPTH_ATTACHMENT
:
3608 case GL_STENCIL_ATTACHMENT
:
3610 case GL_COLOR_ATTACHMENT0
:
3611 case GL_COLOR_ATTACHMENT1
:
3612 case GL_COLOR_ATTACHMENT2
:
3613 case GL_COLOR_ATTACHMENT3
:
3614 case GL_COLOR_ATTACHMENT4
:
3615 case GL_COLOR_ATTACHMENT5
:
3616 case GL_COLOR_ATTACHMENT6
:
3617 case GL_COLOR_ATTACHMENT7
:
3618 case GL_COLOR_ATTACHMENT8
:
3619 case GL_COLOR_ATTACHMENT9
:
3620 case GL_COLOR_ATTACHMENT10
:
3621 case GL_COLOR_ATTACHMENT11
:
3622 case GL_COLOR_ATTACHMENT12
:
3623 case GL_COLOR_ATTACHMENT13
:
3624 case GL_COLOR_ATTACHMENT14
:
3625 case GL_COLOR_ATTACHMENT15
: {
3626 unsigned k
= attachments
[i
] - GL_COLOR_ATTACHMENT0
;
3627 if (k
>= ctx
->Const
.MaxColorAttachments
) {
3628 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3629 "%s(attachment >= max. color attachments)", name
);
3640 /* We don't actually do anything for this yet. Just return after
3641 * validating the parameters and generating the required errors.
3646 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(attachment)", name
);
3651 _mesa_InvalidateSubFramebuffer(GLenum target
, GLsizei numAttachments
,
3652 const GLenum
*attachments
, GLint x
, GLint y
,
3653 GLsizei width
, GLsizei height
)
3655 invalidate_framebuffer_storage(target
, numAttachments
, attachments
,
3656 x
, y
, width
, height
,
3657 "glInvalidateSubFramebuffer");
3661 _mesa_InvalidateFramebuffer(GLenum target
, GLsizei numAttachments
,
3662 const GLenum
*attachments
)
3664 /* The GL_ARB_invalidate_subdata spec says:
3668 * void InvalidateFramebuffer(enum target,
3669 * sizei numAttachments,
3670 * const enum *attachments);
3672 * is equivalent to the command InvalidateSubFramebuffer with <x>, <y>,
3673 * <width>, <height> equal to 0, 0, <MAX_VIEWPORT_DIMS[0]>,
3674 * <MAX_VIEWPORT_DIMS[1]> respectively."
3676 invalidate_framebuffer_storage(target
, numAttachments
, attachments
,
3677 0, 0, MAX_VIEWPORT_WIDTH
, MAX_VIEWPORT_HEIGHT
,
3678 "glInvalidateFramebuffer");
3682 _mesa_DiscardFramebufferEXT(GLenum target
, GLsizei numAttachments
,
3683 const GLenum
*attachments
)
3685 struct gl_framebuffer
*fb
;
3688 GET_CURRENT_CONTEXT(ctx
);
3690 fb
= get_framebuffer_target(ctx
, target
);
3692 _mesa_error(ctx
, GL_INVALID_ENUM
,
3693 "glDiscardFramebufferEXT(target %s)",
3694 _mesa_lookup_enum_by_nr(target
));
3698 if (numAttachments
< 0) {
3699 _mesa_error(ctx
, GL_INVALID_VALUE
,
3700 "glDiscardFramebufferEXT(numAttachments < 0)");
3704 for (i
= 0; i
< numAttachments
; i
++) {
3705 switch (attachments
[i
]) {
3709 if (_mesa_is_user_fbo(fb
))
3712 case GL_COLOR_ATTACHMENT0
:
3713 case GL_DEPTH_ATTACHMENT
:
3714 case GL_STENCIL_ATTACHMENT
:
3715 if (_mesa_is_winsys_fbo(fb
))
3723 if (ctx
->Driver
.DiscardFramebuffer
)
3724 ctx
->Driver
.DiscardFramebuffer(ctx
, target
, numAttachments
, attachments
);
3729 _mesa_error(ctx
, GL_INVALID_ENUM
,
3730 "glDiscardFramebufferEXT(attachment %s)",
3731 _mesa_lookup_enum_by_nr(attachments
[i
]));