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
;
74 /* We bind this framebuffer when applications pass a NULL
75 * drawable/surface in make current. */
76 static struct gl_framebuffer IncompleteFramebuffer
;
79 #define IS_CUBE_FACE(TARGET) \
80 ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
81 (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
85 delete_dummy_renderbuffer(struct gl_renderbuffer
*rb
)
91 delete_dummy_framebuffer(struct gl_framebuffer
*fb
)
98 _mesa_init_fbobjects(struct gl_context
*ctx
)
100 _glthread_INIT_MUTEX(DummyFramebuffer
.Mutex
);
101 _glthread_INIT_MUTEX(DummyRenderbuffer
.Mutex
);
102 _glthread_INIT_MUTEX(IncompleteFramebuffer
.Mutex
);
103 DummyFramebuffer
.Delete
= delete_dummy_framebuffer
;
104 DummyRenderbuffer
.Delete
= delete_dummy_renderbuffer
;
105 IncompleteFramebuffer
.Delete
= delete_dummy_framebuffer
;
108 struct gl_framebuffer
*
109 _mesa_get_incomplete_framebuffer(void)
111 return &IncompleteFramebuffer
;
115 * Helper routine for getting a gl_renderbuffer.
117 struct gl_renderbuffer
*
118 _mesa_lookup_renderbuffer(struct gl_context
*ctx
, GLuint id
)
120 struct gl_renderbuffer
*rb
;
125 rb
= (struct gl_renderbuffer
*)
126 _mesa_HashLookup(ctx
->Shared
->RenderBuffers
, id
);
132 * Helper routine for getting a gl_framebuffer.
134 struct gl_framebuffer
*
135 _mesa_lookup_framebuffer(struct gl_context
*ctx
, GLuint id
)
137 struct gl_framebuffer
*fb
;
142 fb
= (struct gl_framebuffer
*)
143 _mesa_HashLookup(ctx
->Shared
->FrameBuffers
, id
);
149 * Mark the given framebuffer as invalid. This will force the
150 * test for framebuffer completeness to be done before the framebuffer
154 invalidate_framebuffer(struct gl_framebuffer
*fb
)
156 fb
->_Status
= 0; /* "indeterminate" */
161 * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
162 * gl_renderbuffer_attachment object.
163 * This function is only used for user-created FB objects, not the
164 * default / window-system FB object.
165 * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
166 * the depth buffer attachment point.
168 struct gl_renderbuffer_attachment
*
169 _mesa_get_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
174 assert(fb
->Name
> 0);
176 switch (attachment
) {
177 case GL_COLOR_ATTACHMENT0_EXT
:
178 case GL_COLOR_ATTACHMENT1_EXT
:
179 case GL_COLOR_ATTACHMENT2_EXT
:
180 case GL_COLOR_ATTACHMENT3_EXT
:
181 case GL_COLOR_ATTACHMENT4_EXT
:
182 case GL_COLOR_ATTACHMENT5_EXT
:
183 case GL_COLOR_ATTACHMENT6_EXT
:
184 case GL_COLOR_ATTACHMENT7_EXT
:
185 case GL_COLOR_ATTACHMENT8_EXT
:
186 case GL_COLOR_ATTACHMENT9_EXT
:
187 case GL_COLOR_ATTACHMENT10_EXT
:
188 case GL_COLOR_ATTACHMENT11_EXT
:
189 case GL_COLOR_ATTACHMENT12_EXT
:
190 case GL_COLOR_ATTACHMENT13_EXT
:
191 case GL_COLOR_ATTACHMENT14_EXT
:
192 case GL_COLOR_ATTACHMENT15_EXT
:
193 i
= attachment
- GL_COLOR_ATTACHMENT0_EXT
;
194 if (i
>= ctx
->Const
.MaxColorAttachments
) {
197 return &fb
->Attachment
[BUFFER_COLOR0
+ i
];
198 case GL_DEPTH_STENCIL_ATTACHMENT
:
200 case GL_DEPTH_BUFFER
:
201 /* fall-through / new in GL 3.0 */
202 case GL_DEPTH_ATTACHMENT_EXT
:
203 return &fb
->Attachment
[BUFFER_DEPTH
];
204 case GL_STENCIL_BUFFER
:
205 /* fall-through / new in GL 3.0 */
206 case GL_STENCIL_ATTACHMENT_EXT
:
207 return &fb
->Attachment
[BUFFER_STENCIL
];
215 * As above, but only used for getting attachments of the default /
216 * window-system framebuffer (not user-created framebuffer objects).
218 static struct gl_renderbuffer_attachment
*
219 _mesa_get_fb0_attachment(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
222 assert(fb
->Name
== 0);
224 switch (attachment
) {
226 return &fb
->Attachment
[BUFFER_FRONT_LEFT
];
228 return &fb
->Attachment
[BUFFER_FRONT_RIGHT
];
230 return &fb
->Attachment
[BUFFER_BACK_LEFT
];
232 return &fb
->Attachment
[BUFFER_BACK_RIGHT
];
234 if (fb
->Visual
.numAuxBuffers
== 1) {
235 return &fb
->Attachment
[BUFFER_AUX0
];
238 case GL_DEPTH_BUFFER
:
239 /* fall-through / new in GL 3.0 */
240 case GL_DEPTH_ATTACHMENT_EXT
:
241 return &fb
->Attachment
[BUFFER_DEPTH
];
242 case GL_STENCIL_BUFFER
:
243 /* fall-through / new in GL 3.0 */
244 case GL_STENCIL_ATTACHMENT_EXT
:
245 return &fb
->Attachment
[BUFFER_STENCIL
];
254 * Remove any texture or renderbuffer attached to the given attachment
255 * point. Update reference counts, etc.
258 _mesa_remove_attachment(struct gl_context
*ctx
, struct gl_renderbuffer_attachment
*att
)
260 if (att
->Type
== GL_TEXTURE
) {
261 ASSERT(att
->Texture
);
262 if (ctx
->Driver
.FinishRenderTexture
) {
263 /* tell driver that we're done rendering to this texture. */
264 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
266 _mesa_reference_texobj(&att
->Texture
, NULL
); /* unbind */
267 ASSERT(!att
->Texture
);
269 if (att
->Type
== GL_TEXTURE
|| att
->Type
== GL_RENDERBUFFER_EXT
) {
270 ASSERT(!att
->Texture
);
271 _mesa_reference_renderbuffer(&att
->Renderbuffer
, NULL
); /* unbind */
272 ASSERT(!att
->Renderbuffer
);
275 att
->Complete
= GL_TRUE
;
280 * Bind a texture object to an attachment point.
281 * The previous binding, if any, will be removed first.
284 _mesa_set_texture_attachment(struct gl_context
*ctx
,
285 struct gl_framebuffer
*fb
,
286 struct gl_renderbuffer_attachment
*att
,
287 struct gl_texture_object
*texObj
,
288 GLenum texTarget
, GLuint level
, GLuint zoffset
)
290 if (att
->Texture
== texObj
) {
291 /* re-attaching same texture */
292 ASSERT(att
->Type
== GL_TEXTURE
);
293 if (ctx
->Driver
.FinishRenderTexture
)
294 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
298 if (ctx
->Driver
.FinishRenderTexture
&& att
->Texture
)
299 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
300 _mesa_remove_attachment(ctx
, att
);
301 att
->Type
= GL_TEXTURE
;
302 assert(!att
->Texture
);
303 _mesa_reference_texobj(&att
->Texture
, texObj
);
306 /* always update these fields */
307 att
->TextureLevel
= level
;
308 att
->CubeMapFace
= _mesa_tex_target_to_face(texTarget
);
309 att
->Zoffset
= zoffset
;
310 att
->Complete
= GL_FALSE
;
312 if (att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
313 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
316 invalidate_framebuffer(fb
);
321 * Bind a renderbuffer to an attachment point.
322 * The previous binding, if any, will be removed first.
325 _mesa_set_renderbuffer_attachment(struct gl_context
*ctx
,
326 struct gl_renderbuffer_attachment
*att
,
327 struct gl_renderbuffer
*rb
)
329 /* XXX check if re-doing same attachment, exit early */
330 _mesa_remove_attachment(ctx
, att
);
331 att
->Type
= GL_RENDERBUFFER_EXT
;
332 att
->Texture
= NULL
; /* just to be safe */
333 att
->Complete
= GL_FALSE
;
334 _mesa_reference_renderbuffer(&att
->Renderbuffer
, rb
);
339 * Fallback for ctx->Driver.FramebufferRenderbuffer()
340 * Attach a renderbuffer object to a framebuffer object.
343 _mesa_framebuffer_renderbuffer(struct gl_context
*ctx
, struct gl_framebuffer
*fb
,
344 GLenum attachment
, struct gl_renderbuffer
*rb
)
346 struct gl_renderbuffer_attachment
*att
;
348 _glthread_LOCK_MUTEX(fb
->Mutex
);
350 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
353 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
354 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
355 /* do stencil attachment here (depth already done above) */
356 att
= _mesa_get_attachment(ctx
, fb
, GL_STENCIL_ATTACHMENT_EXT
);
358 _mesa_set_renderbuffer_attachment(ctx
, att
, rb
);
362 _mesa_remove_attachment(ctx
, att
);
365 invalidate_framebuffer(fb
);
367 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
375 att_incomplete(const char *msg
)
378 _mesa_debug(NULL
, "attachment incomplete: %s\n", msg
);
389 fbo_incomplete(const char *msg
, int index
)
392 _mesa_debug(NULL
, "FBO Incomplete: %s [%d]\n", msg
, index
);
403 * Test if an attachment point is complete and update its Complete field.
404 * \param format if GL_COLOR, this is a color attachment point,
405 * if GL_DEPTH, this is a depth component attachment point,
406 * if GL_STENCIL, this is a stencil component attachment point.
409 test_attachment_completeness(const struct gl_context
*ctx
, GLenum format
,
410 struct gl_renderbuffer_attachment
*att
)
412 assert(format
== GL_COLOR
|| format
== GL_DEPTH
|| format
== GL_STENCIL
);
414 /* assume complete */
415 att
->Complete
= GL_TRUE
;
417 /* Look for reasons why the attachment might be incomplete */
418 if (att
->Type
== GL_TEXTURE
) {
419 const struct gl_texture_object
*texObj
= att
->Texture
;
420 struct gl_texture_image
*texImage
;
424 att_incomplete("no texobj");
425 att
->Complete
= GL_FALSE
;
429 texImage
= texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
431 att_incomplete("no teximage");
432 att
->Complete
= GL_FALSE
;
435 if (texImage
->Width
< 1 || texImage
->Height
< 1) {
436 att_incomplete("teximage width/height=0");
437 printf("texobj = %u\n", texObj
->Name
);
438 printf("level = %d\n", att
->TextureLevel
);
439 att
->Complete
= GL_FALSE
;
442 if (texObj
->Target
== GL_TEXTURE_3D
&& att
->Zoffset
>= texImage
->Depth
) {
443 att_incomplete("bad z offset");
444 att
->Complete
= GL_FALSE
;
448 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
450 if (format
== GL_COLOR
) {
451 if (baseFormat
!= GL_RGB
&&
452 baseFormat
!= GL_RGBA
&&
453 (!ctx
->Extensions
.ARB_framebuffer_object
||
454 baseFormat
!= GL_ALPHA
) &&
455 (!ctx
->Extensions
.ARB_texture_rg
||
456 baseFormat
!= GL_RED
) &&
457 (!ctx
->Extensions
.ARB_texture_rg
||
458 baseFormat
!= GL_RG
)) {
459 att_incomplete("bad format");
460 att
->Complete
= GL_FALSE
;
463 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
464 att_incomplete("compressed internalformat");
465 att
->Complete
= GL_FALSE
;
469 else if (format
== GL_DEPTH
) {
470 if (baseFormat
== GL_DEPTH_COMPONENT
) {
473 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
474 ctx
->Extensions
.ARB_depth_texture
&&
475 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
479 att
->Complete
= GL_FALSE
;
480 att_incomplete("bad depth format");
485 ASSERT(format
== GL_STENCIL
);
486 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
487 ctx
->Extensions
.ARB_depth_texture
&&
488 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
492 /* no such thing as stencil-only textures */
493 att_incomplete("illegal stencil texture");
494 att
->Complete
= GL_FALSE
;
499 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
500 const GLenum baseFormat
=
501 _mesa_get_format_base_format(att
->Renderbuffer
->Format
);
503 ASSERT(att
->Renderbuffer
);
504 if (!att
->Renderbuffer
->InternalFormat
||
505 att
->Renderbuffer
->Width
< 1 ||
506 att
->Renderbuffer
->Height
< 1) {
507 att_incomplete("0x0 renderbuffer");
508 att
->Complete
= GL_FALSE
;
511 if (format
== GL_COLOR
) {
512 if (baseFormat
!= GL_RGB
&&
513 baseFormat
!= GL_RGBA
) {
514 att_incomplete("bad renderbuffer color format");
515 att
->Complete
= GL_FALSE
;
519 else if (format
== GL_DEPTH
) {
520 if (baseFormat
== GL_DEPTH_COMPONENT
) {
523 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
524 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
528 att_incomplete("bad renderbuffer depth format");
529 att
->Complete
= GL_FALSE
;
534 assert(format
== GL_STENCIL
);
535 if (baseFormat
== GL_STENCIL_INDEX
) {
538 else if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
539 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
543 att
->Complete
= GL_FALSE
;
544 att_incomplete("bad renderbuffer stencil format");
550 ASSERT(att
->Type
== GL_NONE
);
558 * Test if the given framebuffer object is complete and update its
559 * Status field with the results.
560 * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
561 * driver to make hardware-specific validation/completeness checks.
562 * Also update the framebuffer's Width and Height fields if the
563 * framebuffer is complete.
566 _mesa_test_framebuffer_completeness(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
569 GLenum intFormat
= GL_NONE
; /* color buffers' internal format */
570 GLuint minWidth
= ~0, minHeight
= ~0, maxWidth
= 0, maxHeight
= 0;
571 GLint numSamples
= -1;
575 assert(fb
->Name
!= 0);
581 /* Start at -2 to more easily loop over all attachment points.
586 for (i
= -2; i
< (GLint
) ctx
->Const
.MaxColorAttachments
; i
++) {
587 struct gl_renderbuffer_attachment
*att
;
591 * XXX for ARB_fbo, only check color buffers that are named by
592 * GL_READ_BUFFER and GL_DRAW_BUFFERi.
595 /* check for attachment completeness
598 att
= &fb
->Attachment
[BUFFER_DEPTH
];
599 test_attachment_completeness(ctx
, GL_DEPTH
, att
);
600 if (!att
->Complete
) {
601 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
602 fbo_incomplete("depth attachment incomplete", -1);
607 att
= &fb
->Attachment
[BUFFER_STENCIL
];
608 test_attachment_completeness(ctx
, GL_STENCIL
, att
);
609 if (!att
->Complete
) {
610 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
611 fbo_incomplete("stencil attachment incomplete", -1);
616 att
= &fb
->Attachment
[BUFFER_COLOR0
+ i
];
617 test_attachment_completeness(ctx
, GL_COLOR
, att
);
618 if (!att
->Complete
) {
619 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
;
620 fbo_incomplete("color attachment incomplete", i
);
625 /* get width, height, format of the renderbuffer/texture
627 if (att
->Type
== GL_TEXTURE
) {
628 const struct gl_texture_image
*texImg
629 = att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
];
630 minWidth
= MIN2(minWidth
, texImg
->Width
);
631 maxWidth
= MAX2(maxWidth
, texImg
->Width
);
632 minHeight
= MIN2(minHeight
, texImg
->Height
);
633 maxHeight
= MAX2(maxHeight
, texImg
->Height
);
634 f
= texImg
->_BaseFormat
;
636 if (f
!= GL_RGB
&& f
!= GL_RGBA
&& f
!= GL_DEPTH_COMPONENT
637 && f
!= GL_DEPTH_STENCIL_EXT
638 && (!ctx
->Extensions
.ARB_framebuffer_object
|| f
!= GL_ALPHA
)
639 && (!ctx
->Extensions
.ARB_texture_rg
|| f
!= GL_RED
)
640 && (!ctx
->Extensions
.ARB_texture_rg
|| f
!= GL_RG
)) {
641 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
642 fbo_incomplete("texture attachment incomplete", -1);
646 else if (att
->Type
== GL_RENDERBUFFER_EXT
) {
647 minWidth
= MIN2(minWidth
, att
->Renderbuffer
->Width
);
648 maxWidth
= MAX2(minWidth
, att
->Renderbuffer
->Width
);
649 minHeight
= MIN2(minHeight
, att
->Renderbuffer
->Height
);
650 maxHeight
= MAX2(minHeight
, att
->Renderbuffer
->Height
);
651 f
= att
->Renderbuffer
->InternalFormat
;
655 assert(att
->Type
== GL_NONE
);
659 if (numSamples
< 0) {
661 numSamples
= att
->Renderbuffer
->NumSamples
;
664 /* Error-check width, height, format, samples
666 if (numImages
== 1) {
667 /* save format, num samples */
673 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
674 /* check that width, height, format are same */
675 if (minWidth
!= maxWidth
|| minHeight
!= maxHeight
) {
676 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
;
677 fbo_incomplete("width or height mismatch", -1);
680 /* check that all color buffer have same format */
681 if (intFormat
!= GL_NONE
&& f
!= intFormat
) {
682 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
;
683 fbo_incomplete("format mismatch", -1);
687 if (att
->Renderbuffer
&&
688 att
->Renderbuffer
->NumSamples
!= numSamples
) {
689 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
;
690 fbo_incomplete("inconsistant number of samples", i
);
698 if (ctx
->API
== API_OPENGL
) {
699 /* Check that all DrawBuffers are present */
700 for (j
= 0; j
< ctx
->Const
.MaxDrawBuffers
; j
++) {
701 if (fb
->ColorDrawBuffer
[j
] != GL_NONE
) {
702 const struct gl_renderbuffer_attachment
*att
703 = _mesa_get_attachment(ctx
, fb
, fb
->ColorDrawBuffer
[j
]);
705 if (att
->Type
== GL_NONE
) {
706 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
;
707 fbo_incomplete("missing drawbuffer", j
);
713 /* Check that the ReadBuffer is present */
714 if (fb
->ColorReadBuffer
!= GL_NONE
) {
715 const struct gl_renderbuffer_attachment
*att
716 = _mesa_get_attachment(ctx
, fb
, fb
->ColorReadBuffer
);
718 if (att
->Type
== GL_NONE
) {
719 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
;
720 fbo_incomplete("missing readbuffer", -1);
729 if (numImages
== 0) {
730 fb
->_Status
= GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
;
731 fbo_incomplete("no attachments", -1);
735 /* Provisionally set status = COMPLETE ... */
736 fb
->_Status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
738 /* ... but the driver may say the FB is incomplete.
739 * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
742 if (ctx
->Driver
.ValidateFramebuffer
) {
743 ctx
->Driver
.ValidateFramebuffer(ctx
, fb
);
744 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
745 fbo_incomplete("driver marked FBO as incomplete", -1);
749 if (fb
->_Status
== GL_FRAMEBUFFER_COMPLETE_EXT
) {
751 * Note that if ARB_framebuffer_object is supported and the attached
752 * renderbuffers/textures are different sizes, the framebuffer
753 * width/height will be set to the smallest width/height.
755 fb
->Width
= minWidth
;
756 fb
->Height
= minHeight
;
758 /* finally, update the visual info for the framebuffer */
759 _mesa_update_framebuffer_visual(fb
);
765 _mesa_IsRenderbufferEXT(GLuint renderbuffer
)
767 GET_CURRENT_CONTEXT(ctx
);
768 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
770 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
771 if (rb
!= NULL
&& rb
!= &DummyRenderbuffer
)
779 _mesa_BindRenderbufferEXT(GLenum target
, GLuint renderbuffer
)
781 struct gl_renderbuffer
*newRb
;
782 GET_CURRENT_CONTEXT(ctx
);
784 ASSERT_OUTSIDE_BEGIN_END(ctx
);
786 if (target
!= GL_RENDERBUFFER_EXT
) {
787 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindRenderbufferEXT(target)");
791 /* No need to flush here since the render buffer binding has no
792 * effect on rendering state.
796 newRb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
797 if (newRb
== &DummyRenderbuffer
) {
798 /* ID was reserved, but no real renderbuffer object made yet */
801 else if (!newRb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
802 /* All RB IDs must be Gen'd */
803 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindRenderbuffer(buffer)");
808 /* create new renderbuffer object */
809 newRb
= ctx
->Driver
.NewRenderbuffer(ctx
, renderbuffer
);
811 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindRenderbufferEXT");
814 ASSERT(newRb
->AllocStorage
);
815 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, renderbuffer
, newRb
);
816 newRb
->RefCount
= 1; /* referenced by hash table */
823 ASSERT(newRb
!= &DummyRenderbuffer
);
825 _mesa_reference_renderbuffer(&ctx
->CurrentRenderbuffer
, newRb
);
830 * If the given renderbuffer is anywhere attached to the framebuffer, detach
832 * This is used when a renderbuffer object is deleted.
833 * The spec calls for unbinding.
836 detach_renderbuffer(struct gl_context
*ctx
,
837 struct gl_framebuffer
*fb
,
838 struct gl_renderbuffer
*rb
)
841 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
842 if (fb
->Attachment
[i
].Renderbuffer
== rb
) {
843 _mesa_remove_attachment(ctx
, &fb
->Attachment
[i
]);
846 invalidate_framebuffer(fb
);
851 _mesa_DeleteRenderbuffersEXT(GLsizei n
, const GLuint
*renderbuffers
)
854 GET_CURRENT_CONTEXT(ctx
);
856 ASSERT_OUTSIDE_BEGIN_END(ctx
);
857 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
859 for (i
= 0; i
< n
; i
++) {
860 if (renderbuffers
[i
] > 0) {
861 struct gl_renderbuffer
*rb
;
862 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffers
[i
]);
864 /* check if deleting currently bound renderbuffer object */
865 if (rb
== ctx
->CurrentRenderbuffer
) {
867 ASSERT(rb
->RefCount
>= 2);
868 _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT
, 0);
871 if (ctx
->DrawBuffer
->Name
) {
872 detach_renderbuffer(ctx
, ctx
->DrawBuffer
, rb
);
874 if (ctx
->ReadBuffer
->Name
&& ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
875 detach_renderbuffer(ctx
, ctx
->ReadBuffer
, rb
);
878 /* Remove from hash table immediately, to free the ID.
879 * But the object will not be freed until it's no longer
880 * referenced anywhere else.
882 _mesa_HashRemove(ctx
->Shared
->RenderBuffers
, renderbuffers
[i
]);
884 if (rb
!= &DummyRenderbuffer
) {
885 /* no longer referenced by hash table */
886 _mesa_reference_renderbuffer(&rb
, NULL
);
895 _mesa_GenRenderbuffersEXT(GLsizei n
, GLuint
*renderbuffers
)
897 GET_CURRENT_CONTEXT(ctx
);
901 ASSERT_OUTSIDE_BEGIN_END(ctx
);
904 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenRenderbuffersEXT(n)");
911 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->RenderBuffers
, n
);
913 for (i
= 0; i
< n
; i
++) {
914 GLuint name
= first
+ i
;
915 renderbuffers
[i
] = name
;
916 /* insert dummy placeholder into hash table */
917 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
918 _mesa_HashInsert(ctx
->Shared
->RenderBuffers
, name
, &DummyRenderbuffer
);
919 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
925 * Given an internal format token for a render buffer, return the
926 * corresponding base format.
927 * This is very similar to _mesa_base_tex_format() but the set of valid
928 * internal formats is somewhat different.
930 * \return one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT
931 * GL_DEPTH_STENCIL_EXT or zero if error.
933 * XXX in the future when we support red-only and red-green formats
934 * we'll also return GL_RED and GL_RG.
937 _mesa_base_fbo_format(struct gl_context
*ctx
, GLenum internalFormat
)
939 switch (internalFormat
) {
963 case GL_RGBA16_SNORM
:
965 case GL_STENCIL_INDEX
:
966 case GL_STENCIL_INDEX1_EXT
:
967 case GL_STENCIL_INDEX4_EXT
:
968 case GL_STENCIL_INDEX8_EXT
:
969 case GL_STENCIL_INDEX16_EXT
:
970 return GL_STENCIL_INDEX
;
971 case GL_DEPTH_COMPONENT
:
972 case GL_DEPTH_COMPONENT16
:
973 case GL_DEPTH_COMPONENT24
:
974 case GL_DEPTH_COMPONENT32
:
975 return GL_DEPTH_COMPONENT
;
976 case GL_DEPTH_STENCIL_EXT
:
977 case GL_DEPTH24_STENCIL8_EXT
:
978 if (ctx
->Extensions
.EXT_packed_depth_stencil
)
979 return GL_DEPTH_STENCIL_EXT
;
982 /* XXX add floating point formats eventually */
989 /** sentinal value, see below */
990 #define NO_SAMPLES 1000
994 * Helper function used by _mesa_RenderbufferStorageEXT() and
995 * _mesa_RenderbufferStorageMultisample().
996 * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
999 renderbuffer_storage(GLenum target
, GLenum internalFormat
,
1000 GLsizei width
, GLsizei height
, GLsizei samples
)
1002 const char *func
= samples
== NO_SAMPLES
?
1003 "glRenderbufferStorage" : "RenderbufferStorageMultisample";
1004 struct gl_renderbuffer
*rb
;
1006 GET_CURRENT_CONTEXT(ctx
);
1008 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1010 if (target
!= GL_RENDERBUFFER_EXT
) {
1011 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
1015 baseFormat
= _mesa_base_fbo_format(ctx
, internalFormat
);
1016 if (baseFormat
== 0) {
1017 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat)", func
);
1021 if (width
< 1 || width
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1022 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width)", func
);
1026 if (height
< 1 || height
> (GLsizei
) ctx
->Const
.MaxRenderbufferSize
) {
1027 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height)", func
);
1031 if (samples
== NO_SAMPLES
) {
1032 /* NumSamples == 0 indicates non-multisampling */
1035 else if (samples
> (GLsizei
) ctx
->Const
.MaxSamples
) {
1036 /* note: driver may choose to use more samples than what's requested */
1037 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples)", func
);
1041 rb
= ctx
->CurrentRenderbuffer
;
1043 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1047 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1049 if (rb
->InternalFormat
== internalFormat
&&
1050 rb
->Width
== (GLuint
) width
&&
1051 rb
->Height
== (GLuint
) height
) {
1052 /* no change in allocation needed */
1056 /* These MUST get set by the AllocStorage func */
1057 rb
->Format
= MESA_FORMAT_NONE
;
1058 rb
->NumSamples
= samples
;
1060 /* Now allocate the storage */
1061 ASSERT(rb
->AllocStorage
);
1062 if (rb
->AllocStorage(ctx
, rb
, internalFormat
, width
, height
)) {
1063 /* No error - check/set fields now */
1064 assert(rb
->Format
!= MESA_FORMAT_NONE
);
1065 assert(rb
->Width
== (GLuint
) width
);
1066 assert(rb
->Height
== (GLuint
) height
);
1067 rb
->InternalFormat
= internalFormat
;
1068 rb
->_BaseFormat
= baseFormat
;
1069 assert(rb
->_BaseFormat
!= 0);
1072 /* Probably ran out of memory - clear the fields */
1075 rb
->Format
= MESA_FORMAT_NONE
;
1076 rb
->InternalFormat
= GL_NONE
;
1077 rb
->_BaseFormat
= GL_NONE
;
1082 test_framebuffer_completeness(ctx, fb);
1084 /* XXX if this renderbuffer is attached anywhere, invalidate attachment
1090 #if FEATURE_OES_EGL_image
1092 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target
, GLeglImageOES image
)
1094 struct gl_renderbuffer
*rb
;
1095 GET_CURRENT_CONTEXT(ctx
);
1096 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1098 if (!ctx
->Extensions
.OES_EGL_image
) {
1099 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1100 "glEGLImageTargetRenderbufferStorageOES(unsupported)");
1104 if (target
!= GL_RENDERBUFFER
) {
1105 _mesa_error(ctx
, GL_INVALID_ENUM
,
1106 "EGLImageTargetRenderbufferStorageOES");
1110 rb
= ctx
->CurrentRenderbuffer
;
1112 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1113 "EGLImageTargetRenderbufferStorageOES");
1117 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1119 ctx
->Driver
.EGLImageTargetRenderbufferStorage(ctx
, rb
, image
);
1125 * Helper function for _mesa_GetRenderbufferParameterivEXT() and
1126 * _mesa_GetFramebufferAttachmentParameterivEXT()
1127 * We have to be careful to respect the base format. For example, if a
1128 * renderbuffer/texture was created with internalFormat=GL_RGB but the
1129 * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
1130 * we need to return zero.
1133 get_component_bits(GLenum pname
, GLenum baseFormat
, gl_format format
)
1136 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1137 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1138 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1139 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1140 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1141 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1142 if (baseFormat
== GL_RGB
|| baseFormat
== GL_RGBA
)
1143 return _mesa_get_format_bits(format
, pname
);
1146 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1147 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1148 if (baseFormat
== GL_RGBA
|| baseFormat
== GL_ALPHA
)
1149 return _mesa_get_format_bits(format
, pname
);
1152 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1153 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1154 if (baseFormat
== GL_DEPTH_COMPONENT
|| baseFormat
== GL_DEPTH_STENCIL
)
1155 return _mesa_get_format_bits(format
, pname
);
1158 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1159 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1160 if (baseFormat
== GL_STENCIL_INDEX
|| baseFormat
== GL_DEPTH_STENCIL
)
1161 return _mesa_get_format_bits(format
, pname
);
1172 _mesa_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1173 GLsizei width
, GLsizei height
)
1175 /* GL_ARB_fbo says calling this function is equivalent to calling
1176 * glRenderbufferStorageMultisample() with samples=0. We pass in
1177 * a token value here just for error reporting purposes.
1179 renderbuffer_storage(target
, internalFormat
, width
, height
, NO_SAMPLES
);
1184 _mesa_RenderbufferStorageMultisample(GLenum target
, GLsizei samples
,
1185 GLenum internalFormat
,
1186 GLsizei width
, GLsizei height
)
1188 renderbuffer_storage(target
, internalFormat
, width
, height
, samples
);
1193 * OpenGL ES version of glRenderBufferStorage.
1196 _es_RenderbufferStorageEXT(GLenum target
, GLenum internalFormat
,
1197 GLsizei width
, GLsizei height
)
1199 switch (internalFormat
) {
1201 /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
1202 /* choose a closest format */
1203 internalFormat
= GL_RGB5
;
1209 renderbuffer_storage(target
, internalFormat
, width
, height
, 0);
1214 _mesa_GetRenderbufferParameterivEXT(GLenum target
, GLenum pname
, GLint
*params
)
1216 struct gl_renderbuffer
*rb
;
1217 GET_CURRENT_CONTEXT(ctx
);
1219 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1221 if (target
!= GL_RENDERBUFFER_EXT
) {
1222 _mesa_error(ctx
, GL_INVALID_ENUM
,
1223 "glGetRenderbufferParameterivEXT(target)");
1227 rb
= ctx
->CurrentRenderbuffer
;
1229 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1230 "glGetRenderbufferParameterivEXT");
1234 /* No need to flush here since we're just quering state which is
1235 * not effected by rendering.
1239 case GL_RENDERBUFFER_WIDTH_EXT
:
1240 *params
= rb
->Width
;
1242 case GL_RENDERBUFFER_HEIGHT_EXT
:
1243 *params
= rb
->Height
;
1245 case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT
:
1246 *params
= rb
->InternalFormat
;
1248 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1249 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1250 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1251 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1252 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1253 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1254 *params
= get_component_bits(pname
, rb
->_BaseFormat
, rb
->Format
);
1256 case GL_RENDERBUFFER_SAMPLES
:
1257 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1258 *params
= rb
->NumSamples
;
1263 _mesa_error(ctx
, GL_INVALID_ENUM
,
1264 "glGetRenderbufferParameterivEXT(target)");
1270 GLboolean GLAPIENTRY
1271 _mesa_IsFramebufferEXT(GLuint framebuffer
)
1273 GET_CURRENT_CONTEXT(ctx
);
1274 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1276 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1277 if (rb
!= NULL
&& rb
!= &DummyFramebuffer
)
1285 * Check if any of the attachments of the given framebuffer are textures
1286 * (render to texture). Call ctx->Driver.RenderTexture() for such
1290 check_begin_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1293 ASSERT(ctx
->Driver
.RenderTexture
);
1296 return; /* can't render to texture with winsys framebuffers */
1298 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1299 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1300 struct gl_texture_object
*texObj
= att
->Texture
;
1302 && texObj
->Image
[att
->CubeMapFace
][att
->TextureLevel
]) {
1303 ctx
->Driver
.RenderTexture(ctx
, fb
, att
);
1310 * Examine all the framebuffer's attachments to see if any are textures.
1311 * If so, call ctx->Driver.FinishRenderTexture() for each texture to
1312 * notify the device driver that the texture image may have changed.
1315 check_end_texture_render(struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
1318 return; /* can't render to texture with winsys framebuffers */
1320 if (ctx
->Driver
.FinishRenderTexture
) {
1322 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1323 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1324 if (att
->Texture
&& att
->Renderbuffer
) {
1325 ctx
->Driver
.FinishRenderTexture(ctx
, att
);
1333 _mesa_BindFramebufferEXT(GLenum target
, GLuint framebuffer
)
1335 struct gl_framebuffer
*newDrawFb
, *newReadFb
;
1336 struct gl_framebuffer
*oldDrawFb
, *oldReadFb
;
1337 GLboolean bindReadBuf
, bindDrawBuf
;
1338 GET_CURRENT_CONTEXT(ctx
);
1341 if (ctx
->Extensions
.ARB_framebuffer_object
) {
1342 ASSERT(ctx
->Extensions
.EXT_framebuffer_object
);
1343 ASSERT(ctx
->Extensions
.EXT_framebuffer_blit
);
1347 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1349 if (!ctx
->Extensions
.EXT_framebuffer_object
) {
1350 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1351 "glBindFramebufferEXT(unsupported)");
1356 #if FEATURE_EXT_framebuffer_blit
1357 case GL_DRAW_FRAMEBUFFER_EXT
:
1358 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1359 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1362 bindDrawBuf
= GL_TRUE
;
1363 bindReadBuf
= GL_FALSE
;
1365 case GL_READ_FRAMEBUFFER_EXT
:
1366 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1367 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1370 bindDrawBuf
= GL_FALSE
;
1371 bindReadBuf
= GL_TRUE
;
1374 case GL_FRAMEBUFFER_EXT
:
1375 bindDrawBuf
= GL_TRUE
;
1376 bindReadBuf
= GL_TRUE
;
1379 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindFramebufferEXT(target)");
1384 /* Binding a user-created framebuffer object */
1385 newDrawFb
= _mesa_lookup_framebuffer(ctx
, framebuffer
);
1386 if (newDrawFb
== &DummyFramebuffer
) {
1387 /* ID was reserved, but no real framebuffer object made yet */
1390 else if (!newDrawFb
&& ctx
->Extensions
.ARB_framebuffer_object
) {
1391 /* All FBO IDs must be Gen'd */
1392 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFramebuffer(buffer)");
1397 /* create new framebuffer object */
1398 newDrawFb
= ctx
->Driver
.NewFramebuffer(ctx
, framebuffer
);
1400 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindFramebufferEXT");
1403 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, framebuffer
, newDrawFb
);
1405 newReadFb
= newDrawFb
;
1408 /* Binding the window system framebuffer (which was originally set
1409 * with MakeCurrent).
1411 newDrawFb
= ctx
->WinSysDrawBuffer
;
1412 newReadFb
= ctx
->WinSysReadBuffer
;
1416 ASSERT(newDrawFb
!= &DummyFramebuffer
);
1418 /* save pointers to current/old framebuffers */
1419 oldDrawFb
= ctx
->DrawBuffer
;
1420 oldReadFb
= ctx
->ReadBuffer
;
1422 /* check if really changing bindings */
1423 if (oldDrawFb
== newDrawFb
)
1424 bindDrawBuf
= GL_FALSE
;
1425 if (oldReadFb
== newReadFb
)
1426 bindReadBuf
= GL_FALSE
;
1429 * OK, now bind the new Draw/Read framebuffers, if they're changing.
1431 * We also check if we're beginning and/or ending render-to-texture.
1432 * When a framebuffer with texture attachments is unbound, call
1433 * ctx->Driver.FinishRenderTexture().
1434 * When a framebuffer with texture attachments is bound, call
1435 * ctx->Driver.RenderTexture().
1437 * Note that if the ReadBuffer has texture attachments we don't consider
1438 * that a render-to-texture case.
1441 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1443 /* check if old readbuffer was render-to-texture */
1444 check_end_texture_render(ctx
, oldReadFb
);
1446 _mesa_reference_framebuffer(&ctx
->ReadBuffer
, newReadFb
);
1450 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1452 /* check if old read/draw buffers were render-to-texture */
1454 check_end_texture_render(ctx
, oldReadFb
);
1456 if (oldDrawFb
!= oldReadFb
)
1457 check_end_texture_render(ctx
, oldDrawFb
);
1459 /* check if newly bound framebuffer has any texture attachments */
1460 check_begin_texture_render(ctx
, newDrawFb
);
1462 _mesa_reference_framebuffer(&ctx
->DrawBuffer
, newDrawFb
);
1465 if ((bindDrawBuf
|| bindReadBuf
) && ctx
->Driver
.BindFramebuffer
) {
1466 ctx
->Driver
.BindFramebuffer(ctx
, target
, newDrawFb
, newReadFb
);
1472 _mesa_DeleteFramebuffersEXT(GLsizei n
, const GLuint
*framebuffers
)
1475 GET_CURRENT_CONTEXT(ctx
);
1477 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1478 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1480 for (i
= 0; i
< n
; i
++) {
1481 if (framebuffers
[i
] > 0) {
1482 struct gl_framebuffer
*fb
;
1483 fb
= _mesa_lookup_framebuffer(ctx
, framebuffers
[i
]);
1485 ASSERT(fb
== &DummyFramebuffer
|| fb
->Name
== framebuffers
[i
]);
1487 /* check if deleting currently bound framebuffer object */
1488 if (ctx
->Extensions
.EXT_framebuffer_blit
) {
1489 /* separate draw/read binding points */
1490 if (fb
== ctx
->DrawBuffer
) {
1492 ASSERT(fb
->RefCount
>= 2);
1493 _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0);
1495 if (fb
== ctx
->ReadBuffer
) {
1497 ASSERT(fb
->RefCount
>= 2);
1498 _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT
, 0);
1502 /* only one binding point for read/draw buffers */
1503 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
) {
1505 ASSERT(fb
->RefCount
>= 2);
1506 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
1510 /* remove from hash table immediately, to free the ID */
1511 _mesa_HashRemove(ctx
->Shared
->FrameBuffers
, framebuffers
[i
]);
1513 if (fb
!= &DummyFramebuffer
) {
1514 /* But the object will not be freed until it's no longer
1515 * bound in any context.
1517 _mesa_reference_framebuffer(&fb
, NULL
);
1526 _mesa_GenFramebuffersEXT(GLsizei n
, GLuint
*framebuffers
)
1528 GET_CURRENT_CONTEXT(ctx
);
1532 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1535 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenFramebuffersEXT(n)");
1542 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->FrameBuffers
, n
);
1544 for (i
= 0; i
< n
; i
++) {
1545 GLuint name
= first
+ i
;
1546 framebuffers
[i
] = name
;
1547 /* insert dummy placeholder into hash table */
1548 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1549 _mesa_HashInsert(ctx
->Shared
->FrameBuffers
, name
, &DummyFramebuffer
);
1550 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1557 _mesa_CheckFramebufferStatusEXT(GLenum target
)
1559 struct gl_framebuffer
*buffer
;
1560 GET_CURRENT_CONTEXT(ctx
);
1562 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1565 #if FEATURE_EXT_framebuffer_blit
1566 case GL_DRAW_FRAMEBUFFER_EXT
:
1567 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1568 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1571 buffer
= ctx
->DrawBuffer
;
1573 case GL_READ_FRAMEBUFFER_EXT
:
1574 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1575 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1578 buffer
= ctx
->ReadBuffer
;
1581 case GL_FRAMEBUFFER_EXT
:
1582 buffer
= ctx
->DrawBuffer
;
1585 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCheckFramebufferStatus(target)");
1586 return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
1589 if (buffer
->Name
== 0) {
1590 /* The window system / default framebuffer is always complete */
1591 return GL_FRAMEBUFFER_COMPLETE_EXT
;
1594 /* No need to flush here */
1596 if (buffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE
) {
1597 _mesa_test_framebuffer_completeness(ctx
, buffer
);
1600 return buffer
->_Status
;
1606 * Common code called by glFramebufferTexture1D/2D/3DEXT().
1609 framebuffer_texture(struct gl_context
*ctx
, const char *caller
, GLenum target
,
1610 GLenum attachment
, GLenum textarget
, GLuint texture
,
1611 GLint level
, GLint zoffset
)
1613 struct gl_renderbuffer_attachment
*att
;
1614 struct gl_texture_object
*texObj
= NULL
;
1615 struct gl_framebuffer
*fb
;
1616 GLboolean error
= GL_FALSE
;
1618 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1621 case GL_READ_FRAMEBUFFER_EXT
:
1622 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1623 fb
= ctx
->ReadBuffer
;
1625 case GL_DRAW_FRAMEBUFFER_EXT
:
1626 error
= !ctx
->Extensions
.EXT_framebuffer_blit
;
1628 case GL_FRAMEBUFFER_EXT
:
1629 fb
= ctx
->DrawBuffer
;
1636 _mesa_error(ctx
, GL_INVALID_ENUM
,
1637 "glFramebufferTexture%sEXT(target=0x%x)", caller
, target
);
1643 /* check framebuffer binding */
1644 if (fb
->Name
== 0) {
1645 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1646 "glFramebufferTexture%sEXT", caller
);
1651 /* The textarget, level, and zoffset parameters are only validated if
1652 * texture is non-zero.
1655 GLboolean err
= GL_TRUE
;
1657 texObj
= _mesa_lookup_texture(ctx
, texture
);
1658 if (texObj
!= NULL
) {
1659 if (textarget
== 0) {
1660 /* XXX what's the purpose of this? */
1661 err
= (texObj
->Target
!= GL_TEXTURE_3D
) &&
1662 (texObj
->Target
!= GL_TEXTURE_1D_ARRAY_EXT
) &&
1663 (texObj
->Target
!= GL_TEXTURE_2D_ARRAY_EXT
);
1666 err
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
)
1667 ? !IS_CUBE_FACE(textarget
)
1668 : (texObj
->Target
!= textarget
);
1672 /* can't render to a non-existant texture */
1673 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1674 "glFramebufferTexture%sEXT(non existant texture)",
1680 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1681 "glFramebufferTexture%sEXT(texture target mismatch)",
1686 if (texObj
->Target
== GL_TEXTURE_3D
) {
1687 const GLint maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1688 if (zoffset
< 0 || zoffset
>= maxSize
) {
1689 _mesa_error(ctx
, GL_INVALID_VALUE
,
1690 "glFramebufferTexture%sEXT(zoffset)", caller
);
1694 else if ((texObj
->Target
== GL_TEXTURE_1D_ARRAY_EXT
) ||
1695 (texObj
->Target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
1696 if (zoffset
< 0 || zoffset
>= ctx
->Const
.MaxArrayTextureLayers
) {
1697 _mesa_error(ctx
, GL_INVALID_VALUE
,
1698 "glFramebufferTexture%sEXT(layer)", caller
);
1704 (level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
))) {
1705 _mesa_error(ctx
, GL_INVALID_VALUE
,
1706 "glFramebufferTexture%sEXT(level)", caller
);
1711 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1713 _mesa_error(ctx
, GL_INVALID_ENUM
,
1714 "glFramebufferTexture%sEXT(attachment)", caller
);
1718 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1720 _glthread_LOCK_MUTEX(fb
->Mutex
);
1722 _mesa_set_texture_attachment(ctx
, fb
, att
, texObj
, textarget
,
1724 /* Set the render-to-texture flag. We'll check this flag in
1725 * glTexImage() and friends to determine if we need to revalidate
1726 * any FBOs that might be rendering into this texture.
1727 * This flag never gets cleared since it's non-trivial to determine
1728 * when all FBOs might be done rendering to this texture. That's OK
1729 * though since it's uncommon to render to a texture then repeatedly
1730 * call glTexImage() to change images in the texture.
1732 texObj
->_RenderToTexture
= GL_TRUE
;
1735 _mesa_remove_attachment(ctx
, att
);
1738 invalidate_framebuffer(fb
);
1740 _glthread_UNLOCK_MUTEX(fb
->Mutex
);
1746 _mesa_FramebufferTexture1DEXT(GLenum target
, GLenum attachment
,
1747 GLenum textarget
, GLuint texture
, GLint level
)
1749 GET_CURRENT_CONTEXT(ctx
);
1751 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_1D
)) {
1752 _mesa_error(ctx
, GL_INVALID_ENUM
,
1753 "glFramebufferTexture1DEXT(textarget)");
1757 framebuffer_texture(ctx
, "1D", target
, attachment
, textarget
, texture
,
1763 _mesa_FramebufferTexture2DEXT(GLenum target
, GLenum attachment
,
1764 GLenum textarget
, GLuint texture
, GLint level
)
1766 GET_CURRENT_CONTEXT(ctx
);
1768 if ((texture
!= 0) &&
1769 (textarget
!= GL_TEXTURE_2D
) &&
1770 (textarget
!= GL_TEXTURE_RECTANGLE_ARB
) &&
1771 (!IS_CUBE_FACE(textarget
))) {
1772 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1773 "glFramebufferTexture2DEXT(textarget=0x%x)", textarget
);
1777 framebuffer_texture(ctx
, "2D", target
, attachment
, textarget
, texture
,
1783 _mesa_FramebufferTexture3DEXT(GLenum target
, GLenum attachment
,
1784 GLenum textarget
, GLuint texture
,
1785 GLint level
, GLint zoffset
)
1787 GET_CURRENT_CONTEXT(ctx
);
1789 if ((texture
!= 0) && (textarget
!= GL_TEXTURE_3D
)) {
1790 _mesa_error(ctx
, GL_INVALID_ENUM
,
1791 "glFramebufferTexture3DEXT(textarget)");
1795 framebuffer_texture(ctx
, "3D", target
, attachment
, textarget
, texture
,
1801 _mesa_FramebufferTextureLayerEXT(GLenum target
, GLenum attachment
,
1802 GLuint texture
, GLint level
, GLint layer
)
1804 GET_CURRENT_CONTEXT(ctx
);
1806 framebuffer_texture(ctx
, "Layer", target
, attachment
, 0, texture
,
1812 _mesa_FramebufferRenderbufferEXT(GLenum target
, GLenum attachment
,
1813 GLenum renderbufferTarget
,
1814 GLuint renderbuffer
)
1816 struct gl_renderbuffer_attachment
*att
;
1817 struct gl_framebuffer
*fb
;
1818 struct gl_renderbuffer
*rb
;
1819 GET_CURRENT_CONTEXT(ctx
);
1821 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1824 #if FEATURE_EXT_framebuffer_blit
1825 case GL_DRAW_FRAMEBUFFER_EXT
:
1826 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1827 _mesa_error(ctx
, GL_INVALID_ENUM
,
1828 "glFramebufferRenderbufferEXT(target)");
1831 fb
= ctx
->DrawBuffer
;
1833 case GL_READ_FRAMEBUFFER_EXT
:
1834 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1835 _mesa_error(ctx
, GL_INVALID_ENUM
,
1836 "glFramebufferRenderbufferEXT(target)");
1839 fb
= ctx
->ReadBuffer
;
1842 case GL_FRAMEBUFFER_EXT
:
1843 fb
= ctx
->DrawBuffer
;
1846 _mesa_error(ctx
, GL_INVALID_ENUM
,
1847 "glFramebufferRenderbufferEXT(target)");
1851 if (renderbufferTarget
!= GL_RENDERBUFFER_EXT
) {
1852 _mesa_error(ctx
, GL_INVALID_ENUM
,
1853 "glFramebufferRenderbufferEXT(renderbufferTarget)");
1857 if (fb
->Name
== 0) {
1858 /* Can't attach new renderbuffers to a window system framebuffer */
1859 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glFramebufferRenderbufferEXT");
1863 att
= _mesa_get_attachment(ctx
, fb
, attachment
);
1865 _mesa_error(ctx
, GL_INVALID_ENUM
,
1866 "glFramebufferRenderbufferEXT(invalid attachment %s)",
1867 _mesa_lookup_enum_by_nr(attachment
));
1872 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
1874 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1875 "glFramebufferRenderbufferEXT(non-existant"
1876 " renderbuffer %u)", renderbuffer
);
1881 /* remove renderbuffer attachment */
1885 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
&&
1886 rb
&& rb
->Format
!= MESA_FORMAT_NONE
) {
1887 /* make sure the renderbuffer is a depth/stencil format */
1888 const GLenum baseFormat
= _mesa_get_format_base_format(rb
->Format
);
1889 if (baseFormat
!= GL_DEPTH_STENCIL
) {
1890 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1891 "glFramebufferRenderbufferEXT(renderbuffer"
1892 " is not DEPTH_STENCIL format)");
1898 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
1900 assert(ctx
->Driver
.FramebufferRenderbuffer
);
1901 ctx
->Driver
.FramebufferRenderbuffer(ctx
, fb
, attachment
, rb
);
1903 /* Some subsequent GL commands may depend on the framebuffer's visual
1904 * after the binding is updated. Update visual info now.
1906 _mesa_update_framebuffer_visual(fb
);
1911 _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target
, GLenum attachment
,
1912 GLenum pname
, GLint
*params
)
1914 const struct gl_renderbuffer_attachment
*att
;
1915 struct gl_framebuffer
*buffer
;
1916 GET_CURRENT_CONTEXT(ctx
);
1918 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1921 #if FEATURE_EXT_framebuffer_blit
1922 case GL_DRAW_FRAMEBUFFER_EXT
:
1923 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1924 _mesa_error(ctx
, GL_INVALID_ENUM
,
1925 "glGetFramebufferAttachmentParameterivEXT(target)");
1928 buffer
= ctx
->DrawBuffer
;
1930 case GL_READ_FRAMEBUFFER_EXT
:
1931 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
1932 _mesa_error(ctx
, GL_INVALID_ENUM
,
1933 "glGetFramebufferAttachmentParameterivEXT(target)");
1936 buffer
= ctx
->ReadBuffer
;
1939 case GL_FRAMEBUFFER_EXT
:
1940 buffer
= ctx
->DrawBuffer
;
1943 _mesa_error(ctx
, GL_INVALID_ENUM
,
1944 "glGetFramebufferAttachmentParameterivEXT(target)");
1948 if (buffer
->Name
== 0) {
1949 /* the default / window-system FBO */
1950 att
= _mesa_get_fb0_attachment(ctx
, buffer
, attachment
);
1953 /* user-created framebuffer FBO */
1954 att
= _mesa_get_attachment(ctx
, buffer
, attachment
);
1958 _mesa_error(ctx
, GL_INVALID_ENUM
,
1959 "glGetFramebufferAttachmentParameterivEXT(attachment)");
1963 if (attachment
== GL_DEPTH_STENCIL_ATTACHMENT
) {
1964 /* the depth and stencil attachments must point to the same buffer */
1965 const struct gl_renderbuffer_attachment
*depthAtt
, *stencilAtt
;
1966 depthAtt
= _mesa_get_attachment(ctx
, buffer
, GL_DEPTH_ATTACHMENT
);
1967 stencilAtt
= _mesa_get_attachment(ctx
, buffer
, GL_STENCIL_ATTACHMENT
);
1968 if (depthAtt
->Renderbuffer
!= stencilAtt
->Renderbuffer
) {
1969 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1970 "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
1971 " attachments differ)");
1976 /* No need to flush here */
1979 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
:
1980 *params
= att
->Type
;
1982 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
:
1983 if (att
->Type
== GL_RENDERBUFFER_EXT
) {
1984 *params
= att
->Renderbuffer
->Name
;
1986 else if (att
->Type
== GL_TEXTURE
) {
1987 *params
= att
->Texture
->Name
;
1990 _mesa_error(ctx
, GL_INVALID_ENUM
,
1991 "glGetFramebufferAttachmentParameterivEXT(pname)");
1994 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
:
1995 if (att
->Type
== GL_TEXTURE
) {
1996 *params
= att
->TextureLevel
;
1999 _mesa_error(ctx
, GL_INVALID_ENUM
,
2000 "glGetFramebufferAttachmentParameterivEXT(pname)");
2003 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
:
2004 if (att
->Type
== GL_TEXTURE
) {
2005 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_CUBE_MAP
) {
2006 *params
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ att
->CubeMapFace
;
2013 _mesa_error(ctx
, GL_INVALID_ENUM
,
2014 "glGetFramebufferAttachmentParameterivEXT(pname)");
2017 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
:
2018 if (att
->Type
== GL_TEXTURE
) {
2019 if (att
->Texture
&& att
->Texture
->Target
== GL_TEXTURE_3D
) {
2020 *params
= att
->Zoffset
;
2027 _mesa_error(ctx
, GL_INVALID_ENUM
,
2028 "glGetFramebufferAttachmentParameterivEXT(pname)");
2031 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
:
2032 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2033 _mesa_error(ctx
, GL_INVALID_ENUM
,
2034 "glGetFramebufferAttachmentParameterivEXT(pname)");
2037 *params
= _mesa_get_format_color_encoding(att
->Renderbuffer
->Format
);
2040 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE
:
2041 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2042 _mesa_error(ctx
, GL_INVALID_ENUM
,
2043 "glGetFramebufferAttachmentParameterivEXT(pname)");
2047 gl_format format
= att
->Renderbuffer
->Format
;
2048 if (format
== MESA_FORMAT_CI8
|| format
== MESA_FORMAT_S8
) {
2053 *params
= _mesa_get_format_datatype(format
);
2057 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
2058 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
2059 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
2060 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
2061 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
2062 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
2063 if (!ctx
->Extensions
.ARB_framebuffer_object
) {
2064 _mesa_error(ctx
, GL_INVALID_ENUM
,
2065 "glGetFramebufferAttachmentParameterivEXT(pname)");
2067 else if (att
->Texture
) {
2068 const struct gl_texture_image
*texImage
=
2069 _mesa_select_tex_image(ctx
, att
->Texture
, att
->Texture
->Target
,
2072 *params
= get_component_bits(pname
, texImage
->_BaseFormat
,
2073 texImage
->TexFormat
);
2079 else if (att
->Renderbuffer
) {
2080 *params
= get_component_bits(pname
, att
->Renderbuffer
->_BaseFormat
,
2081 att
->Renderbuffer
->Format
);
2088 _mesa_error(ctx
, GL_INVALID_ENUM
,
2089 "glGetFramebufferAttachmentParameterivEXT(pname)");
2096 _mesa_GenerateMipmapEXT(GLenum target
)
2098 struct gl_texture_object
*texObj
;
2099 GET_CURRENT_CONTEXT(ctx
);
2101 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2102 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2108 case GL_TEXTURE_CUBE_MAP
:
2109 /* OK, legal value */
2112 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGenerateMipmapEXT(target)");
2116 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2118 if (texObj
->BaseLevel
>= texObj
->MaxLevel
) {
2123 _mesa_lock_texture(ctx
, texObj
);
2124 if (target
== GL_TEXTURE_CUBE_MAP
) {
2126 for (face
= 0; face
< 6; face
++)
2127 ctx
->Driver
.GenerateMipmap(ctx
,
2128 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
+ face
,
2132 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2134 _mesa_unlock_texture(ctx
, texObj
);
2138 #if FEATURE_EXT_framebuffer_blit
2140 static const struct gl_renderbuffer_attachment
*
2141 find_attachment(const struct gl_framebuffer
*fb
, const struct gl_renderbuffer
*rb
)
2144 for (i
= 0; i
< Elements(fb
->Attachment
); i
++) {
2145 if (fb
->Attachment
[i
].Renderbuffer
== rb
)
2146 return &fb
->Attachment
[i
];
2154 * Blit rectangular region, optionally from one framebuffer to another.
2156 * Note, if the src buffer is multisampled and the dest is not, this is
2157 * when the samples must be resolved to a single color.
2160 _mesa_BlitFramebufferEXT(GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
2161 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
2162 GLbitfield mask
, GLenum filter
)
2164 const GLbitfield legalMaskBits
= (GL_COLOR_BUFFER_BIT
|
2165 GL_DEPTH_BUFFER_BIT
|
2166 GL_STENCIL_BUFFER_BIT
);
2167 const struct gl_framebuffer
*readFb
, *drawFb
;
2168 const struct gl_renderbuffer
*colorReadRb
, *colorDrawRb
;
2169 GET_CURRENT_CONTEXT(ctx
);
2171 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2172 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
2174 if (ctx
->NewState
) {
2175 _mesa_update_state(ctx
);
2178 readFb
= ctx
->ReadBuffer
;
2179 drawFb
= ctx
->DrawBuffer
;
2181 if (!readFb
|| !drawFb
) {
2182 /* This will normally never happen but someday we may want to
2183 * support MakeCurrent() with no drawables.
2188 /* check for complete framebuffers */
2189 if (drawFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
2190 readFb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2191 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2192 "glBlitFramebufferEXT(incomplete draw/read buffers)");
2196 if (filter
!= GL_NEAREST
&& filter
!= GL_LINEAR
) {
2197 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlitFramebufferEXT(filter)");
2201 if (mask
& ~legalMaskBits
) {
2202 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBlitFramebufferEXT(mask)");
2206 /* depth/stencil must be blitted with nearest filtering */
2207 if ((mask
& (GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
))
2208 && filter
!= GL_NEAREST
) {
2209 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2210 "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
2214 /* get color read/draw renderbuffers */
2215 if (mask
& GL_COLOR_BUFFER_BIT
) {
2216 colorReadRb
= readFb
->_ColorReadBuffer
;
2217 colorDrawRb
= drawFb
->_ColorDrawBuffers
[0];
2220 colorReadRb
= colorDrawRb
= NULL
;
2223 if (mask
& GL_STENCIL_BUFFER_BIT
) {
2224 struct gl_renderbuffer
*readRb
= readFb
->_StencilBuffer
;
2225 struct gl_renderbuffer
*drawRb
= drawFb
->_StencilBuffer
;
2228 _mesa_get_format_bits(readRb
->Format
, GL_STENCIL_BITS
) !=
2229 _mesa_get_format_bits(drawRb
->Format
, GL_STENCIL_BITS
)) {
2230 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2231 "glBlitFramebufferEXT(stencil buffer size mismatch");
2236 if (mask
& GL_DEPTH_BUFFER_BIT
) {
2237 struct gl_renderbuffer
*readRb
= readFb
->_DepthBuffer
;
2238 struct gl_renderbuffer
*drawRb
= drawFb
->_DepthBuffer
;
2241 _mesa_get_format_bits(readRb
->Format
, GL_DEPTH_BITS
) !=
2242 _mesa_get_format_bits(drawRb
->Format
, GL_DEPTH_BITS
)) {
2243 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2244 "glBlitFramebufferEXT(depth buffer size mismatch");
2249 if (readFb
->Visual
.samples
> 0 &&
2250 drawFb
->Visual
.samples
> 0 &&
2251 readFb
->Visual
.samples
!= drawFb
->Visual
.samples
) {
2252 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2253 "glBlitFramebufferEXT(mismatched samples");
2257 /* extra checks for multisample copies... */
2258 if (readFb
->Visual
.samples
> 0 || drawFb
->Visual
.samples
> 0) {
2259 /* src and dest region sizes must be the same */
2260 if (srcX1
- srcX0
!= dstX1
- dstX0
||
2261 srcY1
- srcY0
!= dstY1
- dstY0
) {
2262 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2263 "glBlitFramebufferEXT(bad src/dst multisample region sizes");
2267 /* color formats must match */
2270 colorReadRb
->Format
!= colorDrawRb
->Format
) {
2271 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2272 "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
2277 if (!ctx
->Extensions
.EXT_framebuffer_blit
) {
2278 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlitFramebufferEXT");
2284 printf("glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d,"
2286 srcX0
, srcY0
, srcX1
, srcY1
,
2287 dstX0
, dstY0
, dstX1
, dstY1
,
2290 const struct gl_renderbuffer_attachment
*att
;
2292 att
= find_attachment(readFb
, colorReadRb
);
2293 printf(" Src FBO %u RB %u (%dx%d) ",
2294 readFb
->Name
, colorReadRb
->Name
,
2295 colorReadRb
->Width
, colorReadRb
->Height
);
2296 if (att
&& att
->Texture
) {
2297 printf("Tex %u tgt 0x%x level %u face %u",
2299 att
->Texture
->Target
,
2305 att
= find_attachment(drawFb
, colorDrawRb
);
2306 printf(" Dst FBO %u RB %u (%dx%d) ",
2307 drawFb
->Name
, colorDrawRb
->Name
,
2308 colorDrawRb
->Width
, colorDrawRb
->Height
);
2309 if (att
&& att
->Texture
) {
2310 printf("Tex %u tgt 0x%x level %u face %u",
2312 att
->Texture
->Target
,
2320 ASSERT(ctx
->Driver
.BlitFramebuffer
);
2321 ctx
->Driver
.BlitFramebuffer(ctx
,
2322 srcX0
, srcY0
, srcX1
, srcY1
,
2323 dstX0
, dstY0
, dstX1
, dstY1
,
2326 #endif /* FEATURE_EXT_framebuffer_blit */
2328 #if FEATURE_ARB_geometry_shader4
2330 _mesa_FramebufferTextureARB(GLenum target
, GLenum attachment
,
2331 GLuint texture
, GLint level
)
2333 GET_CURRENT_CONTEXT(ctx
);
2334 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2335 "glFramebufferTextureARB "
2336 "not implemented!");
2340 _mesa_FramebufferTextureFaceARB(GLenum target
, GLenum attachment
,
2341 GLuint texture
, GLint level
, GLenum face
)
2343 GET_CURRENT_CONTEXT(ctx
);
2344 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2345 "glFramebufferTextureFaceARB "
2346 "not implemented!");
2348 #endif /* FEATURE_ARB_geometry_shader4 */