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
);
632 #if !FEATURE_OES_framebuffer_object
633 /* Check that all DrawBuffers are present */
634 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
635 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
636 const struct gl_renderbuffer_attachment
*att
637 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
639 if (att
->Type
== GL_NONE
) {
640 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
641 fbo_incomplete("missing drawbuffer", j
);
647 /* Check that the ReadBuffer is present */
648 if (fb
->ColorReadBuffer
!= GL_NONE
) {
649 const struct gl_renderbuffer_attachment
*att
650 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
652 if (att
->Type
== GL_NONE
) {
653 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
654 fbo_incomplete("missing readbuffer", -1);
662 if (numImages
== 0) {
663 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
664 fbo_incomplete("no attachments", -1);
668 /* Provisionally set status = COMPLETE ... */
669 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
671 /* ... but the driver may say the FB is incomplete.
672 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
675 if (ctx
->Driver
.ValidateFramebuffer
) {
676 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
677 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
678 fbo_incomplete("driver marked FBO as incomplete", -1);
682 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
684 * Note that if ARB_framebuffer_object is supported and the attached
685 * renderbuffers/textures are different sizes, the framebuffer
686 * width/height will be set to the smallest width/height.
688 fb
->Width
= minWidth
;
689 fb
->Height
= minHeight
;
691 /* finally, update the visual info for the framebuffer */
692 _mesa_update_framebuffer_visual(fb
);
698 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
700 GET_CURRENT_CONTEXT(ctx
);
701 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
703 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
704 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
712 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
714 struct gl_renderbuffer
*newRb
;
715 GET_CURRENT_CONTEXT(ctx
);
717 ASSERT_OUTSIDE_BEGIN_END(ctx
);
719 if (target
!= GL_RENDERBUFFER_EXT
) {
720 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
724 /* No need to flush here since the render buffer binding has no
725 * effect on rendering state.
729 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
730 if (newRb
== &DummyRenderbuffer
) {
731 /* ID was reserved, but no real renderbuffer object made yet */
734 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
735 /* All RB IDs must be Gen'd */
736 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
741 /* create new renderbuffer object */
742 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
744 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
747 ASSERT(newRb
->AllocStorage
);
748 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
749 newRb
->RefCount
= 1; /* referenced by hash table */
756 ASSERT(newRb
!= &DummyRenderbuffer
);
758 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
763 * If the given renderbuffer is anywhere attached to the framebuffer, detach
765 * This is used when a renderbuffer object is deleted.
766 * The spec calls for unbinding.
769 detach_renderbuffer(GLcontext
*ctx
,
770 struct gl_framebuffer
*fb
,
771 struct gl_renderbuffer
*rb
)
774 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
775 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
776 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
779 invalidate_framebuffer(fb
);
784 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
787 GET_CURRENT_CONTEXT(ctx
);
789 ASSERT_OUTSIDE_BEGIN_END(ctx
);
790 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
792 for (i
= 0; i
< n
; i
++) {
793 if (renderbuffers
[i
] > 0) {
794 struct gl_renderbuffer
*rb
;
795 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
797 /* check if deleting currently bound renderbuffer object */
798 if (rb
== ctx
->CurrentRenderbuffer
) {
800 ASSERT(rb
->RefCount
>= 2);
801 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
804 if (ctx
->DrawBuffer
->Name
) {
805 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
807 if (ctx
->ReadBuffer
->Name
&& ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
808 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
811 /* Remove from hash table immediately, to free the ID.
812 * But the object will not be freed until it's no longer
813 * referenced anywhere else.
815 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
817 if (rb
!= &DummyRenderbuffer
) {
818 /* no longer referenced by hash table */
819 _mesa_reference_renderbuffer(&rb
, NULL
);
828 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
830 GET_CURRENT_CONTEXT(ctx
);
834 ASSERT_OUTSIDE_BEGIN_END(ctx
);
837 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
844 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
846 for (i
= 0; i
< n
; i
++) {
847 GLuint name
= first
+ i
;
848 renderbuffers
[i
] = name
;
849 /* insert dummy placeholder into hash table */
850 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
851 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
852 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
858 * Given an internal format token for a render buffer, return the
859 * corresponding base format.
860 * This is very similar to _mesa_base_tex_format() but the set of valid
861 * internal formats is somewhat different.
863 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
864 * GL_DEPTH_STENCIL_EXT or zero if error.
866 * XXX in the future when we support red-only and red-green formats
867 * we'll also return GL_RED and GL_RG.
870 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
872 switch (internalFormat
) {
891 case GL_STENCIL_INDEX
:
892 case GL_STENCIL_INDEX1_EXT
:
893 case GL_STENCIL_INDEX4_EXT
:
894 case GL_STENCIL_INDEX8_EXT
:
895 case GL_STENCIL_INDEX16_EXT
:
896 return GL_STENCIL_INDEX
;
897 case GL_DEPTH_COMPONENT
:
898 case GL_DEPTH_COMPONENT16
:
899 case GL_DEPTH_COMPONENT24
:
900 case GL_DEPTH_COMPONENT32
:
901 return GL_DEPTH_COMPONENT
;
902 case GL_DEPTH_STENCIL_EXT
:
903 case GL_DEPTH24_STENCIL8_EXT
:
904 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
905 return GL_DEPTH_STENCIL_EXT
;
908 /* XXX add floating point formats eventually */
915 /** sentinal value, see below */
916 #define NO_SAMPLES 1000
920 * Helper function used by _mesa_RenderbufferStorageEXT() and
921 * _mesa_RenderbufferStorageMultisample().
922 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
925 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
926 GLsizei width
, GLsizei height
, GLsizei samples
)
928 const char *func
= samples
== NO_SAMPLES
?
929 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
930 struct gl_renderbuffer
*rb
;
932 GET_CURRENT_CONTEXT(ctx
);
934 ASSERT_OUTSIDE_BEGIN_END(ctx
);
936 if (target
!= GL_RENDERBUFFER_EXT
) {
937 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
941 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
942 if (baseFormat
== 0) {
943 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
947 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
948 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
952 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
953 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
957 if (samples
== NO_SAMPLES
) {
958 /* NumSamples == 0 indicates non-multisampling */
961 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
962 /* note: driver may choose to use more samples than what's requested */
963 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
967 rb
= ctx
->CurrentRenderbuffer
;
969 _mesa_error(ctx
, GL_INVALID_OPERATION
, func
);
973 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
975 if (rb
->InternalFormat
== internalFormat
&&
976 rb
->Width
== (GLuint
) width
&&
977 rb
->Height
== (GLuint
) height
) {
978 /* no change in allocation needed */
982 /* These MUST get set by the AllocStorage func */
983 rb
->Format
= MESA_FORMAT_NONE
;
984 rb
->NumSamples
= samples
;
986 /* Now allocate the storage */
987 ASSERT(rb
->AllocStorage
);
988 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
989 /* No error - check/set fields now */
990 assert(rb
->Format
!= MESA_FORMAT_NONE
);
991 assert(rb
->Width
== (GLuint
) width
);
992 assert(rb
->Height
== (GLuint
) height
);
993 rb
->InternalFormat
= internalFormat
;
994 rb
->_BaseFormat
= baseFormat
;
995 assert(rb
->_BaseFormat
!= 0);
998 /* Probably ran out of memory - clear the fields */
1001 rb
->Format
= MESA_FORMAT_NONE
;
1002 rb
->InternalFormat
= GL_NONE
;
1003 rb
->_BaseFormat
= GL_NONE
;
1008 test_framebuffer_completeness(ctx, fb);
1010 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
1015 #if FEATURE_OES_EGL_image
1017 _mesa_EGLImageTargetRenderbufferStorageOES (GLenum target
, GLeglImageOES image
)
1019 struct gl_renderbuffer
*rb
;
1020 GET_CURRENT_CONTEXT(ctx
);
1021 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1023 if (!ctx
->Extensions
.OES_EGL_image
) {
1024 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1025 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1029 if (target
!= GL_RENDERBUFFER
) {
1030 _mesa_error(ctx
, GL_INVALID_ENUM
, "EGLImageTargetRenderbufferStorageOES");
1034 rb
= ctx
->CurrentRenderbuffer
;
1036 _mesa_error(ctx
, GL_INVALID_OPERATION
, "EGLImageTargetRenderbufferStorageOES");
1040 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1042 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1047 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1048 * _mesa_GetFramebufferAttachmentParameterivEXT()
1049 * We have to be careful to respect the base format. For example, if a
1050 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1051 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1052 * we need to return zero.
1055 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1058 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1059 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1060 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1061 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1062 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1063 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1064 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1065 return _mesa_get_format_bits(format
, pname
);
1068 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1069 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1070 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
)
1071 return _mesa_get_format_bits(format
, pname
);
1074 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1075 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1076 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1077 return _mesa_get_format_bits(format
, pname
);
1080 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1081 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1082 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1083 return _mesa_get_format_bits(format
, pname
);
1094 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1095 GLsizei width
, GLsizei height
)
1097 /* GL_ARB_fbo says calling this function is equivalent to calling
1098 * glRenderbufferStorageMultisample() with samples=0. We pass in
1099 * a token value here just for error reporting purposes.
1101 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1106 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1107 GLenum internalFormat
,
1108 GLsizei width
, GLsizei height
)
1110 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1116 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1118 struct gl_renderbuffer
*rb
;
1119 GET_CURRENT_CONTEXT(ctx
);
1121 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1123 if (target
!= GL_RENDERBUFFER_EXT
) {
1124 _mesa_error(ctx
, GL_INVALID_ENUM
,
1125 "glGetRenderbufferParameterivEXT(target)");
1129 rb
= ctx
->CurrentRenderbuffer
;
1131 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1132 "glGetRenderbufferParameterivEXT");
1136 /* No need to flush here since we're just quering state which is
1137 * not effected by rendering.
1141 case GL_RENDERBUFFER_WIDTH_EXT
:
1142 *params
= rb
->Width
;
1144 case GL_RENDERBUFFER_HEIGHT_EXT
:
1145 *params
= rb
->Height
;
1147 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1148 *params
= rb
->InternalFormat
;
1150 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1151 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1152 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1153 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1154 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1155 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1156 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1158 case GL_RENDERBUFFER_SAMPLES
:
1159 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1160 *params
= rb
->NumSamples
;
1165 _mesa_error(ctx
, GL_INVALID_ENUM
,
1166 "glGetRenderbufferParameterivEXT(target)");
1172 GLboolean GLAPIENTRY
1173 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1175 GET_CURRENT_CONTEXT(ctx
);
1176 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1178 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1179 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1187 * Check if any of the attachments of the given framebuffer are textures
1188 * (render to texture). Call ctx->Driver.RenderTexture() for such
1192 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
1195 ASSERT(ctx
->Driver
.RenderTexture
);
1198 return; /* can't render to texture with winsys framebuffers */
1200 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1201 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1202 struct gl_texture_object
*texObj
= att
->Texture
;
1204 && texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
1205 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1212 * Examine all the framebuffer's attachments to see if any are textures.
1213 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1214 * notify the device driver that the texture image may have changed.
1217 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
1220 return; /* can't render to texture with winsys framebuffers */
1222 if (ctx
->Driver
.FinishRenderTexture
) {
1224 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1225 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1226 if (att
->Texture
&& att
->Renderbuffer
) {
1227 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1235 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1237 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1238 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1239 GLboolean bindReadBuf
, bindDrawBuf
;
1240 GET_CURRENT_CONTEXT(ctx
);
1243 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1244 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1245 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1249 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1251 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1252 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1253 "glBindFramebufferEXT(unsupported)");
1258 #if FEATURE_EXT_framebuffer_blit
1259 case GL_DRAW_FRAMEBUFFER_EXT
:
1260 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1261 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1264 bindDrawBuf
= GL_TRUE
;
1265 bindReadBuf
= GL_FALSE
;
1267 case GL_READ_FRAMEBUFFER_EXT
:
1268 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1269 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1272 bindDrawBuf
= GL_FALSE
;
1273 bindReadBuf
= GL_TRUE
;
1276 case GL_FRAMEBUFFER_EXT
:
1277 bindDrawBuf
= GL_TRUE
;
1278 bindReadBuf
= GL_TRUE
;
1281 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1286 /* Binding a user-created framebuffer object */
1287 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1288 if (newDrawFb
== &DummyFramebuffer
) {
1289 /* ID was reserved, but no real framebuffer object made yet */
1292 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1293 /* All FBO IDs must be Gen'd */
1294 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1299 /* create new framebuffer object */
1300 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1302 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1305 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1307 newReadFb
= newDrawFb
;
1310 /* Binding the window system framebuffer (which was originally set
1311 * with MakeCurrent).
1313 newDrawFb
= ctx
->WinSysDrawBuffer
;
1314 newReadFb
= ctx
->WinSysReadBuffer
;
1318 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1320 /* save pointers to current/old framebuffers */
1321 oldDrawFb
= ctx
->DrawBuffer
;
1322 oldReadFb
= ctx
->ReadBuffer
;
1324 /* check if really changing bindings */
1325 if (oldDrawFb
== newDrawFb
)
1326 bindDrawBuf
= GL_FALSE
;
1327 if (oldReadFb
== newReadFb
)
1328 bindReadBuf
= GL_FALSE
;
1331 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1333 * We also check if we're beginning and/or ending render-to-texture.
1334 * When a framebuffer with texture attachments is unbound, call
1335 * ctx->Driver.FinishRenderTexture().
1336 * When a framebuffer with texture attachments is bound, call
1337 * ctx->Driver.RenderTexture().
1339 * Note that if the ReadBuffer has texture attachments we don't consider
1340 * that a render-to-texture case.
1343 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1345 /* check if old readbuffer was render-to-texture */
1346 check_end_texture_render(ctx
, oldReadFb
);
1348 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1352 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1354 /* check if old read/draw buffers were render-to-texture */
1356 check_end_texture_render(ctx
, oldReadFb
);
1358 if (oldDrawFb
!= oldReadFb
)
1359 check_end_texture_render(ctx
, oldDrawFb
);
1361 /* check if newly bound framebuffer has any texture attachments */
1362 check_begin_texture_render(ctx
, newDrawFb
);
1364 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1367 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1368 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1374 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1377 GET_CURRENT_CONTEXT(ctx
);
1379 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1380 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1382 for (i
= 0; i
< n
; i
++) {
1383 if (framebuffers
[i
] > 0) {
1384 struct gl_framebuffer
*fb
;
1385 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1387 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1389 /* check if deleting currently bound framebuffer object */
1390 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1391 /* separate draw/read binding points */
1392 if (fb
== ctx
->DrawBuffer
) {
1394 ASSERT(fb
->RefCount
>= 2);
1395 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1397 if (fb
== ctx
->ReadBuffer
) {
1399 ASSERT(fb
->RefCount
>= 2);
1400 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1404 /* only one binding point for read/draw buffers */
1405 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1407 ASSERT(fb
->RefCount
>= 2);
1408 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1412 /* remove from hash table immediately, to free the ID */
1413 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1415 if (fb
!= &DummyFramebuffer
) {
1416 /* But the object will not be freed until it's no longer
1417 * bound in any context.
1419 _mesa_reference_framebuffer(&fb
, NULL
);
1428 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1430 GET_CURRENT_CONTEXT(ctx
);
1434 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1437 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1444 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1446 for (i
= 0; i
< n
; i
++) {
1447 GLuint name
= first
+ i
;
1448 framebuffers
[i
] = name
;
1449 /* insert dummy placeholder into hash table */
1450 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1451 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1452 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1459 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1461 struct gl_framebuffer
*buffer
;
1462 GET_CURRENT_CONTEXT(ctx
);
1464 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1467 #if FEATURE_EXT_framebuffer_blit
1468 case GL_DRAW_FRAMEBUFFER_EXT
:
1469 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1470 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1473 buffer
= ctx
->DrawBuffer
;
1475 case GL_READ_FRAMEBUFFER_EXT
:
1476 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1477 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1480 buffer
= ctx
->ReadBuffer
;
1483 case GL_FRAMEBUFFER_EXT
:
1484 buffer
= ctx
->DrawBuffer
;
1487 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1488 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1491 if (buffer
->Name
== 0) {
1492 /* The window system / default framebuffer is always complete */
1493 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1496 /* No need to flush here */
1498 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1499 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1502 return buffer
->_Status
;
1508 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1511 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1512 GLenum attachment
, GLenum textarget
, GLuint texture
,
1513 GLint level
, GLint zoffset
)
1515 struct gl_renderbuffer_attachment
*att
;
1516 struct gl_texture_object
*texObj
= NULL
;
1517 struct gl_framebuffer
*fb
;
1518 GLboolean error
= GL_FALSE
;
1520 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1523 case GL_READ_FRAMEBUFFER_EXT
:
1524 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1525 fb
= ctx
->ReadBuffer
;
1527 case GL_DRAW_FRAMEBUFFER_EXT
:
1528 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1530 case GL_FRAMEBUFFER_EXT
:
1531 fb
= ctx
->DrawBuffer
;
1538 _mesa_error(ctx
, GL_INVALID_ENUM
,
1539 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1545 /* check framebuffer binding */
1546 if (fb
->Name
== 0) {
1547 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1548 "glFramebufferTexture%sEXT", caller
);
1553 /* The textarget, level, and zoffset parameters are only validated if
1554 * texture is non-zero.
1557 GLboolean err
= GL_TRUE
;
1559 texObj
= _mesa_lookup_texture(ctx
, texture
);
1560 if (texObj
!= NULL
) {
1561 if (textarget
== 0) {
1562 /* XXX what's the purpose of this? */
1563 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1564 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1565 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1568 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1569 ? !IS_CUBE_FACE(textarget
)
1570 : (texObj
->Target
!= textarget
);
1574 /* can't render to a non-existant texture */
1575 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1576 "glFramebufferTexture%sEXT(non existant texture)",
1582 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1583 "glFramebufferTexture%sEXT(texture target mismatch)",
1588 if (texObj
->Target
== GL_TEXTURE_3D
) {
1589 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1590 if (zoffset
< 0 || zoffset
>= maxSize
) {
1591 _mesa_error(ctx
, GL_INVALID_VALUE
,
1592 "glFramebufferTexture%sEXT(zoffset)", caller
);
1596 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1597 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1598 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1599 _mesa_error(ctx
, GL_INVALID_VALUE
,
1600 "glFramebufferTexture%sEXT(layer)", caller
);
1606 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1607 _mesa_error(ctx
, GL_INVALID_VALUE
,
1608 "glFramebufferTexture%sEXT(level)", caller
);
1613 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1615 _mesa_error(ctx
, GL_INVALID_ENUM
,
1616 "glFramebufferTexture%sEXT(attachment)", caller
);
1620 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1622 _glthread_LOCK_MUTEX(fb
->Mutex
);
1624 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1626 /* Set the render-to-texture flag. We'll check this flag in
1627 * glTexImage() and friends to determine if we need to revalidate
1628 * any FBOs that might be rendering into this texture.
1629 * This flag never gets cleared since it's non-trivial to determine
1630 * when all FBOs might be done rendering to this texture. That's OK
1631 * though since it's uncommon to render to a texture then repeatedly
1632 * call glTexImage() to change images in the texture.
1634 texObj
->_RenderToTexture
= GL_TRUE
;
1637 _mesa_remove_attachment(ctx
, att
);
1640 invalidate_framebuffer(fb
);
1642 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1648 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1649 GLenum textarget
, GLuint texture
, GLint level
)
1651 GET_CURRENT_CONTEXT(ctx
);
1653 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1654 _mesa_error(ctx
, GL_INVALID_ENUM
,
1655 "glFramebufferTexture1DEXT(textarget)");
1659 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1665 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1666 GLenum textarget
, GLuint texture
, GLint level
)
1668 GET_CURRENT_CONTEXT(ctx
);
1670 if ((texture
!= 0) &&
1671 (textarget
!= GL_TEXTURE_2D
) &&
1672 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1673 (!IS_CUBE_FACE(textarget
))) {
1674 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1675 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
1679 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1685 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1686 GLenum textarget
, GLuint texture
,
1687 GLint level
, GLint zoffset
)
1689 GET_CURRENT_CONTEXT(ctx
);
1691 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1692 _mesa_error(ctx
, GL_INVALID_ENUM
,
1693 "glFramebufferTexture3DEXT(textarget)");
1697 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1703 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1704 GLuint texture
, GLint level
, GLint layer
)
1706 GET_CURRENT_CONTEXT(ctx
);
1708 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1714 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1715 GLenum renderbufferTarget
,
1716 GLuint renderbuffer
)
1718 struct gl_renderbuffer_attachment
*att
;
1719 struct gl_framebuffer
*fb
;
1720 struct gl_renderbuffer
*rb
;
1721 GET_CURRENT_CONTEXT(ctx
);
1723 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1726 #if FEATURE_EXT_framebuffer_blit
1727 case GL_DRAW_FRAMEBUFFER_EXT
:
1728 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1729 _mesa_error(ctx
, GL_INVALID_ENUM
,
1730 "glFramebufferRenderbufferEXT(target)");
1733 fb
= ctx
->DrawBuffer
;
1735 case GL_READ_FRAMEBUFFER_EXT
:
1736 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1737 _mesa_error(ctx
, GL_INVALID_ENUM
,
1738 "glFramebufferRenderbufferEXT(target)");
1741 fb
= ctx
->ReadBuffer
;
1744 case GL_FRAMEBUFFER_EXT
:
1745 fb
= ctx
->DrawBuffer
;
1748 _mesa_error(ctx
, GL_INVALID_ENUM
,
1749 "glFramebufferRenderbufferEXT(target)");
1753 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1754 _mesa_error(ctx
, GL_INVALID_ENUM
,
1755 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1759 if (fb
->Name
== 0) {
1760 /* Can't attach new renderbuffers to a window system framebuffer */
1761 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1765 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1767 _mesa_error(ctx
, GL_INVALID_ENUM
,
1768 "glFramebufferRenderbufferEXT(invalid attachment %s)",
1769 _mesa_lookup_enum_by_nr(attachment
));
1774 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1776 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1777 "glFramebufferRenderbufferEXT(non-existant"
1778 " renderbuffer %u)", renderbuffer
);
1783 /* remove renderbuffer attachment */
1787 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
1788 /* make sure the renderbuffer is a depth/stencil format */
1789 const GLenum baseFormat
=
1790 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
1791 if (baseFormat
!= GL_DEPTH_STENCIL
) {
1792 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1793 "glFramebufferRenderbufferEXT(renderbuffer"
1794 " is not DEPTH_STENCIL format)");
1800 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1802 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1803 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1805 /* Some subsequent GL commands may depend on the framebuffer's visual
1806 * after the binding is updated. Update visual info now.
1808 _mesa_update_framebuffer_visual(fb
);
1813 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1814 GLenum pname
, GLint
*params
)
1816 const struct gl_renderbuffer_attachment
*att
;
1817 struct gl_framebuffer
*buffer
;
1818 GET_CURRENT_CONTEXT(ctx
);
1820 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1823 #if FEATURE_EXT_framebuffer_blit
1824 case GL_DRAW_FRAMEBUFFER_EXT
:
1825 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1826 _mesa_error(ctx
, GL_INVALID_ENUM
,
1827 "glGetFramebufferAttachmentParameterivEXT(target)");
1830 buffer
= ctx
->DrawBuffer
;
1832 case GL_READ_FRAMEBUFFER_EXT
:
1833 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1834 _mesa_error(ctx
, GL_INVALID_ENUM
,
1835 "glGetFramebufferAttachmentParameterivEXT(target)");
1838 buffer
= ctx
->ReadBuffer
;
1841 case GL_FRAMEBUFFER_EXT
:
1842 buffer
= ctx
->DrawBuffer
;
1845 _mesa_error(ctx
, GL_INVALID_ENUM
,
1846 "glGetFramebufferAttachmentParameterivEXT(target)");
1850 if (buffer
->Name
== 0) {
1851 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1852 "glGetFramebufferAttachmentParameterivEXT");
1856 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1858 _mesa_error(ctx
, GL_INVALID_ENUM
,
1859 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1863 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
1864 /* the depth and stencil attachments must point to the same buffer */
1865 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
1866 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
1867 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
1868 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
1869 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1870 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
1871 " attachments differ)");
1876 /* No need to flush here */
1879 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1880 *params
= att
->Type
;
1882 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1883 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1884 *params
= att
->Renderbuffer
->Name
;
1886 else if (att
->Type
== GL_TEXTURE
) {
1887 *params
= att
->Texture
->Name
;
1890 _mesa_error(ctx
, GL_INVALID_ENUM
,
1891 "glGetFramebufferAttachmentParameterivEXT(pname)");
1894 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1895 if (att
->Type
== GL_TEXTURE
) {
1896 *params
= att
->TextureLevel
;
1899 _mesa_error(ctx
, GL_INVALID_ENUM
,
1900 "glGetFramebufferAttachmentParameterivEXT(pname)");
1903 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1904 if (att
->Type
== GL_TEXTURE
) {
1905 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
1906 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1913 _mesa_error(ctx
, GL_INVALID_ENUM
,
1914 "glGetFramebufferAttachmentParameterivEXT(pname)");
1917 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1918 if (att
->Type
== GL_TEXTURE
) {
1919 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
1920 *params
= att
->Zoffset
;
1927 _mesa_error(ctx
, GL_INVALID_ENUM
,
1928 "glGetFramebufferAttachmentParameterivEXT(pname)");
1931 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
1932 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1933 _mesa_error(ctx
, GL_INVALID_ENUM
,
1934 "glGetFramebufferAttachmentParameterivEXT(pname)");
1937 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
1940 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
1941 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1942 _mesa_error(ctx
, GL_INVALID_ENUM
,
1943 "glGetFramebufferAttachmentParameterivEXT(pname)");
1947 gl_format format
= att
->Renderbuffer
->Format
;
1948 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
1953 *params
= _mesa_get_format_datatype(format
);
1957 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1958 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1959 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1960 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1961 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1962 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1963 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1964 _mesa_error(ctx
, GL_INVALID_ENUM
,
1965 "glGetFramebufferAttachmentParameterivEXT(pname)");
1967 else if (att
->Texture
) {
1968 const struct gl_texture_image
*texImage
=
1969 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
1972 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
1973 texImage
->TexFormat
);
1979 else if (att
->Renderbuffer
) {
1980 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
1981 att
->Renderbuffer
->Format
);
1988 _mesa_error(ctx
, GL_INVALID_ENUM
,
1989 "glGetFramebufferAttachmentParameterivEXT(pname)");
1996 _mesa_GenerateMipmapEXT(GLenum target
)
1998 struct gl_texture_object
*texObj
;
1999 GET_CURRENT_CONTEXT(ctx
);
2001 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2002 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2008 case GL_TEXTURE_CUBE_MAP
:
2009 /* OK, legal value */
2012 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2016 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2018 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2023 _mesa_lock_texture(ctx
, texObj
);
2024 if (target
== GL_TEXTURE_CUBE_MAP
) {
2026 for (face
= 0; face
< 6; face
++)
2027 ctx
->Driver
.GenerateMipmap(ctx
,
2028 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2032 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2034 _mesa_unlock_texture(ctx
, texObj
);
2038 #if FEATURE_EXT_framebuffer_blit
2040 static const struct gl_renderbuffer_attachment
*
2041 find_attachment(const struct gl_framebuffer
*fb
, const struct gl_renderbuffer
*rb
)
2044 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2045 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2046 return &fb
->Attachment
[i
];
2054 * Blit rectangular region, optionally from one framebuffer to another.
2056 * Note, if the src buffer is multisampled and the dest is not, this is
2057 * when the samples must be resolved to a single color.
2060 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2061 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2062 GLbitfield mask
, GLenum filter
)
2064 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2065 GL_DEPTH_BUFFER_BIT
|
2066 GL_STENCIL_BUFFER_BIT
);
2067 const struct gl_framebuffer
*readFb
, *drawFb
;
2068 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2069 GET_CURRENT_CONTEXT(ctx
);
2071 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2072 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2074 if (ctx
->NewState
) {
2075 _mesa_update_state(ctx
);
2078 readFb
= ctx
->ReadBuffer
;
2079 drawFb
= ctx
->DrawBuffer
;
2081 if (!readFb
|| !drawFb
) {
2082 /* This will normally never happen but someday we may want to
2083 * support MakeCurrent() with no drawables.
2088 /* check for complete framebuffers */
2089 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2090 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2091 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2092 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2096 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2097 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2101 if (mask
& ~legalMaskBits
) {
2102 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2106 /* depth/stencil must be blitted with nearest filtering */
2107 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2108 && filter
!= GL_NEAREST
) {
2109 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2110 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
2114 /* get color read/draw renderbuffers */
2115 if (mask
& GL_COLOR_BUFFER_BIT
) {
2116 colorReadRb
= readFb
->_ColorReadBuffer
;
2117 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2120 colorReadRb
= colorDrawRb
= NULL
;
2123 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2124 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2125 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2128 _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2129 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2130 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2131 "glBlitFramebufferEXT(stencil buffer size mismatch");
2136 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2137 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2138 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2141 _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2142 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2143 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2144 "glBlitFramebufferEXT(depth buffer size mismatch");
2149 if (readFb
->Visual
.samples
> 0 &&
2150 drawFb
->Visual
.samples
> 0 &&
2151 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2152 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2153 "glBlitFramebufferEXT(mismatched samples");
2157 /* extra checks for multisample copies... */
2158 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2159 /* src and dest region sizes must be the same */
2160 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2161 srcY1
- srcY0
!= dstY1
- dstY0
) {
2162 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2163 "glBlitFramebufferEXT(bad src/dst multisample region sizes");
2167 /* color formats must match */
2170 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2171 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2172 "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
2177 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2178 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2184 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2186 srcX0
, srcY0
, srcX1
, srcY1
,
2187 dstX0
, dstY0
, dstX1
, dstY1
,
2190 const struct gl_renderbuffer_attachment
*att
;
2192 att
= find_attachment(readFb
, colorReadRb
);
2193 printf(" Src FBO %u RB %u (%dx%d) ",
2194 readFb
->Name
, colorReadRb
->Name
,
2195 colorReadRb
->Width
, colorReadRb
->Height
);
2196 if (att
&& att
->Texture
) {
2197 printf("Tex %u tgt 0x%x level %u face %u",
2199 att
->Texture
->Target
,
2205 att
= find_attachment(drawFb
, colorDrawRb
);
2206 printf(" Dst FBO %u RB %u (%dx%d) ",
2207 drawFb
->Name
, colorDrawRb
->Name
,
2208 colorDrawRb
->Width
, colorDrawRb
->Height
);
2209 if (att
&& att
->Texture
) {
2210 printf("Tex %u tgt 0x%x level %u face %u",
2212 att
->Texture
->Target
,
2220 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2221 ctx
->Driver
.BlitFramebuffer(ctx
,
2222 srcX0
, srcY0
, srcX1
, srcY1
,
2223 dstX0
, dstY0
, dstX1
, dstY1
,
2226 #endif /* FEATURE_EXT_framebuffer_blit */