2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 1999-2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * GL_EXT/ARB_framebuffer_object extensions
40 #include "framebuffer.h"
43 #include "renderbuffer.h"
49 /** Set this to 1 to help debug FBO incompleteness problems */
52 /** Set this to 1 to debug/log glBlitFramebuffer() calls */
59 * None of the GL_EXT_framebuffer_object functions are compiled into
66 * When glGenRender/FramebuffersEXT() is called we insert pointers to
67 * these placeholder objects into the hash table.
68 * Later, when the object ID is first bound, we replace the placeholder
69 * with the real frame/renderbuffer.
71 static struct gl_framebuffer DummyFramebuffer
;
72 static struct gl_renderbuffer DummyRenderbuffer
;
75 #define IS_CUBE_FACE(TARGET) \
76 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
77 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
81 delete_dummy_renderbuffer(struct gl_renderbuffer
*rb
)
87 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
94 _mesa_init_fbobjects(GLcontext
*ctx
)
96 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
97 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
102 * Helper routine for getting a gl_renderbuffer.
104 struct gl_renderbuffer
*
105 _mesa_lookup_renderbuffer(GLcontext
*ctx
, GLuint id
)
107 struct gl_renderbuffer
*rb
;
112 rb
= (struct gl_renderbuffer
*)
113 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
119 * Helper routine for getting a gl_framebuffer.
121 struct gl_framebuffer
*
122 _mesa_lookup_framebuffer(GLcontext
*ctx
, GLuint id
)
124 struct gl_framebuffer
*fb
;
129 fb
= (struct gl_framebuffer
*)
130 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
136 * Mark the given framebuffer as invalid. This will force the
137 * test for framebuffer completeness to be done before the framebuffer
141 invalidate_framebuffer(struct gl_framebuffer
*fb
)
143 fb
->_Status
= 0; /* "indeterminate" */
148 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
149 * gl_renderbuffer_attachment object.
150 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
151 * the depth buffer attachment point.
153 struct gl_renderbuffer_attachment
*
154 _mesa_get_attachment(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
159 switch (attachment
) {
160 case GL_COLOR_ATTACHMENT0_EXT
:
161 case GL_COLOR_ATTACHMENT1_EXT
:
162 case GL_COLOR_ATTACHMENT2_EXT
:
163 case GL_COLOR_ATTACHMENT3_EXT
:
164 case GL_COLOR_ATTACHMENT4_EXT
:
165 case GL_COLOR_ATTACHMENT5_EXT
:
166 case GL_COLOR_ATTACHMENT6_EXT
:
167 case GL_COLOR_ATTACHMENT7_EXT
:
168 case GL_COLOR_ATTACHMENT8_EXT
:
169 case GL_COLOR_ATTACHMENT9_EXT
:
170 case GL_COLOR_ATTACHMENT10_EXT
:
171 case GL_COLOR_ATTACHMENT11_EXT
:
172 case GL_COLOR_ATTACHMENT12_EXT
:
173 case GL_COLOR_ATTACHMENT13_EXT
:
174 case GL_COLOR_ATTACHMENT14_EXT
:
175 case GL_COLOR_ATTACHMENT15_EXT
:
176 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
177 if (i
>= ctx
->Const
.MaxColorAttachments
) {
180 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
181 case GL_DEPTH_STENCIL_ATTACHMENT
:
183 case GL_DEPTH_BUFFER
:
184 /* fall-through / new in GL 3.0 */
185 case GL_DEPTH_ATTACHMENT_EXT
:
186 return &fb
->Attachment
[BUFFER_DEPTH
];
187 case GL_STENCIL_BUFFER
:
188 /* fall-through / new in GL 3.0 */
189 case GL_STENCIL_ATTACHMENT_EXT
:
190 return &fb
->Attachment
[BUFFER_STENCIL
];
198 * Remove any texture or renderbuffer attached to the given attachment
199 * point. Update reference counts, etc.
202 _mesa_remove_attachment(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
204 if (att
->Type
== GL_TEXTURE
) {
205 ASSERT(att
->Texture
);
206 if (ctx
->Driver
.FinishRenderTexture
) {
207 /* tell driver that we're done rendering to this texture. */
208 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
210 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
211 ASSERT(!att
->Texture
);
213 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
214 ASSERT(!att
->Texture
);
215 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
216 ASSERT(!att
->Renderbuffer
);
219 att
->Complete
= GL_TRUE
;
224 * Bind a texture object to an attachment point.
225 * The previous binding, if any, will be removed first.
228 _mesa_set_texture_attachment(GLcontext
*ctx
,
229 struct gl_framebuffer
*fb
,
230 struct gl_renderbuffer_attachment
*att
,
231 struct gl_texture_object
*texObj
,
232 GLenum texTarget
, GLuint level
, GLuint zoffset
)
234 if (att
->Texture
== texObj
) {
235 /* re-attaching same texture */
236 ASSERT(att
->Type
== GL_TEXTURE
);
237 if (ctx
->Driver
.FinishRenderTexture
)
238 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
242 if (ctx
->Driver
.FinishRenderTexture
&& att
->Texture
)
243 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
244 _mesa_remove_attachment(ctx
, att
);
245 att
->Type
= GL_TEXTURE
;
246 assert(!att
->Texture
);
247 _mesa_reference_texobj(&att
->Texture
, texObj
);
250 /* always update these fields */
251 att
->TextureLevel
= level
;
252 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
253 att
->Zoffset
= zoffset
;
254 att
->Complete
= GL_FALSE
;
256 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
257 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
260 invalidate_framebuffer(fb
);
265 * Bind a renderbuffer to an attachment point.
266 * The previous binding, if any, will be removed first.
269 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
270 struct gl_renderbuffer_attachment
*att
,
271 struct gl_renderbuffer
*rb
)
273 /* XXX check if re-doing same attachment, exit early */
274 _mesa_remove_attachment(ctx
, att
);
275 att
->Type
= GL_RENDERBUFFER_EXT
;
276 att
->Texture
= NULL
; /* just to be safe */
277 att
->Complete
= GL_FALSE
;
278 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
283 * Fallback for ctx->Driver.FramebufferRenderbuffer()
284 * Attach a renderbuffer object to a framebuffer object.
287 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
288 GLenum attachment
, struct gl_renderbuffer
*rb
)
290 struct gl_renderbuffer_attachment
*att
;
292 _glthread_LOCK_MUTEX(fb
->Mutex
);
294 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
297 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
298 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
299 /* do stencil attachment here (depth already done above) */
300 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
302 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
306 _mesa_remove_attachment(ctx
, att
);
309 invalidate_framebuffer(fb
);
311 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
319 att_incomplete(const char *msg
)
322 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
333 fbo_incomplete(const char *msg
, int index
)
336 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
347 * Test if an attachment point is complete and update its Complete field.
348 * \param format if GL_COLOR, this is a color attachment point,
349 * if GL_DEPTH, this is a depth component attachment point,
350 * if GL_STENCIL, this is a stencil component attachment point.
353 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
354 struct gl_renderbuffer_attachment
*att
)
356 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
358 /* assume complete */
359 att
->Complete
= GL_TRUE
;
361 /* Look for reasons why the attachment might be incomplete */
362 if (att
->Type
== GL_TEXTURE
) {
363 const struct gl_texture_object
*texObj
= att
->Texture
;
364 struct gl_texture_image
*texImage
;
368 att_incomplete("no texobj");
369 att
->Complete
= GL_FALSE
;
373 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
375 att_incomplete("no teximage");
376 att
->Complete
= GL_FALSE
;
379 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
380 att_incomplete("teximage width/height=0");
381 printf("texobj = %u\n", texObj
->Name
);
382 printf("level = %d\n", att
->TextureLevel
);
383 att
->Complete
= GL_FALSE
;
386 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
387 att_incomplete("bad z offset");
388 att
->Complete
= GL_FALSE
;
392 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
394 if (format
== GL_COLOR
) {
395 if (baseFormat
!= GL_RGB
&&
396 baseFormat
!= GL_RGBA
) {
397 att_incomplete("bad format");
398 att
->Complete
= GL_FALSE
;
401 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
402 att_incomplete("compressed internalformat");
403 att
->Complete
= GL_FALSE
;
407 else if (format
== GL_DEPTH
) {
408 if (baseFormat
== GL_DEPTH_COMPONENT
) {
411 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
412 ctx
->Extensions
.ARB_depth_texture
&&
413 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
417 att
->Complete
= GL_FALSE
;
418 att_incomplete("bad depth format");
423 ASSERT(format
== GL_STENCIL
);
424 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
425 ctx
->Extensions
.ARB_depth_texture
&&
426 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
430 /* no such thing as stencil-only textures */
431 att_incomplete("illegal stencil texture");
432 att
->Complete
= GL_FALSE
;
437 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
438 const GLenum baseFormat
=
439 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
441 ASSERT(att
->Renderbuffer
);
442 if (!att
->Renderbuffer
->InternalFormat
||
443 att
->Renderbuffer
->Width
< 1 ||
444 att
->Renderbuffer
->Height
< 1) {
445 att_incomplete("0x0 renderbuffer");
446 att
->Complete
= GL_FALSE
;
449 if (format
== GL_COLOR
) {
450 if (baseFormat
!= GL_RGB
&&
451 baseFormat
!= GL_RGBA
) {
452 att_incomplete("bad renderbuffer color format");
453 att
->Complete
= GL_FALSE
;
457 else if (format
== GL_DEPTH
) {
458 if (baseFormat
== GL_DEPTH_COMPONENT
) {
461 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
462 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
466 att_incomplete("bad renderbuffer depth format");
467 att
->Complete
= GL_FALSE
;
472 assert(format
== GL_STENCIL
);
473 if (baseFormat
== GL_STENCIL_INDEX
) {
476 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
477 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
481 att
->Complete
= GL_FALSE
;
482 att_incomplete("bad renderbuffer stencil format");
488 ASSERT(att
->Type
== GL_NONE
);
496 * Test if the given framebuffer object is complete and update its
497 * Status field with the results.
498 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
499 * driver to make hardware-specific validation/completeness checks.
500 * Also update the framebuffer's Width and Height fields if the
501 * framebuffer is complete.
504 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
507 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
508 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
509 GLint numSamples
= -1;
513 assert(fb
->Name
!= 0);
519 /* Start at -2 to more easily loop over all attachment points.
524 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
525 struct gl_renderbuffer_attachment
*att
;
529 * XXX for ARB_fbo, only check color buffers that are named by
530 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
533 /* check for attachment completeness
536 att
= &fb
->Attachment
[BUFFER_DEPTH
];
537 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
538 if (!att
->Complete
) {
539 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
540 fbo_incomplete("depth attachment incomplete", -1);
545 att
= &fb
->Attachment
[BUFFER_STENCIL
];
546 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
547 if (!att
->Complete
) {
548 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
549 fbo_incomplete("stencil attachment incomplete", -1);
554 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
555 test_attachment_completeness(ctx
, GL_COLOR
, att
);
556 if (!att
->Complete
) {
557 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
558 fbo_incomplete("color attachment incomplete", i
);
563 /* get width, height, format of the renderbuffer/texture
565 if (att
->Type
== GL_TEXTURE
) {
566 const struct gl_texture_image
*texImg
567 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
568 minWidth
= MIN2(minWidth
, texImg
->Width
);
569 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
570 minHeight
= MIN2(minHeight
, texImg
->Height
);
571 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
572 f
= texImg
->_BaseFormat
;
574 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
575 && f
!= GL_DEPTH_STENCIL_EXT
) {
576 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
577 fbo_incomplete("texture attachment incomplete", -1);
581 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
582 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
583 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
584 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
585 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
586 f
= att
->Renderbuffer
->InternalFormat
;
590 assert(att
->Type
== GL_NONE
);
594 if (numSamples
< 0) {
596 numSamples
= att
->Renderbuffer
->NumSamples
;
599 /* Error-check width, height, format, samples
601 if (numImages
== 1) {
602 /* save format, num samples */
608 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
609 /* check that width, height, format are same */
610 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
611 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
612 fbo_incomplete("width or height mismatch", -1);
615 /* check that all color buffer have same format */
616 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
617 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
618 fbo_incomplete("format mismatch", -1);
622 if (att
->Renderbuffer
&&
623 att
->Renderbuffer
->NumSamples
!= numSamples
) {
624 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
625 fbo_incomplete("inconsistant number of samples", i
);
633 if (ctx
->API
== API_OPENGL
) {
634 /* Check that all DrawBuffers are present */
635 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
636 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
637 const struct gl_renderbuffer_attachment
*att
638 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
640 if (att
->Type
== GL_NONE
) {
641 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
642 fbo_incomplete("missing drawbuffer", j
);
648 /* Check that the ReadBuffer is present */
649 if (fb
->ColorReadBuffer
!= GL_NONE
) {
650 const struct gl_renderbuffer_attachment
*att
651 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
653 if (att
->Type
== GL_NONE
) {
654 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
655 fbo_incomplete("missing readbuffer", -1);
664 if (numImages
== 0) {
665 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
666 fbo_incomplete("no attachments", -1);
670 /* Provisionally set status = COMPLETE ... */
671 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
673 /* ... but the driver may say the FB is incomplete.
674 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
677 if (ctx
->Driver
.ValidateFramebuffer
) {
678 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
679 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
680 fbo_incomplete("driver marked FBO as incomplete", -1);
684 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
686 * Note that if ARB_framebuffer_object is supported and the attached
687 * renderbuffers/textures are different sizes, the framebuffer
688 * width/height will be set to the smallest width/height.
690 fb
->Width
= minWidth
;
691 fb
->Height
= minHeight
;
693 /* finally, update the visual info for the framebuffer */
694 _mesa_update_framebuffer_visual(fb
);
700 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
702 GET_CURRENT_CONTEXT(ctx
);
703 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
705 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
706 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
714 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
716 struct gl_renderbuffer
*newRb
;
717 GET_CURRENT_CONTEXT(ctx
);
719 ASSERT_OUTSIDE_BEGIN_END(ctx
);
721 if (target
!= GL_RENDERBUFFER_EXT
) {
722 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
726 /* No need to flush here since the render buffer binding has no
727 * effect on rendering state.
731 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
732 if (newRb
== &DummyRenderbuffer
) {
733 /* ID was reserved, but no real renderbuffer object made yet */
736 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
737 /* All RB IDs must be Gen'd */
738 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
743 /* create new renderbuffer object */
744 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
746 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
749 ASSERT(newRb
->AllocStorage
);
750 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
751 newRb
->RefCount
= 1; /* referenced by hash table */
758 ASSERT(newRb
!= &DummyRenderbuffer
);
760 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
765 * If the given renderbuffer is anywhere attached to the framebuffer, detach
767 * This is used when a renderbuffer object is deleted.
768 * The spec calls for unbinding.
771 detach_renderbuffer(GLcontext
*ctx
,
772 struct gl_framebuffer
*fb
,
773 struct gl_renderbuffer
*rb
)
776 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
777 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
778 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
781 invalidate_framebuffer(fb
);
786 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
789 GET_CURRENT_CONTEXT(ctx
);
791 ASSERT_OUTSIDE_BEGIN_END(ctx
);
792 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
794 for (i
= 0; i
< n
; i
++) {
795 if (renderbuffers
[i
] > 0) {
796 struct gl_renderbuffer
*rb
;
797 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
799 /* check if deleting currently bound renderbuffer object */
800 if (rb
== ctx
->CurrentRenderbuffer
) {
802 ASSERT(rb
->RefCount
>= 2);
803 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
806 if (ctx
->DrawBuffer
->Name
) {
807 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
809 if (ctx
->ReadBuffer
->Name
&& ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
810 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
813 /* Remove from hash table immediately, to free the ID.
814 * But the object will not be freed until it's no longer
815 * referenced anywhere else.
817 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
819 if (rb
!= &DummyRenderbuffer
) {
820 /* no longer referenced by hash table */
821 _mesa_reference_renderbuffer(&rb
, NULL
);
830 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
832 GET_CURRENT_CONTEXT(ctx
);
836 ASSERT_OUTSIDE_BEGIN_END(ctx
);
839 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
846 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
848 for (i
= 0; i
< n
; i
++) {
849 GLuint name
= first
+ i
;
850 renderbuffers
[i
] = name
;
851 /* insert dummy placeholder into hash table */
852 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
853 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
854 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
860 * Given an internal format token for a render buffer, return the
861 * corresponding base format.
862 * This is very similar to _mesa_base_tex_format() but the set of valid
863 * internal formats is somewhat different.
865 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
866 * GL_DEPTH_STENCIL_EXT or zero if error.
868 * XXX in the future when we support red-only and red-green formats
869 * we'll also return GL_RED and GL_RG.
872 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
874 switch (internalFormat
) {
892 case GL_RGBA16_SNORM
:
894 case GL_STENCIL_INDEX
:
895 case GL_STENCIL_INDEX1_EXT
:
896 case GL_STENCIL_INDEX4_EXT
:
897 case GL_STENCIL_INDEX8_EXT
:
898 case GL_STENCIL_INDEX16_EXT
:
899 return GL_STENCIL_INDEX
;
900 case GL_DEPTH_COMPONENT
:
901 case GL_DEPTH_COMPONENT16
:
902 case GL_DEPTH_COMPONENT24
:
903 case GL_DEPTH_COMPONENT32
:
904 return GL_DEPTH_COMPONENT
;
905 case GL_DEPTH_STENCIL_EXT
:
906 case GL_DEPTH24_STENCIL8_EXT
:
907 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
908 return GL_DEPTH_STENCIL_EXT
;
911 /* XXX add floating point formats eventually */
918 /** sentinal value, see below */
919 #define NO_SAMPLES 1000
923 * Helper function used by _mesa_RenderbufferStorageEXT() and
924 * _mesa_RenderbufferStorageMultisample().
925 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
928 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
929 GLsizei width
, GLsizei height
, GLsizei samples
)
931 const char *func
= samples
== NO_SAMPLES
?
932 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
933 struct gl_renderbuffer
*rb
;
935 GET_CURRENT_CONTEXT(ctx
);
937 ASSERT_OUTSIDE_BEGIN_END(ctx
);
939 if (target
!= GL_RENDERBUFFER_EXT
) {
940 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
944 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
945 if (baseFormat
== 0) {
946 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
950 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
951 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
955 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
956 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
960 if (samples
== NO_SAMPLES
) {
961 /* NumSamples == 0 indicates non-multisampling */
964 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
965 /* note: driver may choose to use more samples than what's requested */
966 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
970 rb
= ctx
->CurrentRenderbuffer
;
972 _mesa_error(ctx
, GL_INVALID_OPERATION
, func
);
976 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
978 if (rb
->InternalFormat
== internalFormat
&&
979 rb
->Width
== (GLuint
) width
&&
980 rb
->Height
== (GLuint
) height
) {
981 /* no change in allocation needed */
985 /* These MUST get set by the AllocStorage func */
986 rb
->Format
= MESA_FORMAT_NONE
;
987 rb
->NumSamples
= samples
;
989 /* Now allocate the storage */
990 ASSERT(rb
->AllocStorage
);
991 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
992 /* No error - check/set fields now */
993 assert(rb
->Format
!= MESA_FORMAT_NONE
);
994 assert(rb
->Width
== (GLuint
) width
);
995 assert(rb
->Height
== (GLuint
) height
);
996 rb
->InternalFormat
= internalFormat
;
997 rb
->_BaseFormat
= baseFormat
;
998 assert(rb
->_BaseFormat
!= 0);
1001 /* Probably ran out of memory - clear the fields */
1004 rb
->Format
= MESA_FORMAT_NONE
;
1005 rb
->InternalFormat
= GL_NONE
;
1006 rb
->_BaseFormat
= GL_NONE
;
1011 test_framebuffer_completeness(ctx, fb);
1013 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
1018 #if FEATURE_OES_EGL_image
1020 _mesa_EGLImageTargetRenderbufferStorageOES (GLenum target
, GLeglImageOES image
)
1022 struct gl_renderbuffer
*rb
;
1023 GET_CURRENT_CONTEXT(ctx
);
1024 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1026 if (!ctx
->Extensions
.OES_EGL_image
) {
1027 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1028 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1032 if (target
!= GL_RENDERBUFFER
) {
1033 _mesa_error(ctx
, GL_INVALID_ENUM
, "EGLImageTargetRenderbufferStorageOES");
1037 rb
= ctx
->CurrentRenderbuffer
;
1039 _mesa_error(ctx
, GL_INVALID_OPERATION
, "EGLImageTargetRenderbufferStorageOES");
1043 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1045 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1050 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1051 * _mesa_GetFramebufferAttachmentParameterivEXT()
1052 * We have to be careful to respect the base format. For example, if a
1053 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1054 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1055 * we need to return zero.
1058 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1061 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1062 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1063 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1064 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1065 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1066 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1067 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1068 return _mesa_get_format_bits(format
, pname
);
1071 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1072 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1073 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
)
1074 return _mesa_get_format_bits(format
, pname
);
1077 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1078 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1079 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1080 return _mesa_get_format_bits(format
, pname
);
1083 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1084 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1085 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1086 return _mesa_get_format_bits(format
, pname
);
1097 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1098 GLsizei width
, GLsizei height
)
1100 /* GL_ARB_fbo says calling this function is equivalent to calling
1101 * glRenderbufferStorageMultisample() with samples=0. We pass in
1102 * a token value here just for error reporting purposes.
1104 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1109 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1110 GLenum internalFormat
,
1111 GLsizei width
, GLsizei height
)
1113 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1117 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1118 GLsizei width
, GLsizei height
)
1120 switch (internalFormat
) {
1122 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1123 /* choose a closest format */
1124 internalFormat
= GL_RGB5
;
1130 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1134 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1136 struct gl_renderbuffer
*rb
;
1137 GET_CURRENT_CONTEXT(ctx
);
1139 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1141 if (target
!= GL_RENDERBUFFER_EXT
) {
1142 _mesa_error(ctx
, GL_INVALID_ENUM
,
1143 "glGetRenderbufferParameterivEXT(target)");
1147 rb
= ctx
->CurrentRenderbuffer
;
1149 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1150 "glGetRenderbufferParameterivEXT");
1154 /* No need to flush here since we're just quering state which is
1155 * not effected by rendering.
1159 case GL_RENDERBUFFER_WIDTH_EXT
:
1160 *params
= rb
->Width
;
1162 case GL_RENDERBUFFER_HEIGHT_EXT
:
1163 *params
= rb
->Height
;
1165 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1166 *params
= rb
->InternalFormat
;
1168 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1169 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1170 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1171 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1172 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1173 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1174 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1176 case GL_RENDERBUFFER_SAMPLES
:
1177 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1178 *params
= rb
->NumSamples
;
1183 _mesa_error(ctx
, GL_INVALID_ENUM
,
1184 "glGetRenderbufferParameterivEXT(target)");
1190 GLboolean GLAPIENTRY
1191 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1193 GET_CURRENT_CONTEXT(ctx
);
1194 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1196 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1197 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1205 * Check if any of the attachments of the given framebuffer are textures
1206 * (render to texture). Call ctx->Driver.RenderTexture() for such
1210 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
1213 ASSERT(ctx
->Driver
.RenderTexture
);
1216 return; /* can't render to texture with winsys framebuffers */
1218 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1219 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1220 struct gl_texture_object
*texObj
= att
->Texture
;
1222 && texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
1223 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1230 * Examine all the framebuffer's attachments to see if any are textures.
1231 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1232 * notify the device driver that the texture image may have changed.
1235 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
1238 return; /* can't render to texture with winsys framebuffers */
1240 if (ctx
->Driver
.FinishRenderTexture
) {
1242 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1243 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1244 if (att
->Texture
&& att
->Renderbuffer
) {
1245 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1253 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1255 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1256 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1257 GLboolean bindReadBuf
, bindDrawBuf
;
1258 GET_CURRENT_CONTEXT(ctx
);
1261 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1262 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1263 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1267 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1269 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1270 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1271 "glBindFramebufferEXT(unsupported)");
1276 #if FEATURE_EXT_framebuffer_blit
1277 case GL_DRAW_FRAMEBUFFER_EXT
:
1278 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1279 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1282 bindDrawBuf
= GL_TRUE
;
1283 bindReadBuf
= GL_FALSE
;
1285 case GL_READ_FRAMEBUFFER_EXT
:
1286 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1287 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1290 bindDrawBuf
= GL_FALSE
;
1291 bindReadBuf
= GL_TRUE
;
1294 case GL_FRAMEBUFFER_EXT
:
1295 bindDrawBuf
= GL_TRUE
;
1296 bindReadBuf
= GL_TRUE
;
1299 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1304 /* Binding a user-created framebuffer object */
1305 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1306 if (newDrawFb
== &DummyFramebuffer
) {
1307 /* ID was reserved, but no real framebuffer object made yet */
1310 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1311 /* All FBO IDs must be Gen'd */
1312 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1317 /* create new framebuffer object */
1318 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1320 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1323 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1325 newReadFb
= newDrawFb
;
1328 /* Binding the window system framebuffer (which was originally set
1329 * with MakeCurrent).
1331 newDrawFb
= ctx
->WinSysDrawBuffer
;
1332 newReadFb
= ctx
->WinSysReadBuffer
;
1336 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1338 /* save pointers to current/old framebuffers */
1339 oldDrawFb
= ctx
->DrawBuffer
;
1340 oldReadFb
= ctx
->ReadBuffer
;
1342 /* check if really changing bindings */
1343 if (oldDrawFb
== newDrawFb
)
1344 bindDrawBuf
= GL_FALSE
;
1345 if (oldReadFb
== newReadFb
)
1346 bindReadBuf
= GL_FALSE
;
1349 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1351 * We also check if we're beginning and/or ending render-to-texture.
1352 * When a framebuffer with texture attachments is unbound, call
1353 * ctx->Driver.FinishRenderTexture().
1354 * When a framebuffer with texture attachments is bound, call
1355 * ctx->Driver.RenderTexture().
1357 * Note that if the ReadBuffer has texture attachments we don't consider
1358 * that a render-to-texture case.
1361 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1363 /* check if old readbuffer was render-to-texture */
1364 check_end_texture_render(ctx
, oldReadFb
);
1366 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1370 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1372 /* check if old read/draw buffers were render-to-texture */
1374 check_end_texture_render(ctx
, oldReadFb
);
1376 if (oldDrawFb
!= oldReadFb
)
1377 check_end_texture_render(ctx
, oldDrawFb
);
1379 /* check if newly bound framebuffer has any texture attachments */
1380 check_begin_texture_render(ctx
, newDrawFb
);
1382 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1385 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1386 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1392 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1395 GET_CURRENT_CONTEXT(ctx
);
1397 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1398 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1400 for (i
= 0; i
< n
; i
++) {
1401 if (framebuffers
[i
] > 0) {
1402 struct gl_framebuffer
*fb
;
1403 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1405 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1407 /* check if deleting currently bound framebuffer object */
1408 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1409 /* separate draw/read binding points */
1410 if (fb
== ctx
->DrawBuffer
) {
1412 ASSERT(fb
->RefCount
>= 2);
1413 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1415 if (fb
== ctx
->ReadBuffer
) {
1417 ASSERT(fb
->RefCount
>= 2);
1418 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1422 /* only one binding point for read/draw buffers */
1423 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1425 ASSERT(fb
->RefCount
>= 2);
1426 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1430 /* remove from hash table immediately, to free the ID */
1431 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1433 if (fb
!= &DummyFramebuffer
) {
1434 /* But the object will not be freed until it's no longer
1435 * bound in any context.
1437 _mesa_reference_framebuffer(&fb
, NULL
);
1446 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1448 GET_CURRENT_CONTEXT(ctx
);
1452 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1455 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1462 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1464 for (i
= 0; i
< n
; i
++) {
1465 GLuint name
= first
+ i
;
1466 framebuffers
[i
] = name
;
1467 /* insert dummy placeholder into hash table */
1468 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1469 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1470 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1477 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1479 struct gl_framebuffer
*buffer
;
1480 GET_CURRENT_CONTEXT(ctx
);
1482 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1485 #if FEATURE_EXT_framebuffer_blit
1486 case GL_DRAW_FRAMEBUFFER_EXT
:
1487 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1488 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1491 buffer
= ctx
->DrawBuffer
;
1493 case GL_READ_FRAMEBUFFER_EXT
:
1494 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1495 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1498 buffer
= ctx
->ReadBuffer
;
1501 case GL_FRAMEBUFFER_EXT
:
1502 buffer
= ctx
->DrawBuffer
;
1505 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1506 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1509 if (buffer
->Name
== 0) {
1510 /* The window system / default framebuffer is always complete */
1511 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1514 /* No need to flush here */
1516 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1517 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1520 return buffer
->_Status
;
1526 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1529 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1530 GLenum attachment
, GLenum textarget
, GLuint texture
,
1531 GLint level
, GLint zoffset
)
1533 struct gl_renderbuffer_attachment
*att
;
1534 struct gl_texture_object
*texObj
= NULL
;
1535 struct gl_framebuffer
*fb
;
1536 GLboolean error
= GL_FALSE
;
1538 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1541 case GL_READ_FRAMEBUFFER_EXT
:
1542 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1543 fb
= ctx
->ReadBuffer
;
1545 case GL_DRAW_FRAMEBUFFER_EXT
:
1546 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1548 case GL_FRAMEBUFFER_EXT
:
1549 fb
= ctx
->DrawBuffer
;
1556 _mesa_error(ctx
, GL_INVALID_ENUM
,
1557 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1563 /* check framebuffer binding */
1564 if (fb
->Name
== 0) {
1565 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1566 "glFramebufferTexture%sEXT", caller
);
1571 /* The textarget, level, and zoffset parameters are only validated if
1572 * texture is non-zero.
1575 GLboolean err
= GL_TRUE
;
1577 texObj
= _mesa_lookup_texture(ctx
, texture
);
1578 if (texObj
!= NULL
) {
1579 if (textarget
== 0) {
1580 /* XXX what's the purpose of this? */
1581 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1582 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1583 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1586 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1587 ? !IS_CUBE_FACE(textarget
)
1588 : (texObj
->Target
!= textarget
);
1592 /* can't render to a non-existant texture */
1593 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1594 "glFramebufferTexture%sEXT(non existant texture)",
1600 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1601 "glFramebufferTexture%sEXT(texture target mismatch)",
1606 if (texObj
->Target
== GL_TEXTURE_3D
) {
1607 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1608 if (zoffset
< 0 || zoffset
>= maxSize
) {
1609 _mesa_error(ctx
, GL_INVALID_VALUE
,
1610 "glFramebufferTexture%sEXT(zoffset)", caller
);
1614 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1615 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1616 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1617 _mesa_error(ctx
, GL_INVALID_VALUE
,
1618 "glFramebufferTexture%sEXT(layer)", caller
);
1624 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1625 _mesa_error(ctx
, GL_INVALID_VALUE
,
1626 "glFramebufferTexture%sEXT(level)", caller
);
1631 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1633 _mesa_error(ctx
, GL_INVALID_ENUM
,
1634 "glFramebufferTexture%sEXT(attachment)", caller
);
1638 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1640 _glthread_LOCK_MUTEX(fb
->Mutex
);
1642 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1644 /* Set the render-to-texture flag. We'll check this flag in
1645 * glTexImage() and friends to determine if we need to revalidate
1646 * any FBOs that might be rendering into this texture.
1647 * This flag never gets cleared since it's non-trivial to determine
1648 * when all FBOs might be done rendering to this texture. That's OK
1649 * though since it's uncommon to render to a texture then repeatedly
1650 * call glTexImage() to change images in the texture.
1652 texObj
->_RenderToTexture
= GL_TRUE
;
1655 _mesa_remove_attachment(ctx
, att
);
1658 invalidate_framebuffer(fb
);
1660 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1666 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1667 GLenum textarget
, GLuint texture
, GLint level
)
1669 GET_CURRENT_CONTEXT(ctx
);
1671 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1672 _mesa_error(ctx
, GL_INVALID_ENUM
,
1673 "glFramebufferTexture1DEXT(textarget)");
1677 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1683 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1684 GLenum textarget
, GLuint texture
, GLint level
)
1686 GET_CURRENT_CONTEXT(ctx
);
1688 if ((texture
!= 0) &&
1689 (textarget
!= GL_TEXTURE_2D
) &&
1690 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1691 (!IS_CUBE_FACE(textarget
))) {
1692 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1693 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
1697 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1703 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1704 GLenum textarget
, GLuint texture
,
1705 GLint level
, GLint zoffset
)
1707 GET_CURRENT_CONTEXT(ctx
);
1709 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1710 _mesa_error(ctx
, GL_INVALID_ENUM
,
1711 "glFramebufferTexture3DEXT(textarget)");
1715 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1721 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1722 GLuint texture
, GLint level
, GLint layer
)
1724 GET_CURRENT_CONTEXT(ctx
);
1726 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1732 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1733 GLenum renderbufferTarget
,
1734 GLuint renderbuffer
)
1736 struct gl_renderbuffer_attachment
*att
;
1737 struct gl_framebuffer
*fb
;
1738 struct gl_renderbuffer
*rb
;
1739 GET_CURRENT_CONTEXT(ctx
);
1741 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1744 #if FEATURE_EXT_framebuffer_blit
1745 case GL_DRAW_FRAMEBUFFER_EXT
:
1746 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1747 _mesa_error(ctx
, GL_INVALID_ENUM
,
1748 "glFramebufferRenderbufferEXT(target)");
1751 fb
= ctx
->DrawBuffer
;
1753 case GL_READ_FRAMEBUFFER_EXT
:
1754 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1755 _mesa_error(ctx
, GL_INVALID_ENUM
,
1756 "glFramebufferRenderbufferEXT(target)");
1759 fb
= ctx
->ReadBuffer
;
1762 case GL_FRAMEBUFFER_EXT
:
1763 fb
= ctx
->DrawBuffer
;
1766 _mesa_error(ctx
, GL_INVALID_ENUM
,
1767 "glFramebufferRenderbufferEXT(target)");
1771 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1772 _mesa_error(ctx
, GL_INVALID_ENUM
,
1773 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1777 if (fb
->Name
== 0) {
1778 /* Can't attach new renderbuffers to a window system framebuffer */
1779 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1783 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1785 _mesa_error(ctx
, GL_INVALID_ENUM
,
1786 "glFramebufferRenderbufferEXT(invalid attachment %s)",
1787 _mesa_lookup_enum_by_nr(attachment
));
1792 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1794 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1795 "glFramebufferRenderbufferEXT(non-existant"
1796 " renderbuffer %u)", renderbuffer
);
1801 /* remove renderbuffer attachment */
1805 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
1806 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
1807 /* make sure the renderbuffer is a depth/stencil format */
1808 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
1809 if (baseFormat
!= GL_DEPTH_STENCIL
) {
1810 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1811 "glFramebufferRenderbufferEXT(renderbuffer"
1812 " is not DEPTH_STENCIL format)");
1818 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1820 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1821 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1823 /* Some subsequent GL commands may depend on the framebuffer's visual
1824 * after the binding is updated. Update visual info now.
1826 _mesa_update_framebuffer_visual(fb
);
1831 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1832 GLenum pname
, GLint
*params
)
1834 const struct gl_renderbuffer_attachment
*att
;
1835 struct gl_framebuffer
*buffer
;
1836 GET_CURRENT_CONTEXT(ctx
);
1838 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1841 #if FEATURE_EXT_framebuffer_blit
1842 case GL_DRAW_FRAMEBUFFER_EXT
:
1843 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1844 _mesa_error(ctx
, GL_INVALID_ENUM
,
1845 "glGetFramebufferAttachmentParameterivEXT(target)");
1848 buffer
= ctx
->DrawBuffer
;
1850 case GL_READ_FRAMEBUFFER_EXT
:
1851 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1852 _mesa_error(ctx
, GL_INVALID_ENUM
,
1853 "glGetFramebufferAttachmentParameterivEXT(target)");
1856 buffer
= ctx
->ReadBuffer
;
1859 case GL_FRAMEBUFFER_EXT
:
1860 buffer
= ctx
->DrawBuffer
;
1863 _mesa_error(ctx
, GL_INVALID_ENUM
,
1864 "glGetFramebufferAttachmentParameterivEXT(target)");
1868 if (buffer
->Name
== 0) {
1869 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1870 "glGetFramebufferAttachmentParameterivEXT");
1874 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1876 _mesa_error(ctx
, GL_INVALID_ENUM
,
1877 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1881 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
1882 /* the depth and stencil attachments must point to the same buffer */
1883 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
1884 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
1885 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
1886 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
1887 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1888 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
1889 " attachments differ)");
1894 /* No need to flush here */
1897 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1898 *params
= att
->Type
;
1900 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1901 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1902 *params
= att
->Renderbuffer
->Name
;
1904 else if (att
->Type
== GL_TEXTURE
) {
1905 *params
= att
->Texture
->Name
;
1908 _mesa_error(ctx
, GL_INVALID_ENUM
,
1909 "glGetFramebufferAttachmentParameterivEXT(pname)");
1912 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1913 if (att
->Type
== GL_TEXTURE
) {
1914 *params
= att
->TextureLevel
;
1917 _mesa_error(ctx
, GL_INVALID_ENUM
,
1918 "glGetFramebufferAttachmentParameterivEXT(pname)");
1921 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1922 if (att
->Type
== GL_TEXTURE
) {
1923 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
1924 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1931 _mesa_error(ctx
, GL_INVALID_ENUM
,
1932 "glGetFramebufferAttachmentParameterivEXT(pname)");
1935 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1936 if (att
->Type
== GL_TEXTURE
) {
1937 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
1938 *params
= att
->Zoffset
;
1945 _mesa_error(ctx
, GL_INVALID_ENUM
,
1946 "glGetFramebufferAttachmentParameterivEXT(pname)");
1949 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
1950 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1951 _mesa_error(ctx
, GL_INVALID_ENUM
,
1952 "glGetFramebufferAttachmentParameterivEXT(pname)");
1955 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
1958 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
1959 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1960 _mesa_error(ctx
, GL_INVALID_ENUM
,
1961 "glGetFramebufferAttachmentParameterivEXT(pname)");
1965 gl_format format
= att
->Renderbuffer
->Format
;
1966 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
1971 *params
= _mesa_get_format_datatype(format
);
1975 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1976 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1977 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1978 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1979 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1980 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1981 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1982 _mesa_error(ctx
, GL_INVALID_ENUM
,
1983 "glGetFramebufferAttachmentParameterivEXT(pname)");
1985 else if (att
->Texture
) {
1986 const struct gl_texture_image
*texImage
=
1987 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
1990 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
1991 texImage
->TexFormat
);
1997 else if (att
->Renderbuffer
) {
1998 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
1999 att
->Renderbuffer
->Format
);
2006 _mesa_error(ctx
, GL_INVALID_ENUM
,
2007 "glGetFramebufferAttachmentParameterivEXT(pname)");
2014 _mesa_GenerateMipmapEXT(GLenum target
)
2016 struct gl_texture_object
*texObj
;
2017 GET_CURRENT_CONTEXT(ctx
);
2019 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2020 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2026 case GL_TEXTURE_CUBE_MAP
:
2027 /* OK, legal value */
2030 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2034 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2036 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2041 _mesa_lock_texture(ctx
, texObj
);
2042 if (target
== GL_TEXTURE_CUBE_MAP
) {
2044 for (face
= 0; face
< 6; face
++)
2045 ctx
->Driver
.GenerateMipmap(ctx
,
2046 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2050 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2052 _mesa_unlock_texture(ctx
, texObj
);
2056 #if FEATURE_EXT_framebuffer_blit
2058 static const struct gl_renderbuffer_attachment
*
2059 find_attachment(const struct gl_framebuffer
*fb
, const struct gl_renderbuffer
*rb
)
2062 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2063 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2064 return &fb
->Attachment
[i
];
2072 * Blit rectangular region, optionally from one framebuffer to another.
2074 * Note, if the src buffer is multisampled and the dest is not, this is
2075 * when the samples must be resolved to a single color.
2078 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2079 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2080 GLbitfield mask
, GLenum filter
)
2082 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2083 GL_DEPTH_BUFFER_BIT
|
2084 GL_STENCIL_BUFFER_BIT
);
2085 const struct gl_framebuffer
*readFb
, *drawFb
;
2086 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2087 GET_CURRENT_CONTEXT(ctx
);
2089 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2090 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2092 if (ctx
->NewState
) {
2093 _mesa_update_state(ctx
);
2096 readFb
= ctx
->ReadBuffer
;
2097 drawFb
= ctx
->DrawBuffer
;
2099 if (!readFb
|| !drawFb
) {
2100 /* This will normally never happen but someday we may want to
2101 * support MakeCurrent() with no drawables.
2106 /* check for complete framebuffers */
2107 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2108 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2109 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2110 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2114 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2115 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2119 if (mask
& ~legalMaskBits
) {
2120 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2124 /* depth/stencil must be blitted with nearest filtering */
2125 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2126 && filter
!= GL_NEAREST
) {
2127 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2128 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
2132 /* get color read/draw renderbuffers */
2133 if (mask
& GL_COLOR_BUFFER_BIT
) {
2134 colorReadRb
= readFb
->_ColorReadBuffer
;
2135 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2138 colorReadRb
= colorDrawRb
= NULL
;
2141 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2142 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2143 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2146 _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2147 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2148 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2149 "glBlitFramebufferEXT(stencil buffer size mismatch");
2154 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2155 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2156 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2159 _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2160 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2161 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2162 "glBlitFramebufferEXT(depth buffer size mismatch");
2167 if (readFb
->Visual
.samples
> 0 &&
2168 drawFb
->Visual
.samples
> 0 &&
2169 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2170 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2171 "glBlitFramebufferEXT(mismatched samples");
2175 /* extra checks for multisample copies... */
2176 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2177 /* src and dest region sizes must be the same */
2178 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2179 srcY1
- srcY0
!= dstY1
- dstY0
) {
2180 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2181 "glBlitFramebufferEXT(bad src/dst multisample region sizes");
2185 /* color formats must match */
2188 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2189 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2190 "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
2195 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2196 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2202 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2204 srcX0
, srcY0
, srcX1
, srcY1
,
2205 dstX0
, dstY0
, dstX1
, dstY1
,
2208 const struct gl_renderbuffer_attachment
*att
;
2210 att
= find_attachment(readFb
, colorReadRb
);
2211 printf(" Src FBO %u RB %u (%dx%d) ",
2212 readFb
->Name
, colorReadRb
->Name
,
2213 colorReadRb
->Width
, colorReadRb
->Height
);
2214 if (att
&& att
->Texture
) {
2215 printf("Tex %u tgt 0x%x level %u face %u",
2217 att
->Texture
->Target
,
2223 att
= find_attachment(drawFb
, colorDrawRb
);
2224 printf(" Dst FBO %u RB %u (%dx%d) ",
2225 drawFb
->Name
, colorDrawRb
->Name
,
2226 colorDrawRb
->Width
, colorDrawRb
->Height
);
2227 if (att
&& att
->Texture
) {
2228 printf("Tex %u tgt 0x%x level %u face %u",
2230 att
->Texture
->Target
,
2238 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2239 ctx
->Driver
.BlitFramebuffer(ctx
,
2240 srcX0
, srcY0
, srcX1
, srcY1
,
2241 dstX0
, dstY0
, dstX1
, dstY1
,
2244 #endif /* FEATURE_EXT_framebuffer_blit */