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
];
192 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
194 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
196 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
198 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
206 * Remove any texture or renderbuffer attached to the given attachment
207 * point. Update reference counts, etc.
210 _mesa_remove_attachment(GLcontext
*ctx
, struct gl_renderbuffer_attachment
*att
)
212 if (att
->Type
== GL_TEXTURE
) {
213 ASSERT(att
->Texture
);
214 if (ctx
->Driver
.FinishRenderTexture
) {
215 /* tell driver that we're done rendering to this texture. */
216 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
218 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
219 ASSERT(!att
->Texture
);
221 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
222 ASSERT(!att
->Texture
);
223 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
224 ASSERT(!att
->Renderbuffer
);
227 att
->Complete
= GL_TRUE
;
232 * Bind a texture object to an attachment point.
233 * The previous binding, if any, will be removed first.
236 _mesa_set_texture_attachment(GLcontext
*ctx
,
237 struct gl_framebuffer
*fb
,
238 struct gl_renderbuffer_attachment
*att
,
239 struct gl_texture_object
*texObj
,
240 GLenum texTarget
, GLuint level
, GLuint zoffset
)
242 if (att
->Texture
== texObj
) {
243 /* re-attaching same texture */
244 ASSERT(att
->Type
== GL_TEXTURE
);
245 if (ctx
->Driver
.FinishRenderTexture
)
246 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
250 if (ctx
->Driver
.FinishRenderTexture
&& att
->Texture
)
251 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
252 _mesa_remove_attachment(ctx
, att
);
253 att
->Type
= GL_TEXTURE
;
254 assert(!att
->Texture
);
255 _mesa_reference_texobj(&att
->Texture
, texObj
);
258 /* always update these fields */
259 att
->TextureLevel
= level
;
260 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
261 att
->Zoffset
= zoffset
;
262 att
->Complete
= GL_FALSE
;
264 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
265 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
268 invalidate_framebuffer(fb
);
273 * Bind a renderbuffer to an attachment point.
274 * The previous binding, if any, will be removed first.
277 _mesa_set_renderbuffer_attachment(GLcontext
*ctx
,
278 struct gl_renderbuffer_attachment
*att
,
279 struct gl_renderbuffer
*rb
)
281 /* XXX check if re-doing same attachment, exit early */
282 _mesa_remove_attachment(ctx
, att
);
283 att
->Type
= GL_RENDERBUFFER_EXT
;
284 att
->Texture
= NULL
; /* just to be safe */
285 att
->Complete
= GL_FALSE
;
286 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
291 * Fallback for ctx->Driver.FramebufferRenderbuffer()
292 * Attach a renderbuffer object to a framebuffer object.
295 _mesa_framebuffer_renderbuffer(GLcontext
*ctx
, struct gl_framebuffer
*fb
,
296 GLenum attachment
, struct gl_renderbuffer
*rb
)
298 struct gl_renderbuffer_attachment
*att
;
300 _glthread_LOCK_MUTEX(fb
->Mutex
);
302 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
305 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
306 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
307 /* do stencil attachment here (depth already done above) */
308 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
310 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
314 _mesa_remove_attachment(ctx
, att
);
317 invalidate_framebuffer(fb
);
319 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
327 att_incomplete(const char *msg
)
330 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
341 fbo_incomplete(const char *msg
, int index
)
344 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
355 * Test if an attachment point is complete and update its Complete field.
356 * \param format if GL_COLOR, this is a color attachment point,
357 * if GL_DEPTH, this is a depth component attachment point,
358 * if GL_STENCIL, this is a stencil component attachment point.
361 test_attachment_completeness(const GLcontext
*ctx
, GLenum format
,
362 struct gl_renderbuffer_attachment
*att
)
364 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
366 /* assume complete */
367 att
->Complete
= GL_TRUE
;
369 /* Look for reasons why the attachment might be incomplete */
370 if (att
->Type
== GL_TEXTURE
) {
371 const struct gl_texture_object
*texObj
= att
->Texture
;
372 struct gl_texture_image
*texImage
;
376 att_incomplete("no texobj");
377 att
->Complete
= GL_FALSE
;
381 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
383 att_incomplete("no teximage");
384 att
->Complete
= GL_FALSE
;
387 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
388 att_incomplete("teximage width/height=0");
389 printf("texobj = %u\n", texObj
->Name
);
390 printf("level = %d\n", att
->TextureLevel
);
391 att
->Complete
= GL_FALSE
;
394 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
395 att_incomplete("bad z offset");
396 att
->Complete
= GL_FALSE
;
400 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
402 if (format
== GL_COLOR
) {
403 if (baseFormat
!= GL_RGB
&&
404 baseFormat
!= GL_RGBA
&&
405 (!ctx
->Extensions
.ARB_framebuffer_object
||
406 baseFormat
!= GL_ALPHA
)) {
407 att_incomplete("bad format");
408 att
->Complete
= GL_FALSE
;
411 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
412 att_incomplete("compressed internalformat");
413 att
->Complete
= GL_FALSE
;
417 else if (format
== GL_DEPTH
) {
418 if (baseFormat
== GL_DEPTH_COMPONENT
) {
421 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
422 ctx
->Extensions
.ARB_depth_texture
&&
423 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
427 att
->Complete
= GL_FALSE
;
428 att_incomplete("bad depth format");
433 ASSERT(format
== GL_STENCIL
);
434 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
435 ctx
->Extensions
.ARB_depth_texture
&&
436 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
440 /* no such thing as stencil-only textures */
441 att_incomplete("illegal stencil texture");
442 att
->Complete
= GL_FALSE
;
447 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
448 const GLenum baseFormat
=
449 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
451 ASSERT(att
->Renderbuffer
);
452 if (!att
->Renderbuffer
->InternalFormat
||
453 att
->Renderbuffer
->Width
< 1 ||
454 att
->Renderbuffer
->Height
< 1) {
455 att_incomplete("0x0 renderbuffer");
456 att
->Complete
= GL_FALSE
;
459 if (format
== GL_COLOR
) {
460 if (baseFormat
!= GL_RGB
&&
461 baseFormat
!= GL_RGBA
) {
462 att_incomplete("bad renderbuffer color format");
463 att
->Complete
= GL_FALSE
;
467 else if (format
== GL_DEPTH
) {
468 if (baseFormat
== GL_DEPTH_COMPONENT
) {
471 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
472 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
476 att_incomplete("bad renderbuffer depth format");
477 att
->Complete
= GL_FALSE
;
482 assert(format
== GL_STENCIL
);
483 if (baseFormat
== GL_STENCIL_INDEX
) {
486 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
487 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
491 att
->Complete
= GL_FALSE
;
492 att_incomplete("bad renderbuffer stencil format");
498 ASSERT(att
->Type
== GL_NONE
);
506 * Test if the given framebuffer object is complete and update its
507 * Status field with the results.
508 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
509 * driver to make hardware-specific validation/completeness checks.
510 * Also update the framebuffer's Width and Height fields if the
511 * framebuffer is complete.
514 _mesa_test_framebuffer_completeness(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
517 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
518 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
519 GLint numSamples
= -1;
523 assert(fb
->Name
!= 0);
529 /* Start at -2 to more easily loop over all attachment points.
534 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
535 struct gl_renderbuffer_attachment
*att
;
539 * XXX for ARB_fbo, only check color buffers that are named by
540 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
543 /* check for attachment completeness
546 att
= &fb
->Attachment
[BUFFER_DEPTH
];
547 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
548 if (!att
->Complete
) {
549 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
550 fbo_incomplete("depth attachment incomplete", -1);
555 att
= &fb
->Attachment
[BUFFER_STENCIL
];
556 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
557 if (!att
->Complete
) {
558 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
559 fbo_incomplete("stencil attachment incomplete", -1);
564 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
565 test_attachment_completeness(ctx
, GL_COLOR
, att
);
566 if (!att
->Complete
) {
567 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
568 fbo_incomplete("color attachment incomplete", i
);
573 /* get width, height, format of the renderbuffer/texture
575 if (att
->Type
== GL_TEXTURE
) {
576 const struct gl_texture_image
*texImg
577 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
578 minWidth
= MIN2(minWidth
, texImg
->Width
);
579 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
580 minHeight
= MIN2(minHeight
, texImg
->Height
);
581 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
582 f
= texImg
->_BaseFormat
;
584 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
585 && f
!= GL_DEPTH_STENCIL_EXT
586 && (!ctx
->Extensions
.ARB_framebuffer_object
|| f
!= GL_ALPHA
)) {
587 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
588 fbo_incomplete("texture attachment incomplete", -1);
592 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
593 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
594 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
595 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
596 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
597 f
= att
->Renderbuffer
->InternalFormat
;
601 assert(att
->Type
== GL_NONE
);
605 if (numSamples
< 0) {
607 numSamples
= att
->Renderbuffer
->NumSamples
;
610 /* Error-check width, height, format, samples
612 if (numImages
== 1) {
613 /* save format, num samples */
619 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
620 /* check that width, height, format are same */
621 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
622 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
623 fbo_incomplete("width or height mismatch", -1);
626 /* check that all color buffer have same format */
627 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
628 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
629 fbo_incomplete("format mismatch", -1);
633 if (att
->Renderbuffer
&&
634 att
->Renderbuffer
->NumSamples
!= numSamples
) {
635 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
636 fbo_incomplete("inconsistant number of samples", i
);
644 if (ctx
->API
== API_OPENGL
) {
645 /* Check that all DrawBuffers are present */
646 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
647 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
648 const struct gl_renderbuffer_attachment
*att
649 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
651 if (att
->Type
== GL_NONE
) {
652 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
653 fbo_incomplete("missing drawbuffer", j
);
659 /* Check that the ReadBuffer is present */
660 if (fb
->ColorReadBuffer
!= GL_NONE
) {
661 const struct gl_renderbuffer_attachment
*att
662 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
664 if (att
->Type
== GL_NONE
) {
665 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
666 fbo_incomplete("missing readbuffer", -1);
675 if (numImages
== 0) {
676 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
677 fbo_incomplete("no attachments", -1);
681 /* Provisionally set status = COMPLETE ... */
682 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
684 /* ... but the driver may say the FB is incomplete.
685 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
688 if (ctx
->Driver
.ValidateFramebuffer
) {
689 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
690 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
691 fbo_incomplete("driver marked FBO as incomplete", -1);
695 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
697 * Note that if ARB_framebuffer_object is supported and the attached
698 * renderbuffers/textures are different sizes, the framebuffer
699 * width/height will be set to the smallest width/height.
701 fb
->Width
= minWidth
;
702 fb
->Height
= minHeight
;
704 /* finally, update the visual info for the framebuffer */
705 _mesa_update_framebuffer_visual(fb
);
711 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
713 GET_CURRENT_CONTEXT(ctx
);
714 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
716 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
717 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
725 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
727 struct gl_renderbuffer
*newRb
;
728 GET_CURRENT_CONTEXT(ctx
);
730 ASSERT_OUTSIDE_BEGIN_END(ctx
);
732 if (target
!= GL_RENDERBUFFER_EXT
) {
733 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
737 /* No need to flush here since the render buffer binding has no
738 * effect on rendering state.
742 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
743 if (newRb
== &DummyRenderbuffer
) {
744 /* ID was reserved, but no real renderbuffer object made yet */
747 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
748 /* All RB IDs must be Gen'd */
749 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
754 /* create new renderbuffer object */
755 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
757 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
760 ASSERT(newRb
->AllocStorage
);
761 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
762 newRb
->RefCount
= 1; /* referenced by hash table */
769 ASSERT(newRb
!= &DummyRenderbuffer
);
771 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
776 * If the given renderbuffer is anywhere attached to the framebuffer, detach
778 * This is used when a renderbuffer object is deleted.
779 * The spec calls for unbinding.
782 detach_renderbuffer(GLcontext
*ctx
,
783 struct gl_framebuffer
*fb
,
784 struct gl_renderbuffer
*rb
)
787 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
788 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
789 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
792 invalidate_framebuffer(fb
);
797 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
800 GET_CURRENT_CONTEXT(ctx
);
802 ASSERT_OUTSIDE_BEGIN_END(ctx
);
803 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
805 for (i
= 0; i
< n
; i
++) {
806 if (renderbuffers
[i
] > 0) {
807 struct gl_renderbuffer
*rb
;
808 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
810 /* check if deleting currently bound renderbuffer object */
811 if (rb
== ctx
->CurrentRenderbuffer
) {
813 ASSERT(rb
->RefCount
>= 2);
814 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
817 if (ctx
->DrawBuffer
->Name
) {
818 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
820 if (ctx
->ReadBuffer
->Name
&& ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
821 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
824 /* Remove from hash table immediately, to free the ID.
825 * But the object will not be freed until it's no longer
826 * referenced anywhere else.
828 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
830 if (rb
!= &DummyRenderbuffer
) {
831 /* no longer referenced by hash table */
832 _mesa_reference_renderbuffer(&rb
, NULL
);
841 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
843 GET_CURRENT_CONTEXT(ctx
);
847 ASSERT_OUTSIDE_BEGIN_END(ctx
);
850 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
857 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
859 for (i
= 0; i
< n
; i
++) {
860 GLuint name
= first
+ i
;
861 renderbuffers
[i
] = name
;
862 /* insert dummy placeholder into hash table */
863 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
864 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
865 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
871 * Given an internal format token for a render buffer, return the
872 * corresponding base format.
873 * This is very similar to _mesa_base_tex_format() but the set of valid
874 * internal formats is somewhat different.
876 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
877 * GL_DEPTH_STENCIL_EXT or zero if error.
879 * XXX in the future when we support red-only and red-green formats
880 * we'll also return GL_RED and GL_RG.
883 _mesa_base_fbo_format(GLcontext
*ctx
, GLenum internalFormat
)
885 switch (internalFormat
) {
903 case GL_RGBA16_SNORM
:
905 case GL_STENCIL_INDEX
:
906 case GL_STENCIL_INDEX1_EXT
:
907 case GL_STENCIL_INDEX4_EXT
:
908 case GL_STENCIL_INDEX8_EXT
:
909 case GL_STENCIL_INDEX16_EXT
:
910 return GL_STENCIL_INDEX
;
911 case GL_DEPTH_COMPONENT
:
912 case GL_DEPTH_COMPONENT16
:
913 case GL_DEPTH_COMPONENT24
:
914 case GL_DEPTH_COMPONENT32
:
915 return GL_DEPTH_COMPONENT
;
916 case GL_DEPTH_STENCIL_EXT
:
917 case GL_DEPTH24_STENCIL8_EXT
:
918 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
919 return GL_DEPTH_STENCIL_EXT
;
922 /* XXX add floating point formats eventually */
929 /** sentinal value, see below */
930 #define NO_SAMPLES 1000
934 * Helper function used by _mesa_RenderbufferStorageEXT() and
935 * _mesa_RenderbufferStorageMultisample().
936 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
939 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
940 GLsizei width
, GLsizei height
, GLsizei samples
)
942 const char *func
= samples
== NO_SAMPLES
?
943 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
944 struct gl_renderbuffer
*rb
;
946 GET_CURRENT_CONTEXT(ctx
);
948 ASSERT_OUTSIDE_BEGIN_END(ctx
);
950 if (target
!= GL_RENDERBUFFER_EXT
) {
951 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
955 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
956 if (baseFormat
== 0) {
957 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
961 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
962 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
966 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
967 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
971 if (samples
== NO_SAMPLES
) {
972 /* NumSamples == 0 indicates non-multisampling */
975 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
976 /* note: driver may choose to use more samples than what's requested */
977 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
981 rb
= ctx
->CurrentRenderbuffer
;
983 _mesa_error(ctx
, GL_INVALID_OPERATION
, func
);
987 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
989 if (rb
->InternalFormat
== internalFormat
&&
990 rb
->Width
== (GLuint
) width
&&
991 rb
->Height
== (GLuint
) height
) {
992 /* no change in allocation needed */
996 /* These MUST get set by the AllocStorage func */
997 rb
->Format
= MESA_FORMAT_NONE
;
998 rb
->NumSamples
= samples
;
1000 /* Now allocate the storage */
1001 ASSERT(rb
->AllocStorage
);
1002 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1003 /* No error - check/set fields now */
1004 assert(rb
->Format
!= MESA_FORMAT_NONE
);
1005 assert(rb
->Width
== (GLuint
) width
);
1006 assert(rb
->Height
== (GLuint
) height
);
1007 rb
->InternalFormat
= internalFormat
;
1008 rb
->_BaseFormat
= baseFormat
;
1009 assert(rb
->_BaseFormat
!= 0);
1012 /* Probably ran out of memory - clear the fields */
1015 rb
->Format
= MESA_FORMAT_NONE
;
1016 rb
->InternalFormat
= GL_NONE
;
1017 rb
->_BaseFormat
= GL_NONE
;
1022 test_framebuffer_completeness(ctx, fb);
1024 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
1030 #if FEATURE_OES_EGL_image
1032 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1034 struct gl_renderbuffer
*rb
;
1035 GET_CURRENT_CONTEXT(ctx
);
1036 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1038 if (!ctx
->Extensions
.OES_EGL_image
) {
1039 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1040 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1044 if (target
!= GL_RENDERBUFFER
) {
1045 _mesa_error(ctx
, GL_INVALID_ENUM
,
1046 "EGLImageTargetRenderbufferStorageOES");
1050 rb
= ctx
->CurrentRenderbuffer
;
1052 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1053 "EGLImageTargetRenderbufferStorageOES");
1057 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1059 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1065 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1066 * _mesa_GetFramebufferAttachmentParameterivEXT()
1067 * We have to be careful to respect the base format. For example, if a
1068 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1069 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1070 * we need to return zero.
1073 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1076 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1077 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1078 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1079 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1080 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1081 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1082 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1083 return _mesa_get_format_bits(format
, pname
);
1086 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1087 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1088 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
)
1089 return _mesa_get_format_bits(format
, pname
);
1092 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1093 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1094 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1095 return _mesa_get_format_bits(format
, pname
);
1098 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1099 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1100 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1101 return _mesa_get_format_bits(format
, pname
);
1112 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1113 GLsizei width
, GLsizei height
)
1115 /* GL_ARB_fbo says calling this function is equivalent to calling
1116 * glRenderbufferStorageMultisample() with samples=0. We pass in
1117 * a token value here just for error reporting purposes.
1119 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1124 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1125 GLenum internalFormat
,
1126 GLsizei width
, GLsizei height
)
1128 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1133 * OpenGL ES version of glRenderBufferStorage.
1136 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1137 GLsizei width
, GLsizei height
)
1139 switch (internalFormat
) {
1141 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1142 /* choose a closest format */
1143 internalFormat
= GL_RGB5
;
1149 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1154 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1156 struct gl_renderbuffer
*rb
;
1157 GET_CURRENT_CONTEXT(ctx
);
1159 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1161 if (target
!= GL_RENDERBUFFER_EXT
) {
1162 _mesa_error(ctx
, GL_INVALID_ENUM
,
1163 "glGetRenderbufferParameterivEXT(target)");
1167 rb
= ctx
->CurrentRenderbuffer
;
1169 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1170 "glGetRenderbufferParameterivEXT");
1174 /* No need to flush here since we're just quering state which is
1175 * not effected by rendering.
1179 case GL_RENDERBUFFER_WIDTH_EXT
:
1180 *params
= rb
->Width
;
1182 case GL_RENDERBUFFER_HEIGHT_EXT
:
1183 *params
= rb
->Height
;
1185 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1186 *params
= rb
->InternalFormat
;
1188 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1189 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1190 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1191 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1192 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1193 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1194 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1196 case GL_RENDERBUFFER_SAMPLES
:
1197 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1198 *params
= rb
->NumSamples
;
1203 _mesa_error(ctx
, GL_INVALID_ENUM
,
1204 "glGetRenderbufferParameterivEXT(target)");
1210 GLboolean GLAPIENTRY
1211 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1213 GET_CURRENT_CONTEXT(ctx
);
1214 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1216 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1217 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1225 * Check if any of the attachments of the given framebuffer are textures
1226 * (render to texture). Call ctx->Driver.RenderTexture() for such
1230 check_begin_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
1233 ASSERT(ctx
->Driver
.RenderTexture
);
1236 return; /* can't render to texture with winsys framebuffers */
1238 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1239 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1240 struct gl_texture_object
*texObj
= att
->Texture
;
1242 && texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
1243 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1250 * Examine all the framebuffer's attachments to see if any are textures.
1251 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1252 * notify the device driver that the texture image may have changed.
1255 check_end_texture_render(GLcontext
*ctx
, struct gl_framebuffer
*fb
)
1258 return; /* can't render to texture with winsys framebuffers */
1260 if (ctx
->Driver
.FinishRenderTexture
) {
1262 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1263 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1264 if (att
->Texture
&& att
->Renderbuffer
) {
1265 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1273 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1275 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1276 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1277 GLboolean bindReadBuf
, bindDrawBuf
;
1278 GET_CURRENT_CONTEXT(ctx
);
1281 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1282 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1283 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1287 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1289 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1290 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1291 "glBindFramebufferEXT(unsupported)");
1296 #if FEATURE_EXT_framebuffer_blit
1297 case GL_DRAW_FRAMEBUFFER_EXT
:
1298 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1299 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1302 bindDrawBuf
= GL_TRUE
;
1303 bindReadBuf
= GL_FALSE
;
1305 case GL_READ_FRAMEBUFFER_EXT
:
1306 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1307 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1310 bindDrawBuf
= GL_FALSE
;
1311 bindReadBuf
= GL_TRUE
;
1314 case GL_FRAMEBUFFER_EXT
:
1315 bindDrawBuf
= GL_TRUE
;
1316 bindReadBuf
= GL_TRUE
;
1319 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1324 /* Binding a user-created framebuffer object */
1325 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1326 if (newDrawFb
== &DummyFramebuffer
) {
1327 /* ID was reserved, but no real framebuffer object made yet */
1330 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1331 /* All FBO IDs must be Gen'd */
1332 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1337 /* create new framebuffer object */
1338 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1340 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1343 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1345 newReadFb
= newDrawFb
;
1348 /* Binding the window system framebuffer (which was originally set
1349 * with MakeCurrent).
1351 newDrawFb
= ctx
->WinSysDrawBuffer
;
1352 newReadFb
= ctx
->WinSysReadBuffer
;
1356 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1358 /* save pointers to current/old framebuffers */
1359 oldDrawFb
= ctx
->DrawBuffer
;
1360 oldReadFb
= ctx
->ReadBuffer
;
1362 /* check if really changing bindings */
1363 if (oldDrawFb
== newDrawFb
)
1364 bindDrawBuf
= GL_FALSE
;
1365 if (oldReadFb
== newReadFb
)
1366 bindReadBuf
= GL_FALSE
;
1369 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1371 * We also check if we're beginning and/or ending render-to-texture.
1372 * When a framebuffer with texture attachments is unbound, call
1373 * ctx->Driver.FinishRenderTexture().
1374 * When a framebuffer with texture attachments is bound, call
1375 * ctx->Driver.RenderTexture().
1377 * Note that if the ReadBuffer has texture attachments we don't consider
1378 * that a render-to-texture case.
1381 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1383 /* check if old readbuffer was render-to-texture */
1384 check_end_texture_render(ctx
, oldReadFb
);
1386 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1390 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1392 /* check if old read/draw buffers were render-to-texture */
1394 check_end_texture_render(ctx
, oldReadFb
);
1396 if (oldDrawFb
!= oldReadFb
)
1397 check_end_texture_render(ctx
, oldDrawFb
);
1399 /* check if newly bound framebuffer has any texture attachments */
1400 check_begin_texture_render(ctx
, newDrawFb
);
1402 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1405 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1406 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1412 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1415 GET_CURRENT_CONTEXT(ctx
);
1417 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1418 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1420 for (i
= 0; i
< n
; i
++) {
1421 if (framebuffers
[i
] > 0) {
1422 struct gl_framebuffer
*fb
;
1423 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1425 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1427 /* check if deleting currently bound framebuffer object */
1428 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1429 /* separate draw/read binding points */
1430 if (fb
== ctx
->DrawBuffer
) {
1432 ASSERT(fb
->RefCount
>= 2);
1433 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1435 if (fb
== ctx
->ReadBuffer
) {
1437 ASSERT(fb
->RefCount
>= 2);
1438 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1442 /* only one binding point for read/draw buffers */
1443 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1445 ASSERT(fb
->RefCount
>= 2);
1446 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1450 /* remove from hash table immediately, to free the ID */
1451 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1453 if (fb
!= &DummyFramebuffer
) {
1454 /* But the object will not be freed until it's no longer
1455 * bound in any context.
1457 _mesa_reference_framebuffer(&fb
, NULL
);
1466 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1468 GET_CURRENT_CONTEXT(ctx
);
1472 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1475 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1482 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1484 for (i
= 0; i
< n
; i
++) {
1485 GLuint name
= first
+ i
;
1486 framebuffers
[i
] = name
;
1487 /* insert dummy placeholder into hash table */
1488 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1489 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1490 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1497 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1499 struct gl_framebuffer
*buffer
;
1500 GET_CURRENT_CONTEXT(ctx
);
1502 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1505 #if FEATURE_EXT_framebuffer_blit
1506 case GL_DRAW_FRAMEBUFFER_EXT
:
1507 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1508 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1511 buffer
= ctx
->DrawBuffer
;
1513 case GL_READ_FRAMEBUFFER_EXT
:
1514 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1515 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1518 buffer
= ctx
->ReadBuffer
;
1521 case GL_FRAMEBUFFER_EXT
:
1522 buffer
= ctx
->DrawBuffer
;
1525 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1526 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1529 if (buffer
->Name
== 0) {
1530 /* The window system / default framebuffer is always complete */
1531 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1534 /* No need to flush here */
1536 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1537 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1540 return buffer
->_Status
;
1546 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1549 framebuffer_texture(GLcontext
*ctx
, const char *caller
, GLenum target
,
1550 GLenum attachment
, GLenum textarget
, GLuint texture
,
1551 GLint level
, GLint zoffset
)
1553 struct gl_renderbuffer_attachment
*att
;
1554 struct gl_texture_object
*texObj
= NULL
;
1555 struct gl_framebuffer
*fb
;
1556 GLboolean error
= GL_FALSE
;
1558 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1561 case GL_READ_FRAMEBUFFER_EXT
:
1562 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1563 fb
= ctx
->ReadBuffer
;
1565 case GL_DRAW_FRAMEBUFFER_EXT
:
1566 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1568 case GL_FRAMEBUFFER_EXT
:
1569 fb
= ctx
->DrawBuffer
;
1576 _mesa_error(ctx
, GL_INVALID_ENUM
,
1577 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1583 /* check framebuffer binding */
1584 if (fb
->Name
== 0) {
1585 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1586 "glFramebufferTexture%sEXT", caller
);
1591 /* The textarget, level, and zoffset parameters are only validated if
1592 * texture is non-zero.
1595 GLboolean err
= GL_TRUE
;
1597 texObj
= _mesa_lookup_texture(ctx
, texture
);
1598 if (texObj
!= NULL
) {
1599 if (textarget
== 0) {
1600 /* XXX what's the purpose of this? */
1601 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1602 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1603 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1606 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1607 ? !IS_CUBE_FACE(textarget
)
1608 : (texObj
->Target
!= textarget
);
1612 /* can't render to a non-existant texture */
1613 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1614 "glFramebufferTexture%sEXT(non existant texture)",
1620 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1621 "glFramebufferTexture%sEXT(texture target mismatch)",
1626 if (texObj
->Target
== GL_TEXTURE_3D
) {
1627 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1628 if (zoffset
< 0 || zoffset
>= maxSize
) {
1629 _mesa_error(ctx
, GL_INVALID_VALUE
,
1630 "glFramebufferTexture%sEXT(zoffset)", caller
);
1634 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1635 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1636 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1637 _mesa_error(ctx
, GL_INVALID_VALUE
,
1638 "glFramebufferTexture%sEXT(layer)", caller
);
1644 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1645 _mesa_error(ctx
, GL_INVALID_VALUE
,
1646 "glFramebufferTexture%sEXT(level)", caller
);
1651 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1653 _mesa_error(ctx
, GL_INVALID_ENUM
,
1654 "glFramebufferTexture%sEXT(attachment)", caller
);
1658 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1660 _glthread_LOCK_MUTEX(fb
->Mutex
);
1662 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1664 /* Set the render-to-texture flag. We'll check this flag in
1665 * glTexImage() and friends to determine if we need to revalidate
1666 * any FBOs that might be rendering into this texture.
1667 * This flag never gets cleared since it's non-trivial to determine
1668 * when all FBOs might be done rendering to this texture. That's OK
1669 * though since it's uncommon to render to a texture then repeatedly
1670 * call glTexImage() to change images in the texture.
1672 texObj
->_RenderToTexture
= GL_TRUE
;
1675 _mesa_remove_attachment(ctx
, att
);
1678 invalidate_framebuffer(fb
);
1680 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1686 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1687 GLenum textarget
, GLuint texture
, GLint level
)
1689 GET_CURRENT_CONTEXT(ctx
);
1691 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1692 _mesa_error(ctx
, GL_INVALID_ENUM
,
1693 "glFramebufferTexture1DEXT(textarget)");
1697 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1703 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1704 GLenum textarget
, GLuint texture
, GLint level
)
1706 GET_CURRENT_CONTEXT(ctx
);
1708 if ((texture
!= 0) &&
1709 (textarget
!= GL_TEXTURE_2D
) &&
1710 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1711 (!IS_CUBE_FACE(textarget
))) {
1712 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1713 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
1717 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1723 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1724 GLenum textarget
, GLuint texture
,
1725 GLint level
, GLint zoffset
)
1727 GET_CURRENT_CONTEXT(ctx
);
1729 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1730 _mesa_error(ctx
, GL_INVALID_ENUM
,
1731 "glFramebufferTexture3DEXT(textarget)");
1735 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1741 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1742 GLuint texture
, GLint level
, GLint layer
)
1744 GET_CURRENT_CONTEXT(ctx
);
1746 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1752 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1753 GLenum renderbufferTarget
,
1754 GLuint renderbuffer
)
1756 struct gl_renderbuffer_attachment
*att
;
1757 struct gl_framebuffer
*fb
;
1758 struct gl_renderbuffer
*rb
;
1759 GET_CURRENT_CONTEXT(ctx
);
1761 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1764 #if FEATURE_EXT_framebuffer_blit
1765 case GL_DRAW_FRAMEBUFFER_EXT
:
1766 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1767 _mesa_error(ctx
, GL_INVALID_ENUM
,
1768 "glFramebufferRenderbufferEXT(target)");
1771 fb
= ctx
->DrawBuffer
;
1773 case GL_READ_FRAMEBUFFER_EXT
:
1774 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1775 _mesa_error(ctx
, GL_INVALID_ENUM
,
1776 "glFramebufferRenderbufferEXT(target)");
1779 fb
= ctx
->ReadBuffer
;
1782 case GL_FRAMEBUFFER_EXT
:
1783 fb
= ctx
->DrawBuffer
;
1786 _mesa_error(ctx
, GL_INVALID_ENUM
,
1787 "glFramebufferRenderbufferEXT(target)");
1791 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1792 _mesa_error(ctx
, GL_INVALID_ENUM
,
1793 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1797 if (fb
->Name
== 0) {
1798 /* Can't attach new renderbuffers to a window system framebuffer */
1799 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1803 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1805 _mesa_error(ctx
, GL_INVALID_ENUM
,
1806 "glFramebufferRenderbufferEXT(invalid attachment %s)",
1807 _mesa_lookup_enum_by_nr(attachment
));
1812 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1814 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1815 "glFramebufferRenderbufferEXT(non-existant"
1816 " renderbuffer %u)", renderbuffer
);
1821 /* remove renderbuffer attachment */
1825 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
1826 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
1827 /* make sure the renderbuffer is a depth/stencil format */
1828 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
1829 if (baseFormat
!= GL_DEPTH_STENCIL
) {
1830 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1831 "glFramebufferRenderbufferEXT(renderbuffer"
1832 " is not DEPTH_STENCIL format)");
1838 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1840 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1841 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1843 /* Some subsequent GL commands may depend on the framebuffer's visual
1844 * after the binding is updated. Update visual info now.
1846 _mesa_update_framebuffer_visual(fb
);
1851 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1852 GLenum pname
, GLint
*params
)
1854 const struct gl_renderbuffer_attachment
*att
;
1855 struct gl_framebuffer
*buffer
;
1856 GET_CURRENT_CONTEXT(ctx
);
1858 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1861 #if FEATURE_EXT_framebuffer_blit
1862 case GL_DRAW_FRAMEBUFFER_EXT
:
1863 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1864 _mesa_error(ctx
, GL_INVALID_ENUM
,
1865 "glGetFramebufferAttachmentParameterivEXT(target)");
1868 buffer
= ctx
->DrawBuffer
;
1870 case GL_READ_FRAMEBUFFER_EXT
:
1871 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1872 _mesa_error(ctx
, GL_INVALID_ENUM
,
1873 "glGetFramebufferAttachmentParameterivEXT(target)");
1876 buffer
= ctx
->ReadBuffer
;
1879 case GL_FRAMEBUFFER_EXT
:
1880 buffer
= ctx
->DrawBuffer
;
1883 _mesa_error(ctx
, GL_INVALID_ENUM
,
1884 "glGetFramebufferAttachmentParameterivEXT(target)");
1888 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1890 _mesa_error(ctx
, GL_INVALID_ENUM
,
1891 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1895 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
1896 /* the depth and stencil attachments must point to the same buffer */
1897 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
1898 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
1899 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
1900 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
1901 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1902 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
1903 " attachments differ)");
1908 /* No need to flush here */
1911 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1912 *params
= att
->Type
;
1914 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1915 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1916 *params
= att
->Renderbuffer
->Name
;
1918 else if (att
->Type
== GL_TEXTURE
) {
1919 *params
= att
->Texture
->Name
;
1922 _mesa_error(ctx
, GL_INVALID_ENUM
,
1923 "glGetFramebufferAttachmentParameterivEXT(pname)");
1926 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1927 if (att
->Type
== GL_TEXTURE
) {
1928 *params
= att
->TextureLevel
;
1931 _mesa_error(ctx
, GL_INVALID_ENUM
,
1932 "glGetFramebufferAttachmentParameterivEXT(pname)");
1935 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
1936 if (att
->Type
== GL_TEXTURE
) {
1937 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
1938 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
1945 _mesa_error(ctx
, GL_INVALID_ENUM
,
1946 "glGetFramebufferAttachmentParameterivEXT(pname)");
1949 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
1950 if (att
->Type
== GL_TEXTURE
) {
1951 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
1952 *params
= att
->Zoffset
;
1959 _mesa_error(ctx
, GL_INVALID_ENUM
,
1960 "glGetFramebufferAttachmentParameterivEXT(pname)");
1963 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
1964 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1965 _mesa_error(ctx
, GL_INVALID_ENUM
,
1966 "glGetFramebufferAttachmentParameterivEXT(pname)");
1969 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
1972 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
1973 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1974 _mesa_error(ctx
, GL_INVALID_ENUM
,
1975 "glGetFramebufferAttachmentParameterivEXT(pname)");
1979 gl_format format
= att
->Renderbuffer
->Format
;
1980 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
1985 *params
= _mesa_get_format_datatype(format
);
1989 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1990 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1991 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1992 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1993 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1994 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1995 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
1996 _mesa_error(ctx
, GL_INVALID_ENUM
,
1997 "glGetFramebufferAttachmentParameterivEXT(pname)");
1999 else if (att
->Texture
) {
2000 const struct gl_texture_image
*texImage
=
2001 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2004 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2005 texImage
->TexFormat
);
2011 else if (att
->Renderbuffer
) {
2012 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2013 att
->Renderbuffer
->Format
);
2020 _mesa_error(ctx
, GL_INVALID_ENUM
,
2021 "glGetFramebufferAttachmentParameterivEXT(pname)");
2028 _mesa_GenerateMipmapEXT(GLenum target
)
2030 struct gl_texture_object
*texObj
;
2031 GET_CURRENT_CONTEXT(ctx
);
2033 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2034 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2040 case GL_TEXTURE_CUBE_MAP
:
2041 /* OK, legal value */
2044 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2048 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2050 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2055 _mesa_lock_texture(ctx
, texObj
);
2056 if (target
== GL_TEXTURE_CUBE_MAP
) {
2058 for (face
= 0; face
< 6; face
++)
2059 ctx
->Driver
.GenerateMipmap(ctx
,
2060 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2064 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2066 _mesa_unlock_texture(ctx
, texObj
);
2070 #if FEATURE_EXT_framebuffer_blit
2072 static const struct gl_renderbuffer_attachment
*
2073 find_attachment(const struct gl_framebuffer
*fb
, const struct gl_renderbuffer
*rb
)
2076 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2077 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2078 return &fb
->Attachment
[i
];
2086 * Blit rectangular region, optionally from one framebuffer to another.
2088 * Note, if the src buffer is multisampled and the dest is not, this is
2089 * when the samples must be resolved to a single color.
2092 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2093 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2094 GLbitfield mask
, GLenum filter
)
2096 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2097 GL_DEPTH_BUFFER_BIT
|
2098 GL_STENCIL_BUFFER_BIT
);
2099 const struct gl_framebuffer
*readFb
, *drawFb
;
2100 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2101 GET_CURRENT_CONTEXT(ctx
);
2103 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2104 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2106 if (ctx
->NewState
) {
2107 _mesa_update_state(ctx
);
2110 readFb
= ctx
->ReadBuffer
;
2111 drawFb
= ctx
->DrawBuffer
;
2113 if (!readFb
|| !drawFb
) {
2114 /* This will normally never happen but someday we may want to
2115 * support MakeCurrent() with no drawables.
2120 /* check for complete framebuffers */
2121 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2122 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2123 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2124 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2128 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2129 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2133 if (mask
& ~legalMaskBits
) {
2134 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2138 /* depth/stencil must be blitted with nearest filtering */
2139 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2140 && filter
!= GL_NEAREST
) {
2141 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2142 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
2146 /* get color read/draw renderbuffers */
2147 if (mask
& GL_COLOR_BUFFER_BIT
) {
2148 colorReadRb
= readFb
->_ColorReadBuffer
;
2149 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2152 colorReadRb
= colorDrawRb
= NULL
;
2155 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2156 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2157 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2160 _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2161 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2162 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2163 "glBlitFramebufferEXT(stencil buffer size mismatch");
2168 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2169 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2170 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2173 _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2174 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2175 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2176 "glBlitFramebufferEXT(depth buffer size mismatch");
2181 if (readFb
->Visual
.samples
> 0 &&
2182 drawFb
->Visual
.samples
> 0 &&
2183 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2184 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2185 "glBlitFramebufferEXT(mismatched samples");
2189 /* extra checks for multisample copies... */
2190 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2191 /* src and dest region sizes must be the same */
2192 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2193 srcY1
- srcY0
!= dstY1
- dstY0
) {
2194 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2195 "glBlitFramebufferEXT(bad src/dst multisample region sizes");
2199 /* color formats must match */
2202 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2203 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2204 "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
2209 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2210 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2216 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2218 srcX0
, srcY0
, srcX1
, srcY1
,
2219 dstX0
, dstY0
, dstX1
, dstY1
,
2222 const struct gl_renderbuffer_attachment
*att
;
2224 att
= find_attachment(readFb
, colorReadRb
);
2225 printf(" Src FBO %u RB %u (%dx%d) ",
2226 readFb
->Name
, colorReadRb
->Name
,
2227 colorReadRb
->Width
, colorReadRb
->Height
);
2228 if (att
&& att
->Texture
) {
2229 printf("Tex %u tgt 0x%x level %u face %u",
2231 att
->Texture
->Target
,
2237 att
= find_attachment(drawFb
, colorDrawRb
);
2238 printf(" Dst FBO %u RB %u (%dx%d) ",
2239 drawFb
->Name
, colorDrawRb
->Name
,
2240 colorDrawRb
->Width
, colorDrawRb
->Height
);
2241 if (att
&& att
->Texture
) {
2242 printf("Tex %u tgt 0x%x level %u face %u",
2244 att
->Texture
->Target
,
2252 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2253 ctx
->Driver
.BlitFramebuffer(ctx
,
2254 srcX0
, srcY0
, srcX1
, srcY1
,
2255 dstX0
, dstY0
, dstX1
, dstY1
,
2258 #endif /* FEATURE_EXT_framebuffer_blit */